aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/communicator.h8
-rw-r--r--src/transport/gnunet-communicator-tcp.c1840
-rw-r--r--src/transport/gnunet-communicator-udp.c2292
-rw-r--r--src/transport/gnunet-communicator-unix.c958
-rw-r--r--src/transport/gnunet-helper-transport-bluetooth.c3205
-rw-r--r--src/transport/gnunet-helper-transport-wlan-dummy.c595
-rw-r--r--src/transport/gnunet-helper-transport-wlan.c1607
-rw-r--r--src/transport/gnunet-service-tng.c7781
-rw-r--r--src/transport/gnunet-service-transport.c2390
-rw-r--r--src/transport/gnunet-service-transport.h64
-rw-r--r--src/transport/gnunet-service-transport_ats.c772
-rw-r--r--src/transport/gnunet-service-transport_ats.h56
-rw-r--r--src/transport/gnunet-service-transport_hello.c209
-rw-r--r--src/transport/gnunet-service-transport_hello.h24
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c508
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h38
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c4336
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h86
-rw-r--r--src/transport/gnunet-service-transport_plugins.c486
-rw-r--r--src/transport/gnunet-service-transport_plugins.h24
-rw-r--r--src/transport/gnunet-service-transport_validation.c1702
-rw-r--r--src/transport/gnunet-service-transport_validation.h32
-rw-r--r--src/transport/gnunet-transport-profiler.c560
-rw-r--r--src/transport/gnunet-transport-wlan-receiver.c144
-rw-r--r--src/transport/gnunet-transport-wlan-sender.c280
-rw-r--r--src/transport/gnunet-transport.c1266
-rw-r--r--src/transport/ieee80211_radiotap.h60
-rw-r--r--src/transport/plugin_transport_http.h88
-rw-r--r--src/transport/plugin_transport_http_client.c2426
-rw-r--r--src/transport/plugin_transport_http_common.c961
-rw-r--r--src/transport/plugin_transport_http_common.h91
-rw-r--r--src/transport/plugin_transport_http_server.c3571
-rw-r--r--src/transport/plugin_transport_smtp.c642
-rw-r--r--src/transport/plugin_transport_tcp.c3631
-rw-r--r--src/transport/plugin_transport_template.c188
-rw-r--r--src/transport/plugin_transport_udp.c3988
-rw-r--r--src/transport/plugin_transport_udp.h46
-rw-r--r--src/transport/plugin_transport_udp_broadcasting.c643
-rw-r--r--src/transport/plugin_transport_unix.c1603
-rw-r--r--src/transport/plugin_transport_wlan.c2091
-rw-r--r--src/transport/plugin_transport_wlan.h53
-rw-r--r--src/transport/tcp_connection_legacy.c1315
-rw-r--r--src/transport/tcp_server_legacy.c1283
-rw-r--r--src/transport/tcp_server_mst_legacy.c329
-rw-r--r--src/transport/tcp_service_legacy.c1761
-rw-r--r--src/transport/test_communicator_unix.c222
-rw-r--r--src/transport/test_http_common.c227
-rw-r--r--src/transport/test_plugin_transport.c836
-rw-r--r--src/transport/test_quota_compliance.c326
-rw-r--r--src/transport/test_transport_address_switch.c406
-rw-r--r--src/transport/test_transport_api.c78
-rw-r--r--src/transport/test_transport_api_blacklisting.c178
-rw-r--r--src/transport/test_transport_api_disconnect.c96
-rw-r--r--src/transport/test_transport_api_limited_sockets.c78
-rw-r--r--src/transport/test_transport_api_manipulation_cfg.c175
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c180
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c178
-rw-r--r--src/transport/test_transport_api_monitor_peers.c206
-rw-r--r--src/transport/test_transport_api_reliability.c218
-rw-r--r--src/transport/test_transport_api_restart_reconnect.c182
-rw-r--r--src/transport/test_transport_api_timeout.c128
-rw-r--r--src/transport/test_transport_blacklisting.c705
-rw-r--r--src/transport/test_transport_testing_restart.c133
-rw-r--r--src/transport/test_transport_testing_startstop.c117
-rw-r--r--src/transport/transport-testing-filenames.c124
-rw-r--r--src/transport/transport-testing-loggers.c44
-rw-r--r--src/transport/transport-testing-main.c460
-rw-r--r--src/transport/transport-testing-send.c206
-rw-r--r--src/transport/transport-testing.c1019
-rw-r--r--src/transport/transport-testing.h81
-rw-r--r--src/transport/transport-testing2.c456
-rw-r--r--src/transport/transport-testing2.h62
-rw-r--r--src/transport/transport.h155
-rw-r--r--src/transport/transport_api2_application.c189
-rw-r--r--src/transport/transport_api2_communication.c465
-rw-r--r--src/transport/transport_api2_core.c490
-rw-r--r--src/transport/transport_api2_monitor.c127
-rw-r--r--src/transport/transport_api_address_to_string.c222
-rw-r--r--src/transport/transport_api_blacklist.c91
-rw-r--r--src/transport/transport_api_core.c603
-rw-r--r--src/transport/transport_api_hello_get.c142
-rw-r--r--src/transport/transport_api_manipulation.c130
-rw-r--r--src/transport/transport_api_monitor_peers.c377
-rw-r--r--src/transport/transport_api_monitor_plugins.c294
-rw-r--r--src/transport/transport_api_offer_hello.c81
85 files changed, 33127 insertions, 33393 deletions
diff --git a/src/transport/communicator.h b/src/transport/communicator.h
index 07f316a68..04a9857e5 100644
--- a/src/transport/communicator.h
+++ b/src/transport/communicator.h
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/communicator.h 22 * @file transport/communicator.h
@@ -41,8 +41,7 @@ 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{
46 /** 45 /**
47 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION 46 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION
48 */ 47 */
@@ -89,8 +88,7 @@ struct GNUNET_TRANSPORT_CommunicatorGenericKXConfirmation
89 * free to implement original designs that better fit their 88 * free to implement original designs that better fit their
90 * requirements. 89 * requirements.
91 */ 90 */
92struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits 91struct GNUNET_TRANSPORT_CommunicatorGenericFCLimits {
93{
94 /** 92 /**
95 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS 93 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS
96 */ 94 */
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index c883166c6..a8d692940 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-communicator-tcp.c 22 * @file 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
@@ -63,7 +63,7 @@
63 * Size of our IO buffers for ciphertext data. Must be at 63 * Size of our IO buffers for ciphertext data. Must be at
64 * least UINT_MAX + sizeof (struct TCPBox). 64 * least UINT_MAX + sizeof (struct TCPBox).
65 */ 65 */
66#define BUF_SIZE (2 * 64 * 1024 + sizeof (struct TCPBox)) 66#define BUF_SIZE (2 * 64 * 1024 + sizeof(struct TCPBox))
67 67
68/** 68/**
69 * How often do we rekey based on time (at least) 69 * How often do we rekey based on time (at least)
@@ -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,8 +107,7 @@ 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{
112 /** 111 /**
113 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE 112 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE
114 */ 113 */
@@ -140,8 +139,7 @@ struct TcpHandshakeSignature
140/** 139/**
141 * Encrypted continuation of TCP initial handshake. 140 * Encrypted continuation of TCP initial handshake.
142 */ 141 */
143struct TCPConfirmation 142struct TCPConfirmation {
144{
145 /** 143 /**
146 * Sender's identity 144 * Sender's identity
147 */ 145 */
@@ -163,9 +161,7 @@ struct TCPConfirmation
163/** 161/**
164 * TCP message box. Always sent encrypted! 162 * TCP message box. Always sent encrypted!
165 */ 163 */
166struct TCPBox 164struct TCPBox {
167{
168
169 /** 165 /**
170 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX. Warning: the 166 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX. Warning: the
171 * header size EXCLUDES the size of the `struct TCPBox`. We usually 167 * header size EXCLUDES the size of the `struct TCPBox`. We usually
@@ -193,9 +189,7 @@ struct TCPBox
193 * TCP rekey message box. Always sent encrypted! Data after 189 * TCP rekey message box. Always sent encrypted! Data after
194 * this message will use the new key. 190 * this message will use the new key.
195 */ 191 */
196struct TCPRekey 192struct TCPRekey {
197{
198
199 /** 193 /**
200 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY. 194 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY.
201 */ 195 */
@@ -234,9 +228,7 @@ struct TCPRekey
234 * Needed/useful in case we drop RST/FIN packets on the GNUnet 228 * Needed/useful in case we drop RST/FIN packets on the GNUnet
235 * port due to the possibility of malicious RST/FIN injection. 229 * port due to the possibility of malicious RST/FIN injection.
236 */ 230 */
237struct TCPFinish 231struct TCPFinish {
238{
239
240 /** 232 /**
241 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH. 233 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH.
242 */ 234 */
@@ -260,9 +252,7 @@ GNUNET_NETWORK_STRUCT_END
260/** 252/**
261 * Handle for a queue. 253 * Handle for a queue.
262 */ 254 */
263struct Queue 255struct Queue {
264{
265
266 /** 256 /**
267 * To whom are we talking to. 257 * To whom are we talking to.
268 */ 258 */
@@ -360,12 +350,12 @@ struct Queue
360 /** 350 /**
361 * Plaintext buffer for decrypted plaintext. 351 * Plaintext buffer for decrypted plaintext.
362 */ 352 */
363 char pread_buf[UINT16_MAX + 1 + sizeof (struct TCPBox)]; 353 char pread_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
364 354
365 /** 355 /**
366 * Plaintext buffer for messages to be encrypted. 356 * Plaintext buffer for messages to be encrypted.
367 */ 357 */
368 char pwrite_buf[UINT16_MAX + 1 + sizeof (struct TCPBox)]; 358 char pwrite_buf[UINT16_MAX + 1 + sizeof(struct TCPBox)];
369 359
370 /** 360 /**
371 * At which offset in the ciphertext read buffer should we 361 * At which offset in the ciphertext read buffer should we
@@ -440,9 +430,7 @@ struct Queue
440 * Handle for an incoming connection where we do not yet have enough 430 * Handle for an incoming connection where we do not yet have enough
441 * information to setup a full queue. 431 * information to setup a full queue.
442 */ 432 */
443struct ProtoQueue 433struct ProtoQueue {
444{
445
446 /** 434 /**
447 * Kept in a DLL. 435 * Kept in a DLL.
448 */ 436 */
@@ -565,7 +553,7 @@ static struct ProtoQueue *proto_tail;
565 * @param cls NULL 553 * @param cls NULL
566 */ 554 */
567static void 555static void
568listen_cb (void *cls); 556listen_cb(void *cls);
569 557
570 558
571/** 559/**
@@ -576,53 +564,53 @@ listen_cb (void *cls);
576 * @param queue queue to close down 564 * @param queue queue to close down
577 */ 565 */
578static void 566static void
579queue_destroy (struct Queue *queue) 567queue_destroy(struct Queue *queue)
580{ 568{
581 struct GNUNET_MQ_Handle *mq; 569 struct GNUNET_MQ_Handle *mq;
582 570
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
584 "Disconnecting queue for peer `%s'\n", 572 "Disconnecting queue for peer `%s'\n",
585 GNUNET_i2s (&queue->target)); 573 GNUNET_i2s(&queue->target));
586 if (NULL != (mq = queue->mq)) 574 if (NULL != (mq = queue->mq))
587 { 575 {
588 queue->mq = NULL; 576 queue->mq = NULL;
589 GNUNET_MQ_destroy (mq); 577 GNUNET_MQ_destroy(mq);
590 } 578 }
591 if (NULL != queue->qh) 579 if (NULL != queue->qh)
592 { 580 {
593 GNUNET_TRANSPORT_communicator_mq_del (queue->qh); 581 GNUNET_TRANSPORT_communicator_mq_del(queue->qh);
594 queue->qh = NULL; 582 queue->qh = NULL;
595 } 583 }
596 GNUNET_assert ( 584 GNUNET_assert(
597 GNUNET_YES == 585 GNUNET_YES ==
598 GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); 586 GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue));
599 GNUNET_STATISTICS_set (stats, 587 GNUNET_STATISTICS_set(stats,
600 "# queues active", 588 "# queues active",
601 GNUNET_CONTAINER_multipeermap_size (queue_map), 589 GNUNET_CONTAINER_multipeermap_size(queue_map),
602 GNUNET_NO); 590 GNUNET_NO);
603 if (NULL != queue->read_task) 591 if (NULL != queue->read_task)
604 { 592 {
605 GNUNET_SCHEDULER_cancel (queue->read_task); 593 GNUNET_SCHEDULER_cancel(queue->read_task);
606 queue->read_task = NULL; 594 queue->read_task = NULL;
607 } 595 }
608 if (NULL != queue->write_task) 596 if (NULL != queue->write_task)
609 { 597 {
610 GNUNET_SCHEDULER_cancel (queue->write_task); 598 GNUNET_SCHEDULER_cancel(queue->write_task);
611 queue->write_task = NULL; 599 queue->write_task = NULL;
612 } 600 }
613 GNUNET_NETWORK_socket_close (queue->sock); 601 GNUNET_NETWORK_socket_close(queue->sock);
614 gcry_cipher_close (queue->in_cipher); 602 gcry_cipher_close(queue->in_cipher);
615 gcry_cipher_close (queue->out_cipher); 603 gcry_cipher_close(queue->out_cipher);
616 GNUNET_free (queue->address); 604 GNUNET_free(queue->address);
617 if (0 != queue->backpressure) 605 if (0 != queue->backpressure)
618 queue->destroyed = GNUNET_YES; 606 queue->destroyed = GNUNET_YES;
619 else 607 else
620 GNUNET_free (queue); 608 GNUNET_free(queue);
621 if (NULL == listen_task) 609 if (NULL == listen_task)
622 listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 610 listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
623 listen_sock, 611 listen_sock,
624 &listen_cb, 612 &listen_cb,
625 NULL); 613 NULL);
626} 614}
627 615
628 616
@@ -635,24 +623,24 @@ queue_destroy (struct Queue *queue)
635 * @param smac[out] where to write the HMAC 623 * @param smac[out] where to write the HMAC
636 */ 624 */
637static void 625static void
638calculate_hmac (struct GNUNET_HashCode *hmac_secret, 626calculate_hmac(struct GNUNET_HashCode *hmac_secret,
639 const void *buf, 627 const void *buf,
640 size_t buf_size, 628 size_t buf_size,
641 struct GNUNET_ShortHashCode *smac) 629 struct GNUNET_ShortHashCode *smac)
642{ 630{
643 struct GNUNET_HashCode mac; 631 struct GNUNET_HashCode mac;
644 632
645 GNUNET_CRYPTO_hmac_raw (hmac_secret, 633 GNUNET_CRYPTO_hmac_raw(hmac_secret,
646 sizeof (struct GNUNET_HashCode), 634 sizeof(struct GNUNET_HashCode),
647 buf, 635 buf,
648 buf_size, 636 buf_size,
649 &mac); 637 &mac);
650 /* truncate to `struct GNUNET_ShortHashCode` */ 638 /* truncate to `struct GNUNET_ShortHashCode` */
651 memcpy (smac, &mac, sizeof (struct GNUNET_ShortHashCode)); 639 memcpy(smac, &mac, sizeof(struct GNUNET_ShortHashCode));
652 /* ratchet hmac key */ 640 /* ratchet hmac key */
653 GNUNET_CRYPTO_hash (hmac_secret, 641 GNUNET_CRYPTO_hash(hmac_secret,
654 sizeof (struct GNUNET_HashCode), 642 sizeof(struct GNUNET_HashCode),
655 hmac_secret); 643 hmac_secret);
656} 644}
657 645
658 646
@@ -663,23 +651,23 @@ calculate_hmac (struct GNUNET_HashCode *hmac_secret,
663 * @param queue queue to shut down nicely 651 * @param queue queue to shut down nicely
664 */ 652 */
665static void 653static void
666queue_finish (struct Queue *queue) 654queue_finish(struct Queue *queue)
667{ 655{
668 struct TCPFinish fin; 656 struct TCPFinish fin;
669 657
670 memset (&fin, 0, sizeof (fin)); 658 memset(&fin, 0, sizeof(fin));
671 fin.header.size = htons (sizeof (fin)); 659 fin.header.size = htons(sizeof(fin));
672 fin.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH); 660 fin.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH);
673 calculate_hmac (&queue->out_hmac, &fin, sizeof (fin), &fin.hmac); 661 calculate_hmac(&queue->out_hmac, &fin, sizeof(fin), &fin.hmac);
674 /* if there is any message left in pwrite_buf, we 662 /* if there is any message left in pwrite_buf, we
675 overwrite it (possibly dropping the last message 663 overwrite it (possibly dropping the last message
676 from CORE hard here) */ 664 from CORE hard here) */
677 memcpy (queue->pwrite_buf, &fin, sizeof (fin)); 665 memcpy(queue->pwrite_buf, &fin, sizeof(fin));
678 queue->pwrite_off = sizeof (fin); 666 queue->pwrite_off = sizeof(fin);
679 /* This flag will ensure that #queue_write() no longer 667 /* This flag will ensure that #queue_write() no longer
680 notifies CORE about the possibility of sending 668 notifies CORE about the possibility of sending
681 more data, and that #queue_write() will call 669 more data, and that #queue_write() will call
682 #queue_destroy() once the @c fin was fully written. */ 670 #queue_destroy() once the @c fin was fully written. */
683 queue->finishing = GNUNET_YES; 671 queue->finishing = GNUNET_YES;
684} 672}
685 673
@@ -692,10 +680,10 @@ queue_finish (struct Queue *queue)
692 * @param queue queue for which the timeout should be rescheduled 680 * @param queue queue for which the timeout should be rescheduled
693 */ 681 */
694static void 682static void
695reschedule_queue_timeout (struct Queue *queue) 683reschedule_queue_timeout(struct Queue *queue)
696{ 684{
697 queue->timeout = 685 queue->timeout =
698 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 686 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
699} 687}
700 688
701 689
@@ -705,7 +693,7 @@ reschedule_queue_timeout (struct Queue *queue)
705 * @param cls the `struct Queue *` to disconnect 693 * @param cls the `struct Queue *` to disconnect
706 */ 694 */
707static void 695static void
708queue_read (void *cls); 696queue_read(void *cls);
709 697
710 698
711/** 699/**
@@ -716,31 +704,31 @@ queue_read (void *cls);
716 * @param success #GNUNET_OK on success 704 * @param success #GNUNET_OK on success
717 */ 705 */
718static void 706static void
719core_read_finished_cb (void *cls, int success) 707core_read_finished_cb(void *cls, int success)
720{ 708{
721 struct Queue *queue = cls; 709 struct Queue *queue = cls;
722 710
723 if (GNUNET_OK != success) 711 if (GNUNET_OK != success)
724 GNUNET_STATISTICS_update (stats, 712 GNUNET_STATISTICS_update(stats,
725 "# messages lost in communicator API towards CORE", 713 "# messages lost in communicator API towards CORE",
726 1, 714 1,
727 GNUNET_NO); 715 GNUNET_NO);
728 queue->backpressure--; 716 queue->backpressure--;
729 /* handle deferred queue destruction */ 717 /* handle deferred queue destruction */
730 if ((queue->destroyed) && (0 == queue->backpressure)) 718 if ((queue->destroyed) && (0 == queue->backpressure))
731 { 719 {
732 GNUNET_free (queue); 720 GNUNET_free(queue);
733 return; 721 return;
734 } 722 }
735 reschedule_queue_timeout (queue); 723 reschedule_queue_timeout(queue);
736 /* possibly unchoke reading, now that CORE made progress */ 724 /* possibly unchoke reading, now that CORE made progress */
737 if (NULL == queue->read_task) 725 if (NULL == queue->read_task)
738 queue->read_task = 726 queue->read_task =
739 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( 727 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining(
740 queue->timeout), 728 queue->timeout),
741 queue->sock, 729 queue->sock,
742 &queue_read, 730 &queue_read,
743 queue); 731 queue);
744} 732}
745 733
746 734
@@ -754,34 +742,34 @@ core_read_finished_cb (void *cls, int success)
754 * @param plaintext_len number of bytes of plaintext received 742 * @param plaintext_len number of bytes of plaintext received
755 */ 743 */
756static void 744static void
757pass_plaintext_to_core (struct Queue *queue, 745pass_plaintext_to_core(struct Queue *queue,
758 const void *plaintext, 746 const void *plaintext,
759 size_t plaintext_len) 747 size_t plaintext_len)
760{ 748{
761 const struct GNUNET_MessageHeader *hdr = plaintext; 749 const struct GNUNET_MessageHeader *hdr = plaintext;
762 int ret; 750 int ret;
763 751
764 if (ntohs (hdr->size) != plaintext_len) 752 if (ntohs(hdr->size) != plaintext_len)
765 { 753 {
766 /* NOTE: If we ever allow multiple CORE messages in one 754 /* NOTE: If we ever allow multiple CORE messages in one
767 BOX, this will have to change! */ 755 BOX, this will have to change! */
768 GNUNET_break (0); 756 GNUNET_break(0);
769 return; 757 return;
770 } 758 }
771 ret = GNUNET_TRANSPORT_communicator_receive (ch, 759 ret = GNUNET_TRANSPORT_communicator_receive(ch,
772 &queue->target, 760 &queue->target,
773 hdr, 761 hdr,
774 ADDRESS_VALIDITY_PERIOD, 762 ADDRESS_VALIDITY_PERIOD,
775 &core_read_finished_cb, 763 &core_read_finished_cb,
776 queue); 764 queue);
777 if (GNUNET_OK == ret) 765 if (GNUNET_OK == ret)
778 queue->backpressure++; 766 queue->backpressure++;
779 GNUNET_break (GNUNET_NO != ret); /* backpressure not working!? */ 767 GNUNET_break(GNUNET_NO != ret); /* backpressure not working!? */
780 if (GNUNET_SYSERR == ret) 768 if (GNUNET_SYSERR == ret)
781 GNUNET_STATISTICS_update (stats, 769 GNUNET_STATISTICS_update(stats,
782 "# bytes lost due to CORE not running", 770 "# bytes lost due to CORE not running",
783 plaintext_len, 771 plaintext_len,
784 GNUNET_NO); 772 GNUNET_NO);
785} 773}
786 774
787 775
@@ -795,51 +783,51 @@ pass_plaintext_to_core (struct Queue *queue,
795 * @param hmac_key[out] HMAC key to initialize 783 * @param hmac_key[out] HMAC key to initialize
796 */ 784 */
797static void 785static void
798setup_cipher (const struct GNUNET_HashCode *dh, 786setup_cipher(const struct GNUNET_HashCode *dh,
799 const struct GNUNET_PeerIdentity *pid, 787 const struct GNUNET_PeerIdentity *pid,
800 gcry_cipher_hd_t *cipher, 788 gcry_cipher_hd_t *cipher,
801 struct GNUNET_HashCode *hmac_key) 789 struct GNUNET_HashCode *hmac_key)
802{ 790{
803 char key[256 / 8]; 791 char key[256 / 8];
804 char ctr[128 / 8]; 792 char ctr[128 / 8];
805 793
806 gcry_cipher_open (cipher, 794 gcry_cipher_open(cipher,
807 GCRY_CIPHER_AES256 /* low level: go for speed */, 795 GCRY_CIPHER_AES256 /* low level: go for speed */,
808 GCRY_CIPHER_MODE_CTR, 796 GCRY_CIPHER_MODE_CTR,
809 0 /* flags */); 797 0 /* flags */);
810 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (key, 798 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_kdf(key,
811 sizeof (key), 799 sizeof(key),
812 "TCP-key", 800 "TCP-key",
813 strlen ("TCP-key"), 801 strlen("TCP-key"),
814 dh, 802 dh,
815 sizeof (*dh), 803 sizeof(*dh),
816 pid, 804 pid,
817 sizeof (*pid), 805 sizeof(*pid),
818 NULL, 806 NULL,
819 0)); 807 0));
820 gcry_cipher_setkey (*cipher, key, sizeof (key)); 808 gcry_cipher_setkey(*cipher, key, sizeof(key));
821 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_kdf (ctr, 809 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_kdf(ctr,
822 sizeof (ctr), 810 sizeof(ctr),
823 "TCP-ctr", 811 "TCP-ctr",
824 strlen ("TCP-ctr"), 812 strlen("TCP-ctr"),
825 dh, 813 dh,
826 sizeof (*dh), 814 sizeof(*dh),
827 pid, 815 pid,
828 sizeof (*pid), 816 sizeof(*pid),
829 NULL, 817 NULL,
830 0)); 818 0));
831 gcry_cipher_setctr (*cipher, ctr, sizeof (ctr)); 819 gcry_cipher_setctr(*cipher, ctr, sizeof(ctr));
832 GNUNET_assert (GNUNET_YES == 820 GNUNET_assert(GNUNET_YES ==
833 GNUNET_CRYPTO_kdf (hmac_key, 821 GNUNET_CRYPTO_kdf(hmac_key,
834 sizeof (struct GNUNET_HashCode), 822 sizeof(struct GNUNET_HashCode),
835 "TCP-hmac", 823 "TCP-hmac",
836 strlen ("TCP-hmac"), 824 strlen("TCP-hmac"),
837 dh, 825 dh,
838 sizeof (*dh), 826 sizeof(*dh),
839 pid, 827 pid,
840 sizeof (*pid), 828 sizeof(*pid),
841 NULL, 829 NULL,
842 0)); 830 0));
843} 831}
844 832
845 833
@@ -850,13 +838,13 @@ setup_cipher (const struct GNUNET_HashCode *dh,
850 * @param queue[in,out] queue to initialize decryption cipher for 838 * @param queue[in,out] queue to initialize decryption cipher for
851 */ 839 */
852static void 840static void
853setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, 841setup_in_cipher(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
854 struct Queue *queue) 842 struct Queue *queue)
855{ 843{
856 struct GNUNET_HashCode dh; 844 struct GNUNET_HashCode dh;
857 845
858 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &dh); 846 GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &dh);
859 setup_cipher (&dh, &my_identity, &queue->in_cipher, &queue->in_hmac); 847 setup_cipher(&dh, &my_identity, &queue->in_cipher, &queue->in_hmac);
860} 848}
861 849
862 850
@@ -869,30 +857,30 @@ setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
869 * @param rekey the rekey message 857 * @param rekey the rekey message
870 */ 858 */
871static void 859static void
872do_rekey (struct Queue *queue, const struct TCPRekey *rekey) 860do_rekey(struct Queue *queue, const struct TCPRekey *rekey)
873{ 861{
874 struct TcpHandshakeSignature thp; 862 struct TcpHandshakeSignature thp;
875 863
876 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); 864 thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
877 thp.purpose.size = htonl (sizeof (thp)); 865 thp.purpose.size = htonl(sizeof(thp));
878 thp.sender = queue->target; 866 thp.sender = queue->target;
879 thp.receiver = my_identity; 867 thp.receiver = my_identity;
880 thp.ephemeral = rekey->ephemeral; 868 thp.ephemeral = rekey->ephemeral;
881 thp.monotonic_time = rekey->monotonic_time; 869 thp.monotonic_time = rekey->monotonic_time;
882 /* FIXME: check monotonic time is monotonic... */ 870 /* FIXME: check monotonic time is monotonic... */
883 if (GNUNET_OK != 871 if (GNUNET_OK !=
884 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY, 872 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY,
885 &thp.purpose, 873 &thp.purpose,
886 &rekey->sender_sig, 874 &rekey->sender_sig,
887 &queue->target.public_key)) 875 &queue->target.public_key))
888 { 876 {
889 GNUNET_break (0); 877 GNUNET_break(0);
890 queue_finish (queue); 878 queue_finish(queue);
891 return; 879 return;
892 } 880 }
893 gcry_cipher_close (queue->in_cipher); 881 gcry_cipher_close(queue->in_cipher);
894 queue->rekeyed = GNUNET_YES; 882 queue->rekeyed = GNUNET_YES;
895 setup_in_cipher (&rekey->ephemeral, queue); 883 setup_in_cipher(&rekey->ephemeral, queue);
896} 884}
897 885
898 886
@@ -904,86 +892,89 @@ do_rekey (struct Queue *queue, const struct TCPRekey *rekey)
904 * @return number of bytes of plaintext handled, 0 for none 892 * @return number of bytes of plaintext handled, 0 for none
905 */ 893 */
906static size_t 894static size_t
907try_handle_plaintext (struct Queue *queue) 895try_handle_plaintext(struct Queue *queue)
908{ 896{
909 const struct GNUNET_MessageHeader *hdr = 897 const struct GNUNET_MessageHeader *hdr =
910 (const struct GNUNET_MessageHeader *) queue->pread_buf; 898 (const struct GNUNET_MessageHeader *)queue->pread_buf;
911 const struct TCPBox *box = (const struct TCPBox *) queue->pread_buf; 899 const struct TCPBox *box = (const struct TCPBox *)queue->pread_buf;
912 const struct TCPRekey *rekey = (const struct TCPRekey *) queue->pread_buf; 900 const struct TCPRekey *rekey = (const struct TCPRekey *)queue->pread_buf;
913 const struct TCPFinish *fin = (const struct TCPFinish *) queue->pread_buf; 901 const struct TCPFinish *fin = (const struct TCPFinish *)queue->pread_buf;
914 struct TCPRekey rekeyz; 902 struct TCPRekey rekeyz;
915 struct TCPFinish finz; 903 struct TCPFinish finz;
916 struct GNUNET_ShortHashCode tmac; 904 struct GNUNET_ShortHashCode tmac;
917 uint16_t type; 905 uint16_t type;
918 size_t size = 0; /* make compiler happy */ 906 size_t size = 0; /* make compiler happy */
919 907
920 if (sizeof (*hdr) > queue->pread_off) 908 if (sizeof(*hdr) > queue->pread_off)
921 return 0; /* not even a header */ 909 return 0; /* not even a header */
922 type = ntohs (hdr->type); 910 type = ntohs(hdr->type);
923 switch (type) 911 switch (type)
924 {
925 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX:
926 /* Special case: header size excludes box itself! */
927 if (ntohs (hdr->size) + sizeof (struct TCPBox) > queue->pread_off)
928 return 0;
929 calculate_hmac (&queue->in_hmac, &box[1], ntohs (hdr->size), &tmac);
930 if (0 != memcmp (&tmac, &box->hmac, sizeof (tmac)))
931 {
932 GNUNET_break_op (0);
933 queue_finish (queue);
934 return 0;
935 }
936 pass_plaintext_to_core (queue, (const void *) &box[1], ntohs (hdr->size));
937 size = ntohs (hdr->size) + sizeof (*box);
938 break;
939 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
940 if (sizeof (*rekey) > queue->pread_off)
941 return 0;
942 if (ntohs (hdr->size) != sizeof (*rekey))
943 { 912 {
944 GNUNET_break_op (0); 913 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX:
945 queue_finish (queue); 914 /* Special case: header size excludes box itself! */
946 return 0; 915 if (ntohs(hdr->size) + sizeof(struct TCPBox) > queue->pread_off)
947 } 916 return 0;
948 rekeyz = *rekey; 917 calculate_hmac(&queue->in_hmac, &box[1], ntohs(hdr->size), &tmac);
949 memset (&rekeyz.hmac, 0, sizeof (rekeyz.hmac)); 918 if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac)))
950 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof (rekeyz), &tmac); 919 {
951 if (0 != memcmp (&tmac, &box->hmac, sizeof (tmac))) 920 GNUNET_break_op(0);
952 { 921 queue_finish(queue);
953 GNUNET_break_op (0); 922 return 0;
954 queue_finish (queue); 923 }
955 return 0; 924 pass_plaintext_to_core(queue, (const void *)&box[1], ntohs(hdr->size));
956 } 925 size = ntohs(hdr->size) + sizeof(*box);
957 do_rekey (queue, rekey); 926 break;
958 size = ntohs (hdr->size); 927
959 break; 928 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY:
960 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH: 929 if (sizeof(*rekey) > queue->pread_off)
961 if (sizeof (*fin) > queue->pread_off) 930 return 0;
962 return 0; 931 if (ntohs(hdr->size) != sizeof(*rekey))
963 if (ntohs (hdr->size) != sizeof (*fin)) 932 {
964 { 933 GNUNET_break_op(0);
965 GNUNET_break_op (0); 934 queue_finish(queue);
966 queue_finish (queue); 935 return 0;
967 return 0; 936 }
968 } 937 rekeyz = *rekey;
969 finz = *fin; 938 memset(&rekeyz.hmac, 0, sizeof(rekeyz.hmac));
970 memset (&finz.hmac, 0, sizeof (finz.hmac)); 939 calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
971 calculate_hmac (&queue->in_hmac, &rekeyz, sizeof (rekeyz), &tmac); 940 if (0 != memcmp(&tmac, &box->hmac, sizeof(tmac)))
972 if (0 != memcmp (&tmac, &fin->hmac, sizeof (tmac))) 941 {
973 { 942 GNUNET_break_op(0);
974 GNUNET_break_op (0); 943 queue_finish(queue);
975 queue_finish (queue); 944 return 0;
945 }
946 do_rekey(queue, rekey);
947 size = ntohs(hdr->size);
948 break;
949
950 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_FINISH:
951 if (sizeof(*fin) > queue->pread_off)
952 return 0;
953 if (ntohs(hdr->size) != sizeof(*fin))
954 {
955 GNUNET_break_op(0);
956 queue_finish(queue);
957 return 0;
958 }
959 finz = *fin;
960 memset(&finz.hmac, 0, sizeof(finz.hmac));
961 calculate_hmac(&queue->in_hmac, &rekeyz, sizeof(rekeyz), &tmac);
962 if (0 != memcmp(&tmac, &fin->hmac, sizeof(tmac)))
963 {
964 GNUNET_break_op(0);
965 queue_finish(queue);
966 return 0;
967 }
968 /* handle FINISH by destroying queue */
969 queue_destroy(queue);
970 break;
971
972 default:
973 GNUNET_break_op(0);
974 queue_finish(queue);
976 return 0; 975 return 0;
977 } 976 }
978 /* handle FINISH by destroying queue */ 977 GNUNET_assert(0 != size);
979 queue_destroy (queue);
980 break;
981 default:
982 GNUNET_break_op (0);
983 queue_finish (queue);
984 return 0;
985 }
986 GNUNET_assert (0 != size);
987 return size; 978 return size;
988} 979}
989 980
@@ -994,96 +985,96 @@ try_handle_plaintext (struct Queue *queue)
994 * @param cls the `struct Queue *` to disconnect 985 * @param cls the `struct Queue *` to disconnect
995 */ 986 */
996static void 987static void
997queue_read (void *cls) 988queue_read(void *cls)
998{ 989{
999 struct Queue *queue = cls; 990 struct Queue *queue = cls;
1000 struct GNUNET_TIME_Relative left; 991 struct GNUNET_TIME_Relative left;
1001 ssize_t rcvd; 992 ssize_t rcvd;
1002 993
1003 queue->read_task = NULL; 994 queue->read_task = NULL;
1004 rcvd = GNUNET_NETWORK_socket_recv (queue->sock, 995 rcvd = GNUNET_NETWORK_socket_recv(queue->sock,
1005 &queue->cread_buf[queue->cread_off], 996 &queue->cread_buf[queue->cread_off],
1006 BUF_SIZE - queue->cread_off); 997 BUF_SIZE - queue->cread_off);
1007 if (-1 == rcvd) 998 if (-1 == rcvd)
1008 {
1009 if ((EAGAIN != errno) && (EINTR != errno))
1010 { 999 {
1011 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); 1000 if ((EAGAIN != errno) && (EINTR != errno))
1012 queue_finish (queue); 1001 {
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);
1013 return; 1009 return;
1014 } 1010 }
1015 /* try again */
1016 queue->read_task =
1017 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue);
1018 return;
1019 }
1020 if (0 != rcvd) 1011 if (0 != rcvd)
1021 reschedule_queue_timeout (queue); 1012 reschedule_queue_timeout(queue);
1022 queue->cread_off += rcvd; 1013 queue->cread_off += rcvd;
1023 while ((queue->pread_off < sizeof (queue->pread_buf)) && 1014 while ((queue->pread_off < sizeof(queue->pread_buf)) &&
1024 (queue->cread_off > 0)) 1015 (queue->cread_off > 0))
1025 { 1016 {
1026 size_t max = GNUNET_MIN (sizeof (queue->pread_buf) - queue->pread_off, 1017 size_t max = GNUNET_MIN(sizeof(queue->pread_buf) - queue->pread_off,
1027 queue->cread_off); 1018 queue->cread_off);
1028 size_t done; 1019 size_t done;
1029 size_t total; 1020 size_t total;
1030 1021
1031 GNUNET_assert (0 == 1022 GNUNET_assert(0 ==
1032 gcry_cipher_decrypt (queue->in_cipher, 1023 gcry_cipher_decrypt(queue->in_cipher,
1033 &queue->pread_buf[queue->pread_off], 1024 &queue->pread_buf[queue->pread_off],
1034 max, 1025 max,
1035 queue->cread_buf, 1026 queue->cread_buf,
1036 max)); 1027 max));
1037 queue->pread_off += max; 1028 queue->pread_off += max;
1038 total = 0; 1029 total = 0;
1039 while ((GNUNET_NO == queue->rekeyed) && 1030 while ((GNUNET_NO == queue->rekeyed) &&
1040 (0 != (done = try_handle_plaintext (queue)))) 1031 (0 != (done = try_handle_plaintext(queue))))
1041 { 1032 {
1042 /* 'done' bytes of plaintext were used, shift buffer */ 1033 /* 'done' bytes of plaintext were used, shift buffer */
1043 GNUNET_assert (done <= queue->pread_off); 1034 GNUNET_assert(done <= queue->pread_off);
1044 /* NOTE: this memmove() could possibly sometimes be 1035 /* NOTE: this memmove() could possibly sometimes be
1045 avoided if we pass 'total' into try_handle_plaintext() 1036 avoided if we pass 'total' into try_handle_plaintext()
1046 and use it at an offset into the buffer there! */ 1037 and use it at an offset into the buffer there! */
1047 memmove (queue->pread_buf, 1038 memmove(queue->pread_buf,
1048 &queue->pread_buf[done], 1039 &queue->pread_buf[done],
1049 queue->pread_off - done); 1040 queue->pread_off - done);
1050 queue->pread_off -= done; 1041 queue->pread_off -= done;
1051 total += done; 1042 total += done;
1052 } 1043 }
1053 /* when we encounter a rekey message, the decryption above uses the 1044 /* when we encounter a rekey message, the decryption above uses the
1054 wrong key for everything after the rekey; in that case, we have 1045 wrong key for everything after the rekey; in that case, we have
1055 to re-do the decryption at 'total' instead of at 'max'. If there 1046 to re-do the decryption at 'total' instead of at 'max'. If there
1056 is no rekey and the last message is incomplete (max > total), 1047 is no rekey and the last message is incomplete (max > total),
1057 it is safe to keep the decryption so we shift by 'max' */ 1048 it is safe to keep the decryption so we shift by 'max' */
1058 if (GNUNET_YES == queue->rekeyed) 1049 if (GNUNET_YES == queue->rekeyed)
1059 { 1050 {
1060 max = total; 1051 max = total;
1061 queue->rekeyed = GNUNET_NO; 1052 queue->rekeyed = GNUNET_NO;
1053 }
1054 memmove(queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1055 queue->cread_off -= max;
1062 } 1056 }
1063 memmove (queue->cread_buf, &queue->cread_buf[max], queue->cread_off - max);
1064 queue->cread_off -= max;
1065 }
1066 1057
1067 if (BUF_SIZE == queue->cread_off) 1058 if (BUF_SIZE == queue->cread_off)
1068 return; /* buffer full, suspend reading */ 1059 return; /* buffer full, suspend reading */
1069 left = GNUNET_TIME_absolute_get_remaining (queue->timeout); 1060 left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
1070 if (0 != left.rel_value_us) 1061 if (0 != left.rel_value_us)
1071 {
1072 if (max_queue_length < queue->backpressure)
1073 { 1062 {
1074 /* continue reading */ 1063 if (max_queue_length < queue->backpressure)
1075 queue->read_task = 1064 {
1076 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read, queue); 1065 /* continue reading */
1066 queue->read_task =
1067 GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read, queue);
1068 }
1069 return;
1077 } 1070 }
1078 return; 1071 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1079 } 1072 "Queue %p was idle for %s, disconnecting\n",
1080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1073 queue,
1081 "Queue %p was idle for %s, disconnecting\n", 1074 GNUNET_STRINGS_relative_time_to_string(
1082 queue, 1075 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1083 GNUNET_STRINGS_relative_time_to_string ( 1076 GNUNET_YES));
1084 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1077 queue_finish(queue);
1085 GNUNET_YES));
1086 queue_finish (queue);
1087} 1078}
1088 1079
1089 1080
@@ -1095,7 +1086,7 @@ queue_read (void *cls)
1095 * @return converted bindto specification 1086 * @return converted bindto specification
1096 */ 1087 */
1097static struct sockaddr * 1088static struct sockaddr *
1098tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) 1089tcp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1099{ 1090{
1100 struct sockaddr *in; 1091 struct sockaddr *in;
1101 unsigned int port; 1092 unsigned int port;
@@ -1103,88 +1094,88 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1103 char *colon; 1094 char *colon;
1104 char *cp; 1095 char *cp;
1105 1096
1106 if (1 == sscanf (bindto, "%u%1s", &port, dummy)) 1097 if (1 == sscanf(bindto, "%u%1s", &port, dummy))
1107 {
1108 /* interpreting value as just a PORT number */
1109 if (port > UINT16_MAX)
1110 {
1111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1112 "BINDTO specification `%s' invalid: value too large for port\n",
1113 bindto);
1114 return NULL;
1115 }
1116 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1117 (GNUNET_YES ==
1118 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1119 COMMUNICATOR_CONFIG_SECTION,
1120 "DISABLE_V6")))
1121 {
1122 struct sockaddr_in *i4;
1123
1124 i4 = GNUNET_malloc (sizeof (struct sockaddr_in));
1125 i4->sin_family = AF_INET;
1126 i4->sin_port = htons ((uint16_t) port);
1127 *sock_len = sizeof (struct sockaddr_in);
1128 in = (struct sockaddr *) i4;
1129 }
1130 else
1131 {
1132 struct sockaddr_in6 *i6;
1133
1134 i6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
1135 i6->sin6_family = AF_INET6;
1136 i6->sin6_port = htons ((uint16_t) port);
1137 *sock_len = sizeof (struct sockaddr_in6);
1138 in = (struct sockaddr *) i6;
1139 }
1140 return in;
1141 }
1142 cp = GNUNET_strdup (bindto);
1143 colon = strrchr (cp, ':');
1144 if (NULL != colon)
1145 {
1146 /* interpet value after colon as port */
1147 *colon = '\0';
1148 colon++;
1149 if (1 == sscanf (colon, "%u%1s", &port, dummy))
1150 { 1098 {
1151 /* interpreting value as just a PORT number */ 1099 /* interpreting value as just a PORT number */
1152 if (port > UINT16_MAX) 1100 if (port > UINT16_MAX)
1153 { 1101 {
1154 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1102 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1155 "BINDTO specification `%s' invalid: value too large for port\n", 1103 "BINDTO specification `%s' invalid: value too large for port\n",
1156 bindto); 1104 bindto);
1157 GNUNET_free (cp); 1105 return NULL;
1158 return NULL; 1106 }
1159 } 1107 if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) ||
1108 (GNUNET_YES ==
1109 GNUNET_CONFIGURATION_get_value_yesno(cfg,
1110 COMMUNICATOR_CONFIG_SECTION,
1111 "DISABLE_V6")))
1112 {
1113 struct sockaddr_in *i4;
1114
1115 i4 = GNUNET_malloc(sizeof(struct sockaddr_in));
1116 i4->sin_family = AF_INET;
1117 i4->sin_port = htons((uint16_t)port);
1118 *sock_len = sizeof(struct sockaddr_in);
1119 in = (struct sockaddr *)i4;
1120 }
1121 else
1122 {
1123 struct sockaddr_in6 *i6;
1124
1125 i6 = GNUNET_malloc(sizeof(struct sockaddr_in6));
1126 i6->sin6_family = AF_INET6;
1127 i6->sin6_port = htons((uint16_t)port);
1128 *sock_len = sizeof(struct sockaddr_in6);
1129 in = (struct sockaddr *)i6;
1130 }
1131 return in;
1160 } 1132 }
1161 else 1133 cp = GNUNET_strdup(bindto);
1134 colon = strrchr(cp, ':');
1135 if (NULL != colon)
1162 { 1136 {
1163 GNUNET_log ( 1137 /* interpet value after colon as port */
1164 GNUNET_ERROR_TYPE_ERROR, 1138 *colon = '\0';
1165 "BINDTO specification `%s' invalid: last ':' not followed by number\n", 1139 colon++;
1166 bindto); 1140 if (1 == sscanf(colon, "%u%1s", &port, dummy))
1167 GNUNET_free (cp); 1141 {
1168 return NULL; 1142 /* interpreting value as just a PORT number */
1143 if (port > UINT16_MAX)
1144 {
1145 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
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 }
1169 } 1161 }
1170 }
1171 else 1162 else
1172 { 1163 {
1173 /* interpret missing port as 0, aka pick any free one */ 1164 /* interpret missing port as 0, aka pick any free one */
1174 port = 0; 1165 port = 0;
1175 } 1166 }
1176 { 1167 {
1177 /* try IPv4 */ 1168 /* try IPv4 */
1178 struct sockaddr_in v4; 1169 struct sockaddr_in v4;
1179 1170
1180 if (1 == inet_pton (AF_INET, cp, &v4)) 1171 if (1 == inet_pton(AF_INET, cp, &v4))
1181 { 1172 {
1182 v4.sin_port = htons ((uint16_t) port); 1173 v4.sin_port = htons((uint16_t)port);
1183 in = GNUNET_memdup (&v4, sizeof (v4)); 1174 in = GNUNET_memdup(&v4, sizeof(v4));
1184 *sock_len = sizeof (v4); 1175 *sock_len = sizeof(v4);
1185 GNUNET_free (cp); 1176 GNUNET_free(cp);
1186 return in; 1177 return in;
1187 } 1178 }
1188 } 1179 }
1189 { 1180 {
1190 /* try IPv6 */ 1181 /* try IPv6 */
@@ -1192,22 +1183,22 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1192 const char *start; 1183 const char *start;
1193 1184
1194 start = cp; 1185 start = cp;
1195 if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) 1186 if (('[' == *cp) && (']' == cp[strlen(cp) - 1]))
1196 { 1187 {
1197 start++; /* skip over '[' */ 1188 start++; /* skip over '[' */
1198 cp[strlen (cp) - 1] = '\0'; /* eat ']' */ 1189 cp[strlen(cp) - 1] = '\0'; /* eat ']' */
1199 } 1190 }
1200 if (1 == inet_pton (AF_INET6, start, &v6)) 1191 if (1 == inet_pton(AF_INET6, start, &v6))
1201 { 1192 {
1202 v6.sin6_port = htons ((uint16_t) port); 1193 v6.sin6_port = htons((uint16_t)port);
1203 in = GNUNET_memdup (&v6, sizeof (v6)); 1194 in = GNUNET_memdup(&v6, sizeof(v6));
1204 *sock_len = sizeof (v6); 1195 *sock_len = sizeof(v6);
1205 GNUNET_free (cp); 1196 GNUNET_free(cp);
1206 return in; 1197 return in;
1207 } 1198 }
1208 } 1199 }
1209 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ 1200 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1210 GNUNET_free (cp); 1201 GNUNET_free(cp);
1211 return NULL; 1202 return NULL;
1212} 1203}
1213 1204
@@ -1219,17 +1210,17 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1219 * @param queue queue to setup outgoing (encryption) cipher for 1210 * @param queue queue to setup outgoing (encryption) cipher for
1220 */ 1211 */
1221static void 1212static void
1222setup_out_cipher (struct Queue *queue) 1213setup_out_cipher(struct Queue *queue)
1223{ 1214{
1224 struct GNUNET_HashCode dh; 1215 struct GNUNET_HashCode dh;
1225 1216
1226 GNUNET_CRYPTO_ecdh_eddsa (&queue->ephemeral, &queue->target.public_key, &dh); 1217 GNUNET_CRYPTO_ecdh_eddsa(&queue->ephemeral, &queue->target.public_key, &dh);
1227 /* we don't need the private key anymore, drop it! */ 1218 /* we don't need the private key anymore, drop it! */
1228 memset (&queue->ephemeral, 0, sizeof (queue->ephemeral)); 1219 memset(&queue->ephemeral, 0, sizeof(queue->ephemeral));
1229 setup_cipher (&dh, &queue->target, &queue->out_cipher, &queue->out_hmac); 1220 setup_cipher(&dh, &queue->target, &queue->out_cipher, &queue->out_hmac);
1230 queue->rekey_time = GNUNET_TIME_relative_to_absolute (REKEY_TIME_INTERVAL); 1221 queue->rekey_time = GNUNET_TIME_relative_to_absolute(REKEY_TIME_INTERVAL);
1231 queue->rekey_left_bytes = 1222 queue->rekey_left_bytes =
1232 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES); 1223 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, REKEY_MAX_BYTES);
1233} 1224}
1234 1225
1235 1226
@@ -1240,32 +1231,32 @@ setup_out_cipher (struct Queue *queue)
1240 * @param queue queue to perform rekeying on 1231 * @param queue queue to perform rekeying on
1241 */ 1232 */
1242static void 1233static void
1243inject_rekey (struct Queue *queue) 1234inject_rekey(struct Queue *queue)
1244{ 1235{
1245 struct TCPRekey rekey; 1236 struct TCPRekey rekey;
1246 struct TcpHandshakeSignature thp; 1237 struct TcpHandshakeSignature thp;
1247 1238
1248 GNUNET_assert (0 == queue->pwrite_off); 1239 GNUNET_assert(0 == queue->pwrite_off);
1249 memset (&rekey, 0, sizeof (rekey)); 1240 memset(&rekey, 0, sizeof(rekey));
1250 GNUNET_assert (GNUNET_OK == 1241 GNUNET_assert(GNUNET_OK ==
1251 GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); 1242 GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral));
1252 rekey.header.type = ntohs (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY); 1243 rekey.header.type = ntohs(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_REKEY);
1253 rekey.header.size = ntohs (sizeof (rekey)); 1244 rekey.header.size = ntohs(sizeof(rekey));
1254 GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &rekey.ephemeral); 1245 GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &rekey.ephemeral);
1255 rekey.monotonic_time = 1246 rekey.monotonic_time =
1256 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); 1247 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg));
1257 thp.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY); 1248 thp.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_REKEY);
1258 thp.purpose.size = htonl (sizeof (thp)); 1249 thp.purpose.size = htonl(sizeof(thp));
1259 thp.sender = my_identity; 1250 thp.sender = my_identity;
1260 thp.receiver = queue->target; 1251 thp.receiver = queue->target;
1261 thp.ephemeral = rekey.ephemeral; 1252 thp.ephemeral = rekey.ephemeral;
1262 thp.monotonic_time = rekey.monotonic_time; 1253 thp.monotonic_time = rekey.monotonic_time;
1263 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, 1254 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key,
1264 &thp.purpose, 1255 &thp.purpose,
1265 &rekey.sender_sig)); 1256 &rekey.sender_sig));
1266 calculate_hmac (&queue->out_hmac, &rekey, sizeof (rekey), &rekey.hmac); 1257 calculate_hmac(&queue->out_hmac, &rekey, sizeof(rekey), &rekey.hmac);
1267 memcpy (queue->pwrite_buf, &rekey, sizeof (rekey)); 1258 memcpy(queue->pwrite_buf, &rekey, sizeof(rekey));
1268 queue->pwrite_off = sizeof (rekey); 1259 queue->pwrite_off = sizeof(rekey);
1269} 1260}
1270 1261
1271 1262
@@ -1276,79 +1267,79 @@ inject_rekey (struct Queue *queue)
1276 * @param cls a `struct Queue` 1267 * @param cls a `struct Queue`
1277 */ 1268 */
1278static void 1269static void
1279queue_write (void *cls) 1270queue_write(void *cls)
1280{ 1271{
1281 struct Queue *queue = cls; 1272 struct Queue *queue = cls;
1282 ssize_t sent; 1273 ssize_t sent;
1283 1274
1284 queue->write_task = NULL; 1275 queue->write_task = NULL;
1285 if (0 != queue->cwrite_off) 1276 if (0 != queue->cwrite_off)
1286 {
1287 sent = GNUNET_NETWORK_socket_send (queue->sock,
1288 queue->cwrite_buf,
1289 queue->cwrite_off);
1290 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1291 { 1277 {
1292 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 1278 sent = GNUNET_NETWORK_socket_send(queue->sock,
1293 queue_destroy (queue); 1279 queue->cwrite_buf,
1294 return; 1280 queue->cwrite_off);
1281 if ((-1 == sent) && (EAGAIN != errno) && (EINTR != errno))
1282 {
1283 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send");
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 }
1295 } 1296 }
1296 if (sent > 0)
1297 {
1298 size_t usent = (size_t) sent;
1299
1300 memmove (queue->cwrite_buf,
1301 &queue->cwrite_buf[usent],
1302 queue->cwrite_off - usent);
1303 reschedule_queue_timeout (queue);
1304 }
1305 }
1306 /* can we encrypt more? (always encrypt full messages, needed 1297 /* can we encrypt more? (always encrypt full messages, needed
1307 such that #mq_cancel() can work!) */ 1298 such that #mq_cancel() can work!) */
1308 if ((0 < queue->rekey_left_bytes) && 1299 if ((0 < queue->rekey_left_bytes) &&
1309 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE)) 1300 (queue->cwrite_off + queue->pwrite_off <= BUF_SIZE))
1310 { 1301 {
1311 GNUNET_assert (0 == 1302 GNUNET_assert(0 ==
1312 gcry_cipher_encrypt (queue->out_cipher, 1303 gcry_cipher_encrypt(queue->out_cipher,
1313 &queue->cwrite_buf[queue->cwrite_off], 1304 &queue->cwrite_buf[queue->cwrite_off],
1314 queue->pwrite_off, 1305 queue->pwrite_off,
1315 queue->pwrite_buf, 1306 queue->pwrite_buf,
1316 queue->pwrite_off)); 1307 queue->pwrite_off));
1317 if (queue->rekey_left_bytes > queue->pwrite_off) 1308 if (queue->rekey_left_bytes > queue->pwrite_off)
1318 queue->rekey_left_bytes -= queue->pwrite_off; 1309 queue->rekey_left_bytes -= queue->pwrite_off;
1319 else 1310 else
1320 queue->rekey_left_bytes = 0; 1311 queue->rekey_left_bytes = 0;
1321 queue->cwrite_off += queue->pwrite_off; 1312 queue->cwrite_off += queue->pwrite_off;
1322 queue->pwrite_off = 0; 1313 queue->pwrite_off = 0;
1323 } 1314 }
1324 if ((0 == queue->pwrite_off) && 1315 if ((0 == queue->pwrite_off) &&
1325 ((0 == queue->rekey_left_bytes) || 1316 ((0 == queue->rekey_left_bytes) ||
1326 (0 == 1317 (0 ==
1327 GNUNET_TIME_absolute_get_remaining (queue->rekey_time).rel_value_us))) 1318 GNUNET_TIME_absolute_get_remaining(queue->rekey_time).rel_value_us)))
1328 { 1319 {
1329 gcry_cipher_close (queue->out_cipher); 1320 gcry_cipher_close(queue->out_cipher);
1330 setup_out_cipher (queue); 1321 setup_out_cipher(queue);
1331 inject_rekey (queue); 1322 inject_rekey(queue);
1332 } 1323 }
1333 if ((0 == queue->pwrite_off) && (! queue->finishing) && 1324 if ((0 == queue->pwrite_off) && (!queue->finishing) &&
1334 (queue->mq_awaits_continue)) 1325 (queue->mq_awaits_continue))
1335 { 1326 {
1336 queue->mq_awaits_continue = GNUNET_NO; 1327 queue->mq_awaits_continue = GNUNET_NO;
1337 GNUNET_MQ_impl_send_continue (queue->mq); 1328 GNUNET_MQ_impl_send_continue(queue->mq);
1338 } 1329 }
1339 /* did we just finish writing 'finish'? */ 1330 /* did we just finish writing 'finish'? */
1340 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing)) 1331 if ((0 == queue->cwrite_off) && (GNUNET_YES == queue->finishing))
1341 { 1332 {
1342 queue_destroy (queue); 1333 queue_destroy(queue);
1343 return; 1334 return;
1344 } 1335 }
1345 /* do we care to write more? */ 1336 /* do we care to write more? */
1346 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off)) 1337 if ((0 < queue->cwrite_off) || (0 < queue->pwrite_off))
1347 queue->write_task = 1338 queue->write_task =
1348 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1339 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
1349 queue->sock, 1340 queue->sock,
1350 &queue_write, 1341 &queue_write,
1351 queue); 1342 queue);
1352} 1343}
1353 1344
1354 1345
@@ -1361,32 +1352,32 @@ queue_write (void *cls)
1361 * @param impl_state our `struct Queue` 1352 * @param impl_state our `struct Queue`
1362 */ 1353 */
1363static void 1354static void
1364mq_send (struct GNUNET_MQ_Handle *mq, 1355mq_send(struct GNUNET_MQ_Handle *mq,
1365 const struct GNUNET_MessageHeader *msg, 1356 const struct GNUNET_MessageHeader *msg,
1366 void *impl_state) 1357 void *impl_state)
1367{ 1358{
1368 struct Queue *queue = impl_state; 1359 struct Queue *queue = impl_state;
1369 uint16_t msize = ntohs (msg->size); 1360 uint16_t msize = ntohs(msg->size);
1370 struct TCPBox box; 1361 struct TCPBox box;
1371 1362
1372 GNUNET_assert (mq == queue->mq); 1363 GNUNET_assert(mq == queue->mq);
1373 if (GNUNET_YES == queue->finishing) 1364 if (GNUNET_YES == queue->finishing)
1374 return; /* this queue is dying, drop msg */ 1365 return; /* this queue is dying, drop msg */
1375 GNUNET_assert (0 == queue->pread_off); 1366 GNUNET_assert(0 == queue->pread_off);
1376 box.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX); 1367 box.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_TCP_BOX);
1377 box.header.size = htons (msize); 1368 box.header.size = htons(msize);
1378 calculate_hmac (&queue->out_hmac, msg, msize, &box.hmac); 1369 calculate_hmac(&queue->out_hmac, msg, msize, &box.hmac);
1379 memcpy (&queue->pread_buf[queue->pread_off], &box, sizeof (box)); 1370 memcpy(&queue->pread_buf[queue->pread_off], &box, sizeof(box));
1380 queue->pread_off += sizeof (box); 1371 queue->pread_off += sizeof(box);
1381 memcpy (&queue->pread_buf[queue->pread_off], msg, msize); 1372 memcpy(&queue->pread_buf[queue->pread_off], msg, msize);
1382 queue->pread_off += msize; 1373 queue->pread_off += msize;
1383 GNUNET_assert (NULL != queue->sock); 1374 GNUNET_assert(NULL != queue->sock);
1384 if (NULL == queue->write_task) 1375 if (NULL == queue->write_task)
1385 queue->write_task = 1376 queue->write_task =
1386 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1377 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
1387 queue->sock, 1378 queue->sock,
1388 &queue_write, 1379 &queue_write,
1389 queue); 1380 queue);
1390} 1381}
1391 1382
1392 1383
@@ -1399,15 +1390,15 @@ mq_send (struct GNUNET_MQ_Handle *mq,
1399 * @param impl_state our `struct Queue` 1390 * @param impl_state our `struct Queue`
1400 */ 1391 */
1401static void 1392static void
1402mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) 1393mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
1403{ 1394{
1404 struct Queue *queue = impl_state; 1395 struct Queue *queue = impl_state;
1405 1396
1406 if (mq == queue->mq) 1397 if (mq == queue->mq)
1407 { 1398 {
1408 queue->mq = NULL; 1399 queue->mq = NULL;
1409 queue_finish (queue); 1400 queue_finish(queue);
1410 } 1401 }
1411} 1402}
1412 1403
1413 1404
@@ -1418,11 +1409,11 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
1418 * @param impl_state our `struct Queue` 1409 * @param impl_state our `struct Queue`
1419 */ 1410 */
1420static void 1411static void
1421mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) 1412mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
1422{ 1413{
1423 struct Queue *queue = impl_state; 1414 struct Queue *queue = impl_state;
1424 1415
1425 GNUNET_assert (0 != queue->pwrite_off); 1416 GNUNET_assert(0 != queue->pwrite_off);
1426 queue->pwrite_off = 0; 1417 queue->pwrite_off = 0;
1427} 1418}
1428 1419
@@ -1437,15 +1428,15 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
1437 * @param error error code 1428 * @param error error code
1438 */ 1429 */
1439static void 1430static void
1440mq_error (void *cls, enum GNUNET_MQ_Error error) 1431mq_error(void *cls, enum GNUNET_MQ_Error error)
1441{ 1432{
1442 struct Queue *queue = cls; 1433 struct Queue *queue = cls;
1443 1434
1444 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1435 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1445 "MQ error in queue to %s: %d\n", 1436 "MQ error in queue to %s: %d\n",
1446 GNUNET_i2s (&queue->target), 1437 GNUNET_i2s(&queue->target),
1447 (int) error); 1438 (int)error);
1448 queue_finish (queue); 1439 queue_finish(queue);
1449} 1440}
1450 1441
1451 1442
@@ -1457,56 +1448,58 @@ mq_error (void *cls, enum GNUNET_MQ_Error error)
1457 * @param queue queue to boot 1448 * @param queue queue to boot
1458 */ 1449 */
1459static void 1450static void
1460boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs) 1451boot_queue(struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
1461{ 1452{
1462 queue->nt = 1453 queue->nt =
1463 GNUNET_NT_scanner_get_type (is, queue->address, queue->address_len); 1454 GNUNET_NT_scanner_get_type(is, queue->address, queue->address_len);
1464 (void) GNUNET_CONTAINER_multipeermap_put ( 1455 (void)GNUNET_CONTAINER_multipeermap_put(
1465 queue_map, 1456 queue_map,
1466 &queue->target, 1457 &queue->target,
1467 queue, 1458 queue,
1468 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1459 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1469 GNUNET_STATISTICS_set (stats, 1460 GNUNET_STATISTICS_set(stats,
1470 "# queues active", 1461 "# queues active",
1471 GNUNET_CONTAINER_multipeermap_size (queue_map), 1462 GNUNET_CONTAINER_multipeermap_size(queue_map),
1472 GNUNET_NO); 1463 GNUNET_NO);
1473 queue->timeout = 1464 queue->timeout =
1474 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1465 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1475 queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, 1466 queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send,
1476 &mq_destroy, 1467 &mq_destroy,
1477 &mq_cancel, 1468 &mq_cancel,
1478 queue, 1469 queue,
1479 NULL, 1470 NULL,
1480 &mq_error, 1471 &mq_error,
1481 queue); 1472 queue);
1482 { 1473 {
1483 char *foreign_addr; 1474 char *foreign_addr;
1484 1475
1485 switch (queue->address->sa_family) 1476 switch (queue->address->sa_family)
1486 { 1477 {
1487 case AF_INET: 1478 case AF_INET:
1488 GNUNET_asprintf (&foreign_addr, 1479 GNUNET_asprintf(&foreign_addr,
1489 "%s-%s", 1480 "%s-%s",
1490 COMMUNICATOR_ADDRESS_PREFIX, 1481 COMMUNICATOR_ADDRESS_PREFIX,
1491 GNUNET_a2s (queue->address, queue->address_len)); 1482 GNUNET_a2s(queue->address, queue->address_len));
1492 break; 1483 break;
1493 case AF_INET6: 1484
1494 GNUNET_asprintf (&foreign_addr, 1485 case AF_INET6:
1495 "%s-%s", 1486 GNUNET_asprintf(&foreign_addr,
1496 COMMUNICATOR_ADDRESS_PREFIX, 1487 "%s-%s",
1497 GNUNET_a2s (queue->address, queue->address_len)); 1488 COMMUNICATOR_ADDRESS_PREFIX,
1498 break; 1489 GNUNET_a2s(queue->address, queue->address_len));
1499 default: 1490 break;
1500 GNUNET_assert (0); 1491
1501 } 1492 default:
1502 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, 1493 GNUNET_assert(0);
1503 &queue->target, 1494 }
1504 foreign_addr, 1495 queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch,
1505 0 /* no MTU */, 1496 &queue->target,
1506 queue->nt, 1497 foreign_addr,
1507 cs, 1498 0 /* no MTU */,
1508 queue->mq); 1499 queue->nt,
1509 GNUNET_free (foreign_addr); 1500 cs,
1501 queue->mq);
1502 GNUNET_free(foreign_addr);
1510 } 1503 }
1511} 1504}
1512 1505
@@ -1522,34 +1515,34 @@ boot_queue (struct Queue *queue, enum GNUNET_TRANSPORT_ConnectionStatus cs)
1522 * @param epub our public key for the KX 1515 * @param epub our public key for the KX
1523 */ 1516 */
1524static void 1517static void
1525transmit_kx (struct Queue *queue, 1518transmit_kx(struct Queue *queue,
1526 const struct GNUNET_CRYPTO_EcdhePublicKey *epub) 1519 const struct GNUNET_CRYPTO_EcdhePublicKey *epub)
1527{ 1520{
1528 struct TcpHandshakeSignature ths; 1521 struct TcpHandshakeSignature ths;
1529 struct TCPConfirmation tc; 1522 struct TCPConfirmation tc;
1530 1523
1531 memcpy (queue->cwrite_buf, epub, sizeof (*epub)); 1524 memcpy(queue->cwrite_buf, epub, sizeof(*epub));
1532 queue->cwrite_off = sizeof (epub); 1525 queue->cwrite_off = sizeof(epub);
1533 /* compute 'tc' and append in encrypted format to cwrite_buf */ 1526 /* compute 'tc' and append in encrypted format to cwrite_buf */
1534 tc.sender = my_identity; 1527 tc.sender = my_identity;
1535 tc.monotonic_time = 1528 tc.monotonic_time =
1536 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); 1529 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg));
1537 ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); 1530 ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1538 ths.purpose.size = htonl (sizeof (ths)); 1531 ths.purpose.size = htonl(sizeof(ths));
1539 ths.sender = my_identity; 1532 ths.sender = my_identity;
1540 ths.receiver = queue->target; 1533 ths.receiver = queue->target;
1541 ths.ephemeral = *epub; 1534 ths.ephemeral = *epub;
1542 ths.monotonic_time = tc.monotonic_time; 1535 ths.monotonic_time = tc.monotonic_time;
1543 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, 1536 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key,
1544 &ths.purpose, 1537 &ths.purpose,
1545 &tc.sender_sig)); 1538 &tc.sender_sig));
1546 GNUNET_assert (0 == 1539 GNUNET_assert(0 ==
1547 gcry_cipher_encrypt (queue->out_cipher, 1540 gcry_cipher_encrypt(queue->out_cipher,
1548 &queue->cwrite_buf[queue->cwrite_off], 1541 &queue->cwrite_buf[queue->cwrite_off],
1549 sizeof (tc), 1542 sizeof(tc),
1550 &tc, 1543 &tc,
1551 sizeof (tc))); 1544 sizeof(tc)));
1552 queue->cwrite_off += sizeof (tc); 1545 queue->cwrite_off += sizeof(tc);
1553} 1546}
1554 1547
1555 1548
@@ -1561,15 +1554,15 @@ transmit_kx (struct Queue *queue,
1561 * @param queue the queue to setup 1554 * @param queue the queue to setup
1562 */ 1555 */
1563static void 1556static void
1564start_initial_kx_out (struct Queue *queue) 1557start_initial_kx_out(struct Queue *queue)
1565{ 1558{
1566 struct GNUNET_CRYPTO_EcdhePublicKey epub; 1559 struct GNUNET_CRYPTO_EcdhePublicKey epub;
1567 1560
1568 GNUNET_assert (GNUNET_OK == 1561 GNUNET_assert(GNUNET_OK ==
1569 GNUNET_CRYPTO_ecdhe_key_create2 (&queue->ephemeral)); 1562 GNUNET_CRYPTO_ecdhe_key_create2(&queue->ephemeral));
1570 GNUNET_CRYPTO_ecdhe_key_get_public (&queue->ephemeral, &epub); 1563 GNUNET_CRYPTO_ecdhe_key_get_public(&queue->ephemeral, &epub);
1571 setup_out_cipher (queue); 1564 setup_out_cipher(queue);
1572 transmit_kx (queue, &epub); 1565 transmit_kx(queue, &epub);
1573} 1566}
1574 1567
1575 1568
@@ -1585,31 +1578,31 @@ start_initial_kx_out (struct Queue *queue)
1585 * @return #GNUNET_OK if the signature was OK, #GNUNET_SYSERR if not 1578 * @return #GNUNET_OK if the signature was OK, #GNUNET_SYSERR if not
1586 */ 1579 */
1587static int 1580static int
1588decrypt_and_check_tc (struct Queue *queue, 1581decrypt_and_check_tc(struct Queue *queue,
1589 struct TCPConfirmation *tc, 1582 struct TCPConfirmation *tc,
1590 char *ibuf) 1583 char *ibuf)
1591{ 1584{
1592 struct TcpHandshakeSignature ths; 1585 struct TcpHandshakeSignature ths;
1593 1586
1594 GNUNET_assert ( 1587 GNUNET_assert(
1595 0 == 1588 0 ==
1596 gcry_cipher_decrypt (queue->in_cipher, 1589 gcry_cipher_decrypt(queue->in_cipher,
1597 tc, 1590 tc,
1598 sizeof (*tc), 1591 sizeof(*tc),
1599 &ibuf[sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)], 1592 &ibuf[sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)],
1600 sizeof (tc))); 1593 sizeof(tc)));
1601 ths.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE); 1594 ths.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE);
1602 ths.purpose.size = htonl (sizeof (ths)); 1595 ths.purpose.size = htonl(sizeof(ths));
1603 ths.sender = tc->sender; 1596 ths.sender = tc->sender;
1604 ths.receiver = my_identity; 1597 ths.receiver = my_identity;
1605 memcpy (&ths.ephemeral, ibuf, sizeof (struct GNUNET_CRYPTO_EcdhePublicKey)); 1598 memcpy(&ths.ephemeral, ibuf, sizeof(struct GNUNET_CRYPTO_EcdhePublicKey));
1606 ths.monotonic_time = tc->monotonic_time; 1599 ths.monotonic_time = tc->monotonic_time;
1607 /* FIXME: check monotonic time against previous mono times 1600 /* FIXME: check monotonic time against previous mono times
1608 from this sender! */ 1601 from this sender! */
1609 return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE, 1602 return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_TCP_HANDSHAKE,
1610 &ths.purpose, 1603 &ths.purpose,
1611 &tc->sender_sig, 1604 &tc->sender_sig,
1612 &tc->sender.public_key); 1605 &tc->sender.public_key);
1613} 1606}
1614 1607
1615 1608
@@ -1619,12 +1612,12 @@ decrypt_and_check_tc (struct Queue *queue,
1619 * @param pq proto queue to free 1612 * @param pq proto queue to free
1620 */ 1613 */
1621static void 1614static void
1622free_proto_queue (struct ProtoQueue *pq) 1615free_proto_queue(struct ProtoQueue *pq)
1623{ 1616{
1624 GNUNET_NETWORK_socket_close (pq->sock); 1617 GNUNET_NETWORK_socket_close(pq->sock);
1625 GNUNET_free (pq->address); 1618 GNUNET_free(pq->address);
1626 GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq); 1619 GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq);
1627 GNUNET_free (pq); 1620 GNUNET_free(pq);
1628} 1621}
1629 1622
1630 1623
@@ -1635,7 +1628,7 @@ free_proto_queue (struct ProtoQueue *pq)
1635 * @param cls a `struct ProtoQueue` 1628 * @param cls a `struct ProtoQueue`
1636 */ 1629 */
1637static void 1630static void
1638proto_read_kx (void *cls) 1631proto_read_kx(void *cls)
1639{ 1632{
1640 struct ProtoQueue *pq = cls; 1633 struct ProtoQueue *pq = cls;
1641 ssize_t rcvd; 1634 ssize_t rcvd;
@@ -1644,67 +1637,67 @@ proto_read_kx (void *cls)
1644 struct TCPConfirmation tc; 1637 struct TCPConfirmation tc;
1645 1638
1646 pq->read_task = NULL; 1639 pq->read_task = NULL;
1647 left = GNUNET_TIME_absolute_get_remaining (pq->timeout); 1640 left = GNUNET_TIME_absolute_get_remaining(pq->timeout);
1648 if (0 == left.rel_value_us) 1641 if (0 == left.rel_value_us)
1649 { 1642 {
1650 free_proto_queue (pq); 1643 free_proto_queue(pq);
1651 return; 1644 return;
1652 } 1645 }
1653 rcvd = GNUNET_NETWORK_socket_recv (pq->sock, 1646 rcvd = GNUNET_NETWORK_socket_recv(pq->sock,
1654 &pq->ibuf[pq->ibuf_off], 1647 &pq->ibuf[pq->ibuf_off],
1655 sizeof (pq->ibuf) - pq->ibuf_off); 1648 sizeof(pq->ibuf) - pq->ibuf_off);
1656 if (-1 == rcvd) 1649 if (-1 == rcvd)
1657 {
1658 if ((EAGAIN != errno) && (EINTR != errno))
1659 { 1650 {
1660 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); 1651 if ((EAGAIN != errno) && (EINTR != errno))
1661 free_proto_queue (pq); 1652 {
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);
1662 return; 1660 return;
1663 } 1661 }
1664 /* try again */
1665 pq->read_task =
1666 GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq);
1667 return;
1668 }
1669 pq->ibuf_off += rcvd; 1662 pq->ibuf_off += rcvd;
1670 if (pq->ibuf_off > sizeof (pq->ibuf)) 1663 if (pq->ibuf_off > sizeof(pq->ibuf))
1671 { 1664 {
1672 /* read more */ 1665 /* read more */
1673 pq->read_task = 1666 pq->read_task =
1674 GNUNET_SCHEDULER_add_read_net (left, pq->sock, &proto_read_kx, pq); 1667 GNUNET_SCHEDULER_add_read_net(left, pq->sock, &proto_read_kx, pq);
1675 return; 1668 return;
1676 } 1669 }
1677 /* we got all the data, let's find out who we are talking to! */ 1670 /* we got all the data, let's find out who we are talking to! */
1678 queue = GNUNET_new (struct Queue); 1671 queue = GNUNET_new(struct Queue);
1679 setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) pq->ibuf, 1672 setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *)pq->ibuf,
1680 queue); 1673 queue);
1681 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, pq->ibuf)) 1674 if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, pq->ibuf))
1682 { 1675 {
1683 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1676 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1684 "Invalid TCP KX received from %s\n", 1677 "Invalid TCP KX received from %s\n",
1685 GNUNET_a2s (queue->address, queue->address_len)); 1678 GNUNET_a2s(queue->address, queue->address_len));
1686 gcry_cipher_close (queue->in_cipher); 1679 gcry_cipher_close(queue->in_cipher);
1687 GNUNET_free (queue); 1680 GNUNET_free(queue);
1688 free_proto_queue (pq); 1681 free_proto_queue(pq);
1689 return; 1682 return;
1690 } 1683 }
1691 queue->address = pq->address; /* steals reference */ 1684 queue->address = pq->address; /* steals reference */
1692 queue->address_len = pq->address_len; 1685 queue->address_len = pq->address_len;
1693 queue->target = tc.sender; 1686 queue->target = tc.sender;
1694 start_initial_kx_out (queue); 1687 start_initial_kx_out(queue);
1695 boot_queue (queue, GNUNET_TRANSPORT_CS_INBOUND); 1688 boot_queue(queue, GNUNET_TRANSPORT_CS_INBOUND);
1696 queue->read_task = 1689 queue->read_task =
1697 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1690 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,
1698 queue->sock, 1696 queue->sock,
1699 &queue_read, 1697 &queue_write,
1700 queue); 1698 queue);
1701 queue->write_task = 1699 GNUNET_CONTAINER_DLL_remove(proto_head, proto_tail, pq);
1702 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1700 GNUNET_free(pq);
1703 queue->sock,
1704 &queue_write,
1705 queue);
1706 GNUNET_CONTAINER_DLL_remove (proto_head, proto_tail, pq);
1707 GNUNET_free (pq);
1708} 1701}
1709 1702
1710 1703
@@ -1716,7 +1709,7 @@ proto_read_kx (void *cls)
1716 * @param cls NULL 1709 * @param cls NULL
1717 */ 1710 */
1718static void 1711static void
1719listen_cb (void *cls) 1712listen_cb(void *cls)
1720{ 1713{
1721 struct sockaddr_storage in; 1714 struct sockaddr_storage in;
1722 socklen_t addrlen; 1715 socklen_t addrlen;
@@ -1724,35 +1717,35 @@ listen_cb (void *cls)
1724 struct ProtoQueue *pq; 1717 struct ProtoQueue *pq;
1725 1718
1726 listen_task = NULL; 1719 listen_task = NULL;
1727 GNUNET_assert (NULL != listen_sock); 1720 GNUNET_assert(NULL != listen_sock);
1728 addrlen = sizeof (in); 1721 addrlen = sizeof(in);
1729 memset (&in, 0, sizeof (in)); 1722 memset(&in, 0, sizeof(in));
1730 sock = GNUNET_NETWORK_socket_accept (listen_sock, 1723 sock = GNUNET_NETWORK_socket_accept(listen_sock,
1731 (struct sockaddr *) &in, 1724 (struct sockaddr *)&in,
1732 &addrlen); 1725 &addrlen);
1733 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno))) 1726 if ((NULL == sock) && ((EMFILE == errno) || (ENFILE == errno)))
1734 return; /* system limit reached, wait until connection goes down */ 1727 return; /* system limit reached, wait until connection goes down */
1735 listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1728 listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
1736 listen_sock, 1729 listen_sock,
1737 &listen_cb, 1730 &listen_cb,
1738 NULL); 1731 NULL);
1739 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno))) 1732 if ((NULL == sock) && ((EAGAIN == errno) || (ENOBUFS == errno)))
1740 return; 1733 return;
1741 if (NULL == sock) 1734 if (NULL == sock)
1742 { 1735 {
1743 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); 1736 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "accept");
1744 return; 1737 return;
1745 } 1738 }
1746 pq = GNUNET_new (struct ProtoQueue); 1739 pq = GNUNET_new(struct ProtoQueue);
1747 pq->address_len = addrlen; 1740 pq->address_len = addrlen;
1748 pq->address = GNUNET_memdup (&in, addrlen); 1741 pq->address = GNUNET_memdup(&in, addrlen);
1749 pq->timeout = GNUNET_TIME_relative_to_absolute (PROTO_QUEUE_TIMEOUT); 1742 pq->timeout = GNUNET_TIME_relative_to_absolute(PROTO_QUEUE_TIMEOUT);
1750 pq->sock = sock; 1743 pq->sock = sock;
1751 pq->read_task = GNUNET_SCHEDULER_add_read_net (PROTO_QUEUE_TIMEOUT, 1744 pq->read_task = GNUNET_SCHEDULER_add_read_net(PROTO_QUEUE_TIMEOUT,
1752 pq->sock, 1745 pq->sock,
1753 &proto_read_kx, 1746 &proto_read_kx,
1754 pq); 1747 pq);
1755 GNUNET_CONTAINER_DLL_insert (proto_head, proto_tail, pq); 1748 GNUNET_CONTAINER_DLL_insert(proto_head, proto_tail, pq);
1756} 1749}
1757 1750
1758 1751
@@ -1764,7 +1757,7 @@ listen_cb (void *cls)
1764 * @param cls a `struct Queue` 1757 * @param cls a `struct Queue`
1765 */ 1758 */
1766static void 1759static void
1767queue_read_kx (void *cls) 1760queue_read_kx(void *cls)
1768{ 1761{
1769 struct Queue *queue = cls; 1762 struct Queue *queue = cls;
1770 ssize_t rcvd; 1763 ssize_t rcvd;
@@ -1772,65 +1765,65 @@ queue_read_kx (void *cls)
1772 struct TCPConfirmation tc; 1765 struct TCPConfirmation tc;
1773 1766
1774 queue->read_task = NULL; 1767 queue->read_task = NULL;
1775 left = GNUNET_TIME_absolute_get_remaining (queue->timeout); 1768 left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
1776 if (0 == left.rel_value_us) 1769 if (0 == left.rel_value_us)
1777 { 1770 {
1778 queue_destroy (queue); 1771 queue_destroy(queue);
1779 return; 1772 return;
1780 } 1773 }
1781 rcvd = GNUNET_NETWORK_socket_recv (queue->sock, 1774 rcvd = GNUNET_NETWORK_socket_recv(queue->sock,
1782 &queue->cread_buf[queue->cread_off], 1775 &queue->cread_buf[queue->cread_off],
1783 BUF_SIZE - queue->cread_off); 1776 BUF_SIZE - queue->cread_off);
1784 if (-1 == rcvd) 1777 if (-1 == rcvd)
1785 {
1786 if ((EAGAIN != errno) && (EINTR != errno))
1787 { 1778 {
1788 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); 1779 if ((EAGAIN != errno) && (EINTR != errno))
1789 queue_destroy (queue); 1780 {
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);
1790 return; 1787 return;
1791 } 1788 }
1792 queue->read_task =
1793 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue);
1794 return;
1795 }
1796 queue->cread_off += rcvd; 1789 queue->cread_off += rcvd;
1797 if (queue->cread_off < INITIAL_KX_SIZE) 1790 if (queue->cread_off < INITIAL_KX_SIZE)
1798 { 1791 {
1799 /* read more */ 1792 /* read more */
1800 queue->read_task = 1793 queue->read_task =
1801 GNUNET_SCHEDULER_add_read_net (left, queue->sock, &queue_read_kx, queue); 1794 GNUNET_SCHEDULER_add_read_net(left, queue->sock, &queue_read_kx, queue);
1802 return; 1795 return;
1803 } 1796 }
1804 /* we got all the data, let's find out who we are talking to! */ 1797 /* we got all the data, let's find out who we are talking to! */
1805 setup_in_cipher ((const struct GNUNET_CRYPTO_EcdhePublicKey *) 1798 setup_in_cipher((const struct GNUNET_CRYPTO_EcdhePublicKey *)
1806 queue->cread_buf, 1799 queue->cread_buf,
1807 queue); 1800 queue);
1808 if (GNUNET_OK != decrypt_and_check_tc (queue, &tc, queue->cread_buf)) 1801 if (GNUNET_OK != decrypt_and_check_tc(queue, &tc, queue->cread_buf))
1809 { 1802 {
1810 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1803 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1811 "Invalid TCP KX received from %s\n", 1804 "Invalid TCP KX received from %s\n",
1812 GNUNET_a2s (queue->address, queue->address_len)); 1805 GNUNET_a2s(queue->address, queue->address_len));
1813 queue_destroy (queue); 1806 queue_destroy(queue);
1814 return; 1807 return;
1815 } 1808 }
1816 if (0 != 1809 if (0 !=
1817 memcmp (&tc.sender, &queue->target, sizeof (struct GNUNET_PeerIdentity))) 1810 memcmp(&tc.sender, &queue->target, sizeof(struct GNUNET_PeerIdentity)))
1818 { 1811 {
1819 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1812 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1820 "Invalid sender in TCP KX received from %s\n", 1813 "Invalid sender in TCP KX received from %s\n",
1821 GNUNET_a2s (queue->address, queue->address_len)); 1814 GNUNET_a2s(queue->address, queue->address_len));
1822 queue_destroy (queue); 1815 queue_destroy(queue);
1823 return; 1816 return;
1824 } 1817 }
1825 1818
1826 /* update queue timeout */ 1819 /* update queue timeout */
1827 reschedule_queue_timeout (queue); 1820 reschedule_queue_timeout(queue);
1828 /* prepare to continue with regular read task immediately */ 1821 /* prepare to continue with regular read task immediately */
1829 memmove (queue->cread_buf, 1822 memmove(queue->cread_buf,
1830 &queue->cread_buf[INITIAL_KX_SIZE], 1823 &queue->cread_buf[INITIAL_KX_SIZE],
1831 queue->cread_off - (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->read_task = GNUNET_SCHEDULER_add_now (&queue_read, queue); 1826 queue->read_task = GNUNET_SCHEDULER_add_now(&queue_read, queue);
1834} 1827}
1835 1828
1836 1829
@@ -1853,7 +1846,7 @@ queue_read_kx (void *cls)
1853 * invalid 1846 * invalid
1854 */ 1847 */
1855static int 1848static int
1856mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 1849mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1857{ 1850{
1858 struct Queue *queue; 1851 struct Queue *queue;
1859 const char *path; 1852 const char *path;
@@ -1861,54 +1854,54 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1861 socklen_t in_len; 1854 socklen_t in_len;
1862 struct GNUNET_NETWORK_Handle *sock; 1855 struct GNUNET_NETWORK_Handle *sock;
1863 1856
1864 if (0 != strncmp (address, 1857 if (0 != strncmp(address,
1865 COMMUNICATOR_ADDRESS_PREFIX "-", 1858 COMMUNICATOR_ADDRESS_PREFIX "-",
1866 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 1859 strlen(COMMUNICATOR_ADDRESS_PREFIX "-")))
1867 { 1860 {
1868 GNUNET_break_op (0); 1861 GNUNET_break_op(0);
1869 return GNUNET_SYSERR; 1862 return GNUNET_SYSERR;
1870 } 1863 }
1871 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; 1864 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")];
1872 in = tcp_address_to_sockaddr (path, &in_len); 1865 in = tcp_address_to_sockaddr(path, &in_len);
1873 1866
1874 sock = GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); 1867 sock = GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP);
1875 if (NULL == sock) 1868 if (NULL == sock)
1876 { 1869 {
1877 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1870 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1878 "socket(%d) failed: %s", 1871 "socket(%d) failed: %s",
1879 in->sa_family, 1872 in->sa_family,
1880 strerror (errno)); 1873 strerror(errno));
1881 GNUNET_free (in); 1874 GNUNET_free(in);
1882 return GNUNET_SYSERR; 1875 return GNUNET_SYSERR;
1883 } 1876 }
1884 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sock, in, in_len)) 1877 if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sock, in, in_len))
1885 { 1878 {
1886 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1879 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1887 "connect to `%s' failed: %s", 1880 "connect to `%s' failed: %s",
1888 address, 1881 address,
1889 strerror (errno)); 1882 strerror(errno));
1890 GNUNET_NETWORK_socket_close (sock); 1883 GNUNET_NETWORK_socket_close(sock);
1891 GNUNET_free (in); 1884 GNUNET_free(in);
1892 return GNUNET_SYSERR; 1885 return GNUNET_SYSERR;
1893 } 1886 }
1894 1887
1895 queue = GNUNET_new (struct Queue); 1888 queue = GNUNET_new(struct Queue);
1896 queue->target = *peer; 1889 queue->target = *peer;
1897 queue->address = in; 1890 queue->address = in;
1898 queue->address_len = in_len; 1891 queue->address_len = in_len;
1899 queue->sock = sock; 1892 queue->sock = sock;
1900 boot_queue (queue, GNUNET_TRANSPORT_CS_OUTBOUND); 1893 boot_queue(queue, GNUNET_TRANSPORT_CS_OUTBOUND);
1901 queue->read_task = 1894 queue->read_task =
1902 GNUNET_SCHEDULER_add_read_net (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1895 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,
1903 queue->sock, 1902 queue->sock,
1904 &queue_read_kx, 1903 &queue_write,
1905 queue); 1904 queue);
1906 start_initial_kx_out (queue);
1907 queue->write_task =
1908 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL,
1909 queue->sock,
1910 &queue_write,
1911 queue);
1912 return GNUNET_OK; 1905 return GNUNET_OK;
1913} 1906}
1914 1907
@@ -1922,15 +1915,15 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
1922 * @return #GNUNET_OK to continue to iterate 1915 * @return #GNUNET_OK to continue to iterate
1923 */ 1916 */
1924static int 1917static int
1925get_queue_delete_it (void *cls, 1918get_queue_delete_it(void *cls,
1926 const struct GNUNET_PeerIdentity *target, 1919 const struct GNUNET_PeerIdentity *target,
1927 void *value) 1920 void *value)
1928{ 1921{
1929 struct Queue *queue = value; 1922 struct Queue *queue = value;
1930 1923
1931 (void) cls; 1924 (void)cls;
1932 (void) target; 1925 (void)target;
1933 queue_destroy (queue); 1926 queue_destroy(queue);
1934 return GNUNET_OK; 1927 return GNUNET_OK;
1935} 1928}
1936 1929
@@ -1941,47 +1934,47 @@ get_queue_delete_it (void *cls,
1941 * @param cls NULL (always) 1934 * @param cls NULL (always)
1942 */ 1935 */
1943static void 1936static void
1944do_shutdown (void *cls) 1937do_shutdown(void *cls)
1945{ 1938{
1946 while (NULL != proto_head) 1939 while (NULL != proto_head)
1947 free_proto_queue (proto_head); 1940 free_proto_queue(proto_head);
1948 if (NULL != nat) 1941 if (NULL != nat)
1949 { 1942 {
1950 GNUNET_NAT_unregister (nat); 1943 GNUNET_NAT_unregister(nat);
1951 nat = NULL; 1944 nat = NULL;
1952 } 1945 }
1953 if (NULL != listen_task) 1946 if (NULL != listen_task)
1954 { 1947 {
1955 GNUNET_SCHEDULER_cancel (listen_task); 1948 GNUNET_SCHEDULER_cancel(listen_task);
1956 listen_task = NULL; 1949 listen_task = NULL;
1957 } 1950 }
1958 if (NULL != listen_sock) 1951 if (NULL != listen_sock)
1959 { 1952 {
1960 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (listen_sock)); 1953 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(listen_sock));
1961 listen_sock = NULL; 1954 listen_sock = NULL;
1962 } 1955 }
1963 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); 1956 GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL);
1964 GNUNET_CONTAINER_multipeermap_destroy (queue_map); 1957 GNUNET_CONTAINER_multipeermap_destroy(queue_map);
1965 if (NULL != ch) 1958 if (NULL != ch)
1966 { 1959 {
1967 GNUNET_TRANSPORT_communicator_disconnect (ch); 1960 GNUNET_TRANSPORT_communicator_disconnect(ch);
1968 ch = NULL; 1961 ch = NULL;
1969 } 1962 }
1970 if (NULL != stats) 1963 if (NULL != stats)
1971 { 1964 {
1972 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 1965 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
1973 stats = NULL; 1966 stats = NULL;
1974 } 1967 }
1975 if (NULL != my_private_key) 1968 if (NULL != my_private_key)
1976 { 1969 {
1977 GNUNET_free (my_private_key); 1970 GNUNET_free(my_private_key);
1978 my_private_key = NULL; 1971 my_private_key = NULL;
1979 } 1972 }
1980 if (NULL != is) 1973 if (NULL != is)
1981 { 1974 {
1982 GNUNET_NT_scanner_done (is); 1975 GNUNET_NT_scanner_done(is);
1983 is = NULL; 1976 is = NULL;
1984 } 1977 }
1985} 1978}
1986 1979
1987 1980
@@ -1997,14 +1990,14 @@ do_shutdown (void *cls)
1997 * @param msg payload 1990 * @param msg payload
1998 */ 1991 */
1999static void 1992static void
2000enc_notify_cb (void *cls, 1993enc_notify_cb(void *cls,
2001 const struct GNUNET_PeerIdentity *sender, 1994 const struct GNUNET_PeerIdentity *sender,
2002 const struct GNUNET_MessageHeader *msg) 1995 const struct GNUNET_MessageHeader *msg)
2003{ 1996{
2004 (void) cls; 1997 (void)cls;
2005 (void) sender; 1998 (void)sender;
2006 (void) msg; 1999 (void)msg;
2007 GNUNET_break_op (0); 2000 GNUNET_break_op(0);
2008} 2001}
2009 2002
2010 2003
@@ -2022,39 +2015,39 @@ enc_notify_cb (void *cls,
2022 * @param addrlen actual length of the @a addr 2015 * @param addrlen actual length of the @a addr
2023 */ 2016 */
2024static void 2017static void
2025nat_address_cb (void *cls, 2018nat_address_cb(void *cls,
2026 void **app_ctx, 2019 void **app_ctx,
2027 int add_remove, 2020 int add_remove,
2028 enum GNUNET_NAT_AddressClass ac, 2021 enum GNUNET_NAT_AddressClass ac,
2029 const struct sockaddr *addr, 2022 const struct sockaddr *addr,
2030 socklen_t addrlen) 2023 socklen_t addrlen)
2031{ 2024{
2032 char *my_addr; 2025 char *my_addr;
2033 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 2026 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
2034 2027
2035 if (GNUNET_YES == add_remove) 2028 if (GNUNET_YES == add_remove)
2036 { 2029 {
2037 enum GNUNET_NetworkType nt; 2030 enum GNUNET_NetworkType nt;
2038 2031
2039 GNUNET_asprintf (&my_addr, 2032 GNUNET_asprintf(&my_addr,
2040 "%s-%s", 2033 "%s-%s",
2041 COMMUNICATOR_ADDRESS_PREFIX, 2034 COMMUNICATOR_ADDRESS_PREFIX,
2042 GNUNET_a2s (addr, addrlen)); 2035 GNUNET_a2s(addr, addrlen));
2043 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen); 2036 nt = GNUNET_NT_scanner_get_type(is, addr, addrlen);
2044 ai = 2037 ai =
2045 GNUNET_TRANSPORT_communicator_address_add (ch, 2038 GNUNET_TRANSPORT_communicator_address_add(ch,
2046 my_addr, 2039 my_addr,
2047 nt, 2040 nt,
2048 GNUNET_TIME_UNIT_FOREVER_REL); 2041 GNUNET_TIME_UNIT_FOREVER_REL);
2049 GNUNET_free (my_addr); 2042 GNUNET_free(my_addr);
2050 *app_ctx = ai; 2043 *app_ctx = ai;
2051 } 2044 }
2052 else 2045 else
2053 { 2046 {
2054 ai = *app_ctx; 2047 ai = *app_ctx;
2055 GNUNET_TRANSPORT_communicator_address_remove (ai); 2048 GNUNET_TRANSPORT_communicator_address_remove(ai);
2056 *app_ctx = NULL; 2049 *app_ctx = NULL;
2057 } 2050 }
2058} 2051}
2059 2052
2060 2053
@@ -2067,10 +2060,10 @@ nat_address_cb (void *cls,
2067 * @param c configuration 2060 * @param c configuration
2068 */ 2061 */
2069static void 2062static void
2070run (void *cls, 2063run(void *cls,
2071 char *const *args, 2064 char *const *args,
2072 const char *cfgfile, 2065 const char *cfgfile,
2073 const struct GNUNET_CONFIGURATION_Handle *c) 2066 const struct GNUNET_CONFIGURATION_Handle *c)
2074{ 2067{
2075 char *bindto; 2068 char *bindto;
2076 struct sockaddr *in; 2069 struct sockaddr *in;
@@ -2078,113 +2071,113 @@ run (void *cls,
2078 struct sockaddr_storage in_sto; 2071 struct sockaddr_storage in_sto;
2079 socklen_t sto_len; 2072 socklen_t sto_len;
2080 2073
2081 (void) cls; 2074 (void)cls;
2082 cfg = c; 2075 cfg = c;
2083 if (GNUNET_OK != 2076 if (GNUNET_OK !=
2084 GNUNET_CONFIGURATION_get_value_filename (cfg, 2077 GNUNET_CONFIGURATION_get_value_filename(cfg,
2085 COMMUNICATOR_CONFIG_SECTION, 2078 COMMUNICATOR_CONFIG_SECTION,
2086 "BINDTO", 2079 "BINDTO",
2087 &bindto)) 2080 &bindto))
2088 { 2081 {
2089 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2082 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
2090 COMMUNICATOR_CONFIG_SECTION, 2083 COMMUNICATOR_CONFIG_SECTION,
2091 "BINDTO"); 2084 "BINDTO");
2092 return; 2085 return;
2093 } 2086 }
2094 if (GNUNET_OK != 2087 if (GNUNET_OK !=
2095 GNUNET_CONFIGURATION_get_value_number (cfg, 2088 GNUNET_CONFIGURATION_get_value_number(cfg,
2096 COMMUNICATOR_CONFIG_SECTION, 2089 COMMUNICATOR_CONFIG_SECTION,
2097 "MAX_QUEUE_LENGTH", 2090 "MAX_QUEUE_LENGTH",
2098 &max_queue_length)) 2091 &max_queue_length))
2099 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 2092 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
2100 2093
2101 in = tcp_address_to_sockaddr (bindto, &in_len); 2094 in = tcp_address_to_sockaddr(bindto, &in_len);
2102 if (NULL == in) 2095 if (NULL == in)
2103 { 2096 {
2104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2097 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2105 "Failed to setup TCP socket address with path `%s'\n", 2098 "Failed to setup TCP socket address with path `%s'\n",
2106 bindto); 2099 bindto);
2107 GNUNET_free (bindto); 2100 GNUNET_free(bindto);
2108 return; 2101 return;
2109 } 2102 }
2110 listen_sock = 2103 listen_sock =
2111 GNUNET_NETWORK_socket_create (in->sa_family, SOCK_STREAM, IPPROTO_TCP); 2104 GNUNET_NETWORK_socket_create(in->sa_family, SOCK_STREAM, IPPROTO_TCP);
2112 if (NULL == listen_sock) 2105 if (NULL == listen_sock)
2113 { 2106 {
2114 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 2107 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
2115 GNUNET_free (in); 2108 GNUNET_free(in);
2116 GNUNET_free (bindto); 2109 GNUNET_free(bindto);
2117 return; 2110 return;
2118 } 2111 }
2119 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (listen_sock, in, in_len)) 2112 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(listen_sock, in, in_len))
2120 { 2113 {
2121 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); 2114 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
2122 GNUNET_NETWORK_socket_close (listen_sock); 2115 GNUNET_NETWORK_socket_close(listen_sock);
2123 listen_sock = NULL; 2116 listen_sock = NULL;
2124 GNUNET_free (in); 2117 GNUNET_free(in);
2125 GNUNET_free (bindto); 2118 GNUNET_free(bindto);
2126 return; 2119 return;
2127 } 2120 }
2128 /* We might have bound to port 0, allowing the OS to figure it out; 2121 /* We might have bound to port 0, allowing the OS to figure it out;
2129 thus, get the real IN-address from the socket */ 2122 thus, get the real IN-address from the socket */
2130 sto_len = sizeof (in_sto); 2123 sto_len = sizeof(in_sto);
2131 if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock), 2124 if (0 != getsockname(GNUNET_NETWORK_get_fd(listen_sock),
2132 (struct sockaddr *) &in_sto, 2125 (struct sockaddr *)&in_sto,
2133 &sto_len)) 2126 &sto_len))
2134 { 2127 {
2135 memcpy (&in_sto, in, in_len); 2128 memcpy(&in_sto, in, in_len);
2136 sto_len = in_len; 2129 sto_len = in_len;
2137 } 2130 }
2138 GNUNET_free (in); 2131 GNUNET_free(in);
2139 GNUNET_free (bindto); 2132 GNUNET_free(bindto);
2140 in = (struct sockaddr *) &in_sto; 2133 in = (struct sockaddr *)&in_sto;
2141 in_len = sto_len; 2134 in_len = sto_len;
2142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2135 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2143 "Bound to `%s'\n", 2136 "Bound to `%s'\n",
2144 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); 2137 GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len));
2145 stats = GNUNET_STATISTICS_create ("C-TCP", cfg); 2138 stats = GNUNET_STATISTICS_create("C-TCP", cfg);
2146 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 2139 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
2147 is = GNUNET_NT_scanner_init (); 2140 is = GNUNET_NT_scanner_init();
2148 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); 2141 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg);
2149 if (NULL == my_private_key) 2142 if (NULL == my_private_key)
2150 { 2143 {
2151 GNUNET_log ( 2144 GNUNET_log(
2152 GNUNET_ERROR_TYPE_ERROR, 2145 GNUNET_ERROR_TYPE_ERROR,
2153 _ ( 2146 _(
2154 "Transport service is lacking key configuration settings. Exiting.\n")); 2147 "Transport service is lacking key configuration settings. Exiting.\n"));
2155 GNUNET_SCHEDULER_shutdown (); 2148 GNUNET_SCHEDULER_shutdown();
2156 return; 2149 return;
2157 } 2150 }
2158 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); 2151 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key);
2159 /* start listening */ 2152 /* start listening */
2160 listen_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 2153 listen_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
2161 listen_sock, 2154 listen_sock,
2162 &listen_cb, 2155 &listen_cb,
2163 NULL);
2164 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
2165 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
2166 COMMUNICATOR_CONFIG_SECTION,
2167 COMMUNICATOR_ADDRESS_PREFIX,
2168 GNUNET_TRANSPORT_CC_RELIABLE,
2169 &mq_init,
2170 NULL,
2171 &enc_notify_cb,
2172 NULL); 2156 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);
2173 if (NULL == ch) 2166 if (NULL == ch)
2174 { 2167 {
2175 GNUNET_break (0); 2168 GNUNET_break(0);
2176 GNUNET_SCHEDULER_shutdown (); 2169 GNUNET_SCHEDULER_shutdown();
2177 return; 2170 return;
2178 } 2171 }
2179 nat = GNUNET_NAT_register (cfg, 2172 nat = GNUNET_NAT_register(cfg,
2180 COMMUNICATOR_CONFIG_SECTION, 2173 COMMUNICATOR_CONFIG_SECTION,
2181 IPPROTO_TCP, 2174 IPPROTO_TCP,
2182 1 /* one address */, 2175 1 /* one address */,
2183 (const struct sockaddr **) &in, 2176 (const struct sockaddr **)&in,
2184 &in_len, 2177 &in_len,
2185 &nat_address_cb, 2178 &nat_address_cb,
2186 NULL /* FIXME: support reversal: #5529 */, 2179 NULL /* FIXME: support reversal: #5529 */,
2187 NULL /* closure */); 2180 NULL /* closure */);
2188} 2181}
2189 2182
2190 2183
@@ -2196,25 +2189,26 @@ run (void *cls,
2196 * @return 0 ok, 1 on error 2189 * @return 0 ok, 1 on error
2197 */ 2190 */
2198int 2191int
2199main (int argc, char *const *argv) 2192main(int argc, char *const *argv)
2200{ 2193{
2201 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 2194 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2202 GNUNET_GETOPT_OPTION_END}; 2195 GNUNET_GETOPT_OPTION_END
2196 };
2203 int ret; 2197 int ret;
2204 2198
2205 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 2199 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
2206 return 2; 2200 return 2;
2207 2201
2208 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, 2202 ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
2209 argv, 2203 argv,
2210 "gnunet-communicator-tcp", 2204 "gnunet-communicator-tcp",
2211 _ ("GNUnet TCP communicator"), 2205 _("GNUnet TCP communicator"),
2212 options, 2206 options,
2213 &run, 2207 &run,
2214 NULL)) 2208 NULL))
2215 ? 0 2209 ? 0
2216 : 1; 2210 : 1;
2217 GNUNET_free ((void *) argv); 2211 GNUNET_free((void *)argv);
2218 return ret; 2212 return ret;
2219} 2213}
2220 2214
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 2c8893d75..228540b81 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-communicator-udp.c 22 * @file 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,8 +156,7 @@ 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{
161 /** 160 /**
162 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE 161 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE
163 */ 162 */
@@ -190,9 +189,7 @@ struct UdpHandshakeSignature
190 * "Plaintext" header at beginning of KX message. Followed 189 * "Plaintext" header at beginning of KX message. Followed
191 * by encrypted `struct UDPConfirmation`. 190 * by encrypted `struct UDPConfirmation`.
192 */ 191 */
193struct InitialKX 192struct InitialKX {
194{
195
196 /** 193 /**
197 * Ephemeral key for KX. 194 * Ephemeral key for KX.
198 */ 195 */
@@ -210,8 +207,7 @@ struct InitialKX
210 * Encrypted continuation of UDP initial handshake, followed 207 * Encrypted continuation of UDP initial handshake, followed
211 * by message header with payload. 208 * by message header with payload.
212 */ 209 */
213struct UDPConfirmation 210struct UDPConfirmation {
214{
215 /** 211 /**
216 * Sender's identity 212 * Sender's identity
217 */ 213 */
@@ -238,9 +234,7 @@ struct UDPConfirmation
238 * UDP key acknowledgement. May be sent via backchannel. Allows the 234 * UDP key acknowledgement. May be sent via backchannel. Allows the
239 * sender to use `struct UDPBox` with the acknowledge key henceforth. 235 * sender to use `struct UDPBox` with the acknowledge key henceforth.
240 */ 236 */
241struct UDPAck 237struct UDPAck {
242{
243
244 /** 238 /**
245 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK. 239 * Type is #GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK.
246 */ 240 */
@@ -267,8 +261,7 @@ struct UDPAck
267 * be just any global peer -- an attacker must have at least 261 * be just any global peer -- an attacker must have at least
268 * shared a LAN with the peer they're pretending to be here. 262 * shared a LAN with the peer they're pretending to be here.
269 */ 263 */
270struct UdpBroadcastSignature 264struct UdpBroadcastSignature {
271{
272 /** 265 /**
273 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST 266 * Purpose must be #GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST
274 */ 267 */
@@ -292,9 +285,7 @@ struct UdpBroadcastSignature
292 * recognized in LAN as GNUnet peers if this feature is enabled 285 * recognized in LAN as GNUnet peers if this feature is enabled
293 * anyway. Also, the entire message is in cleartext. 286 * anyway. Also, the entire message is in cleartext.
294 */ 287 */
295struct UDPBroadcast 288struct UDPBroadcast {
296{
297
298 /** 289 /**
299 * Sender's peer identity. 290 * Sender's peer identity.
300 */ 291 */
@@ -312,9 +303,7 @@ struct UDPBroadcast
312 * UDP message box. Always sent encrypted, only allowed after 303 * UDP message box. Always sent encrypted, only allowed after
313 * the receiver sent a `struct UDPAck` for the base key! 304 * the receiver sent a `struct UDPAck` for the base key!
314 */ 305 */
315struct UDPBox 306struct UDPBox {
316{
317
318 /** 307 /**
319 * Key and IV identification code. KDF applied to an acknowledged 308 * Key and IV identification code. KDF applied to an acknowledged
320 * base key and a sequence number. Sequence numbers must be used 309 * base key and a sequence number. Sequence numbers must be used
@@ -347,9 +336,7 @@ struct SharedSecret;
347 * Pre-generated "kid" code (key and IV identification code) to 336 * Pre-generated "kid" code (key and IV identification code) to
348 * quickly derive master key for a `struct UDPBox`. 337 * quickly derive master key for a `struct UDPBox`.
349 */ 338 */
350struct KeyCacheEntry 339struct KeyCacheEntry {
351{
352
353 /** 340 /**
354 * Kept in a DLL. 341 * Kept in a DLL.
355 */ 342 */
@@ -396,8 +383,7 @@ struct ReceiverAddress;
396/** 383/**
397 * Shared secret we generated for a particular sender or receiver. 384 * Shared secret we generated for a particular sender or receiver.
398 */ 385 */
399struct SharedSecret 386struct SharedSecret {
400{
401 /** 387 /**
402 * Kept in a DLL. 388 * Kept in a DLL.
403 */ 389 */
@@ -462,9 +448,7 @@ struct SharedSecret
462 * Information we track per sender address we have recently been 448 * Information we track per sender address we have recently been
463 * in contact with (we decrypt messages from the sender). 449 * in contact with (we decrypt messages from the sender).
464 */ 450 */
465struct SenderAddress 451struct SenderAddress {
466{
467
468 /** 452 /**
469 * To whom are we talking to. 453 * To whom are we talking to.
470 */ 454 */
@@ -516,9 +500,7 @@ struct SenderAddress
516 * Information we track per receiving address we have recently been 500 * Information we track per receiving address we have recently been
517 * in contact with (encryption to receiver). 501 * in contact with (encryption to receiver).
518 */ 502 */
519struct ReceiverAddress 503struct ReceiverAddress {
520{
521
522 /** 504 /**
523 * To whom are we talking to. 505 * To whom are we talking to.
524 */ 506 */
@@ -596,9 +578,7 @@ struct ReceiverAddress
596/** 578/**
597 * Interface we broadcast our presence on. 579 * Interface we broadcast our presence on.
598 */ 580 */
599struct BroadcastInterface 581struct BroadcastInterface {
600{
601
602 /** 582 /**
603 * Kept in a DLL. 583 * Kept in a DLL.
604 */ 584 */
@@ -759,25 +739,25 @@ static uint16_t my_port;
759 * @param bi entity to close down 739 * @param bi entity to close down
760 */ 740 */
761static void 741static void
762bi_destroy (struct BroadcastInterface *bi) 742bi_destroy(struct BroadcastInterface *bi)
763{ 743{
764 if (AF_INET6 == bi->sa->sa_family) 744 if (AF_INET6 == bi->sa->sa_family)
765 {
766 /* Leave the multicast group */
767 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
768 IPPROTO_IPV6,
769 IPV6_LEAVE_GROUP,
770 &bi->mcreq,
771 sizeof (bi->mcreq)))
772 { 745 {
773 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 746 /* Leave the multicast group */
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 }
774 } 755 }
775 } 756 GNUNET_CONTAINER_DLL_remove(bi_head, bi_tail, bi);
776 GNUNET_CONTAINER_DLL_remove (bi_head, bi_tail, bi); 757 GNUNET_SCHEDULER_cancel(bi->broadcast_task);
777 GNUNET_SCHEDULER_cancel (bi->broadcast_task); 758 GNUNET_free(bi->sa);
778 GNUNET_free (bi->sa); 759 GNUNET_free_non_null(bi->ba);
779 GNUNET_free_non_null (bi->ba); 760 GNUNET_free(bi);
780 GNUNET_free (bi);
781} 761}
782 762
783 763
@@ -787,35 +767,35 @@ bi_destroy (struct BroadcastInterface *bi)
787 * @param receiver entity to close down 767 * @param receiver entity to close down
788 */ 768 */
789static void 769static void
790receiver_destroy (struct ReceiverAddress *receiver) 770receiver_destroy(struct ReceiverAddress *receiver)
791{ 771{
792 struct GNUNET_MQ_Handle *mq; 772 struct GNUNET_MQ_Handle *mq;
793 773
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 774 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
795 "Disconnecting receiver for peer `%s'\n", 775 "Disconnecting receiver for peer `%s'\n",
796 GNUNET_i2s (&receiver->target)); 776 GNUNET_i2s(&receiver->target));
797 if (NULL != (mq = receiver->mq)) 777 if (NULL != (mq = receiver->mq))
798 { 778 {
799 receiver->mq = NULL; 779 receiver->mq = NULL;
800 GNUNET_MQ_destroy (mq); 780 GNUNET_MQ_destroy(mq);
801 } 781 }
802 if (NULL != receiver->qh) 782 if (NULL != receiver->qh)
803 { 783 {
804 GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); 784 GNUNET_TRANSPORT_communicator_mq_del(receiver->qh);
805 receiver->qh = NULL; 785 receiver->qh = NULL;
806 } 786 }
807 GNUNET_assert (GNUNET_YES == 787 GNUNET_assert(GNUNET_YES ==
808 GNUNET_CONTAINER_multipeermap_remove (receivers, 788 GNUNET_CONTAINER_multipeermap_remove(receivers,
809 &receiver->target, 789 &receiver->target,
810 receiver)); 790 receiver));
811 GNUNET_assert (receiver == GNUNET_CONTAINER_heap_remove_node (receiver->hn)); 791 GNUNET_assert(receiver == GNUNET_CONTAINER_heap_remove_node(receiver->hn));
812 GNUNET_STATISTICS_set (stats, 792 GNUNET_STATISTICS_set(stats,
813 "# receivers active", 793 "# receivers active",
814 GNUNET_CONTAINER_multipeermap_size (receivers), 794 GNUNET_CONTAINER_multipeermap_size(receivers),
815 GNUNET_NO); 795 GNUNET_NO);
816 GNUNET_free (receiver->address); 796 GNUNET_free(receiver->address);
817 GNUNET_free (receiver->foreign_addr); 797 GNUNET_free(receiver->foreign_addr);
818 GNUNET_free (receiver); 798 GNUNET_free(receiver);
819} 799}
820 800
821 801
@@ -825,16 +805,16 @@ receiver_destroy (struct ReceiverAddress *receiver)
825 * @param kce the key cache entry 805 * @param kce the key cache entry
826 */ 806 */
827static void 807static void
828kce_destroy (struct KeyCacheEntry *kce) 808kce_destroy(struct KeyCacheEntry *kce)
829{ 809{
830 struct SharedSecret *ss = kce->ss; 810 struct SharedSecret *ss = kce->ss;
831 811
832 ss->active_kce_count--; 812 ss->active_kce_count--;
833 GNUNET_CONTAINER_DLL_remove (ss->kce_head, ss->kce_tail, kce); 813 GNUNET_CONTAINER_DLL_remove(ss->kce_head, ss->kce_tail, kce);
834 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove (key_cache, 814 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multishortmap_remove(key_cache,
835 &kce->kid, 815 &kce->kid,
836 kce)); 816 kce));
837 GNUNET_free (kce); 817 GNUNET_free(kce);
838} 818}
839 819
840 820
@@ -846,24 +826,24 @@ kce_destroy (struct KeyCacheEntry *kce)
846 * @param kid[out] where to write the key ID 826 * @param kid[out] where to write the key ID
847 */ 827 */
848static void 828static void
849get_kid (const struct GNUNET_HashCode *msec, 829get_kid(const struct GNUNET_HashCode *msec,
850 uint32_t serial, 830 uint32_t serial,
851 struct GNUNET_ShortHashCode *kid) 831 struct GNUNET_ShortHashCode *kid)
852{ 832{
853 uint32_t sid = htonl (serial); 833 uint32_t sid = htonl(serial);
854 834
855 GNUNET_CRYPTO_hkdf (kid, 835 GNUNET_CRYPTO_hkdf(kid,
856 sizeof (*kid), 836 sizeof(*kid),
857 GCRY_MD_SHA512, 837 GCRY_MD_SHA512,
858 GCRY_MD_SHA256, 838 GCRY_MD_SHA256,
859 &sid, 839 &sid,
860 sizeof (sid), 840 sizeof(sid),
861 msec, 841 msec,
862 sizeof (*msec), 842 sizeof(*msec),
863 "UDP-KID", 843 "UDP-KID",
864 strlen ("UDP-KID"), 844 strlen("UDP-KID"),
865 NULL, 845 NULL,
866 0); 846 0);
867} 847}
868 848
869 849
@@ -874,26 +854,26 @@ get_kid (const struct GNUNET_HashCode *msec,
874 * @param seq sequence number for the key cache entry 854 * @param seq sequence number for the key cache entry
875 */ 855 */
876static void 856static void
877kce_generate (struct SharedSecret *ss, uint32_t seq) 857kce_generate(struct SharedSecret *ss, uint32_t seq)
878{ 858{
879 struct KeyCacheEntry *kce; 859 struct KeyCacheEntry *kce;
880 860
881 GNUNET_assert (0 < seq); 861 GNUNET_assert(0 < seq);
882 kce = GNUNET_new (struct KeyCacheEntry); 862 kce = GNUNET_new(struct KeyCacheEntry);
883 kce->ss = ss; 863 kce->ss = ss;
884 kce->sequence_number = seq; 864 kce->sequence_number = seq;
885 get_kid (&ss->master, seq, &kce->kid); 865 get_kid(&ss->master, seq, &kce->kid);
886 GNUNET_CONTAINER_DLL_insert (ss->kce_head, ss->kce_tail, kce); 866 GNUNET_CONTAINER_DLL_insert(ss->kce_head, ss->kce_tail, kce);
887 ss->active_kce_count++; 867 ss->active_kce_count++;
888 (void) GNUNET_CONTAINER_multishortmap_put ( 868 (void)GNUNET_CONTAINER_multishortmap_put(
889 key_cache, 869 key_cache,
890 &kce->kid, 870 &kce->kid,
891 kce, 871 kce,
892 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 872 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
893 GNUNET_STATISTICS_set (stats, 873 GNUNET_STATISTICS_set(stats,
894 "# KIDs active", 874 "# KIDs active",
895 GNUNET_CONTAINER_multishortmap_size (key_cache), 875 GNUNET_CONTAINER_multishortmap_size(key_cache),
896 GNUNET_NO); 876 GNUNET_NO);
897} 877}
898 878
899 879
@@ -903,31 +883,31 @@ kce_generate (struct SharedSecret *ss, uint32_t seq)
903 * @param ss shared secret to destroy 883 * @param ss shared secret to destroy
904 */ 884 */
905static void 885static void
906secret_destroy (struct SharedSecret *ss) 886secret_destroy(struct SharedSecret *ss)
907{ 887{
908 struct SenderAddress *sender; 888 struct SenderAddress *sender;
909 struct ReceiverAddress *receiver; 889 struct ReceiverAddress *receiver;
910 struct KeyCacheEntry *kce; 890 struct KeyCacheEntry *kce;
911 891
912 if (NULL != (sender = ss->sender)) 892 if (NULL != (sender = ss->sender))
913 { 893 {
914 GNUNET_CONTAINER_DLL_remove (sender->ss_head, sender->ss_tail, ss); 894 GNUNET_CONTAINER_DLL_remove(sender->ss_head, sender->ss_tail, ss);
915 sender->num_secrets--; 895 sender->num_secrets--;
916 } 896 }
917 if (NULL != (receiver = ss->receiver)) 897 if (NULL != (receiver = ss->receiver))
918 { 898 {
919 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss); 899 GNUNET_CONTAINER_DLL_remove(receiver->ss_head, receiver->ss_tail, ss);
920 receiver->num_secrets--; 900 receiver->num_secrets--;
921 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used); 901 receiver->acks_available -= (ss->sequence_allowed - ss->sequence_used);
922 } 902 }
923 while (NULL != (kce = ss->kce_head)) 903 while (NULL != (kce = ss->kce_head))
924 kce_destroy (kce); 904 kce_destroy(kce);
925 GNUNET_STATISTICS_update (stats, "# Secrets active", -1, GNUNET_NO); 905 GNUNET_STATISTICS_update(stats, "# Secrets active", -1, GNUNET_NO);
926 GNUNET_STATISTICS_set (stats, 906 GNUNET_STATISTICS_set(stats,
927 "# KIDs active", 907 "# KIDs active",
928 GNUNET_CONTAINER_multishortmap_size (key_cache), 908 GNUNET_CONTAINER_multishortmap_size(key_cache),
929 GNUNET_NO); 909 GNUNET_NO);
930 GNUNET_free (ss); 910 GNUNET_free(ss);
931} 911}
932 912
933 913
@@ -938,18 +918,18 @@ secret_destroy (struct SharedSecret *ss)
938 * @param sender entity to close down 918 * @param sender entity to close down
939 */ 919 */
940static void 920static void
941sender_destroy (struct SenderAddress *sender) 921sender_destroy(struct SenderAddress *sender)
942{ 922{
943 GNUNET_assert ( 923 GNUNET_assert(
944 GNUNET_YES == 924 GNUNET_YES ==
945 GNUNET_CONTAINER_multipeermap_remove (senders, &sender->target, sender)); 925 GNUNET_CONTAINER_multipeermap_remove(senders, &sender->target, sender));
946 GNUNET_assert (sender == GNUNET_CONTAINER_heap_remove_node (sender->hn)); 926 GNUNET_assert(sender == GNUNET_CONTAINER_heap_remove_node(sender->hn));
947 GNUNET_STATISTICS_set (stats, 927 GNUNET_STATISTICS_set(stats,
948 "# senders active", 928 "# senders active",
949 GNUNET_CONTAINER_multipeermap_size (senders), 929 GNUNET_CONTAINER_multipeermap_size(senders),
950 GNUNET_NO); 930 GNUNET_NO);
951 GNUNET_free (sender->address); 931 GNUNET_free(sender->address);
952 GNUNET_free (sender); 932 GNUNET_free(sender);
953} 933}
954 934
955 935
@@ -962,28 +942,28 @@ sender_destroy (struct SenderAddress *sender)
962 * @param iv[out] where to write the IV 942 * @param iv[out] where to write the IV
963 */ 943 */
964static void 944static void
965get_iv_key (const struct GNUNET_HashCode *msec, 945get_iv_key(const struct GNUNET_HashCode *msec,
966 uint32_t serial, 946 uint32_t serial,
967 char key[AES_KEY_SIZE], 947 char key[AES_KEY_SIZE],
968 char iv[AES_IV_SIZE]) 948 char iv[AES_IV_SIZE])
969{ 949{
970 uint32_t sid = htonl (serial); 950 uint32_t sid = htonl(serial);
971 char res[AES_KEY_SIZE + AES_IV_SIZE]; 951 char res[AES_KEY_SIZE + AES_IV_SIZE];
972 952
973 GNUNET_CRYPTO_hkdf (res, 953 GNUNET_CRYPTO_hkdf(res,
974 sizeof (res), 954 sizeof(res),
975 GCRY_MD_SHA512, 955 GCRY_MD_SHA512,
976 GCRY_MD_SHA256, 956 GCRY_MD_SHA256,
977 &sid, 957 &sid,
978 sizeof (sid), 958 sizeof(sid),
979 msec, 959 msec,
980 sizeof (*msec), 960 sizeof(*msec),
981 "UDP-IV-KEY", 961 "UDP-IV-KEY",
982 strlen ("UDP-IV-KEY"), 962 strlen("UDP-IV-KEY"),
983 NULL, 963 NULL,
984 0); 964 0);
985 memcpy (key, res, AES_KEY_SIZE); 965 memcpy(key, res, AES_KEY_SIZE);
986 memcpy (iv, &res[AES_KEY_SIZE], AES_IV_SIZE); 966 memcpy(iv, &res[AES_KEY_SIZE], AES_IV_SIZE);
987} 967}
988 968
989 969
@@ -993,11 +973,11 @@ get_iv_key (const struct GNUNET_HashCode *msec,
993 * @param sender address for which the timeout should be rescheduled 973 * @param sender address for which the timeout should be rescheduled
994 */ 974 */
995static void 975static void
996reschedule_sender_timeout (struct SenderAddress *sender) 976reschedule_sender_timeout(struct SenderAddress *sender)
997{ 977{
998 sender->timeout = 978 sender->timeout =
999 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 979 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1000 GNUNET_CONTAINER_heap_update_cost (sender->hn, sender->timeout.abs_value_us); 980 GNUNET_CONTAINER_heap_update_cost(sender->hn, sender->timeout.abs_value_us);
1001} 981}
1002 982
1003 983
@@ -1007,12 +987,12 @@ reschedule_sender_timeout (struct SenderAddress *sender)
1007 * @param receiver address for which the timeout should be rescheduled 987 * @param receiver address for which the timeout should be rescheduled
1008 */ 988 */
1009static void 989static void
1010reschedule_receiver_timeout (struct ReceiverAddress *receiver) 990reschedule_receiver_timeout(struct ReceiverAddress *receiver)
1011{ 991{
1012 receiver->timeout = 992 receiver->timeout =
1013 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 993 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1014 GNUNET_CONTAINER_heap_update_cost (receiver->hn, 994 GNUNET_CONTAINER_heap_update_cost(receiver->hn,
1015 receiver->timeout.abs_value_us); 995 receiver->timeout.abs_value_us);
1016} 996}
1017 997
1018 998
@@ -1022,7 +1002,7 @@ reschedule_receiver_timeout (struct ReceiverAddress *receiver)
1022 * @param cls unused, NULL 1002 * @param cls unused, NULL
1023 */ 1003 */
1024static void 1004static void
1025check_timeouts (void *cls) 1005check_timeouts(void *cls)
1026{ 1006{
1027 struct GNUNET_TIME_Relative st; 1007 struct GNUNET_TIME_Relative st;
1028 struct GNUNET_TIME_Relative rt; 1008 struct GNUNET_TIME_Relative rt;
@@ -1030,27 +1010,27 @@ check_timeouts (void *cls)
1030 struct ReceiverAddress *receiver; 1010 struct ReceiverAddress *receiver;
1031 struct SenderAddress *sender; 1011 struct SenderAddress *sender;
1032 1012
1033 (void) cls; 1013 (void)cls;
1034 timeout_task = NULL; 1014 timeout_task = NULL;
1035 rt = GNUNET_TIME_UNIT_FOREVER_REL; 1015 rt = GNUNET_TIME_UNIT_FOREVER_REL;
1036 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek (receivers_heap))) 1016 while (NULL != (receiver = GNUNET_CONTAINER_heap_peek(receivers_heap)))
1037 { 1017 {
1038 rt = GNUNET_TIME_absolute_get_remaining (receiver->timeout); 1018 rt = GNUNET_TIME_absolute_get_remaining(receiver->timeout);
1039 if (0 != rt.rel_value_us) 1019 if (0 != rt.rel_value_us)
1040 break; 1020 break;
1041 receiver_destroy (receiver); 1021 receiver_destroy(receiver);
1042 } 1022 }
1043 st = GNUNET_TIME_UNIT_FOREVER_REL; 1023 st = GNUNET_TIME_UNIT_FOREVER_REL;
1044 while (NULL != (sender = GNUNET_CONTAINER_heap_peek (senders_heap))) 1024 while (NULL != (sender = GNUNET_CONTAINER_heap_peek(senders_heap)))
1045 { 1025 {
1046 st = GNUNET_TIME_absolute_get_remaining (sender->timeout); 1026 st = GNUNET_TIME_absolute_get_remaining(sender->timeout);
1047 if (0 != st.rel_value_us) 1027 if (0 != st.rel_value_us)
1048 break; 1028 break;
1049 sender_destroy (sender); 1029 sender_destroy(sender);
1050 } 1030 }
1051 delay = GNUNET_TIME_relative_min (rt, st); 1031 delay = GNUNET_TIME_relative_min(rt, st);
1052 if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 1032 if (delay.rel_value_us < GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
1053 timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &check_timeouts, NULL); 1033 timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &check_timeouts, NULL);
1054} 1034}
1055 1035
1056 1036
@@ -1060,20 +1040,20 @@ check_timeouts (void *cls)
1060 * @param ss[in,out] data structure to complete 1040 * @param ss[in,out] data structure to complete
1061 */ 1041 */
1062static void 1042static void
1063calculate_cmac (struct SharedSecret *ss) 1043calculate_cmac(struct SharedSecret *ss)
1064{ 1044{
1065 GNUNET_CRYPTO_hkdf (&ss->cmac, 1045 GNUNET_CRYPTO_hkdf(&ss->cmac,
1066 sizeof (ss->cmac), 1046 sizeof(ss->cmac),
1067 GCRY_MD_SHA512, 1047 GCRY_MD_SHA512,
1068 GCRY_MD_SHA256, 1048 GCRY_MD_SHA256,
1069 "CMAC", 1049 "CMAC",
1070 strlen ("CMAC"), 1050 strlen("CMAC"),
1071 &ss->master, 1051 &ss->master,
1072 sizeof (ss->master), 1052 sizeof(ss->master),
1073 "UDP-CMAC", 1053 "UDP-CMAC",
1074 strlen ("UDP-CMAC"), 1054 strlen("UDP-CMAC"),
1075 NULL, 1055 NULL,
1076 0); 1056 0);
1077} 1057}
1078 1058
1079 1059
@@ -1086,36 +1066,36 @@ calculate_cmac (struct SharedSecret *ss)
1086 * @param plaintext_len number of bytes of plaintext received 1066 * @param plaintext_len number of bytes of plaintext received
1087 */ 1067 */
1088static void 1068static void
1089pass_plaintext_to_core (struct SenderAddress *sender, 1069pass_plaintext_to_core(struct SenderAddress *sender,
1090 const void *plaintext, 1070 const void *plaintext,
1091 size_t plaintext_len) 1071 size_t plaintext_len)
1092{ 1072{
1093 const struct GNUNET_MessageHeader *hdr = plaintext; 1073 const struct GNUNET_MessageHeader *hdr = plaintext;
1094 1074
1095 while (ntohs (hdr->size) < plaintext_len) 1075 while (ntohs(hdr->size) < plaintext_len)
1096 { 1076 {
1097 GNUNET_STATISTICS_update (stats, 1077 GNUNET_STATISTICS_update(stats,
1098 "# bytes given to core", 1078 "# bytes given to core",
1099 ntohs (hdr->size), 1079 ntohs(hdr->size),
1100 GNUNET_NO); 1080 GNUNET_NO);
1101 (void) 1081 (void)
1102 GNUNET_TRANSPORT_communicator_receive (ch, 1082 GNUNET_TRANSPORT_communicator_receive(ch,
1103 &sender->target, 1083 &sender->target,
1104 hdr, 1084 hdr,
1105 ADDRESS_VALIDITY_PERIOD, 1085 ADDRESS_VALIDITY_PERIOD,
1106 NULL /* no flow control possible */ 1086 NULL /* no flow control possible */
1107 , 1087 ,
1108 NULL); 1088 NULL);
1109 /* move on to next message, if any */ 1089 /* move on to next message, if any */
1110 plaintext_len -= ntohs (hdr->size); 1090 plaintext_len -= ntohs(hdr->size);
1111 if (plaintext_len < sizeof (*hdr)) 1091 if (plaintext_len < sizeof(*hdr))
1112 break; 1092 break;
1113 hdr = plaintext + ntohs (hdr->size); 1093 hdr = plaintext + ntohs(hdr->size);
1114 } 1094 }
1115 GNUNET_STATISTICS_update (stats, 1095 GNUNET_STATISTICS_update(stats,
1116 "# bytes padding discarded", 1096 "# bytes padding discarded",
1117 plaintext_len, 1097 plaintext_len,
1118 GNUNET_NO); 1098 GNUNET_NO);
1119} 1099}
1120 1100
1121 1101
@@ -1128,20 +1108,20 @@ pass_plaintext_to_core (struct SenderAddress *sender,
1128 * @param cipher[out] cipher to initialize 1108 * @param cipher[out] cipher to initialize
1129 */ 1109 */
1130static void 1110static void
1131setup_cipher (const struct GNUNET_HashCode *msec, 1111setup_cipher(const struct GNUNET_HashCode *msec,
1132 uint32_t serial, 1112 uint32_t serial,
1133 gcry_cipher_hd_t *cipher) 1113 gcry_cipher_hd_t *cipher)
1134{ 1114{
1135 char key[AES_KEY_SIZE]; 1115 char key[AES_KEY_SIZE];
1136 char iv[AES_IV_SIZE]; 1116 char iv[AES_IV_SIZE];
1137 1117
1138 gcry_cipher_open (cipher, 1118 gcry_cipher_open(cipher,
1139 GCRY_CIPHER_AES256 /* low level: go for speed */, 1119 GCRY_CIPHER_AES256 /* low level: go for speed */,
1140 GCRY_CIPHER_MODE_GCM, 1120 GCRY_CIPHER_MODE_GCM,
1141 0 /* flags */); 1121 0 /* flags */);
1142 get_iv_key (msec, serial, key, iv); 1122 get_iv_key(msec, serial, key, iv);
1143 gcry_cipher_setkey (*cipher, key, sizeof (key)); 1123 gcry_cipher_setkey(*cipher, key, sizeof(key));
1144 gcry_cipher_setiv (*cipher, iv, sizeof (iv)); 1124 gcry_cipher_setiv(*cipher, iv, sizeof(iv));
1145} 1125}
1146 1126
1147 1127
@@ -1158,29 +1138,29 @@ setup_cipher (const struct GNUNET_HashCode *msec,
1158 * @return #GNUNET_OK on success 1138 * @return #GNUNET_OK on success
1159 */ 1139 */
1160static int 1140static int
1161try_decrypt (const struct SharedSecret *ss, 1141try_decrypt(const struct SharedSecret *ss,
1162 const char tag[GCM_TAG_SIZE], 1142 const char tag[GCM_TAG_SIZE],
1163 uint32_t serial, 1143 uint32_t serial,
1164 const char *in_buf, 1144 const char *in_buf,
1165 size_t in_buf_size, 1145 size_t in_buf_size,
1166 char *out_buf) 1146 char *out_buf)
1167{ 1147{
1168 gcry_cipher_hd_t cipher; 1148 gcry_cipher_hd_t cipher;
1169 1149
1170 setup_cipher (&ss->master, serial, &cipher); 1150 setup_cipher(&ss->master, serial, &cipher);
1171 GNUNET_assert ( 1151 GNUNET_assert(
1172 0 == 1152 0 ==
1173 gcry_cipher_decrypt (cipher, out_buf, in_buf_size, in_buf, in_buf_size)); 1153 gcry_cipher_decrypt(cipher, out_buf, in_buf_size, in_buf, in_buf_size));
1174 if (0 != gcry_cipher_checktag (cipher, tag, GCM_TAG_SIZE)) 1154 if (0 != gcry_cipher_checktag(cipher, tag, GCM_TAG_SIZE))
1175 { 1155 {
1176 gcry_cipher_close (cipher); 1156 gcry_cipher_close(cipher);
1177 GNUNET_STATISTICS_update (stats, 1157 GNUNET_STATISTICS_update(stats,
1178 "# AEAD authentication failures", 1158 "# AEAD authentication failures",
1179 1, 1159 1,
1180 GNUNET_NO); 1160 GNUNET_NO);
1181 return GNUNET_SYSERR; 1161 return GNUNET_SYSERR;
1182 } 1162 }
1183 gcry_cipher_close (cipher); 1163 gcry_cipher_close(cipher);
1184 return GNUNET_OK; 1164 return GNUNET_OK;
1185} 1165}
1186 1166
@@ -1192,12 +1172,12 @@ try_decrypt (const struct SharedSecret *ss,
1192 * @return new shared secret 1172 * @return new shared secret
1193 */ 1173 */
1194static struct SharedSecret * 1174static struct SharedSecret *
1195setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral) 1175setup_shared_secret_dec(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
1196{ 1176{
1197 struct SharedSecret *ss; 1177 struct SharedSecret *ss;
1198 1178
1199 ss = GNUNET_new (struct SharedSecret); 1179 ss = GNUNET_new(struct SharedSecret);
1200 GNUNET_CRYPTO_eddsa_ecdh (my_private_key, ephemeral, &ss->master); 1180 GNUNET_CRYPTO_eddsa_ecdh(my_private_key, ephemeral, &ss->master);
1201 return ss; 1181 return ss;
1202} 1182}
1203 1183
@@ -1210,20 +1190,20 @@ setup_shared_secret_dec (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral)
1210 * @return new shared secret 1190 * @return new shared secret
1211 */ 1191 */
1212static struct SharedSecret * 1192static struct SharedSecret *
1213setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral, 1193setup_shared_secret_enc(const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
1214 struct ReceiverAddress *receiver) 1194 struct ReceiverAddress *receiver)
1215{ 1195{
1216 struct SharedSecret *ss; 1196 struct SharedSecret *ss;
1217 1197
1218 ss = GNUNET_new (struct SharedSecret); 1198 ss = GNUNET_new(struct SharedSecret);
1219 GNUNET_CRYPTO_ecdh_eddsa (ephemeral, 1199 GNUNET_CRYPTO_ecdh_eddsa(ephemeral,
1220 &receiver->target.public_key, 1200 &receiver->target.public_key,
1221 &ss->master); 1201 &ss->master);
1222 calculate_cmac (ss); 1202 calculate_cmac(ss);
1223 ss->receiver = receiver; 1203 ss->receiver = receiver;
1224 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss); 1204 GNUNET_CONTAINER_DLL_insert(receiver->ss_head, receiver->ss_tail, ss);
1225 receiver->num_secrets++; 1205 receiver->num_secrets++;
1226 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO); 1206 GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO);
1227 return ss; 1207 return ss;
1228} 1208}
1229 1209
@@ -1236,7 +1216,7 @@ setup_shared_secret_enc (const struct GNUNET_CRYPTO_EcdhePrivateKey *ephemeral,
1236 * @param receiver receiver to setup MQ for 1216 * @param receiver receiver to setup MQ for
1237 */ 1217 */
1238static void 1218static void
1239setup_receiver_mq (struct ReceiverAddress *receiver); 1219setup_receiver_mq(struct ReceiverAddress *receiver);
1240 1220
1241 1221
1242/** 1222/**
@@ -1250,36 +1230,36 @@ setup_receiver_mq (struct ReceiverAddress *receiver);
1250 * @return #GNUNET_YES to continue to iterate 1230 * @return #GNUNET_YES to continue to iterate
1251 */ 1231 */
1252static int 1232static int
1253handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) 1233handle_ack(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1254{ 1234{
1255 const struct UDPAck *ack = cls; 1235 const struct UDPAck *ack = cls;
1256 struct ReceiverAddress *receiver = value; 1236 struct ReceiverAddress *receiver = value;
1257 1237
1258 (void) pid; 1238 (void)pid;
1259 for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next) 1239 for (struct SharedSecret *ss = receiver->ss_head; NULL != ss; ss = ss->next)
1260 {
1261 if (0 == memcmp (&ack->cmac, &ss->cmac, sizeof (struct GNUNET_HashCode)))
1262 { 1240 {
1263 uint32_t allowed; 1241 if (0 == memcmp(&ack->cmac, &ss->cmac, sizeof(struct GNUNET_HashCode)))
1264
1265 allowed = ntohl (ack->sequence_max);
1266
1267 if (allowed > ss->sequence_allowed)
1268 {
1269 receiver->acks_available += (allowed - ss->sequence_allowed);
1270 if ((allowed - ss->sequence_allowed) == receiver->acks_available)
1271 { 1242 {
1272 /* we just incremented from zero => MTU change! */ 1243 uint32_t allowed;
1273 setup_receiver_mq (receiver); 1244
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;
1274 } 1261 }
1275 ss->sequence_allowed = allowed;
1276 /* move ss to head to avoid discarding it anytime soon! */
1277 GNUNET_CONTAINER_DLL_remove (receiver->ss_head, receiver->ss_tail, ss);
1278 GNUNET_CONTAINER_DLL_insert (receiver->ss_head, receiver->ss_tail, ss);
1279 }
1280 return GNUNET_NO;
1281 } 1262 }
1282 }
1283 return GNUNET_YES; 1263 return GNUNET_YES;
1284} 1264}
1285 1265
@@ -1293,39 +1273,41 @@ handle_ack (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
1293 * @param buf_size number of bytes in @a buf 1273 * @param buf_size number of bytes in @a buf
1294 */ 1274 */
1295static void 1275static void
1296try_handle_plaintext (struct SenderAddress *sender, 1276try_handle_plaintext(struct SenderAddress *sender,
1297 const void *buf, 1277 const void *buf,
1298 size_t buf_size) 1278 size_t buf_size)
1299{ 1279{
1300 const struct GNUNET_MessageHeader *hdr = 1280 const struct GNUNET_MessageHeader *hdr =
1301 (const struct GNUNET_MessageHeader *) buf; 1281 (const struct GNUNET_MessageHeader *)buf;
1302 const struct UDPAck *ack = (const struct UDPAck *) buf; 1282 const struct UDPAck *ack = (const struct UDPAck *)buf;
1303 uint16_t type; 1283 uint16_t type;
1304 1284
1305 if (sizeof (*hdr) > buf_size) 1285 if (sizeof(*hdr) > buf_size)
1306 return; /* not even a header */ 1286 return; /* not even a header */
1307 if (ntohs (hdr->size) > buf_size) 1287 if (ntohs(hdr->size) > buf_size)
1308 return; /* not even a header */ 1288 return; /* not even a header */
1309 type = ntohs (hdr->type); 1289 type = ntohs(hdr->type);
1310 switch (type) 1290 switch (type)
1311 { 1291 {
1312 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK: 1292 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK:
1313 /* lookup master secret by 'cmac', then update sequence_max */ 1293 /* lookup master secret by 'cmac', then update sequence_max */
1314 GNUNET_CONTAINER_multipeermap_get_multiple (receivers, 1294 GNUNET_CONTAINER_multipeermap_get_multiple(receivers,
1315 &sender->target, 1295 &sender->target,
1316 &handle_ack, 1296 &handle_ack,
1317 (void *) ack); 1297 (void *)ack);
1318 /* There could be more messages after the ACK, handle those as well */ 1298 /* There could be more messages after the ACK, handle those as well */
1319 buf += ntohs (hdr->size); 1299 buf += ntohs(hdr->size);
1320 buf_size -= ntohs (hdr->size); 1300 buf_size -= ntohs(hdr->size);
1321 pass_plaintext_to_core (sender, buf, buf_size); 1301 pass_plaintext_to_core(sender, buf, buf_size);
1322 break; 1302 break;
1323 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD: 1303
1324 /* skip padding */ 1304 case GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD:
1325 break; 1305 /* skip padding */
1326 default: 1306 break;
1327 pass_plaintext_to_core (sender, buf, buf_size); 1307
1328 } 1308 default:
1309 pass_plaintext_to_core(sender, buf, buf_size);
1310 }
1329} 1311}
1330 1312
1331 1313
@@ -1338,29 +1320,29 @@ try_handle_plaintext (struct SenderAddress *sender,
1338 * @param ss shared secret to generate ACKs for 1320 * @param ss shared secret to generate ACKs for
1339 */ 1321 */
1340static void 1322static void
1341consider_ss_ack (struct SharedSecret *ss) 1323consider_ss_ack(struct SharedSecret *ss)
1342{ 1324{
1343 GNUNET_assert (NULL != ss->sender); 1325 GNUNET_assert(NULL != ss->sender);
1344 /* drop ancient KeyCacheEntries */ 1326 /* drop ancient KeyCacheEntries */
1345 while ((NULL != ss->kce_head) && 1327 while ((NULL != ss->kce_head) &&
1346 (MAX_SQN_DELTA < 1328 (MAX_SQN_DELTA <
1347 ss->kce_head->sequence_number - ss->kce_tail->sequence_number)) 1329 ss->kce_head->sequence_number - ss->kce_tail->sequence_number))
1348 kce_destroy (ss->kce_tail); 1330 kce_destroy(ss->kce_tail);
1349 if (ss->active_kce_count < KCN_THRESHOLD) 1331 if (ss->active_kce_count < KCN_THRESHOLD)
1350 { 1332 {
1351 struct UDPAck ack; 1333 struct UDPAck ack;
1352 1334
1353 while (ss->active_kce_count < KCN_TARGET) 1335 while (ss->active_kce_count < KCN_TARGET)
1354 kce_generate (ss, ++ss->sequence_allowed); 1336 kce_generate(ss, ++ss->sequence_allowed);
1355 ack.header.type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK); 1337 ack.header.type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK);
1356 ack.header.size = htons (sizeof (ack)); 1338 ack.header.size = htons(sizeof(ack));
1357 ack.sequence_max = htonl (ss->sequence_allowed); 1339 ack.sequence_max = htonl(ss->sequence_allowed);
1358 ack.cmac = ss->cmac; 1340 ack.cmac = ss->cmac;
1359 GNUNET_TRANSPORT_communicator_notify (ch, 1341 GNUNET_TRANSPORT_communicator_notify(ch,
1360 &ss->sender->target, 1342 &ss->sender->target,
1361 COMMUNICATOR_ADDRESS_PREFIX, 1343 COMMUNICATOR_ADDRESS_PREFIX,
1362 &ack.header); 1344 &ack.header);
1363 } 1345 }
1364} 1346}
1365 1347
1366 1348
@@ -1372,43 +1354,42 @@ consider_ss_ack (struct SharedSecret *ss)
1372 * @param kce key index to decrypt @a box 1354 * @param kce key index to decrypt @a box
1373 */ 1355 */
1374static void 1356static void
1375decrypt_box (const struct UDPBox *box, 1357decrypt_box(const struct UDPBox *box,
1376 size_t box_len, 1358 size_t box_len,
1377 struct KeyCacheEntry *kce) 1359 struct KeyCacheEntry *kce)
1378{ 1360{
1379 struct SharedSecret *ss = kce->ss; 1361 struct SharedSecret *ss = kce->ss;
1380 char out_buf[box_len - sizeof (*box)]; 1362 char out_buf[box_len - sizeof(*box)];
1381 1363
1382 GNUNET_assert (NULL != ss->sender); 1364 GNUNET_assert(NULL != ss->sender);
1383 if (GNUNET_OK != try_decrypt (ss, 1365 if (GNUNET_OK != try_decrypt(ss,
1384 box->gcm_tag, 1366 box->gcm_tag,
1385 kce->sequence_number, 1367 kce->sequence_number,
1386 (const char *) &box[1], 1368 (const char *)&box[1],
1387 sizeof (out_buf), 1369 sizeof(out_buf),
1388 out_buf)) 1370 out_buf))
1389 { 1371 {
1390 GNUNET_STATISTICS_update (stats, 1372 GNUNET_STATISTICS_update(stats,
1391 "# Decryption failures with valid KCE", 1373 "# Decryption failures with valid KCE",
1392 1, 1374 1,
1393 GNUNET_NO); 1375 GNUNET_NO);
1394 kce_destroy (kce); 1376 kce_destroy(kce);
1395 return; 1377 return;
1396 } 1378 }
1397 kce_destroy (kce); 1379 kce_destroy(kce);
1398 GNUNET_STATISTICS_update (stats, 1380 GNUNET_STATISTICS_update(stats,
1399 "# bytes decrypted with BOX", 1381 "# bytes decrypted with BOX",
1400 sizeof (out_buf), 1382 sizeof(out_buf),
1401 GNUNET_NO); 1383 GNUNET_NO);
1402 try_handle_plaintext (ss->sender, out_buf, sizeof (out_buf)); 1384 try_handle_plaintext(ss->sender, out_buf, sizeof(out_buf));
1403 consider_ss_ack (ss); 1385 consider_ss_ack(ss);
1404} 1386}
1405 1387
1406 1388
1407/** 1389/**
1408 * Closure for #find_sender_by_address() 1390 * Closure for #find_sender_by_address()
1409 */ 1391 */
1410struct SearchContext 1392struct SearchContext {
1411{
1412 /** 1393 /**
1413 * Address we are looking for. 1394 * Address we are looking for.
1414 */ 1395 */
@@ -1435,19 +1416,19 @@ struct SearchContext
1435 * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found 1416 * @return #GNUNET_YES if not found (continue to search), #GNUNET_NO if found
1436 */ 1417 */
1437static int 1418static int
1438find_sender_by_address (void *cls, 1419find_sender_by_address(void *cls,
1439 const struct GNUNET_PeerIdentity *key, 1420 const struct GNUNET_PeerIdentity *key,
1440 void *value) 1421 void *value)
1441{ 1422{
1442 struct SearchContext *sc = cls; 1423 struct SearchContext *sc = cls;
1443 struct SenderAddress *sender = value; 1424 struct SenderAddress *sender = value;
1444 1425
1445 if ((sender->address_len == sc->address_len) && 1426 if ((sender->address_len == sc->address_len) &&
1446 (0 == memcmp (sender->address, sc->address, sender->address_len))) 1427 (0 == memcmp(sender->address, sc->address, sender->address_len)))
1447 { 1428 {
1448 sc->sender = sender; 1429 sc->sender = sender;
1449 return GNUNET_NO; /* stop iterating! */ 1430 return GNUNET_NO; /* stop iterating! */
1450 } 1431 }
1451 return GNUNET_YES; 1432 return GNUNET_YES;
1452} 1433}
1453 1434
@@ -1464,45 +1445,45 @@ find_sender_by_address (void *cls,
1464 * decrypting data from @a target 1445 * decrypting data from @a target
1465 */ 1446 */
1466static struct SenderAddress * 1447static struct SenderAddress *
1467setup_sender (const struct GNUNET_PeerIdentity *target, 1448setup_sender(const struct GNUNET_PeerIdentity *target,
1468 const struct sockaddr *address, 1449 const struct sockaddr *address,
1469 socklen_t address_len) 1450 socklen_t address_len)
1470{ 1451{
1471 struct SenderAddress *sender; 1452 struct SenderAddress *sender;
1472 struct SearchContext sc = {.address = address, 1453 struct SearchContext sc = { .address = address,
1473 .address_len = address_len, 1454 .address_len = address_len,
1474 .sender = NULL}; 1455 .sender = NULL };
1475 1456
1476 GNUNET_CONTAINER_multipeermap_get_multiple (senders, 1457 GNUNET_CONTAINER_multipeermap_get_multiple(senders,
1477 target, 1458 target,
1478 &find_sender_by_address, 1459 &find_sender_by_address,
1479 &sc); 1460 &sc);
1480 if (NULL != sc.sender) 1461 if (NULL != sc.sender)
1481 { 1462 {
1482 reschedule_sender_timeout (sc.sender); 1463 reschedule_sender_timeout(sc.sender);
1483 return sc.sender; 1464 return sc.sender;
1484 } 1465 }
1485 sender = GNUNET_new (struct SenderAddress); 1466 sender = GNUNET_new(struct SenderAddress);
1486 sender->target = *target; 1467 sender->target = *target;
1487 sender->address = GNUNET_memdup (address, address_len); 1468 sender->address = GNUNET_memdup(address, address_len);
1488 sender->address_len = address_len; 1469 sender->address_len = address_len;
1489 (void) GNUNET_CONTAINER_multipeermap_put ( 1470 (void)GNUNET_CONTAINER_multipeermap_put(
1490 senders, 1471 senders,
1491 &sender->target, 1472 &sender->target,
1492 sender, 1473 sender,
1493 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1474 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1494 GNUNET_STATISTICS_set (stats, 1475 GNUNET_STATISTICS_set(stats,
1495 "# senders active", 1476 "# senders active",
1496 GNUNET_CONTAINER_multipeermap_size (receivers), 1477 GNUNET_CONTAINER_multipeermap_size(receivers),
1497 GNUNET_NO); 1478 GNUNET_NO);
1498 sender->timeout = 1479 sender->timeout =
1499 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1480 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1500 sender->hn = GNUNET_CONTAINER_heap_insert (senders_heap, 1481 sender->hn = GNUNET_CONTAINER_heap_insert(senders_heap,
1501 sender, 1482 sender,
1502 sender->timeout.abs_value_us); 1483 sender->timeout.abs_value_us);
1503 sender->nt = GNUNET_NT_scanner_get_type (is, address, address_len); 1484 sender->nt = GNUNET_NT_scanner_get_type(is, address, address_len);
1504 if (NULL == timeout_task) 1485 if (NULL == timeout_task)
1505 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); 1486 timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL);
1506 return sender; 1487 return sender;
1507} 1488}
1508 1489
@@ -1515,21 +1496,21 @@ setup_sender (const struct GNUNET_PeerIdentity *target,
1515 * @return #GNUNET_OK if signature is valid 1496 * @return #GNUNET_OK if signature is valid
1516 */ 1497 */
1517static int 1498static int
1518verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, 1499verify_confirmation(const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
1519 const struct UDPConfirmation *uc) 1500 const struct UDPConfirmation *uc)
1520{ 1501{
1521 struct UdpHandshakeSignature uhs; 1502 struct UdpHandshakeSignature uhs;
1522 1503
1523 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); 1504 uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
1524 uhs.purpose.size = htonl (sizeof (uhs)); 1505 uhs.purpose.size = htonl(sizeof(uhs));
1525 uhs.sender = uc->sender; 1506 uhs.sender = uc->sender;
1526 uhs.receiver = my_identity; 1507 uhs.receiver = my_identity;
1527 uhs.ephemeral = *ephemeral; 1508 uhs.ephemeral = *ephemeral;
1528 uhs.monotonic_time = uc->monotonic_time; 1509 uhs.monotonic_time = uc->monotonic_time;
1529 return GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE, 1510 return GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE,
1530 &uhs.purpose, 1511 &uhs.purpose,
1531 &uc->sender_sig, 1512 &uc->sender_sig,
1532 &uc->sender.public_key); 1513 &uc->sender.public_key);
1533} 1514}
1534 1515
1535 1516
@@ -1542,28 +1523,30 @@ verify_confirmation (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
1542 * @return string representation of @a address 1523 * @return string representation of @a address
1543 */ 1524 */
1544static char * 1525static char *
1545sockaddr_to_udpaddr_string (const struct sockaddr *address, 1526sockaddr_to_udpaddr_string(const struct sockaddr *address,
1546 socklen_t address_len) 1527 socklen_t address_len)
1547{ 1528{
1548 char *ret; 1529 char *ret;
1549 1530
1550 switch (address->sa_family) 1531 switch (address->sa_family)
1551 { 1532 {
1552 case AF_INET: 1533 case AF_INET:
1553 GNUNET_asprintf (&ret, 1534 GNUNET_asprintf(&ret,
1554 "%s-%s", 1535 "%s-%s",
1555 COMMUNICATOR_ADDRESS_PREFIX, 1536 COMMUNICATOR_ADDRESS_PREFIX,
1556 GNUNET_a2s (address, address_len)); 1537 GNUNET_a2s(address, address_len));
1557 break; 1538 break;
1558 case AF_INET6: 1539
1559 GNUNET_asprintf (&ret, 1540 case AF_INET6:
1560 "%s-%s", 1541 GNUNET_asprintf(&ret,
1561 COMMUNICATOR_ADDRESS_PREFIX, 1542 "%s-%s",
1562 GNUNET_a2s (address, address_len)); 1543 COMMUNICATOR_ADDRESS_PREFIX,
1563 break; 1544 GNUNET_a2s(address, address_len));
1564 default: 1545 break;
1565 GNUNET_assert (0); 1546
1566 } 1547 default:
1548 GNUNET_assert(0);
1549 }
1567 return ret; 1550 return ret;
1568} 1551}
1569 1552
@@ -1574,137 +1557,137 @@ sockaddr_to_udpaddr_string (const struct sockaddr *address,
1574 * @param cls NULL 1557 * @param cls NULL
1575 */ 1558 */
1576static void 1559static void
1577sock_read (void *cls) 1560sock_read(void *cls)
1578{ 1561{
1579 struct sockaddr_storage sa; 1562 struct sockaddr_storage sa;
1580 socklen_t salen = sizeof (sa); 1563 socklen_t salen = sizeof(sa);
1581 char buf[UINT16_MAX]; 1564 char buf[UINT16_MAX];
1582 ssize_t rcvd; 1565 ssize_t rcvd;
1583 1566
1584 (void) cls; 1567 (void)cls;
1585 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1568 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
1586 udp_sock, 1569 udp_sock,
1587 &sock_read, 1570 &sock_read,
1588 NULL); 1571 NULL);
1589 rcvd = GNUNET_NETWORK_socket_recvfrom (udp_sock, 1572 rcvd = GNUNET_NETWORK_socket_recvfrom(udp_sock,
1590 buf, 1573 buf,
1591 sizeof (buf), 1574 sizeof(buf),
1592 (struct sockaddr *) &sa, 1575 (struct sockaddr *)&sa,
1593 &salen); 1576 &salen);
1594 if (-1 == rcvd) 1577 if (-1 == rcvd)
1595 { 1578 {
1596 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "recv"); 1579 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "recv");
1597 return; 1580 return;
1598 } 1581 }
1599 1582
1600 /* first, see if it is a UDPBox */ 1583 /* first, see if it is a UDPBox */
1601 if (rcvd > sizeof (struct UDPBox)) 1584 if (rcvd > sizeof(struct UDPBox))
1602 {
1603 const struct UDPBox *box;
1604 struct KeyCacheEntry *kce;
1605
1606 box = (const struct UDPBox *) buf;
1607 kce = GNUNET_CONTAINER_multishortmap_get (key_cache, &box->kid);
1608 if (NULL != kce)
1609 { 1585 {
1610 decrypt_box (box, (size_t) rcvd, kce); 1586 const struct UDPBox *box;
1611 return; 1587 struct KeyCacheEntry *kce;
1588
1589 box = (const struct UDPBox *)buf;
1590 kce = GNUNET_CONTAINER_multishortmap_get(key_cache, &box->kid);
1591 if (NULL != kce)
1592 {
1593 decrypt_box(box, (size_t)rcvd, kce);
1594 return;
1595 }
1612 } 1596 }
1613 }
1614 1597
1615 /* next, check if it is a broadcast */ 1598 /* next, check if it is a broadcast */
1616 if (sizeof (struct UDPBroadcast) == rcvd) 1599 if (sizeof(struct UDPBroadcast) == rcvd)
1617 {
1618 const struct UDPBroadcast *ub;
1619 struct UdpBroadcastSignature uhs;
1620
1621 ub = (const struct UDPBroadcast *) buf;
1622 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
1623 uhs.purpose.size = htonl (sizeof (uhs));
1624 uhs.sender = ub->sender;
1625 GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
1626 if (GNUNET_OK ==
1627 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
1628 &uhs.purpose,
1629 &ub->sender_sig,
1630 &ub->sender.public_key))
1631 { 1600 {
1632 char *addr_s; 1601 const struct UDPBroadcast *ub;
1633 enum GNUNET_NetworkType nt; 1602 struct UdpBroadcastSignature uhs;
1634 1603
1635 addr_s = 1604 ub = (const struct UDPBroadcast *)buf;
1636 sockaddr_to_udpaddr_string ((const struct sockaddr *) &sa, salen); 1605 uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
1637 GNUNET_STATISTICS_update (stats, "# broadcasts received", 1, GNUNET_NO); 1606 uhs.purpose.size = htonl(sizeof(uhs));
1638 /* use our own mechanism to determine network type */ 1607 uhs.sender = ub->sender;
1639 nt = 1608 GNUNET_CRYPTO_hash(&sa, salen, &uhs.h_address);
1640 GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen); 1609 if (GNUNET_OK ==
1641 GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s); 1610 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
1642 GNUNET_free (addr_s); 1611 &uhs.purpose,
1643 return; 1612 &ub->sender_sig,
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... */
1644 } 1629 }
1645 /* continue with KX, mostly for statistics... */
1646 }
1647 1630
1648 1631
1649 /* finally, test if it is a KX */ 1632 /* finally, test if it is a KX */
1650 if (rcvd < sizeof (struct UDPConfirmation) + sizeof (struct InitialKX)) 1633 if (rcvd < sizeof(struct UDPConfirmation) + sizeof(struct InitialKX))
1651 { 1634 {
1652 GNUNET_STATISTICS_update (stats, 1635 GNUNET_STATISTICS_update(stats,
1653 "# messages dropped (no kid, too small for KX)", 1636 "# messages dropped (no kid, too small for KX)",
1654 1, 1637 1,
1655 GNUNET_NO); 1638 GNUNET_NO);
1656 return; 1639 return;
1657 } 1640 }
1658 1641
1659 { 1642 {
1660 const struct InitialKX *kx; 1643 const struct InitialKX *kx;
1661 struct SharedSecret *ss; 1644 struct SharedSecret *ss;
1662 char pbuf[rcvd - sizeof (struct InitialKX)]; 1645 char pbuf[rcvd - sizeof(struct InitialKX)];
1663 const struct UDPConfirmation *uc; 1646 const struct UDPConfirmation *uc;
1664 struct SenderAddress *sender; 1647 struct SenderAddress *sender;
1665 1648
1666 kx = (const struct InitialKX *) buf; 1649 kx = (const struct InitialKX *)buf;
1667 ss = setup_shared_secret_dec (&kx->ephemeral); 1650 ss = setup_shared_secret_dec(&kx->ephemeral);
1668 if (GNUNET_OK != try_decrypt (ss, 1651 if (GNUNET_OK != try_decrypt(ss,
1669 kx->gcm_tag, 1652 kx->gcm_tag,
1670 0, 1653 0,
1671 &buf[sizeof (*kx)], 1654 &buf[sizeof(*kx)],
1672 sizeof (pbuf), 1655 sizeof(pbuf),
1673 pbuf)) 1656 pbuf))
1674 { 1657 {
1675 GNUNET_free (ss); 1658 GNUNET_free(ss);
1676 GNUNET_STATISTICS_update ( 1659 GNUNET_STATISTICS_update(
1677 stats, 1660 stats,
1678 "# messages dropped (no kid, AEAD decryption failed)", 1661 "# messages dropped (no kid, AEAD decryption failed)",
1679 1, 1662 1,
1680 GNUNET_NO); 1663 GNUNET_NO);
1681 return; 1664 return;
1682 } 1665 }
1683 uc = (const struct UDPConfirmation *) pbuf; 1666 uc = (const struct UDPConfirmation *)pbuf;
1684 if (GNUNET_OK != verify_confirmation (&kx->ephemeral, uc)) 1667 if (GNUNET_OK != verify_confirmation(&kx->ephemeral, uc))
1685 { 1668 {
1686 GNUNET_break_op (0); 1669 GNUNET_break_op(0);
1687 GNUNET_free (ss); 1670 GNUNET_free(ss);
1688 GNUNET_STATISTICS_update (stats, 1671 GNUNET_STATISTICS_update(stats,
1689 "# messages dropped (sender signature invalid)", 1672 "# messages dropped (sender signature invalid)",
1690 1, 1673 1,
1691 GNUNET_NO); 1674 GNUNET_NO);
1692 return; 1675 return;
1693 } 1676 }
1694 calculate_cmac (ss); 1677 calculate_cmac(ss);
1695 sender = setup_sender (&uc->sender, (const struct sockaddr *) &sa, salen); 1678 sender = setup_sender(&uc->sender, (const struct sockaddr *)&sa, salen);
1696 ss->sender = sender; 1679 ss->sender = sender;
1697 GNUNET_CONTAINER_DLL_insert (sender->ss_head, sender->ss_tail, ss); 1680 GNUNET_CONTAINER_DLL_insert(sender->ss_head, sender->ss_tail, ss);
1698 sender->num_secrets++; 1681 sender->num_secrets++;
1699 GNUNET_STATISTICS_update (stats, "# Secrets active", 1, GNUNET_NO); 1682 GNUNET_STATISTICS_update(stats, "# Secrets active", 1, GNUNET_NO);
1700 GNUNET_STATISTICS_update (stats, 1683 GNUNET_STATISTICS_update(stats,
1701 "# messages decrypted without BOX", 1684 "# messages decrypted without BOX",
1702 1, 1685 1,
1703 GNUNET_NO); 1686 GNUNET_NO);
1704 try_handle_plaintext (sender, &uc[1], sizeof (pbuf) - sizeof (*uc)); 1687 try_handle_plaintext(sender, &uc[1], sizeof(pbuf) - sizeof(*uc));
1705 consider_ss_ack (ss); 1688 consider_ss_ack(ss);
1706 if (sender->num_secrets > MAX_SECRETS) 1689 if (sender->num_secrets > MAX_SECRETS)
1707 secret_destroy (sender->ss_tail); 1690 secret_destroy(sender->ss_tail);
1708 } 1691 }
1709} 1692}
1710 1693
@@ -1717,7 +1700,7 @@ sock_read (void *cls)
1717 * @return converted bindto specification 1700 * @return converted bindto specification
1718 */ 1701 */
1719static struct sockaddr * 1702static struct sockaddr *
1720udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) 1703udp_address_to_sockaddr(const char *bindto, socklen_t *sock_len)
1721{ 1704{
1722 struct sockaddr *in; 1705 struct sockaddr *in;
1723 unsigned int port; 1706 unsigned int port;
@@ -1725,88 +1708,88 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1725 char *colon; 1708 char *colon;
1726 char *cp; 1709 char *cp;
1727 1710
1728 if (1 == sscanf (bindto, "%u%1s", &port, dummy)) 1711 if (1 == sscanf(bindto, "%u%1s", &port, dummy))
1729 {
1730 /* interpreting value as just a PORT number */
1731 if (port > UINT16_MAX)
1732 {
1733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1734 "BINDTO specification `%s' invalid: value too large for port\n",
1735 bindto);
1736 return NULL;
1737 }
1738 if ((GNUNET_NO == GNUNET_NETWORK_test_pf (PF_INET6)) ||
1739 (GNUNET_YES ==
1740 GNUNET_CONFIGURATION_get_value_yesno (cfg,
1741 COMMUNICATOR_CONFIG_SECTION,
1742 "DISABLE_V6")))
1743 { 1712 {
1744 struct sockaddr_in *i4; 1713 /* interpreting value as just a PORT number */
1714 if (port > UINT16_MAX)
1715 {
1716 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1717 "BINDTO specification `%s' invalid: value too large for port\n",
1718 bindto);
1719 return NULL;
1720 }
1721 if ((GNUNET_NO == GNUNET_NETWORK_test_pf(PF_INET6)) ||
1722 (GNUNET_YES ==
1723 GNUNET_CONFIGURATION_get_value_yesno(cfg,
1724 COMMUNICATOR_CONFIG_SECTION,
1725 "DISABLE_V6")))
1726 {
1727 struct sockaddr_in *i4;
1745 1728
1746 i4 = GNUNET_malloc (sizeof (struct sockaddr_in)); 1729 i4 = GNUNET_malloc(sizeof(struct sockaddr_in));
1747 i4->sin_family = AF_INET; 1730 i4->sin_family = AF_INET;
1748 i4->sin_port = htons ((uint16_t) port); 1731 i4->sin_port = htons((uint16_t)port);
1749 *sock_len = sizeof (struct sockaddr_in); 1732 *sock_len = sizeof(struct sockaddr_in);
1750 in = (struct sockaddr *) i4; 1733 in = (struct sockaddr *)i4;
1751 } 1734 }
1752 else 1735 else
1753 { 1736 {
1754 struct sockaddr_in6 *i6; 1737 struct sockaddr_in6 *i6;
1755 1738
1756 i6 = GNUNET_malloc (sizeof (struct sockaddr_in6)); 1739 i6 = GNUNET_malloc(sizeof(struct sockaddr_in6));
1757 i6->sin6_family = AF_INET6; 1740 i6->sin6_family = AF_INET6;
1758 i6->sin6_port = htons ((uint16_t) port); 1741 i6->sin6_port = htons((uint16_t)port);
1759 *sock_len = sizeof (struct sockaddr_in6); 1742 *sock_len = sizeof(struct sockaddr_in6);
1760 in = (struct sockaddr *) i6; 1743 in = (struct sockaddr *)i6;
1744 }
1745 return in;
1761 } 1746 }
1762 return in; 1747 cp = GNUNET_strdup(bindto);
1763 } 1748 colon = strrchr(cp, ':');
1764 cp = GNUNET_strdup (bindto);
1765 colon = strrchr (cp, ':');
1766 if (NULL != colon) 1749 if (NULL != colon)
1767 {
1768 /* interpet value after colon as port */
1769 *colon = '\0';
1770 colon++;
1771 if (1 == sscanf (colon, "%u%1s", &port, dummy))
1772 { 1750 {
1773 /* interpreting value as just a PORT number */ 1751 /* interpet value after colon as port */
1774 if (port > UINT16_MAX) 1752 *colon = '\0';
1775 { 1753 colon++;
1776 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1754 if (1 == sscanf(colon, "%u%1s", &port, dummy))
1777 "BINDTO specification `%s' invalid: value too large for port\n", 1755 {
1778 bindto); 1756 /* interpreting value as just a PORT number */
1779 GNUNET_free (cp); 1757 if (port > UINT16_MAX)
1780 return NULL; 1758 {
1781 } 1759 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
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 }
1782 } 1775 }
1783 else 1776 else
1784 { 1777 {
1785 GNUNET_log ( 1778 /* interpret missing port as 0, aka pick any free one */
1786 GNUNET_ERROR_TYPE_ERROR, 1779 port = 0;
1787 "BINDTO specification `%s' invalid: last ':' not followed by number\n",
1788 bindto);
1789 GNUNET_free (cp);
1790 return NULL;
1791 } 1780 }
1792 }
1793 else
1794 {
1795 /* interpret missing port as 0, aka pick any free one */
1796 port = 0;
1797 }
1798 { 1781 {
1799 /* try IPv4 */ 1782 /* try IPv4 */
1800 struct sockaddr_in v4; 1783 struct sockaddr_in v4;
1801 1784
1802 if (1 == inet_pton (AF_INET, cp, &v4)) 1785 if (1 == inet_pton(AF_INET, cp, &v4))
1803 { 1786 {
1804 v4.sin_port = htons ((uint16_t) port); 1787 v4.sin_port = htons((uint16_t)port);
1805 in = GNUNET_memdup (&v4, sizeof (v4)); 1788 in = GNUNET_memdup(&v4, sizeof(v4));
1806 *sock_len = sizeof (v4); 1789 *sock_len = sizeof(v4);
1807 GNUNET_free (cp); 1790 GNUNET_free(cp);
1808 return in; 1791 return in;
1809 } 1792 }
1810 } 1793 }
1811 { 1794 {
1812 /* try IPv6 */ 1795 /* try IPv6 */
@@ -1814,22 +1797,22 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1814 const char *start; 1797 const char *start;
1815 1798
1816 start = cp; 1799 start = cp;
1817 if (('[' == *cp) && (']' == cp[strlen (cp) - 1])) 1800 if (('[' == *cp) && (']' == cp[strlen(cp) - 1]))
1818 { 1801 {
1819 start++; /* skip over '[' */ 1802 start++; /* skip over '[' */
1820 cp[strlen (cp) - 1] = '\0'; /* eat ']' */ 1803 cp[strlen(cp) - 1] = '\0'; /* eat ']' */
1821 } 1804 }
1822 if (1 == inet_pton (AF_INET6, start, &v6)) 1805 if (1 == inet_pton(AF_INET6, start, &v6))
1823 { 1806 {
1824 v6.sin6_port = htons ((uint16_t) port); 1807 v6.sin6_port = htons((uint16_t)port);
1825 in = GNUNET_memdup (&v6, sizeof (v6)); 1808 in = GNUNET_memdup(&v6, sizeof(v6));
1826 *sock_len = sizeof (v6); 1809 *sock_len = sizeof(v6);
1827 GNUNET_free (cp); 1810 GNUNET_free(cp);
1828 return in; 1811 return in;
1829 } 1812 }
1830 } 1813 }
1831 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */ 1814 /* #5528 FIXME (feature!): maybe also try getnameinfo()? */
1832 GNUNET_free (cp); 1815 GNUNET_free(cp);
1833 return NULL; 1816 return NULL;
1834} 1817}
1835 1818
@@ -1842,22 +1825,22 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len)
1842 * @param pad_size number of bytes of padding to append 1825 * @param pad_size number of bytes of padding to append
1843 */ 1826 */
1844static void 1827static void
1845do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size) 1828do_pad(gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
1846{ 1829{
1847 char pad[pad_size]; 1830 char pad[pad_size];
1848 1831
1849 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof (pad)); 1832 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_WEAK, pad, sizeof(pad));
1850 if (sizeof (pad) > sizeof (struct GNUNET_MessageHeader)) 1833 if (sizeof(pad) > sizeof(struct GNUNET_MessageHeader))
1851 { 1834 {
1852 struct GNUNET_MessageHeader hdr = 1835 struct GNUNET_MessageHeader hdr =
1853 {.size = htons (sizeof (pad)), 1836 { .size = htons(sizeof(pad)),
1854 .type = htons (GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD)}; 1837 .type = htons(GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_PAD) };
1855 1838
1856 memcpy (pad, &hdr, sizeof (hdr)); 1839 memcpy(pad, &hdr, sizeof(hdr));
1857 } 1840 }
1858 GNUNET_assert ( 1841 GNUNET_assert(
1859 0 == 1842 0 ==
1860 gcry_cipher_encrypt (out_cipher, dgram, sizeof (pad), pad, sizeof (pad))); 1843 gcry_cipher_encrypt(out_cipher, dgram, sizeof(pad), pad, sizeof(pad)));
1861} 1844}
1862 1845
1863 1846
@@ -1870,123 +1853,123 @@ do_pad (gcry_cipher_hd_t out_cipher, char *dgram, size_t pad_size)
1870 * @param impl_state our `struct ReceiverAddress` 1853 * @param impl_state our `struct ReceiverAddress`
1871 */ 1854 */
1872static void 1855static void
1873mq_send (struct GNUNET_MQ_Handle *mq, 1856mq_send(struct GNUNET_MQ_Handle *mq,
1874 const struct GNUNET_MessageHeader *msg, 1857 const struct GNUNET_MessageHeader *msg,
1875 void *impl_state) 1858 void *impl_state)
1876{ 1859{
1877 struct ReceiverAddress *receiver = impl_state; 1860 struct ReceiverAddress *receiver = impl_state;
1878 uint16_t msize = ntohs (msg->size); 1861 uint16_t msize = ntohs(msg->size);
1879 1862
1880 GNUNET_assert (mq == receiver->mq); 1863 GNUNET_assert(mq == receiver->mq);
1881 if (msize > receiver->mtu) 1864 if (msize > receiver->mtu)
1882 { 1865 {
1883 GNUNET_break (0); 1866 GNUNET_break(0);
1884 receiver_destroy (receiver); 1867 receiver_destroy(receiver);
1885 return; 1868 return;
1886 } 1869 }
1887 reschedule_receiver_timeout (receiver); 1870 reschedule_receiver_timeout(receiver);
1888 1871
1889 if (0 == receiver->acks_available) 1872 if (0 == receiver->acks_available)
1890 { 1873 {
1891 /* use KX encryption method */ 1874 /* use KX encryption method */
1892 struct UdpHandshakeSignature uhs; 1875 struct UdpHandshakeSignature uhs;
1893 struct UDPConfirmation uc; 1876 struct UDPConfirmation uc;
1894 struct InitialKX kx; 1877 struct InitialKX kx;
1895 struct GNUNET_CRYPTO_EcdhePrivateKey epriv; 1878 struct GNUNET_CRYPTO_EcdhePrivateKey epriv;
1896 char dgram[receiver->mtu + sizeof (uc) + sizeof (kx)]; 1879 char dgram[receiver->mtu + sizeof(uc) + sizeof(kx)];
1897 size_t dpos; 1880 size_t dpos;
1898 gcry_cipher_hd_t out_cipher; 1881 gcry_cipher_hd_t out_cipher;
1899 struct SharedSecret *ss; 1882 struct SharedSecret *ss;
1900 1883
1901 /* setup key material */ 1884 /* setup key material */
1902 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2 (&epriv)); 1885 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_ecdhe_key_create2(&epriv));
1903 1886
1904 ss = setup_shared_secret_enc (&epriv, receiver); 1887 ss = setup_shared_secret_enc(&epriv, receiver);
1905 setup_cipher (&ss->master, 0, &out_cipher); 1888 setup_cipher(&ss->master, 0, &out_cipher);
1906 /* compute 'uc' */ 1889 /* compute 'uc' */
1907 uc.sender = my_identity; 1890 uc.sender = my_identity;
1908 uc.monotonic_time = 1891 uc.monotonic_time =
1909 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (cfg)); 1892 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(cfg));
1910 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE); 1893 uhs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_HANDSHAKE);
1911 uhs.purpose.size = htonl (sizeof (uhs)); 1894 uhs.purpose.size = htonl(sizeof(uhs));
1912 uhs.sender = my_identity; 1895 uhs.sender = my_identity;
1913 uhs.receiver = receiver->target; 1896 uhs.receiver = receiver->target;
1914 GNUNET_CRYPTO_ecdhe_key_get_public (&epriv, &uhs.ephemeral); 1897 GNUNET_CRYPTO_ecdhe_key_get_public(&epriv, &uhs.ephemeral);
1915 uhs.monotonic_time = uc.monotonic_time; 1898 uhs.monotonic_time = uc.monotonic_time;
1916 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, 1899 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key,
1917 &uhs.purpose, 1900 &uhs.purpose,
1918 &uc.sender_sig)); 1901 &uc.sender_sig));
1919 /* Leave space for kx */ 1902 /* Leave space for kx */
1920 dpos = sizeof (struct GNUNET_CRYPTO_EcdhePublicKey); 1903 dpos = sizeof(struct GNUNET_CRYPTO_EcdhePublicKey);
1921 /* Append encrypted uc to dgram */ 1904 /* Append encrypted uc to dgram */
1922 GNUNET_assert (0 == gcry_cipher_encrypt (out_cipher, 1905 GNUNET_assert(0 == gcry_cipher_encrypt(out_cipher,
1923 &dgram[dpos], 1906 &dgram[dpos],
1924 sizeof (uc), 1907 sizeof(uc),
1925 &uc, 1908 &uc,
1926 sizeof (uc))); 1909 sizeof(uc)));
1927 dpos += sizeof (uc); 1910 dpos += sizeof(uc);
1928 /* Append encrypted payload to dgram */ 1911 /* Append encrypted payload to dgram */
1929 GNUNET_assert ( 1912 GNUNET_assert(
1930 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); 1913 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize));
1931 dpos += msize; 1914 dpos += msize;
1932 do_pad (out_cipher, &dgram[dpos], sizeof (dgram) - dpos); 1915 do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
1933 /* Datagram starts with kx */ 1916 /* Datagram starts with kx */
1934 kx.ephemeral = uhs.ephemeral; 1917 kx.ephemeral = uhs.ephemeral;
1935 GNUNET_assert ( 1918 GNUNET_assert(
1936 0 == gcry_cipher_gettag (out_cipher, kx.gcm_tag, sizeof (kx.gcm_tag))); 1919 0 == gcry_cipher_gettag(out_cipher, kx.gcm_tag, sizeof(kx.gcm_tag)));
1937 gcry_cipher_close (out_cipher); 1920 gcry_cipher_close(out_cipher);
1938 memcpy (dgram, &kx, sizeof (kx)); 1921 memcpy(dgram, &kx, sizeof(kx));
1939 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, 1922 if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock,
1940 dgram, 1923 dgram,
1941 sizeof (dgram), 1924 sizeof(dgram),
1942 receiver->address, 1925 receiver->address,
1943 receiver->address_len)) 1926 receiver->address_len))
1944 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 1927 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send");
1945 GNUNET_MQ_impl_send_continue (mq); 1928 GNUNET_MQ_impl_send_continue(mq);
1946 return; 1929 return;
1947 } /* End of KX encryption method */ 1930 } /* End of KX encryption method */
1948 1931
1949 /* begin "BOX" encryption method, scan for ACKs from tail! */ 1932 /* begin "BOX" encryption method, scan for ACKs from tail! */
1950 for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev) 1933 for (struct SharedSecret *ss = receiver->ss_tail; NULL != ss; ss = ss->prev)
1951 {
1952 if (ss->sequence_used < ss->sequence_allowed)
1953 { 1934 {
1954 char dgram[sizeof (struct UDPBox) + receiver->mtu]; 1935 if (ss->sequence_used < ss->sequence_allowed)
1955 struct UDPBox *box; 1936 {
1956 gcry_cipher_hd_t out_cipher; 1937 char dgram[sizeof(struct UDPBox) + receiver->mtu];
1957 size_t dpos; 1938 struct UDPBox *box;
1958 1939 gcry_cipher_hd_t out_cipher;
1959 box = (struct UDPBox *) dgram; 1940 size_t dpos;
1960 ss->sequence_used++; 1941
1961 get_kid (&ss->master, ss->sequence_used, &box->kid); 1942 box = (struct UDPBox *)dgram;
1962 setup_cipher (&ss->master, ss->sequence_used, &out_cipher); 1943 ss->sequence_used++;
1963 /* Append encrypted payload to dgram */ 1944 get_kid(&ss->master, ss->sequence_used, &box->kid);
1964 dpos = sizeof (struct UDPBox); 1945 setup_cipher(&ss->master, ss->sequence_used, &out_cipher);
1965 GNUNET_assert ( 1946 /* Append encrypted payload to dgram */
1966 0 == gcry_cipher_encrypt (out_cipher, &dgram[dpos], msize, msg, msize)); 1947 dpos = sizeof(struct UDPBox);
1967 dpos += msize; 1948 GNUNET_assert(
1968 do_pad (out_cipher, &dgram[dpos], sizeof (dgram) - dpos); 1949 0 == gcry_cipher_encrypt(out_cipher, &dgram[dpos], msize, msg, msize));
1969 GNUNET_assert (0 == gcry_cipher_gettag (out_cipher, 1950 dpos += msize;
1970 box->gcm_tag, 1951 do_pad(out_cipher, &dgram[dpos], sizeof(dgram) - dpos);
1971 sizeof (box->gcm_tag))); 1952 GNUNET_assert(0 == gcry_cipher_gettag(out_cipher,
1972 gcry_cipher_close (out_cipher); 1953 box->gcm_tag,
1973 if (-1 == GNUNET_NETWORK_socket_sendto (udp_sock, 1954 sizeof(box->gcm_tag)));
1974 dgram, 1955 gcry_cipher_close(out_cipher);
1975 sizeof (dgram), 1956 if (-1 == GNUNET_NETWORK_socket_sendto(udp_sock,
1976 receiver->address, 1957 dgram,
1977 receiver->address_len)) 1958 sizeof(dgram),
1978 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "send"); 1959 receiver->address,
1979 GNUNET_MQ_impl_send_continue (mq); 1960 receiver->address_len))
1980 receiver->acks_available--; 1961 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "send");
1981 if (0 == receiver->acks_available) 1962 GNUNET_MQ_impl_send_continue(mq);
1982 { 1963 receiver->acks_available--;
1983 /* We have no more ACKs => MTU change! */ 1964 if (0 == receiver->acks_available)
1984 setup_receiver_mq (receiver); 1965 {
1985 } 1966 /* We have no more ACKs => MTU change! */
1986 return; 1967 setup_receiver_mq(receiver);
1968 }
1969 return;
1970 }
1987 } 1971 }
1988 } 1972 GNUNET_assert(0);
1989 GNUNET_assert (0);
1990} 1973}
1991 1974
1992 1975
@@ -1999,15 +1982,15 @@ mq_send (struct GNUNET_MQ_Handle *mq,
1999 * @param impl_state our `struct ReceiverAddress` 1982 * @param impl_state our `struct ReceiverAddress`
2000 */ 1983 */
2001static void 1984static void
2002mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) 1985mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
2003{ 1986{
2004 struct ReceiverAddress *receiver = impl_state; 1987 struct ReceiverAddress *receiver = impl_state;
2005 1988
2006 if (mq == receiver->mq) 1989 if (mq == receiver->mq)
2007 { 1990 {
2008 receiver->mq = NULL; 1991 receiver->mq = NULL;
2009 receiver_destroy (receiver); 1992 receiver_destroy(receiver);
2010 } 1993 }
2011} 1994}
2012 1995
2013 1996
@@ -2018,10 +2001,10 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
2018 * @param impl_state our `struct RecvierAddress` 2001 * @param impl_state our `struct RecvierAddress`
2019 */ 2002 */
2020static void 2003static void
2021mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) 2004mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
2022{ 2005{
2023 /* Cancellation is impossible with UDP; bail */ 2006 /* Cancellation is impossible with UDP; bail */
2024 GNUNET_assert (0); 2007 GNUNET_assert(0);
2025} 2008}
2026 2009
2027 2010
@@ -2035,15 +2018,15 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
2035 * @param error error code 2018 * @param error error code
2036 */ 2019 */
2037static void 2020static void
2038mq_error (void *cls, enum GNUNET_MQ_Error error) 2021mq_error(void *cls, enum GNUNET_MQ_Error error)
2039{ 2022{
2040 struct ReceiverAddress *receiver = cls; 2023 struct ReceiverAddress *receiver = cls;
2041 2024
2042 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2025 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2043 "MQ error in queue to %s: %d\n", 2026 "MQ error in queue to %s: %d\n",
2044 GNUNET_i2s (&receiver->target), 2027 GNUNET_i2s(&receiver->target),
2045 (int) error); 2028 (int)error);
2046 receiver_destroy (receiver); 2029 receiver_destroy(receiver);
2047} 2030}
2048 2031
2049 2032
@@ -2055,61 +2038,63 @@ mq_error (void *cls, enum GNUNET_MQ_Error error)
2055 * @param receiver receiver to setup MQ for 2038 * @param receiver receiver to setup MQ for
2056 */ 2039 */
2057static void 2040static void
2058setup_receiver_mq (struct ReceiverAddress *receiver) 2041setup_receiver_mq(struct ReceiverAddress *receiver)
2059{ 2042{
2060 size_t base_mtu; 2043 size_t base_mtu;
2061 2044
2062 if (NULL != receiver->qh) 2045 if (NULL != receiver->qh)
2063 { 2046 {
2064 GNUNET_TRANSPORT_communicator_mq_del (receiver->qh); 2047 GNUNET_TRANSPORT_communicator_mq_del(receiver->qh);
2065 receiver->qh = NULL; 2048 receiver->qh = NULL;
2066 } 2049 }
2067 GNUNET_assert (NULL == receiver->mq); 2050 GNUNET_assert(NULL == receiver->mq);
2068 switch (receiver->address->sa_family) 2051 switch (receiver->address->sa_family)
2069 { 2052 {
2070 case AF_INET: 2053 case AF_INET:
2071 base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */ 2054 base_mtu = 1480 /* Ethernet MTU, 1500 - Ethernet header - VLAN tag */
2072 - sizeof (struct GNUNET_TUN_IPv4Header) /* 20 */ 2055 - sizeof(struct GNUNET_TUN_IPv4Header) /* 20 */
2073 - sizeof (struct GNUNET_TUN_UdpHeader) /* 8 */; 2056 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2074 break; 2057 break;
2075 case AF_INET6: 2058
2076 base_mtu = 1280 /* Minimum MTU required by IPv6 */ 2059 case AF_INET6:
2077 - sizeof (struct GNUNET_TUN_IPv6Header) /* 40 */ 2060 base_mtu = 1280 /* Minimum MTU required by IPv6 */
2078 - sizeof (struct GNUNET_TUN_UdpHeader) /* 8 */; 2061 - sizeof(struct GNUNET_TUN_IPv6Header) /* 40 */
2079 break; 2062 - sizeof(struct GNUNET_TUN_UdpHeader) /* 8 */;
2080 default: 2063 break;
2081 GNUNET_assert (0); 2064
2082 break; 2065 default:
2083 } 2066 GNUNET_assert(0);
2067 break;
2068 }
2084 if (0 == receiver->acks_available) 2069 if (0 == receiver->acks_available)
2085 { 2070 {
2086 /* MTU based on full KX messages */ 2071 /* MTU based on full KX messages */
2087 receiver->mtu = base_mtu - sizeof (struct InitialKX) /* 48 */ 2072 receiver->mtu = base_mtu - sizeof(struct InitialKX) /* 48 */
2088 - sizeof (struct UDPConfirmation); /* 104 */ 2073 - sizeof(struct UDPConfirmation); /* 104 */
2089 } 2074 }
2090 else 2075 else
2091 { 2076 {
2092 /* MTU based on BOXed messages */ 2077 /* MTU based on BOXed messages */
2093 receiver->mtu = base_mtu - sizeof (struct UDPBox); 2078 receiver->mtu = base_mtu - sizeof(struct UDPBox);
2094 } 2079 }
2095 /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to 2080 /* => Effective MTU for CORE will range from 1080 (IPv6 + KX) to
2096 1404 (IPv4 + Box) bytes, depending on circumstances... */ 2081 1404 (IPv4 + Box) bytes, depending on circumstances... */
2097 if (NULL == receiver->mq) 2082 if (NULL == receiver->mq)
2098 receiver->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, 2083 receiver->mq = GNUNET_MQ_queue_for_callbacks(&mq_send,
2099 &mq_destroy, 2084 &mq_destroy,
2100 &mq_cancel, 2085 &mq_cancel,
2101 receiver, 2086 receiver,
2102 NULL, 2087 NULL,
2103 &mq_error, 2088 &mq_error,
2104 receiver); 2089 receiver);
2105 receiver->qh = 2090 receiver->qh =
2106 GNUNET_TRANSPORT_communicator_mq_add (ch, 2091 GNUNET_TRANSPORT_communicator_mq_add(ch,
2107 &receiver->target, 2092 &receiver->target,
2108 receiver->foreign_addr, 2093 receiver->foreign_addr,
2109 receiver->mtu, 2094 receiver->mtu,
2110 receiver->nt, 2095 receiver->nt,
2111 GNUNET_TRANSPORT_CS_OUTBOUND, 2096 GNUNET_TRANSPORT_CS_OUTBOUND,
2112 receiver->mq); 2097 receiver->mq);
2113} 2098}
2114 2099
2115 2100
@@ -2132,47 +2117,47 @@ setup_receiver_mq (struct ReceiverAddress *receiver)
2132 * invalid 2117 * invalid
2133 */ 2118 */
2134static int 2119static int
2135mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 2120mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2136{ 2121{
2137 struct ReceiverAddress *receiver; 2122 struct ReceiverAddress *receiver;
2138 const char *path; 2123 const char *path;
2139 struct sockaddr *in; 2124 struct sockaddr *in;
2140 socklen_t in_len; 2125 socklen_t in_len;
2141 2126
2142 if (0 != strncmp (address, 2127 if (0 != strncmp(address,
2143 COMMUNICATOR_ADDRESS_PREFIX "-", 2128 COMMUNICATOR_ADDRESS_PREFIX "-",
2144 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 2129 strlen(COMMUNICATOR_ADDRESS_PREFIX "-")))
2145 { 2130 {
2146 GNUNET_break_op (0); 2131 GNUNET_break_op(0);
2147 return GNUNET_SYSERR; 2132 return GNUNET_SYSERR;
2148 } 2133 }
2149 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; 2134 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")];
2150 in = udp_address_to_sockaddr (path, &in_len); 2135 in = udp_address_to_sockaddr(path, &in_len);
2151 2136
2152 receiver = GNUNET_new (struct ReceiverAddress); 2137 receiver = GNUNET_new(struct ReceiverAddress);
2153 receiver->address = in; 2138 receiver->address = in;
2154 receiver->address_len = in_len; 2139 receiver->address_len = in_len;
2155 receiver->target = *peer; 2140 receiver->target = *peer;
2156 receiver->nt = GNUNET_NT_scanner_get_type (is, in, in_len); 2141 receiver->nt = GNUNET_NT_scanner_get_type(is, in, in_len);
2157 (void) GNUNET_CONTAINER_multipeermap_put ( 2142 (void)GNUNET_CONTAINER_multipeermap_put(
2158 receivers, 2143 receivers,
2159 &receiver->target, 2144 &receiver->target,
2160 receiver, 2145 receiver,
2161 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2146 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2162 receiver->timeout = 2147 receiver->timeout =
2163 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2148 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2164 receiver->hn = GNUNET_CONTAINER_heap_insert (receivers_heap, 2149 receiver->hn = GNUNET_CONTAINER_heap_insert(receivers_heap,
2165 receiver, 2150 receiver,
2166 receiver->timeout.abs_value_us); 2151 receiver->timeout.abs_value_us);
2167 GNUNET_STATISTICS_set (stats, 2152 GNUNET_STATISTICS_set(stats,
2168 "# receivers active", 2153 "# receivers active",
2169 GNUNET_CONTAINER_multipeermap_size (receivers), 2154 GNUNET_CONTAINER_multipeermap_size(receivers),
2170 GNUNET_NO); 2155 GNUNET_NO);
2171 receiver->foreign_addr = 2156 receiver->foreign_addr =
2172 sockaddr_to_udpaddr_string (receiver->address, receiver->address_len); 2157 sockaddr_to_udpaddr_string(receiver->address, receiver->address_len);
2173 setup_receiver_mq (receiver); 2158 setup_receiver_mq(receiver);
2174 if (NULL == timeout_task) 2159 if (NULL == timeout_task)
2175 timeout_task = GNUNET_SCHEDULER_add_now (&check_timeouts, NULL); 2160 timeout_task = GNUNET_SCHEDULER_add_now(&check_timeouts, NULL);
2176 return GNUNET_OK; 2161 return GNUNET_OK;
2177} 2162}
2178 2163
@@ -2186,15 +2171,15 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2186 * @return #GNUNET_OK to continue to iterate 2171 * @return #GNUNET_OK to continue to iterate
2187 */ 2172 */
2188static int 2173static int
2189get_receiver_delete_it (void *cls, 2174get_receiver_delete_it(void *cls,
2190 const struct GNUNET_PeerIdentity *target, 2175 const struct GNUNET_PeerIdentity *target,
2191 void *value) 2176 void *value)
2192{ 2177{
2193 struct ReceiverAddress *receiver = value; 2178 struct ReceiverAddress *receiver = value;
2194 2179
2195 (void) cls; 2180 (void)cls;
2196 (void) target; 2181 (void)target;
2197 receiver_destroy (receiver); 2182 receiver_destroy(receiver);
2198 return GNUNET_OK; 2183 return GNUNET_OK;
2199} 2184}
2200 2185
@@ -2208,15 +2193,15 @@ get_receiver_delete_it (void *cls,
2208 * @return #GNUNET_OK to continue to iterate 2193 * @return #GNUNET_OK to continue to iterate
2209 */ 2194 */
2210static int 2195static int
2211get_sender_delete_it (void *cls, 2196get_sender_delete_it(void *cls,
2212 const struct GNUNET_PeerIdentity *target, 2197 const struct GNUNET_PeerIdentity *target,
2213 void *value) 2198 void *value)
2214{ 2199{
2215 struct SenderAddress *sender = value; 2200 struct SenderAddress *sender = value;
2216 2201
2217 (void) cls; 2202 (void)cls;
2218 (void) target; 2203 (void)target;
2219 sender_destroy (sender); 2204 sender_destroy(sender);
2220 return GNUNET_OK; 2205 return GNUNET_OK;
2221} 2206}
2222 2207
@@ -2227,64 +2212,64 @@ get_sender_delete_it (void *cls,
2227 * @param cls NULL (always) 2212 * @param cls NULL (always)
2228 */ 2213 */
2229static void 2214static void
2230do_shutdown (void *cls) 2215do_shutdown(void *cls)
2231{ 2216{
2232 if (NULL != nat) 2217 if (NULL != nat)
2233 { 2218 {
2234 GNUNET_NAT_unregister (nat); 2219 GNUNET_NAT_unregister(nat);
2235 nat = NULL; 2220 nat = NULL;
2236 } 2221 }
2237 while (NULL != bi_head) 2222 while (NULL != bi_head)
2238 bi_destroy (bi_head); 2223 bi_destroy(bi_head);
2239 if (NULL != broadcast_task) 2224 if (NULL != broadcast_task)
2240 { 2225 {
2241 GNUNET_SCHEDULER_cancel (broadcast_task); 2226 GNUNET_SCHEDULER_cancel(broadcast_task);
2242 broadcast_task = NULL; 2227 broadcast_task = NULL;
2243 } 2228 }
2244 if (NULL != read_task) 2229 if (NULL != read_task)
2245 { 2230 {
2246 GNUNET_SCHEDULER_cancel (read_task); 2231 GNUNET_SCHEDULER_cancel(read_task);
2247 read_task = NULL; 2232 read_task = NULL;
2248 } 2233 }
2249 if (NULL != udp_sock) 2234 if (NULL != udp_sock)
2250 { 2235 {
2251 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (udp_sock)); 2236 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(udp_sock));
2252 udp_sock = NULL; 2237 udp_sock = NULL;
2253 } 2238 }
2254 GNUNET_CONTAINER_multipeermap_iterate (receivers, 2239 GNUNET_CONTAINER_multipeermap_iterate(receivers,
2255 &get_receiver_delete_it, 2240 &get_receiver_delete_it,
2256 NULL); 2241 NULL);
2257 GNUNET_CONTAINER_multipeermap_destroy (receivers); 2242 GNUNET_CONTAINER_multipeermap_destroy(receivers);
2258 GNUNET_CONTAINER_multipeermap_iterate (senders, &get_sender_delete_it, NULL); 2243 GNUNET_CONTAINER_multipeermap_iterate(senders, &get_sender_delete_it, NULL);
2259 GNUNET_CONTAINER_multipeermap_destroy (senders); 2244 GNUNET_CONTAINER_multipeermap_destroy(senders);
2260 GNUNET_CONTAINER_multishortmap_destroy (key_cache); 2245 GNUNET_CONTAINER_multishortmap_destroy(key_cache);
2261 GNUNET_CONTAINER_heap_destroy (senders_heap); 2246 GNUNET_CONTAINER_heap_destroy(senders_heap);
2262 GNUNET_CONTAINER_heap_destroy (receivers_heap); 2247 GNUNET_CONTAINER_heap_destroy(receivers_heap);
2263 if (NULL != ch) 2248 if (NULL != ch)
2264 { 2249 {
2265 GNUNET_TRANSPORT_communicator_disconnect (ch); 2250 GNUNET_TRANSPORT_communicator_disconnect(ch);
2266 ch = NULL; 2251 ch = NULL;
2267 } 2252 }
2268 if (NULL != ah) 2253 if (NULL != ah)
2269 { 2254 {
2270 GNUNET_TRANSPORT_application_done (ah); 2255 GNUNET_TRANSPORT_application_done(ah);
2271 ah = NULL; 2256 ah = NULL;
2272 } 2257 }
2273 if (NULL != stats) 2258 if (NULL != stats)
2274 { 2259 {
2275 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 2260 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
2276 stats = NULL; 2261 stats = NULL;
2277 } 2262 }
2278 if (NULL != my_private_key) 2263 if (NULL != my_private_key)
2279 { 2264 {
2280 GNUNET_free (my_private_key); 2265 GNUNET_free(my_private_key);
2281 my_private_key = NULL; 2266 my_private_key = NULL;
2282 } 2267 }
2283 if (NULL != is) 2268 if (NULL != is)
2284 { 2269 {
2285 GNUNET_NT_scanner_done (is); 2270 GNUNET_NT_scanner_done(is);
2286 is = NULL; 2271 is = NULL;
2287 } 2272 }
2288} 2273}
2289 2274
2290 2275
@@ -2298,24 +2283,24 @@ do_shutdown (void *cls)
2298 * @param msg payload 2283 * @param msg payload
2299 */ 2284 */
2300static void 2285static void
2301enc_notify_cb (void *cls, 2286enc_notify_cb(void *cls,
2302 const struct GNUNET_PeerIdentity *sender, 2287 const struct GNUNET_PeerIdentity *sender,
2303 const struct GNUNET_MessageHeader *msg) 2288 const struct GNUNET_MessageHeader *msg)
2304{ 2289{
2305 const struct UDPAck *ack; 2290 const struct UDPAck *ack;
2306 2291
2307 (void) cls; 2292 (void)cls;
2308 if ((ntohs (msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) || 2293 if ((ntohs(msg->type) != GNUNET_MESSAGE_TYPE_COMMUNICATOR_UDP_ACK) ||
2309 (ntohs (msg->size) != sizeof (struct UDPAck))) 2294 (ntohs(msg->size) != sizeof(struct UDPAck)))
2310 { 2295 {
2311 GNUNET_break_op (0); 2296 GNUNET_break_op(0);
2312 return; 2297 return;
2313 } 2298 }
2314 ack = (const struct UDPAck *) msg; 2299 ack = (const struct UDPAck *)msg;
2315 GNUNET_CONTAINER_multipeermap_get_multiple (receivers, 2300 GNUNET_CONTAINER_multipeermap_get_multiple(receivers,
2316 sender, 2301 sender,
2317 &handle_ack, 2302 &handle_ack,
2318 (void *) ack); 2303 (void *)ack);
2319} 2304}
2320 2305
2321 2306
@@ -2333,39 +2318,39 @@ enc_notify_cb (void *cls,
2333 * @param addrlen actual length of the @a addr 2318 * @param addrlen actual length of the @a addr
2334 */ 2319 */
2335static void 2320static void
2336nat_address_cb (void *cls, 2321nat_address_cb(void *cls,
2337 void **app_ctx, 2322 void **app_ctx,
2338 int add_remove, 2323 int add_remove,
2339 enum GNUNET_NAT_AddressClass ac, 2324 enum GNUNET_NAT_AddressClass ac,
2340 const struct sockaddr *addr, 2325 const struct sockaddr *addr,
2341 socklen_t addrlen) 2326 socklen_t addrlen)
2342{ 2327{
2343 char *my_addr; 2328 char *my_addr;
2344 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 2329 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
2345 2330
2346 if (GNUNET_YES == add_remove) 2331 if (GNUNET_YES == add_remove)
2347 { 2332 {
2348 enum GNUNET_NetworkType nt; 2333 enum GNUNET_NetworkType nt;
2349 2334
2350 GNUNET_asprintf (&my_addr, 2335 GNUNET_asprintf(&my_addr,
2351 "%s-%s", 2336 "%s-%s",
2352 COMMUNICATOR_ADDRESS_PREFIX, 2337 COMMUNICATOR_ADDRESS_PREFIX,
2353 GNUNET_a2s (addr, addrlen)); 2338 GNUNET_a2s(addr, addrlen));
2354 nt = GNUNET_NT_scanner_get_type (is, addr, addrlen); 2339 nt = GNUNET_NT_scanner_get_type(is, addr, addrlen);
2355 ai = 2340 ai =
2356 GNUNET_TRANSPORT_communicator_address_add (ch, 2341 GNUNET_TRANSPORT_communicator_address_add(ch,
2357 my_addr, 2342 my_addr,
2358 nt, 2343 nt,
2359 GNUNET_TIME_UNIT_FOREVER_REL); 2344 GNUNET_TIME_UNIT_FOREVER_REL);
2360 GNUNET_free (my_addr); 2345 GNUNET_free(my_addr);
2361 *app_ctx = ai; 2346 *app_ctx = ai;
2362 } 2347 }
2363 else 2348 else
2364 { 2349 {
2365 ai = *app_ctx; 2350 ai = *app_ctx;
2366 GNUNET_TRANSPORT_communicator_address_remove (ai); 2351 GNUNET_TRANSPORT_communicator_address_remove(ai);
2367 *app_ctx = NULL; 2352 *app_ctx = NULL;
2368 } 2353 }
2369} 2354}
2370 2355
2371 2356
@@ -2375,67 +2360,69 @@ nat_address_cb (void *cls,
2375 * @param cls a `struct BroadcastInterface` 2360 * @param cls a `struct BroadcastInterface`
2376 */ 2361 */
2377static void 2362static void
2378ifc_broadcast (void *cls) 2363ifc_broadcast(void *cls)
2379{ 2364{
2380 struct BroadcastInterface *bi = cls; 2365 struct BroadcastInterface *bi = cls;
2381 struct GNUNET_TIME_Relative delay; 2366 struct GNUNET_TIME_Relative delay;
2382 2367
2383 delay = BROADCAST_FREQUENCY; 2368 delay = BROADCAST_FREQUENCY;
2384 delay.rel_value_us = 2369 delay.rel_value_us =
2385 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); 2370 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
2386 bi->broadcast_task = 2371 bi->broadcast_task =
2387 GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); 2372 GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi);
2388 2373
2389 switch (bi->sa->sa_family) 2374 switch (bi->sa->sa_family)
2390 { 2375 {
2391 case AF_INET: { 2376 case AF_INET: {
2392 static int yes = 1; 2377 static int yes = 1;
2393 static int no = 0; 2378 static int no = 0;
2394 ssize_t sent; 2379 ssize_t sent;
2395 2380
2396 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, 2381 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock,
2397 SOL_SOCKET, 2382 SOL_SOCKET,
2398 SO_BROADCAST, 2383 SO_BROADCAST,
2399 &yes, 2384 &yes,
2400 sizeof (int))) 2385 sizeof(int)))
2401 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 2386 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt");
2402 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 2387 sent = GNUNET_NETWORK_socket_sendto(udp_sock,
2403 &bi->bcm, 2388 &bi->bcm,
2404 sizeof (bi->bcm), 2389 sizeof(bi->bcm),
2405 bi->ba, 2390 bi->ba,
2406 bi->salen); 2391 bi->salen);
2407 if (-1 == sent) 2392 if (-1 == sent)
2408 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 2393 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto");
2409 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock, 2394 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt(udp_sock,
2410 SOL_SOCKET, 2395 SOL_SOCKET,
2411 SO_BROADCAST, 2396 SO_BROADCAST,
2412 &no, 2397 &no,
2413 sizeof (int))) 2398 sizeof(int)))
2414 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 2399 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "setsockopt");
2415 break; 2400 break;
2416 } 2401 }
2417 case AF_INET6: { 2402
2418 ssize_t sent; 2403 case AF_INET6: {
2419 struct sockaddr_in6 dst; 2404 ssize_t sent;
2420 2405 struct sockaddr_in6 dst;
2421 dst.sin6_family = AF_INET6; 2406
2422 dst.sin6_port = htons (my_port); 2407 dst.sin6_family = AF_INET6;
2423 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; 2408 dst.sin6_port = htons(my_port);
2424 dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id; 2409 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
2425 2410 dst.sin6_scope_id = ((struct sockaddr_in6 *)bi->ba)->sin6_scope_id;
2426 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 2411
2427 &bi->bcm, 2412 sent = GNUNET_NETWORK_socket_sendto(udp_sock,
2428 sizeof (bi->bcm), 2413 &bi->bcm,
2429 (const struct sockaddr *) &dst, 2414 sizeof(bi->bcm),
2430 sizeof (dst)); 2415 (const struct sockaddr *)&dst,
2431 if (-1 == sent) 2416 sizeof(dst));
2432 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "sendto"); 2417 if (-1 == sent)
2433 break; 2418 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "sendto");
2434 } 2419 break;
2435 default: 2420 }
2436 GNUNET_break (0); 2421
2437 break; 2422 default:
2438 } 2423 GNUNET_break(0);
2424 break;
2425 }
2439} 2426}
2440 2427
2441 2428
@@ -2454,90 +2441,90 @@ ifc_broadcast (void *cls)
2454 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 2441 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
2455 */ 2442 */
2456static int 2443static int
2457iface_proc (void *cls, 2444iface_proc(void *cls,
2458 const char *name, 2445 const char *name,
2459 int isDefault, 2446 int isDefault,
2460 const struct sockaddr *addr, 2447 const struct sockaddr *addr,
2461 const struct sockaddr *broadcast_addr, 2448 const struct sockaddr *broadcast_addr,
2462 const struct sockaddr *netmask, 2449 const struct sockaddr *netmask,
2463 socklen_t addrlen) 2450 socklen_t addrlen)
2464{ 2451{
2465 struct BroadcastInterface *bi; 2452 struct BroadcastInterface *bi;
2466 enum GNUNET_NetworkType network; 2453 enum GNUNET_NetworkType network;
2467 struct UdpBroadcastSignature ubs; 2454 struct UdpBroadcastSignature ubs;
2468 2455
2469 (void) cls; 2456 (void)cls;
2470 (void) netmask; 2457 (void)netmask;
2471 if (NULL == addr) 2458 if (NULL == addr)
2472 return GNUNET_YES; /* need to know our address! */ 2459 return GNUNET_YES; /* need to know our address! */
2473 network = GNUNET_NT_scanner_get_type (is, addr, addrlen); 2460 network = GNUNET_NT_scanner_get_type(is, addr, addrlen);
2474 if (GNUNET_NT_LOOPBACK == network) 2461 if (GNUNET_NT_LOOPBACK == network)
2475 { 2462 {
2476 /* Broadcasting on loopback does not make sense */ 2463 /* Broadcasting on loopback does not make sense */
2477 return GNUNET_YES; 2464 return GNUNET_YES;
2478 } 2465 }
2479 for (bi = bi_head; NULL != bi; bi = bi->next) 2466 for (bi = bi_head; NULL != bi; bi = bi->next)
2480 {
2481 if ((bi->salen == addrlen) && (0 == memcmp (addr, bi->sa, addrlen)))
2482 { 2467 {
2483 bi->found = GNUNET_YES; 2468 if ((bi->salen == addrlen) && (0 == memcmp(addr, bi->sa, addrlen)))
2484 return GNUNET_OK; 2469 {
2470 bi->found = GNUNET_YES;
2471 return GNUNET_OK;
2472 }
2485 } 2473 }
2486 }
2487 2474
2488 if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr)) 2475 if ((AF_INET6 == addr->sa_family) && (NULL == broadcast_addr))
2489 return GNUNET_OK; /* broadcast_addr is required for IPv6! */ 2476 return GNUNET_OK; /* broadcast_addr is required for IPv6! */
2490 if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket)) 2477 if ((AF_INET6 == addr->sa_family) && (GNUNET_YES != have_v6_socket))
2491 return GNUNET_OK; /* not using IPv6 */ 2478 return GNUNET_OK; /* not using IPv6 */
2492 2479
2493 bi = GNUNET_new (struct BroadcastInterface); 2480 bi = GNUNET_new(struct BroadcastInterface);
2494 bi->sa = GNUNET_memdup (addr, addrlen); 2481 bi->sa = GNUNET_memdup(addr, addrlen);
2495 if (NULL != broadcast_addr) 2482 if (NULL != broadcast_addr)
2496 bi->ba = GNUNET_memdup (broadcast_addr, addrlen); 2483 bi->ba = GNUNET_memdup(broadcast_addr, addrlen);
2497 bi->salen = addrlen; 2484 bi->salen = addrlen;
2498 bi->found = GNUNET_YES; 2485 bi->found = GNUNET_YES;
2499 bi->bcm.sender = my_identity; 2486 bi->bcm.sender = my_identity;
2500 ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); 2487 ubs.purpose.purpose = htonl(GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
2501 ubs.purpose.size = htonl (sizeof (ubs)); 2488 ubs.purpose.size = htonl(sizeof(ubs));
2502 ubs.sender = my_identity; 2489 ubs.sender = my_identity;
2503 GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address); 2490 GNUNET_CRYPTO_hash(addr, addrlen, &ubs.h_address);
2504 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (my_private_key, 2491 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(my_private_key,
2505 &ubs.purpose, 2492 &ubs.purpose,
2506 &bi->bcm.sender_sig)); 2493 &bi->bcm.sender_sig));
2507 bi->broadcast_task = GNUNET_SCHEDULER_add_now (&ifc_broadcast, bi); 2494 bi->broadcast_task = GNUNET_SCHEDULER_add_now(&ifc_broadcast, bi);
2508 GNUNET_CONTAINER_DLL_insert (bi_head, bi_tail, bi); 2495 GNUNET_CONTAINER_DLL_insert(bi_head, bi_tail, bi);
2509 if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr)) 2496 if ((AF_INET6 == addr->sa_family) && (NULL != broadcast_addr))
2510 {
2511 /* Create IPv6 multicast request */
2512 const struct sockaddr_in6 *s6 =
2513 (const struct sockaddr_in6 *) broadcast_addr;
2514
2515 GNUNET_assert (
2516 1 == inet_pton (AF_INET6, "FF05::13B", &bi->mcreq.ipv6mr_multiaddr));
2517
2518 /* http://tools.ietf.org/html/rfc2553#section-5.2:
2519 *
2520 * IPV6_JOIN_GROUP
2521 *
2522 * Join a multicast group on a specified local interface. If the
2523 * interface index is specified as 0, the kernel chooses the local
2524 * interface. For example, some kernels look up the multicast
2525 * group in the normal IPv6 routing table and using the resulting
2526 * interface; we do this for each interface, so no need to use
2527 * zero (anymore...).
2528 */
2529 bi->mcreq.ipv6mr_interface = s6->sin6_scope_id;
2530
2531 /* Join the multicast group */
2532 if (GNUNET_OK != GNUNET_NETWORK_socket_setsockopt (udp_sock,
2533 IPPROTO_IPV6,
2534 IPV6_JOIN_GROUP,
2535 &bi->mcreq,
2536 sizeof (bi->mcreq)))
2537 { 2497 {
2538 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt"); 2498 /* Create IPv6 multicast request */
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 }
2539 } 2527 }
2540 }
2541 return GNUNET_OK; 2528 return GNUNET_OK;
2542} 2529}
2543 2530
@@ -2548,23 +2535,23 @@ iface_proc (void *cls,
2548 * @param cls NULL, unused 2535 * @param cls NULL, unused
2549 */ 2536 */
2550static void 2537static void
2551do_broadcast (void *cls) 2538do_broadcast(void *cls)
2552{ 2539{
2553 struct BroadcastInterface *bin; 2540 struct BroadcastInterface *bin;
2554 2541
2555 (void) cls; 2542 (void)cls;
2556 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next) 2543 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bi->next)
2557 bi->found = GNUNET_NO; 2544 bi->found = GNUNET_NO;
2558 GNUNET_OS_network_interfaces_list (&iface_proc, NULL); 2545 GNUNET_OS_network_interfaces_list(&iface_proc, NULL);
2559 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin) 2546 for (struct BroadcastInterface *bi = bi_head; NULL != bi; bi = bin)
2560 { 2547 {
2561 bin = bi->next; 2548 bin = bi->next;
2562 if (GNUNET_NO == bi->found) 2549 if (GNUNET_NO == bi->found)
2563 bi_destroy (bi); 2550 bi_destroy(bi);
2564 } 2551 }
2565 broadcast_task = GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, 2552 broadcast_task = GNUNET_SCHEDULER_add_delayed(INTERFACE_SCAN_FREQUENCY,
2566 &do_broadcast, 2553 &do_broadcast,
2567 NULL); 2554 NULL);
2568} 2555}
2569 2556
2570 2557
@@ -2577,10 +2564,10 @@ do_broadcast (void *cls)
2577 * @param c configuration 2564 * @param c configuration
2578 */ 2565 */
2579static void 2566static void
2580run (void *cls, 2567run(void *cls,
2581 char *const *args, 2568 char *const *args,
2582 const char *cfgfile, 2569 const char *cfgfile,
2583 const struct GNUNET_CONFIGURATION_Handle *c) 2570 const struct GNUNET_CONFIGURATION_Handle *c)
2584{ 2571{
2585 char *bindto; 2572 char *bindto;
2586 struct sockaddr *in; 2573 struct sockaddr *in;
@@ -2588,141 +2575,143 @@ run (void *cls,
2588 struct sockaddr_storage in_sto; 2575 struct sockaddr_storage in_sto;
2589 socklen_t sto_len; 2576 socklen_t sto_len;
2590 2577
2591 (void) cls; 2578 (void)cls;
2592 cfg = c; 2579 cfg = c;
2593 if (GNUNET_OK != 2580 if (GNUNET_OK !=
2594 GNUNET_CONFIGURATION_get_value_filename (cfg, 2581 GNUNET_CONFIGURATION_get_value_filename(cfg,
2595 COMMUNICATOR_CONFIG_SECTION, 2582 COMMUNICATOR_CONFIG_SECTION,
2596 "BINDTO", 2583 "BINDTO",
2597 &bindto)) 2584 &bindto))
2598 { 2585 {
2599 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2586 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
2600 COMMUNICATOR_CONFIG_SECTION, 2587 COMMUNICATOR_CONFIG_SECTION,
2601 "BINDTO"); 2588 "BINDTO");
2602 return; 2589 return;
2603 } 2590 }
2604 2591
2605 in = udp_address_to_sockaddr (bindto, &in_len); 2592 in = udp_address_to_sockaddr(bindto, &in_len);
2606 if (NULL == in) 2593 if (NULL == in)
2607 { 2594 {
2608 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2595 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2609 "Failed to setup UDP socket address with path `%s'\n", 2596 "Failed to setup UDP socket address with path `%s'\n",
2610 bindto); 2597 bindto);
2611 GNUNET_free (bindto); 2598 GNUNET_free(bindto);
2612 return; 2599 return;
2613 } 2600 }
2614 udp_sock = 2601 udp_sock =
2615 GNUNET_NETWORK_socket_create (in->sa_family, SOCK_DGRAM, IPPROTO_UDP); 2602 GNUNET_NETWORK_socket_create(in->sa_family, SOCK_DGRAM, IPPROTO_UDP);
2616 if (NULL == udp_sock) 2603 if (NULL == udp_sock)
2617 { 2604 {
2618 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 2605 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
2619 GNUNET_free (in); 2606 GNUNET_free(in);
2620 GNUNET_free (bindto); 2607 GNUNET_free(bindto);
2621 return; 2608 return;
2622 } 2609 }
2623 if (AF_INET6 == in->sa_family) 2610 if (AF_INET6 == in->sa_family)
2624 have_v6_socket = GNUNET_YES; 2611 have_v6_socket = GNUNET_YES;
2625 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (udp_sock, in, in_len)) 2612 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(udp_sock, in, in_len))
2626 { 2613 {
2627 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", bindto); 2614 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", bindto);
2628 GNUNET_NETWORK_socket_close (udp_sock); 2615 GNUNET_NETWORK_socket_close(udp_sock);
2629 udp_sock = NULL; 2616 udp_sock = NULL;
2630 GNUNET_free (in); 2617 GNUNET_free(in);
2631 GNUNET_free (bindto); 2618 GNUNET_free(bindto);
2632 return; 2619 return;
2633 } 2620 }
2634 /* We might have bound to port 0, allowing the OS to figure it out; 2621 /* We might have bound to port 0, allowing the OS to figure it out;
2635 thus, get the real IN-address from the socket */ 2622 thus, get the real IN-address from the socket */
2636 sto_len = sizeof (in_sto); 2623 sto_len = sizeof(in_sto);
2637 if (0 != getsockname (GNUNET_NETWORK_get_fd (udp_sock), 2624 if (0 != getsockname(GNUNET_NETWORK_get_fd(udp_sock),
2638 (struct sockaddr *) &in_sto, 2625 (struct sockaddr *)&in_sto,
2639 &sto_len)) 2626 &sto_len))
2640 { 2627 {
2641 memcpy (&in_sto, in, in_len); 2628 memcpy(&in_sto, in, in_len);
2642 sto_len = in_len; 2629 sto_len = in_len;
2643 } 2630 }
2644 GNUNET_free (in); 2631 GNUNET_free(in);
2645 GNUNET_free (bindto); 2632 GNUNET_free(bindto);
2646 in = (struct sockaddr *) &in_sto; 2633 in = (struct sockaddr *)&in_sto;
2647 in_len = sto_len; 2634 in_len = sto_len;
2648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2649 "Bound to `%s'\n", 2636 "Bound to `%s'\n",
2650 GNUNET_a2s ((const struct sockaddr *) &in_sto, sto_len)); 2637 GNUNET_a2s((const struct sockaddr *)&in_sto, sto_len));
2651 switch (in->sa_family) 2638 switch (in->sa_family)
2652 { 2639 {
2653 case AF_INET: 2640 case AF_INET:
2654 my_port = ntohs (((struct sockaddr_in *) in)->sin_port); 2641 my_port = ntohs(((struct sockaddr_in *)in)->sin_port);
2655 break; 2642 break;
2656 case AF_INET6: 2643
2657 my_port = ntohs (((struct sockaddr_in6 *) in)->sin6_port); 2644 case AF_INET6:
2658 break; 2645 my_port = ntohs(((struct sockaddr_in6 *)in)->sin6_port);
2659 default: 2646 break;
2660 GNUNET_break (0); 2647
2661 my_port = 0; 2648 default:
2662 } 2649 GNUNET_break(0);
2663 stats = GNUNET_STATISTICS_create ("C-UDP", cfg); 2650 my_port = 0;
2664 senders = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); 2651 }
2665 receivers = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); 2652 stats = GNUNET_STATISTICS_create("C-UDP", cfg);
2666 senders_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2653 senders = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES);
2654 receivers = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES);
2655 senders_heap = GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
2667 receivers_heap = 2656 receivers_heap =
2668 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 2657 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
2669 key_cache = GNUNET_CONTAINER_multishortmap_create (1024, GNUNET_YES); 2658 key_cache = GNUNET_CONTAINER_multishortmap_create(1024, GNUNET_YES);
2670 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 2659 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
2671 is = GNUNET_NT_scanner_init (); 2660 is = GNUNET_NT_scanner_init();
2672 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); 2661 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration(cfg);
2673 if (NULL == my_private_key) 2662 if (NULL == my_private_key)
2674 { 2663 {
2675 GNUNET_log ( 2664 GNUNET_log(
2676 GNUNET_ERROR_TYPE_ERROR, 2665 GNUNET_ERROR_TYPE_ERROR,
2677 _ ( 2666 _(
2678 "Transport service is lacking key configuration settings. Exiting.\n")); 2667 "Transport service is lacking key configuration settings. Exiting.\n"));
2679 GNUNET_SCHEDULER_shutdown (); 2668 GNUNET_SCHEDULER_shutdown();
2680 return; 2669 return;
2681 } 2670 }
2682 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); 2671 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key);
2683 /* start reading */ 2672 /* start reading */
2684 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 2673 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
2685 udp_sock, 2674 udp_sock,
2686 &sock_read, 2675 &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,
2687 NULL); 2684 NULL);
2688 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
2689 COMMUNICATOR_CONFIG_SECTION,
2690 COMMUNICATOR_ADDRESS_PREFIX,
2691 GNUNET_TRANSPORT_CC_UNRELIABLE,
2692 &mq_init,
2693 NULL,
2694 &enc_notify_cb,
2695 NULL);
2696 if (NULL == ch) 2685 if (NULL == ch)
2697 { 2686 {
2698 GNUNET_break (0); 2687 GNUNET_break(0);
2699 GNUNET_SCHEDULER_shutdown (); 2688 GNUNET_SCHEDULER_shutdown();
2700 return; 2689 return;
2701 } 2690 }
2702 ah = GNUNET_TRANSPORT_application_init (cfg); 2691 ah = GNUNET_TRANSPORT_application_init(cfg);
2703 if (NULL == ah) 2692 if (NULL == ah)
2704 { 2693 {
2705 GNUNET_break (0); 2694 GNUNET_break(0);
2706 GNUNET_SCHEDULER_shutdown (); 2695 GNUNET_SCHEDULER_shutdown();
2707 return; 2696 return;
2708 } 2697 }
2709 /* start broadcasting */ 2698 /* start broadcasting */
2710 if (GNUNET_YES != 2699 if (GNUNET_YES !=
2711 GNUNET_CONFIGURATION_get_value_yesno (cfg, 2700 GNUNET_CONFIGURATION_get_value_yesno(cfg,
2712 COMMUNICATOR_CONFIG_SECTION, 2701 COMMUNICATOR_CONFIG_SECTION,
2713 "DISABLE_BROADCAST")) 2702 "DISABLE_BROADCAST"))
2714 { 2703 {
2715 broadcast_task = GNUNET_SCHEDULER_add_now (&do_broadcast, NULL); 2704 broadcast_task = GNUNET_SCHEDULER_add_now(&do_broadcast, NULL);
2716 } 2705 }
2717 nat = GNUNET_NAT_register (cfg, 2706 nat = GNUNET_NAT_register(cfg,
2718 COMMUNICATOR_CONFIG_SECTION, 2707 COMMUNICATOR_CONFIG_SECTION,
2719 IPPROTO_UDP, 2708 IPPROTO_UDP,
2720 1 /* one address */, 2709 1 /* one address */,
2721 (const struct sockaddr **) &in, 2710 (const struct sockaddr **)&in,
2722 &in_len, 2711 &in_len,
2723 &nat_address_cb, 2712 &nat_address_cb,
2724 NULL /* FIXME: support reversal: #5529 */, 2713 NULL /* FIXME: support reversal: #5529 */,
2725 NULL /* closure */); 2714 NULL /* closure */);
2726} 2715}
2727 2716
2728 2717
@@ -2734,25 +2723,26 @@ run (void *cls,
2734 * @return 0 ok, 1 on error 2723 * @return 0 ok, 1 on error
2735 */ 2724 */
2736int 2725int
2737main (int argc, char *const *argv) 2726main(int argc, char *const *argv)
2738{ 2727{
2739 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 2728 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
2740 GNUNET_GETOPT_OPTION_END}; 2729 GNUNET_GETOPT_OPTION_END
2730 };
2741 int ret; 2731 int ret;
2742 2732
2743 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 2733 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
2744 return 2; 2734 return 2;
2745 2735
2746 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, 2736 ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
2747 argv, 2737 argv,
2748 "gnunet-communicator-udp", 2738 "gnunet-communicator-udp",
2749 _ ("GNUnet UDP communicator"), 2739 _("GNUnet UDP communicator"),
2750 options, 2740 options,
2751 &run, 2741 &run,
2752 NULL)) 2742 NULL))
2753 ? 0 2743 ? 0
2754 : 1; 2744 : 1;
2755 GNUNET_free ((void *) argv); 2745 GNUNET_free((void *)argv);
2756 return ret; 2746 return ret;
2757} 2747}
2758 2748
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index cb1fbc230..da610daa1 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-communicator-unix.c 22 * @file transport/gnunet-communicator-unix.c
@@ -64,8 +64,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
64/** 64/**
65 * UNIX Message-Packet header. 65 * UNIX Message-Packet header.
66 */ 66 */
67struct UNIXMessage 67struct UNIXMessage {
68{
69 /** 68 /**
70 * Message header. 69 * Message header.
71 */ 70 */
@@ -83,9 +82,7 @@ GNUNET_NETWORK_STRUCT_END
83/** 82/**
84 * Handle for a queue. 83 * Handle for a queue.
85 */ 84 */
86struct Queue 85struct Queue {
87{
88
89 /** 86 /**
90 * Queues with pending messages (!) are kept in a DLL. 87 * Queues with pending messages (!) are kept in a DLL.
91 */ 88 */
@@ -208,37 +205,37 @@ static struct GNUNET_TRANSPORT_AddressIdentifier *ai;
208 * @param queue queue to close down 205 * @param queue queue to close down
209 */ 206 */
210static void 207static void
211queue_destroy (struct Queue *queue) 208queue_destroy(struct Queue *queue)
212{ 209{
213 struct GNUNET_MQ_Handle *mq; 210 struct GNUNET_MQ_Handle *mq;
214 211
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
216 "Disconnecting queue for peer `%s'\n", 213 "Disconnecting queue for peer `%s'\n",
217 GNUNET_i2s (&queue->target)); 214 GNUNET_i2s(&queue->target));
218 if (0 != queue->bytes_in_queue) 215 if (0 != queue->bytes_in_queue)
219 { 216 {
220 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); 217 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
221 queue->bytes_in_queue = 0; 218 queue->bytes_in_queue = 0;
222 } 219 }
223 if (NULL != (mq = queue->mq)) 220 if (NULL != (mq = queue->mq))
224 { 221 {
225 queue->mq = NULL; 222 queue->mq = NULL;
226 GNUNET_MQ_destroy (mq); 223 GNUNET_MQ_destroy(mq);
227 } 224 }
228 GNUNET_assert ( 225 GNUNET_assert(
229 GNUNET_YES == 226 GNUNET_YES ==
230 GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); 227 GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue));
231 GNUNET_STATISTICS_set (stats, 228 GNUNET_STATISTICS_set(stats,
232 "# queues active", 229 "# queues active",
233 GNUNET_CONTAINER_multipeermap_size (queue_map), 230 GNUNET_CONTAINER_multipeermap_size(queue_map),
234 GNUNET_NO); 231 GNUNET_NO);
235 if (NULL != queue->timeout_task) 232 if (NULL != queue->timeout_task)
236 { 233 {
237 GNUNET_SCHEDULER_cancel (queue->timeout_task); 234 GNUNET_SCHEDULER_cancel(queue->timeout_task);
238 queue->timeout_task = NULL; 235 queue->timeout_task = NULL;
239 } 236 }
240 GNUNET_free (queue->address); 237 GNUNET_free(queue->address);
241 GNUNET_free (queue); 238 GNUNET_free(queue);
242} 239}
243 240
244 241
@@ -248,28 +245,28 @@ queue_destroy (struct Queue *queue)
248 * @param cls the `struct Queue *` to disconnect 245 * @param cls the `struct Queue *` to disconnect
249 */ 246 */
250static void 247static void
251queue_timeout (void *cls) 248queue_timeout(void *cls)
252{ 249{
253 struct Queue *queue = cls; 250 struct Queue *queue = cls;
254 struct GNUNET_TIME_Relative left; 251 struct GNUNET_TIME_Relative left;
255 252
256 queue->timeout_task = NULL; 253 queue->timeout_task = NULL;
257 left = GNUNET_TIME_absolute_get_remaining (queue->timeout); 254 left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
258 if (0 != left.rel_value_us) 255 if (0 != left.rel_value_us)
259 { 256 {
260 /* not actually our turn yet, but let's at least update 257 /* not actually our turn yet, but let's at least update
261 the monitor, it may think we're about to die ... */ 258 the monitor, it may think we're about to die ... */
262 queue->timeout_task = 259 queue->timeout_task =
263 GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, queue); 260 GNUNET_SCHEDULER_add_delayed(left, &queue_timeout, queue);
264 return; 261 return;
265 } 262 }
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
267 "Queue %p was idle for %s, disconnecting\n", 264 "Queue %p was idle for %s, disconnecting\n",
268 queue, 265 queue,
269 GNUNET_STRINGS_relative_time_to_string ( 266 GNUNET_STRINGS_relative_time_to_string(
270 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 267 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
271 GNUNET_YES)); 268 GNUNET_YES));
272 queue_destroy (queue); 269 queue_destroy(queue);
273} 270}
274 271
275 272
@@ -281,11 +278,11 @@ queue_timeout (void *cls)
281 * @param queue queue for which the timeout should be rescheduled 278 * @param queue queue for which the timeout should be rescheduled
282 */ 279 */
283static void 280static void
284reschedule_queue_timeout (struct Queue *queue) 281reschedule_queue_timeout(struct Queue *queue)
285{ 282{
286 GNUNET_assert (NULL != queue->timeout_task); 283 GNUNET_assert(NULL != queue->timeout_task);
287 queue->timeout = 284 queue->timeout =
288 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 285 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
289} 286}
290 287
291 288
@@ -298,22 +295,22 @@ reschedule_queue_timeout (struct Queue *queue)
298 * @return converted unix path 295 * @return converted unix path
299 */ 296 */
300static struct sockaddr_un * 297static struct sockaddr_un *
301unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) 298unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
302{ 299{
303 struct sockaddr_un *un; 300 struct sockaddr_un *un;
304 size_t slen; 301 size_t slen;
305 302
306 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 303 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */
307 un = GNUNET_new (struct sockaddr_un); 304 un = GNUNET_new(struct sockaddr_un);
308 un->sun_family = AF_UNIX; 305 un->sun_family = AF_UNIX;
309 slen = strlen (unixpath); 306 slen = strlen(unixpath);
310 if (slen >= sizeof (un->sun_path)) 307 if (slen >= sizeof(un->sun_path))
311 slen = sizeof (un->sun_path) - 1; 308 slen = sizeof(un->sun_path) - 1;
312 GNUNET_memcpy (un->sun_path, unixpath, slen); 309 GNUNET_memcpy(un->sun_path, unixpath, slen);
313 un->sun_path[slen] = '\0'; 310 un->sun_path[slen] = '\0';
314 slen = sizeof (struct sockaddr_un); 311 slen = sizeof(struct sockaddr_un);
315#if HAVE_SOCKADDR_UN_SUN_LEN 312#if HAVE_SOCKADDR_UN_SUN_LEN
316 un->sun_len = (u_char) slen; 313 un->sun_len = (u_char)slen;
317#endif 314#endif
318 (*sock_len) = slen; 315 (*sock_len) = slen;
319 if ('@' == un->sun_path[0]) 316 if ('@' == un->sun_path[0])
@@ -325,8 +322,7 @@ unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
325/** 322/**
326 * Closure to #lookup_queue_it(). 323 * Closure to #lookup_queue_it().
327 */ 324 */
328struct LookupCtx 325struct LookupCtx {
329{
330 /** 326 /**
331 * Location to store the queue, if found. 327 * Location to store the queue, if found.
332 */ 328 */
@@ -353,17 +349,17 @@ struct LookupCtx
353 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success 349 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
354 */ 350 */
355static int 351static int
356lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 352lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
357{ 353{
358 struct LookupCtx *lctx = cls; 354 struct LookupCtx *lctx = cls;
359 struct Queue *queue = value; 355 struct Queue *queue = value;
360 356
361 if ((queue->address_len = lctx->un_len) && 357 if ((queue->address_len = lctx->un_len) &&
362 (0 == memcmp (lctx->un, queue->address, queue->address_len))) 358 (0 == memcmp(lctx->un, queue->address, queue->address_len)))
363 { 359 {
364 lctx->res = queue; 360 lctx->res = queue;
365 return GNUNET_NO; 361 return GNUNET_NO;
366 } 362 }
367 return GNUNET_YES; 363 return GNUNET_YES;
368} 364}
369 365
@@ -376,18 +372,18 @@ lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
376 * @return NULL if queue was not found 372 * @return NULL if queue was not found
377 */ 373 */
378static struct Queue * 374static struct Queue *
379lookup_queue (const struct GNUNET_PeerIdentity *peer, 375lookup_queue(const struct GNUNET_PeerIdentity *peer,
380 const struct sockaddr_un *un, 376 const struct sockaddr_un *un,
381 socklen_t un_len) 377 socklen_t un_len)
382{ 378{
383 struct LookupCtx lctx; 379 struct LookupCtx lctx;
384 380
385 lctx.un = un; 381 lctx.un = un;
386 lctx.un_len = un_len; 382 lctx.un_len = un_len;
387 GNUNET_CONTAINER_multipeermap_get_multiple (queue_map, 383 GNUNET_CONTAINER_multipeermap_get_multiple(queue_map,
388 peer, 384 peer,
389 &lookup_queue_it, 385 &lookup_queue_it,
390 &lctx); 386 &lctx);
391 return lctx.res; 387 return lctx.res;
392} 388}
393 389
@@ -399,103 +395,105 @@ lookup_queue (const struct GNUNET_PeerIdentity *peer,
399 * @param cls NULL 395 * @param cls NULL
400 */ 396 */
401static void 397static void
402select_write_cb (void *cls) 398select_write_cb(void *cls)
403{ 399{
404 struct Queue *queue = queue_tail; 400 struct Queue *queue = queue_tail;
405 const struct GNUNET_MessageHeader *msg = queue->msg; 401 const struct GNUNET_MessageHeader *msg = queue->msg;
406 size_t msg_size = ntohs (msg->size); 402 size_t msg_size = ntohs(msg->size);
407 ssize_t sent; 403 ssize_t sent;
408 404
409 /* take queue of the ready list */ 405 /* take queue of the ready list */
410 write_task = NULL; 406 write_task = NULL;
411 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); 407 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
412 if (NULL != queue_head) 408 if (NULL != queue_head)
413 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 409 write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
414 unix_sock, 410 unix_sock,
415 &select_write_cb, 411 &select_write_cb,
416 NULL); 412 NULL);
417 413
418 /* send 'msg' */ 414 /* send 'msg' */
419 queue->msg = NULL; 415 queue->msg = NULL;
420 GNUNET_MQ_impl_send_continue (queue->mq); 416 GNUNET_MQ_impl_send_continue(queue->mq);
421resend: 417resend:
422 /* Send the data */ 418 /* Send the data */
423 sent = GNUNET_NETWORK_socket_sendto (unix_sock, 419 sent = GNUNET_NETWORK_socket_sendto(unix_sock,
424 msg, 420 msg,
425 msg_size, 421 msg_size,
426 (const struct sockaddr *) queue->address, 422 (const struct sockaddr *)queue->address,
427 queue->address_len); 423 queue->address_len);
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
429 "UNIX transmitted message to %s (%d/%u: %s)\n", 425 "UNIX transmitted message to %s (%d/%u: %s)\n",
430 GNUNET_i2s (&queue->target), 426 GNUNET_i2s(&queue->target),
431 (int) sent, 427 (int)sent,
432 (unsigned int) msg_size, 428 (unsigned int)msg_size,
433 (sent < 0) ? strerror (errno) : "ok"); 429 (sent < 0) ? strerror(errno) : "ok");
434 if (-1 != sent) 430 if (-1 != sent)
435 { 431 {
436 GNUNET_STATISTICS_update (stats, 432 GNUNET_STATISTICS_update(stats,
437 "# bytes sent", 433 "# bytes sent",
438 (long long) sent, 434 (long long)sent,
439 GNUNET_NO); 435 GNUNET_NO);
440 reschedule_queue_timeout (queue); 436 reschedule_queue_timeout(queue);
441 return; /* all good */ 437 return; /* all good */
442 } 438 }
443 GNUNET_STATISTICS_update (stats, 439 GNUNET_STATISTICS_update(stats,
444 "# network transmission failures", 440 "# network transmission failures",
445 1, 441 1,
446 GNUNET_NO); 442 GNUNET_NO);
447 switch (errno) 443 switch (errno)
448 {
449 case EAGAIN:
450 case ENOBUFS:
451 /* We should retry later... */
452 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
453 return;
454 case EMSGSIZE: {
455 socklen_t size = 0;
456 socklen_t len = sizeof (size);
457
458 GNUNET_NETWORK_socket_getsockopt (unix_sock,
459 SOL_SOCKET,
460 SO_SNDBUF,
461 &size,
462 &len);
463 if (size > ntohs (msg->size))
464 { 444 {
465 /* Buffer is bigger than message: error, no retry 445 case EAGAIN:
466 * This should never happen!*/ 446 case ENOBUFS:
467 GNUNET_break (0); 447 /* We should retry later... */
448 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send");
449 return;
450
451 case EMSGSIZE: {
452 socklen_t size = 0;
453 socklen_t len = sizeof(size);
454
455 GNUNET_NETWORK_socket_getsockopt(unix_sock,
456 SOL_SOCKET,
457 SO_SNDBUF,
458 &size,
459 &len);
460 if (size > ntohs(msg->size))
461 {
462 /* Buffer is bigger than message: error, no retry
463 * This should never happen!*/
464 GNUNET_break(0);
465 return;
466 }
467 GNUNET_log(
468 GNUNET_ERROR_TYPE_DEBUG,
469 "Trying to increase socket buffer size from %u to %u for message size %u\n",
470 (unsigned int)size,
471 (unsigned int)((msg_size / 1000) + 2) * 1000,
472 (unsigned int)msg_size);
473 size = ((msg_size / 1000) + 2) * 1000;
474 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock,
475 SOL_SOCKET,
476 SO_SNDBUF,
477 &size,
478 sizeof(size)))
479 goto resend; /* Increased buffer size, retry sending */
480 /* Ok, then just try very modest increase */
481 size = msg_size;
482 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock,
483 SOL_SOCKET,
484 SO_SNDBUF,
485 &size,
486 sizeof(size)))
487 goto resend; /* Increased buffer size, retry sending */
488 /* Could not increase buffer size: error, no retry */
489 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
490 return;
491 }
492
493 default:
494 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send");
468 return; 495 return;
469 } 496 }
470 GNUNET_log (
471 GNUNET_ERROR_TYPE_DEBUG,
472 "Trying to increase socket buffer size from %u to %u for message size %u\n",
473 (unsigned int) size,
474 (unsigned int) ((msg_size / 1000) + 2) * 1000,
475 (unsigned int) msg_size);
476 size = ((msg_size / 1000) + 2) * 1000;
477 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
478 SOL_SOCKET,
479 SO_SNDBUF,
480 &size,
481 sizeof (size)))
482 goto resend; /* Increased buffer size, retry sending */
483 /* Ok, then just try very modest increase */
484 size = msg_size;
485 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
486 SOL_SOCKET,
487 SO_SNDBUF,
488 &size,
489 sizeof (size)))
490 goto resend; /* Increased buffer size, retry sending */
491 /* Could not increase buffer size: error, no retry */
492 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
493 return;
494 }
495 default:
496 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send");
497 return;
498 }
499} 497}
500 498
501 499
@@ -508,22 +506,22 @@ resend:
508 * @param impl_state our `struct Queue` 506 * @param impl_state our `struct Queue`
509 */ 507 */
510static void 508static void
511mq_send (struct GNUNET_MQ_Handle *mq, 509mq_send(struct GNUNET_MQ_Handle *mq,
512 const struct GNUNET_MessageHeader *msg, 510 const struct GNUNET_MessageHeader *msg,
513 void *impl_state) 511 void *impl_state)
514{ 512{
515 struct Queue *queue = impl_state; 513 struct Queue *queue = impl_state;
516 514
517 GNUNET_assert (mq == queue->mq); 515 GNUNET_assert(mq == queue->mq);
518 GNUNET_assert (NULL == queue->msg); 516 GNUNET_assert(NULL == queue->msg);
519 queue->msg = msg; 517 queue->msg = msg;
520 GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue); 518 GNUNET_CONTAINER_DLL_insert(queue_head, queue_tail, queue);
521 GNUNET_assert (NULL != unix_sock); 519 GNUNET_assert(NULL != unix_sock);
522 if (NULL == write_task) 520 if (NULL == write_task)
523 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 521 write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
524 unix_sock, 522 unix_sock,
525 &select_write_cb, 523 &select_write_cb,
526 NULL); 524 NULL);
527} 525}
528 526
529 527
@@ -536,15 +534,15 @@ mq_send (struct GNUNET_MQ_Handle *mq,
536 * @param impl_state our `struct Queue` 534 * @param impl_state our `struct Queue`
537 */ 535 */
538static void 536static void
539mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) 537mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
540{ 538{
541 struct Queue *queue = impl_state; 539 struct Queue *queue = impl_state;
542 540
543 if (mq == queue->mq) 541 if (mq == queue->mq)
544 { 542 {
545 queue->mq = NULL; 543 queue->mq = NULL;
546 queue_destroy (queue); 544 queue_destroy(queue);
547 } 545 }
548} 546}
549 547
550 548
@@ -555,19 +553,19 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
555 * @param impl_state our `struct Queue` 553 * @param impl_state our `struct Queue`
556 */ 554 */
557static void 555static void
558mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) 556mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
559{ 557{
560 struct Queue *queue = impl_state; 558 struct Queue *queue = impl_state;
561 559
562 GNUNET_assert (NULL != queue->msg); 560 GNUNET_assert(NULL != queue->msg);
563 queue->msg = NULL; 561 queue->msg = NULL;
564 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); 562 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
565 GNUNET_assert (NULL != write_task); 563 GNUNET_assert(NULL != write_task);
566 if (NULL == queue_head) 564 if (NULL == queue_head)
567 { 565 {
568 GNUNET_SCHEDULER_cancel (write_task); 566 GNUNET_SCHEDULER_cancel(write_task);
569 write_task = NULL; 567 write_task = NULL;
570 } 568 }
571} 569}
572 570
573 571
@@ -581,15 +579,15 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
581 * @param error error code 579 * @param error error code
582 */ 580 */
583static void 581static void
584mq_error (void *cls, enum GNUNET_MQ_Error error) 582mq_error(void *cls, enum GNUNET_MQ_Error error)
585{ 583{
586 struct Queue *queue = cls; 584 struct Queue *queue = cls;
587 585
588 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 586 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
589 "UNIX MQ error in queue to %s: %d\n", 587 "UNIX MQ error in queue to %s: %d\n",
590 GNUNET_i2s (&queue->target), 588 GNUNET_i2s(&queue->target),
591 (int) error); 589 (int)error);
592 queue_destroy (queue); 590 queue_destroy(queue);
593} 591}
594 592
595 593
@@ -604,60 +602,60 @@ mq_error (void *cls, enum GNUNET_MQ_Error error)
604 * @return the queue or NULL of max connections exceeded 602 * @return the queue or NULL of max connections exceeded
605 */ 603 */
606static struct Queue * 604static struct Queue *
607setup_queue (const struct GNUNET_PeerIdentity *target, 605setup_queue(const struct GNUNET_PeerIdentity *target,
608 enum GNUNET_TRANSPORT_ConnectionStatus cs, 606 enum GNUNET_TRANSPORT_ConnectionStatus cs,
609 const struct sockaddr_un *un, 607 const struct sockaddr_un *un,
610 socklen_t un_len) 608 socklen_t un_len)
611{ 609{
612 struct Queue *queue; 610 struct Queue *queue;
613 611
614 queue = GNUNET_new (struct Queue); 612 queue = GNUNET_new(struct Queue);
615 queue->target = *target; 613 queue->target = *target;
616 queue->address = GNUNET_memdup (un, un_len); 614 queue->address = GNUNET_memdup(un, un_len);
617 queue->address_len = un_len; 615 queue->address_len = un_len;
618 (void) GNUNET_CONTAINER_multipeermap_put ( 616 (void)GNUNET_CONTAINER_multipeermap_put(
619 queue_map, 617 queue_map,
620 &queue->target, 618 &queue->target,
621 queue, 619 queue,
622 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 620 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
623 GNUNET_STATISTICS_set (stats, 621 GNUNET_STATISTICS_set(stats,
624 "# queues active", 622 "# queues active",
625 GNUNET_CONTAINER_multipeermap_size (queue_map), 623 GNUNET_CONTAINER_multipeermap_size(queue_map),
626 GNUNET_NO); 624 GNUNET_NO);
627 queue->timeout = 625 queue->timeout =
628 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 626 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
629 queue->timeout_task = 627 queue->timeout_task =
630 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 628 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
631 &queue_timeout, 629 &queue_timeout,
632 queue); 630 queue);
633 queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, 631 queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send,
634 &mq_destroy, 632 &mq_destroy,
635 &mq_cancel, 633 &mq_cancel,
636 queue, 634 queue,
637 NULL, 635 NULL,
638 &mq_error, 636 &mq_error,
639 queue); 637 queue);
640 { 638 {
641 char *foreign_addr; 639 char *foreign_addr;
642 640
643 if ('\0' == un->sun_path[0]) 641 if ('\0' == un->sun_path[0])
644 GNUNET_asprintf (&foreign_addr, 642 GNUNET_asprintf(&foreign_addr,
645 "%s-@%s", 643 "%s-@%s",
646 COMMUNICATOR_ADDRESS_PREFIX, 644 COMMUNICATOR_ADDRESS_PREFIX,
647 &un->sun_path[1]); 645 &un->sun_path[1]);
648 else 646 else
649 GNUNET_asprintf (&foreign_addr, 647 GNUNET_asprintf(&foreign_addr,
650 "%s-%s", 648 "%s-%s",
651 COMMUNICATOR_ADDRESS_PREFIX, 649 COMMUNICATOR_ADDRESS_PREFIX,
652 un->sun_path); 650 un->sun_path);
653 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, 651 queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch,
654 &queue->target, 652 &queue->target,
655 foreign_addr, 653 foreign_addr,
656 UNIX_MTU, 654 UNIX_MTU,
657 GNUNET_NT_LOOPBACK, 655 GNUNET_NT_LOOPBACK,
658 cs, 656 cs,
659 queue->mq); 657 queue->mq);
660 GNUNET_free (foreign_addr); 658 GNUNET_free(foreign_addr);
661 } 659 }
662 return queue; 660 return queue;
663} 661}
@@ -671,7 +669,7 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
671 * @param cls NULL 669 * @param cls NULL
672 */ 670 */
673static void 671static void
674select_read_cb (void *cls); 672select_read_cb(void *cls);
675 673
676 674
677/** 675/**
@@ -682,21 +680,21 @@ select_read_cb (void *cls);
682 * @param success #GNUNET_OK on success 680 * @param success #GNUNET_OK on success
683 */ 681 */
684static void 682static void
685receive_complete_cb (void *cls, int success) 683receive_complete_cb(void *cls, int success)
686{ 684{
687 (void) cls; 685 (void)cls;
688 delivering_messages--; 686 delivering_messages--;
689 if (GNUNET_OK != success) 687 if (GNUNET_OK != success)
690 GNUNET_STATISTICS_update (stats, 688 GNUNET_STATISTICS_update(stats,
691 "# transport transmission failures", 689 "# transport transmission failures",
692 1, 690 1,
693 GNUNET_NO); 691 GNUNET_NO);
694 GNUNET_assert (NULL != unix_sock); 692 GNUNET_assert(NULL != unix_sock);
695 if ((NULL == read_task) && (delivering_messages < max_queue_length)) 693 if ((NULL == read_task) && (delivering_messages < max_queue_length))
696 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 694 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
697 unix_sock, 695 unix_sock,
698 &select_read_cb, 696 &select_read_cb,
699 NULL); 697 NULL);
700} 698}
701 699
702 700
@@ -708,7 +706,7 @@ receive_complete_cb (void *cls, int success)
708 * @param cls NULL 706 * @param cls NULL
709 */ 707 */
710static void 708static void
711select_read_cb (void *cls) 709select_read_cb(void *cls)
712{ 710{
713 char buf[65536] GNUNET_ALIGN; 711 char buf[65536] GNUNET_ALIGN;
714 struct Queue *queue; 712 struct Queue *queue;
@@ -718,93 +716,93 @@ select_read_cb (void *cls)
718 ssize_t ret; 716 ssize_t ret;
719 uint16_t msize; 717 uint16_t msize;
720 718
721 GNUNET_assert (NULL != unix_sock); 719 GNUNET_assert(NULL != unix_sock);
722 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 720 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
723 unix_sock, 721 unix_sock,
724 &select_read_cb, 722 &select_read_cb,
725 NULL); 723 NULL);
726 addrlen = sizeof (un); 724 addrlen = sizeof(un);
727 memset (&un, 0, sizeof (un)); 725 memset(&un, 0, sizeof(un));
728 ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, 726 ret = GNUNET_NETWORK_socket_recvfrom(unix_sock,
729 buf, 727 buf,
730 sizeof (buf), 728 sizeof(buf),
731 (struct sockaddr *) &un, 729 (struct sockaddr *)&un,
732 &addrlen); 730 &addrlen);
733 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno))) 731 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
734 return; 732 return;
735 if (-1 == ret) 733 if (-1 == ret)
736 { 734 {
737 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 735 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom");
738 return; 736 return;
739 } 737 }
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
741 "Read %d bytes from socket %s\n", 739 "Read %d bytes from socket %s\n",
742 (int) ret, 740 (int)ret,
743 un.sun_path); 741 un.sun_path);
744 GNUNET_assert (AF_UNIX == (un.sun_family)); 742 GNUNET_assert(AF_UNIX == (un.sun_family));
745 msg = (struct UNIXMessage *) buf; 743 msg = (struct UNIXMessage *)buf;
746 msize = ntohs (msg->header.size); 744 msize = ntohs(msg->header.size);
747 if ((msize < sizeof (struct UNIXMessage)) || (msize > ret)) 745 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
748 { 746 {
749 GNUNET_break_op (0); 747 GNUNET_break_op(0);
750 return; 748 return;
751 } 749 }
752 queue = lookup_queue (&msg->sender, &un, addrlen); 750 queue = lookup_queue(&msg->sender, &un, addrlen);
753 if (NULL == queue) 751 if (NULL == queue)
754 queue = 752 queue =
755 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); 753 setup_queue(&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
756 else 754 else
757 reschedule_queue_timeout (queue); 755 reschedule_queue_timeout(queue);
758 if (NULL == queue) 756 if (NULL == queue)
759 { 757 {
760 GNUNET_log ( 758 GNUNET_log(
761 GNUNET_ERROR_TYPE_ERROR, 759 GNUNET_ERROR_TYPE_ERROR,
762 _ ( 760 _(
763 "Maximum number of UNIX connections exceeded, dropping incoming message\n")); 761 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
764 return; 762 return;
765 } 763 }
766 764
767 { 765 {
768 uint16_t offset = 0; 766 uint16_t offset = 0;
769 uint16_t tsize = msize - sizeof (struct UNIXMessage); 767 uint16_t tsize = msize - sizeof(struct UNIXMessage);
770 const char *msgbuf = (const char *) &msg[1]; 768 const char *msgbuf = (const char *)&msg[1];
771 769
772 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 770 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
773 {
774 const struct GNUNET_MessageHeader *currhdr;
775 struct GNUNET_MessageHeader al_hdr;
776 uint16_t csize;
777
778 currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset];
779 /* ensure aligned access */
780 memcpy (&al_hdr, currhdr, sizeof (al_hdr));
781 csize = ntohs (al_hdr.size);
782 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
783 (csize > tsize - offset))
784 { 771 {
785 GNUNET_break_op (0); 772 const struct GNUNET_MessageHeader *currhdr;
786 break; 773 struct GNUNET_MessageHeader al_hdr;
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;
787 } 798 }
788 ret = GNUNET_TRANSPORT_communicator_receive (ch,
789 &msg->sender,
790 currhdr,
791 GNUNET_TIME_UNIT_FOREVER_REL,
792 &receive_complete_cb,
793 NULL);
794 if (GNUNET_SYSERR == ret)
795 return; /* transport not up */
796 if (GNUNET_NO == ret)
797 break;
798 delivering_messages++;
799 offset += csize;
800 }
801 } 799 }
802 if (delivering_messages >= max_queue_length) 800 if (delivering_messages >= max_queue_length)
803 { 801 {
804 /* we should try to apply 'back pressure' */ 802 /* we should try to apply 'back pressure' */
805 GNUNET_SCHEDULER_cancel (read_task); 803 GNUNET_SCHEDULER_cancel(read_task);
806 read_task = NULL; 804 read_task = NULL;
807 } 805 }
808} 806}
809 807
810 808
@@ -826,43 +824,43 @@ select_read_cb (void *cls)
826 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid 824 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid
827 */ 825 */
828static int 826static int
829mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 827mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
830{ 828{
831 struct Queue *queue; 829 struct Queue *queue;
832 const char *path; 830 const char *path;
833 struct sockaddr_un *un; 831 struct sockaddr_un *un;
834 socklen_t un_len; 832 socklen_t un_len;
835 833
836 (void) cls; 834 (void)cls;
837 if (0 != strncmp (address, 835 if (0 != strncmp(address,
838 COMMUNICATOR_ADDRESS_PREFIX "-", 836 COMMUNICATOR_ADDRESS_PREFIX "-",
839 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 837 strlen(COMMUNICATOR_ADDRESS_PREFIX "-")))
840 { 838 {
841 GNUNET_break_op (0); 839 GNUNET_break_op(0);
842 return GNUNET_SYSERR; 840 return GNUNET_SYSERR;
843 } 841 }
844 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; 842 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")];
845 un = unix_address_to_sockaddr (path, &un_len); 843 un = unix_address_to_sockaddr(path, &un_len);
846 queue = lookup_queue (peer, un, un_len); 844 queue = lookup_queue(peer, un, un_len);
847 if (NULL != queue) 845 if (NULL != queue)
848 { 846 {
849 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 847 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
850 "Address `%s' for %s ignored, queue exists\n", 848 "Address `%s' for %s ignored, queue exists\n",
851 path, 849 path,
852 GNUNET_i2s (peer)); 850 GNUNET_i2s(peer));
853 GNUNET_free (un); 851 GNUNET_free(un);
854 return GNUNET_OK; 852 return GNUNET_OK;
855 } 853 }
856 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); 854 queue = setup_queue(peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
857 GNUNET_free (un); 855 GNUNET_free(un);
858 if (NULL == queue) 856 if (NULL == queue)
859 { 857 {
860 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 858 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
861 "Failed to setup queue to %s at `%s'\n", 859 "Failed to setup queue to %s at `%s'\n",
862 GNUNET_i2s (peer), 860 GNUNET_i2s(peer),
863 path); 861 path);
864 return GNUNET_NO; 862 return GNUNET_NO;
865 } 863 }
866 return GNUNET_OK; 864 return GNUNET_OK;
867} 865}
868 866
@@ -876,15 +874,15 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
876 * @return #GNUNET_OK to continue to iterate 874 * @return #GNUNET_OK to continue to iterate
877 */ 875 */
878static int 876static int
879get_queue_delete_it (void *cls, 877get_queue_delete_it(void *cls,
880 const struct GNUNET_PeerIdentity *target, 878 const struct GNUNET_PeerIdentity *target,
881 void *value) 879 void *value)
882{ 880{
883 struct Queue *queue = value; 881 struct Queue *queue = value;
884 882
885 (void) cls; 883 (void)cls;
886 (void) target; 884 (void)target;
887 queue_destroy (queue); 885 queue_destroy(queue);
888 return GNUNET_OK; 886 return GNUNET_OK;
889} 887}
890 888
@@ -895,40 +893,40 @@ get_queue_delete_it (void *cls,
895 * @param cls NULL (always) 893 * @param cls NULL (always)
896 */ 894 */
897static void 895static void
898do_shutdown (void *cls) 896do_shutdown(void *cls)
899{ 897{
900 if (NULL != read_task) 898 if (NULL != read_task)
901 { 899 {
902 GNUNET_SCHEDULER_cancel (read_task); 900 GNUNET_SCHEDULER_cancel(read_task);
903 read_task = NULL; 901 read_task = NULL;
904 } 902 }
905 if (NULL != write_task) 903 if (NULL != write_task)
906 { 904 {
907 GNUNET_SCHEDULER_cancel (write_task); 905 GNUNET_SCHEDULER_cancel(write_task);
908 write_task = NULL; 906 write_task = NULL;
909 } 907 }
910 if (NULL != unix_sock) 908 if (NULL != unix_sock)
911 { 909 {
912 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock)); 910 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(unix_sock));
913 unix_sock = NULL; 911 unix_sock = NULL;
914 } 912 }
915 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); 913 GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL);
916 GNUNET_CONTAINER_multipeermap_destroy (queue_map); 914 GNUNET_CONTAINER_multipeermap_destroy(queue_map);
917 if (NULL != ai) 915 if (NULL != ai)
918 { 916 {
919 GNUNET_TRANSPORT_communicator_address_remove (ai); 917 GNUNET_TRANSPORT_communicator_address_remove(ai);
920 ai = NULL; 918 ai = NULL;
921 } 919 }
922 if (NULL != ch) 920 if (NULL != ch)
923 { 921 {
924 GNUNET_TRANSPORT_communicator_disconnect (ch); 922 GNUNET_TRANSPORT_communicator_disconnect(ch);
925 ch = NULL; 923 ch = NULL;
926 } 924 }
927 if (NULL != stats) 925 if (NULL != stats)
928 { 926 {
929 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 927 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
930 stats = NULL; 928 stats = NULL;
931 } 929 }
932} 930}
933 931
934 932
@@ -944,14 +942,14 @@ do_shutdown (void *cls)
944 * @param msg payload 942 * @param msg payload
945 */ 943 */
946static void 944static void
947enc_notify_cb (void *cls, 945enc_notify_cb(void *cls,
948 const struct GNUNET_PeerIdentity *sender, 946 const struct GNUNET_PeerIdentity *sender,
949 const struct GNUNET_MessageHeader *msg) 947 const struct GNUNET_MessageHeader *msg)
950{ 948{
951 (void) cls; 949 (void)cls;
952 (void) sender; 950 (void)sender;
953 (void) msg; 951 (void)msg;
954 GNUNET_break_op (0); 952 GNUNET_break_op(0);
955} 953}
956 954
957 955
@@ -964,109 +962,110 @@ enc_notify_cb (void *cls,
964 * @param cfg configuration 962 * @param cfg configuration
965 */ 963 */
966static void 964static void
967run (void *cls, 965run(void *cls,
968 char *const *args, 966 char *const *args,
969 const char *cfgfile, 967 const char *cfgfile,
970 const struct GNUNET_CONFIGURATION_Handle *cfg) 968 const struct GNUNET_CONFIGURATION_Handle *cfg)
971{ 969{
972 char *unix_socket_path; 970 char *unix_socket_path;
973 struct sockaddr_un *un; 971 struct sockaddr_un *un;
974 socklen_t un_len; 972 socklen_t un_len;
975 char *my_addr; 973 char *my_addr;
976 (void) cls; 974
975 (void)cls;
977 976
978 if (GNUNET_OK != 977 if (GNUNET_OK !=
979 GNUNET_CONFIGURATION_get_value_filename (cfg, 978 GNUNET_CONFIGURATION_get_value_filename(cfg,
980 COMMUNICATOR_CONFIG_SECTION, 979 COMMUNICATOR_CONFIG_SECTION,
981 "UNIXPATH", 980 "UNIXPATH",
982 &unix_socket_path)) 981 &unix_socket_path))
983 { 982 {
984 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 983 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
985 COMMUNICATOR_CONFIG_SECTION, 984 COMMUNICATOR_CONFIG_SECTION,
986 "UNIXPATH"); 985 "UNIXPATH");
987 return; 986 return;
988 } 987 }
989 if (GNUNET_OK != 988 if (GNUNET_OK !=
990 GNUNET_CONFIGURATION_get_value_number (cfg, 989 GNUNET_CONFIGURATION_get_value_number(cfg,
991 COMMUNICATOR_CONFIG_SECTION, 990 COMMUNICATOR_CONFIG_SECTION,
992 "MAX_QUEUE_LENGTH", 991 "MAX_QUEUE_LENGTH",
993 &max_queue_length)) 992 &max_queue_length))
994 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 993 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
995 994
996 un = unix_address_to_sockaddr (unix_socket_path, &un_len); 995 un = unix_address_to_sockaddr(unix_socket_path, &un_len);
997 if (NULL == un) 996 if (NULL == un)
998 { 997 {
999 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 998 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1000 "Failed to setup UNIX domain socket address with path `%s'\n", 999 "Failed to setup UNIX domain socket address with path `%s'\n",
1001 unix_socket_path); 1000 unix_socket_path);
1002 GNUNET_free (unix_socket_path); 1001 GNUNET_free(unix_socket_path);
1003 return; 1002 return;
1004 } 1003 }
1005 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 1004 unix_sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0);
1006 if (NULL == unix_sock) 1005 if (NULL == unix_sock)
1007 { 1006 {
1008 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 1007 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
1009 GNUNET_free (un); 1008 GNUNET_free(un);
1010 GNUNET_free (unix_socket_path); 1009 GNUNET_free(unix_socket_path);
1011 return; 1010 return;
1012 } 1011 }
1013 if (('\0' != un->sun_path[0]) && 1012 if (('\0' != un->sun_path[0]) &&
1014 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))) 1013 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)))
1015 { 1014 {
1016 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1015 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1017 _ ("Cannot create path to `%s'\n"), 1016 _("Cannot create path to `%s'\n"),
1018 un->sun_path); 1017 un->sun_path);
1019 GNUNET_NETWORK_socket_close (unix_sock); 1018 GNUNET_NETWORK_socket_close(unix_sock);
1020 unix_sock = NULL; 1019 unix_sock = NULL;
1021 GNUNET_free (un); 1020 GNUNET_free(un);
1022 GNUNET_free (unix_socket_path); 1021 GNUNET_free(unix_socket_path);
1023 return; 1022 return;
1024 } 1023 }
1025 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock, 1024 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(unix_sock,
1026 (const struct sockaddr *) un, 1025 (const struct sockaddr *)un,
1027 un_len)) 1026 un_len))
1028 { 1027 {
1029 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); 1028 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1030 GNUNET_NETWORK_socket_close (unix_sock); 1029 GNUNET_NETWORK_socket_close(unix_sock);
1031 unix_sock = NULL; 1030 unix_sock = NULL;
1032 GNUNET_free (un); 1031 GNUNET_free(un);
1033 GNUNET_free (unix_socket_path); 1032 GNUNET_free(unix_socket_path);
1034 return; 1033 return;
1035 } 1034 }
1036 GNUNET_free (un); 1035 GNUNET_free(un);
1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); 1036 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1038 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg); 1037 stats = GNUNET_STATISTICS_create("C-UNIX", cfg);
1039 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1038 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
1040 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1039 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
1041 unix_sock, 1040 unix_sock,
1042 &select_read_cb, 1041 &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,
1043 NULL); 1051 NULL);
1044 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1045 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
1046 COMMUNICATOR_CONFIG_SECTION,
1047 COMMUNICATOR_ADDRESS_PREFIX,
1048 GNUNET_TRANSPORT_CC_RELIABLE,
1049 &mq_init,
1050 NULL,
1051 &enc_notify_cb,
1052 NULL);
1053 if (NULL == ch) 1052 if (NULL == ch)
1054 { 1053 {
1055 GNUNET_break (0); 1054 GNUNET_break(0);
1056 GNUNET_SCHEDULER_shutdown (); 1055 GNUNET_SCHEDULER_shutdown();
1057 GNUNET_free (unix_socket_path); 1056 GNUNET_free(unix_socket_path);
1058 return; 1057 return;
1059 } 1058 }
1060 GNUNET_asprintf (&my_addr, 1059 GNUNET_asprintf(&my_addr,
1061 "%s-%s", 1060 "%s-%s",
1062 COMMUNICATOR_ADDRESS_PREFIX, 1061 COMMUNICATOR_ADDRESS_PREFIX,
1063 unix_socket_path); 1062 unix_socket_path);
1064 GNUNET_free (unix_socket_path); 1063 GNUNET_free(unix_socket_path);
1065 ai = GNUNET_TRANSPORT_communicator_address_add (ch, 1064 ai = GNUNET_TRANSPORT_communicator_address_add(ch,
1066 my_addr, 1065 my_addr,
1067 GNUNET_NT_LOOPBACK, 1066 GNUNET_NT_LOOPBACK,
1068 GNUNET_TIME_UNIT_FOREVER_REL); 1067 GNUNET_TIME_UNIT_FOREVER_REL);
1069 GNUNET_free (my_addr); 1068 GNUNET_free(my_addr);
1070} 1069}
1071 1070
1072 1071
@@ -1078,26 +1077,27 @@ run (void *cls,
1078 * @return 0 ok, 1 on error 1077 * @return 0 ok, 1 on error
1079 */ 1078 */
1080int 1079int
1081main (int argc, char *const *argv) 1080main(int argc, char *const *argv)
1082{ 1081{
1083 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1082 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1084 GNUNET_GETOPT_OPTION_END}; 1083 GNUNET_GETOPT_OPTION_END
1084 };
1085 int ret; 1085 int ret;
1086 1086
1087 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1087 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1088 return 2; 1088 return 2;
1089 1089
1090 ret = (GNUNET_OK == 1090 ret = (GNUNET_OK ==
1091 GNUNET_PROGRAM_run (argc, 1091 GNUNET_PROGRAM_run(argc,
1092 argv, 1092 argv,
1093 "gnunet-communicator-unix", 1093 "gnunet-communicator-unix",
1094 _ ("GNUnet UNIX domain socket communicator"), 1094 _("GNUnet UNIX domain socket communicator"),
1095 options, 1095 options,
1096 &run, 1096 &run,
1097 NULL)) 1097 NULL))
1098 ? 0 1098 ? 0
1099 : 1; 1099 : 1;
1100 GNUNET_free ((void *) argv); 1100 GNUNET_free((void *)argv);
1101 return ret; 1101 return ret;
1102} 1102}
1103 1103
@@ -1108,11 +1108,11 @@ main (int argc, char *const *argv)
1108/** 1108/**
1109 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1109 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1110 */ 1110 */
1111void __attribute__ ((constructor)) GNUNET_ARM_memory_init () 1111void __attribute__ ((constructor)) GNUNET_ARM_memory_init()
1112{ 1112{
1113 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 1113 mallopt(M_TRIM_THRESHOLD, 4 * 1024);
1114 mallopt (M_TOP_PAD, 1 * 1024); 1114 mallopt(M_TOP_PAD, 1 * 1024);
1115 malloc_trim (0); 1115 malloc_trim(0);
1116} 1116}
1117#endif 1117#endif
1118 1118
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c
index 217022190..2ac705996 100644
--- a/src/transport/gnunet-helper-transport-bluetooth.c
+++ b/src/transport/gnunet-helper-transport-bluetooth.c
@@ -13,12 +13,12 @@
13 WITHOUT ANY WARRANTY; without even the implied warranty of 13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Affero General Public License for more details. 15 Affero General Public License for more details.
16 16
17 You should have received a copy of the GNU Affero General Public License 17 You should have received a copy of the GNU Affero General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 SPDX-License-Identifier: AGPL3.0-or-later 20 SPDX-License-Identifier: AGPL3.0-or-later
21*/ 21 */
22#include "gnunet_config.h" 22#include "gnunet_config.h"
23 23
24#ifdef MINGW 24#ifdef MINGW
@@ -68,32 +68,31 @@
68#define MAX_LOOPS 5 68#define MAX_LOOPS 5
69 69
70#ifdef MINGW 70#ifdef MINGW
71 /* Maximum size of the interface's name */ 71/* Maximum size of the interface's name */
72 #define IFNAMSIZ 16 72 #define IFNAMSIZ 16
73 73
74 #ifndef NS_BTH 74 #ifndef NS_BTH
75 #define NS_BTH 16 75 #define NS_BTH 16
76 #endif 76 #endif
77 /** 77/**
78 * A copy of the MAC Address. 78 * A copy of the MAC Address.
79 */ 79 */
80 struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy 80struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy {
81 { 81 UINT8 mac[MAC_ADDR_SIZE];
82 UINT8 mac[MAC_ADDR_SIZE]; 82};
83 };
84 83
85 /** 84/**
86 * The UUID used for the SDP service. 85 * The UUID used for the SDP service.
87 * {31191E56-FA7E-4517-870E-71B86BBCC52F} 86 * {31191E56-FA7E-4517-870E-71B86BBCC52F}
88 */ 87 */
89 #define GNUNET_BLUETOOTH_SDP_UUID \ 88 #define GNUNET_BLUETOOTH_SDP_UUID \
90 { \ 89 { \
91 0x31, 0x19, 0x1E, 0x56, \ 90 0x31, 0x19, 0x1E, 0x56, \
92 0xFA, 0x7E, \ 91 0xFA, 0x7E, \
93 0x45, 0x17, \ 92 0x45, 0x17, \
94 0x87, 0x0E, \ 93 0x87, 0x0E, \
95 0x71, 0xB8, 0x6B, 0xBC, 0xC5, 0x2F \ 94 0x71, 0xB8, 0x6B, 0xBC, 0xC5, 0x2F \
96 } 95 }
97#endif 96#endif
98 97
99/** 98/**
@@ -105,8 +104,7 @@
105 * struct for storing the information of the hardware. There is only 104 * struct for storing the information of the hardware. There is only
106 * one of these. 105 * one of these.
107 */ 106 */
108struct HardwareInfos 107struct HardwareInfos {
109{
110 /** 108 /**
111 * Name of the interface, not necessarily 0-terminated (!). 109 * Name of the interface, not necessarily 0-terminated (!).
112 */ 110 */
@@ -136,15 +134,14 @@ struct HardwareInfos
136 /** 134 /**
137 * SDP session 135 * SDP session
138 */ 136 */
139 sdp_session_t *session ; 137 sdp_session_t *session;
140 #endif 138 #endif
141}; 139};
142 140
143/** 141/**
144 * IO buffer used for buffering data in transit (to wireless or to stdout). 142 * IO buffer used for buffering data in transit (to wireless or to stdout).
145 */ 143 */
146struct SendBuffer 144struct SendBuffer {
147{
148 /** 145 /**
149 * How many bytes of data are stored in 'buf' for transmission right now? 146 * How many bytes of data are stored in 'buf' for transmission right now?
150 * Data always starts at offset 0 and extends to 'size'. 147 * Data always starts at offset 0 and extends to 'size'.
@@ -165,40 +162,39 @@ struct SendBuffer
165}; 162};
166 163
167#ifdef LINUX 164#ifdef LINUX
168 /** 165/**
169 * Devices buffer used to keep a list with all the discoverable devices in 166 * Devices buffer used to keep a list with all the discoverable devices in
170 * order to send them HELLO messages one by one when it receive a broadcast message. 167 * order to send them HELLO messages one by one when it receive a broadcast message.
171 */ 168 */
172 struct BroadcastMessages 169struct BroadcastMessages {
173 { 170 /* List with the discoverable devices' addresses */
174 /* List with the discoverable devices' addresses */ 171 bdaddr_t devices[MAX_PORTS];
175 bdaddr_t devices[MAX_PORTS];
176 172
177 /* List with the open sockets */ 173 /* List with the open sockets */
178 int fds[MAX_PORTS]; 174 int fds[MAX_PORTS];
179 175
180 176
181 /* The number of the devices */ 177 /* The number of the devices */
182 int size; 178 int size;
183 179
184 /* The current position */ 180 /* The current position */
185 int pos; 181 int pos;
186 182
187 /* The device id */ 183 /* The device id */
188 int dev_id; 184 int dev_id;
189 }; 185};
190 186
191 /** 187/**
192 * Address used to identify the broadcast messages. 188 * Address used to identify the broadcast messages.
193 */ 189 */
194 static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = {{255, 255, 255, 255, 255, 255}}; 190static struct GNUNET_TRANSPORT_WLAN_MacAddress broadcast_address = { { 255, 255, 255, 255, 255, 255 } };
195 191
196 /** 192/**
197 * Buffer with the discoverable devices. 193 * Buffer with the discoverable devices.
198 */ 194 */
199 static struct BroadcastMessages neighbours; 195static struct BroadcastMessages neighbours;
200 196
201 static int searching_devices_count = 0; 197static int searching_devices_count = 0;
202#endif 198#endif
203 199
204/** 200/**
@@ -223,7 +219,7 @@ static struct SendBuffer write_std;
223/** 219/**
224 * Smallest supported message. 220 * Smallest supported message.
225 */ 221 */
226#define MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) 222#define MIN_BUFFER_SIZE sizeof(struct GNUNET_MessageHeader)
227 223
228 224
229/** 225/**
@@ -234,16 +230,14 @@ static struct SendBuffer write_std;
234 * @param message the actual message 230 * @param message the actual message
235 */ 231 */
236typedef void (*MessageTokenizerCallback) (void *cls, 232typedef void (*MessageTokenizerCallback) (void *cls,
237 const struct 233 const struct
238 GNUNET_MessageHeader * 234 GNUNET_MessageHeader *
239 message); 235 message);
240 236
241/** 237/**
242 * Handle to a message stream tokenizer. 238 * Handle to a message stream tokenizer.
243 */ 239 */
244struct MessageStreamTokenizer 240struct MessageStreamTokenizer {
245{
246
247 /** 241 /**
248 * Function to call on completed messages. 242 * Function to call on completed messages.
249 */ 243 */
@@ -273,7 +267,6 @@ struct MessageStreamTokenizer
273 * Beginning of the buffer. Typed like this to force alignment. 267 * Beginning of the buffer. Typed like this to force alignment.
274 */ 268 */
275 struct GNUNET_MessageHeader *hdr; 269 struct GNUNET_MessageHeader *hdr;
276
277}; 270};
278 271
279 272
@@ -285,23 +278,23 @@ struct MessageStreamTokenizer
285 * @return handle to tokenizer 278 * @return handle to tokenizer
286 */ 279 */
287static struct MessageStreamTokenizer * 280static struct MessageStreamTokenizer *
288mst_create (MessageTokenizerCallback cb, 281mst_create(MessageTokenizerCallback cb,
289 void *cb_cls) 282 void *cb_cls)
290{ 283{
291 struct MessageStreamTokenizer *ret; 284 struct MessageStreamTokenizer *ret;
292 285
293 ret = malloc (sizeof (struct MessageStreamTokenizer)); 286 ret = malloc(sizeof(struct MessageStreamTokenizer));
294 if (NULL == ret) 287 if (NULL == ret)
295 { 288 {
296 fprintf (stderr, "Failed to allocate buffer for tokenizer\n"); 289 fprintf(stderr, "Failed to allocate buffer for tokenizer\n");
297 exit (1); 290 exit(1);
298 } 291 }
299 ret->hdr = malloc (MIN_BUFFER_SIZE); 292 ret->hdr = malloc(MIN_BUFFER_SIZE);
300 if (NULL == ret->hdr) 293 if (NULL == ret->hdr)
301 { 294 {
302 fprintf (stderr, "Failed to allocate buffer for alignment\n"); 295 fprintf(stderr, "Failed to allocate buffer for alignment\n");
303 exit (1); 296 exit(1);
304 } 297 }
305 ret->curr_buf = MIN_BUFFER_SIZE; 298 ret->curr_buf = MIN_BUFFER_SIZE;
306 ret->cb = cb; 299 ret->cb = cb;
307 ret->cb_cls = cb_cls; 300 ret->cb_cls = cb_cls;
@@ -322,8 +315,8 @@ mst_create (MessageTokenizerCallback cb,
322 * GNUNET_SYSERR if the data stream is corrupt 315 * GNUNET_SYSERR if the data stream is corrupt
323 */ 316 */
324static int 317static int
325mst_receive (struct MessageStreamTokenizer *mst, 318mst_receive(struct MessageStreamTokenizer *mst,
326 const char *buf, size_t size) 319 const char *buf, size_t size)
327{ 320{
328 const struct GNUNET_MessageHeader *hdr; 321 const struct GNUNET_MessageHeader *hdr;
329 size_t delta; 322 size_t delta;
@@ -334,161 +327,161 @@ mst_receive (struct MessageStreamTokenizer *mst,
334 int ret; 327 int ret;
335 328
336 ret = GNUNET_OK; 329 ret = GNUNET_OK;
337 ibuf = (char *) mst->hdr; 330 ibuf = (char *)mst->hdr;
338 while (mst->pos > 0) 331 while (mst->pos > 0)
339 {
340do_align:
341 if (mst->pos < mst->off)
342 {
343 //fprintf (stderr, "We processed too many bytes!\n");
344 return GNUNET_SYSERR;
345 }
346 if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
347 (0 != (mst->off % ALIGN_FACTOR)))
348 { 332 {
349 /* need to align or need more space */ 333do_align:
350 mst->pos -= mst->off; 334 if (mst->pos < mst->off)
351 memmove (ibuf, &ibuf[mst->off], mst->pos); 335 {
352 mst->off = 0; 336 //fprintf (stderr, "We processed too many bytes!\n");
353 } 337 return GNUNET_SYSERR;
354 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) 338 }
355 { 339 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
356 delta = 340 (0 != (mst->off % ALIGN_FACTOR)))
357 GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - 341 {
358 (mst->pos - mst->off), size); 342 /* need to align or need more space */
359 GNUNET_memcpy (&ibuf[mst->pos], buf, delta); 343 mst->pos -= mst->off;
360 mst->pos += delta; 344 memmove(ibuf, &ibuf[mst->off], mst->pos);
361 buf += delta; 345 mst->off = 0;
362 size -= delta; 346 }
363 } 347 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
364 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) 348 {
365 { 349 delta =
366 //FIXME should I reset ?? 350 GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) -
367 // mst->off = 0; 351 (mst->pos - mst->off), size);
368 // mst->pos = 0; 352 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
369 return GNUNET_OK; 353 mst->pos += delta;
354 buf += delta;
355 size -= delta;
356 }
357 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
358 {
359 //FIXME should I reset ??
360 // mst->off = 0;
361 // mst->pos = 0;
362 return GNUNET_OK;
363 }
364 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
365 want = ntohs(hdr->size);
366 if (want < sizeof(struct GNUNET_MessageHeader))
367 {
368 fprintf(stderr,
369 "Received invalid message from stdin\n");
370 return GNUNET_SYSERR;
371 }
372 if ((mst->curr_buf - mst->off < want) &&
373 (mst->off > 0))
374 {
375 /* need more space */
376 mst->pos -= mst->off;
377 memmove(ibuf, &ibuf[mst->off], mst->pos);
378 mst->off = 0;
379 }
380 if (want > mst->curr_buf)
381 {
382 if (mst->off != 0)
383 {
384 fprintf(stderr, "Error! We should proceeded 0 bytes\n");
385 return GNUNET_SYSERR;
386 }
387 mst->hdr = realloc(mst->hdr, want);
388 if (NULL == mst->hdr)
389 {
390 fprintf(stderr, "Failed to allocate buffer for alignment\n");
391 exit(1);
392 }
393 ibuf = (char *)mst->hdr;
394 mst->curr_buf = want;
395 }
396 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
397 if (mst->pos - mst->off < want)
398 {
399 delta = GNUNET_MIN(want - (mst->pos - mst->off), size);
400 if (mst->pos + delta > mst->curr_buf)
401 {
402 fprintf(stderr, "The size of the buffer will be exceeded!\n");
403 return GNUNET_SYSERR;
404 }
405 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
406 mst->pos += delta;
407 buf += delta;
408 size -= delta;
409 }
410 if (mst->pos - mst->off < want)
411 {
412 //FIXME should I use this?
413 // mst->off = 0;
414 // mst->pos = 0;
415 return GNUNET_OK;
416 }
417 mst->cb(mst->cb_cls, hdr);
418 mst->off += want;
419 if (mst->off == mst->pos)
420 {
421 /* reset to beginning of buffer, it's free right now! */
422 mst->off = 0;
423 mst->pos = 0;
424 }
370 } 425 }
371 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; 426 if (0 != mst->pos)
372 want = ntohs (hdr->size);
373 if (want < sizeof (struct GNUNET_MessageHeader))
374 { 427 {
375 fprintf (stderr, 428 fprintf(stderr, "There should some valid bytes in the buffer on this stage\n");
376 "Received invalid message from stdin\n");
377 return GNUNET_SYSERR; 429 return GNUNET_SYSERR;
378 } 430 }
379 if ((mst->curr_buf - mst->off < want) &&
380 (mst->off > 0))
381 {
382 /* need more space */
383 mst->pos -= mst->off;
384 memmove (ibuf, &ibuf[mst->off], mst->pos);
385 mst->off = 0;
386 }
387 if (want > mst->curr_buf)
388 {
389 if (mst->off != 0)
390 {
391 fprintf (stderr, "Error! We should proceeded 0 bytes\n");
392 return GNUNET_SYSERR;
393 }
394 mst->hdr = realloc (mst->hdr, want);
395 if (NULL == mst->hdr)
396 {
397 fprintf (stderr, "Failed to allocate buffer for alignment\n");
398 exit (1);
399 }
400 ibuf = (char *) mst->hdr;
401 mst->curr_buf = want;
402 }
403 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
404 if (mst->pos - mst->off < want)
405 {
406 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
407 if (mst->pos + delta > mst->curr_buf)
408 {
409 fprintf (stderr, "The size of the buffer will be exceeded!\n");
410 return GNUNET_SYSERR;
411 }
412 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
413 mst->pos += delta;
414 buf += delta;
415 size -= delta;
416 }
417 if (mst->pos - mst->off < want)
418 {
419 //FIXME should I use this?
420 // mst->off = 0;
421 // mst->pos = 0;
422 return GNUNET_OK;
423 }
424 mst->cb (mst->cb_cls, hdr);
425 mst->off += want;
426 if (mst->off == mst->pos)
427 {
428 /* reset to beginning of buffer, it's free right now! */
429 mst->off = 0;
430 mst->pos = 0;
431 }
432 }
433 if (0 != mst->pos)
434 {
435 fprintf (stderr, "There should some valid bytes in the buffer on this stage\n");
436 return GNUNET_SYSERR;
437 }
438 while (size > 0) 431 while (size > 0)
439 {
440 if (size < sizeof (struct GNUNET_MessageHeader))
441 break;
442 offset = (unsigned long) buf;
443 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
444 if (GNUNET_NO == need_align)
445 {
446 /* can try to do zero-copy and process directly from original buffer */
447 hdr = (const struct GNUNET_MessageHeader *) buf;
448 want = ntohs (hdr->size);
449 if (want < sizeof (struct GNUNET_MessageHeader))
450 {
451 fprintf (stderr,
452 "Received invalid message from stdin\n");
453 //exit (1);
454 mst->off = 0;
455 return GNUNET_SYSERR;
456 }
457 if (size < want)
458 break; /* or not, buffer incomplete, so copy to private buffer... */
459 mst->cb (mst->cb_cls, hdr);
460 buf += want;
461 size -= want;
462 }
463 else
464 { 432 {
465 /* need to copy to private buffer to align; 433 if (size < sizeof(struct GNUNET_MessageHeader))
466 * yes, we go a bit more spagetti than usual here */ 434 break;
467 goto do_align; 435 offset = (unsigned long)buf;
436 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
437 if (GNUNET_NO == need_align)
438 {
439 /* can try to do zero-copy and process directly from original buffer */
440 hdr = (const struct GNUNET_MessageHeader *)buf;
441 want = ntohs(hdr->size);
442 if (want < sizeof(struct GNUNET_MessageHeader))
443 {
444 fprintf(stderr,
445 "Received invalid message from stdin\n");
446 //exit (1);
447 mst->off = 0;
448 return GNUNET_SYSERR;
449 }
450 if (size < want)
451 break; /* or not, buffer incomplete, so copy to private buffer... */
452 mst->cb(mst->cb_cls, hdr);
453 buf += want;
454 size -= want;
455 }
456 else
457 {
458 /* need to copy to private buffer to align;
459 * yes, we go a bit more spagetti than usual here */
460 goto do_align;
461 }
468 } 462 }
469 }
470 if (size > 0) 463 if (size > 0)
471 {
472 if (size + mst->pos > mst->curr_buf)
473 { 464 {
474 mst->hdr = realloc (mst->hdr, size + mst->pos); 465 if (size + mst->pos > mst->curr_buf)
475 if (NULL == mst->hdr) 466 {
476 { 467 mst->hdr = realloc(mst->hdr, size + mst->pos);
477 fprintf (stderr, "Failed to allocate buffer for alignment\n"); 468 if (NULL == mst->hdr)
478 exit (1); 469 {
479 } 470 fprintf(stderr, "Failed to allocate buffer for alignment\n");
480 ibuf = (char *) mst->hdr; 471 exit(1);
481 mst->curr_buf = size + mst->pos; 472 }
482 } 473 ibuf = (char *)mst->hdr;
483 if (mst->pos + size > mst->curr_buf) 474 mst->curr_buf = size + mst->pos;
484 { 475 }
485 fprintf (stderr, 476 if (mst->pos + size > mst->curr_buf)
486 "Assertion failed\n"); 477 {
487 exit (1); 478 fprintf(stderr,
479 "Assertion failed\n");
480 exit(1);
481 }
482 GNUNET_memcpy(&ibuf[mst->pos], buf, size);
483 mst->pos += size;
488 } 484 }
489 GNUNET_memcpy (&ibuf[mst->pos], buf, size);
490 mst->pos += size;
491 }
492 return ret; 485 return ret;
493} 486}
494 487
@@ -498,10 +491,10 @@ do_align:
498 * @param mst tokenizer to destroy 491 * @param mst tokenizer to destroy
499 */ 492 */
500static void 493static void
501mst_destroy (struct MessageStreamTokenizer *mst) 494mst_destroy(struct MessageStreamTokenizer *mst)
502{ 495{
503 free (mst->hdr); 496 free(mst->hdr);
504 free (mst); 497 free(mst);
505} 498}
506 499
507/** 500/**
@@ -512,7 +505,7 @@ mst_destroy (struct MessageStreamTokenizer *mst)
512 * @return crc sum 505 * @return crc sum
513 */ 506 */
514static unsigned long 507static unsigned long
515calc_crc_osdep (const unsigned char *buf, size_t len) 508calc_crc_osdep(const unsigned char *buf, size_t len)
516{ 509{
517 static const unsigned long int crc_tbl_osdep[256] = { 510 static const unsigned long int crc_tbl_osdep[256] = {
518 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 511 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
@@ -585,7 +578,7 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
585 578
586 for (; len > 0; len--, buf++) 579 for (; len > 0; len--, buf++)
587 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8); 580 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
588 return (~crc); 581 return(~crc);
589} 582}
590 583
591 584
@@ -598,11 +591,11 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
598 * @return 0 on success (checksum matches), 1 on error 591 * @return 0 on success (checksum matches), 1 on error
599 */ 592 */
600static int 593static int
601check_crc_buf_osdep (const unsigned char *buf, size_t len) 594check_crc_buf_osdep(const unsigned char *buf, size_t len)
602{ 595{
603 unsigned long crc; 596 unsigned long crc;
604 597
605 crc = calc_crc_osdep (buf, len); 598 crc = calc_crc_osdep(buf, len);
606 buf += len; 599 buf += len;
607 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && 600 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
608 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]) 601 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
@@ -615,402 +608,409 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
615/* ************** end of clone ***************** */ 608/* ************** end of clone ***************** */
616 609
617#ifdef MINGW 610#ifdef MINGW
618 /** 611/**
619 * Function used to get the code of last error and to print the type of error. 612 * Function used to get the code of last error and to print the type of error.
620 */ 613 */
621 static void 614static void
622 print_last_error() 615print_last_error()
623 { 616{
624 LPVOID lpMsgBuf = NULL; 617 LPVOID lpMsgBuf = NULL;
625 618
626 if (FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 619 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
627 NULL, GetLastError(), 0, (LPTSTR) &lpMsgBuf, 0, NULL)) 620 NULL, GetLastError(), 0, (LPTSTR)&lpMsgBuf, 0, NULL))
628 fprintf (stderr, "%s\n", (char *)lpMsgBuf); 621 fprintf(stderr, "%s\n", (char *)lpMsgBuf);
629 else 622 else
630 fprintf (stderr, "Failed to format the message for the last error! Error number : %d\n", GetLastError()); 623 fprintf(stderr, "Failed to format the message for the last error! Error number : %d\n", GetLastError());
631 } 624}
632 625
633 /** 626/**
634 * Function used to initialize the Windows Sockets 627 * Function used to initialize the Windows Sockets
635 */ 628 */
636 static void 629static void
637 initialize_windows_sockets() 630initialize_windows_sockets()
638 { 631{
639 WSADATA wsaData ; 632 WSADATA wsaData;
640 WORD wVersionRequested = MAKEWORD (2, 0); 633 WORD wVersionRequested = MAKEWORD(2, 0);
641 if (WSAStartup (wVersionRequested, &wsaData) != NO_ERROR) 634
635 if (WSAStartup(wVersionRequested, &wsaData) != NO_ERROR)
642 { 636 {
643 fprintf (stderr , "Error initializing window sockets!\n"); 637 fprintf(stderr, "Error initializing window sockets!\n");
644 print_last_error(); 638 print_last_error();
645 ExitProcess (2) ; 639 ExitProcess(2);
646 } 640 }
647 } 641}
648 642
649 /** 643/**
650 * Function used to convert the GUID. 644 * Function used to convert the GUID.
651 * @param bytes the GUID represented as a char array 645 * @param bytes the GUID represented as a char array
652 * @param uuid pointer to the GUID 646 * @param uuid pointer to the GUID
653 */ 647 */
654 static void 648static void
655 convert_guid(char *bytes, GUID * uuid) 649convert_guid(char *bytes, GUID * uuid)
656 { 650{
657 int i; 651 int i;
658 uuid->Data1 = ((bytes[0] << 24) & 0xff000000) | ((bytes[1] << 16) & 0x00ff0000) | ((bytes[2] << 8) & 0x0000ff00) | (bytes[3] & 0x000000ff); 652
659 uuid->Data2 = ((bytes[4] << 8) & 0xff00) | (bytes[5] & 0x00ff); 653 uuid->Data1 = ((bytes[0] << 24) & 0xff000000) | ((bytes[1] << 16) & 0x00ff0000) | ((bytes[2] << 8) & 0x0000ff00) | (bytes[3] & 0x000000ff);
660 uuid->Data3 = ((bytes[6] << 8) & 0xff00) | (bytes[7] & 0x00ff); 654 uuid->Data2 = ((bytes[4] << 8) & 0xff00) | (bytes[5] & 0x00ff);
655 uuid->Data3 = ((bytes[6] << 8) & 0xff00) | (bytes[7] & 0x00ff);
661 656
662 for (i = 0; i < 8; i++) 657 for (i = 0; i < 8; i++)
663 { 658 {
664 uuid->Data4[i] = bytes[i + 8]; 659 uuid->Data4[i] = bytes[i + 8];
665 } 660 }
666 } 661}
667#endif 662#endif
668 663
669#ifdef LINUX 664#ifdef LINUX
670 /** 665/**
671 * Function for assigning a port number 666 * Function for assigning a port number
672 * 667 *
673 * @param socket the socket used to bind 668 * @param socket the socket used to bind
674 * @param addr pointer to the rfcomm address 669 * @param addr pointer to the rfcomm address
675 * @return 0 on success 670 * @return 0 on success
676 */ 671 */
677 static int 672static int
678 bind_socket (int socket, struct sockaddr_rc *addr) 673bind_socket(int socket, struct sockaddr_rc *addr)
679 { 674{
680 int port, status; 675 int port, status;
681 676
682 /* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */ 677 /* Bind every possible port (from 0 to 30) and stop when binding doesn't fail */
683 //FIXME : it should start from port 1, but on my computer it doesn't work :) 678 //FIXME : it should start from port 1, but on my computer it doesn't work :)
684 for (port = 3; port <= 30; port++) 679 for (port = 3; port <= 30; port++)
685 { 680 {
686 addr->rc_channel = port; 681 addr->rc_channel = port;
687 status = bind (socket, (struct sockaddr *) addr, sizeof (struct sockaddr_rc)); 682 status = bind(socket, (struct sockaddr *)addr, sizeof(struct sockaddr_rc));
688 if (status == 0) 683 if (status == 0)
689 return 0; 684 return 0;
690 } 685 }
691 686
692 return -1; 687 return -1;
693 } 688}
694#endif 689#endif
695 690
696#ifdef MINGW 691#ifdef MINGW
697 /** 692/**
698 * Function used for creating the service record and registering it. 693 * Function used for creating the service record and registering it.
699 * 694 *
700 * @param dev pointer to the device struct 695 * @param dev pointer to the device struct
701 * @return 0 on success 696 * @return 0 on success
702 */ 697 */
703 static int 698static int
704 register_service (struct HardwareInfos *dev) 699register_service(struct HardwareInfos *dev)
705 { 700{
706 /* advertise the service */ 701 /* advertise the service */
707 CSADDR_INFO addr_info; 702 CSADDR_INFO addr_info;
708 WSAQUERYSET wqs; 703 WSAQUERYSET wqs;
709 GUID guid; 704 GUID guid;
710 unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID; 705 unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
711 SOCKADDR_BTH addr; 706 SOCKADDR_BTH addr;
712 int addr_len = sizeof (SOCKADDR_BTH); 707 int addr_len = sizeof(SOCKADDR_BTH);
713 int fd; 708 int fd;
714 /* get the port on which we are listening on */ 709
715 memset (& addr, 0, sizeof (SOCKADDR_BTH)); 710 /* get the port on which we are listening on */
716 fd = GNUNET_NETWORK_get_fd (dev->handle); 711 memset(&addr, 0, sizeof(SOCKADDR_BTH));
717 if (fd <= 0) 712 fd = GNUNET_NETWORK_get_fd(dev->handle);
713 if (fd <= 0)
718 { 714 {
719 fprintf (stderr, "Failed to get the file descriptor\n"); 715 fprintf(stderr, "Failed to get the file descriptor\n");
720 return -1; 716 return -1;
721 } 717 }
722 if (SOCKET_ERROR == getsockname (fd, (SOCKADDR*)&addr, &addr_len)) 718 if (SOCKET_ERROR == getsockname(fd, (SOCKADDR*)&addr, &addr_len))
723 { 719 {
724 fprintf (stderr, "Failed to get the port on which we are listening on: \n"); 720 fprintf(stderr, "Failed to get the port on which we are listening on: \n");
725 print_last_error(); 721 print_last_error();
726 return -1; 722 return -1;
727 } 723 }
728 724
729 /* save the device address */ 725 /* save the device address */
730 GNUNET_memcpy (&dev->pl_mac, &addr.btAddr, sizeof (BTH_ADDR)); 726 GNUNET_memcpy(&dev->pl_mac, &addr.btAddr, sizeof(BTH_ADDR));
731 727
732 /* set the address information */ 728 /* set the address information */
733 memset (&addr_info, 0, sizeof (CSADDR_INFO)); 729 memset(&addr_info, 0, sizeof(CSADDR_INFO));
734 addr_info.iProtocol = BTHPROTO_RFCOMM; 730 addr_info.iProtocol = BTHPROTO_RFCOMM;
735 addr_info.iSocketType = SOCK_STREAM; 731 addr_info.iSocketType = SOCK_STREAM;
736 addr_info.LocalAddr.lpSockaddr = (LPSOCKADDR)&addr; 732 addr_info.LocalAddr.lpSockaddr = (LPSOCKADDR)&addr;
737 addr_info.LocalAddr.iSockaddrLength = sizeof (addr); 733 addr_info.LocalAddr.iSockaddrLength = sizeof(addr);
738 addr_info.RemoteAddr.lpSockaddr = (LPSOCKADDR)&addr; 734 addr_info.RemoteAddr.lpSockaddr = (LPSOCKADDR)&addr;
739 addr_info.RemoteAddr.iSockaddrLength = sizeof (addr); 735 addr_info.RemoteAddr.iSockaddrLength = sizeof(addr);
740 736
741 convert_guid((char *) uuid, &guid); 737 convert_guid((char *)uuid, &guid);
742 738
743 /* register the service */ 739 /* register the service */
744 memset (&wqs, 0, sizeof (WSAQUERYSET)); 740 memset(&wqs, 0, sizeof(WSAQUERYSET));
745 wqs.dwSize = sizeof (WSAQUERYSET); 741 wqs.dwSize = sizeof(WSAQUERYSET);
746 wqs.dwNameSpace = NS_BTH; 742 wqs.dwNameSpace = NS_BTH;
747 wqs.lpszServiceInstanceName = "GNUnet Bluetooth Service"; 743 wqs.lpszServiceInstanceName = "GNUnet Bluetooth Service";
748 wqs.lpszComment = "This is the service used by the GNUnnet plugin transport"; 744 wqs.lpszComment = "This is the service used by the GNUnnet plugin transport";
749 wqs.lpServiceClassId = &guid; 745 wqs.lpServiceClassId = &guid;
750 wqs.dwNumberOfCsAddrs = 1; 746 wqs.dwNumberOfCsAddrs = 1;
751 wqs.lpcsaBuffer = &addr_info ; 747 wqs.lpcsaBuffer = &addr_info;
752 wqs.lpBlob = 0; 748 wqs.lpBlob = 0;
753 749
754 if (SOCKET_ERROR == WSASetService (&wqs , RNRSERVICE_REGISTER, 0)) 750 if (SOCKET_ERROR == WSASetService(&wqs, RNRSERVICE_REGISTER, 0))
755 { 751 {
756 fprintf (stderr, "Failed to register the SDP service: "); 752 fprintf(stderr, "Failed to register the SDP service: ");
757 print_last_error(); 753 print_last_error();
758 return -1; 754 return -1;
759 } 755 }
760 else 756 else
761 { 757 {
762 fprintf (stderr, "The SDP service was registered\n"); 758 fprintf(stderr, "The SDP service was registered\n");
763 } 759 }
764 760
765 return 0; 761 return 0;
766 } 762}
767#else 763#else
764/**
765 * Function used for creating the service record and registering it.
766 *
767 * @param dev pointer to the device struct
768 * @param rc_channel the rfcomm channel
769 * @return 0 on success
770 */
771static int
772register_service(struct HardwareInfos *dev, int rc_channel)
773{
768 /** 774 /**
769 * Function used for creating the service record and registering it. 775 * 1. initializations
770 * 776 * 2. set the service ID, class, profile information
771 * @param dev pointer to the device struct 777 * 3. make the service record publicly browsable
772 * @param rc_channel the rfcomm channel 778 * 4. register the RFCOMM channel
773 * @return 0 on success 779 * 5. set the name, provider and description
780 * 6. register the service record to the local SDP server
781 * 7. cleanup
774 */ 782 */
775 static int 783 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
776 register_service (struct HardwareInfos *dev, int rc_channel) 784 dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3],
777 { 785 dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0] };
778 /** 786 const char *service_dsc = "Bluetooth plugin services";
779 * 1. initializations 787 const char *service_prov = "GNUnet provider";
780 * 2. set the service ID, class, profile information 788 uuid_t root_uuid, rfcomm_uuid, svc_uuid;
781 * 3. make the service record publicly browsable 789 sdp_list_t *root_list = 0, *rfcomm_list = 0, *proto_list = 0,
782 * 4. register the RFCOMM channel 790 *access_proto_list = 0, *svc_list = 0;
783 * 5. set the name, provider and description 791 sdp_record_t *record = 0;
784 * 6. register the service record to the local SDP server 792 sdp_data_t *channel = 0;
785 * 7. cleanup 793
786 */ 794 record = sdp_record_alloc();
787 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 795
788 dev->pl_mac.mac[5], dev->pl_mac.mac[4], dev->pl_mac.mac[3], 796 /* Set the general service ID */
789 dev->pl_mac.mac[2], dev->pl_mac.mac[1], dev->pl_mac.mac[0]}; 797 sdp_uuid128_create(&svc_uuid, &svc_uuid_int);
790 const char *service_dsc = "Bluetooth plugin services"; 798 svc_list = sdp_list_append(0, &svc_uuid);
791 const char *service_prov = "GNUnet provider"; 799 sdp_set_service_classes(record, svc_list);
792 uuid_t root_uuid, rfcomm_uuid, svc_uuid; 800 sdp_set_service_id(record, svc_uuid);
793 sdp_list_t *root_list = 0, *rfcomm_list = 0, *proto_list = 0, 801
794 *access_proto_list = 0, *svc_list = 0; 802 /* Make the service record publicly browsable */
795 sdp_record_t *record = 0; 803 sdp_uuid16_create(&root_uuid, PUBLIC_BROWSE_GROUP);
796 sdp_data_t *channel = 0; 804 root_list = sdp_list_append(0, &root_uuid);
797 805 sdp_set_browse_groups(record, root_list);
798 record = sdp_record_alloc(); 806
799 807 /* Register the RFCOMM channel */
800 /* Set the general service ID */ 808 sdp_uuid16_create(&rfcomm_uuid, RFCOMM_UUID);
801 sdp_uuid128_create (&svc_uuid, &svc_uuid_int); 809 channel = sdp_data_alloc(SDP_UINT8, &rc_channel);
802 svc_list = sdp_list_append (0, &svc_uuid); 810 rfcomm_list = sdp_list_append(0, &rfcomm_uuid);
803 sdp_set_service_classes (record, svc_list); 811 sdp_list_append(rfcomm_list, channel);
804 sdp_set_service_id (record, svc_uuid); 812 proto_list = sdp_list_append(0, rfcomm_list);
805 813
806 /* Make the service record publicly browsable */ 814 /* Set protocol information */
807 sdp_uuid16_create (&root_uuid, PUBLIC_BROWSE_GROUP); 815 access_proto_list = sdp_list_append(0, proto_list);
808 root_list = sdp_list_append (0, &root_uuid); 816 sdp_set_access_protos(record, access_proto_list);
809 sdp_set_browse_groups (record, root_list); 817
810 818 /* Set the name, provider, and description */
811 /* Register the RFCOMM channel */ 819 sdp_set_info_attr(record, dev->iface, service_prov, service_dsc);
812 sdp_uuid16_create (&rfcomm_uuid, RFCOMM_UUID); 820
813 channel = sdp_data_alloc (SDP_UINT8, &rc_channel); 821 /* Connect to the local SDP server */
814 rfcomm_list = sdp_list_append (0, &rfcomm_uuid); 822 dev->session = sdp_connect(BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
815 sdp_list_append (rfcomm_list, channel); 823
816 proto_list = sdp_list_append (0, rfcomm_list); 824 if (!dev->session)
817
818 /* Set protocol information */
819 access_proto_list = sdp_list_append (0, proto_list);
820 sdp_set_access_protos (record, access_proto_list);
821
822 /* Set the name, provider, and description */
823 sdp_set_info_attr (record, dev->iface, service_prov, service_dsc);
824
825 /* Connect to the local SDP server */
826 dev->session = sdp_connect (BDADDR_ANY, BDADDR_LOCAL, SDP_RETRY_IF_BUSY);
827
828 if (!dev->session)
829 { 825 {
830 fprintf (stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", 826 fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n",
831 IFNAMSIZ, dev->iface, strerror (errno)); 827 IFNAMSIZ, dev->iface, strerror(errno));
832 //FIXME exit? 828 //FIXME exit?
833 return 1; 829 return 1;
834 } 830 }
835 831
836 /* Register the service record */ 832 /* Register the service record */
837 if (sdp_record_register (dev->session, record, 0) < 0) 833 if (sdp_record_register(dev->session, record, 0) < 0)
838 { 834 {
839 fprintf (stderr, "Failed to register a service record on interface `%.*s': %s\n", 835 fprintf(stderr, "Failed to register a service record on interface `%.*s': %s\n",
840 IFNAMSIZ, dev->iface, strerror (errno)); 836 IFNAMSIZ, dev->iface, strerror(errno));
841 //FIXME exit? 837 //FIXME exit?
842 return 1; 838 return 1;
843 } 839 }
844 840
845 /* Cleanup */ 841 /* Cleanup */
846 sdp_data_free (channel); 842 sdp_data_free(channel);
847 sdp_list_free (root_list, 0); 843 sdp_list_free(root_list, 0);
848 sdp_list_free (rfcomm_list, 0); 844 sdp_list_free(rfcomm_list, 0);
849 sdp_list_free (proto_list, 0); 845 sdp_list_free(proto_list, 0);
850 sdp_list_free (access_proto_list, 0); 846 sdp_list_free(access_proto_list, 0);
851 sdp_list_free (svc_list, 0); 847 sdp_list_free(svc_list, 0);
852 sdp_record_free (record); 848 sdp_record_free(record);
853 849
854 return 0; 850 return 0;
855 } 851}
856#endif 852#endif
857 853
858#ifdef MINGW 854#ifdef MINGW
859 /** 855/**
860 * Function for searching and browsing for a service. This will return the 856 * Function for searching and browsing for a service. This will return the
861 * port number on which the service is running. 857 * port number on which the service is running.
862 * 858 *
863 * @param dest target address 859 * @param dest target address
864 * @return channel 860 * @return channel
865 */ 861 */
866 static int 862static int
867 get_channel(const char *dest) 863get_channel(const char *dest)
868 { 864{
869 HANDLE h; 865 HANDLE h;
870 WSAQUERYSET *wqs; 866 WSAQUERYSET *wqs;
871 DWORD wqs_len = sizeof (WSAQUERYSET); 867 DWORD wqs_len = sizeof(WSAQUERYSET);
872 int done = 0; 868 int done = 0;
873 int channel = -1; 869 int channel = -1;
874 GUID guid; 870 GUID guid;
875 unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID; 871 unsigned char uuid[] = GNUNET_BLUETOOTH_SDP_UUID;
876 convert_guid ((char *) uuid, &guid); 872
877 873 convert_guid((char *)uuid, &guid);
878 wqs = (WSAQUERYSET*)malloc (wqs_len); 874
879 ZeroMemory (wqs, wqs_len); 875 wqs = (WSAQUERYSET*)malloc(wqs_len);
880 876 ZeroMemory(wqs, wqs_len);
881 wqs->dwSize = sizeof (WSAQUERYSET) ; 877
882 wqs->lpServiceClassId = &guid; 878 wqs->dwSize = sizeof(WSAQUERYSET);
883 wqs->dwNameSpace = NS_BTH; 879 wqs->lpServiceClassId = &guid;
884 wqs->dwNumberOfCsAddrs = 0; 880 wqs->dwNameSpace = NS_BTH;
885 wqs->lpszContext = (LPSTR)dest; 881 wqs->dwNumberOfCsAddrs = 0;
886 882 wqs->lpszContext = (LPSTR)dest;
887 if (SOCKET_ERROR == WSALookupServiceBegin (wqs, LUP_FLUSHCACHE | LUP_RETURN_ALL, &h)) 883
884 if (SOCKET_ERROR == WSALookupServiceBegin(wqs, LUP_FLUSHCACHE | LUP_RETURN_ALL, &h))
888 { 885 {
889 if (GetLastError() == WSASERVICE_NOT_FOUND) 886 if (GetLastError() == WSASERVICE_NOT_FOUND)
890 { 887 {
891 fprintf (stderr, "WARNING! The device with address %s wasn't found. Skipping the message!", dest); 888 fprintf(stderr, "WARNING! The device with address %s wasn't found. Skipping the message!", dest);
892 return -1; 889 return -1;
893 } 890 }
894 else 891 else
895 { 892 {
896 fprintf (stderr, "Failed to find the port number: "); 893 fprintf(stderr, "Failed to find the port number: ");
897 print_last_error(); 894 print_last_error();
898 ExitProcess (2); 895 ExitProcess(2);
899 return -1; 896 return -1;
900 } 897 }
901 } 898 }
902 899
903 /* search the sdp service */ 900 /* search the sdp service */
904 while (!done) 901 while (!done)
905 { 902 {
906 if (SOCKET_ERROR == WSALookupServiceNext (h, LUP_FLUSHCACHE | LUP_RETURN_ALL, &wqs_len, wqs)) 903 if (SOCKET_ERROR == WSALookupServiceNext(h, LUP_FLUSHCACHE | LUP_RETURN_ALL, &wqs_len, wqs))
907 {
908 int error = WSAGetLastError();
909
910 switch (error)
911 { 904 {
912 case WSAEFAULT: 905 int error = WSAGetLastError();
913 free (wqs); 906
914 wqs = (WSAQUERYSET*)malloc (wqs_len); 907 switch (error)
915 break; 908 {
916 case WSANO_DATA: 909 case WSAEFAULT:
917 fprintf (stderr, "Failed! The address was valid but there was no data record of requested type\n"); 910 free(wqs);
918 done = 1; 911 wqs = (WSAQUERYSET*)malloc(wqs_len);
919 break; 912 break;
920 case WSA_E_NO_MORE: 913
921 done = 1; 914 case WSANO_DATA:
922 break; 915 fprintf(stderr, "Failed! The address was valid but there was no data record of requested type\n");
923 default: 916 done = 1;
924 fprintf (stderr, "Failed to look over the services: "); 917 break;
925 print_last_error(); 918
926 WSALookupServiceEnd (h); 919 case WSA_E_NO_MORE:
927 ExitProcess (2); 920 done = 1;
921 break;
922
923 default:
924 fprintf(stderr, "Failed to look over the services: ");
925 print_last_error();
926 WSALookupServiceEnd(h);
927 ExitProcess(2);
928 }
928 } 929 }
929 }
930 else 930 else
931 { 931 {
932 channel = ((SOCKADDR_BTH*)wqs->lpcsaBuffer->RemoteAddr.lpSockaddr)->port; 932 channel = ((SOCKADDR_BTH*)wqs->lpcsaBuffer->RemoteAddr.lpSockaddr)->port;
933 } 933 }
934 } 934 }
935 935
936 free (wqs) ; 936 free(wqs);
937 WSALookupServiceEnd (h); 937 WSALookupServiceEnd(h);
938 938
939 return channel; 939 return channel;
940 } 940}
941#else 941#else
942/**
943 * Function used for searching and browsing for a service. This will return the
944 * port number on which the service is running.
945 *
946 * @param dev pointer to the device struct
947 * @param dest target address
948 * @return channel
949 */
950static int
951get_channel(struct HardwareInfos *dev, bdaddr_t dest)
952{
942 /** 953 /**
943 * Function used for searching and browsing for a service. This will return the 954 * 1. detect all nearby devices
944 * port number on which the service is running. 955 * 2. for each device:
945 * 956 * 2.1. connect to the SDP server running
946 * @param dev pointer to the device struct 957 * 2.2. get a list of service records with the specific UUID
947 * @param dest target address 958 * 2.3. for each service record get a list of the protocol sequences and get
948 * @return channel 959 * the port number
949 */ 960 */
950 static int 961 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
951 get_channel(struct HardwareInfos *dev, bdaddr_t dest)
952 {
953 /**
954 * 1. detect all nearby devices
955 * 2. for each device:
956 * 2.1. connect to the SDP server running
957 * 2.2. get a list of service records with the specific UUID
958 * 2.3. for each service record get a list of the protocol sequences and get
959 * the port number
960 */
961 uint8_t svc_uuid_int[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
962 dest.b[5], dest.b[4], dest.b[3], 962 dest.b[5], dest.b[4], dest.b[3],
963 dest.b[2], dest.b[1], dest.b[0]}; 963 dest.b[2], dest.b[1], dest.b[0] };
964 sdp_session_t *session = 0; 964 sdp_session_t *session = 0;
965 sdp_list_t *search_list = 0, *attrid_list = 0, *response_list = 0, *it = 0; 965 sdp_list_t *search_list = 0, *attrid_list = 0, *response_list = 0, *it = 0;
966 uuid_t svc_uuid; 966 uuid_t svc_uuid;
967 uint32_t range = 0x0000ffff; 967 uint32_t range = 0x0000ffff;
968 int channel = -1; 968 int channel = -1;
969 969
970 /* Connect to the local SDP server */ 970 /* Connect to the local SDP server */
971 session = sdp_connect (BDADDR_ANY, &dest, 0); 971 session = sdp_connect(BDADDR_ANY, &dest, 0);
972 if (!session) 972 if (!session)
973 { 973 {
974 fprintf (stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n", 974 fprintf(stderr, "Failed to connect to the SDP server on interface `%.*s': %s\n",
975 IFNAMSIZ, dev->iface, strerror (errno)); 975 IFNAMSIZ, dev->iface, strerror(errno));
976 return -1; 976 return -1;
977 } 977 }
978 978
979 sdp_uuid128_create (&svc_uuid, &svc_uuid_int); 979 sdp_uuid128_create(&svc_uuid, &svc_uuid_int);
980 search_list = sdp_list_append (0, &svc_uuid); 980 search_list = sdp_list_append(0, &svc_uuid);
981 attrid_list = sdp_list_append (0, &range); 981 attrid_list = sdp_list_append(0, &range);
982 982
983 if (sdp_service_search_attr_req (session, search_list, 983 if (sdp_service_search_attr_req(session, search_list,
984 SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0) 984 SDP_ATTR_REQ_RANGE, attrid_list, &response_list) == 0)
985 { 985 {
986 for (it = response_list; it; it = it->next) 986 for (it = response_list; it; it = it->next)
987 {
988 sdp_record_t *record = (sdp_record_t*) it->data;
989 sdp_list_t *proto_list = 0;
990 if (sdp_get_access_protos (record, &proto_list) == 0)
991 { 987 {
992 channel = sdp_get_proto_port (proto_list, RFCOMM_UUID); 988 sdp_record_t *record = (sdp_record_t*)it->data;
993 sdp_list_free (proto_list, 0); 989 sdp_list_t *proto_list = 0;
990 if (sdp_get_access_protos(record, &proto_list) == 0)
991 {
992 channel = sdp_get_proto_port(proto_list, RFCOMM_UUID);
993 sdp_list_free(proto_list, 0);
994 }
995 sdp_record_free(record);
994 } 996 }
995 sdp_record_free (record);
996 }
997 } 997 }
998 998
999 sdp_list_free (search_list, 0); 999 sdp_list_free(search_list, 0);
1000 sdp_list_free (attrid_list, 0); 1000 sdp_list_free(attrid_list, 0);
1001 sdp_list_free (response_list, 0); 1001 sdp_list_free(response_list, 0);
1002 1002
1003 sdp_close (session); 1003 sdp_close(session);
1004 1004
1005 if (-1 == channel) 1005 if (-1 == channel)
1006 fprintf (stderr, 1006 fprintf(stderr,
1007 "Failed to find the listening channel for interface `%.*s': %s\n", 1007 "Failed to find the listening channel for interface `%.*s': %s\n",
1008 IFNAMSIZ, 1008 IFNAMSIZ,
1009 dev->iface, 1009 dev->iface,
1010 strerror (errno)); 1010 strerror(errno));
1011 1011
1012 return channel; 1012 return channel;
1013 } 1013}
1014#endif 1014#endif
1015 1015
1016/** 1016/**
@@ -1024,56 +1024,56 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
1024 * @return number of bytes written to 'buf' 1024 * @return number of bytes written to 'buf'
1025 */ 1025 */
1026static ssize_t 1026static ssize_t
1027read_from_the_socket (void *sock, 1027read_from_the_socket(void *sock,
1028 unsigned char *buf, size_t buf_size, 1028 unsigned char *buf, size_t buf_size,
1029 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) 1029 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
1030{ 1030{
1031 unsigned char tmpbuf[buf_size]; 1031 unsigned char tmpbuf[buf_size];
1032 ssize_t count; 1032 ssize_t count;
1033 1033
1034 #ifdef MINGW 1034 #ifdef MINGW
1035 count = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)sock, tmpbuf, buf_size); 1035 count = GNUNET_NETWORK_socket_recv((struct GNUNET_NETWORK_Handle *)sock, tmpbuf, buf_size);
1036 #else 1036 #else
1037 count = read (*((int *)sock), tmpbuf, buf_size); 1037 count = read(*((int *)sock), tmpbuf, buf_size);
1038 #endif 1038 #endif
1039 1039
1040 if (0 > count) 1040 if (0 > count)
1041 { 1041 {
1042 if (EAGAIN == errno) 1042 if (EAGAIN == errno)
1043 return 0; 1043 return 0;
1044 #if MINGW 1044 #if MINGW
1045 print_last_error(); 1045 print_last_error();
1046 #else 1046 #else
1047 fprintf (stderr, "Failed to read from the HCI socket: %s\n", strerror (errno)); 1047 fprintf(stderr, "Failed to read from the HCI socket: %s\n", strerror(errno));
1048 #endif 1048 #endif
1049 1049
1050 return -1; 1050 return -1;
1051 } 1051 }
1052 1052
1053 #ifdef LINUX 1053 #ifdef LINUX
1054 /* Get the channel used */ 1054 /* Get the channel used */
1055 int len; 1055 int len;
1056 struct sockaddr_rc rc_addr = { 0 }; 1056 struct sockaddr_rc rc_addr = { 0 };
1057 1057
1058 memset (&rc_addr, 0, sizeof (rc_addr)); 1058 memset(&rc_addr, 0, sizeof(rc_addr));
1059 len = sizeof (rc_addr); 1059 len = sizeof(rc_addr);
1060 if (0 > getsockname (*((int *)sock), (struct sockaddr *) &rc_addr, (socklen_t *) &len)) 1060 if (0 > getsockname(*((int *)sock), (struct sockaddr *)&rc_addr, (socklen_t *)&len))
1061 { 1061 {
1062 fprintf (stderr, "getsockname() call failed : %s\n", strerror (errno)); 1062 fprintf(stderr, "getsockname() call failed : %s\n", strerror(errno));
1063 return -1; 1063 return -1;
1064 } 1064 }
1065 1065
1066 memset (ri, 0, sizeof (*ri)); 1066 memset(ri, 0, sizeof(*ri));
1067 ri->ri_channel = rc_addr.rc_channel; 1067 ri->ri_channel = rc_addr.rc_channel;
1068 #endif 1068 #endif
1069 1069
1070 /* Detect CRC32 at the end */ 1070 /* Detect CRC32 at the end */
1071 if (0 == check_crc_buf_osdep (tmpbuf, count - sizeof (uint32_t))) 1071 if (0 == check_crc_buf_osdep(tmpbuf, count - sizeof(uint32_t)))
1072 { 1072 {
1073 count -= sizeof(uint32_t); 1073 count -= sizeof(uint32_t);
1074 } 1074 }
1075 1075
1076 GNUNET_memcpy (buf, tmpbuf, count); 1076 GNUNET_memcpy(buf, tmpbuf, count);
1077 1077
1078 return count; 1078 return count;
1079} 1079}
@@ -1086,204 +1086,199 @@ read_from_the_socket (void *sock,
1086 * @return 0 on success, non-zero on error 1086 * @return 0 on success, non-zero on error
1087 */ 1087 */
1088static int 1088static int
1089open_device (struct HardwareInfos *dev) 1089open_device(struct HardwareInfos *dev)
1090{ 1090{
1091 #ifdef MINGW 1091 #ifdef MINGW
1092 SOCKADDR_BTH addr; 1092 SOCKADDR_BTH addr;
1093 1093
1094 /* bind the RFCOMM socket to the interface */ 1094 /* bind the RFCOMM socket to the interface */
1095 addr.addressFamily = AF_BTH; 1095 addr.addressFamily = AF_BTH;
1096 addr.btAddr = 0; 1096 addr.btAddr = 0;
1097 addr.port = BT_PORT_ANY; 1097 addr.port = BT_PORT_ANY;
1098 1098
1099 if (GNUNET_OK != 1099 if (GNUNET_OK !=
1100 GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof (SOCKADDR_BTH))) 1100 GNUNET_NETWORK_socket_bind(dev->handle, (const SOCKADDR*)&addr, sizeof(SOCKADDR_BTH)))
1101 { 1101 {
1102 fprintf (stderr, "Failed to bind the socket: "); 1102 fprintf(stderr, "Failed to bind the socket: ");
1103 if (GetLastError() == WSAENETDOWN) 1103 if (GetLastError() == WSAENETDOWN)
1104 { 1104 {
1105 fprintf (stderr, "Please make sure that your Bluetooth device is ON!\n"); 1105 fprintf(stderr, "Please make sure that your Bluetooth device is ON!\n");
1106 ExitProcess (2); 1106 ExitProcess(2);
1107 } 1107 }
1108 print_last_error(); 1108 print_last_error();
1109 return -1; 1109 return -1;
1110 } 1110 }
1111 1111
1112 /* start listening on the socket */ 1112 /* start listening on the socket */
1113 if (GNUNET_NETWORK_socket_listen (dev->handle, 4) != GNUNET_OK) 1113 if (GNUNET_NETWORK_socket_listen(dev->handle, 4) != GNUNET_OK)
1114 { 1114 {
1115 fprintf (stderr, "Failed to listen on the socket: "); 1115 fprintf(stderr, "Failed to listen on the socket: ");
1116 print_last_error(); 1116 print_last_error();
1117 return -1; 1117 return -1;
1118 } 1118 }
1119 1119
1120 /* register the sdp service */ 1120 /* register the sdp service */
1121 if (register_service(dev) != 0) 1121 if (register_service(dev) != 0)
1122 { 1122 {
1123 fprintf (stderr, "Failed to register a service: "); 1123 fprintf(stderr, "Failed to register a service: ");
1124 print_last_error(); 1124 print_last_error();
1125 return 1; 1125 return 1;
1126 } 1126 }
1127 #else 1127 #else
1128 int i, dev_id = -1, fd_hci; 1128 int i, dev_id = -1, fd_hci;
1129 struct 1129 struct {
1130 { 1130 struct hci_dev_list_req list;
1131 struct hci_dev_list_req list; 1131 struct hci_dev_req dev[HCI_MAX_DEV];
1132 struct hci_dev_req dev[HCI_MAX_DEV]; 1132 } request; //used for detecting the local devices
1133 } request; //used for detecting the local devices 1133 struct sockaddr_rc rc_addr = { 0 }; //used for binding
1134 struct sockaddr_rc rc_addr = { 0 }; //used for binding 1134
1135 1135 /* Initialize the neighbour structure */
1136 /* Initialize the neighbour structure */ 1136 neighbours.dev_id = -1;
1137 neighbours.dev_id = -1; 1137 for (i = 0; i < MAX_PORTS; i++)
1138 for (i = 0; i < MAX_PORTS; i++) 1138 neighbours.fds[i] = -1;
1139 neighbours.fds[i] = -1; 1139
1140 1140 /* Open a HCI socket */
1141 /* Open a HCI socket */ 1141 fd_hci = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
1142 fd_hci = socket (AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); 1142
1143 1143 if (fd_hci < 0)
1144 if (fd_hci < 0)
1145 { 1144 {
1146 fprintf (stderr, 1145 fprintf(stderr,
1147 "Failed to create HCI socket: %s\n", 1146 "Failed to create HCI socket: %s\n",
1148 strerror (errno)); 1147 strerror(errno));
1149 return -1; 1148 return -1;
1150 } 1149 }
1151 1150
1152 memset (&request, 0, sizeof(request)); 1151 memset(&request, 0, sizeof(request));
1153 request.list.dev_num = HCI_MAX_DEV; 1152 request.list.dev_num = HCI_MAX_DEV;
1154 1153
1155 if (ioctl (fd_hci, HCIGETDEVLIST, (void *) &request) < 0) 1154 if (ioctl(fd_hci, HCIGETDEVLIST, (void *)&request) < 0)
1156 { 1155 {
1157 fprintf (stderr, 1156 fprintf(stderr,
1158 "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n", 1157 "ioctl(HCIGETDEVLIST) on interface `%.*s' failed: %s\n",
1159 IFNAMSIZ, 1158 IFNAMSIZ,
1160 dev->iface, 1159 dev->iface,
1161 strerror (errno)); 1160 strerror(errno));
1162 (void) close (fd_hci); 1161 (void)close(fd_hci);
1163 return 1; 1162 return 1;
1164 } 1163 }
1165 1164
1166 /* Search for a device with dev->iface name */ 1165 /* Search for a device with dev->iface name */
1167 for (i = 0; i < request.list.dev_num; i++) 1166 for (i = 0; i < request.list.dev_num; i++)
1168 { 1167 {
1169 struct hci_dev_info dev_info; 1168 struct hci_dev_info dev_info;
1170 1169
1171 memset (&dev_info, 0, sizeof(struct hci_dev_info)); 1170 memset(&dev_info, 0, sizeof(struct hci_dev_info));
1172 dev_info.dev_id = request.dev[i].dev_id; 1171 dev_info.dev_id = request.dev[i].dev_id;
1173 strncpy (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE); 1172 strncpy(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE);
1174
1175 if (ioctl (fd_hci, HCIGETDEVINFO, (void *) &dev_info))
1176 {
1177 fprintf (stderr,
1178 "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
1179 IFNAMSIZ,
1180 dev->iface,
1181 strerror (errno));
1182 (void) close (fd_hci);
1183 return 1;
1184 }
1185
1186 if (strncmp (dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0)
1187 {
1188
1189 dev_id = dev_info.dev_id; //the device was found
1190 /**
1191 * Copy the MAC address to the device structure
1192 */
1193 GNUNET_memcpy (&dev->pl_mac, &dev_info.bdaddr, sizeof (bdaddr_t));
1194 1173
1195 /* Check if the interface is up */ 1174 if (ioctl(fd_hci, HCIGETDEVINFO, (void *)&dev_info))
1196 if (hci_test_bit (HCI_UP, (void *) &dev_info.flags) == 0)
1197 { 1175 {
1198 /* Bring the interface up */ 1176 fprintf(stderr,
1199 if (ioctl (fd_hci, HCIDEVUP, dev_info.dev_id)) 1177 "ioctl(HCIGETDEVINFO) on interface `%.*s' failed: %s\n",
1200 { 1178 IFNAMSIZ,
1201 fprintf (stderr, 1179 dev->iface,
1202 "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n", 1180 strerror(errno));
1203 IFNAMSIZ, 1181 (void)close(fd_hci);
1204 dev->iface, 1182 return 1;
1205 strerror (errno));
1206 (void) close (fd_hci);
1207 return 1;
1208 }
1209 } 1183 }
1210 1184
1211 /* Check if the device is discoverable */ 1185 if (strncmp(dev_info.name, dev->iface, BLUEZ_DEVNAME_SIZE) == 0)
1212 if (hci_test_bit (HCI_PSCAN, (void *) &dev_info.flags) == 0 ||
1213 hci_test_bit (HCI_ISCAN, (void *) &dev_info.flags) == 0)
1214 { 1186 {
1215 /* Set interface Page Scan and Inqury Scan ON */ 1187 dev_id = dev_info.dev_id; //the device was found
1216 struct hci_dev_req dev_req; 1188 /**
1189 * Copy the MAC address to the device structure
1190 */
1191 GNUNET_memcpy(&dev->pl_mac, &dev_info.bdaddr, sizeof(bdaddr_t));
1192
1193 /* Check if the interface is up */
1194 if (hci_test_bit(HCI_UP, (void *)&dev_info.flags) == 0)
1195 {
1196 /* Bring the interface up */
1197 if (ioctl(fd_hci, HCIDEVUP, dev_info.dev_id))
1198 {
1199 fprintf(stderr,
1200 "ioctl(HCIDEVUP) on interface `%.*s' failed: %s\n",
1201 IFNAMSIZ,
1202 dev->iface,
1203 strerror(errno));
1204 (void)close(fd_hci);
1205 return 1;
1206 }
1207 }
1217 1208
1218 memset (&dev_req, 0, sizeof (dev_req)); 1209 /* Check if the device is discoverable */
1219 dev_req.dev_id = dev_info.dev_id; 1210 if (hci_test_bit(HCI_PSCAN, (void *)&dev_info.flags) == 0 ||
1220 dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY; 1211 hci_test_bit(HCI_ISCAN, (void *)&dev_info.flags) == 0)
1212 {
1213 /* Set interface Page Scan and Inqury Scan ON */
1214 struct hci_dev_req dev_req;
1221 1215
1222 if (ioctl (fd_hci, HCISETSCAN, (unsigned long) &dev_req)) 1216 memset(&dev_req, 0, sizeof(dev_req));
1223 { 1217 dev_req.dev_id = dev_info.dev_id;
1224 fprintf (stderr, 1218 dev_req.dev_opt = SCAN_PAGE | SCAN_INQUIRY;
1225 "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
1226 IFNAMSIZ,
1227 dev->iface,
1228 strerror (errno));
1229 (void) close (fd_hci);
1230 return 1;
1231 }
1232 1219
1220 if (ioctl(fd_hci, HCISETSCAN, (unsigned long)&dev_req))
1221 {
1222 fprintf(stderr,
1223 "ioctl(HCISETSCAN) on interface `%.*s' failed: %s\n",
1224 IFNAMSIZ,
1225 dev->iface,
1226 strerror(errno));
1227 (void)close(fd_hci);
1228 return 1;
1229 }
1230 }
1231 break;
1233 } 1232 }
1234 break;
1235 }
1236
1237 } 1233 }
1238 1234
1239 /* Check if the interface was not found */ 1235 /* Check if the interface was not found */
1240 if (-1 == dev_id) 1236 if (-1 == dev_id)
1241 { 1237 {
1242 fprintf (stderr, 1238 fprintf(stderr,
1243 "The interface %s was not found\n", 1239 "The interface %s was not found\n",
1244 dev->iface); 1240 dev->iface);
1245 (void) close (fd_hci); 1241 (void)close(fd_hci);
1246 return 1; 1242 return 1;
1247 } 1243 }
1248 1244
1249 /* Close the hci socket */ 1245 /* Close the hci socket */
1250 (void) close(fd_hci); 1246 (void)close(fd_hci);
1251 1247
1252 1248
1253 1249
1254 /* Bind the rfcomm socket to the interface */ 1250 /* Bind the rfcomm socket to the interface */
1255 memset (&rc_addr, 0, sizeof (rc_addr)); 1251 memset(&rc_addr, 0, sizeof(rc_addr));
1256 rc_addr.rc_family = AF_BLUETOOTH; 1252 rc_addr.rc_family = AF_BLUETOOTH;
1257 rc_addr.rc_bdaddr = *BDADDR_ANY; 1253 rc_addr.rc_bdaddr = *BDADDR_ANY;
1258 1254
1259 if (bind_socket (dev->fd_rfcomm, &rc_addr) != 0) 1255 if (bind_socket(dev->fd_rfcomm, &rc_addr) != 0)
1260 { 1256 {
1261 fprintf (stderr, 1257 fprintf(stderr,
1262 "Failed to bind interface `%.*s': %s\n", 1258 "Failed to bind interface `%.*s': %s\n",
1263 IFNAMSIZ, 1259 IFNAMSIZ,
1264 dev->iface, 1260 dev->iface,
1265 strerror (errno)); 1261 strerror(errno));
1266 return 1; 1262 return 1;
1267 } 1263 }
1268 1264
1269 /* Register a SDP service */ 1265 /* Register a SDP service */
1270 if (register_service (dev, rc_addr.rc_channel) != 0) 1266 if (register_service(dev, rc_addr.rc_channel) != 0)
1271 { 1267 {
1272 fprintf (stderr, 1268 fprintf(stderr,
1273 "Failed to register a service on interface `%.*s': %s\n", 1269 "Failed to register a service on interface `%.*s': %s\n",
1274 IFNAMSIZ, 1270 IFNAMSIZ,
1275 dev->iface, strerror (errno)); 1271 dev->iface, strerror(errno));
1276 return 1; 1272 return 1;
1277 } 1273 }
1278 1274
1279 /* Switch socket in listening mode */ 1275 /* Switch socket in listening mode */
1280 if (listen (dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number 1276 if (listen(dev->fd_rfcomm, 5) == -1) //FIXME: probably we need a bigger number
1281 { 1277 {
1282 fprintf (stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ, 1278 fprintf(stderr, "Failed to listen on socket for interface `%.*s': %s\n", IFNAMSIZ,
1283 dev->iface, strerror (errno)); 1279 dev->iface, strerror(errno));
1284 return 1; 1280 return 1;
1285 } 1281 }
1286
1287 #endif 1282 #endif
1288 1283
1289 return 0; 1284 return 0;
@@ -1299,47 +1294,47 @@ open_device (struct HardwareInfos *dev)
1299 **** copy from gnunet-helper-transport-wlan.c **** 1294 **** copy from gnunet-helper-transport-wlan.c ****
1300 */ 1295 */
1301static void 1296static void
1302mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1297mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1303 const struct HardwareInfos *dev) 1298 const struct HardwareInfos *dev)
1304{ 1299{
1305 taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA); 1300 taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
1306 taIeeeHeader->addr3 = mac_bssid_gnunet; 1301 taIeeeHeader->addr3 = mac_bssid_gnunet;
1307 1302
1308 #ifdef MINGW 1303 #ifdef MINGW
1309 GNUNET_memcpy (&taIeeeHeader->addr2, &dev->pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 1304 GNUNET_memcpy(&taIeeeHeader->addr2, &dev->pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
1310 #else 1305 #else
1311 taIeeeHeader->addr2 = dev->pl_mac; 1306 taIeeeHeader->addr2 = dev->pl_mac;
1312 #endif 1307 #endif
1313} 1308}
1314 1309
1315#ifdef LINUX 1310#ifdef LINUX
1316 /** 1311/**
1317 * Test if the given interface name really corresponds to a bluetooth 1312 * Test if the given interface name really corresponds to a bluetooth
1318 * device. 1313 * device.
1319 * 1314 *
1320 * @param iface name of the interface 1315 * @param iface name of the interface
1321 * @return 0 on success, 1 on error 1316 * @return 0 on success, 1 on error
1322 **** similar with the one from gnunet-helper-transport-wlan.c **** 1317 **** similar with the one from gnunet-helper-transport-wlan.c ****
1323 */ 1318 */
1324 static int 1319static int
1325 test_bluetooth_interface (const char *iface) 1320test_bluetooth_interface(const char *iface)
1326 { 1321{
1327 char strbuf[512]; 1322 char strbuf[512];
1328 struct stat sbuf; 1323 struct stat sbuf;
1329 int ret; 1324 int ret;
1330 1325
1331 ret = snprintf (strbuf, sizeof (strbuf), 1326 ret = snprintf(strbuf, sizeof(strbuf),
1332 "/sys/class/bluetooth/%s/subsystem", 1327 "/sys/class/bluetooth/%s/subsystem",
1333 iface); 1328 iface);
1334 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf))) 1329 if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf)))
1335 { 1330 {
1336 fprintf (stderr, 1331 fprintf(stderr,
1337 "Did not find 802.15.1 interface `%s'. Exiting.\n", 1332 "Did not find 802.15.1 interface `%s'. Exiting.\n",
1338 iface); 1333 iface);
1339 exit (1); 1334 exit(1);
1340 } 1335 }
1341 return 0; 1336 return 0;
1342 } 1337}
1343#endif 1338#endif
1344 1339
1345/** 1340/**
@@ -1352,19 +1347,19 @@ mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1352 **** same as the one from gnunet-helper-transport-wlan.c **** 1347 **** same as the one from gnunet-helper-transport-wlan.c ****
1353 */ 1348 */
1354static int 1349static int
1355mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1350mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1356 const struct HardwareInfos *dev) 1351 const struct HardwareInfos *dev)
1357{ 1352{
1358 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros; 1353 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros;
1359 1354
1360 if ( (0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || 1355 if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
1361 (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)) ) 1356 (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
1362 return 0; /* some drivers set no Macs, then assume it is all for us! */ 1357 return 0; /* some drivers set no Macs, then assume it is all for us! */
1363 1358
1364 if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) 1359 if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
1365 return 1; /* not a GNUnet ad-hoc package */ 1360 return 1; /* not a GNUnet ad-hoc package */
1366 if ( (0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || 1361 if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
1367 (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)) ) 1362 (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
1368 return 0; /* for us, or broadcast */ 1363 return 0; /* for us, or broadcast */
1369 return 1; /* not for us */ 1364 return 1; /* not for us */
1370} 1365}
@@ -1380,268 +1375,267 @@ mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1380 **** same as the one from gnunet-helper-transport-wlan.c **** 1375 **** same as the one from gnunet-helper-transport-wlan.c ****
1381 */ 1376 */
1382static void 1377static void
1383stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) 1378stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
1384{ 1379{
1385 struct HardwareInfos *dev = cls; 1380 struct HardwareInfos *dev = cls;
1386 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header; 1381 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
1387 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *blueheader; 1382 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *blueheader;
1388 size_t sendsize; 1383 size_t sendsize;
1389 1384
1390 sendsize = ntohs (hdr->size); 1385 sendsize = ntohs(hdr->size);
1391 if ( (sendsize < 1386 if ((sendsize <
1392 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) || 1387 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
1393 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ) 1388 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)))
1394 { 1389 {
1395 fprintf (stderr, "Received malformed message\n"); 1390 fprintf(stderr, "Received malformed message\n");
1396 exit (1); 1391 exit(1);
1397 } 1392 }
1398 sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - 1393 sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) -
1399 sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); 1394 sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1400 if (MAXLINE < sendsize) 1395 if (MAXLINE < sendsize)
1401 { 1396 {
1402 fprintf (stderr, "Packet too big for buffer\n"); 1397 fprintf(stderr, "Packet too big for buffer\n");
1403 exit (1); 1398 exit(1);
1404 } 1399 }
1405 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; 1400 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
1406 GNUNET_memcpy (&write_pout.buf, &header->frame, sendsize); 1401 GNUNET_memcpy(&write_pout.buf, &header->frame, sendsize);
1407 blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf; 1402 blueheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf;
1408 1403
1409 /* payload contains MAC address, but we don't trust it, so we'll 1404 /* payload contains MAC address, but we don't trust it, so we'll
1410 * overwrite it with OUR MAC address to prevent mischief */ 1405 * overwrite it with OUR MAC address to prevent mischief */
1411 mac_set (blueheader, dev); 1406 mac_set(blueheader, dev);
1412 GNUNET_memcpy (&blueheader->addr1, &header->frame.addr1, 1407 GNUNET_memcpy(&blueheader->addr1, &header->frame.addr1,
1413 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 1408 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
1414 write_pout.size = sendsize; 1409 write_pout.size = sendsize;
1415} 1410}
1416 1411
1417#ifdef LINUX 1412#ifdef LINUX
1418 /** 1413/**
1419 * Broadcast a HELLO message for peer discovery 1414 * Broadcast a HELLO message for peer discovery
1420 * 1415 *
1421 * @param dev pointer to the device struct 1416 * @param dev pointer to the device struct
1422 * @param dev pointer to the socket which was added to the set 1417 * @param dev pointer to the socket which was added to the set
1423 * @return 0 on success 1418 * @return 0 on success
1424 */ 1419 */
1425 static int 1420static int
1426 send_broadcast (struct HardwareInfos *dev, int *sendsocket) 1421send_broadcast(struct HardwareInfos *dev, int *sendsocket)
1427 { 1422{
1428 int new_device = 0; 1423 int new_device = 0;
1429 int loops = 0; 1424 int loops = 0;
1430 1425
1431 search_for_devices: 1426search_for_devices:
1432 if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0) 1427 if ((neighbours.size == neighbours.pos && new_device == 1) || neighbours.size == 0)
1433 { 1428 {
1434 inquiry_devices: //skip the conditions and force a inquiry for new devices 1429inquiry_devices: //skip the conditions and force a inquiry for new devices
1435 {
1436 /**
1437 * It means that I sent HELLO messages to all the devices from the list and I should search
1438 * for new ones or that this is the first time when I do a search.
1439 */
1440 inquiry_info *devices = NULL;
1441 int i, responses, max_responses = MAX_PORTS;
1442
1443 /* sanity checks */
1444 if (neighbours.size >= MAX_PORTS)
1445 {
1446 fprintf (stderr, "%.*s reached the top limit for the discovarable devices\n", IFNAMSIZ, dev->iface);
1447 return 2;
1448 }
1449
1450 /* Get the device id */
1451 if (neighbours.dev_id == -1)
1452 { 1430 {
1453 char addr[19] = { 0 }; //the device MAC address 1431 /**
1454 1432 * It means that I sent HELLO messages to all the devices from the list and I should search
1455 ba2str ((bdaddr_t *) &dev->pl_mac, addr); 1433 * for new ones or that this is the first time when I do a search.
1456 neighbours.dev_id = hci_devid (addr); 1434 */
1457 if (neighbours.dev_id < 0) 1435 inquiry_info *devices = NULL;
1458 { 1436 int i, responses, max_responses = MAX_PORTS;
1459 fprintf (stderr, "Failed to get the device id for interface %.*s : %s\n", IFNAMSIZ,
1460 dev->iface, strerror (errno));
1461 return 1;
1462 }
1463 }
1464 1437
1465 devices = malloc (max_responses * sizeof (inquiry_info)); 1438 /* sanity checks */
1466 if (devices == NULL) 1439 if (neighbours.size >= MAX_PORTS)
1467 { 1440 {
1468 fprintf (stderr, "Failed to allocate memory for inquiry info list on interface %.*s\n", IFNAMSIZ, 1441 fprintf(stderr, "%.*s reached the top limit for the discovarable devices\n", IFNAMSIZ, dev->iface);
1469 dev->iface); 1442 return 2;
1470 return 1; 1443 }
1471 }
1472 1444
1473 responses = hci_inquiry (neighbours.dev_id, 8, max_responses, NULL, &devices, IREQ_CACHE_FLUSH); 1445 /* Get the device id */
1474 if (responses < 0) 1446 if (neighbours.dev_id == -1)
1475 { 1447 {
1476 fprintf (stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, dev->iface); 1448 char addr[19] = { 0 }; //the device MAC address
1477 return 1;
1478 }
1479 1449
1480 fprintf (stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage 1450 ba2str((bdaddr_t *)&dev->pl_mac, addr);
1451 neighbours.dev_id = hci_devid(addr);
1452 if (neighbours.dev_id < 0)
1453 {
1454 fprintf(stderr, "Failed to get the device id for interface %.*s : %s\n", IFNAMSIZ,
1455 dev->iface, strerror(errno));
1456 return 1;
1457 }
1458 }
1481 1459
1482 if (responses == 0) 1460 devices = malloc(max_responses * sizeof(inquiry_info));
1483 { 1461 if (devices == NULL)
1484 fprintf (stderr, "LOG : No devices discoverable\n"); 1462 {
1485 return 1; 1463 fprintf(stderr, "Failed to allocate memory for inquiry info list on interface %.*s\n", IFNAMSIZ,
1486 } 1464 dev->iface);
1465 return 1;
1466 }
1487 1467
1488 for (i = 0; i < responses; i++) 1468 responses = hci_inquiry(neighbours.dev_id, 8, max_responses, NULL, &devices, IREQ_CACHE_FLUSH);
1489 { 1469 if (responses < 0)
1490 int j; 1470 {
1491 int found = 0; 1471 fprintf(stderr, "Failed to inquiry on interface %.*s\n", IFNAMSIZ, dev->iface);
1472 return 1;
1473 }
1492 1474
1493 /* sanity check */ 1475 fprintf(stderr, "LOG : Found %d devices\n", responses); //FIXME delete it after debugging stage
1494 if (i >= MAX_PORTS)
1495 {
1496 fprintf (stderr, "%.*s reached the top limit for the discoverable devices (after inquiry)\n", IFNAMSIZ,
1497 dev->iface);
1498 return 2;
1499 }
1500 1476
1501 /* Search if the address already exists on the list */ 1477 if (responses == 0)
1502 for (j = 0; j < neighbours.size; j++)
1503 {
1504 if (memcmp (&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof (bdaddr_t)) == 0)
1505 { 1478 {
1506 found = 1; 1479 fprintf(stderr, "LOG : No devices discoverable\n");
1507 fprintf (stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message 1480 return 1;
1508 break;
1509 } 1481 }
1510 }
1511 1482
1512 if (found == 0) 1483 for (i = 0; i < responses; i++)
1513 { 1484 {
1514 char addr[19] = { 0 }; 1485 int j;
1486 int found = 0;
1515 1487
1516 ba2str (&(devices +i)->bdaddr, addr); 1488 /* sanity check */
1517 fprintf (stderr, "LOG : %s was added to the list\n", addr); //FIXME debugging message 1489 if (i >= MAX_PORTS)
1518 GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), &(devices + i)->bdaddr, sizeof (bdaddr_t)); 1490 {
1519 } 1491 fprintf(stderr, "%.*s reached the top limit for the discoverable devices (after inquiry)\n", IFNAMSIZ,
1520 } 1492 dev->iface);
1493 return 2;
1494 }
1521 1495
1522 free (devices); 1496 /* Search if the address already exists on the list */
1497 for (j = 0; j < neighbours.size; j++)
1498 {
1499 if (memcmp(&(devices + i)->bdaddr, &(neighbours.devices[j]), sizeof(bdaddr_t)) == 0)
1500 {
1501 found = 1;
1502 fprintf(stderr, "LOG : the device already exists on the list\n"); //FIXME debugging message
1503 break;
1504 }
1505 }
1506
1507 if (found == 0)
1508 {
1509 char addr[19] = { 0 };
1510
1511 ba2str(&(devices + i)->bdaddr, addr);
1512 fprintf(stderr, "LOG : %s was added to the list\n", addr); //FIXME debugging message
1513 GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &(devices + i)->bdaddr, sizeof(bdaddr_t));
1514 }
1515 }
1516
1517 free(devices);
1523 } 1518 }
1524 } 1519 }
1525 1520
1526 int connection_successful = 0; 1521 int connection_successful = 0;
1527 struct sockaddr_rc addr_rc = { 0 }; 1522 struct sockaddr_rc addr_rc = { 0 };
1528 int errno_copy = 0; 1523 int errno_copy = 0;
1529 addr_rc.rc_family = AF_BLUETOOTH; 1524 addr_rc.rc_family = AF_BLUETOOTH;
1530 1525
1531 /* Try to connect to a new device from the list */ 1526 /* Try to connect to a new device from the list */
1532 while (neighbours.pos < neighbours.size) 1527 while (neighbours.pos < neighbours.size)
1533 { 1528 {
1534 /* Check if we are already connected to this device */ 1529 /* Check if we are already connected to this device */
1535 if (neighbours.fds[neighbours.pos] == -1) 1530 if (neighbours.fds[neighbours.pos] == -1)
1536 { 1531 {
1537 1532 memset(&addr_rc.rc_bdaddr, 0, sizeof(addr_rc.rc_bdaddr));
1538 memset (&addr_rc.rc_bdaddr, 0, sizeof (addr_rc.rc_bdaddr)); 1533 GNUNET_memcpy(&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), sizeof(addr_rc.rc_bdaddr));
1539 GNUNET_memcpy (&addr_rc.rc_bdaddr, &(neighbours.devices[neighbours.pos]), sizeof (addr_rc.rc_bdaddr));
1540 1534
1541 addr_rc.rc_channel = get_channel (dev, addr_rc.rc_bdaddr); 1535 addr_rc.rc_channel = get_channel(dev, addr_rc.rc_bdaddr);
1542 1536
1543 *sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 1537 *sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1544 if ( (-1 < *sendsocket) && 1538 if ((-1 < *sendsocket) &&
1545 (0 == connect (*sendsocket, 1539 (0 == connect(*sendsocket,
1546 (struct sockaddr *) &addr_rc, 1540 (struct sockaddr *)&addr_rc,
1547 sizeof (addr_rc))) ) 1541 sizeof(addr_rc))))
1548 { 1542 {
1549 neighbours.fds[neighbours.pos++] = *sendsocket; 1543 neighbours.fds[neighbours.pos++] = *sendsocket;
1550 connection_successful = 1; 1544 connection_successful = 1;
1551 char addr[19] = { 0 }; 1545 char addr[19] = { 0 };
1552 ba2str (&(neighbours.devices[neighbours.pos - 1]), addr); 1546 ba2str(&(neighbours.devices[neighbours.pos - 1]), addr);
1553 fprintf (stderr, "LOG : Connected to %s\n", addr); 1547 fprintf(stderr, "LOG : Connected to %s\n", addr);
1554 break; 1548 break;
1555 } 1549 }
1556 else 1550 else
1557 { 1551 {
1558 char addr[19] = { 0 }; 1552 char addr[19] = { 0 };
1559 errno_copy = errno; //Save a copy for later 1553 errno_copy = errno; //Save a copy for later
1560 1554
1561 if (-1 != *sendsocket) 1555 if (-1 != *sendsocket)
1562 { 1556 {
1563 (void) close (*sendsocket); 1557 (void)close(*sendsocket);
1564 *sendsocket = -1; 1558 *sendsocket = -1;
1565 } 1559 }
1566 ba2str (&(neighbours.devices[neighbours.pos]), addr); 1560 ba2str(&(neighbours.devices[neighbours.pos]), addr);
1567 fprintf (stderr, 1561 fprintf(stderr,
1568 "LOG : Couldn't connect on device %s, error : %s\n", 1562 "LOG : Couldn't connect on device %s, error : %s\n",
1569 addr, 1563 addr,
1570 strerror (errno)); 1564 strerror(errno));
1571 if (errno != ECONNREFUSED) //FIXME be sure that this works 1565 if (errno != ECONNREFUSED) //FIXME be sure that this works
1572 { 1566 {
1573 fprintf (stderr, "LOG : Removes %d device from the list\n", neighbours.pos); 1567 fprintf(stderr, "LOG : Removes %d device from the list\n", neighbours.pos);
1574 /* Remove the device from the list */ 1568 /* Remove the device from the list */
1575 GNUNET_memcpy (&neighbours.devices[neighbours.pos], &neighbours.devices[neighbours.size - 1], sizeof (bdaddr_t)); 1569 GNUNET_memcpy(&neighbours.devices[neighbours.pos], &neighbours.devices[neighbours.size - 1], sizeof(bdaddr_t));
1576 memset (&neighbours.devices[neighbours.size - 1], 0, sizeof (bdaddr_t)); 1570 memset(&neighbours.devices[neighbours.size - 1], 0, sizeof(bdaddr_t));
1577 neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1]; 1571 neighbours.fds[neighbours.pos] = neighbours.fds[neighbours.size - 1];
1578 neighbours.fds[neighbours.size - 1] = -1; 1572 neighbours.fds[neighbours.size - 1] = -1;
1579 neighbours.size -= 1; 1573 neighbours.size -= 1;
1580 } 1574 }
1581 1575
1582 neighbours.pos += 1; 1576 neighbours.pos += 1;
1583 1577
1584 if (neighbours.pos >= neighbours.size) 1578 if (neighbours.pos >= neighbours.size)
1585 neighbours.pos = 0; 1579 neighbours.pos = 0;
1586 1580
1587 loops += 1; 1581 loops += 1;
1588 1582
1589 if (loops == MAX_LOOPS) //don't get stuck trying to connect to one device 1583 if (loops == MAX_LOOPS) //don't get stuck trying to connect to one device
1590 return 1; 1584 return 1;
1585 }
1591 } 1586 }
1592 }
1593 else 1587 else
1594 { 1588 {
1595 fprintf (stderr, "LOG : Search for a new device\n"); //FIXME debugging message 1589 fprintf(stderr, "LOG : Search for a new device\n"); //FIXME debugging message
1596 neighbours.pos += 1; 1590 neighbours.pos += 1;
1597 } 1591 }
1598 } 1592 }
1599 1593
1600 /* Cycle on the list */ 1594 /* Cycle on the list */
1601 if (neighbours.pos == neighbours.size) 1595 if (neighbours.pos == neighbours.size)
1602 { 1596 {
1603 neighbours.pos = 0; 1597 neighbours.pos = 0;
1604 searching_devices_count += 1; 1598 searching_devices_count += 1;
1605 1599
1606 if (searching_devices_count == MAX_LOOPS) 1600 if (searching_devices_count == MAX_LOOPS)
1607 { 1601 {
1608 fprintf (stderr, "LOG : Force to inquiry for new devices\n"); 1602 fprintf(stderr, "LOG : Force to inquiry for new devices\n");
1609 searching_devices_count = 0; 1603 searching_devices_count = 0;
1610 goto inquiry_devices; 1604 goto inquiry_devices;
1611 } 1605 }
1612 } 1606 }
1613 /* If a new device wasn't found, search an old one */ 1607 /* If a new device wasn't found, search an old one */
1614 if (connection_successful == 0) 1608 if (connection_successful == 0)
1615 { 1609 {
1616 int loop_check = neighbours.pos; 1610 int loop_check = neighbours.pos;
1617 while (neighbours.fds[neighbours.pos] == -1) 1611 while (neighbours.fds[neighbours.pos] == -1)
1618 {
1619 if (neighbours.pos == neighbours.size)
1620 neighbours.pos = 0;
1621
1622 if (neighbours.pos == loop_check)
1623 { 1612 {
1624 if (errno_copy == ECONNREFUSED) 1613 if (neighbours.pos == neighbours.size)
1625 { 1614 neighbours.pos = 0;
1626 fprintf (stderr, "LOG : No device found. Go back and search again\n"); //FIXME debugging message
1627 new_device = 1;
1628 loops += 1;
1629 goto search_for_devices;
1630 }
1631 else
1632 {
1633 return 1; // Skip the broadcast message
1634 }
1635 }
1636 1615
1637 neighbours.pos += 1; 1616 if (neighbours.pos == loop_check)
1638 } 1617 {
1618 if (errno_copy == ECONNREFUSED)
1619 {
1620 fprintf(stderr, "LOG : No device found. Go back and search again\n"); //FIXME debugging message
1621 new_device = 1;
1622 loops += 1;
1623 goto search_for_devices;
1624 }
1625 else
1626 {
1627 return 1; // Skip the broadcast message
1628 }
1629 }
1630
1631 neighbours.pos += 1;
1632 }
1639 1633
1640 *sendsocket = neighbours.fds[neighbours.pos++]; 1634 *sendsocket = neighbours.fds[neighbours.pos++];
1641 } 1635 }
1642 1636
1643 return 0; 1637 return 0;
1644 } 1638}
1645#endif 1639#endif
1646 1640
1647/** 1641/**
@@ -1656,559 +1650,556 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1656 **** similar to gnunet-helper-transport-wlan.c **** 1650 **** similar to gnunet-helper-transport-wlan.c ****
1657 */ 1651 */
1658int 1652int
1659main (int argc, char *argv[]) 1653main(int argc, char *argv[])
1660{ 1654{
1661#ifdef LINUX 1655#ifdef LINUX
1662 struct HardwareInfos dev; 1656 struct HardwareInfos dev;
1663 char readbuf[MAXLINE]; 1657 char readbuf[MAXLINE];
1664 int maxfd; 1658 int maxfd;
1665 fd_set rfds; 1659 fd_set rfds;
1666 fd_set wfds; 1660 fd_set wfds;
1667 int stdin_open; 1661 int stdin_open;
1668 struct MessageStreamTokenizer *stdin_mst; 1662 struct MessageStreamTokenizer *stdin_mst;
1669 int raw_eno, i; 1663 int raw_eno, i;
1670 int crt_rfds = 0, rfds_list[MAX_PORTS]; 1664 int crt_rfds = 0, rfds_list[MAX_PORTS];
1671 int broadcast, sendsocket; 1665 int broadcast, sendsocket;
1672 1666
1673 /* Assert privs so we can modify the firewall rules! */ 1667 /* Assert privs so we can modify the firewall rules! */
1674 { 1668 {
1675#ifdef HAVE_SETRESUID 1669#ifdef HAVE_SETRESUID
1676 uid_t uid = getuid (); 1670 uid_t uid = getuid();
1677 1671
1678 if (0 != setresuid (uid, 0, 0)) 1672 if (0 != setresuid(uid, 0, 0))
1679 { 1673 {
1680 fprintf (stderr, 1674 fprintf(stderr,
1681 "Failed to setresuid to root: %s\n", 1675 "Failed to setresuid to root: %s\n",
1682 strerror (errno)); 1676 strerror(errno));
1683 return 254; 1677 return 254;
1684 } 1678 }
1685#else 1679#else
1686 if (0 != seteuid (0)) 1680 if (0 != seteuid(0))
1687 { 1681 {
1688 fprintf (stderr, 1682 fprintf(stderr,
1689 "Failed to seteuid back to root: %s\n", strerror (errno)); 1683 "Failed to seteuid back to root: %s\n", strerror(errno));
1690 return 254; 1684 return 254;
1691 } 1685 }
1692#endif 1686#endif
1693 } 1687 }
1694 1688
1695 /* Make use of SGID capabilities on POSIX */ 1689 /* Make use of SGID capabilities on POSIX */
1696 memset (&dev, 0, sizeof (dev)); 1690 memset(&dev, 0, sizeof(dev));
1697 dev.fd_rfcomm = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); 1691 dev.fd_rfcomm = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1698 raw_eno = errno; /* remember for later */ 1692 raw_eno = errno; /* remember for later */
1699 1693
1700 /* Now that we've dropped root rights, we can do error checking */ 1694 /* Now that we've dropped root rights, we can do error checking */
1701 if (2 != argc) 1695 if (2 != argc)
1702 { 1696 {
1703 fprintf (stderr, "You must specify the name of the interface as the first \ 1697 fprintf(stderr, "You must specify the name of the interface as the first \
1704 and only argument to this program.\n"); 1698 and only argument to this program.\n");
1705 if (-1 != dev.fd_rfcomm) 1699 if (-1 != dev.fd_rfcomm)
1706 (void) close (dev.fd_rfcomm); 1700 (void)close(dev.fd_rfcomm);
1707 return 1; 1701 return 1;
1708 } 1702 }
1709 1703
1710 if (-1 == dev.fd_rfcomm) 1704 if (-1 == dev.fd_rfcomm)
1711 { 1705 {
1712 fprintf (stderr, "Failed to create a RFCOMM socket: %s\n", strerror (raw_eno)); 1706 fprintf(stderr, "Failed to create a RFCOMM socket: %s\n", strerror(raw_eno));
1713 return 1; 1707 return 1;
1714 } 1708 }
1715 if (dev.fd_rfcomm >= FD_SETSIZE) 1709 if (dev.fd_rfcomm >= FD_SETSIZE)
1716 { 1710 {
1717 fprintf (stderr, "File descriptor too large for select (%d > %d)\n", 1711 fprintf(stderr, "File descriptor too large for select (%d > %d)\n",
1718 dev.fd_rfcomm, FD_SETSIZE); 1712 dev.fd_rfcomm, FD_SETSIZE);
1719 (void) close (dev.fd_rfcomm); 1713 (void)close(dev.fd_rfcomm);
1720 return 1; 1714 return 1;
1721 } 1715 }
1722 if (0 != test_bluetooth_interface (argv[1])) 1716 if (0 != test_bluetooth_interface(argv[1]))
1723 { 1717 {
1724 (void) close (dev.fd_rfcomm); 1718 (void)close(dev.fd_rfcomm);
1725 return 1; 1719 return 1;
1726 } 1720 }
1727 strncpy (dev.iface, argv[1], IFNAMSIZ); 1721 strncpy(dev.iface, argv[1], IFNAMSIZ);
1728 if (0 != open_device (&dev)) 1722 if (0 != open_device(&dev))
1729 { 1723 {
1730 (void) close (dev.fd_rfcomm); 1724 (void)close(dev.fd_rfcomm);
1731 return 1; 1725 return 1;
1732 } 1726 }
1733 1727
1734 /* Drop privs */ 1728 /* Drop privs */
1735 { 1729 {
1736 uid_t uid = getuid (); 1730 uid_t uid = getuid();
1737 #ifdef HAVE_SETRESUID 1731 #ifdef HAVE_SETRESUID
1738 if (0 != setresuid (uid, uid, uid)) 1732 if (0 != setresuid(uid, uid, uid))
1739 { 1733 {
1740 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); 1734 fprintf(stderr, "Failed to setresuid: %s\n", strerror(errno));
1741 if (-1 != dev.fd_rfcomm) 1735 if (-1 != dev.fd_rfcomm)
1742 (void) close (dev.fd_rfcomm); 1736 (void)close(dev.fd_rfcomm);
1743 return 1; 1737 return 1;
1744 } 1738 }
1745 #else 1739 #else
1746 if (0 != (setuid (uid) | seteuid (uid))) 1740 if (0 != (setuid(uid) | seteuid(uid)))
1747 { 1741 {
1748 fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); 1742 fprintf(stderr, "Failed to setuid: %s\n", strerror(errno));
1749 if (-1 != dev.fd_rfcomm) 1743 if (-1 != dev.fd_rfcomm)
1750 (void) close (dev.fd_rfcomm); 1744 (void)close(dev.fd_rfcomm);
1751 return 1; 1745 return 1;
1752 } 1746 }
1753 #endif 1747 #endif
1754 } 1748 }
1755 1749
1756 /* Send MAC address of the bluetooth interface to STDOUT first */ 1750 /* Send MAC address of the bluetooth interface to STDOUT first */
1757 { 1751 {
1758 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 1752 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
1759 1753
1760 macmsg.hdr.size = htons (sizeof (macmsg)); 1754 macmsg.hdr.size = htons(sizeof(macmsg));
1761 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 1755 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
1762 GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 1756 GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
1763 GNUNET_memcpy (write_std.buf, &macmsg, sizeof (macmsg)); 1757 GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg));
1764 write_std.size = sizeof (macmsg); 1758 write_std.size = sizeof(macmsg);
1765 } 1759 }
1766 1760
1767 1761
1768 stdin_mst = mst_create (&stdin_send_hw, &dev); 1762 stdin_mst = mst_create(&stdin_send_hw, &dev);
1769 stdin_open = 1; 1763 stdin_open = 1;
1770 1764
1771 /** 1765 /**
1772 * TODO : I should make the time out of a mac endpoint smaller and check if the rate 1766 * TODO : I should make the time out of a mac endpoint smaller and check if the rate
1773 * from get_wlan_header (plugin_transport_bluetooth.c) is correct. 1767 * from get_wlan_header (plugin_transport_bluetooth.c) is correct.
1774 */ 1768 */
1775 while (1) 1769 while (1)
1776 { 1770 {
1777 maxfd = -1; 1771 maxfd = -1;
1778 broadcast = 0; 1772 broadcast = 0;
1779 sendsocket = -1; 1773 sendsocket = -1;
1780 1774
1781 FD_ZERO (&rfds); 1775 FD_ZERO(&rfds);
1782 if ((0 == write_pout.size) && (1 == stdin_open)) 1776 if ((0 == write_pout.size) && (1 == stdin_open))
1783 { 1777 {
1784 FD_SET (STDIN_FILENO, &rfds); 1778 FD_SET(STDIN_FILENO, &rfds);
1785 maxfd = MAX (maxfd, STDIN_FILENO); 1779 maxfd = MAX(maxfd, STDIN_FILENO);
1786 } 1780 }
1787 if (0 == write_std.size) 1781 if (0 == write_std.size)
1788 { 1782 {
1789 FD_SET (dev.fd_rfcomm, &rfds); 1783 FD_SET(dev.fd_rfcomm, &rfds);
1790 maxfd = MAX (maxfd, dev.fd_rfcomm); 1784 maxfd = MAX(maxfd, dev.fd_rfcomm);
1791 } 1785 }
1792 1786
1793 for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices 1787 for (i = 0; i < crt_rfds; i++) // it can receive messages from multiple devices
1794 {
1795 FD_SET (rfds_list[i], &rfds);
1796 maxfd = MAX (maxfd, rfds_list[i]);
1797 }
1798 FD_ZERO (&wfds);
1799 if (0 < write_std.size)
1800 {
1801 FD_SET (STDOUT_FILENO, &wfds);
1802 maxfd = MAX (maxfd, STDOUT_FILENO);
1803 }
1804 if (0 < write_pout.size) //it can send messages only to one device per loop
1805 {
1806 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
1807 /* Get the destination address */
1808 frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) write_pout.buf;
1809
1810 if (memcmp (&frame->addr1, &dev.pl_mac,
1811 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
1812 { 1788 {
1813 broadcast = 1; 1789 FD_SET(rfds_list[i], &rfds);
1814 memset (&write_pout, 0, sizeof (write_pout)); //clear the buffer 1790 maxfd = MAX(maxfd, rfds_list[i]);
1815 } 1791 }
1816 else if (memcmp (&frame->addr1, &broadcast_address, 1792 FD_ZERO(&wfds);
1817 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0) 1793 if (0 < write_std.size)
1818 { 1794 {
1819 fprintf (stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", dev.iface, neighbours.pos, neighbours.size); //FIXME: debugging message 1795 FD_SET(STDOUT_FILENO, &wfds);
1820 1796 maxfd = MAX(maxfd, STDOUT_FILENO);
1821 if (send_broadcast(&dev, &sendsocket) != 0) //if the searching wasn't successful don't get stuck on the select stage
1822 {
1823 broadcast = 1;
1824 memset (&write_pout, 0, sizeof (write_pout)); //remove the message
1825 fprintf (stderr, "LOG : Skipping the broadcast message (pos %d, size %d)\n", neighbours.pos, neighbours.size);
1826 }
1827 else
1828 {
1829 FD_SET (sendsocket, &wfds);
1830 maxfd = MAX (maxfd, sendsocket);
1831 }
1832 } 1797 }
1833 else 1798 if (0 < write_pout.size) //it can send messages only to one device per loop
1834 { 1799 {
1835 int found = 0; 1800 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *frame;
1836 int pos = 0; 1801 /* Get the destination address */
1837 /* Search if the address already exists on the list */ 1802 frame = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)write_pout.buf;
1838 for (i = 0; i < neighbours.size; i++)
1839 {
1840 if (memcmp (&frame->addr1, &(neighbours.devices[i]), sizeof (bdaddr_t)) == 0)
1841 {
1842 pos = i;
1843 if (neighbours.fds[i] != -1)
1844 {
1845 found = 1; //save the position where it was found
1846 FD_SET (neighbours.fds[i], &wfds);
1847 maxfd = MAX (maxfd, neighbours.fds[i]);
1848 sendsocket = neighbours.fds[i];
1849 fprintf (stderr, "LOG: the address was found in the list\n");
1850 break;
1851 }
1852 }
1853 }
1854 if (found == 0)
1855 {
1856 int status;
1857 struct sockaddr_rc addr = { 0 };
1858 1803
1859 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, 1804 if (memcmp(&frame->addr1, &dev.pl_mac,
1860 frame->addr1.mac[5], frame->addr1.mac[4], frame->addr1.mac[3], 1805 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
1861 frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message
1862
1863 sendsocket = socket (AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1864
1865 if (sendsocket < 0)
1866 { 1806 {
1867 fprintf (stderr, "Failed to create a RFCOMM socket (sending stage): %s\n", 1807 broadcast = 1;
1868 strerror (errno)); 1808 memset(&write_pout, 0, sizeof(write_pout)); //clear the buffer
1869 return -1;
1870 } 1809 }
1871 1810 else if (memcmp(&frame->addr1, &broadcast_address,
1872 GNUNET_memcpy (&addr.rc_bdaddr, &frame->addr1, sizeof (bdaddr_t)); 1811 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)) == 0)
1873 addr.rc_family = AF_BLUETOOTH;
1874 addr.rc_channel = get_channel (&dev, addr.rc_bdaddr);
1875
1876 int tries = 0;
1877 connect_retry:
1878 status = connect (sendsocket, (struct sockaddr *) &addr, sizeof (addr));
1879 if (0 != status && errno != EAGAIN)
1880 { 1812 {
1881 if (errno == ECONNREFUSED && tries < 2) 1813 fprintf(stderr, "LOG : %s has a broadcast message (pos %d, size %d)\n", dev.iface, neighbours.pos, neighbours.size); //FIXME: debugging message
1882 {
1883 fprintf (stderr, "LOG : %.*s failed to connect. Trying again!\n", IFNAMSIZ, dev.iface);
1884 tries++;
1885 goto connect_retry;
1886 }
1887 else if (errno == EBADF)
1888 {
1889 fprintf (stderr, "LOG : %s failed to connect : %s. Skip it!\n", dev.iface, strerror (errno));
1890 memset (&write_pout, 0, sizeof (write_pout));
1891 broadcast = 1;
1892 }
1893 else
1894 {
1895 fprintf (stderr, "LOG : %s failed to connect : %s. Try again later!\n", dev.iface, strerror (errno));
1896 memset (&write_pout, 0, sizeof (write_pout));
1897 broadcast = 1;
1898 }
1899 1814
1815 if (send_broadcast(&dev, &sendsocket) != 0) //if the searching wasn't successful don't get stuck on the select stage
1816 {
1817 broadcast = 1;
1818 memset(&write_pout, 0, sizeof(write_pout)); //remove the message
1819 fprintf(stderr, "LOG : Skipping the broadcast message (pos %d, size %d)\n", neighbours.pos, neighbours.size);
1820 }
1821 else
1822 {
1823 FD_SET(sendsocket, &wfds);
1824 maxfd = MAX(maxfd, sendsocket);
1825 }
1900 } 1826 }
1901 else 1827 else
1902 { 1828 {
1903 FD_SET (sendsocket, &wfds); 1829 int found = 0;
1904 maxfd = MAX (maxfd, sendsocket); 1830 int pos = 0;
1905 fprintf (stderr, "LOG : Connection successful\n"); 1831 /* Search if the address already exists on the list */
1906 if (pos != 0) // save the socket 1832 for (i = 0; i < neighbours.size; i++)
1907 {
1908 neighbours.fds[pos] = sendsocket;
1909 }
1910 else
1911 {
1912 /* Add the new device to the discovered devices list */
1913 if (neighbours.size < MAX_PORTS)
1914 { 1833 {
1915 neighbours.fds[neighbours.size] = sendsocket; 1834 if (memcmp(&frame->addr1, &(neighbours.devices[i]), sizeof(bdaddr_t)) == 0)
1916 GNUNET_memcpy (&(neighbours.devices[neighbours.size++]), &addr.rc_bdaddr, sizeof (bdaddr_t)); 1835 {
1836 pos = i;
1837 if (neighbours.fds[i] != -1)
1838 {
1839 found = 1; //save the position where it was found
1840 FD_SET(neighbours.fds[i], &wfds);
1841 maxfd = MAX(maxfd, neighbours.fds[i]);
1842 sendsocket = neighbours.fds[i];
1843 fprintf(stderr, "LOG: the address was found in the list\n");
1844 break;
1845 }
1846 }
1917 } 1847 }
1918 else 1848 if (found == 0)
1919 { 1849 {
1920 fprintf (stderr, "The top limit for the discovarable devices' list was reached\n"); 1850 int status;
1851 struct sockaddr_rc addr = { 0 };
1852
1853 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,
1854 frame->addr1.mac[5], frame->addr1.mac[4], frame->addr1.mac[3],
1855 frame->addr1.mac[2], frame->addr1.mac[1], frame->addr1.mac[0]); //FIXME: debugging message
1856
1857 sendsocket = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM);
1858
1859 if (sendsocket < 0)
1860 {
1861 fprintf(stderr, "Failed to create a RFCOMM socket (sending stage): %s\n",
1862 strerror(errno));
1863 return -1;
1864 }
1865
1866 GNUNET_memcpy(&addr.rc_bdaddr, &frame->addr1, sizeof(bdaddr_t));
1867 addr.rc_family = AF_BLUETOOTH;
1868 addr.rc_channel = get_channel(&dev, addr.rc_bdaddr);
1869
1870 int tries = 0;
1871connect_retry:
1872 status = connect(sendsocket, (struct sockaddr *)&addr, sizeof(addr));
1873 if (0 != status && errno != EAGAIN)
1874 {
1875 if (errno == ECONNREFUSED && tries < 2)
1876 {
1877 fprintf(stderr, "LOG : %.*s failed to connect. Trying again!\n", IFNAMSIZ, dev.iface);
1878 tries++;
1879 goto connect_retry;
1880 }
1881 else if (errno == EBADF)
1882 {
1883 fprintf(stderr, "LOG : %s failed to connect : %s. Skip it!\n", dev.iface, strerror(errno));
1884 memset(&write_pout, 0, sizeof(write_pout));
1885 broadcast = 1;
1886 }
1887 else
1888 {
1889 fprintf(stderr, "LOG : %s failed to connect : %s. Try again later!\n", dev.iface, strerror(errno));
1890 memset(&write_pout, 0, sizeof(write_pout));
1891 broadcast = 1;
1892 }
1893 }
1894 else
1895 {
1896 FD_SET(sendsocket, &wfds);
1897 maxfd = MAX(maxfd, sendsocket);
1898 fprintf(stderr, "LOG : Connection successful\n");
1899 if (pos != 0) // save the socket
1900 {
1901 neighbours.fds[pos] = sendsocket;
1902 }
1903 else
1904 {
1905 /* Add the new device to the discovered devices list */
1906 if (neighbours.size < MAX_PORTS)
1907 {
1908 neighbours.fds[neighbours.size] = sendsocket;
1909 GNUNET_memcpy(&(neighbours.devices[neighbours.size++]), &addr.rc_bdaddr, sizeof(bdaddr_t));
1910 }
1911 else
1912 {
1913 fprintf(stderr, "The top limit for the discovarable devices' list was reached\n");
1914 }
1915 }
1916 }
1921 } 1917 }
1922 }
1923 } 1918 }
1924 }
1925 } 1919 }
1926 }
1927 1920
1928 if (broadcast == 0) 1921 if (broadcast == 0)
1929 {
1930 /* Select a fd which is ready for action :) */
1931 {
1932 int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
1933 if ((-1 == retval) && (EINTR == errno))
1934 continue;
1935 if (0 > retval && errno != EBADF) // we handle BADF errors later
1936 {
1937 fprintf (stderr, "select failed: %s\n", strerror (errno));
1938 break;
1939 }
1940 }
1941 if (FD_ISSET (STDOUT_FILENO , &wfds))
1942 {
1943 ssize_t ret =
1944 write (STDOUT_FILENO, write_std.buf + write_std.pos,
1945 write_std.size - write_std.pos);
1946 if (0 > ret)
1947 {
1948 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
1949 break;
1950 }
1951 write_std.pos += ret;
1952 if (write_std.pos == write_std.size)
1953 {
1954 write_std.pos = 0;
1955 write_std.size = 0;
1956 }
1957 fprintf (stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); //FIXME: debugging message
1958
1959 }
1960 if (-1 != sendsocket)
1961 { 1922 {
1962 if (FD_ISSET (sendsocket , &wfds)) 1923 /* Select a fd which is ready for action :) */
1963 { 1924 {
1964 ssize_t ret = write (sendsocket, 1925 int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL);
1965 write_pout.buf + write_std.pos, 1926 if ((-1 == retval) && (EINTR == errno))
1966 write_pout.size - write_pout.pos); 1927 continue;
1967 if (0 > ret) //FIXME should I first check the error type? 1928 if (0 > retval && errno != EBADF) // we handle BADF errors later
1968 {
1969 fprintf (stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n",
1970 strerror (errno));
1971 for (i = 0; i < neighbours.size; i++)
1972 {
1973 if (neighbours.fds[i] == sendsocket)
1974 {
1975 (void) close(sendsocket);
1976 neighbours.fds[i] = -1;
1977 break;
1978 }
1979 }
1980 /* Remove the message */
1981 memset (&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos));
1982 write_pout.pos = 0 ;
1983 write_pout.size = 0;
1984 }
1985 else
1986 {
1987 write_pout.pos += ret;
1988 if ((write_pout.pos != write_pout.size) && (0 != ret))
1989 { 1929 {
1990 /* We should not get partial sends with packet-oriented devices... */ 1930 fprintf(stderr, "select failed: %s\n", strerror(errno));
1991 fprintf (stderr, "Write error, partial send: %u/%u\n",
1992 (unsigned int) write_pout.pos,
1993 (unsigned int) write_pout.size);
1994 break; 1931 break;
1995 } 1932 }
1996
1997 if (write_pout.pos == write_pout.size)
1998 {
1999 write_pout.pos = 0;
2000 write_pout.size = 0;
2001 }
2002 fprintf (stderr, "LOG : %s sends a message to a DEVICE\n", dev.iface); //FIXME: debugging message
2003 }
2004 } 1933 }
2005 } 1934 if (FD_ISSET(STDOUT_FILENO, &wfds))
2006 for (i = 0; i <= maxfd; i++)
2007 {
2008 if (FD_ISSET (i, &rfds))
2009 {
2010 if (i == STDIN_FILENO)
2011 { 1935 {
2012 ssize_t ret = 1936 ssize_t ret =
2013 read (i, readbuf, sizeof (readbuf)); 1937 write(STDOUT_FILENO, write_std.buf + write_std.pos,
1938 write_std.size - write_std.pos);
2014 if (0 > ret) 1939 if (0 > ret)
2015 { 1940 {
2016 fprintf (stderr, 1941 fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno));
2017 "Read error from STDIN: %s\n", 1942 break;
2018 strerror (errno)); 1943 }
2019 break; 1944 write_std.pos += ret;
2020 } 1945 if (write_std.pos == write_std.size)
2021 if (0 == ret) 1946 {
2022 { 1947 write_std.pos = 0;
2023 /* stop reading... */ 1948 write_std.size = 0;
2024 stdin_open = 0; 1949 }
2025 } 1950 fprintf(stderr, "LOG : %s sends a message to STDOUT\n", dev.iface); //FIXME: debugging message
2026 else
2027 {
2028 mst_receive (stdin_mst, readbuf, ret);
2029 fprintf (stderr, "LOG : %s receives a message from STDIN\n", dev.iface); //FIXME: debugging message
2030 }
2031 } 1951 }
2032 else if (i == dev.fd_rfcomm) 1952 if (-1 != sendsocket)
2033 { 1953 {
2034 int readsocket; 1954 if (FD_ISSET(sendsocket, &wfds))
2035 struct sockaddr_rc addr = { 0 };
2036 unsigned int opt = sizeof (addr);
2037
2038 readsocket = accept (dev.fd_rfcomm, (struct sockaddr *) &addr, &opt);
2039 fprintf(stderr, "LOG : %s accepts a message\n", dev.iface); //FIXME: debugging message
2040 if (readsocket == -1)
2041 {
2042 fprintf (stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ,
2043 strerror (errno));
2044 break;
2045 }
2046 else
2047 {
2048 FD_SET (readsocket, &rfds);
2049 maxfd = MAX (maxfd, readsocket);
2050
2051 if (crt_rfds < MAX_PORTS)
2052 rfds_list[crt_rfds++] = readsocket;
2053 else
2054 { 1955 {
2055 fprintf (stderr, "The limit for the read file descriptors list was \ 1956 ssize_t ret = write(sendsocket,
2056 reached\n"); 1957 write_pout.buf + write_std.pos,
2057 break; 1958 write_pout.size - write_pout.pos);
1959 if (0 > ret) //FIXME should I first check the error type?
1960 {
1961 fprintf(stderr, "Failed to write to bluetooth device: %s. Closing the socket!\n",
1962 strerror(errno));
1963 for (i = 0; i < neighbours.size; i++)
1964 {
1965 if (neighbours.fds[i] == sendsocket)
1966 {
1967 (void)close(sendsocket);
1968 neighbours.fds[i] = -1;
1969 break;
1970 }
1971 }
1972 /* Remove the message */
1973 memset(&write_pout.buf + write_std.pos, 0, (write_pout.size - write_pout.pos));
1974 write_pout.pos = 0;
1975 write_pout.size = 0;
1976 }
1977 else
1978 {
1979 write_pout.pos += ret;
1980 if ((write_pout.pos != write_pout.size) && (0 != ret))
1981 {
1982 /* We should not get partial sends with packet-oriented devices... */
1983 fprintf(stderr, "Write error, partial send: %u/%u\n",
1984 (unsigned int)write_pout.pos,
1985 (unsigned int)write_pout.size);
1986 break;
1987 }
1988
1989 if (write_pout.pos == write_pout.size)
1990 {
1991 write_pout.pos = 0;
1992 write_pout.size = 0;
1993 }
1994 fprintf(stderr, "LOG : %s sends a message to a DEVICE\n", dev.iface); //FIXME: debugging message
1995 }
2058 } 1996 }
2059 }
2060
2061 } 1997 }
2062 else 1998 for (i = 0; i <= maxfd; i++)
2063 { 1999 {
2064 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm; 2000 if (FD_ISSET(i, &rfds))
2065 ssize_t ret;
2066 fprintf (stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message
2067 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
2068 ret =
2069 read_from_the_socket ((void *)&i, (unsigned char *) &rrm->frame,
2070 sizeof (write_std.buf)
2071 - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2072 + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2073 rrm);
2074 if (0 >= ret)
2075 {
2076 int j;
2077 FD_CLR (i, &rfds);
2078 close (i);
2079 /* Remove the socket from the list */
2080 for (j = 0; j < crt_rfds; j++)
2081 { 2001 {
2082 if (rfds_list[j] == i) 2002 if (i == STDIN_FILENO)
2083 { 2003 {
2084 rfds_list[j] ^= rfds_list[crt_rfds - 1]; 2004 ssize_t ret =
2085 rfds_list[crt_rfds - 1] ^= rfds_list[j]; 2005 read(i, readbuf, sizeof(readbuf));
2086 rfds_list[j] ^= rfds_list[crt_rfds - 1]; 2006 if (0 > ret)
2087 crt_rfds -= 1; 2007 {
2088 break; 2008 fprintf(stderr,
2089 } 2009 "Read error from STDIN: %s\n",
2010 strerror(errno));
2011 break;
2012 }
2013 if (0 == ret)
2014 {
2015 /* stop reading... */
2016 stdin_open = 0;
2017 }
2018 else
2019 {
2020 mst_receive(stdin_mst, readbuf, ret);
2021 fprintf(stderr, "LOG : %s receives a message from STDIN\n", dev.iface); //FIXME: debugging message
2022 }
2023 }
2024 else if (i == dev.fd_rfcomm)
2025 {
2026 int readsocket;
2027 struct sockaddr_rc addr = { 0 };
2028 unsigned int opt = sizeof(addr);
2029
2030 readsocket = accept(dev.fd_rfcomm, (struct sockaddr *)&addr, &opt);
2031 fprintf(stderr, "LOG : %s accepts a message\n", dev.iface); //FIXME: debugging message
2032 if (readsocket == -1)
2033 {
2034 fprintf(stderr, "Failed to accept a connection on interface: %.*s\n", IFNAMSIZ,
2035 strerror(errno));
2036 break;
2037 }
2038 else
2039 {
2040 FD_SET(readsocket, &rfds);
2041 maxfd = MAX(maxfd, readsocket);
2042
2043 if (crt_rfds < MAX_PORTS)
2044 rfds_list[crt_rfds++] = readsocket;
2045 else
2046 {
2047 fprintf(stderr, "The limit for the read file descriptors list was \
2048 reached\n");
2049 break;
2050 }
2051 }
2052 }
2053 else
2054 {
2055 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2056 ssize_t ret;
2057 fprintf(stderr, "LOG : %s reads something from the socket\n", dev.iface);//FIXME : debugging message
2058 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
2059 ret =
2060 read_from_the_socket((void *)&i, (unsigned char *)&rrm->frame,
2061 sizeof(write_std.buf)
2062 - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2063 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2064 rrm);
2065 if (0 >= ret)
2066 {
2067 int j;
2068 FD_CLR(i, &rfds);
2069 close(i);
2070 /* Remove the socket from the list */
2071 for (j = 0; j < crt_rfds; j++)
2072 {
2073 if (rfds_list[j] == i)
2074 {
2075 rfds_list[j] ^= rfds_list[crt_rfds - 1];
2076 rfds_list[crt_rfds - 1] ^= rfds_list[j];
2077 rfds_list[j] ^= rfds_list[crt_rfds - 1];
2078 crt_rfds -= 1;
2079 break;
2080 }
2081 }
2082
2083 fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno));
2084 break;
2085 }
2086 if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
2087 {
2088 write_std.size = ret
2089 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2090 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2091 rrm->header.size = htons(write_std.size);
2092 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2093 }
2094 }
2090 } 2095 }
2091
2092 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
2093 break;
2094 }
2095 if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
2096 {
2097 write_std.size = ret
2098 + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2099 - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2100 rrm->header.size = htons (write_std.size);
2101 rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2102 }
2103 } 2096 }
2104 }
2105 } 2097 }
2106 }
2107 } 2098 }
2108 /* Error handling, try to clean up a bit at least */ 2099 /* Error handling, try to clean up a bit at least */
2109 mst_destroy (stdin_mst); 2100 mst_destroy(stdin_mst);
2110 stdin_mst = NULL; 2101 stdin_mst = NULL;
2111 sdp_close (dev.session); 2102 sdp_close(dev.session);
2112 (void) close (dev.fd_rfcomm); 2103 (void)close(dev.fd_rfcomm);
2113 if (-1 != sendsocket) 2104 if (-1 != sendsocket)
2114 (void) close (sendsocket); 2105 (void)close(sendsocket);
2115 2106
2116 for (i = 0; i < crt_rfds; i++) 2107 for (i = 0; i < crt_rfds; i++)
2117 (void) close (rfds_list[i]); 2108 (void)close(rfds_list[i]);
2118 2109
2119 for (i = 0; i < neighbours.size; i++) 2110 for (i = 0; i < neighbours.size; i++)
2120 (void) close (neighbours.fds[i]); 2111 (void)close(neighbours.fds[i]);
2121 #else 2112 #else
2122 struct HardwareInfos dev; 2113 struct HardwareInfos dev;
2123 struct GNUNET_NETWORK_Handle *sendsocket; 2114 struct GNUNET_NETWORK_Handle *sendsocket;
2124 struct GNUNET_NETWORK_FDSet *rfds; 2115 struct GNUNET_NETWORK_FDSet *rfds;
2125 struct GNUNET_NETWORK_FDSet *wfds; 2116 struct GNUNET_NETWORK_FDSet *wfds;
2126 struct GNUNET_NETWORK_Handle *rfds_list[MAX_PORTS]; 2117 struct GNUNET_NETWORK_Handle *rfds_list[MAX_PORTS];
2127 char readbuf[MAXLINE] = { 0 }; 2118 char readbuf[MAXLINE] = { 0 };
2128 SOCKADDR_BTH acc_addr = { 0 }; 2119 SOCKADDR_BTH acc_addr = { 0 };
2129 int addr_len = sizeof (SOCKADDR_BTH); 2120 int addr_len = sizeof(SOCKADDR_BTH);
2130 int broadcast, i, stdin_open, crt_rfds = 0; 2121 int broadcast, i, stdin_open, crt_rfds = 0;
2131 HANDLE stdin_handle = GetStdHandle (STD_INPUT_HANDLE); 2122 HANDLE stdin_handle = GetStdHandle(STD_INPUT_HANDLE);
2132 HANDLE stdout_handle = GetStdHandle (STD_OUTPUT_HANDLE); 2123 HANDLE stdout_handle = GetStdHandle(STD_OUTPUT_HANDLE);
2133 struct MessageStreamTokenizer *stdin_mst; 2124 struct MessageStreamTokenizer *stdin_mst;
2134 2125
2135 /* check the handles */ 2126 /* check the handles */
2136 if (stdin_handle == INVALID_HANDLE_VALUE) 2127 if (stdin_handle == INVALID_HANDLE_VALUE)
2137 { 2128 {
2138 fprintf (stderr, "Failed to get the stdin handle\n"); 2129 fprintf(stderr, "Failed to get the stdin handle\n");
2139 ExitProcess (2); 2130 ExitProcess(2);
2140 } 2131 }
2141 2132
2142 if (stdout_handle == INVALID_HANDLE_VALUE) 2133 if (stdout_handle == INVALID_HANDLE_VALUE)
2143 { 2134 {
2144 fprintf (stderr, "Failed to get the stdout handle\n"); 2135 fprintf(stderr, "Failed to get the stdout handle\n");
2145 ExitProcess (2); 2136 ExitProcess(2);
2146 } 2137 }
2147 2138
2148 /* initialize windows sockets */ 2139 /* initialize windows sockets */
2149 initialize_windows_sockets(); 2140 initialize_windows_sockets();
2150 2141
2151 // /* test bluetooth socket family support */ --> it return false because the GNUNET_NETWORK_test_pf should also receive the type of socket (BTHPROTO_RFCOMM) 2142 // /* test bluetooth socket family support */ --> it return false because the GNUNET_NETWORK_test_pf should also receive the type of socket (BTHPROTO_RFCOMM)
2152 // if (GNUNET_NETWORK_test_pf (AF_BTH) != GNUNET_OK) 2143 // if (GNUNET_NETWORK_test_pf (AF_BTH) != GNUNET_OK)
2153 // { 2144 // {
2154 // fprintf (stderr, "AF_BTH family is not supported\n"); 2145 // fprintf (stderr, "AF_BTH family is not supported\n");
2155 // ExitProcess (2); 2146 // ExitProcess (2);
2156 // } 2147 // }
2157 2148
2158 /* create the socket */ 2149 /* create the socket */
2159 dev.handle = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM); 2150 dev.handle = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
2160 if (dev.handle == NULL) 2151 if (dev.handle == NULL)
2161 { 2152 {
2162 fprintf (stderr, "Failed to create RFCOMM socket: "); 2153 fprintf(stderr, "Failed to create RFCOMM socket: ");
2163 print_last_error(); 2154 print_last_error();
2164 ExitProcess (2); 2155 ExitProcess(2);
2165 } 2156 }
2166 2157
2167 2158
2168 if (open_device (&dev) == -1) 2159 if (open_device(&dev) == -1)
2169 { 2160 {
2170 fprintf (stderr, "Failed to open the device\n"); 2161 fprintf(stderr, "Failed to open the device\n");
2171 print_last_error(); 2162 print_last_error();
2172 if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK) 2163 if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
2173 { 2164 {
2174 fprintf (stderr, "Failed to close the socket!\n"); 2165 fprintf(stderr, "Failed to close the socket!\n");
2175 print_last_error(); 2166 print_last_error();
2176 } 2167 }
2177 ExitProcess (2); 2168 ExitProcess(2);
2178 } 2169 }
2179 2170
2180 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (dev.handle, 1) ) 2171 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(dev.handle, 1))
2181 { 2172 {
2182 fprintf (stderr, "Failed to change the socket mode\n"); 2173 fprintf(stderr, "Failed to change the socket mode\n");
2183 ExitProcess (2); 2174 ExitProcess(2);
2184 } 2175 }
2185 2176
2186 memset (&write_std, 0, sizeof (write_std)); 2177 memset(&write_std, 0, sizeof(write_std));
2187 memset (&write_pout, 0, sizeof (write_pout)); 2178 memset(&write_pout, 0, sizeof(write_pout));
2188 stdin_open = 1; 2179 stdin_open = 1;
2189 2180
2190 rfds = GNUNET_NETWORK_fdset_create (); 2181 rfds = GNUNET_NETWORK_fdset_create();
2191 wfds = GNUNET_NETWORK_fdset_create (); 2182 wfds = GNUNET_NETWORK_fdset_create();
2192 2183
2193 /* Send MAC address of the bluetooth interface to STDOUT first */ 2184 /* Send MAC address of the bluetooth interface to STDOUT first */
2194 { 2185 {
2195 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 2186 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
2196 2187
2197 macmsg.hdr.size = htons (sizeof (macmsg)); 2188 macmsg.hdr.size = htons(sizeof(macmsg));
2198 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 2189 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
2199 GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy)); 2190 GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress_Copy));
2200 GNUNET_memcpy (write_std.buf, &macmsg, sizeof (macmsg)); 2191 GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg));
2201 write_std.size = sizeof (macmsg); 2192 write_std.size = sizeof(macmsg);
2202 } 2193 }
2203 2194
2204 2195
2205 stdin_mst = mst_create (&stdin_send_hw, &dev); 2196 stdin_mst = mst_create(&stdin_send_hw, &dev);
2206 stdin_open = 1; 2197 stdin_open = 1;
2207 2198
2208 int pos = 0; 2199 int pos = 0;
2209 int stdin_pos = -1; 2200 int stdin_pos = -1;
2210 int stdout_pos = -1; 2201 int stdout_pos = -1;
2211 while (1) 2202 while (1)
2212 { 2203 {
2213 broadcast = 0; 2204 broadcast = 0;
2214 pos = 0; 2205 pos = 0;
@@ -2216,287 +2207,287 @@ main (int argc, char *argv[])
2216 stdout_pos = -1; 2207 stdout_pos = -1;
2217 sendsocket = NULL; //FIXME ???memleaks 2208 sendsocket = NULL; //FIXME ???memleaks
2218 2209
2219 GNUNET_NETWORK_fdset_zero (rfds); 2210 GNUNET_NETWORK_fdset_zero(rfds);
2220 if ((0 == write_pout.size) && (1 == stdin_open)) 2211 if ((0 == write_pout.size) && (1 == stdin_open))
2221 { 2212 {
2222 stdin_pos = pos; 2213 stdin_pos = pos;
2223 pos +=1; 2214 pos += 1;
2224 GNUNET_NETWORK_fdset_handle_set (rfds, (struct GNUNET_DISK_FileHandle*) &stdin_handle); 2215 GNUNET_NETWORK_fdset_handle_set(rfds, (struct GNUNET_DISK_FileHandle*)&stdin_handle);
2225 } 2216 }
2226 2217
2227 if (0 == write_std.size) 2218 if (0 == write_std.size)
2228 { 2219 {
2229 pos += 1; 2220 pos += 1;
2230 GNUNET_NETWORK_fdset_set (rfds, dev.handle); 2221 GNUNET_NETWORK_fdset_set(rfds, dev.handle);
2231 } 2222 }
2232 2223
2233 for (i = 0; i < crt_rfds; i++) 2224 for (i = 0; i < crt_rfds; i++)
2234 { 2225 {
2235 pos += 1; 2226 pos += 1;
2236 GNUNET_NETWORK_fdset_set (rfds, rfds_list[i]); 2227 GNUNET_NETWORK_fdset_set(rfds, rfds_list[i]);
2237 } 2228 }
2238 2229
2239 GNUNET_NETWORK_fdset_zero (wfds); 2230 GNUNET_NETWORK_fdset_zero(wfds);
2240 if (0 < write_std.size) 2231 if (0 < write_std.size)
2241 { 2232 {
2242 stdout_pos = pos; 2233 stdout_pos = pos;
2243 GNUNET_NETWORK_fdset_handle_set (wfds, (struct GNUNET_DISK_FileHandle*) &stdout_handle); 2234 GNUNET_NETWORK_fdset_handle_set(wfds, (struct GNUNET_DISK_FileHandle*)&stdout_handle);
2244 // printf ("%s\n", write_std.buf); 2235 // printf ("%s\n", write_std.buf);
2245 // memset (write_std.buf, 0, write_std.size); 2236 // memset (write_std.buf, 0, write_std.size);
2246 // write_std.size = 0; 2237 // write_std.size = 0;
2247 } 2238 }
2248 2239
2249 if (0 < write_pout.size) 2240 if (0 < write_pout.size)
2250 {
2251 if (strcmp (argv[1], "ff:ff:ff:ff:ff:ff") == 0) {
2252 fprintf(stderr, "LOG: BROADCAST! Skipping the message\n");
2253 // skip the message
2254 broadcast = 1;
2255 memset (write_pout.buf, 0, write_pout.size);
2256 write_pout.size = 0;
2257 }
2258 else
2259 { 2241 {
2260 SOCKADDR_BTH addr; 2242 if (strcmp(argv[1], "ff:ff:ff:ff:ff:ff") == 0)
2261 fprintf (stderr, "LOG : has a new message for %s\n", argv[1]);
2262 sendsocket = GNUNET_NETWORK_socket_create (AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
2263
2264 if (sendsocket == NULL)
2265 {
2266 fprintf (stderr, "Failed to create RFCOMM socket: \n");
2267 print_last_error();
2268 ExitProcess (2);
2269 }
2270
2271 memset (&addr, 0, sizeof (addr));
2272 //addr.addressFamily = AF_BTH;
2273 if (SOCKET_ERROR ==
2274 WSAStringToAddress (argv[1], AF_BTH, NULL, (LPSOCKADDR) &addr, &addr_len))
2275 {
2276 fprintf (stderr, "Failed to translate the address: ");
2277 print_last_error();
2278 ExitProcess ( 2 ) ;
2279 }
2280 addr.port = get_channel (argv[1]);
2281 if (addr.port == -1)
2282 {
2283 fprintf (stderr, "Couldn't find the sdp service for the address: %s\n", argv[1]);
2284 memset (write_pout.buf, 0, write_pout.size);
2285 write_pout.size = 0;
2286 broadcast = 1; //skipping the select part
2287 }
2288 else
2289 {
2290 if (GNUNET_OK != GNUNET_NETWORK_socket_connect (sendsocket, (LPSOCKADDR)&addr, addr_len))
2291 { 2243 {
2292 fprintf (stderr, "Failed to connect: "); 2244 fprintf(stderr, "LOG: BROADCAST! Skipping the message\n");
2293 print_last_error(); 2245 // skip the message
2294 ExitProcess (2); 2246 broadcast = 1;
2247 memset(write_pout.buf, 0, write_pout.size);
2248 write_pout.size = 0;
2295 } 2249 }
2296 2250 else
2297 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (sendsocket, 1) )
2298 { 2251 {
2299 fprintf (stderr, "Failed to change the socket mode\n"); 2252 SOCKADDR_BTH addr;
2300 ExitProcess (2); 2253 fprintf(stderr, "LOG : has a new message for %s\n", argv[1]);
2301 } 2254 sendsocket = GNUNET_NETWORK_socket_create(AF_BTH, SOCK_STREAM, BTHPROTO_RFCOMM);
2302 2255
2303 GNUNET_NETWORK_fdset_set (wfds, sendsocket); 2256 if (sendsocket == NULL)
2304 } 2257 {
2305 } 2258 fprintf(stderr, "Failed to create RFCOMM socket: \n");
2306 } 2259 print_last_error();
2260 ExitProcess(2);
2261 }
2307 2262
2308 if (broadcast == 0) 2263 memset(&addr, 0, sizeof(addr));
2309 { 2264 //addr.addressFamily = AF_BTH;
2310 int retval = GNUNET_NETWORK_socket_select (rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_()); 2265 if (SOCKET_ERROR ==
2311 if (retval < 0) 2266 WSAStringToAddress(argv[1], AF_BTH, NULL, (LPSOCKADDR)&addr, &addr_len))
2312 { 2267 {
2313 fprintf (stderr, "Select error\n"); 2268 fprintf(stderr, "Failed to translate the address: ");
2314 ExitProcess (2); 2269 print_last_error();
2270 ExitProcess(2);
2271 }
2272 addr.port = get_channel(argv[1]);
2273 if (addr.port == -1)
2274 {
2275 fprintf(stderr, "Couldn't find the sdp service for the address: %s\n", argv[1]);
2276 memset(write_pout.buf, 0, write_pout.size);
2277 write_pout.size = 0;
2278 broadcast = 1; //skipping the select part
2279 }
2280 else
2281 {
2282 if (GNUNET_OK != GNUNET_NETWORK_socket_connect(sendsocket, (LPSOCKADDR)&addr, addr_len))
2283 {
2284 fprintf(stderr, "Failed to connect: ");
2285 print_last_error();
2286 ExitProcess(2);
2287 }
2288
2289 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(sendsocket, 1))
2290 {
2291 fprintf(stderr, "Failed to change the socket mode\n");
2292 ExitProcess(2);
2293 }
2294
2295 GNUNET_NETWORK_fdset_set(wfds, sendsocket);
2296 }
2297 }
2315 } 2298 }
2316 //if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle))
2317 if (retval == stdout_pos)
2318 {
2319 fprintf(stderr, "LOG : sends a message to STDOUT\n"); //FIXME: debugging message
2320 //ssize_t ret;
2321 //ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos);
2322 //ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos);
2323 DWORD ret;
2324 if (FALSE == WriteFile (stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos, &ret, NULL))
2325 {
2326 fprintf (stderr, "Failed to write to STDOUT: ");
2327 print_last_error();
2328 break;
2329 }
2330
2331 if (ret <= 0)
2332 {
2333 fprintf (stderr, "Failed to write to STDOUT\n");
2334 ExitProcess (2);
2335 }
2336 2299
2337 write_std.pos += ret; 2300 if (broadcast == 0)
2338 if (write_std.pos == write_std.size)
2339 {
2340 write_std.pos = 0;
2341 write_std.size = 0;
2342 }
2343 }
2344 if (sendsocket != NULL)
2345 { 2301 {
2346 if (GNUNET_NETWORK_fdset_isset (wfds, sendsocket)) 2302 int retval = GNUNET_NETWORK_socket_select(rfds, wfds, NULL, GNUNET_TIME_relative_get_forever_());
2347 { 2303 if (retval < 0)
2348 ssize_t ret;
2349 ret = GNUNET_NETWORK_socket_send (sendsocket, write_pout.buf + write_pout.pos,
2350 write_pout.size - write_pout.pos);
2351
2352 if (GNUNET_SYSERR == ret)
2353 { 2304 {
2354 fprintf (stderr, "Failed to send to the socket. Closing the socket. Error: \n"); 2305 fprintf(stderr, "Select error\n");
2355 print_last_error(); 2306 ExitProcess(2);
2356 if (GNUNET_NETWORK_socket_close (sendsocket) != GNUNET_OK)
2357 {
2358 fprintf (stderr, "Failed to close the sendsocket!\n");
2359 print_last_error();
2360 }
2361 ExitProcess (2);
2362 } 2307 }
2363 else 2308 //if (GNUNET_NETWORK_fdset_isset (wfds, (struct GNUNET_NETWORK_Handle*)&stdout_handle))
2309 if (retval == stdout_pos)
2364 { 2310 {
2365 write_pout.pos += ret; 2311 fprintf(stderr, "LOG : sends a message to STDOUT\n"); //FIXME: debugging message
2366 if ((write_pout.pos != write_pout.size) && (0 != ret)) 2312 //ssize_t ret;
2367 { 2313 //ret = GNUNET_NETWORK_socket_send ((struct GNUNET_NETWORK_Handle *)&stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos);
2368 /* we should not get partial sends with packet-oriented devices... */ 2314 //ret = write (STDOUT_FILENO, write_std.buf + write_std.pos, write_std.size - write_std.pos);
2369 fprintf (stderr, "Write error, partial send: %u/%u\n", 2315 DWORD ret;
2370 (unsigned int) write_pout.pos, 2316 if (FALSE == WriteFile(stdout_handle, write_std.buf + write_std.pos, write_std.size - write_std.pos, &ret, NULL))
2371 (unsigned int) write_pout.size); 2317 {
2372 break; 2318 fprintf(stderr, "Failed to write to STDOUT: ");
2373 } 2319 print_last_error();
2320 break;
2321 }
2374 2322
2375 if (write_pout.pos == write_pout.size) 2323 if (ret <= 0)
2376 { 2324 {
2377 write_pout.pos = 0; 2325 fprintf(stderr, "Failed to write to STDOUT\n");
2378 write_pout.size = 0; 2326 ExitProcess(2);
2327 }
2379 2328
2380 } 2329 write_std.pos += ret;
2381 fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message 2330 if (write_std.pos == write_std.size)
2331 {
2332 write_std.pos = 0;
2333 write_std.size = 0;
2334 }
2382 } 2335 }
2383 } 2336 if (sendsocket != NULL)
2384 }
2385
2386 //if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
2387 if (retval == stdin_pos)
2388 {
2389 //ssize_t ret;
2390 //ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
2391 //ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
2392 DWORD ret;
2393 if (FALSE == ReadFile (stdin_handle, readbuf, sizeof (readbuf), &ret, NULL)) /* do nothing asynchronous */
2394 {
2395 fprintf (stderr, "Read error from STDIN: ");
2396 print_last_error();
2397 break;
2398 }
2399 if (0 == ret)
2400 {
2401 /* stop reading... */
2402 stdin_open = 0;
2403 } else {
2404 mst_receive (stdin_mst, readbuf, ret);
2405 fprintf (stderr, "LOG : receives a message from STDIN\n"); //FIXME: debugging message
2406 }
2407 }
2408 else
2409 if (GNUNET_NETWORK_fdset_isset (rfds, dev.handle))
2410 {
2411 fprintf (stderr, "LOG: accepting connection\n");
2412 struct GNUNET_NETWORK_Handle *readsocket;
2413 readsocket = GNUNET_NETWORK_socket_accept (dev.handle, (LPSOCKADDR)&acc_addr, &addr_len);
2414 if (readsocket == NULL)
2415 {
2416 fprintf (stderr, "Accept error %d: ", GetLastError());
2417 print_last_error();
2418 ExitProcess (2);
2419 }
2420 else
2421 {
2422 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking (readsocket, 1) )
2423 { 2337 {
2424 fprintf (stderr, "Failed to change the socket mode\n"); 2338 if (GNUNET_NETWORK_fdset_isset(wfds, sendsocket))
2425 ExitProcess (2); 2339 {
2340 ssize_t ret;
2341 ret = GNUNET_NETWORK_socket_send(sendsocket, write_pout.buf + write_pout.pos,
2342 write_pout.size - write_pout.pos);
2343
2344 if (GNUNET_SYSERR == ret)
2345 {
2346 fprintf(stderr, "Failed to send to the socket. Closing the socket. Error: \n");
2347 print_last_error();
2348 if (GNUNET_NETWORK_socket_close(sendsocket) != GNUNET_OK)
2349 {
2350 fprintf(stderr, "Failed to close the sendsocket!\n");
2351 print_last_error();
2352 }
2353 ExitProcess(2);
2354 }
2355 else
2356 {
2357 write_pout.pos += ret;
2358 if ((write_pout.pos != write_pout.size) && (0 != ret))
2359 {
2360 /* we should not get partial sends with packet-oriented devices... */
2361 fprintf(stderr, "Write error, partial send: %u/%u\n",
2362 (unsigned int)write_pout.pos,
2363 (unsigned int)write_pout.size);
2364 break;
2365 }
2366
2367 if (write_pout.pos == write_pout.size)
2368 {
2369 write_pout.pos = 0;
2370 write_pout.size = 0;
2371 }
2372 fprintf(stderr, "LOG : sends a message to a DEVICE\n"); //FIXME: debugging message
2373 }
2374 }
2426 } 2375 }
2427 GNUNET_NETWORK_fdset_set (rfds, readsocket);
2428 2376
2429 if (crt_rfds < MAX_PORTS) 2377 //if (GNUNET_NETWORK_fdset_isset (rfds, (struct GNUNET_NETWORK_Handle*)&stdin_handle))
2430 rfds_list[crt_rfds++] = readsocket; 2378 if (retval == stdin_pos)
2431 else
2432 { 2379 {
2433 fprintf (stderr, "The limit for the read file descriptors list was reached\n"); 2380 //ssize_t ret;
2434 break; 2381 //ret = GNUNET_NETWORK_socket_recv ((struct GNUNET_NETWORK_Handle *)&stdin_handle, readbuf, sizeof (write_pout.buf));
2382 //ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
2383 DWORD ret;
2384 if (FALSE == ReadFile(stdin_handle, readbuf, sizeof(readbuf), &ret, NULL)) /* do nothing asynchronous */
2385 {
2386 fprintf(stderr, "Read error from STDIN: ");
2387 print_last_error();
2388 break;
2389 }
2390 if (0 == ret)
2391 {
2392 /* stop reading... */
2393 stdin_open = 0;
2394 }
2395 else
2396 {
2397 mst_receive(stdin_mst, readbuf, ret);
2398 fprintf(stderr, "LOG : receives a message from STDIN\n"); //FIXME: debugging message
2399 }
2435 } 2400 }
2436 } 2401 else
2437 } 2402 if (GNUNET_NETWORK_fdset_isset(rfds, dev.handle))
2438 else
2439 for (i = 0; i < crt_rfds; i++)
2440 {
2441 if (GNUNET_NETWORK_fdset_isset (rfds, rfds_list[i]))
2442 {
2443 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2444 ssize_t ret;
2445 fprintf (stderr, "LOG: reading something from the socket\n");//FIXME : debugging message
2446 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
2447 ret = read_from_the_socket (rfds_list[i], (unsigned char *) &rrm->frame,
2448 sizeof (write_std.buf)
2449 - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2450 + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2451 rrm);
2452 if (0 >= ret)
2453 { 2403 {
2454 2404 fprintf(stderr, "LOG: accepting connection\n");
2455 //TODO remove the socket from the list 2405 struct GNUNET_NETWORK_Handle *readsocket;
2456 if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK) 2406 readsocket = GNUNET_NETWORK_socket_accept(dev.handle, (LPSOCKADDR)&acc_addr, &addr_len);
2407 if (readsocket == NULL)
2408 {
2409 fprintf(stderr, "Accept error %d: ", GetLastError());
2410 print_last_error();
2411 ExitProcess(2);
2412 }
2413 else
2414 {
2415 if (GNUNET_OK != GNUNET_NETWORK_socket_set_blocking(readsocket, 1))
2416 {
2417 fprintf(stderr, "Failed to change the socket mode\n");
2418 ExitProcess(2);
2419 }
2420 GNUNET_NETWORK_fdset_set(rfds, readsocket);
2421
2422 if (crt_rfds < MAX_PORTS)
2423 rfds_list[crt_rfds++] = readsocket;
2424 else
2425 {
2426 fprintf(stderr, "The limit for the read file descriptors list was reached\n");
2427 break;
2428 }
2429 }
2430 }
2431 else
2432 for (i = 0; i < crt_rfds; i++)
2457 { 2433 {
2458 fprintf (stderr, "Failed to close the sendsocket!\n"); 2434 if (GNUNET_NETWORK_fdset_isset(rfds, rfds_list[i]))
2459 print_last_error(); 2435 {
2436 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2437 ssize_t ret;
2438 fprintf(stderr, "LOG: reading something from the socket\n");//FIXME : debugging message
2439 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
2440 ret = read_from_the_socket(rfds_list[i], (unsigned char *)&rrm->frame,
2441 sizeof(write_std.buf)
2442 - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2443 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2444 rrm);
2445 if (0 >= ret)
2446 {
2447 //TODO remove the socket from the list
2448 if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK)
2449 {
2450 fprintf(stderr, "Failed to close the sendsocket!\n");
2451 print_last_error();
2452 }
2453
2454 fprintf(stderr, "Read error from raw socket: ");
2455 print_last_error();
2456 break;
2457 }
2458 if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
2459 {
2460 write_std.size = ret
2461 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2462 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2463 rrm->header.size = htons(write_std.size);
2464 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2465 }
2466 break;
2467 }
2460 } 2468 }
2461
2462 fprintf (stderr, "Read error from raw socket: ");
2463 print_last_error();
2464 break;
2465
2466 }
2467 if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
2468 {
2469 write_std.size = ret
2470 + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2471 - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2472 rrm->header.size = htons (write_std.size);
2473 rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2474 }
2475 break;
2476 }
2477 } 2469 }
2478 }
2479 } 2470 }
2480 2471
2481 mst_destroy (stdin_mst); 2472 mst_destroy(stdin_mst);
2482 stdin_mst = NULL; 2473 stdin_mst = NULL;
2483 2474
2484 if (GNUNET_NETWORK_socket_close (dev.handle) != GNUNET_OK) 2475 if (GNUNET_NETWORK_socket_close(dev.handle) != GNUNET_OK)
2485 { 2476 {
2486 fprintf (stderr, "Failed to close the socket!\n"); 2477 fprintf(stderr, "Failed to close the socket!\n");
2487 print_last_error(); 2478 print_last_error();
2488 } 2479 }
2489 2480
2490 for (i = 0; i < crt_rfds; i++) 2481 for (i = 0; i < crt_rfds; i++)
2491 { 2482 {
2492 if (GNUNET_NETWORK_socket_close (rfds_list[i]) != GNUNET_OK) 2483 if (GNUNET_NETWORK_socket_close(rfds_list[i]) != GNUNET_OK)
2493 { 2484 {
2494 fprintf (stderr, "Failed to close the socket!\n"); 2485 fprintf(stderr, "Failed to close the socket!\n");
2495 print_last_error(); 2486 print_last_error();
2496 } 2487 }
2497 } 2488 }
2498 2489
2499 WSACleanup(); 2490 WSACleanup();
2500 #endif 2491 #endif
2501 return 1; /* we never exit 'normally' */ 2492 return 1; /* we never exit 'normally' */
2502} 2493}
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c
index 0adf8f6a5..44a54b7f6 100644
--- a/src/transport/gnunet-helper-transport-wlan-dummy.c
+++ b/src/transport/gnunet-helper-transport-wlan-dummy.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012 GNUnet e.V. 3 Copyright (C) 2010, 2012 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -47,9 +47,7 @@
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{
52
53 /** 51 /**
54 * How many bytes that were stored in 'buf' did we already write to the 52 * How many bytes that were stored in 'buf' did we already write to the
55 * destination? Always smaller than 'size'. 53 * destination? Always smaller than 'size'.
@@ -82,11 +80,11 @@ static int closeprog;
82 * @param sig killing signal 80 * @param sig killing signal
83 */ 81 */
84static void 82static void
85sigfunc (int sig) 83sigfunc(int sig)
86{ 84{
87 closeprog = 1; 85 closeprog = 1;
88 (void) unlink (FIFO_FILE1); 86 (void)unlink(FIFO_FILE1);
89 (void) unlink (FIFO_FILE2); 87 (void)unlink(FIFO_FILE2);
90} 88}
91 89
92 90
@@ -98,21 +96,20 @@ sigfunc (int sig)
98 * @return number of bytes written 96 * @return number of bytes written
99 */ 97 */
100static int 98static int
101send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) 99send_mac_to_plugin(char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
102{ 100{
103
104 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 101 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
105 102
106 GNUNET_memcpy (&macmsg.mac, 103 GNUNET_memcpy(&macmsg.mac,
107 (char *) mac, 104 (char *)mac,
108 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 105 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
109 macmsg.hdr.size = 106 macmsg.hdr.size =
110 htons (sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 107 htons(sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
111 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 108 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
112 GNUNET_memcpy (buffer, 109 GNUNET_memcpy(buffer,
113 &macmsg, 110 &macmsg,
114 sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage)); 111 sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage));
115 return sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage); 112 return sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage);
116} 113}
117 114
118 115
@@ -127,7 +124,7 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac)
127 * #GNUNET_SYSERR to stop further processing with error 124 * #GNUNET_SYSERR to stop further processing with error
128 */ 125 */
129static int 126static int
130stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr) 127stdin_send(void *cls, const struct GNUNET_MessageHeader *hdr)
131{ 128{
132 struct SendBuffer *write_pout = cls; 129 struct SendBuffer *write_pout = cls;
133 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; 130 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in;
@@ -135,32 +132,32 @@ stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
135 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader; 132 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage newheader;
136 uint16_t sendsize; 133 uint16_t sendsize;
137 134
138 sendsize = ntohs (hdr->size); 135 sendsize = ntohs(hdr->size);
139 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; 136 in = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
140 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || 137 if ((GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)) ||
141 (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize)) 138 (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize))
142 { 139 {
143 fprintf (stderr, "%s", "Received malformed message\n"); 140 fprintf(stderr, "%s", "Received malformed message\n");
144 exit (1); 141 exit(1);
145 } 142 }
146 payload_size = 143 payload_size =
147 sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); 144 sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage);
148 if ((payload_size + 145 if ((payload_size +
149 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + 146 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) +
150 write_pout->size) > MAXLINE * 2) 147 write_pout->size) > MAXLINE * 2)
151 { 148 {
152 fprintf (stderr, "%s", "Packet too big for buffer\n"); 149 fprintf(stderr, "%s", "Packet too big for buffer\n");
153 exit (1); 150 exit(1);
154 } 151 }
155 memset (&newheader, 0, sizeof (newheader)); 152 memset(&newheader, 0, sizeof(newheader));
156 newheader.header.size = htons (payload_size + sizeof (newheader)); 153 newheader.header.size = htons(payload_size + sizeof(newheader));
157 newheader.header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER); 154 newheader.header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
158 newheader.frame = in->frame; 155 newheader.frame = in->frame;
159 GNUNET_memcpy (write_pout->buf + write_pout->size, 156 GNUNET_memcpy(write_pout->buf + write_pout->size,
160 &newheader, 157 &newheader,
161 sizeof (newheader)); 158 sizeof(newheader));
162 write_pout->size += sizeof (newheader); 159 write_pout->size += sizeof(newheader);
163 GNUNET_memcpy (write_pout->buf + write_pout->size, &in[1], payload_size); 160 GNUNET_memcpy(write_pout->buf + write_pout->size, &in[1], payload_size);
164 write_pout->size += payload_size; 161 write_pout->size += payload_size;
165 return GNUNET_OK; 162 return GNUNET_OK;
166} 163}
@@ -176,18 +173,18 @@ stdin_send (void *cls, const struct GNUNET_MessageHeader *hdr)
176 * #GNUNET_SYSERR to stop further processing with error 173 * #GNUNET_SYSERR to stop further processing with error
177 */ 174 */
178static int 175static int
179file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr) 176file_in_send(void *cls, const struct GNUNET_MessageHeader *hdr)
180{ 177{
181 struct SendBuffer *write_std = cls; 178 struct SendBuffer *write_std = cls;
182 uint16_t sendsize; 179 uint16_t sendsize;
183 180
184 sendsize = ntohs (hdr->size); 181 sendsize = ntohs(hdr->size);
185 if ((sendsize + write_std->size) > MAXLINE * 2) 182 if ((sendsize + write_std->size) > MAXLINE * 2)
186 { 183 {
187 fprintf (stderr, "%s", "Packet too big for buffer\n"); 184 fprintf(stderr, "%s", "Packet too big for buffer\n");
188 exit (1); 185 exit(1);
189 } 186 }
190 GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize); 187 GNUNET_memcpy(write_std->buf + write_std->size, hdr, sendsize);
191 write_std->size += sendsize; 188 write_std->size += sendsize;
192 return GNUNET_OK; 189 return GNUNET_OK;
193} 190}
@@ -201,7 +198,7 @@ file_in_send (void *cls, const struct GNUNET_MessageHeader *hdr)
201 * @return 1 on error, 0 if terminated normally via signal 198 * @return 1 on error, 0 if terminated normally via signal
202 */ 199 */
203int 200int
204main (int argc, char *argv[]) 201main(int argc, char *argv[])
205{ 202{
206 struct stat st; 203 struct stat st;
207 int erg; 204 int erg;
@@ -225,298 +222,298 @@ main (int argc, char *argv[])
225 int first; 222 int first;
226 223
227 if ((2 != argc) || 224 if ((2 != argc) ||
228 ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2")))) 225 ((0 != strcmp(argv[1], "1")) && (0 != strcmp(argv[1], "2"))))
229 {
230 fprintf (
231 stderr,
232 "%s",
233 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
234 return 1;
235 }
236
237 /* make the fifos if needed */
238 umask (0);
239 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) ||
240 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)))
241 {
242 fprintf (stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
243 return 1;
244 }
245 if (0 == strcmp (argv[1], "1"))
246 {
247 if (0 != stat (FIFO_FILE1, &st))
248 { 226 {
249 erg = mkfifo (FIFO_FILE1, 0666); 227 fprintf(
250 if ((0 != erg) && (EEXIST != errno)) 228 stderr,
251 fprintf (stderr, 229 "%s",
252 "Error in mkfifo(%s): %s\n", 230 "This program must be started with the operating mode (1 or 2) as the only argument.\n");
253 FIFO_FILE1, 231 return 1;
254 strerror (errno));
255 } 232 }
256 } 233
257 else 234 /* make the fifos if needed */
258 { 235 umask(0);
259 if (0 != stat (FIFO_FILE2, &st)) 236 if ((GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE1)) ||
237 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(FIFO_FILE2)))
260 { 238 {
261 GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); 239 fprintf(stderr, "Failed to create directory for file `%s'\n", FIFO_FILE1);
262 if ((0 != erg) && (EEXIST != errno)) 240 return 1;
263 fprintf (stderr,
264 "Error in mkfifo(%s): %s\n",
265 FIFO_FILE2,
266 strerror (errno));
267 } 241 }
268 } 242 if (0 == strcmp(argv[1], "1"))
269
270 if (0 == strcmp (argv[1], "1"))
271 {
272 first = 1;
273 fpin = fopen (FIFO_FILE1, "r");
274 if (NULL == fpin)
275 { 243 {
276 fprintf (stderr, 244 if (0 != stat(FIFO_FILE1, &st))
277 "fopen of read FIFO_FILE1 failed: %s\n", 245 {
278 strerror (errno)); 246 erg = mkfifo(FIFO_FILE1, 0666);
279 goto end; 247 if ((0 != erg) && (EEXIST != errno))
248 fprintf(stderr,
249 "Error in mkfifo(%s): %s\n",
250 FIFO_FILE1,
251 strerror(errno));
252 }
280 } 253 }
281 if (NULL == (fpout = fopen (FIFO_FILE2, "w"))) 254 else
282 { 255 {
283 GNUNET_break (0 == mkfifo (FIFO_FILE2, 0666)); 256 if (0 != stat(FIFO_FILE2, &st))
284 fpout = fopen (FIFO_FILE2, "w"); 257 {
258 GNUNET_break(0 == (erg = mkfifo(FIFO_FILE2, 0666)));
259 if ((0 != erg) && (EEXIST != errno))
260 fprintf(stderr,
261 "Error in mkfifo(%s): %s\n",
262 FIFO_FILE2,
263 strerror(errno));
264 }
285 } 265 }
286 if (NULL == fpout) 266
267 if (0 == strcmp(argv[1], "1"))
287 { 268 {
288 fprintf (stderr, 269 first = 1;
289 "fopen of write FIFO_FILE2 failed: %s\n", 270 fpin = fopen(FIFO_FILE1, "r");
290 strerror (errno)); 271 if (NULL == fpin)
291 goto end; 272 {
273 fprintf(stderr,
274 "fopen of read FIFO_FILE1 failed: %s\n",
275 strerror(errno));
276 goto end;
277 }
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 }
292 } 290 }
293 }
294 else 291 else
295 {
296 first = 0;
297 if (NULL == (fpout = fopen (FIFO_FILE1, "w")))
298 { 292 {
299 GNUNET_break (0 == mkfifo (FIFO_FILE1, 0666)); 293 first = 0;
300 fpout = fopen (FIFO_FILE1, "w"); 294 if (NULL == (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 }
301 } 314 }
302 if (NULL == fpout) 315
316 fdpin = fileno(fpin);
317 GNUNET_assert(fpin >= 0);
318 if (fdpin >= FD_SETSIZE)
303 { 319 {
304 fprintf (stderr, 320 fprintf(stderr,
305 "fopen of write FIFO_FILE1 failed: %s\n", 321 "File fdpin number too large (%d > %u)\n",
306 strerror (errno)); 322 fdpin,
323 (unsigned int)FD_SETSIZE);
307 goto end; 324 goto end;
308 } 325 }
309 fpin = fopen (FIFO_FILE2, "r"); 326
310 if (NULL == fpin) 327 fdpout = fileno(fpout);
328 GNUNET_assert(fdpout >= 0);
329
330 if (fdpout >= FD_SETSIZE)
311 { 331 {
312 fprintf (stderr, 332 fprintf(stderr,
313 "fopen of read FIFO_FILE2 failed: %s\n", 333 "File fdpout number too large (%d > %u)\n",
314 strerror (errno)); 334 fdpout,
335 (unsigned int)FD_SETSIZE);
315 goto end; 336 goto end;
316 } 337 }
317 }
318
319 fdpin = fileno (fpin);
320 GNUNET_assert (fpin >= 0);
321 if (fdpin >= FD_SETSIZE)
322 {
323 fprintf (stderr,
324 "File fdpin number too large (%d > %u)\n",
325 fdpin,
326 (unsigned int) FD_SETSIZE);
327 goto end;
328 }
329
330 fdpout = fileno (fpout);
331 GNUNET_assert (fdpout >= 0);
332 338
333 if (fdpout >= FD_SETSIZE) 339 signal(SIGINT, &sigfunc);
334 { 340 signal(SIGTERM, &sigfunc);
335 fprintf (stderr, 341 signal(GNUNET_TERM_SIG, &sigfunc);
336 "File fdpout number too large (%d > %u)\n",
337 fdpout,
338 (unsigned int) FD_SETSIZE);
339 goto end;
340 }
341
342 signal (SIGINT, &sigfunc);
343 signal (SIGTERM, &sigfunc);
344 signal (GNUNET_TERM_SIG, &sigfunc);
345 342
346 write_std.size = 0; 343 write_std.size = 0;
347 write_std.pos = 0; 344 write_std.pos = 0;
348 write_pout.size = 0; 345 write_pout.size = 0;
349 write_pout.pos = 0; 346 write_pout.pos = 0;
350 stdin_mst = GNUNET_MST_create (&stdin_send, &write_pout); 347 stdin_mst = GNUNET_MST_create(&stdin_send, &write_pout);
351 file_in_mst = GNUNET_MST_create (&file_in_send, &write_std); 348 file_in_mst = GNUNET_MST_create(&file_in_send, &write_std);
352 349
353 /* Send 'random' mac address */ 350 /* Send 'random' mac address */
354 macaddr.mac[0] = 0x13; 351 macaddr.mac[0] = 0x13;
355 macaddr.mac[1] = 0x22; 352 macaddr.mac[1] = 0x22;
356 macaddr.mac[2] = 0x33; 353 macaddr.mac[2] = 0x33;
357 macaddr.mac[3] = 0x44; 354 macaddr.mac[3] = 0x44;
358 macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256); 355 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256);
359 macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256); 356 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256);
360 write_std.size = send_mac_to_plugin (write_std.buf, &macaddr); 357 write_std.size = send_mac_to_plugin(write_std.buf, &macaddr);
361 358
362 while (0 == closeprog) 359 while (0 == closeprog)
363 {
364 maxfd = -1;
365 tv.tv_sec = 5;
366 tv.tv_usec = 0;
367
368 FD_ZERO (&rfds);
369 FD_ZERO (&wfds);
370 /* if output queue is empty, read */
371 if (0 == write_pout.size)
372 {
373 FD_SET (STDIN_FILENO, &rfds);
374 maxfd = MAX (STDIN_FILENO, maxfd);
375 }
376 if (0 == write_std.size)
377 { 360 {
378 FD_SET (fdpin, &rfds); 361 maxfd = -1;
379 maxfd = MAX (fdpin, maxfd); 362 tv.tv_sec = 5;
380 } 363 tv.tv_usec = 0;
364
365 FD_ZERO(&rfds);
366 FD_ZERO(&wfds);
367 /* if output queue is empty, read */
368 if (0 == write_pout.size)
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 }
381 378
382 /* if there is something to write, try to write */ 379 /* if there is something to write, try to write */
383 if (0 < write_std.size) 380 if (0 < write_std.size)
384 { 381 {
385 FD_SET (STDOUT_FILENO, &wfds); 382 FD_SET(STDOUT_FILENO, &wfds);
386 maxfd = MAX (maxfd, STDOUT_FILENO); 383 maxfd = MAX(maxfd, STDOUT_FILENO);
387 } 384 }
388 if (0 < write_pout.size) 385 if (0 < write_pout.size)
389 { 386 {
390 FD_SET (fdpout, &wfds); 387 FD_SET(fdpout, &wfds);
391 maxfd = MAX (maxfd, fdpout); 388 maxfd = MAX(maxfd, fdpout);
392 } 389 }
393 390
394 retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv); 391 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
395 if ((-1 == retval) && (EINTR == errno)) 392 if ((-1 == retval) && (EINTR == errno))
396 continue; 393 continue;
397 if (0 > retval) 394 if (0 > retval)
398 { 395 {
399 fprintf (stderr, "select failed: %s\n", strerror (errno)); 396 fprintf(stderr, "select failed: %s\n", strerror(errno));
400 closeprog = 1; 397 closeprog = 1;
401 break; 398 break;
402 } 399 }
403 400
404 if (FD_ISSET (STDOUT_FILENO, &wfds)) 401 if (FD_ISSET(STDOUT_FILENO, &wfds))
405 {
406 ret = write (STDOUT_FILENO,
407 write_std.buf + write_std.pos,
408 write_std.size - write_std.pos);
409 if (0 > ret)
410 {
411 closeprog = 1;
412 fprintf (stderr,
413 "Write ERROR to STDOUT_FILENO: %s\n",
414 strerror (errno));
415 break;
416 }
417 else
418 {
419 write_std.pos += ret;
420 /* check if finished writing */
421 if (write_std.pos == write_std.size)
422 { 402 {
423 write_std.pos = 0; 403 ret = write(STDOUT_FILENO,
424 write_std.size = 0; 404 write_std.buf + write_std.pos,
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 }
425 } 424 }
426 }
427 }
428 425
429 if (FD_ISSET (fdpout, &wfds)) 426 if (FD_ISSET(fdpout, &wfds))
430 {
431 ret = write (fdpout,
432 write_pout.buf + write_pout.pos,
433 write_pout.size - write_pout.pos);
434
435 if (0 > ret)
436 {
437 closeprog = 1;
438 fprintf (stderr,
439 "Write ERROR to fdpout failed: %s\n",
440 strerror (errno));
441 }
442 else
443 {
444 write_pout.pos += ret;
445 /* check if finished writing */
446 if (write_pout.pos == write_pout.size)
447 { 427 {
448 write_pout.pos = 0; 428 ret = write(fdpout,
449 write_pout.size = 0; 429 write_pout.buf + write_pout.pos,
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 }
450 } 449 }
451 }
452 }
453 450
454 if (FD_ISSET (STDIN_FILENO, &rfds)) 451 if (FD_ISSET(STDIN_FILENO, &rfds))
455 { 452 {
456 readsize = read (STDIN_FILENO, readbuf, sizeof (readbuf)); 453 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf));
457 454
458 if (0 > readsize) 455 if (0 > readsize)
459 { 456 {
460 closeprog = 1; 457 closeprog = 1;
461 fprintf (stderr, 458 fprintf(stderr,
462 "Error reading from STDIN_FILENO: %s\n", 459 "Error reading from STDIN_FILENO: %s\n",
463 strerror (errno)); 460 strerror(errno));
464 } 461 }
465 else if (0 < readsize) 462 else if (0 < readsize)
466 { 463 {
467 GNUNET_MST_from_buffer (stdin_mst, 464 GNUNET_MST_from_buffer(stdin_mst,
468 readbuf, 465 readbuf,
469 readsize, 466 readsize,
470 GNUNET_NO, 467 GNUNET_NO,
471 GNUNET_NO); 468 GNUNET_NO);
472 } 469 }
473 else 470 else
474 { 471 {
475 /* eof */ 472 /* eof */
476 closeprog = 1; 473 closeprog = 1;
477 } 474 }
478 } 475 }
479 476
480 if (FD_ISSET (fdpin, &rfds)) 477 if (FD_ISSET(fdpin, &rfds))
481 { 478 {
482 readsize = read (fdpin, readbuf, sizeof (readbuf)); 479 readsize = read(fdpin, readbuf, sizeof(readbuf));
483 if (0 > readsize) 480 if (0 > readsize)
484 { 481 {
485 closeprog = 1; 482 closeprog = 1;
486 fprintf (stderr, "Error reading from fdpin: %s\n", strerror (errno)); 483 fprintf(stderr, "Error reading from fdpin: %s\n", strerror(errno));
487 break; 484 break;
488 } 485 }
489 else if (0 < readsize) 486 else if (0 < readsize)
490 { 487 {
491 GNUNET_MST_from_buffer (file_in_mst, 488 GNUNET_MST_from_buffer(file_in_mst,
492 readbuf, 489 readbuf,
493 readsize, 490 readsize,
494 GNUNET_NO, 491 GNUNET_NO,
495 GNUNET_NO); 492 GNUNET_NO);
496 } 493 }
497 else 494 else
498 { 495 {
499 /* eof */ 496 /* eof */
500 closeprog = 1; 497 closeprog = 1;
501 } 498 }
499 }
502 } 500 }
503 }
504 501
505end: 502end:
506 /* clean up */ 503 /* clean up */
507 if (NULL != stdin_mst) 504 if (NULL != stdin_mst)
508 GNUNET_MST_destroy (stdin_mst); 505 GNUNET_MST_destroy(stdin_mst);
509 if (NULL != file_in_mst) 506 if (NULL != file_in_mst)
510 GNUNET_MST_destroy (file_in_mst); 507 GNUNET_MST_destroy(file_in_mst);
511 508
512 if (NULL != fpout) 509 if (NULL != fpout)
513 fclose (fpout); 510 fclose(fpout);
514 if (NULL != fpin) 511 if (NULL != fpin)
515 fclose (fpin); 512 fclose(fpin);
516 if (1 == first) 513 if (1 == first)
517 { 514 {
518 (void) unlink (FIFO_FILE1); 515 (void)unlink(FIFO_FILE1);
519 (void) unlink (FIFO_FILE2); 516 (void)unlink(FIFO_FILE2);
520 } 517 }
521 return 0; 518 return 0;
522} 519}
diff --git a/src/transport/gnunet-helper-transport-wlan.c b/src/transport/gnunet-helper-transport-wlan.c
index 6cd45ead8..885edb1b0 100644
--- a/src/transport/gnunet-helper-transport-wlan.c
+++ b/src/transport/gnunet-helper-transport-wlan.c
@@ -13,12 +13,12 @@
13 WITHOUT ANY WARRANTY; without even the implied warranty of 13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Affero General Public License for more details. 15 Affero General Public License for more details.
16 16
17 You should have received a copy of the GNU Affero General Public License 17 You should have received a copy of the GNU Affero General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 SPDX-License-Identifier: AGPL3.0-or-later 20 SPDX-License-Identifier: AGPL3.0-or-later
21*/ 21 */
22/** 22/**
23 * @file src/transport/gnunet-helper-transport-wlan.c 23 * @file src/transport/gnunet-helper-transport-wlan.c
24 * @brief mediator between the wlan interface and gnunet; must run as root (SUID will do) 24 * @brief mediator between the wlan interface and gnunet; must run as root (SUID will do)
@@ -234,8 +234,7 @@
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{
239 /** 238 /**
240 * This has a different ID for each parameter, see 239 * This has a different ID for each parameter, see
241 * PRISM_DID_* constants. 240 * PRISM_DID_* constants.
@@ -258,15 +257,13 @@ struct PrismValue
258 * The data value 257 * The data value
259 */ 258 */
260 uint32_t data; 259 uint32_t data;
261
262} __attribute__ ((packed)); 260} __attribute__ ((packed));
263 261
264 262
265/** 263/**
266 * Prism header format ('struct p80211msg' in Linux). All in host byte order (!). 264 * Prism header format ('struct p80211msg' in Linux). All in host byte order (!).
267 */ 265 */
268struct PrismHeader 266struct PrismHeader {
269{
270 /** 267 /**
271 * We expect this to be a PRISM_MSGCODE_*. 268 * We expect this to be a PRISM_MSGCODE_*.
272 */ 269 */
@@ -286,7 +283,6 @@ struct PrismHeader
286 are typically the hosttime, mactime, channel, rssi, sq, signal, noise, 283 are typically the hosttime, mactime, channel, rssi, sq, signal, noise,
287 rate, istx and frmlen values, but documentation is sparse. So we 284 rate, istx and frmlen values, but documentation is sparse. So we
288 will use the 'did' fields to find out what we actually got. */ 285 will use the 'did' fields to find out what we actually got. */
289
290} __attribute__ ((packed)); 286} __attribute__ ((packed));
291 287
292 288
@@ -305,9 +301,7 @@ struct PrismHeader
305 * reliable indicator of alignment requirement. See also 301 * reliable indicator of alignment requirement. See also
306 * 'man 9 ieee80211_radiotap'. 302 * 'man 9 ieee80211_radiotap'.
307 */ 303 */
308enum RadiotapType 304enum RadiotapType {
309{
310
311 /** 305 /**
312 * IEEE80211_RADIOTAP_TSFT __le64 microseconds 306 * IEEE80211_RADIOTAP_TSFT __le64 microseconds
313 * 307 *
@@ -477,7 +471,7 @@ enum RadiotapType
477 * 471 *
478 * Frame was sent/received during CFP (Contention Free Period) 472 * Frame was sent/received during CFP (Contention Free Period)
479 */ 473 */
480#define IEEE80211_RADIOTAP_F_CFP 0x01 474#define IEEE80211_RADIOTAP_F_CFP 0x01
481 475
482/** 476/**
483 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get 477 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -487,7 +481,7 @@ enum RadiotapType
487 * 481 *
488 * Frame was sent/received with short preamble 482 * Frame was sent/received with short preamble
489 */ 483 */
490#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 484#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02
491 485
492/** 486/**
493 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get 487 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -497,7 +491,7 @@ enum RadiotapType
497 * 491 *
498 * Frame was sent/received with WEP encryption 492 * Frame was sent/received with WEP encryption
499 */ 493 */
500#define IEEE80211_RADIOTAP_F_WEP 0x04 494#define IEEE80211_RADIOTAP_F_WEP 0x04
501 495
502/** 496/**
503 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get 497 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -507,7 +501,7 @@ enum RadiotapType
507 * 501 *
508 * Frame was sent/received with fragmentation 502 * Frame was sent/received with fragmentation
509 */ 503 */
510#define IEEE80211_RADIOTAP_F_FRAG 0x08 504#define IEEE80211_RADIOTAP_F_FRAG 0x08
511 505
512/** 506/**
513 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get 507 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -517,7 +511,7 @@ enum RadiotapType
517 * 511 *
518 * Frame includes FCS (CRC at the end that needs to be removeD). 512 * Frame includes FCS (CRC at the end that needs to be removeD).
519 */ 513 */
520#define IEEE80211_RADIOTAP_F_FCS 0x10 514#define IEEE80211_RADIOTAP_F_FCS 0x10
521 515
522/** 516/**
523 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get 517 * Bit in IEEE80211_RADIOTAP_FLAGS (which we might get
@@ -528,44 +522,44 @@ enum RadiotapType
528 * Frame has padding between 802.11 header and payload 522 * Frame has padding between 802.11 header and payload
529 * (to 32-bit boundary) 523 * (to 32-bit boundary)
530 */ 524 */
531#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 525#define IEEE80211_RADIOTAP_F_DATAPAD 0x20
532 526
533 527
534/** 528/**
535 * For IEEE80211_RADIOTAP_RX_FLAGS: 529 * For IEEE80211_RADIOTAP_RX_FLAGS:
536 * frame failed crc check 530 * frame failed crc check
537 */ 531 */
538#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 532#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001
539 533
540/** 534/**
541 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): 535 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
542 * failed due to excessive retries 536 * failed due to excessive retries
543 */ 537 */
544#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 538#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001
545 539
546/** 540/**
547 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): 541 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
548 * used cts 'protection' 542 * used cts 'protection'
549 */ 543 */
550#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 544#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002
551 545
552/** 546/**
553 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): 547 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
554 * used rts/cts handshake 548 * used rts/cts handshake
555 */ 549 */
556#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 550#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004
557 551
558/** 552/**
559 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): 553 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
560 * frame should not be ACKed 554 * frame should not be ACKed
561 */ 555 */
562#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 556#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008
563 557
564/** 558/**
565 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'): 559 * For IEEE80211_RADIOTAP_TX_FLAGS ('txflags' in 'struct RadiotapTransmissionHeader'):
566 * sequence number handled by userspace 560 * sequence number handled by userspace
567 */ 561 */
568#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 562#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010
569 563
570 564
571/** 565/**
@@ -582,8 +576,7 @@ enum RadiotapType
582 * The radio capture header precedes the 802.11 header. 576 * The radio capture header precedes the 802.11 header.
583 * All data in the header is little endian on all platforms. 577 * All data in the header is little endian on all platforms.
584 */ 578 */
585struct Ieee80211RadiotapHeader 579struct Ieee80211RadiotapHeader {
586{
587 /** 580 /**
588 * Version 0. Only increases for drastic changes, introduction of 581 * Version 0. Only increases for drastic changes, introduction of
589 * compatible new fields does not count. 582 * compatible new fields does not count.
@@ -614,9 +607,7 @@ struct Ieee80211RadiotapHeader
614 * Format of the header we need to prepend to messages to be sent to the 607 * Format of the header we need to prepend to messages to be sent to the
615 * Kernel. 608 * Kernel.
616 */ 609 */
617struct RadiotapTransmissionHeader 610struct RadiotapTransmissionHeader {
618{
619
620 /** 611 /**
621 * First we begin with the 'generic' header we also get when receiving 612 * First we begin with the 'generic' header we also get when receiving
622 * messages. 613 * messages.
@@ -640,7 +631,6 @@ struct RadiotapTransmissionHeader
640 * Transmission flags from on the IEEE80211_RADIOTAP_F_TX_* constant family. 631 * Transmission flags from on the IEEE80211_RADIOTAP_F_TX_* constant family.
641 */ 632 */
642 uint16_t txflags; 633 uint16_t txflags;
643
644}; 634};
645 635
646/** 636/**
@@ -656,8 +646,7 @@ struct RadiotapTransmissionHeader
656 * struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments 646 * struct Ieee80211RadiotapHeaderIterator - tracks walk through present radiotap arguments
657 * in the radiotap header. Used when we parse radiotap packets received from the kernel. 647 * in the radiotap header. Used when we parse radiotap packets received from the kernel.
658 */ 648 */
659struct Ieee80211RadiotapHeaderIterator 649struct Ieee80211RadiotapHeaderIterator {
660{
661 /** 650 /**
662 * pointer to the radiotap header we are walking through 651 * pointer to the radiotap header we are walking through
663 */ 652 */
@@ -698,7 +687,6 @@ struct Ieee80211RadiotapHeaderIterator
698 * internal next argument index 687 * internal next argument index
699 */ 688 */
700 unsigned int arg_index; 689 unsigned int arg_index;
701
702}; 690};
703 691
704 692
@@ -710,9 +698,7 @@ struct Ieee80211RadiotapHeaderIterator
710 * struct for storing the information of the hardware. There is only 698 * struct for storing the information of the hardware. There is only
711 * one of these. 699 * one of these.
712 */ 700 */
713struct HardwareInfos 701struct HardwareInfos {
714{
715
716 /** 702 /**
717 * file descriptor for the raw socket 703 * file descriptor for the raw socket
718 */ 704 */
@@ -739,8 +725,7 @@ struct HardwareInfos
739/** 725/**
740 * IO buffer used for buffering data in transit (to wireless or to stdout). 726 * IO buffer used for buffering data in transit (to wireless or to stdout).
741 */ 727 */
742struct SendBuffer 728struct SendBuffer {
743{
744 /** 729 /**
745 * How many bytes of data are stored in 'buf' for transmission right now? 730 * How many bytes of data are stored in 'buf' for transmission right now?
746 * Data always starts at offset 0 and extends to 'size'. 731 * Data always starts at offset 0 and extends to 'size'.
@@ -784,7 +769,7 @@ static struct SendBuffer write_std;
784/** 769/**
785 * Smallest supported message. 770 * Smallest supported message.
786 */ 771 */
787#define MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) 772#define MIN_BUFFER_SIZE sizeof(struct GNUNET_MessageHeader)
788 773
789 774
790/** 775/**
@@ -795,16 +780,14 @@ static struct SendBuffer write_std;
795 * @param message the actual message 780 * @param message the actual message
796 */ 781 */
797typedef void (*MessageTokenizerCallback) (void *cls, 782typedef void (*MessageTokenizerCallback) (void *cls,
798 const struct 783 const struct
799 GNUNET_MessageHeader * 784 GNUNET_MessageHeader *
800 message); 785 message);
801 786
802/** 787/**
803 * Handle to a message stream tokenizer. 788 * Handle to a message stream tokenizer.
804 */ 789 */
805struct MessageStreamTokenizer 790struct MessageStreamTokenizer {
806{
807
808 /** 791 /**
809 * Function to call on completed messages. 792 * Function to call on completed messages.
810 */ 793 */
@@ -834,7 +817,6 @@ struct MessageStreamTokenizer
834 * Beginning of the buffer. Typed like this to force alignment. 817 * Beginning of the buffer. Typed like this to force alignment.
835 */ 818 */
836 struct GNUNET_MessageHeader *hdr; 819 struct GNUNET_MessageHeader *hdr;
837
838}; 820};
839 821
840 822
@@ -846,23 +828,23 @@ struct MessageStreamTokenizer
846 * @return handle to tokenizer 828 * @return handle to tokenizer
847 */ 829 */
848static struct MessageStreamTokenizer * 830static struct MessageStreamTokenizer *
849mst_create (MessageTokenizerCallback cb, 831mst_create(MessageTokenizerCallback cb,
850 void *cb_cls) 832 void *cb_cls)
851{ 833{
852 struct MessageStreamTokenizer *ret; 834 struct MessageStreamTokenizer *ret;
853 835
854 ret = malloc (sizeof (struct MessageStreamTokenizer)); 836 ret = malloc(sizeof(struct MessageStreamTokenizer));
855 if (NULL == ret) 837 if (NULL == ret)
856 { 838 {
857 fprintf (stderr, "Failed to allocate buffer for tokenizer\n"); 839 fprintf(stderr, "Failed to allocate buffer for tokenizer\n");
858 exit (1); 840 exit(1);
859 } 841 }
860 ret->hdr = malloc (MIN_BUFFER_SIZE); 842 ret->hdr = malloc(MIN_BUFFER_SIZE);
861 if (NULL == ret->hdr) 843 if (NULL == ret->hdr)
862 { 844 {
863 fprintf (stderr, "Failed to allocate buffer for alignment\n"); 845 fprintf(stderr, "Failed to allocate buffer for alignment\n");
864 exit (1); 846 exit(1);
865 } 847 }
866 ret->curr_buf = MIN_BUFFER_SIZE; 848 ret->curr_buf = MIN_BUFFER_SIZE;
867 ret->cb = cb; 849 ret->cb = cb;
868 ret->cb_cls = cb_cls; 850 ret->cb_cls = cb_cls;
@@ -881,8 +863,8 @@ mst_create (MessageTokenizerCallback cb,
881 * GNUNET_SYSERR if the data stream is corrupt 863 * GNUNET_SYSERR if the data stream is corrupt
882 */ 864 */
883static int 865static int
884mst_receive (struct MessageStreamTokenizer *mst, 866mst_receive(struct MessageStreamTokenizer *mst,
885 const char *buf, size_t size) 867 const char *buf, size_t size)
886{ 868{
887 const struct GNUNET_MessageHeader *hdr; 869 const struct GNUNET_MessageHeader *hdr;
888 size_t delta; 870 size_t delta;
@@ -893,132 +875,132 @@ mst_receive (struct MessageStreamTokenizer *mst,
893 int ret; 875 int ret;
894 876
895 ret = GNUNET_OK; 877 ret = GNUNET_OK;
896 ibuf = (char *) mst->hdr; 878 ibuf = (char *)mst->hdr;
897 while (mst->pos > 0) 879 while (mst->pos > 0)
898 {
899do_align:
900 if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
901 (0 != (mst->off % ALIGN_FACTOR)))
902 {
903 /* need to align or need more space */
904 mst->pos -= mst->off;
905 memmove (ibuf, &ibuf[mst->off], mst->pos);
906 mst->off = 0;
907 }
908 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
909 {
910 delta =
911 GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
912 (mst->pos - mst->off), size);
913 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
914 mst->pos += delta;
915 buf += delta;
916 size -= delta;
917 }
918 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
919 {
920 return GNUNET_OK;
921 }
922 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
923 want = ntohs (hdr->size);
924 if (want < sizeof (struct GNUNET_MessageHeader))
925 {
926 fprintf (stderr,
927 "Received invalid message from stdin\n");
928 exit (1);
929 }
930 if (mst->curr_buf - mst->off < want)
931 {
932 /* need more space */
933 mst->pos -= mst->off;
934 memmove (ibuf, &ibuf[mst->off], mst->pos);
935 mst->off = 0;
936 }
937 if (want > mst->curr_buf)
938 {
939 mst->hdr = realloc (mst->hdr, want);
940 if (NULL == mst->hdr)
941 {
942 fprintf (stderr, "Failed to allocate buffer for alignment\n");
943 exit (1);
944 }
945 ibuf = (char *) mst->hdr;
946 mst->curr_buf = want;
947 }
948 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
949 if (mst->pos - mst->off < want)
950 { 880 {
951 delta = GNUNET_MIN (want - (mst->pos - mst->off), size); 881do_align:
952 GNUNET_memcpy (&ibuf[mst->pos], buf, delta); 882 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
953 mst->pos += delta; 883 (0 != (mst->off % ALIGN_FACTOR)))
954 buf += delta; 884 {
955 size -= delta; 885 /* need to align or need more space */
956 } 886 mst->pos -= mst->off;
957 if (mst->pos - mst->off < want) 887 memmove(ibuf, &ibuf[mst->off], mst->pos);
958 { 888 mst->off = 0;
959 return GNUNET_OK; 889 }
960 } 890 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
961 mst->cb (mst->cb_cls, hdr); 891 {
962 mst->off += want; 892 delta =
963 if (mst->off == mst->pos) 893 GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) -
964 { 894 (mst->pos - mst->off), size);
965 /* reset to beginning of buffer, it's free right now! */ 895 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
966 mst->off = 0; 896 mst->pos += delta;
967 mst->pos = 0; 897 buf += delta;
898 size -= delta;
899 }
900 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
901 {
902 return GNUNET_OK;
903 }
904 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
905 want = ntohs(hdr->size);
906 if (want < sizeof(struct GNUNET_MessageHeader))
907 {
908 fprintf(stderr,
909 "Received invalid message from stdin\n");
910 exit(1);
911 }
912 if (mst->curr_buf - mst->off < want)
913 {
914 /* need more space */
915 mst->pos -= mst->off;
916 memmove(ibuf, &ibuf[mst->off], mst->pos);
917 mst->off = 0;
918 }
919 if (want > mst->curr_buf)
920 {
921 mst->hdr = realloc(mst->hdr, want);
922 if (NULL == mst->hdr)
923 {
924 fprintf(stderr, "Failed to allocate buffer for alignment\n");
925 exit(1);
926 }
927 ibuf = (char *)mst->hdr;
928 mst->curr_buf = want;
929 }
930 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
931 if (mst->pos - mst->off < want)
932 {
933 delta = GNUNET_MIN(want - (mst->pos - mst->off), size);
934 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
935 mst->pos += delta;
936 buf += delta;
937 size -= delta;
938 }
939 if (mst->pos - mst->off < want)
940 {
941 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 }
968 } 951 }
969 }
970 while (size > 0) 952 while (size > 0)
971 {
972 if (size < sizeof (struct GNUNET_MessageHeader))
973 break;
974 offset = (unsigned long) buf;
975 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
976 if (GNUNET_NO == need_align)
977 { 953 {
978 /* can try to do zero-copy and process directly from original buffer */ 954 if (size < sizeof(struct GNUNET_MessageHeader))
979 hdr = (const struct GNUNET_MessageHeader *) buf; 955 break;
980 want = ntohs (hdr->size); 956 offset = (unsigned long)buf;
981 if (want < sizeof (struct GNUNET_MessageHeader)) 957 need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO;
982 { 958 if (GNUNET_NO == need_align)
983 fprintf (stderr, 959 {
984 "Received invalid message from stdin\n"); 960 /* can try to do zero-copy and process directly from original buffer */
985 exit (1); 961 hdr = (const struct GNUNET_MessageHeader *)buf;
986 } 962 want = ntohs(hdr->size);
987 if (size < want) 963 if (want < sizeof(struct GNUNET_MessageHeader))
988 break; /* or not, buffer incomplete, so copy to private buffer... */ 964 {
989 mst->cb (mst->cb_cls, hdr); 965 fprintf(stderr,
990 buf += want; 966 "Received invalid message from stdin\n");
991 size -= want; 967 exit(1);
992 } 968 }
993 else 969 if (size < want)
994 { 970 break; /* or not, buffer incomplete, so copy to private buffer... */
995 /* need to copy to private buffer to align; 971 mst->cb(mst->cb_cls, hdr);
996 * yes, we go a bit more spagetti than usual here */ 972 buf += want;
997 goto do_align; 973 size -= want;
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 }
998 } 981 }
999 }
1000 if (size > 0) 982 if (size > 0)
1001 {
1002 if (size + mst->pos > mst->curr_buf)
1003 { 983 {
1004 mst->hdr = realloc (mst->hdr, size + mst->pos); 984 if (size + mst->pos > mst->curr_buf)
1005 if (NULL == mst->hdr) 985 {
1006 { 986 mst->hdr = realloc(mst->hdr, size + mst->pos);
1007 fprintf (stderr, "Failed to allocate buffer for alignment\n"); 987 if (NULL == mst->hdr)
1008 exit (1); 988 {
1009 } 989 fprintf(stderr, "Failed to allocate buffer for alignment\n");
1010 ibuf = (char *) mst->hdr; 990 exit(1);
1011 mst->curr_buf = size + mst->pos; 991 }
992 ibuf = (char *)mst->hdr;
993 mst->curr_buf = size + mst->pos;
994 }
995 if (mst->pos + size > mst->curr_buf)
996 {
997 fprintf(stderr,
998 "Assertion failed\n");
999 exit(1);
1000 }
1001 GNUNET_memcpy(&ibuf[mst->pos], buf, size);
1002 mst->pos += size;
1012 } 1003 }
1013 if (mst->pos + size > mst->curr_buf)
1014 {
1015 fprintf (stderr,
1016 "Assertion failed\n");
1017 exit (1);
1018 }
1019 GNUNET_memcpy (&ibuf[mst->pos], buf, size);
1020 mst->pos += size;
1021 }
1022 return ret; 1004 return ret;
1023} 1005}
1024 1006
@@ -1029,10 +1011,10 @@ do_align:
1029 * @param mst tokenizer to destroy 1011 * @param mst tokenizer to destroy
1030 */ 1012 */
1031static void 1013static void
1032mst_destroy (struct MessageStreamTokenizer *mst) 1014mst_destroy(struct MessageStreamTokenizer *mst)
1033{ 1015{
1034 free (mst->hdr); 1016 free(mst->hdr);
1035 free (mst); 1017 free(mst);
1036} 1018}
1037 1019
1038/* ***************** end of server_mst.c clone ***************** **/ 1020/* ***************** end of server_mst.c clone ***************** **/
@@ -1058,12 +1040,12 @@ mst_destroy (struct MessageStreamTokenizer *mst)
1058 * @return 0 on success, -1 on error 1040 * @return 0 on success, -1 on error
1059 */ 1041 */
1060static int 1042static int
1061ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterator, 1043ieee80211_radiotap_iterator_init(struct Ieee80211RadiotapHeaderIterator *iterator,
1062 const struct Ieee80211RadiotapHeader *radiotap_header, 1044 const struct Ieee80211RadiotapHeader *radiotap_header,
1063 size_t max_length) 1045 size_t max_length)
1064{ 1046{
1065 if ( (iterator == NULL) || 1047 if ((iterator == NULL) ||
1066 (radiotap_header == NULL) ) 1048 (radiotap_header == NULL))
1067 return -1; 1049 return -1;
1068 1050
1069 /* Linux only supports version 0 radiotap format */ 1051 /* Linux only supports version 0 radiotap format */
@@ -1071,37 +1053,37 @@ ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterat
1071 return -1; 1053 return -1;
1072 1054
1073 /* sanity check for allowed length and radiotap length field */ 1055 /* sanity check for allowed length and radiotap length field */
1074 if ( (max_length < sizeof (struct Ieee80211RadiotapHeader)) || 1056 if ((max_length < sizeof(struct Ieee80211RadiotapHeader)) ||
1075 (max_length < (GNUNET_le16toh (radiotap_header->it_len))) ) 1057 (max_length < (GNUNET_le16toh(radiotap_header->it_len))))
1076 return -1; 1058 return -1;
1077 1059
1078 memset (iterator, 0, sizeof (struct Ieee80211RadiotapHeaderIterator)); 1060 memset(iterator, 0, sizeof(struct Ieee80211RadiotapHeaderIterator));
1079 iterator->rtheader = radiotap_header; 1061 iterator->rtheader = radiotap_header;
1080 iterator->max_length = GNUNET_le16toh (radiotap_header->it_len); 1062 iterator->max_length = GNUNET_le16toh(radiotap_header->it_len);
1081 iterator->bitmap_shifter = GNUNET_le32toh (radiotap_header->it_present); 1063 iterator->bitmap_shifter = GNUNET_le32toh(radiotap_header->it_present);
1082 iterator->arg = ((uint8_t *) radiotap_header) + sizeof (struct Ieee80211RadiotapHeader); 1064 iterator->arg = ((uint8_t *)radiotap_header) + sizeof(struct Ieee80211RadiotapHeader);
1083 1065
1084 /* find payload start allowing for extended bitmap(s) */ 1066 /* find payload start allowing for extended bitmap(s) */
1085 if (0 != (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) 1067 if (0 != (iterator->bitmap_shifter & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
1086 {
1087 while (GNUNET_le32toh (*((uint32_t *) iterator->arg)) & IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
1088 { 1068 {
1089 iterator->arg += sizeof (uint32_t); 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);
1090 /* 1081 /*
1091 * check for insanity where the present bitmaps 1082 * no need to check again for blowing past stated radiotap
1092 * keep claiming to extend up to or even beyond the 1083 * header length, becuase ieee80211_radiotap_iterator_next
1093 * stated radiotap header length 1084 * checks it before it is dereferenced
1094 */ 1085 */
1095 if (iterator->arg - ((uint8_t*) iterator->rtheader) > iterator->max_length)
1096 return -1;
1097 } 1086 }
1098 iterator->arg += sizeof (uint32_t);
1099 /*
1100 * no need to check again for blowing past stated radiotap
1101 * header length, becuase ieee80211_radiotap_iterator_next
1102 * checks it before it is dereferenced
1103 */
1104 }
1105 /* we are all initialized happily */ 1087 /* we are all initialized happily */
1106 return 0; 1088 return 0;
1107} 1089}
@@ -1120,7 +1102,7 @@ ieee80211_radiotap_iterator_init (struct Ieee80211RadiotapHeaderIterator *iterat
1120 * @return next present arg index on success or -1 if no more or error 1102 * @return next present arg index on success or -1 if no more or error
1121 */ 1103 */
1122static int 1104static int
1123ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterator) 1105ieee80211_radiotap_iterator_next(struct Ieee80211RadiotapHeaderIterator *iterator)
1124{ 1106{
1125 /* 1107 /*
1126 * small length lookup table for all radiotap types we heard of 1108 * small length lookup table for all radiotap types we heard of
@@ -1156,105 +1138,105 @@ ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterat
1156 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22, 1138 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
1157 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11, 1139 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
1158 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11 1140 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
1159 /* 1141 /*
1160 * add more here as they are defined in 1142 * add more here as they are defined in
1161 * include/net/ieee80211_radiotap.h 1143 * include/net/ieee80211_radiotap.h
1162 */ 1144 */
1163 }; 1145 };
1164 1146
1165 /* 1147 /*
1166 * for every radiotap entry we can at 1148 * for every radiotap entry we can at
1167 * least skip (by knowing the length)... 1149 * least skip (by knowing the length)...
1168 */ 1150 */
1169 while (iterator->arg_index < sizeof (rt_sizes)) 1151 while (iterator->arg_index < sizeof(rt_sizes))
1170 {
1171 int hit = (0 != (iterator->bitmap_shifter & 1));
1172
1173 if (hit)
1174 { 1152 {
1175 unsigned int wanted_alignment; 1153 int hit = (0 != (iterator->bitmap_shifter & 1));
1176 unsigned int unalignment; 1154
1177 /* 1155 if (hit)
1178 * arg is present, account for alignment padding 1156 {
1179 * 8-bit args can be at any alignment 1157 unsigned int wanted_alignment;
1180 * 16-bit args must start on 16-bit boundary 1158 unsigned int unalignment;
1181 * 32-bit args must start on 32-bit boundary 1159 /*
1182 * 64-bit args must start on 64-bit boundary 1160 * arg is present, account for alignment padding
1183 * 1161 * 8-bit args can be at any alignment
1184 * note that total arg size can differ from alignment of 1162 * 16-bit args must start on 16-bit boundary
1185 * elements inside arg, so we use upper nybble of length table 1163 * 32-bit args must start on 32-bit boundary
1186 * to base alignment on. First, 'wanted_alignment' is set to be 1164 * 64-bit args must start on 64-bit boundary
1187 * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit 1165 *
1188 * arguments. Then, we calculate the 'unalignment' (how many 1166 * note that total arg size can differ from alignment of
1189 * bytes we are over by taking the difference of 'arg' and the 1167 * elements inside arg, so we use upper nybble of length table
1190 * overall starting point modulo the desired alignment. As 1168 * to base alignment on. First, 'wanted_alignment' is set to be
1191 * desired alignments are powers of two, we can do modulo with 1169 * 1 for 8-bit, 2 for 16-bit, 4 for 32-bit and 8 for 64-bit
1192 * binary "&" (and also avoid the possibility of a division by 1170 * arguments. Then, we calculate the 'unalignment' (how many
1193 * zero if the 'rt_sizes' table contains bogus entries). 1171 * bytes we are over by taking the difference of 'arg' and the
1194 * 1172 * overall starting point modulo the desired alignment. As
1195 * also note: these alignments are relative to the start of the 1173 * desired alignments are powers of two, we can do modulo with
1196 * radiotap header. There is no guarantee that the radiotap 1174 * binary "&" (and also avoid the possibility of a division by
1197 * header itself is aligned on any kind of boundary, thus we 1175 * zero if the 'rt_sizes' table contains bogus entries).
1198 * need to really look at the delta here. 1176 *
1199 */ 1177 * also note: these alignments are relative to the start of the
1200 wanted_alignment = rt_sizes[iterator->arg_index] >> 4; 1178 * radiotap header. There is no guarantee that the radiotap
1201 unalignment = (((void *) iterator->arg) - ((void *) iterator->rtheader)) & (wanted_alignment - 1); 1179 * header itself is aligned on any kind of boundary, thus we
1202 if (0 != unalignment) 1180 * need to really look at the delta here.
1203 { 1181 */
1204 /* need padding (by 'wanted_alignment - unalignment') */ 1182 wanted_alignment = rt_sizes[iterator->arg_index] >> 4;
1205 iterator->arg_index += wanted_alignment - unalignment; 1183 unalignment = (((void *)iterator->arg) - ((void *)iterator->rtheader)) & (wanted_alignment - 1);
1206 } 1184 if (0 != unalignment)
1207 1185 {
1208 /* 1186 /* need padding (by 'wanted_alignment - unalignment') */
1209 * this is what we will return to user, but we need to 1187 iterator->arg_index += wanted_alignment - unalignment;
1210 * move on first so next call has something fresh to test 1188 }
1211 */ 1189
1212 iterator->this_arg_index = iterator->arg_index; 1190 /*
1213 iterator->this_arg = iterator->arg; 1191 * this is what we will return to user, but we need to
1214 1192 * move on first so next call has something fresh to test
1215 /* internally move on the size of this arg (using lower nybble from 1193 */
1216 the table) */ 1194 iterator->this_arg_index = iterator->arg_index;
1217 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; 1195 iterator->this_arg = iterator->arg;
1218 1196
1219 /* 1197 /* internally move on the size of this arg (using lower nybble from
1220 * check for insanity where we are given a bitmap that 1198 the table) */
1221 * claims to have more arg content than the length of the 1199 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
1222 * radiotap section. We will normally end up equalling this 1200
1223 * max_length on the last arg, never exceeding it. 1201 /*
1224 */ 1202 * check for insanity where we are given a bitmap that
1225 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) > iterator->max_length) 1203 * claims to have more arg content than the length of the
1226 return -1; 1204 * radiotap section. We will normally end up equalling this
1227 } 1205 * max_length on the last arg, never exceeding it.
1228 1206 */
1229 /* Now, move on to next bit / next entry */ 1207 if ((((void *)iterator->arg) - ((void *)iterator->rtheader)) > iterator->max_length)
1230 iterator->arg_index++; 1208 return -1;
1231 1209 }
1232 if (0 == (iterator->arg_index % 32)) 1210
1233 { 1211 /* Now, move on to next bit / next entry */
1234 /* completed current uint32_t bitmap */ 1212 iterator->arg_index++;
1235 if (0 != (iterator->bitmap_shifter & 1)) 1213
1236 { 1214 if (0 == (iterator->arg_index % 32))
1237 /* bit 31 was set, there is more; move to next uint32_t bitmap */ 1215 {
1238 iterator->bitmap_shifter = GNUNET_le32toh (*iterator->next_bitmap); 1216 /* completed current uint32_t bitmap */
1239 iterator->next_bitmap++; 1217 if (0 != (iterator->bitmap_shifter & 1))
1240 } 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 }
1241 else 1229 else
1242 { 1230 {
1243 /* no more bitmaps: end (by setting arg_index to high, unsupported value) */ 1231 /* just try the next bit (while loop will move on) */
1244 iterator->arg_index = sizeof (rt_sizes); 1232 iterator->bitmap_shifter >>= 1;
1245 } 1233 }
1246 } 1234
1247 else 1235 /* if we found a valid arg earlier, return it now */
1248 { 1236 if (hit)
1249 /* just try the next bit (while loop will move on) */ 1237 return iterator->this_arg_index;
1250 iterator->bitmap_shifter >>= 1;
1251 } 1238 }
1252 1239
1253 /* if we found a valid arg earlier, return it now */
1254 if (hit)
1255 return iterator->this_arg_index;
1256 }
1257
1258 /* we don't know how to handle any more args (or there are no more), 1240 /* we don't know how to handle any more args (or there are no more),
1259 so we're done (this is not an error) */ 1241 so we're done (this is not an error) */
1260 return -1; 1242 return -1;
@@ -1269,7 +1251,7 @@ ieee80211_radiotap_iterator_next (struct Ieee80211RadiotapHeaderIterator *iterat
1269 * @return crc sum 1251 * @return crc sum
1270 */ 1252 */
1271static unsigned long 1253static unsigned long
1272calc_crc_osdep (const unsigned char *buf, size_t len) 1254calc_crc_osdep(const unsigned char *buf, size_t len)
1273{ 1255{
1274 static const unsigned long int crc_tbl_osdep[256] = { 1256 static const unsigned long int crc_tbl_osdep[256] = {
1275 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 1257 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
@@ -1342,7 +1324,7 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
1342 1324
1343 for (; len > 0; len--, buf++) 1325 for (; len > 0; len--, buf++)
1344 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8); 1326 crc = crc_tbl_osdep[(crc ^ *buf) & 0xFF] ^ (crc >> 8);
1345 return (~crc); 1327 return(~crc);
1346} 1328}
1347 1329
1348 1330
@@ -1355,11 +1337,11 @@ calc_crc_osdep (const unsigned char *buf, size_t len)
1355 * @return 0 on success (checksum matches), 1 on error 1337 * @return 0 on success (checksum matches), 1 on error
1356 */ 1338 */
1357static int 1339static int
1358check_crc_buf_osdep (const unsigned char *buf, size_t len) 1340check_crc_buf_osdep(const unsigned char *buf, size_t len)
1359{ 1341{
1360 unsigned long crc; 1342 unsigned long crc;
1361 1343
1362 crc = calc_crc_osdep (buf, len); 1344 crc = calc_crc_osdep(buf, len);
1363 buf += len; 1345 buf += len;
1364 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && 1346 if (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] &&
1365 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]) 1347 ((crc >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3])
@@ -1380,7 +1362,7 @@ check_crc_buf_osdep (const unsigned char *buf, size_t len)
1380 * @return number of the channel 1362 * @return number of the channel
1381 */ 1363 */
1382static int 1364static int
1383get_channel_from_frequency (int32_t frequency) 1365get_channel_from_frequency(int32_t frequency)
1384{ 1366{
1385 if (frequency >= 2412 && frequency <= 2472) 1367 if (frequency >= 2412 && frequency <= 2472)
1386 return (frequency - 2407) / 5; 1368 return (frequency - 2407) / 5;
@@ -1399,14 +1381,14 @@ get_channel_from_frequency (int32_t frequency)
1399 * @return channel number, -1 on error 1381 * @return channel number, -1 on error
1400 */ 1382 */
1401static int 1383static int
1402linux_get_channel (const struct HardwareInfos *dev) 1384linux_get_channel(const struct HardwareInfos *dev)
1403{ 1385{
1404 struct iwreq wrq; 1386 struct iwreq wrq;
1405 int32_t frequency; 1387 int32_t frequency;
1406 1388
1407 memset (&wrq, 0, sizeof (struct iwreq)); 1389 memset(&wrq, 0, sizeof(struct iwreq));
1408 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); 1390 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ);
1409 if (0 > ioctl (dev->fd_raw, SIOCGIWFREQ, &wrq)) 1391 if (0 > ioctl(dev->fd_raw, SIOCGIWFREQ, &wrq))
1410 return -1; 1392 return -1;
1411 frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */ 1393 frequency = wrq.u.freq.m; /* 'iw_freq' defines 'm' as '__s32', so we keep it signed */
1412 if (100000000 < frequency) 1394 if (100000000 < frequency)
@@ -1414,7 +1396,7 @@ linux_get_channel (const struct HardwareInfos *dev)
1414 else if (1000000 < frequency) 1396 else if (1000000 < frequency)
1415 frequency /= 1000; 1397 frequency /= 1000;
1416 if (1000 < frequency) 1398 if (1000 < frequency)
1417 return get_channel_from_frequency (frequency); 1399 return get_channel_from_frequency(frequency);
1418 return frequency; 1400 return frequency;
1419} 1401}
1420 1402
@@ -1431,9 +1413,9 @@ linux_get_channel (const struct HardwareInfos *dev)
1431 * @return number of bytes written to 'buf' 1413 * @return number of bytes written to 'buf'
1432 */ 1414 */
1433static ssize_t 1415static ssize_t
1434linux_read (struct HardwareInfos *dev, 1416linux_read(struct HardwareInfos *dev,
1435 unsigned char *buf, size_t buf_size, 1417 unsigned char *buf, size_t buf_size,
1436 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri) 1418 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *ri)
1437{ 1419{
1438 unsigned char tmpbuf[buf_size]; 1420 unsigned char tmpbuf[buf_size];
1439 ssize_t caplen; 1421 ssize_t caplen;
@@ -1443,190 +1425,207 @@ linux_read (struct HardwareInfos *dev,
1443 int got_channel = 0; 1425 int got_channel = 0;
1444 int fcs_removed = 0; 1426 int fcs_removed = 0;
1445 1427
1446 caplen = read (dev->fd_raw, tmpbuf, buf_size); 1428 caplen = read(dev->fd_raw, tmpbuf, buf_size);
1447 if (0 > caplen) 1429 if (0 > caplen)
1448 { 1430 {
1449 if (EAGAIN == errno) 1431 if (EAGAIN == errno)
1450 return 0; 1432 return 0;
1451 fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno)); 1433 fprintf(stderr, "Failed to read from RAW socket: %s\n", strerror(errno));
1452 return -1; 1434 return -1;
1453 } 1435 }
1454 1436
1455 memset (ri, 0, sizeof (*ri)); 1437 memset(ri, 0, sizeof(*ri));
1456 switch (dev->arptype_in) 1438 switch (dev->arptype_in)
1457 { 1439 {
1458 case ARPHRD_IEEE80211_PRISM: 1440 case ARPHRD_IEEE80211_PRISM:
1459 { 1441 {
1460 const struct PrismHeader *ph; 1442 const struct PrismHeader *ph;
1461 1443
1462 ph = (const struct PrismHeader*) tmpbuf; 1444 ph = (const struct PrismHeader*)tmpbuf;
1463 n = ph->msglen; 1445 n = ph->msglen;
1464 if ( (n < 8) || (n >= caplen) ) 1446 if ((n < 8) || (n >= caplen))
1465 return 0; /* invalid format */ 1447 return 0; /* invalid format */
1466 if ( (PRISM_MSGCODE_MONITOR == ph->msgcode) && 1448 if ((PRISM_MSGCODE_MONITOR == ph->msgcode) &&
1467 (n >= sizeof (struct PrismHeader)) ) 1449 (n >= sizeof(struct PrismHeader)))
1468 { 1450 {
1469 const char *pos; 1451 const char *pos;
1470 size_t left; 1452 size_t left;
1471 struct PrismValue pv; 1453 struct PrismValue pv;
1472 1454
1473 left = n - sizeof (struct PrismHeader); 1455 left = n - sizeof(struct PrismHeader);
1474 pos = (const char *) &ph[1]; 1456 pos = (const char *)&ph[1];
1475 while (left > sizeof (struct PrismValue)) 1457 while (left > sizeof(struct PrismValue))
1476 { 1458 {
1477 left -= sizeof (struct PrismValue); 1459 left -= sizeof(struct PrismValue);
1478 GNUNET_memcpy (&pv, pos, sizeof (struct PrismValue)); 1460 GNUNET_memcpy(&pv, pos, sizeof(struct PrismValue));
1479 pos += sizeof (struct PrismValue); 1461 pos += sizeof(struct PrismValue);
1480 1462
1481 switch (pv.did) 1463 switch (pv.did)
1482 { 1464 {
1483 case PRISM_DID_NOISE: 1465 case PRISM_DID_NOISE:
1484 if (PRISM_STATUS_OK == pv.status) 1466 if (PRISM_STATUS_OK == pv.status)
1485 { 1467 {
1486 ri->ri_noise = pv.data; 1468 ri->ri_noise = pv.data;
1487 /* got_noise = 1; */ 1469 /* got_noise = 1; */
1488 } 1470 }
1489 break; 1471 break;
1490 case PRISM_DID_RATE: 1472
1491 if (PRISM_STATUS_OK == pv.status) 1473 case PRISM_DID_RATE:
1492 ri->ri_rate = pv.data * 500000; 1474 if (PRISM_STATUS_OK == pv.status)
1493 break; 1475 ri->ri_rate = pv.data * 500000;
1494 case PRISM_DID_CHANNEL: 1476 break;
1495 if (PRISM_STATUS_OK == pv.status) 1477
1496 { 1478 case PRISM_DID_CHANNEL:
1497 ri->ri_channel = pv.data; 1479 if (PRISM_STATUS_OK == pv.status)
1498 got_channel = 1; 1480 {
1499 } 1481 ri->ri_channel = pv.data;
1500 break; 1482 got_channel = 1;
1501 case PRISM_DID_MACTIME: 1483 }
1502 if (PRISM_STATUS_OK == pv.status) 1484 break;
1503 ri->ri_mactime = pv.data; 1485
1504 break; 1486 case PRISM_DID_MACTIME:
1505 case PRISM_DID_SIGNAL: 1487 if (PRISM_STATUS_OK == pv.status)
1506 if (PRISM_STATUS_OK == pv.status) 1488 ri->ri_mactime = pv.data;
1507 { 1489 break;
1508 ri->ri_power = pv.data; 1490
1509 /* got_signal = 1; */ 1491 case PRISM_DID_SIGNAL:
1510 } 1492 if (PRISM_STATUS_OK == pv.status)
1511 break; 1493 {
1512 } 1494 ri->ri_power = pv.data;
1513 } 1495 /* got_signal = 1; */
1514 } 1496 }
1515 if ( (n < 8) || (n >= caplen) ) 1497 break;
1516 return 0; /* invalid format */ 1498 }
1499 }
1500 }
1501 if ((n < 8) || (n >= caplen))
1502 return 0; /* invalid format */
1517 } 1503 }
1518 break; 1504 break;
1519 case ARPHRD_IEEE80211_FULL: 1505
1506 case ARPHRD_IEEE80211_FULL:
1520 { 1507 {
1521 struct Ieee80211RadiotapHeaderIterator iterator; 1508 struct Ieee80211RadiotapHeaderIterator iterator;
1522 struct Ieee80211RadiotapHeader *rthdr; 1509 struct Ieee80211RadiotapHeader *rthdr;
1523 1510
1524 memset (&iterator, 0, sizeof (iterator)); 1511 memset(&iterator, 0, sizeof(iterator));
1525 rthdr = (struct Ieee80211RadiotapHeader *) tmpbuf; 1512 rthdr = (struct Ieee80211RadiotapHeader *)tmpbuf;
1526 n = GNUNET_le16toh (rthdr->it_len); 1513 n = GNUNET_le16toh(rthdr->it_len);
1527 if ( (n < sizeof (struct Ieee80211RadiotapHeader)) || (n >= caplen)) 1514 if ((n < sizeof(struct Ieee80211RadiotapHeader)) || (n >= caplen))
1528 return 0; /* invalid 'it_len' */ 1515 return 0; /* invalid 'it_len' */
1529 if (0 != ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen)) 1516 if (0 != ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen))
1530 return 0; 1517 return 0;
1531 /* go through the radiotap arguments we have been given by the driver */ 1518 /* go through the radiotap arguments we have been given by the driver */
1532 while (0 <= ieee80211_radiotap_iterator_next (&iterator)) 1519 while (0 <= ieee80211_radiotap_iterator_next(&iterator))
1533 { 1520 {
1534 switch (iterator.this_arg_index) 1521 switch (iterator.this_arg_index)
1535 { 1522 {
1536 case IEEE80211_RADIOTAP_TSFT: 1523 case IEEE80211_RADIOTAP_TSFT:
1537 ri->ri_mactime = GNUNET_le64toh (*((uint64_t *) iterator.this_arg)); 1524 ri->ri_mactime = GNUNET_le64toh(*((uint64_t *)iterator.this_arg));
1538 break; 1525 break;
1539 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: 1526
1540 if (!got_signal) 1527 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
1541 { 1528 if (!got_signal)
1542 ri->ri_power = * ((int8_t*) iterator.this_arg); 1529 {
1543 got_signal = 1; 1530 ri->ri_power = *((int8_t*)iterator.this_arg);
1544 } 1531 got_signal = 1;
1545 break; 1532 }
1546 case IEEE80211_RADIOTAP_DB_ANTSIGNAL: 1533 break;
1547 if (!got_signal) 1534
1548 { 1535 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
1549 ri->ri_power = * ((int8_t*) iterator.this_arg); 1536 if (!got_signal)
1550 got_signal = 1; 1537 {
1551 } 1538 ri->ri_power = *((int8_t*)iterator.this_arg);
1552 break; 1539 got_signal = 1;
1553 case IEEE80211_RADIOTAP_DBM_ANTNOISE: 1540 }
1554 if (!got_noise) 1541 break;
1555 { 1542
1556 ri->ri_noise = * ((int8_t*) iterator.this_arg); 1543 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
1557 got_noise = 1; 1544 if (!got_noise)
1558 } 1545 {
1559 break; 1546 ri->ri_noise = *((int8_t*)iterator.this_arg);
1560 case IEEE80211_RADIOTAP_DB_ANTNOISE: 1547 got_noise = 1;
1561 if (!got_noise) 1548 }
1562 { 1549 break;
1563 ri->ri_noise = * ((int8_t*) iterator.this_arg); 1550
1564 got_noise = 1; 1551 case IEEE80211_RADIOTAP_DB_ANTNOISE:
1565 } 1552 if (!got_noise)
1566 break; 1553 {
1567 case IEEE80211_RADIOTAP_ANTENNA: 1554 ri->ri_noise = *((int8_t*)iterator.this_arg);
1568 ri->ri_antenna = *iterator.this_arg; 1555 got_noise = 1;
1569 break; 1556 }
1570 case IEEE80211_RADIOTAP_CHANNEL: 1557 break;
1571 ri->ri_channel = *iterator.this_arg; 1558
1572 got_channel = 1; 1559 case IEEE80211_RADIOTAP_ANTENNA:
1573 break; 1560 ri->ri_antenna = *iterator.this_arg;
1574 case IEEE80211_RADIOTAP_RATE: 1561 break;
1575 ri->ri_rate = (*iterator.this_arg) * 500000; 1562
1576 break; 1563 case IEEE80211_RADIOTAP_CHANNEL:
1577 case IEEE80211_RADIOTAP_FLAGS: 1564 ri->ri_channel = *iterator.this_arg;
1578 { 1565 got_channel = 1;
1579 uint8_t flags = *iterator.this_arg; 1566 break;
1580 /* is the CRC visible at the end? if so, remove */ 1567
1581 if (0 != (flags & IEEE80211_RADIOTAP_F_FCS)) 1568 case IEEE80211_RADIOTAP_RATE:
1582 { 1569 ri->ri_rate = (*iterator.this_arg) * 500000;
1583 fcs_removed = 1; 1570 break;
1584 caplen -= sizeof (uint32_t); 1571
1585 } 1572 case IEEE80211_RADIOTAP_FLAGS:
1586 break; 1573 {
1587 } 1574 uint8_t flags = *iterator.this_arg;
1588 case IEEE80211_RADIOTAP_RX_FLAGS: 1575 /* is the CRC visible at the end? if so, remove */
1589 { 1576 if (0 != (flags & IEEE80211_RADIOTAP_F_FCS))
1590 uint16_t flags = ntohs (* ((uint16_t *) iterator.this_arg)); 1577 {
1591 if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS)) 1578 fcs_removed = 1;
1592 return 0; 1579 caplen -= sizeof(uint32_t);
1593 } 1580 }
1594 break; 1581 break;
1595 } /* end of 'switch' */ 1582 }
1596 } /* end of the 'while' loop */ 1583
1584 case IEEE80211_RADIOTAP_RX_FLAGS:
1585 {
1586 uint16_t flags = ntohs(*((uint16_t *)iterator.this_arg));
1587 if (0 != (flags & IEEE80211_RADIOTAP_F_RX_BADFCS))
1588 return 0;
1589 }
1590 break;
1591 } /* end of 'switch' */
1592 } /* end of the 'while' loop */
1597 } 1593 }
1598 break; 1594 break;
1599 case ARPHRD_IEEE80211: 1595
1600 n = 0; /* no header */ 1596 case ARPHRD_IEEE80211:
1601 break; 1597 n = 0; /* no header */
1602 case ARPHRD_ETHER: 1598 break;
1599
1600 case ARPHRD_ETHER:
1603 { 1601 {
1604 if (sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen) 1602 if (sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) > caplen)
1605 return 0; /* invalid */ 1603 return 0; /* invalid */
1606 GNUNET_memcpy (&buf[sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)], 1604 GNUNET_memcpy(&buf[sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)],
1607 tmpbuf + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame), 1605 tmpbuf + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame),
1608 caplen - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4 /* 4 byte FCS */); 1606 caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4 /* 4 byte FCS */);
1609 return caplen - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4; 1607 return caplen - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame) - 4;
1610 } 1608 }
1611 default: 1609
1612 errno = ENOTSUP; /* unsupported format */ 1610 default:
1613 return -1; 1611 errno = ENOTSUP; /* unsupported format */
1614 } 1612 return -1;
1613 }
1615 caplen -= n; 1614 caplen -= n;
1616 if (! got_channel) 1615 if (!got_channel)
1617 ri->ri_channel = linux_get_channel (dev); 1616 ri->ri_channel = linux_get_channel(dev);
1618 1617
1619 /* detect CRC32 at the end, even if the flag wasn't set and remove it */ 1618 /* detect CRC32 at the end, even if the flag wasn't set and remove it */
1620 if ( (0 == fcs_removed) && 1619 if ((0 == fcs_removed) &&
1621 (0 == check_crc_buf_osdep (tmpbuf + n, caplen - sizeof (uint32_t))) ) 1620 (0 == check_crc_buf_osdep(tmpbuf + n, caplen - sizeof(uint32_t))))
1622 { 1621 {
1623 /* NOTE: this heuristic can of course fail if there happens to 1622 /* NOTE: this heuristic can of course fail if there happens to
1624 be a matching checksum at the end. Would be good to have 1623 be a matching checksum at the end. Would be good to have
1625 some data to see how often this heuristic actually works. */ 1624 some data to see how often this heuristic actually works. */
1626 caplen -= sizeof (uint32_t); 1625 caplen -= sizeof(uint32_t);
1627 } 1626 }
1628 /* copy payload to target buffer */ 1627 /* copy payload to target buffer */
1629 GNUNET_memcpy (buf, tmpbuf + n, caplen); 1628 GNUNET_memcpy(buf, tmpbuf + n, caplen);
1630 return caplen; 1629 return caplen;
1631} 1630}
1632 1631
@@ -1643,7 +1642,7 @@ linux_read (struct HardwareInfos *dev,
1643 * @return 0 on success 1642 * @return 0 on success
1644 */ 1643 */
1645static int 1644static int
1646open_device_raw (struct HardwareInfos *dev) 1645open_device_raw(struct HardwareInfos *dev)
1647{ 1646{
1648 struct ifreq ifr; 1647 struct ifreq ifr;
1649 struct iwreq wrq; 1648 struct iwreq wrq;
@@ -1651,112 +1650,112 @@ open_device_raw (struct HardwareInfos *dev)
1651 struct sockaddr_ll sll; 1650 struct sockaddr_ll sll;
1652 1651
1653 /* find the interface index */ 1652 /* find the interface index */
1654 memset (&ifr, 0, sizeof (ifr)); 1653 memset(&ifr, 0, sizeof(ifr));
1655 strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ); 1654 strncpy(ifr.ifr_name, dev->iface, IFNAMSIZ);
1656 if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr)) 1655 if (-1 == ioctl(dev->fd_raw, SIOCGIFINDEX, &ifr))
1657 { 1656 {
1658 fprintf (stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", 1657 fprintf(stderr, "ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
1659 IFNAMSIZ, dev->iface, strerror (errno)); 1658 IFNAMSIZ, dev->iface, strerror(errno));
1660 return 1; 1659 return 1;
1661 } 1660 }
1662 1661
1663 /* lookup the hardware type */ 1662 /* lookup the hardware type */
1664 memset (&sll, 0, sizeof (sll)); 1663 memset(&sll, 0, sizeof(sll));
1665 sll.sll_family = AF_PACKET; 1664 sll.sll_family = AF_PACKET;
1666 sll.sll_ifindex = ifr.ifr_ifindex; 1665 sll.sll_ifindex = ifr.ifr_ifindex;
1667 sll.sll_protocol = htons (ETH_P_ALL); 1666 sll.sll_protocol = htons(ETH_P_ALL);
1668 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) 1667 if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr))
1669 { 1668 {
1670 fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", 1669 fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
1671 IFNAMSIZ, dev->iface, strerror (errno)); 1670 IFNAMSIZ, dev->iface, strerror(errno));
1672 return 1; 1671 return 1;
1673 } 1672 }
1674 if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && 1673 if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
1675 (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) && 1674 (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
1676 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 1675 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
1677 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) ) 1676 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)))
1678 { 1677 {
1679 fprintf (stderr, "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n", 1678 fprintf(stderr, "Error: interface `%.*s' is not using a supported hardware address family (got %d)\n",
1680 IFNAMSIZ, dev->iface, 1679 IFNAMSIZ, dev->iface,
1681 ifr.ifr_hwaddr.sa_family); 1680 ifr.ifr_hwaddr.sa_family);
1682 return 1; 1681 return 1;
1683 } 1682 }
1684 1683
1685 /* lookup iw mode */ 1684 /* lookup iw mode */
1686 memset (&wrq, 0, sizeof (struct iwreq)); 1685 memset(&wrq, 0, sizeof(struct iwreq));
1687 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ); 1686 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ);
1688 if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq)) 1687 if (-1 == ioctl(dev->fd_raw, SIOCGIWMODE, &wrq))
1689 { 1688 {
1690 /* most probably not supported (ie for rtap ipw interface) * 1689 /* most probably not supported (ie for rtap ipw interface) *
1691 * so just assume its correctly set... */ 1690 * so just assume its correctly set... */
1692 wrq.u.mode = IW_MODE_MONITOR; 1691 wrq.u.mode = IW_MODE_MONITOR;
1693 } 1692 }
1694 1693
1695 if ( (wrq.u.mode != IW_MODE_MONITOR) && 1694 if ((wrq.u.mode != IW_MODE_MONITOR) &&
1696 (wrq.u.mode != IW_MODE_ADHOC) ) 1695 (wrq.u.mode != IW_MODE_ADHOC))
1697 { 1696 {
1698 fprintf (stderr, "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n", 1697 fprintf(stderr, "Error: interface `%.*s' is not in monitor or ad-hoc mode (got %d)\n",
1699 IFNAMSIZ, dev->iface, 1698 IFNAMSIZ, dev->iface,
1700 wrq.u.mode); 1699 wrq.u.mode);
1701 return 1; 1700 return 1;
1702 } 1701 }
1703 1702
1704 /* Is interface st to up, broadcast & running ? */ 1703 /* Is interface st to up, broadcast & running ? */
1705 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) 1704 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
1706 {
1707 /* Bring interface up */
1708 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
1709
1710 if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
1711 { 1705 {
1712 fprintf (stderr, "ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n", 1706 /* Bring interface up */
1713 IFNAMSIZ, dev->iface, strerror (errno)); 1707 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
1714 return 1; 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 } 1715 }
1716 }
1717 1716
1718 /* bind the raw socket to the interface */ 1717 /* bind the raw socket to the interface */
1719 if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll))) 1718 if (-1 == bind(dev->fd_raw, (struct sockaddr *)&sll, sizeof(sll)))
1720 { 1719 {
1721 fprintf (stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ, 1720 fprintf(stderr, "Failed to bind interface `%.*s': %s\n", IFNAMSIZ,
1722 dev->iface, strerror (errno)); 1721 dev->iface, strerror(errno));
1723 return 1; 1722 return 1;
1724 } 1723 }
1725 1724
1726 /* lookup the hardware type */ 1725 /* lookup the hardware type */
1727 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr)) 1726 if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr))
1728 { 1727 {
1729 fprintf (stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", 1728 fprintf(stderr, "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
1730 IFNAMSIZ, dev->iface, strerror (errno)); 1729 IFNAMSIZ, dev->iface, strerror(errno));
1731 return 1; 1730 return 1;
1732 } 1731 }
1733 1732
1734 GNUNET_memcpy (&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE); 1733 GNUNET_memcpy(&dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
1735 dev->arptype_in = ifr.ifr_hwaddr.sa_family; 1734 dev->arptype_in = ifr.ifr_hwaddr.sa_family;
1736 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) && 1735 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) &&
1737 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && 1736 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
1738 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 1737 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
1739 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) 1738 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
1740 { 1739 {
1741 fprintf (stderr, "Unsupported hardware link type %d on interface `%.*s'\n", 1740 fprintf(stderr, "Unsupported hardware link type %d on interface `%.*s'\n",
1742 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface); 1741 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
1743 return 1; 1742 return 1;
1744 } 1743 }
1745 1744
1746 /* enable promiscuous mode */ 1745 /* enable promiscuous mode */
1747 memset (&mr, 0, sizeof (mr)); 1746 memset(&mr, 0, sizeof(mr));
1748 mr.mr_ifindex = sll.sll_ifindex; 1747 mr.mr_ifindex = sll.sll_ifindex;
1749 mr.mr_type = PACKET_MR_PROMISC; 1748 mr.mr_type = PACKET_MR_PROMISC;
1750 if (0 != 1749 if (0 !=
1751 setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, 1750 setsockopt(dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
1752 sizeof (mr))) 1751 sizeof(mr)))
1753 { 1752 {
1754 fprintf (stderr, 1753 fprintf(stderr,
1755 "Failed to enable promiscuous mode on interface `%.*s'\n", 1754 "Failed to enable promiscuous mode on interface `%.*s'\n",
1756 IFNAMSIZ, 1755 IFNAMSIZ,
1757 dev->iface); 1756 dev->iface);
1758 return 1; 1757 return 1;
1759 } 1758 }
1760 return 0; 1759 return 0;
1761} 1760}
1762 1761
@@ -1769,22 +1768,22 @@ open_device_raw (struct HardwareInfos *dev)
1769 * @return 0 on success, 1 on error 1768 * @return 0 on success, 1 on error
1770 */ 1769 */
1771static int 1770static int
1772test_wlan_interface (const char *iface) 1771test_wlan_interface(const char *iface)
1773{ 1772{
1774 char strbuf[512]; 1773 char strbuf[512];
1775 struct stat sbuf; 1774 struct stat sbuf;
1776 int ret; 1775 int ret;
1777 1776
1778 ret = snprintf (strbuf, sizeof (strbuf), 1777 ret = snprintf(strbuf, sizeof(strbuf),
1779 "/sys/class/net/%s/phy80211/subsystem", 1778 "/sys/class/net/%s/phy80211/subsystem",
1780 iface); 1779 iface);
1781 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf))) 1780 if ((ret < 0) || (ret >= sizeof(strbuf)) || (0 != stat(strbuf, &sbuf)))
1782 { 1781 {
1783 fprintf (stderr, 1782 fprintf(stderr,
1784 "Did not find 802.11 interface `%s'. Exiting.\n", 1783 "Did not find 802.11 interface `%s'. Exiting.\n",
1785 iface); 1784 iface);
1786 exit (1); 1785 exit(1);
1787 } 1786 }
1788 return 0; 1787 return 0;
1789} 1788}
1790 1789
@@ -1797,19 +1796,19 @@ test_wlan_interface (const char *iface)
1797 * @return 0 if mac belongs to us, 1 if mac is for another target 1796 * @return 0 if mac belongs to us, 1 if mac is for another target
1798 */ 1797 */
1799static int 1798static int
1800mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1799mac_test(const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1801 const struct HardwareInfos *dev) 1800 const struct HardwareInfos *dev)
1802{ 1801{
1803 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros; 1802 static struct GNUNET_TRANSPORT_WLAN_MacAddress all_zeros;
1804 1803
1805 if ( (0 == memcmp (&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) || 1804 if ((0 == memcmp(&taIeeeHeader->addr3, &all_zeros, MAC_ADDR_SIZE)) ||
1806 (0 == memcmp (&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)) ) 1805 (0 == memcmp(&taIeeeHeader->addr1, &all_zeros, MAC_ADDR_SIZE)))
1807 return 0; /* some drivers set no Macs, then assume it is all for us! */ 1806 return 0; /* some drivers set no Macs, then assume it is all for us! */
1808 1807
1809 if (0 != memcmp (&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE)) 1808 if (0 != memcmp(&taIeeeHeader->addr3, &mac_bssid_gnunet, MAC_ADDR_SIZE))
1810 return 1; /* not a GNUnet ad-hoc package */ 1809 return 1; /* not a GNUnet ad-hoc package */
1811 if ( (0 == memcmp (&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) || 1810 if ((0 == memcmp(&taIeeeHeader->addr1, &dev->pl_mac, MAC_ADDR_SIZE)) ||
1812 (0 == memcmp (&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)) ) 1811 (0 == memcmp(&taIeeeHeader->addr1, &bc_all_mac, MAC_ADDR_SIZE)))
1813 return 0; /* for us, or broadcast */ 1812 return 0; /* for us, or broadcast */
1814 return 1; /* not for us */ 1813 return 1; /* not for us */
1815} 1814}
@@ -1822,10 +1821,10 @@ mac_test (const struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1822 * @param dev pointer to the Hardware_Infos struct 1821 * @param dev pointer to the Hardware_Infos struct
1823 */ 1822 */
1824static void 1823static void
1825mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader, 1824mac_set(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1826 const struct HardwareInfos *dev) 1825 const struct HardwareInfos *dev)
1827{ 1826{
1828 taIeeeHeader->frame_control = htons (IEEE80211_FC0_TYPE_DATA); 1827 taIeeeHeader->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
1829 taIeeeHeader->addr2 = dev->pl_mac; 1828 taIeeeHeader->addr2 = dev->pl_mac;
1830 taIeeeHeader->addr3 = mac_bssid_gnunet; 1829 taIeeeHeader->addr3 = mac_bssid_gnunet;
1831} 1830}
@@ -1840,7 +1839,7 @@ mac_set (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *taIeeeHeader,
1840 * @param hdr pointer to the start of the packet 1839 * @param hdr pointer to the start of the packet
1841 */ 1840 */
1842static void 1841static void
1843stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr) 1842stdin_send_hw(void *cls, const struct GNUNET_MessageHeader *hdr)
1844{ 1843{
1845 struct HardwareInfos *dev = cls; 1844 struct HardwareInfos *dev = cls;
1846 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header; 1845 const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header;
@@ -1849,56 +1848,58 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1849 struct RadiotapTransmissionHeader rtheader; 1848 struct RadiotapTransmissionHeader rtheader;
1850 struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader; 1849 struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame etheader;
1851 1850
1852 sendsize = ntohs (hdr->size); 1851 sendsize = ntohs(hdr->size);
1853 if ( (sendsize < 1852 if ((sendsize <
1854 sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) || 1853 sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage)) ||
1855 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) ) 1854 (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs(hdr->type)))
1856 { 1855 {
1857 fprintf (stderr, "Received malformed message\n"); 1856 fprintf(stderr, "Received malformed message\n");
1858 exit (1); 1857 exit(1);
1859 } 1858 }
1860 sendsize -= (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); 1859 sendsize -= (sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1861 if (MAXLINE < sendsize) 1860 if (MAXLINE < sendsize)
1862 { 1861 {
1863 fprintf (stderr, "Packet too big for buffer\n"); 1862 fprintf(stderr, "Packet too big for buffer\n");
1864 exit (1); 1863 exit(1);
1865 } 1864 }
1866 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) hdr; 1865 header = (const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)hdr;
1867 switch (dev->arptype_in) 1866 switch (dev->arptype_in)
1868 { 1867 {
1869 case ARPHRD_IEEE80211_PRISM: 1868 case ARPHRD_IEEE80211_PRISM:
1870 case ARPHRD_IEEE80211_FULL: 1869 case ARPHRD_IEEE80211_FULL:
1871 case ARPHRD_IEEE80211: 1870 case ARPHRD_IEEE80211:
1872 rtheader.header.it_version = 0; 1871 rtheader.header.it_version = 0;
1873 rtheader.header.it_pad = 0; 1872 rtheader.header.it_pad = 0;
1874 rtheader.header.it_len = GNUNET_htole16 (sizeof (rtheader)); 1873 rtheader.header.it_len = GNUNET_htole16(sizeof(rtheader));
1875 rtheader.header.it_present = GNUNET_htole16 (IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK); 1874 rtheader.header.it_present = GNUNET_htole16(IEEE80211_RADIOTAP_OUR_TRANSMISSION_HEADER_MASK);
1876 rtheader.rate = header->rate; 1875 rtheader.rate = header->rate;
1877 rtheader.pad1 = 0; 1876 rtheader.pad1 = 0;
1878 rtheader.txflags = GNUNET_htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); 1877 rtheader.txflags = GNUNET_htole16(IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
1879 GNUNET_memcpy (write_pout.buf, &rtheader, sizeof (rtheader)); 1878 GNUNET_memcpy(write_pout.buf, &rtheader, sizeof(rtheader));
1880 GNUNET_memcpy (&write_pout.buf[sizeof (rtheader)], &header->frame, sendsize); 1879 GNUNET_memcpy(&write_pout.buf[sizeof(rtheader)], &header->frame, sendsize);
1881 wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *) &write_pout.buf[sizeof (rtheader)]; 1880 wlanheader = (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *)&write_pout.buf[sizeof(rtheader)];
1882 1881
1883 /* payload contains MAC address, but we don't trust it, so we'll 1882 /* payload contains MAC address, but we don't trust it, so we'll
1884 * overwrite it with OUR MAC address to prevent mischief */ 1883 * overwrite it with OUR MAC address to prevent mischief */
1885 mac_set (wlanheader, dev); 1884 mac_set(wlanheader, dev);
1886 write_pout.size = sendsize + sizeof (rtheader); 1885 write_pout.size = sendsize + sizeof(rtheader);
1887 break; 1886 break;
1888 case ARPHRD_ETHER: 1887
1889 etheader.dst = header->frame.addr1; 1888 case ARPHRD_ETHER:
1890 /* etheader.src = header->frame.addr2; --- untrusted input */ 1889 etheader.dst = header->frame.addr1;
1891 etheader.src = dev->pl_mac; 1890 /* etheader.src = header->frame.addr2; --- untrusted input */
1892 etheader.type = htons (ETH_P_IP); 1891 etheader.src = dev->pl_mac;
1893 GNUNET_memcpy (write_pout.buf, &etheader, sizeof (etheader)); 1892 etheader.type = htons(ETH_P_IP);
1894 GNUNET_memcpy (&write_pout.buf[sizeof (etheader)], &header[1], sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame)); 1893 GNUNET_memcpy(write_pout.buf, &etheader, sizeof(etheader));
1895 write_pout.size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + sizeof (etheader); 1894 GNUNET_memcpy(&write_pout.buf[sizeof(etheader)], &header[1], sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame));
1896 break; 1895 write_pout.size = sendsize - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame) + sizeof(etheader);
1897 default: 1896 break;
1898 fprintf (stderr, 1897
1899 "Unsupported ARPTYPE!\n"); 1898 default:
1900 break; 1899 fprintf(stderr,
1901 } 1900 "Unsupported ARPTYPE!\n");
1901 break;
1902 }
1902} 1903}
1903 1904
1904 1905
@@ -1913,7 +1914,7 @@ stdin_send_hw (void *cls, const struct GNUNET_MessageHeader *hdr)
1913 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error 1914 * @return 0 on success (never happens, as we don't return unless aborted), 1 on error
1914 */ 1915 */
1915int 1916int
1916main (int argc, char *argv[]) 1917main(int argc, char *argv[])
1917{ 1918{
1918 struct HardwareInfos dev; 1919 struct HardwareInfos dev;
1919 char readbuf[MAXLINE]; 1920 char readbuf[MAXLINE];
@@ -1927,83 +1928,83 @@ main (int argc, char *argv[])
1927 /* assert privs so we can modify the firewall rules! */ 1928 /* assert privs so we can modify the firewall rules! */
1928 { 1929 {
1929#ifdef HAVE_SETRESUID 1930#ifdef HAVE_SETRESUID
1930 uid_t uid = getuid (); 1931 uid_t uid = getuid();
1931 1932
1932 if (0 != setresuid (uid, 0, 0)) 1933 if (0 != setresuid(uid, 0, 0))
1933 { 1934 {
1934 fprintf (stderr, 1935 fprintf(stderr,
1935 "Failed to setresuid to root: %s\n", 1936 "Failed to setresuid to root: %s\n",
1936 strerror (errno)); 1937 strerror(errno));
1937 return 254; 1938 return 254;
1938 } 1939 }
1939#else 1940#else
1940 if (0 != seteuid (0)) 1941 if (0 != seteuid(0))
1941 { 1942 {
1942 fprintf (stderr, 1943 fprintf(stderr,
1943 "Failed to seteuid back to root: %s\n", strerror (errno)); 1944 "Failed to seteuid back to root: %s\n", strerror(errno));
1944 return 254; 1945 return 254;
1945 } 1946 }
1946#endif 1947#endif
1947 } 1948 }
1948 1949
1949 /* make use of SGID capabilities on POSIX */ 1950 /* make use of SGID capabilities on POSIX */
1950 memset (&dev, 0, sizeof (dev)); 1951 memset(&dev, 0, sizeof(dev));
1951 dev.fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL)); 1952 dev.fd_raw = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
1952 raw_eno = errno; /* remember for later */ 1953 raw_eno = errno; /* remember for later */
1953 1954
1954 /* now that we've dropped root rights, we can do error checking */ 1955 /* now that we've dropped root rights, we can do error checking */
1955 if (2 != argc) 1956 if (2 != argc)
1956 { 1957 {
1957 fprintf (stderr, 1958 fprintf(stderr,
1958 "You must specify the name of the interface as the first and only argument to this program.\n"); 1959 "You must specify the name of the interface as the first and only argument to this program.\n");
1959 if (-1 != dev.fd_raw) 1960 if (-1 != dev.fd_raw)
1960 (void) close (dev.fd_raw); 1961 (void)close(dev.fd_raw);
1961 return 1; 1962 return 1;
1962 } 1963 }
1963 1964
1964 if (-1 == dev.fd_raw) 1965 if (-1 == dev.fd_raw)
1965 { 1966 {
1966 fprintf (stderr, "Failed to create raw socket: %s\n", strerror (raw_eno)); 1967 fprintf(stderr, "Failed to create raw socket: %s\n", strerror(raw_eno));
1967 return 1; 1968 return 1;
1968 } 1969 }
1969 if (dev.fd_raw >= FD_SETSIZE) 1970 if (dev.fd_raw >= FD_SETSIZE)
1970 {
1971 fprintf (stderr, "File descriptor too large for select (%d > %d)\n",
1972 dev.fd_raw, FD_SETSIZE);
1973 (void) close (dev.fd_raw);
1974 return 1;
1975 }
1976 if (0 != test_wlan_interface (argv[1]))
1977 {
1978 (void) close (dev.fd_raw);
1979 return 1;
1980 }
1981 strncpy (dev.iface, argv[1], IFNAMSIZ);
1982 if (0 != open_device_raw (&dev))
1983 {
1984 (void) close (dev.fd_raw);
1985 return 1;
1986 }
1987
1988 /* drop privs */
1989 {
1990 uid_t uid = getuid ();
1991#ifdef HAVE_SETRESUID
1992 if (0 != setresuid (uid, uid, uid))
1993 { 1971 {
1994 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno)); 1972 fprintf(stderr, "File descriptor too large for select (%d > %d)\n",
1995 if (-1 != dev.fd_raw) 1973 dev.fd_raw, FD_SETSIZE);
1996 (void) close (dev.fd_raw); 1974 (void)close(dev.fd_raw);
1997 return 1; 1975 return 1;
1998 } 1976 }
1999#else 1977 if (0 != test_wlan_interface(argv[1]))
2000 if (0 != (setuid (uid) | seteuid (uid)))
2001 { 1978 {
2002 fprintf (stderr, "Failed to setuid: %s\n", strerror (errno)); 1979 (void)close(dev.fd_raw);
2003 if (-1 != dev.fd_raw)
2004 (void) close (dev.fd_raw);
2005 return 1; 1980 return 1;
2006 } 1981 }
1982 strncpy(dev.iface, argv[1], IFNAMSIZ);
1983 if (0 != open_device_raw(&dev))
1984 {
1985 (void)close(dev.fd_raw);
1986 return 1;
1987 }
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 }
2007#endif 2008#endif
2008 } 2009 }
2009 2010
@@ -2012,141 +2013,141 @@ main (int argc, char *argv[])
2012 { 2013 {
2013 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg; 2014 struct GNUNET_TRANSPORT_WLAN_HelperControlMessage macmsg;
2014 2015
2015 macmsg.hdr.size = htons (sizeof (macmsg)); 2016 macmsg.hdr.size = htons(sizeof(macmsg));
2016 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 2017 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
2017 GNUNET_memcpy (&macmsg.mac, &dev.pl_mac, sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)); 2018 GNUNET_memcpy(&macmsg.mac, &dev.pl_mac, sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress));
2018 GNUNET_memcpy (write_std.buf, &macmsg, sizeof (macmsg)); 2019 GNUNET_memcpy(write_std.buf, &macmsg, sizeof(macmsg));
2019 write_std.size = sizeof (macmsg); 2020 write_std.size = sizeof(macmsg);
2020 } 2021 }
2021 2022
2022 stdin_mst = mst_create (&stdin_send_hw, &dev); 2023 stdin_mst = mst_create(&stdin_send_hw, &dev);
2023 stdin_open = 1; 2024 stdin_open = 1;
2024 while (1) 2025 while (1)
2025 {
2026 maxfd = -1;
2027 FD_ZERO (&rfds);
2028 if ((0 == write_pout.size) && (1 == stdin_open))
2029 {
2030 FD_SET (STDIN_FILENO, &rfds);
2031 maxfd = MAX (maxfd, STDIN_FILENO);
2032 }
2033 if (0 == write_std.size)
2034 {
2035 FD_SET (dev.fd_raw, &rfds);
2036 maxfd = MAX (maxfd, dev.fd_raw);
2037 }
2038 FD_ZERO (&wfds);
2039 if (0 < write_std.size)
2040 {
2041 FD_SET (STDOUT_FILENO, &wfds);
2042 maxfd = MAX (maxfd, STDOUT_FILENO);
2043 }
2044 if (0 < write_pout.size)
2045 {
2046 FD_SET (dev.fd_raw, &wfds);
2047 maxfd = MAX (maxfd, dev.fd_raw);
2048 }
2049 { 2026 {
2050 int retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL); 2027 maxfd = -1;
2051 if ((-1 == retval) && (EINTR == errno)) 2028 FD_ZERO(&rfds);
2052 continue; 2029 if ((0 == write_pout.size) && (1 == stdin_open))
2053 if (0 > retval) 2030 {
2031 FD_SET(STDIN_FILENO, &rfds);
2032 maxfd = MAX(maxfd, STDIN_FILENO);
2033 }
2034 if (0 == write_std.size)
2035 {
2036 FD_SET(dev.fd_raw, &rfds);
2037 maxfd = MAX(maxfd, dev.fd_raw);
2038 }
2039 FD_ZERO(&wfds);
2040 if (0 < write_std.size)
2041 {
2042 FD_SET(STDOUT_FILENO, &wfds);
2043 maxfd = MAX(maxfd, STDOUT_FILENO);
2044 }
2045 if (0 < write_pout.size)
2046 {
2047 FD_SET(dev.fd_raw, &wfds);
2048 maxfd = MAX(maxfd, dev.fd_raw);
2049 }
2054 { 2050 {
2055 fprintf (stderr, "select failed: %s\n", strerror (errno)); 2051 int retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL);
2056 break; 2052 if ((-1 == retval) && (EINTR == errno))
2053 continue;
2054 if (0 > retval)
2055 {
2056 fprintf(stderr, "select failed: %s\n", strerror(errno));
2057 break;
2058 }
2057 } 2059 }
2060 if (FD_ISSET(STDOUT_FILENO, &wfds))
2061 {
2062 ssize_t ret =
2063 write(STDOUT_FILENO, write_std.buf + write_std.pos,
2064 write_std.size - write_std.pos);
2065 if (0 > ret)
2066 {
2067 fprintf(stderr, "Failed to write to STDOUT: %s\n", strerror(errno));
2068 break;
2069 }
2070 write_std.pos += ret;
2071 if (write_std.pos == write_std.size)
2072 {
2073 write_std.pos = 0;
2074 write_std.size = 0;
2075 }
2076 }
2077 if (FD_ISSET(dev.fd_raw, &wfds))
2078 {
2079 ssize_t ret =
2080 write(dev.fd_raw, write_pout.buf + write_pout.pos,
2081 write_pout.size - write_pout.pos);
2082 if (0 > ret)
2083 {
2084 fprintf(stderr, "Failed to write to WLAN device: %s\n",
2085 strerror(errno));
2086 break;
2087 }
2088 write_pout.pos += ret;
2089 if ((write_pout.pos != write_pout.size) && (0 != ret))
2090 {
2091 /* we should not get partial sends with packet-oriented devices... */
2092 fprintf(stderr, "Write error, partial send: %u/%u\n",
2093 (unsigned int)write_pout.pos,
2094 (unsigned int)write_pout.size);
2095 break;
2096 }
2097 if (write_pout.pos == write_pout.size)
2098 {
2099 write_pout.pos = 0;
2100 write_pout.size = 0;
2101 }
2102 }
2103
2104 if (FD_ISSET(STDIN_FILENO, &rfds))
2105 {
2106 ssize_t ret =
2107 read(STDIN_FILENO, readbuf, sizeof(readbuf));
2108 if (0 > ret)
2109 {
2110 fprintf(stderr, "Read error from STDIN: %s\n", strerror(errno));
2111 break;
2112 }
2113 if (0 == ret)
2114 {
2115 /* stop reading... */
2116 stdin_open = 0;
2117 }
2118 mst_receive(stdin_mst, readbuf, ret);
2119 }
2120
2121 if (FD_ISSET(dev.fd_raw, &rfds))
2122 {
2123 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2124 ssize_t ret;
2125
2126 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)write_std.buf;
2127 ret =
2128 linux_read(&dev, (unsigned char *)&rrm->frame,
2129 sizeof(write_std.buf)
2130 - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2131 + sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2132 rrm);
2133 if (0 > ret)
2134 {
2135 fprintf(stderr, "Read error from raw socket: %s\n", strerror(errno));
2136 break;
2137 }
2138 if ((0 < ret) && (0 == mac_test(&rrm->frame, &dev)))
2139 {
2140 write_std.size = ret
2141 + sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2142 - sizeof(struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2143 rrm->header.size = htons(write_std.size);
2144 rrm->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2145 }
2146 }
2058 } 2147 }
2059 if (FD_ISSET (STDOUT_FILENO, &wfds))
2060 {
2061 ssize_t ret =
2062 write (STDOUT_FILENO, write_std.buf + write_std.pos,
2063 write_std.size - write_std.pos);
2064 if (0 > ret)
2065 {
2066 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
2067 break;
2068 }
2069 write_std.pos += ret;
2070 if (write_std.pos == write_std.size)
2071 {
2072 write_std.pos = 0;
2073 write_std.size = 0;
2074 }
2075 }
2076 if (FD_ISSET (dev.fd_raw, &wfds))
2077 {
2078 ssize_t ret =
2079 write (dev.fd_raw, write_pout.buf + write_pout.pos,
2080 write_pout.size - write_pout.pos);
2081 if (0 > ret)
2082 {
2083 fprintf (stderr, "Failed to write to WLAN device: %s\n",
2084 strerror (errno));
2085 break;
2086 }
2087 write_pout.pos += ret;
2088 if ((write_pout.pos != write_pout.size) && (0 != ret))
2089 {
2090 /* we should not get partial sends with packet-oriented devices... */
2091 fprintf (stderr, "Write error, partial send: %u/%u\n",
2092 (unsigned int) write_pout.pos,
2093 (unsigned int) write_pout.size);
2094 break;
2095 }
2096 if (write_pout.pos == write_pout.size)
2097 {
2098 write_pout.pos = 0;
2099 write_pout.size = 0;
2100 }
2101 }
2102
2103 if (FD_ISSET (STDIN_FILENO, &rfds))
2104 {
2105 ssize_t ret =
2106 read (STDIN_FILENO, readbuf, sizeof (readbuf));
2107 if (0 > ret)
2108 {
2109 fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
2110 break;
2111 }
2112 if (0 == ret)
2113 {
2114 /* stop reading... */
2115 stdin_open = 0;
2116 }
2117 mst_receive (stdin_mst, readbuf, ret);
2118 }
2119
2120 if (FD_ISSET (dev.fd_raw, &rfds))
2121 {
2122 struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *rrm;
2123 ssize_t ret;
2124
2125 rrm = (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) write_std.buf;
2126 ret =
2127 linux_read (&dev, (unsigned char *) &rrm->frame,
2128 sizeof (write_std.buf)
2129 - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2130 + sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame),
2131 rrm);
2132 if (0 > ret)
2133 {
2134 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
2135 break;
2136 }
2137 if ((0 < ret) && (0 == mac_test (&rrm->frame, &dev)))
2138 {
2139 write_std.size = ret
2140 + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)
2141 - sizeof (struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame);
2142 rrm->header.size = htons (write_std.size);
2143 rrm->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER);
2144 }
2145 }
2146 }
2147 /* Error handling, try to clean up a bit at least */ 2148 /* Error handling, try to clean up a bit at least */
2148 mst_destroy (stdin_mst); 2149 mst_destroy(stdin_mst);
2149 (void) close (dev.fd_raw); 2150 (void)close(dev.fd_raw);
2150 return 1; /* we never exit 'normally' */ 2151 return 1; /* we never exit 'normally' */
2151} 2152}
2152 2153
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index bae187e7c..09e15655f 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V. 3 Copyright (C) 2010-2016, 2018, 2019 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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,8 +308,7 @@ 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{
313 /** 312 /**
314 * Unique value, generated by incrementing the 313 * Unique value, generated by incrementing the
315 * `message_uuid_ctr` of `struct Neighbour`. 314 * `message_uuid_ctr` of `struct Neighbour`.
@@ -321,8 +320,7 @@ struct MessageUUIDP
321/** 320/**
322 * Unique identifier to map an acknowledgement to a transmission. 321 * Unique identifier to map an acknowledgement to a transmission.
323 */ 322 */
324struct AcknowledgementUUIDP 323struct AcknowledgementUUIDP {
325{
326 /** 324 /**
327 * The UUID value. 325 * The UUID value.
328 */ 326 */
@@ -333,8 +331,7 @@ struct AcknowledgementUUIDP
333/** 331/**
334 * Type of a nonce used for challenges. 332 * Type of a nonce used for challenges.
335 */ 333 */
336struct ChallengeNonceP 334struct ChallengeNonceP {
337{
338 /** 335 /**
339 * The value of the nonce. Note that this is NOT a hash. 336 * The value of the nonce. Note that this is NOT a hash.
340 */ 337 */
@@ -345,8 +342,7 @@ struct ChallengeNonceP
345/** 342/**
346 * Outer layer of an encapsulated backchannel message. 343 * Outer layer of an encapsulated backchannel message.
347 */ 344 */
348struct TransportBackchannelEncapsulationMessage 345struct TransportBackchannelEncapsulationMessage {
349{
350 /** 346 /**
351 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION. 347 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION.
352 */ 348 */
@@ -362,9 +358,7 @@ struct TransportBackchannelEncapsulationMessage
362/** 358/**
363 * Body by which a peer confirms that it is using an ephemeral key. 359 * Body by which a peer confirms that it is using an ephemeral key.
364 */ 360 */
365struct EphemeralConfirmationPS 361struct EphemeralConfirmationPS {
366{
367
368 /** 362 /**
369 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL 363 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL
370 */ 364 */
@@ -403,9 +397,7 @@ struct EphemeralConfirmationPS
403 * Plaintext of the variable-size payload that is encrypted 397 * Plaintext of the variable-size payload that is encrypted
404 * within a `struct TransportBackchannelEncapsulationMessage` 398 * within a `struct TransportBackchannelEncapsulationMessage`
405 */ 399 */
406struct TransportDVBoxPayloadP 400struct TransportDVBoxPayloadP {
407{
408
409 /** 401 /**
410 * Sender's peer identity. 402 * Sender's peer identity.
411 */ 403 */
@@ -438,8 +430,7 @@ struct TransportDVBoxPayloadP
438 * Outer layer of an encapsulated unfragmented application message sent 430 * Outer layer of an encapsulated unfragmented application message sent
439 * over an unreliable channel. 431 * over an unreliable channel.
440 */ 432 */
441struct TransportReliabilityBoxMessage 433struct TransportReliabilityBoxMessage {
442{
443 /** 434 /**
444 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX 435 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX
445 */ 436 */
@@ -465,8 +456,7 @@ struct TransportReliabilityBoxMessage
465/** 456/**
466 * Acknowledgement payload. 457 * Acknowledgement payload.
467 */ 458 */
468struct TransportCummulativeAckPayloadP 459struct TransportCummulativeAckPayloadP {
469{
470 /** 460 /**
471 * How long was the ACK delayed for generating cummulative ACKs? 461 * How long was the ACK delayed for generating cummulative ACKs?
472 * Used to calculate the correct network RTT by taking the receipt 462 * Used to calculate the correct network RTT by taking the receipt
@@ -489,8 +479,7 @@ struct TransportCummulativeAckPayloadP
489 * so ACKs are identified by a combination of PID of sender and 479 * so ACKs are identified by a combination of PID of sender and
490 * message UUID, without the queue playing any role! 480 * message UUID, without the queue playing any role!
491 */ 481 */
492struct TransportReliabilityAckMessage 482struct TransportReliabilityAckMessage {
493{
494 /** 483 /**
495 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK 484 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK
496 */ 485 */
@@ -510,8 +499,7 @@ struct TransportReliabilityAckMessage
510/** 499/**
511 * Outer layer of an encapsulated fragmented application message. 500 * Outer layer of an encapsulated fragmented application message.
512 */ 501 */
513struct TransportFragmentBoxMessage 502struct TransportFragmentBoxMessage {
514{
515 /** 503 /**
516 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT 504 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT
517 */ 505 */
@@ -561,8 +549,7 @@ struct TransportFragmentBoxMessage
561 * potential amplificator will check the @e monotonic_time and only respond 549 * potential amplificator will check the @e monotonic_time and only respond
562 * (at most) once per message. 550 * (at most) once per message.
563 */ 551 */
564struct DvInitPS 552struct DvInitPS {
565{
566 /** 553 /**
567 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR 554 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR
568 */ 555 */
@@ -605,8 +592,7 @@ struct DvInitPS
605 * replay old messages. Thus, passively learned paths should always be 592 * replay old messages. Thus, passively learned paths should always be
606 * immediately marked as "potentially stale". 593 * immediately marked as "potentially stale".
607 */ 594 */
608struct DvHopPS 595struct DvHopPS {
609{
610 /** 596 /**
611 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP 597 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP
612 */ 598 */
@@ -633,8 +619,7 @@ struct DvHopPS
633 * An entry describing a peer on a path in a 619 * An entry describing a peer on a path in a
634 * `struct TransportDVLearnMessage` message. 620 * `struct TransportDVLearnMessage` message.
635 */ 621 */
636struct DVPathEntryP 622struct DVPathEntryP {
637{
638 /** 623 /**
639 * Identity of a peer on the path. 624 * Identity of a peer on the path.
640 */ 625 */
@@ -661,8 +646,7 @@ struct DVPathEntryP
661 * zero, peers that can forward to the initator should always try to 646 * zero, peers that can forward to the initator should always try to
662 * forward to the initiator. 647 * forward to the initiator.
663 */ 648 */
664struct TransportDVLearnMessage 649struct TransportDVLearnMessage {
665{
666 /** 650 /**
667 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN 651 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN
668 */ 652 */
@@ -749,8 +733,7 @@ struct TransportDVLearnMessage
749 * the predecessor must be the origin (so this is not really useful 733 * the predecessor must be the origin (so this is not really useful
750 * for anonymization). 734 * for anonymization).
751 */ 735 */
752struct TransportDVBoxMessage 736struct TransportDVBoxMessage {
753{
754 /** 737 /**
755 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX 738 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX
756 */ 739 */
@@ -808,9 +791,7 @@ struct TransportDVBoxMessage
808 * Message send to another peer to validate that it can indeed 791 * Message send to another peer to validate that it can indeed
809 * receive messages at a particular address. 792 * receive messages at a particular address.
810 */ 793 */
811struct TransportValidationChallengeMessage 794struct TransportValidationChallengeMessage {
812{
813
814 /** 795 /**
815 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE 796 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE
816 */ 797 */
@@ -838,9 +819,7 @@ struct TransportValidationChallengeMessage
838 * Message signed by a peer to confirm that it can indeed 819 * Message signed by a peer to confirm that it can indeed
839 * receive messages at a particular address. 820 * receive messages at a particular address.
840 */ 821 */
841struct TransportValidationPS 822struct TransportValidationPS {
842{
843
844 /** 823 /**
845 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE 824 * Purpose is #GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE
846 */ 825 */
@@ -863,9 +842,7 @@ struct TransportValidationPS
863 * Message send to a peer to respond to a 842 * Message send to a peer to respond to a
864 * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE 843 * #GNUNET_MESSAGE_TYPE_ADDRESS_VALIDATION_CHALLENGE
865 */ 844 */
866struct TransportValidationResponseMessage 845struct TransportValidationResponseMessage {
867{
868
869 /** 846 /**
870 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE 847 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE
871 */ 848 */
@@ -909,8 +886,7 @@ struct TransportValidationResponseMessage
909 * send to us, and how much data we already received from the other 886 * send to us, and how much data we already received from the other
910 * peer. 887 * peer.
911 */ 888 */
912struct TransportFlowControlMessage 889struct TransportFlowControlMessage {
913{
914 /** 890 /**
915 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL 891 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL
916 */ 892 */
@@ -966,8 +942,7 @@ GNUNET_NETWORK_STRUCT_END
966/** 942/**
967 * What type of client is the `struct TransportClient` about? 943 * What type of client is the `struct TransportClient` about?
968 */ 944 */
969enum ClientType 945enum ClientType {
970{
971 /** 946 /**
972 * We do not know yet (client is fresh). 947 * We do not know yet (client is fresh).
973 */ 948 */
@@ -999,8 +974,7 @@ enum ClientType
999 * Which transmission options are allowable for transmission? 974 * Which transmission options are allowable for transmission?
1000 * Interpreted bit-wise! 975 * Interpreted bit-wise!
1001 */ 976 */
1002enum RouteMessageOptions 977enum RouteMessageOptions {
1003{
1004 /** 978 /**
1005 * Only confirmed, non-DV direct neighbours. 979 * Only confirmed, non-DV direct neighbours.
1006 */ 980 */
@@ -1033,9 +1007,7 @@ enum RouteMessageOptions
1033/** 1007/**
1034 * When did we launch this DV learning activity? 1008 * When did we launch this DV learning activity?
1035 */ 1009 */
1036struct LearnLaunchEntry 1010struct LearnLaunchEntry {
1037{
1038
1039 /** 1011 /**
1040 * Kept (also) in a DLL sorted by launch time. 1012 * Kept (also) in a DLL sorted by launch time.
1041 */ 1013 */
@@ -1063,8 +1035,7 @@ struct LearnLaunchEntry
1063 * Information we keep per #GOODPUT_AGING_SLOTS about historic 1035 * Information we keep per #GOODPUT_AGING_SLOTS about historic
1064 * (or current) transmission performance. 1036 * (or current) transmission performance.
1065 */ 1037 */
1066struct TransmissionHistoryEntry 1038struct TransmissionHistoryEntry {
1067{
1068 /** 1039 /**
1069 * Number of bytes actually sent in the interval. 1040 * Number of bytes actually sent in the interval.
1070 */ 1041 */
@@ -1081,8 +1052,7 @@ struct TransmissionHistoryEntry
1081/** 1052/**
1082 * Performance data for a transmission possibility. 1053 * Performance data for a transmission possibility.
1083 */ 1054 */
1084struct PerformanceData 1055struct PerformanceData {
1085{
1086 /** 1056 /**
1087 * Weighted average for the RTT. 1057 * Weighted average for the RTT.
1088 */ 1058 */
@@ -1149,9 +1119,7 @@ struct VirtualLink;
1149 * Context from #handle_incoming_msg(). Closure for many 1119 * Context from #handle_incoming_msg(). Closure for many
1150 * message handlers below. 1120 * message handlers below.
1151 */ 1121 */
1152struct CommunicatorMessageContext 1122struct CommunicatorMessageContext {
1153{
1154
1155 /** 1123 /**
1156 * Kept in a DLL of `struct VirtualLink` if waiting for CORE 1124 * Kept in a DLL of `struct VirtualLink` if waiting for CORE
1157 * flow control to unchoke. 1125 * flow control to unchoke.
@@ -1185,9 +1153,7 @@ struct CommunicatorMessageContext
1185/** 1153/**
1186 * Closure for #core_env_sent_cb. 1154 * Closure for #core_env_sent_cb.
1187 */ 1155 */
1188struct CoreSentContext 1156struct CoreSentContext {
1189{
1190
1191 /** 1157 /**
1192 * Kept in a DLL to clear @e vl in case @e vl is lost. 1158 * Kept in a DLL to clear @e vl in case @e vl is lost.
1193 */ 1159 */
@@ -1226,8 +1192,7 @@ struct CoreSentContext
1226 * data that is per neighbour that is not specific to how the 1192 * data that is per neighbour that is not specific to how the
1227 * connectivity is established. 1193 * connectivity is established.
1228 */ 1194 */
1229struct VirtualLink 1195struct VirtualLink {
1230{
1231 /** 1196 /**
1232 * Identity of the peer at the other end of the link. 1197 * Identity of the peer at the other end of the link.
1233 */ 1198 */
@@ -1425,9 +1390,7 @@ struct VirtualLink
1425/** 1390/**
1426 * Data structure kept when we are waiting for an acknowledgement. 1391 * Data structure kept when we are waiting for an acknowledgement.
1427 */ 1392 */
1428struct PendingAcknowledgement 1393struct PendingAcknowledgement {
1429{
1430
1431 /** 1394 /**
1432 * If @e pm is non-NULL, this is the DLL in which this acknowledgement 1395 * If @e pm is non-NULL, this is the DLL in which this acknowledgement
1433 * is kept in relation to its pending message. 1396 * is kept in relation to its pending message.
@@ -1520,9 +1483,7 @@ struct PendingAcknowledgement
1520/** 1483/**
1521 * One possible hop towards a DV target. 1484 * One possible hop towards a DV target.
1522 */ 1485 */
1523struct DistanceVectorHop 1486struct DistanceVectorHop {
1524{
1525
1526 /** 1487 /**
1527 * Kept in a MDLL, sorted by @e timeout. 1488 * Kept in a MDLL, sorted by @e timeout.
1528 */ 1489 */
@@ -1603,9 +1564,7 @@ struct DistanceVectorHop
1603 * Entry in our #dv_routes table, representing a (set of) distance 1564 * Entry in our #dv_routes table, representing a (set of) distance
1604 * vector routes to a particular peer. 1565 * vector routes to a particular peer.
1605 */ 1566 */
1606struct DistanceVector 1567struct DistanceVector {
1607{
1608
1609 /** 1568 /**
1610 * To which peer is this a route? 1569 * To which peer is this a route?
1611 */ 1570 */
@@ -1669,9 +1628,7 @@ struct DistanceVector
1669 * what the communicator can actually provide towards a particular 1628 * what the communicator can actually provide towards a particular
1670 * peer/target). 1629 * peer/target).
1671 */ 1630 */
1672struct QueueEntry 1631struct QueueEntry {
1673{
1674
1675 /** 1632 /**
1676 * Kept as a DLL. 1633 * Kept as a DLL.
1677 */ 1634 */
@@ -1703,8 +1660,7 @@ struct QueueEntry
1703 * A queue is a message queue provided by a communicator 1660 * A queue is a message queue provided by a communicator
1704 * via which we can reach a particular neighbour. 1661 * via which we can reach a particular neighbour.
1705 */ 1662 */
1706struct Queue 1663struct Queue {
1707{
1708 /** 1664 /**
1709 * Kept in a MDLL. 1665 * Kept in a MDLL.
1710 */ 1666 */
@@ -1832,9 +1788,7 @@ struct Queue
1832/** 1788/**
1833 * Information we keep for a message that we are reassembling. 1789 * Information we keep for a message that we are reassembling.
1834 */ 1790 */
1835struct ReassemblyContext 1791struct ReassemblyContext {
1836{
1837
1838 /** 1792 /**
1839 * Original message ID for of the message that all the fragments 1793 * Original message ID for of the message that all the fragments
1840 * belong to. 1794 * belong to.
@@ -1892,9 +1846,7 @@ struct ReassemblyContext
1892/** 1846/**
1893 * A neighbour that at least one communicator is connected to. 1847 * A neighbour that at least one communicator is connected to.
1894 */ 1848 */
1895struct Neighbour 1849struct Neighbour {
1896{
1897
1898 /** 1850 /**
1899 * Which peer is this about? 1851 * Which peer is this about?
1900 */ 1852 */
@@ -1977,9 +1929,7 @@ struct Neighbour
1977 * Another peer attempted to talk to us, we should try to establish 1929 * Another peer attempted to talk to us, we should try to establish
1978 * a connection in the other direction. 1930 * a connection in the other direction.
1979 */ 1931 */
1980struct IncomingRequest 1932struct IncomingRequest {
1981{
1982
1983 /** 1933 /**
1984 * Kept in a DLL. 1934 * Kept in a DLL.
1985 */ 1935 */
@@ -2005,9 +1955,7 @@ struct IncomingRequest
2005/** 1955/**
2006 * A peer that an application (client) would like us to talk to directly. 1956 * A peer that an application (client) would like us to talk to directly.
2007 */ 1957 */
2008struct PeerRequest 1958struct PeerRequest {
2009{
2010
2011 /** 1959 /**
2012 * Which peer is this about? 1960 * Which peer is this about?
2013 */ 1961 */
@@ -2040,9 +1988,7 @@ struct PeerRequest
2040/** 1988/**
2041 * Types of different pending messages. 1989 * Types of different pending messages.
2042 */ 1990 */
2043enum PendingMessageType 1991enum PendingMessageType {
2044{
2045
2046 /** 1992 /**
2047 * Ordinary message received from the CORE service. 1993 * Ordinary message received from the CORE service.
2048 */ 1994 */
@@ -2062,7 +2008,6 @@ enum PendingMessageType
2062 * Pending message created during #forward_dv_box(). 2008 * Pending message created during #forward_dv_box().
2063 */ 2009 */
2064 PMT_DV_BOX = 3 2010 PMT_DV_BOX = 3
2065
2066}; 2011};
2067 2012
2068 2013
@@ -2092,8 +2037,7 @@ enum PendingMessageType
2092 * is never again transmitted (even if it fits below the MTU), and 2037 * is never again transmitted (even if it fits below the MTU), and
2093 * only (remaining) fragments are sent. 2038 * only (remaining) fragments are sent.
2094 */ 2039 */
2095struct PendingMessage 2040struct PendingMessage {
2096{
2097 /** 2041 /**
2098 * Kept in a MDLL of messages for this @a vl. 2042 * Kept in a MDLL of messages for this @a vl.
2099 */ 2043 */
@@ -2232,8 +2176,7 @@ struct PendingMessage
2232/** 2176/**
2233 * Acknowledgement payload. 2177 * Acknowledgement payload.
2234 */ 2178 */
2235struct TransportCummulativeAckPayload 2179struct TransportCummulativeAckPayload {
2236{
2237 /** 2180 /**
2238 * When did we receive the message we are ACKing? Used to calculate 2181 * When did we receive the message we are ACKing? Used to calculate
2239 * the delay we introduced by cummulating ACKs. 2182 * the delay we introduced by cummulating ACKs.
@@ -2251,8 +2194,7 @@ struct TransportCummulativeAckPayload
2251 * Data structure in which we track acknowledgements still to 2194 * Data structure in which we track acknowledgements still to
2252 * be sent to the 2195 * be sent to the
2253 */ 2196 */
2254struct AcknowledgementCummulator 2197struct AcknowledgementCummulator {
2255{
2256 /** 2198 /**
2257 * Target peer for which we are accumulating ACKs here. 2199 * Target peer for which we are accumulating ACKs here.
2258 */ 2200 */
@@ -2292,9 +2234,7 @@ struct AcknowledgementCummulator
2292/** 2234/**
2293 * One of the addresses of this peer. 2235 * One of the addresses of this peer.
2294 */ 2236 */
2295struct AddressListEntry 2237struct AddressListEntry {
2296{
2297
2298 /** 2238 /**
2299 * Kept in a DLL. 2239 * Kept in a DLL.
2300 */ 2240 */
@@ -2346,9 +2286,7 @@ struct AddressListEntry
2346/** 2286/**
2347 * Client connected to the transport service. 2287 * Client connected to the transport service.
2348 */ 2288 */
2349struct TransportClient 2289struct TransportClient {
2350{
2351
2352 /** 2290 /**
2353 * Kept in a DLL. 2291 * Kept in a DLL.
2354 */ 2292 */
@@ -2374,15 +2312,11 @@ struct TransportClient
2374 */ 2312 */
2375 enum ClientType type; 2313 enum ClientType type;
2376 2314
2377 union 2315 union {
2378 {
2379
2380 /** 2316 /**
2381 * Information for @e type #CT_CORE. 2317 * Information for @e type #CT_CORE.
2382 */ 2318 */
2383 struct 2319 struct {
2384 {
2385
2386 /** 2320 /**
2387 * Head of list of messages pending for this client, sorted by 2321 * Head of list of messages pending for this client, sorted by
2388 * transmission time ("next_attempt" + possibly internal prioritization). 2322 * transmission time ("next_attempt" + possibly internal prioritization).
@@ -2393,15 +2327,12 @@ struct TransportClient
2393 * Tail of list of messages pending for this client. 2327 * Tail of list of messages pending for this client.
2394 */ 2328 */
2395 struct PendingMessage *pending_msg_tail; 2329 struct PendingMessage *pending_msg_tail;
2396
2397 } core; 2330 } core;
2398 2331
2399 /** 2332 /**
2400 * Information for @e type #CT_MONITOR. 2333 * Information for @e type #CT_MONITOR.
2401 */ 2334 */
2402 struct 2335 struct {
2403 {
2404
2405 /** 2336 /**
2406 * Peer identity to monitor the addresses of. 2337 * Peer identity to monitor the addresses of.
2407 * Zero to monitor all neighbours. Valid if 2338 * Zero to monitor all neighbours. Valid if
@@ -2413,15 +2344,13 @@ struct TransportClient
2413 * Is this a one-shot monitor? 2344 * Is this a one-shot monitor?
2414 */ 2345 */
2415 int one_shot; 2346 int one_shot;
2416
2417 } monitor; 2347 } monitor;
2418 2348
2419 2349
2420 /** 2350 /**
2421 * Information for @e type #CT_COMMUNICATOR. 2351 * Information for @e type #CT_COMMUNICATOR.
2422 */ 2352 */
2423 struct 2353 struct {
2424 {
2425 /** 2354 /**
2426 * If @e type is #CT_COMMUNICATOR, this communicator 2355 * If @e type is #CT_COMMUNICATOR, this communicator
2427 * supports communicating using these addresses. 2356 * supports communicating using these addresses.
@@ -2461,23 +2390,18 @@ struct TransportClient
2461 * Characteristics of this communicator. 2390 * Characteristics of this communicator.
2462 */ 2391 */
2463 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 2392 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
2464
2465 } communicator; 2393 } communicator;
2466 2394
2467 /** 2395 /**
2468 * Information for @e type #CT_APPLICATION 2396 * Information for @e type #CT_APPLICATION
2469 */ 2397 */
2470 struct 2398 struct {
2471 {
2472
2473 /** 2399 /**
2474 * Map of requests for peers the given client application would like to 2400 * Map of requests for peers the given client application would like to
2475 * see connections for. Maps from PIDs to `struct PeerRequest`. 2401 * see connections for. Maps from PIDs to `struct PeerRequest`.
2476 */ 2402 */
2477 struct GNUNET_CONTAINER_MultiPeerMap *requests; 2403 struct GNUNET_CONTAINER_MultiPeerMap *requests;
2478
2479 } application; 2404 } application;
2480
2481 } details; 2405 } details;
2482}; 2406};
2483 2407
@@ -2486,9 +2410,7 @@ struct TransportClient
2486 * State we keep for validation activities. Each of these 2410 * State we keep for validation activities. Each of these
2487 * is both in the #validation_heap and the #validation_map. 2411 * is both in the #validation_heap and the #validation_map.
2488 */ 2412 */
2489struct ValidationState 2413struct ValidationState {
2490{
2491
2492 /** 2414 /**
2493 * For which peer is @a address to be validated (or possibly valid)? 2415 * For which peer is @a address to be validated (or possibly valid)?
2494 * Serves as key in the #validation_map. 2416 * Serves as key in the #validation_map.
@@ -2598,8 +2520,7 @@ struct ValidationState
2598 * material (to avoid repeatedly checking signatures), and to synchronize 2520 * material (to avoid repeatedly checking signatures), and to synchronize
2599 * monotonic time with the PEERSTORE. 2521 * monotonic time with the PEERSTORE.
2600 */ 2522 */
2601struct Backtalker 2523struct Backtalker {
2602{
2603 /** 2524 /**
2604 * Peer this is about. 2525 * Peer this is about.
2605 */ 2526 */
@@ -2822,11 +2743,11 @@ static struct GNUNET_TIME_Absolute hello_mono_time;
2822 * @return current age of the world 2743 * @return current age of the world
2823 */ 2744 */
2824static unsigned int 2745static unsigned int
2825get_age () 2746get_age()
2826{ 2747{
2827 struct GNUNET_TIME_Absolute now; 2748 struct GNUNET_TIME_Absolute now;
2828 2749
2829 now = GNUNET_TIME_absolute_get (); 2750 now = GNUNET_TIME_absolute_get();
2830 return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15; 2751 return now.abs_value_us / GNUNET_TIME_UNIT_MINUTES.rel_value_us / 15;
2831} 2752}
2832 2753
@@ -2837,13 +2758,13 @@ get_age ()
2837 * @param ir data structure to release 2758 * @param ir data structure to release
2838 */ 2759 */
2839static void 2760static void
2840free_incoming_request (struct IncomingRequest *ir) 2761free_incoming_request(struct IncomingRequest *ir)
2841{ 2762{
2842 GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir); 2763 GNUNET_CONTAINER_DLL_remove(ir_head, ir_tail, ir);
2843 GNUNET_assert (ir_total > 0); 2764 GNUNET_assert(ir_total > 0);
2844 ir_total--; 2765 ir_total--;
2845 GNUNET_PEERSTORE_watch_cancel (ir->wc); 2766 GNUNET_PEERSTORE_watch_cancel(ir->wc);
2846 GNUNET_free (ir); 2767 GNUNET_free(ir);
2847} 2768}
2848 2769
2849 2770
@@ -2853,34 +2774,34 @@ free_incoming_request (struct IncomingRequest *ir)
2853 * @param pa data structure to release 2774 * @param pa data structure to release
2854 */ 2775 */
2855static void 2776static void
2856free_pending_acknowledgement (struct PendingAcknowledgement *pa) 2777free_pending_acknowledgement(struct PendingAcknowledgement *pa)
2857{ 2778{
2858 struct Queue *q = pa->queue; 2779 struct Queue *q = pa->queue;
2859 struct PendingMessage *pm = pa->pm; 2780 struct PendingMessage *pm = pa->pm;
2860 struct DistanceVectorHop *dvh = pa->dvh; 2781 struct DistanceVectorHop *dvh = pa->dvh;
2861 2782
2862 GNUNET_CONTAINER_MDLL_remove (pa, pa_head, pa_tail, pa); 2783 GNUNET_CONTAINER_MDLL_remove(pa, pa_head, pa_tail, pa);
2863 pa_count--; 2784 pa_count--;
2864 if (NULL != q) 2785 if (NULL != q)
2865 { 2786 {
2866 GNUNET_CONTAINER_MDLL_remove (queue, q->pa_head, q->pa_tail, pa); 2787 GNUNET_CONTAINER_MDLL_remove(queue, q->pa_head, q->pa_tail, pa);
2867 pa->queue = NULL; 2788 pa->queue = NULL;
2868 } 2789 }
2869 if (NULL != pm) 2790 if (NULL != pm)
2870 { 2791 {
2871 GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); 2792 GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa);
2872 pa->pm = NULL; 2793 pa->pm = NULL;
2873 } 2794 }
2874 if (NULL != dvh) 2795 if (NULL != dvh)
2875 { 2796 {
2876 GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); 2797 GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa);
2877 pa->queue = NULL; 2798 pa->queue = NULL;
2878 } 2799 }
2879 GNUNET_assert (GNUNET_YES == 2800 GNUNET_assert(GNUNET_YES ==
2880 GNUNET_CONTAINER_multiuuidmap_remove (pending_acks, 2801 GNUNET_CONTAINER_multiuuidmap_remove(pending_acks,
2881 &pa->ack_uuid.value, 2802 &pa->ack_uuid.value,
2882 pa)); 2803 pa));
2883 GNUNET_free (pa); 2804 GNUNET_free(pa);
2884} 2805}
2885 2806
2886 2807
@@ -2893,23 +2814,23 @@ free_pending_acknowledgement (struct PendingAcknowledgement *pa)
2893 * @param root root of the tree to free 2814 * @param root root of the tree to free
2894 */ 2815 */
2895static void 2816static void
2896free_fragment_tree (struct PendingMessage *root) 2817free_fragment_tree(struct PendingMessage *root)
2897{ 2818{
2898 struct PendingMessage *frag; 2819 struct PendingMessage *frag;
2899 2820
2900 while (NULL != (frag = root->head_frag)) 2821 while (NULL != (frag = root->head_frag))
2901 {
2902 struct PendingAcknowledgement *pa;
2903
2904 free_fragment_tree (frag);
2905 while (NULL != (pa = frag->pa_head))
2906 { 2822 {
2907 GNUNET_CONTAINER_MDLL_remove (pm, frag->pa_head, frag->pa_tail, pa); 2823 struct PendingAcknowledgement *pa;
2908 pa->pm = NULL; 2824
2825 free_fragment_tree(frag);
2826 while (NULL != (pa = frag->pa_head))
2827 {
2828 GNUNET_CONTAINER_MDLL_remove(pm, frag->pa_head, frag->pa_tail, pa);
2829 pa->pm = NULL;
2830 }
2831 GNUNET_CONTAINER_MDLL_remove(frag, root->head_frag, root->tail_frag, frag);
2832 GNUNET_free(frag);
2909 } 2833 }
2910 GNUNET_CONTAINER_MDLL_remove (frag, root->head_frag, root->tail_frag, frag);
2911 GNUNET_free (frag);
2912 }
2913} 2834}
2914 2835
2915 2836
@@ -2921,44 +2842,44 @@ free_fragment_tree (struct PendingMessage *root)
2921 * @param pm the pending message to free 2842 * @param pm the pending message to free
2922 */ 2843 */
2923static void 2844static void
2924free_pending_message (struct PendingMessage *pm) 2845free_pending_message(struct PendingMessage *pm)
2925{ 2846{
2926 struct TransportClient *tc = pm->client; 2847 struct TransportClient *tc = pm->client;
2927 struct VirtualLink *vl = pm->vl; 2848 struct VirtualLink *vl = pm->vl;
2928 struct PendingAcknowledgement *pa; 2849 struct PendingAcknowledgement *pa;
2929 2850
2930 if (NULL != tc) 2851 if (NULL != tc)
2931 { 2852 {
2932 GNUNET_CONTAINER_MDLL_remove (client, 2853 GNUNET_CONTAINER_MDLL_remove(client,
2933 tc->details.core.pending_msg_head, 2854 tc->details.core.pending_msg_head,
2934 tc->details.core.pending_msg_tail, 2855 tc->details.core.pending_msg_tail,
2935 pm); 2856 pm);
2936 } 2857 }
2937 if (NULL != vl) 2858 if (NULL != vl)
2938 { 2859 {
2939 GNUNET_CONTAINER_MDLL_remove (vl, 2860 GNUNET_CONTAINER_MDLL_remove(vl,
2940 vl->pending_msg_head, 2861 vl->pending_msg_head,
2941 vl->pending_msg_tail, 2862 vl->pending_msg_tail,
2942 pm); 2863 pm);
2943 } 2864 }
2944 while (NULL != (pa = pm->pa_head)) 2865 while (NULL != (pa = pm->pa_head))
2945 { 2866 {
2946 GNUNET_CONTAINER_MDLL_remove (pm, pm->pa_head, pm->pa_tail, pa); 2867 GNUNET_CONTAINER_MDLL_remove(pm, pm->pa_head, pm->pa_tail, pa);
2947 pa->pm = NULL; 2868 pa->pm = NULL;
2948 } 2869 }
2949 2870
2950 free_fragment_tree (pm); 2871 free_fragment_tree(pm);
2951 if (NULL != pm->qe) 2872 if (NULL != pm->qe)
2952 { 2873 {
2953 GNUNET_assert (pm == pm->qe->pm); 2874 GNUNET_assert(pm == pm->qe->pm);
2954 pm->qe->pm = NULL; 2875 pm->qe->pm = NULL;
2955 } 2876 }
2956 if (NULL != pm->bpm) 2877 if (NULL != pm->bpm)
2957 { 2878 {
2958 free_fragment_tree (pm->bpm); 2879 free_fragment_tree(pm->bpm);
2959 GNUNET_free (pm->bpm); 2880 GNUNET_free(pm->bpm);
2960 } 2881 }
2961 GNUNET_free (pm); 2882 GNUNET_free(pm);
2962} 2883}
2963 2884
2964 2885
@@ -2968,34 +2889,34 @@ free_pending_message (struct PendingMessage *pm)
2968 * @param vl link data to free 2889 * @param vl link data to free
2969 */ 2890 */
2970static void 2891static void
2971free_virtual_link (struct VirtualLink *vl) 2892free_virtual_link(struct VirtualLink *vl)
2972{ 2893{
2973 struct PendingMessage *pm; 2894 struct PendingMessage *pm;
2974 struct CoreSentContext *csc; 2895 struct CoreSentContext *csc;
2975 2896
2976 while (NULL != (pm = vl->pending_msg_head)) 2897 while (NULL != (pm = vl->pending_msg_head))
2977 free_pending_message (pm); 2898 free_pending_message(pm);
2978 GNUNET_assert (GNUNET_YES == 2899 GNUNET_assert(GNUNET_YES ==
2979 GNUNET_CONTAINER_multipeermap_remove (links, &vl->target, vl)); 2900 GNUNET_CONTAINER_multipeermap_remove(links, &vl->target, vl));
2980 if (NULL != vl->visibility_task) 2901 if (NULL != vl->visibility_task)
2981 { 2902 {
2982 GNUNET_SCHEDULER_cancel (vl->visibility_task); 2903 GNUNET_SCHEDULER_cancel(vl->visibility_task);
2983 vl->visibility_task = NULL; 2904 vl->visibility_task = NULL;
2984 } 2905 }
2985 if (NULL != vl->fc_retransmit_task) 2906 if (NULL != vl->fc_retransmit_task)
2986 { 2907 {
2987 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); 2908 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
2988 vl->fc_retransmit_task = NULL; 2909 vl->fc_retransmit_task = NULL;
2989 } 2910 }
2990 while (NULL != (csc = vl->csc_head)) 2911 while (NULL != (csc = vl->csc_head))
2991 { 2912 {
2992 GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, csc); 2913 GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, csc);
2993 GNUNET_assert (vl == csc->vl); 2914 GNUNET_assert(vl == csc->vl);
2994 csc->vl = NULL; 2915 csc->vl = NULL;
2995 } 2916 }
2996 GNUNET_break (NULL == vl->n); 2917 GNUNET_break(NULL == vl->n);
2997 GNUNET_break (NULL == vl->dv); 2918 GNUNET_break(NULL == vl->dv);
2998 GNUNET_free (vl); 2919 GNUNET_free(vl);
2999} 2920}
3000 2921
3001 2922
@@ -3005,20 +2926,20 @@ free_virtual_link (struct VirtualLink *vl)
3005 * @param vs validation state to free 2926 * @param vs validation state to free
3006 */ 2927 */
3007static void 2928static void
3008free_validation_state (struct ValidationState *vs) 2929free_validation_state(struct ValidationState *vs)
3009{ 2930{
3010 GNUNET_assert ( 2931 GNUNET_assert(
3011 GNUNET_YES == 2932 GNUNET_YES ==
3012 GNUNET_CONTAINER_multipeermap_remove (validation_map, &vs->pid, vs)); 2933 GNUNET_CONTAINER_multipeermap_remove(validation_map, &vs->pid, vs));
3013 GNUNET_CONTAINER_heap_remove_node (vs->hn); 2934 GNUNET_CONTAINER_heap_remove_node(vs->hn);
3014 vs->hn = NULL; 2935 vs->hn = NULL;
3015 if (NULL != vs->sc) 2936 if (NULL != vs->sc)
3016 { 2937 {
3017 GNUNET_PEERSTORE_store_cancel (vs->sc); 2938 GNUNET_PEERSTORE_store_cancel(vs->sc);
3018 vs->sc = NULL; 2939 vs->sc = NULL;
3019 } 2940 }
3020 GNUNET_free (vs->address); 2941 GNUNET_free(vs->address);
3021 GNUNET_free (vs); 2942 GNUNET_free(vs);
3022} 2943}
3023 2944
3024 2945
@@ -3029,9 +2950,9 @@ free_validation_state (struct ValidationState *vs)
3029 * @return NULL if we do not have this peer as a neighbour 2950 * @return NULL if we do not have this peer as a neighbour
3030 */ 2951 */
3031static struct Neighbour * 2952static struct Neighbour *
3032lookup_neighbour (const struct GNUNET_PeerIdentity *pid) 2953lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
3033{ 2954{
3034 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); 2955 return GNUNET_CONTAINER_multipeermap_get(neighbours, pid);
3035} 2956}
3036 2957
3037 2958
@@ -3042,17 +2963,16 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
3042 * @return NULL if we do not have this peer as a virtual link 2963 * @return NULL if we do not have this peer as a virtual link
3043 */ 2964 */
3044static struct VirtualLink * 2965static struct VirtualLink *
3045lookup_virtual_link (const struct GNUNET_PeerIdentity *pid) 2966lookup_virtual_link(const struct GNUNET_PeerIdentity *pid)
3046{ 2967{
3047 return GNUNET_CONTAINER_multipeermap_get (links, pid); 2968 return GNUNET_CONTAINER_multipeermap_get(links, pid);
3048} 2969}
3049 2970
3050 2971
3051/** 2972/**
3052 * Details about what to notify monitors about. 2973 * Details about what to notify monitors about.
3053 */ 2974 */
3054struct MonitorEvent 2975struct MonitorEvent {
3055{
3056 /** 2976 /**
3057 * @deprecated To be discussed if we keep these... 2977 * @deprecated To be discussed if we keep these...
3058 */ 2978 */
@@ -3091,20 +3011,20 @@ struct MonitorEvent
3091 * @param dvh hop to free 3011 * @param dvh hop to free
3092 */ 3012 */
3093static void 3013static void
3094free_distance_vector_hop (struct DistanceVectorHop *dvh) 3014free_distance_vector_hop(struct DistanceVectorHop *dvh)
3095{ 3015{
3096 struct Neighbour *n = dvh->next_hop; 3016 struct Neighbour *n = dvh->next_hop;
3097 struct DistanceVector *dv = dvh->dv; 3017 struct DistanceVector *dv = dvh->dv;
3098 struct PendingAcknowledgement *pa; 3018 struct PendingAcknowledgement *pa;
3099 3019
3100 while (NULL != (pa = dvh->pa_head)) 3020 while (NULL != (pa = dvh->pa_head))
3101 { 3021 {
3102 GNUNET_CONTAINER_MDLL_remove (dvh, dvh->pa_head, dvh->pa_tail, pa); 3022 GNUNET_CONTAINER_MDLL_remove(dvh, dvh->pa_head, dvh->pa_tail, pa);
3103 pa->dvh = NULL; 3023 pa->dvh = NULL;
3104 } 3024 }
3105 GNUNET_CONTAINER_MDLL_remove (neighbour, n->dv_head, n->dv_tail, dvh); 3025 GNUNET_CONTAINER_MDLL_remove(neighbour, n->dv_head, n->dv_tail, dvh);
3106 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, dvh); 3026 GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, dvh);
3107 GNUNET_free (dvh); 3027 GNUNET_free(dvh);
3108} 3028}
3109 3029
3110 3030
@@ -3115,7 +3035,7 @@ free_distance_vector_hop (struct DistanceVectorHop *dvh)
3115 * @param cls a `struct VirtualLink` 3035 * @param cls a `struct VirtualLink`
3116 */ 3036 */
3117static void 3037static void
3118check_link_down (void *cls); 3038check_link_down(void *cls);
3119 3039
3120 3040
3121/** 3041/**
@@ -3124,22 +3044,22 @@ check_link_down (void *cls);
3124 * @param pid peer the connection was for 3044 * @param pid peer the connection was for
3125 */ 3045 */
3126static void 3046static void
3127cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid) 3047cores_send_disconnect_info(const struct GNUNET_PeerIdentity *pid)
3128{ 3048{
3129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3130 "Informing CORE clients about disconnect from %s\n", 3050 "Informing CORE clients about disconnect from %s\n",
3131 GNUNET_i2s (pid)); 3051 GNUNET_i2s(pid));
3132 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3052 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3133 { 3053 {
3134 struct GNUNET_MQ_Envelope *env; 3054 struct GNUNET_MQ_Envelope *env;
3135 struct DisconnectInfoMessage *dim; 3055 struct DisconnectInfoMessage *dim;
3136 3056
3137 if (CT_CORE != tc->type) 3057 if (CT_CORE != tc->type)
3138 continue; 3058 continue;
3139 env = GNUNET_MQ_msg (dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 3059 env = GNUNET_MQ_msg(dim, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
3140 dim->peer = *pid; 3060 dim->peer = *pid;
3141 GNUNET_MQ_send (tc->mq, env); 3061 GNUNET_MQ_send(tc->mq, env);
3142 } 3062 }
3143} 3063}
3144 3064
3145 3065
@@ -3150,43 +3070,43 @@ cores_send_disconnect_info (const struct GNUNET_PeerIdentity *pid)
3150 * @param dv route to free 3070 * @param dv route to free
3151 */ 3071 */
3152static void 3072static void
3153free_dv_route (struct DistanceVector *dv) 3073free_dv_route(struct DistanceVector *dv)
3154{ 3074{
3155 struct DistanceVectorHop *dvh; 3075 struct DistanceVectorHop *dvh;
3156 3076
3157 while (NULL != (dvh = dv->dv_head)) 3077 while (NULL != (dvh = dv->dv_head))
3158 free_distance_vector_hop (dvh); 3078 free_distance_vector_hop(dvh);
3159 if (NULL == dv->dv_head) 3079 if (NULL == dv->dv_head)
3160 {
3161 struct VirtualLink *vl;
3162
3163 GNUNET_assert (
3164 GNUNET_YES ==
3165 GNUNET_CONTAINER_multipeermap_remove (dv_routes, &dv->target, dv));
3166 if (NULL != (vl = dv->vl))
3167 { 3080 {
3168 GNUNET_assert (dv == vl->dv); 3081 struct VirtualLink *vl;
3169 vl->dv = NULL;
3170 if (NULL == vl->n)
3171 {
3172 cores_send_disconnect_info (&dv->target);
3173 free_virtual_link (vl);
3174 }
3175 else
3176 {
3177 GNUNET_SCHEDULER_cancel (vl->visibility_task);
3178 vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl);
3179 }
3180 dv->vl = NULL;
3181 }
3182 3082
3183 if (NULL != dv->timeout_task) 3083 GNUNET_assert(
3184 { 3084 GNUNET_YES ==
3185 GNUNET_SCHEDULER_cancel (dv->timeout_task); 3085 GNUNET_CONTAINER_multipeermap_remove(dv_routes, &dv->target, dv));
3186 dv->timeout_task = NULL; 3086 if (NULL != (vl = dv->vl))
3087 {
3088 GNUNET_assert(dv == vl->dv);
3089 vl->dv = NULL;
3090 if (NULL == vl->n)
3091 {
3092 cores_send_disconnect_info(&dv->target);
3093 free_virtual_link(vl);
3094 }
3095 else
3096 {
3097 GNUNET_SCHEDULER_cancel(vl->visibility_task);
3098 vl->visibility_task = GNUNET_SCHEDULER_add_now(&check_link_down, vl);
3099 }
3100 dv->vl = NULL;
3101 }
3102
3103 if (NULL != dv->timeout_task)
3104 {
3105 GNUNET_SCHEDULER_cancel(dv->timeout_task);
3106 dv->timeout_task = NULL;
3107 }
3108 GNUNET_free(dv);
3187 } 3109 }
3188 GNUNET_free (dv);
3189 }
3190} 3110}
3191 3111
3192 3112
@@ -3204,30 +3124,30 @@ free_dv_route (struct DistanceVector *dv)
3204 * @param me detailed information to transmit 3124 * @param me detailed information to transmit
3205 */ 3125 */
3206static void 3126static void
3207notify_monitor (struct TransportClient *tc, 3127notify_monitor(struct TransportClient *tc,
3208 const struct GNUNET_PeerIdentity *peer, 3128 const struct GNUNET_PeerIdentity *peer,
3209 const char *address, 3129 const char *address,
3210 enum GNUNET_NetworkType nt, 3130 enum GNUNET_NetworkType nt,
3211 const struct MonitorEvent *me) 3131 const struct MonitorEvent *me)
3212{ 3132{
3213 struct GNUNET_MQ_Envelope *env; 3133 struct GNUNET_MQ_Envelope *env;
3214 struct GNUNET_TRANSPORT_MonitorData *md; 3134 struct GNUNET_TRANSPORT_MonitorData *md;
3215 size_t addr_len = strlen (address) + 1; 3135 size_t addr_len = strlen(address) + 1;
3216 3136
3217 env = GNUNET_MQ_msg_extra (md, 3137 env = GNUNET_MQ_msg_extra(md,
3218 addr_len, 3138 addr_len,
3219 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA); 3139 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA);
3220 md->nt = htonl ((uint32_t) nt); 3140 md->nt = htonl((uint32_t)nt);
3221 md->peer = *peer; 3141 md->peer = *peer;
3222 md->last_validation = GNUNET_TIME_absolute_hton (me->last_validation); 3142 md->last_validation = GNUNET_TIME_absolute_hton(me->last_validation);
3223 md->valid_until = GNUNET_TIME_absolute_hton (me->valid_until); 3143 md->valid_until = GNUNET_TIME_absolute_hton(me->valid_until);
3224 md->next_validation = GNUNET_TIME_absolute_hton (me->next_validation); 3144 md->next_validation = GNUNET_TIME_absolute_hton(me->next_validation);
3225 md->rtt = GNUNET_TIME_relative_hton (me->rtt); 3145 md->rtt = GNUNET_TIME_relative_hton(me->rtt);
3226 md->cs = htonl ((uint32_t) me->cs); 3146 md->cs = htonl((uint32_t)me->cs);
3227 md->num_msg_pending = htonl (me->num_msg_pending); 3147 md->num_msg_pending = htonl(me->num_msg_pending);
3228 md->num_bytes_pending = htonl (me->num_bytes_pending); 3148 md->num_bytes_pending = htonl(me->num_bytes_pending);
3229 memcpy (&md[1], address, addr_len); 3149 memcpy(&md[1], address, addr_len);
3230 GNUNET_MQ_send (tc->mq, env); 3150 GNUNET_MQ_send(tc->mq, env);
3231} 3151}
3232 3152
3233 3153
@@ -3241,22 +3161,22 @@ notify_monitor (struct TransportClient *tc,
3241 * @param me detailed information to transmit 3161 * @param me detailed information to transmit
3242 */ 3162 */
3243static void 3163static void
3244notify_monitors (const struct GNUNET_PeerIdentity *peer, 3164notify_monitors(const struct GNUNET_PeerIdentity *peer,
3245 const char *address, 3165 const char *address,
3246 enum GNUNET_NetworkType nt, 3166 enum GNUNET_NetworkType nt,
3247 const struct MonitorEvent *me) 3167 const struct MonitorEvent *me)
3248{ 3168{
3249 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3169 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3250 { 3170 {
3251 if (CT_MONITOR != tc->type) 3171 if (CT_MONITOR != tc->type)
3252 continue; 3172 continue;
3253 if (tc->details.monitor.one_shot) 3173 if (tc->details.monitor.one_shot)
3254 continue; 3174 continue;
3255 if ((0 != GNUNET_is_zero (&tc->details.monitor.peer)) && 3175 if ((0 != GNUNET_is_zero(&tc->details.monitor.peer)) &&
3256 (0 != GNUNET_memcmp (&tc->details.monitor.peer, peer))) 3176 (0 != GNUNET_memcmp(&tc->details.monitor.peer, peer)))
3257 continue; 3177 continue;
3258 notify_monitor (tc, peer, address, nt, me); 3178 notify_monitor(tc, peer, address, nt, me);
3259 } 3179 }
3260} 3180}
3261 3181
3262 3182
@@ -3270,18 +3190,18 @@ notify_monitors (const struct GNUNET_PeerIdentity *peer,
3270 * @return our `struct TransportClient` 3190 * @return our `struct TransportClient`
3271 */ 3191 */
3272static void * 3192static void *
3273client_connect_cb (void *cls, 3193client_connect_cb(void *cls,
3274 struct GNUNET_SERVICE_Client *client, 3194 struct GNUNET_SERVICE_Client *client,
3275 struct GNUNET_MQ_Handle *mq) 3195 struct GNUNET_MQ_Handle *mq)
3276{ 3196{
3277 struct TransportClient *tc; 3197 struct TransportClient *tc;
3278 3198
3279 (void) cls; 3199 (void)cls;
3280 tc = GNUNET_new (struct TransportClient); 3200 tc = GNUNET_new(struct TransportClient);
3281 tc->client = client; 3201 tc->client = client;
3282 tc->mq = mq; 3202 tc->mq = mq;
3283 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); 3203 GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc);
3284 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); 3204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
3285 return tc; 3205 return tc;
3286} 3206}
3287 3207
@@ -3292,16 +3212,16 @@ client_connect_cb (void *cls,
3292 * @param rc data structure to free 3212 * @param rc data structure to free
3293 */ 3213 */
3294static void 3214static void
3295free_reassembly_context (struct ReassemblyContext *rc) 3215free_reassembly_context(struct ReassemblyContext *rc)
3296{ 3216{
3297 struct Neighbour *n = rc->neighbour; 3217 struct Neighbour *n = rc->neighbour;
3298 3218
3299 GNUNET_assert (rc == GNUNET_CONTAINER_heap_remove_node (rc->hn)); 3219 GNUNET_assert(rc == GNUNET_CONTAINER_heap_remove_node(rc->hn));
3300 GNUNET_assert (GNUNET_OK == 3220 GNUNET_assert(GNUNET_OK ==
3301 GNUNET_CONTAINER_multihashmap32_remove (n->reassembly_map, 3221 GNUNET_CONTAINER_multihashmap32_remove(n->reassembly_map,
3302 rc->msg_uuid.uuid, 3222 rc->msg_uuid.uuid,
3303 rc)); 3223 rc));
3304 GNUNET_free (rc); 3224 GNUNET_free(rc);
3305} 3225}
3306 3226
3307 3227
@@ -3311,27 +3231,27 @@ free_reassembly_context (struct ReassemblyContext *rc)
3311 * @param cls a `struct Neighbour` 3231 * @param cls a `struct Neighbour`
3312 */ 3232 */
3313static void 3233static void
3314reassembly_cleanup_task (void *cls) 3234reassembly_cleanup_task(void *cls)
3315{ 3235{
3316 struct Neighbour *n = cls; 3236 struct Neighbour *n = cls;
3317 struct ReassemblyContext *rc; 3237 struct ReassemblyContext *rc;
3318 3238
3319 n->reassembly_timeout_task = NULL; 3239 n->reassembly_timeout_task = NULL;
3320 while (NULL != (rc = GNUNET_CONTAINER_heap_peek (n->reassembly_heap))) 3240 while (NULL != (rc = GNUNET_CONTAINER_heap_peek(n->reassembly_heap)))
3321 {
3322 if (0 == GNUNET_TIME_absolute_get_remaining (rc->reassembly_timeout)
3323 .rel_value_us)
3324 { 3241 {
3325 free_reassembly_context (rc); 3242 if (0 == GNUNET_TIME_absolute_get_remaining(rc->reassembly_timeout)
3326 continue; 3243 .rel_value_us)
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;
3327 } 3254 }
3328 GNUNET_assert (NULL == n->reassembly_timeout_task);
3329 n->reassembly_timeout_task =
3330 GNUNET_SCHEDULER_add_at (rc->reassembly_timeout,
3331 &reassembly_cleanup_task,
3332 n);
3333 return;
3334 }
3335} 3255}
3336 3256
3337 3257
@@ -3344,13 +3264,13 @@ reassembly_cleanup_task (void *cls)
3344 * @return #GNUNET_OK (continue iteration) 3264 * @return #GNUNET_OK (continue iteration)
3345 */ 3265 */
3346static int 3266static int
3347free_reassembly_cb (void *cls, uint32_t key, void *value) 3267free_reassembly_cb(void *cls, uint32_t key, void *value)
3348{ 3268{
3349 struct ReassemblyContext *rc = value; 3269 struct ReassemblyContext *rc = value;
3350 3270
3351 (void) cls; 3271 (void)cls;
3352 (void) key; 3272 (void)key;
3353 free_reassembly_context (rc); 3273 free_reassembly_context(rc);
3354 return GNUNET_OK; 3274 return GNUNET_OK;
3355} 3275}
3356 3276
@@ -3361,66 +3281,66 @@ free_reassembly_cb (void *cls, uint32_t key, void *value)
3361 * @param neighbour neighbour entry to free 3281 * @param neighbour neighbour entry to free
3362 */ 3282 */
3363static void 3283static void
3364free_neighbour (struct Neighbour *neighbour) 3284free_neighbour(struct Neighbour *neighbour)
3365{ 3285{
3366 struct DistanceVectorHop *dvh; 3286 struct DistanceVectorHop *dvh;
3367 struct VirtualLink *vl; 3287 struct VirtualLink *vl;
3368 3288
3369 GNUNET_assert (NULL == neighbour->queue_head); 3289 GNUNET_assert(NULL == neighbour->queue_head);
3370 GNUNET_assert (GNUNET_YES == 3290 GNUNET_assert(GNUNET_YES ==
3371 GNUNET_CONTAINER_multipeermap_remove (neighbours, 3291 GNUNET_CONTAINER_multipeermap_remove(neighbours,
3372 &neighbour->pid, 3292 &neighbour->pid,
3373 neighbour)); 3293 neighbour));
3374 if (NULL != neighbour->reassembly_map) 3294 if (NULL != neighbour->reassembly_map)
3375 { 3295 {
3376 GNUNET_CONTAINER_multihashmap32_iterate (neighbour->reassembly_map, 3296 GNUNET_CONTAINER_multihashmap32_iterate(neighbour->reassembly_map,
3377 &free_reassembly_cb, 3297 &free_reassembly_cb,
3378 NULL); 3298 NULL);
3379 GNUNET_CONTAINER_multihashmap32_destroy (neighbour->reassembly_map); 3299 GNUNET_CONTAINER_multihashmap32_destroy(neighbour->reassembly_map);
3380 neighbour->reassembly_map = NULL; 3300 neighbour->reassembly_map = NULL;
3381 GNUNET_CONTAINER_heap_destroy (neighbour->reassembly_heap); 3301 GNUNET_CONTAINER_heap_destroy(neighbour->reassembly_heap);
3382 neighbour->reassembly_heap = NULL; 3302 neighbour->reassembly_heap = NULL;
3383 } 3303 }
3384 while (NULL != (dvh = neighbour->dv_head)) 3304 while (NULL != (dvh = neighbour->dv_head))
3385 { 3305 {
3386 struct DistanceVector *dv = dvh->dv; 3306 struct DistanceVector *dv = dvh->dv;
3387 3307
3388 free_distance_vector_hop (dvh); 3308 free_distance_vector_hop(dvh);
3389 if (NULL == dv->dv_head) 3309 if (NULL == dv->dv_head)
3390 free_dv_route (dv); 3310 free_dv_route(dv);
3391 } 3311 }
3392 if (NULL != neighbour->reassembly_timeout_task) 3312 if (NULL != neighbour->reassembly_timeout_task)
3393 { 3313 {
3394 GNUNET_SCHEDULER_cancel (neighbour->reassembly_timeout_task); 3314 GNUNET_SCHEDULER_cancel(neighbour->reassembly_timeout_task);
3395 neighbour->reassembly_timeout_task = NULL; 3315 neighbour->reassembly_timeout_task = NULL;
3396 } 3316 }
3397 if (NULL != neighbour->get) 3317 if (NULL != neighbour->get)
3398 { 3318 {
3399 GNUNET_PEERSTORE_iterate_cancel (neighbour->get); 3319 GNUNET_PEERSTORE_iterate_cancel(neighbour->get);
3400 neighbour->get = NULL; 3320 neighbour->get = NULL;
3401 } 3321 }
3402 if (NULL != neighbour->sc) 3322 if (NULL != neighbour->sc)
3403 {
3404 GNUNET_PEERSTORE_store_cancel (neighbour->sc);
3405 neighbour->sc = NULL;
3406 }
3407 if (NULL != (vl = neighbour->vl))
3408 {
3409 GNUNET_assert (neighbour == vl->n);
3410 vl->n = NULL;
3411 if (NULL == vl->dv)
3412 { 3323 {
3413 cores_send_disconnect_info (&vl->target); 3324 GNUNET_PEERSTORE_store_cancel(neighbour->sc);
3414 free_virtual_link (vl); 3325 neighbour->sc = NULL;
3415 } 3326 }
3416 else 3327 if (NULL != (vl = neighbour->vl))
3417 { 3328 {
3418 GNUNET_SCHEDULER_cancel (vl->visibility_task); 3329 GNUNET_assert(neighbour == vl->n);
3419 vl->visibility_task = GNUNET_SCHEDULER_add_now (&check_link_down, vl); 3330 vl->n = NULL;
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;
3420 } 3342 }
3421 neighbour->vl = NULL; 3343 GNUNET_free(neighbour);
3422 }
3423 GNUNET_free (neighbour);
3424} 3344}
3425 3345
3426 3346
@@ -3431,16 +3351,16 @@ free_neighbour (struct Neighbour *neighbour)
3431 * @param pid peer the connection is for 3351 * @param pid peer the connection is for
3432 */ 3352 */
3433static void 3353static void
3434core_send_connect_info (struct TransportClient *tc, 3354core_send_connect_info(struct TransportClient *tc,
3435 const struct GNUNET_PeerIdentity *pid) 3355 const struct GNUNET_PeerIdentity *pid)
3436{ 3356{
3437 struct GNUNET_MQ_Envelope *env; 3357 struct GNUNET_MQ_Envelope *env;
3438 struct ConnectInfoMessage *cim; 3358 struct ConnectInfoMessage *cim;
3439 3359
3440 GNUNET_assert (CT_CORE == tc->type); 3360 GNUNET_assert(CT_CORE == tc->type);
3441 env = GNUNET_MQ_msg (cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 3361 env = GNUNET_MQ_msg(cim, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
3442 cim->id = *pid; 3362 cim->id = *pid;
3443 GNUNET_MQ_send (tc->mq, env); 3363 GNUNET_MQ_send(tc->mq, env);
3444} 3364}
3445 3365
3446 3366
@@ -3450,17 +3370,17 @@ core_send_connect_info (struct TransportClient *tc,
3450 * @param pid peer the queue was for 3370 * @param pid peer the queue was for
3451 */ 3371 */
3452static void 3372static void
3453cores_send_connect_info (const struct GNUNET_PeerIdentity *pid) 3373cores_send_connect_info(const struct GNUNET_PeerIdentity *pid)
3454{ 3374{
3455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3456 "Informing CORE clients about connection to %s\n", 3376 "Informing CORE clients about connection to %s\n",
3457 GNUNET_i2s (pid)); 3377 GNUNET_i2s(pid));
3458 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 3378 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
3459 { 3379 {
3460 if (CT_CORE != tc->type) 3380 if (CT_CORE != tc->type)
3461 continue; 3381 continue;
3462 core_send_connect_info (tc, pid); 3382 core_send_connect_info(tc, pid);
3463 } 3383 }
3464} 3384}
3465 3385
3466 3386
@@ -3472,7 +3392,7 @@ cores_send_connect_info (const struct GNUNET_PeerIdentity *pid)
3472 * @param cls the `struct Queue` to process transmissions for 3392 * @param cls the `struct Queue` to process transmissions for
3473 */ 3393 */
3474static void 3394static void
3475transmit_on_queue (void *cls); 3395transmit_on_queue(void *cls);
3476 3396
3477 3397
3478/** 3398/**
@@ -3483,38 +3403,38 @@ transmit_on_queue (void *cls);
3483 * @param p task priority to use, if @a queue is scheduled 3403 * @param p task priority to use, if @a queue is scheduled
3484 */ 3404 */
3485static void 3405static void
3486schedule_transmit_on_queue (struct Queue *queue, 3406schedule_transmit_on_queue(struct Queue *queue,
3487 enum GNUNET_SCHEDULER_Priority p) 3407 enum GNUNET_SCHEDULER_Priority p)
3488{ 3408{
3489 if (queue->tc->details.communicator.total_queue_length >= 3409 if (queue->tc->details.communicator.total_queue_length >=
3490 COMMUNICATOR_TOTAL_QUEUE_LIMIT) 3410 COMMUNICATOR_TOTAL_QUEUE_LIMIT)
3491 { 3411 {
3492 GNUNET_STATISTICS_update ( 3412 GNUNET_STATISTICS_update(
3493 GST_stats, 3413 GST_stats,
3494 "# Transmission throttled due to communicator queue limit", 3414 "# Transmission throttled due to communicator queue limit",
3495 1, 3415 1,
3496 GNUNET_NO); 3416 GNUNET_NO);
3497 queue->idle = GNUNET_NO; 3417 queue->idle = GNUNET_NO;
3498 return; 3418 return;
3499 } 3419 }
3500 if (queue->queue_length >= QUEUE_LENGTH_LIMIT) 3420 if (queue->queue_length >= QUEUE_LENGTH_LIMIT)
3501 { 3421 {
3502 GNUNET_STATISTICS_update (GST_stats, 3422 GNUNET_STATISTICS_update(GST_stats,
3503 "# Transmission throttled due to queue queue limit", 3423 "# Transmission throttled due to queue queue limit",
3504 1, 3424 1,
3505 GNUNET_NO); 3425 GNUNET_NO);
3506 queue->idle = GNUNET_NO; 3426 queue->idle = GNUNET_NO;
3507 return; 3427 return;
3508 } 3428 }
3509 /* queue might indeed be ready, schedule it */ 3429 /* queue might indeed be ready, schedule it */
3510 if (NULL != queue->transmit_task) 3430 if (NULL != queue->transmit_task)
3511 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3431 GNUNET_SCHEDULER_cancel(queue->transmit_task);
3512 queue->transmit_task = 3432 queue->transmit_task =
3513 GNUNET_SCHEDULER_add_with_priority (p, &transmit_on_queue, queue); 3433 GNUNET_SCHEDULER_add_with_priority(p, &transmit_on_queue, queue);
3514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3434 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3515 "Considering transmission on queue `%s' to %s\n", 3435 "Considering transmission on queue `%s' to %s\n",
3516 queue->address, 3436 queue->address,
3517 GNUNET_i2s (&queue->neighbour->pid)); 3437 GNUNET_i2s(&queue->neighbour->pid));
3518} 3438}
3519 3439
3520 3440
@@ -3525,7 +3445,7 @@ schedule_transmit_on_queue (struct Queue *queue,
3525 * @param cls a `struct VirtualLink` 3445 * @param cls a `struct VirtualLink`
3526 */ 3446 */
3527static void 3447static void
3528check_link_down (void *cls) 3448check_link_down(void *cls)
3529{ 3449{
3530 struct VirtualLink *vl = cls; 3450 struct VirtualLink *vl = cls;
3531 struct DistanceVector *dv = vl->dv; 3451 struct DistanceVector *dv = vl->dv;
@@ -3537,30 +3457,30 @@ check_link_down (void *cls)
3537 dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS; 3457 dvh_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
3538 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3458 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3539 pos = pos->next_dv) 3459 pos = pos->next_dv)
3540 dvh_timeout = GNUNET_TIME_absolute_max (dvh_timeout, pos->path_valid_until); 3460 dvh_timeout = GNUNET_TIME_absolute_max(dvh_timeout, pos->path_valid_until);
3541 if (0 == GNUNET_TIME_absolute_get_remaining (dvh_timeout).rel_value_us) 3461 if (0 == GNUNET_TIME_absolute_get_remaining(dvh_timeout).rel_value_us)
3542 { 3462 {
3543 vl->dv->vl = NULL; 3463 vl->dv->vl = NULL;
3544 vl->dv = NULL; 3464 vl->dv = NULL;
3545 } 3465 }
3546 q_timeout = GNUNET_TIME_UNIT_ZERO_ABS; 3466 q_timeout = GNUNET_TIME_UNIT_ZERO_ABS;
3547 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 3467 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
3548 q_timeout = GNUNET_TIME_absolute_max (q_timeout, q->validated_until); 3468 q_timeout = GNUNET_TIME_absolute_max(q_timeout, q->validated_until);
3549 if (0 == GNUNET_TIME_absolute_get_remaining (q_timeout).rel_value_us) 3469 if (0 == GNUNET_TIME_absolute_get_remaining(q_timeout).rel_value_us)
3550 { 3470 {
3551 vl->n->vl = NULL; 3471 vl->n->vl = NULL;
3552 vl->n = NULL; 3472 vl->n = NULL;
3553 } 3473 }
3554 if ((NULL == vl->n) && (NULL == vl->dv)) 3474 if ((NULL == vl->n) && (NULL == vl->dv))
3555 { 3475 {
3556 cores_send_disconnect_info (&vl->target); 3476 cores_send_disconnect_info(&vl->target);
3557 free_virtual_link (vl); 3477 free_virtual_link(vl);
3558 return; 3478 return;
3559 } 3479 }
3560 vl->visibility_task = 3480 vl->visibility_task =
3561 GNUNET_SCHEDULER_add_at (GNUNET_TIME_absolute_max (q_timeout, dvh_timeout), 3481 GNUNET_SCHEDULER_add_at(GNUNET_TIME_absolute_max(q_timeout, dvh_timeout),
3562 &check_link_down, 3482 &check_link_down,
3563 vl); 3483 vl);
3564} 3484}
3565 3485
3566 3486
@@ -3570,77 +3490,77 @@ check_link_down (void *cls)
3570 * @param queue the queue to free 3490 * @param queue the queue to free
3571 */ 3491 */
3572static void 3492static void
3573free_queue (struct Queue *queue) 3493free_queue(struct Queue *queue)
3574{ 3494{
3575 struct Neighbour *neighbour = queue->neighbour; 3495 struct Neighbour *neighbour = queue->neighbour;
3576 struct TransportClient *tc = queue->tc; 3496 struct TransportClient *tc = queue->tc;
3577 struct MonitorEvent me = {.cs = GNUNET_TRANSPORT_CS_DOWN, 3497 struct MonitorEvent me = { .cs = GNUNET_TRANSPORT_CS_DOWN,
3578 .rtt = GNUNET_TIME_UNIT_FOREVER_REL}; 3498 .rtt = GNUNET_TIME_UNIT_FOREVER_REL };
3579 struct QueueEntry *qe; 3499 struct QueueEntry *qe;
3580 int maxxed; 3500 int maxxed;
3581 struct PendingAcknowledgement *pa; 3501 struct PendingAcknowledgement *pa;
3582 struct VirtualLink *vl; 3502 struct VirtualLink *vl;
3583 3503
3584 if (NULL != queue->transmit_task) 3504 if (NULL != queue->transmit_task)
3585 { 3505 {
3586 GNUNET_SCHEDULER_cancel (queue->transmit_task); 3506 GNUNET_SCHEDULER_cancel(queue->transmit_task);
3587 queue->transmit_task = NULL; 3507 queue->transmit_task = NULL;
3588 } 3508 }
3589 while (NULL != (pa = queue->pa_head)) 3509 while (NULL != (pa = queue->pa_head))
3590 { 3510 {
3591 GNUNET_CONTAINER_MDLL_remove (queue, queue->pa_head, queue->pa_tail, pa); 3511 GNUNET_CONTAINER_MDLL_remove(queue, queue->pa_head, queue->pa_tail, pa);
3592 pa->queue = NULL; 3512 pa->queue = NULL;
3593 } 3513 }
3594 3514
3595 GNUNET_CONTAINER_MDLL_remove (neighbour, 3515 GNUNET_CONTAINER_MDLL_remove(neighbour,
3596 neighbour->queue_head, 3516 neighbour->queue_head,
3597 neighbour->queue_tail, 3517 neighbour->queue_tail,
3598 queue); 3518 queue);
3599 GNUNET_CONTAINER_MDLL_remove (client, 3519 GNUNET_CONTAINER_MDLL_remove(client,
3600 tc->details.communicator.queue_head, 3520 tc->details.communicator.queue_head,
3601 tc->details.communicator.queue_tail, 3521 tc->details.communicator.queue_tail,
3602 queue); 3522 queue);
3603 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >= 3523 maxxed = (COMMUNICATOR_TOTAL_QUEUE_LIMIT >=
3604 tc->details.communicator.total_queue_length); 3524 tc->details.communicator.total_queue_length);
3605 while (NULL != (qe = queue->queue_head)) 3525 while (NULL != (qe = queue->queue_head))
3606 {
3607 GNUNET_CONTAINER_DLL_remove (queue->queue_head, queue->queue_tail, qe);
3608 queue->queue_length--;
3609 tc->details.communicator.total_queue_length--;
3610 if (NULL != qe->pm)
3611 { 3526 {
3612 GNUNET_assert (qe == qe->pm->qe); 3527 GNUNET_CONTAINER_DLL_remove(queue->queue_head, queue->queue_tail, qe);
3613 qe->pm->qe = NULL; 3528 queue->queue_length--;
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);
3614 } 3536 }
3615 GNUNET_free (qe); 3537 GNUNET_assert(0 == queue->queue_length);
3616 }
3617 GNUNET_assert (0 == queue->queue_length);
3618 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT < 3538 if ((maxxed) && (COMMUNICATOR_TOTAL_QUEUE_LIMIT <
3619 tc->details.communicator.total_queue_length)) 3539 tc->details.communicator.total_queue_length))
3620 { 3540 {
3621 /* Communicator dropped below threshold, resume all _other_ queues */ 3541 /* Communicator dropped below threshold, resume all _other_ queues */
3622 GNUNET_STATISTICS_update ( 3542 GNUNET_STATISTICS_update(
3623 GST_stats, 3543 GST_stats,
3624 "# Transmission throttled due to communicator queue limit", 3544 "# Transmission throttled due to communicator queue limit",
3625 -1, 3545 -1,
3626 GNUNET_NO); 3546 GNUNET_NO);
3627 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s; 3547 for (struct Queue *s = tc->details.communicator.queue_head; NULL != s;
3628 s = s->next_client) 3548 s = s->next_client)
3629 schedule_transmit_on_queue (s, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 3549 schedule_transmit_on_queue(s, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
3630 } 3550 }
3631 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); 3551 notify_monitors(&neighbour->pid, queue->address, queue->nt, &me);
3632 GNUNET_free (queue); 3552 GNUNET_free(queue);
3633 3553
3634 vl = lookup_virtual_link (&neighbour->pid); 3554 vl = lookup_virtual_link(&neighbour->pid);
3635 if ((NULL != vl) && (neighbour == vl->n)) 3555 if ((NULL != vl) && (neighbour == vl->n))
3636 { 3556 {
3637 GNUNET_SCHEDULER_cancel (vl->visibility_task); 3557 GNUNET_SCHEDULER_cancel(vl->visibility_task);
3638 check_link_down (vl); 3558 check_link_down(vl);
3639 } 3559 }
3640 if (NULL == neighbour->queue_head) 3560 if (NULL == neighbour->queue_head)
3641 { 3561 {
3642 free_neighbour (neighbour); 3562 free_neighbour(neighbour);
3643 } 3563 }
3644} 3564}
3645 3565
3646 3566
@@ -3650,24 +3570,24 @@ free_queue (struct Queue *queue)
3650 * @param ale address list entry to free 3570 * @param ale address list entry to free
3651 */ 3571 */
3652static void 3572static void
3653free_address_list_entry (struct AddressListEntry *ale) 3573free_address_list_entry(struct AddressListEntry *ale)
3654{ 3574{
3655 struct TransportClient *tc = ale->tc; 3575 struct TransportClient *tc = ale->tc;
3656 3576
3657 GNUNET_CONTAINER_DLL_remove (tc->details.communicator.addr_head, 3577 GNUNET_CONTAINER_DLL_remove(tc->details.communicator.addr_head,
3658 tc->details.communicator.addr_tail, 3578 tc->details.communicator.addr_tail,
3659 ale); 3579 ale);
3660 if (NULL != ale->sc) 3580 if (NULL != ale->sc)
3661 { 3581 {
3662 GNUNET_PEERSTORE_store_cancel (ale->sc); 3582 GNUNET_PEERSTORE_store_cancel(ale->sc);
3663 ale->sc = NULL; 3583 ale->sc = NULL;
3664 } 3584 }
3665 if (NULL != ale->st) 3585 if (NULL != ale->st)
3666 { 3586 {
3667 GNUNET_SCHEDULER_cancel (ale->st); 3587 GNUNET_SCHEDULER_cancel(ale->st);
3668 ale->st = NULL; 3588 ale->st = NULL;
3669 } 3589 }
3670 GNUNET_free (ale); 3590 GNUNET_free(ale);
3671} 3591}
3672 3592
3673 3593
@@ -3680,20 +3600,20 @@ free_address_list_entry (struct AddressListEntry *ale)
3680 * @return #GNUNET_YES (always) 3600 * @return #GNUNET_YES (always)
3681 */ 3601 */
3682static int 3602static int
3683stop_peer_request (void *cls, 3603stop_peer_request(void *cls,
3684 const struct GNUNET_PeerIdentity *pid, 3604 const struct GNUNET_PeerIdentity *pid,
3685 void *value) 3605 void *value)
3686{ 3606{
3687 struct TransportClient *tc = cls; 3607 struct TransportClient *tc = cls;
3688 struct PeerRequest *pr = value; 3608 struct PeerRequest *pr = value;
3689 3609
3690 GNUNET_PEERSTORE_watch_cancel (pr->wc); 3610 GNUNET_PEERSTORE_watch_cancel(pr->wc);
3691 GNUNET_assert ( 3611 GNUNET_assert(
3692 GNUNET_YES == 3612 GNUNET_YES ==
3693 GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, 3613 GNUNET_CONTAINER_multipeermap_remove(tc->details.application.requests,
3694 pid, 3614 pid,
3695 pr)); 3615 pr));
3696 GNUNET_free (pr); 3616 GNUNET_free(pr);
3697 3617
3698 return GNUNET_OK; 3618 return GNUNET_OK;
3699} 3619}
@@ -3708,56 +3628,60 @@ stop_peer_request (void *cls,
3708 * @param app_ctx our `struct TransportClient` 3628 * @param app_ctx our `struct TransportClient`
3709 */ 3629 */
3710static void 3630static void
3711client_disconnect_cb (void *cls, 3631client_disconnect_cb(void *cls,
3712 struct GNUNET_SERVICE_Client *client, 3632 struct GNUNET_SERVICE_Client *client,
3713 void *app_ctx) 3633 void *app_ctx)
3714{ 3634{
3715 struct TransportClient *tc = app_ctx; 3635 struct TransportClient *tc = app_ctx;
3716 3636
3717 (void) cls; 3637 (void)cls;
3718 (void) client; 3638 (void)client;
3719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3639 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3720 "Client %p disconnected, cleaning up.\n", 3640 "Client %p disconnected, cleaning up.\n",
3721 tc); 3641 tc);
3722 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); 3642 GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc);
3723 switch (tc->type) 3643 switch (tc->type)
3724 {
3725 case CT_NONE:
3726 break;
3727 case CT_CORE: {
3728 struct PendingMessage *pm;
3729
3730 while (NULL != (pm = tc->details.core.pending_msg_head))
3731 { 3644 {
3732 GNUNET_CONTAINER_MDLL_remove (client, 3645 case CT_NONE:
3733 tc->details.core.pending_msg_head, 3646 break;
3734 tc->details.core.pending_msg_tail, 3647
3735 pm); 3648 case CT_CORE: {
3736 pm->client = NULL; 3649 struct PendingMessage *pm;
3650
3651 while (NULL != (pm = tc->details.core.pending_msg_head))
3652 {
3653 GNUNET_CONTAINER_MDLL_remove(client,
3654 tc->details.core.pending_msg_head,
3655 tc->details.core.pending_msg_tail,
3656 pm);
3657 pm->client = NULL;
3658 }
3737 } 3659 }
3738 }
3739 break;
3740 case CT_MONITOR:
3741 break; 3660 break;
3742 case CT_COMMUNICATOR: { 3661
3743 struct Queue *q; 3662 case CT_MONITOR:
3744 struct AddressListEntry *ale; 3663 break;
3745 3664
3746 while (NULL != (q = tc->details.communicator.queue_head)) 3665 case CT_COMMUNICATOR: {
3747 free_queue (q); 3666 struct Queue *q;
3748 while (NULL != (ale = tc->details.communicator.addr_head)) 3667 struct AddressListEntry *ale;
3749 free_address_list_entry (ale); 3668
3750 GNUNET_free (tc->details.communicator.address_prefix); 3669 while (NULL != (q = tc->details.communicator.queue_head))
3751 } 3670 free_queue(q);
3752 break; 3671 while (NULL != (ale = tc->details.communicator.addr_head))
3753 case CT_APPLICATION: 3672 free_address_list_entry(ale);
3754 GNUNET_CONTAINER_multipeermap_iterate (tc->details.application.requests, 3673 GNUNET_free(tc->details.communicator.address_prefix);
3755 &stop_peer_request, 3674 }
3756 tc);
3757 GNUNET_CONTAINER_multipeermap_destroy (tc->details.application.requests);
3758 break; 3675 break;
3759 } 3676
3760 GNUNET_free (tc); 3677 case CT_APPLICATION:
3678 GNUNET_CONTAINER_multipeermap_iterate(tc->details.application.requests,
3679 &stop_peer_request,
3680 tc);
3681 GNUNET_CONTAINER_multipeermap_destroy(tc->details.application.requests);
3682 break;
3683 }
3684 GNUNET_free(tc);
3761} 3685}
3762 3686
3763 3687
@@ -3771,17 +3695,17 @@ client_disconnect_cb (void *cls,
3771 * @return #GNUNET_OK (continue to iterate) 3695 * @return #GNUNET_OK (continue to iterate)
3772 */ 3696 */
3773static int 3697static int
3774notify_client_connect_info (void *cls, 3698notify_client_connect_info(void *cls,
3775 const struct GNUNET_PeerIdentity *pid, 3699 const struct GNUNET_PeerIdentity *pid,
3776 void *value) 3700 void *value)
3777{ 3701{
3778 struct TransportClient *tc = cls; 3702 struct TransportClient *tc = cls;
3779 3703
3780 (void) value; 3704 (void)value;
3781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3705 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3782 "Telling new CORE client about existing connection to %s\n", 3706 "Telling new CORE client about existing connection to %s\n",
3783 GNUNET_i2s (pid)); 3707 GNUNET_i2s(pid));
3784 core_send_connect_info (tc, pid); 3708 core_send_connect_info(tc, pid);
3785 return GNUNET_OK; 3709 return GNUNET_OK;
3786} 3710}
3787 3711
@@ -3795,34 +3719,34 @@ notify_client_connect_info (void *cls,
3795 * @param start the start message that was sent 3719 * @param start the start message that was sent
3796 */ 3720 */
3797static void 3721static void
3798handle_client_start (void *cls, const struct StartMessage *start) 3722handle_client_start(void *cls, const struct StartMessage *start)
3799{ 3723{
3800 struct TransportClient *tc = cls; 3724 struct TransportClient *tc = cls;
3801 uint32_t options; 3725 uint32_t options;
3802 3726
3803 options = ntohl (start->options); 3727 options = ntohl(start->options);
3804 if ((0 != (1 & options)) && 3728 if ((0 != (1 & options)) &&
3805 (0 != GNUNET_memcmp (&start->self, &GST_my_identity))) 3729 (0 != GNUNET_memcmp(&start->self, &GST_my_identity)))
3806 { 3730 {
3807 /* client thinks this is a different peer, reject */ 3731 /* client thinks this is a different peer, reject */
3808 GNUNET_break (0); 3732 GNUNET_break(0);
3809 GNUNET_SERVICE_client_drop (tc->client); 3733 GNUNET_SERVICE_client_drop(tc->client);
3810 return; 3734 return;
3811 } 3735 }
3812 if (CT_NONE != tc->type) 3736 if (CT_NONE != tc->type)
3813 { 3737 {
3814 GNUNET_break (0); 3738 GNUNET_break(0);
3815 GNUNET_SERVICE_client_drop (tc->client); 3739 GNUNET_SERVICE_client_drop(tc->client);
3816 return; 3740 return;
3817 } 3741 }
3818 tc->type = CT_CORE; 3742 tc->type = CT_CORE;
3819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3743 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3820 "New CORE client with PID %s registered\n", 3744 "New CORE client with PID %s registered\n",
3821 GNUNET_i2s (&start->self)); 3745 GNUNET_i2s(&start->self));
3822 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 3746 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
3823 &notify_client_connect_info, 3747 &notify_client_connect_info,
3824 tc); 3748 tc);
3825 GNUNET_SERVICE_client_continue (tc->client); 3749 GNUNET_SERVICE_client_continue(tc->client);
3826} 3750}
3827 3751
3828 3752
@@ -3833,29 +3757,29 @@ handle_client_start (void *cls, const struct StartMessage *start)
3833 * @param obm the send message that was sent 3757 * @param obm the send message that was sent
3834 */ 3758 */
3835static int 3759static int
3836check_client_send (void *cls, const struct OutboundMessage *obm) 3760check_client_send(void *cls, const struct OutboundMessage *obm)
3837{ 3761{
3838 struct TransportClient *tc = cls; 3762 struct TransportClient *tc = cls;
3839 uint16_t size; 3763 uint16_t size;
3840 const struct GNUNET_MessageHeader *obmm; 3764 const struct GNUNET_MessageHeader *obmm;
3841 3765
3842 if (CT_CORE != tc->type) 3766 if (CT_CORE != tc->type)
3843 { 3767 {
3844 GNUNET_break (0); 3768 GNUNET_break(0);
3845 return GNUNET_SYSERR; 3769 return GNUNET_SYSERR;
3846 } 3770 }
3847 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); 3771 size = ntohs(obm->header.size) - sizeof(struct OutboundMessage);
3848 if (size < sizeof (struct GNUNET_MessageHeader)) 3772 if (size < sizeof(struct GNUNET_MessageHeader))
3849 { 3773 {
3850 GNUNET_break (0); 3774 GNUNET_break(0);
3851 return GNUNET_SYSERR; 3775 return GNUNET_SYSERR;
3852 } 3776 }
3853 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 3777 obmm = (const struct GNUNET_MessageHeader *)&obm[1];
3854 if (size != ntohs (obmm->size)) 3778 if (size != ntohs(obmm->size))
3855 { 3779 {
3856 GNUNET_break (0); 3780 GNUNET_break(0);
3857 return GNUNET_SYSERR; 3781 return GNUNET_SYSERR;
3858 } 3782 }
3859 return GNUNET_OK; 3783 return GNUNET_OK;
3860} 3784}
3861 3785
@@ -3868,25 +3792,25 @@ check_client_send (void *cls, const struct OutboundMessage *obm)
3868 * @param pm handle to the original pending message 3792 * @param pm handle to the original pending message
3869 */ 3793 */
3870static void 3794static void
3871client_send_response (struct PendingMessage *pm) 3795client_send_response(struct PendingMessage *pm)
3872{ 3796{
3873 struct TransportClient *tc = pm->client; 3797 struct TransportClient *tc = pm->client;
3874 struct VirtualLink *vl = pm->vl; 3798 struct VirtualLink *vl = pm->vl;
3875 3799
3876 if (NULL != tc) 3800 if (NULL != tc)
3877 { 3801 {
3878 struct GNUNET_MQ_Envelope *env; 3802 struct GNUNET_MQ_Envelope *env;
3879 struct SendOkMessage *som; 3803 struct SendOkMessage *som;
3880 3804
3881 env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 3805 env = GNUNET_MQ_msg(som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
3882 som->peer = vl->target; 3806 som->peer = vl->target;
3883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3884 "Confirming transmission of <%llu> to %s\n", 3808 "Confirming transmission of <%llu> to %s\n",
3885 pm->logging_uuid, 3809 pm->logging_uuid,
3886 GNUNET_i2s (&vl->target)); 3810 GNUNET_i2s(&vl->target));
3887 GNUNET_MQ_send (tc->mq, env); 3811 GNUNET_MQ_send(tc->mq, env);
3888 } 3812 }
3889 free_pending_message (pm); 3813 free_pending_message(pm);
3890} 3814}
3891 3815
3892 3816
@@ -3900,10 +3824,10 @@ client_send_response (struct PendingMessage *pm)
3900 * @return number of entries set in @a hops_array 3824 * @return number of entries set in @a hops_array
3901 */ 3825 */
3902static unsigned int 3826static unsigned int
3903pick_random_dv_hops (const struct DistanceVector *dv, 3827pick_random_dv_hops(const struct DistanceVector *dv,
3904 enum RouteMessageOptions options, 3828 enum RouteMessageOptions options,
3905 struct DistanceVectorHop **hops_array, 3829 struct DistanceVectorHop **hops_array,
3906 unsigned int hops_array_length) 3830 unsigned int hops_array_length)
3907{ 3831{
3908 uint64_t choices[hops_array_length]; 3832 uint64_t choices[hops_array_length];
3909 uint64_t num_dv; 3833 uint64_t num_dv;
@@ -3915,56 +3839,56 @@ pick_random_dv_hops (const struct DistanceVector *dv,
3915 dv_count = 0; 3839 dv_count = 0;
3916 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3840 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3917 pos = pos->next_dv) 3841 pos = pos->next_dv)
3918 { 3842 {
3919 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && 3843 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
3920 (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) 3844 (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until)
3921 .rel_value_us == 0)) 3845 .rel_value_us == 0))
3922 continue; /* pos unconfirmed and confirmed required */ 3846 continue; /* pos unconfirmed and confirmed required */
3923 num_dv += MAX_DV_HOPS_ALLOWED - pos->distance; 3847 num_dv += MAX_DV_HOPS_ALLOWED - pos->distance;
3924 dv_count++; 3848 dv_count++;
3925 } 3849 }
3926 if (0 == dv_count) 3850 if (0 == dv_count)
3927 return 0; 3851 return 0;
3928 if (dv_count <= hops_array_length) 3852 if (dv_count <= hops_array_length)
3929 { 3853 {
3930 dv_count = 0; 3854 dv_count = 0;
3931 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3855 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3932 pos = pos->next_dv) 3856 pos = pos->next_dv)
3933 hops_array[dv_count++] = pos; 3857 hops_array[dv_count++] = pos;
3934 return dv_count; 3858 return dv_count;
3935 } 3859 }
3936 for (unsigned int i = 0; i < hops_array_length; i++) 3860 for (unsigned int i = 0; i < hops_array_length; i++)
3937 { 3861 {
3938 int ok = GNUNET_NO; 3862 int ok = GNUNET_NO;
3939 while (GNUNET_NO == ok) 3863 while (GNUNET_NO == ok)
3940 {
3941 choices[i] =
3942 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
3943 ok = GNUNET_YES;
3944 for (unsigned int j = 0; j < i; j++)
3945 if (choices[i] == choices[j])
3946 { 3864 {
3947 ok = GNUNET_NO; 3865 choices[i] =
3948 break; 3866 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, num_dv);
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 }
3949 } 3874 }
3950 } 3875 }
3951 }
3952 dv_count = 0; 3876 dv_count = 0;
3953 num_dv = 0; 3877 num_dv = 0;
3954 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 3878 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
3955 pos = pos->next_dv) 3879 pos = pos->next_dv)
3956 { 3880 {
3957 uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance; 3881 uint32_t delta = MAX_DV_HOPS_ALLOWED - pos->distance;
3958 3882
3959 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) && 3883 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) &&
3960 (GNUNET_TIME_absolute_get_remaining (pos->path_valid_until) 3884 (GNUNET_TIME_absolute_get_remaining(pos->path_valid_until)
3961 .rel_value_us == 0)) 3885 .rel_value_us == 0))
3962 continue; /* pos unconfirmed and confirmed required */ 3886 continue; /* pos unconfirmed and confirmed required */
3963 for (unsigned int i = 0; i < hops_array_length; i++) 3887 for (unsigned int i = 0; i < hops_array_length; i++)
3964 if ((num_dv <= choices[i]) && (num_dv + delta > choices[i])) 3888 if ((num_dv <= choices[i]) && (num_dv + delta > choices[i]))
3965 hops_array[dv_count++] = pos; 3889 hops_array[dv_count++] = pos;
3966 num_dv += delta; 3890 num_dv += delta;
3967 } 3891 }
3968 return dv_count; 3892 return dv_count;
3969} 3893}
3970 3894
@@ -3976,7 +3900,7 @@ pick_random_dv_hops (const struct DistanceVector *dv,
3976 * @param cam the send message that was sent 3900 * @param cam the send message that was sent
3977 */ 3901 */
3978static int 3902static int
3979check_communicator_available ( 3903check_communicator_available(
3980 void *cls, 3904 void *cls,
3981 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 3905 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
3982{ 3906{
@@ -3984,15 +3908,15 @@ check_communicator_available (
3984 uint16_t size; 3908 uint16_t size;
3985 3909
3986 if (CT_NONE != tc->type) 3910 if (CT_NONE != tc->type)
3987 { 3911 {
3988 GNUNET_break (0); 3912 GNUNET_break(0);
3989 return GNUNET_SYSERR; 3913 return GNUNET_SYSERR;
3990 } 3914 }
3991 tc->type = CT_COMMUNICATOR; 3915 tc->type = CT_COMMUNICATOR;
3992 size = ntohs (cam->header.size) - sizeof (*cam); 3916 size = ntohs(cam->header.size) - sizeof(*cam);
3993 if (0 == size) 3917 if (0 == size)
3994 return GNUNET_OK; /* receive-only communicator */ 3918 return GNUNET_OK; /* receive-only communicator */
3995 GNUNET_MQ_check_zero_termination (cam); 3919 GNUNET_MQ_check_zero_termination(cam);
3996 return GNUNET_OK; 3920 return GNUNET_OK;
3997} 3921}
3998 3922
@@ -4003,22 +3927,22 @@ check_communicator_available (
4003 * @param cmc context for which we are done handling the message 3927 * @param cmc context for which we are done handling the message
4004 */ 3928 */
4005static void 3929static void
4006finish_cmc_handling (struct CommunicatorMessageContext *cmc) 3930finish_cmc_handling(struct CommunicatorMessageContext *cmc)
4007{ 3931{
4008 if (0 != ntohl (cmc->im.fc_on)) 3932 if (0 != ntohl(cmc->im.fc_on))
4009 { 3933 {
4010 /* send ACK when done to communicator for flow control! */ 3934 /* send ACK when done to communicator for flow control! */
4011 struct GNUNET_MQ_Envelope *env; 3935 struct GNUNET_MQ_Envelope *env;
4012 struct GNUNET_TRANSPORT_IncomingMessageAck *ack; 3936 struct GNUNET_TRANSPORT_IncomingMessageAck *ack;
4013 3937
4014 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK); 3938 env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK);
4015 ack->reserved = htonl (0); 3939 ack->reserved = htonl(0);
4016 ack->fc_id = cmc->im.fc_id; 3940 ack->fc_id = cmc->im.fc_id;
4017 ack->sender = cmc->im.sender; 3941 ack->sender = cmc->im.sender;
4018 GNUNET_MQ_send (cmc->tc->mq, env); 3942 GNUNET_MQ_send(cmc->tc->mq, env);
4019 } 3943 }
4020 GNUNET_SERVICE_client_continue (cmc->tc->client); 3944 GNUNET_SERVICE_client_continue(cmc->tc->client);
4021 GNUNET_free (cmc); 3945 GNUNET_free(cmc);
4022} 3946}
4023 3947
4024 3948
@@ -4032,7 +3956,7 @@ finish_cmc_handling (struct CommunicatorMessageContext *cmc)
4032 * @param rom the message that was sent 3956 * @param rom the message that was sent
4033 */ 3957 */
4034static void 3958static void
4035handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom) 3959handle_client_recv_ok(void *cls, const struct RecvOkMessage *rom)
4036{ 3960{
4037 struct TransportClient *tc = cls; 3961 struct TransportClient *tc = cls;
4038 struct VirtualLink *vl; 3962 struct VirtualLink *vl;
@@ -4040,31 +3964,31 @@ handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom)
4040 struct CommunicatorMessageContext *cmc; 3964 struct CommunicatorMessageContext *cmc;
4041 3965
4042 if (CT_CORE != tc->type) 3966 if (CT_CORE != tc->type)
4043 { 3967 {
4044 GNUNET_break (0); 3968 GNUNET_break(0);
4045 GNUNET_SERVICE_client_drop (tc->client); 3969 GNUNET_SERVICE_client_drop(tc->client);
4046 return; 3970 return;
4047 } 3971 }
4048 vl = lookup_virtual_link (&rom->peer); 3972 vl = lookup_virtual_link(&rom->peer);
4049 if (NULL == vl) 3973 if (NULL == vl)
4050 { 3974 {
4051 GNUNET_STATISTICS_update (GST_stats, 3975 GNUNET_STATISTICS_update(GST_stats,
4052 "# RECV_OK dropped: virtual link unknown", 3976 "# RECV_OK dropped: virtual link unknown",
4053 1, 3977 1,
4054 GNUNET_NO); 3978 GNUNET_NO);
4055 GNUNET_SERVICE_client_continue (tc->client); 3979 GNUNET_SERVICE_client_continue(tc->client);
4056 return; 3980 return;
4057 } 3981 }
4058 delta = ntohl (rom->increase_window_delta); 3982 delta = ntohl(rom->increase_window_delta);
4059 vl->core_recv_window += delta; 3983 vl->core_recv_window += delta;
4060 if (vl->core_recv_window <= 0) 3984 if (vl->core_recv_window <= 0)
4061 return; 3985 return;
4062 /* resume communicators */ 3986 /* resume communicators */
4063 while (NULL != (cmc = vl->cmc_tail)) 3987 while (NULL != (cmc = vl->cmc_tail))
4064 { 3988 {
4065 GNUNET_CONTAINER_DLL_remove (vl->cmc_head, vl->cmc_tail, cmc); 3989 GNUNET_CONTAINER_DLL_remove(vl->cmc_head, vl->cmc_tail, cmc);
4066 finish_cmc_handling (cmc); 3990 finish_cmc_handling(cmc);
4067 } 3991 }
4068} 3992}
4069 3993
4070 3994
@@ -4075,28 +3999,28 @@ handle_client_recv_ok (void *cls, const struct RecvOkMessage *rom)
4075 * @param cam the send message that was sent 3999 * @param cam the send message that was sent
4076 */ 4000 */
4077static void 4001static void
4078handle_communicator_available ( 4002handle_communicator_available(
4079 void *cls, 4003 void *cls,
4080 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam) 4004 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam)
4081{ 4005{
4082 struct TransportClient *tc = cls; 4006 struct TransportClient *tc = cls;
4083 uint16_t size; 4007 uint16_t size;
4084 4008
4085 size = ntohs (cam->header.size) - sizeof (*cam); 4009 size = ntohs(cam->header.size) - sizeof(*cam);
4086 if (0 == size) 4010 if (0 == size)
4087 { 4011 {
4088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4012 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4089 "Receive-only communicator connected\n"); 4013 "Receive-only communicator connected\n");
4090 return; /* receive-only communicator */ 4014 return; /* receive-only communicator */
4091 } 4015 }
4092 tc->details.communicator.address_prefix = 4016 tc->details.communicator.address_prefix =
4093 GNUNET_strdup ((const char *) &cam[1]); 4017 GNUNET_strdup((const char *)&cam[1]);
4094 tc->details.communicator.cc = 4018 tc->details.communicator.cc =
4095 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics) ntohl (cam->cc); 4019 (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(cam->cc);
4096 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4020 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4097 "Communicator with prefix `%s' connected\n", 4021 "Communicator with prefix `%s' connected\n",
4098 tc->details.communicator.address_prefix); 4022 tc->details.communicator.address_prefix);
4099 GNUNET_SERVICE_client_continue (tc->client); 4023 GNUNET_SERVICE_client_continue(tc->client);
4100} 4024}
4101 4025
4102 4026
@@ -4108,7 +4032,7 @@ handle_communicator_available (
4108 * @return #GNUNET_OK if message is well-formed 4032 * @return #GNUNET_OK if message is well-formed
4109 */ 4033 */
4110static int 4034static int
4111check_communicator_backchannel ( 4035check_communicator_backchannel(
4112 void *cls, 4036 void *cls,
4113 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 4037 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
4114{ 4038{
@@ -4117,24 +4041,24 @@ check_communicator_backchannel (
4117 uint16_t msize; 4041 uint16_t msize;
4118 uint16_t isize; 4042 uint16_t isize;
4119 4043
4120 (void) cls; 4044 (void)cls;
4121 msize = ntohs (cb->header.size) - sizeof (*cb); 4045 msize = ntohs(cb->header.size) - sizeof(*cb);
4122 inbox = (const struct GNUNET_MessageHeader *) &cb[1]; 4046 inbox = (const struct GNUNET_MessageHeader *)&cb[1];
4123 isize = ntohs (inbox->size); 4047 isize = ntohs(inbox->size);
4124 if (isize >= msize) 4048 if (isize >= msize)
4125 { 4049 {
4126 GNUNET_break (0); 4050 GNUNET_break(0);
4127 return GNUNET_SYSERR; 4051 return GNUNET_SYSERR;
4128 } 4052 }
4129 is = (const char *) inbox; 4053 is = (const char *)inbox;
4130 is += isize; 4054 is += isize;
4131 msize -= isize; 4055 msize -= isize;
4132 GNUNET_assert (0 < msize); 4056 GNUNET_assert(0 < msize);
4133 if ('\0' != is[msize - 1]) 4057 if ('\0' != is[msize - 1])
4134 { 4058 {
4135 GNUNET_break (0); 4059 GNUNET_break(0);
4136 return GNUNET_SYSERR; 4060 return GNUNET_SYSERR;
4137 } 4061 }
4138 return GNUNET_OK; 4062 return GNUNET_OK;
4139} 4063}
4140 4064
@@ -4146,26 +4070,26 @@ check_communicator_backchannel (
4146 * @param dv[in,out] virtual link to update ephemeral for 4070 * @param dv[in,out] virtual link to update ephemeral for
4147 */ 4071 */
4148static void 4072static void
4149update_ephemeral (struct DistanceVector *dv) 4073update_ephemeral(struct DistanceVector *dv)
4150{ 4074{
4151 struct EphemeralConfirmationPS ec; 4075 struct EphemeralConfirmationPS ec;
4152 4076
4153 if (0 != 4077 if (0 !=
4154 GNUNET_TIME_absolute_get_remaining (dv->ephemeral_validity).rel_value_us) 4078 GNUNET_TIME_absolute_get_remaining(dv->ephemeral_validity).rel_value_us)
4155 return; 4079 return;
4156 dv->monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 4080 dv->monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
4157 dv->ephemeral_validity = 4081 dv->ephemeral_validity =
4158 GNUNET_TIME_absolute_add (dv->monotime, EPHEMERAL_VALIDITY); 4082 GNUNET_TIME_absolute_add(dv->monotime, EPHEMERAL_VALIDITY);
4159 GNUNET_assert (GNUNET_OK == 4083 GNUNET_assert(GNUNET_OK ==
4160 GNUNET_CRYPTO_ecdhe_key_create2 (&dv->private_key)); 4084 GNUNET_CRYPTO_ecdhe_key_create2(&dv->private_key));
4161 GNUNET_CRYPTO_ecdhe_key_get_public (&dv->private_key, &dv->ephemeral_key); 4085 GNUNET_CRYPTO_ecdhe_key_get_public(&dv->private_key, &dv->ephemeral_key);
4162 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL); 4086 ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
4163 ec.purpose.size = htonl (sizeof (ec)); 4087 ec.purpose.size = htonl(sizeof(ec));
4164 ec.target = dv->target; 4088 ec.target = dv->target;
4165 ec.ephemeral_key = dv->ephemeral_key; 4089 ec.ephemeral_key = dv->ephemeral_key;
4166 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 4090 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
4167 &ec.purpose, 4091 &ec.purpose,
4168 &dv->sender_sig)); 4092 &dv->sender_sig));
4169} 4093}
4170 4094
4171 4095
@@ -4179,45 +4103,45 @@ update_ephemeral (struct DistanceVector *dv)
4179 * @param payload_size number of bytes in @a payload 4103 * @param payload_size number of bytes in @a payload
4180 */ 4104 */
4181static void 4105static void
4182queue_send_msg (struct Queue *queue, 4106queue_send_msg(struct Queue *queue,
4183 struct PendingMessage *pm, 4107 struct PendingMessage *pm,
4184 const void *payload, 4108 const void *payload,
4185 size_t payload_size) 4109 size_t payload_size)
4186{ 4110{
4187 struct Neighbour *n = queue->neighbour; 4111 struct Neighbour *n = queue->neighbour;
4188 struct GNUNET_TRANSPORT_SendMessageTo *smt; 4112 struct GNUNET_TRANSPORT_SendMessageTo *smt;
4189 struct GNUNET_MQ_Envelope *env; 4113 struct GNUNET_MQ_Envelope *env;
4190 4114
4191 queue->idle = GNUNET_NO; 4115 queue->idle = GNUNET_NO;
4192 GNUNET_log ( 4116 GNUNET_log(
4193 GNUNET_ERROR_TYPE_DEBUG, 4117 GNUNET_ERROR_TYPE_DEBUG,
4194 "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n", 4118 "Queueing %u bytes of payload for transmission <%llu> on queue %llu to %s\n",
4195 (unsigned int) payload_size, 4119 (unsigned int)payload_size,
4196 (NULL == pm) ? 0 : pm->logging_uuid, 4120 (NULL == pm) ? 0 : pm->logging_uuid,
4197 (unsigned long long) queue->qid, 4121 (unsigned long long)queue->qid,
4198 GNUNET_i2s (&queue->neighbour->pid)); 4122 GNUNET_i2s(&queue->neighbour->pid));
4199 env = GNUNET_MQ_msg_extra (smt, 4123 env = GNUNET_MQ_msg_extra(smt,
4200 payload_size, 4124 payload_size,
4201 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); 4125 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
4202 smt->qid = queue->qid; 4126 smt->qid = queue->qid;
4203 smt->mid = queue->mid_gen; 4127 smt->mid = queue->mid_gen;
4204 smt->receiver = n->pid; 4128 smt->receiver = n->pid;
4205 memcpy (&smt[1], payload, payload_size); 4129 memcpy(&smt[1], payload, payload_size);
4206 { 4130 {
4207 /* Pass the env to the communicator of queue for transmission. */ 4131 /* Pass the env to the communicator of queue for transmission. */
4208 struct QueueEntry *qe; 4132 struct QueueEntry *qe;
4209 4133
4210 qe = GNUNET_new (struct QueueEntry); 4134 qe = GNUNET_new(struct QueueEntry);
4211 qe->mid = queue->mid_gen++; 4135 qe->mid = queue->mid_gen++;
4212 qe->queue = queue; 4136 qe->queue = queue;
4213 if (NULL != pm) 4137 if (NULL != pm)
4214 { 4138 {
4215 qe->pm = pm; 4139 qe->pm = pm;
4216 GNUNET_assert (NULL == pm->qe); 4140 GNUNET_assert(NULL == pm->qe);
4217 pm->qe = qe; 4141 pm->qe = qe;
4218 } 4142 }
4219 GNUNET_CONTAINER_DLL_insert (queue->queue_head, queue->queue_tail, qe); 4143 GNUNET_CONTAINER_DLL_insert(queue->queue_head, queue->queue_tail, qe);
4220 GNUNET_assert (CT_COMMUNICATOR == queue->tc->type); 4144 GNUNET_assert(CT_COMMUNICATOR == queue->tc->type);
4221 queue->queue_length++; 4145 queue->queue_length++;
4222 queue->tc->details.communicator.total_queue_length++; 4146 queue->tc->details.communicator.total_queue_length++;
4223 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT == 4147 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT ==
@@ -4225,7 +4149,7 @@ queue_send_msg (struct Queue *queue,
4225 queue->idle = GNUNET_NO; 4149 queue->idle = GNUNET_NO;
4226 if (QUEUE_LENGTH_LIMIT == queue->queue_length) 4150 if (QUEUE_LENGTH_LIMIT == queue->queue_length)
4227 queue->idle = GNUNET_NO; 4151 queue->idle = GNUNET_NO;
4228 GNUNET_MQ_send (queue->tc->mq, env); 4152 GNUNET_MQ_send(queue->tc->mq, env);
4229 } 4153 }
4230} 4154}
4231 4155
@@ -4241,9 +4165,9 @@ queue_send_msg (struct Queue *queue,
4241 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4165 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4242 */ 4166 */
4243static struct GNUNET_TIME_Relative 4167static struct GNUNET_TIME_Relative
4244route_via_neighbour (const struct Neighbour *n, 4168route_via_neighbour(const struct Neighbour *n,
4245 const struct GNUNET_MessageHeader *hdr, 4169 const struct GNUNET_MessageHeader *hdr,
4246 enum RouteMessageOptions options) 4170 enum RouteMessageOptions options)
4247{ 4171{
4248 struct GNUNET_TIME_Absolute now; 4172 struct GNUNET_TIME_Absolute now;
4249 unsigned int candidates; 4173 unsigned int candidates;
@@ -4252,7 +4176,7 @@ route_via_neighbour (const struct Neighbour *n,
4252 struct GNUNET_TIME_Relative rtt; 4176 struct GNUNET_TIME_Relative rtt;
4253 4177
4254 /* Pick one or two 'random' queues from n (under constraints of options) */ 4178 /* Pick one or two 'random' queues from n (under constraints of options) */
4255 now = GNUNET_TIME_absolute_get (); 4179 now = GNUNET_TIME_absolute_get();
4256 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to 4180 /* FIXME-OPTIMIZE: give queues 'weights' and pick proportional to
4257 weight in the future; weight could be assigned by observed 4181 weight in the future; weight could be assigned by observed
4258 bandwidth (note: not sure if we should do this for this type 4182 bandwidth (note: not sure if we should do this for this type
@@ -4260,53 +4184,53 @@ route_via_neighbour (const struct Neighbour *n,
4260 candidates = 0; 4184 candidates = 0;
4261 for (struct Queue *pos = n->queue_head; NULL != pos; 4185 for (struct Queue *pos = n->queue_head; NULL != pos;
4262 pos = pos->next_neighbour) 4186 pos = pos->next_neighbour)
4263 { 4187 {
4264 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) || 4188 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4265 (pos->validated_until.abs_value_us > now.abs_value_us)) 4189 (pos->validated_until.abs_value_us > now.abs_value_us))
4266 candidates++; 4190 candidates++;
4267 } 4191 }
4268 if (0 == candidates) 4192 if (0 == candidates)
4269 { 4193 {
4270 /* This can happen rarely if the last confirmed queue timed 4194 /* This can happen rarely if the last confirmed queue timed
4271 out just as we were beginning to process this message. */ 4195 out just as we were beginning to process this message. */
4272 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4196 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
4273 "Could not route message of type %u to %s: no valid queue\n", 4197 "Could not route message of type %u to %s: no valid queue\n",
4274 ntohs (hdr->type), 4198 ntohs(hdr->type),
4275 GNUNET_i2s (&n->pid)); 4199 GNUNET_i2s(&n->pid));
4276 GNUNET_STATISTICS_update (GST_stats, 4200 GNUNET_STATISTICS_update(GST_stats,
4277 "# route selection failed (all no valid queue)", 4201 "# route selection failed (all no valid queue)",
4278 1, 4202 1,
4279 GNUNET_NO); 4203 GNUNET_NO);
4280 return GNUNET_TIME_UNIT_FOREVER_REL; 4204 return GNUNET_TIME_UNIT_FOREVER_REL;
4281 } 4205 }
4282 4206
4283 rtt = GNUNET_TIME_UNIT_FOREVER_REL; 4207 rtt = GNUNET_TIME_UNIT_FOREVER_REL;
4284 sel1 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); 4208 sel1 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates);
4285 if (0 == (options & RMO_REDUNDANT)) 4209 if (0 == (options & RMO_REDUNDANT))
4286 sel2 = candidates; /* picks none! */ 4210 sel2 = candidates; /* picks none! */
4287 else 4211 else
4288 sel2 = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, candidates); 4212 sel2 = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, candidates);
4289 candidates = 0; 4213 candidates = 0;
4290 for (struct Queue *pos = n->queue_head; NULL != pos; 4214 for (struct Queue *pos = n->queue_head; NULL != pos;
4291 pos = pos->next_neighbour) 4215 pos = pos->next_neighbour)
4292 {
4293 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4294 (pos->validated_until.abs_value_us > now.abs_value_us))
4295 { 4216 {
4296 if ((sel1 == candidates) || (sel2 == candidates)) 4217 if ((0 == (options & RMO_UNCONFIRMED_ALLOWED)) ||
4297 { 4218 (pos->validated_until.abs_value_us > now.abs_value_us))
4298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4219 {
4299 "Routing message of type %u to %s using %s (#%u)\n", 4220 if ((sel1 == candidates) || (sel2 == candidates))
4300 ntohs (hdr->type), 4221 {
4301 GNUNET_i2s (&n->pid), 4222 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4302 pos->address, 4223 "Routing message of type %u to %s using %s (#%u)\n",
4303 (sel1 == candidates) ? 1 : 2); 4224 ntohs(hdr->type),
4304 rtt = GNUNET_TIME_relative_min (rtt, pos->pd.aged_rtt); 4225 GNUNET_i2s(&n->pid),
4305 queue_send_msg (pos, NULL, hdr, ntohs (hdr->size)); 4226 pos->address,
4306 } 4227 (sel1 == candidates) ? 1 : 2);
4307 candidates++; 4228 rtt = GNUNET_TIME_relative_min(rtt, pos->pd.aged_rtt);
4229 queue_send_msg(pos, NULL, hdr, ntohs(hdr->size));
4230 }
4231 candidates++;
4232 }
4308 } 4233 }
4309 }
4310 return rtt; 4234 return rtt;
4311} 4235}
4312 4236
@@ -4314,8 +4238,7 @@ route_via_neighbour (const struct Neighbour *n,
4314/** 4238/**
4315 * Structure of the key material used to encrypt backchannel messages. 4239 * Structure of the key material used to encrypt backchannel messages.
4316 */ 4240 */
4317struct DVKeyState 4241struct DVKeyState {
4318{
4319 /** 4242 /**
4320 * State of our block cipher. 4243 * State of our block cipher.
4321 */ 4244 */
@@ -4324,9 +4247,7 @@ struct DVKeyState
4324 /** 4247 /**
4325 * Actual key material. 4248 * Actual key material.
4326 */ 4249 */
4327 struct 4250 struct {
4328 {
4329
4330 /** 4251 /**
4331 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()). 4252 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
4332 */ 4253 */
@@ -4341,7 +4262,6 @@ struct DVKeyState
4341 * Counter value to use during setup. 4262 * Counter value to use during setup.
4342 */ 4263 */
4343 char aes_ctr[128 / 8]; 4264 char aes_ctr[128 / 8];
4344
4345 } material; 4265 } material;
4346}; 4266};
4347 4267
@@ -4355,34 +4275,34 @@ struct DVKeyState
4355 * @param key[out] symmetric cipher and HMAC state to generate 4275 * @param key[out] symmetric cipher and HMAC state to generate
4356 */ 4276 */
4357static void 4277static void
4358dv_setup_key_state_from_km (const struct GNUNET_HashCode *km, 4278dv_setup_key_state_from_km(const struct GNUNET_HashCode *km,
4359 const struct GNUNET_ShortHashCode *iv, 4279 const struct GNUNET_ShortHashCode *iv,
4360 struct DVKeyState *key) 4280 struct DVKeyState *key)
4361{ 4281{
4362 /* must match #dh_key_derive_eph_pub */ 4282 /* must match #dh_key_derive_eph_pub */
4363 GNUNET_assert (GNUNET_YES == 4283 GNUNET_assert(GNUNET_YES ==
4364 GNUNET_CRYPTO_kdf (&key->material, 4284 GNUNET_CRYPTO_kdf(&key->material,
4365 sizeof (key->material), 4285 sizeof(key->material),
4366 "transport-backchannel-key", 4286 "transport-backchannel-key",
4367 strlen ("transport-backchannel-key"), 4287 strlen("transport-backchannel-key"),
4368 &km, 4288 &km,
4369 sizeof (km), 4289 sizeof(km),
4370 iv, 4290 iv,
4371 sizeof (*iv))); 4291 sizeof(*iv)));
4372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4292 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4373 "Deriving backchannel key based on KM %s and IV %s\n", 4293 "Deriving backchannel key based on KM %s and IV %s\n",
4374 GNUNET_h2s (km), 4294 GNUNET_h2s(km),
4375 GNUNET_sh2s (iv)); 4295 GNUNET_sh2s(iv));
4376 gcry_cipher_open (&key->cipher, 4296 gcry_cipher_open(&key->cipher,
4377 GCRY_CIPHER_AES256 /* low level: go for speed */, 4297 GCRY_CIPHER_AES256 /* low level: go for speed */,
4378 GCRY_CIPHER_MODE_CTR, 4298 GCRY_CIPHER_MODE_CTR,
4379 0 /* flags */); 4299 0 /* flags */);
4380 gcry_cipher_setkey (key->cipher, 4300 gcry_cipher_setkey(key->cipher,
4381 &key->material.aes_key, 4301 &key->material.aes_key,
4382 sizeof (key->material.aes_key)); 4302 sizeof(key->material.aes_key));
4383 gcry_cipher_setctr (key->cipher, 4303 gcry_cipher_setctr(key->cipher,
4384 &key->material.aes_ctr, 4304 &key->material.aes_ctr,
4385 sizeof (key->material.aes_ctr)); 4305 sizeof(key->material.aes_ctr));
4386} 4306}
4387 4307
4388 4308
@@ -4396,7 +4316,7 @@ dv_setup_key_state_from_km (const struct GNUNET_HashCode *km,
4396 * @param key[out] set to the key material 4316 * @param key[out] set to the key material
4397 */ 4317 */
4398static void 4318static void
4399dh_key_derive_eph_pid ( 4319dh_key_derive_eph_pid(
4400 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral, 4320 const struct GNUNET_CRYPTO_EcdhePrivateKey *priv_ephemeral,
4401 const struct GNUNET_PeerIdentity *target, 4321 const struct GNUNET_PeerIdentity *target,
4402 const struct GNUNET_ShortHashCode *iv, 4322 const struct GNUNET_ShortHashCode *iv,
@@ -4404,10 +4324,10 @@ dh_key_derive_eph_pid (
4404{ 4324{
4405 struct GNUNET_HashCode km; 4325 struct GNUNET_HashCode km;
4406 4326
4407 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa (priv_ephemeral, 4327 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_ecdh_eddsa(priv_ephemeral,
4408 &target->public_key, 4328 &target->public_key,
4409 &km)); 4329 &km));
4410 dv_setup_key_state_from_km (&km, iv, key); 4330 dv_setup_key_state_from_km(&km, iv, key);
4411} 4331}
4412 4332
4413 4333
@@ -4421,16 +4341,16 @@ dh_key_derive_eph_pid (
4421 * @param key[out] set to the key material 4341 * @param key[out] set to the key material
4422 */ 4342 */
4423static void 4343static void
4424dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral, 4344dh_key_derive_eph_pub(const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
4425 const struct GNUNET_ShortHashCode *iv, 4345 const struct GNUNET_ShortHashCode *iv,
4426 struct DVKeyState *key) 4346 struct DVKeyState *key)
4427{ 4347{
4428 struct GNUNET_HashCode km; 4348 struct GNUNET_HashCode km;
4429 4349
4430 GNUNET_assert (GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh (GST_my_private_key, 4350 GNUNET_assert(GNUNET_YES == GNUNET_CRYPTO_eddsa_ecdh(GST_my_private_key,
4431 pub_ephemeral, 4351 pub_ephemeral,
4432 &km)); 4352 &km));
4433 dv_setup_key_state_from_km (&km, iv, key); 4353 dv_setup_key_state_from_km(&km, iv, key);
4434} 4354}
4435 4355
4436 4356
@@ -4444,12 +4364,12 @@ dh_key_derive_eph_pub (const struct GNUNET_CRYPTO_EcdhePublicKey *pub_ephemeral,
4444 * @param data_size number of bytes in @a data 4364 * @param data_size number of bytes in @a data
4445 */ 4365 */
4446static void 4366static void
4447dv_hmac (const struct DVKeyState *key, 4367dv_hmac(const struct DVKeyState *key,
4448 struct GNUNET_HashCode *hmac, 4368 struct GNUNET_HashCode *hmac,
4449 const void *data, 4369 const void *data,
4450 size_t data_size) 4370 size_t data_size)
4451{ 4371{
4452 GNUNET_CRYPTO_hmac (&key->material.hmac_key, data, data_size, hmac); 4372 GNUNET_CRYPTO_hmac(&key->material.hmac_key, data, data_size, hmac);
4453} 4373}
4454 4374
4455 4375
@@ -4463,10 +4383,10 @@ dv_hmac (const struct DVKeyState *key,
4463 * @param in_size number of bytes of input in @a in and available at @a dst 4383 * @param in_size number of bytes of input in @a in and available at @a dst
4464 */ 4384 */
4465static void 4385static void
4466dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size) 4386dv_encrypt(struct DVKeyState *key, const void *in, void *dst, size_t in_size)
4467{ 4387{
4468 GNUNET_assert (0 == 4388 GNUNET_assert(0 ==
4469 gcry_cipher_encrypt (key->cipher, dst, in_size, in, in_size)); 4389 gcry_cipher_encrypt(key->cipher, dst, in_size, in, in_size));
4470} 4390}
4471 4391
4472 4392
@@ -4480,13 +4400,13 @@ dv_encrypt (struct DVKeyState *key, const void *in, void *dst, size_t in_size)
4480 * @param out_size number of bytes of input in @a ciph and available in @a out 4400 * @param out_size number of bytes of input in @a ciph and available in @a out
4481 */ 4401 */
4482static void 4402static void
4483dv_decrypt (struct DVKeyState *key, 4403dv_decrypt(struct DVKeyState *key,
4484 void *out, 4404 void *out,
4485 const void *ciph, 4405 const void *ciph,
4486 size_t out_size) 4406 size_t out_size)
4487{ 4407{
4488 GNUNET_assert ( 4408 GNUNET_assert(
4489 0 == gcry_cipher_decrypt (key->cipher, out, out_size, ciph, out_size)); 4409 0 == gcry_cipher_decrypt(key->cipher, out, out_size, ciph, out_size));
4490} 4410}
4491 4411
4492 4412
@@ -4496,10 +4416,10 @@ dv_decrypt (struct DVKeyState *key,
4496 * @param key key material to clean up (memory must not be free'd!) 4416 * @param key key material to clean up (memory must not be free'd!)
4497 */ 4417 */
4498static void 4418static void
4499dv_key_clean (struct DVKeyState *key) 4419dv_key_clean(struct DVKeyState *key)
4500{ 4420{
4501 gcry_cipher_close (key->cipher); 4421 gcry_cipher_close(key->cipher);
4502 GNUNET_CRYPTO_zero_keys (&key->material, sizeof (key->material)); 4422 GNUNET_CRYPTO_zero_keys(&key->material, sizeof(key->material));
4503} 4423}
4504 4424
4505 4425
@@ -4532,92 +4452,92 @@ typedef void (*DVMessageHandler) (void *cls,
4532 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4452 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4533 */ 4453 */
4534static struct GNUNET_TIME_Relative 4454static struct GNUNET_TIME_Relative
4535encapsulate_for_dv (struct DistanceVector *dv, 4455encapsulate_for_dv(struct DistanceVector *dv,
4536 unsigned int num_dvhs, 4456 unsigned int num_dvhs,
4537 struct DistanceVectorHop **dvhs, 4457 struct DistanceVectorHop **dvhs,
4538 const struct GNUNET_MessageHeader *hdr, 4458 const struct GNUNET_MessageHeader *hdr,
4539 DVMessageHandler use, 4459 DVMessageHandler use,
4540 void *use_cls, 4460 void *use_cls,
4541 enum RouteMessageOptions options) 4461 enum RouteMessageOptions options)
4542{ 4462{
4543 struct TransportDVBoxMessage box_hdr; 4463 struct TransportDVBoxMessage box_hdr;
4544 struct TransportDVBoxPayloadP payload_hdr; 4464 struct TransportDVBoxPayloadP payload_hdr;
4545 uint16_t enc_body_size = ntohs (hdr->size); 4465 uint16_t enc_body_size = ntohs(hdr->size);
4546 char enc[sizeof (struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN; 4466 char enc[sizeof(struct TransportDVBoxPayloadP) + enc_body_size] GNUNET_ALIGN;
4547 struct TransportDVBoxPayloadP *enc_payload_hdr = 4467 struct TransportDVBoxPayloadP *enc_payload_hdr =
4548 (struct TransportDVBoxPayloadP *) enc; 4468 (struct TransportDVBoxPayloadP *)enc;
4549 struct DVKeyState key; 4469 struct DVKeyState key;
4550 struct GNUNET_TIME_Relative rtt; 4470 struct GNUNET_TIME_Relative rtt;
4551 4471
4552 /* Encrypt payload */ 4472 /* Encrypt payload */
4553 box_hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX); 4473 box_hdr.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX);
4554 box_hdr.total_hops = htons (0); 4474 box_hdr.total_hops = htons(0);
4555 update_ephemeral (dv); 4475 update_ephemeral(dv);
4556 box_hdr.ephemeral_key = dv->ephemeral_key; 4476 box_hdr.ephemeral_key = dv->ephemeral_key;
4557 payload_hdr.sender_sig = dv->sender_sig; 4477 payload_hdr.sender_sig = dv->sender_sig;
4558 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 4478 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
4559 &box_hdr.iv, 4479 &box_hdr.iv,
4560 sizeof (box_hdr.iv)); 4480 sizeof(box_hdr.iv));
4561 dh_key_derive_eph_pid (&dv->private_key, &dv->target, &box_hdr.iv, &key); 4481 dh_key_derive_eph_pid(&dv->private_key, &dv->target, &box_hdr.iv, &key);
4562 payload_hdr.sender = GST_my_identity; 4482 payload_hdr.sender = GST_my_identity;
4563 payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton (dv->monotime); 4483 payload_hdr.monotonic_time = GNUNET_TIME_absolute_hton(dv->monotime);
4564 dv_encrypt (&key, &payload_hdr, enc_payload_hdr, sizeof (payload_hdr)); 4484 dv_encrypt(&key, &payload_hdr, enc_payload_hdr, sizeof(payload_hdr));
4565 dv_encrypt (&key, 4485 dv_encrypt(&key,
4566 hdr, 4486 hdr,
4567 &enc[sizeof (struct TransportDVBoxPayloadP)], 4487 &enc[sizeof(struct TransportDVBoxPayloadP)],
4568 enc_body_size); 4488 enc_body_size);
4569 dv_hmac (&key, &box_hdr.hmac, enc, sizeof (enc)); 4489 dv_hmac(&key, &box_hdr.hmac, enc, sizeof(enc));
4570 dv_key_clean (&key); 4490 dv_key_clean(&key);
4571 rtt = GNUNET_TIME_UNIT_FOREVER_REL; 4491 rtt = GNUNET_TIME_UNIT_FOREVER_REL;
4572 /* For each selected path, take the pre-computed header and body 4492 /* For each selected path, take the pre-computed header and body
4573 and add the path in the middle of the message; then send it. */ 4493 and add the path in the middle of the message; then send it. */
4574 for (unsigned int i = 0; i < num_dvhs; i++) 4494 for (unsigned int i = 0; i < num_dvhs; i++)
4575 {
4576 struct DistanceVectorHop *dvh = dvhs[i];
4577 unsigned int num_hops = dvh->distance + 1;
4578 char buf[sizeof (struct TransportDVBoxMessage) +
4579 sizeof (struct GNUNET_PeerIdentity) * num_hops +
4580 sizeof (struct TransportDVBoxPayloadP) +
4581 enc_body_size] GNUNET_ALIGN;
4582 struct GNUNET_PeerIdentity *dhops;
4583
4584 box_hdr.header.size = htons (sizeof (buf));
4585 box_hdr.num_hops = htons (num_hops);
4586 memcpy (buf, &box_hdr, sizeof (box_hdr));
4587 dhops = (struct GNUNET_PeerIdentity *) &buf[sizeof (box_hdr)];
4588 memcpy (dhops,
4589 dvh->path,
4590 dvh->distance * sizeof (struct GNUNET_PeerIdentity));
4591 dhops[dvh->distance] = dv->target;
4592 if (GNUNET_EXTRA_LOGGING > 0)
4593 { 4495 {
4594 char *path; 4496 struct DistanceVectorHop *dvh = dvhs[i];
4595 4497 unsigned int num_hops = dvh->distance + 1;
4596 path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity)); 4498 char buf[sizeof(struct TransportDVBoxMessage) +
4597 for (unsigned int j = 0; j <= num_hops; j++) 4499 sizeof(struct GNUNET_PeerIdentity) * num_hops +
4598 { 4500 sizeof(struct TransportDVBoxPayloadP) +
4599 char *tmp; 4501 enc_body_size] GNUNET_ALIGN;
4600 4502 struct GNUNET_PeerIdentity *dhops;
4601 GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j])); 4503
4602 GNUNET_free (path); 4504 box_hdr.header.size = htons(sizeof(buf));
4603 path = tmp; 4505 box_hdr.num_hops = htons(num_hops);
4604 } 4506 memcpy(buf, &box_hdr, sizeof(box_hdr));
4605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4507 dhops = (struct GNUNET_PeerIdentity *)&buf[sizeof(box_hdr)];
4606 "Routing message of type %u to %s using DV (#%u/%u) via %s\n", 4508 memcpy(dhops,
4607 ntohs (hdr->type), 4509 dvh->path,
4608 GNUNET_i2s (&dv->target), 4510 dvh->distance * sizeof(struct GNUNET_PeerIdentity));
4609 i + 1, 4511 dhops[dvh->distance] = dv->target;
4610 num_dvhs + 1, 4512 if (GNUNET_EXTRA_LOGGING > 0)
4611 path); 4513 {
4612 GNUNET_free (path); 4514 char *path;
4613 } 4515
4614 rtt = GNUNET_TIME_relative_min (rtt, dvh->pd.aged_rtt); 4516 path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity));
4615 memcpy (&dhops[num_hops], enc, sizeof (enc)); 4517 for (unsigned int j = 0; j <= num_hops; j++)
4616 use (use_cls, 4518 {
4617 dvh->next_hop, 4519 char *tmp;
4618 (const struct GNUNET_MessageHeader *) buf, 4520
4619 options); 4521 GNUNET_asprintf(&tmp, "%s-%s", path, GNUNET_i2s(&dhops[j]));
4620 } 4522 GNUNET_free(path);
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 }
4621 return rtt; 4541 return rtt;
4622} 4542}
4623 4543
@@ -4632,13 +4552,13 @@ encapsulate_for_dv (struct DistanceVector *dv,
4632 * @param options message options for queue selection 4552 * @param options message options for queue selection
4633 */ 4553 */
4634static void 4554static void
4635send_dv_to_neighbour (void *cls, 4555send_dv_to_neighbour(void *cls,
4636 struct Neighbour *next_hop, 4556 struct Neighbour *next_hop,
4637 const struct GNUNET_MessageHeader *hdr, 4557 const struct GNUNET_MessageHeader *hdr,
4638 enum RouteMessageOptions options) 4558 enum RouteMessageOptions options)
4639{ 4559{
4640 (void) cls; 4560 (void)cls;
4641 (void) route_via_neighbour (next_hop, hdr, options); 4561 (void)route_via_neighbour(next_hop, hdr, options);
4642} 4562}
4643 4563
4644 4564
@@ -4654,9 +4574,9 @@ send_dv_to_neighbour (void *cls,
4654 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4574 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4655 */ 4575 */
4656static struct GNUNET_TIME_Relative 4576static struct GNUNET_TIME_Relative
4657route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, 4577route_control_message_without_fc(const struct GNUNET_PeerIdentity *target,
4658 const struct GNUNET_MessageHeader *hdr, 4578 const struct GNUNET_MessageHeader *hdr,
4659 enum RouteMessageOptions options) 4579 enum RouteMessageOptions options)
4660{ 4580{
4661 struct VirtualLink *vl; 4581 struct VirtualLink *vl;
4662 struct Neighbour *n; 4582 struct Neighbour *n;
@@ -4664,78 +4584,78 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4664 struct GNUNET_TIME_Relative rtt1; 4584 struct GNUNET_TIME_Relative rtt1;
4665 struct GNUNET_TIME_Relative rtt2; 4585 struct GNUNET_TIME_Relative rtt2;
4666 4586
4667 vl = lookup_virtual_link (target); 4587 vl = lookup_virtual_link(target);
4668 GNUNET_assert (NULL != vl); 4588 GNUNET_assert(NULL != vl);
4669 n = vl->n; 4589 n = vl->n;
4670 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL; 4590 dv = (0 != (options & RMO_DV_ALLOWED)) ? vl->dv : NULL;
4671 if (0 == (options & RMO_UNCONFIRMED_ALLOWED)) 4591 if (0 == (options & RMO_UNCONFIRMED_ALLOWED))
4672 { 4592 {
4673 /* if confirmed is required, and we do not have anything 4593 /* if confirmed is required, and we do not have anything
4674 confirmed, drop respective options */ 4594 confirmed, drop respective options */
4675 if (NULL == n) 4595 if (NULL == n)
4676 n = lookup_neighbour (target); 4596 n = lookup_neighbour(target);
4677 if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED))) 4597 if ((NULL == dv) && (0 != (options & RMO_DV_ALLOWED)))
4678 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, target); 4598 dv = GNUNET_CONTAINER_multipeermap_get(dv_routes, target);
4679 } 4599 }
4680 if ((NULL == n) && (NULL == dv)) 4600 if ((NULL == n) && (NULL == dv))
4681 { 4601 {
4682 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4602 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
4683 "Cannot route message of type %u to %s: no route\n", 4603 "Cannot route message of type %u to %s: no route\n",
4684 ntohs (hdr->type), 4604 ntohs(hdr->type),
4685 GNUNET_i2s (target)); 4605 GNUNET_i2s(target));
4686 GNUNET_STATISTICS_update (GST_stats, 4606 GNUNET_STATISTICS_update(GST_stats,
4687 "# Messages dropped in routing: no acceptable method", 4607 "# Messages dropped in routing: no acceptable method",
4688 1, 4608 1,
4689 GNUNET_NO); 4609 GNUNET_NO);
4690 return GNUNET_TIME_UNIT_FOREVER_REL; 4610 return GNUNET_TIME_UNIT_FOREVER_REL;
4691 } 4611 }
4692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4612 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4693 "Routing message of type %u to %s with options %X\n", 4613 "Routing message of type %u to %s with options %X\n",
4694 ntohs (hdr->type), 4614 ntohs(hdr->type),
4695 GNUNET_i2s (target), 4615 GNUNET_i2s(target),
4696 (unsigned int) options); 4616 (unsigned int)options);
4697 /* If both dv and n are possible and we must choose: 4617 /* If both dv and n are possible and we must choose:
4698 flip a coin for the choice between the two; for now 50/50 */ 4618 flip a coin for the choice between the two; for now 50/50 */
4699 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT))) 4619 if ((NULL != n) && (NULL != dv) && (0 == (options & RMO_REDUNDANT)))
4700 { 4620 {
4701 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 2)) 4621 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2))
4702 n = NULL; 4622 n = NULL;
4703 else 4623 else
4704 dv = NULL; 4624 dv = NULL;
4705 } 4625 }
4706 if ((NULL != n) && (NULL != dv)) 4626 if ((NULL != n) && (NULL != dv))
4707 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's 4627 options &= ~RMO_REDUNDANT; /* We will do one DV and one direct, that's
4708 enough for redunancy, so clear the flag. */ 4628 enough for redunancy, so clear the flag. */
4709 rtt1 = GNUNET_TIME_UNIT_FOREVER_REL; 4629 rtt1 = GNUNET_TIME_UNIT_FOREVER_REL;
4710 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL; 4630 rtt2 = GNUNET_TIME_UNIT_FOREVER_REL;
4711 if (NULL != n) 4631 if (NULL != n)
4712 { 4632 {
4713 rtt1 = route_via_neighbour (n, hdr, options); 4633 rtt1 = route_via_neighbour(n, hdr, options);
4714 } 4634 }
4715 if (NULL != dv) 4635 if (NULL != dv)
4716 { 4636 {
4717 struct DistanceVectorHop *hops[2]; 4637 struct DistanceVectorHop *hops[2];
4718 unsigned int res; 4638 unsigned int res;
4719 4639
4720 res = pick_random_dv_hops (dv, 4640 res = pick_random_dv_hops(dv,
4721 options, 4641 options,
4722 hops, 4642 hops,
4723 (0 == (options & RMO_REDUNDANT)) ? 1 : 2); 4643 (0 == (options & RMO_REDUNDANT)) ? 1 : 2);
4724 if (0 == res) 4644 if (0 == res)
4725 { 4645 {
4726 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4646 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
4727 "Failed to route message, could not determine DV path\n"); 4647 "Failed to route message, could not determine DV path\n");
4728 return rtt1; 4648 return rtt1;
4729 } 4649 }
4730 rtt2 = encapsulate_for_dv (dv, 4650 rtt2 = encapsulate_for_dv(dv,
4731 res, 4651 res,
4732 hops, 4652 hops,
4733 hdr, 4653 hdr,
4734 &send_dv_to_neighbour, 4654 &send_dv_to_neighbour,
4735 NULL, 4655 NULL,
4736 options & (~RMO_REDUNDANT)); 4656 options & (~RMO_REDUNDANT));
4737 } 4657 }
4738 return GNUNET_TIME_relative_min (rtt1, rtt2); 4658 return GNUNET_TIME_relative_min(rtt1, rtt2);
4739} 4659}
4740 4660
4741 4661
@@ -4746,7 +4666,7 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4746 * @param cls a `struct VirtualLink` to work with 4666 * @param cls a `struct VirtualLink` to work with
4747 */ 4667 */
4748static void 4668static void
4749consider_sending_fc (void *cls) 4669consider_sending_fc(void *cls)
4750{ 4670{
4751 struct VirtualLink *vl = cls; 4671 struct VirtualLink *vl = cls;
4752 struct GNUNET_TIME_Absolute monotime; 4672 struct GNUNET_TIME_Absolute monotime;
@@ -4754,7 +4674,7 @@ consider_sending_fc (void *cls)
4754 struct GNUNET_TIME_Relative duration; 4674 struct GNUNET_TIME_Relative duration;
4755 struct GNUNET_TIME_Relative rtt; 4675 struct GNUNET_TIME_Relative rtt;
4756 4676
4757 duration = GNUNET_TIME_absolute_get_duration (vl->last_fc_transmission); 4677 duration = GNUNET_TIME_absolute_get_duration(vl->last_fc_transmission);
4758 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing 4678 /* OPTIMIZE-FC-BDP: decide sane criteria on when to do this, instead of doing
4759 it always! */ 4679 it always! */
4760 /* For example, we should probably ONLY do this if a bit more than 4680 /* For example, we should probably ONLY do this if a bit more than
@@ -4763,41 +4683,41 @@ consider_sending_fc (void *cls)
4763 need an estimate for the bandwidth-delay-product for the entire 4683 need an estimate for the bandwidth-delay-product for the entire
4764 VL, as that determines "significantly". We have the delay, but 4684 VL, as that determines "significantly". We have the delay, but
4765 the bandwidth statistics need to be added for the VL!*/ 4685 the bandwidth statistics need to be added for the VL!*/
4766 (void) duration; 4686 (void)duration;
4767 4687
4768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4688 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4769 "Sending FC seq %u to %s with new window %llu\n", 4689 "Sending FC seq %u to %s with new window %llu\n",
4770 (unsigned int) vl->fc_seq_gen, 4690 (unsigned int)vl->fc_seq_gen,
4771 GNUNET_i2s (&vl->target), 4691 GNUNET_i2s(&vl->target),
4772 (unsigned long long) vl->incoming_fc_window_size); 4692 (unsigned long long)vl->incoming_fc_window_size);
4773 monotime = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 4693 monotime = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
4774 vl->last_fc_transmission = monotime; 4694 vl->last_fc_transmission = monotime;
4775 fc.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL); 4695 fc.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL);
4776 fc.header.size = htons (sizeof (fc)); 4696 fc.header.size = htons(sizeof(fc));
4777 fc.seq = htonl (vl->fc_seq_gen++); 4697 fc.seq = htonl(vl->fc_seq_gen++);
4778 fc.inbound_window_size = GNUNET_htonll (vl->incoming_fc_window_size); 4698 fc.inbound_window_size = GNUNET_htonll(vl->incoming_fc_window_size);
4779 fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used); 4699 fc.outbound_sent = GNUNET_htonll(vl->outbound_fc_window_size_used);
4780 fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size); 4700 fc.outbound_window_size = GNUNET_htonll(vl->outbound_fc_window_size);
4781 fc.sender_time = GNUNET_TIME_absolute_hton (monotime); 4701 fc.sender_time = GNUNET_TIME_absolute_hton(monotime);
4782 rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE); 4702 rtt = route_control_message_without_fc(&vl->target, &fc.header, RMO_NONE);
4783 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) 4703 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
4784 { 4704 {
4785 rtt = GNUNET_TIME_UNIT_SECONDS; 4705 rtt = GNUNET_TIME_UNIT_SECONDS;
4786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4787 "FC retransmission to %s failed, will retry in %s\n", 4707 "FC retransmission to %s failed, will retry in %s\n",
4788 GNUNET_i2s (&vl->target), 4708 GNUNET_i2s(&vl->target),
4789 GNUNET_STRINGS_relative_time_to_string (rtt, GNUNET_YES)); 4709 GNUNET_STRINGS_relative_time_to_string(rtt, GNUNET_YES));
4790 vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO; 4710 vl->last_fc_rtt = GNUNET_TIME_UNIT_ZERO;
4791 } 4711 }
4792 else 4712 else
4793 { 4713 {
4794 /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */ 4714 /* OPTIMIZE-FC-BDP: rtt is not ideal, we can do better! */
4795 vl->last_fc_rtt = rtt; 4715 vl->last_fc_rtt = rtt;
4796 } 4716 }
4797 if (NULL != vl->fc_retransmit_task) 4717 if (NULL != vl->fc_retransmit_task)
4798 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); 4718 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
4799 vl->fc_retransmit_task = 4719 vl->fc_retransmit_task =
4800 GNUNET_SCHEDULER_add_delayed (rtt, &consider_sending_fc, vl); 4720 GNUNET_SCHEDULER_add_delayed(rtt, &consider_sending_fc, vl);
4801} 4721}
4802 4722
4803 4723
@@ -4818,7 +4738,7 @@ consider_sending_fc (void *cls)
4818 * @param vl virtual link where we should check for transmission 4738 * @param vl virtual link where we should check for transmission
4819 */ 4739 */
4820static void 4740static void
4821check_vl_transmission (struct VirtualLink *vl) 4741check_vl_transmission(struct VirtualLink *vl)
4822{ 4742{
4823 struct Neighbour *n = vl->n; 4743 struct Neighbour *n = vl->n;
4824 struct DistanceVector *dv = vl->dv; 4744 struct DistanceVector *dv = vl->dv;
@@ -4830,57 +4750,57 @@ check_vl_transmission (struct VirtualLink *vl)
4830 elig = GNUNET_NO; 4750 elig = GNUNET_NO;
4831 for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm; 4751 for (struct PendingMessage *pm = vl->pending_msg_head; NULL != pm;
4832 pm = pm->next_vl) 4752 pm = pm->next_vl)
4833 { 4753 {
4834 if (NULL != pm->qe) 4754 if (NULL != pm->qe)
4835 continue; /* not eligible, is in a queue! */ 4755 continue; /* not eligible, is in a queue! */
4836 if (pm->bytes_msg + vl->outbound_fc_window_size_used > 4756 if (pm->bytes_msg + vl->outbound_fc_window_size_used >
4837 vl->outbound_fc_window_size) 4757 vl->outbound_fc_window_size)
4838 { 4758 {
4839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4840 "Stalled transmision on VL %s due to flow control: %llu < %llu\n", 4760 "Stalled transmision on VL %s due to flow control: %llu < %llu\n",
4841 GNUNET_i2s (&vl->target), 4761 GNUNET_i2s(&vl->target),
4842 (unsigned long long) vl->outbound_fc_window_size, 4762 (unsigned long long)vl->outbound_fc_window_size,
4843 (unsigned long long) (pm->bytes_msg + 4763 (unsigned long long)(pm->bytes_msg +
4844 vl->outbound_fc_window_size_used)); 4764 vl->outbound_fc_window_size_used));
4845 consider_sending_fc (vl); 4765 consider_sending_fc(vl);
4846 return; /* We have a message, but flow control says "nope" */ 4766 return; /* We have a message, but flow control says "nope" */
4847 } 4767 }
4848 elig = GNUNET_YES; 4768 elig = GNUNET_YES;
4849 break; 4769 break;
4850 } 4770 }
4851 if (GNUNET_NO == elig) 4771 if (GNUNET_NO == elig)
4852 return; 4772 return;
4853 4773
4854 /* Notify queues at direct neighbours that we are interested */ 4774 /* Notify queues at direct neighbours that we are interested */
4855 now = GNUNET_TIME_absolute_get (); 4775 now = GNUNET_TIME_absolute_get();
4856 if (NULL != n) 4776 if (NULL != n)
4857 {
4858 for (struct Queue *queue = n->queue_head; NULL != queue;
4859 queue = queue->next_neighbour)
4860 if ((GNUNET_YES == queue->idle) &&
4861 (queue->validated_until.abs_value_us > now.abs_value_us))
4862 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4863 }
4864 /* Notify queues via DV that we are interested */
4865 if (NULL != dv)
4866 {
4867 /* Do DV with lower scheduler priority, which effectively means that
4868 IF a neighbour exists and is available, we prefer it. */
4869 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
4870 pos = pos->next_dv)
4871 { 4777 {
4872 struct Neighbour *nh = pos->next_hop; 4778 for (struct Queue *queue = n->queue_head; NULL != queue;
4873
4874 if (pos->path_valid_until.abs_value_us <= now.abs_value_us)
4875 continue; /* skip this one: path not validated */
4876 for (struct Queue *queue = nh->queue_head; NULL != queue;
4877 queue = queue->next_neighbour) 4779 queue = queue->next_neighbour)
4878 if ((GNUNET_YES == queue->idle) && 4780 if ((GNUNET_YES == queue->idle) &&
4879 (queue->validated_until.abs_value_us > now.abs_value_us)) 4781 (queue->validated_until.abs_value_us > now.abs_value_us))
4880 schedule_transmit_on_queue (queue, 4782 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
4881 GNUNET_SCHEDULER_PRIORITY_BACKGROUND); 4783 }
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 }
4882 } 4803 }
4883 }
4884} 4804}
4885 4805
4886 4806
@@ -4891,7 +4811,7 @@ check_vl_transmission (struct VirtualLink *vl)
4891 * @param obm the send message that was sent 4811 * @param obm the send message that was sent
4892 */ 4812 */
4893static void 4813static void
4894handle_client_send (void *cls, const struct OutboundMessage *obm) 4814handle_client_send(void *cls, const struct OutboundMessage *obm)
4895{ 4815{
4896 struct TransportClient *tc = cls; 4816 struct TransportClient *tc = cls;
4897 struct PendingMessage *pm; 4817 struct PendingMessage *pm;
@@ -4900,46 +4820,46 @@ handle_client_send (void *cls, const struct OutboundMessage *obm)
4900 struct VirtualLink *vl; 4820 struct VirtualLink *vl;
4901 enum GNUNET_MQ_PriorityPreferences pp; 4821 enum GNUNET_MQ_PriorityPreferences pp;
4902 4822
4903 GNUNET_assert (CT_CORE == tc->type); 4823 GNUNET_assert(CT_CORE == tc->type);
4904 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 4824 obmm = (const struct GNUNET_MessageHeader *)&obm[1];
4905 bytes_msg = ntohs (obmm->size); 4825 bytes_msg = ntohs(obmm->size);
4906 pp = (enum GNUNET_MQ_PriorityPreferences) ntohl (obm->priority); 4826 pp = (enum GNUNET_MQ_PriorityPreferences)ntohl(obm->priority);
4907 vl = lookup_virtual_link (&obm->peer); 4827 vl = lookup_virtual_link(&obm->peer);
4908 if (NULL == vl) 4828 if (NULL == vl)
4909 { 4829 {
4910 /* Failure: don't have this peer as a neighbour (anymore). 4830 /* Failure: don't have this peer as a neighbour (anymore).
4911 Might have gone down asynchronously, so this is NOT 4831 Might have gone down asynchronously, so this is NOT
4912 a protocol violation by CORE. Still count the event, 4832 a protocol violation by CORE. Still count the event,
4913 as this should be rare. */ 4833 as this should be rare. */
4914 GNUNET_SERVICE_client_continue (tc->client); 4834 GNUNET_SERVICE_client_continue(tc->client);
4915 GNUNET_STATISTICS_update (GST_stats, 4835 GNUNET_STATISTICS_update(GST_stats,
4916 "# messages dropped (neighbour unknown)", 4836 "# messages dropped (neighbour unknown)",
4917 1, 4837 1,
4918 GNUNET_NO); 4838 GNUNET_NO);
4919 return; 4839 return;
4920 } 4840 }
4921 4841
4922 pm = GNUNET_malloc (sizeof (struct PendingMessage) + bytes_msg); 4842 pm = GNUNET_malloc(sizeof(struct PendingMessage) + bytes_msg);
4923 pm->logging_uuid = logging_uuid_gen++; 4843 pm->logging_uuid = logging_uuid_gen++;
4924 pm->prefs = pp; 4844 pm->prefs = pp;
4925 pm->client = tc; 4845 pm->client = tc;
4926 pm->vl = vl; 4846 pm->vl = vl;
4927 pm->bytes_msg = bytes_msg; 4847 pm->bytes_msg = bytes_msg;
4928 memcpy (&pm[1], obmm, bytes_msg); 4848 memcpy(&pm[1], obmm, bytes_msg);
4929 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4849 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4930 "Sending %u bytes as <%llu> to %s\n", 4850 "Sending %u bytes as <%llu> to %s\n",
4931 bytes_msg, 4851 bytes_msg,
4932 pm->logging_uuid, 4852 pm->logging_uuid,
4933 GNUNET_i2s (&obm->peer)); 4853 GNUNET_i2s(&obm->peer));
4934 GNUNET_CONTAINER_MDLL_insert (client, 4854 GNUNET_CONTAINER_MDLL_insert(client,
4935 tc->details.core.pending_msg_head, 4855 tc->details.core.pending_msg_head,
4936 tc->details.core.pending_msg_tail, 4856 tc->details.core.pending_msg_tail,
4937 pm); 4857 pm);
4938 GNUNET_CONTAINER_MDLL_insert (vl, 4858 GNUNET_CONTAINER_MDLL_insert(vl,
4939 vl->pending_msg_head, 4859 vl->pending_msg_head,
4940 vl->pending_msg_tail, 4860 vl->pending_msg_tail,
4941 pm); 4861 pm);
4942 check_vl_transmission (vl); 4862 check_vl_transmission(vl);
4943} 4863}
4944 4864
4945 4865
@@ -4953,39 +4873,39 @@ handle_client_send (void *cls, const struct OutboundMessage *obm)
4953 * @param cb the send message that was sent 4873 * @param cb the send message that was sent
4954 */ 4874 */
4955static void 4875static void
4956handle_communicator_backchannel ( 4876handle_communicator_backchannel(
4957 void *cls, 4877 void *cls,
4958 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 4878 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
4959{ 4879{
4960 struct TransportClient *tc = cls; 4880 struct TransportClient *tc = cls;
4961 const struct GNUNET_MessageHeader *inbox = 4881 const struct GNUNET_MessageHeader *inbox =
4962 (const struct GNUNET_MessageHeader *) &cb[1]; 4882 (const struct GNUNET_MessageHeader *)&cb[1];
4963 uint16_t isize = ntohs (inbox->size); 4883 uint16_t isize = ntohs(inbox->size);
4964 const char *is = ((const char *) &cb[1]) + isize; 4884 const char *is = ((const char *)&cb[1]) + isize;
4965 char 4885 char
4966 mbuf[isize + 4886 mbuf[isize +
4967 sizeof (struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN; 4887 sizeof(struct TransportBackchannelEncapsulationMessage)] GNUNET_ALIGN;
4968 struct TransportBackchannelEncapsulationMessage *be = 4888 struct TransportBackchannelEncapsulationMessage *be =
4969 (struct TransportBackchannelEncapsulationMessage *) mbuf; 4889 (struct TransportBackchannelEncapsulationMessage *)mbuf;
4970 4890
4971 /* 0-termination of 'is' was checked already in 4891 /* 0-termination of 'is' was checked already in
4972 #check_communicator_backchannel() */ 4892 #check_communicator_backchannel() */
4973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4893 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
4974 "Preparing backchannel transmission to %s:%s of type %u\n", 4894 "Preparing backchannel transmission to %s:%s of type %u\n",
4975 GNUNET_i2s (&cb->pid), 4895 GNUNET_i2s(&cb->pid),
4976 is, 4896 is,
4977 ntohs (inbox->size)); 4897 ntohs(inbox->size));
4978 /* encapsulate and encrypt message */ 4898 /* encapsulate and encrypt message */
4979 be->header.type = 4899 be->header.type =
4980 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION); 4900 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION);
4981 be->header.size = htons (sizeof (mbuf)); 4901 be->header.size = htons(sizeof(mbuf));
4982 memcpy (&be[1], inbox, isize); 4902 memcpy(&be[1], inbox, isize);
4983 memcpy (&mbuf[sizeof (struct TransportBackchannelEncapsulationMessage) + 4903 memcpy(&mbuf[sizeof(struct TransportBackchannelEncapsulationMessage) +
4984 isize], 4904 isize],
4985 is, 4905 is,
4986 strlen (is) + 1); 4906 strlen(is) + 1);
4987 route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED); 4907 route_control_message_without_fc(&cb->pid, &be->header, RMO_DV_ALLOWED);
4988 GNUNET_SERVICE_client_continue (tc->client); 4908 GNUNET_SERVICE_client_continue(tc->client);
4989} 4909}
4990 4910
4991 4911
@@ -4997,17 +4917,17 @@ handle_communicator_backchannel (
4997 * @return #GNUNET_OK if message is well-formed 4917 * @return #GNUNET_OK if message is well-formed
4998 */ 4918 */
4999static int 4919static int
5000check_add_address (void *cls, 4920check_add_address(void *cls,
5001 const struct GNUNET_TRANSPORT_AddAddressMessage *aam) 4921 const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
5002{ 4922{
5003 struct TransportClient *tc = cls; 4923 struct TransportClient *tc = cls;
5004 4924
5005 if (CT_COMMUNICATOR != tc->type) 4925 if (CT_COMMUNICATOR != tc->type)
5006 { 4926 {
5007 GNUNET_break (0); 4927 GNUNET_break(0);
5008 return GNUNET_SYSERR; 4928 return GNUNET_SYSERR;
5009 } 4929 }
5010 GNUNET_MQ_check_zero_termination (aam); 4930 GNUNET_MQ_check_zero_termination(aam);
5011 return GNUNET_OK; 4931 return GNUNET_OK;
5012} 4932}
5013 4933
@@ -5018,7 +4938,7 @@ check_add_address (void *cls,
5018 * @param cls an `struct AddressListEntry *` 4938 * @param cls an `struct AddressListEntry *`
5019 */ 4939 */
5020static void 4940static void
5021store_pi (void *cls); 4941store_pi(void *cls);
5022 4942
5023 4943
5024/** 4944/**
@@ -5028,26 +4948,26 @@ store_pi (void *cls);
5028 * @param success #GNUNET_YES if peerstore was successful 4948 * @param success #GNUNET_YES if peerstore was successful
5029 */ 4949 */
5030static void 4950static void
5031peerstore_store_own_cb (void *cls, int success) 4951peerstore_store_own_cb(void *cls, int success)
5032{ 4952{
5033 struct AddressListEntry *ale = cls; 4953 struct AddressListEntry *ale = cls;
5034 4954
5035 ale->sc = NULL; 4955 ale->sc = NULL;
5036 if (GNUNET_YES != success) 4956 if (GNUNET_YES != success)
5037 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 4957 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
5038 "Failed to store our own address `%s' in peerstore!\n", 4958 "Failed to store our own address `%s' in peerstore!\n",
5039 ale->address); 4959 ale->address);
5040 else 4960 else
5041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4961 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5042 "Successfully stored our own address `%s' in peerstore!\n", 4962 "Successfully stored our own address `%s' in peerstore!\n",
5043 ale->address); 4963 ale->address);
5044 /* refresh period is 1/4 of expiration time, that should be plenty 4964 /* refresh period is 1/4 of expiration time, that should be plenty
5045 without being excessive. */ 4965 without being excessive. */
5046 ale->st = 4966 ale->st =
5047 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide (ale->expiration, 4967 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_divide(ale->expiration,
5048 4ULL), 4968 4ULL),
5049 &store_pi, 4969 &store_pi,
5050 ale); 4970 ale);
5051} 4971}
5052 4972
5053 4973
@@ -5057,7 +4977,7 @@ peerstore_store_own_cb (void *cls, int success)
5057 * @param cls an `struct AddressListEntry *` 4977 * @param cls an `struct AddressListEntry *`
5058 */ 4978 */
5059static void 4979static void
5060store_pi (void *cls) 4980store_pi(void *cls)
5061{ 4981{
5062 struct AddressListEntry *ale = cls; 4982 struct AddressListEntry *ale = cls;
5063 void *addr; 4983 void *addr;
@@ -5065,36 +4985,36 @@ store_pi (void *cls)
5065 struct GNUNET_TIME_Absolute expiration; 4985 struct GNUNET_TIME_Absolute expiration;
5066 4986
5067 ale->st = NULL; 4987 ale->st = NULL;
5068 expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); 4988 expiration = GNUNET_TIME_relative_to_absolute(ale->expiration);
5069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4989 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5070 "Storing our address `%s' in peerstore until %s!\n", 4990 "Storing our address `%s' in peerstore until %s!\n",
5071 ale->address, 4991 ale->address,
5072 GNUNET_STRINGS_absolute_time_to_string (expiration)); 4992 GNUNET_STRINGS_absolute_time_to_string(expiration));
5073 GNUNET_HELLO_sign_address (ale->address, 4993 GNUNET_HELLO_sign_address(ale->address,
5074 ale->nt, 4994 ale->nt,
5075 hello_mono_time, 4995 hello_mono_time,
5076 GST_my_private_key, 4996 GST_my_private_key,
5077 &addr, 4997 &addr,
5078 &addr_len); 4998 &addr_len);
5079 ale->sc = GNUNET_PEERSTORE_store (peerstore, 4999 ale->sc = GNUNET_PEERSTORE_store(peerstore,
5080 "transport", 5000 "transport",
5081 &GST_my_identity, 5001 &GST_my_identity,
5082 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, 5002 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
5083 addr, 5003 addr,
5084 addr_len, 5004 addr_len,
5085 expiration, 5005 expiration,
5086 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 5006 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
5087 &peerstore_store_own_cb, 5007 &peerstore_store_own_cb,
5088 ale); 5008 ale);
5089 GNUNET_free (addr); 5009 GNUNET_free(addr);
5090 if (NULL == ale->sc) 5010 if (NULL == ale->sc)
5091 { 5011 {
5092 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5012 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
5093 "Failed to store our address `%s' with peerstore\n", 5013 "Failed to store our address `%s' with peerstore\n",
5094 ale->address); 5014 ale->address);
5095 ale->st = 5015 ale->st =
5096 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &store_pi, ale); 5016 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &store_pi, ale);
5097 } 5017 }
5098} 5018}
5099 5019
5100 5020
@@ -5105,30 +5025,30 @@ store_pi (void *cls)
5105 * @param aam the send message that was sent 5025 * @param aam the send message that was sent
5106 */ 5026 */
5107static void 5027static void
5108handle_add_address (void *cls, 5028handle_add_address(void *cls,
5109 const struct GNUNET_TRANSPORT_AddAddressMessage *aam) 5029 const struct GNUNET_TRANSPORT_AddAddressMessage *aam)
5110{ 5030{
5111 struct TransportClient *tc = cls; 5031 struct TransportClient *tc = cls;
5112 struct AddressListEntry *ale; 5032 struct AddressListEntry *ale;
5113 size_t slen; 5033 size_t slen;
5114 5034
5115 /* 0-termination of &aam[1] was checked in #check_add_address */ 5035 /* 0-termination of &aam[1] was checked in #check_add_address */
5116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5036 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5117 "Communicator added address `%s'!\n", 5037 "Communicator added address `%s'!\n",
5118 (const char *) &aam[1]); 5038 (const char *)&aam[1]);
5119 slen = ntohs (aam->header.size) - sizeof (*aam); 5039 slen = ntohs(aam->header.size) - sizeof(*aam);
5120 ale = GNUNET_malloc (sizeof (struct AddressListEntry) + slen); 5040 ale = GNUNET_malloc(sizeof(struct AddressListEntry) + slen);
5121 ale->tc = tc; 5041 ale->tc = tc;
5122 ale->address = (const char *) &ale[1]; 5042 ale->address = (const char *)&ale[1];
5123 ale->expiration = GNUNET_TIME_relative_ntoh (aam->expiration); 5043 ale->expiration = GNUNET_TIME_relative_ntoh(aam->expiration);
5124 ale->aid = aam->aid; 5044 ale->aid = aam->aid;
5125 ale->nt = (enum GNUNET_NetworkType) ntohl (aam->nt); 5045 ale->nt = (enum GNUNET_NetworkType)ntohl(aam->nt);
5126 memcpy (&ale[1], &aam[1], slen); 5046 memcpy(&ale[1], &aam[1], slen);
5127 GNUNET_CONTAINER_DLL_insert (tc->details.communicator.addr_head, 5047 GNUNET_CONTAINER_DLL_insert(tc->details.communicator.addr_head,
5128 tc->details.communicator.addr_tail, 5048 tc->details.communicator.addr_tail,
5129 ale); 5049 ale);
5130 ale->st = GNUNET_SCHEDULER_add_now (&store_pi, ale); 5050 ale->st = GNUNET_SCHEDULER_add_now(&store_pi, ale);
5131 GNUNET_SERVICE_client_continue (tc->client); 5051 GNUNET_SERVICE_client_continue(tc->client);
5132} 5052}
5133 5053
5134 5054
@@ -5139,34 +5059,34 @@ handle_add_address (void *cls,
5139 * @param dam the send message that was sent 5059 * @param dam the send message that was sent
5140 */ 5060 */
5141static void 5061static void
5142handle_del_address (void *cls, 5062handle_del_address(void *cls,
5143 const struct GNUNET_TRANSPORT_DelAddressMessage *dam) 5063 const struct GNUNET_TRANSPORT_DelAddressMessage *dam)
5144{ 5064{
5145 struct TransportClient *tc = cls; 5065 struct TransportClient *tc = cls;
5146 struct AddressListEntry *alen; 5066 struct AddressListEntry *alen;
5147 5067
5148 if (CT_COMMUNICATOR != tc->type) 5068 if (CT_COMMUNICATOR != tc->type)
5149 { 5069 {
5150 GNUNET_break (0); 5070 GNUNET_break(0);
5151 GNUNET_SERVICE_client_drop (tc->client); 5071 GNUNET_SERVICE_client_drop(tc->client);
5152 return; 5072 return;
5153 } 5073 }
5154 for (struct AddressListEntry *ale = tc->details.communicator.addr_head; 5074 for (struct AddressListEntry *ale = tc->details.communicator.addr_head;
5155 NULL != ale; 5075 NULL != ale;
5156 ale = alen) 5076 ale = alen)
5157 { 5077 {
5158 alen = ale->next; 5078 alen = ale->next;
5159 if (dam->aid != ale->aid) 5079 if (dam->aid != ale->aid)
5160 continue; 5080 continue;
5161 GNUNET_assert (ale->tc == tc); 5081 GNUNET_assert(ale->tc == tc);
5162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5082 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5163 "Communicator deleted address `%s'!\n", 5083 "Communicator deleted address `%s'!\n",
5164 ale->address); 5084 ale->address);
5165 free_address_list_entry (ale); 5085 free_address_list_entry(ale);
5166 GNUNET_SERVICE_client_continue (tc->client); 5086 GNUNET_SERVICE_client_continue(tc->client);
5167 } 5087 }
5168 GNUNET_break (0); 5088 GNUNET_break(0);
5169 GNUNET_SERVICE_client_drop (tc->client); 5089 GNUNET_SERVICE_client_drop(tc->client);
5170} 5090}
5171 5091
5172 5092
@@ -5178,8 +5098,8 @@ handle_del_address (void *cls,
5178 * @param msg message to demultiplex 5098 * @param msg message to demultiplex
5179 */ 5099 */
5180static void 5100static void
5181demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, 5101demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
5182 const struct GNUNET_MessageHeader *msg); 5102 const struct GNUNET_MessageHeader *msg);
5183 5103
5184 5104
5185/** 5105/**
@@ -5190,23 +5110,23 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
5190 * @param cls a `struct CoreSentContext` 5110 * @param cls a `struct CoreSentContext`
5191 */ 5111 */
5192static void 5112static void
5193core_env_sent_cb (void *cls) 5113core_env_sent_cb(void *cls)
5194{ 5114{
5195 struct CoreSentContext *ctx = cls; 5115 struct CoreSentContext *ctx = cls;
5196 struct VirtualLink *vl = ctx->vl; 5116 struct VirtualLink *vl = ctx->vl;
5197 5117
5198 if (NULL == vl) 5118 if (NULL == vl)
5199 { 5119 {
5200 /* lost the link in the meantime, ignore */ 5120 /* lost the link in the meantime, ignore */
5201 GNUNET_free (ctx); 5121 GNUNET_free(ctx);
5202 return; 5122 return;
5203 } 5123 }
5204 GNUNET_CONTAINER_DLL_remove (vl->csc_head, vl->csc_tail, ctx); 5124 GNUNET_CONTAINER_DLL_remove(vl->csc_head, vl->csc_tail, ctx);
5205 GNUNET_assert (vl->incoming_fc_window_size_ram >= ctx->size); 5125 GNUNET_assert(vl->incoming_fc_window_size_ram >= ctx->size);
5206 vl->incoming_fc_window_size_ram -= ctx->size; 5126 vl->incoming_fc_window_size_ram -= ctx->size;
5207 vl->incoming_fc_window_size_used += ctx->isize; 5127 vl->incoming_fc_window_size_used += ctx->isize;
5208 consider_sending_fc (vl); 5128 consider_sending_fc(vl);
5209 GNUNET_free (ctx); 5129 GNUNET_free(ctx);
5210} 5130}
5211 5131
5212 5132
@@ -5219,109 +5139,109 @@ core_env_sent_cb (void *cls)
5219 * @param mh the message that was received 5139 * @param mh the message that was received
5220 */ 5140 */
5221static void 5141static void
5222handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh) 5142handle_raw_message(void *cls, const struct GNUNET_MessageHeader *mh)
5223{ 5143{
5224 struct CommunicatorMessageContext *cmc = cls; 5144 struct CommunicatorMessageContext *cmc = cls;
5225 struct VirtualLink *vl; 5145 struct VirtualLink *vl;
5226 uint16_t size = ntohs (mh->size); 5146 uint16_t size = ntohs(mh->size);
5227 int have_core; 5147 int have_core;
5228 5148
5229 if ((size > UINT16_MAX - sizeof (struct InboundMessage)) || 5149 if ((size > UINT16_MAX - sizeof(struct InboundMessage)) ||
5230 (size < sizeof (struct GNUNET_MessageHeader))) 5150 (size < sizeof(struct GNUNET_MessageHeader)))
5231 { 5151 {
5232 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 5152 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
5233 5153
5234 GNUNET_break (0); 5154 GNUNET_break(0);
5235 finish_cmc_handling (cmc); 5155 finish_cmc_handling(cmc);
5236 GNUNET_SERVICE_client_drop (client); 5156 GNUNET_SERVICE_client_drop(client);
5237 return; 5157 return;
5238 } 5158 }
5239 vl = lookup_virtual_link (&cmc->im.sender); 5159 vl = lookup_virtual_link(&cmc->im.sender);
5240 if (NULL == vl) 5160 if (NULL == vl)
5241 { 5161 {
5242 /* FIXME: sender is giving us messages for CORE but we don't have 5162 /* FIXME: sender is giving us messages for CORE but we don't have
5243 the link up yet! I *suspect* this can happen right now (i.e. 5163 the link up yet! I *suspect* this can happen right now (i.e.
5244 sender has verified us, but we didn't verify sender), but if 5164 sender has verified us, but we didn't verify sender), but if
5245 we pass this on, CORE would be confused (link down, messages 5165 we pass this on, CORE would be confused (link down, messages
5246 arrive). We should investigate more if this happens often, 5166 arrive). We should investigate more if this happens often,
5247 or in a persistent manner, and possibly do "something" about 5167 or in a persistent manner, and possibly do "something" about
5248 it. Thus logging as error for now. */ 5168 it. Thus logging as error for now. */
5249 GNUNET_break_op (0); 5169 GNUNET_break_op(0);
5250 GNUNET_STATISTICS_update (GST_stats, 5170 GNUNET_STATISTICS_update(GST_stats,
5251 "# CORE messages droped (virtual link still down)", 5171 "# CORE messages droped (virtual link still down)",
5252 1, 5172 1,
5253 GNUNET_NO); 5173 GNUNET_NO);
5254 5174
5255 finish_cmc_handling (cmc); 5175 finish_cmc_handling(cmc);
5256 return; 5176 return;
5257 } 5177 }
5258 if (vl->incoming_fc_window_size_ram > UINT_MAX - size) 5178 if (vl->incoming_fc_window_size_ram > UINT_MAX - size)
5259 { 5179 {
5260 GNUNET_STATISTICS_update (GST_stats, 5180 GNUNET_STATISTICS_update(GST_stats,
5261 "# CORE messages droped (FC arithmetic overflow)", 5181 "# CORE messages droped (FC arithmetic overflow)",
5262 1, 5182 1,
5263 GNUNET_NO); 5183 GNUNET_NO);
5264 5184
5265 finish_cmc_handling (cmc); 5185 finish_cmc_handling(cmc);
5266 return; 5186 return;
5267 } 5187 }
5268 if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size) 5188 if (vl->incoming_fc_window_size_ram + size > vl->available_fc_window_size)
5269 { 5189 {
5270 GNUNET_STATISTICS_update (GST_stats, 5190 GNUNET_STATISTICS_update(GST_stats,
5271 "# CORE messages droped (FC window overflow)", 5191 "# CORE messages droped (FC window overflow)",
5272 1, 5192 1,
5273 GNUNET_NO); 5193 GNUNET_NO);
5274 finish_cmc_handling (cmc); 5194 finish_cmc_handling(cmc);
5275 return; 5195 return;
5276 } 5196 }
5277 5197
5278 /* Forward to all CORE clients */ 5198 /* Forward to all CORE clients */
5279 have_core = GNUNET_NO; 5199 have_core = GNUNET_NO;
5280 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 5200 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
5281 { 5201 {
5282 struct GNUNET_MQ_Envelope *env; 5202 struct GNUNET_MQ_Envelope *env;
5283 struct InboundMessage *im; 5203 struct InboundMessage *im;
5284 struct CoreSentContext *ctx; 5204 struct CoreSentContext *ctx;
5285 5205
5286 if (CT_CORE != tc->type) 5206 if (CT_CORE != tc->type)
5287 continue; 5207 continue;
5288 vl->incoming_fc_window_size_ram += size; 5208 vl->incoming_fc_window_size_ram += size;
5289 env = GNUNET_MQ_msg_extra (im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 5209 env = GNUNET_MQ_msg_extra(im, size, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
5290 ctx = GNUNET_new (struct CoreSentContext); 5210 ctx = GNUNET_new(struct CoreSentContext);
5291 ctx->vl = vl; 5211 ctx->vl = vl;
5292 ctx->size = size; 5212 ctx->size = size;
5293 ctx->isize = (GNUNET_NO == have_core) ? size : 0; 5213 ctx->isize = (GNUNET_NO == have_core) ? size : 0;
5294 have_core = GNUNET_YES; 5214 have_core = GNUNET_YES;
5295 GNUNET_CONTAINER_DLL_insert (vl->csc_head, vl->csc_tail, ctx); 5215 GNUNET_CONTAINER_DLL_insert(vl->csc_head, vl->csc_tail, ctx);
5296 GNUNET_MQ_notify_sent (env, &core_env_sent_cb, ctx); 5216 GNUNET_MQ_notify_sent(env, &core_env_sent_cb, ctx);
5297 im->peer = cmc->im.sender; 5217 im->peer = cmc->im.sender;
5298 memcpy (&im[1], mh, size); 5218 memcpy(&im[1], mh, size);
5299 GNUNET_MQ_send (tc->mq, env); 5219 GNUNET_MQ_send(tc->mq, env);
5300 vl->core_recv_window--; 5220 vl->core_recv_window--;
5301 } 5221 }
5302 if (GNUNET_NO == have_core) 5222 if (GNUNET_NO == have_core)
5303 { 5223 {
5304 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5224 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
5305 "Dropped message to CORE: no CORE client connected!\n"); 5225 "Dropped message to CORE: no CORE client connected!\n");
5306 /* Nevertheless, count window as used, as it is from the 5226 /* Nevertheless, count window as used, as it is from the
5307 perspective of the other peer! */ 5227 perspective of the other peer! */
5308 vl->incoming_fc_window_size_used += size; 5228 vl->incoming_fc_window_size_used += size;
5309 /* TODO-M1 */ 5229 /* TODO-M1 */
5310 finish_cmc_handling (cmc); 5230 finish_cmc_handling(cmc);
5311 return; 5231 return;
5312 } 5232 }
5313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5314 "Delivered message from %s of type %u to CORE\n", 5234 "Delivered message from %s of type %u to CORE\n",
5315 GNUNET_i2s (&cmc->im.sender), 5235 GNUNET_i2s(&cmc->im.sender),
5316 ntohs (mh->type)); 5236 ntohs(mh->type));
5317 if (vl->core_recv_window > 0) 5237 if (vl->core_recv_window > 0)
5318 { 5238 {
5319 finish_cmc_handling (cmc); 5239 finish_cmc_handling(cmc);
5320 return; 5240 return;
5321 } 5241 }
5322 /* Wait with calling #finish_cmc_handling(cmc) until the message 5242 /* Wait with calling #finish_cmc_handling(cmc) until the message
5323 was processed by CORE MQs (for CORE flow control)! */ 5243 was processed by CORE MQs (for CORE flow control)! */
5324 GNUNET_CONTAINER_DLL_insert (vl->cmc_head, vl->cmc_tail, cmc); 5244 GNUNET_CONTAINER_DLL_insert(vl->cmc_head, vl->cmc_tail, cmc);
5325} 5245}
5326 5246
5327 5247
@@ -5333,27 +5253,27 @@ handle_raw_message (void *cls, const struct GNUNET_MessageHeader *mh)
5333 * @return #GNUNET_YES if message is well-formed 5253 * @return #GNUNET_YES if message is well-formed
5334 */ 5254 */
5335static int 5255static int
5336check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) 5256check_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5337{ 5257{
5338 uint16_t size = ntohs (fb->header.size); 5258 uint16_t size = ntohs(fb->header.size);
5339 uint16_t bsize = size - sizeof (*fb); 5259 uint16_t bsize = size - sizeof(*fb);
5340 5260
5341 (void) cls; 5261 (void)cls;
5342 if (0 == bsize) 5262 if (0 == bsize)
5343 { 5263 {
5344 GNUNET_break_op (0); 5264 GNUNET_break_op(0);
5345 return GNUNET_SYSERR; 5265 return GNUNET_SYSERR;
5346 } 5266 }
5347 if (bsize + ntohs (fb->frag_off) > ntohs (fb->msg_size)) 5267 if (bsize + ntohs(fb->frag_off) > ntohs(fb->msg_size))
5348 { 5268 {
5349 GNUNET_break_op (0); 5269 GNUNET_break_op(0);
5350 return GNUNET_SYSERR; 5270 return GNUNET_SYSERR;
5351 } 5271 }
5352 if (ntohs (fb->frag_off) >= ntohs (fb->msg_size)) 5272 if (ntohs(fb->frag_off) >= ntohs(fb->msg_size))
5353 { 5273 {
5354 GNUNET_break_op (0); 5274 GNUNET_break_op(0);
5355 return GNUNET_SYSERR; 5275 return GNUNET_SYSERR;
5356 } 5276 }
5357 return GNUNET_YES; 5277 return GNUNET_YES;
5358} 5278}
5359 5279
@@ -5364,16 +5284,16 @@ check_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5364 * @param cls a `struct AcknowledgementCummulator *` 5284 * @param cls a `struct AcknowledgementCummulator *`
5365 */ 5285 */
5366static void 5286static void
5367destroy_ack_cummulator (void *cls) 5287destroy_ack_cummulator(void *cls)
5368{ 5288{
5369 struct AcknowledgementCummulator *ac = cls; 5289 struct AcknowledgementCummulator *ac = cls;
5370 5290
5371 ac->task = NULL; 5291 ac->task = NULL;
5372 GNUNET_assert (0 == ac->num_acks); 5292 GNUNET_assert(0 == ac->num_acks);
5373 GNUNET_assert ( 5293 GNUNET_assert(
5374 GNUNET_YES == 5294 GNUNET_YES ==
5375 GNUNET_CONTAINER_multipeermap_remove (ack_cummulators, &ac->target, ac)); 5295 GNUNET_CONTAINER_multipeermap_remove(ack_cummulators, &ac->target, ac));
5376 GNUNET_free (ac); 5296 GNUNET_free(ac);
5377} 5297}
5378 5298
5379 5299
@@ -5383,39 +5303,39 @@ destroy_ack_cummulator (void *cls)
5383 * @param cls a `struct AcknowledgementCummulator *` 5303 * @param cls a `struct AcknowledgementCummulator *`
5384 */ 5304 */
5385static void 5305static void
5386transmit_cummulative_ack_cb (void *cls) 5306transmit_cummulative_ack_cb(void *cls)
5387{ 5307{
5388 struct AcknowledgementCummulator *ac = cls; 5308 struct AcknowledgementCummulator *ac = cls;
5389 char buf[sizeof (struct TransportReliabilityAckMessage) + 5309 char buf[sizeof(struct TransportReliabilityAckMessage) +
5390 ac->ack_counter * 5310 ac->ack_counter *
5391 sizeof (struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN; 5311 sizeof(struct TransportCummulativeAckPayloadP)] GNUNET_ALIGN;
5392 struct TransportReliabilityAckMessage *ack = 5312 struct TransportReliabilityAckMessage *ack =
5393 (struct TransportReliabilityAckMessage *) buf; 5313 (struct TransportReliabilityAckMessage *)buf;
5394 struct TransportCummulativeAckPayloadP *ap; 5314 struct TransportCummulativeAckPayloadP *ap;
5395 5315
5396 ac->task = NULL; 5316 ac->task = NULL;
5397 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5317 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5398 "Sending ACK with %u components to %s\n", 5318 "Sending ACK with %u components to %s\n",
5399 ac->ack_counter, 5319 ac->ack_counter,
5400 GNUNET_i2s (&ac->target)); 5320 GNUNET_i2s(&ac->target));
5401 GNUNET_assert (0 < ac->ack_counter); 5321 GNUNET_assert(0 < ac->ack_counter);
5402 ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK); 5322 ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK);
5403 ack->header.size = 5323 ack->header.size =
5404 htons (sizeof (*ack) + 5324 htons(sizeof(*ack) +
5405 ac->ack_counter * sizeof (struct TransportCummulativeAckPayloadP)); 5325 ac->ack_counter * sizeof(struct TransportCummulativeAckPayloadP));
5406 ack->ack_counter = htonl (ac->ack_counter++); 5326 ack->ack_counter = htonl(ac->ack_counter++);
5407 ap = (struct TransportCummulativeAckPayloadP *) &ack[1]; 5327 ap = (struct TransportCummulativeAckPayloadP *)&ack[1];
5408 for (unsigned int i = 0; i < ac->ack_counter; i++) 5328 for (unsigned int i = 0; i < ac->ack_counter; i++)
5409 { 5329 {
5410 ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid; 5330 ap[i].ack_uuid = ac->ack_uuids[i].ack_uuid;
5411 ap[i].ack_delay = GNUNET_TIME_relative_hton ( 5331 ap[i].ack_delay = GNUNET_TIME_relative_hton(
5412 GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time)); 5332 GNUNET_TIME_absolute_get_duration(ac->ack_uuids[i].receive_time));
5413 } 5333 }
5414 route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED); 5334 route_control_message_without_fc(&ac->target, &ack->header, RMO_DV_ALLOWED);
5415 ac->num_acks = 0; 5335 ac->num_acks = 0;
5416 ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT, 5336 ac->task = GNUNET_SCHEDULER_add_delayed(ACK_CUMMULATOR_TIMEOUT,
5417 &destroy_ack_cummulator, 5337 &destroy_ack_cummulator,
5418 ac); 5338 ac);
5419} 5339}
5420 5340
5421 5341
@@ -5428,56 +5348,55 @@ transmit_cummulative_ack_cb (void *cls)
5428 * @param max_delay how long can the ACK wait 5348 * @param max_delay how long can the ACK wait
5429 */ 5349 */
5430static void 5350static void
5431cummulative_ack (const struct GNUNET_PeerIdentity *pid, 5351cummulative_ack(const struct GNUNET_PeerIdentity *pid,
5432 const struct AcknowledgementUUIDP *ack_uuid, 5352 const struct AcknowledgementUUIDP *ack_uuid,
5433 struct GNUNET_TIME_Absolute max_delay) 5353 struct GNUNET_TIME_Absolute max_delay)
5434{ 5354{
5435 struct AcknowledgementCummulator *ac; 5355 struct AcknowledgementCummulator *ac;
5436 5356
5437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5357 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5438 "Scheduling ACK %s for transmission to %s\n", 5358 "Scheduling ACK %s for transmission to %s\n",
5439 GNUNET_uuid2s (&ack_uuid->value), 5359 GNUNET_uuid2s(&ack_uuid->value),
5440 GNUNET_i2s (pid)); 5360 GNUNET_i2s(pid));
5441 ac = GNUNET_CONTAINER_multipeermap_get (ack_cummulators, pid); 5361 ac = GNUNET_CONTAINER_multipeermap_get(ack_cummulators, pid);
5442 if (NULL == ac) 5362 if (NULL == ac)
5443 { 5363 {
5444 ac = GNUNET_new (struct AcknowledgementCummulator); 5364 ac = GNUNET_new(struct AcknowledgementCummulator);
5445 ac->target = *pid; 5365 ac->target = *pid;
5446 ac->min_transmission_time = max_delay; 5366 ac->min_transmission_time = max_delay;
5447 GNUNET_assert (GNUNET_YES == 5367 GNUNET_assert(GNUNET_YES ==
5448 GNUNET_CONTAINER_multipeermap_put ( 5368 GNUNET_CONTAINER_multipeermap_put(
5449 ack_cummulators, 5369 ack_cummulators,
5450 &ac->target, 5370 &ac->target,
5451 ac, 5371 ac,
5452 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 5372 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
5453 } 5373 }
5454 else 5374 else
5455 {
5456 if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
5457 { 5375 {
5458 /* must run immediately, ack buffer full! */ 5376 if (MAX_CUMMULATIVE_ACKS == ac->num_acks)
5459 GNUNET_SCHEDULER_cancel (ac->task); 5377 {
5460 transmit_cummulative_ack_cb (ac); 5378 /* must run immediately, ack buffer full! */
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);
5461 } 5385 }
5462 GNUNET_SCHEDULER_cancel (ac->task); 5386 GNUNET_assert(ac->num_acks < MAX_CUMMULATIVE_ACKS);
5463 ac->min_transmission_time = 5387 ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get();
5464 GNUNET_TIME_absolute_min (ac->min_transmission_time, max_delay);
5465 }
5466 GNUNET_assert (ac->num_acks < MAX_CUMMULATIVE_ACKS);
5467 ac->ack_uuids[ac->num_acks].receive_time = GNUNET_TIME_absolute_get ();
5468 ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid; 5388 ac->ack_uuids[ac->num_acks].ack_uuid = *ack_uuid;
5469 ac->num_acks++; 5389 ac->num_acks++;
5470 ac->task = GNUNET_SCHEDULER_add_at (ac->min_transmission_time, 5390 ac->task = GNUNET_SCHEDULER_add_at(ac->min_transmission_time,
5471 &transmit_cummulative_ack_cb, 5391 &transmit_cummulative_ack_cb,
5472 ac); 5392 ac);
5473} 5393}
5474 5394
5475 5395
5476/** 5396/**
5477 * Closure for #find_by_message_uuid. 5397 * Closure for #find_by_message_uuid.
5478 */ 5398 */
5479struct FindByMessageUuidContext 5399struct FindByMessageUuidContext {
5480{
5481 /** 5400 /**
5482 * UUID to look for. 5401 * UUID to look for.
5483 */ 5402 */
@@ -5500,17 +5419,17 @@ struct FindByMessageUuidContext
5500 * @return #GNUNET_YES if not found, #GNUNET_NO if found 5419 * @return #GNUNET_YES if not found, #GNUNET_NO if found
5501 */ 5420 */
5502static int 5421static int
5503find_by_message_uuid (void *cls, uint32_t key, void *value) 5422find_by_message_uuid(void *cls, uint32_t key, void *value)
5504{ 5423{
5505 struct FindByMessageUuidContext *fc = cls; 5424 struct FindByMessageUuidContext *fc = cls;
5506 struct ReassemblyContext *rc = value; 5425 struct ReassemblyContext *rc = value;
5507 5426
5508 (void) key; 5427 (void)key;
5509 if (0 == GNUNET_memcmp (&fc->message_uuid, &rc->msg_uuid)) 5428 if (0 == GNUNET_memcmp(&fc->message_uuid, &rc->msg_uuid))
5510 { 5429 {
5511 fc->rc = rc; 5430 fc->rc = rc;
5512 return GNUNET_NO; 5431 return GNUNET_NO;
5513 } 5432 }
5514 return GNUNET_YES; 5433 return GNUNET_YES;
5515} 5434}
5516 5435
@@ -5523,7 +5442,7 @@ find_by_message_uuid (void *cls, uint32_t key, void *value)
5523 * @param fb the message that was received 5442 * @param fb the message that was received
5524 */ 5443 */
5525static void 5444static void
5526handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb) 5445handle_fragment_box(void *cls, const struct TransportFragmentBoxMessage *fb)
5527{ 5446{
5528 struct CommunicatorMessageContext *cmc = cls; 5447 struct CommunicatorMessageContext *cmc = cls;
5529 struct Neighbour *n; 5448 struct Neighbour *n;
@@ -5536,142 +5455,142 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5536 struct GNUNET_TIME_Relative cdelay; 5455 struct GNUNET_TIME_Relative cdelay;
5537 struct FindByMessageUuidContext fc; 5456 struct FindByMessageUuidContext fc;
5538 5457
5539 n = lookup_neighbour (&cmc->im.sender); 5458 n = lookup_neighbour(&cmc->im.sender);
5540 if (NULL == n) 5459 if (NULL == n)
5541 { 5460 {
5542 struct GNUNET_SERVICE_Client *client = cmc->tc->client; 5461 struct GNUNET_SERVICE_Client *client = cmc->tc->client;
5543 5462
5544 GNUNET_break (0); 5463 GNUNET_break(0);
5545 finish_cmc_handling (cmc); 5464 finish_cmc_handling(cmc);
5546 GNUNET_SERVICE_client_drop (client); 5465 GNUNET_SERVICE_client_drop(client);
5547 return; 5466 return;
5548 } 5467 }
5549 if (NULL == n->reassembly_map) 5468 if (NULL == n->reassembly_map)
5550 { 5469 {
5551 n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create (8); 5470 n->reassembly_map = GNUNET_CONTAINER_multihashmap32_create(8);
5552 n->reassembly_heap = 5471 n->reassembly_heap =
5553 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 5472 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
5554 n->reassembly_timeout_task = 5473 n->reassembly_timeout_task =
5555 GNUNET_SCHEDULER_add_delayed (REASSEMBLY_EXPIRATION, 5474 GNUNET_SCHEDULER_add_delayed(REASSEMBLY_EXPIRATION,
5556 &reassembly_cleanup_task, 5475 &reassembly_cleanup_task,
5557 n); 5476 n);
5558 } 5477 }
5559 msize = ntohs (fb->msg_size); 5478 msize = ntohs(fb->msg_size);
5560 fc.message_uuid = fb->msg_uuid; 5479 fc.message_uuid = fb->msg_uuid;
5561 fc.rc = NULL; 5480 fc.rc = NULL;
5562 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (n->reassembly_map, 5481 (void)GNUNET_CONTAINER_multihashmap32_get_multiple(n->reassembly_map,
5563 fb->msg_uuid.uuid, 5482 fb->msg_uuid.uuid,
5564 &find_by_message_uuid, 5483 &find_by_message_uuid,
5565 &fc); 5484 &fc);
5566 if (NULL == (rc = fc.rc)) 5485 if (NULL == (rc = fc.rc))
5567 { 5486 {
5568 rc = GNUNET_malloc (sizeof (*rc) + msize + /* reassembly payload buffer */ 5487 rc = GNUNET_malloc(sizeof(*rc) + msize + /* reassembly payload buffer */
5569 (msize + 7) / 8 * sizeof (uint8_t) /* bitfield */); 5488 (msize + 7) / 8 * sizeof(uint8_t) /* bitfield */);
5570 rc->msg_uuid = fb->msg_uuid; 5489 rc->msg_uuid = fb->msg_uuid;
5571 rc->neighbour = n; 5490 rc->neighbour = n;
5572 rc->msg_size = msize; 5491 rc->msg_size = msize;
5573 rc->reassembly_timeout = 5492 rc->reassembly_timeout =
5574 GNUNET_TIME_relative_to_absolute (REASSEMBLY_EXPIRATION); 5493 GNUNET_TIME_relative_to_absolute(REASSEMBLY_EXPIRATION);
5575 rc->last_frag = GNUNET_TIME_absolute_get (); 5494 rc->last_frag = GNUNET_TIME_absolute_get();
5576 rc->hn = GNUNET_CONTAINER_heap_insert (n->reassembly_heap, 5495 rc->hn = GNUNET_CONTAINER_heap_insert(n->reassembly_heap,
5577 rc, 5496 rc,
5578 rc->reassembly_timeout.abs_value_us); 5497 rc->reassembly_timeout.abs_value_us);
5579 GNUNET_assert (GNUNET_OK == 5498 GNUNET_assert(GNUNET_OK ==
5580 GNUNET_CONTAINER_multihashmap32_put ( 5499 GNUNET_CONTAINER_multihashmap32_put(
5581 n->reassembly_map, 5500 n->reassembly_map,
5582 rc->msg_uuid.uuid, 5501 rc->msg_uuid.uuid,
5583 rc, 5502 rc,
5584 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 5503 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
5585 target = (char *) &rc[1]; 5504 target = (char *)&rc[1];
5586 rc->bitfield = (uint8_t *) (target + rc->msg_size); 5505 rc->bitfield = (uint8_t *)(target + rc->msg_size);
5587 rc->msg_missing = rc->msg_size; 5506 rc->msg_missing = rc->msg_size;
5588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5507 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5589 "Received fragment at offset %u/%u from %s for NEW message %u\n", 5508 "Received fragment at offset %u/%u from %s for NEW message %u\n",
5590 ntohs (fb->frag_off), 5509 ntohs(fb->frag_off),
5591 msize, 5510 msize,
5592 GNUNET_i2s (&cmc->im.sender), 5511 GNUNET_i2s(&cmc->im.sender),
5593 (unsigned int) fb->msg_uuid.uuid); 5512 (unsigned int)fb->msg_uuid.uuid);
5594 } 5513 }
5595 else 5514 else
5596 { 5515 {
5597 target = (char *) &rc[1]; 5516 target = (char *)&rc[1];
5598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5517 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5599 "Received fragment at offset %u/%u from %s for message %u\n", 5518 "Received fragment at offset %u/%u from %s for message %u\n",
5600 ntohs (fb->frag_off), 5519 ntohs(fb->frag_off),
5601 msize, 5520 msize,
5602 GNUNET_i2s (&cmc->im.sender), 5521 GNUNET_i2s(&cmc->im.sender),
5603 (unsigned int) fb->msg_uuid.uuid); 5522 (unsigned int)fb->msg_uuid.uuid);
5604 } 5523 }
5605 if (msize != rc->msg_size) 5524 if (msize != rc->msg_size)
5606 { 5525 {
5607 GNUNET_break (0); 5526 GNUNET_break(0);
5608 finish_cmc_handling (cmc); 5527 finish_cmc_handling(cmc);
5609 return; 5528 return;
5610 } 5529 }
5611 5530
5612 /* reassemble */ 5531 /* reassemble */
5613 fsize = ntohs (fb->header.size) - sizeof (*fb); 5532 fsize = ntohs(fb->header.size) - sizeof(*fb);
5614 if (0 == fsize) 5533 if (0 == fsize)
5615 { 5534 {
5616 GNUNET_break (0); 5535 GNUNET_break(0);
5617 finish_cmc_handling (cmc); 5536 finish_cmc_handling(cmc);
5618 return; 5537 return;
5619 } 5538 }
5620 frag_off = ntohs (fb->frag_off); 5539 frag_off = ntohs(fb->frag_off);
5621 if (frag_off + fsize > msize) 5540 if (frag_off + fsize > msize)
5622 { 5541 {
5623 /* Fragment (plus fragment size) exceeds message size! */ 5542 /* Fragment (plus fragment size) exceeds message size! */
5624 GNUNET_break_op (0); 5543 GNUNET_break_op(0);
5625 finish_cmc_handling (cmc); 5544 finish_cmc_handling(cmc);
5626 return; 5545 return;
5627 } 5546 }
5628 memcpy (&target[frag_off], &fb[1], fsize); 5547 memcpy(&target[frag_off], &fb[1], fsize);
5629 /* update bitfield and msg_missing */ 5548 /* update bitfield and msg_missing */
5630 for (unsigned int i = frag_off; i < frag_off + fsize; i++) 5549 for (unsigned int i = frag_off; i < frag_off + fsize; i++)
5631 {
5632 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
5633 { 5550 {
5634 rc->bitfield[i / 8] |= (1 << (i % 8)); 5551 if (0 == (rc->bitfield[i / 8] & (1 << (i % 8))))
5635 rc->msg_missing--; 5552 {
5553 rc->bitfield[i / 8] |= (1 << (i % 8));
5554 rc->msg_missing--;
5555 }
5636 } 5556 }
5637 }
5638 5557
5639 /* Compute cummulative ACK */ 5558 /* Compute cummulative ACK */
5640 cdelay = GNUNET_TIME_absolute_get_duration (rc->last_frag); 5559 cdelay = GNUNET_TIME_absolute_get_duration(rc->last_frag);
5641 cdelay = GNUNET_TIME_relative_multiply (cdelay, rc->msg_missing / fsize); 5560 cdelay = GNUNET_TIME_relative_multiply(cdelay, rc->msg_missing / fsize);
5642 if (0 == rc->msg_missing) 5561 if (0 == rc->msg_missing)
5643 cdelay = GNUNET_TIME_UNIT_ZERO; 5562 cdelay = GNUNET_TIME_UNIT_ZERO;
5644 cummulative_ack (&cmc->im.sender, 5563 cummulative_ack(&cmc->im.sender,
5645 &fb->ack_uuid, 5564 &fb->ack_uuid,
5646 GNUNET_TIME_relative_to_absolute (cdelay)); 5565 GNUNET_TIME_relative_to_absolute(cdelay));
5647 rc->last_frag = GNUNET_TIME_absolute_get (); 5566 rc->last_frag = GNUNET_TIME_absolute_get();
5648 /* is reassembly complete? */ 5567 /* is reassembly complete? */
5649 if (0 != rc->msg_missing) 5568 if (0 != rc->msg_missing)
5650 { 5569 {
5651 finish_cmc_handling (cmc); 5570 finish_cmc_handling(cmc);
5652 return; 5571 return;
5653 } 5572 }
5654 /* reassembly is complete, verify result */ 5573 /* reassembly is complete, verify result */
5655 msg = (const struct GNUNET_MessageHeader *) &rc[1]; 5574 msg = (const struct GNUNET_MessageHeader *)&rc[1];
5656 if (ntohs (msg->size) != rc->msg_size) 5575 if (ntohs(msg->size) != rc->msg_size)
5657 { 5576 {
5658 GNUNET_break (0); 5577 GNUNET_break(0);
5659 free_reassembly_context (rc); 5578 free_reassembly_context(rc);
5660 finish_cmc_handling (cmc); 5579 finish_cmc_handling(cmc);
5661 return; 5580 return;
5662 } 5581 }
5663 /* successful reassembly */ 5582 /* successful reassembly */
5664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5665 "Fragment reassembly complete for message %u\n", 5584 "Fragment reassembly complete for message %u\n",
5666 (unsigned int) fb->msg_uuid.uuid); 5585 (unsigned int)fb->msg_uuid.uuid);
5667 /* FIXME: check that the resulting msg is NOT a 5586 /* FIXME: check that the resulting msg is NOT a
5668 DV Box or Reliability Box, as that is NOT allowed! */ 5587 DV Box or Reliability Box, as that is NOT allowed! */
5669 demultiplex_with_cmc (cmc, msg); 5588 demultiplex_with_cmc(cmc, msg);
5670 /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still 5589 /* FIXME-OPTIMIZE: really free here? Might be bad if fragments are still
5671 en-route and we forget that we finished this reassembly immediately! 5590 en-route and we forget that we finished this reassembly immediately!
5672 -> keep around until timeout? 5591 -> keep around until timeout?
5673 -> shorten timeout based on ACK? */ 5592 -> shorten timeout based on ACK? */
5674 free_reassembly_context (rc); 5593 free_reassembly_context(rc);
5675} 5594}
5676 5595
5677 5596
@@ -5683,11 +5602,11 @@ handle_fragment_box (void *cls, const struct TransportFragmentBoxMessage *fb)
5683 * @return #GNUNET_YES if message is well-formed 5602 * @return #GNUNET_YES if message is well-formed
5684 */ 5603 */
5685static int 5604static int
5686check_reliability_box (void *cls, 5605check_reliability_box(void *cls,
5687 const struct TransportReliabilityBoxMessage *rb) 5606 const struct TransportReliabilityBoxMessage *rb)
5688{ 5607{
5689 (void) cls; 5608 (void)cls;
5690 GNUNET_MQ_check_boxed_message (rb); 5609 GNUNET_MQ_check_boxed_message(rb);
5691 return GNUNET_YES; 5610 return GNUNET_YES;
5692} 5611}
5693 5612
@@ -5700,34 +5619,34 @@ check_reliability_box (void *cls,
5700 * @param rb the message that was received 5619 * @param rb the message that was received
5701 */ 5620 */
5702static void 5621static void
5703handle_reliability_box (void *cls, 5622handle_reliability_box(void *cls,
5704 const struct TransportReliabilityBoxMessage *rb) 5623 const struct TransportReliabilityBoxMessage *rb)
5705{ 5624{
5706 struct CommunicatorMessageContext *cmc = cls; 5625 struct CommunicatorMessageContext *cmc = cls;
5707 const struct GNUNET_MessageHeader *inbox = 5626 const struct GNUNET_MessageHeader *inbox =
5708 (const struct GNUNET_MessageHeader *) &rb[1]; 5627 (const struct GNUNET_MessageHeader *)&rb[1];
5709 struct GNUNET_TIME_Relative rtt; 5628 struct GNUNET_TIME_Relative rtt;
5710 5629
5711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5630 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5712 "Received reliability box from %s with UUID %s of type %u\n", 5631 "Received reliability box from %s with UUID %s of type %u\n",
5713 GNUNET_i2s (&cmc->im.sender), 5632 GNUNET_i2s(&cmc->im.sender),
5714 GNUNET_uuid2s (&rb->ack_uuid.value), 5633 GNUNET_uuid2s(&rb->ack_uuid.value),
5715 (unsigned int) ntohs (inbox->type)); 5634 (unsigned int)ntohs(inbox->type));
5716 rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we 5635 rtt = GNUNET_TIME_UNIT_SECONDS; /* FIXME: should base this on "RTT", but we
5717 do not really have an RTT for the 5636 do not really have an RTT for the
5718 *incoming* queue (should we have 5637 * incoming* queue (should we have
5719 the sender add it to the rb message?) */ 5638 the sender add it to the rb message?) */
5720 cummulative_ack ( 5639 cummulative_ack(
5721 &cmc->im.sender, 5640 &cmc->im.sender,
5722 &rb->ack_uuid, 5641 &rb->ack_uuid,
5723 (0 == ntohl (rb->ack_countdown)) 5642 (0 == ntohl(rb->ack_countdown))
5724 ? GNUNET_TIME_UNIT_ZERO_ABS 5643 ? GNUNET_TIME_UNIT_ZERO_ABS
5725 : GNUNET_TIME_relative_to_absolute ( 5644 : GNUNET_TIME_relative_to_absolute(
5726 GNUNET_TIME_relative_divide (rtt, 8 /* FIXME: magic constant */))); 5645 GNUNET_TIME_relative_divide(rtt, 8 /* FIXME: magic constant */)));
5727 /* continue with inner message */ 5646 /* continue with inner message */
5728 /* FIXME: check that inbox is NOT a DV Box, fragment or another 5647 /* FIXME: check that inbox is NOT a DV Box, fragment or another
5729 reliability box (not allowed!) */ 5648 reliability box (not allowed!) */
5730 demultiplex_with_cmc (cmc, inbox); 5649 demultiplex_with_cmc(cmc, inbox);
5731} 5650}
5732 5651
5733 5652
@@ -5740,20 +5659,20 @@ handle_reliability_box (void *cls,
5740 * @param age current age 5659 * @param age current age
5741 */ 5660 */
5742static void 5661static void
5743update_pd_age (struct PerformanceData *pd, unsigned int age) 5662update_pd_age(struct PerformanceData *pd, unsigned int age)
5744{ 5663{
5745 unsigned int sage; 5664 unsigned int sage;
5746 5665
5747 if (age == pd->last_age) 5666 if (age == pd->last_age)
5748 return; /* nothing to do */ 5667 return; /* nothing to do */
5749 sage = GNUNET_MAX (pd->last_age, age - 2 * GOODPUT_AGING_SLOTS); 5668 sage = GNUNET_MAX(pd->last_age, age - 2 * GOODPUT_AGING_SLOTS);
5750 for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++) 5669 for (unsigned int i = sage; i <= age - GOODPUT_AGING_SLOTS; i++)
5751 { 5670 {
5752 struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS]; 5671 struct TransmissionHistoryEntry *the = &pd->the[i % GOODPUT_AGING_SLOTS];
5753 5672
5754 the->bytes_sent = 0; 5673 the->bytes_sent = 0;
5755 the->bytes_received = 0; 5674 the->bytes_received = 0;
5756 } 5675 }
5757 pd->last_age = age; 5676 pd->last_age = age;
5758} 5677}
5759 5678
@@ -5767,20 +5686,20 @@ update_pd_age (struct PerformanceData *pd, unsigned int age)
5767 * @param bytes_transmitted_ok number of bytes receiver confirmed as received 5686 * @param bytes_transmitted_ok number of bytes receiver confirmed as received
5768 */ 5687 */
5769static void 5688static void
5770update_performance_data (struct PerformanceData *pd, 5689update_performance_data(struct PerformanceData *pd,
5771 struct GNUNET_TIME_Relative rtt, 5690 struct GNUNET_TIME_Relative rtt,
5772 uint16_t bytes_transmitted_ok) 5691 uint16_t bytes_transmitted_ok)
5773{ 5692{
5774 uint64_t nval = rtt.rel_value_us; 5693 uint64_t nval = rtt.rel_value_us;
5775 uint64_t oval = pd->aged_rtt.rel_value_us; 5694 uint64_t oval = pd->aged_rtt.rel_value_us;
5776 unsigned int age = get_age (); 5695 unsigned int age = get_age();
5777 struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS]; 5696 struct TransmissionHistoryEntry *the = &pd->the[age % GOODPUT_AGING_SLOTS];
5778 5697
5779 if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us) 5698 if (oval == GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us)
5780 pd->aged_rtt = rtt; 5699 pd->aged_rtt = rtt;
5781 else 5700 else
5782 pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8; 5701 pd->aged_rtt.rel_value_us = (nval + 7 * oval) / 8;
5783 update_pd_age (pd, age); 5702 update_pd_age(pd, age);
5784 the->bytes_received += bytes_transmitted_ok; 5703 the->bytes_received += bytes_transmitted_ok;
5785} 5704}
5786 5705
@@ -5793,11 +5712,11 @@ update_performance_data (struct PerformanceData *pd,
5793 * @param bytes_transmitted_ok number of bytes successfully transmitted 5712 * @param bytes_transmitted_ok number of bytes successfully transmitted
5794 */ 5713 */
5795static void 5714static void
5796update_queue_performance (struct Queue *q, 5715update_queue_performance(struct Queue *q,
5797 struct GNUNET_TIME_Relative rtt, 5716 struct GNUNET_TIME_Relative rtt,
5798 uint16_t bytes_transmitted_ok) 5717 uint16_t bytes_transmitted_ok)
5799{ 5718{
5800 update_performance_data (&q->pd, rtt, bytes_transmitted_ok); 5719 update_performance_data(&q->pd, rtt, bytes_transmitted_ok);
5801} 5720}
5802 5721
5803 5722
@@ -5809,11 +5728,11 @@ update_queue_performance (struct Queue *q,
5809 * @param bytes_transmitted_ok number of bytes successfully transmitted 5728 * @param bytes_transmitted_ok number of bytes successfully transmitted
5810 */ 5729 */
5811static void 5730static void
5812update_dvh_performance (struct DistanceVectorHop *dvh, 5731update_dvh_performance(struct DistanceVectorHop *dvh,
5813 struct GNUNET_TIME_Relative rtt, 5732 struct GNUNET_TIME_Relative rtt,
5814 uint16_t bytes_transmitted_ok) 5733 uint16_t bytes_transmitted_ok)
5815{ 5734{
5816 update_performance_data (&dvh->pd, rtt, bytes_transmitted_ok); 5735 update_performance_data(&dvh->pd, rtt, bytes_transmitted_ok);
5817} 5736}
5818 5737
5819 5738
@@ -5825,45 +5744,47 @@ update_dvh_performance (struct DistanceVectorHop *dvh,
5825 * @param pm pending message that was transmitted 5744 * @param pm pending message that was transmitted
5826 */ 5745 */
5827static void 5746static void
5828completed_pending_message (struct PendingMessage *pm) 5747completed_pending_message(struct PendingMessage *pm)
5829{ 5748{
5830 struct PendingMessage *pos; 5749 struct PendingMessage *pos;
5831 5750
5832 switch (pm->pmt) 5751 switch (pm->pmt)
5833 { 5752 {
5834 case PMT_CORE: 5753 case PMT_CORE:
5835 case PMT_RELIABILITY_BOX: 5754 case PMT_RELIABILITY_BOX:
5836 /* Full message sent, we are done */ 5755 /* Full message sent, we are done */
5837 client_send_response (pm); 5756 client_send_response(pm);
5838 return; 5757 return;
5839 case PMT_FRAGMENT_BOX: 5758
5840 /* Fragment sent over reliabile channel */ 5759 case PMT_FRAGMENT_BOX:
5841 free_fragment_tree (pm); 5760 /* Fragment sent over reliabile channel */
5842 pos = pm->frag_parent; 5761 free_fragment_tree(pm);
5843 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm);
5844 GNUNET_free (pm);
5845 /* check if subtree is done */
5846 while ((NULL == pos->head_frag) && (pos->frag_off == pos->bytes_msg) &&
5847 (pos != pm))
5848 {
5849 pm = pos;
5850 pos = pm->frag_parent; 5762 pos = pm->frag_parent;
5851 GNUNET_CONTAINER_MDLL_remove (frag, pos->head_frag, pos->tail_frag, pm); 5763 GNUNET_CONTAINER_MDLL_remove(frag, pos->head_frag, pos->tail_frag, pm);
5852 GNUNET_free (pm); 5764 GNUNET_free(pm);
5853 } 5765 /* check if subtree is done */
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 }
5854 5774
5855 /* Was this the last applicable fragmment? */ 5775 /* Was this the last applicable fragmment? */
5856 if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) && 5776 if ((NULL == pos->head_frag) && (NULL == pos->frag_parent) &&
5857 (pos->frag_off == pos->bytes_msg)) 5777 (pos->frag_off == pos->bytes_msg))
5858 client_send_response (pos); 5778 client_send_response(pos);
5859 return; 5779 return;
5860 case PMT_DV_BOX: 5780
5861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5781 case PMT_DV_BOX:
5862 "Completed transmission of message %llu (DV Box)\n", 5782 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
5863 pm->logging_uuid); 5783 "Completed transmission of message %llu (DV Box)\n",
5864 free_pending_message (pm); 5784 pm->logging_uuid);
5865 return; 5785 free_pending_message(pm);
5866 } 5786 return;
5787 }
5867} 5788}
5868 5789
5869 5790
@@ -5875,23 +5796,23 @@ completed_pending_message (struct PendingMessage *pm)
5875 * other peer 5796 * other peer
5876 */ 5797 */
5877static void 5798static void
5878handle_acknowledged (struct PendingAcknowledgement *pa, 5799handle_acknowledged(struct PendingAcknowledgement *pa,
5879 struct GNUNET_TIME_Relative ack_delay) 5800 struct GNUNET_TIME_Relative ack_delay)
5880{ 5801{
5881 struct GNUNET_TIME_Relative delay; 5802 struct GNUNET_TIME_Relative delay;
5882 5803
5883 delay = GNUNET_TIME_absolute_get_duration (pa->transmission_time); 5804 delay = GNUNET_TIME_absolute_get_duration(pa->transmission_time);
5884 if (delay.rel_value_us > ack_delay.rel_value_us) 5805 if (delay.rel_value_us > ack_delay.rel_value_us)
5885 delay = GNUNET_TIME_UNIT_ZERO; 5806 delay = GNUNET_TIME_UNIT_ZERO;
5886 else 5807 else
5887 delay = GNUNET_TIME_relative_subtract (delay, ack_delay); 5808 delay = GNUNET_TIME_relative_subtract(delay, ack_delay);
5888 if (NULL != pa->queue) 5809 if (NULL != pa->queue)
5889 update_queue_performance (pa->queue, delay, pa->message_size); 5810 update_queue_performance(pa->queue, delay, pa->message_size);
5890 if (NULL != pa->dvh) 5811 if (NULL != pa->dvh)
5891 update_dvh_performance (pa->dvh, delay, pa->message_size); 5812 update_dvh_performance(pa->dvh, delay, pa->message_size);
5892 if (NULL != pa->pm) 5813 if (NULL != pa->pm)
5893 completed_pending_message (pa->pm); 5814 completed_pending_message(pa->pm);
5894 free_pending_acknowledgement (pa); 5815 free_pending_acknowledgement(pa);
5895} 5816}
5896 5817
5897 5818
@@ -5903,25 +5824,25 @@ handle_acknowledged (struct PendingAcknowledgement *pa,
5903 * @return #GNUNET_Ok if @a ra is well-formed 5824 * @return #GNUNET_Ok if @a ra is well-formed
5904 */ 5825 */
5905static int 5826static int
5906check_reliability_ack (void *cls, 5827check_reliability_ack(void *cls,
5907 const struct TransportReliabilityAckMessage *ra) 5828 const struct TransportReliabilityAckMessage *ra)
5908{ 5829{
5909 unsigned int n_acks; 5830 unsigned int n_acks;
5910 5831
5911 (void) cls; 5832 (void)cls;
5912 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / 5833 n_acks = (ntohs(ra->header.size) - sizeof(*ra)) /
5913 sizeof (struct TransportCummulativeAckPayloadP); 5834 sizeof(struct TransportCummulativeAckPayloadP);
5914 if (0 == n_acks) 5835 if (0 == n_acks)
5915 { 5836 {
5916 GNUNET_break_op (0); 5837 GNUNET_break_op(0);
5917 return GNUNET_SYSERR; 5838 return GNUNET_SYSERR;
5918 } 5839 }
5919 if ((ntohs (ra->header.size) - sizeof (*ra)) != 5840 if ((ntohs(ra->header.size) - sizeof(*ra)) !=
5920 n_acks * sizeof (struct TransportCummulativeAckPayloadP)) 5841 n_acks * sizeof(struct TransportCummulativeAckPayloadP))
5921 { 5842 {
5922 GNUNET_break_op (0); 5843 GNUNET_break_op(0);
5923 return GNUNET_SYSERR; 5844 return GNUNET_SYSERR;
5924 } 5845 }
5925 return GNUNET_OK; 5846 return GNUNET_OK;
5926} 5847}
5927 5848
@@ -5934,46 +5855,46 @@ check_reliability_ack (void *cls,
5934 * @param ra the message that was received 5855 * @param ra the message that was received
5935 */ 5856 */
5936static void 5857static void
5937handle_reliability_ack (void *cls, 5858handle_reliability_ack(void *cls,
5938 const struct TransportReliabilityAckMessage *ra) 5859 const struct TransportReliabilityAckMessage *ra)
5939{ 5860{
5940 struct CommunicatorMessageContext *cmc = cls; 5861 struct CommunicatorMessageContext *cmc = cls;
5941 const struct TransportCummulativeAckPayloadP *ack; 5862 const struct TransportCummulativeAckPayloadP *ack;
5942 unsigned int n_acks; 5863 unsigned int n_acks;
5943 uint32_t ack_counter; 5864 uint32_t ack_counter;
5944 5865
5945 n_acks = (ntohs (ra->header.size) - sizeof (*ra)) / 5866 n_acks = (ntohs(ra->header.size) - sizeof(*ra)) /
5946 sizeof (struct TransportCummulativeAckPayloadP); 5867 sizeof(struct TransportCummulativeAckPayloadP);
5947 ack = (const struct TransportCummulativeAckPayloadP *) &ra[1]; 5868 ack = (const struct TransportCummulativeAckPayloadP *)&ra[1];
5948 for (unsigned int i = 0; i < n_acks; i++) 5869 for (unsigned int i = 0; i < n_acks; i++)
5949 { 5870 {
5950 struct PendingAcknowledgement *pa = 5871 struct PendingAcknowledgement *pa =
5951 GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value); 5872 GNUNET_CONTAINER_multiuuidmap_get(pending_acks, &ack[i].ack_uuid.value);
5952 if (NULL == pa) 5873 if (NULL == pa)
5953 { 5874 {
5954 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 5875 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
5955 "Received ACK from %s with UUID %s which is unknown to us!\n", 5876 "Received ACK from %s with UUID %s which is unknown to us!\n",
5956 GNUNET_i2s (&cmc->im.sender), 5877 GNUNET_i2s(&cmc->im.sender),
5957 GNUNET_uuid2s (&ack[i].ack_uuid.value)); 5878 GNUNET_uuid2s(&ack[i].ack_uuid.value));
5958 GNUNET_STATISTICS_update ( 5879 GNUNET_STATISTICS_update(
5959 GST_stats, 5880 GST_stats,
5960 "# FRAGMENT_ACKS dropped, no matching pending message", 5881 "# FRAGMENT_ACKS dropped, no matching pending message",
5961 1, 5882 1,
5962 GNUNET_NO); 5883 GNUNET_NO);
5963 continue; 5884 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));
5964 } 5891 }
5965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5966 "Received ACK from %s with UUID %s\n",
5967 GNUNET_i2s (&cmc->im.sender),
5968 GNUNET_uuid2s (&ack[i].ack_uuid.value));
5969 handle_acknowledged (pa, GNUNET_TIME_relative_ntoh (ack[i].ack_delay));
5970 }
5971 5892
5972 ack_counter = htonl (ra->ack_counter); 5893 ack_counter = htonl(ra->ack_counter);
5973 (void) ack_counter; /* silence compiler warning for now */ 5894 (void)ack_counter; /* silence compiler warning for now */
5974 // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere! 5895 // FIXME-OPTIMIZE: track ACK losses based on ack_counter somewhere!
5975 // (DV and/or Neighbour?) 5896 // (DV and/or Neighbour?)
5976 finish_cmc_handling (cmc); 5897 finish_cmc_handling(cmc);
5977} 5898}
5978 5899
5979 5900
@@ -5985,30 +5906,30 @@ handle_reliability_ack (void *cls,
5985 * @return #GNUNET_YES if message is well-formed 5906 * @return #GNUNET_YES if message is well-formed
5986 */ 5907 */
5987static int 5908static int
5988check_backchannel_encapsulation ( 5909check_backchannel_encapsulation(
5989 void *cls, 5910 void *cls,
5990 const struct TransportBackchannelEncapsulationMessage *be) 5911 const struct TransportBackchannelEncapsulationMessage *be)
5991{ 5912{
5992 uint16_t size = ntohs (be->header.size) - sizeof (*be); 5913 uint16_t size = ntohs(be->header.size) - sizeof(*be);
5993 const struct GNUNET_MessageHeader *inbox = 5914 const struct GNUNET_MessageHeader *inbox =
5994 (const struct GNUNET_MessageHeader *) &be[1]; 5915 (const struct GNUNET_MessageHeader *)&be[1];
5995 const char *is; 5916 const char *is;
5996 uint16_t isize; 5917 uint16_t isize;
5997 5918
5998 (void) cls; 5919 (void)cls;
5999 if (ntohs (inbox->size) >= size) 5920 if (ntohs(inbox->size) >= size)
6000 { 5921 {
6001 GNUNET_break_op (0); 5922 GNUNET_break_op(0);
6002 return GNUNET_SYSERR; 5923 return GNUNET_SYSERR;
6003 } 5924 }
6004 isize = ntohs (inbox->size); 5925 isize = ntohs(inbox->size);
6005 is = ((const char *) inbox) + isize; 5926 is = ((const char *)inbox) + isize;
6006 size -= isize; 5927 size -= isize;
6007 if ('\0' != is[size - 1]) 5928 if ('\0' != is[size - 1])
6008 { 5929 {
6009 GNUNET_break_op (0); 5930 GNUNET_break_op(0);
6010 return GNUNET_SYSERR; 5931 return GNUNET_SYSERR;
6011 } 5932 }
6012 return GNUNET_YES; 5933 return GNUNET_YES;
6013} 5934}
6014 5935
@@ -6022,7 +5943,7 @@ check_backchannel_encapsulation (
6022 * @param be the message that was received 5943 * @param be the message that was received
6023 */ 5944 */
6024static void 5945static void
6025handle_backchannel_encapsulation ( 5946handle_backchannel_encapsulation(
6026 void *cls, 5947 void *cls,
6027 const struct TransportBackchannelEncapsulationMessage *be) 5948 const struct TransportBackchannelEncapsulationMessage *be)
6028{ 5949{
@@ -6031,41 +5952,41 @@ handle_backchannel_encapsulation (
6031 struct GNUNET_MQ_Envelope *env; 5952 struct GNUNET_MQ_Envelope *env;
6032 struct TransportClient *tc; 5953 struct TransportClient *tc;
6033 const struct GNUNET_MessageHeader *inbox = 5954 const struct GNUNET_MessageHeader *inbox =
6034 (const struct GNUNET_MessageHeader *) &be[1]; 5955 (const struct GNUNET_MessageHeader *)&be[1];
6035 uint16_t isize = ntohs (inbox->size); 5956 uint16_t isize = ntohs(inbox->size);
6036 const char *target_communicator = ((const char *) inbox) + isize; 5957 const char *target_communicator = ((const char *)inbox) + isize;
6037 5958
6038 /* Find client providing this communicator */ 5959 /* Find client providing this communicator */
6039 for (tc = clients_head; NULL != tc; tc = tc->next) 5960 for (tc = clients_head; NULL != tc; tc = tc->next)
6040 if ((CT_COMMUNICATOR == tc->type) && 5961 if ((CT_COMMUNICATOR == tc->type) &&
6041 (0 == 5962 (0 ==
6042 strcmp (tc->details.communicator.address_prefix, target_communicator))) 5963 strcmp(tc->details.communicator.address_prefix, target_communicator)))
6043 break; 5964 break;
6044 if (NULL == tc) 5965 if (NULL == tc)
6045 { 5966 {
6046 char *stastr; 5967 char *stastr;
6047 5968
6048 GNUNET_asprintf ( 5969 GNUNET_asprintf(
6049 &stastr, 5970 &stastr,
6050 "# Backchannel message dropped: target communicator `%s' unknown", 5971 "# Backchannel message dropped: target communicator `%s' unknown",
6051 target_communicator); 5972 target_communicator);
6052 GNUNET_STATISTICS_update (GST_stats, stastr, 1, GNUNET_NO); 5973 GNUNET_STATISTICS_update(GST_stats, stastr, 1, GNUNET_NO);
6053 GNUNET_free (stastr); 5974 GNUNET_free(stastr);
6054 return; 5975 return;
6055 } 5976 }
6056 /* Finally, deliver backchannel message to communicator */ 5977 /* Finally, deliver backchannel message to communicator */
6057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5978 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6058 "Delivering backchannel message from %s of type %u to %s\n", 5979 "Delivering backchannel message from %s of type %u to %s\n",
6059 GNUNET_i2s (&cmc->im.sender), 5980 GNUNET_i2s(&cmc->im.sender),
6060 ntohs (inbox->type), 5981 ntohs(inbox->type),
6061 target_communicator); 5982 target_communicator);
6062 env = GNUNET_MQ_msg_extra ( 5983 env = GNUNET_MQ_msg_extra(
6063 cbi, 5984 cbi,
6064 isize, 5985 isize,
6065 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING); 5986 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING);
6066 cbi->pid = cmc->im.sender; 5987 cbi->pid = cmc->im.sender;
6067 memcpy (&cbi[1], inbox, isize); 5988 memcpy(&cbi[1], inbox, isize);
6068 GNUNET_MQ_send (tc->mq, env); 5989 GNUNET_MQ_send(tc->mq, env);
6069} 5990}
6070 5991
6071 5992
@@ -6079,26 +6000,26 @@ handle_backchannel_encapsulation (
6079 * @param cls a `struct DistanceVector` 6000 * @param cls a `struct DistanceVector`
6080 */ 6001 */
6081static void 6002static void
6082path_cleanup_cb (void *cls) 6003path_cleanup_cb(void *cls)
6083{ 6004{
6084 struct DistanceVector *dv = cls; 6005 struct DistanceVector *dv = cls;
6085 struct DistanceVectorHop *pos; 6006 struct DistanceVectorHop *pos;
6086 6007
6087 dv->timeout_task = NULL; 6008 dv->timeout_task = NULL;
6088 while (NULL != (pos = dv->dv_head)) 6009 while (NULL != (pos = dv->dv_head))
6089 { 6010 {
6090 GNUNET_assert (dv == pos->dv); 6011 GNUNET_assert(dv == pos->dv);
6091 if (GNUNET_TIME_absolute_get_remaining (pos->timeout).rel_value_us > 0) 6012 if (GNUNET_TIME_absolute_get_remaining(pos->timeout).rel_value_us > 0)
6092 break; 6013 break;
6093 free_distance_vector_hop (pos); 6014 free_distance_vector_hop(pos);
6094 } 6015 }
6095 if (NULL == pos) 6016 if (NULL == pos)
6096 { 6017 {
6097 free_dv_route (dv); 6018 free_dv_route(dv);
6098 return; 6019 return;
6099 } 6020 }
6100 dv->timeout_task = 6021 dv->timeout_task =
6101 GNUNET_SCHEDULER_add_at (pos->timeout, &path_cleanup_cb, dv); 6022 GNUNET_SCHEDULER_add_at(pos->timeout, &path_cleanup_cb, dv);
6102} 6023}
6103 6024
6104 6025
@@ -6110,44 +6031,44 @@ path_cleanup_cb (void *cls)
6110 * @param hop a path to some peer that is the reason for activation 6031 * @param hop a path to some peer that is the reason for activation
6111 */ 6032 */
6112static void 6033static void
6113activate_core_visible_dv_path (struct DistanceVectorHop *hop) 6034activate_core_visible_dv_path(struct DistanceVectorHop *hop)
6114{ 6035{
6115 struct DistanceVector *dv = hop->dv; 6036 struct DistanceVector *dv = hop->dv;
6116 struct VirtualLink *vl; 6037 struct VirtualLink *vl;
6117 6038
6118 vl = lookup_virtual_link (&dv->target); 6039 vl = lookup_virtual_link(&dv->target);
6119 if (NULL != vl) 6040 if (NULL != vl)
6120 { 6041 {
6121 /* Link was already up, remember dv is also now available and we are done */ 6042 /* Link was already up, remember dv is also now available and we are done */
6122 vl->dv = dv; 6043 vl->dv = dv;
6123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6044 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6124 "Virtual link to %s could now also use DV!\n", 6045 "Virtual link to %s could now also use DV!\n",
6125 GNUNET_i2s (&dv->target)); 6046 GNUNET_i2s(&dv->target));
6126 return; 6047 return;
6127 } 6048 }
6128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6049 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6129 "Creating new virtual link to %s using DV!\n", 6050 "Creating new virtual link to %s using DV!\n",
6130 GNUNET_i2s (&dv->target)); 6051 GNUNET_i2s(&dv->target));
6131 vl = GNUNET_new (struct VirtualLink); 6052 vl = GNUNET_new(struct VirtualLink);
6132 vl->message_uuid_ctr = 6053 vl->message_uuid_ctr =
6133 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX); 6054 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT64_MAX);
6134 vl->target = dv->target; 6055 vl->target = dv->target;
6135 vl->dv = dv; 6056 vl->dv = dv;
6136 dv->vl = vl; 6057 dv->vl = vl;
6137 vl->core_recv_window = RECV_WINDOW_SIZE; 6058 vl->core_recv_window = RECV_WINDOW_SIZE;
6138 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; 6059 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
6139 vl->visibility_task = 6060 vl->visibility_task =
6140 GNUNET_SCHEDULER_add_at (hop->path_valid_until, &check_link_down, vl); 6061 GNUNET_SCHEDULER_add_at(hop->path_valid_until, &check_link_down, vl);
6141 GNUNET_break (GNUNET_YES == 6062 GNUNET_break(GNUNET_YES ==
6142 GNUNET_CONTAINER_multipeermap_put ( 6063 GNUNET_CONTAINER_multipeermap_put(
6143 links, 6064 links,
6144 &vl->target, 6065 &vl->target,
6145 vl, 6066 vl,
6146 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6067 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6147 consider_sending_fc (vl); 6068 consider_sending_fc(vl);
6148 /* We lacked a confirmed connection to the target 6069 /* We lacked a confirmed connection to the target
6149 before, so tell CORE about it (finally!) */ 6070 before, so tell CORE about it (finally!) */
6150 cores_send_connect_info (&dv->target); 6071 cores_send_connect_info(&dv->target);
6151} 6072}
6152 6073
6153 6074
@@ -6177,10 +6098,10 @@ activate_core_visible_dv_path (struct DistanceVectorHop *hop)
6177 * or path[i+1] is a direct neighbour for i>0) 6098 * or path[i+1] is a direct neighbour for i>0)
6178 */ 6099 */
6179static int 6100static int
6180learn_dv_path (const struct GNUNET_PeerIdentity *path, 6101learn_dv_path(const struct GNUNET_PeerIdentity *path,
6181 unsigned int path_len, 6102 unsigned int path_len,
6182 struct GNUNET_TIME_Relative network_latency, 6103 struct GNUNET_TIME_Relative network_latency,
6183 struct GNUNET_TIME_Absolute path_valid_until) 6104 struct GNUNET_TIME_Absolute path_valid_until)
6184{ 6105{
6185 struct DistanceVectorHop *hop; 6106 struct DistanceVectorHop *hop;
6186 struct DistanceVector *dv; 6107 struct DistanceVector *dv;
@@ -6188,143 +6109,143 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
6188 unsigned int shorter_distance; 6109 unsigned int shorter_distance;
6189 6110
6190 if (path_len < 3) 6111 if (path_len < 3)
6191 { 6112 {
6192 /* what a boring path! not allowed! */ 6113 /* what a boring path! not allowed! */
6193 GNUNET_break (0); 6114 GNUNET_break(0);
6194 return GNUNET_SYSERR; 6115 return GNUNET_SYSERR;
6195 } 6116 }
6196 GNUNET_assert (0 == GNUNET_memcmp (&GST_my_identity, &path[0])); 6117 GNUNET_assert(0 == GNUNET_memcmp(&GST_my_identity, &path[0]));
6197 next_hop = lookup_neighbour (&path[1]); 6118 next_hop = lookup_neighbour(&path[1]);
6198 if (NULL == next_hop) 6119 if (NULL == next_hop)
6199 { 6120 {
6200 /* next hop must be a neighbour, otherwise this whole thing is useless! */ 6121 /* next hop must be a neighbour, otherwise this whole thing is useless! */
6201 GNUNET_break (0); 6122 GNUNET_break(0);
6202 return GNUNET_SYSERR;
6203 }
6204 for (unsigned int i = 2; i < path_len; i++)
6205 if (NULL != lookup_neighbour (&path[i]))
6206 {
6207 /* Useless path: we have a direct connection to some hop
6208 in the middle of the path, so this one is not even
6209 terribly useful for redundancy */
6210 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
6211 "Path of %u hops useless: directly link to hop %u (%s)\n",
6212 path_len,
6213 i,
6214 GNUNET_i2s (&path[i]));
6215 GNUNET_STATISTICS_update (GST_stats,
6216 "# Useless DV path ignored: hop is neighbour",
6217 1,
6218 GNUNET_NO);
6219 return GNUNET_SYSERR; 6123 return GNUNET_SYSERR;
6220 } 6124 }
6221 dv = GNUNET_CONTAINER_multipeermap_get (dv_routes, &path[path_len - 1]); 6125 for (unsigned int i = 2; i < path_len; i++)
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]);
6222 if (NULL == dv) 6143 if (NULL == dv)
6223 { 6144 {
6224 dv = GNUNET_new (struct DistanceVector); 6145 dv = GNUNET_new(struct DistanceVector);
6225 dv->target = path[path_len - 1]; 6146 dv->target = path[path_len - 1];
6226 dv->timeout_task = GNUNET_SCHEDULER_add_delayed (DV_PATH_VALIDITY_TIMEOUT, 6147 dv->timeout_task = GNUNET_SCHEDULER_add_delayed(DV_PATH_VALIDITY_TIMEOUT,
6227 &path_cleanup_cb, 6148 &path_cleanup_cb,
6228 dv); 6149 dv);
6229 GNUNET_assert (GNUNET_OK == 6150 GNUNET_assert(GNUNET_OK ==
6230 GNUNET_CONTAINER_multipeermap_put ( 6151 GNUNET_CONTAINER_multipeermap_put(
6231 dv_routes, 6152 dv_routes,
6232 &dv->target, 6153 &dv->target,
6233 dv, 6154 dv,
6234 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 6155 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
6235 } 6156 }
6236 /* Check if we have this path already! */ 6157 /* Check if we have this path already! */
6237 shorter_distance = 0; 6158 shorter_distance = 0;
6238 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos; 6159 for (struct DistanceVectorHop *pos = dv->dv_head; NULL != pos;
6239 pos = pos->next_dv) 6160 pos = pos->next_dv)
6240 {
6241 if (pos->distance < path_len - 2)
6242 shorter_distance++;
6243 /* Note that the distances in 'pos' excludes us (path[0]) and
6244 the next_hop (path[1]), so we need to subtract two
6245 and check next_hop explicitly */
6246 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
6247 { 6161 {
6248 int match = GNUNET_YES; 6162 if (pos->distance < path_len - 2)
6249 6163 shorter_distance++;
6250 for (unsigned int i = 0; i < pos->distance; i++) 6164 /* Note that the distances in 'pos' excludes us (path[0]) and
6251 { 6165 the next_hop (path[1]), so we need to subtract two
6252 if (0 != GNUNET_memcmp (&pos->path[i], &path[i + 2])) 6166 and check next_hop explicitly */
6167 if ((pos->distance == path_len - 2) && (pos->next_hop == next_hop))
6253 { 6168 {
6254 match = GNUNET_NO; 6169 int match = GNUNET_YES;
6255 break; 6170
6256 } 6171 for (unsigned int i = 0; i < pos->distance; i++)
6257 } 6172 {
6258 if (GNUNET_YES == match) 6173 if (0 != GNUNET_memcmp(&pos->path[i], &path[i + 2]))
6259 { 6174 {
6260 struct GNUNET_TIME_Relative last_timeout; 6175 match = GNUNET_NO;
6261 6176 break;
6262 /* Re-discovered known path, update timeout */ 6177 }
6263 GNUNET_STATISTICS_update (GST_stats, 6178 }
6264 "# Known DV path refreshed", 6179 if (GNUNET_YES == match)
6265 1, 6180 {
6266 GNUNET_NO); 6181 struct GNUNET_TIME_Relative last_timeout;
6267 last_timeout = GNUNET_TIME_absolute_get_remaining (pos->timeout); 6182
6268 pos->timeout = 6183 /* Re-discovered known path, update timeout */
6269 GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 6184 GNUNET_STATISTICS_update(GST_stats,
6270 pos->path_valid_until = 6185 "# Known DV path refreshed",
6271 GNUNET_TIME_absolute_max (pos->path_valid_until, path_valid_until); 6186 1,
6272 GNUNET_CONTAINER_MDLL_remove (dv, dv->dv_head, dv->dv_tail, pos); 6187 GNUNET_NO);
6273 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, pos); 6188 last_timeout = GNUNET_TIME_absolute_get_remaining(pos->timeout);
6274 if (0 < 6189 pos->timeout =
6275 GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) 6190 GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT);
6276 activate_core_visible_dv_path (pos); 6191 pos->path_valid_until =
6277 if (last_timeout.rel_value_us < 6192 GNUNET_TIME_absolute_max(pos->path_valid_until, path_valid_until);
6278 GNUNET_TIME_relative_subtract (DV_PATH_VALIDITY_TIMEOUT, 6193 GNUNET_CONTAINER_MDLL_remove(dv, dv->dv_head, dv->dv_tail, pos);
6279 DV_PATH_DISCOVERY_FREQUENCY) 6194 GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, pos);
6280 .rel_value_us) 6195 if (0 <
6281 { 6196 GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us)
6282 /* Some peer send DV learn messages too often, we are learning 6197 activate_core_visible_dv_path(pos);
6283 the same path faster than it would be useful; do not forward! */ 6198 if (last_timeout.rel_value_us <
6284 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6199 GNUNET_TIME_relative_subtract(DV_PATH_VALIDITY_TIMEOUT,
6285 "Rediscovered path too quickly, not forwarding further\n"); 6200 DV_PATH_DISCOVERY_FREQUENCY)
6286 return GNUNET_NO; 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 }
6287 } 6214 }
6288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6289 "Refreshed known path to %s, forwarding further\n",
6290 GNUNET_i2s (&dv->target));
6291 return GNUNET_YES;
6292 }
6293 } 6215 }
6294 }
6295 /* Count how many shorter paths we have (incl. direct 6216 /* Count how many shorter paths we have (incl. direct
6296 neighbours) before simply giving up on this one! */ 6217 neighbours) before simply giving up on this one! */
6297 if (shorter_distance >= MAX_DV_PATHS_TO_TARGET) 6218 if (shorter_distance >= MAX_DV_PATHS_TO_TARGET)
6298 { 6219 {
6299 /* We have a shorter path already! */ 6220 /* We have a shorter path already! */
6300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6221 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6301 "Have many shorter DV paths %s, not forwarding further\n", 6222 "Have many shorter DV paths %s, not forwarding further\n",
6302 GNUNET_i2s (&dv->target)); 6223 GNUNET_i2s(&dv->target));
6303 return GNUNET_NO; 6224 return GNUNET_NO;
6304 } 6225 }
6305 /* create new DV path entry */ 6226 /* create new DV path entry */
6306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6227 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6307 "Discovered new DV path to %s\n", 6228 "Discovered new DV path to %s\n",
6308 GNUNET_i2s (&dv->target)); 6229 GNUNET_i2s(&dv->target));
6309 hop = GNUNET_malloc (sizeof (struct DistanceVectorHop) + 6230 hop = GNUNET_malloc(sizeof(struct DistanceVectorHop) +
6310 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); 6231 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2));
6311 hop->next_hop = next_hop; 6232 hop->next_hop = next_hop;
6312 hop->dv = dv; 6233 hop->dv = dv;
6313 hop->path = (const struct GNUNET_PeerIdentity *) &hop[1]; 6234 hop->path = (const struct GNUNET_PeerIdentity *)&hop[1];
6314 memcpy (&hop[1], 6235 memcpy(&hop[1],
6315 &path[2], 6236 &path[2],
6316 sizeof (struct GNUNET_PeerIdentity) * (path_len - 2)); 6237 sizeof(struct GNUNET_PeerIdentity) * (path_len - 2));
6317 hop->timeout = GNUNET_TIME_relative_to_absolute (DV_PATH_VALIDITY_TIMEOUT); 6238 hop->timeout = GNUNET_TIME_relative_to_absolute(DV_PATH_VALIDITY_TIMEOUT);
6318 hop->path_valid_until = path_valid_until; 6239 hop->path_valid_until = path_valid_until;
6319 hop->distance = path_len - 2; 6240 hop->distance = path_len - 2;
6320 hop->pd.aged_rtt = network_latency; 6241 hop->pd.aged_rtt = network_latency;
6321 GNUNET_CONTAINER_MDLL_insert (dv, dv->dv_head, dv->dv_tail, hop); 6242 GNUNET_CONTAINER_MDLL_insert(dv, dv->dv_head, dv->dv_tail, hop);
6322 GNUNET_CONTAINER_MDLL_insert (neighbour, 6243 GNUNET_CONTAINER_MDLL_insert(neighbour,
6323 next_hop->dv_head, 6244 next_hop->dv_head,
6324 next_hop->dv_tail, 6245 next_hop->dv_tail,
6325 hop); 6246 hop);
6326 if (0 < GNUNET_TIME_absolute_get_remaining (path_valid_until).rel_value_us) 6247 if (0 < GNUNET_TIME_absolute_get_remaining(path_valid_until).rel_value_us)
6327 activate_core_visible_dv_path (hop); 6248 activate_core_visible_dv_path(hop);
6328 return GNUNET_YES; 6249 return GNUNET_YES;
6329} 6250}
6330 6251
@@ -6337,36 +6258,36 @@ learn_dv_path (const struct GNUNET_PeerIdentity *path,
6337 * @return #GNUNET_YES if message is well-formed 6258 * @return #GNUNET_YES if message is well-formed
6338 */ 6259 */
6339static int 6260static int
6340check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) 6261check_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6341{ 6262{
6342 uint16_t size = ntohs (dvl->header.size); 6263 uint16_t size = ntohs(dvl->header.size);
6343 uint16_t num_hops = ntohs (dvl->num_hops); 6264 uint16_t num_hops = ntohs(dvl->num_hops);
6344 const struct DVPathEntryP *hops = (const struct DVPathEntryP *) &dvl[1]; 6265 const struct DVPathEntryP *hops = (const struct DVPathEntryP *)&dvl[1];
6345 6266
6346 (void) cls; 6267 (void)cls;
6347 if (size != sizeof (*dvl) + num_hops * sizeof (struct DVPathEntryP)) 6268 if (size != sizeof(*dvl) + num_hops * sizeof(struct DVPathEntryP))
6348 {
6349 GNUNET_break_op (0);
6350 return GNUNET_SYSERR;
6351 }
6352 if (num_hops > MAX_DV_HOPS_ALLOWED)
6353 {
6354 GNUNET_break_op (0);
6355 return GNUNET_SYSERR;
6356 }
6357 for (unsigned int i = 0; i < num_hops; i++)
6358 {
6359 if (0 == GNUNET_memcmp (&dvl->initiator, &hops[i].hop))
6360 { 6269 {
6361 GNUNET_break_op (0); 6270 GNUNET_break_op(0);
6362 return GNUNET_SYSERR; 6271 return GNUNET_SYSERR;
6363 } 6272 }
6364 if (0 == GNUNET_memcmp (&GST_my_identity, &hops[i].hop)) 6273 if (num_hops > MAX_DV_HOPS_ALLOWED)
6365 { 6274 {
6366 GNUNET_break_op (0); 6275 GNUNET_break_op(0);
6367 return GNUNET_SYSERR; 6276 return GNUNET_SYSERR;
6368 } 6277 }
6369 } 6278 for (unsigned int i = 0; i < num_hops; i++)
6279 {
6280 if (0 == GNUNET_memcmp(&dvl->initiator, &hops[i].hop))
6281 {
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 }
6370 return GNUNET_YES; 6291 return GNUNET_YES;
6371} 6292}
6372 6293
@@ -6383,56 +6304,56 @@ check_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6383 * delay 6304 * delay
6384 */ 6305 */
6385static void 6306static void
6386forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop, 6307forward_dv_learn(const struct GNUNET_PeerIdentity *next_hop,
6387 const struct TransportDVLearnMessage *msg, 6308 const struct TransportDVLearnMessage *msg,
6388 uint16_t bi_history, 6309 uint16_t bi_history,
6389 uint16_t nhops, 6310 uint16_t nhops,
6390 const struct DVPathEntryP *hops, 6311 const struct DVPathEntryP *hops,
6391 struct GNUNET_TIME_Absolute in_time) 6312 struct GNUNET_TIME_Absolute in_time)
6392{ 6313{
6393 struct DVPathEntryP *dhops; 6314 struct DVPathEntryP *dhops;
6394 char buf[sizeof (struct TransportDVLearnMessage) + 6315 char buf[sizeof(struct TransportDVLearnMessage) +
6395 (nhops + 1) * sizeof (struct DVPathEntryP)] GNUNET_ALIGN; 6316 (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN;
6396 struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *) buf; 6317 struct TransportDVLearnMessage *fwd = (struct TransportDVLearnMessage *)buf;
6397 struct GNUNET_TIME_Relative nnd; 6318 struct GNUNET_TIME_Relative nnd;
6398 6319
6399 /* compute message for forwarding */ 6320 /* compute message for forwarding */
6400 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6321 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6401 "Forwarding DV learn message originating from %s to %s\n", 6322 "Forwarding DV learn message originating from %s to %s\n",
6402 GNUNET_i2s (&msg->initiator), 6323 GNUNET_i2s(&msg->initiator),
6403 GNUNET_i2s2 (next_hop)); 6324 GNUNET_i2s2(next_hop));
6404 GNUNET_assert (nhops < MAX_DV_HOPS_ALLOWED); 6325 GNUNET_assert(nhops < MAX_DV_HOPS_ALLOWED);
6405 fwd->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 6326 fwd->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
6406 fwd->header.size = htons (sizeof (struct TransportDVLearnMessage) + 6327 fwd->header.size = htons(sizeof(struct TransportDVLearnMessage) +
6407 (nhops + 1) * sizeof (struct DVPathEntryP)); 6328 (nhops + 1) * sizeof(struct DVPathEntryP));
6408 fwd->num_hops = htons (nhops + 1); 6329 fwd->num_hops = htons(nhops + 1);
6409 fwd->bidirectional = htons (bi_history); 6330 fwd->bidirectional = htons(bi_history);
6410 nnd = GNUNET_TIME_relative_add (GNUNET_TIME_absolute_get_duration (in_time), 6331 nnd = GNUNET_TIME_relative_add(GNUNET_TIME_absolute_get_duration(in_time),
6411 GNUNET_TIME_relative_ntoh ( 6332 GNUNET_TIME_relative_ntoh(
6412 msg->non_network_delay)); 6333 msg->non_network_delay));
6413 fwd->non_network_delay = GNUNET_TIME_relative_hton (nnd); 6334 fwd->non_network_delay = GNUNET_TIME_relative_hton(nnd);
6414 fwd->init_sig = msg->init_sig; 6335 fwd->init_sig = msg->init_sig;
6415 fwd->initiator = msg->initiator; 6336 fwd->initiator = msg->initiator;
6416 fwd->challenge = msg->challenge; 6337 fwd->challenge = msg->challenge;
6417 dhops = (struct DVPathEntryP *) &fwd[1]; 6338 dhops = (struct DVPathEntryP *)&fwd[1];
6418 GNUNET_memcpy (dhops, hops, sizeof (struct DVPathEntryP) * nhops); 6339 GNUNET_memcpy(dhops, hops, sizeof(struct DVPathEntryP) * nhops);
6419 dhops[nhops].hop = GST_my_identity; 6340 dhops[nhops].hop = GST_my_identity;
6420 { 6341 {
6421 struct DvHopPS dhp = {.purpose.purpose = 6342 struct DvHopPS dhp = { .purpose.purpose =
6422 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 6343 htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
6423 .purpose.size = htonl (sizeof (dhp)), 6344 .purpose.size = htonl(sizeof(dhp)),
6424 .pred = dhops[nhops - 1].hop, 6345 .pred = dhops[nhops - 1].hop,
6425 .succ = *next_hop, 6346 .succ = *next_hop,
6426 .challenge = msg->challenge}; 6347 .challenge = msg->challenge };
6427 6348
6428 GNUNET_assert (GNUNET_OK == 6349 GNUNET_assert(GNUNET_OK ==
6429 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 6350 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
6430 &dhp.purpose, 6351 &dhp.purpose,
6431 &dhops[nhops].hop_sig)); 6352 &dhops[nhops].hop_sig));
6432 } 6353 }
6433 route_control_message_without_fc (next_hop, 6354 route_control_message_without_fc(next_hop,
6434 &fwd->header, 6355 &fwd->header,
6435 RMO_UNCONFIRMED_ALLOWED); 6356 RMO_UNCONFIRMED_ALLOWED);
6436} 6357}
6437 6358
6438 6359
@@ -6446,28 +6367,28 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
6446 * @return #GNUNET_OK if the signature is valid 6367 * @return #GNUNET_OK if the signature is valid
6447 */ 6368 */
6448static int 6369static int
6449validate_dv_initiator_signature ( 6370validate_dv_initiator_signature(
6450 struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time, 6371 struct GNUNET_TIME_AbsoluteNBO sender_monotonic_time,
6451 const struct GNUNET_PeerIdentity *init, 6372 const struct GNUNET_PeerIdentity *init,
6452 const struct ChallengeNonceP *challenge, 6373 const struct ChallengeNonceP *challenge,
6453 const struct GNUNET_CRYPTO_EddsaSignature *init_sig) 6374 const struct GNUNET_CRYPTO_EddsaSignature *init_sig)
6454{ 6375{
6455 struct DvInitPS ip = {.purpose.purpose = htonl ( 6376 struct DvInitPS ip = { .purpose.purpose = htonl(
6456 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 6377 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
6457 .purpose.size = htonl (sizeof (ip)), 6378 .purpose.size = htonl(sizeof(ip)),
6458 .monotonic_time = sender_monotonic_time, 6379 .monotonic_time = sender_monotonic_time,
6459 .challenge = *challenge}; 6380 .challenge = *challenge };
6460 6381
6461 if ( 6382 if (
6462 GNUNET_OK != 6383 GNUNET_OK !=
6463 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR, 6384 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR,
6464 &ip.purpose, 6385 &ip.purpose,
6465 init_sig, 6386 init_sig,
6466 &init->public_key)) 6387 &init->public_key))
6467 { 6388 {
6468 GNUNET_break_op (0); 6389 GNUNET_break_op(0);
6469 return GNUNET_SYSERR; 6390 return GNUNET_SYSERR;
6470 } 6391 }
6471 return GNUNET_OK; 6392 return GNUNET_OK;
6472} 6393}
6473 6394
@@ -6475,8 +6396,7 @@ validate_dv_initiator_signature (
6475/** 6396/**
6476 * Closure for #dv_neighbour_selection and #dv_neighbour_transmission. 6397 * Closure for #dv_neighbour_selection and #dv_neighbour_transmission.
6477 */ 6398 */
6478struct NeighbourSelectionContext 6399struct NeighbourSelectionContext {
6479{
6480 /** 6400 /**
6481 * Original message we received. 6401 * Original message we received.
6482 */ 6402 */
@@ -6528,18 +6448,19 @@ struct NeighbourSelectionContext
6528 * @return #GNUNET_YES (always) 6448 * @return #GNUNET_YES (always)
6529 */ 6449 */
6530static int 6450static int
6531dv_neighbour_selection (void *cls, 6451dv_neighbour_selection(void *cls,
6532 const struct GNUNET_PeerIdentity *pid, 6452 const struct GNUNET_PeerIdentity *pid,
6533 void *value) 6453 void *value)
6534{ 6454{
6535 struct NeighbourSelectionContext *nsc = cls; 6455 struct NeighbourSelectionContext *nsc = cls;
6536 6456
6537 (void) value; 6457 (void)value;
6538 if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) 6458 if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator))
6539 return GNUNET_YES; /* skip initiator */ 6459 return GNUNET_YES; /* skip initiator */
6540 for (unsigned int i = 0; i < nsc->nhops; i++) 6460 for (unsigned int i = 0; i < nsc->nhops; i++)
6541 if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) 6461 if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop))
6542 return GNUNET_YES; /* skip peers on path */ 6462 return GNUNET_YES;
6463 /* skip peers on path */
6543 nsc->num_eligible++; 6464 nsc->num_eligible++;
6544 return GNUNET_YES; 6465 return GNUNET_YES;
6545} 6466}
@@ -6556,31 +6477,32 @@ dv_neighbour_selection (void *cls,
6556 * @return #GNUNET_YES (always) 6477 * @return #GNUNET_YES (always)
6557 */ 6478 */
6558static int 6479static int
6559dv_neighbour_transmission (void *cls, 6480dv_neighbour_transmission(void *cls,
6560 const struct GNUNET_PeerIdentity *pid, 6481 const struct GNUNET_PeerIdentity *pid,
6561 void *value) 6482 void *value)
6562{ 6483{
6563 struct NeighbourSelectionContext *nsc = cls; 6484 struct NeighbourSelectionContext *nsc = cls;
6564 6485
6565 (void) value; 6486 (void)value;
6566 if (0 == GNUNET_memcmp (pid, &nsc->dvl->initiator)) 6487 if (0 == GNUNET_memcmp(pid, &nsc->dvl->initiator))
6567 return GNUNET_YES; /* skip initiator */ 6488 return GNUNET_YES; /* skip initiator */
6568 for (unsigned int i = 0; i < nsc->nhops; i++) 6489 for (unsigned int i = 0; i < nsc->nhops; i++)
6569 if (0 == GNUNET_memcmp (pid, &nsc->hops[i].hop)) 6490 if (0 == GNUNET_memcmp(pid, &nsc->hops[i].hop))
6570 return GNUNET_YES; /* skip peers on path */ 6491 return GNUNET_YES;
6492 /* skip peers on path */
6571 for (unsigned int i = 0; i < nsc->num_selections; i++) 6493 for (unsigned int i = 0; i < nsc->num_selections; i++)
6572 { 6494 {
6573 if (nsc->selections[i] == nsc->num_eligible) 6495 if (nsc->selections[i] == nsc->num_eligible)
6574 { 6496 {
6575 forward_dv_learn (pid, 6497 forward_dv_learn(pid,
6576 nsc->dvl, 6498 nsc->dvl,
6577 nsc->bi_history, 6499 nsc->bi_history,
6578 nsc->nhops, 6500 nsc->nhops,
6579 nsc->hops, 6501 nsc->hops,
6580 nsc->in_time); 6502 nsc->in_time);
6581 break; 6503 break;
6504 }
6582 } 6505 }
6583 }
6584 nsc->num_eligible++; 6506 nsc->num_eligible++;
6585 return GNUNET_YES; 6507 return GNUNET_YES;
6586} 6508}
@@ -6630,42 +6552,42 @@ dv_neighbour_transmission (void *cls,
6630 * theory forward to 6552 * theory forward to
6631 */ 6553 */
6632static unsigned int 6554static unsigned int
6633calculate_fork_degree (unsigned int hops_taken, 6555calculate_fork_degree(unsigned int hops_taken,
6634 unsigned int neighbour_count, 6556 unsigned int neighbour_count,
6635 unsigned int eligible_count) 6557 unsigned int eligible_count)
6636{ 6558{
6637 double target_total = 50.0; /* FIXME: use LOG(NSE)? */ 6559 double target_total = 50.0; /* FIXME: use LOG(NSE)? */
6638 double eligible_ratio = 6560 double eligible_ratio =
6639 ((double) eligible_count) / ((double) neighbour_count); 6561 ((double)eligible_count) / ((double)neighbour_count);
6640 double boost_factor = eligible_ratio * eligible_ratio; 6562 double boost_factor = eligible_ratio * eligible_ratio;
6641 unsigned int rnd; 6563 unsigned int rnd;
6642 double left; 6564 double left;
6643 6565
6644 if (hops_taken >= 64) 6566 if (hops_taken >= 64)
6645 { 6567 {
6646 GNUNET_break (0); 6568 GNUNET_break(0);
6647 return 0; /* precaution given bitshift below */ 6569 return 0; /* precaution given bitshift below */
6648 } 6570 }
6649 for (unsigned int i = 1; i < hops_taken; i++) 6571 for (unsigned int i = 1; i < hops_taken; i++)
6650 { 6572 {
6651 /* For each hop, subtract the expected number of targets 6573 /* For each hop, subtract the expected number of targets
6652 reached at distance d (so what remains divided by 2^d) */ 6574 reached at distance d (so what remains divided by 2^d) */
6653 target_total -= (target_total * boost_factor / (1LLU << i)); 6575 target_total -= (target_total * boost_factor / (1LLU << i));
6654 } 6576 }
6655 rnd = 6577 rnd =
6656 (unsigned int) floor (target_total * boost_factor / (1LLU << hops_taken)); 6578 (unsigned int)floor(target_total * boost_factor / (1LLU << hops_taken));
6657 /* round up or down probabilistically depending on how close we were 6579 /* round up or down probabilistically depending on how close we were
6658 when floor()ing to rnd */ 6580 when floor()ing to rnd */
6659 left = target_total - (double) rnd; 6581 left = target_total - (double)rnd;
6660 if (UINT32_MAX * left > 6582 if (UINT32_MAX * left >
6661 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)) 6583 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX))
6662 rnd++; /* round up */ 6584 rnd++; /* round up */
6663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6585 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6664 "Forwarding DV learn message of %u hops %u(/%u/%u) times\n", 6586 "Forwarding DV learn message of %u hops %u(/%u/%u) times\n",
6665 hops_taken, 6587 hops_taken,
6666 rnd, 6588 rnd,
6667 eligible_count, 6589 eligible_count,
6668 neighbour_count); 6590 neighbour_count);
6669 return rnd; 6591 return rnd;
6670} 6592}
6671 6593
@@ -6677,14 +6599,14 @@ calculate_fork_degree (unsigned int hops_taken,
6677 * @param success #GNUNET_YES if peerstore was successful 6599 * @param success #GNUNET_YES if peerstore was successful
6678 */ 6600 */
6679static void 6601static void
6680neighbour_store_dvmono_cb (void *cls, int success) 6602neighbour_store_dvmono_cb(void *cls, int success)
6681{ 6603{
6682 struct Neighbour *n = cls; 6604 struct Neighbour *n = cls;
6683 6605
6684 n->sc = NULL; 6606 n->sc = NULL;
6685 if (GNUNET_YES != success) 6607 if (GNUNET_YES != success)
6686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6608 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
6687 "Failed to store other peer's monotonic time in peerstore!\n"); 6609 "Failed to store other peer's monotonic time in peerstore!\n");
6688} 6610}
6689 6611
6690 6612
@@ -6696,7 +6618,7 @@ neighbour_store_dvmono_cb (void *cls, int success)
6696 * @param dvl the message that was received 6618 * @param dvl the message that was received
6697 */ 6619 */
6698static void 6620static void
6699handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl) 6621handle_dv_learn(void *cls, const struct TransportDVLearnMessage *dvl)
6700{ 6622{
6701 struct CommunicatorMessageContext *cmc = cls; 6623 struct CommunicatorMessageContext *cmc = cls;
6702 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc; 6624 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc;
@@ -6709,287 +6631,287 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
6709 struct GNUNET_TIME_Absolute in_time; 6631 struct GNUNET_TIME_Absolute in_time;
6710 struct Neighbour *n; 6632 struct Neighbour *n;
6711 6633
6712 nhops = ntohs (dvl->bidirectional); /* 0 = sender is initiator */ 6634 nhops = ntohs(dvl->bidirectional); /* 0 = sender is initiator */
6713 bi_history = ntohs (dvl->bidirectional); 6635 bi_history = ntohs(dvl->bidirectional);
6714 hops = (const struct DVPathEntryP *) &dvl[1]; 6636 hops = (const struct DVPathEntryP *)&dvl[1];
6715 if (0 == nhops) 6637 if (0 == nhops)
6716 {
6717 /* sanity check */
6718 if (0 != GNUNET_memcmp (&dvl->initiator, &cmc->im.sender))
6719 { 6638 {
6720 GNUNET_break (0); 6639 /* sanity check */
6721 finish_cmc_handling (cmc); 6640 if (0 != GNUNET_memcmp(&dvl->initiator, &cmc->im.sender))
6722 return; 6641 {
6642 GNUNET_break(0);
6643 finish_cmc_handling(cmc);
6644 return;
6645 }
6723 } 6646 }
6724 }
6725 else 6647 else
6726 {
6727 /* sanity check */
6728 if (0 != GNUNET_memcmp (&hops[nhops - 1].hop, &cmc->im.sender))
6729 { 6648 {
6730 GNUNET_break (0); 6649 /* sanity check */
6731 finish_cmc_handling (cmc); 6650 if (0 != GNUNET_memcmp(&hops[nhops - 1].hop, &cmc->im.sender))
6732 return; 6651 {
6652 GNUNET_break(0);
6653 finish_cmc_handling(cmc);
6654 return;
6655 }
6733 } 6656 }
6734 }
6735 6657
6736 GNUNET_assert (CT_COMMUNICATOR == cmc->tc->type); 6658 GNUNET_assert(CT_COMMUNICATOR == cmc->tc->type);
6737 cc = cmc->tc->details.communicator.cc; 6659 cc = cmc->tc->details.communicator.cc;
6738 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE == 6660 bi_hop = (GNUNET_TRANSPORT_CC_RELIABLE ==
6739 cc); // FIXME: add bi-directional flag to cc? 6661 cc); // FIXME: add bi-directional flag to cc?
6740 in_time = GNUNET_TIME_absolute_get (); 6662 in_time = GNUNET_TIME_absolute_get();
6741 6663
6742 /* continue communicator here, everything else can happen asynchronous! */ 6664 /* continue communicator here, everything else can happen asynchronous! */
6743 finish_cmc_handling (cmc); 6665 finish_cmc_handling(cmc);
6744 6666
6745 n = lookup_neighbour (&dvl->initiator); 6667 n = lookup_neighbour(&dvl->initiator);
6746 if (NULL != n) 6668 if (NULL != n)
6747 {
6748 if ((n->dv_monotime_available == GNUNET_YES) &&
6749 (GNUNET_TIME_absolute_ntoh (dvl->monotonic_time).abs_value_us <
6750 n->last_dv_learn_monotime.abs_value_us))
6751 {
6752 GNUNET_STATISTICS_update (GST_stats,
6753 "# DV learn discarded due to time travel",
6754 1,
6755 GNUNET_NO);
6756 return;
6757 }
6758 if (GNUNET_OK != validate_dv_initiator_signature (dvl->monotonic_time,
6759 &dvl->initiator,
6760 &dvl->challenge,
6761 &dvl->init_sig))
6762 { 6669 {
6763 GNUNET_break_op (0); 6670 if ((n->dv_monotime_available == GNUNET_YES) &&
6764 return; 6671 (GNUNET_TIME_absolute_ntoh(dvl->monotonic_time).abs_value_us <
6765 } 6672 n->last_dv_learn_monotime.abs_value_us))
6766 n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh (dvl->monotonic_time); 6673 {
6767 if (GNUNET_YES == n->dv_monotime_available) 6674 GNUNET_STATISTICS_update(GST_stats,
6768 { 6675 "# DV learn discarded due to time travel",
6769 if (NULL != n->sc) 6676 1,
6770 GNUNET_PEERSTORE_store_cancel (n->sc); 6677 GNUNET_NO);
6771 n->sc = 6678 return;
6772 GNUNET_PEERSTORE_store (peerstore, 6679 }
6773 "transport", 6680 if (GNUNET_OK != validate_dv_initiator_signature(dvl->monotonic_time,
6774 &dvl->initiator, 6681 &dvl->initiator,
6775 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, 6682 &dvl->challenge,
6776 &dvl->monotonic_time, 6683 &dvl->init_sig))
6777 sizeof (dvl->monotonic_time), 6684 {
6778 GNUNET_TIME_UNIT_FOREVER_ABS, 6685 GNUNET_break_op(0);
6779 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 6686 return;
6780 &neighbour_store_dvmono_cb, 6687 }
6781 n); 6688 n->last_dv_learn_monotime = GNUNET_TIME_absolute_ntoh(dvl->monotonic_time);
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 }
6782 } 6705 }
6783 }
6784 /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!, 6706 /* OPTIMIZE-FIXME: asynchronously (!) verify signatures!,
6785 If signature verification load too high, implement random drop strategy */ 6707 If signature verification load too high, implement random drop strategy */
6786 for (unsigned int i = 0; i < nhops; i++) 6708 for (unsigned int i = 0; i < nhops; i++)
6787 { 6709 {
6788 struct DvHopPS dhp = {.purpose.purpose = 6710 struct DvHopPS dhp = { .purpose.purpose =
6789 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP), 6711 htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP),
6790 .purpose.size = htonl (sizeof (dhp)), 6712 .purpose.size = htonl(sizeof(dhp)),
6791 .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop, 6713 .pred = (0 == i) ? dvl->initiator : hops[i - 1].hop,
6792 .succ = (nhops == i + 1) ? GST_my_identity 6714 .succ = (nhops == i + 1) ? GST_my_identity
6793 : hops[i + 1].hop, 6715 : hops[i + 1].hop,
6794 .challenge = dvl->challenge}; 6716 .challenge = dvl->challenge };
6795 6717
6796 if (GNUNET_OK != 6718 if (GNUNET_OK !=
6797 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP, 6719 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_HOP,
6798 &dhp.purpose, 6720 &dhp.purpose,
6799 &hops[i].hop_sig, 6721 &hops[i].hop_sig,
6800 &hops[i].hop.public_key)) 6722 &hops[i].hop.public_key))
6801 { 6723 {
6802 GNUNET_break_op (0); 6724 GNUNET_break_op(0);
6803 return; 6725 return;
6726 }
6804 } 6727 }
6805 }
6806 6728
6807 if (GNUNET_EXTRA_LOGGING > 0) 6729 if (GNUNET_EXTRA_LOGGING > 0)
6808 { 6730 {
6809 char *path; 6731 char *path;
6810 6732
6811 path = GNUNET_strdup (GNUNET_i2s (&dvl->initiator)); 6733 path = GNUNET_strdup(GNUNET_i2s(&dvl->initiator));
6812 for (unsigned int i = 0; i < nhops; i++) 6734 for (unsigned int i = 0; i < nhops; i++)
6813 { 6735 {
6814 char *tmp; 6736 char *tmp;
6815 6737
6816 GNUNET_asprintf (&tmp, 6738 GNUNET_asprintf(&tmp,
6817 "%s%s%s", 6739 "%s%s%s",
6818 path, 6740 path,
6819 (bi_history & (1 << (nhops - i))) ? "<->" : "-->", 6741 (bi_history & (1 << (nhops - i))) ? "<->" : "-->",
6820 GNUNET_i2s (&hops[i].hop)); 6742 GNUNET_i2s(&hops[i].hop));
6821 GNUNET_free (path); 6743 GNUNET_free(path);
6822 path = tmp; 6744 path = tmp;
6823 } 6745 }
6824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6746 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6825 "Received DVInit via %s%s%s\n", 6747 "Received DVInit via %s%s%s\n",
6826 path, 6748 path,
6827 bi_hop ? "<->" : "-->", 6749 bi_hop ? "<->" : "-->",
6828 GNUNET_i2s (&GST_my_identity)); 6750 GNUNET_i2s(&GST_my_identity));
6829 GNUNET_free (path); 6751 GNUNET_free(path);
6830 } 6752 }
6831 6753
6832 do_fwd = GNUNET_YES; 6754 do_fwd = GNUNET_YES;
6833 if (0 == GNUNET_memcmp (&GST_my_identity, &dvl->initiator)) 6755 if (0 == GNUNET_memcmp(&GST_my_identity, &dvl->initiator))
6834 { 6756 {
6835 struct GNUNET_PeerIdentity path[nhops + 1]; 6757 struct GNUNET_PeerIdentity path[nhops + 1];
6836 struct GNUNET_TIME_Relative host_latency_sum; 6758 struct GNUNET_TIME_Relative host_latency_sum;
6837 struct GNUNET_TIME_Relative latency; 6759 struct GNUNET_TIME_Relative latency;
6838 struct GNUNET_TIME_Relative network_latency; 6760 struct GNUNET_TIME_Relative network_latency;
6839 6761
6840 /* We initiated this, learn the forward path! */ 6762 /* We initiated this, learn the forward path! */
6841 path[0] = GST_my_identity; 6763 path[0] = GST_my_identity;
6842 path[1] = hops[0].hop; 6764 path[1] = hops[0].hop;
6843 host_latency_sum = GNUNET_TIME_relative_ntoh (dvl->non_network_delay); 6765 host_latency_sum = GNUNET_TIME_relative_ntoh(dvl->non_network_delay);
6844 6766
6845 // Need also something to lookup initiation time 6767 // Need also something to lookup initiation time
6846 // to compute RTT! -> add RTT argument here? 6768 // to compute RTT! -> add RTT argument here?
6847 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly 6769 latency = GNUNET_TIME_UNIT_FOREVER_REL; // FIXME: initialize properly
6848 // (based on dvl->challenge, we can identify time of origin!) 6770 // (based on dvl->challenge, we can identify time of origin!)
6849 6771
6850 network_latency = GNUNET_TIME_relative_subtract (latency, host_latency_sum); 6772 network_latency = GNUNET_TIME_relative_subtract(latency, host_latency_sum);
6851 /* assumption: latency on all links is the same */ 6773 /* assumption: latency on all links is the same */
6852 network_latency = GNUNET_TIME_relative_divide (network_latency, nhops); 6774 network_latency = GNUNET_TIME_relative_divide(network_latency, nhops);
6853 6775
6854 for (unsigned int i = 2; i <= nhops; i++) 6776 for (unsigned int i = 2; i <= nhops; i++)
6855 { 6777 {
6856 struct GNUNET_TIME_Relative ilat; 6778 struct GNUNET_TIME_Relative ilat;
6857 6779
6858 /* assumption: linear latency increase per hop */ 6780 /* assumption: linear latency increase per hop */
6859 ilat = GNUNET_TIME_relative_multiply (network_latency, i); 6781 ilat = GNUNET_TIME_relative_multiply(network_latency, i);
6860 path[i] = hops[i - 1].hop; 6782 path[i] = hops[i - 1].hop;
6861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6783 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6862 "Learned path with %u hops to %s with latency %s\n", 6784 "Learned path with %u hops to %s with latency %s\n",
6863 i,
6864 GNUNET_i2s (&path[i]),
6865 GNUNET_STRINGS_relative_time_to_string (ilat, GNUNET_YES));
6866 learn_dv_path (path,
6867 i, 6785 i,
6868 ilat, 6786 GNUNET_i2s(&path[i]),
6869 GNUNET_TIME_relative_to_absolute ( 6787 GNUNET_STRINGS_relative_time_to_string(ilat, GNUNET_YES));
6870 ADDRESS_VALIDATION_LIFETIME)); 6788 learn_dv_path(path,
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;
6871 } 6797 }
6872 /* as we initiated, do not forward again (would be circular!) */
6873 do_fwd = GNUNET_NO;
6874 return;
6875 }
6876 if (bi_hop) 6798 if (bi_hop)
6877 {
6878 /* last hop was bi-directional, we could learn something here! */
6879 struct GNUNET_PeerIdentity path[nhops + 2];
6880
6881 path[0] = GST_my_identity;
6882 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
6883 for (unsigned int i = 0; i < nhops; i++)
6884 { 6799 {
6885 int iret; 6800 /* last hop was bi-directional, we could learn something here! */
6886 6801 struct GNUNET_PeerIdentity path[nhops + 2];
6887 if (0 == (bi_history & (1 << i)))
6888 break; /* i-th hop not bi-directional, stop learning! */
6889 if (i == nhops - 1)
6890 {
6891 path[i + 2] = dvl->initiator;
6892 }
6893 else
6894 {
6895 path[i + 2] = hops[nhops - i - 2].hop;
6896 }
6897 6802
6898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6803 path[0] = GST_my_identity;
6899 "Learned inverse path with %u hops to %s\n", 6804 path[1] = hops[nhops - 1].hop; /* direct neighbour == predecessor! */
6900 i + 1, 6805 for (unsigned int i = 0; i < nhops; i++)
6901 GNUNET_i2s (&path[i + 2])); 6806 {
6902 iret = learn_dv_path (path, 6807 int iret;
6903 i + 2, 6808
6904 GNUNET_TIME_UNIT_FOREVER_REL, 6809 if (0 == (bi_history & (1 << i)))
6905 GNUNET_TIME_UNIT_ZERO_ABS); 6810 break; /* i-th hop not bi-directional, stop learning! */
6906 if (GNUNET_SYSERR == iret) 6811 if (i == nhops - 1)
6907 { 6812 {
6908 /* path invalid or too long to be interesting for US, thus should also 6813 path[i + 2] = dvl->initiator;
6909 not be interesting to our neighbours, cut path when forwarding to 6814 }
6910 'i' hops, except of course for the one that goes back to the 6815 else
6911 initiator */ 6816 {
6912 GNUNET_STATISTICS_update (GST_stats, 6817 path[i + 2] = hops[nhops - i - 2].hop;
6913 "# DV learn not forwarded due invalidity of path", 6818 }
6914 1, 6819
6915 GNUNET_NO); 6820 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6916 do_fwd = GNUNET_NO; 6821 "Learned inverse path with %u hops to %s\n",
6917 break; 6822 i + 1,
6918 } 6823 GNUNET_i2s(&path[i + 2]));
6919 if ((GNUNET_NO == iret) && (nhops == i + 1)) 6824 iret = learn_dv_path(path,
6920 { 6825 i + 2,
6921 /* we have better paths, and this is the longest target, 6826 GNUNET_TIME_UNIT_FOREVER_REL,
6922 so there cannot be anything interesting later */ 6827 GNUNET_TIME_UNIT_ZERO_ABS);
6923 GNUNET_STATISTICS_update (GST_stats, 6828 if (GNUNET_SYSERR == iret)
6924 "# DV learn not forwarded, got better paths", 6829 {
6925 1, 6830 /* path invalid or too long to be interesting for US, thus should also
6926 GNUNET_NO); 6831 not be interesting to our neighbours, cut path when forwarding to
6927 do_fwd = GNUNET_NO; 6832 'i' hops, except of course for the one that goes back to the
6928 break; 6833 initiator */
6929 } 6834 GNUNET_STATISTICS_update(GST_stats,
6835 "# DV learn not forwarded due invalidity of path",
6836 1,
6837 GNUNET_NO);
6838 do_fwd = GNUNET_NO;
6839 break;
6840 }
6841 if ((GNUNET_NO == iret) && (nhops == i + 1))
6842 {
6843 /* we have better paths, and this is the longest target,
6844 so there cannot be anything interesting later */
6845 GNUNET_STATISTICS_update(GST_stats,
6846 "# DV learn not forwarded, got better paths",
6847 1,
6848 GNUNET_NO);
6849 do_fwd = GNUNET_NO;
6850 break;
6851 }
6852 }
6930 } 6853 }
6931 }
6932 6854
6933 if (MAX_DV_HOPS_ALLOWED == nhops) 6855 if (MAX_DV_HOPS_ALLOWED == nhops)
6934 { 6856 {
6935 /* At limit, we're out of here! */ 6857 /* At limit, we're out of here! */
6936 finish_cmc_handling (cmc); 6858 finish_cmc_handling(cmc);
6937 return; 6859 return;
6938 } 6860 }
6939 6861
6940 /* Forward to initiator, if path non-trivial and possible */ 6862 /* Forward to initiator, if path non-trivial and possible */
6941 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0); 6863 bi_history = (bi_history << 1) | (bi_hop ? 1 : 0);
6942 did_initiator = GNUNET_NO; 6864 did_initiator = GNUNET_NO;
6943 if ((1 < nhops) && 6865 if ((1 < nhops) &&
6944 (GNUNET_YES == 6866 (GNUNET_YES ==
6945 GNUNET_CONTAINER_multipeermap_contains (neighbours, &dvl->initiator))) 6867 GNUNET_CONTAINER_multipeermap_contains(neighbours, &dvl->initiator)))
6946 { 6868 {
6947 /* send back to origin! */ 6869 /* send back to origin! */
6948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6870 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6949 "Sending DVL back to initiator %s\n", 6871 "Sending DVL back to initiator %s\n",
6950 GNUNET_i2s (&dvl->initiator)); 6872 GNUNET_i2s(&dvl->initiator));
6951 forward_dv_learn (&dvl->initiator, dvl, bi_history, nhops, hops, in_time); 6873 forward_dv_learn(&dvl->initiator, dvl, bi_history, nhops, hops, in_time);
6952 did_initiator = GNUNET_YES; 6874 did_initiator = GNUNET_YES;
6953 } 6875 }
6954 /* We forward under two conditions: either we still learned something 6876 /* We forward under two conditions: either we still learned something
6955 ourselves (do_fwd), or the path was darn short and thus the initiator is 6877 ourselves (do_fwd), or the path was darn short and thus the initiator is
6956 likely to still be very interested in this (and we did NOT already 6878 likely to still be very interested in this (and we did NOT already
6957 send it back to the initiator) */ 6879 send it back to the initiator) */
6958 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) && 6880 if ((do_fwd) || ((nhops < MIN_DV_PATH_LENGTH_FOR_INITIATOR) &&
6959 (GNUNET_NO == did_initiator))) 6881 (GNUNET_NO == did_initiator)))
6960 { 6882 {
6961 /* Pick random neighbours that are not yet on the path */ 6883 /* Pick random neighbours that are not yet on the path */
6962 struct NeighbourSelectionContext nsc; 6884 struct NeighbourSelectionContext nsc;
6963 unsigned int n_cnt; 6885 unsigned int n_cnt;
6964 6886
6965 n_cnt = GNUNET_CONTAINER_multipeermap_size (neighbours); 6887 n_cnt = GNUNET_CONTAINER_multipeermap_size(neighbours);
6966 nsc.nhops = nhops; 6888 nsc.nhops = nhops;
6967 nsc.dvl = dvl; 6889 nsc.dvl = dvl;
6968 nsc.bi_history = bi_history; 6890 nsc.bi_history = bi_history;
6969 nsc.hops = hops; 6891 nsc.hops = hops;
6970 nsc.in_time = in_time; 6892 nsc.in_time = in_time;
6971 nsc.num_eligible = 0; 6893 nsc.num_eligible = 0;
6972 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6894 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
6973 &dv_neighbour_selection, 6895 &dv_neighbour_selection,
6974 &nsc); 6896 &nsc);
6975 if (0 == nsc.num_eligible) 6897 if (0 == nsc.num_eligible)
6976 return; /* done here, cannot forward to anyone else */ 6898 return; /* done here, cannot forward to anyone else */
6977 nsc.num_selections = calculate_fork_degree (nhops, n_cnt, nsc.num_eligible); 6899 nsc.num_selections = calculate_fork_degree(nhops, n_cnt, nsc.num_eligible);
6978 nsc.num_selections = 6900 nsc.num_selections =
6979 GNUNET_MIN (MAX_DV_DISCOVERY_SELECTION, nsc.num_selections); 6901 GNUNET_MIN(MAX_DV_DISCOVERY_SELECTION, nsc.num_selections);
6980 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6902 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
6981 "Forwarding DVL to %u other peers\n", 6903 "Forwarding DVL to %u other peers\n",
6982 nsc.num_selections); 6904 nsc.num_selections);
6983 for (unsigned int i = 0; i < nsc.num_selections; i++) 6905 for (unsigned int i = 0; i < nsc.num_selections; i++)
6984 nsc.selections[i] = 6906 nsc.selections[i] =
6985 (nsc.num_selections == n_cnt) 6907 (nsc.num_selections == n_cnt)
6986 ? i /* all were selected, avoid collisions by chance */ 6908 ? i /* all were selected, avoid collisions by chance */
6987 : GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, n_cnt); 6909 : GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, n_cnt);
6988 nsc.num_eligible = 0; 6910 nsc.num_eligible = 0;
6989 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 6911 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
6990 &dv_neighbour_transmission, 6912 &dv_neighbour_transmission,
6991 &nsc); 6913 &nsc);
6992 } 6914 }
6993} 6915}
6994 6916
6995 6917
@@ -7001,27 +6923,27 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
7001 * @return #GNUNET_YES if message is well-formed 6923 * @return #GNUNET_YES if message is well-formed
7002 */ 6924 */
7003static int 6925static int
7004check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) 6926check_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7005{ 6927{
7006 uint16_t size = ntohs (dvb->header.size); 6928 uint16_t size = ntohs(dvb->header.size);
7007 uint16_t num_hops = ntohs (dvb->num_hops); 6929 uint16_t num_hops = ntohs(dvb->num_hops);
7008 const struct GNUNET_PeerIdentity *hops = 6930 const struct GNUNET_PeerIdentity *hops =
7009 (const struct GNUNET_PeerIdentity *) &dvb[1]; 6931 (const struct GNUNET_PeerIdentity *)&dvb[1];
7010 6932
7011 (void) cls; 6933 (void)cls;
7012 if (size < sizeof (*dvb) + num_hops * sizeof (struct GNUNET_PeerIdentity) + 6934 if (size < sizeof(*dvb) + num_hops * sizeof(struct GNUNET_PeerIdentity) +
7013 sizeof (struct GNUNET_MessageHeader)) 6935 sizeof(struct GNUNET_MessageHeader))
7014 {
7015 GNUNET_break_op (0);
7016 return GNUNET_SYSERR;
7017 }
7018 /* This peer must not be on the path */
7019 for (unsigned int i = 0; i < num_hops; i++)
7020 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity))
7021 { 6936 {
7022 GNUNET_break_op (0); 6937 GNUNET_break_op(0);
7023 return GNUNET_SYSERR; 6938 return GNUNET_SYSERR;
7024 } 6939 }
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 }
7025 return GNUNET_YES; 6947 return GNUNET_YES;
7026} 6948}
7027 6949
@@ -7039,13 +6961,13 @@ check_dv_box (void *cls, const struct TransportDVBoxMessage *dvb)
7039 * @param payload_size number of bytes in @a payload 6961 * @param payload_size number of bytes in @a payload
7040 */ 6962 */
7041static void 6963static void
7042forward_dv_box (struct Neighbour *next_hop, 6964forward_dv_box(struct Neighbour *next_hop,
7043 const struct TransportDVBoxMessage *hdr, 6965 const struct TransportDVBoxMessage *hdr,
7044 uint16_t total_hops, 6966 uint16_t total_hops,
7045 uint16_t num_hops, 6967 uint16_t num_hops,
7046 const struct GNUNET_PeerIdentity *hops, 6968 const struct GNUNET_PeerIdentity *hops,
7047 const void *enc_payload, 6969 const void *enc_payload,
7048 uint16_t enc_payload_size) 6970 uint16_t enc_payload_size)
7049{ 6971{
7050 struct VirtualLink *vl = next_hop->vl; 6972 struct VirtualLink *vl = next_hop->vl;
7051 struct PendingMessage *pm; 6973 struct PendingMessage *pm;
@@ -7053,33 +6975,33 @@ forward_dv_box (struct Neighbour *next_hop,
7053 char *buf; 6975 char *buf;
7054 struct GNUNET_PeerIdentity *dhops; 6976 struct GNUNET_PeerIdentity *dhops;
7055 6977
7056 GNUNET_assert (NULL != vl); 6978 GNUNET_assert(NULL != vl);
7057 msg_size = sizeof (struct TransportDVBoxMessage) + 6979 msg_size = sizeof(struct TransportDVBoxMessage) +
7058 num_hops * sizeof (struct GNUNET_PeerIdentity) + enc_payload_size; 6980 num_hops * sizeof(struct GNUNET_PeerIdentity) + enc_payload_size;
7059 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); 6981 pm = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size);
7060 pm->pmt = PMT_DV_BOX; 6982 pm->pmt = PMT_DV_BOX;
7061 pm->vl = vl; 6983 pm->vl = vl;
7062 pm->timeout = GNUNET_TIME_relative_to_absolute (DV_FORWARD_TIMEOUT); 6984 pm->timeout = GNUNET_TIME_relative_to_absolute(DV_FORWARD_TIMEOUT);
7063 pm->logging_uuid = logging_uuid_gen++; 6985 pm->logging_uuid = logging_uuid_gen++;
7064 pm->prefs = GNUNET_MQ_PRIO_BACKGROUND; 6986 pm->prefs = GNUNET_MQ_PRIO_BACKGROUND;
7065 pm->bytes_msg = msg_size; 6987 pm->bytes_msg = msg_size;
7066 buf = (char *) &pm[1]; 6988 buf = (char *)&pm[1];
7067 memcpy (buf, hdr, sizeof (*hdr)); 6989 memcpy(buf, hdr, sizeof(*hdr));
7068 dhops = 6990 dhops =
7069 (struct GNUNET_PeerIdentity *) &buf[sizeof (struct TransportDVBoxMessage)]; 6991 (struct GNUNET_PeerIdentity *)&buf[sizeof(struct TransportDVBoxMessage)];
7070 memcpy (dhops, hops, num_hops * sizeof (struct GNUNET_PeerIdentity)); 6992 memcpy(dhops, hops, num_hops * sizeof(struct GNUNET_PeerIdentity));
7071 memcpy (&dhops[num_hops], enc_payload, enc_payload_size); 6993 memcpy(&dhops[num_hops], enc_payload, enc_payload_size);
7072 GNUNET_CONTAINER_MDLL_insert (vl, 6994 GNUNET_CONTAINER_MDLL_insert(vl,
7073 vl->pending_msg_head, 6995 vl->pending_msg_head,
7074 vl->pending_msg_tail, 6996 vl->pending_msg_tail,
7075 pm); 6997 pm);
7076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6998 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7077 "Created pending message %llu for DV Box with next hop %s (%u/%u)\n", 6999 "Created pending message %llu for DV Box with next hop %s (%u/%u)\n",
7078 pm->logging_uuid, 7000 pm->logging_uuid,
7079 GNUNET_i2s (&next_hop->pid), 7001 GNUNET_i2s(&next_hop->pid),
7080 (unsigned int) num_hops, 7002 (unsigned int)num_hops,
7081 (unsigned int) total_hops); 7003 (unsigned int)total_hops);
7082 check_vl_transmission (vl); 7004 check_vl_transmission(vl);
7083} 7005}
7084 7006
7085 7007
@@ -7089,30 +7011,30 @@ forward_dv_box (struct Neighbour *next_hop,
7089 * @param b data structure to release 7011 * @param b data structure to release
7090 */ 7012 */
7091static void 7013static void
7092free_backtalker (struct Backtalker *b) 7014free_backtalker(struct Backtalker *b)
7093{ 7015{
7094 if (NULL != b->get) 7016 if (NULL != b->get)
7095 { 7017 {
7096 GNUNET_PEERSTORE_iterate_cancel (b->get); 7018 GNUNET_PEERSTORE_iterate_cancel(b->get);
7097 b->get = NULL; 7019 b->get = NULL;
7098 GNUNET_assert (NULL != b->cmc); 7020 GNUNET_assert(NULL != b->cmc);
7099 finish_cmc_handling (b->cmc); 7021 finish_cmc_handling(b->cmc);
7100 b->cmc = NULL; 7022 b->cmc = NULL;
7101 } 7023 }
7102 if (NULL != b->task) 7024 if (NULL != b->task)
7103 { 7025 {
7104 GNUNET_SCHEDULER_cancel (b->task); 7026 GNUNET_SCHEDULER_cancel(b->task);
7105 b->task = NULL; 7027 b->task = NULL;
7106 } 7028 }
7107 if (NULL != b->sc) 7029 if (NULL != b->sc)
7108 { 7030 {
7109 GNUNET_PEERSTORE_store_cancel (b->sc); 7031 GNUNET_PEERSTORE_store_cancel(b->sc);
7110 b->sc = NULL; 7032 b->sc = NULL;
7111 } 7033 }
7112 GNUNET_assert ( 7034 GNUNET_assert(
7113 GNUNET_YES == 7035 GNUNET_YES ==
7114 GNUNET_CONTAINER_multipeermap_remove (backtalkers, &b->pid, b)); 7036 GNUNET_CONTAINER_multipeermap_remove(backtalkers, &b->pid, b));
7115 GNUNET_free (b); 7037 GNUNET_free(b);
7116} 7038}
7117 7039
7118 7040
@@ -7125,15 +7047,15 @@ free_backtalker (struct Backtalker *b)
7125 * @return #GNUNET_OK (always) 7047 * @return #GNUNET_OK (always)
7126 */ 7048 */
7127static int 7049static int
7128free_backtalker_cb (void *cls, 7050free_backtalker_cb(void *cls,
7129 const struct GNUNET_PeerIdentity *pid, 7051 const struct GNUNET_PeerIdentity *pid,
7130 void *value) 7052 void *value)
7131{ 7053{
7132 struct Backtalker *b = value; 7054 struct Backtalker *b = value;
7133 7055
7134 (void) cls; 7056 (void)cls;
7135 (void) pid; 7057 (void)pid;
7136 free_backtalker (b); 7058 free_backtalker(b);
7137 return GNUNET_OK; 7059 return GNUNET_OK;
7138} 7060}
7139 7061
@@ -7144,18 +7066,18 @@ free_backtalker_cb (void *cls,
7144 * @param cls a `struct Backtalker` 7066 * @param cls a `struct Backtalker`
7145 */ 7067 */
7146static void 7068static void
7147backtalker_timeout_cb (void *cls) 7069backtalker_timeout_cb(void *cls)
7148{ 7070{
7149 struct Backtalker *b = cls; 7071 struct Backtalker *b = cls;
7150 7072
7151 b->task = NULL; 7073 b->task = NULL;
7152 if (0 != GNUNET_TIME_absolute_get_remaining (b->timeout).rel_value_us) 7074 if (0 != GNUNET_TIME_absolute_get_remaining(b->timeout).rel_value_us)
7153 { 7075 {
7154 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); 7076 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b);
7155 return; 7077 return;
7156 } 7078 }
7157 GNUNET_assert (NULL == b->sc); 7079 GNUNET_assert(NULL == b->sc);
7158 free_backtalker (b); 7080 free_backtalker(b);
7159} 7081}
7160 7082
7161 7083
@@ -7168,52 +7090,52 @@ backtalker_timeout_cb (void *cls)
7168 * @param emsg error message 7090 * @param emsg error message
7169 */ 7091 */
7170static void 7092static void
7171backtalker_monotime_cb (void *cls, 7093backtalker_monotime_cb(void *cls,
7172 const struct GNUNET_PEERSTORE_Record *record, 7094 const struct GNUNET_PEERSTORE_Record *record,
7173 const char *emsg) 7095 const char *emsg)
7174{ 7096{
7175 struct Backtalker *b = cls; 7097 struct Backtalker *b = cls;
7176 struct GNUNET_TIME_AbsoluteNBO *mtbe; 7098 struct GNUNET_TIME_AbsoluteNBO *mtbe;
7177 struct GNUNET_TIME_Absolute mt; 7099 struct GNUNET_TIME_Absolute mt;
7178 7100
7179 (void) emsg; 7101 (void)emsg;
7180 if (NULL == record) 7102 if (NULL == record)
7181 { 7103 {
7182 /* we're done with #backtalker_monotime_cb() invocations, 7104 /* we're done with #backtalker_monotime_cb() invocations,
7183 continue normal processing */ 7105 continue normal processing */
7184 b->get = NULL; 7106 b->get = NULL;
7185 GNUNET_assert (NULL != b->cmc); 7107 GNUNET_assert(NULL != b->cmc);
7186 if (0 != b->body_size) 7108 if (0 != b->body_size)
7187 demultiplex_with_cmc (b->cmc, 7109 demultiplex_with_cmc(b->cmc,
7188 (const struct GNUNET_MessageHeader *) &b[1]); 7110 (const struct GNUNET_MessageHeader *)&b[1]);
7189 else 7111 else
7190 finish_cmc_handling (b->cmc); 7112 finish_cmc_handling(b->cmc);
7191 b->cmc = NULL; 7113 b->cmc = NULL;
7192 return; 7114 return;
7193 } 7115 }
7194 if (sizeof (*mtbe) != record->value_size) 7116 if (sizeof(*mtbe) != record->value_size)
7195 { 7117 {
7196 GNUNET_break (0); 7118 GNUNET_break(0);
7197 return; 7119 return;
7198 } 7120 }
7199 mtbe = record->value; 7121 mtbe = record->value;
7200 mt = GNUNET_TIME_absolute_ntoh (*mtbe); 7122 mt = GNUNET_TIME_absolute_ntoh(*mtbe);
7201 if (mt.abs_value_us > b->monotonic_time.abs_value_us) 7123 if (mt.abs_value_us > b->monotonic_time.abs_value_us)
7202 { 7124 {
7203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7125 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7204 "Backtalker message from %s dropped, monotime in the past\n", 7126 "Backtalker message from %s dropped, monotime in the past\n",
7205 GNUNET_i2s (&b->pid)); 7127 GNUNET_i2s(&b->pid));
7206 GNUNET_STATISTICS_update ( 7128 GNUNET_STATISTICS_update(
7207 GST_stats, 7129 GST_stats,
7208 "# Backchannel messages dropped: monotonic time not increasing", 7130 "# Backchannel messages dropped: monotonic time not increasing",
7209 1, 7131 1,
7210 GNUNET_NO); 7132 GNUNET_NO);
7211 b->monotonic_time = mt; 7133 b->monotonic_time = mt;
7212 /* Setting body_size to 0 prevents call to #forward_backchannel_payload() 7134 /* Setting body_size to 0 prevents call to #forward_backchannel_payload()
7213 */ 7135 */
7214 b->body_size = 0; 7136 b->body_size = 0;
7215 return; 7137 return;
7216 } 7138 }
7217} 7139}
7218 7140
7219 7141
@@ -7225,17 +7147,17 @@ backtalker_monotime_cb (void *cls,
7225 * @param success #GNUNET_OK on success 7147 * @param success #GNUNET_OK on success
7226 */ 7148 */
7227static void 7149static void
7228backtalker_monotime_store_cb (void *cls, int success) 7150backtalker_monotime_store_cb(void *cls, int success)
7229{ 7151{
7230 struct Backtalker *b = cls; 7152 struct Backtalker *b = cls;
7231 7153
7232 if (GNUNET_OK != success) 7154 if (GNUNET_OK != success)
7233 { 7155 {
7234 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 7156 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
7235 "Failed to store backtalker's monotonic time in PEERSTORE!\n"); 7157 "Failed to store backtalker's monotonic time in PEERSTORE!\n");
7236 } 7158 }
7237 b->sc = NULL; 7159 b->sc = NULL;
7238 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); 7160 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b);
7239} 7161}
7240 7162
7241 7163
@@ -7245,32 +7167,32 @@ backtalker_monotime_store_cb (void *cls, int success)
7245 * @param b a backtalker with updated monotonic time 7167 * @param b a backtalker with updated monotonic time
7246 */ 7168 */
7247static void 7169static void
7248update_backtalker_monotime (struct Backtalker *b) 7170update_backtalker_monotime(struct Backtalker *b)
7249{ 7171{
7250 struct GNUNET_TIME_AbsoluteNBO mtbe; 7172 struct GNUNET_TIME_AbsoluteNBO mtbe;
7251 7173
7252 if (NULL != b->sc) 7174 if (NULL != b->sc)
7253 { 7175 {
7254 GNUNET_PEERSTORE_store_cancel (b->sc); 7176 GNUNET_PEERSTORE_store_cancel(b->sc);
7255 b->sc = NULL; 7177 b->sc = NULL;
7256 } 7178 }
7257 else 7179 else
7258 { 7180 {
7259 GNUNET_SCHEDULER_cancel (b->task); 7181 GNUNET_SCHEDULER_cancel(b->task);
7260 b->task = NULL; 7182 b->task = NULL;
7261 } 7183 }
7262 mtbe = GNUNET_TIME_absolute_hton (b->monotonic_time); 7184 mtbe = GNUNET_TIME_absolute_hton(b->monotonic_time);
7263 b->sc = 7185 b->sc =
7264 GNUNET_PEERSTORE_store (peerstore, 7186 GNUNET_PEERSTORE_store(peerstore,
7265 "transport", 7187 "transport",
7266 &b->pid, 7188 &b->pid,
7267 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, 7189 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME,
7268 &mtbe, 7190 &mtbe,
7269 sizeof (mtbe), 7191 sizeof(mtbe),
7270 GNUNET_TIME_UNIT_FOREVER_ABS, 7192 GNUNET_TIME_UNIT_FOREVER_ABS,
7271 GNUNET_PEERSTORE_STOREOPTION_REPLACE, 7193 GNUNET_PEERSTORE_STOREOPTION_REPLACE,
7272 &backtalker_monotime_store_cb, 7194 &backtalker_monotime_store_cb,
7273 b); 7195 b);
7274} 7196}
7275 7197
7276 7198
@@ -7282,221 +7204,223 @@ update_backtalker_monotime (struct Backtalker *b)
7282 * @param dvb the message that was received 7204 * @param dvb the message that was received
7283 */ 7205 */
7284static void 7206static void
7285handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb) 7207handle_dv_box(void *cls, const struct TransportDVBoxMessage *dvb)
7286{ 7208{
7287 struct CommunicatorMessageContext *cmc = cls; 7209 struct CommunicatorMessageContext *cmc = cls;
7288 uint16_t size = ntohs (dvb->header.size) - sizeof (*dvb); 7210 uint16_t size = ntohs(dvb->header.size) - sizeof(*dvb);
7289 uint16_t num_hops = ntohs (dvb->num_hops); 7211 uint16_t num_hops = ntohs(dvb->num_hops);
7290 const struct GNUNET_PeerIdentity *hops = 7212 const struct GNUNET_PeerIdentity *hops =
7291 (const struct GNUNET_PeerIdentity *) &dvb[1]; 7213 (const struct GNUNET_PeerIdentity *)&dvb[1];
7292 const char *enc_payload = (const char *) &hops[num_hops]; 7214 const char *enc_payload = (const char *)&hops[num_hops];
7293 uint16_t enc_payload_size = 7215 uint16_t enc_payload_size =
7294 size - (num_hops * sizeof (struct GNUNET_PeerIdentity)); 7216 size - (num_hops * sizeof(struct GNUNET_PeerIdentity));
7295 struct DVKeyState key; 7217 struct DVKeyState key;
7296 struct GNUNET_HashCode hmac; 7218 struct GNUNET_HashCode hmac;
7297 const char *hdr; 7219 const char *hdr;
7298 size_t hdr_len; 7220 size_t hdr_len;
7299 7221
7300 if (GNUNET_EXTRA_LOGGING > 0) 7222 if (GNUNET_EXTRA_LOGGING > 0)
7301 {
7302 char *path;
7303
7304 path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
7305 for (unsigned int i = 0; i < num_hops; i++)
7306 { 7223 {
7307 char *tmp; 7224 char *path;
7225
7226 path = GNUNET_strdup(GNUNET_i2s(&GST_my_identity));
7227 for (unsigned int i = 0; i < num_hops; i++)
7228 {
7229 char *tmp;
7308 7230
7309 GNUNET_asprintf (&tmp, "%s->%s", path, GNUNET_i2s (&hops[i])); 7231 GNUNET_asprintf(&tmp, "%s->%s", path, GNUNET_i2s(&hops[i]));
7310 GNUNET_free (path); 7232 GNUNET_free(path);
7311 path = tmp; 7233 path = tmp;
7234 }
7235 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7236 "Received DVBox with remainig path %s\n",
7237 path);
7238 GNUNET_free(path);
7312 } 7239 }
7313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7314 "Received DVBox with remainig path %s\n",
7315 path);
7316 GNUNET_free (path);
7317 }
7318 7240
7319 if (num_hops > 0) 7241 if (num_hops > 0)
7320 {
7321 /* We're trying from the end of the hops array, as we may be
7322 able to find a shortcut unknown to the origin that way */
7323 for (int i = num_hops - 1; i >= 0; i--)
7324 { 7242 {
7325 struct Neighbour *n; 7243 /* We're trying from the end of the hops array, as we may be
7326 7244 able to find a shortcut unknown to the origin that way */
7327 if (0 == GNUNET_memcmp (&hops[i], &GST_my_identity)) 7245 for (int i = num_hops - 1; i >= 0; i--)
7328 { 7246 {
7329 GNUNET_break_op (0); 7247 struct Neighbour *n;
7330 finish_cmc_handling (cmc); 7248
7331 return; 7249 if (0 == GNUNET_memcmp(&hops[i], &GST_my_identity))
7332 } 7250 {
7333 n = lookup_neighbour (&hops[i]); 7251 GNUNET_break_op(0);
7334 if (NULL == n) 7252 finish_cmc_handling(cmc);
7335 continue; 7253 return;
7336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7254 }
7337 "Skipping %u/%u hops ahead while routing DV Box\n", 7255 n = lookup_neighbour(&hops[i]);
7338 i, 7256 if (NULL == n)
7339 num_hops); 7257 continue;
7340 forward_dv_box (n, 7258 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7341 dvb, 7259 "Skipping %u/%u hops ahead while routing DV Box\n",
7342 ntohs (dvb->total_hops) + 1, 7260 i,
7343 num_hops - i - 1, /* number of hops left */ 7261 num_hops);
7344 &hops[i + 1], /* remaining hops */ 7262 forward_dv_box(n,
7345 enc_payload, 7263 dvb,
7346 enc_payload_size); 7264 ntohs(dvb->total_hops) + 1,
7347 GNUNET_STATISTICS_update (GST_stats, 7265 num_hops - i - 1, /* number of hops left */
7348 "# DV hops skipped routing boxes", 7266 &hops[i + 1], /* remaining hops */
7349 i, 7267 enc_payload,
7350 GNUNET_NO); 7268 enc_payload_size);
7351 GNUNET_STATISTICS_update (GST_stats, 7269 GNUNET_STATISTICS_update(GST_stats,
7352 "# DV boxes routed (total)", 7270 "# DV hops skipped routing boxes",
7353 1, 7271 i,
7354 GNUNET_NO); 7272 GNUNET_NO);
7355 finish_cmc_handling (cmc); 7273 GNUNET_STATISTICS_update(GST_stats,
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);
7356 return; 7286 return;
7357 } 7287 }
7358 /* Woopsie, next hop not in neighbours, drop! */
7359 GNUNET_STATISTICS_update (GST_stats,
7360 "# DV Boxes dropped: next hop unknown",
7361 1,
7362 GNUNET_NO);
7363 finish_cmc_handling (cmc);
7364 return;
7365 }
7366 /* We are the target. Unbox and handle message. */ 7288 /* We are the target. Unbox and handle message. */
7367 GNUNET_STATISTICS_update (GST_stats, 7289 GNUNET_STATISTICS_update(GST_stats,
7368 "# DV boxes opened (ultimate target)", 7290 "# DV boxes opened (ultimate target)",
7369 1, 7291 1,
7370 GNUNET_NO); 7292 GNUNET_NO);
7371 cmc->total_hops = ntohs (dvb->total_hops); 7293 cmc->total_hops = ntohs(dvb->total_hops);
7372 7294
7373 dh_key_derive_eph_pub (&dvb->ephemeral_key, &dvb->iv, &key); 7295 dh_key_derive_eph_pub(&dvb->ephemeral_key, &dvb->iv, &key);
7374 hdr = (const char *) &dvb[1]; 7296 hdr = (const char *)&dvb[1];
7375 hdr_len = ntohs (dvb->header.size) - sizeof (*dvb); 7297 hdr_len = ntohs(dvb->header.size) - sizeof(*dvb);
7376 dv_hmac (&key, &hmac, hdr, hdr_len); 7298 dv_hmac(&key, &hmac, hdr, hdr_len);
7377 if (0 != GNUNET_memcmp (&hmac, &dvb->hmac)) 7299 if (0 != GNUNET_memcmp(&hmac, &dvb->hmac))
7378 { 7300 {
7379 /* HMAC missmatch, disard! */ 7301 /* HMAC missmatch, disard! */
7380 GNUNET_break_op (0); 7302 GNUNET_break_op(0);
7381 finish_cmc_handling (cmc); 7303 finish_cmc_handling(cmc);
7382 return; 7304 return;
7383 } 7305 }
7384 /* begin actual decryption */ 7306 /* begin actual decryption */
7385 { 7307 {
7386 struct Backtalker *b; 7308 struct Backtalker *b;
7387 struct GNUNET_TIME_Absolute monotime; 7309 struct GNUNET_TIME_Absolute monotime;
7388 struct TransportDVBoxPayloadP ppay; 7310 struct TransportDVBoxPayloadP ppay;
7389 char body[hdr_len - sizeof (ppay)] GNUNET_ALIGN; 7311 char body[hdr_len - sizeof(ppay)] GNUNET_ALIGN;
7390 const struct GNUNET_MessageHeader *mh = 7312 const struct GNUNET_MessageHeader *mh =
7391 (const struct GNUNET_MessageHeader *) body; 7313 (const struct GNUNET_MessageHeader *)body;
7392 7314
7393 GNUNET_assert (hdr_len >= 7315 GNUNET_assert(hdr_len >=
7394 sizeof (ppay) + sizeof (struct GNUNET_MessageHeader)); 7316 sizeof(ppay) + sizeof(struct GNUNET_MessageHeader));
7395 dv_decrypt (&key, &ppay, hdr, sizeof (ppay)); 7317 dv_decrypt(&key, &ppay, hdr, sizeof(ppay));
7396 dv_decrypt (&key, &body, &hdr[sizeof (ppay)], hdr_len - sizeof (ppay)); 7318 dv_decrypt(&key, &body, &hdr[sizeof(ppay)], hdr_len - sizeof(ppay));
7397 dv_key_clean (&key); 7319 dv_key_clean(&key);
7398 if (ntohs (mh->size) != sizeof (body)) 7320 if (ntohs(mh->size) != sizeof(body))
7399 { 7321 {
7400 GNUNET_break_op (0); 7322 GNUNET_break_op(0);
7401 finish_cmc_handling (cmc); 7323 finish_cmc_handling(cmc);
7402 return; 7324 return;
7403 } 7325 }
7404 /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */ 7326 /* need to prevent box-in-a-box (and DV_LEARN) so check inbox type! */
7405 switch (ntohs (mh->type)) 7327 switch (ntohs(mh->type))
7406 { 7328 {
7407 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX: 7329 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX:
7408 GNUNET_break_op (0); 7330 GNUNET_break_op(0);
7409 finish_cmc_handling (cmc); 7331 finish_cmc_handling(cmc);
7410 return; 7332 return;
7411 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN: 7333
7412 GNUNET_break_op (0); 7334 case GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN:
7413 finish_cmc_handling (cmc); 7335 GNUNET_break_op(0);
7414 return; 7336 finish_cmc_handling(cmc);
7415 default: 7337 return;
7416 /* permitted, continue */ 7338
7417 break; 7339 default:
7418 } 7340 /* permitted, continue */
7419 monotime = GNUNET_TIME_absolute_ntoh (ppay.monotonic_time); 7341 break;
7420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7342 }
7421 "Decrypted backtalk from %s\n", 7343 monotime = GNUNET_TIME_absolute_ntoh(ppay.monotonic_time);
7422 GNUNET_i2s (&ppay.sender)); 7344 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7423 b = GNUNET_CONTAINER_multipeermap_get (backtalkers, &ppay.sender); 7345 "Decrypted backtalk from %s\n",
7346 GNUNET_i2s(&ppay.sender));
7347 b = GNUNET_CONTAINER_multipeermap_get(backtalkers, &ppay.sender);
7424 if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us)) 7348 if ((NULL != b) && (monotime.abs_value_us < b->monotonic_time.abs_value_us))
7425 {
7426 GNUNET_STATISTICS_update (
7427 GST_stats,
7428 "# Backchannel messages dropped: monotonic time not increasing",
7429 1,
7430 GNUNET_NO);
7431 finish_cmc_handling (cmc);
7432 return;
7433 }
7434 if ((NULL == b) ||
7435 (0 != GNUNET_memcmp (&b->last_ephemeral, &dvb->ephemeral_key)))
7436 {
7437 /* Check signature */
7438 struct EphemeralConfirmationPS ec;
7439
7440 ec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
7441 ec.purpose.size = htonl (sizeof (ec));
7442 ec.target = GST_my_identity;
7443 ec.ephemeral_key = dvb->ephemeral_key;
7444 if (
7445 GNUNET_OK !=
7446 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL,
7447 &ec.purpose,
7448 &ppay.sender_sig,
7449 &ppay.sender.public_key))
7450 { 7349 {
7451 /* Signature invalid, disard! */ 7350 GNUNET_STATISTICS_update(
7452 GNUNET_break_op (0); 7351 GST_stats,
7453 finish_cmc_handling (cmc); 7352 "# Backchannel messages dropped: monotonic time not increasing",
7353 1,
7354 GNUNET_NO);
7355 finish_cmc_handling(cmc);
7454 return; 7356 return;
7455 } 7357 }
7456 } 7358 if ((NULL == b) ||
7359 (0 != GNUNET_memcmp(&b->last_ephemeral, &dvb->ephemeral_key)))
7360 {
7361 /* Check signature */
7362 struct EphemeralConfirmationPS ec;
7363
7364 ec.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_EPHEMERAL);
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 }
7457 /* Update sender, we now know the real origin! */ 7381 /* Update sender, we now know the real origin! */
7458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7382 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7459 "DVBox received for me from %s via %s\n", 7383 "DVBox received for me from %s via %s\n",
7460 GNUNET_i2s2 (&ppay.sender), 7384 GNUNET_i2s2(&ppay.sender),
7461 GNUNET_i2s (&cmc->im.sender)); 7385 GNUNET_i2s(&cmc->im.sender));
7462 cmc->im.sender = ppay.sender; 7386 cmc->im.sender = ppay.sender;
7463 7387
7464 if (NULL != b) 7388 if (NULL != b)
7465 { 7389 {
7466 /* update key cache and mono time */ 7390 /* update key cache and mono time */
7467 b->last_ephemeral = dvb->ephemeral_key; 7391 b->last_ephemeral = dvb->ephemeral_key;
7468 b->monotonic_time = monotime; 7392 b->monotonic_time = monotime;
7469 update_backtalker_monotime (b); 7393 update_backtalker_monotime(b);
7470 b->timeout = 7394 b->timeout =
7471 GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); 7395 GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT);
7472 7396
7473 demultiplex_with_cmc (cmc, mh); 7397 demultiplex_with_cmc(cmc, mh);
7474 return; 7398 return;
7475 } 7399 }
7476 /* setup data structure to cache signature AND check 7400 /* setup data structure to cache signature AND check
7477 monotonic time with PEERSTORE before forwarding backchannel payload */ 7401 monotonic time with PEERSTORE before forwarding backchannel payload */
7478 b = GNUNET_malloc (sizeof (struct Backtalker) + sizeof (body)); 7402 b = GNUNET_malloc(sizeof(struct Backtalker) + sizeof(body));
7479 b->pid = ppay.sender; 7403 b->pid = ppay.sender;
7480 b->body_size = sizeof (body); 7404 b->body_size = sizeof(body);
7481 memcpy (&b[1], body, sizeof (body)); 7405 memcpy(&b[1], body, sizeof(body));
7482 GNUNET_assert (GNUNET_YES == 7406 GNUNET_assert(GNUNET_YES ==
7483 GNUNET_CONTAINER_multipeermap_put ( 7407 GNUNET_CONTAINER_multipeermap_put(
7484 backtalkers, 7408 backtalkers,
7485 &b->pid, 7409 &b->pid,
7486 b, 7410 b,
7487 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7411 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7488 b->monotonic_time = monotime; /* NOTE: to be checked still! */ 7412 b->monotonic_time = monotime; /* NOTE: to be checked still! */
7489 b->cmc = cmc; 7413 b->cmc = cmc;
7490 b->timeout = 7414 b->timeout =
7491 GNUNET_TIME_relative_to_absolute (BACKCHANNEL_INACTIVITY_TIMEOUT); 7415 GNUNET_TIME_relative_to_absolute(BACKCHANNEL_INACTIVITY_TIMEOUT);
7492 b->task = GNUNET_SCHEDULER_add_at (b->timeout, &backtalker_timeout_cb, b); 7416 b->task = GNUNET_SCHEDULER_add_at(b->timeout, &backtalker_timeout_cb, b);
7493 b->get = 7417 b->get =
7494 GNUNET_PEERSTORE_iterate (peerstore, 7418 GNUNET_PEERSTORE_iterate(peerstore,
7495 "transport", 7419 "transport",
7496 &b->pid, 7420 &b->pid,
7497 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME, 7421 GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME,
7498 &backtalker_monotime_cb, 7422 &backtalker_monotime_cb,
7499 b); 7423 b);
7500 } /* end actual decryption */ 7424 } /* end actual decryption */
7501} 7425}
7502 7426
@@ -7509,17 +7433,17 @@ handle_dv_box (void *cls, const struct TransportDVBoxMessage *dvb)
7509 * @return #GNUNET_YES if message is well-formed 7433 * @return #GNUNET_YES if message is well-formed
7510 */ 7434 */
7511static int 7435static int
7512check_incoming_msg (void *cls, 7436check_incoming_msg(void *cls,
7513 const struct GNUNET_TRANSPORT_IncomingMessage *im) 7437 const struct GNUNET_TRANSPORT_IncomingMessage *im)
7514{ 7438{
7515 struct TransportClient *tc = cls; 7439 struct TransportClient *tc = cls;
7516 7440
7517 if (CT_COMMUNICATOR != tc->type) 7441 if (CT_COMMUNICATOR != tc->type)
7518 { 7442 {
7519 GNUNET_break (0); 7443 GNUNET_break(0);
7520 return GNUNET_SYSERR; 7444 return GNUNET_SYSERR;
7521 } 7445 }
7522 GNUNET_MQ_check_boxed_message (im); 7446 GNUNET_MQ_check_boxed_message(im);
7523 return GNUNET_OK; 7447 return GNUNET_OK;
7524} 7448}
7525 7449
@@ -7527,8 +7451,7 @@ check_incoming_msg (void *cls,
7527/** 7451/**
7528 * Closure for #check_known_address. 7452 * Closure for #check_known_address.
7529 */ 7453 */
7530struct CheckKnownAddressContext 7454struct CheckKnownAddressContext {
7531{
7532 /** 7455 /**
7533 * Set to the address we are looking for. 7456 * Set to the address we are looking for.
7534 */ 7457 */
@@ -7551,15 +7474,15 @@ struct CheckKnownAddressContext
7551 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found 7474 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found
7552 */ 7475 */
7553static int 7476static int
7554check_known_address (void *cls, 7477check_known_address(void *cls,
7555 const struct GNUNET_PeerIdentity *pid, 7478 const struct GNUNET_PeerIdentity *pid,
7556 void *value) 7479 void *value)
7557{ 7480{
7558 struct CheckKnownAddressContext *ckac = cls; 7481 struct CheckKnownAddressContext *ckac = cls;
7559 struct ValidationState *vs = value; 7482 struct ValidationState *vs = value;
7560 7483
7561 (void) pid; 7484 (void)pid;
7562 if (0 != strcmp (vs->address, ckac->address)) 7485 if (0 != strcmp(vs->address, ckac->address))
7563 return GNUNET_OK; 7486 return GNUNET_OK;
7564 ckac->vs = vs; 7487 ckac->vs = vs;
7565 return GNUNET_NO; 7488 return GNUNET_NO;
@@ -7572,7 +7495,7 @@ check_known_address (void *cls,
7572 * @param cls NULL 7495 * @param cls NULL
7573 */ 7496 */
7574static void 7497static void
7575validation_start_cb (void *cls); 7498validation_start_cb(void *cls);
7576 7499
7577 7500
7578/** 7501/**
@@ -7583,8 +7506,8 @@ validation_start_cb (void *cls);
7583 * @param new_time new time for revalidation 7506 * @param new_time new time for revalidation
7584 */ 7507 */
7585static void 7508static void
7586update_next_challenge_time (struct ValidationState *vs, 7509update_next_challenge_time(struct ValidationState *vs,
7587 struct GNUNET_TIME_Absolute new_time) 7510 struct GNUNET_TIME_Absolute new_time)
7588{ 7511{
7589 struct GNUNET_TIME_Relative delta; 7512 struct GNUNET_TIME_Relative delta;
7590 7513
@@ -7593,21 +7516,21 @@ update_next_challenge_time (struct ValidationState *vs,
7593 vs->next_challenge = new_time; 7516 vs->next_challenge = new_time;
7594 if (NULL == vs->hn) 7517 if (NULL == vs->hn)
7595 vs->hn = 7518 vs->hn =
7596 GNUNET_CONTAINER_heap_insert (validation_heap, vs, new_time.abs_value_us); 7519 GNUNET_CONTAINER_heap_insert(validation_heap, vs, new_time.abs_value_us);
7597 else 7520 else
7598 GNUNET_CONTAINER_heap_update_cost (vs->hn, new_time.abs_value_us); 7521 GNUNET_CONTAINER_heap_update_cost(vs->hn, new_time.abs_value_us);
7599 if ((vs != GNUNET_CONTAINER_heap_peek (validation_heap)) && 7522 if ((vs != GNUNET_CONTAINER_heap_peek(validation_heap)) &&
7600 (NULL != validation_task)) 7523 (NULL != validation_task))
7601 return; 7524 return;
7602 if (NULL != validation_task) 7525 if (NULL != validation_task)
7603 GNUNET_SCHEDULER_cancel (validation_task); 7526 GNUNET_SCHEDULER_cancel(validation_task);
7604 /* randomize a bit */ 7527 /* randomize a bit */
7605 delta.rel_value_us = 7528 delta.rel_value_us =
7606 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 7529 GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK,
7607 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us); 7530 MIN_DELAY_ADDRESS_VALIDATION.rel_value_us);
7608 new_time = GNUNET_TIME_absolute_add (new_time, delta); 7531 new_time = GNUNET_TIME_absolute_add(new_time, delta);
7609 validation_task = 7532 validation_task =
7610 GNUNET_SCHEDULER_add_at (new_time, &validation_start_cb, NULL); 7533 GNUNET_SCHEDULER_add_at(new_time, &validation_start_cb, NULL);
7611} 7534}
7612 7535
7613 7536
@@ -7618,57 +7541,57 @@ update_next_challenge_time (struct ValidationState *vs,
7618 * @param address an address to reach @a pid (presumably) 7541 * @param address an address to reach @a pid (presumably)
7619 */ 7542 */
7620static void 7543static void
7621start_address_validation (const struct GNUNET_PeerIdentity *pid, 7544start_address_validation(const struct GNUNET_PeerIdentity *pid,
7622 const char *address) 7545 const char *address)
7623{ 7546{
7624 struct GNUNET_TIME_Absolute now; 7547 struct GNUNET_TIME_Absolute now;
7625 struct ValidationState *vs; 7548 struct ValidationState *vs;
7626 struct CheckKnownAddressContext ckac = {.address = address, .vs = NULL}; 7549 struct CheckKnownAddressContext ckac = { .address = address, .vs = NULL };
7627 7550
7628 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 7551 (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
7629 pid, 7552 pid,
7630 &check_known_address, 7553 &check_known_address,
7631 &ckac); 7554 &ckac);
7632 if (NULL != (vs = ckac.vs)) 7555 if (NULL != (vs = ckac.vs))
7633 { 7556 {
7634 /* if 'vs' is not currently valid, we need to speed up retrying the 7557 /* if 'vs' is not currently valid, we need to speed up retrying the
7635 * validation */ 7558 * validation */
7636 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us) 7559 if (vs->validated_until.abs_value_us < vs->next_challenge.abs_value_us)
7637 { 7560 {
7638 /* reduce backoff as we got a fresh advertisement */ 7561 /* reduce backoff as we got a fresh advertisement */
7639 vs->challenge_backoff = 7562 vs->challenge_backoff =
7640 GNUNET_TIME_relative_min (FAST_VALIDATION_CHALLENGE_FREQ, 7563 GNUNET_TIME_relative_min(FAST_VALIDATION_CHALLENGE_FREQ,
7641 GNUNET_TIME_relative_divide (vs->challenge_backoff, 7564 GNUNET_TIME_relative_divide(vs->challenge_backoff,
7642 2)); 7565 2));
7643 update_next_challenge_time (vs, 7566 update_next_challenge_time(vs,
7644 GNUNET_TIME_relative_to_absolute ( 7567 GNUNET_TIME_relative_to_absolute(
7645 vs->challenge_backoff)); 7568 vs->challenge_backoff));
7569 }
7570 return;
7646 } 7571 }
7647 return; 7572 now = GNUNET_TIME_absolute_get();
7648 } 7573 vs = GNUNET_new(struct ValidationState);
7649 now = GNUNET_TIME_absolute_get ();
7650 vs = GNUNET_new (struct ValidationState);
7651 vs->pid = *pid; 7574 vs->pid = *pid;
7652 vs->valid_until = 7575 vs->valid_until =
7653 GNUNET_TIME_relative_to_absolute (ADDRESS_VALIDATION_LIFETIME); 7576 GNUNET_TIME_relative_to_absolute(ADDRESS_VALIDATION_LIFETIME);
7654 vs->first_challenge_use = now; 7577 vs->first_challenge_use = now;
7655 vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 7578 vs->validation_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
7656 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 7579 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
7657 &vs->challenge, 7580 &vs->challenge,
7658 sizeof (vs->challenge)); 7581 sizeof(vs->challenge));
7659 vs->address = GNUNET_strdup (address); 7582 vs->address = GNUNET_strdup(address);
7660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7583 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7661 "Starting address validation `%s' of peer %s using challenge %s\n", 7584 "Starting address validation `%s' of peer %s using challenge %s\n",
7662 address, 7585 address,
7663 GNUNET_i2s (pid), 7586 GNUNET_i2s(pid),
7664 GNUNET_sh2s (&vs->challenge.value)); 7587 GNUNET_sh2s(&vs->challenge.value));
7665 GNUNET_assert (GNUNET_YES == 7588 GNUNET_assert(GNUNET_YES ==
7666 GNUNET_CONTAINER_multipeermap_put ( 7589 GNUNET_CONTAINER_multipeermap_put(
7667 validation_map, 7590 validation_map,
7668 &vs->pid, 7591 &vs->pid,
7669 vs, 7592 vs,
7670 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7593 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
7671 update_next_challenge_time (vs, now); 7594 update_next_challenge_time(vs, now);
7672} 7595}
7673 7596
7674 7597
@@ -7680,27 +7603,27 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid,
7680 * @param emsg error message, or NULL if no errors 7603 * @param emsg error message, or NULL if no errors
7681 */ 7604 */
7682static void 7605static void
7683handle_hello_for_incoming (void *cls, 7606handle_hello_for_incoming(void *cls,
7684 const struct GNUNET_PEERSTORE_Record *record, 7607 const struct GNUNET_PEERSTORE_Record *record,
7685 const char *emsg) 7608 const char *emsg)
7686{ 7609{
7687 struct IncomingRequest *ir = cls; 7610 struct IncomingRequest *ir = cls;
7688 const char *val; 7611 const char *val;
7689 7612
7690 if (NULL != emsg) 7613 if (NULL != emsg)
7691 { 7614 {
7692 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 7615 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
7693 "Got failure from PEERSTORE: %s\n", 7616 "Got failure from PEERSTORE: %s\n",
7694 emsg); 7617 emsg);
7695 return; 7618 return;
7696 } 7619 }
7697 val = record->value; 7620 val = record->value;
7698 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) 7621 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
7699 { 7622 {
7700 GNUNET_break (0); 7623 GNUNET_break(0);
7701 return; 7624 return;
7702 } 7625 }
7703 start_address_validation (&ir->pid, (const char *) record->value); 7626 start_address_validation(&ir->pid, (const char *)record->value);
7704} 7627}
7705 7628
7706 7629
@@ -7713,7 +7636,7 @@ handle_hello_for_incoming (void *cls,
7713 * @param tvc the message that was received 7636 * @param tvc the message that was received
7714 */ 7637 */
7715static void 7638static void
7716handle_validation_challenge ( 7639handle_validation_challenge(
7717 void *cls, 7640 void *cls,
7718 const struct TransportValidationChallengeMessage *tvc) 7641 const struct TransportValidationChallengeMessage *tvc)
7719{ 7642{
@@ -7727,44 +7650,44 @@ handle_validation_challenge (
7727 7650
7728 /* DV-routed messages are not allowed for validation challenges */ 7651 /* DV-routed messages are not allowed for validation challenges */
7729 if (cmc->total_hops > 0) 7652 if (cmc->total_hops > 0)
7730 { 7653 {
7731 GNUNET_break_op (0); 7654 GNUNET_break_op(0);
7732 finish_cmc_handling (cmc); 7655 finish_cmc_handling(cmc);
7733 return; 7656 return;
7734 } 7657 }
7735 validity_duration = cmc->im.expected_address_validity; 7658 validity_duration = cmc->im.expected_address_validity;
7736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7659 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7737 "Received address validation challenge %s\n", 7660 "Received address validation challenge %s\n",
7738 GNUNET_sh2s (&tvc->challenge.value)); 7661 GNUNET_sh2s(&tvc->challenge.value));
7739 /* If we have a virtual link, we use this mechanism to signal the 7662 /* If we have a virtual link, we use this mechanism to signal the
7740 size of the flow control window, and to allow the sender 7663 size of the flow control window, and to allow the sender
7741 to ask for increases. If for us the virtual link is still down, 7664 to ask for increases. If for us the virtual link is still down,
7742 we will always give a window size of zero. */ 7665 we will always give a window size of zero. */
7743 tvr.header.type = 7666 tvr.header.type =
7744 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE); 7667 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE);
7745 tvr.header.size = htons (sizeof (tvr)); 7668 tvr.header.size = htons(sizeof(tvr));
7746 tvr.reserved = htonl (0); 7669 tvr.reserved = htonl(0);
7747 tvr.challenge = tvc->challenge; 7670 tvr.challenge = tvc->challenge;
7748 tvr.origin_time = tvc->sender_time; 7671 tvr.origin_time = tvc->sender_time;
7749 tvr.validity_duration = validity_duration; 7672 tvr.validity_duration = validity_duration;
7750 { 7673 {
7751 /* create signature */ 7674 /* create signature */
7752 struct TransportValidationPS tvp = 7675 struct TransportValidationPS tvp =
7753 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 7676 { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
7754 .purpose.size = htonl (sizeof (tvp)), 7677 .purpose.size = htonl(sizeof(tvp)),
7755 .validity_duration = validity_duration, 7678 .validity_duration = validity_duration,
7756 .challenge = tvc->challenge}; 7679 .challenge = tvc->challenge };
7757 7680
7758 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 7681 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
7759 &tvp.purpose, 7682 &tvp.purpose,
7760 &tvr.signature)); 7683 &tvr.signature));
7761 } 7684 }
7762 route_control_message_without_fc (&cmc->im.sender, 7685 route_control_message_without_fc(&cmc->im.sender,
7763 &tvr.header, 7686 &tvr.header,
7764 RMO_ANYTHING_GOES | RMO_REDUNDANT); 7687 RMO_ANYTHING_GOES | RMO_REDUNDANT);
7765 sender = cmc->im.sender; 7688 sender = cmc->im.sender;
7766 finish_cmc_handling (cmc); 7689 finish_cmc_handling(cmc);
7767 vl = lookup_virtual_link (&sender); 7690 vl = lookup_virtual_link(&sender);
7768 if (NULL != vl) 7691 if (NULL != vl)
7769 return; 7692 return;
7770 7693
@@ -7773,36 +7696,36 @@ handle_validation_challenge (
7773 CORE), so we must try to bring the link up! */ 7696 CORE), so we must try to bring the link up! */
7774 7697
7775 /* (1) Check existing queues, if any, we may be lucky! */ 7698 /* (1) Check existing queues, if any, we may be lucky! */
7776 n = lookup_neighbour (&sender); 7699 n = lookup_neighbour(&sender);
7777 if (NULL != n) 7700 if (NULL != n)
7778 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 7701 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
7779 start_address_validation (&sender, q->address); 7702 start_address_validation(&sender, q->address);
7780 /* (2) Also try to see if we have addresses in PEERSTORE for this peer 7703 /* (2) Also try to see if we have addresses in PEERSTORE for this peer
7781 we could use */ 7704 we could use */
7782 for (ir = ir_head; NULL != ir; ir = ir->next) 7705 for (ir = ir_head; NULL != ir; ir = ir->next)
7783 if (0 == GNUNET_memcmp (&ir->pid, &sender)) 7706 if (0 == GNUNET_memcmp(&ir->pid, &sender))
7784 return; /* we are already trying */ 7707 return;
7785 ir = GNUNET_new (struct IncomingRequest); 7708 /* we are already trying */
7709 ir = GNUNET_new(struct IncomingRequest);
7786 ir->pid = sender; 7710 ir->pid = sender;
7787 GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); 7711 GNUNET_CONTAINER_DLL_insert(ir_head, ir_tail, ir);
7788 ir->wc = GNUNET_PEERSTORE_watch (peerstore, 7712 ir->wc = GNUNET_PEERSTORE_watch(peerstore,
7789 "transport", 7713 "transport",
7790 &ir->pid, 7714 &ir->pid,
7791 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 7715 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
7792 &handle_hello_for_incoming, 7716 &handle_hello_for_incoming,
7793 ir); 7717 ir);
7794 ir_total++; 7718 ir_total++;
7795 /* Bound attempts we do in parallel here, might otherwise get excessive */ 7719 /* Bound attempts we do in parallel here, might otherwise get excessive */
7796 while (ir_total > MAX_INCOMING_REQUEST) 7720 while (ir_total > MAX_INCOMING_REQUEST)
7797 free_incoming_request (ir_head); 7721 free_incoming_request(ir_head);
7798} 7722}
7799 7723
7800 7724
7801/** 7725/**
7802 * Closure for #check_known_challenge. 7726 * Closure for #check_known_challenge.
7803 */ 7727 */
7804struct CheckKnownChallengeContext 7728struct CheckKnownChallengeContext {
7805{
7806 /** 7729 /**
7807 * Set to the challenge we are looking for. 7730 * Set to the challenge we are looking for.
7808 */ 7731 */
@@ -7825,15 +7748,15 @@ struct CheckKnownChallengeContext
7825 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found 7748 * @return #GNUNET_OK if not matching, #GNUNET_NO if match found
7826 */ 7749 */
7827static int 7750static int
7828check_known_challenge (void *cls, 7751check_known_challenge(void *cls,
7829 const struct GNUNET_PeerIdentity *pid, 7752 const struct GNUNET_PeerIdentity *pid,
7830 void *value) 7753 void *value)
7831{ 7754{
7832 struct CheckKnownChallengeContext *ckac = cls; 7755 struct CheckKnownChallengeContext *ckac = cls;
7833 struct ValidationState *vs = value; 7756 struct ValidationState *vs = value;
7834 7757
7835 (void) pid; 7758 (void)pid;
7836 if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge)) 7759 if (0 != GNUNET_memcmp(&vs->challenge, ckac->challenge))
7837 return GNUNET_OK; 7760 return GNUNET_OK;
7838 ckac->vs = vs; 7761 ckac->vs = vs;
7839 return GNUNET_NO; 7762 return GNUNET_NO;
@@ -7848,17 +7771,17 @@ check_known_challenge (void *cls,
7848 * @param success #GNUNET_YES on success 7771 * @param success #GNUNET_YES on success
7849 */ 7772 */
7850static void 7773static void
7851peerstore_store_validation_cb (void *cls, int success) 7774peerstore_store_validation_cb(void *cls, int success)
7852{ 7775{
7853 struct ValidationState *vs = cls; 7776 struct ValidationState *vs = cls;
7854 7777
7855 vs->sc = NULL; 7778 vs->sc = NULL;
7856 if (GNUNET_YES == success) 7779 if (GNUNET_YES == success)
7857 return; 7780 return;
7858 GNUNET_STATISTICS_update (GST_stats, 7781 GNUNET_STATISTICS_update(GST_stats,
7859 "# Peerstore failed to store foreign address", 7782 "# Peerstore failed to store foreign address",
7860 1, 7783 1,
7861 GNUNET_NO); 7784 GNUNET_NO);
7862} 7785}
7863 7786
7864 7787
@@ -7870,19 +7793,19 @@ peerstore_store_validation_cb (void *cls, int success)
7870 * @return NULL if no such queue exists 7793 * @return NULL if no such queue exists
7871 */ 7794 */
7872static struct Queue * 7795static struct Queue *
7873find_queue (const struct GNUNET_PeerIdentity *pid, const char *address) 7796find_queue(const struct GNUNET_PeerIdentity *pid, const char *address)
7874{ 7797{
7875 struct Neighbour *n; 7798 struct Neighbour *n;
7876 7799
7877 n = lookup_neighbour (pid); 7800 n = lookup_neighbour(pid);
7878 if (NULL == n) 7801 if (NULL == n)
7879 return NULL; 7802 return NULL;
7880 for (struct Queue *pos = n->queue_head; NULL != pos; 7803 for (struct Queue *pos = n->queue_head; NULL != pos;
7881 pos = pos->next_neighbour) 7804 pos = pos->next_neighbour)
7882 { 7805 {
7883 if (0 == strcmp (pos->address, address)) 7806 if (0 == strcmp(pos->address, address))
7884 return pos; 7807 return pos;
7885 } 7808 }
7886 return NULL; 7809 return NULL;
7887} 7810}
7888 7811
@@ -7896,161 +7819,161 @@ find_queue (const struct GNUNET_PeerIdentity *pid, const char *address)
7896 * @param tvr the message that was received 7819 * @param tvr the message that was received
7897 */ 7820 */
7898static void 7821static void
7899handle_validation_response ( 7822handle_validation_response(
7900 void *cls, 7823 void *cls,
7901 const struct TransportValidationResponseMessage *tvr) 7824 const struct TransportValidationResponseMessage *tvr)
7902{ 7825{
7903 struct CommunicatorMessageContext *cmc = cls; 7826 struct CommunicatorMessageContext *cmc = cls;
7904 struct ValidationState *vs; 7827 struct ValidationState *vs;
7905 struct CheckKnownChallengeContext ckac = {.challenge = &tvr->challenge, 7828 struct CheckKnownChallengeContext ckac = { .challenge = &tvr->challenge,
7906 .vs = NULL}; 7829 .vs = NULL };
7907 struct GNUNET_TIME_Absolute origin_time; 7830 struct GNUNET_TIME_Absolute origin_time;
7908 struct Queue *q; 7831 struct Queue *q;
7909 struct Neighbour *n; 7832 struct Neighbour *n;
7910 struct VirtualLink *vl; 7833 struct VirtualLink *vl;
7911 7834
7912 /* check this is one of our challenges */ 7835 /* check this is one of our challenges */
7913 (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 7836 (void)GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
7914 &cmc->im.sender, 7837 &cmc->im.sender,
7915 &check_known_challenge, 7838 &check_known_challenge,
7916 &ckac); 7839 &ckac);
7917 if (NULL == (vs = ckac.vs)) 7840 if (NULL == (vs = ckac.vs))
7918 { 7841 {
7919 /* This can happen simply if we 'forgot' the challenge by now, 7842 /* This can happen simply if we 'forgot' the challenge by now,
7920 i.e. because we received the validation response twice */ 7843 i.e. because we received the validation response twice */
7921 GNUNET_STATISTICS_update (GST_stats, 7844 GNUNET_STATISTICS_update(GST_stats,
7922 "# Validations dropped, challenge unknown", 7845 "# Validations dropped, challenge unknown",
7923 1, 7846 1,
7924 GNUNET_NO); 7847 GNUNET_NO);
7925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7848 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7926 "Validation response %s dropped, challenge unknown\n", 7849 "Validation response %s dropped, challenge unknown\n",
7927 GNUNET_sh2s (&tvr->challenge.value)); 7850 GNUNET_sh2s(&tvr->challenge.value));
7928 finish_cmc_handling (cmc); 7851 finish_cmc_handling(cmc);
7929 return; 7852 return;
7930 } 7853 }
7931 7854
7932 /* sanity check on origin time */ 7855 /* sanity check on origin time */
7933 origin_time = GNUNET_TIME_absolute_ntoh (tvr->origin_time); 7856 origin_time = GNUNET_TIME_absolute_ntoh(tvr->origin_time);
7934 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) || 7857 if ((origin_time.abs_value_us < vs->first_challenge_use.abs_value_us) ||
7935 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us)) 7858 (origin_time.abs_value_us > vs->last_challenge_use.abs_value_us))
7936 { 7859 {
7937 GNUNET_break_op (0); 7860 GNUNET_break_op(0);
7938 finish_cmc_handling (cmc); 7861 finish_cmc_handling(cmc);
7939 return; 7862 return;
7940 } 7863 }
7941 7864
7942 { 7865 {
7943 /* check signature */ 7866 /* check signature */
7944 struct TransportValidationPS tvp = 7867 struct TransportValidationPS tvp =
7945 {.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE), 7868 { .purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE),
7946 .purpose.size = htonl (sizeof (tvp)), 7869 .purpose.size = htonl(sizeof(tvp)),
7947 .validity_duration = tvr->validity_duration, 7870 .validity_duration = tvr->validity_duration,
7948 .challenge = tvr->challenge}; 7871 .challenge = tvr->challenge };
7949 7872
7950 if ( 7873 if (
7951 GNUNET_OK != 7874 GNUNET_OK !=
7952 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE, 7875 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_CHALLENGE,
7953 &tvp.purpose, 7876 &tvp.purpose,
7954 &tvr->signature, 7877 &tvr->signature,
7955 &cmc->im.sender.public_key)) 7878 &cmc->im.sender.public_key))
7956 { 7879 {
7957 GNUNET_break_op (0); 7880 GNUNET_break_op(0);
7958 finish_cmc_handling (cmc); 7881 finish_cmc_handling(cmc);
7959 return; 7882 return;
7960 } 7883 }
7961 } 7884 }
7962 7885
7963 /* validity is capped by our willingness to keep track of the 7886 /* validity is capped by our willingness to keep track of the
7964 validation entry and the maximum the other peer allows */ 7887 validation entry and the maximum the other peer allows */
7965 vs->valid_until = GNUNET_TIME_relative_to_absolute ( 7888 vs->valid_until = GNUNET_TIME_relative_to_absolute(
7966 GNUNET_TIME_relative_min (GNUNET_TIME_relative_ntoh ( 7889 GNUNET_TIME_relative_min(GNUNET_TIME_relative_ntoh(
7967 tvr->validity_duration), 7890 tvr->validity_duration),
7968 MAX_ADDRESS_VALID_UNTIL)); 7891 MAX_ADDRESS_VALID_UNTIL));
7969 vs->validated_until = 7892 vs->validated_until =
7970 GNUNET_TIME_absolute_min (vs->valid_until, 7893 GNUNET_TIME_absolute_min(vs->valid_until,
7971 GNUNET_TIME_relative_to_absolute ( 7894 GNUNET_TIME_relative_to_absolute(
7972 ADDRESS_VALIDATION_LIFETIME)); 7895 ADDRESS_VALIDATION_LIFETIME));
7973 vs->validation_rtt = GNUNET_TIME_absolute_get_duration (origin_time); 7896 vs->validation_rtt = GNUNET_TIME_absolute_get_duration(origin_time);
7974 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO; 7897 vs->challenge_backoff = GNUNET_TIME_UNIT_ZERO;
7975 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 7898 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
7976 &vs->challenge, 7899 &vs->challenge,
7977 sizeof (vs->challenge)); 7900 sizeof(vs->challenge));
7978 vs->first_challenge_use = GNUNET_TIME_absolute_subtract ( 7901 vs->first_challenge_use = GNUNET_TIME_absolute_subtract(
7979 vs->validated_until, 7902 vs->validated_until,
7980 GNUNET_TIME_relative_multiply (vs->validation_rtt, 7903 GNUNET_TIME_relative_multiply(vs->validation_rtt,
7981 VALIDATION_RTT_BUFFER_FACTOR)); 7904 VALIDATION_RTT_BUFFER_FACTOR));
7982 vs->last_challenge_use = 7905 vs->last_challenge_use =
7983 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */ 7906 GNUNET_TIME_UNIT_ZERO_ABS; /* challenge was not yet used */
7984 update_next_challenge_time (vs, vs->first_challenge_use); 7907 update_next_challenge_time(vs, vs->first_challenge_use);
7985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
7986 "Validation response %s accepted, address valid until %s\n", 7909 "Validation response %s accepted, address valid until %s\n",
7987 GNUNET_sh2s (&tvr->challenge.value), 7910 GNUNET_sh2s(&tvr->challenge.value),
7988 GNUNET_STRINGS_absolute_time_to_string (vs->valid_until)); 7911 GNUNET_STRINGS_absolute_time_to_string(vs->valid_until));
7989 vs->sc = GNUNET_PEERSTORE_store (peerstore, 7912 vs->sc = GNUNET_PEERSTORE_store(peerstore,
7990 "transport", 7913 "transport",
7991 &cmc->im.sender, 7914 &cmc->im.sender,
7992 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 7915 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
7993 vs->address, 7916 vs->address,
7994 strlen (vs->address) + 1, 7917 strlen(vs->address) + 1,
7995 vs->valid_until, 7918 vs->valid_until,
7996 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE, 7919 GNUNET_PEERSTORE_STOREOPTION_MULTIPLE,
7997 &peerstore_store_validation_cb, 7920 &peerstore_store_validation_cb,
7998 vs); 7921 vs);
7999 finish_cmc_handling (cmc); 7922 finish_cmc_handling(cmc);
8000 7923
8001 /* Finally, we now possibly have a confirmed (!) working queue, 7924 /* Finally, we now possibly have a confirmed (!) working queue,
8002 update queue status (if queue still is around) */ 7925 update queue status (if queue still is around) */
8003 q = find_queue (&vs->pid, vs->address); 7926 q = find_queue(&vs->pid, vs->address);
8004 if (NULL == q) 7927 if (NULL == q)
8005 { 7928 {
8006 GNUNET_STATISTICS_update (GST_stats, 7929 GNUNET_STATISTICS_update(GST_stats,
8007 "# Queues lost at time of successful validation", 7930 "# Queues lost at time of successful validation",
8008 1, 7931 1,
8009 GNUNET_NO); 7932 GNUNET_NO);
8010 return; 7933 return;
8011 } 7934 }
8012 q->validated_until = vs->validated_until; 7935 q->validated_until = vs->validated_until;
8013 q->pd.aged_rtt = vs->validation_rtt; 7936 q->pd.aged_rtt = vs->validation_rtt;
8014 n = q->neighbour; 7937 n = q->neighbour;
8015 vl = lookup_virtual_link (&vs->pid); 7938 vl = lookup_virtual_link(&vs->pid);
8016 if (NULL != vl) 7939 if (NULL != vl)
8017 {
8018 /* Link was already up, remember n is also now available and we are done */
8019 if (NULL == vl->n)
8020 {
8021 vl->n = n;
8022 n->vl = vl;
8023 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
8024 "Virtual link to %s could now also direct neighbour!\n",
8025 GNUNET_i2s (&vs->pid));
8026 }
8027 else
8028 { 7940 {
8029 GNUNET_assert (n == vl->n); 7941 /* Link was already up, remember n is also now available and we are done */
7942 if (NULL == vl->n)
7943 {
7944 vl->n = n;
7945 n->vl = vl;
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;
8030 } 7955 }
8031 return; 7956 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8032 } 7957 "Creating new virtual link to %s using direct neighbour!\n",
8033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7958 GNUNET_i2s(&vs->pid));
8034 "Creating new virtual link to %s using direct neighbour!\n", 7959 vl = GNUNET_new(struct VirtualLink);
8035 GNUNET_i2s (&vs->pid));
8036 vl = GNUNET_new (struct VirtualLink);
8037 vl->target = n->pid; 7960 vl->target = n->pid;
8038 vl->n = n; 7961 vl->n = n;
8039 n->vl = vl; 7962 n->vl = vl;
8040 vl->core_recv_window = RECV_WINDOW_SIZE; 7963 vl->core_recv_window = RECV_WINDOW_SIZE;
8041 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE; 7964 vl->available_fc_window_size = DEFAULT_WINDOW_SIZE;
8042 vl->visibility_task = 7965 vl->visibility_task =
8043 GNUNET_SCHEDULER_add_at (q->validated_until, &check_link_down, vl); 7966 GNUNET_SCHEDULER_add_at(q->validated_until, &check_link_down, vl);
8044 GNUNET_break (GNUNET_YES == 7967 GNUNET_break(GNUNET_YES ==
8045 GNUNET_CONTAINER_multipeermap_put ( 7968 GNUNET_CONTAINER_multipeermap_put(
8046 links, 7969 links,
8047 &vl->target, 7970 &vl->target,
8048 vl, 7971 vl,
8049 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 7972 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
8050 consider_sending_fc (vl); 7973 consider_sending_fc(vl);
8051 /* We lacked a confirmed connection to the target 7974 /* We lacked a confirmed connection to the target
8052 before, so tell CORE about it (finally!) */ 7975 before, so tell CORE about it (finally!) */
8053 cores_send_connect_info (&n->pid); 7976 cores_send_connect_info(&n->pid);
8054} 7977}
8055 7978
8056 7979
@@ -8060,19 +7983,19 @@ handle_validation_response (
8060 * @param im the send message that was received 7983 * @param im the send message that was received
8061 */ 7984 */
8062static void 7985static void
8063handle_incoming_msg (void *cls, 7986handle_incoming_msg(void *cls,
8064 const struct GNUNET_TRANSPORT_IncomingMessage *im) 7987 const struct GNUNET_TRANSPORT_IncomingMessage *im)
8065{ 7988{
8066 struct TransportClient *tc = cls; 7989 struct TransportClient *tc = cls;
8067 struct CommunicatorMessageContext *cmc = 7990 struct CommunicatorMessageContext *cmc =
8068 GNUNET_new (struct CommunicatorMessageContext); 7991 GNUNET_new(struct CommunicatorMessageContext);
8069 7992
8070 cmc->tc = tc; 7993 cmc->tc = tc;
8071 cmc->im = *im; 7994 cmc->im = *im;
8072 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 7995 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8073 "Received message via communicator from peer %s\n", 7996 "Received message via communicator from peer %s\n",
8074 GNUNET_i2s (&im->sender)); 7997 GNUNET_i2s(&im->sender));
8075 demultiplex_with_cmc (cmc, (const struct GNUNET_MessageHeader *) &im[1]); 7998 demultiplex_with_cmc(cmc, (const struct GNUNET_MessageHeader *)&im[1]);
8076} 7999}
8077 8000
8078 8001
@@ -8085,7 +8008,7 @@ handle_incoming_msg (void *cls,
8085 * @param fc the message that was received 8008 * @param fc the message that was received
8086 */ 8009 */
8087static void 8010static void
8088handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc) 8011handle_flow_control(void *cls, const struct TransportFlowControlMessage *fc)
8089{ 8012{
8090 struct CommunicatorMessageContext *cmc = cls; 8013 struct CommunicatorMessageContext *cmc = cls;
8091 struct VirtualLink *vl; 8014 struct VirtualLink *vl;
@@ -8094,70 +8017,70 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
8094 uint64_t os; 8017 uint64_t os;
8095 uint64_t wnd; 8018 uint64_t wnd;
8096 8019
8097 vl = lookup_virtual_link (&cmc->im.sender); 8020 vl = lookup_virtual_link(&cmc->im.sender);
8098 if (NULL == vl) 8021 if (NULL == vl)
8099 { 8022 {
8100 GNUNET_STATISTICS_update (GST_stats, 8023 GNUNET_STATISTICS_update(GST_stats,
8101 "# FC dropped: virtual link unknown", 8024 "# FC dropped: virtual link unknown",
8102 1, 8025 1,
8103 GNUNET_NO); 8026 GNUNET_NO);
8104 finish_cmc_handling (cmc); 8027 finish_cmc_handling(cmc);
8105 return; 8028 return;
8106 } 8029 }
8107 st = GNUNET_TIME_absolute_ntoh (fc->sender_time); 8030 st = GNUNET_TIME_absolute_ntoh(fc->sender_time);
8108 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us) 8031 if (st.abs_value_us < vl->last_fc_timestamp.abs_value_us)
8109 { 8032 {
8110 /* out of order, drop */ 8033 /* out of order, drop */
8111 GNUNET_STATISTICS_update (GST_stats, 8034 GNUNET_STATISTICS_update(GST_stats,
8112 "# FC dropped: message out of order", 8035 "# FC dropped: message out of order",
8113 1, 8036 1,
8114 GNUNET_NO); 8037 GNUNET_NO);
8115 finish_cmc_handling (cmc); 8038 finish_cmc_handling(cmc);
8116 return; 8039 return;
8117 } 8040 }
8118 seq = ntohl (fc->seq); 8041 seq = ntohl(fc->seq);
8119 if (seq < vl->last_fc_seq) 8042 if (seq < vl->last_fc_seq)
8120 { 8043 {
8121 /* Wrap-around/reset of other peer; start all counters from zero */ 8044 /* Wrap-around/reset of other peer; start all counters from zero */
8122 vl->outbound_fc_window_size_used = 0; 8045 vl->outbound_fc_window_size_used = 0;
8123 } 8046 }
8124 vl->last_fc_seq = seq; 8047 vl->last_fc_seq = seq;
8125 vl->last_fc_timestamp = st; 8048 vl->last_fc_timestamp = st;
8126 vl->outbound_fc_window_size = GNUNET_ntohll (fc->inbound_window_size); 8049 vl->outbound_fc_window_size = GNUNET_ntohll(fc->inbound_window_size);
8127 os = GNUNET_ntohll (fc->outbound_sent); 8050 os = GNUNET_ntohll(fc->outbound_sent);
8128 vl->incoming_fc_window_size_loss = 8051 vl->incoming_fc_window_size_loss =
8129 (int64_t) (os - vl->incoming_fc_window_size_used); 8052 (int64_t)(os - vl->incoming_fc_window_size_used);
8130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8053 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8131 "Received FC from %s, seq %u, new window %llu (loss at %lld)\n", 8054 "Received FC from %s, seq %u, new window %llu (loss at %lld)\n",
8132 GNUNET_i2s (&vl->target), 8055 GNUNET_i2s(&vl->target),
8133 (unsigned int) seq, 8056 (unsigned int)seq,
8134 (unsigned long long) vl->outbound_fc_window_size, 8057 (unsigned long long)vl->outbound_fc_window_size,
8135 (long long) vl->incoming_fc_window_size_loss); 8058 (long long)vl->incoming_fc_window_size_loss);
8136 wnd = GNUNET_ntohll (fc->outbound_window_size); 8059 wnd = GNUNET_ntohll(fc->outbound_window_size);
8137 if ((wnd < vl->incoming_fc_window_size) || 8060 if ((wnd < vl->incoming_fc_window_size) ||
8138 (vl->last_outbound_window_size_received != wnd) || 8061 (vl->last_outbound_window_size_received != wnd) ||
8139 (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) % 8062 (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX) %
8140 FC_NO_CHANGE_REPLY_PROBABILITY)) 8063 FC_NO_CHANGE_REPLY_PROBABILITY))
8141 { 8064 {
8142 /* Consider re-sending our FC message, as clearly the 8065 /* Consider re-sending our FC message, as clearly the
8143 other peer's idea of the window is not up-to-date */ 8066 other peer's idea of the window is not up-to-date */
8144 consider_sending_fc (vl); 8067 consider_sending_fc(vl);
8145 } 8068 }
8146 if ((wnd == vl->incoming_fc_window_size) && 8069 if ((wnd == vl->incoming_fc_window_size) &&
8147 (vl->last_outbound_window_size_received == wnd) && 8070 (vl->last_outbound_window_size_received == wnd) &&
8148 (NULL != vl->fc_retransmit_task)) 8071 (NULL != vl->fc_retransmit_task))
8149 { 8072 {
8150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8073 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8151 "Stopping FC retransmission to %s: peer is current at window %llu\n", 8074 "Stopping FC retransmission to %s: peer is current at window %llu\n",
8152 GNUNET_i2s (&vl->target), 8075 GNUNET_i2s(&vl->target),
8153 (unsigned long long) wnd); 8076 (unsigned long long)wnd);
8154 GNUNET_SCHEDULER_cancel (vl->fc_retransmit_task); 8077 GNUNET_SCHEDULER_cancel(vl->fc_retransmit_task);
8155 vl->fc_retransmit_task = NULL; 8078 vl->fc_retransmit_task = NULL;
8156 } 8079 }
8157 vl->last_outbound_window_size_received = wnd; 8080 vl->last_outbound_window_size_received = wnd;
8158 /* FC window likely increased, check transmission possibilities! */ 8081 /* FC window likely increased, check transmission possibilities! */
8159 check_vl_transmission (vl); 8082 check_vl_transmission(vl);
8160 finish_cmc_handling (cmc); 8083 finish_cmc_handling(cmc);
8161} 8084}
8162 8085
8163 8086
@@ -8169,68 +8092,68 @@ handle_flow_control (void *cls, const struct TransportFlowControlMessage *fc)
8169 * @param msg message to demultiplex 8092 * @param msg message to demultiplex
8170 */ 8093 */
8171static void 8094static void
8172demultiplex_with_cmc (struct CommunicatorMessageContext *cmc, 8095demultiplex_with_cmc(struct CommunicatorMessageContext *cmc,
8173 const struct GNUNET_MessageHeader *msg) 8096 const struct GNUNET_MessageHeader *msg)
8174{ 8097{
8175 struct GNUNET_MQ_MessageHandler handlers[] = 8098 struct GNUNET_MQ_MessageHandler handlers[] =
8176 {GNUNET_MQ_hd_var_size (fragment_box, 8099 { GNUNET_MQ_hd_var_size(fragment_box,
8177 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT, 8100 GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT,
8178 struct TransportFragmentBoxMessage, 8101 struct TransportFragmentBoxMessage,
8179 &cmc), 8102 &cmc),
8180 GNUNET_MQ_hd_var_size (reliability_box, 8103 GNUNET_MQ_hd_var_size(reliability_box,
8181 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX, 8104 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX,
8182 struct TransportReliabilityBoxMessage, 8105 struct TransportReliabilityBoxMessage,
8183 &cmc), 8106 &cmc),
8184 GNUNET_MQ_hd_var_size (reliability_ack, 8107 GNUNET_MQ_hd_var_size(reliability_ack,
8185 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK, 8108 GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_ACK,
8186 struct TransportReliabilityAckMessage, 8109 struct TransportReliabilityAckMessage,
8187 &cmc), 8110 &cmc),
8188 GNUNET_MQ_hd_var_size (backchannel_encapsulation, 8111 GNUNET_MQ_hd_var_size(backchannel_encapsulation,
8189 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION, 8112 GNUNET_MESSAGE_TYPE_TRANSPORT_BACKCHANNEL_ENCAPSULATION,
8190 struct TransportBackchannelEncapsulationMessage, 8113 struct TransportBackchannelEncapsulationMessage,
8114 &cmc),
8115 GNUNET_MQ_hd_var_size(dv_learn,
8116 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN,
8117 struct TransportDVLearnMessage,
8118 &cmc),
8119 GNUNET_MQ_hd_var_size(dv_box,
8120 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX,
8121 struct TransportDVBoxMessage,
8122 &cmc),
8123 GNUNET_MQ_hd_fixed_size(
8124 validation_challenge,
8125 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
8126 struct TransportValidationChallengeMessage,
8127 &cmc),
8128 GNUNET_MQ_hd_fixed_size(flow_control,
8129 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
8130 struct TransportFlowControlMessage,
8191 &cmc), 8131 &cmc),
8192 GNUNET_MQ_hd_var_size (dv_learn, 8132 GNUNET_MQ_hd_fixed_size(
8193 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN, 8133 validation_response,
8194 struct TransportDVLearnMessage, 8134 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
8195 &cmc), 8135 struct TransportValidationResponseMessage,
8196 GNUNET_MQ_hd_var_size (dv_box, 8136 &cmc),
8197 GNUNET_MESSAGE_TYPE_TRANSPORT_DV_BOX, 8137 GNUNET_MQ_handler_end() };
8198 struct TransportDVBoxMessage,
8199 &cmc),
8200 GNUNET_MQ_hd_fixed_size (
8201 validation_challenge,
8202 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE,
8203 struct TransportValidationChallengeMessage,
8204 &cmc),
8205 GNUNET_MQ_hd_fixed_size (flow_control,
8206 GNUNET_MESSAGE_TYPE_TRANSPORT_FLOW_CONTROL,
8207 struct TransportFlowControlMessage,
8208 &cmc),
8209 GNUNET_MQ_hd_fixed_size (
8210 validation_response,
8211 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_RESPONSE,
8212 struct TransportValidationResponseMessage,
8213 &cmc),
8214 GNUNET_MQ_handler_end ()};
8215 int ret; 8138 int ret;
8216 8139
8217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8218 "Handling message of type %u with %u bytes\n", 8141 "Handling message of type %u with %u bytes\n",
8219 (unsigned int) ntohs (msg->type), 8142 (unsigned int)ntohs(msg->type),
8220 (unsigned int) ntohs (msg->size)); 8143 (unsigned int)ntohs(msg->size));
8221 ret = GNUNET_MQ_handle_message (handlers, msg); 8144 ret = GNUNET_MQ_handle_message(handlers, msg);
8222 if (GNUNET_SYSERR == ret) 8145 if (GNUNET_SYSERR == ret)
8223 { 8146 {
8224 GNUNET_break (0); 8147 GNUNET_break(0);
8225 GNUNET_SERVICE_client_drop (cmc->tc->client); 8148 GNUNET_SERVICE_client_drop(cmc->tc->client);
8226 GNUNET_free (cmc); 8149 GNUNET_free(cmc);
8227 return; 8150 return;
8228 } 8151 }
8229 if (GNUNET_NO == ret) 8152 if (GNUNET_NO == ret)
8230 { 8153 {
8231 /* unencapsulated 'raw' message */ 8154 /* unencapsulated 'raw' message */
8232 handle_raw_message (&cmc, msg); 8155 handle_raw_message(&cmc, msg);
8233 } 8156 }
8234} 8157}
8235 8158
8236 8159
@@ -8241,17 +8164,17 @@ demultiplex_with_cmc (struct CommunicatorMessageContext *cmc,
8241 * @param aqm the send message that was sent 8164 * @param aqm the send message that was sent
8242 */ 8165 */
8243static int 8166static int
8244check_add_queue_message (void *cls, 8167check_add_queue_message(void *cls,
8245 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 8168 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
8246{ 8169{
8247 struct TransportClient *tc = cls; 8170 struct TransportClient *tc = cls;
8248 8171
8249 if (CT_COMMUNICATOR != tc->type) 8172 if (CT_COMMUNICATOR != tc->type)
8250 { 8173 {
8251 GNUNET_break (0); 8174 GNUNET_break(0);
8252 return GNUNET_SYSERR; 8175 return GNUNET_SYSERR;
8253 } 8176 }
8254 GNUNET_MQ_check_zero_termination (aqm); 8177 GNUNET_MQ_check_zero_termination(aqm);
8255 return GNUNET_OK; 8178 return GNUNET_OK;
8256} 8179}
8257 8180
@@ -8262,7 +8185,7 @@ check_add_queue_message (void *cls,
8262 * @param pm pending message to generate UUID for. 8185 * @param pm pending message to generate UUID for.
8263 */ 8186 */
8264static void 8187static void
8265set_pending_message_uuid (struct PendingMessage *pm) 8188set_pending_message_uuid(struct PendingMessage *pm)
8266{ 8189{
8267 if (pm->msg_uuid_set) 8190 if (pm->msg_uuid_set)
8268 return; 8191 return;
@@ -8280,36 +8203,37 @@ set_pending_message_uuid (struct PendingMessage *pm)
8280 * @return corresponding fresh pending acknowledgement 8203 * @return corresponding fresh pending acknowledgement
8281 */ 8204 */
8282static struct PendingAcknowledgement * 8205static struct PendingAcknowledgement *
8283prepare_pending_acknowledgement (struct Queue *queue, 8206prepare_pending_acknowledgement(struct Queue *queue,
8284 struct DistanceVectorHop *dvh, 8207 struct DistanceVectorHop *dvh,
8285 struct PendingMessage *pm) 8208 struct PendingMessage *pm)
8286{ 8209{
8287 struct PendingAcknowledgement *pa; 8210 struct PendingAcknowledgement *pa;
8288 8211
8289 pa = GNUNET_new (struct PendingAcknowledgement); 8212 pa = GNUNET_new(struct PendingAcknowledgement);
8290 pa->queue = queue; 8213 pa->queue = queue;
8291 pa->dvh = dvh; 8214 pa->dvh = dvh;
8292 pa->pm = pm; 8215 pa->pm = pm;
8293 do 8216 do
8294 { 8217 {
8295 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 8218 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
8296 &pa->ack_uuid, 8219 &pa->ack_uuid,
8297 sizeof (pa->ack_uuid)); 8220 sizeof(pa->ack_uuid));
8298 } while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put ( 8221 }
8299 pending_acks, 8222 while (GNUNET_YES != GNUNET_CONTAINER_multiuuidmap_put(
8300 &pa->ack_uuid.value, 8223 pending_acks,
8301 pa, 8224 &pa->ack_uuid.value,
8302 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 8225 pa,
8303 GNUNET_CONTAINER_MDLL_insert (queue, queue->pa_head, queue->pa_tail, pa); 8226 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
8304 GNUNET_CONTAINER_MDLL_insert (pm, pm->pa_head, pm->pa_tail, pa); 8227 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);
8305 if (NULL != dvh) 8229 if (NULL != dvh)
8306 GNUNET_CONTAINER_MDLL_insert (dvh, dvh->pa_head, dvh->pa_tail, pa); 8230 GNUNET_CONTAINER_MDLL_insert(dvh, dvh->pa_head, dvh->pa_tail, pa);
8307 pa->transmission_time = GNUNET_TIME_absolute_get (); 8231 pa->transmission_time = GNUNET_TIME_absolute_get();
8308 pa->message_size = pm->bytes_msg; 8232 pa->message_size = pm->bytes_msg;
8309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8233 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8310 "Waiting for ACKnowledgment `%s' for <%llu>\n", 8234 "Waiting for ACKnowledgment `%s' for <%llu>\n",
8311 GNUNET_uuid2s (&pa->ack_uuid.value), 8235 GNUNET_uuid2s(&pa->ack_uuid.value),
8312 pm->logging_uuid); 8236 pm->logging_uuid);
8313 return pa; 8237 return pa;
8314} 8238}
8315 8239
@@ -8326,28 +8250,28 @@ prepare_pending_acknowledgement (struct Queue *queue,
8326 * @return new message to transmit 8250 * @return new message to transmit
8327 */ 8251 */
8328static struct PendingMessage * 8252static struct PendingMessage *
8329fragment_message (struct Queue *queue, 8253fragment_message(struct Queue *queue,
8330 struct DistanceVectorHop *dvh, 8254 struct DistanceVectorHop *dvh,
8331 struct PendingMessage *pm) 8255 struct PendingMessage *pm)
8332{ 8256{
8333 struct PendingAcknowledgement *pa; 8257 struct PendingAcknowledgement *pa;
8334 struct PendingMessage *ff; 8258 struct PendingMessage *ff;
8335 uint16_t mtu; 8259 uint16_t mtu;
8336 8260
8337 mtu = (0 == queue->mtu) 8261 mtu = (0 == queue->mtu)
8338 ? UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo) 8262 ? UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)
8339 : queue->mtu; 8263 : queue->mtu;
8340 set_pending_message_uuid (pm); 8264 set_pending_message_uuid(pm);
8341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8265 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8342 "Fragmenting message %llu <%llu> to %s for MTU %u\n", 8266 "Fragmenting message %llu <%llu> to %s for MTU %u\n",
8343 (unsigned long long) pm->msg_uuid.uuid, 8267 (unsigned long long)pm->msg_uuid.uuid,
8344 pm->logging_uuid, 8268 pm->logging_uuid,
8345 GNUNET_i2s (&pm->vl->target), 8269 GNUNET_i2s(&pm->vl->target),
8346 (unsigned int) mtu); 8270 (unsigned int)mtu);
8347 pa = prepare_pending_acknowledgement (queue, dvh, pm); 8271 pa = prepare_pending_acknowledgement(queue, dvh, pm);
8348 8272
8349 /* This invariant is established in #handle_add_queue_message() */ 8273 /* This invariant is established in #handle_add_queue_message() */
8350 GNUNET_assert (mtu > sizeof (struct TransportFragmentBoxMessage)); 8274 GNUNET_assert(mtu > sizeof(struct TransportFragmentBoxMessage));
8351 8275
8352 /* select fragment for transmission, descending the tree if it has 8276 /* select fragment for transmission, descending the tree if it has
8353 been expanded until we are at a leaf or at a fragment that is small 8277 been expanded until we are at a leaf or at a fragment that is small
@@ -8356,68 +8280,68 @@ fragment_message (struct Queue *queue,
8356 ff = pm; 8280 ff = pm;
8357 while (((ff->bytes_msg > mtu) || (pm == ff)) && 8281 while (((ff->bytes_msg > mtu) || (pm == ff)) &&
8358 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag)) 8282 (ff->frag_off == ff->bytes_msg) && (NULL != ff->head_frag))
8359 { 8283 {
8360 ff = ff->head_frag; /* descent into fragmented fragments */ 8284 ff = ff->head_frag; /* descent into fragmented fragments */
8361 } 8285 }
8362 8286
8363 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg)) 8287 if (((ff->bytes_msg > mtu) || (pm == ff)) && (pm->frag_off < pm->bytes_msg))
8364 { 8288 {
8365 /* Did not yet calculate all fragments, calculate next fragment */ 8289 /* Did not yet calculate all fragments, calculate next fragment */
8366 struct PendingMessage *frag; 8290 struct PendingMessage *frag;
8367 struct TransportFragmentBoxMessage tfb; 8291 struct TransportFragmentBoxMessage tfb;
8368 const char *orig; 8292 const char *orig;
8369 char *msg; 8293 char *msg;
8370 uint16_t fragmax; 8294 uint16_t fragmax;
8371 uint16_t fragsize; 8295 uint16_t fragsize;
8372 uint16_t msize; 8296 uint16_t msize;
8373 uint16_t xoff = 0; 8297 uint16_t xoff = 0;
8374 8298
8375 orig = (const char *) &ff[1]; 8299 orig = (const char *)&ff[1];
8376 msize = ff->bytes_msg; 8300 msize = ff->bytes_msg;
8377 if (pm != ff) 8301 if (pm != ff)
8378 { 8302 {
8379 const struct TransportFragmentBoxMessage *tfbo; 8303 const struct TransportFragmentBoxMessage *tfbo;
8380 8304
8381 tfbo = (const struct TransportFragmentBoxMessage *) orig; 8305 tfbo = (const struct TransportFragmentBoxMessage *)orig;
8382 orig += sizeof (struct TransportFragmentBoxMessage); 8306 orig += sizeof(struct TransportFragmentBoxMessage);
8383 msize -= sizeof (struct TransportFragmentBoxMessage); 8307 msize -= sizeof(struct TransportFragmentBoxMessage);
8384 xoff = ntohs (tfbo->frag_off); 8308 xoff = ntohs(tfbo->frag_off);
8385 } 8309 }
8386 fragmax = mtu - sizeof (struct TransportFragmentBoxMessage); 8310 fragmax = mtu - sizeof(struct TransportFragmentBoxMessage);
8387 fragsize = GNUNET_MIN (msize - ff->frag_off, fragmax); 8311 fragsize = GNUNET_MIN(msize - ff->frag_off, fragmax);
8388 frag = 8312 frag =
8389 GNUNET_malloc (sizeof (struct PendingMessage) + 8313 GNUNET_malloc(sizeof(struct PendingMessage) +
8390 sizeof (struct TransportFragmentBoxMessage) + fragsize); 8314 sizeof(struct TransportFragmentBoxMessage) + fragsize);
8391 frag->logging_uuid = logging_uuid_gen++; 8315 frag->logging_uuid = logging_uuid_gen++;
8392 frag->vl = pm->vl; 8316 frag->vl = pm->vl;
8393 frag->frag_parent = ff; 8317 frag->frag_parent = ff;
8394 frag->timeout = pm->timeout; 8318 frag->timeout = pm->timeout;
8395 frag->bytes_msg = sizeof (struct TransportFragmentBoxMessage) + fragsize; 8319 frag->bytes_msg = sizeof(struct TransportFragmentBoxMessage) + fragsize;
8396 frag->pmt = PMT_FRAGMENT_BOX; 8320 frag->pmt = PMT_FRAGMENT_BOX;
8397 msg = (char *) &frag[1]; 8321 msg = (char *)&frag[1];
8398 tfb.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT); 8322 tfb.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_FRAGMENT);
8399 tfb.header.size = 8323 tfb.header.size =
8400 htons (sizeof (struct TransportFragmentBoxMessage) + fragsize); 8324 htons(sizeof(struct TransportFragmentBoxMessage) + fragsize);
8401 tfb.ack_uuid = pa->ack_uuid; 8325 tfb.ack_uuid = pa->ack_uuid;
8402 tfb.msg_uuid = pm->msg_uuid; 8326 tfb.msg_uuid = pm->msg_uuid;
8403 tfb.frag_off = htons (ff->frag_off + xoff); 8327 tfb.frag_off = htons(ff->frag_off + xoff);
8404 tfb.msg_size = htons (pm->bytes_msg); 8328 tfb.msg_size = htons(pm->bytes_msg);
8405 memcpy (msg, &tfb, sizeof (tfb)); 8329 memcpy(msg, &tfb, sizeof(tfb));
8406 memcpy (&msg[sizeof (tfb)], &orig[ff->frag_off], fragsize); 8330 memcpy(&msg[sizeof(tfb)], &orig[ff->frag_off], fragsize);
8407 GNUNET_CONTAINER_MDLL_insert (frag, ff->head_frag, ff->tail_frag, frag); 8331 GNUNET_CONTAINER_MDLL_insert(frag, ff->head_frag, ff->tail_frag, frag);
8408 ff->frag_off += fragsize; 8332 ff->frag_off += fragsize;
8409 ff = frag; 8333 ff = frag;
8410 } 8334 }
8411 8335
8412 /* Move head to the tail and return it */ 8336 /* Move head to the tail and return it */
8413 GNUNET_CONTAINER_MDLL_remove (frag, 8337 GNUNET_CONTAINER_MDLL_remove(frag,
8414 ff->frag_parent->head_frag, 8338 ff->frag_parent->head_frag,
8415 ff->frag_parent->tail_frag, 8339 ff->frag_parent->tail_frag,
8416 ff); 8340 ff);
8417 GNUNET_CONTAINER_MDLL_insert_tail (frag, 8341 GNUNET_CONTAINER_MDLL_insert_tail(frag,
8418 ff->frag_parent->head_frag, 8342 ff->frag_parent->head_frag,
8419 ff->frag_parent->tail_frag, 8343 ff->frag_parent->tail_frag,
8420 ff); 8344 ff);
8421 return ff; 8345 return ff;
8422} 8346}
8423 8347
@@ -8435,9 +8359,9 @@ fragment_message (struct Queue *queue,
8435 * @return new message to transmit 8359 * @return new message to transmit
8436 */ 8360 */
8437static struct PendingMessage * 8361static struct PendingMessage *
8438reliability_box_message (struct Queue *queue, 8362reliability_box_message(struct Queue *queue,
8439 struct DistanceVectorHop *dvh, 8363 struct DistanceVectorHop *dvh,
8440 struct PendingMessage *pm) 8364 struct PendingMessage *pm)
8441{ 8365{
8442 struct TransportReliabilityBoxMessage rbox; 8366 struct TransportReliabilityBoxMessage rbox;
8443 struct PendingAcknowledgement *pa; 8367 struct PendingAcknowledgement *pa;
@@ -8449,39 +8373,39 @@ reliability_box_message (struct Queue *queue,
8449 do nothing */ 8373 do nothing */
8450 if (NULL != pm->bpm) 8374 if (NULL != pm->bpm)
8451 return pm->bpm; /* already computed earlier: do nothing */ 8375 return pm->bpm; /* already computed earlier: do nothing */
8452 GNUNET_assert (NULL == pm->head_frag); 8376 GNUNET_assert(NULL == pm->head_frag);
8453 if (pm->bytes_msg + sizeof (rbox) > UINT16_MAX) 8377 if (pm->bytes_msg + sizeof(rbox) > UINT16_MAX)
8454 { 8378 {
8455 /* failed hard */ 8379 /* failed hard */
8456 GNUNET_break (0); 8380 GNUNET_break(0);
8457 client_send_response (pm); 8381 client_send_response(pm);
8458 return NULL; 8382 return NULL;
8459 } 8383 }
8460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8461 "Preparing reliability box for message <%llu> to %s on queue %s\n", 8385 "Preparing reliability box for message <%llu> to %s on queue %s\n",
8462 pm->logging_uuid, 8386 pm->logging_uuid,
8463 GNUNET_i2s (&pm->vl->target), 8387 GNUNET_i2s(&pm->vl->target),
8464 queue->address); 8388 queue->address);
8465 pa = prepare_pending_acknowledgement (queue, dvh, pm); 8389 pa = prepare_pending_acknowledgement(queue, dvh, pm);
8466 8390
8467 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (rbox) + 8391 bpm = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(rbox) +
8468 pm->bytes_msg); 8392 pm->bytes_msg);
8469 bpm->logging_uuid = logging_uuid_gen++; 8393 bpm->logging_uuid = logging_uuid_gen++;
8470 bpm->vl = pm->vl; 8394 bpm->vl = pm->vl;
8471 bpm->frag_parent = pm; 8395 bpm->frag_parent = pm;
8472 GNUNET_CONTAINER_MDLL_insert (frag, pm->head_frag, pm->tail_frag, bpm); 8396 GNUNET_CONTAINER_MDLL_insert(frag, pm->head_frag, pm->tail_frag, bpm);
8473 bpm->timeout = pm->timeout; 8397 bpm->timeout = pm->timeout;
8474 bpm->pmt = PMT_RELIABILITY_BOX; 8398 bpm->pmt = PMT_RELIABILITY_BOX;
8475 bpm->bytes_msg = pm->bytes_msg + sizeof (rbox); 8399 bpm->bytes_msg = pm->bytes_msg + sizeof(rbox);
8476 set_pending_message_uuid (bpm); 8400 set_pending_message_uuid(bpm);
8477 rbox.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX); 8401 rbox.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RELIABILITY_BOX);
8478 rbox.header.size = htons (sizeof (rbox) + pm->bytes_msg); 8402 rbox.header.size = htons(sizeof(rbox) + pm->bytes_msg);
8479 rbox.ack_countdown = htonl (0); // FIXME: implement ACK countdown support 8403 rbox.ack_countdown = htonl(0); // FIXME: implement ACK countdown support
8480 8404
8481 rbox.ack_uuid = pa->ack_uuid; 8405 rbox.ack_uuid = pa->ack_uuid;
8482 msg = (char *) &bpm[1]; 8406 msg = (char *)&bpm[1];
8483 memcpy (msg, &rbox, sizeof (rbox)); 8407 memcpy(msg, &rbox, sizeof(rbox));
8484 memcpy (&msg[sizeof (rbox)], &pm[1], pm->bytes_msg); 8408 memcpy(&msg[sizeof(rbox)], &pm[1], pm->bytes_msg);
8485 pm->bpm = bpm; 8409 pm->bpm = bpm;
8486 return bpm; 8410 return bpm;
8487} 8411}
@@ -8496,61 +8420,60 @@ reliability_box_message (struct Queue *queue,
8496 * @param next_attempt timestamp to use 8420 * @param next_attempt timestamp to use
8497 */ 8421 */
8498static void 8422static void
8499update_pm_next_attempt (struct PendingMessage *pm, 8423update_pm_next_attempt(struct PendingMessage *pm,
8500 struct GNUNET_TIME_Absolute next_attempt) 8424 struct GNUNET_TIME_Absolute next_attempt)
8501{ 8425{
8502 struct VirtualLink *vl = pm->vl; 8426 struct VirtualLink *vl = pm->vl;
8503 8427
8504 pm->next_attempt = next_attempt; 8428 pm->next_attempt = next_attempt;
8505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8429 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8506 "Next attempt for message <%llu> set to %s\n", 8430 "Next attempt for message <%llu> set to %s\n",
8507 pm->logging_uuid, 8431 pm->logging_uuid,
8508 GNUNET_STRINGS_absolute_time_to_string (next_attempt)); 8432 GNUNET_STRINGS_absolute_time_to_string(next_attempt));
8509 8433
8510 if (NULL == pm->frag_parent) 8434 if (NULL == pm->frag_parent)
8511 { 8435 {
8512 struct PendingMessage *pos; 8436 struct PendingMessage *pos;
8513 8437
8514 /* re-insert sort in neighbour list */ 8438 /* re-insert sort in neighbour list */
8515 GNUNET_CONTAINER_MDLL_remove (vl, 8439 GNUNET_CONTAINER_MDLL_remove(vl,
8516 vl->pending_msg_head, 8440 vl->pending_msg_head,
8517 vl->pending_msg_tail, 8441 vl->pending_msg_tail,
8518 pm); 8442 pm);
8519 pos = vl->pending_msg_tail; 8443 pos = vl->pending_msg_tail;
8520 while ((NULL != pos) && 8444 while ((NULL != pos) &&
8521 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) 8445 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
8522 pos = pos->prev_vl; 8446 pos = pos->prev_vl;
8523 GNUNET_CONTAINER_MDLL_insert_after (vl, 8447 GNUNET_CONTAINER_MDLL_insert_after(vl,
8524 vl->pending_msg_head, 8448 vl->pending_msg_head,
8525 vl->pending_msg_tail, 8449 vl->pending_msg_tail,
8526 pos, 8450 pos,
8527 pm); 8451 pm);
8528 } 8452 }
8529 else 8453 else
8530 { 8454 {
8531 /* re-insert sort in fragment list */ 8455 /* re-insert sort in fragment list */
8532 struct PendingMessage *fp = pm->frag_parent; 8456 struct PendingMessage *fp = pm->frag_parent;
8533 struct PendingMessage *pos; 8457 struct PendingMessage *pos;
8534 8458
8535 GNUNET_CONTAINER_MDLL_remove (frag, fp->head_frag, fp->tail_frag, pm); 8459 GNUNET_CONTAINER_MDLL_remove(frag, fp->head_frag, fp->tail_frag, pm);
8536 pos = fp->tail_frag; 8460 pos = fp->tail_frag;
8537 while ((NULL != pos) && 8461 while ((NULL != pos) &&
8538 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us)) 8462 (next_attempt.abs_value_us > pos->next_attempt.abs_value_us))
8539 pos = pos->prev_frag; 8463 pos = pos->prev_frag;
8540 GNUNET_CONTAINER_MDLL_insert_after (frag, 8464 GNUNET_CONTAINER_MDLL_insert_after(frag,
8541 fp->head_frag, 8465 fp->head_frag,
8542 fp->tail_frag, 8466 fp->tail_frag,
8543 pos, 8467 pos,
8544 pm); 8468 pm);
8545 } 8469 }
8546} 8470}
8547 8471
8548 8472
8549/** 8473/**
8550 * Context for #select_best_pending_from_link(). 8474 * Context for #select_best_pending_from_link().
8551 */ 8475 */
8552struct PendingMessageScoreContext 8476struct PendingMessageScoreContext {
8553{
8554 /** 8477 /**
8555 * Set to the best message that was found, NULL for none. 8478 * Set to the best message that was found, NULL for none.
8556 */ 8479 */
@@ -8595,107 +8518,107 @@ struct PendingMessageScoreContext
8595 * from DV encapsulation (0 for without DV) 8518 * from DV encapsulation (0 for without DV)
8596 */ 8519 */
8597static void 8520static void
8598select_best_pending_from_link (struct PendingMessageScoreContext *sc, 8521select_best_pending_from_link(struct PendingMessageScoreContext *sc,
8599 struct Queue *queue, 8522 struct Queue *queue,
8600 struct VirtualLink *vl, 8523 struct VirtualLink *vl,
8601 struct DistanceVectorHop *dvh, 8524 struct DistanceVectorHop *dvh,
8602 size_t overhead) 8525 size_t overhead)
8603{ 8526{
8604 struct GNUNET_TIME_Absolute now; 8527 struct GNUNET_TIME_Absolute now;
8605 8528
8606 now = GNUNET_TIME_absolute_get (); 8529 now = GNUNET_TIME_absolute_get();
8607 for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos; 8530 for (struct PendingMessage *pos = vl->pending_msg_head; NULL != pos;
8608 pos = pos->next_vl) 8531 pos = pos->next_vl)
8609 { 8532 {
8610 size_t real_overhead = overhead; 8533 size_t real_overhead = overhead;
8611 int frag; 8534 int frag;
8612 int relb; 8535 int relb;
8613 8536
8614 if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt)) 8537 if ((NULL != dvh) && (PMT_DV_BOX == pos->pmt))
8615 continue; /* DV messages must not be DV-routed to next hop! */ 8538 continue; /* DV messages must not be DV-routed to next hop! */
8616 if (pos->next_attempt.abs_value_us > now.abs_value_us) 8539 if (pos->next_attempt.abs_value_us > now.abs_value_us)
8617 break; /* too early for all messages, they are sorted by next_attempt */ 8540 break; /* too early for all messages, they are sorted by next_attempt */
8618 if (NULL != pos->qe) 8541 if (NULL != pos->qe)
8619 continue; /* not eligible */ 8542 continue; /* not eligible */
8620 sc->consideration_counter++; 8543 sc->consideration_counter++;
8621 /* determine if we have to fragment, if so add fragmentation 8544 /* determine if we have to fragment, if so add fragmentation
8622 overhead! */ 8545 overhead! */
8623 frag = GNUNET_NO; 8546 frag = GNUNET_NO;
8624 if ( ( (0 != queue->mtu) && 8547 if (((0 != queue->mtu) &&
8625 (pos->bytes_msg + real_overhead > queue->mtu) ) || 8548 (pos->bytes_msg + real_overhead > queue->mtu)) ||
8626 (pos->bytes_msg > UINT16_MAX - sizeof (struct GNUNET_TRANSPORT_SendMessageTo)) || 8549 (pos->bytes_msg > UINT16_MAX - sizeof(struct GNUNET_TRANSPORT_SendMessageTo)) ||
8627 (NULL != pos->head_frag /* fragments already exist, should 8550 (NULL != pos->head_frag /* fragments already exist, should
8628 respect that even if MTU is 0 for 8551 respect that even if MTU is 0 for
8629 this queue */) ) 8552 this queue */))
8630 { 8553 {
8631 frag = GNUNET_YES; 8554 frag = GNUNET_YES;
8632 if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc) 8555 if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)
8633 { 8556 {
8634 /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation 8557 /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation
8635 header without the ACK UUID when using a *reliable* channel! */ 8558 header without the ACK UUID when using a *reliable* channel! */
8636 } 8559 }
8637 real_overhead = overhead + sizeof (struct TransportFragmentBoxMessage); 8560 real_overhead = overhead + sizeof(struct TransportFragmentBoxMessage);
8638 } 8561 }
8639 /* determine if we have to reliability-box, if so add reliability box 8562 /* determine if we have to reliability-box, if so add reliability box
8640 overhead */ 8563 overhead */
8641 relb = GNUNET_NO; 8564 relb = GNUNET_NO;
8642 if ((GNUNET_NO == frag) && 8565 if ((GNUNET_NO == frag) &&
8643 (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) && 8566 (0 == (pos->prefs & GNUNET_MQ_PREF_UNRELIABLE)) &&
8644 (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc)) 8567 (GNUNET_TRANSPORT_CC_RELIABLE != queue->tc->details.communicator.cc))
8645 { 8568 {
8646 relb = GNUNET_YES; 8569 relb = GNUNET_YES;
8647 real_overhead += sizeof (struct TransportReliabilityBoxMessage); 8570 real_overhead += sizeof(struct TransportReliabilityBoxMessage);
8648 } 8571 }
8649 8572
8650 /* Finally, compare to existing 'best' in sc to see if this 'pos' pending 8573 /* Finally, compare to existing 'best' in sc to see if this 'pos' pending
8651 message would beat it! */ 8574 message would beat it! */
8652 if (NULL != sc->best) 8575 if (NULL != sc->best)
8653 { 8576 {
8654 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue; 8577 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue;
8655 OPTIMIZE-ME: This is a heuristic, which so far has NOT been 8578 OPTIMIZE-ME: This is a heuristic, which so far has NOT been
8656 experimentally validated. There may be some huge potential for 8579 experimentally validated. There may be some huge potential for
8657 improvement here. Also, we right now only compare how well the 8580 improvement here. Also, we right now only compare how well the
8658 given message fits _this_ queue, and do not consider how well other 8581 given message fits _this_ queue, and do not consider how well other
8659 queues might suit the message. Taking other queues into consideration 8582 queues might suit the message. Taking other queues into consideration
8660 may further improve the result, but could also be expensive 8583 may further improve the result, but could also be expensive
8661 in terms of CPU time. */ 8584 in terms of CPU time. */
8662 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead; 8585 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead;
8663 long long pm_score = frag * 40 + relb * 20 + real_overhead; 8586 long long pm_score = frag * 40 + relb * 20 + real_overhead;
8664 long long time_delta = 8587 long long time_delta =
8665 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) / 8588 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) /
8666 1000LL; 8589 1000LL;
8667 8590
8668 /* "time_delta" considers which message has been 'ready' for transmission 8591 /* "time_delta" considers which message has been 'ready' for transmission
8669 for longer, if a message has a preference for low latency, increase 8592 for longer, if a message has a preference for low latency, increase
8670 the weight of the time_delta by 10x if it is favorable for that message */ 8593 the weight of the time_delta by 10x if it is favorable for that message */
8671 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8594 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8672 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY))) 8595 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)))
8673 time_delta *= 10; /* increase weight (always, both are low latency) */ 8596 time_delta *= 10; /* increase weight (always, both are low latency) */
8674 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8597 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8675 (time_delta > 0)) 8598 (time_delta > 0))
8676 time_delta *= 8599 time_delta *=
8677 10; /* increase weight, favors 'pos', which is low latency */ 8600 10; /* increase weight, favors 'pos', which is low latency */
8678 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) && 8601 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
8679 (time_delta < 0)) 8602 (time_delta < 0))
8680 time_delta *= 8603 time_delta *=
8681 10; /* increase weight, favors 'sc->best', which is low latency */ 8604 10; /* increase weight, favors 'sc->best', which is low latency */
8682 if (0 != queue->mtu) 8605 if (0 != queue->mtu)
8683 { 8606 {
8684 /* Grant bonus if we are bellow MTU, larger bonus the closer we will 8607 /* Grant bonus if we are bellow MTU, larger bonus the closer we will
8685 be to the MTU */ 8608 be to the MTU */
8686 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg) 8609 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg)
8687 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg); 8610 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg);
8688 if (queue->mtu > real_overhead + pos->bytes_msg) 8611 if (queue->mtu > real_overhead + pos->bytes_msg)
8689 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg); 8612 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg);
8690 } 8613 }
8691 if (sc_score + time_delta > pm_score) 8614 if (sc_score + time_delta > pm_score)
8692 continue; /* sc_score larger, keep sc->best */ 8615 continue; /* sc_score larger, keep sc->best */
8616 }
8617 sc->best = pos;
8618 sc->dvh = dvh;
8619 sc->frag = frag;
8620 sc->relb = relb;
8693 } 8621 }
8694 sc->best = pos;
8695 sc->dvh = dvh;
8696 sc->frag = frag;
8697 sc->relb = relb;
8698 }
8699} 8622}
8700 8623
8701 8624
@@ -8710,26 +8633,26 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
8710 * @param options options of the original message 8633 * @param options options of the original message
8711 */ 8634 */
8712static void 8635static void
8713extract_box_cb (void *cls, 8636extract_box_cb(void *cls,
8714 struct Neighbour *next_hop, 8637 struct Neighbour *next_hop,
8715 const struct GNUNET_MessageHeader *hdr, 8638 const struct GNUNET_MessageHeader *hdr,
8716 enum RouteMessageOptions options) 8639 enum RouteMessageOptions options)
8717{ 8640{
8718 struct PendingMessageScoreContext *sc = cls; 8641 struct PendingMessageScoreContext *sc = cls;
8719 struct PendingMessage *pm = sc->best; 8642 struct PendingMessage *pm = sc->best;
8720 struct PendingMessage *bpm; 8643 struct PendingMessage *bpm;
8721 uint16_t bsize = ntohs (hdr->size); 8644 uint16_t bsize = ntohs(hdr->size);
8722 8645
8723 GNUNET_assert (NULL == pm->bpm); 8646 GNUNET_assert(NULL == pm->bpm);
8724 bpm = GNUNET_malloc (sizeof (struct PendingMessage) + bsize); 8647 bpm = GNUNET_malloc(sizeof(struct PendingMessage) + bsize);
8725 bpm->logging_uuid = logging_uuid_gen++; 8648 bpm->logging_uuid = logging_uuid_gen++;
8726 bpm->pmt = PMT_DV_BOX; 8649 bpm->pmt = PMT_DV_BOX;
8727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8650 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8728 "Creating DV Box %llu for original message %llu (next hop is %s)\n", 8651 "Creating DV Box %llu for original message %llu (next hop is %s)\n",
8729 bpm->logging_uuid, 8652 bpm->logging_uuid,
8730 pm->logging_uuid, 8653 pm->logging_uuid,
8731 GNUNET_i2s (&next_hop->pid)); 8654 GNUNET_i2s(&next_hop->pid));
8732 memcpy (&bpm[1], hdr, bsize); 8655 memcpy(&bpm[1], hdr, bsize);
8733 pm->bpm = bpm; 8656 pm->bpm = bpm;
8734} 8657}
8735 8658
@@ -8750,7 +8673,7 @@ extract_box_cb (void *cls,
8750 * @param cls the `struct Queue` to process transmissions for 8673 * @param cls the `struct Queue` to process transmissions for
8751 */ 8674 */
8752static void 8675static void
8753transmit_on_queue (void *cls) 8676transmit_on_queue(void *cls)
8754{ 8677{
8755 struct Queue *queue = cls; 8678 struct Queue *queue = cls;
8756 struct Neighbour *n = queue->neighbour; 8679 struct Neighbour *n = queue->neighbour;
@@ -8759,104 +8682,104 @@ transmit_on_queue (void *cls)
8759 8682
8760 queue->transmit_task = NULL; 8683 queue->transmit_task = NULL;
8761 if (NULL == n->vl) 8684 if (NULL == n->vl)
8762 { 8685 {
8763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8686 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8764 "Virtual link `%s' is down, cannot have PM for queue `%s'\n", 8687 "Virtual link `%s' is down, cannot have PM for queue `%s'\n",
8765 GNUNET_i2s (&n->pid), 8688 GNUNET_i2s(&n->pid),
8766 queue->address); 8689 queue->address);
8767 queue->idle = GNUNET_YES; 8690 queue->idle = GNUNET_YES;
8768 return; 8691 return;
8769 } 8692 }
8770 memset (&sc, 0, sizeof (sc)); 8693 memset(&sc, 0, sizeof(sc));
8771 select_best_pending_from_link (&sc, queue, n->vl, NULL, 0); 8694 select_best_pending_from_link(&sc, queue, n->vl, NULL, 0);
8772 if (NULL == sc.best) 8695 if (NULL == sc.best)
8773 { 8696 {
8774 /* Also look at DVH that have the n as first hop! */ 8697 /* Also look at DVH that have the n as first hop! */
8775 for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh; 8698 for (struct DistanceVectorHop *dvh = n->dv_head; NULL != dvh;
8776 dvh = dvh->next_neighbour) 8699 dvh = dvh->next_neighbour)
8777 { 8700 {
8778 select_best_pending_from_link (&sc, 8701 select_best_pending_from_link(&sc,
8779 queue, 8702 queue,
8780 dvh->dv->vl, 8703 dvh->dv->vl,
8781 dvh, 8704 dvh,
8782 sizeof (struct GNUNET_PeerIdentity) * 8705 sizeof(struct GNUNET_PeerIdentity) *
8783 (1 + dvh->distance) + 8706 (1 + dvh->distance) +
8784 sizeof (struct TransportDVBoxMessage) + 8707 sizeof(struct TransportDVBoxMessage) +
8785 sizeof (struct TransportDVBoxPayloadP)); 8708 sizeof(struct TransportDVBoxPayloadP));
8709 }
8786 } 8710 }
8787 }
8788 if (NULL == sc.best) 8711 if (NULL == sc.best)
8789 { 8712 {
8790 /* no message pending, nothing to do here! */ 8713 /* no message pending, nothing to do here! */
8791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8792 "No pending messages, queue `%s' to %s now idle\n", 8715 "No pending messages, queue `%s' to %s now idle\n",
8793 queue->address, 8716 queue->address,
8794 GNUNET_i2s (&n->pid)); 8717 GNUNET_i2s(&n->pid));
8795 queue->idle = GNUNET_YES; 8718 queue->idle = GNUNET_YES;
8796 return; 8719 return;
8797 } 8720 }
8798 8721
8799 /* Given selection in `sc`, do transmission */ 8722 /* Given selection in `sc`, do transmission */
8800 pm = sc.best; 8723 pm = sc.best;
8801 if (NULL != sc.dvh) 8724 if (NULL != sc.dvh)
8802 { 8725 {
8803 GNUNET_assert (PMT_DV_BOX != pm->pmt); 8726 GNUNET_assert(PMT_DV_BOX != pm->pmt);
8804 if (NULL != sc.best->bpm) 8727 if (NULL != sc.best->bpm)
8805 { 8728 {
8806 /* We did this boxing before, but possibly for a different path! 8729 /* We did this boxing before, but possibly for a different path!
8807 Discard old DV box! OPTIMIZE-ME: we might want to check if 8730 Discard old DV box! OPTIMIZE-ME: we might want to check if
8808 it is the same and then not re-build the message... */ 8731 it is the same and then not re-build the message... */
8809 free_pending_message (sc.best->bpm); 8732 free_pending_message(sc.best->bpm);
8810 sc.best->bpm = NULL; 8733 sc.best->bpm = NULL;
8811 } 8734 }
8812 encapsulate_for_dv (sc.dvh->dv, 8735 encapsulate_for_dv(sc.dvh->dv,
8813 1, 8736 1,
8814 &sc.dvh, 8737 &sc.dvh,
8815 (const struct GNUNET_MessageHeader *) &sc.best[1], 8738 (const struct GNUNET_MessageHeader *)&sc.best[1],
8816 &extract_box_cb, 8739 &extract_box_cb,
8817 &sc, 8740 &sc,
8818 RMO_NONE); 8741 RMO_NONE);
8819 GNUNET_assert (NULL != sc.best->bpm); 8742 GNUNET_assert(NULL != sc.best->bpm);
8820 pm = sc.best->bpm; 8743 pm = sc.best->bpm;
8821 } 8744 }
8822 if (GNUNET_YES == sc.frag) 8745 if (GNUNET_YES == sc.frag)
8823 { 8746 {
8824 pm = fragment_message (queue, sc.dvh, pm); 8747 pm = fragment_message(queue, sc.dvh, pm);
8825 if (NULL == pm) 8748 if (NULL == pm)
8826 { 8749 {
8827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8750 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8828 "Fragmentation failed queue %s to %s for <%llu>, trying again\n", 8751 "Fragmentation failed queue %s to %s for <%llu>, trying again\n",
8829 queue->address, 8752 queue->address,
8830 GNUNET_i2s (&n->pid), 8753 GNUNET_i2s(&n->pid),
8831 sc.best->logging_uuid); 8754 sc.best->logging_uuid);
8832 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8755 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8833 return; 8756 return;
8757 }
8834 } 8758 }
8835 }
8836 else if (GNUNET_YES == sc.relb) 8759 else if (GNUNET_YES == sc.relb)
8837 { 8760 {
8838 pm = reliability_box_message (queue, sc.dvh, pm); 8761 pm = reliability_box_message(queue, sc.dvh, pm);
8839 if (NULL == pm) 8762 if (NULL == pm)
8840 { 8763 {
8841 /* Reliability boxing failed, try next message... */ 8764 /* Reliability boxing failed, try next message... */
8842 GNUNET_log ( 8765 GNUNET_log(
8843 GNUNET_ERROR_TYPE_DEBUG, 8766 GNUNET_ERROR_TYPE_DEBUG,
8844 "Reliability boxing failed queue %s to %s for <%llu>, trying again\n", 8767 "Reliability boxing failed queue %s to %s for <%llu>, trying again\n",
8845 queue->address, 8768 queue->address,
8846 GNUNET_i2s (&n->pid), 8769 GNUNET_i2s(&n->pid),
8847 sc.best->logging_uuid); 8770 sc.best->logging_uuid);
8848 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8771 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8849 return; 8772 return;
8773 }
8850 } 8774 }
8851 }
8852 8775
8853 /* Pass 'pm' for transission to the communicator */ 8776 /* Pass 'pm' for transission to the communicator */
8854 GNUNET_log ( 8777 GNUNET_log(
8855 GNUNET_ERROR_TYPE_DEBUG, 8778 GNUNET_ERROR_TYPE_DEBUG,
8856 "Passing message <%llu> to queue %s for peer %s (considered %u others)\n", 8779 "Passing message <%llu> to queue %s for peer %s (considered %u others)\n",
8857 pm->logging_uuid, 8780 pm->logging_uuid,
8858 queue->address, 8781 queue->address,
8859 GNUNET_i2s (&n->pid), 8782 GNUNET_i2s(&n->pid),
8860 sc.consideration_counter); 8783 sc.consideration_counter);
8861 8784
8862 /* Flow control: increment amount of traffic sent; if we are routing 8785 /* Flow control: increment amount of traffic sent; if we are routing
@@ -8867,50 +8790,50 @@ transmit_on_queue (void *cls)
8867 pm->vl->outbound_fc_window_size_used += pm->bytes_msg; 8790 pm->vl->outbound_fc_window_size_used += pm->bytes_msg;
8868 8791
8869 if (pm->vl != queue->neighbour->vl) 8792 if (pm->vl != queue->neighbour->vl)
8870 { 8793 {
8871 /* If the virtual link of the queue differs, this better be distance 8794 /* If the virtual link of the queue differs, this better be distance
8872 vector routing! */ 8795 vector routing! */
8873 GNUNET_assert (NULL != sc.dvh); 8796 GNUNET_assert(NULL != sc.dvh);
8874 /* If we do distance vector routing, we better not do this for a 8797 /* If we do distance vector routing, we better not do this for a
8875 message that was itself DV-routed */ 8798 message that was itself DV-routed */
8876 GNUNET_assert (PMT_DV_BOX != sc.best->pmt); 8799 GNUNET_assert(PMT_DV_BOX != sc.best->pmt);
8877 /* We use the size of the unboxed message here, to avoid counting 8800 /* We use the size of the unboxed message here, to avoid counting
8878 the DV-Box header which is eaten up on the way by intermediaries */ 8801 the DV-Box header which is eaten up on the way by intermediaries */
8879 queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg; 8802 queue->neighbour->vl->outbound_fc_window_size_used += sc.best->bytes_msg;
8880 } 8803 }
8881 else 8804 else
8882 { 8805 {
8883 GNUNET_assert (NULL == sc.dvh); 8806 GNUNET_assert(NULL == sc.dvh);
8884 } 8807 }
8885 8808
8886 queue_send_msg (queue, pm, &pm[1], pm->bytes_msg); 8809 queue_send_msg(queue, pm, &pm[1], pm->bytes_msg);
8887 8810
8888 /* Check if this transmission somehow conclusively finished handing 'pm' 8811 /* Check if this transmission somehow conclusively finished handing 'pm'
8889 even without any explicit ACKs */ 8812 even without any explicit ACKs */
8890 if ((PMT_CORE == pm->pmt) || 8813 if ((PMT_CORE == pm->pmt) ||
8891 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)) 8814 (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc))
8892 { 8815 {
8893 completed_pending_message (pm); 8816 completed_pending_message(pm);
8894 } 8817 }
8895 else 8818 else
8896 { 8819 {
8897 /* Message not finished, waiting for acknowledgement. 8820 /* Message not finished, waiting for acknowledgement.
8898 Update time by which we might retransmit 's' based on queue 8821 Update time by which we might retransmit 's' based on queue
8899 characteristics (i.e. RTT); it takes one RTT for the message to 8822 characteristics (i.e. RTT); it takes one RTT for the message to
8900 arrive and the ACK to come back in the best case; but the other 8823 arrive and the ACK to come back in the best case; but the other
8901 side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before 8824 side is allowed to delay ACKs by 2 RTTs, so we use 4 RTT before
8902 retransmitting. 8825 retransmitting.
8903 8826
8904 OPTIMIZE: Note that in the future this heuristic should likely 8827 OPTIMIZE: Note that in the future this heuristic should likely
8905 be improved further (measure RTT stability, consider message 8828 be improved further (measure RTT stability, consider message
8906 urgency and size when delaying ACKs, etc.) */ 8829 urgency and size when delaying ACKs, etc.) */
8907 update_pm_next_attempt (pm, 8830 update_pm_next_attempt(pm,
8908 GNUNET_TIME_relative_to_absolute ( 8831 GNUNET_TIME_relative_to_absolute(
8909 GNUNET_TIME_relative_multiply (queue->pd.aged_rtt, 8832 GNUNET_TIME_relative_multiply(queue->pd.aged_rtt,
8910 4))); 8833 4)));
8911 } 8834 }
8912 /* finally, re-schedule queue transmission task itself */ 8835 /* finally, re-schedule queue transmission task itself */
8913 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8836 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
8914} 8837}
8915 8838
8916 8839
@@ -8921,35 +8844,35 @@ transmit_on_queue (void *cls)
8921 * @param dqm the send message that was sent 8844 * @param dqm the send message that was sent
8922 */ 8845 */
8923static void 8846static void
8924handle_del_queue_message (void *cls, 8847handle_del_queue_message(void *cls,
8925 const struct GNUNET_TRANSPORT_DelQueueMessage *dqm) 8848 const struct GNUNET_TRANSPORT_DelQueueMessage *dqm)
8926{ 8849{
8927 struct TransportClient *tc = cls; 8850 struct TransportClient *tc = cls;
8928 8851
8929 if (CT_COMMUNICATOR != tc->type) 8852 if (CT_COMMUNICATOR != tc->type)
8930 { 8853 {
8931 GNUNET_break (0); 8854 GNUNET_break(0);
8932 GNUNET_SERVICE_client_drop (tc->client); 8855 GNUNET_SERVICE_client_drop(tc->client);
8933 return; 8856 return;
8934 } 8857 }
8935 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; 8858 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
8936 queue = queue->next_client) 8859 queue = queue->next_client)
8937 { 8860 {
8938 struct Neighbour *neighbour = queue->neighbour; 8861 struct Neighbour *neighbour = queue->neighbour;
8939 8862
8940 if ((dqm->qid != queue->qid) || 8863 if ((dqm->qid != queue->qid) ||
8941 (0 != GNUNET_memcmp (&dqm->receiver, &neighbour->pid))) 8864 (0 != GNUNET_memcmp(&dqm->receiver, &neighbour->pid)))
8942 continue; 8865 continue;
8943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8866 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
8944 "Dropped queue %s to peer %s\n", 8867 "Dropped queue %s to peer %s\n",
8945 queue->address, 8868 queue->address,
8946 GNUNET_i2s (&neighbour->pid)); 8869 GNUNET_i2s(&neighbour->pid));
8947 free_queue (queue); 8870 free_queue(queue);
8948 GNUNET_SERVICE_client_continue (tc->client); 8871 GNUNET_SERVICE_client_continue(tc->client);
8949 return; 8872 return;
8950 } 8873 }
8951 GNUNET_break (0); 8874 GNUNET_break(0);
8952 GNUNET_SERVICE_client_drop (tc->client); 8875 GNUNET_SERVICE_client_drop(tc->client);
8953} 8876}
8954 8877
8955 8878
@@ -8960,97 +8883,97 @@ handle_del_queue_message (void *cls,
8960 * @param sma the send message that was sent 8883 * @param sma the send message that was sent
8961 */ 8884 */
8962static void 8885static void
8963handle_send_message_ack (void *cls, 8886handle_send_message_ack(void *cls,
8964 const struct GNUNET_TRANSPORT_SendMessageToAck *sma) 8887 const struct GNUNET_TRANSPORT_SendMessageToAck *sma)
8965{ 8888{
8966 struct TransportClient *tc = cls; 8889 struct TransportClient *tc = cls;
8967 struct QueueEntry *qe; 8890 struct QueueEntry *qe;
8968 struct PendingMessage *pm; 8891 struct PendingMessage *pm;
8969 8892
8970 if (CT_COMMUNICATOR != tc->type) 8893 if (CT_COMMUNICATOR != tc->type)
8971 { 8894 {
8972 GNUNET_break (0); 8895 GNUNET_break(0);
8973 GNUNET_SERVICE_client_drop (tc->client); 8896 GNUNET_SERVICE_client_drop(tc->client);
8974 return; 8897 return;
8975 } 8898 }
8976 8899
8977 /* find our queue entry matching the ACK */ 8900 /* find our queue entry matching the ACK */
8978 qe = NULL; 8901 qe = NULL;
8979 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue; 8902 for (struct Queue *queue = tc->details.communicator.queue_head; NULL != queue;
8980 queue = queue->next_client) 8903 queue = queue->next_client)
8981 {
8982 if (0 != GNUNET_memcmp (&queue->neighbour->pid, &sma->receiver))
8983 continue;
8984 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
8985 qep = qep->next)
8986 { 8904 {
8987 if (qep->mid != sma->mid) 8905 if (0 != GNUNET_memcmp(&queue->neighbour->pid, &sma->receiver))
8988 continue; 8906 continue;
8989 qe = qep; 8907 for (struct QueueEntry *qep = queue->queue_head; NULL != qep;
8908 qep = qep->next)
8909 {
8910 if (qep->mid != sma->mid)
8911 continue;
8912 qe = qep;
8913 break;
8914 }
8990 break; 8915 break;
8991 } 8916 }
8992 break;
8993 }
8994 if (NULL == qe) 8917 if (NULL == qe)
8995 { 8918 {
8996 /* this should never happen */ 8919 /* this should never happen */
8997 GNUNET_break (0); 8920 GNUNET_break(0);
8998 GNUNET_SERVICE_client_drop (tc->client); 8921 GNUNET_SERVICE_client_drop(tc->client);
8999 return; 8922 return;
9000 } 8923 }
9001 GNUNET_CONTAINER_DLL_remove (qe->queue->queue_head, 8924 GNUNET_CONTAINER_DLL_remove(qe->queue->queue_head,
9002 qe->queue->queue_tail, 8925 qe->queue->queue_tail,
9003 qe); 8926 qe);
9004 qe->queue->queue_length--; 8927 qe->queue->queue_length--;
9005 tc->details.communicator.total_queue_length--; 8928 tc->details.communicator.total_queue_length--;
9006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 8929 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9007 "Received ACK on queue %s to peer %s (new length: %u/%u)\n", 8930 "Received ACK on queue %s to peer %s (new length: %u/%u)\n",
9008 qe->queue->address, 8931 qe->queue->address,
9009 GNUNET_i2s (&qe->queue->neighbour->pid), 8932 GNUNET_i2s(&qe->queue->neighbour->pid),
9010 qe->queue->queue_length, 8933 qe->queue->queue_length,
9011 tc->details.communicator.total_queue_length); 8934 tc->details.communicator.total_queue_length);
9012 GNUNET_SERVICE_client_continue (tc->client); 8935 GNUNET_SERVICE_client_continue(tc->client);
9013 8936
9014 /* if applicable, resume transmissions that waited on ACK */ 8937 /* if applicable, resume transmissions that waited on ACK */
9015 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 == 8938 if (COMMUNICATOR_TOTAL_QUEUE_LIMIT - 1 ==
9016 tc->details.communicator.total_queue_length) 8939 tc->details.communicator.total_queue_length)
9017 { 8940 {
9018 /* Communicator dropped below threshold, resume all queues 8941 /* Communicator dropped below threshold, resume all queues
9019 incident with this client! */ 8942 incident with this client! */
9020 GNUNET_STATISTICS_update ( 8943 GNUNET_STATISTICS_update(
9021 GST_stats, 8944 GST_stats,
9022 "# Transmission throttled due to communicator queue limit", 8945 "# Transmission throttled due to communicator queue limit",
9023 -1, 8946 -1,
9024 GNUNET_NO); 8947 GNUNET_NO);
9025 for (struct Queue *queue = tc->details.communicator.queue_head; 8948 for (struct Queue *queue = tc->details.communicator.queue_head;
9026 NULL != queue; 8949 NULL != queue;
9027 queue = queue->next_client) 8950 queue = queue->next_client)
9028 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8951 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9029 } 8952 }
9030 else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length) 8953 else if (QUEUE_LENGTH_LIMIT - 1 == qe->queue->queue_length)
9031 { 8954 {
9032 /* queue dropped below threshold; only resume this one queue */ 8955 /* queue dropped below threshold; only resume this one queue */
9033 GNUNET_STATISTICS_update (GST_stats, 8956 GNUNET_STATISTICS_update(GST_stats,
9034 "# Transmission throttled due to queue queue limit", 8957 "# Transmission throttled due to queue queue limit",
9035 -1, 8958 -1,
9036 GNUNET_NO); 8959 GNUNET_NO);
9037 schedule_transmit_on_queue (qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 8960 schedule_transmit_on_queue(qe->queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9038 } 8961 }
9039 8962
9040 if (NULL != (pm = qe->pm)) 8963 if (NULL != (pm = qe->pm))
9041 { 8964 {
9042 struct VirtualLink *vl; 8965 struct VirtualLink *vl;
9043 8966
9044 GNUNET_assert (qe == pm->qe); 8967 GNUNET_assert(qe == pm->qe);
9045 pm->qe = NULL; 8968 pm->qe = NULL;
9046 /* If waiting for this communicator may have blocked transmission 8969 /* If waiting for this communicator may have blocked transmission
9047 of pm on other queues for this neighbour, force schedule 8970 of pm on other queues for this neighbour, force schedule
9048 transmit on queue for queues of the neighbour */ 8971 transmit on queue for queues of the neighbour */
9049 vl = pm->vl; 8972 vl = pm->vl;
9050 if (vl->pending_msg_head == pm) 8973 if (vl->pending_msg_head == pm)
9051 check_vl_transmission (vl); 8974 check_vl_transmission(vl);
9052 } 8975 }
9053 GNUNET_free (qe); 8976 GNUNET_free(qe);
9054} 8977}
9055 8978
9056 8979
@@ -9064,24 +8987,24 @@ handle_send_message_ack (void *cls,
9064 * @return #GNUNET_OK (continue to iterate) 8987 * @return #GNUNET_OK (continue to iterate)
9065 */ 8988 */
9066static int 8989static int
9067notify_client_queues (void *cls, 8990notify_client_queues(void *cls,
9068 const struct GNUNET_PeerIdentity *pid, 8991 const struct GNUNET_PeerIdentity *pid,
9069 void *value) 8992 void *value)
9070{ 8993{
9071 struct TransportClient *tc = cls; 8994 struct TransportClient *tc = cls;
9072 struct Neighbour *neighbour = value; 8995 struct Neighbour *neighbour = value;
9073 8996
9074 GNUNET_assert (CT_MONITOR == tc->type); 8997 GNUNET_assert(CT_MONITOR == tc->type);
9075 for (struct Queue *q = neighbour->queue_head; NULL != q; 8998 for (struct Queue *q = neighbour->queue_head; NULL != q;
9076 q = q->next_neighbour) 8999 q = q->next_neighbour)
9077 { 9000 {
9078 struct MonitorEvent me = {.rtt = q->pd.aged_rtt, 9001 struct MonitorEvent me = { .rtt = q->pd.aged_rtt,
9079 .cs = q->cs, 9002 .cs = q->cs,
9080 .num_msg_pending = q->num_msg_pending, 9003 .num_msg_pending = q->num_msg_pending,
9081 .num_bytes_pending = q->num_bytes_pending}; 9004 .num_bytes_pending = q->num_bytes_pending };
9082 9005
9083 notify_monitor (tc, pid, q->address, q->nt, &me); 9006 notify_monitor(tc, pid, q->address, q->nt, &me);
9084 } 9007 }
9085 return GNUNET_OK; 9008 return GNUNET_OK;
9086} 9009}
9087 9010
@@ -9093,23 +9016,23 @@ notify_client_queues (void *cls,
9093 * @param start the start message that was sent 9016 * @param start the start message that was sent
9094 */ 9017 */
9095static void 9018static void
9096handle_monitor_start (void *cls, 9019handle_monitor_start(void *cls,
9097 const struct GNUNET_TRANSPORT_MonitorStart *start) 9020 const struct GNUNET_TRANSPORT_MonitorStart *start)
9098{ 9021{
9099 struct TransportClient *tc = cls; 9022 struct TransportClient *tc = cls;
9100 9023
9101 if (CT_NONE != tc->type) 9024 if (CT_NONE != tc->type)
9102 { 9025 {
9103 GNUNET_break (0); 9026 GNUNET_break(0);
9104 GNUNET_SERVICE_client_drop (tc->client); 9027 GNUNET_SERVICE_client_drop(tc->client);
9105 return; 9028 return;
9106 } 9029 }
9107 tc->type = CT_MONITOR; 9030 tc->type = CT_MONITOR;
9108 tc->details.monitor.peer = start->peer; 9031 tc->details.monitor.peer = start->peer;
9109 tc->details.monitor.one_shot = ntohl (start->one_shot); 9032 tc->details.monitor.one_shot = ntohl(start->one_shot);
9110 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &notify_client_queues, tc); 9033 GNUNET_CONTAINER_multipeermap_iterate(neighbours, &notify_client_queues, tc);
9111 GNUNET_SERVICE_client_mark_monitor (tc->client); 9034 GNUNET_SERVICE_client_mark_monitor(tc->client);
9112 GNUNET_SERVICE_client_continue (tc->client); 9035 GNUNET_SERVICE_client_continue(tc->client);
9113} 9036}
9114 9037
9115 9038
@@ -9121,16 +9044,16 @@ handle_monitor_start (void *cls,
9121 * @return NULL if no such transport client is available 9044 * @return NULL if no such transport client is available
9122 */ 9045 */
9123static struct TransportClient * 9046static struct TransportClient *
9124lookup_communicator (const char *prefix) 9047lookup_communicator(const char *prefix)
9125{ 9048{
9126 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 9049 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
9127 { 9050 {
9128 if (CT_COMMUNICATOR != tc->type) 9051 if (CT_COMMUNICATOR != tc->type)
9129 continue; 9052 continue;
9130 if (0 == strcmp (prefix, tc->details.communicator.address_prefix)) 9053 if (0 == strcmp(prefix, tc->details.communicator.address_prefix))
9131 return tc; 9054 return tc;
9132 } 9055 }
9133 GNUNET_log ( 9056 GNUNET_log(
9134 GNUNET_ERROR_TYPE_WARNING, 9057 GNUNET_ERROR_TYPE_WARNING,
9135 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n", 9058 "Somone suggested use of communicator for `%s', but we do not have such a communicator!\n",
9136 prefix); 9059 prefix);
@@ -9146,7 +9069,7 @@ lookup_communicator (const char *prefix)
9146 * @param address the address to try 9069 * @param address the address to try
9147 */ 9070 */
9148static void 9071static void
9149suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address) 9072suggest_to_connect(const struct GNUNET_PeerIdentity *pid, const char *address)
9150{ 9073{
9151 static uint32_t idgen; 9074 static uint32_t idgen;
9152 struct TransportClient *tc; 9075 struct TransportClient *tc;
@@ -9155,40 +9078,40 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9155 struct GNUNET_MQ_Envelope *env; 9078 struct GNUNET_MQ_Envelope *env;
9156 size_t alen; 9079 size_t alen;
9157 9080
9158 prefix = GNUNET_HELLO_address_to_prefix (address); 9081 prefix = GNUNET_HELLO_address_to_prefix(address);
9159 if (NULL == prefix) 9082 if (NULL == prefix)
9160 { 9083 {
9161 GNUNET_break (0); /* We got an invalid address!? */ 9084 GNUNET_break(0); /* We got an invalid address!? */
9162 return; 9085 return;
9163 } 9086 }
9164 tc = lookup_communicator (prefix); 9087 tc = lookup_communicator(prefix);
9165 if (NULL == tc) 9088 if (NULL == tc)
9166 { 9089 {
9167 GNUNET_STATISTICS_update (GST_stats, 9090 GNUNET_STATISTICS_update(GST_stats,
9168 "# Suggestions ignored due to missing communicator", 9091 "# Suggestions ignored due to missing communicator",
9169 1, 9092 1,
9170 GNUNET_NO); 9093 GNUNET_NO);
9171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9094 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
9172 "Cannot connect to %s at `%s', no matching communicator present\n", 9095 "Cannot connect to %s at `%s', no matching communicator present\n",
9173 GNUNET_i2s (pid), 9096 GNUNET_i2s(pid),
9174 address); 9097 address);
9175 GNUNET_free (prefix); 9098 GNUNET_free(prefix);
9176 return; 9099 return;
9177 } 9100 }
9178 /* forward suggestion for queue creation to communicator */ 9101 /* forward suggestion for queue creation to communicator */
9179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9102 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9180 "Request #%u for `%s' communicator to create queue to `%s'\n", 9103 "Request #%u for `%s' communicator to create queue to `%s'\n",
9181 (unsigned int) idgen, 9104 (unsigned int)idgen,
9182 prefix, 9105 prefix,
9183 address); 9106 address);
9184 GNUNET_free (prefix); 9107 GNUNET_free(prefix);
9185 alen = strlen (address) + 1; 9108 alen = strlen(address) + 1;
9186 env = 9109 env =
9187 GNUNET_MQ_msg_extra (cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 9110 GNUNET_MQ_msg_extra(cqm, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
9188 cqm->request_id = htonl (idgen++); 9111 cqm->request_id = htonl(idgen++);
9189 cqm->receiver = *pid; 9112 cqm->receiver = *pid;
9190 memcpy (&cqm[1], address, alen); 9113 memcpy(&cqm[1], address, alen);
9191 GNUNET_MQ_send (tc->mq, env); 9114 GNUNET_MQ_send(tc->mq, env);
9192} 9115}
9193 9116
9194 9117
@@ -9200,22 +9123,22 @@ suggest_to_connect (const struct GNUNET_PeerIdentity *pid, const char *address)
9200 * @param vs state to derive validation challenge from 9123 * @param vs state to derive validation challenge from
9201 */ 9124 */
9202static void 9125static void
9203validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs) 9126validation_transmit_on_queue(struct Queue *q, struct ValidationState *vs)
9204{ 9127{
9205 struct TransportValidationChallengeMessage tvc; 9128 struct TransportValidationChallengeMessage tvc;
9206 9129
9207 vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic (GST_cfg); 9130 vs->last_challenge_use = GNUNET_TIME_absolute_get_monotonic(GST_cfg);
9208 tvc.header.type = 9131 tvc.header.type =
9209 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE); 9132 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_VALIDATION_CHALLENGE);
9210 tvc.header.size = htons (sizeof (tvc)); 9133 tvc.header.size = htons(sizeof(tvc));
9211 tvc.reserved = htonl (0); 9134 tvc.reserved = htonl(0);
9212 tvc.challenge = vs->challenge; 9135 tvc.challenge = vs->challenge;
9213 tvc.sender_time = GNUNET_TIME_absolute_hton (vs->last_challenge_use); 9136 tvc.sender_time = GNUNET_TIME_absolute_hton(vs->last_challenge_use);
9214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9137 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
9215 "Sending address validation challenge %s to %s\n", 9138 "Sending address validation challenge %s to %s\n",
9216 GNUNET_sh2s (&tvc.challenge.value), 9139 GNUNET_sh2s(&tvc.challenge.value),
9217 GNUNET_i2s (&q->neighbour->pid)); 9140 GNUNET_i2s(&q->neighbour->pid));
9218 queue_send_msg (q, NULL, &tvc, sizeof (tvc)); 9141 queue_send_msg(q, NULL, &tvc, sizeof(tvc));
9219} 9142}
9220 9143
9221 9144
@@ -9225,56 +9148,55 @@ validation_transmit_on_queue (struct Queue *q, struct ValidationState *vs)
9225 * @param cls NULL 9148 * @param cls NULL
9226 */ 9149 */
9227static void 9150static void
9228validation_start_cb (void *cls) 9151validation_start_cb(void *cls)
9229{ 9152{
9230 struct ValidationState *vs; 9153 struct ValidationState *vs;
9231 struct Queue *q; 9154 struct Queue *q;
9232 9155
9233 (void) cls; 9156 (void)cls;
9234 validation_task = NULL; 9157 validation_task = NULL;
9235 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 9158 vs = GNUNET_CONTAINER_heap_peek(validation_heap);
9236 /* drop validations past their expiration */ 9159 /* drop validations past their expiration */
9237 while ( 9160 while (
9238 (NULL != vs) && 9161 (NULL != vs) &&
9239 (0 == GNUNET_TIME_absolute_get_remaining (vs->valid_until).rel_value_us)) 9162 (0 == GNUNET_TIME_absolute_get_remaining(vs->valid_until).rel_value_us))
9240 { 9163 {
9241 free_validation_state (vs); 9164 free_validation_state(vs);
9242 vs = GNUNET_CONTAINER_heap_peek (validation_heap); 9165 vs = GNUNET_CONTAINER_heap_peek(validation_heap);
9243 } 9166 }
9244 if (NULL == vs) 9167 if (NULL == vs)
9245 { 9168 {
9246 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9169 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
9247 "Address validation task not scheduled anymore, nothing to do\n"); 9170 "Address validation task not scheduled anymore, nothing to do\n");
9248 return; /* woopsie, no more addresses known, should only 9171 return; /* woopsie, no more addresses known, should only
9249 happen if we're really a lonely peer */ 9172 happen if we're really a lonely peer */
9250 } 9173 }
9251 q = find_queue (&vs->pid, vs->address); 9174 q = find_queue(&vs->pid, vs->address);
9252 if (NULL == q) 9175 if (NULL == q)
9253 { 9176 {
9254 vs->awaiting_queue = GNUNET_YES; 9177 vs->awaiting_queue = GNUNET_YES;
9255 suggest_to_connect (&vs->pid, vs->address); 9178 suggest_to_connect(&vs->pid, vs->address);
9256 } 9179 }
9257 else 9180 else
9258 validation_transmit_on_queue (q, vs); 9181 validation_transmit_on_queue(q, vs);
9259 /* Finally, reschedule next attempt */ 9182 /* Finally, reschedule next attempt */
9260 vs->challenge_backoff = 9183 vs->challenge_backoff =
9261 GNUNET_TIME_randomized_backoff (vs->challenge_backoff, 9184 GNUNET_TIME_randomized_backoff(vs->challenge_backoff,
9262 MAX_VALIDATION_CHALLENGE_FREQ); 9185 MAX_VALIDATION_CHALLENGE_FREQ);
9263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9186 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9264 "Address validation task will run again in %s\n", 9187 "Address validation task will run again in %s\n",
9265 GNUNET_STRINGS_relative_time_to_string (vs->challenge_backoff, 9188 GNUNET_STRINGS_relative_time_to_string(vs->challenge_backoff,
9266 GNUNET_YES)); 9189 GNUNET_YES));
9267 update_next_challenge_time (vs, 9190 update_next_challenge_time(vs,
9268 GNUNET_TIME_relative_to_absolute ( 9191 GNUNET_TIME_relative_to_absolute(
9269 vs->challenge_backoff)); 9192 vs->challenge_backoff));
9270} 9193}
9271 9194
9272 9195
9273/** 9196/**
9274 * Closure for #check_connection_quality. 9197 * Closure for #check_connection_quality.
9275 */ 9198 */
9276struct QueueQualityContext 9199struct QueueQualityContext {
9277{
9278 /** 9200 /**
9279 * Set to the @e k'th queue encountered. 9201 * Set to the @e k'th queue encountered.
9280 */ 9202 */
@@ -9310,26 +9232,26 @@ struct QueueQualityContext
9310 * @return #GNUNET_OK (continue to iterate) 9232 * @return #GNUNET_OK (continue to iterate)
9311 */ 9233 */
9312static int 9234static int
9313check_connection_quality (void *cls, 9235check_connection_quality(void *cls,
9314 const struct GNUNET_PeerIdentity *pid, 9236 const struct GNUNET_PeerIdentity *pid,
9315 void *value) 9237 void *value)
9316{ 9238{
9317 struct QueueQualityContext *ctx = cls; 9239 struct QueueQualityContext *ctx = cls;
9318 struct Neighbour *n = value; 9240 struct Neighbour *n = value;
9319 int do_inc; 9241 int do_inc;
9320 9242
9321 (void) pid; 9243 (void)pid;
9322 do_inc = GNUNET_NO; 9244 do_inc = GNUNET_NO;
9323 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour) 9245 for (struct Queue *q = n->queue_head; NULL != q; q = q->next_neighbour)
9324 { 9246 {
9325 ctx->num_queues++; 9247 ctx->num_queues++;
9326 if (0 == ctx->k--) 9248 if (0 == ctx->k--)
9327 ctx->q = q; 9249 ctx->q = q;
9328 /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput 9250 /* FIXME-CONQ-STATISTICS: in the future, add reliability / goodput
9329 statistics and consider those as well here? */ 9251 statistics and consider those as well here? */
9330 if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us) 9252 if (q->pd.aged_rtt.rel_value_us < DV_QUALITY_RTT_THRESHOLD.rel_value_us)
9331 do_inc = GNUNET_YES; 9253 do_inc = GNUNET_YES;
9332 } 9254 }
9333 if (GNUNET_YES == do_inc) 9255 if (GNUNET_YES == do_inc)
9334 ctx->quality_count++; 9256 ctx->quality_count++;
9335 return GNUNET_OK; 9257 return GNUNET_OK;
@@ -9348,103 +9270,103 @@ check_connection_quality (void *cls,
9348 * @param cls NULL 9270 * @param cls NULL
9349 */ 9271 */
9350static void 9272static void
9351start_dv_learn (void *cls) 9273start_dv_learn(void *cls)
9352{ 9274{
9353 struct LearnLaunchEntry *lle; 9275 struct LearnLaunchEntry *lle;
9354 struct QueueQualityContext qqc; 9276 struct QueueQualityContext qqc;
9355 struct TransportDVLearnMessage dvl; 9277 struct TransportDVLearnMessage dvl;
9356 9278
9357 (void) cls; 9279 (void)cls;
9358 dvlearn_task = NULL; 9280 dvlearn_task = NULL;
9359 if (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)) 9281 if (0 == GNUNET_CONTAINER_multipeermap_size(neighbours))
9360 return; /* lost all connectivity, cannot do learning */ 9282 return; /* lost all connectivity, cannot do learning */
9361 qqc.quality_count = 0; 9283 qqc.quality_count = 0;
9362 qqc.num_queues = 0; 9284 qqc.num_queues = 0;
9363 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 9285 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
9364 &check_connection_quality, 9286 &check_connection_quality,
9365 &qqc); 9287 &qqc);
9366 if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD) 9288 if (qqc.quality_count > DV_LEARN_QUALITY_THRESHOLD)
9367 { 9289 {
9368 struct GNUNET_TIME_Relative delay; 9290 struct GNUNET_TIME_Relative delay;
9369 unsigned int factor; 9291 unsigned int factor;
9370 9292
9371 /* scale our retries by how far we are above the threshold */ 9293 /* scale our retries by how far we are above the threshold */
9372 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD; 9294 factor = qqc.quality_count / DV_LEARN_QUALITY_THRESHOLD;
9373 delay = GNUNET_TIME_relative_multiply (DV_LEARN_BASE_FREQUENCY, factor); 9295 delay = GNUNET_TIME_relative_multiply(DV_LEARN_BASE_FREQUENCY, factor);
9374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9296 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9375 "At connection quality %u, will launch DV learn in %s\n", 9297 "At connection quality %u, will launch DV learn in %s\n",
9376 qqc.quality_count, 9298 qqc.quality_count,
9377 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 9299 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
9378 dvlearn_task = GNUNET_SCHEDULER_add_delayed (delay, &start_dv_learn, NULL); 9300 dvlearn_task = GNUNET_SCHEDULER_add_delayed(delay, &start_dv_learn, NULL);
9379 return; 9301 return;
9380 } 9302 }
9381 /* remove old entries in #dvlearn_map if it has grown too big */ 9303 /* remove old entries in #dvlearn_map if it has grown too big */
9382 while (MAX_DV_LEARN_PENDING >= 9304 while (MAX_DV_LEARN_PENDING >=
9383 GNUNET_CONTAINER_multishortmap_size (dvlearn_map)) 9305 GNUNET_CONTAINER_multishortmap_size(dvlearn_map))
9384 { 9306 {
9385 lle = lle_tail; 9307 lle = lle_tail;
9386 GNUNET_assert (GNUNET_YES == 9308 GNUNET_assert(GNUNET_YES ==
9387 GNUNET_CONTAINER_multishortmap_remove (dvlearn_map, 9309 GNUNET_CONTAINER_multishortmap_remove(dvlearn_map,
9388 &lle->challenge.value, 9310 &lle->challenge.value,
9389 lle)); 9311 lle));
9390 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); 9312 GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle);
9391 GNUNET_free (lle); 9313 GNUNET_free(lle);
9392 } 9314 }
9393 /* setup data structure for learning */ 9315 /* setup data structure for learning */
9394 lle = GNUNET_new (struct LearnLaunchEntry); 9316 lle = GNUNET_new(struct LearnLaunchEntry);
9395 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, 9317 GNUNET_CRYPTO_random_block(GNUNET_CRYPTO_QUALITY_NONCE,
9396 &lle->challenge, 9318 &lle->challenge,
9397 sizeof (lle->challenge)); 9319 sizeof(lle->challenge));
9398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9399 "Starting launch DV learn with challenge %s\n", 9321 "Starting launch DV learn with challenge %s\n",
9400 GNUNET_sh2s (&lle->challenge.value)); 9322 GNUNET_sh2s(&lle->challenge.value));
9401 GNUNET_CONTAINER_DLL_insert (lle_head, lle_tail, lle); 9323 GNUNET_CONTAINER_DLL_insert(lle_head, lle_tail, lle);
9402 GNUNET_break (GNUNET_YES == 9324 GNUNET_break(GNUNET_YES ==
9403 GNUNET_CONTAINER_multishortmap_put ( 9325 GNUNET_CONTAINER_multishortmap_put(
9404 dvlearn_map, 9326 dvlearn_map,
9405 &lle->challenge.value, 9327 &lle->challenge.value,
9406 lle, 9328 lle,
9407 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9329 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9408 dvl.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN); 9330 dvl.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_LEARN);
9409 dvl.header.size = htons (sizeof (dvl)); 9331 dvl.header.size = htons(sizeof(dvl));
9410 dvl.num_hops = htons (0); 9332 dvl.num_hops = htons(0);
9411 dvl.bidirectional = htons (0); 9333 dvl.bidirectional = htons(0);
9412 dvl.non_network_delay = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_ZERO); 9334 dvl.non_network_delay = GNUNET_TIME_relative_hton(GNUNET_TIME_UNIT_ZERO);
9413 dvl.monotonic_time = 9335 dvl.monotonic_time =
9414 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get_monotonic (GST_cfg)); 9336 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get_monotonic(GST_cfg));
9415 { 9337 {
9416 struct DvInitPS dvip = {.purpose.purpose = htonl ( 9338 struct DvInitPS dvip = { .purpose.purpose = htonl(
9417 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR), 9339 GNUNET_SIGNATURE_PURPOSE_TRANSPORT_DV_INITIATOR),
9418 .purpose.size = htonl (sizeof (dvip)), 9340 .purpose.size = htonl(sizeof(dvip)),
9419 .monotonic_time = dvl.monotonic_time, 9341 .monotonic_time = dvl.monotonic_time,
9420 .challenge = lle->challenge}; 9342 .challenge = lle->challenge };
9421 9343
9422 GNUNET_assert (GNUNET_OK == GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 9344 GNUNET_assert(GNUNET_OK == GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
9423 &dvip.purpose, 9345 &dvip.purpose,
9424 &dvl.init_sig)); 9346 &dvl.init_sig));
9425 } 9347 }
9426 dvl.initiator = GST_my_identity; 9348 dvl.initiator = GST_my_identity;
9427 dvl.challenge = lle->challenge; 9349 dvl.challenge = lle->challenge;
9428 9350
9429 qqc.quality_count = 0; 9351 qqc.quality_count = 0;
9430 qqc.k = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues); 9352 qqc.k = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, qqc.num_queues);
9431 qqc.num_queues = 0; 9353 qqc.num_queues = 0;
9432 qqc.q = NULL; 9354 qqc.q = NULL;
9433 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 9355 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
9434 &check_connection_quality, 9356 &check_connection_quality,
9435 &qqc); 9357 &qqc);
9436 GNUNET_assert (NULL != qqc.q); 9358 GNUNET_assert(NULL != qqc.q);
9437 9359
9438 /* Do this as close to transmission time as possible! */ 9360 /* Do this as close to transmission time as possible! */
9439 lle->launch_time = GNUNET_TIME_absolute_get (); 9361 lle->launch_time = GNUNET_TIME_absolute_get();
9440 9362
9441 queue_send_msg (qqc.q, NULL, &dvl, sizeof (dvl)); 9363 queue_send_msg(qqc.q, NULL, &dvl, sizeof(dvl));
9442 /* reschedule this job, randomizing the time it runs (but no 9364 /* reschedule this job, randomizing the time it runs (but no
9443 actual backoff!) */ 9365 actual backoff!) */
9444 dvlearn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_randomize ( 9366 dvlearn_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_randomize(
9445 DV_LEARN_BASE_FREQUENCY), 9367 DV_LEARN_BASE_FREQUENCY),
9446 &start_dv_learn, 9368 &start_dv_learn,
9447 NULL); 9369 NULL);
9448} 9370}
9449 9371
9450 9372
@@ -9458,21 +9380,21 @@ start_dv_learn (void *cls)
9458 * @return #GNUNET_NO if a match was found and we can stop looking 9380 * @return #GNUNET_NO if a match was found and we can stop looking
9459 */ 9381 */
9460static int 9382static int
9461check_validation_request_pending (void *cls, 9383check_validation_request_pending(void *cls,
9462 const struct GNUNET_PeerIdentity *pid, 9384 const struct GNUNET_PeerIdentity *pid,
9463 void *value) 9385 void *value)
9464{ 9386{
9465 struct Queue *q = cls; 9387 struct Queue *q = cls;
9466 struct ValidationState *vs = value; 9388 struct ValidationState *vs = value;
9467 9389
9468 (void) pid; 9390 (void)pid;
9469 if ((GNUNET_YES == vs->awaiting_queue) && 9391 if ((GNUNET_YES == vs->awaiting_queue) &&
9470 (0 == strcmp (vs->address, q->address))) 9392 (0 == strcmp(vs->address, q->address)))
9471 { 9393 {
9472 vs->awaiting_queue = GNUNET_NO; 9394 vs->awaiting_queue = GNUNET_NO;
9473 validation_transmit_on_queue (q, vs); 9395 validation_transmit_on_queue(q, vs);
9474 return GNUNET_NO; 9396 return GNUNET_NO;
9475 } 9397 }
9476 return GNUNET_OK; 9398 return GNUNET_OK;
9477} 9399}
9478 9400
@@ -9486,31 +9408,31 @@ check_validation_request_pending (void *cls,
9486 * @param emsg error message 9408 * @param emsg error message
9487 */ 9409 */
9488static void 9410static void
9489neighbour_dv_monotime_cb (void *cls, 9411neighbour_dv_monotime_cb(void *cls,
9490 const struct GNUNET_PEERSTORE_Record *record, 9412 const struct GNUNET_PEERSTORE_Record *record,
9491 const char *emsg) 9413 const char *emsg)
9492{ 9414{
9493 struct Neighbour *n = cls; 9415 struct Neighbour *n = cls;
9494 struct GNUNET_TIME_AbsoluteNBO *mtbe; 9416 struct GNUNET_TIME_AbsoluteNBO *mtbe;
9495 9417
9496 (void) emsg; 9418 (void)emsg;
9497 if (NULL == record) 9419 if (NULL == record)
9498 { 9420 {
9499 /* we're done with #neighbour_dv_monotime_cb() invocations, 9421 /* we're done with #neighbour_dv_monotime_cb() invocations,
9500 continue normal processing */ 9422 continue normal processing */
9501 n->get = NULL; 9423 n->get = NULL;
9502 n->dv_monotime_available = GNUNET_YES; 9424 n->dv_monotime_available = GNUNET_YES;
9503 return; 9425 return;
9504 } 9426 }
9505 if (sizeof (*mtbe) != record->value_size) 9427 if (sizeof(*mtbe) != record->value_size)
9506 { 9428 {
9507 GNUNET_break (0); 9429 GNUNET_break(0);
9508 return; 9430 return;
9509 } 9431 }
9510 mtbe = record->value; 9432 mtbe = record->value;
9511 n->last_dv_learn_monotime = 9433 n->last_dv_learn_monotime =
9512 GNUNET_TIME_absolute_max (n->last_dv_learn_monotime, 9434 GNUNET_TIME_absolute_max(n->last_dv_learn_monotime,
9513 GNUNET_TIME_absolute_ntoh (*mtbe)); 9435 GNUNET_TIME_absolute_ntoh(*mtbe));
9514} 9436}
9515 9437
9516 9438
@@ -9521,8 +9443,8 @@ neighbour_dv_monotime_cb (void *cls,
9521 * @param aqm the send message that was sent 9443 * @param aqm the send message that was sent
9522 */ 9444 */
9523static void 9445static void
9524handle_add_queue_message (void *cls, 9446handle_add_queue_message(void *cls,
9525 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 9447 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
9526{ 9448{
9527 struct TransportClient *tc = cls; 9449 struct TransportClient *tc = cls;
9528 struct Queue *queue; 9450 struct Queue *queue;
@@ -9530,77 +9452,77 @@ handle_add_queue_message (void *cls,
9530 const char *addr; 9452 const char *addr;
9531 uint16_t addr_len; 9453 uint16_t addr_len;
9532 9454
9533 if (ntohl (aqm->mtu) <= sizeof (struct TransportFragmentBoxMessage)) 9455 if (ntohl(aqm->mtu) <= sizeof(struct TransportFragmentBoxMessage))
9534 { 9456 {
9535 /* MTU so small as to be useless for transmissions, 9457 /* MTU so small as to be useless for transmissions,
9536 required for #fragment_message()! */ 9458 required for #fragment_message()! */
9537 GNUNET_break_op (0); 9459 GNUNET_break_op(0);
9538 GNUNET_SERVICE_client_drop (tc->client); 9460 GNUNET_SERVICE_client_drop(tc->client);
9539 return; 9461 return;
9540 } 9462 }
9541 neighbour = lookup_neighbour (&aqm->receiver); 9463 neighbour = lookup_neighbour(&aqm->receiver);
9542 if (NULL == neighbour) 9464 if (NULL == neighbour)
9543 { 9465 {
9544 neighbour = GNUNET_new (struct Neighbour); 9466 neighbour = GNUNET_new(struct Neighbour);
9545 neighbour->pid = aqm->receiver; 9467 neighbour->pid = aqm->receiver;
9546 GNUNET_assert (GNUNET_OK == 9468 GNUNET_assert(GNUNET_OK ==
9547 GNUNET_CONTAINER_multipeermap_put ( 9469 GNUNET_CONTAINER_multipeermap_put(
9548 neighbours, 9470 neighbours,
9549 &neighbour->pid, 9471 &neighbour->pid,
9550 neighbour, 9472 neighbour,
9551 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 9473 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
9552 neighbour->get = 9474 neighbour->get =
9553 GNUNET_PEERSTORE_iterate (peerstore, 9475 GNUNET_PEERSTORE_iterate(peerstore,
9554 "transport", 9476 "transport",
9555 &neighbour->pid, 9477 &neighbour->pid,
9556 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME, 9478 GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME,
9557 &neighbour_dv_monotime_cb, 9479 &neighbour_dv_monotime_cb,
9558 neighbour); 9480 neighbour);
9559 } 9481 }
9560 addr_len = ntohs (aqm->header.size) - sizeof (*aqm); 9482 addr_len = ntohs(aqm->header.size) - sizeof(*aqm);
9561 addr = (const char *) &aqm[1]; 9483 addr = (const char *)&aqm[1];
9562 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9484 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9563 "New queue %s to %s available with QID %llu\n", 9485 "New queue %s to %s available with QID %llu\n",
9564 addr, 9486 addr,
9565 GNUNET_i2s (&aqm->receiver), 9487 GNUNET_i2s(&aqm->receiver),
9566 (unsigned long long) aqm->qid); 9488 (unsigned long long)aqm->qid);
9567 queue = GNUNET_malloc (sizeof (struct Queue) + addr_len); 9489 queue = GNUNET_malloc(sizeof(struct Queue) + addr_len);
9568 queue->tc = tc; 9490 queue->tc = tc;
9569 queue->address = (const char *) &queue[1]; 9491 queue->address = (const char *)&queue[1];
9570 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL; 9492 queue->pd.aged_rtt = GNUNET_TIME_UNIT_FOREVER_REL;
9571 queue->qid = aqm->qid; 9493 queue->qid = aqm->qid;
9572 queue->mtu = ntohl (aqm->mtu); 9494 queue->mtu = ntohl(aqm->mtu);
9573 queue->nt = (enum GNUNET_NetworkType) ntohl (aqm->nt); 9495 queue->nt = (enum GNUNET_NetworkType)ntohl(aqm->nt);
9574 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (aqm->cs); 9496 queue->cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(aqm->cs);
9575 queue->neighbour = neighbour; 9497 queue->neighbour = neighbour;
9576 queue->idle = GNUNET_YES; 9498 queue->idle = GNUNET_YES;
9577 memcpy (&queue[1], addr, addr_len); 9499 memcpy(&queue[1], addr, addr_len);
9578 /* notify monitors about new queue */ 9500 /* notify monitors about new queue */
9579 { 9501 {
9580 struct MonitorEvent me = {.rtt = queue->pd.aged_rtt, .cs = queue->cs}; 9502 struct MonitorEvent me = { .rtt = queue->pd.aged_rtt, .cs = queue->cs };
9581 9503
9582 notify_monitors (&neighbour->pid, queue->address, queue->nt, &me); 9504 notify_monitors(&neighbour->pid, queue->address, queue->nt, &me);
9583 } 9505 }
9584 GNUNET_CONTAINER_MDLL_insert (neighbour, 9506 GNUNET_CONTAINER_MDLL_insert(neighbour,
9585 neighbour->queue_head, 9507 neighbour->queue_head,
9586 neighbour->queue_tail, 9508 neighbour->queue_tail,
9587 queue); 9509 queue);
9588 GNUNET_CONTAINER_MDLL_insert (client, 9510 GNUNET_CONTAINER_MDLL_insert(client,
9589 tc->details.communicator.queue_head, 9511 tc->details.communicator.queue_head,
9590 tc->details.communicator.queue_tail, 9512 tc->details.communicator.queue_tail,
9591 queue); 9513 queue);
9592 /* check if valdiations are waiting for the queue */ 9514 /* check if valdiations are waiting for the queue */
9593 (void) 9515 (void)
9594 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 9516 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
9595 &aqm->receiver, 9517 &aqm->receiver,
9596 &check_validation_request_pending, 9518 &check_validation_request_pending,
9597 queue); 9519 queue);
9598 /* look for traffic for this queue */ 9520 /* look for traffic for this queue */
9599 schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT); 9521 schedule_transmit_on_queue(queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
9600 /* might be our first queue, try launching DV learning */ 9522 /* might be our first queue, try launching DV learning */
9601 if (NULL == dvlearn_task) 9523 if (NULL == dvlearn_task)
9602 dvlearn_task = GNUNET_SCHEDULER_add_now (&start_dv_learn, NULL); 9524 dvlearn_task = GNUNET_SCHEDULER_add_now(&start_dv_learn, NULL);
9603 GNUNET_SERVICE_client_continue (tc->client); 9525 GNUNET_SERVICE_client_continue(tc->client);
9604} 9526}
9605 9527
9606 9528
@@ -9612,25 +9534,25 @@ handle_add_queue_message (void *cls,
9612 * @param cqr confirmation message 9534 * @param cqr confirmation message
9613 */ 9535 */
9614static void 9536static void
9615handle_queue_create_ok (void *cls, 9537handle_queue_create_ok(void *cls,
9616 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 9538 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
9617{ 9539{
9618 struct TransportClient *tc = cls; 9540 struct TransportClient *tc = cls;
9619 9541
9620 if (CT_COMMUNICATOR != tc->type) 9542 if (CT_COMMUNICATOR != tc->type)
9621 { 9543 {
9622 GNUNET_break (0); 9544 GNUNET_break(0);
9623 GNUNET_SERVICE_client_drop (tc->client); 9545 GNUNET_SERVICE_client_drop(tc->client);
9624 return; 9546 return;
9625 } 9547 }
9626 GNUNET_STATISTICS_update (GST_stats, 9548 GNUNET_STATISTICS_update(GST_stats,
9627 "# Suggestions succeeded at communicator", 9549 "# Suggestions succeeded at communicator",
9628 1, 9550 1,
9629 GNUNET_NO); 9551 GNUNET_NO);
9630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9552 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9631 "Request #%u for communicator to create queue succeeded\n", 9553 "Request #%u for communicator to create queue succeeded\n",
9632 (unsigned int) ntohs (cqr->request_id)); 9554 (unsigned int)ntohs(cqr->request_id));
9633 GNUNET_SERVICE_client_continue (tc->client); 9555 GNUNET_SERVICE_client_continue(tc->client);
9634} 9556}
9635 9557
9636 9558
@@ -9643,26 +9565,26 @@ handle_queue_create_ok (void *cls,
9643 * @param cqr failure message 9565 * @param cqr failure message
9644 */ 9566 */
9645static void 9567static void
9646handle_queue_create_fail ( 9568handle_queue_create_fail(
9647 void *cls, 9569 void *cls,
9648 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr) 9570 const struct GNUNET_TRANSPORT_CreateQueueResponse *cqr)
9649{ 9571{
9650 struct TransportClient *tc = cls; 9572 struct TransportClient *tc = cls;
9651 9573
9652 if (CT_COMMUNICATOR != tc->type) 9574 if (CT_COMMUNICATOR != tc->type)
9653 { 9575 {
9654 GNUNET_break (0); 9576 GNUNET_break(0);
9655 GNUNET_SERVICE_client_drop (tc->client); 9577 GNUNET_SERVICE_client_drop(tc->client);
9656 return; 9578 return;
9657 } 9579 }
9658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9580 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9659 "Request #%u for communicator to create queue failed\n", 9581 "Request #%u for communicator to create queue failed\n",
9660 (unsigned int) ntohs (cqr->request_id)); 9582 (unsigned int)ntohs(cqr->request_id));
9661 GNUNET_STATISTICS_update (GST_stats, 9583 GNUNET_STATISTICS_update(GST_stats,
9662 "# Suggestions failed in queue creation at communicator", 9584 "# Suggestions failed in queue creation at communicator",
9663 1, 9585 1,
9664 GNUNET_NO); 9586 GNUNET_NO);
9665 GNUNET_SERVICE_client_continue (tc->client); 9587 GNUNET_SERVICE_client_continue(tc->client);
9666} 9588}
9667 9589
9668 9590
@@ -9674,27 +9596,27 @@ handle_queue_create_fail (
9674 * @param msg the start message 9596 * @param msg the start message
9675 */ 9597 */
9676static void 9598static void
9677handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) 9599handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg)
9678{ 9600{
9679 struct TransportClient *tc = cls; 9601 struct TransportClient *tc = cls;
9680 struct PeerRequest *pr; 9602 struct PeerRequest *pr;
9681 9603
9682 if (CT_APPLICATION != tc->type) 9604 if (CT_APPLICATION != tc->type)
9683 { 9605 {
9684 GNUNET_break (0); 9606 GNUNET_break(0);
9685 GNUNET_SERVICE_client_drop (tc->client); 9607 GNUNET_SERVICE_client_drop(tc->client);
9686 return; 9608 return;
9687 } 9609 }
9688 pr = GNUNET_CONTAINER_multipeermap_get (tc->details.application.requests, 9610 pr = GNUNET_CONTAINER_multipeermap_get(tc->details.application.requests,
9689 &msg->peer); 9611 &msg->peer);
9690 if (NULL == pr) 9612 if (NULL == pr)
9691 { 9613 {
9692 GNUNET_break (0); 9614 GNUNET_break(0);
9693 GNUNET_SERVICE_client_drop (tc->client); 9615 GNUNET_SERVICE_client_drop(tc->client);
9694 return; 9616 return;
9695 } 9617 }
9696 (void) stop_peer_request (tc, &pr->pid, pr); 9618 (void)stop_peer_request(tc, &pr->pid, pr);
9697 GNUNET_SERVICE_client_continue (tc->client); 9619 GNUNET_SERVICE_client_continue(tc->client);
9698} 9620}
9699 9621
9700 9622
@@ -9706,27 +9628,27 @@ handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg)
9706 * @param emsg error message, or NULL if no errors 9628 * @param emsg error message, or NULL if no errors
9707 */ 9629 */
9708static void 9630static void
9709handle_hello_for_client (void *cls, 9631handle_hello_for_client(void *cls,
9710 const struct GNUNET_PEERSTORE_Record *record, 9632 const struct GNUNET_PEERSTORE_Record *record,
9711 const char *emsg) 9633 const char *emsg)
9712{ 9634{
9713 struct PeerRequest *pr = cls; 9635 struct PeerRequest *pr = cls;
9714 const char *val; 9636 const char *val;
9715 9637
9716 if (NULL != emsg) 9638 if (NULL != emsg)
9717 { 9639 {
9718 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 9640 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
9719 "Got failure from PEERSTORE: %s\n", 9641 "Got failure from PEERSTORE: %s\n",
9720 emsg); 9642 emsg);
9721 return; 9643 return;
9722 } 9644 }
9723 val = record->value; 9645 val = record->value;
9724 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) 9646 if ((0 == record->value_size) || ('\0' != val[record->value_size - 1]))
9725 { 9647 {
9726 GNUNET_break (0); 9648 GNUNET_break(0);
9727 return; 9649 return;
9728 } 9650 }
9729 start_address_validation (&pr->pid, (const char *) record->value); 9651 start_address_validation(&pr->pid, (const char *)record->value);
9730} 9652}
9731 9653
9732 9654
@@ -9738,51 +9660,51 @@ handle_hello_for_client (void *cls,
9738 * @param msg the start message 9660 * @param msg the start message
9739 */ 9661 */
9740static void 9662static void
9741handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) 9663handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg)
9742{ 9664{
9743 struct TransportClient *tc = cls; 9665 struct TransportClient *tc = cls;
9744 struct PeerRequest *pr; 9666 struct PeerRequest *pr;
9745 9667
9746 if (CT_NONE == tc->type) 9668 if (CT_NONE == tc->type)
9747 { 9669 {
9748 tc->type = CT_APPLICATION; 9670 tc->type = CT_APPLICATION;
9749 tc->details.application.requests = 9671 tc->details.application.requests =
9750 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); 9672 GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES);
9751 } 9673 }
9752 if (CT_APPLICATION != tc->type) 9674 if (CT_APPLICATION != tc->type)
9753 { 9675 {
9754 GNUNET_break (0); 9676 GNUNET_break(0);
9755 GNUNET_SERVICE_client_drop (tc->client); 9677 GNUNET_SERVICE_client_drop(tc->client);
9756 return; 9678 return;
9757 } 9679 }
9758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 9680 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
9759 "Client suggested we talk to %s with preference %d at rate %u\n", 9681 "Client suggested we talk to %s with preference %d at rate %u\n",
9760 GNUNET_i2s (&msg->peer), 9682 GNUNET_i2s(&msg->peer),
9761 (int) ntohl (msg->pk), 9683 (int)ntohl(msg->pk),
9762 (int) ntohl (msg->bw.value__)); 9684 (int)ntohl(msg->bw.value__));
9763 pr = GNUNET_new (struct PeerRequest); 9685 pr = GNUNET_new(struct PeerRequest);
9764 pr->tc = tc; 9686 pr->tc = tc;
9765 pr->pid = msg->peer; 9687 pr->pid = msg->peer;
9766 pr->bw = msg->bw; 9688 pr->bw = msg->bw;
9767 pr->pk = (enum GNUNET_MQ_PriorityPreferences) ntohl (msg->pk); 9689 pr->pk = (enum GNUNET_MQ_PriorityPreferences)ntohl(msg->pk);
9768 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put ( 9690 if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_put(
9769 tc->details.application.requests, 9691 tc->details.application.requests,
9770 &pr->pid, 9692 &pr->pid,
9771 pr, 9693 pr,
9772 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 9694 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
9773 { 9695 {
9774 GNUNET_break (0); 9696 GNUNET_break(0);
9775 GNUNET_free (pr); 9697 GNUNET_free(pr);
9776 GNUNET_SERVICE_client_drop (tc->client); 9698 GNUNET_SERVICE_client_drop(tc->client);
9777 return; 9699 return;
9778 } 9700 }
9779 pr->wc = GNUNET_PEERSTORE_watch (peerstore, 9701 pr->wc = GNUNET_PEERSTORE_watch(peerstore,
9780 "transport", 9702 "transport",
9781 &pr->pid, 9703 &pr->pid,
9782 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY, 9704 GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
9783 &handle_hello_for_client, 9705 &handle_hello_for_client,
9784 pr); 9706 pr);
9785 GNUNET_SERVICE_client_continue (tc->client); 9707 GNUNET_SERVICE_client_continue(tc->client);
9786} 9708}
9787 9709
9788 9710
@@ -9795,11 +9717,11 @@ handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg)
9795 * @return #GNUNET_OK on success 9717 * @return #GNUNET_OK on success
9796 */ 9718 */
9797static int 9719static int
9798check_request_hello_validation (void *cls, 9720check_request_hello_validation(void *cls,
9799 const struct RequestHelloValidationMessage *m) 9721 const struct RequestHelloValidationMessage *m)
9800{ 9722{
9801 (void) cls; 9723 (void)cls;
9802 GNUNET_MQ_check_zero_termination (m); 9724 GNUNET_MQ_check_zero_termination(m);
9803 return GNUNET_OK; 9725 return GNUNET_OK;
9804} 9726}
9805 9727
@@ -9812,13 +9734,13 @@ check_request_hello_validation (void *cls,
9812 * @param m message to verify 9734 * @param m message to verify
9813 */ 9735 */
9814static void 9736static void
9815handle_request_hello_validation (void *cls, 9737handle_request_hello_validation(void *cls,
9816 const struct RequestHelloValidationMessage *m) 9738 const struct RequestHelloValidationMessage *m)
9817{ 9739{
9818 struct TransportClient *tc = cls; 9740 struct TransportClient *tc = cls;
9819 9741
9820 start_address_validation (&m->peer, (const char *) &m[1]); 9742 start_address_validation(&m->peer, (const char *)&m[1]);
9821 GNUNET_SERVICE_client_continue (tc->client); 9743 GNUNET_SERVICE_client_continue(tc->client);
9822} 9744}
9823 9745
9824 9746
@@ -9831,16 +9753,16 @@ handle_request_hello_validation (void *cls,
9831 * @return #GNUNET_OK (always) 9753 * @return #GNUNET_OK (always)
9832 */ 9754 */
9833static int 9755static int
9834free_neighbour_cb (void *cls, 9756free_neighbour_cb(void *cls,
9835 const struct GNUNET_PeerIdentity *pid, 9757 const struct GNUNET_PeerIdentity *pid,
9836 void *value) 9758 void *value)
9837{ 9759{
9838 struct Neighbour *neighbour = value; 9760 struct Neighbour *neighbour = value;
9839 9761
9840 (void) cls; 9762 (void)cls;
9841 (void) pid; 9763 (void)pid;
9842 GNUNET_break (0); // should this ever happen? 9764 GNUNET_break(0); // should this ever happen?
9843 free_neighbour (neighbour); 9765 free_neighbour(neighbour);
9844 9766
9845 return GNUNET_OK; 9767 return GNUNET_OK;
9846} 9768}
@@ -9855,15 +9777,15 @@ free_neighbour_cb (void *cls,
9855 * @return #GNUNET_OK (always) 9777 * @return #GNUNET_OK (always)
9856 */ 9778 */
9857static int 9779static int
9858free_dv_routes_cb (void *cls, 9780free_dv_routes_cb(void *cls,
9859 const struct GNUNET_PeerIdentity *pid, 9781 const struct GNUNET_PeerIdentity *pid,
9860 void *value) 9782 void *value)
9861{ 9783{
9862 struct DistanceVector *dv = value; 9784 struct DistanceVector *dv = value;
9863 9785
9864 (void) cls; 9786 (void)cls;
9865 (void) pid; 9787 (void)pid;
9866 free_dv_route (dv); 9788 free_dv_route(dv);
9867 9789
9868 return GNUNET_OK; 9790 return GNUNET_OK;
9869} 9791}
@@ -9878,15 +9800,15 @@ free_dv_routes_cb (void *cls,
9878 * @return #GNUNET_OK (always) 9800 * @return #GNUNET_OK (always)
9879 */ 9801 */
9880static int 9802static int
9881free_validation_state_cb (void *cls, 9803free_validation_state_cb(void *cls,
9882 const struct GNUNET_PeerIdentity *pid, 9804 const struct GNUNET_PeerIdentity *pid,
9883 void *value) 9805 void *value)
9884{ 9806{
9885 struct ValidationState *vs = value; 9807 struct ValidationState *vs = value;
9886 9808
9887 (void) cls; 9809 (void)cls;
9888 (void) pid; 9810 (void)pid;
9889 free_validation_state (vs); 9811 free_validation_state(vs);
9890 return GNUNET_OK; 9812 return GNUNET_OK;
9891} 9813}
9892 9814
@@ -9900,13 +9822,13 @@ free_validation_state_cb (void *cls,
9900 * @return #GNUNET_OK (always) 9822 * @return #GNUNET_OK (always)
9901 */ 9823 */
9902static int 9824static int
9903free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value) 9825free_pending_ack_cb(void *cls, const struct GNUNET_Uuid *key, void *value)
9904{ 9826{
9905 struct PendingAcknowledgement *pa = value; 9827 struct PendingAcknowledgement *pa = value;
9906 9828
9907 (void) cls; 9829 (void)cls;
9908 (void) key; 9830 (void)key;
9909 free_pending_acknowledgement (pa); 9831 free_pending_acknowledgement(pa);
9910 return GNUNET_OK; 9832 return GNUNET_OK;
9911} 9833}
9912 9834
@@ -9920,15 +9842,15 @@ free_pending_ack_cb (void *cls, const struct GNUNET_Uuid *key, void *value)
9920 * @return #GNUNET_OK (always) 9842 * @return #GNUNET_OK (always)
9921 */ 9843 */
9922static int 9844static int
9923free_ack_cummulator_cb (void *cls, 9845free_ack_cummulator_cb(void *cls,
9924 const struct GNUNET_PeerIdentity *pid, 9846 const struct GNUNET_PeerIdentity *pid,
9925 void *value) 9847 void *value)
9926{ 9848{
9927 struct AcknowledgementCummulator *ac = value; 9849 struct AcknowledgementCummulator *ac = value;
9928 9850
9929 (void) cls; 9851 (void)cls;
9930 (void) pid; 9852 (void)pid;
9931 GNUNET_free (ac); 9853 GNUNET_free(ac);
9932 return GNUNET_OK; 9854 return GNUNET_OK;
9933} 9855}
9934 9856
@@ -9940,67 +9862,68 @@ free_ack_cummulator_cb (void *cls,
9940 * @param cls closure, unused 9862 * @param cls closure, unused
9941 */ 9863 */
9942static void 9864static void
9943do_shutdown (void *cls) 9865do_shutdown(void *cls)
9944{ 9866{
9945 struct LearnLaunchEntry *lle; 9867 struct LearnLaunchEntry *lle;
9946 (void) cls;
9947 9868
9948 GNUNET_CONTAINER_multipeermap_iterate (neighbours, &free_neighbour_cb, NULL); 9869 (void)cls;
9870
9871 GNUNET_CONTAINER_multipeermap_iterate(neighbours, &free_neighbour_cb, NULL);
9949 if (NULL != peerstore) 9872 if (NULL != peerstore)
9950 { 9873 {
9951 GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_NO); 9874 GNUNET_PEERSTORE_disconnect(peerstore, GNUNET_NO);
9952 peerstore = NULL; 9875 peerstore = NULL;
9953 } 9876 }
9954 if (NULL != GST_stats) 9877 if (NULL != GST_stats)
9955 { 9878 {
9956 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 9879 GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO);
9957 GST_stats = NULL; 9880 GST_stats = NULL;
9958 } 9881 }
9959 if (NULL != GST_my_private_key) 9882 if (NULL != GST_my_private_key)
9960 { 9883 {
9961 GNUNET_free (GST_my_private_key); 9884 GNUNET_free(GST_my_private_key);
9962 GST_my_private_key = NULL; 9885 GST_my_private_key = NULL;
9963 } 9886 }
9964 GNUNET_CONTAINER_multipeermap_iterate (ack_cummulators, 9887 GNUNET_CONTAINER_multipeermap_iterate(ack_cummulators,
9965 &free_ack_cummulator_cb, 9888 &free_ack_cummulator_cb,
9966 NULL); 9889 NULL);
9967 GNUNET_CONTAINER_multipeermap_destroy (ack_cummulators); 9890 GNUNET_CONTAINER_multipeermap_destroy(ack_cummulators);
9968 ack_cummulators = NULL; 9891 ack_cummulators = NULL;
9969 GNUNET_CONTAINER_multiuuidmap_iterate (pending_acks, 9892 GNUNET_CONTAINER_multiuuidmap_iterate(pending_acks,
9970 &free_pending_ack_cb, 9893 &free_pending_ack_cb,
9971 NULL); 9894 NULL);
9972 GNUNET_CONTAINER_multiuuidmap_destroy (pending_acks); 9895 GNUNET_CONTAINER_multiuuidmap_destroy(pending_acks);
9973 pending_acks = NULL; 9896 pending_acks = NULL;
9974 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (neighbours)); 9897 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(neighbours));
9975 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 9898 GNUNET_CONTAINER_multipeermap_destroy(neighbours);
9976 neighbours = NULL; 9899 neighbours = NULL;
9977 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (links)); 9900 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(links));
9978 GNUNET_CONTAINER_multipeermap_destroy (links); 9901 GNUNET_CONTAINER_multipeermap_destroy(links);
9979 links = NULL; 9902 links = NULL;
9980 GNUNET_CONTAINER_multipeermap_iterate (backtalkers, 9903 GNUNET_CONTAINER_multipeermap_iterate(backtalkers,
9981 &free_backtalker_cb, 9904 &free_backtalker_cb,
9982 NULL); 9905 NULL);
9983 GNUNET_CONTAINER_multipeermap_destroy (backtalkers); 9906 GNUNET_CONTAINER_multipeermap_destroy(backtalkers);
9984 backtalkers = NULL; 9907 backtalkers = NULL;
9985 GNUNET_CONTAINER_multipeermap_iterate (validation_map, 9908 GNUNET_CONTAINER_multipeermap_iterate(validation_map,
9986 &free_validation_state_cb, 9909 &free_validation_state_cb,
9987 NULL); 9910 NULL);
9988 GNUNET_CONTAINER_multipeermap_destroy (validation_map); 9911 GNUNET_CONTAINER_multipeermap_destroy(validation_map);
9989 validation_map = NULL; 9912 validation_map = NULL;
9990 while (NULL != ir_head) 9913 while (NULL != ir_head)
9991 free_incoming_request (ir_head); 9914 free_incoming_request(ir_head);
9992 GNUNET_assert (0 == ir_total); 9915 GNUNET_assert(0 == ir_total);
9993 while (NULL != (lle = lle_head)) 9916 while (NULL != (lle = lle_head))
9994 { 9917 {
9995 GNUNET_CONTAINER_DLL_remove (lle_head, lle_tail, lle); 9918 GNUNET_CONTAINER_DLL_remove(lle_head, lle_tail, lle);
9996 GNUNET_free (lle); 9919 GNUNET_free(lle);
9997 } 9920 }
9998 GNUNET_CONTAINER_multishortmap_destroy (dvlearn_map); 9921 GNUNET_CONTAINER_multishortmap_destroy(dvlearn_map);
9999 dvlearn_map = NULL; 9922 dvlearn_map = NULL;
10000 GNUNET_CONTAINER_heap_destroy (validation_heap); 9923 GNUNET_CONTAINER_heap_destroy(validation_heap);
10001 validation_heap = NULL; 9924 validation_heap = NULL;
10002 GNUNET_CONTAINER_multipeermap_iterate (dv_routes, &free_dv_routes_cb, NULL); 9925 GNUNET_CONTAINER_multipeermap_iterate(dv_routes, &free_dv_routes_cb, NULL);
10003 GNUNET_CONTAINER_multipeermap_destroy (dv_routes); 9926 GNUNET_CONTAINER_multipeermap_destroy(dv_routes);
10004 dv_routes = NULL; 9927 dv_routes = NULL;
10005} 9928}
10006 9929
@@ -10013,58 +9936,58 @@ do_shutdown (void *cls)
10013 * @param service the initialized service 9936 * @param service the initialized service
10014 */ 9937 */
10015static void 9938static void
10016run (void *cls, 9939run(void *cls,
10017 const struct GNUNET_CONFIGURATION_Handle *c, 9940 const struct GNUNET_CONFIGURATION_Handle *c,
10018 struct GNUNET_SERVICE_Handle *service) 9941 struct GNUNET_SERVICE_Handle *service)
10019{ 9942{
10020 (void) cls; 9943 (void)cls;
10021 (void) service; 9944 (void)service;
10022 /* setup globals */ 9945 /* setup globals */
10023 hello_mono_time = GNUNET_TIME_absolute_get_monotonic (c); 9946 hello_mono_time = GNUNET_TIME_absolute_get_monotonic(c);
10024 GST_cfg = c; 9947 GST_cfg = c;
10025 backtalkers = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); 9948 backtalkers = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES);
10026 pending_acks = GNUNET_CONTAINER_multiuuidmap_create (32768, GNUNET_YES); 9949 pending_acks = GNUNET_CONTAINER_multiuuidmap_create(32768, GNUNET_YES);
10027 ack_cummulators = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES); 9950 ack_cummulators = GNUNET_CONTAINER_multipeermap_create(256, GNUNET_YES);
10028 neighbours = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 9951 neighbours = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES);
10029 links = GNUNET_CONTAINER_multipeermap_create (512, GNUNET_YES); 9952 links = GNUNET_CONTAINER_multipeermap_create(512, GNUNET_YES);
10030 dv_routes = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 9953 dv_routes = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES);
10031 dvlearn_map = GNUNET_CONTAINER_multishortmap_create (2 * MAX_DV_LEARN_PENDING, 9954 dvlearn_map = GNUNET_CONTAINER_multishortmap_create(2 * MAX_DV_LEARN_PENDING,
10032 GNUNET_YES); 9955 GNUNET_YES);
10033 validation_map = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); 9956 validation_map = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES);
10034 validation_heap = 9957 validation_heap =
10035 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 9958 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
10036 GST_my_private_key = 9959 GST_my_private_key =
10037 GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); 9960 GNUNET_CRYPTO_eddsa_key_create_from_configuration(GST_cfg);
10038 if (NULL == GST_my_private_key) 9961 if (NULL == GST_my_private_key)
10039 { 9962 {
10040 GNUNET_log ( 9963 GNUNET_log(
10041 GNUNET_ERROR_TYPE_ERROR, 9964 GNUNET_ERROR_TYPE_ERROR,
10042 _ ( 9965 _(
10043 "Transport service is lacking key configuration settings. Exiting.\n")); 9966 "Transport service is lacking key configuration settings. Exiting.\n"));
10044 GNUNET_SCHEDULER_shutdown (); 9967 GNUNET_SCHEDULER_shutdown();
10045 return; 9968 return;
10046 } 9969 }
10047 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, 9970 GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key,
10048 &GST_my_identity.public_key); 9971 &GST_my_identity.public_key);
10049 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 9972 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
10050 "My identity is `%s'\n", 9973 "My identity is `%s'\n",
10051 GNUNET_i2s_full (&GST_my_identity)); 9974 GNUNET_i2s_full(&GST_my_identity));
10052 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); 9975 GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg);
10053 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 9976 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
10054 peerstore = GNUNET_PEERSTORE_connect (GST_cfg); 9977 peerstore = GNUNET_PEERSTORE_connect(GST_cfg);
10055 if (NULL == peerstore) 9978 if (NULL == peerstore)
10056 { 9979 {
10057 GNUNET_break (0); 9980 GNUNET_break(0);
10058 GNUNET_SCHEDULER_shutdown (); 9981 GNUNET_SCHEDULER_shutdown();
10059 return; 9982 return;
10060 } 9983 }
10061} 9984}
10062 9985
10063 9986
10064/** 9987/**
10065 * Define "main" method using service macro. 9988 * Define "main" method using service macro.
10066 */ 9989 */
10067GNUNET_SERVICE_MAIN ( 9990GNUNET_SERVICE_MAIN(
10068 "transport", 9991 "transport",
10069 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN, 9992 GNUNET_SERVICE_OPTION_SOFT_SHUTDOWN,
10070 &run, 9993 &run,
@@ -10072,78 +9995,78 @@ GNUNET_SERVICE_MAIN (
10072 &client_disconnect_cb, 9995 &client_disconnect_cb,
10073 NULL, 9996 NULL,
10074 /* communication with applications */ 9997 /* communication with applications */
10075 GNUNET_MQ_hd_fixed_size (suggest, 9998 GNUNET_MQ_hd_fixed_size(suggest,
10076 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST, 9999 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST,
10077 struct ExpressPreferenceMessage, 10000 struct ExpressPreferenceMessage,
10078 NULL), 10001 NULL),
10079 GNUNET_MQ_hd_fixed_size (suggest_cancel, 10002 GNUNET_MQ_hd_fixed_size(suggest_cancel,
10080 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL, 10003 GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL,
10081 struct ExpressPreferenceMessage, 10004 struct ExpressPreferenceMessage,
10082 NULL), 10005 NULL),
10083 GNUNET_MQ_hd_var_size (request_hello_validation, 10006 GNUNET_MQ_hd_var_size(request_hello_validation,
10084 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION, 10007 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION,
10085 struct RequestHelloValidationMessage, 10008 struct RequestHelloValidationMessage,
10086 NULL), 10009 NULL),
10087 /* communication with core */ 10010 /* communication with core */
10088 GNUNET_MQ_hd_fixed_size (client_start, 10011 GNUNET_MQ_hd_fixed_size(client_start,
10089 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 10012 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
10090 struct StartMessage, 10013 struct StartMessage,
10091 NULL), 10014 NULL),
10092 GNUNET_MQ_hd_var_size (client_send, 10015 GNUNET_MQ_hd_var_size(client_send,
10093 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 10016 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
10094 struct OutboundMessage, 10017 struct OutboundMessage,
10095 NULL), 10018 NULL),
10096 GNUNET_MQ_hd_fixed_size (client_recv_ok, 10019 GNUNET_MQ_hd_fixed_size(client_recv_ok,
10097 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK, 10020 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK,
10098 struct RecvOkMessage, 10021 struct RecvOkMessage,
10099 NULL), 10022 NULL),
10100 /* communication with communicators */ 10023 /* communication with communicators */
10101 GNUNET_MQ_hd_var_size (communicator_available, 10024 GNUNET_MQ_hd_var_size(communicator_available,
10102 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 10025 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
10103 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 10026 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
10104 NULL), 10027 NULL),
10105 GNUNET_MQ_hd_var_size (communicator_backchannel, 10028 GNUNET_MQ_hd_var_size(communicator_backchannel,
10106 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 10029 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
10107 struct GNUNET_TRANSPORT_CommunicatorBackchannel, 10030 struct GNUNET_TRANSPORT_CommunicatorBackchannel,
10108 NULL), 10031 NULL),
10109 GNUNET_MQ_hd_var_size (add_address, 10032 GNUNET_MQ_hd_var_size(add_address,
10110 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 10033 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
10111 struct GNUNET_TRANSPORT_AddAddressMessage, 10034 struct GNUNET_TRANSPORT_AddAddressMessage,
10112 NULL), 10035 NULL),
10113 GNUNET_MQ_hd_fixed_size (del_address, 10036 GNUNET_MQ_hd_fixed_size(del_address,
10114 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 10037 GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
10115 struct GNUNET_TRANSPORT_DelAddressMessage, 10038 struct GNUNET_TRANSPORT_DelAddressMessage,
10116 NULL), 10039 NULL),
10117 GNUNET_MQ_hd_var_size (incoming_msg, 10040 GNUNET_MQ_hd_var_size(incoming_msg,
10118 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 10041 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
10119 struct GNUNET_TRANSPORT_IncomingMessage, 10042 struct GNUNET_TRANSPORT_IncomingMessage,
10120 NULL), 10043 NULL),
10121 GNUNET_MQ_hd_fixed_size (queue_create_ok, 10044 GNUNET_MQ_hd_fixed_size(queue_create_ok,
10122 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 10045 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
10123 struct GNUNET_TRANSPORT_CreateQueueResponse, 10046 struct GNUNET_TRANSPORT_CreateQueueResponse,
10124 NULL), 10047 NULL),
10125 GNUNET_MQ_hd_fixed_size (queue_create_fail, 10048 GNUNET_MQ_hd_fixed_size(queue_create_fail,
10126 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 10049 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
10127 struct GNUNET_TRANSPORT_CreateQueueResponse, 10050 struct GNUNET_TRANSPORT_CreateQueueResponse,
10128 NULL), 10051 NULL),
10129 GNUNET_MQ_hd_var_size (add_queue_message, 10052 GNUNET_MQ_hd_var_size(add_queue_message,
10130 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 10053 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
10131 struct GNUNET_TRANSPORT_AddQueueMessage, 10054 struct GNUNET_TRANSPORT_AddQueueMessage,
10132 NULL), 10055 NULL),
10133 GNUNET_MQ_hd_fixed_size (del_queue_message, 10056 GNUNET_MQ_hd_fixed_size(del_queue_message,
10134 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 10057 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
10135 struct GNUNET_TRANSPORT_DelQueueMessage, 10058 struct GNUNET_TRANSPORT_DelQueueMessage,
10136 NULL), 10059 NULL),
10137 GNUNET_MQ_hd_fixed_size (send_message_ack, 10060 GNUNET_MQ_hd_fixed_size(send_message_ack,
10138 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, 10061 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
10139 struct GNUNET_TRANSPORT_SendMessageToAck, 10062 struct GNUNET_TRANSPORT_SendMessageToAck,
10140 NULL), 10063 NULL),
10141 /* communication with monitors */ 10064 /* communication with monitors */
10142 GNUNET_MQ_hd_fixed_size (monitor_start, 10065 GNUNET_MQ_hd_fixed_size(monitor_start,
10143 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START, 10066 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START,
10144 struct GNUNET_TRANSPORT_MonitorStart, 10067 struct GNUNET_TRANSPORT_MonitorStart,
10145 NULL), 10068 NULL),
10146 GNUNET_MQ_handler_end ()); 10069 GNUNET_MQ_handler_end());
10147 10070
10148 10071
10149/* end of file gnunet-service-transport.c */ 10072/* end of file gnunet-service-transport.c */
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 1e8f81483..5080e650e 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2016 GNUnet e.V. 3 Copyright (C) 2010-2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -47,7 +47,7 @@
47 * How many messages can we have pending for a given client process 47 * How many messages can we have pending for a given client process
48 * before we start to drop incoming messages? We typically should 48 * before we start to drop incoming messages? We typically should
49 * have only one client and so this would be the primary buffer for 49 * have only one client and so this would be the primary buffer for
50 * messages, so the number should be chosen rather generously. 50 * messages, so the number should be chosen rather generously.
51 * 51 *
52 * The expectation here is that most of the time the queue is large 52 * The expectation here is that most of the time the queue is large
53 * enough so that a drop is virtually never required. Note that 53 * enough so that a drop is virtually never required. Note that
@@ -61,8 +61,7 @@
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{
66 /** 65 /**
67 * Kept in a DLL. 66 * Kept in a DLL.
68 */ 67 */
@@ -93,8 +92,7 @@ struct GNUNET_ATS_SessionKiller
93/** 92/**
94 * What type of client is the `struct TransportClient` about? 93 * What type of client is the `struct TransportClient` about?
95 */ 94 */
96enum ClientType 95enum ClientType {
97{
98 /** 96 /**
99 * We do not know yet (client is fresh). 97 * We do not know yet (client is fresh).
100 */ 98 */
@@ -130,9 +128,7 @@ struct GST_BlacklistCheck;
130/** 128/**
131 * Client connected to the transport service. 129 * Client connected to the transport service.
132 */ 130 */
133struct TransportClient 131struct TransportClient {
134{
135
136 /** 132 /**
137 * This is a doubly-linked list. 133 * This is a doubly-linked list.
138 */ 134 */
@@ -158,9 +154,7 @@ struct TransportClient
158 */ 154 */
159 enum ClientType type; 155 enum ClientType type;
160 156
161 union 157 union {
162 {
163
164 /** 158 /**
165 * Peer identity to monitor the addresses of. 159 * Peer identity to monitor the addresses of.
166 * Zero to monitor all neighbours. Valid if 160 * Zero to monitor all neighbours. Valid if
@@ -171,9 +165,7 @@ struct TransportClient
171 /** 165 /**
172 * Additional details if @e type is CT_BLACKLIST. 166 * Additional details if @e type is CT_BLACKLIST.
173 */ 167 */
174 struct 168 struct {
175 {
176
177 /** 169 /**
178 * Blacklist check that we're currently performing (or NULL 170 * Blacklist check that we're currently performing (or NULL
179 * if we're performing one that has been cancelled). 171 * if we're performing one that has been cancelled).
@@ -189,9 +181,7 @@ struct TransportClient
189 * #GNUNET_YES if we have to call receive_done for this client 181 * #GNUNET_YES if we have to call receive_done for this client
190 */ 182 */
191 int call_receive_done; 183 int call_receive_done;
192
193 } blacklist; 184 } blacklist;
194
195 } details; 185 } details;
196}; 186};
197 187
@@ -199,9 +189,7 @@ struct TransportClient
199/** 189/**
200 * Context we use when performing a blacklist check. 190 * Context we use when performing a blacklist check.
201 */ 191 */
202struct GST_BlacklistCheck 192struct GST_BlacklistCheck {
203{
204
205 /** 193 /**
206 * This is a linked list. 194 * This is a linked list.
207 */ 195 */
@@ -252,8 +240,7 @@ struct GST_BlacklistCheck
252/** 240/**
253 * Context for address to string operations 241 * Context for address to string operations
254 */ 242 */
255struct AddressToStringContext 243struct AddressToStringContext {
256{
257 /** 244 /**
258 * This is a doubly-linked list. 245 * This is a doubly-linked list.
259 */ 246 */
@@ -274,9 +261,7 @@ struct AddressToStringContext
274/** 261/**
275 * Closure for #handle_send_transmit_continuation() 262 * Closure for #handle_send_transmit_continuation()
276 */ 263 */
277struct SendTransmitContinuationContext 264struct SendTransmitContinuationContext {
278{
279
280 /** 265 /**
281 * Client that made the request. 266 * Client that made the request.
282 */ 267 */
@@ -431,31 +416,31 @@ struct GNUNET_NT_InterfaceScanner *GST_is;
431 * @param may_drop #GNUNET_YES if the message can be dropped 416 * @param may_drop #GNUNET_YES if the message can be dropped
432 */ 417 */
433static void 418static void
434unicast (struct TransportClient *tc, 419unicast(struct TransportClient *tc,
435 const struct GNUNET_MessageHeader *msg, 420 const struct GNUNET_MessageHeader *msg,
436 int may_drop) 421 int may_drop)
437{ 422{
438 struct GNUNET_MQ_Envelope *env; 423 struct GNUNET_MQ_Envelope *env;
439 424
440 if ((GNUNET_MQ_get_length (tc->mq) >= MAX_PENDING) && 425 if ((GNUNET_MQ_get_length(tc->mq) >= MAX_PENDING) &&
441 (GNUNET_YES == may_drop)) 426 (GNUNET_YES == may_drop))
442 { 427 {
443 GNUNET_log ( 428 GNUNET_log(
444 GNUNET_ERROR_TYPE_DEBUG, 429 GNUNET_ERROR_TYPE_DEBUG,
445 "Dropping message of type %u and size %u, have %u/%u messages pending\n", 430 "Dropping message of type %u and size %u, have %u/%u messages pending\n",
446 ntohs (msg->type), 431 ntohs(msg->type),
447 ntohs (msg->size), 432 ntohs(msg->size),
448 GNUNET_MQ_get_length (tc->mq), 433 GNUNET_MQ_get_length(tc->mq),
449 MAX_PENDING); 434 MAX_PENDING);
450 GNUNET_STATISTICS_update (GST_stats, 435 GNUNET_STATISTICS_update(GST_stats,
451 gettext_noop ( 436 gettext_noop(
452 "# messages dropped due to slow client"), 437 "# messages dropped due to slow client"),
453 1, 438 1,
454 GNUNET_NO); 439 GNUNET_NO);
455 return; 440 return;
456 } 441 }
457 env = GNUNET_MQ_msg_copy (msg); 442 env = GNUNET_MQ_msg_copy(msg);
458 GNUNET_MQ_send (tc->mq, env); 443 GNUNET_MQ_send(tc->mq, env);
459} 444}
460 445
461 446
@@ -469,17 +454,17 @@ unicast (struct TransportClient *tc,
469 * @return our `struct TransportClient` 454 * @return our `struct TransportClient`
470 */ 455 */
471static void * 456static void *
472client_connect_cb (void *cls, 457client_connect_cb(void *cls,
473 struct GNUNET_SERVICE_Client *client, 458 struct GNUNET_SERVICE_Client *client,
474 struct GNUNET_MQ_Handle *mq) 459 struct GNUNET_MQ_Handle *mq)
475{ 460{
476 struct TransportClient *tc; 461 struct TransportClient *tc;
477 462
478 tc = GNUNET_new (struct TransportClient); 463 tc = GNUNET_new(struct TransportClient);
479 tc->client = client; 464 tc->client = client;
480 tc->mq = mq; 465 tc->mq = mq;
481 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc); 466 GNUNET_CONTAINER_DLL_insert(clients_head, clients_tail, tc);
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc); 467 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p connected\n", tc);
483 return tc; 468 return tc;
484} 469}
485 470
@@ -490,7 +475,7 @@ client_connect_cb (void *cls,
490 * @param cls the `struct BlacklistCheck*` 475 * @param cls the `struct BlacklistCheck*`
491 */ 476 */
492static void 477static void
493do_blacklist_check (void *cls); 478do_blacklist_check(void *cls);
494 479
495 480
496/** 481/**
@@ -503,16 +488,16 @@ do_blacklist_check (void *cls);
503 * @return #GNUNET_OK (continue to iterate) 488 * @return #GNUNET_OK (continue to iterate)
504 */ 489 */
505static int 490static int
506mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) 491mark_match_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
507{ 492{
508 struct TransportClient *tc = cls; 493 struct TransportClient *tc = cls;
509 struct SendTransmitContinuationContext *stcc = value; 494 struct SendTransmitContinuationContext *stcc = value;
510 495
511 if (tc == stcc->tc) 496 if (tc == stcc->tc)
512 { 497 {
513 stcc->down = GNUNET_YES; 498 stcc->down = GNUNET_YES;
514 stcc->tc = NULL; 499 stcc->tc = NULL;
515 } 500 }
516 return GNUNET_OK; 501 return GNUNET_OK;
517} 502}
518 503
@@ -526,46 +511,50 @@ mark_match_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
526 * @param app_ctx our `struct TransportClient` 511 * @param app_ctx our `struct TransportClient`
527 */ 512 */
528static void 513static void
529client_disconnect_cb (void *cls, 514client_disconnect_cb(void *cls,
530 struct GNUNET_SERVICE_Client *client, 515 struct GNUNET_SERVICE_Client *client,
531 void *app_ctx) 516 void *app_ctx)
532{ 517{
533 struct TransportClient *tc = app_ctx; 518 struct TransportClient *tc = app_ctx;
534 struct GST_BlacklistCheck *bc; 519 struct GST_BlacklistCheck *bc;
535 520
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
537 "Client %p disconnected, cleaning up.\n", 522 "Client %p disconnected, cleaning up.\n",
538 tc); 523 tc);
539 GNUNET_CONTAINER_multipeermap_iterate (active_stccs, &mark_match_down, tc); 524 GNUNET_CONTAINER_multipeermap_iterate(active_stccs, &mark_match_down, tc);
540 for (struct AddressToStringContext *cur = a2s_head; NULL != cur; 525 for (struct AddressToStringContext *cur = a2s_head; NULL != cur;
541 cur = cur->next) 526 cur = cur->next)
542 { 527 {
543 if (cur->tc == tc) 528 if (cur->tc == tc)
544 cur->tc = NULL; 529 cur->tc = NULL;
545 } 530 }
546 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc); 531 GNUNET_CONTAINER_DLL_remove(clients_head, clients_tail, tc);
547 switch (tc->type) 532 switch (tc->type)
548 { 533 {
549 case CT_NONE: 534 case CT_NONE:
550 break; 535 break;
551 case CT_CORE: 536
552 break; 537 case CT_CORE:
553 case CT_MONITOR: 538 break;
554 break; 539
555 case CT_BLACKLIST: 540 case CT_MONITOR:
556 for (bc = bc_head; NULL != bc; bc = bc->next) 541 break;
557 { 542
558 if (bc->bl_pos != tc) 543 case CT_BLACKLIST:
559 continue; 544 for (bc = bc_head; NULL != bc; bc = bc->next)
560 bc->bl_pos = tc->next; 545 {
561 if (NULL == bc->task) 546 if (bc->bl_pos != tc)
562 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); 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
554 case CT_CORE_NO_HANDLERS:
555 break;
563 } 556 }
564 break; 557 GNUNET_free(tc);
565 case CT_CORE_NO_HANDLERS:
566 break;
567 }
568 GNUNET_free (tc);
569} 558}
570 559
571 560
@@ -582,24 +571,24 @@ client_disconnect_cb (void *cls,
582 * @param bandwidth_out outbound bandwidth in NBO 571 * @param bandwidth_out outbound bandwidth in NBO
583 */ 572 */
584static void 573static void
585notify_client_about_neighbour (void *cls, 574notify_client_about_neighbour(void *cls,
586 const struct GNUNET_PeerIdentity *peer, 575 const struct GNUNET_PeerIdentity *peer,
587 const struct GNUNET_HELLO_Address *address, 576 const struct GNUNET_HELLO_Address *address,
588 enum GNUNET_TRANSPORT_PeerState state, 577 enum GNUNET_TRANSPORT_PeerState state,
589 struct GNUNET_TIME_Absolute state_timeout, 578 struct GNUNET_TIME_Absolute state_timeout,
590 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 579 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
591 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 580 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
592{ 581{
593 struct TransportClient *tc = cls; 582 struct TransportClient *tc = cls;
594 struct ConnectInfoMessage cim; 583 struct ConnectInfoMessage cim;
595 584
596 if (GNUNET_NO == GST_neighbours_test_connected (peer)) 585 if (GNUNET_NO == GST_neighbours_test_connected(peer))
597 return; 586 return;
598 cim.header.size = htons (sizeof (struct ConnectInfoMessage)); 587 cim.header.size = htons(sizeof(struct ConnectInfoMessage));
599 cim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 588 cim.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
600 cim.id = *peer; 589 cim.id = *peer;
601 cim.quota_out = bandwidth_out; 590 cim.quota_out = bandwidth_out;
602 unicast (tc, &cim.header, GNUNET_NO); 591 unicast(tc, &cim.header, GNUNET_NO);
603} 592}
604 593
605 594
@@ -612,39 +601,39 @@ notify_client_about_neighbour (void *cls,
612 * @param start the start message that was sent 601 * @param start the start message that was sent
613 */ 602 */
614static void 603static void
615handle_client_start (void *cls, const struct StartMessage *start) 604handle_client_start(void *cls, const struct StartMessage *start)
616{ 605{
617 struct TransportClient *tc = cls; 606 struct TransportClient *tc = cls;
618 const struct GNUNET_MessageHeader *hello; 607 const struct GNUNET_MessageHeader *hello;
619 uint32_t options; 608 uint32_t options;
620 609
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc); 610 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Client %p sent START\n", tc);
622 options = ntohl (start->options); 611 options = ntohl(start->options);
623 if ((0 != (1 & options)) && 612 if ((0 != (1 & options)) &&
624 (0 != memcmp (&start->self, 613 (0 != memcmp(&start->self,
625 &GST_my_identity, 614 &GST_my_identity,
626 sizeof (struct GNUNET_PeerIdentity)))) 615 sizeof(struct GNUNET_PeerIdentity))))
627 { 616 {
628 /* client thinks this is a different peer, reject */ 617 /* client thinks this is a different peer, reject */
629 GNUNET_break (0); 618 GNUNET_break(0);
630 GNUNET_SERVICE_client_drop (tc->client); 619 GNUNET_SERVICE_client_drop(tc->client);
631 return; 620 return;
632 } 621 }
633 if (CT_NONE != tc->type) 622 if (CT_NONE != tc->type)
634 { 623 {
635 GNUNET_break (0); 624 GNUNET_break(0);
636 GNUNET_SERVICE_client_drop (tc->client); 625 GNUNET_SERVICE_client_drop(tc->client);
637 return; 626 return;
638 } 627 }
639 if (0 != (2 & options)) 628 if (0 != (2 & options))
640 tc->type = CT_CORE; 629 tc->type = CT_CORE;
641 else 630 else
642 tc->type = CT_CORE_NO_HANDLERS; 631 tc->type = CT_CORE_NO_HANDLERS;
643 hello = GST_hello_get (); 632 hello = GST_hello_get();
644 if (NULL != hello) 633 if (NULL != hello)
645 unicast (tc, hello, GNUNET_NO); 634 unicast(tc, hello, GNUNET_NO);
646 GST_neighbours_iterate (&notify_client_about_neighbour, tc); 635 GST_neighbours_iterate(&notify_client_about_neighbour, tc);
647 GNUNET_SERVICE_client_continue (tc->client); 636 GNUNET_SERVICE_client_continue(tc->client);
648} 637}
649 638
650 639
@@ -655,7 +644,7 @@ handle_client_start (void *cls, const struct StartMessage *start)
655 * @param message the HELLO message 644 * @param message the HELLO message
656 */ 645 */
657static int 646static int
658check_client_hello (void *cls, const struct GNUNET_MessageHeader *message) 647check_client_hello(void *cls, const struct GNUNET_MessageHeader *message)
659{ 648{
660 return GNUNET_OK; /* FIXME: check here? */ 649 return GNUNET_OK; /* FIXME: check here? */
661} 650}
@@ -668,13 +657,13 @@ check_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
668 * @param message the HELLO message 657 * @param message the HELLO message
669 */ 658 */
670static void 659static void
671handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message) 660handle_client_hello(void *cls, const struct GNUNET_MessageHeader *message)
672{ 661{
673 struct TransportClient *tc = cls; 662 struct TransportClient *tc = cls;
674 663
675 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n"); 664 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received HELLO message\n");
676 GST_validation_handle_hello (message); 665 GST_validation_handle_hello(message);
677 GNUNET_SERVICE_client_continue (tc->client); 666 GNUNET_SERVICE_client_continue(tc->client);
678} 667}
679 668
680 669
@@ -688,55 +677,55 @@ handle_client_hello (void *cls, const struct GNUNET_MessageHeader *message)
688 * @param bytes_on_wire bytes sent on wire 677 * @param bytes_on_wire bytes sent on wire
689 */ 678 */
690static void 679static void
691handle_send_transmit_continuation (void *cls, 680handle_send_transmit_continuation(void *cls,
692 int success, 681 int success,
693 size_t bytes_payload, 682 size_t bytes_payload,
694 size_t bytes_on_wire) 683 size_t bytes_on_wire)
695{ 684{
696 struct SendTransmitContinuationContext *stcc = cls; 685 struct SendTransmitContinuationContext *stcc = cls;
697 struct SendOkMessage send_ok_msg; 686 struct SendOkMessage send_ok_msg;
698 struct GNUNET_TIME_Relative delay; 687 struct GNUNET_TIME_Relative delay;
699 const struct GNUNET_HELLO_Address *addr; 688 const struct GNUNET_HELLO_Address *addr;
700 689
701 delay = GNUNET_TIME_absolute_get_duration (stcc->send_time); 690 delay = GNUNET_TIME_absolute_get_duration(stcc->send_time);
702 addr = GST_neighbour_get_current_address (&stcc->target); 691 addr = GST_neighbour_get_current_address(&stcc->target);
703 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 692 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
704 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 693 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
705 "It took us %s to send %u/%u bytes to %s (%d, %s)\n", 694 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
706 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 695 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
707 (unsigned int) bytes_payload, 696 (unsigned int)bytes_payload,
708 (unsigned int) bytes_on_wire, 697 (unsigned int)bytes_on_wire,
709 GNUNET_i2s (&stcc->target), 698 GNUNET_i2s(&stcc->target),
710 success, 699 success,
711 (NULL != addr) ? addr->transport_name : "%"); 700 (NULL != addr) ? addr->transport_name : "%");
712 else 701 else
713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 702 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
714 "It took us %s to send %u/%u bytes to %s (%d, %s)\n", 703 "It took us %s to send %u/%u bytes to %s (%d, %s)\n",
715 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 704 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
716 (unsigned int) bytes_payload, 705 (unsigned int)bytes_payload,
717 (unsigned int) bytes_on_wire, 706 (unsigned int)bytes_on_wire,
718 GNUNET_i2s (&stcc->target), 707 GNUNET_i2s(&stcc->target),
719 success, 708 success,
720 (NULL != addr) ? addr->transport_name : "%"); 709 (NULL != addr) ? addr->transport_name : "%");
721 710
722 if (GNUNET_NO == stcc->down) 711 if (GNUNET_NO == stcc->down)
723 { 712 {
724 /* Only send confirmation if we are still connected */ 713 /* Only send confirmation if we are still connected */
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 714 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
726 "Sending SEND_OK for transmission request %llu\n", 715 "Sending SEND_OK for transmission request %llu\n",
727 stcc->uuid); 716 stcc->uuid);
728 send_ok_msg.header.size = htons (sizeof (send_ok_msg)); 717 send_ok_msg.header.size = htons(sizeof(send_ok_msg));
729 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 718 send_ok_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
730 send_ok_msg.bytes_msg = htonl (bytes_payload); 719 send_ok_msg.bytes_msg = htonl(bytes_payload);
731 send_ok_msg.bytes_physical = htonl (bytes_on_wire); 720 send_ok_msg.bytes_physical = htonl(bytes_on_wire);
732 send_ok_msg.success = htonl (success); 721 send_ok_msg.success = htonl(success);
733 send_ok_msg.peer = stcc->target; 722 send_ok_msg.peer = stcc->target;
734 unicast (stcc->tc, &send_ok_msg.header, GNUNET_NO); 723 unicast(stcc->tc, &send_ok_msg.header, GNUNET_NO);
735 } 724 }
736 GNUNET_assert ( 725 GNUNET_assert(
737 GNUNET_OK == 726 GNUNET_OK ==
738 GNUNET_CONTAINER_multipeermap_remove (active_stccs, &stcc->target, stcc)); 727 GNUNET_CONTAINER_multipeermap_remove(active_stccs, &stcc->target, stcc));
739 GNUNET_free (stcc); 728 GNUNET_free(stcc);
740} 729}
741 730
742 731
@@ -747,23 +736,23 @@ handle_send_transmit_continuation (void *cls,
747 * @param obm the send message that was sent 736 * @param obm the send message that was sent
748 */ 737 */
749static int 738static int
750check_client_send (void *cls, const struct OutboundMessage *obm) 739check_client_send(void *cls, const struct OutboundMessage *obm)
751{ 740{
752 uint16_t size; 741 uint16_t size;
753 const struct GNUNET_MessageHeader *obmm; 742 const struct GNUNET_MessageHeader *obmm;
754 743
755 size = ntohs (obm->header.size) - sizeof (struct OutboundMessage); 744 size = ntohs(obm->header.size) - sizeof(struct OutboundMessage);
756 if (size < sizeof (struct GNUNET_MessageHeader)) 745 if (size < sizeof(struct GNUNET_MessageHeader))
757 { 746 {
758 GNUNET_break (0); 747 GNUNET_break(0);
759 return GNUNET_SYSERR; 748 return GNUNET_SYSERR;
760 } 749 }
761 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 750 obmm = (const struct GNUNET_MessageHeader *)&obm[1];
762 if (size != ntohs (obmm->size)) 751 if (size != ntohs(obmm->size))
763 { 752 {
764 GNUNET_break (0); 753 GNUNET_break(0);
765 return GNUNET_SYSERR; 754 return GNUNET_SYSERR;
766 } 755 }
767 return GNUNET_OK; 756 return GNUNET_OK;
768} 757}
769 758
@@ -775,53 +764,53 @@ check_client_send (void *cls, const struct OutboundMessage *obm)
775 * @param obm the send message that was sent 764 * @param obm the send message that was sent
776 */ 765 */
777static void 766static void
778handle_client_send (void *cls, const struct OutboundMessage *obm) 767handle_client_send(void *cls, const struct OutboundMessage *obm)
779{ 768{
780 static unsigned long long uuid_gen; 769 static unsigned long long uuid_gen;
781 struct TransportClient *tc = cls; 770 struct TransportClient *tc = cls;
782 const struct GNUNET_MessageHeader *obmm; 771 const struct GNUNET_MessageHeader *obmm;
783 struct SendTransmitContinuationContext *stcc; 772 struct SendTransmitContinuationContext *stcc;
784 773
785 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 774 obmm = (const struct GNUNET_MessageHeader *)&obm[1];
786 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer)) 775 if (GNUNET_NO == GST_neighbours_test_connected(&obm->peer))
787 { 776 {
788 /* not connected, not allowed to send; can happen due to asynchronous operations */ 777 /* not connected, not allowed to send; can happen due to asynchronous operations */
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 778 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
790 "Could not send message to peer `%s': not connected\n", 779 "Could not send message to peer `%s': not connected\n",
791 GNUNET_i2s (&obm->peer)); 780 GNUNET_i2s(&obm->peer));
792 GNUNET_STATISTICS_update ( 781 GNUNET_STATISTICS_update(
793 GST_stats, 782 GST_stats,
794 gettext_noop ("# bytes payload dropped (other peer was not connected)"), 783 gettext_noop("# bytes payload dropped (other peer was not connected)"),
795 ntohs (obmm->size), 784 ntohs(obmm->size),
796 GNUNET_NO); 785 GNUNET_NO);
797 GNUNET_SERVICE_client_continue (tc->client); 786 GNUNET_SERVICE_client_continue(tc->client);
798 return; 787 return;
799 } 788 }
800 GNUNET_log ( 789 GNUNET_log(
801 GNUNET_ERROR_TYPE_DEBUG, 790 GNUNET_ERROR_TYPE_DEBUG,
802 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n", 791 "Received SEND request %llu for `%s' and first message of type %u and total size %u\n",
803 uuid_gen, 792 uuid_gen,
804 GNUNET_i2s (&obm->peer), 793 GNUNET_i2s(&obm->peer),
805 ntohs (obmm->type), 794 ntohs(obmm->type),
806 ntohs (obmm->size)); 795 ntohs(obmm->size));
807 GNUNET_SERVICE_client_continue (tc->client); 796 GNUNET_SERVICE_client_continue(tc->client);
808 797
809 stcc = GNUNET_new (struct SendTransmitContinuationContext); 798 stcc = GNUNET_new(struct SendTransmitContinuationContext);
810 stcc->target = obm->peer; 799 stcc->target = obm->peer;
811 stcc->tc = tc; 800 stcc->tc = tc;
812 stcc->send_time = GNUNET_TIME_absolute_get (); 801 stcc->send_time = GNUNET_TIME_absolute_get();
813 stcc->uuid = uuid_gen++; 802 stcc->uuid = uuid_gen++;
814 (void) GNUNET_CONTAINER_multipeermap_put ( 803 (void)GNUNET_CONTAINER_multipeermap_put(
815 active_stccs, 804 active_stccs,
816 &stcc->target, 805 &stcc->target,
817 stcc, 806 stcc,
818 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 807 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
819 GST_manipulation_send (&obm->peer, 808 GST_manipulation_send(&obm->peer,
820 obmm, 809 obmm,
821 ntohs (obmm->size), 810 ntohs(obmm->size),
822 GNUNET_TIME_relative_ntoh (obm->timeout), 811 GNUNET_TIME_relative_ntoh(obm->timeout),
823 &handle_send_transmit_continuation, 812 &handle_send_transmit_continuation,
824 stcc); 813 stcc);
825} 814}
826 815
827 816
@@ -840,50 +829,50 @@ handle_client_send (void *cls, const struct OutboundMessage *obm)
840 * never #GNUNET_NO 829 * never #GNUNET_NO
841 */ 830 */
842static void 831static void
843transmit_address_to_client (void *cls, const char *buf, int res) 832transmit_address_to_client(void *cls, const char *buf, int res)
844{ 833{
845 struct AddressToStringContext *actx = cls; 834 struct AddressToStringContext *actx = cls;
846 struct GNUNET_MQ_Envelope *env; 835 struct GNUNET_MQ_Envelope *env;
847 struct AddressToStringResultMessage *atsm; 836 struct AddressToStringResultMessage *atsm;
848 size_t slen; 837 size_t slen;
849 838
850 GNUNET_assert ((GNUNET_OK == res) || (GNUNET_SYSERR == res)); 839 GNUNET_assert((GNUNET_OK == res) || (GNUNET_SYSERR == res));
851 if (NULL == actx->tc) 840 if (NULL == actx->tc)
852 return; 841 return;
853 if (NULL == buf) 842 if (NULL == buf)
854 {
855 env = GNUNET_MQ_msg (atsm,
856 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
857 if (GNUNET_OK == res)
858 {
859 /* this was the last call, transmit */
860 atsm->res = htonl (GNUNET_OK);
861 atsm->addr_len = htonl (0);
862 GNUNET_MQ_send (actx->tc->mq, env);
863 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
864 GNUNET_free (actx);
865 return;
866 }
867 if (GNUNET_SYSERR == res)
868 { 843 {
869 /* address conversion failed, but there will be more callbacks */ 844 env = GNUNET_MQ_msg(atsm,
870 atsm->res = htonl (GNUNET_SYSERR); 845 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
871 atsm->addr_len = htonl (0); 846 if (GNUNET_OK == res)
872 GNUNET_MQ_send (actx->tc->mq, env); 847 {
873 return; 848 /* this was the last call, transmit */
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 }
874 } 864 }
875 } 865 GNUNET_assert(GNUNET_OK == res);
876 GNUNET_assert (GNUNET_OK == res);
877 /* succesful conversion, append*/ 866 /* succesful conversion, append*/
878 slen = strlen (buf) + 1; 867 slen = strlen(buf) + 1;
879 env = 868 env =
880 GNUNET_MQ_msg_extra (atsm, 869 GNUNET_MQ_msg_extra(atsm,
881 slen, 870 slen,
882 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 871 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
883 atsm->res = htonl (GNUNET_YES); 872 atsm->res = htonl(GNUNET_YES);
884 atsm->addr_len = htonl (slen); 873 atsm->addr_len = htonl(slen);
885 GNUNET_memcpy (&atsm[1], buf, slen); 874 GNUNET_memcpy(&atsm[1], buf, slen);
886 GNUNET_MQ_send (actx->tc->mq, env); 875 GNUNET_MQ_send(actx->tc->mq, env);
887} 876}
888 877
889 878
@@ -895,29 +884,29 @@ transmit_address_to_client (void *cls, const char *buf, int res)
895 * @return #GNUNET_OK if @a alum is well-formed 884 * @return #GNUNET_OK if @a alum is well-formed
896 */ 885 */
897static int 886static int
898check_client_address_to_string (void *cls, 887check_client_address_to_string(void *cls,
899 const struct AddressLookupMessage *alum) 888 const struct AddressLookupMessage *alum)
900{ 889{
901 const char *plugin_name; 890 const char *plugin_name;
902 const char *address; 891 const char *address;
903 uint32_t address_len; 892 uint32_t address_len;
904 uint16_t size; 893 uint16_t size;
905 894
906 size = ntohs (alum->header.size); 895 size = ntohs(alum->header.size);
907 address_len = ntohs (alum->addrlen); 896 address_len = ntohs(alum->addrlen);
908 if (size <= sizeof (struct AddressLookupMessage) + address_len) 897 if (size <= sizeof(struct AddressLookupMessage) + address_len)
909 { 898 {
910 GNUNET_break (0); 899 GNUNET_break(0);
911 return GNUNET_SYSERR; 900 return GNUNET_SYSERR;
912 } 901 }
913 address = (const char *) &alum[1]; 902 address = (const char *)&alum[1];
914 plugin_name = (const char *) &address[address_len]; 903 plugin_name = (const char *)&address[address_len];
915 if ('\0' != plugin_name[size - sizeof (struct AddressLookupMessage) - 904 if ('\0' != plugin_name[size - sizeof(struct AddressLookupMessage) -
916 address_len - 1]) 905 address_len - 1])
917 { 906 {
918 GNUNET_break (0); 907 GNUNET_break(0);
919 return GNUNET_SYSERR; 908 return GNUNET_SYSERR;
920 } 909 }
921 return GNUNET_OK; 910 return GNUNET_OK;
922} 911}
923 912
@@ -929,8 +918,8 @@ check_client_address_to_string (void *cls,
929 * @param alum the resolution request 918 * @param alum the resolution request
930 */ 919 */
931static void 920static void
932handle_client_address_to_string (void *cls, 921handle_client_address_to_string(void *cls,
933 const struct AddressLookupMessage *alum) 922 const struct AddressLookupMessage *alum)
934{ 923{
935 struct TransportClient *tc = cls; 924 struct TransportClient *tc = cls;
936 struct GNUNET_TRANSPORT_PluginFunctions *papi; 925 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -943,45 +932,45 @@ handle_client_address_to_string (void *cls,
943 struct GNUNET_TIME_Relative rtimeout; 932 struct GNUNET_TIME_Relative rtimeout;
944 int32_t numeric; 933 int32_t numeric;
945 934
946 address_len = ntohs (alum->addrlen); 935 address_len = ntohs(alum->addrlen);
947 address = (const char *) &alum[1]; 936 address = (const char *)&alum[1];
948 plugin_name = (const char *) &address[address_len]; 937 plugin_name = (const char *)&address[address_len];
949 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); 938 rtimeout = GNUNET_TIME_relative_ntoh(alum->timeout);
950 numeric = ntohs (alum->numeric_only); 939 numeric = ntohs(alum->numeric_only);
951 papi = GST_plugins_printer_find (plugin_name); 940 papi = GST_plugins_printer_find(plugin_name);
952 if (NULL == papi) 941 if (NULL == papi)
953 { 942 {
954 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 943 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
955 "Failed to find plugin `%s'\n", 944 "Failed to find plugin `%s'\n",
956 plugin_name); 945 plugin_name);
957 env = GNUNET_MQ_msg (atsm, 946 env = GNUNET_MQ_msg(atsm,
958 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 947 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
959 atsm->res = htonl (GNUNET_SYSERR); 948 atsm->res = htonl(GNUNET_SYSERR);
960 atsm->addr_len = htonl (0); 949 atsm->addr_len = htonl(0);
961 GNUNET_MQ_send (tc->mq, env); 950 GNUNET_MQ_send(tc->mq, env);
962 env = GNUNET_MQ_msg (atsm, 951 env = GNUNET_MQ_msg(atsm,
963 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY); 952 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
964 atsm->res = htonl (GNUNET_OK); 953 atsm->res = htonl(GNUNET_OK);
965 atsm->addr_len = htonl (0); 954 atsm->addr_len = htonl(0);
966 GNUNET_MQ_send (tc->mq, env); 955 GNUNET_MQ_send(tc->mq, env);
967 return; 956 return;
968 } 957 }
969 actx = GNUNET_new (struct AddressToStringContext); 958 actx = GNUNET_new(struct AddressToStringContext);
970 actx->tc = tc; 959 actx->tc = tc;
971 GNUNET_CONTAINER_DLL_insert (a2s_head, a2s_tail, actx); 960 GNUNET_CONTAINER_DLL_insert(a2s_head, a2s_tail, actx);
972 GNUNET_SERVICE_client_disable_continue_warning (tc->client); 961 GNUNET_SERVICE_client_disable_continue_warning(tc->client);
973 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 962 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
974 "Pretty-printing address of %u bytes using plugin `%s'\n", 963 "Pretty-printing address of %u bytes using plugin `%s'\n",
975 address_len, 964 address_len,
976 plugin_name); 965 plugin_name);
977 papi->address_pretty_printer (papi->cls, 966 papi->address_pretty_printer(papi->cls,
978 plugin_name, 967 plugin_name,
979 address, 968 address,
980 address_len, 969 address_len,
981 numeric, 970 numeric,
982 rtimeout, 971 rtimeout,
983 &transmit_address_to_client, 972 &transmit_address_to_client,
984 actx); 973 actx);
985} 974}
986 975
987 976
@@ -993,7 +982,7 @@ handle_client_address_to_string (void *cls,
993 * @return composed message 982 * @return composed message
994 */ 983 */
995static struct PeerIterateResponseMessage * 984static struct PeerIterateResponseMessage *
996compose_address_iterate_response_message ( 985compose_address_iterate_response_message(
997 const struct GNUNET_PeerIdentity *peer, 986 const struct GNUNET_PeerIdentity *peer,
998 const struct GNUNET_HELLO_Address *address) 987 const struct GNUNET_HELLO_Address *address)
999{ 988{
@@ -1003,34 +992,34 @@ compose_address_iterate_response_message (
1003 size_t alen; 992 size_t alen;
1004 char *addr; 993 char *addr;
1005 994
1006 GNUNET_assert (NULL != peer); 995 GNUNET_assert(NULL != peer);
1007 if (NULL != address) 996 if (NULL != address)
1008 { 997 {
1009 tlen = strlen (address->transport_name) + 1; 998 tlen = strlen(address->transport_name) + 1;
1010 alen = address->address_length; 999 alen = address->address_length;
1011 } 1000 }
1012 else 1001 else
1013 { 1002 {
1014 tlen = 0; 1003 tlen = 0;
1015 alen = 0; 1004 alen = 0;
1016 } 1005 }
1017 size = (sizeof (struct PeerIterateResponseMessage) + alen + tlen); 1006 size = (sizeof(struct PeerIterateResponseMessage) + alen + tlen);
1018 msg = GNUNET_malloc (size); 1007 msg = GNUNET_malloc(size);
1019 msg->header.size = htons (size); 1008 msg->header.size = htons(size);
1020 msg->header.type = 1009 msg->header.type =
1021 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE); 1010 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE);
1022 msg->reserved = htonl (0); 1011 msg->reserved = htonl(0);
1023 msg->peer = *peer; 1012 msg->peer = *peer;
1024 msg->addrlen = htonl (alen); 1013 msg->addrlen = htonl(alen);
1025 msg->pluginlen = htonl (tlen); 1014 msg->pluginlen = htonl(tlen);
1026 1015
1027 if (NULL != address) 1016 if (NULL != address)
1028 { 1017 {
1029 msg->local_address_info = htonl ((uint32_t) address->local_info); 1018 msg->local_address_info = htonl((uint32_t)address->local_info);
1030 addr = (char *) &msg[1]; 1019 addr = (char *)&msg[1];
1031 GNUNET_memcpy (addr, address->address, alen); 1020 GNUNET_memcpy(addr, address->address, alen);
1032 GNUNET_memcpy (&addr[alen], address->transport_name, tlen); 1021 GNUNET_memcpy(&addr[alen], address->transport_name, tlen);
1033 } 1022 }
1034 return msg; 1023 return msg;
1035} 1024}
1036 1025
@@ -1039,8 +1028,7 @@ compose_address_iterate_response_message (
1039 * Context for #send_validation_information() and 1028 * Context for #send_validation_information() and
1040 * #send_peer_information(). 1029 * #send_peer_information().
1041 */ 1030 */
1042struct IterationContext 1031struct IterationContext {
1043{
1044 /** 1032 /**
1045 * Context to use for the transmission. 1033 * Context to use for the transmission.
1046 */ 1034 */
@@ -1070,31 +1058,31 @@ struct IterationContext
1070 * @param bandwidth_out outbound quota in NBO 1058 * @param bandwidth_out outbound quota in NBO
1071 */ 1059 */
1072static void 1060static void
1073send_peer_information (void *cls, 1061send_peer_information(void *cls,
1074 const struct GNUNET_PeerIdentity *peer, 1062 const struct GNUNET_PeerIdentity *peer,
1075 const struct GNUNET_HELLO_Address *address, 1063 const struct GNUNET_HELLO_Address *address,
1076 enum GNUNET_TRANSPORT_PeerState state, 1064 enum GNUNET_TRANSPORT_PeerState state,
1077 struct GNUNET_TIME_Absolute state_timeout, 1065 struct GNUNET_TIME_Absolute state_timeout,
1078 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1066 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1079 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1067 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1080{ 1068{
1081 struct IterationContext *pc = cls; 1069 struct IterationContext *pc = cls;
1082 struct GNUNET_MQ_Envelope *env; 1070 struct GNUNET_MQ_Envelope *env;
1083 struct PeerIterateResponseMessage *msg; 1071 struct PeerIterateResponseMessage *msg;
1084 1072
1085 if ((GNUNET_YES != pc->all) && (0 != memcmp (peer, &pc->id, sizeof (pc->id)))) 1073 if ((GNUNET_YES != pc->all) && (0 != memcmp(peer, &pc->id, sizeof(pc->id))))
1086 return; 1074 return;
1087 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1088 "Sending information about `%s' using address `%s' in state `%s'\n", 1076 "Sending information about `%s' using address `%s' in state `%s'\n",
1089 GNUNET_i2s (peer), 1077 GNUNET_i2s(peer),
1090 (NULL != address) ? GST_plugins_a2s (address) : "<none>", 1078 (NULL != address) ? GST_plugins_a2s(address) : "<none>",
1091 GNUNET_TRANSPORT_ps2s (state)); 1079 GNUNET_TRANSPORT_ps2s(state));
1092 msg = compose_address_iterate_response_message (peer, address); 1080 msg = compose_address_iterate_response_message(peer, address);
1093 msg->state = htonl (state); 1081 msg->state = htonl(state);
1094 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); 1082 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1095 env = GNUNET_MQ_msg_copy (&msg->header); 1083 env = GNUNET_MQ_msg_copy(&msg->header);
1096 GNUNET_free (msg); 1084 GNUNET_free(msg);
1097 GNUNET_MQ_send (pc->tc->mq, env); 1085 GNUNET_MQ_send(pc->tc->mq, env);
1098} 1086}
1099 1087
1100 1088
@@ -1106,61 +1094,61 @@ send_peer_information (void *cls,
1106 * @param msg the peer address information request 1094 * @param msg the peer address information request
1107 */ 1095 */
1108static void 1096static void
1109handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg) 1097handle_client_monitor_peers(void *cls, const struct PeerMonitorMessage *msg)
1110{ 1098{
1111 struct TransportClient *tc = cls; 1099 struct TransportClient *tc = cls;
1112 struct IterationContext pc; 1100 struct IterationContext pc;
1113 1101
1114 if (CT_NONE != tc->type) 1102 if (CT_NONE != tc->type)
1115 { 1103 {
1116 GNUNET_break (0); 1104 GNUNET_break(0);
1117 GNUNET_SERVICE_client_drop (tc->client); 1105 GNUNET_SERVICE_client_drop(tc->client);
1118 return; 1106 return;
1119 } 1107 }
1120 GNUNET_SERVICE_client_disable_continue_warning (tc->client); 1108 GNUNET_SERVICE_client_disable_continue_warning(tc->client);
1121 GNUNET_SERVICE_client_mark_monitor (tc->client); 1109 GNUNET_SERVICE_client_mark_monitor(tc->client);
1122 1110
1123 /* Send initial list */ 1111 /* Send initial list */
1124 pc.tc = tc; 1112 pc.tc = tc;
1125 if (0 == memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) 1113 if (0 == memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1126 { 1114 {
1127 /* iterate over all neighbours */ 1115 /* iterate over all neighbours */
1128 pc.all = GNUNET_YES; 1116 pc.all = GNUNET_YES;
1129 pc.id = msg->peer; 1117 pc.id = msg->peer;
1130 } 1118 }
1131 else 1119 else
1132 { 1120 {
1133 /* just return one neighbour */ 1121 /* just return one neighbour */
1134 pc.all = GNUNET_NO; 1122 pc.all = GNUNET_NO;
1135 pc.id = msg->peer; 1123 pc.id = msg->peer;
1136 } 1124 }
1137 GST_neighbours_iterate (&send_peer_information, &pc); 1125 GST_neighbours_iterate(&send_peer_information, &pc);
1138 1126
1139 if (GNUNET_YES != ntohl (msg->one_shot)) 1127 if (GNUNET_YES != ntohl(msg->one_shot))
1140 { 1128 {
1141 tc->details.monitor_peer = msg->peer; 1129 tc->details.monitor_peer = msg->peer;
1142 tc->type = CT_MONITOR; 1130 tc->type = CT_MONITOR;
1143 if (0 != 1131 if (0 !=
1144 memcmp (&msg->peer, &all_zeros, sizeof (struct GNUNET_PeerIdentity))) 1132 memcmp(&msg->peer, &all_zeros, sizeof(struct GNUNET_PeerIdentity)))
1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1133 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1146 "Client %p started monitoring of the peer `%s'\n", 1134 "Client %p started monitoring of the peer `%s'\n",
1147 tc, 1135 tc,
1148 GNUNET_i2s (&msg->peer)); 1136 GNUNET_i2s(&msg->peer));
1149 else 1137 else
1150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1138 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1151 "Client %p started monitoring all peers\n", 1139 "Client %p started monitoring all peers\n",
1152 tc); 1140 tc);
1153 } 1141 }
1154 else 1142 else
1155 { 1143 {
1156 struct GNUNET_MessageHeader *msg; 1144 struct GNUNET_MessageHeader *msg;
1157 struct GNUNET_MQ_Envelope *env; 1145 struct GNUNET_MQ_Envelope *env;
1158 1146
1159 env = 1147 env =
1160 GNUNET_MQ_msg (msg, 1148 GNUNET_MQ_msg(msg,
1161 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END); 1149 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END);
1162 GNUNET_MQ_send (tc->mq, env); 1150 GNUNET_MQ_send(tc->mq, env);
1163 } 1151 }
1164} 1152}
1165 1153
1166 1154
@@ -1177,9 +1165,9 @@ handle_client_monitor_peers (void *cls, const struct PeerMonitorMessage *msg)
1177 * merely signalling that the initial iteration is over 1165 * merely signalling that the initial iteration is over
1178 */ 1166 */
1179static void 1167static void
1180plugin_session_info_cb (void *cls, 1168plugin_session_info_cb(void *cls,
1181 struct GNUNET_ATS_Session *session, 1169 struct GNUNET_ATS_Session *session,
1182 const struct GNUNET_TRANSPORT_SessionInfo *info) 1170 const struct GNUNET_TRANSPORT_SessionInfo *info)
1183{ 1171{
1184 struct GNUNET_MQ_Envelope *env; 1172 struct GNUNET_MQ_Envelope *env;
1185 struct TransportPluginMonitorMessage *msg; 1173 struct TransportPluginMonitorMessage *msg;
@@ -1190,65 +1178,65 @@ plugin_session_info_cb (void *cls,
1190 char *name; 1178 char *name;
1191 char *addr; 1179 char *addr;
1192 1180
1193 if (0 == GNUNET_notification_context_get_size (plugin_nc)) 1181 if (0 == GNUNET_notification_context_get_size(plugin_nc))
1194 { 1182 {
1195 GST_plugins_monitor_subscribe (NULL, NULL); 1183 GST_plugins_monitor_subscribe(NULL, NULL);
1196 return; 1184 return;
1197 } 1185 }
1198 if ((NULL == info) && (NULL == session)) 1186 if ((NULL == info) && (NULL == session))
1199 {
1200 /* end of initial iteration */
1201 if (NULL != sync_client)
1202 { 1187 {
1203 env = 1188 /* end of initial iteration */
1204 GNUNET_MQ_msg (sync, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC); 1189 if (NULL != sync_client)
1205 GNUNET_MQ_send (sync_client->mq, env); 1190 {
1206 sync_client = NULL; 1191 env =
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;
1207 } 1197 }
1208 return; 1198 GNUNET_assert(NULL != info);
1209 } 1199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1210 GNUNET_assert (NULL != info); 1200 "Plugin event for peer %s on transport %s\n",
1211 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1201 GNUNET_i2s(&info->address->peer),
1212 "Plugin event for peer %s on transport %s\n", 1202 info->address->transport_name);
1213 GNUNET_i2s (&info->address->peer), 1203 slen = strlen(info->address->transport_name) + 1;
1214 info->address->transport_name);
1215 slen = strlen (info->address->transport_name) + 1;
1216 alen = info->address->address_length; 1204 alen = info->address->address_length;
1217 size = sizeof (struct TransportPluginMonitorMessage) + slen + alen; 1205 size = sizeof(struct TransportPluginMonitorMessage) + slen + alen;
1218 if (size > UINT16_MAX) 1206 if (size > UINT16_MAX)
1219 { 1207 {
1220 GNUNET_break (0); 1208 GNUNET_break(0);
1221 return; 1209 return;
1222 } 1210 }
1223 msg = GNUNET_malloc (size); 1211 msg = GNUNET_malloc(size);
1224 msg->header.size = htons (size); 1212 msg->header.size = htons(size);
1225 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT); 1213 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT);
1226 msg->session_state = htons ((uint16_t) info->state); 1214 msg->session_state = htons((uint16_t)info->state);
1227 msg->is_inbound = htons ((int16_t) info->is_inbound); 1215 msg->is_inbound = htons((int16_t)info->is_inbound);
1228 msg->msgs_pending = htonl (info->num_msg_pending); 1216 msg->msgs_pending = htonl(info->num_msg_pending);
1229 msg->bytes_pending = htonl (info->num_bytes_pending); 1217 msg->bytes_pending = htonl(info->num_bytes_pending);
1230 msg->timeout = GNUNET_TIME_absolute_hton (info->session_timeout); 1218 msg->timeout = GNUNET_TIME_absolute_hton(info->session_timeout);
1231 msg->delay = GNUNET_TIME_absolute_hton (info->receive_delay); 1219 msg->delay = GNUNET_TIME_absolute_hton(info->receive_delay);
1232 msg->peer = info->address->peer; 1220 msg->peer = info->address->peer;
1233 msg->session_id = (uint64_t) (intptr_t) session; 1221 msg->session_id = (uint64_t)(intptr_t)session;
1234 msg->plugin_name_len = htons (slen); 1222 msg->plugin_name_len = htons(slen);
1235 msg->plugin_address_len = htons (alen); 1223 msg->plugin_address_len = htons(alen);
1236 name = (char *) &msg[1]; 1224 name = (char *)&msg[1];
1237 GNUNET_memcpy (name, info->address->transport_name, slen); 1225 GNUNET_memcpy(name, info->address->transport_name, slen);
1238 addr = &name[slen]; 1226 addr = &name[slen];
1239 GNUNET_memcpy (addr, info->address->address, alen); 1227 GNUNET_memcpy(addr, info->address->address, alen);
1240 if (NULL != sync_client) 1228 if (NULL != sync_client)
1241 { 1229 {
1242 struct GNUNET_MQ_Envelope *env; 1230 struct GNUNET_MQ_Envelope *env;
1243 1231
1244 env = GNUNET_MQ_msg_copy (&msg->header); 1232 env = GNUNET_MQ_msg_copy(&msg->header);
1245 GNUNET_MQ_send (sync_client->mq, env); 1233 GNUNET_MQ_send(sync_client->mq, env);
1246 } 1234 }
1247 else 1235 else
1248 { 1236 {
1249 GNUNET_notification_context_broadcast (plugin_nc, &msg->header, GNUNET_NO); 1237 GNUNET_notification_context_broadcast(plugin_nc, &msg->header, GNUNET_NO);
1250 } 1238 }
1251 GNUNET_free (msg); 1239 GNUNET_free(msg);
1252} 1240}
1253 1241
1254 1242
@@ -1259,17 +1247,17 @@ plugin_session_info_cb (void *cls,
1259 * @param message the peer address information request 1247 * @param message the peer address information request
1260 */ 1248 */
1261static void 1249static void
1262handle_client_monitor_plugins (void *cls, 1250handle_client_monitor_plugins(void *cls,
1263 const struct GNUNET_MessageHeader *message) 1251 const struct GNUNET_MessageHeader *message)
1264{ 1252{
1265 struct TransportClient *tc = cls; 1253 struct TransportClient *tc = cls;
1266 1254
1267 GNUNET_SERVICE_client_mark_monitor (tc->client); 1255 GNUNET_SERVICE_client_mark_monitor(tc->client);
1268 GNUNET_SERVICE_client_disable_continue_warning (tc->client); 1256 GNUNET_SERVICE_client_disable_continue_warning(tc->client);
1269 GNUNET_notification_context_add (plugin_nc, tc->mq); 1257 GNUNET_notification_context_add(plugin_nc, tc->mq);
1270 GNUNET_assert (NULL == sync_client); 1258 GNUNET_assert(NULL == sync_client);
1271 sync_client = tc; 1259 sync_client = tc;
1272 GST_plugins_monitor_subscribe (&plugin_session_info_cb, NULL); 1260 GST_plugins_monitor_subscribe(&plugin_session_info_cb, NULL);
1273} 1261}
1274 1262
1275 1263
@@ -1280,28 +1268,28 @@ handle_client_monitor_plugins (void *cls,
1280 * @param may_drop #GNUNET_YES if the message can be dropped / is payload 1268 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
1281 */ 1269 */
1282void 1270void
1283GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop) 1271GST_clients_broadcast(const struct GNUNET_MessageHeader *msg, int may_drop)
1284{ 1272{
1285 int done; 1273 int done;
1286 1274
1287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1275 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1288 "Asked to broadcast message of type %u with %u bytes\n", 1276 "Asked to broadcast message of type %u with %u bytes\n",
1289 (unsigned int) ntohs (msg->type), 1277 (unsigned int)ntohs(msg->type),
1290 (unsigned int) ntohs (msg->size)); 1278 (unsigned int)ntohs(msg->size));
1291 done = GNUNET_NO; 1279 done = GNUNET_NO;
1292 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 1280 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1293 { 1281 {
1294 if (CT_NONE == tc->type) 1282 if (CT_NONE == tc->type)
1295 continue; /* client not yet ready */ 1283 continue; /* client not yet ready */
1296 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type)) 1284 if ((GNUNET_YES == may_drop) && (CT_CORE != tc->type))
1297 continue; /* skip, this client does not care about payload */ 1285 continue; /* skip, this client does not care about payload */
1298 unicast (tc, msg, may_drop); 1286 unicast(tc, msg, may_drop);
1299 done = GNUNET_YES; 1287 done = GNUNET_YES;
1300 } 1288 }
1301 if (GNUNET_NO == done) 1289 if (GNUNET_NO == done)
1302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1303 "Message of type %u not delivered, is CORE service up?\n", 1291 "Message of type %u not delivered, is CORE service up?\n",
1304 ntohs (msg->type)); 1292 ntohs(msg->type));
1305} 1293}
1306 1294
1307 1295
@@ -1314,7 +1302,7 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
1314 * @param state_timeout the time out for the state 1302 * @param state_timeout the time out for the state
1315 */ 1303 */
1316void 1304void
1317GST_clients_broadcast_peer_notification ( 1305GST_clients_broadcast_peer_notification(
1318 const struct GNUNET_PeerIdentity *peer, 1306 const struct GNUNET_PeerIdentity *peer,
1319 const struct GNUNET_HELLO_Address *address, 1307 const struct GNUNET_HELLO_Address *address,
1320 enum GNUNET_TRANSPORT_PeerState state, 1308 enum GNUNET_TRANSPORT_PeerState state,
@@ -1323,25 +1311,25 @@ GST_clients_broadcast_peer_notification (
1323 struct GNUNET_MQ_Envelope *env; 1311 struct GNUNET_MQ_Envelope *env;
1324 struct PeerIterateResponseMessage *msg; 1312 struct PeerIterateResponseMessage *msg;
1325 1313
1326 msg = compose_address_iterate_response_message (peer, address); 1314 msg = compose_address_iterate_response_message(peer, address);
1327 msg->state = htonl (state); 1315 msg->state = htonl(state);
1328 msg->state_timeout = GNUNET_TIME_absolute_hton (state_timeout); 1316 msg->state_timeout = GNUNET_TIME_absolute_hton(state_timeout);
1329 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next) 1317 for (struct TransportClient *tc = clients_head; NULL != tc; tc = tc->next)
1330 { 1318 {
1331 if (CT_MONITOR != tc->type) 1319 if (CT_MONITOR != tc->type)
1332 continue; 1320 continue;
1333 if ((0 == memcmp (&tc->details.monitor_peer, 1321 if ((0 == memcmp(&tc->details.monitor_peer,
1334 &all_zeros, 1322 &all_zeros,
1335 sizeof (struct GNUNET_PeerIdentity))) || 1323 sizeof(struct GNUNET_PeerIdentity))) ||
1336 (0 == memcmp (&tc->details.monitor_peer, 1324 (0 == memcmp(&tc->details.monitor_peer,
1337 peer, 1325 peer,
1338 sizeof (struct GNUNET_PeerIdentity)))) 1326 sizeof(struct GNUNET_PeerIdentity))))
1339 { 1327 {
1340 env = GNUNET_MQ_msg_copy (&msg->header); 1328 env = GNUNET_MQ_msg_copy(&msg->header);
1341 GNUNET_MQ_send (tc->mq, env); 1329 GNUNET_MQ_send(tc->mq, env);
1330 }
1342 } 1331 }
1343 } 1332 GNUNET_free(msg);
1344 GNUNET_free (msg);
1345} 1333}
1346 1334
1347 1335
@@ -1355,7 +1343,7 @@ GST_clients_broadcast_peer_notification (
1355 * @return #GNUNET_OK (continue to iterate) 1343 * @return #GNUNET_OK (continue to iterate)
1356 */ 1344 */
1357static int 1345static int
1358mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value) 1346mark_peer_down(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1359{ 1347{
1360 struct SendTransmitContinuationContext *stcc = value; 1348 struct SendTransmitContinuationContext *stcc = value;
1361 1349
@@ -1371,19 +1359,19 @@ mark_peer_down (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
1371 * @param peer peer that disconnected 1359 * @param peer peer that disconnected
1372 */ 1360 */
1373void 1361void
1374GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer) 1362GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer)
1375{ 1363{
1376 struct DisconnectInfoMessage disconnect_msg; 1364 struct DisconnectInfoMessage disconnect_msg;
1377 1365
1378 GNUNET_CONTAINER_multipeermap_get_multiple (active_stccs, 1366 GNUNET_CONTAINER_multipeermap_get_multiple(active_stccs,
1379 peer, 1367 peer,
1380 &mark_peer_down, 1368 &mark_peer_down,
1381 NULL); 1369 NULL);
1382 disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage)); 1370 disconnect_msg.header.size = htons(sizeof(struct DisconnectInfoMessage));
1383 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 1371 disconnect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
1384 disconnect_msg.reserved = htonl (0); 1372 disconnect_msg.reserved = htonl(0);
1385 disconnect_msg.peer = *peer; 1373 disconnect_msg.peer = *peer;
1386 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO); 1374 GST_clients_broadcast(&disconnect_msg.header, GNUNET_NO);
1387} 1375}
1388 1376
1389 1377
@@ -1399,27 +1387,27 @@ GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer)
1399 * @param bandwidth_out outbound quota in NBO 1387 * @param bandwidth_out outbound quota in NBO
1400 */ 1388 */
1401static void 1389static void
1402transmit_our_hello (void *cls, 1390transmit_our_hello(void *cls,
1403 const struct GNUNET_PeerIdentity *peer, 1391 const struct GNUNET_PeerIdentity *peer,
1404 const struct GNUNET_HELLO_Address *address, 1392 const struct GNUNET_HELLO_Address *address,
1405 enum GNUNET_TRANSPORT_PeerState state, 1393 enum GNUNET_TRANSPORT_PeerState state,
1406 struct GNUNET_TIME_Absolute state_timeout, 1394 struct GNUNET_TIME_Absolute state_timeout,
1407 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1395 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1408 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1396 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1409{ 1397{
1410 const struct GNUNET_MessageHeader *hello = cls; 1398 const struct GNUNET_MessageHeader *hello = cls;
1411 1399
1412 if (0 == memcmp (peer, &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))) 1400 if (0 == memcmp(peer, &GST_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1413 return; /* not to ourselves */ 1401 return; /* not to ourselves */
1414 if (GNUNET_NO == GST_neighbours_test_connected (peer)) 1402 if (GNUNET_NO == GST_neighbours_test_connected(peer))
1415 return; 1403 return;
1416 1404
1417 GST_neighbours_send (peer, 1405 GST_neighbours_send(peer,
1418 hello, 1406 hello,
1419 ntohs (hello->size), 1407 ntohs(hello->size),
1420 hello_expiration, 1408 hello_expiration,
1421 NULL, 1409 NULL,
1422 NULL); 1410 NULL);
1423} 1411}
1424 1412
1425 1413
@@ -1430,12 +1418,12 @@ transmit_our_hello (void *cls,
1430 * @param hello new HELLO 1418 * @param hello new HELLO
1431 */ 1419 */
1432static void 1420static void
1433process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) 1421process_hello_update(void *cls, const struct GNUNET_MessageHeader *hello)
1434{ 1422{
1435 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n"); 1423 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to clients\n");
1436 GST_clients_broadcast (hello, GNUNET_NO); 1424 GST_clients_broadcast(hello, GNUNET_NO);
1437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n"); 1425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Broadcasting HELLO to neighbours\n");
1438 GST_neighbours_iterate (&transmit_our_hello, (void *) hello); 1426 GST_neighbours_iterate(&transmit_our_hello, (void *)hello);
1439} 1427}
1440 1428
1441 1429
@@ -1450,44 +1438,44 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
1450 * @return how long the plugin should wait until receiving more data 1438 * @return how long the plugin should wait until receiving more data
1451 */ 1439 */
1452static struct GNUNET_TIME_Relative 1440static struct GNUNET_TIME_Relative
1453process_payload (const struct GNUNET_HELLO_Address *address, 1441process_payload(const struct GNUNET_HELLO_Address *address,
1454 struct GNUNET_ATS_Session *session, 1442 struct GNUNET_ATS_Session *session,
1455 const struct GNUNET_MessageHeader *message) 1443 const struct GNUNET_MessageHeader *message)
1456{ 1444{
1457 struct GNUNET_TIME_Relative ret; 1445 struct GNUNET_TIME_Relative ret;
1458 int do_forward; 1446 int do_forward;
1459 struct InboundMessage *im; 1447 struct InboundMessage *im;
1460 size_t msg_size = ntohs (message->size); 1448 size_t msg_size = ntohs(message->size);
1461 size_t size = sizeof (struct InboundMessage) + msg_size; 1449 size_t size = sizeof(struct InboundMessage) + msg_size;
1462 char buf[size] GNUNET_ALIGN; 1450 char buf[size] GNUNET_ALIGN;
1463 1451
1464 do_forward = GNUNET_SYSERR; 1452 do_forward = GNUNET_SYSERR;
1465 ret = GST_neighbours_calculate_receive_delay (&address->peer, 1453 ret = GST_neighbours_calculate_receive_delay(&address->peer,
1466 msg_size, 1454 msg_size,
1467 &do_forward); 1455 &do_forward);
1468 if (! GST_neighbours_test_connected (&address->peer)) 1456 if (!GST_neighbours_test_connected(&address->peer))
1469 { 1457 {
1470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1458 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1471 "Discarded %u bytes type %u payload from peer `%s'\n", 1459 "Discarded %u bytes type %u payload from peer `%s'\n",
1472 (unsigned int) msg_size, 1460 (unsigned int)msg_size,
1473 ntohs (message->type), 1461 ntohs(message->type),
1474 GNUNET_i2s (&address->peer)); 1462 GNUNET_i2s(&address->peer));
1475 GNUNET_STATISTICS_update ( 1463 GNUNET_STATISTICS_update(
1476 GST_stats, 1464 GST_stats,
1477 gettext_noop ("# bytes payload discarded due to not connected peer"), 1465 gettext_noop("# bytes payload discarded due to not connected peer"),
1478 msg_size, 1466 msg_size,
1479 GNUNET_NO); 1467 GNUNET_NO);
1480 return ret; 1468 return ret;
1481 } 1469 }
1482 1470
1483 if (GNUNET_YES != do_forward) 1471 if (GNUNET_YES != do_forward)
1484 return ret; 1472 return ret;
1485 im = (struct InboundMessage *) buf; 1473 im = (struct InboundMessage *)buf;
1486 im->header.size = htons (size); 1474 im->header.size = htons(size);
1487 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 1475 im->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
1488 im->peer = address->peer; 1476 im->peer = address->peer;
1489 GNUNET_memcpy (&im[1], message, ntohs (message->size)); 1477 GNUNET_memcpy(&im[1], message, ntohs(message->size));
1490 GST_clients_broadcast (&im->header, GNUNET_YES); 1478 GST_clients_broadcast(&im->header, GNUNET_YES);
1491 return ret; 1479 return ret;
1492} 1480}
1493 1481
@@ -1498,14 +1486,14 @@ process_payload (const struct GNUNET_HELLO_Address *address,
1498 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill 1486 * @param cls the `struct GNUNET_ATS_SessionKiller` with the information for the kill
1499 */ 1487 */
1500static void 1488static void
1501kill_session_task (void *cls) 1489kill_session_task(void *cls)
1502{ 1490{
1503 struct GNUNET_ATS_SessionKiller *sk = cls; 1491 struct GNUNET_ATS_SessionKiller *sk = cls;
1504 1492
1505 sk->task = NULL; 1493 sk->task = NULL;
1506 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); 1494 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk);
1507 sk->plugin->disconnect_session (sk->plugin->cls, sk->session); 1495 sk->plugin->disconnect_session(sk->plugin->cls, sk->session);
1508 GNUNET_free (sk); 1496 GNUNET_free(sk);
1509} 1497}
1510 1498
1511 1499
@@ -1517,7 +1505,7 @@ kill_session_task (void *cls)
1517 * @param session session to termiante 1505 * @param session session to termiante
1518 */ 1506 */
1519static void 1507static void
1520kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session) 1508kill_session(const char *plugin_name, struct GNUNET_ATS_Session *session)
1521{ 1509{
1522 struct GNUNET_TRANSPORT_PluginFunctions *plugin; 1510 struct GNUNET_TRANSPORT_PluginFunctions *plugin;
1523 struct GNUNET_ATS_SessionKiller *sk; 1511 struct GNUNET_ATS_SessionKiller *sk;
@@ -1525,18 +1513,18 @@ kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session)
1525 for (sk = sk_head; NULL != sk; sk = sk->next) 1513 for (sk = sk_head; NULL != sk; sk = sk->next)
1526 if (sk->session == session) 1514 if (sk->session == session)
1527 return; 1515 return;
1528 plugin = GST_plugins_find (plugin_name); 1516 plugin = GST_plugins_find(plugin_name);
1529 if (NULL == plugin) 1517 if (NULL == plugin)
1530 { 1518 {
1531 GNUNET_break (0); 1519 GNUNET_break(0);
1532 return; 1520 return;
1533 } 1521 }
1534 /* need to issue disconnect asynchronously */ 1522 /* need to issue disconnect asynchronously */
1535 sk = GNUNET_new (struct GNUNET_ATS_SessionKiller); 1523 sk = GNUNET_new(struct GNUNET_ATS_SessionKiller);
1536 sk->session = session; 1524 sk->session = session;
1537 sk->plugin = plugin; 1525 sk->plugin = plugin;
1538 sk->task = GNUNET_SCHEDULER_add_now (&kill_session_task, sk); 1526 sk->task = GNUNET_SCHEDULER_add_now(&kill_session_task, sk);
1539 GNUNET_CONTAINER_DLL_insert (sk_head, sk_tail, sk); 1527 GNUNET_CONTAINER_DLL_insert(sk_head, sk_tail, sk);
1540} 1528}
1541 1529
1542 1530
@@ -1551,37 +1539,37 @@ kill_session (const char *plugin_name, struct GNUNET_ATS_Session *session)
1551 * @param result the result 1539 * @param result the result
1552 */ 1540 */
1553static void 1541static void
1554connect_bl_check_cont (void *cls, 1542connect_bl_check_cont(void *cls,
1555 const struct GNUNET_PeerIdentity *peer, 1543 const struct GNUNET_PeerIdentity *peer,
1556 const struct GNUNET_HELLO_Address *address, 1544 const struct GNUNET_HELLO_Address *address,
1557 struct GNUNET_ATS_Session *session, 1545 struct GNUNET_ATS_Session *session,
1558 int result) 1546 int result)
1559{ 1547{
1560 struct GNUNET_MessageHeader *msg = cls; 1548 struct GNUNET_MessageHeader *msg = cls;
1561 1549
1562 if (GNUNET_OK == result) 1550 if (GNUNET_OK == result)
1563 {
1564 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1565 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1566 "Received SYN message from peer `%s' at `%s'\n",
1567 GNUNET_i2s (peer),
1568 GST_plugins_a2s (address));
1569 if (GNUNET_OK != GST_neighbours_handle_session_syn (msg, peer))
1570 { 1551 {
1571 GST_blacklist_abort_matching (address, session); 1552 /* Blacklist allows to speak to this peer, forward SYN to neighbours */
1572 kill_session (address->transport_name, session); 1553 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
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;
1573 } 1564 }
1574 GNUNET_free (msg); 1565 GNUNET_free(msg);
1575 return;
1576 }
1577 GNUNET_free (msg);
1578 if (GNUNET_SYSERR == result) 1566 if (GNUNET_SYSERR == result)
1579 return; /* check was aborted, session destroyed */ 1567 return; /* check was aborted, session destroyed */
1580 /* Blacklist denies to speak to this peer */ 1568 /* Blacklist denies to speak to this peer */
1581 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1569 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1582 "Discarding SYN message from `%s' due to denied blacklist check\n", 1570 "Discarding SYN message from `%s' due to denied blacklist check\n",
1583 GNUNET_i2s (peer)); 1571 GNUNET_i2s(peer));
1584 kill_session (address->transport_name, session); 1572 kill_session(address->transport_name, session);
1585} 1573}
1586 1574
1587 1575
@@ -1599,10 +1587,10 @@ connect_bl_check_cont (void *cls,
1599 * (plugins that do not support this, can ignore the return value) 1587 * (plugins that do not support this, can ignore the return value)
1600 */ 1588 */
1601struct GNUNET_TIME_Relative 1589struct GNUNET_TIME_Relative
1602GST_receive_callback (void *cls, 1590GST_receive_callback(void *cls,
1603 const struct GNUNET_HELLO_Address *address, 1591 const struct GNUNET_HELLO_Address *address,
1604 struct GNUNET_ATS_Session *session, 1592 struct GNUNET_ATS_Session *session,
1605 const struct GNUNET_MessageHeader *message) 1593 const struct GNUNET_MessageHeader *message)
1606{ 1594{
1607 const char *plugin_name = cls; 1595 const char *plugin_name = cls;
1608 struct GNUNET_TIME_Relative ret; 1596 struct GNUNET_TIME_Relative ret;
@@ -1611,104 +1599,115 @@ GST_receive_callback (void *cls,
1611 ret = GNUNET_TIME_UNIT_ZERO; 1599 ret = GNUNET_TIME_UNIT_ZERO;
1612 if (NULL == message) 1600 if (NULL == message)
1613 goto end; 1601 goto end;
1614 type = ntohs (message->type); 1602 type = ntohs(message->type);
1615 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1603 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1616 "Received message with type %u from peer `%s' at %s\n", 1604 "Received message with type %u from peer `%s' at %s\n",
1617 type, 1605 type,
1618 GNUNET_i2s (&address->peer), 1606 GNUNET_i2s(&address->peer),
1619 GST_plugins_a2s (address)); 1607 GST_plugins_a2s(address));
1620 1608
1621 GNUNET_STATISTICS_update (GST_stats, 1609 GNUNET_STATISTICS_update(GST_stats,
1622 gettext_noop ("# bytes total received"), 1610 gettext_noop("# bytes total received"),
1623 ntohs (message->size), 1611 ntohs(message->size),
1624 GNUNET_NO); 1612 GNUNET_NO);
1625 GST_neighbours_notify_data_recv (address, message); 1613 GST_neighbours_notify_data_recv(address, message);
1626 switch (type) 1614 switch (type)
1627 {
1628 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1629 /* Legacy HELLO message, discard */
1630 return ret;
1631 case GNUNET_MESSAGE_TYPE_HELLO:
1632 if (GNUNET_OK != GST_validation_handle_hello (message))
1633 { 1615 {
1634 GNUNET_break_op (0); 1616 case GNUNET_MESSAGE_TYPE_HELLO_LEGACY:
1635 GST_blacklist_abort_matching (address, session); 1617 /* Legacy HELLO message, discard */
1636 } 1618 return ret;
1637 return ret; 1619
1638 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 1620 case GNUNET_MESSAGE_TYPE_HELLO:
1639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1621 if (GNUNET_OK != GST_validation_handle_hello(message))
1640 "Processing PING from `%s'\n", 1622 {
1641 GST_plugins_a2s (address)); 1623 GNUNET_break_op(0);
1642 if (GNUNET_OK != 1624 GST_blacklist_abort_matching(address, session);
1643 GST_validation_handle_ping (&address->peer, message, address, session)) 1625 }
1644 { 1626 return ret;
1645 GST_blacklist_abort_matching (address, session); 1627
1646 kill_session (plugin_name, session); 1628 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
1647 } 1629 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1648 break; 1630 "Processing PING from `%s'\n",
1649 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 1631 GST_plugins_a2s(address));
1650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1632 if (GNUNET_OK !=
1651 "Processing PONG from `%s'\n", 1633 GST_validation_handle_ping(&address->peer, message, address, session))
1652 GST_plugins_a2s (address)); 1634 {
1653 if (GNUNET_OK != GST_validation_handle_pong (&address->peer, message)) 1635 GST_blacklist_abort_matching(address, session);
1654 { 1636 kill_session(plugin_name, session);
1655 GNUNET_break_op (0); 1637 }
1656 GST_blacklist_abort_matching (address, session); 1638 break;
1657 kill_session (plugin_name, session); 1639
1658 } 1640 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
1659 break; 1641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1660 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN: 1642 "Processing PONG from `%s'\n",
1661 /* Do blacklist check if communication with this peer is allowed */ 1643 GST_plugins_a2s(address));
1662 (void) GST_blacklist_test_allowed (&address->peer, 1644 if (GNUNET_OK != GST_validation_handle_pong(&address->peer, message))
1645 {
1646 GNUNET_break_op(0);
1647 GST_blacklist_abort_matching(address, session);
1648 kill_session(plugin_name, session);
1649 }
1650 break;
1651
1652 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN:
1653 /* Do blacklist check if communication with this peer is allowed */
1654 (void)GST_blacklist_test_allowed(&address->peer,
1663 NULL, 1655 NULL,
1664 &connect_bl_check_cont, 1656 &connect_bl_check_cont,
1665 GNUNET_copy_message (message), 1657 GNUNET_copy_message(message),
1666 address, 1658 address,
1667 session); 1659 session);
1668 break; 1660 break;
1669 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK: 1661
1670 if (GNUNET_OK != 1662 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK:
1671 GST_neighbours_handle_session_syn_ack (message, address, session)) 1663 if (GNUNET_OK !=
1672 { 1664 GST_neighbours_handle_session_syn_ack(message, address, session))
1673 GST_blacklist_abort_matching (address, session); 1665 {
1674 kill_session (plugin_name, session); 1666 GST_blacklist_abort_matching(address, session);
1675 } 1667 kill_session(plugin_name, session);
1676 break; 1668 }
1677 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: 1669 break;
1678 if (GNUNET_OK != 1670
1679 GST_neighbours_handle_session_ack (message, address, session)) 1671 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK:
1680 { 1672 if (GNUNET_OK !=
1681 GNUNET_break_op (0); 1673 GST_neighbours_handle_session_ack(message, address, session))
1682 GST_blacklist_abort_matching (address, session); 1674 {
1683 kill_session (plugin_name, session); 1675 GNUNET_break_op(0);
1684 } 1676 GST_blacklist_abort_matching(address, session);
1685 break; 1677 kill_session(plugin_name, session);
1686 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 1678 }
1687 GST_neighbours_handle_disconnect_message (&address->peer, message); 1679 break;
1688 break; 1680
1689 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA: 1681 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
1690 GST_neighbours_handle_quota_message (&address->peer, message); 1682 GST_neighbours_handle_disconnect_message(&address->peer, message);
1691 break; 1683 break;
1692 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: 1684
1693 GST_neighbours_keepalive (&address->peer, message); 1685 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA:
1694 break; 1686 GST_neighbours_handle_quota_message(&address->peer, message);
1695 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE: 1687 break;
1696 GST_neighbours_keepalive_response (&address->peer, message); 1688
1697 break; 1689 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
1698 default: 1690 GST_neighbours_keepalive(&address->peer, message);
1699 /* should be payload */ 1691 break;
1700 GNUNET_STATISTICS_update (GST_stats, 1692
1701 gettext_noop ("# bytes payload received"), 1693 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE:
1702 ntohs (message->size), 1694 GST_neighbours_keepalive_response(&address->peer, message);
1703 GNUNET_NO); 1695 break;
1704 ret = process_payload (address, session, message); 1696
1705 break; 1697 default:
1706 } 1698 /* should be payload */
1699 GNUNET_STATISTICS_update(GST_stats,
1700 gettext_noop("# bytes payload received"),
1701 ntohs(message->size),
1702 GNUNET_NO);
1703 ret = process_payload(address, session, message);
1704 break;
1705 }
1707end: 1706end:
1708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1707 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1709 "Allowing receive from peer %s to continue in %s\n", 1708 "Allowing receive from peer %s to continue in %s\n",
1710 GNUNET_i2s (&address->peer), 1709 GNUNET_i2s(&address->peer),
1711 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); 1710 GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES));
1712 return ret; 1711 return ret;
1713} 1712}
1714 1713
@@ -1723,7 +1722,7 @@ end:
1723 * @param address the address to add or remove 1722 * @param address the address to add or remove
1724 */ 1723 */
1725static void 1724static void
1726plugin_env_address_change_notification ( 1725plugin_env_address_change_notification(
1727 void *cls, 1726 void *cls,
1728 int add_remove, 1727 int add_remove,
1729 const struct GNUNET_HELLO_Address *address) 1728 const struct GNUNET_HELLO_Address *address)
@@ -1731,29 +1730,29 @@ plugin_env_address_change_notification (
1731 static int addresses = 0; 1730 static int addresses = 0;
1732 1731
1733 if (GNUNET_YES == add_remove) 1732 if (GNUNET_YES == add_remove)
1734 {
1735 addresses++;
1736 GNUNET_STATISTICS_update (GST_stats, "# transport addresses", 1, GNUNET_NO);
1737 }
1738 else if (GNUNET_NO == add_remove)
1739 {
1740 if (0 == addresses)
1741 { 1733 {
1742 GNUNET_break (0); 1734 addresses++;
1735 GNUNET_STATISTICS_update(GST_stats, "# transport addresses", 1, GNUNET_NO);
1743 } 1736 }
1744 else 1737 else if (GNUNET_NO == add_remove)
1745 { 1738 {
1746 addresses--; 1739 if (0 == addresses)
1747 GNUNET_STATISTICS_update (GST_stats, 1740 {
1748 "# transport addresses", 1741 GNUNET_break(0);
1749 -1, 1742 }
1750 GNUNET_NO); 1743 else
1744 {
1745 addresses--;
1746 GNUNET_STATISTICS_update(GST_stats,
1747 "# transport addresses",
1748 -1,
1749 GNUNET_NO);
1750 }
1751 } 1751 }
1752 } 1752 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1753 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1753 "Transport now has %u addresses to communicate\n",
1754 "Transport now has %u addresses to communicate\n", 1754 addresses);
1755 addresses); 1755 GST_hello_modify_addresses(add_remove, address);
1756 GST_hello_modify_addresses (add_remove, address);
1757} 1756}
1758 1757
1759 1758
@@ -1771,45 +1770,45 @@ plugin_env_address_change_notification (
1771 * @param session which session is being destoyed 1770 * @param session which session is being destoyed
1772 */ 1771 */
1773static void 1772static void
1774plugin_env_session_end (void *cls, 1773plugin_env_session_end(void *cls,
1775 const struct GNUNET_HELLO_Address *address, 1774 const struct GNUNET_HELLO_Address *address,
1776 struct GNUNET_ATS_Session *session) 1775 struct GNUNET_ATS_Session *session)
1777{ 1776{
1778 struct GNUNET_ATS_SessionKiller *sk; 1777 struct GNUNET_ATS_SessionKiller *sk;
1779 1778
1780 if (NULL == address) 1779 if (NULL == address)
1781 { 1780 {
1782 GNUNET_break (0); 1781 GNUNET_break(0);
1783 return; 1782 return;
1784 } 1783 }
1785 if (NULL == session) 1784 if (NULL == session)
1786 { 1785 {
1787 GNUNET_break (0); 1786 GNUNET_break(0);
1788 return; 1787 return;
1789 } 1788 }
1790 GNUNET_assert (strlen (address->transport_name) > 0); 1789 GNUNET_assert(strlen(address->transport_name) > 0);
1791 1790
1792 GNUNET_log ( 1791 GNUNET_log(
1793 GNUNET_ERROR_TYPE_DEBUG, 1792 GNUNET_ERROR_TYPE_DEBUG,
1794 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n", 1793 "Notification from plugin about terminated session %p from peer `%s' address `%s'\n",
1795 session, 1794 session,
1796 GNUNET_i2s (&address->peer), 1795 GNUNET_i2s(&address->peer),
1797 GST_plugins_a2s (address)); 1796 GST_plugins_a2s(address));
1798 1797
1799 GST_neighbours_session_terminated (&address->peer, session); 1798 GST_neighbours_session_terminated(&address->peer, session);
1800 GST_ats_del_session (address, session); 1799 GST_ats_del_session(address, session);
1801 GST_blacklist_abort_matching (address, session); 1800 GST_blacklist_abort_matching(address, session);
1802 1801
1803 for (sk = sk_head; NULL != sk; sk = sk->next) 1802 for (sk = sk_head; NULL != sk; sk = sk->next)
1804 {
1805 if (sk->session == session)
1806 { 1803 {
1807 GNUNET_CONTAINER_DLL_remove (sk_head, sk_tail, sk); 1804 if (sk->session == session)
1808 GNUNET_SCHEDULER_cancel (sk->task); 1805 {
1809 GNUNET_free (sk); 1806 GNUNET_CONTAINER_DLL_remove(sk_head, sk_tail, sk);
1810 break; 1807 GNUNET_SCHEDULER_cancel(sk->task);
1808 GNUNET_free(sk);
1809 break;
1810 }
1811 } 1811 }
1812 }
1813} 1812}
1814 1813
1815 1814
@@ -1825,7 +1824,7 @@ plugin_env_session_end (void *cls,
1825 * @param result the result 1824 * @param result the result
1826 */ 1825 */
1827static void 1826static void
1828plugin_env_session_start_bl_check_cont ( 1827plugin_env_session_start_bl_check_cont(
1829 void *cls, 1828 void *cls,
1830 const struct GNUNET_PeerIdentity *peer, 1829 const struct GNUNET_PeerIdentity *peer,
1831 const struct GNUNET_HELLO_Address *address, 1830 const struct GNUNET_HELLO_Address *address,
@@ -1833,19 +1832,19 @@ plugin_env_session_start_bl_check_cont (
1833 int result) 1832 int result)
1834{ 1833{
1835 if (GNUNET_OK != result) 1834 if (GNUNET_OK != result)
1836 { 1835 {
1837 kill_session (address->transport_name, session); 1836 kill_session(address->transport_name, session);
1838 return; 1837 return;
1839 } 1838 }
1840 if (GNUNET_YES != 1839 if (GNUNET_YES !=
1841 GNUNET_HELLO_address_check_option (address, 1840 GNUNET_HELLO_address_check_option(address,
1842 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1841 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1843 { 1842 {
1844 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1843 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1845 "Informing verifier about inbound session's address `%s'\n", 1844 "Informing verifier about inbound session's address `%s'\n",
1846 GST_plugins_a2s (address)); 1845 GST_plugins_a2s(address));
1847 GST_validation_handle_address (address); 1846 GST_validation_handle_address(address);
1848 } 1847 }
1849} 1848}
1850 1849
1851 1850
@@ -1858,49 +1857,49 @@ plugin_env_session_start_bl_check_cont (
1858 * @param scope network scope information 1857 * @param scope network scope information
1859 */ 1858 */
1860static void 1859static void
1861plugin_env_session_start (void *cls, 1860plugin_env_session_start(void *cls,
1862 const struct GNUNET_HELLO_Address *address, 1861 const struct GNUNET_HELLO_Address *address,
1863 struct GNUNET_ATS_Session *session, 1862 struct GNUNET_ATS_Session *session,
1864 enum GNUNET_NetworkType scope) 1863 enum GNUNET_NetworkType scope)
1865{ 1864{
1866 struct GNUNET_ATS_Properties prop; 1865 struct GNUNET_ATS_Properties prop;
1867 1866
1868 if (NULL == address) 1867 if (NULL == address)
1869 { 1868 {
1870 GNUNET_break (0); 1869 GNUNET_break(0);
1871 return; 1870 return;
1872 } 1871 }
1873 if (NULL == session) 1872 if (NULL == session)
1874 { 1873 {
1875 GNUNET_break (0); 1874 GNUNET_break(0);
1876 return; 1875 return;
1877 } 1876 }
1878 GNUNET_log ( 1877 GNUNET_log(
1879 GNUNET_ERROR_TYPE_INFO, 1878 GNUNET_ERROR_TYPE_INFO,
1880 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n", 1879 "Notification from plugin `%s' about new session from peer `%s' address `%s'\n",
1881 address->transport_name, 1880 address->transport_name,
1882 GNUNET_i2s (&address->peer), 1881 GNUNET_i2s(&address->peer),
1883 GST_plugins_a2s (address)); 1882 GST_plugins_a2s(address));
1884 if (GNUNET_YES == 1883 if (GNUNET_YES ==
1885 GNUNET_HELLO_address_check_option (address, 1884 GNUNET_HELLO_address_check_option(address,
1886 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1885 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1887 { 1886 {
1888 /* inbound is always new, but outbound MAY already be known, but 1887 /* inbound is always new, but outbound MAY already be known, but
1889 for example for UNIX, we have symmetric connections and thus we 1888 for example for UNIX, we have symmetric connections and thus we
1890 may not know the address yet; add if necessary! */ 1889 may not know the address yet; add if necessary! */
1891 /* FIXME: maybe change API here so we just pass scope? */ 1890 /* FIXME: maybe change API here so we just pass scope? */
1892 memset (&prop, 0, sizeof (prop)); 1891 memset(&prop, 0, sizeof(prop));
1893 GNUNET_break (GNUNET_NT_UNSPECIFIED != scope); 1892 GNUNET_break(GNUNET_NT_UNSPECIFIED != scope);
1894 prop.scope = scope; 1893 prop.scope = scope;
1895 GST_ats_add_inbound_address (address, session, &prop); 1894 GST_ats_add_inbound_address(address, session, &prop);
1896 } 1895 }
1897 /* Do blacklist check if communication with this peer is allowed */ 1896 /* Do blacklist check if communication with this peer is allowed */
1898 (void) GST_blacklist_test_allowed (&address->peer, 1897 (void)GST_blacklist_test_allowed(&address->peer,
1899 address->transport_name, 1898 address->transport_name,
1900 &plugin_env_session_start_bl_check_cont, 1899 &plugin_env_session_start_bl_check_cont,
1901 NULL, 1900 NULL,
1902 address, 1901 address,
1903 session); 1902 session);
1904} 1903}
1905 1904
1906 1905
@@ -1916,59 +1915,58 @@ plugin_env_session_start (void *cls,
1916 * @param address address to use (for peer given in address) 1915 * @param address address to use (for peer given in address)
1917 * @param session session to use (if available) 1916 * @param session session to use (if available)
1918 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO, 1917 * @param bandwidth_out assigned outbound bandwidth for the connection in NBO,
1919 * 0 to disconnect from peer 1918 * 0 to disconnect from peer
1920 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO, 1919 * @param bandwidth_in assigned inbound bandwidth for the connection in NBO,
1921 * 0 to disconnect from peer 1920 * 0 to disconnect from peer
1922 * @param ats ATS information 1921 * @param ats ATS information
1923 * @param ats_count number of @a ats elements 1922 * @param ats_count number of @a ats elements
1924 */ 1923 */
1925static void 1924static void
1926ats_request_address_change (void *cls, 1925ats_request_address_change(void *cls,
1927 const struct GNUNET_PeerIdentity *peer, 1926 const struct GNUNET_PeerIdentity *peer,
1928 const struct GNUNET_HELLO_Address *address, 1927 const struct GNUNET_HELLO_Address *address,
1929 struct GNUNET_ATS_Session *session, 1928 struct GNUNET_ATS_Session *session,
1930 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 1929 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
1931 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 1930 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
1932{ 1931{
1933 uint32_t bw_in = ntohl (bandwidth_in.value__); 1932 uint32_t bw_in = ntohl(bandwidth_in.value__);
1934 uint32_t bw_out = ntohl (bandwidth_out.value__); 1933 uint32_t bw_out = ntohl(bandwidth_out.value__);
1935 1934
1936 if (NULL == peer) 1935 if (NULL == peer)
1937 { 1936 {
1938 /* ATS service died, all suggestions become invalid! 1937 /* ATS service died, all suggestions become invalid!
1939 (but we'll keep using the allocations for a little 1938 (but we'll keep using the allocations for a little
1940 while, to keep going while ATS restarts) */ 1939 while, to keep going while ATS restarts) */
1941 /* FIXME: We should drop all 1940 /* FIXME: We should drop all
1942 connections now, as ATS won't explicitly tell 1941 connections now, as ATS won't explicitly tell
1943 us and be unaware of ongoing resource allocations! */ 1942 us and be unaware of ongoing resource allocations! */
1944 return; 1943 return;
1945 } 1944 }
1946 /* ATS tells me to disconnect from peer */ 1945 /* ATS tells me to disconnect from peer */
1947 if ((0 == bw_in) && (0 == bw_out)) 1946 if ((0 == bw_in) && (0 == bw_out))
1948 { 1947 {
1949 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1948 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1950 "ATS tells me to disconnect from peer `%s'\n", 1949 "ATS tells me to disconnect from peer `%s'\n",
1951 GNUNET_i2s (peer)); 1950 GNUNET_i2s(peer));
1952 GST_neighbours_force_disconnect (peer); 1951 GST_neighbours_force_disconnect(peer);
1953 return; 1952 return;
1954 } 1953 }
1955 GNUNET_assert (NULL != address); 1954 GNUNET_assert(NULL != address);
1956 GNUNET_STATISTICS_update (GST_stats, 1955 GNUNET_STATISTICS_update(GST_stats,
1957 "# ATS suggestions received", 1956 "# ATS suggestions received",
1958 1, 1957 1,
1959 GNUNET_NO); 1958 GNUNET_NO);
1960 GST_neighbours_switch_to_address (address, 1959 GST_neighbours_switch_to_address(address,
1961 session, 1960 session,
1962 bandwidth_in, 1961 bandwidth_in,
1963 bandwidth_out); 1962 bandwidth_out);
1964} 1963}
1965 1964
1966 1965
1967/** 1966/**
1968 * Closure for #test_connection_ok(). 1967 * Closure for #test_connection_ok().
1969 */ 1968 */
1970struct TestConnectionContext 1969struct TestConnectionContext {
1971{
1972 /** 1970 /**
1973 * Is this the first neighbour we're checking? 1971 * Is this the first neighbour we're checking?
1974 */ 1972 */
@@ -1993,19 +1991,19 @@ struct TestConnectionContext
1993 * #GNUNET_NO if we must shutdown the connection 1991 * #GNUNET_NO if we must shutdown the connection
1994 */ 1992 */
1995static void 1993static void
1996confirm_or_drop_neighbour (void *cls, 1994confirm_or_drop_neighbour(void *cls,
1997 const struct GNUNET_PeerIdentity *peer, 1995 const struct GNUNET_PeerIdentity *peer,
1998 const struct GNUNET_HELLO_Address *address, 1996 const struct GNUNET_HELLO_Address *address,
1999 struct GNUNET_ATS_Session *session, 1997 struct GNUNET_ATS_Session *session,
2000 int allowed) 1998 int allowed)
2001{ 1999{
2002 if (GNUNET_OK == allowed) 2000 if (GNUNET_OK == allowed)
2003 return; /* we're done */ 2001 return; /* we're done */
2004 GNUNET_STATISTICS_update (GST_stats, 2002 GNUNET_STATISTICS_update(GST_stats,
2005 gettext_noop ("# disconnects due to blacklist"), 2003 gettext_noop("# disconnects due to blacklist"),
2006 1, 2004 1,
2007 GNUNET_NO); 2005 GNUNET_NO);
2008 GST_neighbours_force_disconnect (peer); 2006 GST_neighbours_force_disconnect(peer);
2009} 2007}
2010 2008
2011 2009
@@ -2022,31 +2020,31 @@ confirm_or_drop_neighbour (void *cls,
2022 * @param bandwidth_out bandwidth assigned outbound 2020 * @param bandwidth_out bandwidth assigned outbound
2023 */ 2021 */
2024static void 2022static void
2025test_connection_ok (void *cls, 2023test_connection_ok(void *cls,
2026 const struct GNUNET_PeerIdentity *peer, 2024 const struct GNUNET_PeerIdentity *peer,
2027 const struct GNUNET_HELLO_Address *address, 2025 const struct GNUNET_HELLO_Address *address,
2028 enum GNUNET_TRANSPORT_PeerState state, 2026 enum GNUNET_TRANSPORT_PeerState state,
2029 struct GNUNET_TIME_Absolute state_timeout, 2027 struct GNUNET_TIME_Absolute state_timeout,
2030 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2028 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2031 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2029 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2032{ 2030{
2033 struct TestConnectionContext *tcc = cls; 2031 struct TestConnectionContext *tcc = cls;
2034 struct GST_BlacklistCheck *bc; 2032 struct GST_BlacklistCheck *bc;
2035 2033
2036 bc = GNUNET_new (struct GST_BlacklistCheck); 2034 bc = GNUNET_new(struct GST_BlacklistCheck);
2037 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); 2035 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc);
2038 bc->peer = *peer; 2036 bc->peer = *peer;
2039 bc->address = GNUNET_HELLO_address_copy (address); 2037 bc->address = GNUNET_HELLO_address_copy(address);
2040 bc->cont = &confirm_or_drop_neighbour; 2038 bc->cont = &confirm_or_drop_neighbour;
2041 bc->cont_cls = NULL; 2039 bc->cont_cls = NULL;
2042 bc->bl_pos = tcc->tc; 2040 bc->bl_pos = tcc->tc;
2043 if (GNUNET_YES == tcc->first) 2041 if (GNUNET_YES == tcc->first)
2044 { 2042 {
2045 /* all would wait for the same client, no need to 2043 /* all would wait for the same client, no need to
2046 * create more than just the first task right now */ 2044 * create more than just the first task right now */
2047 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); 2045 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
2048 tcc->first = GNUNET_NO; 2046 tcc->first = GNUNET_NO;
2049 } 2047 }
2050} 2048}
2051 2049
2052 2050
@@ -2059,26 +2057,26 @@ test_connection_ok (void *cls,
2059 * @param message the blacklist-init message that was sent 2057 * @param message the blacklist-init message that was sent
2060 */ 2058 */
2061static void 2059static void
2062handle_client_blacklist_init (void *cls, 2060handle_client_blacklist_init(void *cls,
2063 const struct GNUNET_MessageHeader *message) 2061 const struct GNUNET_MessageHeader *message)
2064{ 2062{
2065 struct TransportClient *tc = cls; 2063 struct TransportClient *tc = cls;
2066 struct TestConnectionContext tcc; 2064 struct TestConnectionContext tcc;
2067 2065
2068 if (CT_NONE != tc->type) 2066 if (CT_NONE != tc->type)
2069 { 2067 {
2070 GNUNET_break (0); 2068 GNUNET_break(0);
2071 GNUNET_SERVICE_client_drop (tc->client); 2069 GNUNET_SERVICE_client_drop(tc->client);
2072 return; 2070 return;
2073 } 2071 }
2074 GNUNET_SERVICE_client_mark_monitor (tc->client); 2072 GNUNET_SERVICE_client_mark_monitor(tc->client);
2075 tc->type = CT_BLACKLIST; 2073 tc->type = CT_BLACKLIST;
2076 tc->details.blacklist.call_receive_done = GNUNET_YES; 2074 tc->details.blacklist.call_receive_done = GNUNET_YES;
2077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc); 2075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "New blacklist client %p\n", tc);
2078 /* confirm that all existing connections are OK! */ 2076 /* confirm that all existing connections are OK! */
2079 tcc.tc = tc; 2077 tcc.tc = tc;
2080 tcc.first = GNUNET_YES; 2078 tcc.first = GNUNET_YES;
2081 GST_neighbours_iterate (&test_connection_ok, &tcc); 2079 GST_neighbours_iterate(&test_connection_ok, &tcc);
2082} 2080}
2083 2081
2084 2082
@@ -2091,13 +2089,13 @@ handle_client_blacklist_init (void *cls,
2091 * @return #GNUNET_OK (continue to iterate) 2089 * @return #GNUNET_OK (continue to iterate)
2092 */ 2090 */
2093static int 2091static int
2094free_blacklist_entry (void *cls, 2092free_blacklist_entry(void *cls,
2095 const struct GNUNET_PeerIdentity *key, 2093 const struct GNUNET_PeerIdentity *key,
2096 void *value) 2094 void *value)
2097{ 2095{
2098 char *be = value; 2096 char *be = value;
2099 2097
2100 GNUNET_free_non_null (be); 2098 GNUNET_free_non_null(be);
2101 return GNUNET_OK; 2099 return GNUNET_OK;
2102} 2100}
2103 2101
@@ -2109,12 +2107,12 @@ free_blacklist_entry (void *cls,
2109 * @param message containing information 2107 * @param message containing information
2110 */ 2108 */
2111static void 2109static void
2112handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm) 2110handle_client_set_metric(void *cls, const struct TrafficMetricMessage *tm)
2113{ 2111{
2114 struct TransportClient *tc = cls; 2112 struct TransportClient *tc = cls;
2115 2113
2116 GST_manipulation_set_metric (tm); 2114 GST_manipulation_set_metric(tm);
2117 GNUNET_SERVICE_client_continue (tc->client); 2115 GNUNET_SERVICE_client_continue(tc->client);
2118} 2116}
2119 2117
2120 2118
@@ -2125,58 +2123,58 @@ handle_client_set_metric (void *cls, const struct TrafficMetricMessage *tm)
2125 * @param cls closure, unused 2123 * @param cls closure, unused
2126 */ 2124 */
2127static void 2125static void
2128shutdown_task (void *cls) 2126shutdown_task(void *cls)
2129{ 2127{
2130 struct AddressToStringContext *cur; 2128 struct AddressToStringContext *cur;
2131 2129
2132 GST_neighbours_stop (); 2130 GST_neighbours_stop();
2133 GST_plugins_unload (); 2131 GST_plugins_unload();
2134 GST_validation_stop (); 2132 GST_validation_stop();
2135 GST_ats_done (); 2133 GST_ats_done();
2136 GNUNET_ATS_scheduling_done (GST_ats); 2134 GNUNET_ATS_scheduling_done(GST_ats);
2137 GST_ats = NULL; 2135 GST_ats = NULL;
2138 GNUNET_ATS_connectivity_done (GST_ats_connect); 2136 GNUNET_ATS_connectivity_done(GST_ats_connect);
2139 GST_ats_connect = NULL; 2137 GST_ats_connect = NULL;
2140 GNUNET_NT_scanner_done (GST_is); 2138 GNUNET_NT_scanner_done(GST_is);
2141 GST_is = NULL; 2139 GST_is = NULL;
2142 while (NULL != (cur = a2s_head)) 2140 while (NULL != (cur = a2s_head))
2143 { 2141 {
2144 GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, cur); 2142 GNUNET_CONTAINER_DLL_remove(a2s_head, a2s_tail, cur);
2145 GNUNET_free (cur); 2143 GNUNET_free(cur);
2146 } 2144 }
2147 if (NULL != plugin_nc) 2145 if (NULL != plugin_nc)
2148 { 2146 {
2149 GNUNET_notification_context_destroy (plugin_nc); 2147 GNUNET_notification_context_destroy(plugin_nc);
2150 plugin_nc = NULL; 2148 plugin_nc = NULL;
2151 } 2149 }
2152 GNUNET_CONTAINER_multipeermap_destroy (active_stccs); 2150 GNUNET_CONTAINER_multipeermap_destroy(active_stccs);
2153 active_stccs = NULL; 2151 active_stccs = NULL;
2154 if (NULL != blacklist) 2152 if (NULL != blacklist)
2155 { 2153 {
2156 GNUNET_CONTAINER_multipeermap_iterate (blacklist, 2154 GNUNET_CONTAINER_multipeermap_iterate(blacklist,
2157 &free_blacklist_entry, 2155 &free_blacklist_entry,
2158 NULL); 2156 NULL);
2159 GNUNET_CONTAINER_multipeermap_destroy (blacklist); 2157 GNUNET_CONTAINER_multipeermap_destroy(blacklist);
2160 blacklist = NULL; 2158 blacklist = NULL;
2161 } 2159 }
2162 GST_hello_stop (); 2160 GST_hello_stop();
2163 GST_manipulation_stop (); 2161 GST_manipulation_stop();
2164 2162
2165 if (NULL != GST_peerinfo) 2163 if (NULL != GST_peerinfo)
2166 { 2164 {
2167 GNUNET_PEERINFO_disconnect (GST_peerinfo); 2165 GNUNET_PEERINFO_disconnect(GST_peerinfo);
2168 GST_peerinfo = NULL; 2166 GST_peerinfo = NULL;
2169 } 2167 }
2170 if (NULL != GST_stats) 2168 if (NULL != GST_stats)
2171 { 2169 {
2172 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 2170 GNUNET_STATISTICS_destroy(GST_stats, GNUNET_NO);
2173 GST_stats = NULL; 2171 GST_stats = NULL;
2174 } 2172 }
2175 if (NULL != GST_my_private_key) 2173 if (NULL != GST_my_private_key)
2176 { 2174 {
2177 GNUNET_free (GST_my_private_key); 2175 GNUNET_free(GST_my_private_key);
2178 GST_my_private_key = NULL; 2176 GST_my_private_key = NULL;
2179 } 2177 }
2180} 2178}
2181 2179
2182 2180
@@ -2186,7 +2184,7 @@ shutdown_task (void *cls)
2186 * @param cls the `struct GST_BlacklistCheck *` 2184 * @param cls the `struct GST_BlacklistCheck *`
2187 */ 2185 */
2188static void 2186static void
2189do_blacklist_check (void *cls) 2187do_blacklist_check(void *cls)
2190{ 2188{
2191 struct GST_BlacklistCheck *bc = cls; 2189 struct GST_BlacklistCheck *bc = cls;
2192 struct TransportClient *tc; 2190 struct TransportClient *tc;
@@ -2195,34 +2193,34 @@ do_blacklist_check (void *cls)
2195 2193
2196 bc->task = NULL; 2194 bc->task = NULL;
2197 while (NULL != (tc = bc->bl_pos)) 2195 while (NULL != (tc = bc->bl_pos))
2198 { 2196 {
2199 if (CT_BLACKLIST == tc->type) 2197 if (CT_BLACKLIST == tc->type)
2200 break; 2198 break;
2201 bc->bl_pos = tc->next; 2199 bc->bl_pos = tc->next;
2202 } 2200 }
2203 if (NULL == tc) 2201 if (NULL == tc)
2204 { 2202 {
2205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2203 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2206 "No other blacklist clients active, will allow neighbour `%s'\n", 2204 "No other blacklist clients active, will allow neighbour `%s'\n",
2207 GNUNET_i2s (&bc->peer)); 2205 GNUNET_i2s(&bc->peer));
2208 2206
2209 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK); 2207 bc->cont(bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_OK);
2210 GST_blacklist_test_cancel (bc); 2208 GST_blacklist_test_cancel(bc);
2211 return; 2209 return;
2212 } 2210 }
2213 if ((NULL != tc->details.blacklist.bc) || 2211 if ((NULL != tc->details.blacklist.bc) ||
2214 (GNUNET_NO != tc->details.blacklist.waiting_for_reply)) 2212 (GNUNET_NO != tc->details.blacklist.waiting_for_reply))
2215 return; /* someone else busy with this client */ 2213 return; /* someone else busy with this client */
2216 tc->details.blacklist.bc = bc; 2214 tc->details.blacklist.bc = bc;
2217 env = GNUNET_MQ_msg (bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY); 2215 env = GNUNET_MQ_msg(bm, GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY);
2218 bm->is_allowed = htonl (0); 2216 bm->is_allowed = htonl(0);
2219 bm->peer = bc->peer; 2217 bm->peer = bc->peer;
2220 GNUNET_MQ_send (tc->mq, env); 2218 GNUNET_MQ_send(tc->mq, env);
2221 if (GNUNET_YES == tc->details.blacklist.call_receive_done) 2219 if (GNUNET_YES == tc->details.blacklist.call_receive_done)
2222 { 2220 {
2223 tc->details.blacklist.call_receive_done = GNUNET_NO; 2221 tc->details.blacklist.call_receive_done = GNUNET_NO;
2224 GNUNET_SERVICE_client_continue (tc->client); 2222 GNUNET_SERVICE_client_continue(tc->client);
2225 } 2223 }
2226 tc->details.blacklist.waiting_for_reply = GNUNET_YES; 2224 tc->details.blacklist.waiting_for_reply = GNUNET_YES;
2227} 2225}
2228 2226
@@ -2234,62 +2232,62 @@ do_blacklist_check (void *cls)
2234 * @param msg the blacklist-reply message that was sent 2232 * @param msg the blacklist-reply message that was sent
2235 */ 2233 */
2236static void 2234static void
2237handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg) 2235handle_client_blacklist_reply(void *cls, const struct BlacklistMessage *msg)
2238{ 2236{
2239 struct TransportClient *tc = cls; 2237 struct TransportClient *tc = cls;
2240 struct GST_BlacklistCheck *bc; 2238 struct GST_BlacklistCheck *bc;
2241 2239
2242 if (CT_BLACKLIST != tc->type) 2240 if (CT_BLACKLIST != tc->type)
2243 { 2241 {
2244 GNUNET_break (0); 2242 GNUNET_break(0);
2245 GNUNET_SERVICE_client_drop (tc->client); 2243 GNUNET_SERVICE_client_drop(tc->client);
2246 return; 2244 return;
2247 } 2245 }
2248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2249 "Blacklist client %p sent reply for `%s'\n", 2247 "Blacklist client %p sent reply for `%s'\n",
2250 tc, 2248 tc,
2251 GNUNET_i2s (&msg->peer)); 2249 GNUNET_i2s(&msg->peer));
2252 bc = tc->details.blacklist.bc; 2250 bc = tc->details.blacklist.bc;
2253 tc->details.blacklist.bc = NULL; 2251 tc->details.blacklist.bc = NULL;
2254 tc->details.blacklist.waiting_for_reply = GNUNET_NO; 2252 tc->details.blacklist.waiting_for_reply = GNUNET_NO;
2255 tc->details.blacklist.call_receive_done = GNUNET_YES; 2253 tc->details.blacklist.call_receive_done = GNUNET_YES;
2256 if (NULL != bc) 2254 if (NULL != bc)
2257 {
2258 /* only run this if the blacklist check has not been
2259 * cancelled in the meantime... */
2260 GNUNET_assert (bc->bl_pos == tc);
2261 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
2262 {
2263 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2264 "Blacklist check failed, peer not allowed\n");
2265 /* For the duration of the continuation, make the ongoing
2266 check invisible (to avoid double-cancellation); then
2267 add it back again so we can re-use GST_blacklist_test_cancel() */
2268 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
2269 bc->cont (bc->cont_cls, &bc->peer, bc->address, bc->session, GNUNET_NO);
2270 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
2271 GST_blacklist_test_cancel (bc);
2272 tc->details.blacklist.call_receive_done = GNUNET_NO;
2273 GNUNET_SERVICE_client_continue (tc->client);
2274 return;
2275 }
2276 else
2277 { 2255 {
2278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2256 /* only run this if the blacklist check has not been
2279 "Blacklist check succeeded, continuing with checks\n"); 2257 * cancelled in the meantime... */
2280 tc->details.blacklist.call_receive_done = GNUNET_NO; 2258 GNUNET_assert(bc->bl_pos == tc);
2281 GNUNET_SERVICE_client_continue (tc->client); 2259 if (ntohl(msg->is_allowed) == GNUNET_SYSERR)
2282 bc->bl_pos = tc->next; 2260 {
2283 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); 2261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
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 }
2284 } 2283 }
2285 }
2286 /* check if any other blacklist checks are waiting for this blacklister */ 2284 /* check if any other blacklist checks are waiting for this blacklister */
2287 for (bc = bc_head; bc != NULL; bc = bc->next) 2285 for (bc = bc_head; bc != NULL; bc = bc->next)
2288 if ((bc->bl_pos == tc) && (NULL == bc->task)) 2286 if ((bc->bl_pos == tc) && (NULL == bc->task))
2289 { 2287 {
2290 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); 2288 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
2291 break; 2289 break;
2292 } 2290 }
2293} 2291}
2294 2292
2295 2293
@@ -2300,32 +2298,32 @@ handle_client_blacklist_reply (void *cls, const struct BlacklistMessage *msg)
2300 * @param transport_name transport to blacklist for this peer, NULL for all 2298 * @param transport_name transport to blacklist for this peer, NULL for all
2301 */ 2299 */
2302void 2300void
2303GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, 2301GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer,
2304 const char *transport_name) 2302 const char *transport_name)
2305{ 2303{
2306 char *transport = NULL; 2304 char *transport = NULL;
2307 2305
2308 if (NULL != transport_name) 2306 if (NULL != transport_name)
2309 { 2307 {
2310 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2308 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2311 "Adding peer `%s' with plugin `%s' to blacklist\n", 2309 "Adding peer `%s' with plugin `%s' to blacklist\n",
2312 GNUNET_i2s (peer), 2310 GNUNET_i2s(peer),
2313 transport_name); 2311 transport_name);
2314 transport = GNUNET_strdup (transport_name); 2312 transport = GNUNET_strdup(transport_name);
2315 } 2313 }
2316 else 2314 else
2317 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2315 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2318 "Adding peer `%s' with all plugins to blacklist\n", 2316 "Adding peer `%s' with all plugins to blacklist\n",
2319 GNUNET_i2s (peer)); 2317 GNUNET_i2s(peer));
2320 if (NULL == blacklist) 2318 if (NULL == blacklist)
2321 blacklist = 2319 blacklist =
2322 GNUNET_CONTAINER_multipeermap_create (TRANSPORT_BLACKLIST_HT_SIZE, 2320 GNUNET_CONTAINER_multipeermap_create(TRANSPORT_BLACKLIST_HT_SIZE,
2323 GNUNET_NO); 2321 GNUNET_NO);
2324 2322
2325 GNUNET_CONTAINER_multipeermap_put (blacklist, 2323 GNUNET_CONTAINER_multipeermap_put(blacklist,
2326 peer, 2324 peer,
2327 transport, 2325 transport,
2328 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2326 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2329} 2327}
2330 2328
2331 2329
@@ -2336,27 +2334,27 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
2336 * @param session session used to abort matching checks 2334 * @param session session used to abort matching checks
2337 */ 2335 */
2338void 2336void
2339GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address, 2337GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address,
2340 struct GNUNET_ATS_Session *session) 2338 struct GNUNET_ATS_Session *session)
2341{ 2339{
2342 struct GST_BlacklistCheck *bc; 2340 struct GST_BlacklistCheck *bc;
2343 struct GST_BlacklistCheck *n; 2341 struct GST_BlacklistCheck *n;
2344 2342
2345 n = bc_head; 2343 n = bc_head;
2346 while (NULL != (bc = n)) 2344 while (NULL != (bc = n))
2347 {
2348 n = bc->next;
2349 if ((bc->session == session) &&
2350 (0 == GNUNET_HELLO_address_cmp (bc->address, address)))
2351 { 2345 {
2352 bc->cont (bc->cont_cls, 2346 n = bc->next;
2353 &bc->peer, 2347 if ((bc->session == session) &&
2354 bc->address, 2348 (0 == GNUNET_HELLO_address_cmp(bc->address, address)))
2355 bc->session, 2349 {
2356 GNUNET_SYSERR); 2350 bc->cont(bc->cont_cls,
2357 GST_blacklist_test_cancel (bc); 2351 &bc->peer,
2352 bc->address,
2353 bc->session,
2354 GNUNET_SYSERR);
2355 GST_blacklist_test_cancel(bc);
2356 }
2358 } 2357 }
2359 }
2360} 2358}
2361 2359
2362 2360
@@ -2370,7 +2368,7 @@ GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
2370 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches 2368 * @return #GNUNET_OK if the entry does not match, #GNUNET_NO if it matches
2371 */ 2369 */
2372static int 2370static int
2373test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 2371test_blacklisted(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2374{ 2372{
2375 const char *transport_name = cls; 2373 const char *transport_name = cls;
2376 char *be = value; 2374 char *be = value;
@@ -2384,21 +2382,21 @@ test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2384 * 2382 *
2385 */ 2383 */
2386 2384
2387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2388 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n", 2386 "Comparing BL request for peer `%4s':`%s' with BL entry: `%s'\n",
2389 GNUNET_i2s (key), 2387 GNUNET_i2s(key),
2390 (NULL == transport_name) ? "unspecified" : transport_name, 2388 (NULL == transport_name) ? "unspecified" : transport_name,
2391 (NULL == be) ? "all plugins" : be); 2389 (NULL == be) ? "all plugins" : be);
2392 /* all plugins for this peer were blacklisted: disallow */ 2390 /* all plugins for this peer were blacklisted: disallow */
2393 if (NULL == value) 2391 if (NULL == value)
2394 return GNUNET_NO; 2392 return GNUNET_NO;
2395 2393
2396 /* blacklist check for specific transport */ 2394 /* blacklist check for specific transport */
2397 if ((NULL != transport_name) && (NULL != value)) 2395 if ((NULL != transport_name) && (NULL != value))
2398 { 2396 {
2399 if (0 == strcmp (transport_name, be)) 2397 if (0 == strcmp(transport_name, be))
2400 return GNUNET_NO; /* plugin is blacklisted! */ 2398 return GNUNET_NO; /* plugin is blacklisted! */
2401 } 2399 }
2402 return GNUNET_OK; 2400 return GNUNET_OK;
2403} 2401}
2404 2402
@@ -2416,70 +2414,70 @@ test_blacklisted (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
2416 * was made instantly and @a cont was already called 2414 * was made instantly and @a cont was already called
2417 */ 2415 */
2418struct GST_BlacklistCheck * 2416struct GST_BlacklistCheck *
2419GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, 2417GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer,
2420 const char *transport_name, 2418 const char *transport_name,
2421 GST_BlacklistTestContinuation cont, 2419 GST_BlacklistTestContinuation cont,
2422 void *cont_cls, 2420 void *cont_cls,
2423 const struct GNUNET_HELLO_Address *address, 2421 const struct GNUNET_HELLO_Address *address,
2424 struct GNUNET_ATS_Session *session) 2422 struct GNUNET_ATS_Session *session)
2425{ 2423{
2426 struct GST_BlacklistCheck *bc; 2424 struct GST_BlacklistCheck *bc;
2427 struct TransportClient *tc; 2425 struct TransportClient *tc;
2428 2426
2429 GNUNET_assert (NULL != peer); 2427 GNUNET_assert(NULL != peer);
2430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2428 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2431 "Blacklist check for peer `%s':%s\n", 2429 "Blacklist check for peer `%s':%s\n",
2432 GNUNET_i2s (peer), 2430 GNUNET_i2s(peer),
2433 (NULL != transport_name) ? transport_name : "unspecified"); 2431 (NULL != transport_name) ? transport_name : "unspecified");
2434 2432
2435 /* Check local blacklist by iterating over hashmap 2433 /* Check local blacklist by iterating over hashmap
2436 * If iteration is aborted, we found a matching blacklist entry */ 2434 * If iteration is aborted, we found a matching blacklist entry */
2437 if ((NULL != blacklist) && 2435 if ((NULL != blacklist) &&
2438 (GNUNET_SYSERR == 2436 (GNUNET_SYSERR ==
2439 GNUNET_CONTAINER_multipeermap_get_multiple (blacklist, 2437 GNUNET_CONTAINER_multipeermap_get_multiple(blacklist,
2440 peer, 2438 peer,
2441 &test_blacklisted, 2439 &test_blacklisted,
2442 (void *) transport_name))) 2440 (void *)transport_name)))
2443 { 2441 {
2444 /* Disallowed by config, disapprove instantly */ 2442 /* Disallowed by config, disapprove instantly */
2445 GNUNET_STATISTICS_update (GST_stats, 2443 GNUNET_STATISTICS_update(GST_stats,
2446 gettext_noop ("# disconnects due to blacklist"), 2444 gettext_noop("# disconnects due to blacklist"),
2447 1, 2445 1,
2448 GNUNET_NO); 2446 GNUNET_NO);
2449 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2447 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2450 _ ("Disallowing connection to peer `%s' on transport %s\n"), 2448 _("Disallowing connection to peer `%s' on transport %s\n"),
2451 GNUNET_i2s (peer), 2449 GNUNET_i2s(peer),
2452 (NULL != transport_name) ? transport_name : "unspecified"); 2450 (NULL != transport_name) ? transport_name : "unspecified");
2453 if (NULL != cont) 2451 if (NULL != cont)
2454 cont (cont_cls, peer, address, session, GNUNET_NO); 2452 cont(cont_cls, peer, address, session, GNUNET_NO);
2455 return NULL; 2453 return NULL;
2456 } 2454 }
2457 2455
2458 for (tc = clients_head; NULL != tc; tc = tc->next) 2456 for (tc = clients_head; NULL != tc; tc = tc->next)
2459 if (CT_BLACKLIST == tc->type) 2457 if (CT_BLACKLIST == tc->type)
2460 break; 2458 break;
2461 if (NULL == tc) 2459 if (NULL == tc)
2462 { 2460 {
2463 /* no blacklist clients, approve instantly */ 2461 /* no blacklist clients, approve instantly */
2464 if (NULL != cont) 2462 if (NULL != cont)
2465 cont (cont_cls, peer, address, session, GNUNET_OK); 2463 cont(cont_cls, peer, address, session, GNUNET_OK);
2466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2464 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2467 "Allowing connection to peer `%s' %s\n", 2465 "Allowing connection to peer `%s' %s\n",
2468 GNUNET_i2s (peer), 2466 GNUNET_i2s(peer),
2469 (NULL != transport_name) ? transport_name : ""); 2467 (NULL != transport_name) ? transport_name : "");
2470 return NULL; 2468 return NULL;
2471 } 2469 }
2472 2470
2473 /* need to query blacklist clients */ 2471 /* need to query blacklist clients */
2474 bc = GNUNET_new (struct GST_BlacklistCheck); 2472 bc = GNUNET_new(struct GST_BlacklistCheck);
2475 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); 2473 GNUNET_CONTAINER_DLL_insert(bc_head, bc_tail, bc);
2476 bc->peer = *peer; 2474 bc->peer = *peer;
2477 bc->address = GNUNET_HELLO_address_copy (address); 2475 bc->address = GNUNET_HELLO_address_copy(address);
2478 bc->session = session; 2476 bc->session = session;
2479 bc->cont = cont; 2477 bc->cont = cont;
2480 bc->cont_cls = cont_cls; 2478 bc->cont_cls = cont_cls;
2481 bc->bl_pos = tc; 2479 bc->bl_pos = tc;
2482 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc); 2480 bc->task = GNUNET_SCHEDULER_add_now(&do_blacklist_check, bc);
2483 return bc; 2481 return bc;
2484} 2482}
2485 2483
@@ -2490,25 +2488,25 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
2490 * @param bc check to cancel 2488 * @param bc check to cancel
2491 */ 2489 */
2492void 2490void
2493GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc) 2491GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc)
2494{ 2492{
2495 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); 2493 GNUNET_CONTAINER_DLL_remove(bc_head, bc_tail, bc);
2496 if (NULL != bc->bl_pos) 2494 if (NULL != bc->bl_pos)
2497 {
2498 if ((CT_BLACKLIST == bc->bl_pos->type) &&
2499 (bc->bl_pos->details.blacklist.bc == bc))
2500 { 2495 {
2501 /* we're at the head of the queue, remove us! */ 2496 if ((CT_BLACKLIST == bc->bl_pos->type) &&
2502 bc->bl_pos->details.blacklist.bc = NULL; 2497 (bc->bl_pos->details.blacklist.bc == bc))
2498 {
2499 /* we're at the head of the queue, remove us! */
2500 bc->bl_pos->details.blacklist.bc = NULL;
2501 }
2503 } 2502 }
2504 }
2505 if (NULL != bc->task) 2503 if (NULL != bc->task)
2506 { 2504 {
2507 GNUNET_SCHEDULER_cancel (bc->task); 2505 GNUNET_SCHEDULER_cancel(bc->task);
2508 bc->task = NULL; 2506 bc->task = NULL;
2509 } 2507 }
2510 GNUNET_free_non_null (bc->address); 2508 GNUNET_free_non_null(bc->address);
2511 GNUNET_free (bc); 2509 GNUNET_free(bc);
2512} 2510}
2513 2511
2514 2512
@@ -2521,10 +2519,10 @@ GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
2521 * @param value value of the option 2519 * @param value value of the option
2522 */ 2520 */
2523static void 2521static void
2524blacklist_cfg_iter (void *cls, 2522blacklist_cfg_iter(void *cls,
2525 const char *section, 2523 const char *section,
2526 const char *option, 2524 const char *option,
2527 const char *value) 2525 const char *value)
2528{ 2526{
2529 unsigned int *res = cls; 2527 unsigned int *res = cls;
2530 struct GNUNET_PeerIdentity peer; 2528 struct GNUNET_PeerIdentity peer;
@@ -2532,32 +2530,32 @@ blacklist_cfg_iter (void *cls,
2532 char *pos; 2530 char *pos;
2533 2531
2534 if (GNUNET_OK != 2532 if (GNUNET_OK !=
2535 GNUNET_CRYPTO_eddsa_public_key_from_string (option, 2533 GNUNET_CRYPTO_eddsa_public_key_from_string(option,
2536 strlen (option), 2534 strlen(option),
2537 &peer.public_key)) 2535 &peer.public_key))
2538 return; 2536 return;
2539 2537
2540 if ((NULL == value) || (0 == strcmp (value, ""))) 2538 if ((NULL == value) || (0 == strcmp(value, "")))
2541 { 2539 {
2542 /* Blacklist whole peer */ 2540 /* Blacklist whole peer */
2543 GST_blacklist_add_peer (&peer, NULL); 2541 GST_blacklist_add_peer(&peer, NULL);
2544 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2542 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2545 _ ("Adding blacklisting entry for peer `%s'\n"), 2543 _("Adding blacklisting entry for peer `%s'\n"),
2546 GNUNET_i2s (&peer)); 2544 GNUNET_i2s(&peer));
2547 } 2545 }
2548 else 2546 else
2549 {
2550 plugs = GNUNET_strdup (value);
2551 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
2552 { 2547 {
2553 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2548 plugs = GNUNET_strdup(value);
2554 _ ("Adding blacklisting entry for peer `%s':`%s'\n"), 2549 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " "))
2555 GNUNET_i2s (&peer), 2550 {
2556 pos); 2551 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2557 GST_blacklist_add_peer (&peer, pos); 2552 _("Adding blacklisting entry for peer `%s':`%s'\n"),
2553 GNUNET_i2s(&peer),
2554 pos);
2555 GST_blacklist_add_peer(&peer, pos);
2556 }
2557 GNUNET_free(plugs);
2558 } 2558 }
2559 GNUNET_free (plugs);
2560 }
2561 (*res)++; 2559 (*res)++;
2562} 2560}
2563 2561
@@ -2569,23 +2567,23 @@ blacklist_cfg_iter (void *cls,
2569 * @param my_id my peer identity 2567 * @param my_id my peer identity
2570 */ 2568 */
2571static void 2569static void
2572read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg, 2570read_blacklist_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg,
2573 const struct GNUNET_PeerIdentity *my_id) 2571 const struct GNUNET_PeerIdentity *my_id)
2574{ 2572{
2575 char cfg_sect[512]; 2573 char cfg_sect[512];
2576 unsigned int res = 0; 2574 unsigned int res = 0;
2577 2575
2578 GNUNET_snprintf (cfg_sect, 2576 GNUNET_snprintf(cfg_sect,
2579 sizeof (cfg_sect), 2577 sizeof(cfg_sect),
2580 "transport-blacklist-%s", 2578 "transport-blacklist-%s",
2581 GNUNET_i2s_full (my_id)); 2579 GNUNET_i2s_full(my_id));
2582 GNUNET_CONFIGURATION_iterate_section_values (cfg, 2580 GNUNET_CONFIGURATION_iterate_section_values(cfg,
2583 cfg_sect, 2581 cfg_sect,
2584 &blacklist_cfg_iter, 2582 &blacklist_cfg_iter,
2585 &res); 2583 &res);
2586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2584 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2587 "Loaded %u blacklisting entries from configuration\n", 2585 "Loaded %u blacklisting entries from configuration\n",
2588 res); 2586 res);
2589} 2587}
2590 2588
2591 2589
@@ -2597,9 +2595,9 @@ read_blacklist_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg,
2597 * @param service the initialized service 2595 * @param service the initialized service
2598 */ 2596 */
2599static void 2597static void
2600run (void *cls, 2598run(void *cls,
2601 const struct GNUNET_CONFIGURATION_Handle *c, 2599 const struct GNUNET_CONFIGURATION_Handle *c,
2602 struct GNUNET_SERVICE_Handle *service) 2600 struct GNUNET_SERVICE_Handle *service)
2603{ 2601{
2604 char *keyfile; 2602 char *keyfile;
2605 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 2603 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
@@ -2610,70 +2608,70 @@ run (void *cls,
2610 2608
2611 /* setup globals */ 2609 /* setup globals */
2612 GST_cfg = c; 2610 GST_cfg = c;
2613 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, 2611 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(c,
2614 "PEER", 2612 "PEER",
2615 "PRIVATE_KEY", 2613 "PRIVATE_KEY",
2616 &keyfile)) 2614 &keyfile))
2617 { 2615 {
2618 GNUNET_log ( 2616 GNUNET_log(
2619 GNUNET_ERROR_TYPE_ERROR, 2617 GNUNET_ERROR_TYPE_ERROR,
2620 _ ( 2618 _(
2621 "Transport service is lacking key configuration settings. Exiting.\n")); 2619 "Transport service is lacking key configuration settings. Exiting.\n"));
2622 GNUNET_SCHEDULER_shutdown (); 2620 GNUNET_SCHEDULER_shutdown();
2623 return; 2621 return;
2624 } 2622 }
2625 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (c, 2623 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(c,
2626 "transport", 2624 "transport",
2627 "HELLO_EXPIRATION", 2625 "HELLO_EXPIRATION",
2628 &hello_expiration)) 2626 &hello_expiration))
2629 { 2627 {
2630 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION; 2628 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
2631 } 2629 }
2632 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); 2630 pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile);
2633 GNUNET_free (keyfile); 2631 GNUNET_free(keyfile);
2634 GNUNET_assert (NULL != pk); 2632 GNUNET_assert(NULL != pk);
2635 GST_my_private_key = pk; 2633 GST_my_private_key = pk;
2636 2634
2637 GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); 2635 GST_stats = GNUNET_STATISTICS_create("transport", GST_cfg);
2638 GST_peerinfo = GNUNET_PEERINFO_connect (GST_cfg); 2636 GST_peerinfo = GNUNET_PEERINFO_connect(GST_cfg);
2639 GNUNET_CRYPTO_eddsa_key_get_public (GST_my_private_key, 2637 GNUNET_CRYPTO_eddsa_key_get_public(GST_my_private_key,
2640 &GST_my_identity.public_key); 2638 &GST_my_identity.public_key);
2641 GNUNET_assert (NULL != GST_my_private_key); 2639 GNUNET_assert(NULL != GST_my_private_key);
2642 2640
2643 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2641 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2644 "My identity is `%s'\n", 2642 "My identity is `%s'\n",
2645 GNUNET_i2s_full (&GST_my_identity)); 2643 GNUNET_i2s_full(&GST_my_identity));
2646 2644
2647 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 2645 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
2648 if (NULL == GST_peerinfo) 2646 if (NULL == GST_peerinfo)
2649 { 2647 {
2650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2648 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2651 _ ("Could not access PEERINFO service. Exiting.\n")); 2649 _("Could not access PEERINFO service. Exiting.\n"));
2652 GNUNET_SCHEDULER_shutdown (); 2650 GNUNET_SCHEDULER_shutdown();
2653 return; 2651 return;
2654 } 2652 }
2655 2653
2656 max_fd_rlimit = 0; 2654 max_fd_rlimit = 0;
2657#if HAVE_GETRLIMIT 2655#if HAVE_GETRLIMIT
2658 { 2656 {
2659 struct rlimit r_file; 2657 struct rlimit r_file;
2660 2658
2661 if (0 == getrlimit (RLIMIT_NOFILE, &r_file)) 2659 if (0 == getrlimit(RLIMIT_NOFILE, &r_file))
2662 { 2660 {
2663 max_fd_rlimit = r_file.rlim_cur; 2661 max_fd_rlimit = r_file.rlim_cur;
2664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2665 "Maximum number of open files was: %u/%u\n", 2663 "Maximum number of open files was: %u/%u\n",
2666 (unsigned int) r_file.rlim_cur, 2664 (unsigned int)r_file.rlim_cur,
2667 (unsigned int) r_file.rlim_max); 2665 (unsigned int)r_file.rlim_max);
2668 } 2666 }
2669 max_fd_rlimit = 2667 max_fd_rlimit =
2670 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */ 2668 (9 * max_fd_rlimit) / 10; /* Keep 10% for rest of transport */
2671 } 2669 }
2672#endif 2670#endif
2673 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (GST_cfg, 2671 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(GST_cfg,
2674 "transport", 2672 "transport",
2675 "MAX_FD", 2673 "MAX_FD",
2676 &max_fd_cfg)) 2674 &max_fd_cfg))
2677 max_fd_cfg = max_fd_rlimit; 2675 max_fd_cfg = max_fd_rlimit;
2678 2676
2679 if (max_fd_cfg > max_fd_rlimit) 2677 if (max_fd_cfg > max_fd_rlimit)
@@ -2683,14 +2681,14 @@ run (void *cls,
2683 if (max_fd < DEFAULT_MAX_FDS) 2681 if (max_fd < DEFAULT_MAX_FDS)
2684 max_fd = DEFAULT_MAX_FDS; 2682 max_fd = DEFAULT_MAX_FDS;
2685 2683
2686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2684 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2687 "Limiting number of sockets to %u: validation %u, neighbors: %u\n", 2685 "Limiting number of sockets to %u: validation %u, neighbors: %u\n",
2688 max_fd, 2686 max_fd,
2689 (max_fd / 3), 2687 (max_fd / 3),
2690 (max_fd / 3) * 2); 2688 (max_fd / 3) * 2);
2691 2689
2692 friend_only = 2690 friend_only =
2693 GNUNET_CONFIGURATION_get_value_yesno (GST_cfg, "topology", "FRIENDS-ONLY"); 2691 GNUNET_CONFIGURATION_get_value_yesno(GST_cfg, "topology", "FRIENDS-ONLY");
2694 if (GNUNET_SYSERR == friend_only) 2692 if (GNUNET_SYSERR == friend_only)
2695 friend_only = GNUNET_NO; /* According to topology defaults */ 2693 friend_only = GNUNET_NO; /* According to topology defaults */
2696 /* start subsystems */ 2694 /* start subsystems */
@@ -2699,79 +2697,79 @@ run (void *cls,
2699 struct GNUNET_PeerIdentity dstj; 2697 struct GNUNET_PeerIdentity dstj;
2700 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0"; 2698 const char *ds = "DSTJBRRKZ8TBW3FGK6B0M5QXWT9WYNZ45H5MCV4HY7ST64Q8T9F0";
2701 2699
2702 GNUNET_assert ( 2700 GNUNET_assert(
2703 GNUNET_OK == 2701 GNUNET_OK ==
2704 GNUNET_CRYPTO_eddsa_public_key_from_string (ds, 2702 GNUNET_CRYPTO_eddsa_public_key_from_string(ds,
2705 strlen (ds), 2703 strlen(ds),
2706 &dstj.public_key)); 2704 &dstj.public_key));
2707 GST_blacklist_add_peer (&dstj, NULL); 2705 GST_blacklist_add_peer(&dstj, NULL);
2708 } 2706 }
2709 read_blacklist_configuration (GST_cfg, &GST_my_identity); 2707 read_blacklist_configuration(GST_cfg, &GST_my_identity);
2710 GST_is = GNUNET_NT_scanner_init (); 2708 GST_is = GNUNET_NT_scanner_init();
2711 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg); 2709 GST_ats_connect = GNUNET_ATS_connectivity_init(GST_cfg);
2712 GST_ats = 2710 GST_ats =
2713 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); 2711 GNUNET_ATS_scheduling_init(GST_cfg, &ats_request_address_change, NULL);
2714 GST_ats_init (); 2712 GST_ats_init();
2715 GST_manipulation_init (); 2713 GST_manipulation_init();
2716 GST_plugins_load (&GST_manipulation_recv, 2714 GST_plugins_load(&GST_manipulation_recv,
2717 &plugin_env_address_change_notification, 2715 &plugin_env_address_change_notification,
2718 &plugin_env_session_start, 2716 &plugin_env_session_start,
2719 &plugin_env_session_end); 2717 &plugin_env_session_end);
2720 GST_hello_start (friend_only, &process_hello_update, NULL); 2718 GST_hello_start(friend_only, &process_hello_update, NULL);
2721 GST_neighbours_start ((max_fd / 3) * 2); 2719 GST_neighbours_start((max_fd / 3) * 2);
2722 active_stccs = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); 2720 active_stccs = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES);
2723 plugin_nc = GNUNET_notification_context_create (0); 2721 plugin_nc = GNUNET_notification_context_create(0);
2724 GST_validation_start ((max_fd / 3)); 2722 GST_validation_start((max_fd / 3));
2725} 2723}
2726 2724
2727 2725
2728/** 2726/**
2729 * Define "main" method using service macro. 2727 * Define "main" method using service macro.
2730 */ 2728 */
2731GNUNET_SERVICE_MAIN ( 2729GNUNET_SERVICE_MAIN(
2732 "transport", 2730 "transport",
2733 GNUNET_SERVICE_OPTION_NONE, 2731 GNUNET_SERVICE_OPTION_NONE,
2734 &run, 2732 &run,
2735 &client_connect_cb, 2733 &client_connect_cb,
2736 &client_disconnect_cb, 2734 &client_disconnect_cb,
2737 NULL, 2735 NULL,
2738 GNUNET_MQ_hd_fixed_size (client_start, 2736 GNUNET_MQ_hd_fixed_size(client_start,
2739 GNUNET_MESSAGE_TYPE_TRANSPORT_START, 2737 GNUNET_MESSAGE_TYPE_TRANSPORT_START,
2740 struct StartMessage, 2738 struct StartMessage,
2741 NULL), 2739 NULL),
2742 GNUNET_MQ_hd_var_size (client_hello, 2740 GNUNET_MQ_hd_var_size(client_hello,
2743 GNUNET_MESSAGE_TYPE_HELLO, 2741 GNUNET_MESSAGE_TYPE_HELLO,
2744 struct GNUNET_MessageHeader, 2742 struct GNUNET_MessageHeader,
2745 NULL), 2743 NULL),
2746 GNUNET_MQ_hd_var_size (client_send, 2744 GNUNET_MQ_hd_var_size(client_send,
2747 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 2745 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND,
2748 struct OutboundMessage, 2746 struct OutboundMessage,
2749 NULL), 2747 NULL),
2750 GNUNET_MQ_hd_var_size (client_address_to_string, 2748 GNUNET_MQ_hd_var_size(client_address_to_string,
2751 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING, 2749 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING,
2752 struct AddressLookupMessage, 2750 struct AddressLookupMessage,
2753 NULL), 2751 NULL),
2754 GNUNET_MQ_hd_fixed_size (client_monitor_peers, 2752 GNUNET_MQ_hd_fixed_size(client_monitor_peers,
2755 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST, 2753 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST,
2756 struct PeerMonitorMessage, 2754 struct PeerMonitorMessage,
2757 NULL), 2755 NULL),
2758 GNUNET_MQ_hd_fixed_size (client_blacklist_init, 2756 GNUNET_MQ_hd_fixed_size(client_blacklist_init,
2759 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, 2757 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
2760 struct GNUNET_MessageHeader, 2758 struct GNUNET_MessageHeader,
2761 NULL), 2759 NULL),
2762 GNUNET_MQ_hd_fixed_size (client_blacklist_reply, 2760 GNUNET_MQ_hd_fixed_size(client_blacklist_reply,
2763 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, 2761 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
2764 struct BlacklistMessage, 2762 struct BlacklistMessage,
2765 NULL), 2763 NULL),
2766 GNUNET_MQ_hd_fixed_size (client_set_metric, 2764 GNUNET_MQ_hd_fixed_size(client_set_metric,
2767 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC, 2765 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC,
2768 struct TrafficMetricMessage, 2766 struct TrafficMetricMessage,
2769 NULL), 2767 NULL),
2770 GNUNET_MQ_hd_fixed_size (client_monitor_plugins, 2768 GNUNET_MQ_hd_fixed_size(client_monitor_plugins,
2771 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START, 2769 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START,
2772 struct GNUNET_MessageHeader, 2770 struct GNUNET_MessageHeader,
2773 NULL), 2771 NULL),
2774 GNUNET_MQ_handler_end ()); 2772 GNUNET_MQ_handler_end());
2775 2773
2776 2774
2777/* end of file gnunet-service-transport.c */ 2775/* end of file gnunet-service-transport.c */
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index 467469064..fb42f1fae 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport.h 22 * @file transport/gnunet-service-transport.h
@@ -83,12 +83,12 @@ 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 GNUNET_PeerIdentity *peer,
87 const struct GNUNET_HELLO_Address *address, 87 const struct GNUNET_HELLO_Address *address,
88 enum GNUNET_TRANSPORT_PeerState state, 88 enum GNUNET_TRANSPORT_PeerState state,
89 struct GNUNET_TIME_Absolute state_timeout, 89 struct GNUNET_TIME_Absolute state_timeout,
90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
91 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); 91 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
92 92
93 93
94/** 94/**
@@ -105,8 +105,8 @@ typedef void
105typedef void 105typedef void
106(*GST_BlacklistTestContinuation) (void *cls, 106(*GST_BlacklistTestContinuation) (void *cls,
107 const struct GNUNET_PeerIdentity *peer, 107 const struct GNUNET_PeerIdentity *peer,
108 const struct GNUNET_HELLO_Address *address, 108 const struct GNUNET_HELLO_Address *address,
109 struct GNUNET_ATS_Session *session, 109 struct GNUNET_ATS_Session *session,
110 int result); 110 int result);
111 111
112 112
@@ -117,8 +117,8 @@ typedef void
117 * @param transport_name transport to blacklist for this peer, NULL for all 117 * @param transport_name transport to blacklist for this peer, NULL for all
118 */ 118 */
119void 119void
120GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, 120GST_blacklist_add_peer(const struct GNUNET_PeerIdentity *peer,
121 const char *transport_name); 121 const char *transport_name);
122 122
123 123
124/** 124/**
@@ -141,12 +141,12 @@ struct GST_BlacklistCheck;
141 * was made instantly and @a cont was already called 141 * was made instantly and @a cont was already called
142 */ 142 */
143struct GST_BlacklistCheck * 143struct GST_BlacklistCheck *
144GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, 144GST_blacklist_test_allowed(const struct GNUNET_PeerIdentity *peer,
145 const char *transport_name, 145 const char *transport_name,
146 GST_BlacklistTestContinuation cont, 146 GST_BlacklistTestContinuation cont,
147 void *cont_cls, 147 void *cont_cls,
148 const struct GNUNET_HELLO_Address *address, 148 const struct GNUNET_HELLO_Address *address,
149 struct GNUNET_ATS_Session *session); 149 struct GNUNET_ATS_Session *session);
150 150
151 151
152/** 152/**
@@ -156,8 +156,8 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
156 * @param session session used to abort matching checks 156 * @param session session used to abort matching checks
157 */ 157 */
158void 158void
159GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address, 159GST_blacklist_abort_matching(const struct GNUNET_HELLO_Address *address,
160 struct GNUNET_ATS_Session *session); 160 struct GNUNET_ATS_Session *session);
161 161
162/** 162/**
163 * Cancel a blacklist check. 163 * Cancel a blacklist check.
@@ -165,7 +165,7 @@ GST_blacklist_abort_matching (const struct GNUNET_HELLO_Address *address,
165 * @param bc check to cancel 165 * @param bc check to cancel
166 */ 166 */
167void 167void
168GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc); 168GST_blacklist_test_cancel(struct GST_BlacklistCheck *bc);
169 169
170 170
171/** 171/**
@@ -182,10 +182,10 @@ GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
182 * (plugins that do not support this, can ignore the return value) 182 * (plugins that do not support this, can ignore the return value)
183 */ 183 */
184struct GNUNET_TIME_Relative 184struct GNUNET_TIME_Relative
185GST_receive_callback (void *cls, 185GST_receive_callback(void *cls,
186 const struct GNUNET_HELLO_Address *address, 186 const struct GNUNET_HELLO_Address *address,
187 struct GNUNET_ATS_Session *session, 187 struct GNUNET_ATS_Session *session,
188 const struct GNUNET_MessageHeader *message); 188 const struct GNUNET_MessageHeader *message);
189 189
190/** 190/**
191 * Broadcast the given message to all of our clients. 191 * Broadcast the given message to all of our clients.
@@ -194,8 +194,8 @@ GST_receive_callback (void *cls,
194 * @param may_drop #GNUNET_YES if the message can be dropped / is payload 194 * @param may_drop #GNUNET_YES if the message can be dropped / is payload
195 */ 195 */
196void 196void
197GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, 197GST_clients_broadcast(const struct GNUNET_MessageHeader *msg,
198 int may_drop); 198 int may_drop);
199 199
200 200
201/** 201/**
@@ -207,10 +207,10 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
207 * @param state_timeout the time out for the state 207 * @param state_timeout the time out for the state
208 */ 208 */
209void 209void
210GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer, 210GST_clients_broadcast_peer_notification(const struct GNUNET_PeerIdentity *peer,
211 const struct GNUNET_HELLO_Address *address, 211 const struct GNUNET_HELLO_Address *address,
212 enum GNUNET_TRANSPORT_PeerState state, 212 enum GNUNET_TRANSPORT_PeerState state,
213 struct GNUNET_TIME_Absolute state_timeout); 213 struct GNUNET_TIME_Absolute state_timeout);
214 214
215 215
216/** 216/**
@@ -220,7 +220,7 @@ GST_clients_broadcast_peer_notification (const struct GNUNET_PeerIdentity *peer,
220 * @param peer peer that disconnected 220 * @param peer peer that disconnected
221 */ 221 */
222void 222void
223GST_clients_broadcast_disconnect (const struct GNUNET_PeerIdentity *peer); 223GST_clients_broadcast_disconnect(const struct GNUNET_PeerIdentity *peer);
224 224
225 225
226 226
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index f8756c750..555302813 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/gnunet-service-transport_ats.c 21 * @file transport/gnunet-service-transport_ats.c
22 * @brief interfacing between transport and ATS service 22 * @brief interfacing between transport and ATS service
@@ -32,15 +32,13 @@
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{
43
44 /** 42 /**
45 * The address (with peer identity). Must never change 43 * The address (with peer identity). Must never change
46 * while this struct is in the #p2a map. 44 * while this struct is in the #p2a map.
@@ -89,7 +87,6 @@ struct AddressInfo
89 * not yet remove it because we still have a valid session. 87 * not yet remove it because we still have a valid session.
90 */ 88 */
91 int expired; 89 int expired;
92
93}; 90};
94 91
95 92
@@ -108,9 +105,7 @@ static unsigned int num_blocked;
108/** 105/**
109 * Closure for #find_ai_cb() and #find_ai_no_session_cb(). 106 * Closure for #find_ai_cb() and #find_ai_no_session_cb().
110 */ 107 */
111struct FindClosure 108struct FindClosure {
112{
113
114 /** 109 /**
115 * Session to look for (only used if the address is inbound). 110 * Session to look for (only used if the address is inbound).
116 */ 111 */
@@ -125,7 +120,6 @@ struct FindClosure
125 * Where to store the result. 120 * Where to store the result.
126 */ 121 */
127 struct AddressInfo *ret; 122 struct AddressInfo *ret;
128
129}; 123};
130 124
131 125
@@ -135,16 +129,16 @@ struct FindClosure
135 * is changed. 129 * is changed.
136 */ 130 */
137static void 131static void
138publish_p2a_stat_update () 132publish_p2a_stat_update()
139{ 133{
140 GNUNET_STATISTICS_set (GST_stats, 134 GNUNET_STATISTICS_set(GST_stats,
141 gettext_noop ("# Addresses given to ATS"), 135 gettext_noop("# Addresses given to ATS"),
142 GNUNET_CONTAINER_multipeermap_size (p2a) - num_blocked, 136 GNUNET_CONTAINER_multipeermap_size(p2a) - num_blocked,
143 GNUNET_NO); 137 GNUNET_NO);
144 GNUNET_STATISTICS_set (GST_stats, 138 GNUNET_STATISTICS_set(GST_stats,
145 "# blocked addresses", 139 "# blocked addresses",
146 num_blocked, 140 num_blocked,
147 GNUNET_NO); 141 GNUNET_NO);
148} 142}
149 143
150 144
@@ -159,21 +153,21 @@ publish_p2a_stat_update ()
159 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value 153 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
160 */ 154 */
161static int 155static int
162find_ai_cb (void *cls, 156find_ai_cb(void *cls,
163 const struct GNUNET_PeerIdentity *key, 157 const struct GNUNET_PeerIdentity *key,
164 void *value) 158 void *value)
165{ 159{
166 struct FindClosure *fc = cls; 160 struct FindClosure *fc = cls;
167 struct AddressInfo *ai = value; 161 struct AddressInfo *ai = value;
168 162
169 if ( (0 == 163 if ((0 ==
170 GNUNET_HELLO_address_cmp (fc->address, 164 GNUNET_HELLO_address_cmp(fc->address,
171 ai->address) ) && 165 ai->address)) &&
172 (fc->session == ai->session) ) 166 (fc->session == ai->session))
173 { 167 {
174 fc->ret = ai; 168 fc->ret = ai;
175 return GNUNET_NO; 169 return GNUNET_NO;
176 } 170 }
177 return GNUNET_YES; 171 return GNUNET_YES;
178} 172}
179 173
@@ -187,18 +181,18 @@ find_ai_cb (void *cls,
187 * @return NULL if this combination is unknown 181 * @return NULL if this combination is unknown
188 */ 182 */
189static struct AddressInfo * 183static struct AddressInfo *
190find_ai (const struct GNUNET_HELLO_Address *address, 184find_ai(const struct GNUNET_HELLO_Address *address,
191 struct GNUNET_ATS_Session *session) 185 struct GNUNET_ATS_Session *session)
192{ 186{
193 struct FindClosure fc; 187 struct FindClosure fc;
194 188
195 fc.address = address; 189 fc.address = address;
196 fc.session = session; 190 fc.session = session;
197 fc.ret = NULL; 191 fc.ret = NULL;
198 GNUNET_CONTAINER_multipeermap_get_multiple (p2a, 192 GNUNET_CONTAINER_multipeermap_get_multiple(p2a,
199 &address->peer, 193 &address->peer,
200 &find_ai_cb, 194 &find_ai_cb,
201 &fc); 195 &fc);
202 return fc.ret; 196 return fc.ret;
203} 197}
204 198
@@ -213,9 +207,9 @@ find_ai (const struct GNUNET_HELLO_Address *address,
213 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value 207 * @return #GNUNET_YES to continue to iterate, #GNUNET_NO if we found the value
214 */ 208 */
215static int 209static int
216find_ai_no_session_cb (void *cls, 210find_ai_no_session_cb(void *cls,
217 const struct GNUNET_PeerIdentity *key, 211 const struct GNUNET_PeerIdentity *key,
218 void *value) 212 void *value)
219{ 213{
220 struct FindClosure *fc = cls; 214 struct FindClosure *fc = cls;
221 struct AddressInfo *ai = value; 215 struct AddressInfo *ai = value;
@@ -223,12 +217,12 @@ find_ai_no_session_cb (void *cls,
223 if (ai->expired) 217 if (ai->expired)
224 return GNUNET_YES; /* expired do not count here */ 218 return GNUNET_YES; /* expired do not count here */
225 if (0 == 219 if (0 ==
226 GNUNET_HELLO_address_cmp (fc->address, 220 GNUNET_HELLO_address_cmp(fc->address,
227 ai->address)) 221 ai->address))
228 { 222 {
229 fc->ret = ai; 223 fc->ret = ai;
230 return GNUNET_NO; 224 return GNUNET_NO;
231 } 225 }
232 return GNUNET_YES; 226 return GNUNET_YES;
233} 227}
234 228
@@ -241,17 +235,17 @@ find_ai_no_session_cb (void *cls,
241 * @return NULL if this combination is unknown 235 * @return NULL if this combination is unknown
242 */ 236 */
243static struct AddressInfo * 237static struct AddressInfo *
244find_ai_no_session (const struct GNUNET_HELLO_Address *address) 238find_ai_no_session(const struct GNUNET_HELLO_Address *address)
245{ 239{
246 struct FindClosure fc; 240 struct FindClosure fc;
247 241
248 fc.address = address; 242 fc.address = address;
249 fc.session = NULL; 243 fc.session = NULL;
250 fc.ret = NULL; 244 fc.ret = NULL;
251 GNUNET_CONTAINER_multipeermap_get_multiple (p2a, 245 GNUNET_CONTAINER_multipeermap_get_multiple(p2a,
252 &address->peer, 246 &address->peer,
253 &find_ai_no_session_cb, 247 &find_ai_no_session_cb,
254 &fc); 248 &fc);
255 return fc.ret; 249 return fc.ret;
256} 250}
257 251
@@ -266,10 +260,10 @@ find_ai_no_session (const struct GNUNET_HELLO_Address *address)
266 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. 260 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
267 */ 261 */
268int 262int
269GST_ats_is_known (const struct GNUNET_HELLO_Address *address, 263GST_ats_is_known(const struct GNUNET_HELLO_Address *address,
270 struct GNUNET_ATS_Session *session) 264 struct GNUNET_ATS_Session *session)
271{ 265{
272 return (NULL != find_ai (address, session)) ? GNUNET_YES : GNUNET_NO; 266 return (NULL != find_ai(address, session)) ? GNUNET_YES : GNUNET_NO;
273} 267}
274 268
275 269
@@ -281,11 +275,11 @@ GST_ats_is_known (const struct GNUNET_HELLO_Address *address,
281 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not. 275 * @return #GNUNET_YES if @a address is known, #GNUNET_NO if not.
282 */ 276 */
283int 277int
284GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address) 278GST_ats_is_known_no_session(const struct GNUNET_HELLO_Address *address)
285{ 279{
286 return (NULL != find_ai_no_session (address)) 280 return (NULL != find_ai_no_session(address))
287 ? GNUNET_YES 281 ? GNUNET_YES
288 : GNUNET_NO; 282 : GNUNET_NO;
289} 283}
290 284
291 285
@@ -296,22 +290,22 @@ GST_ats_is_known_no_session (const struct GNUNET_HELLO_Address *address)
296 * @param cls the `struct AddressInfo` of the address to unblock 290 * @param cls the `struct AddressInfo` of the address to unblock
297 */ 291 */
298static void 292static void
299unblock_address (void *cls) 293unblock_address(void *cls)
300{ 294{
301 struct AddressInfo *ai = cls; 295 struct AddressInfo *ai = cls;
302 296
303 ai->unblock_task = NULL; 297 ai->unblock_task = NULL;
304 LOG (GNUNET_ERROR_TYPE_DEBUG, 298 LOG(GNUNET_ERROR_TYPE_DEBUG,
305 "Unblocking address %s of peer %s\n", 299 "Unblocking address %s of peer %s\n",
306 GST_plugins_a2s (ai->address), 300 GST_plugins_a2s(ai->address),
307 GNUNET_i2s (&ai->address->peer)); 301 GNUNET_i2s(&ai->address->peer));
308 ai->ar = GNUNET_ATS_address_add (GST_ats, 302 ai->ar = GNUNET_ATS_address_add(GST_ats,
309 ai->address, 303 ai->address,
310 ai->session, 304 ai->session,
311 &ai->properties); 305 &ai->properties);
312 GNUNET_break (NULL != ai->ar); 306 GNUNET_break(NULL != ai->ar);
313 num_blocked--; 307 num_blocked--;
314 publish_p2a_stat_update (); 308 publish_p2a_stat_update();
315} 309}
316 310
317 311
@@ -325,61 +319,61 @@ unblock_address (void *cls)
325 * @param session the session (can be NULL) 319 * @param session the session (can be NULL)
326 */ 320 */
327void 321void
328GST_ats_block_address (const struct GNUNET_HELLO_Address *address, 322GST_ats_block_address(const struct GNUNET_HELLO_Address *address,
329 struct GNUNET_ATS_Session *session) 323 struct GNUNET_ATS_Session *session)
330{ 324{
331 struct AddressInfo *ai; 325 struct AddressInfo *ai;
332 326
333 if (0 == 327 if (0 ==
334 memcmp (&GST_my_identity, 328 memcmp(&GST_my_identity,
335 &address->peer, 329 &address->peer,
336 sizeof (struct GNUNET_PeerIdentity))) 330 sizeof(struct GNUNET_PeerIdentity)))
337 return; /* our own, ignore! */ 331 return; /* our own, ignore! */
338 ai = find_ai (address, 332 ai = find_ai(address,
339 session); 333 session);
340 if (NULL == ai || NULL == ai->ar) 334 if (NULL == ai || NULL == ai->ar)
341 { 335 {
342 /* The address is already gone/blocked, this can happen during a blacklist 336 /* The address is already gone/blocked, this can happen during a blacklist
343 * callback. */ 337 * callback. */
344 return; 338 return;
345 } 339 }
346 ai->back_off = GNUNET_TIME_STD_BACKOFF (ai->back_off); 340 ai->back_off = GNUNET_TIME_STD_BACKOFF(ai->back_off);
347 if (GNUNET_YES == 341 if (GNUNET_YES ==
348 GNUNET_HELLO_address_check_option (address, 342 GNUNET_HELLO_address_check_option(address,
349 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 343 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
350 LOG (GNUNET_ERROR_TYPE_DEBUG, 344 LOG(GNUNET_ERROR_TYPE_DEBUG,
351 "Removing address %s of peer %s from use (inbound died)\n", 345 "Removing address %s of peer %s from use (inbound died)\n",
352 GST_plugins_a2s (address), 346 GST_plugins_a2s(address),
353 GNUNET_i2s (&address->peer)); 347 GNUNET_i2s(&address->peer));
354 else 348 else
355 LOG (GNUNET_ERROR_TYPE_INFO, 349 LOG(GNUNET_ERROR_TYPE_INFO,
356 "Blocking address %s of peer %s from use for %s\n", 350 "Blocking address %s of peer %s from use for %s\n",
357 GST_plugins_a2s (address), 351 GST_plugins_a2s(address),
358 GNUNET_i2s (&address->peer), 352 GNUNET_i2s(&address->peer),
359 GNUNET_STRINGS_relative_time_to_string (ai->back_off, 353 GNUNET_STRINGS_relative_time_to_string(ai->back_off,
360 GNUNET_YES)); 354 GNUNET_YES));
361 /* destroy session and address */ 355 /* destroy session and address */
362 if ( (NULL == session) || 356 if ((NULL == session) ||
363 (GNUNET_NO == 357 (GNUNET_NO ==
364 GNUNET_ATS_address_del_session (ai->ar, 358 GNUNET_ATS_address_del_session(ai->ar,
365 session)) ) 359 session)))
366 { 360 {
367 GNUNET_ATS_address_destroy (ai->ar); 361 GNUNET_ATS_address_destroy(ai->ar);
368 } 362 }
369 /* "ar" has been freed, regardless how the branch 363 /* "ar" has been freed, regardless how the branch
370 above played out: it was either freed in 364 above played out: it was either freed in
371 #GNUNET_ATS_address_del_session() because it was 365 #GNUNET_ATS_address_del_session() because it was
372 incoming, or explicitly in 366 incoming, or explicitly in
373 #GNUNET_ATS_address_del_session(). */ 367 #GNUNET_ATS_address_del_session(). */
374 ai->ar = NULL; 368 ai->ar = NULL;
375 369
376 /* determine when the address should come back to life */ 370 /* determine when the address should come back to life */
377 ai->blocked = GNUNET_TIME_relative_to_absolute (ai->back_off); 371 ai->blocked = GNUNET_TIME_relative_to_absolute(ai->back_off);
378 ai->unblock_task = GNUNET_SCHEDULER_add_delayed (ai->back_off, 372 ai->unblock_task = GNUNET_SCHEDULER_add_delayed(ai->back_off,
379 &unblock_address, 373 &unblock_address,
380 ai); 374 ai);
381 num_blocked++; 375 num_blocked++;
382 publish_p2a_stat_update (); 376 publish_p2a_stat_update();
383} 377}
384 378
385 379
@@ -392,24 +386,24 @@ GST_ats_block_address (const struct GNUNET_HELLO_Address *address,
392 * @param session the session (can be NULL) 386 * @param session the session (can be NULL)
393 */ 387 */
394void 388void
395GST_ats_block_reset (const struct GNUNET_HELLO_Address *address, 389GST_ats_block_reset(const struct GNUNET_HELLO_Address *address,
396 struct GNUNET_ATS_Session *session) 390 struct GNUNET_ATS_Session *session)
397{ 391{
398 struct AddressInfo *ai; 392 struct AddressInfo *ai;
399 393
400 if (0 == 394 if (0 ==
401 memcmp (&GST_my_identity, 395 memcmp(&GST_my_identity,
402 &address->peer, 396 &address->peer,
403 sizeof (struct GNUNET_PeerIdentity))) 397 sizeof(struct GNUNET_PeerIdentity)))
404 return; /* our own, ignore! */ 398 return; /* our own, ignore! */
405 ai = find_ai (address, session); 399 ai = find_ai(address, session);
406 if (NULL == ai) 400 if (NULL == ai)
407 { 401 {
408 GNUNET_break (0); 402 GNUNET_break(0);
409 return; 403 return;
410 } 404 }
411 /* address is in successful use, so it should not be blocked right now */ 405 /* address is in successful use, so it should not be blocked right now */
412 GNUNET_break (NULL == ai->unblock_task); 406 GNUNET_break(NULL == ai->unblock_task);
413 ai->back_off = GNUNET_TIME_UNIT_ZERO; 407 ai->back_off = GNUNET_TIME_UNIT_ZERO;
414} 408}
415 409
@@ -425,60 +419,60 @@ GST_ats_block_reset (const struct GNUNET_HELLO_Address *address,
425 * @param prop performance information 419 * @param prop performance information
426 */ 420 */
427void 421void
428GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address, 422GST_ats_add_inbound_address(const struct GNUNET_HELLO_Address *address,
429 struct GNUNET_ATS_Session *session, 423 struct GNUNET_ATS_Session *session,
430 const struct GNUNET_ATS_Properties *prop) 424 const struct GNUNET_ATS_Properties *prop)
431{ 425{
432 struct GNUNET_ATS_AddressRecord *ar; 426 struct GNUNET_ATS_AddressRecord *ar;
433 struct AddressInfo *ai; 427 struct AddressInfo *ai;
434 428
435 if (0 == 429 if (0 ==
436 memcmp (&GST_my_identity, 430 memcmp(&GST_my_identity,
437 &address->peer, 431 &address->peer,
438 sizeof (struct GNUNET_PeerIdentity))) 432 sizeof(struct GNUNET_PeerIdentity)))
439 return; /* our own, ignore! */ 433 return; /* our own, ignore! */
440 434
441 /* Sanity checks for a valid inbound address */ 435 /* Sanity checks for a valid inbound address */
442 if (NULL == address->transport_name) 436 if (NULL == address->transport_name)
443 { 437 {
444 GNUNET_break(0); 438 GNUNET_break(0);
445 return; 439 return;
446 } 440 }
447 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); 441 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
448 GNUNET_assert (GNUNET_YES == 442 GNUNET_assert(GNUNET_YES ==
449 GNUNET_HELLO_address_check_option (address, 443 GNUNET_HELLO_address_check_option(address,
450 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 444 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
451 GNUNET_assert (NULL != session); 445 GNUNET_assert(NULL != session);
452 ai = find_ai (address, session); 446 ai = find_ai(address, session);
453 if (NULL != ai) 447 if (NULL != ai)
454 { 448 {
455 /* This should only be called for new sessions, and thus 449 /* This should only be called for new sessions, and thus
456 we should not already have the address */ 450 we should not already have the address */
457 GNUNET_break (0); 451 GNUNET_break(0);
458 return; 452 return;
459 } 453 }
460 /* Is indeed new, let's tell ATS */ 454 /* Is indeed new, let's tell ATS */
461 LOG (GNUNET_ERROR_TYPE_DEBUG, 455 LOG(GNUNET_ERROR_TYPE_DEBUG,
462 "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n", 456 "Notifying ATS about peer `%s''s new inbound address `%s' session %p in network %s\n",
463 GNUNET_i2s (&address->peer), 457 GNUNET_i2s(&address->peer),
464 GST_plugins_a2s (address), 458 GST_plugins_a2s(address),
465 session, 459 session,
466 GNUNET_NT_to_string (prop->scope)); 460 GNUNET_NT_to_string(prop->scope));
467 ar = GNUNET_ATS_address_add (GST_ats, 461 ar = GNUNET_ATS_address_add(GST_ats,
468 address, 462 address,
469 session, 463 session,
470 prop); 464 prop);
471 GNUNET_assert (NULL != ar); 465 GNUNET_assert(NULL != ar);
472 ai = GNUNET_new (struct AddressInfo); 466 ai = GNUNET_new(struct AddressInfo);
473 ai->address = GNUNET_HELLO_address_copy (address); 467 ai->address = GNUNET_HELLO_address_copy(address);
474 ai->session = session; 468 ai->session = session;
475 ai->properties = *prop; 469 ai->properties = *prop;
476 ai->ar = ar; 470 ai->ar = ar;
477 (void) GNUNET_CONTAINER_multipeermap_put (p2a, 471 (void)GNUNET_CONTAINER_multipeermap_put(p2a,
478 &ai->address->peer, 472 &ai->address->peer,
479 ai, 473 ai,
480 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 474 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
481 publish_p2a_stat_update (); 475 publish_p2a_stat_update();
482} 476}
483 477
484 478
@@ -490,49 +484,49 @@ GST_ats_add_inbound_address (const struct GNUNET_HELLO_Address *address,
490 * @param prop performance information 484 * @param prop performance information
491 */ 485 */
492void 486void
493GST_ats_add_address (const struct GNUNET_HELLO_Address *address, 487GST_ats_add_address(const struct GNUNET_HELLO_Address *address,
494 const struct GNUNET_ATS_Properties *prop) 488 const struct GNUNET_ATS_Properties *prop)
495{ 489{
496 struct GNUNET_ATS_AddressRecord *ar; 490 struct GNUNET_ATS_AddressRecord *ar;
497 struct AddressInfo *ai; 491 struct AddressInfo *ai;
498 492
499 if (0 == 493 if (0 ==
500 memcmp (&GST_my_identity, 494 memcmp(&GST_my_identity,
501 &address->peer, 495 &address->peer,
502 sizeof (struct GNUNET_PeerIdentity))) 496 sizeof(struct GNUNET_PeerIdentity)))
503 return; /* our own, ignore! */ 497 return; /* our own, ignore! */
504 /* validadte address */ 498 /* validadte address */
505 if (NULL == address->transport_name) 499 if (NULL == address->transport_name)
506 { 500 {
507 GNUNET_break(0); 501 GNUNET_break(0);
508 return; 502 return;
509 } 503 }
510 GNUNET_assert (GNUNET_YES != 504 GNUNET_assert(GNUNET_YES !=
511 GNUNET_HELLO_address_check_option (address, 505 GNUNET_HELLO_address_check_option(address,
512 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 506 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
513 ai = find_ai_no_session (address); 507 ai = find_ai_no_session(address);
514 GNUNET_assert (NULL == ai); 508 GNUNET_assert(NULL == ai);
515 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop->scope); 509 GNUNET_break(GNUNET_NT_UNSPECIFIED != prop->scope);
516 510
517 /* address seems sane, let's tell ATS */ 511 /* address seems sane, let's tell ATS */
518 LOG (GNUNET_ERROR_TYPE_INFO, 512 LOG(GNUNET_ERROR_TYPE_INFO,
519 "Notifying ATS about peer %s's new address `%s'\n", 513 "Notifying ATS about peer %s's new address `%s'\n",
520 GNUNET_i2s (&address->peer), 514 GNUNET_i2s(&address->peer),
521 GST_plugins_a2s (address)); 515 GST_plugins_a2s(address));
522 ar = GNUNET_ATS_address_add (GST_ats, 516 ar = GNUNET_ATS_address_add(GST_ats,
523 address, 517 address,
524 NULL, 518 NULL,
525 prop); 519 prop);
526 GNUNET_assert (NULL != ar); 520 GNUNET_assert(NULL != ar);
527 ai = GNUNET_new (struct AddressInfo); 521 ai = GNUNET_new(struct AddressInfo);
528 ai->address = GNUNET_HELLO_address_copy (address); 522 ai->address = GNUNET_HELLO_address_copy(address);
529 ai->ar = ar; 523 ai->ar = ar;
530 ai->properties = *prop; 524 ai->properties = *prop;
531 (void) GNUNET_CONTAINER_multipeermap_put (p2a, 525 (void)GNUNET_CONTAINER_multipeermap_put(p2a,
532 &ai->address->peer, 526 &ai->address->peer,
533 ai, 527 ai,
534 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
535 publish_p2a_stat_update (); 529 publish_p2a_stat_update();
536} 530}
537 531
538 532
@@ -546,41 +540,41 @@ GST_ats_add_address (const struct GNUNET_HELLO_Address *address,
546 * @param session the session 540 * @param session the session
547 */ 541 */
548void 542void
549GST_ats_new_session (const struct GNUNET_HELLO_Address *address, 543GST_ats_new_session(const struct GNUNET_HELLO_Address *address,
550 struct GNUNET_ATS_Session *session) 544 struct GNUNET_ATS_Session *session)
551{ 545{
552 struct AddressInfo *ai; 546 struct AddressInfo *ai;
553 547
554 if (0 == 548 if (0 ==
555 memcmp (&GST_my_identity, 549 memcmp(&GST_my_identity,
556 &address->peer, 550 &address->peer,
557 sizeof (struct GNUNET_PeerIdentity))) 551 sizeof(struct GNUNET_PeerIdentity)))
558 return; /* our own, ignore! */ 552 return; /* our own, ignore! */
559 ai = find_ai (address, NULL); 553 ai = find_ai(address, NULL);
560 if (NULL == ai) 554 if (NULL == ai)
561 { 555 {
562 /* We may simply already be aware of the session, even if some 556 /* We may simply already be aware of the session, even if some
563 other part of the code could not tell if it just created a new 557 other part of the code could not tell if it just created a new
564 session or just got one recycled from the plugin; hence, we may 558 session or just got one recycled from the plugin; hence, we may
565 be called with "new" session even for an "old" session; in that 559 be called with "new" session even for an "old" session; in that
566 case, check that this is the case, but just ignore it. */ 560 case, check that this is the case, but just ignore it. */
567 GNUNET_assert (NULL != (find_ai (address, session))); 561 GNUNET_assert(NULL != (find_ai(address, session)));
568 return; 562 return;
569 } 563 }
570 GNUNET_assert (NULL == ai->session); 564 GNUNET_assert(NULL == ai->session);
571 ai->session = session; 565 ai->session = session;
572 LOG (GNUNET_ERROR_TYPE_DEBUG, 566 LOG(GNUNET_ERROR_TYPE_DEBUG,
573 "Telling ATS about new session for peer %s\n", 567 "Telling ATS about new session for peer %s\n",
574 GNUNET_i2s (&address->peer)); 568 GNUNET_i2s(&address->peer));
575 /* Note that the address might currently be blocked; we only 569 /* Note that the address might currently be blocked; we only
576 tell ATS about the session if the address is currently not 570 tell ATS about the session if the address is currently not
577 blocked; otherwise, ATS will be told about the session on 571 blocked; otherwise, ATS will be told about the session on
578 unblock. */ 572 unblock. */
579 if (NULL != ai->ar) 573 if (NULL != ai->ar)
580 GNUNET_ATS_address_add_session (ai->ar, 574 GNUNET_ATS_address_add_session(ai->ar,
581 session); 575 session);
582 else 576 else
583 GNUNET_assert (NULL != ai->unblock_task); 577 GNUNET_assert(NULL != ai->unblock_task);
584} 578}
585 579
586 580
@@ -590,30 +584,30 @@ GST_ats_new_session (const struct GNUNET_HELLO_Address *address,
590 * @param ai the `struct AddressInfo` 584 * @param ai the `struct AddressInfo`
591 */ 585 */
592static void 586static void
593destroy_ai (struct AddressInfo *ai) 587destroy_ai(struct AddressInfo *ai)
594{ 588{
595 GNUNET_assert (NULL == ai->session); 589 GNUNET_assert(NULL == ai->session);
596 if (NULL != ai->unblock_task) 590 if (NULL != ai->unblock_task)
597 { 591 {
598 GNUNET_SCHEDULER_cancel (ai->unblock_task); 592 GNUNET_SCHEDULER_cancel(ai->unblock_task);
599 ai->unblock_task = NULL; 593 ai->unblock_task = NULL;
600 num_blocked--; 594 num_blocked--;
601 } 595 }
602 GNUNET_assert (GNUNET_YES == 596 GNUNET_assert(GNUNET_YES ==
603 GNUNET_CONTAINER_multipeermap_remove (p2a, 597 GNUNET_CONTAINER_multipeermap_remove(p2a,
604 &ai->address->peer, 598 &ai->address->peer,
605 ai)); 599 ai));
606 LOG (GNUNET_ERROR_TYPE_DEBUG, 600 LOG(GNUNET_ERROR_TYPE_DEBUG,
607 "Telling ATS to destroy address from peer %s\n", 601 "Telling ATS to destroy address from peer %s\n",
608 GNUNET_i2s (&ai->address->peer)); 602 GNUNET_i2s(&ai->address->peer));
609 if (NULL != ai->ar) 603 if (NULL != ai->ar)
610 { 604 {
611 GNUNET_ATS_address_destroy (ai->ar); 605 GNUNET_ATS_address_destroy(ai->ar);
612 ai->ar = NULL; 606 ai->ar = NULL;
613 } 607 }
614 publish_p2a_stat_update (); 608 publish_p2a_stat_update();
615 GNUNET_HELLO_address_free (ai->address); 609 GNUNET_HELLO_address_free(ai->address);
616 GNUNET_free (ai); 610 GNUNET_free(ai);
617} 611}
618 612
619 613
@@ -629,100 +623,100 @@ destroy_ai (struct AddressInfo *ai)
629 * @param session the session 623 * @param session the session
630 */ 624 */
631void 625void
632GST_ats_del_session (const struct GNUNET_HELLO_Address *address, 626GST_ats_del_session(const struct GNUNET_HELLO_Address *address,
633 struct GNUNET_ATS_Session *session) 627 struct GNUNET_ATS_Session *session)
634{ 628{
635 struct AddressInfo *ai; 629 struct AddressInfo *ai;
636 630
637 if (0 == 631 if (0 ==
638 memcmp (&GST_my_identity, 632 memcmp(&GST_my_identity,
639 &address->peer, 633 &address->peer,
640 sizeof (struct GNUNET_PeerIdentity))) 634 sizeof(struct GNUNET_PeerIdentity)))
641 return; /* our own, ignore! */ 635 return; /* our own, ignore! */
642 if (NULL == session) 636 if (NULL == session)
643 { 637 {
644 GNUNET_break (0); 638 GNUNET_break(0);
645 return; 639 return;
646 } 640 }
647 ai = find_ai (address, 641 ai = find_ai(address,
648 session); 642 session);
649 if (NULL == ai) 643 if (NULL == ai)
650 { 644 {
651 /* We sometimes create sessions just for sending a PING, 645 /* We sometimes create sessions just for sending a PING,
652 and if those are destroyed they were never known to 646 and if those are destroyed they were never known to
653 ATS which means we end up here (however, in this 647 ATS which means we end up here (however, in this
654 case, the address must be an outbound address). */ 648 case, the address must be an outbound address). */
655 GNUNET_break (GNUNET_YES != 649 GNUNET_break(GNUNET_YES !=
656 GNUNET_HELLO_address_check_option (address, 650 GNUNET_HELLO_address_check_option(address,
657 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 651 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
658 return; 652 return;
659 } 653 }
660 GNUNET_assert (session == ai->session); 654 GNUNET_assert(session == ai->session);
661 ai->session = NULL; 655 ai->session = NULL;
662 LOG (GNUNET_ERROR_TYPE_DEBUG, 656 LOG(GNUNET_ERROR_TYPE_DEBUG,
663 "Telling ATS to destroy session %p from peer %s\n", 657 "Telling ATS to destroy session %p from peer %s\n",
664 session, 658 session,
665 GNUNET_i2s (&address->peer)); 659 GNUNET_i2s(&address->peer));
666 if (GNUNET_YES == ai->expired) 660 if (GNUNET_YES == ai->expired)
667 {
668 /* last reason to keep this 'ai' around is now gone, the
669 session is dead as well, clean up */
670 if (NULL != ai->ar)
671 { 661 {
672 /* Address expired but not blocked, and thus 'ar' was still 662 /* last reason to keep this 'ai' around is now gone, the
673 live because of the session; deleting just the session 663 session is dead as well, clean up */
674 will do for an inbound session, but for an outbound we 664 if (NULL != ai->ar)
675 then also need to destroy the address with ATS. */ 665 {
676 if (GNUNET_NO == 666 /* Address expired but not blocked, and thus 'ar' was still
677 GNUNET_ATS_address_del_session (ai->ar, 667 live because of the session; deleting just the session
678 session)) 668 will do for an inbound session, but for an outbound we
679 { 669 then also need to destroy the address with ATS. */
680 GNUNET_ATS_address_destroy (ai->ar); 670 if (GNUNET_NO ==
681 } 671 GNUNET_ATS_address_del_session(ai->ar,
682 /* "ar" has been freed, regardless how the branch 672 session))
683 above played out: it was either freed in 673 {
684 #GNUNET_ATS_address_del_session() because it was 674 GNUNET_ATS_address_destroy(ai->ar);
685 incoming, or explicitly in 675 }
686 #GNUNET_ATS_address_del_session(). */ 676 /* "ar" has been freed, regardless how the branch
687 ai->ar = NULL; 677 above played out: it was either freed in
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;
688 } 685 }
689 destroy_ai (ai);
690 return;
691 }
692 686
693 if (NULL == ai->ar) 687 if (NULL == ai->ar)
694 {
695 /* If ATS doesn't know about the address/session, this means
696 this address was blocked. */
697 if (GNUNET_YES ==
698 GNUNET_HELLO_address_check_option (address,
699 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
700 { 688 {
701 /* This was a blocked inbound session, which now lost the 689 /* If ATS doesn't know about the address/session, this means
702 session. But inbound addresses are by themselves useless, 690 this address was blocked. */
703 so we must forget about the address as well. */ 691 if (GNUNET_YES ==
704 destroy_ai (ai); 692 GNUNET_HELLO_address_check_option(address,
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; 705 return;
706 } 706 }
707 /* Otherwise, we are done as we have set `ai->session` to NULL
708 already and ATS will simply not be told about the session when
709 the connection is unblocked and the outbound address becomes
710 available again. . */
711 return;
712 }
713 707
714 /* This is the "simple" case where ATS knows about the session and 708 /* This is the "simple" case where ATS knows about the session and
715 the address is neither blocked nor expired. Delete the session, 709 the address is neither blocked nor expired. Delete the session,
716 and if it was inbound, free the address as well. */ 710 and if it was inbound, free the address as well. */
717 if (GNUNET_YES == 711 if (GNUNET_YES ==
718 GNUNET_ATS_address_del_session (ai->ar, 712 GNUNET_ATS_address_del_session(ai->ar,
719 session)) 713 session))
720 { 714 {
721 /* This was an inbound address, the session is now gone, so we 715 /* This was an inbound address, the session is now gone, so we
722 need to also forget about the address itself. */ 716 need to also forget about the address itself. */
723 ai->ar = NULL; 717 ai->ar = NULL;
724 destroy_ai (ai); 718 destroy_ai(ai);
725 } 719 }
726} 720}
727 721
728 722
@@ -734,31 +728,31 @@ GST_ats_del_session (const struct GNUNET_HELLO_Address *address,
734 * @param distance new distance value 728 * @param distance new distance value
735 */ 729 */
736void 730void
737GST_ats_update_distance (const struct GNUNET_HELLO_Address *address, 731GST_ats_update_distance(const struct GNUNET_HELLO_Address *address,
738 uint32_t distance) 732 uint32_t distance)
739{ 733{
740 struct AddressInfo *ai; 734 struct AddressInfo *ai;
741 735
742 ai = find_ai_no_session (address); 736 ai = find_ai_no_session(address);
743 if (NULL == ai) 737 if (NULL == ai)
744 { 738 {
745 /* We do not know about this address, do nothing. */ 739 /* We do not know about this address, do nothing. */
746 return; 740 return;
747 } 741 }
748 LOG (GNUNET_ERROR_TYPE_DEBUG, 742 LOG(GNUNET_ERROR_TYPE_DEBUG,
749 "Updated distance for peer `%s' to %u\n", 743 "Updated distance for peer `%s' to %u\n",
750 GNUNET_i2s (&address->peer), 744 GNUNET_i2s(&address->peer),
751 distance); 745 distance);
752 ai->properties.distance = distance; 746 ai->properties.distance = distance;
753 /* Give manipulation its chance to change metrics */ 747 /* Give manipulation its chance to change metrics */
754 GST_manipulation_manipulate_metrics (address, 748 GST_manipulation_manipulate_metrics(address,
755 ai->session, 749 ai->session,
756 &ai->properties); 750 &ai->properties);
757 /* Address may be blocked, only give ATS if address is 751 /* Address may be blocked, only give ATS if address is
758 currently active. */ 752 currently active. */
759 if (NULL != ai->ar) 753 if (NULL != ai->ar)
760 GNUNET_ATS_address_update (ai->ar, 754 GNUNET_ATS_address_update(ai->ar,
761 &ai->properties); 755 &ai->properties);
762} 756}
763 757
764 758
@@ -770,32 +764,32 @@ GST_ats_update_distance (const struct GNUNET_HELLO_Address *address,
770 * @param delay new delay value 764 * @param delay new delay value
771 */ 765 */
772void 766void
773GST_ats_update_delay (const struct GNUNET_HELLO_Address *address, 767GST_ats_update_delay(const struct GNUNET_HELLO_Address *address,
774 struct GNUNET_TIME_Relative delay) 768 struct GNUNET_TIME_Relative delay)
775{ 769{
776 struct AddressInfo *ai; 770 struct AddressInfo *ai;
777 771
778 ai = find_ai_no_session (address); 772 ai = find_ai_no_session(address);
779 if (NULL == ai) 773 if (NULL == ai)
780 { 774 {
781 /* We do not know about this address, do nothing. */ 775 /* We do not know about this address, do nothing. */
782 return; 776 return;
783 } 777 }
784 LOG (GNUNET_ERROR_TYPE_DEBUG, 778 LOG(GNUNET_ERROR_TYPE_DEBUG,
785 "Updated latency for peer `%s' to %s\n", 779 "Updated latency for peer `%s' to %s\n",
786 GNUNET_i2s (&address->peer), 780 GNUNET_i2s(&address->peer),
787 GNUNET_STRINGS_relative_time_to_string (delay, 781 GNUNET_STRINGS_relative_time_to_string(delay,
788 GNUNET_YES)); 782 GNUNET_YES));
789 ai->properties.delay = delay; 783 ai->properties.delay = delay;
790 /* Give manipulation its chance to change metrics */ 784 /* Give manipulation its chance to change metrics */
791 GST_manipulation_manipulate_metrics (address, 785 GST_manipulation_manipulate_metrics(address,
792 ai->session, 786 ai->session,
793 &ai->properties); 787 &ai->properties);
794 /* Address may be blocked, only give ATS if address is 788 /* Address may be blocked, only give ATS if address is
795 currently active. */ 789 currently active. */
796 if (NULL != ai->ar) 790 if (NULL != ai->ar)
797 GNUNET_ATS_address_update (ai->ar, 791 GNUNET_ATS_address_update(ai->ar,
798 &ai->properties); 792 &ai->properties);
799} 793}
800 794
801 795
@@ -808,35 +802,35 @@ GST_ats_update_delay (const struct GNUNET_HELLO_Address *address,
808 * @param bps_out new utilization outbound 802 * @param bps_out new utilization outbound
809 */ 803 */
810void 804void
811GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address, 805GST_ats_update_utilization(const struct GNUNET_HELLO_Address *address,
812 uint32_t bps_in, 806 uint32_t bps_in,
813 uint32_t bps_out) 807 uint32_t bps_out)
814{ 808{
815 struct AddressInfo *ai; 809 struct AddressInfo *ai;
816 810
817 ai = find_ai_no_session (address); 811 ai = find_ai_no_session(address);
818 if (NULL == ai) 812 if (NULL == ai)
819 { 813 {
820 /* We do not know about this address, do nothing. */ 814 /* We do not know about this address, do nothing. */
821 return; 815 return;
822 } 816 }
823 LOG (GNUNET_ERROR_TYPE_DEBUG, 817 LOG(GNUNET_ERROR_TYPE_DEBUG,
824 "Updating utilization for peer `%s' address %s: %u/%u\n", 818 "Updating utilization for peer `%s' address %s: %u/%u\n",
825 GNUNET_i2s (&address->peer), 819 GNUNET_i2s(&address->peer),
826 GST_plugins_a2s (address), 820 GST_plugins_a2s(address),
827 (unsigned int) bps_in, 821 (unsigned int)bps_in,
828 (unsigned int) bps_out); 822 (unsigned int)bps_out);
829 ai->properties.utilization_in = bps_in; 823 ai->properties.utilization_in = bps_in;
830 ai->properties.utilization_out = bps_out; 824 ai->properties.utilization_out = bps_out;
831 /* Give manipulation its chance to change metrics */ 825 /* Give manipulation its chance to change metrics */
832 GST_manipulation_manipulate_metrics (address, 826 GST_manipulation_manipulate_metrics(address,
833 ai->session, 827 ai->session,
834 &ai->properties); 828 &ai->properties);
835 /* Address may be blocked, only give ATS if address is 829 /* Address may be blocked, only give ATS if address is
836 currently active. */ 830 currently active. */
837 if (NULL != ai->ar) 831 if (NULL != ai->ar)
838 GNUNET_ATS_address_update (ai->ar, 832 GNUNET_ATS_address_update(ai->ar,
839 &ai->properties); 833 &ai->properties);
840} 834}
841 835
842 836
@@ -848,34 +842,34 @@ GST_ats_update_utilization (const struct GNUNET_HELLO_Address *address,
848 * @param address the address 842 * @param address the address
849 */ 843 */
850void 844void
851GST_ats_expire_address (const struct GNUNET_HELLO_Address *address) 845GST_ats_expire_address(const struct GNUNET_HELLO_Address *address)
852{ 846{
853 struct AddressInfo *ai; 847 struct AddressInfo *ai;
854 848
855 if (0 == 849 if (0 ==
856 memcmp (&GST_my_identity, 850 memcmp(&GST_my_identity,
857 &address->peer, 851 &address->peer,
858 sizeof (struct GNUNET_PeerIdentity))) 852 sizeof(struct GNUNET_PeerIdentity)))
859 return; /* our own, ignore! */ 853 return; /* our own, ignore! */
860 LOG (GNUNET_ERROR_TYPE_DEBUG, 854 LOG(GNUNET_ERROR_TYPE_DEBUG,
861 "Address %s of peer %s expired\n", 855 "Address %s of peer %s expired\n",
862 GST_plugins_a2s (address), 856 GST_plugins_a2s(address),
863 GNUNET_i2s (&address->peer)); 857 GNUNET_i2s(&address->peer));
864 ai = find_ai_no_session (address); 858 ai = find_ai_no_session(address);
865 if (NULL == ai) 859 if (NULL == ai)
866 { 860 {
867 GNUNET_assert (0); 861 GNUNET_assert(0);
868 return; 862 return;
869 } 863 }
870 if (NULL != ai->session) 864 if (NULL != ai->session)
871 { 865 {
872 /* Got an active session, just remember the expiration 866 /* Got an active session, just remember the expiration
873 and act upon it when the session goes down. */ 867 and act upon it when the session goes down. */
874 ai->expired = GNUNET_YES; 868 ai->expired = GNUNET_YES;
875 return; 869 return;
876 } 870 }
877 /* Address expired, no session, free resources */ 871 /* Address expired, no session, free resources */
878 destroy_ai (ai); 872 destroy_ai(ai);
879} 873}
880 874
881 875
@@ -883,9 +877,9 @@ GST_ats_expire_address (const struct GNUNET_HELLO_Address *address)
883 * Initialize ATS subsystem. 877 * Initialize ATS subsystem.
884 */ 878 */
885void 879void
886GST_ats_init () 880GST_ats_init()
887{ 881{
888 p2a = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_YES); 882 p2a = GNUNET_CONTAINER_multipeermap_create(4, GNUNET_YES);
889} 883}
890 884
891 885
@@ -898,13 +892,13 @@ GST_ats_init ()
898 * @return #GNUNET_OK (continue to iterate) 892 * @return #GNUNET_OK (continue to iterate)
899 */ 893 */
900static int 894static int
901destroy_ai_cb (void *cls, 895destroy_ai_cb(void *cls,
902 const struct GNUNET_PeerIdentity *key, 896 const struct GNUNET_PeerIdentity *key,
903 void *value) 897 void *value)
904{ 898{
905 struct AddressInfo *ai = value; 899 struct AddressInfo *ai = value;
906 900
907 destroy_ai (ai); 901 destroy_ai(ai);
908 return GNUNET_OK; 902 return GNUNET_OK;
909} 903}
910 904
@@ -913,13 +907,13 @@ destroy_ai_cb (void *cls,
913 * Shutdown ATS subsystem. 907 * Shutdown ATS subsystem.
914 */ 908 */
915void 909void
916GST_ats_done () 910GST_ats_done()
917{ 911{
918 GNUNET_CONTAINER_multipeermap_iterate (p2a, 912 GNUNET_CONTAINER_multipeermap_iterate(p2a,
919 &destroy_ai_cb, 913 &destroy_ai_cb,
920 NULL); 914 NULL);
921 publish_p2a_stat_update (); 915 publish_p2a_stat_update();
922 GNUNET_CONTAINER_multipeermap_destroy (p2a); 916 GNUNET_CONTAINER_multipeermap_destroy(p2a);
923 p2a = NULL; 917 p2a = NULL;
924} 918}
925 919
diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h
index c8f2c309f..9c906a9a2 100644
--- a/src/transport/gnunet-service-transport_ats.h
+++ b/src/transport/gnunet-service-transport_ats.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/gnunet-service-transport_ats.h 21 * @file transport/gnunet-service-transport_ats.h
22 * @brief interfacing between transport and ATS service 22 * @brief interfacing between transport and ATS service
@@ -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 2d7440650..24a8321a2 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_hello.c 22 * @file transport/gnunet-service-transport_hello.c
@@ -36,7 +36,7 @@
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(GNUNET_TIME_UNIT_HOURS, 6)
40 40
41/** 41/**
42 * Hello address expiration 42 * Hello address expiration
@@ -48,8 +48,7 @@ extern struct GNUNET_TIME_Relative hello_expiration;
48 * Entry in linked list of network addresses for ourselves. Also 48 * Entry in linked list of network addresses for ourselves. Also
49 * includes a cached signature for 'struct TransportPongMessage's. 49 * includes a cached signature for 'struct TransportPongMessage's.
50 */ 50 */
51struct OwnAddressList 51struct OwnAddressList {
52{
53 /** 52 /**
54 * This is a doubly-linked list. 53 * This is a doubly-linked list.
55 */ 54 */
@@ -82,7 +81,6 @@ struct OwnAddressList
82 * multiple origins. 81 * multiple origins.
83 */ 82 */
84 unsigned int rc; 83 unsigned int rc;
85
86}; 84};
87 85
88 86
@@ -125,8 +123,7 @@ static struct GNUNET_SCHEDULER_Task *hello_task;
125/** 123/**
126 * Closure for #address_generator(). 124 * Closure for #address_generator().
127 */ 125 */
128struct GeneratorContext 126struct GeneratorContext {
129{
130 /** 127 /**
131 * Where are we in the DLL? 128 * Where are we in the DLL?
132 */ 129 */
@@ -149,19 +146,19 @@ struct GeneratorContext
149 * end of the iteration. 146 * end of the iteration.
150 */ 147 */
151static ssize_t 148static ssize_t
152address_generator (void *cls, 149address_generator(void *cls,
153 size_t max, 150 size_t max,
154 void *buf) 151 void *buf)
155{ 152{
156 struct GeneratorContext *gc = cls; 153 struct GeneratorContext *gc = cls;
157 ssize_t ret; 154 ssize_t ret;
158 155
159 if (NULL == gc->addr_pos) 156 if (NULL == gc->addr_pos)
160 return GNUNET_SYSERR; /* Done */ 157 return GNUNET_SYSERR; /* Done */
161 ret = GNUNET_HELLO_add_address (gc->addr_pos->address, 158 ret = GNUNET_HELLO_add_address(gc->addr_pos->address,
162 gc->expiration, 159 gc->expiration,
163 buf, 160 buf,
164 max); 161 max);
165 gc->addr_pos = gc->addr_pos->next; 162 gc->addr_pos = gc->addr_pos->next;
166 return ret; 163 return ret;
167} 164}
@@ -174,38 +171,38 @@ address_generator (void *cls,
174 * @param cls unused 171 * @param cls unused
175 */ 172 */
176static void 173static void
177refresh_hello_task (void *cls) 174refresh_hello_task(void *cls)
178{ 175{
179 struct GeneratorContext gc; 176 struct GeneratorContext gc;
180 177
181 hello_task = NULL; 178 hello_task = NULL;
182 gc.addr_pos = oal_head; 179 gc.addr_pos = oal_head;
183 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration); 180 gc.expiration = GNUNET_TIME_relative_to_absolute(hello_expiration);
184 181
185 GNUNET_free_non_null (our_hello); 182 GNUNET_free_non_null(our_hello);
186 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, 183 our_hello = GNUNET_HELLO_create(&GST_my_identity.public_key,
187 &address_generator, 184 &address_generator,
188 &gc, 185 &gc,
189 friend_option); 186 friend_option);
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
191 "Refreshed my %s HELLO, new size is %d\n", 188 "Refreshed my %s HELLO, new size is %d\n",
192 (GNUNET_YES == friend_option) ? "friend-only" : "public", 189 (GNUNET_YES == friend_option) ? "friend-only" : "public",
193 GNUNET_HELLO_size (our_hello)); 190 GNUNET_HELLO_size(our_hello));
194 GNUNET_STATISTICS_update (GST_stats, 191 GNUNET_STATISTICS_update(GST_stats,
195 gettext_noop ("# refreshed my HELLO"), 192 gettext_noop("# refreshed my HELLO"),
196 1, 193 1,
197 GNUNET_NO); 194 GNUNET_NO);
198 if (NULL != hello_cb) 195 if (NULL != hello_cb)
199 hello_cb (hello_cb_cls, 196 hello_cb(hello_cb_cls,
200 GST_hello_get ()); 197 GST_hello_get());
201 GNUNET_PEERINFO_add_peer (GST_peerinfo, 198 GNUNET_PEERINFO_add_peer(GST_peerinfo,
202 our_hello, 199 our_hello,
203 NULL, 200 NULL,
204 NULL); 201 NULL);
205 hello_task = 202 hello_task =
206 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, 203 GNUNET_SCHEDULER_add_delayed(HELLO_REFRESH_PERIOD,
207 &refresh_hello_task, 204 &refresh_hello_task,
208 NULL); 205 NULL);
209} 206}
210 207
211 208
@@ -215,14 +212,14 @@ refresh_hello_task (void *cls)
215 * have been shutdown). 212 * have been shutdown).
216 */ 213 */
217static void 214static void
218refresh_hello () 215refresh_hello()
219{ 216{
220 if (NULL != hello_task) 217 if (NULL != hello_task)
221 { 218 {
222 GNUNET_SCHEDULER_cancel (hello_task); 219 GNUNET_SCHEDULER_cancel(hello_task);
223 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, 220 hello_task = GNUNET_SCHEDULER_add_now(&refresh_hello_task,
224 NULL); 221 NULL);
225 } 222 }
226} 223}
227 224
228 225
@@ -234,14 +231,14 @@ refresh_hello ()
234 * @param cb_cls closure for @a cb 231 * @param cb_cls closure for @a cb
235 */ 232 */
236void 233void
237GST_hello_start (int friend_only, 234GST_hello_start(int friend_only,
238 GST_HelloCallback cb, 235 GST_HelloCallback cb,
239 void *cb_cls) 236 void *cb_cls)
240{ 237{
241 hello_cb = cb; 238 hello_cb = cb;
242 hello_cb_cls = cb_cls; 239 hello_cb_cls = cb_cls;
243 friend_option = friend_only; 240 friend_option = friend_only;
244 refresh_hello_task (NULL); 241 refresh_hello_task(NULL);
245} 242}
246 243
247 244
@@ -249,20 +246,20 @@ GST_hello_start (int friend_only,
249 * Shutdown the HELLO module. 246 * Shutdown the HELLO module.
250 */ 247 */
251void 248void
252GST_hello_stop () 249GST_hello_stop()
253{ 250{
254 hello_cb = NULL; 251 hello_cb = NULL;
255 hello_cb_cls = NULL; 252 hello_cb_cls = NULL;
256 if (NULL != hello_task) 253 if (NULL != hello_task)
257 { 254 {
258 GNUNET_SCHEDULER_cancel (hello_task); 255 GNUNET_SCHEDULER_cancel(hello_task);
259 hello_task = NULL; 256 hello_task = NULL;
260 } 257 }
261 if (NULL != our_hello) 258 if (NULL != our_hello)
262 { 259 {
263 GNUNET_free (our_hello); 260 GNUNET_free(our_hello);
264 our_hello = NULL; 261 our_hello = NULL;
265 } 262 }
266} 263}
267 264
268 265
@@ -272,9 +269,9 @@ GST_hello_stop ()
272 * @return our HELLO message 269 * @return our HELLO message
273 */ 270 */
274const struct GNUNET_MessageHeader * 271const struct GNUNET_MessageHeader *
275GST_hello_get () 272GST_hello_get()
276{ 273{
277 return (const struct GNUNET_MessageHeader *) our_hello; 274 return (const struct GNUNET_MessageHeader *)our_hello;
278} 275}
279 276
280 277
@@ -285,52 +282,52 @@ GST_hello_get ()
285 * @param address address to add or remove 282 * @param address address to add or remove
286 */ 283 */
287void 284void
288GST_hello_modify_addresses (int addremove, 285GST_hello_modify_addresses(int addremove,
289 const struct GNUNET_HELLO_Address *address) 286 const struct GNUNET_HELLO_Address *address)
290{ 287{
291 struct OwnAddressList *al; 288 struct OwnAddressList *al;
292 289
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
294 (GNUNET_YES == addremove) 291 (GNUNET_YES == addremove)
295 ? "Adding `%s' to the set of our addresses\n" 292 ? "Adding `%s' to the set of our addresses\n"
296 : "Removing `%s' from the set of our addresses\n", 293 : "Removing `%s' from the set of our addresses\n",
297 GST_plugins_a2s (address)); 294 GST_plugins_a2s(address));
298 GNUNET_assert (NULL != address); 295 GNUNET_assert(NULL != address);
299 for (al = oal_head; al != NULL; al = al->next) 296 for (al = oal_head; al != NULL; al = al->next)
300 if (0 == GNUNET_HELLO_address_cmp (address, al->address)) 297 if (0 == GNUNET_HELLO_address_cmp(address, al->address))
301 break; 298 break;
302 if (GNUNET_NO == addremove) 299 if (GNUNET_NO == addremove)
303 {
304 if (NULL == al)
305 { 300 {
306 /* address to be removed not found!? */ 301 if (NULL == al)
307 GNUNET_break (0); 302 {
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();
308 return; 316 return;
309 } 317 }
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 }
321 if (NULL != al) 318 if (NULL != al)
322 { 319 {
323 /* address added twice or more */ 320 /* address added twice or more */
324 al->rc++; 321 al->rc++;
325 return; 322 return;
326 } 323 }
327 al = GNUNET_new (struct OwnAddressList); 324 al = GNUNET_new(struct OwnAddressList);
328 al->rc = 1; 325 al->rc = 1;
329 GNUNET_CONTAINER_DLL_insert (oal_head, 326 GNUNET_CONTAINER_DLL_insert(oal_head,
330 oal_tail, 327 oal_tail,
331 al); 328 al);
332 al->address = GNUNET_HELLO_address_copy (address); 329 al->address = GNUNET_HELLO_address_copy(address);
333 refresh_hello (); 330 refresh_hello();
334} 331}
335 332
336 333
@@ -345,20 +342,20 @@ GST_hello_modify_addresses (int addremove,
345 * #GNUNET_NO if not 342 * #GNUNET_NO if not
346 */ 343 */
347int 344int
348GST_hello_test_address (const struct GNUNET_HELLO_Address *address, 345GST_hello_test_address(const struct GNUNET_HELLO_Address *address,
349 struct GNUNET_CRYPTO_EddsaSignature **sig, 346 struct GNUNET_CRYPTO_EddsaSignature **sig,
350 struct GNUNET_TIME_Absolute **sig_expiration) 347 struct GNUNET_TIME_Absolute **sig_expiration)
351{ 348{
352 struct OwnAddressList *al; 349 struct OwnAddressList *al;
353 350
354 for (al = oal_head; al != NULL; al = al->next) 351 for (al = oal_head; al != NULL; al = al->next)
355 if (0 == GNUNET_HELLO_address_cmp (address, 352 if (0 == GNUNET_HELLO_address_cmp(address,
356 al->address)) 353 al->address))
357 { 354 {
358 *sig = &al->pong_signature; 355 *sig = &al->pong_signature;
359 *sig_expiration = &al->pong_sig_expires; 356 *sig_expiration = &al->pong_sig_expires;
360 return GNUNET_YES; 357 return GNUNET_YES;
361 } 358 }
362 *sig = NULL; 359 *sig = NULL;
363 *sig_expiration = NULL; 360 *sig_expiration = NULL;
364 return GNUNET_NO; 361 return GNUNET_NO;
diff --git a/src/transport/gnunet-service-transport_hello.h b/src/transport/gnunet-service-transport_hello.h
index f96b2a84d..6dee4eb07 100644
--- a/src/transport/gnunet-service-transport_hello.h
+++ b/src/transport/gnunet-service-transport_hello.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/gnunet-service-transport_hello.h 21 * @file transport/gnunet-service-transport_hello.h
22 * @brief hello API 22 * @brief hello API
@@ -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 0b042dd6a..07f7eb618 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2013 GNUnet e.V. 3 Copyright (C) 2010-2013 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -36,8 +36,7 @@
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{
41 /** 40 /**
42 * Peer ID 41 * Peer ID
43 */ 42 */
@@ -78,8 +77,7 @@ struct TM_Peer
78/** 77/**
79 * Entry in the delay queue for an outbound delayed message 78 * Entry in the delay queue for an outbound delayed message
80 */ 79 */
81struct DelayQueueEntry 80struct DelayQueueEntry {
82{
83 /** 81 /**
84 * Next in DLL 82 * Next in DLL
85 */ 83 */
@@ -171,39 +169,39 @@ static struct GNUNET_SCHEDULER_Task *generic_send_delay_task;
171 * @param message containing information 169 * @param message containing information
172 */ 170 */
173void 171void
174GST_manipulation_set_metric (const struct TrafficMetricMessage *tm) 172GST_manipulation_set_metric(const struct TrafficMetricMessage *tm)
175{ 173{
176 static struct GNUNET_PeerIdentity zero; 174 static struct GNUNET_PeerIdentity zero;
177 struct TM_Peer *tmp; 175 struct TM_Peer *tmp;
178 176
179 if (0 == memcmp (&tm->peer, 177 if (0 == memcmp(&tm->peer,
180 &zero, 178 &zero,
181 sizeof(struct GNUNET_PeerIdentity))) 179 sizeof(struct GNUNET_PeerIdentity)))
182 { 180 {
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 181 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
184 "Received traffic metrics for all peers\n"); 182 "Received traffic metrics for all peers\n");
185 delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in); 183 delay_in = GNUNET_TIME_relative_ntoh(tm->delay_in);
186 delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out); 184 delay_out = GNUNET_TIME_relative_ntoh(tm->delay_out);
187 return; 185 return;
188 } 186 }
189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
190 "Received traffic metrics for peer `%s'\n", 188 "Received traffic metrics for peer `%s'\n",
191 GNUNET_i2s (&tm->peer)); 189 GNUNET_i2s(&tm->peer));
192 if (NULL == 190 if (NULL ==
193 (tmp = GNUNET_CONTAINER_multipeermap_get (peers, 191 (tmp = GNUNET_CONTAINER_multipeermap_get(peers,
194 &tm->peer))) 192 &tm->peer)))
195 { 193 {
196 tmp = GNUNET_new (struct TM_Peer); 194 tmp = GNUNET_new(struct TM_Peer);
197 tmp->peer = tm->peer; 195 tmp->peer = tm->peer;
198 GNUNET_CONTAINER_multipeermap_put (peers, 196 GNUNET_CONTAINER_multipeermap_put(peers,
199 &tm->peer, 197 &tm->peer,
200 tmp, 198 tmp,
201 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 199 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
202 } 200 }
203 GNUNET_ATS_properties_ntoh (&tmp->properties, 201 GNUNET_ATS_properties_ntoh(&tmp->properties,
204 &tm->properties); 202 &tm->properties);
205 tmp->delay_in = GNUNET_TIME_relative_ntoh (tm->delay_in); 203 tmp->delay_in = GNUNET_TIME_relative_ntoh(tm->delay_in);
206 tmp->delay_out = GNUNET_TIME_relative_ntoh (tm->delay_out); 204 tmp->delay_out = GNUNET_TIME_relative_ntoh(tm->delay_out);
207} 205}
208 206
209 207
@@ -214,51 +212,51 @@ GST_manipulation_set_metric (const struct TrafficMetricMessage *tm)
214 * @param cls the `struct DelayQueueEntry` to transmit 212 * @param cls the `struct DelayQueueEntry` to transmit
215 */ 213 */
216static void 214static void
217send_delayed (void *cls) 215send_delayed(void *cls)
218{ 216{
219 struct DelayQueueEntry *dqe = cls; 217 struct DelayQueueEntry *dqe = cls;
220 struct DelayQueueEntry *next; 218 struct DelayQueueEntry *next;
221 struct TM_Peer *tmp = dqe->tmp; 219 struct TM_Peer *tmp = dqe->tmp;
222 220
223 GNUNET_break (GNUNET_YES == 221 GNUNET_break(GNUNET_YES ==
224 GST_neighbours_test_connected (&dqe->id)); 222 GST_neighbours_test_connected(&dqe->id));
225 if (NULL != tmp) 223 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)
233 { 224 {
234 /* More delayed messages */ 225 tmp->send_delay_task = NULL;
235 tmp->send_delay_task = GNUNET_SCHEDULER_add_at (next->sent_at, 226 GNUNET_CONTAINER_DLL_remove(tmp->send_head,
236 &send_delayed, 227 tmp->send_tail,
237 next); 228 dqe);
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 }
238 } 237 }
239 }
240 else 238 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)
249 { 239 {
250 /* More delayed messages */ 240 /* Remove from generic queue */
251 generic_send_delay_task = GNUNET_SCHEDULER_add_at (next->sent_at, 241 generic_send_delay_task = NULL;
252 &send_delayed, 242 GNUNET_CONTAINER_DLL_remove(generic_dqe_head,
253 next); 243 generic_dqe_tail,
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 }
254 } 253 }
255 } 254 GST_neighbours_send(&dqe->id,
256 GST_neighbours_send (&dqe->id, 255 dqe->msg,
257 dqe->msg, 256 dqe->msg_size,
258 dqe->msg_size, 257 dqe->timeout,
259 dqe->timeout, 258 dqe->cont,
260 dqe->cont, 259 dqe->cont_cls);
261 dqe->cont_cls);
262 GNUNET_free(dqe); 260 GNUNET_free(dqe);
263} 261}
264 262
@@ -275,71 +273,71 @@ send_delayed (void *cls)
275 * @param cont_cls cls for @a cont 273 * @param cont_cls cls for @a cont
276 */ 274 */
277void 275void
278GST_manipulation_send (const struct GNUNET_PeerIdentity *target, 276GST_manipulation_send(const struct GNUNET_PeerIdentity *target,
279 const void *msg, 277 const void *msg,
280 size_t msg_size, 278 size_t msg_size,
281 struct GNUNET_TIME_Relative timeout, 279 struct GNUNET_TIME_Relative timeout,
282 GST_NeighbourSendContinuation cont, 280 GST_NeighbourSendContinuation cont,
283 void *cont_cls) 281 void *cont_cls)
284{ 282{
285 struct TM_Peer *tmp; 283 struct TM_Peer *tmp;
286 struct DelayQueueEntry *dqe; 284 struct DelayQueueEntry *dqe;
287 struct GNUNET_TIME_Relative delay; 285 struct GNUNET_TIME_Relative delay;
288 286
289 if (NULL != (tmp = 287 if (NULL != (tmp =
290 GNUNET_CONTAINER_multipeermap_get (peers, 288 GNUNET_CONTAINER_multipeermap_get(peers,
291 target))) 289 target)))
292 delay = tmp->delay_out; 290 delay = tmp->delay_out;
293 else 291 else
294 delay = delay_out; 292 delay = delay_out;
295 if (0 == delay.rel_value_us) 293 if (0 == delay.rel_value_us)
296 { 294 {
297 /* Normal sending */ 295 /* Normal sending */
298 GST_neighbours_send (target, 296 GST_neighbours_send(target,
299 msg, 297 msg,
300 msg_size, 298 msg_size,
301 timeout, 299 timeout,
302 cont, cont_cls); 300 cont, cont_cls);
303 return; 301 return;
304 } 302 }
305 dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size); 303 dqe = GNUNET_malloc(sizeof(struct DelayQueueEntry) + msg_size);
306 dqe->id = *target; 304 dqe->id = *target;
307 dqe->tmp = tmp; 305 dqe->tmp = tmp;
308 dqe->sent_at = GNUNET_TIME_relative_to_absolute (delay); 306 dqe->sent_at = GNUNET_TIME_relative_to_absolute(delay);
309 dqe->cont = cont; 307 dqe->cont = cont;
310 dqe->cont_cls = cont_cls; 308 dqe->cont_cls = cont_cls;
311 dqe->msg = &dqe[1]; 309 dqe->msg = &dqe[1];
312 dqe->msg_size = msg_size; 310 dqe->msg_size = msg_size;
313 dqe->timeout = timeout; 311 dqe->timeout = timeout;
314 GNUNET_memcpy (dqe->msg, 312 GNUNET_memcpy(dqe->msg,
315 msg, 313 msg,
316 msg_size); 314 msg_size);
317 if (NULL == tmp) 315 if (NULL == tmp)
318 { 316 {
319 GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head, 317 GNUNET_CONTAINER_DLL_insert_tail(generic_dqe_head,
320 generic_dqe_tail, 318 generic_dqe_tail,
321 dqe); 319 dqe);
322 if (NULL == generic_send_delay_task) 320 if (NULL == generic_send_delay_task)
323 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed (delay, 321 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(delay,
324 &send_delayed, 322 &send_delayed,
325 dqe); 323 dqe);
326 } 324 }
327 else 325 else
328 { 326 {
329 GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head, 327 GNUNET_CONTAINER_DLL_insert_tail(tmp->send_head,
330 tmp->send_tail, 328 tmp->send_tail,
331 dqe); 329 dqe);
332 if (NULL == tmp->send_delay_task) 330 if (NULL == tmp->send_delay_task)
333 tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed (delay, 331 tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed(delay,
334 &send_delayed, 332 &send_delayed,
335 dqe); 333 dqe);
336 } 334 }
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
338 "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", 336 "Delaying %u byte message to peer `%s' with peer specific delay for %s\n",
339 (unsigned int) msg_size, 337 (unsigned int)msg_size,
340 GNUNET_i2s (target), 338 GNUNET_i2s(target),
341 GNUNET_STRINGS_relative_time_to_string (delay, 339 GNUNET_STRINGS_relative_time_to_string(delay,
342 GNUNET_YES)); 340 GNUNET_YES));
343} 341}
344 342
345 343
@@ -352,15 +350,15 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target,
352 * @param prop[IN|OUT] metrics to modify 350 * @param prop[IN|OUT] metrics to modify
353 */ 351 */
354void 352void
355GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address, 353GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address,
356 struct GNUNET_ATS_Session *session, 354 struct GNUNET_ATS_Session *session,
357 struct GNUNET_ATS_Properties *prop) 355 struct GNUNET_ATS_Properties *prop)
358{ 356{
359 const struct GNUNET_PeerIdentity *peer = &address->peer; 357 const struct GNUNET_PeerIdentity *peer = &address->peer;
360 struct TM_Peer *tmp; 358 struct TM_Peer *tmp;
361 359
362 tmp = GNUNET_CONTAINER_multipeermap_get (peers, 360 tmp = GNUNET_CONTAINER_multipeermap_get(peers,
363 peer); 361 peer);
364 if (NULL != tmp) 362 if (NULL != tmp)
365 *prop = tmp->properties; 363 *prop = tmp->properties;
366} 364}
@@ -377,33 +375,33 @@ GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address,
377 * @return manipulated delay for next receive 375 * @return manipulated delay for next receive
378 */ 376 */
379struct GNUNET_TIME_Relative 377struct GNUNET_TIME_Relative
380GST_manipulation_recv (void *cls, 378GST_manipulation_recv(void *cls,
381 const struct GNUNET_HELLO_Address *address, 379 const struct GNUNET_HELLO_Address *address,
382 struct GNUNET_ATS_Session *session, 380 struct GNUNET_ATS_Session *session,
383 const struct GNUNET_MessageHeader *message) 381 const struct GNUNET_MessageHeader *message)
384{ 382{
385 struct TM_Peer *tmp; 383 struct TM_Peer *tmp;
386 struct GNUNET_TIME_Relative quota_delay; 384 struct GNUNET_TIME_Relative quota_delay;
387 struct GNUNET_TIME_Relative m_delay; 385 struct GNUNET_TIME_Relative m_delay;
388 386
389 if (NULL != 387 if (NULL !=
390 (tmp = GNUNET_CONTAINER_multipeermap_get (peers, 388 (tmp = GNUNET_CONTAINER_multipeermap_get(peers,
391 &address->peer))) 389 &address->peer)))
392 m_delay = tmp->delay_in; 390 m_delay = tmp->delay_in;
393 else 391 else
394 m_delay = delay_in; 392 m_delay = delay_in;
395 393
396 quota_delay = GST_receive_callback (cls, 394 quota_delay = GST_receive_callback(cls,
397 address, 395 address,
398 session, 396 session,
399 message); 397 message);
400 m_delay = GNUNET_TIME_relative_max (m_delay, 398 m_delay = GNUNET_TIME_relative_max(m_delay,
401 quota_delay); 399 quota_delay);
402 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
403 "Delaying next receive for peer `%s' for %s\n", 401 "Delaying next receive for peer `%s' for %s\n",
404 GNUNET_i2s (&address->peer), 402 GNUNET_i2s(&address->peer),
405 GNUNET_STRINGS_relative_time_to_string (m_delay, 403 GNUNET_STRINGS_relative_time_to_string(m_delay,
406 GNUNET_YES)); 404 GNUNET_YES));
407 return m_delay; 405 return m_delay;
408} 406}
409 407
@@ -412,38 +410,38 @@ GST_manipulation_recv (void *cls,
412 * Initialize traffic manipulation 410 * Initialize traffic manipulation
413 */ 411 */
414void 412void
415GST_manipulation_init () 413GST_manipulation_init()
416{ 414{
417 struct GNUNET_TIME_Relative delay; 415 struct GNUNET_TIME_Relative delay;
418 416
419 if ( (GNUNET_OK == 417 if ((GNUNET_OK ==
420 GNUNET_CONFIGURATION_get_value_time (GST_cfg, 418 GNUNET_CONFIGURATION_get_value_time(GST_cfg,
421 "transport", 419 "transport",
422 "MANIPULATE_DELAY_IN", 420 "MANIPULATE_DELAY_IN",
423 &delay)) && 421 &delay)) &&
424 (delay.rel_value_us > 0) ) 422 (delay.rel_value_us > 0))
425 { 423 {
426 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 424 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
427 "Delaying inbound traffic for %s\n", 425 "Delaying inbound traffic for %s\n",
428 GNUNET_STRINGS_relative_time_to_string (delay, 426 GNUNET_STRINGS_relative_time_to_string(delay,
429 GNUNET_YES)); 427 GNUNET_YES));
430 delay_in = delay; 428 delay_in = delay;
431 } 429 }
432 if ( (GNUNET_OK == 430 if ((GNUNET_OK ==
433 GNUNET_CONFIGURATION_get_value_time (GST_cfg, 431 GNUNET_CONFIGURATION_get_value_time(GST_cfg,
434 "transport", 432 "transport",
435 "MANIPULATE_DELAY_OUT", 433 "MANIPULATE_DELAY_OUT",
436 &delay)) && 434 &delay)) &&
437 (delay.rel_value_us > 0) ) 435 (delay.rel_value_us > 0))
438 { 436 {
439 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 437 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
440 "Delaying outbound traffic for %s\n", 438 "Delaying outbound traffic for %s\n",
441 GNUNET_STRINGS_relative_time_to_string (delay, 439 GNUNET_STRINGS_relative_time_to_string(delay,
442 GNUNET_YES)); 440 GNUNET_YES));
443 delay_out = delay; 441 delay_out = delay;
444 } 442 }
445 peers = GNUNET_CONTAINER_multipeermap_create (4, 443 peers = GNUNET_CONTAINER_multipeermap_create(4,
446 GNUNET_NO); 444 GNUNET_NO);
447} 445}
448 446
449 447
@@ -453,58 +451,58 @@ GST_manipulation_init ()
453 * @param peer the disconnecting peer 451 * @param peer the disconnecting peer
454 */ 452 */
455void 453void
456GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer) 454GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer)
457{ 455{
458 struct TM_Peer *tmp; 456 struct TM_Peer *tmp;
459 struct DelayQueueEntry *dqe; 457 struct DelayQueueEntry *dqe;
460 struct DelayQueueEntry *next; 458 struct DelayQueueEntry *next;
461 459
462 tmp = GNUNET_CONTAINER_multipeermap_get (peers, 460 tmp = GNUNET_CONTAINER_multipeermap_get(peers,
463 peer); 461 peer);
464 if (NULL != tmp) 462 if (NULL != tmp)
465 {
466 while (NULL != (dqe = tmp->send_head))
467 { 463 {
468 GNUNET_CONTAINER_DLL_remove (tmp->send_head, 464 while (NULL != (dqe = tmp->send_head))
469 tmp->send_tail, 465 {
470 dqe); 466 GNUNET_CONTAINER_DLL_remove(tmp->send_head,
471 if (NULL != dqe->cont) 467 tmp->send_tail,
472 dqe->cont (dqe->cont_cls, 468 dqe);
473 GNUNET_SYSERR, 469 if (NULL != dqe->cont)
474 dqe->msg_size, 470 dqe->cont(dqe->cont_cls,
475 0); 471 GNUNET_SYSERR,
476 GNUNET_free(dqe); 472 dqe->msg_size,
473 0);
474 GNUNET_free(dqe);
475 }
477 } 476 }
478 }
479 next = generic_dqe_head; 477 next = generic_dqe_head;
480 while (NULL != (dqe = next)) 478 while (NULL != (dqe = next))
481 {
482 next = dqe->next;
483 if (0 == memcmp (peer,
484 &dqe->id,
485 sizeof (dqe->id)))
486 { 479 {
487 GNUNET_CONTAINER_DLL_remove (generic_dqe_head, 480 next = dqe->next;
488 generic_dqe_tail, 481 if (0 == memcmp(peer,
489 dqe); 482 &dqe->id,
490 if (NULL != dqe->cont) 483 sizeof(dqe->id)))
491 dqe->cont (dqe->cont_cls, 484 {
492 GNUNET_SYSERR, 485 GNUNET_CONTAINER_DLL_remove(generic_dqe_head,
493 dqe->msg_size, 486 generic_dqe_tail,
494 0); 487 dqe);
495 GNUNET_free(dqe); 488 if (NULL != dqe->cont)
489 dqe->cont(dqe->cont_cls,
490 GNUNET_SYSERR,
491 dqe->msg_size,
492 0);
493 GNUNET_free(dqe);
494 }
496 } 495 }
497 }
498 if (NULL != generic_send_delay_task) 496 if (NULL != generic_send_delay_task)
499 { 497 {
500 GNUNET_SCHEDULER_cancel (generic_send_delay_task); 498 GNUNET_SCHEDULER_cancel(generic_send_delay_task);
501 generic_send_delay_task = NULL; 499 generic_send_delay_task = NULL;
502 if (NULL != generic_dqe_head) 500 if (NULL != generic_dqe_head)
503 generic_send_delay_task 501 generic_send_delay_task
504 = GNUNET_SCHEDULER_add_at (generic_dqe_head->sent_at, 502 = GNUNET_SCHEDULER_add_at(generic_dqe_head->sent_at,
505 &send_delayed, 503 &send_delayed,
506 generic_dqe_head); 504 generic_dqe_head);
507 } 505 }
508} 506}
509 507
510 508
@@ -517,35 +515,35 @@ GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer)
517 * @return #GNUNET_OK (continue to iterate) 515 * @return #GNUNET_OK (continue to iterate)
518 */ 516 */
519static int 517static int
520free_tmps (void *cls, 518free_tmps(void *cls,
521 const struct GNUNET_PeerIdentity *key, 519 const struct GNUNET_PeerIdentity *key,
522 void *value) 520 void *value)
523{ 521{
524 struct TM_Peer *tmp = value; 522 struct TM_Peer *tmp = value;
525 struct DelayQueueEntry *dqe; 523 struct DelayQueueEntry *dqe;
526 524
527 GNUNET_break (GNUNET_YES == 525 GNUNET_break(GNUNET_YES ==
528 GNUNET_CONTAINER_multipeermap_remove (peers, 526 GNUNET_CONTAINER_multipeermap_remove(peers,
529 key, 527 key,
530 value)); 528 value));
531 while (NULL != (dqe = tmp->send_head)) 529 while (NULL != (dqe = tmp->send_head))
532 { 530 {
533 GNUNET_CONTAINER_DLL_remove (tmp->send_head, 531 GNUNET_CONTAINER_DLL_remove(tmp->send_head,
534 tmp->send_tail, 532 tmp->send_tail,
535 dqe); 533 dqe);
536 if (NULL != dqe->cont) 534 if (NULL != dqe->cont)
537 dqe->cont (dqe->cont_cls, 535 dqe->cont(dqe->cont_cls,
538 GNUNET_SYSERR, 536 GNUNET_SYSERR,
539 dqe->msg_size, 537 dqe->msg_size,
540 0); 538 0);
541 GNUNET_free (dqe); 539 GNUNET_free(dqe);
542 } 540 }
543 if (NULL != tmp->send_delay_task) 541 if (NULL != tmp->send_delay_task)
544 { 542 {
545 GNUNET_SCHEDULER_cancel (tmp->send_delay_task); 543 GNUNET_SCHEDULER_cancel(tmp->send_delay_task);
546 tmp->send_delay_task = NULL; 544 tmp->send_delay_task = NULL;
547 } 545 }
548 GNUNET_free (tmp); 546 GNUNET_free(tmp);
549 return GNUNET_OK; 547 return GNUNET_OK;
550} 548}
551 549
@@ -554,32 +552,32 @@ free_tmps (void *cls,
554 * Stop traffic manipulation 552 * Stop traffic manipulation
555 */ 553 */
556void 554void
557GST_manipulation_stop () 555GST_manipulation_stop()
558{ 556{
559 struct DelayQueueEntry *cur; 557 struct DelayQueueEntry *cur;
560 558
561 GNUNET_CONTAINER_multipeermap_iterate (peers, 559 GNUNET_CONTAINER_multipeermap_iterate(peers,
562 &free_tmps, 560 &free_tmps,
563 NULL); 561 NULL);
564 GNUNET_CONTAINER_multipeermap_destroy (peers); 562 GNUNET_CONTAINER_multipeermap_destroy(peers);
565 peers = NULL; 563 peers = NULL;
566 while (NULL != (cur = generic_dqe_head)) 564 while (NULL != (cur = generic_dqe_head))
567 { 565 {
568 GNUNET_CONTAINER_DLL_remove (generic_dqe_head, 566 GNUNET_CONTAINER_DLL_remove(generic_dqe_head,
569 generic_dqe_tail, 567 generic_dqe_tail,
570 cur); 568 cur);
571 if (NULL != cur->cont) 569 if (NULL != cur->cont)
572 cur->cont (cur->cont_cls, 570 cur->cont(cur->cont_cls,
573 GNUNET_SYSERR, 571 GNUNET_SYSERR,
574 cur->msg_size, 572 cur->msg_size,
575 0); 573 0);
576 GNUNET_free (cur); 574 GNUNET_free(cur);
577 } 575 }
578 if (NULL != generic_send_delay_task) 576 if (NULL != generic_send_delay_task)
579 { 577 {
580 GNUNET_SCHEDULER_cancel (generic_send_delay_task); 578 GNUNET_SCHEDULER_cancel(generic_send_delay_task);
581 generic_send_delay_task = NULL; 579 generic_send_delay_task = NULL;
582 } 580 }
583} 581}
584 582
585/* end of file gnunet-service-transport_manipulation.c */ 583/* 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 87e71329a..e2ab69d94 100644
--- a/src/transport/gnunet-service-transport_manipulation.h
+++ b/src/transport/gnunet-service-transport_manipulation.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_neighbours.h 22 * @file transport/gnunet-service-transport_neighbours.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 3472e8ee0..73d9a27f1 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_neighbours.c 22 * @file transport/gnunet-service-transport_neighbours.c
@@ -50,7 +50,7 @@
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(GNUNET_TIME_UNIT_MILLISECONDS, 500)
54 54
55/** 55/**
56 * How often must a peer violate bandwidth quotas before we start 56 * How often must a peer violate bandwidth quotas before we start
@@ -61,13 +61,13 @@
61/** 61/**
62 * How long are we willing to wait for a response from ATS before timing out? 62 * How long are we willing to wait for a response from ATS before timing out?
63 */ 63 */
64#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 64#define ATS_RESPONSE_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
65 65
66/** 66/**
67 * How long are we willing to wait for an ACK from the other peer before 67 * How long are we willing to wait for an ACK from the other peer before
68 * giving up on our connect operation? 68 * giving up on our connect operation?
69 */ 69 */
70#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 70#define SETUP_CONNECTION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
71 71
72/** 72/**
73 * How long are we willing to wait for a successful reconnect if 73 * How long are we willing to wait for a successful reconnect if
@@ -85,8 +85,7 @@
85/** 85/**
86 * State describing which kind a reply this neighbour should send 86 * State describing which kind a reply this neighbour should send
87 */ 87 */
88enum GST_ACK_State 88enum GST_ACK_State {
89{
90 /** 89 /**
91 * We did not receive a SYN message for this neighbour 90 * We did not receive a SYN message for this neighbour
92 */ 91 */
@@ -116,8 +115,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
116 * a 'ACK'. Once the 'ACK' is received, both peers 115 * a 'ACK'. Once the 'ACK' is received, both peers
117 * should be connected. 116 * should be connected.
118 */ 117 */
119struct TransportSynMessage 118struct TransportSynMessage {
120{
121 /** 119 /**
122 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN 120 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN
123 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK 121 * or #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK
@@ -134,7 +132,6 @@ struct TransportSynMessage
134 * message implies which session is preferred by the sender. 132 * message implies which session is preferred by the sender.
135 */ 133 */
136 struct GNUNET_TIME_AbsoluteNBO timestamp; 134 struct GNUNET_TIME_AbsoluteNBO timestamp;
137
138}; 135};
139 136
140 137
@@ -146,8 +143,7 @@ struct TransportSynMessage
146 * When the keep alive response with type is received, transport service 143 * When the keep alive response with type is received, transport service
147 * will call the respective plugin to update the session timeout 144 * will call the respective plugin to update the session timeout
148 */ 145 */
149struct GNUNET_ATS_SessionKeepAliveMessage 146struct GNUNET_ATS_SessionKeepAliveMessage {
150{
151 /** 147 /**
152 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or 148 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE or
153 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE. 149 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE.
@@ -166,8 +162,7 @@ struct GNUNET_ATS_SessionKeepAliveMessage
166 * the other peer should limit transmissions to the indicated 162 * the other peer should limit transmissions to the indicated
167 * quota. 163 * quota.
168 */ 164 */
169struct GNUNET_ATS_SessionQuotaMessage 165struct GNUNET_ATS_SessionQuotaMessage {
170{
171 /** 166 /**
172 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA. 167 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA.
173 */ 168 */
@@ -186,8 +181,7 @@ struct GNUNET_ATS_SessionQuotaMessage
186 * notification, peers must not rely on always receiving disconnect 181 * notification, peers must not rely on always receiving disconnect
187 * messages. 182 * messages.
188 */ 183 */
189struct GNUNET_ATS_SessionDisconnectMessage 184struct GNUNET_ATS_SessionDisconnectMessage {
190{
191 /** 185 /**
192 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT 186 * Header of type #GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT
193 */ 187 */
@@ -221,7 +215,6 @@ struct GNUNET_ATS_SessionDisconnectMessage
221 * corresponding 'SYN' message. 215 * corresponding 'SYN' message.
222 */ 216 */
223 struct GNUNET_CRYPTO_EddsaSignature signature; 217 struct GNUNET_CRYPTO_EddsaSignature signature;
224
225}; 218};
226 219
227GNUNET_NETWORK_STRUCT_END 220GNUNET_NETWORK_STRUCT_END
@@ -231,9 +224,7 @@ GNUNET_NETWORK_STRUCT_END
231 * For each neighbour we keep a list of messages 224 * For each neighbour we keep a list of messages
232 * that we still want to transmit to the neighbour. 225 * that we still want to transmit to the neighbour.
233 */ 226 */
234struct MessageQueue 227struct MessageQueue {
235{
236
237 /** 228 /**
238 * This is a doubly linked list. 229 * This is a doubly linked list.
239 */ 230 */
@@ -269,16 +260,13 @@ struct MessageQueue
269 * At what time should we fail? 260 * At what time should we fail?
270 */ 261 */
271 struct GNUNET_TIME_Absolute timeout; 262 struct GNUNET_TIME_Absolute timeout;
272
273}; 263};
274 264
275 265
276/** 266/**
277 * A possible address we could use to communicate with a neighbour. 267 * A possible address we could use to communicate with a neighbour.
278 */ 268 */
279struct NeighbourAddress 269struct NeighbourAddress {
280{
281
282 /** 270 /**
283 * Active session for this address. 271 * Active session for this address.
284 */ 272 */
@@ -321,9 +309,7 @@ struct NeighbourAddress
321/** 309/**
322 * Entry in neighbours. 310 * Entry in neighbours.
323 */ 311 */
324struct NeighbourMapEntry 312struct NeighbourMapEntry {
325{
326
327 /** 313 /**
328 * Head of list of messages we would like to send to this peer; 314 * Head of list of messages we would like to send to this peer;
329 * must contain at most one message per client. 315 * must contain at most one message per client.
@@ -497,19 +483,23 @@ static struct GNUNET_SCHEDULER_Task *util_transmission_tk;
497 * @return corresponding human-readable string 483 * @return corresponding human-readable string
498 */ 484 */
499static char * 485static char *
500print_ack_state (enum GST_ACK_State s) 486print_ack_state(enum GST_ACK_State s)
501{ 487{
502 switch (s) { 488 switch (s)
489 {
503 case ACK_UNDEFINED: 490 case ACK_UNDEFINED:
504 return "UNDEFINED"; 491 return "UNDEFINED";
492
505 case ACK_SEND_SYN_ACK: 493 case ACK_SEND_SYN_ACK:
506 return "SEND_SYN_ACK"; 494 return "SEND_SYN_ACK";
495
507 case ACK_SEND_ACK: 496 case ACK_SEND_ACK:
508 return "SEND_ACK"; 497 return "SEND_ACK";
498
509 default: 499 default:
510 GNUNET_break (0); 500 GNUNET_break(0);
511 return "N/A"; 501 return "N/A";
512 } 502 }
513} 503}
514 504
515 505
@@ -521,30 +511,30 @@ print_ack_state (enum GST_ACK_State s)
521 * @param n affected peer 511 * @param n affected peer
522 */ 512 */
523static void 513static void
524send_outbound_quota_to_clients (struct NeighbourMapEntry *n) 514send_outbound_quota_to_clients(struct NeighbourMapEntry *n)
525{ 515{
526 struct QuotaSetMessage q_msg; 516 struct QuotaSetMessage q_msg;
527 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; 517 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
528 518
529 if (! GNUNET_TRANSPORT_is_connected (n->state)) 519 if (!GNUNET_TRANSPORT_is_connected(n->state))
530 return; 520 return;
531#if IGNORE_INBOUND_QUOTA 521#if IGNORE_INBOUND_QUOTA
532 bandwidth_min = n->primary_address.bandwidth_out; 522 bandwidth_min = n->primary_address.bandwidth_out;
533#else 523#else
534 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out, 524 bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out,
535 n->neighbour_receive_quota); 525 n->neighbour_receive_quota);
536#endif 526#endif
537 527
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 528 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
539 "Sending outbound quota of %u Bps for peer `%s' to all clients\n", 529 "Sending outbound quota of %u Bps for peer `%s' to all clients\n",
540 ntohl (bandwidth_min.value__), 530 ntohl(bandwidth_min.value__),
541 GNUNET_i2s (&n->id)); 531 GNUNET_i2s(&n->id));
542 q_msg.header.size = htons (sizeof (struct QuotaSetMessage)); 532 q_msg.header.size = htons(sizeof(struct QuotaSetMessage));
543 q_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA); 533 q_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA);
544 q_msg.quota = bandwidth_min; 534 q_msg.quota = bandwidth_min;
545 q_msg.peer = n->id; 535 q_msg.peer = n->id;
546 GST_clients_broadcast (&q_msg.header, 536 GST_clients_broadcast(&q_msg.header,
547 GNUNET_NO); 537 GNUNET_NO);
548} 538}
549 539
550 540
@@ -554,28 +544,28 @@ send_outbound_quota_to_clients (struct NeighbourMapEntry *n)
554 * @param n the peer that connected 544 * @param n the peer that connected
555 */ 545 */
556static void 546static void
557neighbours_connect_notification (struct NeighbourMapEntry *n) 547neighbours_connect_notification(struct NeighbourMapEntry *n)
558{ 548{
559 size_t len = sizeof(struct ConnectInfoMessage); 549 size_t len = sizeof(struct ConnectInfoMessage);
560 char buf[len] GNUNET_ALIGN; 550 char buf[len] GNUNET_ALIGN;
561 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf; 551 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *)buf;
562 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min; 552 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_min;
563 553
564#if IGNORE_INBOUND_QUOTA 554#if IGNORE_INBOUND_QUOTA
565 bandwidth_min = n->primary_address.bandwidth_out; 555 bandwidth_min = n->primary_address.bandwidth_out;
566#else 556#else
567 bandwidth_min = GNUNET_BANDWIDTH_value_min (n->primary_address.bandwidth_out, 557 bandwidth_min = GNUNET_BANDWIDTH_value_min(n->primary_address.bandwidth_out,
568 n->neighbour_receive_quota); 558 n->neighbour_receive_quota);
569#endif 559#endif
570 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 560 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
571 "We are now connected to peer `%s'\n", 561 "We are now connected to peer `%s'\n",
572 GNUNET_i2s (&n->id)); 562 GNUNET_i2s(&n->id));
573 connect_msg->header.size = htons (sizeof(buf)); 563 connect_msg->header.size = htons(sizeof(buf));
574 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 564 connect_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
575 connect_msg->id = n->id; 565 connect_msg->id = n->id;
576 connect_msg->quota_out = bandwidth_min; 566 connect_msg->quota_out = bandwidth_min;
577 GST_clients_broadcast (&connect_msg->header, 567 GST_clients_broadcast(&connect_msg->header,
578 GNUNET_NO); 568 GNUNET_NO);
579} 569}
580 570
581 571
@@ -586,13 +576,13 @@ neighbours_connect_notification (struct NeighbourMapEntry *n)
586 * @param n the peer that disconnected 576 * @param n the peer that disconnected
587 */ 577 */
588static void 578static void
589neighbours_disconnect_notification (struct NeighbourMapEntry *n) 579neighbours_disconnect_notification(struct NeighbourMapEntry *n)
590{ 580{
591 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 581 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
592 "Peer `%s' disconnected\n", 582 "Peer `%s' disconnected\n",
593 GNUNET_i2s (&n->id)); 583 GNUNET_i2s(&n->id));
594 GST_manipulation_peer_disconnect (&n->id); 584 GST_manipulation_peer_disconnect(&n->id);
595 GST_clients_broadcast_disconnect (&n->id); 585 GST_clients_broadcast_disconnect(&n->id);
596} 586}
597 587
598 588
@@ -608,26 +598,26 @@ neighbours_disconnect_notification (struct NeighbourMapEntry *n)
608 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect 598 * @param bandwidth_out bandwidth assigned outbound, 0 on disconnect
609 */ 599 */
610static void 600static void
611neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer, 601neighbours_changed_notification(const struct GNUNET_PeerIdentity *peer,
612 const struct GNUNET_HELLO_Address *address, 602 const struct GNUNET_HELLO_Address *address,
613 enum GNUNET_TRANSPORT_PeerState state, 603 enum GNUNET_TRANSPORT_PeerState state,
614 struct GNUNET_TIME_Absolute state_timeout, 604 struct GNUNET_TIME_Absolute state_timeout,
615 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 605 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
616 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 606 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
617{ 607{
618 (void) bandwidth_in; 608 (void)bandwidth_in;
619 (void) bandwidth_out; 609 (void)bandwidth_out;
620 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 610 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
621 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n", 611 "Notifying about change for peer `%s' with address `%s' in state `%s' timing out at %s\n",
622 GNUNET_i2s (peer), 612 GNUNET_i2s(peer),
623 GST_plugins_a2s (address), 613 GST_plugins_a2s(address),
624 GNUNET_TRANSPORT_ps2s (state), 614 GNUNET_TRANSPORT_ps2s(state),
625 GNUNET_STRINGS_absolute_time_to_string (state_timeout)); 615 GNUNET_STRINGS_absolute_time_to_string(state_timeout));
626 /* FIXME: include bandwidth in notification! */ 616 /* FIXME: include bandwidth in notification! */
627 GST_clients_broadcast_peer_notification (peer, 617 GST_clients_broadcast_peer_notification(peer,
628 address, 618 address,
629 state, 619 state,
630 state_timeout); 620 state_timeout);
631} 621}
632 622
633 623
@@ -638,11 +628,11 @@ neighbours_changed_notification (const struct GNUNET_PeerIdentity *peer,
638 * @return the entry, NULL if there is no existing record 628 * @return the entry, NULL if there is no existing record
639 */ 629 */
640static struct NeighbourMapEntry * 630static struct NeighbourMapEntry *
641lookup_neighbour (const struct GNUNET_PeerIdentity *pid) 631lookup_neighbour(const struct GNUNET_PeerIdentity *pid)
642{ 632{
643 if (NULL == neighbours) 633 if (NULL == neighbours)
644 return NULL; 634 return NULL;
645 return GNUNET_CONTAINER_multipeermap_get (neighbours, pid); 635 return GNUNET_CONTAINER_multipeermap_get(neighbours, pid);
646} 636}
647 637
648 638
@@ -653,11 +643,11 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
653 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 643 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
654 */ 644 */
655static int 645static int
656test_connected (struct NeighbourMapEntry *n) 646test_connected(struct NeighbourMapEntry *n)
657{ 647{
658 if (NULL == n) 648 if (NULL == n)
659 return GNUNET_NO; 649 return GNUNET_NO;
660 return GNUNET_TRANSPORT_is_connected (n->state); 650 return GNUNET_TRANSPORT_is_connected(n->state);
661} 651}
662 652
663 653
@@ -669,20 +659,20 @@ test_connected (struct NeighbourMapEntry *n)
669 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents! 659 * @param na address we are done with; @a na itself must NOT be 'free'd, only the contents!
670 */ 660 */
671static void 661static void
672free_address (struct NeighbourAddress *na) 662free_address(struct NeighbourAddress *na)
673{ 663{
674 if (GNUNET_YES == na->ats_active) 664 if (GNUNET_YES == na->ats_active)
675 GST_validation_set_address_use (na->address, 665 GST_validation_set_address_use(na->address,
676 GNUNET_NO); 666 GNUNET_NO);
677 if (NULL != na->address) 667 if (NULL != na->address)
678 { 668 {
679 GST_ats_block_address (na->address, 669 GST_ats_block_address(na->address,
680 na->session); 670 na->session);
681 GNUNET_HELLO_address_free (na->address); 671 GNUNET_HELLO_address_free(na->address);
682 na->address = NULL; 672 na->address = NULL;
683 } 673 }
684 na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0); 674 na->bandwidth_in = GNUNET_BANDWIDTH_value_init(0);
685 na->bandwidth_out = GNUNET_BANDWIDTH_value_init (0); 675 na->bandwidth_out = GNUNET_BANDWIDTH_value_init(0);
686 na->ats_active = GNUNET_NO; 676 na->ats_active = GNUNET_NO;
687 na->keep_alive_nonce = 0; 677 na->keep_alive_nonce = 0;
688 na->session = NULL; 678 na->session = NULL;
@@ -697,7 +687,7 @@ free_address (struct NeighbourAddress *na)
697 * @param cls the `struct NeighbourMapEntry` for which we are running 687 * @param cls the `struct NeighbourMapEntry` for which we are running
698 */ 688 */
699static void 689static void
700master_task (void *cls); 690master_task(void *cls);
701 691
702 692
703/** 693/**
@@ -708,50 +698,50 @@ master_task (void *cls);
708 * @param timeout the new timeout 698 * @param timeout the new timeout
709 */ 699 */
710static void 700static void
711set_state_and_timeout (struct NeighbourMapEntry *n, 701set_state_and_timeout(struct NeighbourMapEntry *n,
712 enum GNUNET_TRANSPORT_PeerState s, 702 enum GNUNET_TRANSPORT_PeerState s,
713 struct GNUNET_TIME_Absolute timeout) 703 struct GNUNET_TIME_Absolute timeout)
714{ 704{
715 if (GNUNET_TRANSPORT_is_connected (s) && 705 if (GNUNET_TRANSPORT_is_connected(s) &&
716 (! GNUNET_TRANSPORT_is_connected (n->state)) ) 706 (!GNUNET_TRANSPORT_is_connected(n->state)))
717 { 707 {
718 neighbours_connect_notification (n); 708 neighbours_connect_notification(n);
719 GNUNET_STATISTICS_set (GST_stats, 709 GNUNET_STATISTICS_set(GST_stats,
720 gettext_noop ("# peers connected"), 710 gettext_noop("# peers connected"),
721 ++neighbours_connected, 711 ++neighbours_connected,
722 GNUNET_NO); 712 GNUNET_NO);
723 } 713 }
724 if ((! GNUNET_TRANSPORT_is_connected (s)) && 714 if ((!GNUNET_TRANSPORT_is_connected(s)) &&
725 GNUNET_TRANSPORT_is_connected (n->state) ) 715 GNUNET_TRANSPORT_is_connected(n->state))
726 { 716 {
727 GNUNET_STATISTICS_set (GST_stats, 717 GNUNET_STATISTICS_set(GST_stats,
728 gettext_noop ("# peers connected"), 718 gettext_noop("# peers connected"),
729 --neighbours_connected, 719 --neighbours_connected,
730 GNUNET_NO); 720 GNUNET_NO);
731 neighbours_disconnect_notification (n); 721 neighbours_disconnect_notification(n);
732 } 722 }
733 n->state = s; 723 n->state = s;
734 if ( (timeout.abs_value_us < n->timeout.abs_value_us) && 724 if ((timeout.abs_value_us < n->timeout.abs_value_us) &&
735 (NULL != n->task ) ) 725 (NULL != n->task))
736 { 726 {
737 /* new timeout is earlier, reschedule master task */ 727 /* new timeout is earlier, reschedule master task */
738 GNUNET_SCHEDULER_cancel (n->task); 728 GNUNET_SCHEDULER_cancel(n->task);
739 n->task = GNUNET_SCHEDULER_add_at (timeout, 729 n->task = GNUNET_SCHEDULER_add_at(timeout,
740 &master_task, 730 &master_task,
741 n); 731 n);
742 } 732 }
743 n->timeout = timeout; 733 n->timeout = timeout;
744 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 734 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
745 "Neighbour `%s' changed state to %s with timeout %s\n", 735 "Neighbour `%s' changed state to %s with timeout %s\n",
746 GNUNET_i2s (&n->id), 736 GNUNET_i2s(&n->id),
747 GNUNET_TRANSPORT_ps2s(s), 737 GNUNET_TRANSPORT_ps2s(s),
748 GNUNET_STRINGS_absolute_time_to_string (timeout)); 738 GNUNET_STRINGS_absolute_time_to_string(timeout));
749 neighbours_changed_notification (&n->id, 739 neighbours_changed_notification(&n->id,
750 n->primary_address.address, 740 n->primary_address.address,
751 n->state, 741 n->state,
752 n->timeout, 742 n->timeout,
753 n->primary_address.bandwidth_in, 743 n->primary_address.bandwidth_in,
754 n->primary_address.bandwidth_out); 744 n->primary_address.bandwidth_out);
755} 745}
756 746
757 747
@@ -767,62 +757,62 @@ set_state_and_timeout (struct NeighbourMapEntry *n,
767 * @param bandwidth_out outbound quota to be used when connection is up 757 * @param bandwidth_out outbound quota to be used when connection is up
768 */ 758 */
769static void 759static void
770set_alternative_address (struct NeighbourMapEntry *n, 760set_alternative_address(struct NeighbourMapEntry *n,
771 const struct GNUNET_HELLO_Address *address, 761 const struct GNUNET_HELLO_Address *address,
772 struct GNUNET_ATS_Session *session, 762 struct GNUNET_ATS_Session *session,
773 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 763 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
774 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 764 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
775{ 765{
776 struct GNUNET_TRANSPORT_PluginFunctions *papi; 766 struct GNUNET_TRANSPORT_PluginFunctions *papi;
777 767
778 if (NULL == (papi = GST_plugins_find (address->transport_name))) 768 if (NULL == (papi = GST_plugins_find(address->transport_name)))
779 { 769 {
780 GNUNET_break (0); 770 GNUNET_break(0);
781 return; 771 return;
782 } 772 }
783 if (session == n->alternative_address.session) 773 if (session == n->alternative_address.session)
784 { 774 {
785 n->alternative_address.bandwidth_in = bandwidth_in; 775 n->alternative_address.bandwidth_in = bandwidth_in;
786 n->alternative_address.bandwidth_out = bandwidth_out; 776 n->alternative_address.bandwidth_out = bandwidth_out;
787 return; 777 return;
788 } 778 }
789 if (NULL != n->alternative_address.address) 779 if (NULL != n->alternative_address.address)
790 { 780 {
791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 781 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
792 "Replacing existing alternative address with another one\n"); 782 "Replacing existing alternative address with another one\n");
793 free_address (&n->alternative_address); 783 free_address(&n->alternative_address);
794 } 784 }
795 if (NULL == session) 785 if (NULL == session)
796 session = papi->get_session (papi->cls, 786 session = papi->get_session(papi->cls,
797 address); 787 address);
798 if (NULL == session) 788 if (NULL == session)
799 { 789 {
800 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 790 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
801 "Failed to obtain new session for peer `%s' and address '%s'\n", 791 "Failed to obtain new session for peer `%s' and address '%s'\n",
802 GNUNET_i2s (&address->peer), 792 GNUNET_i2s(&address->peer),
803 GST_plugins_a2s (address)); 793 GST_plugins_a2s(address));
804 GNUNET_STATISTICS_update (GST_stats, 794 GNUNET_STATISTICS_update(GST_stats,
805 gettext_noop ("# session creation failed"), 795 gettext_noop("# session creation failed"),
806 1, 796 1,
807 GNUNET_NO); 797 GNUNET_NO);
808 return; 798 return;
809 } 799 }
810 GST_ats_new_session (address, 800 GST_ats_new_session(address,
811 session); 801 session);
812 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 802 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
813 "Neighbour `%s' configured alternative address %s\n", 803 "Neighbour `%s' configured alternative address %s\n",
814 GNUNET_i2s (&n->id), 804 GNUNET_i2s(&n->id),
815 GST_plugins_a2s(address)); 805 GST_plugins_a2s(address));
816 806
817 n->alternative_address.address = GNUNET_HELLO_address_copy (address); 807 n->alternative_address.address = GNUNET_HELLO_address_copy(address);
818 n->alternative_address.bandwidth_in = bandwidth_in; 808 n->alternative_address.bandwidth_in = bandwidth_in;
819 n->alternative_address.bandwidth_out = bandwidth_out; 809 n->alternative_address.bandwidth_out = bandwidth_out;
820 n->alternative_address.session = session; 810 n->alternative_address.session = session;
821 n->alternative_address.ats_active = GNUNET_NO; 811 n->alternative_address.ats_active = GNUNET_NO;
822 n->alternative_address.keep_alive_nonce = 0; 812 n->alternative_address.keep_alive_nonce = 0;
823 GNUNET_assert (GNUNET_YES == 813 GNUNET_assert(GNUNET_YES ==
824 GST_ats_is_known (n->alternative_address.address, 814 GST_ats_is_known(n->alternative_address.address,
825 n->alternative_address.session)); 815 n->alternative_address.session));
826} 816}
827 817
828 818
@@ -843,40 +833,40 @@ set_alternative_address (struct NeighbourMapEntry *n,
843 * @a use_keepalive_timeout is #GNUNET_YES. 833 * @a use_keepalive_timeout is #GNUNET_YES.
844 */ 834 */
845static struct GNUNET_TIME_Relative 835static struct GNUNET_TIME_Relative
846send_with_session (struct NeighbourMapEntry *n, 836send_with_session(struct NeighbourMapEntry *n,
847 const void *msgbuf, 837 const void *msgbuf,
848 size_t msgbuf_size, 838 size_t msgbuf_size,
849 uint32_t priority, 839 uint32_t priority,
850 struct GNUNET_TIME_Relative timeout, 840 struct GNUNET_TIME_Relative timeout,
851 unsigned int use_keepalive_timeout, 841 unsigned int use_keepalive_timeout,
852 GNUNET_TRANSPORT_TransmitContinuation cont, 842 GNUNET_TRANSPORT_TransmitContinuation cont,
853 void *cont_cls) 843 void *cont_cls)
854{ 844{
855 struct GNUNET_TRANSPORT_PluginFunctions *papi; 845 struct GNUNET_TRANSPORT_PluginFunctions *papi;
856 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL; 846 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL;
857 847
858 GNUNET_assert (NULL != n->primary_address.session); 848 GNUNET_assert(NULL != n->primary_address.session);
859 if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) || 849 if (((NULL == (papi = GST_plugins_find(n->primary_address.address->transport_name)) ||
860 (-1 == papi->send (papi->cls, 850 (-1 == papi->send(papi->cls,
861 n->primary_address.session, 851 n->primary_address.session,
862 msgbuf, 852 msgbuf,
863 msgbuf_size, 853 msgbuf_size,
864 priority, 854 priority,
865 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout : 855 (result = (GNUNET_NO == use_keepalive_timeout) ? timeout :
866 GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 856 GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
867 papi->query_keepalive_factor (papi->cls))), 857 papi->query_keepalive_factor(papi->cls))),
868 cont, 858 cont,
869 cont_cls)))) && 859 cont_cls)))) &&
870 (NULL != cont)) 860 (NULL != cont))
871 cont (cont_cls, 861 cont(cont_cls,
872 &n->id, 862 &n->id,
873 GNUNET_SYSERR, 863 GNUNET_SYSERR,
874 msgbuf_size, 864 msgbuf_size,
875 0); 865 0);
876 GST_neighbours_notify_data_sent (n->primary_address.address, 866 GST_neighbours_notify_data_sent(n->primary_address.address,
877 n->primary_address.session, 867 n->primary_address.session,
878 msgbuf_size); 868 msgbuf_size);
879 GNUNET_break (NULL != papi); 869 GNUNET_break(NULL != papi);
880 return result; 870 return result;
881} 871}
882 872
@@ -888,20 +878,20 @@ send_with_session (struct NeighbourMapEntry *n,
888 * @param n the neighbour 878 * @param n the neighbour
889 */ 879 */
890static void 880static void
891unset_primary_address (struct NeighbourMapEntry *n) 881unset_primary_address(struct NeighbourMapEntry *n)
892{ 882{
893 /* Notify monitoring about change */ 883 /* Notify monitoring about change */
894 if (NULL == n->primary_address.address) 884 if (NULL == n->primary_address.address)
895 return; 885 return;
896 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 886 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
897 "Disabling primary address\n"); 887 "Disabling primary address\n");
898 neighbours_changed_notification (&n->id, 888 neighbours_changed_notification(&n->id,
899 n->primary_address.address, 889 n->primary_address.address,
900 n->state, 890 n->state,
901 n->timeout, 891 n->timeout,
902 GNUNET_BANDWIDTH_value_init (0), 892 GNUNET_BANDWIDTH_value_init(0),
903 GNUNET_BANDWIDTH_value_init (0)); 893 GNUNET_BANDWIDTH_value_init(0));
904 free_address (&n->primary_address); 894 free_address(&n->primary_address);
905} 895}
906 896
907 897
@@ -911,68 +901,68 @@ unset_primary_address (struct NeighbourMapEntry *n)
911 * @param n entry to free 901 * @param n entry to free
912 */ 902 */
913static void 903static void
914free_neighbour (struct NeighbourMapEntry *n) 904free_neighbour(struct NeighbourMapEntry *n)
915{ 905{
916 struct MessageQueue *mq; 906 struct MessageQueue *mq;
917 907
918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 908 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
919 "Freeing neighbour state of peer `%s'\n", 909 "Freeing neighbour state of peer `%s'\n",
920 GNUNET_i2s (&n->id)); 910 GNUNET_i2s(&n->id));
921 n->is_active = NULL; /* always free'd by its own continuation! */ 911 n->is_active = NULL; /* always free'd by its own continuation! */
922 912
923 /* fail messages currently in the queue */ 913 /* fail messages currently in the queue */
924 while (NULL != (mq = n->messages_head)) 914 while (NULL != (mq = n->messages_head))
925 { 915 {
926 GNUNET_CONTAINER_DLL_remove (n->messages_head, 916 GNUNET_CONTAINER_DLL_remove(n->messages_head,
927 n->messages_tail, 917 n->messages_tail,
928 mq); 918 mq);
929 if (NULL != mq->cont) 919 if (NULL != mq->cont)
930 mq->cont (mq->cont_cls, 920 mq->cont(mq->cont_cls,
931 GNUNET_SYSERR, 921 GNUNET_SYSERR,
932 mq->message_buf_size, 922 mq->message_buf_size,
933 0); 923 0);
934 GNUNET_free (mq); 924 GNUNET_free(mq);
935 } 925 }
936 /* Mark peer as disconnected */ 926 /* Mark peer as disconnected */
937 set_state_and_timeout (n, 927 set_state_and_timeout(n,
938 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED, 928 GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED,
939 GNUNET_TIME_UNIT_FOREVER_ABS); 929 GNUNET_TIME_UNIT_FOREVER_ABS);
940 /* free addresses and mark as unused */ 930 /* free addresses and mark as unused */
941 unset_primary_address (n); 931 unset_primary_address(n);
942 932
943 if (NULL != n->alternative_address.address) 933 if (NULL != n->alternative_address.address)
944 { 934 {
945 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 935 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
946 "Cleaning up alternative address\n"); 936 "Cleaning up alternative address\n");
947 free_address (&n->alternative_address); 937 free_address(&n->alternative_address);
948 } 938 }
949 GNUNET_assert (GNUNET_YES == 939 GNUNET_assert(GNUNET_YES ==
950 GNUNET_CONTAINER_multipeermap_remove (neighbours, 940 GNUNET_CONTAINER_multipeermap_remove(neighbours,
951 &n->id, 941 &n->id,
952 n)); 942 n));
953 943
954 /* Cancel address requests for this peer */ 944 /* Cancel address requests for this peer */
955 if (NULL != n->suggest_handle) 945 if (NULL != n->suggest_handle)
956 { 946 {
957 GNUNET_ATS_connectivity_suggest_cancel (n->suggest_handle); 947 GNUNET_ATS_connectivity_suggest_cancel(n->suggest_handle);
958 n->suggest_handle = NULL; 948 n->suggest_handle = NULL;
959 } 949 }
960 950
961 /* Cancel the disconnect task */ 951 /* Cancel the disconnect task */
962 if (NULL != n->delayed_disconnect_task) 952 if (NULL != n->delayed_disconnect_task)
963 { 953 {
964 GNUNET_SCHEDULER_cancel (n->delayed_disconnect_task); 954 GNUNET_SCHEDULER_cancel(n->delayed_disconnect_task);
965 n->delayed_disconnect_task = NULL; 955 n->delayed_disconnect_task = NULL;
966 } 956 }
967 957
968 /* Cancel the master task */ 958 /* Cancel the master task */
969 if (NULL != n->task) 959 if (NULL != n->task)
970 { 960 {
971 GNUNET_SCHEDULER_cancel (n->task); 961 GNUNET_SCHEDULER_cancel(n->task);
972 n->task = NULL; 962 n->task = NULL;
973 } 963 }
974 /* free rest of memory */ 964 /* free rest of memory */
975 GNUNET_free (n); 965 GNUNET_free(n);
976} 966}
977 967
978 968
@@ -987,26 +977,26 @@ free_neighbour (struct NeighbourMapEntry *n)
987 * @param physical bytes on wire 977 * @param physical bytes on wire
988 */ 978 */
989static void 979static void
990send_disconnect_cont (void *cls, 980send_disconnect_cont(void *cls,
991 const struct GNUNET_PeerIdentity *target, 981 const struct GNUNET_PeerIdentity *target,
992 int result, 982 int result,
993 size_t payload, 983 size_t payload,
994 size_t physical) 984 size_t physical)
995{ 985{
996 struct NeighbourMapEntry *n; 986 struct NeighbourMapEntry *n;
997 987
998 (void) cls; 988 (void)cls;
999 (void) result; 989 (void)result;
1000 (void) payload; 990 (void)payload;
1001 (void) physical; 991 (void)physical;
1002 n = lookup_neighbour (target); 992 n = lookup_neighbour(target);
1003 if (NULL == n) 993 if (NULL == n)
1004 return; /* already gone */ 994 return; /* already gone */
1005 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state) 995 if (GNUNET_TRANSPORT_PS_DISCONNECT != n->state)
1006 return; /* have created a fresh entry since */ 996 return; /* have created a fresh entry since */
1007 if (NULL != n->task) 997 if (NULL != n->task)
1008 GNUNET_SCHEDULER_cancel (n->task); 998 GNUNET_SCHEDULER_cancel(n->task);
1009 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 999 n->task = GNUNET_SCHEDULER_add_now(&master_task, n);
1010} 1000}
1011 1001
1012 1002
@@ -1016,43 +1006,43 @@ send_disconnect_cont (void *cls,
1016 * @param n neighbour to send DISCONNECT message. 1006 * @param n neighbour to send DISCONNECT message.
1017 */ 1007 */
1018static void 1008static void
1019send_disconnect (struct NeighbourMapEntry *n) 1009send_disconnect(struct NeighbourMapEntry *n)
1020{ 1010{
1021 struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg; 1011 struct GNUNET_ATS_SessionDisconnectMessage disconnect_msg;
1022 1012
1023 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1013 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1024 "Sending DISCONNECT message to peer `%4s'\n", 1014 "Sending DISCONNECT message to peer `%4s'\n",
1025 GNUNET_i2s (&n->id)); 1015 GNUNET_i2s(&n->id));
1026 disconnect_msg.header.size = htons (sizeof (struct GNUNET_ATS_SessionDisconnectMessage)); 1016 disconnect_msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionDisconnectMessage));
1027 disconnect_msg.header.type = 1017 disconnect_msg.header.type =
1028 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 1018 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1029 disconnect_msg.reserved = htonl (0); 1019 disconnect_msg.reserved = htonl(0);
1030 disconnect_msg.purpose.size = 1020 disconnect_msg.purpose.size =
1031 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 1021 htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
1032 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + 1022 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) +
1033 sizeof (struct GNUNET_TIME_AbsoluteNBO)); 1023 sizeof(struct GNUNET_TIME_AbsoluteNBO));
1034 disconnect_msg.purpose.purpose = 1024 disconnect_msg.purpose.purpose =
1035 htonl (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT); 1025 htonl(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT);
1036 disconnect_msg.timestamp = 1026 disconnect_msg.timestamp =
1037 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1027 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get());
1038 disconnect_msg.public_key = GST_my_identity.public_key; 1028 disconnect_msg.public_key = GST_my_identity.public_key;
1039 GNUNET_assert (GNUNET_OK == 1029 GNUNET_assert(GNUNET_OK ==
1040 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, 1030 GNUNET_CRYPTO_eddsa_sign(GST_my_private_key,
1041 &disconnect_msg.purpose, 1031 &disconnect_msg.purpose,
1042 &disconnect_msg.signature)); 1032 &disconnect_msg.signature));
1043 1033
1044 (void) send_with_session (n, 1034 (void)send_with_session(n,
1045 &disconnect_msg, 1035 &disconnect_msg,
1046 sizeof (disconnect_msg), 1036 sizeof(disconnect_msg),
1047 UINT32_MAX, 1037 UINT32_MAX,
1048 GNUNET_TIME_UNIT_FOREVER_REL, 1038 GNUNET_TIME_UNIT_FOREVER_REL,
1049 GNUNET_NO, 1039 GNUNET_NO,
1050 &send_disconnect_cont, 1040 &send_disconnect_cont,
1051 NULL); 1041 NULL);
1052 GNUNET_STATISTICS_update (GST_stats, 1042 GNUNET_STATISTICS_update(GST_stats,
1053 gettext_noop ("# DISCONNECT messages sent"), 1043 gettext_noop("# DISCONNECT messages sent"),
1054 1, 1044 1,
1055 GNUNET_NO); 1045 GNUNET_NO);
1056} 1046}
1057 1047
1058 1048
@@ -1062,73 +1052,81 @@ send_disconnect (struct NeighbourMapEntry *n)
1062 * @param n neighbour to disconnect from 1052 * @param n neighbour to disconnect from
1063 */ 1053 */
1064static void 1054static void
1065disconnect_neighbour (struct NeighbourMapEntry *n) 1055disconnect_neighbour(struct NeighbourMapEntry *n)
1066{ 1056{
1067 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1057 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1068 "Disconnecting from peer %s in state %s\n", 1058 "Disconnecting from peer %s in state %s\n",
1069 GNUNET_i2s (&n->id), 1059 GNUNET_i2s(&n->id),
1070 GNUNET_TRANSPORT_ps2s (n->state)); 1060 GNUNET_TRANSPORT_ps2s(n->state));
1071 /* depending on state, notify neighbour and/or upper layers of this peer 1061 /* depending on state, notify neighbour and/or upper layers of this peer
1072 about disconnect */ 1062 about disconnect */
1073 switch (n->state) 1063 switch (n->state)
1074 { 1064 {
1075 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 1065 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
1076 case GNUNET_TRANSPORT_PS_INIT_ATS: 1066 case GNUNET_TRANSPORT_PS_INIT_ATS:
1077 /* other peer is completely unaware of us, no need to send DISCONNECT */ 1067 /* other peer is completely unaware of us, no need to send DISCONNECT */
1078 free_neighbour (n); 1068 free_neighbour(n);
1079 return; 1069 return;
1080 case GNUNET_TRANSPORT_PS_SYN_SENT: 1070
1081 send_disconnect (n); 1071 case GNUNET_TRANSPORT_PS_SYN_SENT:
1082 set_state_and_timeout (n, 1072 send_disconnect(n);
1083 GNUNET_TRANSPORT_PS_DISCONNECT, 1073 set_state_and_timeout(n,
1084 GNUNET_TIME_UNIT_FOREVER_ABS); 1074 GNUNET_TRANSPORT_PS_DISCONNECT,
1085 break; 1075 GNUNET_TIME_UNIT_FOREVER_ABS);
1086 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 1076 break;
1087 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */ 1077
1088 free_neighbour (n); 1078 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
1089 return; 1079 /* we never ACK'ed the other peer's request, no need to send DISCONNECT */
1090 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 1080 free_neighbour(n);
1091 /* we DID ACK the other peer's request, must send DISCONNECT */ 1081 return;
1092 send_disconnect (n); 1082
1093 set_state_and_timeout (n, 1083 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
1094 GNUNET_TRANSPORT_PS_DISCONNECT, 1084 /* we DID ACK the other peer's request, must send DISCONNECT */
1095 GNUNET_TIME_UNIT_FOREVER_ABS); 1085 send_disconnect(n);
1096 break; 1086 set_state_and_timeout(n,
1097 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1087 GNUNET_TRANSPORT_PS_DISCONNECT,
1098 case GNUNET_TRANSPORT_PS_CONNECTED: 1088 GNUNET_TIME_UNIT_FOREVER_ABS);
1099 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1089 break;
1100 /* we are currently connected, need to send disconnect and do 1090
1101 internal notifications and update statistics */ 1091 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1102 send_disconnect (n); 1092 case GNUNET_TRANSPORT_PS_CONNECTED:
1103 set_state_and_timeout (n, 1093 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1104 GNUNET_TRANSPORT_PS_DISCONNECT, 1094 /* we are currently connected, need to send disconnect and do
1105 GNUNET_TIME_UNIT_FOREVER_ABS); 1095 internal notifications and update statistics */
1106 break; 1096 send_disconnect(n);
1107 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 1097 set_state_and_timeout(n,
1108 /* Disconnecting while waiting for an ATS address to reconnect, 1098 GNUNET_TRANSPORT_PS_DISCONNECT,
1109 * cannot send DISCONNECT */ 1099 GNUNET_TIME_UNIT_FOREVER_ABS);
1110 free_neighbour (n); 1100 break;
1111 return; 1101
1112 case GNUNET_TRANSPORT_PS_DISCONNECT: 1102 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
1113 /* already disconnected, ignore */ 1103 /* Disconnecting while waiting for an ATS address to reconnect,
1114 break; 1104 * cannot send DISCONNECT */
1115 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 1105 free_neighbour(n);
1116 /* already cleaned up, how did we get here!? */ 1106 return;
1117 GNUNET_assert (0); 1107
1118 break; 1108 case GNUNET_TRANSPORT_PS_DISCONNECT:
1119 default: 1109 /* already disconnected, ignore */
1120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1110 break;
1121 "Unhandled state `%s'\n", 1111
1122 GNUNET_TRANSPORT_ps2s (n->state)); 1112 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
1123 GNUNET_break (0); 1113 /* already cleaned up, how did we get here!? */
1124 break; 1114 GNUNET_assert(0);
1125 } 1115 break;
1116
1117 default:
1118 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1119 "Unhandled state `%s'\n",
1120 GNUNET_TRANSPORT_ps2s(n->state));
1121 GNUNET_break(0);
1122 break;
1123 }
1126 /* schedule timeout to clean up */ 1124 /* schedule timeout to clean up */
1127 if (NULL != n->task) 1125 if (NULL != n->task)
1128 GNUNET_SCHEDULER_cancel (n->task); 1126 GNUNET_SCHEDULER_cancel(n->task);
1129 n->task = GNUNET_SCHEDULER_add_delayed (DISCONNECT_SENT_TIMEOUT, 1127 n->task = GNUNET_SCHEDULER_add_delayed(DISCONNECT_SENT_TIMEOUT,
1130 &master_task, 1128 &master_task,
1131 n); 1129 n);
1132} 1130}
1133 1131
1134 1132
@@ -1143,39 +1141,39 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
1143 * @a n was freed 1141 * @a n was freed
1144 */ 1142 */
1145static int 1143static int
1146set_incoming_quota (struct NeighbourMapEntry *n, 1144set_incoming_quota(struct NeighbourMapEntry *n,
1147 struct GNUNET_BANDWIDTH_Value32NBO quota) 1145 struct GNUNET_BANDWIDTH_Value32NBO quota)
1148{ 1146{
1149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1147 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1150 "Setting inbound quota of %u Bps for peer `%s' to all clients\n", 1148 "Setting inbound quota of %u Bps for peer `%s' to all clients\n",
1151 ntohl (quota.value__), GNUNET_i2s (&n->id)); 1149 ntohl(quota.value__), GNUNET_i2s(&n->id));
1152 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, 1150 GNUNET_BANDWIDTH_tracker_update_quota(&n->in_tracker,
1153 quota); 1151 quota);
1154 if (0 != ntohl (quota.value__)) 1152 if (0 != ntohl(quota.value__))
1155 { 1153 {
1156 struct GNUNET_ATS_SessionQuotaMessage sqm; 1154 struct GNUNET_ATS_SessionQuotaMessage sqm;
1157 1155
1158 sqm.header.size = htons (sizeof (struct GNUNET_ATS_SessionQuotaMessage)); 1156 sqm.header.size = htons(sizeof(struct GNUNET_ATS_SessionQuotaMessage));
1159 sqm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA); 1157 sqm.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_QUOTA);
1160 sqm.quota = quota.value__; 1158 sqm.quota = quota.value__;
1161 if (NULL != n->primary_address.session) 1159 if (NULL != n->primary_address.session)
1162 (void) send_with_session (n, 1160 (void)send_with_session(n,
1163 &sqm, 1161 &sqm,
1164 sizeof (sqm), 1162 sizeof(sqm),
1165 UINT32_MAX - 1, 1163 UINT32_MAX - 1,
1166 GNUNET_TIME_UNIT_FOREVER_REL, 1164 GNUNET_TIME_UNIT_FOREVER_REL,
1167 GNUNET_NO, 1165 GNUNET_NO,
1168 NULL, NULL); 1166 NULL, NULL);
1169 return GNUNET_YES; 1167 return GNUNET_YES;
1170 } 1168 }
1171 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1169 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1172 "Disconnecting peer `%s' due to SET_QUOTA\n", 1170 "Disconnecting peer `%s' due to SET_QUOTA\n",
1173 GNUNET_i2s (&n->id)); 1171 GNUNET_i2s(&n->id));
1174 if (GNUNET_YES == test_connected (n)) 1172 if (GNUNET_YES == test_connected(n))
1175 GNUNET_STATISTICS_update (GST_stats, 1173 GNUNET_STATISTICS_update(GST_stats,
1176 gettext_noop ("# disconnects due to quota of 0"), 1174 gettext_noop("# disconnects due to quota of 0"),
1177 1, GNUNET_NO); 1175 1, GNUNET_NO);
1178 disconnect_neighbour (n); 1176 disconnect_neighbour(n);
1179 return GNUNET_NO; 1177 return GNUNET_NO;
1180} 1178}
1181 1179
@@ -1192,78 +1190,78 @@ set_incoming_quota (struct NeighbourMapEntry *n,
1192 * @param bandwidth_out outbound quota to be used when connection is up 1190 * @param bandwidth_out outbound quota to be used when connection is up
1193 */ 1191 */
1194static void 1192static void
1195set_primary_address (struct NeighbourMapEntry *n, 1193set_primary_address(struct NeighbourMapEntry *n,
1196 const struct GNUNET_HELLO_Address *address, 1194 const struct GNUNET_HELLO_Address *address,
1197 struct GNUNET_ATS_Session *session, 1195 struct GNUNET_ATS_Session *session,
1198 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 1196 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
1199 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 1197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
1200{ 1198{
1201 if (session == n->primary_address.session) 1199 if (session == n->primary_address.session)
1202 {
1203 GST_validation_set_address_use (n->primary_address.address,
1204 GNUNET_YES);
1205 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
1206 { 1200 {
1207 n->primary_address.bandwidth_in = bandwidth_in; 1201 GST_validation_set_address_use(n->primary_address.address,
1208 if (GNUNET_YES != 1202 GNUNET_YES);
1209 set_incoming_quota (n, 1203 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
1210 bandwidth_in)) 1204 {
1211 return; 1205 n->primary_address.bandwidth_in = bandwidth_in;
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;
1212 } 1217 }
1213 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 1218 if ((NULL != n->primary_address.address) &&
1219 (0 == GNUNET_HELLO_address_cmp(address,
1220 n->primary_address.address)))
1214 { 1221 {
1215 n->primary_address.bandwidth_out = bandwidth_out; 1222 GNUNET_break(0);
1216 send_outbound_quota_to_clients (n); 1223 return;
1217 } 1224 }
1218 return;
1219 }
1220 if ( (NULL != n->primary_address.address) &&
1221 (0 == GNUNET_HELLO_address_cmp (address,
1222 n->primary_address.address)) )
1223 {
1224 GNUNET_break (0);
1225 return;
1226 }
1227 if (NULL == session) 1225 if (NULL == session)
1228 { 1226 {
1229 GNUNET_break (0); 1227 GNUNET_break(0);
1230 GST_ats_block_address (address, 1228 GST_ats_block_address(address,
1231 session); 1229 session);
1232 return; 1230 return;
1233 } 1231 }
1234 if (NULL != n->primary_address.address) 1232 if (NULL != n->primary_address.address)
1235 { 1233 {
1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1234 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1237 "Replacing existing primary address with another one\n"); 1235 "Replacing existing primary address with another one\n");
1238 free_address (&n->primary_address); 1236 free_address(&n->primary_address);
1239 } 1237 }
1240 n->primary_address.address = GNUNET_HELLO_address_copy (address); 1238 n->primary_address.address = GNUNET_HELLO_address_copy(address);
1241 n->primary_address.bandwidth_in = bandwidth_in; 1239 n->primary_address.bandwidth_in = bandwidth_in;
1242 n->primary_address.bandwidth_out = bandwidth_out; 1240 n->primary_address.bandwidth_out = bandwidth_out;
1243 n->primary_address.session = session; 1241 n->primary_address.session = session;
1244 n->primary_address.keep_alive_nonce = 0; 1242 n->primary_address.keep_alive_nonce = 0;
1245 GNUNET_assert (GNUNET_YES == 1243 GNUNET_assert(GNUNET_YES ==
1246 GST_ats_is_known (n->primary_address.address, 1244 GST_ats_is_known(n->primary_address.address,
1247 n->primary_address.session)); 1245 n->primary_address.session));
1248 /* subsystems about address use */ 1246 /* subsystems about address use */
1249 GST_validation_set_address_use (n->primary_address.address, 1247 GST_validation_set_address_use(n->primary_address.address,
1250 GNUNET_YES); 1248 GNUNET_YES);
1251 if (GNUNET_YES != 1249 if (GNUNET_YES !=
1252 set_incoming_quota (n, 1250 set_incoming_quota(n,
1253 bandwidth_in)) 1251 bandwidth_in))
1254 return; 1252 return;
1255 send_outbound_quota_to_clients (n); 1253 send_outbound_quota_to_clients(n);
1256 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1254 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1257 "Neighbour `%s' switched to address `%s'\n", 1255 "Neighbour `%s' switched to address `%s'\n",
1258 GNUNET_i2s (&n->id), 1256 GNUNET_i2s(&n->id),
1259 GST_plugins_a2s(address)); 1257 GST_plugins_a2s(address));
1260 1258
1261 neighbours_changed_notification (&n->id, 1259 neighbours_changed_notification(&n->id,
1262 n->primary_address.address, 1260 n->primary_address.address,
1263 n->state, 1261 n->state,
1264 n->timeout, 1262 n->timeout,
1265 n->primary_address.bandwidth_in, 1263 n->primary_address.bandwidth_in,
1266 n->primary_address.bandwidth_out); 1264 n->primary_address.bandwidth_out);
1267} 1265}
1268 1266
1269 1267
@@ -1277,75 +1275,75 @@ set_primary_address (struct NeighbourMapEntry *n,
1277 * @param physical bytes sent on wire 1275 * @param physical bytes sent on wire
1278 */ 1276 */
1279static void 1277static void
1280transmit_send_continuation (void *cls, 1278transmit_send_continuation(void *cls,
1281 const struct GNUNET_PeerIdentity *receiver, 1279 const struct GNUNET_PeerIdentity *receiver,
1282 int success, 1280 int success,
1283 size_t size_payload, 1281 size_t size_payload,
1284 size_t physical) 1282 size_t physical)
1285{ 1283{
1286 struct MessageQueue *mq = cls; 1284 struct MessageQueue *mq = cls;
1287 struct NeighbourMapEntry *n; 1285 struct NeighbourMapEntry *n;
1288 1286
1289 if (NULL == (n = lookup_neighbour (receiver))) 1287 if (NULL == (n = lookup_neighbour(receiver)))
1290 { 1288 {
1291 if (NULL != mq->cont) 1289 if (NULL != mq->cont)
1292 mq->cont (mq->cont_cls, 1290 mq->cont(mq->cont_cls,
1293 GNUNET_SYSERR /* not connected */, 1291 GNUNET_SYSERR /* not connected */,
1294 size_payload, 1292 size_payload,
1295 0); 1293 0);
1296 GNUNET_free (mq); 1294 GNUNET_free(mq);
1297 return; /* disconnect or other error while transmitting, can happen */ 1295 return; /* disconnect or other error while transmitting, can happen */
1298 } 1296 }
1299 if (n->is_active == mq) 1297 if (n->is_active == mq)
1300 { 1298 {
1301 /* this is still "our" neighbour, remove us from its queue 1299 /* this is still "our" neighbour, remove us from its queue
1302 and allow it to send the next message now */ 1300 and allow it to send the next message now */
1303 n->is_active = NULL; 1301 n->is_active = NULL;
1304 if (NULL != n->task) 1302 if (NULL != n->task)
1305 GNUNET_SCHEDULER_cancel (n->task); 1303 GNUNET_SCHEDULER_cancel(n->task);
1306 n->task = GNUNET_SCHEDULER_add_now (&master_task, 1304 n->task = GNUNET_SCHEDULER_add_now(&master_task,
1307 n); 1305 n);
1308 } 1306 }
1309 if (bytes_in_send_queue < mq->message_buf_size) 1307 if (bytes_in_send_queue < mq->message_buf_size)
1310 { 1308 {
1311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1309 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1312 "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n", 1310 "Bytes_in_send_queue `%llu', Message_size %u, result: %s, payload %u, on wire %u\n",
1313 bytes_in_send_queue, 1311 bytes_in_send_queue,
1314 (unsigned int) mq->message_buf_size, 1312 (unsigned int)mq->message_buf_size,
1315 (GNUNET_OK == success) ? "OK" : "FAIL", 1313 (GNUNET_OK == success) ? "OK" : "FAIL",
1316 (unsigned int) size_payload, 1314 (unsigned int)size_payload,
1317 (unsigned int) physical); 1315 (unsigned int)physical);
1318 GNUNET_break (0); 1316 GNUNET_break(0);
1319 } 1317 }
1320 1318
1321 GNUNET_break (size_payload == mq->message_buf_size); 1319 GNUNET_break(size_payload == mq->message_buf_size);
1322 bytes_in_send_queue -= mq->message_buf_size; 1320 bytes_in_send_queue -= mq->message_buf_size;
1323 GNUNET_STATISTICS_set (GST_stats, 1321 GNUNET_STATISTICS_set(GST_stats,
1324 gettext_noop ("# bytes in message queue for other peers"), 1322 gettext_noop("# bytes in message queue for other peers"),
1325 bytes_in_send_queue, 1323 bytes_in_send_queue,
1326 GNUNET_NO); 1324 GNUNET_NO);
1327 if (GNUNET_OK == success) 1325 if (GNUNET_OK == success)
1328 GNUNET_STATISTICS_update (GST_stats, 1326 GNUNET_STATISTICS_update(GST_stats,
1329 gettext_noop ("# messages transmitted to other peers"), 1327 gettext_noop("# messages transmitted to other peers"),
1330 1, 1328 1,
1331 GNUNET_NO); 1329 GNUNET_NO);
1332 else 1330 else
1333 GNUNET_STATISTICS_update (GST_stats, 1331 GNUNET_STATISTICS_update(GST_stats,
1334 gettext_noop 1332 gettext_noop
1335 ("# transmission failures for messages to other peers"), 1333 ("# transmission failures for messages to other peers"),
1336 1, GNUNET_NO); 1334 1, GNUNET_NO);
1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1335 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1338 "Sending message to `%s' of type %u with %u bytes was a %s\n", 1336 "Sending message to `%s' of type %u with %u bytes was a %s\n",
1339 GNUNET_i2s (receiver), 1337 GNUNET_i2s(receiver),
1340 ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type), 1338 ntohs(((struct GNUNET_MessageHeader *)mq->message_buf)->type),
1341 (unsigned int) mq->message_buf_size, 1339 (unsigned int)mq->message_buf_size,
1342 (success == GNUNET_OK) ? "success" : "FAILURE"); 1340 (success == GNUNET_OK) ? "success" : "FAILURE");
1343 if (NULL != mq->cont) 1341 if (NULL != mq->cont)
1344 mq->cont (mq->cont_cls, 1342 mq->cont(mq->cont_cls,
1345 success, 1343 success,
1346 size_payload, 1344 size_payload,
1347 physical); 1345 physical);
1348 GNUNET_free (mq); 1346 GNUNET_free(mq);
1349} 1347}
1350 1348
1351 1349
@@ -1361,77 +1359,77 @@ transmit_send_continuation (void *cls,
1361 * @param n target peer for which to transmit 1359 * @param n target peer for which to transmit
1362 */ 1360 */
1363static void 1361static void
1364try_transmission_to_peer (struct NeighbourMapEntry *n) 1362try_transmission_to_peer(struct NeighbourMapEntry *n)
1365{ 1363{
1366 struct MessageQueue *mq; 1364 struct MessageQueue *mq;
1367 struct GNUNET_TIME_Relative timeout; 1365 struct GNUNET_TIME_Relative timeout;
1368 1366
1369 if (NULL == n->primary_address.address) 1367 if (NULL == n->primary_address.address)
1370 { 1368 {
1371 /* no address, why are we here? */ 1369 /* no address, why are we here? */
1372 GNUNET_break (0); 1370 GNUNET_break(0);
1373 return; 1371 return;
1374 } 1372 }
1375 if ((0 == n->primary_address.address->address_length) && 1373 if ((0 == n->primary_address.address->address_length) &&
1376 (NULL == n->primary_address.session)) 1374 (NULL == n->primary_address.session))
1377 { 1375 {
1378 /* no address, why are we here? */ 1376 /* no address, why are we here? */
1379 GNUNET_break (0); 1377 GNUNET_break(0);
1380 return; 1378 return;
1381 } 1379 }
1382 if (NULL != n->is_active) 1380 if (NULL != n->is_active)
1383 { 1381 {
1384 /* transmission already pending */ 1382 /* transmission already pending */
1385 return; 1383 return;
1386 } 1384 }
1387 1385
1388 /* timeout messages from the queue that are past their due date */ 1386 /* timeout messages from the queue that are past their due date */
1389 while (NULL != (mq = n->messages_head)) 1387 while (NULL != (mq = n->messages_head))
1390 { 1388 {
1391 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout); 1389 timeout = GNUNET_TIME_absolute_get_remaining(mq->timeout);
1392 if (timeout.rel_value_us > 0) 1390 if (timeout.rel_value_us > 0)
1393 break; 1391 break;
1394 GNUNET_STATISTICS_update (GST_stats, 1392 GNUNET_STATISTICS_update(GST_stats,
1395 gettext_noop ("# messages timed out while in transport queue"), 1393 gettext_noop("# messages timed out while in transport queue"),
1396 1, 1394 1,
1397 GNUNET_NO); 1395 GNUNET_NO);
1398 GNUNET_CONTAINER_DLL_remove (n->messages_head, 1396 GNUNET_CONTAINER_DLL_remove(n->messages_head,
1399 n->messages_tail, 1397 n->messages_tail,
1400 mq); 1398 mq);
1401 n->is_active = mq; 1399 n->is_active = mq;
1402 transmit_send_continuation (mq, 1400 transmit_send_continuation(mq,
1403 &n->id, 1401 &n->id,
1404 GNUNET_SYSERR, 1402 GNUNET_SYSERR,
1405 mq->message_buf_size, 1403 mq->message_buf_size,
1406 0); /* timeout */ 1404 0); /* timeout */
1407 } 1405 }
1408 if (NULL == mq) 1406 if (NULL == mq)
1409 return; /* no more messages */ 1407 return; /* no more messages */
1410 if (NULL == n->primary_address.address) 1408 if (NULL == n->primary_address.address)
1411 { 1409 {
1412 /* transmit_send_continuation() caused us to drop session, 1410 /* transmit_send_continuation() caused us to drop session,
1413 can't try transmission anymore. */ 1411 can't try transmission anymore. */
1414 return; 1412 return;
1415 } 1413 }
1416 1414
1417 1415
1418 GNUNET_CONTAINER_DLL_remove (n->messages_head, 1416 GNUNET_CONTAINER_DLL_remove(n->messages_head,
1419 n->messages_tail, 1417 n->messages_tail,
1420 mq); 1418 mq);
1421 n->is_active = mq; 1419 n->is_active = mq;
1422 1420
1423 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1424 "Giving message with %u bytes to plugin session %p\n", 1422 "Giving message with %u bytes to plugin session %p\n",
1425 (unsigned int) mq->message_buf_size, 1423 (unsigned int)mq->message_buf_size,
1426 n->primary_address.session); 1424 n->primary_address.session);
1427 (void) send_with_session (n, 1425 (void)send_with_session(n,
1428 mq->message_buf, 1426 mq->message_buf,
1429 mq->message_buf_size, 1427 mq->message_buf_size,
1430 0 /* priority */, 1428 0 /* priority */,
1431 timeout, 1429 timeout,
1432 GNUNET_NO, 1430 GNUNET_NO,
1433 &transmit_send_continuation, 1431 &transmit_send_continuation,
1434 mq); 1432 mq);
1435} 1433}
1436 1434
1437 1435
@@ -1444,45 +1442,45 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1444 * @param n neighbour that went idle and needs a keepalive 1442 * @param n neighbour that went idle and needs a keepalive
1445 */ 1443 */
1446static void 1444static void
1447send_keepalive (struct NeighbourMapEntry *n) 1445send_keepalive(struct NeighbourMapEntry *n)
1448{ 1446{
1449 struct GNUNET_ATS_SessionKeepAliveMessage m; 1447 struct GNUNET_ATS_SessionKeepAliveMessage m;
1450 struct GNUNET_TIME_Relative timeout; 1448 struct GNUNET_TIME_Relative timeout;
1451 uint32_t nonce; 1449 uint32_t nonce;
1452 1450
1453 GNUNET_assert ((GNUNET_TRANSPORT_PS_CONNECTED == n->state) || 1451 GNUNET_assert((GNUNET_TRANSPORT_PS_CONNECTED == n->state) ||
1454 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)); 1452 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state));
1455 if (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time).rel_value_us > 0) 1453 if (GNUNET_TIME_absolute_get_remaining(n->keep_alive_time).rel_value_us > 0)
1456 return; /* no keepalive needed at this time */ 1454 return; /* no keepalive needed at this time */
1457 1455
1458 nonce = 0; /* 0 indicates 'not set' */ 1456 nonce = 0; /* 0 indicates 'not set' */
1459 while (0 == nonce) 1457 while (0 == nonce)
1460 nonce = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1458 nonce = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE,
1461 UINT32_MAX); 1459 UINT32_MAX);
1462 1460
1463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1461 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1464 "Sending KEEPALIVE to peer `%s' with nonce %u\n", 1462 "Sending KEEPALIVE to peer `%s' with nonce %u\n",
1465 GNUNET_i2s (&n->id), 1463 GNUNET_i2s(&n->id),
1466 nonce); 1464 nonce);
1467 m.header.size = htons (sizeof (struct GNUNET_ATS_SessionKeepAliveMessage)); 1465 m.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1468 m.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE); 1466 m.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE);
1469 m.nonce = htonl (nonce); 1467 m.nonce = htonl(nonce);
1470 1468
1471 timeout = send_with_session (n, 1469 timeout = send_with_session(n,
1472 &m, 1470 &m,
1473 sizeof (m), 1471 sizeof(m),
1474 UINT32_MAX /* priority */, 1472 UINT32_MAX /* priority */,
1475 GNUNET_TIME_UNIT_FOREVER_REL, 1473 GNUNET_TIME_UNIT_FOREVER_REL,
1476 GNUNET_YES, 1474 GNUNET_YES,
1477 NULL, NULL); 1475 NULL, NULL);
1478 GNUNET_STATISTICS_update (GST_stats, 1476 GNUNET_STATISTICS_update(GST_stats,
1479 gettext_noop ("# KEEPALIVES sent"), 1477 gettext_noop("# KEEPALIVES sent"),
1480 1, 1478 1,
1481 GNUNET_NO); 1479 GNUNET_NO);
1482 n->primary_address.keep_alive_nonce = nonce; 1480 n->primary_address.keep_alive_nonce = nonce;
1483 n->expect_latency_response = GNUNET_YES; 1481 n->expect_latency_response = GNUNET_YES;
1484 n->last_keep_alive_time = GNUNET_TIME_absolute_get (); 1482 n->last_keep_alive_time = GNUNET_TIME_absolute_get();
1485 n->keep_alive_time = GNUNET_TIME_relative_to_absolute (timeout); 1483 n->keep_alive_time = GNUNET_TIME_relative_to_absolute(timeout);
1486} 1484}
1487 1485
1488 1486
@@ -1494,57 +1492,57 @@ send_keepalive (struct NeighbourMapEntry *n)
1494 * @param m the keep alive message containing the nonce to respond to 1492 * @param m the keep alive message containing the nonce to respond to
1495 */ 1493 */
1496void 1494void
1497GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour, 1495GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour,
1498 const struct GNUNET_MessageHeader *m) 1496 const struct GNUNET_MessageHeader *m)
1499{ 1497{
1500 struct NeighbourMapEntry *n; 1498 struct NeighbourMapEntry *n;
1501 const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in; 1499 const struct GNUNET_ATS_SessionKeepAliveMessage *msg_in;
1502 struct GNUNET_ATS_SessionKeepAliveMessage msg; 1500 struct GNUNET_ATS_SessionKeepAliveMessage msg;
1503 1501
1504 if (sizeof (struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size)) 1502 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size))
1505 { 1503 {
1506 GNUNET_break_op (0); 1504 GNUNET_break_op(0);
1507 return; 1505 return;
1508 } 1506 }
1509 1507
1510 msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m; 1508 msg_in = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m;
1511 if (NULL == (n = lookup_neighbour (neighbour))) 1509 if (NULL == (n = lookup_neighbour(neighbour)))
1512 { 1510 {
1513 GNUNET_STATISTICS_update (GST_stats, 1511 GNUNET_STATISTICS_update(GST_stats,
1514 gettext_noop 1512 gettext_noop
1515 ("# KEEPALIVE messages discarded (peer unknown)"), 1513 ("# KEEPALIVE messages discarded (peer unknown)"),
1516 1, GNUNET_NO); 1514 1, GNUNET_NO);
1517 return; 1515 return;
1518 } 1516 }
1519 if (NULL == n->primary_address.session) 1517 if (NULL == n->primary_address.session)
1520 { 1518 {
1521 GNUNET_STATISTICS_update (GST_stats, 1519 GNUNET_STATISTICS_update(GST_stats,
1522 gettext_noop 1520 gettext_noop
1523 ("# KEEPALIVE messages discarded (no session)"), 1521 ("# KEEPALIVE messages discarded (no session)"),
1524 1, GNUNET_NO); 1522 1, GNUNET_NO);
1525 return; 1523 return;
1526 } 1524 }
1527 1525
1528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1526 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1529 "Received KEEPALIVE request from peer `%s' with nonce %u\n", 1527 "Received KEEPALIVE request from peer `%s' with nonce %u\n",
1530 GNUNET_i2s (&n->id), 1528 GNUNET_i2s(&n->id),
1531 ntohl (msg_in->nonce)); 1529 ntohl(msg_in->nonce));
1532 GNUNET_STATISTICS_update (GST_stats, 1530 GNUNET_STATISTICS_update(GST_stats,
1533 gettext_noop ("# KEEPALIVES received in good order"), 1531 gettext_noop("# KEEPALIVES received in good order"),
1534 1, 1532 1,
1535 GNUNET_NO); 1533 GNUNET_NO);
1536 1534
1537 /* send reply to allow neighbour to measure latency */ 1535 /* send reply to allow neighbour to measure latency */
1538 msg.header.size = htons (sizeof (struct GNUNET_ATS_SessionKeepAliveMessage)); 1536 msg.header.size = htons(sizeof(struct GNUNET_ATS_SessionKeepAliveMessage));
1539 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE); 1537 msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE_RESPONSE);
1540 msg.nonce = msg_in->nonce; 1538 msg.nonce = msg_in->nonce;
1541 (void) send_with_session (n, 1539 (void)send_with_session(n,
1542 &msg, 1540 &msg,
1543 sizeof (struct GNUNET_ATS_SessionKeepAliveMessage), 1541 sizeof(struct GNUNET_ATS_SessionKeepAliveMessage),
1544 UINT32_MAX /* priority */, 1542 UINT32_MAX /* priority */,
1545 GNUNET_TIME_UNIT_FOREVER_REL, 1543 GNUNET_TIME_UNIT_FOREVER_REL,
1546 GNUNET_YES, 1544 GNUNET_YES,
1547 NULL, NULL); 1545 NULL, NULL);
1548} 1546}
1549 1547
1550 1548
@@ -1557,97 +1555,97 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
1557 * @param m the message containing the keep alive response 1555 * @param m the message containing the keep alive response
1558 */ 1556 */
1559void 1557void
1560GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, 1558GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour,
1561 const struct GNUNET_MessageHeader *m) 1559 const struct GNUNET_MessageHeader *m)
1562{ 1560{
1563 struct NeighbourMapEntry *n; 1561 struct NeighbourMapEntry *n;
1564 const struct GNUNET_ATS_SessionKeepAliveMessage *msg; 1562 const struct GNUNET_ATS_SessionKeepAliveMessage *msg;
1565 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1563 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1566 struct GNUNET_TIME_Relative latency; 1564 struct GNUNET_TIME_Relative latency;
1567 1565
1568 if (sizeof (struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs (m->size)) 1566 if (sizeof(struct GNUNET_ATS_SessionKeepAliveMessage) != ntohs(m->size))
1569 { 1567 {
1570 GNUNET_break_op (0); 1568 GNUNET_break_op(0);
1571 return; 1569 return;
1572 } 1570 }
1573 1571
1574 msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *) m; 1572 msg = (const struct GNUNET_ATS_SessionKeepAliveMessage *)m;
1575 if (NULL == (n = lookup_neighbour (neighbour))) 1573 if (NULL == (n = lookup_neighbour(neighbour)))
1576 { 1574 {
1577 GNUNET_STATISTICS_update (GST_stats, 1575 GNUNET_STATISTICS_update(GST_stats,
1578 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (not connected)"), 1576 gettext_noop("# KEEPALIVE_RESPONSEs discarded (not connected)"),
1579 1, 1577 1,
1580 GNUNET_NO); 1578 GNUNET_NO);
1581 return; 1579 return;
1582 } 1580 }
1583 if ( (GNUNET_TRANSPORT_PS_CONNECTED != n->state) || 1581 if ((GNUNET_TRANSPORT_PS_CONNECTED != n->state) ||
1584 (GNUNET_YES != n->expect_latency_response) ) 1582 (GNUNET_YES != n->expect_latency_response))
1585 { 1583 {
1586 GNUNET_STATISTICS_update (GST_stats, 1584 GNUNET_STATISTICS_update(GST_stats,
1587 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (not expected)"), 1585 gettext_noop("# KEEPALIVE_RESPONSEs discarded (not expected)"),
1588 1, 1586 1,
1589 GNUNET_NO); 1587 GNUNET_NO);
1590 return; 1588 return;
1591 } 1589 }
1592 if (NULL == n->primary_address.address) 1590 if (NULL == n->primary_address.address)
1593 { 1591 {
1594 GNUNET_STATISTICS_update (GST_stats, 1592 GNUNET_STATISTICS_update(GST_stats,
1595 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (address changed)"), 1593 gettext_noop("# KEEPALIVE_RESPONSEs discarded (address changed)"),
1596 1, 1594 1,
1597 GNUNET_NO); 1595 GNUNET_NO);
1598 return; 1596 return;
1599 } 1597 }
1600 if (n->primary_address.keep_alive_nonce != ntohl (msg->nonce)) 1598 if (n->primary_address.keep_alive_nonce != ntohl(msg->nonce))
1601 { 1599 {
1602 if (0 == n->primary_address.keep_alive_nonce) 1600 if (0 == n->primary_address.keep_alive_nonce)
1603 GNUNET_STATISTICS_update (GST_stats, 1601 GNUNET_STATISTICS_update(GST_stats,
1604 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (no nonce)"), 1602 gettext_noop("# KEEPALIVE_RESPONSEs discarded (no nonce)"),
1605 1, 1603 1,
1606 GNUNET_NO); 1604 GNUNET_NO);
1607 else 1605 else
1608 GNUNET_STATISTICS_update (GST_stats, 1606 GNUNET_STATISTICS_update(GST_stats,
1609 gettext_noop ("# KEEPALIVE_RESPONSEs discarded (bad nonce)"), 1607 gettext_noop("# KEEPALIVE_RESPONSEs discarded (bad nonce)"),
1610 1, 1608 1,
1611 GNUNET_NO); 1609 GNUNET_NO);
1612 return; 1610 return;
1613 } 1611 }
1614 GNUNET_STATISTICS_update (GST_stats, 1612 GNUNET_STATISTICS_update(GST_stats,
1615 gettext_noop ("# KEEPALIVE_RESPONSEs received (OK)"), 1613 gettext_noop("# KEEPALIVE_RESPONSEs received (OK)"),
1616 1, 1614 1,
1617 GNUNET_NO); 1615 GNUNET_NO);
1618 1616
1619 1617
1620 /* Update session timeout here */ 1618 /* Update session timeout here */
1621 if (NULL != (papi = GST_plugins_find (n->primary_address.address->transport_name))) 1619 if (NULL != (papi = GST_plugins_find(n->primary_address.address->transport_name)))
1622 { 1620 {
1623 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1621 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1624 "Updating session for peer `%s' for session %p\n", 1622 "Updating session for peer `%s' for session %p\n",
1625 GNUNET_i2s (&n->id), 1623 GNUNET_i2s(&n->id),
1626 n->primary_address.session); 1624 n->primary_address.session);
1627 papi->update_session_timeout (papi->cls, 1625 papi->update_session_timeout(papi->cls,
1628 &n->id, 1626 &n->id,
1629 n->primary_address.session); 1627 n->primary_address.session);
1630 } 1628 }
1631 else 1629 else
1632 { 1630 {
1633 GNUNET_break (0); 1631 GNUNET_break(0);
1634 } 1632 }
1635 1633
1636 n->primary_address.keep_alive_nonce = 0; 1634 n->primary_address.keep_alive_nonce = 0;
1637 n->expect_latency_response = GNUNET_NO; 1635 n->expect_latency_response = GNUNET_NO;
1638 set_state_and_timeout (n, 1636 set_state_and_timeout(n,
1639 n->state, 1637 n->state,
1640 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 1638 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
1641 1639
1642 latency = GNUNET_TIME_absolute_get_duration (n->last_keep_alive_time); 1640 latency = GNUNET_TIME_absolute_get_duration(n->last_keep_alive_time);
1643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1644 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n", 1642 "Received KEEPALIVE_RESPONSE from peer `%s', latency is %s\n",
1645 GNUNET_i2s (&n->id), 1643 GNUNET_i2s(&n->id),
1646 GNUNET_STRINGS_relative_time_to_string (latency, 1644 GNUNET_STRINGS_relative_time_to_string(latency,
1647 GNUNET_YES)); 1645 GNUNET_YES));
1648 GST_ats_update_delay (n->primary_address.address, 1646 GST_ats_update_delay(n->primary_address.address,
1649 GNUNET_TIME_relative_divide (latency, 1647 GNUNET_TIME_relative_divide(latency,
1650 2)); 1648 2));
1651} 1649}
1652 1650
1653 1651
@@ -1664,74 +1662,74 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
1664 * @return how long to wait before reading more from this sender 1662 * @return how long to wait before reading more from this sender
1665 */ 1663 */
1666struct GNUNET_TIME_Relative 1664struct GNUNET_TIME_Relative
1667GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender, 1665GST_neighbours_calculate_receive_delay(const struct GNUNET_PeerIdentity *sender,
1668 ssize_t size, 1666 ssize_t size,
1669 int *do_forward) 1667 int *do_forward)
1670{ 1668{
1671 struct NeighbourMapEntry *n; 1669 struct NeighbourMapEntry *n;
1672 struct GNUNET_TIME_Relative ret; 1670 struct GNUNET_TIME_Relative ret;
1673 1671
1674 if (NULL == neighbours) 1672 if (NULL == neighbours)
1675 { 1673 {
1676 *do_forward = GNUNET_NO; 1674 *do_forward = GNUNET_NO;
1677 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */ 1675 return GNUNET_TIME_UNIT_FOREVER_REL; /* This can happen during shutdown */
1678 } 1676 }
1679 if (NULL == (n = lookup_neighbour (sender))) 1677 if (NULL == (n = lookup_neighbour(sender)))
1680 { 1678 {
1681 GNUNET_STATISTICS_update (GST_stats, 1679 GNUNET_STATISTICS_update(GST_stats,
1682 gettext_noop ("# messages discarded due to lack of neighbour record"), 1680 gettext_noop("# messages discarded due to lack of neighbour record"),
1683 1, 1681 1,
1684 GNUNET_NO); 1682 GNUNET_NO);
1685 *do_forward = GNUNET_NO; 1683 *do_forward = GNUNET_NO;
1686 return GNUNET_TIME_UNIT_ZERO; 1684 return GNUNET_TIME_UNIT_ZERO;
1687 } 1685 }
1688 if (! test_connected (n)) 1686 if (!test_connected(n))
1689 { 1687 {
1690 *do_forward = GNUNET_SYSERR; 1688 *do_forward = GNUNET_SYSERR;
1691 return GNUNET_TIME_UNIT_ZERO; 1689 return GNUNET_TIME_UNIT_ZERO;
1692 } 1690 }
1693 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size)) 1691 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, size))
1694 { 1692 {
1695 n->quota_violation_count++; 1693 n->quota_violation_count++;
1696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1694 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1697 "Bandwidth quota (%u b/s) violation detected (total of %u).\n", 1695 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
1698 n->in_tracker.available_bytes_per_s__, 1696 n->in_tracker.available_bytes_per_s__,
1699 n->quota_violation_count); 1697 n->quota_violation_count);
1700 /* Discount 32k per violation */ 1698 /* Discount 32k per violation */
1701 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024); 1699 GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, -32 * 1024);
1702 } 1700 }
1703 else 1701 else
1704 {
1705 if (n->quota_violation_count > 0)
1706 { 1702 {
1707 /* try to add 32k back */ 1703 if (n->quota_violation_count > 0)
1708 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024); 1704 {
1709 n->quota_violation_count--; 1705 /* try to add 32k back */
1706 GNUNET_BANDWIDTH_tracker_consume(&n->in_tracker, 32 * 1024);
1707 n->quota_violation_count--;
1708 }
1710 } 1709 }
1711 }
1712 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 1710 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
1713 { 1711 {
1714 GNUNET_STATISTICS_update (GST_stats, 1712 GNUNET_STATISTICS_update(GST_stats,
1715 gettext_noop 1713 gettext_noop
1716 ("# bandwidth quota violations by other peers"), 1714 ("# bandwidth quota violations by other peers"),
1717 1, GNUNET_NO); 1715 1, GNUNET_NO);
1718 *do_forward = GNUNET_NO; 1716 *do_forward = GNUNET_NO;
1719 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; 1717 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
1720 } 1718 }
1721 *do_forward = GNUNET_YES; 1719 *do_forward = GNUNET_YES;
1722 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 32 * 1024); 1720 ret = GNUNET_BANDWIDTH_tracker_get_delay(&n->in_tracker, 32 * 1024);
1723 if (ret.rel_value_us > 0) 1721 if (ret.rel_value_us > 0)
1724 { 1722 {
1725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1723 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1726 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n", 1724 "Throttling read (%lld bytes excess at %u b/s), waiting %s before reading more.\n",
1727 (long long) n->in_tracker.consumption_since_last_update__, 1725 (long long)n->in_tracker.consumption_since_last_update__,
1728 (unsigned int) n->in_tracker.available_bytes_per_s__, 1726 (unsigned int)n->in_tracker.available_bytes_per_s__,
1729 GNUNET_STRINGS_relative_time_to_string (ret, GNUNET_YES)); 1727 GNUNET_STRINGS_relative_time_to_string(ret, GNUNET_YES));
1730 GNUNET_STATISTICS_update (GST_stats, 1728 GNUNET_STATISTICS_update(GST_stats,
1731 gettext_noop ("# ms throttling suggested"), 1729 gettext_noop("# ms throttling suggested"),
1732 (int64_t) ret.rel_value_us / 1000LL, 1730 (int64_t)ret.rel_value_us / 1000LL,
1733 GNUNET_NO); 1731 GNUNET_NO);
1734 } 1732 }
1735 return ret; 1733 return ret;
1736} 1734}
1737 1735
@@ -1747,61 +1745,61 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
1747 * @param cont_cls closure for @a cont 1745 * @param cont_cls closure for @a cont
1748 */ 1746 */
1749void 1747void
1750GST_neighbours_send (const struct GNUNET_PeerIdentity *target, 1748GST_neighbours_send(const struct GNUNET_PeerIdentity *target,
1751 const void *msg, 1749 const void *msg,
1752 size_t msg_size, 1750 size_t msg_size,
1753 struct GNUNET_TIME_Relative timeout, 1751 struct GNUNET_TIME_Relative timeout,
1754 GST_NeighbourSendContinuation cont, 1752 GST_NeighbourSendContinuation cont,
1755 void *cont_cls) 1753 void *cont_cls)
1756{ 1754{
1757 struct NeighbourMapEntry *n; 1755 struct NeighbourMapEntry *n;
1758 struct MessageQueue *mq; 1756 struct MessageQueue *mq;
1759 1757
1760 /* All ove these cases should never happen; they are all API violations. 1758 /* All ove these cases should never happen; they are all API violations.
1761 But we check anyway, just to be sure. */ 1759 But we check anyway, just to be sure. */
1762 if (NULL == (n = lookup_neighbour (target))) 1760 if (NULL == (n = lookup_neighbour(target)))
1763 { 1761 {
1764 GNUNET_break (0); 1762 GNUNET_break(0);
1765 if (NULL != cont) 1763 if (NULL != cont)
1766 cont (cont_cls, 1764 cont(cont_cls,
1767 GNUNET_SYSERR, 1765 GNUNET_SYSERR,
1768 msg_size, 1766 msg_size,
1769 0); 1767 0);
1770 return; 1768 return;
1771 } 1769 }
1772 if (GNUNET_YES != test_connected (n)) 1770 if (GNUNET_YES != test_connected(n))
1773 { 1771 {
1774 GNUNET_break (0); 1772 GNUNET_break(0);
1775 if (NULL != cont) 1773 if (NULL != cont)
1776 cont (cont_cls, 1774 cont(cont_cls,
1777 GNUNET_SYSERR, 1775 GNUNET_SYSERR,
1778 msg_size, 1776 msg_size,
1779 0); 1777 0);
1780 return; 1778 return;
1781 } 1779 }
1782 bytes_in_send_queue += msg_size; 1780 bytes_in_send_queue += msg_size;
1783 GNUNET_STATISTICS_set (GST_stats, 1781 GNUNET_STATISTICS_set(GST_stats,
1784 gettext_noop 1782 gettext_noop
1785 ("# bytes in message queue for other peers"), 1783 ("# bytes in message queue for other peers"),
1786 bytes_in_send_queue, GNUNET_NO); 1784 bytes_in_send_queue, GNUNET_NO);
1787 mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size); 1785 mq = GNUNET_malloc(sizeof(struct MessageQueue) + msg_size);
1788 mq->cont = cont; 1786 mq->cont = cont;
1789 mq->cont_cls = cont_cls; 1787 mq->cont_cls = cont_cls;
1790 GNUNET_memcpy (&mq[1], msg, msg_size); 1788 GNUNET_memcpy(&mq[1], msg, msg_size);
1791 mq->message_buf = (const char *) &mq[1]; 1789 mq->message_buf = (const char *)&mq[1];
1792 mq->message_buf_size = msg_size; 1790 mq->message_buf_size = msg_size;
1793 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1791 mq->timeout = GNUNET_TIME_relative_to_absolute(timeout);
1794 1792
1795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1793 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1796 "Enqueueing %u bytes to send to peer %s\n", 1794 "Enqueueing %u bytes to send to peer %s\n",
1797 (unsigned int) msg_size, 1795 (unsigned int)msg_size,
1798 GNUNET_i2s (target)); 1796 GNUNET_i2s(target));
1799 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, 1797 GNUNET_CONTAINER_DLL_insert_tail(n->messages_head,
1800 n->messages_tail, 1798 n->messages_tail,
1801 mq); 1799 mq);
1802 if (NULL != n->task) 1800 if (NULL != n->task)
1803 GNUNET_SCHEDULER_cancel (n->task); 1801 GNUNET_SCHEDULER_cancel(n->task);
1804 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 1802 n->task = GNUNET_SCHEDULER_add_now(&master_task, n);
1805} 1803}
1806 1804
1807 1805
@@ -1818,73 +1816,77 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1818 * @param size_on_wire how much bandwidth was consumed on the wire (ignored) 1816 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1819 */ 1817 */
1820static void 1818static void
1821send_session_syn_cont (void *cls, 1819send_session_syn_cont(void *cls,
1822 const struct GNUNET_PeerIdentity *target, 1820 const struct GNUNET_PeerIdentity *target,
1823 int result, 1821 int result,
1824 size_t size_payload, 1822 size_t size_payload,
1825 size_t size_on_wire) 1823 size_t size_on_wire)
1826{ 1824{
1827 struct NeighbourMapEntry *n; 1825 struct NeighbourMapEntry *n;
1828 1826
1829 (void) cls; 1827 (void)cls;
1830 (void) size_payload; 1828 (void)size_payload;
1831 (void) size_on_wire; 1829 (void)size_on_wire;
1832 n = lookup_neighbour (target); 1830 n = lookup_neighbour(target);
1833 if (NULL == n) 1831 if (NULL == n)
1834 { 1832 {
1835 /* SYN continuation was called after neighbor was freed, 1833 /* SYN continuation was called after neighbor was freed,
1836 * for example due to a time out for the state or the session 1834 * for example due to a time out for the state or the session
1837 * used was already terminated: nothing to do here... */ 1835 * used was already terminated: nothing to do here... */
1838 return; 1836 return;
1839 } 1837 }
1840 1838
1841 if ( (GNUNET_TRANSPORT_PS_SYN_SENT != n->state) && 1839 if ((GNUNET_TRANSPORT_PS_SYN_SENT != n->state) &&
1842 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) && 1840 (GNUNET_TRANSPORT_PS_RECONNECT_SENT != n->state) &&
1843 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state)) 1841 (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT != n->state))
1844 { 1842 {
1845 /* SYN continuation was called after neighbor changed state, 1843 /* SYN continuation was called after neighbor changed state,
1846 * for example due to a time out for the state or the session 1844 * for example due to a time out for the state or the session
1847 * used was already terminated: nothing to do here... */ 1845 * used was already terminated: nothing to do here... */
1848 return; 1846 return;
1849 } 1847 }
1850 if (GNUNET_OK == result) 1848 if (GNUNET_OK == result)
1851 return; 1849 return;
1852 1850
1853 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1851 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1854 _("Failed to send SYN message to peer `%s'\n"), 1852 _("Failed to send SYN message to peer `%s'\n"),
1855 GNUNET_i2s (target)); 1853 GNUNET_i2s(target));
1856 switch (n->state) { 1854 switch (n->state)
1857 case GNUNET_TRANSPORT_PS_SYN_SENT: 1855 {
1858 /* Remove address and request an additional one */ 1856 case GNUNET_TRANSPORT_PS_SYN_SENT:
1859 unset_primary_address (n); 1857 /* Remove address and request an additional one */
1860 set_state_and_timeout (n, 1858 unset_primary_address(n);
1861 GNUNET_TRANSPORT_PS_INIT_ATS, 1859 set_state_and_timeout(n,
1862 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 1860 GNUNET_TRANSPORT_PS_INIT_ATS,
1863 break; 1861 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
1864 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 1862 break;
1865 /* Remove address and request an additional one */ 1863
1866 unset_primary_address (n); 1864 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1867 set_state_and_timeout (n, 1865 /* Remove address and request an additional one */
1868 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 1866 unset_primary_address(n);
1869 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1867 set_state_and_timeout(n,
1870 break; 1868 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1871 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 1869 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
1872 /* Remove address and request and go back to primary address */ 1870 break;
1873 GNUNET_STATISTICS_update (GST_stats, 1871
1874 gettext_noop ("# Failed attempts to switch addresses (failed to send SYN CONT)"), 1872 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1875 1, 1873 /* Remove address and request and go back to primary address */
1876 GNUNET_NO); 1874 GNUNET_STATISTICS_update(GST_stats,
1877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1875 gettext_noop("# Failed attempts to switch addresses (failed to send SYN CONT)"),
1878 "Switch failed, cleaning up alternative address\n"); 1876 1,
1879 free_address (&n->alternative_address); 1877 GNUNET_NO);
1880 set_state_and_timeout (n, 1878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1881 GNUNET_TRANSPORT_PS_CONNECTED, 1879 "Switch failed, cleaning up alternative address\n");
1882 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 1880 free_address(&n->alternative_address);
1883 break; 1881 set_state_and_timeout(n,
1884 default: 1882 GNUNET_TRANSPORT_PS_CONNECTED,
1885 disconnect_neighbour (n); 1883 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
1886 break; 1884 break;
1887 } 1885
1886 default:
1887 disconnect_neighbour(n);
1888 break;
1889 }
1888} 1890}
1889 1891
1890 1892
@@ -1894,90 +1896,94 @@ send_session_syn_cont (void *cls,
1894 * @param na address to use 1896 * @param na address to use
1895 */ 1897 */
1896static void 1898static void
1897send_syn (struct NeighbourAddress *na) 1899send_syn(struct NeighbourAddress *na)
1898{ 1900{
1899 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1901 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1900 struct TransportSynMessage connect_msg; 1902 struct TransportSynMessage connect_msg;
1901 struct NeighbourMapEntry *n; 1903 struct NeighbourMapEntry *n;
1902 1904
1903 GNUNET_assert (NULL != na->session); 1905 GNUNET_assert(NULL != na->session);
1904 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1906 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1905 "Sending SYN message to peer `%s' at %s\n", 1907 "Sending SYN message to peer `%s' at %s\n",
1906 GNUNET_i2s (&na->address->peer), 1908 GNUNET_i2s(&na->address->peer),
1907 GST_plugins_a2s (na->address)); 1909 GST_plugins_a2s(na->address));
1908 1910
1909 papi = GST_plugins_find (na->address->transport_name); 1911 papi = GST_plugins_find(na->address->transport_name);
1910 GNUNET_assert (NULL != papi); 1912 GNUNET_assert(NULL != papi);
1911 GNUNET_STATISTICS_update (GST_stats, 1913 GNUNET_STATISTICS_update(GST_stats,
1912 gettext_noop 1914 gettext_noop
1913 ("# SYN messages sent"), 1915 ("# SYN messages sent"),
1914 1, GNUNET_NO); 1916 1, GNUNET_NO);
1915 na->connect_timestamp = GNUNET_TIME_absolute_get (); 1917 na->connect_timestamp = GNUNET_TIME_absolute_get();
1916 connect_msg.header.size = htons (sizeof (struct TransportSynMessage)); 1918 connect_msg.header.size = htons(sizeof(struct TransportSynMessage));
1917 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN); 1919 connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN);
1918 connect_msg.reserved = htonl (0); 1920 connect_msg.reserved = htonl(0);
1919 connect_msg.timestamp = GNUNET_TIME_absolute_hton (na->connect_timestamp); 1921 connect_msg.timestamp = GNUNET_TIME_absolute_hton(na->connect_timestamp);
1920 if (-1 == 1922 if (-1 ==
1921 papi->send (papi->cls, 1923 papi->send(papi->cls,
1922 na->session, 1924 na->session,
1923 (const char *) &connect_msg, 1925 (const char *)&connect_msg,
1924 sizeof (struct TransportSynMessage), 1926 sizeof(struct TransportSynMessage),
1925 UINT_MAX, 1927 UINT_MAX,
1926 SETUP_CONNECTION_TIMEOUT, 1928 SETUP_CONNECTION_TIMEOUT,
1927 &send_session_syn_cont, NULL)) 1929 &send_session_syn_cont, NULL))
1928 { 1930 {
1929 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1931 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1930 _("Failed to transmit SYN message to %s\n"), 1932 _("Failed to transmit SYN message to %s\n"),
1931 GST_plugins_a2s (na->address)); 1933 GST_plugins_a2s(na->address));
1932 n = lookup_neighbour (&na->address->peer); 1934 n = lookup_neighbour(&na->address->peer);
1933 if (NULL == n) 1935 if (NULL == n)
1934 { 1936 {
1935 GNUNET_break (0); 1937 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 }
1936 return; 1982 return;
1937 } 1983 }
1938 switch (n->state) { 1984 GST_neighbours_notify_data_sent(na->address,
1939 case GNUNET_TRANSPORT_PS_SYN_SENT: 1985 na->session,
1940 /* Remove address and request and additional one */ 1986 sizeof(struct TransportSynMessage));
1941 GNUNET_assert (na == &n->primary_address);
1942 unset_primary_address (n);
1943 set_state_and_timeout (n,
1944 GNUNET_TRANSPORT_PS_INIT_ATS,
1945 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT));
1946 /* Hard failure to send the SYN message with this address:
1947 Destroy address and session */
1948 break;
1949 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
1950 /* Remove address and request an additional one */
1951 GNUNET_assert (na == &n->primary_address);
1952 unset_primary_address (n);
1953 set_state_and_timeout (n,
1954 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
1955 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1956 break;
1957 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
1958 GNUNET_assert (na == &n->alternative_address);
1959 GNUNET_STATISTICS_update (GST_stats,
1960 gettext_noop ("# Failed attempts to switch addresses (failed to send SYN)"),
1961 1,
1962 GNUNET_NO);
1963 /* Remove address and request an additional one */
1964 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1965 "Switch failed, cleaning up alternative address\n");
1966 free_address (&n->alternative_address);
1967 set_state_and_timeout (n,
1968 GNUNET_TRANSPORT_PS_CONNECTED,
1969 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
1970 break;
1971 default:
1972 GNUNET_break (0);
1973 disconnect_neighbour (n);
1974 break;
1975 }
1976 return;
1977 }
1978 GST_neighbours_notify_data_sent (na->address,
1979 na->session,
1980 sizeof (struct TransportSynMessage));
1981} 1987}
1982 1988
1983 1989
@@ -1994,50 +2000,50 @@ send_syn (struct NeighbourAddress *na)
1994 * @param size_on_wire how much bandwidth was consumed on the wire (ignored) 2000 * @param size_on_wire how much bandwidth was consumed on the wire (ignored)
1995 */ 2001 */
1996static void 2002static void
1997send_session_syn_ack_cont (void *cls, 2003send_session_syn_ack_cont(void *cls,
1998 const struct GNUNET_PeerIdentity *target, 2004 const struct GNUNET_PeerIdentity *target,
1999 int result, 2005 int result,
2000 size_t size_payload, 2006 size_t size_payload,
2001 size_t size_on_wire) 2007 size_t size_on_wire)
2002{ 2008{
2003 struct NeighbourMapEntry *n; 2009 struct NeighbourMapEntry *n;
2004 2010
2005 (void) cls; 2011 (void)cls;
2006 (void) size_payload; 2012 (void)size_payload;
2007 (void) size_on_wire; 2013 (void)size_on_wire;
2008 n = lookup_neighbour (target); 2014 n = lookup_neighbour(target);
2009 if (NULL == n) 2015 if (NULL == n)
2010 { 2016 {
2011 /* SYN_ACK continuation was called after neighbor was freed, 2017 /* SYN_ACK continuation was called after neighbor was freed,
2012 * for example due to a time out for the state or the session 2018 * for example due to a time out for the state or the session
2013 * used was already terminated: nothing to do here... */ 2019 * used was already terminated: nothing to do here... */
2014 return; 2020 return;
2015 } 2021 }
2016 2022
2017 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) 2023 if (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state)
2018 { 2024 {
2019 /* SYN_ACK continuation was called after neighbor changed state, 2025 /* SYN_ACK continuation was called after neighbor changed state,
2020 * for example due to a time out for the state or the session 2026 * for example due to a time out for the state or the session
2021 * used was already terminated: nothing to do here... */ 2027 * used was already terminated: nothing to do here... */
2022 return; 2028 return;
2023 } 2029 }
2024 if (GNUNET_OK == result) 2030 if (GNUNET_OK == result)
2025 return; 2031 return;
2026 2032
2027 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2033 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2028 _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"), 2034 _("Failed to send SYN_ACK message to peer `%s' using address `%s'\n"),
2029 GNUNET_i2s (target), 2035 GNUNET_i2s(target),
2030 GST_plugins_a2s (n->primary_address.address)); 2036 GST_plugins_a2s(n->primary_address.address));
2031 2037
2032 /* Remove address and request and additional one */ 2038 /* Remove address and request and additional one */
2033 /* FIXME: what if the neighbour's primary address 2039 /* FIXME: what if the neighbour's primary address
2034 changed in the meantime? Might want to instead 2040 changed in the meantime? Might want to instead
2035 pass "something" around in closure to be sure. */ 2041 pass "something" around in closure to be sure. */
2036 unset_primary_address (n); 2042 unset_primary_address(n);
2037 n->ack_state = ACK_SEND_SYN_ACK; 2043 n->ack_state = ACK_SEND_SYN_ACK;
2038 set_state_and_timeout (n, 2044 set_state_and_timeout(n,
2039 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2045 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2040 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2046 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
2041} 2047}
2042 2048
2043 2049
@@ -2049,8 +2055,8 @@ send_session_syn_ack_cont (void *cls,
2049 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise 2055 * @return #GNUNET_SYSERR if sending immediately failed, #GNUNET_OK otherwise
2050 */ 2056 */
2051static void 2057static void
2052send_syn_ack_message (struct NeighbourAddress *na, 2058send_syn_ack_message(struct NeighbourAddress *na,
2053 struct GNUNET_TIME_Absolute timestamp) 2059 struct GNUNET_TIME_Absolute timestamp)
2054{ 2060{
2055 const struct GNUNET_HELLO_Address *address = na->address; 2061 const struct GNUNET_HELLO_Address *address = na->address;
2056 struct GNUNET_ATS_Session *session = na->session; 2062 struct GNUNET_ATS_Session *session = na->session;
@@ -2058,61 +2064,61 @@ send_syn_ack_message (struct NeighbourAddress *na,
2058 struct TransportSynMessage connect_msg; 2064 struct TransportSynMessage connect_msg;
2059 struct NeighbourMapEntry *n; 2065 struct NeighbourMapEntry *n;
2060 2066
2061 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2067 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2062 "Sending SYN_ACK to peer `%s'\n", 2068 "Sending SYN_ACK to peer `%s'\n",
2063 GNUNET_i2s (&address->peer)); 2069 GNUNET_i2s(&address->peer));
2064 2070
2065 if (NULL == (papi = GST_plugins_find (address->transport_name))) 2071 if (NULL == (papi = GST_plugins_find(address->transport_name)))
2066 { 2072 {
2067 GNUNET_break (0); 2073 GNUNET_break(0);
2068 return; 2074 return;
2069 } 2075 }
2070 if (NULL == session) 2076 if (NULL == session)
2071 session = papi->get_session (papi->cls, 2077 session = papi->get_session(papi->cls,
2072 address); 2078 address);
2073 if (NULL == session) 2079 if (NULL == session)
2074 { 2080 {
2075 GNUNET_break (0); 2081 GNUNET_break(0);
2076 return; 2082 return;
2077 } 2083 }
2078 GST_ats_new_session (address, 2084 GST_ats_new_session(address,
2079 session); 2085 session);
2080 GNUNET_STATISTICS_update (GST_stats, 2086 GNUNET_STATISTICS_update(GST_stats,
2081 gettext_noop 2087 gettext_noop
2082 ("# SYN_ACK messages sent"), 2088 ("# SYN_ACK messages sent"),
2083 1, GNUNET_NO); 2089 1, GNUNET_NO);
2084 connect_msg.header.size = htons (sizeof (struct TransportSynMessage)); 2090 connect_msg.header.size = htons(sizeof(struct TransportSynMessage));
2085 connect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK); 2091 connect_msg.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_SYN_ACK);
2086 connect_msg.reserved = htonl (0); 2092 connect_msg.reserved = htonl(0);
2087 connect_msg.timestamp = GNUNET_TIME_absolute_hton (timestamp); 2093 connect_msg.timestamp = GNUNET_TIME_absolute_hton(timestamp);
2088 2094
2089 if (GNUNET_SYSERR == 2095 if (GNUNET_SYSERR ==
2090 papi->send (papi->cls, 2096 papi->send(papi->cls,
2091 session, 2097 session,
2092 (const char *) &connect_msg, 2098 (const char *)&connect_msg,
2093 sizeof (struct TransportSynMessage), 2099 sizeof(struct TransportSynMessage),
2094 UINT_MAX, 2100 UINT_MAX,
2095 GNUNET_TIME_UNIT_FOREVER_REL, 2101 GNUNET_TIME_UNIT_FOREVER_REL,
2096 &send_session_syn_ack_cont, NULL)) 2102 &send_session_syn_ack_cont, NULL))
2097 { 2103 {
2098 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 2104 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
2099 _("Failed to transmit SYN_ACK message to %s\n"), 2105 _("Failed to transmit SYN_ACK message to %s\n"),
2100 GST_plugins_a2s (address)); 2106 GST_plugins_a2s(address));
2101 2107
2102 n = lookup_neighbour (&address->peer); 2108 n = lookup_neighbour(&address->peer);
2103 if (NULL == n) 2109 if (NULL == n)
2104 { 2110 {
2105 GNUNET_break (0); 2111 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));
2106 return; 2120 return;
2107 } 2121 }
2108 /* Remove address and request and additional one */
2109 unset_primary_address (n);
2110 n->ack_state = ACK_SEND_SYN_ACK;
2111 set_state_and_timeout (n,
2112 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2113 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2114 return;
2115 }
2116} 2122}
2117 2123
2118 2124
@@ -2125,7 +2131,7 @@ send_syn_ack_message (struct NeighbourAddress *na,
2125 * @param cls the `struct NeighbourMapEntry` to update calculations for 2131 * @param cls the `struct NeighbourMapEntry` to update calculations for
2126 */ 2132 */
2127static void 2133static void
2128inbound_bw_tracker_update (void *cls) 2134inbound_bw_tracker_update(void *cls)
2129{ 2135{
2130 struct NeighbourMapEntry *n = cls; 2136 struct NeighbourMapEntry *n = cls;
2131 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2137 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -2134,23 +2140,23 @@ inbound_bw_tracker_update (void *cls)
2134 2140
2135 if (NULL == n->primary_address.address) 2141 if (NULL == n->primary_address.address)
2136 return; /* not active, ignore */ 2142 return; /* not active, ignore */
2137 papi = GST_plugins_find (n->primary_address.address->transport_name); 2143 papi = GST_plugins_find(n->primary_address.address->transport_name);
2138 GNUNET_assert (NULL != papi); 2144 GNUNET_assert(NULL != papi);
2139 if (NULL == papi->update_inbound_delay) 2145 if (NULL == papi->update_inbound_delay)
2140 return; 2146 return;
2141 delay = GST_neighbours_calculate_receive_delay (&n->id, 2147 delay = GST_neighbours_calculate_receive_delay(&n->id,
2142 0, 2148 0,
2143 &do_forward); 2149 &do_forward);
2144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2145 "New inbound delay for peer `%s' is %llu ms\n", 2151 "New inbound delay for peer `%s' is %llu ms\n",
2146 GNUNET_i2s (&n->id), 2152 GNUNET_i2s(&n->id),
2147 (unsigned long long) delay.rel_value_us / 1000LL); 2153 (unsigned long long)delay.rel_value_us / 1000LL);
2148 if (NULL == n->primary_address.session) 2154 if (NULL == n->primary_address.session)
2149 return; 2155 return;
2150 papi->update_inbound_delay (papi->cls, 2156 papi->update_inbound_delay(papi->cls,
2151 &n->id, 2157 &n->id,
2152 n->primary_address.session, 2158 n->primary_address.session,
2153 delay); 2159 delay);
2154} 2160}
2155 2161
2156 2162
@@ -2161,44 +2167,44 @@ inbound_bw_tracker_update (void *cls)
2161 * @return new neighbour map entry 2167 * @return new neighbour map entry
2162 */ 2168 */
2163static struct NeighbourMapEntry * 2169static struct NeighbourMapEntry *
2164setup_neighbour (const struct GNUNET_PeerIdentity *peer) 2170setup_neighbour(const struct GNUNET_PeerIdentity *peer)
2165{ 2171{
2166 struct NeighbourMapEntry *n; 2172 struct NeighbourMapEntry *n;
2167 2173
2168 if (0 == 2174 if (0 ==
2169 memcmp (&GST_my_identity, 2175 memcmp(&GST_my_identity,
2170 peer, 2176 peer,
2171 sizeof (struct GNUNET_PeerIdentity))) 2177 sizeof(struct GNUNET_PeerIdentity)))
2172 { 2178 {
2173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2179 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2174 "Cowardly refusing to consider myself my neighbour!\n"); 2180 "Cowardly refusing to consider myself my neighbour!\n");
2175 return NULL; 2181 return NULL;
2176 } 2182 }
2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2183 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2178 "Creating new neighbour entry for `%s'\n", 2184 "Creating new neighbour entry for `%s'\n",
2179 GNUNET_i2s (peer)); 2185 GNUNET_i2s(peer));
2180 n = GNUNET_new (struct NeighbourMapEntry); 2186 n = GNUNET_new(struct NeighbourMapEntry);
2181 n->id = *peer; 2187 n->id = *peer;
2182 n->ack_state = ACK_UNDEFINED; 2188 n->ack_state = ACK_UNDEFINED;
2183 n->last_util_transmission = GNUNET_TIME_absolute_get(); 2189 n->last_util_transmission = GNUNET_TIME_absolute_get();
2184 n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 2190 n->neighbour_receive_quota = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
2185 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 2191 GNUNET_BANDWIDTH_tracker_init(&n->in_tracker,
2186 &inbound_bw_tracker_update, 2192 &inbound_bw_tracker_update,
2187 n, 2193 n,
2188 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 2194 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
2189 MAX_BANDWIDTH_CARRY_S); 2195 MAX_BANDWIDTH_CARRY_S);
2190 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 2196 n->task = GNUNET_SCHEDULER_add_now(&master_task, n);
2191 set_state_and_timeout (n, 2197 set_state_and_timeout(n,
2192 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 2198 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
2193 GNUNET_TIME_UNIT_FOREVER_ABS); 2199 GNUNET_TIME_UNIT_FOREVER_ABS);
2194 GNUNET_assert (GNUNET_OK == 2200 GNUNET_assert(GNUNET_OK ==
2195 GNUNET_CONTAINER_multipeermap_put (neighbours, 2201 GNUNET_CONTAINER_multipeermap_put(neighbours,
2196 &n->id, 2202 &n->id,
2197 n, 2203 n,
2198 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2204 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2199 n->suggest_handle = GNUNET_ATS_connectivity_suggest (GST_ats_connect, 2205 n->suggest_handle = GNUNET_ATS_connectivity_suggest(GST_ats_connect,
2200 peer, 2206 peer,
2201 0); 2207 0);
2202 2208
2203 return n; 2209 return n;
2204} 2210}
@@ -2207,8 +2213,7 @@ setup_neighbour (const struct GNUNET_PeerIdentity *peer)
2207/** 2213/**
2208 * Entry in a DLL we use to keep track of pending blacklist checks. 2214 * Entry in a DLL we use to keep track of pending blacklist checks.
2209 */ 2215 */
2210struct BlacklistCheckSwitchContext 2216struct BlacklistCheckSwitchContext {
2211{
2212 /** 2217 /**
2213 * DLL prev pointer. 2218 * DLL prev pointer.
2214 */ 2219 */
@@ -2245,135 +2250,145 @@ struct BlacklistCheckSwitchContext
2245 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 2250 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
2246 */ 2251 */
2247int 2252int
2248GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, 2253GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message,
2249 const struct GNUNET_PeerIdentity *peer) 2254 const struct GNUNET_PeerIdentity *peer)
2250{ 2255{
2251 const struct TransportSynMessage *scm; 2256 const struct TransportSynMessage *scm;
2252 struct NeighbourMapEntry *n; 2257 struct NeighbourMapEntry *n;
2253 struct GNUNET_TIME_Absolute ts; 2258 struct GNUNET_TIME_Absolute ts;
2254 2259
2255 if (ntohs (message->size) != sizeof (struct TransportSynMessage)) 2260 if (ntohs(message->size) != sizeof(struct TransportSynMessage))
2256 { 2261 {
2257 GNUNET_break_op (0); 2262 GNUNET_break_op(0);
2258 return GNUNET_SYSERR; 2263 return GNUNET_SYSERR;
2259 } 2264 }
2260 GNUNET_STATISTICS_update (GST_stats, 2265 GNUNET_STATISTICS_update(GST_stats,
2261 gettext_noop 2266 gettext_noop
2262 ("# SYN messages received"), 2267 ("# SYN messages received"),
2263 1, GNUNET_NO); 2268 1, GNUNET_NO);
2264 if (NULL == neighbours) 2269 if (NULL == neighbours)
2265 { 2270 {
2266 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2271 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2267 _("SYN request from peer `%s' ignored due impending shutdown\n"), 2272 _("SYN request from peer `%s' ignored due impending shutdown\n"),
2268 GNUNET_i2s (peer)); 2273 GNUNET_i2s(peer));
2269 return GNUNET_OK; /* we're shutting down */ 2274 return GNUNET_OK; /* we're shutting down */
2270 } 2275 }
2271 scm = (const struct TransportSynMessage *) message; 2276 scm = (const struct TransportSynMessage *)message;
2272 GNUNET_break_op (0 == ntohl (scm->reserved)); 2277 GNUNET_break_op(0 == ntohl(scm->reserved));
2273 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 2278 ts = GNUNET_TIME_absolute_ntoh(scm->timestamp);
2274 if (0 == 2279 if (0 ==
2275 memcmp (&GST_my_identity, 2280 memcmp(&GST_my_identity,
2276 peer, 2281 peer,
2277 sizeof (struct GNUNET_PeerIdentity))) 2282 sizeof(struct GNUNET_PeerIdentity)))
2278 { 2283 {
2279 /* loopback connection-to-self, ignore */ 2284 /* loopback connection-to-self, ignore */
2280 return GNUNET_SYSERR; 2285 return GNUNET_SYSERR;
2281 } 2286 }
2282 n = lookup_neighbour (peer); 2287 n = lookup_neighbour(peer);
2283 if (NULL == n) 2288 if (NULL == n)
2284 { 2289 {
2285 /* This is a new neighbour and set to not connected */ 2290 /* This is a new neighbour and set to not connected */
2286 n = setup_neighbour (peer); 2291 n = setup_neighbour(peer);
2287 GNUNET_assert (NULL != n); 2292 GNUNET_assert(NULL != n);
2288 } 2293 }
2289 2294
2290 /* Remember this SYN message in neighbour */ 2295 /* Remember this SYN message in neighbour */
2291 n->ack_state = ACK_SEND_SYN_ACK; 2296 n->ack_state = ACK_SEND_SYN_ACK;
2292 n->connect_ack_timestamp = ts; 2297 n->connect_ack_timestamp = ts;
2293 2298
2294 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2299 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2295 "Received SYN for peer `%s' in state %s/%s\n", 2300 "Received SYN for peer `%s' in state %s/%s\n",
2296 GNUNET_i2s (peer), 2301 GNUNET_i2s(peer),
2297 GNUNET_TRANSPORT_ps2s (n->state), 2302 GNUNET_TRANSPORT_ps2s(n->state),
2298 print_ack_state (n->ack_state)); 2303 print_ack_state(n->ack_state));
2299 2304
2300 switch (n->state) 2305 switch (n->state)
2301 { 2306 {
2302 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 2307 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2303 /* Request an address from ATS to send SYN_ACK to this peer */ 2308 /* Request an address from ATS to send SYN_ACK to this peer */
2304 set_state_and_timeout (n, 2309 set_state_and_timeout(n,
2305 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2310 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2306 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2311 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
2307 break; 2312 break;
2308 case GNUNET_TRANSPORT_PS_INIT_ATS: 2313
2309 /* SYN message takes priority over us asking ATS for address: 2314 case GNUNET_TRANSPORT_PS_INIT_ATS:
2310 * Wait for ATS to suggest an address and send SYN_ACK */ 2315 /* SYN message takes priority over us asking ATS for address:
2311 set_state_and_timeout (n, 2316 * Wait for ATS to suggest an address and send SYN_ACK */
2312 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2317 set_state_and_timeout(n,
2313 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2318 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2314 break; 2319 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
2315 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 2320 break;
2316 /* We already wait for an address to send an SYN_ACK */ 2321
2317 break; 2322 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2318 case GNUNET_TRANSPORT_PS_SYN_SENT: 2323 /* We already wait for an address to send an SYN_ACK */
2319 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 2324 break;
2320 /* Send ACK immediately */ 2325
2321 n->ack_state = ACK_SEND_ACK; 2326 case GNUNET_TRANSPORT_PS_SYN_SENT:
2322 send_syn_ack_message (&n->primary_address, 2327 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2323 ts); 2328 /* Send ACK immediately */
2324 break; 2329 n->ack_state = ACK_SEND_ACK;
2325 case GNUNET_TRANSPORT_PS_CONNECTED: 2330 send_syn_ack_message(&n->primary_address,
2326 /* we are already connected and can thus send the ACK immediately */ 2331 ts);
2327 GNUNET_assert (NULL != n->primary_address.address); 2332 break;
2328 GNUNET_assert (NULL != n->primary_address.session); 2333
2329 n->ack_state = ACK_SEND_ACK; 2334 case GNUNET_TRANSPORT_PS_CONNECTED:
2330 send_syn_ack_message (&n->primary_address, 2335 /* we are already connected and can thus send the ACK immediately */
2331 ts); 2336 GNUNET_assert(NULL != n->primary_address.address);
2332 break; 2337 GNUNET_assert(NULL != n->primary_address.session);
2333 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2338 n->ack_state = ACK_SEND_ACK;
2334 /* We wait for ATS address suggestion */ 2339 send_syn_ack_message(&n->primary_address,
2335 break; 2340 ts);
2336 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 2341 break;
2337 /* We received a SYN message while waiting for a SYN_ACK in fast 2342
2338 * reconnect. Send SYN_ACK immediately */ 2343 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2339 n->ack_state = ACK_SEND_ACK; 2344 /* We wait for ATS address suggestion */
2340 send_syn_ack_message (&n->primary_address, 2345 break;
2341 n->connect_ack_timestamp); 2346
2342 break; 2347 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2343 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2348 /* We received a SYN message while waiting for a SYN_ACK in fast
2344 /* We are already connected and can thus send the ACK immediately; 2349 * reconnect. Send SYN_ACK immediately */
2345 still, it can never hurt to have an alternative address, so also 2350 n->ack_state = ACK_SEND_ACK;
2346 tell ATS about it */ 2351 send_syn_ack_message(&n->primary_address,
2347 GNUNET_assert (NULL != n->primary_address.address); 2352 n->connect_ack_timestamp);
2348 GNUNET_assert (NULL != n->primary_address.session); 2353 break;
2349 n->ack_state = ACK_SEND_ACK; 2354
2350 send_syn_ack_message (&n->primary_address, 2355 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2351 ts); 2356 /* We are already connected and can thus send the ACK immediately;
2352 break; 2357 still, it can never hurt to have an alternative address, so also
2353 case GNUNET_TRANSPORT_PS_DISCONNECT: 2358 tell ATS about it */
2354 /* Get rid of remains and re-try */ 2359 GNUNET_assert(NULL != n->primary_address.address);
2355 free_neighbour (n); 2360 GNUNET_assert(NULL != n->primary_address.session);
2356 n = setup_neighbour (peer); 2361 n->ack_state = ACK_SEND_ACK;
2357 GNUNET_assert (NULL != n); 2362 send_syn_ack_message(&n->primary_address,
2358 /* Remember the SYN time stamp for ACK message */ 2363 ts);
2359 n->ack_state = ACK_SEND_SYN_ACK; 2364 break;
2360 n->connect_ack_timestamp = ts; 2365
2361 /* Request an address for the peer */ 2366 case GNUNET_TRANSPORT_PS_DISCONNECT:
2362 set_state_and_timeout (n, 2367 /* Get rid of remains and re-try */
2363 GNUNET_TRANSPORT_PS_SYN_RECV_ATS, 2368 free_neighbour(n);
2364 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 2369 n = setup_neighbour(peer);
2365 break; 2370 GNUNET_assert(NULL != n);
2366 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 2371 /* Remember the SYN time stamp for ACK message */
2367 /* should not be possible */ 2372 n->ack_state = ACK_SEND_SYN_ACK;
2368 GNUNET_assert (0); 2373 n->connect_ack_timestamp = ts;
2369 break; 2374 /* Request an address for the peer */
2370 default: 2375 set_state_and_timeout(n,
2371 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2376 GNUNET_TRANSPORT_PS_SYN_RECV_ATS,
2372 "Unhandled state `%s'\n", 2377 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
2373 GNUNET_TRANSPORT_ps2s (n->state)); 2378 break;
2374 GNUNET_break (0); 2379
2375 return GNUNET_SYSERR; 2380 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2376 } 2381 /* should not be possible */
2382 GNUNET_assert(0);
2383 break;
2384
2385 default:
2386 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2387 "Unhandled state `%s'\n",
2388 GNUNET_TRANSPORT_ps2s(n->state));
2389 GNUNET_break(0);
2390 return GNUNET_SYSERR;
2391 }
2377 return GNUNET_OK; 2392 return GNUNET_OK;
2378} 2393}
2379 2394
@@ -2388,50 +2403,50 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
2388 * @param address address of the other peer, 2403 * @param address address of the other peer,
2389 * @param session session to use or NULL if transport should initiate a session 2404 * @param session session to use or NULL if transport should initiate a session
2390 * @param bandwidth_in inbound quota to be used when connection is up, 2405 * @param bandwidth_in inbound quota to be used when connection is up,
2391 * 0 to disconnect from peer 2406 * 0 to disconnect from peer
2392 * @param bandwidth_out outbound quota to be used when connection is up, 2407 * @param bandwidth_out outbound quota to be used when connection is up,
2393 * 0 to disconnect from peer 2408 * 0 to disconnect from peer
2394 * @return #GNUNET_OK if we were able to just update the bandwidth and session, 2409 * @return #GNUNET_OK if we were able to just update the bandwidth and session,
2395 * #GNUNET_NO if more extensive changes are required (address changed) 2410 * #GNUNET_NO if more extensive changes are required (address changed)
2396 */ 2411 */
2397static int 2412static int
2398try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address, 2413try_run_fast_ats_update(const struct GNUNET_HELLO_Address *address,
2399 struct GNUNET_ATS_Session *session, 2414 struct GNUNET_ATS_Session *session,
2400 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2415 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2401 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2416 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2402{ 2417{
2403 struct NeighbourMapEntry *n; 2418 struct NeighbourMapEntry *n;
2404 2419
2405 n = lookup_neighbour (&address->peer); 2420 n = lookup_neighbour(&address->peer);
2406 if ( (NULL == n) || 2421 if ((NULL == n) ||
2407 (NULL == n->primary_address.address) || 2422 (NULL == n->primary_address.address) ||
2408 (0 != GNUNET_HELLO_address_cmp (address, 2423 (0 != GNUNET_HELLO_address_cmp(address,
2409 n->primary_address.address)) ) 2424 n->primary_address.address)))
2410 return GNUNET_NO; 2425 return GNUNET_NO;
2411 /* We are not really switching addresses, but merely adjusting 2426 /* We are not really switching addresses, but merely adjusting
2412 session and/or bandwidth, can do fast ATS update! */ 2427 session and/or bandwidth, can do fast ATS update! */
2413 if (session != n->primary_address.session) 2428 if (session != n->primary_address.session)
2414 { 2429 {
2415 /* switch to a different session, but keeping same address; could 2430 /* switch to a different session, but keeping same address; could
2416 happen if there is a 2nd inbound connection */ 2431 happen if there is a 2nd inbound connection */
2417 n->primary_address.session = session; 2432 n->primary_address.session = session;
2418 GNUNET_assert (GNUNET_YES == 2433 GNUNET_assert(GNUNET_YES ==
2419 GST_ats_is_known (n->primary_address.address, 2434 GST_ats_is_known(n->primary_address.address,
2420 n->primary_address.session)); 2435 n->primary_address.session));
2421 } 2436 }
2422 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__) 2437 if (n->primary_address.bandwidth_in.value__ != bandwidth_in.value__)
2423 { 2438 {
2424 n->primary_address.bandwidth_in = bandwidth_in; 2439 n->primary_address.bandwidth_in = bandwidth_in;
2425 if (GNUNET_YES != 2440 if (GNUNET_YES !=
2426 set_incoming_quota (n, 2441 set_incoming_quota(n,
2427 bandwidth_in)) 2442 bandwidth_in))
2428 return GNUNET_NO; 2443 return GNUNET_NO;
2429 } 2444 }
2430 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__) 2445 if (n->primary_address.bandwidth_out.value__ != bandwidth_out.value__)
2431 { 2446 {
2432 n->primary_address.bandwidth_out = bandwidth_out; 2447 n->primary_address.bandwidth_out = bandwidth_out;
2433 send_outbound_quota_to_clients (n); 2448 send_outbound_quota_to_clients(n);
2434 } 2449 }
2435 return GNUNET_OK; 2450 return GNUNET_OK;
2436} 2451}
2437 2452
@@ -2450,11 +2465,11 @@ try_run_fast_ats_update (const struct GNUNET_HELLO_Address *address,
2450 * #GNUNET_SYSERR if operation was aborted 2465 * #GNUNET_SYSERR if operation was aborted
2451 */ 2466 */
2452static void 2467static void
2453switch_address_bl_check_cont (void *cls, 2468switch_address_bl_check_cont(void *cls,
2454 const struct GNUNET_PeerIdentity *peer, 2469 const struct GNUNET_PeerIdentity *peer,
2455 const struct GNUNET_HELLO_Address *address, 2470 const struct GNUNET_HELLO_Address *address,
2456 struct GNUNET_ATS_Session *session, 2471 struct GNUNET_ATS_Session *session,
2457 int result) 2472 int result)
2458{ 2473{
2459 struct BlacklistCheckSwitchContext *blc_ctx = cls; 2474 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2460 struct GNUNET_TRANSPORT_PluginFunctions *papi; 2475 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -2463,277 +2478,289 @@ switch_address_bl_check_cont (void *cls,
2463 if (GNUNET_SYSERR == result) 2478 if (GNUNET_SYSERR == result)
2464 goto cleanup; 2479 goto cleanup;
2465 2480
2466 papi = GST_plugins_find (address->transport_name); 2481 papi = GST_plugins_find(address->transport_name);
2467 if (NULL == papi) { 2482 if (NULL == papi)
2468 /* This can happen during shutdown. */ 2483 {
2469 goto cleanup; 2484 /* This can happen during shutdown. */
2470 } 2485 goto cleanup;
2486 }
2471 2487
2472 if (GNUNET_NO == result) 2488 if (GNUNET_NO == result)
2473 { 2489 {
2474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2490 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2475 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n", 2491 "Blacklist denied to switch to suggested address `%s' session %p for peer `%s'\n",
2476 GST_plugins_a2s (address), 2492 GST_plugins_a2s(address),
2477 session, 2493 session,
2478 GNUNET_i2s (peer)); 2494 GNUNET_i2s(peer));
2479 GNUNET_STATISTICS_update (GST_stats, 2495 GNUNET_STATISTICS_update(GST_stats,
2480 "# ATS suggestions ignored (blacklist denied)", 2496 "# ATS suggestions ignored (blacklist denied)",
2481 1, 2497 1,
2482 GNUNET_NO); 2498 GNUNET_NO);
2483 if (NULL != session) 2499 if (NULL != session)
2484 papi->disconnect_session (papi->cls, 2500 papi->disconnect_session(papi->cls,
2485 session); 2501 session);
2486 if (GNUNET_YES != 2502 if (GNUNET_YES !=
2487 GNUNET_HELLO_address_check_option (address, 2503 GNUNET_HELLO_address_check_option(address,
2488 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 2504 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2489 GST_ats_block_address (address, 2505 GST_ats_block_address(address,
2490 NULL); 2506 NULL);
2491 goto cleanup; 2507 goto cleanup;
2492 } 2508 }
2493 2509
2494 2510
2495 if (NULL == session) 2511 if (NULL == session)
2496 { 2512 {
2497 /* need to create a session, ATS only gave us an address */ 2513 /* need to create a session, ATS only gave us an address */
2498 session = papi->get_session (papi->cls, 2514 session = papi->get_session(papi->cls,
2499 address); 2515 address);
2500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2516 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2501 "Obtained new session for peer `%s' and address '%s': %p\n", 2517 "Obtained new session for peer `%s' and address '%s': %p\n",
2502 GNUNET_i2s (&address->peer), 2518 GNUNET_i2s(&address->peer),
2503 GST_plugins_a2s (address), 2519 GST_plugins_a2s(address),
2504 session); 2520 session);
2505 if (NULL != session) 2521 if (NULL != session)
2506 GST_ats_new_session (address, 2522 GST_ats_new_session(address,
2507 session); 2523 session);
2508 } 2524 }
2509 if (NULL == session) 2525 if (NULL == session)
2510 { 2526 {
2511 /* session creation failed, bad!, fail! */ 2527 /* session creation failed, bad!, fail! */
2512 GNUNET_STATISTICS_update (GST_stats, 2528 GNUNET_STATISTICS_update(GST_stats,
2513 "# ATS suggestions ignored (failed to create session)", 2529 "# ATS suggestions ignored (failed to create session)",
2514 1, 2530 1,
2515 GNUNET_NO); 2531 GNUNET_NO);
2516 /* No session could be obtained, remove blacklist check and clean up */ 2532 /* No session could be obtained, remove blacklist check and clean up */
2517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2533 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2518 "Failed to obtain new session for peer `%s' and address '%s'\n", 2534 "Failed to obtain new session for peer `%s' and address '%s'\n",
2519 GNUNET_i2s (&address->peer), 2535 GNUNET_i2s(&address->peer),
2520 GST_plugins_a2s (address)); 2536 GST_plugins_a2s(address));
2521 GST_ats_block_address (address, 2537 GST_ats_block_address(address,
2522 session); 2538 session);
2523 goto cleanup; 2539 goto cleanup;
2524 } 2540 }
2525 2541
2526 /* We did this check already before going into blacklist, but 2542 /* We did this check already before going into blacklist, but
2527 it is theoretically possible that the situation changed in 2543 it is theoretically possible that the situation changed in
2528 the meantime, hence we check again here */ 2544 the meantime, hence we check again here */
2529 if (GNUNET_OK == 2545 if (GNUNET_OK ==
2530 try_run_fast_ats_update (address, 2546 try_run_fast_ats_update(address,
2531 session, 2547 session,
2532 blc_ctx->bandwidth_in, 2548 blc_ctx->bandwidth_in,
2533 blc_ctx->bandwidth_out)) 2549 blc_ctx->bandwidth_out))
2534 goto cleanup; /* was just a minor update, we're done */ 2550 goto cleanup; /* was just a minor update, we're done */
2535 2551
2536 /* check if we also need to setup the neighbour entry */ 2552 /* check if we also need to setup the neighbour entry */
2537 if (NULL == (n = lookup_neighbour (peer))) 2553 if (NULL == (n = lookup_neighbour(peer)))
2538 {
2539 n = setup_neighbour (peer);
2540 if (NULL == n)
2541 { 2554 {
2542 /* not sure how this can happen... */ 2555 n = setup_neighbour(peer);
2543 GNUNET_break (0); 2556 if (NULL == n)
2544 goto cleanup; 2557 {
2558 /* not sure how this can happen... */
2559 GNUNET_break(0);
2560 goto cleanup;
2561 }
2562 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2545 } 2563 }
2546 n->state = GNUNET_TRANSPORT_PS_INIT_ATS;
2547 }
2548 2564
2549 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2565 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2550 "Peer `%s' switches to address `%s'\n", 2566 "Peer `%s' switches to address `%s'\n",
2551 GNUNET_i2s (&address->peer), 2567 GNUNET_i2s(&address->peer),
2552 GST_plugins_a2s (address)); 2568 GST_plugins_a2s(address));
2553 2569
2554 switch (n->state) 2570 switch (n->state)
2555 {
2556 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2557 GNUNET_break (0);
2558 GST_ats_block_address (address,
2559 session);
2560 free_neighbour (n);
2561 return;
2562 case GNUNET_TRANSPORT_PS_INIT_ATS:
2563 /* We requested an address and ATS suggests one:
2564 * set primary address and send SYN message*/
2565 set_primary_address (n,
2566 address,
2567 session,
2568 blc_ctx->bandwidth_in,
2569 blc_ctx->bandwidth_out);
2570 if (ACK_SEND_SYN_ACK == n->ack_state)
2571 {
2572 /* Send pending SYN_ACK message */
2573 n->ack_state = ACK_SEND_ACK;
2574 send_syn_ack_message (&n->primary_address,
2575 n->connect_ack_timestamp);
2576 }
2577 set_state_and_timeout (n,
2578 GNUNET_TRANSPORT_PS_SYN_SENT,
2579 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2580 send_syn (&n->primary_address);
2581 break;
2582 case GNUNET_TRANSPORT_PS_SYN_SENT:
2583 /* ATS suggested a new address while waiting for an SYN_ACK:
2584 * Switch and send new SYN */
2585 /* ATS suggests a different address, switch again */
2586 set_primary_address (n,
2587 address,
2588 session,
2589 blc_ctx->bandwidth_in,
2590 blc_ctx->bandwidth_out);
2591 if (ACK_SEND_SYN_ACK == n->ack_state)
2592 {
2593 /* Send pending SYN_ACK message */
2594 n->ack_state = ACK_SEND_ACK;
2595 send_syn_ack_message (&n->primary_address,
2596 n->connect_ack_timestamp);
2597 }
2598 set_state_and_timeout (n,
2599 GNUNET_TRANSPORT_PS_SYN_SENT,
2600 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2601 send_syn (&n->primary_address);
2602 break;
2603 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2604 /* We requested an address and ATS suggests one:
2605 * set primary address and send SYN_ACK message*/
2606 set_primary_address (n,
2607 address,
2608 session,
2609 blc_ctx->bandwidth_in,
2610 blc_ctx->bandwidth_out);
2611 /* Send an ACK message as a response to the SYN msg */
2612 set_state_and_timeout (n,
2613 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2614 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2615 send_syn_ack_message (&n->primary_address,
2616 n->connect_ack_timestamp);
2617 if ( (ACK_SEND_SYN_ACK == n->ack_state) ||
2618 (ACK_UNDEFINED == n->ack_state) )
2619 n->ack_state = ACK_SEND_ACK;
2620 break;
2621 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2622 /* ATS asks us to switch while we were trying to connect; switch to new
2623 address and check blacklist again */
2624 if ( (ACK_SEND_SYN_ACK == n->ack_state) )
2625 { 2571 {
2626 n->ack_state = ACK_SEND_ACK; 2572 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2627 send_syn_ack_message (&n->primary_address, 2573 GNUNET_break(0);
2628 n->connect_ack_timestamp); 2574 GST_ats_block_address(address,
2629 } 2575 session);
2630 set_primary_address (n, 2576 free_neighbour(n);
2631 address, 2577 return;
2632 session, 2578
2633 blc_ctx->bandwidth_in, 2579 case GNUNET_TRANSPORT_PS_INIT_ATS:
2634 blc_ctx->bandwidth_out); 2580 /* We requested an address and ATS suggests one:
2635 set_state_and_timeout (n, 2581 * set primary address and send SYN message*/
2636 GNUNET_TRANSPORT_PS_SYN_RECV_ACK, 2582 set_primary_address(n,
2637 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); 2583 address,
2638 break; 2584 session,
2639 case GNUNET_TRANSPORT_PS_CONNECTED: 2585 blc_ctx->bandwidth_in,
2640 GNUNET_assert (NULL != n->primary_address.address); 2586 blc_ctx->bandwidth_out);
2641 GNUNET_assert (NULL != n->primary_address.session); 2587 if (ACK_SEND_SYN_ACK == n->ack_state)
2642 GNUNET_break (n->primary_address.session != session); 2588 {
2643 /* ATS asks us to switch a life connection; see if we can get 2589 /* Send pending SYN_ACK message */
2644 a SYN_ACK on it before we actually do this! */ 2590 n->ack_state = ACK_SEND_ACK;
2645 set_alternative_address (n, 2591 send_syn_ack_message(&n->primary_address,
2646 address, 2592 n->connect_ack_timestamp);
2647 session, 2593 }
2648 blc_ctx->bandwidth_in, 2594 set_state_and_timeout(n,
2649 blc_ctx->bandwidth_out); 2595 GNUNET_TRANSPORT_PS_SYN_SENT,
2650 set_state_and_timeout (n, 2596 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2651 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT, 2597 send_syn(&n->primary_address);
2652 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT)); 2598 break;
2653 GNUNET_STATISTICS_update (GST_stats, 2599
2654 gettext_noop ("# Attempts to switch addresses"), 2600 case GNUNET_TRANSPORT_PS_SYN_SENT:
2655 1, 2601 /* ATS suggested a new address while waiting for an SYN_ACK:
2656 GNUNET_NO); 2602 * Switch and send new SYN */
2657 send_syn (&n->alternative_address); 2603 /* ATS suggests a different address, switch again */
2658 break; 2604 set_primary_address(n,
2659 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 2605 address,
2660 set_primary_address (n, 2606 session,
2661 address, 2607 blc_ctx->bandwidth_in,
2662 session, 2608 blc_ctx->bandwidth_out);
2663 blc_ctx->bandwidth_in, 2609 if (ACK_SEND_SYN_ACK == n->ack_state)
2664 blc_ctx->bandwidth_out); 2610 {
2665 if (ACK_SEND_SYN_ACK == n->ack_state) 2611 /* Send pending SYN_ACK message */
2666 { 2612 n->ack_state = ACK_SEND_ACK;
2667 /* Send pending SYN_ACK message */ 2613 send_syn_ack_message(&n->primary_address,
2668 n->ack_state = ACK_SEND_ACK; 2614 n->connect_ack_timestamp);
2669 send_syn_ack_message (&n->primary_address, 2615 }
2670 n->connect_ack_timestamp); 2616 set_state_and_timeout(n,
2671 } 2617 GNUNET_TRANSPORT_PS_SYN_SENT,
2672 set_state_and_timeout (n, 2618 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2673 GNUNET_TRANSPORT_PS_RECONNECT_SENT, 2619 send_syn(&n->primary_address);
2674 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 2620 break;
2675 send_syn (&n->primary_address); 2621
2676 break; 2622 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2677 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 2623 /* We requested an address and ATS suggests one:
2678 /* ATS asks us to switch while we were trying to reconnect; switch to new 2624 * set primary address and send SYN_ACK message*/
2679 address and send SYN again */ 2625 set_primary_address(n,
2680 set_primary_address (n, 2626 address,
2681 address, 2627 session,
2682 session, 2628 blc_ctx->bandwidth_in,
2683 blc_ctx->bandwidth_in, 2629 blc_ctx->bandwidth_out);
2684 blc_ctx->bandwidth_out); 2630 /* Send an ACK message as a response to the SYN msg */
2685 set_state_and_timeout (n, 2631 set_state_and_timeout(n,
2686 GNUNET_TRANSPORT_PS_RECONNECT_SENT, 2632 GNUNET_TRANSPORT_PS_SYN_RECV_ACK,
2687 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 2633 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
2688 send_syn (&n->primary_address); 2634 send_syn_ack_message(&n->primary_address,
2689 break; 2635 n->connect_ack_timestamp);
2690 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 2636 if ((ACK_SEND_SYN_ACK == n->ack_state) ||
2691 if ( (0 == GNUNET_HELLO_address_cmp (n->primary_address.address, 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,
2692 address)) && 2716 address)) &&
2693 (n->primary_address.session == session) ) 2717 (n->primary_address.session == session))
2694 { 2718 {
2695 /* ATS switches back to still-active session */ 2719 /* ATS switches back to still-active session */
2696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2720 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2697 "ATS double-switched, cleaning up alternative address\n"); 2721 "ATS double-switched, cleaning up alternative address\n");
2698 free_address (&n->alternative_address); 2722 free_address(&n->alternative_address);
2699 set_state_and_timeout (n, 2723 set_state_and_timeout(n,
2700 GNUNET_TRANSPORT_PS_CONNECTED, 2724 GNUNET_TRANSPORT_PS_CONNECTED,
2701 n->timeout); 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
2748 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2749 GNUNET_assert(0);
2750 break;
2751
2752 default:
2753 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2754 "Unhandled state `%s'\n",
2755 GNUNET_TRANSPORT_ps2s(n->state));
2756 GNUNET_break(0);
2702 break; 2757 break;
2703 } 2758 }
2704 /* ATS asks us to switch a life connection, send */ 2759cleanup:
2705 set_alternative_address (n, 2760 GNUNET_CONTAINER_DLL_remove(pending_bc_head,
2706 address, 2761 pending_bc_tail,
2707 session, 2762 blc_ctx);
2708 blc_ctx->bandwidth_in, 2763 GNUNET_free(blc_ctx);
2709 blc_ctx->bandwidth_out);
2710 set_state_and_timeout (n,
2711 GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT,
2712 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
2713 send_syn (&n->alternative_address);
2714 break;
2715 case GNUNET_TRANSPORT_PS_DISCONNECT:
2716 /* not going to switch addresses while disconnecting */
2717 GNUNET_STATISTICS_update (GST_stats,
2718 "# ATS suggestion ignored (disconnecting)",
2719 1,
2720 GNUNET_NO);
2721 return;
2722 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2723 GNUNET_assert (0);
2724 break;
2725 default:
2726 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2727 "Unhandled state `%s'\n",
2728 GNUNET_TRANSPORT_ps2s (n->state));
2729 GNUNET_break (0);
2730 break;
2731 }
2732 cleanup:
2733 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2734 pending_bc_tail,
2735 blc_ctx);
2736 GNUNET_free (blc_ctx);
2737} 2764}
2738 2765
2739 2766
@@ -2750,70 +2777,70 @@ switch_address_bl_check_cont (void *cls,
2750 * @param address address of the other peer, 2777 * @param address address of the other peer,
2751 * @param session session to use or NULL if transport should initiate a session 2778 * @param session session to use or NULL if transport should initiate a session
2752 * @param bandwidth_in inbound quota to be used when connection is up, 2779 * @param bandwidth_in inbound quota to be used when connection is up,
2753 * 0 to disconnect from peer 2780 * 0 to disconnect from peer
2754 * @param bandwidth_out outbound quota to be used when connection is up, 2781 * @param bandwidth_out outbound quota to be used when connection is up,
2755 * 0 to disconnect from peer 2782 * 0 to disconnect from peer
2756 */ 2783 */
2757void 2784void
2758GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, 2785GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address,
2759 struct GNUNET_ATS_Session *session, 2786 struct GNUNET_ATS_Session *session,
2760 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 2787 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
2761 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out) 2788 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out)
2762{ 2789{
2763 struct GST_BlacklistCheck *blc; 2790 struct GST_BlacklistCheck *blc;
2764 struct BlacklistCheckSwitchContext *blc_ctx; 2791 struct BlacklistCheckSwitchContext *blc_ctx;
2765 2792
2766 GNUNET_assert (NULL != address->transport_name); 2793 GNUNET_assert(NULL != address->transport_name);
2767 if (GNUNET_OK == 2794 if (GNUNET_OK ==
2768 try_run_fast_ats_update (address, 2795 try_run_fast_ats_update(address,
2769 session, 2796 session,
2770 bandwidth_in, 2797 bandwidth_in,
2771 bandwidth_out)) 2798 bandwidth_out))
2772 return; 2799 return;
2773 2800
2774 /* Check if plugin is available */ 2801 /* Check if plugin is available */
2775 if (NULL == (GST_plugins_find (address->transport_name))) 2802 if (NULL == (GST_plugins_find(address->transport_name)))
2776 { 2803 {
2777 /* we don't have the plugin for this address */ 2804 /* we don't have the plugin for this address */
2778 GNUNET_break (0); 2805 GNUNET_break(0);
2779 GST_ats_block_address (address, 2806 GST_ats_block_address(address,
2780 session); 2807 session);
2781 return; 2808 return;
2782 } 2809 }
2783 if ((NULL == session) && 2810 if ((NULL == session) &&
2784 (GNUNET_HELLO_address_check_option (address, 2811 (GNUNET_HELLO_address_check_option(address,
2785 GNUNET_HELLO_ADDRESS_INFO_INBOUND))) 2812 GNUNET_HELLO_ADDRESS_INFO_INBOUND)))
2786 { 2813 {
2787 /* This is a inbound address and we do not have a session to use! */ 2814 /* This is a inbound address and we do not have a session to use! */
2788 GNUNET_break (0); 2815 GNUNET_break(0);
2789 GST_ats_block_address (address, 2816 GST_ats_block_address(address,
2790 session); 2817 session);
2791 return; 2818 return;
2792 } 2819 }
2793 2820
2794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2821 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2795 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n", 2822 "ATS suggests address '%s' for peer `%s' at %u/%u speed\n",
2796 GST_plugins_a2s (address), 2823 GST_plugins_a2s(address),
2797 GNUNET_i2s (&address->peer), 2824 GNUNET_i2s(&address->peer),
2798 (unsigned int) ntohl (bandwidth_in.value__), 2825 (unsigned int)ntohl(bandwidth_in.value__),
2799 (unsigned int) ntohl (bandwidth_out.value__)); 2826 (unsigned int)ntohl(bandwidth_out.value__));
2800 2827
2801 /* Perform blacklist check */ 2828 /* Perform blacklist check */
2802 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext); 2829 blc_ctx = GNUNET_new(struct BlacklistCheckSwitchContext);
2803 blc_ctx->bandwidth_in = bandwidth_in; 2830 blc_ctx->bandwidth_in = bandwidth_in;
2804 blc_ctx->bandwidth_out = bandwidth_out; 2831 blc_ctx->bandwidth_out = bandwidth_out;
2805 GNUNET_CONTAINER_DLL_insert (pending_bc_head, 2832 GNUNET_CONTAINER_DLL_insert(pending_bc_head,
2806 pending_bc_tail, 2833 pending_bc_tail,
2807 blc_ctx); 2834 blc_ctx);
2808 if (NULL != (blc = GST_blacklist_test_allowed (&address->peer, 2835 if (NULL != (blc = GST_blacklist_test_allowed(&address->peer,
2809 address->transport_name, 2836 address->transport_name,
2810 &switch_address_bl_check_cont, 2837 &switch_address_bl_check_cont,
2811 blc_ctx, 2838 blc_ctx,
2812 address, 2839 address,
2813 session))) 2840 session)))
2814 { 2841 {
2815 blc_ctx->blc = blc; 2842 blc_ctx->blc = blc;
2816 } 2843 }
2817} 2844}
2818 2845
2819 2846
@@ -2827,39 +2854,39 @@ GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address,
2827 * @return #GNUNET_OK (continue to iterate) 2854 * @return #GNUNET_OK (continue to iterate)
2828 */ 2855 */
2829static int 2856static int
2830send_utilization_data (void *cls, 2857send_utilization_data(void *cls,
2831 const struct GNUNET_PeerIdentity *key, 2858 const struct GNUNET_PeerIdentity *key,
2832 void *value) 2859 void *value)
2833{ 2860{
2834 struct NeighbourMapEntry *n = value; 2861 struct NeighbourMapEntry *n = value;
2835 uint32_t bps_in; 2862 uint32_t bps_in;
2836 uint32_t bps_out; 2863 uint32_t bps_out;
2837 struct GNUNET_TIME_Relative delta; 2864 struct GNUNET_TIME_Relative delta;
2838 2865
2839 (void) cls; 2866 (void)cls;
2840 if ( (GNUNET_YES != test_connected (n)) || 2867 if ((GNUNET_YES != test_connected(n)) ||
2841 (NULL == n->primary_address.address) ) 2868 (NULL == n->primary_address.address))
2842 return GNUNET_OK; 2869 return GNUNET_OK;
2843 delta = GNUNET_TIME_absolute_get_difference (n->last_util_transmission, 2870 delta = GNUNET_TIME_absolute_get_difference(n->last_util_transmission,
2844 GNUNET_TIME_absolute_get ()); 2871 GNUNET_TIME_absolute_get());
2845 bps_in = 0; 2872 bps_in = 0;
2846 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us)) 2873 if ((0 != n->util_total_bytes_recv) && (0 != delta.rel_value_us))
2847 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) / (delta.rel_value_us); 2874 bps_in = (1000LL * 1000LL * n->util_total_bytes_recv) / (delta.rel_value_us);
2848 bps_out = 0; 2875 bps_out = 0;
2849 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us)) 2876 if ((0 != n->util_total_bytes_sent) && (0 != delta.rel_value_us))
2850 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us; 2877 bps_out = (1000LL * 1000LL * n->util_total_bytes_sent) / delta.rel_value_us;
2851 2878
2852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2879 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2853 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n", 2880 "`%s' total: received %u Bytes/s, sent %u Bytes/s\n",
2854 GNUNET_i2s (key), 2881 GNUNET_i2s(key),
2855 bps_in, 2882 bps_in,
2856 bps_out); 2883 bps_out);
2857 GST_ats_update_utilization (n->primary_address.address, 2884 GST_ats_update_utilization(n->primary_address.address,
2858 bps_in, 2885 bps_in,
2859 bps_out); 2886 bps_out);
2860 n->util_total_bytes_recv = 0; 2887 n->util_total_bytes_recv = 0;
2861 n->util_total_bytes_sent = 0; 2888 n->util_total_bytes_sent = 0;
2862 n->last_util_transmission = GNUNET_TIME_absolute_get (); 2889 n->last_util_transmission = GNUNET_TIME_absolute_get();
2863 return GNUNET_OK; 2890 return GNUNET_OK;
2864} 2891}
2865 2892
@@ -2870,17 +2897,17 @@ send_utilization_data (void *cls,
2870 * @param cls the `struct NeighbourMapEntry` for which we are running 2897 * @param cls the `struct NeighbourMapEntry` for which we are running
2871 */ 2898 */
2872static void 2899static void
2873utilization_transmission (void *cls) 2900utilization_transmission(void *cls)
2874{ 2901{
2875 (void) cls; 2902 (void)cls;
2876 util_transmission_tk = NULL; 2903 util_transmission_tk = NULL;
2877 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 2904 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
2878 &send_utilization_data, 2905 &send_utilization_data,
2879 NULL); 2906 NULL);
2880 util_transmission_tk 2907 util_transmission_tk
2881 = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, 2908 = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL,
2882 &utilization_transmission, 2909 &utilization_transmission,
2883 NULL); 2910 NULL);
2884} 2911}
2885 2912
2886 2913
@@ -2893,15 +2920,15 @@ utilization_transmission (void *cls)
2893 * @param message the message we received (really only the size is used) 2920 * @param message the message we received (really only the size is used)
2894 */ 2921 */
2895void 2922void
2896GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address, 2923GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address,
2897 const struct GNUNET_MessageHeader *message) 2924 const struct GNUNET_MessageHeader *message)
2898{ 2925{
2899 struct NeighbourMapEntry *n; 2926 struct NeighbourMapEntry *n;
2900 2927
2901 n = lookup_neighbour (&address->peer); 2928 n = lookup_neighbour(&address->peer);
2902 if (NULL == n) 2929 if (NULL == n)
2903 return; 2930 return;
2904 n->util_total_bytes_recv += ntohs (message->size); 2931 n->util_total_bytes_recv += ntohs(message->size);
2905} 2932}
2906 2933
2907 2934
@@ -2915,15 +2942,15 @@ GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address,
2915 * @param message the message we sent (really only the size is used) 2942 * @param message the message we sent (really only the size is used)
2916 */ 2943 */
2917void 2944void
2918GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address, 2945GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address,
2919 struct GNUNET_ATS_Session *session, 2946 struct GNUNET_ATS_Session *session,
2920 size_t size) 2947 size_t size)
2921{ 2948{
2922 struct NeighbourMapEntry *n; 2949 struct NeighbourMapEntry *n;
2923 2950
2924 n = lookup_neighbour (&address->peer); 2951 n = lookup_neighbour(&address->peer);
2925 if (NULL == n) 2952 if (NULL == n)
2926 return; 2953 return;
2927 if (n->primary_address.session != session) 2954 if (n->primary_address.session != session)
2928 return; 2955 return;
2929 n->util_total_bytes_sent += size; 2956 n->util_total_bytes_sent += size;
@@ -2938,146 +2965,157 @@ GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
2938 * @param cls the 'struct NeighbourMapEntry' for which we are running 2965 * @param cls the 'struct NeighbourMapEntry' for which we are running
2939 */ 2966 */
2940static void 2967static void
2941master_task (void *cls) 2968master_task(void *cls)
2942{ 2969{
2943 struct NeighbourMapEntry *n = cls; 2970 struct NeighbourMapEntry *n = cls;
2944 struct GNUNET_TIME_Relative delay; 2971 struct GNUNET_TIME_Relative delay;
2945 2972
2946 n->task = NULL; 2973 n->task = NULL;
2947 delay = GNUNET_TIME_absolute_get_remaining (n->timeout); 2974 delay = GNUNET_TIME_absolute_get_remaining(n->timeout);
2948 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2975 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2949 "Master task runs for neighbour `%s' in state %s with timeout in %s\n", 2976 "Master task runs for neighbour `%s' in state %s with timeout in %s\n",
2950 GNUNET_i2s (&n->id), 2977 GNUNET_i2s(&n->id),
2951 GNUNET_TRANSPORT_ps2s(n->state), 2978 GNUNET_TRANSPORT_ps2s(n->state),
2952 GNUNET_STRINGS_relative_time_to_string (delay, 2979 GNUNET_STRINGS_relative_time_to_string(delay,
2953 GNUNET_YES)); 2980 GNUNET_YES));
2954 switch (n->state) 2981 switch (n->state)
2955 {
2956 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2957 /* invalid state for master task, clean up */
2958 GNUNET_break (0);
2959 free_neighbour (n);
2960 return;
2961 case GNUNET_TRANSPORT_PS_INIT_ATS:
2962 if (0 == delay.rel_value_us)
2963 {
2964 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2965 "Connection to `%s' timed out waiting for ATS to provide address\n",
2966 GNUNET_i2s (&n->id));
2967 free_neighbour (n);
2968 return;
2969 }
2970 break;
2971 case GNUNET_TRANSPORT_PS_SYN_SENT:
2972 if (0 == delay.rel_value_us)
2973 { 2982 {
2974 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2983 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2975 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n", 2984 /* invalid state for master task, clean up */
2976 GNUNET_i2s (&n->id)); 2985 GNUNET_break(0);
2977 /* Remove address and request and additional one */ 2986 free_neighbour(n);
2978 unset_primary_address (n);
2979 set_state_and_timeout (n,
2980 GNUNET_TRANSPORT_PS_INIT_ATS,
2981 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2982 return; 2987 return;
2983 } 2988
2984 break; 2989 case GNUNET_TRANSPORT_PS_INIT_ATS:
2985 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 2990 if (0 == delay.rel_value_us)
2986 if (0 == delay.rel_value_us) 2991 {
2987 { 2992 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2988 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2993 "Connection to `%s' timed out waiting for ATS to provide address\n",
2989 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n", 2994 GNUNET_i2s(&n->id));
2990 GNUNET_i2s (&n->id)); 2995 free_neighbour(n);
2991 free_neighbour (n); 2996 return;
2992 return; 2997 }
2993 } 2998 break;
2994 break; 2999
2995 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 3000 case GNUNET_TRANSPORT_PS_SYN_SENT:
2996 if (0 == delay.rel_value_us) 3001 if (0 == delay.rel_value_us)
2997 { 3002 {
2998 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3003 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
2999 "Connection to `%s' timed out waiting for other peer to send ACK\n", 3004 "Connection to `%s' timed out waiting for other peer to send SYN_ACK\n",
3000 GNUNET_i2s (&n->id)); 3005 GNUNET_i2s(&n->id));
3001 disconnect_neighbour (n); 3006 /* Remove address and request and additional one */
3002 return; 3007 unset_primary_address(n);
3003 } 3008 set_state_and_timeout(n,
3004 break; 3009 GNUNET_TRANSPORT_PS_INIT_ATS,
3005 case GNUNET_TRANSPORT_PS_CONNECTED: 3010 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
3006 if (0 == delay.rel_value_us) 3011 return;
3007 { 3012 }
3008 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3013 break;
3009 "Connection to `%s' timed out, missing KEEPALIVE_RESPONSEs\n", 3014
3010 GNUNET_i2s (&n->id)); 3015 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3011 disconnect_neighbour (n); 3016 if (0 == delay.rel_value_us)
3012 return; 3017 {
3013 } 3018 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3014 try_transmission_to_peer (n); 3019 "Connection to `%s' timed out waiting ATS to provide address to use for SYN_ACK\n",
3015 send_keepalive (n); 3020 GNUNET_i2s(&n->id));
3016 break; 3021 free_neighbour(n);
3017 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3022 return;
3018 if (0 == delay.rel_value_us) 3023 }
3019 { 3024 break;
3020 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3025
3021 "Connection to `%s' timed out, waiting for ATS replacement address\n", 3026 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3022 GNUNET_i2s (&n->id)); 3027 if (0 == delay.rel_value_us)
3023 disconnect_neighbour (n); 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
3050 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3051 if (0 == delay.rel_value_us)
3052 {
3053 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3054 "Connection to `%s' timed out, waiting for ATS replacement address\n",
3055 GNUNET_i2s(&n->id));
3056 disconnect_neighbour(n);
3057 return;
3058 }
3059 break;
3060
3061 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3062 if (0 == delay.rel_value_us)
3063 {
3064 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3065 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n",
3066 GNUNET_i2s(&n->id));
3067 disconnect_neighbour(n);
3068 return;
3069 }
3070 break;
3071
3072 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3073 if (0 == delay.rel_value_us)
3074 {
3075 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3076 "Switch failed, cleaning up alternative address\n");
3077 free_address(&n->alternative_address);
3078 set_state_and_timeout(n,
3079 GNUNET_TRANSPORT_PS_CONNECTED,
3080 GNUNET_TIME_relative_to_absolute(SETUP_CONNECTION_TIMEOUT));
3081 }
3082 try_transmission_to_peer(n);
3083 send_keepalive(n);
3084 break;
3085
3086 case GNUNET_TRANSPORT_PS_DISCONNECT:
3087 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3088 "Cleaning up connection to `%s' after sending DISCONNECT\n",
3089 GNUNET_i2s(&n->id));
3090 free_neighbour(n);
3024 return; 3091 return;
3092
3093 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3094 /* how did we get here!? */
3095 GNUNET_assert(0);
3096 break;
3097
3098 default:
3099 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3100 "Unhandled state `%s'\n",
3101 GNUNET_TRANSPORT_ps2s(n->state));
3102 GNUNET_break(0);
3103 break;
3025 } 3104 }
3026 break; 3105 delay = GNUNET_TIME_absolute_get_remaining(n->timeout);
3027 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3106 if ((GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ||
3028 if (0 == delay.rel_value_us) 3107 (GNUNET_TRANSPORT_PS_CONNECTED == n->state))
3029 { 3108 {
3030 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3109 /* if we are *now* in one of the two states, we're sending
3031 "Connection to `%s' timed out, waiting for other peer to SYN_ACK replacement address\n", 3110 keep alive messages, so we need to consider the keepalive
3032 GNUNET_i2s (&n->id)); 3111 delay, not just the connection timeout */
3033 disconnect_neighbour (n); 3112 delay = GNUNET_TIME_relative_min(GNUNET_TIME_absolute_get_remaining(n->keep_alive_time),
3034 return; 3113 delay);
3035 } 3114 }
3036 break;
3037 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3038 if (0 == delay.rel_value_us)
3039 {
3040 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3041 "Switch failed, cleaning up alternative address\n");
3042 free_address (&n->alternative_address);
3043 set_state_and_timeout (n,
3044 GNUNET_TRANSPORT_PS_CONNECTED,
3045 GNUNET_TIME_relative_to_absolute (SETUP_CONNECTION_TIMEOUT));
3046 }
3047 try_transmission_to_peer (n);
3048 send_keepalive (n);
3049 break;
3050 case GNUNET_TRANSPORT_PS_DISCONNECT:
3051 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
3052 "Cleaning up connection to `%s' after sending DISCONNECT\n",
3053 GNUNET_i2s (&n->id));
3054 free_neighbour (n);
3055 return;
3056 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3057 /* how did we get here!? */
3058 GNUNET_assert (0);
3059 break;
3060 default:
3061 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3062 "Unhandled state `%s'\n",
3063 GNUNET_TRANSPORT_ps2s (n->state));
3064 GNUNET_break (0);
3065 break;
3066 }
3067 delay = GNUNET_TIME_absolute_get_remaining (n->timeout);
3068 if ( (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) ||
3069 (GNUNET_TRANSPORT_PS_CONNECTED == n->state) )
3070 {
3071 /* if we are *now* in one of the two states, we're sending
3072 keep alive messages, so we need to consider the keepalive
3073 delay, not just the connection timeout */
3074 delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time),
3075 delay);
3076 }
3077 if (NULL == n->task) 3115 if (NULL == n->task)
3078 n->task = GNUNET_SCHEDULER_add_delayed (delay, 3116 n->task = GNUNET_SCHEDULER_add_delayed(delay,
3079 &master_task, 3117 &master_task,
3080 n); 3118 n);
3081} 3119}
3082 3120
3083 3121
@@ -3088,23 +3126,23 @@ master_task (void *cls)
3088 * @param n neighbour to send the ACK to 3126 * @param n neighbour to send the ACK to
3089 */ 3127 */
3090static void 3128static void
3091send_session_ack_message (struct NeighbourMapEntry *n) 3129send_session_ack_message(struct NeighbourMapEntry *n)
3092{ 3130{
3093 struct GNUNET_MessageHeader msg; 3131 struct GNUNET_MessageHeader msg;
3094 3132
3095 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3133 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3096 "Sending ACK message to peer `%s'\n", 3134 "Sending ACK message to peer `%s'\n",
3097 GNUNET_i2s (&n->id)); 3135 GNUNET_i2s(&n->id));
3098 3136
3099 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 3137 msg.size = htons(sizeof(struct GNUNET_MessageHeader));
3100 msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK); 3138 msg.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK);
3101 (void) send_with_session (n, 3139 (void)send_with_session(n,
3102 &msg, 3140 &msg,
3103 sizeof (struct GNUNET_MessageHeader), 3141 sizeof(struct GNUNET_MessageHeader),
3104 UINT32_MAX, 3142 UINT32_MAX,
3105 GNUNET_TIME_UNIT_FOREVER_REL, 3143 GNUNET_TIME_UNIT_FOREVER_REL,
3106 GNUNET_NO, 3144 GNUNET_NO,
3107 NULL, NULL); 3145 NULL, NULL);
3108} 3146}
3109 3147
3110 3148
@@ -3120,135 +3158,145 @@ send_session_ack_message (struct NeighbourMapEntry *n)
3120 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 3158 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3121 */ 3159 */
3122int 3160int
3123GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message, 3161GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message,
3124 const struct GNUNET_HELLO_Address *address, 3162 const struct GNUNET_HELLO_Address *address,
3125 struct GNUNET_ATS_Session *session) 3163 struct GNUNET_ATS_Session *session)
3126{ 3164{
3127 const struct TransportSynMessage *scm; 3165 const struct TransportSynMessage *scm;
3128 struct GNUNET_TIME_Absolute ts; 3166 struct GNUNET_TIME_Absolute ts;
3129 struct NeighbourMapEntry *n; 3167 struct NeighbourMapEntry *n;
3130 3168
3131 (void) session; 3169 (void)session;
3132 if (ntohs (message->size) != sizeof (struct TransportSynMessage)) 3170 if (ntohs(message->size) != sizeof(struct TransportSynMessage))
3133 { 3171 {
3134 GNUNET_break_op (0); 3172 GNUNET_break_op(0);
3135 return GNUNET_SYSERR; 3173 return GNUNET_SYSERR;
3136 } 3174 }
3137 GNUNET_STATISTICS_update (GST_stats, 3175 GNUNET_STATISTICS_update(GST_stats,
3138 gettext_noop 3176 gettext_noop
3139 ("# SYN_ACK messages received"), 3177 ("# SYN_ACK messages received"),
3140 1, GNUNET_NO); 3178 1, GNUNET_NO);
3141 scm = (const struct TransportSynMessage *) message; 3179 scm = (const struct TransportSynMessage *)message;
3142 GNUNET_break_op (ntohl (scm->reserved) == 0); 3180 GNUNET_break_op(ntohl(scm->reserved) == 0);
3143 if (NULL == (n = lookup_neighbour (&address->peer))) 3181 if (NULL == (n = lookup_neighbour(&address->peer)))
3144 { 3182 {
3145 GNUNET_STATISTICS_update (GST_stats, 3183 GNUNET_STATISTICS_update(GST_stats,
3146 gettext_noop 3184 gettext_noop
3147 ("# unexpected SYN_ACK messages (no peer)"), 3185 ("# unexpected SYN_ACK messages (no peer)"),
3148 1, GNUNET_NO); 3186 1, GNUNET_NO);
3149 return GNUNET_SYSERR; 3187 return GNUNET_SYSERR;
3150 } 3188 }
3151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3152 "Received SYN_ACK message from peer `%s' in state %s/%s\n", 3190 "Received SYN_ACK message from peer `%s' in state %s/%s\n",
3153 GNUNET_i2s (&address->peer), 3191 GNUNET_i2s(&address->peer),
3154 GNUNET_TRANSPORT_ps2s (n->state), 3192 GNUNET_TRANSPORT_ps2s(n->state),
3155 print_ack_state (n->ack_state)); 3193 print_ack_state(n->ack_state));
3156 ts = GNUNET_TIME_absolute_ntoh (scm->timestamp); 3194 ts = GNUNET_TIME_absolute_ntoh(scm->timestamp);
3157 switch (n->state) 3195 switch (n->state)
3158 { 3196 {
3159 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3197 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3160 GNUNET_break (0); 3198 GNUNET_break(0);
3161 free_neighbour (n); 3199 free_neighbour(n);
3162 return GNUNET_SYSERR; 3200 return GNUNET_SYSERR;
3163 case GNUNET_TRANSPORT_PS_INIT_ATS: 3201
3164 GNUNET_STATISTICS_update (GST_stats, 3202 case GNUNET_TRANSPORT_PS_INIT_ATS:
3165 gettext_noop ("# unexpected SYN_ACK messages (not ready)"), 3203 GNUNET_STATISTICS_update(GST_stats,
3166 1, 3204 gettext_noop("# unexpected SYN_ACK messages (not ready)"),
3167 GNUNET_NO); 3205 1,
3168 break; 3206 GNUNET_NO);
3169 case GNUNET_TRANSPORT_PS_SYN_SENT: 3207 break;
3170 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us) 3208
3171 { 3209 case GNUNET_TRANSPORT_PS_SYN_SENT:
3172 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3210 if (ts.abs_value_us != n->primary_address.connect_timestamp.abs_value_us)
3173 "SYN_ACK ignored as the timestamp does not match our SYN request\n"); 3211 {
3174 return GNUNET_OK; 3212 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3213 "SYN_ACK ignored as the timestamp does not match our SYN request\n");
3214 return GNUNET_OK;
3215 }
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;
3175 } 3299 }
3176 set_state_and_timeout (n,
3177 GNUNET_TRANSPORT_PS_CONNECTED,
3178 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3179 set_primary_address (n,
3180 n->primary_address.address,
3181 n->primary_address.session,
3182 n->primary_address.bandwidth_in,
3183 n->primary_address.bandwidth_out);
3184 send_session_ack_message (n);
3185 break;
3186 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3187 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3188 GNUNET_STATISTICS_update (GST_stats,
3189 gettext_noop ("# unexpected SYN_ACK messages (not ready)"),
3190 1,
3191 GNUNET_NO);
3192 break;
3193 case GNUNET_TRANSPORT_PS_CONNECTED:
3194 /* duplicate SYN_ACK, let's answer by duplicate ACK just in case */
3195 send_session_ack_message (n);
3196 break;
3197 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3198 /* we didn't expect any SYN_ACK, as we are waiting for ATS
3199 to give us a new address... */
3200 GNUNET_STATISTICS_update (GST_stats,
3201 gettext_noop ("# unexpected SYN_ACK messages (waiting on ATS)"),
3202 1,
3203 GNUNET_NO);
3204 break;
3205 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3206 /* Reconnecting with new address address worked; go back to connected! */
3207 set_state_and_timeout (n,
3208 GNUNET_TRANSPORT_PS_CONNECTED,
3209 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3210 send_session_ack_message (n);
3211 break;
3212 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3213 /* new address worked; adopt it and go back to connected! */
3214 set_state_and_timeout (n,
3215 GNUNET_TRANSPORT_PS_CONNECTED,
3216 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3217 GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
3218
3219 /* Set primary addresses */
3220 set_primary_address (n,
3221 n->alternative_address.address,
3222 n->alternative_address.session,
3223 n->alternative_address.bandwidth_in,
3224 n->alternative_address.bandwidth_out);
3225 GNUNET_STATISTICS_update (GST_stats,
3226 gettext_noop ("# Successful attempts to switch addresses"),
3227 1,
3228 GNUNET_NO);
3229
3230 GNUNET_HELLO_address_free (n->alternative_address.address);
3231 memset (&n->alternative_address,
3232 0,
3233 sizeof (n->alternative_address));
3234 send_session_ack_message (n);
3235 break;
3236 case GNUNET_TRANSPORT_PS_DISCONNECT:
3237 GNUNET_STATISTICS_update (GST_stats,
3238 gettext_noop
3239 ("# unexpected SYN_ACK messages (disconnecting)"),
3240 1, GNUNET_NO);
3241 return GNUNET_SYSERR;
3242 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3243 GNUNET_assert (0);
3244 break;
3245 default:
3246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3247 "Unhandled state `%s'\n",
3248 GNUNET_TRANSPORT_ps2s (n->state));
3249 GNUNET_break (0);
3250 return GNUNET_SYSERR;
3251 }
3252 return GNUNET_OK; 3300 return GNUNET_OK;
3253} 3301}
3254 3302
@@ -3263,124 +3311,134 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
3263 * this session was not in use 3311 * this session was not in use
3264 */ 3312 */
3265int 3313int
3266GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, 3314GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer,
3267 struct GNUNET_ATS_Session *session) 3315 struct GNUNET_ATS_Session *session)
3268{ 3316{
3269 struct NeighbourMapEntry *n; 3317 struct NeighbourMapEntry *n;
3270 3318
3271 if (NULL == (n = lookup_neighbour (peer))) 3319 if (NULL == (n = lookup_neighbour(peer)))
3272 return GNUNET_NO; /* can't affect us */ 3320 return GNUNET_NO; /* can't affect us */
3273 if (session != n->primary_address.session) 3321 if (session != n->primary_address.session)
3274 {
3275 /* Free alternative address */
3276 if (session == n->alternative_address.session)
3277 { 3322 {
3278 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3323 /* Free alternative address */
3279 set_state_and_timeout (n, 3324 if (session == n->alternative_address.session)
3280 GNUNET_TRANSPORT_PS_CONNECTED, 3325 {
3281 n->timeout); 3326 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3282 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3327 set_state_and_timeout(n,
3283 "Session died, cleaning up alternative address\n"); 3328 GNUNET_TRANSPORT_PS_CONNECTED,
3284 free_address (&n->alternative_address); 3329 n->timeout);
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 */
3285 } 3335 }
3286 return GNUNET_NO; /* doesn't affect us further */
3287 }
3288 3336
3289 n->expect_latency_response = GNUNET_NO; 3337 n->expect_latency_response = GNUNET_NO;
3290 /* The session for neighbour's primary address died */ 3338 /* The session for neighbour's primary address died */
3291 switch (n->state) 3339 switch (n->state)
3292 { 3340 {
3293 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 3341 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
3294 GNUNET_break (0); 3342 GNUNET_break(0);
3295 free_neighbour (n); 3343 free_neighbour(n);
3296 return GNUNET_YES; 3344 return GNUNET_YES;
3297 case GNUNET_TRANSPORT_PS_INIT_ATS: 3345
3298 GNUNET_break (0); 3346 case GNUNET_TRANSPORT_PS_INIT_ATS:
3299 free_neighbour (n); 3347 GNUNET_break(0);
3300 return GNUNET_YES; 3348 free_neighbour(n);
3301 case GNUNET_TRANSPORT_PS_SYN_SENT: 3349 return GNUNET_YES;
3302 /* The session used to send the SYN terminated: 3350
3303 * this implies a connect error*/ 3351 case GNUNET_TRANSPORT_PS_SYN_SENT:
3304 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3352 /* The session used to send the SYN terminated:
3305 "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n", 3353 * this implies a connect error*/
3306 GST_plugins_a2s (n->primary_address.address), 3354 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3307 n->primary_address.session); 3355 "Failed to send SYN in CONNECT_SENT with `%s' %p: session terminated\n",
3308 3356 GST_plugins_a2s(n->primary_address.address),
3309 /* Destroy the address since it cannot be used */ 3357 n->primary_address.session);
3310 unset_primary_address (n); 3358
3311 set_state_and_timeout (n, 3359 /* Destroy the address since it cannot be used */
3312 GNUNET_TRANSPORT_PS_INIT_ATS, 3360 unset_primary_address(n);
3313 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3361 set_state_and_timeout(n,
3314 break; 3362 GNUNET_TRANSPORT_PS_INIT_ATS,
3315 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 3363 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
3316 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 3364 break;
3317 /* error on inbound session; free neighbour entirely */ 3365
3318 free_neighbour (n); 3366 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
3319 return GNUNET_YES; 3367 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
3320 case GNUNET_TRANSPORT_PS_CONNECTED: 3368 /* error on inbound session; free neighbour entirely */
3321 /* Our primary connection died, try a fast reconnect */ 3369 free_neighbour(n);
3322 unset_primary_address (n); 3370 return GNUNET_YES;
3323 set_state_and_timeout (n, 3371
3324 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3372 case GNUNET_TRANSPORT_PS_CONNECTED:
3325 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3373 /* Our primary connection died, try a fast reconnect */
3326 break; 3374 unset_primary_address(n);
3327 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 3375 set_state_and_timeout(n,
3328 /* we don't have an address, how can it go down? */ 3376 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3329 GNUNET_break (0); 3377 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
3330 break; 3378 break;
3331 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 3379
3332 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3380 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
3333 "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n", 3381 /* we don't have an address, how can it go down? */
3334 GST_plugins_a2s (n->primary_address.address), 3382 GNUNET_break(0);
3335 n->primary_address.session); 3383 break;
3336 /* Destroy the address since it cannot be used */ 3384
3337 unset_primary_address (n); 3385 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
3338 set_state_and_timeout (n, 3386 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3339 GNUNET_TRANSPORT_PS_RECONNECT_ATS, 3387 "Failed to send SYN in RECONNECT_SENT with `%s' %p: session terminated\n",
3340 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT)); 3388 GST_plugins_a2s(n->primary_address.address),
3341 break; 3389 n->primary_address.session);
3342 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 3390 /* Destroy the address since it cannot be used */
3343 /* primary went down while we were waiting for SYN_ACK on secondary; 3391 unset_primary_address(n);
3344 secondary as primary */ 3392 set_state_and_timeout(n,
3345 3393 GNUNET_TRANSPORT_PS_RECONNECT_ATS,
3346 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3394 GNUNET_TIME_relative_to_absolute(ATS_RESPONSE_TIMEOUT));
3347 "Connection `%s' %p to peer `%s' was terminated while switching, " 3395 break;
3348 "switching to alternative address `%s' %p\n", 3396
3349 GST_plugins_a2s (n->primary_address.address), 3397 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
3350 n->primary_address.session, 3398 /* primary went down while we were waiting for SYN_ACK on secondary;
3351 GNUNET_i2s (peer), 3399 secondary as primary */
3352 GST_plugins_a2s (n->alternative_address.address), 3400
3353 n->alternative_address.session); 3401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3354 3402 "Connection `%s' %p to peer `%s' was terminated while switching, "
3355 /* Destroy the inbound address since it cannot be used */ 3403 "switching to alternative address `%s' %p\n",
3356 free_address (&n->primary_address); 3404 GST_plugins_a2s(n->primary_address.address),
3357 n->primary_address = n->alternative_address; 3405 n->primary_address.session,
3358 GNUNET_assert (GNUNET_YES == 3406 GNUNET_i2s(peer),
3359 GST_ats_is_known (n->primary_address.address, 3407 GST_plugins_a2s(n->alternative_address.address),
3408 n->alternative_address.session);
3409
3410 /* Destroy the inbound address since it cannot be used */
3411 free_address(&n->primary_address);
3412 n->primary_address = n->alternative_address;
3413 GNUNET_assert(GNUNET_YES ==
3414 GST_ats_is_known(n->primary_address.address,
3360 n->primary_address.session)); 3415 n->primary_address.session));
3361 memset (&n->alternative_address, 3416 memset(&n->alternative_address,
3362 0, 3417 0,
3363 sizeof (struct NeighbourAddress)); 3418 sizeof(struct NeighbourAddress));
3364 set_state_and_timeout (n, 3419 set_state_and_timeout(n,
3365 GNUNET_TRANSPORT_PS_RECONNECT_SENT, 3420 GNUNET_TRANSPORT_PS_RECONNECT_SENT,
3366 GNUNET_TIME_relative_to_absolute (FAST_RECONNECT_TIMEOUT)); 3421 GNUNET_TIME_relative_to_absolute(FAST_RECONNECT_TIMEOUT));
3367 break; 3422 break;
3368 case GNUNET_TRANSPORT_PS_DISCONNECT: 3423
3369 unset_primary_address (n); 3424 case GNUNET_TRANSPORT_PS_DISCONNECT:
3370 break; 3425 unset_primary_address(n);
3371 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 3426 break;
3372 /* neighbour was freed and plugins told to terminate session */ 3427
3373 return GNUNET_NO; 3428 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
3374 default: 3429 /* neighbour was freed and plugins told to terminate session */
3375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3430 return GNUNET_NO;
3376 "Unhandled state `%s'\n", 3431
3377 GNUNET_TRANSPORT_ps2s (n->state)); 3432 default:
3378 GNUNET_break (0); 3433 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3379 break; 3434 "Unhandled state `%s'\n",
3380 } 3435 GNUNET_TRANSPORT_ps2s(n->state));
3436 GNUNET_break(0);
3437 break;
3438 }
3381 if (NULL != n->task) 3439 if (NULL != n->task)
3382 GNUNET_SCHEDULER_cancel (n->task); 3440 GNUNET_SCHEDULER_cancel(n->task);
3383 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 3441 n->task = GNUNET_SCHEDULER_add_now(&master_task, n);
3384 return GNUNET_YES; 3442 return GNUNET_YES;
3385} 3443}
3386 3444
@@ -3396,32 +3454,32 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
3396 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 3454 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
3397 */ 3455 */
3398int 3456int
3399GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, 3457GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
3400 const struct GNUNET_HELLO_Address *address, 3458 const struct GNUNET_HELLO_Address *address,
3401 struct GNUNET_ATS_Session *session) 3459 struct GNUNET_ATS_Session *session)
3402{ 3460{
3403 struct NeighbourMapEntry *n; 3461 struct NeighbourMapEntry *n;
3404 3462
3405 (void) session; 3463 (void)session;
3406 if (ntohs (message->size) != sizeof (struct GNUNET_MessageHeader)) 3464 if (ntohs(message->size) != sizeof(struct GNUNET_MessageHeader))
3407 { 3465 {
3408 GNUNET_break_op (0); 3466 GNUNET_break_op(0);
3409 return GNUNET_SYSERR; 3467 return GNUNET_SYSERR;
3410 } 3468 }
3411 GNUNET_STATISTICS_update (GST_stats, 3469 GNUNET_STATISTICS_update(GST_stats,
3412 gettext_noop ("# ACK messages received"), 3470 gettext_noop("# ACK messages received"),
3413 1, 3471 1,
3414 GNUNET_NO); 3472 GNUNET_NO);
3415 if (NULL == (n = lookup_neighbour (&address->peer))) 3473 if (NULL == (n = lookup_neighbour(&address->peer)))
3416 { 3474 {
3417 GNUNET_break_op (0); 3475 GNUNET_break_op(0);
3418 return GNUNET_SYSERR; 3476 return GNUNET_SYSERR;
3419 } 3477 }
3420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3478 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3421 "Received ACK for peer `%s' in state %s/%s\n", 3479 "Received ACK for peer `%s' in state %s/%s\n",
3422 GNUNET_i2s (&address->peer), 3480 GNUNET_i2s(&address->peer),
3423 GNUNET_TRANSPORT_ps2s (n->state), 3481 GNUNET_TRANSPORT_ps2s(n->state),
3424 print_ack_state (n->ack_state)); 3482 print_ack_state(n->ack_state));
3425 3483
3426 /* Check if we are in a plausible state for having sent 3484 /* Check if we are in a plausible state for having sent
3427 a SYN_ACK. If not, return, otherwise break. 3485 a SYN_ACK. If not, return, otherwise break.
@@ -3434,48 +3492,49 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3434 now wait for the ACK to finally be connected 3492 now wait for the ACK to finally be connected
3435 - If we sent a SYN_ACK to this peer before */ 3493 - If we sent a SYN_ACK to this peer before */
3436 3494
3437 if ( ( (GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) && 3495 if (((GNUNET_TRANSPORT_PS_SYN_RECV_ACK != n->state) &&
3438 (ACK_SEND_ACK != n->ack_state) ) || 3496 (ACK_SEND_ACK != n->ack_state)) ||
3439 (NULL == n->primary_address.address) ) 3497 (NULL == n->primary_address.address))
3440 { 3498 {
3441 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3499 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
3442 "Received unexpected ACK message from peer `%s' in state %s/%s\n", 3500 "Received unexpected ACK message from peer `%s' in state %s/%s\n",
3443 GNUNET_i2s (&address->peer), 3501 GNUNET_i2s(&address->peer),
3444 GNUNET_TRANSPORT_ps2s (n->state), 3502 GNUNET_TRANSPORT_ps2s(n->state),
3445 print_ack_state (n->ack_state)); 3503 print_ack_state(n->ack_state));
3446 3504
3447 GNUNET_STATISTICS_update (GST_stats, 3505 GNUNET_STATISTICS_update(GST_stats,
3448 gettext_noop ("# unexpected ACK messages"), 3506 gettext_noop("# unexpected ACK messages"),
3449 1, 3507 1,
3450 GNUNET_NO); 3508 GNUNET_NO);
3451 return GNUNET_OK; 3509 return GNUNET_OK;
3452 } 3510 }
3453 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state) 3511 if (GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT == n->state)
3454 { 3512 {
3455 /* We tried to switch addresses while being connect. We explicitly wait 3513 /* We tried to switch addresses while being connect. We explicitly wait
3456 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED, 3514 * for a SYN_ACK before going to GNUNET_TRANSPORT_PS_CONNECTED,
3457 * so we do not want to set the address as in use! */ 3515 * so we do not want to set the address as in use! */
3458 return GNUNET_OK; 3516 return GNUNET_OK;
3459 } 3517 }
3460 set_state_and_timeout (n, 3518 set_state_and_timeout(n,
3461 GNUNET_TRANSPORT_PS_CONNECTED, 3519 GNUNET_TRANSPORT_PS_CONNECTED,
3462 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT)); 3520 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT));
3463 3521
3464 if (NULL == n->primary_address.address) { 3522 if (NULL == n->primary_address.address)
3465 /* See issue #3693. 3523 {
3466 * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which 3524 /* See issue #3693.
3467 * really means we did try (and succeed) to send a SYN and are waiting for 3525 * We are in state = PSY_SYN_RECV_ACK or ack_state = ACK_SEND_ACK, which
3468 * an ACK. 3526 * really means we did try (and succeed) to send a SYN and are waiting for
3469 * That suggests that the primary_address used to be non-NULL, but maybe it 3527 * an ACK.
3470 * got reset to NULL without the state being changed appropriately? 3528 * That suggests that the primary_address used to be non-NULL, but maybe it
3471 */ 3529 * got reset to NULL without the state being changed appropriately?
3472 GNUNET_break (0); 3530 */
3473 return GNUNET_OK; 3531 GNUNET_break(0);
3474 } 3532 return GNUNET_OK;
3533 }
3475 3534
3476 /* Reset backoff for primary address */ 3535 /* Reset backoff for primary address */
3477 GST_ats_block_reset (n->primary_address.address, 3536 GST_ats_block_reset(n->primary_address.address,
3478 n->primary_address.session); 3537 n->primary_address.session);
3479 return GNUNET_OK; 3538 return GNUNET_OK;
3480} 3539}
3481 3540
@@ -3487,9 +3546,9 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
3487 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not 3546 * @return #GNUNET_YES if we are connected, #GNUNET_NO if not
3488 */ 3547 */
3489int 3548int
3490GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target) 3549GST_neighbours_test_connected(const struct GNUNET_PeerIdentity *target)
3491{ 3550{
3492 return test_connected (lookup_neighbour (target)); 3551 return test_connected(lookup_neighbour(target));
3493} 3552}
3494 3553
3495 3554
@@ -3499,15 +3558,15 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
3499 * @param cls the `struct NeighbourMapEntry` to free 3558 * @param cls the `struct NeighbourMapEntry` to free
3500 */ 3559 */
3501static void 3560static void
3502delayed_disconnect (void *cls) 3561delayed_disconnect(void *cls)
3503{ 3562{
3504 struct NeighbourMapEntry *n = cls; 3563 struct NeighbourMapEntry *n = cls;
3505 3564
3506 n->delayed_disconnect_task = NULL; 3565 n->delayed_disconnect_task = NULL;
3507 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3566 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3508 "Disconnecting by request from peer %s\n", 3567 "Disconnecting by request from peer %s\n",
3509 GNUNET_i2s (&n->id)); 3568 GNUNET_i2s(&n->id));
3510 free_neighbour (n); 3569 free_neighbour(n);
3511} 3570}
3512 3571
3513 3572
@@ -3519,42 +3578,42 @@ delayed_disconnect (void *cls)
3519 * @param msg the quota message 3578 * @param msg the quota message
3520 */ 3579 */
3521void 3580void
3522GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer, 3581GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer,
3523 const struct GNUNET_MessageHeader *msg) 3582 const struct GNUNET_MessageHeader *msg)
3524{ 3583{
3525 struct NeighbourMapEntry *n; 3584 struct NeighbourMapEntry *n;
3526 const struct GNUNET_ATS_SessionQuotaMessage *sqm; 3585 const struct GNUNET_ATS_SessionQuotaMessage *sqm;
3527 struct GNUNET_BANDWIDTH_Value32NBO last; 3586 struct GNUNET_BANDWIDTH_Value32NBO last;
3528 3587
3529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3588 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3530 "Received QUOTA message from peer `%s'\n", 3589 "Received QUOTA message from peer `%s'\n",
3531 GNUNET_i2s (peer)); 3590 GNUNET_i2s(peer));
3532 if (ntohs (msg->size) != sizeof (struct GNUNET_ATS_SessionQuotaMessage)) 3591 if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionQuotaMessage))
3533 { 3592 {
3534 GNUNET_break_op (0); 3593 GNUNET_break_op(0);
3535 GNUNET_STATISTICS_update (GST_stats, 3594 GNUNET_STATISTICS_update(GST_stats,
3536 gettext_noop ("# quota messages ignored (malformed)"), 3595 gettext_noop("# quota messages ignored (malformed)"),
3537 1, 3596 1,
3538 GNUNET_NO); 3597 GNUNET_NO);
3539 return; 3598 return;
3540 } 3599 }
3541 GNUNET_STATISTICS_update (GST_stats, 3600 GNUNET_STATISTICS_update(GST_stats,
3542 gettext_noop 3601 gettext_noop
3543 ("# QUOTA messages received"), 3602 ("# QUOTA messages received"),
3544 1, GNUNET_NO); 3603 1, GNUNET_NO);
3545 sqm = (const struct GNUNET_ATS_SessionQuotaMessage *) msg; 3604 sqm = (const struct GNUNET_ATS_SessionQuotaMessage *)msg;
3546 if (NULL == (n = lookup_neighbour (peer))) 3605 if (NULL == (n = lookup_neighbour(peer)))
3547 { 3606 {
3548 /* gone already */ 3607 /* gone already */
3549 return; 3608 return;
3550 } 3609 }
3551 last = GNUNET_BANDWIDTH_value_max (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 3610 last = GNUNET_BANDWIDTH_value_max(GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
3552 GNUNET_BANDWIDTH_value_init (ntohl (sqm->quota))); 3611 GNUNET_BANDWIDTH_value_init(ntohl(sqm->quota)));
3553 if (last.value__ != n->neighbour_receive_quota.value__) 3612 if (last.value__ != n->neighbour_receive_quota.value__)
3554 { 3613 {
3555 n->neighbour_receive_quota = last; 3614 n->neighbour_receive_quota = last;
3556 send_outbound_quota_to_clients (n); 3615 send_outbound_quota_to_clients(n);
3557 } 3616 }
3558} 3617}
3559 3618
3560 3619
@@ -3566,86 +3625,85 @@ GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
3566 * @param msg the disconnect message 3625 * @param msg the disconnect message
3567 */ 3626 */
3568void 3627void
3569GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, 3628GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer,
3570 const struct GNUNET_MessageHeader *msg) 3629 const struct GNUNET_MessageHeader *msg)
3571{ 3630{
3572 struct NeighbourMapEntry *n; 3631 struct NeighbourMapEntry *n;
3573 const struct GNUNET_ATS_SessionDisconnectMessage *sdm; 3632 const struct GNUNET_ATS_SessionDisconnectMessage *sdm;
3574 3633
3575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3634 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3576 "Received DISCONNECT message from peer `%s'\n", 3635 "Received DISCONNECT message from peer `%s'\n",
3577 GNUNET_i2s (peer)); 3636 GNUNET_i2s(peer));
3578 if (ntohs (msg->size) != sizeof (struct GNUNET_ATS_SessionDisconnectMessage)) 3637 if (ntohs(msg->size) != sizeof(struct GNUNET_ATS_SessionDisconnectMessage))
3579 { 3638 {
3580 GNUNET_break_op (0); 3639 GNUNET_break_op(0);
3581 GNUNET_STATISTICS_update (GST_stats, 3640 GNUNET_STATISTICS_update(GST_stats,
3582 gettext_noop 3641 gettext_noop
3583 ("# disconnect messages ignored (malformed)"), 3642 ("# disconnect messages ignored (malformed)"),
3584 1, 3643 1,
3585 GNUNET_NO); 3644 GNUNET_NO);
3586 return; 3645 return;
3587 } 3646 }
3588 GNUNET_STATISTICS_update (GST_stats, 3647 GNUNET_STATISTICS_update(GST_stats,
3589 gettext_noop 3648 gettext_noop
3590 ("# DISCONNECT messages received"), 3649 ("# DISCONNECT messages received"),
3591 1, GNUNET_NO); 3650 1, GNUNET_NO);
3592 sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *) msg; 3651 sdm = (const struct GNUNET_ATS_SessionDisconnectMessage *)msg;
3593 if (NULL == (n = lookup_neighbour (peer))) 3652 if (NULL == (n = lookup_neighbour(peer)))
3594 { 3653 {
3595 /* gone already */ 3654 /* gone already */
3596 return; 3655 return;
3597 } 3656 }
3598 if (GNUNET_TIME_absolute_ntoh (sdm->timestamp).abs_value_us <= n->connect_ack_timestamp.abs_value_us) 3657 if (GNUNET_TIME_absolute_ntoh(sdm->timestamp).abs_value_us <= n->connect_ack_timestamp.abs_value_us)
3599 { 3658 {
3600 GNUNET_STATISTICS_update (GST_stats, 3659 GNUNET_STATISTICS_update(GST_stats,
3601 gettext_noop ("# disconnect messages ignored (timestamp)"), 3660 gettext_noop("# disconnect messages ignored (timestamp)"),
3602 1, 3661 1,
3603 GNUNET_NO); 3662 GNUNET_NO);
3604 return; 3663 return;
3605 } 3664 }
3606 if (0 != memcmp (peer, 3665 if (0 != memcmp(peer,
3607 &sdm->public_key, 3666 &sdm->public_key,
3608 sizeof (struct GNUNET_PeerIdentity))) 3667 sizeof(struct GNUNET_PeerIdentity)))
3609 { 3668 {
3610 GNUNET_break_op (0); 3669 GNUNET_break_op(0);
3611 return; 3670 return;
3612 } 3671 }
3613 if (ntohl (sdm->purpose.size) != 3672 if (ntohl(sdm->purpose.size) !=
3614 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 3673 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
3615 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + 3674 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) +
3616 sizeof (struct GNUNET_TIME_AbsoluteNBO)) 3675 sizeof(struct GNUNET_TIME_AbsoluteNBO))
3617 { 3676 {
3618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3677 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3619 "DISCONNECT message from peer `%s' has invalid size\n", 3678 "DISCONNECT message from peer `%s' has invalid size\n",
3620 GNUNET_i2s (peer)); 3679 GNUNET_i2s(peer));
3621 GNUNET_break_op (0); 3680 GNUNET_break_op(0);
3622 return; 3681 return;
3623 } 3682 }
3624 if (GNUNET_OK != 3683 if (GNUNET_OK !=
3625 GNUNET_CRYPTO_eddsa_verify (GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT, 3684 GNUNET_CRYPTO_eddsa_verify(GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT,
3626 &sdm->purpose, 3685 &sdm->purpose,
3627 &sdm->signature, 3686 &sdm->signature,
3628 &sdm->public_key)) 3687 &sdm->public_key))
3629 { 3688 {
3630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3689 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3631 "DISCONNECT message from peer `%s' cannot be verified \n", 3690 "DISCONNECT message from peer `%s' cannot be verified \n",
3632 GNUNET_i2s (peer)); 3691 GNUNET_i2s(peer));
3633 GNUNET_break_op (0); 3692 GNUNET_break_op(0);
3634 return; 3693 return;
3635 } 3694 }
3636 if (NULL == n->delayed_disconnect_task) 3695 if (NULL == n->delayed_disconnect_task)
3637 { 3696 {
3638 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now (&delayed_disconnect, 3697 n->delayed_disconnect_task = GNUNET_SCHEDULER_add_now(&delayed_disconnect,
3639 n); 3698 n);
3640 } 3699 }
3641} 3700}
3642 3701
3643 3702
3644/** 3703/**
3645 * Closure for the #neighbours_iterate() function. 3704 * Closure for the #neighbours_iterate() function.
3646 */ 3705 */
3647struct IteratorContext 3706struct IteratorContext {
3648{
3649 /** 3707 /**
3650 * Function to call on each connected neighbour. 3708 * Function to call on each connected neighbour.
3651 */ 3709 */
@@ -3667,32 +3725,32 @@ struct IteratorContext
3667 * @return #GNUNET_OK (continue to iterate) 3725 * @return #GNUNET_OK (continue to iterate)
3668 */ 3726 */
3669static int 3727static int
3670neighbours_iterate (void *cls, 3728neighbours_iterate(void *cls,
3671 const struct GNUNET_PeerIdentity *key, 3729 const struct GNUNET_PeerIdentity *key,
3672 void *value) 3730 void *value)
3673{ 3731{
3674 struct IteratorContext *ic = cls; 3732 struct IteratorContext *ic = cls;
3675 struct NeighbourMapEntry *n = value; 3733 struct NeighbourMapEntry *n = value;
3676 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in; 3734 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in;
3677 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out; 3735 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out;
3678 3736
3679 (void) key; 3737 (void)key;
3680 if (NULL != n->primary_address.address) 3738 if (NULL != n->primary_address.address)
3681 { 3739 {
3682 bandwidth_in = n->primary_address.bandwidth_in; 3740 bandwidth_in = n->primary_address.bandwidth_in;
3683 bandwidth_out = n->primary_address.bandwidth_out; 3741 bandwidth_out = n->primary_address.bandwidth_out;
3684 } 3742 }
3685 else 3743 else
3686 { 3744 {
3687 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3745 bandwidth_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3688 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; 3746 bandwidth_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT;
3689 } 3747 }
3690 ic->cb (ic->cb_cls, 3748 ic->cb(ic->cb_cls,
3691 &n->id, 3749 &n->id,
3692 n->primary_address.address, 3750 n->primary_address.address,
3693 n->state, 3751 n->state,
3694 n->timeout, 3752 n->timeout,
3695 bandwidth_in, bandwidth_out); 3753 bandwidth_in, bandwidth_out);
3696 return GNUNET_OK; 3754 return GNUNET_OK;
3697} 3755}
3698 3756
@@ -3704,8 +3762,8 @@ neighbours_iterate (void *cls,
3704 * @param cb_cls closure for @a cb 3762 * @param cb_cls closure for @a cb
3705 */ 3763 */
3706void 3764void
3707GST_neighbours_iterate (GST_NeighbourIterator cb, 3765GST_neighbours_iterate(GST_NeighbourIterator cb,
3708 void *cb_cls) 3766 void *cb_cls)
3709{ 3767{
3710 struct IteratorContext ic; 3768 struct IteratorContext ic;
3711 3769
@@ -3713,9 +3771,9 @@ GST_neighbours_iterate (GST_NeighbourIterator cb,
3713 return; /* can happen during shutdown */ 3771 return; /* can happen during shutdown */
3714 ic.cb = cb; 3772 ic.cb = cb;
3715 ic.cb_cls = cb_cls; 3773 ic.cb_cls = cb_cls;
3716 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 3774 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
3717 &neighbours_iterate, 3775 &neighbours_iterate,
3718 &ic); 3776 &ic);
3719} 3777}
3720 3778
3721 3779
@@ -3725,21 +3783,21 @@ GST_neighbours_iterate (GST_NeighbourIterator cb,
3725 * @param target peer to disconnect from 3783 * @param target peer to disconnect from
3726 */ 3784 */
3727void 3785void
3728GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target) 3786GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target)
3729{ 3787{
3730 struct NeighbourMapEntry *n; 3788 struct NeighbourMapEntry *n;
3731 3789
3732 if (NULL == (n = lookup_neighbour (target))) 3790 if (NULL == (n = lookup_neighbour(target)))
3733 return; /* not active */ 3791 return; /* not active */
3734 if (GNUNET_YES == test_connected (n)) 3792 if (GNUNET_YES == test_connected(n))
3735 GNUNET_STATISTICS_update (GST_stats, 3793 GNUNET_STATISTICS_update(GST_stats,
3736 gettext_noop ("# disconnected from peer upon explicit request"), 3794 gettext_noop("# disconnected from peer upon explicit request"),
3737 1, 3795 1,
3738 GNUNET_NO); 3796 GNUNET_NO);
3739 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3797 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
3740 "Forced disconnect from peer %s\n", 3798 "Forced disconnect from peer %s\n",
3741 GNUNET_i2s (target)); 3799 GNUNET_i2s(target));
3742 disconnect_neighbour (n); 3800 disconnect_neighbour(n);
3743} 3801}
3744 3802
3745 3803
@@ -3750,11 +3808,11 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
3750 * @return address currently used 3808 * @return address currently used
3751 */ 3809 */
3752const struct GNUNET_HELLO_Address * 3810const struct GNUNET_HELLO_Address *
3753GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer) 3811GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer)
3754{ 3812{
3755 struct NeighbourMapEntry *n; 3813 struct NeighbourMapEntry *n;
3756 3814
3757 n = lookup_neighbour (peer); 3815 n = lookup_neighbour(peer);
3758 if (NULL == n) 3816 if (NULL == n)
3759 return NULL; 3817 return NULL;
3760 return n->primary_address.address; 3818 return n->primary_address.address;
@@ -3767,14 +3825,14 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer)
3767 * @param max_fds maximum number of fds to use 3825 * @param max_fds maximum number of fds to use
3768 */ 3826 */
3769void 3827void
3770GST_neighbours_start (unsigned int max_fds) 3828GST_neighbours_start(unsigned int max_fds)
3771{ 3829{
3772 (void) max_fds; 3830 (void)max_fds;
3773 neighbours = GNUNET_CONTAINER_multipeermap_create (NEIGHBOUR_TABLE_SIZE, 3831 neighbours = GNUNET_CONTAINER_multipeermap_create(NEIGHBOUR_TABLE_SIZE,
3774 GNUNET_NO); 3832 GNUNET_NO);
3775 util_transmission_tk = GNUNET_SCHEDULER_add_delayed (UTIL_TRANSMISSION_INTERVAL, 3833 util_transmission_tk = GNUNET_SCHEDULER_add_delayed(UTIL_TRANSMISSION_INTERVAL,
3776 &utilization_transmission, 3834 &utilization_transmission,
3777 NULL); 3835 NULL);
3778} 3836}
3779 3837
3780 3838
@@ -3787,18 +3845,18 @@ GST_neighbours_start (unsigned int max_fds)
3787 * @return #GNUNET_OK (continue to iterate) 3845 * @return #GNUNET_OK (continue to iterate)
3788 */ 3846 */
3789static int 3847static int
3790disconnect_all_neighbours (void *cls, 3848disconnect_all_neighbours(void *cls,
3791 const struct GNUNET_PeerIdentity *key, 3849 const struct GNUNET_PeerIdentity *key,
3792 void *value) 3850 void *value)
3793{ 3851{
3794 struct NeighbourMapEntry *n = value; 3852 struct NeighbourMapEntry *n = value;
3795 3853
3796 (void) cls; 3854 (void)cls;
3797 (void) key; 3855 (void)key;
3798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3856 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
3799 "Disconnecting peer `%4s' during shutdown\n", 3857 "Disconnecting peer `%4s' during shutdown\n",
3800 GNUNET_i2s (&n->id)); 3858 GNUNET_i2s(&n->id));
3801 free_neighbour (n); 3859 free_neighbour(n);
3802 return GNUNET_OK; 3860 return GNUNET_OK;
3803} 3861}
3804 3862
@@ -3807,19 +3865,19 @@ disconnect_all_neighbours (void *cls,
3807 * Cleanup the neighbours subsystem. 3865 * Cleanup the neighbours subsystem.
3808 */ 3866 */
3809void 3867void
3810GST_neighbours_stop () 3868GST_neighbours_stop()
3811{ 3869{
3812 if (NULL == neighbours) 3870 if (NULL == neighbours)
3813 return; 3871 return;
3814 if (NULL != util_transmission_tk) 3872 if (NULL != util_transmission_tk)
3815 { 3873 {
3816 GNUNET_SCHEDULER_cancel (util_transmission_tk); 3874 GNUNET_SCHEDULER_cancel(util_transmission_tk);
3817 util_transmission_tk = NULL; 3875 util_transmission_tk = NULL;
3818 } 3876 }
3819 GNUNET_CONTAINER_multipeermap_iterate (neighbours, 3877 GNUNET_CONTAINER_multipeermap_iterate(neighbours,
3820 &disconnect_all_neighbours, 3878 &disconnect_all_neighbours,
3821 NULL); 3879 NULL);
3822 GNUNET_CONTAINER_multipeermap_destroy (neighbours); 3880 GNUNET_CONTAINER_multipeermap_destroy(neighbours);
3823 neighbours = NULL; 3881 neighbours = NULL;
3824} 3882}
3825 3883
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index 92ad62be9..2ce149cf3 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_neighbours.h 22 * @file 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,9 @@ 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 GNUNET_PeerIdentity *sender,
109 ssize_t size, 109 ssize_t size,
110 int *do_forward); 110 int *do_forward);
111 111
112 112
113/** 113/**
@@ -118,8 +118,8 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
118 * @param m the keep alive message containing the nonce to respond to 118 * @param m the keep alive message containing the nonce to respond to
119 */ 119 */
120void 120void
121GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour, 121GST_neighbours_keepalive(const struct GNUNET_PeerIdentity *neighbour,
122 const struct GNUNET_MessageHeader *m); 122 const struct GNUNET_MessageHeader *m);
123 123
124 124
125/** 125/**
@@ -131,8 +131,8 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour,
131 * @param m the message containing the keep alive response 131 * @param m the message containing the keep alive response
132 */ 132 */
133void 133void
134GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour, 134GST_neighbours_keepalive_response(const struct GNUNET_PeerIdentity *neighbour,
135 const struct GNUNET_MessageHeader *m); 135 const struct GNUNET_MessageHeader *m);
136 136
137 137
138/** 138/**
@@ -141,7 +141,7 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
141 * @param target peer to disconnect from 141 * @param target peer to disconnect from
142 */ 142 */
143void 143void
144GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target); 144GST_neighbours_force_disconnect(const struct GNUNET_PeerIdentity *target);
145 145
146 146
147/** 147/**
@@ -172,7 +172,7 @@ typedef void
172 * @param cb_cls closure for @a cb 172 * @param cb_cls closure for @a cb
173 */ 173 */
174void 174void
175GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls); 175GST_neighbours_iterate(GST_NeighbourIterator cb, void *cb_cls);
176 176
177 177
178/** 178/**
@@ -184,8 +184,8 @@ GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
184 * this session was not in use 184 * this session was not in use
185 */ 185 */
186int 186int
187GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, 187GST_neighbours_session_terminated(const struct GNUNET_PeerIdentity *peer,
188 struct GNUNET_ATS_Session *session); 188 struct GNUNET_ATS_Session *session);
189 189
190 190
191/** 191/**
@@ -197,8 +197,8 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
197 * @param message the message we received (really only the size is used) 197 * @param message the message we received (really only the size is used)
198 */ 198 */
199void 199void
200GST_neighbours_notify_data_recv (const struct GNUNET_HELLO_Address *address, 200GST_neighbours_notify_data_recv(const struct GNUNET_HELLO_Address *address,
201 const struct GNUNET_MessageHeader *message); 201 const struct GNUNET_MessageHeader *message);
202 202
203 203
204/** 204/**
@@ -211,9 +211,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) 211 * @param message the message we sent (really only the size is used)
212 */ 212 */
213void 213void
214GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address, 214GST_neighbours_notify_data_sent(const struct GNUNET_HELLO_Address *address,
215 struct GNUNET_ATS_Session *session, 215 struct GNUNET_ATS_Session *session,
216 size_t size); 216 size_t size);
217 217
218 218
219/** 219/**
@@ -226,10 +226,10 @@ GST_neighbours_notify_data_sent (const struct GNUNET_HELLO_Address *address,
226 * @param bandwidth_out outbound quota to be used when connection is up 226 * @param bandwidth_out outbound quota to be used when connection is up
227 */ 227 */
228void 228void
229GST_neighbours_switch_to_address (const struct GNUNET_HELLO_Address *address, 229GST_neighbours_switch_to_address(const struct GNUNET_HELLO_Address *address,
230 struct GNUNET_ATS_Session *session, 230 struct GNUNET_ATS_Session *session,
231 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 231 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
232 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); 232 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out);
233 233
234 234
235/** 235/**
@@ -241,8 +241,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 241 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
242 */ 242 */
243int 243int
244GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message, 244GST_neighbours_handle_session_syn(const struct GNUNET_MessageHeader *message,
245 const struct GNUNET_PeerIdentity *peer); 245 const struct GNUNET_PeerIdentity *peer);
246 246
247 247
248/** 248/**
@@ -255,9 +255,9 @@ GST_neighbours_handle_session_syn (const struct GNUNET_MessageHeader *message,
255 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 255 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
256 */ 256 */
257int 257int
258GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *message, 258GST_neighbours_handle_session_syn_ack(const struct GNUNET_MessageHeader *message,
259 const struct GNUNET_HELLO_Address *address, 259 const struct GNUNET_HELLO_Address *address,
260 struct GNUNET_ATS_Session *session); 260 struct GNUNET_ATS_Session *session);
261 261
262 262
263/** 263/**
@@ -271,9 +271,9 @@ GST_neighbours_handle_session_syn_ack (const struct GNUNET_MessageHeader *messag
271 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 271 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
272 */ 272 */
273int 273int
274GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message, 274GST_neighbours_handle_session_ack(const struct GNUNET_MessageHeader *message,
275 const struct GNUNET_HELLO_Address *address, 275 const struct GNUNET_HELLO_Address *address,
276 struct GNUNET_ATS_Session *session); 276 struct GNUNET_ATS_Session *session);
277 277
278 278
279/** 279/**
@@ -283,7 +283,7 @@ GST_neighbours_handle_session_ack (const struct GNUNET_MessageHeader *message,
283 * @return address currently used 283 * @return address currently used
284 */ 284 */
285const struct GNUNET_HELLO_Address * 285const struct GNUNET_HELLO_Address *
286GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer); 286GST_neighbour_get_current_address(const struct GNUNET_PeerIdentity *peer);
287 287
288 288
289/** 289/**
@@ -294,8 +294,8 @@ GST_neighbour_get_current_address (const struct GNUNET_PeerIdentity *peer);
294 * @param msg the quota message 294 * @param msg the quota message
295 */ 295 */
296void 296void
297GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer, 297GST_neighbours_handle_quota_message(const struct GNUNET_PeerIdentity *peer,
298 const struct GNUNET_MessageHeader *msg); 298 const struct GNUNET_MessageHeader *msg);
299 299
300 300
301/** 301/**
@@ -306,8 +306,8 @@ GST_neighbours_handle_quota_message (const struct GNUNET_PeerIdentity *peer,
306 * @param msg the disconnect message 306 * @param msg the disconnect message
307 */ 307 */
308void 308void
309GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, 309GST_neighbours_handle_disconnect_message(const struct GNUNET_PeerIdentity *peer,
310 const struct GNUNET_MessageHeader *msg); 310 const struct GNUNET_MessageHeader *msg);
311 311
312 312
313#endif 313#endif
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index c6c5e0444..b9203f9f4 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2010-2014 GNUnet e.V. 3 Copyright (C) 2010-2014 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_plugins.c 22 * @file transport/gnunet-service-transport_plugins.c
@@ -32,8 +32,7 @@
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{
37 /** 36 /**
38 * This is a doubly-linked list. 37 * This is a doubly-linked list.
39 */ 38 */
@@ -65,7 +64,6 @@ struct TransportPlugin
65 * for this plugin. 64 * for this plugin.
66 */ 65 */
67 struct GNUNET_TRANSPORT_PluginEnvironment env; 66 struct GNUNET_TRANSPORT_PluginEnvironment env;
68
69}; 67};
70 68
71/** 69/**
@@ -88,12 +86,12 @@ static struct TransportPlugin *plugins_tail;
88 * @param distance new distance 86 * @param distance new distance
89 */ 87 */
90static void 88static void
91plugin_env_update_distance (void *cls, 89plugin_env_update_distance(void *cls,
92 const struct GNUNET_HELLO_Address *address, 90 const struct GNUNET_HELLO_Address *address,
93 uint32_t distance) 91 uint32_t distance)
94{ 92{
95 GST_ats_update_distance (address, 93 GST_ats_update_distance(address,
96 distance); 94 distance);
97} 95}
98 96
99 97
@@ -107,18 +105,18 @@ plugin_env_update_distance (void *cls,
107 * @return type of the network @a addr belongs to 105 * @return type of the network @a addr belongs to
108 */ 106 */
109static enum GNUNET_NetworkType 107static enum GNUNET_NetworkType
110plugin_env_address_to_type (void *cls, 108plugin_env_address_to_type(void *cls,
111 const struct sockaddr *addr, 109 const struct sockaddr *addr,
112 size_t addrlen) 110 size_t addrlen)
113{ 111{
114 if (NULL == GST_is) 112 if (NULL == GST_is)
115 { 113 {
116 GNUNET_break(0); 114 GNUNET_break(0);
117 return GNUNET_NT_UNSPECIFIED; 115 return GNUNET_NT_UNSPECIFIED;
118 } 116 }
119 return GNUNET_NT_scanner_get_type (GST_is, 117 return GNUNET_NT_scanner_get_type(GST_is,
120 addr, 118 addr,
121 addrlen); 119 addrlen);
122} 120}
123 121
124 122
@@ -135,10 +133,10 @@ plugin_env_address_to_type (void *cls,
135 * @param address_type_cb function to call when a address type is requested 133 * @param address_type_cb function to call when a address type is requested
136 */ 134 */
137void 135void
138GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 136GST_plugins_load(GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
139 GNUNET_TRANSPORT_AddressNotification address_cb, 137 GNUNET_TRANSPORT_AddressNotification address_cb,
140 GNUNET_TRANSPORT_SessionStart session_start_cb, 138 GNUNET_TRANSPORT_SessionStart session_start_cb,
141 GNUNET_TRANSPORT_SessionEnd session_end_cb) 139 GNUNET_TRANSPORT_SessionEnd session_end_cb)
142{ 140{
143 struct TransportPlugin *plug; 141 struct TransportPlugin *plug;
144 struct TransportPlugin *next; 142 struct TransportPlugin *next;
@@ -149,175 +147,175 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
149 int fail; 147 int fail;
150 148
151 if (GNUNET_OK != 149 if (GNUNET_OK !=
152 GNUNET_CONFIGURATION_get_value_number (GST_cfg, 150 GNUNET_CONFIGURATION_get_value_number(GST_cfg,
153 "TRANSPORT", 151 "TRANSPORT",
154 "NEIGHBOUR_LIMIT", 152 "NEIGHBOUR_LIMIT",
155 &tneigh)) 153 &tneigh))
156 {
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
159 return;
160 }
161 if (GNUNET_OK !=
162 GNUNET_CONFIGURATION_get_value_string (GST_cfg,
163 "TRANSPORT",
164 "PLUGINS",
165 &plugs))
166 return;
167 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
168 _("Starting transport plugins `%s'\n"),
169 plugs);
170 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
171 {
172 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
173 _("Loading `%s' transport plugin\n"),
174 pos);
175 GNUNET_asprintf (&libname,
176 "libgnunet_plugin_transport_%s",
177 pos);
178 plug = GNUNET_new (struct TransportPlugin);
179 plug->short_name = GNUNET_strdup (pos);
180 plug->lib_name = libname;
181 plug->env.cfg = GST_cfg;
182 plug->env.my_identity = &GST_my_identity;
183 plug->env.get_our_hello = &GST_hello_get;
184 plug->env.cls = plug->short_name;
185 plug->env.receive = recv_cb;
186 plug->env.notify_address = address_cb;
187 plug->env.session_start = session_start_cb;
188 plug->env.session_end = session_end_cb;
189 plug->env.get_address_type = &plugin_env_address_to_type;
190 plug->env.update_address_distance = &plugin_env_update_distance;
191 plug->env.max_connections = tneigh;
192 plug->env.stats = GST_stats;
193 GNUNET_CONTAINER_DLL_insert (plugins_head,
194 plugins_tail,
195 plug);
196 }
197 GNUNET_free (plugs);
198 next = plugins_head;
199 while (NULL != next)
200 {
201 plug = next;
202 next = plug->next;
203 plug->api = GNUNET_PLUGIN_load (plug->lib_name,
204 &plug->env);
205 if (NULL == plug->api)
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
208 _("Failed to load transport plugin for `%s'\n"),
209 plug->lib_name);
210 GNUNET_CONTAINER_DLL_remove (plugins_head,
211 plugins_tail,
212 plug);
213 GNUNET_free (plug->short_name);
214 GNUNET_free (plug->lib_name);
215 GNUNET_free (plug);
216 continue;
217 }
218 fail = GNUNET_NO;
219 if (NULL == plug->api->address_pretty_printer)
220 {
221 fail = GNUNET_YES;
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
223 _("Missing function `%s' in transport plugin for `%s'\n"),
224 "address_pretty_printer",
225 plug->lib_name);
226 }
227 if (NULL == plug->api->address_to_string)
228 {
229 fail = GNUNET_YES;
230 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
231 _("Missing function `%s' in transport plugin for `%s'\n"),
232 "address_to_string",
233 plug->lib_name);
234 }
235 if (NULL == plug->api->string_to_address)
236 {
237 fail = GNUNET_YES;
238 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
239 _("Missing function `%s' in transport plugin for `%s'\n"),
240 "string_to_address",
241 plug->lib_name);
242 }
243 if (NULL == plug->api->check_address)
244 {
245 fail = GNUNET_YES;
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
247 _("Missing function `%s' in transport plugin for `%s'\n"),
248 "check_address",
249 plug->lib_name);
250 }
251 if (NULL == plug->api->get_session)
252 {
253 fail = GNUNET_YES;
254 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
255 _("Missing function `%s' in transport plugin for `%s'\n"),
256 "get_session",
257 plug->lib_name);
258 }
259 if (NULL == plug->api->get_network)
260 {
261 fail = GNUNET_YES;
262 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
263 _("Missing function `%s' in transport plugin for `%s'\n"),
264 "get_network",
265 plug->lib_name);
266 }
267 if (NULL == plug->api->send)
268 {
269 fail = GNUNET_YES;
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 _("Missing function `%s' in transport plugin for `%s'\n"),
272 "send",
273 plug->lib_name);
274 }
275 if (NULL == plug->api->disconnect_peer)
276 {
277 fail = GNUNET_YES;
278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
279 _("Missing function `%s' in transport plugin for `%s'\n"),
280 "disconnect_peer",
281 plug->lib_name);
282 }
283 if (NULL == plug->api->disconnect_session)
284 {
285 fail = GNUNET_YES;
286 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
287 _("Missing function `%s' in transport plugin for `%s'\n"),
288 "disconnect_session",
289 plug->lib_name);
290 }
291 if (NULL == plug->api->query_keepalive_factor)
292 { 154 {
293 fail = GNUNET_YES; 155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
294 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 156 _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
295 _("Missing function `%s' in transport plugin for `%s'\n"), 157 return;
296 "query_keepalive_factor",
297 plug->lib_name);
298 } 158 }
299 if (NULL == plug->api->update_session_timeout) 159 if (GNUNET_OK !=
160 GNUNET_CONFIGURATION_get_value_string(GST_cfg,
161 "TRANSPORT",
162 "PLUGINS",
163 &plugs))
164 return;
165 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
166 _("Starting transport plugins `%s'\n"),
167 plugs);
168 for (pos = strtok(plugs, " "); pos != NULL; pos = strtok(NULL, " "))
300 { 169 {
301 fail = GNUNET_YES; 170 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 171 _("Loading `%s' transport plugin\n"),
303 _("Missing function `%s' in transport plugin for `%s'\n"), 172 pos);
304 "update_session_timeout", 173 GNUNET_asprintf(&libname,
305 plug->lib_name); 174 "libgnunet_plugin_transport_%s",
175 pos);
176 plug = GNUNET_new(struct TransportPlugin);
177 plug->short_name = GNUNET_strdup(pos);
178 plug->lib_name = libname;
179 plug->env.cfg = GST_cfg;
180 plug->env.my_identity = &GST_my_identity;
181 plug->env.get_our_hello = &GST_hello_get;
182 plug->env.cls = plug->short_name;
183 plug->env.receive = recv_cb;
184 plug->env.notify_address = address_cb;
185 plug->env.session_start = session_start_cb;
186 plug->env.session_end = session_end_cb;
187 plug->env.get_address_type = &plugin_env_address_to_type;
188 plug->env.update_address_distance = &plugin_env_update_distance;
189 plug->env.max_connections = tneigh;
190 plug->env.stats = GST_stats;
191 GNUNET_CONTAINER_DLL_insert(plugins_head,
192 plugins_tail,
193 plug);
306 } 194 }
307 if (GNUNET_YES == fail) 195 GNUNET_free(plugs);
196 next = plugins_head;
197 while (NULL != next)
308 { 198 {
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 199 plug = next;
310 _("Did not load plugin `%s' due to missing functions\n"), 200 next = plug->next;
311 plug->lib_name); 201 plug->api = GNUNET_PLUGIN_load(plug->lib_name,
312 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); 202 &plug->env);
313 GNUNET_CONTAINER_DLL_remove (plugins_head, 203 if (NULL == plug->api)
314 plugins_tail, 204 {
315 plug); 205 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
316 GNUNET_free (plug->short_name); 206 _("Failed to load transport plugin for `%s'\n"),
317 GNUNET_free (plug->lib_name); 207 plug->lib_name);
318 GNUNET_free (plug); 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 }
319 } 318 }
320 }
321} 319}
322 320
323 321
@@ -325,18 +323,18 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
325 * Unload all plugins 323 * Unload all plugins
326 */ 324 */
327void 325void
328GST_plugins_unload () 326GST_plugins_unload()
329{ 327{
330 struct TransportPlugin *plug; 328 struct TransportPlugin *plug;
331 329
332 while (NULL != (plug = plugins_head)) 330 while (NULL != (plug = plugins_head))
333 { 331 {
334 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); 332 GNUNET_break(NULL == GNUNET_PLUGIN_unload(plug->lib_name, plug->api));
335 GNUNET_free (plug->lib_name); 333 GNUNET_free(plug->lib_name);
336 GNUNET_free (plug->short_name); 334 GNUNET_free(plug->short_name);
337 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug); 335 GNUNET_CONTAINER_DLL_remove(plugins_head, plugins_tail, plug);
338 GNUNET_free (plug); 336 GNUNET_free(plug);
339 } 337 }
340} 338}
341 339
342 340
@@ -347,12 +345,12 @@ GST_plugins_unload ()
347 * @return the plugin's API, NULL if the plugin is not loaded 345 * @return the plugin's API, NULL if the plugin is not loaded
348 */ 346 */
349struct GNUNET_TRANSPORT_PluginFunctions * 347struct GNUNET_TRANSPORT_PluginFunctions *
350GST_plugins_find (const char *name) 348GST_plugins_find(const char *name)
351{ 349{
352 struct TransportPlugin *pos; 350 struct TransportPlugin *pos;
353 351
354 for (pos = plugins_head; NULL != pos; pos = pos->next) 352 for (pos = plugins_head; NULL != pos; pos = pos->next)
355 if (0 == strcmp (name, pos->short_name)) 353 if (0 == strcmp(name, pos->short_name))
356 break; 354 break;
357 if (NULL == pos) 355 if (NULL == pos)
358 return NULL; 356 return NULL;
@@ -371,18 +369,18 @@ GST_plugins_find (const char *name)
371 * @return the plugin's API, NULL if the plugin is not loaded 369 * @return the plugin's API, NULL if the plugin is not loaded
372 */ 370 */
373struct GNUNET_TRANSPORT_PluginFunctions * 371struct GNUNET_TRANSPORT_PluginFunctions *
374GST_plugins_printer_find (const char *name) 372GST_plugins_printer_find(const char *name)
375{ 373{
376 struct TransportPlugin *pos; 374 struct TransportPlugin *pos;
377 char *stripped = GNUNET_strdup (name); 375 char *stripped = GNUNET_strdup(name);
378 char *sep = strchr (stripped, '_'); 376 char *sep = strchr(stripped, '_');
379 377
380 if (NULL != sep) 378 if (NULL != sep)
381 sep[0] = '\0'; 379 sep[0] = '\0';
382 for (pos = plugins_head; NULL != pos; pos = pos->next) 380 for (pos = plugins_head; NULL != pos; pos = pos->next)
383 if (pos->short_name == strstr (pos->short_name, stripped)) 381 if (pos->short_name == strstr(pos->short_name, stripped))
384 break; 382 break;
385 GNUNET_free (stripped); 383 GNUNET_free(stripped);
386 if (NULL == pos) 384 if (NULL == pos)
387 return NULL; 385 return NULL;
388 return pos->api; 386 return pos->api;
@@ -397,7 +395,7 @@ GST_plugins_printer_find (const char *name)
397 * @return statically allocated (!) human-readable address 395 * @return statically allocated (!) human-readable address
398 */ 396 */
399const char * 397const char *
400GST_plugins_a2s (const struct GNUNET_HELLO_Address *address) 398GST_plugins_a2s(const struct GNUNET_HELLO_Address *address)
401{ 399{
402 struct GNUNET_TRANSPORT_PluginFunctions *api; 400 struct GNUNET_TRANSPORT_PluginFunctions *api;
403 static char unable_to_show[1024]; 401 static char unable_to_show[1024];
@@ -407,28 +405,28 @@ GST_plugins_a2s (const struct GNUNET_HELLO_Address *address)
407 return "<NULL>"; 405 return "<NULL>";
408 if (0 == address->address_length) 406 if (0 == address->address_length)
409 return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */ 407 return TRANSPORT_SESSION_INBOUND_STRING; /* Addresse with length 0 are inbound, address->address itself may be NULL */
410 api = GST_plugins_printer_find (address->transport_name); 408 api = GST_plugins_printer_find(address->transport_name);
411 if (NULL == api) 409 if (NULL == api)
412 { 410 {
413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 411 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
414 "Failed to find transport plugin `%s'\n", 412 "Failed to find transport plugin `%s'\n",
415 address->transport_name); 413 address->transport_name);
416 return "<plugin unknown>"; 414 return "<plugin unknown>";
417 } 415 }
418 if (0 == address->address_length) 416 if (0 == address->address_length)
419 { 417 {
420 GNUNET_snprintf (unable_to_show, 418 GNUNET_snprintf(unable_to_show,
421 sizeof (unable_to_show), 419 sizeof(unable_to_show),
422 "<unable to stringify %u-byte long address of %s transport>", 420 "<unable to stringify %u-byte long address of %s transport>",
423 (unsigned int) address->address_length, 421 (unsigned int)address->address_length,
424 address->transport_name); 422 address->transport_name);
425 return unable_to_show; 423 return unable_to_show;
426 } 424 }
427 return (NULL != (s = api->address_to_string (NULL, 425 return(NULL != (s = api->address_to_string(NULL,
428 address->address, 426 address->address,
429 address->address_length)) 427 address->address_length))
430 ? s 428 ? s
431 : "<invalid>"); 429 : "<invalid>");
432} 430}
433 431
434 432
@@ -439,18 +437,18 @@ GST_plugins_a2s (const struct GNUNET_HELLO_Address *address)
439 * @param cb_cls closure for @a cb 437 * @param cb_cls closure for @a cb
440 */ 438 */
441void 439void
442GST_plugins_monitor_subscribe (GNUNET_TRANSPORT_SessionInfoCallback cb, 440GST_plugins_monitor_subscribe(GNUNET_TRANSPORT_SessionInfoCallback cb,
443 void *cb_cls) 441 void *cb_cls)
444{ 442{
445 struct TransportPlugin *pos; 443 struct TransportPlugin *pos;
446 444
447 for (pos = plugins_head; NULL != pos; pos = pos->next) 445 for (pos = plugins_head; NULL != pos; pos = pos->next)
448 if (NULL == pos->api->setup_monitor) 446 if (NULL == pos->api->setup_monitor)
449 GNUNET_break (0); 447 GNUNET_break(0);
450 else 448 else
451 pos->api->setup_monitor (pos->api->cls, 449 pos->api->setup_monitor(pos->api->cls,
452 cb, 450 cb,
453 cb_cls); 451 cb_cls);
454} 452}
455 453
456 454
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
index cfb72dfed..2b6f6f070 100644
--- a/src/transport/gnunet-service-transport_plugins.h
+++ b/src/transport/gnunet-service-transport_plugins.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_plugins.h 22 * @file 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 6abe8d2d2..71f43fada 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_validation.c 22 * @file transport/gnunet-service-transport_validation.c
@@ -42,8 +42,7 @@
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{
47 /** 46 /**
48 * Undefined state 47 * Undefined state
49 * 48 *
@@ -90,14 +89,14 @@ enum GNUNET_TRANSPORT_ValidationState
90 * OTOH, we don't want to spend too much time generating PONG signatures, 89 * OTOH, we don't want to spend too much time generating PONG signatures,
91 * so they must have some lifetime to reduce our CPU usage. 90 * so they must have some lifetime to reduce our CPU usage.
92 */ 91 */
93#define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 1) 92#define PONG_SIGNATURE_LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 1)
94 93
95/** 94/**
96 * After how long do we expire an address in a HELLO that we just 95 * After how long do we expire an address in a HELLO that we just
97 * validated? This value is also used for our own addresses when we 96 * validated? This value is also used for our own addresses when we
98 * create a HELLO. 97 * create a HELLO.
99 */ 98 */
100#define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) 99#define HELLO_ADDRESS_EXPIRATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 12)
101 100
102/** 101/**
103 * How often do we allow PINGing an address that we have not yet 102 * How often do we allow PINGing an address that we have not yet
@@ -105,24 +104,24 @@ enum GNUNET_TRANSPORT_ValidationState
105 * we cannot validate (because after this time we can destroy the 104 * we cannot validate (because after this time we can destroy the
106 * validation record). 105 * validation record).
107 */ 106 */
108#define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 107#define UNVALIDATED_PING_KEEPALIVE GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
109 108
110/** 109/**
111 * How often do we PING an address that we have successfully validated 110 * How often do we PING an address that we have successfully validated
112 * in the past but are not actively using? Should be (significantly) 111 * in the past but are not actively using? Should be (significantly)
113 * smaller than HELLO_ADDRESS_EXPIRATION. 112 * smaller than HELLO_ADDRESS_EXPIRATION.
114 */ 113 */
115#define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 114#define VALIDATED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
116 115
117/** 116/**
118 * How often do we PING an address that we are currently using? 117 * How often do we PING an address that we are currently using?
119 */ 118 */
120#define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2) 119#define CONNECTED_PING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 2)
121 120
122/** 121/**
123 * How much delay is acceptable for sending the PING or PONG? 122 * How much delay is acceptable for sending the PING or PONG?
124 */ 123 */
125#define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 124#define ACCEPTABLE_PING_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
126 125
127/** 126/**
128 * Size of the validation map hashmap. 127 * Size of the validation map hashmap.
@@ -148,9 +147,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
148 * or an empty address if we are just sending a PING to confirm that a 147 * or an empty address if we are just sending a PING to confirm that a
149 * connection which the receiver (of the PING) initiated is still valid. 148 * connection which the receiver (of the PING) initiated is still valid.
150 */ 149 */
151struct TransportPingMessage 150struct TransportPingMessage {
152{
153
154 /** 151 /**
155 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING 152 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PING
156 */ 153 */
@@ -165,7 +162,6 @@ struct TransportPingMessage
165 * Who is the intended recipient? 162 * Who is the intended recipient?
166 */ 163 */
167 struct GNUNET_PeerIdentity target; 164 struct GNUNET_PeerIdentity target;
168
169}; 165};
170 166
171 167
@@ -179,9 +175,7 @@ struct TransportPingMessage
179 * if the PING had not address either (and we received the request via 175 * if the PING had not address either (and we received the request via
180 * a connection that we initiated). 176 * a connection that we initiated).
181 */ 177 */
182struct TransportPongMessage 178struct TransportPongMessage {
183{
184
185 /** 179 /**
186 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG 180 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_PONG
187 */ 181 */
@@ -214,16 +208,13 @@ struct TransportPongMessage
214 * being signed, hence not redundant). 208 * being signed, hence not redundant).
215 */ 209 */
216 uint32_t addrlen GNUNET_PACKED; 210 uint32_t addrlen GNUNET_PACKED;
217
218}; 211};
219GNUNET_NETWORK_STRUCT_END 212GNUNET_NETWORK_STRUCT_END
220 213
221/** 214/**
222 * Information about an address under validation 215 * Information about an address under validation
223 */ 216 */
224struct ValidationEntry 217struct ValidationEntry {
225{
226
227 /** 218 /**
228 * The address. 219 * The address.
229 */ 220 */
@@ -361,8 +352,7 @@ static struct GNUNET_TIME_Absolute validation_next;
361/** 352/**
362 * Context for the validation entry match function. 353 * Context for the validation entry match function.
363 */ 354 */
364struct ValidationEntryMatchContext 355struct ValidationEntryMatchContext {
365{
366 /** 356 /**
367 * Where to store the result? 357 * Where to store the result?
368 */ 358 */
@@ -372,7 +362,6 @@ struct ValidationEntryMatchContext
372 * Address we're interested in. 362 * Address we're interested in.
373 */ 363 */
374 const struct GNUNET_HELLO_Address *address; 364 const struct GNUNET_HELLO_Address *address;
375
376}; 365};
377 366
378 367
@@ -382,12 +371,12 @@ struct ValidationEntryMatchContext
382 * is changed. 371 * is changed.
383 */ 372 */
384static void 373static void
385publish_ve_stat_update () 374publish_ve_stat_update()
386{ 375{
387 GNUNET_STATISTICS_set (GST_stats, 376 GNUNET_STATISTICS_set(GST_stats,
388 gettext_noop ("# Addresses in validation map"), 377 gettext_noop("# Addresses in validation map"),
389 GNUNET_CONTAINER_multipeermap_size (validation_map), 378 GNUNET_CONTAINER_multipeermap_size(validation_map),
390 GNUNET_NO); 379 GNUNET_NO);
391} 380}
392 381
393 382
@@ -401,19 +390,19 @@ publish_ve_stat_update ()
401 * #GNUNET_NO if the entry does match 390 * #GNUNET_NO if the entry does match
402 */ 391 */
403static int 392static int
404validation_entry_match (void *cls, 393validation_entry_match(void *cls,
405 const struct GNUNET_PeerIdentity *key, 394 const struct GNUNET_PeerIdentity *key,
406 void *value) 395 void *value)
407{ 396{
408 struct ValidationEntryMatchContext *vemc = cls; 397 struct ValidationEntryMatchContext *vemc = cls;
409 struct ValidationEntry *ve = value; 398 struct ValidationEntry *ve = value;
410 399
411 if (0 == GNUNET_HELLO_address_cmp (ve->address, 400 if (0 == GNUNET_HELLO_address_cmp(ve->address,
412 vemc->address)) 401 vemc->address))
413 { 402 {
414 vemc->ve = ve; 403 vemc->ve = ve;
415 return GNUNET_NO; 404 return GNUNET_NO;
416 } 405 }
417 return GNUNET_YES; 406 return GNUNET_YES;
418} 407}
419 408
@@ -426,8 +415,8 @@ validation_entry_match (void *cls,
426 * @param state new state 415 * @param state new state
427 */ 416 */
428static void 417static void
429validation_entry_changed (struct ValidationEntry *ve, 418validation_entry_changed(struct ValidationEntry *ve,
430 enum GNUNET_TRANSPORT_ValidationState state) 419 enum GNUNET_TRANSPORT_ValidationState state)
431{ 420{
432 ve->state = state; 421 ve->state = state;
433} 422}
@@ -442,9 +431,9 @@ validation_entry_changed (struct ValidationEntry *ve,
442 * @return #GNUNET_YES (continue to iterate) 431 * @return #GNUNET_YES (continue to iterate)
443 */ 432 */
444static int 433static int
445cleanup_validation_entry (void *cls, 434cleanup_validation_entry(void *cls,
446 const struct GNUNET_PeerIdentity *key, 435 const struct GNUNET_PeerIdentity *key,
447 void *value) 436 void *value)
448{ 437{
449 struct ValidationEntry *ve = value; 438 struct ValidationEntry *ve = value;
450 439
@@ -452,47 +441,47 @@ cleanup_validation_entry (void *cls,
452 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS; 441 ve->valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
453 442
454 /* Notify about deleted entry */ 443 /* Notify about deleted entry */
455 validation_entry_changed (ve, 444 validation_entry_changed(ve,
456 GNUNET_TRANSPORT_VS_REMOVE); 445 GNUNET_TRANSPORT_VS_REMOVE);
457 446
458 if (NULL != ve->bc) 447 if (NULL != ve->bc)
459 { 448 {
460 GST_blacklist_test_cancel (ve->bc); 449 GST_blacklist_test_cancel(ve->bc);
461 ve->bc = NULL; 450 ve->bc = NULL;
462 } 451 }
463 GNUNET_break (GNUNET_OK == 452 GNUNET_break(GNUNET_OK ==
464 GNUNET_CONTAINER_multipeermap_remove (validation_map, 453 GNUNET_CONTAINER_multipeermap_remove(validation_map,
465 &ve->address->peer, 454 &ve->address->peer,
466 ve)); 455 ve));
467 publish_ve_stat_update (); 456 publish_ve_stat_update();
468 if (GNUNET_YES == ve->known_to_ats) 457 if (GNUNET_YES == ve->known_to_ats)
469 { 458 {
470 GST_ats_expire_address (ve->address); 459 GST_ats_expire_address(ve->address);
471 GNUNET_assert (GNUNET_NO == 460 GNUNET_assert(GNUNET_NO ==
472 GST_ats_is_known_no_session (ve->address)); 461 GST_ats_is_known_no_session(ve->address));
473 ve->known_to_ats = GNUNET_NO; 462 ve->known_to_ats = GNUNET_NO;
474 } 463 }
475 GNUNET_HELLO_address_free (ve->address); 464 GNUNET_HELLO_address_free(ve->address);
476 if (NULL != ve->timeout_task) 465 if (NULL != ve->timeout_task)
477 { 466 {
478 GNUNET_SCHEDULER_cancel (ve->timeout_task); 467 GNUNET_SCHEDULER_cancel(ve->timeout_task);
479 ve->timeout_task = NULL; 468 ve->timeout_task = NULL;
480 } 469 }
481 if (NULL != ve->revalidation_task) 470 if (NULL != ve->revalidation_task)
482 { 471 {
483 GNUNET_SCHEDULER_cancel (ve->revalidation_task); 472 GNUNET_SCHEDULER_cancel(ve->revalidation_task);
484 ve->revalidation_task = NULL; 473 ve->revalidation_task = NULL;
485 } 474 }
486 if ( (GNUNET_YES == ve->expecting_pong) && 475 if ((GNUNET_YES == ve->expecting_pong) &&
487 (validations_running > 0) ) 476 (validations_running > 0))
488 { 477 {
489 validations_running--; 478 validations_running--;
490 GNUNET_STATISTICS_set (GST_stats, 479 GNUNET_STATISTICS_set(GST_stats,
491 gettext_noop ("# validations running"), 480 gettext_noop("# validations running"),
492 validations_running, 481 validations_running,
493 GNUNET_NO); 482 GNUNET_NO);
494 } 483 }
495 GNUNET_free (ve); 484 GNUNET_free(ve);
496 return GNUNET_OK; 485 return GNUNET_OK;
497} 486}
498 487
@@ -504,7 +493,7 @@ cleanup_validation_entry (void *cls,
504 * @param cls the `struct ValidationEntry` 493 * @param cls the `struct ValidationEntry`
505 */ 494 */
506static void 495static void
507timeout_hello_validation (void *cls) 496timeout_hello_validation(void *cls)
508{ 497{
509 struct ValidationEntry *ve = cls; 498 struct ValidationEntry *ve = cls;
510 struct GNUNET_TIME_Absolute max; 499 struct GNUNET_TIME_Absolute max;
@@ -514,27 +503,27 @@ timeout_hello_validation (void *cls)
514 /* For valid addresses, we want to wait until the expire; 503 /* For valid addresses, we want to wait until the expire;
515 for addresses under PING validation, we want to wait 504 for addresses under PING validation, we want to wait
516 until we give up on the PING */ 505 until we give up on the PING */
517 max = GNUNET_TIME_absolute_max (ve->valid_until, 506 max = GNUNET_TIME_absolute_max(ve->valid_until,
518 ve->revalidation_block); 507 ve->revalidation_block);
519 left = GNUNET_TIME_absolute_get_remaining (max); 508 left = GNUNET_TIME_absolute_get_remaining(max);
520 if (left.rel_value_us > 0) 509 if (left.rel_value_us > 0)
521 { 510 {
522 /* We should wait a bit longer. This happens when 511 /* We should wait a bit longer. This happens when
523 address lifetimes are extended due to successful 512 address lifetimes are extended due to successful
524 validations. */ 513 validations. */
525 ve->timeout_task = 514 ve->timeout_task =
526 GNUNET_SCHEDULER_add_delayed (left, 515 GNUNET_SCHEDULER_add_delayed(left,
527 &timeout_hello_validation, 516 &timeout_hello_validation,
528 ve); 517 ve);
529 return; 518 return;
530 } 519 }
531 GNUNET_STATISTICS_update (GST_stats, 520 GNUNET_STATISTICS_update(GST_stats,
532 gettext_noop ("# address records discarded (timeout)"), 521 gettext_noop("# address records discarded (timeout)"),
533 1, 522 1,
534 GNUNET_NO); 523 GNUNET_NO);
535 cleanup_validation_entry (NULL, 524 cleanup_validation_entry(NULL,
536 &ve->address->peer, 525 &ve->address->peer,
537 ve); 526 ve);
538} 527}
539 528
540 529
@@ -551,11 +540,11 @@ timeout_hello_validation (void *cls)
551 * #GNUNET_SYSERR if operation was aborted 540 * #GNUNET_SYSERR if operation was aborted
552 */ 541 */
553static void 542static void
554transmit_ping_if_allowed (void *cls, 543transmit_ping_if_allowed(void *cls,
555 const struct GNUNET_PeerIdentity *pid, 544 const struct GNUNET_PeerIdentity *pid,
556 const struct GNUNET_HELLO_Address *address_null, 545 const struct GNUNET_HELLO_Address *address_null,
557 struct GNUNET_ATS_Session *session_null, 546 struct GNUNET_ATS_Session *session_null,
558 int result) 547 int result)
559{ 548{
560 struct ValidationEntry *ve = cls; 549 struct ValidationEntry *ve = cls;
561 struct TransportPingMessage ping; 550 struct TransportPingMessage ping;
@@ -570,117 +559,116 @@ transmit_ping_if_allowed (void *cls,
570 559
571 ve->bc = NULL; 560 ve->bc = NULL;
572 if (GNUNET_OK != result) 561 if (GNUNET_OK != result)
573 { 562 {
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 563 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
575 "Blacklist denies sending PING to `%s' `%s' `%s'\n", 564 "Blacklist denies sending PING to `%s' `%s' `%s'\n",
576 GNUNET_i2s (pid), 565 GNUNET_i2s(pid),
577 GST_plugins_a2s (ve->address), 566 GST_plugins_a2s(ve->address),
578 ve->address->transport_name); 567 ve->address->transport_name);
579 GNUNET_STATISTICS_update (GST_stats, 568 GNUNET_STATISTICS_update(GST_stats,
580 gettext_noop ("# address records discarded (blacklist)"), 569 gettext_noop("# address records discarded (blacklist)"),
581 1, 570 1,
582 GNUNET_NO); 571 GNUNET_NO);
583 cleanup_validation_entry (NULL, 572 cleanup_validation_entry(NULL,
584 pid, 573 pid,
585 ve); 574 ve);
586 return; 575 return;
587 } 576 }
588 hello = GST_hello_get (); 577 hello = GST_hello_get();
589 GNUNET_assert (NULL != hello); 578 GNUNET_assert(NULL != hello);
590 slen = strlen (ve->address->transport_name) + 1; 579 slen = strlen(ve->address->transport_name) + 1;
591 hsize = ntohs (hello->size); 580 hsize = ntohs(hello->size);
592 tsize = sizeof (struct TransportPingMessage) + 581 tsize = sizeof(struct TransportPingMessage) +
593 ve->address->address_length + slen + hsize; 582 ve->address->address_length + slen + hsize;
594 583
595 ping.header.size = 584 ping.header.size =
596 htons (sizeof (struct TransportPingMessage) + 585 htons(sizeof(struct TransportPingMessage) +
597 ve->address->address_length + slen); 586 ve->address->address_length + slen);
598 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 587 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
599 ping.challenge = htonl (ve->challenge); 588 ping.challenge = htonl(ve->challenge);
600 ping.target = *pid; 589 ping.target = *pid;
601 590
602 if (tsize >= GNUNET_MAX_MESSAGE_SIZE) 591 if (tsize >= GNUNET_MAX_MESSAGE_SIZE)
603 { 592 {
604 GNUNET_break (0); 593 GNUNET_break(0);
605 hsize = 0; 594 hsize = 0;
606 tsize = 595 tsize =
607 sizeof (struct TransportPingMessage) + ve->address->address_length + 596 sizeof(struct TransportPingMessage) + ve->address->address_length +
608 slen + hsize; 597 slen + hsize;
609 } 598 }
610 { 599 {
611 char message_buf[tsize] GNUNET_ALIGN; 600 char message_buf[tsize] GNUNET_ALIGN;
612 601
613 GNUNET_memcpy (message_buf, 602 GNUNET_memcpy(message_buf,
614 hello, 603 hello,
615 hsize); 604 hsize);
616 GNUNET_memcpy (&message_buf[hsize], 605 GNUNET_memcpy(&message_buf[hsize],
617 &ping, 606 &ping,
618 sizeof (struct TransportPingMessage)); 607 sizeof(struct TransportPingMessage));
619 GNUNET_memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize], 608 GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + hsize],
620 ve->address->transport_name, 609 ve->address->transport_name,
621 slen); 610 slen);
622 GNUNET_memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], 611 GNUNET_memcpy(&message_buf[sizeof(struct TransportPingMessage) + slen + hsize],
623 ve->address->address, 612 ve->address->address,
624 ve->address->address_length); 613 ve->address->address_length);
625 papi = GST_plugins_find (ve->address->transport_name); 614 papi = GST_plugins_find(ve->address->transport_name);
626 GNUNET_assert (NULL != papi); 615 GNUNET_assert(NULL != papi);
627 session = papi->get_session (papi->cls, 616 session = papi->get_session(papi->cls,
628 ve->address); 617 ve->address);
629 if (NULL == session) 618 if (NULL == session)
630 { 619 {
631 /* Could not get a valid session */ 620 /* Could not get a valid session */
632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 621 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
633 "Failed to get session to send PING to `%s' at `%s'\n", 622 "Failed to get session to send PING to `%s' at `%s'\n",
634 GNUNET_i2s (pid), 623 GNUNET_i2s(pid),
635 GST_plugins_a2s (ve->address)); 624 GST_plugins_a2s(ve->address));
636 return; 625 return;
637 } 626 }
638 627
639 ret = papi->send (papi->cls, session, 628 ret = papi->send(papi->cls, session,
640 message_buf, tsize, 629 message_buf, tsize,
641 PING_PRIORITY, 630 PING_PRIORITY,
642 ACCEPTABLE_PING_DELAY, 631 ACCEPTABLE_PING_DELAY,
643 NULL, NULL); 632 NULL, NULL);
644 if (-1 == ret) 633 if (-1 == ret)
645 { 634 {
646 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 635 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
647 "Failed to send PING to `%s' at `%s'\n", 636 "Failed to send PING to `%s' at `%s'\n",
648 GNUNET_i2s (pid), 637 GNUNET_i2s(pid),
649 GST_plugins_a2s (ve->address)); 638 GST_plugins_a2s(ve->address));
650 return; 639 return;
651 } 640 }
652 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 641 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
653 "Transmitted plain PING to `%s' `%s' `%s'\n", 642 "Transmitted plain PING to `%s' `%s' `%s'\n",
654 GNUNET_i2s (pid), 643 GNUNET_i2s(pid),
655 GST_plugins_a2s (ve->address), 644 GST_plugins_a2s(ve->address),
656 ve->address->transport_name); 645 ve->address->transport_name);
657 ve->network = papi->get_network (papi->cls, 646 ve->network = papi->get_network(papi->cls,
658 session); 647 session);
659 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); 648 GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network);
660 GST_neighbours_notify_data_sent (ve->address, 649 GST_neighbours_notify_data_sent(ve->address,
661 session, 650 session,
662 tsize); 651 tsize);
663 next = GNUNET_TIME_relative_to_absolute (validation_delay); 652 next = GNUNET_TIME_relative_to_absolute(validation_delay);
664 validation_next = GNUNET_TIME_absolute_max (next, 653 validation_next = GNUNET_TIME_absolute_max(next,
665 validation_next); 654 validation_next);
666 ve->send_time = GNUNET_TIME_absolute_get (); 655 ve->send_time = GNUNET_TIME_absolute_get();
667 GNUNET_STATISTICS_update (GST_stats, 656 GNUNET_STATISTICS_update(GST_stats,
668 gettext_noop ("# PINGs for address validation sent"), 657 gettext_noop("# PINGs for address validation sent"),
669 1, 658 1,
670 GNUNET_NO); 659 GNUNET_NO);
671 ve->expecting_pong = GNUNET_YES; 660 ve->expecting_pong = GNUNET_YES;
672 validations_running++; 661 validations_running++;
673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 662 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
674 "Validation started, %u validation processes running\n", 663 "Validation started, %u validation processes running\n",
675 validations_running); 664 validations_running);
676 GNUNET_STATISTICS_set (GST_stats, 665 GNUNET_STATISTICS_set(GST_stats,
677 gettext_noop ("# validations running"), 666 gettext_noop("# validations running"),
678 validations_running, 667 validations_running,
679 GNUNET_NO); 668 GNUNET_NO);
680 /* Notify about PING sent */ 669 /* Notify about PING sent */
681 validation_entry_changed (ve, 670 validation_entry_changed(ve,
682 GNUNET_TRANSPORT_VS_UPDATE); 671 GNUNET_TRANSPORT_VS_UPDATE);
683
684 } 672 }
685} 673}
686 674
@@ -691,7 +679,7 @@ transmit_ping_if_allowed (void *cls,
691 * @param cls the `struct ValidationEntry` 679 * @param cls the `struct ValidationEntry`
692 */ 680 */
693static void 681static void
694revalidate_address (void *cls) 682revalidate_address(void *cls)
695{ 683{
696 struct ValidationEntry *ve = cls; 684 struct ValidationEntry *ve = cls;
697 struct GNUNET_TIME_Relative canonical_delay; 685 struct GNUNET_TIME_Relative canonical_delay;
@@ -701,12 +689,12 @@ revalidate_address (void *cls)
701 uint32_t rdelay; 689 uint32_t rdelay;
702 690
703 ve->revalidation_task = NULL; 691 ve->revalidation_task = NULL;
704 delay = GNUNET_TIME_absolute_get_remaining (ve->revalidation_block); 692 delay = GNUNET_TIME_absolute_get_remaining(ve->revalidation_block);
705 /* Considering current connectivity situation, what is the maximum 693 /* Considering current connectivity situation, what is the maximum
706 block period permitted? */ 694 block period permitted? */
707 if (GNUNET_YES == ve->in_use) 695 if (GNUNET_YES == ve->in_use)
708 canonical_delay = CONNECTED_PING_FREQUENCY; 696 canonical_delay = CONNECTED_PING_FREQUENCY;
709 else if (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value_us > 0) 697 else if (GNUNET_TIME_absolute_get_remaining(ve->valid_until).rel_value_us > 0)
710 canonical_delay = VALIDATED_PING_FREQUENCY; 698 canonical_delay = VALIDATED_PING_FREQUENCY;
711 else 699 else
712 canonical_delay = UNVALIDATED_PING_KEEPALIVE; 700 canonical_delay = UNVALIDATED_PING_KEEPALIVE;
@@ -714,94 +702,94 @@ revalidate_address (void *cls)
714 new maximum delay (which may be lower); the real delay 702 new maximum delay (which may be lower); the real delay
715 is originally randomized between "canonical_delay" and "2 * canonical_delay", 703 is originally randomized between "canonical_delay" and "2 * canonical_delay",
716 so continue to permit that window for the operation. */ 704 so continue to permit that window for the operation. */
717 delay = GNUNET_TIME_relative_min (delay, 705 delay = GNUNET_TIME_relative_min(delay,
718 GNUNET_TIME_relative_multiply (canonical_delay, 706 GNUNET_TIME_relative_multiply(canonical_delay,
719 2)); 707 2));
720 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (delay); 708 ve->revalidation_block = GNUNET_TIME_relative_to_absolute(delay);
721 if (delay.rel_value_us > 0) 709 if (delay.rel_value_us > 0)
722 { 710 {
723 /* should wait a bit longer */ 711 /* should wait a bit longer */
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 712 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
725 "Waiting for %s longer before (re)validating address `%s'\n", 713 "Waiting for %s longer before (re)validating address `%s'\n",
726 GNUNET_STRINGS_relative_time_to_string (delay, 714 GNUNET_STRINGS_relative_time_to_string(delay,
727 GNUNET_YES), 715 GNUNET_YES),
728 GST_plugins_a2s (ve->address)); 716 GST_plugins_a2s(ve->address));
729 ve->revalidation_task = 717 ve->revalidation_task =
730 GNUNET_SCHEDULER_add_delayed (delay, 718 GNUNET_SCHEDULER_add_delayed(delay,
731 &revalidate_address, ve); 719 &revalidate_address, ve);
732 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); 720 ve->next_validation = GNUNET_TIME_relative_to_absolute(delay);
733 return; 721 return;
734 } 722 }
735 /* check if globally we have too many active validations at a 723 /* check if globally we have too many active validations at a
736 too high rate, if so, delay ours */ 724 too high rate, if so, delay ours */
737 blocked_for = GNUNET_TIME_absolute_get_remaining (validation_next); 725 blocked_for = GNUNET_TIME_absolute_get_remaining(validation_next);
738 if ( (validations_running > validations_fast_start_threshold) && 726 if ((validations_running > validations_fast_start_threshold) &&
739 (blocked_for.rel_value_us > 0) ) 727 (blocked_for.rel_value_us > 0))
740 { 728 {
741 /* Validations are blocked, have to wait for blocked_for time */ 729 /* Validations are blocked, have to wait for blocked_for time */
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 730 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
743 "Validations blocked for another %s, delaying validating address `%s'\n", 731 "Validations blocked for another %s, delaying validating address `%s'\n",
744 GNUNET_STRINGS_relative_time_to_string (blocked_for, 732 GNUNET_STRINGS_relative_time_to_string(blocked_for,
745 GNUNET_YES), 733 GNUNET_YES),
746 GST_plugins_a2s (ve->address)); 734 GST_plugins_a2s(ve->address));
747 GNUNET_STATISTICS_update (GST_stats, 735 GNUNET_STATISTICS_update(GST_stats,
748 gettext_noop ("# validations delayed by global throttle"), 736 gettext_noop("# validations delayed by global throttle"),
749 1, 737 1,
750 GNUNET_NO); 738 GNUNET_NO);
751 ve->revalidation_task = 739 ve->revalidation_task =
752 GNUNET_SCHEDULER_add_delayed (blocked_for, 740 GNUNET_SCHEDULER_add_delayed(blocked_for,
753 &revalidate_address, 741 &revalidate_address,
754 ve); 742 ve);
755 ve->next_validation = GNUNET_TIME_relative_to_absolute (blocked_for); 743 ve->next_validation = GNUNET_TIME_relative_to_absolute(blocked_for);
756 return; 744 return;
757 } 745 }
758 746
759 /* We are good to go; remember to not go again for `canonical_delay` time; 747 /* We are good to go; remember to not go again for `canonical_delay` time;
760 add up to `canonical_delay` to randomize start time */ 748 add up to `canonical_delay` to randomize start time */
761 ve->revalidation_block = GNUNET_TIME_relative_to_absolute (canonical_delay); 749 ve->revalidation_block = GNUNET_TIME_relative_to_absolute(canonical_delay);
762 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */ 750 /* schedule next PINGing with some extra random delay to avoid synchronous re-validations */
763 rdelay = 751 rdelay =
764 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 752 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
765 canonical_delay.rel_value_us); 753 canonical_delay.rel_value_us);
766 754
767 delay = GNUNET_TIME_relative_add (canonical_delay, 755 delay = GNUNET_TIME_relative_add(canonical_delay,
768 GNUNET_TIME_relative_multiply 756 GNUNET_TIME_relative_multiply
769 (GNUNET_TIME_UNIT_MICROSECONDS, 757 (GNUNET_TIME_UNIT_MICROSECONDS,
770 rdelay)); 758 rdelay));
771 759
772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 760 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
773 "Validating now, next scheduled for %s, now validating address `%s'\n", 761 "Validating now, next scheduled for %s, now validating address `%s'\n",
774 GNUNET_STRINGS_relative_time_to_string (blocked_for, 762 GNUNET_STRINGS_relative_time_to_string(blocked_for,
775 GNUNET_YES), 763 GNUNET_YES),
776 GST_plugins_a2s (ve->address)); 764 GST_plugins_a2s(ve->address));
777 ve->revalidation_task = 765 ve->revalidation_task =
778 GNUNET_SCHEDULER_add_delayed (delay, 766 GNUNET_SCHEDULER_add_delayed(delay,
779 &revalidate_address, 767 &revalidate_address,
780 ve); 768 ve);
781 ve->next_validation = GNUNET_TIME_relative_to_absolute (delay); 769 ve->next_validation = GNUNET_TIME_relative_to_absolute(delay);
782 770
783 /* start PINGing by checking blacklist */ 771 /* start PINGing by checking blacklist */
784 GNUNET_STATISTICS_update (GST_stats, 772 GNUNET_STATISTICS_update(GST_stats,
785 gettext_noop ("# address revalidations started"), 1, 773 gettext_noop("# address revalidations started"), 1,
786 GNUNET_NO); 774 GNUNET_NO);
787 if (NULL != ve->bc) 775 if (NULL != ve->bc)
788 { 776 {
789 GST_blacklist_test_cancel (ve->bc); 777 GST_blacklist_test_cancel(ve->bc);
790 ve->bc = NULL; 778 ve->bc = NULL;
791 } 779 }
792 bc = GST_blacklist_test_allowed (&ve->address->peer, 780 bc = GST_blacklist_test_allowed(&ve->address->peer,
793 ve->address->transport_name, 781 ve->address->transport_name,
794 &transmit_ping_if_allowed, 782 &transmit_ping_if_allowed,
795 ve, 783 ve,
796 NULL, 784 NULL,
797 NULL); 785 NULL);
798 if (NULL != bc) 786 if (NULL != bc)
799 { 787 {
800 /* If transmit_ping_if_allowed was already called it may have freed ve, 788 /* If transmit_ping_if_allowed was already called it may have freed ve,
801 * so only set ve->bc if it has not been called. 789 * so only set ve->bc if it has not been called.
802 */ 790 */
803 ve->bc = bc; 791 ve->bc = bc;
804 } 792 }
805} 793}
806 794
807 795
@@ -815,41 +803,41 @@ revalidate_address (void *cls)
815 * if we don't have an existing entry and no public key was given 803 * if we don't have an existing entry and no public key was given
816 */ 804 */
817static struct ValidationEntry * 805static struct ValidationEntry *
818find_validation_entry (const struct GNUNET_HELLO_Address *address) 806find_validation_entry(const struct GNUNET_HELLO_Address *address)
819{ 807{
820 struct ValidationEntryMatchContext vemc; 808 struct ValidationEntryMatchContext vemc;
821 struct ValidationEntry *ve; 809 struct ValidationEntry *ve;
822 810
823 vemc.ve = NULL; 811 vemc.ve = NULL;
824 vemc.address = address; 812 vemc.address = address;
825 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 813 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
826 &address->peer, 814 &address->peer,
827 &validation_entry_match, &vemc); 815 &validation_entry_match, &vemc);
828 if (NULL != (ve = vemc.ve)) 816 if (NULL != (ve = vemc.ve))
829 return ve; 817 return ve;
830 GNUNET_assert (GNUNET_NO == 818 GNUNET_assert(GNUNET_NO ==
831 GST_ats_is_known_no_session (address)); 819 GST_ats_is_known_no_session(address));
832 ve = GNUNET_new (struct ValidationEntry); 820 ve = GNUNET_new(struct ValidationEntry);
833 ve->in_use = GNUNET_SYSERR; /* not defined */ 821 ve->in_use = GNUNET_SYSERR; /* not defined */
834 ve->address = GNUNET_HELLO_address_copy (address); 822 ve->address = GNUNET_HELLO_address_copy(address);
835 ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS; 823 ve->pong_sig_valid_until = GNUNET_TIME_UNIT_ZERO_ABS;
836 memset (&ve->pong_sig_cache, 824 memset(&ve->pong_sig_cache,
837 '\0', 825 '\0',
838 sizeof (struct GNUNET_CRYPTO_EddsaSignature)); 826 sizeof(struct GNUNET_CRYPTO_EddsaSignature));
839 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL; 827 ve->latency = GNUNET_TIME_UNIT_FOREVER_REL;
840 ve->challenge = 828 ve->challenge =
841 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); 829 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
842 ve->timeout_task = 830 ve->timeout_task =
843 GNUNET_SCHEDULER_add_delayed (UNVALIDATED_PING_KEEPALIVE, 831 GNUNET_SCHEDULER_add_delayed(UNVALIDATED_PING_KEEPALIVE,
844 &timeout_hello_validation, 832 &timeout_hello_validation,
845 ve); 833 ve);
846 GNUNET_CONTAINER_multipeermap_put (validation_map, 834 GNUNET_CONTAINER_multipeermap_put(validation_map,
847 &address->peer, 835 &address->peer,
848 ve, 836 ve,
849 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 837 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
850 publish_ve_stat_update (); 838 publish_ve_stat_update();
851 validation_entry_changed (ve, 839 validation_entry_changed(ve,
852 GNUNET_TRANSPORT_VS_NEW); 840 GNUNET_TRANSPORT_VS_NEW);
853 return ve; 841 return ve;
854} 842}
855 843
@@ -866,9 +854,9 @@ find_validation_entry (const struct GNUNET_HELLO_Address *address)
866 * #GNUNET_SYSERR would abort iteration (but we always iterate all) 854 * #GNUNET_SYSERR would abort iteration (but we always iterate all)
867 */ 855 */
868static int 856static int
869add_valid_address (void *cls, 857add_valid_address(void *cls,
870 const struct GNUNET_HELLO_Address *address, 858 const struct GNUNET_HELLO_Address *address,
871 struct GNUNET_TIME_Absolute expiration) 859 struct GNUNET_TIME_Absolute expiration)
872{ 860{
873 const struct GNUNET_HELLO_Message *hello = cls; 861 const struct GNUNET_HELLO_Message *hello = cls;
874 struct ValidationEntry *ve; 862 struct ValidationEntry *ve;
@@ -876,60 +864,60 @@ add_valid_address (void *cls,
876 struct GNUNET_ATS_Properties prop; 864 struct GNUNET_ATS_Properties prop;
877 struct GNUNET_TRANSPORT_PluginFunctions *papi; 865 struct GNUNET_TRANSPORT_PluginFunctions *papi;
878 866
879 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 867 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us)
880 return GNUNET_OK; /* expired */ 868 return GNUNET_OK; /* expired */
881 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) 869 if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid))
882 { 870 {
883 GNUNET_break (0); 871 GNUNET_break(0);
884 return GNUNET_OK; /* invalid HELLO !? */ 872 return GNUNET_OK; /* invalid HELLO !? */
885 } 873 }
886 if (NULL == (papi = GST_plugins_find (address->transport_name))) 874 if (NULL == (papi = GST_plugins_find(address->transport_name)))
887 { 875 {
888 /* might have been valid in the past, but we don't have that 876 /* might have been valid in the past, but we don't have that
889 plugin loaded right now */ 877 plugin loaded right now */
890 return GNUNET_OK; 878 return GNUNET_OK;
891 } 879 }
892 if (NULL == 880 if (NULL ==
893 papi->address_to_string (papi->cls, 881 papi->address_to_string(papi->cls,
894 address->address, 882 address->address,
895 address->address_length)) 883 address->address_length))
896 { 884 {
897 /* Why do we try to add an ill-formed address? */ 885 /* Why do we try to add an ill-formed address? */
898 GNUNET_break (0); 886 GNUNET_break(0);
899 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 887 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
900 "Address with %u bytes for plugin %s and peer %s is malformed\n", 888 "Address with %u bytes for plugin %s and peer %s is malformed\n",
901 (unsigned int) address->address_length, 889 (unsigned int)address->address_length,
902 address->transport_name, 890 address->transport_name,
903 GNUNET_i2s (&pid)); 891 GNUNET_i2s(&pid));
904 return GNUNET_OK; 892 return GNUNET_OK;
905 } 893 }
906 894
907 ve = find_validation_entry (address); 895 ve = find_validation_entry(address);
908 ve->network = papi->get_network_for_address (papi->cls, 896 ve->network = papi->get_network_for_address(papi->cls,
909 address); 897 address);
910 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); 898 GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network);
911 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, 899 ve->valid_until = GNUNET_TIME_absolute_max(ve->valid_until,
912 expiration); 900 expiration);
913 if (NULL == ve->revalidation_task) 901 if (NULL == ve->revalidation_task)
914 { 902 {
915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 903 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
916 "Starting revalidations for valid address `%s'\n", 904 "Starting revalidations for valid address `%s'\n",
917 GST_plugins_a2s (ve->address)); 905 GST_plugins_a2s(ve->address));
918 ve->next_validation = GNUNET_TIME_absolute_get(); 906 ve->next_validation = GNUNET_TIME_absolute_get();
919 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); 907 ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve);
920 } 908 }
921 validation_entry_changed (ve, 909 validation_entry_changed(ve,
922 GNUNET_TRANSPORT_VS_UPDATE); 910 GNUNET_TRANSPORT_VS_UPDATE);
923 memset (&prop, 0, sizeof (prop)); 911 memset(&prop, 0, sizeof(prop));
924 prop.scope = ve->network; 912 prop.scope = ve->network;
925 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); 913 prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2);
926 if (GNUNET_YES != ve->known_to_ats) 914 if (GNUNET_YES != ve->known_to_ats)
927 { 915 {
928 ve->known_to_ats = GNUNET_YES; 916 ve->known_to_ats = GNUNET_YES;
929 GST_ats_add_address (address, &prop); 917 GST_ats_add_address(address, &prop);
930 GNUNET_assert (GNUNET_YES == 918 GNUNET_assert(GNUNET_YES ==
931 GST_ats_is_known_no_session (ve->address)); 919 GST_ats_is_known_no_session(ve->address));
932 } 920 }
933 return GNUNET_OK; 921 return GNUNET_OK;
934} 922}
935 923
@@ -944,28 +932,28 @@ add_valid_address (void *cls,
944 * @param err_msg error message 932 * @param err_msg error message
945 */ 933 */
946static void 934static void
947process_peerinfo_hello (void *cls, 935process_peerinfo_hello(void *cls,
948 const struct GNUNET_PeerIdentity *peer, 936 const struct GNUNET_PeerIdentity *peer,
949 const struct GNUNET_HELLO_Message *hello, 937 const struct GNUNET_HELLO_Message *hello,
950 const char *err_msg) 938 const char *err_msg)
951{ 939{
952 GNUNET_assert (NULL != peer); 940 GNUNET_assert(NULL != peer);
953 if (NULL == hello) 941 if (NULL == hello)
954 return; 942 return;
955 if (0 == memcmp (&GST_my_identity, 943 if (0 == memcmp(&GST_my_identity,
956 peer, 944 peer,
957 sizeof (struct GNUNET_PeerIdentity))) 945 sizeof(struct GNUNET_PeerIdentity)))
958 { 946 {
959 /* Peerinfo returned own identity, skip validation */ 947 /* Peerinfo returned own identity, skip validation */
960 return; 948 return;
961 } 949 }
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 950 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
963 "Handling HELLO for peer `%s'\n", 951 "Handling HELLO for peer `%s'\n",
964 GNUNET_i2s (peer)); 952 GNUNET_i2s(peer));
965 GNUNET_assert (NULL == 953 GNUNET_assert(NULL ==
966 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, 954 GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO,
967 &add_valid_address, 955 &add_valid_address,
968 (void *) hello)); 956 (void *)hello));
969} 957}
970 958
971 959
@@ -975,7 +963,7 @@ process_peerinfo_hello (void *cls,
975 * @param max_fds maximum number of fds to use 963 * @param max_fds maximum number of fds to use
976 */ 964 */
977void 965void
978GST_validation_start (unsigned int max_fds) 966GST_validation_start(unsigned int max_fds)
979{ 967{
980 /** 968 /**
981 * Initialization for validation throttling 969 * Initialization for validation throttling
@@ -993,19 +981,19 @@ GST_validation_start (unsigned int max_fds)
993 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); 981 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
994 validations_fast_start_threshold = (max_fds / 2); 982 validations_fast_start_threshold = (max_fds / 2);
995 validations_running = 0; 983 validations_running = 0;
996 GNUNET_STATISTICS_set (GST_stats, 984 GNUNET_STATISTICS_set(GST_stats,
997 gettext_noop ("# validations running"), 985 gettext_noop("# validations running"),
998 validations_running, 986 validations_running,
999 GNUNET_NO); 987 GNUNET_NO);
1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 988 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1001 "Validation uses a fast start threshold of %u connections and a delay of %s\n", 989 "Validation uses a fast start threshold of %u connections and a delay of %s\n",
1002 validations_fast_start_threshold, 990 validations_fast_start_threshold,
1003 GNUNET_STRINGS_relative_time_to_string (validation_delay, 991 GNUNET_STRINGS_relative_time_to_string(validation_delay,
1004 GNUNET_YES)); 992 GNUNET_YES));
1005 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE, 993 validation_map = GNUNET_CONTAINER_multipeermap_create(VALIDATION_MAP_SIZE,
1006 GNUNET_NO); 994 GNUNET_NO);
1007 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, 995 pnc = GNUNET_PEERINFO_notify(GST_cfg, GNUNET_YES,
1008 &process_peerinfo_hello, NULL); 996 &process_peerinfo_hello, NULL);
1009} 997}
1010 998
1011 999
@@ -1013,14 +1001,14 @@ GST_validation_start (unsigned int max_fds)
1013 * Stop the validation subsystem. 1001 * Stop the validation subsystem.
1014 */ 1002 */
1015void 1003void
1016GST_validation_stop () 1004GST_validation_stop()
1017{ 1005{
1018 GNUNET_CONTAINER_multipeermap_iterate (validation_map, 1006 GNUNET_CONTAINER_multipeermap_iterate(validation_map,
1019 &cleanup_validation_entry, 1007 &cleanup_validation_entry,
1020 NULL); 1008 NULL);
1021 GNUNET_CONTAINER_multipeermap_destroy (validation_map); 1009 GNUNET_CONTAINER_multipeermap_destroy(validation_map);
1022 validation_map = NULL; 1010 validation_map = NULL;
1023 GNUNET_PEERINFO_notify_cancel (pnc); 1011 GNUNET_PEERINFO_notify_cancel(pnc);
1024} 1012}
1025 1013
1026 1014
@@ -1036,41 +1024,41 @@ GST_validation_stop ()
1036 * @param address target address 1024 * @param address target address
1037 */ 1025 */
1038static void 1026static void
1039multicast_pong (void *cls, 1027multicast_pong(void *cls,
1040 struct GNUNET_TIME_Absolute valid_until, 1028 struct GNUNET_TIME_Absolute valid_until,
1041 struct GNUNET_TIME_Absolute validation_block, 1029 struct GNUNET_TIME_Absolute validation_block,
1042 const struct GNUNET_HELLO_Address *address) 1030 const struct GNUNET_HELLO_Address *address)
1043{ 1031{
1044 struct TransportPongMessage *pong = cls; 1032 struct TransportPongMessage *pong = cls;
1045 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1033 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1046 struct GNUNET_ATS_Session *session; 1034 struct GNUNET_ATS_Session *session;
1047 1035
1048 papi = GST_plugins_find (address->transport_name); 1036 papi = GST_plugins_find(address->transport_name);
1049 if (NULL == papi) 1037 if (NULL == papi)
1050 { 1038 {
1051 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1039 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1052 "Plugin %s not supported, cannot send PONG\n", 1040 "Plugin %s not supported, cannot send PONG\n",
1053 address->transport_name); 1041 address->transport_name);
1054 return; 1042 return;
1055 } 1043 }
1056 GNUNET_assert (NULL != papi->send); 1044 GNUNET_assert(NULL != papi->send);
1057 GNUNET_assert (NULL != papi->get_session); 1045 GNUNET_assert(NULL != papi->get_session);
1058 session = papi->get_session(papi->cls, address); 1046 session = papi->get_session(papi->cls, address);
1059 if (NULL == session) 1047 if (NULL == session)
1060 { 1048 {
1061 GNUNET_break (0); 1049 GNUNET_break(0);
1062 return; 1050 return;
1063 } 1051 }
1064 GST_ats_new_session (address, session); 1052 GST_ats_new_session(address, session);
1065 papi->send (papi->cls, session, 1053 papi->send(papi->cls, session,
1066 (const char *) pong, 1054 (const char *)pong,
1067 ntohs (pong->header.size), 1055 ntohs(pong->header.size),
1068 PONG_PRIORITY, 1056 PONG_PRIORITY,
1069 ACCEPTABLE_PING_DELAY, 1057 ACCEPTABLE_PING_DELAY,
1070 NULL, NULL); 1058 NULL, NULL);
1071 GST_neighbours_notify_data_sent (address, 1059 GST_neighbours_notify_data_sent(address,
1072 session, 1060 session,
1073 pong->header.size); 1061 pong->header.size);
1074} 1062}
1075 1063
1076 1064
@@ -1084,10 +1072,10 @@ multicast_pong (void *cls,
1084 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 1072 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1085 */ 1073 */
1086int 1074int
1087GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, 1075GST_validation_handle_ping(const struct GNUNET_PeerIdentity *sender,
1088 const struct GNUNET_MessageHeader *hdr, 1076 const struct GNUNET_MessageHeader *hdr,
1089 const struct GNUNET_HELLO_Address *sender_address, 1077 const struct GNUNET_HELLO_Address *sender_address,
1090 struct GNUNET_ATS_Session *session) 1078 struct GNUNET_ATS_Session *session)
1091{ 1079{
1092 const struct TransportPingMessage *ping; 1080 const struct TransportPingMessage *ping;
1093 struct TransportPongMessage *pong; 1081 struct TransportPongMessage *pong;
@@ -1104,32 +1092,32 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1104 struct GNUNET_HELLO_Address address; 1092 struct GNUNET_HELLO_Address address;
1105 1093
1106 if (0 == 1094 if (0 ==
1107 memcmp (&GST_my_identity, 1095 memcmp(&GST_my_identity,
1108 sender, 1096 sender,
1109 sizeof (struct GNUNET_PeerIdentity))) 1097 sizeof(struct GNUNET_PeerIdentity)))
1110 return GNUNET_OK; /* our own, ignore! */ 1098 return GNUNET_OK; /* our own, ignore! */
1111 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) 1099 if (ntohs(hdr->size) < sizeof(struct TransportPingMessage))
1112 { 1100 {
1113 GNUNET_break_op (0); 1101 GNUNET_break_op(0);
1114 return GNUNET_SYSERR; 1102 return GNUNET_SYSERR;
1115 } 1103 }
1116 ping = (const struct TransportPingMessage *) hdr; 1104 ping = (const struct TransportPingMessage *)hdr;
1117 if (0 != 1105 if (0 !=
1118 memcmp (&ping->target, 1106 memcmp(&ping->target,
1119 &GST_my_identity, 1107 &GST_my_identity,
1120 sizeof (struct GNUNET_PeerIdentity))) 1108 sizeof(struct GNUNET_PeerIdentity)))
1121 { 1109 {
1122 GNUNET_STATISTICS_update (GST_stats, 1110 GNUNET_STATISTICS_update(GST_stats,
1123 gettext_noop 1111 gettext_noop
1124 ("# PING message for different peer received"), 1, 1112 ("# PING message for different peer received"), 1,
1125 GNUNET_NO); 1113 GNUNET_NO);
1126 return GNUNET_SYSERR; 1114 return GNUNET_SYSERR;
1127 } 1115 }
1128 GNUNET_STATISTICS_update (GST_stats, 1116 GNUNET_STATISTICS_update(GST_stats,
1129 gettext_noop ("# PING messages received"), 1, 1117 gettext_noop("# PING messages received"), 1,
1130 GNUNET_NO); 1118 GNUNET_NO);
1131 addr = (const char *) &ping[1]; 1119 addr = (const char *)&ping[1];
1132 len_address = ntohs (hdr->size) - sizeof (struct TransportPingMessage); 1120 len_address = ntohs(hdr->size) - sizeof(struct TransportPingMessage);
1133 /* peer wants to confirm that this is one of our addresses, this is what is 1121 /* peer wants to confirm that this is one of our addresses, this is what is
1134 * used for address validation */ 1122 * used for address validation */
1135 1123
@@ -1137,198 +1125,198 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1137 sig_cache_exp = NULL; 1125 sig_cache_exp = NULL;
1138 papi = NULL; 1126 papi = NULL;
1139 if (len_address > 0) 1127 if (len_address > 0)
1140 {
1141 addrend = memchr (addr, '\0', len_address);
1142 if (NULL == addrend)
1143 { 1128 {
1144 GNUNET_break_op (0); 1129 addrend = memchr(addr, '\0', len_address);
1145 return GNUNET_SYSERR; 1130 if (NULL == addrend)
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 }
1146 } 1205 }
1147 addrend++; 1206 else
1148 len_plugin = strlen (addr) + 1;
1149 len_address -= len_plugin;
1150 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1151 address.address = addrend;
1152 address.address_length = len_address;
1153 address.transport_name = addr;
1154 address.peer = GST_my_identity;
1155
1156 if (NULL == address.transport_name)
1157 {
1158 GNUNET_break (0);
1159 }
1160
1161 if (0 != strstr (address.transport_name, "_client"))
1162 {
1163 plugin_name = GNUNET_strdup (address.transport_name);
1164 pos = strstr (plugin_name, "_client");
1165 GNUNET_assert (NULL != pos);
1166 GNUNET_snprintf (pos, strlen ("_server") + 1, "%s", "_server");
1167 }
1168 else
1169 plugin_name = GNUNET_strdup (address.transport_name);
1170
1171 if (NULL == (papi = GST_plugins_find (plugin_name)))
1172 {
1173 /* we don't have the plugin for this address */
1174 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1175 _("Plugin `%s' not available, cannot confirm having this address\n"),
1176 plugin_name);
1177 GNUNET_free (plugin_name);
1178 return GNUNET_SYSERR;
1179 }
1180 GNUNET_free (plugin_name);
1181 if (GNUNET_OK !=
1182 papi->check_address (papi->cls,
1183 addrend,
1184 len_address))
1185 {
1186 GNUNET_STATISTICS_update (GST_stats,
1187 gettext_noop
1188 ("# failed address checks during validation"), 1,
1189 GNUNET_NO);
1190 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1191 _("Address `%s' is not one of my addresses, not confirming PING\n"),
1192 GST_plugins_a2s (&address));
1193 return GNUNET_SYSERR;
1194 }
1195 else
1196 { 1207 {
1197 GNUNET_STATISTICS_update (GST_stats, 1208 addrend = NULL; /* make gcc happy */
1198 gettext_noop 1209 len_plugin = 0;
1199 ("# successful address checks during validation"), 1, 1210 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1200 GNUNET_NO); 1211 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1201 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1202 "Address `%s' is one of my addresses, confirming PING\n",
1203 GST_plugins_a2s (&address));
1204 }
1205 1212
1206 if (GNUNET_YES != 1213 sig_cache = &no_address_signature;
1207 GST_hello_test_address (&address, 1214 sig_cache_exp = &no_address_signature_expiration;
1208 &sig_cache,
1209 &sig_cache_exp))
1210 {
1211 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1212 _("Not confirming PING from peer `%s' with address `%s' since I cannot confirm having this address.\n"),
1213 GNUNET_i2s (sender),
1214 GST_plugins_a2s (&address));
1215 return GNUNET_SYSERR;
1216 } 1215 }
1217 }
1218 else
1219 {
1220 addrend = NULL; /* make gcc happy */
1221 len_plugin = 0;
1222 static struct GNUNET_CRYPTO_EddsaSignature no_address_signature;
1223 static struct GNUNET_TIME_Absolute no_address_signature_expiration;
1224 1216
1225 sig_cache = &no_address_signature; 1217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1226 sig_cache_exp = &no_address_signature_expiration; 1218 "I am `%s', sending PONG to peer `%s'\n",
1227 } 1219 GNUNET_i2s_full(&GST_my_identity),
1228 1220 GNUNET_i2s(sender));
1229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1230 "I am `%s', sending PONG to peer `%s'\n",
1231 GNUNET_i2s_full (&GST_my_identity),
1232 GNUNET_i2s (sender));
1233 1221
1234 /* message with structure: 1222 /* message with structure:
1235 * [TransportPongMessage][Transport name][Address] */ 1223 * [TransportPongMessage][Transport name][Address] */
1236 1224
1237 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + len_address + len_plugin); 1225 pong = GNUNET_malloc(sizeof(struct TransportPongMessage) + len_address + len_plugin);
1238 pong->header.size = 1226 pong->header.size =
1239 htons (sizeof (struct TransportPongMessage) + len_address + len_plugin); 1227 htons(sizeof(struct TransportPongMessage) + len_address + len_plugin);
1240 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 1228 pong->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
1241 pong->purpose.size = 1229 pong->purpose.size =
1242 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 1230 htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
1243 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) + 1231 sizeof(uint32_t) + sizeof(struct GNUNET_TIME_AbsoluteNBO) +
1244 len_address + len_plugin); 1232 len_address + len_plugin);
1245 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 1233 pong->purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
1246 GNUNET_memcpy (&pong->challenge, &ping->challenge, sizeof (ping->challenge)); 1234 GNUNET_memcpy(&pong->challenge, &ping->challenge, sizeof(ping->challenge));
1247 pong->addrlen = htonl (len_address + len_plugin); 1235 pong->addrlen = htonl(len_address + len_plugin);
1248 GNUNET_memcpy (&pong[1], addr, len_plugin); /* Copy transport plugin */ 1236 GNUNET_memcpy(&pong[1], addr, len_plugin); /* Copy transport plugin */
1249 if (len_address > 0) 1237 if (len_address > 0)
1250 { 1238 {
1251 GNUNET_assert (NULL != addrend); 1239 GNUNET_assert(NULL != addrend);
1252 GNUNET_memcpy (&((char *) &pong[1])[len_plugin], addrend, len_address); 1240 GNUNET_memcpy(&((char *)&pong[1])[len_plugin], addrend, len_address);
1253 } 1241 }
1254 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value_us < 1242 if (GNUNET_TIME_absolute_get_remaining(*sig_cache_exp).rel_value_us <
1255 PONG_SIGNATURE_LIFETIME.rel_value_us / 4) 1243 PONG_SIGNATURE_LIFETIME.rel_value_us / 4)
1256 {
1257 /* create / update cached sig */
1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1259 "Creating PONG signature to indicate ownership.\n");
1260 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
1261 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
1262 if (GNUNET_OK !=
1263 GNUNET_CRYPTO_eddsa_sign (GST_my_private_key, &pong->purpose,
1264 sig_cache))
1265 { 1244 {
1266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1245 /* create / update cached sig */
1267 _("Failed to create PONG signature for peer `%s'\n"), GNUNET_i2s (sender)); 1246 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1247 "Creating PONG signature to indicate ownership.\n");
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 }
1268 } 1257 }
1269 }
1270 else 1258 else
1271 { 1259 {
1272 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); 1260 pong->expiration = GNUNET_TIME_absolute_hton(*sig_cache_exp);
1273 } 1261 }
1274 pong->signature = *sig_cache; 1262 pong->signature = *sig_cache;
1275 1263
1276 GNUNET_assert (NULL != sender_address); 1264 GNUNET_assert(NULL != sender_address);
1277 1265
1278 /* first see if the session we got this PING from can be used to transmit 1266 /* first see if the session we got this PING from can be used to transmit
1279 * a response reliably */ 1267 * a response reliably */
1280 if (NULL == papi) 1268 if (NULL == papi)
1281 {
1282 ret = -1;
1283 }
1284 else
1285 {
1286 GNUNET_assert (NULL != papi->send);
1287 GNUNET_assert (NULL != papi->get_session);
1288 if (NULL == session)
1289 { 1269 {
1290 session = papi->get_session (papi->cls, sender_address);
1291 }
1292 if (NULL == session)
1293 {
1294 GNUNET_break (0);
1295 ret = -1; 1270 ret = -1;
1296 } 1271 }
1297 else 1272 else
1298 { 1273 {
1299 ret = papi->send (papi->cls, session, 1274 GNUNET_assert(NULL != papi->send);
1300 (const char *) pong, 1275 GNUNET_assert(NULL != papi->get_session);
1301 ntohs (pong->header.size), 1276 if (NULL == session)
1302 PONG_PRIORITY, ACCEPTABLE_PING_DELAY, 1277 {
1303 NULL, NULL); 1278 session = papi->get_session(papi->cls, sender_address);
1304 if (-1 != ret) 1279 }
1305 GST_neighbours_notify_data_sent (sender_address, 1280 if (NULL == session)
1306 session, 1281 {
1307 pong->header.size); 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 }
1308 } 1297 }
1309 }
1310 if (-1 != ret) 1298 if (-1 != ret)
1311 { 1299 {
1312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1313 "Transmitted PONG to `%s' via reliable mechanism\n", 1301 "Transmitted PONG to `%s' via reliable mechanism\n",
1314 GNUNET_i2s (sender)); 1302 GNUNET_i2s(sender));
1315 /* done! */ 1303 /* done! */
1316 GNUNET_STATISTICS_update (GST_stats, 1304 GNUNET_STATISTICS_update(GST_stats,
1317 gettext_noop 1305 gettext_noop
1318 ("# PONGs unicast via reliable transport"), 1, 1306 ("# PONGs unicast via reliable transport"), 1,
1319 GNUNET_NO); 1307 GNUNET_NO);
1320 GNUNET_free (pong); 1308 GNUNET_free(pong);
1321 return GNUNET_OK; 1309 return GNUNET_OK;
1322 } 1310 }
1323 1311
1324 /* no reliable method found, try transmission via all known addresses */ 1312 /* no reliable method found, try transmission via all known addresses */
1325 GNUNET_STATISTICS_update (GST_stats, 1313 GNUNET_STATISTICS_update(GST_stats,
1326 gettext_noop 1314 gettext_noop
1327 ("# PONGs multicast to all available addresses"), 1, 1315 ("# PONGs multicast to all available addresses"), 1,
1328 GNUNET_NO); 1316 GNUNET_NO);
1329 GST_validation_get_addresses (sender, 1317 GST_validation_get_addresses(sender,
1330 &multicast_pong, pong); 1318 &multicast_pong, pong);
1331 GNUNET_free (pong); 1319 GNUNET_free(pong);
1332 return GNUNET_OK; 1320 return GNUNET_OK;
1333} 1321}
1334 1322
@@ -1339,36 +1327,36 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1339 * @param address address we should try to validate 1327 * @param address address we should try to validate
1340 */ 1328 */
1341void 1329void
1342GST_validation_handle_address (const struct GNUNET_HELLO_Address *address) 1330GST_validation_handle_address(const struct GNUNET_HELLO_Address *address)
1343{ 1331{
1344 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1332 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1345 struct ValidationEntry *ve; 1333 struct ValidationEntry *ve;
1346 1334
1347 papi = GST_plugins_find (address->transport_name); 1335 papi = GST_plugins_find(address->transport_name);
1348 if (NULL == papi) 1336 if (NULL == papi)
1349 { 1337 {
1350 /* This plugin is currently unvailable ... ignore */ 1338 /* This plugin is currently unvailable ... ignore */
1351 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1339 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1352 "No plugin available for %s\n", 1340 "No plugin available for %s\n",
1353 address->transport_name); 1341 address->transport_name);
1354 return; 1342 return;
1355 } 1343 }
1356 ve = find_validation_entry (address); 1344 ve = find_validation_entry(address);
1357 if (NULL == ve->revalidation_task) 1345 if (NULL == ve->revalidation_task)
1358 { 1346 {
1359 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1347 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1360 "Validation process started for fresh address `%s' of %s\n", 1348 "Validation process started for fresh address `%s' of %s\n",
1361 GST_plugins_a2s (ve->address), 1349 GST_plugins_a2s(ve->address),
1362 GNUNET_i2s (&ve->address->peer)); 1350 GNUNET_i2s(&ve->address->peer));
1363 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); 1351 ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address, ve);
1364 } 1352 }
1365 else 1353 else
1366 { 1354 {
1367 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1355 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1368 "Validation already running for address `%s' of %s\n", 1356 "Validation already running for address `%s' of %s\n",
1369 GST_plugins_a2s (ve->address), 1357 GST_plugins_a2s(ve->address),
1370 GNUNET_i2s (&ve->address->peer)); 1358 GNUNET_i2s(&ve->address->peer));
1371 } 1359 }
1372} 1360}
1373 1361
1374 1362
@@ -1382,17 +1370,17 @@ GST_validation_handle_address (const struct GNUNET_HELLO_Address *address)
1382 * @return #GNUNET_OK (keep the address) 1370 * @return #GNUNET_OK (keep the address)
1383 */ 1371 */
1384static int 1372static int
1385validate_address_iterator (void *cls, 1373validate_address_iterator(void *cls,
1386 const struct GNUNET_HELLO_Address *address, 1374 const struct GNUNET_HELLO_Address *address,
1387 struct GNUNET_TIME_Absolute expiration) 1375 struct GNUNET_TIME_Absolute expiration)
1388{ 1376{
1389 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 1377 if (0 == GNUNET_TIME_absolute_get_remaining(expiration).rel_value_us)
1390 { 1378 {
1391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1379 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1392 "Skipping expired address from HELLO\n"); 1380 "Skipping expired address from HELLO\n");
1393 return GNUNET_OK; /* expired */ 1381 return GNUNET_OK; /* expired */
1394 } 1382 }
1395 GST_validation_handle_address (address); 1383 GST_validation_handle_address(address);
1396 return GNUNET_OK; 1384 return GNUNET_OK;
1397} 1385}
1398 1386
@@ -1407,19 +1395,19 @@ validate_address_iterator (void *cls,
1407 * end of the iteration. 1395 * end of the iteration.
1408 */ 1396 */
1409static ssize_t 1397static ssize_t
1410add_valid_peer_address (void *cls, 1398add_valid_peer_address(void *cls,
1411 size_t max, 1399 size_t max,
1412 void *buf) 1400 void *buf)
1413{ 1401{
1414 struct ValidationEntry *ve = cls; 1402 struct ValidationEntry *ve = cls;
1415 1403
1416 if (GNUNET_YES == ve->copied) 1404 if (GNUNET_YES == ve->copied)
1417 return GNUNET_SYSERR; /* Done */ 1405 return GNUNET_SYSERR; /* Done */
1418 ve->copied = GNUNET_YES; 1406 ve->copied = GNUNET_YES;
1419 return GNUNET_HELLO_add_address (ve->address, 1407 return GNUNET_HELLO_add_address(ve->address,
1420 ve->valid_until, 1408 ve->valid_until,
1421 buf, 1409 buf,
1422 max); 1410 max);
1423} 1411}
1424 1412
1425 1413
@@ -1432,8 +1420,8 @@ add_valid_peer_address (void *cls,
1432 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 1420 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1433 */ 1421 */
1434int 1422int
1435GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, 1423GST_validation_handle_pong(const struct GNUNET_PeerIdentity *sender,
1436 const struct GNUNET_MessageHeader *hdr) 1424 const struct GNUNET_MessageHeader *hdr)
1437{ 1425{
1438 const struct TransportPongMessage *pong; 1426 const struct TransportPongMessage *pong;
1439 struct ValidationEntry *ve; 1427 struct ValidationEntry *ve;
@@ -1448,197 +1436,197 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1448 int do_verify; 1436 int do_verify;
1449 1437
1450 if (0 == 1438 if (0 ==
1451 memcmp (&GST_my_identity, 1439 memcmp(&GST_my_identity,
1452 sender, 1440 sender,
1453 sizeof (struct GNUNET_PeerIdentity))) 1441 sizeof(struct GNUNET_PeerIdentity)))
1454 return GNUNET_OK; /* our own, ignore! */ 1442 return GNUNET_OK; /* our own, ignore! */
1455 1443
1456 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) 1444 if (ntohs(hdr->size) < sizeof(struct TransportPongMessage))
1457 { 1445 {
1458 GNUNET_break_op (0); 1446 GNUNET_break_op(0);
1459 return GNUNET_SYSERR; 1447 return GNUNET_SYSERR;
1460 } 1448 }
1461 GNUNET_STATISTICS_update (GST_stats, 1449 GNUNET_STATISTICS_update(GST_stats,
1462 gettext_noop ("# PONG messages received"), 1, 1450 gettext_noop("# PONG messages received"), 1,
1463 GNUNET_NO); 1451 GNUNET_NO);
1464 1452
1465 /* message with structure: 1453 /* message with structure:
1466 * [TransportPongMessage][Transport name][Address] */ 1454 * [TransportPongMessage][Transport name][Address] */
1467 1455
1468 pong = (const struct TransportPongMessage *) hdr; 1456 pong = (const struct TransportPongMessage *)hdr;
1469 tname = (const char *) &pong[1]; 1457 tname = (const char *)&pong[1];
1470 size = ntohs (hdr->size) - sizeof (struct TransportPongMessage); 1458 size = ntohs(hdr->size) - sizeof(struct TransportPongMessage);
1471 addr = memchr (tname, '\0', size); 1459 addr = memchr(tname, '\0', size);
1472 if (NULL == addr) 1460 if (NULL == addr)
1473 { 1461 {
1474 GNUNET_break_op (0); 1462 GNUNET_break_op(0);
1475 return GNUNET_SYSERR; 1463 return GNUNET_SYSERR;
1476 } 1464 }
1477 addr++; 1465 addr++;
1478 slen = strlen (tname) + 1; 1466 slen = strlen(tname) + 1;
1479 addrlen = size - slen; 1467 addrlen = size - slen;
1480 1468
1481 if (NULL == GST_plugins_find (tname)) 1469 if (NULL == GST_plugins_find(tname))
1482 { 1470 {
1483 /* we got the PONG, but the transport plugin specified in it 1471 /* we got the PONG, but the transport plugin specified in it
1484 is not supported by this peer, so this cannot be a good 1472 is not supported by this peer, so this cannot be a good
1485 PONG for us. */ 1473 PONG for us. */
1486 GNUNET_break_op (0); 1474 GNUNET_break_op(0);
1487 return GNUNET_OK; 1475 return GNUNET_OK;
1488 } 1476 }
1489 1477
1490 address.peer = *sender; 1478 address.peer = *sender;
1491 address.address = addr; 1479 address.address = addr;
1492 address.address_length = addrlen; 1480 address.address_length = addrlen;
1493 address.transport_name = tname; 1481 address.transport_name = tname;
1494 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; 1482 address.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
1495 ve = find_validation_entry (&address); 1483 ve = find_validation_entry(&address);
1496 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong)) 1484 if ((NULL == ve) || (GNUNET_NO == ve->expecting_pong))
1497 { 1485 {
1498 GNUNET_STATISTICS_update (GST_stats, 1486 GNUNET_STATISTICS_update(GST_stats,
1499 gettext_noop 1487 gettext_noop
1500 ("# PONGs dropped, no matching pending validation"), 1488 ("# PONGs dropped, no matching pending validation"),
1501 1, GNUNET_NO); 1489 1, GNUNET_NO);
1502 return GNUNET_OK; 1490 return GNUNET_OK;
1503 } 1491 }
1504 /* now check that PONG is well-formed */ 1492 /* now check that PONG is well-formed */
1505 if (0 != memcmp (&ve->address->peer, 1493 if (0 != memcmp(&ve->address->peer,
1506 sender, 1494 sender,
1507 sizeof (struct GNUNET_PeerIdentity))) 1495 sizeof(struct GNUNET_PeerIdentity)))
1508 { 1496 {
1509 GNUNET_break_op (0); 1497 GNUNET_break_op(0);
1510 return GNUNET_SYSERR; 1498 return GNUNET_SYSERR;
1511 } 1499 }
1512 if (0 == 1500 if (0 ==
1513 GNUNET_TIME_absolute_get_remaining 1501 GNUNET_TIME_absolute_get_remaining
1514 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value_us) 1502 (GNUNET_TIME_absolute_ntoh(pong->expiration)).rel_value_us)
1515 { 1503 {
1516 GNUNET_STATISTICS_update (GST_stats, 1504 GNUNET_STATISTICS_update(GST_stats,
1517 gettext_noop 1505 gettext_noop
1518 ("# PONGs dropped, signature expired"), 1, 1506 ("# PONGs dropped, signature expired"), 1,
1519 GNUNET_NO); 1507 GNUNET_NO);
1520 return GNUNET_SYSERR; 1508 return GNUNET_SYSERR;
1521 } 1509 }
1522 1510
1523 sig_res = GNUNET_SYSERR; 1511 sig_res = GNUNET_SYSERR;
1524 do_verify = GNUNET_YES; 1512 do_verify = GNUNET_YES;
1525 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us) 1513 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us)
1526 {
1527 /* We have a cached and valid signature for this peer,
1528 * try to compare instead of verify */
1529 if (0 == memcmp (&ve->pong_sig_cache,
1530 &pong->signature,
1531 sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1532 { 1514 {
1533 /* signatures are identical, we can skip verification */ 1515 /* We have a cached and valid signature for this peer,
1534 sig_res = GNUNET_OK; 1516 * try to compare instead of verify */
1535 do_verify = GNUNET_NO; 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 }
1536 } 1530 }
1537 else
1538 {
1539 sig_res = GNUNET_SYSERR;
1540 /* signatures do not match, we have to verify */
1541 }
1542 }
1543 1531
1544 if (GNUNET_YES == do_verify) 1532 if (GNUNET_YES == do_verify)
1545 {
1546 /* Do expensive verification */
1547 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1548 &pong->purpose,
1549 &pong->signature,
1550 &ve->address->peer.public_key);
1551 if (sig_res == GNUNET_SYSERR)
1552 { 1533 {
1553 GNUNET_break_op (0); 1534 /* Do expensive verification */
1554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1535 sig_res = GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1555 "Failed to verify: invalid signature on address `%s':%s from peer `%s'\n", 1536 &pong->purpose,
1556 tname, 1537 &pong->signature,
1557 GST_plugins_a2s (ve->address), 1538 &ve->address->peer.public_key);
1558 GNUNET_i2s (sender)); 1539 if (sig_res == GNUNET_SYSERR)
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 }
1559 } 1548 }
1560 }
1561 if (sig_res == GNUNET_SYSERR) 1549 if (sig_res == GNUNET_SYSERR)
1562 { 1550 {
1563 GNUNET_break_op (0); 1551 GNUNET_break_op(0);
1564 return GNUNET_SYSERR; 1552 return GNUNET_SYSERR;
1565 } 1553 }
1566 1554
1567 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1555 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1568 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", 1556 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1569 GNUNET_i2s (sender), 1557 GNUNET_i2s(sender),
1570 tname, 1558 tname,
1571 GST_plugins_a2s (ve->address)); 1559 GST_plugins_a2s(ve->address));
1572 GNUNET_STATISTICS_update (GST_stats, 1560 GNUNET_STATISTICS_update(GST_stats,
1573 gettext_noop ("# validations succeeded"), 1561 gettext_noop("# validations succeeded"),
1574 1, 1562 1,
1575 GNUNET_NO); 1563 GNUNET_NO);
1576 /* validity achieved, remember it! */ 1564 /* validity achieved, remember it! */
1577 ve->expecting_pong = GNUNET_NO; 1565 ve->expecting_pong = GNUNET_NO;
1578 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 1566 ve->valid_until = GNUNET_TIME_relative_to_absolute(HELLO_ADDRESS_EXPIRATION);
1579 ve->pong_sig_cache = pong->signature; 1567 ve->pong_sig_cache = pong->signature;
1580 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh (pong->expiration); 1568 ve->pong_sig_valid_until = GNUNET_TIME_absolute_ntoh(pong->expiration);
1581 ve->latency = GNUNET_TIME_absolute_get_duration (ve->send_time); 1569 ve->latency = GNUNET_TIME_absolute_get_duration(ve->send_time);
1582 { 1570 {
1583 if (GNUNET_YES == ve->known_to_ats) 1571 if (GNUNET_YES == ve->known_to_ats)
1584 { 1572 {
1585 GNUNET_assert (GNUNET_YES == 1573 GNUNET_assert(GNUNET_YES ==
1586 GST_ats_is_known_no_session (ve->address)); 1574 GST_ats_is_known_no_session(ve->address));
1587 GST_ats_update_delay (ve->address, 1575 GST_ats_update_delay(ve->address,
1588 GNUNET_TIME_relative_divide (ve->latency, 2)); 1576 GNUNET_TIME_relative_divide(ve->latency, 2));
1589 } 1577 }
1590 else 1578 else
1591 { 1579 {
1592 struct GNUNET_ATS_Properties prop; 1580 struct GNUNET_ATS_Properties prop;
1593 1581
1594 memset (&prop, 0, sizeof (prop)); 1582 memset(&prop, 0, sizeof(prop));
1595 GNUNET_break (GNUNET_NT_UNSPECIFIED != ve->network); 1583 GNUNET_break(GNUNET_NT_UNSPECIFIED != ve->network);
1596 prop.scope = ve->network; 1584 prop.scope = ve->network;
1597 prop.delay = GNUNET_TIME_relative_divide (ve->latency, 2); 1585 prop.delay = GNUNET_TIME_relative_divide(ve->latency, 2);
1598 GNUNET_assert (GNUNET_NO == 1586 GNUNET_assert(GNUNET_NO ==
1599 GST_ats_is_known_no_session (ve->address)); 1587 GST_ats_is_known_no_session(ve->address));
1600 ve->known_to_ats = GNUNET_YES; 1588 ve->known_to_ats = GNUNET_YES;
1601 GST_ats_add_address (ve->address, &prop); 1589 GST_ats_add_address(ve->address, &prop);
1602 GNUNET_assert (GNUNET_YES == 1590 GNUNET_assert(GNUNET_YES ==
1603 GST_ats_is_known_no_session (ve->address)); 1591 GST_ats_is_known_no_session(ve->address));
1604 } 1592 }
1605 } 1593 }
1606 if (validations_running > 0) 1594 if (validations_running > 0)
1607 { 1595 {
1608 validations_running--; 1596 validations_running--;
1609 GNUNET_STATISTICS_set (GST_stats, 1597 GNUNET_STATISTICS_set(GST_stats,
1610 gettext_noop ("# validations running"), 1598 gettext_noop("# validations running"),
1611 validations_running, 1599 validations_running,
1612 GNUNET_NO); 1600 GNUNET_NO);
1613 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1601 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1614 "Validation finished, %u validation processes running\n", 1602 "Validation finished, %u validation processes running\n",
1615 validations_running); 1603 validations_running);
1616 } 1604 }
1617 else 1605 else
1618 { 1606 {
1619 GNUNET_break (0); 1607 GNUNET_break(0);
1620 } 1608 }
1621 1609
1622 /* Notify about new validity */ 1610 /* Notify about new validity */
1623 validation_entry_changed (ve, 1611 validation_entry_changed(ve,
1624 GNUNET_TRANSPORT_VS_UPDATE); 1612 GNUNET_TRANSPORT_VS_UPDATE);
1625 1613
1626 /* build HELLO to store in PEERINFO */ 1614 /* build HELLO to store in PEERINFO */
1627 GNUNET_STATISTICS_update (GST_stats, 1615 GNUNET_STATISTICS_update(GST_stats,
1628 gettext_noop ("# HELLOs given to peerinfo"), 1616 gettext_noop("# HELLOs given to peerinfo"),
1629 1, 1617 1,
1630 GNUNET_NO); 1618 GNUNET_NO);
1631 ve->copied = GNUNET_NO; 1619 ve->copied = GNUNET_NO;
1632 hello = GNUNET_HELLO_create (&ve->address->peer.public_key, 1620 hello = GNUNET_HELLO_create(&ve->address->peer.public_key,
1633 &add_valid_peer_address, 1621 &add_valid_peer_address,
1634 ve, 1622 ve,
1635 GNUNET_NO); 1623 GNUNET_NO);
1636 GNUNET_break (NULL != 1624 GNUNET_break(NULL !=
1637 GNUNET_PEERINFO_add_peer (GST_peerinfo, 1625 GNUNET_PEERINFO_add_peer(GST_peerinfo,
1638 hello, 1626 hello,
1639 NULL, 1627 NULL,
1640 NULL)); 1628 NULL));
1641 GNUNET_free (hello); 1629 GNUNET_free(hello);
1642 return GNUNET_OK; 1630 return GNUNET_OK;
1643} 1631}
1644 1632
@@ -1651,42 +1639,42 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1651 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error 1639 * @return #GNUNET_OK if the message was fine, #GNUNET_SYSERR on serious error
1652 */ 1640 */
1653int 1641int
1654GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) 1642GST_validation_handle_hello(const struct GNUNET_MessageHeader *hello)
1655{ 1643{
1656 const struct GNUNET_HELLO_Message *hm = 1644 const struct GNUNET_HELLO_Message *hm =
1657 (const struct GNUNET_HELLO_Message *) hello; 1645 (const struct GNUNET_HELLO_Message *)hello;
1658 struct GNUNET_PeerIdentity pid; 1646 struct GNUNET_PeerIdentity pid;
1659 int friend; 1647 int friend;
1660 1648
1661 friend = GNUNET_HELLO_is_friend_only (hm); 1649 friend = GNUNET_HELLO_is_friend_only(hm);
1662 if ( ( (GNUNET_YES != friend) && 1650 if (((GNUNET_YES != friend) &&
1663 (GNUNET_NO != friend) ) || 1651 (GNUNET_NO != friend)) ||
1664 (GNUNET_OK != GNUNET_HELLO_get_id (hm, &pid)) ) 1652 (GNUNET_OK != GNUNET_HELLO_get_id(hm, &pid)))
1665 { 1653 {
1666 /* malformed HELLO */ 1654 /* malformed HELLO */
1667 GNUNET_break_op (0); 1655 GNUNET_break_op(0);
1668 return GNUNET_SYSERR; 1656 return GNUNET_SYSERR;
1669 } 1657 }
1670 if (0 == 1658 if (0 ==
1671 memcmp (&GST_my_identity, 1659 memcmp(&GST_my_identity,
1672 &pid, 1660 &pid,
1673 sizeof (struct GNUNET_PeerIdentity))) 1661 sizeof(struct GNUNET_PeerIdentity)))
1674 { 1662 {
1675 /* got our own HELLO, how boring */ 1663 /* got our own HELLO, how boring */
1676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1664 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1677 "Validation received our own HELLO (%s), ignoring\n", 1665 "Validation received our own HELLO (%s), ignoring\n",
1678 GNUNET_i2s (&pid)); 1666 GNUNET_i2s(&pid));
1679 return GNUNET_OK; 1667 return GNUNET_OK;
1680 } 1668 }
1681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1669 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1682 "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n", 1670 "Validation received HELLO message for peer `%s' with size %u, checking for new addresses\n",
1683 GNUNET_i2s (&pid), 1671 GNUNET_i2s(&pid),
1684 ntohs (hello->size)); 1672 ntohs(hello->size));
1685 GNUNET_assert (NULL == 1673 GNUNET_assert(NULL ==
1686 GNUNET_HELLO_iterate_addresses (hm, 1674 GNUNET_HELLO_iterate_addresses(hm,
1687 GNUNET_NO, 1675 GNUNET_NO,
1688 &validate_address_iterator, 1676 &validate_address_iterator,
1689 NULL)); 1677 NULL));
1690 return GNUNET_OK; 1678 return GNUNET_OK;
1691} 1679}
1692 1680
@@ -1694,8 +1682,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1694/** 1682/**
1695 * Closure for #iterate_addresses(). 1683 * Closure for #iterate_addresses().
1696 */ 1684 */
1697struct IteratorContext 1685struct IteratorContext {
1698{
1699 /** 1686 /**
1700 * Function to call on each address. 1687 * Function to call on each address.
1701 */ 1688 */
@@ -1705,7 +1692,6 @@ struct IteratorContext
1705 * Closure for @e cb. 1692 * Closure for @e cb.
1706 */ 1693 */
1707 void *cb_cls; 1694 void *cb_cls;
1708
1709}; 1695};
1710 1696
1711 1697
@@ -1718,17 +1704,17 @@ struct IteratorContext
1718 * @return #GNUNET_OK (continue to iterate) 1704 * @return #GNUNET_OK (continue to iterate)
1719 */ 1705 */
1720static int 1706static int
1721iterate_addresses (void *cls, 1707iterate_addresses(void *cls,
1722 const struct GNUNET_PeerIdentity *key, 1708 const struct GNUNET_PeerIdentity *key,
1723 void *value) 1709 void *value)
1724{ 1710{
1725 struct IteratorContext *ic = cls; 1711 struct IteratorContext *ic = cls;
1726 struct ValidationEntry *ve = value; 1712 struct ValidationEntry *ve = value;
1727 1713
1728 ic->cb (ic->cb_cls, 1714 ic->cb(ic->cb_cls,
1729 ve->valid_until, 1715 ve->valid_until,
1730 ve->revalidation_block, 1716 ve->revalidation_block,
1731 ve->address); 1717 ve->address);
1732 return GNUNET_OK; 1718 return GNUNET_OK;
1733} 1719}
1734 1720
@@ -1742,17 +1728,17 @@ iterate_addresses (void *cls,
1742 * @param cb_cls closure for @a cb 1728 * @param cb_cls closure for @a cb
1743 */ 1729 */
1744void 1730void
1745GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, 1731GST_validation_get_addresses(const struct GNUNET_PeerIdentity *target,
1746 GST_ValidationAddressCallback cb, 1732 GST_ValidationAddressCallback cb,
1747 void *cb_cls) 1733 void *cb_cls)
1748{ 1734{
1749 struct IteratorContext ic; 1735 struct IteratorContext ic;
1750 1736
1751 ic.cb = cb; 1737 ic.cb = cb;
1752 ic.cb_cls = cb_cls; 1738 ic.cb_cls = cb_cls;
1753 GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, 1739 GNUNET_CONTAINER_multipeermap_get_multiple(validation_map,
1754 target, 1740 target,
1755 &iterate_addresses, &ic); 1741 &iterate_addresses, &ic);
1756} 1742}
1757 1743
1758 1744
@@ -1766,37 +1752,37 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1766 * #GNUNET_NO if we are no longer using the address for a connection 1752 * #GNUNET_NO if we are no longer using the address for a connection
1767 */ 1753 */
1768void 1754void
1769GST_validation_set_address_use (const struct GNUNET_HELLO_Address *address, 1755GST_validation_set_address_use(const struct GNUNET_HELLO_Address *address,
1770 int in_use) 1756 int in_use)
1771{ 1757{
1772 struct ValidationEntry *ve; 1758 struct ValidationEntry *ve;
1773 1759
1774 if (GNUNET_HELLO_address_check_option (address, 1760 if (GNUNET_HELLO_address_check_option(address,
1775 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 1761 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
1776 return; /* ignore inbound for validation */ 1762 return; /* ignore inbound for validation */
1777 if (NULL == GST_plugins_find (address->transport_name)) 1763 if (NULL == GST_plugins_find(address->transport_name))
1778 { 1764 {
1779 /* How can we use an address for which we don't have the plugin? */ 1765 /* How can we use an address for which we don't have the plugin? */
1780 GNUNET_break (0); 1766 GNUNET_break(0);
1781 return; 1767 return;
1782 } 1768 }
1783 ve = find_validation_entry (address); 1769 ve = find_validation_entry(address);
1784 if (NULL == ve) 1770 if (NULL == ve)
1785 { 1771 {
1786 GNUNET_break (0); 1772 GNUNET_break(0);
1787 return; 1773 return;
1788 } 1774 }
1789 if (in_use == ve->in_use) 1775 if (in_use == ve->in_use)
1790 return; 1776 return;
1791 ve->in_use = in_use; 1777 ve->in_use = in_use;
1792 if (GNUNET_YES == in_use) 1778 if (GNUNET_YES == in_use)
1793 { 1779 {
1794 /* from now on, higher frequeny, so reschedule now */ 1780 /* from now on, higher frequeny, so reschedule now */
1795 if (NULL != ve->revalidation_task) 1781 if (NULL != ve->revalidation_task)
1796 GNUNET_SCHEDULER_cancel (ve->revalidation_task); 1782 GNUNET_SCHEDULER_cancel(ve->revalidation_task);
1797 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, 1783 ve->revalidation_task = GNUNET_SCHEDULER_add_now(&revalidate_address,
1798 ve); 1784 ve);
1799 } 1785 }
1800} 1786}
1801 1787
1802 1788
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h
index f6ae764b7..a5b9b7603 100644
--- a/src/transport/gnunet-service-transport_validation.h
+++ b/src/transport/gnunet-service-transport_validation.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-service-transport_validation.h 22 * @file 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 d4f8589d1..9451f95da 100644
--- a/src/transport/gnunet-transport-profiler.c
+++ b/src/transport/gnunet-transport-profiler.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2016 GNUnet e.V. 3 Copyright (C) 2011-2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -34,8 +34,7 @@
34#include "gnunet_transport_service.h" 34#include "gnunet_transport_service.h"
35 35
36 36
37struct Iteration 37struct Iteration {
38{
39 struct Iteration *next; 38 struct Iteration *next;
40 struct Iteration *prev; 39 struct Iteration *prev;
41 struct GNUNET_TIME_Absolute start; 40 struct GNUNET_TIME_Absolute start;
@@ -54,7 +53,7 @@ struct Iteration
54 * Timeout for a connections 53 * Timeout for a connections
55 */ 54 */
56#define CONNECT_TIMEOUT \ 55#define CONNECT_TIMEOUT \
57 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 56 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
58 57
59/** 58/**
60 * Benchmarking block size in bye 59 * Benchmarking block size in bye
@@ -161,7 +160,7 @@ static unsigned int verbosity;
161 * @param cls NULL 160 * @param cls NULL
162 */ 161 */
163static void 162static void
164shutdown_task (void *cls) 163shutdown_task(void *cls)
165{ 164{
166 struct Iteration *icur; 165 struct Iteration *icur;
167 struct Iteration *inext; 166 struct Iteration *inext;
@@ -174,28 +173,28 @@ shutdown_task (void *cls)
174 float stddev_duration; 173 float stddev_duration;
175 174
176 if (NULL != ats_sh) 175 if (NULL != ats_sh)
177 { 176 {
178 GNUNET_ATS_connectivity_suggest_cancel (ats_sh); 177 GNUNET_ATS_connectivity_suggest_cancel(ats_sh);
179 ats_sh = NULL; 178 ats_sh = NULL;
180 } 179 }
181 if (NULL != bl_handle) 180 if (NULL != bl_handle)
182 { 181 {
183 GNUNET_TRANSPORT_blacklist_cancel (bl_handle); 182 GNUNET_TRANSPORT_blacklist_cancel(bl_handle);
184 bl_handle = NULL; 183 bl_handle = NULL;
185 } 184 }
186 if (NULL != ats) 185 if (NULL != ats)
187 { 186 {
188 GNUNET_ATS_connectivity_done (ats); 187 GNUNET_ATS_connectivity_done(ats);
189 ats = NULL; 188 ats = NULL;
190 } 189 }
191 if (NULL != handle) 190 if (NULL != handle)
192 { 191 {
193 GNUNET_TRANSPORT_core_disconnect (handle); 192 GNUNET_TRANSPORT_core_disconnect(handle);
194 handle = NULL; 193 handle = NULL;
195 } 194 }
196 195
197 if (verbosity > 0) 196 if (verbosity > 0)
198 fprintf (stdout, "\n"); 197 fprintf(stdout, "\n");
199 198
200 /* Output format: 199 /* Output format:
201 * All time values in ms 200 * All time values in ms
@@ -203,95 +202,95 @@ shutdown_task (void *cls)
203 * #messages;#messagesize;#avg_dur;#avg_rate;#duration_i0;#duration_i0;... */ 202 * #messages;#messagesize;#avg_dur;#avg_rate;#duration_i0;#duration_i0;... */
204 203
205 if (benchmark_send) 204 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))
214 {
215 inext = icur->next;
216 icur->rate = ((benchmark_count * benchmark_size) / 1024) /
217 ((float) icur->dur.rel_value_us / (1000 * 1000));
218 if (verbosity > 0)
219 fprintf (stdout,
220 _ ("%llu B in %llu ms == %.2f KB/s!\n"),
221 ((long long unsigned int) benchmark_count * benchmark_size),
222 ((long long unsigned int) icur->dur.rel_value_us / 1000),
223 (float) icur->rate);
224
225 avg_duration += icur->dur.rel_value_us / (1000);
226 avg_rate += icur->rate;
227 iterations++;
228 }
229 if (0 == iterations)
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))
240 { 205 {
241 inext = icur->next; 206 /* First iteration to calculcate avg and stddev */
242 stddev_rate += ((icur->rate - avg_rate) * (icur->rate - avg_rate)); 207 iterations = 0;
243 stddev_duration += (((icur->dur.rel_value_us / 1000) - avg_duration) * 208 avg_duration = 0;
244 ((icur->dur.rel_value_us / 1000) - avg_duration)); 209 avg_rate = 0.0;
245 } 210
246 /* Calculate standard deviation rate */ 211 inext = ihead;
247 stddev_rate = stddev_rate / iterations; 212 while (NULL != (icur = inext))
248 stddev_rate = sqrtf (stddev_rate); 213 {
249 214 inext = icur->next;
250 /* Calculate standard deviation duration */ 215 icur->rate = ((benchmark_count * benchmark_size) / 1024) /
251 stddev_duration = stddev_duration / iterations; 216 ((float)icur->dur.rel_value_us / (1000 * 1000));
252 stddev_duration = sqrtf (stddev_duration); 217 if (verbosity > 0)
253 218 fprintf(stdout,
254 /* Output */ 219 _("%llu B in %llu ms == %.2f KB/s!\n"),
255 fprintf (stdout, 220 ((long long unsigned int)benchmark_count * benchmark_size),
256 "%u;%u;%llu;%llu;%.2f;%.2f", 221 ((long long unsigned int)icur->dur.rel_value_us / 1000),
257 benchmark_count, 222 (float)icur->rate);
258 benchmark_size, 223
259 avg_duration, 224 avg_duration += icur->dur.rel_value_us / (1000);
260 (unsigned long long) stddev_duration, 225 avg_rate += icur->rate;
261 avg_rate, 226 iterations++;
262 stddev_rate); 227 }
263 228 if (0 == iterations)
264 inext = ihead; 229 iterations = 1; /* avoid division by zero */
265 while (NULL != (icur = inext)) 230 /* Calculate average rate */
266 { 231 avg_rate /= iterations;
267 inext = icur->next; 232 /* Calculate average duration */
268 GNUNET_CONTAINER_DLL_remove (ihead, itail, icur); 233 avg_duration /= iterations;
269 234
270 fprintf (stdout, 235 stddev_rate = 0;
271 ";%llu;%.2f", 236 stddev_duration = 0;
272 (long long unsigned int) (icur->dur.rel_value_us / 1000), 237 inext = ihead;
273 icur->rate); 238 while (NULL != (icur = inext))
274 239 {
275 GNUNET_free (icur); 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 } 276 }
277 }
278#if 0 277#if 0
279 if (benchmark_receive) 278 if (benchmark_receive)
280 { 279 {
281 duration = GNUNET_TIME_absolute_get_duration (start_time); 280 duration = GNUNET_TIME_absolute_get_duration(start_time);
282 fprintf (stdout, 281 fprintf(stdout,
283 "Received %llu bytes/s (%llu bytes in %s)\n", 282 "Received %llu bytes/s (%llu bytes in %s)\n",
284 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 283 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
285 traffic_received, 284 traffic_received,
286 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 285 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES));
287 } 286 }
288#endif 287#endif
289 fprintf (stdout, "\n"); 288 fprintf(stdout, "\n");
290} 289}
291 290
292 291
293static void 292static void
294iteration_done (); 293iteration_done();
295 294
296 295
297/** 296/**
@@ -306,66 +305,66 @@ iteration_done ();
306 * @return number of bytes written to @a buf 305 * @return number of bytes written to @a buf
307 */ 306 */
308static void 307static void
309send_msg (void *cls) 308send_msg(void *cls)
310{ 309{
311 struct GNUNET_MQ_Envelope *env; 310 struct GNUNET_MQ_Envelope *env;
312 struct GNUNET_MessageHeader *m; 311 struct GNUNET_MessageHeader *m;
313 312
314 if (NULL == mq) 313 if (NULL == mq)
315 return; 314 return;
316 env = GNUNET_MQ_msg_extra (m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY); 315 env = GNUNET_MQ_msg_extra(m, benchmark_size, GNUNET_MESSAGE_TYPE_DUMMY);
317 memset (&m[1], 52, benchmark_size - sizeof (struct GNUNET_MessageHeader)); 316 memset(&m[1], 52, benchmark_size - sizeof(struct GNUNET_MessageHeader));
318 317
319 if (itail->msgs_sent < benchmark_count) 318 if (itail->msgs_sent < benchmark_count)
320 { 319 {
321 GNUNET_MQ_notify_sent (env, &send_msg, NULL); 320 GNUNET_MQ_notify_sent(env, &send_msg, NULL);
322 } 321 }
323 else 322 else
324 { 323 {
325 iteration_done (); 324 iteration_done();
326 } 325 }
327 GNUNET_MQ_send (mq, env); 326 GNUNET_MQ_send(mq, env);
328 if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) 327 if ((verbosity > 0) && (0 == itail->msgs_sent % 10))
329 fprintf (stdout, "."); 328 fprintf(stdout, ".");
330} 329}
331 330
332 331
333static void 332static void
334iteration_start () 333iteration_start()
335{ 334{
336 struct Iteration *icur; 335 struct Iteration *icur;
337 336
338 ret = 0; 337 ret = 0;
339 if (! benchmark_send) 338 if (!benchmark_send)
340 return; 339 return;
341 benchmark_running = GNUNET_YES; 340 benchmark_running = GNUNET_YES;
342 icur = GNUNET_new (struct Iteration); 341 icur = GNUNET_new(struct Iteration);
343 GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); 342 GNUNET_CONTAINER_DLL_insert_tail(ihead, itail, icur);
344 icur->start = GNUNET_TIME_absolute_get (); 343 icur->start = GNUNET_TIME_absolute_get();
345 if (verbosity > 0) 344 if (verbosity > 0)
346 fprintf ( 345 fprintf(
347 stdout, 346 stdout,
348 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", 347 "\nStarting benchmark, starting to send %u messages in %u byte blocks\n",
349 benchmark_count, 348 benchmark_count,
350 benchmark_size); 349 benchmark_size);
351 send_msg (NULL); 350 send_msg(NULL);
352} 351}
353 352
354 353
355static void 354static void
356iteration_done () 355iteration_done()
357{ 356{
358 static int it_count = 0; 357 static int it_count = 0;
359 358
360 it_count++; 359 it_count++;
361 itail->dur = GNUNET_TIME_absolute_get_duration (itail->start); 360 itail->dur = GNUNET_TIME_absolute_get_duration(itail->start);
362 if (it_count == benchmark_iterations) 361 if (it_count == benchmark_iterations)
363 { 362 {
364 benchmark_running = GNUNET_NO; 363 benchmark_running = GNUNET_NO;
365 GNUNET_SCHEDULER_shutdown (); 364 GNUNET_SCHEDULER_shutdown();
366 return; 365 return;
367 } 366 }
368 iteration_start (); 367 iteration_start();
369} 368}
370 369
371 370
@@ -379,20 +378,20 @@ iteration_done ()
379 * @return NULL 378 * @return NULL
380 */ 379 */
381static void * 380static void *
382notify_connect (void *cls, 381notify_connect(void *cls,
383 const struct GNUNET_PeerIdentity *peer, 382 const struct GNUNET_PeerIdentity *peer,
384 struct GNUNET_MQ_Handle *m) 383 struct GNUNET_MQ_Handle *m)
385{ 384{
386 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 385 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
387 { 386 {
388 fprintf (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid)); 387 fprintf(stdout, "Connected to different peer `%s'\n", GNUNET_i2s(&pid));
389 return NULL; 388 return NULL;
390 } 389 }
391 390
392 if (verbosity > 0) 391 if (verbosity > 0)
393 fprintf (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid)); 392 fprintf(stdout, "Successfully connected to `%s'\n", GNUNET_i2s(&pid));
394 mq = m; 393 mq = m;
395 iteration_start (); 394 iteration_start();
396 return NULL; 395 return NULL;
397} 396}
398 397
@@ -406,20 +405,20 @@ notify_connect (void *cls,
406 * @param internal_cls NULL 405 * @param internal_cls NULL
407 */ 406 */
408static void 407static void
409notify_disconnect (void *cls, 408notify_disconnect(void *cls,
410 const struct GNUNET_PeerIdentity *peer, 409 const struct GNUNET_PeerIdentity *peer,
411 void *internal_cls) 410 void *internal_cls)
412{ 411{
413 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 412 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
414 return; 413 return;
415 mq = NULL; 414 mq = NULL;
416 if (GNUNET_YES == benchmark_running) 415 if (GNUNET_YES == benchmark_running)
417 { 416 {
418 fprintf (stdout, 417 fprintf(stdout,
419 "Disconnected from peer `%s' while benchmarking\n", 418 "Disconnected from peer `%s' while benchmarking\n",
420 GNUNET_i2s (&pid)); 419 GNUNET_i2s(&pid));
421 return; 420 return;
422 } 421 }
423} 422}
424 423
425 424
@@ -431,7 +430,7 @@ notify_disconnect (void *cls,
431 * @return #GNUNET_OK 430 * @return #GNUNET_OK
432 */ 431 */
433static int 432static int
434check_dummy (void *cls, const struct GNUNET_MessageHeader *message) 433check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
435{ 434{
436 return GNUNET_OK; /* all messages are fine */ 435 return GNUNET_OK; /* all messages are fine */
437} 436}
@@ -444,26 +443,26 @@ check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
444 * @param message the message 443 * @param message the message
445 */ 444 */
446static void 445static void
447handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) 446handle_dummy(void *cls, const struct GNUNET_MessageHeader *message)
448{ 447{
449 if (! benchmark_receive) 448 if (!benchmark_receive)
450 return; 449 return;
451 if (verbosity > 0) 450 if (verbosity > 0)
452 fprintf (stdout, 451 fprintf(stdout,
453 "Received %u bytes\n", 452 "Received %u bytes\n",
454 (unsigned int) ntohs (message->size)); 453 (unsigned int)ntohs(message->size));
455} 454}
456 455
457 456
458static int 457static int
459blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer) 458blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *peer)
460{ 459{
461 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 460 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
462 { 461 {
463 if (verbosity > 0) 462 if (verbosity > 0)
464 fprintf (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer)); 463 fprintf(stdout, "Denying connection to `%s'\n", GNUNET_i2s(peer));
465 return GNUNET_SYSERR; 464 return GNUNET_SYSERR;
466 } 465 }
467 return GNUNET_OK; 466 return GNUNET_OK;
468} 467}
469 468
@@ -477,144 +476,145 @@ blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
477 * @param mycfg configuration 476 * @param mycfg configuration
478 */ 477 */
479static void 478static void
480run (void *cls, 479run(void *cls,
481 char *const *args, 480 char *const *args,
482 const char *cfgfile, 481 const char *cfgfile,
483 const struct GNUNET_CONFIGURATION_Handle *mycfg) 482 const struct GNUNET_CONFIGURATION_Handle *mycfg)
484{ 483{
485 struct GNUNET_MQ_MessageHandler handlers[] = 484 struct GNUNET_MQ_MessageHandler handlers[] =
486 {GNUNET_MQ_hd_var_size (dummy, 485 { GNUNET_MQ_hd_var_size(dummy,
487 GNUNET_MESSAGE_TYPE_DUMMY, 486 GNUNET_MESSAGE_TYPE_DUMMY,
488 struct GNUNET_MessageHeader, 487 struct GNUNET_MessageHeader,
489 NULL), 488 NULL),
490 GNUNET_MQ_handler_end ()}; 489 GNUNET_MQ_handler_end() };
491 490
492 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 491 cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg;
493 492
494 ret = 1; 493 ret = 1;
495 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) 494 if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size)
496 { 495 {
497 fprintf (stderr, "Message size too big!\n"); 496 fprintf(stderr, "Message size too big!\n");
498 return; 497 return;
499 } 498 }
500 499
501 if (NULL == cpid) 500 if (NULL == cpid)
502 { 501 {
503 fprintf (stderr, "No peer identity given\n"); 502 fprintf(stderr, "No peer identity given\n");
504 return; 503 return;
505 } 504 }
506 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, 505 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string(cpid,
507 strlen (cpid), 506 strlen(cpid),
508 &pid.public_key)) 507 &pid.public_key))
509 { 508 {
510 fprintf (stderr, "Failed to parse peer identity `%s'\n", cpid); 509 fprintf(stderr, "Failed to parse peer identity `%s'\n", cpid);
511 return; 510 return;
512 } 511 }
513 if (1 == benchmark_send) 512 if (1 == benchmark_send)
514 { 513 {
515 if (verbosity > 0) 514 if (verbosity > 0)
516 fprintf (stderr, 515 fprintf(stderr,
517 "Trying to send %u messages with size %u to peer `%s'\n", 516 "Trying to send %u messages with size %u to peer `%s'\n",
518 benchmark_count, 517 benchmark_count,
519 benchmark_size, 518 benchmark_size,
520 GNUNET_i2s (&pid)); 519 GNUNET_i2s(&pid));
521 } 520 }
522 else if (1 == benchmark_receive) 521 else if (1 == benchmark_receive)
523 { 522 {
524 fprintf (stderr, 523 fprintf(stderr,
525 "Trying to receive messages from peer `%s'\n", 524 "Trying to receive messages from peer `%s'\n",
526 GNUNET_i2s (&pid)); 525 GNUNET_i2s(&pid));
527 } 526 }
528 else 527 else
529 { 528 {
530 fprintf (stderr, "No operation given\n"); 529 fprintf(stderr, "No operation given\n");
531 return; 530 return;
532 } 531 }
533 532
534 ats = GNUNET_ATS_connectivity_init (cfg); 533 ats = GNUNET_ATS_connectivity_init(cfg);
535 if (NULL == ats) 534 if (NULL == ats)
536 { 535 {
537 fprintf (stderr, "Failed to connect to ATS service\n"); 536 fprintf(stderr, "Failed to connect to ATS service\n");
538 ret = 1; 537 ret = 1;
539 return; 538 return;
540 } 539 }
541 540
542 handle = GNUNET_TRANSPORT_core_connect (cfg, 541 handle = GNUNET_TRANSPORT_core_connect(cfg,
543 NULL, 542 NULL,
544 handlers, 543 handlers,
545 NULL, 544 NULL,
546 &notify_connect, 545 &notify_connect,
547 &notify_disconnect, 546 &notify_disconnect,
548 NULL); 547 NULL);
549 if (NULL == handle) 548 if (NULL == handle)
550 { 549 {
551 fprintf (stderr, "Failed to connect to transport service\n"); 550 fprintf(stderr, "Failed to connect to transport service\n");
552 GNUNET_ATS_connectivity_done (ats); 551 GNUNET_ATS_connectivity_done(ats);
553 ats = NULL; 552 ats = NULL;
554 ret = 1; 553 ret = 1;
555 return; 554 return;
556 } 555 }
557 556
558 bl_handle = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); 557 bl_handle = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_cb, NULL);
559 ats_sh = GNUNET_ATS_connectivity_suggest (ats, &pid, 1); 558 ats_sh = GNUNET_ATS_connectivity_suggest(ats, &pid, 1);
560 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 559 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
561} 560}
562 561
563 562
564int 563int
565main (int argc, char *const *argv) 564main(int argc, char *const *argv)
566{ 565{
567 int res; 566 int res;
567
568 benchmark_count = DEFAULT_MESSAGE_COUNT; 568 benchmark_count = DEFAULT_MESSAGE_COUNT;
569 benchmark_size = DEFAULT_MESSAGE_SIZE; 569 benchmark_size = DEFAULT_MESSAGE_SIZE;
570 benchmark_iterations = DEFAULT_ITERATION_COUNT; 570 benchmark_iterations = DEFAULT_ITERATION_COUNT;
571 benchmark_running = GNUNET_NO; 571 benchmark_running = GNUNET_NO;
572 572
573 struct GNUNET_GETOPT_CommandLineOption options[] = { 573 struct GNUNET_GETOPT_CommandLineOption options[] = {
574 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 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 606 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
607 return 2; 607 return 2;
608 608
609 res = 609 res =
610 GNUNET_PROGRAM_run (argc, 610 GNUNET_PROGRAM_run(argc,
611 argv, 611 argv,
612 "gnunet-transport", 612 "gnunet-transport",
613 gettext_noop ("Direct access to transport service."), 613 gettext_noop("Direct access to transport service."),
614 options, 614 options,
615 &run, 615 &run,
616 NULL); 616 NULL);
617 GNUNET_free ((void *) argv); 617 GNUNET_free((void *)argv);
618 if (GNUNET_OK == res) 618 if (GNUNET_OK == res)
619 return ret; 619 return ret;
620 return 1; 620 return 1;
diff --git a/src/transport/gnunet-transport-wlan-receiver.c b/src/transport/gnunet-transport-wlan-receiver.c
index 9b31377e7..c6adeec0a 100644
--- a/src/transport/gnunet-transport-wlan-receiver.c
+++ b/src/transport/gnunet-transport-wlan-receiver.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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)
76 { 69 {
77 ret = read (commpipe[0], msg_buf, sizeof (msg_buf)); 70 /* A positive (non-negative) PID indicates the parent process */
78 if (0 > ret) 71 if (0 != close(commpipe[1])) /* Close unused side of pipe (in side) */
79 { 72 fprintf(stderr, "Failed to close fd: %s\n", strerror(errno));
80 fprintf (stderr, "read failed: %s\n", strerror (errno)); 73 start = time(NULL);
81 break; 74 count = 0;
82 } 75 while (1)
83 count += ret; 76 {
84 akt = time (NULL); 77 ret = read(commpipe[0], msg_buf, sizeof(msg_buf));
85 if (akt - start > 30) 78 if (0 > ret)
86 { 79 {
87 bytes_per_s = count / (akt - start); 80 fprintf(stderr, "read failed: %s\n", strerror(errno));
88 bytes_per_s /= 1024; 81 break;
89 printf ("recv %f kb/s\n", bytes_per_s); 82 }
90 start = akt; 83 count += ret;
91 count = 0; 84 akt = time(NULL);
92 } 85 if (akt - start > 30)
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 }
93 } 94 }
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)
108 { 96 {
109 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 97 /* A zero PID indicates that this is the child process */
110 _exit (1); 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)
108 {
109 fprintf(stderr, "Could not start gnunet-helper-transport-wlan!");
110 _exit(1);
111 }
111 } 112 }
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 36273f765..c3485ac47 100644
--- a/src/transport/gnunet-transport-wlan-sender.c
+++ b/src/transport/gnunet-transport-wlan-sender.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2011 GNUnet e.V. 3 Copyright (C) 2011 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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)
207 { 180 {
208 ret = write (commpipe[1], msg_buf, WLAN_MTU); 181 /* A positive (non-negative) PID indicates the parent process */
209 if (0 > ret) 182 if (0 != close(commpipe[0])) /* Close unused side of pipe (in side) */
210 { 183 fprintf(stderr, "Failed to close fd: %s\n", strerror(errno));
211 fprintf (stderr, "write failed: %s\n", strerror (errno)); 184 setvbuf(stdout,
212 break; 185 (char *)NULL,
213 } 186 _IONBF,
214 count += ret; 187 0); /* Set non-buffered output on stdout */
215 akt = time (NULL); 188
216 if (akt - start > 30) 189 if (0 != close(macpipe[1]))
217 { 190 fprintf(stderr, "Failed to close fd: %s\n", strerror(errno));
218 bytes_per_s = count / (akt - start); 191 if (sizeof(hcm) != read(macpipe[0], &hcm, sizeof(hcm)))
219 bytes_per_s /= 1024; 192 fprintf(stderr, "Failed to read hcm...\n");
220 printf ("send %f kbytes/s\n", bytes_per_s); 193 fprintf(stderr,
221 start = akt; 194 "Got MAC %.2X:%.2X:%.2X:%.2X:%.2X:%.2X\n",
222 count = 0; 195 hcm.mac.mac[0],
223 } 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)
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 }
224 } 225 }
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)
244 { 227 {
245 fprintf (stderr, "Could not start gnunet-helper-transport-wlan!"); 228 /* A zero PID indicates that this is the child process */
246 _exit (1); 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)
244 {
245 fprintf(stderr, "Could not start gnunet-helper-transport-wlan!");
246 _exit(1);
247 }
247 } 248 }
248 }
249 return 0; 249 return 0;
250} 250}
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c
index ebc3f402d..6cc342d06 100644
--- a/src/transport/gnunet-transport.c
+++ b/src/transport/gnunet-transport.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2011-2014, 2016, 2017 GNUnet e.V. 3 Copyright (C) 2011-2014, 2016, 2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -34,19 +34,18 @@
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{
50 /** 49 /**
51 * Next in DLL 50 * Next in DLL
52 */ 51 */
@@ -96,8 +95,7 @@ struct ValidationResolutionContext
96/** 95/**
97 * Struct to store information about peers in monitor mode 96 * Struct to store information about peers in monitor mode
98 */ 97 */
99struct MonitoredPeer 98struct MonitoredPeer {
100{
101 /** 99 /**
102 * State of the peer 100 * State of the peer
103 */ 101 */
@@ -117,8 +115,7 @@ struct MonitoredPeer
117/** 115/**
118 * Context to store name resolutions for valiation 116 * Context to store name resolutions for valiation
119 */ 117 */
120struct PeerResolutionContext 118struct PeerResolutionContext {
121{
122 /** 119 /**
123 * Next in DLL 120 * Next in DLL
124 */ 121 */
@@ -332,15 +329,15 @@ static struct PeerResolutionContext *rc_tail;
332 * @return #GNUNET_OK (continue to iterate) 329 * @return #GNUNET_OK (continue to iterate)
333 */ 330 */
334static int 331static int
335destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 332destroy_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
336{ 333{
337 struct MonitoredPeer *m = value; 334 struct MonitoredPeer *m = value;
338 335
339 GNUNET_assert ( 336 GNUNET_assert(
340 GNUNET_OK == 337 GNUNET_OK ==
341 GNUNET_CONTAINER_multipeermap_remove (monitored_peers, key, value)); 338 GNUNET_CONTAINER_multipeermap_remove(monitored_peers, key, value));
342 GNUNET_free_non_null (m->address); 339 GNUNET_free_non_null(m->address);
343 GNUNET_free (value); 340 GNUNET_free(value);
344 return GNUNET_OK; 341 return GNUNET_OK;
345} 342}
346 343
@@ -352,7 +349,7 @@ destroy_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
352 * @param cls NULL 349 * @param cls NULL
353 */ 350 */
354static void 351static void
355shutdown_task (void *cls) 352shutdown_task(void *cls)
356{ 353{
357 struct GNUNET_TIME_Relative duration; 354 struct GNUNET_TIME_Relative duration;
358 struct ValidationResolutionContext *cur; 355 struct ValidationResolutionContext *cur;
@@ -360,82 +357,82 @@ shutdown_task (void *cls)
360 struct PeerResolutionContext *rc; 357 struct PeerResolutionContext *rc;
361 358
362 if (NULL != op_timeout) 359 if (NULL != op_timeout)
363 { 360 {
364 GNUNET_SCHEDULER_cancel (op_timeout); 361 GNUNET_SCHEDULER_cancel(op_timeout);
365 op_timeout = NULL; 362 op_timeout = NULL;
366 } 363 }
367 if (NULL != pic) 364 if (NULL != pic)
368 { 365 {
369 GNUNET_TRANSPORT_monitor_peers_cancel (pic); 366 GNUNET_TRANSPORT_monitor_peers_cancel(pic);
370 pic = NULL; 367 pic = NULL;
371 } 368 }
372 if (NULL != pm) 369 if (NULL != pm)
373 { 370 {
374 GNUNET_TRANSPORT_monitor_plugins_cancel (pm); 371 GNUNET_TRANSPORT_monitor_plugins_cancel(pm);
375 pm = NULL; 372 pm = NULL;
376 } 373 }
377 374
378 next = vc_head; 375 next = vc_head;
379 for (cur = next; NULL != cur; cur = next) 376 for (cur = next; NULL != cur; cur = next)
380 { 377 {
381 next = cur->next; 378 next = cur->next;
382 379
383 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); 380 GNUNET_TRANSPORT_address_to_string_cancel(cur->asc);
384 GNUNET_CONTAINER_DLL_remove (vc_head, vc_tail, cur); 381 GNUNET_CONTAINER_DLL_remove(vc_head, vc_tail, cur);
385 GNUNET_free (cur->transport); 382 GNUNET_free(cur->transport);
386 GNUNET_HELLO_address_free (cur->addrcp); 383 GNUNET_HELLO_address_free(cur->addrcp);
387 GNUNET_free (cur); 384 GNUNET_free(cur);
388 } 385 }
389 while (NULL != (rc = rc_head)) 386 while (NULL != (rc = rc_head))
390 { 387 {
391 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); 388 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc);
392 GNUNET_TRANSPORT_address_to_string_cancel (rc->asc); 389 GNUNET_TRANSPORT_address_to_string_cancel(rc->asc);
393 GNUNET_free (rc->transport); 390 GNUNET_free(rc->transport);
394 GNUNET_free (rc->addrcp); 391 GNUNET_free(rc->addrcp);
395 GNUNET_free (rc); 392 GNUNET_free(rc);
396 } 393 }
397 if (NULL != handle) 394 if (NULL != handle)
398 { 395 {
399 GNUNET_TRANSPORT_core_disconnect (handle); 396 GNUNET_TRANSPORT_core_disconnect(handle);
400 handle = NULL; 397 handle = NULL;
401 } 398 }
402 if (benchmark_send) 399 if (benchmark_send)
403 { 400 {
404 duration = GNUNET_TIME_absolute_get_duration (start_time); 401 duration = GNUNET_TIME_absolute_get_duration(start_time);
405 fprintf (stdout, 402 fprintf(stdout,
406 _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"), 403 _("Transmitted %llu bytes/s (%llu bytes in %s)\n"),
407 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), 404 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us),
408 traffic_sent, 405 traffic_sent,
409 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 406 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES));
410 } 407 }
411 if (benchmark_receive) 408 if (benchmark_receive)
412 { 409 {
413 duration = GNUNET_TIME_absolute_get_duration (start_time); 410 duration = GNUNET_TIME_absolute_get_duration(start_time);
414 fprintf (stdout, 411 fprintf(stdout,
415 _ ("Received %llu bytes/s (%llu bytes in %s)\n"), 412 _("Received %llu bytes/s (%llu bytes in %s)\n"),
416 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), 413 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us),
417 traffic_received, 414 traffic_received,
418 GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); 415 GNUNET_STRINGS_relative_time_to_string(duration, GNUNET_YES));
419 } 416 }
420 417
421 if (NULL != monitored_peers) 418 if (NULL != monitored_peers)
422 { 419 {
423 GNUNET_CONTAINER_multipeermap_iterate (monitored_peers, &destroy_it, NULL); 420 GNUNET_CONTAINER_multipeermap_iterate(monitored_peers, &destroy_it, NULL);
424 GNUNET_CONTAINER_multipeermap_destroy (monitored_peers); 421 GNUNET_CONTAINER_multipeermap_destroy(monitored_peers);
425 monitored_peers = NULL; 422 monitored_peers = NULL;
426 } 423 }
427 if (NULL != monitored_plugins) 424 if (NULL != monitored_plugins)
428 { 425 {
429 GNUNET_break (0 == GNUNET_CONTAINER_multipeermap_size (monitored_plugins)); 426 GNUNET_break(0 == GNUNET_CONTAINER_multipeermap_size(monitored_plugins));
430 GNUNET_CONTAINER_multipeermap_destroy (monitored_plugins); 427 GNUNET_CONTAINER_multipeermap_destroy(monitored_plugins);
431 monitored_plugins = NULL; 428 monitored_plugins = NULL;
432 } 429 }
433 if (NULL != blacklist) 430 if (NULL != blacklist)
434 { 431 {
435 GNUNET_TRANSPORT_blacklist_cancel (blacklist); 432 GNUNET_TRANSPORT_blacklist_cancel(blacklist);
436 blacklist = NULL; 433 blacklist = NULL;
437 ret = 0; 434 ret = 0;
438 } 435 }
439} 436}
440 437
441 438
@@ -443,42 +440,42 @@ shutdown_task (void *cls)
443 * We are done, shut down. 440 * We are done, shut down.
444 */ 441 */
445static void 442static void
446operation_timeout (void *cls) 443operation_timeout(void *cls)
447{ 444{
448 struct PeerResolutionContext *cur; 445 struct PeerResolutionContext *cur;
449 struct PeerResolutionContext *next; 446 struct PeerResolutionContext *next;
450 447
451 op_timeout = NULL; 448 op_timeout = NULL;
452 if ((benchmark_send) || (benchmark_receive)) 449 if ((benchmark_send) || (benchmark_receive))
453 { 450 {
454 fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); 451 fprintf(stdout, _("Failed to connect to `%s'\n"), GNUNET_i2s_full(&pid));
455 GNUNET_SCHEDULER_shutdown (); 452 GNUNET_SCHEDULER_shutdown();
456 ret = 1; 453 ret = 1;
457 return; 454 return;
458 } 455 }
459 if (iterate_connections) 456 if (iterate_connections)
460 {
461 next = rc_head;
462 while (NULL != (cur = next))
463 { 457 {
464 next = cur->next; 458 next = rc_head;
465 fprintf (stdout, 459 while (NULL != (cur = next))
466 _ ("Failed to resolve address for peer `%s'\n"), 460 {
467 GNUNET_i2s (&cur->addrcp->peer)); 461 next = cur->next;
468 462 fprintf(stdout,
469 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, cur); 463 _("Failed to resolve address for peer `%s'\n"),
470 GNUNET_TRANSPORT_address_to_string_cancel (cur->asc); 464 GNUNET_i2s(&cur->addrcp->peer));
471 GNUNET_free (cur->transport); 465
472 GNUNET_free (cur->addrcp); 466 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, cur);
473 GNUNET_free (cur); 467 GNUNET_TRANSPORT_address_to_string_cancel(cur->asc);
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;
474 } 478 }
475 fprintf (stdout,
476 "%s",
477 _ ("Failed to list connections, timeout occurred\n"));
478 GNUNET_SCHEDULER_shutdown ();
479 ret = 1;
480 return;
481 }
482} 479}
483 480
484 481
@@ -489,21 +486,21 @@ operation_timeout (void *cls)
489 * @param cls closure with the message queue 486 * @param cls closure with the message queue
490 */ 487 */
491static void 488static void
492do_send (void *cls) 489do_send(void *cls)
493{ 490{
494 struct GNUNET_MQ_Handle *mq = cls; 491 struct GNUNET_MQ_Handle *mq = cls;
495 struct GNUNET_MessageHeader *m; 492 struct GNUNET_MessageHeader *m;
496 struct GNUNET_MQ_Envelope *env; 493 struct GNUNET_MQ_Envelope *env;
497 494
498 env = GNUNET_MQ_msg_extra (m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY); 495 env = GNUNET_MQ_msg_extra(m, BLOCKSIZE * 1024, GNUNET_MESSAGE_TYPE_DUMMY);
499 memset (&m[1], 52, BLOCKSIZE * 1024 - sizeof (struct GNUNET_MessageHeader)); 496 memset(&m[1], 52, BLOCKSIZE * 1024 - sizeof(struct GNUNET_MessageHeader));
500 traffic_sent += BLOCKSIZE * 1024; 497 traffic_sent += BLOCKSIZE * 1024;
501 GNUNET_MQ_notify_sent (env, &do_send, mq); 498 GNUNET_MQ_notify_sent(env, &do_send, mq);
502 if (verbosity > 0) 499 if (verbosity > 0)
503 fprintf (stdout, 500 fprintf(stdout,
504 _ ("Transmitting %u bytes\n"), 501 _("Transmitting %u bytes\n"),
505 (unsigned int) BLOCKSIZE * 1024); 502 (unsigned int)BLOCKSIZE * 1024);
506 GNUNET_MQ_send (mq, env); 503 GNUNET_MQ_send(mq, env);
507} 504}
508 505
509 506
@@ -516,29 +513,29 @@ do_send (void *cls)
516 * @param mq message queue for sending to @a peer 513 * @param mq message queue for sending to @a peer
517 */ 514 */
518static void * 515static void *
519notify_connect (void *cls, 516notify_connect(void *cls,
520 const struct GNUNET_PeerIdentity *peer, 517 const struct GNUNET_PeerIdentity *peer,
521 struct GNUNET_MQ_Handle *mq) 518 struct GNUNET_MQ_Handle *mq)
522{ 519{
523 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 520 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
524 return NULL; 521 return NULL;
525 ret = 0; 522 ret = 0;
526 if (! benchmark_send) 523 if (!benchmark_send)
527 return NULL; 524 return NULL;
528 if (NULL != op_timeout) 525 if (NULL != op_timeout)
529 { 526 {
530 GNUNET_SCHEDULER_cancel (op_timeout); 527 GNUNET_SCHEDULER_cancel(op_timeout);
531 op_timeout = NULL; 528 op_timeout = NULL;
532 } 529 }
533 if (verbosity > 0) 530 if (verbosity > 0)
534 fprintf ( 531 fprintf(
535 stdout, 532 stdout,
536 _ ( 533 _(
537 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), 534 "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"),
538 GNUNET_i2s (peer), 535 GNUNET_i2s(peer),
539 BLOCKSIZE); 536 BLOCKSIZE);
540 start_time = GNUNET_TIME_absolute_get (); 537 start_time = GNUNET_TIME_absolute_get();
541 do_send (mq); 538 do_send(mq);
542 return mq; 539 return mq;
543} 540}
544 541
@@ -552,19 +549,19 @@ notify_connect (void *cls,
552 * @param internal_cls what we returned from #notify_connect() 549 * @param internal_cls what we returned from #notify_connect()
553 */ 550 */
554static void 551static void
555notify_disconnect (void *cls, 552notify_disconnect(void *cls,
556 const struct GNUNET_PeerIdentity *peer, 553 const struct GNUNET_PeerIdentity *peer,
557 void *internal_cls) 554 void *internal_cls)
558{ 555{
559 if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) 556 if (0 != memcmp(&pid, peer, sizeof(struct GNUNET_PeerIdentity)))
560 return; 557 return;
561 if (NULL == internal_cls) 558 if (NULL == internal_cls)
562 return; /* not about target peer */ 559 return; /* not about target peer */
563 if (! benchmark_send) 560 if (!benchmark_send)
564 return; /* not transmitting */ 561 return; /* not transmitting */
565 fprintf (stdout, 562 fprintf(stdout,
566 _ ("Disconnected from peer `%s' while benchmarking\n"), 563 _("Disconnected from peer `%s' while benchmarking\n"),
567 GNUNET_i2s (&pid)); 564 GNUNET_i2s(&pid));
568} 565}
569 566
570 567
@@ -578,20 +575,20 @@ notify_disconnect (void *cls,
578 * @return NULL 575 * @return NULL
579 */ 576 */
580static void * 577static void *
581monitor_notify_connect (void *cls, 578monitor_notify_connect(void *cls,
582 const struct GNUNET_PeerIdentity *peer, 579 const struct GNUNET_PeerIdentity *peer,
583 struct GNUNET_MQ_Handle *mq) 580 struct GNUNET_MQ_Handle *mq)
584{ 581{
585 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 582 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
586 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 583 const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now);
587 584
588 monitor_connect_counter++; 585 monitor_connect_counter++;
589 fprintf (stdout, 586 fprintf(stdout,
590 _ ("%24s: %-17s %4s (%u connections in total)\n"), 587 _("%24s: %-17s %4s (%u connections in total)\n"),
591 now_str, 588 now_str,
592 _ ("Connected to"), 589 _("Connected to"),
593 GNUNET_i2s (peer), 590 GNUNET_i2s(peer),
594 monitor_connect_counter); 591 monitor_connect_counter);
595 return NULL; 592 return NULL;
596} 593}
597 594
@@ -605,22 +602,22 @@ monitor_notify_connect (void *cls,
605 * @param internal_cls what we returned from #monitor_notify_connect() 602 * @param internal_cls what we returned from #monitor_notify_connect()
606 */ 603 */
607static void 604static void
608monitor_notify_disconnect (void *cls, 605monitor_notify_disconnect(void *cls,
609 const struct GNUNET_PeerIdentity *peer, 606 const struct GNUNET_PeerIdentity *peer,
610 void *internal_cls) 607 void *internal_cls)
611{ 608{
612 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 609 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
613 const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); 610 const char *now_str = GNUNET_STRINGS_absolute_time_to_string(now);
614 611
615 GNUNET_assert (monitor_connect_counter > 0); 612 GNUNET_assert(monitor_connect_counter > 0);
616 monitor_connect_counter--; 613 monitor_connect_counter--;
617 614
618 fprintf (stdout, 615 fprintf(stdout,
619 _ ("%24s: %-17s %4s (%u connections in total)\n"), 616 _("%24s: %-17s %4s (%u connections in total)\n"),
620 now_str, 617 now_str,
621 _ ("Disconnected from"), 618 _("Disconnected from"),
622 GNUNET_i2s (peer), 619 GNUNET_i2s(peer),
623 monitor_connect_counter); 620 monitor_connect_counter);
624} 621}
625 622
626 623
@@ -632,7 +629,7 @@ monitor_notify_disconnect (void *cls,
632 * @return #GNUNET_OK 629 * @return #GNUNET_OK
633 */ 630 */
634static int 631static int
635check_dummy (void *cls, const struct GNUNET_MessageHeader *message) 632check_dummy(void *cls, const struct GNUNET_MessageHeader *message)
636{ 633{
637 return GNUNET_OK; /* all messages are fine */ 634 return GNUNET_OK; /* all messages are fine */
638} 635}
@@ -645,17 +642,17 @@ check_dummy (void *cls, const struct GNUNET_MessageHeader *message)
645 * @param message the message 642 * @param message the message
646 */ 643 */
647static void 644static void
648handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) 645handle_dummy(void *cls, const struct GNUNET_MessageHeader *message)
649{ 646{
650 if (! benchmark_receive) 647 if (!benchmark_receive)
651 return; 648 return;
652 if (verbosity > 0) 649 if (verbosity > 0)
653 fprintf (stdout, 650 fprintf(stdout,
654 _ ("Received %u bytes\n"), 651 _("Received %u bytes\n"),
655 (unsigned int) ntohs (message->size)); 652 (unsigned int)ntohs(message->size));
656 if (0 == traffic_received) 653 if (0 == traffic_received)
657 start_time = GNUNET_TIME_absolute_get (); 654 start_time = GNUNET_TIME_absolute_get();
658 traffic_received += ntohs (message->size); 655 traffic_received += ntohs(message->size);
659} 656}
660 657
661 658
@@ -669,41 +666,40 @@ handle_dummy (void *cls, const struct GNUNET_MessageHeader *message)
669 * @param state_timeout when will the peer's state expire 666 * @param state_timeout when will the peer's state expire
670 */ 667 */
671static void 668static void
672resolve_peer_address (const struct GNUNET_HELLO_Address *address, 669resolve_peer_address(const struct GNUNET_HELLO_Address *address,
673 int numeric, 670 int numeric,
674 enum GNUNET_TRANSPORT_PeerState state, 671 enum GNUNET_TRANSPORT_PeerState state,
675 struct GNUNET_TIME_Absolute state_timeout); 672 struct GNUNET_TIME_Absolute state_timeout);
676 673
677 674
678static void 675static void
679print_info (const struct GNUNET_PeerIdentity *id, 676print_info(const struct GNUNET_PeerIdentity *id,
680 const char *transport, 677 const char *transport,
681 const char *addr, 678 const char *addr,
682 enum GNUNET_TRANSPORT_PeerState state, 679 enum GNUNET_TRANSPORT_PeerState state,
683 struct GNUNET_TIME_Absolute state_timeout) 680 struct GNUNET_TIME_Absolute state_timeout)
684{ 681{
685
686 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || 682 if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
687 (GNUNET_YES == monitor_connections)) 683 (GNUNET_YES == monitor_connections))
688 { 684 {
689 fprintf (stdout, 685 fprintf(stdout,
690 _ ("Peer `%s': %s %s in state `%s' until %s\n"), 686 _("Peer `%s': %s %s in state `%s' until %s\n"),
691 GNUNET_i2s (id), 687 GNUNET_i2s(id),
692 (NULL == transport) ? "<none>" : transport, 688 (NULL == transport) ? "<none>" : transport,
693 (NULL == transport) ? "<none>" : addr, 689 (NULL == transport) ? "<none>" : addr,
694 GNUNET_TRANSPORT_ps2s (state), 690 GNUNET_TRANSPORT_ps2s(state),
695 GNUNET_STRINGS_absolute_time_to_string (state_timeout)); 691 GNUNET_STRINGS_absolute_time_to_string(state_timeout));
696 } 692 }
697 else if ((GNUNET_YES == iterate_connections) && 693 else if ((GNUNET_YES == iterate_connections) &&
698 (GNUNET_TRANSPORT_is_connected (state))) 694 (GNUNET_TRANSPORT_is_connected(state)))
699 { 695 {
700 /* Only connected peers, skip state */ 696 /* Only connected peers, skip state */
701 fprintf (stdout, 697 fprintf(stdout,
702 _ ("Peer `%s': %s %s\n"), 698 _("Peer `%s': %s %s\n"),
703 GNUNET_i2s (id), 699 GNUNET_i2s(id),
704 transport, 700 transport,
705 addr); 701 addr);
706 } 702 }
707} 703}
708 704
709 705
@@ -724,82 +720,82 @@ print_info (const struct GNUNET_PeerIdentity *id,
724 * if #GNUNET_SYSERR: communication error (IPC error) 720 * if #GNUNET_SYSERR: communication error (IPC error)
725 */ 721 */
726static void 722static void
727process_peer_string (void *cls, const char *address, int res) 723process_peer_string(void *cls, const char *address, int res)
728{ 724{
729 struct PeerResolutionContext *rc = cls; 725 struct PeerResolutionContext *rc = cls;
730 726
731 if (NULL != address) 727 if (NULL != address)
732 {
733 if (GNUNET_SYSERR == res)
734 { 728 {
735 fprintf ( 729 if (GNUNET_SYSERR == res)
736 stderr, 730 {
737 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", 731 fprintf(
738 GNUNET_i2s (&rc->addrcp->peer), 732 stderr,
739 rc->addrcp->transport_name, 733 "Failed to convert address for peer `%s' plugin `%s' length %u to string \n",
740 (unsigned int) rc->addrcp->address_length); 734 GNUNET_i2s(&rc->addrcp->peer),
741 print_info (&rc->addrcp->peer, 735 rc->addrcp->transport_name,
742 rc->transport, 736 (unsigned int)rc->addrcp->address_length);
743 NULL, 737 print_info(&rc->addrcp->peer,
744 rc->state, 738 rc->transport,
745 rc->state_timeout); 739 NULL,
746 rc->printed = GNUNET_YES; 740 rc->state,
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 */
747 return; 756 return;
748 } 757 }
749 if (GNUNET_OK == res)
750 {
751 print_info (&rc->addrcp->peer,
752 rc->transport,
753 address,
754 rc->state,
755 rc->state_timeout);
756 rc->printed = GNUNET_YES;
757 return; /* Wait for done call */
758 }
759 /* GNUNET_NO == res: ignore, was simply not supported */
760 return;
761 }
762 /* NULL == address, last call, we are done */ 758 /* NULL == address, last call, we are done */
763 759
764 rc->asc = NULL; 760 rc->asc = NULL;
765 GNUNET_assert (address_resolutions > 0); 761 GNUNET_assert(address_resolutions > 0);
766 address_resolutions--; 762 address_resolutions--;
767 if (GNUNET_NO == rc->printed) 763 if (GNUNET_NO == rc->printed)
768 {
769 if (numeric == GNUNET_NO)
770 {
771 /* Failed to resolve address, try numeric lookup
772 (note: this should not be needed, as transport
773 should fallback to numeric conversion if DNS takes
774 too long) */
775 resolve_peer_address (rc->addrcp,
776 GNUNET_YES,
777 rc->state,
778 rc->state_timeout);
779 }
780 else
781 { 764 {
782 print_info (&rc->addrcp->peer, 765 if (numeric == GNUNET_NO)
783 rc->transport, 766 {
784 NULL, 767 /* Failed to resolve address, try numeric lookup
785 rc->state, 768 (note: this should not be needed, as transport
786 rc->state_timeout); 769 should fallback to numeric conversion if DNS takes
770 too long) */
771 resolve_peer_address(rc->addrcp,
772 GNUNET_YES,
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 }
787 } 784 }
788 } 785 GNUNET_free(rc->transport);
789 GNUNET_free (rc->transport); 786 GNUNET_free(rc->addrcp);
790 GNUNET_free (rc->addrcp); 787 GNUNET_CONTAINER_DLL_remove(rc_head, rc_tail, rc);
791 GNUNET_CONTAINER_DLL_remove (rc_head, rc_tail, rc); 788 GNUNET_free(rc);
792 GNUNET_free (rc);
793 if ((0 == address_resolutions) && (iterate_connections)) 789 if ((0 == address_resolutions) && (iterate_connections))
794 {
795 if (NULL != op_timeout)
796 { 790 {
797 GNUNET_SCHEDULER_cancel (op_timeout); 791 if (NULL != op_timeout)
798 op_timeout = NULL; 792 {
793 GNUNET_SCHEDULER_cancel(op_timeout);
794 op_timeout = NULL;
795 }
796 ret = 0;
797 GNUNET_SCHEDULER_shutdown();
799 } 798 }
800 ret = 0;
801 GNUNET_SCHEDULER_shutdown ();
802 }
803} 799}
804 800
805 801
@@ -814,28 +810,28 @@ process_peer_string (void *cls, const char *address, int res)
814 * @param state_timeout when will the peer's state expire 810 * @param state_timeout when will the peer's state expire
815 */ 811 */
816static void 812static void
817resolve_peer_address (const struct GNUNET_HELLO_Address *address, 813resolve_peer_address(const struct GNUNET_HELLO_Address *address,
818 int numeric, 814 int numeric,
819 enum GNUNET_TRANSPORT_PeerState state, 815 enum GNUNET_TRANSPORT_PeerState state,
820 struct GNUNET_TIME_Absolute state_timeout) 816 struct GNUNET_TIME_Absolute state_timeout)
821{ 817{
822 struct PeerResolutionContext *rc; 818 struct PeerResolutionContext *rc;
823 819
824 rc = GNUNET_new (struct PeerResolutionContext); 820 rc = GNUNET_new(struct PeerResolutionContext);
825 GNUNET_CONTAINER_DLL_insert (rc_head, rc_tail, rc); 821 GNUNET_CONTAINER_DLL_insert(rc_head, rc_tail, rc);
826 address_resolutions++; 822 address_resolutions++;
827 rc->transport = GNUNET_strdup (address->transport_name); 823 rc->transport = GNUNET_strdup(address->transport_name);
828 rc->addrcp = GNUNET_HELLO_address_copy (address); 824 rc->addrcp = GNUNET_HELLO_address_copy(address);
829 rc->printed = GNUNET_NO; 825 rc->printed = GNUNET_NO;
830 rc->state = state; 826 rc->state = state;
831 rc->state_timeout = state_timeout; 827 rc->state_timeout = state_timeout;
832 /* Resolve address to string */ 828 /* Resolve address to string */
833 rc->asc = GNUNET_TRANSPORT_address_to_string (cfg, 829 rc->asc = GNUNET_TRANSPORT_address_to_string(cfg,
834 address, 830 address,
835 numeric, 831 numeric,
836 RESOLUTION_TIMEOUT, 832 RESOLUTION_TIMEOUT,
837 &process_peer_string, 833 &process_peer_string,
838 rc); 834 rc);
839} 835}
840 836
841 837
@@ -850,46 +846,44 @@ resolve_peer_address (const struct GNUNET_HELLO_Address *address,
850 * @param state_timeout time out for the current state 846 * @param state_timeout time out for the current state
851 */ 847 */
852static void 848static void
853process_peer_iteration_cb (void *cls, 849process_peer_iteration_cb(void *cls,
854 const struct GNUNET_PeerIdentity *peer, 850 const struct GNUNET_PeerIdentity *peer,
855 const struct GNUNET_HELLO_Address *address, 851 const struct GNUNET_HELLO_Address *address,
856 enum GNUNET_TRANSPORT_PeerState state, 852 enum GNUNET_TRANSPORT_PeerState state,
857 struct GNUNET_TIME_Absolute state_timeout) 853 struct GNUNET_TIME_Absolute state_timeout)
858{ 854{
859 if (NULL == peer) 855 if (NULL == peer)
860 { 856 {
861 /* done */ 857 /* done */
862 pic = NULL; 858 pic = NULL;
863 return; 859 return;
864 } 860 }
865 861
866 if ((GNUNET_NO == iterate_all) && 862 if ((GNUNET_NO == iterate_all) &&
867 (GNUNET_NO == GNUNET_TRANSPORT_is_connected (state))) 863 (GNUNET_NO == GNUNET_TRANSPORT_is_connected(state)))
868 return; /* Display only connected peers */ 864 return; /* Display only connected peers */
869 865
870 if (NULL != op_timeout) 866 if (NULL != op_timeout)
871 GNUNET_SCHEDULER_cancel (op_timeout); 867 GNUNET_SCHEDULER_cancel(op_timeout);
872 op_timeout = 868 op_timeout =
873 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); 869 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL);
874 870
875 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 871 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
876 "Received address for peer `%s': %s\n", 872 "Received address for peer `%s': %s\n",
877 GNUNET_i2s (peer), 873 GNUNET_i2s(peer),
878 address ? address->transport_name : ""); 874 address ? address->transport_name : "");
879 875
880 if (NULL != address) 876 if (NULL != address)
881 resolve_peer_address (address, numeric, state, state_timeout); 877 resolve_peer_address(address, numeric, state, state_timeout);
882 else 878 else
883 print_info (peer, NULL, NULL, state, state_timeout); 879 print_info(peer, NULL, NULL, state, state_timeout);
884} 880}
885 881
886 882
887/** 883/**
888 * Context for address resolution by #plugin_monitoring_cb(). 884 * Context for address resolution by #plugin_monitoring_cb().
889 */ 885 */
890struct PluginMonitorAddress 886struct PluginMonitorAddress {
891{
892
893 /** 887 /**
894 * Ongoing resolution request. 888 * Ongoing resolution request.
895 */ 889 */
@@ -915,52 +909,57 @@ struct PluginMonitorAddress
915 * @param info the monitoring information 909 * @param info the monitoring information
916 */ 910 */
917static void 911static void
918print_plugin_event_info (struct PluginMonitorAddress *addr, 912print_plugin_event_info(struct PluginMonitorAddress *addr,
919 const struct GNUNET_TRANSPORT_SessionInfo *info) 913 const struct GNUNET_TRANSPORT_SessionInfo *info)
920{ 914{
921 const char *state; 915 const char *state;
922 916
923 switch (info->state) 917 switch (info->state)
924 { 918 {
925 case GNUNET_TRANSPORT_SS_INIT: 919 case GNUNET_TRANSPORT_SS_INIT:
926 state = "INIT"; 920 state = "INIT";
927 break; 921 break;
928 case GNUNET_TRANSPORT_SS_HANDSHAKE: 922
929 state = "HANDSHAKE"; 923 case GNUNET_TRANSPORT_SS_HANDSHAKE:
930 break; 924 state = "HANDSHAKE";
931 case GNUNET_TRANSPORT_SS_UP: 925 break;
932 state = "UP"; 926
933 break; 927 case GNUNET_TRANSPORT_SS_UP:
934 case GNUNET_TRANSPORT_SS_UPDATE: 928 state = "UP";
935 state = "UPDATE"; 929 break;
936 break; 930
937 case GNUNET_TRANSPORT_SS_DONE: 931 case GNUNET_TRANSPORT_SS_UPDATE:
938 state = "DONE"; 932 state = "UPDATE";
939 break; 933 break;
940 default: 934
941 state = "UNKNOWN"; 935 case GNUNET_TRANSPORT_SS_DONE:
942 break; 936 state = "DONE";
943 } 937 break;
944 fprintf (stdout, 938
945 "%s: state %s timeout in %s @ %s%s\n", 939 default:
946 GNUNET_i2s (&info->address->peer), 940 state = "UNKNOWN";
947 state, 941 break;
948 GNUNET_STRINGS_relative_time_to_string ( 942 }
949 GNUNET_TIME_absolute_get_remaining (info->session_timeout), 943 fprintf(stdout,
950 GNUNET_YES), 944 "%s: state %s timeout in %s @ %s%s\n",
951 addr->str, 945 GNUNET_i2s(&info->address->peer),
952 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : ""); 946 state,
953 fprintf (stdout, 947 GNUNET_STRINGS_relative_time_to_string(
954 "%s: queue has %3u messages and %6u bytes\n", 948 GNUNET_TIME_absolute_get_remaining(info->session_timeout),
955 GNUNET_i2s (&info->address->peer), 949 GNUNET_YES),
956 info->num_msg_pending, 950 addr->str,
957 info->num_bytes_pending); 951 (info->is_inbound == GNUNET_YES) ? " (INBOUND)" : "");
952 fprintf(stdout,
953 "%s: queue has %3u messages and %6u bytes\n",
954 GNUNET_i2s(&info->address->peer),
955 info->num_msg_pending,
956 info->num_bytes_pending);
958 if (0 != 957 if (0 !=
959 GNUNET_TIME_absolute_get_remaining (info->receive_delay).rel_value_us) 958 GNUNET_TIME_absolute_get_remaining(info->receive_delay).rel_value_us)
960 fprintf (stdout, 959 fprintf(stdout,
961 "%s: receiving blocked until %s\n", 960 "%s: receiving blocked until %s\n",
962 GNUNET_i2s (&info->address->peer), 961 GNUNET_i2s(&info->address->peer),
963 GNUNET_STRINGS_absolute_time_to_string (info->receive_delay)); 962 GNUNET_STRINGS_absolute_time_to_string(info->receive_delay));
964} 963}
965 964
966 965
@@ -981,19 +980,19 @@ print_plugin_event_info (struct PluginMonitorAddress *addr,
981 * if #GNUNET_SYSERR: communication error (IPC error) 980 * if #GNUNET_SYSERR: communication error (IPC error)
982 */ 981 */
983static void 982static void
984address_cb (void *cls, const char *address, int res) 983address_cb(void *cls, const char *address, int res)
985{ 984{
986 struct PluginMonitorAddress *addr = cls; 985 struct PluginMonitorAddress *addr = cls;
987 986
988 if (NULL == address) 987 if (NULL == address)
989 { 988 {
990 addr->asc = NULL; 989 addr->asc = NULL;
991 return; 990 return;
992 } 991 }
993 if (NULL != addr->str) 992 if (NULL != addr->str)
994 return; 993 return;
995 addr->str = GNUNET_strdup (address); 994 addr->str = GNUNET_strdup(address);
996 print_plugin_event_info (addr, &addr->si); 995 print_plugin_event_info(addr, &addr->si);
997} 996}
998 997
999 998
@@ -1015,10 +1014,10 @@ address_cb (void *cls, const char *address, int res)
1015 * was being cancelled while sessions were active 1014 * was being cancelled while sessions were active
1016 */ 1015 */
1017static void 1016static void
1018plugin_monitoring_cb (void *cls, 1017plugin_monitoring_cb(void *cls,
1019 struct GNUNET_TRANSPORT_PluginSession *session, 1018 struct GNUNET_TRANSPORT_PluginSession *session,
1020 void **session_ctx, 1019 void **session_ctx,
1021 const struct GNUNET_TRANSPORT_SessionInfo *info) 1020 const struct GNUNET_TRANSPORT_SessionInfo *info)
1022{ 1021{
1023 struct PluginMonitorAddress *addr; 1022 struct PluginMonitorAddress *addr;
1024 1023
@@ -1026,50 +1025,50 @@ plugin_monitoring_cb (void *cls,
1026 return; /* in sync with transport service */ 1025 return; /* in sync with transport service */
1027 addr = *session_ctx; 1026 addr = *session_ctx;
1028 if (NULL == info) 1027 if (NULL == info)
1029 {
1030 if (NULL != addr)
1031 { 1028 {
1032 if (NULL != addr->asc) 1029 if (NULL != addr)
1033 { 1030 {
1034 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc); 1031 if (NULL != addr->asc)
1035 addr->asc = NULL; 1032 {
1036 } 1033 GNUNET_TRANSPORT_address_to_string_cancel(addr->asc);
1037 GNUNET_free_non_null (addr->str); 1034 addr->asc = NULL;
1038 GNUNET_free (addr); 1035 }
1039 *session_ctx = NULL; 1036 GNUNET_free_non_null(addr->str);
1037 GNUNET_free(addr);
1038 *session_ctx = NULL;
1039 }
1040 return; /* shutdown */
1040 } 1041 }
1041 return; /* shutdown */
1042 }
1043 if (0 != 1042 if (0 !=
1044 memcmp (&info->address->peer, &pid, sizeof (struct GNUNET_PeerIdentity))) 1043 memcmp(&info->address->peer, &pid, sizeof(struct GNUNET_PeerIdentity)))
1045 return; /* filtered */ 1044 return; /* filtered */
1046 if (NULL == addr) 1045 if (NULL == addr)
1047 { 1046 {
1048 addr = GNUNET_new (struct PluginMonitorAddress); 1047 addr = GNUNET_new(struct PluginMonitorAddress);
1049 addr->asc = 1048 addr->asc =
1050 GNUNET_TRANSPORT_address_to_string (cfg, 1049 GNUNET_TRANSPORT_address_to_string(cfg,
1051 info->address, 1050 info->address,
1052 numeric, 1051 numeric,
1053 GNUNET_TIME_UNIT_FOREVER_REL, 1052 GNUNET_TIME_UNIT_FOREVER_REL,
1054 &address_cb, 1053 &address_cb,
1055 addr); 1054 addr);
1056 *session_ctx = addr; 1055 *session_ctx = addr;
1057 } 1056 }
1058 if (NULL == addr->str) 1057 if (NULL == addr->str)
1059 addr->si = *info; 1058 addr->si = *info;
1060 else 1059 else
1061 print_plugin_event_info (addr, info); 1060 print_plugin_event_info(addr, info);
1062 if (GNUNET_TRANSPORT_SS_DONE == info->state) 1061 if (GNUNET_TRANSPORT_SS_DONE == info->state)
1063 {
1064 if (NULL != addr->asc)
1065 { 1062 {
1066 GNUNET_TRANSPORT_address_to_string_cancel (addr->asc); 1063 if (NULL != addr->asc)
1067 addr->asc = NULL; 1064 {
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;
1068 } 1071 }
1069 GNUNET_free_non_null (addr->str);
1070 GNUNET_free (addr);
1071 *session_ctx = NULL;
1072 }
1073} 1072}
1074 1073
1075 1074
@@ -1084,64 +1083,64 @@ plugin_monitoring_cb (void *cls,
1084 * @param state_timeout time out for the current state 1083 * @param state_timeout time out for the current state
1085 */ 1084 */
1086static void 1085static void
1087process_peer_monitoring_cb (void *cls, 1086process_peer_monitoring_cb(void *cls,
1088 const struct GNUNET_PeerIdentity *peer, 1087 const struct GNUNET_PeerIdentity *peer,
1089 const struct GNUNET_HELLO_Address *address, 1088 const struct GNUNET_HELLO_Address *address,
1090 enum GNUNET_TRANSPORT_PeerState state, 1089 enum GNUNET_TRANSPORT_PeerState state,
1091 struct GNUNET_TIME_Absolute state_timeout) 1090 struct GNUNET_TIME_Absolute state_timeout)
1092{ 1091{
1093 struct MonitoredPeer *m; 1092 struct MonitoredPeer *m;
1094 1093
1095 if (NULL == peer) 1094 if (NULL == peer)
1096 { 1095 {
1097 fprintf (stdout, 1096 fprintf(stdout,
1098 "%s", 1097 "%s",
1099 _ ( 1098 _(
1100 "Monitor disconnected from transport service. Reconnecting.\n")); 1099 "Monitor disconnected from transport service. Reconnecting.\n"));
1101 return; 1100 return;
1102 } 1101 }
1103 1102
1104 if (NULL != op_timeout) 1103 if (NULL != op_timeout)
1105 GNUNET_SCHEDULER_cancel (op_timeout); 1104 GNUNET_SCHEDULER_cancel(op_timeout);
1106 op_timeout = 1105 op_timeout =
1107 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); 1106 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL);
1108 1107
1109 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get (monitored_peers, peer))) 1108 if (NULL == (m = GNUNET_CONTAINER_multipeermap_get(monitored_peers, peer)))
1110 { 1109 {
1111 m = GNUNET_new (struct MonitoredPeer); 1110 m = GNUNET_new(struct MonitoredPeer);
1112 GNUNET_CONTAINER_multipeermap_put ( 1111 GNUNET_CONTAINER_multipeermap_put(
1113 monitored_peers, 1112 monitored_peers,
1114 peer, 1113 peer,
1115 m, 1114 m,
1116 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 1115 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
1117 } 1116 }
1118 else 1117 else
1119 {
1120 if ((m->state == state) &&
1121 (m->state_timeout.abs_value_us == state_timeout.abs_value_us) &&
1122 (NULL == address) && (NULL == m->address))
1123 { 1118 {
1124 return; /* No real change */ 1119 if ((m->state == state) &&
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 */
1125 } 1128 }
1126 if ((m->state == state) && (NULL != address) && (NULL != m->address) &&
1127 (0 == GNUNET_HELLO_address_cmp (m->address, address)))
1128 return; /* No real change */
1129 }
1130 1129
1131 if (NULL != m->address) 1130 if (NULL != m->address)
1132 { 1131 {
1133 GNUNET_free (m->address); 1132 GNUNET_free(m->address);
1134 m->address = NULL; 1133 m->address = NULL;
1135 } 1134 }
1136 if (NULL != address) 1135 if (NULL != address)
1137 m->address = GNUNET_HELLO_address_copy (address); 1136 m->address = GNUNET_HELLO_address_copy(address);
1138 m->state = state; 1137 m->state = state;
1139 m->state_timeout = state_timeout; 1138 m->state_timeout = state_timeout;
1140 1139
1141 if (NULL != address) 1140 if (NULL != address)
1142 resolve_peer_address (m->address, numeric, m->state, m->state_timeout); 1141 resolve_peer_address(m->address, numeric, m->state, m->state_timeout);
1143 else 1142 else
1144 print_info (peer, NULL, NULL, m->state, m->state_timeout); 1143 print_info(peer, NULL, NULL, m->state, m->state_timeout);
1145} 1144}
1146 1145
1147 1146
@@ -1155,9 +1154,9 @@ process_peer_monitoring_cb (void *cls,
1155 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not 1154 * @return #GNUNET_OK if the connection is allowed, #GNUNET_SYSERR if not
1156 */ 1155 */
1157static int 1156static int
1158blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid) 1157blacklist_cb(void *cls, const struct GNUNET_PeerIdentity *cpid)
1159{ 1158{
1160 if (0 == memcmp (cpid, &pid, sizeof (struct GNUNET_PeerIdentity))) 1159 if (0 == memcmp(cpid, &pid, sizeof(struct GNUNET_PeerIdentity)))
1161 return GNUNET_SYSERR; 1160 return GNUNET_SYSERR;
1162 return GNUNET_OK; 1161 return GNUNET_OK;
1163} 1162}
@@ -1172,258 +1171,259 @@ blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *cpid)
1172 * @param mycfg configuration 1171 * @param mycfg configuration
1173 */ 1172 */
1174static void 1173static void
1175run (void *cls, 1174run(void *cls,
1176 char *const *args, 1175 char *const *args,
1177 const char *cfgfile, 1176 const char *cfgfile,
1178 const struct GNUNET_CONFIGURATION_Handle *mycfg) 1177 const struct GNUNET_CONFIGURATION_Handle *mycfg)
1179{ 1178{
1180 static struct GNUNET_PeerIdentity zero_pid; 1179 static struct GNUNET_PeerIdentity zero_pid;
1181 int counter = 0; 1180 int counter = 0;
1181
1182 ret = 1; 1182 ret = 1;
1183 1183
1184 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 1184 cfg = (struct GNUNET_CONFIGURATION_Handle *)mycfg;
1185 1185
1186 counter = benchmark_send + benchmark_receive + iterate_connections + 1186 counter = benchmark_send + benchmark_receive + iterate_connections +
1187 monitor_connections + monitor_connects + do_disconnect + 1187 monitor_connections + monitor_connects + do_disconnect +
1188 monitor_plugins; 1188 monitor_plugins;
1189 1189
1190 if (1 < counter) 1190 if (1 < counter)
1191 {
1192 fprintf (
1193 stderr,
1194 _ (
1195 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1196 "disconnect",
1197 "benchmark send",
1198 "benchmark receive",
1199 "information",
1200 "monitor",
1201 "events",
1202 "plugins");
1203 return;
1204 }
1205 if (0 == counter)
1206 {
1207 fprintf (
1208 stderr,
1209 _ (
1210 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1211 "disconnect",
1212 "benchmark send",
1213 "benchmark receive",
1214 "information",
1215 "monitor",
1216 "events",
1217 "plugins");
1218 return;
1219 }
1220
1221 if (do_disconnect) /* -D: Disconnect from peer */
1222 {
1223 if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
1224 { 1191 {
1225 fprintf (stderr, 1192 fprintf(
1226 _ ("Option `%s' makes no sense without option `%s'.\n"), 1193 stderr,
1227 "-D", 1194 _(
1228 "-p"); 1195 "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"),
1229 ret = 1; 1196 "disconnect",
1197 "benchmark send",
1198 "benchmark receive",
1199 "information",
1200 "monitor",
1201 "events",
1202 "plugins");
1230 return; 1203 return;
1231 } 1204 }
1232 blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); 1205 if (0 == counter)
1233 if (NULL == blacklist)
1234 { 1206 {
1235 fprintf (stderr, 1207 fprintf(
1236 "%s", 1208 stderr,
1237 _ ( 1209 _(
1238 "Failed to connect to transport service for disconnection\n")); 1210 "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"),
1239 ret = 1; 1211 "disconnect",
1212 "benchmark send",
1213 "benchmark receive",
1214 "information",
1215 "monitor",
1216 "events",
1217 "plugins");
1240 return; 1218 return;
1241 } 1219 }
1242 fprintf (stdout, 1220
1243 "%s", 1221 if (do_disconnect) /* -D: Disconnect from peer */
1244 _ ("Blacklisting request in place, stop with CTRL-C\n"));
1245 }
1246 else if (benchmark_send) /* -s: Benchmark sending */
1247 {
1248 if (0 == memcmp (&zero_pid, &pid, sizeof (pid)))
1249 { 1222 {
1250 fprintf (stderr, 1223 if (0 == memcmp(&zero_pid, &pid, sizeof(pid)))
1251 _ ("Option `%s' makes no sense without option `%s'.\n"), 1224 {
1252 "-s", 1225 fprintf(stderr,
1253 "-p"); 1226 _("Option `%s' makes no sense without option `%s'.\n"),
1254 ret = 1; 1227 "-D",
1255 return; 1228 "-p");
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"));
1256 } 1245 }
1257 handle = GNUNET_TRANSPORT_core_connect (cfg, 1246 else if (benchmark_send) /* -s: Benchmark sending */
1258 NULL,
1259 NULL,
1260 NULL,
1261 &notify_connect,
1262 &notify_disconnect,
1263 NULL);
1264 if (NULL == handle)
1265 { 1247 {
1266 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); 1248 if (0 == memcmp(&zero_pid, &pid, sizeof(pid)))
1267 ret = 1; 1249 {
1268 return; 1250 fprintf(stderr,
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);
1269 } 1273 }
1270 start_time = GNUNET_TIME_absolute_get ();
1271 op_timeout =
1272 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL);
1273 }
1274 else if (benchmark_receive) /* -b: Benchmark receiving */ 1274 else if (benchmark_receive) /* -b: Benchmark receiving */
1275 { 1275 {
1276 struct GNUNET_MQ_MessageHandler handlers[] = 1276 struct GNUNET_MQ_MessageHandler handlers[] =
1277 {GNUNET_MQ_hd_var_size (dummy, 1277 { GNUNET_MQ_hd_var_size(dummy,
1278 GNUNET_MESSAGE_TYPE_DUMMY, 1278 GNUNET_MESSAGE_TYPE_DUMMY,
1279 struct GNUNET_MessageHeader, 1279 struct GNUNET_MessageHeader,
1280 NULL), 1280 NULL),
1281 GNUNET_MQ_handler_end ()}; 1281 GNUNET_MQ_handler_end() };
1282 1282
1283 handle = GNUNET_TRANSPORT_core_connect (cfg, 1283 handle = GNUNET_TRANSPORT_core_connect(cfg,
1284 NULL, 1284 NULL,
1285 handlers, 1285 handlers,
1286 NULL, 1286 NULL,
1287 NULL, 1287 NULL,
1288 NULL, 1288 NULL,
1289 NULL); 1289 NULL);
1290 if (NULL == handle) 1290 if (NULL == handle)
1291 { 1291 {
1292 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); 1292 fprintf(stderr, "%s", _("Failed to connect to transport service\n"));
1293 ret = 1; 1293 ret = 1;
1294 return; 1294 return;
1295 }
1296 if (verbosity > 0)
1297 fprintf(stdout, "%s", _("Starting to receive benchmark data\n"));
1298 start_time = GNUNET_TIME_absolute_get();
1295 } 1299 }
1296 if (verbosity > 0)
1297 fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n"));
1298 start_time = GNUNET_TIME_absolute_get ();
1299 }
1300 else if (iterate_connections) /* -i: List information about peers once */ 1300 else if (iterate_connections) /* -i: List information about peers once */
1301 { 1301 {
1302 pic = GNUNET_TRANSPORT_monitor_peers (cfg, 1302 pic = GNUNET_TRANSPORT_monitor_peers(cfg,
1303 &pid, 1303 &pid,
1304 GNUNET_YES, 1304 GNUNET_YES,
1305 &process_peer_iteration_cb, 1305 &process_peer_iteration_cb,
1306 (void *) cfg); 1306 (void *)cfg);
1307 op_timeout = 1307 op_timeout =
1308 GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout, NULL); 1308 GNUNET_SCHEDULER_add_delayed(OP_TIMEOUT, &operation_timeout, NULL);
1309 } 1309 }
1310 else if (monitor_connections) /* -m: List information about peers continuously 1310 else if (monitor_connections) /* -m: List information about peers continuously
1311 */ 1311 */
1312 { 1312 {
1313 monitored_peers = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 1313 monitored_peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
1314 pic = GNUNET_TRANSPORT_monitor_peers (cfg, 1314 pic = GNUNET_TRANSPORT_monitor_peers(cfg,
1315 &pid, 1315 &pid,
1316 GNUNET_NO, 1316 GNUNET_NO,
1317 &process_peer_monitoring_cb, 1317 &process_peer_monitoring_cb,
1318 NULL); 1318 NULL);
1319 } 1319 }
1320 else if (monitor_plugins) /* -P: List information about plugins continuously 1320 else if (monitor_plugins) /* -P: List information about plugins continuously
1321 */ 1321 */
1322 { 1322 {
1323 monitored_plugins = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 1323 monitored_plugins = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
1324 pm = GNUNET_TRANSPORT_monitor_plugins (cfg, &plugin_monitoring_cb, NULL); 1324 pm = GNUNET_TRANSPORT_monitor_plugins(cfg, &plugin_monitoring_cb, NULL);
1325 } 1325 }
1326 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */ 1326 else if (monitor_connects) /* -e : Monitor (dis)connect events continuously */
1327 {
1328 monitor_connect_counter = 0;
1329 handle = GNUNET_TRANSPORT_core_connect (cfg,
1330 NULL,
1331 NULL,
1332 NULL,
1333 &monitor_notify_connect,
1334 &monitor_notify_disconnect,
1335 NULL);
1336 if (NULL == handle)
1337 { 1327 {
1338 fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); 1328 monitor_connect_counter = 0;
1339 ret = 1; 1329 handle = GNUNET_TRANSPORT_core_connect(cfg,
1340 return; 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;
1341 } 1343 }
1342 ret = 0;
1343 }
1344 else 1344 else
1345 { 1345 {
1346 GNUNET_break (0); 1346 GNUNET_break(0);
1347 return; 1347 return;
1348 } 1348 }
1349 1349
1350 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 1350 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
1351} 1351}
1352 1352
1353 1353
1354int 1354int
1355main (int argc, char *const *argv) 1355main(int argc, char *const *argv)
1356{ 1356{
1357 int res; 1357 int res;
1358 struct GNUNET_GETOPT_CommandLineOption options[] = 1358 struct GNUNET_GETOPT_CommandLineOption options[] =
1359 {GNUNET_GETOPT_option_flag ( 1359 { GNUNET_GETOPT_option_flag(
1360 'a', 1360 'a',
1361 "all", 1361 "all",
1362 gettext_noop ( 1362 gettext_noop(
1363 "print information for all peers (instead of only connected peers)"), 1363 "print information for all peers (instead of only connected peers)"),
1364 &iterate_all), 1364 &iterate_all),
1365 GNUNET_GETOPT_option_flag ( 1365 GNUNET_GETOPT_option_flag(
1366 'b', 1366 'b',
1367 "benchmark", 1367 "benchmark",
1368 gettext_noop ( 1368 gettext_noop(
1369 "measure how fast we are receiving data from all peers (until CTRL-C)"), 1369 "measure how fast we are receiving data from all peers (until CTRL-C)"),
1370 &benchmark_receive), 1370 &benchmark_receive),
1371 GNUNET_GETOPT_option_flag ('D', 1371 GNUNET_GETOPT_option_flag('D',
1372 "disconnect", 1372 "disconnect",
1373 gettext_noop ("disconnect from a peer"), 1373 gettext_noop("disconnect from a peer"),
1374 &do_disconnect), 1374 &do_disconnect),
1375 GNUNET_GETOPT_option_flag ( 1375 GNUNET_GETOPT_option_flag(
1376 'i', 1376 'i',
1377 "information", 1377 "information",
1378 gettext_noop ( 1378 gettext_noop(
1379 "provide information about all current connections (once)"), 1379 "provide information about all current connections (once)"),
1380 &iterate_connections), 1380 &iterate_connections),
1381 GNUNET_GETOPT_option_flag ( 1381 GNUNET_GETOPT_option_flag(
1382 'm', 1382 'm',
1383 "monitor", 1383 "monitor",
1384 gettext_noop ( 1384 gettext_noop(
1385 "provide information about all current connections (continuously)"), 1385 "provide information about all current connections (continuously)"),
1386 &monitor_connections), 1386 &monitor_connections),
1387 GNUNET_GETOPT_option_flag ( 1387 GNUNET_GETOPT_option_flag(
1388 'e', 1388 'e',
1389 "events", 1389 "events",
1390 gettext_noop ( 1390 gettext_noop(
1391 "provide information about all connects and disconnect events (continuously)"), 1391 "provide information about all connects and disconnect events (continuously)"),
1392 &monitor_connects), 1392 &monitor_connects),
1393 GNUNET_GETOPT_option_flag ('n', 1393 GNUNET_GETOPT_option_flag('n',
1394 "numeric", 1394 "numeric",
1395 gettext_noop ("do not resolve hostnames"), 1395 gettext_noop("do not resolve hostnames"),
1396 &numeric), 1396 &numeric),
1397 GNUNET_GETOPT_option_base32_auto ('p', 1397 GNUNET_GETOPT_option_base32_auto('p',
1398 "peer", 1398 "peer",
1399 "PEER", 1399 "PEER",
1400 gettext_noop ("peer identity"), 1400 gettext_noop("peer identity"),
1401 &pid), 1401 &pid),
1402 GNUNET_GETOPT_option_flag ('P', 1402 GNUNET_GETOPT_option_flag('P',
1403 "plugins", 1403 "plugins",
1404 gettext_noop ("monitor plugin sessions"), 1404 gettext_noop("monitor plugin sessions"),
1405 &monitor_plugins), 1405 &monitor_plugins),
1406 GNUNET_GETOPT_option_flag ( 1406 GNUNET_GETOPT_option_flag(
1407 's', 1407 's',
1408 "send", 1408 "send",
1409 gettext_noop ( 1409 gettext_noop(
1410 "send data for benchmarking to the other peer (until CTRL-C)"), 1410 "send data for benchmarking to the other peer (until CTRL-C)"),
1411 &benchmark_send), 1411 &benchmark_send),
1412 GNUNET_GETOPT_option_verbose (&verbosity), 1412 GNUNET_GETOPT_option_verbose(&verbosity),
1413 GNUNET_GETOPT_OPTION_END}; 1413 GNUNET_GETOPT_OPTION_END };
1414 1414
1415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1415 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1416 return 2; 1416 return 2;
1417 1417
1418 res = 1418 res =
1419 GNUNET_PROGRAM_run (argc, 1419 GNUNET_PROGRAM_run(argc,
1420 argv, 1420 argv,
1421 "gnunet-transport", 1421 "gnunet-transport",
1422 gettext_noop ("Direct access to transport service."), 1422 gettext_noop("Direct access to transport service."),
1423 options, 1423 options,
1424 &run, 1424 &run,
1425 NULL); 1425 NULL);
1426 GNUNET_free ((void *) argv); 1426 GNUNET_free((void *)argv);
1427 if (GNUNET_OK == res) 1427 if (GNUNET_OK == res)
1428 return ret; 1428 return ret;
1429 return 1; 1429 return 1;
diff --git a/src/transport/ieee80211_radiotap.h b/src/transport/ieee80211_radiotap.h
index ed1cd69dd..f05449f18 100644
--- a/src/transport/ieee80211_radiotap.h
+++ b/src/transport/ieee80211_radiotap.h
@@ -40,7 +40,7 @@
40// #include <asm/unaligned.h> 40// #include <asm/unaligned.h>
41 41
42/* Base version of the radiotap packet header data */ 42/* Base version of the radiotap packet header data */
43#define PKTHDR_RADIOTAP_VERSION 0 43#define PKTHDR_RADIOTAP_VERSION 0
44 44
45/* A generic radio capture format is desirable. There is one for 45/* A generic radio capture format is desirable. There is one for
46 * Linux, but it is neither rigidly defined (there were not even 46 * Linux, but it is neither rigidly defined (there were not even
@@ -61,8 +61,7 @@
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{
66 u8 it_version; /* Version 0. Only increases 65 u8 it_version; /* Version 0. Only increases
67 * for drastic changes, 66 * for drastic changes,
68 * introduction of compatible 67 * introduction of compatible
@@ -180,8 +179,7 @@ struct ieee80211_radiotap_header
180 * Number of unicast retries a transmitted frame used. 179 * Number of unicast retries a transmitted frame used.
181 * 180 *
182 */ 181 */
183enum ieee80211_radiotap_type 182enum ieee80211_radiotap_type {
184{
185 IEEE80211_RADIOTAP_TSFT = 0, 183 IEEE80211_RADIOTAP_TSFT = 0,
186 IEEE80211_RADIOTAP_FLAGS = 1, 184 IEEE80211_RADIOTAP_FLAGS = 1,
187 IEEE80211_RADIOTAP_RATE = 2, 185 IEEE80211_RADIOTAP_RATE = 2,
@@ -208,68 +206,68 @@ enum ieee80211_radiotap_type
208}; 206};
209 207
210/* Channel flags. */ 208/* Channel flags. */
211#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */ 209#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
212#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ 210#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
213#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ 211#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
214#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */ 212#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
215#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ 213#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
216#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ 214#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
217#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ 215#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
218#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ 216#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
219 217
220/* For IEEE80211_RADIOTAP_FLAGS */ 218/* For IEEE80211_RADIOTAP_FLAGS */
221#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received 219#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
222 * during CFP 220 * during CFP
223 */ 221 */
224#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received 222#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
225 * with short 223 * with short
226 * preamble 224 * preamble
227 */ 225 */
228#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received 226#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
229 * with WEP encryption 227 * with WEP encryption
230 */ 228 */
231#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received 229#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
232 * with fragmentation 230 * with fragmentation
233 */ 231 */
234#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ 232#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
235#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between 233#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
236 * 802.11 header and payload 234 * 802.11 header and payload
237 * (to 32-bit boundary) 235 * (to 32-bit boundary)
238 */ 236 */
239#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */ 237#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */
240 238
241/* For IEEE80211_RADIOTAP_RX_FLAGS */ 239/* For IEEE80211_RADIOTAP_RX_FLAGS */
242#define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */ 240#define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */
243 241
244/* For IEEE80211_RADIOTAP_TX_FLAGS */ 242/* For IEEE80211_RADIOTAP_TX_FLAGS */
245#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive 243#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
246 * retries */ 244 * retries */
247#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ 245#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
248#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ 246#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
249 247
250/* Ugly macro to convert literal channel numbers into their mhz equivalents 248/* Ugly macro to convert literal channel numbers into their mhz equivalents
251 * There are certianly some conditions that will break this (like feeding it '30') 249 * There are certianly some conditions that will break this (like feeding it '30')
252 * but they shouldn't arise since nothing talks on channel 30. */ 250 * but they shouldn't arise since nothing talks on channel 30. */
253#define ieee80211chan2mhz(x) \ 251#define ieee80211chan2mhz(x) \
254 (((x) <= 14) ? \ 252 (((x) <= 14) ? \
255 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \ 253 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
256 ((x) + 1000) * 5) 254 ((x) + 1000) * 5)
257 255
258/* helpers */ 256/* helpers */
259static inline u16 257static inline u16
260get_unaligned_le16 (const u8 *p) 258get_unaligned_le16(const u8 *p)
261{ 259{
262 return p[0] | p[1] << 8; 260 return p[0] | p[1] << 8;
263} 261}
264 262
265 263
266static inline int 264static inline int
267ieee80211_get_radiotap_len (unsigned char *data) 265ieee80211_get_radiotap_len(unsigned char *data)
268{ 266{
269 struct ieee80211_radiotap_header *hdr = 267 struct ieee80211_radiotap_header *hdr =
270 (struct ieee80211_radiotap_header *) data; 268 (struct ieee80211_radiotap_header *)data;
271 269
272 return get_unaligned_le16 ((const u8 *) &hdr->it_len); 270 return get_unaligned_le16((const u8 *)&hdr->it_len);
273} 271}
274 272
275#endif /* IEEE80211_RADIOTAP_H */ 273#endif /* IEEE80211_RADIOTAP_H */
diff --git a/src/transport/plugin_transport_http.h b/src/transport/plugin_transport_http.h
index b6ada8f86..4ad8f6e58 100644
--- a/src/transport/plugin_transport_http.h
+++ b/src/transport/plugin_transport_http.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_http.h 22 * @file transport/plugin_transport_http.h
@@ -62,13 +62,12 @@
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(GNUNET_TIME_UNIT_SECONDS, 15)
66 66
67/** 67/**
68 * Encapsulation of all of the state of the plugin. 68 * Encapsulation of all of the state of the plugin.
69 */ 69 */
70struct Plugin 70struct Plugin {
71{
72 /** 71 /**
73 * Our environment. 72 * Our environment.
74 */ 73 */
@@ -262,7 +261,6 @@ struct Plugin
262 * curl perform task 261 * curl perform task
263 */ 262 */
264 struct GNUNET_SCHEDULER_Task * client_perform_task; 263 struct GNUNET_SCHEDULER_Task * client_perform_task;
265
266}; 264};
267 265
268GNUNET_NETWORK_STRUCT_BEGIN 266GNUNET_NETWORK_STRUCT_BEGIN
@@ -270,8 +268,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
270/** 268/**
271 * HTTP addresses including a full URI 269 * HTTP addresses including a full URI
272 */ 270 */
273struct HttpAddress 271struct HttpAddress {
274{
275 /** 272 /**
276 * Length of the address following in NBO 273 * Length of the address following in NBO
277 */ 274 */
@@ -286,8 +283,7 @@ struct HttpAddress
286/** 283/**
287 * IPv4 addresses 284 * IPv4 addresses
288 */ 285 */
289struct IPv4HttpAddress 286struct IPv4HttpAddress {
290{
291 /** 287 /**
292 * IPv4 address, in network byte order. 288 * IPv4 address, in network byte order.
293 */ 289 */
@@ -302,8 +298,7 @@ struct IPv4HttpAddress
302/** 298/**
303 * IPv4 addresses 299 * IPv4 addresses
304 */ 300 */
305struct IPv6HttpAddress 301struct IPv6HttpAddress {
306{
307 /** 302 /**
308 * IPv6 address. 303 * IPv6 address.
309 */ 304 */
@@ -317,8 +312,7 @@ struct IPv6HttpAddress
317GNUNET_NETWORK_STRUCT_END 312GNUNET_NETWORK_STRUCT_END
318 313
319 314
320struct ServerRequest 315struct ServerRequest {
321{
322 /** 316 /**
323 * _RECV or _SEND 317 * _RECV or _SEND
324 */ 318 */
@@ -344,8 +338,7 @@ struct ServerRequest
344/** 338/**
345 * Session handle for connections. 339 * Session handle for connections.
346 */ 340 */
347struct GNUNET_ATS_Session 341struct GNUNET_ATS_Session {
348{
349 /** 342 /**
350 * To whom are we talking to 343 * To whom are we talking to
351 */ 344 */
@@ -455,8 +448,7 @@ struct GNUNET_ATS_Session
455/** 448/**
456 * Message to send using http 449 * Message to send using http
457 */ 450 */
458struct HTTP_Message 451struct HTTP_Message {
459{
460 /** 452 /**
461 * next pointer for double linked list 453 * next pointer for double linked list
462 */ 454 */
@@ -497,81 +489,81 @@ struct HTTP_Message
497 489
498 490
499struct GNUNET_ATS_Session * 491struct GNUNET_ATS_Session *
500create_session (struct Plugin *plugin, 492create_session(struct Plugin *plugin,
501 const struct GNUNET_PeerIdentity *target, 493 const struct GNUNET_PeerIdentity *target,
502 const void *addr, 494 const void *addr,
503 size_t addrlen); 495 size_t addrlen);
504 496
505 497
506int 498int
507exist_session (struct Plugin *plugin, 499exist_session(struct Plugin *plugin,
508 struct GNUNET_ATS_Session *s); 500 struct GNUNET_ATS_Session *s);
509 501
510 502
511void 503void
512delete_session (struct GNUNET_ATS_Session *s); 504delete_session(struct GNUNET_ATS_Session *s);
513 505
514 506
515int 507int
516exist_session (struct Plugin *plugin, 508exist_session(struct Plugin *plugin,
517 struct GNUNET_ATS_Session *s); 509 struct GNUNET_ATS_Session *s);
518 510
519 511
520struct GNUNET_TIME_Relative 512struct GNUNET_TIME_Relative
521http_plugin_receive (void *cls, 513http_plugin_receive(void *cls,
522 const struct GNUNET_PeerIdentity *peer, 514 const struct GNUNET_PeerIdentity *peer,
523 const struct GNUNET_MessageHeader *message, 515 const struct GNUNET_MessageHeader *message,
524 struct GNUNET_ATS_Session *session, 516 struct GNUNET_ATS_Session *session,
525 const char *sender_address, 517 const char *sender_address,
526 uint16_t sender_address_len); 518 uint16_t sender_address_len);
527 519
528 520
529const char * 521const char *
530http_plugin_address_to_string (void *cls, 522http_plugin_address_to_string(void *cls,
531 const void *addr, 523 const void *addr,
532 size_t addrlen); 524 size_t addrlen);
533 525
534 526
535int 527int
536client_disconnect (struct GNUNET_ATS_Session *s); 528client_disconnect(struct GNUNET_ATS_Session *s);
537 529
538 530
539int 531int
540client_connect (struct GNUNET_ATS_Session *s); 532client_connect(struct GNUNET_ATS_Session *s);
541 533
542 534
543int 535int
544client_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); 536client_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
545 537
546 538
547int 539int
548client_start (struct Plugin *plugin); 540client_start(struct Plugin *plugin);
549 541
550 542
551void 543void
552client_stop (struct Plugin *plugin); 544client_stop(struct Plugin *plugin);
553 545
554 546
555int 547int
556server_disconnect (struct GNUNET_ATS_Session *s); 548server_disconnect(struct GNUNET_ATS_Session *s);
557 549
558 550
559int 551int
560server_send (struct GNUNET_ATS_Session *s, struct HTTP_Message *msg); 552server_send(struct GNUNET_ATS_Session *s, struct HTTP_Message *msg);
561 553
562 554
563int 555int
564server_start (struct Plugin *plugin); 556server_start(struct Plugin *plugin);
565 557
566 558
567void 559void
568server_stop (struct Plugin *plugin); 560server_stop(struct Plugin *plugin);
569 561
570 562
571void 563void
572notify_session_end (void *cls, 564notify_session_end(void *cls,
573 const struct GNUNET_PeerIdentity *peer, 565 const struct GNUNET_PeerIdentity *peer,
574 struct GNUNET_ATS_Session *s); 566 struct GNUNET_ATS_Session *s);
575 567
576 568
577/*#ifndef PLUGIN_TRANSPORT_HTTP_H*/ 569/*#ifndef PLUGIN_TRANSPORT_HTTP_H*/
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index c4d70d4c3..6148e9a44 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_http_client.c 22 * @file transport/plugin_transport_http_client.c
@@ -39,7 +39,7 @@
39 39
40#define VERBOSE_CURL GNUNET_NO 40#define VERBOSE_CURL GNUNET_NO
41 41
42#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) 42#define PUT_DISCONNECT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1)
43 43
44#define ENABLE_PUT GNUNET_YES 44#define ENABLE_PUT GNUNET_YES
45#define ENABLE_GET GNUNET_YES 45#define ENABLE_GET GNUNET_YES
@@ -53,7 +53,7 @@
53#include "gnunet_curl_lib.h" 53#include "gnunet_curl_lib.h"
54 54
55 55
56#define LOG(kind,...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__) 56#define LOG(kind, ...) GNUNET_log_from(kind, PLUGIN_NAME, __VA_ARGS__)
57 57
58/** 58/**
59 * Encapsulation of all of the state of the plugin. 59 * Encapsulation of all of the state of the plugin.
@@ -63,8 +63,7 @@ struct HTTP_Client_Plugin;
63/** 63/**
64 * State of a HTTP PUT request 64 * State of a HTTP PUT request
65 */ 65 */
66enum HTTP_PUT_REQUEST_STATE 66enum HTTP_PUT_REQUEST_STATE {
67{
68 /** 67 /**
69 * Just created, not yet connected 68 * Just created, not yet connected
70 */ 69 */
@@ -104,8 +103,7 @@ enum HTTP_PUT_REQUEST_STATE
104/** 103/**
105 * Message to send using http 104 * Message to send using http
106 */ 105 */
107struct HTTP_Message 106struct HTTP_Message {
108{
109 /** 107 /**
110 * next pointer for double linked list 108 * next pointer for double linked list
111 */ 109 */
@@ -142,7 +140,6 @@ struct HTTP_Message
142 * buffer length 140 * buffer length
143 */ 141 */
144 size_t size; 142 size_t size;
145
146}; 143};
147 144
148 145
@@ -156,8 +153,7 @@ struct GNUNET_ATS_Session;
156 * A request handle 153 * A request handle
157 * 154 *
158 */ 155 */
159struct RequestHandle 156struct RequestHandle {
160{
161 /** 157 /**
162 * Current state of this request 158 * Current state of this request
163 */ 159 */
@@ -178,8 +174,7 @@ struct RequestHandle
178/** 174/**
179 * Session handle for connections. 175 * Session handle for connections.
180 */ 176 */
181struct GNUNET_ATS_Session 177struct GNUNET_ATS_Session {
182{
183 /** 178 /**
184 * The URL to connect to 179 * The URL to connect to
185 */ 180 */
@@ -272,8 +267,7 @@ struct GNUNET_ATS_Session
272/** 267/**
273 * Encapsulation of all of the state of the plugin. 268 * Encapsulation of all of the state of the plugin.
274 */ 269 */
275struct HTTP_Client_Plugin 270struct HTTP_Client_Plugin {
276{
277 /** 271 /**
278 * Our environment. 272 * Our environment.
279 */ 273 */
@@ -394,7 +388,7 @@ struct HTTP_Client_Plugin
394 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 388 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
395 */ 389 */
396static int 390static int
397http_client_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *s); 391http_client_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *s);
398 392
399 393
400/** 394/**
@@ -406,15 +400,15 @@ http_client_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *s);
406 * @param state new state of the session 400 * @param state new state of the session
407 */ 401 */
408static void 402static void
409notify_session_monitor (struct HTTP_Client_Plugin *plugin, 403notify_session_monitor(struct HTTP_Client_Plugin *plugin,
410 struct GNUNET_ATS_Session *session, 404 struct GNUNET_ATS_Session *session,
411 enum GNUNET_TRANSPORT_SessionState state) 405 enum GNUNET_TRANSPORT_SessionState state)
412{ 406{
413 struct GNUNET_TRANSPORT_SessionInfo info; 407 struct GNUNET_TRANSPORT_SessionInfo info;
414 408
415 if (NULL == plugin->sic) 409 if (NULL == plugin->sic)
416 return; 410 return;
417 memset (&info, 0, sizeof (info)); 411 memset(&info, 0, sizeof(info));
418 info.state = state; 412 info.state = state;
419 info.is_inbound = GNUNET_NO; 413 info.is_inbound = GNUNET_NO;
420 info.num_msg_pending = session->msgs_in_queue; 414 info.num_msg_pending = session->msgs_in_queue;
@@ -422,9 +416,9 @@ notify_session_monitor (struct HTTP_Client_Plugin *plugin,
422 info.receive_delay = session->next_receive; 416 info.receive_delay = session->next_receive;
423 info.session_timeout = session->timeout; 417 info.session_timeout = session->timeout;
424 info.address = session->address; 418 info.address = session->address;
425 plugin->sic (plugin->sic_cls, 419 plugin->sic(plugin->sic_cls,
426 session, 420 session,
427 &info); 421 &info);
428} 422}
429 423
430 424
@@ -434,7 +428,7 @@ notify_session_monitor (struct HTTP_Client_Plugin *plugin,
434 * @param s the session to delete 428 * @param s the session to delete
435 */ 429 */
436static void 430static void
437client_delete_session (struct GNUNET_ATS_Session *s) 431client_delete_session(struct GNUNET_ATS_Session *s)
438{ 432{
439 struct HTTP_Client_Plugin *plugin = s->plugin; 433 struct HTTP_Client_Plugin *plugin = s->plugin;
440 struct HTTP_Message *pos; 434 struct HTTP_Message *pos;
@@ -442,95 +436,95 @@ client_delete_session (struct GNUNET_ATS_Session *s)
442 CURLMcode mret; 436 CURLMcode mret;
443 437
444 if (NULL != s->timeout_task) 438 if (NULL != s->timeout_task)
445 { 439 {
446 GNUNET_SCHEDULER_cancel (s->timeout_task); 440 GNUNET_SCHEDULER_cancel(s->timeout_task);
447 s->timeout_task = NULL; 441 s->timeout_task = NULL;
448 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 442 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
449 } 443 }
450 if (NULL != s->put_disconnect_task) 444 if (NULL != s->put_disconnect_task)
451 { 445 {
452 GNUNET_SCHEDULER_cancel (s->put_disconnect_task); 446 GNUNET_SCHEDULER_cancel(s->put_disconnect_task);
453 s->put_disconnect_task = NULL; 447 s->put_disconnect_task = NULL;
454 } 448 }
455 if (NULL != s->recv_wakeup_task) 449 if (NULL != s->recv_wakeup_task)
456 { 450 {
457 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); 451 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task);
458 s->recv_wakeup_task = NULL; 452 s->recv_wakeup_task = NULL;
459 } 453 }
460 GNUNET_assert (GNUNET_OK == 454 GNUNET_assert(GNUNET_OK ==
461 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, 455 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions,
462 &s->address->peer, 456 &s->address->peer,
463 s)); 457 s));
464 if (NULL != s->put.easyhandle) 458 if (NULL != s->put.easyhandle)
465 { 459 {
466 LOG (GNUNET_ERROR_TYPE_DEBUG, 460 LOG(GNUNET_ERROR_TYPE_DEBUG,
467 "Session %p/request %p: disconnecting PUT request to peer `%s'\n", 461 "Session %p/request %p: disconnecting PUT request to peer `%s'\n",
468 s, 462 s,
469 s->put.easyhandle, 463 s->put.easyhandle,
470 GNUNET_i2s (&s->address->peer)); 464 GNUNET_i2s(&s->address->peer));
471 465
472 /* remove curl handle from multi handle */ 466 /* remove curl handle from multi handle */
473 mret = curl_multi_remove_handle (plugin->curl_multi_handle, 467 mret = curl_multi_remove_handle(plugin->curl_multi_handle,
474 s->put.easyhandle); 468 s->put.easyhandle);
475 GNUNET_break (CURLM_OK == mret); 469 GNUNET_break(CURLM_OK == mret);
476 curl_easy_cleanup (s->put.easyhandle); 470 curl_easy_cleanup(s->put.easyhandle);
477 GNUNET_assert (plugin->cur_requests > 0); 471 GNUNET_assert(plugin->cur_requests > 0);
478 plugin->cur_requests--; 472 plugin->cur_requests--;
479 s->put.easyhandle = NULL; 473 s->put.easyhandle = NULL;
480 } 474 }
481 if (NULL != s->get.easyhandle) 475 if (NULL != s->get.easyhandle)
482 { 476 {
483 LOG (GNUNET_ERROR_TYPE_DEBUG, 477 LOG(GNUNET_ERROR_TYPE_DEBUG,
484 "Session %p/request %p: disconnecting GET request to peer `%s'\n", 478 "Session %p/request %p: disconnecting GET request to peer `%s'\n",
485 s, s->get.easyhandle, 479 s, s->get.easyhandle,
486 GNUNET_i2s (&s->address->peer)); 480 GNUNET_i2s(&s->address->peer));
487 /* remove curl handle from multi handle */ 481 /* remove curl handle from multi handle */
488 mret = curl_multi_remove_handle (plugin->curl_multi_handle, 482 mret = curl_multi_remove_handle(plugin->curl_multi_handle,
489 s->get.easyhandle); 483 s->get.easyhandle);
490 GNUNET_break (CURLM_OK == mret); 484 GNUNET_break(CURLM_OK == mret);
491 curl_easy_cleanup (s->get.easyhandle); 485 curl_easy_cleanup(s->get.easyhandle);
492 GNUNET_assert (plugin->cur_requests > 0); 486 GNUNET_assert(plugin->cur_requests > 0);
493 plugin->cur_requests--; 487 plugin->cur_requests--;
494 s->get.easyhandle = NULL; 488 s->get.easyhandle = NULL;
495 } 489 }
496 490
497 GNUNET_STATISTICS_set (plugin->env->stats, 491 GNUNET_STATISTICS_set(plugin->env->stats,
498 HTTP_STAT_STR_CONNECTIONS, 492 HTTP_STAT_STR_CONNECTIONS,
499 plugin->cur_requests, 493 plugin->cur_requests,
500 GNUNET_NO); 494 GNUNET_NO);
501 next = s->msg_head; 495 next = s->msg_head;
502 while (NULL != (pos = next)) 496 while (NULL != (pos = next))
503 { 497 {
504 next = pos->next; 498 next = pos->next;
505 GNUNET_CONTAINER_DLL_remove (s->msg_head, 499 GNUNET_CONTAINER_DLL_remove(s->msg_head,
506 s->msg_tail, 500 s->msg_tail,
507 pos); 501 pos);
508 GNUNET_assert (0 < s->msgs_in_queue); 502 GNUNET_assert(0 < s->msgs_in_queue);
509 s->msgs_in_queue--; 503 s->msgs_in_queue--;
510 GNUNET_assert (pos->size <= s->bytes_in_queue); 504 GNUNET_assert(pos->size <= s->bytes_in_queue);
511 s->bytes_in_queue -= pos->size; 505 s->bytes_in_queue -= pos->size;
512 if (NULL != pos->transmit_cont) 506 if (NULL != pos->transmit_cont)
513 pos->transmit_cont (pos->transmit_cont_cls, 507 pos->transmit_cont(pos->transmit_cont_cls,
514 &s->address->peer, 508 &s->address->peer,
515 GNUNET_SYSERR, 509 GNUNET_SYSERR,
516 pos->size, 510 pos->size,
517 pos->pos + s->overhead); 511 pos->pos + s->overhead);
518 s->overhead = 0; 512 s->overhead = 0;
519 GNUNET_free (pos); 513 GNUNET_free(pos);
520 } 514 }
521 GNUNET_assert (0 == s->msgs_in_queue); 515 GNUNET_assert(0 == s->msgs_in_queue);
522 GNUNET_assert (0 == s->bytes_in_queue); 516 GNUNET_assert(0 == s->bytes_in_queue);
523 notify_session_monitor (plugin, 517 notify_session_monitor(plugin,
524 s, 518 s,
525 GNUNET_TRANSPORT_SS_DONE); 519 GNUNET_TRANSPORT_SS_DONE);
526 if (NULL != s->msg_tk) 520 if (NULL != s->msg_tk)
527 { 521 {
528 GNUNET_MST_destroy (s->msg_tk); 522 GNUNET_MST_destroy(s->msg_tk);
529 s->msg_tk = NULL; 523 s->msg_tk = NULL;
530 } 524 }
531 GNUNET_HELLO_address_free (s->address); 525 GNUNET_HELLO_address_free(s->address);
532 GNUNET_free (s->url); 526 GNUNET_free(s->url);
533 GNUNET_free (s); 527 GNUNET_free(s);
534} 528}
535 529
536 530
@@ -540,10 +534,10 @@ client_delete_session (struct GNUNET_ATS_Session *s)
540 * @param s the session 534 * @param s the session
541 */ 535 */
542static void 536static void
543client_reschedule_session_timeout (struct GNUNET_ATS_Session *s) 537client_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
544{ 538{
545 GNUNET_assert (NULL != s->timeout_task); 539 GNUNET_assert(NULL != s->timeout_task);
546 s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 540 s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
547} 541}
548 542
549 543
@@ -554,7 +548,7 @@ client_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
554 * @param tc gnunet scheduler task context 548 * @param tc gnunet scheduler task context
555 */ 549 */
556static void 550static void
557client_run (void *cls); 551client_run(void *cls);
558 552
559 553
560/** 554/**
@@ -565,8 +559,8 @@ client_run (void *cls);
565 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok 559 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
566 */ 560 */
567static int 561static int
568client_schedule (struct HTTP_Client_Plugin *plugin, 562client_schedule(struct HTTP_Client_Plugin *plugin,
569 int now) 563 int now)
570{ 564{
571 fd_set rs; 565 fd_set rs;
572 fd_set ws; 566 fd_set ws;
@@ -580,54 +574,54 @@ client_schedule (struct HTTP_Client_Plugin *plugin,
580 574
581 /* Cancel previous scheduled task */ 575 /* Cancel previous scheduled task */
582 if (plugin->client_perform_task != NULL) 576 if (plugin->client_perform_task != NULL)
583 { 577 {
584 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 578 GNUNET_SCHEDULER_cancel(plugin->client_perform_task);
585 plugin->client_perform_task = NULL; 579 plugin->client_perform_task = NULL;
586 } 580 }
587 max = -1; 581 max = -1;
588 FD_ZERO (&rs); 582 FD_ZERO(&rs);
589 FD_ZERO (&ws); 583 FD_ZERO(&ws);
590 FD_ZERO (&es); 584 FD_ZERO(&es);
591 mret = curl_multi_fdset (plugin->curl_multi_handle, &rs, &ws, &es, &max); 585 mret = curl_multi_fdset(plugin->curl_multi_handle, &rs, &ws, &es, &max);
592 if (mret != CURLM_OK) 586 if (mret != CURLM_OK)
593 { 587 {
594 LOG (GNUNET_ERROR_TYPE_ERROR, 588 LOG(GNUNET_ERROR_TYPE_ERROR,
595 _("%s failed at %s:%d: `%s'\n"), 589 _("%s failed at %s:%d: `%s'\n"),
596 "curl_multi_fdset", 590 "curl_multi_fdset",
597 __FILE__, 591 __FILE__,
598 __LINE__, 592 __LINE__,
599 curl_multi_strerror (mret)); 593 curl_multi_strerror(mret));
600 return GNUNET_SYSERR; 594 return GNUNET_SYSERR;
601 } 595 }
602 mret = curl_multi_timeout (plugin->curl_multi_handle, &to); 596 mret = curl_multi_timeout(plugin->curl_multi_handle, &to);
603 if (-1 == to) 597 if (-1 == to)
604 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); 598 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1);
605 else 599 else
606 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to); 600 timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, to);
607 if (now == GNUNET_YES) 601 if (now == GNUNET_YES)
608 timeout = GNUNET_TIME_UNIT_MILLISECONDS; 602 timeout = GNUNET_TIME_UNIT_MILLISECONDS;
609 603
610 if (CURLM_OK != mret) 604 if (CURLM_OK != mret)
611 { 605 {
612 LOG (GNUNET_ERROR_TYPE_ERROR, 606 LOG(GNUNET_ERROR_TYPE_ERROR,
613 _("%s failed at %s:%d: `%s'\n"), 607 _("%s failed at %s:%d: `%s'\n"),
614 "curl_multi_timeout", __FILE__, __LINE__, 608 "curl_multi_timeout", __FILE__, __LINE__,
615 curl_multi_strerror (mret)); 609 curl_multi_strerror(mret));
616 return GNUNET_SYSERR; 610 return GNUNET_SYSERR;
617 } 611 }
618 612
619 grs = GNUNET_NETWORK_fdset_create (); 613 grs = GNUNET_NETWORK_fdset_create();
620 gws = GNUNET_NETWORK_fdset_create (); 614 gws = GNUNET_NETWORK_fdset_create();
621 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 615 GNUNET_NETWORK_fdset_copy_native(grs, &rs, max + 1);
622 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 616 GNUNET_NETWORK_fdset_copy_native(gws, &ws, max + 1);
623 617
624 /* Schedule task to run when select is ready to read or write */ 618 /* Schedule task to run when select is ready to read or write */
625 plugin->client_perform_task = 619 plugin->client_perform_task =
626 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 620 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
627 timeout, grs, gws, 621 timeout, grs, gws,
628 &client_run, plugin); 622 &client_run, plugin);
629 GNUNET_NETWORK_fdset_destroy (gws); 623 GNUNET_NETWORK_fdset_destroy(gws);
630 GNUNET_NETWORK_fdset_destroy (grs); 624 GNUNET_NETWORK_fdset_destroy(grs);
631 return GNUNET_OK; 625 return GNUNET_OK;
632} 626}
633 627
@@ -644,55 +638,58 @@ client_schedule (struct HTTP_Client_Plugin *plugin,
644 * @return always 0 638 * @return always 0
645 */ 639 */
646static int 640static int
647client_log (CURL *curl, 641client_log(CURL *curl,
648 curl_infotype type, 642 curl_infotype type,
649 const char *data, 643 const char *data,
650 size_t size, 644 size_t size,
651 void *cls) 645 void *cls)
652{ 646{
653 struct RequestHandle *ch = cls; 647 struct RequestHandle *ch = cls;
654 const char *ttype = "UNSPECIFIED"; 648 const char *ttype = "UNSPECIFIED";
655 char text[size + 2]; 649 char text[size + 2];
656 650
657 if (! ((CURLINFO_TEXT == type) || 651 if (!((CURLINFO_TEXT == type) ||
658 (CURLINFO_HEADER_IN == type) || 652 (CURLINFO_HEADER_IN == type) ||
659 (CURLINFO_HEADER_OUT == type))) 653 (CURLINFO_HEADER_OUT == type)))
660 return 0; 654 return 0;
661 switch (type) 655 switch (type)
662 { 656 {
663 case CURLINFO_TEXT: 657 case CURLINFO_TEXT:
664 ttype = "TEXT"; 658 ttype = "TEXT";
665 break; 659 break;
666 case CURLINFO_HEADER_IN: 660
667 ttype = "HEADER_IN"; 661 case CURLINFO_HEADER_IN:
668 break; 662 ttype = "HEADER_IN";
669 case CURLINFO_HEADER_OUT: 663 break;
670 ttype = "HEADER_OUT"; 664
671 /* Overhead*/ 665 case CURLINFO_HEADER_OUT:
672 GNUNET_assert (NULL != ch); 666 ttype = "HEADER_OUT";
673 GNUNET_assert (NULL != ch->easyhandle); 667 /* Overhead*/
674 GNUNET_assert (NULL != ch->s); 668 GNUNET_assert(NULL != ch);
675 ch->s->overhead += size; 669 GNUNET_assert(NULL != ch->easyhandle);
676 break; 670 GNUNET_assert(NULL != ch->s);
677 default: 671 ch->s->overhead += size;
678 ttype = "UNSPECIFIED"; 672 break;
679 break; 673
680 } 674 default:
681 GNUNET_memcpy (text, data, size); 675 ttype = "UNSPECIFIED";
676 break;
677 }
678 GNUNET_memcpy(text, data, size);
682 if (text[size - 1] == '\n') 679 if (text[size - 1] == '\n')
683 { 680 {
684 text[size] = '\0'; 681 text[size] = '\0';
685 } 682 }
686 else 683 else
687 { 684 {
688 text[size] = '\n'; 685 text[size] = '\n';
689 text[size + 1] = '\0'; 686 text[size + 1] = '\0';
690 } 687 }
691 LOG (GNUNET_ERROR_TYPE_DEBUG, 688 LOG(GNUNET_ERROR_TYPE_DEBUG,
692 "Request %p %s: %s", 689 "Request %p %s: %s",
693 ch->easyhandle, 690 ch->easyhandle,
694 ttype, 691 ttype,
695 text); 692 text);
696 return 0; 693 return 0;
697} 694}
698#endif 695#endif
@@ -704,7 +701,7 @@ client_log (CURL *curl,
704 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 701 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
705 */ 702 */
706static int 703static int
707client_connect_get (struct GNUNET_ATS_Session *s); 704client_connect_get(struct GNUNET_ATS_Session *s);
708 705
709 706
710/** 707/**
@@ -714,7 +711,7 @@ client_connect_get (struct GNUNET_ATS_Session *s);
714 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success 711 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success
715 */ 712 */
716static int 713static int
717client_connect_put (struct GNUNET_ATS_Session *s); 714client_connect_put(struct GNUNET_ATS_Session *s);
718 715
719 716
720/** 717/**
@@ -745,86 +742,86 @@ client_connect_put (struct GNUNET_ATS_Session *s);
745 * and does NOT mean that the message was not transmitted (DV) 742 * and does NOT mean that the message was not transmitted (DV)
746 */ 743 */
747static ssize_t 744static ssize_t
748http_client_plugin_send (void *cls, 745http_client_plugin_send(void *cls,
749 struct GNUNET_ATS_Session *s, 746 struct GNUNET_ATS_Session *s,
750 const char *msgbuf, 747 const char *msgbuf,
751 size_t msgbuf_size, 748 size_t msgbuf_size,
752 unsigned int priority, 749 unsigned int priority,
753 struct GNUNET_TIME_Relative to, 750 struct GNUNET_TIME_Relative to,
754 GNUNET_TRANSPORT_TransmitContinuation cont, 751 GNUNET_TRANSPORT_TransmitContinuation cont,
755 void *cont_cls) 752 void *cont_cls)
756{ 753{
757 struct HTTP_Client_Plugin *plugin = cls; 754 struct HTTP_Client_Plugin *plugin = cls;
758 struct HTTP_Message *msg; 755 struct HTTP_Message *msg;
759 char *stat_txt; 756 char *stat_txt;
760 757
761 LOG (GNUNET_ERROR_TYPE_DEBUG, 758 LOG(GNUNET_ERROR_TYPE_DEBUG,
762 "Session %p/request %p: Sending message with %u to peer `%s' \n", 759 "Session %p/request %p: Sending message with %u to peer `%s' \n",
763 s, 760 s,
764 s->put.easyhandle, 761 s->put.easyhandle,
765 msgbuf_size, 762 msgbuf_size,
766 GNUNET_i2s (&s->address->peer)); 763 GNUNET_i2s(&s->address->peer));
767 764
768 /* create new message and schedule */ 765 /* create new message and schedule */
769 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); 766 msg = GNUNET_malloc(sizeof(struct HTTP_Message) + msgbuf_size);
770 msg->size = msgbuf_size; 767 msg->size = msgbuf_size;
771 msg->buf = (char *) &msg[1]; 768 msg->buf = (char *)&msg[1];
772 msg->transmit_cont = cont; 769 msg->transmit_cont = cont;
773 msg->transmit_cont_cls = cont_cls; 770 msg->transmit_cont_cls = cont_cls;
774 GNUNET_memcpy (msg->buf, 771 GNUNET_memcpy(msg->buf,
775 msgbuf, 772 msgbuf,
776 msgbuf_size); 773 msgbuf_size);
777 GNUNET_CONTAINER_DLL_insert_tail (s->msg_head, 774 GNUNET_CONTAINER_DLL_insert_tail(s->msg_head,
778 s->msg_tail, 775 s->msg_tail,
779 msg); 776 msg);
780 s->msgs_in_queue++; 777 s->msgs_in_queue++;
781 s->bytes_in_queue += msg->size; 778 s->bytes_in_queue += msg->size;
782 779
783 GNUNET_asprintf (&stat_txt, 780 GNUNET_asprintf(&stat_txt,
784 "# bytes currently in %s_client buffers", 781 "# bytes currently in %s_client buffers",
785 plugin->protocol); 782 plugin->protocol);
786 GNUNET_STATISTICS_update (plugin->env->stats, 783 GNUNET_STATISTICS_update(plugin->env->stats,
787 stat_txt, msgbuf_size, GNUNET_NO); 784 stat_txt, msgbuf_size, GNUNET_NO);
788 GNUNET_free (stat_txt); 785 GNUNET_free(stat_txt);
789 notify_session_monitor (plugin, 786 notify_session_monitor(plugin,
790 s, 787 s,
791 GNUNET_TRANSPORT_SS_UPDATE); 788 GNUNET_TRANSPORT_SS_UPDATE);
792 if (H_TMP_DISCONNECTING == s->put.state) 789 if (H_TMP_DISCONNECTING == s->put.state)
793 { 790 {
794 /* PUT request is currently getting disconnected */ 791 /* PUT request is currently getting disconnected */
795 s->put.state = H_TMP_RECONNECT_REQUIRED; 792 s->put.state = H_TMP_RECONNECT_REQUIRED;
796 LOG (GNUNET_ERROR_TYPE_DEBUG, 793 LOG(GNUNET_ERROR_TYPE_DEBUG,
797 "Session %p/request %p: currently disconnecting, reconnecting immediately\n", 794 "Session %p/request %p: currently disconnecting, reconnecting immediately\n",
798 s, 795 s,
799 s->put.easyhandle); 796 s->put.easyhandle);
800 return msgbuf_size; 797 return msgbuf_size;
801 } 798 }
802 if (H_PAUSED == s->put.state) 799 if (H_PAUSED == s->put.state)
803 { 800 {
804 /* PUT request was paused, unpause */ 801 /* PUT request was paused, unpause */
805 GNUNET_assert (s->put_disconnect_task != NULL); 802 GNUNET_assert(s->put_disconnect_task != NULL);
806 GNUNET_SCHEDULER_cancel (s->put_disconnect_task); 803 GNUNET_SCHEDULER_cancel(s->put_disconnect_task);
807 s->put_disconnect_task = NULL; 804 s->put_disconnect_task = NULL;
808 LOG (GNUNET_ERROR_TYPE_DEBUG, 805 LOG(GNUNET_ERROR_TYPE_DEBUG,
809 "Session %p/request %p: unpausing request\n", 806 "Session %p/request %p: unpausing request\n",
810 s, s->put.easyhandle); 807 s, s->put.easyhandle);
811 s->put.state = H_CONNECTED; 808 s->put.state = H_CONNECTED;
812 if (NULL != s->put.easyhandle) 809 if (NULL != s->put.easyhandle)
813 curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); 810 curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT);
814 } 811 }
815 else if (H_TMP_DISCONNECTED == s->put.state) 812 else if (H_TMP_DISCONNECTED == s->put.state)
816 {
817 /* PUT request was disconnected, reconnect */
818 LOG (GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
819 GNUNET_break (NULL == s->put.easyhandle);
820 if (GNUNET_SYSERR == client_connect_put (s))
821 { 813 {
822 /* Could not reconnect */ 814 /* PUT request was disconnected, reconnect */
823 http_client_plugin_session_disconnect (plugin, s); 815 LOG(GNUNET_ERROR_TYPE_DEBUG, "Session %p: Reconnecting PUT request\n", s);
824 return GNUNET_SYSERR; 816 GNUNET_break(NULL == s->put.easyhandle);
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 }
825 } 823 }
826 } 824 client_schedule(s->plugin, GNUNET_YES);
827 client_schedule (s->plugin, GNUNET_YES);
828 return msgbuf_size; 825 return msgbuf_size;
829} 826}
830 827
@@ -837,26 +834,26 @@ http_client_plugin_send (void *cls,
837 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 834 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
838 */ 835 */
839static int 836static int
840http_client_plugin_session_disconnect (void *cls, 837http_client_plugin_session_disconnect(void *cls,
841 struct GNUNET_ATS_Session *s) 838 struct GNUNET_ATS_Session *s)
842{ 839{
843 struct HTTP_Client_Plugin *plugin = cls; 840 struct HTTP_Client_Plugin *plugin = cls;
844 841
845 LOG (GNUNET_ERROR_TYPE_DEBUG, 842 LOG(GNUNET_ERROR_TYPE_DEBUG,
846 "Session %p: notifying transport about ending session\n", 843 "Session %p: notifying transport about ending session\n",
847 s); 844 s);
848 plugin->env->session_end (plugin->env->cls, 845 plugin->env->session_end(plugin->env->cls,
849 s->address, 846 s->address,
850 s); 847 s);
851 client_delete_session (s); 848 client_delete_session(s);
852 849
853 /* Re-schedule since handles have changed */ 850 /* Re-schedule since handles have changed */
854 if (NULL != plugin->client_perform_task) 851 if (NULL != plugin->client_perform_task)
855 { 852 {
856 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 853 GNUNET_SCHEDULER_cancel(plugin->client_perform_task);
857 plugin->client_perform_task = NULL; 854 plugin->client_perform_task = NULL;
858 } 855 }
859 client_schedule (plugin, GNUNET_YES); 856 client_schedule(plugin, GNUNET_YES);
860 857
861 return GNUNET_OK; 858 return GNUNET_OK;
862} 859}
@@ -871,7 +868,7 @@ http_client_plugin_session_disconnect (void *cls,
871 * @return keepalive factor 868 * @return keepalive factor
872 */ 869 */
873static unsigned int 870static unsigned int
874http_client_query_keepalive_factor (void *cls) 871http_client_query_keepalive_factor(void *cls)
875{ 872{
876 return 3; 873 return 3;
877} 874}
@@ -886,14 +883,14 @@ http_client_query_keepalive_factor (void *cls)
886 * @return #GNUNET_OK (continue iterating) 883 * @return #GNUNET_OK (continue iterating)
887 */ 884 */
888static int 885static int
889destroy_session_cb (void *cls, 886destroy_session_cb(void *cls,
890 const struct GNUNET_PeerIdentity *peer, 887 const struct GNUNET_PeerIdentity *peer,
891 void *value) 888 void *value)
892{ 889{
893 struct HTTP_Client_Plugin *plugin = cls; 890 struct HTTP_Client_Plugin *plugin = cls;
894 struct GNUNET_ATS_Session *session = value; 891 struct GNUNET_ATS_Session *session = value;
895 892
896 http_client_plugin_session_disconnect (plugin, session); 893 http_client_plugin_session_disconnect(plugin, session);
897 return GNUNET_OK; 894 return GNUNET_OK;
898} 895}
899 896
@@ -907,26 +904,25 @@ destroy_session_cb (void *cls,
907 * @param target peer from which to disconnect 904 * @param target peer from which to disconnect
908 */ 905 */
909static void 906static void
910http_client_plugin_peer_disconnect (void *cls, 907http_client_plugin_peer_disconnect(void *cls,
911 const struct GNUNET_PeerIdentity *target) 908 const struct GNUNET_PeerIdentity *target)
912{ 909{
913 struct HTTP_Client_Plugin *plugin = cls; 910 struct HTTP_Client_Plugin *plugin = cls;
914 911
915 LOG (GNUNET_ERROR_TYPE_DEBUG, 912 LOG(GNUNET_ERROR_TYPE_DEBUG,
916 "Transport tells me to disconnect `%s'\n", 913 "Transport tells me to disconnect `%s'\n",
917 GNUNET_i2s (target)); 914 GNUNET_i2s(target));
918 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 915 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
919 target, 916 target,
920 &destroy_session_cb, 917 &destroy_session_cb,
921 plugin); 918 plugin);
922} 919}
923 920
924 921
925/** 922/**
926 * Closure for #session_lookup_client_by_address(). 923 * Closure for #session_lookup_client_by_address().
927 */ 924 */
928struct GNUNET_ATS_SessionClientCtx 925struct GNUNET_ATS_SessionClientCtx {
929{
930 /** 926 /**
931 * Address we are looking for. 927 * Address we are looking for.
932 */ 928 */
@@ -948,19 +944,19 @@ struct GNUNET_ATS_SessionClientCtx
948 * @return #GNUNET_NO if found, #GNUNET_OK if not 944 * @return #GNUNET_NO if found, #GNUNET_OK if not
949 */ 945 */
950static int 946static int
951session_lookup_client_by_address (void *cls, 947session_lookup_client_by_address(void *cls,
952 const struct GNUNET_PeerIdentity *key, 948 const struct GNUNET_PeerIdentity *key,
953 void *value) 949 void *value)
954{ 950{
955 struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls; 951 struct GNUNET_ATS_SessionClientCtx *sc_ctx = cls;
956 struct GNUNET_ATS_Session *s = value; 952 struct GNUNET_ATS_Session *s = value;
957 953
958 if (0 == GNUNET_HELLO_address_cmp (sc_ctx->address, 954 if (0 == GNUNET_HELLO_address_cmp(sc_ctx->address,
959 s->address)) 955 s->address))
960 { 956 {
961 sc_ctx->ret = s; 957 sc_ctx->ret = s;
962 return GNUNET_NO; 958 return GNUNET_NO;
963 } 959 }
964 return GNUNET_YES; 960 return GNUNET_YES;
965} 961}
966 962
@@ -973,16 +969,16 @@ session_lookup_client_by_address (void *cls,
973 * @return the session or NULL 969 * @return the session or NULL
974 */ 970 */
975static struct GNUNET_ATS_Session * 971static struct GNUNET_ATS_Session *
976client_lookup_session (struct HTTP_Client_Plugin *plugin, 972client_lookup_session(struct HTTP_Client_Plugin *plugin,
977 const struct GNUNET_HELLO_Address *address) 973 const struct GNUNET_HELLO_Address *address)
978{ 974{
979 struct GNUNET_ATS_SessionClientCtx sc_ctx; 975 struct GNUNET_ATS_SessionClientCtx sc_ctx;
980 976
981 sc_ctx.address = address; 977 sc_ctx.address = address;
982 sc_ctx.ret = NULL; 978 sc_ctx.ret = NULL;
983 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 979 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
984 &session_lookup_client_by_address, 980 &session_lookup_client_by_address,
985 &sc_ctx); 981 &sc_ctx);
986 return sc_ctx.ret; 982 return sc_ctx.ret;
987} 983}
988 984
@@ -995,19 +991,19 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin,
995 * @param cls the `struct GNUNET_ATS_Session *` with the put 991 * @param cls the `struct GNUNET_ATS_Session *` with the put
996 */ 992 */
997static void 993static void
998client_put_disconnect (void *cls) 994client_put_disconnect(void *cls)
999{ 995{
1000 struct GNUNET_ATS_Session *s = cls; 996 struct GNUNET_ATS_Session *s = cls;
1001 997
1002 s->put_disconnect_task = NULL; 998 s->put_disconnect_task = NULL;
1003 LOG (GNUNET_ERROR_TYPE_DEBUG, 999 LOG(GNUNET_ERROR_TYPE_DEBUG,
1004 "Session %p/request %p: will be disconnected due to no activity\n", 1000 "Session %p/request %p: will be disconnected due to no activity\n",
1005 s, s->put.easyhandle); 1001 s, s->put.easyhandle);
1006 s->put.state = H_TMP_DISCONNECTING; 1002 s->put.state = H_TMP_DISCONNECTING;
1007 if (NULL != s->put.easyhandle) 1003 if (NULL != s->put.easyhandle)
1008 curl_easy_pause (s->put.easyhandle, 1004 curl_easy_pause(s->put.easyhandle,
1009 CURLPAUSE_CONT); 1005 CURLPAUSE_CONT);
1010 client_schedule (s->plugin, GNUNET_YES); 1006 client_schedule(s->plugin, GNUNET_YES);
1011} 1007}
1012 1008
1013 1009
@@ -1022,10 +1018,10 @@ client_put_disconnect (void *cls)
1022 * @return bytes written to stream, returning 0 will terminate request! 1018 * @return bytes written to stream, returning 0 will terminate request!
1023 */ 1019 */
1024static size_t 1020static size_t
1025client_send_cb (void *stream, 1021client_send_cb(void *stream,
1026 size_t size, 1022 size_t size,
1027 size_t nmemb, 1023 size_t nmemb,
1028 void *cls) 1024 void *cls)
1029{ 1025{
1030 struct GNUNET_ATS_Session *s = cls; 1026 struct GNUNET_ATS_Session *s = cls;
1031 struct HTTP_Client_Plugin *plugin = s->plugin; 1027 struct HTTP_Client_Plugin *plugin = s->plugin;
@@ -1034,90 +1030,90 @@ client_send_cb (void *stream,
1034 char *stat_txt; 1030 char *stat_txt;
1035 1031
1036 if (H_TMP_DISCONNECTING == s->put.state) 1032 if (H_TMP_DISCONNECTING == s->put.state)
1037 {
1038 LOG (GNUNET_ERROR_TYPE_DEBUG,
1039 "Session %p/request %p: disconnect due to inactivity\n",
1040 s, s->put.easyhandle);
1041 return 0;
1042 }
1043
1044 if (NULL == msg)
1045 {
1046 if (GNUNET_YES == plugin->emulate_xhr)
1047 { 1033 {
1048 LOG (GNUNET_ERROR_TYPE_DEBUG, 1034 LOG(GNUNET_ERROR_TYPE_DEBUG,
1049 "Session %p/request %p: PUT request finished\n", 1035 "Session %p/request %p: disconnect due to inactivity\n",
1050 s, 1036 s, s->put.easyhandle);
1051 s->put.easyhandle);
1052 s->put.state = H_TMP_DISCONNECTING;
1053 return 0; 1037 return 0;
1054 } 1038 }
1055 1039
1056 /* We have nothing to send, so pause PUT request */ 1040 if (NULL == msg)
1057 LOG (GNUNET_ERROR_TYPE_DEBUG, 1041 {
1058 "Session %p/request %p: nothing to send, suspending\n", 1042 if (GNUNET_YES == plugin->emulate_xhr)
1059 s, 1043 {
1060 s->put.easyhandle); 1044 LOG(GNUNET_ERROR_TYPE_DEBUG,
1061 s->put_disconnect_task 1045 "Session %p/request %p: PUT request finished\n",
1062 = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, 1046 s,
1063 &client_put_disconnect, 1047 s->put.easyhandle);
1064 s); 1048 s->put.state = H_TMP_DISCONNECTING;
1065 s->put.state = H_PAUSED; 1049 return 0;
1066 return CURL_READFUNC_PAUSE; 1050 }
1067 } 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 }
1068 /* data to send */ 1064 /* data to send */
1069 GNUNET_assert (msg->pos < msg->size); 1065 GNUNET_assert(msg->pos < msg->size);
1070 /* calculate how much fits in buffer */ 1066 /* calculate how much fits in buffer */
1071 len = GNUNET_MIN (msg->size - msg->pos, 1067 len = GNUNET_MIN(msg->size - msg->pos,
1072 size * nmemb); 1068 size * nmemb);
1073 GNUNET_memcpy (stream, 1069 GNUNET_memcpy(stream,
1074 &msg->buf[msg->pos], 1070 &msg->buf[msg->pos],
1075 len); 1071 len);
1076 msg->pos += len; 1072 msg->pos += len;
1077 if (msg->pos == msg->size) 1073 if (msg->pos == msg->size)
1078 { 1074 {
1079 LOG (GNUNET_ERROR_TYPE_DEBUG, 1075 LOG(GNUNET_ERROR_TYPE_DEBUG,
1080 "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n", 1076 "Session %p/request %p: sent message with %u bytes sent, removing message from queue\n",
1081 s, 1077 s,
1082 s->put.easyhandle, 1078 s->put.easyhandle,
1083 msg->size, 1079 msg->size,
1084 msg->pos); 1080 msg->pos);
1085 /* Calling transmit continuation */ 1081 /* Calling transmit continuation */
1086 GNUNET_CONTAINER_DLL_remove (s->msg_head, 1082 GNUNET_CONTAINER_DLL_remove(s->msg_head,
1087 s->msg_tail, 1083 s->msg_tail,
1088 msg); 1084 msg);
1089 GNUNET_assert (0 < s->msgs_in_queue); 1085 GNUNET_assert(0 < s->msgs_in_queue);
1090 s->msgs_in_queue--; 1086 s->msgs_in_queue--;
1091 GNUNET_assert (msg->size <= s->bytes_in_queue); 1087 GNUNET_assert(msg->size <= s->bytes_in_queue);
1092 s->bytes_in_queue -= msg->size; 1088 s->bytes_in_queue -= msg->size;
1093 if (NULL != msg->transmit_cont) 1089 if (NULL != msg->transmit_cont)
1094 msg->transmit_cont (msg->transmit_cont_cls, 1090 msg->transmit_cont(msg->transmit_cont_cls,
1095 &s->address->peer, 1091 &s->address->peer,
1096 GNUNET_OK, 1092 GNUNET_OK,
1097 msg->size, 1093 msg->size,
1098 msg->size + s->overhead); 1094 msg->size + s->overhead);
1099 s->overhead = 0; 1095 s->overhead = 0;
1100 GNUNET_free (msg); 1096 GNUNET_free(msg);
1101 } 1097 }
1102 notify_session_monitor (plugin, 1098 notify_session_monitor(plugin,
1103 s, 1099 s,
1104 GNUNET_TRANSPORT_SS_UPDATE); 1100 GNUNET_TRANSPORT_SS_UPDATE);
1105 GNUNET_asprintf (&stat_txt, 1101 GNUNET_asprintf(&stat_txt,
1106 "# bytes currently in %s_client buffers", 1102 "# bytes currently in %s_client buffers",
1107 plugin->protocol); 1103 plugin->protocol);
1108 GNUNET_STATISTICS_update (plugin->env->stats, 1104 GNUNET_STATISTICS_update(plugin->env->stats,
1109 stat_txt, 1105 stat_txt,
1110 - len, 1106 -len,
1111 GNUNET_NO); 1107 GNUNET_NO);
1112 GNUNET_free (stat_txt); 1108 GNUNET_free(stat_txt);
1113 GNUNET_asprintf (&stat_txt, 1109 GNUNET_asprintf(&stat_txt,
1114 "# bytes transmitted via %s_client", 1110 "# bytes transmitted via %s_client",
1115 plugin->protocol); 1111 plugin->protocol);
1116 GNUNET_STATISTICS_update (plugin->env->stats, 1112 GNUNET_STATISTICS_update(plugin->env->stats,
1117 stat_txt, 1113 stat_txt,
1118 len, 1114 len,
1119 GNUNET_NO); 1115 GNUNET_NO);
1120 GNUNET_free (stat_txt); 1116 GNUNET_free(stat_txt);
1121 return len; 1117 return len;
1122} 1118}
1123 1119
@@ -1128,26 +1124,26 @@ client_send_cb (void *stream,
1128 * @param cls the session 1124 * @param cls the session
1129 */ 1125 */
1130static void 1126static void
1131client_wake_up (void *cls) 1127client_wake_up(void *cls)
1132{ 1128{
1133 struct GNUNET_ATS_Session *s = cls; 1129 struct GNUNET_ATS_Session *s = cls;
1134 1130
1135 s->recv_wakeup_task = NULL; 1131 s->recv_wakeup_task = NULL;
1136 LOG (GNUNET_ERROR_TYPE_DEBUG, 1132 LOG(GNUNET_ERROR_TYPE_DEBUG,
1137 "Session %p/request %p: Waking up GET handle\n", 1133 "Session %p/request %p: Waking up GET handle\n",
1138 s, s->get.easyhandle); 1134 s, s->get.easyhandle);
1139 if (H_PAUSED == s->put.state) 1135 if (H_PAUSED == s->put.state)
1140 { 1136 {
1141 /* PUT request was paused, unpause */ 1137 /* PUT request was paused, unpause */
1142 GNUNET_assert (s->put_disconnect_task != NULL); 1138 GNUNET_assert(s->put_disconnect_task != NULL);
1143 GNUNET_SCHEDULER_cancel (s->put_disconnect_task); 1139 GNUNET_SCHEDULER_cancel(s->put_disconnect_task);
1144 s->put_disconnect_task = NULL; 1140 s->put_disconnect_task = NULL;
1145 s->put.state = H_CONNECTED; 1141 s->put.state = H_CONNECTED;
1146 if (NULL != s->put.easyhandle) 1142 if (NULL != s->put.easyhandle)
1147 curl_easy_pause (s->put.easyhandle, CURLPAUSE_CONT); 1143 curl_easy_pause(s->put.easyhandle, CURLPAUSE_CONT);
1148 } 1144 }
1149 if (NULL != s->get.easyhandle) 1145 if (NULL != s->get.easyhandle)
1150 curl_easy_pause (s->get.easyhandle, CURLPAUSE_CONT); 1146 curl_easy_pause(s->get.easyhandle, CURLPAUSE_CONT);
1151} 1147}
1152 1148
1153 1149
@@ -1159,8 +1155,8 @@ client_wake_up (void *cls)
1159 * @return always #GNUNET_OK 1155 * @return always #GNUNET_OK
1160 */ 1156 */
1161static int 1157static int
1162client_receive_mst_cb (void *cls, 1158client_receive_mst_cb(void *cls,
1163 const struct GNUNET_MessageHeader *message) 1159 const struct GNUNET_MessageHeader *message)
1164{ 1160{
1165 struct GNUNET_ATS_Session *s = cls; 1161 struct GNUNET_ATS_Session *s = cls;
1166 struct HTTP_Client_Plugin *plugin; 1162 struct HTTP_Client_Plugin *plugin;
@@ -1168,32 +1164,32 @@ client_receive_mst_cb (void *cls,
1168 char *stat_txt; 1164 char *stat_txt;
1169 1165
1170 plugin = s->plugin; 1166 plugin = s->plugin;
1171 delay = s->plugin->env->receive (plugin->env->cls, 1167 delay = s->plugin->env->receive(plugin->env->cls,
1172 s->address, 1168 s->address,
1173 s, 1169 s,
1174 message); 1170 message);
1175 GNUNET_asprintf (&stat_txt, 1171 GNUNET_asprintf(&stat_txt,
1176 "# bytes received via %s_client", 1172 "# bytes received via %s_client",
1177 plugin->protocol); 1173 plugin->protocol);
1178 GNUNET_STATISTICS_update (plugin->env->stats, 1174 GNUNET_STATISTICS_update(plugin->env->stats,
1179 stat_txt, 1175 stat_txt,
1180 ntohs (message->size), 1176 ntohs(message->size),
1181 GNUNET_NO); 1177 GNUNET_NO);
1182 GNUNET_free (stat_txt); 1178 GNUNET_free(stat_txt);
1183 1179
1184 s->next_receive = GNUNET_TIME_relative_to_absolute (delay); 1180 s->next_receive = GNUNET_TIME_relative_to_absolute(delay);
1185 if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us) 1181 if (GNUNET_TIME_absolute_get().abs_value_us < s->next_receive.abs_value_us)
1186 { 1182 {
1187 LOG (GNUNET_ERROR_TYPE_DEBUG, 1183 LOG(GNUNET_ERROR_TYPE_DEBUG,
1188 "Client: peer `%s' address `%s' next read delayed for %s\n", 1184 "Client: peer `%s' address `%s' next read delayed for %s\n",
1189 GNUNET_i2s (&s->address->peer), 1185 GNUNET_i2s(&s->address->peer),
1190 http_common_plugin_address_to_string (s->plugin->protocol, 1186 http_common_plugin_address_to_string(s->plugin->protocol,
1191 s->address->address, 1187 s->address->address,
1192 s->address->address_length), 1188 s->address->address_length),
1193 GNUNET_STRINGS_relative_time_to_string (delay, 1189 GNUNET_STRINGS_relative_time_to_string(delay,
1194 GNUNET_YES)); 1190 GNUNET_YES));
1195 } 1191 }
1196 client_reschedule_session_timeout (s); 1192 client_reschedule_session_timeout(s);
1197 return GNUNET_OK; 1193 return GNUNET_OK;
1198} 1194}
1199 1195
@@ -1209,10 +1205,10 @@ client_receive_mst_cb (void *cls,
1209 * @return bytes read from stream 1205 * @return bytes read from stream
1210 */ 1206 */
1211static size_t 1207static size_t
1212client_receive_put (void *stream, 1208client_receive_put(void *stream,
1213 size_t size, 1209 size_t size,
1214 size_t nmemb, 1210 size_t nmemb,
1215 void *cls) 1211 void *cls)
1216{ 1212{
1217 return size * nmemb; 1213 return size * nmemb;
1218} 1214}
@@ -1229,53 +1225,53 @@ client_receive_put (void *stream,
1229 * @return bytes read from stream 1225 * @return bytes read from stream
1230 */ 1226 */
1231static size_t 1227static size_t
1232client_receive (void *stream, 1228client_receive(void *stream,
1233 size_t size, 1229 size_t size,
1234 size_t nmemb, 1230 size_t nmemb,
1235 void *cls) 1231 void *cls)
1236{ 1232{
1237 struct GNUNET_ATS_Session *s = cls; 1233 struct GNUNET_ATS_Session *s = cls;
1238 struct GNUNET_TIME_Absolute now; 1234 struct GNUNET_TIME_Absolute now;
1239 size_t len = size * nmemb; 1235 size_t len = size * nmemb;
1240 1236
1241 LOG (GNUNET_ERROR_TYPE_DEBUG, 1237 LOG(GNUNET_ERROR_TYPE_DEBUG,
1242 "Session %p / request %p: Received %u bytes from peer `%s'\n", 1238 "Session %p / request %p: Received %u bytes from peer `%s'\n",
1243 s, 1239 s,
1244 s->get.easyhandle, 1240 s->get.easyhandle,
1245 len, 1241 len,
1246 GNUNET_i2s (&s->address->peer)); 1242 GNUNET_i2s(&s->address->peer));
1247 now = GNUNET_TIME_absolute_get (); 1243 now = GNUNET_TIME_absolute_get();
1248 if (now.abs_value_us < s->next_receive.abs_value_us) 1244 if (now.abs_value_us < s->next_receive.abs_value_us)
1249 {
1250 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1251 struct GNUNET_TIME_Relative delta
1252 = GNUNET_TIME_absolute_get_difference (now, s->next_receive);
1253
1254 LOG (GNUNET_ERROR_TYPE_DEBUG,
1255 "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1256 s,
1257 s->get.easyhandle,
1258 GNUNET_STRINGS_relative_time_to_string (delta,
1259 GNUNET_YES));
1260 if (s->recv_wakeup_task != NULL)
1261 { 1245 {
1262 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); 1246 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
1263 s->recv_wakeup_task = NULL; 1247 struct GNUNET_TIME_Relative delta
1248 = GNUNET_TIME_absolute_get_difference(now, s->next_receive);
1249
1250 LOG(GNUNET_ERROR_TYPE_DEBUG,
1251 "Session %p / request %p: No inbound bandwidth available! Next read was delayed for %s\n",
1252 s,
1253 s->get.easyhandle,
1254 GNUNET_STRINGS_relative_time_to_string(delta,
1255 GNUNET_YES));
1256 if (s->recv_wakeup_task != NULL)
1257 {
1258 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task);
1259 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;
1264 } 1266 }
1265 s->recv_wakeup_task
1266 = GNUNET_SCHEDULER_add_delayed (delta,
1267 &client_wake_up,
1268 s);
1269 return CURL_WRITEFUNC_PAUSE;
1270 }
1271 if (NULL == s->msg_tk) 1267 if (NULL == s->msg_tk)
1272 s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb, 1268 s->msg_tk = GNUNET_MST_create(&client_receive_mst_cb,
1273 s); 1269 s);
1274 GNUNET_MST_from_buffer (s->msg_tk, 1270 GNUNET_MST_from_buffer(s->msg_tk,
1275 stream, 1271 stream,
1276 len, 1272 len,
1277 GNUNET_NO, 1273 GNUNET_NO,
1278 GNUNET_NO); 1274 GNUNET_NO);
1279 return len; 1275 return len;
1280} 1276}
1281 1277
@@ -1286,7 +1282,7 @@ client_receive (void *stream,
1286 * @param cls plugin as closure 1282 * @param cls plugin as closure
1287 */ 1283 */
1288static void 1284static void
1289client_run (void *cls) 1285client_run(void *cls)
1290{ 1286{
1291 struct HTTP_Client_Plugin *plugin = cls; 1287 struct HTTP_Client_Plugin *plugin = cls;
1292 int running; 1288 int running;
@@ -1299,136 +1295,141 @@ client_run (void *cls)
1299 plugin->client_perform_task = NULL; 1295 plugin->client_perform_task = NULL;
1300 /* While data are available or timeouts occured */ 1296 /* While data are available or timeouts occured */
1301 do 1297 do
1302 {
1303 running = 0;
1304 /* Perform operations for all handles */
1305 mret = curl_multi_perform (plugin->curl_multi_handle, &running);
1306
1307 /* Get additional information for all handles */
1308 while (NULL != (msg = curl_multi_info_read (plugin->curl_multi_handle, &msgs_left)))
1309 { 1298 {
1310 CURL *easy_h = msg->easy_handle; 1299 running = 0;
1311 struct GNUNET_ATS_Session *s = NULL; 1300 /* Perform operations for all handles */
1312 char *d = NULL; /* curl requires 'd' to be a 'char *' */ 1301 mret = curl_multi_perform(plugin->curl_multi_handle, &running);
1313
1314 GNUNET_assert (NULL != easy_h);
1315
1316 /* Obtain session from easy handle */
1317 GNUNET_assert (CURLE_OK == curl_easy_getinfo (easy_h, CURLINFO_PRIVATE, &d));
1318 s = (struct GNUNET_ATS_Session *) d;
1319 GNUNET_assert (NULL != s);
1320
1321 if (msg->msg != CURLMSG_DONE)
1322 continue; /* This should not happen */
1323
1324 /* Get HTTP response code */
1325 GNUNET_break (CURLE_OK == curl_easy_getinfo (easy_h,
1326 CURLINFO_RESPONSE_CODE, &http_statuscode));
1327
1328 if (easy_h == s->put.easyhandle)
1329 put_request = GNUNET_YES;
1330 else
1331 put_request = GNUNET_NO;
1332
1333 /* Log status of terminated request */
1334 if ((0 != msg->data.result) || (http_statuscode != 200))
1335 LOG (GNUNET_ERROR_TYPE_DEBUG,
1336 "Session %p/request %p: %s request to `%s' ended with status %i reason %i: `%s'\n",
1337 s, msg->easy_handle,
1338 (GNUNET_YES == put_request) ? "PUT" : "GET",
1339 GNUNET_i2s (&s->address->peer),
1340 http_statuscode,
1341 msg->data.result,
1342 curl_easy_strerror (msg->data.result));
1343 else
1344 LOG (GNUNET_ERROR_TYPE_DEBUG,
1345 "Session %p/request %p: %s request to `%s' ended normal\n",
1346 s, msg->easy_handle,
1347 (GNUNET_YES == put_request) ? "PUT" : "GET",
1348 GNUNET_i2s (&s->address->peer));
1349
1350 /* Remove easy handle from multi handle */
1351 curl_multi_remove_handle (plugin->curl_multi_handle, easy_h);
1352
1353 /* Clean up easy handle */
1354 curl_easy_cleanup (easy_h);
1355
1356 /* Remove information */
1357 GNUNET_assert (plugin->cur_requests > 0);
1358 plugin->cur_requests--;
1359 LOG (GNUNET_ERROR_TYPE_INFO,
1360 "%s request to %s done, number of requests decreased to %u\n",
1361 (GNUNET_YES == put_request) ? "PUT" : "GET",
1362 s->url,
1363 plugin->cur_requests);
1364 1302
1365 if (GNUNET_YES == put_request) 1303 /* Get additional information for all handles */
1366 { 1304 while (NULL != (msg = curl_multi_info_read(plugin->curl_multi_handle, &msgs_left)))
1367 /* Clean up a PUT request */ 1305 {
1368 s->put.easyhandle = NULL; 1306 CURL *easy_h = msg->easy_handle;
1369 s->put.s = NULL; 1307 struct GNUNET_ATS_Session *s = NULL;
1370 1308 char *d = NULL; /* curl requires 'd' to be a 'char *' */
1371 switch (s->put.state) { 1309
1372 case H_NOT_CONNECTED: 1310 GNUNET_assert(NULL != easy_h);
1373 case H_DISCONNECTED: 1311
1374 case H_TMP_DISCONNECTED: 1312 /* Obtain session from easy handle */
1375 /* This must not happen */ 1313 GNUNET_assert(CURLE_OK == curl_easy_getinfo(easy_h, CURLINFO_PRIVATE, &d));
1376 GNUNET_break (0); 1314 s = (struct GNUNET_ATS_Session *)d;
1377 break; 1315 GNUNET_assert(NULL != s);
1378 case H_TMP_RECONNECT_REQUIRED: 1316
1379 /* Transport called send while disconnect in progess, reconnect */ 1317 if (msg->msg != CURLMSG_DONE)
1380 if (GNUNET_SYSERR == client_connect_put (s)) 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)
1381 { 1362 {
1382 /* Reconnect failed, disconnect session */ 1363 /* Clean up a PUT request */
1383 http_client_plugin_session_disconnect (plugin, s); 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 }
1384 } 1401 }
1385 break; 1402 else if (GNUNET_NO == put_request)
1386 case H_TMP_DISCONNECTING: 1403 {
1387 /* PUT gets temporarily disconnected */ 1404 /* Clean up a GET request */
1388 s->put.state = H_TMP_DISCONNECTED; 1405 s->get.easyhandle = NULL;
1389 break; 1406 s->get.s = NULL;
1390 case H_PAUSED: 1407
1391 case H_CONNECTED: 1408 /* If we are emulating an XHR client we need to make another GET
1392 /* PUT gets permanently disconnected */ 1409 * request.
1393 s->put.state = H_DISCONNECTED; 1410 */
1394 http_client_plugin_session_disconnect (plugin, s); 1411 if (GNUNET_YES == plugin->emulate_xhr)
1395 break; 1412 {
1396 default: 1413 if (GNUNET_SYSERR == client_connect_get(s))
1397 GNUNET_break (0); 1414 http_client_plugin_session_disconnect(plugin, s);
1398 break; 1415 }
1399 } 1416 else
1400 } 1417 {
1401 else if (GNUNET_NO == put_request) 1418 /* GET request was terminated, so disconnect session */
1402 { 1419 http_client_plugin_session_disconnect(plugin, s);
1403 /* Clean up a GET request */ 1420 }
1404 s->get.easyhandle = NULL; 1421 }
1405 s->get.s = NULL; 1422 else
1406 1423 GNUNET_break(0); /* Must not happen */
1407 /* If we are emulating an XHR client we need to make another GET
1408 * request.
1409 */
1410 if (GNUNET_YES == plugin->emulate_xhr)
1411 {
1412 if (GNUNET_SYSERR == client_connect_get (s))
1413 http_client_plugin_session_disconnect (plugin, s);
1414 }
1415 else
1416 {
1417 /* GET request was terminated, so disconnect session */
1418 http_client_plugin_session_disconnect (plugin, s);
1419 }
1420 }
1421 else
1422 GNUNET_break (0); /* Must not happen */
1423 1424
1424 GNUNET_STATISTICS_set (plugin->env->stats, 1425 GNUNET_STATISTICS_set(plugin->env->stats,
1425 HTTP_STAT_STR_CONNECTIONS, 1426 HTTP_STAT_STR_CONNECTIONS,
1426 plugin->cur_requests, 1427 plugin->cur_requests,
1427 GNUNET_NO); 1428 GNUNET_NO);
1429 }
1428 } 1430 }
1429 }
1430 while (mret == CURLM_CALL_MULTI_PERFORM); 1431 while (mret == CURLM_CALL_MULTI_PERFORM);
1431 client_schedule (plugin, GNUNET_NO); 1432 client_schedule(plugin, GNUNET_NO);
1432} 1433}
1433 1434
1434 1435
@@ -1442,48 +1443,51 @@ client_run (void *cls)
1442 * @return opened socket 1443 * @return opened socket
1443 */ 1444 */
1444static curl_socket_t 1445static curl_socket_t
1445open_tcp_stealth_socket_cb (void *clientp, 1446open_tcp_stealth_socket_cb(void *clientp,
1446 curlsocktype purpose, 1447 curlsocktype purpose,
1447 struct curl_sockaddr *address) 1448 struct curl_sockaddr *address)
1448{ 1449{
1449 struct GNUNET_ATS_Session *s = clientp; 1450 struct GNUNET_ATS_Session *s = clientp;
1450 int ret; 1451 int ret;
1451 1452
1452 switch (purpose) 1453 switch (purpose)
1453 { 1454 {
1454 case CURLSOCKTYPE_IPCXN: 1455 case CURLSOCKTYPE_IPCXN:
1455 ret = socket (address->family, 1456 ret = socket(address->family,
1456 address->socktype, 1457 address->socktype,
1457 address->protocol); 1458 address->protocol);
1458 if (-1 == ret) 1459 if (-1 == ret)
1459 return CURL_SOCKET_BAD; 1460 return CURL_SOCKET_BAD;
1460 if ( ( (SOCK_STREAM != address->socktype) || 1461 if (((SOCK_STREAM != address->socktype) ||
1461 ( (0 != address->protocol) && 1462 ((0 != address->protocol) &&
1462 (IPPROTO_TCP != address->protocol))) ) 1463 (IPPROTO_TCP != address->protocol))))
1463 return (curl_socket_t) ret; 1464 return (curl_socket_t)ret;
1464 if ( (0 != setsockopt (ret, 1465 if ((0 != setsockopt(ret,
1465 IPPROTO_TCP, 1466 IPPROTO_TCP,
1466 TCP_STEALTH, 1467 TCP_STEALTH,
1467 &s->address->peer, 1468 &s->address->peer,
1468 sizeof (struct GNUNET_PeerIdentity))) ) 1469 sizeof(struct GNUNET_PeerIdentity))))
1469 { 1470 {
1470 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1471 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1471 _("TCP_STEALTH not supported on this platform.\n")); 1472 _("TCP_STEALTH not supported on this platform.\n"));
1472 (void) close (ret); 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;
1481 break;
1482
1483 case CURLSOCKTYPE_LAST:
1484 GNUNET_break(0);
1485 return CURL_SOCKET_BAD;
1486
1487 default:
1488 GNUNET_break(0);
1473 return CURL_SOCKET_BAD; 1489 return CURL_SOCKET_BAD;
1474 } 1490 }
1475 return (curl_socket_t) ret;
1476 case CURLSOCKTYPE_ACCEPT:
1477 GNUNET_break (0);
1478 return CURL_SOCKET_BAD;
1479 break;
1480 case CURLSOCKTYPE_LAST:
1481 GNUNET_break (0);
1482 return CURL_SOCKET_BAD;
1483 default:
1484 GNUNET_break (0);
1485 return CURL_SOCKET_BAD;
1486 }
1487} 1491}
1488#endif 1492#endif
1489 1493
@@ -1495,175 +1499,175 @@ open_tcp_stealth_socket_cb (void *clientp,
1495 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 1499 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1496 */ 1500 */
1497static int 1501static int
1498client_connect_get (struct GNUNET_ATS_Session *s) 1502client_connect_get(struct GNUNET_ATS_Session *s)
1499{ 1503{
1500 CURLMcode mret; 1504 CURLMcode mret;
1501 struct HttpAddress *ha; 1505 struct HttpAddress *ha;
1502 uint32_t options; 1506 uint32_t options;
1503 1507
1504 ha = (struct HttpAddress *) s->address->address; 1508 ha = (struct HttpAddress *)s->address->address;
1505 options = ntohl (ha->options); 1509 options = ntohl(ha->options);
1506 /* create get request */ 1510 /* create get request */
1507 s->get.easyhandle = curl_easy_init (); 1511 s->get.easyhandle = curl_easy_init();
1508 s->get.s = s; 1512 s->get.s = s;
1509 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) 1513 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1510 { 1514 {
1511#ifdef TCP_STEALTH 1515#ifdef TCP_STEALTH
1512 curl_easy_setopt (s->get.easyhandle, 1516 curl_easy_setopt(s->get.easyhandle,
1513 CURLOPT_OPENSOCKETFUNCTION, 1517 CURLOPT_OPENSOCKETFUNCTION,
1514 &open_tcp_stealth_socket_cb); 1518 &open_tcp_stealth_socket_cb);
1515 curl_easy_setopt (s->get.easyhandle, 1519 curl_easy_setopt(s->get.easyhandle,
1516 CURLOPT_OPENSOCKETDATA, 1520 CURLOPT_OPENSOCKETDATA,
1517 s); 1521 s);
1518#else 1522#else
1519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1520 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); 1524 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1521 curl_easy_cleanup (s->get.easyhandle); 1525 curl_easy_cleanup(s->get.easyhandle);
1522 s->get.easyhandle = NULL; 1526 s->get.easyhandle = NULL;
1523 s->get.s = NULL; 1527 s->get.s = NULL;
1524 return GNUNET_SYSERR; 1528 return GNUNET_SYSERR;
1525#endif 1529#endif
1526 } 1530 }
1527 1531
1528#if VERBOSE_CURL 1532#if VERBOSE_CURL
1529 curl_easy_setopt (s->get.easyhandle, 1533 curl_easy_setopt(s->get.easyhandle,
1530 CURLOPT_VERBOSE, 1534 CURLOPT_VERBOSE,
1531 1L); 1535 1L);
1532 curl_easy_setopt (s->get.easyhandle, 1536 curl_easy_setopt(s->get.easyhandle,
1533 CURLOPT_DEBUGFUNCTION, 1537 CURLOPT_DEBUGFUNCTION,
1534 &client_log); 1538 &client_log);
1535 curl_easy_setopt (s->get.easyhandle, 1539 curl_easy_setopt(s->get.easyhandle,
1536 CURLOPT_DEBUGDATA, 1540 CURLOPT_DEBUGDATA,
1537 &s->get); 1541 &s->get);
1538#endif 1542#endif
1539#if BUILD_HTTPS 1543#if BUILD_HTTPS
1540 curl_easy_setopt (s->get.easyhandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 1544 curl_easy_setopt(s->get.easyhandle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
1541 { 1545 {
1542 if (HTTP_OPTIONS_VERIFY_CERTIFICATE == 1546 if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
1543 (options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 1547 (options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1544 { 1548 {
1545 curl_easy_setopt (s->get.easyhandle, 1549 curl_easy_setopt(s->get.easyhandle,
1546 CURLOPT_SSL_VERIFYPEER, 1L); 1550 CURLOPT_SSL_VERIFYPEER, 1L);
1547 curl_easy_setopt (s->get.easyhandle, 1551 curl_easy_setopt(s->get.easyhandle,
1548 CURLOPT_SSL_VERIFYHOST, 1552 CURLOPT_SSL_VERIFYHOST,
1549 2L); 1553 2L);
1550 } 1554 }
1551 else 1555 else
1552 { 1556 {
1553 curl_easy_setopt (s->get.easyhandle, 1557 curl_easy_setopt(s->get.easyhandle,
1554 CURLOPT_SSL_VERIFYPEER, 1558 CURLOPT_SSL_VERIFYPEER,
1555 0L); 1559 0L);
1556 curl_easy_setopt (s->get.easyhandle, 1560 curl_easy_setopt(s->get.easyhandle,
1557 CURLOPT_SSL_VERIFYHOST, 1561 CURLOPT_SSL_VERIFYHOST,
1558 0L); 1562 0L);
1559 } 1563 }
1560 } 1564 }
1561 curl_easy_setopt (s->get.easyhandle, 1565 curl_easy_setopt(s->get.easyhandle,
1562 CURLOPT_PROTOCOLS, 1566 CURLOPT_PROTOCOLS,
1563 CURLPROTO_HTTPS); 1567 CURLPROTO_HTTPS);
1564 curl_easy_setopt (s->get.easyhandle, 1568 curl_easy_setopt(s->get.easyhandle,
1565 CURLOPT_REDIR_PROTOCOLS, 1569 CURLOPT_REDIR_PROTOCOLS,
1566 CURLPROTO_HTTPS); 1570 CURLPROTO_HTTPS);
1567#else 1571#else
1568 curl_easy_setopt (s->get.easyhandle, 1572 curl_easy_setopt(s->get.easyhandle,
1569 CURLOPT_PROTOCOLS, 1573 CURLOPT_PROTOCOLS,
1570 CURLPROTO_HTTP); 1574 CURLPROTO_HTTP);
1571 curl_easy_setopt (s->get.easyhandle, 1575 curl_easy_setopt(s->get.easyhandle,
1572 CURLOPT_REDIR_PROTOCOLS, 1576 CURLOPT_REDIR_PROTOCOLS,
1573 CURLPROTO_HTTP); 1577 CURLPROTO_HTTP);
1574#endif 1578#endif
1575 1579
1576 if (NULL != s->plugin->proxy_hostname) 1580 if (NULL != s->plugin->proxy_hostname)
1577 { 1581 {
1578 curl_easy_setopt (s->get.easyhandle, 1582 curl_easy_setopt(s->get.easyhandle,
1579 CURLOPT_PROXY, 1583 CURLOPT_PROXY,
1580 s->plugin->proxy_hostname); 1584 s->plugin->proxy_hostname);
1581 curl_easy_setopt (s->get.easyhandle, 1585 curl_easy_setopt(s->get.easyhandle,
1582 CURLOPT_PROXYTYPE, 1586 CURLOPT_PROXYTYPE,
1583 s->plugin->proxytype); 1587 s->plugin->proxytype);
1584 if (NULL != s->plugin->proxy_username) 1588 if (NULL != s->plugin->proxy_username)
1585 curl_easy_setopt (s->get.easyhandle, 1589 curl_easy_setopt(s->get.easyhandle,
1586 CURLOPT_PROXYUSERNAME, 1590 CURLOPT_PROXYUSERNAME,
1587 s->plugin->proxy_username); 1591 s->plugin->proxy_username);
1588 if (NULL != s->plugin->proxy_password) 1592 if (NULL != s->plugin->proxy_password)
1589 curl_easy_setopt (s->get.easyhandle, 1593 curl_easy_setopt(s->get.easyhandle,
1590 CURLOPT_PROXYPASSWORD, 1594 CURLOPT_PROXYPASSWORD,
1591 s->plugin->proxy_password); 1595 s->plugin->proxy_password);
1592 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) 1596 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1593 curl_easy_setopt (s->get.easyhandle, 1597 curl_easy_setopt(s->get.easyhandle,
1594 CURLOPT_HTTPPROXYTUNNEL, 1598 CURLOPT_HTTPPROXYTUNNEL,
1595 s->plugin->proxy_use_httpproxytunnel); 1599 s->plugin->proxy_use_httpproxytunnel);
1596 } 1600 }
1597 1601
1598 if (GNUNET_YES == s->plugin->emulate_xhr) 1602 if (GNUNET_YES == s->plugin->emulate_xhr)
1599 { 1603 {
1600 char *url; 1604 char *url;
1601 1605
1602 GNUNET_asprintf (&url, 1606 GNUNET_asprintf(&url,
1603 "%s,1", 1607 "%s,1",
1604 s->url);
1605 curl_easy_setopt (s->get.easyhandle,
1606 CURLOPT_URL,
1607 url);
1608 GNUNET_free(url);
1609 }
1610 else
1611 {
1612 curl_easy_setopt (s->get.easyhandle,
1613 CURLOPT_URL,
1614 s->url); 1608 s->url);
1615 } 1609 curl_easy_setopt(s->get.easyhandle,
1616 curl_easy_setopt (s->get.easyhandle, 1610 CURLOPT_URL,
1617 CURLOPT_READFUNCTION, 1611 url);
1618 &client_send_cb); 1612 GNUNET_free(url);
1619 curl_easy_setopt (s->get.easyhandle, 1613 }
1620 CURLOPT_READDATA, 1614 else
1621 s); 1615 {
1622 curl_easy_setopt (s->get.easyhandle, 1616 curl_easy_setopt(s->get.easyhandle,
1623 CURLOPT_WRITEFUNCTION, 1617 CURLOPT_URL,
1624 &client_receive); 1618 s->url);
1625 curl_easy_setopt (s->get.easyhandle, 1619 }
1626 CURLOPT_WRITEDATA, 1620 curl_easy_setopt(s->get.easyhandle,
1627 s); 1621 CURLOPT_READFUNCTION,
1622 &client_send_cb);
1623 curl_easy_setopt(s->get.easyhandle,
1624 CURLOPT_READDATA,
1625 s);
1626 curl_easy_setopt(s->get.easyhandle,
1627 CURLOPT_WRITEFUNCTION,
1628 &client_receive);
1629 curl_easy_setopt(s->get.easyhandle,
1630 CURLOPT_WRITEDATA,
1631 s);
1628 /* No timeout by default, timeout done with session timeout */ 1632 /* No timeout by default, timeout done with session timeout */
1629 curl_easy_setopt (s->get.easyhandle, 1633 curl_easy_setopt(s->get.easyhandle,
1630 CURLOPT_TIMEOUT, 1634 CURLOPT_TIMEOUT,
1631 0L); 1635 0L);
1632 curl_easy_setopt (s->get.easyhandle, 1636 curl_easy_setopt(s->get.easyhandle,
1633 CURLOPT_PRIVATE, s); 1637 CURLOPT_PRIVATE, s);
1634 curl_easy_setopt (s->get.easyhandle, 1638 curl_easy_setopt(s->get.easyhandle,
1635 CURLOPT_CONNECTTIMEOUT_MS, 1639 CURLOPT_CONNECTTIMEOUT_MS,
1636 (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); 1640 (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
1637 curl_easy_setopt (s->get.easyhandle, CURLOPT_BUFFERSIZE, 1641 curl_easy_setopt(s->get.easyhandle, CURLOPT_BUFFERSIZE,
1638 2 * GNUNET_MAX_MESSAGE_SIZE); 1642 2 * GNUNET_MAX_MESSAGE_SIZE);
1639#if CURL_TCP_NODELAY 1643#if CURL_TCP_NODELAY
1640 curl_easy_setopt (ps->recv_endpoint, 1644 curl_easy_setopt(ps->recv_endpoint,
1641 CURLOPT_TCP_NODELAY, 1645 CURLOPT_TCP_NODELAY,
1642 1L); 1646 1L);
1643#endif 1647#endif
1644 curl_easy_setopt (s->get.easyhandle, 1648 curl_easy_setopt(s->get.easyhandle,
1645 CURLOPT_FOLLOWLOCATION, 1649 CURLOPT_FOLLOWLOCATION,
1646 0L); 1650 0L);
1647 1651
1648 mret = curl_multi_add_handle (s->plugin->curl_multi_handle, 1652 mret = curl_multi_add_handle(s->plugin->curl_multi_handle,
1649 s->get.easyhandle); 1653 s->get.easyhandle);
1650 if (CURLM_OK != mret) 1654 if (CURLM_OK != mret)
1651 { 1655 {
1652 LOG (GNUNET_ERROR_TYPE_ERROR, 1656 LOG(GNUNET_ERROR_TYPE_ERROR,
1653 "Session %p : Failed to add GET handle to multihandle: `%s'\n", 1657 "Session %p : Failed to add GET handle to multihandle: `%s'\n",
1654 s, 1658 s,
1655 curl_multi_strerror (mret)); 1659 curl_multi_strerror(mret));
1656 curl_easy_cleanup (s->get.easyhandle); 1660 curl_easy_cleanup(s->get.easyhandle);
1657 s->get.easyhandle = NULL; 1661 s->get.easyhandle = NULL;
1658 s->get.s = NULL; 1662 s->get.s = NULL;
1659 GNUNET_break (0); 1663 GNUNET_break(0);
1660 return GNUNET_SYSERR; 1664 return GNUNET_SYSERR;
1661 } 1665 }
1662 s->plugin->cur_requests++; 1666 s->plugin->cur_requests++;
1663 LOG (GNUNET_ERROR_TYPE_INFO, 1667 LOG(GNUNET_ERROR_TYPE_INFO,
1664 "GET request `%s' established, number of requests increased to %u\n", 1668 "GET request `%s' established, number of requests increased to %u\n",
1665 s->url, 1669 s->url,
1666 s->plugin->cur_requests); 1670 s->plugin->cur_requests);
1667 return GNUNET_OK; 1671 return GNUNET_OK;
1668} 1672}
1669 1673
@@ -1675,164 +1679,164 @@ client_connect_get (struct GNUNET_ATS_Session *s)
1675 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok 1679 * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok
1676 */ 1680 */
1677static int 1681static int
1678client_connect_put (struct GNUNET_ATS_Session *s) 1682client_connect_put(struct GNUNET_ATS_Session *s)
1679{ 1683{
1680 CURLMcode mret; 1684 CURLMcode mret;
1681 struct HttpAddress *ha; 1685 struct HttpAddress *ha;
1682 uint32_t options; 1686 uint32_t options;
1683 1687
1684 ha = (struct HttpAddress *) s->address->address; 1688 ha = (struct HttpAddress *)s->address->address;
1685 options = ntohl (ha->options); 1689 options = ntohl(ha->options);
1686 /* create put request */ 1690 /* create put request */
1687 LOG (GNUNET_ERROR_TYPE_DEBUG, 1691 LOG(GNUNET_ERROR_TYPE_DEBUG,
1688 "Session %p: Init PUT handle\n", 1692 "Session %p: Init PUT handle\n",
1689 s); 1693 s);
1690 s->put.easyhandle = curl_easy_init (); 1694 s->put.easyhandle = curl_easy_init();
1691 s->put.s = s; 1695 s->put.s = s;
1692#if VERBOSE_CURL 1696#if VERBOSE_CURL
1693 curl_easy_setopt (s->put.easyhandle, 1697 curl_easy_setopt(s->put.easyhandle,
1694 CURLOPT_VERBOSE, 1698 CURLOPT_VERBOSE,
1695 1L); 1699 1L);
1696 curl_easy_setopt (s->put.easyhandle, 1700 curl_easy_setopt(s->put.easyhandle,
1697 CURLOPT_DEBUGFUNCTION, 1701 CURLOPT_DEBUGFUNCTION,
1698 &client_log); 1702 &client_log);
1699 curl_easy_setopt (s->put.easyhandle, 1703 curl_easy_setopt(s->put.easyhandle,
1700 CURLOPT_DEBUGDATA, 1704 CURLOPT_DEBUGDATA,
1701 &s->put); 1705 &s->put);
1702#endif 1706#endif
1703 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH)) 1707 if (0 != (options & HTTP_OPTIONS_TCP_STEALTH))
1704 { 1708 {
1705#ifdef TCP_STEALTH 1709#ifdef TCP_STEALTH
1706 curl_easy_setopt (s->put.easyhandle, 1710 curl_easy_setopt(s->put.easyhandle,
1707 CURLOPT_OPENSOCKETFUNCTION, 1711 CURLOPT_OPENSOCKETFUNCTION,
1708 &open_tcp_stealth_socket_cb); 1712 &open_tcp_stealth_socket_cb);
1709 curl_easy_setopt (s->put.easyhandle, 1713 curl_easy_setopt(s->put.easyhandle,
1710 CURLOPT_OPENSOCKETDATA, 1714 CURLOPT_OPENSOCKETDATA,
1711 s); 1715 s);
1712#else 1716#else
1713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1717 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1714 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n"); 1718 "Cannot connect, TCP STEALTH needed and not supported by kernel.\n");
1715 curl_easy_cleanup (s->put.easyhandle); 1719 curl_easy_cleanup(s->put.easyhandle);
1716 s->put.easyhandle = NULL; 1720 s->put.easyhandle = NULL;
1717 s->put.s = NULL; 1721 s->put.s = NULL;
1718 s->put.state = H_DISCONNECTED; 1722 s->put.state = H_DISCONNECTED;
1719 return GNUNET_SYSERR; 1723 return GNUNET_SYSERR;
1720#endif 1724#endif
1721 } 1725 }
1722#if BUILD_HTTPS 1726#if BUILD_HTTPS
1723 curl_easy_setopt (s->put.easyhandle, 1727 curl_easy_setopt(s->put.easyhandle,
1724 CURLOPT_SSLVERSION, 1728 CURLOPT_SSLVERSION,
1725 CURL_SSLVERSION_TLSv1); 1729 CURL_SSLVERSION_TLSv1);
1726 { 1730 {
1727 struct HttpAddress *ha; 1731 struct HttpAddress *ha;
1728 ha = (struct HttpAddress *) s->address->address; 1732 ha = (struct HttpAddress *)s->address->address;
1729 1733
1730 if (HTTP_OPTIONS_VERIFY_CERTIFICATE == 1734 if (HTTP_OPTIONS_VERIFY_CERTIFICATE ==
1731 (ntohl (ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 1735 (ntohl(ha->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE))
1732 { 1736 {
1733 curl_easy_setopt (s->put.easyhandle, 1737 curl_easy_setopt(s->put.easyhandle,
1734 CURLOPT_SSL_VERIFYPEER, 1738 CURLOPT_SSL_VERIFYPEER,
1735 1L); 1739 1L);
1736 curl_easy_setopt (s->put.easyhandle, 1740 curl_easy_setopt(s->put.easyhandle,
1737 CURLOPT_SSL_VERIFYHOST, 1741 CURLOPT_SSL_VERIFYHOST,
1738 2L); 1742 2L);
1739 } 1743 }
1740 else 1744 else
1741 { 1745 {
1742 curl_easy_setopt (s->put.easyhandle, 1746 curl_easy_setopt(s->put.easyhandle,
1743 CURLOPT_SSL_VERIFYPEER, 1747 CURLOPT_SSL_VERIFYPEER,
1744 0L); 1748 0L);
1745 curl_easy_setopt (s->put.easyhandle, 1749 curl_easy_setopt(s->put.easyhandle,
1746 CURLOPT_SSL_VERIFYHOST, 1750 CURLOPT_SSL_VERIFYHOST,
1747 0L); 1751 0L);
1748 } 1752 }
1749 } 1753 }
1750 curl_easy_setopt (s->put.easyhandle, 1754 curl_easy_setopt(s->put.easyhandle,
1751 CURLOPT_PROTOCOLS, 1755 CURLOPT_PROTOCOLS,
1752 CURLPROTO_HTTPS); 1756 CURLPROTO_HTTPS);
1753 curl_easy_setopt (s->put.easyhandle, 1757 curl_easy_setopt(s->put.easyhandle,
1754 CURLOPT_REDIR_PROTOCOLS, 1758 CURLOPT_REDIR_PROTOCOLS,
1755 CURLPROTO_HTTPS); 1759 CURLPROTO_HTTPS);
1756#else 1760#else
1757 curl_easy_setopt (s->put.easyhandle, 1761 curl_easy_setopt(s->put.easyhandle,
1758 CURLOPT_PROTOCOLS, 1762 CURLOPT_PROTOCOLS,
1759 CURLPROTO_HTTP); 1763 CURLPROTO_HTTP);
1760 curl_easy_setopt (s->put.easyhandle, 1764 curl_easy_setopt(s->put.easyhandle,
1761 CURLOPT_REDIR_PROTOCOLS, 1765 CURLOPT_REDIR_PROTOCOLS,
1762 CURLPROTO_HTTP); 1766 CURLPROTO_HTTP);
1763#endif 1767#endif
1764 if (NULL != s->plugin->proxy_hostname) 1768 if (NULL != s->plugin->proxy_hostname)
1765 { 1769 {
1766 curl_easy_setopt (s->put.easyhandle, 1770 curl_easy_setopt(s->put.easyhandle,
1767 CURLOPT_PROXY, 1771 CURLOPT_PROXY,
1768 s->plugin->proxy_hostname); 1772 s->plugin->proxy_hostname);
1769 curl_easy_setopt (s->put.easyhandle, 1773 curl_easy_setopt(s->put.easyhandle,
1770 CURLOPT_PROXYTYPE, 1774 CURLOPT_PROXYTYPE,
1771 s->plugin->proxytype); 1775 s->plugin->proxytype);
1772 if (NULL != s->plugin->proxy_username) 1776 if (NULL != s->plugin->proxy_username)
1773 curl_easy_setopt (s->put.easyhandle, 1777 curl_easy_setopt(s->put.easyhandle,
1774 CURLOPT_PROXYUSERNAME, 1778 CURLOPT_PROXYUSERNAME,
1775 s->plugin->proxy_username); 1779 s->plugin->proxy_username);
1776 if (NULL != s->plugin->proxy_password) 1780 if (NULL != s->plugin->proxy_password)
1777 curl_easy_setopt (s->put.easyhandle, 1781 curl_easy_setopt(s->put.easyhandle,
1778 CURLOPT_PROXYPASSWORD, 1782 CURLOPT_PROXYPASSWORD,
1779 s->plugin->proxy_password); 1783 s->plugin->proxy_password);
1780 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel) 1784 if (GNUNET_YES == s->plugin->proxy_use_httpproxytunnel)
1781 curl_easy_setopt (s->put.easyhandle, 1785 curl_easy_setopt(s->put.easyhandle,
1782 CURLOPT_HTTPPROXYTUNNEL, 1786 CURLOPT_HTTPPROXYTUNNEL,
1783 s->plugin->proxy_use_httpproxytunnel); 1787 s->plugin->proxy_use_httpproxytunnel);
1784 } 1788 }
1785 1789
1786 curl_easy_setopt (s->put.easyhandle, 1790 curl_easy_setopt(s->put.easyhandle,
1787 CURLOPT_URL, 1791 CURLOPT_URL,
1788 s->url); 1792 s->url);
1789 curl_easy_setopt (s->put.easyhandle, 1793 curl_easy_setopt(s->put.easyhandle,
1790 CURLOPT_UPLOAD, 1794 CURLOPT_UPLOAD,
1791 1L); 1795 1L);
1792 curl_easy_setopt (s->put.easyhandle, 1796 curl_easy_setopt(s->put.easyhandle,
1793 CURLOPT_READFUNCTION, 1797 CURLOPT_READFUNCTION,
1794 &client_send_cb); 1798 &client_send_cb);
1795 curl_easy_setopt (s->put.easyhandle, 1799 curl_easy_setopt(s->put.easyhandle,
1796 CURLOPT_READDATA, 1800 CURLOPT_READDATA,
1797 s); 1801 s);
1798 curl_easy_setopt (s->put.easyhandle, 1802 curl_easy_setopt(s->put.easyhandle,
1799 CURLOPT_WRITEFUNCTION, 1803 CURLOPT_WRITEFUNCTION,
1800 &client_receive_put); 1804 &client_receive_put);
1801 curl_easy_setopt (s->put.easyhandle, 1805 curl_easy_setopt(s->put.easyhandle,
1802 CURLOPT_WRITEDATA, 1806 CURLOPT_WRITEDATA,
1803 s); 1807 s);
1804 /* No timeout by default, timeout done with session timeout */ 1808 /* No timeout by default, timeout done with session timeout */
1805 curl_easy_setopt (s->put.easyhandle, 1809 curl_easy_setopt(s->put.easyhandle,
1806 CURLOPT_TIMEOUT, 1810 CURLOPT_TIMEOUT,
1807 0L); 1811 0L);
1808 curl_easy_setopt (s->put.easyhandle, 1812 curl_easy_setopt(s->put.easyhandle,
1809 CURLOPT_PRIVATE, 1813 CURLOPT_PRIVATE,
1810 s); 1814 s);
1811 curl_easy_setopt (s->put.easyhandle, 1815 curl_easy_setopt(s->put.easyhandle,
1812 CURLOPT_CONNECTTIMEOUT_MS, 1816 CURLOPT_CONNECTTIMEOUT_MS,
1813 (long) (HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL)); 1817 (long)(HTTP_CLIENT_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL));
1814 curl_easy_setopt (s->put.easyhandle, CURLOPT_BUFFERSIZE, 1818 curl_easy_setopt(s->put.easyhandle, CURLOPT_BUFFERSIZE,
1815 2 * GNUNET_MAX_MESSAGE_SIZE); 1819 2 * GNUNET_MAX_MESSAGE_SIZE);
1816#if CURL_TCP_NODELAY 1820#if CURL_TCP_NODELAY
1817 curl_easy_setopt (s->put.easyhandle, CURLOPT_TCP_NODELAY, 1); 1821 curl_easy_setopt(s->put.easyhandle, CURLOPT_TCP_NODELAY, 1);
1818#endif 1822#endif
1819 mret = curl_multi_add_handle (s->plugin->curl_multi_handle, 1823 mret = curl_multi_add_handle(s->plugin->curl_multi_handle,
1820 s->put.easyhandle); 1824 s->put.easyhandle);
1821 if (CURLM_OK != mret) 1825 if (CURLM_OK != mret)
1822 { 1826 {
1823 LOG (GNUNET_ERROR_TYPE_ERROR, 1827 LOG(GNUNET_ERROR_TYPE_ERROR,
1824 "Session %p : Failed to add PUT handle to multihandle: `%s'\n", 1828 "Session %p : Failed to add PUT handle to multihandle: `%s'\n",
1825 s, curl_multi_strerror (mret)); 1829 s, curl_multi_strerror(mret));
1826 curl_easy_cleanup (s->put.easyhandle); 1830 curl_easy_cleanup(s->put.easyhandle);
1827 s->put.easyhandle = NULL; 1831 s->put.easyhandle = NULL;
1828 s->put.s = NULL; 1832 s->put.s = NULL;
1829 s->put.state = H_DISCONNECTED; 1833 s->put.state = H_DISCONNECTED;
1830 return GNUNET_SYSERR; 1834 return GNUNET_SYSERR;
1831 } 1835 }
1832 s->put.state = H_CONNECTED; 1836 s->put.state = H_CONNECTED;
1833 s->plugin->cur_requests++; 1837 s->plugin->cur_requests++;
1834 1838
1835 LOG (GNUNET_ERROR_TYPE_INFO, 1839 LOG(GNUNET_ERROR_TYPE_INFO,
1836 "PUT request `%s' established, number of requests increased to %u\n", 1840 "PUT request `%s' established, number of requests increased to %u\n",
1837 s->url, s->plugin->cur_requests); 1841 s->url, s->plugin->cur_requests);
1838 1842
@@ -1847,7 +1851,7 @@ client_connect_put (struct GNUNET_ATS_Session *s)
1847 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise 1851 * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
1848 */ 1852 */
1849static int 1853static int
1850client_connect (struct GNUNET_ATS_Session *s) 1854client_connect(struct GNUNET_ATS_Session *s)
1851{ 1855{
1852 struct HTTP_Client_Plugin *plugin = s->plugin; 1856 struct HTTP_Client_Plugin *plugin = s->plugin;
1853 int res = GNUNET_OK; 1857 int res = GNUNET_OK;
@@ -1857,57 +1861,57 @@ client_connect (struct GNUNET_ATS_Session *s)
1857 http_common_plugin_address_to_string(plugin->protocol, 1861 http_common_plugin_address_to_string(plugin->protocol,
1858 s->address->address, 1862 s->address->address,
1859 s->address->address_length)) 1863 s->address->address_length))
1860 { 1864 {
1861 LOG (GNUNET_ERROR_TYPE_DEBUG, 1865 LOG(GNUNET_ERROR_TYPE_DEBUG,
1862 "Invalid address peer `%s'\n", 1866 "Invalid address peer `%s'\n",
1863 GNUNET_i2s(&s->address->peer)); 1867 GNUNET_i2s(&s->address->peer));
1864 return GNUNET_SYSERR; 1868 return GNUNET_SYSERR;
1865 } 1869 }
1866 1870
1867 GNUNET_asprintf (&s->url, 1871 GNUNET_asprintf(&s->url,
1868 "%s/%s;%u", 1872 "%s/%s;%u",
1869 http_common_plugin_address_to_url (NULL, 1873 http_common_plugin_address_to_url(NULL,
1870 s->address->address, 1874 s->address->address,
1871 s->address->address_length), 1875 s->address->address_length),
1872 GNUNET_i2s_full (plugin->env->my_identity), 1876 GNUNET_i2s_full(plugin->env->my_identity),
1873 plugin->last_tag); 1877 plugin->last_tag);
1874 1878
1875 plugin->last_tag++; 1879 plugin->last_tag++;
1876 LOG (GNUNET_ERROR_TYPE_DEBUG, 1880 LOG(GNUNET_ERROR_TYPE_DEBUG,
1877 "Initiating outbound session peer `%s' using address `%s'\n", 1881 "Initiating outbound session peer `%s' using address `%s'\n",
1878 GNUNET_i2s (&s->address->peer), s->url); 1882 GNUNET_i2s(&s->address->peer), s->url);
1879 1883
1880 if (GNUNET_SYSERR == client_connect_get (s)) 1884 if (GNUNET_SYSERR == client_connect_get(s))
1881 return GNUNET_SYSERR; 1885 return GNUNET_SYSERR;
1882 /* If we are emulating an XHR client then delay sending a PUT request until 1886 /* If we are emulating an XHR client then delay sending a PUT request until
1883 * there is something to send. 1887 * there is something to send.
1884 */ 1888 */
1885 if (GNUNET_YES == plugin->emulate_xhr) 1889 if (GNUNET_YES == plugin->emulate_xhr)
1886 { 1890 {
1887 s->put.state = H_TMP_DISCONNECTED; 1891 s->put.state = H_TMP_DISCONNECTED;
1888 } 1892 }
1889 else if (GNUNET_SYSERR == client_connect_put (s)) 1893 else if (GNUNET_SYSERR == client_connect_put(s))
1890 return GNUNET_SYSERR; 1894 return GNUNET_SYSERR;
1891 1895
1892 LOG (GNUNET_ERROR_TYPE_DEBUG, 1896 LOG(GNUNET_ERROR_TYPE_DEBUG,
1893 "Session %p: connected with GET %p and PUT %p\n", 1897 "Session %p: connected with GET %p and PUT %p\n",
1894 s, s->get.easyhandle, 1898 s, s->get.easyhandle,
1895 s->put.easyhandle); 1899 s->put.easyhandle);
1896 /* Perform connect */ 1900 /* Perform connect */
1897 GNUNET_STATISTICS_set (plugin->env->stats, 1901 GNUNET_STATISTICS_set(plugin->env->stats,
1898 HTTP_STAT_STR_CONNECTIONS, 1902 HTTP_STAT_STR_CONNECTIONS,
1899 plugin->cur_requests, 1903 plugin->cur_requests,
1900 GNUNET_NO); 1904 GNUNET_NO);
1901 /* Re-schedule since handles have changed */ 1905 /* Re-schedule since handles have changed */
1902 if (NULL != plugin->client_perform_task) 1906 if (NULL != plugin->client_perform_task)
1903 { 1907 {
1904 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 1908 GNUNET_SCHEDULER_cancel(plugin->client_perform_task);
1905 plugin->client_perform_task = NULL; 1909 plugin->client_perform_task = NULL;
1906 } 1910 }
1907 1911
1908 /* Schedule task to run immediately */ 1912 /* Schedule task to run immediately */
1909 plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, 1913 plugin->client_perform_task = GNUNET_SCHEDULER_add_now(client_run,
1910 plugin); 1914 plugin);
1911 return res; 1915 return res;
1912} 1916}
1913 1917
@@ -1920,8 +1924,8 @@ client_connect (struct GNUNET_ATS_Session *s)
1920 * @return the network type 1924 * @return the network type
1921 */ 1925 */
1922static enum GNUNET_NetworkType 1926static enum GNUNET_NetworkType
1923http_client_plugin_get_network (void *cls, 1927http_client_plugin_get_network(void *cls,
1924 struct GNUNET_ATS_Session *session) 1928 struct GNUNET_ATS_Session *session)
1925{ 1929{
1926 return session->scope; 1930 return session->scope;
1927} 1931}
@@ -1935,13 +1939,13 @@ http_client_plugin_get_network (void *cls,
1935 * @return the network type 1939 * @return the network type
1936 */ 1940 */
1937static enum GNUNET_NetworkType 1941static enum GNUNET_NetworkType
1938http_client_plugin_get_network_for_address (void *cls, 1942http_client_plugin_get_network_for_address(void *cls,
1939 const struct GNUNET_HELLO_Address *address) 1943 const struct GNUNET_HELLO_Address *address)
1940{ 1944{
1941 struct HTTP_Client_Plugin *plugin = cls; 1945 struct HTTP_Client_Plugin *plugin = cls;
1942 1946
1943 return http_common_get_network_for_address (plugin->env, 1947 return http_common_get_network_for_address(plugin->env,
1944 address); 1948 address);
1945} 1949}
1946 1950
1947 1951
@@ -1951,33 +1955,33 @@ http_client_plugin_get_network_for_address (void *cls,
1951 * @param cls the `struct GNUNET_ATS_Session` of the idle session 1955 * @param cls the `struct GNUNET_ATS_Session` of the idle session
1952 */ 1956 */
1953static void 1957static void
1954client_session_timeout (void *cls) 1958client_session_timeout(void *cls)
1955{ 1959{
1956 struct GNUNET_ATS_Session *s = cls; 1960 struct GNUNET_ATS_Session *s = cls;
1957 struct GNUNET_TIME_Relative left; 1961 struct GNUNET_TIME_Relative left;
1958 1962
1959 s->timeout_task = NULL; 1963 s->timeout_task = NULL;
1960 left = GNUNET_TIME_absolute_get_remaining (s->timeout); 1964 left = GNUNET_TIME_absolute_get_remaining(s->timeout);
1961 if (0 != left.rel_value_us) 1965 if (0 != left.rel_value_us)
1962 { 1966 {
1963 /* not actually our turn yet, but let's at least update 1967 /* not actually our turn yet, but let's at least update
1964 the monitor, it may think we're about to die ... */ 1968 the monitor, it may think we're about to die ... */
1965 notify_session_monitor (s->plugin, 1969 notify_session_monitor(s->plugin,
1966 s, 1970 s,
1967 GNUNET_TRANSPORT_SS_UPDATE); 1971 GNUNET_TRANSPORT_SS_UPDATE);
1968 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, 1972 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left,
1969 &client_session_timeout, 1973 &client_session_timeout,
1970 s); 1974 s);
1971 return; 1975 return;
1972 } 1976 }
1973 LOG (TIMEOUT_LOG, 1977 LOG(TIMEOUT_LOG,
1974 "Session %p was idle for %s, disconnecting\n", 1978 "Session %p was idle for %s, disconnecting\n",
1975 s, 1979 s,
1976 GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, 1980 GNUNET_STRINGS_relative_time_to_string(HTTP_CLIENT_SESSION_TIMEOUT,
1977 GNUNET_YES)); 1981 GNUNET_YES));
1978 GNUNET_assert (GNUNET_OK == 1982 GNUNET_assert(GNUNET_OK ==
1979 http_client_plugin_session_disconnect (s->plugin, 1983 http_client_plugin_session_disconnect(s->plugin,
1980 s)); 1984 s));
1981} 1985}
1982 1986
1983 1987
@@ -1990,8 +1994,8 @@ client_session_timeout (void *cls)
1990 * @return the session or NULL of max connections exceeded 1994 * @return the session or NULL of max connections exceeded
1991 */ 1995 */
1992static struct GNUNET_ATS_Session * 1996static struct GNUNET_ATS_Session *
1993http_client_plugin_get_session (void *cls, 1997http_client_plugin_get_session(void *cls,
1994 const struct GNUNET_HELLO_Address *address) 1998 const struct GNUNET_HELLO_Address *address)
1995{ 1999{
1996 struct HTTP_Client_Plugin *plugin = cls; 2000 struct HTTP_Client_Plugin *plugin = cls;
1997 struct GNUNET_ATS_Session *s; 2001 struct GNUNET_ATS_Session *s;
@@ -2000,96 +2004,96 @@ http_client_plugin_get_session (void *cls,
2000 size_t salen = 0; 2004 size_t salen = 0;
2001 int res; 2005 int res;
2002 2006
2003 GNUNET_assert (NULL != address->address); 2007 GNUNET_assert(NULL != address->address);
2004 2008
2005 /* find existing session */ 2009 /* find existing session */
2006 s = client_lookup_session (plugin, address); 2010 s = client_lookup_session(plugin, address);
2007 if (NULL != s) 2011 if (NULL != s)
2008 return s; 2012 return s;
2009 2013
2010 /* create a new session */ 2014 /* create a new session */
2011 if (plugin->max_requests <= plugin->cur_requests) 2015 if (plugin->max_requests <= plugin->cur_requests)
2012 { 2016 {
2013 LOG (GNUNET_ERROR_TYPE_WARNING, 2017 LOG(GNUNET_ERROR_TYPE_WARNING,
2014 "Maximum number of requests (%u) reached: " 2018 "Maximum number of requests (%u) reached: "
2015 "cannot connect to peer `%s'\n", 2019 "cannot connect to peer `%s'\n",
2016 plugin->max_requests, 2020 plugin->max_requests,
2017 GNUNET_i2s (&address->peer)); 2021 GNUNET_i2s(&address->peer));
2018 return NULL; 2022 return NULL;
2019 } 2023 }
2020 2024
2021 /* Determine network location */ 2025 /* Determine network location */
2022 net_type = GNUNET_NT_UNSPECIFIED; 2026 net_type = GNUNET_NT_UNSPECIFIED;
2023 sa = http_common_socket_from_address (address->address, 2027 sa = http_common_socket_from_address(address->address,
2024 address->address_length, 2028 address->address_length,
2025 &res); 2029 &res);
2026 if (GNUNET_SYSERR == res) 2030 if (GNUNET_SYSERR == res)
2027 return NULL; 2031 return NULL;
2028 if (GNUNET_YES == res) 2032 if (GNUNET_YES == res)
2029 {
2030 GNUNET_assert (NULL != sa);
2031 if (AF_INET == sa->sa_family)
2032 { 2033 {
2033 salen = sizeof (struct sockaddr_in); 2034 GNUNET_assert(NULL != sa);
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);
2034 } 2045 }
2035 else if (AF_INET6 == sa->sa_family) 2046 else if (GNUNET_NO == res)
2036 { 2047 {
2037 salen = sizeof (struct sockaddr_in6); 2048 /* Cannot convert to sockaddr -> is external hostname */
2049 net_type = GNUNET_NT_WAN;
2038 } 2050 }
2039 net_type = plugin->env->get_address_type (plugin->env->cls, sa, salen);
2040 GNUNET_free (sa);
2041 }
2042 else if (GNUNET_NO == res)
2043 {
2044 /* Cannot convert to sockaddr -> is external hostname */
2045 net_type = GNUNET_NT_WAN;
2046 }
2047 if (GNUNET_NT_UNSPECIFIED == net_type) 2051 if (GNUNET_NT_UNSPECIFIED == net_type)
2048 { 2052 {
2049 GNUNET_break (0); 2053 GNUNET_break(0);
2050 return NULL; 2054 return NULL;
2051 } 2055 }
2052 2056
2053 s = GNUNET_new (struct GNUNET_ATS_Session); 2057 s = GNUNET_new(struct GNUNET_ATS_Session);
2054 s->plugin = plugin; 2058 s->plugin = plugin;
2055 s->address = GNUNET_HELLO_address_copy (address); 2059 s->address = GNUNET_HELLO_address_copy(address);
2056 s->scope = net_type; 2060 s->scope = net_type;
2057 2061
2058 s->put.state = H_NOT_CONNECTED; 2062 s->put.state = H_NOT_CONNECTED;
2059 s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_CLIENT_SESSION_TIMEOUT); 2063 s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_CLIENT_SESSION_TIMEOUT);
2060 s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, 2064 s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_CLIENT_SESSION_TIMEOUT,
2061 &client_session_timeout, 2065 &client_session_timeout,
2062 s); 2066 s);
2063 LOG (GNUNET_ERROR_TYPE_DEBUG, 2067 LOG(GNUNET_ERROR_TYPE_DEBUG,
2064 "Created new session %p for `%s' address `%s''\n", 2068 "Created new session %p for `%s' address `%s''\n",
2065 s, 2069 s,
2066 http_common_plugin_address_to_string (plugin->protocol, 2070 http_common_plugin_address_to_string(plugin->protocol,
2067 s->address->address, 2071 s->address->address,
2068 s->address->address_length), 2072 s->address->address_length),
2069 GNUNET_i2s (&s->address->peer)); 2073 GNUNET_i2s(&s->address->peer));
2070 2074
2071 /* add new session */ 2075 /* add new session */
2072 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions, 2076 (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions,
2073 &s->address->peer, 2077 &s->address->peer,
2074 s, 2078 s,
2075 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2079 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2076 /* initiate new connection */ 2080 /* initiate new connection */
2077 if (GNUNET_SYSERR == client_connect (s)) 2081 if (GNUNET_SYSERR == client_connect(s))
2078 { 2082 {
2079 LOG (GNUNET_ERROR_TYPE_ERROR, 2083 LOG(GNUNET_ERROR_TYPE_ERROR,
2080 "Cannot connect to peer `%s' address `%s''\n", 2084 "Cannot connect to peer `%s' address `%s''\n",
2081 http_common_plugin_address_to_string (plugin->protocol, 2085 http_common_plugin_address_to_string(plugin->protocol,
2082 s->address->address, s->address->address_length), 2086 s->address->address, s->address->address_length),
2083 GNUNET_i2s (&s->address->peer)); 2087 GNUNET_i2s(&s->address->peer));
2084 client_delete_session (s); 2088 client_delete_session(s);
2085 return NULL; 2089 return NULL;
2086 } 2090 }
2087 notify_session_monitor (plugin, 2091 notify_session_monitor(plugin,
2088 s, 2092 s,
2089 GNUNET_TRANSPORT_SS_INIT); 2093 GNUNET_TRANSPORT_SS_INIT);
2090 notify_session_monitor (plugin, 2094 notify_session_monitor(plugin,
2091 s, 2095 s,
2092 GNUNET_TRANSPORT_SS_UP); /* or handshake? */ 2096 GNUNET_TRANSPORT_SS_UP); /* or handshake? */
2093 return s; 2097 return s;
2094} 2098}
2095 2099
@@ -2101,18 +2105,18 @@ http_client_plugin_get_session (void *cls,
2101 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 2105 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
2102 */ 2106 */
2103static int 2107static int
2104client_start (struct HTTP_Client_Plugin *plugin) 2108client_start(struct HTTP_Client_Plugin *plugin)
2105{ 2109{
2106 curl_global_init (CURL_GLOBAL_ALL); 2110 curl_global_init(CURL_GLOBAL_ALL);
2107 plugin->curl_multi_handle = curl_multi_init (); 2111 plugin->curl_multi_handle = curl_multi_init();
2108 2112
2109 if (NULL == plugin->curl_multi_handle) 2113 if (NULL == plugin->curl_multi_handle)
2110 { 2114 {
2111 LOG (GNUNET_ERROR_TYPE_ERROR, 2115 LOG(GNUNET_ERROR_TYPE_ERROR,
2112 _("Could not initialize curl multi handle, failed to start %s plugin!\n"), 2116 _("Could not initialize curl multi handle, failed to start %s plugin!\n"),
2113 plugin->name); 2117 plugin->name);
2114 return GNUNET_SYSERR; 2118 return GNUNET_SYSERR;
2115 } 2119 }
2116 return GNUNET_OK; 2120 return GNUNET_OK;
2117} 2121}
2118 2122
@@ -2130,9 +2134,9 @@ client_start (struct HTTP_Client_Plugin *plugin)
2130 * and transport; always returns #GNUNET_NO (this is the client!) 2134 * and transport; always returns #GNUNET_NO (this is the client!)
2131 */ 2135 */
2132static int 2136static int
2133http_client_plugin_address_suggested (void *cls, 2137http_client_plugin_address_suggested(void *cls,
2134 const void *addr, 2138 const void *addr,
2135 size_t addrlen) 2139 size_t addrlen)
2136{ 2140{
2137 /* A HTTP/S client does not have any valid address so:*/ 2141 /* A HTTP/S client does not have any valid address so:*/
2138 return GNUNET_NO; 2142 return GNUNET_NO;
@@ -2146,43 +2150,43 @@ http_client_plugin_address_suggested (void *cls,
2146 * @return NULL 2150 * @return NULL
2147 */ 2151 */
2148void * 2152void *
2149LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) 2153LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
2150{ 2154{
2151 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2155 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2152 struct HTTP_Client_Plugin *plugin = api->cls; 2156 struct HTTP_Client_Plugin *plugin = api->cls;
2153 2157
2154 if (NULL == api->cls) 2158 if (NULL == api->cls)
2155 { 2159 {
2156 /* Stub shutdown */ 2160 /* Stub shutdown */
2157 GNUNET_free (api); 2161 GNUNET_free(api);
2158 return NULL; 2162 return NULL;
2159 } 2163 }
2160 LOG (GNUNET_ERROR_TYPE_DEBUG, 2164 LOG(GNUNET_ERROR_TYPE_DEBUG,
2161 _("Shutting down plugin `%s'\n"), 2165 _("Shutting down plugin `%s'\n"),
2162 plugin->name); 2166 plugin->name);
2163 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 2167 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
2164 &destroy_session_cb, 2168 &destroy_session_cb,
2165 plugin); 2169 plugin);
2166 if (NULL != plugin->client_perform_task) 2170 if (NULL != plugin->client_perform_task)
2167 { 2171 {
2168 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 2172 GNUNET_SCHEDULER_cancel(plugin->client_perform_task);
2169 plugin->client_perform_task = NULL; 2173 plugin->client_perform_task = NULL;
2170 } 2174 }
2171 if (NULL != plugin->curl_multi_handle) 2175 if (NULL != plugin->curl_multi_handle)
2172 { 2176 {
2173 curl_multi_cleanup (plugin->curl_multi_handle); 2177 curl_multi_cleanup(plugin->curl_multi_handle);
2174 plugin->curl_multi_handle = NULL; 2178 plugin->curl_multi_handle = NULL;
2175 } 2179 }
2176 curl_global_cleanup (); 2180 curl_global_cleanup();
2177 LOG (GNUNET_ERROR_TYPE_DEBUG, 2181 LOG(GNUNET_ERROR_TYPE_DEBUG,
2178 _("Shutdown for plugin `%s' complete\n"), 2182 _("Shutdown for plugin `%s' complete\n"),
2179 plugin->name); 2183 plugin->name);
2180 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); 2184 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions);
2181 GNUNET_free_non_null (plugin->proxy_hostname); 2185 GNUNET_free_non_null(plugin->proxy_hostname);
2182 GNUNET_free_non_null (plugin->proxy_username); 2186 GNUNET_free_non_null(plugin->proxy_username);
2183 GNUNET_free_non_null (plugin->proxy_password); 2187 GNUNET_free_non_null(plugin->proxy_password);
2184 GNUNET_free (plugin); 2188 GNUNET_free(plugin);
2185 GNUNET_free (api); 2189 GNUNET_free(api);
2186 return NULL; 2190 return NULL;
2187} 2191}
2188 2192
@@ -2194,115 +2198,115 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2194 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2198 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2195 */ 2199 */
2196static int 2200static int
2197client_configure_plugin (struct HTTP_Client_Plugin *plugin) 2201client_configure_plugin(struct HTTP_Client_Plugin *plugin)
2198{ 2202{
2199 unsigned long long max_requests; 2203 unsigned long long max_requests;
2200 char *proxy_type; 2204 char *proxy_type;
2201 2205
2202 /* Optional parameters */ 2206 /* Optional parameters */
2203 if (GNUNET_OK != 2207 if (GNUNET_OK !=
2204 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, 2208 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg,
2205 plugin->name, 2209 plugin->name,
2206 "MAX_CONNECTIONS", 2210 "MAX_CONNECTIONS",
2207 &max_requests)) 2211 &max_requests))
2208 max_requests = 128; 2212 max_requests = 128;
2209 plugin->max_requests = max_requests; 2213 plugin->max_requests = max_requests;
2210 2214
2211 LOG (GNUNET_ERROR_TYPE_DEBUG, 2215 LOG(GNUNET_ERROR_TYPE_DEBUG,
2212 _("Maximum number of requests is %u\n"), 2216 _("Maximum number of requests is %u\n"),
2213 plugin->max_requests); 2217 plugin->max_requests);
2214 2218
2215 /* Read proxy configuration */ 2219 /* Read proxy configuration */
2216 if (GNUNET_OK == 2220 if (GNUNET_OK ==
2217 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 2221 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2218 plugin->name, 2222 plugin->name,
2219 "PROXY", 2223 "PROXY",
2220 &plugin->proxy_hostname)) 2224 &plugin->proxy_hostname))
2221 {
2222 LOG (GNUNET_ERROR_TYPE_DEBUG,
2223 "Found proxy host: `%s'\n",
2224 plugin->proxy_hostname);
2225 /* proxy username */
2226 if (GNUNET_OK ==
2227 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
2228 plugin->name,
2229 "PROXY_USERNAME",
2230 &plugin->proxy_username))
2231 { 2225 {
2232 LOG (GNUNET_ERROR_TYPE_DEBUG, 2226 LOG(GNUNET_ERROR_TYPE_DEBUG,
2233 "Found proxy username name: `%s'\n", 2227 "Found proxy host: `%s'\n",
2234 plugin->proxy_username); 2228 plugin->proxy_hostname);
2235 } 2229 /* proxy username */
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 }
2236 2240
2237 /* proxy password */ 2241 /* proxy password */
2238 if (GNUNET_OK == 2242 if (GNUNET_OK ==
2239 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 2243 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2240 plugin->name, 2244 plugin->name,
2241 "PROXY_PASSWORD", 2245 "PROXY_PASSWORD",
2242 &plugin->proxy_password)) 2246 &plugin->proxy_password))
2243 { 2247 {
2244 LOG (GNUNET_ERROR_TYPE_DEBUG, 2248 LOG(GNUNET_ERROR_TYPE_DEBUG,
2245 "Found proxy password name: `%s'\n", 2249 "Found proxy password name: `%s'\n",
2246 plugin->proxy_password); 2250 plugin->proxy_password);
2247 } 2251 }
2248 2252
2249 /* proxy type */ 2253 /* proxy type */
2250 if (GNUNET_OK == 2254 if (GNUNET_OK ==
2251 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 2255 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2252 plugin->name, 2256 plugin->name,
2253 "PROXY_TYPE", 2257 "PROXY_TYPE",
2254 &proxy_type)) 2258 &proxy_type))
2255 { 2259 {
2256 GNUNET_STRINGS_utf8_toupper (proxy_type, proxy_type); 2260 GNUNET_STRINGS_utf8_toupper(proxy_type, proxy_type);
2257 2261
2258 if (0 == strcmp(proxy_type, "HTTP")) 2262 if (0 == strcmp(proxy_type, "HTTP"))
2259 plugin->proxytype = CURLPROXY_HTTP; 2263 plugin->proxytype = CURLPROXY_HTTP;
2260 else if (0 == strcmp(proxy_type, "SOCKS4")) 2264 else if (0 == strcmp(proxy_type, "SOCKS4"))
2261 plugin->proxytype = CURLPROXY_SOCKS4; 2265 plugin->proxytype = CURLPROXY_SOCKS4;
2262 else if (0 == strcmp(proxy_type, "SOCKS5")) 2266 else if (0 == strcmp(proxy_type, "SOCKS5"))
2263 plugin->proxytype = CURLPROXY_SOCKS5; 2267 plugin->proxytype = CURLPROXY_SOCKS5;
2264 else if (0 == strcmp(proxy_type, "SOCKS4A")) 2268 else if (0 == strcmp(proxy_type, "SOCKS4A"))
2265 plugin->proxytype = CURLPROXY_SOCKS4A; 2269 plugin->proxytype = CURLPROXY_SOCKS4A;
2266 else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME ")) 2270 else if (0 == strcmp(proxy_type, "SOCKS5_HOSTNAME "))
2267 plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME ; 2271 plugin->proxytype = CURLPROXY_SOCKS5_HOSTNAME;
2268 else 2272 else
2269 { 2273 {
2270 LOG (GNUNET_ERROR_TYPE_ERROR, 2274 LOG(GNUNET_ERROR_TYPE_ERROR,
2271 _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"), 2275 _("Invalid proxy type: `%s', disabling proxy! Check configuration!\n"),
2272 proxy_type); 2276 proxy_type);
2273 2277
2274 GNUNET_free (proxy_type); 2278 GNUNET_free(proxy_type);
2275 GNUNET_free (plugin->proxy_hostname); 2279 GNUNET_free(plugin->proxy_hostname);
2276 plugin->proxy_hostname = NULL; 2280 plugin->proxy_hostname = NULL;
2277 GNUNET_free_non_null (plugin->proxy_username); 2281 GNUNET_free_non_null(plugin->proxy_username);
2278 plugin->proxy_username = NULL; 2282 plugin->proxy_username = NULL;
2279 GNUNET_free_non_null (plugin->proxy_password); 2283 GNUNET_free_non_null(plugin->proxy_password);
2280 plugin->proxy_password = NULL; 2284 plugin->proxy_password = NULL;
2281 2285
2282 return GNUNET_SYSERR; 2286 return GNUNET_SYSERR;
2283 } 2287 }
2284 2288
2285 LOG (GNUNET_ERROR_TYPE_DEBUG, 2289 LOG(GNUNET_ERROR_TYPE_DEBUG,
2286 "Found proxy type: `%s'\n", 2290 "Found proxy type: `%s'\n",
2287 proxy_type); 2291 proxy_type);
2288 } 2292 }
2289 2293
2290 /* proxy http tunneling */ 2294 /* proxy http tunneling */
2291 plugin->proxy_use_httpproxytunnel 2295 plugin->proxy_use_httpproxytunnel
2292 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 2296 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
2293 plugin->name, 2297 plugin->name,
2294 "PROXY_HTTP_TUNNELING"); 2298 "PROXY_HTTP_TUNNELING");
2295 if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel) 2299 if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel)
2296 plugin->proxy_use_httpproxytunnel = GNUNET_NO; 2300 plugin->proxy_use_httpproxytunnel = GNUNET_NO;
2297 2301
2298 GNUNET_free_non_null (proxy_type); 2302 GNUNET_free_non_null(proxy_type);
2299 } 2303 }
2300 2304
2301 /* Should we emulate an XHR client for testing? */ 2305 /* Should we emulate an XHR client for testing? */
2302 plugin->emulate_xhr 2306 plugin->emulate_xhr
2303 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 2307 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
2304 plugin->name, 2308 plugin->name,
2305 "EMULATE_XHR"); 2309 "EMULATE_XHR");
2306 return GNUNET_OK; 2310 return GNUNET_OK;
2307} 2311}
2308 2312
@@ -2316,13 +2320,13 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin)
2316 * @return res string if conversion was successful, NULL otherwise 2320 * @return res string if conversion was successful, NULL otherwise
2317 */ 2321 */
2318static const char * 2322static const char *
2319http_client_plugin_address_to_string (void *cls, 2323http_client_plugin_address_to_string(void *cls,
2320 const void *addr, 2324 const void *addr,
2321 size_t addrlen) 2325 size_t addrlen)
2322{ 2326{
2323 return http_common_plugin_address_to_string (PLUGIN_NAME, 2327 return http_common_plugin_address_to_string(PLUGIN_NAME,
2324 addr, 2328 addr,
2325 addrlen); 2329 addrlen);
2326} 2330}
2327 2331
2328 2332
@@ -2336,11 +2340,11 @@ http_client_plugin_address_to_string (void *cls,
2336 * @param session which session is being updated 2340 * @param session which session is being updated
2337 */ 2341 */
2338static void 2342static void
2339http_client_plugin_update_session_timeout (void *cls, 2343http_client_plugin_update_session_timeout(void *cls,
2340 const struct GNUNET_PeerIdentity *peer, 2344 const struct GNUNET_PeerIdentity *peer,
2341 struct GNUNET_ATS_Session *session) 2345 struct GNUNET_ATS_Session *session)
2342{ 2346{
2343 client_reschedule_session_timeout (session); 2347 client_reschedule_session_timeout(session);
2344} 2348}
2345 2349
2346 2350
@@ -2355,24 +2359,24 @@ http_client_plugin_update_session_timeout (void *cls,
2355 * @param delay new delay to use for receiving 2359 * @param delay new delay to use for receiving
2356 */ 2360 */
2357static void 2361static void
2358http_client_plugin_update_inbound_delay (void *cls, 2362http_client_plugin_update_inbound_delay(void *cls,
2359 const struct GNUNET_PeerIdentity *peer, 2363 const struct GNUNET_PeerIdentity *peer,
2360 struct GNUNET_ATS_Session *s, 2364 struct GNUNET_ATS_Session *s,
2361 struct GNUNET_TIME_Relative delay) 2365 struct GNUNET_TIME_Relative delay)
2362{ 2366{
2363 s->next_receive = GNUNET_TIME_relative_to_absolute (delay); 2367 s->next_receive = GNUNET_TIME_relative_to_absolute(delay);
2364 LOG (GNUNET_ERROR_TYPE_DEBUG, 2368 LOG(GNUNET_ERROR_TYPE_DEBUG,
2365 "New inbound delay %s\n", 2369 "New inbound delay %s\n",
2366 GNUNET_STRINGS_relative_time_to_string (delay, 2370 GNUNET_STRINGS_relative_time_to_string(delay,
2367 GNUNET_NO)); 2371 GNUNET_NO));
2368 if (s->recv_wakeup_task != NULL) 2372 if (s->recv_wakeup_task != NULL)
2369 { 2373 {
2370 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); 2374 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task);
2371 s->recv_wakeup_task 2375 s->recv_wakeup_task
2372 = GNUNET_SCHEDULER_add_delayed (delay, 2376 = GNUNET_SCHEDULER_add_delayed(delay,
2373 &client_wake_up, 2377 &client_wake_up,
2374 s); 2378 s);
2375 } 2379 }
2376} 2380}
2377 2381
2378 2382
@@ -2386,19 +2390,19 @@ http_client_plugin_update_inbound_delay (void *cls,
2386 * @return #GNUNET_OK (continue to iterate) 2390 * @return #GNUNET_OK (continue to iterate)
2387 */ 2391 */
2388static int 2392static int
2389send_session_info_iter (void *cls, 2393send_session_info_iter(void *cls,
2390 const struct GNUNET_PeerIdentity *peer, 2394 const struct GNUNET_PeerIdentity *peer,
2391 void *value) 2395 void *value)
2392{ 2396{
2393 struct HTTP_Client_Plugin *plugin = cls; 2397 struct HTTP_Client_Plugin *plugin = cls;
2394 struct GNUNET_ATS_Session *session = value; 2398 struct GNUNET_ATS_Session *session = value;
2395 2399
2396 notify_session_monitor (plugin, 2400 notify_session_monitor(plugin,
2397 session, 2401 session,
2398 GNUNET_TRANSPORT_SS_INIT); 2402 GNUNET_TRANSPORT_SS_INIT);
2399 notify_session_monitor (plugin, 2403 notify_session_monitor(plugin,
2400 session, 2404 session,
2401 GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */ 2405 GNUNET_TRANSPORT_SS_UP); /* FIXME: or handshake? */
2402 return GNUNET_OK; 2406 return GNUNET_OK;
2403} 2407}
2404 2408
@@ -2416,22 +2420,22 @@ send_session_info_iter (void *cls,
2416 * @param sic_cls closure for @a sic 2420 * @param sic_cls closure for @a sic
2417 */ 2421 */
2418static void 2422static void
2419http_client_plugin_setup_monitor (void *cls, 2423http_client_plugin_setup_monitor(void *cls,
2420 GNUNET_TRANSPORT_SessionInfoCallback sic, 2424 GNUNET_TRANSPORT_SessionInfoCallback sic,
2421 void *sic_cls) 2425 void *sic_cls)
2422{ 2426{
2423 struct HTTP_Client_Plugin *plugin = cls; 2427 struct HTTP_Client_Plugin *plugin = cls;
2424 2428
2425 plugin->sic = sic; 2429 plugin->sic = sic;
2426 plugin->sic_cls = sic_cls; 2430 plugin->sic_cls = sic_cls;
2427 if (NULL != sic) 2431 if (NULL != sic)
2428 { 2432 {
2429 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 2433 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
2430 &send_session_info_iter, 2434 &send_session_info_iter,
2431 plugin); 2435 plugin);
2432 /* signal end of first iteration */ 2436 /* signal end of first iteration */
2433 sic (sic_cls, NULL, NULL); 2437 sic(sic_cls, NULL, NULL);
2434 } 2438 }
2435} 2439}
2436 2440
2437 2441
@@ -2439,29 +2443,29 @@ http_client_plugin_setup_monitor (void *cls,
2439 * Entry point for the plugin. 2443 * Entry point for the plugin.
2440 */ 2444 */
2441void * 2445void *
2442LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) 2446LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
2443{ 2447{
2444 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2448 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2445 struct GNUNET_TRANSPORT_PluginFunctions *api; 2449 struct GNUNET_TRANSPORT_PluginFunctions *api;
2446 struct HTTP_Client_Plugin *plugin; 2450 struct HTTP_Client_Plugin *plugin;
2447 2451
2448 if (NULL == env->receive) 2452 if (NULL == env->receive)
2449 { 2453 {
2450 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 2454 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2451 initialze the plugin or the API */ 2455 initialze the plugin or the API */
2452 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 2456 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
2453 api->cls = NULL; 2457 api->cls = NULL;
2454 api->address_to_string = &http_client_plugin_address_to_string; 2458 api->address_to_string = &http_client_plugin_address_to_string;
2455 api->string_to_address = &http_common_plugin_string_to_address; 2459 api->string_to_address = &http_common_plugin_string_to_address;
2456 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 2460 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
2457 return api; 2461 return api;
2458 } 2462 }
2459 2463
2460 plugin = GNUNET_new (struct HTTP_Client_Plugin); 2464 plugin = GNUNET_new(struct HTTP_Client_Plugin);
2461 plugin->env = env; 2465 plugin->env = env;
2462 plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128, 2466 plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128,
2463 GNUNET_YES); 2467 GNUNET_YES);
2464 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 2468 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
2465 api->cls = plugin; 2469 api->cls = plugin;
2466 api->send = &http_client_plugin_send; 2470 api->send = &http_client_plugin_send;
2467 api->disconnect_session = &http_client_plugin_session_disconnect; 2471 api->disconnect_session = &http_client_plugin_session_disconnect;
@@ -2486,18 +2490,18 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2486#endif 2490#endif
2487 plugin->last_tag = 1; 2491 plugin->last_tag = 1;
2488 2492
2489 if (GNUNET_SYSERR == client_configure_plugin (plugin)) 2493 if (GNUNET_SYSERR == client_configure_plugin(plugin))
2490 { 2494 {
2491 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 2495 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
2492 return NULL; 2496 return NULL;
2493 } 2497 }
2494 2498
2495 /* Start client */ 2499 /* Start client */
2496 if (GNUNET_SYSERR == client_start (plugin)) 2500 if (GNUNET_SYSERR == client_start(plugin))
2497 { 2501 {
2498 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 2502 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
2499 return NULL; 2503 return NULL;
2500 } 2504 }
2501 return api; 2505 return api;
2502} 2506}
2503 2507
diff --git a/src/transport/plugin_transport_http_common.c b/src/transport/plugin_transport_http_common.c
index 0a0545dd6..902fc5c36 100644
--- a/src/transport/plugin_transport_http_common.c
+++ b/src/transport/plugin_transport_http_common.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2002-2013 GNUnet e.V. 3 Copyright (C) 2002-2013 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -30,144 +30,145 @@
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;
53 char *port_start = NULL; 53 char *port_start = NULL;
54 char *path_start = NULL; 54 char *path_start = NULL;
55
55 protocol_start = src; 56 protocol_start = src;
56 57
57 sp = GNUNET_new (struct SplittedHTTPAddress); 58 sp = GNUNET_new(struct SplittedHTTPAddress);
58 /* Address string consists of protocol://host[:port]path*/ 59 /* Address string consists of protocol://host[:port]path*/
59 60
60 host_start = strstr (src, "://"); 61 host_start = strstr(src, "://");
61 if (NULL == host_start) 62 if (NULL == host_start)
62 { 63 {
63 GNUNET_free(src); 64 GNUNET_free(src);
64 GNUNET_free(sp); 65 GNUNET_free(sp);
65 return NULL ; 66 return NULL;
66 } 67 }
67 host_start[0] = '\0'; 68 host_start[0] = '\0';
68 sp->protocol = GNUNET_strdup (protocol_start); 69 sp->protocol = GNUNET_strdup(protocol_start);
69 70
70 host_start += strlen ("://"); 71 host_start += strlen("://");
71 if (strlen (host_start) == 0) 72 if (strlen(host_start) == 0)
72 { 73 {
73 GNUNET_free(src); 74 GNUNET_free(src);
74 GNUNET_free(sp->protocol); 75 GNUNET_free(sp->protocol);
75 GNUNET_free(sp); 76 GNUNET_free(sp);
76 return NULL ; 77 return NULL;
77 } 78 }
78 79
79 /* Find path start */ 80 /* Find path start */
80 path_start = strchr (host_start, '/'); 81 path_start = strchr(host_start, '/');
81 if (NULL != path_start) 82 if (NULL != path_start)
82 { 83 {
83 sp->path = GNUNET_strdup (path_start); 84 sp->path = GNUNET_strdup(path_start);
84 path_start[0] = '\0'; 85 path_start[0] = '\0';
85 } 86 }
87 else
88 sp->path = GNUNET_strdup("");
89
90 if (strlen(host_start) < 1)
91 {
92 GNUNET_free(src);
93 GNUNET_free(sp->protocol);
94 GNUNET_free(sp->path);
95 GNUNET_free(sp);
96 return NULL;
97 }
98
99 if (NULL != (port_start = strrchr(host_start, ':')))
100 {
101 /* *We COULD have a port, but also an IPv6 address! */
102 if (NULL != (v6_end = strchr(host_start, ']')))
103 {
104 if (v6_end < port_start)
105 {
106 /* IPv6 address + port */
107 port_start[0] = '\0';
108 port_start++;
109 sp->port = atoi(port_start);
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 }
86 else 144 else
87 sp->path = GNUNET_strdup (""); 145 {
88 146 /* No ':' as port separator, default port for protocol */
89 if (strlen (host_start) < 1) 147 if (0 == strcmp(sp->protocol, "https"))
90 { 148 sp->port = HTTPS_DEFAULT_PORT;
91 GNUNET_free(src); 149 else if (0 == strcmp(sp->protocol, "http"))
92 GNUNET_free(sp->protocol); 150 sp->port = HTTP_DEFAULT_PORT;
93 GNUNET_free(sp->path); 151 else
94 GNUNET_free(sp);
95 return NULL ;
96 }
97
98 if (NULL != (port_start = strrchr (host_start, ':')))
99 {
100 /* *We COULD have a port, but also an IPv6 address! */
101 if (NULL != (v6_end = strchr (host_start, ']')))
102 {
103 if (v6_end < port_start)
104 {
105 /* IPv6 address + port */
106 port_start[0] = '\0';
107 port_start++;
108 sp->port = atoi (port_start);
109 if ((0 == sp->port) || (65535 < sp->port))
110 { 152 {
153 GNUNET_break(0);
111 GNUNET_free(src); 154 GNUNET_free(src);
112 GNUNET_free(sp->protocol); 155 GNUNET_free(sp->protocol);
113 GNUNET_free(sp->path); 156 GNUNET_free(sp->path);
114 GNUNET_free(sp); 157 GNUNET_free(sp);
115 return NULL ; 158 return NULL;
116 } 159 }
117 } 160 }
118 else 161 if (strlen(host_start) > 0)
119 { 162 sp->host = GNUNET_strdup(host_start);
120 /* IPv6 address + no port */
121 if (0 == strcmp (sp->protocol, "https"))
122 sp->port = HTTPS_DEFAULT_PORT;
123 else if (0 == strcmp (sp->protocol, "http"))
124 sp->port = HTTP_DEFAULT_PORT;
125 }
126 }
127 else
128 {
129 /* No IPv6 address */
130 port_start[0] = '\0';
131 port_start++;
132 sp->port = atoi (port_start);
133 if ((0 == sp->port) || (65535 < sp->port))
134 {
135 GNUNET_free(src);
136 GNUNET_free(sp->protocol);
137 GNUNET_free(sp->path);
138 GNUNET_free(sp);
139 return NULL ;
140 }
141 }
142 }
143 else 163 else
144 {
145 /* No ':' as port separator, default port for protocol */
146 if (0 == strcmp (sp->protocol, "https"))
147 sp->port = HTTPS_DEFAULT_PORT;
148 else if (0 == strcmp (sp->protocol, "http"))
149 sp->port = HTTP_DEFAULT_PORT;
150 else
151 { 164 {
152 GNUNET_break(0); 165 GNUNET_break(0);
153 GNUNET_free(src); 166 GNUNET_free(src);
154 GNUNET_free(sp->protocol); 167 GNUNET_free(sp->protocol);
155 GNUNET_free(sp->path); 168 GNUNET_free(sp->path);
156 GNUNET_free(sp); 169 GNUNET_free(sp);
157 return NULL ; 170 return NULL;
158 } 171 }
159 }
160 if (strlen (host_start) > 0)
161 sp->host = GNUNET_strdup (host_start);
162 else
163 {
164 GNUNET_break(0);
165 GNUNET_free(src);
166 GNUNET_free(sp->protocol);
167 GNUNET_free(sp->path);
168 GNUNET_free(sp);
169 return NULL ;
170 }
171 GNUNET_free(src); 172 GNUNET_free(src);
172 return sp; 173 return sp;
173} 174}
@@ -175,8 +176,7 @@ http_split_address (const char * addr)
175/** 176/**
176 * Closure for #append_port(). 177 * Closure for #append_port().
177 */ 178 */
178struct PrettyPrinterContext 179struct PrettyPrinterContext {
179{
180 /** 180 /**
181 * DLL 181 * DLL
182 */ 182 */
@@ -251,150 +251,149 @@ static struct PrettyPrinterContext *dll_ppc_tail;
251 * @return string representing the same address or NULL on error 251 * @return string representing the same address or NULL on error
252 */ 252 */
253static const char * 253static const char *
254http_common_plugin_dnsresult_to_address (const char *plugin, 254http_common_plugin_dnsresult_to_address(const char *plugin,
255 const struct SplittedHTTPAddress *saddr, 255 const struct SplittedHTTPAddress *saddr,
256 uint32_t options, 256 uint32_t options,
257 const char *dnsresult) 257 const char *dnsresult)
258{ 258{
259 static char rbuf[1024]; 259 static char rbuf[1024];
260 char *res; 260 char *res;
261 261
262 GNUNET_asprintf (&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol, 262 GNUNET_asprintf(&res, "%s.%u.%s://%s:%u%s", plugin, options, saddr->protocol,
263 dnsresult, saddr->port, saddr->path); 263 dnsresult, saddr->port, saddr->path);
264 if (strlen (res) + 1 < 500) 264 if (strlen(res) + 1 < 500)
265 { 265 {
266 GNUNET_memcpy (rbuf, res, strlen (res) + 1); 266 GNUNET_memcpy(rbuf, res, strlen(res) + 1);
267 GNUNET_free(res); 267 GNUNET_free(res);
268 return rbuf; 268 return rbuf;
269 } 269 }
270 GNUNET_break(0); 270 GNUNET_break(0);
271 GNUNET_free(res); 271 GNUNET_free(res);
272 return NULL ; 272 return NULL;
273} 273}
274 274
275 275
276static void 276static void
277http_common_dns_reverse_lookup_cb (void *cls, const char *hostname) 277http_common_dns_reverse_lookup_cb(void *cls, const char *hostname)
278{ 278{
279 struct PrettyPrinterContext *ppc = cls; 279 struct PrettyPrinterContext *ppc = cls;
280 280
281 if (NULL != hostname) 281 if (NULL != hostname)
282 { 282 {
283 ppc->asc (ppc->asc_cls, 283 ppc->asc(ppc->asc_cls,
284 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr, ppc->options, 284 http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options,
285 hostname), GNUNET_OK); 285 hostname), GNUNET_OK);
286 ppc->sucess = GNUNET_YES; 286 ppc->sucess = GNUNET_YES;
287 287 }
288 }
289 else 288 else
290 { 289 {
291 ppc->asc (ppc->asc_cls, NULL, 290 ppc->asc(ppc->asc_cls, NULL,
292 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); 291 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK);
293 292
294 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); 293 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc);
295 http_clean_splitted (ppc->saddr); 294 http_clean_splitted(ppc->saddr);
296 GNUNET_free(ppc->plugin); 295 GNUNET_free(ppc->plugin);
297 GNUNET_free(ppc); 296 GNUNET_free(ppc);
298 } 297 }
299} 298}
300 299
301 300
302static int 301static int
303http_common_dns_reverse_lookup (const struct sockaddr *sockaddr, 302http_common_dns_reverse_lookup(const struct sockaddr *sockaddr,
304 socklen_t sockaddr_len, 303 socklen_t sockaddr_len,
305 const char *type, 304 const char *type,
306 struct SplittedHTTPAddress *saddr, 305 struct SplittedHTTPAddress *saddr,
307 uint32_t options, 306 uint32_t options,
308 struct GNUNET_TIME_Relative timeout, 307 struct GNUNET_TIME_Relative timeout,
309 GNUNET_TRANSPORT_AddressStringCallback asc, 308 GNUNET_TRANSPORT_AddressStringCallback asc,
310 void *asc_cls) 309 void *asc_cls)
311{ 310{
312 struct PrettyPrinterContext *ppc; 311 struct PrettyPrinterContext *ppc;
313 312
314 ppc = GNUNET_new (struct PrettyPrinterContext); 313 ppc = GNUNET_new(struct PrettyPrinterContext);
315 ppc->saddr = saddr; 314 ppc->saddr = saddr;
316 ppc->asc = asc; 315 ppc->asc = asc;
317 ppc->asc_cls = asc_cls; 316 ppc->asc_cls = asc_cls;
318 ppc->plugin = GNUNET_strdup (type); 317 ppc->plugin = GNUNET_strdup(type);
319 ppc->options = options; 318 ppc->options = options;
320 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sockaddr, 319 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sockaddr,
321 sockaddr_len, 320 sockaddr_len,
322 GNUNET_YES, 321 GNUNET_YES,
323 timeout, 322 timeout,
324 &http_common_dns_reverse_lookup_cb, 323 &http_common_dns_reverse_lookup_cb,
325 ppc); 324 ppc);
326 if (NULL == ppc->resolver_handle) 325 if (NULL == ppc->resolver_handle)
327 { 326 {
328 GNUNET_free(ppc->plugin); 327 GNUNET_free(ppc->plugin);
329 GNUNET_free(ppc); 328 GNUNET_free(ppc);
330 return GNUNET_SYSERR; 329 return GNUNET_SYSERR;
331 } 330 }
332 GNUNET_CONTAINER_DLL_insert (dll_ppc_head, 331 GNUNET_CONTAINER_DLL_insert(dll_ppc_head,
333 dll_ppc_tail, 332 dll_ppc_tail,
334 ppc); 333 ppc);
335 return GNUNET_OK; 334 return GNUNET_OK;
336} 335}
337 336
338 337
339static void 338static void
340http_common_dns_ip_lookup_cb (void *cls, 339http_common_dns_ip_lookup_cb(void *cls,
341 const struct sockaddr *addr, 340 const struct sockaddr *addr,
342 socklen_t addrlen) 341 socklen_t addrlen)
343{ 342{
344 struct PrettyPrinterContext *ppc = cls; 343 struct PrettyPrinterContext *ppc = cls;
345 344
346 if (NULL != addr) 345 if (NULL != addr)
347 { 346 {
348 ppc->asc (ppc->asc_cls, 347 ppc->asc(ppc->asc_cls,
349 http_common_plugin_dnsresult_to_address (ppc->plugin, ppc->saddr, ppc->options, 348 http_common_plugin_dnsresult_to_address(ppc->plugin, ppc->saddr, ppc->options,
350 GNUNET_a2s (addr, addrlen)), GNUNET_OK); 349 GNUNET_a2s(addr, addrlen)), GNUNET_OK);
351 ppc->sucess = GNUNET_YES; 350 ppc->sucess = GNUNET_YES;
352 ppc->asc (ppc->asc_cls, GNUNET_a2s (addr, addrlen), GNUNET_OK); 351 ppc->asc(ppc->asc_cls, GNUNET_a2s(addr, addrlen), GNUNET_OK);
353 } 352 }
354 else 353 else
355 { 354 {
356 ppc->asc (ppc->asc_cls, NULL, 355 ppc->asc(ppc->asc_cls, NULL,
357 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK); 356 (GNUNET_NO == ppc->sucess) ? GNUNET_SYSERR : GNUNET_OK);
358 357
359 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc); 358 GNUNET_CONTAINER_DLL_remove(dll_ppc_head, dll_ppc_tail, ppc);
360 GNUNET_free(ppc->plugin); 359 GNUNET_free(ppc->plugin);
361 http_clean_splitted (ppc->saddr); 360 http_clean_splitted(ppc->saddr);
362 GNUNET_free(ppc); 361 GNUNET_free(ppc);
363 } 362 }
364} 363}
365 364
366 365
367static int 366static int
368http_common_dns_ip_lookup (const char *name, 367http_common_dns_ip_lookup(const char *name,
369 const char *type, 368 const char *type,
370 struct SplittedHTTPAddress *saddr, 369 struct SplittedHTTPAddress *saddr,
371 uint32_t options, 370 uint32_t options,
372 struct GNUNET_TIME_Relative timeout, 371 struct GNUNET_TIME_Relative timeout,
373 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) 372 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
374{ 373{
375 struct PrettyPrinterContext *ppc; 374 struct PrettyPrinterContext *ppc;
376 375
377 ppc = GNUNET_new (struct PrettyPrinterContext); 376 ppc = GNUNET_new(struct PrettyPrinterContext);
378 ppc->sucess = GNUNET_NO; 377 ppc->sucess = GNUNET_NO;
379 ppc->saddr = saddr; 378 ppc->saddr = saddr;
380 ppc->asc = asc; 379 ppc->asc = asc;
381 ppc->asc_cls = asc_cls; 380 ppc->asc_cls = asc_cls;
382 ppc->plugin = GNUNET_strdup (type); 381 ppc->plugin = GNUNET_strdup(type);
383 ppc->options = options; 382 ppc->options = options;
384 ppc->resolver_handle = GNUNET_RESOLVER_ip_get (name, 383 ppc->resolver_handle = GNUNET_RESOLVER_ip_get(name,
385 AF_UNSPEC, 384 AF_UNSPEC,
386 timeout, 385 timeout,
387 &http_common_dns_ip_lookup_cb, 386 &http_common_dns_ip_lookup_cb,
388 ppc); 387 ppc);
389 if (NULL == ppc->resolver_handle) 388 if (NULL == ppc->resolver_handle)
390 { 389 {
391 GNUNET_free(ppc->plugin); 390 GNUNET_free(ppc->plugin);
392 GNUNET_free(ppc); 391 GNUNET_free(ppc);
393 return GNUNET_SYSERR; 392 return GNUNET_SYSERR;
394 } 393 }
395 GNUNET_CONTAINER_DLL_insert (dll_ppc_head, 394 GNUNET_CONTAINER_DLL_insert(dll_ppc_head,
396 dll_ppc_tail, 395 dll_ppc_tail,
397 ppc); 396 ppc);
398 return GNUNET_OK; 397 return GNUNET_OK;
399} 398}
400 399
@@ -414,13 +413,13 @@ http_common_dns_ip_lookup (const char *name,
414 * @param asc_cls closure for @a asc 413 * @param asc_cls closure for @a asc
415 */ 414 */
416void 415void
417http_common_plugin_address_pretty_printer (void *cls, const char *type, 416http_common_plugin_address_pretty_printer(void *cls, const char *type,
418 const void *addr, 417 const void *addr,
419 size_t addrlen, 418 size_t addrlen,
420 int numeric, 419 int numeric,
421 struct GNUNET_TIME_Relative timeout, 420 struct GNUNET_TIME_Relative timeout,
422 GNUNET_TRANSPORT_AddressStringCallback asc, 421 GNUNET_TRANSPORT_AddressStringCallback asc,
423 void *asc_cls) 422 void *asc_cls)
424{ 423{
425 const struct HttpAddress *address = addr; 424 const struct HttpAddress *address = addr;
426 struct SplittedHTTPAddress *saddr; 425 struct SplittedHTTPAddress *saddr;
@@ -432,121 +431,121 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type,
432 431
433 saddr = NULL; 432 saddr = NULL;
434 sock_addr = NULL; 433 sock_addr = NULL;
435 if ( (addrlen < sizeof(struct HttpAddress)) || 434 if ((addrlen < sizeof(struct HttpAddress)) ||
436 (addrlen != http_common_address_get_size (address)) ) 435 (addrlen != http_common_address_get_size(address)))
437 { 436 {
438 GNUNET_break(0); 437 GNUNET_break(0);
439 goto handle_error; 438 goto handle_error;
440 } 439 }
441 440
442 addr_str = (char *) &address[1]; 441 addr_str = (char *)&address[1];
443 if (addr_str[ntohl (address->urlen) - 1] != '\0') 442 if (addr_str[ntohl(address->urlen) - 1] != '\0')
444 { 443 {
445 GNUNET_break(0); 444 GNUNET_break(0);
446 goto handle_error; 445 goto handle_error;
447 } 446 }
448 447
449 saddr = http_split_address (addr_str); 448 saddr = http_split_address(addr_str);
450 if (NULL == saddr) 449 if (NULL == saddr)
451 { 450 {
452 GNUNET_break(0); 451 GNUNET_break(0);
453 goto handle_error; 452 goto handle_error;
454 } 453 }
455 454
456 sock_addr = http_common_socket_from_address (addr, addrlen, &res); 455 sock_addr = http_common_socket_from_address(addr, addrlen, &res);
457 if (GNUNET_SYSERR == res) 456 if (GNUNET_SYSERR == res)
458 { 457 {
459 /* Malformed address */ 458 /* Malformed address */
460 GNUNET_break (0); 459 GNUNET_break(0);
461 goto handle_error; 460 goto handle_error;
462 } 461 }
463 else if (GNUNET_NO == res) 462 else if (GNUNET_NO == res)
464 { 463 {
465 /* Could not convert to IP */ 464 /* Could not convert to IP */
466 have_ip = GNUNET_NO; 465 have_ip = GNUNET_NO;
467 } 466 }
468 else if (GNUNET_YES == res) 467 else if (GNUNET_YES == res)
469 { 468 {
470 /* Converted to IP */ 469 /* Converted to IP */
471 have_ip = GNUNET_YES; 470 have_ip = GNUNET_YES;
472 } 471 }
473 else 472 else
474 {
475 /* Must not happen */
476 GNUNET_break (0);
477 goto handle_error;
478 }
479
480 if ( (GNUNET_YES == numeric) &&
481 (GNUNET_YES == have_ip) )
482 {
483 /* No lookup required */
484 ret = http_common_plugin_address_to_string (type, address, addrlen);
485 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
486 asc (asc_cls, NULL, GNUNET_OK);
487 http_clean_splitted (saddr);
488 GNUNET_free_non_null (sock_addr);
489 return;
490 }
491 if ( (GNUNET_YES == numeric) &&
492 (GNUNET_NO == have_ip) )
493 {
494 /* Forward lookup */
495 if (GNUNET_SYSERR ==
496 http_common_dns_ip_lookup (saddr->host, type, saddr,
497 address->options, timeout,
498 asc, asc_cls))
499 { 473 {
474 /* Must not happen */
500 GNUNET_break(0); 475 GNUNET_break(0);
501 goto handle_error; 476 goto handle_error;
502 } 477 }
503 /* Wait for resolver callback */ 478
504 GNUNET_free_non_null (sock_addr); 479 if ((GNUNET_YES == numeric) &&
505 return; 480 (GNUNET_YES == have_ip))
506 }
507 if ( (GNUNET_NO == numeric) &&
508 (GNUNET_YES == have_ip) )
509 {
510 /* Reverse lookup */
511 if (GNUNET_SYSERR ==
512 http_common_dns_reverse_lookup (sock_addr,
513 (AF_INET == sock_addr->sa_family)
514 ? sizeof(struct sockaddr_in)
515 : sizeof(struct sockaddr_in6),
516 type,
517 saddr,
518 address->options, timeout,
519 asc, asc_cls))
520 { 481 {
521 GNUNET_break(0); 482 /* No lookup required */
522 goto handle_error; 483 ret = http_common_plugin_address_to_string(type, address, addrlen);
484 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
485 asc(asc_cls, NULL, GNUNET_OK);
486 http_clean_splitted(saddr);
487 GNUNET_free_non_null(sock_addr);
488 return;
489 }
490 if ((GNUNET_YES == numeric) &&
491 (GNUNET_NO == have_ip))
492 {
493 /* Forward lookup */
494 if (GNUNET_SYSERR ==
495 http_common_dns_ip_lookup(saddr->host, type, saddr,
496 address->options, timeout,
497 asc, asc_cls))
498 {
499 GNUNET_break(0);
500 goto handle_error;
501 }
502 /* Wait for resolver callback */
503 GNUNET_free_non_null(sock_addr);
504 return;
505 }
506 if ((GNUNET_NO == numeric) &&
507 (GNUNET_YES == have_ip))
508 {
509 /* Reverse lookup */
510 if (GNUNET_SYSERR ==
511 http_common_dns_reverse_lookup(sock_addr,
512 (AF_INET == sock_addr->sa_family)
513 ? sizeof(struct sockaddr_in)
514 : sizeof(struct sockaddr_in6),
515 type,
516 saddr,
517 address->options, timeout,
518 asc, asc_cls))
519 {
520 GNUNET_break(0);
521 goto handle_error;
522 }
523 /* Wait for resolver callback */
524 GNUNET_free_non_null(sock_addr);
525 return;
526 }
527 if ((GNUNET_NO == numeric) &&
528 (GNUNET_NO == have_ip))
529 {
530 /* No lookup required */
531 ret = http_common_plugin_address_to_string(type, address, addrlen);
532 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
533 asc(asc_cls, NULL, GNUNET_OK);
534 GNUNET_free_non_null(sock_addr);
535 http_clean_splitted(saddr);
536 return;
523 } 537 }
524 /* Wait for resolver callback */
525 GNUNET_free_non_null (sock_addr);
526 return;
527 }
528 if ( (GNUNET_NO == numeric) &&
529 (GNUNET_NO == have_ip) )
530 {
531 /* No lookup required */
532 ret = http_common_plugin_address_to_string (type, address, addrlen);
533 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
534 asc (asc_cls, NULL, GNUNET_OK);
535 GNUNET_free_non_null (sock_addr);
536 http_clean_splitted (saddr);
537 return;
538 }
539 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */ 538 /* Error (argument supplied not GNUNET_YES or GNUNET_NO) */
540 GNUNET_break (0); 539 GNUNET_break(0);
541 goto handle_error; 540 goto handle_error;
542 541
543 handle_error: 542handle_error:
544 /* Report error */ 543 /* Report error */
545 asc (asc_cls, NULL, GNUNET_SYSERR); 544 asc(asc_cls, NULL, GNUNET_SYSERR);
546 asc (asc_cls, NULL, GNUNET_OK); 545 asc(asc_cls, NULL, GNUNET_OK);
547 GNUNET_free_non_null (sock_addr); 546 GNUNET_free_non_null(sock_addr);
548 if (NULL != saddr) 547 if (NULL != saddr)
549 http_clean_splitted (saddr); 548 http_clean_splitted(saddr);
550} 549}
551 550
552 551
@@ -554,36 +553,36 @@ http_common_plugin_address_pretty_printer (void *cls, const char *type,
554 * FIXME. 553 * FIXME.
555 */ 554 */
556const char * 555const char *
557http_common_plugin_address_to_url (void *cls, 556http_common_plugin_address_to_url(void *cls,
558 const void *addr, 557 const void *addr,
559 size_t addrlen) 558 size_t addrlen)
560{ 559{
561 static char rbuf[1024]; 560 static char rbuf[1024];
562 const struct HttpAddress *address = addr; 561 const struct HttpAddress *address = addr;
563 const char * addr_str; 562 const char * addr_str;
564 563
565 if (NULL == addr) 564 if (NULL == addr)
566 { 565 {
567 GNUNET_break(0); 566 GNUNET_break(0);
568 return NULL; 567 return NULL;
569 } 568 }
570 if (0 == addrlen) 569 if (0 == addrlen)
571 { 570 {
572 GNUNET_break(0); 571 GNUNET_break(0);
573 return NULL; 572 return NULL;
574 } 573 }
575 if (addrlen != http_common_address_get_size (address)) 574 if (addrlen != http_common_address_get_size(address))
576 { 575 {
577 GNUNET_break(0); 576 GNUNET_break(0);
578 return NULL; 577 return NULL;
579 } 578 }
580 addr_str = (char *) &address[1]; 579 addr_str = (char *)&address[1];
581 if (addr_str[ntohl (address->urlen) - 1] != '\0') 580 if (addr_str[ntohl(address->urlen) - 1] != '\0')
582 return NULL; 581 return NULL;
583 582
584 GNUNET_memcpy (rbuf, 583 GNUNET_memcpy(rbuf,
585 &address[1], 584 &address[1],
586 ntohl (address->urlen)); 585 ntohl(address->urlen));
587 return rbuf; 586 return rbuf;
588} 587}
589 588
@@ -600,9 +599,9 @@ http_common_plugin_address_to_url (void *cls,
600 * @return string representing the same address 599 * @return string representing the same address
601 */ 600 */
602const char * 601const char *
603http_common_plugin_address_to_string (const char *plugin, 602http_common_plugin_address_to_string(const char *plugin,
604 const void *addr, 603 const void *addr,
605 size_t addrlen) 604 size_t addrlen)
606{ 605{
607 static char rbuf[1024]; 606 static char rbuf[1024];
608 const struct HttpAddress *address = addr; 607 const struct HttpAddress *address = addr;
@@ -614,19 +613,19 @@ http_common_plugin_address_to_string (const char *plugin,
614 return NULL; 613 return NULL;
615 if (0 == addrlen) 614 if (0 == addrlen)
616 return NULL; 615 return NULL;
617 if (addrlen != http_common_address_get_size (address)) 616 if (addrlen != http_common_address_get_size(address))
618 return NULL; 617 return NULL;
619 addr_str = (char *) &address[1]; 618 addr_str = (char *)&address[1];
620 if (addr_str[ntohl (address->urlen) - 1] != '\0') 619 if (addr_str[ntohl(address->urlen) - 1] != '\0')
621 return NULL; 620 return NULL;
622 GNUNET_asprintf (&res, "%s.%u.%s", plugin, ntohl (address->options), 621 GNUNET_asprintf(&res, "%s.%u.%s", plugin, ntohl(address->options),
623 &address[1]); 622 &address[1]);
624 if (strlen (res) + 1 < 500) 623 if (strlen(res) + 1 < 500)
625 { 624 {
626 GNUNET_memcpy (rbuf, res, strlen (res) + 1); 625 GNUNET_memcpy(rbuf, res, strlen(res) + 1);
627 GNUNET_free(res); 626 GNUNET_free(res);
628 return rbuf; 627 return rbuf;
629 } 628 }
630 GNUNET_break(0); 629 GNUNET_break(0);
631 GNUNET_free(res); 630 GNUNET_free(res);
632 return NULL; 631 return NULL;
@@ -645,11 +644,11 @@ http_common_plugin_address_to_string (const char *plugin,
645 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 644 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
646 */ 645 */
647int 646int
648http_common_plugin_string_to_address (void *cls, 647http_common_plugin_string_to_address(void *cls,
649 const char *addr, 648 const char *addr,
650 uint16_t addrlen, 649 uint16_t addrlen,
651 void **buf, 650 void **buf,
652 size_t *added) 651 size_t *added)
653{ 652{
654 struct HttpAddress *a; 653 struct HttpAddress *a;
655 char *address; 654 char *address;
@@ -663,46 +662,46 @@ http_common_plugin_string_to_address (void *cls,
663 plugin = NULL; 662 plugin = NULL;
664 optionstr = NULL; 663 optionstr = NULL;
665 if ((NULL == addr) || (addrlen == 0)) 664 if ((NULL == addr) || (addrlen == 0))
666 { 665 {
667 GNUNET_break(0); 666 GNUNET_break(0);
668 return GNUNET_SYSERR; 667 return GNUNET_SYSERR;
669 } 668 }
670 if ('\0' != addr[addrlen - 1]) 669 if ('\0' != addr[addrlen - 1])
671 { 670 {
672 GNUNET_break(0); 671 GNUNET_break(0);
673 return GNUNET_SYSERR; 672 return GNUNET_SYSERR;
674 } 673 }
675 if (strlen (addr) != addrlen - 1) 674 if (strlen(addr) != addrlen - 1)
676 { 675 {
677 GNUNET_break(0); 676 GNUNET_break(0);
678 return GNUNET_SYSERR; 677 return GNUNET_SYSERR;
679 } 678 }
680 plugin = GNUNET_strdup (addr); 679 plugin = GNUNET_strdup(addr);
681 optionstr = strchr (plugin, '.'); 680 optionstr = strchr(plugin, '.');
682 if (NULL == optionstr) 681 if (NULL == optionstr)
683 { 682 {
684 GNUNET_break(0); 683 GNUNET_break(0);
685 GNUNET_free(plugin); 684 GNUNET_free(plugin);
686 return GNUNET_SYSERR; 685 return GNUNET_SYSERR;
687 } 686 }
688 optionstr[0] = '\0'; 687 optionstr[0] = '\0';
689 optionstr++; 688 optionstr++;
690 options = atol (optionstr); /* 0 on conversion error, that's ok */ 689 options = atol(optionstr); /* 0 on conversion error, that's ok */
691 address = strchr (optionstr, '.'); 690 address = strchr(optionstr, '.');
692 if (NULL == address) 691 if (NULL == address)
693 { 692 {
694 GNUNET_break(0); 693 GNUNET_break(0);
695 GNUNET_free(plugin); 694 GNUNET_free(plugin);
696 return GNUNET_SYSERR; 695 return GNUNET_SYSERR;
697 } 696 }
698 address[0] = '\0'; 697 address[0] = '\0';
699 address++; 698 address++;
700 urlen = strlen (address) + 1; 699 urlen = strlen(address) + 1;
701 700
702 a = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); 701 a = GNUNET_malloc(sizeof(struct HttpAddress) + urlen);
703 a->options = htonl (options); 702 a->options = htonl(options);
704 a->urlen = htonl (urlen); 703 a->urlen = htonl(urlen);
705 GNUNET_memcpy (&a[1], address, urlen); 704 GNUNET_memcpy(&a[1], address, urlen);
706 705
707 (*buf) = a; 706 (*buf) = a;
708 (*added) = sizeof(struct HttpAddress) + urlen; 707 (*added) = sizeof(struct HttpAddress) + urlen;
@@ -720,24 +719,24 @@ http_common_plugin_string_to_address (void *cls,
720 * @return the HttpAddress 719 * @return the HttpAddress
721 */ 720 */
722struct HttpAddress * 721struct HttpAddress *
723http_common_address_from_socket (const char *protocol, 722http_common_address_from_socket(const char *protocol,
724 const struct sockaddr *addr, 723 const struct sockaddr *addr,
725 socklen_t addrlen) 724 socklen_t addrlen)
726{ 725{
727 struct HttpAddress *address = NULL; 726 struct HttpAddress *address = NULL;
728 char *res; 727 char *res;
729 size_t len; 728 size_t len;
730 729
731 GNUNET_asprintf (&res, 730 GNUNET_asprintf(&res,
732 "%s://%s", 731 "%s://%s",
733 protocol, 732 protocol,
734 GNUNET_a2s (addr, 733 GNUNET_a2s(addr,
735 addrlen)); 734 addrlen));
736 len = strlen (res) + 1; 735 len = strlen(res) + 1;
737 address = GNUNET_malloc (sizeof (struct HttpAddress) + len); 736 address = GNUNET_malloc(sizeof(struct HttpAddress) + len);
738 address->options = htonl (HTTP_OPTIONS_NONE); 737 address->options = htonl(HTTP_OPTIONS_NONE);
739 address->urlen = htonl (len); 738 address->urlen = htonl(len);
740 GNUNET_memcpy (&address[1], res, len); 739 GNUNET_memcpy(&address[1], res, len);
741 GNUNET_free(res); 740 GNUNET_free(res);
742 return address; 741 return address;
743} 742}
@@ -755,9 +754,9 @@ http_common_address_from_socket (const char *protocol,
755 * @return the string 754 * @return the string
756 */ 755 */
757struct sockaddr * 756struct sockaddr *
758http_common_socket_from_address (const void *addr, 757http_common_socket_from_address(const void *addr,
759 size_t addrlen, 758 size_t addrlen,
760 int *res) 759 int *res)
761{ 760{
762 const struct HttpAddress *ha; 761 const struct HttpAddress *ha;
763 struct SplittedHTTPAddress * spa; 762 struct SplittedHTTPAddress * spa;
@@ -766,68 +765,68 @@ http_common_socket_from_address (const void *addr,
766 size_t urlen; 765 size_t urlen;
767 766
768 (*res) = GNUNET_SYSERR; 767 (*res) = GNUNET_SYSERR;
769 ha = (const struct HttpAddress *) addr; 768 ha = (const struct HttpAddress *)addr;
770 if (NULL == addr) 769 if (NULL == addr)
771 { 770 {
772 GNUNET_break (0); 771 GNUNET_break(0);
773 return NULL; 772 return NULL;
774 } 773 }
775 if (0 == addrlen) 774 if (0 == addrlen)
776 { 775 {
777 GNUNET_break (0); 776 GNUNET_break(0);
778 return NULL; 777 return NULL;
779 } 778 }
780 if (addrlen < sizeof(struct HttpAddress)) 779 if (addrlen < sizeof(struct HttpAddress))
781 { 780 {
782 GNUNET_break (0); 781 GNUNET_break(0);
783 return NULL; 782 return NULL;
784 } 783 }
785 urlen = ntohl (ha->urlen); 784 urlen = ntohl(ha->urlen);
786 if (sizeof(struct HttpAddress) + urlen != addrlen) 785 if (sizeof(struct HttpAddress) + urlen != addrlen)
787 { 786 {
788 /* This is a legacy addresses */ 787 /* This is a legacy addresses */
789 return NULL; 788 return NULL;
790 } 789 }
791 if (addrlen < sizeof(struct HttpAddress) + urlen) 790 if (addrlen < sizeof(struct HttpAddress) + urlen)
792 { 791 {
793 /* This is a legacy addresses */ 792 /* This is a legacy addresses */
794 return NULL; 793 return NULL;
795 } 794 }
796 if (((char *) addr)[addrlen - 1] != '\0') 795 if (((char *)addr)[addrlen - 1] != '\0')
797 { 796 {
798 GNUNET_break (0); 797 GNUNET_break(0);
799 return NULL; 798 return NULL;
800 } 799 }
801 spa = http_split_address ((const char *) &ha[1]); 800 spa = http_split_address((const char *)&ha[1]);
802 if (NULL == spa) 801 if (NULL == spa)
803 { 802 {
804 (*res) = GNUNET_SYSERR; 803 (*res) = GNUNET_SYSERR;
805 return NULL; 804 return NULL;
806 } 805 }
807 806
808 s = GNUNET_new (struct sockaddr_storage); 807 s = GNUNET_new(struct sockaddr_storage);
809 GNUNET_asprintf (&to_conv, "%s:%u", spa->host, spa->port); 808 GNUNET_asprintf(&to_conv, "%s:%u", spa->host, spa->port);
810 if (GNUNET_SYSERR 809 if (GNUNET_SYSERR
811 == GNUNET_STRINGS_to_address_ip (to_conv, strlen (to_conv), s)) 810 == GNUNET_STRINGS_to_address_ip(to_conv, strlen(to_conv), s))
812 { 811 {
813 /* could be a hostname */ 812 /* could be a hostname */
814 GNUNET_free(s); 813 GNUNET_free(s);
815 (*res) = GNUNET_NO; 814 (*res) = GNUNET_NO;
816 s = NULL; 815 s = NULL;
817 } 816 }
818 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family)) 817 else if ((AF_INET != s->ss_family) && (AF_INET6 != s->ss_family))
819 { 818 {
820 GNUNET_free (s); 819 GNUNET_free(s);
821 (*res) = GNUNET_SYSERR; 820 (*res) = GNUNET_SYSERR;
822 s = NULL; 821 s = NULL;
823 } 822 }
824 else 823 else
825 { 824 {
826 (*res) = GNUNET_YES; 825 (*res) = GNUNET_YES;
827 } 826 }
828 http_clean_splitted (spa); 827 http_clean_splitted(spa);
829 GNUNET_free (to_conv); 828 GNUNET_free(to_conv);
830 return (struct sockaddr *) s; 829 return (struct sockaddr *)s;
831} 830}
832 831
833 832
@@ -838,9 +837,9 @@ http_common_socket_from_address (const void *addr,
838 * @return the size 837 * @return the size
839 */ 838 */
840size_t 839size_t
841http_common_address_get_size (const struct HttpAddress * addr) 840http_common_address_get_size(const struct HttpAddress * addr)
842{ 841{
843 return sizeof(struct HttpAddress) + ntohl (addr->urlen); 842 return sizeof(struct HttpAddress) + ntohl(addr->urlen);
844} 843}
845 844
846 845
@@ -854,17 +853,18 @@ http_common_address_get_size (const struct HttpAddress * addr)
854 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error 853 * @return #GNUNET_YES if equal, #GNUNET_NO if not, #GNUNET_SYSERR on error
855 */ 854 */
856size_t 855size_t
857http_common_cmp_addresses (const void *addr1, 856http_common_cmp_addresses(const void *addr1,
858 size_t addrlen1, 857 size_t addrlen1,
859 const void *addr2, 858 const void *addr2,
860 size_t addrlen2) 859 size_t addrlen2)
861{ 860{
862 const char *a1 = addr1; 861 const char *a1 = addr1;
863 const char *a2 = addr2; 862 const char *a2 = addr2;
864 const struct HttpAddress *ha1; 863 const struct HttpAddress *ha1;
865 const struct HttpAddress *ha2; 864 const struct HttpAddress *ha2;
866 ha1 = (const struct HttpAddress *) a1; 865
867 ha2 = (const struct HttpAddress *) a2; 866 ha1 = (const struct HttpAddress *)a1;
867 ha2 = (const struct HttpAddress *)a2;
868 868
869 if (NULL == a1) 869 if (NULL == a1)
870 return GNUNET_SYSERR; 870 return GNUNET_SYSERR;
@@ -885,7 +885,7 @@ http_common_cmp_addresses (const void *addr1,
885 if (ha1->urlen != ha2->urlen) 885 if (ha1->urlen != ha2->urlen)
886 return GNUNET_NO; 886 return GNUNET_NO;
887 887
888 if (0 == strcmp ((const char *) &ha1[1], (const char *) &ha2[1])) 888 if (0 == strcmp((const char *)&ha1[1], (const char *)&ha2[1]))
889 return GNUNET_YES; 889 return GNUNET_YES;
890 return GNUNET_NO; 890 return GNUNET_NO;
891} 891}
@@ -899,37 +899,36 @@ http_common_cmp_addresses (const void *addr1,
899 * @return the network type 899 * @return the network type
900 */ 900 */
901enum GNUNET_NetworkType 901enum GNUNET_NetworkType
902http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env, 902http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env,
903 const struct GNUNET_HELLO_Address *address) 903 const struct GNUNET_HELLO_Address *address)
904{ 904{
905
906 struct sockaddr *sa; 905 struct sockaddr *sa;
907 enum GNUNET_NetworkType net_type; 906 enum GNUNET_NetworkType net_type;
908 size_t salen = 0; 907 size_t salen = 0;
909 int res; 908 int res;
910 909
911 net_type = GNUNET_NT_UNSPECIFIED; 910 net_type = GNUNET_NT_UNSPECIFIED;
912 sa = http_common_socket_from_address (address->address, 911 sa = http_common_socket_from_address(address->address,
913 address->address_length, 912 address->address_length,
914 &res); 913 &res);
915 if (GNUNET_SYSERR == res) 914 if (GNUNET_SYSERR == res)
916 return net_type; 915 return net_type;
917 if (GNUNET_YES == res) 916 if (GNUNET_YES == res)
918 {
919 GNUNET_assert (NULL != sa);
920 if (AF_INET == sa->sa_family)
921 {
922 salen = sizeof (struct sockaddr_in);
923 }
924 else if (AF_INET6 == sa->sa_family)
925 { 917 {
926 salen = sizeof (struct sockaddr_in6); 918 GNUNET_assert(NULL != sa);
919 if (AF_INET == sa->sa_family)
920 {
921 salen = sizeof(struct sockaddr_in);
922 }
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);
927 } 931 }
928 net_type = env->get_address_type (env->cls,
929 sa,
930 salen);
931 GNUNET_free (sa);
932 }
933 return net_type; 932 return net_type;
934} 933}
935 934
diff --git a/src/transport/plugin_transport_http_common.h b/src/transport/plugin_transport_http_common.h
index 0410be8e9..6aaf663a1 100644
--- a/src/transport/plugin_transport_http_common.h
+++ b/src/transport/plugin_transport_http_common.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/plugin_transport_http_common.c 21 * @file transport/plugin_transport_http_common.c
22 * @brief functionality shared by http client and server transport service plugin 22 * @brief functionality shared by http client and server transport service plugin
@@ -33,10 +33,10 @@
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(GNUNET_TIME_UNIT_SECONDS, 3)
37#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) 37#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
38#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7) 38#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 7)
39#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 7) 39#define SERVER_SESSION_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 7)
40#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG 40#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
41 41
42#else 42#else
@@ -47,8 +47,8 @@
47#define PROTOCOL "http" 47#define PROTOCOL "http"
48#endif 48#endif
49 49
50#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 50#define HTTP_SERVER_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
51#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) 51#define HTTP_CLIENT_NOT_VALIDATED_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15)
52#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT 52#define HTTP_CLIENT_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
53#define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT 53#define HTTP_SERVER_SESSION_TIMEOUT GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
54#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG 54#define TIMEOUT_LOG GNUNET_ERROR_TYPE_DEBUG
@@ -61,8 +61,7 @@
61/** 61/**
62 * Bits in the `options` field of HTTP addresses. 62 * Bits in the `options` field of HTTP addresses.
63 */ 63 */
64enum HttpAddressOptions 64enum HttpAddressOptions {
65{
66 /** 65 /**
67 * No bits set. 66 * No bits set.
68 */ 67 */
@@ -87,8 +86,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
87/** 86/**
88 * HttpAddress 87 * HttpAddress
89 */ 88 */
90struct HttpAddress 89struct HttpAddress {
91{
92 /** 90 /**
93 * Address options 91 * Address options
94 * see `enum HttpAddressOptions` 92 * see `enum HttpAddressOptions`
@@ -106,8 +104,7 @@ GNUNET_NETWORK_STRUCT_END
106/** 104/**
107 * Representation of HTTP URL split into its components. 105 * Representation of HTTP URL split into its components.
108 */ 106 */
109struct SplittedHTTPAddress 107struct SplittedHTTPAddress {
110{
111 char *protocol; 108 char *protocol;
112 char *host; 109 char *host;
113 char *path; 110 char *path;
@@ -120,7 +117,7 @@ struct SplittedHTTPAddress
120 * and path components. 117 * and path components.
121 */ 118 */
122struct SplittedHTTPAddress * 119struct SplittedHTTPAddress *
123http_split_address (const char *addr); 120http_split_address(const char *addr);
124 121
125 122
126/** 123/**
@@ -138,14 +135,14 @@ http_split_address (const char *addr);
138 * @param asc_cls closure for @a asc 135 * @param asc_cls closure for @a asc
139 */ 136 */
140void 137void
141http_common_plugin_address_pretty_printer (void *cls, 138http_common_plugin_address_pretty_printer(void *cls,
142 const char *type, 139 const char *type,
143 const void *addr, 140 const void *addr,
144 size_t addrlen, 141 size_t addrlen,
145 int numeric, 142 int numeric,
146 struct GNUNET_TIME_Relative timeout, 143 struct GNUNET_TIME_Relative timeout,
147 GNUNET_TRANSPORT_AddressStringCallback asc, 144 GNUNET_TRANSPORT_AddressStringCallback asc,
148 void *asc_cls); 145 void *asc_cls);
149 146
150 147
151/** 148/**
@@ -160,9 +157,9 @@ http_common_plugin_address_pretty_printer (void *cls,
160 * @return string representing the same address 157 * @return string representing the same address
161 */ 158 */
162const char * 159const char *
163http_common_plugin_address_to_string (const char *plugin, 160http_common_plugin_address_to_string(const char *plugin,
164 const void *addr, 161 const void *addr,
165 size_t addrlen); 162 size_t addrlen);
166 163
167 164
168/** 165/**
@@ -178,11 +175,11 @@ http_common_plugin_address_to_string (const char *plugin,
178 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 175 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
179 */ 176 */
180int 177int
181http_common_plugin_string_to_address (void *cls, 178http_common_plugin_string_to_address(void *cls,
182 const char *addr, 179 const char *addr,
183 uint16_t addrlen, 180 uint16_t addrlen,
184 void **buf, 181 void **buf,
185 size_t *added); 182 size_t *added);
186 183
187 184
188/** 185/**
@@ -194,9 +191,9 @@ http_common_plugin_string_to_address (void *cls,
194 * @return the string 191 * @return the string
195 */ 192 */
196struct HttpAddress * 193struct HttpAddress *
197http_common_address_from_socket (const char *protocol, 194http_common_address_from_socket(const char *protocol,
198 const struct sockaddr *addr, 195 const struct sockaddr *addr,
199 socklen_t addrlen); 196 socklen_t addrlen);
200 197
201 198
202/** 199/**
@@ -211,15 +208,15 @@ http_common_address_from_socket (const char *protocol,
211 * @return the string 208 * @return the string
212 */ 209 */
213struct sockaddr * 210struct sockaddr *
214http_common_socket_from_address (const void *addr, 211http_common_socket_from_address(const void *addr,
215 size_t addrlen, 212 size_t addrlen,
216 int *res); 213 int *res);
217 214
218 215
219const char * 216const char *
220http_common_plugin_address_to_url (void *cls, 217http_common_plugin_address_to_url(void *cls,
221 const void *addr, 218 const void *addr,
222 size_t addrlen); 219 size_t addrlen);
223 220
224 221
225/** 222/**
@@ -229,7 +226,7 @@ http_common_plugin_address_to_url (void *cls,
229 * @return the size 226 * @return the size
230 */ 227 */
231size_t 228size_t
232http_common_address_get_size (const struct HttpAddress * addr); 229http_common_address_get_size(const struct HttpAddress * addr);
233 230
234 231
235/** 232/**
@@ -242,10 +239,10 @@ http_common_address_get_size (const struct HttpAddress * addr);
242 * @return #GNUNET_YES if equal, #GNUNET_NO else 239 * @return #GNUNET_YES if equal, #GNUNET_NO else
243 */ 240 */
244size_t 241size_t
245http_common_cmp_addresses (const void *addr1, 242http_common_cmp_addresses(const void *addr1,
246 size_t addrlen1, 243 size_t addrlen1,
247 const void *addr2, 244 const void *addr2,
248 size_t addrlen2); 245 size_t addrlen2);
249 246
250 247
251/** 248/**
@@ -256,8 +253,8 @@ http_common_cmp_addresses (const void *addr1,
256 * @return the network type 253 * @return the network type
257 */ 254 */
258enum GNUNET_NetworkType 255enum GNUNET_NetworkType
259http_common_get_network_for_address (struct GNUNET_TRANSPORT_PluginEnvironment *env, 256http_common_get_network_for_address(struct GNUNET_TRANSPORT_PluginEnvironment *env,
260 const struct GNUNET_HELLO_Address *address); 257 const struct GNUNET_HELLO_Address *address);
261 258
262 259
263/* end of plugin_transport_http_common.h */ 260/* 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 495105fe3..1b454c09f 100644
--- a/src/transport/plugin_transport_http_server.c
+++ b/src/transport/plugin_transport_http_server.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_http_server.c 22 * @file transport/plugin_transport_http_server.c
@@ -51,14 +51,13 @@
51#define _SEND 1 51#define _SEND 1
52 52
53 53
54#define LOG(kind,...) GNUNET_log_from (kind, "transport-" PLUGIN_NAME,__VA_ARGS__) 54#define LOG(kind, ...) GNUNET_log_from(kind, "transport-" PLUGIN_NAME, __VA_ARGS__)
55 55
56 56
57/** 57/**
58 * Information we keep with MHD for an HTTP request. 58 * Information we keep with MHD for an HTTP request.
59 */ 59 */
60struct ServerRequest 60struct ServerRequest {
61{
62 /** 61 /**
63 * The session this server request belongs to 62 * The session this server request belongs to
64 * Can be NULL, when session was disconnected and freed 63 * Can be NULL, when session was disconnected and freed
@@ -96,15 +95,13 @@ struct ServerRequest
96 * Currently suspended 95 * Currently suspended
97 */ 96 */
98 bool suspended; 97 bool suspended;
99
100}; 98};
101 99
102 100
103/** 101/**
104 * Wrapper to manage addresses 102 * Wrapper to manage addresses
105 */ 103 */
106struct HttpAddressWrapper 104struct HttpAddressWrapper {
107{
108 /** 105 /**
109 * Linked list next 106 * Linked list next
110 */ 107 */
@@ -130,8 +127,7 @@ struct HttpAddressWrapper
130/** 127/**
131 * Message to send using http 128 * Message to send using http
132 */ 129 */
133struct HTTP_Message 130struct HTTP_Message {
134{
135 /** 131 /**
136 * next pointer for double linked list 132 * next pointer for double linked list
137 */ 133 */
@@ -179,9 +175,7 @@ struct HTTP_Message
179/** 175/**
180 * Session handle for connections. 176 * Session handle for connections.
181 */ 177 */
182struct GNUNET_ATS_Session 178struct GNUNET_ATS_Session {
183{
184
185 /** 179 /**
186 * To whom are we talking to (set to our identity 180 * To whom are we talking to (set to our identity
187 * if we are still waiting for the welcome message) 181 * if we are still waiting for the welcome message)
@@ -268,15 +262,13 @@ struct GNUNET_ATS_Session
268 * #GNUNET_YES if this session is known to the service. 262 * #GNUNET_YES if this session is known to the service.
269 */ 263 */
270 int known_to_service; 264 int known_to_service;
271
272}; 265};
273 266
274 267
275/** 268/**
276 * Encapsulation of all of the state of the plugin. 269 * Encapsulation of all of the state of the plugin.
277 */ 270 */
278struct HTTP_Server_Plugin 271struct HTTP_Server_Plugin {
279{
280 /** 272 /**
281 * Our environment. 273 * Our environment.
282 */ 274 */
@@ -457,7 +449,6 @@ struct HTTP_Server_Plugin
457 * Regex for parsing URLs. FIXME: this seems overkill. 449 * Regex for parsing URLs. FIXME: this seems overkill.
458 */ 450 */
459 regex_t url_regex; 451 regex_t url_regex;
460
461}; 452};
462 453
463 454
@@ -470,15 +461,15 @@ struct HTTP_Server_Plugin
470 * @param state new state of the session 461 * @param state new state of the session
471 */ 462 */
472static void 463static void
473notify_session_monitor (struct HTTP_Server_Plugin *plugin, 464notify_session_monitor(struct HTTP_Server_Plugin *plugin,
474 struct GNUNET_ATS_Session *session, 465 struct GNUNET_ATS_Session *session,
475 enum GNUNET_TRANSPORT_SessionState state) 466 enum GNUNET_TRANSPORT_SessionState state)
476{ 467{
477 struct GNUNET_TRANSPORT_SessionInfo info; 468 struct GNUNET_TRANSPORT_SessionInfo info;
478 469
479 if (NULL == plugin->sic) 470 if (NULL == plugin->sic)
480 return; 471 return;
481 memset (&info, 0, sizeof (info)); 472 memset(&info, 0, sizeof(info));
482 info.state = state; 473 info.state = state;
483 info.is_inbound = GNUNET_YES; 474 info.is_inbound = GNUNET_YES;
484 info.num_msg_pending = session->msgs_in_queue; 475 info.num_msg_pending = session->msgs_in_queue;
@@ -486,9 +477,9 @@ notify_session_monitor (struct HTTP_Server_Plugin *plugin,
486 info.receive_delay = session->next_receive; 477 info.receive_delay = session->next_receive;
487 info.session_timeout = session->timeout; 478 info.session_timeout = session->timeout;
488 info.address = session->address; 479 info.address = session->address;
489 plugin->sic (plugin->sic_cls, 480 plugin->sic(plugin->sic_cls,
490 session, 481 session,
491 &info); 482 &info);
492} 483}
493 484
494 485
@@ -498,16 +489,16 @@ notify_session_monitor (struct HTTP_Server_Plugin *plugin,
498 * @param cls the session 489 * @param cls the session
499 */ 490 */
500static void 491static void
501server_wake_up (void *cls) 492server_wake_up(void *cls)
502{ 493{
503 struct GNUNET_ATS_Session *s = cls; 494 struct GNUNET_ATS_Session *s = cls;
504 495
505 s->recv_wakeup_task = NULL; 496 s->recv_wakeup_task = NULL;
506 LOG (GNUNET_ERROR_TYPE_DEBUG, 497 LOG(GNUNET_ERROR_TYPE_DEBUG,
507 "Session %p: Waking up PUT handle\n", 498 "Session %p: Waking up PUT handle\n",
508 s); 499 s);
509 GNUNET_assert (s->server_recv->suspended); 500 GNUNET_assert(s->server_recv->suspended);
510 MHD_resume_connection (s->server_recv->mhd_conn); 501 MHD_resume_connection(s->server_recv->mhd_conn);
511 s->server_recv->suspended = false; 502 s->server_recv->suspended = false;
512} 503}
513 504
@@ -521,9 +512,9 @@ server_wake_up (void *cls)
521 * until timeout 512 * until timeout
522 */ 513 */
523static void 514static void
524server_reschedule (struct HTTP_Server_Plugin *plugin, 515server_reschedule(struct HTTP_Server_Plugin *plugin,
525 struct MHD_Daemon *server, 516 struct MHD_Daemon *server,
526 int now); 517 int now);
527 518
528 519
529/** 520/**
@@ -532,106 +523,106 @@ server_reschedule (struct HTTP_Server_Plugin *plugin,
532 * @param s the session to delete 523 * @param s the session to delete
533 */ 524 */
534static void 525static void
535server_delete_session (struct GNUNET_ATS_Session *s) 526server_delete_session(struct GNUNET_ATS_Session *s)
536{ 527{
537 struct HTTP_Server_Plugin *plugin = s->plugin; 528 struct HTTP_Server_Plugin *plugin = s->plugin;
538 struct HTTP_Message *msg; 529 struct HTTP_Message *msg;
539 530
540 if (NULL != s->timeout_task) 531 if (NULL != s->timeout_task)
541 { 532 {
542 GNUNET_SCHEDULER_cancel (s->timeout_task); 533 GNUNET_SCHEDULER_cancel(s->timeout_task);
543 s->timeout_task = NULL; 534 s->timeout_task = NULL;
544 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 535 s->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
545 } 536 }
546 if (NULL != s->recv_wakeup_task) 537 if (NULL != s->recv_wakeup_task)
547 { 538 {
548 GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); 539 GNUNET_SCHEDULER_cancel(s->recv_wakeup_task);
549 s->recv_wakeup_task = NULL; 540 s->recv_wakeup_task = NULL;
550 if (NULL != s->server_recv) 541 if (NULL != s->server_recv)
551 { 542 {
552 GNUNET_assert (s->server_recv->suspended); 543 GNUNET_assert(s->server_recv->suspended);
553 s->server_recv->suspended = false; 544 s->server_recv->suspended = false;
554 MHD_resume_connection (s->server_recv->mhd_conn); 545 MHD_resume_connection(s->server_recv->mhd_conn);
555 } 546 }
556 } 547 }
557 GNUNET_assert (GNUNET_OK == 548 GNUNET_assert(GNUNET_OK ==
558 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, 549 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions,
559 &s->target, 550 &s->target,
560 s)); 551 s));
561 while (NULL != (msg = s->msg_head)) 552 while (NULL != (msg = s->msg_head))
562 { 553 {
563 GNUNET_CONTAINER_DLL_remove (s->msg_head, 554 GNUNET_CONTAINER_DLL_remove(s->msg_head,
564 s->msg_tail, 555 s->msg_tail,
565 msg); 556 msg);
566 if (NULL != msg->transmit_cont) 557 if (NULL != msg->transmit_cont)
567 msg->transmit_cont (msg->transmit_cont_cls, 558 msg->transmit_cont(msg->transmit_cont_cls,
568 &s->target, 559 &s->target,
569 GNUNET_SYSERR, 560 GNUNET_SYSERR,
570 msg->size, 561 msg->size,
571 msg->pos + msg->overhead); 562 msg->pos + msg->overhead);
572 GNUNET_assert (s->msgs_in_queue > 0); 563 GNUNET_assert(s->msgs_in_queue > 0);
573 s->msgs_in_queue--; 564 s->msgs_in_queue--;
574 GNUNET_assert (s->bytes_in_queue >= msg->size); 565 GNUNET_assert(s->bytes_in_queue >= msg->size);
575 s->bytes_in_queue -= msg->size; 566 s->bytes_in_queue -= msg->size;
576 GNUNET_free (msg); 567 GNUNET_free(msg);
577 } 568 }
578 569
579 GNUNET_assert (0 == s->msgs_in_queue); 570 GNUNET_assert(0 == s->msgs_in_queue);
580 GNUNET_assert (0 == s->bytes_in_queue); 571 GNUNET_assert(0 == s->bytes_in_queue);
581 572
582 if (NULL != s->server_send) 573 if (NULL != s->server_send)
583 { 574 {
584 LOG (GNUNET_ERROR_TYPE_DEBUG, 575 LOG(GNUNET_ERROR_TYPE_DEBUG,
585 "Server: %p / %p Terminating inbound PUT session to peer `%s'\n", 576 "Server: %p / %p Terminating inbound PUT session to peer `%s'\n",
586 s, s->server_send, 577 s, s->server_send,
587 GNUNET_i2s (&s->target)); 578 GNUNET_i2s(&s->target));
588 s->server_send->session = NULL; 579 s->server_send->session = NULL;
589 MHD_set_connection_option (s->server_send->mhd_conn, 580 MHD_set_connection_option(s->server_send->mhd_conn,
590 MHD_CONNECTION_OPTION_TIMEOUT, 581 MHD_CONNECTION_OPTION_TIMEOUT,
591 1 /* 0 = no timeout, so this is MIN */); 582 1 /* 0 = no timeout, so this is MIN */);
592 if (s->server_send->suspended) 583 if (s->server_send->suspended)
593 { 584 {
594 s->server_send->suspended = false; 585 s->server_send->suspended = false;
595 MHD_resume_connection (s->server_send->mhd_conn); 586 MHD_resume_connection(s->server_send->mhd_conn);
596 } 587 }
597 server_reschedule (plugin, 588 server_reschedule(plugin,
598 s->server_send->mhd_daemon, 589 s->server_send->mhd_daemon,
599 GNUNET_YES); 590 GNUNET_YES);
600 } 591 }
601 592
602 if (NULL != s->server_recv) 593 if (NULL != s->server_recv)
603 { 594 {
604 LOG (GNUNET_ERROR_TYPE_DEBUG, 595 LOG(GNUNET_ERROR_TYPE_DEBUG,
605 "Server: %p / %p Terminating inbound GET session to peer `%s'\n", 596 "Server: %p / %p Terminating inbound GET session to peer `%s'\n",
606 s, s->server_recv, GNUNET_i2s (&s->target)); 597 s, s->server_recv, GNUNET_i2s(&s->target));
607 s->server_recv->session = NULL; 598 s->server_recv->session = NULL;
608 MHD_set_connection_option (s->server_recv->mhd_conn, 599 MHD_set_connection_option(s->server_recv->mhd_conn,
609 MHD_CONNECTION_OPTION_TIMEOUT, 600 MHD_CONNECTION_OPTION_TIMEOUT,
610 1 /* 0 = no timeout, so this is MIN */); 601 1 /* 0 = no timeout, so this is MIN */);
611 server_reschedule (plugin, 602 server_reschedule(plugin,
612 s->server_recv->mhd_daemon, 603 s->server_recv->mhd_daemon,
613 GNUNET_YES); 604 GNUNET_YES);
614 } 605 }
615 notify_session_monitor (plugin, 606 notify_session_monitor(plugin,
616 s, 607 s,
617 GNUNET_TRANSPORT_SS_DONE); 608 GNUNET_TRANSPORT_SS_DONE);
618 if (GNUNET_YES == s->known_to_service) 609 if (GNUNET_YES == s->known_to_service)
619 { 610 {
620 plugin->env->session_end (plugin->env->cls, 611 plugin->env->session_end(plugin->env->cls,
621 s->address, 612 s->address,
622 s); 613 s);
623 s->known_to_service = GNUNET_NO; 614 s->known_to_service = GNUNET_NO;
624 } 615 }
625 if (NULL != s->msg_tk) 616 if (NULL != s->msg_tk)
626 { 617 {
627 GNUNET_MST_destroy (s->msg_tk); 618 GNUNET_MST_destroy(s->msg_tk);
628 s->msg_tk = NULL; 619 s->msg_tk = NULL;
629 } 620 }
630 GNUNET_HELLO_address_free (s->address); 621 GNUNET_HELLO_address_free(s->address);
631 LOG (GNUNET_ERROR_TYPE_DEBUG, 622 LOG(GNUNET_ERROR_TYPE_DEBUG,
632 "Session %p destroyed\n", 623 "Session %p destroyed\n",
633 s); 624 s);
634 GNUNET_free (s); 625 GNUNET_free(s);
635} 626}
636 627
637 628
@@ -644,10 +635,10 @@ server_delete_session (struct GNUNET_ATS_Session *s)
644 * @return #GNUNET_OK on success 635 * @return #GNUNET_OK on success
645 */ 636 */
646static int 637static int
647http_server_plugin_disconnect_session (void *cls, 638http_server_plugin_disconnect_session(void *cls,
648 struct GNUNET_ATS_Session *s) 639 struct GNUNET_ATS_Session *s)
649{ 640{
650 server_delete_session (s); 641 server_delete_session(s);
651 return GNUNET_OK; 642 return GNUNET_OK;
652} 643}
653 644
@@ -658,31 +649,31 @@ http_server_plugin_disconnect_session (void *cls,
658 * @param cls the session 649 * @param cls the session
659 */ 650 */
660static void 651static void
661server_session_timeout (void *cls) 652server_session_timeout(void *cls)
662{ 653{
663 struct GNUNET_ATS_Session *s = cls; 654 struct GNUNET_ATS_Session *s = cls;
664 struct GNUNET_TIME_Relative left; 655 struct GNUNET_TIME_Relative left;
665 656
666 s->timeout_task = NULL; 657 s->timeout_task = NULL;
667 left = GNUNET_TIME_absolute_get_remaining (s->timeout); 658 left = GNUNET_TIME_absolute_get_remaining(s->timeout);
668 if (0 != left.rel_value_us) 659 if (0 != left.rel_value_us)
669 { 660 {
670 /* not actually our turn yet, but let's at least update 661 /* not actually our turn yet, but let's at least update
671 the monitor, it may think we're about to die ... */ 662 the monitor, it may think we're about to die ... */
672 notify_session_monitor (s->plugin, 663 notify_session_monitor(s->plugin,
673 s, 664 s,
674 GNUNET_TRANSPORT_SS_UP); 665 GNUNET_TRANSPORT_SS_UP);
675 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, 666 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left,
676 &server_session_timeout, 667 &server_session_timeout,
677 s); 668 s);
678 return; 669 return;
679 } 670 }
680 GNUNET_log (TIMEOUT_LOG, 671 GNUNET_log(TIMEOUT_LOG,
681 "Session %p was idle for %s, disconnecting\n", 672 "Session %p was idle for %s, disconnecting\n",
682 s, 673 s,
683 GNUNET_STRINGS_relative_time_to_string (HTTP_SERVER_SESSION_TIMEOUT, 674 GNUNET_STRINGS_relative_time_to_string(HTTP_SERVER_SESSION_TIMEOUT,
684 GNUNET_YES)); 675 GNUNET_YES));
685 server_delete_session (s); 676 server_delete_session(s);
686} 677}
687 678
688 679
@@ -692,10 +683,10 @@ server_session_timeout (void *cls)
692 * @param s the session 683 * @param s the session
693 */ 684 */
694static void 685static void
695server_reschedule_session_timeout (struct GNUNET_ATS_Session *s) 686server_reschedule_session_timeout(struct GNUNET_ATS_Session *s)
696{ 687{
697 GNUNET_assert (NULL != s->timeout_task); 688 GNUNET_assert(NULL != s->timeout_task);
698 s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 689 s->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
699} 690}
700 691
701 692
@@ -727,65 +718,65 @@ server_reschedule_session_timeout (struct GNUNET_ATS_Session *s)
727 * and does NOT mean that the message was not transmitted (DV) 718 * and does NOT mean that the message was not transmitted (DV)
728 */ 719 */
729static ssize_t 720static ssize_t
730http_server_plugin_send (void *cls, 721http_server_plugin_send(void *cls,
731 struct GNUNET_ATS_Session *session, 722 struct GNUNET_ATS_Session *session,
732 const char *msgbuf, 723 const char *msgbuf,
733 size_t msgbuf_size, 724 size_t msgbuf_size,
734 unsigned int priority, 725 unsigned int priority,
735 struct GNUNET_TIME_Relative to, 726 struct GNUNET_TIME_Relative to,
736 GNUNET_TRANSPORT_TransmitContinuation cont, 727 GNUNET_TRANSPORT_TransmitContinuation cont,
737 void *cont_cls) 728 void *cont_cls)
738{ 729{
739 struct HTTP_Server_Plugin *plugin = cls; 730 struct HTTP_Server_Plugin *plugin = cls;
740 struct HTTP_Message *msg; 731 struct HTTP_Message *msg;
741 ssize_t bytes_sent = 0; 732 ssize_t bytes_sent = 0;
742 char *stat_txt; 733 char *stat_txt;
743 734
744 LOG (GNUNET_ERROR_TYPE_DEBUG, 735 LOG(GNUNET_ERROR_TYPE_DEBUG,
745 "Session %p/request %p: Sending message with %u to peer `%s'\n", 736 "Session %p/request %p: Sending message with %u to peer `%s'\n",
746 session, 737 session,
747 session->server_send, 738 session->server_send,
748 msgbuf_size, 739 msgbuf_size,
749 GNUNET_i2s (&session->target)); 740 GNUNET_i2s(&session->target));
750 741
751 /* create new message and schedule */ 742 /* create new message and schedule */
752 bytes_sent = sizeof (struct HTTP_Message) + msgbuf_size; 743 bytes_sent = sizeof(struct HTTP_Message) + msgbuf_size;
753 msg = GNUNET_malloc (bytes_sent); 744 msg = GNUNET_malloc(bytes_sent);
754 msg->next = NULL; 745 msg->next = NULL;
755 msg->size = msgbuf_size; 746 msg->size = msgbuf_size;
756 msg->pos = 0; 747 msg->pos = 0;
757 msg->buf = (char *) &msg[1]; 748 msg->buf = (char *)&msg[1];
758 msg->transmit_cont = cont; 749 msg->transmit_cont = cont;
759 msg->transmit_cont_cls = cont_cls; 750 msg->transmit_cont_cls = cont_cls;
760 GNUNET_memcpy (msg->buf, 751 GNUNET_memcpy(msg->buf,
761 msgbuf, 752 msgbuf,
762 msgbuf_size); 753 msgbuf_size);
763 GNUNET_CONTAINER_DLL_insert_tail (session->msg_head, 754 GNUNET_CONTAINER_DLL_insert_tail(session->msg_head,
764 session->msg_tail, 755 session->msg_tail,
765 msg); 756 msg);
766 session->msgs_in_queue++; 757 session->msgs_in_queue++;
767 session->bytes_in_queue += msg->size; 758 session->bytes_in_queue += msg->size;
768 notify_session_monitor (plugin, 759 notify_session_monitor(plugin,
769 session, 760 session,
770 GNUNET_TRANSPORT_SS_UP); 761 GNUNET_TRANSPORT_SS_UP);
771 GNUNET_asprintf (&stat_txt, 762 GNUNET_asprintf(&stat_txt,
772 "# bytes currently in %s_server buffers", 763 "# bytes currently in %s_server buffers",
773 plugin->protocol); 764 plugin->protocol);
774 GNUNET_STATISTICS_update (plugin->env->stats, 765 GNUNET_STATISTICS_update(plugin->env->stats,
775 stat_txt, msgbuf_size, GNUNET_NO); 766 stat_txt, msgbuf_size, GNUNET_NO);
776 GNUNET_free (stat_txt); 767 GNUNET_free(stat_txt);
777 768
778 if (NULL != session->server_send) 769 if (NULL != session->server_send)
779 {
780 if (session->server_send->suspended)
781 { 770 {
782 MHD_resume_connection (session->server_send->mhd_conn); 771 if (session->server_send->suspended)
783 session->server_send->suspended = false; 772 {
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);
784 } 779 }
785 server_reschedule (session->plugin,
786 session->server_send->mhd_daemon,
787 GNUNET_YES);
788 }
789 return bytes_sent; 780 return bytes_sent;
790} 781}
791 782
@@ -799,9 +790,9 @@ http_server_plugin_send (void *cls,
799 * @return #GNUNET_OK (continue to iterate) 790 * @return #GNUNET_OK (continue to iterate)
800 */ 791 */
801static int 792static int
802destroy_session_shutdown_cb (void *cls, 793destroy_session_shutdown_cb(void *cls,
803 const struct GNUNET_PeerIdentity *peer, 794 const struct GNUNET_PeerIdentity *peer,
804 void *value) 795 void *value)
805{ 796{
806 struct GNUNET_ATS_Session *s = value; 797 struct GNUNET_ATS_Session *s = value;
807 struct ServerRequest *sc_send; 798 struct ServerRequest *sc_send;
@@ -809,7 +800,7 @@ destroy_session_shutdown_cb (void *cls,
809 800
810 sc_send = s->server_send; 801 sc_send = s->server_send;
811 sc_recv = s->server_recv; 802 sc_recv = s->server_recv;
812 server_delete_session (s); 803 server_delete_session(s);
813 if (NULL != sc_send) 804 if (NULL != sc_send)
814 sc_send->session = NULL; 805 sc_send->session = NULL;
815 if (NULL != sc_recv) 806 if (NULL != sc_recv)
@@ -828,13 +819,13 @@ destroy_session_shutdown_cb (void *cls,
828 * @return #GNUNET_OK (continue to iterate) 819 * @return #GNUNET_OK (continue to iterate)
829 */ 820 */
830static int 821static int
831destroy_session_cb (void *cls, 822destroy_session_cb(void *cls,
832 const struct GNUNET_PeerIdentity *peer, 823 const struct GNUNET_PeerIdentity *peer,
833 void *value) 824 void *value)
834{ 825{
835 struct GNUNET_ATS_Session *s = value; 826 struct GNUNET_ATS_Session *s = value;
836 827
837 server_delete_session (s); 828 server_delete_session(s);
838 return GNUNET_OK; 829 return GNUNET_OK;
839} 830}
840 831
@@ -848,18 +839,18 @@ destroy_session_cb (void *cls,
848 * @param target peer from which to disconnect 839 * @param target peer from which to disconnect
849 */ 840 */
850static void 841static void
851http_server_plugin_disconnect_peer (void *cls, 842http_server_plugin_disconnect_peer(void *cls,
852 const struct GNUNET_PeerIdentity *target) 843 const struct GNUNET_PeerIdentity *target)
853{ 844{
854 struct HTTP_Server_Plugin *plugin = cls; 845 struct HTTP_Server_Plugin *plugin = cls;
855 846
856 LOG (GNUNET_ERROR_TYPE_DEBUG, 847 LOG(GNUNET_ERROR_TYPE_DEBUG,
857 "Transport tells me to disconnect `%s'\n", 848 "Transport tells me to disconnect `%s'\n",
858 GNUNET_i2s (target)); 849 GNUNET_i2s(target));
859 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 850 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
860 target, 851 target,
861 &destroy_session_cb, 852 &destroy_session_cb,
862 plugin); 853 plugin);
863} 854}
864 855
865 856
@@ -876,9 +867,9 @@ http_server_plugin_disconnect_peer (void *cls,
876 * and transport 867 * and transport
877 */ 868 */
878static int 869static int
879http_server_plugin_address_suggested (void *cls, 870http_server_plugin_address_suggested(void *cls,
880 const void *addr, 871 const void *addr,
881 size_t addrlen) 872 size_t addrlen)
882{ 873{
883 struct HTTP_Server_Plugin *plugin = cls; 874 struct HTTP_Server_Plugin *plugin = cls;
884 struct HttpAddressWrapper *next; 875 struct HttpAddressWrapper *next;
@@ -886,26 +877,26 @@ http_server_plugin_address_suggested (void *cls,
886 const struct HttpAddress *haddr = addr; 877 const struct HttpAddress *haddr = addr;
887 878
888 if ((NULL != plugin->ext_addr) && 879 if ((NULL != plugin->ext_addr) &&
889 GNUNET_YES == (http_common_cmp_addresses (addr, addrlen, 880 GNUNET_YES == (http_common_cmp_addresses(addr, addrlen,
890 plugin->ext_addr->address, 881 plugin->ext_addr->address,
891 plugin->ext_addr->address_length))) 882 plugin->ext_addr->address_length)))
892 { 883 {
893 /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */ 884 /* Checking HTTP_OPTIONS_VERIFY_CERTIFICATE option for external hostname */
894 if ((ntohl (haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) != 885 if ((ntohl(haddr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE) !=
895 (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE)) 886 (plugin->options & HTTP_OPTIONS_VERIFY_CERTIFICATE))
896 return GNUNET_NO; /* VERIFY option not set as required! */ 887 return GNUNET_NO; /* VERIFY option not set as required! */
897 return GNUNET_OK;
898 }
899 next = plugin->addr_head;
900 while (NULL != (pos = next))
901 {
902 next = pos->next;
903 if (GNUNET_YES == (http_common_cmp_addresses(addr,
904 addrlen,
905 pos->address,
906 pos->addrlen)))
907 return GNUNET_OK; 888 return GNUNET_OK;
908 } 889 }
890 next = plugin->addr_head;
891 while (NULL != (pos = next))
892 {
893 next = pos->next;
894 if (GNUNET_YES == (http_common_cmp_addresses(addr,
895 addrlen,
896 pos->address,
897 pos->addrlen)))
898 return GNUNET_OK;
899 }
909 return GNUNET_NO; 900 return GNUNET_NO;
910} 901}
911 902
@@ -921,8 +912,8 @@ http_server_plugin_address_suggested (void *cls,
921 * @return always NULL 912 * @return always NULL
922 */ 913 */
923static struct GNUNET_ATS_Session * 914static struct GNUNET_ATS_Session *
924http_server_plugin_get_session (void *cls, 915http_server_plugin_get_session(void *cls,
925 const struct GNUNET_HELLO_Address *address) 916 const struct GNUNET_HELLO_Address *address)
926{ 917{
927 return NULL; 918 return NULL;
928} 919}
@@ -935,14 +926,14 @@ http_server_plugin_get_session (void *cls,
935 * @param cls plugin as closure 926 * @param cls plugin as closure
936 */ 927 */
937static void 928static void
938server_v4_run (void *cls) 929server_v4_run(void *cls)
939{ 930{
940 struct HTTP_Server_Plugin *plugin = cls; 931 struct HTTP_Server_Plugin *plugin = cls;
941 932
942 plugin->server_v4_task = NULL; 933 plugin->server_v4_task = NULL;
943 plugin->server_v4_immediately = GNUNET_NO; 934 plugin->server_v4_immediately = GNUNET_NO;
944 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v4)); 935 GNUNET_assert(MHD_YES == MHD_run(plugin->server_v4));
945 server_reschedule (plugin, plugin->server_v4, GNUNET_NO); 936 server_reschedule(plugin, plugin->server_v4, GNUNET_NO);
946} 937}
947 938
948 939
@@ -953,14 +944,14 @@ server_v4_run (void *cls)
953 * @param cls plugin as closure 944 * @param cls plugin as closure
954 */ 945 */
955static void 946static void
956server_v6_run (void *cls) 947server_v6_run(void *cls)
957{ 948{
958 struct HTTP_Server_Plugin *plugin = cls; 949 struct HTTP_Server_Plugin *plugin = cls;
959 950
960 plugin->server_v6_task = NULL; 951 plugin->server_v6_task = NULL;
961 plugin->server_v6_immediately = GNUNET_NO; 952 plugin->server_v6_immediately = GNUNET_NO;
962 GNUNET_assert (MHD_YES == MHD_run (plugin->server_v6)); 953 GNUNET_assert(MHD_YES == MHD_run(plugin->server_v6));
963 server_reschedule (plugin, plugin->server_v6, GNUNET_NO); 954 server_reschedule(plugin, plugin->server_v6, GNUNET_NO);
964} 955}
965 956
966 957
@@ -974,9 +965,9 @@ server_v6_run (void *cls)
974 * @return gnunet task identifier 965 * @return gnunet task identifier
975 */ 966 */
976static struct GNUNET_SCHEDULER_Task * 967static struct GNUNET_SCHEDULER_Task *
977server_schedule (struct HTTP_Server_Plugin *plugin, 968server_schedule(struct HTTP_Server_Plugin *plugin,
978 struct MHD_Daemon *daemon_handle, 969 struct MHD_Daemon *daemon_handle,
979 int now) 970 int now)
980{ 971{
981 struct GNUNET_SCHEDULER_Task * ret; 972 struct GNUNET_SCHEDULER_Task * ret;
982 fd_set rs; 973 fd_set rs;
@@ -994,76 +985,76 @@ server_schedule (struct HTTP_Server_Plugin *plugin,
994 return NULL; 985 return NULL;
995 986
996 ret = NULL; 987 ret = NULL;
997 FD_ZERO (&rs); 988 FD_ZERO(&rs);
998 FD_ZERO (&ws); 989 FD_ZERO(&ws);
999 FD_ZERO (&es); 990 FD_ZERO(&es);
1000 wrs = GNUNET_NETWORK_fdset_create (); 991 wrs = GNUNET_NETWORK_fdset_create();
1001 wws = GNUNET_NETWORK_fdset_create (); 992 wws = GNUNET_NETWORK_fdset_create();
1002 max = -1; 993 max = -1;
1003 GNUNET_assert (MHD_YES == 994 GNUNET_assert(MHD_YES ==
1004 MHD_get_fdset (daemon_handle, 995 MHD_get_fdset(daemon_handle,
1005 &rs, 996 &rs,
1006 &ws, 997 &ws,
1007 &es, 998 &es,
1008 &max)); 999 &max));
1009 haveto = MHD_get_timeout (daemon_handle, &timeout); 1000 haveto = MHD_get_timeout(daemon_handle, &timeout);
1010 if (haveto == MHD_YES) 1001 if (haveto == MHD_YES)
1011 { 1002 {
1012 if (timeout != last_timeout) 1003 if (timeout != last_timeout)
1013 { 1004 {
1014 LOG (GNUNET_ERROR_TYPE_DEBUG, 1005 LOG(GNUNET_ERROR_TYPE_DEBUG,
1015 "SELECT Timeout changed from %llu to %llu (ms)\n", 1006 "SELECT Timeout changed from %llu to %llu (ms)\n",
1016 last_timeout, timeout); 1007 last_timeout, timeout);
1017 last_timeout = timeout; 1008 last_timeout = timeout;
1018 } 1009 }
1019 if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL) 1010 if (timeout <= GNUNET_TIME_UNIT_SECONDS.rel_value_us / 1000LL)
1020 tv.rel_value_us = (uint64_t) timeout * 1000LL; 1011 tv.rel_value_us = (uint64_t)timeout * 1000LL;
1021 else 1012 else
1022 tv = GNUNET_TIME_UNIT_SECONDS; 1013 tv = GNUNET_TIME_UNIT_SECONDS;
1023 } 1014 }
1024 else 1015 else
1025 tv = GNUNET_TIME_UNIT_SECONDS; 1016 tv = GNUNET_TIME_UNIT_SECONDS;
1026 /* Force immediate run, since we have outbound data to send */ 1017 /* Force immediate run, since we have outbound data to send */
1027 if (now == GNUNET_YES) 1018 if (now == GNUNET_YES)
1028 tv = GNUNET_TIME_UNIT_MILLISECONDS; 1019 tv = GNUNET_TIME_UNIT_MILLISECONDS;
1029 GNUNET_NETWORK_fdset_copy_native (wrs, &rs, max + 1); 1020 GNUNET_NETWORK_fdset_copy_native(wrs, &rs, max + 1);
1030 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 1021 GNUNET_NETWORK_fdset_copy_native(wws, &ws, max + 1);
1031 1022
1032 if (daemon_handle == plugin->server_v4) 1023 if (daemon_handle == plugin->server_v4)
1033 {
1034 if (plugin->server_v4_task != NULL)
1035 { 1024 {
1036 GNUNET_SCHEDULER_cancel (plugin->server_v4_task); 1025 if (plugin->server_v4_task != NULL)
1037 plugin->server_v4_task = NULL; 1026 {
1038 } 1027 GNUNET_SCHEDULER_cancel(plugin->server_v4_task);
1028 plugin->server_v4_task = NULL;
1029 }
1039#if 0 1030#if 0
1040 LOG (GNUNET_ERROR_TYPE_DEBUG, 1031 LOG(GNUNET_ERROR_TYPE_DEBUG,
1041 "Scheduling IPv4 server task in %llu ms\n", 1032 "Scheduling IPv4 server task in %llu ms\n",
1042 tv); 1033 tv);
1043#endif 1034#endif
1044 ret = 1035 ret =
1045 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1036 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1046 tv, wrs, wws, 1037 tv, wrs, wws,
1047 &server_v4_run, plugin); 1038 &server_v4_run, plugin);
1048 } 1039 }
1049 if (daemon_handle == plugin->server_v6) 1040 if (daemon_handle == plugin->server_v6)
1050 {
1051 if (plugin->server_v6_task != NULL)
1052 { 1041 {
1053 GNUNET_SCHEDULER_cancel (plugin->server_v6_task); 1042 if (plugin->server_v6_task != NULL)
1054 plugin->server_v6_task = NULL; 1043 {
1055 } 1044 GNUNET_SCHEDULER_cancel(plugin->server_v6_task);
1045 plugin->server_v6_task = NULL;
1046 }
1056#if 0 1047#if 0
1057 LOG (GNUNET_ERROR_TYPE_DEBUG, 1048 LOG(GNUNET_ERROR_TYPE_DEBUG,
1058 "Scheduling IPv6 server task in %llu ms\n", tv); 1049 "Scheduling IPv6 server task in %llu ms\n", tv);
1059#endif 1050#endif
1060 ret = 1051 ret =
1061 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1052 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1062 tv, wrs, wws, 1053 tv, wrs, wws,
1063 &server_v6_run, plugin); 1054 &server_v6_run, plugin);
1064 } 1055 }
1065 GNUNET_NETWORK_fdset_destroy (wrs); 1056 GNUNET_NETWORK_fdset_destroy(wrs);
1066 GNUNET_NETWORK_fdset_destroy (wws); 1057 GNUNET_NETWORK_fdset_destroy(wws);
1067 return ret; 1058 return ret;
1068} 1059}
1069 1060
@@ -1077,41 +1068,41 @@ server_schedule (struct HTTP_Server_Plugin *plugin,
1077 * until timeout 1068 * until timeout
1078 */ 1069 */
1079static void 1070static void
1080server_reschedule (struct HTTP_Server_Plugin *plugin, 1071server_reschedule(struct HTTP_Server_Plugin *plugin,
1081 struct MHD_Daemon *server, 1072 struct MHD_Daemon *server,
1082 int now) 1073 int now)
1083{ 1074{
1084 if ((server == plugin->server_v4) && (plugin->server_v4 != NULL)) 1075 if ((server == plugin->server_v4) && (plugin->server_v4 != NULL))
1085 { 1076 {
1086 if (GNUNET_YES == plugin->server_v4_immediately) 1077 if (GNUNET_YES == plugin->server_v4_immediately)
1087 return; /* No rescheduling, server will run asap */ 1078 return; /* No rescheduling, server will run asap */
1088 1079
1089 if (GNUNET_YES == now) 1080 if (GNUNET_YES == now)
1090 plugin->server_v4_immediately = GNUNET_YES; 1081 plugin->server_v4_immediately = GNUNET_YES;
1091 1082
1092 if (plugin->server_v4_task != NULL) 1083 if (plugin->server_v4_task != NULL)
1093 { 1084 {
1094 GNUNET_SCHEDULER_cancel (plugin->server_v4_task); 1085 GNUNET_SCHEDULER_cancel(plugin->server_v4_task);
1095 plugin->server_v4_task = NULL; 1086 plugin->server_v4_task = NULL;
1087 }
1088 plugin->server_v4_task = server_schedule(plugin, plugin->server_v4, now);
1096 } 1089 }
1097 plugin->server_v4_task = server_schedule (plugin, plugin->server_v4, now);
1098 }
1099 1090
1100 if ((server == plugin->server_v6) && (plugin->server_v6 != NULL)) 1091 if ((server == plugin->server_v6) && (plugin->server_v6 != NULL))
1101 { 1092 {
1102 if (GNUNET_YES == plugin->server_v6_immediately) 1093 if (GNUNET_YES == plugin->server_v6_immediately)
1103 return; /* No rescheduling, server will run asap */ 1094 return; /* No rescheduling, server will run asap */
1104 1095
1105 if (GNUNET_YES == now) 1096 if (GNUNET_YES == now)
1106 plugin->server_v6_immediately = GNUNET_YES; 1097 plugin->server_v6_immediately = GNUNET_YES;
1107 1098
1108 if (plugin->server_v6_task != NULL) 1099 if (plugin->server_v6_task != NULL)
1109 { 1100 {
1110 GNUNET_SCHEDULER_cancel (plugin->server_v6_task); 1101 GNUNET_SCHEDULER_cancel(plugin->server_v6_task);
1111 plugin->server_v6_task = NULL; 1102 plugin->server_v6_task = NULL;
1103 }
1104 plugin->server_v6_task = server_schedule(plugin, plugin->server_v6, now);
1112 } 1105 }
1113 plugin->server_v6_task = server_schedule (plugin, plugin->server_v6, now);
1114 }
1115} 1106}
1116 1107
1117 1108
@@ -1124,7 +1115,7 @@ server_reschedule (struct HTTP_Server_Plugin *plugin,
1124 * @return keepalive factor 1115 * @return keepalive factor
1125 */ 1116 */
1126static unsigned int 1117static unsigned int
1127http_server_query_keepalive_factor (void *cls) 1118http_server_query_keepalive_factor(void *cls)
1128{ 1119{
1129 return 3; 1120 return 3;
1130} 1121}
@@ -1140,11 +1131,11 @@ http_server_query_keepalive_factor (void *cls)
1140 * @param session which session is being updated 1131 * @param session which session is being updated
1141 */ 1132 */
1142static void 1133static void
1143http_server_plugin_update_session_timeout (void *cls, 1134http_server_plugin_update_session_timeout(void *cls,
1144 const struct GNUNET_PeerIdentity *peer, 1135 const struct GNUNET_PeerIdentity *peer,
1145 struct GNUNET_ATS_Session *session) 1136 struct GNUNET_ATS_Session *session)
1146{ 1137{
1147 server_reschedule_session_timeout (session); 1138 server_reschedule_session_timeout(session);
1148} 1139}
1149 1140
1150 1141
@@ -1156,31 +1147,31 @@ http_server_plugin_update_session_timeout (void *cls,
1156 * @param to timeout in seconds 1147 * @param to timeout in seconds
1157 */ 1148 */
1158static void 1149static void
1159server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin, 1150server_mhd_connection_timeout(struct HTTP_Server_Plugin *plugin,
1160 struct GNUNET_ATS_Session *s, 1151 struct GNUNET_ATS_Session *s,
1161 unsigned int to) 1152 unsigned int to)
1162{ 1153{
1163 /* Setting timeouts for other connections */ 1154 /* Setting timeouts for other connections */
1164 if (NULL != s->server_recv) 1155 if (NULL != s->server_recv)
1165 { 1156 {
1166 LOG (GNUNET_ERROR_TYPE_DEBUG, 1157 LOG(GNUNET_ERROR_TYPE_DEBUG,
1167 "Setting timeout for %p to %u sec.\n", 1158 "Setting timeout for %p to %u sec.\n",
1168 s->server_recv, to); 1159 s->server_recv, to);
1169 MHD_set_connection_option (s->server_recv->mhd_conn, 1160 MHD_set_connection_option(s->server_recv->mhd_conn,
1170 MHD_CONNECTION_OPTION_TIMEOUT, 1161 MHD_CONNECTION_OPTION_TIMEOUT,
1171 to); 1162 to);
1172 server_reschedule (plugin, s->server_recv->mhd_daemon, GNUNET_NO); 1163 server_reschedule(plugin, s->server_recv->mhd_daemon, GNUNET_NO);
1173 } 1164 }
1174 if (NULL != s->server_send) 1165 if (NULL != s->server_send)
1175 { 1166 {
1176 LOG (GNUNET_ERROR_TYPE_DEBUG, 1167 LOG(GNUNET_ERROR_TYPE_DEBUG,
1177 "Setting timeout for %p to %u sec.\n", 1168 "Setting timeout for %p to %u sec.\n",
1178 s->server_send, to); 1169 s->server_send, to);
1179 MHD_set_connection_option (s->server_send->mhd_conn, 1170 MHD_set_connection_option(s->server_send->mhd_conn,
1180 MHD_CONNECTION_OPTION_TIMEOUT, 1171 MHD_CONNECTION_OPTION_TIMEOUT,
1181 to); 1172 to);
1182 server_reschedule (plugin, s->server_send->mhd_daemon, GNUNET_NO); 1173 server_reschedule(plugin, s->server_send->mhd_daemon, GNUNET_NO);
1183 } 1174 }
1184} 1175}
1185 1176
1186 1177
@@ -1195,11 +1186,11 @@ server_mhd_connection_timeout (struct HTTP_Server_Plugin *plugin,
1195 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1186 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1196 */ 1187 */
1197static int 1188static int
1198server_parse_url (struct HTTP_Server_Plugin *plugin, 1189server_parse_url(struct HTTP_Server_Plugin *plugin,
1199 const char *url, 1190 const char *url,
1200 struct GNUNET_PeerIdentity *target, 1191 struct GNUNET_PeerIdentity *target,
1201 uint32_t *tag, 1192 uint32_t *tag,
1202 uint32_t *options) 1193 uint32_t *options)
1203{ 1194{
1204 regmatch_t matches[4]; 1195 regmatch_t matches[4];
1205 const char *tag_start; 1196 const char *tag_start;
@@ -1214,105 +1205,105 @@ server_parse_url (struct HTTP_Server_Plugin *plugin,
1214 ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$") 1205 ("^.*/([0-9A-Z]+);([0-9]+)(,[0-9]+)?$")
1215 1206
1216 if (NULL == url) 1207 if (NULL == url)
1217 { 1208 {
1218 GNUNET_break (0); 1209 GNUNET_break(0);
1219 return GNUNET_SYSERR; 1210 return GNUNET_SYSERR;
1220 } 1211 }
1221 1212
1222 if (regexec(&plugin->url_regex, url, 4, matches, 0)) 1213 if (regexec(&plugin->url_regex, url, 4, matches, 0))
1223 { 1214 {
1224 LOG (GNUNET_ERROR_TYPE_DEBUG, 1215 LOG(GNUNET_ERROR_TYPE_DEBUG,
1225 "URL `%s' did not match regex\n", url); 1216 "URL `%s' did not match regex\n", url);
1226 return GNUNET_SYSERR; 1217 return GNUNET_SYSERR;
1227 } 1218 }
1228 1219
1229 target_start = &url[matches[1].rm_so]; 1220 target_start = &url[matches[1].rm_so];
1230 tag_start = &url[matches[2].rm_so]; 1221 tag_start = &url[matches[2].rm_so];
1231 1222
1232 /* convert tag */ 1223 /* convert tag */
1233 rc = strtoul (tag_start, &tag_end, 10); 1224 rc = strtoul(tag_start, &tag_end, 10);
1234 if (&url[matches[2].rm_eo] != tag_end) 1225 if (&url[matches[2].rm_eo] != tag_end)
1235 { 1226 {
1236 LOG (GNUNET_ERROR_TYPE_DEBUG, 1227 LOG(GNUNET_ERROR_TYPE_DEBUG,
1237 "URL tag did not line up with submatch\n"); 1228 "URL tag did not line up with submatch\n");
1238 return GNUNET_SYSERR; 1229 return GNUNET_SYSERR;
1239 } 1230 }
1240 if (rc == 0) 1231 if (rc == 0)
1241 { 1232 {
1242 LOG (GNUNET_ERROR_TYPE_DEBUG, 1233 LOG(GNUNET_ERROR_TYPE_DEBUG,
1243 "URL tag is zero\n"); 1234 "URL tag is zero\n");
1244 return GNUNET_SYSERR; 1235 return GNUNET_SYSERR;
1245 } 1236 }
1246 if ((rc == ULONG_MAX) && (ERANGE == errno)) 1237 if ((rc == ULONG_MAX) && (ERANGE == errno))
1247 { 1238 {
1248 LOG (GNUNET_ERROR_TYPE_DEBUG, 1239 LOG(GNUNET_ERROR_TYPE_DEBUG,
1249 "URL tag > ULONG_MAX\n"); 1240 "URL tag > ULONG_MAX\n");
1250 return GNUNET_SYSERR; 1241 return GNUNET_SYSERR;
1251 } 1242 }
1252 if (rc > UINT32_MAX) 1243 if (rc > UINT32_MAX)
1253 { 1244 {
1254 LOG (GNUNET_ERROR_TYPE_DEBUG, 1245 LOG(GNUNET_ERROR_TYPE_DEBUG,
1255 "URL tag > UINT32_MAX\n"); 1246 "URL tag > UINT32_MAX\n");
1256 return GNUNET_SYSERR; 1247 return GNUNET_SYSERR;
1257 } 1248 }
1258 (*tag) = (uint32_t)rc; 1249 (*tag) = (uint32_t)rc;
1259 LOG (GNUNET_ERROR_TYPE_DEBUG, 1250 LOG(GNUNET_ERROR_TYPE_DEBUG,
1260 "Found tag `%u' in url\n", 1251 "Found tag `%u' in url\n",
1261 *tag); 1252 *tag);
1262 1253
1263 /* convert peer id */ 1254 /* convert peer id */
1264 hash_length = matches[1].rm_eo - matches[1].rm_so; 1255 hash_length = matches[1].rm_eo - matches[1].rm_so;
1265 if (hash_length != plugin->peer_id_length) 1256 if (hash_length != plugin->peer_id_length)
1266 {
1267 LOG (GNUNET_ERROR_TYPE_DEBUG,
1268 "URL target is %u bytes, expecting %u\n",
1269 hash_length, plugin->peer_id_length);
1270 return GNUNET_SYSERR;
1271 }
1272 if (GNUNET_OK !=
1273 GNUNET_CRYPTO_eddsa_public_key_from_string (target_start,
1274 hash_length,
1275 &target->public_key))
1276 {
1277 LOG (GNUNET_ERROR_TYPE_DEBUG,
1278 "URL target conversion failed\n");
1279 return GNUNET_SYSERR;
1280 }
1281 LOG (GNUNET_ERROR_TYPE_DEBUG,
1282 "Found target `%s' in URL\n",
1283 GNUNET_i2s_full (target));
1284
1285 /* convert options */
1286 if (-1 == matches[3].rm_so)
1287 {
1288 *options = 0;
1289 }
1290 else
1291 {
1292 rc = strtoul (&url[matches[3].rm_so + 1], &options_end, 10);
1293 if (&url[matches[3].rm_eo] != options_end)
1294 { 1257 {
1295 LOG (GNUNET_ERROR_TYPE_DEBUG, 1258 LOG(GNUNET_ERROR_TYPE_DEBUG,
1296 "URL options did not line up with submatch\n"); 1259 "URL target is %u bytes, expecting %u\n",
1260 hash_length, plugin->peer_id_length);
1297 return GNUNET_SYSERR; 1261 return GNUNET_SYSERR;
1298 } 1262 }
1299 if ((rc == ULONG_MAX) && (ERANGE == errno)) 1263 if (GNUNET_OK !=
1264 GNUNET_CRYPTO_eddsa_public_key_from_string(target_start,
1265 hash_length,
1266 &target->public_key))
1300 { 1267 {
1301 LOG (GNUNET_ERROR_TYPE_DEBUG, 1268 LOG(GNUNET_ERROR_TYPE_DEBUG,
1302 "URL options > ULONG_MAX\n"); 1269 "URL target conversion failed\n");
1303 return GNUNET_SYSERR; 1270 return GNUNET_SYSERR;
1304 } 1271 }
1305 if (rc > UINT32_MAX) 1272 LOG(GNUNET_ERROR_TYPE_DEBUG,
1273 "Found target `%s' in URL\n",
1274 GNUNET_i2s_full(target));
1275
1276 /* convert options */
1277 if (-1 == matches[3].rm_so)
1306 { 1278 {
1307 LOG (GNUNET_ERROR_TYPE_DEBUG, 1279 *options = 0;
1308 "URL options > UINT32_MAX\n"); 1280 }
1309 return GNUNET_SYSERR; 1281 else
1282 {
1283 rc = strtoul(&url[matches[3].rm_so + 1], &options_end, 10);
1284 if (&url[matches[3].rm_eo] != options_end)
1285 {
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);
1310 } 1306 }
1311 (*options) = (uint32_t) rc;
1312 LOG (GNUNET_ERROR_TYPE_DEBUG,
1313 "Found options `%u' in url\n",
1314 *options);
1315 }
1316 return GNUNET_OK; 1307 return GNUNET_OK;
1317} 1308}
1318 1309
@@ -1320,8 +1311,7 @@ server_parse_url (struct HTTP_Server_Plugin *plugin,
1320/** 1311/**
1321 * Closure for #session_tag_it(). 1312 * Closure for #session_tag_it().
1322 */ 1313 */
1323struct GNUNET_ATS_SessionTagContext 1314struct GNUNET_ATS_SessionTagContext {
1324{
1325 /** 1315 /**
1326 * Set to session matching the tag. 1316 * Set to session matching the tag.
1327 */ 1317 */
@@ -1343,18 +1333,18 @@ struct GNUNET_ATS_SessionTagContext
1343 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not 1333 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not
1344 */ 1334 */
1345static int 1335static int
1346session_tag_it (void *cls, 1336session_tag_it(void *cls,
1347 const struct GNUNET_PeerIdentity *key, 1337 const struct GNUNET_PeerIdentity *key,
1348 void *value) 1338 void *value)
1349{ 1339{
1350 struct GNUNET_ATS_SessionTagContext *stc = cls; 1340 struct GNUNET_ATS_SessionTagContext *stc = cls;
1351 struct GNUNET_ATS_Session *s = value; 1341 struct GNUNET_ATS_Session *s = value;
1352 1342
1353 if (s->tag == stc->tag) 1343 if (s->tag == stc->tag)
1354 { 1344 {
1355 stc->res = s; 1345 stc->res = s;
1356 return GNUNET_NO; 1346 return GNUNET_NO;
1357 } 1347 }
1358 return GNUNET_YES; 1348 return GNUNET_YES;
1359} 1349}
1360 1350
@@ -1369,10 +1359,10 @@ session_tag_it (void *cls,
1369 * @return the server connecetion 1359 * @return the server connecetion
1370 */ 1360 */
1371static struct ServerRequest * 1361static struct ServerRequest *
1372server_lookup_connection (struct HTTP_Server_Plugin *plugin, 1362server_lookup_connection(struct HTTP_Server_Plugin *plugin,
1373 struct MHD_Connection *mhd_connection, 1363 struct MHD_Connection *mhd_connection,
1374 const char *url, 1364 const char *url,
1375 const char *method) 1365 const char *method)
1376{ 1366{
1377 struct GNUNET_ATS_Session *s = NULL; 1367 struct GNUNET_ATS_Session *s = NULL;
1378 struct ServerRequest *sc = NULL; 1368 struct ServerRequest *sc = NULL;
@@ -1386,129 +1376,131 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1386 unsigned int to; 1376 unsigned int to;
1387 enum GNUNET_NetworkType scope; 1377 enum GNUNET_NetworkType scope;
1388 1378
1389 conn_info = MHD_get_connection_info (mhd_connection, 1379 conn_info = MHD_get_connection_info(mhd_connection,
1390 MHD_CONNECTION_INFO_CLIENT_ADDRESS); 1380 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
1391 if ((conn_info->client_addr->sa_family != AF_INET) && 1381 if ((conn_info->client_addr->sa_family != AF_INET) &&
1392 (conn_info->client_addr->sa_family != AF_INET6)) 1382 (conn_info->client_addr->sa_family != AF_INET6))
1393 return NULL; 1383 return NULL;
1394 LOG (GNUNET_ERROR_TYPE_DEBUG, 1384 LOG(GNUNET_ERROR_TYPE_DEBUG,
1395 "New %s request from %s\n", 1385 "New %s request from %s\n",
1396 method, 1386 method,
1397 url); 1387 url);
1398 stc.tag = 0; 1388 stc.tag = 0;
1399 options = 0; /* make gcc happy */ 1389 options = 0; /* make gcc happy */
1400 if (GNUNET_SYSERR == 1390 if (GNUNET_SYSERR ==
1401 server_parse_url (plugin, url, &target, &stc.tag, &options)) 1391 server_parse_url(plugin, url, &target, &stc.tag, &options))
1402 { 1392 {
1403 LOG (GNUNET_ERROR_TYPE_DEBUG, 1393 LOG(GNUNET_ERROR_TYPE_DEBUG,
1404 "Invalid url %s\n", url); 1394 "Invalid url %s\n", url);
1405 return NULL; 1395 return NULL;
1406 } 1396 }
1407 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) 1397 if (0 == strcmp(MHD_HTTP_METHOD_PUT, method))
1408 direction = _RECEIVE; 1398 direction = _RECEIVE;
1409 else if (0 == strcmp (MHD_HTTP_METHOD_GET, method)) 1399 else if (0 == strcmp(MHD_HTTP_METHOD_GET, method))
1410 direction = _SEND; 1400 direction = _SEND;
1411 else 1401 else
1412 { 1402 {
1413 LOG (GNUNET_ERROR_TYPE_DEBUG, 1403 LOG(GNUNET_ERROR_TYPE_DEBUG,
1414 "Invalid method %s for request from %s\n", 1404 "Invalid method %s for request from %s\n",
1415 method, url); 1405 method, url);
1416 return NULL; 1406 return NULL;
1417 } 1407 }
1418 1408
1419 plugin->cur_request++; 1409 plugin->cur_request++;
1420 LOG (GNUNET_ERROR_TYPE_DEBUG, 1410 LOG(GNUNET_ERROR_TYPE_DEBUG,
1421 "New %s request from %s with tag %u (%u of %u)\n", 1411 "New %s request from %s with tag %u (%u of %u)\n",
1422 method, 1412 method,
1423 GNUNET_i2s (&target), 1413 GNUNET_i2s(&target),
1424 stc.tag, 1414 stc.tag,
1425 plugin->cur_request, plugin->max_request); 1415 plugin->cur_request, plugin->max_request);
1426 /* find existing session */ 1416 /* find existing session */
1427 stc.res = NULL; 1417 stc.res = NULL;
1428 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 1418 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
1429 &target, 1419 &target,
1430 &session_tag_it, 1420 &session_tag_it,
1431 &stc); 1421 &stc);
1432 if (NULL == (s = stc.res)) 1422 if (NULL == (s = stc.res))
1433 { 1423 {
1434 /* create new session */ 1424 /* create new session */
1435 addr = NULL; 1425 addr = NULL;
1436 switch (conn_info->client_addr->sa_family) 1426 switch (conn_info->client_addr->sa_family)
1437 { 1427 {
1438 case (AF_INET): 1428 case (AF_INET):
1439 addr = http_common_address_from_socket (plugin->protocol, 1429 addr = http_common_address_from_socket(plugin->protocol,
1440 conn_info->client_addr, 1430 conn_info->client_addr,
1441 sizeof (struct sockaddr_in)); 1431 sizeof(struct sockaddr_in));
1442 addr_len = http_common_address_get_size (addr); 1432 addr_len = http_common_address_get_size(addr);
1443 scope = plugin->env->get_address_type (plugin->env->cls, 1433 scope = plugin->env->get_address_type(plugin->env->cls,
1444 conn_info->client_addr, 1434 conn_info->client_addr,
1445 sizeof (struct sockaddr_in)); 1435 sizeof(struct sockaddr_in));
1446 break; 1436 break;
1447 case (AF_INET6): 1437
1448 addr = http_common_address_from_socket (plugin->protocol, 1438 case (AF_INET6):
1449 conn_info->client_addr, 1439 addr = http_common_address_from_socket(plugin->protocol,
1450 sizeof (struct sockaddr_in6)); 1440 conn_info->client_addr,
1451 addr_len = http_common_address_get_size (addr); 1441 sizeof(struct sockaddr_in6));
1452 scope = plugin->env->get_address_type (plugin->env->cls, 1442 addr_len = http_common_address_get_size(addr);
1453 conn_info->client_addr, 1443 scope = plugin->env->get_address_type(plugin->env->cls,
1454 sizeof (struct sockaddr_in6)); 1444 conn_info->client_addr,
1455 break; 1445 sizeof(struct sockaddr_in6));
1456 default: 1446 break;
1457 /* external host name */ 1447
1458 return NULL; 1448 default:
1459 } 1449 /* external host name */
1460 s = GNUNET_new (struct GNUNET_ATS_Session); 1450 return NULL;
1461 s->target = target; 1451 }
1462 s->plugin = plugin; 1452 s = GNUNET_new(struct GNUNET_ATS_Session);
1463 s->scope = scope; 1453 s->target = target;
1464 s->address = GNUNET_HELLO_address_allocate (&s->target, 1454 s->plugin = plugin;
1465 PLUGIN_NAME, 1455 s->scope = scope;
1466 addr, 1456 s->address = GNUNET_HELLO_address_allocate(&s->target,
1467 addr_len, 1457 PLUGIN_NAME,
1468 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 1458 addr,
1469 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS; 1459 addr_len,
1470 s->tag = stc.tag; 1460 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1471 s->timeout = GNUNET_TIME_relative_to_absolute (HTTP_SERVER_SESSION_TIMEOUT); 1461 s->next_receive = GNUNET_TIME_UNIT_ZERO_ABS;
1472 s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_SERVER_SESSION_TIMEOUT, 1462 s->tag = stc.tag;
1473 &server_session_timeout, 1463 s->timeout = GNUNET_TIME_relative_to_absolute(HTTP_SERVER_SESSION_TIMEOUT);
1474 s); 1464 s->timeout_task = GNUNET_SCHEDULER_add_delayed(HTTP_SERVER_SESSION_TIMEOUT,
1475 (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessions, 1465 &server_session_timeout,
1466 s);
1467 (void)GNUNET_CONTAINER_multipeermap_put(plugin->sessions,
1476 &s->target, 1468 &s->target,
1477 s, 1469 s,
1478 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1470 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1479 notify_session_monitor (plugin, 1471 notify_session_monitor(plugin,
1480 s, 1472 s,
1481 GNUNET_TRANSPORT_SS_INIT); 1473 GNUNET_TRANSPORT_SS_INIT);
1482 notify_session_monitor (plugin, 1474 notify_session_monitor(plugin,
1483 s, 1475 s,
1484 GNUNET_TRANSPORT_SS_HANDSHAKE); 1476 GNUNET_TRANSPORT_SS_HANDSHAKE);
1485 LOG (GNUNET_ERROR_TYPE_DEBUG, 1477 LOG(GNUNET_ERROR_TYPE_DEBUG,
1486 "Creating new session %p for peer `%s' connecting from `%s'\n", 1478 "Creating new session %p for peer `%s' connecting from `%s'\n",
1487 s, GNUNET_i2s (&target), 1479 s, GNUNET_i2s(&target),
1488 http_common_plugin_address_to_string (plugin->protocol, 1480 http_common_plugin_address_to_string(plugin->protocol,
1489 addr, 1481 addr,
1490 addr_len)); 1482 addr_len));
1491 GNUNET_free_non_null (addr); 1483 GNUNET_free_non_null(addr);
1492 } 1484 }
1493 1485
1494 if ( (_RECEIVE == direction) && 1486 if ((_RECEIVE == direction) &&
1495 (NULL != s->server_recv) ) 1487 (NULL != s->server_recv))
1496 { 1488 {
1497 LOG (GNUNET_ERROR_TYPE_DEBUG, 1489 LOG(GNUNET_ERROR_TYPE_DEBUG,
1498 "Duplicate PUT request from `%s' tag %u, dismissing new request\n", 1490 "Duplicate PUT request from `%s' tag %u, dismissing new request\n",
1499 GNUNET_i2s (&target), 1491 GNUNET_i2s(&target),
1500 stc.tag); 1492 stc.tag);
1501 return NULL; 1493 return NULL;
1502 } 1494 }
1503 if ((_SEND == direction) && (NULL != s->server_send)) 1495 if ((_SEND == direction) && (NULL != s->server_send))
1504 { 1496 {
1505 LOG (GNUNET_ERROR_TYPE_DEBUG, 1497 LOG(GNUNET_ERROR_TYPE_DEBUG,
1506 "Duplicate GET request from `%s' tag %u, dismissing new request\n", 1498 "Duplicate GET request from `%s' tag %u, dismissing new request\n",
1507 GNUNET_i2s (&target), 1499 GNUNET_i2s(&target),
1508 stc.tag); 1500 stc.tag);
1509 return NULL; 1501 return NULL;
1510 } 1502 }
1511 sc = GNUNET_new (struct ServerRequest); 1503 sc = GNUNET_new(struct ServerRequest);
1512 if (conn_info->client_addr->sa_family == AF_INET) 1504 if (conn_info->client_addr->sa_family == AF_INET)
1513 sc->mhd_daemon = plugin->server_v4; 1505 sc->mhd_daemon = plugin->server_v4;
1514 if (conn_info->client_addr->sa_family == AF_INET6) 1506 if (conn_info->client_addr->sa_family == AF_INET6)
@@ -1519,30 +1511,30 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1519 sc->session = s; 1511 sc->session = s;
1520 sc->options = options; 1512 sc->options = options;
1521 if (direction == _SEND) 1513 if (direction == _SEND)
1522 { 1514 {
1523 s->server_send = sc; 1515 s->server_send = sc;
1524 } 1516 }
1525 if (direction == _RECEIVE) 1517 if (direction == _RECEIVE)
1526 { 1518 {
1527 s->server_recv = sc; 1519 s->server_recv = sc;
1528 } 1520 }
1529 1521
1530 if ((GNUNET_NO == s->known_to_service) && 1522 if ((GNUNET_NO == s->known_to_service) &&
1531 (NULL != s->server_send) && 1523 (NULL != s->server_send) &&
1532 (NULL != s->server_recv) ) 1524 (NULL != s->server_recv))
1533 { 1525 {
1534 s->known_to_service = GNUNET_YES; 1526 s->known_to_service = GNUNET_YES;
1535 notify_session_monitor (plugin, 1527 notify_session_monitor(plugin,
1536 s, 1528 s,
1537 GNUNET_TRANSPORT_SS_UP); 1529 GNUNET_TRANSPORT_SS_UP);
1538 plugin->env->session_start (plugin->env->cls, 1530 plugin->env->session_start(plugin->env->cls,
1539 s->address, 1531 s->address,
1540 s, 1532 s,
1541 s->scope); 1533 s->scope);
1542 } 1534 }
1543 1535
1544 to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL); 1536 to = (HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL);
1545 server_mhd_connection_timeout (plugin, s, to); 1537 server_mhd_connection_timeout(plugin, s, to);
1546 return sc; 1538 return sc;
1547} 1539}
1548 1540
@@ -1557,10 +1549,10 @@ server_lookup_connection (struct HTTP_Server_Plugin *plugin,
1557 * @return bytes written to @a buf 1549 * @return bytes written to @a buf
1558 */ 1550 */
1559static ssize_t 1551static ssize_t
1560server_send_callback (void *cls, 1552server_send_callback(void *cls,
1561 uint64_t pos, 1553 uint64_t pos,
1562 char *buf, 1554 char *buf,
1563 size_t max) 1555 size_t max)
1564{ 1556{
1565 struct ServerRequest *sc = cls; 1557 struct ServerRequest *sc = cls;
1566 struct GNUNET_ATS_Session *s = sc->session; 1558 struct GNUNET_ATS_Session *s = sc->session;
@@ -1569,79 +1561,79 @@ server_send_callback (void *cls,
1569 char *stat_txt; 1561 char *stat_txt;
1570 1562
1571 if (NULL == s) 1563 if (NULL == s)
1572 { 1564 {
1573 /* session is disconnecting */ 1565 /* session is disconnecting */
1574 return 0; 1566 return 0;
1575 } 1567 }
1576 1568
1577 sc = s->server_send; 1569 sc = s->server_send;
1578 if (NULL == sc) 1570 if (NULL == sc)
1579 return 0; 1571 return 0;
1580 msg = s->msg_head; 1572 msg = s->msg_head;
1581 if (NULL != msg) 1573 if (NULL != msg)
1582 { 1574 {
1583 /* sending */ 1575 /* sending */
1584 bytes_read = GNUNET_MIN (msg->size - msg->pos, 1576 bytes_read = GNUNET_MIN(msg->size - msg->pos,
1585 max); 1577 max);
1586 GNUNET_memcpy (buf, &msg->buf[msg->pos], bytes_read); 1578 GNUNET_memcpy(buf, &msg->buf[msg->pos], bytes_read);
1587 msg->pos += bytes_read; 1579 msg->pos += bytes_read;
1588 1580
1589 /* removing message */ 1581 /* removing message */
1590 if (msg->pos == msg->size) 1582 if (msg->pos == msg->size)
1591 { 1583 {
1592 GNUNET_CONTAINER_DLL_remove (s->msg_head, 1584 GNUNET_CONTAINER_DLL_remove(s->msg_head,
1593 s->msg_tail, 1585 s->msg_tail,
1594 msg); 1586 msg);
1595 if (NULL != msg->transmit_cont) 1587 if (NULL != msg->transmit_cont)
1596 msg->transmit_cont (msg->transmit_cont_cls, &s->target, GNUNET_OK, 1588 msg->transmit_cont(msg->transmit_cont_cls, &s->target, GNUNET_OK,
1597 msg->size, msg->size + msg->overhead); 1589 msg->size, msg->size + msg->overhead);
1598 GNUNET_assert (s->msgs_in_queue > 0); 1590 GNUNET_assert(s->msgs_in_queue > 0);
1599 s->msgs_in_queue--; 1591 s->msgs_in_queue--;
1600 GNUNET_assert (s->bytes_in_queue >= msg->size); 1592 GNUNET_assert(s->bytes_in_queue >= msg->size);
1601 s->bytes_in_queue -= msg->size; 1593 s->bytes_in_queue -= msg->size;
1602 GNUNET_free (msg); 1594 GNUNET_free(msg);
1603 notify_session_monitor (s->plugin, 1595 notify_session_monitor(s->plugin,
1604 s, 1596 s,
1605 GNUNET_TRANSPORT_SS_UPDATE); 1597 GNUNET_TRANSPORT_SS_UPDATE);
1598 }
1606 } 1599 }
1607 }
1608 if (0 < bytes_read) 1600 if (0 < bytes_read)
1609 { 1601 {
1610 sc->connected = GNUNET_YES; 1602 sc->connected = GNUNET_YES;
1611 LOG (GNUNET_ERROR_TYPE_DEBUG, 1603 LOG(GNUNET_ERROR_TYPE_DEBUG,
1612 "Sent %u bytes to peer `%s' with session %p \n", 1604 "Sent %u bytes to peer `%s' with session %p \n",
1613 bytes_read, 1605 bytes_read,
1614 GNUNET_i2s (&s->target), 1606 GNUNET_i2s(&s->target),
1615 s); 1607 s);
1616 GNUNET_asprintf (&stat_txt, 1608 GNUNET_asprintf(&stat_txt,
1617 "# bytes currently in %s_server buffers", 1609 "# bytes currently in %s_server buffers",
1618 s->plugin->protocol); 1610 s->plugin->protocol);
1619 GNUNET_STATISTICS_update (s->plugin->env->stats, 1611 GNUNET_STATISTICS_update(s->plugin->env->stats,
1620 stat_txt, 1612 stat_txt,
1621 - bytes_read, 1613 -bytes_read,
1622 GNUNET_NO); 1614 GNUNET_NO);
1623 GNUNET_free (stat_txt); 1615 GNUNET_free(stat_txt);
1624 GNUNET_asprintf (&stat_txt, 1616 GNUNET_asprintf(&stat_txt,
1625 "# bytes transmitted via %s_server", 1617 "# bytes transmitted via %s_server",
1626 s->plugin->protocol); 1618 s->plugin->protocol);
1627 GNUNET_STATISTICS_update (s->plugin->env->stats, 1619 GNUNET_STATISTICS_update(s->plugin->env->stats,
1628 stat_txt, bytes_read, GNUNET_NO); 1620 stat_txt, bytes_read, GNUNET_NO);
1629 GNUNET_free (stat_txt); 1621 GNUNET_free(stat_txt);
1630 } 1622 }
1631 else if ((sc->options & OPTION_LONG_POLL) && sc->connected) 1623 else if ((sc->options & OPTION_LONG_POLL) && sc->connected)
1632 { 1624 {
1633 LOG (GNUNET_ERROR_TYPE_DEBUG, 1625 LOG(GNUNET_ERROR_TYPE_DEBUG,
1634 "Completing GET response to peer `%s' with session %p\n", 1626 "Completing GET response to peer `%s' with session %p\n",
1635 GNUNET_i2s (&s->target), 1627 GNUNET_i2s(&s->target),
1636 s); 1628 s);
1637 return MHD_CONTENT_READER_END_OF_STREAM; 1629 return MHD_CONTENT_READER_END_OF_STREAM;
1638 } 1630 }
1639 else 1631 else
1640 { 1632 {
1641 MHD_suspend_connection (s->server_send->mhd_conn); 1633 MHD_suspend_connection(s->server_send->mhd_conn);
1642 s->server_send->suspended = true; 1634 s->server_send->suspended = true;
1643 return 0; 1635 return 0;
1644 } 1636 }
1645 return bytes_read; 1637 return bytes_read;
1646} 1638}
1647 1639
@@ -1654,8 +1646,8 @@ server_send_callback (void *cls,
1654 * @return #GNUNET_OK (all OK) 1646 * @return #GNUNET_OK (all OK)
1655 */ 1647 */
1656static int 1648static int
1657server_receive_mst_cb (void *cls, 1649server_receive_mst_cb(void *cls,
1658 const struct GNUNET_MessageHeader *message) 1650 const struct GNUNET_MessageHeader *message)
1659{ 1651{
1660 struct GNUNET_ATS_Session *s = cls; 1652 struct GNUNET_ATS_Session *s = cls;
1661 struct HTTP_Server_Plugin *plugin = s->plugin; 1653 struct HTTP_Server_Plugin *plugin = s->plugin;
@@ -1663,41 +1655,41 @@ server_receive_mst_cb (void *cls,
1663 char *stat_txt; 1655 char *stat_txt;
1664 1656
1665 if (GNUNET_NO == s->known_to_service) 1657 if (GNUNET_NO == s->known_to_service)
1666 { 1658 {
1667 s->known_to_service = GNUNET_YES; 1659 s->known_to_service = GNUNET_YES;
1668 plugin->env->session_start (plugin->env->cls, 1660 plugin->env->session_start(plugin->env->cls,
1669 s->address, 1661 s->address,
1670 s, 1662 s,
1671 s->scope); 1663 s->scope);
1672 notify_session_monitor (plugin, 1664 notify_session_monitor(plugin,
1673 s, 1665 s,
1674 GNUNET_TRANSPORT_SS_UP); 1666 GNUNET_TRANSPORT_SS_UP);
1675 } 1667 }
1676 delay = plugin->env->receive (plugin->env->cls, 1668 delay = plugin->env->receive(plugin->env->cls,
1677 s->address, 1669 s->address,
1678 s, 1670 s,
1679 message); 1671 message);
1680 GNUNET_asprintf (&stat_txt, 1672 GNUNET_asprintf(&stat_txt,
1681 "# bytes received via %s_server", 1673 "# bytes received via %s_server",
1682 plugin->protocol); 1674 plugin->protocol);
1683 GNUNET_STATISTICS_update (plugin->env->stats, 1675 GNUNET_STATISTICS_update(plugin->env->stats,
1684 stat_txt, 1676 stat_txt,
1685 ntohs (message->size), 1677 ntohs(message->size),
1686 GNUNET_NO); 1678 GNUNET_NO);
1687 GNUNET_free (stat_txt); 1679 GNUNET_free(stat_txt);
1688 s->next_receive = GNUNET_TIME_relative_to_absolute (delay); 1680 s->next_receive = GNUNET_TIME_relative_to_absolute(delay);
1689 if (delay.rel_value_us > 0) 1681 if (delay.rel_value_us > 0)
1690 { 1682 {
1691 LOG (GNUNET_ERROR_TYPE_DEBUG, 1683 LOG(GNUNET_ERROR_TYPE_DEBUG,
1692 "Peer `%s' address `%s' next read delayed for %s\n", 1684 "Peer `%s' address `%s' next read delayed for %s\n",
1693 GNUNET_i2s (&s->target), 1685 GNUNET_i2s(&s->target),
1694 http_common_plugin_address_to_string (plugin->protocol, 1686 http_common_plugin_address_to_string(plugin->protocol,
1695 s->address->address, 1687 s->address->address,
1696 s->address->address_length), 1688 s->address->address_length),
1697 GNUNET_STRINGS_relative_time_to_string (delay, 1689 GNUNET_STRINGS_relative_time_to_string(delay,
1698 GNUNET_YES)); 1690 GNUNET_YES));
1699 } 1691 }
1700 server_reschedule_session_timeout (s); 1692 server_reschedule_session_timeout(s);
1701 return GNUNET_OK; 1693 return GNUNET_OK;
1702} 1694}
1703 1695
@@ -1711,15 +1703,15 @@ server_receive_mst_cb (void *cls,
1711static void 1703static void
1712add_cors_headers(struct MHD_Response *response) 1704add_cors_headers(struct MHD_Response *response)
1713{ 1705{
1714 MHD_add_response_header (response, 1706 MHD_add_response_header(response,
1715 "Access-Control-Allow-Origin", 1707 "Access-Control-Allow-Origin",
1716 "*"); 1708 "*");
1717 MHD_add_response_header (response, 1709 MHD_add_response_header(response,
1718 "Access-Control-Allow-Methods", 1710 "Access-Control-Allow-Methods",
1719 "GET, PUT, OPTIONS"); 1711 "GET, PUT, OPTIONS");
1720 MHD_add_response_header (response, 1712 MHD_add_response_header(response,
1721 "Access-Control-Max-Age", 1713 "Access-Control-Max-Age",
1722 "86400"); 1714 "86400");
1723} 1715}
1724 1716
1725 1717
@@ -1737,14 +1729,14 @@ add_cors_headers(struct MHD_Response *response)
1737 * @return MHD_YES if connection is accepted, MHD_NO on reject 1729 * @return MHD_YES if connection is accepted, MHD_NO on reject
1738 */ 1730 */
1739static int 1731static int
1740server_access_cb (void *cls, 1732server_access_cb(void *cls,
1741 struct MHD_Connection *mhd_connection, 1733 struct MHD_Connection *mhd_connection,
1742 const char *url, 1734 const char *url,
1743 const char *method, 1735 const char *method,
1744 const char *version, 1736 const char *version,
1745 const char *upload_data, 1737 const char *upload_data,
1746 size_t *upload_data_size, 1738 size_t *upload_data_size,
1747 void **httpSessionCache) 1739 void **httpSessionCache)
1748{ 1740{
1749 struct HTTP_Server_Plugin *plugin = cls; 1741 struct HTTP_Server_Plugin *plugin = cls;
1750 struct ServerRequest *sc = *httpSessionCache; 1742 struct ServerRequest *sc = *httpSessionCache;
@@ -1752,166 +1744,166 @@ server_access_cb (void *cls,
1752 struct MHD_Response *response; 1744 struct MHD_Response *response;
1753 int res = MHD_YES; 1745 int res = MHD_YES;
1754 1746
1755 LOG (GNUNET_ERROR_TYPE_DEBUG, 1747 LOG(GNUNET_ERROR_TYPE_DEBUG,
1756 _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"), 1748 _("Access from connection %p (%u of %u) for `%s' `%s' url `%s' with upload data size %u\n"),
1757 sc, 1749 sc,
1758 plugin->cur_request, 1750 plugin->cur_request,
1759 plugin->max_request, 1751 plugin->max_request,
1760 method, 1752 method,
1761 version, 1753 version,
1762 url, 1754 url,
1763 (*upload_data_size)); 1755 (*upload_data_size));
1764 if (NULL == sc) 1756 if (NULL == sc)
1765 {
1766 /* CORS pre-flight request */
1767 if (0 == strcmp (MHD_HTTP_METHOD_OPTIONS, method))
1768 { 1757 {
1769 response = MHD_create_response_from_buffer (0, NULL, 1758 /* CORS pre-flight request */
1770 MHD_RESPMEM_PERSISTENT); 1759 if (0 == strcmp(MHD_HTTP_METHOD_OPTIONS, method))
1771 add_cors_headers(response); 1760 {
1772 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 1761 response = MHD_create_response_from_buffer(0, NULL,
1773 MHD_destroy_response (response); 1762 MHD_RESPMEM_PERSISTENT);
1774 return res; 1763 add_cors_headers(response);
1775 } 1764 res = MHD_queue_response(mhd_connection, MHD_HTTP_OK, response);
1776 /* new connection */ 1765 MHD_destroy_response(response);
1777 sc = server_lookup_connection (plugin, mhd_connection, url, method); 1766 return res;
1778 if (NULL != sc) 1767 }
1779 { 1768 /* new connection */
1780 /* attach to new / existing session */ 1769 sc = server_lookup_connection(plugin, mhd_connection, url, method);
1781 (*httpSessionCache) = sc; 1770 if (NULL != sc)
1782 } 1771 {
1783 else 1772 /* attach to new / existing session */
1784 { 1773 (*httpSessionCache) = sc;
1785 /* existing session already has matching connection, refuse */ 1774 }
1786 response = MHD_create_response_from_buffer (strlen (HTTP_ERROR_RESPONSE), 1775 else
1787 HTTP_ERROR_RESPONSE, 1776 {
1788 MHD_RESPMEM_PERSISTENT); 1777 /* existing session already has matching connection, refuse */
1789 MHD_add_response_header (response, 1778 response = MHD_create_response_from_buffer(strlen(HTTP_ERROR_RESPONSE),
1790 MHD_HTTP_HEADER_CONTENT_TYPE, 1779 HTTP_ERROR_RESPONSE,
1791 "text/html"); 1780 MHD_RESPMEM_PERSISTENT);
1792 add_cors_headers(response); 1781 MHD_add_response_header(response,
1793 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); 1782 MHD_HTTP_HEADER_CONTENT_TYPE,
1794 MHD_destroy_response (response); 1783 "text/html");
1795 return res; 1784 add_cors_headers(response);
1785 res = MHD_queue_response(mhd_connection, MHD_HTTP_NOT_FOUND, response);
1786 MHD_destroy_response(response);
1787 return res;
1788 }
1796 } 1789 }
1797 }
1798 /* 'old' connection */ 1790 /* 'old' connection */
1799 if (NULL == (s = sc->session)) 1791 if (NULL == (s = sc->session))
1800 { 1792 {
1801 /* Session was already disconnected; 1793 /* Session was already disconnected;
1802 sent HTTP/1.1: 200 OK as response */ 1794 sent HTTP/1.1: 200 OK as response */
1803 response = MHD_create_response_from_buffer (strlen ("Thank you!"), 1795 response = MHD_create_response_from_buffer(strlen("Thank you!"),
1804 "Thank you!", 1796 "Thank you!",
1805 MHD_RESPMEM_PERSISTENT); 1797 MHD_RESPMEM_PERSISTENT);
1806 add_cors_headers(response); 1798 add_cors_headers(response);
1807 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 1799 MHD_queue_response(mhd_connection, MHD_HTTP_OK, response);
1808 MHD_destroy_response (response); 1800 MHD_destroy_response(response);
1809 return MHD_YES;
1810 }
1811
1812 if (sc->direction == _SEND)
1813 {
1814 response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 32 * 1024,
1815 &server_send_callback, sc, NULL);
1816 add_cors_headers(response);
1817 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1818 MHD_destroy_response (response);
1819 return MHD_YES;
1820 }
1821 if (sc->direction == _RECEIVE)
1822 {
1823 if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO))
1824 {
1825 /* (*upload_data_size == 0) first callback when header are passed */
1826 LOG (GNUNET_ERROR_TYPE_DEBUG,
1827 "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n",
1828 s, sc,
1829 GNUNET_i2s (&s->target),
1830 http_common_plugin_address_to_string (plugin->protocol,
1831 s->address->address,
1832 s->address->address_length));
1833 sc->connected = GNUNET_YES;
1834 return MHD_YES; 1801 return MHD_YES;
1835 } 1802 }
1836 else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES)) 1803
1837 { 1804 if (sc->direction == _SEND)
1838 /* (*upload_data_size == 0) when upload is complete */ 1805 {
1839 LOG (GNUNET_ERROR_TYPE_DEBUG, 1806 response = MHD_create_response_from_callback(MHD_SIZE_UNKNOWN, 32 * 1024,
1840 "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n", 1807 &server_send_callback, sc, NULL);
1841 s, sc,
1842 GNUNET_i2s (&s->target),
1843 http_common_plugin_address_to_string (plugin->protocol,
1844 s->address->address,
1845 s->address->address_length));
1846 sc->connected = GNUNET_NO;
1847 /* Sent HTTP/1.1: 200 OK as PUT Response\ */
1848 response = MHD_create_response_from_buffer (strlen ("Thank you!"),
1849 "Thank you!",
1850 MHD_RESPMEM_PERSISTENT);
1851 add_cors_headers(response); 1808 add_cors_headers(response);
1852 MHD_queue_response (mhd_connection, MHD_HTTP_OK, response); 1809 MHD_queue_response(mhd_connection, MHD_HTTP_OK, response);
1853 MHD_destroy_response (response); 1810 MHD_destroy_response(response);
1854 return MHD_YES; 1811 return MHD_YES;
1855 } 1812 }
1856 else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES)) 1813 if (sc->direction == _RECEIVE)
1857 { 1814 {
1858 struct GNUNET_TIME_Relative delay; 1815 if ((*upload_data_size == 0) && (sc->connected == GNUNET_NO))
1859 1816 {
1860 /* (*upload_data_size > 0) for every segment received */ 1817 /* (*upload_data_size == 0) first callback when header are passed */
1861 LOG (GNUNET_ERROR_TYPE_DEBUG, 1818 LOG(GNUNET_ERROR_TYPE_DEBUG,
1862 "Session %p / Connection %p: Peer `%s' PUT on address `%s' received %u bytes\n", 1819 "Session %p / Connection %p: Peer `%s' PUT on address `%s' connected\n",
1863 s, sc, 1820 s, sc,
1864 GNUNET_i2s (&s->target), 1821 GNUNET_i2s(&s->target),
1865 http_common_plugin_address_to_string (plugin->protocol, 1822 http_common_plugin_address_to_string(plugin->protocol,
1866 s->address->address, 1823 s->address->address,
1867 s->address->address_length), 1824 s->address->address_length));
1868 *upload_data_size); 1825 sc->connected = GNUNET_YES;
1869 delay = GNUNET_TIME_absolute_get_remaining (s->next_receive); 1826 return MHD_YES;
1870 if (0 == delay.rel_value_us) 1827 }
1871 { 1828 else if ((*upload_data_size == 0) && (sc->connected == GNUNET_YES))
1872 LOG (GNUNET_ERROR_TYPE_DEBUG,
1873 "PUT with %u bytes forwarded to MST\n",
1874 *upload_data_size);
1875 if (s->msg_tk == NULL)
1876 { 1829 {
1877 s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb, 1830 /* (*upload_data_size == 0) when upload is complete */
1878 s); 1831 LOG(GNUNET_ERROR_TYPE_DEBUG,
1832 "Session %p / Connection %p: Peer `%s' PUT on address `%s' finished upload\n",
1833 s, sc,
1834 GNUNET_i2s(&s->target),
1835 http_common_plugin_address_to_string(plugin->protocol,
1836 s->address->address,
1837 s->address->address_length));
1838 sc->connected = GNUNET_NO;
1839 /* Sent HTTP/1.1: 200 OK as PUT Response\ */
1840 response = MHD_create_response_from_buffer(strlen("Thank you!"),
1841 "Thank you!",
1842 MHD_RESPMEM_PERSISTENT);
1843 add_cors_headers(response);
1844 MHD_queue_response(mhd_connection, MHD_HTTP_OK, response);
1845 MHD_destroy_response(response);
1846 return MHD_YES;
1847 }
1848 else if ((*upload_data_size > 0) && (sc->connected == GNUNET_YES))
1849 {
1850 struct GNUNET_TIME_Relative delay;
1851
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;
1879 } 1900 }
1880 GNUNET_MST_from_buffer (s->msg_tk,
1881 upload_data,
1882 *upload_data_size,
1883 GNUNET_NO, GNUNET_NO);
1884 server_mhd_connection_timeout (plugin, s,
1885 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL
1886 / 1000LL);
1887 (*upload_data_size) = 0;
1888 }
1889 else 1901 else
1890 { 1902 {
1891 /* delay processing */ 1903 GNUNET_break(0);
1892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1904 return MHD_NO;
1893 "Session %p / Connection %p: no inbound bandwidth available! Next read was delayed by %s\n", 1905 }
1894 s,
1895 sc,
1896 GNUNET_STRINGS_relative_time_to_string (delay,
1897 GNUNET_YES));
1898 GNUNET_assert(s->server_recv->mhd_conn == mhd_connection);
1899 MHD_suspend_connection (s->server_recv->mhd_conn);
1900 s->server_recv->suspended = true;
1901 if (NULL == s->recv_wakeup_task)
1902 s->recv_wakeup_task
1903 = GNUNET_SCHEDULER_add_delayed (delay,
1904 &server_wake_up,
1905 s);
1906 }
1907 return MHD_YES;
1908 }
1909 else
1910 {
1911 GNUNET_break (0);
1912 return MHD_NO;
1913 } 1906 }
1914 }
1915 return res; 1907 return res;
1916} 1908}
1917 1909
@@ -1924,54 +1916,54 @@ server_access_cb (void *cls,
1924 * @param httpSessionCache the pointer to distinguish 1916 * @param httpSessionCache the pointer to distinguish
1925 */ 1917 */
1926static void 1918static void
1927server_disconnect_cb (void *cls, 1919server_disconnect_cb(void *cls,
1928 struct MHD_Connection *connection, 1920 struct MHD_Connection *connection,
1929 void **httpSessionCache) 1921 void **httpSessionCache)
1930{ 1922{
1931 struct HTTP_Server_Plugin *plugin = cls; 1923 struct HTTP_Server_Plugin *plugin = cls;
1932 struct ServerRequest *sc = *httpSessionCache; 1924 struct ServerRequest *sc = *httpSessionCache;
1933 1925
1934 LOG (GNUNET_ERROR_TYPE_DEBUG, 1926 LOG(GNUNET_ERROR_TYPE_DEBUG,
1935 "Disconnect for connection %p\n", 1927 "Disconnect for connection %p\n",
1936 sc); 1928 sc);
1937 if (NULL == sc) 1929 if (NULL == sc)
1938 { 1930 {
1939 /* CORS pre-flight request finished */ 1931 /* CORS pre-flight request finished */
1940 return; 1932 return;
1941 } 1933 }
1942 1934
1943 if (NULL != sc->session) 1935 if (NULL != sc->session)
1944 { 1936 {
1945 if (sc->direction == _SEND) 1937 if (sc->direction == _SEND)
1946 { 1938 {
1947 LOG (GNUNET_ERROR_TYPE_DEBUG, 1939 LOG(GNUNET_ERROR_TYPE_DEBUG,
1948 "Peer `%s' connection %p, GET on address `%s' disconnected\n", 1940 "Peer `%s' connection %p, GET on address `%s' disconnected\n",
1949 GNUNET_i2s (&sc->session->target), 1941 GNUNET_i2s(&sc->session->target),
1950 sc->session->server_send, 1942 sc->session->server_send,
1951 http_common_plugin_address_to_string (plugin->protocol, 1943 http_common_plugin_address_to_string(plugin->protocol,
1952 sc->session->address->address, 1944 sc->session->address->address,
1953 sc->session->address->address_length)); 1945 sc->session->address->address_length));
1954 1946
1955 sc->session->server_send = NULL; 1947 sc->session->server_send = NULL;
1956 } 1948 }
1957 else if (sc->direction == _RECEIVE) 1949 else if (sc->direction == _RECEIVE)
1958 { 1950 {
1959 LOG (GNUNET_ERROR_TYPE_DEBUG, 1951 LOG(GNUNET_ERROR_TYPE_DEBUG,
1960 "Peer `%s' connection %p PUT on address `%s' disconnected\n", 1952 "Peer `%s' connection %p PUT on address `%s' disconnected\n",
1961 GNUNET_i2s (&sc->session->target), 1953 GNUNET_i2s(&sc->session->target),
1962 sc->session->server_recv, 1954 sc->session->server_recv,
1963 http_common_plugin_address_to_string (plugin->protocol, 1955 http_common_plugin_address_to_string(plugin->protocol,
1964 sc->session->address->address, 1956 sc->session->address->address,
1965 sc->session->address->address_length)); 1957 sc->session->address->address_length));
1966 sc->session->server_recv = NULL; 1958 sc->session->server_recv = NULL;
1967 if (NULL != sc->session->msg_tk) 1959 if (NULL != sc->session->msg_tk)
1968 { 1960 {
1969 GNUNET_MST_destroy (sc->session->msg_tk); 1961 GNUNET_MST_destroy(sc->session->msg_tk);
1970 sc->session->msg_tk = NULL; 1962 sc->session->msg_tk = NULL;
1971 } 1963 }
1972 } 1964 }
1973 } 1965 }
1974 GNUNET_free (sc); 1966 GNUNET_free(sc);
1975 plugin->cur_request--; 1967 plugin->cur_request--;
1976} 1968}
1977 1969
@@ -1986,10 +1978,10 @@ server_disconnect_cb (void *cls,
1986 * @see #MHD_OPTION_NOTIFY_CONNECTION 1978 * @see #MHD_OPTION_NOTIFY_CONNECTION
1987 */ 1979 */
1988static void 1980static void
1989server_connection_cb (void *cls, 1981server_connection_cb(void *cls,
1990 struct MHD_Connection *connection, 1982 struct MHD_Connection *connection,
1991 void **socket_context, 1983 void **socket_context,
1992 enum MHD_ConnectionNotificationCode toe) 1984 enum MHD_ConnectionNotificationCode toe)
1993{ 1985{
1994 struct HTTP_Server_Plugin *plugin = cls; 1986 struct HTTP_Server_Plugin *plugin = cls;
1995 const union MHD_ConnectionInfo *info; 1987 const union MHD_ConnectionInfo *info;
@@ -1998,12 +1990,12 @@ server_connection_cb (void *cls,
1998 return; 1990 return;
1999 1991
2000 /* Reschedule to remove closed socket from our select set */ 1992 /* Reschedule to remove closed socket from our select set */
2001 info = MHD_get_connection_info (connection, 1993 info = MHD_get_connection_info(connection,
2002 MHD_CONNECTION_INFO_DAEMON); 1994 MHD_CONNECTION_INFO_DAEMON);
2003 GNUNET_assert (NULL != info); 1995 GNUNET_assert(NULL != info);
2004 server_reschedule (plugin, 1996 server_reschedule(plugin,
2005 info->daemon, 1997 info->daemon,
2006 GNUNET_YES); 1998 GNUNET_YES);
2007} 1999}
2008 2000
2009 2001
@@ -2016,27 +2008,27 @@ server_connection_cb (void *cls,
2016 * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected 2008 * @return MHD_YES if connection is accepted, MHD_NO if connection is rejected
2017 */ 2009 */
2018static int 2010static int
2019server_accept_cb (void *cls, 2011server_accept_cb(void *cls,
2020 const struct sockaddr *addr, 2012 const struct sockaddr *addr,
2021 socklen_t addr_len) 2013 socklen_t addr_len)
2022{ 2014{
2023 struct HTTP_Server_Plugin *plugin = cls; 2015 struct HTTP_Server_Plugin *plugin = cls;
2024 2016
2025 if (plugin->cur_request <= plugin->max_request) 2017 if (plugin->cur_request <= plugin->max_request)
2026 { 2018 {
2027 LOG (GNUNET_ERROR_TYPE_DEBUG, 2019 LOG(GNUNET_ERROR_TYPE_DEBUG,
2028 _("Accepting connection (%u of %u) from `%s'\n"), 2020 _("Accepting connection (%u of %u) from `%s'\n"),
2029 plugin->cur_request, plugin->max_request, 2021 plugin->cur_request, plugin->max_request,
2030 GNUNET_a2s (addr, addr_len)); 2022 GNUNET_a2s(addr, addr_len));
2031 return MHD_YES; 2023 return MHD_YES;
2032 } 2024 }
2033 else 2025 else
2034 { 2026 {
2035 LOG (GNUNET_ERROR_TYPE_WARNING, 2027 LOG(GNUNET_ERROR_TYPE_WARNING,
2036 _("Server reached maximum number connections (%u), rejecting new connection\n"), 2028 _("Server reached maximum number connections (%u), rejecting new connection\n"),
2037 plugin->max_request); 2029 plugin->max_request);
2038 return MHD_NO; 2030 return MHD_NO;
2039 } 2031 }
2040} 2032}
2041 2033
2042 2034
@@ -2049,19 +2041,19 @@ server_accept_cb (void *cls,
2049 * will be called by MHD) 2041 * will be called by MHD)
2050 */ 2042 */
2051static void 2043static void
2052server_log (void *arg, 2044server_log(void *arg,
2053 const char *fmt, 2045 const char *fmt,
2054 va_list ap) 2046 va_list ap)
2055{ 2047{
2056 char text[1024]; 2048 char text[1024];
2057 2049
2058 vsnprintf (text, 2050 vsnprintf(text,
2059 sizeof (text), 2051 sizeof(text),
2060 fmt, 2052 fmt,
2061 ap); 2053 ap);
2062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2054 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2063 "Server: %s\n", 2055 "Server: %s\n",
2064 text); 2056 text);
2065} 2057}
2066 2058
2067 2059
@@ -2073,32 +2065,32 @@ server_log (void *arg,
2073 * @return content of the file 2065 * @return content of the file
2074 */ 2066 */
2075static char * 2067static char *
2076server_load_file (const char *file) 2068server_load_file(const char *file)
2077{ 2069{
2078 struct GNUNET_DISK_FileHandle *gn_file; 2070 struct GNUNET_DISK_FileHandle *gn_file;
2079 uint64_t fsize; 2071 uint64_t fsize;
2080 char *text = NULL; 2072 char *text = NULL;
2081 2073
2082 if (GNUNET_OK != GNUNET_DISK_file_size (file, 2074 if (GNUNET_OK != GNUNET_DISK_file_size(file,
2083 &fsize, GNUNET_NO, GNUNET_YES)) 2075 &fsize, GNUNET_NO, GNUNET_YES))
2084 return NULL; 2076 return NULL;
2085 text = GNUNET_malloc (fsize + 1); 2077 text = GNUNET_malloc(fsize + 1);
2086 gn_file = 2078 gn_file =
2087 GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ, 2079 GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ,
2088 GNUNET_DISK_PERM_USER_READ); 2080 GNUNET_DISK_PERM_USER_READ);
2089 if (NULL == gn_file) 2081 if (NULL == gn_file)
2090 { 2082 {
2091 GNUNET_free (text); 2083 GNUNET_free(text);
2092 return NULL; 2084 return NULL;
2093 } 2085 }
2094 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fsize)) 2086 if (GNUNET_SYSERR == GNUNET_DISK_file_read(gn_file, text, fsize))
2095 { 2087 {
2096 GNUNET_free (text); 2088 GNUNET_free(text);
2097 GNUNET_DISK_file_close (gn_file); 2089 GNUNET_DISK_file_close(gn_file);
2098 return NULL; 2090 return NULL;
2099 } 2091 }
2100 text[fsize] = '\0'; 2092 text[fsize] = '\0';
2101 GNUNET_DISK_file_close (gn_file); 2093 GNUNET_DISK_file_close(gn_file);
2102 return text; 2094 return text;
2103} 2095}
2104#endif 2096#endif
@@ -2112,7 +2104,7 @@ server_load_file (const char *file)
2112 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2104 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2113 */ 2105 */
2114static int 2106static int
2115server_load_certificate (struct HTTP_Server_Plugin *plugin) 2107server_load_certificate(struct HTTP_Server_Plugin *plugin)
2116{ 2108{
2117 int res = GNUNET_OK; 2109 int res = GNUNET_OK;
2118 char *key_file; 2110 char *key_file;
@@ -2120,110 +2112,110 @@ server_load_certificate (struct HTTP_Server_Plugin *plugin)
2120 2112
2121 2113
2122 if (GNUNET_OK != 2114 if (GNUNET_OK !=
2123 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, 2115 GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg,
2124 plugin->name, 2116 plugin->name,
2125 "KEY_FILE", &key_file)) 2117 "KEY_FILE", &key_file))
2126 { 2118 {
2127 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2119 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
2128 plugin->name, "CERT_FILE"); 2120 plugin->name, "CERT_FILE");
2129 return GNUNET_SYSERR; 2121 return GNUNET_SYSERR;
2130 } 2122 }
2131 if (GNUNET_OK != 2123 if (GNUNET_OK !=
2132 GNUNET_CONFIGURATION_get_value_filename (plugin->env->cfg, 2124 GNUNET_CONFIGURATION_get_value_filename(plugin->env->cfg,
2133 plugin->name, 2125 plugin->name,
2134 "CERT_FILE", &cert_file)) 2126 "CERT_FILE", &cert_file))
2135 { 2127 {
2136 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2128 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
2137 plugin->name, "CERT_FILE"); 2129 plugin->name, "CERT_FILE");
2138 GNUNET_free (key_file); 2130 GNUNET_free(key_file);
2139 return GNUNET_SYSERR; 2131 return GNUNET_SYSERR;
2140 } 2132 }
2141 /* Get crypto init string from config. If not present, use 2133 /* Get crypto init string from config. If not present, use
2142 * default values */ 2134 * default values */
2143 if (GNUNET_OK == 2135 if (GNUNET_OK ==
2144 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 2136 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
2145 plugin->name, 2137 plugin->name,
2146 "CRYPTO_INIT", 2138 "CRYPTO_INIT",
2147 &plugin->crypto_init)) 2139 &plugin->crypto_init))
2148 LOG (GNUNET_ERROR_TYPE_DEBUG, 2140 LOG(GNUNET_ERROR_TYPE_DEBUG,
2149 "Using crypto init string `%s'\n", 2141 "Using crypto init string `%s'\n",
2150 plugin->crypto_init); 2142 plugin->crypto_init);
2151 else 2143 else
2152 LOG (GNUNET_ERROR_TYPE_DEBUG, 2144 LOG(GNUNET_ERROR_TYPE_DEBUG,
2153 "Using default crypto init string \n"); 2145 "Using default crypto init string \n");
2154 2146
2155 /* read key & certificates from file */ 2147 /* read key & certificates from file */
2156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2148 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2157 "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n", 2149 "Trying to loading TLS certificate from key-file `%s' cert-file`%s'\n",
2158 key_file, cert_file); 2150 key_file, cert_file);
2151
2152 plugin->key = server_load_file(key_file);
2153 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);
2159 2193
2160 plugin->key = server_load_file (key_file); 2194 plugin->key = server_load_file(key_file);
2161 plugin->cert = server_load_file (cert_file); 2195 plugin->cert = server_load_file(cert_file);
2196 }
2162 2197
2163 if ((plugin->key == NULL) || (plugin->cert == NULL)) 2198 if ((plugin->key == NULL) || (plugin->cert == NULL))
2164 { 2199 {
2165 struct GNUNET_OS_Process *cert_creation; 2200 LOG(GNUNET_ERROR_TYPE_ERROR,
2166 2201 _("No usable TLS certificate found and creating one at `%s/%s' failed!\n"),
2167 GNUNET_free_non_null (plugin->key); 2202 key_file, cert_file);
2168 plugin->key = NULL; 2203 GNUNET_free(key_file);
2169 GNUNET_free_non_null (plugin->cert); 2204 GNUNET_free(cert_file);
2170 plugin->cert = NULL; 2205
2171 2206 GNUNET_free_non_null(plugin->key);
2172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2173 "No usable TLS certificate found, creating certificate\n");
2174 errno = 0;
2175 cert_creation =
2176 GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
2177 NULL, NULL, NULL,
2178 "gnunet-transport-certificate-creation",
2179 "gnunet-transport-certificate-creation",
2180 key_file,
2181 cert_file,
2182 NULL);
2183 if (NULL == cert_creation)
2184 {
2185 LOG (GNUNET_ERROR_TYPE_ERROR,
2186 _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
2187 GNUNET_free (key_file);
2188 GNUNET_free (cert_file);
2189
2190 GNUNET_free_non_null (plugin->key);
2191 plugin->key = NULL; 2207 plugin->key = NULL;
2192 GNUNET_free_non_null (plugin->cert); 2208 GNUNET_free_non_null(plugin->cert);
2193 plugin->cert = NULL; 2209 plugin->cert = NULL;
2194 GNUNET_free_non_null (plugin->crypto_init); 2210 GNUNET_free_non_null(plugin->crypto_init);
2195 plugin->crypto_init = NULL; 2211 plugin->crypto_init = NULL;
2196 2212
2197 return GNUNET_SYSERR; 2213 return GNUNET_SYSERR;
2198 } 2214 }
2199 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (cert_creation)); 2215 GNUNET_free(key_file);
2200 GNUNET_OS_process_destroy (cert_creation); 2216 GNUNET_free(cert_file);
2201 2217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2202 plugin->key = server_load_file (key_file); 2218 "TLS certificate loaded\n");
2203 plugin->cert = server_load_file (cert_file);
2204 }
2205
2206 if ((plugin->key == NULL) || (plugin->cert == NULL))
2207 {
2208 LOG (GNUNET_ERROR_TYPE_ERROR,
2209 _("No usable TLS certificate found and creating one at `%s/%s' failed!\n"),
2210 key_file, cert_file);
2211 GNUNET_free (key_file);
2212 GNUNET_free (cert_file);
2213
2214 GNUNET_free_non_null (plugin->key);
2215 plugin->key = NULL;
2216 GNUNET_free_non_null (plugin->cert);
2217 plugin->cert = NULL;
2218 GNUNET_free_non_null (plugin->crypto_init);
2219 plugin->crypto_init = NULL;
2220
2221 return GNUNET_SYSERR;
2222 }
2223 GNUNET_free (key_file);
2224 GNUNET_free (cert_file);
2225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2226 "TLS certificate loaded\n");
2227 return res; 2219 return res;
2228} 2220}
2229#endif 2221#endif
@@ -2239,81 +2231,81 @@ server_load_certificate (struct HTTP_Server_Plugin *plugin)
2239 * @return NULL on error 2231 * @return NULL on error
2240 */ 2232 */
2241static struct MHD_Daemon * 2233static struct MHD_Daemon *
2242run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin, 2234run_mhd_start_daemon(struct HTTP_Server_Plugin *plugin,
2243 const struct sockaddr_in *addr, 2235 const struct sockaddr_in *addr,
2244 int v6) 2236 int v6)
2245{ 2237{
2246 struct MHD_Daemon *server; 2238 struct MHD_Daemon *server;
2247 unsigned int timeout; 2239 unsigned int timeout;
2248 2240
2249#if MHD_VERSION >= 0x00090E00 2241#if MHD_VERSION >= 0x00090E00
2250 timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL; 2242 timeout = HTTP_SERVER_NOT_VALIDATED_TIMEOUT.rel_value_us / 1000LL / 1000LL;
2251 LOG (GNUNET_ERROR_TYPE_DEBUG, 2243 LOG(GNUNET_ERROR_TYPE_DEBUG,
2252 "MHD can set timeout per connection! Default time out %u sec.\n", 2244 "MHD can set timeout per connection! Default time out %u sec.\n",
2253 timeout); 2245 timeout);
2254#else 2246#else
2255 timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL; 2247 timeout = HTTP_SERVER_SESSION_TIMEOUT.rel_value_us / 1000LL / 1000LL;
2256 LOG (GNUNET_ERROR_TYPE_WARNING, 2248 LOG(GNUNET_ERROR_TYPE_WARNING,
2257 "MHD cannot set timeout per connection! Default time out %u sec.\n", 2249 "MHD cannot set timeout per connection! Default time out %u sec.\n",
2258 timeout); 2250 timeout);
2259#endif 2251#endif
2260 server = MHD_start_daemon ( 2252 server = MHD_start_daemon(
2261#if VERBOSE_SERVER 2253#if VERBOSE_SERVER
2262 MHD_USE_DEBUG | 2254 MHD_USE_DEBUG |
2263#endif 2255#endif
2264#if BUILD_HTTPS 2256#if BUILD_HTTPS
2265 MHD_USE_SSL | 2257 MHD_USE_SSL |
2266#endif 2258#endif
2267 MHD_USE_SUSPEND_RESUME | 2259 MHD_USE_SUSPEND_RESUME |
2268 v6, 2260 v6,
2269 plugin->port, 2261 plugin->port,
2270 &server_accept_cb, plugin, 2262 &server_accept_cb, plugin,
2271 &server_access_cb, plugin, 2263 &server_access_cb, plugin,
2272 MHD_OPTION_SOCK_ADDR, 2264 MHD_OPTION_SOCK_ADDR,
2273 addr, 2265 addr,
2274 MHD_OPTION_CONNECTION_LIMIT, 2266 MHD_OPTION_CONNECTION_LIMIT,
2275 (unsigned int) plugin->max_request, 2267 (unsigned int)plugin->max_request,
2276#if BUILD_HTTPS 2268#if BUILD_HTTPS
2277 MHD_OPTION_HTTPS_PRIORITIES, 2269 MHD_OPTION_HTTPS_PRIORITIES,
2278 plugin->crypto_init, 2270 plugin->crypto_init,
2279 MHD_OPTION_HTTPS_MEM_KEY, 2271 MHD_OPTION_HTTPS_MEM_KEY,
2280 plugin->key, 2272 plugin->key,
2281 MHD_OPTION_HTTPS_MEM_CERT, 2273 MHD_OPTION_HTTPS_MEM_CERT,
2282 plugin->cert, 2274 plugin->cert,
2283#endif 2275#endif
2284 MHD_OPTION_CONNECTION_TIMEOUT, 2276 MHD_OPTION_CONNECTION_TIMEOUT,
2285 timeout, 2277 timeout,
2286 MHD_OPTION_CONNECTION_MEMORY_LIMIT, 2278 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
2287 (size_t) (2 * 2279 (size_t)(2 *
2288 GNUNET_MAX_MESSAGE_SIZE), 2280 GNUNET_MAX_MESSAGE_SIZE),
2289 MHD_OPTION_NOTIFY_COMPLETED, 2281 MHD_OPTION_NOTIFY_COMPLETED,
2290 &server_disconnect_cb, plugin, 2282 &server_disconnect_cb, plugin,
2291 MHD_OPTION_NOTIFY_CONNECTION, 2283 MHD_OPTION_NOTIFY_CONNECTION,
2292 &server_connection_cb, plugin, 2284 &server_connection_cb, plugin,
2293 MHD_OPTION_EXTERNAL_LOGGER, 2285 MHD_OPTION_EXTERNAL_LOGGER,
2294 &server_log, NULL, 2286 &server_log, NULL,
2295 MHD_OPTION_END); 2287 MHD_OPTION_END);
2296#ifdef TCP_STEALTH 2288#ifdef TCP_STEALTH
2297 if ( (NULL != server) && 2289 if ((NULL != server) &&
2298 (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH)) ) 2290 (0 != (plugin->options & HTTP_OPTIONS_TCP_STEALTH)))
2299 { 2291 {
2300 const union MHD_DaemonInfo *di; 2292 const union MHD_DaemonInfo *di;
2301 2293
2302 di = MHD_get_daemon_info (server, 2294 di = MHD_get_daemon_info(server,
2303 MHD_DAEMON_INFO_LISTEN_FD, 2295 MHD_DAEMON_INFO_LISTEN_FD,
2304 NULL); 2296 NULL);
2305 if ( (0 != setsockopt ((int) di->listen_fd, 2297 if ((0 != setsockopt((int)di->listen_fd,
2306 IPPROTO_TCP, 2298 IPPROTO_TCP,
2307 TCP_STEALTH, 2299 TCP_STEALTH,
2308 plugin->env->my_identity, 2300 plugin->env->my_identity,
2309 sizeof (struct GNUNET_PeerIdentity))) ) 2301 sizeof(struct GNUNET_PeerIdentity))))
2310 { 2302 {
2311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2303 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2312 _("TCP_STEALTH not supported on this platform.\n")); 2304 _("TCP_STEALTH not supported on this platform.\n"));
2313 MHD_stop_daemon (server); 2305 MHD_stop_daemon(server);
2314 server = NULL; 2306 server = NULL;
2307 }
2315 } 2308 }
2316 }
2317#endif 2309#endif
2318 return server; 2310 return server;
2319} 2311}
@@ -2326,76 +2318,76 @@ run_mhd_start_daemon (struct HTTP_Server_Plugin *plugin,
2326 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2318 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2327 */ 2319 */
2328static int 2320static int
2329server_start (struct HTTP_Server_Plugin *plugin) 2321server_start(struct HTTP_Server_Plugin *plugin)
2330{ 2322{
2331 const char *msg; 2323 const char *msg;
2332 2324
2333 GNUNET_assert (NULL != plugin); 2325 GNUNET_assert(NULL != plugin);
2334#if BUILD_HTTPS 2326#if BUILD_HTTPS
2335 if (GNUNET_SYSERR == server_load_certificate (plugin)) 2327 if (GNUNET_SYSERR == server_load_certificate(plugin))
2336 { 2328 {
2337 LOG (GNUNET_ERROR_TYPE_ERROR, 2329 LOG(GNUNET_ERROR_TYPE_ERROR,
2338 _("Could not load or create server certificate! Loading plugin failed!\n")); 2330 _("Could not load or create server certificate! Loading plugin failed!\n"));
2339 return GNUNET_SYSERR; 2331 return GNUNET_SYSERR;
2340 } 2332 }
2341#endif 2333#endif
2342 2334
2343 2335
2344 2336
2345 plugin->server_v4 = NULL; 2337 plugin->server_v4 = NULL;
2346 if (GNUNET_YES == plugin->use_ipv4) 2338 if (GNUNET_YES == plugin->use_ipv4)
2347 {
2348 plugin->server_v4
2349 = run_mhd_start_daemon (plugin,
2350 (const struct sockaddr_in *) plugin->server_addr_v4,
2351 MHD_NO_FLAG);
2352
2353 if (NULL == plugin->server_v4)
2354 { 2339 {
2355 LOG (GNUNET_ERROR_TYPE_ERROR, 2340 plugin->server_v4
2356 "Failed to start %s IPv4 server component on port %u\n", 2341 = run_mhd_start_daemon(plugin,
2357 plugin->name, 2342 (const struct sockaddr_in *)plugin->server_addr_v4,
2358 plugin->port); 2343 MHD_NO_FLAG);
2344
2345 if (NULL == plugin->server_v4)
2346 {
2347 LOG(GNUNET_ERROR_TYPE_ERROR,
2348 "Failed to start %s IPv4 server component on port %u\n",
2349 plugin->name,
2350 plugin->port);
2351 }
2352 else
2353 server_reschedule(plugin,
2354 plugin->server_v4,
2355 GNUNET_NO);
2359 } 2356 }
2360 else
2361 server_reschedule (plugin,
2362 plugin->server_v4,
2363 GNUNET_NO);
2364 }
2365 2357
2366 2358
2367 plugin->server_v6 = NULL; 2359 plugin->server_v6 = NULL;
2368 if (GNUNET_YES == plugin->use_ipv6) 2360 if (GNUNET_YES == plugin->use_ipv6)
2369 {
2370 plugin->server_v6
2371 = run_mhd_start_daemon (plugin,
2372 (const struct sockaddr_in *) plugin->server_addr_v6,
2373 MHD_USE_IPv6);
2374 if (NULL == plugin->server_v6)
2375 { 2361 {
2376 LOG (GNUNET_ERROR_TYPE_ERROR, 2362 plugin->server_v6
2377 "Failed to start %s IPv6 server component on port %u\n", 2363 = run_mhd_start_daemon(plugin,
2378 plugin->name, 2364 (const struct sockaddr_in *)plugin->server_addr_v6,
2379 plugin->port); 2365 MHD_USE_IPv6);
2366 if (NULL == plugin->server_v6)
2367 {
2368 LOG(GNUNET_ERROR_TYPE_ERROR,
2369 "Failed to start %s IPv6 server component on port %u\n",
2370 plugin->name,
2371 plugin->port);
2372 }
2373 else
2374 {
2375 server_reschedule(plugin,
2376 plugin->server_v6,
2377 GNUNET_NO);
2378 }
2380 } 2379 }
2381 else 2380 msg = "No";
2381 if ((NULL == plugin->server_v6) &&
2382 (NULL == plugin->server_v4))
2382 { 2383 {
2383 server_reschedule (plugin, 2384 LOG(GNUNET_ERROR_TYPE_ERROR,
2384 plugin->server_v6, 2385 "%s %s server component started on port %u\n",
2385 GNUNET_NO); 2386 msg,
2387 plugin->name,
2388 plugin->port);
2389 return GNUNET_SYSERR;
2386 } 2390 }
2387 }
2388 msg = "No";
2389 if ( (NULL == plugin->server_v6) &&
2390 (NULL == plugin->server_v4) )
2391 {
2392 LOG (GNUNET_ERROR_TYPE_ERROR,
2393 "%s %s server component started on port %u\n",
2394 msg,
2395 plugin->name,
2396 plugin->port);
2397 return GNUNET_SYSERR;
2398 }
2399 if ((NULL != plugin->server_v6) && 2391 if ((NULL != plugin->server_v6) &&
2400 (NULL != plugin->server_v4)) 2392 (NULL != plugin->server_v4))
2401 msg = "IPv4 and IPv6"; 2393 msg = "IPv4 and IPv6";
@@ -2403,11 +2395,11 @@ server_start (struct HTTP_Server_Plugin *plugin)
2403 msg = "IPv6"; 2395 msg = "IPv6";
2404 else if (NULL != plugin->server_v4) 2396 else if (NULL != plugin->server_v4)
2405 msg = "IPv4"; 2397 msg = "IPv4";
2406 LOG (GNUNET_ERROR_TYPE_DEBUG, 2398 LOG(GNUNET_ERROR_TYPE_DEBUG,
2407 "%s %s server component started on port %u\n", 2399 "%s %s server component started on port %u\n",
2408 msg, 2400 msg,
2409 plugin->name, 2401 plugin->name,
2410 plugin->port); 2402 plugin->port);
2411 return GNUNET_OK; 2403 return GNUNET_OK;
2412} 2404}
2413 2405
@@ -2421,47 +2413,47 @@ server_start (struct HTTP_Server_Plugin *plugin)
2421 * @param addrlen address length 2413 * @param addrlen address length
2422 */ 2414 */
2423static void 2415static void
2424server_add_address (void *cls, 2416server_add_address(void *cls,
2425 int add_remove, 2417 int add_remove,
2426 const struct sockaddr *addr, 2418 const struct sockaddr *addr,
2427 socklen_t addrlen) 2419 socklen_t addrlen)
2428{ 2420{
2429 struct HTTP_Server_Plugin *plugin = cls; 2421 struct HTTP_Server_Plugin *plugin = cls;
2430 struct GNUNET_HELLO_Address *address; 2422 struct GNUNET_HELLO_Address *address;
2431 struct HttpAddressWrapper *w = NULL; 2423 struct HttpAddressWrapper *w = NULL;
2432 2424
2433 w = GNUNET_new (struct HttpAddressWrapper); 2425 w = GNUNET_new(struct HttpAddressWrapper);
2434 w->address = http_common_address_from_socket (plugin->protocol, 2426 w->address = http_common_address_from_socket(plugin->protocol,
2435 addr, 2427 addr,
2436 addrlen); 2428 addrlen);
2437 if (NULL == w->address) 2429 if (NULL == w->address)
2438 { 2430 {
2439 GNUNET_free (w); 2431 GNUNET_free(w);
2440 return; 2432 return;
2441 } 2433 }
2442 w->addrlen = http_common_address_get_size (w->address); 2434 w->addrlen = http_common_address_get_size(w->address);
2443 2435
2444 GNUNET_CONTAINER_DLL_insert (plugin->addr_head, 2436 GNUNET_CONTAINER_DLL_insert(plugin->addr_head,
2445 plugin->addr_tail, 2437 plugin->addr_tail,
2446 w); 2438 w);
2447 LOG (GNUNET_ERROR_TYPE_DEBUG, 2439 LOG(GNUNET_ERROR_TYPE_DEBUG,
2448 "Notifying transport to add address `%s'\n", 2440 "Notifying transport to add address `%s'\n",
2449 http_common_plugin_address_to_string (plugin->protocol, 2441 http_common_plugin_address_to_string(plugin->protocol,
2450 w->address, 2442 w->address,
2451 w->addrlen)); 2443 w->addrlen));
2452 /* modify our published address list */ 2444 /* modify our published address list */
2453#if BUILD_HTTPS 2445#if BUILD_HTTPS
2454 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2446 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2455 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2447 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2456#else 2448#else
2457 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2449 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2458 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2450 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2459#endif 2451#endif
2460 2452
2461 plugin->env->notify_address (plugin->env->cls, 2453 plugin->env->notify_address(plugin->env->cls,
2462 add_remove, 2454 add_remove,
2463 address); 2455 address);
2464 GNUNET_HELLO_address_free (address); 2456 GNUNET_HELLO_address_free(address);
2465} 2457}
2466 2458
2467 2459
@@ -2474,10 +2466,10 @@ server_add_address (void *cls,
2474 * @param addrlen address length 2466 * @param addrlen address length
2475 */ 2467 */
2476static void 2468static void
2477server_remove_address (void *cls, 2469server_remove_address(void *cls,
2478 int add_remove, 2470 int add_remove,
2479 const struct sockaddr *addr, 2471 const struct sockaddr *addr,
2480 socklen_t addrlen) 2472 socklen_t addrlen)
2481{ 2473{
2482 struct HTTP_Server_Plugin *plugin = cls; 2474 struct HTTP_Server_Plugin *plugin = cls;
2483 struct GNUNET_HELLO_Address *address; 2475 struct GNUNET_HELLO_Address *address;
@@ -2485,48 +2477,48 @@ server_remove_address (void *cls,
2485 size_t saddr_len; 2477 size_t saddr_len;
2486 void * saddr; 2478 void * saddr;
2487 2479
2488 saddr = http_common_address_from_socket (plugin->protocol, 2480 saddr = http_common_address_from_socket(plugin->protocol,
2489 addr, 2481 addr,
2490 addrlen); 2482 addrlen);
2491 if (NULL == saddr) 2483 if (NULL == saddr)
2492 return; 2484 return;
2493 saddr_len = http_common_address_get_size (saddr); 2485 saddr_len = http_common_address_get_size(saddr);
2494 2486
2495 while (NULL != w) 2487 while (NULL != w)
2496 { 2488 {
2497 if (GNUNET_YES == 2489 if (GNUNET_YES ==
2498 http_common_cmp_addresses (w->address, 2490 http_common_cmp_addresses(w->address,
2499 w->addrlen, 2491 w->addrlen,
2500 saddr, 2492 saddr,
2501 saddr_len)) 2493 saddr_len))
2502 break; 2494 break;
2503 w = w->next; 2495 w = w->next;
2504 } 2496 }
2505 GNUNET_free (saddr); 2497 GNUNET_free(saddr);
2506 2498
2507 if (NULL == w) 2499 if (NULL == w)
2508 return; 2500 return;
2509 2501
2510 LOG (GNUNET_ERROR_TYPE_DEBUG, 2502 LOG(GNUNET_ERROR_TYPE_DEBUG,
2511 "Notifying transport to remove address `%s'\n", 2503 "Notifying transport to remove address `%s'\n",
2512 http_common_plugin_address_to_string (plugin->protocol, 2504 http_common_plugin_address_to_string(plugin->protocol,
2513 w->address, 2505 w->address,
2514 w->addrlen)); 2506 w->addrlen));
2515 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, 2507 GNUNET_CONTAINER_DLL_remove(plugin->addr_head,
2516 plugin->addr_tail, 2508 plugin->addr_tail,
2517 w); 2509 w);
2518 /* modify our published address list */ 2510 /* modify our published address list */
2519#if BUILD_HTTPS 2511#if BUILD_HTTPS
2520 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2512 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2521 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2513 "https_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2522#else 2514#else
2523 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2515 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2524 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE); 2516 "http_client", w->address, w->addrlen, GNUNET_HELLO_ADDRESS_INFO_NONE);
2525#endif 2517#endif
2526 plugin->env->notify_address (plugin->env->cls, add_remove, address); 2518 plugin->env->notify_address(plugin->env->cls, add_remove, address);
2527 GNUNET_HELLO_address_free (address); 2519 GNUNET_HELLO_address_free(address);
2528 GNUNET_free (w->address); 2520 GNUNET_free(w->address);
2529 GNUNET_free (w); 2521 GNUNET_free(w);
2530} 2522}
2531 2523
2532 2524
@@ -2544,66 +2536,67 @@ server_remove_address (void *cls,
2544 * @param addrlen actual lenght of the address 2536 * @param addrlen actual lenght of the address
2545 */ 2537 */
2546static void 2538static void
2547server_nat_port_map_callback (void *cls, 2539server_nat_port_map_callback(void *cls,
2548 void **app_ctx, 2540 void **app_ctx,
2549 int add_remove, 2541 int add_remove,
2550 enum GNUNET_NAT_AddressClass ac, 2542 enum GNUNET_NAT_AddressClass ac,
2551 const struct sockaddr *addr, 2543 const struct sockaddr *addr,
2552 socklen_t addrlen) 2544 socklen_t addrlen)
2553{ 2545{
2554 struct HTTP_Server_Plugin *plugin = cls; 2546 struct HTTP_Server_Plugin *plugin = cls;
2555 2547
2556 (void) app_ctx; 2548 (void)app_ctx;
2557 LOG (GNUNET_ERROR_TYPE_DEBUG, 2549 LOG(GNUNET_ERROR_TYPE_DEBUG,
2558 "NAT called to %s address `%s'\n", 2550 "NAT called to %s address `%s'\n",
2559 (add_remove == GNUNET_NO) ? "remove" : "add", 2551 (add_remove == GNUNET_NO) ? "remove" : "add",
2560 GNUNET_a2s (addr, addrlen)); 2552 GNUNET_a2s(addr, addrlen));
2561 2553
2562 if (AF_INET == addr->sa_family) 2554 if (AF_INET == addr->sa_family)
2563 { 2555 {
2564 struct sockaddr_in *s4 = (struct sockaddr_in *) addr; 2556 struct sockaddr_in *s4 = (struct sockaddr_in *)addr;
2565 2557
2566 if (GNUNET_NO == plugin->use_ipv4) 2558 if (GNUNET_NO == plugin->use_ipv4)
2567 return; 2559 return;
2568 2560
2569 if ((NULL != plugin->server_addr_v4) && 2561 if ((NULL != plugin->server_addr_v4) &&
2570 (0 != memcmp (&plugin->server_addr_v4->sin_addr, 2562 (0 != memcmp(&plugin->server_addr_v4->sin_addr,
2571 &s4->sin_addr, 2563 &s4->sin_addr,
2572 sizeof (struct in_addr)))) 2564 sizeof(struct in_addr))))
2573 { 2565 {
2574 LOG (GNUNET_ERROR_TYPE_DEBUG, 2566 LOG(GNUNET_ERROR_TYPE_DEBUG,
2575 "Skipping address `%s' (not bindto address)\n", 2567 "Skipping address `%s' (not bindto address)\n",
2576 GNUNET_a2s (addr, addrlen)); 2568 GNUNET_a2s(addr, addrlen));
2577 return; 2569 return;
2570 }
2578 } 2571 }
2579 }
2580 2572
2581 if (AF_INET6 == addr->sa_family) 2573 if (AF_INET6 == addr->sa_family)
2582 {
2583 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *) addr;
2584 if (GNUNET_NO == plugin->use_ipv6)
2585 return;
2586
2587 if ((NULL != plugin->server_addr_v6) &&
2588 (0 != memcmp (&plugin->server_addr_v6->sin6_addr,
2589 &s6->sin6_addr, sizeof (struct in6_addr))))
2590 { 2574 {
2591 LOG (GNUNET_ERROR_TYPE_DEBUG, 2575 struct sockaddr_in6 *s6 = (struct sockaddr_in6 *)addr;
2592 "Skipping address `%s' (not bindto address)\n", 2576 if (GNUNET_NO == plugin->use_ipv6)
2593 GNUNET_a2s (addr, addrlen)); 2577 return;
2594 return; 2578
2579 if ((NULL != plugin->server_addr_v6) &&
2580 (0 != memcmp(&plugin->server_addr_v6->sin6_addr,
2581 &s6->sin6_addr, sizeof(struct in6_addr))))
2582 {
2583 LOG(GNUNET_ERROR_TYPE_DEBUG,
2584 "Skipping address `%s' (not bindto address)\n",
2585 GNUNET_a2s(addr, addrlen));
2586 return;
2587 }
2595 } 2588 }
2596 }
2597 2589
2598 switch (add_remove) 2590 switch (add_remove)
2599 { 2591 {
2600 case GNUNET_YES: 2592 case GNUNET_YES:
2601 server_add_address (cls, add_remove, addr, addrlen); 2593 server_add_address(cls, add_remove, addr, addrlen);
2602 break; 2594 break;
2603 case GNUNET_NO: 2595
2604 server_remove_address (cls, add_remove, addr, addrlen); 2596 case GNUNET_NO:
2605 break; 2597 server_remove_address(cls, add_remove, addr, addrlen);
2606 } 2598 break;
2599 }
2607} 2600}
2608 2601
2609 2602
@@ -2618,11 +2611,11 @@ server_nat_port_map_callback (void *cls,
2618 * @return number of addresses 2611 * @return number of addresses
2619 */ 2612 */
2620static int 2613static int
2621server_get_addresses (struct HTTP_Server_Plugin *plugin, 2614server_get_addresses(struct HTTP_Server_Plugin *plugin,
2622 const char *service_name, 2615 const char *service_name,
2623 const struct GNUNET_CONFIGURATION_Handle *cfg, 2616 const struct GNUNET_CONFIGURATION_Handle *cfg,
2624 struct sockaddr ***addrs, 2617 struct sockaddr ***addrs,
2625 socklen_t ** addr_lens) 2618 socklen_t ** addr_lens)
2626{ 2619{
2627 int disablev6; 2620 int disablev6;
2628 unsigned long long port; 2621 unsigned long long port;
@@ -2643,156 +2636,156 @@ server_get_addresses (struct HTTP_Server_Plugin *plugin,
2643 disablev6 = !plugin->use_ipv6; 2636 disablev6 = !plugin->use_ipv6;
2644 2637
2645 port = 0; 2638 port = 0;
2646 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) 2639 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT"))
2647 {
2648 GNUNET_break (GNUNET_OK ==
2649 GNUNET_CONFIGURATION_get_value_number (cfg, service_name,
2650 "PORT", &port));
2651 if (port > 65535)
2652 { 2640 {
2653 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2641 GNUNET_break(GNUNET_OK ==
2654 _("Require valid port number for service in configuration!\n")); 2642 GNUNET_CONFIGURATION_get_value_number(cfg, service_name,
2655 return GNUNET_SYSERR; 2643 "PORT", &port));
2644 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 }
2656 } 2650 }
2657 }
2658 if (0 == port) 2651 if (0 == port)
2659 { 2652 {
2660 LOG (GNUNET_ERROR_TYPE_INFO, 2653 LOG(GNUNET_ERROR_TYPE_INFO,
2661 "Starting in listen only mode\n"); 2654 "Starting in listen only mode\n");
2662 return -1; /* listen only */ 2655 return -1; /* listen only */
2663 } 2656 }
2664 2657
2665 2658
2666 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, 2659 if (GNUNET_CONFIGURATION_have_value(cfg, service_name,
2667 "BINDTO")) 2660 "BINDTO"))
2668 { 2661 {
2669 GNUNET_break (GNUNET_OK == 2662 GNUNET_break(GNUNET_OK ==
2670 GNUNET_CONFIGURATION_get_value_string (cfg, service_name, 2663 GNUNET_CONFIGURATION_get_value_string(cfg, service_name,
2671 "BINDTO", &hostname)); 2664 "BINDTO", &hostname));
2672 } 2665 }
2673 else 2666 else
2674 hostname = NULL; 2667 hostname = NULL;
2675 2668
2676 if (NULL != hostname) 2669 if (NULL != hostname)
2677 {
2678 LOG (GNUNET_ERROR_TYPE_DEBUG,
2679 "Resolving `%s' since that is where `%s' will bind to.\n",
2680 hostname, service_name);
2681 memset (&hints, 0, sizeof (struct addrinfo));
2682 if (disablev6)
2683 hints.ai_family = AF_INET;
2684 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
2685 (NULL == res))
2686 {
2687 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2688 _("Failed to resolve `%s': %s\n"),
2689 hostname,
2690 gai_strerror (ret));
2691 GNUNET_free (hostname);
2692 return GNUNET_SYSERR;
2693 }
2694 next = res;
2695 i = 0;
2696 while (NULL != (pos = next))
2697 { 2670 {
2698 next = pos->ai_next; 2671 LOG(GNUNET_ERROR_TYPE_DEBUG,
2699 if ((disablev6) && (pos->ai_family == AF_INET6)) 2672 "Resolving `%s' since that is where `%s' will bind to.\n",
2700 continue; 2673 hostname, service_name);
2701 i++; 2674 memset(&hints, 0, sizeof(struct addrinfo));
2702 } 2675 if (disablev6)
2703 if (0 == i) 2676 hints.ai_family = AF_INET;
2704 { 2677 if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) ||
2705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2678 (NULL == res))
2706 _("Failed to find %saddress for `%s'.\n"), 2679 {
2707 disablev6 ? "IPv4 " : "", hostname); 2680 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
2708 freeaddrinfo (res); 2681 _("Failed to resolve `%s': %s\n"),
2709 GNUNET_free (hostname); 2682 hostname,
2710 return GNUNET_SYSERR; 2683 gai_strerror(ret));
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;
2711 } 2745 }
2712 resi = i;
2713 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
2714 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
2715 i = 0;
2716 next = res;
2717 while (NULL != (pos = next))
2718 {
2719 next = pos->ai_next;
2720 if ((disablev6) && (pos->ai_family == AF_INET6))
2721 continue;
2722 if ((pos->ai_protocol != IPPROTO_TCP) && (0 != pos->ai_protocol))
2723 continue; /* not TCP */
2724 if ((pos->ai_socktype != SOCK_STREAM) && (0 != pos->ai_socktype))
2725 continue; /* huh? */
2726 LOG (GNUNET_ERROR_TYPE_DEBUG,
2727 "Service will bind to `%s'\n",
2728 GNUNET_a2s (pos->ai_addr,
2729 pos->ai_addrlen));
2730 if (pos->ai_family == AF_INET)
2731 {
2732 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in));
2733 saddrlens[i] = pos->ai_addrlen;
2734 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2735 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2736 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
2737 }
2738 else
2739 {
2740 GNUNET_assert (pos->ai_family == AF_INET6);
2741 GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6));
2742 saddrlens[i] = pos->ai_addrlen;
2743 saddrs[i] = GNUNET_malloc (saddrlens[i]);
2744 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
2745 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
2746 }
2747 i++;
2748 }
2749 GNUNET_free (hostname);
2750 freeaddrinfo (res);
2751 resi = i;
2752 }
2753 else 2746 else
2754 {
2755 /* will bind against everything, just set port */
2756 if (disablev6)
2757 { 2747 {
2758 /* V4-only */ 2748 /* will bind against everything, just set port */
2759 resi = 1; 2749 if (disablev6)
2760 i = 0; 2750 {
2761 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 2751 /* V4-only */
2762 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 2752 resi = 1;
2763 2753 i = 0;
2764 saddrlens[i] = sizeof (struct sockaddr_in); 2754 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
2765 saddrs[i] = GNUNET_malloc (saddrlens[i]); 2755 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
2756
2757 saddrlens[i] = sizeof(struct sockaddr_in);
2758 saddrs[i] = GNUNET_malloc(saddrlens[i]);
2766#if HAVE_SOCKADDR_IN_SIN_LEN 2759#if HAVE_SOCKADDR_IN_SIN_LEN
2767 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; 2760 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i];
2768#endif 2761#endif
2769 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; 2762 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET;
2770 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 2763 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
2771 } 2764 }
2772 else 2765 else
2773 { 2766 {
2774 /* dual stack */ 2767 /* dual stack */
2775 resi = 2; 2768 resi = 2;
2776 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 2769 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
2777 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 2770 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
2778 i = 0; 2771 i = 0;
2779 saddrlens[i] = sizeof (struct sockaddr_in6); 2772 saddrlens[i] = sizeof(struct sockaddr_in6);
2780 saddrs[i] = GNUNET_malloc (saddrlens[i]); 2773 saddrs[i] = GNUNET_malloc(saddrlens[i]);
2781#if HAVE_SOCKADDR_IN_SIN_LEN 2774#if HAVE_SOCKADDR_IN_SIN_LEN
2782 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; 2775 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0];
2783#endif 2776#endif
2784 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; 2777 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6;
2785 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); 2778 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port);
2786 i++; 2779 i++;
2787 saddrlens[i] = sizeof (struct sockaddr_in); 2780 saddrlens[i] = sizeof(struct sockaddr_in);
2788 saddrs[i] = GNUNET_malloc (saddrlens[i]); 2781 saddrs[i] = GNUNET_malloc(saddrlens[i]);
2789#if HAVE_SOCKADDR_IN_SIN_LEN 2782#if HAVE_SOCKADDR_IN_SIN_LEN
2790 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; 2783 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1];
2791#endif 2784#endif
2792 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; 2785 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET;
2793 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 2786 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
2787 }
2794 } 2788 }
2795 }
2796 *addrs = saddrs; 2789 *addrs = saddrs;
2797 *addr_lens = saddrlens; 2790 *addr_lens = saddrlens;
2798 return resi; 2791 return resi;
@@ -2805,44 +2798,44 @@ server_get_addresses (struct HTTP_Server_Plugin *plugin,
2805 * @param plugin the plugin handle 2798 * @param plugin the plugin handle
2806 */ 2799 */
2807static void 2800static void
2808server_start_report_addresses (struct HTTP_Server_Plugin *plugin) 2801server_start_report_addresses(struct HTTP_Server_Plugin *plugin)
2809{ 2802{
2810 int res = GNUNET_OK; 2803 int res = GNUNET_OK;
2811 struct sockaddr **addrs; 2804 struct sockaddr **addrs;
2812 socklen_t *addrlens; 2805 socklen_t *addrlens;
2813 2806
2814 res = server_get_addresses (plugin, 2807 res = server_get_addresses(plugin,
2815 plugin->name, 2808 plugin->name,
2816 plugin->env->cfg, 2809 plugin->env->cfg,
2817 &addrs, &addrlens); 2810 &addrs, &addrlens);
2818 LOG (GNUNET_ERROR_TYPE_DEBUG, 2811 LOG(GNUNET_ERROR_TYPE_DEBUG,
2819 _("Found %u addresses to report to NAT service\n"), 2812 _("Found %u addresses to report to NAT service\n"),
2820 res); 2813 res);
2821 2814
2822 if (GNUNET_SYSERR == res) 2815 if (GNUNET_SYSERR == res)
2823 { 2816 {
2824 plugin->nat = NULL; 2817 plugin->nat = NULL;
2825 return; 2818 return;
2826 } 2819 }
2827 2820
2828 plugin->nat 2821 plugin->nat
2829 = GNUNET_NAT_register (plugin->env->cfg, 2822 = GNUNET_NAT_register(plugin->env->cfg,
2830 "transport-http_server", 2823 "transport-http_server",
2831 IPPROTO_TCP, 2824 IPPROTO_TCP,
2832 (unsigned int) res, 2825 (unsigned int)res,
2833 (const struct sockaddr **) addrs, 2826 (const struct sockaddr **)addrs,
2834 addrlens, 2827 addrlens,
2835 &server_nat_port_map_callback, 2828 &server_nat_port_map_callback,
2836 NULL, 2829 NULL,
2837 plugin); 2830 plugin);
2838 while (res > 0) 2831 while (res > 0)
2839 { 2832 {
2840 res--; 2833 res--;
2841 GNUNET_assert (NULL != addrs[res]); 2834 GNUNET_assert(NULL != addrs[res]);
2842 GNUNET_free (addrs[res]); 2835 GNUNET_free(addrs[res]);
2843 } 2836 }
2844 GNUNET_free_non_null (addrs); 2837 GNUNET_free_non_null(addrs);
2845 GNUNET_free_non_null (addrlens); 2838 GNUNET_free_non_null(addrlens);
2846} 2839}
2847 2840
2848 2841
@@ -2852,26 +2845,26 @@ server_start_report_addresses (struct HTTP_Server_Plugin *plugin)
2852 * @param plugin the plugin handle 2845 * @param plugin the plugin handle
2853 */ 2846 */
2854static void 2847static void
2855server_stop_report_addresses (struct HTTP_Server_Plugin *plugin) 2848server_stop_report_addresses(struct HTTP_Server_Plugin *plugin)
2856{ 2849{
2857 struct HttpAddressWrapper *w; 2850 struct HttpAddressWrapper *w;
2858 2851
2859 /* Stop NAT handle */ 2852 /* Stop NAT handle */
2860 if (NULL != plugin->nat) 2853 if (NULL != plugin->nat)
2861 { 2854 {
2862 GNUNET_NAT_unregister (plugin->nat); 2855 GNUNET_NAT_unregister(plugin->nat);
2863 plugin->nat = NULL; 2856 plugin->nat = NULL;
2864 } 2857 }
2865 /* Clean up addresses */ 2858 /* Clean up addresses */
2866 while (NULL != plugin->addr_head) 2859 while (NULL != plugin->addr_head)
2867 { 2860 {
2868 w = plugin->addr_head; 2861 w = plugin->addr_head;
2869 GNUNET_CONTAINER_DLL_remove (plugin->addr_head, 2862 GNUNET_CONTAINER_DLL_remove(plugin->addr_head,
2870 plugin->addr_tail, 2863 plugin->addr_tail,
2871 w); 2864 w);
2872 GNUNET_free (w->address); 2865 GNUNET_free(w->address);
2873 GNUNET_free (w); 2866 GNUNET_free(w);
2874 } 2867 }
2875} 2868}
2876 2869
2877 2870
@@ -2882,39 +2875,39 @@ server_stop_report_addresses (struct HTTP_Server_Plugin *plugin)
2882 * @return #GNUNET_YES on success, else #GNUNET_NO 2875 * @return #GNUNET_YES on success, else #GNUNET_NO
2883 */ 2876 */
2884static int 2877static int
2885server_check_ipv6_support (struct HTTP_Server_Plugin *plugin) 2878server_check_ipv6_support(struct HTTP_Server_Plugin *plugin)
2886{ 2879{
2887 struct GNUNET_NETWORK_Handle *desc = NULL; 2880 struct GNUNET_NETWORK_Handle *desc = NULL;
2888 int res = GNUNET_NO; 2881 int res = GNUNET_NO;
2889 2882
2890 /* Probe IPv6 support */ 2883 /* Probe IPv6 support */
2891 desc = GNUNET_NETWORK_socket_create (PF_INET6, 2884 desc = GNUNET_NETWORK_socket_create(PF_INET6,
2892 SOCK_STREAM, 2885 SOCK_STREAM,
2893 0); 2886 0);
2894 if (NULL == desc) 2887 if (NULL == desc)
2895 { 2888 {
2896 if ( (errno == ENOBUFS) || 2889 if ((errno == ENOBUFS) ||
2897 (errno == ENOMEM) || 2890 (errno == ENOMEM) ||
2898 (errno == ENFILE) || 2891 (errno == ENFILE) ||
2899 (errno == EACCES) ) 2892 (errno == EACCES))
2900 { 2893 {
2901 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 2894 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR,
2902 "socket"); 2895 "socket");
2903 } 2896 }
2904 LOG (GNUNET_ERROR_TYPE_WARNING, 2897 LOG(GNUNET_ERROR_TYPE_WARNING,
2905 _("Disabling IPv6 since it is not supported on this system!\n")); 2898 _("Disabling IPv6 since it is not supported on this system!\n"));
2906 res = GNUNET_NO; 2899 res = GNUNET_NO;
2907 } 2900 }
2908 else 2901 else
2909 { 2902 {
2910 GNUNET_break (GNUNET_OK == 2903 GNUNET_break(GNUNET_OK ==
2911 GNUNET_NETWORK_socket_close (desc)); 2904 GNUNET_NETWORK_socket_close(desc));
2912 desc = NULL; 2905 desc = NULL;
2913 res = GNUNET_YES; 2906 res = GNUNET_YES;
2914 } 2907 }
2915 LOG (GNUNET_ERROR_TYPE_DEBUG, 2908 LOG(GNUNET_ERROR_TYPE_DEBUG,
2916 "Testing IPv6 on this system: %s\n", 2909 "Testing IPv6 on this system: %s\n",
2917 (res == GNUNET_YES) ? "successful" : "failed"); 2910 (res == GNUNET_YES) ? "successful" : "failed");
2918 return res; 2911 return res;
2919} 2912}
2920 2913
@@ -2925,7 +2918,7 @@ server_check_ipv6_support (struct HTTP_Server_Plugin *plugin)
2925 * @param cls plugin 2918 * @param cls plugin
2926 */ 2919 */
2927static void 2920static void
2928server_notify_external_hostname (void *cls) 2921server_notify_external_hostname(void *cls)
2929{ 2922{
2930 struct HTTP_Server_Plugin *plugin = cls; 2923 struct HTTP_Server_Plugin *plugin = cls;
2931 struct HttpAddress *ext_addr; 2924 struct HttpAddress *ext_addr;
@@ -2934,48 +2927,48 @@ server_notify_external_hostname (void *cls)
2934 char *url; 2927 char *url;
2935 2928
2936 plugin->notify_ext_task = NULL; 2929 plugin->notify_ext_task = NULL;
2937 GNUNET_asprintf (&url, 2930 GNUNET_asprintf(&url,
2938 "%s://%s", 2931 "%s://%s",
2939 plugin->protocol, 2932 plugin->protocol,
2940 plugin->external_hostname); 2933 plugin->external_hostname);
2941 urlen = strlen (url) + 1; 2934 urlen = strlen(url) + 1;
2942 ext_addr = GNUNET_malloc (sizeof (struct HttpAddress) + urlen); 2935 ext_addr = GNUNET_malloc(sizeof(struct HttpAddress) + urlen);
2943 ext_addr->options = htonl (plugin->options); 2936 ext_addr->options = htonl(plugin->options);
2944 ext_addr->urlen = htonl (urlen); 2937 ext_addr->urlen = htonl(urlen);
2945 ext_addr_len = sizeof (struct HttpAddress) + urlen; 2938 ext_addr_len = sizeof(struct HttpAddress) + urlen;
2946 GNUNET_memcpy (&ext_addr[1], url, urlen); 2939 GNUNET_memcpy(&ext_addr[1], url, urlen);
2947 GNUNET_free (url); 2940 GNUNET_free(url);
2948 2941
2949 LOG (GNUNET_ERROR_TYPE_DEBUG, 2942 LOG(GNUNET_ERROR_TYPE_DEBUG,
2950 "Notifying transport about external hostname address `%s'\n", 2943 "Notifying transport about external hostname address `%s'\n",
2951 plugin->external_hostname); 2944 plugin->external_hostname);
2952 2945
2953#if BUILD_HTTPS 2946#if BUILD_HTTPS
2954 if (GNUNET_YES == plugin->verify_external_hostname) 2947 if (GNUNET_YES == plugin->verify_external_hostname)
2955 LOG (GNUNET_ERROR_TYPE_INFO, 2948 LOG(GNUNET_ERROR_TYPE_INFO,
2956 "Enabling SSL verification for external hostname address `%s'\n", 2949 "Enabling SSL verification for external hostname address `%s'\n",
2957 plugin->external_hostname); 2950 plugin->external_hostname);
2958 plugin->ext_addr 2951 plugin->ext_addr
2959 = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2952 = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2960 "https_client", 2953 "https_client",
2961 ext_addr, 2954 ext_addr,
2962 ext_addr_len, 2955 ext_addr_len,
2963 GNUNET_HELLO_ADDRESS_INFO_NONE); 2956 GNUNET_HELLO_ADDRESS_INFO_NONE);
2964 plugin->env->notify_address (plugin->env->cls, 2957 plugin->env->notify_address(plugin->env->cls,
2965 GNUNET_YES, 2958 GNUNET_YES,
2966 plugin->ext_addr); 2959 plugin->ext_addr);
2967 GNUNET_free (ext_addr); 2960 GNUNET_free(ext_addr);
2968#else 2961#else
2969 plugin->ext_addr 2962 plugin->ext_addr
2970 = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2963 = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2971 "http_client", 2964 "http_client",
2972 ext_addr, 2965 ext_addr,
2973 ext_addr_len, 2966 ext_addr_len,
2974 GNUNET_HELLO_ADDRESS_INFO_NONE); 2967 GNUNET_HELLO_ADDRESS_INFO_NONE);
2975 plugin->env->notify_address (plugin->env->cls, 2968 plugin->env->notify_address(plugin->env->cls,
2976 GNUNET_YES, 2969 GNUNET_YES,
2977 plugin->ext_addr); 2970 plugin->ext_addr);
2978 GNUNET_free (ext_addr); 2971 GNUNET_free(ext_addr);
2979#endif 2972#endif
2980} 2973}
2981 2974
@@ -2987,7 +2980,7 @@ server_notify_external_hostname (void *cls)
2987 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2980 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2988 */ 2981 */
2989static int 2982static int
2990server_configure_plugin (struct HTTP_Server_Plugin *plugin) 2983server_configure_plugin(struct HTTP_Server_Plugin *plugin)
2991{ 2984{
2992 unsigned long long port; 2985 unsigned long long port;
2993 unsigned long long max_connections; 2986 unsigned long long max_connections;
@@ -2998,225 +2991,225 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin)
2998 2991
2999 /* Use IPv4? */ 2992 /* Use IPv4? */
3000 if (GNUNET_CONFIGURATION_have_value 2993 if (GNUNET_CONFIGURATION_have_value
3001 (plugin->env->cfg, plugin->name, "USE_IPv4")) 2994 (plugin->env->cfg, plugin->name, "USE_IPv4"))
3002 { 2995 {
3003 plugin->use_ipv4 = 2996 plugin->use_ipv4 =
3004 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 2997 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
3005 plugin->name, 2998 plugin->name,
3006 "USE_IPv4"); 2999 "USE_IPv4");
3007 } 3000 }
3008 else 3001 else
3009 plugin->use_ipv4 = GNUNET_YES; 3002 plugin->use_ipv4 = GNUNET_YES;
3010 LOG (GNUNET_ERROR_TYPE_DEBUG, 3003 LOG(GNUNET_ERROR_TYPE_DEBUG,
3011 _("IPv4 support is %s\n"), 3004 _("IPv4 support is %s\n"),
3012 (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled"); 3005 (plugin->use_ipv4 == GNUNET_YES) ? "enabled" : "disabled");
3013 3006
3014 /* Use IPv6? */ 3007 /* Use IPv6? */
3015 if (GNUNET_CONFIGURATION_have_value 3008 if (GNUNET_CONFIGURATION_have_value
3016 (plugin->env->cfg, plugin->name, "USE_IPv6")) 3009 (plugin->env->cfg, plugin->name, "USE_IPv6"))
3017 { 3010 {
3018 plugin->use_ipv6 = 3011 plugin->use_ipv6 =
3019 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 3012 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
3020 plugin->name, 3013 plugin->name,
3021 "USE_IPv6"); 3014 "USE_IPv6");
3022 } 3015 }
3023 else 3016 else
3024 plugin->use_ipv6 = GNUNET_YES; 3017 plugin->use_ipv6 = GNUNET_YES;
3025 LOG (GNUNET_ERROR_TYPE_DEBUG, 3018 LOG(GNUNET_ERROR_TYPE_DEBUG,
3026 _("IPv6 support is %s\n"), 3019 _("IPv6 support is %s\n"),
3027 (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled"); 3020 (plugin->use_ipv6 == GNUNET_YES) ? "enabled" : "disabled");
3028 3021
3029 if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO)) 3022 if ((plugin->use_ipv4 == GNUNET_NO) && (plugin->use_ipv6 == GNUNET_NO))
3030 { 3023 {
3031 LOG (GNUNET_ERROR_TYPE_ERROR, 3024 LOG(GNUNET_ERROR_TYPE_ERROR,
3032 _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n")); 3025 _("Neither IPv4 nor IPv6 are enabled! Fix in configuration\n"));
3033 return GNUNET_SYSERR; 3026 return GNUNET_SYSERR;
3034 } 3027 }
3035 3028
3036 /* Reading port number from config file */ 3029 /* Reading port number from config file */
3037 if ((GNUNET_OK != 3030 if ((GNUNET_OK !=
3038 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, 3031 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg,
3039 plugin->name, 3032 plugin->name,
3040 "PORT", &port)) || (port > 65535)) 3033 "PORT", &port)) || (port > 65535))
3041 { 3034 {
3042 LOG (GNUNET_ERROR_TYPE_ERROR, 3035 LOG(GNUNET_ERROR_TYPE_ERROR,
3043 _("Port is required! Fix in configuration\n")); 3036 _("Port is required! Fix in configuration\n"));
3044 return GNUNET_SYSERR;
3045 }
3046 plugin->port = port;
3047
3048 LOG (GNUNET_ERROR_TYPE_INFO,
3049 _("Using port %u\n"), plugin->port);
3050
3051 if ( (plugin->use_ipv4 == GNUNET_YES) &&
3052 (GNUNET_YES ==
3053 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg,
3054 plugin->name,
3055 "BINDTO",
3056 &bind4_address)))
3057 {
3058 LOG (GNUNET_ERROR_TYPE_DEBUG,
3059 "Binding %s plugin to specific IPv4 address: `%s'\n",
3060 plugin->protocol,
3061 bind4_address);
3062 plugin->server_addr_v4 = GNUNET_new (struct sockaddr_in);
3063 if (1 != inet_pton (AF_INET,
3064 bind4_address,
3065 &plugin->server_addr_v4->sin_addr))
3066 {
3067 LOG (GNUNET_ERROR_TYPE_ERROR,
3068 _("Specific IPv4 address `%s' in configuration file is invalid!\n"),
3069 bind4_address);
3070 GNUNET_free (bind4_address);
3071 GNUNET_free (plugin->server_addr_v4);
3072 plugin->server_addr_v4 = NULL;
3073 return GNUNET_SYSERR; 3037 return GNUNET_SYSERR;
3074 } 3038 }
3075 else 3039 plugin->port = port;
3040
3041 LOG(GNUNET_ERROR_TYPE_INFO,
3042 _("Using port %u\n"), plugin->port);
3043
3044 if ((plugin->use_ipv4 == GNUNET_YES) &&
3045 (GNUNET_YES ==
3046 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
3047 plugin->name,
3048 "BINDTO",
3049 &bind4_address)))
3076 { 3050 {
3077 LOG (GNUNET_ERROR_TYPE_DEBUG, 3051 LOG(GNUNET_ERROR_TYPE_DEBUG,
3078 "Binding to IPv4 address %s\n", 3052 "Binding %s plugin to specific IPv4 address: `%s'\n",
3079 bind4_address); 3053 plugin->protocol,
3080 plugin->server_addr_v4->sin_family = AF_INET; 3054 bind4_address);
3081 plugin->server_addr_v4->sin_port = htons (plugin->port); 3055 plugin->server_addr_v4 = GNUNET_new(struct sockaddr_in);
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);
3082 } 3077 }
3083 GNUNET_free (bind4_address);
3084 }
3085 3078
3086 if ((plugin->use_ipv6 == GNUNET_YES) && 3079 if ((plugin->use_ipv6 == GNUNET_YES) &&
3087 (GNUNET_YES == 3080 (GNUNET_YES ==
3088 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 3081 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
3089 plugin->name, 3082 plugin->name,
3090 "BINDTO6", 3083 "BINDTO6",
3091 &bind6_address))) 3084 &bind6_address)))
3092 {
3093 LOG (GNUNET_ERROR_TYPE_DEBUG,
3094 "Binding %s plugin to specific IPv6 address: `%s'\n",
3095 plugin->protocol, bind6_address);
3096 plugin->server_addr_v6 = GNUNET_new (struct sockaddr_in6);
3097 if (1 !=
3098 inet_pton (AF_INET6,
3099 bind6_address,
3100 &plugin->server_addr_v6->sin6_addr))
3101 {
3102 LOG (GNUNET_ERROR_TYPE_ERROR,
3103 _("Specific IPv6 address `%s' in configuration file is invalid!\n"),
3104 bind6_address);
3105 GNUNET_free (bind6_address);
3106 GNUNET_free (plugin->server_addr_v6);
3107 plugin->server_addr_v6 = NULL;
3108 return GNUNET_SYSERR;
3109 }
3110 else
3111 { 3085 {
3112 LOG (GNUNET_ERROR_TYPE_DEBUG, 3086 LOG(GNUNET_ERROR_TYPE_DEBUG,
3113 "Binding to IPv6 address %s\n", 3087 "Binding %s plugin to specific IPv6 address: `%s'\n",
3114 bind6_address); 3088 plugin->protocol, bind6_address);
3115 plugin->server_addr_v6->sin6_family = AF_INET6; 3089 plugin->server_addr_v6 = GNUNET_new(struct sockaddr_in6);
3116 plugin->server_addr_v6->sin6_port = htons (plugin->port); 3090 if (1 !=
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);
3117 } 3112 }
3118 GNUNET_free (bind6_address);
3119 }
3120 3113
3121 plugin->verify_external_hostname = GNUNET_NO; 3114 plugin->verify_external_hostname = GNUNET_NO;
3122#if BUILD_HTTPS 3115#if BUILD_HTTPS
3123 plugin->verify_external_hostname 3116 plugin->verify_external_hostname
3124 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 3117 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
3125 plugin->name, 3118 plugin->name,
3126 "VERIFY_EXTERNAL_HOSTNAME"); 3119 "VERIFY_EXTERNAL_HOSTNAME");
3127 if (GNUNET_SYSERR == plugin->verify_external_hostname) 3120 if (GNUNET_SYSERR == plugin->verify_external_hostname)
3128 plugin->verify_external_hostname = GNUNET_NO; 3121 plugin->verify_external_hostname = GNUNET_NO;
3129 if (GNUNET_YES == plugin->verify_external_hostname) 3122 if (GNUNET_YES == plugin->verify_external_hostname)
3130 plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE; 3123 plugin->options |= HTTP_OPTIONS_VERIFY_CERTIFICATE;
3131#endif 3124#endif
3132 external_hostname_use_port 3125 external_hostname_use_port
3133 = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 3126 = GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
3134 plugin->name, 3127 plugin->name,
3135 "EXTERNAL_HOSTNAME_USE_PORT"); 3128 "EXTERNAL_HOSTNAME_USE_PORT");
3136 if (GNUNET_SYSERR == external_hostname_use_port) 3129 if (GNUNET_SYSERR == external_hostname_use_port)
3137 external_hostname_use_port = GNUNET_NO; 3130 external_hostname_use_port = GNUNET_NO;
3138 3131
3139 3132
3140 if (GNUNET_YES == 3133 if (GNUNET_YES ==
3141 GNUNET_CONFIGURATION_get_value_string (plugin->env->cfg, 3134 GNUNET_CONFIGURATION_get_value_string(plugin->env->cfg,
3142 plugin->name, 3135 plugin->name,
3143 "EXTERNAL_HOSTNAME", 3136 "EXTERNAL_HOSTNAME",
3144 &eh_tmp)) 3137 &eh_tmp))
3145 { 3138 {
3146 char *tmp; 3139 char *tmp;
3147 char *pos = NULL; 3140 char *pos = NULL;
3148 char *pos_url = NULL; 3141 char *pos_url = NULL;
3149 3142
3150 if (NULL != strstr(eh_tmp, "://")) 3143 if (NULL != strstr(eh_tmp, "://"))
3151 tmp = &strstr(eh_tmp, "://")[3]; 3144 tmp = &strstr(eh_tmp, "://")[3];
3152 else
3153 tmp = eh_tmp;
3154
3155 if (GNUNET_YES == external_hostname_use_port)
3156 {
3157 if ( (strlen (tmp) > 1) && (NULL != (pos = strchr(tmp, '/'))) )
3158 {
3159 pos_url = pos + 1;
3160 pos[0] = '\0';
3161 GNUNET_asprintf (&plugin->external_hostname,
3162 "%s:%u/%s",
3163 tmp,
3164 (uint16_t) port,
3165 pos_url);
3166 }
3167 else 3145 else
3168 GNUNET_asprintf (&plugin->external_hostname, 3146 tmp = eh_tmp;
3169 "%s:%u", 3147
3170 tmp, 3148 if (GNUNET_YES == external_hostname_use_port)
3171 (uint16_t) port); 3149 {
3172 } 3150 if ((strlen(tmp) > 1) && (NULL != (pos = strchr(tmp, '/'))))
3173 else 3151 {
3174 plugin->external_hostname = GNUNET_strdup (tmp); 3152 pos_url = pos + 1;
3175 GNUNET_free (eh_tmp); 3153 pos[0] = '\0';
3176 3154 GNUNET_asprintf(&plugin->external_hostname,
3177 LOG (GNUNET_ERROR_TYPE_INFO, 3155 "%s:%u/%s",
3178 _("Using external hostname `%s'\n"), 3156 tmp,
3179 plugin->external_hostname); 3157 (uint16_t)port,
3180 plugin->notify_ext_task = GNUNET_SCHEDULER_add_now (&server_notify_external_hostname, 3158 pos_url);
3181 plugin); 3159 }
3182 3160 else
3183 /* Use only configured external hostname */ 3161 GNUNET_asprintf(&plugin->external_hostname,
3184 if (GNUNET_CONFIGURATION_have_value 3162 "%s:%u",
3185 (plugin->env->cfg, 3163 tmp,
3186 plugin->name, 3164 (uint16_t)port);
3187 "EXTERNAL_HOSTNAME_ONLY")) 3165 }
3188 { 3166 else
3189 plugin->external_only = 3167 plugin->external_hostname = GNUNET_strdup(tmp);
3190 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 3168 GNUNET_free(eh_tmp);
3191 plugin->name, 3169
3192 "EXTERNAL_HOSTNAME_ONLY"); 3170 LOG(GNUNET_ERROR_TYPE_INFO,
3193 } 3171 _("Using external hostname `%s'\n"),
3194 else 3172 plugin->external_hostname);
3195 plugin->external_only = GNUNET_NO; 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
3188 plugin->external_only = GNUNET_NO;
3196 3189
3197 if (GNUNET_YES == plugin->external_only) 3190 if (GNUNET_YES == plugin->external_only)
3198 LOG (GNUNET_ERROR_TYPE_DEBUG, 3191 LOG(GNUNET_ERROR_TYPE_DEBUG,
3199 _("Notifying transport only about hostname `%s'\n"), 3192 _("Notifying transport only about hostname `%s'\n"),
3200 plugin->external_hostname); 3193 plugin->external_hostname);
3201 } 3194 }
3202 else 3195 else
3203 LOG (GNUNET_ERROR_TYPE_DEBUG, 3196 LOG(GNUNET_ERROR_TYPE_DEBUG,
3204 "No external hostname configured\n"); 3197 "No external hostname configured\n");
3205 3198
3206 /* Optional parameters */ 3199 /* Optional parameters */
3207 if (GNUNET_OK != 3200 if (GNUNET_OK !=
3208 GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, 3201 GNUNET_CONFIGURATION_get_value_number(plugin->env->cfg,
3209 plugin->name, 3202 plugin->name,
3210 "MAX_CONNECTIONS", 3203 "MAX_CONNECTIONS",
3211 &max_connections)) 3204 &max_connections))
3212 max_connections = 128; 3205 max_connections = 128;
3213 plugin->max_request = max_connections; 3206 plugin->max_request = max_connections;
3214 3207
3215 LOG (GNUNET_ERROR_TYPE_DEBUG, 3208 LOG(GNUNET_ERROR_TYPE_DEBUG,
3216 _("Maximum number of connections is %u\n"), 3209 _("Maximum number of connections is %u\n"),
3217 plugin->max_request); 3210 plugin->max_request);
3218 3211
3219 plugin->peer_id_length = strlen (GNUNET_i2s_full (plugin->env->my_identity)); 3212 plugin->peer_id_length = strlen(GNUNET_i2s_full(plugin->env->my_identity));
3220 3213
3221 return GNUNET_OK; 3214 return GNUNET_OK;
3222} 3215}
@@ -3229,94 +3222,94 @@ server_configure_plugin (struct HTTP_Server_Plugin *plugin)
3229 * @return NULL 3222 * @return NULL
3230 */ 3223 */
3231void * 3224void *
3232LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) 3225LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
3233{ 3226{
3234 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3227 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3235 struct HTTP_Server_Plugin *plugin = api->cls; 3228 struct HTTP_Server_Plugin *plugin = api->cls;
3236 3229
3237 if (NULL == api->cls) 3230 if (NULL == api->cls)
3238 { 3231 {
3239 /* Free for stub mode */ 3232 /* Free for stub mode */
3240 GNUNET_free (api); 3233 GNUNET_free(api);
3241 return NULL; 3234 return NULL;
3242 } 3235 }
3243 plugin->in_shutdown = GNUNET_YES; 3236 plugin->in_shutdown = GNUNET_YES;
3244 LOG (GNUNET_ERROR_TYPE_INFO, 3237 LOG(GNUNET_ERROR_TYPE_INFO,
3245 _("Shutting down plugin `%s'\n"), 3238 _("Shutting down plugin `%s'\n"),
3246 plugin->name); 3239 plugin->name);
3247 3240
3248 if (NULL != plugin->notify_ext_task) 3241 if (NULL != plugin->notify_ext_task)
3249 { 3242 {
3250 GNUNET_SCHEDULER_cancel (plugin->notify_ext_task); 3243 GNUNET_SCHEDULER_cancel(plugin->notify_ext_task);
3251 plugin->notify_ext_task = NULL; 3244 plugin->notify_ext_task = NULL;
3252 } 3245 }
3253 3246
3254 if (NULL != plugin->ext_addr) 3247 if (NULL != plugin->ext_addr)
3255 { 3248 {
3256 LOG (GNUNET_ERROR_TYPE_DEBUG, 3249 LOG(GNUNET_ERROR_TYPE_DEBUG,
3257 "Notifying transport to remove address `%s'\n", 3250 "Notifying transport to remove address `%s'\n",
3258 http_common_plugin_address_to_string (plugin->protocol, 3251 http_common_plugin_address_to_string(plugin->protocol,
3259 plugin->ext_addr->address, 3252 plugin->ext_addr->address,
3260 plugin->ext_addr->address_length)); 3253 plugin->ext_addr->address_length));
3261#if BUILD_HTTPS 3254#if BUILD_HTTPS
3262 plugin->env->notify_address (plugin->env->cls, 3255 plugin->env->notify_address(plugin->env->cls,
3263 GNUNET_NO, 3256 GNUNET_NO,
3264 plugin->ext_addr); 3257 plugin->ext_addr);
3265#else 3258#else
3266 plugin->env->notify_address (plugin->env->cls, 3259 plugin->env->notify_address(plugin->env->cls,
3267 GNUNET_NO, 3260 GNUNET_NO,
3268 plugin->ext_addr); 3261 plugin->ext_addr);
3269#endif 3262#endif
3270 GNUNET_HELLO_address_free (plugin->ext_addr); 3263 GNUNET_HELLO_address_free(plugin->ext_addr);
3271 plugin->ext_addr = NULL; 3264 plugin->ext_addr = NULL;
3272 } 3265 }
3273 3266
3274 /* Stop to report addresses to transport service */ 3267 /* Stop to report addresses to transport service */
3275 server_stop_report_addresses (plugin); 3268 server_stop_report_addresses(plugin);
3276 if (NULL != plugin->server_v4_task) 3269 if (NULL != plugin->server_v4_task)
3277 { 3270 {
3278 GNUNET_SCHEDULER_cancel (plugin->server_v4_task); 3271 GNUNET_SCHEDULER_cancel(plugin->server_v4_task);
3279 plugin->server_v4_task = NULL; 3272 plugin->server_v4_task = NULL;
3280 } 3273 }
3281 3274
3282 if (NULL != plugin->server_v6_task) 3275 if (NULL != plugin->server_v6_task)
3283 { 3276 {
3284 GNUNET_SCHEDULER_cancel (plugin->server_v6_task); 3277 GNUNET_SCHEDULER_cancel(plugin->server_v6_task);
3285 plugin->server_v6_task = NULL; 3278 plugin->server_v6_task = NULL;
3286 } 3279 }
3287#if BUILD_HTTPS 3280#if BUILD_HTTPS
3288 GNUNET_free_non_null (plugin->crypto_init); 3281 GNUNET_free_non_null(plugin->crypto_init);
3289 GNUNET_free_non_null (plugin->cert); 3282 GNUNET_free_non_null(plugin->cert);
3290 GNUNET_free_non_null (plugin->key); 3283 GNUNET_free_non_null(plugin->key);
3291#endif 3284#endif
3292 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 3285 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
3293 &destroy_session_shutdown_cb, 3286 &destroy_session_shutdown_cb,
3294 plugin); 3287 plugin);
3295 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); 3288 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions);
3296 plugin->sessions = NULL; 3289 plugin->sessions = NULL;
3297 if (NULL != plugin->server_v4) 3290 if (NULL != plugin->server_v4)
3298 { 3291 {
3299 MHD_stop_daemon (plugin->server_v4); 3292 MHD_stop_daemon(plugin->server_v4);
3300 plugin->server_v4 = NULL; 3293 plugin->server_v4 = NULL;
3301 } 3294 }
3302 if (NULL != plugin->server_v6) 3295 if (NULL != plugin->server_v6)
3303 { 3296 {
3304 MHD_stop_daemon (plugin->server_v6); 3297 MHD_stop_daemon(plugin->server_v6);
3305 plugin->server_v6 = NULL; 3298 plugin->server_v6 = NULL;
3306 } 3299 }
3307 /* Clean up */ 3300 /* Clean up */
3308 GNUNET_free_non_null (plugin->external_hostname); 3301 GNUNET_free_non_null(plugin->external_hostname);
3309 GNUNET_free_non_null (plugin->ext_addr); 3302 GNUNET_free_non_null(plugin->ext_addr);
3310 GNUNET_free_non_null (plugin->server_addr_v4); 3303 GNUNET_free_non_null(plugin->server_addr_v4);
3311 GNUNET_free_non_null (plugin->server_addr_v6); 3304 GNUNET_free_non_null(plugin->server_addr_v6);
3312 regfree (&plugin->url_regex); 3305 regfree(&plugin->url_regex);
3313 3306
3314 LOG (GNUNET_ERROR_TYPE_DEBUG, 3307 LOG(GNUNET_ERROR_TYPE_DEBUG,
3315 _("Shutdown for plugin `%s' complete\n"), 3308 _("Shutdown for plugin `%s' complete\n"),
3316 plugin->name); 3309 plugin->name);
3317 3310
3318 GNUNET_free (plugin); 3311 GNUNET_free(plugin);
3319 GNUNET_free (api); 3312 GNUNET_free(api);
3320 return NULL; 3313 return NULL;
3321} 3314}
3322 3315
@@ -3333,13 +3326,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3333 * @return string representing the same address 3326 * @return string representing the same address
3334 */ 3327 */
3335static const char * 3328static const char *
3336http_server_plugin_address_to_string (void *cls, 3329http_server_plugin_address_to_string(void *cls,
3337 const void *addr, 3330 const void *addr,
3338 size_t addrlen) 3331 size_t addrlen)
3339{ 3332{
3340 return http_common_plugin_address_to_string (PLUGIN_NAME, 3333 return http_common_plugin_address_to_string(PLUGIN_NAME,
3341 addr, 3334 addr,
3342 addrlen); 3335 addrlen);
3343} 3336}
3344 3337
3345 3338
@@ -3351,8 +3344,8 @@ http_server_plugin_address_to_string (void *cls,
3351 * @return the network type in HBO or #GNUNET_SYSERR 3344 * @return the network type in HBO or #GNUNET_SYSERR
3352 */ 3345 */
3353static enum GNUNET_NetworkType 3346static enum GNUNET_NetworkType
3354http_server_plugin_get_network (void *cls, 3347http_server_plugin_get_network(void *cls,
3355 struct GNUNET_ATS_Session *session) 3348 struct GNUNET_ATS_Session *session)
3356{ 3349{
3357 return session->scope; 3350 return session->scope;
3358} 3351}
@@ -3366,13 +3359,13 @@ http_server_plugin_get_network (void *cls,
3366 * @return the network type 3359 * @return the network type
3367 */ 3360 */
3368static enum GNUNET_NetworkType 3361static enum GNUNET_NetworkType
3369http_server_plugin_get_network_for_address (void *cls, 3362http_server_plugin_get_network_for_address(void *cls,
3370 const struct GNUNET_HELLO_Address *address) 3363 const struct GNUNET_HELLO_Address *address)
3371{ 3364{
3372 struct HTTP_Server_Plugin *plugin = cls; 3365 struct HTTP_Server_Plugin *plugin = cls;
3373 3366
3374 return http_common_get_network_for_address (plugin->env, 3367 return http_common_get_network_for_address(plugin->env,
3375 address); 3368 address);
3376} 3369}
3377 3370
3378 3371
@@ -3387,24 +3380,24 @@ http_server_plugin_get_network_for_address (void *cls,
3387 * @param delay new delay to use for receiving 3380 * @param delay new delay to use for receiving
3388 */ 3381 */
3389static void 3382static void
3390http_server_plugin_update_inbound_delay (void *cls, 3383http_server_plugin_update_inbound_delay(void *cls,
3391 const struct GNUNET_PeerIdentity *peer, 3384 const struct GNUNET_PeerIdentity *peer,
3392 struct GNUNET_ATS_Session *session, 3385 struct GNUNET_ATS_Session *session,
3393 struct GNUNET_TIME_Relative delay) 3386 struct GNUNET_TIME_Relative delay)
3394{ 3387{
3395 session->next_receive = GNUNET_TIME_relative_to_absolute (delay); 3388 session->next_receive = GNUNET_TIME_relative_to_absolute(delay);
3396 LOG (GNUNET_ERROR_TYPE_DEBUG, 3389 LOG(GNUNET_ERROR_TYPE_DEBUG,
3397 "New inbound delay %s\n", 3390 "New inbound delay %s\n",
3398 GNUNET_STRINGS_relative_time_to_string (delay, 3391 GNUNET_STRINGS_relative_time_to_string(delay,
3399 GNUNET_NO)); 3392 GNUNET_NO));
3400 if (NULL != session->recv_wakeup_task) 3393 if (NULL != session->recv_wakeup_task)
3401 { 3394 {
3402 GNUNET_SCHEDULER_cancel (session->recv_wakeup_task); 3395 GNUNET_SCHEDULER_cancel(session->recv_wakeup_task);
3403 session->recv_wakeup_task 3396 session->recv_wakeup_task
3404 = GNUNET_SCHEDULER_add_delayed (delay, 3397 = GNUNET_SCHEDULER_add_delayed(delay,
3405 &server_wake_up, 3398 &server_wake_up,
3406 session); 3399 session);
3407 } 3400 }
3408} 3401}
3409 3402
3410 3403
@@ -3418,16 +3411,16 @@ http_server_plugin_update_inbound_delay (void *cls,
3418 * @return #GNUNET_OK (continue to iterate) 3411 * @return #GNUNET_OK (continue to iterate)
3419 */ 3412 */
3420static int 3413static int
3421send_session_info_iter (void *cls, 3414send_session_info_iter(void *cls,
3422 const struct GNUNET_PeerIdentity *peer, 3415 const struct GNUNET_PeerIdentity *peer,
3423 void *value) 3416 void *value)
3424{ 3417{
3425 struct HTTP_Server_Plugin *plugin = cls; 3418 struct HTTP_Server_Plugin *plugin = cls;
3426 struct GNUNET_ATS_Session *session = value; 3419 struct GNUNET_ATS_Session *session = value;
3427 3420
3428 notify_session_monitor (plugin, 3421 notify_session_monitor(plugin,
3429 session, 3422 session,
3430 GNUNET_TRANSPORT_SS_INIT); 3423 GNUNET_TRANSPORT_SS_INIT);
3431 return GNUNET_OK; 3424 return GNUNET_OK;
3432} 3425}
3433 3426
@@ -3445,22 +3438,22 @@ send_session_info_iter (void *cls,
3445 * @param sic_cls closure for @a sic 3438 * @param sic_cls closure for @a sic
3446 */ 3439 */
3447static void 3440static void
3448http_server_plugin_setup_monitor (void *cls, 3441http_server_plugin_setup_monitor(void *cls,
3449 GNUNET_TRANSPORT_SessionInfoCallback sic, 3442 GNUNET_TRANSPORT_SessionInfoCallback sic,
3450 void *sic_cls) 3443 void *sic_cls)
3451{ 3444{
3452 struct HTTP_Server_Plugin *plugin = cls; 3445 struct HTTP_Server_Plugin *plugin = cls;
3453 3446
3454 plugin->sic = sic; 3447 plugin->sic = sic;
3455 plugin->sic_cls = sic_cls; 3448 plugin->sic_cls = sic_cls;
3456 if (NULL != sic) 3449 if (NULL != sic)
3457 { 3450 {
3458 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 3451 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
3459 &send_session_info_iter, 3452 &send_session_info_iter,
3460 plugin); 3453 plugin);
3461 /* signal end of first iteration */ 3454 /* signal end of first iteration */
3462 sic (sic_cls, NULL, NULL); 3455 sic(sic_cls, NULL, NULL);
3463 } 3456 }
3464} 3457}
3465 3458
3466 3459
@@ -3471,29 +3464,29 @@ http_server_plugin_setup_monitor (void *cls,
3471 * @return api 3464 * @return api
3472 */ 3465 */
3473void * 3466void *
3474LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) 3467LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
3475{ 3468{
3476 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3469 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3477 struct GNUNET_TRANSPORT_PluginFunctions *api; 3470 struct GNUNET_TRANSPORT_PluginFunctions *api;
3478 struct HTTP_Server_Plugin *plugin; 3471 struct HTTP_Server_Plugin *plugin;
3479 3472
3480 if (NULL == env->receive) 3473 if (NULL == env->receive)
3481 { 3474 {
3482 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3475 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3483 initialze the plugin or the API */ 3476 initialze the plugin or the API */
3484 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3477 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3485 api->cls = NULL; 3478 api->cls = NULL;
3486 api->address_to_string = &http_server_plugin_address_to_string; 3479 api->address_to_string = &http_server_plugin_address_to_string;
3487 api->string_to_address = &http_common_plugin_string_to_address; 3480 api->string_to_address = &http_common_plugin_string_to_address;
3488 api->address_pretty_printer = &http_common_plugin_address_pretty_printer; 3481 api->address_pretty_printer = &http_common_plugin_address_pretty_printer;
3489 return api; 3482 return api;
3490 } 3483 }
3491 plugin = GNUNET_new (struct HTTP_Server_Plugin); 3484 plugin = GNUNET_new(struct HTTP_Server_Plugin);
3492 plugin->env = env; 3485 plugin->env = env;
3493 plugin->sessions = GNUNET_CONTAINER_multipeermap_create (128, 3486 plugin->sessions = GNUNET_CONTAINER_multipeermap_create(128,
3494 GNUNET_YES); 3487 GNUNET_YES);
3495 3488
3496 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3489 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3497 api->cls = plugin; 3490 api->cls = plugin;
3498 api->send = &http_server_plugin_send; 3491 api->send = &http_server_plugin_send;
3499 api->disconnect_peer = &http_server_plugin_disconnect_peer; 3492 api->disconnect_peer = &http_server_plugin_disconnect_peer;
@@ -3519,51 +3512,51 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3519#endif 3512#endif
3520 3513
3521 if (GNUNET_YES == 3514 if (GNUNET_YES ==
3522 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3515 GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
3523 plugin->name, 3516 plugin->name,
3524 "TCP_STEALTH")) 3517 "TCP_STEALTH"))
3525 { 3518 {
3526#ifdef TCP_STEALTH 3519#ifdef TCP_STEALTH
3527 plugin->options |= HTTP_OPTIONS_TCP_STEALTH; 3520 plugin->options |= HTTP_OPTIONS_TCP_STEALTH;
3528#else 3521#else
3529 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3522 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3530 _("TCP_STEALTH not supported on this platform.\n")); 3523 _("TCP_STEALTH not supported on this platform.\n"));
3531 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3524 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
3532 return NULL; 3525 return NULL;
3533#endif 3526#endif
3534 } 3527 }
3535 3528
3536 /* Compile URL regex */ 3529 /* Compile URL regex */
3537 if (regcomp (&plugin->url_regex, 3530 if (regcomp(&plugin->url_regex,
3538 URL_REGEX, 3531 URL_REGEX,
3539 REG_EXTENDED)) 3532 REG_EXTENDED))
3540 { 3533 {
3541 LOG (GNUNET_ERROR_TYPE_ERROR, 3534 LOG(GNUNET_ERROR_TYPE_ERROR,
3542 _("Unable to compile URL regex\n")); 3535 _("Unable to compile URL regex\n"));
3543 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3536 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
3544 return NULL; 3537 return NULL;
3545 } 3538 }
3546 3539
3547 /* Configure plugin */ 3540 /* Configure plugin */
3548 if (GNUNET_SYSERR == server_configure_plugin (plugin)) 3541 if (GNUNET_SYSERR == server_configure_plugin(plugin))
3549 { 3542 {
3550 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3543 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
3551 return NULL; 3544 return NULL;
3552 } 3545 }
3553 3546
3554 /* Check IPv6 support */ 3547 /* Check IPv6 support */
3555 if (GNUNET_YES == plugin->use_ipv6) 3548 if (GNUNET_YES == plugin->use_ipv6)
3556 plugin->use_ipv6 = server_check_ipv6_support (plugin); 3549 plugin->use_ipv6 = server_check_ipv6_support(plugin);
3557 3550
3558 /* Report addresses to transport service */ 3551 /* Report addresses to transport service */
3559 if (GNUNET_NO == plugin->external_only) 3552 if (GNUNET_NO == plugin->external_only)
3560 server_start_report_addresses (plugin); 3553 server_start_report_addresses(plugin);
3561 3554
3562 if (GNUNET_SYSERR == server_start (plugin)) 3555 if (GNUNET_SYSERR == server_start(plugin))
3563 { 3556 {
3564 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3557 LIBGNUNET_PLUGIN_TRANSPORT_DONE(api);
3565 return NULL; 3558 return NULL;
3566 } 3559 }
3567 return api; 3560 return api;
3568} 3561}
3569 3562
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index 1c61f07d7..d7b87e7b1 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_smtp.c 22 * @file transport/plugin_transport_smtp.c
@@ -53,9 +53,7 @@
53/** 53/**
54 * Host-Address in a SMTP network. 54 * Host-Address in a SMTP network.
55 */ 55 */
56typedef struct 56typedef struct {
57{
58
59 /** 57 /**
60 * Filter line that every sender must include in the E-mails such 58 * Filter line that every sender must include in the E-mails such
61 * that the receiver can effectively filter out the GNUnet traffic 59 * that the receiver can effectively filter out the GNUnet traffic
@@ -69,7 +67,6 @@ typedef struct
69 * of a multiple of 8 bytes long. 67 * of a multiple of 8 bytes long.
70 */ 68 */
71 char senderAddress[0]; 69 char senderAddress[0];
72
73} EmailAddress; 70} EmailAddress;
74 71
75GNUNET_NETWORK_STRUCT_BEGIN 72GNUNET_NETWORK_STRUCT_BEGIN
@@ -78,15 +75,13 @@ GNUNET_NETWORK_STRUCT_BEGIN
78 * Encapsulation of a GNUnet message in the SMTP mail body (before 75 * Encapsulation of a GNUnet message in the SMTP mail body (before
79 * base64 encoding). 76 * base64 encoding).
80 */ 77 */
81typedef struct 78typedef struct {
82{
83 GNUNET_MessageHeader header; 79 GNUNET_MessageHeader header;
84 80
85 /** 81 /**
86 * What is the identity of the sender (GNUNET_hash of public key) 82 * What is the identity of the sender (GNUNET_hash of public key)
87 */ 83 */
88 GNUNET_PeerIdentity sender; 84 GNUNET_PeerIdentity sender;
89
90} SMTPMessage; 85} SMTPMessage;
91GNUNET_NETWORK_STRUCT_END 86GNUNET_NETWORK_STRUCT_END
92 87
@@ -148,13 +143,13 @@ static GNUNET_CronTime last_transmission;
148 143
149/* ********************* the real stuff ******************* */ 144/* ********************* the real stuff ******************* */
150 145
151#define strAUTOncmp(a,b) strncmp(a,b,strlen(b)) 146#define strAUTOncmp(a, b) strncmp(a, b, strlen(b))
152 147
153/** 148/**
154 * Listen to the pipe, decode messages and send to core. 149 * Listen to the pipe, decode messages and send to core.
155 */ 150 */
156static void * 151static void *
157listenAndDistribute (void *unused) 152listenAndDistribute(void *unused)
158{ 153{
159 char *line; 154 char *line;
160 unsigned int linesize; 155 unsigned int linesize;
@@ -168,92 +163,92 @@ listenAndDistribute (void *unused)
168 unsigned int pos; 163 unsigned int pos;
169 164
170 linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2) / MAX_CHAR_PER_LINE; /* maximum size of a line supported */ 165 linesize = ((GNUNET_MAX_BUFFER_SIZE * 4 / 3) + 8) * (MAX_CHAR_PER_LINE + 2) / MAX_CHAR_PER_LINE; /* maximum size of a line supported */
171 line = GNUNET_malloc (linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */ 166 line = GNUNET_malloc(linesize + 2); /* 2 bytes for off-by-one errors, just to be safe... */
172 167
173#define READLINE(l,limit) \ 168#define READLINE(l, limit) \
174 do { retl = fgets(l, (limit), fdes); \ 169 do { retl = fgets(l, (limit), fdes); \
175 if ( (retl == NULL) || (smtp_shutdown == GNUNET_YES)) {\ 170 if ((retl == NULL) || (smtp_shutdown == GNUNET_YES)) { \
176 goto END; \ 171 goto END; \
177 }\ 172 } \
178 if (core_api->load_monitor != NULL) \ 173 if (core_api->load_monitor != NULL) \
179 GNUNET_network_monitor_notify_transmission(core_api->load_monitor, GNUNET_ND_DOWNLOAD, strlen(retl)); \ 174 GNUNET_network_monitor_notify_transmission (core_api->load_monitor, GNUNET_ND_DOWNLOAD, strlen(retl)); \
180 } while (0) 175 } while (0)
181 176
182 177
183 while (smtp_shutdown == GNUNET_NO) 178 while (smtp_shutdown == GNUNET_NO)
184 {
185 fd = OPEN (pipename, O_RDONLY | O_ASYNC);
186 if (fd == -1)
187 { 179 {
188 if (smtp_shutdown == GNUNET_NO) 180 fd = OPEN(pipename, O_RDONLY | O_ASYNC);
189 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); 181 if (fd == -1)
190 continue; 182 {
191 } 183 if (smtp_shutdown == GNUNET_NO)
192 fdes = fdopen (fd, "r"); 184 GNUNET_thread_sleep(5 * GNUNET_CRON_SECONDS);
193 while (smtp_shutdown == GNUNET_NO) 185 continue;
194 { 186 }
195 /* skip until end of header */ 187 fdes = fdopen(fd, "r");
196 do 188 while (smtp_shutdown == GNUNET_NO)
197 { 189 {
198 READLINE (line, linesize); 190 /* skip until end of header */
199 } 191 do
200 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ 192 {
201 READLINE (line, linesize); /* read base64 encoded message; decode, process */ 193 READLINE(line, linesize);
202 pos = 0; 194 }
203 while (1) 195 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */
204 { 196 READLINE(line, linesize); /* read base64 encoded message; decode, process */
205 pos = strlen (line) - 1; /* ignore new line */ 197 pos = 0;
206 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ 198 while (1)
207 if ((line[pos] == '\r') || (line[pos] == '\n')) 199 {
208 break; /* empty line => end of message! */ 200 pos = strlen(line) - 1; /* ignore new line */
209 } 201 READLINE(&line[pos], linesize - pos); /* read base64 encoded message; decode, process */
210 size = GNUNET_STRINGS_base64_decode (line, pos, &out); 202 if ((line[pos] == '\r') || (line[pos] == '\n'))
211 if (size < sizeof (SMTPMessage)) 203 break; /* empty line => end of message! */
212 { 204 }
213 GNUNET_GE_BREAK (ectx, 0); 205 size = GNUNET_STRINGS_base64_decode(line, pos, &out);
214 GNUNET_free (out); 206 if (size < sizeof(SMTPMessage))
215 goto END; 207 {
216 } 208 GNUNET_GE_BREAK(ectx, 0);
217 209 GNUNET_free(out);
218 mp = (SMTPMessage *) &out[size - sizeof (SMTPMessage)]; 210 goto END;
219 if (ntohs (mp->header.size) != size) 211 }
220 { 212
221 GNUNET_GE_LOG (ectx, 213 mp = (SMTPMessage *)&out[size - sizeof(SMTPMessage)];
222 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 214 if (ntohs(mp->header.size) != size)
223 _("Received malformed message via %s. Ignored.\n"), 215 {
224 "SMTP"); 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");
225#if DEBUG_SMTP 220#if DEBUG_SMTP
226 GNUNET_GE_LOG (ectx, 221 GNUNET_GE_LOG(ectx,
227 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 222 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
228 "Size returned by base64=%d, in the msg=%d.\n", size, 223 "Size returned by base64=%d, in the msg=%d.\n", size,
229 ntohl (mp->size)); 224 ntohl(mp->size));
230#endif 225#endif
231 GNUNET_free (out); 226 GNUNET_free(out);
232 goto END; 227 goto END;
233 } 228 }
234 if (stats != NULL) 229 if (stats != NULL)
235 stats->change (stat_bytesReceived, size); 230 stats->change(stat_bytesReceived, size);
236 coreMP = GNUNET_new (GNUNET_TransportPacket); 231 coreMP = GNUNET_new(GNUNET_TransportPacket);
237 coreMP->msg = out; 232 coreMP->msg = out;
238 coreMP->size = size - sizeof (SMTPMessage); 233 coreMP->size = size - sizeof(SMTPMessage);
239 coreMP->tsession = NULL; 234 coreMP->tsession = NULL;
240 coreMP->sender = mp->sender; 235 coreMP->sender = mp->sender;
241#if DEBUG_SMTP 236#if DEBUG_SMTP
242 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 237 GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
243 "SMTP message passed to the core.\n"); 238 "SMTP message passed to the core.\n");
244#endif 239#endif
245 240
246 core_api->receive (coreMP); 241 core_api->receive(coreMP);
247 } 242 }
248END: 243END:
249#if DEBUG_SMTP 244#if DEBUG_SMTP
250 GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 245 GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
251 "SMTP message processed.\n"); 246 "SMTP message processed.\n");
252#endif 247#endif
253 if (fdes != NULL) 248 if (fdes != NULL)
254 fclose (fdes); 249 fclose(fdes);
255 } 250 }
256 GNUNET_free (line); 251 GNUNET_free(line);
257 return NULL; 252 return NULL;
258} 253}
259 254
@@ -269,20 +264,20 @@ END:
269 * @return GNUNET_OK on success, GNUNET_SYSERR on error 264 * @return GNUNET_OK on success, GNUNET_SYSERR on error
270 */ 265 */
271static int 266static int
272api_verify_hello (const GNUNET_MessageHello * hello) 267api_verify_hello(const GNUNET_MessageHello * hello)
273{ 268{
274 const EmailAddress *maddr; 269 const EmailAddress *maddr;
275 270
276 maddr = (const EmailAddress *) &hello[1]; 271 maddr = (const EmailAddress *)&hello[1];
277 if ((ntohs (hello->header.size) != 272 if ((ntohs(hello->header.size) !=
278 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) || 273 sizeof(GNUNET_MessageHello) + ntohs(hello->senderAddressSize)) ||
279 (maddr->senderAddress 274 (maddr->senderAddress
280 [ntohs (hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0')) 275 [ntohs(hello->senderAddressSize) - 1 - FILTER_STRING_SIZE] != '\0'))
281 { 276 {
282 GNUNET_GE_BREAK (ectx, 0); 277 GNUNET_GE_BREAK(ectx, 0);
283 return GNUNET_SYSERR; /* obviously invalid */ 278 return GNUNET_SYSERR; /* obviously invalid */
284 } 279 }
285 if (NULL == strstr (maddr->filter, ": ")) 280 if (NULL == strstr(maddr->filter, ": "))
286 return GNUNET_SYSERR; 281 return GNUNET_SYSERR;
287 return GNUNET_OK; 282 return GNUNET_OK;
288} 283}
@@ -295,65 +290,64 @@ api_verify_hello (const GNUNET_MessageHello * hello)
295 * @return hello on success, NULL on error 290 * @return hello on success, NULL on error
296 */ 291 */
297static GNUNET_MessageHello * 292static GNUNET_MessageHello *
298api_create_hello () 293api_create_hello()
299{ 294{
300 GNUNET_MessageHello *msg; 295 GNUNET_MessageHello *msg;
301 char *filter; 296 char *filter;
302 EmailAddress *haddr; 297 EmailAddress *haddr;
303 int i; 298 int i;
304 299
305 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "FILTER", 300 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "FILTER",
306 "X-mailer: GNUnet", &filter); 301 "X-mailer: GNUnet", &filter);
307 if (NULL == strstr (filter, ": ")) 302 if (NULL == strstr(filter, ": "))
308 { 303 {
309 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 304 GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
310 _("SMTP filter string to invalid, lacks ': '\n")); 305 _("SMTP filter string to invalid, lacks ': '\n"));
311 GNUNET_free (filter); 306 GNUNET_free(filter);
312 return NULL; 307 return NULL;
313 } 308 }
314 309
315 if (strlen (filter) > FILTER_STRING_SIZE) 310 if (strlen(filter) > FILTER_STRING_SIZE)
316 { 311 {
317 filter[FILTER_STRING_SIZE] = '\0'; 312 filter[FILTER_STRING_SIZE] = '\0';
318 GNUNET_GE_LOG (ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 313 GNUNET_GE_LOG(ectx, GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
319 _("SMTP filter string to long, capped to `%s'\n"), filter); 314 _("SMTP filter string to long, capped to `%s'\n"), filter);
320 } 315 }
321 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */ 316 i = (strlen(email) + 8) & (~7); /* make multiple of 8 */
322 msg = 317 msg =
323 GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i); 318 GNUNET_malloc(sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i);
324 memset (msg, 0, sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i); 319 memset(msg, 0, sizeof(GNUNET_MessageHello) + sizeof(EmailAddress) + i);
325 haddr = (EmailAddress *) &msg[1]; 320 haddr = (EmailAddress *)&msg[1];
326 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE); 321 memset(&haddr->filter[0], 0, FILTER_STRING_SIZE);
327 strcpy (&haddr->filter[0], filter); 322 strcpy(&haddr->filter[0], filter);
328 GNUNET_memcpy (&haddr->senderAddress[0], email, strlen (email) + 1); 323 GNUNET_memcpy(&haddr->senderAddress[0], email, strlen(email) + 1);
329 msg->senderAddressSize = htons (strlen (email) + 1 + sizeof (EmailAddress)); 324 msg->senderAddressSize = htons(strlen(email) + 1 + sizeof(EmailAddress));
330 msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP); 325 msg->protocol = htons(GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP);
331 msg->MTU = htonl (smtpAPI.mtu); 326 msg->MTU = htonl(smtpAPI.mtu);
332 msg->header.size = htons (GNUNET_sizeof_hello (msg)); 327 msg->header.size = htons(GNUNET_sizeof_hello(msg));
333 if (api_verify_hello (msg) == GNUNET_SYSERR) 328 if (api_verify_hello(msg) == GNUNET_SYSERR)
334 GNUNET_GE_ASSERT (ectx, 0); 329 GNUNET_GE_ASSERT(ectx, 0);
335 GNUNET_free (filter); 330 GNUNET_free(filter);
336 return msg; 331 return msg;
337} 332}
338 333
339struct GetMessageClosure 334struct GetMessageClosure {
340{
341 unsigned int esize; 335 unsigned int esize;
342 unsigned int pos; 336 unsigned int pos;
343 char *ebody; 337 char *ebody;
344}; 338};
345 339
346static const char * 340static const char *
347get_message (void **buf, int *len, void *cls) 341get_message(void **buf, int *len, void *cls)
348{ 342{
349 struct GetMessageClosure *gmc = cls; 343 struct GetMessageClosure *gmc = cls;
350 344
351 *buf = NULL; 345 *buf = NULL;
352 if (len == NULL) 346 if (len == NULL)
353 { 347 {
354 gmc->pos = 0; 348 gmc->pos = 0;
355 return NULL; 349 return NULL;
356 } 350 }
357 if (gmc->pos == gmc->esize) 351 if (gmc->pos == gmc->esize)
358 return NULL; /* done */ 352 return NULL; /* done */
359 *len = gmc->esize; 353 *len = gmc->esize;
@@ -371,8 +365,8 @@ get_message (void **buf, int *len, void *cls)
371 * @return GNUNET_SYSERR on error, GNUNET_OK on success 365 * @return GNUNET_SYSERR on error, GNUNET_OK on success
372 */ 366 */
373static int 367static int
374api_send (GNUNET_TSession * tsession, const void *msg, const unsigned int size, 368api_send(GNUNET_TSession * tsession, const void *msg, const unsigned int size,
375 int important) 369 int important)
376{ 370{
377 const GNUNET_MessageHello *hello; 371 const GNUNET_MessageHello *hello;
378 const EmailAddress *haddr; 372 const EmailAddress *haddr;
@@ -392,139 +386,139 @@ api_send (GNUNET_TSession * tsession, const void *msg, const unsigned int size,
392 if (smtp_shutdown == GNUNET_YES) 386 if (smtp_shutdown == GNUNET_YES)
393 return GNUNET_SYSERR; 387 return GNUNET_SYSERR;
394 if ((size == 0) || (size > smtpAPI.mtu)) 388 if ((size == 0) || (size > smtpAPI.mtu))
395 { 389 {
396 GNUNET_GE_BREAK (ectx, 0); 390 GNUNET_GE_BREAK(ectx, 0);
397 return GNUNET_SYSERR; 391 return GNUNET_SYSERR;
398 } 392 }
399 now = GNUNET_get_time (); 393 now = GNUNET_get_time();
400 if ((important != GNUNET_YES) && 394 if ((important != GNUNET_YES) &&
401 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) 395 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS)
402 return GNUNET_NO; /* rate too high */ 396 return GNUNET_NO; /* rate too high */
403 last_transmission = now; 397 last_transmission = now;
404 398
405 hello = (const GNUNET_MessageHello *) tsession->internal; 399 hello = (const GNUNET_MessageHello *)tsession->internal;
406 if (hello == NULL) 400 if (hello == NULL)
407 return GNUNET_SYSERR; 401 return GNUNET_SYSERR;
408 GNUNET_mutex_lock (lock); 402 GNUNET_mutex_lock(lock);
409 session = smtp_create_session (); 403 session = smtp_create_session();
410 if (session == NULL) 404 if (session == NULL)
411 { 405 {
412 GNUNET_GE_LOG (ectx, 406 GNUNET_GE_LOG(ectx,
413 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 407 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
414 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), 408 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"),
415 "smtp_create_session", smtp_strerror (smtp_errno (), ebuf, 409 "smtp_create_session", smtp_strerror(smtp_errno(), ebuf,
416 EBUF_LEN)); 410 EBUF_LEN));
417 GNUNET_mutex_unlock (lock); 411 GNUNET_mutex_unlock(lock);
418 return GNUNET_SYSERR; 412 return GNUNET_SYSERR;
419 } 413 }
420 if (0 == smtp_set_server (session, smtp_server_name)) 414 if (0 == smtp_set_server(session, smtp_server_name))
421 { 415 {
422 GNUNET_GE_LOG (ectx, 416 GNUNET_GE_LOG(ectx,
423 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 417 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
424 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"), 418 GNUNET_GE_IMMEDIATE, _("SMTP: `%s' failed: %s.\n"),
425 "smtp_set_server", smtp_strerror (smtp_errno (), ebuf, 419 "smtp_set_server", smtp_strerror(smtp_errno(), ebuf,
426 EBUF_LEN)); 420 EBUF_LEN));
427 smtp_destroy_session (session); 421 smtp_destroy_session(session);
428 GNUNET_mutex_unlock (lock); 422 GNUNET_mutex_unlock(lock);
429 return GNUNET_SYSERR; 423 return GNUNET_SYSERR;
430 } 424 }
431 haddr = (const EmailAddress *) &hello[1]; 425 haddr = (const EmailAddress *)&hello[1];
432 message = smtp_add_message (session); 426 message = smtp_add_message(session);
433 if (message == NULL) 427 if (message == NULL)
434 { 428 {
435 GNUNET_GE_LOG (ectx, 429 GNUNET_GE_LOG(ectx,
436 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 430 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
437 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 431 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
438 "smtp_add_message", smtp_strerror (smtp_errno (), ebuf, 432 "smtp_add_message", smtp_strerror(smtp_errno(), ebuf,
439 EBUF_LEN)); 433 EBUF_LEN));
440 smtp_destroy_session (session); 434 smtp_destroy_session(session);
441 GNUNET_mutex_unlock (lock); 435 GNUNET_mutex_unlock(lock);
442 return GNUNET_SYSERR; 436 return GNUNET_SYSERR;
443 } 437 }
444 smtp_set_header (message, "To", NULL, haddr->senderAddress); 438 smtp_set_header(message, "To", NULL, haddr->senderAddress);
445 smtp_set_header (message, "From", NULL, email); 439 smtp_set_header(message, "From", NULL, email);
446 440
447 filter = GNUNET_strdup (haddr->filter); 441 filter = GNUNET_strdup(haddr->filter);
448 fvalue = strstr (filter, ": "); 442 fvalue = strstr(filter, ": ");
449 GNUNET_GE_ASSERT (NULL, NULL != fvalue); 443 GNUNET_GE_ASSERT(NULL, NULL != fvalue);
450 fvalue[0] = '\0'; 444 fvalue[0] = '\0';
451 fvalue += 2; 445 fvalue += 2;
452 if (0 == smtp_set_header (message, filter, fvalue)) 446 if (0 == smtp_set_header(message, filter, fvalue))
453 { 447 {
454 GNUNET_GE_LOG (ectx, 448 GNUNET_GE_LOG(ectx,
455 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 449 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
456 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 450 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
457 "smtp_set_header", smtp_strerror (smtp_errno (), ebuf, 451 "smtp_set_header", smtp_strerror(smtp_errno(), ebuf,
458 EBUF_LEN)); 452 EBUF_LEN));
459 smtp_destroy_session (session); 453 smtp_destroy_session(session);
460 GNUNET_mutex_unlock (lock); 454 GNUNET_mutex_unlock(lock);
461 GNUNET_free (filter); 455 GNUNET_free(filter);
462 return GNUNET_SYSERR; 456 return GNUNET_SYSERR;
463 } 457 }
464 GNUNET_free (filter); 458 GNUNET_free(filter);
465 m = GNUNET_malloc (size + sizeof (SMTPMessage)); 459 m = GNUNET_malloc(size + sizeof(SMTPMessage));
466 GNUNET_memcpy (m, msg, size); 460 GNUNET_memcpy(m, msg, size);
467 mp = (SMTPMessage *) &m[size]; 461 mp = (SMTPMessage *)&m[size];
468 mp->header.size = htons (size + sizeof (SMTPMessage)); 462 mp->header.size = htons(size + sizeof(SMTPMessage));
469 mp->header.type = htons (0); 463 mp->header.type = htons(0);
470 mp->sender = *core_api->my_identity; 464 mp->sender = *core_api->my_identity;
471 gm_cls.ebody = NULL; 465 gm_cls.ebody = NULL;
472 gm_cls.pos = 0; 466 gm_cls.pos = 0;
473 gm_cls.esize = GNUNET_STRINGS_base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody); 467 gm_cls.esize = GNUNET_STRINGS_base64_encode(m, size + sizeof(SMTPMessage), &gm_cls.ebody);
474 GNUNET_free (m); 468 GNUNET_free(m);
475 if (0 == smtp_size_set_estimate (message, gm_cls.esize)) 469 if (0 == smtp_size_set_estimate(message, gm_cls.esize))
476 { 470 {
477 GNUNET_GE_LOG (ectx, 471 GNUNET_GE_LOG(ectx,
478 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 472 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
479 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 473 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
480 "smtp_size_set_estimate", smtp_strerror (smtp_errno (), ebuf, 474 "smtp_size_set_estimate", smtp_strerror(smtp_errno(), ebuf,
481 EBUF_LEN)); 475 EBUF_LEN));
482 } 476 }
483 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls)) 477 if (0 == smtp_set_messagecb(message, &get_message, &gm_cls))
484 { 478 {
485 GNUNET_GE_LOG (ectx, 479 GNUNET_GE_LOG(ectx,
486 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 480 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
487 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 481 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
488 "smtp_set_messagecb", smtp_strerror (smtp_errno (), ebuf, 482 "smtp_set_messagecb", smtp_strerror(smtp_errno(), ebuf,
489 EBUF_LEN)); 483 EBUF_LEN));
490 smtp_destroy_session (session); 484 smtp_destroy_session(session);
491 GNUNET_mutex_unlock (lock); 485 GNUNET_mutex_unlock(lock);
492 GNUNET_free (gm_cls.ebody); 486 GNUNET_free(gm_cls.ebody);
493 return GNUNET_SYSERR; 487 return GNUNET_SYSERR;
494 } 488 }
495 recipient = smtp_add_recipient (message, haddr->senderAddress); 489 recipient = smtp_add_recipient(message, haddr->senderAddress);
496 if (recipient == NULL) 490 if (recipient == NULL)
497 { 491 {
498 GNUNET_GE_LOG (ectx, 492 GNUNET_GE_LOG(ectx,
499 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 493 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
500 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 494 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
501 "smtp_add_recipient", smtp_strerror (smtp_errno (), ebuf, 495 "smtp_add_recipient", smtp_strerror(smtp_errno(), ebuf,
502 EBUF_LEN)); 496 EBUF_LEN));
503 smtp_destroy_session (session); 497 smtp_destroy_session(session);
504 GNUNET_mutex_unlock (lock); 498 GNUNET_mutex_unlock(lock);
505 return GNUNET_SYSERR; 499 return GNUNET_SYSERR;
506 } 500 }
507 if (0 == smtp_start_session (session)) 501 if (0 == smtp_start_session(session))
508 { 502 {
509 GNUNET_GE_LOG (ectx, 503 GNUNET_GE_LOG(ectx,
510 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 504 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
511 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"), 505 GNUNET_GE_BULK, _("SMTP: `%s' failed: %s.\n"),
512 "smtp_start_session", smtp_strerror (smtp_errno (), ebuf, 506 "smtp_start_session", smtp_strerror(smtp_errno(), ebuf,
513 EBUF_LEN)); 507 EBUF_LEN));
514 smtp_destroy_session (session); 508 smtp_destroy_session(session);
515 GNUNET_mutex_unlock (lock); 509 GNUNET_mutex_unlock(lock);
516 GNUNET_free (gm_cls.ebody); 510 GNUNET_free(gm_cls.ebody);
517 return GNUNET_SYSERR; 511 return GNUNET_SYSERR;
518 } 512 }
519 if (stats != NULL) 513 if (stats != NULL)
520 stats->change (stat_bytesSent, size); 514 stats->change(stat_bytesSent, size);
521 if (core_api->load_monitor != NULL) 515 if (core_api->load_monitor != NULL)
522 GNUNET_network_monitor_notify_transmission (core_api->load_monitor, 516 GNUNET_network_monitor_notify_transmission(core_api->load_monitor,
523 GNUNET_ND_UPLOAD, gm_cls.esize); 517 GNUNET_ND_UPLOAD, gm_cls.esize);
524 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ 518 smtp_message_reset_status(message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */
525 smtp_destroy_session (session); 519 smtp_destroy_session(session);
526 GNUNET_mutex_unlock (lock); 520 GNUNET_mutex_unlock(lock);
527 GNUNET_free (gm_cls.ebody); 521 GNUNET_free(gm_cls.ebody);
528 return GNUNET_OK; 522 return GNUNET_OK;
529} 523}
530 524
@@ -536,15 +530,15 @@ api_send (GNUNET_TSession * tsession, const void *msg, const unsigned int size,
536 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 530 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
537 */ 531 */
538static int 532static int
539api_connect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr, 533api_connect(const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
540 int may_reuse) 534 int may_reuse)
541{ 535{
542 GNUNET_TSession *tsession; 536 GNUNET_TSession *tsession;
543 537
544 tsession = GNUNET_new (GNUNET_TSession); 538 tsession = GNUNET_new(GNUNET_TSession);
545 tsession->internal = GNUNET_malloc (GNUNET_sizeof_hello (hello)); 539 tsession->internal = GNUNET_malloc(GNUNET_sizeof_hello(hello));
546 tsession->peer = hello->senderIdentity; 540 tsession->peer = hello->senderIdentity;
547 GNUNET_memcpy (tsession->internal, hello, GNUNET_sizeof_hello (hello)); 541 GNUNET_memcpy(tsession->internal, hello, GNUNET_sizeof_hello(hello));
548 tsession->ttype = smtpAPI.protocol_number; 542 tsession->ttype = smtpAPI.protocol_number;
549 (*tsessionPtr) = tsession; 543 (*tsessionPtr) = tsession;
550 return GNUNET_OK; 544 return GNUNET_OK;
@@ -557,14 +551,14 @@ api_connect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
557 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 551 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
558 */ 552 */
559static int 553static int
560api_disconnect (GNUNET_TSession * tsession) 554api_disconnect(GNUNET_TSession * tsession)
561{ 555{
562 if (tsession != NULL) 556 if (tsession != NULL)
563 { 557 {
564 if (tsession->internal != NULL) 558 if (tsession->internal != NULL)
565 GNUNET_free (tsession->internal); 559 GNUNET_free(tsession->internal);
566 GNUNET_free (tsession); 560 GNUNET_free(tsession);
567 } 561 }
568 return GNUNET_OK; 562 return GNUNET_OK;
569} 563}
570 564
@@ -573,18 +567,18 @@ api_disconnect (GNUNET_TSession * tsession)
573 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed 567 * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
574 */ 568 */
575static int 569static int
576api_start_transport_server () 570api_start_transport_server()
577{ 571{
578 smtp_shutdown = GNUNET_NO; 572 smtp_shutdown = GNUNET_NO;
579 /* initialize SMTP network */ 573 /* initialize SMTP network */
580 dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4); 574 dispatchThread = GNUNET_thread_create(&listenAndDistribute, NULL, 1024 * 4);
581 if (dispatchThread == NULL) 575 if (dispatchThread == NULL)
582 { 576 {
583 GNUNET_GE_DIE_STRERROR (ectx, 577 GNUNET_GE_DIE_STRERROR(ectx,
584 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, 578 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
585 "pthread_create"); 579 "pthread_create");
586 return GNUNET_SYSERR; 580 return GNUNET_SYSERR;
587 } 581 }
588 return GNUNET_OK; 582 return GNUNET_OK;
589} 583}
590 584
@@ -593,13 +587,13 @@ api_start_transport_server ()
593 * restarted later! 587 * restarted later!
594 */ 588 */
595static int 589static int
596api_stop_transport_server () 590api_stop_transport_server()
597{ 591{
598 void *unused; 592 void *unused;
599 593
600 smtp_shutdown = GNUNET_YES; 594 smtp_shutdown = GNUNET_YES;
601 GNUNET_thread_stop_sleep (dispatchThread); 595 GNUNET_thread_stop_sleep(dispatchThread);
602 GNUNET_thread_join (dispatchThread, &unused); 596 GNUNET_thread_join(dispatchThread, &unused);
603 return GNUNET_OK; 597 return GNUNET_OK;
604} 598}
605 599
@@ -607,8 +601,8 @@ api_stop_transport_server ()
607 * Convert SMTP hello to an IP address (always fails). 601 * Convert SMTP hello to an IP address (always fails).
608 */ 602 */
609static int 603static int
610api_hello_to_address (const GNUNET_MessageHello * hello, void **sa, 604api_hello_to_address(const GNUNET_MessageHello * hello, void **sa,
611 unsigned int *sa_len) 605 unsigned int *sa_len)
612{ 606{
613 return GNUNET_SYSERR; 607 return GNUNET_SYSERR;
614} 608}
@@ -617,7 +611,7 @@ api_hello_to_address (const GNUNET_MessageHello * hello, void **sa,
617 * Always fails. 611 * Always fails.
618 */ 612 */
619static int 613static int
620api_associate (GNUNET_TSession * tsession) 614api_associate(GNUNET_TSession * tsession)
621{ 615{
622 return GNUNET_SYSERR; /* SMTP connections can never be associated */ 616 return GNUNET_SYSERR; /* SMTP connections can never be associated */
623} 617}
@@ -627,8 +621,8 @@ api_associate (GNUNET_TSession * tsession)
627 * frequency limits to SMTP in the future!). 621 * frequency limits to SMTP in the future!).
628 */ 622 */
629static int 623static int
630api_test_would_try (GNUNET_TSession * tsession, unsigned int size, 624api_test_would_try(GNUNET_TSession * tsession, unsigned int size,
631 int important) 625 int important)
632{ 626{
633 return GNUNET_OK; /* we always try... */ 627 return GNUNET_OK; /* we always try... */
634} 628}
@@ -638,64 +632,64 @@ api_test_would_try (GNUNET_TSession * tsession, unsigned int size,
638 * returns the smtp transport API. 632 * returns the smtp transport API.
639 */ 633 */
640GNUNET_TransportAPI * 634GNUNET_TransportAPI *
641inittransport_smtp (struct GNUNET_CoreAPIForTransport * core) 635inittransport_smtp(struct GNUNET_CoreAPIForTransport * core)
642{ 636{
643 unsigned long long mtu; 637 unsigned long long mtu;
644 struct sigaction sa; 638 struct sigaction sa;
645 639
646 core_api = core; 640 core_api = core;
647 ectx = core->ectx; 641 ectx = core->ectx;
648 if (!GNUNET_GC_have_configuration_value (core_api->cfg, "SMTP", "EMAIL")) 642 if (!GNUNET_GC_have_configuration_value(core_api->cfg, "SMTP", "EMAIL"))
649 { 643 {
650 GNUNET_GE_LOG (ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, 644 GNUNET_GE_LOG(ectx, GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
651 _ 645 _
652 ("No email-address specified, can not start SMTP transport.\n")); 646 ("No email-address specified, can not start SMTP transport.\n"));
653 return NULL; 647 return NULL;
654 } 648 }
655 GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "MTU", 1200, 649 GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "MTU", 1200,
656 SMTP_MESSAGE_SIZE, 650 SMTP_MESSAGE_SIZE,
657 SMTP_MESSAGE_SIZE, &mtu); 651 SMTP_MESSAGE_SIZE, &mtu);
658 GNUNET_GC_get_configuration_value_number (core_api->cfg, "SMTP", "RATELIMIT", 652 GNUNET_GC_get_configuration_value_number(core_api->cfg, "SMTP", "RATELIMIT",
659 0, 0, 1024 * 1024, &rate_limit); 653 0, 0, 1024 * 1024, &rate_limit);
660 stats = core_api->service_request ("stats"); 654 stats = core_api->service_request("stats");
661 if (stats != NULL) 655 if (stats != NULL)
662 { 656 {
663 stat_bytesReceived = 657 stat_bytesReceived =
664 stats->create (gettext_noop ("# bytes received via SMTP")); 658 stats->create(gettext_noop("# bytes received via SMTP"));
665 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP")); 659 stat_bytesSent = stats->create(gettext_noop("# bytes sent via SMTP"));
666 stat_bytesDropped = 660 stat_bytesDropped =
667 stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); 661 stats->create(gettext_noop("# bytes dropped by SMTP (outgoing)"));
668 } 662 }
669 GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", &pipename); 663 GNUNET_GC_get_configuration_value_filename(core_api->cfg, "SMTP", "PIPE", &pipename);
670 unlink (pipename); 664 unlink(pipename);
671 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 665 if (0 != mkfifo(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
672 { 666 {
673 GNUNET_GE_LOG_STRERROR (ectx, 667 GNUNET_GE_LOG_STRERROR(ectx,
674 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL, 668 GNUNET_GE_ADMIN | GNUNET_GE_BULK | GNUNET_GE_FATAL,
675 "mkfifo"); 669 "mkfifo");
676 GNUNET_free (pipename); 670 GNUNET_free(pipename);
677 core_api->service_release (stats); 671 core_api->service_release(stats);
678 stats = NULL; 672 stats = NULL;
679 return NULL; 673 return NULL;
680 } 674 }
681 /* we need to allow the mailer program to send us messages; 675 /* we need to allow the mailer program to send us messages;
682 * easiest done by giving it write permissions (see Mantis #1142) */ 676 * easiest done by giving it write permissions (see Mantis #1142) */
683 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 677 if (0 != chmod(pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
684 GNUNET_GE_LOG_STRERROR (ectx, 678 GNUNET_GE_LOG_STRERROR(ectx,
685 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 679 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
686 GNUNET_GE_WARNING, "chmod"); 680 GNUNET_GE_WARNING, "chmod");
687 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "EMAIL", NULL, 681 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "EMAIL", NULL,
688 &email); 682 &email);
689 lock = GNUNET_mutex_create (GNUNET_NO); 683 lock = GNUNET_mutex_create(GNUNET_NO);
690 GNUNET_GC_get_configuration_value_string (core_api->cfg, "SMTP", "SERVER", 684 GNUNET_GC_get_configuration_value_string(core_api->cfg, "SMTP", "SERVER",
691 "localhost:25", &smtp_server_name); 685 "localhost:25", &smtp_server_name);
692 sa.sa_handler = SIG_IGN; 686 sa.sa_handler = SIG_IGN;
693 sigemptyset (&sa.sa_mask); 687 sigemptyset(&sa.sa_mask);
694 sa.sa_flags = 0; 688 sa.sa_flags = 0;
695 sigaction (SIGPIPE, &sa, &old_handler); 689 sigaction(SIGPIPE, &sa, &old_handler);
696 690
697 smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP; 691 smtpAPI.protocol_number = GNUNET_TRANSPORT_PROTOCOL_NUMBER_SMTP;
698 smtpAPI.mtu = mtu - sizeof (SMTPMessage); 692 smtpAPI.mtu = mtu - sizeof(SMTPMessage);
699 smtpAPI.cost = 50; 693 smtpAPI.cost = 50;
700 smtpAPI.hello_verify = &api_verify_hello; 694 smtpAPI.hello_verify = &api_verify_hello;
701 smtpAPI.hello_create = &api_create_hello; 695 smtpAPI.hello_create = &api_create_hello;
@@ -711,21 +705,21 @@ inittransport_smtp (struct GNUNET_CoreAPIForTransport * core)
711} 705}
712 706
713void 707void
714donetransport_smtp () 708donetransport_smtp()
715{ 709{
716 sigaction (SIGPIPE, &old_handler, NULL); 710 sigaction(SIGPIPE, &old_handler, NULL);
717 GNUNET_free (smtp_server_name); 711 GNUNET_free(smtp_server_name);
718 if (stats != NULL) 712 if (stats != NULL)
719 { 713 {
720 core_api->service_release (stats); 714 core_api->service_release(stats);
721 stats = NULL; 715 stats = NULL;
722 } 716 }
723 GNUNET_mutex_destroy (lock); 717 GNUNET_mutex_destroy(lock);
724 lock = NULL; 718 lock = NULL;
725 unlink (pipename); 719 unlink(pipename);
726 GNUNET_free (pipename); 720 GNUNET_free(pipename);
727 pipename = NULL; 721 pipename = NULL;
728 GNUNET_free (email); 722 GNUNET_free(email);
729 email = NULL; 723 email = NULL;
730} 724}
731 725
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 0ea0bf460..80b21d86a 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2002--2015 GNUnet e.V. 3 Copyright (C) 2002--2015 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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,8 +103,7 @@ 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{
108 /** 107 /**
109 * UID of the other end of the connection. 108 * UID of the other end of the connection.
110 */ 109 */
@@ -186,7 +185,7 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls,
186 * @param connection connection to destroy 185 * @param connection connection to destroy
187 */ 186 */
188void 187void
189GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); 188GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection);
190 189
191 190
192/** 191/**
@@ -250,8 +249,7 @@ typedef void (*GNUNET_SERVER_MessageCallback) (
250 * Message handler. Each struct specifies how to handle on particular 249 * Message handler. Each struct specifies how to handle on particular
251 * type of message received. 250 * type of message received.
252 */ 251 */
253struct GNUNET_SERVER_MessageHandler 252struct GNUNET_SERVER_MessageHandler {
254{
255 /** 253 /**
256 * Function to call for messages of "type". 254 * Function to call for messages of "type".
257 */ 255 */
@@ -280,8 +278,7 @@ struct GNUNET_SERVER_MessageHandler
280/** 278/**
281 * Options for the service (bitmask). 279 * Options for the service (bitmask).
282 */ 280 */
283enum LEGACY_SERVICE_Options 281enum LEGACY_SERVICE_Options {
284{
285 /** 282 /**
286 * Use defaults. Terminates all client connections and the listen 283 * Use defaults. Terminates all client connections and the listen
287 * sockets immediately upon receiving the shutdown signal. 284 * sockets immediately upon receiving the shutdown signal.
@@ -312,7 +309,7 @@ enum LEGACY_SERVICE_Options
312 * @param client the client to disconnect from 309 * @param client the client to disconnect from
313 */ 310 */
314void 311void
315GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); 312GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client);
316 313
317/** 314/**
318 * Return user context associated with the given client. 315 * Return user context associated with the given client.
@@ -323,8 +320,8 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client);
323 * @return pointer to user context 320 * @return pointer to user context
324 */ 321 */
325void * 322void *
326GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, 323GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client,
327 size_t size); 324 size_t size);
328 325
329 326
330/** 327/**
@@ -353,8 +350,8 @@ typedef int (*GNUNET_SERVER_MessageTokenizerCallback) (
353 * @return handle to tokenizer 350 * @return handle to tokenizer
354 */ 351 */
355struct GNUNET_SERVER_MessageStreamTokenizer * 352struct GNUNET_SERVER_MessageStreamTokenizer *
356GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, 353GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb,
357 void *cb_cls); 354 void *cb_cls);
358 355
359/** 356/**
360 * Add incoming data to the receive buffer and call the 357 * Add incoming data to the receive buffer and call the
@@ -373,12 +370,12 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
373 * #GNUNET_SYSERR if the data stream is corrupt 370 * #GNUNET_SYSERR if the data stream is corrupt
374 */ 371 */
375int 372int
376GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 373GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst,
377 void *client_identity, 374 void *client_identity,
378 const char *buf, 375 const char *buf,
379 size_t size, 376 size_t size,
380 int purge, 377 int purge,
381 int one_shot); 378 int one_shot);
382 379
383 380
384/** 381/**
@@ -387,7 +384,7 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
387 * @param mst tokenizer to destroy 384 * @param mst tokenizer to destroy
388 */ 385 */
389void 386void
390GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst); 387GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst);
391 388
392 389
393/** 390/**
@@ -399,9 +396,9 @@ GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst);
399 * @param size number of bytes in user context struct (for verification only) 396 * @param size number of bytes in user context struct (for verification only)
400 */ 397 */
401void 398void
402GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, 399GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client,
403 void *ptr, 400 void *ptr,
404 size_t size); 401 size_t size);
405/** 402/**
406 * Return user context associated with the given client. 403 * Return user context associated with the given client.
407 * 404 *
@@ -410,7 +407,7 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
410 * @return pointer to user context of type 'type *'. 407 * @return pointer to user context of type 'type *'.
411 */ 408 */
412#define GNUNET_SERVER_client_get_user_context(client, type) \ 409#define GNUNET_SERVER_client_get_user_context(client, type) \
413 (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type)) 410 (type *)GNUNET_SERVER_client_get_user_context_(client, sizeof(type))
414 411
415/** 412/**
416 * Set user context to be associated with the given client. 413 * Set user context to be associated with the given client.
@@ -419,7 +416,7 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
419 * @param value pointer to user context 416 * @param value pointer to user context
420 */ 417 */
421#define GNUNET_SERVER_client_set_user_context(client, value) \ 418#define GNUNET_SERVER_client_set_user_context(client, value) \
422 GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value)) 419 GNUNET_SERVER_client_set_user_context_(client, value, sizeof(*value))
423 420
424 421
425/** 422/**
@@ -438,7 +435,7 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
438 * NULL if we are already going to notify someone else (busy) 435 * NULL if we are already going to notify someone else (busy)
439 */ 436 */
440struct GNUNET_SERVER_TransmitHandle * 437struct GNUNET_SERVER_TransmitHandle *
441GNUNET_SERVER_notify_transmit_ready ( 438GNUNET_SERVER_notify_transmit_ready(
442 struct GNUNET_SERVER_Client *client, 439 struct GNUNET_SERVER_Client *client,
443 size_t size, 440 size_t size,
444 struct GNUNET_TIME_Relative timeout, 441 struct GNUNET_TIME_Relative timeout,
@@ -451,7 +448,7 @@ GNUNET_SERVER_notify_transmit_ready (
451 * @param th request to abort 448 * @param th request to abort
452 */ 449 */
453void 450void
454GNUNET_SERVER_notify_transmit_ready_cancel ( 451GNUNET_SERVER_notify_transmit_ready_cancel(
455 struct GNUNET_SERVER_TransmitHandle *th); 452 struct GNUNET_SERVER_TransmitHandle *th);
456 453
457 454
@@ -463,7 +460,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel (
463 * @param client the client to keep 460 * @param client the client to keep
464 */ 461 */
465void 462void
466GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); 463GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client);
467 464
468 465
469/** 466/**
@@ -475,7 +472,7 @@ GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client);
475 * @param client the client to drop 472 * @param client the client to drop
476 */ 473 */
477void 474void
478GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); 475GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client);
479 476
480 477
481/** 478/**
@@ -499,7 +496,7 @@ typedef void (*LEGACY_SERVICE_Main) (
499 * @param server server to stop accepting connections. 496 * @param server server to stop accepting connections.
500 */ 497 */
501void 498void
502GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); 499GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server);
503 500
504/** 501/**
505 * Notify us when the server has enough space to transmit 502 * Notify us when the server has enough space to transmit
@@ -517,7 +514,7 @@ GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server);
517 * NULL if we are already going to notify someone else (busy) 514 * NULL if we are already going to notify someone else (busy)
518 */ 515 */
519struct GNUNET_SERVER_TransmitHandle * 516struct GNUNET_SERVER_TransmitHandle *
520GNUNET_SERVER_notify_transmit_ready ( 517GNUNET_SERVER_notify_transmit_ready(
521 struct GNUNET_SERVER_Client *client, 518 struct GNUNET_SERVER_Client *client,
522 size_t size, 519 size_t size,
523 struct GNUNET_TIME_Relative timeout, 520 struct GNUNET_TIME_Relative timeout,
@@ -537,8 +534,8 @@ GNUNET_SERVER_notify_transmit_ready (
537 * @return the client handle 534 * @return the client handle
538 */ 535 */
539struct GNUNET_SERVER_Client * 536struct GNUNET_SERVER_Client *
540GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, 537GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server,
541 struct GNUNET_CONNECTION_Handle *connection); 538 struct GNUNET_CONNECTION_Handle *connection);
542 539
543 540
544/** 541/**
@@ -547,7 +544,7 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
547 * @param server server to resume accepting connections. 544 * @param server server to resume accepting connections.
548 */ 545 */
549void 546void
550GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server); 547GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server);
551 548
552/** 549/**
553 * Free resources held by this server. 550 * Free resources held by this server.
@@ -555,7 +552,7 @@ GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server);
555 * @param server server to destroy 552 * @param server server to destroy
556 */ 553 */
557void 554void
558GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); 555GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server);
559 556
560 557
561#include "tcp_connection_legacy.c" 558#include "tcp_connection_legacy.c"
@@ -568,8 +565,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
568/** 565/**
569 * Initial handshake message for a session. 566 * Initial handshake message for a session.
570 */ 567 */
571struct WelcomeMessage 568struct WelcomeMessage {
572{
573 /** 569 /**
574 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME. 570 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME.
575 */ 571 */
@@ -585,8 +581,7 @@ struct WelcomeMessage
585 * Basically a WELCOME message, but with the purpose 581 * Basically a WELCOME message, but with the purpose
586 * of giving the waiting peer a client handle to use 582 * of giving the waiting peer a client handle to use
587 */ 583 */
588struct TCP_NAT_ProbeMessage 584struct TCP_NAT_ProbeMessage {
589{
590 /** 585 /**
591 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE. 586 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE.
592 */ 587 */
@@ -602,9 +597,7 @@ GNUNET_NETWORK_STRUCT_END
602/** 597/**
603 * Context for sending a NAT probe via TCP. 598 * Context for sending a NAT probe via TCP.
604 */ 599 */
605struct TCPProbeContext 600struct TCPProbeContext {
606{
607
608 /** 601 /**
609 * Active probes are kept in a DLL. 602 * Active probes are kept in a DLL.
610 */ 603 */
@@ -639,9 +632,7 @@ struct TCPProbeContext
639/** 632/**
640 * Bits in the `options` field of TCP addresses. 633 * Bits in the `options` field of TCP addresses.
641 */ 634 */
642enum TcpAddressOptions 635enum TcpAddressOptions {
643{
644
645 /** 636 /**
646 * No bits set. 637 * No bits set.
647 */ 638 */
@@ -663,8 +654,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
663/** 654/**
664 * Network format for IPv4 addresses. 655 * Network format for IPv4 addresses.
665 */ 656 */
666struct IPv4TcpAddress 657struct IPv4TcpAddress {
667{
668 /** 658 /**
669 * Optional options and flags for this address, 659 * Optional options and flags for this address,
670 * see `enum TcpAddressOptions` 660 * see `enum TcpAddressOptions`
@@ -685,8 +675,7 @@ struct IPv4TcpAddress
685/** 675/**
686 * Network format for IPv6 addresses. 676 * Network format for IPv6 addresses.
687 */ 677 */
688struct IPv6TcpAddress 678struct IPv6TcpAddress {
689{
690 /** 679 /**
691 * Optional flags for this address 680 * Optional flags for this address
692 * see `enum TcpAddressOptions` 681 * see `enum TcpAddressOptions`
@@ -714,9 +703,7 @@ struct Plugin;
714 * Information kept for each message that is yet to 703 * Information kept for each message that is yet to
715 * be transmitted. 704 * be transmitted.
716 */ 705 */
717struct PendingMessage 706struct PendingMessage {
718{
719
720 /** 707 /**
721 * This is a doubly-linked list. 708 * This is a doubly-linked list.
722 */ 709 */
@@ -760,8 +747,7 @@ struct PendingMessage
760/** 747/**
761 * Session handle for TCP connections. 748 * Session handle for TCP connections.
762 */ 749 */
763struct GNUNET_ATS_Session 750struct GNUNET_ATS_Session {
764{
765 /** 751 /**
766 * To whom are we talking to (set to our identity 752 * To whom are we talking to (set to our identity
767 * if we are still waiting for the welcome message) 753 * if we are still waiting for the welcome message)
@@ -863,8 +849,7 @@ struct GNUNET_ATS_Session
863 * Context for address to string conversion, closure 849 * Context for address to string conversion, closure
864 * for #append_port(). 850 * for #append_port().
865 */ 851 */
866struct PrettyPrinterContext 852struct PrettyPrinterContext {
867{
868 /** 853 /**
869 * DLL 854 * DLL
870 */ 855 */
@@ -920,8 +905,7 @@ struct PrettyPrinterContext
920/** 905/**
921 * Encapsulation of all of the state of the plugin. 906 * Encapsulation of all of the state of the plugin.
922 */ 907 */
923struct Plugin 908struct Plugin {
924{
925 /** 909 /**
926 * Our environment. 910 * Our environment.
927 */ 911 */
@@ -1052,10 +1036,10 @@ struct Plugin
1052 * set to NULL). 1036 * set to NULL).
1053 */ 1037 */
1054static int 1038static int
1055get_server_addresses (const char *service_name, 1039get_server_addresses(const char *service_name,
1056 const struct GNUNET_CONFIGURATION_Handle *cfg, 1040 const struct GNUNET_CONFIGURATION_Handle *cfg,
1057 struct sockaddr ***addrs, 1041 struct sockaddr ***addrs,
1058 socklen_t **addr_lens) 1042 socklen_t **addr_lens)
1059{ 1043{
1060 int disablev6; 1044 int disablev6;
1061 struct GNUNET_NETWORK_Handle *desc; 1045 struct GNUNET_NETWORK_Handle *desc;
@@ -1076,72 +1060,72 @@ get_server_addresses (const char *service_name,
1076 *addrs = NULL; 1060 *addrs = NULL;
1077 *addr_lens = NULL; 1061 *addr_lens = NULL;
1078 desc = NULL; 1062 desc = NULL;
1079 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) 1063 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6"))
1080 { 1064 {
1081 if (GNUNET_SYSERR == 1065 if (GNUNET_SYSERR ==
1082 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1066 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg,
1083 service_name, 1067 service_name,
1084 "DISABLEV6"))) 1068 "DISABLEV6")))
1085 return GNUNET_SYSERR; 1069 return GNUNET_SYSERR;
1086 } 1070 }
1087 else 1071 else
1088 disablev6 = GNUNET_NO; 1072 disablev6 = GNUNET_NO;
1089 1073
1090 if (! disablev6) 1074 if (!disablev6)
1091 {
1092 /* probe IPv6 support */
1093 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
1094 if (NULL == desc)
1095 {
1096 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1097 (EACCES == errno))
1098 {
1099 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1100 return GNUNET_SYSERR;
1101 }
1102 LOG (GNUNET_ERROR_TYPE_INFO,
1103 _ (
1104 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
1105 service_name,
1106 strerror (errno));
1107 disablev6 = GNUNET_YES;
1108 }
1109 else
1110 { 1075 {
1111 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); 1076 /* probe IPv6 support */
1112 desc = NULL; 1077 desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0);
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 }
1113 } 1098 }
1114 }
1115 1099
1116 port = 0; 1100 port = 0;
1117 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) 1101 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT"))
1118 {
1119 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
1120 service_name,
1121 "PORT",
1122 &port))
1123 {
1124 LOG (GNUNET_ERROR_TYPE_ERROR,
1125 _ ("Require valid port number for service `%s' in configuration!\n"),
1126 service_name);
1127 }
1128 if (port > 65535)
1129 { 1102 {
1130 LOG (GNUNET_ERROR_TYPE_ERROR, 1103 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg,
1131 _ ("Require valid port number for service `%s' in configuration!\n"), 1104 service_name,
1132 service_name); 1105 "PORT",
1133 return GNUNET_SYSERR; 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 }
1134 } 1119 }
1135 }
1136 1120
1137 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) 1121 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO"))
1138 { 1122 {
1139 GNUNET_break (GNUNET_OK == 1123 GNUNET_break(GNUNET_OK ==
1140 GNUNET_CONFIGURATION_get_value_string (cfg, 1124 GNUNET_CONFIGURATION_get_value_string(cfg,
1141 service_name, 1125 service_name,
1142 "BINDTO", 1126 "BINDTO",
1143 &hostname)); 1127 &hostname));
1144 } 1128 }
1145 else 1129 else
1146 hostname = NULL; 1130 hostname = NULL;
1147 1131
@@ -1149,232 +1133,232 @@ get_server_addresses (const char *service_name,
1149 abstract = GNUNET_NO; 1133 abstract = GNUNET_NO;
1150#ifdef AF_UNIX 1134#ifdef AF_UNIX
1151 if ((GNUNET_YES == 1135 if ((GNUNET_YES ==
1152 GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && 1136 GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) &&
1153 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, 1137 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg,
1154 service_name, 1138 service_name,
1155 "UNIXPATH", 1139 "UNIXPATH",
1156 &unixpath)) && 1140 &unixpath)) &&
1157 (0 < strlen (unixpath))) 1141 (0 < strlen(unixpath)))
1158 {
1159 /* probe UNIX support */
1160 struct sockaddr_un s_un;
1161
1162 if (strlen (unixpath) >= sizeof (s_un.sun_path))
1163 { 1142 {
1164 LOG (GNUNET_ERROR_TYPE_WARNING, 1143 /* probe UNIX support */
1165 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), 1144 struct sockaddr_un s_un;
1166 unixpath, 1145
1167 (unsigned long long) sizeof (s_un.sun_path)); 1146 if (strlen(unixpath) >= sizeof(s_un.sun_path))
1168 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 1147 {
1169 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); 1148 LOG(GNUNET_ERROR_TYPE_WARNING,
1170 } 1149 _("UNIXPATH `%s' too long, maximum length is %llu\n"),
1150 unixpath,
1151 (unsigned long long)sizeof(s_un.sun_path));
1152 unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath);
1153 LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath);
1154 }
1171#ifdef LINUX 1155#ifdef LINUX
1172 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1156 abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg,
1173 "TESTING", 1157 "TESTING",
1174 "USE_ABSTRACT_SOCKETS"); 1158 "USE_ABSTRACT_SOCKETS");
1175 if (GNUNET_SYSERR == abstract) 1159 if (GNUNET_SYSERR == abstract)
1176 abstract = GNUNET_NO; 1160 abstract = GNUNET_NO;
1177#endif 1161#endif
1178 if ((GNUNET_YES != abstract) && 1162 if ((GNUNET_YES != abstract) &&
1179 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) 1163 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath)))
1180 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); 1164 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath);
1181 }
1182 if (NULL != unixpath)
1183 {
1184 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
1185 if (NULL == desc)
1186 {
1187 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
1188 (EACCES == errno))
1189 {
1190 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
1191 GNUNET_free_non_null (hostname);
1192 GNUNET_free (unixpath);
1193 return GNUNET_SYSERR;
1194 }
1195 LOG (GNUNET_ERROR_TYPE_INFO,
1196 _ (
1197 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
1198 service_name,
1199 strerror (errno));
1200 GNUNET_free (unixpath);
1201 unixpath = NULL;
1202 } 1165 }
1203 else 1166 if (NULL != unixpath)
1204 { 1167 {
1205 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); 1168 desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0);
1206 desc = NULL; 1169 if (NULL == desc)
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 }
1207 } 1192 }
1208 }
1209#endif 1193#endif
1210 1194
1211 if ((0 == port) && (NULL == unixpath)) 1195 if ((0 == port) && (NULL == unixpath))
1212 {
1213 LOG (GNUNET_ERROR_TYPE_ERROR,
1214 _ (
1215 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1216 service_name);
1217 GNUNET_free_non_null (hostname);
1218 return GNUNET_SYSERR;
1219 }
1220 if (0 == port)
1221 {
1222 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
1223 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
1224 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1225 GNUNET_free_non_null (unixpath);
1226 GNUNET_free_non_null (hostname);
1227 *addrs = saddrs;
1228 *addr_lens = saddrlens;
1229 return 1;
1230 }
1231
1232 if (NULL != hostname)
1233 {
1234 LOG (GNUNET_ERROR_TYPE_DEBUG,
1235 "Resolving `%s' since that is where `%s' will bind to.\n",
1236 hostname,
1237 service_name);
1238 memset (&hints, 0, sizeof (struct addrinfo));
1239 if (disablev6)
1240 hints.ai_family = AF_INET;
1241 hints.ai_protocol = IPPROTO_TCP;
1242 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
1243 (NULL == res))
1244 {
1245 LOG (GNUNET_ERROR_TYPE_ERROR,
1246 _ ("Failed to resolve `%s': %s\n"),
1247 hostname,
1248 gai_strerror (ret));
1249 GNUNET_free (hostname);
1250 GNUNET_free_non_null (unixpath);
1251 return GNUNET_SYSERR;
1252 }
1253 next = res;
1254 i = 0;
1255 while (NULL != (pos = next))
1256 { 1196 {
1257 next = pos->ai_next; 1197 LOG(GNUNET_ERROR_TYPE_ERROR,
1258 if ((disablev6) && (pos->ai_family == AF_INET6)) 1198 _(
1259 continue; 1199 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
1260 i++; 1200 service_name);
1201 GNUNET_free_non_null(hostname);
1202 return GNUNET_SYSERR;
1261 } 1203 }
1262 if (0 == i) 1204 if (0 == port)
1263 { 1205 {
1264 LOG (GNUNET_ERROR_TYPE_ERROR, 1206 saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *));
1265 _ ("Failed to find %saddress for `%s'.\n"), 1207 saddrlens = GNUNET_malloc(2 * sizeof(socklen_t));
1266 disablev6 ? "IPv4 " : "", 1208 add_unixpath(saddrs, saddrlens, unixpath, abstract);
1267 hostname); 1209 GNUNET_free_non_null(unixpath);
1268 freeaddrinfo (res); 1210 GNUNET_free_non_null(hostname);
1269 GNUNET_free (hostname); 1211 *addrs = saddrs;
1270 GNUNET_free_non_null (unixpath); 1212 *addr_lens = saddrlens;
1271 return GNUNET_SYSERR; 1213 return 1;
1272 } 1214 }
1273 resi = i; 1215
1274 if (NULL != unixpath) 1216 if (NULL != hostname)
1275 resi++;
1276 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1277 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1278 i = 0;
1279 if (NULL != unixpath)
1280 {
1281 add_unixpath (saddrs, saddrlens, unixpath, abstract);
1282 i++;
1283 }
1284 next = res;
1285 while (NULL != (pos = next))
1286 {
1287 next = pos->ai_next;
1288 if ((disablev6) && (AF_INET6 == pos->ai_family))
1289 continue;
1290 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
1291 continue; /* not TCP */
1292 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
1293 continue; /* huh? */
1294 LOG (GNUNET_ERROR_TYPE_DEBUG,
1295 "Service `%s' will bind to `%s'\n",
1296 service_name,
1297 GNUNET_a2s (pos->ai_addr, pos->ai_addrlen));
1298 if (AF_INET == pos->ai_family)
1299 {
1300 GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen);
1301 saddrlens[i] = pos->ai_addrlen;
1302 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1303 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1304 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port);
1305 }
1306 else
1307 {
1308 GNUNET_assert (AF_INET6 == pos->ai_family);
1309 GNUNET_assert (sizeof (struct sockaddr_in6) == pos->ai_addrlen);
1310 saddrlens[i] = pos->ai_addrlen;
1311 saddrs[i] = GNUNET_malloc (saddrlens[i]);
1312 GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]);
1313 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port);
1314 }
1315 i++;
1316 }
1317 GNUNET_free (hostname);
1318 freeaddrinfo (res);
1319 resi = i;
1320 }
1321 else
1322 {
1323 /* will bind against everything, just set port */
1324 if (disablev6)
1325 { 1217 {
1326 /* V4-only */ 1218 LOG(GNUNET_ERROR_TYPE_DEBUG,
1327 resi = 1; 1219 "Resolving `%s' since that is where `%s' will bind to.\n",
1220 hostname,
1221 service_name);
1222 memset(&hints, 0, sizeof(struct addrinfo));
1223 if (disablev6)
1224 hints.ai_family = AF_INET;
1225 hints.ai_protocol = IPPROTO_TCP;
1226 if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) ||
1227 (NULL == res))
1228 {
1229 LOG(GNUNET_ERROR_TYPE_ERROR,
1230 _("Failed to resolve `%s': %s\n"),
1231 hostname,
1232 gai_strerror(ret));
1233 GNUNET_free(hostname);
1234 GNUNET_free_non_null(unixpath);
1235 return GNUNET_SYSERR;
1236 }
1237 next = res;
1238 i = 0;
1239 while (NULL != (pos = next))
1240 {
1241 next = pos->ai_next;
1242 if ((disablev6) && (pos->ai_family == AF_INET6))
1243 continue;
1244 i++;
1245 }
1246 if (0 == i)
1247 {
1248 LOG(GNUNET_ERROR_TYPE_ERROR,
1249 _("Failed to find %saddress for `%s'.\n"),
1250 disablev6 ? "IPv4 " : "",
1251 hostname);
1252 freeaddrinfo(res);
1253 GNUNET_free(hostname);
1254 GNUNET_free_non_null(unixpath);
1255 return GNUNET_SYSERR;
1256 }
1257 resi = i;
1328 if (NULL != unixpath) 1258 if (NULL != unixpath)
1329 resi++; 1259 resi++;
1260 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
1261 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
1330 i = 0; 1262 i = 0;
1331 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
1332 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
1333 if (NULL != unixpath) 1263 if (NULL != unixpath)
1334 { 1264 {
1335 add_unixpath (saddrs, saddrlens, unixpath, abstract); 1265 add_unixpath(saddrs, saddrlens, unixpath, abstract);
1336 i++; 1266 i++;
1337 } 1267 }
1338 saddrlens[i] = sizeof (struct sockaddr_in); 1268 next = res;
1339 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1269 while (NULL != (pos = next))
1340#if HAVE_SOCKADDR_IN_SIN_LEN 1270 {
1341 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; 1271 next = pos->ai_next;
1342#endif 1272 if ((disablev6) && (AF_INET6 == pos->ai_family))
1343 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; 1273 continue;
1344 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 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;
1345 } 1304 }
1346 else 1305 else
1347 { 1306 {
1348 /* dual stack */ 1307 /* will bind against everything, just set port */
1349 resi = 2; 1308 if (disablev6)
1350 if (NULL != unixpath) 1309 {
1351 resi++; 1310 /* V4-only */
1352 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 1311 resi = 1;
1353 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 1312 if (NULL != unixpath)
1354 i = 0; 1313 resi++;
1355 if (NULL != unixpath) 1314 i = 0;
1356 { 1315 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
1357 add_unixpath (saddrs, saddrlens, unixpath, abstract); 1316 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
1358 i++; 1317 if (NULL != unixpath)
1359 } 1318 {
1360 saddrlens[i] = sizeof (struct sockaddr_in6); 1319 add_unixpath(saddrs, saddrlens, unixpath, abstract);
1361 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1320 i++;
1321 }
1322 saddrlens[i] = sizeof(struct sockaddr_in);
1323 saddrs[i] = GNUNET_malloc(saddrlens[i]);
1362#if HAVE_SOCKADDR_IN_SIN_LEN 1324#if HAVE_SOCKADDR_IN_SIN_LEN
1363 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; 1325 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i];
1364#endif 1326#endif
1365 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; 1327 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET;
1366 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); 1328 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
1367 i++; 1329 }
1368 saddrlens[i] = sizeof (struct sockaddr_in); 1330 else
1369 saddrs[i] = GNUNET_malloc (saddrlens[i]); 1331 {
1332 /* dual stack */
1333 resi = 2;
1334 if (NULL != unixpath)
1335 resi++;
1336 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
1337 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
1338 i = 0;
1339 if (NULL != unixpath)
1340 {
1341 add_unixpath(saddrs, saddrlens, unixpath, abstract);
1342 i++;
1343 }
1344 saddrlens[i] = sizeof(struct sockaddr_in6);
1345 saddrs[i] = GNUNET_malloc(saddrlens[i]);
1346#if HAVE_SOCKADDR_IN_SIN_LEN
1347 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0];
1348#endif
1349 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6;
1350 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port);
1351 i++;
1352 saddrlens[i] = sizeof(struct sockaddr_in);
1353 saddrs[i] = GNUNET_malloc(saddrlens[i]);
1370#if HAVE_SOCKADDR_IN_SIN_LEN 1354#if HAVE_SOCKADDR_IN_SIN_LEN
1371 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; 1355 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1];
1372#endif 1356#endif
1373 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; 1357 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET;
1374 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 1358 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
1359 }
1375 } 1360 }
1376 } 1361 GNUNET_free_non_null(unixpath);
1377 GNUNET_free_non_null (unixpath);
1378 *addrs = saddrs; 1362 *addrs = saddrs;
1379 *addr_lens = saddrlens; 1363 *addr_lens = saddrlens;
1380 return resi; 1364 return resi;
@@ -1391,26 +1375,26 @@ get_server_addresses (const char *service_name,
1391 * @param state new state of the session 1375 * @param state new state of the session
1392 */ 1376 */
1393static void 1377static void
1394notify_session_monitor (struct Plugin *plugin, 1378notify_session_monitor(struct Plugin *plugin,
1395 struct GNUNET_ATS_Session *session, 1379 struct GNUNET_ATS_Session *session,
1396 enum GNUNET_TRANSPORT_SessionState state) 1380 enum GNUNET_TRANSPORT_SessionState state)
1397{ 1381{
1398 struct GNUNET_TRANSPORT_SessionInfo info; 1382 struct GNUNET_TRANSPORT_SessionInfo info;
1399 1383
1400 if (NULL == plugin->sic) 1384 if (NULL == plugin->sic)
1401 return; 1385 return;
1402 memset (&info, 0, sizeof (info)); 1386 memset(&info, 0, sizeof(info));
1403 info.state = state; 1387 info.state = state;
1404 info.is_inbound = 1388 info.is_inbound =
1405 GNUNET_HELLO_address_check_option (session->address, 1389 GNUNET_HELLO_address_check_option(session->address,
1406 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 1390 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
1407 info.num_msg_pending = session->msgs_in_queue; 1391 info.num_msg_pending = session->msgs_in_queue;
1408 info.num_bytes_pending = session->bytes_in_queue; 1392 info.num_bytes_pending = session->bytes_in_queue;
1409 if (NULL != session->receive_delay_task) 1393 if (NULL != session->receive_delay_task)
1410 info.receive_delay = session->receive_delay; 1394 info.receive_delay = session->receive_delay;
1411 info.session_timeout = session->timeout; 1395 info.session_timeout = session->timeout;
1412 info.address = session->address; 1396 info.address = session->address;
1413 plugin->sic (plugin->sic_cls, session, &info); 1397 plugin->sic(plugin->sic_cls, session, &info);
1414} 1398}
1415 1399
1416 1400
@@ -1427,12 +1411,12 @@ notify_session_monitor (struct Plugin *plugin,
1427 * @param addrlen actual length of @a addr 1411 * @param addrlen actual length of @a addr
1428 */ 1412 */
1429static void 1413static void
1430tcp_nat_port_map_callback (void *cls, 1414tcp_nat_port_map_callback(void *cls,
1431 void **app_ctx, 1415 void **app_ctx,
1432 int add_remove, 1416 int add_remove,
1433 enum GNUNET_NAT_AddressClass ac, 1417 enum GNUNET_NAT_AddressClass ac,
1434 const struct sockaddr *addr, 1418 const struct sockaddr *addr,
1435 socklen_t addrlen) 1419 socklen_t addrlen)
1436{ 1420{
1437 struct Plugin *plugin = cls; 1421 struct Plugin *plugin = cls;
1438 struct GNUNET_HELLO_Address *address; 1422 struct GNUNET_HELLO_Address *address;
@@ -1441,55 +1425,57 @@ tcp_nat_port_map_callback (void *cls,
1441 void *arg; 1425 void *arg;
1442 size_t args; 1426 size_t args;
1443 1427
1444 (void) app_ctx; 1428 (void)app_ctx;
1445 LOG (GNUNET_ERROR_TYPE_INFO, 1429 LOG(GNUNET_ERROR_TYPE_INFO,
1446 "NAT notification to %s address `%s'\n", 1430 "NAT notification to %s address `%s'\n",
1447 (GNUNET_YES == add_remove) ? "add" : "remove", 1431 (GNUNET_YES == add_remove) ? "add" : "remove",
1448 GNUNET_a2s (addr, addrlen)); 1432 GNUNET_a2s(addr, addrlen));
1449 /* convert 'addr' to our internal format */ 1433 /* convert 'addr' to our internal format */
1450 switch (addr->sa_family) 1434 switch (addr->sa_family)
1451 { 1435 {
1452 case AF_INET: 1436 case AF_INET:
1453 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 1437 GNUNET_assert(addrlen == sizeof(struct sockaddr_in));
1454 memset (&t4, 0, sizeof (t4)); 1438 memset(&t4, 0, sizeof(t4));
1455 t4.options = htonl (plugin->myoptions); 1439 t4.options = htonl(plugin->myoptions);
1456 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 1440 t4.ipv4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
1457 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; 1441 t4.t4_port = ((struct sockaddr_in *)addr)->sin_port;
1458 arg = &t4; 1442 arg = &t4;
1459 args = sizeof (t4); 1443 args = sizeof(t4);
1460 break; 1444 break;
1461 case AF_INET6: 1445
1462 if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) 1446 case AF_INET6:
1463 { 1447 if (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)addr)->sin6_addr))
1464 /* skip link local, we don't allow them in 1448 {
1465 #tcp_plugin_check_address() */ 1449 /* skip link local, we don't allow them in
1450 #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; 1466 return;
1467 } 1467 }
1468 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
1469 memset (&t6, 0, sizeof (t6));
1470 GNUNET_memcpy (&t6.ipv6_addr,
1471 &((struct sockaddr_in6 *) addr)->sin6_addr,
1472 sizeof (struct in6_addr));
1473 t6.options = htonl (plugin->myoptions);
1474 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1475 arg = &t6;
1476 args = sizeof (t6);
1477 break;
1478 default:
1479 GNUNET_break (0);
1480 return;
1481 }
1482 /* modify our published address list */ 1468 /* modify our published address list */
1483 GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) || 1469 GNUNET_assert((args == sizeof(struct IPv4TcpAddress)) ||
1484 (args == sizeof (struct IPv6TcpAddress))); 1470 (args == sizeof(struct IPv6TcpAddress)));
1485 /* TODO: use 'ac' here in the future... */ 1471 /* TODO: use 'ac' here in the future... */
1486 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1472 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1487 PLUGIN_NAME, 1473 PLUGIN_NAME,
1488 arg, 1474 arg,
1489 args, 1475 args,
1490 GNUNET_HELLO_ADDRESS_INFO_NONE); 1476 GNUNET_HELLO_ADDRESS_INFO_NONE);
1491 plugin->env->notify_address (plugin->env->cls, add_remove, address); 1477 plugin->env->notify_address(plugin->env->cls, add_remove, address);
1492 GNUNET_HELLO_address_free (address); 1478 GNUNET_HELLO_address_free(address);
1493} 1479}
1494 1480
1495 1481
@@ -1505,7 +1491,7 @@ tcp_nat_port_map_callback (void *cls,
1505 * @return string representing the same address 1491 * @return string representing the same address
1506 */ 1492 */
1507static const char * 1493static const char *
1508tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 1494tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
1509{ 1495{
1510 static char rbuf[INET6_ADDRSTRLEN + 12]; 1496 static char rbuf[INET6_ADDRSTRLEN + 12];
1511 char buf[INET6_ADDRSTRLEN]; 1497 char buf[INET6_ADDRSTRLEN];
@@ -1519,41 +1505,43 @@ tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1519 uint32_t options; 1505 uint32_t options;
1520 1506
1521 switch (addrlen) 1507 switch (addrlen)
1522 { 1508 {
1523 case sizeof (struct IPv6TcpAddress): 1509 case sizeof(struct IPv6TcpAddress):
1524 t6 = addr; 1510 t6 = addr;
1525 af = AF_INET6; 1511 af = AF_INET6;
1526 port = ntohs (t6->t6_port); 1512 port = ntohs(t6->t6_port);
1527 options = ntohl (t6->options); 1513 options = ntohl(t6->options);
1528 GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); 1514 GNUNET_memcpy(&a6, &t6->ipv6_addr, sizeof(a6));
1529 sb = &a6; 1515 sb = &a6;
1530 break; 1516 break;
1531 case sizeof (struct IPv4TcpAddress): 1517
1532 t4 = addr; 1518 case sizeof(struct IPv4TcpAddress):
1533 af = AF_INET; 1519 t4 = addr;
1534 port = ntohs (t4->t4_port); 1520 af = AF_INET;
1535 options = ntohl (t4->options); 1521 port = ntohs(t4->t4_port);
1536 GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); 1522 options = ntohl(t4->options);
1537 sb = &a4; 1523 GNUNET_memcpy(&a4, &t4->ipv4_addr, sizeof(a4));
1538 break; 1524 sb = &a4;
1539 default: 1525 break;
1540 LOG (GNUNET_ERROR_TYPE_WARNING, 1526
1541 _ ("Unexpected address length: %u bytes\n"), 1527 default:
1542 (unsigned int) addrlen); 1528 LOG(GNUNET_ERROR_TYPE_WARNING,
1543 return NULL; 1529 _("Unexpected address length: %u bytes\n"),
1544 } 1530 (unsigned int)addrlen);
1545 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) 1531 return NULL;
1546 { 1532 }
1547 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 1533 if (NULL == inet_ntop(af, sb, buf, INET6_ADDRSTRLEN))
1548 return NULL; 1534 {
1549 } 1535 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
1550 GNUNET_snprintf (rbuf, 1536 return NULL;
1551 sizeof (rbuf), 1537 }
1552 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 1538 GNUNET_snprintf(rbuf,
1553 PLUGIN_NAME, 1539 sizeof(rbuf),
1554 options, 1540 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
1555 buf, 1541 PLUGIN_NAME,
1556 port); 1542 options,
1543 buf,
1544 port);
1557 return rbuf; 1545 return rbuf;
1558} 1546}
1559 1547
@@ -1571,11 +1559,11 @@ tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
1571 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1559 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1572 */ 1560 */
1573static int 1561static int
1574tcp_plugin_string_to_address (void *cls, 1562tcp_plugin_string_to_address(void *cls,
1575 const char *addr, 1563 const char *addr,
1576 uint16_t addrlen, 1564 uint16_t addrlen,
1577 void **buf, 1565 void **buf,
1578 size_t *added) 1566 size_t *added)
1579{ 1567{
1580 struct sockaddr_storage socket_address; 1568 struct sockaddr_storage socket_address;
1581 char *address; 1569 char *address;
@@ -1588,77 +1576,79 @@ tcp_plugin_string_to_address (void *cls,
1588 plugin = NULL; 1576 plugin = NULL;
1589 optionstr = NULL; 1577 optionstr = NULL;
1590 if ((NULL == addr) || (0 == addrlen)) 1578 if ((NULL == addr) || (0 == addrlen))
1591 { 1579 {
1592 GNUNET_break (0); 1580 GNUNET_break(0);
1593 return GNUNET_SYSERR; 1581 return GNUNET_SYSERR;
1594 } 1582 }
1595 if ('\0' != addr[addrlen - 1]) 1583 if ('\0' != addr[addrlen - 1])
1596 { 1584 {
1597 GNUNET_break (0); 1585 GNUNET_break(0);
1598 return GNUNET_SYSERR; 1586 return GNUNET_SYSERR;
1599 } 1587 }
1600 if (strlen (addr) != addrlen - 1) 1588 if (strlen(addr) != addrlen - 1)
1601 { 1589 {
1602 GNUNET_break (0); 1590 GNUNET_break(0);
1603 return GNUNET_SYSERR; 1591 return GNUNET_SYSERR;
1604 } 1592 }
1605 plugin = GNUNET_strdup (addr); 1593 plugin = GNUNET_strdup(addr);
1606 optionstr = strchr (plugin, '.'); 1594 optionstr = strchr(plugin, '.');
1607 if (NULL == optionstr) 1595 if (NULL == optionstr)
1608 { 1596 {
1609 GNUNET_break (0); 1597 GNUNET_break(0);
1610 GNUNET_free (plugin); 1598 GNUNET_free(plugin);
1611 return GNUNET_SYSERR; 1599 return GNUNET_SYSERR;
1612 } 1600 }
1613 optionstr[0] = '\0'; 1601 optionstr[0] = '\0';
1614 optionstr++; 1602 optionstr++;
1615 options = atol (optionstr); 1603 options = atol(optionstr);
1616 address = strchr (optionstr, '.'); 1604 address = strchr(optionstr, '.');
1617 if (NULL == address) 1605 if (NULL == address)
1618 { 1606 {
1619 GNUNET_break (0); 1607 GNUNET_break(0);
1620 GNUNET_free (plugin); 1608 GNUNET_free(plugin);
1621 return GNUNET_SYSERR; 1609 return GNUNET_SYSERR;
1622 } 1610 }
1623 address[0] = '\0'; 1611 address[0] = '\0';
1624 address++; 1612 address++;
1625 1613
1626 if (GNUNET_OK != 1614 if (GNUNET_OK !=
1627 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) 1615 GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address))
1628 { 1616 {
1629 GNUNET_break (0); 1617 GNUNET_break(0);
1630 GNUNET_free (plugin); 1618 GNUNET_free(plugin);
1631 return GNUNET_SYSERR; 1619 return GNUNET_SYSERR;
1632 } 1620 }
1633 1621
1634 GNUNET_free (plugin); 1622 GNUNET_free(plugin);
1635 switch (socket_address.ss_family) 1623 switch (socket_address.ss_family)
1636 { 1624 {
1637 case AF_INET: { 1625 case AF_INET: {
1638 struct IPv4TcpAddress *t4; 1626 struct IPv4TcpAddress *t4;
1639 struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; 1627 struct sockaddr_in *in4 = (struct sockaddr_in *)&socket_address;
1640 t4 = GNUNET_new (struct IPv4TcpAddress); 1628 t4 = GNUNET_new(struct IPv4TcpAddress);
1641 t4->options = htonl (options); 1629 t4->options = htonl(options);
1642 t4->ipv4_addr = in4->sin_addr.s_addr; 1630 t4->ipv4_addr = in4->sin_addr.s_addr;
1643 t4->t4_port = in4->sin_port; 1631 t4->t4_port = in4->sin_port;
1644 *buf = t4; 1632 *buf = t4;
1645 *added = sizeof (struct IPv4TcpAddress); 1633 *added = sizeof(struct IPv4TcpAddress);
1646 return GNUNET_OK; 1634 return GNUNET_OK;
1647 } 1635 }
1648 case AF_INET6: { 1636
1649 struct IPv6TcpAddress *t6; 1637 case AF_INET6: {
1650 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; 1638 struct IPv6TcpAddress *t6;
1651 t6 = GNUNET_new (struct IPv6TcpAddress); 1639 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&socket_address;
1652 t6->options = htonl (options); 1640 t6 = GNUNET_new(struct IPv6TcpAddress);
1653 t6->ipv6_addr = in6->sin6_addr; 1641 t6->options = htonl(options);
1654 t6->t6_port = in6->sin6_port; 1642 t6->ipv6_addr = in6->sin6_addr;
1655 *buf = t6; 1643 t6->t6_port = in6->sin6_port;
1656 *added = sizeof (struct IPv6TcpAddress); 1644 *buf = t6;
1657 return GNUNET_OK; 1645 *added = sizeof(struct IPv6TcpAddress);
1658 } 1646 return GNUNET_OK;
1659 default: 1647 }
1660 return GNUNET_SYSERR; 1648
1661 } 1649 default:
1650 return GNUNET_SYSERR;
1651 }
1662} 1652}
1663 1653
1664 1654
@@ -1673,11 +1663,11 @@ tcp_plugin_string_to_address (void *cls,
1673 * @return NULL if no matching session exists 1663 * @return NULL if no matching session exists
1674 */ 1664 */
1675static struct GNUNET_ATS_Session * 1665static struct GNUNET_ATS_Session *
1676lookup_session_by_client (struct Plugin *plugin, 1666lookup_session_by_client(struct Plugin *plugin,
1677 struct GNUNET_SERVER_Client *client) 1667 struct GNUNET_SERVER_Client *client)
1678{ 1668{
1679 return GNUNET_SERVER_client_get_user_context (client, 1669 return GNUNET_SERVER_client_get_user_context(client,
1680 struct GNUNET_ATS_Session); 1670 struct GNUNET_ATS_Session);
1681} 1671}
1682 1672
1683 1673
@@ -1691,111 +1681,111 @@ lookup_session_by_client (struct Plugin *plugin,
1691 * @return #GNUNET_OK on success 1681 * @return #GNUNET_OK on success
1692 */ 1682 */
1693static int 1683static int
1694tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session) 1684tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session)
1695{ 1685{
1696 struct Plugin *plugin = cls; 1686 struct Plugin *plugin = cls;
1697 struct PendingMessage *pm; 1687 struct PendingMessage *pm;
1698 1688
1699 LOG (GNUNET_ERROR_TYPE_DEBUG, 1689 LOG(GNUNET_ERROR_TYPE_DEBUG,
1700 "Disconnecting session of peer `%s' address `%s'\n", 1690 "Disconnecting session of peer `%s' address `%s'\n",
1701 GNUNET_i2s (&session->target), 1691 GNUNET_i2s(&session->target),
1702 tcp_plugin_address_to_string (session->plugin, 1692 tcp_plugin_address_to_string(session->plugin,
1703 session->address->address, 1693 session->address->address,
1704 session->address->address_length)); 1694 session->address->address_length));
1705 1695
1706 if (NULL != session->timeout_task) 1696 if (NULL != session->timeout_task)
1707 { 1697 {
1708 GNUNET_SCHEDULER_cancel (session->timeout_task); 1698 GNUNET_SCHEDULER_cancel(session->timeout_task);
1709 session->timeout_task = NULL; 1699 session->timeout_task = NULL;
1710 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 1700 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
1711 } 1701 }
1712 1702
1713 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, 1703 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(plugin->sessionmap,
1714 &session->target, 1704 &session->target,
1715 session)) 1705 session))
1716 { 1706 {
1717 GNUNET_STATISTICS_update (session->plugin->env->stats, 1707 GNUNET_STATISTICS_update(session->plugin->env->stats,
1718 gettext_noop ("# TCP sessions active"), 1708 gettext_noop("# TCP sessions active"),
1719 -1, 1709 -1,
1720 GNUNET_NO); 1710 GNUNET_NO);
1721 } 1711 }
1722 else 1712 else
1723 { 1713 {
1724 GNUNET_assert (GNUNET_YES == 1714 GNUNET_assert(GNUNET_YES ==
1725 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, 1715 GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns,
1726 &session->target, 1716 &session->target,
1727 session)); 1717 session));
1728 } 1718 }
1729 if (NULL != session->client) 1719 if (NULL != session->client)
1730 GNUNET_SERVER_client_set_user_context (session->client, NULL); 1720 GNUNET_SERVER_client_set_user_context(session->client, NULL);
1731 1721
1732 /* clean up state */ 1722 /* clean up state */
1733 if (NULL != session->transmit_handle) 1723 if (NULL != session->transmit_handle)
1734 { 1724 {
1735 GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle); 1725 GNUNET_SERVER_notify_transmit_ready_cancel(session->transmit_handle);
1736 session->transmit_handle = NULL; 1726 session->transmit_handle = NULL;
1737 } 1727 }
1738 session->plugin->env->session_end (session->plugin->env->cls, 1728 session->plugin->env->session_end(session->plugin->env->cls,
1739 session->address, 1729 session->address,
1740 session); 1730 session);
1741 1731
1742 if (NULL != session->nat_connection_timeout) 1732 if (NULL != session->nat_connection_timeout)
1743 { 1733 {
1744 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); 1734 GNUNET_SCHEDULER_cancel(session->nat_connection_timeout);
1745 session->nat_connection_timeout = NULL; 1735 session->nat_connection_timeout = NULL;
1746 } 1736 }
1747 1737
1748 while (NULL != (pm = session->pending_messages_head)) 1738 while (NULL != (pm = session->pending_messages_head))
1749 { 1739 {
1750 LOG (GNUNET_ERROR_TYPE_DEBUG, 1740 LOG(GNUNET_ERROR_TYPE_DEBUG,
1751 (NULL != pm->transmit_cont) 1741 (NULL != pm->transmit_cont)
1752 ? "Could not deliver message to `%s' at %s.\n" 1742 ? "Could not deliver message to `%s' at %s.\n"
1753 : "Could not deliver message to `%s' at %s, notifying.\n", 1743 : "Could not deliver message to `%s' at %s, notifying.\n",
1754 GNUNET_i2s (&session->target), 1744 GNUNET_i2s(&session->target),
1755 tcp_plugin_address_to_string (session->plugin, 1745 tcp_plugin_address_to_string(session->plugin,
1756 session->address->address, 1746 session->address->address,
1757 session->address->address_length)); 1747 session->address->address_length));
1758 GNUNET_STATISTICS_update (session->plugin->env->stats, 1748 GNUNET_STATISTICS_update(session->plugin->env->stats,
1759 gettext_noop ("# bytes currently in TCP buffers"), 1749 gettext_noop("# bytes currently in TCP buffers"),
1760 -(int64_t) pm->message_size, 1750 -(int64_t)pm->message_size,
1761 GNUNET_NO); 1751 GNUNET_NO);
1762 GNUNET_STATISTICS_update (session->plugin->env->stats, 1752 GNUNET_STATISTICS_update(session->plugin->env->stats,
1763 gettext_noop ( 1753 gettext_noop(
1764 "# bytes discarded by TCP (disconnect)"), 1754 "# bytes discarded by TCP (disconnect)"),
1765 pm->message_size, 1755 pm->message_size,
1766 GNUNET_NO); 1756 GNUNET_NO);
1767 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 1757 GNUNET_CONTAINER_DLL_remove(session->pending_messages_head,
1768 session->pending_messages_tail, 1758 session->pending_messages_tail,
1769 pm); 1759 pm);
1770 GNUNET_assert (0 < session->msgs_in_queue); 1760 GNUNET_assert(0 < session->msgs_in_queue);
1771 session->msgs_in_queue--; 1761 session->msgs_in_queue--;
1772 GNUNET_assert (pm->message_size <= session->bytes_in_queue); 1762 GNUNET_assert(pm->message_size <= session->bytes_in_queue);
1773 session->bytes_in_queue -= pm->message_size; 1763 session->bytes_in_queue -= pm->message_size;
1774 if (NULL != pm->transmit_cont) 1764 if (NULL != pm->transmit_cont)
1775 pm->transmit_cont (pm->transmit_cont_cls, 1765 pm->transmit_cont(pm->transmit_cont_cls,
1776 &session->target, 1766 &session->target,
1777 GNUNET_SYSERR, 1767 GNUNET_SYSERR,
1778 pm->message_size, 1768 pm->message_size,
1779 0); 1769 0);
1780 GNUNET_free (pm); 1770 GNUNET_free(pm);
1781 } 1771 }
1782 GNUNET_assert (0 == session->msgs_in_queue); 1772 GNUNET_assert(0 == session->msgs_in_queue);
1783 GNUNET_assert (0 == session->bytes_in_queue); 1773 GNUNET_assert(0 == session->bytes_in_queue);
1784 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE); 1774 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_DONE);
1785 1775
1786 if (NULL != session->receive_delay_task) 1776 if (NULL != session->receive_delay_task)
1787 { 1777 {
1788 GNUNET_SCHEDULER_cancel (session->receive_delay_task); 1778 GNUNET_SCHEDULER_cancel(session->receive_delay_task);
1789 session->receive_delay_task = NULL; 1779 session->receive_delay_task = NULL;
1790 } 1780 }
1791 if (NULL != session->client) 1781 if (NULL != session->client)
1792 { 1782 {
1793 GNUNET_SERVER_client_disconnect (session->client); 1783 GNUNET_SERVER_client_disconnect(session->client);
1794 session->client = NULL; 1784 session->client = NULL;
1795 } 1785 }
1796 GNUNET_HELLO_address_free (session->address); 1786 GNUNET_HELLO_address_free(session->address);
1797 GNUNET_assert (NULL == session->transmit_handle); 1787 GNUNET_assert(NULL == session->transmit_handle);
1798 GNUNET_free (session); 1788 GNUNET_free(session);
1799 return GNUNET_OK; 1789 return GNUNET_OK;
1800} 1790}
1801 1791
@@ -1809,7 +1799,7 @@ tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session)
1809 * @return keepalive factor 1799 * @return keepalive factor
1810 */ 1800 */
1811static unsigned int 1801static unsigned int
1812tcp_plugin_query_keepalive_factor (void *cls) 1802tcp_plugin_query_keepalive_factor(void *cls)
1813{ 1803{
1814 return 3; 1804 return 3;
1815} 1805}
@@ -1821,29 +1811,29 @@ tcp_plugin_query_keepalive_factor (void *cls)
1821 * @param cls the `struct GNUNET_ATS_Session` of the idle session 1811 * @param cls the `struct GNUNET_ATS_Session` of the idle session
1822 */ 1812 */
1823static void 1813static void
1824session_timeout (void *cls) 1814session_timeout(void *cls)
1825{ 1815{
1826 struct GNUNET_ATS_Session *s = cls; 1816 struct GNUNET_ATS_Session *s = cls;
1827 struct GNUNET_TIME_Relative left; 1817 struct GNUNET_TIME_Relative left;
1828 1818
1829 s->timeout_task = NULL; 1819 s->timeout_task = NULL;
1830 left = GNUNET_TIME_absolute_get_remaining (s->timeout); 1820 left = GNUNET_TIME_absolute_get_remaining(s->timeout);
1831 if (0 != left.rel_value_us) 1821 if (0 != left.rel_value_us)
1832 { 1822 {
1833 /* not actually our turn yet, but let's at least update 1823 /* not actually our turn yet, but let's at least update
1834 the monitor, it may think we're about to die ... */ 1824 the monitor, it may think we're about to die ... */
1835 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 1825 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1836 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); 1826 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s);
1837 return; 1827 return;
1838 } 1828 }
1839 LOG (GNUNET_ERROR_TYPE_DEBUG, 1829 LOG(GNUNET_ERROR_TYPE_DEBUG,
1840 "Session %p was idle for %s, disconnecting\n", 1830 "Session %p was idle for %s, disconnecting\n",
1841 s, 1831 s,
1842 GNUNET_STRINGS_relative_time_to_string ( 1832 GNUNET_STRINGS_relative_time_to_string(
1843 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1833 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1844 GNUNET_YES)); 1834 GNUNET_YES));
1845 /* call session destroy function */ 1835 /* call session destroy function */
1846 tcp_plugin_disconnect_session (s->plugin, s); 1836 tcp_plugin_disconnect_session(s->plugin, s);
1847} 1837}
1848 1838
1849 1839
@@ -1853,11 +1843,11 @@ session_timeout (void *cls)
1853 * @param s session to increment timeout for 1843 * @param s session to increment timeout for
1854 */ 1844 */
1855static void 1845static void
1856reschedule_session_timeout (struct GNUNET_ATS_Session *s) 1846reschedule_session_timeout(struct GNUNET_ATS_Session *s)
1857{ 1847{
1858 GNUNET_assert (NULL != s->timeout_task); 1848 GNUNET_assert(NULL != s->timeout_task);
1859 s->timeout = 1849 s->timeout =
1860 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1850 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1861} 1851}
1862 1852
1863 1853
@@ -1874,75 +1864,75 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1874 * @return new session object 1864 * @return new session object
1875 */ 1865 */
1876static struct GNUNET_ATS_Session * 1866static struct GNUNET_ATS_Session *
1877create_session (struct Plugin *plugin, 1867create_session(struct Plugin *plugin,
1878 const struct GNUNET_HELLO_Address *address, 1868 const struct GNUNET_HELLO_Address *address,
1879 enum GNUNET_NetworkType scope, 1869 enum GNUNET_NetworkType scope,
1880 struct GNUNET_SERVER_Client *client, 1870 struct GNUNET_SERVER_Client *client,
1881 int is_nat) 1871 int is_nat)
1882{ 1872{
1883 struct GNUNET_ATS_Session *session; 1873 struct GNUNET_ATS_Session *session;
1884 struct PendingMessage *pm; 1874 struct PendingMessage *pm;
1885 1875
1886 if (GNUNET_YES != is_nat) 1876 if (GNUNET_YES != is_nat)
1887 GNUNET_assert (NULL != client); 1877 GNUNET_assert(NULL != client);
1888 else 1878 else
1889 GNUNET_assert (NULL == client); 1879 GNUNET_assert(NULL == client);
1890 1880
1891 LOG (GNUNET_ERROR_TYPE_DEBUG, 1881 LOG(GNUNET_ERROR_TYPE_DEBUG,
1892 "Creating new session for peer `%s' at address %s\n", 1882 "Creating new session for peer `%s' at address %s\n",
1893 GNUNET_i2s (&address->peer), 1883 GNUNET_i2s(&address->peer),
1894 tcp_plugin_address_to_string (plugin, 1884 tcp_plugin_address_to_string(plugin,
1895 address->address, 1885 address->address,
1896 address->address_length)); 1886 address->address_length));
1897 session = GNUNET_new (struct GNUNET_ATS_Session); 1887 session = GNUNET_new(struct GNUNET_ATS_Session);
1898 session->last_activity = GNUNET_TIME_absolute_get (); 1888 session->last_activity = GNUNET_TIME_absolute_get();
1899 session->plugin = plugin; 1889 session->plugin = plugin;
1900 session->is_nat = is_nat; 1890 session->is_nat = is_nat;
1901 if (NULL != client) 1891 if (NULL != client)
1902 { 1892 {
1903 session->client = client; 1893 session->client = client;
1904 GNUNET_SERVER_client_set_user_context (client, session); 1894 GNUNET_SERVER_client_set_user_context(client, session);
1905 } 1895 }
1906 session->address = GNUNET_HELLO_address_copy (address); 1896 session->address = GNUNET_HELLO_address_copy(address);
1907 session->target = address->peer; 1897 session->target = address->peer;
1908 session->expecting_welcome = GNUNET_YES; 1898 session->expecting_welcome = GNUNET_YES;
1909 session->scope = scope; 1899 session->scope = scope;
1910 pm = GNUNET_malloc (sizeof (struct PendingMessage) + 1900 pm = GNUNET_malloc(sizeof(struct PendingMessage) +
1911 sizeof (struct WelcomeMessage)); 1901 sizeof(struct WelcomeMessage));
1912 pm->msg = (const char *) &pm[1]; 1902 pm->msg = (const char *)&pm[1];
1913 pm->message_size = sizeof (struct WelcomeMessage); 1903 pm->message_size = sizeof(struct WelcomeMessage);
1914 GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof (struct WelcomeMessage)); 1904 GNUNET_memcpy(&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage));
1915 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 1905 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
1916 GNUNET_STATISTICS_update (plugin->env->stats, 1906 GNUNET_STATISTICS_update(plugin->env->stats,
1917 gettext_noop ("# bytes currently in TCP buffers"), 1907 gettext_noop("# bytes currently in TCP buffers"),
1918 pm->message_size, 1908 pm->message_size,
1919 GNUNET_NO); 1909 GNUNET_NO);
1920 GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, 1910 GNUNET_CONTAINER_DLL_insert(session->pending_messages_head,
1921 session->pending_messages_tail, 1911 session->pending_messages_tail,
1922 pm); 1912 pm);
1923 session->msgs_in_queue++; 1913 session->msgs_in_queue++;
1924 session->bytes_in_queue += pm->message_size; 1914 session->bytes_in_queue += pm->message_size;
1925 session->timeout = 1915 session->timeout =
1926 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1916 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1927 session->timeout_task = 1917 session->timeout_task =
1928 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1918 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1929 &session_timeout, 1919 &session_timeout,
1930 session); 1920 session);
1931 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT); 1921 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_INIT);
1932 if (GNUNET_YES != is_nat) 1922 if (GNUNET_YES != is_nat)
1933 { 1923 {
1934 GNUNET_STATISTICS_update (plugin->env->stats, 1924 GNUNET_STATISTICS_update(plugin->env->stats,
1935 gettext_noop ("# TCP sessions active"), 1925 gettext_noop("# TCP sessions active"),
1936 1, 1926 1,
1937 GNUNET_NO); 1927 GNUNET_NO);
1938 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP); 1928 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UP);
1939 } 1929 }
1940 else 1930 else
1941 { 1931 {
1942 notify_session_monitor (session->plugin, 1932 notify_session_monitor(session->plugin,
1943 session, 1933 session,
1944 GNUNET_TRANSPORT_SS_HANDSHAKE); 1934 GNUNET_TRANSPORT_SS_HANDSHAKE);
1945 } 1935 }
1946 return session; 1936 return session;
1947} 1937}
1948 1938
@@ -1954,7 +1944,7 @@ create_session (struct Plugin *plugin,
1954 * @param session for which session should we do this 1944 * @param session for which session should we do this
1955 */ 1945 */
1956static void 1946static void
1957process_pending_messages (struct GNUNET_ATS_Session *session); 1947process_pending_messages(struct GNUNET_ATS_Session *session);
1958 1948
1959 1949
1960/** 1950/**
@@ -1969,7 +1959,7 @@ process_pending_messages (struct GNUNET_ATS_Session *session);
1969 * @return number of bytes written to @a buf 1959 * @return number of bytes written to @a buf
1970 */ 1960 */
1971static size_t 1961static size_t
1972do_transmit (void *cls, size_t size, void *buf) 1962do_transmit(void *cls, size_t size, void *buf)
1973{ 1963{
1974 struct GNUNET_ATS_Session *session = cls; 1964 struct GNUNET_ATS_Session *session = cls;
1975 struct GNUNET_PeerIdentity pid; 1965 struct GNUNET_PeerIdentity pid;
@@ -1984,127 +1974,127 @@ do_transmit (void *cls, size_t size, void *buf)
1984 session->transmit_handle = NULL; 1974 session->transmit_handle = NULL;
1985 plugin = session->plugin; 1975 plugin = session->plugin;
1986 if (NULL == buf) 1976 if (NULL == buf)
1987 { 1977 {
1988 LOG (GNUNET_ERROR_TYPE_DEBUG, 1978 LOG(GNUNET_ERROR_TYPE_DEBUG,
1989 "Timeout trying to transmit to peer `%s', discarding message queue.\n", 1979 "Timeout trying to transmit to peer `%s', discarding message queue.\n",
1990 GNUNET_i2s (&session->target)); 1980 GNUNET_i2s(&session->target));
1991 /* timeout; cancel all messages that have already expired */ 1981 /* timeout; cancel all messages that have already expired */
1992 hd = NULL; 1982 hd = NULL;
1993 tl = NULL; 1983 tl = NULL;
1994 ret = 0; 1984 ret = 0;
1995 now = GNUNET_TIME_absolute_get (); 1985 now = GNUNET_TIME_absolute_get();
1996 while ((NULL != (pos = session->pending_messages_head)) && 1986 while ((NULL != (pos = session->pending_messages_head)) &&
1997 (pos->timeout.abs_value_us <= now.abs_value_us)) 1987 (pos->timeout.abs_value_us <= now.abs_value_us))
1998 { 1988 {
1999 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 1989 GNUNET_CONTAINER_DLL_remove(session->pending_messages_head,
2000 session->pending_messages_tail, 1990 session->pending_messages_tail,
2001 pos); 1991 pos);
2002 GNUNET_assert (0 < session->msgs_in_queue); 1992 GNUNET_assert(0 < session->msgs_in_queue);
2003 session->msgs_in_queue--; 1993 session->msgs_in_queue--;
2004 GNUNET_assert (pos->message_size <= session->bytes_in_queue); 1994 GNUNET_assert(pos->message_size <= session->bytes_in_queue);
2005 session->bytes_in_queue -= pos->message_size; 1995 session->bytes_in_queue -= pos->message_size;
2006 LOG (GNUNET_ERROR_TYPE_DEBUG, 1996 LOG(GNUNET_ERROR_TYPE_DEBUG,
2007 "Failed to transmit %u byte message to `%s'.\n", 1997 "Failed to transmit %u byte message to `%s'.\n",
2008 pos->message_size, 1998 pos->message_size,
2009 GNUNET_i2s (&session->target)); 1999 GNUNET_i2s(&session->target));
2010 ret += pos->message_size; 2000 ret += pos->message_size;
2011 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); 2001 GNUNET_CONTAINER_DLL_insert_after(hd, tl, tl, pos);
2012 } 2002 }
2013 /* do this call before callbacks (so that if callbacks destroy 2003 /* do this call before callbacks (so that if callbacks destroy
2014 * session, they have a chance to cancel actions done by this 2004 * session, they have a chance to cancel actions done by this
2015 * call) */ 2005 * call) */
2016 process_pending_messages (session); 2006 process_pending_messages(session);
2017 pid = session->target; 2007 pid = session->target;
2018 /* no do callbacks and do not use session again since 2008 /* no do callbacks and do not use session again since
2019 * the callbacks may abort the session */ 2009 * the callbacks may abort the session */
2020 while (NULL != (pos = hd)) 2010 while (NULL != (pos = hd))
2021 { 2011 {
2022 GNUNET_CONTAINER_DLL_remove (hd, tl, pos); 2012 GNUNET_CONTAINER_DLL_remove(hd, tl, pos);
2023 if (NULL != pos->transmit_cont) 2013 if (NULL != pos->transmit_cont)
2024 pos->transmit_cont (pos->transmit_cont_cls, 2014 pos->transmit_cont(pos->transmit_cont_cls,
2025 &pid, 2015 &pid,
2026 GNUNET_SYSERR, 2016 GNUNET_SYSERR,
2027 pos->message_size, 2017 pos->message_size,
2028 0); 2018 0);
2029 GNUNET_free (pos); 2019 GNUNET_free(pos);
2030 } 2020 }
2031 GNUNET_STATISTICS_update (plugin->env->stats, 2021 GNUNET_STATISTICS_update(plugin->env->stats,
2032 gettext_noop ("# bytes currently in TCP buffers"), 2022 gettext_noop("# bytes currently in TCP buffers"),
2033 -(int64_t) ret, 2023 -(int64_t)ret,
2034 GNUNET_NO); 2024 GNUNET_NO);
2035 GNUNET_STATISTICS_update (plugin->env->stats, 2025 GNUNET_STATISTICS_update(plugin->env->stats,
2036 gettext_noop ( 2026 gettext_noop(
2037 "# bytes discarded by TCP (timeout)"), 2027 "# bytes discarded by TCP (timeout)"),
2038 ret, 2028 ret,
2039 GNUNET_NO); 2029 GNUNET_NO);
2040 if (0 < ret) 2030 if (0 < ret)
2041 notify_session_monitor (session->plugin, 2031 notify_session_monitor(session->plugin,
2042 session, 2032 session,
2043 GNUNET_TRANSPORT_SS_UPDATE); 2033 GNUNET_TRANSPORT_SS_UPDATE);
2044 return 0; 2034 return 0;
2045 } 2035 }
2046 /* copy all pending messages that would fit */ 2036 /* copy all pending messages that would fit */
2047 ret = 0; 2037 ret = 0;
2048 cbuf = buf; 2038 cbuf = buf;
2049 hd = NULL; 2039 hd = NULL;
2050 tl = NULL; 2040 tl = NULL;
2051 while (NULL != (pos = session->pending_messages_head)) 2041 while (NULL != (pos = session->pending_messages_head))
2052 { 2042 {
2053 if (ret + pos->message_size > size) 2043 if (ret + pos->message_size > size)
2054 break; 2044 break;
2055 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 2045 GNUNET_CONTAINER_DLL_remove(session->pending_messages_head,
2056 session->pending_messages_tail, 2046 session->pending_messages_tail,
2057 pos); 2047 pos);
2058 GNUNET_assert (0 < session->msgs_in_queue); 2048 GNUNET_assert(0 < session->msgs_in_queue);
2059 session->msgs_in_queue--; 2049 session->msgs_in_queue--;
2060 GNUNET_assert (pos->message_size <= session->bytes_in_queue); 2050 GNUNET_assert(pos->message_size <= session->bytes_in_queue);
2061 session->bytes_in_queue -= pos->message_size; 2051 session->bytes_in_queue -= pos->message_size;
2062 GNUNET_assert (size >= pos->message_size); 2052 GNUNET_assert(size >= pos->message_size);
2063 LOG (GNUNET_ERROR_TYPE_DEBUG, 2053 LOG(GNUNET_ERROR_TYPE_DEBUG,
2064 "Transmitting message of type %u size %u to peer %s at %s\n", 2054 "Transmitting message of type %u size %u to peer %s at %s\n",
2065 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), 2055 ntohs(((struct GNUNET_MessageHeader *)pos->msg)->type),
2066 pos->message_size, 2056 pos->message_size,
2067 GNUNET_i2s (&session->target), 2057 GNUNET_i2s(&session->target),
2068 tcp_plugin_address_to_string (session->plugin, 2058 tcp_plugin_address_to_string(session->plugin,
2069 session->address->address, 2059 session->address->address,
2070 session->address->address_length)); 2060 session->address->address_length));
2071 /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ 2061 /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */
2072 GNUNET_memcpy (cbuf, pos->msg, pos->message_size); 2062 GNUNET_memcpy(cbuf, pos->msg, pos->message_size);
2073 cbuf += pos->message_size; 2063 cbuf += pos->message_size;
2074 ret += pos->message_size; 2064 ret += pos->message_size;
2075 size -= pos->message_size; 2065 size -= pos->message_size;
2076 GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); 2066 GNUNET_CONTAINER_DLL_insert_tail(hd, tl, pos);
2077 } 2067 }
2078 notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 2068 notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
2079 /* schedule 'continuation' before callbacks so that callbacks that 2069 /* schedule 'continuation' before callbacks so that callbacks that
2080 * cancel everything don't cause us to use a session that no longer 2070 * cancel everything don't cause us to use a session that no longer
2081 * exists... */ 2071 * exists... */
2082 process_pending_messages (session); 2072 process_pending_messages(session);
2083 session->last_activity = GNUNET_TIME_absolute_get (); 2073 session->last_activity = GNUNET_TIME_absolute_get();
2084 pid = session->target; 2074 pid = session->target;
2085 /* we'll now call callbacks that may cancel the session; hence 2075 /* we'll now call callbacks that may cancel the session; hence
2086 * we should not use 'session' after this point */ 2076 * we should not use 'session' after this point */
2087 while (NULL != (pos = hd)) 2077 while (NULL != (pos = hd))
2088 { 2078 {
2089 GNUNET_CONTAINER_DLL_remove (hd, tl, pos); 2079 GNUNET_CONTAINER_DLL_remove(hd, tl, pos);
2090 if (NULL != pos->transmit_cont) 2080 if (NULL != pos->transmit_cont)
2091 pos->transmit_cont (pos->transmit_cont_cls, 2081 pos->transmit_cont(pos->transmit_cont_cls,
2092 &pid, 2082 &pid,
2093 GNUNET_OK, 2083 GNUNET_OK,
2094 pos->message_size, 2084 pos->message_size,
2095 pos->message_size); /* FIXME: include TCP overhead */ 2085 pos->message_size); /* FIXME: include TCP overhead */
2096 GNUNET_free (pos); 2086 GNUNET_free(pos);
2097 } 2087 }
2098 GNUNET_assert (NULL == hd); 2088 GNUNET_assert(NULL == hd);
2099 GNUNET_assert (NULL == tl); 2089 GNUNET_assert(NULL == tl);
2100 GNUNET_STATISTICS_update (plugin->env->stats, 2090 GNUNET_STATISTICS_update(plugin->env->stats,
2101 gettext_noop ("# bytes currently in TCP buffers"), 2091 gettext_noop("# bytes currently in TCP buffers"),
2102 -(int64_t) ret, 2092 -(int64_t)ret,
2103 GNUNET_NO); 2093 GNUNET_NO);
2104 GNUNET_STATISTICS_update (plugin->env->stats, 2094 GNUNET_STATISTICS_update(plugin->env->stats,
2105 gettext_noop ("# bytes transmitted via TCP"), 2095 gettext_noop("# bytes transmitted via TCP"),
2106 ret, 2096 ret,
2107 GNUNET_NO); 2097 GNUNET_NO);
2108 return ret; 2098 return ret;
2109} 2099}
2110 2100
@@ -2116,23 +2106,23 @@ do_transmit (void *cls, size_t size, void *buf)
2116 * @param session for which session should we do this 2106 * @param session for which session should we do this
2117 */ 2107 */
2118static void 2108static void
2119process_pending_messages (struct GNUNET_ATS_Session *session) 2109process_pending_messages(struct GNUNET_ATS_Session *session)
2120{ 2110{
2121 struct PendingMessage *pm; 2111 struct PendingMessage *pm;
2122 2112
2123 GNUNET_assert (NULL != session->client); 2113 GNUNET_assert(NULL != session->client);
2124 if (NULL != session->transmit_handle) 2114 if (NULL != session->transmit_handle)
2125 return; 2115 return;
2126 if (NULL == (pm = session->pending_messages_head)) 2116 if (NULL == (pm = session->pending_messages_head))
2127 return; 2117 return;
2128 2118
2129 session->transmit_handle = 2119 session->transmit_handle =
2130 GNUNET_SERVER_notify_transmit_ready (session->client, 2120 GNUNET_SERVER_notify_transmit_ready(session->client,
2131 pm->message_size, 2121 pm->message_size,
2132 GNUNET_TIME_absolute_get_remaining ( 2122 GNUNET_TIME_absolute_get_remaining(
2133 pm->timeout), 2123 pm->timeout),
2134 &do_transmit, 2124 &do_transmit,
2135 session); 2125 session);
2136} 2126}
2137 2127
2138 2128
@@ -2164,85 +2154,85 @@ process_pending_messages (struct GNUNET_ATS_Session *session)
2164 * and does NOT mean that the message was not transmitted (DV) 2154 * and does NOT mean that the message was not transmitted (DV)
2165 */ 2155 */
2166static ssize_t 2156static ssize_t
2167tcp_plugin_send (void *cls, 2157tcp_plugin_send(void *cls,
2168 struct GNUNET_ATS_Session *session, 2158 struct GNUNET_ATS_Session *session,
2169 const char *msgbuf, 2159 const char *msgbuf,
2170 size_t msgbuf_size, 2160 size_t msgbuf_size,
2171 unsigned int priority, 2161 unsigned int priority,
2172 struct GNUNET_TIME_Relative to, 2162 struct GNUNET_TIME_Relative to,
2173 GNUNET_TRANSPORT_TransmitContinuation cont, 2163 GNUNET_TRANSPORT_TransmitContinuation cont,
2174 void *cont_cls) 2164 void *cont_cls)
2175{ 2165{
2176 struct Plugin *plugin = cls; 2166 struct Plugin *plugin = cls;
2177 struct PendingMessage *pm; 2167 struct PendingMessage *pm;
2178 2168
2179 /* create new message entry */ 2169 /* create new message entry */
2180 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); 2170 pm = GNUNET_malloc(sizeof(struct PendingMessage) + msgbuf_size);
2181 pm->msg = (const char *) &pm[1]; 2171 pm->msg = (const char *)&pm[1];
2182 GNUNET_memcpy (&pm[1], msgbuf, msgbuf_size); 2172 GNUNET_memcpy(&pm[1], msgbuf, msgbuf_size);
2183 pm->message_size = msgbuf_size; 2173 pm->message_size = msgbuf_size;
2184 pm->timeout = GNUNET_TIME_relative_to_absolute (to); 2174 pm->timeout = GNUNET_TIME_relative_to_absolute(to);
2185 pm->transmit_cont = cont; 2175 pm->transmit_cont = cont;
2186 pm->transmit_cont_cls = cont_cls; 2176 pm->transmit_cont_cls = cont_cls;
2187 2177
2188 LOG (GNUNET_ERROR_TYPE_DEBUG, 2178 LOG(GNUNET_ERROR_TYPE_DEBUG,
2189 "Asked to transmit %u bytes to `%s', added message to list.\n", 2179 "Asked to transmit %u bytes to `%s', added message to list.\n",
2190 msgbuf_size, 2180 msgbuf_size,
2191 GNUNET_i2s (&session->target)); 2181 GNUNET_i2s(&session->target));
2192 2182
2193 if (GNUNET_YES == 2183 if (GNUNET_YES ==
2194 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, 2184 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap,
2195 &session->target, 2185 &session->target,
2196 session)) 2186 session))
2197 { 2187 {
2198 GNUNET_assert (NULL != session->client); 2188 GNUNET_assert(NULL != session->client);
2199 GNUNET_SERVER_client_set_timeout (session->client, 2189 GNUNET_SERVER_client_set_timeout(session->client,
2200 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2190 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2201 GNUNET_STATISTICS_update (plugin->env->stats, 2191 GNUNET_STATISTICS_update(plugin->env->stats,
2202 gettext_noop ("# bytes currently in TCP buffers"), 2192 gettext_noop("# bytes currently in TCP buffers"),
2203 msgbuf_size, 2193 msgbuf_size,
2204 GNUNET_NO); 2194 GNUNET_NO);
2205 2195
2206 /* append pm to pending_messages list */ 2196 /* append pm to pending_messages list */
2207 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, 2197 GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head,
2208 session->pending_messages_tail, 2198 session->pending_messages_tail,
2209 pm); 2199 pm);
2210 notify_session_monitor (session->plugin, 2200 notify_session_monitor(session->plugin,
2211 session, 2201 session,
2212 GNUNET_TRANSPORT_SS_UPDATE); 2202 GNUNET_TRANSPORT_SS_UPDATE);
2213 session->msgs_in_queue++; 2203 session->msgs_in_queue++;
2214 session->bytes_in_queue += pm->message_size; 2204 session->bytes_in_queue += pm->message_size;
2215 process_pending_messages (session); 2205 process_pending_messages(session);
2216 return msgbuf_size; 2206 return msgbuf_size;
2217 } 2207 }
2218 if (GNUNET_YES == 2208 if (GNUNET_YES ==
2219 GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, 2209 GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns,
2220 &session->target, 2210 &session->target,
2221 session)) 2211 session))
2222 { 2212 {
2223 LOG (GNUNET_ERROR_TYPE_DEBUG, 2213 LOG(GNUNET_ERROR_TYPE_DEBUG,
2224 "This NAT WAIT session for peer `%s' is not yet ready!\n", 2214 "This NAT WAIT session for peer `%s' is not yet ready!\n",
2225 GNUNET_i2s (&session->target)); 2215 GNUNET_i2s(&session->target));
2226 GNUNET_STATISTICS_update (plugin->env->stats, 2216 GNUNET_STATISTICS_update(plugin->env->stats,
2227 gettext_noop ("# bytes currently in TCP buffers"), 2217 gettext_noop("# bytes currently in TCP buffers"),
2228 msgbuf_size, 2218 msgbuf_size,
2229 GNUNET_NO); 2219 GNUNET_NO);
2230 /* append pm to pending_messages list */ 2220 /* append pm to pending_messages list */
2231 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, 2221 GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head,
2232 session->pending_messages_tail, 2222 session->pending_messages_tail,
2233 pm); 2223 pm);
2234 session->msgs_in_queue++; 2224 session->msgs_in_queue++;
2235 session->bytes_in_queue += pm->message_size; 2225 session->bytes_in_queue += pm->message_size;
2236 notify_session_monitor (session->plugin, 2226 notify_session_monitor(session->plugin,
2237 session, 2227 session,
2238 GNUNET_TRANSPORT_SS_HANDSHAKE); 2228 GNUNET_TRANSPORT_SS_HANDSHAKE);
2239 return msgbuf_size; 2229 return msgbuf_size;
2240 } 2230 }
2241 LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); 2231 LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session);
2242 if (NULL != cont) 2232 if (NULL != cont)
2243 cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); 2233 cont(cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0);
2244 GNUNET_break (0); 2234 GNUNET_break(0);
2245 GNUNET_free (pm); 2235 GNUNET_free(pm);
2246 return GNUNET_SYSERR; /* session does not exist here */ 2236 return GNUNET_SYSERR; /* session does not exist here */
2247} 2237}
2248 2238
@@ -2250,8 +2240,7 @@ tcp_plugin_send (void *cls,
2250/** 2240/**
2251 * Closure for #session_lookup_it(). 2241 * Closure for #session_lookup_it().
2252 */ 2242 */
2253struct GNUNET_ATS_SessionItCtx 2243struct GNUNET_ATS_SessionItCtx {
2254{
2255 /** 2244 /**
2256 * Address we are looking for. 2245 * Address we are looking for.
2257 */ 2246 */
@@ -2273,14 +2262,14 @@ struct GNUNET_ATS_SessionItCtx
2273 * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session 2262 * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session
2274 */ 2263 */
2275static int 2264static int
2276session_lookup_it (void *cls, 2265session_lookup_it(void *cls,
2277 const struct GNUNET_PeerIdentity *key, 2266 const struct GNUNET_PeerIdentity *key,
2278 void *value) 2267 void *value)
2279{ 2268{
2280 struct GNUNET_ATS_SessionItCtx *si_ctx = cls; 2269 struct GNUNET_ATS_SessionItCtx *si_ctx = cls;
2281 struct GNUNET_ATS_Session *session = value; 2270 struct GNUNET_ATS_Session *session = value;
2282 2271
2283 if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) 2272 if (0 != GNUNET_HELLO_address_cmp(si_ctx->address, session->address))
2284 return GNUNET_YES; 2273 return GNUNET_YES;
2285 si_ctx->result = session; 2274 si_ctx->result = session;
2286 return GNUNET_NO; 2275 return GNUNET_NO;
@@ -2293,18 +2282,18 @@ session_lookup_it (void *cls,
2293 * @param cls the `struct GNUNET_ATS_Session` 2282 * @param cls the `struct GNUNET_ATS_Session`
2294 */ 2283 */
2295static void 2284static void
2296nat_connect_timeout (void *cls) 2285nat_connect_timeout(void *cls)
2297{ 2286{
2298 struct GNUNET_ATS_Session *session = cls; 2287 struct GNUNET_ATS_Session *session = cls;
2299 2288
2300 session->nat_connection_timeout = NULL; 2289 session->nat_connection_timeout = NULL;
2301 LOG (GNUNET_ERROR_TYPE_DEBUG, 2290 LOG(GNUNET_ERROR_TYPE_DEBUG,
2302 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", 2291 "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n",
2303 GNUNET_i2s (&session->target), 2292 GNUNET_i2s(&session->target),
2304 tcp_plugin_address_to_string (session->plugin, 2293 tcp_plugin_address_to_string(session->plugin,
2305 session->address->address, 2294 session->address->address,
2306 session->address->address_length)); 2295 session->address->address_length));
2307 tcp_plugin_disconnect_session (session->plugin, session); 2296 tcp_plugin_disconnect_session(session->plugin, session);
2308} 2297}
2309 2298
2310 2299
@@ -2318,11 +2307,11 @@ nat_connect_timeout (void *cls)
2318 * @param session which session is being updated 2307 * @param session which session is being updated
2319 */ 2308 */
2320static void 2309static void
2321tcp_plugin_update_session_timeout (void *cls, 2310tcp_plugin_update_session_timeout(void *cls,
2322 const struct GNUNET_PeerIdentity *peer, 2311 const struct GNUNET_PeerIdentity *peer,
2323 struct GNUNET_ATS_Session *session) 2312 struct GNUNET_ATS_Session *session)
2324{ 2313{
2325 reschedule_session_timeout (session); 2314 reschedule_session_timeout(session);
2326} 2315}
2327 2316
2328 2317
@@ -2333,13 +2322,13 @@ tcp_plugin_update_session_timeout (void *cls,
2333 * @param cls the `struct GNUNET_ATS_Session *` 2322 * @param cls the `struct GNUNET_ATS_Session *`
2334 */ 2323 */
2335static void 2324static void
2336delayed_done (void *cls) 2325delayed_done(void *cls)
2337{ 2326{
2338 struct GNUNET_ATS_Session *session = cls; 2327 struct GNUNET_ATS_Session *session = cls;
2339 2328
2340 session->receive_delay_task = NULL; 2329 session->receive_delay_task = NULL;
2341 reschedule_session_timeout (session); 2330 reschedule_session_timeout(session);
2342 GNUNET_SERVER_receive_done (session->client, GNUNET_OK); 2331 GNUNET_SERVER_receive_done(session->client, GNUNET_OK);
2343} 2332}
2344 2333
2345 2334
@@ -2354,20 +2343,20 @@ delayed_done (void *cls)
2354 * @param delay new delay to use for receiving 2343 * @param delay new delay to use for receiving
2355 */ 2344 */
2356static void 2345static void
2357tcp_plugin_update_inbound_delay (void *cls, 2346tcp_plugin_update_inbound_delay(void *cls,
2358 const struct GNUNET_PeerIdentity *peer, 2347 const struct GNUNET_PeerIdentity *peer,
2359 struct GNUNET_ATS_Session *session, 2348 struct GNUNET_ATS_Session *session,
2360 struct GNUNET_TIME_Relative delay) 2349 struct GNUNET_TIME_Relative delay)
2361{ 2350{
2362 if (NULL == session->receive_delay_task) 2351 if (NULL == session->receive_delay_task)
2363 return; 2352 return;
2364 LOG (GNUNET_ERROR_TYPE_DEBUG, 2353 LOG(GNUNET_ERROR_TYPE_DEBUG,
2365 "New inbound delay %s\n", 2354 "New inbound delay %s\n",
2366 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO)); 2355 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_NO));
2367 session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); 2356 session->receive_delay = GNUNET_TIME_relative_to_absolute(delay);
2368 GNUNET_SCHEDULER_cancel (session->receive_delay_task); 2357 GNUNET_SCHEDULER_cancel(session->receive_delay_task);
2369 session->receive_delay_task = 2358 session->receive_delay_task =
2370 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); 2359 GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session);
2371} 2360}
2372 2361
2373 2362
@@ -2381,7 +2370,7 @@ tcp_plugin_update_inbound_delay (void *cls,
2381 * @return the session if the address is valid, NULL otherwise 2370 * @return the session if the address is valid, NULL otherwise
2382 */ 2371 */
2383static struct GNUNET_ATS_Session * 2372static struct GNUNET_ATS_Session *
2384tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) 2373tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2385{ 2374{
2386 struct Plugin *plugin = cls; 2375 struct Plugin *plugin = cls;
2387 struct GNUNET_ATS_Session *session = NULL; 2376 struct GNUNET_ATS_Session *session = NULL;
@@ -2397,235 +2386,236 @@ tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2397 enum GNUNET_NetworkType net_type; 2386 enum GNUNET_NetworkType net_type;
2398 unsigned int is_natd = GNUNET_NO; 2387 unsigned int is_natd = GNUNET_NO;
2399 size_t addrlen; 2388 size_t addrlen;
2389
2400#ifdef TCP_STEALTH 2390#ifdef TCP_STEALTH
2401 struct GNUNET_NETWORK_Handle *s; 2391 struct GNUNET_NETWORK_Handle *s;
2402#endif 2392#endif
2403 2393
2404 addrlen = address->address_length; 2394 addrlen = address->address_length;
2405 LOG (GNUNET_ERROR_TYPE_DEBUG, 2395 LOG(GNUNET_ERROR_TYPE_DEBUG,
2406 "Trying to get session for `%s' address of peer `%s'\n", 2396 "Trying to get session for `%s' address of peer `%s'\n",
2407 tcp_plugin_address_to_string (plugin, 2397 tcp_plugin_address_to_string(plugin,
2408 address->address, 2398 address->address,
2409 address->address_length), 2399 address->address_length),
2410 GNUNET_i2s (&address->peer)); 2400 GNUNET_i2s(&address->peer));
2411 2401
2412 if (GNUNET_HELLO_address_check_option (address, 2402 if (GNUNET_HELLO_address_check_option(address,
2413 GNUNET_HELLO_ADDRESS_INFO_INBOUND)) 2403 GNUNET_HELLO_ADDRESS_INFO_INBOUND))
2414 { 2404 {
2415 GNUNET_break (0); 2405 GNUNET_break(0);
2416 return NULL; 2406 return NULL;
2417 } 2407 }
2418 2408
2419 /* look for existing session */ 2409 /* look for existing session */
2420 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, 2410 if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(plugin->sessionmap,
2421 &address->peer)) 2411 &address->peer))
2422 { 2412 {
2423 struct GNUNET_ATS_SessionItCtx si_ctx; 2413 struct GNUNET_ATS_SessionItCtx si_ctx;
2424 2414
2425 si_ctx.address = address; 2415 si_ctx.address = address;
2426 si_ctx.result = NULL; 2416 si_ctx.result = NULL;
2427 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, 2417 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap,
2428 &address->peer, 2418 &address->peer,
2429 &session_lookup_it, 2419 &session_lookup_it,
2430 &si_ctx); 2420 &si_ctx);
2431 if (NULL != si_ctx.result) 2421 if (NULL != si_ctx.result)
2432 { 2422 {
2433 session = si_ctx.result; 2423 session = si_ctx.result;
2434 LOG (GNUNET_ERROR_TYPE_DEBUG, 2424 LOG(GNUNET_ERROR_TYPE_DEBUG,
2435 "Found existing session for `%s' address `%s'\n", 2425 "Found existing session for `%s' address `%s'\n",
2436 GNUNET_i2s (&address->peer), 2426 GNUNET_i2s(&address->peer),
2437 tcp_plugin_address_to_string (plugin, 2427 tcp_plugin_address_to_string(plugin,
2438 address->address, 2428 address->address,
2439 address->address_length)); 2429 address->address_length));
2440 return session; 2430 return session;
2441 } 2431 }
2442 /* This is a bit of a hack, limiting TCP to never allow more than 2432 /* This is a bit of a hack, limiting TCP to never allow more than
2443 one TCP connection to any given peer at the same time. 2433 one TCP connection to any given peer at the same time.
2444 Without this, peers sometimes disagree about which of the TCP 2434 Without this, peers sometimes disagree about which of the TCP
2445 connections they should use, causing one side to believe that 2435 connections they should use, causing one side to believe that
2446 they transmit successfully, while the other receives nothing. */ 2436 they transmit successfully, while the other receives nothing. */
2447 return NULL; /* Refuse to have more than one TCP connection per 2437 return NULL; /* Refuse to have more than one TCP connection per
2448 peer pair at the same time. */ 2438 peer pair at the same time. */
2449 } 2439 }
2450 2440
2451 if (addrlen == sizeof (struct IPv6TcpAddress)) 2441 if (addrlen == sizeof(struct IPv6TcpAddress))
2452 { 2442 {
2453 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 2443 GNUNET_assert(NULL != address->address); /* make static analysis happy */
2454 t6 = address->address; 2444 t6 = address->address;
2455 options = t6->options; 2445 options = t6->options;
2456 af = AF_INET6; 2446 af = AF_INET6;
2457 memset (&a6, 0, sizeof (a6)); 2447 memset(&a6, 0, sizeof(a6));
2458#if HAVE_SOCKADDR_IN_SIN_LEN 2448#if HAVE_SOCKADDR_IN_SIN_LEN
2459 a6.sin6_len = sizeof (a6); 2449 a6.sin6_len = sizeof(a6);
2460#endif 2450#endif
2461 a6.sin6_family = AF_INET6; 2451 a6.sin6_family = AF_INET6;
2462 a6.sin6_port = t6->t6_port; 2452 a6.sin6_port = t6->t6_port;
2463 if (t6->t6_port == 0) 2453 if (t6->t6_port == 0)
2464 is_natd = GNUNET_YES; 2454 is_natd = GNUNET_YES;
2465 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); 2455 GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
2466 sb = &a6; 2456 sb = &a6;
2467 sbs = sizeof (a6); 2457 sbs = sizeof(a6);
2468 } 2458 }
2469 else if (addrlen == sizeof (struct IPv4TcpAddress)) 2459 else if (addrlen == sizeof(struct IPv4TcpAddress))
2470 { 2460 {
2471 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 2461 GNUNET_assert(NULL != address->address); /* make static analysis happy */
2472 t4 = address->address; 2462 t4 = address->address;
2473 options = t4->options; 2463 options = t4->options;
2474 af = AF_INET; 2464 af = AF_INET;
2475 memset (&a4, 0, sizeof (a4)); 2465 memset(&a4, 0, sizeof(a4));
2476#if HAVE_SOCKADDR_IN_SIN_LEN 2466#if HAVE_SOCKADDR_IN_SIN_LEN
2477 a4.sin_len = sizeof (a4); 2467 a4.sin_len = sizeof(a4);
2478#endif 2468#endif
2479 a4.sin_family = AF_INET; 2469 a4.sin_family = AF_INET;
2480 a4.sin_port = t4->t4_port; 2470 a4.sin_port = t4->t4_port;
2481 if (t4->t4_port == 0) 2471 if (t4->t4_port == 0)
2482 is_natd = GNUNET_YES; 2472 is_natd = GNUNET_YES;
2483 a4.sin_addr.s_addr = t4->ipv4_addr; 2473 a4.sin_addr.s_addr = t4->ipv4_addr;
2484 sb = &a4; 2474 sb = &a4;
2485 sbs = sizeof (a4); 2475 sbs = sizeof(a4);
2486 } 2476 }
2487 else 2477 else
2488 { 2478 {
2489 GNUNET_STATISTICS_update ( 2479 GNUNET_STATISTICS_update(
2490 plugin->env->stats, 2480 plugin->env->stats,
2491 gettext_noop ("# requests to create session with invalid address"), 2481 gettext_noop("# requests to create session with invalid address"),
2492 1, 2482 1,
2493 GNUNET_NO); 2483 GNUNET_NO);
2494 return NULL; 2484 return NULL;
2495 } 2485 }
2496 2486
2497 net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs); 2487 net_type = plugin->env->get_address_type(plugin->env->cls, sb, sbs);
2498 GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED); 2488 GNUNET_break(net_type != GNUNET_NT_UNSPECIFIED);
2499 2489
2500 if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) 2490 if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress)))
2501 { 2491 {
2502 /* NAT client only works with IPv4 addresses */ 2492 /* NAT client only works with IPv4 addresses */
2503 return NULL; 2493 return NULL;
2504 } 2494 }
2505 2495
2506 if (plugin->cur_connections >= plugin->max_connections) 2496 if (plugin->cur_connections >= plugin->max_connections)
2507 { 2497 {
2508 /* saturated */ 2498 /* saturated */
2509 return NULL; 2499 return NULL;
2510 } 2500 }
2511 2501
2512 if ((is_natd == GNUNET_YES) && 2502 if ((is_natd == GNUNET_YES) &&
2513 (GNUNET_YES == 2503 (GNUNET_YES ==
2514 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, 2504 GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns,
2515 &address->peer))) 2505 &address->peer)))
2516 { 2506 {
2517 /* Only do one NAT punch attempt per peer identity */ 2507 /* Only do one NAT punch attempt per peer identity */
2518 return NULL; 2508 return NULL;
2519 } 2509 }
2520 2510
2521 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && 2511 if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) &&
2522 (GNUNET_NO == 2512 (GNUNET_NO ==
2523 GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, 2513 GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns,
2524 &address->peer))) 2514 &address->peer)))
2525 { 2515 {
2526 struct sockaddr_in local_sa; 2516 struct sockaddr_in local_sa;
2527 2517
2528 LOG (GNUNET_ERROR_TYPE_DEBUG, 2518 LOG(GNUNET_ERROR_TYPE_DEBUG,
2529 "Found valid IPv4 NAT address (creating session)!\n"); 2519 "Found valid IPv4 NAT address (creating session)!\n");
2530 session = create_session (plugin, address, net_type, NULL, GNUNET_YES); 2520 session = create_session(plugin, address, net_type, NULL, GNUNET_YES);
2531 session->nat_connection_timeout = 2521 session->nat_connection_timeout =
2532 GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session); 2522 GNUNET_SCHEDULER_add_delayed(NAT_TIMEOUT, &nat_connect_timeout, session);
2533 GNUNET_assert (GNUNET_OK == 2523 GNUNET_assert(GNUNET_OK ==
2534 GNUNET_CONTAINER_multipeermap_put ( 2524 GNUNET_CONTAINER_multipeermap_put(
2535 plugin->nat_wait_conns, 2525 plugin->nat_wait_conns,
2536 &session->target, 2526 &session->target,
2537 session, 2527 session,
2538 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 2528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2539 2529
2540 LOG (GNUNET_ERROR_TYPE_DEBUG, 2530 LOG(GNUNET_ERROR_TYPE_DEBUG,
2541 "Created NAT WAIT connection to `%s' at `%s'\n", 2531 "Created NAT WAIT connection to `%s' at `%s'\n",
2542 GNUNET_i2s (&session->target), 2532 GNUNET_i2s(&session->target),
2543 GNUNET_a2s (sb, sbs)); 2533 GNUNET_a2s(sb, sbs));
2544 memset (&local_sa, 0, sizeof (local_sa)); 2534 memset(&local_sa, 0, sizeof(local_sa));
2545 local_sa.sin_family = AF_INET; 2535 local_sa.sin_family = AF_INET;
2546 local_sa.sin_port = htons (plugin->open_port); 2536 local_sa.sin_port = htons(plugin->open_port);
2547 /* We leave sin_address at 0, let the kernel figure it out, 2537 /* We leave sin_address at 0, let the kernel figure it out,
2548 even if our bind() is more specific. (May want to reconsider 2538 even if our bind() is more specific. (May want to reconsider
2549 later.) */ 2539 later.) */
2550 if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4)) 2540 if (GNUNET_OK == GNUNET_NAT_request_reversal(plugin->nat, &local_sa, &a4))
2551 return session; 2541 return session;
2552 LOG (GNUNET_ERROR_TYPE_DEBUG, 2542 LOG(GNUNET_ERROR_TYPE_DEBUG,
2553 "Running NAT client for `%s' at `%s' failed\n", 2543 "Running NAT client for `%s' at `%s' failed\n",
2554 GNUNET_i2s (&session->target), 2544 GNUNET_i2s(&session->target),
2555 GNUNET_a2s (sb, sbs)); 2545 GNUNET_a2s(sb, sbs));
2556 tcp_plugin_disconnect_session (plugin, session); 2546 tcp_plugin_disconnect_session(plugin, session);
2557 return NULL; 2547 return NULL;
2558 } 2548 }
2559 2549
2560 /* create new outbound session */ 2550 /* create new outbound session */
2561 if (0 != (options & TCP_OPTIONS_TCP_STEALTH)) 2551 if (0 != (options & TCP_OPTIONS_TCP_STEALTH))
2562 {
2563#ifdef TCP_STEALTH
2564 s = GNUNET_NETWORK_socket_create (af, SOCK_STREAM, 0);
2565 if (NULL == s)
2566 { 2552 {
2567 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 2553#ifdef TCP_STEALTH
2568 "socket"); 2554 s = GNUNET_NETWORK_socket_create(af, SOCK_STREAM, 0);
2569 sa = NULL; 2555 if (NULL == s)
2570 } 2556 {
2571 else 2557 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
2572 { 2558 "socket");
2573 if ((GNUNET_OK != 2559 sa = NULL;
2574 GNUNET_NETWORK_socket_setsockopt (s, 2560 }
2575 IPPROTO_TCP,
2576 TCP_STEALTH,
2577 &session->target,
2578 sizeof (
2579 struct GNUNET_PeerIdentity))) ||
2580 (GNUNET_OK !=
2581 GNUNET_NETWORK_socket_setsockopt (s,
2582 IPPROTO_TCP,
2583 TCP_STEALTH_INTEGRITY,
2584 &plugin->my_welcome,
2585 sizeof (struct WelcomeMessage))))
2586 {
2587 /* TCP STEALTH not supported by kernel */
2588 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s));
2589 sa = NULL;
2590 }
2591 else 2561 else
2592 { 2562 {
2593 sa = GNUNET_CONNECTION_connect_socket (s, sb, sbs); 2563 if ((GNUNET_OK !=
2594 } 2564 GNUNET_NETWORK_socket_setsockopt(s,
2595 } 2565 IPPROTO_TCP,
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 }
2596#else 2586#else
2597 sa = NULL; 2587 sa = NULL;
2598#endif 2588#endif
2599 } 2589 }
2600 else 2590 else
2601 { 2591 {
2602 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); 2592 sa = GNUNET_CONNECTION_create_from_sockaddr(af, sb, sbs);
2603 } 2593 }
2604 if (NULL == sa) 2594 if (NULL == sa)
2605 { 2595 {
2606 LOG (GNUNET_ERROR_TYPE_DEBUG, 2596 LOG(GNUNET_ERROR_TYPE_DEBUG,
2607 "Failed to create connection to `%s' at `%s'\n", 2597 "Failed to create connection to `%s' at `%s'\n",
2608 GNUNET_i2s (&address->peer), 2598 GNUNET_i2s(&address->peer),
2609 GNUNET_a2s (sb, sbs)); 2599 GNUNET_a2s(sb, sbs));
2610 return NULL; 2600 return NULL;
2611 } 2601 }
2612 LOG (GNUNET_ERROR_TYPE_DEBUG, 2602 LOG(GNUNET_ERROR_TYPE_DEBUG,
2613 "Asked to transmit to `%s', creating fresh session using address `%s'.\n", 2603 "Asked to transmit to `%s', creating fresh session using address `%s'.\n",
2614 GNUNET_i2s (&address->peer), 2604 GNUNET_i2s(&address->peer),
2615 GNUNET_a2s (sb, sbs)); 2605 GNUNET_a2s(sb, sbs));
2616 2606
2617 session = create_session (plugin, 2607 session = create_session(plugin,
2618 address, 2608 address,
2619 net_type, 2609 net_type,
2620 GNUNET_SERVER_connect_socket (plugin->server, sa), 2610 GNUNET_SERVER_connect_socket(plugin->server, sa),
2621 GNUNET_NO); 2611 GNUNET_NO);
2622 (void) GNUNET_CONTAINER_multipeermap_put ( 2612 (void)GNUNET_CONTAINER_multipeermap_put(
2623 plugin->sessionmap, 2613 plugin->sessionmap,
2624 &session->target, 2614 &session->target,
2625 session, 2615 session,
2626 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2616 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2627 /* Send TCP Welcome */ 2617 /* Send TCP Welcome */
2628 process_pending_messages (session); 2618 process_pending_messages(session);
2629 2619
2630 return session; 2620 return session;
2631} 2621}
@@ -2642,19 +2632,19 @@ tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2642 * @return #GNUNET_YES (continue to iterate) 2632 * @return #GNUNET_YES (continue to iterate)
2643 */ 2633 */
2644static int 2634static int
2645session_disconnect_it (void *cls, 2635session_disconnect_it(void *cls,
2646 const struct GNUNET_PeerIdentity *key, 2636 const struct GNUNET_PeerIdentity *key,
2647 void *value) 2637 void *value)
2648{ 2638{
2649 struct Plugin *plugin = cls; 2639 struct Plugin *plugin = cls;
2650 struct GNUNET_ATS_Session *session = value; 2640 struct GNUNET_ATS_Session *session = value;
2651 2641
2652 GNUNET_STATISTICS_update (session->plugin->env->stats, 2642 GNUNET_STATISTICS_update(session->plugin->env->stats,
2653 gettext_noop ( 2643 gettext_noop(
2654 "# transport-service disconnect requests for TCP"), 2644 "# transport-service disconnect requests for TCP"),
2655 1, 2645 1,
2656 GNUNET_NO); 2646 GNUNET_NO);
2657 tcp_plugin_disconnect_session (plugin, session); 2647 tcp_plugin_disconnect_session(plugin, session);
2658 return GNUNET_YES; 2648 return GNUNET_YES;
2659} 2649}
2660 2650
@@ -2676,21 +2666,21 @@ session_disconnect_it (void *cls,
2676 * to be cancelled 2666 * to be cancelled
2677 */ 2667 */
2678static void 2668static void
2679tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) 2669tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2680{ 2670{
2681 struct Plugin *plugin = cls; 2671 struct Plugin *plugin = cls;
2682 2672
2683 LOG (GNUNET_ERROR_TYPE_DEBUG, 2673 LOG(GNUNET_ERROR_TYPE_DEBUG,
2684 "Disconnecting peer `%s'\n", 2674 "Disconnecting peer `%s'\n",
2685 GNUNET_i2s (target)); 2675 GNUNET_i2s(target));
2686 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, 2676 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap,
2687 target, 2677 target,
2688 &session_disconnect_it, 2678 &session_disconnect_it,
2689 plugin); 2679 plugin);
2690 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, 2680 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->nat_wait_conns,
2691 target, 2681 target,
2692 &session_disconnect_it, 2682 &session_disconnect_it,
2693 plugin); 2683 plugin);
2694} 2684}
2695 2685
2696 2686
@@ -2705,42 +2695,42 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2705 * @param hostname hostname part of the address 2695 * @param hostname hostname part of the address
2706 */ 2696 */
2707static void 2697static void
2708append_port (void *cls, const char *hostname) 2698append_port(void *cls, const char *hostname)
2709{ 2699{
2710 struct PrettyPrinterContext *ppc = cls; 2700 struct PrettyPrinterContext *ppc = cls;
2711 struct Plugin *plugin = ppc->plugin; 2701 struct Plugin *plugin = ppc->plugin;
2712 char *ret; 2702 char *ret;
2713 2703
2714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2704 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
2715 "append_port called with hostname `%s'\n", 2705 "append_port called with hostname `%s'\n",
2716 hostname); 2706 hostname);
2717 if (NULL == hostname) 2707 if (NULL == hostname)
2718 { 2708 {
2719 /* Final call, done */ 2709 /* Final call, done */
2720 ppc->resolver_handle = NULL; 2710 ppc->resolver_handle = NULL;
2721 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 2711 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head,
2722 plugin->ppc_dll_tail, 2712 plugin->ppc_dll_tail,
2723 ppc); 2713 ppc);
2724 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); 2714 ppc->asc(ppc->asc_cls, NULL, GNUNET_OK);
2725 GNUNET_free (ppc); 2715 GNUNET_free(ppc);
2726 return; 2716 return;
2727 } 2717 }
2728 if (GNUNET_YES == ppc->ipv6) 2718 if (GNUNET_YES == ppc->ipv6)
2729 GNUNET_asprintf (&ret, 2719 GNUNET_asprintf(&ret,
2730 "%s.%u.[%s]:%d", 2720 "%s.%u.[%s]:%d",
2731 PLUGIN_NAME, 2721 PLUGIN_NAME,
2732 ppc->options, 2722 ppc->options,
2733 hostname, 2723 hostname,
2734 ppc->port); 2724 ppc->port);
2735 else 2725 else
2736 GNUNET_asprintf (&ret, 2726 GNUNET_asprintf(&ret,
2737 "%s.%u.%s:%d", 2727 "%s.%u.%s:%d",
2738 PLUGIN_NAME, 2728 PLUGIN_NAME,
2739 ppc->options, 2729 ppc->options,
2740 hostname, 2730 hostname,
2741 ppc->port); 2731 ppc->port);
2742 ppc->asc (ppc->asc_cls, ret, GNUNET_OK); 2732 ppc->asc(ppc->asc_cls, ret, GNUNET_OK);
2743 GNUNET_free (ret); 2733 GNUNET_free(ret);
2744} 2734}
2745 2735
2746 2736
@@ -2758,14 +2748,14 @@ append_port (void *cls, const char *hostname)
2758 * @param asc_cls closure for @a asc 2748 * @param asc_cls closure for @a asc
2759 */ 2749 */
2760static void 2750static void
2761tcp_plugin_address_pretty_printer (void *cls, 2751tcp_plugin_address_pretty_printer(void *cls,
2762 const char *type, 2752 const char *type,
2763 const void *addr, 2753 const void *addr,
2764 size_t addrlen, 2754 size_t addrlen,
2765 int numeric, 2755 int numeric,
2766 struct GNUNET_TIME_Relative timeout, 2756 struct GNUNET_TIME_Relative timeout,
2767 GNUNET_TRANSPORT_AddressStringCallback asc, 2757 GNUNET_TRANSPORT_AddressStringCallback asc,
2768 void *asc_cls) 2758 void *asc_cls)
2769{ 2759{
2770 struct Plugin *plugin = cls; 2760 struct Plugin *plugin = cls;
2771 struct PrettyPrinterContext *ppc; 2761 struct PrettyPrinterContext *ppc;
@@ -2778,43 +2768,43 @@ tcp_plugin_address_pretty_printer (void *cls,
2778 uint16_t port; 2768 uint16_t port;
2779 uint32_t options; 2769 uint32_t options;
2780 2770
2781 if (sizeof (struct IPv6TcpAddress) == addrlen) 2771 if (sizeof(struct IPv6TcpAddress) == addrlen)
2782 { 2772 {
2783 t6 = addr; 2773 t6 = addr;
2784 memset (&a6, 0, sizeof (a6)); 2774 memset(&a6, 0, sizeof(a6));
2785 a6.sin6_family = AF_INET6; 2775 a6.sin6_family = AF_INET6;
2786 a6.sin6_port = t6->t6_port; 2776 a6.sin6_port = t6->t6_port;
2787 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); 2777 GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
2788 port = ntohs (t6->t6_port); 2778 port = ntohs(t6->t6_port);
2789 options = ntohl (t6->options); 2779 options = ntohl(t6->options);
2790 sb = &a6; 2780 sb = &a6;
2791 sbs = sizeof (a6); 2781 sbs = sizeof(a6);
2792 } 2782 }
2793 else if (sizeof (struct IPv4TcpAddress) == addrlen) 2783 else if (sizeof(struct IPv4TcpAddress) == addrlen)
2794 { 2784 {
2795 t4 = addr; 2785 t4 = addr;
2796 memset (&a4, 0, sizeof (a4)); 2786 memset(&a4, 0, sizeof(a4));
2797 a4.sin_family = AF_INET; 2787 a4.sin_family = AF_INET;
2798 a4.sin_port = t4->t4_port; 2788 a4.sin_port = t4->t4_port;
2799 a4.sin_addr.s_addr = t4->ipv4_addr; 2789 a4.sin_addr.s_addr = t4->ipv4_addr;
2800 port = ntohs (t4->t4_port); 2790 port = ntohs(t4->t4_port);
2801 options = ntohl (t4->options); 2791 options = ntohl(t4->options);
2802 sb = &a4; 2792 sb = &a4;
2803 sbs = sizeof (a4); 2793 sbs = sizeof(a4);
2804 } 2794 }
2805 else 2795 else
2806 { 2796 {
2807 /* invalid address */ 2797 /* invalid address */
2808 LOG (GNUNET_ERROR_TYPE_WARNING, 2798 LOG(GNUNET_ERROR_TYPE_WARNING,
2809 _ ("Unexpected address length: %u bytes\n"), 2799 _("Unexpected address length: %u bytes\n"),
2810 (unsigned int) addrlen); 2800 (unsigned int)addrlen);
2811 asc (asc_cls, NULL, GNUNET_SYSERR); 2801 asc(asc_cls, NULL, GNUNET_SYSERR);
2812 asc (asc_cls, NULL, GNUNET_OK); 2802 asc(asc_cls, NULL, GNUNET_OK);
2813 return; 2803 return;
2814 } 2804 }
2815 ppc = GNUNET_new (struct PrettyPrinterContext); 2805 ppc = GNUNET_new(struct PrettyPrinterContext);
2816 ppc->plugin = plugin; 2806 ppc->plugin = plugin;
2817 if (addrlen == sizeof (struct IPv6TcpAddress)) 2807 if (addrlen == sizeof(struct IPv6TcpAddress))
2818 ppc->ipv6 = GNUNET_YES; 2808 ppc->ipv6 = GNUNET_YES;
2819 else 2809 else
2820 ppc->ipv6 = GNUNET_NO; 2810 ppc->ipv6 = GNUNET_NO;
@@ -2822,20 +2812,20 @@ tcp_plugin_address_pretty_printer (void *cls,
2822 ppc->asc_cls = asc_cls; 2812 ppc->asc_cls = asc_cls;
2823 ppc->port = port; 2813 ppc->port = port;
2824 ppc->options = options; 2814 ppc->options = options;
2825 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); 2815 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n");
2826 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, 2816 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb,
2827 sbs, 2817 sbs,
2828 ! numeric, 2818 !numeric,
2829 timeout, 2819 timeout,
2830 &append_port, 2820 &append_port,
2831 ppc); 2821 ppc);
2832 if (NULL == ppc->resolver_handle) 2822 if (NULL == ppc->resolver_handle)
2833 { 2823 {
2834 GNUNET_break (0); 2824 GNUNET_break(0);
2835 GNUNET_free (ppc); 2825 GNUNET_free(ppc);
2836 return; 2826 return;
2837 } 2827 }
2838 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); 2828 GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
2839} 2829}
2840 2830
2841 2831
@@ -2855,69 +2845,69 @@ tcp_plugin_address_pretty_printer (void *cls,
2855 * and transport, #GNUNET_SYSERR if not 2845 * and transport, #GNUNET_SYSERR if not
2856 */ 2846 */
2857static int 2847static int
2858tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) 2848tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen)
2859{ 2849{
2860 struct Plugin *plugin = cls; 2850 struct Plugin *plugin = cls;
2861 const struct IPv4TcpAddress *v4; 2851 const struct IPv4TcpAddress *v4;
2862 const struct IPv6TcpAddress *v6; 2852 const struct IPv6TcpAddress *v6;
2863 2853
2864 if ((addrlen != sizeof (struct IPv4TcpAddress)) && 2854 if ((addrlen != sizeof(struct IPv4TcpAddress)) &&
2865 (addrlen != sizeof (struct IPv6TcpAddress))) 2855 (addrlen != sizeof(struct IPv6TcpAddress)))
2866 {
2867 GNUNET_break_op (0);
2868 return GNUNET_SYSERR;
2869 }
2870
2871 if (addrlen == sizeof (struct IPv4TcpAddress))
2872 {
2873 struct sockaddr_in s4;
2874
2875 v4 = (const struct IPv4TcpAddress *) addr;
2876 if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof (uint32_t)))
2877 { 2856 {
2878 GNUNET_break (0); 2857 GNUNET_break_op(0);
2879 return GNUNET_SYSERR; 2858 return GNUNET_SYSERR;
2880 } 2859 }
2881 memset (&s4, 0, sizeof (s4)); 2860
2882 s4.sin_family = AF_INET; 2861 if (addrlen == sizeof(struct IPv4TcpAddress))
2862 {
2863 struct sockaddr_in s4;
2864
2865 v4 = (const struct IPv4TcpAddress *)addr;
2866 if (0 != memcmp(&v4->options, &plugin->myoptions, sizeof(uint32_t)))
2867 {
2868 GNUNET_break(0);
2869 return GNUNET_SYSERR;
2870 }
2871 memset(&s4, 0, sizeof(s4));
2872 s4.sin_family = AF_INET;
2883#if HAVE_SOCKADDR_IN_SIN_LEN 2873#if HAVE_SOCKADDR_IN_SIN_LEN
2884 s4.sin_len = sizeof (s4); 2874 s4.sin_len = sizeof(s4);
2885#endif 2875#endif
2886 s4.sin_port = v4->t4_port; 2876 s4.sin_port = v4->t4_port;
2887 s4.sin_addr.s_addr = v4->ipv4_addr; 2877 s4.sin_addr.s_addr = v4->ipv4_addr;
2888
2889 if (GNUNET_OK !=
2890 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in)))
2891 return GNUNET_SYSERR;
2892 }
2893 else
2894 {
2895 struct sockaddr_in6 s6;
2896 2878
2897 v6 = (const struct IPv6TcpAddress *) addr; 2879 if (GNUNET_OK !=
2898 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 2880 GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in)))
2899 { 2881 return GNUNET_SYSERR;
2900 GNUNET_break_op (0);
2901 return GNUNET_SYSERR;
2902 } 2882 }
2903 if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof (uint32_t))) 2883 else
2904 { 2884 {
2905 GNUNET_break (0); 2885 struct sockaddr_in6 s6;
2906 return GNUNET_SYSERR; 2886
2907 } 2887 v6 = (const struct IPv6TcpAddress *)addr;
2908 memset (&s6, 0, sizeof (s6)); 2888 if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr))
2909 s6.sin6_family = AF_INET6; 2889 {
2890 GNUNET_break_op(0);
2891 return GNUNET_SYSERR;
2892 }
2893 if (0 != memcmp(&v6->options, &plugin->myoptions, sizeof(uint32_t)))
2894 {
2895 GNUNET_break(0);
2896 return GNUNET_SYSERR;
2897 }
2898 memset(&s6, 0, sizeof(s6));
2899 s6.sin6_family = AF_INET6;
2910#if HAVE_SOCKADDR_IN_SIN_LEN 2900#if HAVE_SOCKADDR_IN_SIN_LEN
2911 s6.sin6_len = sizeof (s6); 2901 s6.sin6_len = sizeof(s6);
2912#endif 2902#endif
2913 s6.sin6_port = v6->t6_port; 2903 s6.sin6_port = v6->t6_port;
2914 s6.sin6_addr = v6->ipv6_addr; 2904 s6.sin6_addr = v6->ipv6_addr;
2915 2905
2916 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, 2906 if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat,
2917 &s6, 2907 &s6,
2918 sizeof (struct sockaddr_in6))) 2908 sizeof(struct sockaddr_in6)))
2919 return GNUNET_SYSERR; 2909 return GNUNET_SYSERR;
2920 } 2910 }
2921 return GNUNET_OK; 2911 return GNUNET_OK;
2922} 2912}
2923 2913
@@ -2932,9 +2922,9 @@ tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
2932 * @param message the actual message 2922 * @param message the actual message
2933 */ 2923 */
2934static void 2924static void
2935handle_tcp_nat_probe (void *cls, 2925handle_tcp_nat_probe(void *cls,
2936 struct GNUNET_SERVER_Client *client, 2926 struct GNUNET_SERVER_Client *client,
2937 const struct GNUNET_MessageHeader *message) 2927 const struct GNUNET_MessageHeader *message)
2938{ 2928{
2939 struct Plugin *plugin = cls; 2929 struct Plugin *plugin = cls;
2940 struct GNUNET_ATS_Session *session; 2930 struct GNUNET_ATS_Session *session;
@@ -2946,113 +2936,115 @@ handle_tcp_nat_probe (void *cls,
2946 const struct sockaddr_in *s4; 2936 const struct sockaddr_in *s4;
2947 const struct sockaddr_in6 *s6; 2937 const struct sockaddr_in6 *s6;
2948 2938
2949 LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); 2939 LOG(GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n");
2950 /* We have received a TCP NAT probe, meaning we (hopefully) initiated 2940 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
2951 * a connection to this peer by running gnunet-nat-client. This peer 2941 * a connection to this peer by running gnunet-nat-client. This peer
2952 * received the punch message and now wants us to use the new connection 2942 * received the punch message and now wants us to use the new connection
2953 * as the default for that peer. Do so and then send a WELCOME message 2943 * as the default for that peer. Do so and then send a WELCOME message
2954 * so we can really be connected! 2944 * so we can really be connected!
2955 */ 2945 */
2956 if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage)) 2946 if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage))
2957 { 2947 {
2958 GNUNET_break_op (0); 2948 GNUNET_break_op(0);
2959 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2949 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
2960 return; 2950 return;
2961 } 2951 }
2962 2952
2963 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; 2953 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *)message;
2964 if (0 == memcmp (&tcp_nat_probe->clientIdentity, 2954 if (0 == memcmp(&tcp_nat_probe->clientIdentity,
2965 plugin->env->my_identity, 2955 plugin->env->my_identity,
2966 sizeof (struct GNUNET_PeerIdentity))) 2956 sizeof(struct GNUNET_PeerIdentity)))
2967 { 2957 {
2968 /* refuse connections from ourselves */ 2958 /* refuse connections from ourselves */
2969 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2959 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
2970 return; 2960 return;
2971 } 2961 }
2972 2962
2973 session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, 2963 session = GNUNET_CONTAINER_multipeermap_get(plugin->nat_wait_conns,
2974 &tcp_nat_probe->clientIdentity); 2964 &tcp_nat_probe->clientIdentity);
2975 if (NULL == session) 2965 if (NULL == session)
2976 { 2966 {
2977 LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); 2967 LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n");
2978 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2968 GNUNET_SERVER_receive_done(client, GNUNET_OK);
2979 return; 2969 return;
2980 } 2970 }
2981 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); 2971 LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n");
2982 2972
2983 if (NULL != session->nat_connection_timeout) 2973 if (NULL != session->nat_connection_timeout)
2984 { 2974 {
2985 GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); 2975 GNUNET_SCHEDULER_cancel(session->nat_connection_timeout);
2986 session->nat_connection_timeout = NULL; 2976 session->nat_connection_timeout = NULL;
2987 } 2977 }
2988 2978
2989 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 2979 if (GNUNET_OK != GNUNET_SERVER_client_get_address(client, &vaddr, &alen))
2990 { 2980 {
2991 GNUNET_break (0); 2981 GNUNET_break(0);
2992 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2982 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
2993 tcp_plugin_disconnect_session (plugin, session); 2983 tcp_plugin_disconnect_session(plugin, session);
2994 return; 2984 return;
2995 } 2985 }
2996 GNUNET_assert ( 2986 GNUNET_assert(
2997 GNUNET_YES == 2987 GNUNET_YES ==
2998 GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, 2988 GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns,
2999 &tcp_nat_probe->clientIdentity, 2989 &tcp_nat_probe->clientIdentity,
3000 session)); 2990 session));
3001 GNUNET_SERVER_client_set_user_context (client, session); 2991 GNUNET_SERVER_client_set_user_context(client, session);
3002 (void) GNUNET_CONTAINER_multipeermap_put ( 2992 (void)GNUNET_CONTAINER_multipeermap_put(
3003 plugin->sessionmap, 2993 plugin->sessionmap,
3004 &session->target, 2994 &session->target,
3005 session, 2995 session,
3006 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2996 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3007 session->last_activity = GNUNET_TIME_absolute_get (); 2997 session->last_activity = GNUNET_TIME_absolute_get();
3008 LOG (GNUNET_ERROR_TYPE_DEBUG, 2998 LOG(GNUNET_ERROR_TYPE_DEBUG,
3009 "Found address `%s' for incoming connection\n", 2999 "Found address `%s' for incoming connection\n",
3010 GNUNET_a2s (vaddr, alen)); 3000 GNUNET_a2s(vaddr, alen));
3011 switch (((const struct sockaddr *) vaddr)->sa_family) 3001 switch (((const struct sockaddr *)vaddr)->sa_family)
3012 { 3002 {
3013 case AF_INET: 3003 case AF_INET:
3014 s4 = vaddr; 3004 s4 = vaddr;
3015 t4 = GNUNET_new (struct IPv4TcpAddress); 3005 t4 = GNUNET_new(struct IPv4TcpAddress);
3016 t4->options = htonl (TCP_OPTIONS_NONE); 3006 t4->options = htonl(TCP_OPTIONS_NONE);
3017 t4->t4_port = s4->sin_port; 3007 t4->t4_port = s4->sin_port;
3018 t4->ipv4_addr = s4->sin_addr.s_addr; 3008 t4->ipv4_addr = s4->sin_addr.s_addr;
3019 session->address = 3009 session->address =
3020 GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, 3010 GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity,
3021 PLUGIN_NAME, 3011 PLUGIN_NAME,
3022 &t4, 3012 &t4,
3023 sizeof (struct IPv4TcpAddress), 3013 sizeof(struct IPv4TcpAddress),
3024 GNUNET_HELLO_ADDRESS_INFO_NONE); 3014 GNUNET_HELLO_ADDRESS_INFO_NONE);
3025 break; 3015 break;
3026 case AF_INET6: 3016
3027 s6 = vaddr; 3017 case AF_INET6:
3028 t6 = GNUNET_new (struct IPv6TcpAddress); 3018 s6 = vaddr;
3029 t6->options = htonl (TCP_OPTIONS_NONE); 3019 t6 = GNUNET_new(struct IPv6TcpAddress);
3030 t6->t6_port = s6->sin6_port; 3020 t6->options = htonl(TCP_OPTIONS_NONE);
3031 GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); 3021 t6->t6_port = s6->sin6_port;
3032 session->address = 3022 GNUNET_memcpy(&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
3033 GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, 3023 session->address =
3034 PLUGIN_NAME, 3024 GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity,
3035 &t6, 3025 PLUGIN_NAME,
3036 sizeof (struct IPv6TcpAddress), 3026 &t6,
3037 GNUNET_HELLO_ADDRESS_INFO_NONE); 3027 sizeof(struct IPv6TcpAddress),
3038 break; 3028 GNUNET_HELLO_ADDRESS_INFO_NONE);
3039 default: 3029 break;
3040 GNUNET_break_op (0); 3030
3041 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); 3031 default:
3042 GNUNET_free (vaddr); 3032 GNUNET_break_op(0);
3043 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3033 LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n");
3044 tcp_plugin_disconnect_session (plugin, session); 3034 GNUNET_free(vaddr);
3045 return; 3035 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3046 } 3036 tcp_plugin_disconnect_session(plugin, session);
3047 GNUNET_free (vaddr); 3037 return;
3048 GNUNET_break (NULL == session->client); 3038 }
3039 GNUNET_free(vaddr);
3040 GNUNET_break(NULL == session->client);
3049 session->client = client; 3041 session->client = client;
3050 GNUNET_STATISTICS_update (plugin->env->stats, 3042 GNUNET_STATISTICS_update(plugin->env->stats,
3051 gettext_noop ("# TCP sessions active"), 3043 gettext_noop("# TCP sessions active"),
3052 1, 3044 1,
3053 GNUNET_NO); 3045 GNUNET_NO);
3054 process_pending_messages (session); 3046 process_pending_messages(session);
3055 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3047 GNUNET_SERVER_receive_done(client, GNUNET_OK);
3056} 3048}
3057 3049
3058 3050
@@ -3065,12 +3057,12 @@ handle_tcp_nat_probe (void *cls,
3065 * @param message the actual message 3057 * @param message the actual message
3066 */ 3058 */
3067static void 3059static void
3068handle_tcp_welcome (void *cls, 3060handle_tcp_welcome(void *cls,
3069 struct GNUNET_SERVER_Client *client, 3061 struct GNUNET_SERVER_Client *client,
3070 const struct GNUNET_MessageHeader *message) 3062 const struct GNUNET_MessageHeader *message)
3071{ 3063{
3072 struct Plugin *plugin = cls; 3064 struct Plugin *plugin = cls;
3073 const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; 3065 const struct WelcomeMessage *wm = (const struct WelcomeMessage *)message;
3074 struct GNUNET_HELLO_Address *address; 3066 struct GNUNET_HELLO_Address *address;
3075 struct GNUNET_ATS_Session *session; 3067 struct GNUNET_ATS_Session *session;
3076 size_t alen; 3068 size_t alen;
@@ -3080,141 +3072,141 @@ handle_tcp_welcome (void *cls,
3080 const struct sockaddr_in *s4; 3072 const struct sockaddr_in *s4;
3081 const struct sockaddr_in6 *s6; 3073 const struct sockaddr_in6 *s6;
3082 3074
3083 if (0 == memcmp (&wm->clientIdentity, 3075 if (0 == memcmp(&wm->clientIdentity,
3084 plugin->env->my_identity, 3076 plugin->env->my_identity,
3085 sizeof (struct GNUNET_PeerIdentity))) 3077 sizeof(struct GNUNET_PeerIdentity)))
3086 {
3087 /* refuse connections from ourselves */
3088 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3089 { 3078 {
3090 LOG (GNUNET_ERROR_TYPE_INFO, 3079 /* refuse connections from ourselves */
3091 "Received WELCOME message from my own identity `%s' on address `%s'\n", 3080 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen))
3092 GNUNET_i2s (&wm->clientIdentity), 3081 {
3093 GNUNET_a2s (vaddr, alen)); 3082 LOG(GNUNET_ERROR_TYPE_INFO,
3094 GNUNET_free (vaddr); 3083 "Received WELCOME message from my own identity `%s' on address `%s'\n",
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;
3095 } 3090 }
3096 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3097 return;
3098 }
3099 3091
3100 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 3092 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen))
3101 { 3093 {
3102 LOG (GNUNET_ERROR_TYPE_DEBUG, 3094 LOG(GNUNET_ERROR_TYPE_DEBUG,
3103 "Received WELCOME message from `%s' on address `%s'\n", 3095 "Received WELCOME message from `%s' on address `%s'\n",
3104 GNUNET_i2s (&wm->clientIdentity), 3096 GNUNET_i2s(&wm->clientIdentity),
3105 GNUNET_a2s (vaddr, alen)); 3097 GNUNET_a2s(vaddr, alen));
3106 GNUNET_free (vaddr); 3098 GNUNET_free(vaddr);
3107 } 3099 }
3108 GNUNET_STATISTICS_update (plugin->env->stats, 3100 GNUNET_STATISTICS_update(plugin->env->stats,
3109 gettext_noop ("# TCP WELCOME messages received"), 3101 gettext_noop("# TCP WELCOME messages received"),
3110 1, 3102 1,
3111 GNUNET_NO); 3103 GNUNET_NO);
3112 session = lookup_session_by_client (plugin, client); 3104 session = lookup_session_by_client(plugin, client);
3113 if (NULL != session) 3105 if (NULL != session)
3114 {
3115 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
3116 { 3106 {
3117 LOG (GNUNET_ERROR_TYPE_DEBUG, 3107 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen))
3118 "Found existing session %p for peer `%s'\n", 3108 {
3119 session, 3109 LOG(GNUNET_ERROR_TYPE_DEBUG,
3120 GNUNET_a2s (vaddr, alen)); 3110 "Found existing session %p for peer `%s'\n",
3121 GNUNET_free (vaddr); 3111 session,
3112 GNUNET_a2s(vaddr, alen));
3113 GNUNET_free(vaddr);
3114 }
3122 } 3115 }
3123 }
3124 else 3116 else
3125 { 3117 {
3126 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 3118 if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen))
3127 { 3119 {
3128 if (alen == sizeof (struct sockaddr_in)) 3120 if (alen == sizeof(struct sockaddr_in))
3129 { 3121 {
3130 s4 = vaddr; 3122 s4 = vaddr;
3131 memset (&t4, '\0', sizeof (t4)); 3123 memset(&t4, '\0', sizeof(t4));
3132 t4.options = htonl (TCP_OPTIONS_NONE); 3124 t4.options = htonl(TCP_OPTIONS_NONE);
3133 t4.t4_port = s4->sin_port; 3125 t4.t4_port = s4->sin_port;
3134 t4.ipv4_addr = s4->sin_addr.s_addr; 3126 t4.ipv4_addr = s4->sin_addr.s_addr;
3135 address = 3127 address =
3136 GNUNET_HELLO_address_allocate (&wm->clientIdentity, 3128 GNUNET_HELLO_address_allocate(&wm->clientIdentity,
3137 PLUGIN_NAME, 3129 PLUGIN_NAME,
3138 &t4, 3130 &t4,
3139 sizeof (t4), 3131 sizeof(t4),
3140 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 3132 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
3141 } 3133 }
3142 else if (alen == sizeof (struct sockaddr_in6)) 3134 else if (alen == sizeof(struct sockaddr_in6))
3143 { 3135 {
3144 s6 = vaddr; 3136 s6 = vaddr;
3145 memset (&t6, '\0', sizeof (t6)); 3137 memset(&t6, '\0', sizeof(t6));
3146 t6.options = htonl (TCP_OPTIONS_NONE); 3138 t6.options = htonl(TCP_OPTIONS_NONE);
3147 t6.t6_port = s6->sin6_port; 3139 t6.t6_port = s6->sin6_port;
3148 GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); 3140 GNUNET_memcpy(&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
3149 address = 3141 address =
3150 GNUNET_HELLO_address_allocate (&wm->clientIdentity, 3142 GNUNET_HELLO_address_allocate(&wm->clientIdentity,
3151 PLUGIN_NAME, 3143 PLUGIN_NAME,
3152 &t6, 3144 &t6,
3153 sizeof (t6), 3145 sizeof(t6),
3154 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 3146 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
3155 } 3147 }
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 }
3156 else 3187 else
3157 { 3188 {
3158 GNUNET_break (0); 3189 LOG(GNUNET_ERROR_TYPE_DEBUG,
3159 GNUNET_free_non_null (vaddr); 3190 "Did not obtain TCP socket address for incoming connection\n");
3160 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3191 GNUNET_break(0);
3161 return; 3192 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3162 } 3193 return;
3163 session = create_session (plugin, 3194 }
3164 address,
3165 plugin->env->get_address_type (plugin->env->cls,
3166 vaddr,
3167 alen),
3168 client,
3169 GNUNET_NO);
3170 GNUNET_break (GNUNET_NT_UNSPECIFIED != session->scope);
3171 GNUNET_HELLO_address_free (address);
3172 LOG (GNUNET_ERROR_TYPE_DEBUG,
3173 "Creating new%s session %p for peer `%s' client %p\n",
3174 GNUNET_HELLO_address_check_option (session->address,
3175 GNUNET_HELLO_ADDRESS_INFO_INBOUND)
3176 ? " inbound"
3177 : "",
3178 session,
3179 tcp_plugin_address_to_string (plugin,
3180 session->address->address,
3181 session->address->address_length),
3182 client);
3183 GNUNET_free (vaddr);
3184 (void) GNUNET_CONTAINER_multipeermap_put (
3185 plugin->sessionmap,
3186 &session->target,
3187 session,
3188 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3189 /* Notify transport and ATS about new session */
3190 plugin->env->session_start (plugin->env->cls,
3191 session->address,
3192 session,
3193 session->scope);
3194 }
3195 else
3196 {
3197 LOG (GNUNET_ERROR_TYPE_DEBUG,
3198 "Did not obtain TCP socket address for incoming connection\n");
3199 GNUNET_break (0);
3200 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3201 return;
3202 } 3195 }
3203 }
3204 3196
3205 if (GNUNET_YES != session->expecting_welcome) 3197 if (GNUNET_YES != session->expecting_welcome)
3206 { 3198 {
3207 GNUNET_break_op (0); 3199 GNUNET_break_op(0);
3208 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3200 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3209 return; 3201 return;
3210 } 3202 }
3211 session->last_activity = GNUNET_TIME_absolute_get (); 3203 session->last_activity = GNUNET_TIME_absolute_get();
3212 session->expecting_welcome = GNUNET_NO; 3204 session->expecting_welcome = GNUNET_NO;
3213 3205
3214 process_pending_messages (session); 3206 process_pending_messages(session);
3215 GNUNET_SERVER_client_set_timeout (client, 3207 GNUNET_SERVER_client_set_timeout(client,
3216 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 3208 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
3217 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3209 GNUNET_SERVER_receive_done(client, GNUNET_OK);
3218} 3210}
3219 3211
3220 3212
@@ -3227,102 +3219,102 @@ handle_tcp_welcome (void *cls,
3227 * @param message the actual message 3219 * @param message the actual message
3228 */ 3220 */
3229static void 3221static void
3230handle_tcp_data (void *cls, 3222handle_tcp_data(void *cls,
3231 struct GNUNET_SERVER_Client *client, 3223 struct GNUNET_SERVER_Client *client,
3232 const struct GNUNET_MessageHeader *message) 3224 const struct GNUNET_MessageHeader *message)
3233{ 3225{
3234 struct Plugin *plugin = cls; 3226 struct Plugin *plugin = cls;
3235 struct GNUNET_ATS_Session *session; 3227 struct GNUNET_ATS_Session *session;
3236 struct GNUNET_TIME_Relative delay; 3228 struct GNUNET_TIME_Relative delay;
3237 uint16_t type; 3229 uint16_t type;
3238 3230
3239 type = ntohs (message->type); 3231 type = ntohs(message->type);
3240 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || 3232 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
3241 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) 3233 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
3242 { 3234 {
3243 /* We don't want to propagate WELCOME and NAT Probe messages up! */ 3235 /* We don't want to propagate WELCOME and NAT Probe messages up! */
3244 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3236 GNUNET_SERVER_receive_done(client, GNUNET_OK);
3245 return; 3237 return;
3246 } 3238 }
3247 session = lookup_session_by_client (plugin, client); 3239 session = lookup_session_by_client(plugin, client);
3248 if (NULL == session) 3240 if (NULL == session)
3249 { 3241 {
3250 /* No inbound session found */ 3242 /* No inbound session found */
3251 void *vaddr = NULL; 3243 void *vaddr = NULL;
3252 size_t alen; 3244 size_t alen;
3253 3245
3254 GNUNET_assert (GNUNET_OK == 3246 GNUNET_assert(GNUNET_OK ==
3255 GNUNET_SERVER_client_get_address (client, &vaddr, &alen)); 3247 GNUNET_SERVER_client_get_address(client, &vaddr, &alen));
3256 LOG (GNUNET_ERROR_TYPE_ERROR, 3248 LOG(GNUNET_ERROR_TYPE_ERROR,
3257 "Received unexpected %u bytes of type %u from `%s'\n", 3249 "Received unexpected %u bytes of type %u from `%s'\n",
3258 (unsigned int) ntohs (message->size), 3250 (unsigned int)ntohs(message->size),
3259 (unsigned int) ntohs (message->type), 3251 (unsigned int)ntohs(message->type),
3260 GNUNET_a2s (vaddr, alen)); 3252 GNUNET_a2s(vaddr, alen));
3261 GNUNET_break_op (0); 3253 GNUNET_break_op(0);
3262 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3254 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3263 GNUNET_free_non_null (vaddr); 3255 GNUNET_free_non_null(vaddr);
3264 return; 3256 return;
3265 } 3257 }
3266 if (GNUNET_YES == session->expecting_welcome) 3258 if (GNUNET_YES == session->expecting_welcome)
3267 { 3259 {
3268 /* Session is expecting WELCOME message */ 3260 /* Session is expecting WELCOME message */
3269 void *vaddr = NULL; 3261 void *vaddr = NULL;
3270 size_t alen; 3262 size_t alen;
3271 3263
3272 GNUNET_SERVER_client_get_address (client, &vaddr, &alen); 3264 GNUNET_SERVER_client_get_address(client, &vaddr, &alen);
3273 LOG (GNUNET_ERROR_TYPE_ERROR, 3265 LOG(GNUNET_ERROR_TYPE_ERROR,
3274 "Received unexpected %u bytes of type %u from `%s'\n", 3266 "Received unexpected %u bytes of type %u from `%s'\n",
3275 (unsigned int) ntohs (message->size), 3267 (unsigned int)ntohs(message->size),
3276 (unsigned int) ntohs (message->type), 3268 (unsigned int)ntohs(message->type),
3277 GNUNET_a2s (vaddr, alen)); 3269 GNUNET_a2s(vaddr, alen));
3278 GNUNET_break_op (0); 3270 GNUNET_break_op(0);
3279 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3271 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
3280 GNUNET_free_non_null (vaddr); 3272 GNUNET_free_non_null(vaddr);
3281 return; 3273 return;
3282 } 3274 }
3283 3275
3284 session->last_activity = GNUNET_TIME_absolute_get (); 3276 session->last_activity = GNUNET_TIME_absolute_get();
3285 { 3277 {
3286 void *vaddr = NULL; 3278 void *vaddr = NULL;
3287 size_t alen; 3279 size_t alen;
3288 3280
3289 GNUNET_SERVER_client_get_address (client, &vaddr, &alen); 3281 GNUNET_SERVER_client_get_address(client, &vaddr, &alen);
3290 LOG (GNUNET_ERROR_TYPE_DEBUG, 3282 LOG(GNUNET_ERROR_TYPE_DEBUG,
3291 "Passing %u bytes of type %u from `%s' at %s to transport service.\n", 3283 "Passing %u bytes of type %u from `%s' at %s to transport service.\n",
3292 (unsigned int) ntohs (message->size), 3284 (unsigned int)ntohs(message->size),
3293 (unsigned int) ntohs (message->type), 3285 (unsigned int)ntohs(message->type),
3294 GNUNET_i2s (&session->target), 3286 GNUNET_i2s(&session->target),
3295 GNUNET_a2s (vaddr, alen)); 3287 GNUNET_a2s(vaddr, alen));
3296 GNUNET_free_non_null (vaddr); 3288 GNUNET_free_non_null(vaddr);
3297 } 3289 }
3298 3290
3299 GNUNET_STATISTICS_update (plugin->env->stats, 3291 GNUNET_STATISTICS_update(plugin->env->stats,
3300 gettext_noop ("# bytes received via TCP"), 3292 gettext_noop("# bytes received via TCP"),
3301 ntohs (message->size), 3293 ntohs(message->size),
3302 GNUNET_NO); 3294 GNUNET_NO);
3303 3295
3304 GNUNET_assert ( 3296 GNUNET_assert(
3305 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, 3297 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap,
3306 &session->target, 3298 &session->target,
3307 session)); 3299 session));
3308 delay = 3300 delay =
3309 plugin->env->receive (plugin->env->cls, session->address, session, message); 3301 plugin->env->receive(plugin->env->cls, session->address, session, message);
3310 reschedule_session_timeout (session); 3302 reschedule_session_timeout(session);
3311 if (0 == delay.rel_value_us) 3303 if (0 == delay.rel_value_us)
3312 { 3304 {
3313 GNUNET_SERVER_receive_done (client, GNUNET_OK); 3305 GNUNET_SERVER_receive_done(client, GNUNET_OK);
3314 } 3306 }
3315 else 3307 else
3316 { 3308 {
3317 LOG (GNUNET_ERROR_TYPE_DEBUG, 3309 LOG(GNUNET_ERROR_TYPE_DEBUG,
3318 "Throttling receiving from `%s' for %s\n", 3310 "Throttling receiving from `%s' for %s\n",
3319 GNUNET_i2s (&session->target), 3311 GNUNET_i2s(&session->target),
3320 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 3312 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
3321 GNUNET_SERVER_disable_receive_done_warning (client); 3313 GNUNET_SERVER_disable_receive_done_warning(client);
3322 GNUNET_assert (NULL == session->receive_delay_task); 3314 GNUNET_assert(NULL == session->receive_delay_task);
3323 session->receive_delay_task = 3315 session->receive_delay_task =
3324 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); 3316 GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session);
3325 } 3317 }
3326} 3318}
3327 3319
3328 3320
@@ -3335,30 +3327,30 @@ handle_tcp_data (void *cls,
3335 * @param client identification of the client 3327 * @param client identification of the client
3336 */ 3328 */
3337static void 3329static void
3338connect_notify (void *cls, struct GNUNET_SERVER_Client *client) 3330connect_notify(void *cls, struct GNUNET_SERVER_Client *client)
3339{ 3331{
3340 struct Plugin *plugin = cls; 3332 struct Plugin *plugin = cls;
3341 3333
3342 if (NULL == client) 3334 if (NULL == client)
3343 return; 3335 return;
3344 plugin->cur_connections++; 3336 plugin->cur_connections++;
3345 GNUNET_STATISTICS_set (plugin->env->stats, 3337 GNUNET_STATISTICS_set(plugin->env->stats,
3346 gettext_noop ("# TCP server connections active"), 3338 gettext_noop("# TCP server connections active"),
3347 plugin->cur_connections, 3339 plugin->cur_connections,
3348 GNUNET_NO); 3340 GNUNET_NO);
3349 GNUNET_STATISTICS_update (plugin->env->stats, 3341 GNUNET_STATISTICS_update(plugin->env->stats,
3350 gettext_noop ("# TCP server connect events"), 3342 gettext_noop("# TCP server connect events"),
3351 1, 3343 1,
3352 GNUNET_NO); 3344 GNUNET_NO);
3353 if (plugin->cur_connections != plugin->max_connections) 3345 if (plugin->cur_connections != plugin->max_connections)
3354 return; 3346 return;
3355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3347 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
3356 _ ("TCP connection limit reached, suspending server\n")); 3348 _("TCP connection limit reached, suspending server\n"));
3357 GNUNET_STATISTICS_update (plugin->env->stats, 3349 GNUNET_STATISTICS_update(plugin->env->stats,
3358 gettext_noop ("# TCP service suspended"), 3350 gettext_noop("# TCP service suspended"),
3359 1, 3351 1,
3360 GNUNET_NO); 3352 GNUNET_NO);
3361 GNUNET_SERVER_suspend ( 3353 GNUNET_SERVER_suspend(
3362 plugin->server); /* Maximum number of connections rechead */ 3354 plugin->server); /* Maximum number of connections rechead */
3363} 3355}
3364 3356
@@ -3372,43 +3364,43 @@ connect_notify (void *cls, struct GNUNET_SERVER_Client *client)
3372 * @param client identification of the client 3364 * @param client identification of the client
3373 */ 3365 */
3374static void 3366static void
3375disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) 3367disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client)
3376{ 3368{
3377 struct Plugin *plugin = cls; 3369 struct Plugin *plugin = cls;
3378 struct GNUNET_ATS_Session *session; 3370 struct GNUNET_ATS_Session *session;
3379 3371
3380 if (NULL == client) 3372 if (NULL == client)
3381 return; 3373 return;
3382 GNUNET_assert (plugin->cur_connections >= 1); 3374 GNUNET_assert(plugin->cur_connections >= 1);
3383 plugin->cur_connections--; 3375 plugin->cur_connections--;
3384 session = lookup_session_by_client (plugin, client); 3376 session = lookup_session_by_client(plugin, client);
3385 if (NULL == session) 3377 if (NULL == session)
3386 return; /* unknown, nothing to do */ 3378 return; /* unknown, nothing to do */
3387 LOG (GNUNET_ERROR_TYPE_DEBUG, 3379 LOG(GNUNET_ERROR_TYPE_DEBUG,
3388 "Destroying session of `%s' with %s due to network-level disconnect.\n", 3380 "Destroying session of `%s' with %s due to network-level disconnect.\n",
3389 GNUNET_i2s (&session->target), 3381 GNUNET_i2s(&session->target),
3390 tcp_plugin_address_to_string (session->plugin, 3382 tcp_plugin_address_to_string(session->plugin,
3391 session->address->address, 3383 session->address->address,
3392 session->address->address_length)); 3384 session->address->address_length));
3393 3385
3394 if (plugin->cur_connections == plugin->max_connections) 3386 if (plugin->cur_connections == plugin->max_connections)
3395 { 3387 {
3396 GNUNET_STATISTICS_update (session->plugin->env->stats, 3388 GNUNET_STATISTICS_update(session->plugin->env->stats,
3397 gettext_noop ("# TCP service resumed"), 3389 gettext_noop("# TCP service resumed"),
3398 1, 3390 1,
3399 GNUNET_NO); 3391 GNUNET_NO);
3400 GNUNET_SERVER_resume (plugin->server); /* Resume server */ 3392 GNUNET_SERVER_resume(plugin->server); /* Resume server */
3401 } 3393 }
3402 GNUNET_STATISTICS_set (plugin->env->stats, 3394 GNUNET_STATISTICS_set(plugin->env->stats,
3403 gettext_noop ("# TCP server connections active"), 3395 gettext_noop("# TCP server connections active"),
3404 plugin->cur_connections, 3396 plugin->cur_connections,
3405 GNUNET_NO); 3397 GNUNET_NO);
3406 GNUNET_STATISTICS_update (session->plugin->env->stats, 3398 GNUNET_STATISTICS_update(session->plugin->env->stats,
3407 gettext_noop ( 3399 gettext_noop(
3408 "# network-level TCP disconnect events"), 3400 "# network-level TCP disconnect events"),
3409 1, 3401 1,
3410 GNUNET_NO); 3402 GNUNET_NO);
3411 tcp_plugin_disconnect_session (plugin, session); 3403 tcp_plugin_disconnect_session(plugin, session);
3412} 3404}
3413 3405
3414 3406
@@ -3421,28 +3413,28 @@ disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
3421 * @return number of bytes copied into @a buf 3413 * @return number of bytes copied into @a buf
3422 */ 3414 */
3423static size_t 3415static size_t
3424notify_send_probe (void *cls, size_t size, void *buf) 3416notify_send_probe(void *cls, size_t size, void *buf)
3425{ 3417{
3426 struct TCPProbeContext *tcp_probe_ctx = cls; 3418 struct TCPProbeContext *tcp_probe_ctx = cls;
3427 struct Plugin *plugin = tcp_probe_ctx->plugin; 3419 struct Plugin *plugin = tcp_probe_ctx->plugin;
3428 size_t ret; 3420 size_t ret;
3429 3421
3430 tcp_probe_ctx->transmit_handle = NULL; 3422 tcp_probe_ctx->transmit_handle = NULL;
3431 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, 3423 GNUNET_CONTAINER_DLL_remove(plugin->probe_head,
3432 plugin->probe_tail, 3424 plugin->probe_tail,
3433 tcp_probe_ctx); 3425 tcp_probe_ctx);
3434 if (NULL == buf) 3426 if (NULL == buf)
3435 { 3427 {
3436 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); 3428 GNUNET_CONNECTION_destroy(tcp_probe_ctx->sock);
3437 GNUNET_free (tcp_probe_ctx); 3429 GNUNET_free(tcp_probe_ctx);
3438 return 0; 3430 return 0;
3439 } 3431 }
3440 GNUNET_assert (size >= sizeof (tcp_probe_ctx->message)); 3432 GNUNET_assert(size >= sizeof(tcp_probe_ctx->message));
3441 GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message)); 3433 GNUNET_memcpy(buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message));
3442 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, 3434 GNUNET_SERVER_connect_socket(tcp_probe_ctx->plugin->server,
3443 tcp_probe_ctx->sock); 3435 tcp_probe_ctx->sock);
3444 ret = sizeof (tcp_probe_ctx->message); 3436 ret = sizeof(tcp_probe_ctx->message);
3445 GNUNET_free (tcp_probe_ctx); 3437 GNUNET_free(tcp_probe_ctx);
3446 return ret; 3438 return ret;
3447} 3439}
3448 3440
@@ -3457,9 +3449,9 @@ notify_send_probe (void *cls, size_t size, void *buf)
3457 * @param addrlen number of bytes in @a addr 3449 * @param addrlen number of bytes in @a addr
3458 */ 3450 */
3459static void 3451static void
3460try_connection_reversal (void *cls, 3452try_connection_reversal(void *cls,
3461 const struct sockaddr *addr, 3453 const struct sockaddr *addr,
3462 socklen_t addrlen) 3454 socklen_t addrlen)
3463{ 3455{
3464 struct Plugin *plugin = cls; 3456 struct Plugin *plugin = cls;
3465 struct GNUNET_CONNECTION_Handle *sock; 3457 struct GNUNET_CONNECTION_Handle *sock;
@@ -3469,31 +3461,31 @@ try_connection_reversal (void *cls,
3469 * We have received an ICMP response, ostensibly from a peer 3461 * We have received an ICMP response, ostensibly from a peer
3470 * that wants to connect to us! Send a message to establish a connection. 3462 * that wants to connect to us! Send a message to establish a connection.
3471 */ 3463 */
3472 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); 3464 sock = GNUNET_CONNECTION_create_from_sockaddr(AF_INET, addr, addrlen);
3473 if (NULL == sock) 3465 if (NULL == sock)
3474 { 3466 {
3475 /* failed for some odd reason (out of sockets?); ignore attempt */ 3467 /* failed for some odd reason (out of sockets?); ignore attempt */
3476 return; 3468 return;
3477 } 3469 }
3478 3470
3479 tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); 3471 tcp_probe_ctx = GNUNET_new(struct TCPProbeContext);
3480 tcp_probe_ctx->message.header.size = 3472 tcp_probe_ctx->message.header.size =
3481 htons (sizeof (struct TCP_NAT_ProbeMessage)); 3473 htons(sizeof(struct TCP_NAT_ProbeMessage));
3482 tcp_probe_ctx->message.header.type = 3474 tcp_probe_ctx->message.header.type =
3483 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); 3475 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
3484 tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity; 3476 tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity;
3485 tcp_probe_ctx->plugin = plugin; 3477 tcp_probe_ctx->plugin = plugin;
3486 tcp_probe_ctx->sock = sock; 3478 tcp_probe_ctx->sock = sock;
3487 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, 3479 GNUNET_CONTAINER_DLL_insert(plugin->probe_head,
3488 plugin->probe_tail, 3480 plugin->probe_tail,
3489 tcp_probe_ctx); 3481 tcp_probe_ctx);
3490 tcp_probe_ctx->transmit_handle = 3482 tcp_probe_ctx->transmit_handle =
3491 GNUNET_CONNECTION_notify_transmit_ready (sock, 3483 GNUNET_CONNECTION_notify_transmit_ready(sock,
3492 ntohs (tcp_probe_ctx->message 3484 ntohs(tcp_probe_ctx->message
3493 .header.size), 3485 .header.size),
3494 GNUNET_TIME_UNIT_FOREVER_REL, 3486 GNUNET_TIME_UNIT_FOREVER_REL,
3495 &notify_send_probe, 3487 &notify_send_probe,
3496 tcp_probe_ctx); 3488 tcp_probe_ctx);
3497} 3489}
3498 3490
3499 3491
@@ -3505,7 +3497,7 @@ try_connection_reversal (void *cls,
3505 * @return the network type in HBO or #GNUNET_SYSERR 3497 * @return the network type in HBO or #GNUNET_SYSERR
3506 */ 3498 */
3507static enum GNUNET_NetworkType 3499static enum GNUNET_NetworkType
3508tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) 3500tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
3509{ 3501{
3510 return session->scope; 3502 return session->scope;
3511} 3503}
@@ -3519,8 +3511,8 @@ tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
3519 * @return the network type 3511 * @return the network type
3520 */ 3512 */
3521static enum GNUNET_NetworkType 3513static enum GNUNET_NetworkType
3522tcp_plugin_get_network_for_address (void *cls, 3514tcp_plugin_get_network_for_address(void *cls,
3523 const struct GNUNET_HELLO_Address *address) 3515 const struct GNUNET_HELLO_Address *address)
3524{ 3516{
3525 struct Plugin *plugin = cls; 3517 struct Plugin *plugin = cls;
3526 size_t addrlen; 3518 size_t addrlen;
@@ -3532,40 +3524,40 @@ tcp_plugin_get_network_for_address (void *cls,
3532 size_t sbs; 3524 size_t sbs;
3533 3525
3534 addrlen = address->address_length; 3526 addrlen = address->address_length;
3535 if (addrlen == sizeof (struct IPv6TcpAddress)) 3527 if (addrlen == sizeof(struct IPv6TcpAddress))
3536 { 3528 {
3537 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 3529 GNUNET_assert(NULL != address->address); /* make static analysis happy */
3538 t6 = address->address; 3530 t6 = address->address;
3539 memset (&a6, 0, sizeof (a6)); 3531 memset(&a6, 0, sizeof(a6));
3540#if HAVE_SOCKADDR_IN_SIN_LEN 3532#if HAVE_SOCKADDR_IN_SIN_LEN
3541 a6.sin6_len = sizeof (a6); 3533 a6.sin6_len = sizeof(a6);
3542#endif 3534#endif
3543 a6.sin6_family = AF_INET6; 3535 a6.sin6_family = AF_INET6;
3544 a6.sin6_port = t6->t6_port; 3536 a6.sin6_port = t6->t6_port;
3545 GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); 3537 GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
3546 sb = &a6; 3538 sb = &a6;
3547 sbs = sizeof (a6); 3539 sbs = sizeof(a6);
3548 } 3540 }
3549 else if (addrlen == sizeof (struct IPv4TcpAddress)) 3541 else if (addrlen == sizeof(struct IPv4TcpAddress))
3550 { 3542 {
3551 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 3543 GNUNET_assert(NULL != address->address); /* make static analysis happy */
3552 t4 = address->address; 3544 t4 = address->address;
3553 memset (&a4, 0, sizeof (a4)); 3545 memset(&a4, 0, sizeof(a4));
3554#if HAVE_SOCKADDR_IN_SIN_LEN 3546#if HAVE_SOCKADDR_IN_SIN_LEN
3555 a4.sin_len = sizeof (a4); 3547 a4.sin_len = sizeof(a4);
3556#endif 3548#endif
3557 a4.sin_family = AF_INET; 3549 a4.sin_family = AF_INET;
3558 a4.sin_port = t4->t4_port; 3550 a4.sin_port = t4->t4_port;
3559 a4.sin_addr.s_addr = t4->ipv4_addr; 3551 a4.sin_addr.s_addr = t4->ipv4_addr;
3560 sb = &a4; 3552 sb = &a4;
3561 sbs = sizeof (a4); 3553 sbs = sizeof(a4);
3562 } 3554 }
3563 else 3555 else
3564 { 3556 {
3565 GNUNET_break (0); 3557 GNUNET_break(0);
3566 return GNUNET_NT_UNSPECIFIED; 3558 return GNUNET_NT_UNSPECIFIED;
3567 } 3559 }
3568 return plugin->env->get_address_type (plugin->env->cls, sb, sbs); 3560 return plugin->env->get_address_type(plugin->env->cls, sb, sbs);
3569} 3561}
3570 3562
3571 3563
@@ -3579,17 +3571,17 @@ tcp_plugin_get_network_for_address (void *cls,
3579 * @return #GNUNET_OK (continue to iterate) 3571 * @return #GNUNET_OK (continue to iterate)
3580 */ 3572 */
3581static int 3573static int
3582send_session_info_iter (void *cls, 3574send_session_info_iter(void *cls,
3583 const struct GNUNET_PeerIdentity *peer, 3575 const struct GNUNET_PeerIdentity *peer,
3584 void *value) 3576 void *value)
3585{ 3577{
3586 struct Plugin *plugin = cls; 3578 struct Plugin *plugin = cls;
3587 struct GNUNET_ATS_Session *session = value; 3579 struct GNUNET_ATS_Session *session = value;
3588 3580
3589 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); 3581 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT);
3590 /* FIXME: cannot tell if this is up or not from current 3582 /* FIXME: cannot tell if this is up or not from current
3591 session state... */ 3583 session state... */
3592 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); 3584 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP);
3593 return GNUNET_OK; 3585 return GNUNET_OK;
3594} 3586}
3595 3587
@@ -3607,22 +3599,22 @@ send_session_info_iter (void *cls,
3607 * @param sic_cls closure for @a sic 3599 * @param sic_cls closure for @a sic
3608 */ 3600 */
3609static void 3601static void
3610tcp_plugin_setup_monitor (void *cls, 3602tcp_plugin_setup_monitor(void *cls,
3611 GNUNET_TRANSPORT_SessionInfoCallback sic, 3603 GNUNET_TRANSPORT_SessionInfoCallback sic,
3612 void *sic_cls) 3604 void *sic_cls)
3613{ 3605{
3614 struct Plugin *plugin = cls; 3606 struct Plugin *plugin = cls;
3615 3607
3616 plugin->sic = sic; 3608 plugin->sic = sic;
3617 plugin->sic_cls = sic_cls; 3609 plugin->sic_cls = sic_cls;
3618 if (NULL != sic) 3610 if (NULL != sic)
3619 { 3611 {
3620 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, 3612 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap,
3621 &send_session_info_iter, 3613 &send_session_info_iter,
3622 plugin); 3614 plugin);
3623 /* signal end of first iteration */ 3615 /* signal end of first iteration */
3624 sic (sic_cls, NULL, NULL); 3616 sic(sic_cls, NULL, NULL);
3625 } 3617 }
3626} 3618}
3627 3619
3628 3620
@@ -3633,19 +3625,19 @@ tcp_plugin_setup_monitor (void *cls,
3633 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error 3625 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error
3634 */ 3626 */
3635void * 3627void *
3636libgnunet_plugin_transport_tcp_init (void *cls) 3628libgnunet_plugin_transport_tcp_init(void *cls)
3637{ 3629{
3638 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = 3630 static const struct GNUNET_SERVER_MessageHandler my_handlers[] =
3639 {{&handle_tcp_welcome, 3631 { { &handle_tcp_welcome,
3640 NULL, 3632 NULL,
3641 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, 3633 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
3642 sizeof (struct WelcomeMessage)}, 3634 sizeof(struct WelcomeMessage) },
3643 {&handle_tcp_nat_probe, 3635 { &handle_tcp_nat_probe,
3644 NULL, 3636 NULL,
3645 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, 3637 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
3646 sizeof (struct TCP_NAT_ProbeMessage)}, 3638 sizeof(struct TCP_NAT_ProbeMessage) },
3647 {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, 3639 { &handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0 },
3648 {NULL, NULL, 0, 0}}; 3640 { NULL, NULL, 0, 0 } };
3649 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3641 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3650 struct GNUNET_TRANSPORT_PluginFunctions *api; 3642 struct GNUNET_TRANSPORT_PluginFunctions *api;
3651 struct Plugin *plugin; 3643 struct Plugin *plugin;
@@ -3655,6 +3647,7 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3655 unsigned long long max_connections; 3647 unsigned long long max_connections;
3656 unsigned int i; 3648 unsigned int i;
3657 struct GNUNET_TIME_Relative idle_timeout; 3649 struct GNUNET_TIME_Relative idle_timeout;
3650
3658#ifdef TCP_STEALTH 3651#ifdef TCP_STEALTH
3659 struct GNUNET_NETWORK_Handle *const *lsocks; 3652 struct GNUNET_NETWORK_Handle *const *lsocks;
3660#endif 3653#endif
@@ -3664,152 +3657,152 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3664 socklen_t *addrlens; 3657 socklen_t *addrlens;
3665 3658
3666 if (NULL == env->receive) 3659 if (NULL == env->receive)
3667 { 3660 {
3668 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3661 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3669 initialze the plugin or the API */ 3662 initialze the plugin or the API */
3670 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3663 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3671 api->cls = NULL; 3664 api->cls = NULL;
3672 api->address_pretty_printer = &tcp_plugin_address_pretty_printer; 3665 api->address_pretty_printer = &tcp_plugin_address_pretty_printer;
3673 api->address_to_string = &tcp_plugin_address_to_string; 3666 api->address_to_string = &tcp_plugin_address_to_string;
3674 api->string_to_address = &tcp_plugin_string_to_address; 3667 api->string_to_address = &tcp_plugin_string_to_address;
3675 return api; 3668 return api;
3676 } 3669 }
3677 3670
3678 GNUNET_assert (NULL != env->cfg); 3671 GNUNET_assert(NULL != env->cfg);
3679 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3672 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3680 "transport-tcp", 3673 "transport-tcp",
3681 "MAX_CONNECTIONS", 3674 "MAX_CONNECTIONS",
3682 &max_connections)) 3675 &max_connections))
3683 max_connections = 128; 3676 max_connections = 128;
3684 3677
3685 aport = 0; 3678 aport = 0;
3686 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3679 if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3687 "transport-tcp", 3680 "transport-tcp",
3688 "PORT", 3681 "PORT",
3689 &bport)) || 3682 &bport)) ||
3690 (bport > 65535) || 3683 (bport > 65535) ||
3691 ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg, 3684 ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(env->cfg,
3692 "transport-tcp", 3685 "transport-tcp",
3693 "ADVERTISED-PORT", 3686 "ADVERTISED-PORT",
3694 &aport)) && 3687 &aport)) &&
3695 (aport > 65535))) 3688 (aport > 65535)))
3696 { 3689 {
3697 LOG (GNUNET_ERROR_TYPE_ERROR, 3690 LOG(GNUNET_ERROR_TYPE_ERROR,
3698 _ ("Require valid port number for service `%s' in configuration!\n"), 3691 _("Require valid port number for service `%s' in configuration!\n"),
3699 "transport-tcp"); 3692 "transport-tcp");
3700 return NULL; 3693 return NULL;
3701 } 3694 }
3702 if (0 == aport) 3695 if (0 == aport)
3703 aport = bport; 3696 aport = bport;
3704 if (0 == bport) 3697 if (0 == bport)
3705 aport = 0; 3698 aport = 0;
3706 if (0 != bport) 3699 if (0 != bport)
3707 {
3708 service = LEGACY_SERVICE_start ("transport-tcp",
3709 env->cfg,
3710 LEGACY_SERVICE_OPTION_NONE);
3711 if (NULL == service)
3712 { 3700 {
3713 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n")); 3701 service = LEGACY_SERVICE_start("transport-tcp",
3714 return NULL; 3702 env->cfg,
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 }
3715 } 3709 }
3716 }
3717 else 3710 else
3718 service = NULL; 3711 service = NULL;
3719 3712
3720 api = NULL; 3713 api = NULL;
3721 plugin = GNUNET_new (struct Plugin); 3714 plugin = GNUNET_new(struct Plugin);
3722 plugin->sessionmap = 3715 plugin->sessionmap =
3723 GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); 3716 GNUNET_CONTAINER_multipeermap_create(max_connections, GNUNET_YES);
3724 plugin->max_connections = max_connections; 3717 plugin->max_connections = max_connections;
3725 plugin->open_port = bport; 3718 plugin->open_port = bport;
3726 plugin->adv_port = aport; 3719 plugin->adv_port = aport;
3727 plugin->env = env; 3720 plugin->env = env;
3728 plugin->my_welcome.header.size = htons (sizeof (struct WelcomeMessage)); 3721 plugin->my_welcome.header.size = htons(sizeof(struct WelcomeMessage));
3729 plugin->my_welcome.header.type = 3722 plugin->my_welcome.header.type =
3730 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); 3723 htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
3731 plugin->my_welcome.clientIdentity = *plugin->env->my_identity; 3724 plugin->my_welcome.clientIdentity = *plugin->env->my_identity;
3732 3725
3733 if ((NULL != service) && 3726 if ((NULL != service) &&
3734 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3727 (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
3735 "transport-tcp", 3728 "transport-tcp",
3736 "TCP_STEALTH"))) 3729 "TCP_STEALTH")))
3737 { 3730 {
3738#ifdef TCP_STEALTH 3731#ifdef TCP_STEALTH
3739 plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; 3732 plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH;
3740 lsocks = LEGACY_SERVICE_get_listen_sockets (service); 3733 lsocks = LEGACY_SERVICE_get_listen_sockets(service);
3741 if (NULL != lsocks) 3734 if (NULL != lsocks)
3742 {
3743 uint32_t len = sizeof (struct WelcomeMessage);
3744
3745 for (i = 0; NULL != lsocks[i]; i++)
3746 {
3747 if (
3748 (GNUNET_OK !=
3749 GNUNET_NETWORK_socket_setsockopt (lsocks[i],
3750 IPPROTO_TCP,
3751 TCP_STEALTH,
3752 env->my_identity,
3753 sizeof (
3754 struct GNUNET_PeerIdentity))) ||
3755 (GNUNET_OK !=
3756 GNUNET_NETWORK_socket_setsockopt (lsocks[i],
3757 IPPROTO_TCP,
3758 TCP_STEALTH_INTEGRITY_LEN,
3759 &len,
3760 sizeof (len))))
3761 { 3735 {
3762 /* TCP STEALTH not supported by kernel */ 3736 uint32_t len = sizeof(struct WelcomeMessage);
3763 GNUNET_assert (0 == i); 3737
3764 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3738 for (i = 0; NULL != lsocks[i]; i++)
3765 _ ("TCP_STEALTH not supported on this platform.\n")); 3739 {
3766 goto die; 3740 if (
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 }
3767 } 3762 }
3768 }
3769 }
3770#else 3763#else
3771 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3764 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
3772 _ ("TCP_STEALTH not supported on this platform.\n")); 3765 _("TCP_STEALTH not supported on this platform.\n"));
3773 goto die; 3766 goto die;
3774#endif 3767#endif
3775 } 3768 }
3776 3769
3777 if ((NULL != service) && 3770 if ((NULL != service) &&
3778 (GNUNET_SYSERR != 3771 (GNUNET_SYSERR !=
3779 (ret_s = 3772 (ret_s =
3780 get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens)))) 3773 get_server_addresses("transport-tcp", env->cfg, &addrs, &addrlens))))
3781 { 3774 {
3782 for (ret = ret_s - 1; ret >= 0; ret--) 3775 for (ret = ret_s - 1; ret >= 0; ret--)
3783 LOG (GNUNET_ERROR_TYPE_INFO, 3776 LOG(GNUNET_ERROR_TYPE_INFO,
3784 "Binding to address `%s'\n", 3777 "Binding to address `%s'\n",
3785 GNUNET_a2s (addrs[ret], addrlens[ret])); 3778 GNUNET_a2s(addrs[ret], addrlens[ret]));
3786 plugin->nat = GNUNET_NAT_register (env->cfg, 3779 plugin->nat = GNUNET_NAT_register(env->cfg,
3787 "transport-tcp", 3780 "transport-tcp",
3788 IPPROTO_TCP, 3781 IPPROTO_TCP,
3789 (unsigned int) ret_s, 3782 (unsigned int)ret_s,
3790 (const struct sockaddr **) addrs, 3783 (const struct sockaddr **)addrs,
3791 addrlens, 3784 addrlens,
3792 &tcp_nat_port_map_callback, 3785 &tcp_nat_port_map_callback,
3793 &try_connection_reversal, 3786 &try_connection_reversal,
3794 plugin); 3787 plugin);
3795 for (ret = ret_s - 1; ret >= 0; ret--) 3788 for (ret = ret_s - 1; ret >= 0; ret--)
3796 GNUNET_free (addrs[ret]); 3789 GNUNET_free(addrs[ret]);
3797 GNUNET_free_non_null (addrs); 3790 GNUNET_free_non_null(addrs);
3798 GNUNET_free_non_null (addrlens); 3791 GNUNET_free_non_null(addrlens);
3799 } 3792 }
3800 else 3793 else
3801 { 3794 {
3802 plugin->nat = GNUNET_NAT_register (plugin->env->cfg, 3795 plugin->nat = GNUNET_NAT_register(plugin->env->cfg,
3803 "transport-tcp", 3796 "transport-tcp",
3804 IPPROTO_TCP, 3797 IPPROTO_TCP,
3805 0, 3798 0,
3806 NULL, 3799 NULL,
3807 NULL, 3800 NULL,
3808 NULL, 3801 NULL,
3809 &try_connection_reversal, 3802 &try_connection_reversal,
3810 plugin); 3803 plugin);
3811 } 3804 }
3812 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3805 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3813 api->cls = plugin; 3806 api->cls = plugin;
3814 api->send = &tcp_plugin_send; 3807 api->send = &tcp_plugin_send;
3815 api->get_session = &tcp_plugin_get_session; 3808 api->get_session = &tcp_plugin_get_session;
@@ -3827,65 +3820,65 @@ libgnunet_plugin_transport_tcp_init (void *cls)
3827 api->setup_monitor = &tcp_plugin_setup_monitor; 3820 api->setup_monitor = &tcp_plugin_setup_monitor;
3828 plugin->service = service; 3821 plugin->service = service;
3829 if (NULL != service) 3822 if (NULL != service)
3830 { 3823 {
3831 plugin->server = LEGACY_SERVICE_get_server (service); 3824 plugin->server = LEGACY_SERVICE_get_server(service);
3832 } 3825 }
3833 else 3826 else
3834 {
3835 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg,
3836 "transport-tcp",
3837 "TIMEOUT",
3838 &idle_timeout))
3839 { 3827 {
3840 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 3828 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg,
3841 "transport-tcp", 3829 "transport-tcp",
3842 "TIMEOUT"); 3830 "TIMEOUT",
3843 goto die; 3831 &idle_timeout))
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);
3844 } 3843 }
3845 plugin->server = GNUNET_SERVER_create_with_sockets (NULL, 3844 plugin->handlers = GNUNET_malloc(sizeof(my_handlers));
3846 plugin, 3845 GNUNET_memcpy(plugin->handlers, my_handlers, sizeof(my_handlers));
3847 NULL,
3848 idle_timeout,
3849 GNUNET_YES);
3850 }
3851 plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
3852 GNUNET_memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
3853 for (i = 0; 3846 for (i = 0;
3854 i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler); 3847 i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);
3855 i++) 3848 i++)
3856 plugin->handlers[i].callback_cls = plugin; 3849 plugin->handlers[i].callback_cls = plugin;
3857 3850
3858 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); 3851 GNUNET_SERVER_add_handlers(plugin->server, plugin->handlers);
3859 GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin); 3852 GNUNET_SERVER_connect_notify(plugin->server, &connect_notify, plugin);
3860 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); 3853 GNUNET_SERVER_disconnect_notify(plugin->server, &disconnect_notify, plugin);
3861 plugin->nat_wait_conns = 3854 plugin->nat_wait_conns =
3862 GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); 3855 GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES);
3863 if (0 != bport) 3856 if (0 != bport)
3864 LOG (GNUNET_ERROR_TYPE_INFO, 3857 LOG(GNUNET_ERROR_TYPE_INFO,
3865 _ ("TCP transport listening on port %llu\n"), 3858 _("TCP transport listening on port %llu\n"),
3866 bport); 3859 bport);
3867 else 3860 else
3868 LOG (GNUNET_ERROR_TYPE_INFO, 3861 LOG(GNUNET_ERROR_TYPE_INFO,
3869 _ ("TCP transport not listening on any port (client only)\n")); 3862 _("TCP transport not listening on any port (client only)\n"));
3870 if ((aport != bport) && (0 != bport)) 3863 if ((aport != bport) && (0 != bport))
3871 LOG (GNUNET_ERROR_TYPE_INFO, 3864 LOG(GNUNET_ERROR_TYPE_INFO,
3872 _ ("TCP transport advertises itself as being on port %llu\n"), 3865 _("TCP transport advertises itself as being on port %llu\n"),
3873 aport); 3866 aport);
3874 /* Initially set connections to 0 */ 3867 /* Initially set connections to 0 */
3875 GNUNET_STATISTICS_set (plugin->env->stats, 3868 GNUNET_STATISTICS_set(plugin->env->stats,
3876 gettext_noop ("# TCP sessions active"), 3869 gettext_noop("# TCP sessions active"),
3877 0, 3870 0,
3878 GNUNET_NO); 3871 GNUNET_NO);
3879 return api; 3872 return api;
3880 3873
3881die: 3874die:
3882 if (NULL != plugin->nat) 3875 if (NULL != plugin->nat)
3883 GNUNET_NAT_unregister (plugin->nat); 3876 GNUNET_NAT_unregister(plugin->nat);
3884 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); 3877 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap);
3885 if (NULL != service) 3878 if (NULL != service)
3886 LEGACY_SERVICE_stop (service); 3879 LEGACY_SERVICE_stop(service);
3887 GNUNET_free (plugin); 3880 GNUNET_free(plugin);
3888 GNUNET_free_non_null (api); 3881 GNUNET_free_non_null(api);
3889 return NULL; 3882 return NULL;
3890} 3883}
3891 3884
@@ -3897,7 +3890,7 @@ die:
3897 * @return NULL 3890 * @return NULL
3898 */ 3891 */
3899void * 3892void *
3900libgnunet_plugin_transport_tcp_done (void *cls) 3893libgnunet_plugin_transport_tcp_done(void *cls)
3901{ 3894{
3902 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3895 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3903 struct Plugin *plugin = api->cls; 3896 struct Plugin *plugin = api->cls;
@@ -3906,52 +3899,52 @@ libgnunet_plugin_transport_tcp_done (void *cls)
3906 struct PrettyPrinterContext *next; 3899 struct PrettyPrinterContext *next;
3907 3900
3908 if (NULL == plugin) 3901 if (NULL == plugin)
3909 { 3902 {
3910 GNUNET_free (api); 3903 GNUNET_free(api);
3911 return NULL; 3904 return NULL;
3912 } 3905 }
3913 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); 3906 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n");
3914 3907
3915 /* Removing leftover sessions */ 3908 /* Removing leftover sessions */
3916 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, 3909 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap,
3917 &session_disconnect_it, 3910 &session_disconnect_it,
3918 plugin); 3911 plugin);
3919 /* Removing leftover NAT sessions */ 3912 /* Removing leftover NAT sessions */
3920 GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, 3913 GNUNET_CONTAINER_multipeermap_iterate(plugin->nat_wait_conns,
3921 &session_disconnect_it, 3914 &session_disconnect_it,
3922 plugin); 3915 plugin);
3923 3916
3924 for (cur = plugin->ppc_dll_head; NULL != cur; cur = next) 3917 for (cur = plugin->ppc_dll_head; NULL != cur; cur = next)
3925 { 3918 {
3926 next = cur->next; 3919 next = cur->next;
3927 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 3920 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head,
3928 plugin->ppc_dll_tail, 3921 plugin->ppc_dll_tail,
3929 cur); 3922 cur);
3930 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 3923 GNUNET_RESOLVER_request_cancel(cur->resolver_handle);
3931 cur->asc (cur->asc_cls, NULL, GNUNET_OK); 3924 cur->asc(cur->asc_cls, NULL, GNUNET_OK);
3932 GNUNET_free (cur); 3925 GNUNET_free(cur);
3933 } 3926 }
3934 3927
3935 if (NULL != plugin->service) 3928 if (NULL != plugin->service)
3936 LEGACY_SERVICE_stop (plugin->service); 3929 LEGACY_SERVICE_stop(plugin->service);
3937 else 3930 else
3938 GNUNET_SERVER_destroy (plugin->server); 3931 GNUNET_SERVER_destroy(plugin->server);
3939 GNUNET_free (plugin->handlers); 3932 GNUNET_free(plugin->handlers);
3940 if (NULL != plugin->nat) 3933 if (NULL != plugin->nat)
3941 GNUNET_NAT_unregister (plugin->nat); 3934 GNUNET_NAT_unregister(plugin->nat);
3942 while (NULL != (tcp_probe = plugin->probe_head)) 3935 while (NULL != (tcp_probe = plugin->probe_head))
3943 { 3936 {
3944 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, 3937 GNUNET_CONTAINER_DLL_remove(plugin->probe_head,
3945 plugin->probe_tail, 3938 plugin->probe_tail,
3946 tcp_probe); 3939 tcp_probe);
3947 GNUNET_CONNECTION_destroy (tcp_probe->sock); 3940 GNUNET_CONNECTION_destroy(tcp_probe->sock);
3948 GNUNET_free (tcp_probe); 3941 GNUNET_free(tcp_probe);
3949 } 3942 }
3950 GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); 3943 GNUNET_CONTAINER_multipeermap_destroy(plugin->nat_wait_conns);
3951 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); 3944 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap);
3952 GNUNET_break (0 == plugin->cur_connections); 3945 GNUNET_break(0 == plugin->cur_connections);
3953 GNUNET_free (plugin); 3946 GNUNET_free(plugin);
3954 GNUNET_free (api); 3947 GNUNET_free(api);
3955 return NULL; 3948 return NULL;
3956} 3949}
3957 3950
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index 8ec2c3992..7977590b0 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_template.c 22 * @file transport/plugin_transport_template.c
@@ -31,14 +31,14 @@
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(GNUNET_TIME_UNIT_HOURS, 6)
42 42
43#define PLUGIN_NAME "template" 43#define PLUGIN_NAME "template"
44 44
@@ -51,8 +51,7 @@ struct Plugin;
51/** 51/**
52 * Session handle for connections. 52 * Session handle for connections.
53 */ 53 */
54struct GNUNET_ATS_Session 54struct GNUNET_ATS_Session {
55{
56 /** 55 /**
57 * To whom are we talking to (set to our identity 56 * To whom are we talking to (set to our identity
58 * if we are still waiting for the welcome message) 57 * if we are still waiting for the welcome message)
@@ -102,13 +101,11 @@ struct GNUNET_ATS_Session
102 * to send to us. 101 * to send to us.
103 */ 102 */
104 uint32_t quota; 103 uint32_t quota;
105
106}; 104};
107 105
108GNUNET_NETWORK_STRUCT_BEGIN 106GNUNET_NETWORK_STRUCT_BEGIN
109 107
110struct TemplateAddress 108struct TemplateAddress {
111{
112 /** 109 /**
113 * Address options in NBO 110 * Address options in NBO
114 */ 111 */
@@ -122,8 +119,7 @@ GNUNET_NETWORK_STRUCT_END
122/** 119/**
123 * Encapsulation of all of the state of the plugin. 120 * Encapsulation of all of the state of the plugin.
124 */ 121 */
125struct Plugin 122struct Plugin {
126{
127 /** 123 /**
128 * Our environment. 124 * Our environment.
129 */ 125 */
@@ -147,7 +143,6 @@ struct Plugin
147 /** 143 /**
148 * Options in HBO to be used with addresses 144 * Options in HBO to be used with addresses
149 */ 145 */
150
151}; 146};
152 147
153 148
@@ -161,15 +156,15 @@ struct Plugin
161 * @param state new state of the session 156 * @param state new state of the session
162 */ 157 */
163static void 158static void
164notify_session_monitor (struct Plugin *plugin, 159notify_session_monitor(struct Plugin *plugin,
165 struct GNUNET_ATS_Session *session, 160 struct GNUNET_ATS_Session *session,
166 enum GNUNET_TRANSPORT_SessionState state) 161 enum GNUNET_TRANSPORT_SessionState state)
167{ 162{
168 struct GNUNET_TRANSPORT_SessionInfo info; 163 struct GNUNET_TRANSPORT_SessionInfo info;
169 164
170 if (NULL == plugin->sic) 165 if (NULL == plugin->sic)
171 return; 166 return;
172 memset (&info, 0, sizeof (info)); 167 memset(&info, 0, sizeof(info));
173 info.state = state; 168 info.state = state;
174 info.is_inbound = GNUNET_SYSERR; /* FIXME */ 169 info.is_inbound = GNUNET_SYSERR; /* FIXME */
175 // info.num_msg_pending = 170 // info.num_msg_pending =
@@ -177,9 +172,9 @@ notify_session_monitor (struct Plugin *plugin,
177 // info.receive_delay = 172 // info.receive_delay =
178 // info.session_timeout = session->timeout; 173 // info.session_timeout = session->timeout;
179 // info.address = session->address; 174 // info.address = session->address;
180 plugin->sic (plugin->sic_cls, 175 plugin->sic(plugin->sic_cls,
181 session, 176 session,
182 &info); 177 &info);
183} 178}
184#endif 179#endif
185 180
@@ -212,14 +207,14 @@ notify_session_monitor (struct Plugin *plugin,
212 * and does NOT mean that the message was not transmitted (DV) 207 * and does NOT mean that the message was not transmitted (DV)
213 */ 208 */
214static ssize_t 209static ssize_t
215template_plugin_send (void *cls, 210template_plugin_send(void *cls,
216 struct GNUNET_ATS_Session *session, 211 struct GNUNET_ATS_Session *session,
217 const char *msgbuf, 212 const char *msgbuf,
218 size_t msgbuf_size, 213 size_t msgbuf_size,
219 unsigned int priority, 214 unsigned int priority,
220 struct GNUNET_TIME_Relative to, 215 struct GNUNET_TIME_Relative to,
221 GNUNET_TRANSPORT_TransmitContinuation cont, 216 GNUNET_TRANSPORT_TransmitContinuation cont,
222 void *cont_cls) 217 void *cont_cls)
223{ 218{
224 /* struct Plugin *plugin = cls; */ 219 /* struct Plugin *plugin = cls; */
225 ssize_t bytes_sent = 0; 220 ssize_t bytes_sent = 0;
@@ -237,8 +232,8 @@ template_plugin_send (void *cls,
237 * @param target peer from which to disconnect 232 * @param target peer from which to disconnect
238 */ 233 */
239static void 234static void
240template_plugin_disconnect_peer (void *cls, 235template_plugin_disconnect_peer(void *cls,
241 const struct GNUNET_PeerIdentity *target) 236 const struct GNUNET_PeerIdentity *target)
242{ 237{
243 // struct Plugin *plugin = cls; 238 // struct Plugin *plugin = cls;
244 // FIXME 239 // FIXME
@@ -255,8 +250,8 @@ template_plugin_disconnect_peer (void *cls,
255 * @return #GNUNET_OK on success 250 * @return #GNUNET_OK on success
256 */ 251 */
257static int 252static int
258template_plugin_disconnect_session (void *cls, 253template_plugin_disconnect_session(void *cls,
259 struct GNUNET_ATS_Session *session) 254 struct GNUNET_ATS_Session *session)
260{ 255{
261 // struct Plugin *plugin = cls; 256 // struct Plugin *plugin = cls;
262 // FIXME 257 // FIXME
@@ -273,7 +268,7 @@ template_plugin_disconnect_session (void *cls,
273 * @return keepalive factor 268 * @return keepalive factor
274 */ 269 */
275static unsigned int 270static unsigned int
276template_plugin_query_keepalive_factor (void *cls) 271template_plugin_query_keepalive_factor(void *cls)
277{ 272{
278 return 3; 273 return 3;
279} 274}
@@ -287,10 +282,10 @@ template_plugin_query_keepalive_factor (void *cls)
287 * @return the network type in HBO or #GNUNET_SYSERR 282 * @return the network type in HBO or #GNUNET_SYSERR
288 */ 283 */
289static enum GNUNET_NetworkType 284static enum GNUNET_NetworkType
290template_plugin_get_network (void *cls, 285template_plugin_get_network(void *cls,
291 struct GNUNET_ATS_Session *session) 286 struct GNUNET_ATS_Session *session)
292{ 287{
293 GNUNET_assert (NULL != session); 288 GNUNET_assert(NULL != session);
294 return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */ 289 return GNUNET_NT_UNSPECIFIED; /* Change to correct network type */
295} 290}
296 291
@@ -303,8 +298,8 @@ template_plugin_get_network (void *cls,
303 * @return the network type 298 * @return the network type
304 */ 299 */
305static enum GNUNET_NetworkType 300static enum GNUNET_NetworkType
306template_plugin_get_network_for_address (void *cls, 301template_plugin_get_network_for_address(void *cls,
307 const struct GNUNET_HELLO_Address *address) 302 const struct GNUNET_HELLO_Address *address)
308{ 303{
309 return GNUNET_NT_WAN; /* FOR NOW */ 304 return GNUNET_NT_WAN; /* FOR NOW */
310} 305}
@@ -325,15 +320,15 @@ template_plugin_get_network_for_address (void *cls,
325 * @param asc_cls closure for @a asc 320 * @param asc_cls closure for @a asc
326 */ 321 */
327static void 322static void
328template_plugin_address_pretty_printer (void *cls, const char *type, 323template_plugin_address_pretty_printer(void *cls, const char *type,
329 const void *addr, size_t addrlen, 324 const void *addr, size_t addrlen,
330 int numeric, 325 int numeric,
331 struct GNUNET_TIME_Relative timeout, 326 struct GNUNET_TIME_Relative timeout,
332 GNUNET_TRANSPORT_AddressStringCallback 327 GNUNET_TRANSPORT_AddressStringCallback
333 asc, void *asc_cls) 328 asc, void *asc_cls)
334{ 329{
335 asc (asc_cls, "converted address", GNUNET_OK); /* return address */ 330 asc(asc_cls, "converted address", GNUNET_OK); /* return address */
336 asc (asc_cls, NULL, GNUNET_OK); /* done */ 331 asc(asc_cls, NULL, GNUNET_OK); /* done */
337} 332}
338 333
339 334
@@ -351,7 +346,7 @@ template_plugin_address_pretty_printer (void *cls, const char *type,
351 * and transport 346 * and transport
352 */ 347 */
353static int 348static int
354template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) 349template_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
355{ 350{
356 /* struct Plugin *plugin = cls; */ 351 /* struct Plugin *plugin = cls; */
357 352
@@ -372,18 +367,18 @@ template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
372 * @return string representing the same address 367 * @return string representing the same address
373 */ 368 */
374static const char * 369static const char *
375template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 370template_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
376{ 371{
377 /* 372 /*
378 * Print address in format template.options.address 373 * Print address in format template.options.address
379 */ 374 */
380 375
381 if (0 == addrlen) 376 if (0 == addrlen)
382 { 377 {
383 return TRANSPORT_SESSION_INBOUND_STRING; 378 return TRANSPORT_SESSION_INBOUND_STRING;
384 } 379 }
385 380
386 GNUNET_break (0); 381 GNUNET_break(0);
387 return NULL; 382 return NULL;
388} 383}
389 384
@@ -401,15 +396,15 @@ template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
401 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 396 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
402 */ 397 */
403static int 398static int
404template_plugin_string_to_address (void *cls, 399template_plugin_string_to_address(void *cls,
405 const char *addr, 400 const char *addr,
406 uint16_t addrlen, 401 uint16_t addrlen,
407 void **buf, size_t *added) 402 void **buf, size_t *added)
408{ 403{
409 /* 404 /*
410 * Parse string in format template.options.address 405 * Parse string in format template.options.address
411 */ 406 */
412 GNUNET_break (0); 407 GNUNET_break(0);
413 return GNUNET_SYSERR; 408 return GNUNET_SYSERR;
414} 409}
415 410
@@ -424,20 +419,19 @@ template_plugin_string_to_address (void *cls,
424 * @return the session if the address is valid, NULL otherwise 419 * @return the session if the address is valid, NULL otherwise
425 */ 420 */
426static struct GNUNET_ATS_Session * 421static struct GNUNET_ATS_Session *
427template_plugin_get_session (void *cls, 422template_plugin_get_session(void *cls,
428 const struct GNUNET_HELLO_Address *address) 423 const struct GNUNET_HELLO_Address *address)
429{ 424{
430 GNUNET_break (0); 425 GNUNET_break(0);
431 return NULL; 426 return NULL;
432} 427}
433 428
434 429
435static void 430static void
436template_plugin_update_session_timeout (void *cls, 431template_plugin_update_session_timeout(void *cls,
437 const struct GNUNET_PeerIdentity *peer, 432 const struct GNUNET_PeerIdentity *peer,
438 struct GNUNET_ATS_Session *session) 433 struct GNUNET_ATS_Session *session)
439{ 434{
440
441} 435}
442 436
443 437
@@ -452,16 +446,16 @@ template_plugin_update_session_timeout (void *cls,
452 * @return #GNUNET_OK (continue to iterate) 446 * @return #GNUNET_OK (continue to iterate)
453 */ 447 */
454static int 448static int
455send_session_info_iter (void *cls, 449send_session_info_iter(void *cls,
456 const struct GNUNET_PeerIdentity *peer, 450 const struct GNUNET_PeerIdentity *peer,
457 void *value) 451 void *value)
458{ 452{
459 struct Plugin *plugin = cls; 453 struct Plugin *plugin = cls;
460 struct GNUNET_ATS_Session *session = value; 454 struct GNUNET_ATS_Session *session = value;
461 455
462 notify_session_monitor (plugin, 456 notify_session_monitor(plugin,
463 session, 457 session,
464 GNUNET_TRANSPORT_SS_UP); 458 GNUNET_TRANSPORT_SS_UP);
465 return GNUNET_OK; 459 return GNUNET_OK;
466} 460}
467#endif 461#endif
@@ -480,24 +474,24 @@ send_session_info_iter (void *cls,
480 * @param sic_cls closure for @a sic 474 * @param sic_cls closure for @a sic
481 */ 475 */
482static void 476static void
483template_plugin_setup_monitor (void *cls, 477template_plugin_setup_monitor(void *cls,
484 GNUNET_TRANSPORT_SessionInfoCallback sic, 478 GNUNET_TRANSPORT_SessionInfoCallback sic,
485 void *sic_cls) 479 void *sic_cls)
486{ 480{
487 struct Plugin *plugin = cls; 481 struct Plugin *plugin = cls;
488 482
489 plugin->sic = sic; 483 plugin->sic = sic;
490 plugin->sic_cls = sic_cls; 484 plugin->sic_cls = sic_cls;
491 if (NULL != sic) 485 if (NULL != sic)
492 { 486 {
493#if 0 487#if 0
494 GNUNET_CONTAINER_multipeermap_iterate (NULL /* FIXME */, 488 GNUNET_CONTAINER_multipeermap_iterate(NULL /* FIXME */,
495 &send_session_info_iter, 489 &send_session_info_iter,
496 plugin); 490 plugin);
497#endif 491#endif
498 /* signal end of first iteration */ 492 /* signal end of first iteration */
499 sic (sic_cls, NULL, NULL); 493 sic(sic_cls, NULL, NULL);
500 } 494 }
501} 495}
502 496
503 497
@@ -505,27 +499,27 @@ template_plugin_setup_monitor (void *cls,
505 * Entry point for the plugin. 499 * Entry point for the plugin.
506 */ 500 */
507void * 501void *
508libgnunet_plugin_transport_template_init (void *cls) 502libgnunet_plugin_transport_template_init(void *cls)
509{ 503{
510 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 504 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
511 struct GNUNET_TRANSPORT_PluginFunctions *api; 505 struct GNUNET_TRANSPORT_PluginFunctions *api;
512 struct Plugin *plugin; 506 struct Plugin *plugin;
513 507
514 if (NULL == env->receive) 508 if (NULL == env->receive)
515 { 509 {
516 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 510 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
517 initialze the plugin or the API */ 511 initialze the plugin or the API */
518 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 512 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
519 api->cls = NULL; 513 api->cls = NULL;
520 api->address_to_string = &template_plugin_address_to_string; 514 api->address_to_string = &template_plugin_address_to_string;
521 api->string_to_address = &template_plugin_string_to_address; 515 api->string_to_address = &template_plugin_string_to_address;
522 api->address_pretty_printer = &template_plugin_address_pretty_printer; 516 api->address_pretty_printer = &template_plugin_address_pretty_printer;
523 return api; 517 return api;
524 } 518 }
525 519
526 plugin = GNUNET_new (struct Plugin); 520 plugin = GNUNET_new(struct Plugin);
527 plugin->env = env; 521 plugin->env = env;
528 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 522 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
529 api->cls = plugin; 523 api->cls = plugin;
530 api->send = &template_plugin_send; 524 api->send = &template_plugin_send;
531 api->disconnect_peer = &template_plugin_disconnect_peer; 525 api->disconnect_peer = &template_plugin_disconnect_peer;
@@ -540,7 +534,7 @@ libgnunet_plugin_transport_template_init (void *cls)
540 api->get_network_for_address = &template_plugin_get_network_for_address; 534 api->get_network_for_address = &template_plugin_get_network_for_address;
541 api->update_session_timeout = &template_plugin_update_session_timeout; 535 api->update_session_timeout = &template_plugin_update_session_timeout;
542 api->setup_monitor = &template_plugin_setup_monitor; 536 api->setup_monitor = &template_plugin_setup_monitor;
543 LOG (GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n"); 537 LOG(GNUNET_ERROR_TYPE_INFO, "Template plugin successfully loaded\n");
544 return api; 538 return api;
545} 539}
546 540
@@ -549,13 +543,13 @@ libgnunet_plugin_transport_template_init (void *cls)
549 * Exit point from the plugin. 543 * Exit point from the plugin.
550 */ 544 */
551void * 545void *
552libgnunet_plugin_transport_template_done (void *cls) 546libgnunet_plugin_transport_template_done(void *cls)
553{ 547{
554 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 548 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
555 struct Plugin *plugin = api->cls; 549 struct Plugin *plugin = api->cls;
556 550
557 GNUNET_free (plugin); 551 GNUNET_free(plugin);
558 GNUNET_free (api); 552 GNUNET_free(api);
559 return NULL; 553 return NULL;
560} 554}
561 555
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 1d34cdd1a..755809194 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010-2017 GNUnet e.V. 3 Copyright (C) 2010-2017 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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,8 +71,7 @@
71/** 71/**
72 * UDP Message-Packet header (after defragmentation). 72 * UDP Message-Packet header (after defragmentation).
73 */ 73 */
74struct UDPMessage 74struct UDPMessage {
75{
76 /** 75 /**
77 * Message header. 76 * Message header.
78 */ 77 */
@@ -93,8 +92,7 @@ struct UDPMessage
93/** 92/**
94 * Closure for #append_port(). 93 * Closure for #append_port().
95 */ 94 */
96struct PrettyPrinterContext 95struct PrettyPrinterContext {
97{
98 /** 96 /**
99 * DLL 97 * DLL
100 */ 98 */
@@ -150,8 +148,7 @@ struct PrettyPrinterContext
150/** 148/**
151 * Session with another peer. 149 * Session with another peer.
152 */ 150 */
153struct GNUNET_ATS_Session 151struct GNUNET_ATS_Session {
154{
155 /** 152 /**
156 * Which peer is this session for? 153 * Which peer is this session for?
157 */ 154 */
@@ -251,9 +248,7 @@ struct GNUNET_ATS_Session
251 * Data structure to track defragmentation contexts based 248 * Data structure to track defragmentation contexts based
252 * on the source of the UDP traffic. 249 * on the source of the UDP traffic.
253 */ 250 */
254struct DefragContext 251struct DefragContext {
255{
256
257 /** 252 /**
258 * Defragmentation context. 253 * Defragmentation context.
259 */ 254 */
@@ -302,8 +297,7 @@ struct DefragContext
302/** 297/**
303 * Context to send fragmented messages 298 * Context to send fragmented messages
304 */ 299 */
305struct UDP_FragmentationContext 300struct UDP_FragmentationContext {
306{
307 /** 301 /**
308 * Next in linked list 302 * Next in linked list
309 */ 303 */
@@ -393,8 +387,7 @@ typedef void (*QueueContinuation) (void *cls,
393/** 387/**
394 * Information we track for each message in the queue. 388 * Information we track for each message in the queue.
395 */ 389 */
396struct UDP_MessageWrapper 390struct UDP_MessageWrapper {
397{
398 /** 391 /**
399 * Session this message belongs to 392 * Session this message belongs to
400 */ 393 */
@@ -478,8 +471,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
478/** 471/**
479 * UDP ACK Message-Packet header. 472 * UDP ACK Message-Packet header.
480 */ 473 */
481struct UDP_ACK_Message 474struct UDP_ACK_Message {
482{
483 /** 475 /**
484 * Message header. 476 * Message header.
485 */ 477 */
@@ -513,9 +505,9 @@ GNUNET_NETWORK_STRUCT_END
513 * @param state new state of the session 505 * @param state new state of the session
514 */ 506 */
515static void 507static void
516notify_session_monitor (struct Plugin *plugin, 508notify_session_monitor(struct Plugin *plugin,
517 struct GNUNET_ATS_Session *session, 509 struct GNUNET_ATS_Session *session,
518 enum GNUNET_TRANSPORT_SessionState state) 510 enum GNUNET_TRANSPORT_SessionState state)
519{ 511{
520 struct GNUNET_TRANSPORT_SessionInfo info; 512 struct GNUNET_TRANSPORT_SessionInfo info;
521 513
@@ -523,7 +515,7 @@ notify_session_monitor (struct Plugin *plugin,
523 return; 515 return;
524 if (GNUNET_YES == session->in_destroy) 516 if (GNUNET_YES == session->in_destroy)
525 return; /* already destroyed, just RC>0 left-over actions */ 517 return; /* already destroyed, just RC>0 left-over actions */
526 memset (&info, 0, sizeof (info)); 518 memset(&info, 0, sizeof(info));
527 info.state = state; 519 info.state = state;
528 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 520 info.is_inbound = GNUNET_SYSERR; /* hard to say */
529 info.num_msg_pending = session->msgs_in_queue; 521 info.num_msg_pending = session->msgs_in_queue;
@@ -533,7 +525,7 @@ notify_session_monitor (struct Plugin *plugin,
533 to receive from others) */ 525 to receive from others) */
534 info.session_timeout = session->timeout; 526 info.session_timeout = session->timeout;
535 info.address = session->address; 527 info.address = session->address;
536 plugin->sic (plugin->sic_cls, session, &info); 528 plugin->sic(plugin->sic_cls, session, &info);
537} 529}
538 530
539 531
@@ -546,15 +538,15 @@ notify_session_monitor (struct Plugin *plugin,
546 * @return #GNUNET_OK (continue to iterate) 538 * @return #GNUNET_OK (continue to iterate)
547 */ 539 */
548static int 540static int
549send_session_info_iter (void *cls, 541send_session_info_iter(void *cls,
550 const struct GNUNET_PeerIdentity *peer, 542 const struct GNUNET_PeerIdentity *peer,
551 void *value) 543 void *value)
552{ 544{
553 struct Plugin *plugin = cls; 545 struct Plugin *plugin = cls;
554 struct GNUNET_ATS_Session *session = value; 546 struct GNUNET_ATS_Session *session = value;
555 547
556 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); 548 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT);
557 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); 549 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP);
558 return GNUNET_OK; 550 return GNUNET_OK;
559} 551}
560 552
@@ -572,22 +564,22 @@ send_session_info_iter (void *cls,
572 * @param sic_cls closure for @a sic 564 * @param sic_cls closure for @a sic
573 */ 565 */
574static void 566static void
575udp_plugin_setup_monitor (void *cls, 567udp_plugin_setup_monitor(void *cls,
576 GNUNET_TRANSPORT_SessionInfoCallback sic, 568 GNUNET_TRANSPORT_SessionInfoCallback sic,
577 void *sic_cls) 569 void *sic_cls)
578{ 570{
579 struct Plugin *plugin = cls; 571 struct Plugin *plugin = cls;
580 572
581 plugin->sic = sic; 573 plugin->sic = sic;
582 plugin->sic_cls = sic_cls; 574 plugin->sic_cls = sic_cls;
583 if (NULL != sic) 575 if (NULL != sic)
584 { 576 {
585 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 577 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
586 &send_session_info_iter, 578 &send_session_info_iter,
587 plugin); 579 plugin);
588 /* signal end of first iteration */ 580 /* signal end of first iteration */
589 sic (sic_cls, NULL, NULL); 581 sic(sic_cls, NULL, NULL);
590 } 582 }
591} 583}
592 584
593 585
@@ -600,25 +592,25 @@ udp_plugin_setup_monitor (void *cls,
600 * @param s session to free 592 * @param s session to free
601 */ 593 */
602static void 594static void
603free_session (struct GNUNET_ATS_Session *s) 595free_session(struct GNUNET_ATS_Session *s)
604{ 596{
605 if (NULL != s->address) 597 if (NULL != s->address)
606 { 598 {
607 GNUNET_HELLO_address_free (s->address); 599 GNUNET_HELLO_address_free(s->address);
608 s->address = NULL; 600 s->address = NULL;
609 } 601 }
610 if (NULL != s->frag_ctx) 602 if (NULL != s->frag_ctx)
611 { 603 {
612 GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); 604 GNUNET_FRAGMENT_context_destroy(s->frag_ctx->frag, NULL, NULL);
613 GNUNET_free (s->frag_ctx); 605 GNUNET_free(s->frag_ctx);
614 s->frag_ctx = NULL; 606 s->frag_ctx = NULL;
615 } 607 }
616 if (NULL != s->mst) 608 if (NULL != s->mst)
617 { 609 {
618 GNUNET_MST_destroy (s->mst); 610 GNUNET_MST_destroy(s->mst);
619 s->mst = NULL; 611 s->mst = NULL;
620 } 612 }
621 GNUNET_free (s); 613 GNUNET_free(s);
622} 614}
623 615
624 616
@@ -631,7 +623,7 @@ free_session (struct GNUNET_ATS_Session *s)
631 * @return keepalive factor 623 * @return keepalive factor
632 */ 624 */
633static unsigned int 625static unsigned int
634udp_query_keepalive_factor (void *cls) 626udp_query_keepalive_factor(void *cls)
635{ 627{
636 return 15; 628 return 15;
637} 629}
@@ -645,7 +637,7 @@ udp_query_keepalive_factor (void *cls)
645 * @return the network type 637 * @return the network type
646 */ 638 */
647static enum GNUNET_NetworkType 639static enum GNUNET_NetworkType
648udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) 640udp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
649{ 641{
650 return session->scope; 642 return session->scope;
651} 643}
@@ -659,8 +651,8 @@ udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
659 * @return the network type 651 * @return the network type
660 */ 652 */
661static enum GNUNET_NetworkType 653static enum GNUNET_NetworkType
662udp_plugin_get_network_for_address (void *cls, 654udp_plugin_get_network_for_address(void *cls,
663 const struct GNUNET_HELLO_Address *address) 655 const struct GNUNET_HELLO_Address *address)
664{ 656{
665 struct Plugin *plugin = cls; 657 struct Plugin *plugin = cls;
666 size_t addrlen; 658 size_t addrlen;
@@ -672,40 +664,40 @@ udp_plugin_get_network_for_address (void *cls,
672 size_t sbs; 664 size_t sbs;
673 665
674 addrlen = address->address_length; 666 addrlen = address->address_length;
675 if (addrlen == sizeof (struct IPv6UdpAddress)) 667 if (addrlen == sizeof(struct IPv6UdpAddress))
676 { 668 {
677 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 669 GNUNET_assert(NULL != address->address); /* make static analysis happy */
678 u6 = address->address; 670 u6 = address->address;
679 memset (&a6, 0, sizeof (a6)); 671 memset(&a6, 0, sizeof(a6));
680#if HAVE_SOCKADDR_IN_SIN_LEN 672#if HAVE_SOCKADDR_IN_SIN_LEN
681 a6.sin6_len = sizeof (a6); 673 a6.sin6_len = sizeof(a6);
682#endif 674#endif
683 a6.sin6_family = AF_INET6; 675 a6.sin6_family = AF_INET6;
684 a6.sin6_port = u6->u6_port; 676 a6.sin6_port = u6->u6_port;
685 GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); 677 GNUNET_memcpy(&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
686 sb = &a6; 678 sb = &a6;
687 sbs = sizeof (a6); 679 sbs = sizeof(a6);
688 } 680 }
689 else if (addrlen == sizeof (struct IPv4UdpAddress)) 681 else if (addrlen == sizeof(struct IPv4UdpAddress))
690 { 682 {
691 GNUNET_assert (NULL != address->address); /* make static analysis happy */ 683 GNUNET_assert(NULL != address->address); /* make static analysis happy */
692 u4 = address->address; 684 u4 = address->address;
693 memset (&a4, 0, sizeof (a4)); 685 memset(&a4, 0, sizeof(a4));
694#if HAVE_SOCKADDR_IN_SIN_LEN 686#if HAVE_SOCKADDR_IN_SIN_LEN
695 a4.sin_len = sizeof (a4); 687 a4.sin_len = sizeof(a4);
696#endif 688#endif
697 a4.sin_family = AF_INET; 689 a4.sin_family = AF_INET;
698 a4.sin_port = u4->u4_port; 690 a4.sin_port = u4->u4_port;
699 a4.sin_addr.s_addr = u4->ipv4_addr; 691 a4.sin_addr.s_addr = u4->ipv4_addr;
700 sb = &a4; 692 sb = &a4;
701 sbs = sizeof (a4); 693 sbs = sizeof(a4);
702 } 694 }
703 else 695 else
704 { 696 {
705 GNUNET_break (0); 697 GNUNET_break(0);
706 return GNUNET_NT_UNSPECIFIED; 698 return GNUNET_NT_UNSPECIFIED;
707 } 699 }
708 return plugin->env->get_address_type (plugin->env->cls, sb, sbs); 700 return plugin->env->get_address_type(plugin->env->cls, sb, sbs);
709} 701}
710 702
711 703
@@ -719,7 +711,7 @@ udp_plugin_get_network_for_address (void *cls,
719 * @param cls the plugin handle 711 * @param cls the plugin handle
720 */ 712 */
721static void 713static void
722udp_plugin_select_v4 (void *cls); 714udp_plugin_select_v4(void *cls);
723 715
724 716
725/** 717/**
@@ -730,7 +722,7 @@ udp_plugin_select_v4 (void *cls);
730 * @param cls the plugin handle 722 * @param cls the plugin handle
731 */ 723 */
732static void 724static void
733udp_plugin_select_v6 (void *cls); 725udp_plugin_select_v6(void *cls);
734 726
735 727
736/** 728/**
@@ -739,7 +731,7 @@ udp_plugin_select_v6 (void *cls);
739 * @param plugin plugin to reschedule 731 * @param plugin plugin to reschedule
740 */ 732 */
741static void 733static void
742schedule_select_v4 (struct Plugin *plugin) 734schedule_select_v4(struct Plugin *plugin)
743{ 735{
744 struct GNUNET_TIME_Relative min_delay; 736 struct GNUNET_TIME_Relative min_delay;
745 struct GNUNET_TIME_Relative delay; 737 struct GNUNET_TIME_Relative delay;
@@ -747,47 +739,47 @@ schedule_select_v4 (struct Plugin *plugin)
747 struct UDP_MessageWrapper *min_udpw; 739 struct UDP_MessageWrapper *min_udpw;
748 740
749 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) 741 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
750 { 742 {
751 /* Find a message ready to send: 743 /* Find a message ready to send:
752 * Flow delay from other peer is expired or not set (0) */ 744 * Flow delay from other peer is expired or not set (0) */
753 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 745 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
754 min_udpw = NULL; 746 min_udpw = NULL;
755 for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next) 747 for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next)
756 { 748 {
757 delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); 749 delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time);
758 if (delay.rel_value_us < min_delay.rel_value_us) 750 if (delay.rel_value_us < min_delay.rel_value_us)
759 { 751 {
760 min_delay = delay; 752 min_delay = delay;
761 min_udpw = udpw; 753 min_udpw = udpw;
762 } 754 }
763 } 755 }
764 if (NULL != plugin->select_task_v4) 756 if (NULL != plugin->select_task_v4)
765 GNUNET_SCHEDULER_cancel (plugin->select_task_v4); 757 GNUNET_SCHEDULER_cancel(plugin->select_task_v4);
766 if (NULL != min_udpw) 758 if (NULL != min_udpw)
767 { 759 {
768 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 760 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
769 { 761 {
770 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 762 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
771 "Calculated flow delay for UDPv4 at %s for %s\n", 763 "Calculated flow delay for UDPv4 at %s for %s\n",
772 GNUNET_STRINGS_relative_time_to_string (min_delay, 764 GNUNET_STRINGS_relative_time_to_string(min_delay,
773 GNUNET_YES), 765 GNUNET_YES),
774 GNUNET_i2s (&min_udpw->session->target)); 766 GNUNET_i2s(&min_udpw->session->target));
775 } 767 }
776 else 768 else
777 { 769 {
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
779 "Calculated flow delay for UDPv4 at %s for %s\n", 771 "Calculated flow delay for UDPv4 at %s for %s\n",
780 GNUNET_STRINGS_relative_time_to_string (min_delay, 772 GNUNET_STRINGS_relative_time_to_string(min_delay,
781 GNUNET_YES), 773 GNUNET_YES),
782 GNUNET_i2s (&min_udpw->session->target)); 774 GNUNET_i2s(&min_udpw->session->target));
783 } 775 }
784 } 776 }
785 plugin->select_task_v4 = 777 plugin->select_task_v4 =
786 GNUNET_SCHEDULER_add_read_net (min_delay, 778 GNUNET_SCHEDULER_add_read_net(min_delay,
787 plugin->sockv4, 779 plugin->sockv4,
788 &udp_plugin_select_v4, 780 &udp_plugin_select_v4,
789 plugin); 781 plugin);
790 } 782 }
791} 783}
792 784
793 785
@@ -797,7 +789,7 @@ schedule_select_v4 (struct Plugin *plugin)
797 * @param plugin plugin to reschedule 789 * @param plugin plugin to reschedule
798 */ 790 */
799static void 791static void
800schedule_select_v6 (struct Plugin *plugin) 792schedule_select_v6(struct Plugin *plugin)
801{ 793{
802 struct GNUNET_TIME_Relative min_delay; 794 struct GNUNET_TIME_Relative min_delay;
803 struct GNUNET_TIME_Relative delay; 795 struct GNUNET_TIME_Relative delay;
@@ -805,45 +797,45 @@ schedule_select_v6 (struct Plugin *plugin)
805 struct UDP_MessageWrapper *min_udpw; 797 struct UDP_MessageWrapper *min_udpw;
806 798
807 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) 799 if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6))
808 { 800 {
809 min_delay = GNUNET_TIME_UNIT_FOREVER_REL; 801 min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
810 min_udpw = NULL; 802 min_udpw = NULL;
811 for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next) 803 for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next)
812 { 804 {
813 delay = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time); 805 delay = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time);
814 if (delay.rel_value_us < min_delay.rel_value_us) 806 if (delay.rel_value_us < min_delay.rel_value_us)
815 { 807 {
816 min_delay = delay; 808 min_delay = delay;
817 min_udpw = udpw; 809 min_udpw = udpw;
818 } 810 }
819 } 811 }
820 if (NULL != plugin->select_task_v6) 812 if (NULL != plugin->select_task_v6)
821 GNUNET_SCHEDULER_cancel (plugin->select_task_v6); 813 GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
822 if (NULL != min_udpw) 814 if (NULL != min_udpw)
823 { 815 {
824 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 816 if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
825 { 817 {
826 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 818 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
827 "Calculated flow delay for UDPv6 at %s for %s\n", 819 "Calculated flow delay for UDPv6 at %s for %s\n",
828 GNUNET_STRINGS_relative_time_to_string (min_delay, 820 GNUNET_STRINGS_relative_time_to_string(min_delay,
829 GNUNET_YES), 821 GNUNET_YES),
830 GNUNET_i2s (&min_udpw->session->target)); 822 GNUNET_i2s(&min_udpw->session->target));
831 } 823 }
832 else 824 else
833 { 825 {
834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 826 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
835 "Calculated flow delay for UDPv6 at %s for %s\n", 827 "Calculated flow delay for UDPv6 at %s for %s\n",
836 GNUNET_STRINGS_relative_time_to_string (min_delay, 828 GNUNET_STRINGS_relative_time_to_string(min_delay,
837 GNUNET_YES), 829 GNUNET_YES),
838 GNUNET_i2s (&min_udpw->session->target)); 830 GNUNET_i2s(&min_udpw->session->target));
839 } 831 }
840 } 832 }
841 plugin->select_task_v6 = 833 plugin->select_task_v6 =
842 GNUNET_SCHEDULER_add_read_net (min_delay, 834 GNUNET_SCHEDULER_add_read_net(min_delay,
843 plugin->sockv6, 835 plugin->sockv6,
844 &udp_plugin_select_v6, 836 &udp_plugin_select_v6,
845 plugin); 837 plugin);
846 } 838 }
847} 839}
848 840
849 841
@@ -862,7 +854,7 @@ schedule_select_v6 (struct Plugin *plugin)
862 * @return string representing the same address 854 * @return string representing the same address
863 */ 855 */
864const char * 856const char *
865udp_address_to_string (void *cls, const void *addr, size_t addrlen) 857udp_address_to_string(void *cls, const void *addr, size_t addrlen)
866{ 858{
867 static char rbuf[INET6_ADDRSTRLEN + 10]; 859 static char rbuf[INET6_ADDRSTRLEN + 10];
868 char buf[INET6_ADDRSTRLEN]; 860 char buf[INET6_ADDRSTRLEN];
@@ -876,42 +868,42 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
876 uint32_t options; 868 uint32_t options;
877 869
878 if (NULL == addr) 870 if (NULL == addr)
879 { 871 {
880 GNUNET_break_op (0); 872 GNUNET_break_op(0);
881 return NULL; 873 return NULL;
882 } 874 }
883 875
884 if (addrlen == sizeof (struct IPv6UdpAddress)) 876 if (addrlen == sizeof(struct IPv6UdpAddress))
885 { 877 {
886 t6 = addr; 878 t6 = addr;
887 af = AF_INET6; 879 af = AF_INET6;
888 options = ntohl (t6->options); 880 options = ntohl(t6->options);
889 port = ntohs (t6->u6_port); 881 port = ntohs(t6->u6_port);
890 a6 = t6->ipv6_addr; 882 a6 = t6->ipv6_addr;
891 sb = &a6; 883 sb = &a6;
892 } 884 }
893 else if (addrlen == sizeof (struct IPv4UdpAddress)) 885 else if (addrlen == sizeof(struct IPv4UdpAddress))
894 { 886 {
895 t4 = addr; 887 t4 = addr;
896 af = AF_INET; 888 af = AF_INET;
897 options = ntohl (t4->options); 889 options = ntohl(t4->options);
898 port = ntohs (t4->u4_port); 890 port = ntohs(t4->u4_port);
899 a4.s_addr = t4->ipv4_addr; 891 a4.s_addr = t4->ipv4_addr;
900 sb = &a4; 892 sb = &a4;
901 } 893 }
902 else 894 else
903 { 895 {
904 GNUNET_break_op (0); 896 GNUNET_break_op(0);
905 return NULL; 897 return NULL;
906 } 898 }
907 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 899 inet_ntop(af, sb, buf, INET6_ADDRSTRLEN);
908 GNUNET_snprintf (rbuf, 900 GNUNET_snprintf(rbuf,
909 sizeof (rbuf), 901 sizeof(rbuf),
910 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", 902 (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
911 PLUGIN_NAME, 903 PLUGIN_NAME,
912 options, 904 options,
913 buf, 905 buf,
914 port); 906 port);
915 return rbuf; 907 return rbuf;
916} 908}
917 909
@@ -928,11 +920,11 @@ udp_address_to_string (void *cls, const void *addr, size_t addrlen)
928 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 920 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
929 */ 921 */
930static int 922static int
931udp_string_to_address (void *cls, 923udp_string_to_address(void *cls,
932 const char *addr, 924 const char *addr,
933 uint16_t addrlen, 925 uint16_t addrlen,
934 void **buf, 926 void **buf,
935 size_t *added) 927 size_t *added)
936{ 928{
937 struct sockaddr_storage socket_address; 929 struct sockaddr_storage socket_address;
938 char *address; 930 char *address;
@@ -946,82 +938,84 @@ udp_string_to_address (void *cls,
946 optionstr = NULL; 938 optionstr = NULL;
947 939
948 if ((NULL == addr) || (0 == addrlen)) 940 if ((NULL == addr) || (0 == addrlen))
949 { 941 {
950 GNUNET_break (0); 942 GNUNET_break(0);
951 return GNUNET_SYSERR; 943 return GNUNET_SYSERR;
952 } 944 }
953 if ('\0' != addr[addrlen - 1]) 945 if ('\0' != addr[addrlen - 1])
954 { 946 {
955 GNUNET_break (0); 947 GNUNET_break(0);
956 return GNUNET_SYSERR; 948 return GNUNET_SYSERR;
957 } 949 }
958 if (strlen (addr) != addrlen - 1) 950 if (strlen(addr) != addrlen - 1)
959 { 951 {
960 GNUNET_break (0); 952 GNUNET_break(0);
961 return GNUNET_SYSERR; 953 return GNUNET_SYSERR;
962 } 954 }
963 plugin = GNUNET_strdup (addr); 955 plugin = GNUNET_strdup(addr);
964 optionstr = strchr (plugin, '.'); 956 optionstr = strchr(plugin, '.');
965 if (NULL == optionstr) 957 if (NULL == optionstr)
966 { 958 {
967 GNUNET_break (0); 959 GNUNET_break(0);
968 GNUNET_free (plugin); 960 GNUNET_free(plugin);
969 return GNUNET_SYSERR; 961 return GNUNET_SYSERR;
970 } 962 }
971 optionstr[0] = '\0'; 963 optionstr[0] = '\0';
972 optionstr++; 964 optionstr++;
973 options = atol (optionstr); 965 options = atol(optionstr);
974 address = strchr (optionstr, '.'); 966 address = strchr(optionstr, '.');
975 if (NULL == address) 967 if (NULL == address)
976 { 968 {
977 GNUNET_break (0); 969 GNUNET_break(0);
978 GNUNET_free (plugin); 970 GNUNET_free(plugin);
979 return GNUNET_SYSERR; 971 return GNUNET_SYSERR;
980 } 972 }
981 address[0] = '\0'; 973 address[0] = '\0';
982 address++; 974 address++;
983 975
984 if (GNUNET_OK != 976 if (GNUNET_OK !=
985 GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) 977 GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address))
986 { 978 {
987 GNUNET_break (0); 979 GNUNET_break(0);
988 GNUNET_free (plugin); 980 GNUNET_free(plugin);
989 return GNUNET_SYSERR; 981 return GNUNET_SYSERR;
990 } 982 }
991 GNUNET_free (plugin); 983 GNUNET_free(plugin);
992 984
993 switch (socket_address.ss_family) 985 switch (socket_address.ss_family)
994 { 986 {
995 case AF_INET: { 987 case AF_INET: {
996 struct IPv4UdpAddress *u4; 988 struct IPv4UdpAddress *u4;
997 const struct sockaddr_in *in4 = 989 const struct sockaddr_in *in4 =
998 (const struct sockaddr_in *) &socket_address; 990 (const struct sockaddr_in *)&socket_address;
999 991
1000 u4 = GNUNET_new (struct IPv4UdpAddress); 992 u4 = GNUNET_new(struct IPv4UdpAddress);
1001 u4->options = htonl (options); 993 u4->options = htonl(options);
1002 u4->ipv4_addr = in4->sin_addr.s_addr; 994 u4->ipv4_addr = in4->sin_addr.s_addr;
1003 u4->u4_port = in4->sin_port; 995 u4->u4_port = in4->sin_port;
1004 *buf = u4; 996 *buf = u4;
1005 *added = sizeof (struct IPv4UdpAddress); 997 *added = sizeof(struct IPv4UdpAddress);
1006 return GNUNET_OK; 998 return GNUNET_OK;
1007 } 999 }
1008 case AF_INET6: { 1000
1009 struct IPv6UdpAddress *u6; 1001 case AF_INET6: {
1010 const struct sockaddr_in6 *in6 = 1002 struct IPv6UdpAddress *u6;
1011 (const struct sockaddr_in6 *) &socket_address; 1003 const struct sockaddr_in6 *in6 =
1012 1004 (const struct sockaddr_in6 *)&socket_address;
1013 u6 = GNUNET_new (struct IPv6UdpAddress); 1005
1014 u6->options = htonl (options); 1006 u6 = GNUNET_new(struct IPv6UdpAddress);
1015 u6->ipv6_addr = in6->sin6_addr; 1007 u6->options = htonl(options);
1016 u6->u6_port = in6->sin6_port; 1008 u6->ipv6_addr = in6->sin6_addr;
1017 *buf = u6; 1009 u6->u6_port = in6->sin6_port;
1018 *added = sizeof (struct IPv6UdpAddress); 1010 *buf = u6;
1019 return GNUNET_OK; 1011 *added = sizeof(struct IPv6UdpAddress);
1020 } 1012 return GNUNET_OK;
1021 default: 1013 }
1022 GNUNET_break (0); 1014
1023 return GNUNET_SYSERR; 1015 default:
1024 } 1016 GNUNET_break(0);
1017 return GNUNET_SYSERR;
1018 }
1025} 1019}
1026 1020
1027 1021
@@ -1032,39 +1026,39 @@ udp_string_to_address (void *cls,
1032 * @param hostname result from DNS resolver 1026 * @param hostname result from DNS resolver
1033 */ 1027 */
1034static void 1028static void
1035append_port (void *cls, const char *hostname) 1029append_port(void *cls, const char *hostname)
1036{ 1030{
1037 struct PrettyPrinterContext *ppc = cls; 1031 struct PrettyPrinterContext *ppc = cls;
1038 struct Plugin *plugin = ppc->plugin; 1032 struct Plugin *plugin = ppc->plugin;
1039 char *ret; 1033 char *ret;
1040 1034
1041 if (NULL == hostname) 1035 if (NULL == hostname)
1042 { 1036 {
1043 /* Final call, done */ 1037 /* Final call, done */
1044 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 1038 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head,
1045 plugin->ppc_dll_tail, 1039 plugin->ppc_dll_tail,
1046 ppc); 1040 ppc);
1047 ppc->resolver_handle = NULL; 1041 ppc->resolver_handle = NULL;
1048 ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); 1042 ppc->asc(ppc->asc_cls, NULL, GNUNET_OK);
1049 GNUNET_free (ppc); 1043 GNUNET_free(ppc);
1050 return; 1044 return;
1051 } 1045 }
1052 if (GNUNET_YES == ppc->ipv6) 1046 if (GNUNET_YES == ppc->ipv6)
1053 GNUNET_asprintf (&ret, 1047 GNUNET_asprintf(&ret,
1054 "%s.%u.[%s]:%d", 1048 "%s.%u.[%s]:%d",
1055 PLUGIN_NAME, 1049 PLUGIN_NAME,
1056 ppc->options, 1050 ppc->options,
1057 hostname, 1051 hostname,
1058 ppc->port); 1052 ppc->port);
1059 else 1053 else
1060 GNUNET_asprintf (&ret, 1054 GNUNET_asprintf(&ret,
1061 "%s.%u.%s:%d", 1055 "%s.%u.%s:%d",
1062 PLUGIN_NAME, 1056 PLUGIN_NAME,
1063 ppc->options, 1057 ppc->options,
1064 hostname, 1058 hostname,
1065 ppc->port); 1059 ppc->port);
1066 ppc->asc (ppc->asc_cls, ret, GNUNET_OK); 1060 ppc->asc(ppc->asc_cls, ret, GNUNET_OK);
1067 GNUNET_free (ret); 1061 GNUNET_free(ret);
1068} 1062}
1069 1063
1070 1064
@@ -1083,14 +1077,14 @@ append_port (void *cls, const char *hostname)
1083 * @param asc_cls closure for @a asc 1077 * @param asc_cls closure for @a asc
1084 */ 1078 */
1085static void 1079static void
1086udp_plugin_address_pretty_printer (void *cls, 1080udp_plugin_address_pretty_printer(void *cls,
1087 const char *type, 1081 const char *type,
1088 const void *addr, 1082 const void *addr,
1089 size_t addrlen, 1083 size_t addrlen,
1090 int numeric, 1084 int numeric,
1091 struct GNUNET_TIME_Relative timeout, 1085 struct GNUNET_TIME_Relative timeout,
1092 GNUNET_TRANSPORT_AddressStringCallback asc, 1086 GNUNET_TRANSPORT_AddressStringCallback asc,
1093 void *asc_cls) 1087 void *asc_cls)
1094{ 1088{
1095 struct Plugin *plugin = cls; 1089 struct Plugin *plugin = cls;
1096 struct PrettyPrinterContext *ppc; 1090 struct PrettyPrinterContext *ppc;
@@ -1103,61 +1097,61 @@ udp_plugin_address_pretty_printer (void *cls,
1103 uint16_t port; 1097 uint16_t port;
1104 uint32_t options; 1098 uint32_t options;
1105 1099
1106 if (addrlen == sizeof (struct IPv6UdpAddress)) 1100 if (addrlen == sizeof(struct IPv6UdpAddress))
1107 { 1101 {
1108 u6 = addr; 1102 u6 = addr;
1109 memset (&a6, 0, sizeof (a6)); 1103 memset(&a6, 0, sizeof(a6));
1110 a6.sin6_family = AF_INET6; 1104 a6.sin6_family = AF_INET6;
1111#if HAVE_SOCKADDR_IN_SIN_LEN 1105#if HAVE_SOCKADDR_IN_SIN_LEN
1112 a6.sin6_len = sizeof (a6); 1106 a6.sin6_len = sizeof(a6);
1113#endif 1107#endif
1114 a6.sin6_port = u6->u6_port; 1108 a6.sin6_port = u6->u6_port;
1115 a6.sin6_addr = u6->ipv6_addr; 1109 a6.sin6_addr = u6->ipv6_addr;
1116 port = ntohs (u6->u6_port); 1110 port = ntohs(u6->u6_port);
1117 options = ntohl (u6->options); 1111 options = ntohl(u6->options);
1118 sb = (const struct sockaddr *) &a6; 1112 sb = (const struct sockaddr *)&a6;
1119 sbs = sizeof (a6); 1113 sbs = sizeof(a6);
1120 } 1114 }
1121 else if (addrlen == sizeof (struct IPv4UdpAddress)) 1115 else if (addrlen == sizeof(struct IPv4UdpAddress))
1122 { 1116 {
1123 u4 = addr; 1117 u4 = addr;
1124 memset (&a4, 0, sizeof (a4)); 1118 memset(&a4, 0, sizeof(a4));
1125 a4.sin_family = AF_INET; 1119 a4.sin_family = AF_INET;
1126#if HAVE_SOCKADDR_IN_SIN_LEN 1120#if HAVE_SOCKADDR_IN_SIN_LEN
1127 a4.sin_len = sizeof (a4); 1121 a4.sin_len = sizeof(a4);
1128#endif 1122#endif
1129 a4.sin_port = u4->u4_port; 1123 a4.sin_port = u4->u4_port;
1130 a4.sin_addr.s_addr = u4->ipv4_addr; 1124 a4.sin_addr.s_addr = u4->ipv4_addr;
1131 port = ntohs (u4->u4_port); 1125 port = ntohs(u4->u4_port);
1132 options = ntohl (u4->options); 1126 options = ntohl(u4->options);
1133 sb = (const struct sockaddr *) &a4; 1127 sb = (const struct sockaddr *)&a4;
1134 sbs = sizeof (a4); 1128 sbs = sizeof(a4);
1135 } 1129 }
1136 else 1130 else
1137 { 1131 {
1138 /* invalid address */ 1132 /* invalid address */
1139 GNUNET_break_op (0); 1133 GNUNET_break_op(0);
1140 asc (asc_cls, NULL, GNUNET_SYSERR); 1134 asc(asc_cls, NULL, GNUNET_SYSERR);
1141 asc (asc_cls, NULL, GNUNET_OK); 1135 asc(asc_cls, NULL, GNUNET_OK);
1142 return; 1136 return;
1143 } 1137 }
1144 ppc = GNUNET_new (struct PrettyPrinterContext); 1138 ppc = GNUNET_new(struct PrettyPrinterContext);
1145 ppc->plugin = plugin; 1139 ppc->plugin = plugin;
1146 ppc->asc = asc; 1140 ppc->asc = asc;
1147 ppc->asc_cls = asc_cls; 1141 ppc->asc_cls = asc_cls;
1148 ppc->port = port; 1142 ppc->port = port;
1149 ppc->options = options; 1143 ppc->options = options;
1150 if (addrlen == sizeof (struct IPv6UdpAddress)) 1144 if (addrlen == sizeof(struct IPv6UdpAddress))
1151 ppc->ipv6 = GNUNET_YES; 1145 ppc->ipv6 = GNUNET_YES;
1152 else 1146 else
1153 ppc->ipv6 = GNUNET_NO; 1147 ppc->ipv6 = GNUNET_NO;
1154 GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); 1148 GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
1155 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, 1149 ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb,
1156 sbs, 1150 sbs,
1157 ! numeric, 1151 !numeric,
1158 timeout, 1152 timeout,
1159 &append_port, 1153 &append_port,
1160 ppc); 1154 ppc);
1161} 1155}
1162 1156
1163 1157
@@ -1171,7 +1165,7 @@ udp_plugin_address_pretty_printer (void *cls,
1171 * @return #GNUNET_OK if port is either our open or advertised port 1165 * @return #GNUNET_OK if port is either our open or advertised port
1172 */ 1166 */
1173static int 1167static int
1174check_port (const struct Plugin *plugin, uint16_t in_port) 1168check_port(const struct Plugin *plugin, uint16_t in_port)
1175{ 1169{
1176 if ((plugin->port == in_port) || (plugin->aport == in_port)) 1170 if ((plugin->port == in_port) || (plugin->aport == in_port))
1177 return GNUNET_OK; 1171 return GNUNET_OK;
@@ -1195,56 +1189,56 @@ check_port (const struct Plugin *plugin, uint16_t in_port)
1195 * and transport, #GNUNET_SYSERR if not 1189 * and transport, #GNUNET_SYSERR if not
1196 */ 1190 */
1197static int 1191static int
1198udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) 1192udp_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1199{ 1193{
1200 struct Plugin *plugin = cls; 1194 struct Plugin *plugin = cls;
1201 const struct IPv4UdpAddress *v4; 1195 const struct IPv4UdpAddress *v4;
1202 const struct IPv6UdpAddress *v6; 1196 const struct IPv6UdpAddress *v6;
1203 1197
1204 if (sizeof (struct IPv4UdpAddress) == addrlen) 1198 if (sizeof(struct IPv4UdpAddress) == addrlen)
1205 { 1199 {
1206 struct sockaddr_in s4; 1200 struct sockaddr_in s4;
1207 1201
1208 v4 = (const struct IPv4UdpAddress *) addr; 1202 v4 = (const struct IPv4UdpAddress *)addr;
1209 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) 1203 if (GNUNET_OK != check_port(plugin, ntohs(v4->u4_port)))
1210 return GNUNET_SYSERR; 1204 return GNUNET_SYSERR;
1211 memset (&s4, 0, sizeof (s4)); 1205 memset(&s4, 0, sizeof(s4));
1212 s4.sin_family = AF_INET; 1206 s4.sin_family = AF_INET;
1213#if HAVE_SOCKADDR_IN_SIN_LEN 1207#if HAVE_SOCKADDR_IN_SIN_LEN
1214 s4.sin_len = sizeof (s4); 1208 s4.sin_len = sizeof(s4);
1215#endif 1209#endif
1216 s4.sin_port = v4->u4_port; 1210 s4.sin_port = v4->u4_port;
1217 s4.sin_addr.s_addr = v4->ipv4_addr; 1211 s4.sin_addr.s_addr = v4->ipv4_addr;
1218 1212
1219 if (GNUNET_OK != 1213 if (GNUNET_OK !=
1220 GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in))) 1214 GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in)))
1221 return GNUNET_SYSERR; 1215 return GNUNET_SYSERR;
1222 } 1216 }
1223 else if (sizeof (struct IPv6UdpAddress) == addrlen) 1217 else if (sizeof(struct IPv6UdpAddress) == addrlen)
1224 { 1218 {
1225 struct sockaddr_in6 s6; 1219 struct sockaddr_in6 s6;
1226 1220
1227 v6 = (const struct IPv6UdpAddress *) addr; 1221 v6 = (const struct IPv6UdpAddress *)addr;
1228 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 1222 if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr))
1229 return GNUNET_OK; /* plausible, if unlikely... */ 1223 return GNUNET_OK; /* plausible, if unlikely... */
1230 memset (&s6, 0, sizeof (s6)); 1224 memset(&s6, 0, sizeof(s6));
1231 s6.sin6_family = AF_INET6; 1225 s6.sin6_family = AF_INET6;
1232#if HAVE_SOCKADDR_IN_SIN_LEN 1226#if HAVE_SOCKADDR_IN_SIN_LEN
1233 s6.sin6_len = sizeof (s6); 1227 s6.sin6_len = sizeof(s6);
1234#endif 1228#endif
1235 s6.sin6_port = v6->u6_port; 1229 s6.sin6_port = v6->u6_port;
1236 s6.sin6_addr = v6->ipv6_addr; 1230 s6.sin6_addr = v6->ipv6_addr;
1237 1231
1238 if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, 1232 if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat,
1239 &s6, 1233 &s6,
1240 sizeof (struct sockaddr_in6))) 1234 sizeof(struct sockaddr_in6)))
1241 return GNUNET_SYSERR; 1235 return GNUNET_SYSERR;
1242 } 1236 }
1243 else 1237 else
1244 { 1238 {
1245 GNUNET_break_op (0); 1239 GNUNET_break_op(0);
1246 return GNUNET_SYSERR; 1240 return GNUNET_SYSERR;
1247 } 1241 }
1248 return GNUNET_OK; 1242 return GNUNET_OK;
1249} 1243}
1250 1244
@@ -1262,12 +1256,12 @@ udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1262 * @param addrlen actual length of the @a addr 1256 * @param addrlen actual length of the @a addr
1263 */ 1257 */
1264static void 1258static void
1265udp_nat_port_map_callback (void *cls, 1259udp_nat_port_map_callback(void *cls,
1266 void **app_ctx, 1260 void **app_ctx,
1267 int add_remove, 1261 int add_remove,
1268 enum GNUNET_NAT_AddressClass ac, 1262 enum GNUNET_NAT_AddressClass ac,
1269 const struct sockaddr *addr, 1263 const struct sockaddr *addr,
1270 socklen_t addrlen) 1264 socklen_t addrlen)
1271{ 1265{
1272 struct Plugin *plugin = cls; 1266 struct Plugin *plugin = cls;
1273 struct GNUNET_HELLO_Address *address; 1267 struct GNUNET_HELLO_Address *address;
@@ -1276,57 +1270,59 @@ udp_nat_port_map_callback (void *cls,
1276 void *arg; 1270 void *arg;
1277 size_t args; 1271 size_t args;
1278 1272
1279 (void) app_ctx; 1273 (void)app_ctx;
1280 LOG (GNUNET_ERROR_TYPE_DEBUG, 1274 LOG(GNUNET_ERROR_TYPE_DEBUG,
1281 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n" 1275 (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n"
1282 : "NAT notification to remove address `%s'\n", 1276 : "NAT notification to remove address `%s'\n",
1283 GNUNET_a2s (addr, addrlen)); 1277 GNUNET_a2s(addr, addrlen));
1284 /* convert 'address' to our internal format */ 1278 /* convert 'address' to our internal format */
1285 switch (addr->sa_family) 1279 switch (addr->sa_family)
1286 { 1280 {
1287 case AF_INET: { 1281 case AF_INET: {
1288 const struct sockaddr_in *i4; 1282 const struct sockaddr_in *i4;
1289 1283
1290 GNUNET_assert (sizeof (struct sockaddr_in) == addrlen); 1284 GNUNET_assert(sizeof(struct sockaddr_in) == addrlen);
1291 i4 = (const struct sockaddr_in *) addr; 1285 i4 = (const struct sockaddr_in *)addr;
1292 if (0 == ntohs (i4->sin_port)) 1286 if (0 == ntohs(i4->sin_port))
1293 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1287 return; /* Port = 0 means unmapped, ignore these for UDP. */
1294 memset (&u4, 0, sizeof (u4)); 1288 memset(&u4, 0, sizeof(u4));
1295 u4.options = htonl (plugin->myoptions); 1289 u4.options = htonl(plugin->myoptions);
1296 u4.ipv4_addr = i4->sin_addr.s_addr; 1290 u4.ipv4_addr = i4->sin_addr.s_addr;
1297 u4.u4_port = i4->sin_port; 1291 u4.u4_port = i4->sin_port;
1298 arg = &u4; 1292 arg = &u4;
1299 args = sizeof (struct IPv4UdpAddress); 1293 args = sizeof(struct IPv4UdpAddress);
1300 break; 1294 break;
1301 } 1295 }
1302 case AF_INET6: { 1296
1303 const struct sockaddr_in6 *i6; 1297 case AF_INET6: {
1304 1298 const struct sockaddr_in6 *i6;
1305 GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen); 1299
1306 i6 = (const struct sockaddr_in6 *) addr; 1300 GNUNET_assert(sizeof(struct sockaddr_in6) == addrlen);
1307 if (0 == ntohs (i6->sin6_port)) 1301 i6 = (const struct sockaddr_in6 *)addr;
1308 return; /* Port = 0 means unmapped, ignore these for UDP. */ 1302 if (0 == ntohs(i6->sin6_port))
1309 memset (&u6, 0, sizeof (u6)); 1303 return; /* Port = 0 means unmapped, ignore these for UDP. */
1310 u6.options = htonl (plugin->myoptions); 1304 memset(&u6, 0, sizeof(u6));
1311 u6.ipv6_addr = i6->sin6_addr; 1305 u6.options = htonl(plugin->myoptions);
1312 u6.u6_port = i6->sin6_port; 1306 u6.ipv6_addr = i6->sin6_addr;
1313 arg = &u6; 1307 u6.u6_port = i6->sin6_port;
1314 args = sizeof (struct IPv6UdpAddress); 1308 arg = &u6;
1315 break; 1309 args = sizeof(struct IPv6UdpAddress);
1316 } 1310 break;
1317 default: 1311 }
1318 GNUNET_break (0); 1312
1319 return; 1313 default:
1320 } 1314 GNUNET_break(0);
1315 return;
1316 }
1321 /* modify our published address list */ 1317 /* modify our published address list */
1322 /* TODO: use 'ac' here in the future... */ 1318 /* TODO: use 'ac' here in the future... */
1323 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1319 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1324 PLUGIN_NAME, 1320 PLUGIN_NAME,
1325 arg, 1321 arg,
1326 args, 1322 args,
1327 GNUNET_HELLO_ADDRESS_INFO_NONE); 1323 GNUNET_HELLO_ADDRESS_INFO_NONE);
1328 plugin->env->notify_address (plugin->env->cls, add_remove, address); 1324 plugin->env->notify_address(plugin->env->cls, add_remove, address);
1329 GNUNET_HELLO_address_free (address); 1325 GNUNET_HELLO_address_free(address);
1330} 1326}
1331 1327
1332 1328
@@ -1336,8 +1332,7 @@ udp_nat_port_map_callback (void *cls,
1336/** 1332/**
1337 * Closure for #session_cmp_it(). 1333 * Closure for #session_cmp_it().
1338 */ 1334 */
1339struct GNUNET_ATS_SessionCompareContext 1335struct GNUNET_ATS_SessionCompareContext {
1340{
1341 /** 1336 /**
1342 * Set to session matching the address. 1337 * Set to session matching the address.
1343 */ 1338 */
@@ -1359,17 +1354,17 @@ struct GNUNET_ATS_SessionCompareContext
1359 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not 1354 * @return #GNUNET_NO if we found the session, #GNUNET_OK if not
1360 */ 1355 */
1361static int 1356static int
1362session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 1357session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1363{ 1358{
1364 struct GNUNET_ATS_SessionCompareContext *cctx = cls; 1359 struct GNUNET_ATS_SessionCompareContext *cctx = cls;
1365 struct GNUNET_ATS_Session *s = value; 1360 struct GNUNET_ATS_Session *s = value;
1366 1361
1367 if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address)) 1362 if (0 == GNUNET_HELLO_address_cmp(s->address, cctx->address))
1368 { 1363 {
1369 GNUNET_assert (GNUNET_NO == s->in_destroy); 1364 GNUNET_assert(GNUNET_NO == s->in_destroy);
1370 cctx->res = s; 1365 cctx->res = s;
1371 return GNUNET_NO; 1366 return GNUNET_NO;
1372 } 1367 }
1373 return GNUNET_OK; 1368 return GNUNET_OK;
1374} 1369}
1375 1370
@@ -1384,8 +1379,8 @@ session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1384 * @return the session if it exists, or NULL if it is not found 1379 * @return the session if it exists, or NULL if it is not found
1385 */ 1380 */
1386static struct GNUNET_ATS_Session * 1381static struct GNUNET_ATS_Session *
1387udp_plugin_lookup_session (void *cls, 1382udp_plugin_lookup_session(void *cls,
1388 const struct GNUNET_HELLO_Address *address) 1383 const struct GNUNET_HELLO_Address *address)
1389{ 1384{
1390 struct Plugin *plugin = cls; 1385 struct Plugin *plugin = cls;
1391 const struct IPv6UdpAddress *udp_a6; 1386 const struct IPv6UdpAddress *udp_a6;
@@ -1393,54 +1388,54 @@ udp_plugin_lookup_session (void *cls,
1393 struct GNUNET_ATS_SessionCompareContext cctx; 1388 struct GNUNET_ATS_SessionCompareContext cctx;
1394 1389
1395 if (NULL == address->address) 1390 if (NULL == address->address)
1396 {
1397 GNUNET_break (0);
1398 return NULL;
1399 }
1400 if (sizeof (struct IPv4UdpAddress) == address->address_length)
1401 {
1402 if (NULL == plugin->sockv4)
1403 return NULL;
1404 udp_a4 = (const struct IPv4UdpAddress *) address->address;
1405 if (0 == udp_a4->u4_port)
1406 { 1391 {
1407 GNUNET_break (0); 1392 GNUNET_break(0);
1408 return NULL; 1393 return NULL;
1409 } 1394 }
1410 } 1395 if (sizeof(struct IPv4UdpAddress) == address->address_length)
1411 else if (sizeof (struct IPv6UdpAddress) == address->address_length)
1412 {
1413 if (NULL == plugin->sockv6)
1414 return NULL;
1415 udp_a6 = (const struct IPv6UdpAddress *) address->address;
1416 if (0 == udp_a6->u6_port)
1417 { 1396 {
1418 GNUNET_break (0); 1397 if (NULL == plugin->sockv4)
1419 return NULL; 1398 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 }
1406 else if (sizeof(struct IPv6UdpAddress) == address->address_length)
1407 {
1408 if (NULL == plugin->sockv6)
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 }
1420 } 1416 }
1421 }
1422 else 1417 else
1423 { 1418 {
1424 GNUNET_break (0); 1419 GNUNET_break(0);
1425 return NULL; 1420 return NULL;
1426 } 1421 }
1427 1422
1428 /* check if session already exists */ 1423 /* check if session already exists */
1429 cctx.address = address; 1424 cctx.address = address;
1430 cctx.res = NULL; 1425 cctx.res = NULL;
1431 LOG (GNUNET_ERROR_TYPE_DEBUG, 1426 LOG(GNUNET_ERROR_TYPE_DEBUG,
1432 "Looking for existing session for peer `%s' with address `%s'\n", 1427 "Looking for existing session for peer `%s' with address `%s'\n",
1433 GNUNET_i2s (&address->peer), 1428 GNUNET_i2s(&address->peer),
1434 udp_address_to_string (plugin, 1429 udp_address_to_string(plugin,
1435 address->address, 1430 address->address,
1436 address->address_length)); 1431 address->address_length));
1437 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 1432 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
1438 &address->peer, 1433 &address->peer,
1439 &session_cmp_it, 1434 &session_cmp_it,
1440 &cctx); 1435 &cctx);
1441 if (NULL == cctx.res) 1436 if (NULL == cctx.res)
1442 return NULL; 1437 return NULL;
1443 LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); 1438 LOG(GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
1444 return cctx.res; 1439 return cctx.res;
1445} 1440}
1446 1441
@@ -1454,12 +1449,12 @@ udp_plugin_lookup_session (void *cls,
1454 * @param s session to reschedule timeout activity for 1449 * @param s session to reschedule timeout activity for
1455 */ 1450 */
1456static void 1451static void
1457reschedule_session_timeout (struct GNUNET_ATS_Session *s) 1452reschedule_session_timeout(struct GNUNET_ATS_Session *s)
1458{ 1453{
1459 if (GNUNET_YES == s->in_destroy) 1454 if (GNUNET_YES == s->in_destroy)
1460 return; 1455 return;
1461 GNUNET_assert (NULL != s->timeout_task); 1456 GNUNET_assert(NULL != s->timeout_task);
1462 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); 1457 s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT);
1463} 1458}
1464 1459
1465 1460
@@ -1473,22 +1468,22 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *s)
1473 * @param session which session is being updated 1468 * @param session which session is being updated
1474 */ 1469 */
1475static void 1470static void
1476udp_plugin_update_session_timeout (void *cls, 1471udp_plugin_update_session_timeout(void *cls,
1477 const struct GNUNET_PeerIdentity *peer, 1472 const struct GNUNET_PeerIdentity *peer,
1478 struct GNUNET_ATS_Session *session) 1473 struct GNUNET_ATS_Session *session)
1479{ 1474{
1480 struct Plugin *plugin = cls; 1475 struct Plugin *plugin = cls;
1481 1476
1482 if (GNUNET_YES != 1477 if (GNUNET_YES !=
1483 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, 1478 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions,
1484 peer, 1479 peer,
1485 session)) 1480 session))
1486 { 1481 {
1487 GNUNET_break (0); 1482 GNUNET_break(0);
1488 return; 1483 return;
1489 } 1484 }
1490 /* Reschedule session timeout */ 1485 /* Reschedule session timeout */
1491 reschedule_session_timeout (session); 1486 reschedule_session_timeout(session);
1492} 1487}
1493 1488
1494 1489
@@ -1503,47 +1498,47 @@ udp_plugin_update_session_timeout (void *cls,
1503 * @param udpw message wrapper to dequeue 1498 * @param udpw message wrapper to dequeue
1504 */ 1499 */
1505static void 1500static void
1506dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) 1501dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1507{ 1502{
1508 struct GNUNET_ATS_Session *session = udpw->session; 1503 struct GNUNET_ATS_Session *session = udpw->session;
1509 1504
1510 if (plugin->bytes_in_buffer < udpw->msg_size) 1505 if (plugin->bytes_in_buffer < udpw->msg_size)
1511 { 1506 {
1512 GNUNET_break (0); 1507 GNUNET_break(0);
1513 } 1508 }
1514 else 1509 else
1515 { 1510 {
1516 GNUNET_STATISTICS_update (plugin->env->stats, 1511 GNUNET_STATISTICS_update(plugin->env->stats,
1517 "# UDP, total bytes in send buffers", 1512 "# UDP, total bytes in send buffers",
1518 -(long long) udpw->msg_size, 1513 -(long long)udpw->msg_size,
1519 GNUNET_NO); 1514 GNUNET_NO);
1520 plugin->bytes_in_buffer -= udpw->msg_size; 1515 plugin->bytes_in_buffer -= udpw->msg_size;
1521 } 1516 }
1522 GNUNET_STATISTICS_update (plugin->env->stats, 1517 GNUNET_STATISTICS_update(plugin->env->stats,
1523 "# UDP, total messages in send buffers", 1518 "# UDP, total messages in send buffers",
1524 -1, 1519 -1,
1525 GNUNET_NO); 1520 GNUNET_NO);
1526 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) 1521 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1527 { 1522 {
1528 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, 1523 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_queue_head,
1529 plugin->ipv4_queue_tail, 1524 plugin->ipv4_queue_tail,
1530 udpw); 1525 udpw);
1531 } 1526 }
1532 else if (sizeof (struct IPv6UdpAddress) == 1527 else if (sizeof(struct IPv6UdpAddress) ==
1533 udpw->session->address->address_length) 1528 udpw->session->address->address_length)
1534 { 1529 {
1535 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, 1530 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_queue_head,
1536 plugin->ipv6_queue_tail, 1531 plugin->ipv6_queue_tail,
1537 udpw); 1532 udpw);
1538 } 1533 }
1539 else 1534 else
1540 { 1535 {
1541 GNUNET_break (0); 1536 GNUNET_break(0);
1542 return; 1537 return;
1543 } 1538 }
1544 GNUNET_assert (session->msgs_in_queue > 0); 1539 GNUNET_assert(session->msgs_in_queue > 0);
1545 session->msgs_in_queue--; 1540 session->msgs_in_queue--;
1546 GNUNET_assert (session->bytes_in_queue >= udpw->msg_size); 1541 GNUNET_assert(session->bytes_in_queue >= udpw->msg_size);
1547 session->bytes_in_queue -= udpw->msg_size; 1542 session->bytes_in_queue -= udpw->msg_size;
1548} 1543}
1549 1544
@@ -1555,56 +1550,56 @@ dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1555 * @param udpw message wrapper to queue 1550 * @param udpw message wrapper to queue
1556 */ 1551 */
1557static void 1552static void
1558enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) 1553enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1559{ 1554{
1560 struct GNUNET_ATS_Session *session = udpw->session; 1555 struct GNUNET_ATS_Session *session = udpw->session;
1561 1556
1562 if (GNUNET_YES == session->in_destroy) 1557 if (GNUNET_YES == session->in_destroy)
1563 { 1558 {
1564 GNUNET_break (0); 1559 GNUNET_break(0);
1565 GNUNET_free (udpw); 1560 GNUNET_free(udpw);
1566 return; 1561 return;
1567 } 1562 }
1568 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size) 1563 if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
1569 { 1564 {
1570 GNUNET_break (0); 1565 GNUNET_break(0);
1571 } 1566 }
1572 else 1567 else
1573 { 1568 {
1574 GNUNET_STATISTICS_update (plugin->env->stats, 1569 GNUNET_STATISTICS_update(plugin->env->stats,
1575 "# UDP, total bytes in send buffers", 1570 "# UDP, total bytes in send buffers",
1576 udpw->msg_size, 1571 udpw->msg_size,
1577 GNUNET_NO); 1572 GNUNET_NO);
1578 plugin->bytes_in_buffer += udpw->msg_size; 1573 plugin->bytes_in_buffer += udpw->msg_size;
1579 } 1574 }
1580 GNUNET_STATISTICS_update (plugin->env->stats, 1575 GNUNET_STATISTICS_update(plugin->env->stats,
1581 "# UDP, total messages in send buffers", 1576 "# UDP, total messages in send buffers",
1582 1, 1577 1,
1583 GNUNET_NO); 1578 GNUNET_NO);
1584 if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) 1579 if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1585 { 1580 {
1586 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, 1581 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head,
1587 plugin->ipv4_queue_tail, 1582 plugin->ipv4_queue_tail,
1588 udpw); 1583 udpw);
1589 } 1584 }
1590 else if (sizeof (struct IPv6UdpAddress) == 1585 else if (sizeof(struct IPv6UdpAddress) ==
1591 udpw->session->address->address_length) 1586 udpw->session->address->address_length)
1592 { 1587 {
1593 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, 1588 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_queue_head,
1594 plugin->ipv6_queue_tail, 1589 plugin->ipv6_queue_tail,
1595 udpw); 1590 udpw);
1596 } 1591 }
1597 else 1592 else
1598 { 1593 {
1599 GNUNET_break (0); 1594 GNUNET_break(0);
1600 udpw->cont (udpw->cont_cls, 1595 udpw->cont(udpw->cont_cls,
1601 &session->target, 1596 &session->target,
1602 GNUNET_SYSERR, 1597 GNUNET_SYSERR,
1603 udpw->msg_size, 1598 udpw->msg_size,
1604 0); 1599 0);
1605 GNUNET_free (udpw); 1600 GNUNET_free(udpw);
1606 return; 1601 return;
1607 } 1602 }
1608 session->msgs_in_queue++; 1603 session->msgs_in_queue++;
1609 session->bytes_in_queue += udpw->msg_size; 1604 session->bytes_in_queue += udpw->msg_size;
1610} 1605}
@@ -1621,7 +1616,7 @@ enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
1621 * #GNUNET_SYSERR if the transmission failed 1616 * #GNUNET_SYSERR if the transmission failed
1622 */ 1617 */
1623static void 1618static void
1624fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result) 1619fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
1625{ 1620{
1626 struct Plugin *plugin = frag_ctx->plugin; 1621 struct Plugin *plugin = frag_ctx->plugin;
1627 struct GNUNET_ATS_Session *s = frag_ctx->session; 1622 struct GNUNET_ATS_Session *s = frag_ctx->session;
@@ -1630,122 +1625,122 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
1630 size_t overhead; 1625 size_t overhead;
1631 struct GNUNET_TIME_Relative delay; 1626 struct GNUNET_TIME_Relative delay;
1632 1627
1633 LOG (GNUNET_ERROR_TYPE_DEBUG, 1628 LOG(GNUNET_ERROR_TYPE_DEBUG,
1634 "%p: Fragmented message removed with result %s\n", 1629 "%p: Fragmented message removed with result %s\n",
1635 frag_ctx, 1630 frag_ctx,
1636 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS"); 1631 (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS");
1637 /* Call continuation for fragmented message */ 1632 /* Call continuation for fragmented message */
1638 if (frag_ctx->on_wire_size >= frag_ctx->payload_size) 1633 if (frag_ctx->on_wire_size >= frag_ctx->payload_size)
1639 overhead = frag_ctx->on_wire_size - frag_ctx->payload_size; 1634 overhead = frag_ctx->on_wire_size - frag_ctx->payload_size;
1640 else 1635 else
1641 overhead = frag_ctx->on_wire_size; 1636 overhead = frag_ctx->on_wire_size;
1642 delay = GNUNET_TIME_absolute_get_duration (frag_ctx->start_time); 1637 delay = GNUNET_TIME_absolute_get_duration(frag_ctx->start_time);
1643 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 1638 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
1644 { 1639 {
1645 LOG (GNUNET_ERROR_TYPE_WARNING, 1640 LOG(GNUNET_ERROR_TYPE_WARNING,
1646 "Fragmented message acknowledged after %s (expected at %s)\n", 1641 "Fragmented message acknowledged after %s (expected at %s)\n",
1647 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 1642 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
1648 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); 1643 GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time));
1649 } 1644 }
1650 else 1645 else
1651 { 1646 {
1652 LOG (GNUNET_ERROR_TYPE_DEBUG, 1647 LOG(GNUNET_ERROR_TYPE_DEBUG,
1653 "Fragmented message acknowledged after %s (expected at %s)\n", 1648 "Fragmented message acknowledged after %s (expected at %s)\n",
1654 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 1649 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
1655 GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); 1650 GNUNET_STRINGS_absolute_time_to_string(frag_ctx->next_frag_time));
1656 } 1651 }
1657 1652
1658 if (NULL != frag_ctx->cont) 1653 if (NULL != frag_ctx->cont)
1659 frag_ctx->cont (frag_ctx->cont_cls, 1654 frag_ctx->cont(frag_ctx->cont_cls,
1660 &s->target, 1655 &s->target,
1661 result, 1656 result,
1662 s->frag_ctx->payload_size, 1657 s->frag_ctx->payload_size,
1663 frag_ctx->on_wire_size); 1658 frag_ctx->on_wire_size);
1664 GNUNET_STATISTICS_update (plugin->env->stats, 1659 GNUNET_STATISTICS_update(plugin->env->stats,
1665 "# UDP, fragmented messages active", 1660 "# UDP, fragmented messages active",
1666 -1, 1661 -1,
1667 GNUNET_NO); 1662 GNUNET_NO);
1668 1663
1669 if (GNUNET_OK == result) 1664 if (GNUNET_OK == result)
1670 { 1665 {
1671 GNUNET_STATISTICS_update (plugin->env->stats, 1666 GNUNET_STATISTICS_update(plugin->env->stats,
1672 "# UDP, fragmented msgs, messages, sent, success", 1667 "# UDP, fragmented msgs, messages, sent, success",
1673 1, 1668 1,
1674 GNUNET_NO); 1669 GNUNET_NO);
1675 GNUNET_STATISTICS_update (plugin->env->stats, 1670 GNUNET_STATISTICS_update(plugin->env->stats,
1676 "# UDP, fragmented msgs, bytes payload, sent, success", 1671 "# UDP, fragmented msgs, bytes payload, sent, success",
1677 s->frag_ctx->payload_size, 1672 s->frag_ctx->payload_size,
1678 GNUNET_NO); 1673 GNUNET_NO);
1679 GNUNET_STATISTICS_update ( 1674 GNUNET_STATISTICS_update(
1680 plugin->env->stats, 1675 plugin->env->stats,
1681 "# UDP, fragmented msgs, bytes overhead, sent, success", 1676 "# UDP, fragmented msgs, bytes overhead, sent, success",
1682 overhead, 1677 overhead,
1683 GNUNET_NO); 1678 GNUNET_NO);
1684 GNUNET_STATISTICS_update (plugin->env->stats, 1679 GNUNET_STATISTICS_update(plugin->env->stats,
1685 "# UDP, total, bytes overhead, sent", 1680 "# UDP, total, bytes overhead, sent",
1686 overhead, 1681 overhead,
1687 GNUNET_NO); 1682 GNUNET_NO);
1688 GNUNET_STATISTICS_update (plugin->env->stats, 1683 GNUNET_STATISTICS_update(plugin->env->stats,
1689 "# UDP, total, bytes payload, sent", 1684 "# UDP, total, bytes payload, sent",
1690 s->frag_ctx->payload_size, 1685 s->frag_ctx->payload_size,
1691 GNUNET_NO); 1686 GNUNET_NO);
1692 } 1687 }
1693 else 1688 else
1694 { 1689 {
1695 GNUNET_STATISTICS_update (plugin->env->stats, 1690 GNUNET_STATISTICS_update(plugin->env->stats,
1696 "# UDP, fragmented msgs, messages, sent, failure", 1691 "# UDP, fragmented msgs, messages, sent, failure",
1697 1, 1692 1,
1698 GNUNET_NO); 1693 GNUNET_NO);
1699 GNUNET_STATISTICS_update (plugin->env->stats, 1694 GNUNET_STATISTICS_update(plugin->env->stats,
1700 "# UDP, fragmented msgs, bytes payload, sent, failure", 1695 "# UDP, fragmented msgs, bytes payload, sent, failure",
1701 s->frag_ctx->payload_size, 1696 s->frag_ctx->payload_size,
1702 GNUNET_NO); 1697 GNUNET_NO);
1703 GNUNET_STATISTICS_update (plugin->env->stats, 1698 GNUNET_STATISTICS_update(plugin->env->stats,
1704 "# UDP, fragmented msgs, bytes payload, sent, failure", 1699 "# UDP, fragmented msgs, bytes payload, sent, failure",
1705 overhead, 1700 overhead,
1706 GNUNET_NO); 1701 GNUNET_NO);
1707 GNUNET_STATISTICS_update (plugin->env->stats, 1702 GNUNET_STATISTICS_update(plugin->env->stats,
1708 "# UDP, fragmented msgs, bytes payload, sent, failure", 1703 "# UDP, fragmented msgs, bytes payload, sent, failure",
1709 overhead, 1704 overhead,
1710 GNUNET_NO); 1705 GNUNET_NO);
1711 } 1706 }
1712 1707
1713 /* Remove remaining fragments from queue, no need to transmit those 1708 /* Remove remaining fragments from queue, no need to transmit those
1714 any longer. */ 1709 any longer. */
1715 if (s->address->address_length == sizeof (struct IPv6UdpAddress)) 1710 if (s->address->address_length == sizeof(struct IPv6UdpAddress))
1716 { 1711 {
1717 udpw = plugin->ipv6_queue_head; 1712 udpw = plugin->ipv6_queue_head;
1718 while (NULL != udpw) 1713 while (NULL != udpw)
1719 { 1714 {
1720 tmp = udpw->next; 1715 tmp = udpw->next;
1721 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx)) 1716 if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx))
1722 { 1717 {
1723 dequeue (plugin, udpw); 1718 dequeue(plugin, udpw);
1724 GNUNET_free (udpw); 1719 GNUNET_free(udpw);
1725 } 1720 }
1726 udpw = tmp; 1721 udpw = tmp;
1727 } 1722 }
1728 } 1723 }
1729 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 1724 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
1730 { 1725 {
1731 udpw = plugin->ipv4_queue_head; 1726 udpw = plugin->ipv4_queue_head;
1732 while (NULL != udpw) 1727 while (NULL != udpw)
1733 { 1728 {
1734 tmp = udpw->next; 1729 tmp = udpw->next;
1735 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx)) 1730 if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx))
1736 { 1731 {
1737 dequeue (plugin, udpw); 1732 dequeue(plugin, udpw);
1738 GNUNET_free (udpw); 1733 GNUNET_free(udpw);
1739 } 1734 }
1740 udpw = tmp; 1735 udpw = tmp;
1741 } 1736 }
1742 } 1737 }
1743 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 1738 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
1744 GNUNET_FRAGMENT_context_destroy (frag_ctx->frag, 1739 GNUNET_FRAGMENT_context_destroy(frag_ctx->frag,
1745 &s->last_expected_msg_delay, 1740 &s->last_expected_msg_delay,
1746 &s->last_expected_ack_delay); 1741 &s->last_expected_ack_delay);
1747 s->frag_ctx = NULL; 1742 s->frag_ctx = NULL;
1748 GNUNET_free (frag_ctx); 1743 GNUNET_free(frag_ctx);
1749} 1744}
1750 1745
1751 1746
@@ -1758,45 +1753,45 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
1758 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1753 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1759 */ 1754 */
1760static void 1755static void
1761qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) 1756qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1762{ 1757{
1763 struct Plugin *plugin = cls; 1758 struct Plugin *plugin = cls;
1764 1759
1765 GNUNET_assert (NULL != udpw->frag_ctx); 1760 GNUNET_assert(NULL != udpw->frag_ctx);
1766 if (GNUNET_OK == result) 1761 if (GNUNET_OK == result)
1767 { 1762 {
1768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1763 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1769 "Fragment of message with %u bytes transmitted to %s\n", 1764 "Fragment of message with %u bytes transmitted to %s\n",
1770 (unsigned int) udpw->payload_size, 1765 (unsigned int)udpw->payload_size,
1771 GNUNET_i2s (&udpw->session->target)); 1766 GNUNET_i2s(&udpw->session->target));
1772 GNUNET_FRAGMENT_context_transmission_done (udpw->frag_ctx->frag); 1767 GNUNET_FRAGMENT_context_transmission_done(udpw->frag_ctx->frag);
1773 GNUNET_STATISTICS_update (plugin->env->stats, 1768 GNUNET_STATISTICS_update(plugin->env->stats,
1774 "# UDP, fragmented msgs, fragments, sent, success", 1769 "# UDP, fragmented msgs, fragments, sent, success",
1775 1, 1770 1,
1776 GNUNET_NO); 1771 GNUNET_NO);
1777 GNUNET_STATISTICS_update ( 1772 GNUNET_STATISTICS_update(
1778 plugin->env->stats, 1773 plugin->env->stats,
1779 "# UDP, fragmented msgs, fragments bytes, sent, success", 1774 "# UDP, fragmented msgs, fragments bytes, sent, success",
1780 udpw->msg_size, 1775 udpw->msg_size,
1781 GNUNET_NO); 1776 GNUNET_NO);
1782 } 1777 }
1783 else 1778 else
1784 { 1779 {
1785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1780 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1786 "Failed to transmit fragment of message with %u bytes to %s\n", 1781 "Failed to transmit fragment of message with %u bytes to %s\n",
1787 (unsigned int) udpw->payload_size, 1782 (unsigned int)udpw->payload_size,
1788 GNUNET_i2s (&udpw->session->target)); 1783 GNUNET_i2s(&udpw->session->target));
1789 fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); 1784 fragmented_message_done(udpw->frag_ctx, GNUNET_SYSERR);
1790 GNUNET_STATISTICS_update (plugin->env->stats, 1785 GNUNET_STATISTICS_update(plugin->env->stats,
1791 "# UDP, fragmented msgs, fragments, sent, failure", 1786 "# UDP, fragmented msgs, fragments, sent, failure",
1792 1, 1787 1,
1793 GNUNET_NO); 1788 GNUNET_NO);
1794 GNUNET_STATISTICS_update ( 1789 GNUNET_STATISTICS_update(
1795 plugin->env->stats, 1790 plugin->env->stats,
1796 "# UDP, fragmented msgs, fragments bytes, sent, failure", 1791 "# UDP, fragmented msgs, fragments bytes, sent, failure",
1797 udpw->msg_size, 1792 udpw->msg_size,
1798 GNUNET_NO); 1793 GNUNET_NO);
1799 } 1794 }
1800} 1795}
1801 1796
1802 1797
@@ -1810,35 +1805,35 @@ qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1810 * @param msg the message that was created 1805 * @param msg the message that was created
1811 */ 1806 */
1812static void 1807static void
1813enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) 1808enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg)
1814{ 1809{
1815 struct UDP_FragmentationContext *frag_ctx = cls; 1810 struct UDP_FragmentationContext *frag_ctx = cls;
1816 struct Plugin *plugin = frag_ctx->plugin; 1811 struct Plugin *plugin = frag_ctx->plugin;
1817 struct UDP_MessageWrapper *udpw; 1812 struct UDP_MessageWrapper *udpw;
1818 struct GNUNET_ATS_Session *session = frag_ctx->session; 1813 struct GNUNET_ATS_Session *session = frag_ctx->session;
1819 size_t msg_len = ntohs (msg->size); 1814 size_t msg_len = ntohs(msg->size);
1820 1815
1821 LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); 1816 LOG(GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len);
1822 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); 1817 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msg_len);
1823 udpw->session = session; 1818 udpw->session = session;
1824 udpw->msg_buf = (char *) &udpw[1]; 1819 udpw->msg_buf = (char *)&udpw[1];
1825 udpw->msg_size = msg_len; 1820 udpw->msg_size = msg_len;
1826 udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */ 1821 udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */
1827 udpw->timeout = frag_ctx->timeout; 1822 udpw->timeout = frag_ctx->timeout;
1828 udpw->start_time = frag_ctx->start_time; 1823 udpw->start_time = frag_ctx->start_time;
1829 udpw->transmission_time = frag_ctx->next_frag_time; 1824 udpw->transmission_time = frag_ctx->next_frag_time;
1830 frag_ctx->next_frag_time = 1825 frag_ctx->next_frag_time =
1831 GNUNET_TIME_absolute_add (frag_ctx->next_frag_time, 1826 GNUNET_TIME_absolute_add(frag_ctx->next_frag_time,
1832 frag_ctx->flow_delay_from_other_peer); 1827 frag_ctx->flow_delay_from_other_peer);
1833 udpw->frag_ctx = frag_ctx; 1828 udpw->frag_ctx = frag_ctx;
1834 udpw->qc = &qc_fragment_sent; 1829 udpw->qc = &qc_fragment_sent;
1835 udpw->qc_cls = plugin; 1830 udpw->qc_cls = plugin;
1836 GNUNET_memcpy (udpw->msg_buf, msg, msg_len); 1831 GNUNET_memcpy(udpw->msg_buf, msg, msg_len);
1837 enqueue (plugin, udpw); 1832 enqueue(plugin, udpw);
1838 if (session->address->address_length == sizeof (struct IPv4UdpAddress)) 1833 if (session->address->address_length == sizeof(struct IPv4UdpAddress))
1839 schedule_select_v4 (plugin); 1834 schedule_select_v4(plugin);
1840 else 1835 else
1841 schedule_select_v6 (plugin); 1836 schedule_select_v6(plugin);
1842} 1837}
1843 1838
1844 1839
@@ -1851,7 +1846,7 @@ enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
1851 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure 1846 * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure
1852 */ 1847 */
1853static void 1848static void
1854qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) 1849qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
1855{ 1850{
1856 struct Plugin *plugin = cls; 1851 struct Plugin *plugin = cls;
1857 size_t overhead; 1852 size_t overhead;
@@ -1863,68 +1858,68 @@ qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1863 overhead = udpw->msg_size; 1858 overhead = udpw->msg_size;
1864 1859
1865 if (NULL != udpw->cont) 1860 if (NULL != udpw->cont)
1866 { 1861 {
1867 delay = GNUNET_TIME_absolute_get_duration (udpw->start_time); 1862 delay = GNUNET_TIME_absolute_get_duration(udpw->start_time);
1868 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 1863 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
1869 { 1864 {
1870 LOG (GNUNET_ERROR_TYPE_WARNING, 1865 LOG(GNUNET_ERROR_TYPE_WARNING,
1871 "Message sent via UDP with delay of %s\n", 1866 "Message sent via UDP with delay of %s\n",
1872 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1867 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
1873 } 1868 }
1874 else 1869 else
1875 { 1870 {
1876 LOG (GNUNET_ERROR_TYPE_DEBUG, 1871 LOG(GNUNET_ERROR_TYPE_DEBUG,
1877 "Message sent via UDP with delay of %s\n", 1872 "Message sent via UDP with delay of %s\n",
1878 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); 1873 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES));
1879 } 1874 }
1880 udpw->cont (udpw->cont_cls, 1875 udpw->cont(udpw->cont_cls,
1881 &udpw->session->target, 1876 &udpw->session->target,
1882 result, 1877 result,
1883 udpw->payload_size, 1878 udpw->payload_size,
1884 overhead); 1879 overhead);
1885 } 1880 }
1886 if (GNUNET_OK == result) 1881 if (GNUNET_OK == result)
1887 { 1882 {
1888 GNUNET_STATISTICS_update (plugin->env->stats, 1883 GNUNET_STATISTICS_update(plugin->env->stats,
1889 "# UDP, unfragmented msgs, messages, sent, success", 1884 "# UDP, unfragmented msgs, messages, sent, success",
1890 1, 1885 1,
1891 GNUNET_NO); 1886 GNUNET_NO);
1892 GNUNET_STATISTICS_update ( 1887 GNUNET_STATISTICS_update(
1893 plugin->env->stats, 1888 plugin->env->stats,
1894 "# UDP, unfragmented msgs, bytes payload, sent, success", 1889 "# UDP, unfragmented msgs, bytes payload, sent, success",
1895 udpw->payload_size, 1890 udpw->payload_size,
1896 GNUNET_NO); 1891 GNUNET_NO);
1897 GNUNET_STATISTICS_update ( 1892 GNUNET_STATISTICS_update(
1898 plugin->env->stats, 1893 plugin->env->stats,
1899 "# UDP, unfragmented msgs, bytes overhead, sent, success", 1894 "# UDP, unfragmented msgs, bytes overhead, sent, success",
1900 overhead, 1895 overhead,
1901 GNUNET_NO); 1896 GNUNET_NO);
1902 GNUNET_STATISTICS_update (plugin->env->stats, 1897 GNUNET_STATISTICS_update(plugin->env->stats,
1903 "# UDP, total, bytes overhead, sent", 1898 "# UDP, total, bytes overhead, sent",
1904 overhead, 1899 overhead,
1905 GNUNET_NO); 1900 GNUNET_NO);
1906 GNUNET_STATISTICS_update (plugin->env->stats, 1901 GNUNET_STATISTICS_update(plugin->env->stats,
1907 "# UDP, total, bytes payload, sent", 1902 "# UDP, total, bytes payload, sent",
1908 udpw->payload_size, 1903 udpw->payload_size,
1909 GNUNET_NO); 1904 GNUNET_NO);
1910 } 1905 }
1911 else 1906 else
1912 { 1907 {
1913 GNUNET_STATISTICS_update (plugin->env->stats, 1908 GNUNET_STATISTICS_update(plugin->env->stats,
1914 "# UDP, unfragmented msgs, messages, sent, failure", 1909 "# UDP, unfragmented msgs, messages, sent, failure",
1915 1, 1910 1,
1916 GNUNET_NO); 1911 GNUNET_NO);
1917 GNUNET_STATISTICS_update ( 1912 GNUNET_STATISTICS_update(
1918 plugin->env->stats, 1913 plugin->env->stats,
1919 "# UDP, unfragmented msgs, bytes payload, sent, failure", 1914 "# UDP, unfragmented msgs, bytes payload, sent, failure",
1920 udpw->payload_size, 1915 udpw->payload_size,
1921 GNUNET_NO); 1916 GNUNET_NO);
1922 GNUNET_STATISTICS_update ( 1917 GNUNET_STATISTICS_update(
1923 plugin->env->stats, 1918 plugin->env->stats,
1924 "# UDP, unfragmented msgs, bytes overhead, sent, failure", 1919 "# UDP, unfragmented msgs, bytes overhead, sent, failure",
1925 overhead, 1920 overhead,
1926 GNUNET_NO); 1921 GNUNET_NO);
1927 } 1922 }
1928} 1923}
1929 1924
1930 1925
@@ -1956,54 +1951,54 @@ qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
1956 * and does NOT mean that the message was not transmitted (DV) 1951 * and does NOT mean that the message was not transmitted (DV)
1957 */ 1952 */
1958static ssize_t 1953static ssize_t
1959udp_plugin_send (void *cls, 1954udp_plugin_send(void *cls,
1960 struct GNUNET_ATS_Session *s, 1955 struct GNUNET_ATS_Session *s,
1961 const char *msgbuf, 1956 const char *msgbuf,
1962 size_t msgbuf_size, 1957 size_t msgbuf_size,
1963 unsigned int priority, 1958 unsigned int priority,
1964 struct GNUNET_TIME_Relative to, 1959 struct GNUNET_TIME_Relative to,
1965 GNUNET_TRANSPORT_TransmitContinuation cont, 1960 GNUNET_TRANSPORT_TransmitContinuation cont,
1966 void *cont_cls) 1961 void *cont_cls)
1967{ 1962{
1968 struct Plugin *plugin = cls; 1963 struct Plugin *plugin = cls;
1969 size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); 1964 size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage);
1970 struct UDP_FragmentationContext *frag_ctx; 1965 struct UDP_FragmentationContext *frag_ctx;
1971 struct UDP_MessageWrapper *udpw; 1966 struct UDP_MessageWrapper *udpw;
1972 struct UDPMessage *udp; 1967 struct UDPMessage *udp;
1973 char mbuf[udpmlen] GNUNET_ALIGN; 1968 char mbuf[udpmlen] GNUNET_ALIGN;
1974 struct GNUNET_TIME_Relative latency; 1969 struct GNUNET_TIME_Relative latency;
1975 1970
1976 if ((sizeof (struct IPv6UdpAddress) == s->address->address_length) && 1971 if ((sizeof(struct IPv6UdpAddress) == s->address->address_length) &&
1977 (NULL == plugin->sockv6)) 1972 (NULL == plugin->sockv6))
1978 return GNUNET_SYSERR; 1973 return GNUNET_SYSERR;
1979 if ((sizeof (struct IPv4UdpAddress) == s->address->address_length) && 1974 if ((sizeof(struct IPv4UdpAddress) == s->address->address_length) &&
1980 (NULL == plugin->sockv4)) 1975 (NULL == plugin->sockv4))
1981 return GNUNET_SYSERR; 1976 return GNUNET_SYSERR;
1982 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) 1977 if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
1983 { 1978 {
1984 GNUNET_break (0); 1979 GNUNET_break(0);
1985 return GNUNET_SYSERR; 1980 return GNUNET_SYSERR;
1986 } 1981 }
1987 if (GNUNET_YES != 1982 if (GNUNET_YES !=
1988 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessions, 1983 GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessions,
1989 &s->target, 1984 &s->target,
1990 s)) 1985 s))
1991 { 1986 {
1992 GNUNET_break (0); 1987 GNUNET_break(0);
1993 return GNUNET_SYSERR; 1988 return GNUNET_SYSERR;
1994 } 1989 }
1995 LOG (GNUNET_ERROR_TYPE_DEBUG, 1990 LOG(GNUNET_ERROR_TYPE_DEBUG,
1996 "UDP transmits %u-byte message to `%s' using address `%s'\n", 1991 "UDP transmits %u-byte message to `%s' using address `%s'\n",
1997 udpmlen, 1992 udpmlen,
1998 GNUNET_i2s (&s->target), 1993 GNUNET_i2s(&s->target),
1999 udp_address_to_string (plugin, 1994 udp_address_to_string(plugin,
2000 s->address->address, 1995 s->address->address,
2001 s->address->address_length)); 1996 s->address->address_length));
2002 1997
2003 udp = (struct UDPMessage *) mbuf; 1998 udp = (struct UDPMessage *)mbuf;
2004 udp->header.size = htons (udpmlen); 1999 udp->header.size = htons(udpmlen);
2005 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); 2000 udp->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
2006 udp->reserved = htonl (0); 2001 udp->reserved = htonl(0);
2007 udp->sender = *plugin->env->my_identity; 2002 udp->sender = *plugin->env->my_identity;
2008 2003
2009 /* We do not update the session time out here! Otherwise this 2004 /* We do not update the session time out here! Otherwise this
@@ -2015,100 +2010,100 @@ udp_plugin_send (void *cls,
2015 * responses! 2010 * responses!
2016 */ 2011 */
2017 if (udpmlen <= UDP_MTU) 2012 if (udpmlen <= UDP_MTU)
2018 { 2013 {
2019 /* unfragmented message */ 2014 /* unfragmented message */
2020 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + udpmlen); 2015 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + udpmlen);
2021 udpw->session = s; 2016 udpw->session = s;
2022 udpw->msg_buf = (char *) &udpw[1]; 2017 udpw->msg_buf = (char *)&udpw[1];
2023 udpw->msg_size = udpmlen; /* message size with UDP overhead */ 2018 udpw->msg_size = udpmlen; /* message size with UDP overhead */
2024 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */ 2019 udpw->payload_size = msgbuf_size; /* message size without UDP overhead */
2025 udpw->start_time = GNUNET_TIME_absolute_get (); 2020 udpw->start_time = GNUNET_TIME_absolute_get();
2026 udpw->timeout = GNUNET_TIME_relative_to_absolute (to); 2021 udpw->timeout = GNUNET_TIME_relative_to_absolute(to);
2027 udpw->transmission_time = s->last_transmit_time; 2022 udpw->transmission_time = s->last_transmit_time;
2028 s->last_transmit_time = 2023 s->last_transmit_time =
2029 GNUNET_TIME_absolute_add (s->last_transmit_time, 2024 GNUNET_TIME_absolute_add(s->last_transmit_time,
2030 s->flow_delay_from_other_peer); 2025 s->flow_delay_from_other_peer);
2031 udpw->cont = cont; 2026 udpw->cont = cont;
2032 udpw->cont_cls = cont_cls; 2027 udpw->cont_cls = cont_cls;
2033 udpw->frag_ctx = NULL; 2028 udpw->frag_ctx = NULL;
2034 udpw->qc = &qc_message_sent; 2029 udpw->qc = &qc_message_sent;
2035 udpw->qc_cls = plugin; 2030 udpw->qc_cls = plugin;
2036 GNUNET_memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage)); 2031 GNUNET_memcpy(udpw->msg_buf, udp, sizeof(struct UDPMessage));
2037 GNUNET_memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], 2032 GNUNET_memcpy(&udpw->msg_buf[sizeof(struct UDPMessage)],
2038 msgbuf, 2033 msgbuf,
2039 msgbuf_size); 2034 msgbuf_size);
2040 enqueue (plugin, udpw); 2035 enqueue(plugin, udpw);
2041 GNUNET_STATISTICS_update (plugin->env->stats, 2036 GNUNET_STATISTICS_update(plugin->env->stats,
2042 "# UDP, unfragmented messages queued total", 2037 "# UDP, unfragmented messages queued total",
2043 1, 2038 1,
2044 GNUNET_NO); 2039 GNUNET_NO);
2045 GNUNET_STATISTICS_update (plugin->env->stats, 2040 GNUNET_STATISTICS_update(plugin->env->stats,
2046 "# UDP, unfragmented bytes payload queued total", 2041 "# UDP, unfragmented bytes payload queued total",
2047 msgbuf_size, 2042 msgbuf_size,
2048 GNUNET_NO); 2043 GNUNET_NO);
2049 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 2044 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2050 schedule_select_v4 (plugin); 2045 schedule_select_v4(plugin);
2051 else 2046 else
2052 schedule_select_v6 (plugin); 2047 schedule_select_v6(plugin);
2053 } 2048 }
2054 else 2049 else
2055 { 2050 {
2056 /* fragmented message */ 2051 /* fragmented message */
2057 if (NULL != s->frag_ctx) 2052 if (NULL != s->frag_ctx)
2058 return GNUNET_SYSERR; 2053 return GNUNET_SYSERR;
2059 GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size); 2054 GNUNET_memcpy(&udp[1], msgbuf, msgbuf_size);
2060 frag_ctx = GNUNET_new (struct UDP_FragmentationContext); 2055 frag_ctx = GNUNET_new(struct UDP_FragmentationContext);
2061 frag_ctx->plugin = plugin; 2056 frag_ctx->plugin = plugin;
2062 frag_ctx->session = s; 2057 frag_ctx->session = s;
2063 frag_ctx->cont = cont; 2058 frag_ctx->cont = cont;
2064 frag_ctx->cont_cls = cont_cls; 2059 frag_ctx->cont_cls = cont_cls;
2065 frag_ctx->start_time = GNUNET_TIME_absolute_get (); 2060 frag_ctx->start_time = GNUNET_TIME_absolute_get();
2066 frag_ctx->next_frag_time = s->last_transmit_time; 2061 frag_ctx->next_frag_time = s->last_transmit_time;
2067 frag_ctx->flow_delay_from_other_peer = 2062 frag_ctx->flow_delay_from_other_peer =
2068 GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer, 2063 GNUNET_TIME_relative_divide(s->flow_delay_from_other_peer,
2069 1 + (msgbuf_size / UDP_MTU)); 2064 1 + (msgbuf_size / UDP_MTU));
2070 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to); 2065 frag_ctx->timeout = GNUNET_TIME_relative_to_absolute(to);
2071 frag_ctx->payload_size = 2066 frag_ctx->payload_size =
2072 msgbuf_size; /* unfragmented message size without UDP overhead */ 2067 msgbuf_size; /* unfragmented message size without UDP overhead */
2073 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ 2068 frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
2074 frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 2069 frag_ctx->frag = GNUNET_FRAGMENT_context_create(plugin->env->stats,
2075 UDP_MTU, 2070 UDP_MTU,
2076 &plugin->tracker, 2071 &plugin->tracker,
2077 s->last_expected_msg_delay, 2072 s->last_expected_msg_delay,
2078 s->last_expected_ack_delay, 2073 s->last_expected_ack_delay,
2079 &udp->header, 2074 &udp->header,
2080 &enqueue_fragment, 2075 &enqueue_fragment,
2081 frag_ctx); 2076 frag_ctx);
2082 s->frag_ctx = frag_ctx; 2077 s->frag_ctx = frag_ctx;
2083 s->last_transmit_time = frag_ctx->next_frag_time; 2078 s->last_transmit_time = frag_ctx->next_frag_time;
2084 latency = GNUNET_TIME_absolute_get_remaining (s->last_transmit_time); 2079 latency = GNUNET_TIME_absolute_get_remaining(s->last_transmit_time);
2085 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2080 if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2086 LOG (GNUNET_ERROR_TYPE_WARNING, 2081 LOG(GNUNET_ERROR_TYPE_WARNING,
2087 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2082 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2088 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), 2083 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES),
2089 GNUNET_i2s (&s->target), 2084 GNUNET_i2s(&s->target),
2090 (unsigned int) s->msgs_in_queue); 2085 (unsigned int)s->msgs_in_queue);
2091 else 2086 else
2092 LOG (GNUNET_ERROR_TYPE_DEBUG, 2087 LOG(GNUNET_ERROR_TYPE_DEBUG,
2093 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", 2088 "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2094 GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), 2089 GNUNET_STRINGS_relative_time_to_string(latency, GNUNET_YES),
2095 GNUNET_i2s (&s->target), 2090 GNUNET_i2s(&s->target),
2096 (unsigned int) s->msgs_in_queue); 2091 (unsigned int)s->msgs_in_queue);
2097 2092
2098 GNUNET_STATISTICS_update (plugin->env->stats, 2093 GNUNET_STATISTICS_update(plugin->env->stats,
2099 "# UDP, fragmented messages active", 2094 "# UDP, fragmented messages active",
2100 1, 2095 1,
2101 GNUNET_NO); 2096 GNUNET_NO);
2102 GNUNET_STATISTICS_update (plugin->env->stats, 2097 GNUNET_STATISTICS_update(plugin->env->stats,
2103 "# UDP, fragmented messages, total", 2098 "# UDP, fragmented messages, total",
2104 1, 2099 1,
2105 GNUNET_NO); 2100 GNUNET_NO);
2106 GNUNET_STATISTICS_update (plugin->env->stats, 2101 GNUNET_STATISTICS_update(plugin->env->stats,
2107 "# UDP, fragmented bytes (payload)", 2102 "# UDP, fragmented bytes (payload)",
2108 frag_ctx->payload_size, 2103 frag_ctx->payload_size,
2109 GNUNET_NO); 2104 GNUNET_NO);
2110 } 2105 }
2111 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2106 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2112 return udpmlen; 2107 return udpmlen;
2113} 2108}
2114 2109
@@ -2119,8 +2114,7 @@ udp_plugin_send (void *cls,
2119/** 2114/**
2120 * Closure for #find_receive_context(). 2115 * Closure for #find_receive_context().
2121 */ 2116 */
2122struct FindReceiveContext 2117struct FindReceiveContext {
2123{
2124 /** 2118 /**
2125 * Where to store the result. 2119 * Where to store the result.
2126 */ 2120 */
@@ -2154,20 +2148,20 @@ struct FindReceiveContext
2154 * #GNUNET_NO if not. 2148 * #GNUNET_NO if not.
2155 */ 2149 */
2156static int 2150static int
2157find_receive_context (void *cls, 2151find_receive_context(void *cls,
2158 struct GNUNET_CONTAINER_HeapNode *node, 2152 struct GNUNET_CONTAINER_HeapNode *node,
2159 void *element, 2153 void *element,
2160 GNUNET_CONTAINER_HeapCostType cost) 2154 GNUNET_CONTAINER_HeapCostType cost)
2161{ 2155{
2162 struct FindReceiveContext *frc = cls; 2156 struct FindReceiveContext *frc = cls;
2163 struct DefragContext *e = element; 2157 struct DefragContext *e = element;
2164 2158
2165 if ((frc->udp_addr_len == e->udp_addr_len) && 2159 if ((frc->udp_addr_len == e->udp_addr_len) &&
2166 (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len))) 2160 (0 == memcmp(frc->udp_addr, e->udp_addr, frc->udp_addr_len)))
2167 { 2161 {
2168 frc->rc = e; 2162 frc->rc = e;
2169 return GNUNET_NO; 2163 return GNUNET_NO;
2170 } 2164 }
2171 return GNUNET_YES; 2165 return GNUNET_YES;
2172} 2166}
2173 2167
@@ -2181,96 +2175,96 @@ find_receive_context (void *cls,
2181 * @return #GNUNET_OK on success 2175 * @return #GNUNET_OK on success
2182 */ 2176 */
2183static int 2177static int
2184udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s) 2178udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s)
2185{ 2179{
2186 struct Plugin *plugin = cls; 2180 struct Plugin *plugin = cls;
2187 struct UDP_MessageWrapper *udpw; 2181 struct UDP_MessageWrapper *udpw;
2188 struct UDP_MessageWrapper *next; 2182 struct UDP_MessageWrapper *next;
2189 struct FindReceiveContext frc; 2183 struct FindReceiveContext frc;
2190 2184
2191 GNUNET_assert (GNUNET_YES != s->in_destroy); 2185 GNUNET_assert(GNUNET_YES != s->in_destroy);
2192 LOG (GNUNET_ERROR_TYPE_DEBUG, 2186 LOG(GNUNET_ERROR_TYPE_DEBUG,
2193 "Session %p to peer `%s' at address %s ended\n", 2187 "Session %p to peer `%s' at address %s ended\n",
2194 s, 2188 s,
2195 GNUNET_i2s (&s->target), 2189 GNUNET_i2s(&s->target),
2196 udp_address_to_string (plugin, 2190 udp_address_to_string(plugin,
2197 s->address->address, 2191 s->address->address,
2198 s->address->address_length)); 2192 s->address->address_length));
2199 if (NULL != s->timeout_task) 2193 if (NULL != s->timeout_task)
2200 { 2194 {
2201 GNUNET_SCHEDULER_cancel (s->timeout_task); 2195 GNUNET_SCHEDULER_cancel(s->timeout_task);
2202 s->timeout_task = NULL; 2196 s->timeout_task = NULL;
2203 } 2197 }
2204 if (NULL != s->frag_ctx) 2198 if (NULL != s->frag_ctx)
2205 { 2199 {
2206 /* Remove fragmented message due to disconnect */ 2200 /* Remove fragmented message due to disconnect */
2207 fragmented_message_done (s->frag_ctx, GNUNET_SYSERR); 2201 fragmented_message_done(s->frag_ctx, GNUNET_SYSERR);
2208 } 2202 }
2209 GNUNET_assert ( 2203 GNUNET_assert(
2210 GNUNET_YES == 2204 GNUNET_YES ==
2211 GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); 2205 GNUNET_CONTAINER_multipeermap_remove(plugin->sessions, &s->target, s));
2212 frc.rc = NULL; 2206 frc.rc = NULL;
2213 frc.udp_addr = s->address->address; 2207 frc.udp_addr = s->address->address;
2214 frc.udp_addr_len = s->address->address_length; 2208 frc.udp_addr_len = s->address->address_length;
2215 /* Lookup existing receive context for this address */ 2209 /* Lookup existing receive context for this address */
2216 if (NULL != plugin->defrag_ctxs) 2210 if (NULL != plugin->defrag_ctxs)
2217 {
2218 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs,
2219 &find_receive_context,
2220 &frc);
2221 if (NULL != frc.rc)
2222 { 2211 {
2223 struct DefragContext *d_ctx = frc.rc; 2212 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
2213 &find_receive_context,
2214 &frc);
2215 if (NULL != frc.rc)
2216 {
2217 struct DefragContext *d_ctx = frc.rc;
2224 2218
2225 GNUNET_CONTAINER_heap_remove_node (d_ctx->hnode); 2219 GNUNET_CONTAINER_heap_remove_node(d_ctx->hnode);
2226 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); 2220 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
2227 GNUNET_free (d_ctx); 2221 GNUNET_free(d_ctx);
2222 }
2228 } 2223 }
2229 }
2230 s->in_destroy = GNUNET_YES; 2224 s->in_destroy = GNUNET_YES;
2231 next = plugin->ipv4_queue_head; 2225 next = plugin->ipv4_queue_head;
2232 while (NULL != (udpw = next)) 2226 while (NULL != (udpw = next))
2233 {
2234 next = udpw->next;
2235 if (udpw->session == s)
2236 { 2227 {
2237 dequeue (plugin, udpw); 2228 next = udpw->next;
2238 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 2229 if (udpw->session == s)
2239 GNUNET_free (udpw); 2230 {
2231 dequeue(plugin, udpw);
2232 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
2233 GNUNET_free(udpw);
2234 }
2240 } 2235 }
2241 }
2242 next = plugin->ipv6_queue_head; 2236 next = plugin->ipv6_queue_head;
2243 while (NULL != (udpw = next)) 2237 while (NULL != (udpw = next))
2244 {
2245 next = udpw->next;
2246 if (udpw->session == s)
2247 { 2238 {
2248 dequeue (plugin, udpw); 2239 next = udpw->next;
2249 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 2240 if (udpw->session == s)
2250 GNUNET_free (udpw); 2241 {
2242 dequeue(plugin, udpw);
2243 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
2244 GNUNET_free(udpw);
2245 }
2251 } 2246 }
2252 }
2253 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont)) 2247 if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont))
2254 { 2248 {
2255 /* The 'frag_ctx' itself will be freed in #free_session() a bit 2249 /* The 'frag_ctx' itself will be freed in #free_session() a bit
2256 later, as it might be in use right now */ 2250 later, as it might be in use right now */
2257 LOG (GNUNET_ERROR_TYPE_DEBUG, 2251 LOG(GNUNET_ERROR_TYPE_DEBUG,
2258 "Calling continuation for fragemented message to `%s' with result SYSERR\n", 2252 "Calling continuation for fragemented message to `%s' with result SYSERR\n",
2259 GNUNET_i2s (&s->target)); 2253 GNUNET_i2s(&s->target));
2260 s->frag_ctx->cont (s->frag_ctx->cont_cls, 2254 s->frag_ctx->cont(s->frag_ctx->cont_cls,
2261 &s->target, 2255 &s->target,
2262 GNUNET_SYSERR, 2256 GNUNET_SYSERR,
2263 s->frag_ctx->payload_size, 2257 s->frag_ctx->payload_size,
2264 s->frag_ctx->on_wire_size); 2258 s->frag_ctx->on_wire_size);
2265 } 2259 }
2266 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE); 2260 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_DONE);
2267 plugin->env->session_end (plugin->env->cls, s->address, s); 2261 plugin->env->session_end(plugin->env->cls, s->address, s);
2268 GNUNET_STATISTICS_set (plugin->env->stats, 2262 GNUNET_STATISTICS_set(plugin->env->stats,
2269 "# UDP sessions active", 2263 "# UDP sessions active",
2270 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), 2264 GNUNET_CONTAINER_multipeermap_size(plugin->sessions),
2271 GNUNET_NO); 2265 GNUNET_NO);
2272 if (0 == s->rc) 2266 if (0 == s->rc)
2273 free_session (s); 2267 free_session(s);
2274 return GNUNET_OK; 2268 return GNUNET_OK;
2275} 2269}
2276 2270
@@ -2284,10 +2278,10 @@ udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
2284 * @param udp_addr_len number of bytes in @a udp_addr 2278 * @param udp_addr_len number of bytes in @a udp_addr
2285 */ 2279 */
2286static void 2280static void
2287read_process_ack (struct Plugin *plugin, 2281read_process_ack(struct Plugin *plugin,
2288 const struct GNUNET_MessageHeader *msg, 2282 const struct GNUNET_MessageHeader *msg,
2289 const union UdpAddress *udp_addr, 2283 const union UdpAddress *udp_addr,
2290 socklen_t udp_addr_len) 2284 socklen_t udp_addr_len)
2291{ 2285{
2292 const struct GNUNET_MessageHeader *ack; 2286 const struct GNUNET_MessageHeader *ack;
2293 const struct UDP_ACK_Message *udp_ack; 2287 const struct UDP_ACK_Message *udp_ack;
@@ -2296,93 +2290,93 @@ read_process_ack (struct Plugin *plugin,
2296 struct GNUNET_TIME_Relative flow_delay; 2290 struct GNUNET_TIME_Relative flow_delay;
2297 2291
2298 /* check message format */ 2292 /* check message format */
2299 if (ntohs (msg->size) < 2293 if (ntohs(msg->size) <
2300 sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader)) 2294 sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader))
2301 { 2295 {
2302 GNUNET_break_op (0); 2296 GNUNET_break_op(0);
2303 return; 2297 return;
2304 } 2298 }
2305 udp_ack = (const struct UDP_ACK_Message *) msg; 2299 udp_ack = (const struct UDP_ACK_Message *)msg;
2306 ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; 2300 ack = (const struct GNUNET_MessageHeader *)&udp_ack[1];
2307 if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) 2301 if (ntohs(ack->size) != ntohs(msg->size) - sizeof(struct UDP_ACK_Message))
2308 { 2302 {
2309 GNUNET_break_op (0); 2303 GNUNET_break_op(0);
2310 return; 2304 return;
2311 } 2305 }
2312 2306
2313 /* Locate session */ 2307 /* Locate session */
2314 address = GNUNET_HELLO_address_allocate (&udp_ack->sender, 2308 address = GNUNET_HELLO_address_allocate(&udp_ack->sender,
2315 PLUGIN_NAME, 2309 PLUGIN_NAME,
2316 udp_addr, 2310 udp_addr,
2317 udp_addr_len, 2311 udp_addr_len,
2318 GNUNET_HELLO_ADDRESS_INFO_NONE); 2312 GNUNET_HELLO_ADDRESS_INFO_NONE);
2319 s = udp_plugin_lookup_session (plugin, address); 2313 s = udp_plugin_lookup_session(plugin, address);
2320 if (NULL == s) 2314 if (NULL == s)
2321 { 2315 {
2322 LOG (GNUNET_ERROR_TYPE_WARNING, 2316 LOG(GNUNET_ERROR_TYPE_WARNING,
2323 "UDP session of address %s for ACK not found\n", 2317 "UDP session of address %s for ACK not found\n",
2324 udp_address_to_string (plugin, 2318 udp_address_to_string(plugin,
2325 address->address, 2319 address->address,
2326 address->address_length)); 2320 address->address_length));
2327 GNUNET_HELLO_address_free (address); 2321 GNUNET_HELLO_address_free(address);
2328 return; 2322 return;
2329 } 2323 }
2330 if (NULL == s->frag_ctx) 2324 if (NULL == s->frag_ctx)
2331 { 2325 {
2332 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2326 LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2333 "Fragmentation context of address %s for ACK (%s) not found\n", 2327 "Fragmentation context of address %s for ACK (%s) not found\n",
2334 udp_address_to_string (plugin, 2328 udp_address_to_string(plugin,
2335 address->address, 2329 address->address,
2336 address->address_length), 2330 address->address_length),
2337 GNUNET_FRAGMENT_print_ack (ack)); 2331 GNUNET_FRAGMENT_print_ack(ack));
2338 GNUNET_HELLO_address_free (address); 2332 GNUNET_HELLO_address_free(address);
2339 return; 2333 return;
2340 } 2334 }
2341 GNUNET_HELLO_address_free (address); 2335 GNUNET_HELLO_address_free(address);
2342 2336
2343 /* evaluate flow delay: how long should we wait between messages? */ 2337 /* evaluate flow delay: how long should we wait between messages? */
2344 if (UINT32_MAX == ntohl (udp_ack->delay)) 2338 if (UINT32_MAX == ntohl(udp_ack->delay))
2345 { 2339 {
2346 /* Other peer asked for us to terminate the session */ 2340 /* Other peer asked for us to terminate the session */
2347 LOG (GNUNET_ERROR_TYPE_INFO, 2341 LOG(GNUNET_ERROR_TYPE_INFO,
2348 "Asked to disconnect UDP session of %s\n", 2342 "Asked to disconnect UDP session of %s\n",
2349 GNUNET_i2s (&udp_ack->sender)); 2343 GNUNET_i2s(&udp_ack->sender));
2350 udp_disconnect_session (plugin, s); 2344 udp_disconnect_session(plugin, s);
2351 return; 2345 return;
2352 } 2346 }
2353 flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); 2347 flow_delay.rel_value_us = (uint64_t)ntohl(udp_ack->delay);
2354 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 2348 if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2355 LOG (GNUNET_ERROR_TYPE_WARNING, 2349 LOG(GNUNET_ERROR_TYPE_WARNING,
2356 "We received a sending delay of %s for %s\n", 2350 "We received a sending delay of %s for %s\n",
2357 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), 2351 GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES),
2358 GNUNET_i2s (&udp_ack->sender)); 2352 GNUNET_i2s(&udp_ack->sender));
2359 else 2353 else
2360 LOG (GNUNET_ERROR_TYPE_DEBUG, 2354 LOG(GNUNET_ERROR_TYPE_DEBUG,
2361 "We received a sending delay of %s for %s\n", 2355 "We received a sending delay of %s for %s\n",
2362 GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), 2356 GNUNET_STRINGS_relative_time_to_string(flow_delay, GNUNET_YES),
2363 GNUNET_i2s (&udp_ack->sender)); 2357 GNUNET_i2s(&udp_ack->sender));
2364 /* Flow delay is for the reassembled packet, however, our delay 2358 /* Flow delay is for the reassembled packet, however, our delay
2365 is per packet, so we need to adjust: */ 2359 is per packet, so we need to adjust: */
2366 s->flow_delay_from_other_peer = flow_delay; 2360 s->flow_delay_from_other_peer = flow_delay;
2367 2361
2368 /* Handle ACK */ 2362 /* Handle ACK */
2369 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) 2363 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack(s->frag_ctx->frag, ack))
2370 { 2364 {
2371 LOG (GNUNET_ERROR_TYPE_DEBUG, 2365 LOG(GNUNET_ERROR_TYPE_DEBUG,
2372 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 2366 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
2373 (unsigned int) ntohs (msg->size), 2367 (unsigned int)ntohs(msg->size),
2374 GNUNET_i2s (&udp_ack->sender), 2368 GNUNET_i2s(&udp_ack->sender),
2375 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2369 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2376 /* Expect more ACKs to arrive */ 2370 /* Expect more ACKs to arrive */
2377 return; 2371 return;
2378 } 2372 }
2379 2373
2380 /* Remove fragmented message after successful sending */ 2374 /* Remove fragmented message after successful sending */
2381 LOG (GNUNET_ERROR_TYPE_DEBUG, 2375 LOG(GNUNET_ERROR_TYPE_DEBUG,
2382 "Message from %s at %s full ACK'ed\n", 2376 "Message from %s at %s full ACK'ed\n",
2383 GNUNET_i2s (&udp_ack->sender), 2377 GNUNET_i2s(&udp_ack->sender),
2384 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2378 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2385 fragmented_message_done (s->frag_ctx, GNUNET_OK); 2379 fragmented_message_done(s->frag_ctx, GNUNET_OK);
2386} 2380}
2387 2381
2388 2382
@@ -2395,17 +2389,17 @@ read_process_ack (struct Plugin *plugin,
2395 * @return #GNUNET_OK (always) 2389 * @return #GNUNET_OK (always)
2396 */ 2390 */
2397static int 2391static int
2398process_inbound_tokenized_messages (void *cls, 2392process_inbound_tokenized_messages(void *cls,
2399 const struct GNUNET_MessageHeader *hdr) 2393 const struct GNUNET_MessageHeader *hdr)
2400{ 2394{
2401 struct GNUNET_ATS_Session *session = cls; 2395 struct GNUNET_ATS_Session *session = cls;
2402 struct Plugin *plugin = session->plugin; 2396 struct Plugin *plugin = session->plugin;
2403 2397
2404 if (GNUNET_YES == session->in_destroy) 2398 if (GNUNET_YES == session->in_destroy)
2405 return GNUNET_OK; 2399 return GNUNET_OK;
2406 reschedule_session_timeout (session); 2400 reschedule_session_timeout(session);
2407 session->flow_delay_for_other_peer = 2401 session->flow_delay_for_other_peer =
2408 plugin->env->receive (plugin->env->cls, session->address, session, hdr); 2402 plugin->env->receive(plugin->env->cls, session->address, session, hdr);
2409 return GNUNET_OK; 2403 return GNUNET_OK;
2410} 2404}
2411 2405
@@ -2419,13 +2413,13 @@ process_inbound_tokenized_messages (void *cls,
2419 * @return #GNUNET_OK (continue to iterate) 2413 * @return #GNUNET_OK (continue to iterate)
2420 */ 2414 */
2421static int 2415static int
2422disconnect_and_free_it (void *cls, 2416disconnect_and_free_it(void *cls,
2423 const struct GNUNET_PeerIdentity *key, 2417 const struct GNUNET_PeerIdentity *key,
2424 void *value) 2418 void *value)
2425{ 2419{
2426 struct Plugin *plugin = cls; 2420 struct Plugin *plugin = cls;
2427 2421
2428 udp_disconnect_session (plugin, value); 2422 udp_disconnect_session(plugin, value);
2429 return GNUNET_OK; 2423 return GNUNET_OK;
2430} 2424}
2431 2425
@@ -2439,17 +2433,17 @@ disconnect_and_free_it (void *cls,
2439 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 2433 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
2440 */ 2434 */
2441static void 2435static void
2442udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) 2436udp_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2443{ 2437{
2444 struct Plugin *plugin = cls; 2438 struct Plugin *plugin = cls;
2445 2439
2446 LOG (GNUNET_ERROR_TYPE_DEBUG, 2440 LOG(GNUNET_ERROR_TYPE_DEBUG,
2447 "Disconnecting from peer `%s'\n", 2441 "Disconnecting from peer `%s'\n",
2448 GNUNET_i2s (target)); 2442 GNUNET_i2s(target));
2449 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessions, 2443 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessions,
2450 target, 2444 target,
2451 &disconnect_and_free_it, 2445 &disconnect_and_free_it,
2452 plugin); 2446 plugin);
2453} 2447}
2454 2448
2455 2449
@@ -2459,29 +2453,29 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2459 * @param cls the `struct GNUNET_ATS_Session` to time out 2453 * @param cls the `struct GNUNET_ATS_Session` to time out
2460 */ 2454 */
2461static void 2455static void
2462session_timeout (void *cls) 2456session_timeout(void *cls)
2463{ 2457{
2464 struct GNUNET_ATS_Session *s = cls; 2458 struct GNUNET_ATS_Session *s = cls;
2465 struct Plugin *plugin = s->plugin; 2459 struct Plugin *plugin = s->plugin;
2466 struct GNUNET_TIME_Relative left; 2460 struct GNUNET_TIME_Relative left;
2467 2461
2468 s->timeout_task = NULL; 2462 s->timeout_task = NULL;
2469 left = GNUNET_TIME_absolute_get_remaining (s->timeout); 2463 left = GNUNET_TIME_absolute_get_remaining(s->timeout);
2470 if (left.rel_value_us > 0) 2464 if (left.rel_value_us > 0)
2471 { 2465 {
2472 /* not actually our turn yet, but let's at least update 2466 /* not actually our turn yet, but let's at least update
2473 the monitor, it may think we're about to die ... */ 2467 the monitor, it may think we're about to die ... */
2474 notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2468 notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2475 s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); 2469 s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s);
2476 return; 2470 return;
2477 } 2471 }
2478 LOG (GNUNET_ERROR_TYPE_DEBUG, 2472 LOG(GNUNET_ERROR_TYPE_DEBUG,
2479 "Session %p was idle for %s, disconnecting\n", 2473 "Session %p was idle for %s, disconnecting\n",
2480 s, 2474 s,
2481 GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, 2475 GNUNET_STRINGS_relative_time_to_string(UDP_SESSION_TIME_OUT,
2482 GNUNET_YES)); 2476 GNUNET_YES));
2483 /* call session destroy function */ 2477 /* call session destroy function */
2484 udp_disconnect_session (plugin, s); 2478 udp_disconnect_session(plugin, s);
2485} 2479}
2486 2480
2487 2481
@@ -2497,46 +2491,46 @@ session_timeout (void *cls)
2497 * @return NULL on error, otherwise session handle 2491 * @return NULL on error, otherwise session handle
2498 */ 2492 */
2499static struct GNUNET_ATS_Session * 2493static struct GNUNET_ATS_Session *
2500udp_plugin_create_session (void *cls, 2494udp_plugin_create_session(void *cls,
2501 const struct GNUNET_HELLO_Address *address, 2495 const struct GNUNET_HELLO_Address *address,
2502 enum GNUNET_NetworkType network_type) 2496 enum GNUNET_NetworkType network_type)
2503{ 2497{
2504 struct Plugin *plugin = cls; 2498 struct Plugin *plugin = cls;
2505 struct GNUNET_ATS_Session *s; 2499 struct GNUNET_ATS_Session *s;
2506 2500
2507 s = GNUNET_new (struct GNUNET_ATS_Session); 2501 s = GNUNET_new(struct GNUNET_ATS_Session);
2508 s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s); 2502 s->mst = GNUNET_MST_create(&process_inbound_tokenized_messages, s);
2509 s->plugin = plugin; 2503 s->plugin = plugin;
2510 s->address = GNUNET_HELLO_address_copy (address); 2504 s->address = GNUNET_HELLO_address_copy(address);
2511 s->target = address->peer; 2505 s->target = address->peer;
2512 s->last_transmit_time = GNUNET_TIME_absolute_get (); 2506 s->last_transmit_time = GNUNET_TIME_absolute_get();
2513 s->last_expected_ack_delay = 2507 s->last_expected_ack_delay =
2514 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); 2508 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250);
2515 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 2509 s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
2516 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; 2510 s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO;
2517 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; 2511 s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO;
2518 s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); 2512 s->timeout = GNUNET_TIME_relative_to_absolute(UDP_SESSION_TIME_OUT);
2519 s->timeout_task = 2513 s->timeout_task =
2520 GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s); 2514 GNUNET_SCHEDULER_add_delayed(UDP_SESSION_TIME_OUT, &session_timeout, s);
2521 s->scope = network_type; 2515 s->scope = network_type;
2522 2516
2523 LOG (GNUNET_ERROR_TYPE_DEBUG, 2517 LOG(GNUNET_ERROR_TYPE_DEBUG,
2524 "Creating new session %p for peer `%s' address `%s'\n", 2518 "Creating new session %p for peer `%s' address `%s'\n",
2525 s, 2519 s,
2526 GNUNET_i2s (&address->peer), 2520 GNUNET_i2s(&address->peer),
2527 udp_address_to_string (plugin, 2521 udp_address_to_string(plugin,
2528 address->address, 2522 address->address,
2529 address->address_length)); 2523 address->address_length));
2530 GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put ( 2524 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multipeermap_put(
2531 plugin->sessions, 2525 plugin->sessions,
2532 &s->target, 2526 &s->target,
2533 s, 2527 s,
2534 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 2528 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
2535 GNUNET_STATISTICS_set (plugin->env->stats, 2529 GNUNET_STATISTICS_set(plugin->env->stats,
2536 "# UDP sessions active", 2530 "# UDP sessions active",
2537 GNUNET_CONTAINER_multipeermap_size (plugin->sessions), 2531 GNUNET_CONTAINER_multipeermap_size(plugin->sessions),
2538 GNUNET_NO); 2532 GNUNET_NO);
2539 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT); 2533 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_INIT);
2540 return s; 2534 return s;
2541} 2535}
2542 2536
@@ -2550,7 +2544,7 @@ udp_plugin_create_session (void *cls,
2550 * @return the session or NULL of max connections exceeded 2544 * @return the session or NULL of max connections exceeded
2551 */ 2545 */
2552static struct GNUNET_ATS_Session * 2546static struct GNUNET_ATS_Session *
2553udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) 2547udp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
2554{ 2548{
2555 struct Plugin *plugin = cls; 2549 struct Plugin *plugin = cls;
2556 struct GNUNET_ATS_Session *s; 2550 struct GNUNET_ATS_Session *s;
@@ -2559,54 +2553,54 @@ udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2559 const struct IPv6UdpAddress *udp_v6; 2553 const struct IPv6UdpAddress *udp_v6;
2560 2554
2561 if (NULL == address) 2555 if (NULL == address)
2562 { 2556 {
2563 GNUNET_break (0); 2557 GNUNET_break(0);
2564 return NULL; 2558 return NULL;
2565 } 2559 }
2566 if ((address->address_length != sizeof (struct IPv4UdpAddress)) && 2560 if ((address->address_length != sizeof(struct IPv4UdpAddress)) &&
2567 (address->address_length != sizeof (struct IPv6UdpAddress))) 2561 (address->address_length != sizeof(struct IPv6UdpAddress)))
2568 { 2562 {
2569 GNUNET_break_op (0); 2563 GNUNET_break_op(0);
2570 return NULL; 2564 return NULL;
2571 } 2565 }
2572 if (NULL != (s = udp_plugin_lookup_session (cls, address))) 2566 if (NULL != (s = udp_plugin_lookup_session(cls, address)))
2573 return s; 2567 return s;
2574 2568
2575 /* need to create new session */ 2569 /* need to create new session */
2576 if (sizeof (struct IPv4UdpAddress) == address->address_length) 2570 if (sizeof(struct IPv4UdpAddress) == address->address_length)
2577 { 2571 {
2578 struct sockaddr_in v4; 2572 struct sockaddr_in v4;
2579 2573
2580 udp_v4 = (const struct IPv4UdpAddress *) address->address; 2574 udp_v4 = (const struct IPv4UdpAddress *)address->address;
2581 memset (&v4, '\0', sizeof (v4)); 2575 memset(&v4, '\0', sizeof(v4));
2582 v4.sin_family = AF_INET; 2576 v4.sin_family = AF_INET;
2583#if HAVE_SOCKADDR_IN_SIN_LEN 2577#if HAVE_SOCKADDR_IN_SIN_LEN
2584 v4.sin_len = sizeof (struct sockaddr_in); 2578 v4.sin_len = sizeof(struct sockaddr_in);
2585#endif 2579#endif
2586 v4.sin_port = udp_v4->u4_port; 2580 v4.sin_port = udp_v4->u4_port;
2587 v4.sin_addr.s_addr = udp_v4->ipv4_addr; 2581 v4.sin_addr.s_addr = udp_v4->ipv4_addr;
2588 network_type = plugin->env->get_address_type (plugin->env->cls, 2582 network_type = plugin->env->get_address_type(plugin->env->cls,
2589 (const struct sockaddr *) &v4, 2583 (const struct sockaddr *)&v4,
2590 sizeof (v4)); 2584 sizeof(v4));
2591 } 2585 }
2592 if (sizeof (struct IPv6UdpAddress) == address->address_length) 2586 if (sizeof(struct IPv6UdpAddress) == address->address_length)
2593 { 2587 {
2594 struct sockaddr_in6 v6; 2588 struct sockaddr_in6 v6;
2595 2589
2596 udp_v6 = (const struct IPv6UdpAddress *) address->address; 2590 udp_v6 = (const struct IPv6UdpAddress *)address->address;
2597 memset (&v6, '\0', sizeof (v6)); 2591 memset(&v6, '\0', sizeof(v6));
2598 v6.sin6_family = AF_INET6; 2592 v6.sin6_family = AF_INET6;
2599#if HAVE_SOCKADDR_IN_SIN_LEN 2593#if HAVE_SOCKADDR_IN_SIN_LEN
2600 v6.sin6_len = sizeof (struct sockaddr_in6); 2594 v6.sin6_len = sizeof(struct sockaddr_in6);
2601#endif 2595#endif
2602 v6.sin6_port = udp_v6->u6_port; 2596 v6.sin6_port = udp_v6->u6_port;
2603 v6.sin6_addr = udp_v6->ipv6_addr; 2597 v6.sin6_addr = udp_v6->ipv6_addr;
2604 network_type = plugin->env->get_address_type (plugin->env->cls, 2598 network_type = plugin->env->get_address_type(plugin->env->cls,
2605 (const struct sockaddr *) &v6, 2599 (const struct sockaddr *)&v6,
2606 sizeof (v6)); 2600 sizeof(v6));
2607 } 2601 }
2608 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); 2602 GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type);
2609 return udp_plugin_create_session (cls, address, network_type); 2603 return udp_plugin_create_session(cls, address, network_type);
2610} 2604}
2611 2605
2612 2606
@@ -2620,50 +2614,50 @@ udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
2620 * @param network_type network type the address belongs to 2614 * @param network_type network type the address belongs to
2621 */ 2615 */
2622static void 2616static void
2623process_udp_message (struct Plugin *plugin, 2617process_udp_message(struct Plugin *plugin,
2624 const struct UDPMessage *msg, 2618 const struct UDPMessage *msg,
2625 const union UdpAddress *udp_addr, 2619 const union UdpAddress *udp_addr,
2626 size_t udp_addr_len, 2620 size_t udp_addr_len,
2627 enum GNUNET_NetworkType network_type) 2621 enum GNUNET_NetworkType network_type)
2628{ 2622{
2629 struct GNUNET_ATS_Session *s; 2623 struct GNUNET_ATS_Session *s;
2630 struct GNUNET_HELLO_Address *address; 2624 struct GNUNET_HELLO_Address *address;
2631 2625
2632 GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); 2626 GNUNET_break(GNUNET_NT_UNSPECIFIED != network_type);
2633 if (0 != ntohl (msg->reserved)) 2627 if (0 != ntohl(msg->reserved))
2634 { 2628 {
2635 GNUNET_break_op (0); 2629 GNUNET_break_op(0);
2636 return; 2630 return;
2637 } 2631 }
2638 if (ntohs (msg->header.size) < 2632 if (ntohs(msg->header.size) <
2639 sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) 2633 sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage))
2640 { 2634 {
2641 GNUNET_break_op (0); 2635 GNUNET_break_op(0);
2642 return; 2636 return;
2643 } 2637 }
2644 2638
2645 address = GNUNET_HELLO_address_allocate (&msg->sender, 2639 address = GNUNET_HELLO_address_allocate(&msg->sender,
2646 PLUGIN_NAME, 2640 PLUGIN_NAME,
2647 udp_addr, 2641 udp_addr,
2648 udp_addr_len, 2642 udp_addr_len,
2649 GNUNET_HELLO_ADDRESS_INFO_NONE); 2643 GNUNET_HELLO_ADDRESS_INFO_NONE);
2650 if (NULL == (s = udp_plugin_lookup_session (plugin, address))) 2644 if (NULL == (s = udp_plugin_lookup_session(plugin, address)))
2651 { 2645 {
2652 s = udp_plugin_create_session (plugin, address, network_type); 2646 s = udp_plugin_create_session(plugin, address, network_type);
2653 plugin->env->session_start (plugin->env->cls, address, s, s->scope); 2647 plugin->env->session_start(plugin->env->cls, address, s, s->scope);
2654 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP); 2648 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UP);
2655 } 2649 }
2656 GNUNET_free (address); 2650 GNUNET_free(address);
2657 2651
2658 s->rc++; 2652 s->rc++;
2659 GNUNET_MST_from_buffer (s->mst, 2653 GNUNET_MST_from_buffer(s->mst,
2660 (const char *) &msg[1], 2654 (const char *)&msg[1],
2661 ntohs (msg->header.size) - sizeof (struct UDPMessage), 2655 ntohs(msg->header.size) - sizeof(struct UDPMessage),
2662 GNUNET_YES, 2656 GNUNET_YES,
2663 GNUNET_NO); 2657 GNUNET_NO);
2664 s->rc--; 2658 s->rc--;
2665 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) 2659 if ((0 == s->rc) && (GNUNET_YES == s->in_destroy))
2666 free_session (s); 2660 free_session(s);
2667} 2661}
2668 2662
2669 2663
@@ -2674,29 +2668,29 @@ process_udp_message (struct Plugin *plugin,
2674 * @param msg the message 2668 * @param msg the message
2675 */ 2669 */
2676static void 2670static void
2677fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) 2671fragment_msg_proc(void *cls, const struct GNUNET_MessageHeader *msg)
2678{ 2672{
2679 struct DefragContext *dc = cls; 2673 struct DefragContext *dc = cls;
2680 const struct UDPMessage *um; 2674 const struct UDPMessage *um;
2681 2675
2682 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) 2676 if (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
2683 { 2677 {
2684 GNUNET_break_op (0); 2678 GNUNET_break_op(0);
2685 return; 2679 return;
2686 } 2680 }
2687 if (ntohs (msg->size) < sizeof (struct UDPMessage)) 2681 if (ntohs(msg->size) < sizeof(struct UDPMessage))
2688 { 2682 {
2689 GNUNET_break_op (0); 2683 GNUNET_break_op(0);
2690 return; 2684 return;
2691 } 2685 }
2692 um = (const struct UDPMessage *) msg; 2686 um = (const struct UDPMessage *)msg;
2693 dc->sender = um->sender; 2687 dc->sender = um->sender;
2694 dc->have_sender = GNUNET_YES; 2688 dc->have_sender = GNUNET_YES;
2695 process_udp_message (dc->plugin, 2689 process_udp_message(dc->plugin,
2696 um, 2690 um,
2697 dc->udp_addr, 2691 dc->udp_addr,
2698 dc->udp_addr_len, 2692 dc->udp_addr_len,
2699 dc->network_type); 2693 dc->network_type);
2700} 2694}
2701 2695
2702 2696
@@ -2710,24 +2704,24 @@ fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
2710 * #GNUNET_SYSERR if we failed to send the ACK 2704 * #GNUNET_SYSERR if we failed to send the ACK
2711 */ 2705 */
2712static void 2706static void
2713ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) 2707ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
2714{ 2708{
2715 struct Plugin *plugin = cls; 2709 struct Plugin *plugin = cls;
2716 2710
2717 if (GNUNET_OK == result) 2711 if (GNUNET_OK == result)
2718 { 2712 {
2719 GNUNET_STATISTICS_update (plugin->env->stats, 2713 GNUNET_STATISTICS_update(plugin->env->stats,
2720 "# UDP, ACK messages sent", 2714 "# UDP, ACK messages sent",
2721 1, 2715 1,
2722 GNUNET_NO); 2716 GNUNET_NO);
2723 } 2717 }
2724 else 2718 else
2725 { 2719 {
2726 GNUNET_STATISTICS_update (plugin->env->stats, 2720 GNUNET_STATISTICS_update(plugin->env->stats,
2727 "# UDP, ACK transmissions failed", 2721 "# UDP, ACK transmissions failed",
2728 1, 2722 1,
2729 GNUNET_NO); 2723 GNUNET_NO);
2730 } 2724 }
2731} 2725}
2732 2726
2733 2727
@@ -2739,11 +2733,11 @@ ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
2739 * @param msg ack to transmit 2733 * @param msg ack to transmit
2740 */ 2734 */
2741static void 2735static void
2742ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) 2736ack_proc(void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2743{ 2737{
2744 struct DefragContext *rc = cls; 2738 struct DefragContext *rc = cls;
2745 struct Plugin *plugin = rc->plugin; 2739 struct Plugin *plugin = rc->plugin;
2746 size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); 2740 size_t msize = sizeof(struct UDP_ACK_Message) + ntohs(msg->size);
2747 struct UDP_ACK_Message *udp_ack; 2741 struct UDP_ACK_Message *udp_ack;
2748 uint32_t delay; 2742 uint32_t delay;
2749 struct UDP_MessageWrapper *udpw; 2743 struct UDP_MessageWrapper *udpw;
@@ -2751,36 +2745,36 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2751 struct GNUNET_HELLO_Address *address; 2745 struct GNUNET_HELLO_Address *address;
2752 2746
2753 if (GNUNET_NO == rc->have_sender) 2747 if (GNUNET_NO == rc->have_sender)
2754 { 2748 {
2755 /* tried to defragment but never succeeded, hence will not ACK */ 2749 /* tried to defragment but never succeeded, hence will not ACK */
2756 /* This can happen if we just lost msgs */ 2750 /* This can happen if we just lost msgs */
2757 GNUNET_STATISTICS_update (plugin->env->stats, 2751 GNUNET_STATISTICS_update(plugin->env->stats,
2758 "# UDP, fragments discarded without ACK", 2752 "# UDP, fragments discarded without ACK",
2759 1, 2753 1,
2760 GNUNET_NO); 2754 GNUNET_NO);
2761 return; 2755 return;
2762 } 2756 }
2763 address = GNUNET_HELLO_address_allocate (&rc->sender, 2757 address = GNUNET_HELLO_address_allocate(&rc->sender,
2764 PLUGIN_NAME, 2758 PLUGIN_NAME,
2765 rc->udp_addr, 2759 rc->udp_addr,
2766 rc->udp_addr_len, 2760 rc->udp_addr_len,
2767 GNUNET_HELLO_ADDRESS_INFO_NONE); 2761 GNUNET_HELLO_ADDRESS_INFO_NONE);
2768 s = udp_plugin_lookup_session (plugin, address); 2762 s = udp_plugin_lookup_session(plugin, address);
2769 GNUNET_HELLO_address_free (address); 2763 GNUNET_HELLO_address_free(address);
2770 if (NULL == s) 2764 if (NULL == s)
2771 { 2765 {
2772 LOG (GNUNET_ERROR_TYPE_ERROR, 2766 LOG(GNUNET_ERROR_TYPE_ERROR,
2773 "Trying to transmit ACK to peer `%s' but no session found!\n", 2767 "Trying to transmit ACK to peer `%s' but no session found!\n",
2774 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len)); 2768 udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len));
2775 GNUNET_CONTAINER_heap_remove_node (rc->hnode); 2769 GNUNET_CONTAINER_heap_remove_node(rc->hnode);
2776 GNUNET_DEFRAGMENT_context_destroy (rc->defrag); 2770 GNUNET_DEFRAGMENT_context_destroy(rc->defrag);
2777 GNUNET_free (rc); 2771 GNUNET_free(rc);
2778 GNUNET_STATISTICS_update (plugin->env->stats, 2772 GNUNET_STATISTICS_update(plugin->env->stats,
2779 "# UDP, ACK transmissions failed", 2773 "# UDP, ACK transmissions failed",
2780 1, 2774 1,
2781 GNUNET_NO); 2775 GNUNET_NO);
2782 return; 2776 return;
2783 } 2777 }
2784 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == 2778 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
2785 s->flow_delay_for_other_peer.rel_value_us) 2779 s->flow_delay_for_other_peer.rel_value_us)
2786 delay = UINT32_MAX; 2780 delay = UINT32_MAX;
@@ -2788,32 +2782,32 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2788 delay = s->flow_delay_for_other_peer.rel_value_us; 2782 delay = s->flow_delay_for_other_peer.rel_value_us;
2789 else 2783 else
2790 delay = UINT32_MAX - 1; /* largest value we can communicate */ 2784 delay = UINT32_MAX - 1; /* largest value we can communicate */
2791 LOG (GNUNET_ERROR_TYPE_DEBUG, 2785 LOG(GNUNET_ERROR_TYPE_DEBUG,
2792 "Sending ACK to `%s' including delay of %s\n", 2786 "Sending ACK to `%s' including delay of %s\n",
2793 udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len), 2787 udp_address_to_string(plugin, rc->udp_addr, rc->udp_addr_len),
2794 GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, 2788 GNUNET_STRINGS_relative_time_to_string(s->flow_delay_for_other_peer,
2795 GNUNET_YES)); 2789 GNUNET_YES));
2796 udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); 2790 udpw = GNUNET_malloc(sizeof(struct UDP_MessageWrapper) + msize);
2797 udpw->msg_size = msize; 2791 udpw->msg_size = msize;
2798 udpw->payload_size = 0; 2792 udpw->payload_size = 0;
2799 udpw->session = s; 2793 udpw->session = s;
2800 udpw->start_time = GNUNET_TIME_absolute_get (); 2794 udpw->start_time = GNUNET_TIME_absolute_get();
2801 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 2795 udpw->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
2802 udpw->msg_buf = (char *) &udpw[1]; 2796 udpw->msg_buf = (char *)&udpw[1];
2803 udpw->qc = &ack_message_sent; 2797 udpw->qc = &ack_message_sent;
2804 udpw->qc_cls = plugin; 2798 udpw->qc_cls = plugin;
2805 udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf; 2799 udp_ack = (struct UDP_ACK_Message *)udpw->msg_buf;
2806 udp_ack->header.size = htons ((uint16_t) msize); 2800 udp_ack->header.size = htons((uint16_t)msize);
2807 udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); 2801 udp_ack->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
2808 udp_ack->delay = htonl (delay); 2802 udp_ack->delay = htonl(delay);
2809 udp_ack->sender = *plugin->env->my_identity; 2803 udp_ack->sender = *plugin->env->my_identity;
2810 GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size)); 2804 GNUNET_memcpy(&udp_ack[1], msg, ntohs(msg->size));
2811 enqueue (plugin, udpw); 2805 enqueue(plugin, udpw);
2812 notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE); 2806 notify_session_monitor(plugin, s, GNUNET_TRANSPORT_SS_UPDATE);
2813 if (s->address->address_length == sizeof (struct IPv4UdpAddress)) 2807 if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2814 schedule_select_v4 (plugin); 2808 schedule_select_v4(plugin);
2815 else 2809 else
2816 schedule_select_v6 (plugin); 2810 schedule_select_v6(plugin);
2817} 2811}
2818 2812
2819 2813
@@ -2827,11 +2821,11 @@ ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
2827 * @param network_type network type the address belongs to 2821 * @param network_type network type the address belongs to
2828 */ 2822 */
2829static void 2823static void
2830read_process_fragment (struct Plugin *plugin, 2824read_process_fragment(struct Plugin *plugin,
2831 const struct GNUNET_MessageHeader *msg, 2825 const struct GNUNET_MessageHeader *msg,
2832 const union UdpAddress *udp_addr, 2826 const union UdpAddress *udp_addr,
2833 size_t udp_addr_len, 2827 size_t udp_addr_len,
2834 enum GNUNET_NetworkType network_type) 2828 enum GNUNET_NetworkType network_type)
2835{ 2829{
2836 struct DefragContext *d_ctx; 2830 struct DefragContext *d_ctx;
2837 struct GNUNET_TIME_Absolute now; 2831 struct GNUNET_TIME_Absolute now;
@@ -2842,65 +2836,65 @@ read_process_fragment (struct Plugin *plugin,
2842 frc.udp_addr_len = udp_addr_len; 2836 frc.udp_addr_len = udp_addr_len;
2843 2837
2844 /* Lookup existing receive context for this address */ 2838 /* Lookup existing receive context for this address */
2845 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, 2839 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
2846 &find_receive_context, 2840 &find_receive_context,
2847 &frc); 2841 &frc);
2848 now = GNUNET_TIME_absolute_get (); 2842 now = GNUNET_TIME_absolute_get();
2849 d_ctx = frc.rc; 2843 d_ctx = frc.rc;
2850 2844
2851 if (NULL == d_ctx) 2845 if (NULL == d_ctx)
2852 { 2846 {
2853 /* Create a new defragmentation context */ 2847 /* Create a new defragmentation context */
2854 d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len); 2848 d_ctx = GNUNET_malloc(sizeof(struct DefragContext) + udp_addr_len);
2855 GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len); 2849 GNUNET_memcpy(&d_ctx[1], udp_addr, udp_addr_len);
2856 d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1]; 2850 d_ctx->udp_addr = (const union UdpAddress *)&d_ctx[1];
2857 d_ctx->udp_addr_len = udp_addr_len; 2851 d_ctx->udp_addr_len = udp_addr_len;
2858 d_ctx->network_type = network_type; 2852 d_ctx->network_type = network_type;
2859 d_ctx->plugin = plugin; 2853 d_ctx->plugin = plugin;
2860 d_ctx->defrag = 2854 d_ctx->defrag =
2861 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 2855 GNUNET_DEFRAGMENT_context_create(plugin->env->stats,
2862 UDP_MTU, 2856 UDP_MTU,
2863 UDP_MAX_MESSAGES_IN_DEFRAG, 2857 UDP_MAX_MESSAGES_IN_DEFRAG,
2864 d_ctx, 2858 d_ctx,
2865 &fragment_msg_proc, 2859 &fragment_msg_proc,
2866 &ack_proc); 2860 &ack_proc);
2867 d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, 2861 d_ctx->hnode = GNUNET_CONTAINER_heap_insert(plugin->defrag_ctxs,
2868 d_ctx, 2862 d_ctx,
2869 (GNUNET_CONTAINER_HeapCostType) 2863 (GNUNET_CONTAINER_HeapCostType)
2870 now.abs_value_us); 2864 now.abs_value_us);
2871 LOG (GNUNET_ERROR_TYPE_DEBUG, 2865 LOG(GNUNET_ERROR_TYPE_DEBUG,
2872 "Created new defragmentation context for %u-byte fragment from `%s'\n", 2866 "Created new defragmentation context for %u-byte fragment from `%s'\n",
2873 (unsigned int) ntohs (msg->size), 2867 (unsigned int)ntohs(msg->size),
2874 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2868 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2875 } 2869 }
2876 else 2870 else
2877 { 2871 {
2878 LOG (GNUNET_ERROR_TYPE_DEBUG, 2872 LOG(GNUNET_ERROR_TYPE_DEBUG,
2879 "Found existing defragmentation context for %u-byte fragment from `%s'\n", 2873 "Found existing defragmentation context for %u-byte fragment from `%s'\n",
2880 (unsigned int) ntohs (msg->size), 2874 (unsigned int)ntohs(msg->size),
2881 udp_address_to_string (plugin, udp_addr, udp_addr_len)); 2875 udp_address_to_string(plugin, udp_addr, udp_addr_len));
2882 } 2876 }
2883 2877
2884 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) 2878 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment(d_ctx->defrag, msg))
2885 { 2879 {
2886 /* keep this 'rc' from expiring */ 2880 /* keep this 'rc' from expiring */
2887 GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, 2881 GNUNET_CONTAINER_heap_update_cost(d_ctx->hnode,
2888 (GNUNET_CONTAINER_HeapCostType) 2882 (GNUNET_CONTAINER_HeapCostType)
2889 now.abs_value_us); 2883 now.abs_value_us);
2890 } 2884 }
2891 if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > 2885 if (GNUNET_CONTAINER_heap_get_size(plugin->defrag_ctxs) >
2892 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) 2886 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
2893 { 2887 {
2894 /* remove 'rc' that was inactive the longest */ 2888 /* remove 'rc' that was inactive the longest */
2895 d_ctx = GNUNET_CONTAINER_heap_remove_root (plugin->defrag_ctxs); 2889 d_ctx = GNUNET_CONTAINER_heap_remove_root(plugin->defrag_ctxs);
2896 GNUNET_assert (NULL != d_ctx); 2890 GNUNET_assert(NULL != d_ctx);
2897 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); 2891 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
2898 GNUNET_free (d_ctx); 2892 GNUNET_free(d_ctx);
2899 GNUNET_STATISTICS_update (plugin->env->stats, 2893 GNUNET_STATISTICS_update(plugin->env->stats,
2900 "# UDP, Defragmentations aborted", 2894 "# UDP, Defragmentations aborted",
2901 1, 2895 1,
2902 GNUNET_NO); 2896 GNUNET_NO);
2903 } 2897 }
2904} 2898}
2905 2899
2906 2900
@@ -2911,7 +2905,7 @@ read_process_fragment (struct Plugin *plugin,
2911 * @param rsock socket to read from 2905 * @param rsock socket to read from
2912 */ 2906 */
2913static void 2907static void
2914udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) 2908udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2915{ 2909{
2916 socklen_t fromlen; 2910 socklen_t fromlen;
2917 struct sockaddr_storage addr; 2911 struct sockaddr_storage addr;
@@ -2927,14 +2921,14 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2927 size_t int_addr_len; 2921 size_t int_addr_len;
2928 enum GNUNET_NetworkType network_type; 2922 enum GNUNET_NetworkType network_type;
2929 2923
2930 fromlen = sizeof (addr); 2924 fromlen = sizeof(addr);
2931 memset (&addr, 0, sizeof (addr)); 2925 memset(&addr, 0, sizeof(addr));
2932 size = GNUNET_NETWORK_socket_recvfrom (rsock, 2926 size = GNUNET_NETWORK_socket_recvfrom(rsock,
2933 buf, 2927 buf,
2934 sizeof (buf), 2928 sizeof(buf),
2935 (struct sockaddr *) &addr, 2929 (struct sockaddr *)&addr,
2936 &fromlen); 2930 &fromlen);
2937 sa = (const struct sockaddr *) &addr; 2931 sa = (const struct sockaddr *)&addr;
2938#if MINGW 2932#if MINGW
2939 /* On SOCK_DGRAM UDP sockets recvfrom might fail with a 2933 /* On SOCK_DGRAM UDP sockets recvfrom might fail with a
2940 * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!) 2934 * WSAECONNRESET error to indicate that previous sendto() (yes, sendto!)
@@ -2950,111 +2944,117 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
2950 return; 2944 return;
2951#endif 2945#endif
2952 if (-1 == size) 2946 if (-1 == size)
2953 { 2947 {
2954 LOG (GNUNET_ERROR_TYPE_DEBUG, 2948 LOG(GNUNET_ERROR_TYPE_DEBUG,
2955 "UDP failed to receive data: %s\n", 2949 "UDP failed to receive data: %s\n",
2956 strerror (errno)); 2950 strerror(errno));
2957 /* Connection failure or something. Not a protocol violation. */ 2951 /* Connection failure or something. Not a protocol violation. */
2958 return; 2952 return;
2959 } 2953 }
2960 2954
2961 /* Check if this is a STUN packet */ 2955 /* Check if this is a STUN packet */
2962 if (GNUNET_NO != 2956 if (GNUNET_NO !=
2963 GNUNET_NAT_stun_handle_packet (plugin->nat, 2957 GNUNET_NAT_stun_handle_packet(plugin->nat,
2964 (const struct sockaddr *) &addr, 2958 (const struct sockaddr *)&addr,
2965 fromlen, 2959 fromlen,
2966 buf, 2960 buf,
2967 size)) 2961 size))
2968 return; /* was STUN, do not process further */ 2962 return; /* was STUN, do not process further */
2969 2963
2970 if (size < sizeof (struct GNUNET_MessageHeader)) 2964 if (size < sizeof(struct GNUNET_MessageHeader))
2971 { 2965 {
2972 LOG (GNUNET_ERROR_TYPE_WARNING, 2966 LOG(GNUNET_ERROR_TYPE_WARNING,
2973 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", 2967 "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n",
2974 (unsigned int) size, 2968 (unsigned int)size,
2975 GNUNET_a2s (sa, fromlen)); 2969 GNUNET_a2s(sa, fromlen));
2976 /* _MAY_ be a connection failure (got partial message) */ 2970 /* _MAY_ be a connection failure (got partial message) */
2977 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ 2971 /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */
2978 GNUNET_break_op (0); 2972 GNUNET_break_op(0);
2979 return; 2973 return;
2980 } 2974 }
2981 2975
2982 msg = (const struct GNUNET_MessageHeader *) buf; 2976 msg = (const struct GNUNET_MessageHeader *)buf;
2983 LOG (GNUNET_ERROR_TYPE_DEBUG, 2977 LOG(GNUNET_ERROR_TYPE_DEBUG,
2984 "UDP received %u-byte message from `%s' type %u\n", 2978 "UDP received %u-byte message from `%s' type %u\n",
2985 (unsigned int) size, 2979 (unsigned int)size,
2986 GNUNET_a2s (sa, fromlen), 2980 GNUNET_a2s(sa, fromlen),
2987 ntohs (msg->type)); 2981 ntohs(msg->type));
2988 if (size != ntohs (msg->size)) 2982 if (size != ntohs(msg->size))
2989 { 2983 {
2990 LOG (GNUNET_ERROR_TYPE_WARNING, 2984 LOG(GNUNET_ERROR_TYPE_WARNING,
2991 "UDP malformed message (size %u) header from %s\n", 2985 "UDP malformed message (size %u) header from %s\n",
2992 (unsigned int) size, 2986 (unsigned int)size,
2993 GNUNET_a2s (sa, fromlen)); 2987 GNUNET_a2s(sa, fromlen));
2994 GNUNET_break_op (0); 2988 GNUNET_break_op(0);
2995 return; 2989 return;
2996 } 2990 }
2997 GNUNET_STATISTICS_update (plugin->env->stats, 2991 GNUNET_STATISTICS_update(plugin->env->stats,
2998 "# UDP, total bytes received", 2992 "# UDP, total bytes received",
2999 size, 2993 size,
3000 GNUNET_NO); 2994 GNUNET_NO);
3001 network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen); 2995 network_type = plugin->env->get_address_type(plugin->env->cls, sa, fromlen);
3002 switch (sa->sa_family) 2996 switch (sa->sa_family)
3003 {
3004 case AF_INET:
3005 sa4 = (const struct sockaddr_in *) &addr;
3006 v4.options = 0;
3007 v4.ipv4_addr = sa4->sin_addr.s_addr;
3008 v4.u4_port = sa4->sin_port;
3009 int_addr = (union UdpAddress *) &v4;
3010 int_addr_len = sizeof (v4);
3011 break;
3012 case AF_INET6:
3013 sa6 = (const struct sockaddr_in6 *) &addr;
3014 v6.options = 0;
3015 v6.ipv6_addr = sa6->sin6_addr;
3016 v6.u6_port = sa6->sin6_port;
3017 int_addr = (union UdpAddress *) &v6;
3018 int_addr_len = sizeof (v6);
3019 break;
3020 default:
3021 GNUNET_break (0);
3022 return;
3023 }
3024
3025 switch (ntohs (msg->type))
3026 {
3027 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
3028 if (GNUNET_YES == plugin->enable_broadcasting_receiving)
3029 udp_broadcast_receive (plugin,
3030 buf,
3031 size,
3032 int_addr,
3033 int_addr_len,
3034 network_type);
3035 return;
3036 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3037 if (ntohs (msg->size) < sizeof (struct UDPMessage))
3038 { 2997 {
3039 GNUNET_break_op (0); 2998 case AF_INET:
2999 sa4 = (const struct sockaddr_in *)&addr;
3000 v4.options = 0;
3001 v4.ipv4_addr = sa4->sin_addr.s_addr;
3002 v4.u4_port = sa4->sin_port;
3003 int_addr = (union UdpAddress *)&v4;
3004 int_addr_len = sizeof(v4);
3005 break;
3006
3007 case AF_INET6:
3008 sa6 = (const struct sockaddr_in6 *)&addr;
3009 v6.options = 0;
3010 v6.ipv6_addr = sa6->sin6_addr;
3011 v6.u6_port = sa6->sin6_port;
3012 int_addr = (union UdpAddress *)&v6;
3013 int_addr_len = sizeof(v6);
3014 break;
3015
3016 default:
3017 GNUNET_break(0);
3018 return;
3019 }
3020
3021 switch (ntohs(msg->type))
3022 {
3023 case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON:
3024 if (GNUNET_YES == plugin->enable_broadcasting_receiving)
3025 udp_broadcast_receive(plugin,
3026 buf,
3027 size,
3028 int_addr,
3029 int_addr_len,
3030 network_type);
3031 return;
3032
3033 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
3034 if (ntohs(msg->size) < sizeof(struct UDPMessage))
3035 {
3036 GNUNET_break_op(0);
3037 return;
3038 }
3039 process_udp_message(plugin,
3040 (const struct UDPMessage *)msg,
3041 int_addr,
3042 int_addr_len,
3043 network_type);
3044 return;
3045
3046 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
3047 read_process_ack(plugin, msg, int_addr, int_addr_len);
3048 return;
3049
3050 case GNUNET_MESSAGE_TYPE_FRAGMENT:
3051 read_process_fragment(plugin, msg, int_addr, int_addr_len, network_type);
3052 return;
3053
3054 default:
3055 GNUNET_break_op(0);
3040 return; 3056 return;
3041 } 3057 }
3042 process_udp_message (plugin,
3043 (const struct UDPMessage *) msg,
3044 int_addr,
3045 int_addr_len,
3046 network_type);
3047 return;
3048 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
3049 read_process_ack (plugin, msg, int_addr, int_addr_len);
3050 return;
3051 case GNUNET_MESSAGE_TYPE_FRAGMENT:
3052 read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type);
3053 return;
3054 default:
3055 GNUNET_break_op (0);
3056 return;
3057 }
3058} 3058}
3059 3059
3060 3060
@@ -3068,8 +3068,8 @@ udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
3068 * @return message selected for transmission, or NULL for none 3068 * @return message selected for transmission, or NULL for none
3069 */ 3069 */
3070static struct UDP_MessageWrapper * 3070static struct UDP_MessageWrapper *
3071remove_timeout_messages_and_select (struct Plugin *plugin, 3071remove_timeout_messages_and_select(struct Plugin *plugin,
3072 struct GNUNET_NETWORK_Handle *sock) 3072 struct GNUNET_NETWORK_Handle *sock)
3073{ 3073{
3074 struct UDP_MessageWrapper *udpw; 3074 struct UDP_MessageWrapper *udpw;
3075 struct GNUNET_TIME_Relative remaining; 3075 struct GNUNET_TIME_Relative remaining;
@@ -3078,67 +3078,67 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3078 3078
3079 removed = GNUNET_NO; 3079 removed = GNUNET_NO;
3080 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head 3080 udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head
3081 : plugin->ipv6_queue_head; 3081 : plugin->ipv6_queue_head;
3082 while (NULL != udpw) 3082 while (NULL != udpw)
3083 { 3083 {
3084 session = udpw->session; 3084 session = udpw->session;
3085 /* Find messages with timeout */ 3085 /* Find messages with timeout */
3086 remaining = GNUNET_TIME_absolute_get_remaining (udpw->timeout); 3086 remaining = GNUNET_TIME_absolute_get_remaining(udpw->timeout);
3087 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us) 3087 if (GNUNET_TIME_UNIT_ZERO.rel_value_us == remaining.rel_value_us)
3088 { 3088 {
3089 /* Message timed out */ 3089 /* Message timed out */
3090 removed = GNUNET_YES; 3090 removed = GNUNET_YES;
3091 dequeue (plugin, udpw); 3091 dequeue(plugin, udpw);
3092 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3092 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3093 GNUNET_free (udpw); 3093 GNUNET_free(udpw);
3094 3094
3095 if (sock == plugin->sockv4) 3095 if (sock == plugin->sockv4)
3096 { 3096 {
3097 udpw = plugin->ipv4_queue_head; 3097 udpw = plugin->ipv4_queue_head;
3098 } 3098 }
3099 else if (sock == plugin->sockv6) 3099 else if (sock == plugin->sockv6)
3100 { 3100 {
3101 udpw = plugin->ipv6_queue_head; 3101 udpw = plugin->ipv6_queue_head;
3102 } 3102 }
3103 else 3103 else
3104 { 3104 {
3105 GNUNET_break (0); /* should never happen */ 3105 GNUNET_break(0); /* should never happen */
3106 udpw = NULL; 3106 udpw = NULL;
3107 } 3107 }
3108 GNUNET_STATISTICS_update (plugin->env->stats, 3108 GNUNET_STATISTICS_update(plugin->env->stats,
3109 "# messages discarded due to timeout", 3109 "# messages discarded due to timeout",
3110 1, 3110 1,
3111 GNUNET_NO); 3111 GNUNET_NO);
3112 } 3112 }
3113 else
3114 {
3115 /* Message did not time out, check transmission time */
3116 remaining = GNUNET_TIME_absolute_get_remaining (udpw->transmission_time);
3117 if (0 == remaining.rel_value_us)
3118 {
3119 /* this message is not delayed */
3120 LOG (GNUNET_ERROR_TYPE_DEBUG,
3121 "Message for peer `%s' (%u bytes) is not delayed \n",
3122 GNUNET_i2s (&udpw->session->target),
3123 udpw->payload_size);
3124 break; /* Found message to send, break */
3125 }
3126 else 3113 else
3127 { 3114 {
3128 /* Message is delayed, try next */ 3115 /* Message did not time out, check transmission time */
3129 LOG (GNUNET_ERROR_TYPE_DEBUG, 3116 remaining = GNUNET_TIME_absolute_get_remaining(udpw->transmission_time);
3130 "Message for peer `%s' (%u bytes) is delayed for %s\n", 3117 if (0 == remaining.rel_value_us)
3131 GNUNET_i2s (&udpw->session->target), 3118 {
3132 udpw->payload_size, 3119 /* this message is not delayed */
3133 GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); 3120 LOG(GNUNET_ERROR_TYPE_DEBUG,
3134 udpw = udpw->next; 3121 "Message for peer `%s' (%u bytes) is not delayed \n",
3135 } 3122 GNUNET_i2s(&udpw->session->target),
3136 } 3123 udpw->payload_size);
3137 } 3124 break; /* Found message to send, break */
3125 }
3126 else
3127 {
3128 /* Message is delayed, try next */
3129 LOG(GNUNET_ERROR_TYPE_DEBUG,
3130 "Message for peer `%s' (%u bytes) is delayed for %s\n",
3131 GNUNET_i2s(&udpw->session->target),
3132 udpw->payload_size,
3133 GNUNET_STRINGS_relative_time_to_string(remaining, GNUNET_YES));
3134 udpw = udpw->next;
3135 }
3136 }
3137 }
3138 if (GNUNET_YES == removed) 3138 if (GNUNET_YES == removed)
3139 notify_session_monitor (session->plugin, 3139 notify_session_monitor(session->plugin,
3140 session, 3140 session,
3141 GNUNET_TRANSPORT_SS_UPDATE); 3141 GNUNET_TRANSPORT_SS_UPDATE);
3142 return udpw; 3142 return udpw;
3143} 3143}
3144 3144
@@ -3153,50 +3153,50 @@ remove_timeout_messages_and_select (struct Plugin *plugin,
3153 * @param error the errno value returned from the sendto() call 3153 * @param error the errno value returned from the sendto() call
3154 */ 3154 */
3155static void 3155static void
3156analyze_send_error (struct Plugin *plugin, 3156analyze_send_error(struct Plugin *plugin,
3157 const struct sockaddr *sa, 3157 const struct sockaddr *sa,
3158 socklen_t slen, 3158 socklen_t slen,
3159 int error) 3159 int error)
3160{ 3160{
3161 enum GNUNET_NetworkType type; 3161 enum GNUNET_NetworkType type;
3162 3162
3163 type = plugin->env->get_address_type (plugin->env->cls, sa, slen); 3163 type = plugin->env->get_address_type(plugin->env->cls, sa, slen);
3164 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) && 3164 if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) &&
3165 ((ENETUNREACH == errno) || (ENETDOWN == errno))) 3165 ((ENETUNREACH == errno) || (ENETDOWN == errno)))
3166 { 3166 {
3167 if (slen == sizeof (struct sockaddr_in)) 3167 if (slen == sizeof(struct sockaddr_in))
3168 { 3168 {
3169 /* IPv4: "Network unreachable" or "Network down" 3169 /* IPv4: "Network unreachable" or "Network down"
3170 * 3170 *
3171 * This indicates we do not have connectivity 3171 * This indicates we do not have connectivity
3172 */ 3172 */
3173 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3173 LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3174 _ ("UDP could not transmit message to `%s': " 3174 _("UDP could not transmit message to `%s': "
3175 "Network seems down, please check your network configuration\n"), 3175 "Network seems down, please check your network configuration\n"),
3176 GNUNET_a2s (sa, slen)); 3176 GNUNET_a2s(sa, slen));
3177 } 3177 }
3178 if (slen == sizeof (struct sockaddr_in6)) 3178 if (slen == sizeof(struct sockaddr_in6))
3179 { 3179 {
3180 /* IPv6: "Network unreachable" or "Network down" 3180 /* IPv6: "Network unreachable" or "Network down"
3181 * 3181 *
3182 * This indicates that this system is IPv6 enabled, but does not 3182 * This indicates that this system is IPv6 enabled, but does not
3183 * have a valid global IPv6 address assigned or we do not have 3183 * have a valid global IPv6 address assigned or we do not have
3184 * connectivity 3184 * connectivity
3185 */ 3185 */
3186 LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, 3186 LOG(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK,
3187 _ ( 3187 _(
3188 "UDP could not transmit IPv6 message! " 3188 "UDP could not transmit IPv6 message! "
3189 "Please check your network configuration and disable IPv6 if your " 3189 "Please check your network configuration and disable IPv6 if your "
3190 "connection does not have a global IPv6 address\n")); 3190 "connection does not have a global IPv6 address\n"));
3191 } 3191 }
3192 } 3192 }
3193 else 3193 else
3194 { 3194 {
3195 LOG (GNUNET_ERROR_TYPE_WARNING, 3195 LOG(GNUNET_ERROR_TYPE_WARNING,
3196 "UDP could not transmit message to `%s': `%s'\n", 3196 "UDP could not transmit message to `%s': `%s'\n",
3197 GNUNET_a2s (sa, slen), 3197 GNUNET_a2s(sa, slen),
3198 strerror (error)); 3198 strerror(error));
3199 } 3199 }
3200} 3200}
3201 3201
3202 3202
@@ -3208,7 +3208,7 @@ analyze_send_error (struct Plugin *plugin,
3208 * @param sock which socket (v4/v6) to send on 3208 * @param sock which socket (v4/v6) to send on
3209 */ 3209 */
3210static void 3210static void
3211udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) 3211udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3212{ 3212{
3213 ssize_t sent; 3213 ssize_t sent;
3214 socklen_t slen; 3214 socklen_t slen;
@@ -3220,95 +3220,95 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3220 struct UDP_MessageWrapper *udpw; 3220 struct UDP_MessageWrapper *udpw;
3221 3221
3222 /* Find message(s) to send */ 3222 /* Find message(s) to send */
3223 while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock))) 3223 while (NULL != (udpw = remove_timeout_messages_and_select(plugin, sock)))
3224 {
3225 if (sizeof (struct IPv4UdpAddress) ==
3226 udpw->session->address->address_length)
3227 { 3224 {
3228 u4 = udpw->session->address->address; 3225 if (sizeof(struct IPv4UdpAddress) ==
3229 memset (&a4, 0, sizeof (a4)); 3226 udpw->session->address->address_length)
3230 a4.sin_family = AF_INET; 3227 {
3228 u4 = udpw->session->address->address;
3229 memset(&a4, 0, sizeof(a4));
3230 a4.sin_family = AF_INET;
3231#if HAVE_SOCKADDR_IN_SIN_LEN 3231#if HAVE_SOCKADDR_IN_SIN_LEN
3232 a4.sin_len = sizeof (a4); 3232 a4.sin_len = sizeof(a4);
3233#endif 3233#endif
3234 a4.sin_port = u4->u4_port; 3234 a4.sin_port = u4->u4_port;
3235 a4.sin_addr.s_addr = u4->ipv4_addr; 3235 a4.sin_addr.s_addr = u4->ipv4_addr;
3236 a = (const struct sockaddr *) &a4; 3236 a = (const struct sockaddr *)&a4;
3237 slen = sizeof (a4); 3237 slen = sizeof(a4);
3238 } 3238 }
3239 else if (sizeof (struct IPv6UdpAddress) == 3239 else if (sizeof(struct IPv6UdpAddress) ==
3240 udpw->session->address->address_length) 3240 udpw->session->address->address_length)
3241 { 3241 {
3242 u6 = udpw->session->address->address; 3242 u6 = udpw->session->address->address;
3243 memset (&a6, 0, sizeof (a6)); 3243 memset(&a6, 0, sizeof(a6));
3244 a6.sin6_family = AF_INET6; 3244 a6.sin6_family = AF_INET6;
3245#if HAVE_SOCKADDR_IN_SIN_LEN 3245#if HAVE_SOCKADDR_IN_SIN_LEN
3246 a6.sin6_len = sizeof (a6); 3246 a6.sin6_len = sizeof(a6);
3247#endif 3247#endif
3248 a6.sin6_port = u6->u6_port; 3248 a6.sin6_port = u6->u6_port;
3249 a6.sin6_addr = u6->ipv6_addr; 3249 a6.sin6_addr = u6->ipv6_addr;
3250 a = (const struct sockaddr *) &a6; 3250 a = (const struct sockaddr *)&a6;
3251 slen = sizeof (a6); 3251 slen = sizeof(a6);
3252 } 3252 }
3253 else 3253 else
3254 { 3254 {
3255 GNUNET_break (0); 3255 GNUNET_break(0);
3256 dequeue (plugin, udpw); 3256 dequeue(plugin, udpw);
3257 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3257 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3258 notify_session_monitor (plugin, 3258 notify_session_monitor(plugin,
3259 udpw->session, 3259 udpw->session,
3260 GNUNET_TRANSPORT_SS_UPDATE); 3260 GNUNET_TRANSPORT_SS_UPDATE);
3261 GNUNET_free (udpw); 3261 GNUNET_free(udpw);
3262 continue; 3262 continue;
3263 } 3263 }
3264 sent = GNUNET_NETWORK_socket_sendto (sock, 3264 sent = GNUNET_NETWORK_socket_sendto(sock,
3265 udpw->msg_buf, 3265 udpw->msg_buf,
3266 udpw->msg_size, 3266 udpw->msg_size,
3267 a, 3267 a,
3268 slen); 3268 slen);
3269 udpw->session->last_transmit_time = 3269 udpw->session->last_transmit_time =
3270 GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (), 3270 GNUNET_TIME_absolute_max(GNUNET_TIME_absolute_get(),
3271 udpw->session->last_transmit_time); 3271 udpw->session->last_transmit_time);
3272 dequeue (plugin, udpw); 3272 dequeue(plugin, udpw);
3273 if (GNUNET_SYSERR == sent) 3273 if (GNUNET_SYSERR == sent)
3274 { 3274 {
3275 /* Failure */ 3275 /* Failure */
3276 analyze_send_error (plugin, a, slen, errno); 3276 analyze_send_error(plugin, a, slen, errno);
3277 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3277 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3278 GNUNET_STATISTICS_update (plugin->env->stats, 3278 GNUNET_STATISTICS_update(plugin->env->stats,
3279 "# UDP, total, bytes, sent, failure", 3279 "# UDP, total, bytes, sent, failure",
3280 sent, 3280 sent,
3281 GNUNET_NO); 3281 GNUNET_NO);
3282 GNUNET_STATISTICS_update (plugin->env->stats, 3282 GNUNET_STATISTICS_update(plugin->env->stats,
3283 "# UDP, total, messages, sent, failure", 3283 "# UDP, total, messages, sent, failure",
3284 1, 3284 1,
3285 GNUNET_NO); 3285 GNUNET_NO);
3286 } 3286 }
3287 else 3287 else
3288 { 3288 {
3289 /* Success */ 3289 /* Success */
3290 LOG (GNUNET_ERROR_TYPE_DEBUG, 3290 LOG(GNUNET_ERROR_TYPE_DEBUG,
3291 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", 3291 "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n",
3292 (unsigned int) (udpw->msg_size), 3292 (unsigned int)(udpw->msg_size),
3293 GNUNET_i2s (&udpw->session->target), 3293 GNUNET_i2s(&udpw->session->target),
3294 GNUNET_a2s (a, slen), 3294 GNUNET_a2s(a, slen),
3295 (int) sent, 3295 (int)sent,
3296 (sent < 0) ? strerror (errno) : "ok"); 3296 (sent < 0) ? strerror(errno) : "ok");
3297 GNUNET_STATISTICS_update (plugin->env->stats, 3297 GNUNET_STATISTICS_update(plugin->env->stats,
3298 "# UDP, total, bytes, sent, success", 3298 "# UDP, total, bytes, sent, success",
3299 sent, 3299 sent,
3300 GNUNET_NO); 3300 GNUNET_NO);
3301 GNUNET_STATISTICS_update (plugin->env->stats, 3301 GNUNET_STATISTICS_update(plugin->env->stats,
3302 "# UDP, total, messages, sent, success", 3302 "# UDP, total, messages, sent, success",
3303 1, 3303 1,
3304 GNUNET_NO); 3304 GNUNET_NO);
3305 if (NULL != udpw->frag_ctx) 3305 if (NULL != udpw->frag_ctx)
3306 udpw->frag_ctx->on_wire_size += udpw->msg_size; 3306 udpw->frag_ctx->on_wire_size += udpw->msg_size;
3307 udpw->qc (udpw->qc_cls, udpw, GNUNET_OK); 3307 udpw->qc(udpw->qc_cls, udpw, GNUNET_OK);
3308 } 3308 }
3309 notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE); 3309 notify_session_monitor(plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE);
3310 GNUNET_free (udpw); 3310 GNUNET_free(udpw);
3311 } 3311 }
3312} 3312}
3313 3313
3314 3314
@@ -3323,7 +3323,7 @@ udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
3323 * @param cls the plugin handle 3323 * @param cls the plugin handle
3324 */ 3324 */
3325static void 3325static void
3326udp_plugin_select_v4 (void *cls) 3326udp_plugin_select_v4(void *cls)
3327{ 3327{
3328 struct Plugin *plugin = cls; 3328 struct Plugin *plugin = cls;
3329 const struct GNUNET_SCHEDULER_TaskContext *tc; 3329 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -3331,12 +3331,12 @@ udp_plugin_select_v4 (void *cls)
3331 plugin->select_task_v4 = NULL; 3331 plugin->select_task_v4 = NULL;
3332 if (NULL == plugin->sockv4) 3332 if (NULL == plugin->sockv4)
3333 return; 3333 return;
3334 tc = GNUNET_SCHEDULER_get_task_context (); 3334 tc = GNUNET_SCHEDULER_get_task_context();
3335 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3335 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3336 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) 3336 (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv4)))
3337 udp_select_read (plugin, plugin->sockv4); 3337 udp_select_read(plugin, plugin->sockv4);
3338 udp_select_send (plugin, plugin->sockv4); 3338 udp_select_send(plugin, plugin->sockv4);
3339 schedule_select_v4 (plugin); 3339 schedule_select_v4(plugin);
3340} 3340}
3341 3341
3342 3342
@@ -3348,7 +3348,7 @@ udp_plugin_select_v4 (void *cls)
3348 * @param cls the plugin handle 3348 * @param cls the plugin handle
3349 */ 3349 */
3350static void 3350static void
3351udp_plugin_select_v6 (void *cls) 3351udp_plugin_select_v6(void *cls)
3352{ 3352{
3353 struct Plugin *plugin = cls; 3353 struct Plugin *plugin = cls;
3354 const struct GNUNET_SCHEDULER_TaskContext *tc; 3354 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -3356,13 +3356,13 @@ udp_plugin_select_v6 (void *cls)
3356 plugin->select_task_v6 = NULL; 3356 plugin->select_task_v6 = NULL;
3357 if (NULL == plugin->sockv6) 3357 if (NULL == plugin->sockv6)
3358 return; 3358 return;
3359 tc = GNUNET_SCHEDULER_get_task_context (); 3359 tc = GNUNET_SCHEDULER_get_task_context();
3360 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && 3360 if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3361 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) 3361 (GNUNET_NETWORK_fdset_isset(tc->read_ready, plugin->sockv6)))
3362 udp_select_read (plugin, plugin->sockv6); 3362 udp_select_read(plugin, plugin->sockv6);
3363 3363
3364 udp_select_send (plugin, plugin->sockv6); 3364 udp_select_send(plugin, plugin->sockv6);
3365 schedule_select_v6 (plugin); 3365 schedule_select_v6(plugin);
3366} 3366}
3367 3367
3368 3368
@@ -3378,9 +3378,9 @@ udp_plugin_select_v6 (void *cls)
3378 * @return number of sockets that were successfully bound 3378 * @return number of sockets that were successfully bound
3379 */ 3379 */
3380static unsigned int 3380static unsigned int
3381setup_sockets (struct Plugin *plugin, 3381setup_sockets(struct Plugin *plugin,
3382 const struct sockaddr_in6 *bind_v6, 3382 const struct sockaddr_in6 *bind_v6,
3383 const struct sockaddr_in *bind_v4) 3383 const struct sockaddr_in *bind_v4)
3384{ 3384{
3385 int tries; 3385 int tries;
3386 unsigned int sockets_created = 0; 3386 unsigned int sockets_created = 0;
@@ -3395,186 +3395,186 @@ setup_sockets (struct Plugin *plugin,
3395 /* Create IPv6 socket */ 3395 /* Create IPv6 socket */
3396 eno = EINVAL; 3396 eno = EINVAL;
3397 if (GNUNET_YES == plugin->enable_ipv6) 3397 if (GNUNET_YES == plugin->enable_ipv6)
3398 {
3399 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
3400 if (NULL == plugin->sockv6)
3401 { 3398 {
3402 LOG (GNUNET_ERROR_TYPE_INFO, 3399 plugin->sockv6 = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_DGRAM, 0);
3403 _ ("Disabling IPv6 since it is not supported on this system!\n")); 3400 if (NULL == plugin->sockv6)
3404 plugin->enable_ipv6 = GNUNET_NO; 3401 {
3402 LOG(GNUNET_ERROR_TYPE_INFO,
3403 _("Disabling IPv6 since it is not supported on this system!\n"));
3404 plugin->enable_ipv6 = GNUNET_NO;
3405 }
3406 else
3407 {
3408 memset(&server_addrv6, 0, sizeof(struct sockaddr_in6));
3409#if HAVE_SOCKADDR_IN_SIN_LEN
3410 server_addrv6.sin6_len = sizeof(struct sockaddr_in6);
3411#endif
3412 server_addrv6.sin6_family = AF_INET6;
3413 if (NULL != bind_v6)
3414 server_addrv6.sin6_addr = bind_v6->sin6_addr;
3415 else
3416 server_addrv6.sin6_addr = in6addr_any;
3417
3418 if (0 == plugin->port) /* autodetect */
3419 server_addrv6.sin6_port = htons(
3420 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3421 32000);
3422 else
3423 server_addrv6.sin6_port = htons(plugin->port);
3424 addrlen = sizeof(struct sockaddr_in6);
3425 server_addr = (const struct sockaddr *)&server_addrv6;
3426
3427 tries = 0;
3428 while (tries < 10)
3429 {
3430 LOG(GNUNET_ERROR_TYPE_DEBUG,
3431 "Binding to IPv6 `%s'\n",
3432 GNUNET_a2s(server_addr, addrlen));
3433 /* binding */
3434 if (GNUNET_OK ==
3435 GNUNET_NETWORK_socket_bind(plugin->sockv6, server_addr, addrlen))
3436 break;
3437 eno = errno;
3438 if (0 != plugin->port)
3439 {
3440 tries = 10; /* fail immediately */
3441 break; /* bind failed on specific port */
3442 }
3443 /* autodetect */
3444 server_addrv6.sin6_port = htons(
3445 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3446 32000);
3447 tries++;
3448 }
3449 if (tries >= 10)
3450 {
3451 GNUNET_NETWORK_socket_close(plugin->sockv6);
3452 plugin->enable_ipv6 = GNUNET_NO;
3453 plugin->sockv6 = NULL;
3454 }
3455 else
3456 {
3457 plugin->port = ntohs(server_addrv6.sin6_port);
3458 }
3459 if (NULL != plugin->sockv6)
3460 {
3461 LOG(GNUNET_ERROR_TYPE_DEBUG,
3462 "IPv6 UDP socket created listinging at %s\n",
3463 GNUNET_a2s(server_addr, addrlen));
3464 addrs[sockets_created] = server_addr;
3465 addrlens[sockets_created] = addrlen;
3466 sockets_created++;
3467 }
3468 else
3469 {
3470 LOG(GNUNET_ERROR_TYPE_WARNING,
3471 _("Failed to bind UDP socket to %s: %s\n"),
3472 GNUNET_a2s(server_addr, addrlen),
3473 strerror(eno));
3474 }
3475 }
3476 }
3477
3478 /* Create IPv4 socket */
3479 eno = EINVAL;
3480 plugin->sockv4 = GNUNET_NETWORK_socket_create(PF_INET, SOCK_DGRAM, 0);
3481 if (NULL == plugin->sockv4)
3482 {
3483 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "socket");
3484 LOG(GNUNET_ERROR_TYPE_INFO,
3485 _("Disabling IPv4 since it is not supported on this system!\n"));
3486 plugin->enable_ipv4 = GNUNET_NO;
3405 } 3487 }
3406 else 3488 else
3407 { 3489 {
3408 memset (&server_addrv6, 0, sizeof (struct sockaddr_in6)); 3490 memset(&server_addrv4, 0, sizeof(struct sockaddr_in));
3409#if HAVE_SOCKADDR_IN_SIN_LEN 3491#if HAVE_SOCKADDR_IN_SIN_LEN
3410 server_addrv6.sin6_len = sizeof (struct sockaddr_in6); 3492 server_addrv4.sin_len = sizeof(struct sockaddr_in);
3411#endif 3493#endif
3412 server_addrv6.sin6_family = AF_INET6; 3494 server_addrv4.sin_family = AF_INET;
3413 if (NULL != bind_v6) 3495 if (NULL != bind_v4)
3414 server_addrv6.sin6_addr = bind_v6->sin6_addr; 3496 server_addrv4.sin_addr = bind_v4->sin_addr;
3415 else 3497 else
3416 server_addrv6.sin6_addr = in6addr_any; 3498 server_addrv4.sin_addr.s_addr = INADDR_ANY;
3417 3499
3418 if (0 == plugin->port) /* autodetect */ 3500 if (0 == plugin->port)
3419 server_addrv6.sin6_port = htons ( 3501 /* autodetect */
3420 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 3502 server_addrv4.sin_port = htons(
3421 32000); 3503 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3422 else 3504 else
3423 server_addrv6.sin6_port = htons (plugin->port); 3505 server_addrv4.sin_port = htons(plugin->port);
3424 addrlen = sizeof (struct sockaddr_in6); 3506
3425 server_addr = (const struct sockaddr *) &server_addrv6; 3507 addrlen = sizeof(struct sockaddr_in);
3508 server_addr = (const struct sockaddr *)&server_addrv4;
3426 3509
3427 tries = 0; 3510 tries = 0;
3428 while (tries < 10) 3511 while (tries < 10)
3429 {
3430 LOG (GNUNET_ERROR_TYPE_DEBUG,
3431 "Binding to IPv6 `%s'\n",
3432 GNUNET_a2s (server_addr, addrlen));
3433 /* binding */
3434 if (GNUNET_OK ==
3435 GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen))
3436 break;
3437 eno = errno;
3438 if (0 != plugin->port)
3439 { 3512 {
3440 tries = 10; /* fail immediately */ 3513 LOG(GNUNET_ERROR_TYPE_DEBUG,
3441 break; /* bind failed on specific port */ 3514 "Binding to IPv4 `%s'\n",
3515 GNUNET_a2s(server_addr, addrlen));
3516
3517 /* binding */
3518 if (GNUNET_OK ==
3519 GNUNET_NETWORK_socket_bind(plugin->sockv4, server_addr, addrlen))
3520 break;
3521 eno = errno;
3522 if (0 != plugin->port)
3523 {
3524 tries = 10; /* fail */
3525 break; /* bind failed on specific port */
3526 }
3527
3528 /* autodetect */
3529 server_addrv4.sin_port = htons(
3530 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3531 tries++;
3442 } 3532 }
3443 /* autodetect */
3444 server_addrv6.sin6_port = htons (
3445 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) +
3446 32000);
3447 tries++;
3448 }
3449 if (tries >= 10) 3533 if (tries >= 10)
3450 { 3534 {
3451 GNUNET_NETWORK_socket_close (plugin->sockv6); 3535 GNUNET_NETWORK_socket_close(plugin->sockv4);
3452 plugin->enable_ipv6 = GNUNET_NO; 3536 plugin->enable_ipv4 = GNUNET_NO;
3453 plugin->sockv6 = NULL; 3537 plugin->sockv4 = NULL;
3454 } 3538 }
3455 else
3456 {
3457 plugin->port = ntohs (server_addrv6.sin6_port);
3458 }
3459 if (NULL != plugin->sockv6)
3460 {
3461 LOG (GNUNET_ERROR_TYPE_DEBUG,
3462 "IPv6 UDP socket created listinging at %s\n",
3463 GNUNET_a2s (server_addr, addrlen));
3464 addrs[sockets_created] = server_addr;
3465 addrlens[sockets_created] = addrlen;
3466 sockets_created++;
3467 }
3468 else 3539 else
3469 { 3540 {
3470 LOG (GNUNET_ERROR_TYPE_WARNING, 3541 plugin->port = ntohs(server_addrv4.sin_port);
3471 _ ("Failed to bind UDP socket to %s: %s\n"), 3542 }
3472 GNUNET_a2s (server_addr, addrlen),
3473 strerror (eno));
3474 }
3475 }
3476 }
3477 3543
3478 /* Create IPv4 socket */ 3544 if (NULL != plugin->sockv4)
3479 eno = EINVAL; 3545 {
3480 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); 3546 LOG(GNUNET_ERROR_TYPE_DEBUG,
3481 if (NULL == plugin->sockv4) 3547 "IPv4 socket created on port %s\n",
3482 { 3548 GNUNET_a2s(server_addr, addrlen));
3483 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 3549 addrs[sockets_created] = server_addr;
3484 LOG (GNUNET_ERROR_TYPE_INFO, 3550 addrlens[sockets_created] = addrlen;
3485 _ ("Disabling IPv4 since it is not supported on this system!\n")); 3551 sockets_created++;
3486 plugin->enable_ipv4 = GNUNET_NO; 3552 }
3487 } 3553 else
3488 else 3554 {
3489 { 3555 LOG(GNUNET_ERROR_TYPE_ERROR,
3490 memset (&server_addrv4, 0, sizeof (struct sockaddr_in)); 3556 _("Failed to bind UDP socket to %s: %s\n"),
3491#if HAVE_SOCKADDR_IN_SIN_LEN 3557 GNUNET_a2s(server_addr, addrlen),
3492 server_addrv4.sin_len = sizeof (struct sockaddr_in); 3558 strerror(eno));
3493#endif 3559 }
3494 server_addrv4.sin_family = AF_INET;
3495 if (NULL != bind_v4)
3496 server_addrv4.sin_addr = bind_v4->sin_addr;
3497 else
3498 server_addrv4.sin_addr.s_addr = INADDR_ANY;
3499
3500 if (0 == plugin->port)
3501 /* autodetect */
3502 server_addrv4.sin_port = htons (
3503 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3504 else
3505 server_addrv4.sin_port = htons (plugin->port);
3506
3507 addrlen = sizeof (struct sockaddr_in);
3508 server_addr = (const struct sockaddr *) &server_addrv4;
3509
3510 tries = 0;
3511 while (tries < 10)
3512 {
3513 LOG (GNUNET_ERROR_TYPE_DEBUG,
3514 "Binding to IPv4 `%s'\n",
3515 GNUNET_a2s (server_addr, addrlen));
3516
3517 /* binding */
3518 if (GNUNET_OK ==
3519 GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen))
3520 break;
3521 eno = errno;
3522 if (0 != plugin->port)
3523 {
3524 tries = 10; /* fail */
3525 break; /* bind failed on specific port */
3526 }
3527
3528 /* autodetect */
3529 server_addrv4.sin_port = htons (
3530 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000);
3531 tries++;
3532 }
3533 if (tries >= 10)
3534 {
3535 GNUNET_NETWORK_socket_close (plugin->sockv4);
3536 plugin->enable_ipv4 = GNUNET_NO;
3537 plugin->sockv4 = NULL;
3538 }
3539 else
3540 {
3541 plugin->port = ntohs (server_addrv4.sin_port);
3542 } 3560 }
3543 3561
3544 if (NULL != plugin->sockv4) 3562 if (0 == sockets_created)
3545 {
3546 LOG (GNUNET_ERROR_TYPE_DEBUG,
3547 "IPv4 socket created on port %s\n",
3548 GNUNET_a2s (server_addr, addrlen));
3549 addrs[sockets_created] = server_addr;
3550 addrlens[sockets_created] = addrlen;
3551 sockets_created++;
3552 }
3553 else
3554 { 3563 {
3555 LOG (GNUNET_ERROR_TYPE_ERROR, 3564 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
3556 _ ("Failed to bind UDP socket to %s: %s\n"), 3565 return 0; /* No sockets created, return */
3557 GNUNET_a2s (server_addr, addrlen),
3558 strerror (eno));
3559 } 3566 }
3560 } 3567 schedule_select_v4(plugin);
3561 3568 schedule_select_v6(plugin);
3562 if (0 == sockets_created) 3569 plugin->nat = GNUNET_NAT_register(plugin->env->cfg,
3563 { 3570 "transport-udp",
3564 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n")); 3571 IPPROTO_UDP,
3565 return 0; /* No sockets created, return */ 3572 sockets_created,
3566 } 3573 addrs,
3567 schedule_select_v4 (plugin); 3574 addrlens,
3568 schedule_select_v6 (plugin); 3575 &udp_nat_port_map_callback,
3569 plugin->nat = GNUNET_NAT_register (plugin->env->cfg, 3576 NULL,
3570 "transport-udp", 3577 plugin);
3571 IPPROTO_UDP,
3572 sockets_created,
3573 addrs,
3574 addrlens,
3575 &udp_nat_port_map_callback,
3576 NULL,
3577 plugin);
3578 return sockets_created; 3578 return sockets_created;
3579} 3579}
3580 3580
@@ -3587,7 +3587,7 @@ setup_sockets (struct Plugin *plugin,
3587 * @return our `struct GNUNET_TRANSPORT_PluginFunctions` 3587 * @return our `struct GNUNET_TRANSPORT_PluginFunctions`
3588 */ 3588 */
3589void * 3589void *
3590libgnunet_plugin_transport_udp_init (void *cls) 3590libgnunet_plugin_transport_udp_init(void *cls)
3591{ 3591{
3592 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 3592 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
3593 struct GNUNET_TRANSPORT_PluginFunctions *api; 3593 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -3608,128 +3608,128 @@ libgnunet_plugin_transport_udp_init (void *cls)
3608 int have_bind6; 3608 int have_bind6;
3609 3609
3610 if (NULL == env->receive) 3610 if (NULL == env->receive)
3611 { 3611 {
3612 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 3612 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
3613 initialze the plugin or the API */ 3613 initialze the plugin or the API */
3614 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3614 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3615 api->cls = NULL; 3615 api->cls = NULL;
3616 api->address_pretty_printer = &udp_plugin_address_pretty_printer; 3616 api->address_pretty_printer = &udp_plugin_address_pretty_printer;
3617 api->address_to_string = &udp_address_to_string; 3617 api->address_to_string = &udp_address_to_string;
3618 api->string_to_address = &udp_string_to_address; 3618 api->string_to_address = &udp_string_to_address;
3619 return api; 3619 return api;
3620 } 3620 }
3621 3621
3622 /* Get port number: port == 0 : autodetect a port, 3622 /* Get port number: port == 0 : autodetect a port,
3623 * > 0 : use this port, not given : 2086 default */ 3623 * > 0 : use this port, not given : 2086 default */
3624 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3624 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3625 "transport-udp", 3625 "transport-udp",
3626 "PORT", 3626 "PORT",
3627 &port)) 3627 &port))
3628 port = 2086; 3628 port = 2086;
3629 if (port > 65535) 3629 if (port > 65535)
3630 { 3630 {
3631 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3631 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3632 "transport-udp", 3632 "transport-udp",
3633 "PORT", 3633 "PORT",
3634 _ ("must be in [0,65535]")); 3634 _("must be in [0,65535]"));
3635 return NULL; 3635 return NULL;
3636 } 3636 }
3637 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3637 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3638 "transport-udp", 3638 "transport-udp",
3639 "ADVERTISED_PORT", 3639 "ADVERTISED_PORT",
3640 &aport)) 3640 &aport))
3641 aport = port; 3641 aport = port;
3642 if (aport > 65535) 3642 if (aport > 65535)
3643 { 3643 {
3644 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3644 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3645 "transport-udp", 3645 "transport-udp",
3646 "ADVERTISED_PORT", 3646 "ADVERTISED_PORT",
3647 _ ("must be in [0,65535]")); 3647 _("must be in [0,65535]"));
3648 return NULL; 3648 return NULL;
3649 } 3649 }
3650 3650
3651 if (GNUNET_YES == 3651 if (GNUNET_YES ==
3652 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6")) 3652 GNUNET_CONFIGURATION_get_value_yesno(env->cfg, "nat", "DISABLEV6"))
3653 enable_v6 = GNUNET_NO; 3653 enable_v6 = GNUNET_NO;
3654 else 3654 else
3655 enable_v6 = GNUNET_YES; 3655 enable_v6 = GNUNET_YES;
3656 3656
3657 have_bind4 = GNUNET_NO; 3657 have_bind4 = GNUNET_NO;
3658 memset (&server_addrv4, 0, sizeof (server_addrv4)); 3658 memset(&server_addrv4, 0, sizeof(server_addrv4));
3659 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3659 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg,
3660 "transport-udp", 3660 "transport-udp",
3661 "BINDTO", 3661 "BINDTO",
3662 &bind4_address)) 3662 &bind4_address))
3663 { 3663 {
3664 LOG (GNUNET_ERROR_TYPE_DEBUG, 3664 LOG(GNUNET_ERROR_TYPE_DEBUG,
3665 "Binding UDP plugin to specific address: `%s'\n", 3665 "Binding UDP plugin to specific address: `%s'\n",
3666 bind4_address); 3666 bind4_address);
3667 if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) 3667 if (1 != inet_pton(AF_INET, bind4_address, &server_addrv4.sin_addr))
3668 { 3668 {
3669 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3669 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3670 "transport-udp", 3670 "transport-udp",
3671 "BINDTO", 3671 "BINDTO",
3672 _ ("must be valid IPv4 address")); 3672 _("must be valid IPv4 address"));
3673 GNUNET_free (bind4_address); 3673 GNUNET_free(bind4_address);
3674 return NULL; 3674 return NULL;
3675 }
3676 have_bind4 = GNUNET_YES;
3675 } 3677 }
3676 have_bind4 = GNUNET_YES; 3678 GNUNET_free_non_null(bind4_address);
3677 }
3678 GNUNET_free_non_null (bind4_address);
3679 have_bind6 = GNUNET_NO; 3679 have_bind6 = GNUNET_NO;
3680 memset (&server_addrv6, 0, sizeof (server_addrv6)); 3680 memset(&server_addrv6, 0, sizeof(server_addrv6));
3681 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3681 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg,
3682 "transport-udp", 3682 "transport-udp",
3683 "BINDTO6", 3683 "BINDTO6",
3684 &bind6_address)) 3684 &bind6_address))
3685 { 3685 {
3686 LOG (GNUNET_ERROR_TYPE_DEBUG, 3686 LOG(GNUNET_ERROR_TYPE_DEBUG,
3687 "Binding udp plugin to specific address: `%s'\n", 3687 "Binding udp plugin to specific address: `%s'\n",
3688 bind6_address); 3688 bind6_address);
3689 if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) 3689 if (1 != inet_pton(AF_INET6, bind6_address, &server_addrv6.sin6_addr))
3690 { 3690 {
3691 GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, 3691 GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR,
3692 "transport-udp", 3692 "transport-udp",
3693 "BINDTO6", 3693 "BINDTO6",
3694 _ ("must be valid IPv6 address")); 3694 _("must be valid IPv6 address"));
3695 GNUNET_free (bind6_address); 3695 GNUNET_free(bind6_address);
3696 return NULL; 3696 return NULL;
3697 }
3698 have_bind6 = GNUNET_YES;
3697 } 3699 }
3698 have_bind6 = GNUNET_YES; 3700 GNUNET_free_non_null(bind6_address);
3699 }
3700 GNUNET_free_non_null (bind6_address);
3701 3701
3702 enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3702 enable_broadcasting = GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
3703 "transport-udp", 3703 "transport-udp",
3704 "BROADCAST"); 3704 "BROADCAST");
3705 if (enable_broadcasting == GNUNET_SYSERR) 3705 if (enable_broadcasting == GNUNET_SYSERR)
3706 enable_broadcasting = GNUNET_NO; 3706 enable_broadcasting = GNUNET_NO;
3707 3707
3708 enable_broadcasting_recv = 3708 enable_broadcasting_recv =
3709 GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3709 GNUNET_CONFIGURATION_get_value_yesno(env->cfg,
3710 "transport-udp", 3710 "transport-udp",
3711 "BROADCAST_RECEIVE"); 3711 "BROADCAST_RECEIVE");
3712 if (enable_broadcasting_recv == GNUNET_SYSERR) 3712 if (enable_broadcasting_recv == GNUNET_SYSERR)
3713 enable_broadcasting_recv = GNUNET_YES; 3713 enable_broadcasting_recv = GNUNET_YES;
3714 3714
3715 if (GNUNET_SYSERR == 3715 if (GNUNET_SYSERR ==
3716 GNUNET_CONFIGURATION_get_value_time (env->cfg, 3716 GNUNET_CONFIGURATION_get_value_time(env->cfg,
3717 "transport-udp", 3717 "transport-udp",
3718 "BROADCAST_INTERVAL", 3718 "BROADCAST_INTERVAL",
3719 &interval)) 3719 &interval))
3720 { 3720 {
3721 interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); 3721 interval = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10);
3722 } 3722 }
3723 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, 3723 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg,
3724 "transport-udp", 3724 "transport-udp",
3725 "MAX_BPS", 3725 "MAX_BPS",
3726 &udp_max_bps)) 3726 &udp_max_bps))
3727 { 3727 {
3728 /* 50 MB/s == infinity for practical purposes */ 3728 /* 50 MB/s == infinity for practical purposes */
3729 udp_max_bps = 1024 * 1024 * 50; 3729 udp_max_bps = 1024 * 1024 * 50;
3730 } 3730 }
3731 3731
3732 p = GNUNET_new (struct Plugin); 3732 p = GNUNET_new(struct Plugin);
3733 p->port = port; 3733 p->port = port;
3734 p->aport = aport; 3734 p->aport = aport;
3735 p->broadcast_interval = interval; 3735 p->broadcast_interval = interval;
@@ -3738,33 +3738,33 @@ libgnunet_plugin_transport_udp_init (void *cls)
3738 p->enable_broadcasting = enable_broadcasting; 3738 p->enable_broadcasting = enable_broadcasting;
3739 p->enable_broadcasting_receiving = enable_broadcasting_recv; 3739 p->enable_broadcasting_receiving = enable_broadcasting_recv;
3740 p->env = env; 3740 p->env = env;
3741 p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); 3741 p->sessions = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO);
3742 p->defrag_ctxs = 3742 p->defrag_ctxs =
3743 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 3743 GNUNET_CONTAINER_heap_create(GNUNET_CONTAINER_HEAP_ORDER_MIN);
3744 GNUNET_BANDWIDTH_tracker_init (&p->tracker, 3744 GNUNET_BANDWIDTH_tracker_init(&p->tracker,
3745 NULL, 3745 NULL,
3746 NULL, 3746 NULL,
3747 GNUNET_BANDWIDTH_value_init ( 3747 GNUNET_BANDWIDTH_value_init(
3748 (uint32_t) udp_max_bps), 3748 (uint32_t)udp_max_bps),
3749 30); 3749 30);
3750 res = setup_sockets (p, 3750 res = setup_sockets(p,
3751 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, 3751 (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL,
3752 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); 3752 (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL);
3753 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6))) 3753 if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6)))
3754 { 3754 {
3755 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n")); 3755 LOG(GNUNET_ERROR_TYPE_ERROR, _("Failed to create UDP network sockets\n"));
3756 GNUNET_CONTAINER_multipeermap_destroy (p->sessions); 3756 GNUNET_CONTAINER_multipeermap_destroy(p->sessions);
3757 GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); 3757 GNUNET_CONTAINER_heap_destroy(p->defrag_ctxs);
3758 if (NULL != p->nat) 3758 if (NULL != p->nat)
3759 GNUNET_NAT_unregister (p->nat); 3759 GNUNET_NAT_unregister(p->nat);
3760 GNUNET_free (p); 3760 GNUNET_free(p);
3761 return NULL; 3761 return NULL;
3762 } 3762 }
3763 3763
3764 /* Setup broadcasting and receiving beacons */ 3764 /* Setup broadcasting and receiving beacons */
3765 setup_broadcast (p, &server_addrv6, &server_addrv4); 3765 setup_broadcast(p, &server_addrv6, &server_addrv4);
3766 3766
3767 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 3767 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
3768 api->cls = p; 3768 api->cls = p;
3769 api->disconnect_session = &udp_disconnect_session; 3769 api->disconnect_session = &udp_disconnect_session;
3770 api->query_keepalive_factor = &udp_query_keepalive_factor; 3770 api->query_keepalive_factor = &udp_query_keepalive_factor;
@@ -3794,16 +3794,16 @@ libgnunet_plugin_transport_udp_init (void *cls)
3794 * @return #GNUNET_YES 3794 * @return #GNUNET_YES
3795 */ 3795 */
3796static int 3796static int
3797heap_cleanup_iterator (void *cls, 3797heap_cleanup_iterator(void *cls,
3798 struct GNUNET_CONTAINER_HeapNode *node, 3798 struct GNUNET_CONTAINER_HeapNode *node,
3799 void *element, 3799 void *element,
3800 GNUNET_CONTAINER_HeapCostType cost) 3800 GNUNET_CONTAINER_HeapCostType cost)
3801{ 3801{
3802 struct DefragContext *d_ctx = element; 3802 struct DefragContext *d_ctx = element;
3803 3803
3804 GNUNET_CONTAINER_heap_remove_node (node); 3804 GNUNET_CONTAINER_heap_remove_node(node);
3805 GNUNET_DEFRAGMENT_context_destroy (d_ctx->defrag); 3805 GNUNET_DEFRAGMENT_context_destroy(d_ctx->defrag);
3806 GNUNET_free (d_ctx); 3806 GNUNET_free(d_ctx);
3807 return GNUNET_YES; 3807 return GNUNET_YES;
3808} 3808}
3809 3809
@@ -3816,7 +3816,7 @@ heap_cleanup_iterator (void *cls,
3816 * @return NULL 3816 * @return NULL
3817 */ 3817 */
3818void * 3818void *
3819libgnunet_plugin_transport_udp_done (void *cls) 3819libgnunet_plugin_transport_udp_done(void *cls)
3820{ 3820{
3821 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3821 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3822 struct Plugin *plugin = api->cls; 3822 struct Plugin *plugin = api->cls;
@@ -3824,77 +3824,77 @@ libgnunet_plugin_transport_udp_done (void *cls)
3824 struct UDP_MessageWrapper *udpw; 3824 struct UDP_MessageWrapper *udpw;
3825 3825
3826 if (NULL == plugin) 3826 if (NULL == plugin)
3827 { 3827 {
3828 GNUNET_free (api); 3828 GNUNET_free(api);
3829 return NULL; 3829 return NULL;
3830 } 3830 }
3831 stop_broadcast (plugin); 3831 stop_broadcast(plugin);
3832 if (NULL != plugin->select_task_v4) 3832 if (NULL != plugin->select_task_v4)
3833 { 3833 {
3834 GNUNET_SCHEDULER_cancel (plugin->select_task_v4); 3834 GNUNET_SCHEDULER_cancel(plugin->select_task_v4);
3835 plugin->select_task_v4 = NULL; 3835 plugin->select_task_v4 = NULL;
3836 } 3836 }
3837 if (NULL != plugin->select_task_v6) 3837 if (NULL != plugin->select_task_v6)
3838 { 3838 {
3839 GNUNET_SCHEDULER_cancel (plugin->select_task_v6); 3839 GNUNET_SCHEDULER_cancel(plugin->select_task_v6);
3840 plugin->select_task_v6 = NULL; 3840 plugin->select_task_v6 = NULL;
3841 } 3841 }
3842 if (NULL != plugin->sockv4) 3842 if (NULL != plugin->sockv4)
3843 { 3843 {
3844 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); 3844 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv4));
3845 plugin->sockv4 = NULL; 3845 plugin->sockv4 = NULL;
3846 } 3846 }
3847 if (NULL != plugin->sockv6) 3847 if (NULL != plugin->sockv6)
3848 { 3848 {
3849 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); 3849 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(plugin->sockv6));
3850 plugin->sockv6 = NULL; 3850 plugin->sockv6 = NULL;
3851 } 3851 }
3852 if (NULL != plugin->nat) 3852 if (NULL != plugin->nat)
3853 { 3853 {
3854 GNUNET_NAT_unregister (plugin->nat); 3854 GNUNET_NAT_unregister(plugin->nat);
3855 plugin->nat = NULL; 3855 plugin->nat = NULL;
3856 } 3856 }
3857 if (NULL != plugin->defrag_ctxs) 3857 if (NULL != plugin->defrag_ctxs)
3858 { 3858 {
3859 GNUNET_CONTAINER_heap_iterate (plugin->defrag_ctxs, 3859 GNUNET_CONTAINER_heap_iterate(plugin->defrag_ctxs,
3860 &heap_cleanup_iterator, 3860 &heap_cleanup_iterator,
3861 NULL); 3861 NULL);
3862 GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); 3862 GNUNET_CONTAINER_heap_destroy(plugin->defrag_ctxs);
3863 plugin->defrag_ctxs = NULL; 3863 plugin->defrag_ctxs = NULL;
3864 } 3864 }
3865 while (NULL != (udpw = plugin->ipv4_queue_head)) 3865 while (NULL != (udpw = plugin->ipv4_queue_head))
3866 { 3866 {
3867 dequeue (plugin, udpw); 3867 dequeue(plugin, udpw);
3868 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3868 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3869 GNUNET_free (udpw); 3869 GNUNET_free(udpw);
3870 } 3870 }
3871 while (NULL != (udpw = plugin->ipv6_queue_head)) 3871 while (NULL != (udpw = plugin->ipv6_queue_head))
3872 { 3872 {
3873 dequeue (plugin, udpw); 3873 dequeue(plugin, udpw);
3874 udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); 3874 udpw->qc(udpw->qc_cls, udpw, GNUNET_SYSERR);
3875 GNUNET_free (udpw); 3875 GNUNET_free(udpw);
3876 } 3876 }
3877 GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, 3877 GNUNET_CONTAINER_multipeermap_iterate(plugin->sessions,
3878 &disconnect_and_free_it, 3878 &disconnect_and_free_it,
3879 plugin); 3879 plugin);
3880 GNUNET_CONTAINER_multipeermap_destroy (plugin->sessions); 3880 GNUNET_CONTAINER_multipeermap_destroy(plugin->sessions);
3881 3881
3882 while (NULL != (cur = plugin->ppc_dll_head)) 3882 while (NULL != (cur = plugin->ppc_dll_head))
3883 { 3883 {
3884 GNUNET_break (0); 3884 GNUNET_break(0);
3885 GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, 3885 GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head,
3886 plugin->ppc_dll_tail, 3886 plugin->ppc_dll_tail,
3887 cur); 3887 cur);
3888 GNUNET_RESOLVER_request_cancel (cur->resolver_handle); 3888 GNUNET_RESOLVER_request_cancel(cur->resolver_handle);
3889 if (NULL != cur->timeout_task) 3889 if (NULL != cur->timeout_task)
3890 { 3890 {
3891 GNUNET_SCHEDULER_cancel (cur->timeout_task); 3891 GNUNET_SCHEDULER_cancel(cur->timeout_task);
3892 cur->timeout_task = NULL; 3892 cur->timeout_task = NULL;
3893 } 3893 }
3894 GNUNET_free (cur); 3894 GNUNET_free(cur);
3895 } 3895 }
3896 GNUNET_free (plugin); 3896 GNUNET_free(plugin);
3897 GNUNET_free (api); 3897 GNUNET_free(api);
3898 return NULL; 3898 return NULL;
3899} 3899}
3900 3900
diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h
index cccb3ceb3..6bdc020ff 100644
--- a/src/transport/plugin_transport_udp.h
+++ b/src/transport/plugin_transport_udp.h
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_udp.h 22 * @file 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,8 +60,7 @@ 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{
65 /** 64 /**
66 * Optional options and flags for this address 65 * Optional options and flags for this address
67 */ 66 */
@@ -82,8 +81,7 @@ struct IPv4UdpAddress
82/** 81/**
83 * Network format for IPv6 addresses. 82 * Network format for IPv6 addresses.
84 */ 83 */
85struct IPv6UdpAddress 84struct IPv6UdpAddress {
86{
87 /** 85 /**
88 * Optional options and flags for this address 86 * Optional options and flags for this address
89 */ 87 */
@@ -105,8 +103,7 @@ GNUNET_NETWORK_STRUCT_END
105 * Either an IPv4 or IPv6 UDP address. Note that without a "length", 103 * Either an IPv4 or IPv6 UDP address. Note that without a "length",
106 * one cannot tell which one of the two types this address represents. 104 * one cannot tell which one of the two types this address represents.
107 */ 105 */
108union UdpAddress 106union UdpAddress {
109{
110 /** 107 /**
111 * IPv4 case. 108 * IPv4 case.
112 */ 109 */
@@ -134,9 +131,7 @@ struct PrettyPrinterContext;
134/** 131/**
135 * Encapsulation of all of the state of the plugin. 132 * Encapsulation of all of the state of the plugin.
136 */ 133 */
137struct Plugin 134struct Plugin {
138{
139
140 /** 135 /**
141 * Our environment. 136 * Our environment.
142 */ 137 */
@@ -302,7 +297,6 @@ struct Plugin
302 * Port we advertise on. 297 * Port we advertise on.
303 */ 298 */
304 uint16_t aport; 299 uint16_t aport;
305
306}; 300};
307 301
308 302
@@ -318,9 +312,9 @@ struct Plugin
318 * @return string representing the same address 312 * @return string representing the same address
319 */ 313 */
320const char * 314const char *
321udp_address_to_string (void *cls, 315udp_address_to_string(void *cls,
322 const void *addr, 316 const void *addr,
323 size_t addrlen); 317 size_t addrlen);
324 318
325 319
326/** 320/**
@@ -335,22 +329,22 @@ udp_address_to_string (void *cls,
335 * @param network_type network type of the sender's address 329 * @param network_type network type of the sender's address
336 */ 330 */
337void 331void
338udp_broadcast_receive (struct Plugin *plugin, 332udp_broadcast_receive(struct Plugin *plugin,
339 const char *buf, 333 const char *buf,
340 ssize_t size, 334 ssize_t size,
341 const union UdpAddress *udp_addr, 335 const union UdpAddress *udp_addr,
342 size_t udp_addr_len, 336 size_t udp_addr_len,
343 enum GNUNET_NetworkType network_type); 337 enum GNUNET_NetworkType network_type);
344 338
345 339
346void 340void
347setup_broadcast (struct Plugin *plugin, 341setup_broadcast(struct Plugin *plugin,
348 struct sockaddr_in6 *server_addrv6, 342 struct sockaddr_in6 *server_addrv6,
349 struct sockaddr_in *server_addrv4); 343 struct sockaddr_in *server_addrv4);
350 344
351 345
352void 346void
353stop_broadcast (struct Plugin *plugin); 347stop_broadcast(struct Plugin *plugin);
354 348
355/*#ifndef PLUGIN_TRANSPORT_UDP_H*/ 349/*#ifndef PLUGIN_TRANSPORT_UDP_H*/
356#endif 350#endif
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c
index 0c26aa624..8ef73e3ae 100644
--- a/src/transport/plugin_transport_udp_broadcasting.c
+++ b/src/transport/plugin_transport_udp_broadcasting.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_udp_broadcasting.c 22 * @file 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
@@ -53,29 +53,27 @@
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 unsigned long delay_msecs; 56 unsigned long delay_msecs;
57 unsigned long timeout_msecs; 57 unsigned long timeout_msecs;
58}; 58};
59#endif 59#endif
60/************************************/ 60/************************************/
61 61
62 62
63struct UDP_Beacon_Message 63struct UDP_Beacon_Message {
64{ 64 /**
65 /** 65 * Message header.
66 * Message header. 66 */
67 */
68 struct GNUNET_MessageHeader header; 67 struct GNUNET_MessageHeader header;
69 68
70 /** 69 /**
71 * What is the identity of the sender 70 * What is the identity of the sender
72 */ 71 */
73 struct GNUNET_PeerIdentity sender; 72 struct GNUNET_PeerIdentity sender;
74}; 73};
75 74
76 75
77struct BroadcastAddress 76struct BroadcastAddress {
78{
79 struct BroadcastAddress *next; 77 struct BroadcastAddress *next;
80 78
81 struct BroadcastAddress *prev; 79 struct BroadcastAddress *prev;
@@ -108,8 +106,7 @@ struct BroadcastAddress
108/** 106/**
109 * Client-specific context for #broadcast_mst_cb(). 107 * Client-specific context for #broadcast_mst_cb().
110 */ 108 */
111struct MstContext 109struct MstContext {
112{
113 struct Plugin *plugin; 110 struct Plugin *plugin;
114 111
115 const union UdpAddress *udp_addr; 112 const union UdpAddress *udp_addr;
@@ -132,8 +129,8 @@ struct MstContext
132 * @return #GNUNET_OK (always) 129 * @return #GNUNET_OK (always)
133 */ 130 */
134static int 131static int
135broadcast_mst_cb (void *cls, 132broadcast_mst_cb(void *cls,
136 const struct GNUNET_MessageHeader *message) 133 const struct GNUNET_MessageHeader *message)
137{ 134{
138 struct MstContext *mc = cls; 135 struct MstContext *mc = cls;
139 struct Plugin *plugin = mc->plugin; 136 struct Plugin *plugin = mc->plugin;
@@ -141,32 +138,32 @@ broadcast_mst_cb (void *cls,
141 const struct GNUNET_MessageHeader *hello; 138 const struct GNUNET_MessageHeader *hello;
142 const struct UDP_Beacon_Message *msg; 139 const struct UDP_Beacon_Message *msg;
143 140
144 msg = (const struct UDP_Beacon_Message *) message; 141 msg = (const struct UDP_Beacon_Message *)message;
145 142
146 if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON != 143 if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
147 ntohs (msg->header.type)) 144 ntohs(msg->header.type))
148 return GNUNET_OK; 145 return GNUNET_OK;
149 LOG (GNUNET_ERROR_TYPE_DEBUG, 146 LOG(GNUNET_ERROR_TYPE_DEBUG,
150 "Received beacon with %u bytes from peer `%s' via address `%s'\n", 147 "Received beacon with %u bytes from peer `%s' via address `%s'\n",
151 ntohs (msg->header.size), 148 ntohs(msg->header.size),
152 GNUNET_i2s (&msg->sender), 149 GNUNET_i2s(&msg->sender),
153 udp_address_to_string (NULL, 150 udp_address_to_string(NULL,
154 mc->udp_addr, 151 mc->udp_addr,
155 mc->udp_addr_len)); 152 mc->udp_addr_len));
156 hello = (struct GNUNET_MessageHeader *) &msg[1]; 153 hello = (struct GNUNET_MessageHeader *)&msg[1];
157 address = GNUNET_HELLO_address_allocate (&msg->sender, 154 address = GNUNET_HELLO_address_allocate(&msg->sender,
158 PLUGIN_NAME, 155 PLUGIN_NAME,
159 mc->udp_addr, 156 mc->udp_addr,
160 mc->udp_addr_len, 157 mc->udp_addr_len,
161 GNUNET_HELLO_ADDRESS_INFO_NONE); 158 GNUNET_HELLO_ADDRESS_INFO_NONE);
162 plugin->env->receive (plugin->env->cls, 159 plugin->env->receive(plugin->env->cls,
163 address, 160 address,
164 NULL, 161 NULL,
165 hello); 162 hello);
166 GNUNET_HELLO_address_free (address); 163 GNUNET_HELLO_address_free(address);
167 GNUNET_STATISTICS_update (plugin->env->stats, 164 GNUNET_STATISTICS_update(plugin->env->stats,
168 _("# Multicast HELLO beacons received via UDP"), 165 _("# Multicast HELLO beacons received via UDP"),
169 1, GNUNET_NO); 166 1, GNUNET_NO);
170 return GNUNET_OK; 167 return GNUNET_OK;
171} 168}
172 169
@@ -183,58 +180,59 @@ broadcast_mst_cb (void *cls,
183 * @param network_type network type of the sender's address 180 * @param network_type network type of the sender's address
184 */ 181 */
185void 182void
186udp_broadcast_receive (struct Plugin *plugin, 183udp_broadcast_receive(struct Plugin *plugin,
187 const char *buf, 184 const char *buf,
188 ssize_t size, 185 ssize_t size,
189 const union UdpAddress *udp_addr, 186 const union UdpAddress *udp_addr,
190 size_t udp_addr_len, 187 size_t udp_addr_len,
191 enum GNUNET_NetworkType network_type) 188 enum GNUNET_NetworkType network_type)
192{ 189{
193 struct GNUNET_MessageStreamTokenizer *broadcast_mst; 190 struct GNUNET_MessageStreamTokenizer *broadcast_mst;
194 struct MstContext mc; 191 struct MstContext mc;
195 192
196 broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb, 193 broadcast_mst = GNUNET_MST_create(&broadcast_mst_cb,
197 &mc); 194 &mc);
198 mc.plugin = plugin; 195 mc.plugin = plugin;
199 mc.udp_addr = udp_addr; 196 mc.udp_addr = udp_addr;
200 mc.udp_addr_len = udp_addr_len; 197 mc.udp_addr_len = udp_addr_len;
201 mc.ats_address_network_type = network_type; 198 mc.ats_address_network_type = network_type;
202 GNUNET_MST_from_buffer (broadcast_mst, 199 GNUNET_MST_from_buffer(broadcast_mst,
203 buf, size, 200 buf, size,
204 GNUNET_NO, 201 GNUNET_NO,
205 GNUNET_NO); 202 GNUNET_NO);
206 GNUNET_MST_destroy (broadcast_mst); 203 GNUNET_MST_destroy(broadcast_mst);
207} 204}
208 205
209 206
210static unsigned int 207static unsigned int
211prepare_beacon (struct Plugin *plugin, 208prepare_beacon(struct Plugin *plugin,
212 struct UDP_Beacon_Message *msg) 209 struct UDP_Beacon_Message *msg)
213{ 210{
214 uint16_t hello_size; 211 uint16_t hello_size;
215 uint16_t msg_size; 212 uint16_t msg_size;
216 213
217 const struct GNUNET_MessageHeader *hello; 214 const struct GNUNET_MessageHeader *hello;
218 hello = plugin->env->get_our_hello (); 215
216 hello = plugin->env->get_our_hello();
219 if (NULL == hello) 217 if (NULL == hello)
220 return 0; 218 return 0;
221 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); 219 hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello);
222 msg_size = hello_size + sizeof (struct UDP_Beacon_Message); 220 msg_size = hello_size + sizeof(struct UDP_Beacon_Message);
223 221
224 if (hello_size < (sizeof (struct GNUNET_MessageHeader)) || 222 if (hello_size < (sizeof(struct GNUNET_MessageHeader)) ||
225 (msg_size > (UDP_MTU))) 223 (msg_size > (UDP_MTU)))
226 return 0; 224 return 0;
227 225
228 msg->sender = *(plugin->env->my_identity); 226 msg->sender = *(plugin->env->my_identity);
229 msg->header.size = htons (msg_size); 227 msg->header.size = htons(msg_size);
230 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); 228 msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
231 GNUNET_memcpy (&msg[1], hello, hello_size); 229 GNUNET_memcpy(&msg[1], hello, hello_size);
232 return msg_size; 230 return msg_size;
233} 231}
234 232
235 233
236static void 234static void
237udp_ipv4_broadcast_send (void *cls) 235udp_ipv4_broadcast_send(void *cls)
238{ 236{
239 struct BroadcastAddress *baddr = cls; 237 struct BroadcastAddress *baddr = cls;
240 struct Plugin *plugin = baddr->plugin; 238 struct Plugin *plugin = baddr->plugin;
@@ -244,83 +242,82 @@ udp_ipv4_broadcast_send (void *cls)
244 242
245 baddr->broadcast_task = NULL; 243 baddr->broadcast_task = NULL;
246 244
247 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf); 245 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *)&buf);
248 if (0 != msg_size) 246 if (0 != msg_size)
249 {
250 struct sockaddr_in *addr = (struct sockaddr_in *) baddr->addr;
251
252 addr->sin_port = htons (plugin->port);
253 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size,
254 (const struct sockaddr *) addr,
255 baddr->addrlen);
256 if (sent == GNUNET_SYSERR)
257 { 247 {
258 if ((ENETUNREACH == errno) || (ENETDOWN == errno)) 248 struct sockaddr_in *addr = (struct sockaddr_in *)baddr->addr;
259 { 249
260 /* "Network unreachable" or "Network down" 250 addr->sin_port = htons(plugin->port);
261 * 251 sent = GNUNET_NETWORK_socket_sendto(plugin->sockv4, &buf, msg_size,
262 * This indicates that we just do not have network connectivity 252 (const struct sockaddr *)addr,
263 */ 253 baddr->addrlen);
264 GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING, 254 if (sent == GNUNET_SYSERR)
265 "Network connectivity is down, cannot send beacon!\n"); 255 {
266 } 256 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
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 }
267 else 268 else
268 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); 269 {
269 } 270 LOG(GNUNET_ERROR_TYPE_DEBUG,
270 else 271 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
271 { 272 GNUNET_a2s(baddr->addr, baddr->addrlen));
272 LOG (GNUNET_ERROR_TYPE_DEBUG, 273 }
273 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
274 GNUNET_a2s (baddr->addr, baddr->addrlen));
275 } 274 }
276 }
277 275
278#if LINUX 276#if LINUX
279 /* 277 /*
280 * Cryogenic 278 * Cryogenic
281 */ 279 */
282 if (NULL != baddr->cryogenic_fd) 280 if (NULL != baddr->cryogenic_fd)
283 {
284 baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*0.5;
285 baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*1.5;
286
287 if (ioctl(baddr->cryogenic_fd->fd,
288 PM_SET_DELAY_AND_TIMEOUT,
289 &baddr->cryogenic_times) < 0)
290 { 281 {
291 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl"); 282 baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5;
292 baddr->broadcast_task = 283 baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5;
293 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
294 &udp_ipv4_broadcast_send, baddr);
295 }
296 else
297 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
298 baddr->cryogenic_fd,
299 &udp_ipv4_broadcast_send,
300 baddr);
301 284
302 } 285 if (ioctl(baddr->cryogenic_fd->fd,
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 }
303 else 300 else
304#endif 301#endif
305 baddr->broadcast_task = 302 baddr->broadcast_task =
306 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, 303 GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval,
307 &udp_ipv4_broadcast_send, baddr); 304 &udp_ipv4_broadcast_send, baddr);
308} 305}
309 306
310 307
311static void 308static void
312udp_ipv6_broadcast_send (void *cls) 309udp_ipv6_broadcast_send(void *cls)
313{ 310{
314 struct BroadcastAddress *baddr = cls; 311 struct BroadcastAddress *baddr = cls;
315 struct Plugin *plugin = baddr->plugin; 312 struct Plugin *plugin = baddr->plugin;
316 ssize_t sent; 313 ssize_t sent;
317 uint16_t msg_size; 314 uint16_t msg_size;
318 char buf[65536] GNUNET_ALIGN; 315 char buf[65536] GNUNET_ALIGN;
319 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) baddr->addr; 316 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)baddr->addr;
320 317
321 baddr->broadcast_task = NULL; 318 baddr->broadcast_task = NULL;
322 319
323 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf); 320 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *)&buf);
324 /* Note: unclear if this actually works to limit the multicast to 321 /* Note: unclear if this actually works to limit the multicast to
325 the specified interface as we're not (necessarily) using a 322 the specified interface as we're not (necessarily) using a
326 link-local multicast group and the kernel suggests that the 323 link-local multicast group and the kernel suggests that the
@@ -330,63 +327,63 @@ udp_ipv6_broadcast_send (void *cls)
330 in that case, we might want to revert to only doing this 327 in that case, we might want to revert to only doing this
331 once, and not per interface (hard to test...) */ 328 once, and not per interface (hard to test...) */
332 plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id; 329 plugin->ipv6_multicast_address.sin6_scope_id = s6->sin6_scope_id;
333 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size, 330 sent = GNUNET_NETWORK_socket_sendto(plugin->sockv6, &buf, msg_size,
334 (const struct sockaddr *) 331 (const struct sockaddr *)
335 &plugin->ipv6_multicast_address, 332 &plugin->ipv6_multicast_address,
336 sizeof (struct sockaddr_in6)); 333 sizeof(struct sockaddr_in6));
337 plugin->ipv6_multicast_address.sin6_scope_id = 0; 334 plugin->ipv6_multicast_address.sin6_scope_id = 0;
338 if (sent == GNUNET_SYSERR) 335 if (sent == GNUNET_SYSERR)
339 {
340 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
341 { 336 {
342 /* "Network unreachable" or "Network down" 337 if ((ENETUNREACH == errno) || (ENETDOWN == errno))
343 * 338 {
344 * This indicates that this system is IPv6 enabled, but does not 339 /* "Network unreachable" or "Network down"
345 * have a valid global IPv6 address assigned 340 *
346 */ 341 * This indicates that this system is IPv6 enabled, but does not
347 GNUNET_log (GNUNET_ERROR_TYPE_BULK | GNUNET_ERROR_TYPE_WARNING, 342 * have a valid global IPv6 address assigned
348 "Network connectivity is down, cannot send beacon!\n"); 343 */
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 } 349 }
350 else
351 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
352 }
353 else 350 else
354 { 351 {
355 LOG (GNUNET_ERROR_TYPE_DEBUG, 352 LOG(GNUNET_ERROR_TYPE_DEBUG,
356 "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n", 353 "Sending IPv6 HELLO beacon broadcast with %d bytes to address %s\n",
357 (int) sent, 354 (int)sent,
358 GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address, 355 GNUNET_a2s((const struct sockaddr *)&plugin->ipv6_multicast_address,
359 sizeof (struct sockaddr_in6))); 356 sizeof(struct sockaddr_in6)));
360 } 357 }
361#if LINUX 358#if LINUX
362 /* 359 /*
363 * Cryogenic 360 * Cryogenic
364 */ 361 */
365 if (NULL != baddr->cryogenic_fd) 362 if (NULL != baddr->cryogenic_fd)
366 {
367 baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*0.5;
368 baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us/1000.0)*1.5;
369
370 if (ioctl(baddr->cryogenic_fd->fd,
371 PM_SET_DELAY_AND_TIMEOUT,
372 &baddr->cryogenic_times) < 0)
373 { 363 {
374 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctl"); 364 baddr->cryogenic_times.delay_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 0.5;
375 baddr->broadcast_task = 365 baddr->cryogenic_times.timeout_msecs = (plugin->broadcast_interval.rel_value_us / 1000.0) * 1.5;
376 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, 366
377 &udp_ipv6_broadcast_send, baddr); 367 if (ioctl(baddr->cryogenic_fd->fd,
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);
378 } 381 }
379 else
380 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
381 baddr->cryogenic_fd,
382 &udp_ipv6_broadcast_send,
383 baddr);
384 }
385 else 382 else
386#endif 383#endif
387 baddr->broadcast_task = 384 baddr->broadcast_task =
388 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, 385 GNUNET_SCHEDULER_add_delayed(plugin->broadcast_interval,
389 &udp_ipv6_broadcast_send, baddr); 386 &udp_ipv6_broadcast_send, baddr);
390} 387}
391 388
392 389
@@ -403,12 +400,12 @@ udp_ipv6_broadcast_send (void *cls)
403 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort 400 * @return #GNUNET_OK to continue iteration, #GNUNET_SYSERR to abort
404 */ 401 */
405static int 402static int
406iface_proc (void *cls, 403iface_proc(void *cls,
407 const char *name, 404 const char *name,
408 int isDefault, 405 int isDefault,
409 const struct sockaddr *addr, 406 const struct sockaddr *addr,
410 const struct sockaddr *broadcast_addr, 407 const struct sockaddr *broadcast_addr,
411 const struct sockaddr *netmask, socklen_t addrlen) 408 const struct sockaddr *netmask, socklen_t addrlen)
412{ 409{
413 struct Plugin *plugin = cls; 410 struct Plugin *plugin = cls;
414 struct BroadcastAddress *ba; 411 struct BroadcastAddress *ba;
@@ -416,113 +413,113 @@ iface_proc (void *cls,
416 413
417 if (NULL == addr) 414 if (NULL == addr)
418 return GNUNET_OK; 415 return GNUNET_OK;
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 416 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
420 "address %s for interface %s %p\n ", 417 "address %s for interface %s %p\n ",
421 GNUNET_a2s (addr, addrlen), name, addr); 418 GNUNET_a2s(addr, addrlen), name, addr);
422 if (NULL == broadcast_addr) 419 if (NULL == broadcast_addr)
423 return GNUNET_OK; 420 return GNUNET_OK;
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 421 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
425 "broadcast address %s for interface %s %p\n ", 422 "broadcast address %s for interface %s %p\n ",
426 GNUNET_a2s (broadcast_addr, addrlen), name, broadcast_addr); 423 GNUNET_a2s(broadcast_addr, addrlen), name, broadcast_addr);
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ", 424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "netmask %s for interface %s %p\n ",
428 GNUNET_a2s (netmask, addrlen), name, netmask); 425 GNUNET_a2s(netmask, addrlen), name, netmask);
429 426
430 network = plugin->env->get_address_type (plugin->env->cls, broadcast_addr, addrlen); 427 network = plugin->env->get_address_type(plugin->env->cls, broadcast_addr, addrlen);
431 if (GNUNET_NT_LOOPBACK == network) 428 if (GNUNET_NT_LOOPBACK == network)
432 { 429 {
433 /* Broadcasting on loopback does not make sense */ 430 /* Broadcasting on loopback does not make sense */
434 return GNUNET_YES; 431 return GNUNET_YES;
435 } 432 }
436 433
437 ba = GNUNET_new (struct BroadcastAddress); 434 ba = GNUNET_new(struct BroadcastAddress);
438 ba->plugin = plugin; 435 ba->plugin = plugin;
439 ba->addr = GNUNET_malloc (addrlen); 436 ba->addr = GNUNET_malloc(addrlen);
440 GNUNET_memcpy (ba->addr, broadcast_addr, addrlen); 437 GNUNET_memcpy(ba->addr, broadcast_addr, addrlen);
441 ba->addrlen = addrlen; 438 ba->addrlen = addrlen;
442 439
443 if ( (GNUNET_YES == plugin->enable_ipv4) && 440 if ((GNUNET_YES == plugin->enable_ipv4) &&
444 (NULL != plugin->sockv4) && 441 (NULL != plugin->sockv4) &&
445 (addrlen == sizeof (struct sockaddr_in)) ) 442 (addrlen == sizeof(struct sockaddr_in)))
446 {
447#if LINUX
448 /*
449 * setup Cryogenic FD for ipv4 broadcasting
450 */
451 char *filename;
452
453 GNUNET_asprintf (&filename,
454 "/dev/cryogenic/%s",
455 name);
456 if (0 == ACCESS (name, R_OK))
457 { 443 {
458 ba->cryogenic_fd = 444#if LINUX
459 GNUNET_DISK_file_open (filename, 445 /*
460 GNUNET_DISK_OPEN_WRITE, 446 * setup Cryogenic FD for ipv4 broadcasting
461 GNUNET_DISK_PERM_NONE); 447 */
462 } 448 char *filename;
463 GNUNET_free (filename); 449
450 GNUNET_asprintf(&filename,
451 "/dev/cryogenic/%s",
452 name);
453 if (0 == ACCESS(name, R_OK))
454 {
455 ba->cryogenic_fd =
456 GNUNET_DISK_file_open(filename,
457 GNUNET_DISK_OPEN_WRITE,
458 GNUNET_DISK_PERM_NONE);
459 }
460 GNUNET_free(filename);
464#endif 461#endif
465 ba->broadcast_task = 462 ba->broadcast_task =
466 GNUNET_SCHEDULER_add_now (&udp_ipv4_broadcast_send, ba); 463 GNUNET_SCHEDULER_add_now(&udp_ipv4_broadcast_send, ba);
467 } 464 }
468 if ((GNUNET_YES == plugin->enable_ipv6) && 465 if ((GNUNET_YES == plugin->enable_ipv6) &&
469 (NULL != plugin->sockv6) && 466 (NULL != plugin->sockv6) &&
470 (addrlen == sizeof (struct sockaddr_in6))) 467 (addrlen == sizeof(struct sockaddr_in6)))
471 { 468 {
472 /* Create IPv6 multicast request */ 469 /* Create IPv6 multicast request */
473 struct ipv6_mreq multicastRequest; 470 struct ipv6_mreq multicastRequest;
474 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) broadcast_addr; 471 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *)broadcast_addr;
475 472
476 multicastRequest.ipv6mr_multiaddr = 473 multicastRequest.ipv6mr_multiaddr =
477 plugin->ipv6_multicast_address.sin6_addr; 474 plugin->ipv6_multicast_address.sin6_addr;
478 /* http://tools.ietf.org/html/rfc2553#section-5.2: 475 /* http://tools.ietf.org/html/rfc2553#section-5.2:
479 * 476 *
480 * IPV6_JOIN_GROUP 477 * IPV6_JOIN_GROUP
481 * 478 *
482 * Join a multicast group on a specified local interface. If the 479 * Join a multicast group on a specified local interface. If the
483 * interface index is specified as 0, the kernel chooses the local 480 * interface index is specified as 0, the kernel chooses the local
484 * interface. For example, some kernels look up the multicast 481 * interface. For example, some kernels look up the multicast
485 * group in the normal IPv6 routing table and using the resulting 482 * group in the normal IPv6 routing table and using the resulting
486 * interface; we do this for each interface, so no need to use 483 * interface; we do this for each interface, so no need to use
487 * zero (anymore...). 484 * zero (anymore...).
488 */
489 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
490
491 /* Join the multicast group */
492 if (GNUNET_OK !=
493 GNUNET_NETWORK_socket_setsockopt
494 (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP,
495 &multicastRequest, sizeof (multicastRequest)))
496 {
497 LOG (GNUNET_ERROR_TYPE_WARNING,
498 "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
499 }
500 else
501 {
502#if LINUX
503 /*
504 * setup Cryogenic FD for ipv6 broadcasting
505 */ 485 */
506 char *filename; 486 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
507 487
508 GNUNET_asprintf (&filename, 488 /* Join the multicast group */
509 "/dev/cryogenic/%s", 489 if (GNUNET_OK !=
510 name); 490 GNUNET_NETWORK_socket_setsockopt
511 if (0 == ACCESS (name, R_OK)) 491 (plugin->sockv6, IPPROTO_IPV6, IPV6_JOIN_GROUP,
512 { 492 &multicastRequest, sizeof(multicastRequest)))
513 ba->cryogenic_fd = 493 {
514 GNUNET_DISK_file_open (filename, 494 LOG(GNUNET_ERROR_TYPE_WARNING,
515 GNUNET_DISK_OPEN_WRITE, 495 "Failed to join IPv6 multicast group: IPv6 broadcasting not running\n");
516 GNUNET_DISK_PERM_NONE); 496 }
517 } 497 else
518 GNUNET_free (filename); 498 {
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);
519#endif 516#endif
520 ba->broadcast_task = 517 ba->broadcast_task =
521 GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, ba); 518 GNUNET_SCHEDULER_add_now(&udp_ipv6_broadcast_send, ba);
519 }
522 } 520 }
523 } 521 GNUNET_CONTAINER_DLL_insert(plugin->broadcast_head,
524 GNUNET_CONTAINER_DLL_insert (plugin->broadcast_head, 522 plugin->broadcast_tail, ba);
525 plugin->broadcast_tail, ba);
526 return GNUNET_OK; 523 return GNUNET_OK;
527} 524}
528 525
@@ -535,48 +532,48 @@ iface_proc (void *cls,
535 * @param server_addrv4 532 * @param server_addrv4
536 */ 533 */
537void 534void
538setup_broadcast (struct Plugin *plugin, 535setup_broadcast(struct Plugin *plugin,
539 struct sockaddr_in6 *server_addrv6, 536 struct sockaddr_in6 *server_addrv6,
540 struct sockaddr_in *server_addrv4) 537 struct sockaddr_in *server_addrv4)
541{ 538{
542 if (GNUNET_YES == 539 if (GNUNET_YES ==
543 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 540 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
544 "topology", 541 "topology",
545 "FRIENDS-ONLY")) 542 "FRIENDS-ONLY"))
546 { 543 {
547 LOG (GNUNET_ERROR_TYPE_WARNING, 544 LOG(GNUNET_ERROR_TYPE_WARNING,
548 _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n")); 545 _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
549 return; 546 return;
550 } 547 }
551 548
552 if (GNUNET_YES != plugin->enable_broadcasting) 549 if (GNUNET_YES != plugin->enable_broadcasting)
553 return; /* We do not send, just receive */ 550 return; /* We do not send, just receive */
554 551
555 /* create IPv4 broadcast socket */ 552 /* create IPv4 broadcast socket */
556 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) 553 if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
557 {
558 static int yes = 1;
559
560 if (GNUNET_NETWORK_socket_setsockopt
561 (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
562 sizeof (int)) != GNUNET_OK)
563 { 554 {
564 LOG (GNUNET_ERROR_TYPE_WARNING, 555 static int yes = 1;
565 _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), 556
566 ntohs (server_addrv4->sin_port)); 557 if (GNUNET_NETWORK_socket_setsockopt
558 (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes,
559 sizeof(int)) != GNUNET_OK)
560 {
561 LOG(GNUNET_ERROR_TYPE_WARNING,
562 _("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"),
563 ntohs(server_addrv4->sin_port));
564 }
567 } 565 }
568 }
569 /* create IPv6 multicast socket */ 566 /* create IPv6 multicast socket */
570 if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL)) 567 if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
571 { 568 {
572 memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6)); 569 memset(&plugin->ipv6_multicast_address, 0, sizeof(struct sockaddr_in6));
573 GNUNET_assert (1 == 570 GNUNET_assert(1 ==
574 inet_pton (AF_INET6, "FF05::13B", 571 inet_pton(AF_INET6, "FF05::13B",
575 &plugin->ipv6_multicast_address.sin6_addr)); 572 &plugin->ipv6_multicast_address.sin6_addr));
576 plugin->ipv6_multicast_address.sin6_family = AF_INET6; 573 plugin->ipv6_multicast_address.sin6_family = AF_INET6;
577 plugin->ipv6_multicast_address.sin6_port = htons (plugin->port); 574 plugin->ipv6_multicast_address.sin6_port = htons(plugin->port);
578 } 575 }
579 GNUNET_OS_network_interfaces_list (&iface_proc, plugin); 576 GNUNET_OS_network_interfaces_list(&iface_proc, plugin);
580} 577}
581 578
582 579
@@ -586,55 +583,55 @@ setup_broadcast (struct Plugin *plugin,
586 * @param plugin 583 * @param plugin
587 */ 584 */
588void 585void
589stop_broadcast (struct Plugin *plugin) 586stop_broadcast(struct Plugin *plugin)
590{ 587{
591 if (GNUNET_YES == plugin->enable_broadcasting) 588 if (GNUNET_YES == plugin->enable_broadcasting)
592 {
593 /* Disable broadcasting */
594 while (plugin->broadcast_head != NULL)
595 { 589 {
596 struct BroadcastAddress *p = plugin->broadcast_head; 590 /* Disable broadcasting */
597 591 while (plugin->broadcast_head != NULL)
598 if (p->broadcast_task != NULL)
599 {
600 GNUNET_SCHEDULER_cancel (p->broadcast_task);
601 p->broadcast_task = NULL;
602 }
603 if ((GNUNET_YES == plugin->enable_ipv6) &&
604 (NULL != plugin->sockv6) &&
605 (p->addrlen == sizeof (struct sockaddr_in6)))
606 {
607 /* Create IPv6 multicast request */
608 struct ipv6_mreq multicastRequest;
609 const struct sockaddr_in6 *s6 = (const struct sockaddr_in6 *) p->addr;
610
611 multicastRequest.ipv6mr_multiaddr =
612 plugin->ipv6_multicast_address.sin6_addr;
613 multicastRequest.ipv6mr_interface = s6->sin6_scope_id;
614
615 /* Leave the multicast group */
616 if (GNUNET_OK ==
617 GNUNET_NETWORK_socket_setsockopt
618 (plugin->sockv6, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
619 &multicastRequest, sizeof (multicastRequest)))
620 { 592 {
621 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); 593 struct BroadcastAddress *p = plugin->broadcast_head;
622 } 594
623 else 595 if (p->broadcast_task != NULL)
624 { 596 {
625 LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 multicasting stopped\n"); 597 GNUNET_SCHEDULER_cancel(p->broadcast_task);
626 } 598 p->broadcast_task = NULL;
627 } 599 }
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 }
628 625
629#if LINUX 626#if LINUX
630 GNUNET_DISK_file_close(p->cryogenic_fd); 627 GNUNET_DISK_file_close(p->cryogenic_fd);
631#endif 628#endif
632 GNUNET_CONTAINER_DLL_remove (plugin->broadcast_head, 629 GNUNET_CONTAINER_DLL_remove(plugin->broadcast_head,
633 plugin->broadcast_tail, p); 630 plugin->broadcast_tail, p);
634 GNUNET_free (p->addr); 631 GNUNET_free(p->addr);
635 GNUNET_free (p); 632 GNUNET_free(p);
633 }
636 } 634 }
637 }
638} 635}
639 636
640/* end of plugin_transport_udp_broadcasting.c */ 637/* end of plugin_transport_udp_broadcasting.c */
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 2c408ebf5..5f7b38479 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_unix.c 22 * @file transport/plugin_transport_unix.c
@@ -51,8 +51,7 @@
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{
56 /** 55 /**
57 * No special options. 56 * No special options.
58 */ 57 */
@@ -69,9 +68,9 @@ enum UNIX_ADDRESS_OPTIONS
69 * How long until we give up on transmitting the welcome message? 68 * How long until we give up on transmitting the welcome message?
70 */ 69 */
71#define HOSTNAME_RESOLVE_TIMEOUT \ 70#define HOSTNAME_RESOLVE_TIMEOUT \
72 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 71 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
73 72
74#define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__) 73#define LOG(kind, ...) GNUNET_log_from(kind, "transport-unix", __VA_ARGS__)
75 74
76 75
77GNUNET_NETWORK_STRUCT_BEGIN 76GNUNET_NETWORK_STRUCT_BEGIN
@@ -79,8 +78,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
79/** 78/**
80 * Binary format for an UNIX Domain Socket address in GNUnet. 79 * Binary format for an UNIX Domain Socket address in GNUnet.
81 */ 80 */
82struct UnixAddress 81struct UnixAddress {
83{
84 /** 82 /**
85 * Options to use for the address, in NBO 83 * Options to use for the address, in NBO
86 */ 84 */
@@ -98,8 +96,7 @@ struct UnixAddress
98/** 96/**
99 * UNIX Message-Packet header. 97 * UNIX Message-Packet header.
100 */ 98 */
101struct UNIXMessage 99struct UNIXMessage {
102{
103 /** 100 /**
104 * Message header. 101 * Message header.
105 */ 102 */
@@ -117,8 +114,7 @@ GNUNET_NETWORK_STRUCT_END
117/** 114/**
118 * Information we track for a message awaiting transmission. 115 * Information we track for a message awaiting transmission.
119 */ 116 */
120struct UNIXMessageWrapper 117struct UNIXMessageWrapper {
121{
122 /** 118 /**
123 * We keep messages in a doubly linked list. 119 * We keep messages in a doubly linked list.
124 */ 120 */
@@ -174,9 +170,7 @@ struct UNIXMessageWrapper
174/** 170/**
175 * Handle for a session. 171 * Handle for a session.
176 */ 172 */
177struct GNUNET_ATS_Session 173struct GNUNET_ATS_Session {
178{
179
180 /** 174 /**
181 * Sessions with pending messages (!) are kept in a DLL. 175 * Sessions with pending messages (!) are kept in a DLL.
182 */ 176 */
@@ -236,8 +230,7 @@ struct Plugin;
236/** 230/**
237 * Information we keep for each of our listen sockets. 231 * Information we keep for each of our listen sockets.
238 */ 232 */
239struct UNIX_Sock_Info 233struct UNIX_Sock_Info {
240{
241 /** 234 /**
242 * The network handle 235 * The network handle
243 */ 236 */
@@ -248,9 +241,7 @@ struct UNIX_Sock_Info
248/** 241/**
249 * Encapsulation of all of the state of the plugin. 242 * Encapsulation of all of the state of the plugin.
250 */ 243 */
251struct Plugin 244struct Plugin {
252{
253
254 /** 245 /**
255 * ID of task used to update our addresses when one expires. 246 * ID of task used to update our addresses when one expires.
256 */ 247 */
@@ -332,15 +323,15 @@ struct Plugin
332 * @param state new state of the session 323 * @param state new state of the session
333 */ 324 */
334static void 325static void
335notify_session_monitor (struct Plugin *plugin, 326notify_session_monitor(struct Plugin *plugin,
336 struct GNUNET_ATS_Session *session, 327 struct GNUNET_ATS_Session *session,
337 enum GNUNET_TRANSPORT_SessionState state) 328 enum GNUNET_TRANSPORT_SessionState state)
338{ 329{
339 struct GNUNET_TRANSPORT_SessionInfo info; 330 struct GNUNET_TRANSPORT_SessionInfo info;
340 331
341 if (NULL == plugin->sic) 332 if (NULL == plugin->sic)
342 return; 333 return;
343 memset (&info, 0, sizeof (info)); 334 memset(&info, 0, sizeof(info));
344 info.state = state; 335 info.state = state;
345 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 336 info.is_inbound = GNUNET_SYSERR; /* hard to say */
346 info.num_msg_pending = session->msgs_in_queue; 337 info.num_msg_pending = session->msgs_in_queue;
@@ -350,7 +341,7 @@ notify_session_monitor (struct Plugin *plugin,
350 to receive from others) */ 341 to receive from others) */
351 info.session_timeout = session->timeout; 342 info.session_timeout = session->timeout;
352 info.address = session->address; 343 info.address = session->address;
353 plugin->sic (plugin->sic_cls, session, &info); 344 plugin->sic(plugin->sic_cls, session, &info);
354} 345}
355 346
356 347
@@ -366,50 +357,50 @@ notify_session_monitor (struct Plugin *plugin,
366 * @return string representing the same address 357 * @return string representing the same address
367 */ 358 */
368static const char * 359static const char *
369unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) 360unix_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
370{ 361{
371 static char rbuf[1024]; 362 static char rbuf[1024];
372 struct UnixAddress *ua = (struct UnixAddress *) addr; 363 struct UnixAddress *ua = (struct UnixAddress *)addr;
373 char *addrstr; 364 char *addrstr;
374 size_t addr_str_len; 365 size_t addr_str_len;
375 unsigned int off; 366 unsigned int off;
376 367
377 if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) 368 if ((NULL == addr) || (sizeof(struct UnixAddress) > addrlen))
378 { 369 {
379 GNUNET_break (0); 370 GNUNET_break(0);
380 return NULL; 371 return NULL;
381 } 372 }
382 addrstr = (char *) &ua[1]; 373 addrstr = (char *)&ua[1];
383 addr_str_len = ntohl (ua->addrlen); 374 addr_str_len = ntohl(ua->addrlen);
384 375
385 if (addr_str_len != addrlen - sizeof (struct UnixAddress)) 376 if (addr_str_len != addrlen - sizeof(struct UnixAddress))
386 { 377 {
387 GNUNET_break (0); 378 GNUNET_break(0);
388 return NULL; 379 return NULL;
389 } 380 }
390 if ('\0' != addrstr[addr_str_len - 1]) 381 if ('\0' != addrstr[addr_str_len - 1])
391 { 382 {
392 GNUNET_break (0); 383 GNUNET_break(0);
393 return NULL; 384 return NULL;
394 } 385 }
395 if (strlen (addrstr) + 1 != addr_str_len) 386 if (strlen(addrstr) + 1 != addr_str_len)
396 { 387 {
397 GNUNET_break (0); 388 GNUNET_break(0);
398 return NULL; 389 return NULL;
399 } 390 }
400 391
401 off = 0; 392 off = 0;
402 if ('\0' == addrstr[0]) 393 if ('\0' == addrstr[0])
403 off++; 394 off++;
404 memset (rbuf, 0, sizeof (rbuf)); 395 memset(rbuf, 0, sizeof(rbuf));
405 GNUNET_snprintf (rbuf, 396 GNUNET_snprintf(rbuf,
406 sizeof (rbuf) - 1, 397 sizeof(rbuf) - 1,
407 "%s.%u.%s%.*s", 398 "%s.%u.%s%.*s",
408 PLUGIN_NAME, 399 PLUGIN_NAME,
409 ntohl (ua->options), 400 ntohl(ua->options),
410 (off == 1) ? "@" : "", 401 (off == 1) ? "@" : "",
411 (int) (addr_str_len - off), 402 (int)(addr_str_len - off),
412 &addrstr[off]); 403 &addrstr[off]);
413 return rbuf; 404 return rbuf;
414} 405}
415 406
@@ -424,61 +415,61 @@ unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
424 * @return #GNUNET_OK on success 415 * @return #GNUNET_OK on success
425 */ 416 */
426static int 417static int
427unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session) 418unix_plugin_session_disconnect(void *cls, struct GNUNET_ATS_Session *session)
428{ 419{
429 struct Plugin *plugin = cls; 420 struct Plugin *plugin = cls;
430 struct UNIXMessageWrapper *msgw; 421 struct UNIXMessageWrapper *msgw;
431 struct UNIXMessageWrapper *next; 422 struct UNIXMessageWrapper *next;
432 423
433 LOG (GNUNET_ERROR_TYPE_DEBUG, 424 LOG(GNUNET_ERROR_TYPE_DEBUG,
434 "Disconnecting session for peer `%s' `%s'\n", 425 "Disconnecting session for peer `%s' `%s'\n",
435 GNUNET_i2s (&session->target), 426 GNUNET_i2s(&session->target),
436 unix_plugin_address_to_string (NULL, 427 unix_plugin_address_to_string(NULL,
437 session->address->address, 428 session->address->address,
438 session->address->address_length)); 429 session->address->address_length));
439 plugin->env->session_end (plugin->env->cls, session->address, session); 430 plugin->env->session_end(plugin->env->cls, session->address, session);
440 next = plugin->msg_head; 431 next = plugin->msg_head;
441 while (NULL != next) 432 while (NULL != next)
442 { 433 {
443 msgw = next; 434 msgw = next;
444 next = msgw->next; 435 next = msgw->next;
445 if (msgw->session != session) 436 if (msgw->session != session)
446 continue; 437 continue;
447 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); 438 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw);
448 session->msgs_in_queue--; 439 session->msgs_in_queue--;
449 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 440 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize);
450 session->bytes_in_queue -= msgw->msgsize; 441 session->bytes_in_queue -= msgw->msgsize;
451 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); 442 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize);
452 plugin->bytes_in_queue -= msgw->msgsize; 443 plugin->bytes_in_queue -= msgw->msgsize;
453 if (NULL != msgw->cont) 444 if (NULL != msgw->cont)
454 msgw->cont (msgw->cont_cls, 445 msgw->cont(msgw->cont_cls,
455 &msgw->session->target, 446 &msgw->session->target,
456 GNUNET_SYSERR, 447 GNUNET_SYSERR,
457 msgw->payload, 448 msgw->payload,
458 0); 449 0);
459 GNUNET_free (msgw->msg); 450 GNUNET_free(msgw->msg);
460 GNUNET_free (msgw); 451 GNUNET_free(msgw);
461 } 452 }
462 GNUNET_assert (GNUNET_YES == 453 GNUNET_assert(GNUNET_YES ==
463 GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, 454 GNUNET_CONTAINER_multipeermap_remove(plugin->session_map,
464 &session->target, 455 &session->target,
465 session)); 456 session));
466 GNUNET_STATISTICS_set (plugin->env->stats, 457 GNUNET_STATISTICS_set(plugin->env->stats,
467 "# UNIX sessions active", 458 "# UNIX sessions active",
468 GNUNET_CONTAINER_multipeermap_size ( 459 GNUNET_CONTAINER_multipeermap_size(
469 plugin->session_map), 460 plugin->session_map),
470 GNUNET_NO); 461 GNUNET_NO);
471 if (NULL != session->timeout_task) 462 if (NULL != session->timeout_task)
472 { 463 {
473 GNUNET_SCHEDULER_cancel (session->timeout_task); 464 GNUNET_SCHEDULER_cancel(session->timeout_task);
474 session->timeout_task = NULL; 465 session->timeout_task = NULL;
475 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; 466 session->timeout = GNUNET_TIME_UNIT_ZERO_ABS;
476 } 467 }
477 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE); 468 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_DONE);
478 GNUNET_HELLO_address_free (session->address); 469 GNUNET_HELLO_address_free(session->address);
479 GNUNET_break (0 == session->bytes_in_queue); 470 GNUNET_break(0 == session->bytes_in_queue);
480 GNUNET_break (0 == session->msgs_in_queue); 471 GNUNET_break(0 == session->msgs_in_queue);
481 GNUNET_free (session); 472 GNUNET_free(session);
482 return GNUNET_OK; 473 return GNUNET_OK;
483} 474}
484 475
@@ -489,31 +480,31 @@ unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session)
489 * @param cls the `struct GNUNET_ATS_Session *` to disconnect 480 * @param cls the `struct GNUNET_ATS_Session *` to disconnect
490 */ 481 */
491static void 482static void
492session_timeout (void *cls) 483session_timeout(void *cls)
493{ 484{
494 struct GNUNET_ATS_Session *session = cls; 485 struct GNUNET_ATS_Session *session = cls;
495 struct GNUNET_TIME_Relative left; 486 struct GNUNET_TIME_Relative left;
496 487
497 session->timeout_task = NULL; 488 session->timeout_task = NULL;
498 left = GNUNET_TIME_absolute_get_remaining (session->timeout); 489 left = GNUNET_TIME_absolute_get_remaining(session->timeout);
499 if (0 != left.rel_value_us) 490 if (0 != left.rel_value_us)
500 { 491 {
501 /* not actually our turn yet, but let's at least update 492 /* not actually our turn yet, but let's at least update
502 the monitor, it may think we're about to die ... */ 493 the monitor, it may think we're about to die ... */
503 notify_session_monitor (session->plugin, 494 notify_session_monitor(session->plugin,
504 session, 495 session,
505 GNUNET_TRANSPORT_SS_UPDATE); 496 GNUNET_TRANSPORT_SS_UPDATE);
506 session->timeout_task = 497 session->timeout_task =
507 GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session); 498 GNUNET_SCHEDULER_add_delayed(left, &session_timeout, session);
508 return; 499 return;
509 } 500 }
510 LOG (GNUNET_ERROR_TYPE_DEBUG, 501 LOG(GNUNET_ERROR_TYPE_DEBUG,
511 "Session %p was idle for %s, disconnecting\n", 502 "Session %p was idle for %s, disconnecting\n",
512 session, 503 session,
513 GNUNET_STRINGS_relative_time_to_string ( 504 GNUNET_STRINGS_relative_time_to_string(
514 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 505 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
515 GNUNET_YES)); 506 GNUNET_YES));
516 unix_plugin_session_disconnect (session->plugin, session); 507 unix_plugin_session_disconnect(session->plugin, session);
517} 508}
518 509
519 510
@@ -525,11 +516,11 @@ session_timeout (void *cls)
525 * @param session session for which the timeout should be rescheduled 516 * @param session session for which the timeout should be rescheduled
526 */ 517 */
527static void 518static void
528reschedule_session_timeout (struct GNUNET_ATS_Session *session) 519reschedule_session_timeout(struct GNUNET_ATS_Session *session)
529{ 520{
530 GNUNET_assert (NULL != session->timeout_task); 521 GNUNET_assert(NULL != session->timeout_task);
531 session->timeout = 522 session->timeout =
532 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 523 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
533} 524}
534 525
535 526
@@ -541,22 +532,22 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *session)
541 * @return converted unix path 532 * @return converted unix path
542 */ 533 */
543static struct sockaddr_un * 534static struct sockaddr_un *
544unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) 535unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
545{ 536{
546 struct sockaddr_un *un; 537 struct sockaddr_un *un;
547 size_t slen; 538 size_t slen;
548 539
549 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 540 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */
550 un = GNUNET_new (struct sockaddr_un); 541 un = GNUNET_new(struct sockaddr_un);
551 un->sun_family = AF_UNIX; 542 un->sun_family = AF_UNIX;
552 slen = strlen (unixpath); 543 slen = strlen(unixpath);
553 if (slen >= sizeof (un->sun_path)) 544 if (slen >= sizeof(un->sun_path))
554 slen = sizeof (un->sun_path) - 1; 545 slen = sizeof(un->sun_path) - 1;
555 GNUNET_memcpy (un->sun_path, unixpath, slen); 546 GNUNET_memcpy(un->sun_path, unixpath, slen);
556 un->sun_path[slen] = '\0'; 547 un->sun_path[slen] = '\0';
557 slen = sizeof (struct sockaddr_un); 548 slen = sizeof(struct sockaddr_un);
558#if HAVE_SOCKADDR_UN_SUN_LEN 549#if HAVE_SOCKADDR_UN_SUN_LEN
559 un->sun_len = (u_char) slen; 550 un->sun_len = (u_char)slen;
560#endif 551#endif
561 (*sock_len) = slen; 552 (*sock_len) = slen;
562 return un; 553 return un;
@@ -566,8 +557,7 @@ unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
566/** 557/**
567 * Closure to #lookup_session_it(). 558 * Closure to #lookup_session_it().
568 */ 559 */
569struct LookupCtx 560struct LookupCtx {
570{
571 /** 561 /**
572 * Location to store the session, if found. 562 * Location to store the session, if found.
573 */ 563 */
@@ -589,18 +579,18 @@ struct LookupCtx
589 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success 579 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
590 */ 580 */
591static int 581static int
592lookup_session_it (void *cls, 582lookup_session_it(void *cls,
593 const struct GNUNET_PeerIdentity *key, 583 const struct GNUNET_PeerIdentity *key,
594 void *value) 584 void *value)
595{ 585{
596 struct LookupCtx *lctx = cls; 586 struct LookupCtx *lctx = cls;
597 struct GNUNET_ATS_Session *session = value; 587 struct GNUNET_ATS_Session *session = value;
598 588
599 if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address)) 589 if (0 == GNUNET_HELLO_address_cmp(lctx->address, session->address))
600 { 590 {
601 lctx->res = session; 591 lctx->res = session;
602 return GNUNET_NO; 592 return GNUNET_NO;
603 } 593 }
604 return GNUNET_YES; 594 return GNUNET_YES;
605} 595}
606 596
@@ -613,17 +603,17 @@ lookup_session_it (void *cls,
613 * @return NULL if session was not found 603 * @return NULL if session was not found
614 */ 604 */
615static struct GNUNET_ATS_Session * 605static struct GNUNET_ATS_Session *
616lookup_session (struct Plugin *plugin, 606lookup_session(struct Plugin *plugin,
617 const struct GNUNET_HELLO_Address *address) 607 const struct GNUNET_HELLO_Address *address)
618{ 608{
619 struct LookupCtx lctx; 609 struct LookupCtx lctx;
620 610
621 lctx.address = address; 611 lctx.address = address;
622 lctx.res = NULL; 612 lctx.res = NULL;
623 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, 613 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map,
624 &address->peer, 614 &address->peer,
625 &lookup_session_it, 615 &lookup_session_it,
626 &lctx); 616 &lctx);
627 return lctx.res; 617 return lctx.res;
628} 618}
629 619
@@ -637,7 +627,7 @@ lookup_session (struct Plugin *plugin,
637 * @return keepalive factor 627 * @return keepalive factor
638 */ 628 */
639static unsigned int 629static unsigned int
640unix_plugin_query_keepalive_factor (void *cls) 630unix_plugin_query_keepalive_factor(void *cls)
641{ 631{
642 return 3; 632 return 3;
643} 633}
@@ -665,18 +655,18 @@ unix_plugin_query_keepalive_factor (void *cls)
665 * @return on success the number of bytes written, RETRY for retry, -1 on errors 655 * @return on success the number of bytes written, RETRY for retry, -1 on errors
666 */ 656 */
667static ssize_t 657static ssize_t
668unix_real_send (void *cls, 658unix_real_send(void *cls,
669 struct GNUNET_NETWORK_Handle *send_handle, 659 struct GNUNET_NETWORK_Handle *send_handle,
670 const struct GNUNET_PeerIdentity *target, 660 const struct GNUNET_PeerIdentity *target,
671 const char *msgbuf, 661 const char *msgbuf,
672 size_t msgbuf_size, 662 size_t msgbuf_size,
673 unsigned int priority, 663 unsigned int priority,
674 struct GNUNET_TIME_Absolute timeout, 664 struct GNUNET_TIME_Absolute timeout,
675 const struct UnixAddress *addr, 665 const struct UnixAddress *addr,
676 size_t addrlen, 666 size_t addrlen,
677 size_t payload, 667 size_t payload,
678 GNUNET_TRANSPORT_TransmitContinuation cont, 668 GNUNET_TRANSPORT_TransmitContinuation cont,
679 void *cont_cls) 669 void *cont_cls)
680{ 670{
681 struct Plugin *plugin = cls; 671 struct Plugin *plugin = cls;
682 ssize_t sent; 672 ssize_t sent;
@@ -685,96 +675,96 @@ unix_real_send (void *cls,
685 const char *unixpath; 675 const char *unixpath;
686 676
687 if (NULL == send_handle) 677 if (NULL == send_handle)
688 { 678 {
689 GNUNET_break (0); /* We do not have a send handle */ 679 GNUNET_break(0); /* We do not have a send handle */
690 return GNUNET_SYSERR; 680 return GNUNET_SYSERR;
691 } 681 }
692 if ((NULL == addr) || (0 == addrlen)) 682 if ((NULL == addr) || (0 == addrlen))
693 { 683 {
694 GNUNET_break (0); /* Can never send if we don't have an address */ 684 GNUNET_break(0); /* Can never send if we don't have an address */
695 return GNUNET_SYSERR; 685 return GNUNET_SYSERR;
696 } 686 }
697 687
698 /* Prepare address */ 688 /* Prepare address */
699 unixpath = (const char *) &addr[1]; 689 unixpath = (const char *)&addr[1];
700 if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len))) 690 if (NULL == (un = unix_address_to_sockaddr(unixpath, &un_len)))
701 { 691 {
702 GNUNET_break (0); 692 GNUNET_break(0);
703 return -1; 693 return -1;
704 } 694 }
705 695
706 if ((GNUNET_YES == plugin->is_abstract) && 696 if ((GNUNET_YES == plugin->is_abstract) &&
707 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options)))) 697 (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options))))
708 { 698 {
709 un->sun_path[0] = '\0'; 699 un->sun_path[0] = '\0';
710 } 700 }
711resend: 701resend:
712 /* Send the data */ 702 /* Send the data */
713 sent = GNUNET_NETWORK_socket_sendto (send_handle, 703 sent = GNUNET_NETWORK_socket_sendto(send_handle,
714 msgbuf, 704 msgbuf,
715 msgbuf_size, 705 msgbuf_size,
716 (const struct sockaddr *) un, 706 (const struct sockaddr *)un,
717 un_len); 707 un_len);
718 if (GNUNET_SYSERR == sent) 708 if (GNUNET_SYSERR == sent)
719 {
720 if ((EAGAIN == errno) || (ENOBUFS == errno))
721 { 709 {
722 GNUNET_free (un); 710 if ((EAGAIN == errno) || (ENOBUFS == errno))
723 return RETRY; /* We have to retry later */
724 }
725 if (EMSGSIZE == errno)
726 {
727 socklen_t size = 0;
728 socklen_t len = sizeof (size);
729
730 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
731 send_handle,
732 SOL_SOCKET,
733 SO_SNDBUF,
734 &size,
735 &len);
736 if (size < msgbuf_size)
737 {
738 LOG (GNUNET_ERROR_TYPE_DEBUG,
739 "Trying to increase socket buffer size from %u to %u for message size %u\n",
740 (unsigned int) size,
741 (unsigned int) ((msgbuf_size / 1000) + 2) * 1000,
742 (unsigned int) msgbuf_size);
743 size = ((msgbuf_size / 1000) + 2) * 1000;
744 if (GNUNET_OK ==
745 GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *)
746 send_handle,
747 SOL_SOCKET,
748 SO_SNDBUF,
749 &size,
750 sizeof (size)))
751 goto resend; /* Increased buffer size, retry sending */
752 else
753 { 711 {
754 /* Could not increase buffer size: error, no retry */ 712 GNUNET_free(un);
755 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); 713 return RETRY; /* We have to retry later */
756 GNUNET_free (un); 714 }
757 return GNUNET_SYSERR; 715 if (EMSGSIZE == errno)
716 {
717 socklen_t size = 0;
718 socklen_t len = sizeof(size);
719
720 GNUNET_NETWORK_socket_getsockopt((struct GNUNET_NETWORK_Handle *)
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 } 758 }
759 }
760 else
761 {
762 /* Buffer is bigger than message: error, no retry
763 * This should never happen!*/
764 GNUNET_break (0);
765 GNUNET_free (un);
766 return GNUNET_SYSERR;
767 }
768 } 759 }
769 } 760
770 761 LOG(GNUNET_ERROR_TYPE_DEBUG,
771 LOG (GNUNET_ERROR_TYPE_DEBUG, 762 "UNIX transmitted %u-byte message to %s (%d: %s)\n",
772 "UNIX transmitted %u-byte message to %s (%d: %s)\n", 763 (unsigned int)msgbuf_size,
773 (unsigned int) msgbuf_size, 764 GNUNET_a2s((const struct sockaddr *)un, un_len),
774 GNUNET_a2s ((const struct sockaddr *) un, un_len), 765 (int)sent,
775 (int) sent, 766 (sent < 0) ? strerror(errno) : "ok");
776 (sent < 0) ? strerror (errno) : "ok"); 767 GNUNET_free(un);
777 GNUNET_free (un);
778 return sent; 768 return sent;
779} 769}
780 770
@@ -787,9 +777,9 @@ resend:
787 * @return the network type in HBO or #GNUNET_SYSERR 777 * @return the network type in HBO or #GNUNET_SYSERR
788 */ 778 */
789static enum GNUNET_NetworkType 779static enum GNUNET_NetworkType
790unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) 780unix_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session)
791{ 781{
792 GNUNET_assert (NULL != session); 782 GNUNET_assert(NULL != session);
793 return GNUNET_NT_LOOPBACK; 783 return GNUNET_NT_LOOPBACK;
794} 784}
795 785
@@ -802,9 +792,8 @@ unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
802 * @return the network type 792 * @return the network type
803 */ 793 */
804static enum GNUNET_NetworkType 794static enum GNUNET_NetworkType
805unix_plugin_get_network_for_address (void *cls, 795unix_plugin_get_network_for_address(void *cls,
806 const struct GNUNET_HELLO_Address *address) 796 const struct GNUNET_HELLO_Address *address)
807
808{ 797{
809 return GNUNET_NT_LOOPBACK; 798 return GNUNET_NT_LOOPBACK;
810} 799}
@@ -819,7 +808,7 @@ unix_plugin_get_network_for_address (void *cls,
819 * @return the session or NULL of max connections exceeded 808 * @return the session or NULL of max connections exceeded
820 */ 809 */
821static struct GNUNET_ATS_Session * 810static struct GNUNET_ATS_Session *
822unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) 811unix_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address)
823{ 812{
824 struct Plugin *plugin = cls; 813 struct Plugin *plugin = cls;
825 struct GNUNET_ATS_Session *session; 814 struct GNUNET_ATS_Session *session;
@@ -828,80 +817,80 @@ unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
828 uint32_t addr_str_len; 817 uint32_t addr_str_len;
829 uint32_t addr_option; 818 uint32_t addr_option;
830 819
831 ua = (struct UnixAddress *) address->address; 820 ua = (struct UnixAddress *)address->address;
832 if ((NULL == address->address) || (0 == address->address_length) || 821 if ((NULL == address->address) || (0 == address->address_length) ||
833 (sizeof (struct UnixAddress) > address->address_length)) 822 (sizeof(struct UnixAddress) > address->address_length))
834 { 823 {
835 GNUNET_break (0); 824 GNUNET_break(0);
836 return NULL; 825 return NULL;
837 } 826 }
838 addrstr = (char *) &ua[1]; 827 addrstr = (char *)&ua[1];
839 addr_str_len = ntohl (ua->addrlen); 828 addr_str_len = ntohl(ua->addrlen);
840 addr_option = ntohl (ua->options); 829 addr_option = ntohl(ua->options);
841 830
842 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && 831 if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) &&
843 (GNUNET_NO == plugin->is_abstract)) 832 (GNUNET_NO == plugin->is_abstract))
844 { 833 {
845 return NULL; 834 return NULL;
846 } 835 }
847 836
848 if (addr_str_len != address->address_length - sizeof (struct UnixAddress)) 837 if (addr_str_len != address->address_length - sizeof(struct UnixAddress))
849 { 838 {
850 return NULL; /* This can be a legacy address */ 839 return NULL; /* This can be a legacy address */
851 } 840 }
852 841
853 if ('\0' != addrstr[addr_str_len - 1]) 842 if ('\0' != addrstr[addr_str_len - 1])
854 { 843 {
855 GNUNET_break (0); 844 GNUNET_break(0);
856 return NULL; 845 return NULL;
857 } 846 }
858 if (strlen (addrstr) + 1 != addr_str_len) 847 if (strlen(addrstr) + 1 != addr_str_len)
859 { 848 {
860 GNUNET_break (0); 849 GNUNET_break(0);
861 return NULL; 850 return NULL;
862 } 851 }
863 852
864 /* Check if a session for this address already exists */ 853 /* Check if a session for this address already exists */
865 if (NULL != (session = lookup_session (plugin, address))) 854 if (NULL != (session = lookup_session(plugin, address)))
866 { 855 {
867 LOG (GNUNET_ERROR_TYPE_DEBUG, 856 LOG(GNUNET_ERROR_TYPE_DEBUG,
868 "Found existing session %p for address `%s'\n", 857 "Found existing session %p for address `%s'\n",
869 session, 858 session,
870 unix_plugin_address_to_string (NULL, 859 unix_plugin_address_to_string(NULL,
871 address->address, 860 address->address,
872 address->address_length)); 861 address->address_length));
873 return session; 862 return session;
874 } 863 }
875 864
876 /* create a new session */ 865 /* create a new session */
877 session = GNUNET_new (struct GNUNET_ATS_Session); 866 session = GNUNET_new(struct GNUNET_ATS_Session);
878 session->target = address->peer; 867 session->target = address->peer;
879 session->address = GNUNET_HELLO_address_copy (address); 868 session->address = GNUNET_HELLO_address_copy(address);
880 session->plugin = plugin; 869 session->plugin = plugin;
881 session->timeout = 870 session->timeout =
882 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 871 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
883 session->timeout_task = 872 session->timeout_task =
884 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 873 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
885 &session_timeout, 874 &session_timeout,
886 session); 875 session);
887 LOG (GNUNET_ERROR_TYPE_DEBUG, 876 LOG(GNUNET_ERROR_TYPE_DEBUG,
888 "Creating a new session %p for address `%s'\n", 877 "Creating a new session %p for address `%s'\n",
889 session, 878 session,
890 unix_plugin_address_to_string (NULL, 879 unix_plugin_address_to_string(NULL,
891 address->address, 880 address->address,
892 address->address_length)); 881 address->address_length));
893 (void) GNUNET_CONTAINER_multipeermap_put ( 882 (void)GNUNET_CONTAINER_multipeermap_put(
894 plugin->session_map, 883 plugin->session_map,
895 &address->peer, 884 &address->peer,
896 session, 885 session,
897 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 886 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
898 GNUNET_STATISTICS_set (plugin->env->stats, 887 GNUNET_STATISTICS_set(plugin->env->stats,
899 "# UNIX sessions active", 888 "# UNIX sessions active",
900 GNUNET_CONTAINER_multipeermap_size ( 889 GNUNET_CONTAINER_multipeermap_size(
901 plugin->session_map), 890 plugin->session_map),
902 GNUNET_NO); 891 GNUNET_NO);
903 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); 892 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT);
904 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); 893 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP);
905 return session; 894 return session;
906} 895}
907 896
@@ -916,21 +905,21 @@ unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
916 * @param session which session is being updated 905 * @param session which session is being updated
917 */ 906 */
918static void 907static void
919unix_plugin_update_session_timeout (void *cls, 908unix_plugin_update_session_timeout(void *cls,
920 const struct GNUNET_PeerIdentity *peer, 909 const struct GNUNET_PeerIdentity *peer,
921 struct GNUNET_ATS_Session *session) 910 struct GNUNET_ATS_Session *session)
922{ 911{
923 struct Plugin *plugin = cls; 912 struct Plugin *plugin = cls;
924 913
925 if (GNUNET_OK != 914 if (GNUNET_OK !=
926 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, 915 GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map,
927 &session->target, 916 &session->target,
928 session)) 917 session))
929 { 918 {
930 GNUNET_break (0); 919 GNUNET_break(0);
931 return; 920 return;
932 } 921 }
933 reschedule_session_timeout (session); 922 reschedule_session_timeout(session);
934} 923}
935 924
936 925
@@ -944,47 +933,47 @@ unix_plugin_update_session_timeout (void *cls,
944 * @param ua_len length of the address @a ua 933 * @param ua_len length of the address @a ua
945 */ 934 */
946static void 935static void
947unix_demultiplexer (struct Plugin *plugin, 936unix_demultiplexer(struct Plugin *plugin,
948 struct GNUNET_PeerIdentity *sender, 937 struct GNUNET_PeerIdentity *sender,
949 const struct GNUNET_MessageHeader *currhdr, 938 const struct GNUNET_MessageHeader *currhdr,
950 const struct UnixAddress *ua, 939 const struct UnixAddress *ua,
951 size_t ua_len) 940 size_t ua_len)
952{ 941{
953 struct GNUNET_ATS_Session *session; 942 struct GNUNET_ATS_Session *session;
954 struct GNUNET_HELLO_Address *address; 943 struct GNUNET_HELLO_Address *address;
955 944
956 GNUNET_assert (ua_len >= sizeof (struct UnixAddress)); 945 GNUNET_assert(ua_len >= sizeof(struct UnixAddress));
957 LOG (GNUNET_ERROR_TYPE_DEBUG, 946 LOG(GNUNET_ERROR_TYPE_DEBUG,
958 "Received message from %s\n", 947 "Received message from %s\n",
959 unix_plugin_address_to_string (NULL, ua, ua_len)); 948 unix_plugin_address_to_string(NULL, ua, ua_len));
960 GNUNET_STATISTICS_update (plugin->env->stats, 949 GNUNET_STATISTICS_update(plugin->env->stats,
961 "# bytes received via UNIX", 950 "# bytes received via UNIX",
962 ntohs (currhdr->size), 951 ntohs(currhdr->size),
963 GNUNET_NO); 952 GNUNET_NO);
964 953
965 /* Look for existing session */ 954 /* Look for existing session */
966 address = GNUNET_HELLO_address_allocate ( 955 address = GNUNET_HELLO_address_allocate(
967 sender, 956 sender,
968 PLUGIN_NAME, 957 PLUGIN_NAME,
969 ua, 958 ua,
970 ua_len, 959 ua_len,
971 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ 960 GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */
972 session = lookup_session (plugin, address); 961 session = lookup_session(plugin, address);
973 if (NULL == session) 962 if (NULL == session)
974 { 963 {
975 session = unix_plugin_get_session (plugin, address); 964 session = unix_plugin_get_session(plugin, address);
976 /* Notify transport and ATS about new inbound session */ 965 /* Notify transport and ATS about new inbound session */
977 plugin->env->session_start (NULL, 966 plugin->env->session_start(NULL,
978 session->address, 967 session->address,
979 session, 968 session,
980 GNUNET_NT_LOOPBACK); 969 GNUNET_NT_LOOPBACK);
981 } 970 }
982 else 971 else
983 { 972 {
984 reschedule_session_timeout (session); 973 reschedule_session_timeout(session);
985 } 974 }
986 GNUNET_HELLO_address_free (address); 975 GNUNET_HELLO_address_free(address);
987 plugin->env->receive (plugin->env->cls, session->address, session, currhdr); 976 plugin->env->receive(plugin->env->cls, session->address, session, currhdr);
988} 977}
989 978
990 979
@@ -994,7 +983,7 @@ unix_demultiplexer (struct Plugin *plugin,
994 * @param plugin the plugin 983 * @param plugin the plugin
995 */ 984 */
996static void 985static void
997unix_plugin_do_read (struct Plugin *plugin) 986unix_plugin_do_read(struct Plugin *plugin)
998{ 987{
999 char buf[65536] GNUNET_ALIGN; 988 char buf[65536] GNUNET_ALIGN;
1000 struct UnixAddress *ua; 989 struct UnixAddress *ua;
@@ -1011,71 +1000,71 @@ unix_plugin_do_read (struct Plugin *plugin)
1011 uint16_t csize; 1000 uint16_t csize;
1012 size_t ua_len; 1001 size_t ua_len;
1013 1002
1014 addrlen = sizeof (un); 1003 addrlen = sizeof(un);
1015 memset (&un, 0, sizeof (un)); 1004 memset(&un, 0, sizeof(un));
1016 ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, 1005 ret = GNUNET_NETWORK_socket_recvfrom(plugin->unix_sock.desc,
1017 buf, 1006 buf,
1018 sizeof (buf), 1007 sizeof(buf),
1019 (struct sockaddr *) &un, 1008 (struct sockaddr *)&un,
1020 &addrlen); 1009 &addrlen);
1021 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) 1010 if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS)))
1022 return; 1011 return;
1023 if (GNUNET_SYSERR == ret) 1012 if (GNUNET_SYSERR == ret)
1024 { 1013 {
1025 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 1014 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom");
1026 return; 1015 return;
1027 } 1016 }
1028 else 1017 else
1029 { 1018 {
1030 LOG (GNUNET_ERROR_TYPE_DEBUG, 1019 LOG(GNUNET_ERROR_TYPE_DEBUG,
1031 "Read %d bytes from socket %s\n", 1020 "Read %d bytes from socket %s\n",
1032 (int) ret, 1021 (int)ret,
1033 un.sun_path); 1022 un.sun_path);
1034 } 1023 }
1035 1024
1036 GNUNET_assert (AF_UNIX == (un.sun_family)); 1025 GNUNET_assert(AF_UNIX == (un.sun_family));
1037 is_abstract = GNUNET_NO; 1026 is_abstract = GNUNET_NO;
1038 if ('\0' == un.sun_path[0]) 1027 if ('\0' == un.sun_path[0])
1039 { 1028 {
1040 un.sun_path[0] = '@'; 1029 un.sun_path[0] = '@';
1041 is_abstract = GNUNET_YES; 1030 is_abstract = GNUNET_YES;
1042 } 1031 }
1043 1032
1044 ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; 1033 ua_len = sizeof(struct UnixAddress) + strlen(un.sun_path) + 1;
1045 ua = GNUNET_malloc (ua_len); 1034 ua = GNUNET_malloc(ua_len);
1046 ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1); 1035 ua->addrlen = htonl(strlen(&un.sun_path[0]) + 1);
1047 GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); 1036 GNUNET_memcpy(&ua[1], &un.sun_path[0], strlen(un.sun_path) + 1);
1048 if (is_abstract) 1037 if (is_abstract)
1049 ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); 1038 ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS);
1050 else 1039 else
1051 ua->options = htonl (UNIX_OPTIONS_NONE); 1040 ua->options = htonl(UNIX_OPTIONS_NONE);
1052 1041
1053 msg = (struct UNIXMessage *) buf; 1042 msg = (struct UNIXMessage *)buf;
1054 csize = ntohs (msg->header.size); 1043 csize = ntohs(msg->header.size);
1055 if ((csize < sizeof (struct UNIXMessage)) || (csize > ret)) 1044 if ((csize < sizeof(struct UNIXMessage)) || (csize > ret))
1056 { 1045 {
1057 GNUNET_break_op (0); 1046 GNUNET_break_op(0);
1058 GNUNET_free (ua); 1047 GNUNET_free(ua);
1059 return; 1048 return;
1060 } 1049 }
1061 msgbuf = (char *) &msg[1]; 1050 msgbuf = (char *)&msg[1];
1062 GNUNET_memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); 1051 GNUNET_memcpy(&sender, &msg->sender, sizeof(struct GNUNET_PeerIdentity));
1063 offset = 0; 1052 offset = 0;
1064 tsize = csize - sizeof (struct UNIXMessage); 1053 tsize = csize - sizeof(struct UNIXMessage);
1065 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 1054 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
1066 {
1067 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
1068 csize = ntohs (currhdr->size);
1069 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
1070 (csize > tsize - offset))
1071 { 1055 {
1072 GNUNET_break_op (0); 1056 currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset];
1073 break; 1057 csize = ntohs(currhdr->size);
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;
1074 } 1066 }
1075 unix_demultiplexer (plugin, &sender, currhdr, ua, ua_len); 1067 GNUNET_free(ua);
1076 offset += csize;
1077 }
1078 GNUNET_free (ua);
1079} 1068}
1080 1069
1081 1070
@@ -1085,7 +1074,7 @@ unix_plugin_do_read (struct Plugin *plugin)
1085 * @param plugin handle to the plugin 1074 * @param plugin handle to the plugin
1086 */ 1075 */
1087static void 1076static void
1088unix_plugin_do_write (struct Plugin *plugin) 1077unix_plugin_do_write(struct Plugin *plugin)
1089{ 1078{
1090 ssize_t sent = 0; 1079 ssize_t sent = 0;
1091 struct UNIXMessageWrapper *msgw; 1080 struct UNIXMessageWrapper *msgw;
@@ -1095,108 +1084,108 @@ unix_plugin_do_write (struct Plugin *plugin)
1095 session = NULL; 1084 session = NULL;
1096 did_delete = GNUNET_NO; 1085 did_delete = GNUNET_NO;
1097 while (NULL != (msgw = plugin->msg_head)) 1086 while (NULL != (msgw = plugin->msg_head))
1098 { 1087 {
1099 if (GNUNET_TIME_absolute_get_remaining (msgw->timeout).rel_value_us > 0) 1088 if (GNUNET_TIME_absolute_get_remaining(msgw->timeout).rel_value_us > 0)
1100 break; /* Message is ready for sending */ 1089 break; /* Message is ready for sending */
1101 /* Message has a timeout */ 1090 /* Message has a timeout */
1102 did_delete = GNUNET_YES; 1091 did_delete = GNUNET_YES;
1103 LOG (GNUNET_ERROR_TYPE_DEBUG, 1092 LOG(GNUNET_ERROR_TYPE_DEBUG,
1104 "Timeout for message with %u bytes \n", 1093 "Timeout for message with %u bytes \n",
1105 (unsigned int) msgw->msgsize); 1094 (unsigned int)msgw->msgsize);
1106 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); 1095 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw);
1107 session = msgw->session; 1096 session = msgw->session;
1108 session->msgs_in_queue--; 1097 session->msgs_in_queue--;
1109 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 1098 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize);
1110 session->bytes_in_queue -= msgw->msgsize; 1099 session->bytes_in_queue -= msgw->msgsize;
1111 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); 1100 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize);
1112 plugin->bytes_in_queue -= msgw->msgsize; 1101 plugin->bytes_in_queue -= msgw->msgsize;
1113 GNUNET_STATISTICS_set (plugin->env->stats, 1102 GNUNET_STATISTICS_set(plugin->env->stats,
1114 "# bytes currently in UNIX buffers", 1103 "# bytes currently in UNIX buffers",
1115 plugin->bytes_in_queue, 1104 plugin->bytes_in_queue,
1116 GNUNET_NO); 1105 GNUNET_NO);
1117 GNUNET_STATISTICS_update (plugin->env->stats, 1106 GNUNET_STATISTICS_update(plugin->env->stats,
1118 "# UNIX bytes discarded", 1107 "# UNIX bytes discarded",
1119 msgw->msgsize, 1108 msgw->msgsize,
1120 GNUNET_NO); 1109 GNUNET_NO);
1121 if (NULL != msgw->cont) 1110 if (NULL != msgw->cont)
1122 msgw->cont (msgw->cont_cls, 1111 msgw->cont(msgw->cont_cls,
1123 &msgw->session->target, 1112 &msgw->session->target,
1124 GNUNET_SYSERR, 1113 GNUNET_SYSERR,
1125 msgw->payload, 1114 msgw->payload,
1126 0); 1115 0);
1127 GNUNET_free (msgw->msg); 1116 GNUNET_free(msgw->msg);
1128 GNUNET_free (msgw); 1117 GNUNET_free(msgw);
1129 } 1118 }
1130 if (NULL == msgw) 1119 if (NULL == msgw)
1131 { 1120 {
1132 if (GNUNET_YES == did_delete) 1121 if (GNUNET_YES == did_delete)
1133 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1122 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1134 return; /* Nothing to send at the moment */ 1123 return; /* Nothing to send at the moment */
1135 } 1124 }
1136 session = msgw->session; 1125 session = msgw->session;
1137 sent = unix_real_send (plugin, 1126 sent = unix_real_send(plugin,
1138 plugin->unix_sock.desc, 1127 plugin->unix_sock.desc,
1139 &session->target, 1128 &session->target,
1140 (const char *) msgw->msg, 1129 (const char *)msgw->msg,
1141 msgw->msgsize, 1130 msgw->msgsize,
1142 msgw->priority, 1131 msgw->priority,
1143 msgw->timeout, 1132 msgw->timeout,
1144 msgw->session->address->address, 1133 msgw->session->address->address,
1145 msgw->session->address->address_length, 1134 msgw->session->address->address_length,
1146 msgw->payload, 1135 msgw->payload,
1147 msgw->cont, 1136 msgw->cont,
1148 msgw->cont_cls); 1137 msgw->cont_cls);
1149 if (RETRY == sent) 1138 if (RETRY == sent)
1150 { 1139 {
1151 GNUNET_STATISTICS_update (plugin->env->stats, 1140 GNUNET_STATISTICS_update(plugin->env->stats,
1152 "# UNIX retry attempts", 1141 "# UNIX retry attempts",
1153 1, 1142 1,
1154 GNUNET_NO); 1143 GNUNET_NO);
1155 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1144 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1156 return; 1145 return;
1157 } 1146 }
1158 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); 1147 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw);
1159 session->msgs_in_queue--; 1148 session->msgs_in_queue--;
1160 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 1149 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize);
1161 session->bytes_in_queue -= msgw->msgsize; 1150 session->bytes_in_queue -= msgw->msgsize;
1162 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); 1151 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize);
1163 plugin->bytes_in_queue -= msgw->msgsize; 1152 plugin->bytes_in_queue -= msgw->msgsize;
1164 GNUNET_STATISTICS_set (plugin->env->stats, 1153 GNUNET_STATISTICS_set(plugin->env->stats,
1165 "# bytes currently in UNIX buffers", 1154 "# bytes currently in UNIX buffers",
1166 plugin->bytes_in_queue, 1155 plugin->bytes_in_queue,
1167 GNUNET_NO); 1156 GNUNET_NO);
1168 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1157 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1169 if (GNUNET_SYSERR == sent) 1158 if (GNUNET_SYSERR == sent)
1170 { 1159 {
1171 /* failed and no retry */ 1160 /* failed and no retry */
1172 if (NULL != msgw->cont) 1161 if (NULL != msgw->cont)
1173 msgw->cont (msgw->cont_cls, 1162 msgw->cont(msgw->cont_cls,
1174 &msgw->session->target, 1163 &msgw->session->target,
1175 GNUNET_SYSERR, 1164 GNUNET_SYSERR,
1176 msgw->payload, 1165 msgw->payload,
1177 0); 1166 0);
1178 GNUNET_STATISTICS_update (plugin->env->stats, 1167 GNUNET_STATISTICS_update(plugin->env->stats,
1179 "# UNIX bytes discarded", 1168 "# UNIX bytes discarded",
1180 msgw->msgsize, 1169 msgw->msgsize,
1181 GNUNET_NO); 1170 GNUNET_NO);
1182 GNUNET_free (msgw->msg); 1171 GNUNET_free(msgw->msg);
1183 GNUNET_free (msgw); 1172 GNUNET_free(msgw);
1184 return; 1173 return;
1185 } 1174 }
1186 /* successfully sent bytes */ 1175 /* successfully sent bytes */
1187 GNUNET_break (sent > 0); 1176 GNUNET_break(sent > 0);
1188 GNUNET_STATISTICS_update (plugin->env->stats, 1177 GNUNET_STATISTICS_update(plugin->env->stats,
1189 "# bytes transmitted via UNIX", 1178 "# bytes transmitted via UNIX",
1190 msgw->msgsize, 1179 msgw->msgsize,
1191 GNUNET_NO); 1180 GNUNET_NO);
1192 if (NULL != msgw->cont) 1181 if (NULL != msgw->cont)
1193 msgw->cont (msgw->cont_cls, 1182 msgw->cont(msgw->cont_cls,
1194 &msgw->session->target, 1183 &msgw->session->target,
1195 GNUNET_OK, 1184 GNUNET_OK,
1196 msgw->payload, 1185 msgw->payload,
1197 msgw->msgsize); 1186 msgw->msgsize);
1198 GNUNET_free (msgw->msg); 1187 GNUNET_free(msgw->msg);
1199 GNUNET_free (msgw); 1188 GNUNET_free(msgw);
1200} 1189}
1201 1190
1202 1191
@@ -1207,20 +1196,20 @@ unix_plugin_do_write (struct Plugin *plugin)
1207 * @param cls the plugin handle 1196 * @param cls the plugin handle
1208 */ 1197 */
1209static void 1198static void
1210unix_plugin_select_read (void *cls) 1199unix_plugin_select_read(void *cls)
1211{ 1200{
1212 struct Plugin *plugin = cls; 1201 struct Plugin *plugin = cls;
1213 const struct GNUNET_SCHEDULER_TaskContext *tc; 1202 const struct GNUNET_SCHEDULER_TaskContext *tc;
1214 1203
1215 plugin->read_task = NULL; 1204 plugin->read_task = NULL;
1216 tc = GNUNET_SCHEDULER_get_task_context (); 1205 tc = GNUNET_SCHEDULER_get_task_context();
1217 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1206 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1218 unix_plugin_do_read (plugin); 1207 unix_plugin_do_read(plugin);
1219 plugin->read_task = 1208 plugin->read_task =
1220 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1209 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
1221 plugin->unix_sock.desc, 1210 plugin->unix_sock.desc,
1222 &unix_plugin_select_read, 1211 &unix_plugin_select_read,
1223 plugin); 1212 plugin);
1224} 1213}
1225 1214
1226 1215
@@ -1231,22 +1220,22 @@ unix_plugin_select_read (void *cls)
1231 * @param cls the plugin handle 1220 * @param cls the plugin handle
1232 */ 1221 */
1233static void 1222static void
1234unix_plugin_select_write (void *cls) 1223unix_plugin_select_write(void *cls)
1235{ 1224{
1236 struct Plugin *plugin = cls; 1225 struct Plugin *plugin = cls;
1237 const struct GNUNET_SCHEDULER_TaskContext *tc; 1226 const struct GNUNET_SCHEDULER_TaskContext *tc;
1238 1227
1239 plugin->write_task = NULL; 1228 plugin->write_task = NULL;
1240 tc = GNUNET_SCHEDULER_get_task_context (); 1229 tc = GNUNET_SCHEDULER_get_task_context();
1241 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1230 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1242 unix_plugin_do_write (plugin); 1231 unix_plugin_do_write(plugin);
1243 if (NULL == plugin->msg_head) 1232 if (NULL == plugin->msg_head)
1244 return; /* write queue empty */ 1233 return; /* write queue empty */
1245 plugin->write_task = 1234 plugin->write_task =
1246 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1235 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
1247 plugin->unix_sock.desc, 1236 plugin->unix_sock.desc,
1248 &unix_plugin_select_write, 1237 &unix_plugin_select_write,
1249 plugin); 1238 plugin);
1250} 1239}
1251 1240
1252 1241
@@ -1278,14 +1267,14 @@ unix_plugin_select_write (void *cls)
1278 * and does NOT mean that the message was not transmitted (DV) 1267 * and does NOT mean that the message was not transmitted (DV)
1279 */ 1268 */
1280static ssize_t 1269static ssize_t
1281unix_plugin_send (void *cls, 1270unix_plugin_send(void *cls,
1282 struct GNUNET_ATS_Session *session, 1271 struct GNUNET_ATS_Session *session,
1283 const char *msgbuf, 1272 const char *msgbuf,
1284 size_t msgbuf_size, 1273 size_t msgbuf_size,
1285 unsigned int priority, 1274 unsigned int priority,
1286 struct GNUNET_TIME_Relative to, 1275 struct GNUNET_TIME_Relative to,
1287 GNUNET_TRANSPORT_TransmitContinuation cont, 1276 GNUNET_TRANSPORT_TransmitContinuation cont,
1288 void *cont_cls) 1277 void *cont_cls)
1289{ 1278{
1290 struct Plugin *plugin = cls; 1279 struct Plugin *plugin = cls;
1291 struct UNIXMessageWrapper *wrapper; 1280 struct UNIXMessageWrapper *wrapper;
@@ -1293,60 +1282,60 @@ unix_plugin_send (void *cls,
1293 int ssize; 1282 int ssize;
1294 1283
1295 if (GNUNET_OK != 1284 if (GNUNET_OK !=
1296 GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, 1285 GNUNET_CONTAINER_multipeermap_contains_value(plugin->session_map,
1297 &session->target, 1286 &session->target,
1298 session)) 1287 session))
1299 { 1288 {
1300 LOG (GNUNET_ERROR_TYPE_ERROR, 1289 LOG(GNUNET_ERROR_TYPE_ERROR,
1301 "Invalid session for peer `%s' `%s'\n", 1290 "Invalid session for peer `%s' `%s'\n",
1302 GNUNET_i2s (&session->target), 1291 GNUNET_i2s(&session->target),
1303 unix_plugin_address_to_string (NULL, 1292 unix_plugin_address_to_string(NULL,
1304 session->address->address, 1293 session->address->address,
1305 session->address->address_length)); 1294 session->address->address_length));
1306 GNUNET_break (0); 1295 GNUNET_break(0);
1307 return GNUNET_SYSERR; 1296 return GNUNET_SYSERR;
1308 } 1297 }
1309 LOG (GNUNET_ERROR_TYPE_DEBUG, 1298 LOG(GNUNET_ERROR_TYPE_DEBUG,
1310 "Sending %u bytes with session for peer `%s' `%s'\n", 1299 "Sending %u bytes with session for peer `%s' `%s'\n",
1311 msgbuf_size, 1300 msgbuf_size,
1312 GNUNET_i2s (&session->target), 1301 GNUNET_i2s(&session->target),
1313 unix_plugin_address_to_string (NULL, 1302 unix_plugin_address_to_string(NULL,
1314 session->address->address, 1303 session->address->address,
1315 session->address->address_length)); 1304 session->address->address_length));
1316 ssize = sizeof (struct UNIXMessage) + msgbuf_size; 1305 ssize = sizeof(struct UNIXMessage) + msgbuf_size;
1317 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); 1306 message = GNUNET_malloc(sizeof(struct UNIXMessage) + msgbuf_size);
1318 message->header.size = htons (ssize); 1307 message->header.size = htons(ssize);
1319 message->header.type = htons (0); 1308 message->header.type = htons(0);
1320 GNUNET_memcpy (&message->sender, 1309 GNUNET_memcpy(&message->sender,
1321 plugin->env->my_identity, 1310 plugin->env->my_identity,
1322 sizeof (struct GNUNET_PeerIdentity)); 1311 sizeof(struct GNUNET_PeerIdentity));
1323 GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); 1312 GNUNET_memcpy(&message[1], msgbuf, msgbuf_size);
1324 wrapper = GNUNET_new (struct UNIXMessageWrapper); 1313 wrapper = GNUNET_new(struct UNIXMessageWrapper);
1325 wrapper->msg = message; 1314 wrapper->msg = message;
1326 wrapper->msgsize = ssize; 1315 wrapper->msgsize = ssize;
1327 wrapper->payload = msgbuf_size; 1316 wrapper->payload = msgbuf_size;
1328 wrapper->priority = priority; 1317 wrapper->priority = priority;
1329 wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); 1318 wrapper->timeout = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), to);
1330 wrapper->cont = cont; 1319 wrapper->cont = cont;
1331 wrapper->cont_cls = cont_cls; 1320 wrapper->cont_cls = cont_cls;
1332 wrapper->session = session; 1321 wrapper->session = session;
1333 GNUNET_CONTAINER_DLL_insert_tail (plugin->msg_head, 1322 GNUNET_CONTAINER_DLL_insert_tail(plugin->msg_head,
1334 plugin->msg_tail, 1323 plugin->msg_tail,
1335 wrapper); 1324 wrapper);
1336 plugin->bytes_in_queue += ssize; 1325 plugin->bytes_in_queue += ssize;
1337 session->bytes_in_queue += ssize; 1326 session->bytes_in_queue += ssize;
1338 session->msgs_in_queue++; 1327 session->msgs_in_queue++;
1339 GNUNET_STATISTICS_set (plugin->env->stats, 1328 GNUNET_STATISTICS_set(plugin->env->stats,
1340 "# bytes currently in UNIX buffers", 1329 "# bytes currently in UNIX buffers",
1341 plugin->bytes_in_queue, 1330 plugin->bytes_in_queue,
1342 GNUNET_NO); 1331 GNUNET_NO);
1343 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); 1332 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UPDATE);
1344 if (NULL == plugin->write_task) 1333 if (NULL == plugin->write_task)
1345 plugin->write_task = 1334 plugin->write_task =
1346 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 1335 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
1347 plugin->unix_sock.desc, 1336 plugin->unix_sock.desc,
1348 &unix_plugin_select_write, 1337 &unix_plugin_select_write,
1349 plugin); 1338 plugin);
1350 return ssize; 1339 return ssize;
1351} 1340}
1352 1341
@@ -1358,57 +1347,57 @@ unix_plugin_send (void *cls,
1358 * @return number of sockets created or #GNUNET_SYSERR on error 1347 * @return number of sockets created or #GNUNET_SYSERR on error
1359 */ 1348 */
1360static int 1349static int
1361unix_transport_server_start (void *cls) 1350unix_transport_server_start(void *cls)
1362{ 1351{
1363 struct Plugin *plugin = cls; 1352 struct Plugin *plugin = cls;
1364 struct sockaddr_un *un; 1353 struct sockaddr_un *un;
1365 socklen_t un_len; 1354 socklen_t un_len;
1366 1355
1367 un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len); 1356 un = unix_address_to_sockaddr(plugin->unix_socket_path, &un_len);
1368 if (GNUNET_YES == plugin->is_abstract) 1357 if (GNUNET_YES == plugin->is_abstract)
1369 { 1358 {
1370 plugin->unix_socket_path[0] = '@'; 1359 plugin->unix_socket_path[0] = '@';
1371 un->sun_path[0] = '\0'; 1360 un->sun_path[0] = '\0';
1372 } 1361 }
1373 plugin->unix_sock.desc = 1362 plugin->unix_sock.desc =
1374 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 1363 GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0);
1375 if (NULL == plugin->unix_sock.desc) 1364 if (NULL == plugin->unix_sock.desc)
1376 { 1365 {
1377 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 1366 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
1378 GNUNET_free (un); 1367 GNUNET_free(un);
1379 return GNUNET_SYSERR; 1368 return GNUNET_SYSERR;
1380 } 1369 }
1381 if ('\0' != un->sun_path[0]) 1370 if ('\0' != un->sun_path[0])
1382 {
1383 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))
1384 { 1371 {
1385 LOG (GNUNET_ERROR_TYPE_ERROR, 1372 if (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path))
1386 _ ("Cannot create path to `%s'\n"), 1373 {
1387 un->sun_path); 1374 LOG(GNUNET_ERROR_TYPE_ERROR,
1388 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); 1375 _("Cannot create path to `%s'\n"),
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);
1389 plugin->unix_sock.desc = NULL; 1390 plugin->unix_sock.desc = NULL;
1390 GNUNET_free (un); 1391 GNUNET_free(un);
1391 return GNUNET_SYSERR; 1392 return GNUNET_SYSERR;
1392 } 1393 }
1393 } 1394 LOG(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
1394 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc,
1395 (const struct sockaddr *) un,
1396 un_len))
1397 {
1398 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
1399 LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path);
1400 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
1401 plugin->unix_sock.desc = NULL;
1402 GNUNET_free (un);
1403 return GNUNET_SYSERR;
1404 }
1405 LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path);
1406 plugin->read_task = 1395 plugin->read_task =
1407 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1396 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
1408 plugin->unix_sock.desc, 1397 plugin->unix_sock.desc,
1409 &unix_plugin_select_read, 1398 &unix_plugin_select_read,
1410 plugin); 1399 plugin);
1411 GNUNET_free (un); 1400 GNUNET_free(un);
1412 return 1; 1401 return 1;
1413} 1402}
1414 1403
@@ -1430,7 +1419,7 @@ unix_transport_server_start (void *cls)
1430 * 1419 *
1431 */ 1420 */
1432static int 1421static int
1433unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) 1422unix_plugin_check_address(void *cls, const void *addr, size_t addrlen)
1434{ 1423{
1435 struct Plugin *plugin = cls; 1424 struct Plugin *plugin = cls;
1436 const struct UnixAddress *ua = addr; 1425 const struct UnixAddress *ua = addr;
@@ -1438,25 +1427,25 @@ unix_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1438 size_t addr_str_len; 1427 size_t addr_str_len;
1439 1428
1440 if ((NULL == addr) || (0 == addrlen) || 1429 if ((NULL == addr) || (0 == addrlen) ||
1441 (sizeof (struct UnixAddress) > addrlen)) 1430 (sizeof(struct UnixAddress) > addrlen))
1442 { 1431 {
1443 GNUNET_break (0); 1432 GNUNET_break(0);
1444 return GNUNET_SYSERR; 1433 return GNUNET_SYSERR;
1445 } 1434 }
1446 addrstr = (char *) &ua[1]; 1435 addrstr = (char *)&ua[1];
1447 addr_str_len = ntohl (ua->addrlen); 1436 addr_str_len = ntohl(ua->addrlen);
1448 if ('\0' != addrstr[addr_str_len - 1]) 1437 if ('\0' != addrstr[addr_str_len - 1])
1449 { 1438 {
1450 GNUNET_break (0); 1439 GNUNET_break(0);
1451 return GNUNET_SYSERR; 1440 return GNUNET_SYSERR;
1452 } 1441 }
1453 if (strlen (addrstr) + 1 != addr_str_len) 1442 if (strlen(addrstr) + 1 != addr_str_len)
1454 { 1443 {
1455 GNUNET_break (0); 1444 GNUNET_break(0);
1456 return GNUNET_SYSERR; 1445 return GNUNET_SYSERR;
1457 } 1446 }
1458 1447
1459 if (0 == strcmp (plugin->unix_socket_path, addrstr)) 1448 if (0 == strcmp(plugin->unix_socket_path, addrstr))
1460 return GNUNET_OK; 1449 return GNUNET_OK;
1461 return GNUNET_SYSERR; 1450 return GNUNET_SYSERR;
1462} 1451}
@@ -1477,23 +1466,23 @@ unix_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1477 * @param asc_cls closure for @a asc 1466 * @param asc_cls closure for @a asc
1478 */ 1467 */
1479static void 1468static void
1480unix_plugin_address_pretty_printer (void *cls, 1469unix_plugin_address_pretty_printer(void *cls,
1481 const char *type, 1470 const char *type,
1482 const void *addr, 1471 const void *addr,
1483 size_t addrlen, 1472 size_t addrlen,
1484 int numeric, 1473 int numeric,
1485 struct GNUNET_TIME_Relative timeout, 1474 struct GNUNET_TIME_Relative timeout,
1486 GNUNET_TRANSPORT_AddressStringCallback asc, 1475 GNUNET_TRANSPORT_AddressStringCallback asc,
1487 void *asc_cls) 1476 void *asc_cls)
1488{ 1477{
1489 const char *ret; 1478 const char *ret;
1490 1479
1491 if ((NULL != addr) && (addrlen > 0)) 1480 if ((NULL != addr) && (addrlen > 0))
1492 ret = unix_plugin_address_to_string (NULL, addr, addrlen); 1481 ret = unix_plugin_address_to_string(NULL, addr, addrlen);
1493 else 1482 else
1494 ret = NULL; 1483 ret = NULL;
1495 asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 1484 asc(asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
1496 asc (asc_cls, NULL, GNUNET_OK); 1485 asc(asc_cls, NULL, GNUNET_OK);
1497} 1486}
1498 1487
1499 1488
@@ -1510,11 +1499,11 @@ unix_plugin_address_pretty_printer (void *cls,
1510 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1499 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1511 */ 1500 */
1512static int 1501static int
1513unix_plugin_string_to_address (void *cls, 1502unix_plugin_string_to_address(void *cls,
1514 const char *addr, 1503 const char *addr,
1515 uint16_t addrlen, 1504 uint16_t addrlen,
1516 void **buf, 1505 void **buf,
1517 size_t *added) 1506 size_t *added)
1518{ 1507{
1519 struct UnixAddress *ua; 1508 struct UnixAddress *ua;
1520 char *address; 1509 char *address;
@@ -1529,53 +1518,53 @@ unix_plugin_string_to_address (void *cls,
1529 optionstr = NULL; 1518 optionstr = NULL;
1530 1519
1531 if ((NULL == addr) || (addrlen == 0)) 1520 if ((NULL == addr) || (addrlen == 0))
1532 { 1521 {
1533 GNUNET_break (0); 1522 GNUNET_break(0);
1534 return GNUNET_SYSERR; 1523 return GNUNET_SYSERR;
1535 } 1524 }
1536 if ('\0' != addr[addrlen - 1]) 1525 if ('\0' != addr[addrlen - 1])
1537 { 1526 {
1538 GNUNET_break (0); 1527 GNUNET_break(0);
1539 return GNUNET_SYSERR; 1528 return GNUNET_SYSERR;
1540 } 1529 }
1541 if (strlen (addr) != addrlen - 1) 1530 if (strlen(addr) != addrlen - 1)
1542 { 1531 {
1543 GNUNET_break (0); 1532 GNUNET_break(0);
1544 return GNUNET_SYSERR; 1533 return GNUNET_SYSERR;
1545 } 1534 }
1546 plugin = GNUNET_strdup (addr); 1535 plugin = GNUNET_strdup(addr);
1547 optionstr = strchr (plugin, '.'); 1536 optionstr = strchr(plugin, '.');
1548 if (NULL == optionstr) 1537 if (NULL == optionstr)
1549 { 1538 {
1550 GNUNET_break (0); 1539 GNUNET_break(0);
1551 GNUNET_free (plugin); 1540 GNUNET_free(plugin);
1552 return GNUNET_SYSERR; 1541 return GNUNET_SYSERR;
1553 } 1542 }
1554 optionstr[0] = '\0'; 1543 optionstr[0] = '\0';
1555 optionstr++; 1544 optionstr++;
1556 options = atol (optionstr); 1545 options = atol(optionstr);
1557 address = strchr (optionstr, '.'); 1546 address = strchr(optionstr, '.');
1558 if (NULL == address) 1547 if (NULL == address)
1559 { 1548 {
1560 GNUNET_break (0); 1549 GNUNET_break(0);
1561 GNUNET_free (plugin); 1550 GNUNET_free(plugin);
1562 return GNUNET_SYSERR; 1551 return GNUNET_SYSERR;
1563 } 1552 }
1564 address[0] = '\0'; 1553 address[0] = '\0';
1565 address++; 1554 address++;
1566 if (0 != strcmp (plugin, PLUGIN_NAME)) 1555 if (0 != strcmp(plugin, PLUGIN_NAME))
1567 { 1556 {
1568 GNUNET_break (0); 1557 GNUNET_break(0);
1569 GNUNET_free (plugin); 1558 GNUNET_free(plugin);
1570 return GNUNET_SYSERR; 1559 return GNUNET_SYSERR;
1571 } 1560 }
1572 1561
1573 ua_size = sizeof (struct UnixAddress) + strlen (address) + 1; 1562 ua_size = sizeof(struct UnixAddress) + strlen(address) + 1;
1574 ua = GNUNET_malloc (ua_size); 1563 ua = GNUNET_malloc(ua_size);
1575 ua->options = htonl (options); 1564 ua->options = htonl(options);
1576 ua->addrlen = htonl (strlen (address) + 1); 1565 ua->addrlen = htonl(strlen(address) + 1);
1577 GNUNET_memcpy (&ua[1], address, strlen (address) + 1); 1566 GNUNET_memcpy(&ua[1], address, strlen(address) + 1);
1578 GNUNET_free (plugin); 1567 GNUNET_free(plugin);
1579 1568
1580 (*buf) = ua; 1569 (*buf) = ua;
1581 (*added) = ua_size; 1570 (*added) = ua_size;
@@ -1589,7 +1578,7 @@ unix_plugin_string_to_address (void *cls,
1589 * @param cls the plugin 1578 * @param cls the plugin
1590 */ 1579 */
1591static void 1580static void
1592address_notification (void *cls) 1581address_notification(void *cls)
1593{ 1582{
1594 struct Plugin *plugin = cls; 1583 struct Plugin *plugin = cls;
1595 struct GNUNET_HELLO_Address *address; 1584 struct GNUNET_HELLO_Address *address;
@@ -1597,24 +1586,24 @@ address_notification (void *cls)
1597 struct UnixAddress *ua; 1586 struct UnixAddress *ua;
1598 char *unix_path; 1587 char *unix_path;
1599 1588
1600 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; 1589 len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1;
1601 ua = GNUNET_malloc (len); 1590 ua = GNUNET_malloc(len);
1602 ua->options = htonl (plugin->myoptions); 1591 ua->options = htonl(plugin->myoptions);
1603 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); 1592 ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1);
1604 unix_path = (char *) &ua[1]; 1593 unix_path = (char *)&ua[1];
1605 GNUNET_memcpy (unix_path, 1594 GNUNET_memcpy(unix_path,
1606 plugin->unix_socket_path, 1595 plugin->unix_socket_path,
1607 strlen (plugin->unix_socket_path) + 1); 1596 strlen(plugin->unix_socket_path) + 1);
1608 1597
1609 plugin->address_update_task = NULL; 1598 plugin->address_update_task = NULL;
1610 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1599 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1611 PLUGIN_NAME, 1600 PLUGIN_NAME,
1612 ua, 1601 ua,
1613 len, 1602 len,
1614 GNUNET_HELLO_ADDRESS_INFO_NONE); 1603 GNUNET_HELLO_ADDRESS_INFO_NONE);
1615 plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); 1604 plugin->env->notify_address(plugin->env->cls, GNUNET_YES, address);
1616 GNUNET_free (ua); 1605 GNUNET_free(ua);
1617 GNUNET_free (address); 1606 GNUNET_free(address);
1618} 1607}
1619 1608
1620 1609
@@ -1627,14 +1616,14 @@ address_notification (void *cls)
1627 * @return #GNUNET_YES (always, continue to iterate) 1616 * @return #GNUNET_YES (always, continue to iterate)
1628 */ 1617 */
1629static int 1618static int
1630get_session_delete_it (void *cls, 1619get_session_delete_it(void *cls,
1631 const struct GNUNET_PeerIdentity *key, 1620 const struct GNUNET_PeerIdentity *key,
1632 void *value) 1621 void *value)
1633{ 1622{
1634 struct Plugin *plugin = cls; 1623 struct Plugin *plugin = cls;
1635 struct GNUNET_ATS_Session *session = value; 1624 struct GNUNET_ATS_Session *session = value;
1636 1625
1637 unix_plugin_session_disconnect (plugin, session); 1626 unix_plugin_session_disconnect(plugin, session);
1638 return GNUNET_YES; 1627 return GNUNET_YES;
1639} 1628}
1640 1629
@@ -1647,15 +1636,15 @@ get_session_delete_it (void *cls,
1647 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed 1636 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed
1648 */ 1637 */
1649static void 1638static void
1650unix_plugin_peer_disconnect (void *cls, 1639unix_plugin_peer_disconnect(void *cls,
1651 const struct GNUNET_PeerIdentity *target) 1640 const struct GNUNET_PeerIdentity *target)
1652{ 1641{
1653 struct Plugin *plugin = cls; 1642 struct Plugin *plugin = cls;
1654 1643
1655 GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, 1644 GNUNET_CONTAINER_multipeermap_get_multiple(plugin->session_map,
1656 target, 1645 target,
1657 &get_session_delete_it, 1646 &get_session_delete_it,
1658 plugin); 1647 plugin);
1659} 1648}
1660 1649
1661 1650
@@ -1669,15 +1658,15 @@ unix_plugin_peer_disconnect (void *cls,
1669 * @return #GNUNET_OK (continue to iterate) 1658 * @return #GNUNET_OK (continue to iterate)
1670 */ 1659 */
1671static int 1660static int
1672send_session_info_iter (void *cls, 1661send_session_info_iter(void *cls,
1673 const struct GNUNET_PeerIdentity *peer, 1662 const struct GNUNET_PeerIdentity *peer,
1674 void *value) 1663 void *value)
1675{ 1664{
1676 struct Plugin *plugin = cls; 1665 struct Plugin *plugin = cls;
1677 struct GNUNET_ATS_Session *session = value; 1666 struct GNUNET_ATS_Session *session = value;
1678 1667
1679 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); 1668 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT);
1680 notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); 1669 notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP);
1681 return GNUNET_OK; 1670 return GNUNET_OK;
1682} 1671}
1683 1672
@@ -1695,22 +1684,22 @@ send_session_info_iter (void *cls,
1695 * @param sic_cls closure for @a sic 1684 * @param sic_cls closure for @a sic
1696 */ 1685 */
1697static void 1686static void
1698unix_plugin_setup_monitor (void *cls, 1687unix_plugin_setup_monitor(void *cls,
1699 GNUNET_TRANSPORT_SessionInfoCallback sic, 1688 GNUNET_TRANSPORT_SessionInfoCallback sic,
1700 void *sic_cls) 1689 void *sic_cls)
1701{ 1690{
1702 struct Plugin *plugin = cls; 1691 struct Plugin *plugin = cls;
1703 1692
1704 plugin->sic = sic; 1693 plugin->sic = sic;
1705 plugin->sic_cls = sic_cls; 1694 plugin->sic_cls = sic_cls;
1706 if (NULL != sic) 1695 if (NULL != sic)
1707 { 1696 {
1708 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, 1697 GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map,
1709 &send_session_info_iter, 1698 &send_session_info_iter,
1710 plugin); 1699 plugin);
1711 /* signal end of first iteration */ 1700 /* signal end of first iteration */
1712 sic (sic_cls, NULL, NULL); 1701 sic(sic_cls, NULL, NULL);
1713 } 1702 }
1714} 1703}
1715 1704
1716 1705
@@ -1722,7 +1711,7 @@ unix_plugin_setup_monitor (void *cls,
1722 * @return NULL on error, plugin functions otherwise 1711 * @return NULL on error, plugin functions otherwise
1723 */ 1712 */
1724void * 1713void *
1725libgnunet_plugin_transport_unix_init (void *cls) 1714libgnunet_plugin_transport_unix_init(void *cls)
1726{ 1715{
1727 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 1716 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
1728 struct GNUNET_TRANSPORT_PluginFunctions *api; 1717 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -1730,45 +1719,45 @@ libgnunet_plugin_transport_unix_init (void *cls)
1730 int sockets_created; 1719 int sockets_created;
1731 1720
1732 if (NULL == env->receive) 1721 if (NULL == env->receive)
1733 { 1722 {
1734 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 1723 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
1735 initialze the plugin or the API */ 1724 initialze the plugin or the API */
1736 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 1725 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
1737 api->cls = NULL; 1726 api->cls = NULL;
1738 api->address_pretty_printer = &unix_plugin_address_pretty_printer; 1727 api->address_pretty_printer = &unix_plugin_address_pretty_printer;
1739 api->address_to_string = &unix_plugin_address_to_string; 1728 api->address_to_string = &unix_plugin_address_to_string;
1740 api->string_to_address = &unix_plugin_string_to_address; 1729 api->string_to_address = &unix_plugin_string_to_address;
1741 return api; 1730 return api;
1742 } 1731 }
1743 1732
1744 plugin = GNUNET_new (struct Plugin); 1733 plugin = GNUNET_new(struct Plugin);
1745 if (GNUNET_OK != 1734 if (GNUNET_OK !=
1746 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 1735 GNUNET_CONFIGURATION_get_value_filename(env->cfg,
1747 "transport-unix", 1736 "transport-unix",
1748 "UNIXPATH", 1737 "UNIXPATH",
1749 &plugin->unix_socket_path)) 1738 &plugin->unix_socket_path))
1750 { 1739 {
1751 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 1740 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
1752 "transport-unix", 1741 "transport-unix",
1753 "UNIXPATH"); 1742 "UNIXPATH");
1754 GNUNET_free (plugin); 1743 GNUNET_free(plugin);
1755 return NULL; 1744 return NULL;
1756 } 1745 }
1757 1746
1758 plugin->env = env; 1747 plugin->env = env;
1759 1748
1760 /* Initialize my flags */ 1749 /* Initialize my flags */
1761#ifdef LINUX 1750#ifdef LINUX
1762 plugin->is_abstract = 1751 plugin->is_abstract =
1763 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 1752 GNUNET_CONFIGURATION_get_value_yesno(plugin->env->cfg,
1764 "testing", 1753 "testing",
1765 "USE_ABSTRACT_SOCKETS"); 1754 "USE_ABSTRACT_SOCKETS");
1766#endif 1755#endif
1767 plugin->myoptions = UNIX_OPTIONS_NONE; 1756 plugin->myoptions = UNIX_OPTIONS_NONE;
1768 if (GNUNET_YES == plugin->is_abstract) 1757 if (GNUNET_YES == plugin->is_abstract)
1769 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS; 1758 plugin->myoptions = UNIX_OPTIONS_USE_ABSTRACT_SOCKETS;
1770 1759
1771 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 1760 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
1772 api->cls = plugin; 1761 api->cls = plugin;
1773 api->get_session = &unix_plugin_get_session; 1762 api->get_session = &unix_plugin_get_session;
1774 api->send = &unix_plugin_send; 1763 api->send = &unix_plugin_send;
@@ -1783,18 +1772,18 @@ libgnunet_plugin_transport_unix_init (void *cls)
1783 api->get_network_for_address = &unix_plugin_get_network_for_address; 1772 api->get_network_for_address = &unix_plugin_get_network_for_address;
1784 api->update_session_timeout = &unix_plugin_update_session_timeout; 1773 api->update_session_timeout = &unix_plugin_update_session_timeout;
1785 api->setup_monitor = &unix_plugin_setup_monitor; 1774 api->setup_monitor = &unix_plugin_setup_monitor;
1786 sockets_created = unix_transport_server_start (plugin); 1775 sockets_created = unix_transport_server_start(plugin);
1787 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) 1776 if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created))
1788 { 1777 {
1789 LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n")); 1778 LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX listen socket\n"));
1790 GNUNET_free (api); 1779 GNUNET_free(api);
1791 GNUNET_free (plugin->unix_socket_path); 1780 GNUNET_free(plugin->unix_socket_path);
1792 GNUNET_free (plugin); 1781 GNUNET_free(plugin);
1793 return NULL; 1782 return NULL;
1794 } 1783 }
1795 plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 1784 plugin->session_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
1796 plugin->address_update_task = 1785 plugin->address_update_task =
1797 GNUNET_SCHEDULER_add_now (&address_notification, plugin); 1786 GNUNET_SCHEDULER_add_now(&address_notification, plugin);
1798 return api; 1787 return api;
1799} 1788}
1800 1789
@@ -1806,7 +1795,7 @@ libgnunet_plugin_transport_unix_init (void *cls)
1806 * @return NULL (always) 1795 * @return NULL (always)
1807 */ 1796 */
1808void * 1797void *
1809libgnunet_plugin_transport_unix_done (void *cls) 1798libgnunet_plugin_transport_unix_done(void *cls)
1810{ 1799{
1811 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 1800 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
1812 struct Plugin *plugin = api->cls; 1801 struct Plugin *plugin = api->cls;
@@ -1817,75 +1806,75 @@ libgnunet_plugin_transport_unix_done (void *cls)
1817 struct GNUNET_ATS_Session *session; 1806 struct GNUNET_ATS_Session *session;
1818 1807
1819 if (NULL == plugin) 1808 if (NULL == plugin)
1820 { 1809 {
1821 GNUNET_free (api); 1810 GNUNET_free(api);
1822 return NULL; 1811 return NULL;
1823 } 1812 }
1824 len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; 1813 len = sizeof(struct UnixAddress) + strlen(plugin->unix_socket_path) + 1;
1825 ua = GNUNET_malloc (len); 1814 ua = GNUNET_malloc(len);
1826 ua->options = htonl (plugin->myoptions); 1815 ua->options = htonl(plugin->myoptions);
1827 ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); 1816 ua->addrlen = htonl(strlen(plugin->unix_socket_path) + 1);
1828 GNUNET_memcpy (&ua[1], 1817 GNUNET_memcpy(&ua[1],
1829 plugin->unix_socket_path, 1818 plugin->unix_socket_path,
1830 strlen (plugin->unix_socket_path) + 1); 1819 strlen(plugin->unix_socket_path) + 1);
1831 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1820 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1832 PLUGIN_NAME, 1821 PLUGIN_NAME,
1833 ua, 1822 ua,
1834 len, 1823 len,
1835 GNUNET_HELLO_ADDRESS_INFO_NONE); 1824 GNUNET_HELLO_ADDRESS_INFO_NONE);
1836 plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); 1825 plugin->env->notify_address(plugin->env->cls, GNUNET_NO, address);
1837 1826
1838 GNUNET_free (address); 1827 GNUNET_free(address);
1839 GNUNET_free (ua); 1828 GNUNET_free(ua);
1840 1829
1841 while (NULL != (msgw = plugin->msg_head)) 1830 while (NULL != (msgw = plugin->msg_head))
1842 { 1831 {
1843 GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); 1832 GNUNET_CONTAINER_DLL_remove(plugin->msg_head, plugin->msg_tail, msgw);
1844 session = msgw->session; 1833 session = msgw->session;
1845 session->msgs_in_queue--; 1834 session->msgs_in_queue--;
1846 GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); 1835 GNUNET_assert(session->bytes_in_queue >= msgw->msgsize);
1847 session->bytes_in_queue -= msgw->msgsize; 1836 session->bytes_in_queue -= msgw->msgsize;
1848 GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); 1837 GNUNET_assert(plugin->bytes_in_queue >= msgw->msgsize);
1849 plugin->bytes_in_queue -= msgw->msgsize; 1838 plugin->bytes_in_queue -= msgw->msgsize;
1850 if (NULL != msgw->cont) 1839 if (NULL != msgw->cont)
1851 msgw->cont (msgw->cont_cls, 1840 msgw->cont(msgw->cont_cls,
1852 &msgw->session->target, 1841 &msgw->session->target,
1853 GNUNET_SYSERR, 1842 GNUNET_SYSERR,
1854 msgw->payload, 1843 msgw->payload,
1855 0); 1844 0);
1856 GNUNET_free (msgw->msg); 1845 GNUNET_free(msgw->msg);
1857 GNUNET_free (msgw); 1846 GNUNET_free(msgw);
1858 } 1847 }
1859 1848
1860 if (NULL != plugin->read_task) 1849 if (NULL != plugin->read_task)
1861 { 1850 {
1862 GNUNET_SCHEDULER_cancel (plugin->read_task); 1851 GNUNET_SCHEDULER_cancel(plugin->read_task);
1863 plugin->read_task = NULL; 1852 plugin->read_task = NULL;
1864 } 1853 }
1865 if (NULL != plugin->write_task) 1854 if (NULL != plugin->write_task)
1866 { 1855 {
1867 GNUNET_SCHEDULER_cancel (plugin->write_task); 1856 GNUNET_SCHEDULER_cancel(plugin->write_task);
1868 plugin->write_task = NULL; 1857 plugin->write_task = NULL;
1869 } 1858 }
1870 if (NULL != plugin->address_update_task) 1859 if (NULL != plugin->address_update_task)
1871 { 1860 {
1872 GNUNET_SCHEDULER_cancel (plugin->address_update_task); 1861 GNUNET_SCHEDULER_cancel(plugin->address_update_task);
1873 plugin->address_update_task = NULL; 1862 plugin->address_update_task = NULL;
1874 } 1863 }
1875 if (NULL != plugin->unix_sock.desc) 1864 if (NULL != plugin->unix_sock.desc)
1876 { 1865 {
1877 GNUNET_break (GNUNET_OK == 1866 GNUNET_break(GNUNET_OK ==
1878 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc)); 1867 GNUNET_NETWORK_socket_close(plugin->unix_sock.desc));
1879 plugin->unix_sock.desc = NULL; 1868 plugin->unix_sock.desc = NULL;
1880 } 1869 }
1881 GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, 1870 GNUNET_CONTAINER_multipeermap_iterate(plugin->session_map,
1882 &get_session_delete_it, 1871 &get_session_delete_it,
1883 plugin); 1872 plugin);
1884 GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); 1873 GNUNET_CONTAINER_multipeermap_destroy(plugin->session_map);
1885 GNUNET_break (0 == plugin->bytes_in_queue); 1874 GNUNET_break(0 == plugin->bytes_in_queue);
1886 GNUNET_free (plugin->unix_socket_path); 1875 GNUNET_free(plugin->unix_socket_path);
1887 GNUNET_free (plugin); 1876 GNUNET_free(plugin);
1888 GNUNET_free (api); 1877 GNUNET_free(api);
1889 return NULL; 1878 return NULL;
1890} 1879}
1891 1880
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index e1a93bf88..a6d44ecb5 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010-2014 GNUnet e.V. 3 Copyright (C) 2010-2014 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/plugin_transport_wlan.c 22 * @file transport/plugin_transport_wlan.c
@@ -47,20 +47,20 @@
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(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2)
57 57
58/** 58/**
59 * We reduce the frequence of HELLO beacons in relation to 59 * We reduce the frequence of HELLO beacons in relation to
60 * the number of MAC addresses currently visible to us. 60 * the number of MAC addresses currently visible to us.
61 * This is the multiplication factor. 61 * This is the multiplication factor.
62 */ 62 */
63#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) 63#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2)
64 64
65 65
66/* end case wlan */ 66/* end case wlan */
@@ -74,12 +74,12 @@
74#define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy" 74#define DUMMY_HELPER_NAME "gnunet-helper-transport-wlan-dummy"
75#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_bluetooth_init 75#define LIBGNUNET_PLUGIN_TRANSPORT_INIT libgnunet_plugin_transport_bluetooth_init
76#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_bluetooth_done 76#define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_bluetooth_done
77#define LOG(kind,...) GNUNET_log_from (kind, "transport-bluetooth",__VA_ARGS__) 77#define LOG(kind, ...) GNUNET_log_from(kind, "transport-bluetooth", __VA_ARGS__)
78 78
79/** 79/**
80 * time out of a mac endpoint 80 * time out of a mac endpoint
81 */ 81 */
82#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60) 82#define MACENDPOINT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 60)
83 83
84 84
85/** 85/**
@@ -87,7 +87,7 @@
87 * the number of MAC addresses currently visible to us. 87 * the number of MAC addresses currently visible to us.
88 * This is the multiplication factor. 88 * This is the multiplication factor.
89 */ 89 */
90#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 90#define HELLO_BEACON_SCALING_FACTOR GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
91 91
92/* end case bluetooth */ 92/* end case bluetooth */
93#else 93#else
@@ -154,9 +154,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
154 * the CRC and then tokenize the payload and pass it to the 154 * the CRC and then tokenize the payload and pass it to the
155 * 'receive' callback. 155 * 'receive' callback.
156 */ 156 */
157struct WlanHeader 157struct WlanHeader {
158{
159
160 /** 158 /**
161 * Message type is #GNUNET_MESSAGE_TYPE_WLAN_DATA. 159 * Message type is #GNUNET_MESSAGE_TYPE_WLAN_DATA.
162 */ 160 */
@@ -179,15 +177,13 @@ struct WlanHeader
179 177
180 /* followed by payload, possibly including 178 /* followed by payload, possibly including
181 multiple messages! */ 179 multiple messages! */
182
183}; 180};
184 181
185 182
186/** 183/**
187 * Address format for WLAN. 184 * Address format for WLAN.
188 */ 185 */
189struct WlanAddress 186struct WlanAddress {
190{
191 /** 187 /**
192 * Options set for the WLAN, in NBO. 188 * Options set for the WLAN, in NBO.
193 */ 189 */
@@ -207,8 +203,7 @@ GNUNET_NETWORK_STRUCT_END
207 * Information kept for each message that is yet to be fragmented and 203 * Information kept for each message that is yet to be fragmented and
208 * transmitted. 204 * transmitted.
209 */ 205 */
210struct PendingMessage 206struct PendingMessage {
211{
212 /** 207 /**
213 * next entry in the DLL 208 * next entry in the DLL
214 */ 209 */
@@ -240,15 +235,13 @@ struct PendingMessage
240 * Timeout task (for this message). 235 * Timeout task (for this message).
241 */ 236 */
242 struct GNUNET_SCHEDULER_Task * timeout_task; 237 struct GNUNET_SCHEDULER_Task * timeout_task;
243
244}; 238};
245 239
246 240
247/** 241/**
248 * Session handle for connections with other peers. 242 * Session handle for connections with other peers.
249 */ 243 */
250struct GNUNET_ATS_Session 244struct GNUNET_ATS_Session {
251{
252 /** 245 /**
253 * To whom are we talking to (set to our identity 246 * To whom are we talking to (set to our identity
254 * if we are still waiting for the welcome message) 247 * if we are still waiting for the welcome message)
@@ -286,16 +279,13 @@ struct GNUNET_ATS_Session
286 * Timeout task (for the session). 279 * Timeout task (for the session).
287 */ 280 */
288 struct GNUNET_SCHEDULER_Task * timeout_task; 281 struct GNUNET_SCHEDULER_Task * timeout_task;
289
290}; 282};
291 283
292 284
293/** 285/**
294 * Struct for messages that are being fragmented in a MAC's transmission queue. 286 * Struct for messages that are being fragmented in a MAC's transmission queue.
295 */ 287 */
296struct FragmentMessage 288struct FragmentMessage {
297{
298
299 /** 289 /**
300 * This is a doubly-linked list. 290 * This is a doubly-linked list.
301 */ 291 */
@@ -362,16 +352,13 @@ struct FragmentMessage
362 * Number of bytes used to transmit message 352 * Number of bytes used to transmit message
363 */ 353 */
364 size_t size_on_wire; 354 size_t size_on_wire;
365
366}; 355};
367 356
368 357
369/** 358/**
370 * Struct to represent one network card connection 359 * Struct to represent one network card connection
371 */ 360 */
372struct MacEndpoint 361struct MacEndpoint {
373{
374
375 /** 362 /**
376 * We keep all MACs in a DLL in the plugin. 363 * We keep all MACs in a DLL in the plugin.
377 */ 364 */
@@ -456,15 +443,13 @@ struct MacEndpoint
456 * Antenna we should use for this MAC 443 * Antenna we should use for this MAC
457 */ 444 */
458 uint8_t antenna; 445 uint8_t antenna;
459
460}; 446};
461 447
462 448
463/** 449/**
464 * Encapsulation of all of the state of the plugin. 450 * Encapsulation of all of the state of the plugin.
465 */ 451 */
466struct Plugin 452struct Plugin {
467{
468 /** 453 /**
469 * Our environment. 454 * Our environment.
470 */ 455 */
@@ -551,7 +536,6 @@ struct Plugin
551 * Options for addresses 536 * Options for addresses
552 */ 537 */
553 uint32_t options; 538 uint32_t options;
554
555}; 539};
556 540
557 541
@@ -560,8 +544,7 @@ struct Plugin
560 * the session or the MAC endpoint associated with the 544 * the session or the MAC endpoint associated with the
561 * message (or both). 545 * message (or both).
562 */ 546 */
563struct MacAndSession 547struct MacAndSession {
564{
565 /** 548 /**
566 * NULL if the identity of the other peer is not known. 549 * NULL if the identity of the other peer is not known.
567 */ 550 */
@@ -583,16 +566,16 @@ struct MacAndSession
583 * this function 566 * this function
584 */ 567 */
585static const char * 568static const char *
586mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac) 569mac_to_string(const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
587{ 570{
588 static char macstr[20]; 571 static char macstr[20];
589 572
590 GNUNET_snprintf (macstr, 573 GNUNET_snprintf(macstr,
591 sizeof (macstr), 574 sizeof(macstr),
592 "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 575 "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
593 mac->mac[0], mac->mac[1], 576 mac->mac[0], mac->mac[1],
594 mac->mac[2], mac->mac[3], 577 mac->mac[2], mac->mac[3],
595 mac->mac[4], mac->mac[5]); 578 mac->mac[4], mac->mac[5]);
596 return macstr; 579 return macstr;
597} 580}
598 581
@@ -609,25 +592,25 @@ mac_to_string (const struct GNUNET_TRANSPORT_WLAN_MacAddress * mac)
609 * @return string representing the same address 592 * @return string representing the same address
610 */ 593 */
611static const char * 594static const char *
612wlan_plugin_address_to_string (void *cls, 595wlan_plugin_address_to_string(void *cls,
613 const void *addr, 596 const void *addr,
614 size_t addrlen) 597 size_t addrlen)
615{ 598{
616 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac; 599 const struct GNUNET_TRANSPORT_WLAN_MacAddress *mac;
617 static char macstr[36]; 600 static char macstr[36];
618 601
619 if (sizeof (struct WlanAddress) != addrlen) 602 if (sizeof(struct WlanAddress) != addrlen)
620 { 603 {
621 GNUNET_break (0); 604 GNUNET_break(0);
622 return NULL; 605 return NULL;
623 } 606 }
624 mac = &((struct WlanAddress *) addr)->mac; 607 mac = &((struct WlanAddress *)addr)->mac;
625 GNUNET_snprintf (macstr, 608 GNUNET_snprintf(macstr,
626 sizeof (macstr), 609 sizeof(macstr),
627 "%s.%u.%s", 610 "%s.%u.%s",
628 PLUGIN_NAME, 611 PLUGIN_NAME,
629 ntohl (((struct WlanAddress *) addr)->options), 612 ntohl(((struct WlanAddress *)addr)->options),
630 mac_to_string (mac)); 613 mac_to_string(mac));
631 return macstr; 614 return macstr;
632} 615}
633 616
@@ -641,15 +624,15 @@ wlan_plugin_address_to_string (void *cls,
641 * @param state new state of the session 624 * @param state new state of the session
642 */ 625 */
643static void 626static void
644notify_session_monitor (struct Plugin *plugin, 627notify_session_monitor(struct Plugin *plugin,
645 struct GNUNET_ATS_Session *session, 628 struct GNUNET_ATS_Session *session,
646 enum GNUNET_TRANSPORT_SessionState state) 629 enum GNUNET_TRANSPORT_SessionState state)
647{ 630{
648 struct GNUNET_TRANSPORT_SessionInfo info; 631 struct GNUNET_TRANSPORT_SessionInfo info;
649 632
650 if (NULL == plugin->sic) 633 if (NULL == plugin->sic)
651 return; 634 return;
652 memset (&info, 0, sizeof (info)); 635 memset(&info, 0, sizeof(info));
653 info.state = state; 636 info.state = state;
654 info.is_inbound = GNUNET_SYSERR; /* hard to say */ 637 info.is_inbound = GNUNET_SYSERR; /* hard to say */
655 info.num_msg_pending = 0; /* we queue per MAC, not per peer */ 638 info.num_msg_pending = 0; /* we queue per MAC, not per peer */
@@ -657,9 +640,9 @@ notify_session_monitor (struct Plugin *plugin,
657 info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS; /* not supported by WLAN */ 640 info.receive_delay = GNUNET_TIME_UNIT_ZERO_ABS; /* not supported by WLAN */
658 info.session_timeout = session->timeout; 641 info.session_timeout = session->timeout;
659 info.address = session->address; 642 info.address = session->address;
660 plugin->sic (plugin->sic_cls, 643 plugin->sic(plugin->sic_cls,
661 session, 644 session,
662 &info); 645 &info);
663} 646}
664 647
665 648
@@ -671,24 +654,24 @@ notify_session_monitor (struct Plugin *plugin,
671 * @param size total message size 654 * @param size total message size
672 */ 655 */
673static void 656static void
674get_radiotap_header (struct MacEndpoint *endpoint, 657get_radiotap_header(struct MacEndpoint *endpoint,
675 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header, 658 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *header,
676 uint16_t size) 659 uint16_t size)
677{ 660{
678 header->header.type = ntohs (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER); 661 header->header.type = ntohs(GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER);
679 header->header.size = ntohs (size); 662 header->header.size = ntohs(size);
680 if (NULL != endpoint) 663 if (NULL != endpoint)
681 { 664 {
682 header->rate = endpoint->rate; 665 header->rate = endpoint->rate;
683 header->tx_power = endpoint->tx_power; 666 header->tx_power = endpoint->tx_power;
684 header->antenna = endpoint->antenna; 667 header->antenna = endpoint->antenna;
685 } 668 }
686 else 669 else
687 { 670 {
688 header->rate = 255; 671 header->rate = 255;
689 header->tx_power = 0; 672 header->tx_power = 0;
690 header->antenna = 0; 673 header->antenna = 0;
691 } 674 }
692} 675}
693 676
694 677
@@ -701,18 +684,18 @@ get_radiotap_header (struct MacEndpoint *endpoint,
701 * @param size size of the whole packet, needed to calculate the time to send the packet 684 * @param size size of the whole packet, needed to calculate the time to send the packet
702 */ 685 */
703static void 686static void
704get_wlan_header (struct Plugin *plugin, 687get_wlan_header(struct Plugin *plugin,
705 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header, 688 struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame *header,
706 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr, 689 const struct GNUNET_TRANSPORT_WLAN_MacAddress *to_mac_addr,
707 unsigned int size) 690 unsigned int size)
708{ 691{
709 const int rate = 11000000; 692 const int rate = 11000000;
710 693
711 header->frame_control = htons (IEEE80211_FC0_TYPE_DATA); 694 header->frame_control = htons(IEEE80211_FC0_TYPE_DATA);
712 header->addr1 = *to_mac_addr; 695 header->addr1 = *to_mac_addr;
713 header->addr2 = plugin->mac_address; 696 header->addr2 = plugin->mac_address;
714 header->addr3 = mac_bssid_gnunet; 697 header->addr3 = mac_bssid_gnunet;
715 header->duration = GNUNET_htole16 ((size * 1000000) / rate + 290); 698 header->duration = GNUNET_htole16((size * 1000000) / rate + 290);
716 header->sequence_control = 0; // FIXME? 699 header->sequence_control = 0; // FIXME?
717 header->llc[0] = WLAN_LLC_DSAP_FIELD; 700 header->llc[0] = WLAN_LLC_DSAP_FIELD;
718 header->llc[1] = WLAN_LLC_SSAP_FIELD; 701 header->llc[1] = WLAN_LLC_SSAP_FIELD;
@@ -729,44 +712,44 @@ get_wlan_header (struct Plugin *plugin,
729 * @param hdr pointer to the hdr where the ack is stored 712 * @param hdr pointer to the hdr where the ack is stored
730 */ 713 */
731static void 714static void
732send_ack (void *cls, 715send_ack(void *cls,
733 uint32_t msg_id, 716 uint32_t msg_id,
734 const struct GNUNET_MessageHeader *hdr) 717 const struct GNUNET_MessageHeader *hdr)
735{ 718{
736 struct MacEndpoint *endpoint = cls; 719 struct MacEndpoint *endpoint = cls;
737 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header; 720 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage* radio_header;
738 uint16_t msize = ntohs (hdr->size); 721 uint16_t msize = ntohs(hdr->size);
739 size_t size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize; 722 size_t size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
740 char buf[size]; 723 char buf[size];
741 724
742 if (NULL == endpoint) 725 if (NULL == endpoint)
743 { 726 {
744 GNUNET_break (0); 727 GNUNET_break(0);
745 return; 728 return;
746 } 729 }
747 if (size >= GNUNET_MAX_MESSAGE_SIZE) 730 if (size >= GNUNET_MAX_MESSAGE_SIZE)
748 { 731 {
749 GNUNET_break (0); 732 GNUNET_break(0);
750 return; 733 return;
751 } 734 }
752 LOG (GNUNET_ERROR_TYPE_DEBUG, 735 LOG(GNUNET_ERROR_TYPE_DEBUG,
753 "Sending ACK to %s\n", 736 "Sending ACK to %s\n",
754 mac_to_string (&endpoint->wlan_addr.mac)); 737 mac_to_string(&endpoint->wlan_addr.mac));
755 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf; 738 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf;
756 get_radiotap_header (endpoint, radio_header, size); 739 get_radiotap_header(endpoint, radio_header, size);
757 get_wlan_header (endpoint->plugin, 740 get_wlan_header(endpoint->plugin,
758 &radio_header->frame, 741 &radio_header->frame,
759 &endpoint->wlan_addr.mac, 742 &endpoint->wlan_addr.mac,
760 sizeof (endpoint->wlan_addr.mac)); 743 sizeof(endpoint->wlan_addr.mac));
761 GNUNET_memcpy (&radio_header[1], hdr, msize); 744 GNUNET_memcpy(&radio_header[1], hdr, msize);
762 if (NULL != 745 if (NULL !=
763 GNUNET_HELPER_send (endpoint->plugin->suid_helper, 746 GNUNET_HELPER_send(endpoint->plugin->suid_helper,
764 &radio_header->header, 747 &radio_header->header,
765 GNUNET_NO /* dropping ACKs is bad */, 748 GNUNET_NO /* dropping ACKs is bad */,
766 NULL, NULL)) 749 NULL, NULL))
767 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 750 GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
768 _("# ACKs sent"), 751 _("# ACKs sent"),
769 1, GNUNET_NO); 752 1, GNUNET_NO);
770} 753}
771 754
772 755
@@ -777,24 +760,24 @@ send_ack (void *cls,
777 * @param hdr pointer to the data 760 * @param hdr pointer to the data
778 */ 761 */
779static void 762static void
780wlan_data_message_handler (void *cls, 763wlan_data_message_handler(void *cls,
781 const struct GNUNET_MessageHeader *hdr) 764 const struct GNUNET_MessageHeader *hdr)
782{ 765{
783 struct MacEndpoint *endpoint = cls; 766 struct MacEndpoint *endpoint = cls;
784 struct Plugin *plugin = endpoint->plugin; 767 struct Plugin *plugin = endpoint->plugin;
785 struct MacAndSession mas; 768 struct MacAndSession mas;
786 769
787 GNUNET_STATISTICS_update (plugin->env->stats, 770 GNUNET_STATISTICS_update(plugin->env->stats,
788 _("# Messages defragmented"), 771 _("# Messages defragmented"),
789 1, 772 1,
790 GNUNET_NO); 773 GNUNET_NO);
791 mas.session = NULL; 774 mas.session = NULL;
792 mas.endpoint = endpoint; 775 mas.endpoint = endpoint;
793 (void) GNUNET_SERVER_mst_receive (plugin->fragment_data_tokenizer, 776 (void)GNUNET_SERVER_mst_receive(plugin->fragment_data_tokenizer,
794 &mas, 777 &mas,
795 (const char *) hdr, 778 (const char *)hdr,
796 ntohs (hdr->size), 779 ntohs(hdr->size),
797 GNUNET_YES, GNUNET_NO); 780 GNUNET_YES, GNUNET_NO);
798} 781}
799 782
800 783
@@ -805,32 +788,32 @@ wlan_data_message_handler (void *cls,
805 * @param session the session free 788 * @param session the session free
806 */ 789 */
807static int 790static int
808wlan_plugin_disconnect_session (void *cls, 791wlan_plugin_disconnect_session(void *cls,
809 struct GNUNET_ATS_Session *session) 792 struct GNUNET_ATS_Session *session)
810{ 793{
811 struct MacEndpoint *endpoint = session->mac; 794 struct MacEndpoint *endpoint = session->mac;
812 struct Plugin *plugin = endpoint->plugin; 795 struct Plugin *plugin = endpoint->plugin;
813 796
814 plugin->env->session_end (plugin->env->cls, 797 plugin->env->session_end(plugin->env->cls,
815 session->address, 798 session->address,
816 session); 799 session);
817 notify_session_monitor (plugin, 800 notify_session_monitor(plugin,
818 session, 801 session,
819 GNUNET_TRANSPORT_SS_DONE); 802 GNUNET_TRANSPORT_SS_DONE);
820 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head, 803 GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head,
821 endpoint->sessions_tail, 804 endpoint->sessions_tail,
822 session); 805 session);
823 if (session->timeout_task != NULL) 806 if (session->timeout_task != NULL)
824 { 807 {
825 GNUNET_SCHEDULER_cancel (session->timeout_task); 808 GNUNET_SCHEDULER_cancel(session->timeout_task);
826 session->timeout_task = NULL; 809 session->timeout_task = NULL;
827 } 810 }
828 GNUNET_STATISTICS_update (plugin->env->stats, 811 GNUNET_STATISTICS_update(plugin->env->stats,
829 _("# Sessions allocated"), 812 _("# Sessions allocated"),
830 -1, 813 -1,
831 GNUNET_NO); 814 GNUNET_NO);
832 GNUNET_HELLO_address_free (session->address); 815 GNUNET_HELLO_address_free(session->address);
833 GNUNET_free (session); 816 GNUNET_free(session);
834 return GNUNET_OK; 817 return GNUNET_OK;
835} 818}
836 819
@@ -844,7 +827,7 @@ wlan_plugin_disconnect_session (void *cls,
844 * @return keepalive factor 827 * @return keepalive factor
845 */ 828 */
846static unsigned int 829static unsigned int
847wlan_plugin_query_keepalive_factor (void *cls) 830wlan_plugin_query_keepalive_factor(void *cls)
848{ 831{
849 return 3; 832 return 3;
850} 833}
@@ -856,23 +839,23 @@ wlan_plugin_query_keepalive_factor (void *cls)
856 * @param cls pointer to the Session 839 * @param cls pointer to the Session
857 */ 840 */
858static void 841static void
859session_timeout (void *cls) 842session_timeout(void *cls)
860{ 843{
861 struct GNUNET_ATS_Session *session = cls; 844 struct GNUNET_ATS_Session *session = cls;
862 struct GNUNET_TIME_Relative left; 845 struct GNUNET_TIME_Relative left;
863 846
864 session->timeout_task = NULL; 847 session->timeout_task = NULL;
865 left = GNUNET_TIME_absolute_get_remaining (session->timeout); 848 left = GNUNET_TIME_absolute_get_remaining(session->timeout);
866 if (0 != left.rel_value_us) 849 if (0 != left.rel_value_us)
867 { 850 {
868 session->timeout_task = 851 session->timeout_task =
869 GNUNET_SCHEDULER_add_delayed (left, 852 GNUNET_SCHEDULER_add_delayed(left,
870 &session_timeout, 853 &session_timeout,
871 session); 854 session);
872 return; 855 return;
873 } 856 }
874 wlan_plugin_disconnect_session (session->mac->plugin, 857 wlan_plugin_disconnect_session(session->mac->plugin,
875 session); 858 session);
876} 859}
877 860
878 861
@@ -885,13 +868,13 @@ session_timeout (void *cls)
885 * @return returns the session or NULL 868 * @return returns the session or NULL
886 */ 869 */
887static struct GNUNET_ATS_Session * 870static struct GNUNET_ATS_Session *
888lookup_session (struct MacEndpoint *endpoint, 871lookup_session(struct MacEndpoint *endpoint,
889 const struct GNUNET_PeerIdentity *peer) 872 const struct GNUNET_PeerIdentity *peer)
890{ 873{
891 struct GNUNET_ATS_Session *session; 874 struct GNUNET_ATS_Session *session;
892 875
893 for (session = endpoint->sessions_head; NULL != session; session = session->next) 876 for (session = endpoint->sessions_head; NULL != session; session = session->next)
894 if (0 == memcmp (peer, &session->target, sizeof (struct GNUNET_PeerIdentity))) 877 if (0 == memcmp(peer, &session->target, sizeof(struct GNUNET_PeerIdentity)))
895 return session; 878 return session;
896 return NULL; 879 return NULL;
897} 880}
@@ -905,41 +888,41 @@ lookup_session (struct MacEndpoint *endpoint,
905 * @return returns the session or NULL 888 * @return returns the session or NULL
906 */ 889 */
907static struct GNUNET_ATS_Session * 890static struct GNUNET_ATS_Session *
908create_session (struct MacEndpoint *endpoint, 891create_session(struct MacEndpoint *endpoint,
909 const struct GNUNET_PeerIdentity *peer) 892 const struct GNUNET_PeerIdentity *peer)
910{ 893{
911 struct GNUNET_ATS_Session *session; 894 struct GNUNET_ATS_Session *session;
912 895
913 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 896 GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
914 _("# Sessions allocated"), 897 _("# Sessions allocated"),
915 1, 898 1,
916 GNUNET_NO); 899 GNUNET_NO);
917 session = GNUNET_new (struct GNUNET_ATS_Session); 900 session = GNUNET_new(struct GNUNET_ATS_Session);
918 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head, 901 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head,
919 endpoint->sessions_tail, 902 endpoint->sessions_tail,
920 session); 903 session);
921 session->address = GNUNET_HELLO_address_allocate (peer, 904 session->address = GNUNET_HELLO_address_allocate(peer,
922 PLUGIN_NAME, 905 PLUGIN_NAME,
923 &endpoint->wlan_addr, 906 &endpoint->wlan_addr,
924 sizeof (endpoint->wlan_addr), 907 sizeof(endpoint->wlan_addr),
925 GNUNET_HELLO_ADDRESS_INFO_NONE); 908 GNUNET_HELLO_ADDRESS_INFO_NONE);
926 session->mac = endpoint; 909 session->mac = endpoint;
927 session->target = *peer; 910 session->target = *peer;
928 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 911 session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
929 session->timeout_task = 912 session->timeout_task =
930 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout, 913 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, &session_timeout,
931 session); 914 session);
932 notify_session_monitor (endpoint->plugin, 915 notify_session_monitor(endpoint->plugin,
933 session, 916 session,
934 GNUNET_TRANSPORT_SS_INIT); 917 GNUNET_TRANSPORT_SS_INIT);
935 notify_session_monitor (endpoint->plugin, 918 notify_session_monitor(endpoint->plugin,
936 session, 919 session,
937 GNUNET_TRANSPORT_SS_UP); 920 GNUNET_TRANSPORT_SS_UP);
938 LOG (GNUNET_ERROR_TYPE_DEBUG, 921 LOG(GNUNET_ERROR_TYPE_DEBUG,
939 "Created new session %p for peer `%s' with endpoint %s\n", 922 "Created new session %p for peer `%s' with endpoint %s\n",
940 session, 923 session,
941 GNUNET_i2s (peer), 924 GNUNET_i2s(peer),
942 mac_to_string (&endpoint->wlan_addr.mac)); 925 mac_to_string(&endpoint->wlan_addr.mac));
943 926
944 return session; 927 return session;
945} 928}
@@ -953,14 +936,14 @@ create_session (struct MacEndpoint *endpoint,
953 * @return returns the session 936 * @return returns the session
954 */ 937 */
955static struct GNUNET_ATS_Session * 938static struct GNUNET_ATS_Session *
956get_session (struct MacEndpoint *endpoint, 939get_session(struct MacEndpoint *endpoint,
957 const struct GNUNET_PeerIdentity *peer) 940 const struct GNUNET_PeerIdentity *peer)
958{ 941{
959 struct GNUNET_ATS_Session *session; 942 struct GNUNET_ATS_Session *session;
960 943
961 if (NULL != (session = lookup_session (endpoint, peer))) 944 if (NULL != (session = lookup_session(endpoint, peer)))
962 return session; 945 return session;
963 return create_session (endpoint, peer); 946 return create_session(endpoint, peer);
964} 947}
965 948
966 949
@@ -975,13 +958,13 @@ get_session (struct MacEndpoint *endpoint,
975 * if the helper was stopped) 958 * if the helper was stopped)
976 */ 959 */
977static void 960static void
978fragment_transmission_done (void *cls, 961fragment_transmission_done(void *cls,
979 int result) 962 int result)
980{ 963{
981 struct FragmentMessage *fm = cls; 964 struct FragmentMessage *fm = cls;
982 965
983 fm->sh = NULL; 966 fm->sh = NULL;
984 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext); 967 GNUNET_FRAGMENT_context_transmission_done(fm->fragcontext);
985} 968}
986 969
987 970
@@ -992,8 +975,8 @@ fragment_transmission_done (void *cls,
992 * @param hdr pointer to the start of the fragment message 975 * @param hdr pointer to the start of the fragment message
993 */ 976 */
994static void 977static void
995transmit_fragment (void *cls, 978transmit_fragment(void *cls,
996 const struct GNUNET_MessageHeader *hdr) 979 const struct GNUNET_MessageHeader *hdr)
997{ 980{
998 struct FragmentMessage *fm = cls; 981 struct FragmentMessage *fm = cls;
999 struct MacEndpoint *endpoint = fm->macendpoint; 982 struct MacEndpoint *endpoint = fm->macendpoint;
@@ -1001,51 +984,51 @@ transmit_fragment (void *cls,
1001 uint16_t msize; 984 uint16_t msize;
1002 985
1003 if (NULL == endpoint) 986 if (NULL == endpoint)
1004 { 987 {
1005 GNUNET_break (0); 988 GNUNET_break(0);
1006 return; 989 return;
1007 } 990 }
1008 msize = ntohs (hdr->size); 991 msize = ntohs(hdr->size);
1009 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize; 992 size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + msize;
1010 { 993 {
1011 char buf[size]; 994 char buf[size];
1012 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header; 995 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radio_header;
1013 996
1014 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *) buf; 997 radio_header = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *)buf;
1015 get_radiotap_header (endpoint, radio_header, size); 998 get_radiotap_header(endpoint, radio_header, size);
1016 LOG (GNUNET_ERROR_TYPE_DEBUG, 999 LOG(GNUNET_ERROR_TYPE_DEBUG,
1017 "Sending %u bytes of data to MAC `%s'\n", 1000 "Sending %u bytes of data to MAC `%s'\n",
1018 (unsigned int) msize, 1001 (unsigned int)msize,
1019 mac_to_string (&endpoint->wlan_addr.mac)); 1002 mac_to_string(&endpoint->wlan_addr.mac));
1020 1003
1021 get_wlan_header (endpoint->plugin, 1004 get_wlan_header(endpoint->plugin,
1022 &radio_header->frame, 1005 &radio_header->frame,
1023 &endpoint->wlan_addr.mac, 1006 &endpoint->wlan_addr.mac,
1024 sizeof (endpoint->wlan_addr.mac)); 1007 sizeof(endpoint->wlan_addr.mac));
1025 GNUNET_memcpy (&radio_header[1], hdr, msize); 1008 GNUNET_memcpy(&radio_header[1], hdr, msize);
1026 GNUNET_assert (NULL == fm->sh); 1009 GNUNET_assert(NULL == fm->sh);
1027 fm->sh = GNUNET_HELPER_send (endpoint->plugin->suid_helper, 1010 fm->sh = GNUNET_HELPER_send(endpoint->plugin->suid_helper,
1028 &radio_header->header, 1011 &radio_header->header,
1029 GNUNET_NO, 1012 GNUNET_NO,
1030 &fragment_transmission_done, fm); 1013 &fragment_transmission_done, fm);
1031 fm->size_on_wire += size; 1014 fm->size_on_wire += size;
1032 if (NULL != fm->sh) 1015 if (NULL != fm->sh)
1033 { 1016 {
1034 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 1017 GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1035 _("# message fragments sent"), 1018 _("# message fragments sent"),
1036 1, 1019 1,
1037 GNUNET_NO); 1020 GNUNET_NO);
1038 } 1021 }
1039 else 1022 else
1040 { 1023 {
1041 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext); 1024 GNUNET_FRAGMENT_context_transmission_done(fm->fragcontext);
1042 } 1025 }
1043 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 1026 GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1044 "# bytes currently in buffers", 1027 "# bytes currently in buffers",
1045 -msize, GNUNET_NO); 1028 -msize, GNUNET_NO);
1046 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 1029 GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1047 "# bytes transmitted", 1030 "# bytes transmitted",
1048 msize, GNUNET_NO); 1031 msize, GNUNET_NO);
1049 } 1032 }
1050} 1033}
1051 1034
@@ -1056,39 +1039,39 @@ transmit_fragment (void *cls,
1056 * @param fm message to free 1039 * @param fm message to free
1057 */ 1040 */
1058static void 1041static void
1059free_fragment_message (struct FragmentMessage *fm) 1042free_fragment_message(struct FragmentMessage *fm)
1060{ 1043{
1061 struct MacEndpoint *endpoint = fm->macendpoint; 1044 struct MacEndpoint *endpoint = fm->macendpoint;
1062 1045
1063 GNUNET_STATISTICS_update (endpoint->plugin->env->stats, 1046 GNUNET_STATISTICS_update(endpoint->plugin->env->stats,
1064 _("# messages pending (with fragmentation)"), 1047 _("# messages pending (with fragmentation)"),
1065 -1, GNUNET_NO); 1048 -1, GNUNET_NO);
1066 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head, 1049 GNUNET_CONTAINER_DLL_remove(endpoint->sending_messages_head,
1067 endpoint->sending_messages_tail, 1050 endpoint->sending_messages_tail,
1068 fm); 1051 fm);
1069 if (NULL != fm->sh) 1052 if (NULL != fm->sh)
1070 { 1053 {
1071 GNUNET_HELPER_send_cancel (fm->sh); 1054 GNUNET_HELPER_send_cancel(fm->sh);
1072 fm->sh = NULL; 1055 fm->sh = NULL;
1073 } 1056 }
1074 if (NULL != fm->msg) 1057 if (NULL != fm->msg)
1075 { 1058 {
1076 GNUNET_free (fm->msg); 1059 GNUNET_free(fm->msg);
1077 fm->msg = NULL; 1060 fm->msg = NULL;
1078 } 1061 }
1079 if (NULL != fm->fragcontext) 1062 if (NULL != fm->fragcontext)
1080 { 1063 {
1081 GNUNET_FRAGMENT_context_destroy (fm->fragcontext, 1064 GNUNET_FRAGMENT_context_destroy(fm->fragcontext,
1082 &endpoint->msg_delay, 1065 &endpoint->msg_delay,
1083 &endpoint->ack_delay); 1066 &endpoint->ack_delay);
1084 fm->fragcontext = NULL; 1067 fm->fragcontext = NULL;
1085 } 1068 }
1086 if (NULL != fm->timeout_task) 1069 if (NULL != fm->timeout_task)
1087 { 1070 {
1088 GNUNET_SCHEDULER_cancel (fm->timeout_task); 1071 GNUNET_SCHEDULER_cancel(fm->timeout_task);
1089 fm->timeout_task = NULL; 1072 fm->timeout_task = NULL;
1090 } 1073 }
1091 GNUNET_free (fm); 1074 GNUNET_free(fm);
1092} 1075}
1093 1076
1094 1077
@@ -1098,21 +1081,21 @@ free_fragment_message (struct FragmentMessage *fm)
1098 * @param cls pointer to the 'struct FragmentMessage' 1081 * @param cls pointer to the 'struct FragmentMessage'
1099 */ 1082 */
1100static void 1083static void
1101fragmentmessage_timeout (void *cls) 1084fragmentmessage_timeout(void *cls)
1102{ 1085{
1103 struct FragmentMessage *fm = cls; 1086 struct FragmentMessage *fm = cls;
1104 1087
1105 fm->timeout_task = NULL; 1088 fm->timeout_task = NULL;
1106 if (NULL != fm->cont) 1089 if (NULL != fm->cont)
1107 { 1090 {
1108 fm->cont (fm->cont_cls, 1091 fm->cont(fm->cont_cls,
1109 &fm->target, 1092 &fm->target,
1110 GNUNET_SYSERR, 1093 GNUNET_SYSERR,
1111 fm->size_payload, 1094 fm->size_payload,
1112 fm->size_on_wire); 1095 fm->size_on_wire);
1113 fm->cont = NULL; 1096 fm->cont = NULL;
1114 } 1097 }
1115 free_fragment_message (fm); 1098 free_fragment_message(fm);
1116} 1099}
1117 1100
1118 1101
@@ -1131,49 +1114,49 @@ fragmentmessage_timeout (void *cls)
1131 * @param cont_cls closure for @a cont 1114 * @param cont_cls closure for @a cont
1132 */ 1115 */
1133static void 1116static void
1134send_with_fragmentation (struct MacEndpoint *endpoint, 1117send_with_fragmentation(struct MacEndpoint *endpoint,
1135 struct GNUNET_TIME_Relative timeout, 1118 struct GNUNET_TIME_Relative timeout,
1136 const struct GNUNET_PeerIdentity *target, 1119 const struct GNUNET_PeerIdentity *target,
1137 const struct GNUNET_MessageHeader *msg, 1120 const struct GNUNET_MessageHeader *msg,
1138 size_t payload_size, 1121 size_t payload_size,
1139 GNUNET_TRANSPORT_TransmitContinuation cont, 1122 GNUNET_TRANSPORT_TransmitContinuation cont,
1140 void *cont_cls) 1123 void *cont_cls)
1141 1124
1142{ 1125{
1143 struct FragmentMessage *fm; 1126 struct FragmentMessage *fm;
1144 struct Plugin *plugin; 1127 struct Plugin *plugin;
1145 1128
1146 plugin = endpoint->plugin; 1129 plugin = endpoint->plugin;
1147 fm = GNUNET_new (struct FragmentMessage); 1130 fm = GNUNET_new(struct FragmentMessage);
1148 fm->macendpoint = endpoint; 1131 fm->macendpoint = endpoint;
1149 fm->target = *target; 1132 fm->target = *target;
1150 fm->size_payload = payload_size; 1133 fm->size_payload = payload_size;
1151 fm->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1134 fm->timeout = GNUNET_TIME_relative_to_absolute(timeout);
1152 fm->cont = cont; 1135 fm->cont = cont;
1153 fm->cont_cls = cont_cls; 1136 fm->cont_cls = cont_cls;
1154 /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */ 1137 /* 1 MBit/s typical data rate, 1430 byte fragments => ~100 ms per message */
1155 fm->timeout_task = 1138 fm->timeout_task =
1156 GNUNET_SCHEDULER_add_delayed (timeout, 1139 GNUNET_SCHEDULER_add_delayed(timeout,
1157 &fragmentmessage_timeout, 1140 &fragmentmessage_timeout,
1158 fm); 1141 fm);
1159 if (GNUNET_YES == plugin->have_mac) 1142 if (GNUNET_YES == plugin->have_mac)
1160 { 1143 {
1161 fm->fragcontext = 1144 fm->fragcontext =
1162 GNUNET_FRAGMENT_context_create (plugin->env->stats, 1145 GNUNET_FRAGMENT_context_create(plugin->env->stats,
1163 WLAN_MTU, 1146 WLAN_MTU,
1164 &plugin->tracker, 1147 &plugin->tracker,
1165 fm->macendpoint->msg_delay, 1148 fm->macendpoint->msg_delay,
1166 fm->macendpoint->ack_delay, 1149 fm->macendpoint->ack_delay,
1167 msg, 1150 msg,
1168 &transmit_fragment, fm); 1151 &transmit_fragment, fm);
1169 } 1152 }
1170 else 1153 else
1171 { 1154 {
1172 fm->msg = GNUNET_copy_message (msg); 1155 fm->msg = GNUNET_copy_message(msg);
1173 } 1156 }
1174 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sending_messages_head, 1157 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sending_messages_head,
1175 endpoint->sending_messages_tail, 1158 endpoint->sending_messages_tail,
1176 fm); 1159 fm);
1177} 1160}
1178 1161
1179 1162
@@ -1183,38 +1166,38 @@ send_with_fragmentation (struct MacEndpoint *endpoint,
1183 * @param endpoint pointer to the MacEndpoint to free 1166 * @param endpoint pointer to the MacEndpoint to free
1184 */ 1167 */
1185static void 1168static void
1186free_macendpoint (struct MacEndpoint *endpoint) 1169free_macendpoint(struct MacEndpoint *endpoint)
1187{ 1170{
1188 struct Plugin *plugin = endpoint->plugin; 1171 struct Plugin *plugin = endpoint->plugin;
1189 struct FragmentMessage *fm; 1172 struct FragmentMessage *fm;
1190 struct GNUNET_ATS_Session *session; 1173 struct GNUNET_ATS_Session *session;
1191 1174
1192 GNUNET_STATISTICS_update (plugin->env->stats, 1175 GNUNET_STATISTICS_update(plugin->env->stats,
1193 _("# MAC endpoints allocated"), 1176 _("# MAC endpoints allocated"),
1194 -1, 1177 -1,
1195 GNUNET_NO); 1178 GNUNET_NO);
1196 while (NULL != (session = endpoint->sessions_head)) 1179 while (NULL != (session = endpoint->sessions_head))
1197 wlan_plugin_disconnect_session (plugin, 1180 wlan_plugin_disconnect_session(plugin,
1198 session); 1181 session);
1199 while (NULL != (fm = endpoint->sending_messages_head)) 1182 while (NULL != (fm = endpoint->sending_messages_head))
1200 free_fragment_message (fm); 1183 free_fragment_message(fm);
1201 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, 1184 GNUNET_CONTAINER_DLL_remove(plugin->mac_head,
1202 plugin->mac_tail, 1185 plugin->mac_tail,
1203 endpoint); 1186 endpoint);
1204 1187
1205 if (NULL != endpoint->defrag) 1188 if (NULL != endpoint->defrag)
1206 { 1189 {
1207 GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag); 1190 GNUNET_DEFRAGMENT_context_destroy(endpoint->defrag);
1208 endpoint->defrag = NULL; 1191 endpoint->defrag = NULL;
1209 } 1192 }
1210 1193
1211 plugin->mac_count--; 1194 plugin->mac_count--;
1212 if (NULL != endpoint->timeout_task) 1195 if (NULL != endpoint->timeout_task)
1213 { 1196 {
1214 GNUNET_SCHEDULER_cancel (endpoint->timeout_task); 1197 GNUNET_SCHEDULER_cancel(endpoint->timeout_task);
1215 endpoint->timeout_task = NULL; 1198 endpoint->timeout_task = NULL;
1216 } 1199 }
1217 GNUNET_free (endpoint); 1200 GNUNET_free(endpoint);
1218} 1201}
1219 1202
1220 1203
@@ -1224,22 +1207,22 @@ free_macendpoint (struct MacEndpoint *endpoint)
1224 * @param cls pointer to the `struct MacEndpoint *` 1207 * @param cls pointer to the `struct MacEndpoint *`
1225 */ 1208 */
1226static void 1209static void
1227macendpoint_timeout (void *cls) 1210macendpoint_timeout(void *cls)
1228{ 1211{
1229 struct MacEndpoint *endpoint = cls; 1212 struct MacEndpoint *endpoint = cls;
1230 struct GNUNET_TIME_Relative timeout; 1213 struct GNUNET_TIME_Relative timeout;
1231 1214
1232 endpoint->timeout_task = NULL; 1215 endpoint->timeout_task = NULL;
1233 timeout = GNUNET_TIME_absolute_get_remaining (endpoint->timeout); 1216 timeout = GNUNET_TIME_absolute_get_remaining(endpoint->timeout);
1234 if (0 == timeout.rel_value_us) 1217 if (0 == timeout.rel_value_us)
1235 { 1218 {
1236 free_macendpoint (endpoint); 1219 free_macendpoint(endpoint);
1237 return; 1220 return;
1238 } 1221 }
1239 endpoint->timeout_task = 1222 endpoint->timeout_task =
1240 GNUNET_SCHEDULER_add_delayed (timeout, 1223 GNUNET_SCHEDULER_add_delayed(timeout,
1241 &macendpoint_timeout, 1224 &macendpoint_timeout,
1242 endpoint); 1225 endpoint);
1243} 1226}
1244 1227
1245 1228
@@ -1251,43 +1234,43 @@ macendpoint_timeout (void *cls)
1251 * @return handle to our data structure for this MAC 1234 * @return handle to our data structure for this MAC
1252 */ 1235 */
1253static struct MacEndpoint * 1236static struct MacEndpoint *
1254create_macendpoint (struct Plugin *plugin, 1237create_macendpoint(struct Plugin *plugin,
1255 struct WlanAddress *mac) 1238 struct WlanAddress *mac)
1256{ 1239{
1257 struct MacEndpoint *pos; 1240 struct MacEndpoint *pos;
1258 1241
1259 for (pos = plugin->mac_head; NULL != pos; pos = pos->next) 1242 for (pos = plugin->mac_head; NULL != pos; pos = pos->next)
1260 if (0 == memcmp (mac, &pos->wlan_addr, sizeof (pos->wlan_addr))) 1243 if (0 == memcmp(mac, &pos->wlan_addr, sizeof(pos->wlan_addr)))
1261 return pos; 1244 return pos;
1262 pos = GNUNET_new (struct MacEndpoint); 1245 pos = GNUNET_new(struct MacEndpoint);
1263 pos->wlan_addr = (*mac); 1246 pos->wlan_addr = (*mac);
1264 pos->plugin = plugin; 1247 pos->plugin = plugin;
1265 pos->defrag = 1248 pos->defrag =
1266 GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 1249 GNUNET_DEFRAGMENT_context_create(plugin->env->stats,
1267 WLAN_MTU, 1250 WLAN_MTU,
1268 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, 1251 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
1269 pos, 1252 pos,
1270 &wlan_data_message_handler, 1253 &wlan_data_message_handler,
1271 &send_ack); 1254 &send_ack);
1272 1255
1273 pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 1256 pos->msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
1274 pos->ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100); 1257 pos->ack_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100);
1275 pos->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); 1258 pos->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT);
1276 pos->timeout_task = 1259 pos->timeout_task =
1277 GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT, &macendpoint_timeout, 1260 GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, &macendpoint_timeout,
1278 pos); 1261 pos);
1279 GNUNET_CONTAINER_DLL_insert (plugin->mac_head, 1262 GNUNET_CONTAINER_DLL_insert(plugin->mac_head,
1280 plugin->mac_tail, 1263 plugin->mac_tail,
1281 pos); 1264 pos);
1282 plugin->mac_count++; 1265 plugin->mac_count++;
1283 GNUNET_STATISTICS_update (plugin->env->stats, 1266 GNUNET_STATISTICS_update(plugin->env->stats,
1284 _("# MAC endpoints allocated"), 1267 _("# MAC endpoints allocated"),
1285 1, GNUNET_NO); 1268 1, GNUNET_NO);
1286 LOG (GNUNET_ERROR_TYPE_DEBUG, 1269 LOG(GNUNET_ERROR_TYPE_DEBUG,
1287 "New MAC endpoint `%s'\n", 1270 "New MAC endpoint `%s'\n",
1288 wlan_plugin_address_to_string (NULL, 1271 wlan_plugin_address_to_string(NULL,
1289 &pos->wlan_addr, 1272 &pos->wlan_addr,
1290 sizeof (struct WlanAddress))); 1273 sizeof(struct WlanAddress)));
1291 return pos; 1274 return pos;
1292} 1275}
1293 1276
@@ -1300,8 +1283,8 @@ create_macendpoint (struct Plugin *plugin,
1300 * @return the network type in HBO or #GNUNET_SYSERR 1283 * @return the network type in HBO or #GNUNET_SYSERR
1301 */ 1284 */
1302static enum GNUNET_NetworkType 1285static enum GNUNET_NetworkType
1303wlan_plugin_get_network (void *cls, 1286wlan_plugin_get_network(void *cls,
1304 struct GNUNET_ATS_Session *session) 1287 struct GNUNET_ATS_Session *session)
1305{ 1288{
1306#if BUILD_WLAN 1289#if BUILD_WLAN
1307 return GNUNET_NT_WLAN; 1290 return GNUNET_NT_WLAN;
@@ -1319,7 +1302,7 @@ wlan_plugin_get_network (void *cls,
1319 * @return the network type 1302 * @return the network type
1320 */ 1303 */
1321static enum GNUNET_NetworkType 1304static enum GNUNET_NetworkType
1322wlan_plugin_get_network_for_address (void *cls, 1305wlan_plugin_get_network_for_address(void *cls,
1323 const struct GNUNET_HELLO_Address *address) 1306 const struct GNUNET_HELLO_Address *address)
1324{ 1307{
1325#if BUILD_WLAN 1308#if BUILD_WLAN
@@ -1339,28 +1322,28 @@ wlan_plugin_get_network_for_address (void *cls,
1339 * @return the session or NULL of max connections exceeded 1322 * @return the session or NULL of max connections exceeded
1340 */ 1323 */
1341static struct GNUNET_ATS_Session * 1324static struct GNUNET_ATS_Session *
1342wlan_plugin_get_session (void *cls, 1325wlan_plugin_get_session(void *cls,
1343 const struct GNUNET_HELLO_Address *address) 1326 const struct GNUNET_HELLO_Address *address)
1344{ 1327{
1345 struct Plugin *plugin = cls; 1328 struct Plugin *plugin = cls;
1346 struct MacEndpoint *endpoint; 1329 struct MacEndpoint *endpoint;
1347 1330
1348 if (NULL == address) 1331 if (NULL == address)
1349 return NULL; 1332 return NULL;
1350 if (sizeof (struct WlanAddress) != address->address_length) 1333 if (sizeof(struct WlanAddress) != address->address_length)
1351 { 1334 {
1352 GNUNET_break (0); 1335 GNUNET_break(0);
1353 return NULL; 1336 return NULL;
1354 } 1337 }
1355 LOG (GNUNET_ERROR_TYPE_DEBUG, 1338 LOG(GNUNET_ERROR_TYPE_DEBUG,
1356 "Service asked to create session for peer `%s' with MAC `%s'\n", 1339 "Service asked to create session for peer `%s' with MAC `%s'\n",
1357 GNUNET_i2s (&address->peer), 1340 GNUNET_i2s(&address->peer),
1358 wlan_plugin_address_to_string (NULL, 1341 wlan_plugin_address_to_string(NULL,
1359 address->address, 1342 address->address,
1360 address->address_length)); 1343 address->address_length));
1361 endpoint = create_macendpoint (plugin, 1344 endpoint = create_macendpoint(plugin,
1362 (struct WlanAddress *) address->address); 1345 (struct WlanAddress *)address->address);
1363 return get_session (endpoint, &address->peer); 1346 return get_session(endpoint, &address->peer);
1364} 1347}
1365 1348
1366 1349
@@ -1373,8 +1356,8 @@ wlan_plugin_get_session (void *cls,
1373 * @param target peer from which to disconnect 1356 * @param target peer from which to disconnect
1374 */ 1357 */
1375static void 1358static void
1376wlan_plugin_disconnect_peer (void *cls, 1359wlan_plugin_disconnect_peer(void *cls,
1377 const struct GNUNET_PeerIdentity *target) 1360 const struct GNUNET_PeerIdentity *target)
1378{ 1361{
1379 struct Plugin *plugin = cls; 1362 struct Plugin *plugin = cls;
1380 struct GNUNET_ATS_Session *session; 1363 struct GNUNET_ATS_Session *session;
@@ -1382,12 +1365,12 @@ wlan_plugin_disconnect_peer (void *cls,
1382 1365
1383 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next) 1366 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next)
1384 for (session = endpoint->sessions_head; NULL != session; session = session->next) 1367 for (session = endpoint->sessions_head; NULL != session; session = session->next)
1385 if (0 == memcmp (target, &session->target, 1368 if (0 == memcmp(target, &session->target,
1386 sizeof (struct GNUNET_PeerIdentity))) 1369 sizeof(struct GNUNET_PeerIdentity)))
1387 { 1370 {
1388 wlan_plugin_disconnect_session (plugin, session); 1371 wlan_plugin_disconnect_session(plugin, session);
1389 break; /* inner-loop only (in case peer has another MAC as well!) */ 1372 break; /* inner-loop only (in case peer has another MAC as well!) */
1390 } 1373 }
1391} 1374}
1392 1375
1393 1376
@@ -1419,43 +1402,43 @@ wlan_plugin_disconnect_peer (void *cls,
1419 * and does NOT mean that the message was not transmitted (DV) 1402 * and does NOT mean that the message was not transmitted (DV)
1420 */ 1403 */
1421static ssize_t 1404static ssize_t
1422wlan_plugin_send (void *cls, 1405wlan_plugin_send(void *cls,
1423 struct GNUNET_ATS_Session *session, 1406 struct GNUNET_ATS_Session *session,
1424 const char *msgbuf, size_t msgbuf_size, 1407 const char *msgbuf, size_t msgbuf_size,
1425 unsigned int priority, 1408 unsigned int priority,
1426 struct GNUNET_TIME_Relative to, 1409 struct GNUNET_TIME_Relative to,
1427 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1410 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1428{ 1411{
1429 struct Plugin *plugin = cls; 1412 struct Plugin *plugin = cls;
1430 struct WlanHeader *wlanheader; 1413 struct WlanHeader *wlanheader;
1431 size_t size = msgbuf_size + sizeof (struct WlanHeader); 1414 size_t size = msgbuf_size + sizeof(struct WlanHeader);
1432 char buf[size] GNUNET_ALIGN; 1415 char buf[size] GNUNET_ALIGN;
1433 1416
1434 LOG (GNUNET_ERROR_TYPE_DEBUG, 1417 LOG(GNUNET_ERROR_TYPE_DEBUG,
1435 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n", 1418 "Transmitting %u bytes of payload to peer `%s' (starting with %u byte message of type %u)\n",
1436 msgbuf_size, 1419 msgbuf_size,
1437 GNUNET_i2s (&session->target), 1420 GNUNET_i2s(&session->target),
1438 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->size), 1421 (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->size),
1439 (unsigned int) ntohs (((struct GNUNET_MessageHeader*)msgbuf)->type)); 1422 (unsigned int)ntohs(((struct GNUNET_MessageHeader*)msgbuf)->type));
1440 wlanheader = (struct WlanHeader *) buf; 1423 wlanheader = (struct WlanHeader *)buf;
1441 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader)); 1424 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader));
1442 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA); 1425 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA);
1443 wlanheader->sender = *plugin->env->my_identity; 1426 wlanheader->sender = *plugin->env->my_identity;
1444 wlanheader->target = session->target; 1427 wlanheader->target = session->target;
1445 wlanheader->crc = htonl (GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size)); 1428 wlanheader->crc = htonl(GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size));
1446 GNUNET_memcpy (&wlanheader[1], 1429 GNUNET_memcpy(&wlanheader[1],
1447 msgbuf, 1430 msgbuf,
1448 msgbuf_size); 1431 msgbuf_size);
1449 GNUNET_STATISTICS_update (plugin->env->stats, 1432 GNUNET_STATISTICS_update(plugin->env->stats,
1450 "# bytes currently in buffers", 1433 "# bytes currently in buffers",
1451 msgbuf_size, 1434 msgbuf_size,
1452 GNUNET_NO); 1435 GNUNET_NO);
1453 send_with_fragmentation (session->mac, 1436 send_with_fragmentation(session->mac,
1454 to, 1437 to,
1455 &session->target, 1438 &session->target,
1456 &wlanheader->header, 1439 &wlanheader->header,
1457 msgbuf_size, 1440 msgbuf_size,
1458 cont, cont_cls); 1441 cont, cont_cls);
1459 return size; 1442 return size;
1460} 1443}
1461 1444
@@ -1469,9 +1452,9 @@ wlan_plugin_send (void *cls,
1469 * @param hdr start of the message 1452 * @param hdr start of the message
1470 */ 1453 */
1471static int 1454static int
1472process_data (void *cls, 1455process_data(void *cls,
1473 void *client, 1456 void *client,
1474 const struct GNUNET_MessageHeader *hdr) 1457 const struct GNUNET_MessageHeader *hdr)
1475{ 1458{
1476 struct Plugin *plugin = cls; 1459 struct Plugin *plugin = cls;
1477 struct GNUNET_HELLO_Address *address; 1460 struct GNUNET_HELLO_Address *address;
@@ -1482,217 +1465,221 @@ process_data (void *cls,
1482 int ret; 1465 int ret;
1483 uint16_t msize; 1466 uint16_t msize;
1484 1467
1485 msize = ntohs (hdr->size); 1468 msize = ntohs(hdr->size);
1486
1487 GNUNET_STATISTICS_update (plugin->env->stats,
1488 "# bytes received",
1489 msize, GNUNET_NO);
1490 1469
1491 switch (ntohs (hdr->type)) 1470 GNUNET_STATISTICS_update(plugin->env->stats,
1492 { 1471 "# bytes received",
1493 case GNUNET_MESSAGE_TYPE_HELLO: 1472 msize, GNUNET_NO);
1494 1473
1495 if (GNUNET_OK != 1474 switch (ntohs(hdr->type))
1496 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hdr,
1497 &tmpsource))
1498 {
1499 GNUNET_break_op (0);
1500 break;
1501 }
1502 if (NULL == mas->endpoint)
1503 { 1475 {
1504 GNUNET_break (0); 1476 case GNUNET_MESSAGE_TYPE_HELLO:
1505 break;
1506 }
1507 1477
1508 LOG (GNUNET_ERROR_TYPE_DEBUG, 1478 if (GNUNET_OK !=
1509 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n", 1479 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hdr,
1510 (unsigned int) msize, 1480 &tmpsource))
1511 GNUNET_i2s (&tmpsource), 1481 {
1512 wlan_plugin_address_to_string (NULL, 1482 GNUNET_break_op(0);
1483 break;
1484 }
1485 if (NULL == mas->endpoint)
1486 {
1487 GNUNET_break(0);
1488 break;
1489 }
1490
1491 LOG(GNUNET_ERROR_TYPE_DEBUG,
1492 "Processing %u bytes of HELLO from peer `%s' at MAC %s\n",
1493 (unsigned int)msize,
1494 GNUNET_i2s(&tmpsource),
1495 wlan_plugin_address_to_string(NULL,
1513 &mas->endpoint->wlan_addr, 1496 &mas->endpoint->wlan_addr,
1514 sizeof (mas->endpoint->wlan_addr))); 1497 sizeof(mas->endpoint->wlan_addr)));
1515 1498
1516 GNUNET_STATISTICS_update (plugin->env->stats, 1499 GNUNET_STATISTICS_update(plugin->env->stats,
1517 _("# HELLO messages received"), 1, 1500 _("# HELLO messages received"), 1,
1518 GNUNET_NO); 1501 GNUNET_NO);
1519 address = GNUNET_HELLO_address_allocate (&tmpsource, 1502 address = GNUNET_HELLO_address_allocate(&tmpsource,
1520 PLUGIN_NAME, 1503 PLUGIN_NAME,
1521 &mas->endpoint->wlan_addr, 1504 &mas->endpoint->wlan_addr,
1522 sizeof (mas->endpoint->wlan_addr), 1505 sizeof(mas->endpoint->wlan_addr),
1523 GNUNET_HELLO_ADDRESS_INFO_NONE); 1506 GNUNET_HELLO_ADDRESS_INFO_NONE);
1524 mas->session = lookup_session (mas->endpoint, 1507 mas->session = lookup_session(mas->endpoint,
1525 &tmpsource); 1508 &tmpsource);
1526 if (NULL == mas->session) 1509 if (NULL == mas->session)
1527 { 1510 {
1528 mas->session = create_session (mas->endpoint, 1511 mas->session = create_session(mas->endpoint,
1529 &tmpsource); 1512 &tmpsource);
1530 plugin->env->session_start (plugin->env->cls, 1513 plugin->env->session_start(plugin->env->cls,
1531 address, 1514 address,
1532 mas->session, 1515 mas->session,
1533 scope); 1516 scope);
1534 } 1517 }
1535 plugin->env->receive (plugin->env->cls, 1518 plugin->env->receive(plugin->env->cls,
1536 address, 1519 address,
1537 mas->session, 1520 mas->session,
1538 hdr); 1521 hdr);
1539 GNUNET_HELLO_address_free (address); 1522 GNUNET_HELLO_address_free(address);
1540 break;
1541 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1542 if (NULL == mas->endpoint)
1543 {
1544 GNUNET_break (0);
1545 break; 1523 break;
1546 } 1524
1547 LOG (GNUNET_ERROR_TYPE_DEBUG, 1525 case GNUNET_MESSAGE_TYPE_FRAGMENT:
1548 "Processing %u bytes of FRAGMENT from MAC %s\n", 1526 if (NULL == mas->endpoint)
1549 (unsigned int) msize, 1527 {
1550 wlan_plugin_address_to_string (NULL, 1528 GNUNET_break(0);
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,
1551 &mas->endpoint->wlan_addr, 1535 &mas->endpoint->wlan_addr,
1552 sizeof (mas->endpoint->wlan_addr))); 1536 sizeof(mas->endpoint->wlan_addr)));
1553 GNUNET_STATISTICS_update (plugin->env->stats, 1537 GNUNET_STATISTICS_update(plugin->env->stats,
1554 _("# fragments received"), 1538 _("# fragments received"),
1555 1, 1539 1,
1556 GNUNET_NO); 1540 GNUNET_NO);
1557 (void) GNUNET_DEFRAGMENT_process_fragment (mas->endpoint->defrag, 1541 (void)GNUNET_DEFRAGMENT_process_fragment(mas->endpoint->defrag,
1558 hdr); 1542 hdr);
1559 break;
1560 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK:
1561 if (NULL == mas->endpoint)
1562 {
1563 GNUNET_break (0);
1564 break; 1543 break;
1565 } 1544
1566 GNUNET_STATISTICS_update (plugin->env->stats, 1545 case GNUNET_MESSAGE_TYPE_FRAGMENT_ACK:
1567 _("# ACKs received"), 1546 if (NULL == mas->endpoint)
1568 1, GNUNET_NO); 1547 {
1569 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next) 1548 GNUNET_break(0);
1570 { 1549 break;
1571 ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr); 1550 }
1572 if (GNUNET_OK == ret) 1551 GNUNET_STATISTICS_update(plugin->env->stats,
1573 { 1552 _("# ACKs received"),
1574 LOG (GNUNET_ERROR_TYPE_DEBUG, 1553 1, GNUNET_NO);
1575 "Got last ACK, finished message transmission to `%s' (%p)\n", 1554 for (fm = mas->endpoint->sending_messages_head; NULL != fm; fm = fm->next)
1576 wlan_plugin_address_to_string (NULL, 1555 {
1577 &mas->endpoint->wlan_addr, 1556 ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr);
1578 sizeof (mas->endpoint->wlan_addr)), 1557 if (GNUNET_OK == ret)
1579 fm); 1558 {
1580 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute (MACENDPOINT_TIMEOUT); 1559 LOG(GNUNET_ERROR_TYPE_DEBUG,
1581 if (NULL != fm->cont) 1560 "Got last ACK, finished message transmission to `%s' (%p)\n",
1582 { 1561 wlan_plugin_address_to_string(NULL,
1583 fm->cont (fm->cont_cls, 1562 &mas->endpoint->wlan_addr,
1584 &fm->target, 1563 sizeof(mas->endpoint->wlan_addr)),
1585 GNUNET_OK, 1564 fm);
1586 fm->size_payload, 1565 mas->endpoint->timeout = GNUNET_TIME_relative_to_absolute(MACENDPOINT_TIMEOUT);
1587 fm->size_on_wire); 1566 if (NULL != fm->cont)
1588 fm->cont = NULL; 1567 {
1589 } 1568 fm->cont(fm->cont_cls,
1590 free_fragment_message (fm); 1569 &fm->target,
1591 break; 1570 GNUNET_OK,
1592 } 1571 fm->size_payload,
1593 if (GNUNET_NO == ret) 1572 fm->size_on_wire);
1594 { 1573 fm->cont = NULL;
1595 LOG (GNUNET_ERROR_TYPE_DEBUG, 1574 }
1596 "Got an ACK, message transmission to `%s' not yet finished\n", 1575 free_fragment_message(fm);
1597 wlan_plugin_address_to_string (NULL, 1576 break;
1598 &mas->endpoint->wlan_addr, 1577 }
1599 sizeof (mas->endpoint->wlan_addr))); 1578 if (GNUNET_NO == ret)
1600 break; 1579 {
1601 } 1580 LOG(GNUNET_ERROR_TYPE_DEBUG,
1602 } 1581 "Got an ACK, message transmission to `%s' not yet finished\n",
1603 if (NULL == fm) 1582 wlan_plugin_address_to_string(NULL,
1604 LOG (GNUNET_ERROR_TYPE_DEBUG, 1583 &mas->endpoint->wlan_addr,
1605 "ACK not matched against any active fragmentation with MAC `%s'\n", 1584 sizeof(mas->endpoint->wlan_addr)));
1606 wlan_plugin_address_to_string (NULL, 1585 break;
1586 }
1587 }
1588 if (NULL == fm)
1589 LOG(GNUNET_ERROR_TYPE_DEBUG,
1590 "ACK not matched against any active fragmentation with MAC `%s'\n",
1591 wlan_plugin_address_to_string(NULL,
1607 &mas->endpoint->wlan_addr, 1592 &mas->endpoint->wlan_addr,
1608 sizeof (mas->endpoint->wlan_addr))); 1593 sizeof(mas->endpoint->wlan_addr)));
1609 break;
1610 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1611 if (NULL == mas->endpoint)
1612 {
1613 GNUNET_break (0);
1614 break;
1615 }
1616 if (msize < sizeof (struct WlanHeader))
1617 {
1618 GNUNET_break (0);
1619 break;
1620 }
1621 wlanheader = (const struct WlanHeader *) hdr;
1622 if (0 != memcmp (&wlanheader->target,
1623 plugin->env->my_identity,
1624 sizeof (struct GNUNET_PeerIdentity)))
1625 {
1626 LOG (GNUNET_ERROR_TYPE_DEBUG,
1627 "Data for `%s', not for me, ignoring\n",
1628 GNUNET_i2s (&wlanheader->target));
1629 break; 1594 break;
1630 } 1595
1631 if (ntohl (wlanheader->crc) != 1596 case GNUNET_MESSAGE_TYPE_WLAN_DATA:
1632 GNUNET_CRYPTO_crc32_n (&wlanheader[1], 1597 if (NULL == mas->endpoint)
1633 msize - sizeof (struct WlanHeader))) 1598 {
1634 { 1599 GNUNET_break(0);
1635 GNUNET_STATISTICS_update (plugin->env->stats, 1600 break;
1636 _("# DATA messages discarded due to CRC32 error"), 1601 }
1637 1, 1602 if (msize < sizeof(struct WlanHeader))
1638 GNUNET_NO); 1603 {
1639 break; 1604 GNUNET_break(0);
1640 } 1605 break;
1641 mas->session = lookup_session (mas->endpoint, 1606 }
1642 &wlanheader->sender); 1607 wlanheader = (const struct WlanHeader *)hdr;
1643 if (NULL == mas->session) 1608 if (0 != memcmp(&wlanheader->target,
1644 { 1609 plugin->env->my_identity,
1645 mas->session = create_session (mas->endpoint, 1610 sizeof(struct GNUNET_PeerIdentity)))
1646 &wlanheader->sender); 1611 {
1647 address = GNUNET_HELLO_address_allocate (&wlanheader->sender, 1612 LOG(GNUNET_ERROR_TYPE_DEBUG,
1648 PLUGIN_NAME, 1613 "Data for `%s', not for me, ignoring\n",
1649 &mas->endpoint->wlan_addr, 1614 GNUNET_i2s(&wlanheader->target));
1650 sizeof (struct WlanAddress), 1615 break;
1651 GNUNET_HELLO_ADDRESS_INFO_NONE); 1616 }
1652 plugin->env->session_start (plugin->env->cls, 1617 if (ntohl(wlanheader->crc) !=
1653 address, 1618 GNUNET_CRYPTO_crc32_n(&wlanheader[1],
1654 mas->session, 1619 msize - sizeof(struct WlanHeader)))
1655 scope); 1620 {
1656 LOG (GNUNET_ERROR_TYPE_DEBUG, 1621 GNUNET_STATISTICS_update(plugin->env->stats,
1657 "Notifying transport about peer `%s''s new session %p \n", 1622 _("# DATA messages discarded due to CRC32 error"),
1658 GNUNET_i2s (&wlanheader->sender), 1623 1,
1659 mas->session); 1624 GNUNET_NO);
1660 GNUNET_HELLO_address_free (address); 1625 break;
1661 } 1626 }
1662 LOG (GNUNET_ERROR_TYPE_DEBUG, 1627 mas->session = lookup_session(mas->endpoint,
1663 "Processing %u bytes of DATA from peer `%s'\n", 1628 &wlanheader->sender);
1664 (unsigned int) msize, 1629 if (NULL == mas->session)
1665 GNUNET_i2s (&wlanheader->sender)); 1630 {
1666 mas->session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1631 mas->session = create_session(mas->endpoint,
1667 (void) GNUNET_SERVER_mst_receive (plugin->wlan_header_payload_tokenizer, 1632 &wlanheader->sender);
1668 mas, 1633 address = GNUNET_HELLO_address_allocate(&wlanheader->sender,
1669 (const char *) &wlanheader[1], 1634 PLUGIN_NAME,
1670 msize - sizeof (struct WlanHeader), 1635 &mas->endpoint->wlan_addr,
1671 GNUNET_YES, 1636 sizeof(struct WlanAddress),
1637 GNUNET_HELLO_ADDRESS_INFO_NONE);
1638 plugin->env->session_start(plugin->env->cls,
1639 address,
1640 mas->session,
1641 scope);
1642 LOG(GNUNET_ERROR_TYPE_DEBUG,
1643 "Notifying transport about peer `%s''s new session %p \n",
1644 GNUNET_i2s(&wlanheader->sender),
1645 mas->session);
1646 GNUNET_HELLO_address_free(address);
1647 }
1648 LOG(GNUNET_ERROR_TYPE_DEBUG,
1649 "Processing %u bytes of DATA from peer `%s'\n",
1650 (unsigned int)msize,
1651 GNUNET_i2s(&wlanheader->sender));
1652 mas->session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1653 (void)GNUNET_SERVER_mst_receive(plugin->wlan_header_payload_tokenizer,
1654 mas,
1655 (const char *)&wlanheader[1],
1656 msize - sizeof(struct WlanHeader),
1657 GNUNET_YES,
1672 GNUNET_NO); 1658 GNUNET_NO);
1673 break;
1674 default:
1675 if (NULL == mas->endpoint)
1676 {
1677 GNUNET_break (0);
1678 break; 1659 break;
1679 } 1660
1680 if (NULL == mas->session) 1661 default:
1681 { 1662 if (NULL == mas->endpoint)
1682 GNUNET_break (0); 1663 {
1664 GNUNET_break(0);
1665 break;
1666 }
1667 if (NULL == mas->session)
1668 {
1669 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);
1683 break; 1681 break;
1684 } 1682 }
1685 LOG (GNUNET_ERROR_TYPE_DEBUG,
1686 "Received packet with %u bytes of type %u from peer %s\n",
1687 (unsigned int) msize,
1688 (unsigned int) ntohs (hdr->type),
1689 GNUNET_i2s (&mas->session->target));
1690 plugin->env->receive (plugin->env->cls,
1691 mas->session->address,
1692 mas->session,
1693 hdr);
1694 break;
1695 }
1696 return GNUNET_OK; 1683 return GNUNET_OK;
1697} 1684}
1698 1685
@@ -1703,7 +1690,7 @@ process_data (void *cls,
1703 * @param cls pointer to the plugin struct 1690 * @param cls pointer to the plugin struct
1704 */ 1691 */
1705static void 1692static void
1706send_hello_beacon (void *cls) 1693send_hello_beacon(void *cls)
1707{ 1694{
1708 struct Plugin *plugin = cls; 1695 struct Plugin *plugin = cls;
1709 uint16_t size; 1696 uint16_t size;
@@ -1711,42 +1698,42 @@ send_hello_beacon (void *cls)
1711 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader; 1698 struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *radioHeader;
1712 const struct GNUNET_MessageHeader *hello; 1699 const struct GNUNET_MessageHeader *hello;
1713 1700
1714 hello = plugin->env->get_our_hello (); 1701 hello = plugin->env->get_our_hello();
1715 if (NULL != hello) 1702 if (NULL != hello)
1716 { 1703 {
1717 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); 1704 hello_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message *)hello);
1718 GNUNET_assert (sizeof (struct WlanHeader) + hello_size <= WLAN_MTU); 1705 GNUNET_assert(sizeof(struct WlanHeader) + hello_size <= WLAN_MTU);
1719 size = sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size; 1706 size = sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) + hello_size;
1720 { 1707 {
1721 char buf[size] GNUNET_ALIGN; 1708 char buf[size] GNUNET_ALIGN;
1722 1709
1723 LOG (GNUNET_ERROR_TYPE_DEBUG, 1710 LOG(GNUNET_ERROR_TYPE_DEBUG,
1724 "Sending %u byte HELLO beacon\n", 1711 "Sending %u byte HELLO beacon\n",
1725 (unsigned int) size); 1712 (unsigned int)size);
1726 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*) buf; 1713 radioHeader = (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage*)buf;
1727 get_radiotap_header (NULL, radioHeader, size); 1714 get_radiotap_header(NULL, radioHeader, size);
1728 LOG (GNUNET_ERROR_TYPE_DEBUG, 1715 LOG(GNUNET_ERROR_TYPE_DEBUG,
1729 "Broadcasting %u bytes of data to MAC `%s'\n", 1716 "Broadcasting %u bytes of data to MAC `%s'\n",
1730 (unsigned int) size, 1717 (unsigned int)size,
1731 mac_to_string (&bc_all_mac)); 1718 mac_to_string(&bc_all_mac));
1732 get_wlan_header (plugin, &radioHeader->frame, &bc_all_mac, size); 1719 get_wlan_header(plugin, &radioHeader->frame, &bc_all_mac, size);
1733 GNUNET_memcpy (&radioHeader[1], hello, hello_size); 1720 GNUNET_memcpy(&radioHeader[1], hello, hello_size);
1734 if (NULL != 1721 if (NULL !=
1735 GNUNET_HELPER_send (plugin->suid_helper, 1722 GNUNET_HELPER_send(plugin->suid_helper,
1736 &radioHeader->header, 1723 &radioHeader->header,
1737 GNUNET_YES /* can drop */, 1724 GNUNET_YES /* can drop */,
1738 NULL, NULL)) 1725 NULL, NULL))
1739 GNUNET_STATISTICS_update (plugin->env->stats, 1726 GNUNET_STATISTICS_update(plugin->env->stats,
1740 _("# HELLO beacons sent"), 1727 _("# HELLO beacons sent"),
1741 1, GNUNET_NO); 1728 1, GNUNET_NO);
1742 } } 1729 }
1730 }
1743 plugin->beacon_task = 1731 plugin->beacon_task =
1744 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 1732 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply
1745 (HELLO_BEACON_SCALING_FACTOR, 1733 (HELLO_BEACON_SCALING_FACTOR,
1746 plugin->mac_count + 1), 1734 plugin->mac_count + 1),
1747 &send_hello_beacon, 1735 &send_hello_beacon,
1748 plugin); 1736 plugin);
1749
1750} 1737}
1751 1738
1752 1739
@@ -1757,8 +1744,8 @@ send_hello_beacon (void *cls)
1757 * @param hdr header of the GNUNET_MessageHeader 1744 * @param hdr header of the GNUNET_MessageHeader
1758 */ 1745 */
1759static int 1746static int
1760handle_helper_message (void *cls, 1747handle_helper_message(void *cls,
1761 const struct GNUNET_MessageHeader *hdr) 1748 const struct GNUNET_MessageHeader *hdr)
1762{ 1749{
1763 struct Plugin *plugin = cls; 1750 struct Plugin *plugin = cls;
1764 struct GNUNET_HELLO_Address *my_address; 1751 struct GNUNET_HELLO_Address *my_address;
@@ -1770,155 +1757,156 @@ handle_helper_message (void *cls,
1770 struct FragmentMessage *fm; 1757 struct FragmentMessage *fm;
1771 struct MacEndpoint *endpoint; 1758 struct MacEndpoint *endpoint;
1772 1759
1773 msize = ntohs (hdr->size); 1760 msize = ntohs(hdr->size);
1774 switch (ntohs (hdr->type)) 1761 switch (ntohs(hdr->type))
1775 {
1776 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
1777 if (msize != sizeof (struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1778 { 1762 {
1779 GNUNET_break (0); 1763 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
1780 break; 1764 if (msize != sizeof(struct GNUNET_TRANSPORT_WLAN_HelperControlMessage))
1781 } 1765 {
1782 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *) hdr; 1766 GNUNET_break(0);
1783 if (GNUNET_YES == plugin->have_mac) 1767 break;
1784 { 1768 }
1785 if (0 == memcmp (&plugin->mac_address, 1769 cm = (const struct GNUNET_TRANSPORT_WLAN_HelperControlMessage *)hdr;
1786 &cm->mac, 1770 if (GNUNET_YES == plugin->have_mac)
1787 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) 1771 {
1788 break; /* no change */ 1772 if (0 == memcmp(&plugin->mac_address,
1789 /* remove old address */ 1773 &cm->mac,
1790 memset (&wa, 0, sizeof (struct WlanAddress)); 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));
1791 wa.mac = plugin->mac_address; 1821 wa.mac = plugin->mac_address;
1792 wa.options = htonl(plugin->options); 1822 wa.options = htonl(plugin->options);
1793 my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1823 my_address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
1794 PLUGIN_NAME, 1824 PLUGIN_NAME,
1795 &wa, sizeof (wa), 1825 &wa, sizeof(wa),
1796 GNUNET_HELLO_ADDRESS_INFO_NONE); 1826 GNUNET_HELLO_ADDRESS_INFO_NONE);
1797 plugin->env->notify_address (plugin->env->cls, 1827
1798 GNUNET_NO, 1828 LOG(GNUNET_ERROR_TYPE_DEBUG,
1799 my_address); 1829 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n",
1800 GNUNET_HELLO_address_free (my_address); 1830 mac_to_string(&cm->mac),
1801 plugin->mac_address = cm->mac; 1831 GNUNET_i2s(plugin->env->my_identity));
1802 } 1832 plugin->env->notify_address(plugin->env->cls,
1803 else 1833 GNUNET_YES,
1804 { 1834 my_address);
1805 plugin->mac_address = cm->mac; 1835 GNUNET_HELLO_address_free(my_address);
1806 plugin->have_mac = GNUNET_YES; 1836 break;
1807 for (endpoint = plugin->mac_head; NULL != endpoint; endpoint = endpoint->next) 1837
1808 { 1838 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER:
1809 for (fm = endpoint->sending_messages_head; NULL != fm; fm = fm->next) 1839 LOG(GNUNET_ERROR_TYPE_DEBUG,
1840 "Got data message from helper with %u bytes\n",
1841 msize);
1842 GNUNET_STATISTICS_update(plugin->env->stats,
1843 _("# DATA messages received"), 1,
1844 GNUNET_NO);
1845 if (msize < sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1810 { 1846 {
1811 if (NULL != fm->fragcontext) 1847 LOG(GNUNET_ERROR_TYPE_DEBUG,
1812 { 1848 "Size of packet is too small (%u bytes < %u)\n",
1813 GNUNET_break (0); /* should not happen */ 1849 msize, sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage));
1814 continue; 1850 break;
1815 }
1816 fm->fragcontext =
1817 GNUNET_FRAGMENT_context_create (plugin->env->stats,
1818 WLAN_MTU,
1819 &plugin->tracker,
1820 fm->macendpoint->msg_delay,
1821 fm->macendpoint->ack_delay,
1822 fm->msg,
1823 &transmit_fragment, fm);
1824 GNUNET_free (fm->msg);
1825 fm->msg = NULL;
1826 } 1851 }
1827 } 1852 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *)hdr;
1828 GNUNET_break (NULL == plugin->beacon_task);
1829 plugin->beacon_task = GNUNET_SCHEDULER_add_now (&send_hello_beacon,
1830 plugin);
1831 1853
1832 } 1854 /* check if message is actually for us */
1855 if (0 != memcmp(&rxinfo->frame.addr3, &mac_bssid_gnunet,
1856 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1857 {
1858 /* Not the GNUnet BSSID */
1859 break;
1860 }
1861 if ((0 != memcmp(&rxinfo->frame.addr1, &bc_all_mac,
1862 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1863 (0 != memcmp(&rxinfo->frame.addr1, &plugin->mac_address,
1864 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress))))
1865 {
1866 /* Neither broadcast nor specifically for us */
1867 break;
1868 }
1869 if (0 == memcmp(&rxinfo->frame.addr2, &plugin->mac_address,
1870 sizeof(struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1871 {
1872 /* packet is FROM us, thus not FOR us */
1873 break;
1874 }
1833 1875
1834 memset (&wa, 0, sizeof (struct WlanAddress)); 1876 GNUNET_STATISTICS_update(plugin->env->stats,
1835 wa.mac = plugin->mac_address; 1877 _("# DATA messages processed"),
1836 wa.options = htonl(plugin->options); 1878 1, GNUNET_NO);
1837 my_address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 1879 LOG(GNUNET_ERROR_TYPE_DEBUG,
1838 PLUGIN_NAME, 1880 "Receiving %u bytes of data from MAC `%s'\n",
1839 &wa, sizeof (wa), 1881 (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1840 GNUNET_HELLO_ADDRESS_INFO_NONE); 1882 mac_to_string(&rxinfo->frame.addr2));
1841 1883 LOG(GNUNET_ERROR_TYPE_DEBUG,
1842 LOG (GNUNET_ERROR_TYPE_DEBUG, 1884 "Receiving %u bytes of data to MAC `%s'\n",
1843 "Received WLAN_HELPER_CONTROL message with MAC address `%s' for peer `%s'\n", 1885 (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1844 mac_to_string (&cm->mac), 1886 mac_to_string(&rxinfo->frame.addr1));
1845 GNUNET_i2s (plugin->env->my_identity)); 1887 LOG(GNUNET_ERROR_TYPE_DEBUG,
1846 plugin->env->notify_address (plugin->env->cls, 1888 "Receiving %u bytes of data with BSSID MAC `%s'\n",
1847 GNUNET_YES, 1889 (unsigned int)(msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1848 my_address); 1890 mac_to_string(&rxinfo->frame.addr3));
1849 GNUNET_HELLO_address_free (my_address); 1891 wa.mac = rxinfo->frame.addr2;
1850 break; 1892 wa.options = htonl(0);
1851 case GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER: 1893 mas.endpoint = create_macendpoint(plugin, &wa);
1852 LOG (GNUNET_ERROR_TYPE_DEBUG, 1894 mas.session = NULL;
1853 "Got data message from helper with %u bytes\n", 1895 (void)GNUNET_SERVER_mst_receive(plugin->helper_payload_tokenizer,
1854 msize); 1896 &mas,
1855 GNUNET_STATISTICS_update (plugin->env->stats, 1897 (const char*)&rxinfo[1],
1856 _("# DATA messages received"), 1, 1898 msize - sizeof(struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1857 GNUNET_NO); 1899 GNUNET_YES, GNUNET_NO);
1858 if (msize < sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage))
1859 {
1860 LOG (GNUNET_ERROR_TYPE_DEBUG,
1861 "Size of packet is too small (%u bytes < %u)\n",
1862 msize, sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage));
1863 break; 1900 break;
1864 }
1865 rxinfo = (const struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage *) hdr;
1866 1901
1867 /* check if message is actually for us */ 1902 default:
1868 if (0 != memcmp (&rxinfo->frame.addr3, &mac_bssid_gnunet, 1903 GNUNET_break(0);
1869 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) 1904 LOG(GNUNET_ERROR_TYPE_ERROR,
1870 { 1905 "Unexpected message of type %u (%u bytes)",
1871 /* Not the GNUnet BSSID */ 1906 ntohs(hdr->type),
1907 ntohs(hdr->size));
1872 break; 1908 break;
1873 } 1909 }
1874 if ( (0 != memcmp (&rxinfo->frame.addr1, &bc_all_mac,
1875 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) &&
1876 (0 != memcmp (&rxinfo->frame.addr1, &plugin->mac_address,
1877 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress))) )
1878 {
1879 /* Neither broadcast nor specifically for us */
1880 break;
1881 }
1882 if (0 == memcmp (&rxinfo->frame.addr2, &plugin->mac_address,
1883 sizeof (struct GNUNET_TRANSPORT_WLAN_MacAddress)))
1884 {
1885 /* packet is FROM us, thus not FOR us */
1886 break;
1887 }
1888
1889 GNUNET_STATISTICS_update (plugin->env->stats,
1890 _("# DATA messages processed"),
1891 1, GNUNET_NO);
1892 LOG (GNUNET_ERROR_TYPE_DEBUG,
1893 "Receiving %u bytes of data from MAC `%s'\n",
1894 (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1895 mac_to_string (&rxinfo->frame.addr2));
1896 LOG (GNUNET_ERROR_TYPE_DEBUG,
1897 "Receiving %u bytes of data to MAC `%s'\n",
1898 (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1899 mac_to_string (&rxinfo->frame.addr1));
1900 LOG (GNUNET_ERROR_TYPE_DEBUG,
1901 "Receiving %u bytes of data with BSSID MAC `%s'\n",
1902 (unsigned int) (msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage)),
1903 mac_to_string (&rxinfo->frame.addr3));
1904 wa.mac = rxinfo->frame.addr2;
1905 wa.options = htonl (0);
1906 mas.endpoint = create_macendpoint (plugin, &wa);
1907 mas.session = NULL;
1908 (void) GNUNET_SERVER_mst_receive (plugin->helper_payload_tokenizer,
1909 &mas,
1910 (const char*) &rxinfo[1],
1911 msize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage),
1912 GNUNET_YES, GNUNET_NO);
1913 break;
1914 default:
1915 GNUNET_break (0);
1916 LOG (GNUNET_ERROR_TYPE_ERROR,
1917 "Unexpected message of type %u (%u bytes)",
1918 ntohs (hdr->type),
1919 ntohs (hdr->size));
1920 break;
1921 }
1922 return GNUNET_OK; 1910 return GNUNET_OK;
1923} 1911}
1924 1912
@@ -1936,34 +1924,34 @@ handle_helper_message (void *cls,
1936 * and transport 1924 * and transport
1937 */ 1925 */
1938static int 1926static int
1939wlan_plugin_address_suggested (void *cls, 1927wlan_plugin_address_suggested(void *cls,
1940 const void *addr, 1928 const void *addr,
1941 size_t addrlen) 1929 size_t addrlen)
1942{ 1930{
1943 struct Plugin *plugin = cls; 1931 struct Plugin *plugin = cls;
1944 struct WlanAddress *wa = (struct WlanAddress *) addr; 1932 struct WlanAddress *wa = (struct WlanAddress *)addr;
1945 1933
1946 if (addrlen != sizeof (struct WlanAddress)) 1934 if (addrlen != sizeof(struct WlanAddress))
1947 { 1935 {
1948 GNUNET_break_op (0); 1936 GNUNET_break_op(0);
1949 return GNUNET_SYSERR; 1937 return GNUNET_SYSERR;
1950 } 1938 }
1951 if (GNUNET_YES != plugin->have_mac) 1939 if (GNUNET_YES != plugin->have_mac)
1952 { 1940 {
1953 LOG (GNUNET_ERROR_TYPE_DEBUG, 1941 LOG(GNUNET_ERROR_TYPE_DEBUG,
1954 "Rejecting MAC `%s': I don't know my MAC!\n", 1942 "Rejecting MAC `%s': I don't know my MAC!\n",
1955 mac_to_string (addr)); 1943 mac_to_string(addr));
1956 return GNUNET_NO; /* don't know my MAC */ 1944 return GNUNET_NO; /* don't know my MAC */
1957 } 1945 }
1958 if (0 != memcmp (&wa->mac, 1946 if (0 != memcmp(&wa->mac,
1959 &plugin->mac_address, 1947 &plugin->mac_address,
1960 sizeof (wa->mac))) 1948 sizeof(wa->mac)))
1961 { 1949 {
1962 LOG (GNUNET_ERROR_TYPE_DEBUG, 1950 LOG(GNUNET_ERROR_TYPE_DEBUG,
1963 "Rejecting MAC `%s': not my MAC!\n", 1951 "Rejecting MAC `%s': not my MAC!\n",
1964 mac_to_string (addr)); 1952 mac_to_string(addr));
1965 return GNUNET_NO; /* not my MAC */ 1953 return GNUNET_NO; /* not my MAC */
1966 } 1954 }
1967 return GNUNET_OK; 1955 return GNUNET_OK;
1968} 1956}
1969 1957
@@ -1982,27 +1970,27 @@ wlan_plugin_address_suggested (void *cls,
1982 * @param asc_cls closure for @a asc 1970 * @param asc_cls closure for @a asc
1983 */ 1971 */
1984static void 1972static void
1985wlan_plugin_address_pretty_printer (void *cls, 1973wlan_plugin_address_pretty_printer(void *cls,
1986 const char *type, 1974 const char *type,
1987 const void *addr, 1975 const void *addr,
1988 size_t addrlen, 1976 size_t addrlen,
1989 int numeric, 1977 int numeric,
1990 struct GNUNET_TIME_Relative timeout, 1978 struct GNUNET_TIME_Relative timeout,
1991 GNUNET_TRANSPORT_AddressStringCallback asc, 1979 GNUNET_TRANSPORT_AddressStringCallback asc,
1992 void *asc_cls) 1980 void *asc_cls)
1993{ 1981{
1994 const char *ret; 1982 const char *ret;
1995 1983
1996 if (sizeof (struct WlanAddress) == addrlen) 1984 if (sizeof(struct WlanAddress) == addrlen)
1997 ret = wlan_plugin_address_to_string (NULL, 1985 ret = wlan_plugin_address_to_string(NULL,
1998 addr, 1986 addr,
1999 addrlen); 1987 addrlen);
2000 else 1988 else
2001 ret = NULL; 1989 ret = NULL;
2002 asc (asc_cls, 1990 asc(asc_cls,
2003 ret, 1991 ret,
2004 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); 1992 (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK);
2005 asc (asc_cls, NULL, GNUNET_OK); 1993 asc(asc_cls, NULL, GNUNET_OK);
2006} 1994}
2007 1995
2008 1996
@@ -2012,7 +2000,7 @@ wlan_plugin_address_pretty_printer (void *cls,
2012 * @param cls pointer to the api struct 2000 * @param cls pointer to the api struct
2013 */ 2001 */
2014void * 2002void *
2015LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) 2003LIBGNUNET_PLUGIN_TRANSPORT_DONE(void *cls)
2016{ 2004{
2017 struct WlanAddress wa; 2005 struct WlanAddress wa;
2018 struct GNUNET_HELLO_Address *address; 2006 struct GNUNET_HELLO_Address *address;
@@ -2022,62 +2010,62 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2022 struct MacEndpoint *endpoint_next; 2010 struct MacEndpoint *endpoint_next;
2023 2011
2024 if (NULL == plugin) 2012 if (NULL == plugin)
2025 { 2013 {
2026 GNUNET_free (api); 2014 GNUNET_free(api);
2027 return NULL; 2015 return NULL;
2028 } 2016 }
2029 if (GNUNET_YES == plugin->have_mac) 2017 if (GNUNET_YES == plugin->have_mac)
2030 { 2018 {
2031 memset (&wa, 0, sizeof(wa)); 2019 memset(&wa, 0, sizeof(wa));
2032 wa.options = htonl (plugin->options); 2020 wa.options = htonl(plugin->options);
2033 wa.mac = plugin->mac_address; 2021 wa.mac = plugin->mac_address;
2034 address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, 2022 address = GNUNET_HELLO_address_allocate(plugin->env->my_identity,
2035 PLUGIN_NAME, 2023 PLUGIN_NAME,
2036 &wa, sizeof (struct WlanAddress), 2024 &wa, sizeof(struct WlanAddress),
2037 GNUNET_HELLO_ADDRESS_INFO_NONE); 2025 GNUNET_HELLO_ADDRESS_INFO_NONE);
2038 2026
2039 plugin->env->notify_address (plugin->env->cls, 2027 plugin->env->notify_address(plugin->env->cls,
2040 GNUNET_NO, 2028 GNUNET_NO,
2041 address); 2029 address);
2042 plugin->have_mac = GNUNET_NO; 2030 plugin->have_mac = GNUNET_NO;
2043 GNUNET_HELLO_address_free (address); 2031 GNUNET_HELLO_address_free(address);
2044 } 2032 }
2045 2033
2046 if (NULL != plugin->beacon_task) 2034 if (NULL != plugin->beacon_task)
2047 { 2035 {
2048 GNUNET_SCHEDULER_cancel (plugin->beacon_task); 2036 GNUNET_SCHEDULER_cancel(plugin->beacon_task);
2049 plugin->beacon_task = NULL; 2037 plugin->beacon_task = NULL;
2050 } 2038 }
2051 if (NULL != plugin->suid_helper) 2039 if (NULL != plugin->suid_helper)
2052 { 2040 {
2053 GNUNET_HELPER_stop (plugin->suid_helper, 2041 GNUNET_HELPER_stop(plugin->suid_helper,
2054 GNUNET_NO); 2042 GNUNET_NO);
2055 plugin->suid_helper = NULL; 2043 plugin->suid_helper = NULL;
2056 } 2044 }
2057 endpoint_next = plugin->mac_head; 2045 endpoint_next = plugin->mac_head;
2058 while (NULL != (endpoint = endpoint_next)) 2046 while (NULL != (endpoint = endpoint_next))
2059 { 2047 {
2060 endpoint_next = endpoint->next; 2048 endpoint_next = endpoint->next;
2061 free_macendpoint (endpoint); 2049 free_macendpoint(endpoint);
2062 } 2050 }
2063 if (NULL != plugin->fragment_data_tokenizer) 2051 if (NULL != plugin->fragment_data_tokenizer)
2064 { 2052 {
2065 GNUNET_SERVER_mst_destroy (plugin->fragment_data_tokenizer); 2053 GNUNET_SERVER_mst_destroy(plugin->fragment_data_tokenizer);
2066 plugin->fragment_data_tokenizer = NULL; 2054 plugin->fragment_data_tokenizer = NULL;
2067 } 2055 }
2068 if (NULL != plugin->wlan_header_payload_tokenizer) 2056 if (NULL != plugin->wlan_header_payload_tokenizer)
2069 { 2057 {
2070 GNUNET_SERVER_mst_destroy (plugin->wlan_header_payload_tokenizer); 2058 GNUNET_SERVER_mst_destroy(plugin->wlan_header_payload_tokenizer);
2071 plugin->wlan_header_payload_tokenizer = NULL; 2059 plugin->wlan_header_payload_tokenizer = NULL;
2072 } 2060 }
2073 if (NULL != plugin->helper_payload_tokenizer) 2061 if (NULL != plugin->helper_payload_tokenizer)
2074 { 2062 {
2075 GNUNET_SERVER_mst_destroy (plugin->helper_payload_tokenizer); 2063 GNUNET_SERVER_mst_destroy(plugin->helper_payload_tokenizer);
2076 plugin->helper_payload_tokenizer = NULL; 2064 plugin->helper_payload_tokenizer = NULL;
2077 } 2065 }
2078 GNUNET_free_non_null (plugin->wlan_interface); 2066 GNUNET_free_non_null(plugin->wlan_interface);
2079 GNUNET_free (plugin); 2067 GNUNET_free(plugin);
2080 GNUNET_free (api); 2068 GNUNET_free(api);
2081 return NULL; 2069 return NULL;
2082} 2070}
2083 2071
@@ -2095,11 +2083,11 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
2095 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 2083 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
2096 */ 2084 */
2097static int 2085static int
2098wlan_plugin_string_to_address (void *cls, 2086wlan_plugin_string_to_address(void *cls,
2099 const char *addr, 2087 const char *addr,
2100 uint16_t addrlen, 2088 uint16_t addrlen,
2101 void **buf, 2089 void **buf,
2102 size_t *added) 2090 size_t *added)
2103{ 2091{
2104 struct WlanAddress *wa; 2092 struct WlanAddress *wa;
2105 unsigned int a[6]; 2093 unsigned int a[6];
@@ -2108,36 +2096,36 @@ wlan_plugin_string_to_address (void *cls,
2108 uint32_t options; 2096 uint32_t options;
2109 2097
2110 if ((NULL == addr) || (0 == addrlen)) 2098 if ((NULL == addr) || (0 == addrlen))
2111 { 2099 {
2112 GNUNET_break (0); 2100 GNUNET_break(0);
2113 return GNUNET_SYSERR; 2101 return GNUNET_SYSERR;
2114 } 2102 }
2115 if ('\0' != addr[addrlen - 1]) 2103 if ('\0' != addr[addrlen - 1])
2116 { 2104 {
2117 GNUNET_break (0); 2105 GNUNET_break(0);
2118 return GNUNET_SYSERR; 2106 return GNUNET_SYSERR;
2119 } 2107 }
2120 if (strlen (addr) != addrlen - 1) 2108 if (strlen(addr) != addrlen - 1)
2121 { 2109 {
2122 GNUNET_break (0); 2110 GNUNET_break(0);
2123 return GNUNET_SYSERR; 2111 return GNUNET_SYSERR;
2124 } 2112 }
2125 2113
2126 if (8 != SSCANF (addr, 2114 if (8 != SSCANF(addr,
2127 "%4s.%u.%X:%X:%X:%X:%X:%X", 2115 "%4s.%u.%X:%X:%X:%X:%X:%X",
2128 plugin, &options, 2116 plugin, &options,
2129 &a[0], &a[1], &a[2], 2117 &a[0], &a[1], &a[2],
2130 &a[3], &a[4], &a[5])) 2118 &a[3], &a[4], &a[5]))
2131 { 2119 {
2132 GNUNET_break (0); 2120 GNUNET_break(0);
2133 return GNUNET_SYSERR; 2121 return GNUNET_SYSERR;
2134 } 2122 }
2135 wa = GNUNET_new (struct WlanAddress); 2123 wa = GNUNET_new(struct WlanAddress);
2136 for (i=0;i<6;i++) 2124 for (i = 0; i < 6; i++)
2137 wa->mac.mac[i] = a[i]; 2125 wa->mac.mac[i] = a[i];
2138 wa->options = htonl (0); 2126 wa->options = htonl(0);
2139 *buf = wa; 2127 *buf = wa;
2140 *added = sizeof (struct WlanAddress); 2128 *added = sizeof(struct WlanAddress);
2141 return GNUNET_OK; 2129 return GNUNET_OK;
2142} 2130}
2143 2131
@@ -2155,9 +2143,9 @@ wlan_plugin_string_to_address (void *cls,
2155 * @param sic_cls closure for @a sic 2143 * @param sic_cls closure for @a sic
2156 */ 2144 */
2157static void 2145static void
2158wlan_plugin_setup_monitor (void *cls, 2146wlan_plugin_setup_monitor(void *cls,
2159 GNUNET_TRANSPORT_SessionInfoCallback sic, 2147 GNUNET_TRANSPORT_SessionInfoCallback sic,
2160 void *sic_cls) 2148 void *sic_cls)
2161{ 2149{
2162 struct Plugin *plugin = cls; 2150 struct Plugin *plugin = cls;
2163 struct MacEndpoint *mac; 2151 struct MacEndpoint *mac;
@@ -2166,19 +2154,19 @@ wlan_plugin_setup_monitor (void *cls,
2166 plugin->sic = sic; 2154 plugin->sic = sic;
2167 plugin->sic_cls = sic_cls; 2155 plugin->sic_cls = sic_cls;
2168 if (NULL != sic) 2156 if (NULL != sic)
2169 { 2157 {
2170 for (mac = plugin->mac_head; NULL != mac; mac = mac->next) 2158 for (mac = plugin->mac_head; NULL != mac; mac = mac->next)
2171 for (session = mac->sessions_head; NULL != session; session = session->next) 2159 for (session = mac->sessions_head; NULL != session; session = session->next)
2172 { 2160 {
2173 notify_session_monitor (plugin, 2161 notify_session_monitor(plugin,
2174 session, 2162 session,
2175 GNUNET_TRANSPORT_SS_INIT); 2163 GNUNET_TRANSPORT_SS_INIT);
2176 notify_session_monitor (plugin, 2164 notify_session_monitor(plugin,
2177 session, 2165 session,
2178 GNUNET_TRANSPORT_SS_UP); 2166 GNUNET_TRANSPORT_SS_UP);
2179 } 2167 }
2180 sic (sic_cls, NULL, NULL); 2168 sic(sic_cls, NULL, NULL);
2181 } 2169 }
2182} 2170}
2183 2171
2184 2172
@@ -2193,12 +2181,12 @@ wlan_plugin_setup_monitor (void *cls,
2193 * @param session which session is being updated 2181 * @param session which session is being updated
2194 */ 2182 */
2195static void 2183static void
2196wlan_plugin_update_session_timeout (void *cls, 2184wlan_plugin_update_session_timeout(void *cls,
2197 const struct GNUNET_PeerIdentity *peer, 2185 const struct GNUNET_PeerIdentity *peer,
2198 struct GNUNET_ATS_Session *session) 2186 struct GNUNET_ATS_Session *session)
2199{ 2187{
2200 GNUNET_assert (NULL != session->timeout_task); 2188 GNUNET_assert(NULL != session->timeout_task);
2201 session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2189 session->timeout = GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2202} 2190}
2203 2191
2204 2192
@@ -2213,10 +2201,10 @@ wlan_plugin_update_session_timeout (void *cls,
2213 * @param delay new delay to use for receiving 2201 * @param delay new delay to use for receiving
2214 */ 2202 */
2215static void 2203static void
2216wlan_plugin_update_inbound_delay (void *cls, 2204wlan_plugin_update_inbound_delay(void *cls,
2217 const struct GNUNET_PeerIdentity *peer, 2205 const struct GNUNET_PeerIdentity *peer,
2218 struct GNUNET_ATS_Session *session, 2206 struct GNUNET_ATS_Session *session,
2219 struct GNUNET_TIME_Relative delay) 2207 struct GNUNET_TIME_Relative delay)
2220{ 2208{
2221 /* does nothing, as inbound delay is not supported by WLAN */ 2209 /* does nothing, as inbound delay is not supported by WLAN */
2222} 2210}
@@ -2229,7 +2217,7 @@ wlan_plugin_update_inbound_delay (void *cls,
2229 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error 2217 * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error
2230 */ 2218 */
2231void * 2219void *
2232LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) 2220LIBGNUNET_PLUGIN_TRANSPORT_INIT(void *cls)
2233{ 2221{
2234 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2222 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
2235 struct GNUNET_TRANSPORT_PluginFunctions *api; 2223 struct GNUNET_TRANSPORT_PluginFunctions *api;
@@ -2240,124 +2228,127 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
2240 2228
2241 /* check for 'special' mode */ 2229 /* check for 'special' mode */
2242 if (NULL == env->receive) 2230 if (NULL == env->receive)
2243 { 2231 {
2244 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully 2232 /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
2245 initialze the plugin or the API */ 2233 initialze the plugin or the API */
2246 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 2234 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
2247 api->cls = NULL; 2235 api->cls = NULL;
2248 api->address_pretty_printer = &wlan_plugin_address_pretty_printer; 2236 api->address_pretty_printer = &wlan_plugin_address_pretty_printer;
2249 api->address_to_string = &wlan_plugin_address_to_string; 2237 api->address_to_string = &wlan_plugin_address_to_string;
2250 api->string_to_address = &wlan_plugin_string_to_address; 2238 api->string_to_address = &wlan_plugin_string_to_address;
2251 return api; 2239 return api;
2252 } 2240 }
2253 2241
2254 testmode = 0; 2242 testmode = 0;
2255 /* check configuration */ 2243 /* check configuration */
2256 if ( (GNUNET_YES == 2244 if ((GNUNET_YES ==
2257 GNUNET_CONFIGURATION_have_value (env->cfg, 2245 GNUNET_CONFIGURATION_have_value(env->cfg,
2258 CONFIG_NAME, 2246 CONFIG_NAME,
2259 "TESTMODE")) && 2247 "TESTMODE")) &&
2260 ( (GNUNET_SYSERR == 2248 ((GNUNET_SYSERR ==
2261 GNUNET_CONFIGURATION_get_value_number (env->cfg, 2249 GNUNET_CONFIGURATION_get_value_number(env->cfg,
2262 CONFIG_NAME, 2250 CONFIG_NAME,
2263 "TESTMODE", 2251 "TESTMODE",
2264 &testmode)) || 2252 &testmode)) ||
2265 (testmode > 2) ) ) 2253 (testmode > 2)))
2266 { 2254 {
2267 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2255 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
2268 CONFIG_NAME, 2256 CONFIG_NAME,
2269 "TESTMODE"); 2257 "TESTMODE");
2270 return NULL; 2258 return NULL;
2271 } 2259 }
2272 binary = GNUNET_OS_get_libexec_binary_path (HELPER_NAME); 2260 binary = GNUNET_OS_get_libexec_binary_path(HELPER_NAME);
2273 if ( (0 == testmode) && 2261 if ((0 == testmode) &&
2274 (GNUNET_YES != 2262 (GNUNET_YES !=
2275 GNUNET_OS_check_helper_binary (binary, 2263 GNUNET_OS_check_helper_binary(binary,
2276 GNUNET_YES, 2264 GNUNET_YES,
2277 NULL)) ) 2265 NULL)))
2278 { 2266 {
2279 LOG (GNUNET_ERROR_TYPE_ERROR, 2267 LOG(GNUNET_ERROR_TYPE_ERROR,
2280 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"), 2268 _("Helper binary `%s' not SUID, cannot run WLAN transport\n"),
2281 HELPER_NAME); 2269 HELPER_NAME);
2282 GNUNET_free (binary); 2270 GNUNET_free(binary);
2283 return NULL; 2271 return NULL;
2284 } 2272 }
2285 GNUNET_free (binary); 2273 GNUNET_free(binary);
2286 if (GNUNET_YES != 2274 if (GNUNET_YES !=
2287 GNUNET_CONFIGURATION_get_value_string (env->cfg, 2275 GNUNET_CONFIGURATION_get_value_string(env->cfg,
2288 CONFIG_NAME, 2276 CONFIG_NAME,
2289 "INTERFACE", 2277 "INTERFACE",
2290 &wlan_interface)) 2278 &wlan_interface))
2291 { 2279 {
2292 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 2280 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
2293 CONFIG_NAME, 2281 CONFIG_NAME,
2294 "INTERFACE"); 2282 "INTERFACE");
2295 return NULL; 2283 return NULL;
2296 } 2284 }
2297 2285
2298 plugin = GNUNET_new (struct Plugin); 2286 plugin = GNUNET_new(struct Plugin);
2299 plugin->wlan_interface = wlan_interface; 2287 plugin->wlan_interface = wlan_interface;
2300 plugin->env = env; 2288 plugin->env = env;
2301 GNUNET_STATISTICS_set (plugin->env->stats, 2289 GNUNET_STATISTICS_set(plugin->env->stats,
2302 _("# sessions allocated"), 2290 _("# sessions allocated"),
2303 0, GNUNET_NO); 2291 0, GNUNET_NO);
2304 GNUNET_STATISTICS_set (plugin->env->stats, 2292 GNUNET_STATISTICS_set(plugin->env->stats,
2305 _("# MAC endpoints allocated"), 2293 _("# MAC endpoints allocated"),
2306 0, 0); 2294 0, 0);
2307 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, NULL, NULL, 2295 GNUNET_BANDWIDTH_tracker_init(&plugin->tracker, NULL, NULL,
2308 GNUNET_BANDWIDTH_value_init (100 * 1024 * 2296 GNUNET_BANDWIDTH_value_init(100 * 1024 *
2309 1024 / 8), 2297 1024 / 8),
2310 100); 2298 100);
2311 plugin->fragment_data_tokenizer = GNUNET_SERVER_mst_create (&process_data, 2299 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,
2312 plugin); 2304 plugin);
2313 plugin->wlan_header_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
2314 plugin);
2315 plugin->helper_payload_tokenizer = GNUNET_SERVER_mst_create (&process_data,
2316 plugin);
2317 2305
2318 plugin->options = 0; 2306 plugin->options = 0;
2319 2307
2320 /* some compilers do not like switch on 'long long'... */ 2308 /* some compilers do not like switch on 'long long'... */
2321 switch ((unsigned int) testmode) 2309 switch ((unsigned int)testmode)
2322 { 2310 {
2323 case 0: /* normal */ 2311 case 0: /* normal */
2324 plugin->helper_argv[0] = (char *) HELPER_NAME; 2312 plugin->helper_argv[0] = (char *)HELPER_NAME;
2325 plugin->helper_argv[1] = wlan_interface; 2313 plugin->helper_argv[1] = wlan_interface;
2326 plugin->helper_argv[2] = NULL; 2314 plugin->helper_argv[2] = NULL;
2327 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO, 2315 plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO,
2328 HELPER_NAME, 2316 HELPER_NAME,
2329 plugin->helper_argv, 2317 plugin->helper_argv,
2330 &handle_helper_message, 2318 &handle_helper_message,
2331 NULL, 2319 NULL,
2332 plugin); 2320 plugin);
2333 break; 2321 break;
2334 case 1: /* testmode, peer 1 */ 2322
2335 plugin->helper_argv[0] = (char *) DUMMY_HELPER_NAME; 2323 case 1: /* testmode, peer 1 */
2336 plugin->helper_argv[1] = (char *) "1"; 2324 plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME;
2337 plugin->helper_argv[2] = NULL; 2325 plugin->helper_argv[1] = (char *)"1";
2338 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO, 2326 plugin->helper_argv[2] = NULL;
2339 DUMMY_HELPER_NAME, 2327 plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO,
2340 plugin->helper_argv, 2328 DUMMY_HELPER_NAME,
2341 &handle_helper_message, 2329 plugin->helper_argv,
2342 NULL, 2330 &handle_helper_message,
2343 plugin); 2331 NULL,
2344 break; 2332 plugin);
2345 case 2: /* testmode, peer 2 */ 2333 break;
2346 plugin->helper_argv[0] = (char *) DUMMY_HELPER_NAME; 2334
2347 plugin->helper_argv[1] = (char *) "2"; 2335 case 2: /* testmode, peer 2 */
2348 plugin->helper_argv[2] = NULL; 2336 plugin->helper_argv[0] = (char *)DUMMY_HELPER_NAME;
2349 plugin->suid_helper = GNUNET_HELPER_start (GNUNET_NO, 2337 plugin->helper_argv[1] = (char *)"2";
2350 DUMMY_HELPER_NAME, 2338 plugin->helper_argv[2] = NULL;
2351 plugin->helper_argv, 2339 plugin->suid_helper = GNUNET_HELPER_start(GNUNET_NO,
2352 &handle_helper_message, 2340 DUMMY_HELPER_NAME,
2353 NULL, 2341 plugin->helper_argv,
2354 plugin); 2342 &handle_helper_message,
2355 break; 2343 NULL,
2356 default: 2344 plugin);
2357 GNUNET_assert (0); 2345 break;
2358 } 2346
2347 default:
2348 GNUNET_assert(0);
2349 }
2359 2350
2360 api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); 2351 api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions);
2361 api->cls = plugin; 2352 api->cls = plugin;
2362 api->send = &wlan_plugin_send; 2353 api->send = &wlan_plugin_send;
2363 api->get_session = &wlan_plugin_get_session; 2354 api->get_session = &wlan_plugin_get_session;
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index 926e16e6f..cdc3e34ff 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2010, 2011 GNUnet e.V. 3 Copyright (C) 2010, 2011 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -34,7 +34,7 @@
34 */ 34 */
35#ifdef MINGW 35#ifdef MINGW
36 #define MAC_ADDR_SIZE 8 36 #define MAC_ADDR_SIZE 8
37 typedef uint8_t u_int8_t; 37typedef uint8_t u_int8_t;
38#else 38#else
39 #define MAC_ADDR_SIZE 6 39 #define MAC_ADDR_SIZE 6
40#endif 40#endif
@@ -63,16 +63,14 @@ GNUNET_NETWORK_STRUCT_BEGIN
63/** 63/**
64 * A MAC Address. 64 * A MAC Address.
65 */ 65 */
66struct GNUNET_TRANSPORT_WLAN_MacAddress 66struct GNUNET_TRANSPORT_WLAN_MacAddress {
67{
68 uint8_t mac[MAC_ADDR_SIZE]; 67 uint8_t mac[MAC_ADDR_SIZE];
69}; 68};
70 69
71/** 70/**
72 * Format of a WLAN Control Message. 71 * Format of a WLAN Control Message.
73 */ 72 */
74struct GNUNET_TRANSPORT_WLAN_HelperControlMessage 73struct GNUNET_TRANSPORT_WLAN_HelperControlMessage {
75{
76 /** 74 /**
77 * Message header. Type is 75 * Message header. Type is
78 * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL 76 * GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL
@@ -88,9 +86,7 @@ struct GNUNET_TRANSPORT_WLAN_HelperControlMessage
88/** 86/**
89 * generic definitions for IEEE 802.3 frames 87 * generic definitions for IEEE 802.3 frames
90 */ 88 */
91struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame 89struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame {
92{
93
94 /** 90 /**
95 * Address 1: destination address in ad-hoc mode or AP, BSSID if station, 91 * Address 1: destination address in ad-hoc mode or AP, BSSID if station,
96 */ 92 */
@@ -105,15 +101,13 @@ struct GNUNET_TRANSPORT_WLAN_Ieee8023Frame
105 * Packet type ID. 101 * Packet type ID.
106 */ 102 */
107 uint16_t type; 103 uint16_t type;
108
109}; 104};
110 105
111 106
112/** 107/**
113 * generic definitions for IEEE 802.11 frames 108 * generic definitions for IEEE 802.11 frames
114 */ 109 */
115struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame 110struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame {
116{
117 /** 111 /**
118 * 802.11 Frame Control field. A bitmask. The overall field is a 112 * 802.11 Frame Control field. A bitmask. The overall field is a
119 * 16-bit mask of the respecitve fields. The lowest two bits should 113 * 16-bit mask of the respecitve fields. The lowest two bits should
@@ -157,7 +151,6 @@ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame
157 u_int8_t llc[4]; 151 u_int8_t llc[4];
158 152
159 /* payload */ 153 /* payload */
160
161} GNUNET_PACKED; 154} GNUNET_PACKED;
162 155
163 156
@@ -166,9 +159,7 @@ struct GNUNET_TRANSPORT_WLAN_Ieee80211Frame
166 * Message from the plugin to the WLAN helper: send the given message with the 159 * Message from the plugin to the WLAN helper: send the given message with the
167 * given connection parameters. 160 * given connection parameters.
168 */ 161 */
169struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage 162struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage {
170{
171
172 /** 163 /**
173 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'. 164 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER'.
174 */ 165 */
@@ -207,9 +198,7 @@ struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage
207/** 198/**
208 * 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
209 */ 200 */
210struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage 201struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage {
211{
212
213 /** 202 /**
214 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'. 203 * Type is 'GNUNET_MESSAGE_TYPE_WLAN_DATA_FROM_HELPER'.
215 */ 204 */
@@ -273,7 +262,7 @@ GNUNET_NETWORK_STRUCT_END
273 * GNUnet bssid 262 * GNUnet bssid
274 */ 263 */
275static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = { 264static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = {
276 {0x13, 0x22, 0x33, 0x44, 0x55, 0x66} 265 { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 }
277}; 266};
278 267
279 268
@@ -281,7 +270,7 @@ static const struct GNUNET_TRANSPORT_WLAN_MacAddress mac_bssid_gnunet = {
281 * Broadcast MAC 270 * Broadcast MAC
282 */ 271 */
283static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = { 272static const struct GNUNET_TRANSPORT_WLAN_MacAddress bc_all_mac = {
284 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} 273 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }
285}; 274};
286 275
287#endif 276#endif
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c
index 999e8827a..42fe6a8a6 100644
--- a/src/transport/tcp_connection_legacy.c
+++ b/src/transport/tcp_connection_legacy.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/connection.c 22 * @file util/connection.c
@@ -42,19 +42,17 @@
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{
57
58 /** 56 /**
59 * Function to call if the send buffer has notify_size 57 * Function to call if the send buffer has notify_size
60 * bytes available. 58 * bytes available.
@@ -93,9 +91,7 @@ struct GNUNET_CONNECTION_TransmitHandle
93 * During connect, we try multiple possible IP addresses 91 * During connect, we try multiple possible IP addresses
94 * to find out which one might work. 92 * to find out which one might work.
95 */ 93 */
96struct AddressProbe 94struct AddressProbe {
97{
98
99 /** 95 /**
100 * This is a linked list. 96 * This is a linked list.
101 */ 97 */
@@ -136,9 +132,7 @@ struct AddressProbe
136/** 132/**
137 * @brief handle for a network connection 133 * @brief handle for a network connection
138 */ 134 */
139struct GNUNET_CONNECTION_Handle 135struct GNUNET_CONNECTION_Handle {
140{
141
142 /** 136 /**
143 * Configuration to use. 137 * Configuration to use.
144 */ 138 */
@@ -274,7 +268,7 @@ struct GNUNET_CONNECTION_Handle
274 * @param connection the connection to set persistent 268 * @param connection the connection to set persistent
275 */ 269 */
276void 270void
277GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection) 271GNUNET_CONNECTION_persist_(struct GNUNET_CONNECTION_Handle *connection)
278{ 272{
279 connection->persist = GNUNET_YES; 273 connection->persist = GNUNET_YES;
280} 274}
@@ -292,9 +286,9 @@ GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection)
292 * @return #GNUNET_OK on success 286 * @return #GNUNET_OK on success
293 */ 287 */
294int 288int
295GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection) 289GNUNET_CONNECTION_disable_corking(struct GNUNET_CONNECTION_Handle *connection)
296{ 290{
297 return GNUNET_NETWORK_socket_disable_corking (connection->sock); 291 return GNUNET_NETWORK_socket_disable_corking(connection->sock);
298} 292}
299 293
300 294
@@ -307,13 +301,13 @@ GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection)
307 * @return the boxed connection handle 301 * @return the boxed connection handle
308 */ 302 */
309struct GNUNET_CONNECTION_Handle * 303struct GNUNET_CONNECTION_Handle *
310GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket) 304GNUNET_CONNECTION_create_from_existing(struct GNUNET_NETWORK_Handle *osSocket)
311{ 305{
312 struct GNUNET_CONNECTION_Handle *connection; 306 struct GNUNET_CONNECTION_Handle *connection;
313 307
314 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); 308 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle);
315 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 309 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
316 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); 310 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size);
317 connection->sock = osSocket; 311 connection->sock = osSocket;
318 return connection; 312 return connection;
319} 313}
@@ -329,9 +323,9 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket)
329 * @return the connection handle, NULL on error 323 * @return the connection handle, NULL on error
330 */ 324 */
331struct GNUNET_CONNECTION_Handle * 325struct GNUNET_CONNECTION_Handle *
332GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, 326GNUNET_CONNECTION_create_from_accept(GNUNET_CONNECTION_AccessCheck access_cb,
333 void *access_cb_cls, 327 void *access_cb_cls,
334 struct GNUNET_NETWORK_Handle *lsock) 328 struct GNUNET_NETWORK_Handle *lsock)
335{ 329{
336 struct GNUNET_CONNECTION_Handle *connection; 330 struct GNUNET_CONNECTION_Handle *connection;
337 char addr[128]; 331 char addr[128];
@@ -342,6 +336,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
342 struct sockaddr_in6 *v6; 336 struct sockaddr_in6 *v6;
343 struct sockaddr *sa; 337 struct sockaddr *sa;
344 void *uaddr; 338 void *uaddr;
339
345#ifdef SO_PEERCRED 340#ifdef SO_PEERCRED
346 struct ucred uc; 341 struct ucred uc;
347 socklen_t olen; 342 socklen_t olen;
@@ -354,109 +349,109 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
354 gc.gid = 0; 349 gc.gid = 0;
355#endif 350#endif
356 351
357 addrlen = sizeof (addr); 352 addrlen = sizeof(addr);
358 sock = 353 sock =
359 GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); 354 GNUNET_NETWORK_socket_accept(lsock, (struct sockaddr *)&addr, &addrlen);
360 if (NULL == sock) 355 if (NULL == sock)
361 { 356 {
362 if (EAGAIN != errno) 357 if (EAGAIN != errno)
363 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "accept"); 358 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "accept");
364 return NULL; 359 return NULL;
365 } 360 }
366 if ((addrlen > sizeof (addr)) || (addrlen < sizeof (sa_family_t))) 361 if ((addrlen > sizeof(addr)) || (addrlen < sizeof(sa_family_t)))
367 { 362 {
368 GNUNET_break (0); 363 GNUNET_break(0);
369 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 364 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock));
370 return NULL; 365 return NULL;
371 } 366 }
372 367
373 sa = (struct sockaddr *) addr; 368 sa = (struct sockaddr *)addr;
374 v6 = (struct sockaddr_in6 *) addr; 369 v6 = (struct sockaddr_in6 *)addr;
375 if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) 370 if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED(&v6->sin6_addr)))
376 { 371 {
377 /* convert to V4 address */ 372 /* convert to V4 address */
378 v4 = GNUNET_new (struct sockaddr_in); 373 v4 = GNUNET_new(struct sockaddr_in);
379 memset (v4, 0, sizeof (struct sockaddr_in)); 374 memset(v4, 0, sizeof(struct sockaddr_in));
380 v4->sin_family = AF_INET; 375 v4->sin_family = AF_INET;
381#if HAVE_SOCKADDR_IN_SIN_LEN 376#if HAVE_SOCKADDR_IN_SIN_LEN
382 v4->sin_len = (u_char) sizeof (struct sockaddr_in); 377 v4->sin_len = (u_char)sizeof(struct sockaddr_in);
383#endif 378#endif
384 GNUNET_memcpy (&v4->sin_addr, 379 GNUNET_memcpy(&v4->sin_addr,
385 &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - 380 &((char *)&v6->sin6_addr)[sizeof(struct in6_addr) -
386 sizeof (struct in_addr)], 381 sizeof(struct in_addr)],
387 sizeof (struct in_addr)); 382 sizeof(struct in_addr));
388 v4->sin_port = v6->sin6_port; 383 v4->sin_port = v6->sin6_port;
389 uaddr = v4; 384 uaddr = v4;
390 addrlen = sizeof (struct sockaddr_in); 385 addrlen = sizeof(struct sockaddr_in);
391 } 386 }
392 else 387 else
393 { 388 {
394 uaddr = GNUNET_malloc (addrlen); 389 uaddr = GNUNET_malloc(addrlen);
395 GNUNET_memcpy (uaddr, addr, addrlen); 390 GNUNET_memcpy(uaddr, addr, addrlen);
396 } 391 }
397 gcp = NULL; 392 gcp = NULL;
398 if (AF_UNIX == sa->sa_family) 393 if (AF_UNIX == sa->sa_family)
399 { 394 {
400#if HAVE_GETPEEREID 395#if HAVE_GETPEEREID
401 /* most BSDs */ 396 /* most BSDs */
402 if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) 397 if (0 == getpeereid(GNUNET_NETWORK_get_fd(sock), &gc.uid, &gc.gid))
403 gcp = &gc; 398 gcp = &gc;
404#else 399#else
405#ifdef SO_PEERCRED 400#ifdef SO_PEERCRED
406 /* largely traditional GNU/Linux */ 401 /* largely traditional GNU/Linux */
407 olen = sizeof (uc); 402 olen = sizeof(uc);
408 if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock), 403 if ((0 == getsockopt(GNUNET_NETWORK_get_fd(sock),
409 SOL_SOCKET, 404 SOL_SOCKET,
410 SO_PEERCRED, 405 SO_PEERCRED,
411 &uc, 406 &uc,
412 &olen)) && 407 &olen)) &&
413 (olen == sizeof (uc))) 408 (olen == sizeof(uc)))
414 { 409 {
415 gc.uid = uc.uid; 410 gc.uid = uc.uid;
416 gc.gid = uc.gid; 411 gc.gid = uc.gid;
417 gcp = &gc; 412 gcp = &gc;
418 } 413 }
419#else 414#else
420#if HAVE_GETPEERUCRED 415#if HAVE_GETPEERUCRED
421 /* this is for Solaris 10 */ 416 /* this is for Solaris 10 */
422 ucred_t *uc; 417 ucred_t *uc;
423 418
424 uc = NULL; 419 uc = NULL;
425 if (0 == getpeerucred (GNUNET_NETWORK_get_fd (sock), &uc)) 420 if (0 == getpeerucred(GNUNET_NETWORK_get_fd(sock), &uc))
426 { 421 {
427 gc.uid = ucred_geteuid (uc); 422 gc.uid = ucred_geteuid(uc);
428 gc.gid = ucred_getegid (uc); 423 gc.gid = ucred_getegid(uc);
429 gcp = &gc; 424 gcp = &gc;
430 } 425 }
431 ucred_free (uc); 426 ucred_free(uc);
432#endif 427#endif
433#endif 428#endif
434#endif 429#endif
435 } 430 }
436 431
437 if ((NULL != access_cb) && 432 if ((NULL != access_cb) &&
438 (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen)))) 433 (GNUNET_YES != (aret = access_cb(access_cb_cls, gcp, uaddr, addrlen))))
439 { 434 {
440 if (GNUNET_NO == aret) 435 if (GNUNET_NO == aret)
441 LOG (GNUNET_ERROR_TYPE_INFO, 436 LOG(GNUNET_ERROR_TYPE_INFO,
442 _ ("Access denied to `%s'\n"), 437 _("Access denied to `%s'\n"),
443 GNUNET_a2s (uaddr, addrlen)); 438 GNUNET_a2s(uaddr, addrlen));
444 GNUNET_break (GNUNET_OK == 439 GNUNET_break(GNUNET_OK ==
445 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); 440 GNUNET_NETWORK_socket_shutdown(sock, SHUT_RDWR));
446 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 441 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock));
447 GNUNET_free (uaddr); 442 GNUNET_free(uaddr);
448 return NULL; 443 return NULL;
449 } 444 }
450 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); 445 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle);
451 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 446 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
452 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); 447 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size);
453 connection->addr = uaddr; 448 connection->addr = uaddr;
454 connection->addrlen = addrlen; 449 connection->addrlen = addrlen;
455 connection->sock = sock; 450 connection->sock = sock;
456 LOG (GNUNET_ERROR_TYPE_INFO, 451 LOG(GNUNET_ERROR_TYPE_INFO,
457 _ ("Accepting connection from `%s': %p\n"), 452 _("Accepting connection from `%s': %p\n"),
458 GNUNET_a2s (uaddr, addrlen), 453 GNUNET_a2s(uaddr, addrlen),
459 connection); 454 connection);
460 return connection; 455 return connection;
461} 456}
462 457
@@ -470,14 +465,14 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb,
470 * @return #GNUNET_OK on success 465 * @return #GNUNET_OK on success
471 */ 466 */
472int 467int
473GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, 468GNUNET_CONNECTION_get_address(struct GNUNET_CONNECTION_Handle *connection,
474 void **addr, 469 void **addr,
475 size_t *addrlen) 470 size_t *addrlen)
476{ 471{
477 if ((NULL == connection->addr) || (0 == connection->addrlen)) 472 if ((NULL == connection->addr) || (0 == connection->addrlen))
478 return GNUNET_NO; 473 return GNUNET_NO;
479 *addr = GNUNET_malloc (connection->addrlen); 474 *addr = GNUNET_malloc(connection->addrlen);
480 GNUNET_memcpy (*addr, connection->addr, connection->addrlen); 475 GNUNET_memcpy(*addr, connection->addr, connection->addrlen);
481 *addrlen = connection->addrlen; 476 *addrlen = connection->addrlen;
482 return GNUNET_OK; 477 return GNUNET_OK;
483} 478}
@@ -490,22 +485,22 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection,
490 * @param errcode error code to send 485 * @param errcode error code to send
491 */ 486 */
492static void 487static void
493signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode) 488signal_receive_error(struct GNUNET_CONNECTION_Handle *connection, int errcode)
494{ 489{
495 GNUNET_CONNECTION_Receiver receiver; 490 GNUNET_CONNECTION_Receiver receiver;
496 491
497 LOG (GNUNET_ERROR_TYPE_DEBUG, 492 LOG(GNUNET_ERROR_TYPE_DEBUG,
498 "Receive encounters error (%s), connection closed (%p)\n", 493 "Receive encounters error (%s), connection closed (%p)\n",
499 strerror (errcode), 494 strerror(errcode),
500 connection); 495 connection);
501 GNUNET_assert (NULL != (receiver = connection->receiver)); 496 GNUNET_assert(NULL != (receiver = connection->receiver));
502 connection->receiver = NULL; 497 connection->receiver = NULL;
503 receiver (connection->receiver_cls, 498 receiver(connection->receiver_cls,
504 NULL, 499 NULL,
505 0, 500 0,
506 connection->addr, 501 connection->addr,
507 connection->addrlen, 502 connection->addrlen,
508 errcode); 503 errcode);
509} 504}
510 505
511 506
@@ -515,16 +510,16 @@ signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode)
515 * @param connection connection to signal for 510 * @param connection connection to signal for
516 */ 511 */
517static void 512static void
518signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection) 513signal_receive_timeout(struct GNUNET_CONNECTION_Handle *connection)
519{ 514{
520 GNUNET_CONNECTION_Receiver receiver; 515 GNUNET_CONNECTION_Receiver receiver;
521 516
522 LOG (GNUNET_ERROR_TYPE_DEBUG, 517 LOG(GNUNET_ERROR_TYPE_DEBUG,
523 "Connection signals timeout to receiver (%p)!\n", 518 "Connection signals timeout to receiver (%p)!\n",
524 connection); 519 connection);
525 GNUNET_assert (NULL != (receiver = connection->receiver)); 520 GNUNET_assert(NULL != (receiver = connection->receiver));
526 connection->receiver = NULL; 521 connection->receiver = NULL;
527 receiver (connection->receiver_cls, NULL, 0, NULL, 0, 0); 522 receiver(connection->receiver_cls, NULL, 0, NULL, 0, 0);
528} 523}
529 524
530 525
@@ -535,34 +530,34 @@ signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection)
535 * @param ecode error code (errno) 530 * @param ecode error code (errno)
536 */ 531 */
537static void 532static void
538signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode) 533signal_transmit_error(struct GNUNET_CONNECTION_Handle *connection, int ecode)
539{ 534{
540 GNUNET_CONNECTION_TransmitReadyNotify notify; 535 GNUNET_CONNECTION_TransmitReadyNotify notify;
541 536
542 LOG (GNUNET_ERROR_TYPE_DEBUG, 537 LOG(GNUNET_ERROR_TYPE_DEBUG,
543 "Transmission encounterd error (%s), connection closed (%p)\n", 538 "Transmission encounterd error (%s), connection closed (%p)\n",
544 strerror (ecode), 539 strerror(ecode),
545 connection); 540 connection);
546 if (NULL != connection->sock) 541 if (NULL != connection->sock)
547 { 542 {
548 (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); 543 (void)GNUNET_NETWORK_socket_shutdown(connection->sock, SHUT_RDWR);
549 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); 544 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(connection->sock));
550 connection->sock = NULL; 545 connection->sock = NULL;
551 GNUNET_assert (NULL == connection->write_task); 546 GNUNET_assert(NULL == connection->write_task);
552 } 547 }
553 if (NULL != connection->read_task) 548 if (NULL != connection->read_task)
554 { 549 {
555 /* send errors trigger read errors... */ 550 /* send errors trigger read errors... */
556 GNUNET_SCHEDULER_cancel (connection->read_task); 551 GNUNET_SCHEDULER_cancel(connection->read_task);
557 connection->read_task = NULL; 552 connection->read_task = NULL;
558 signal_receive_timeout (connection); 553 signal_receive_timeout(connection);
559 return; 554 return;
560 } 555 }
561 if (NULL == connection->nth.notify_ready) 556 if (NULL == connection->nth.notify_ready)
562 return; /* nobody to tell about it */ 557 return; /* nobody to tell about it */
563 notify = connection->nth.notify_ready; 558 notify = connection->nth.notify_ready;
564 connection->nth.notify_ready = NULL; 559 connection->nth.notify_ready = NULL;
565 notify (connection->nth.notify_ready_cls, 0, NULL); 560 notify(connection->nth.notify_ready_cls, 0, NULL);
566} 561}
567 562
568 563
@@ -573,37 +568,37 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode)
573 * @param connection the connection we tried to establish 568 * @param connection the connection we tried to establish
574 */ 569 */
575static void 570static void
576connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) 571connect_fail_continuation(struct GNUNET_CONNECTION_Handle *connection)
577{ 572{
578 LOG (GNUNET_ERROR_TYPE_INFO, 573 LOG(GNUNET_ERROR_TYPE_INFO,
579 "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", 574 "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n",
580 connection->hostname, 575 connection->hostname,
581 connection->port); 576 connection->port);
582 GNUNET_break (NULL == connection->ap_head); 577 GNUNET_break(NULL == connection->ap_head);
583 GNUNET_break (NULL == connection->ap_tail); 578 GNUNET_break(NULL == connection->ap_tail);
584 GNUNET_break (GNUNET_NO == connection->dns_active); 579 GNUNET_break(GNUNET_NO == connection->dns_active);
585 GNUNET_break (NULL == connection->sock); 580 GNUNET_break(NULL == connection->sock);
586 GNUNET_assert (NULL == connection->write_task); 581 GNUNET_assert(NULL == connection->write_task);
587 GNUNET_assert (NULL == connection->proxy_handshake); 582 GNUNET_assert(NULL == connection->proxy_handshake);
588 583
589 /* signal errors for jobs that used to wait on the connection */ 584 /* signal errors for jobs that used to wait on the connection */
590 connection->destroy_later = 1; 585 connection->destroy_later = 1;
591 if (NULL != connection->receiver) 586 if (NULL != connection->receiver)
592 signal_receive_error (connection, ECONNREFUSED); 587 signal_receive_error(connection, ECONNREFUSED);
593 if (NULL != connection->nth.notify_ready) 588 if (NULL != connection->nth.notify_ready)
594 { 589 {
595 GNUNET_assert (NULL != connection->nth.timeout_task); 590 GNUNET_assert(NULL != connection->nth.timeout_task);
596 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); 591 GNUNET_SCHEDULER_cancel(connection->nth.timeout_task);
597 connection->nth.timeout_task = NULL; 592 connection->nth.timeout_task = NULL;
598 signal_transmit_error (connection, ECONNREFUSED); 593 signal_transmit_error(connection, ECONNREFUSED);
599 } 594 }
600 if (-1 == connection->destroy_later) 595 if (-1 == connection->destroy_later)
601 { 596 {
602 /* do it now */ 597 /* do it now */
603 connection->destroy_later = 0; 598 connection->destroy_later = 0;
604 GNUNET_CONNECTION_destroy (connection); 599 GNUNET_CONNECTION_destroy(connection);
605 return; 600 return;
606 } 601 }
607 connection->destroy_later = 0; 602 connection->destroy_later = 0;
608} 603}
609 604
@@ -614,7 +609,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection)
614 * @param cls our connection handle 609 * @param cls our connection handle
615 */ 610 */
616static void 611static void
617transmit_ready (void *cls); 612transmit_ready(void *cls);
618 613
619 614
620/** 615/**
@@ -624,7 +619,7 @@ transmit_ready (void *cls);
624 * @param cls connection to read from 619 * @param cls connection to read from
625 */ 620 */
626static void 621static void
627receive_ready (void *cls); 622receive_ready(void *cls);
628 623
629 624
630/** 625/**
@@ -633,42 +628,42 @@ receive_ready (void *cls);
633 * @param connection the connection we tried to establish 628 * @param connection the connection we tried to establish
634 */ 629 */
635static void 630static void
636connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) 631connect_success_continuation(struct GNUNET_CONNECTION_Handle *connection)
637{ 632{
638 LOG (GNUNET_ERROR_TYPE_DEBUG, 633 LOG(GNUNET_ERROR_TYPE_DEBUG,
639 "Connection to `%s' succeeded! (%p)\n", 634 "Connection to `%s' succeeded! (%p)\n",
640 GNUNET_a2s (connection->addr, connection->addrlen), 635 GNUNET_a2s(connection->addr, connection->addrlen),
641 connection); 636 connection);
642 /* trigger jobs that waited for the connection */ 637 /* trigger jobs that waited for the connection */
643 if (NULL != connection->receiver) 638 if (NULL != connection->receiver)
644 { 639 {
645 LOG (GNUNET_ERROR_TYPE_DEBUG, 640 LOG(GNUNET_ERROR_TYPE_DEBUG,
646 "Connection succeeded, starting with receiving data (%p)\n", 641 "Connection succeeded, starting with receiving data (%p)\n",
647 connection); 642 connection);
648 GNUNET_assert (NULL == connection->read_task); 643 GNUNET_assert(NULL == connection->read_task);
649 connection->read_task = 644 connection->read_task =
650 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( 645 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining(
651 connection->receive_timeout), 646 connection->receive_timeout),
652 connection->sock,
653 &receive_ready,
654 connection);
655 }
656 if (NULL != connection->nth.notify_ready)
657 {
658 LOG (GNUNET_ERROR_TYPE_DEBUG,
659 "Connection succeeded, starting with sending data (%p)\n",
660 connection);
661 GNUNET_assert (connection->nth.timeout_task != NULL);
662 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task);
663 connection->nth.timeout_task = NULL;
664 GNUNET_assert (connection->write_task == NULL);
665 connection->write_task =
666 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining (
667 connection->nth.transmit_timeout),
668 connection->sock, 647 connection->sock,
669 &transmit_ready, 648 &receive_ready,
670 connection); 649 connection);
671 } 650 }
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 }
672} 667}
673 668
674 669
@@ -679,7 +674,7 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection)
679 * @param cls the `struct AddressProbe *` with the address that we are probing 674 * @param cls the `struct AddressProbe *` with the address that we are probing
680 */ 675 */
681static void 676static void
682connect_probe_continuation (void *cls) 677connect_probe_continuation(void *cls)
683{ 678{
684 struct AddressProbe *ap = cls; 679 struct AddressProbe *ap = cls;
685 struct GNUNET_CONNECTION_Handle *connection = ap->connection; 680 struct GNUNET_CONNECTION_Handle *connection = ap->connection;
@@ -688,44 +683,44 @@ connect_probe_continuation (void *cls)
688 int error; 683 int error;
689 socklen_t len; 684 socklen_t len;
690 685
691 GNUNET_assert (NULL != ap->sock); 686 GNUNET_assert(NULL != ap->sock);
692 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); 687 GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, ap);
693 len = sizeof (error); 688 len = sizeof(error);
694 errno = 0; 689 errno = 0;
695 error = 0; 690 error = 0;
696 tc = GNUNET_SCHEDULER_get_task_context (); 691 tc = GNUNET_SCHEDULER_get_task_context();
697 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || 692 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
698 (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock, 693 (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt(ap->sock,
699 SOL_SOCKET, 694 SOL_SOCKET,
700 SO_ERROR, 695 SO_ERROR,
701 &error, 696 &error,
702 &len)) || 697 &len)) ||
703 (0 != error)) 698 (0 != error))
704 { 699 {
705 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); 700 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(ap->sock));
706 GNUNET_free (ap); 701 GNUNET_free(ap);
707 if ((NULL == connection->ap_head) && 702 if ((NULL == connection->ap_head) &&
708 (GNUNET_NO == connection->dns_active) && 703 (GNUNET_NO == connection->dns_active) &&
709 (NULL == connection->proxy_handshake)) 704 (NULL == connection->proxy_handshake))
710 connect_fail_continuation (connection); 705 connect_fail_continuation(connection);
711 return; 706 return;
712 } 707 }
713 GNUNET_assert (NULL == connection->sock); 708 GNUNET_assert(NULL == connection->sock);
714 connection->sock = ap->sock; 709 connection->sock = ap->sock;
715 GNUNET_assert (NULL == connection->addr); 710 GNUNET_assert(NULL == connection->addr);
716 connection->addr = GNUNET_malloc (ap->addrlen); 711 connection->addr = GNUNET_malloc(ap->addrlen);
717 GNUNET_memcpy (connection->addr, ap->addr, ap->addrlen); 712 GNUNET_memcpy(connection->addr, ap->addr, ap->addrlen);
718 connection->addrlen = ap->addrlen; 713 connection->addrlen = ap->addrlen;
719 GNUNET_free (ap); 714 GNUNET_free(ap);
720 /* cancel all other attempts */ 715 /* cancel all other attempts */
721 while (NULL != (pos = connection->ap_head)) 716 while (NULL != (pos = connection->ap_head))
722 { 717 {
723 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); 718 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(pos->sock));
724 GNUNET_SCHEDULER_cancel (pos->task); 719 GNUNET_SCHEDULER_cancel(pos->task);
725 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); 720 GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, pos);
726 GNUNET_free (pos); 721 GNUNET_free(pos);
727 } 722 }
728 connect_success_continuation (connection); 723 connect_success_continuation(connection);
729} 724}
730 725
731 726
@@ -738,85 +733,87 @@ connect_probe_continuation (void *cls)
738 * @param addrlen length of @a addr 733 * @param addrlen length of @a addr
739 */ 734 */
740static void 735static void
741try_connect_using_address (void *cls, 736try_connect_using_address(void *cls,
742 const struct sockaddr *addr, 737 const struct sockaddr *addr,
743 socklen_t addrlen) 738 socklen_t addrlen)
744{ 739{
745 struct GNUNET_CONNECTION_Handle *connection = cls; 740 struct GNUNET_CONNECTION_Handle *connection = cls;
746 struct AddressProbe *ap; 741 struct AddressProbe *ap;
747 struct GNUNET_TIME_Relative delay; 742 struct GNUNET_TIME_Relative delay;
748 743
749 if (NULL == addr) 744 if (NULL == addr)
750 { 745 {
751 connection->dns_active = NULL; 746 connection->dns_active = NULL;
752 if ((NULL == connection->ap_head) && (NULL == connection->sock) && 747 if ((NULL == connection->ap_head) && (NULL == connection->sock) &&
753 (NULL == connection->proxy_handshake)) 748 (NULL == connection->proxy_handshake))
754 connect_fail_continuation (connection); 749 connect_fail_continuation(connection);
755 return; 750 return;
756 } 751 }
757 if (NULL != connection->sock) 752 if (NULL != connection->sock)
758 return; /* already connected */ 753 return; /* already connected */
759 GNUNET_assert (NULL == connection->addr); 754 GNUNET_assert(NULL == connection->addr);
760 /* try to connect */ 755 /* try to connect */
761 LOG (GNUNET_ERROR_TYPE_DEBUG, 756 LOG(GNUNET_ERROR_TYPE_DEBUG,
762 "Trying to connect using address `%s:%u/%s:%u'\n", 757 "Trying to connect using address `%s:%u/%s:%u'\n",
763 connection->hostname, 758 connection->hostname,
764 connection->port, 759 connection->port,
765 GNUNET_a2s (addr, addrlen), 760 GNUNET_a2s(addr, addrlen),
766 connection->port); 761 connection->port);
767 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); 762 ap = GNUNET_malloc(sizeof(struct AddressProbe) + addrlen);
768 ap->addr = (const struct sockaddr *) &ap[1]; 763 ap->addr = (const struct sockaddr *)&ap[1];
769 GNUNET_memcpy (&ap[1], addr, addrlen); 764 GNUNET_memcpy(&ap[1], addr, addrlen);
770 ap->addrlen = addrlen; 765 ap->addrlen = addrlen;
771 ap->connection = connection; 766 ap->connection = connection;
772 767
773 switch (ap->addr->sa_family) 768 switch (ap->addr->sa_family)
774 { 769 {
775 case AF_INET: 770 case AF_INET:
776 ((struct sockaddr_in *) ap->addr)->sin_port = htons (connection->port); 771 ((struct sockaddr_in *)ap->addr)->sin_port = htons(connection->port);
777 break; 772 break;
778 case AF_INET6: 773
779 ((struct sockaddr_in6 *) ap->addr)->sin6_port = htons (connection->port); 774 case AF_INET6:
780 break; 775 ((struct sockaddr_in6 *)ap->addr)->sin6_port = htons(connection->port);
781 default: 776 break;
782 GNUNET_break (0); 777
783 GNUNET_free (ap); 778 default:
784 return; /* not supported by us */ 779 GNUNET_break(0);
785 } 780 GNUNET_free(ap);
786 ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); 781 return; /* not supported by us */
782 }
783 ap->sock = GNUNET_NETWORK_socket_create(ap->addr->sa_family, SOCK_STREAM, 0);
787 if (NULL == ap->sock) 784 if (NULL == ap->sock)
788 { 785 {
789 GNUNET_free (ap); 786 GNUNET_free(ap);
790 return; /* not supported by OS */ 787 return; /* not supported by OS */
791 } 788 }
792 LOG (GNUNET_ERROR_TYPE_INFO, 789 LOG(GNUNET_ERROR_TYPE_INFO,
793 "Trying to connect to `%s' (%p)\n", 790 "Trying to connect to `%s' (%p)\n",
794 GNUNET_a2s (ap->addr, ap->addrlen), 791 GNUNET_a2s(ap->addr, ap->addrlen),
795 connection); 792 connection);
796 if ((GNUNET_OK != 793 if ((GNUNET_OK !=
797 GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && 794 GNUNET_NETWORK_socket_connect(ap->sock, ap->addr, ap->addrlen)) &&
798 (EINPROGRESS != errno)) 795 (EINPROGRESS != errno))
799 { 796 {
800 /* maybe refused / unsupported address, try next */ 797 /* maybe refused / unsupported address, try next */
801 LOG_STRERROR (GNUNET_ERROR_TYPE_INFO, "connect"); 798 LOG_STRERROR(GNUNET_ERROR_TYPE_INFO, "connect");
802 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); 799 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(ap->sock));
803 GNUNET_free (ap); 800 GNUNET_free(ap);
804 return; 801 return;
805 } 802 }
806 GNUNET_CONTAINER_DLL_insert (connection->ap_head, connection->ap_tail, ap); 803 GNUNET_CONTAINER_DLL_insert(connection->ap_head, connection->ap_tail, ap);
807 delay = CONNECT_RETRY_TIMEOUT; 804 delay = CONNECT_RETRY_TIMEOUT;
808 if (NULL != connection->nth.notify_ready) 805 if (NULL != connection->nth.notify_ready)
809 delay = GNUNET_TIME_relative_min (delay, 806 delay = GNUNET_TIME_relative_min(delay,
810 GNUNET_TIME_absolute_get_remaining ( 807 GNUNET_TIME_absolute_get_remaining(
811 connection->nth.transmit_timeout)); 808 connection->nth.transmit_timeout));
812 if (NULL != connection->receiver) 809 if (NULL != connection->receiver)
813 delay = GNUNET_TIME_relative_min (delay, 810 delay = GNUNET_TIME_relative_min(delay,
814 GNUNET_TIME_absolute_get_remaining ( 811 GNUNET_TIME_absolute_get_remaining(
815 connection->receive_timeout)); 812 connection->receive_timeout));
816 ap->task = GNUNET_SCHEDULER_add_write_net (delay, 813 ap->task = GNUNET_SCHEDULER_add_write_net(delay,
817 ap->sock, 814 ap->sock,
818 &connect_probe_continuation, 815 &connect_probe_continuation,
819 ap); 816 ap);
820} 817}
821 818
822 819
@@ -831,25 +828,25 @@ try_connect_using_address (void *cls,
831 * @return the connection handle 828 * @return the connection handle
832 */ 829 */
833struct GNUNET_CONNECTION_Handle * 830struct GNUNET_CONNECTION_Handle *
834GNUNET_CONNECTION_create_from_connect ( 831GNUNET_CONNECTION_create_from_connect(
835 const struct GNUNET_CONFIGURATION_Handle *cfg, 832 const struct GNUNET_CONFIGURATION_Handle *cfg,
836 const char *hostname, 833 const char *hostname,
837 uint16_t port) 834 uint16_t port)
838{ 835{
839 struct GNUNET_CONNECTION_Handle *connection; 836 struct GNUNET_CONNECTION_Handle *connection;
840 837
841 GNUNET_assert (0 < strlen (hostname)); /* sanity check */ 838 GNUNET_assert(0 < strlen(hostname)); /* sanity check */
842 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); 839 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle);
843 connection->cfg = cfg; 840 connection->cfg = cfg;
844 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 841 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
845 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); 842 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size);
846 connection->port = port; 843 connection->port = port;
847 connection->hostname = GNUNET_strdup (hostname); 844 connection->hostname = GNUNET_strdup(hostname);
848 connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname, 845 connection->dns_active = GNUNET_RESOLVER_ip_get(connection->hostname,
849 AF_UNSPEC, 846 AF_UNSPEC,
850 CONNECT_RETRY_TIMEOUT, 847 CONNECT_RETRY_TIMEOUT,
851 &try_connect_using_address, 848 &try_connect_using_address,
852 connection); 849 connection);
853 return connection; 850 return connection;
854} 851}
855 852
@@ -864,7 +861,7 @@ GNUNET_CONNECTION_create_from_connect (
864 * @return the connection handle, NULL on systems without UNIX support 861 * @return the connection handle, NULL on systems without UNIX support
865 */ 862 */
866struct GNUNET_CONNECTION_Handle * 863struct GNUNET_CONNECTION_Handle *
867GNUNET_CONNECTION_create_from_connect_to_unixpath ( 864GNUNET_CONNECTION_create_from_connect_to_unixpath(
868 const struct GNUNET_CONFIGURATION_Handle *cfg, 865 const struct GNUNET_CONFIGURATION_Handle *cfg,
869 const char *unixpath) 866 const char *unixpath)
870{ 867{
@@ -872,51 +869,51 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (
872 struct GNUNET_CONNECTION_Handle *connection; 869 struct GNUNET_CONNECTION_Handle *connection;
873 struct sockaddr_un *un; 870 struct sockaddr_un *un;
874 871
875 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 872 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */
876 un = GNUNET_new (struct sockaddr_un); 873 un = GNUNET_new(struct sockaddr_un);
877 un->sun_family = AF_UNIX; 874 un->sun_family = AF_UNIX;
878 GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); 875 GNUNET_strlcpy(un->sun_path, unixpath, sizeof(un->sun_path));
879#ifdef LINUX 876#ifdef LINUX
880 { 877 {
881 int abstract; 878 int abstract;
882 879
883 abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, 880 abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg,
884 "TESTING", 881 "TESTING",
885 "USE_ABSTRACT_SOCKETS"); 882 "USE_ABSTRACT_SOCKETS");
886 if (GNUNET_YES == abstract) 883 if (GNUNET_YES == abstract)
887 un->sun_path[0] = '\0'; 884 un->sun_path[0] = '\0';
888 } 885 }
889#endif 886#endif
890#if HAVE_SOCKADDR_UN_SUN_LEN 887#if HAVE_SOCKADDR_UN_SUN_LEN
891 un->sun_len = (u_char) sizeof (struct sockaddr_un); 888 un->sun_len = (u_char)sizeof(struct sockaddr_un);
892#endif 889#endif
893 connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); 890 connection = GNUNET_new(struct GNUNET_CONNECTION_Handle);
894 connection->cfg = cfg; 891 connection->cfg = cfg;
895 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; 892 connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE;
896 connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); 893 connection->write_buffer = GNUNET_malloc(connection->write_buffer_size);
897 connection->port = 0; 894 connection->port = 0;
898 connection->hostname = NULL; 895 connection->hostname = NULL;
899 connection->addr = (struct sockaddr *) un; 896 connection->addr = (struct sockaddr *)un;
900 connection->addrlen = sizeof (struct sockaddr_un); 897 connection->addrlen = sizeof(struct sockaddr_un);
901 connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); 898 connection->sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0);
902 if (NULL == connection->sock) 899 if (NULL == connection->sock)
903 { 900 {
904 GNUNET_free (connection->addr); 901 GNUNET_free(connection->addr);
905 GNUNET_free (connection->write_buffer); 902 GNUNET_free(connection->write_buffer);
906 GNUNET_free (connection); 903 GNUNET_free(connection);
907 return NULL; 904 return NULL;
908 } 905 }
909 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock, 906 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect(connection->sock,
910 connection->addr, 907 connection->addr,
911 connection->addrlen)) && 908 connection->addrlen)) &&
912 (EINPROGRESS != errno)) 909 (EINPROGRESS != errno))
913 { 910 {
914 /* Just return; we expect everything to work eventually so don't fail HARD */ 911 /* Just return; we expect everything to work eventually so don't fail HARD */
915 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); 912 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(connection->sock));
916 connection->sock = NULL; 913 connection->sock = NULL;
917 return connection; 914 return connection;
918 } 915 }
919 connect_success_continuation (connection); 916 connect_success_continuation(connection);
920 return connection; 917 return connection;
921#else 918#else
922 return NULL; 919 return NULL;
@@ -935,31 +932,31 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (
935 * @return the connection handle 932 * @return the connection handle
936 */ 933 */
937struct GNUNET_CONNECTION_Handle * 934struct GNUNET_CONNECTION_Handle *
938GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, 935GNUNET_CONNECTION_connect_socket(struct GNUNET_NETWORK_Handle *s,
939 const struct sockaddr *serv_addr, 936 const struct sockaddr *serv_addr,
940 socklen_t addrlen) 937 socklen_t addrlen)
941{ 938{
942 struct GNUNET_CONNECTION_Handle *connection; 939 struct GNUNET_CONNECTION_Handle *connection;
943 940
944 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && 941 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect(s, serv_addr, addrlen)) &&
945 (EINPROGRESS != errno)) 942 (EINPROGRESS != errno))
946 { 943 {
947 /* maybe refused / unsupported address, try next */ 944 /* maybe refused / unsupported address, try next */
948 LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect"); 945 LOG_STRERROR(GNUNET_ERROR_TYPE_DEBUG, "connect");
949 LOG (GNUNET_ERROR_TYPE_DEBUG, 946 LOG(GNUNET_ERROR_TYPE_DEBUG,
950 "Attempt to connect to `%s' failed\n", 947 "Attempt to connect to `%s' failed\n",
951 GNUNET_a2s (serv_addr, addrlen)); 948 GNUNET_a2s(serv_addr, addrlen));
952 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); 949 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(s));
953 return NULL; 950 return NULL;
954 } 951 }
955 connection = GNUNET_CONNECTION_create_from_existing (s); 952 connection = GNUNET_CONNECTION_create_from_existing(s);
956 connection->addr = GNUNET_malloc (addrlen); 953 connection->addr = GNUNET_malloc(addrlen);
957 GNUNET_memcpy (connection->addr, serv_addr, addrlen); 954 GNUNET_memcpy(connection->addr, serv_addr, addrlen);
958 connection->addrlen = addrlen; 955 connection->addrlen = addrlen;
959 LOG (GNUNET_ERROR_TYPE_INFO, 956 LOG(GNUNET_ERROR_TYPE_INFO,
960 "Trying to connect to `%s' (%p)\n", 957 "Trying to connect to `%s' (%p)\n",
961 GNUNET_a2s (serv_addr, addrlen), 958 GNUNET_a2s(serv_addr, addrlen),
962 connection); 959 connection);
963 return connection; 960 return connection;
964} 961}
965 962
@@ -976,19 +973,19 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s,
976 * @return the connection handle 973 * @return the connection handle
977 */ 974 */
978struct GNUNET_CONNECTION_Handle * 975struct GNUNET_CONNECTION_Handle *
979GNUNET_CONNECTION_create_from_sockaddr (int af_family, 976GNUNET_CONNECTION_create_from_sockaddr(int af_family,
980 const struct sockaddr *serv_addr, 977 const struct sockaddr *serv_addr,
981 socklen_t addrlen) 978 socklen_t addrlen)
982{ 979{
983 struct GNUNET_NETWORK_Handle *s; 980 struct GNUNET_NETWORK_Handle *s;
984 981
985 s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); 982 s = GNUNET_NETWORK_socket_create(af_family, SOCK_STREAM, 0);
986 if (NULL == s) 983 if (NULL == s)
987 { 984 {
988 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); 985 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket");
989 return NULL; 986 return NULL;
990 } 987 }
991 return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen); 988 return GNUNET_CONNECTION_connect_socket(s, serv_addr, addrlen);
992} 989}
993 990
994 991
@@ -1001,7 +998,7 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family,
1001 * @return #GNUNET_YES if valid, #GNUNET_NO otherwise 998 * @return #GNUNET_YES if valid, #GNUNET_NO otherwise
1002 */ 999 */
1003int 1000int
1004GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) 1001GNUNET_CONNECTION_check(struct GNUNET_CONNECTION_Handle *connection)
1005{ 1002{
1006 if ((NULL != connection->ap_head) || (NULL != connection->dns_active) || 1003 if ((NULL != connection->ap_head) || (NULL != connection->dns_active) ||
1007 (NULL != connection->proxy_handshake)) 1004 (NULL != connection->proxy_handshake))
@@ -1020,78 +1017,78 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection)
1020 * @param connection connection to destroy 1017 * @param connection connection to destroy
1021 */ 1018 */
1022void 1019void
1023GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) 1020GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection)
1024{ 1021{
1025 struct AddressProbe *pos; 1022 struct AddressProbe *pos;
1026 1023
1027 if (0 != connection->destroy_later) 1024 if (0 != connection->destroy_later)
1028 { 1025 {
1029 connection->destroy_later = -1; 1026 connection->destroy_later = -1;
1030 return; 1027 return;
1031 } 1028 }
1032 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); 1029 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection);
1033 GNUNET_assert (NULL == connection->nth.notify_ready); 1030 GNUNET_assert(NULL == connection->nth.notify_ready);
1034 GNUNET_assert (NULL == connection->receiver); 1031 GNUNET_assert(NULL == connection->receiver);
1035 if (NULL != connection->write_task) 1032 if (NULL != connection->write_task)
1036 { 1033 {
1037 GNUNET_SCHEDULER_cancel (connection->write_task); 1034 GNUNET_SCHEDULER_cancel(connection->write_task);
1038 connection->write_task = NULL; 1035 connection->write_task = NULL;
1039 connection->write_buffer_off = 0; 1036 connection->write_buffer_off = 0;
1040 } 1037 }
1041 if (NULL != connection->read_task) 1038 if (NULL != connection->read_task)
1042 { 1039 {
1043 GNUNET_SCHEDULER_cancel (connection->read_task); 1040 GNUNET_SCHEDULER_cancel(connection->read_task);
1044 connection->read_task = NULL; 1041 connection->read_task = NULL;
1045 } 1042 }
1046 if (NULL != connection->nth.timeout_task) 1043 if (NULL != connection->nth.timeout_task)
1047 { 1044 {
1048 GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); 1045 GNUNET_SCHEDULER_cancel(connection->nth.timeout_task);
1049 connection->nth.timeout_task = NULL; 1046 connection->nth.timeout_task = NULL;
1050 } 1047 }
1051 connection->nth.notify_ready = NULL; 1048 connection->nth.notify_ready = NULL;
1052 if (NULL != connection->dns_active) 1049 if (NULL != connection->dns_active)
1053 { 1050 {
1054 GNUNET_RESOLVER_request_cancel (connection->dns_active); 1051 GNUNET_RESOLVER_request_cancel(connection->dns_active);
1055 connection->dns_active = NULL; 1052 connection->dns_active = NULL;
1056 } 1053 }
1057 if (NULL != connection->proxy_handshake) 1054 if (NULL != connection->proxy_handshake)
1058 { 1055 {
1059 /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ 1056 /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */
1060 connection->proxy_handshake->destroy_later = -1; 1057 connection->proxy_handshake->destroy_later = -1;
1061 connection->proxy_handshake = NULL; /* Not leaked ??? */ 1058 connection->proxy_handshake = NULL; /* Not leaked ??? */
1062 } 1059 }
1063 while (NULL != (pos = connection->ap_head)) 1060 while (NULL != (pos = connection->ap_head))
1064 { 1061 {
1065 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); 1062 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(pos->sock));
1066 GNUNET_SCHEDULER_cancel (pos->task); 1063 GNUNET_SCHEDULER_cancel(pos->task);
1067 GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); 1064 GNUNET_CONTAINER_DLL_remove(connection->ap_head, connection->ap_tail, pos);
1068 GNUNET_free (pos); 1065 GNUNET_free(pos);
1069 } 1066 }
1070 if ((NULL != connection->sock) && (GNUNET_YES != connection->persist)) 1067 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)
1080 { 1068 {
1081 GNUNET_break (GNUNET_OK == 1069 if ((GNUNET_OK !=
1082 GNUNET_NETWORK_socket_close (connection->sock)); 1070 GNUNET_NETWORK_socket_shutdown(connection->sock, SHUT_RDWR)) &&
1071 (ENOTCONN != errno) && (ECONNRESET != errno))
1072 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "shutdown");
1083 } 1073 }
1084 else 1074 if (NULL != connection->sock)
1085 { 1075 {
1086 GNUNET_NETWORK_socket_free_memory_only_ ( 1076 if (GNUNET_YES != connection->persist)
1087 connection->sock); /* at least no memory leak (we deliberately 1077 {
1088 * leak the socket in this special case) ... */ 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) ... */
1086 }
1089 } 1087 }
1090 } 1088 GNUNET_free_non_null(connection->addr);
1091 GNUNET_free_non_null (connection->addr); 1089 GNUNET_free_non_null(connection->hostname);
1092 GNUNET_free_non_null (connection->hostname); 1090 GNUNET_free(connection->write_buffer);
1093 GNUNET_free (connection->write_buffer); 1091 GNUNET_free(connection);
1094 GNUNET_free (connection);
1095} 1092}
1096 1093
1097 1094
@@ -1102,7 +1099,7 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection)
1102 * @param cls connection to read from 1099 * @param cls connection to read from
1103 */ 1100 */
1104static void 1101static void
1105receive_ready (void *cls) 1102receive_ready(void *cls)
1106{ 1103{
1107 struct GNUNET_CONNECTION_Handle *connection = cls; 1104 struct GNUNET_CONNECTION_Handle *connection = cls;
1108 const struct GNUNET_SCHEDULER_TaskContext *tc; 1105 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -1111,49 +1108,49 @@ receive_ready (void *cls)
1111 GNUNET_CONNECTION_Receiver receiver; 1108 GNUNET_CONNECTION_Receiver receiver;
1112 1109
1113 connection->read_task = NULL; 1110 connection->read_task = NULL;
1114 tc = GNUNET_SCHEDULER_get_task_context (); 1111 tc = GNUNET_SCHEDULER_get_task_context();
1115 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1112 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1116 { 1113 {
1117 LOG (GNUNET_ERROR_TYPE_DEBUG, 1114 LOG(GNUNET_ERROR_TYPE_DEBUG,
1118 "Receive from `%s' encounters error: timeout (%s, %p)\n", 1115 "Receive from `%s' encounters error: timeout (%s, %p)\n",
1119 GNUNET_a2s (connection->addr, connection->addrlen), 1116 GNUNET_a2s(connection->addr, connection->addrlen),
1120 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration ( 1117 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(
1121 connection->receive_timeout), 1118 connection->receive_timeout),
1122 GNUNET_YES), 1119 GNUNET_YES),
1123 connection); 1120 connection);
1124 signal_receive_timeout (connection); 1121 signal_receive_timeout(connection);
1125 return; 1122 return;
1126 } 1123 }
1127 if (NULL == connection->sock) 1124 if (NULL == connection->sock)
1128 { 1125 {
1129 /* connect failed for good */ 1126 /* connect failed for good */
1130 signal_receive_error (connection, ECONNREFUSED); 1127 signal_receive_error(connection, ECONNREFUSED);
1131 return; 1128 return;
1132 } 1129 }
1133 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); 1130 GNUNET_assert(GNUNET_NETWORK_fdset_isset(tc->read_ready, connection->sock));
1134RETRY: 1131RETRY:
1135 ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max); 1132 ret = GNUNET_NETWORK_socket_recv(connection->sock, buffer, connection->max);
1136 if (-1 == ret) 1133 if (-1 == ret)
1137 { 1134 {
1138 if (EINTR == errno) 1135 if (EINTR == errno)
1139 goto RETRY; 1136 goto RETRY;
1140 signal_receive_error (connection, errno); 1137 signal_receive_error(connection, errno);
1141 return; 1138 return;
1142 } 1139 }
1143 LOG (GNUNET_ERROR_TYPE_DEBUG, 1140 LOG(GNUNET_ERROR_TYPE_DEBUG,
1144 "receive_ready read %u/%u bytes from `%s' (%p)!\n", 1141 "receive_ready read %u/%u bytes from `%s' (%p)!\n",
1145 (unsigned int) ret, 1142 (unsigned int)ret,
1146 connection->max, 1143 connection->max,
1147 GNUNET_a2s (connection->addr, connection->addrlen), 1144 GNUNET_a2s(connection->addr, connection->addrlen),
1148 connection); 1145 connection);
1149 GNUNET_assert (NULL != (receiver = connection->receiver)); 1146 GNUNET_assert(NULL != (receiver = connection->receiver));
1150 connection->receiver = NULL; 1147 connection->receiver = NULL;
1151 receiver (connection->receiver_cls, 1148 receiver(connection->receiver_cls,
1152 buffer, 1149 buffer,
1153 ret, 1150 ret,
1154 connection->addr, 1151 connection->addr,
1155 connection->addrlen, 1152 connection->addrlen,
1156 0); 1153 0);
1157} 1154}
1158 1155
1159 1156
@@ -1173,36 +1170,36 @@ RETRY:
1173 * called with error) 1170 * called with error)
1174 */ 1171 */
1175int 1172int
1176GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, 1173GNUNET_CONNECTION_receive(struct GNUNET_CONNECTION_Handle *connection,
1177 size_t max, 1174 size_t max,
1178 struct GNUNET_TIME_Relative timeout, 1175 struct GNUNET_TIME_Relative timeout,
1179 GNUNET_CONNECTION_Receiver receiver, 1176 GNUNET_CONNECTION_Receiver receiver,
1180 void *receiver_cls) 1177 void *receiver_cls)
1181{ 1178{
1182 GNUNET_assert ((NULL == connection->read_task) && 1179 GNUNET_assert((NULL == connection->read_task) &&
1183 (NULL == connection->receiver)); 1180 (NULL == connection->receiver));
1184 GNUNET_assert (NULL != receiver); 1181 GNUNET_assert(NULL != receiver);
1185 connection->receiver = receiver; 1182 connection->receiver = receiver;
1186 connection->receiver_cls = receiver_cls; 1183 connection->receiver_cls = receiver_cls;
1187 connection->receive_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1184 connection->receive_timeout = GNUNET_TIME_relative_to_absolute(timeout);
1188 connection->max = max; 1185 connection->max = max;
1189 if (NULL != connection->sock) 1186 if (NULL != connection->sock)
1190 { 1187 {
1191 connection->read_task = 1188 connection->read_task =
1192 GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( 1189 GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_absolute_get_remaining(
1193 connection->receive_timeout), 1190 connection->receive_timeout),
1194 connection->sock, 1191 connection->sock,
1195 &receive_ready, 1192 &receive_ready,
1196 connection); 1193 connection);
1197 return GNUNET_OK; 1194 return GNUNET_OK;
1198 } 1195 }
1199 if ((NULL == connection->dns_active) && (NULL == connection->ap_head) && 1196 if ((NULL == connection->dns_active) && (NULL == connection->ap_head) &&
1200 (NULL == connection->proxy_handshake)) 1197 (NULL == connection->proxy_handshake))
1201 { 1198 {
1202 connection->receiver = NULL; 1199 connection->receiver = NULL;
1203 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); 1200 receiver(receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
1204 return GNUNET_SYSERR; 1201 return GNUNET_SYSERR;
1205 } 1202 }
1206 return GNUNET_OK; 1203 return GNUNET_OK;
1207} 1204}
1208 1205
@@ -1216,14 +1213,14 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection,
1216 * @return closure of the original receiver callback closure 1213 * @return closure of the original receiver callback closure
1217 */ 1214 */
1218void * 1215void *
1219GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection) 1216GNUNET_CONNECTION_receive_cancel(struct GNUNET_CONNECTION_Handle *connection)
1220{ 1217{
1221 if (NULL != connection->read_task) 1218 if (NULL != connection->read_task)
1222 { 1219 {
1223 GNUNET_assert (connection == 1220 GNUNET_assert(connection ==
1224 GNUNET_SCHEDULER_cancel (connection->read_task)); 1221 GNUNET_SCHEDULER_cancel(connection->read_task));
1225 connection->read_task = NULL; 1222 connection->read_task = NULL;
1226 } 1223 }
1227 connection->receiver = NULL; 1224 connection->receiver = NULL;
1228 return connection->receiver_cls; 1225 return connection->receiver_cls;
1229} 1226}
@@ -1237,44 +1234,44 @@ GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection)
1237 * @return #GNUNET_YES if we were able to call notify 1234 * @return #GNUNET_YES if we were able to call notify
1238 */ 1235 */
1239static int 1236static int
1240process_notify (struct GNUNET_CONNECTION_Handle *connection) 1237process_notify(struct GNUNET_CONNECTION_Handle *connection)
1241{ 1238{
1242 size_t used; 1239 size_t used;
1243 size_t avail; 1240 size_t avail;
1244 size_t size; 1241 size_t size;
1245 GNUNET_CONNECTION_TransmitReadyNotify notify; 1242 GNUNET_CONNECTION_TransmitReadyNotify notify;
1246 1243
1247 LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); 1244 LOG(GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n");
1248 GNUNET_assert (NULL == connection->write_task); 1245 GNUNET_assert(NULL == connection->write_task);
1249 if (NULL == (notify = connection->nth.notify_ready)) 1246 if (NULL == (notify = connection->nth.notify_ready))
1250 { 1247 {
1251 LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n"); 1248 LOG(GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n");
1252 return GNUNET_NO; 1249 return GNUNET_NO;
1253 } 1250 }
1254 used = connection->write_buffer_off - connection->write_buffer_pos; 1251 used = connection->write_buffer_off - connection->write_buffer_pos;
1255 avail = connection->write_buffer_size - used; 1252 avail = connection->write_buffer_size - used;
1256 size = connection->nth.notify_size; 1253 size = connection->nth.notify_size;
1257 if (size > avail) 1254 if (size > avail)
1258 { 1255 {
1259 LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); 1256 LOG(GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n");
1260 return GNUNET_NO; 1257 return GNUNET_NO;
1261 } 1258 }
1262 connection->nth.notify_ready = NULL; 1259 connection->nth.notify_ready = NULL;
1263 if (connection->write_buffer_size - connection->write_buffer_off < size) 1260 if (connection->write_buffer_size - connection->write_buffer_off < size)
1264 { 1261 {
1265 /* need to compact */ 1262 /* need to compact */
1266 memmove (connection->write_buffer, 1263 memmove(connection->write_buffer,
1267 &connection->write_buffer[connection->write_buffer_pos], 1264 &connection->write_buffer[connection->write_buffer_pos],
1268 used); 1265 used);
1269 connection->write_buffer_off -= connection->write_buffer_pos; 1266 connection->write_buffer_off -= connection->write_buffer_pos;
1270 connection->write_buffer_pos = 0; 1267 connection->write_buffer_pos = 0;
1271 } 1268 }
1272 avail = connection->write_buffer_size - connection->write_buffer_off; 1269 avail = connection->write_buffer_size - connection->write_buffer_off;
1273 GNUNET_assert (avail >= size); 1270 GNUNET_assert(avail >= size);
1274 size = notify (connection->nth.notify_ready_cls, 1271 size = notify(connection->nth.notify_ready_cls,
1275 avail, 1272 avail,
1276 &connection->write_buffer[connection->write_buffer_off]); 1273 &connection->write_buffer[connection->write_buffer_off]);
1277 GNUNET_assert (size <= avail); 1274 GNUNET_assert(size <= avail);
1278 if (0 != size) 1275 if (0 != size)
1279 connection->write_buffer_off += size; 1276 connection->write_buffer_off += size;
1280 return GNUNET_YES; 1277 return GNUNET_YES;
@@ -1292,22 +1289,22 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection)
1292 * @param cls the `struct GNUNET_CONNECTION_Handle` 1289 * @param cls the `struct GNUNET_CONNECTION_Handle`
1293 */ 1290 */
1294static void 1291static void
1295transmit_timeout (void *cls) 1292transmit_timeout(void *cls)
1296{ 1293{
1297 struct GNUNET_CONNECTION_Handle *connection = cls; 1294 struct GNUNET_CONNECTION_Handle *connection = cls;
1298 GNUNET_CONNECTION_TransmitReadyNotify notify; 1295 GNUNET_CONNECTION_TransmitReadyNotify notify;
1299 1296
1300 connection->nth.timeout_task = NULL; 1297 connection->nth.timeout_task = NULL;
1301 LOG (GNUNET_ERROR_TYPE_DEBUG, 1298 LOG(GNUNET_ERROR_TYPE_DEBUG,
1302 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1299 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1303 connection->hostname, 1300 connection->hostname,
1304 connection->port, 1301 connection->port,
1305 GNUNET_a2s (connection->addr, connection->addrlen), 1302 GNUNET_a2s(connection->addr, connection->addrlen),
1306 connection); 1303 connection);
1307 notify = connection->nth.notify_ready; 1304 notify = connection->nth.notify_ready;
1308 GNUNET_assert (NULL != notify); 1305 GNUNET_assert(NULL != notify);
1309 connection->nth.notify_ready = NULL; 1306 connection->nth.notify_ready = NULL;
1310 notify (connection->nth.notify_ready_cls, 0, NULL); 1307 notify(connection->nth.notify_ready_cls, 0, NULL);
1311} 1308}
1312 1309
1313 1310
@@ -1320,21 +1317,21 @@ transmit_timeout (void *cls)
1320 * @param cls the `struct GNUNET_CONNECTION_Handle` 1317 * @param cls the `struct GNUNET_CONNECTION_Handle`
1321 */ 1318 */
1322static void 1319static void
1323connect_error (void *cls) 1320connect_error(void *cls)
1324{ 1321{
1325 struct GNUNET_CONNECTION_Handle *connection = cls; 1322 struct GNUNET_CONNECTION_Handle *connection = cls;
1326 GNUNET_CONNECTION_TransmitReadyNotify notify; 1323 GNUNET_CONNECTION_TransmitReadyNotify notify;
1327 1324
1328 LOG (GNUNET_ERROR_TYPE_DEBUG, 1325 LOG(GNUNET_ERROR_TYPE_DEBUG,
1329 "Transmission request of size %u fails (%s/%u), connection failed (%p).\n", 1326 "Transmission request of size %u fails (%s/%u), connection failed (%p).\n",
1330 connection->nth.notify_size, 1327 connection->nth.notify_size,
1331 connection->hostname, 1328 connection->hostname,
1332 connection->port, 1329 connection->port,
1333 connection); 1330 connection);
1334 connection->write_task = NULL; 1331 connection->write_task = NULL;
1335 notify = connection->nth.notify_ready; 1332 notify = connection->nth.notify_ready;
1336 connection->nth.notify_ready = NULL; 1333 connection->nth.notify_ready = NULL;
1337 notify (connection->nth.notify_ready_cls, 0, NULL); 1334 notify(connection->nth.notify_ready_cls, 0, NULL);
1338} 1335}
1339 1336
1340 1337
@@ -1344,7 +1341,7 @@ connect_error (void *cls)
1344 * @param cls our connection handle 1341 * @param cls our connection handle
1345 */ 1342 */
1346static void 1343static void
1347transmit_ready (void *cls) 1344transmit_ready(void *cls)
1348{ 1345{
1349 struct GNUNET_CONNECTION_Handle *connection = cls; 1346 struct GNUNET_CONNECTION_Handle *connection = cls;
1350 GNUNET_CONNECTION_TransmitReadyNotify notify; 1347 GNUNET_CONNECTION_TransmitReadyNotify notify;
@@ -1352,107 +1349,107 @@ transmit_ready (void *cls)
1352 ssize_t ret; 1349 ssize_t ret;
1353 size_t have; 1350 size_t have;
1354 1351
1355 LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); 1352 LOG(GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection);
1356 GNUNET_assert (NULL != connection->write_task); 1353 GNUNET_assert(NULL != connection->write_task);
1357 connection->write_task = NULL; 1354 connection->write_task = NULL;
1358 GNUNET_assert (NULL == connection->nth.timeout_task); 1355 GNUNET_assert(NULL == connection->nth.timeout_task);
1359 tc = GNUNET_SCHEDULER_get_task_context (); 1356 tc = GNUNET_SCHEDULER_get_task_context();
1360 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1357 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1361 { 1358 {
1362 LOG (GNUNET_ERROR_TYPE_DEBUG, 1359 LOG(GNUNET_ERROR_TYPE_DEBUG,
1363 "Transmit to `%s' fails, time out reached (%p).\n", 1360 "Transmit to `%s' fails, time out reached (%p).\n",
1364 GNUNET_a2s (connection->addr, connection->addrlen), 1361 GNUNET_a2s(connection->addr, connection->addrlen),
1365 connection); 1362 connection);
1366 notify = connection->nth.notify_ready; 1363 notify = connection->nth.notify_ready;
1367 GNUNET_assert (NULL != notify); 1364 GNUNET_assert(NULL != notify);
1368 connection->nth.notify_ready = NULL; 1365 connection->nth.notify_ready = NULL;
1369 notify (connection->nth.notify_ready_cls, 0, NULL); 1366 notify(connection->nth.notify_ready_cls, 0, NULL);
1370 return; 1367 return;
1371 } 1368 }
1372 GNUNET_assert (NULL != connection->sock); 1369 GNUNET_assert(NULL != connection->sock);
1373 if (NULL == tc->write_ready) 1370 if (NULL == tc->write_ready)
1374 { 1371 {
1375 /* special circumstances (in particular, PREREQ_DONE after 1372 /* special circumstances (in particular, PREREQ_DONE after
1376 * connect): not yet ready to write, but no "fatal" error either. 1373 * connect): not yet ready to write, but no "fatal" error either.
1377 * Hence retry. */ 1374 * Hence retry. */
1378 goto SCHEDULE_WRITE; 1375 goto SCHEDULE_WRITE;
1379 } 1376 }
1380 if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) 1377 if (!GNUNET_NETWORK_fdset_isset(tc->write_ready, connection->sock))
1381 { 1378 {
1382 GNUNET_assert (NULL == connection->write_task); 1379 GNUNET_assert(NULL == connection->write_task);
1383 /* special circumstances (in particular, shutdown): not yet ready 1380 /* special circumstances (in particular, shutdown): not yet ready
1384 * to write, but no "fatal" error either. Hence retry. */ 1381 * to write, but no "fatal" error either. Hence retry. */
1385 goto SCHEDULE_WRITE; 1382 goto SCHEDULE_WRITE;
1386 } 1383 }
1387 GNUNET_assert (connection->write_buffer_off >= connection->write_buffer_pos); 1384 GNUNET_assert(connection->write_buffer_off >= connection->write_buffer_pos);
1388 if ((NULL != connection->nth.notify_ready) && 1385 if ((NULL != connection->nth.notify_ready) &&
1389 (connection->write_buffer_size < connection->nth.notify_size)) 1386 (connection->write_buffer_size < connection->nth.notify_size))
1390 { 1387 {
1391 connection->write_buffer = 1388 connection->write_buffer =
1392 GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); 1389 GNUNET_realloc(connection->write_buffer, connection->nth.notify_size);
1393 connection->write_buffer_size = connection->nth.notify_size; 1390 connection->write_buffer_size = connection->nth.notify_size;
1394 } 1391 }
1395 process_notify (connection); 1392 process_notify(connection);
1396 have = connection->write_buffer_off - connection->write_buffer_pos; 1393 have = connection->write_buffer_off - connection->write_buffer_pos;
1397 if (0 == have) 1394 if (0 == have)
1398 { 1395 {
1399 /* no data ready for writing, terminate write loop */ 1396 /* no data ready for writing, terminate write loop */
1400 return; 1397 return;
1401 } 1398 }
1402 GNUNET_assert (have <= connection->write_buffer_size); 1399 GNUNET_assert(have <= connection->write_buffer_size);
1403 GNUNET_assert (have + connection->write_buffer_pos <= 1400 GNUNET_assert(have + connection->write_buffer_pos <=
1404 connection->write_buffer_size); 1401 connection->write_buffer_size);
1405 GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); 1402 GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_size);
1406RETRY: 1403RETRY:
1407 ret = 1404 ret =
1408 GNUNET_NETWORK_socket_send (connection->sock, 1405 GNUNET_NETWORK_socket_send(connection->sock,
1409 &connection 1406 &connection
1410 ->write_buffer[connection->write_buffer_pos], 1407 ->write_buffer[connection->write_buffer_pos],
1411 have); 1408 have);
1412 if (-1 == ret) 1409 if (-1 == ret)
1413 {
1414 if (EINTR == errno)
1415 goto RETRY;
1416 if (NULL != connection->write_task)
1417 { 1410 {
1418 GNUNET_SCHEDULER_cancel (connection->write_task); 1411 if (EINTR == errno)
1419 connection->write_task = NULL; 1412 goto RETRY;
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 } 1420 }
1421 signal_transmit_error (connection, errno); 1421 LOG(GNUNET_ERROR_TYPE_DEBUG,
1422 return; 1422 "Connection transmitted %u/%u bytes to `%s' (%p)\n",
1423 } 1423 (unsigned int)ret,
1424 LOG (GNUNET_ERROR_TYPE_DEBUG, 1424 have,
1425 "Connection transmitted %u/%u bytes to `%s' (%p)\n", 1425 GNUNET_a2s(connection->addr, connection->addrlen),
1426 (unsigned int) ret, 1426 connection);
1427 have,
1428 GNUNET_a2s (connection->addr, connection->addrlen),
1429 connection);
1430 connection->write_buffer_pos += ret; 1427 connection->write_buffer_pos += ret;
1431 if (connection->write_buffer_pos == connection->write_buffer_off) 1428 if (connection->write_buffer_pos == connection->write_buffer_off)
1432 { 1429 {
1433 /* transmitted all pending data */ 1430 /* transmitted all pending data */
1434 connection->write_buffer_pos = 0; 1431 connection->write_buffer_pos = 0;
1435 connection->write_buffer_off = 0; 1432 connection->write_buffer_off = 0;
1436 } 1433 }
1437 if ((0 == connection->write_buffer_off) && 1434 if ((0 == connection->write_buffer_off) &&
1438 (NULL == connection->nth.notify_ready)) 1435 (NULL == connection->nth.notify_ready))
1439 return; /* all data sent! */ 1436 return; /* all data sent! */
1440 /* not done writing, schedule more */ 1437 /* not done writing, schedule more */
1441SCHEDULE_WRITE: 1438SCHEDULE_WRITE:
1442 LOG (GNUNET_ERROR_TYPE_DEBUG, 1439 LOG(GNUNET_ERROR_TYPE_DEBUG,
1443 "Re-scheduling transmit_ready (more to do) (%p).\n", 1440 "Re-scheduling transmit_ready (more to do) (%p).\n",
1444 connection); 1441 connection);
1445 have = connection->write_buffer_off - connection->write_buffer_pos; 1442 have = connection->write_buffer_off - connection->write_buffer_pos;
1446 GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); 1443 GNUNET_assert((NULL != connection->nth.notify_ready) || (have > 0));
1447 if (NULL == connection->write_task) 1444 if (NULL == connection->write_task)
1448 connection->write_task = 1445 connection->write_task =
1449 GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL) 1446 GNUNET_SCHEDULER_add_write_net((connection->nth.notify_ready == NULL)
1450 ? GNUNET_TIME_UNIT_FOREVER_REL 1447 ? GNUNET_TIME_UNIT_FOREVER_REL
1451 : GNUNET_TIME_absolute_get_remaining ( 1448 : GNUNET_TIME_absolute_get_remaining(
1452 connection->nth.transmit_timeout), 1449 connection->nth.transmit_timeout),
1453 connection->sock, 1450 connection->sock,
1454 &transmit_ready, 1451 &transmit_ready,
1455 connection); 1452 connection);
1456} 1453}
1457 1454
1458 1455
@@ -1471,7 +1468,7 @@ SCHEDULE_WRITE:
1471 * NULL if we are already going to notify someone else (busy) 1468 * NULL if we are already going to notify someone else (busy)
1472 */ 1469 */
1473struct GNUNET_CONNECTION_TransmitHandle * 1470struct GNUNET_CONNECTION_TransmitHandle *
1474GNUNET_CONNECTION_notify_transmit_ready ( 1471GNUNET_CONNECTION_notify_transmit_ready(
1475 struct GNUNET_CONNECTION_Handle *connection, 1472 struct GNUNET_CONNECTION_Handle *connection,
1476 size_t size, 1473 size_t size,
1477 struct GNUNET_TIME_Relative timeout, 1474 struct GNUNET_TIME_Relative timeout,
@@ -1479,52 +1476,52 @@ GNUNET_CONNECTION_notify_transmit_ready (
1479 void *notify_cls) 1476 void *notify_cls)
1480{ 1477{
1481 if (NULL != connection->nth.notify_ready) 1478 if (NULL != connection->nth.notify_ready)
1482 { 1479 {
1483 GNUNET_assert (0); 1480 GNUNET_assert(0);
1484 return NULL; 1481 return NULL;
1485 } 1482 }
1486 GNUNET_assert (NULL != notify); 1483 GNUNET_assert(NULL != notify);
1487 GNUNET_assert (size < GNUNET_MAX_MESSAGE_SIZE); 1484 GNUNET_assert(size < GNUNET_MAX_MESSAGE_SIZE);
1488 GNUNET_assert (connection->write_buffer_off <= connection->write_buffer_size); 1485 GNUNET_assert(connection->write_buffer_off <= connection->write_buffer_size);
1489 GNUNET_assert (connection->write_buffer_pos <= 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_off); 1487 GNUNET_assert(connection->write_buffer_pos <= connection->write_buffer_off);
1491 connection->nth.notify_ready = notify; 1488 connection->nth.notify_ready = notify;
1492 connection->nth.notify_ready_cls = notify_cls; 1489 connection->nth.notify_ready_cls = notify_cls;
1493 connection->nth.connection = connection; 1490 connection->nth.connection = connection;
1494 connection->nth.notify_size = size; 1491 connection->nth.notify_size = size;
1495 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1492 connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute(timeout);
1496 GNUNET_assert (NULL == connection->nth.timeout_task); 1493 GNUNET_assert(NULL == connection->nth.timeout_task);
1497 if ((NULL == connection->sock) && (NULL == connection->ap_head) && 1494 if ((NULL == connection->sock) && (NULL == connection->ap_head) &&
1498 (NULL == connection->dns_active) && (NULL == connection->proxy_handshake)) 1495 (NULL == connection->dns_active) && (NULL == connection->proxy_handshake))
1499 { 1496 {
1500 if (NULL != connection->write_task) 1497 if (NULL != connection->write_task)
1501 GNUNET_SCHEDULER_cancel (connection->write_task); 1498 GNUNET_SCHEDULER_cancel(connection->write_task);
1502 connection->write_task = 1499 connection->write_task =
1503 GNUNET_SCHEDULER_add_now (&connect_error, connection); 1500 GNUNET_SCHEDULER_add_now(&connect_error, connection);
1504 return &connection->nth; 1501 return &connection->nth;
1505 } 1502 }
1506 if (NULL != connection->write_task) 1503 if (NULL != connection->write_task)
1507 return &connection->nth; /* previous transmission still in progress */ 1504 return &connection->nth; /* previous transmission still in progress */
1508 if (NULL != connection->sock) 1505 if (NULL != connection->sock)
1509 { 1506 {
1510 /* connected, try to transmit now */ 1507 /* connected, try to transmit now */
1511 LOG (GNUNET_ERROR_TYPE_DEBUG, 1508 LOG(GNUNET_ERROR_TYPE_DEBUG,
1512 "Scheduling transmission (%p).\n", 1509 "Scheduling transmission (%p).\n",
1513 connection); 1510 connection);
1514 connection->write_task = 1511 connection->write_task =
1515 GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( 1512 GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_absolute_get_remaining(
1516 connection->nth.transmit_timeout), 1513 connection->nth.transmit_timeout),
1517 connection->sock, 1514 connection->sock,
1518 &transmit_ready, 1515 &transmit_ready,
1519 connection); 1516 connection);
1520 return &connection->nth; 1517 return &connection->nth;
1521 } 1518 }
1522 /* not yet connected, wait for connection */ 1519 /* not yet connected, wait for connection */
1523 LOG (GNUNET_ERROR_TYPE_DEBUG, 1520 LOG(GNUNET_ERROR_TYPE_DEBUG,
1524 "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", 1521 "Need to wait to schedule transmission for connection, adding timeout task (%p).\n",
1525 connection); 1522 connection);
1526 connection->nth.timeout_task = 1523 connection->nth.timeout_task =
1527 GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); 1524 GNUNET_SCHEDULER_add_delayed(timeout, &transmit_timeout, connection);
1528 return &connection->nth; 1525 return &connection->nth;
1529} 1526}
1530 1527
@@ -1535,21 +1532,21 @@ GNUNET_CONNECTION_notify_transmit_ready (
1535 * @param th notification to cancel 1532 * @param th notification to cancel
1536 */ 1533 */
1537void 1534void
1538GNUNET_CONNECTION_notify_transmit_ready_cancel ( 1535GNUNET_CONNECTION_notify_transmit_ready_cancel(
1539 struct GNUNET_CONNECTION_TransmitHandle *th) 1536 struct GNUNET_CONNECTION_TransmitHandle *th)
1540{ 1537{
1541 GNUNET_assert (NULL != th->notify_ready); 1538 GNUNET_assert(NULL != th->notify_ready);
1542 th->notify_ready = NULL; 1539 th->notify_ready = NULL;
1543 if (NULL != th->timeout_task) 1540 if (NULL != th->timeout_task)
1544 { 1541 {
1545 GNUNET_SCHEDULER_cancel (th->timeout_task); 1542 GNUNET_SCHEDULER_cancel(th->timeout_task);
1546 th->timeout_task = NULL; 1543 th->timeout_task = NULL;
1547 } 1544 }
1548 if (NULL != th->connection->write_task) 1545 if (NULL != th->connection->write_task)
1549 { 1546 {
1550 GNUNET_SCHEDULER_cancel (th->connection->write_task); 1547 GNUNET_SCHEDULER_cancel(th->connection->write_task);
1551 th->connection->write_task = NULL; 1548 th->connection->write_task = NULL;
1552 } 1549 }
1553} 1550}
1554 1551
1555 1552
@@ -1560,11 +1557,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (
1560 * @return connection to be proxied 1557 * @return connection to be proxied
1561 */ 1558 */
1562struct GNUNET_CONNECTION_Handle * 1559struct GNUNET_CONNECTION_Handle *
1563GNUNET_CONNECTION_create_proxied_from_handshake ( 1560GNUNET_CONNECTION_create_proxied_from_handshake(
1564 struct GNUNET_CONNECTION_Handle *cph) 1561 struct GNUNET_CONNECTION_Handle *cph)
1565{ 1562{
1566 struct GNUNET_CONNECTION_Handle *proxied = 1563 struct GNUNET_CONNECTION_Handle *proxied =
1567 GNUNET_CONNECTION_create_from_existing (NULL); 1564 GNUNET_CONNECTION_create_from_existing(NULL);
1568 1565
1569 proxied->proxy_handshake = cph; 1566 proxied->proxy_handshake = cph;
1570 return proxied; 1567 return proxied;
@@ -1579,17 +1576,17 @@ GNUNET_CONNECTION_create_proxied_from_handshake (
1579 * @param proxied connection connection to proxy server 1576 * @param proxied connection connection to proxy server
1580 */ 1577 */
1581void 1578void
1582GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied) 1579GNUNET_CONNECTION_acivate_proxied(struct GNUNET_CONNECTION_Handle *proxied)
1583{ 1580{
1584 struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake; 1581 struct GNUNET_CONNECTION_Handle *cph = proxied->proxy_handshake;
1585 1582
1586 GNUNET_assert (NULL != cph); 1583 GNUNET_assert(NULL != cph);
1587 GNUNET_assert (NULL == proxied->sock); 1584 GNUNET_assert(NULL == proxied->sock);
1588 GNUNET_assert (NULL != cph->sock); 1585 GNUNET_assert(NULL != cph->sock);
1589 proxied->sock = cph->sock; 1586 proxied->sock = cph->sock;
1590 cph->sock = NULL; 1587 cph->sock = NULL;
1591 GNUNET_CONNECTION_destroy (cph); 1588 GNUNET_CONNECTION_destroy(cph);
1592 connect_success_continuation (proxied); 1589 connect_success_continuation(proxied);
1593} 1590}
1594 1591
1595 1592
diff --git a/src/transport/tcp_server_legacy.c b/src/transport/tcp_server_legacy.c
index d66cb8387..f2d5386ff 100644
--- a/src/transport/tcp_server_legacy.c
+++ b/src/transport/tcp_server_legacy.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/server.c 22 * @file util/server.c
@@ -28,14 +28,13 @@
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, filename) GNUNET_log_from_strerror_file(kind, "util-server", syscall, filename)
32 32
33 33
34/** 34/**
35 * List of arrays of message handlers. 35 * List of arrays of message handlers.
36 */ 36 */
37struct HandlerList 37struct HandlerList {
38{
39 /** 38 /**
40 * This is a linked list. 39 * This is a linked list.
41 */ 40 */
@@ -51,8 +50,7 @@ struct HandlerList
51/** 50/**
52 * List of arrays of message handlers. 51 * List of arrays of message handlers.
53 */ 52 */
54struct NotifyList 53struct NotifyList {
55{
56 /** 54 /**
57 * This is a doubly linked list. 55 * This is a doubly linked list.
58 */ 56 */
@@ -78,8 +76,7 @@ struct NotifyList
78/** 76/**
79 * @brief handle for a server 77 * @brief handle for a server
80 */ 78 */
81struct GNUNET_SERVER_Handle 79struct GNUNET_SERVER_Handle {
82{
83 /** 80 /**
84 * List of handlers for incoming messages. 81 * List of handlers for incoming messages.
85 */ 82 */
@@ -182,8 +179,7 @@ struct GNUNET_SERVER_Handle
182/** 179/**
183 * Handle server returns for aborting transmission to a client. 180 * Handle server returns for aborting transmission to a client.
184 */ 181 */
185struct GNUNET_SERVER_TransmitHandle 182struct GNUNET_SERVER_TransmitHandle {
186{
187 /** 183 /**
188 * Function to call to get the message. 184 * Function to call to get the message.
189 */ 185 */
@@ -198,16 +194,13 @@ struct GNUNET_SERVER_TransmitHandle
198 * Active connection transmission handle. 194 * Active connection transmission handle.
199 */ 195 */
200 struct GNUNET_CONNECTION_TransmitHandle *cth; 196 struct GNUNET_CONNECTION_TransmitHandle *cth;
201
202}; 197};
203 198
204 199
205/** 200/**
206 * @brief handle for a client of the server 201 * @brief handle for a client of the server
207 */ 202 */
208struct GNUNET_SERVER_Client 203struct GNUNET_SERVER_Client {
209{
210
211 /** 204 /**
212 * This is a doubly linked list. 205 * This is a doubly linked list.
213 */ 206 */
@@ -345,13 +338,13 @@ struct GNUNET_SERVER_Client
345 * @return pointer to user context 338 * @return pointer to user context
346 */ 339 */
347void * 340void *
348GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, 341GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client,
349 size_t size) 342 size_t size)
350{ 343{
351 if ((0 == client->user_context_size) && 344 if ((0 == client->user_context_size) &&
352 (NULL == client->user_context)) 345 (NULL == client->user_context))
353 return NULL; /* never set */ 346 return NULL; /* never set */
354 GNUNET_assert (size == client->user_context_size); 347 GNUNET_assert(size == client->user_context_size);
355 return client->user_context; 348 return client->user_context;
356} 349}
357 350
@@ -365,16 +358,16 @@ GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
365 * @param size number of bytes in user context struct (for verification only) 358 * @param size number of bytes in user context struct (for verification only)
366 */ 359 */
367void 360void
368GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, 361GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client,
369 void *ptr, 362 void *ptr,
370 size_t size) 363 size_t size)
371{ 364{
372 if (NULL == ptr) 365 if (NULL == ptr)
373 { 366 {
374 client->user_context_size = 0; 367 client->user_context_size = 0;
375 client->user_context = ptr; 368 client->user_context = ptr;
376 return; 369 return;
377 } 370 }
378 client->user_context_size = size; 371 client->user_context_size = size;
379 client->user_context = ptr; 372 client->user_context = ptr;
380} 373}
@@ -387,7 +380,7 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
387 * socket 380 * socket
388 */ 381 */
389static void 382static void
390process_listen_socket (void *cls) 383process_listen_socket(void *cls)
391{ 384{
392 struct GNUNET_SERVER_Handle *server = cls; 385 struct GNUNET_SERVER_Handle *server = cls;
393 const struct GNUNET_SCHEDULER_TaskContext *tc; 386 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -395,27 +388,27 @@ process_listen_socket (void *cls)
395 unsigned int i; 388 unsigned int i;
396 389
397 server->listen_task = NULL; 390 server->listen_task = NULL;
398 tc = GNUNET_SCHEDULER_get_task_context (); 391 tc = GNUNET_SCHEDULER_get_task_context();
399 for (i = 0; NULL != server->listen_sockets[i]; i++) 392 for (i = 0; NULL != server->listen_sockets[i]; i++)
400 {
401 if (GNUNET_NETWORK_fdset_isset (tc->read_ready,
402 server->listen_sockets[i]))
403 { 393 {
404 sock = 394 if (GNUNET_NETWORK_fdset_isset(tc->read_ready,
405 GNUNET_CONNECTION_create_from_accept (server->access_cb, 395 server->listen_sockets[i]))
406 server->access_cb_cls, 396 {
407 server->listen_sockets[i]); 397 sock =
408 if (NULL != sock) 398 GNUNET_CONNECTION_create_from_accept(server->access_cb,
409 { 399 server->access_cb_cls,
410 LOG (GNUNET_ERROR_TYPE_DEBUG, 400 server->listen_sockets[i]);
411 "Server accepted incoming connection.\n"); 401 if (NULL != sock)
412 (void) GNUNET_SERVER_connect_socket (server, 402 {
413 sock); 403 LOG(GNUNET_ERROR_TYPE_DEBUG,
414 } 404 "Server accepted incoming connection.\n");
405 (void)GNUNET_SERVER_connect_socket(server,
406 sock);
407 }
408 }
415 } 409 }
416 }
417 /* listen for more! */ 410 /* listen for more! */
418 GNUNET_SERVER_resume (server); 411 GNUNET_SERVER_resume(server);
419} 412}
420 413
421 414
@@ -427,87 +420,90 @@ process_listen_socket (void *cls)
427 * @return NULL on error, otherwise the listen socket 420 * @return NULL on error, otherwise the listen socket
428 */ 421 */
429static struct GNUNET_NETWORK_Handle * 422static struct GNUNET_NETWORK_Handle *
430open_listen_socket (const struct sockaddr *server_addr, 423open_listen_socket(const struct sockaddr *server_addr,
431 socklen_t socklen) 424 socklen_t socklen)
432{ 425{
433 struct GNUNET_NETWORK_Handle *sock; 426 struct GNUNET_NETWORK_Handle *sock;
434 uint16_t port; 427 uint16_t port;
435 int eno; 428 int eno;
436 429
437 switch (server_addr->sa_family) 430 switch (server_addr->sa_family)
438 { 431 {
439 case AF_INET: 432 case AF_INET:
440 port = ntohs (((const struct sockaddr_in *) server_addr)->sin_port); 433 port = ntohs(((const struct sockaddr_in *)server_addr)->sin_port);
441 break; 434 break;
442 case AF_INET6: 435
443 port = ntohs (((const struct sockaddr_in6 *) server_addr)->sin6_port); 436 case AF_INET6:
444 break; 437 port = ntohs(((const struct sockaddr_in6 *)server_addr)->sin6_port);
445 case AF_UNIX: 438 break;
446 port = 0; 439
447 break; 440 case AF_UNIX:
448 default: 441 port = 0;
449 GNUNET_break (0); 442 break;
450 port = 0; 443
451 break; 444 default:
452 } 445 GNUNET_break(0);
453 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0); 446 port = 0;
447 break;
448 }
449 sock = GNUNET_NETWORK_socket_create(server_addr->sa_family, SOCK_STREAM, 0);
454 if (NULL == sock) 450 if (NULL == sock)
455 { 451 {
456 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 452 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket");
457 errno = 0; 453 errno = 0;
458 return NULL; 454 return NULL;
459 } 455 }
460 /* bind the socket */ 456 /* bind the socket */
461 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen)) 457 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(sock, server_addr, socklen))
462 {
463 eno = errno;
464 if (EADDRINUSE != errno)
465 { 458 {
466 /* we don't log 'EADDRINUSE' here since an IPv4 bind may 459 eno = errno;
467 * fail if we already took the port on IPv6; if both IPv4 and 460 if (EADDRINUSE != errno)
468 * IPv6 binds fail, then our caller will log using the 461 {
469 * errno preserved in 'eno' */ 462 /* we don't log 'EADDRINUSE' here since an IPv4 bind may
470 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, 463 * fail if we already took the port on IPv6; if both IPv4 and
471 "bind"); 464 * IPv6 binds fail, then our caller will log using the
472 if (0 != port) 465 * errno preserved in 'eno' */
473 LOG (GNUNET_ERROR_TYPE_ERROR, 466 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR,
474 _("`%s' failed for port %d (%s).\n"), 467 "bind");
475 "bind", 468 if (0 != port)
476 port, 469 LOG(GNUNET_ERROR_TYPE_ERROR,
477 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); 470 _("`%s' failed for port %d (%s).\n"),
478 eno = 0; 471 "bind",
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;
479 } 494 }
480 else 495 if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5))
481 { 496 {
482 if (0 != port) 497 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR,
483 LOG (GNUNET_ERROR_TYPE_WARNING, 498 "listen");
484 _("`%s' failed for port %d (%s): address already in use\n"), 499 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock));
485 "bind", port, 500 errno = 0;
486 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6"); 501 return NULL;
487 else if (AF_UNIX == server_addr->sa_family)
488 {
489 LOG (GNUNET_ERROR_TYPE_WARNING,
490 _("`%s' failed for `%s': address already in use\n"),
491 "bind",
492 GNUNET_a2s (server_addr, socklen));
493 }
494 } 502 }
495 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
496 errno = eno;
497 return NULL;
498 }
499 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
500 {
501 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
502 "listen");
503 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
504 errno = 0;
505 return NULL;
506 }
507 if (0 != port) 503 if (0 != port)
508 LOG (GNUNET_ERROR_TYPE_DEBUG, 504 LOG(GNUNET_ERROR_TYPE_DEBUG,
509 "Server starts to listen on port %u.\n", 505 "Server starts to listen on port %u.\n",
510 port); 506 port);
511 return sock; 507 return sock;
512} 508}
513 509
@@ -525,22 +521,22 @@ open_listen_socket (const struct sockaddr *server_addr,
525 * (typically, "port" already in use) 521 * (typically, "port" already in use)
526 */ 522 */
527struct GNUNET_SERVER_Handle * 523struct GNUNET_SERVER_Handle *
528GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb, 524GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb,
529 void *access_cb_cls, 525 void *access_cb_cls,
530 struct GNUNET_NETWORK_Handle **lsocks, 526 struct GNUNET_NETWORK_Handle **lsocks,
531 struct GNUNET_TIME_Relative idle_timeout, 527 struct GNUNET_TIME_Relative idle_timeout,
532 int require_found) 528 int require_found)
533{ 529{
534 struct GNUNET_SERVER_Handle *server; 530 struct GNUNET_SERVER_Handle *server;
535 531
536 server = GNUNET_new (struct GNUNET_SERVER_Handle); 532 server = GNUNET_new(struct GNUNET_SERVER_Handle);
537 server->idle_timeout = idle_timeout; 533 server->idle_timeout = idle_timeout;
538 server->listen_sockets = lsocks; 534 server->listen_sockets = lsocks;
539 server->access_cb = access_cb; 535 server->access_cb = access_cb;
540 server->access_cb_cls = access_cb_cls; 536 server->access_cb_cls = access_cb_cls;
541 server->require_found = require_found; 537 server->require_found = require_found;
542 if (NULL != lsocks) 538 if (NULL != lsocks)
543 GNUNET_SERVER_resume (server); 539 GNUNET_SERVER_resume(server);
544 return server; 540 return server;
545} 541}
546 542
@@ -559,12 +555,12 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb,
559 * (typically, "port" already in use) 555 * (typically, "port" already in use)
560 */ 556 */
561struct GNUNET_SERVER_Handle * 557struct GNUNET_SERVER_Handle *
562GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb, 558GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb,
563 void *access_cb_cls, 559 void *access_cb_cls,
564 struct sockaddr *const *server_addr, 560 struct sockaddr *const *server_addr,
565 const socklen_t * socklen, 561 const socklen_t * socklen,
566 struct GNUNET_TIME_Relative idle_timeout, 562 struct GNUNET_TIME_Relative idle_timeout,
567 int require_found) 563 int require_found)
568{ 564{
569 struct GNUNET_NETWORK_Handle **lsocks; 565 struct GNUNET_NETWORK_Handle **lsocks;
570 unsigned int i; 566 unsigned int i;
@@ -576,48 +572,48 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb,
576 while (NULL != server_addr[i]) 572 while (NULL != server_addr[i])
577 i++; 573 i++;
578 if (i > 0) 574 if (i > 0)
579 {
580 lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (i + 1));
581 i = 0;
582 j = 0;
583 while (NULL != server_addr[i])
584 { 575 {
585 seen = 0; 576 lsocks = GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1));
586 for (k=0;k<i;k++) 577 i = 0;
587 if ( (socklen[k] == socklen[i]) && 578 j = 0;
588 (0 == memcmp (server_addr[k], server_addr[i], socklen[i])) ) 579 while (NULL != server_addr[i])
589 { 580 {
590 seen = 1; 581 seen = 0;
591 break; 582 for (k = 0; k < i; k++)
592 } 583 if ((socklen[k] == socklen[i]) &&
593 if (0 != seen) 584 (0 == memcmp(server_addr[k], server_addr[i], socklen[i])))
594 { 585 {
595 /* duplicate address, skip */ 586 seen = 1;
596 i++; 587 break;
597 continue; 588 }
598 } 589 if (0 != seen)
599 lsocks[j] = open_listen_socket (server_addr[i], socklen[i]); 590 {
600 if (NULL != lsocks[j]) 591 /* duplicate address, skip */
601 j++; 592 i++;
602 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 }
603 } 607 }
604 if (0 == j) 608 else
605 { 609 {
606 if (0 != errno)
607 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
608 GNUNET_free (lsocks);
609 lsocks = NULL; 610 lsocks = NULL;
610 } 611 }
611 } 612 return GNUNET_SERVER_create_with_sockets(access_cb,
612 else 613 access_cb_cls,
613 { 614 lsocks,
614 lsocks = NULL; 615 idle_timeout,
615 } 616 require_found);
616 return GNUNET_SERVER_create_with_sockets (access_cb,
617 access_cb_cls,
618 lsocks,
619 idle_timeout,
620 require_found);
621} 617}
622 618
623 619
@@ -634,10 +630,10 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb,
634 * @param client the client to set the 'monitor' flag on 630 * @param client the client to set the 'monitor' flag on
635 */ 631 */
636void 632void
637GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client) 633GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client)
638{ 634{
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
640 "Marking client as monitor!\n"); 636 "Marking client as monitor!\n");
641 client->is_monitor = GNUNET_YES; 637 client->is_monitor = GNUNET_YES;
642} 638}
643 639
@@ -649,11 +645,11 @@ GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client)
649 * @param cls the `struct GNUNET_SERVER_Handle *` to destroy 645 * @param cls the `struct GNUNET_SERVER_Handle *` to destroy
650 */ 646 */
651static void 647static void
652do_destroy (void *cls) 648do_destroy(void *cls)
653{ 649{
654 struct GNUNET_SERVER_Handle *server = cls; 650 struct GNUNET_SERVER_Handle *server = cls;
655 651
656 GNUNET_SERVER_destroy (server); 652 GNUNET_SERVER_destroy(server);
657} 653}
658 654
659 655
@@ -664,7 +660,7 @@ do_destroy (void *cls)
664 * @param server server to test for full shutdown 660 * @param server server to test for full shutdown
665 */ 661 */
666static void 662static void
667test_monitor_clients (struct GNUNET_SERVER_Handle *server) 663test_monitor_clients(struct GNUNET_SERVER_Handle *server)
668{ 664{
669 struct GNUNET_SERVER_Client *client; 665 struct GNUNET_SERVER_Client *client;
670 666
@@ -672,9 +668,10 @@ test_monitor_clients (struct GNUNET_SERVER_Handle *server)
672 return; 668 return;
673 for (client = server->clients_head; NULL != client; client = client->next) 669 for (client = server->clients_head; NULL != client; client = client->next)
674 if (GNUNET_NO == client->is_monitor) 670 if (GNUNET_NO == client->is_monitor)
675 return; /* not done yet */ 671 return;
672 /* not done yet */
676 server->in_soft_shutdown = GNUNET_SYSERR; 673 server->in_soft_shutdown = GNUNET_SYSERR;
677 (void) GNUNET_SCHEDULER_add_now (&do_destroy, server); 674 (void)GNUNET_SCHEDULER_add_now(&do_destroy, server);
678} 675}
679 676
680 677
@@ -684,13 +681,13 @@ test_monitor_clients (struct GNUNET_SERVER_Handle *server)
684 * @param server server to stop accepting connections. 681 * @param server server to stop accepting connections.
685 */ 682 */
686void 683void
687GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server) 684GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server)
688{ 685{
689 if (NULL != server->listen_task) 686 if (NULL != server->listen_task)
690 { 687 {
691 GNUNET_SCHEDULER_cancel (server->listen_task); 688 GNUNET_SCHEDULER_cancel(server->listen_task);
692 server->listen_task = NULL; 689 server->listen_task = NULL;
693 } 690 }
694} 691}
695 692
696 693
@@ -700,7 +697,7 @@ GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
700 * @param server server to stop accepting connections. 697 * @param server server to stop accepting connections.
701 */ 698 */
702void 699void
703GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server) 700GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
704{ 701{
705 struct GNUNET_NETWORK_FDSet *r; 702 struct GNUNET_NETWORK_FDSet *r;
706 unsigned int i; 703 unsigned int i;
@@ -710,25 +707,25 @@ GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
710 if (NULL == server->listen_sockets[0]) 707 if (NULL == server->listen_sockets[0])
711 return; /* nothing to do, no listen sockets! */ 708 return; /* nothing to do, no listen sockets! */
712 if (NULL == server->listen_sockets[1]) 709 if (NULL == server->listen_sockets[1])
713 { 710 {
714 /* simplified method: no fd set needed; this is then much simpler 711 /* simplified method: no fd set needed; this is then much simpler
715 and much more efficient */ 712 and much more efficient */
716 server->listen_task = 713 server->listen_task =
717 GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL, 714 GNUNET_SCHEDULER_add_read_net_with_priority(GNUNET_TIME_UNIT_FOREVER_REL,
718 GNUNET_SCHEDULER_PRIORITY_HIGH, 715 GNUNET_SCHEDULER_PRIORITY_HIGH,
719 server->listen_sockets[0], 716 server->listen_sockets[0],
720 &process_listen_socket, server); 717 &process_listen_socket, server);
721 return; 718 return;
722 } 719 }
723 r = GNUNET_NETWORK_fdset_create (); 720 r = GNUNET_NETWORK_fdset_create();
724 i = 0; 721 i = 0;
725 while (NULL != server->listen_sockets[i]) 722 while (NULL != server->listen_sockets[i])
726 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); 723 GNUNET_NETWORK_fdset_set(r, server->listen_sockets[i++]);
727 server->listen_task = 724 server->listen_task =
728 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH, 725 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH,
729 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 726 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
730 &process_listen_socket, server); 727 &process_listen_socket, server);
731 GNUNET_NETWORK_fdset_destroy (r); 728 GNUNET_NETWORK_fdset_destroy(r);
732} 729}
733 730
734 731
@@ -739,29 +736,29 @@ GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
739 * @param server server to stop listening on 736 * @param server server to stop listening on
740 */ 737 */
741void 738void
742GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server) 739GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server)
743{ 740{
744 unsigned int i; 741 unsigned int i;
745 742
746 LOG (GNUNET_ERROR_TYPE_DEBUG, 743 LOG(GNUNET_ERROR_TYPE_DEBUG,
747 "Server in soft shutdown\n"); 744 "Server in soft shutdown\n");
748 if (NULL != server->listen_task) 745 if (NULL != server->listen_task)
749 { 746 {
750 GNUNET_SCHEDULER_cancel (server->listen_task); 747 GNUNET_SCHEDULER_cancel(server->listen_task);
751 server->listen_task = NULL; 748 server->listen_task = NULL;
752 } 749 }
753 if (NULL != server->listen_sockets) 750 if (NULL != server->listen_sockets)
754 { 751 {
755 i = 0; 752 i = 0;
756 while (NULL != server->listen_sockets[i]) 753 while (NULL != server->listen_sockets[i])
757 GNUNET_break (GNUNET_OK == 754 GNUNET_break(GNUNET_OK ==
758 GNUNET_NETWORK_socket_close (server->listen_sockets[i++])); 755 GNUNET_NETWORK_socket_close(server->listen_sockets[i++]));
759 GNUNET_free (server->listen_sockets); 756 GNUNET_free(server->listen_sockets);
760 server->listen_sockets = NULL; 757 server->listen_sockets = NULL;
761 } 758 }
762 if (GNUNET_NO == server->in_soft_shutdown) 759 if (GNUNET_NO == server->in_soft_shutdown)
763 server->in_soft_shutdown = GNUNET_YES; 760 server->in_soft_shutdown = GNUNET_YES;
764 test_monitor_clients (server); 761 test_monitor_clients(server);
765} 762}
766 763
767 764
@@ -771,54 +768,54 @@ GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server)
771 * @param server server to destroy 768 * @param server server to destroy
772 */ 769 */
773void 770void
774GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server) 771GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server)
775{ 772{
776 struct HandlerList *hpos; 773 struct HandlerList *hpos;
777 struct NotifyList *npos; 774 struct NotifyList *npos;
778 unsigned int i; 775 unsigned int i;
779 776
780 LOG (GNUNET_ERROR_TYPE_DEBUG, 777 LOG(GNUNET_ERROR_TYPE_DEBUG,
781 "Server shutting down.\n"); 778 "Server shutting down.\n");
782 if (NULL != server->listen_task) 779 if (NULL != server->listen_task)
783 { 780 {
784 GNUNET_SCHEDULER_cancel (server->listen_task); 781 GNUNET_SCHEDULER_cancel(server->listen_task);
785 server->listen_task = NULL; 782 server->listen_task = NULL;
786 } 783 }
787 if (NULL != server->listen_sockets) 784 if (NULL != server->listen_sockets)
788 { 785 {
789 i = 0; 786 i = 0;
790 while (NULL != server->listen_sockets[i]) 787 while (NULL != server->listen_sockets[i])
791 GNUNET_break (GNUNET_OK == 788 GNUNET_break(GNUNET_OK ==
792 GNUNET_NETWORK_socket_close (server->listen_sockets[i++])); 789 GNUNET_NETWORK_socket_close(server->listen_sockets[i++]));
793 GNUNET_free (server->listen_sockets); 790 GNUNET_free(server->listen_sockets);
794 server->listen_sockets = NULL; 791 server->listen_sockets = NULL;
795 } 792 }
796 while (NULL != server->clients_head) 793 while (NULL != server->clients_head)
797 GNUNET_SERVER_client_disconnect (server->clients_head); 794 GNUNET_SERVER_client_disconnect(server->clients_head);
798 while (NULL != (hpos = server->handlers)) 795 while (NULL != (hpos = server->handlers))
799 { 796 {
800 server->handlers = hpos->next; 797 server->handlers = hpos->next;
801 GNUNET_free (hpos); 798 GNUNET_free(hpos);
802 } 799 }
803 while (NULL != (npos = server->disconnect_notify_list_head)) 800 while (NULL != (npos = server->disconnect_notify_list_head))
804 { 801 {
805 npos->callback (npos->callback_cls, 802 npos->callback(npos->callback_cls,
806 NULL); 803 NULL);
807 GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head, 804 GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head,
808 server->disconnect_notify_list_tail, 805 server->disconnect_notify_list_tail,
809 npos); 806 npos);
810 GNUNET_free (npos); 807 GNUNET_free(npos);
811 } 808 }
812 while (NULL != (npos = server->connect_notify_list_head)) 809 while (NULL != (npos = server->connect_notify_list_head))
813 { 810 {
814 npos->callback (npos->callback_cls, 811 npos->callback(npos->callback_cls,
815 NULL); 812 NULL);
816 GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head, 813 GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head,
817 server->connect_notify_list_tail, 814 server->connect_notify_list_tail,
818 npos); 815 npos);
819 GNUNET_free (npos); 816 GNUNET_free(npos);
820 } 817 }
821 GNUNET_free (server); 818 GNUNET_free(server);
822} 819}
823 820
824 821
@@ -836,12 +833,12 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server)
836 * (or server is destroyed). 833 * (or server is destroyed).
837 */ 834 */
838void 835void
839GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, 836GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server,
840 const struct GNUNET_SERVER_MessageHandler *handlers) 837 const struct GNUNET_SERVER_MessageHandler *handlers)
841{ 838{
842 struct HandlerList *p; 839 struct HandlerList *p;
843 840
844 p = GNUNET_new (struct HandlerList); 841 p = GNUNET_new(struct HandlerList);
845 p->handlers = handlers; 842 p->handlers = handlers;
846 p->next = server->handlers; 843 p->next = server->handlers;
847 server->handlers = p; 844 server->handlers = p;
@@ -859,11 +856,11 @@ GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
859 * @param cls closure for @a create, @a receive, @a destroy 856 * @param cls closure for @a create, @a receive, @a destroy
860 */ 857 */
861void 858void
862GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server, 859GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server,
863 GNUNET_SERVER_MstCreateCallback create, 860 GNUNET_SERVER_MstCreateCallback create,
864 GNUNET_SERVER_MstDestroyCallback destroy, 861 GNUNET_SERVER_MstDestroyCallback destroy,
865 GNUNET_SERVER_MstReceiveCallback receive, 862 GNUNET_SERVER_MstReceiveCallback receive,
866 void *cls) 863 void *cls)
867{ 864{
868 server->mst_create = create; 865 server->mst_create = create;
869 server->mst_destroy = destroy; 866 server->mst_destroy = destroy;
@@ -878,19 +875,19 @@ GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
878 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from 875 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from
879 */ 876 */
880static void 877static void
881warn_no_receive_done (void *cls) 878warn_no_receive_done(void *cls)
882{ 879{
883 struct GNUNET_SERVER_Client *client = cls; 880 struct GNUNET_SERVER_Client *client = cls;
884 881
885 GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ 882 GNUNET_break(0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
886 client->warn_task = 883 client->warn_task =
887 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 884 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
888 &warn_no_receive_done, client); 885 &warn_no_receive_done, client);
889 LOG (GNUNET_ERROR_TYPE_WARNING, 886 LOG(GNUNET_ERROR_TYPE_WARNING,
890 _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), 887 _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
891 (unsigned int) client->warn_type, 888 (unsigned int)client->warn_type,
892 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (client->warn_start), 889 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(client->warn_start),
893 GNUNET_YES)); 890 GNUNET_YES));
894} 891}
895 892
896 893
@@ -902,13 +899,13 @@ warn_no_receive_done (void *cls)
902 * @param client client for which to disable the warning 899 * @param client client for which to disable the warning
903 */ 900 */
904void 901void
905GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client) 902GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client)
906{ 903{
907 if (NULL != client->warn_task) 904 if (NULL != client->warn_task)
908 { 905 {
909 GNUNET_SCHEDULER_cancel (client->warn_task); 906 GNUNET_SCHEDULER_cancel(client->warn_task);
910 client->warn_task = NULL; 907 client->warn_task = NULL;
911 } 908 }
912} 909}
913 910
914 911
@@ -928,9 +925,9 @@ GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
928 * client should be shut down 925 * client should be shut down
929 */ 926 */
930int 927int
931GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, 928GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server,
932 struct GNUNET_SERVER_Client *sender, 929 struct GNUNET_SERVER_Client *sender,
933 const struct GNUNET_MessageHeader *message) 930 const struct GNUNET_MessageHeader *message)
934{ 931{
935 struct HandlerList *pos; 932 struct HandlerList *pos;
936 const struct GNUNET_SERVER_MessageHandler *mh; 933 const struct GNUNET_SERVER_MessageHandler *mh;
@@ -939,62 +936,62 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
939 uint16_t size; 936 uint16_t size;
940 int found; 937 int found;
941 938
942 type = ntohs (message->type); 939 type = ntohs(message->type);
943 size = ntohs (message->size); 940 size = ntohs(message->size);
944 LOG (GNUNET_ERROR_TYPE_INFO, 941 LOG(GNUNET_ERROR_TYPE_INFO,
945 "Received message of type %u and size %u from client\n", 942 "Received message of type %u and size %u from client\n",
946 type, size); 943 type, size);
947 found = GNUNET_NO; 944 found = GNUNET_NO;
948 for (pos = server->handlers; NULL != pos; pos = pos->next) 945 for (pos = server->handlers; NULL != pos; pos = pos->next)
949 {
950 i = 0;
951 while (pos->handlers[i].callback != NULL)
952 { 946 {
953 mh = &pos->handlers[i]; 947 i = 0;
954 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL)) 948 while (pos->handlers[i].callback != NULL)
955 {
956 if ((0 != mh->expected_size) && (mh->expected_size != size))
957 { 949 {
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 {
958#if GNUNET8_NETWORK_IS_DEAD 955#if GNUNET8_NETWORK_IS_DEAD
959 LOG (GNUNET_ERROR_TYPE_WARNING, 956 LOG(GNUNET_ERROR_TYPE_WARNING,
960 "Expected %u bytes for message of type %u, got %u\n", 957 "Expected %u bytes for message of type %u, got %u\n",
961 mh->expected_size, mh->type, size); 958 mh->expected_size, mh->type, size);
962 GNUNET_break_op (0); 959 GNUNET_break_op(0);
963#else 960#else
964 LOG (GNUNET_ERROR_TYPE_DEBUG, 961 LOG(GNUNET_ERROR_TYPE_DEBUG,
965 "Expected %u bytes for message of type %u, got %u\n", 962 "Expected %u bytes for message of type %u, got %u\n",
966 mh->expected_size, mh->type, size); 963 mh->expected_size, mh->type, size);
967#endif 964#endif
968 return GNUNET_SYSERR; 965 return GNUNET_SYSERR;
969 } 966 }
970 if (NULL != sender) 967 if (NULL != sender)
971 { 968 {
972 if ( (0 == sender->suspended) && 969 if ((0 == sender->suspended) &&
973 (NULL == sender->warn_task) ) 970 (NULL == sender->warn_task))
974 { 971 {
975 GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */ 972 GNUNET_break(0 != type); /* type should never be 0 here, as we don't use 0 */
976 sender->warn_start = GNUNET_TIME_absolute_get (); 973 sender->warn_start = GNUNET_TIME_absolute_get();
977 sender->warn_task = 974 sender->warn_task =
978 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 975 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
979 &warn_no_receive_done, 976 &warn_no_receive_done,
980 sender); 977 sender);
981 sender->warn_type = type; 978 sender->warn_type = type;
982 } 979 }
983 sender->suspended++; 980 sender->suspended++;
981 }
982 mh->callback(mh->callback_cls, sender, message);
983 found = GNUNET_YES;
984 }
985 i++;
984 } 986 }
985 mh->callback (mh->callback_cls, sender, message);
986 found = GNUNET_YES;
987 }
988 i++;
989 } 987 }
990 }
991 if (GNUNET_NO == found) 988 if (GNUNET_NO == found)
992 { 989 {
993 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 990 LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
994 "Received message of unknown type %d\n", type); 991 "Received message of unknown type %d\n", type);
995 if (GNUNET_YES == server->require_found) 992 if (GNUNET_YES == server->require_found)
996 return GNUNET_SYSERR; 993 return GNUNET_SYSERR;
997 } 994 }
998 return GNUNET_OK; 995 return GNUNET_OK;
999} 996}
1000 997
@@ -1010,12 +1007,12 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
1010 * @param errCode code indicating errors receiving, 0 for success 1007 * @param errCode code indicating errors receiving, 0 for success
1011 */ 1008 */
1012static void 1009static void
1013process_incoming (void *cls, 1010process_incoming(void *cls,
1014 const void *buf, 1011 const void *buf,
1015 size_t available, 1012 size_t available,
1016 const struct sockaddr *addr, 1013 const struct sockaddr *addr,
1017 socklen_t addrlen, 1014 socklen_t addrlen,
1018 int errCode); 1015 int errCode);
1019 1016
1020 1017
1021/** 1018/**
@@ -1032,52 +1029,52 @@ process_incoming (void *cls,
1032 * #GNUNET_SYSERR if we should instantly abort due to error in a previous step 1029 * #GNUNET_SYSERR if we should instantly abort due to error in a previous step
1033 */ 1030 */
1034static void 1031static void
1035process_mst (struct GNUNET_SERVER_Client *client, 1032process_mst(struct GNUNET_SERVER_Client *client,
1036 int ret) 1033 int ret)
1037{ 1034{
1038 while ((GNUNET_SYSERR != ret) && (NULL != client->server) && 1035 while ((GNUNET_SYSERR != ret) && (NULL != client->server) &&
1039 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) 1036 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
1040 {
1041 if (GNUNET_OK == ret)
1042 { 1037 {
1043 LOG (GNUNET_ERROR_TYPE_DEBUG, 1038 if (GNUNET_OK == ret)
1044 "Server re-enters receive loop, timeout: %s.\n", 1039 {
1045 GNUNET_STRINGS_relative_time_to_string (client->idle_timeout, GNUNET_YES)); 1040 LOG(GNUNET_ERROR_TYPE_DEBUG,
1046 client->receive_pending = GNUNET_YES; 1041 "Server re-enters receive loop, timeout: %s.\n",
1047 if (GNUNET_OK != 1042 GNUNET_STRINGS_relative_time_to_string(client->idle_timeout, GNUNET_YES));
1048 GNUNET_CONNECTION_receive (client->connection, 1043 client->receive_pending = GNUNET_YES;
1049 GNUNET_MAX_MESSAGE_SIZE - 1, 1044 if (GNUNET_OK !=
1050 client->idle_timeout, 1045 GNUNET_CONNECTION_receive(client->connection,
1051 &process_incoming, 1046 GNUNET_MAX_MESSAGE_SIZE - 1,
1052 client)) 1047 client->idle_timeout,
1053 return; 1048 &process_incoming,
1054 break; 1049 client))
1050 return;
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);
1055 } 1063 }
1056 LOG (GNUNET_ERROR_TYPE_DEBUG, 1064 LOG(GNUNET_ERROR_TYPE_DEBUG,
1057 "Server processes additional messages instantly.\n"); 1065 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
1058 if (NULL != client->server->mst_receive) 1066 ret, client->server,
1059 ret = 1067 client->shutdown_now,
1060 client->server->mst_receive (client->server->mst_cls, client->mst, 1068 client->suspended);
1061 client, NULL, 0, GNUNET_NO, GNUNET_YES);
1062 else
1063 ret =
1064 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
1065 GNUNET_YES);
1066 }
1067 LOG (GNUNET_ERROR_TYPE_DEBUG,
1068 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
1069 ret, client->server,
1070 client->shutdown_now,
1071 client->suspended);
1072 if (GNUNET_NO == ret) 1069 if (GNUNET_NO == ret)
1073 { 1070 {
1074 LOG (GNUNET_ERROR_TYPE_DEBUG, 1071 LOG(GNUNET_ERROR_TYPE_DEBUG,
1075 "Server has more data pending but is suspended.\n"); 1072 "Server has more data pending but is suspended.\n");
1076 client->receive_pending = GNUNET_SYSERR; /* data pending */ 1073 client->receive_pending = GNUNET_SYSERR; /* data pending */
1077 } 1074 }
1078 if ( (GNUNET_SYSERR == ret) || 1075 if ((GNUNET_SYSERR == ret) ||
1079 (GNUNET_YES == client->shutdown_now) ) 1076 (GNUNET_YES == client->shutdown_now))
1080 GNUNET_SERVER_client_disconnect (client); 1077 GNUNET_SERVER_client_disconnect(client);
1081} 1078}
1082 1079
1083 1080
@@ -1092,12 +1089,12 @@ process_mst (struct GNUNET_SERVER_Client *client,
1092 * @param errCode code indicating errors receiving, 0 for success 1089 * @param errCode code indicating errors receiving, 0 for success
1093 */ 1090 */
1094static void 1091static void
1095process_incoming (void *cls, 1092process_incoming(void *cls,
1096 const void *buf, 1093 const void *buf,
1097 size_t available, 1094 size_t available,
1098 const struct sockaddr *addr, 1095 const struct sockaddr *addr,
1099 socklen_t addrlen, 1096 socklen_t addrlen,
1100 int errCode) 1097 int errCode)
1101{ 1098{
1102 struct GNUNET_SERVER_Client *client = cls; 1099 struct GNUNET_SERVER_Client *client = cls;
1103 struct GNUNET_SERVER_Handle *server = client->server; 1100 struct GNUNET_SERVER_Handle *server = client->server;
@@ -1105,82 +1102,82 @@ process_incoming (void *cls,
1105 struct GNUNET_TIME_Absolute now; 1102 struct GNUNET_TIME_Absolute now;
1106 int ret; 1103 int ret;
1107 1104
1108 GNUNET_assert (GNUNET_YES == client->receive_pending); 1105 GNUNET_assert(GNUNET_YES == client->receive_pending);
1109 client->receive_pending = GNUNET_NO; 1106 client->receive_pending = GNUNET_NO;
1110 now = GNUNET_TIME_absolute_get (); 1107 now = GNUNET_TIME_absolute_get();
1111 end = GNUNET_TIME_absolute_add (client->last_activity, 1108 end = GNUNET_TIME_absolute_add(client->last_activity,
1112 client->idle_timeout); 1109 client->idle_timeout);
1113 1110
1114 if ( (NULL == buf) && 1111 if ((NULL == buf) &&
1115 (0 == available) && 1112 (0 == available) &&
1116 (NULL == addr) && 1113 (NULL == addr) &&
1117 (0 == errCode) && 1114 (0 == errCode) &&
1118 (GNUNET_YES != client->shutdown_now) && 1115 (GNUNET_YES != client->shutdown_now) &&
1119 (NULL != server) && 1116 (NULL != server) &&
1120 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && 1117 (GNUNET_YES == GNUNET_CONNECTION_check(client->connection)) &&
1121 (end.abs_value_us > now.abs_value_us) ) 1118 (end.abs_value_us > now.abs_value_us))
1122 { 1119 {
1123 /* wait longer, timeout changed (i.e. due to us sending) */ 1120 /* wait longer, timeout changed (i.e. due to us sending) */
1124 LOG (GNUNET_ERROR_TYPE_DEBUG, 1121 LOG(GNUNET_ERROR_TYPE_DEBUG,
1125 "Receive time out, but no disconnect due to sending (%p)\n", 1122 "Receive time out, but no disconnect due to sending (%p)\n",
1126 client); 1123 client);
1127 client->receive_pending = GNUNET_YES; 1124 client->receive_pending = GNUNET_YES;
1128 GNUNET_CONNECTION_receive (client->connection, 1125 GNUNET_CONNECTION_receive(client->connection,
1129 GNUNET_MAX_MESSAGE_SIZE - 1, 1126 GNUNET_MAX_MESSAGE_SIZE - 1,
1130 GNUNET_TIME_absolute_get_remaining (end), 1127 GNUNET_TIME_absolute_get_remaining(end),
1131 &process_incoming, 1128 &process_incoming,
1132 client); 1129 client);
1133 return; 1130 return;
1134 } 1131 }
1135 if ( (NULL == buf) || 1132 if ((NULL == buf) ||
1136 (0 == available) || 1133 (0 == available) ||
1137 (0 != errCode) || 1134 (0 != errCode) ||
1138 (NULL == server) || 1135 (NULL == server) ||
1139 (GNUNET_YES == client->shutdown_now) || 1136 (GNUNET_YES == client->shutdown_now) ||
1140 (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)) ) 1137 (GNUNET_YES != GNUNET_CONNECTION_check(client->connection)))
1141 { 1138 {
1142 /* other side closed connection, error connecting, etc. */ 1139 /* other side closed connection, error connecting, etc. */
1143 LOG (GNUNET_ERROR_TYPE_DEBUG, 1140 LOG(GNUNET_ERROR_TYPE_DEBUG,
1144 "Failed to connect or other side closed connection (%p)\n", 1141 "Failed to connect or other side closed connection (%p)\n",
1145 client); 1142 client);
1146 GNUNET_SERVER_client_disconnect (client); 1143 GNUNET_SERVER_client_disconnect(client);
1147 return; 1144 return;
1148 } 1145 }
1149 LOG (GNUNET_ERROR_TYPE_DEBUG, 1146 LOG(GNUNET_ERROR_TYPE_DEBUG,
1150 "Server receives %u bytes from `%s'.\n", 1147 "Server receives %u bytes from `%s'.\n",
1151 (unsigned int) available, 1148 (unsigned int)available,
1152 GNUNET_a2s (addr, addrlen)); 1149 GNUNET_a2s(addr, addrlen));
1153 GNUNET_SERVER_client_keep (client); 1150 GNUNET_SERVER_client_keep(client);
1154 client->last_activity = now; 1151 client->last_activity = now;
1155 1152
1156 if (NULL != server->mst_receive) 1153 if (NULL != server->mst_receive)
1157 { 1154 {
1158 ret = client->server->mst_receive (client->server->mst_cls, 1155 ret = client->server->mst_receive(client->server->mst_cls,
1159 client->mst, 1156 client->mst,
1160 client, 1157 client,
1161 buf, 1158 buf,
1162 available, 1159 available,
1163 GNUNET_NO, 1160 GNUNET_NO,
1164 GNUNET_YES); 1161 GNUNET_YES);
1165 } 1162 }
1166 else if (NULL != client->mst) 1163 else if (NULL != client->mst)
1167 { 1164 {
1168 ret = 1165 ret =
1169 GNUNET_SERVER_mst_receive (client->mst, 1166 GNUNET_SERVER_mst_receive(client->mst,
1170 client, 1167 client,
1171 buf, 1168 buf,
1172 available, 1169 available,
1173 GNUNET_NO, 1170 GNUNET_NO,
1174 GNUNET_YES); 1171 GNUNET_YES);
1175 } 1172 }
1176 else 1173 else
1177 { 1174 {
1178 GNUNET_break (0); 1175 GNUNET_break(0);
1179 return; 1176 return;
1180 } 1177 }
1181 process_mst (client, 1178 process_mst(client,
1182 ret); 1179 ret);
1183 GNUNET_SERVER_client_drop (client); 1180 GNUNET_SERVER_client_drop(client);
1184} 1181}
1185 1182
1186 1183
@@ -1191,30 +1188,30 @@ process_incoming (void *cls,
1191 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from 1188 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from
1192 */ 1189 */
1193static void 1190static void
1194restart_processing (void *cls) 1191restart_processing(void *cls)
1195{ 1192{
1196 struct GNUNET_SERVER_Client *client = cls; 1193 struct GNUNET_SERVER_Client *client = cls;
1197 1194
1198 GNUNET_assert (GNUNET_YES != client->shutdown_now); 1195 GNUNET_assert(GNUNET_YES != client->shutdown_now);
1199 client->restart_task = NULL; 1196 client->restart_task = NULL;
1200 if (GNUNET_NO == client->receive_pending) 1197 if (GNUNET_NO == client->receive_pending)
1201 { 1198 {
1202 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); 1199 LOG(GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
1203 client->receive_pending = GNUNET_YES; 1200 client->receive_pending = GNUNET_YES;
1204 GNUNET_CONNECTION_receive (client->connection, 1201 GNUNET_CONNECTION_receive(client->connection,
1205 GNUNET_MAX_MESSAGE_SIZE - 1, 1202 GNUNET_MAX_MESSAGE_SIZE - 1,
1206 client->idle_timeout, 1203 client->idle_timeout,
1207 &process_incoming, 1204 &process_incoming,
1208 client); 1205 client);
1209 return; 1206 return;
1210 } 1207 }
1211 LOG (GNUNET_ERROR_TYPE_DEBUG, 1208 LOG(GNUNET_ERROR_TYPE_DEBUG,
1212 "Server continues processing messages still in the buffer.\n"); 1209 "Server continues processing messages still in the buffer.\n");
1213 GNUNET_SERVER_client_keep (client); 1210 GNUNET_SERVER_client_keep(client);
1214 client->receive_pending = GNUNET_NO; 1211 client->receive_pending = GNUNET_NO;
1215 process_mst (client, 1212 process_mst(client,
1216 GNUNET_NO); 1213 GNUNET_NO);
1217 GNUNET_SERVER_client_drop (client); 1214 GNUNET_SERVER_client_drop(client);
1218} 1215}
1219 1216
1220 1217
@@ -1229,25 +1226,25 @@ restart_processing (void *cls)
1229 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 1226 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
1230 */ 1227 */
1231static int 1228static int
1232client_message_tokenizer_callback (void *cls, 1229client_message_tokenizer_callback(void *cls,
1233 void *client, 1230 void *client,
1234 const struct GNUNET_MessageHeader *message) 1231 const struct GNUNET_MessageHeader *message)
1235{ 1232{
1236 struct GNUNET_SERVER_Handle *server = cls; 1233 struct GNUNET_SERVER_Handle *server = cls;
1237 struct GNUNET_SERVER_Client *sender = client; 1234 struct GNUNET_SERVER_Client *sender = client;
1238 int ret; 1235 int ret;
1239 1236
1240 LOG (GNUNET_ERROR_TYPE_DEBUG, 1237 LOG(GNUNET_ERROR_TYPE_DEBUG,
1241 "Tokenizer gives server message of type %u and size %u from client\n", 1238 "Tokenizer gives server message of type %u and size %u from client\n",
1242 ntohs (message->type), ntohs (message->size)); 1239 ntohs(message->type), ntohs(message->size));
1243 sender->in_process_client_buffer = GNUNET_YES; 1240 sender->in_process_client_buffer = GNUNET_YES;
1244 ret = GNUNET_SERVER_inject (server, sender, message); 1241 ret = GNUNET_SERVER_inject(server, sender, message);
1245 sender->in_process_client_buffer = GNUNET_NO; 1242 sender->in_process_client_buffer = GNUNET_NO;
1246 if ( (GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now) ) 1243 if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now))
1247 { 1244 {
1248 GNUNET_SERVER_client_disconnect (sender); 1245 GNUNET_SERVER_client_disconnect(sender);
1249 return GNUNET_SYSERR; 1246 return GNUNET_SYSERR;
1250 } 1247 }
1251 return GNUNET_OK; 1248 return GNUNET_OK;
1252} 1249}
1253 1250
@@ -1264,37 +1261,37 @@ client_message_tokenizer_callback (void *cls,
1264 * @return the client handle 1261 * @return the client handle
1265 */ 1262 */
1266struct GNUNET_SERVER_Client * 1263struct GNUNET_SERVER_Client *
1267GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, 1264GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server,
1268 struct GNUNET_CONNECTION_Handle *connection) 1265 struct GNUNET_CONNECTION_Handle *connection)
1269{ 1266{
1270 struct GNUNET_SERVER_Client *client; 1267 struct GNUNET_SERVER_Client *client;
1271 struct NotifyList *n; 1268 struct NotifyList *n;
1272 1269
1273 client = GNUNET_new (struct GNUNET_SERVER_Client); 1270 client = GNUNET_new(struct GNUNET_SERVER_Client);
1274 client->connection = connection; 1271 client->connection = connection;
1275 client->server = server; 1272 client->server = server;
1276 client->last_activity = GNUNET_TIME_absolute_get (); 1273 client->last_activity = GNUNET_TIME_absolute_get();
1277 client->idle_timeout = server->idle_timeout; 1274 client->idle_timeout = server->idle_timeout;
1278 GNUNET_CONTAINER_DLL_insert (server->clients_head, 1275 GNUNET_CONTAINER_DLL_insert(server->clients_head,
1279 server->clients_tail, 1276 server->clients_tail,
1280 client); 1277 client);
1281 if (NULL != server->mst_create) 1278 if (NULL != server->mst_create)
1282 client->mst = 1279 client->mst =
1283 server->mst_create (server->mst_cls, client); 1280 server->mst_create(server->mst_cls, client);
1284 else 1281 else
1285 client->mst = 1282 client->mst =
1286 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, 1283 GNUNET_SERVER_mst_create(&client_message_tokenizer_callback,
1287 server); 1284 server);
1288 GNUNET_assert (NULL != client->mst); 1285 GNUNET_assert(NULL != client->mst);
1289 for (n = server->connect_notify_list_head; NULL != n; n = n->next) 1286 for (n = server->connect_notify_list_head; NULL != n; n = n->next)
1290 n->callback (n->callback_cls, client); 1287 n->callback(n->callback_cls, client);
1291 client->receive_pending = GNUNET_YES; 1288 client->receive_pending = GNUNET_YES;
1292 if (GNUNET_SYSERR == 1289 if (GNUNET_SYSERR ==
1293 GNUNET_CONNECTION_receive (client->connection, 1290 GNUNET_CONNECTION_receive(client->connection,
1294 GNUNET_MAX_MESSAGE_SIZE - 1, 1291 GNUNET_MAX_MESSAGE_SIZE - 1,
1295 client->idle_timeout, 1292 client->idle_timeout,
1296 &process_incoming, 1293 &process_incoming,
1297 client)) 1294 client))
1298 return NULL; 1295 return NULL;
1299 return client; 1296 return client;
1300} 1297}
@@ -1309,8 +1306,8 @@ GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
1309 * @param timeout new timeout for activities on the socket 1306 * @param timeout new timeout for activities on the socket
1310 */ 1307 */
1311void 1308void
1312GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, 1309GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client,
1313 struct GNUNET_TIME_Relative timeout) 1310 struct GNUNET_TIME_Relative timeout)
1314{ 1311{
1315 client->idle_timeout = timeout; 1312 client->idle_timeout = timeout;
1316} 1313}
@@ -1324,7 +1321,7 @@ GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
1324 * @param client the client to keep 1321 * @param client the client to keep
1325 */ 1322 */
1326void 1323void
1327GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client) 1324GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client)
1328{ 1325{
1329 client->reference_count++; 1326 client->reference_count++;
1330} 1327}
@@ -1339,12 +1336,12 @@ GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client)
1339 * @param client the client to drop 1336 * @param client the client to drop
1340 */ 1337 */
1341void 1338void
1342GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client) 1339GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client)
1343{ 1340{
1344 GNUNET_assert (client->reference_count > 0); 1341 GNUNET_assert(client->reference_count > 0);
1345 client->reference_count--; 1342 client->reference_count--;
1346 if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count)) 1343 if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count))
1347 GNUNET_SERVER_client_disconnect (client); 1344 GNUNET_SERVER_client_disconnect(client);
1348} 1345}
1349 1346
1350 1347
@@ -1357,10 +1354,10 @@ GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
1357 * @return #GNUNET_OK on success 1354 * @return #GNUNET_OK on success
1358 */ 1355 */
1359int 1356int
1360GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, 1357GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client,
1361 void **addr, size_t * addrlen) 1358 void **addr, size_t * addrlen)
1362{ 1359{
1363 return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen); 1360 return GNUNET_CONNECTION_get_address(client->connection, addr, addrlen);
1364} 1361}
1365 1362
1366 1363
@@ -1375,18 +1372,18 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1375 * @param callback_cls closure for @a callback 1372 * @param callback_cls closure for @a callback
1376 */ 1373 */
1377void 1374void
1378GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, 1375GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server,
1379 GNUNET_SERVER_DisconnectCallback callback, 1376 GNUNET_SERVER_DisconnectCallback callback,
1380 void *callback_cls) 1377 void *callback_cls)
1381{ 1378{
1382 struct NotifyList *n; 1379 struct NotifyList *n;
1383 1380
1384 n = GNUNET_new (struct NotifyList); 1381 n = GNUNET_new(struct NotifyList);
1385 n->callback = callback; 1382 n->callback = callback;
1386 n->callback_cls = callback_cls; 1383 n->callback_cls = callback_cls;
1387 GNUNET_CONTAINER_DLL_insert (server->disconnect_notify_list_head, 1384 GNUNET_CONTAINER_DLL_insert(server->disconnect_notify_list_head,
1388 server->disconnect_notify_list_tail, 1385 server->disconnect_notify_list_tail,
1389 n); 1386 n);
1390} 1387}
1391 1388
1392 1389
@@ -1404,21 +1401,21 @@ GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
1404 * @param callback_cls closure for @a callback 1401 * @param callback_cls closure for @a callback
1405 */ 1402 */
1406void 1403void
1407GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server, 1404GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server,
1408 GNUNET_SERVER_ConnectCallback callback, 1405 GNUNET_SERVER_ConnectCallback callback,
1409 void *callback_cls) 1406 void *callback_cls)
1410{ 1407{
1411 struct NotifyList *n; 1408 struct NotifyList *n;
1412 struct GNUNET_SERVER_Client *client; 1409 struct GNUNET_SERVER_Client *client;
1413 1410
1414 n = GNUNET_new (struct NotifyList); 1411 n = GNUNET_new(struct NotifyList);
1415 n->callback = callback; 1412 n->callback = callback;
1416 n->callback_cls = callback_cls; 1413 n->callback_cls = callback_cls;
1417 GNUNET_CONTAINER_DLL_insert (server->connect_notify_list_head, 1414 GNUNET_CONTAINER_DLL_insert(server->connect_notify_list_head,
1418 server->connect_notify_list_tail, 1415 server->connect_notify_list_tail,
1419 n); 1416 n);
1420 for (client = server->clients_head; NULL != client; client = client->next) 1417 for (client = server->clients_head; NULL != client; client = client->next)
1421 callback (callback_cls, client); 1418 callback(callback_cls, client);
1422} 1419}
1423 1420
1424 1421
@@ -1430,9 +1427,9 @@ GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
1430 * @param callback_cls closure for @a callback 1427 * @param callback_cls closure for @a callback
1431 */ 1428 */
1432void 1429void
1433GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, 1430GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1434 GNUNET_SERVER_DisconnectCallback callback, 1431 GNUNET_SERVER_DisconnectCallback callback,
1435 void *callback_cls) 1432 void *callback_cls)
1436{ 1433{
1437 struct NotifyList *pos; 1434 struct NotifyList *pos;
1438 1435
@@ -1440,14 +1437,14 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1440 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1437 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1441 break; 1438 break;
1442 if (NULL == pos) 1439 if (NULL == pos)
1443 { 1440 {
1444 GNUNET_break (0); 1441 GNUNET_break(0);
1445 return; 1442 return;
1446 } 1443 }
1447 GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head, 1444 GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head,
1448 server->disconnect_notify_list_tail, 1445 server->disconnect_notify_list_tail,
1449 pos); 1446 pos);
1450 GNUNET_free (pos); 1447 GNUNET_free(pos);
1451} 1448}
1452 1449
1453 1450
@@ -1459,9 +1456,9 @@ GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1459 * @param callback_cls closure for @a callback 1456 * @param callback_cls closure for @a callback
1460 */ 1457 */
1461void 1458void
1462GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server, 1459GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1463 GNUNET_SERVER_ConnectCallback callback, 1460 GNUNET_SERVER_ConnectCallback callback,
1464 void *callback_cls) 1461 void *callback_cls)
1465{ 1462{
1466 struct NotifyList *pos; 1463 struct NotifyList *pos;
1467 1464
@@ -1469,14 +1466,14 @@ GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1469 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1466 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1470 break; 1467 break;
1471 if (NULL == pos) 1468 if (NULL == pos)
1472 { 1469 {
1473 GNUNET_break (0); 1470 GNUNET_break(0);
1474 return; 1471 return;
1475 } 1472 }
1476 GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head, 1473 GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head,
1477 server->connect_notify_list_tail, 1474 server->connect_notify_list_tail,
1478 pos); 1475 pos);
1479 GNUNET_free (pos); 1476 GNUNET_free(pos);
1480} 1477}
1481 1478
1482 1479
@@ -1489,86 +1486,86 @@ GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1489 * @param client the client to disconnect from 1486 * @param client the client to disconnect from
1490 */ 1487 */
1491void 1488void
1492GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client) 1489GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
1493{ 1490{
1494 struct GNUNET_SERVER_Handle *server = client->server; 1491 struct GNUNET_SERVER_Handle *server = client->server;
1495 struct NotifyList *n; 1492 struct NotifyList *n;
1496 1493
1497 LOG (GNUNET_ERROR_TYPE_DEBUG, 1494 LOG(GNUNET_ERROR_TYPE_DEBUG,
1498 "Client is being disconnected from the server.\n"); 1495 "Client is being disconnected from the server.\n");
1499 if (NULL != client->restart_task) 1496 if (NULL != client->restart_task)
1500 { 1497 {
1501 GNUNET_SCHEDULER_cancel (client->restart_task); 1498 GNUNET_SCHEDULER_cancel(client->restart_task);
1502 client->restart_task = NULL; 1499 client->restart_task = NULL;
1503 } 1500 }
1504 if (NULL != client->warn_task) 1501 if (NULL != client->warn_task)
1505 { 1502 {
1506 GNUNET_SCHEDULER_cancel (client->warn_task); 1503 GNUNET_SCHEDULER_cancel(client->warn_task);
1507 client->warn_task = NULL; 1504 client->warn_task = NULL;
1508 } 1505 }
1509 if (GNUNET_YES == client->receive_pending) 1506 if (GNUNET_YES == client->receive_pending)
1510 { 1507 {
1511 GNUNET_CONNECTION_receive_cancel (client->connection); 1508 GNUNET_CONNECTION_receive_cancel(client->connection);
1512 client->receive_pending = GNUNET_NO; 1509 client->receive_pending = GNUNET_NO;
1513 } 1510 }
1514 client->shutdown_now = GNUNET_YES; 1511 client->shutdown_now = GNUNET_YES;
1515 client->reference_count++; /* make sure nobody else clean up client... */ 1512 client->reference_count++; /* make sure nobody else clean up client... */
1516 if ( (NULL != client->mst) && 1513 if ((NULL != client->mst) &&
1517 (NULL != server) ) 1514 (NULL != server))
1518 { 1515 {
1519 GNUNET_CONTAINER_DLL_remove (server->clients_head, 1516 GNUNET_CONTAINER_DLL_remove(server->clients_head,
1520 server->clients_tail, 1517 server->clients_tail,
1521 client); 1518 client);
1522 if (NULL != server->mst_destroy) 1519 if (NULL != server->mst_destroy)
1523 server->mst_destroy (server->mst_cls, 1520 server->mst_destroy(server->mst_cls,
1524 client->mst); 1521 client->mst);
1525 else 1522 else
1526 GNUNET_SERVER_mst_destroy (client->mst); 1523 GNUNET_SERVER_mst_destroy(client->mst);
1527 client->mst = NULL; 1524 client->mst = NULL;
1528 for (n = server->disconnect_notify_list_head; NULL != n; n = n->next) 1525 for (n = server->disconnect_notify_list_head; NULL != n; n = n->next)
1529 n->callback (n->callback_cls, 1526 n->callback(n->callback_cls,
1530 client); 1527 client);
1531 } 1528 }
1532 client->reference_count--; 1529 client->reference_count--;
1533 if (client->reference_count > 0) 1530 if (client->reference_count > 0)
1534 { 1531 {
1535 LOG (GNUNET_ERROR_TYPE_DEBUG, 1532 LOG(GNUNET_ERROR_TYPE_DEBUG,
1536 "RC of %p still positive, not destroying everything.\n", 1533 "RC of %p still positive, not destroying everything.\n",
1537 client); 1534 client);
1538 client->server = NULL; 1535 client->server = NULL;
1539 return; 1536 return;
1540 } 1537 }
1541 if (GNUNET_YES == client->in_process_client_buffer) 1538 if (GNUNET_YES == client->in_process_client_buffer)
1542 { 1539 {
1543 LOG (GNUNET_ERROR_TYPE_DEBUG, 1540 LOG(GNUNET_ERROR_TYPE_DEBUG,
1544 "Still processing inputs of %p, not destroying everything.\n", 1541 "Still processing inputs of %p, not destroying everything.\n",
1545 client); 1542 client);
1546 return; 1543 return;
1547 } 1544 }
1548 LOG (GNUNET_ERROR_TYPE_DEBUG, 1545 LOG(GNUNET_ERROR_TYPE_DEBUG,
1549 "RC of %p now zero, destroying everything.\n", 1546 "RC of %p now zero, destroying everything.\n",
1550 client); 1547 client);
1551 if (GNUNET_YES == client->persist) 1548 if (GNUNET_YES == client->persist)
1552 GNUNET_CONNECTION_persist_ (client->connection); 1549 GNUNET_CONNECTION_persist_(client->connection);
1553 if (NULL != client->th.cth) 1550 if (NULL != client->th.cth)
1554 GNUNET_SERVER_notify_transmit_ready_cancel (&client->th); 1551 GNUNET_SERVER_notify_transmit_ready_cancel(&client->th);
1555 GNUNET_CONNECTION_destroy (client->connection); 1552 GNUNET_CONNECTION_destroy(client->connection);
1556 /* need to cancel again, as it might have been re-added 1553 /* need to cancel again, as it might have been re-added
1557 in the meantime (i.e. during callbacks) */ 1554 in the meantime (i.e. during callbacks) */
1558 if (NULL != client->warn_task) 1555 if (NULL != client->warn_task)
1559 { 1556 {
1560 GNUNET_SCHEDULER_cancel (client->warn_task); 1557 GNUNET_SCHEDULER_cancel(client->warn_task);
1561 client->warn_task = NULL; 1558 client->warn_task = NULL;
1562 } 1559 }
1563 if (GNUNET_YES == client->receive_pending) 1560 if (GNUNET_YES == client->receive_pending)
1564 { 1561 {
1565 GNUNET_CONNECTION_receive_cancel (client->connection); 1562 GNUNET_CONNECTION_receive_cancel(client->connection);
1566 client->receive_pending = GNUNET_NO; 1563 client->receive_pending = GNUNET_NO;
1567 } 1564 }
1568 GNUNET_free (client); 1565 GNUNET_free(client);
1569 /* we might be in soft-shutdown, test if we're done */ 1566 /* we might be in soft-shutdown, test if we're done */
1570 if (NULL != server) 1567 if (NULL != server)
1571 test_monitor_clients (server); 1568 test_monitor_clients(server);
1572} 1569}
1573 1570
1574 1571
@@ -1581,9 +1578,9 @@ GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1581 * @return #GNUNET_OK on success 1578 * @return #GNUNET_OK on success
1582 */ 1579 */
1583int 1580int
1584GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client) 1581GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client)
1585{ 1582{
1586 return GNUNET_CONNECTION_disable_corking (client->connection); 1583 return GNUNET_CONNECTION_disable_corking(client->connection);
1587} 1584}
1588 1585
1589 1586
@@ -1597,7 +1594,7 @@ GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client)
1597 * @return number of bytes actually transmitted 1594 * @return number of bytes actually transmitted
1598 */ 1595 */
1599static size_t 1596static size_t
1600transmit_ready_callback_wrapper (void *cls, size_t size, void *buf) 1597transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
1601{ 1598{
1602 struct GNUNET_SERVER_Client *client = cls; 1599 struct GNUNET_SERVER_Client *client = cls;
1603 GNUNET_CONNECTION_TransmitReadyNotify callback; 1600 GNUNET_CONNECTION_TransmitReadyNotify callback;
@@ -1605,8 +1602,8 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
1605 client->th.cth = NULL; 1602 client->th.cth = NULL;
1606 callback = client->th.callback; 1603 callback = client->th.callback;
1607 client->th.callback = NULL; 1604 client->th.callback = NULL;
1608 client->last_activity = GNUNET_TIME_absolute_get (); 1605 client->last_activity = GNUNET_TIME_absolute_get();
1609 return callback (client->th.callback_cls, size, buf); 1606 return callback(client->th.callback_cls, size, buf);
1610} 1607}
1611 1608
1612 1609
@@ -1626,20 +1623,20 @@ transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
1626 * NULL if we are already going to notify someone else (busy) 1623 * NULL if we are already going to notify someone else (busy)
1627 */ 1624 */
1628struct GNUNET_SERVER_TransmitHandle * 1625struct GNUNET_SERVER_TransmitHandle *
1629GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, 1626GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client,
1630 size_t size, 1627 size_t size,
1631 struct GNUNET_TIME_Relative timeout, 1628 struct GNUNET_TIME_Relative timeout,
1632 GNUNET_CONNECTION_TransmitReadyNotify callback, 1629 GNUNET_CONNECTION_TransmitReadyNotify callback,
1633 void *callback_cls) 1630 void *callback_cls)
1634{ 1631{
1635 if (NULL != client->th.callback) 1632 if (NULL != client->th.callback)
1636 return NULL; 1633 return NULL;
1637 client->th.callback_cls = callback_cls; 1634 client->th.callback_cls = callback_cls;
1638 client->th.callback = callback; 1635 client->th.callback = callback;
1639 client->th.cth = GNUNET_CONNECTION_notify_transmit_ready (client->connection, size, 1636 client->th.cth = GNUNET_CONNECTION_notify_transmit_ready(client->connection, size,
1640 timeout, 1637 timeout,
1641 &transmit_ready_callback_wrapper, 1638 &transmit_ready_callback_wrapper,
1642 client); 1639 client);
1643 return &client->th; 1640 return &client->th;
1644} 1641}
1645 1642
@@ -1650,9 +1647,9 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
1650 * @param th request to abort 1647 * @param th request to abort
1651 */ 1648 */
1652void 1649void
1653GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th) 1650GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th)
1654{ 1651{
1655 GNUNET_CONNECTION_notify_transmit_ready_cancel (th->cth); 1652 GNUNET_CONNECTION_notify_transmit_ready_cancel(th->cth);
1656 th->cth = NULL; 1653 th->cth = NULL;
1657 th->callback = NULL; 1654 th->callback = NULL;
1658} 1655}
@@ -1665,7 +1662,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle
1665 * @param client the client to set the persistent flag on 1662 * @param client the client to set the persistent flag on
1666 */ 1663 */
1667void 1664void
1668GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client) 1665GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client)
1669{ 1666{
1670 client->persist = GNUNET_YES; 1667 client->persist = GNUNET_YES;
1671} 1668}
@@ -1684,50 +1681,50 @@ GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client)
1684 * serious error) 1681 * serious error)
1685 */ 1682 */
1686void 1683void
1687GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, 1684GNUNET_SERVER_receive_done(struct GNUNET_SERVER_Client *client,
1688 int success) 1685 int success)
1689{ 1686{
1690 if (NULL == client) 1687 if (NULL == client)
1691 return; 1688 return;
1692 GNUNET_assert (client->suspended > 0); 1689 GNUNET_assert(client->suspended > 0);
1693 client->suspended--; 1690 client->suspended--;
1694 if (GNUNET_OK != success) 1691 if (GNUNET_OK != success)
1695 { 1692 {
1696 LOG (GNUNET_ERROR_TYPE_DEBUG, 1693 LOG(GNUNET_ERROR_TYPE_DEBUG,
1697 "GNUNET_SERVER_receive_done called with failure indication\n"); 1694 "GNUNET_SERVER_receive_done called with failure indication\n");
1698 if ( (client->reference_count > 0) || (client->suspended > 0) ) 1695 if ((client->reference_count > 0) || (client->suspended > 0))
1699 client->shutdown_now = GNUNET_YES; 1696 client->shutdown_now = GNUNET_YES;
1700 else 1697 else
1701 GNUNET_SERVER_client_disconnect (client); 1698 GNUNET_SERVER_client_disconnect(client);
1702 return; 1699 return;
1703 } 1700 }
1704 if (client->suspended > 0) 1701 if (client->suspended > 0)
1705 { 1702 {
1706 LOG (GNUNET_ERROR_TYPE_DEBUG, 1703 LOG(GNUNET_ERROR_TYPE_DEBUG,
1707 "GNUNET_SERVER_receive_done called, but more clients pending\n"); 1704 "GNUNET_SERVER_receive_done called, but more clients pending\n");
1708 return; 1705 return;
1709 } 1706 }
1710 if (NULL != client->warn_task) 1707 if (NULL != client->warn_task)
1711 { 1708 {
1712 GNUNET_SCHEDULER_cancel (client->warn_task); 1709 GNUNET_SCHEDULER_cancel(client->warn_task);
1713 client->warn_task = NULL; 1710 client->warn_task = NULL;
1714 } 1711 }
1715 if (GNUNET_YES == client->in_process_client_buffer) 1712 if (GNUNET_YES == client->in_process_client_buffer)
1716 { 1713 {
1717 LOG (GNUNET_ERROR_TYPE_DEBUG, 1714 LOG(GNUNET_ERROR_TYPE_DEBUG,
1718 "GNUNET_SERVER_receive_done called while still in processing loop\n"); 1715 "GNUNET_SERVER_receive_done called while still in processing loop\n");
1719 return; 1716 return;
1720 } 1717 }
1721 if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now)) 1718 if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now))
1722 { 1719 {
1723 GNUNET_SERVER_client_disconnect (client); 1720 GNUNET_SERVER_client_disconnect(client);
1724 return; 1721 return;
1725 } 1722 }
1726 LOG (GNUNET_ERROR_TYPE_DEBUG, 1723 LOG(GNUNET_ERROR_TYPE_DEBUG,
1727 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); 1724 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1728 GNUNET_assert (NULL == client->restart_task); 1725 GNUNET_assert(NULL == client->restart_task);
1729 client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing, 1726 client->restart_task = GNUNET_SCHEDULER_add_now(&restart_processing,
1730 client); 1727 client);
1731} 1728}
1732 1729
1733 1730
diff --git a/src/transport/tcp_server_mst_legacy.c b/src/transport/tcp_server_mst_legacy.c
index 868f64d7c..03c02ff75 100644
--- a/src/transport/tcp_server_mst_legacy.c
+++ b/src/transport/tcp_server_mst_legacy.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/server_mst.c 22 * @file util/server_mst.c
@@ -38,9 +38,7 @@
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{
43
44 /** 42 /**
45 * Function to call on completed messages. 43 * Function to call on completed messages.
46 */ 44 */
@@ -70,7 +68,6 @@ struct GNUNET_SERVER_MessageStreamTokenizer
70 * Beginning of the buffer. Typed like this to force alignment. 68 * Beginning of the buffer. Typed like this to force alignment.
71 */ 69 */
72 struct GNUNET_MessageHeader *hdr; 70 struct GNUNET_MessageHeader *hdr;
73
74}; 71};
75 72
76 73
@@ -83,13 +80,13 @@ struct GNUNET_SERVER_MessageStreamTokenizer
83 * @return handle to tokenizer 80 * @return handle to tokenizer
84 */ 81 */
85struct GNUNET_SERVER_MessageStreamTokenizer * 82struct GNUNET_SERVER_MessageStreamTokenizer *
86GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, 83GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb,
87 void *cb_cls) 84 void *cb_cls)
88{ 85{
89 struct GNUNET_SERVER_MessageStreamTokenizer *ret; 86 struct GNUNET_SERVER_MessageStreamTokenizer *ret;
90 87
91 ret = GNUNET_new (struct GNUNET_SERVER_MessageStreamTokenizer); 88 ret = GNUNET_new(struct GNUNET_SERVER_MessageStreamTokenizer);
92 ret->hdr = GNUNET_malloc (GNUNET_MIN_MESSAGE_SIZE); 89 ret->hdr = GNUNET_malloc(GNUNET_MIN_MESSAGE_SIZE);
93 ret->curr_buf = GNUNET_MIN_MESSAGE_SIZE; 90 ret->curr_buf = GNUNET_MIN_MESSAGE_SIZE;
94 ret->cb = cb; 91 ret->cb = cb;
95 ret->cb_cls = cb_cls; 92 ret->cb_cls = cb_cls;
@@ -113,10 +110,10 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
113 * #GNUNET_SYSERR if the data stream is corrupt 110 * #GNUNET_SYSERR if the data stream is corrupt
114 */ 111 */
115int 112int
116GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, 113GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst,
117 void *client_identity, 114 void *client_identity,
118 const char *buf, size_t size, 115 const char *buf, size_t size,
119 int purge, int one_shot) 116 int purge, int one_shot)
120{ 117{
121 const struct GNUNET_MessageHeader *hdr; 118 const struct GNUNET_MessageHeader *hdr;
122 size_t delta; 119 size_t delta;
@@ -126,170 +123,170 @@ GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
126 unsigned long offset; 123 unsigned long offset;
127 int ret; 124 int ret;
128 125
129 GNUNET_assert (mst->off <= mst->pos); 126 GNUNET_assert(mst->off <= mst->pos);
130 GNUNET_assert (mst->pos <= mst->curr_buf); 127 GNUNET_assert(mst->pos <= mst->curr_buf);
131 LOG (GNUNET_ERROR_TYPE_DEBUG, 128 LOG(GNUNET_ERROR_TYPE_DEBUG,
132 "Server-mst receives %u bytes with %u bytes already in private buffer\n", 129 "Server-mst receives %u bytes with %u bytes already in private buffer\n",
133 (unsigned int) size, (unsigned int) (mst->pos - mst->off)); 130 (unsigned int)size, (unsigned int)(mst->pos - mst->off));
134 ret = GNUNET_OK; 131 ret = GNUNET_OK;
135 ibuf = (char *) mst->hdr; 132 ibuf = (char *)mst->hdr;
136 while (mst->pos > 0) 133 while (mst->pos > 0)
137 {
138do_align:
139 GNUNET_assert (mst->pos >= mst->off);
140 if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
141 (0 != (mst->off % ALIGN_FACTOR)))
142 {
143 /* need to align or need more space */
144 mst->pos -= mst->off;
145 memmove (ibuf, &ibuf[mst->off], mst->pos);
146 mst->off = 0;
147 }
148 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
149 {
150 delta =
151 GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
152 (mst->pos - mst->off), size);
153 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
154 mst->pos += delta;
155 buf += delta;
156 size -= delta;
157 }
158 if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
159 {
160 if (purge)
161 {
162 mst->off = 0;
163 mst->pos = 0;
164 }
165 return GNUNET_OK;
166 }
167 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
168 want = ntohs (hdr->size);
169 if (want < sizeof (struct GNUNET_MessageHeader))
170 {
171 GNUNET_break_op (0);
172 return GNUNET_SYSERR;
173 }
174 if ( (mst->curr_buf - mst->off < want) &&
175 (mst->off > 0) )
176 {
177 /* can get more space by moving */
178 mst->pos -= mst->off;
179 memmove (ibuf, &ibuf[mst->off], mst->pos);
180 mst->off = 0;
181 }
182 if (mst->curr_buf < want)
183 {
184 /* need to get more space by growing buffer */
185 GNUNET_assert (0 == mst->off);
186 mst->hdr = GNUNET_realloc (mst->hdr, want);
187 ibuf = (char *) mst->hdr;
188 mst->curr_buf = want;
189 }
190 hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
191 if (mst->pos - mst->off < want)
192 {
193 delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
194 GNUNET_assert (mst->pos + delta <= mst->curr_buf);
195 GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
196 mst->pos += delta;
197 buf += delta;
198 size -= delta;
199 }
200 if (mst->pos - mst->off < want)
201 {
202 if (purge)
203 {
204 mst->off = 0;
205 mst->pos = 0;
206 }
207 return GNUNET_OK;
208 }
209 if (one_shot == GNUNET_SYSERR)
210 { 134 {
211 /* cannot call callback again, but return value saying that 135do_align:
212 * we have another full message in the buffer */ 136 GNUNET_assert(mst->pos >= mst->off);
213 ret = GNUNET_NO; 137 if ((mst->curr_buf - mst->off < sizeof(struct GNUNET_MessageHeader)) ||
214 goto copy; 138 (0 != (mst->off % ALIGN_FACTOR)))
215 } 139 {
216 if (one_shot == GNUNET_YES) 140 /* need to align or need more space */
217 one_shot = GNUNET_SYSERR; 141 mst->pos -= mst->off;
218 mst->off += want; 142 memmove(ibuf, &ibuf[mst->off], mst->pos);
219 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) 143 mst->off = 0;
220 return GNUNET_SYSERR; 144 }
221 if (mst->off == mst->pos) 145 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
222 { 146 {
223 /* reset to beginning of buffer, it's free right now! */ 147 delta =
224 mst->off = 0; 148 GNUNET_MIN(sizeof(struct GNUNET_MessageHeader) -
225 mst->pos = 0; 149 (mst->pos - mst->off), size);
226 } 150 GNUNET_memcpy(&ibuf[mst->pos], buf, delta);
227 } 151 mst->pos += delta;
228 GNUNET_assert (0 == mst->pos); 152 buf += delta;
229 while (size > 0) 153 size -= delta;
230 { 154 }
231 LOG (GNUNET_ERROR_TYPE_DEBUG, 155 if (mst->pos - mst->off < sizeof(struct GNUNET_MessageHeader))
232 "Server-mst has %u bytes left in inbound buffer\n", 156 {
233 (unsigned int) size); 157 if (purge)
234 if (size < sizeof (struct GNUNET_MessageHeader)) 158 {
235 break; 159 mst->off = 0;
236 offset = (unsigned long) buf; 160 mst->pos = 0;
237 need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; 161 }
238 if (GNUNET_NO == need_align) 162 return GNUNET_OK;
239 { 163 }
240 /* can try to do zero-copy and process directly from original buffer */ 164 hdr = (const struct GNUNET_MessageHeader *)&ibuf[mst->off];
241 hdr = (const struct GNUNET_MessageHeader *) buf; 165 want = ntohs(hdr->size);
242 want = ntohs (hdr->size); 166 if (want < sizeof(struct GNUNET_MessageHeader))
243 if (want < sizeof (struct GNUNET_MessageHeader)) 167 {
244 { 168 GNUNET_break_op(0);
245 GNUNET_break_op (0); 169 return GNUNET_SYSERR;
246 mst->off = 0; 170 }
247 return GNUNET_SYSERR; 171 if ((mst->curr_buf - mst->off < want) &&
248 } 172 (mst->off > 0))
249 if (size < want) 173 {
250 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 }
251 if (one_shot == GNUNET_SYSERR) 206 if (one_shot == GNUNET_SYSERR)
252 { 207 {
253 /* cannot call callback again, but return value saying that 208 /* cannot call callback again, but return value saying that
254 * we have another full message in the buffer */ 209 * we have another full message in the buffer */
255 ret = GNUNET_NO; 210 ret = GNUNET_NO;
256 goto copy; 211 goto copy;
257 } 212 }
258 if (one_shot == GNUNET_YES) 213 if (one_shot == GNUNET_YES)
259 one_shot = GNUNET_SYSERR; 214 one_shot = GNUNET_SYSERR;
260 if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) 215 mst->off += want;
216 if (GNUNET_SYSERR == mst->cb(mst->cb_cls, client_identity, hdr))
261 return GNUNET_SYSERR; 217 return GNUNET_SYSERR;
262 buf += want; 218 if (mst->off == mst->pos)
263 size -= want; 219 {
220 /* reset to beginning of buffer, it's free right now! */
221 mst->off = 0;
222 mst->pos = 0;
223 }
264 } 224 }
265 else 225 GNUNET_assert(0 == mst->pos);
226 while (size > 0)
266 { 227 {
267 /* need to copy to private buffer to align; 228 LOG(GNUNET_ERROR_TYPE_DEBUG,
268 * yes, we go a bit more spagetti than usual here */ 229 "Server-mst has %u bytes left in inbound buffer\n",
269 goto do_align; 230 (unsigned int)size);
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 }
270 } 268 }
271 }
272copy: 269copy:
273 if ((size > 0) && (!purge)) 270 if ((size > 0) && (!purge))
274 {
275 if (size + mst->pos > mst->curr_buf)
276 { 271 {
277 mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); 272 if (size + mst->pos > mst->curr_buf)
278 ibuf = (char *) mst->hdr; 273 {
279 mst->curr_buf = size + mst->pos; 274 mst->hdr = GNUNET_realloc(mst->hdr, 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;
280 } 281 }
281 GNUNET_assert (size + mst->pos <= mst->curr_buf);
282 GNUNET_memcpy (&ibuf[mst->pos], buf, size);
283 mst->pos += size;
284 }
285 if (purge) 282 if (purge)
286 { 283 {
287 mst->off = 0; 284 mst->off = 0;
288 mst->pos = 0; 285 mst->pos = 0;
289 } 286 }
290 LOG (GNUNET_ERROR_TYPE_DEBUG, 287 LOG(GNUNET_ERROR_TYPE_DEBUG,
291 "Server-mst leaves %u bytes in private buffer\n", 288 "Server-mst leaves %u bytes in private buffer\n",
292 (unsigned int) (mst->pos - mst->off)); 289 (unsigned int)(mst->pos - mst->off));
293 return ret; 290 return ret;
294} 291}
295 292
@@ -300,10 +297,10 @@ copy:
300 * @param mst tokenizer to destroy 297 * @param mst tokenizer to destroy
301 */ 298 */
302void 299void
303GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst) 300GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst)
304{ 301{
305 GNUNET_free (mst->hdr); 302 GNUNET_free(mst->hdr);
306 GNUNET_free (mst); 303 GNUNET_free(mst);
307} 304}
308 305
309 306
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c
index e59fa4a1c..3bb08c0e8 100644
--- a/src/transport/tcp_service_legacy.c
+++ b/src/transport/tcp_service_legacy.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file util/service.c 22 * @file util/service.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,8 +105,7 @@ NEXT:
105/** 105/**
106 * Context for "service_task". 106 * Context for "service_task".
107 */ 107 */
108struct LEGACY_SERVICE_Context 108struct LEGACY_SERVICE_Context {
109{
110 /** 109 /**
111 * Our configuration. 110 * Our configuration.
112 */ 111 */
@@ -238,21 +237,21 @@ struct LEGACY_SERVICE_Context
238 * @return number of bytes written to 'buf' 237 * @return number of bytes written to 'buf'
239 */ 238 */
240static size_t 239static size_t
241write_test (void *cls, size_t size, void *buf) 240write_test(void *cls, size_t size, void *buf)
242{ 241{
243 struct GNUNET_SERVER_Client *client = cls; 242 struct GNUNET_SERVER_Client *client = cls;
244 struct GNUNET_MessageHeader *msg; 243 struct GNUNET_MessageHeader *msg;
245 244
246 if (size < sizeof (struct GNUNET_MessageHeader)) 245 if (size < sizeof(struct GNUNET_MessageHeader))
247 { 246 {
248 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 247 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
249 return 0; /* client disconnected */ 248 return 0; /* client disconnected */
250 } 249 }
251 msg = (struct GNUNET_MessageHeader *) buf; 250 msg = (struct GNUNET_MessageHeader *)buf;
252 msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); 251 msg->type = htons(GNUNET_MESSAGE_TYPE_TEST);
253 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 252 msg->size = htons(sizeof(struct GNUNET_MessageHeader));
254 GNUNET_SERVER_receive_done (client, GNUNET_OK); 253 GNUNET_SERVER_receive_done(client, GNUNET_OK);
255 return sizeof (struct GNUNET_MessageHeader); 254 return sizeof(struct GNUNET_MessageHeader);
256} 255}
257 256
258 257
@@ -264,18 +263,18 @@ write_test (void *cls, size_t size, void *buf)
264 * @param message the actual message 263 * @param message the actual message
265 */ 264 */
266static void 265static void
267handle_test (void *cls, 266handle_test(void *cls,
268 struct GNUNET_SERVER_Client *client, 267 struct GNUNET_SERVER_Client *client,
269 const struct GNUNET_MessageHeader *message) 268 const struct GNUNET_MessageHeader *message)
270{ 269{
271 /* simply bounce message back to acknowledge */ 270 /* simply bounce message back to acknowledge */
272 if (NULL == 271 if (NULL ==
273 GNUNET_SERVER_notify_transmit_ready (client, 272 GNUNET_SERVER_notify_transmit_ready(client,
274 sizeof (struct GNUNET_MessageHeader), 273 sizeof(struct GNUNET_MessageHeader),
275 GNUNET_TIME_UNIT_FOREVER_REL, 274 GNUNET_TIME_UNIT_FOREVER_REL,
276 &write_test, 275 &write_test,
277 client)) 276 client))
278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 277 GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
279} 278}
280 279
281 280
@@ -285,11 +284,11 @@ handle_test (void *cls,
285 * struct. 284 * struct.
286 */ 285 */
287static const struct GNUNET_SERVER_MessageHandler defhandlers[] = 286static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
288 {{&handle_test, 287{ { &handle_test,
289 NULL, 288 NULL,
290 GNUNET_MESSAGE_TYPE_TEST, 289 GNUNET_MESSAGE_TYPE_TEST,
291 sizeof (struct GNUNET_MessageHeader)}, 290 sizeof(struct GNUNET_MessageHeader) },
292 {NULL, NULL, 0, 0}}; 291 { NULL, NULL, 0, 0 } };
293 292
294 293
295/* ****************** service core routines ************** */ 294/* ****************** service core routines ************** */
@@ -306,10 +305,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] =
306 * for unknown address family (will be denied). 305 * for unknown address family (will be denied).
307 */ 306 */
308static int 307static int
309check_access (void *cls, 308check_access(void *cls,
310 const struct GNUNET_CONNECTION_Credentials *uc, 309 const struct GNUNET_CONNECTION_Credentials *uc,
311 const struct sockaddr *addr, 310 const struct sockaddr *addr,
312 socklen_t addrlen) 311 socklen_t addrlen)
313{ 312{
314 struct LEGACY_SERVICE_Context *sctx = cls; 313 struct LEGACY_SERVICE_Context *sctx = cls;
315 const struct sockaddr_in *i4; 314 const struct sockaddr_in *i4;
@@ -317,41 +316,43 @@ check_access (void *cls,
317 int ret; 316 int ret;
318 317
319 switch (addr->sa_family) 318 switch (addr->sa_family)
320 { 319 {
321 case AF_INET: 320 case AF_INET:
322 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 321 GNUNET_assert(addrlen == sizeof(struct sockaddr_in));
323 i4 = (const struct sockaddr_in *) addr; 322 i4 = (const struct sockaddr_in *)addr;
324 ret = ((NULL == sctx->v4_allowed) || 323 ret = ((NULL == sctx->v4_allowed) ||
325 (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && 324 (check_ipv4_listed(sctx->v4_allowed, &i4->sin_addr))) &&
326 ((NULL == sctx->v4_denied) || 325 ((NULL == sctx->v4_denied) ||
327 (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); 326 (!check_ipv4_listed(sctx->v4_denied, &i4->sin_addr)));
328 break; 327 break;
329 case AF_INET6: 328
330 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 329 case AF_INET6:
331 i6 = (const struct sockaddr_in6 *) addr; 330 GNUNET_assert(addrlen == sizeof(struct sockaddr_in6));
332 ret = ((NULL == sctx->v6_allowed) || 331 i6 = (const struct sockaddr_in6 *)addr;
333 (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && 332 ret = ((NULL == sctx->v6_allowed) ||
334 ((NULL == sctx->v6_denied) || 333 (check_ipv6_listed(sctx->v6_allowed, &i6->sin6_addr))) &&
335 (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); 334 ((NULL == sctx->v6_denied) ||
336 break; 335 (!check_ipv6_listed(sctx->v6_denied, &i6->sin6_addr)));
336 break;
337
337#ifndef WINDOWS 338#ifndef WINDOWS
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#endif 342#endif
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 if (GNUNET_SYSERR ==
550 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg,
551 service_name,
552 "DISABLEV6")))
553 return GNUNET_SYSERR;
554 }
555 else
556 disablev6 = GNUNET_NO;
557
558 if (! disablev6)
559 {
560 /* probe IPv6 support */
561 desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0);
562 if (NULL == desc)
563 { 549 {
564 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || 550 if (GNUNET_SYSERR ==
565 (EACCES == errno)) 551 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg,
566 { 552 service_name,
567 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket"); 553 "DISABLEV6")))
568 return GNUNET_SYSERR; 554 return GNUNET_SYSERR;
569 }
570 LOG (GNUNET_ERROR_TYPE_INFO,
571 _ (
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 } 555 }
577 else 556 else
557 disablev6 = GNUNET_NO;
558
559 if (!disablev6)
578 { 560 {
579 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); 561 /* probe IPv6 support */
580 desc = NULL; 562 desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0);
563 if (NULL == desc)
564 {
565 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
566 (EACCES == errno))
567 {
568 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket");
569 return GNUNET_SYSERR;
570 }
571 LOG(GNUNET_ERROR_TYPE_INFO,
572 _(
573 "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
574 service_name,
575 strerror(errno));
576 disablev6 = GNUNET_YES;
577 }
578 else
579 {
580 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
581 desc = NULL;
582 }
581 } 583 }
582 }
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"))
586 {
587 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg,
588 service_name,
589 "PORT",
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 { 587 {
598 LOG (GNUNET_ERROR_TYPE_ERROR, 588 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg,
599 _ ("Require valid port number for service `%s' in configuration!\n"), 589 service_name,
600 service_name); 590 "PORT",
601 return GNUNET_SYSERR; 591 &port))
592 {
593 LOG(GNUNET_ERROR_TYPE_ERROR,
594 _("Require valid port number for service `%s' in configuration!\n"),
595 service_name);
596 }
597 if (port > 65535)
598 {
599 LOG(GNUNET_ERROR_TYPE_ERROR,
600 _("Require valid port number for service `%s' in configuration!\n"),
601 service_name);
602 return GNUNET_SYSERR;
603 }
602 } 604 }
603 }
604 605
605 if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) 606 if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO"))
606 { 607 {
607 GNUNET_break (GNUNET_OK == 608 GNUNET_break(GNUNET_OK ==
608 GNUNET_CONFIGURATION_get_value_string (cfg, 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)))
626 {
627 /* probe UNIX support */
628 struct sockaddr_un s_un;
629
630 if (strlen (unixpath) >= sizeof (s_un.sun_path))
631 { 627 {
632 LOG (GNUNET_ERROR_TYPE_WARNING, 628 /* probe UNIX support */
633 _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), 629 struct sockaddr_un s_un;
634 unixpath, 630
635 (unsigned long long) sizeof (s_un.sun_path)); 631 if (strlen(unixpath) >= sizeof(s_un.sun_path))
636 unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); 632 {
637 LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); 633 LOG(GNUNET_ERROR_TYPE_WARNING,
638 } 634 _("UNIXPATH `%s' too long, maximum length is %llu\n"),
635 unixpath,
636 (unsigned long long)sizeof(s_un.sun_path));
637 unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath);
638 LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath);
639 }
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 if (NULL != unixpath)
651 {
652 desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
653 if (NULL == desc)
654 {
655 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
656 (EACCES == errno))
657 {
658 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
659 GNUNET_free_non_null (hostname);
660 GNUNET_free (unixpath);
661 return GNUNET_SYSERR;
662 }
663 LOG (GNUNET_ERROR_TYPE_INFO,
664 _ (
665 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
666 service_name,
667 strerror (errno));
668 GNUNET_free (unixpath);
669 unixpath = NULL;
670 } 650 }
671 else 651 if (NULL != unixpath)
672 { 652 {
673 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); 653 desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0);
674 desc = NULL; 654 if (NULL == desc)
655 {
656 if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) ||
657 (EACCES == errno))
658 {
659 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket");
660 GNUNET_free_non_null(hostname);
661 GNUNET_free(unixpath);
662 return GNUNET_SYSERR;
663 }
664 LOG(GNUNET_ERROR_TYPE_INFO,
665 _(
666 "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"),
667 service_name,
668 strerror(errno));
669 GNUNET_free(unixpath);
670 unixpath = NULL;
671 }
672 else
673 {
674 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc));
675 desc = NULL;
676 }
675 } 677 }
676 }
677#endif 678#endif
678 679
679 if ((0 == port) && (NULL == unixpath)) 680 if ((0 == port) && (NULL == unixpath))
680 {
681 LOG (GNUNET_ERROR_TYPE_ERROR,
682 _ (
683 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
684 service_name);
685 GNUNET_free_non_null (hostname);
686 return GNUNET_SYSERR;
687 }
688 if (0 == port)
689 {
690 saddrs = GNUNET_malloc (2 * sizeof (struct sockaddr *));
691 saddrlens = GNUNET_malloc (2 * sizeof (socklen_t));
692 add_unixpath (saddrs, saddrlens, unixpath, abstract);
693 GNUNET_free_non_null (unixpath);
694 GNUNET_free_non_null (hostname);
695 *addrs = saddrs;
696 *addr_lens = saddrlens;
697 return 1;
698 }
699
700 if (NULL != hostname)
701 {
702 LOG (GNUNET_ERROR_TYPE_DEBUG,
703 "Resolving `%s' since that is where `%s' will bind to.\n",
704 hostname,
705 service_name);
706 memset (&hints, 0, sizeof (struct addrinfo));
707 if (disablev6)
708 hints.ai_family = AF_INET;
709 hints.ai_protocol = IPPROTO_TCP;
710 if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) ||
711 (NULL == res))
712 { 681 {
713 LOG (GNUNET_ERROR_TYPE_ERROR, 682 LOG(GNUNET_ERROR_TYPE_ERROR,
714 _ ("Failed to resolve `%s': %s\n"), 683 _(
715 hostname, 684 "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"),
716 gai_strerror (ret)); 685 service_name);
717 GNUNET_free (hostname); 686 GNUNET_free_non_null(hostname);
718 GNUNET_free_non_null (unixpath);
719 return GNUNET_SYSERR; 687 return GNUNET_SYSERR;
720 } 688 }
721 next = res; 689 if (0 == port)
722 i = 0;
723 while (NULL != (pos = next))
724 {
725 next = pos->ai_next;
726 if ((disablev6) && (pos->ai_family == AF_INET6))
727 continue;
728 i++;
729 }
730 if (0 == i)
731 {
732 LOG (GNUNET_ERROR_TYPE_ERROR,
733 _ ("Failed to find %saddress for `%s'.\n"),
734 disablev6 ? "IPv4 " : "",
735 hostname);
736 freeaddrinfo (res);
737 GNUNET_free (hostname);
738 GNUNET_free_non_null (unixpath);
739 return GNUNET_SYSERR;
740 }
741 resi = i;
742 if (NULL != unixpath)
743 resi++;
744 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
745 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
746 i = 0;
747 if (NULL != unixpath)
748 {
749 add_unixpath (saddrs, saddrlens, unixpath, abstract);
750 i++;
751 }
752 next = res;
753 while (NULL != (pos = next))
754 { 690 {
755 next = pos->ai_next; 691 saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *));
756 if ((disablev6) && (AF_INET6 == pos->ai_family)) 692 saddrlens = GNUNET_malloc(2 * sizeof(socklen_t));
757 continue; 693 add_unixpath(saddrs, saddrlens, unixpath, abstract);
758 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) 694 GNUNET_free_non_null(unixpath);
759 continue; /* not TCP */ 695 GNUNET_free_non_null(hostname);
760 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) 696 *addrs = saddrs;
761 continue; /* huh? */ 697 *addr_lens = saddrlens;
762 LOG (GNUNET_ERROR_TYPE_DEBUG, 698 return 1;
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 } 699 }
785 GNUNET_free (hostname); 700
786 freeaddrinfo (res); 701 if (NULL != hostname)
787 resi = i;
788 }
789 else
790 {
791 /* will bind against everything, just set port */
792 if (disablev6)
793 { 702 {
794 /* V4-only */ 703 LOG(GNUNET_ERROR_TYPE_DEBUG,
795 resi = 1; 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))
713 {
714 LOG(GNUNET_ERROR_TYPE_ERROR,
715 _("Failed to resolve `%s': %s\n"),
716 hostname,
717 gai_strerror(ret));
718 GNUNET_free(hostname);
719 GNUNET_free_non_null(unixpath);
720 return GNUNET_SYSERR;
721 }
722 next = res;
723 i = 0;
724 while (NULL != (pos = next))
725 {
726 next = pos->ai_next;
727 if ((disablev6) && (pos->ai_family == AF_INET6))
728 continue;
729 i++;
730 }
731 if (0 == i)
732 {
733 LOG(GNUNET_ERROR_TYPE_ERROR,
734 _("Failed to find %saddress for `%s'.\n"),
735 disablev6 ? "IPv4 " : "",
736 hostname);
737 freeaddrinfo(res);
738 GNUNET_free(hostname);
739 GNUNET_free_non_null(unixpath);
740 return GNUNET_SYSERR;
741 }
742 resi = i;
796 if (NULL != unixpath) 743 if (NULL != unixpath)
797 resi++; 744 resi++;
745 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
746 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
798 i = 0; 747 i = 0;
799 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *));
800 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t));
801 if (NULL != unixpath) 748 if (NULL != unixpath)
802 { 749 {
803 add_unixpath (saddrs, saddrlens, unixpath, abstract); 750 add_unixpath(saddrs, saddrlens, unixpath, abstract);
804 i++; 751 i++;
805 } 752 }
806 saddrlens[i] = sizeof (struct sockaddr_in); 753 next = res;
807 saddrs[i] = GNUNET_malloc (saddrlens[i]); 754 while (NULL != (pos = next))
808#if HAVE_SOCKADDR_IN_SIN_LEN 755 {
809 ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; 756 next = pos->ai_next;
810#endif 757 if ((disablev6) && (AF_INET6 == pos->ai_family))
811 ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; 758 continue;
812 ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); 759 if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol))
760 continue; /* not TCP */
761 if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype))
762 continue; /* huh? */
763 LOG(GNUNET_ERROR_TYPE_DEBUG,
764 "Service `%s' will bind to `%s'\n",
765 service_name,
766 GNUNET_a2s(pos->ai_addr, pos->ai_addrlen));
767 if (AF_INET == pos->ai_family)
768 {
769 GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen);
770 saddrlens[i] = pos->ai_addrlen;
771 saddrs[i] = GNUNET_malloc(saddrlens[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;
813 } 789 }
814 else 790 else
815 { 791 {
816 /* dual stack */ 792 /* will bind against everything, just set port */
817 resi = 2; 793 if (disablev6)
818 if (NULL != unixpath) 794 {
819 resi++; 795 /* V4-only */
820 saddrs = GNUNET_malloc ((resi + 1) * sizeof (struct sockaddr *)); 796 resi = 1;
821 saddrlens = GNUNET_malloc ((resi + 1) * sizeof (socklen_t)); 797 if (NULL != unixpath)
822 i = 0; 798 resi++;
823 if (NULL != unixpath) 799 i = 0;
824 { 800 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
825 add_unixpath (saddrs, saddrlens, unixpath, abstract); 801 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
826 i++; 802 if (NULL != unixpath)
827 } 803 {
828 saddrlens[i] = sizeof (struct sockaddr_in6); 804 add_unixpath(saddrs, saddrlens, unixpath, abstract);
829 saddrs[i] = GNUNET_malloc (saddrlens[i]); 805 i++;
806 }
807 saddrlens[i] = sizeof(struct sockaddr_in);
808 saddrs[i] = GNUNET_malloc(saddrlens[i]);
830#if HAVE_SOCKADDR_IN_SIN_LEN 809#if HAVE_SOCKADDR_IN_SIN_LEN
831 ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; 810 ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i];
832#endif 811#endif
833 ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; 812 ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET;
834 ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); 813 ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port);
835 i++; 814 }
836 saddrlens[i] = sizeof (struct sockaddr_in); 815 else
837 saddrs[i] = GNUNET_malloc (saddrlens[i]); 816 {
817 /* dual stack */
818 resi = 2;
819 if (NULL != unixpath)
820 resi++;
821 saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *));
822 saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t));
823 i = 0;
824 if (NULL != unixpath)
825 {
826 add_unixpath(saddrs, saddrlens, unixpath, abstract);
827 i++;
828 }
829 saddrlens[i] = sizeof(struct sockaddr_in6);
830 saddrs[i] = GNUNET_malloc(saddrlens[i]);
831#if HAVE_SOCKADDR_IN_SIN_LEN
832 ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0];
833#endif
834 ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6;
835 ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port);
836 i++;
837 saddrlens[i] = sizeof(struct sockaddr_in);
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);
844 }
843 } 845 }
844 } 846 GNUNET_free_non_null(unixpath);
845 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;
@@ -858,7 +859,7 @@ LEGACY_SERVICE_get_server_addresses (
858 * and #GNUNET_SYSERR on error. 859 * and #GNUNET_SYSERR on error.
859 */ 860 */
860static int 861static int
861receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) 862receive_sockets_from_parent(struct LEGACY_SERVICE_Context *sctx)
862{ 863{
863 const char *env_buf; 864 const char *env_buf;
864 int fail; 865 int fail;
@@ -866,72 +867,73 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
866 uint64_t i; 867 uint64_t i;
867 HANDLE lsocks_pipe; 868 HANDLE lsocks_pipe;
868 869
869 env_buf = getenv ("GNUNET_OS_READ_LSOCKS"); 870 env_buf = getenv("GNUNET_OS_READ_LSOCKS");
870 if ((NULL == env_buf) || (strlen (env_buf) <= 0)) 871 if ((NULL == env_buf) || (strlen(env_buf) <= 0))
871 return GNUNET_NO; 872 return GNUNET_NO;
872 /* Using W32 API directly here, because this pipe will 873 /* Using W32 API directly here, because this pipe will
873 * never be used outside of this function, and it's just too much of a bother 874 * never be used outside of this function, and it's just too much of a bother
874 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) 875 * to create a GNUnet API that boxes a HANDLE (the way it is done with socks)
875 */ 876 */
876 lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10); 877 lsocks_pipe = (HANDLE)strtoul(env_buf, NULL, 10);
877 if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) 878 if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe))
878 return GNUNET_NO; 879 return GNUNET_NO;
879 fail = 1; 880 fail = 1;
880 do 881 do
881 {
882 int ret;
883 int fail2;
884 DWORD rd;
885
886 ret = ReadFile (lsocks_pipe, &count, sizeof (count), &rd, NULL);
887 if ((0 == ret) || (sizeof (count) != rd) || (0 == count))
888 break;
889 sctx->lsocks =
890 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1));
891
892 fail2 = 1;
893 for (i = 0; i < count; i++)
894 { 882 {
895 WSAPROTOCOL_INFOA pi; 883 int ret;
896 uint64_t size; 884 int fail2;
897 SOCKET s; 885 DWORD rd;
898 886
899 ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL); 887 ret = ReadFile(lsocks_pipe, &count, sizeof(count), &rd, NULL);
900 if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size)) 888 if ((0 == ret) || (sizeof(count) != rd) || (0 == count))
901 break;
902 ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL);
903 if ((0 == ret) || (sizeof (pi) != rd))
904 break; 889 break;
905 s = WSASocketA (pi.iAddressFamily, 890 sctx->lsocks =
906 pi.iSocketType, 891 GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (count + 1));
907 pi.iProtocol, 892
908 &pi, 893 fail2 = 1;
909 0, 894 for (i = 0; i < count; i++)
910 WSA_FLAG_OVERLAPPED); 895 {
911 sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s); 896 WSAPROTOCOL_INFOA pi;
912 if (NULL == sctx->lsocks[i]) 897 uint64_t size;
898 SOCKET s;
899
900 ret = ReadFile(lsocks_pipe, &size, sizeof(size), &rd, NULL);
901 if ((0 == ret) || (sizeof(size) != rd) || (sizeof(pi) != size))
902 break;
903 ret = ReadFile(lsocks_pipe, &pi, sizeof(pi), &rd, NULL);
904 if ((0 == ret) || (sizeof(pi) != rd))
905 break;
906 s = WSASocketA(pi.iAddressFamily,
907 pi.iSocketType,
908 pi.iProtocol,
909 &pi,
910 0,
911 WSA_FLAG_OVERLAPPED);
912 sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native(s);
913 if (NULL == sctx->lsocks[i])
914 break;
915 else if (i == count - 1)
916 fail2 = 0;
917 }
918 if (fail2)
913 break; 919 break;
914 else if (i == count - 1) 920 sctx->lsocks[count] = NULL;
915 fail2 = 0; 921 fail = 0;
916 } 922 }
917 if (fail2) 923 while (fail);
918 break;
919 sctx->lsocks[count] = NULL;
920 fail = 0;
921 } while (fail);
922 924
923 CloseHandle (lsocks_pipe); 925 CloseHandle(lsocks_pipe);
924 926
925 if (fail) 927 if (fail)
926 { 928 {
927 LOG (GNUNET_ERROR_TYPE_ERROR, 929 LOG(GNUNET_ERROR_TYPE_ERROR,
928 _ ("Could not access a pre-bound socket, will try to bind myself\n")); 930 _("Could not access a pre-bound socket, will try to bind myself\n"));
929 for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) 931 for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++)
930 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i])); 932 GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[i]));
931 GNUNET_free_non_null (sctx->lsocks); 933 GNUNET_free_non_null(sctx->lsocks);
932 sctx->lsocks = NULL; 934 sctx->lsocks = NULL;
933 return GNUNET_NO; 935 return GNUNET_NO;
934 } 936 }
935 return GNUNET_YES; 937 return GNUNET_YES;
936} 938}
937#endif 939#endif
@@ -956,7 +958,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx)
956 * @return #GNUNET_OK if configuration succeeded 958 * @return #GNUNET_OK if configuration succeeded
957 */ 959 */
958static int 960static int
959setup_service (struct LEGACY_SERVICE_Context *sctx) 961setup_service(struct LEGACY_SERVICE_Context *sctx)
960{ 962{
961 struct GNUNET_TIME_Relative idleout; 963 struct GNUNET_TIME_Relative idleout;
962 int tolerant; 964 int tolerant;
@@ -967,99 +969,99 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
967 int flags; 969 int flags;
968#endif 970#endif
969 971
970 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, 972 if (GNUNET_CONFIGURATION_have_value(sctx->cfg,
971 sctx->service_name, 973 sctx->service_name,
972 "TIMEOUT")) 974 "TIMEOUT"))
973 {
974 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
975 sctx->service_name,
976 "TIMEOUT",
977 &idleout))
978 { 975 {
979 LOG (GNUNET_ERROR_TYPE_ERROR, 976 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(sctx->cfg,
980 _ ("Specified value for `%s' of service `%s' is invalid\n"), 977 sctx->service_name,
981 "TIMEOUT", 978 "TIMEOUT",
982 sctx->service_name); 979 &idleout))
983 return GNUNET_SYSERR; 980 {
981 LOG(GNUNET_ERROR_TYPE_ERROR,
982 _("Specified value for `%s' of service `%s' is invalid\n"),
983 "TIMEOUT",
984 sctx->service_name);
985 return GNUNET_SYSERR;
986 }
987 sctx->timeout = idleout;
984 } 988 }
985 sctx->timeout = idleout;
986 }
987 else 989 else
988 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 990 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
989 991
990 if (GNUNET_CONFIGURATION_have_value (sctx->cfg, 992 if (GNUNET_CONFIGURATION_have_value(sctx->cfg,
991 sctx->service_name, 993 sctx->service_name,
992 "TOLERANT")) 994 "TOLERANT"))
993 {
994 if (GNUNET_SYSERR ==
995 (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
996 sctx->service_name,
997 "TOLERANT")))
998 { 995 {
999 LOG (GNUNET_ERROR_TYPE_ERROR, 996 if (GNUNET_SYSERR ==
1000 _ ("Specified value for `%s' of service `%s' is invalid\n"), 997 (tolerant = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg,
1001 "TOLERANT", 998 sctx->service_name,
1002 sctx->service_name); 999 "TOLERANT")))
1003 return GNUNET_SYSERR; 1000 {
1001 LOG(GNUNET_ERROR_TYPE_ERROR,
1002 _("Specified value for `%s' of service `%s' is invalid\n"),
1003 "TOLERANT",
1004 sctx->service_name);
1005 return GNUNET_SYSERR;
1006 }
1004 } 1007 }
1005 }
1006 else 1008 else
1007 tolerant = GNUNET_NO; 1009 tolerant = GNUNET_NO;
1008 1010
1009#ifndef MINGW 1011#ifndef MINGW
1010 errno = 0; 1012 errno = 0;
1011 if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && 1013 if ((NULL != (nfds = getenv("LISTEN_FDS"))) &&
1012 (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && 1014 (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) &&
1013 (cnt + 4 < FD_SETSIZE)) 1015 (cnt + 4 < FD_SETSIZE))
1014 {
1015 sctx->lsocks =
1016 GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1));
1017 while (0 < cnt--)
1018 { 1016 {
1019 flags = fcntl (3 + cnt, F_GETFD); 1017 sctx->lsocks =
1020 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) || 1018 GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (cnt + 1));
1021 (NULL == 1019 while (0 < cnt--)
1022 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) 1020 {
1023 { 1021 flags = fcntl(3 + cnt, F_GETFD);
1024 LOG (GNUNET_ERROR_TYPE_ERROR, 1022 if ((flags < 0) || (0 != (flags & FD_CLOEXEC)) ||
1025 _ ( 1023 (NULL ==
1026 "Could not access pre-bound socket %u, will try to bind myself\n"), 1024 (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native(3 + cnt))))
1027 (unsigned int) 3 + cnt); 1025 {
1028 cnt++; 1026 LOG(GNUNET_ERROR_TYPE_ERROR,
1029 while (sctx->lsocks[cnt] != NULL) 1027 _(
1030 GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[cnt++])); 1028 "Could not access pre-bound socket %u, will try to bind myself\n"),
1031 GNUNET_free (sctx->lsocks); 1029 (unsigned int)3 + cnt);
1032 sctx->lsocks = NULL; 1030 cnt++;
1033 break; 1031 while (sctx->lsocks[cnt] != NULL)
1034 } 1032 GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[cnt++]));
1033 GNUNET_free(sctx->lsocks);
1034 sctx->lsocks = NULL;
1035 break;
1036 }
1037 }
1038 unsetenv("LISTEN_FDS");
1035 } 1039 }
1036 unsetenv ("LISTEN_FDS");
1037 }
1038#else 1040#else
1039 if (getenv ("GNUNET_OS_READ_LSOCKS") != NULL) 1041 if (getenv("GNUNET_OS_READ_LSOCKS") != NULL)
1040 { 1042 {
1041 receive_sockets_from_parent (sctx); 1043 receive_sockets_from_parent(sctx);
1042 putenv ("GNUNET_OS_READ_LSOCKS="); 1044 putenv("GNUNET_OS_READ_LSOCKS=");
1043 } 1045 }
1044#endif 1046#endif
1045 1047
1046 if ((NULL == sctx->lsocks) && 1048 if ((NULL == sctx->lsocks) &&
1047 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name, 1049 (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name,
1048 sctx->cfg, 1050 sctx->cfg,
1049 &sctx->addrs, 1051 &sctx->addrs,
1050 &sctx->addrlens))) 1052 &sctx->addrlens)))
1051 return GNUNET_SYSERR; 1053 return GNUNET_SYSERR;
1052 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; 1054 sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES;
1053 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, 1055 sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg,
1054 sctx->service_name, 1056 sctx->service_name,
1055 "UNIX_MATCH_UID"); 1057 "UNIX_MATCH_UID");
1056 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, 1058 sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno(sctx->cfg,
1057 sctx->service_name, 1059 sctx->service_name,
1058 "UNIX_MATCH_GID"); 1060 "UNIX_MATCH_GID");
1059 process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); 1061 process_acl4(&sctx->v4_denied, sctx, "REJECT_FROM");
1060 process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); 1062 process_acl4(&sctx->v4_allowed, sctx, "ACCEPT_FROM");
1061 process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); 1063 process_acl6(&sctx->v6_denied, sctx, "REJECT_FROM6");
1062 process_acl6 (&sctx->v6_allowed, sctx, "ACCEPT_FROM6"); 1064 process_acl6(&sctx->v6_allowed, sctx, "ACCEPT_FROM6");
1063 1065
1064 return GNUNET_OK; 1066 return GNUNET_OK;
1065} 1067}
@@ -1073,14 +1075,14 @@ setup_service (struct LEGACY_SERVICE_Context *sctx)
1073 * @return value of the 'USERNAME' option 1075 * @return value of the 'USERNAME' option
1074 */ 1076 */
1075static char * 1077static char *
1076get_user_name (struct LEGACY_SERVICE_Context *sctx) 1078get_user_name(struct LEGACY_SERVICE_Context *sctx)
1077{ 1079{
1078 char *un; 1080 char *un;
1079 1081
1080 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, 1082 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(sctx->cfg,
1081 sctx->service_name, 1083 sctx->service_name,
1082 "USERNAME", 1084 "USERNAME",
1083 &un)) 1085 &un))
1084 return NULL; 1086 return NULL;
1085 return un; 1087 return un;
1086} 1088}
@@ -1094,7 +1096,7 @@ get_user_name (struct LEGACY_SERVICE_Context *sctx)
1094 * @return #GNUNET_OK on success (including no work to be done) 1096 * @return #GNUNET_OK on success (including no work to be done)
1095 */ 1097 */
1096static int 1098static int
1097write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) 1099write_pid_file(struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1098{ 1100{
1099 FILE *pidfd; 1101 FILE *pidfd;
1100 char *pif; 1102 char *pif;
@@ -1102,46 +1104,46 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1102 char *rdir; 1104 char *rdir;
1103 int len; 1105 int len;
1104 1106
1105 if (NULL == (pif = get_pid_file_name (sctx))) 1107 if (NULL == (pif = get_pid_file_name(sctx)))
1106 return GNUNET_OK; /* no file desired */ 1108 return GNUNET_OK; /* no file desired */
1107 user = get_user_name (sctx); 1109 user = get_user_name(sctx);
1108 rdir = GNUNET_strdup (pif); 1110 rdir = GNUNET_strdup(pif);
1109 len = strlen (rdir); 1111 len = strlen(rdir);
1110 while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) 1112 while ((len > 0) && (rdir[len] != DIR_SEPARATOR))
1111 len--; 1113 len--;
1112 rdir[len] = '\0'; 1114 rdir[len] = '\0';
1113 if (0 != access (rdir, F_OK)) 1115 if (0 != access(rdir, F_OK))
1114 { 1116 {
1115 /* we get to create a directory -- and claim it 1117 /* we get to create a directory -- and claim it
1116 * as ours! */ 1118 * as ours! */
1117 (void) GNUNET_DISK_directory_create (rdir); 1119 (void)GNUNET_DISK_directory_create(rdir);
1118 if ((NULL != user) && (0 < strlen (user))) 1120 if ((NULL != user) && (0 < strlen(user)))
1119 GNUNET_DISK_file_change_owner (rdir, user); 1121 GNUNET_DISK_file_change_owner(rdir, user);
1120 } 1122 }
1121 if (0 != access (rdir, W_OK | X_OK)) 1123 if (0 != access(rdir, W_OK | X_OK))
1122 { 1124 {
1123 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); 1125 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "access", rdir);
1124 GNUNET_free (rdir); 1126 GNUNET_free(rdir);
1125 GNUNET_free_non_null (user); 1127 GNUNET_free_non_null(user);
1126 GNUNET_free (pif); 1128 GNUNET_free(pif);
1127 return GNUNET_SYSERR; 1129 return GNUNET_SYSERR;
1128 } 1130 }
1129 GNUNET_free (rdir); 1131 GNUNET_free(rdir);
1130 pidfd = fopen (pif, "w"); 1132 pidfd = fopen(pif, "w");
1131 if (NULL == pidfd) 1133 if (NULL == pidfd)
1132 { 1134 {
1133 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); 1135 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "fopen", pif);
1134 GNUNET_free (pif); 1136 GNUNET_free(pif);
1135 GNUNET_free_non_null (user); 1137 GNUNET_free_non_null(user);
1136 return GNUNET_SYSERR; 1138 return GNUNET_SYSERR;
1137 } 1139 }
1138 if (0 > fprintf (pidfd, "%u", pid)) 1140 if (0 > fprintf(pidfd, "%u", pid))
1139 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); 1141 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "fprintf", pif);
1140 GNUNET_break (0 == fclose (pidfd)); 1142 GNUNET_break(0 == fclose(pidfd));
1141 if ((NULL != user) && (0 < strlen (user))) 1143 if ((NULL != user) && (0 < strlen(user)))
1142 GNUNET_DISK_file_change_owner (pif, user); 1144 GNUNET_DISK_file_change_owner(pif, user);
1143 GNUNET_free_non_null (user); 1145 GNUNET_free_non_null(user);
1144 GNUNET_free (pif); 1146 GNUNET_free(pif);
1145 return GNUNET_OK; 1147 return GNUNET_OK;
1146} 1148}
1147 1149
@@ -1152,16 +1154,16 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid)
1152 * @param cls the `struct LEGACY_SERVICE_Context` 1154 * @param cls the `struct LEGACY_SERVICE_Context`
1153 */ 1155 */
1154static void 1156static void
1155shutdown_task (void *cls) 1157shutdown_task(void *cls)
1156{ 1158{
1157 struct LEGACY_SERVICE_Context *service = cls; 1159 struct LEGACY_SERVICE_Context *service = cls;
1158 struct GNUNET_SERVER_Handle *server = service->server; 1160 struct GNUNET_SERVER_Handle *server = service->server;
1159 1161
1160 service->shutdown_task = NULL; 1162 service->shutdown_task = NULL;
1161 if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN)) 1163 if (0 != (service->options & LEGACY_SERVICE_OPTION_SOFT_SHUTDOWN))
1162 GNUNET_SERVER_stop_listening (server); 1164 GNUNET_SERVER_stop_listening(server);
1163 else 1165 else
1164 GNUNET_SERVER_destroy (server); 1166 GNUNET_SERVER_destroy(server);
1165} 1167}
1166 1168
1167 1169
@@ -1171,81 +1173,81 @@ shutdown_task (void *cls)
1171 * @param cls service context 1173 * @param cls service context
1172 */ 1174 */
1173static void 1175static void
1174service_task (void *cls) 1176service_task(void *cls)
1175{ 1177{
1176 struct LEGACY_SERVICE_Context *sctx = cls; 1178 struct LEGACY_SERVICE_Context *sctx = cls;
1177 unsigned int i; 1179 unsigned int i;
1178 1180
1179 GNUNET_RESOLVER_connect (sctx->cfg); 1181 GNUNET_RESOLVER_connect(sctx->cfg);
1180 if (NULL != sctx->lsocks) 1182 if (NULL != sctx->lsocks)
1181 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, 1183 sctx->server = GNUNET_SERVER_create_with_sockets(&check_access,
1182 sctx, 1184 sctx,
1183 sctx->lsocks, 1185 sctx->lsocks,
1184 sctx->timeout, 1186 sctx->timeout,
1185 sctx->require_found); 1187 sctx->require_found);
1186 else 1188 else
1187 sctx->server = GNUNET_SERVER_create (&check_access, 1189 sctx->server = GNUNET_SERVER_create(&check_access,
1188 sctx, 1190 sctx,
1189 sctx->addrs, 1191 sctx->addrs,
1190 sctx->addrlens, 1192 sctx->addrlens,
1191 sctx->timeout, 1193 sctx->timeout,
1192 sctx->require_found); 1194 sctx->require_found);
1193 if (NULL == sctx->server) 1195 if (NULL == sctx->server)
1194 { 1196 {
1195 if (NULL != sctx->addrs) 1197 if (NULL != sctx->addrs)
1196 for (i = 0; NULL != sctx->addrs[i]; i++) 1198 for (i = 0; NULL != sctx->addrs[i]; i++)
1197 LOG (GNUNET_ERROR_TYPE_INFO, 1199 LOG(GNUNET_ERROR_TYPE_INFO,
1198 _ ("Failed to start `%s' at `%s'\n"), 1200 _("Failed to start `%s' at `%s'\n"),
1199 sctx->service_name, 1201 sctx->service_name,
1200 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); 1202 GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i]));
1201 sctx->ret = GNUNET_SYSERR; 1203 sctx->ret = GNUNET_SYSERR;
1202 return; 1204 return;
1203 } 1205 }
1204#ifndef WINDOWS 1206#ifndef WINDOWS
1205 if (NULL != sctx->addrs) 1207 if (NULL != sctx->addrs)
1206 for (i = 0; NULL != sctx->addrs[i]; i++) 1208 for (i = 0; NULL != sctx->addrs[i]; i++)
1207 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1209 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1208 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) 1210 ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
1209 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) 1211 GNUNET_DISK_fix_permissions(((const struct sockaddr_un *)
1210 sctx->addrs[i]) 1212 sctx->addrs[i])
1211 ->sun_path, 1213 ->sun_path,
1212 sctx->match_uid, 1214 sctx->match_uid,
1213 sctx->match_gid); 1215 sctx->match_gid);
1214#endif 1216#endif
1215 1217
1216 1218
1217 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN)) 1219 if (0 == (sctx->options & LEGACY_SERVICE_OPTION_MANUAL_SHUTDOWN))
1218 { 1220 {
1219 /* install a task that will kill the server 1221 /* install a task that will kill the server
1220 * process if the scheduler ever gets a shutdown signal */ 1222 * process if the scheduler ever gets a shutdown signal */
1221 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx); 1223 sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown(&shutdown_task, sctx);
1222 } 1224 }
1223 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1225 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers));
1224 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1226 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers));
1225 i = 0; 1227 i = 0;
1226 while (NULL != sctx->my_handlers[i].callback) 1228 while (NULL != sctx->my_handlers[i].callback)
1227 sctx->my_handlers[i++].callback_cls = sctx; 1229 sctx->my_handlers[i++].callback_cls = sctx;
1228 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); 1230 GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers);
1229 if (-1 != sctx->ready_confirm_fd) 1231 if (-1 != sctx->ready_confirm_fd)
1230 { 1232 {
1231 GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1)); 1233 GNUNET_break(1 == write(sctx->ready_confirm_fd, ".", 1));
1232 GNUNET_break (0 == close (sctx->ready_confirm_fd)); 1234 GNUNET_break(0 == close(sctx->ready_confirm_fd));
1233 sctx->ready_confirm_fd = -1; 1235 sctx->ready_confirm_fd = -1;
1234 write_pid_file (sctx, getpid ()); 1236 write_pid_file(sctx, getpid());
1235 } 1237 }
1236 if (NULL != sctx->addrs) 1238 if (NULL != sctx->addrs)
1237 {
1238 i = 0;
1239 while (NULL != sctx->addrs[i])
1240 { 1239 {
1241 LOG (GNUNET_ERROR_TYPE_INFO, 1240 i = 0;
1242 _ ("Service `%s' runs at %s\n"), 1241 while (NULL != sctx->addrs[i])
1243 sctx->service_name, 1242 {
1244 GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); 1243 LOG(GNUNET_ERROR_TYPE_INFO,
1245 i++; 1244 _("Service `%s' runs at %s\n"),
1245 sctx->service_name,
1246 GNUNET_a2s(sctx->addrs[i], sctx->addrlens[i]));
1247 i++;
1248 }
1246 } 1249 }
1247 } 1250 sctx->task(sctx->task_cls, sctx->server, sctx->cfg);
1248 sctx->task (sctx->task_cls, sctx->server, sctx->cfg);
1249} 1251}
1250 1252
1251 1253
@@ -1256,76 +1258,79 @@ service_task (void *cls)
1256 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1258 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1257 */ 1259 */
1258static int 1260static int
1259detach_terminal (struct LEGACY_SERVICE_Context *sctx) 1261detach_terminal(struct LEGACY_SERVICE_Context *sctx)
1260{ 1262{
1261#ifndef MINGW 1263#ifndef MINGW
1262 pid_t pid; 1264 pid_t pid;
1263 int nullfd; 1265 int nullfd;
1264 int filedes[2]; 1266 int filedes[2];
1265 1267
1266 if (0 != pipe (filedes)) 1268 if (0 != pipe(filedes))
1267 { 1269 {
1268 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); 1270 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "pipe");
1269 return GNUNET_SYSERR; 1271 return GNUNET_SYSERR;
1270 } 1272 }
1271 pid = fork (); 1273 pid = fork();
1272 if (pid < 0) 1274 if (pid < 0)
1273 { 1275 {
1274 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "fork"); 1276 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "fork");
1275 return GNUNET_SYSERR; 1277 return GNUNET_SYSERR;
1276 } 1278 }
1277 if (0 != pid) 1279 if (0 != pid)
1278 {
1279 /* Parent */
1280 char c;
1281
1282 GNUNET_break (0 == close (filedes[1]));
1283 c = 'X';
1284 if (1 != read (filedes[0], &c, sizeof (char)))
1285 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read");
1286 fflush (stdout);
1287 switch (c)
1288 { 1280 {
1289 case '.': 1281 /* Parent */
1290 exit (0); 1282 char c;
1291 case 'I': 1283
1292 LOG (GNUNET_ERROR_TYPE_INFO, 1284 GNUNET_break(0 == close(filedes[1]));
1293 _ ("Service process failed to initialize\n")); 1285 c = 'X';
1294 break; 1286 if (1 != read(filedes[0], &c, sizeof(char)))
1295 case 'S': 1287 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "read");
1296 LOG (GNUNET_ERROR_TYPE_INFO, 1288 fflush(stdout);
1297 _ ("Service process could not initialize server function\n")); 1289 switch (c)
1298 break; 1290 {
1299 case 'X': 1291 case '.':
1300 LOG (GNUNET_ERROR_TYPE_INFO, 1292 exit(0);
1301 _ ("Service process failed to report status\n")); 1293
1302 break; 1294 case 'I':
1295 LOG(GNUNET_ERROR_TYPE_INFO,
1296 _("Service process failed to initialize\n"));
1297 break;
1298
1299 case 'S':
1300 LOG(GNUNET_ERROR_TYPE_INFO,
1301 _("Service process could not initialize server function\n"));
1302 break;
1303
1304 case 'X':
1305 LOG(GNUNET_ERROR_TYPE_INFO,
1306 _("Service process failed to report status\n"));
1307 break;
1308 }
1309 exit(1); /* child reported error */
1303 } 1310 }
1304 exit (1); /* child reported error */ 1311 GNUNET_break(0 == close(0));
1305 } 1312 GNUNET_break(0 == close(1));
1306 GNUNET_break (0 == close (0)); 1313 GNUNET_break(0 == close(filedes[0]));
1307 GNUNET_break (0 == close (1)); 1314 nullfd = open("/dev/null", O_RDWR | O_APPEND);
1308 GNUNET_break (0 == close (filedes[0]));
1309 nullfd = open ("/dev/null", O_RDWR | O_APPEND);
1310 if (nullfd < 0) 1315 if (nullfd < 0)
1311 return GNUNET_SYSERR; 1316 return GNUNET_SYSERR;
1312 /* set stdin/stdout to /dev/null */ 1317 /* set stdin/stdout to /dev/null */
1313 if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) 1318 if ((dup2(nullfd, 0) < 0) || (dup2(nullfd, 1) < 0))
1314 { 1319 {
1315 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); 1320 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "dup2");
1316 (void) close (nullfd); 1321 (void)close(nullfd);
1317 return GNUNET_SYSERR; 1322 return GNUNET_SYSERR;
1318 } 1323 }
1319 (void) close (nullfd); 1324 (void)close(nullfd);
1320 /* Detach from controlling terminal */ 1325 /* Detach from controlling terminal */
1321 pid = setsid (); 1326 pid = setsid();
1322 if (-1 == pid) 1327 if (-1 == pid)
1323 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "setsid"); 1328 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid");
1324 sctx->ready_confirm_fd = filedes[1]; 1329 sctx->ready_confirm_fd = filedes[1];
1325#else 1330#else
1326 /* FIXME: we probably need to do something else 1331 /* FIXME: we probably need to do something else
1327 * elsewhere in order to fork the process itself... */ 1332 * elsewhere in order to fork the process itself... */
1328 FreeConsole (); 1333 FreeConsole();
1329#endif 1334#endif
1330 return GNUNET_OK; 1335 return GNUNET_OK;
1331} 1336}
@@ -1338,45 +1343,45 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx)
1338 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 1343 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
1339 */ 1344 */
1340static int 1345static int
1341set_user_id (struct LEGACY_SERVICE_Context *sctx) 1346set_user_id(struct LEGACY_SERVICE_Context *sctx)
1342{ 1347{
1343 char *user; 1348 char *user;
1344 1349
1345 if (NULL == (user = get_user_name (sctx))) 1350 if (NULL == (user = get_user_name(sctx)))
1346 return GNUNET_OK; /* keep */ 1351 return GNUNET_OK; /* keep */
1347#ifndef MINGW 1352#ifndef MINGW
1348 struct passwd *pws; 1353 struct passwd *pws;
1349 1354
1350 errno = 0; 1355 errno = 0;
1351 pws = getpwnam (user); 1356 pws = getpwnam(user);
1352 if (NULL == pws) 1357 if (NULL == pws)
1353 { 1358 {
1354 LOG (GNUNET_ERROR_TYPE_ERROR, 1359 LOG(GNUNET_ERROR_TYPE_ERROR,
1355 _ ("Cannot obtain information about user `%s': %s\n"), 1360 _("Cannot obtain information about user `%s': %s\n"),
1356 user, 1361 user,
1357 errno == 0 ? _ ("No such user") : strerror (errno)); 1362 errno == 0 ? _("No such user") : strerror(errno));
1358 GNUNET_free (user); 1363 GNUNET_free(user);
1359 return GNUNET_SYSERR; 1364 return GNUNET_SYSERR;
1360 } 1365 }
1361 if ((0 != setgid (pws->pw_gid)) || (0 != setegid (pws->pw_gid)) || 1366 if ((0 != setgid(pws->pw_gid)) || (0 != setegid(pws->pw_gid)) ||
1362#if HAVE_INITGROUPS 1367#if HAVE_INITGROUPS
1363 (0 != initgroups (user, pws->pw_gid)) || 1368 (0 != initgroups(user, pws->pw_gid)) ||
1364#endif 1369#endif
1365 (0 != setuid (pws->pw_uid)) || (0 != seteuid (pws->pw_uid))) 1370 (0 != setuid(pws->pw_uid)) || (0 != seteuid(pws->pw_uid)))
1366 {
1367 if ((0 != setregid (pws->pw_gid, pws->pw_gid)) ||
1368 (0 != setreuid (pws->pw_uid, pws->pw_uid)))
1369 { 1371 {
1370 LOG (GNUNET_ERROR_TYPE_ERROR, 1372 if ((0 != setregid(pws->pw_gid, pws->pw_gid)) ||
1371 _ ("Cannot change user/group to `%s': %s\n"), 1373 (0 != setreuid(pws->pw_uid, pws->pw_uid)))
1372 user, 1374 {
1373 strerror (errno)); 1375 LOG(GNUNET_ERROR_TYPE_ERROR,
1374 GNUNET_free (user); 1376 _("Cannot change user/group to `%s': %s\n"),
1375 return GNUNET_SYSERR; 1377 user,
1378 strerror(errno));
1379 GNUNET_free(user);
1380 return GNUNET_SYSERR;
1381 }
1376 } 1382 }
1377 }
1378#endif 1383#endif
1379 GNUNET_free (user); 1384 GNUNET_free(user);
1380 return GNUNET_OK; 1385 return GNUNET_OK;
1381} 1386}
1382 1387
@@ -1387,15 +1392,15 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx)
1387 * @param sctx service context 1392 * @param sctx service context
1388 */ 1393 */
1389static void 1394static void
1390pid_file_delete (struct LEGACY_SERVICE_Context *sctx) 1395pid_file_delete(struct LEGACY_SERVICE_Context *sctx)
1391{ 1396{
1392 char *pif = get_pid_file_name (sctx); 1397 char *pif = get_pid_file_name(sctx);
1393 1398
1394 if (NULL == pif) 1399 if (NULL == pif)
1395 return; /* no PID file */ 1400 return; /* no PID file */
1396 if (0 != unlink (pif)) 1401 if (0 != unlink(pif))
1397 LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); 1402 LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "unlink", pif);
1398 GNUNET_free (pif); 1403 GNUNET_free(pif);
1399} 1404}
1400 1405
1401 1406
@@ -1413,19 +1418,19 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx)
1413 * if we shutdown nicely 1418 * if we shutdown nicely
1414 */ 1419 */
1415int 1420int
1416LEGACY_SERVICE_run (int argc, 1421LEGACY_SERVICE_run(int argc,
1417 char *const *argv, 1422 char *const *argv,
1418 const char *service_name, 1423 const char *service_name,
1419 enum LEGACY_SERVICE_Options options, 1424 enum LEGACY_SERVICE_Options options,
1420 LEGACY_SERVICE_Main task, 1425 LEGACY_SERVICE_Main task,
1421 void *task_cls) 1426 void *task_cls)
1422{ 1427{
1423#define HANDLE_ERROR \ 1428#define HANDLE_ERROR \
1424 do \ 1429 do \
1425 { \ 1430 { \
1426 GNUNET_break (0); \ 1431 GNUNET_break(0); \
1427 goto shutdown; \ 1432 goto shutdown; \
1428 } while (0) 1433 } while (0)
1429 1434
1430 int err; 1435 int err;
1431 int ret; 1436 int ret;
@@ -1443,32 +1448,32 @@ LEGACY_SERVICE_run (int argc,
1443 const char *xdg; 1448 const char *xdg;
1444 1449
1445 struct GNUNET_GETOPT_CommandLineOption service_options[] = 1450 struct GNUNET_GETOPT_CommandLineOption service_options[] =
1446 {GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn), 1451 { GNUNET_GETOPT_option_cfgfile(&opt_cfg_fn),
1447 GNUNET_GETOPT_option_flag ('d', 1452 GNUNET_GETOPT_option_flag('d',
1448 "daemonize", 1453 "daemonize",
1449 gettext_noop ( 1454 gettext_noop(
1450 "do daemonize (detach from terminal)"), 1455 "do daemonize (detach from terminal)"),
1451 &do_daemonize), 1456 &do_daemonize),
1452 GNUNET_GETOPT_option_help (NULL), 1457 GNUNET_GETOPT_option_help(NULL),
1453 GNUNET_GETOPT_option_loglevel (&loglev), 1458 GNUNET_GETOPT_option_loglevel(&loglev),
1454 GNUNET_GETOPT_option_logfile (&logfile), 1459 GNUNET_GETOPT_option_logfile(&logfile),
1455 GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), 1460 GNUNET_GETOPT_option_version(PACKAGE_VERSION " " VCS_VERSION),
1456 GNUNET_GETOPT_OPTION_END}; 1461 GNUNET_GETOPT_OPTION_END };
1457 err = 1; 1462 err = 1;
1458 do_daemonize = 0; 1463 do_daemonize = 0;
1459 logfile = NULL; 1464 logfile = NULL;
1460 loglev = NULL; 1465 loglev = NULL;
1461 opt_cfg_fn = NULL; 1466 opt_cfg_fn = NULL;
1462 xdg = getenv ("XDG_CONFIG_HOME"); 1467 xdg = getenv("XDG_CONFIG_HOME");
1463 if (NULL != xdg) 1468 if (NULL != xdg)
1464 GNUNET_asprintf (&cfg_fn, 1469 GNUNET_asprintf(&cfg_fn,
1465 "%s%s%s", 1470 "%s%s%s",
1466 xdg, 1471 xdg,
1467 DIR_SEPARATOR_STR, 1472 DIR_SEPARATOR_STR,
1468 GNUNET_OS_project_data_get ()->config_file); 1473 GNUNET_OS_project_data_get()->config_file);
1469 else 1474 else
1470 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 1475 cfg_fn = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file);
1471 memset (&sctx, 0, sizeof (sctx)); 1476 memset(&sctx, 0, sizeof(sctx));
1472 sctx.options = options; 1477 sctx.options = options;
1473 sctx.ready_confirm_fd = -1; 1478 sctx.ready_confirm_fd = -1;
1474 sctx.ret = GNUNET_OK; 1479 sctx.ret = GNUNET_OK;
@@ -1476,117 +1481,117 @@ LEGACY_SERVICE_run (int argc,
1476 sctx.task = task; 1481 sctx.task = task;
1477 sctx.task_cls = task_cls; 1482 sctx.task_cls = task_cls;
1478 sctx.service_name = service_name; 1483 sctx.service_name = service_name;
1479 sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); 1484 sctx.cfg = cfg = GNUNET_CONFIGURATION_create();
1480 1485
1481 /* setup subsystems */ 1486 /* setup subsystems */
1482 ret = GNUNET_GETOPT_run (service_name, service_options, argc, argv); 1487 ret = GNUNET_GETOPT_run(service_name, service_options, argc, argv);
1483 if (GNUNET_SYSERR == ret) 1488 if (GNUNET_SYSERR == ret)
1484 goto shutdown; 1489 goto shutdown;
1485 if (GNUNET_NO == ret) 1490 if (GNUNET_NO == ret)
1486 { 1491 {
1487 err = 0; 1492 err = 0;
1488 goto shutdown; 1493 goto shutdown;
1489 } 1494 }
1490 if (GNUNET_OK != GNUNET_log_setup (service_name, loglev, logfile)) 1495 if (GNUNET_OK != GNUNET_log_setup(service_name, loglev, logfile))
1491 HANDLE_ERROR; 1496 HANDLE_ERROR;
1492 if (NULL == opt_cfg_fn) 1497 if (NULL == opt_cfg_fn)
1493 opt_cfg_fn = GNUNET_strdup (cfg_fn); 1498 opt_cfg_fn = GNUNET_strdup(cfg_fn);
1494 if (GNUNET_YES == GNUNET_DISK_file_test (opt_cfg_fn)) 1499 if (GNUNET_YES == GNUNET_DISK_file_test(opt_cfg_fn))
1495 {
1496 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn))
1497 { 1500 {
1498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1501 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, opt_cfg_fn))
1499 _ ("Malformed configuration file `%s', exit ...\n"), 1502 {
1500 opt_cfg_fn); 1503 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1501 goto shutdown; 1504 _("Malformed configuration file `%s', exit ...\n"),
1505 opt_cfg_fn);
1506 goto shutdown;
1507 }
1502 } 1508 }
1503 }
1504 else 1509 else
1505 {
1506 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL))
1507 { 1510 {
1508 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1511 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, NULL))
1509 _ ("Malformed configuration, exit ...\n")); 1512 {
1510 goto shutdown; 1513 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1514 _("Malformed configuration, exit ...\n"));
1515 goto shutdown;
1516 }
1517 if (0 != strcmp(opt_cfg_fn, cfg_fn))
1518 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1519 _("Could not access configuration file `%s'\n"),
1520 opt_cfg_fn);
1511 } 1521 }
1512 if (0 != strcmp (opt_cfg_fn, cfg_fn)) 1522 if (GNUNET_OK != setup_service(&sctx))
1513 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1514 _ ("Could not access configuration file `%s'\n"),
1515 opt_cfg_fn);
1516 }
1517 if (GNUNET_OK != setup_service (&sctx))
1518 goto shutdown; 1523 goto shutdown;
1519 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal (&sctx))) 1524 if ((1 == do_daemonize) && (GNUNET_OK != detach_terminal(&sctx)))
1520 HANDLE_ERROR; 1525 HANDLE_ERROR;
1521 if (GNUNET_OK != set_user_id (&sctx)) 1526 if (GNUNET_OK != set_user_id(&sctx))
1522 goto shutdown; 1527 goto shutdown;
1523 LOG (GNUNET_ERROR_TYPE_DEBUG, 1528 LOG(GNUNET_ERROR_TYPE_DEBUG,
1524 "Service `%s' runs with configuration from `%s'\n", 1529 "Service `%s' runs with configuration from `%s'\n",
1525 service_name, 1530 service_name,
1526 opt_cfg_fn); 1531 opt_cfg_fn);
1527 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, 1532 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg,
1528 "TESTING", 1533 "TESTING",
1529 "SKEW_OFFSET", 1534 "SKEW_OFFSET",
1530 &skew_offset)) && 1535 &skew_offset)) &&
1531 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, 1536 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(sctx.cfg,
1532 "TESTING", 1537 "TESTING",
1533 "SKEW_VARIANCE", 1538 "SKEW_VARIANCE",
1534 &skew_variance))) 1539 &skew_variance)))
1535 { 1540 {
1536 clock_offset = skew_offset - skew_variance; 1541 clock_offset = skew_offset - skew_variance;
1537 GNUNET_TIME_set_offset (clock_offset); 1542 GNUNET_TIME_set_offset(clock_offset);
1538 LOG (GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset); 1543 LOG(GNUNET_ERROR_TYPE_DEBUG, "Skewing clock by %dll ms\n", clock_offset);
1539 } 1544 }
1540 /* actually run service */ 1545 /* actually run service */
1541 err = 0; 1546 err = 0;
1542 GNUNET_SCHEDULER_run (&service_task, &sctx); 1547 GNUNET_SCHEDULER_run(&service_task, &sctx);
1543 /* shutdown */ 1548 /* shutdown */
1544 if ((1 == do_daemonize) && (NULL != sctx.server)) 1549 if ((1 == do_daemonize) && (NULL != sctx.server))
1545 pid_file_delete (&sctx); 1550 pid_file_delete(&sctx);
1546 GNUNET_free_non_null (sctx.my_handlers); 1551 GNUNET_free_non_null(sctx.my_handlers);
1547 1552
1548shutdown: 1553shutdown:
1549 if (-1 != sctx.ready_confirm_fd) 1554 if (-1 != sctx.ready_confirm_fd)
1550 { 1555 {
1551 if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1)) 1556 if (1 != write(sctx.ready_confirm_fd, err ? "I" : "S", 1))
1552 LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); 1557 LOG_STRERROR(GNUNET_ERROR_TYPE_WARNING, "write");
1553 GNUNET_break (0 == close (sctx.ready_confirm_fd)); 1558 GNUNET_break(0 == close(sctx.ready_confirm_fd));
1554 } 1559 }
1555#if HAVE_MALLINFO 1560#if HAVE_MALLINFO
1556 { 1561 {
1557 char *counter; 1562 char *counter;
1558 1563
1559 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg, 1564 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx.cfg,
1560 service_name, 1565 service_name,
1561 "GAUGER_HEAP")) && 1566 "GAUGER_HEAP")) &&
1562 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg, 1567 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx.cfg,
1563 service_name, 1568 service_name,
1564 "GAUGER_HEAP", 1569 "GAUGER_HEAP",
1565 &counter))) 1570 &counter)))
1566 { 1571 {
1567 struct mallinfo mi; 1572 struct mallinfo mi;
1568 1573
1569 mi = mallinfo (); 1574 mi = mallinfo();
1570 GAUGER (service_name, counter, mi.usmblks, "blocks"); 1575 GAUGER(service_name, counter, mi.usmblks, "blocks");
1571 GNUNET_free (counter); 1576 GNUNET_free(counter);
1572 } 1577 }
1573 } 1578 }
1574#endif 1579#endif
1575 GNUNET_CONFIGURATION_destroy (cfg); 1580 GNUNET_CONFIGURATION_destroy(cfg);
1576 i = 0; 1581 i = 0;
1577 if (NULL != sctx.addrs) 1582 if (NULL != sctx.addrs)
1578 while (NULL != sctx.addrs[i]) 1583 while (NULL != sctx.addrs[i])
1579 GNUNET_free (sctx.addrs[i++]); 1584 GNUNET_free(sctx.addrs[i++]);
1580 GNUNET_free_non_null (sctx.addrs); 1585 GNUNET_free_non_null(sctx.addrs);
1581 GNUNET_free_non_null (sctx.addrlens); 1586 GNUNET_free_non_null(sctx.addrlens);
1582 GNUNET_free_non_null (logfile); 1587 GNUNET_free_non_null(logfile);
1583 GNUNET_free_non_null (loglev); 1588 GNUNET_free_non_null(loglev);
1584 GNUNET_free (cfg_fn); 1589 GNUNET_free(cfg_fn);
1585 GNUNET_free_non_null (opt_cfg_fn); 1590 GNUNET_free_non_null(opt_cfg_fn);
1586 GNUNET_free_non_null (sctx.v4_denied); 1591 GNUNET_free_non_null(sctx.v4_denied);
1587 GNUNET_free_non_null (sctx.v6_denied); 1592 GNUNET_free_non_null(sctx.v6_denied);
1588 GNUNET_free_non_null (sctx.v4_allowed); 1593 GNUNET_free_non_null(sctx.v4_allowed);
1589 GNUNET_free_non_null (sctx.v6_allowed); 1594 GNUNET_free_non_null(sctx.v6_allowed);
1590 1595
1591 return err ? GNUNET_SYSERR : sctx.ret; 1596 return err ? GNUNET_SYSERR : sctx.ret;
1592} 1597}
@@ -1602,14 +1607,14 @@ shutdown:
1602 * @return NULL on error, service handle 1607 * @return NULL on error, service handle
1603 */ 1608 */
1604struct LEGACY_SERVICE_Context * 1609struct LEGACY_SERVICE_Context *
1605LEGACY_SERVICE_start (const char *service_name, 1610LEGACY_SERVICE_start(const char *service_name,
1606 const struct GNUNET_CONFIGURATION_Handle *cfg, 1611 const struct GNUNET_CONFIGURATION_Handle *cfg,
1607 enum LEGACY_SERVICE_Options options) 1612 enum LEGACY_SERVICE_Options options)
1608{ 1613{
1609 int i; 1614 int i;
1610 struct LEGACY_SERVICE_Context *sctx; 1615 struct LEGACY_SERVICE_Context *sctx;
1611 1616
1612 sctx = GNUNET_new (struct LEGACY_SERVICE_Context); 1617 sctx = GNUNET_new(struct LEGACY_SERVICE_Context);
1613 sctx->ready_confirm_fd = -1; /* no daemonizing */ 1618 sctx->ready_confirm_fd = -1; /* no daemonizing */
1614 sctx->ret = GNUNET_OK; 1619 sctx->ret = GNUNET_OK;
1615 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; 1620 sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL;
@@ -1618,47 +1623,47 @@ LEGACY_SERVICE_start (const char *service_name,
1618 sctx->options = options; 1623 sctx->options = options;
1619 1624
1620 /* setup subsystems */ 1625 /* setup subsystems */
1621 if (GNUNET_OK != setup_service (sctx)) 1626 if (GNUNET_OK != setup_service(sctx))
1622 { 1627 {
1623 LEGACY_SERVICE_stop (sctx); 1628 LEGACY_SERVICE_stop(sctx);
1624 return NULL; 1629 return NULL;
1625 } 1630 }
1626 if (NULL != sctx->lsocks) 1631 if (NULL != sctx->lsocks)
1627 sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, 1632 sctx->server = GNUNET_SERVER_create_with_sockets(&check_access,
1628 sctx, 1633 sctx,
1629 sctx->lsocks, 1634 sctx->lsocks,
1630 sctx->timeout, 1635 sctx->timeout,
1631 sctx->require_found); 1636 sctx->require_found);
1632 else 1637 else
1633 sctx->server = GNUNET_SERVER_create (&check_access, 1638 sctx->server = GNUNET_SERVER_create(&check_access,
1634 sctx, 1639 sctx,
1635 sctx->addrs, 1640 sctx->addrs,
1636 sctx->addrlens, 1641 sctx->addrlens,
1637 sctx->timeout, 1642 sctx->timeout,
1638 sctx->require_found); 1643 sctx->require_found);
1639 1644
1640 if (NULL == sctx->server) 1645 if (NULL == sctx->server)
1641 { 1646 {
1642 LEGACY_SERVICE_stop (sctx); 1647 LEGACY_SERVICE_stop(sctx);
1643 return NULL; 1648 return NULL;
1644 } 1649 }
1645#ifndef WINDOWS 1650#ifndef WINDOWS
1646 if (NULL != sctx->addrs) 1651 if (NULL != sctx->addrs)
1647 for (i = 0; NULL != sctx->addrs[i]; i++) 1652 for (i = 0; NULL != sctx->addrs[i]; i++)
1648 if ((AF_UNIX == sctx->addrs[i]->sa_family) && 1653 if ((AF_UNIX == sctx->addrs[i]->sa_family) &&
1649 ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) 1654 ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0]))
1650 GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) 1655 GNUNET_DISK_fix_permissions(((const struct sockaddr_un *)
1651 sctx->addrs[i]) 1656 sctx->addrs[i])
1652 ->sun_path, 1657 ->sun_path,
1653 sctx->match_uid, 1658 sctx->match_uid,
1654 sctx->match_gid); 1659 sctx->match_gid);
1655#endif 1660#endif
1656 sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); 1661 sctx->my_handlers = GNUNET_malloc(sizeof(defhandlers));
1657 GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); 1662 GNUNET_memcpy(sctx->my_handlers, defhandlers, sizeof(defhandlers));
1658 i = 0; 1663 i = 0;
1659 while ((sctx->my_handlers[i].callback != NULL)) 1664 while ((sctx->my_handlers[i].callback != NULL))
1660 sctx->my_handlers[i++].callback_cls = sctx; 1665 sctx->my_handlers[i++].callback_cls = sctx;
1661 GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); 1666 GNUNET_SERVER_add_handlers(sctx->server, sctx->my_handlers);
1662 return sctx; 1667 return sctx;
1663} 1668}
1664 1669
@@ -1671,7 +1676,7 @@ LEGACY_SERVICE_start (const char *service_name,
1671 * @return handle to the server for this service, NULL if there is none 1676 * @return handle to the server for this service, NULL if there is none
1672 */ 1677 */
1673struct GNUNET_SERVER_Handle * 1678struct GNUNET_SERVER_Handle *
1674LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx) 1679LEGACY_SERVICE_get_server(struct LEGACY_SERVICE_Context *ctx)
1675{ 1680{
1676 return ctx->server; 1681 return ctx->server;
1677} 1682}
@@ -1685,7 +1690,7 @@ LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx)
1685 * array of listen sockets. 1690 * array of listen sockets.
1686 */ 1691 */
1687struct GNUNET_NETWORK_Handle *const * 1692struct GNUNET_NETWORK_Handle *const *
1688LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) 1693LEGACY_SERVICE_get_listen_sockets(struct LEGACY_SERVICE_Context *ctx)
1689{ 1694{
1690 return ctx->lsocks; 1695 return ctx->lsocks;
1691} 1696}
@@ -1697,7 +1702,7 @@ LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx)
1697 * @param sctx the service context returned from the start function 1702 * @param sctx the service context returned from the start function
1698 */ 1703 */
1699void 1704void
1700LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) 1705LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *sctx)
1701{ 1706{
1702 unsigned int i; 1707 unsigned int i;
1703 1708
@@ -1705,43 +1710,43 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx)
1705 { 1710 {
1706 char *counter; 1711 char *counter;
1707 1712
1708 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg, 1713 if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value(sctx->cfg,
1709 sctx->service_name, 1714 sctx->service_name,
1710 "GAUGER_HEAP")) && 1715 "GAUGER_HEAP")) &&
1711 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg, 1716 (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(sctx->cfg,
1712 sctx->service_name, 1717 sctx->service_name,
1713 "GAUGER_HEAP", 1718 "GAUGER_HEAP",
1714 &counter))) 1719 &counter)))
1715 { 1720 {
1716 struct mallinfo mi; 1721 struct mallinfo mi;
1717 1722
1718 mi = mallinfo (); 1723 mi = mallinfo();
1719 GAUGER (sctx->service_name, counter, mi.usmblks, "blocks"); 1724 GAUGER(sctx->service_name, counter, mi.usmblks, "blocks");
1720 GNUNET_free (counter); 1725 GNUNET_free(counter);
1721 } 1726 }
1722 } 1727 }
1723#endif 1728#endif
1724 if (NULL != sctx->shutdown_task) 1729 if (NULL != sctx->shutdown_task)
1725 { 1730 {
1726 GNUNET_SCHEDULER_cancel (sctx->shutdown_task); 1731 GNUNET_SCHEDULER_cancel(sctx->shutdown_task);
1727 sctx->shutdown_task = NULL; 1732 sctx->shutdown_task = NULL;
1728 } 1733 }
1729 if (NULL != sctx->server) 1734 if (NULL != sctx->server)
1730 GNUNET_SERVER_destroy (sctx->server); 1735 GNUNET_SERVER_destroy(sctx->server);
1731 GNUNET_free_non_null (sctx->my_handlers); 1736 GNUNET_free_non_null(sctx->my_handlers);
1732 if (NULL != sctx->addrs) 1737 if (NULL != sctx->addrs)
1733 { 1738 {
1734 i = 0; 1739 i = 0;
1735 while (NULL != sctx->addrs[i]) 1740 while (NULL != sctx->addrs[i])
1736 GNUNET_free (sctx->addrs[i++]); 1741 GNUNET_free(sctx->addrs[i++]);
1737 GNUNET_free (sctx->addrs); 1742 GNUNET_free(sctx->addrs);
1738 } 1743 }
1739 GNUNET_free_non_null (sctx->addrlens); 1744 GNUNET_free_non_null(sctx->addrlens);
1740 GNUNET_free_non_null (sctx->v4_denied); 1745 GNUNET_free_non_null(sctx->v4_denied);
1741 GNUNET_free_non_null (sctx->v6_denied); 1746 GNUNET_free_non_null(sctx->v6_denied);
1742 GNUNET_free_non_null (sctx->v4_allowed); 1747 GNUNET_free_non_null(sctx->v4_allowed);
1743 GNUNET_free_non_null (sctx->v6_allowed); 1748 GNUNET_free_non_null(sctx->v6_allowed);
1744 GNUNET_free (sctx); 1749 GNUNET_free(sctx);
1745} 1750}
1746 1751
1747 1752
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c
index fed15b236..77bd4bb38 100644
--- a/src/transport/test_communicator_unix.c
+++ b/src/transport/test_communicator_unix.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/test_communicator_unix.c 22 * @file transport/test_communicator_unix.c
@@ -33,7 +33,7 @@
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, "test_transport_communicator_unix", __VA_ARGS__)
37 37
38#define NUM_PEERS 2 38#define NUM_PEERS 2
39 39
@@ -52,12 +52,12 @@ static uint32_t payload = 42;
52 52
53 53
54static void 54static void
55communicator_available_cb (void *cls, 55communicator_available_cb(void *cls,
56 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 56 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
57 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 57 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
58 char *address_prefix) 58 char *address_prefix)
59{ 59{
60 LOG (GNUNET_ERROR_TYPE_DEBUG, 60 LOG(GNUNET_ERROR_TYPE_DEBUG,
61 "Communicator available. (cc: %u, prefix: %s)\n", 61 "Communicator available. (cc: %u, prefix: %s)\n",
62 cc, 62 cc,
63 address_prefix); 63 address_prefix);
@@ -65,23 +65,23 @@ communicator_available_cb (void *cls,
65 65
66 66
67static void 67static void
68add_address_cb (void *cls, 68add_address_cb(void *cls,
69 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 69 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
70 const char *address, 70 const char *address,
71 struct GNUNET_TIME_Relative expiration, 71 struct GNUNET_TIME_Relative expiration,
72 uint32_t aid, 72 uint32_t aid,
73 enum GNUNET_NetworkType nt) 73 enum GNUNET_NetworkType nt)
74{ 74{
75 LOG (GNUNET_ERROR_TYPE_DEBUG, 75 LOG(GNUNET_ERROR_TYPE_DEBUG,
76 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", 76 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n",
77 address, 77 address,
78 expiration.rel_value_us, 78 expiration.rel_value_us,
79 aid, 79 aid,
80 nt); 80 nt);
81 //addresses[1] = GNUNET_strdup (address); 81 //addresses[1] = GNUNET_strdup (address);
82 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0], 82 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(tc_hs[0],
83 &peer_id[1], 83 &peer_id[1],
84 address); 84 address);
85} 85}
86 86
87 87
@@ -97,15 +97,15 @@ add_address_cb (void *cls,
97 * #GNUNET_NO if queue will not be established (bogous address) 97 * #GNUNET_NO if queue will not be established (bogous address)
98 */ 98 */
99static void 99static void
100queue_create_reply_cb (void *cls, 100queue_create_reply_cb(void *cls,
101 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 101 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
102 int will_try) 102 int will_try)
103{ 103{
104 if (GNUNET_YES == will_try) 104 if (GNUNET_YES == will_try)
105 LOG (GNUNET_ERROR_TYPE_DEBUG, 105 LOG(GNUNET_ERROR_TYPE_DEBUG,
106 "Queue will be established!\n"); 106 "Queue will be established!\n");
107 else 107 else
108 LOG (GNUNET_ERROR_TYPE_WARNING, 108 LOG(GNUNET_ERROR_TYPE_WARNING,
109 "Queue won't be established (bougus address?)!\n"); 109 "Queue won't be established (bougus address?)!\n");
110} 110}
111 111
@@ -122,15 +122,15 @@ queue_create_reply_cb (void *cls,
122 * @param tc_queue Handle to newly opened queue 122 * @param tc_queue Handle to newly opened queue
123 */ 123 */
124static void 124static void
125add_queue_cb (void *cls, 125add_queue_cb(void *cls,
126 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 126 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
127 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue) 127 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue)
128{ 128{
129 LOG (GNUNET_ERROR_TYPE_DEBUG, 129 LOG(GNUNET_ERROR_TYPE_DEBUG,
130 "Got Queue!\n"); 130 "Got Queue!\n");
131 GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue, 131 GNUNET_TRANSPORT_TESTING_transport_communicator_send(tc_queue,
132 &payload, 132 &payload,
133 sizeof (payload)); 133 sizeof(payload));
134} 134}
135 135
136 136
@@ -144,9 +144,9 @@ add_queue_cb (void *cls,
144 * @param msg Received message 144 * @param msg Received message
145 */ 145 */
146void 146void
147incoming_message_cb (void *cls, 147incoming_message_cb(void *cls,
148 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 148 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
149 const struct GNUNET_MessageHeader *msg) 149 const struct GNUNET_MessageHeader *msg)
150{ 150{
151} 151}
152 152
@@ -157,35 +157,35 @@ incoming_message_cb (void *cls,
157 * @param cls Closure - Handle to configuration 157 * @param cls Closure - Handle to configuration
158 */ 158 */
159static void 159static void
160run (void *cls) 160run(void *cls)
161{ 161{
162 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 162 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
163 163
164 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 164 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
165 "transport", 165 "transport",
166 "gnunet-communicator-unix", 166 "gnunet-communicator-unix",
167 "test_communicator_1.conf", 167 "test_communicator_1.conf",
168 &communicator_available_cb, 168 &communicator_available_cb,
169 NULL, 169 NULL,
170 &queue_create_reply_cb, 170 &queue_create_reply_cb,
171 &add_queue_cb, 171 &add_queue_cb,
172 NULL, 172 NULL,
173 NULL); /* cls */ 173 NULL); /* cls */
174 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 174 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
175 "transport", 175 "transport",
176 "gnunet-communicator-unix", 176 "gnunet-communicator-unix",
177 "test_communicator_2.conf", 177 "test_communicator_2.conf",
178 &communicator_available_cb, 178 &communicator_available_cb,
179 &add_address_cb, 179 &add_address_cb,
180 NULL, 180 NULL,
181 &add_queue_cb, 181 &add_queue_cb,
182 NULL, 182 NULL,
183 NULL); /* cls */ 183 NULL); /* cls */
184} 184}
185 185
186int 186int
187main (int argc, 187main(int argc,
188 char *const *argv) 188 char *const *argv)
189{ 189{
190 char *cfg_filename; 190 char *cfg_filename;
191 char *opt_cfg_filename; 191 char *opt_cfg_filename;
@@ -195,73 +195,73 @@ main (int argc,
195 struct GNUNET_CONFIGURATION_Handle *cfg; 195 struct GNUNET_CONFIGURATION_Handle *cfg;
196 196
197 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 197 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
198 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), 198 GNUNET_GETOPT_option_cfgfile(&opt_cfg_filename),
199 GNUNET_GETOPT_option_help (NULL), 199 GNUNET_GETOPT_option_help(NULL),
200 GNUNET_GETOPT_option_loglevel (&loglev), 200 GNUNET_GETOPT_option_loglevel(&loglev),
201 GNUNET_GETOPT_option_logfile (&logfile), 201 GNUNET_GETOPT_option_logfile(&logfile),
202 GNUNET_GETOPT_OPTION_END 202 GNUNET_GETOPT_OPTION_END
203 }; 203 };
204 204
205 if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix", 205 if (GNUNET_OK != GNUNET_log_setup("test_communicator_unix",
206 loglev, 206 loglev,
207 logfile)) 207 logfile))
208 { 208 {
209 GNUNET_break (0); 209 GNUNET_break(0);
210 return GNUNET_SYSERR; 210 return GNUNET_SYSERR;
211 } 211 }
212 212
213 xdg = getenv ("XDG_CONFIG_HOME"); 213 xdg = getenv("XDG_CONFIG_HOME");
214 if (NULL != xdg) 214 if (NULL != xdg)
215 GNUNET_asprintf (&cfg_filename, 215 GNUNET_asprintf(&cfg_filename,
216 "%s%s%s", 216 "%s%s%s",
217 xdg, 217 xdg,
218 DIR_SEPARATOR_STR, 218 DIR_SEPARATOR_STR,
219 GNUNET_OS_project_data_get ()->config_file); 219 GNUNET_OS_project_data_get()->config_file);
220 else 220 else
221 cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 221 cfg_filename = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file);
222 cfg = GNUNET_CONFIGURATION_create (); 222 cfg = GNUNET_CONFIGURATION_create();
223 if (NULL != opt_cfg_filename) 223 if (NULL != opt_cfg_filename)
224 {
225 if ( (GNUNET_YES !=
226 GNUNET_DISK_file_test (opt_cfg_filename)) ||
227 (GNUNET_SYSERR ==
228 GNUNET_CONFIGURATION_load (cfg,
229 opt_cfg_filename)) )
230 { 224 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 225 if ((GNUNET_YES !=
232 _("Malformed configuration file `%s', exit ...\n"), 226 GNUNET_DISK_file_test(opt_cfg_filename)) ||
233 opt_cfg_filename); 227 (GNUNET_SYSERR ==
234 return GNUNET_SYSERR; 228 GNUNET_CONFIGURATION_load(cfg,
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 }
235 } 236 }
236 }
237 else 237 else
238 {
239 if (GNUNET_YES ==
240 GNUNET_DISK_file_test (cfg_filename))
241 {
242 if (GNUNET_SYSERR ==
243 GNUNET_CONFIGURATION_load (cfg,
244 cfg_filename))
245 {
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
247 _("Malformed configuration file `%s', exit ...\n"),
248 cfg_filename);
249 return GNUNET_SYSERR;
250 }
251 }
252 else
253 { 238 {
254 if (GNUNET_SYSERR == 239 if (GNUNET_YES ==
255 GNUNET_CONFIGURATION_load (cfg, 240 GNUNET_DISK_file_test(cfg_filename))
256 NULL)) 241 {
257 { 242 if (GNUNET_SYSERR ==
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 243 GNUNET_CONFIGURATION_load(cfg,
259 _("Malformed configuration, exit ...\n")); 244 cfg_filename))
260 return GNUNET_SYSERR; 245 {
261 } 246 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
247 _("Malformed configuration file `%s', exit ...\n"),
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 }
262 } 263 }
263 } 264 GNUNET_SCHEDULER_run(&run,
264 GNUNET_SCHEDULER_run (&run, 265 cfg);
265 cfg);
266} 266}
267 267
diff --git a/src/transport/test_http_common.c b/src/transport/test_http_common.c
index 70ad04719..251b1543a 100644
--- a/src/transport/test_http_common.c
+++ b/src/transport/test_http_common.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_http_common.c 21 * @file transport/test_http_common.c
22 * @brief base test case for common http functionality 22 * @brief base test case for common http functionality
@@ -28,124 +28,124 @@
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 {
54 GNUNET_break (0);
55 return GNUNET_NO;
56 }
57 else if ((NULL != addr->protocol) && (NULL != protocol))
58 {
59 if (0 != strcmp(addr->protocol, protocol))
60 { 53 {
61 GNUNET_break (0); 54 GNUNET_break(0);
62 return GNUNET_NO; 55 return GNUNET_NO;
63 } 56 }
64 } 57 else if ((NULL != addr->protocol) && (NULL != protocol))
58 {
59 if (0 != strcmp(addr->protocol, protocol))
60 {
61 GNUNET_break(0);
62 return GNUNET_NO;
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 {
69 GNUNET_break (0);
70 return GNUNET_NO;
71 }
72 else if ((NULL != addr->host) && (NULL != host))
73 {
74 if (0 != strcmp(addr->host, host))
75 { 68 {
76 GNUNET_break (0); 69 GNUNET_break(0);
77 return GNUNET_NO; 70 return GNUNET_NO;
78 } 71 }
79 } 72 else if ((NULL != addr->host) && (NULL != host))
73 {
74 if (0 != strcmp(addr->host, host))
75 {
76 GNUNET_break(0);
77 return GNUNET_NO;
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 {
84 GNUNET_break (0);
85 return GNUNET_NO;
86 }
87 else if ((NULL != addr->path) && (NULL != path))
88 {
89 if (0 != strcmp(addr->path, path))
90 { 83 {
91 GNUNET_break (0); 84 GNUNET_break(0);
92 return GNUNET_NO; 85 return GNUNET_NO;
93 } 86 }
94 } 87 else if ((NULL != addr->path) && (NULL != path))
88 {
89 if (0 != strcmp(addr->path, path))
90 {
91 GNUNET_break(0);
92 return GNUNET_NO;
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, "/");
@@ -157,12 +157,11 @@ test_pass_hostname ()
157 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path"); 157 check_pass("http://test.local:81/path", "http", "test.local", 81, "/path");
158 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/"); 158 check_pass("http://test.local:81/path/", "http", "test.local", 81, "/path/");
159 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more"); 159 check_pass("http://test.local:81/path/more", "http", "test.local", 81, "/path/more");
160
161} 160}
162 161
163 162
164static void 163static void
165test_pass_ipv4 () 164test_pass_ipv4()
166{ 165{
167 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, ""); 166 check_pass("http://127.0.0.1", "http", "127.0.0.1", HTTP_DEFAULT_PORT, "");
168 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, "/");
@@ -177,7 +176,7 @@ test_pass_ipv4 ()
177 176
178 177
179static void 178static void
180test_fail_ipv6 () 179test_fail_ipv6()
181{ 180{
182 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, ""); 181 check_pass("http://[::1]", "http", "[::1]", HTTP_DEFAULT_PORT, "");
183 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/"); 182 check_pass("http://[::1]/", "http", "[::1]", HTTP_DEFAULT_PORT, "/");
@@ -192,64 +191,64 @@ test_fail_ipv6 ()
192 191
193 192
194static void 193static void
195test_fail () 194test_fail()
196{ 195{
197 if (GNUNET_SYSERR == check_fail ("")) 196 if (GNUNET_SYSERR == check_fail(""))
198 GNUNET_break (0); 197 GNUNET_break(0);
199 if (GNUNET_SYSERR == check_fail ("http")) 198 if (GNUNET_SYSERR == check_fail("http"))
200 GNUNET_break (0); 199 GNUNET_break(0);
201 if (GNUNET_SYSERR == check_fail ("://")) 200 if (GNUNET_SYSERR == check_fail("://"))
202 GNUNET_break (0); 201 GNUNET_break(0);
203 if (GNUNET_SYSERR == check_fail ("http://")) 202 if (GNUNET_SYSERR == check_fail("http://"))
204 GNUNET_break (0); 203 GNUNET_break(0);
205 if (GNUNET_SYSERR == check_fail ("//localhost")) 204 if (GNUNET_SYSERR == check_fail("//localhost"))
206 GNUNET_break (0); 205 GNUNET_break(0);
207 if (GNUNET_SYSERR == check_fail ("//:80")) 206 if (GNUNET_SYSERR == check_fail("//:80"))
208 GNUNET_break (0); 207 GNUNET_break(0);
209 if (GNUNET_SYSERR == check_fail ("//:80/")) 208 if (GNUNET_SYSERR == check_fail("//:80/"))
210 GNUNET_break (0); 209 GNUNET_break(0);
211 if (GNUNET_SYSERR == check_fail ("//:80:")) 210 if (GNUNET_SYSERR == check_fail("//:80:"))
212 GNUNET_break (0); 211 GNUNET_break(0);
213 if (GNUNET_SYSERR == check_fail ("http://localhost:a/")) 212 if (GNUNET_SYSERR == check_fail("http://localhost:a/"))
214 GNUNET_break (0); 213 GNUNET_break(0);
215 if (GNUNET_SYSERR == check_fail ("http://127.0.0.1:a/")) 214 if (GNUNET_SYSERR == check_fail("http://127.0.0.1:a/"))
216 GNUNET_break (0); 215 GNUNET_break(0);
217} 216}
218 217
219 218
220int 219int
221main (int argc, char *argv[]) 220main(int argc, char *argv[])
222{ 221{
223 int ret = 0; 222 int ret = 0;
224 struct SplittedHTTPAddress * spa; 223 struct SplittedHTTPAddress * spa;
225 224
226 GNUNET_log_setup ("test", "DEBUG", NULL); 225 GNUNET_log_setup("test", "DEBUG", NULL);
227 spa = http_split_address (""); 226 spa = http_split_address("");
228 if (NULL != spa) 227 if (NULL != spa)
229 { 228 {
230 clean (spa); 229 clean(spa);
231 spa = NULL; 230 spa = NULL;
232 GNUNET_break (0); 231 GNUNET_break(0);
233 } 232 }
234 233
235 spa = http_split_address ("http://"); 234 spa = http_split_address("http://");
236 if (NULL != spa) 235 if (NULL != spa)
237 { 236 {
238 clean (spa); 237 clean(spa);
239 GNUNET_break (0); 238 GNUNET_break(0);
240 } 239 }
241 240
242 spa = http_split_address ("://"); 241 spa = http_split_address("://");
243 if (NULL != spa) 242 if (NULL != spa)
244 { 243 {
245 clean (spa); 244 clean(spa);
246 GNUNET_break (0); 245 GNUNET_break(0);
247 } 246 }
248 247
249 test_pass_hostname (); 248 test_pass_hostname();
250 test_pass_ipv4 (); 249 test_pass_ipv4();
251 test_fail_ipv6 (); 250 test_fail_ipv6();
252 test_fail (); 251 test_fail();
253 252
254 return ret; 253 return ret;
255} 254}
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index fe0840041..686938afc 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2018 GNUnet e.V. 3 Copyright (C) 2009, 2018 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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
@@ -77,7 +77,7 @@ static uint32_t max_connect_per_transport;
77struct GNUNET_TRANSPORT_PluginEnvironment env; 77struct GNUNET_TRANSPORT_PluginEnvironment env;
78 78
79/** 79/**
80 *handle for the api provided by this plugin 80 * handle for the api provided by this plugin
81 */ 81 */
82struct GNUNET_TRANSPORT_PluginFunctions *api; 82struct GNUNET_TRANSPORT_PluginFunctions *api;
83 83
@@ -120,8 +120,7 @@ unsigned int pretty_printers_running;
120 */ 120 */
121static int ok; 121static int ok;
122 122
123struct AddressWrapper 123struct AddressWrapper {
124{
125 struct AddressWrapper *next; 124 struct AddressWrapper *next;
126 125
127 struct AddressWrapper *prev; 126 struct AddressWrapper *prev;
@@ -131,165 +130,165 @@ struct AddressWrapper
131 char *addrstring; 130 char *addrstring;
132 131
133 struct GNUNET_SCHEDULER_Task *test_task; 132 struct GNUNET_SCHEDULER_Task *test_task;
134
135}; 133};
136 134
137 135
138static void 136static void
139end () 137end()
140{ 138{
141 struct AddressWrapper *w; 139 struct AddressWrapper *w;
142 int c = 0; 140 int c = 0;
141
143 ok = 0; 142 ok = 0;
144 143
145 if (NULL != timeout_endbadly) 144 if (NULL != timeout_endbadly)
146 { 145 {
147 GNUNET_SCHEDULER_cancel (timeout_endbadly); 146 GNUNET_SCHEDULER_cancel(timeout_endbadly);
148 timeout_endbadly = NULL; 147 timeout_endbadly = NULL;
149 } 148 }
150 if (NULL != api) 149 if (NULL != api)
151 GNUNET_PLUGIN_unload (libname, api); 150 GNUNET_PLUGIN_unload(libname, api);
152 151
153 while (NULL != head) 152 while (NULL != head)
154 { 153 {
155 w = head; 154 w = head;
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 155 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
157 "Plugin did not remove address `%s'\n", 156 "Plugin did not remove address `%s'\n",
158 w->addrstring); 157 w->addrstring);
159 GNUNET_CONTAINER_DLL_remove(head, tail, w); 158 GNUNET_CONTAINER_DLL_remove(head, tail, w);
160 c++; 159 c++;
161 GNUNET_HELLO_address_free(w->address); 160 GNUNET_HELLO_address_free(w->address);
162 GNUNET_free(w->addrstring); 161 GNUNET_free(w->addrstring);
163 GNUNET_free(w); 162 GNUNET_free(w);
164 } 163 }
165 if (c > 0) 164 if (c > 0)
166 { 165 {
167 GNUNET_break(0); 166 GNUNET_break(0);
168 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n", 167 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses \n",
169 c); 168 c);
170 ok = 1; 169 ok = 1;
171 } 170 }
172 171
173 GNUNET_free(libname); 172 GNUNET_free(libname);
174 libname = NULL; 173 libname = NULL;
175 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 174 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
176 stats = NULL; 175 stats = NULL;
177 176
178 if (NULL != suid_helper) 177 if (NULL != suid_helper)
179 { 178 {
180 GNUNET_HELPER_stop (suid_helper, GNUNET_NO); 179 GNUNET_HELPER_stop(suid_helper, GNUNET_NO);
181 suid_helper = NULL; 180 suid_helper = NULL;
182 } 181 }
183} 182}
184 183
185 184
186static void 185static void
187end_badly (void *cls) 186end_badly(void *cls)
188{ 187{
189 struct AddressWrapper *w; 188 struct AddressWrapper *w;
190 int c = 0; 189 int c = 0;
191 190
192 timeout_endbadly = NULL; 191 timeout_endbadly = NULL;
193 if (NULL != timeout_wait) 192 if (NULL != timeout_wait)
194 { 193 {
195 GNUNET_SCHEDULER_cancel (timeout_wait); 194 GNUNET_SCHEDULER_cancel(timeout_wait);
196 timeout_wait = NULL; 195 timeout_wait = NULL;
197 } 196 }
198 197
199 if (pretty_printers_running > 0) 198 if (pretty_printers_running > 0)
200 { 199 {
201 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 200 timeout_endbadly = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
202 &end_badly, &ok); 201 &end_badly, &ok);
203 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 202 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
204 "Have pending calls to pretty_printer ... deferring shutdown\n"); 203 "Have pending calls to pretty_printer ... deferring shutdown\n");
205 return; 204 return;
206 } 205 }
207 206
208 if (NULL != cls) 207 if (NULL != cls)
209 { 208 {
210 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
211 "Test took too long to execute, timeout .... \n"); 210 "Test took too long to execute, timeout .... \n");
212 } 211 }
213 212
214 if (NULL != libname) 213 if (NULL != libname)
215 { 214 {
216 if (NULL != api) 215 if (NULL != api)
217 GNUNET_PLUGIN_unload (libname, api); 216 GNUNET_PLUGIN_unload(libname, api);
218 GNUNET_free(libname); 217 GNUNET_free(libname);
219 libname = NULL; 218 libname = NULL;
220 } 219 }
221 220
222 while (NULL != head) 221 while (NULL != head)
223 { 222 {
224 w = head; 223 w = head;
225 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n", 224 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove address `%s'\n",
226 w->addrstring); 225 w->addrstring);
227 GNUNET_CONTAINER_DLL_remove(head, tail, w); 226 GNUNET_CONTAINER_DLL_remove(head, tail, w);
228 c++; 227 c++;
229 GNUNET_HELLO_address_free(w->address); 228 GNUNET_HELLO_address_free(w->address);
230 if (NULL != w->test_task) 229 if (NULL != w->test_task)
231 GNUNET_SCHEDULER_cancel (w->test_task); 230 GNUNET_SCHEDULER_cancel(w->test_task);
232 GNUNET_free(w->addrstring); 231 GNUNET_free(w->addrstring);
233 GNUNET_free(w); 232 GNUNET_free(w);
234 } 233 }
235 if (c > 0) 234 if (c > 0)
236 { 235 {
237 GNUNET_break(0); 236 GNUNET_break(0);
238 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n", 237 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Plugin did not remove %u addresses\n",
239 c); 238 c);
240 } 239 }
241 240
242 if (NULL != stats) 241 if (NULL != stats)
243 { 242 {
244 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 243 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
245 stats = NULL; 244 stats = NULL;
246 } 245 }
247 246
248 if (NULL != suid_helper) 247 if (NULL != suid_helper)
249 { 248 {
250 GNUNET_HELPER_stop (suid_helper, GNUNET_NO); 249 GNUNET_HELPER_stop(suid_helper, GNUNET_NO);
251 suid_helper = NULL; 250 suid_helper = NULL;
252 } 251 }
253 252
254 ok = 1; 253 ok = 1;
255} 254}
256 255
257static void 256static void
258wait_end (void *cls) 257wait_end(void *cls)
259{ 258{
260 timeout_wait = NULL; 259 timeout_wait = NULL;
261 if (0 == addresses_reported) 260 if (0 == addresses_reported)
262 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, 261 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
263 "Plugin did not report any addresses, could not check address conversion functions\n"); 262 "Plugin did not report any addresses, could not check address conversion functions\n");
264 end (); 263 end();
265} 264}
266 265
267 266
268static void 267static void
269end_badly_now () 268end_badly_now()
270{ 269{
271 if (NULL != timeout_wait) 270 if (NULL != timeout_wait)
272 { 271 {
273 GNUNET_SCHEDULER_cancel (timeout_wait); 272 GNUNET_SCHEDULER_cancel(timeout_wait);
274 timeout_wait = NULL; 273 timeout_wait = NULL;
275 } 274 }
276 if (NULL != timeout_endbadly) 275 if (NULL != timeout_endbadly)
277 { 276 {
278 GNUNET_SCHEDULER_cancel (timeout_endbadly); 277 GNUNET_SCHEDULER_cancel(timeout_endbadly);
279 timeout_endbadly = NULL; 278 timeout_endbadly = NULL;
280 } 279 }
281 timeout_endbadly = GNUNET_SCHEDULER_add_now (&end_badly, NULL ); 280 timeout_endbadly = GNUNET_SCHEDULER_add_now(&end_badly, NULL);
282} 281}
283 282
284 283
285static struct GNUNET_TIME_Relative 284static struct GNUNET_TIME_Relative
286env_receive (void *cls, 285env_receive(void *cls,
287 const struct GNUNET_HELLO_Address *address, 286 const struct GNUNET_HELLO_Address *address,
288 struct GNUNET_ATS_Session *session, 287 struct GNUNET_ATS_Session *session,
289 const struct GNUNET_MessageHeader *message) 288 const struct GNUNET_MessageHeader *message)
290{ 289{
291 /* do nothing */ 290 /* do nothing */
292 return GNUNET_TIME_relative_get_zero_ (); 291 return GNUNET_TIME_relative_get_zero_();
293} 292}
294 293
295static int got_reply; 294static int got_reply;
@@ -304,28 +303,28 @@ static int got_reply;
304 * @param res result code 303 * @param res result code
305 */ 304 */
306static void 305static void
307address_pretty_printer_cb (void *cls, const char *address, int res) 306address_pretty_printer_cb(void *cls, const char *address, int res)
308{ 307{
309 if (NULL != address) 308 if (NULL != address)
310 {
311 got_reply = GNUNET_YES;
312 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address);
313 pretty_printers_running--;
314 }
315 else
316 {
317 if (GNUNET_NO == got_reply)
318 { 309 {
310 got_reply = GNUNET_YES;
311 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Pretty address : `%s'\n", address);
319 pretty_printers_running--; 312 pretty_printers_running--;
320 GNUNET_break(0);
321 end_badly_now ();
322 } 313 }
323 } 314 else
315 {
316 if (GNUNET_NO == got_reply)
317 {
318 pretty_printers_running--;
319 GNUNET_break(0);
320 end_badly_now();
321 }
322 }
324} 323}
325 324
326 325
327static void 326static void
328test_addr_string (void *cls) 327test_addr_string(void *cls)
329{ 328{
330 struct AddressWrapper *w = cls; 329 struct AddressWrapper *w = cls;
331 void *s2a; 330 void *s2a;
@@ -333,209 +332,208 @@ test_addr_string (void *cls)
333 332
334 w->test_task = NULL; 333 w->test_task = NULL;
335 334
336 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 335 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
337 "Testing: address_to_string \n"); 336 "Testing: address_to_string \n");
338 w->addrstring = GNUNET_strdup (api->address_to_string (api, 337 w->addrstring = GNUNET_strdup(api->address_to_string(api,
339 w->address->address, 338 w->address->address,
340 w->address->address_length)); 339 w->address->address_length));
341 if (NULL == w->addrstring) 340 if (NULL == w->addrstring)
342 { 341 {
343 GNUNET_break(0); 342 GNUNET_break(0);
344 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 343 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
345 "Plugin cannot convert address to string!\n"); 344 "Plugin cannot convert address to string!\n");
346 end_badly_now (); 345 end_badly_now();
347 return; 346 return;
348 } 347 }
349 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 348 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
350 "Plugin added address `%s'\n", 349 "Plugin added address `%s'\n",
351 w->addrstring); 350 w->addrstring);
352 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 351 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
353 "Testing address_to_string: OK\n"); 352 "Testing address_to_string: OK\n");
354 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 353 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
355 "Testing: string_to_address \n"); 354 "Testing: string_to_address \n");
356 s2a = NULL; 355 s2a = NULL;
357 s2a_len = 0; 356 s2a_len = 0;
358 if ((GNUNET_OK != 357 if ((GNUNET_OK !=
359 api->string_to_address (api, w->addrstring, 358 api->string_to_address(api, w->addrstring,
360 strlen (w->addrstring) + 1, 359 strlen(w->addrstring) + 1,
361 &s2a, &s2a_len)) || 360 &s2a, &s2a_len)) ||
362 (NULL == s2a)) 361 (NULL == s2a))
363 { 362 {
364 GNUNET_break(0); 363 GNUNET_break(0);
365 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 364 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
366 "Plugin cannot convert string to address!\n"); 365 "Plugin cannot convert string to address!\n");
367 end_badly_now (); 366 end_badly_now();
368 return; 367 return;
369 } 368 }
370 369
371 /* 370 /*
372 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 371 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
373 "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len); 372 "Plugin creates `%s' %u\n",api->address_to_string (api, s2a, s2a_len), s2a_len);
374 373
375 int c1; 374 int c1;
376 for (c1 = 0; c1 < s2a_len; c1++ ) 375 for (c1 = 0; c1 < s2a_len; c1++ )
377 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]); 376 fprintf (stderr, "%u == %u\n", ((char *) s2a)[c1], ((char *) w->addr)[c1]);
378 */ 377 */
379 if (s2a_len != w->address->address_length) 378 if (s2a_len != w->address->address_length)
380 { 379 {
381 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 380 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
382 "Plugin creates different address length when converting address->string->address: %u != %u\n", 381 "Plugin creates different address length when converting address->string->address: %u != %u\n",
383 (unsigned int) w->address->address_length, 382 (unsigned int)w->address->address_length,
384 (unsigned int) s2a_len); 383 (unsigned int)s2a_len);
385 } 384 }
386 else if (0 != memcmp (s2a, w->address->address, s2a_len)) 385 else if (0 != memcmp(s2a, w->address->address, s2a_len))
387 { 386 {
388 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 387 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
389 "Plugin creates different address length when converting back and forth %i!\n", 388 "Plugin creates different address length when converting back and forth %i!\n",
390 memcmp (s2a, 389 memcmp(s2a,
391 w->address->address, 390 w->address->address,
392 s2a_len)); 391 s2a_len));
393 } 392 }
394 else 393 else
395 { 394 {
396 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 395 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
397 "Testing string_to_address: OK\n"); 396 "Testing string_to_address: OK\n");
398 } 397 }
399 GNUNET_free(s2a); 398 GNUNET_free(s2a);
400 399
401 pretty_printers_running++; 400 pretty_printers_running++;
402 api->address_pretty_printer (api->cls, 401 api->address_pretty_printer(api->cls,
403 w->address->transport_name, 402 w->address->transport_name,
404 w->address->address, 403 w->address->address,
405 w->address->address_length, 404 w->address->address_length,
406 GNUNET_YES, 405 GNUNET_YES,
407 GNUNET_TIME_UNIT_MINUTES, 406 GNUNET_TIME_UNIT_MINUTES,
408 &address_pretty_printer_cb, w); 407 &address_pretty_printer_cb, w);
409 408
410 if (GNUNET_OK != 409 if (GNUNET_OK !=
411 api->check_address (api->cls, 410 api->check_address(api->cls,
412 w->address->address, 411 w->address->address,
413 w->address->address_length)) 412 w->address->address_length))
414 { 413 {
415 GNUNET_break (0); 414 GNUNET_break(0);
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 415 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
417 "Plugin refuses added address!\n"); 416 "Plugin refuses added address!\n");
418 end_badly_now (); 417 end_badly_now();
419 return; 418 return;
420 } 419 }
421 if (NULL != timeout_wait) 420 if (NULL != timeout_wait)
422 { 421 {
423 GNUNET_SCHEDULER_cancel (timeout_wait); 422 GNUNET_SCHEDULER_cancel(timeout_wait);
424 timeout_wait = NULL; 423 timeout_wait = NULL;
425 } 424 }
426 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL); 425 timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL);
427} 426}
428 427
429 428
430static void 429static void
431env_notify_address (void *cls, 430env_notify_address(void *cls,
432 int add_remove, 431 int add_remove,
433 const struct GNUNET_HELLO_Address *address) 432 const struct GNUNET_HELLO_Address *address)
434{ 433{
435 struct AddressWrapper *w; 434 struct AddressWrapper *w;
436 struct AddressWrapper *wtmp; 435 struct AddressWrapper *wtmp;
437 436
438 if (GNUNET_YES == add_remove) 437 if (GNUNET_YES == add_remove)
439 {
440 addresses_reported++;
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
442 "Adding address of length %u\n",
443 (unsigned int) address->address_length);
444
445 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
446 {
447 if ((address->address_length == wtmp->address->address_length) &&
448 (0 == memcmp (address->address, wtmp->address->address, address->address_length)))
449 {
450 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
451 "Duplicate address notification .... \n");
452 return;
453 }
454 }
455
456 w = GNUNET_new (struct AddressWrapper);
457 w->address = GNUNET_HELLO_address_copy (address);
458 GNUNET_CONTAINER_DLL_insert (head, tail, w);
459 got_reply = GNUNET_NO;
460 w->test_task = GNUNET_SCHEDULER_add_now (&test_addr_string,
461 w);
462 return;
463 }
464
465 if (GNUNET_NO == add_remove)
466 {
467 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
468 "Removing address of length %u\n",
469 (unsigned int) address->address_length);
470 w = head;
471 while (NULL != w)
472 { 438 {
473 if ((address->address_length == w->address->address_length) && 439 addresses_reported++;
474 (0 == memcmp (w->address->address, address->address, address->address_length))) 440 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
475 { 441 "Adding address of length %u\n",
476 break; 442 (unsigned int)address->address_length);
477 } 443
478 w = w->next; 444 for (wtmp = head; NULL != wtmp; wtmp = wtmp->next)
445 {
446 if ((address->address_length == wtmp->address->address_length) &&
447 (0 == memcmp(address->address, wtmp->address->address, address->address_length)))
448 {
449 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
450 "Duplicate address notification .... \n");
451 return;
452 }
453 }
454
455 w = GNUNET_new(struct AddressWrapper);
456 w->address = GNUNET_HELLO_address_copy(address);
457 GNUNET_CONTAINER_DLL_insert(head, tail, w);
458 got_reply = GNUNET_NO;
459 w->test_task = GNUNET_SCHEDULER_add_now(&test_addr_string,
460 w);
461 return;
479 } 462 }
480 463
481 if (w == NULL) 464 if (GNUNET_NO == add_remove)
482 { 465 {
483 GNUNET_break(0); 466 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
484 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 467 "Removing address of length %u\n",
485 "Plugin removes address never added!\n"); 468 (unsigned int)address->address_length);
486 end_badly_now (); 469 w = head;
470 while (NULL != w)
471 {
472 if ((address->address_length == w->address->address_length) &&
473 (0 == memcmp(w->address->address, address->address, address->address_length)))
474 {
475 break;
476 }
477 w = w->next;
478 }
479
480 if (w == NULL)
481 {
482 GNUNET_break(0);
483 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
484 "Plugin removes address never added!\n");
485 end_badly_now();
486 return;
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);
487 return; 493 return;
488 } 494 }
489
490 GNUNET_CONTAINER_DLL_remove(head, tail, w);
491 GNUNET_HELLO_address_free (w->address);
492 GNUNET_free(w->addrstring);
493 GNUNET_free(w);
494 return;
495 }
496 GNUNET_break(0); 495 GNUNET_break(0);
497 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 496 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
498 "Invalid operation: %u\n", 497 "Invalid operation: %u\n",
499 add_remove); 498 add_remove);
500 end_badly_now (); 499 end_badly_now();
501} 500}
502 501
503 502
504static enum GNUNET_NetworkType 503static enum GNUNET_NetworkType
505env_get_address_type (void *cls, 504env_get_address_type(void *cls,
506 const struct sockaddr *addr, 505 const struct sockaddr *addr,
507 size_t addrlen) 506 size_t addrlen)
508{ 507{
509 return GNUNET_NT_LOOPBACK; 508 return GNUNET_NT_LOOPBACK;
510} 509}
511 510
512 511
513static const struct GNUNET_MessageHeader * 512static const struct GNUNET_MessageHeader *
514env_get_our_hello () 513env_get_our_hello()
515{ 514{
516 return (const struct GNUNET_MessageHeader *) hello; 515 return (const struct GNUNET_MessageHeader *)hello;
517} 516}
518 517
519 518
520static void 519static void
521env_session_end (void *cls, 520env_session_end(void *cls,
522 const struct GNUNET_HELLO_Address *address, 521 const struct GNUNET_HELLO_Address *address,
523 struct GNUNET_ATS_Session *session) 522 struct GNUNET_ATS_Session *session)
524{ 523{
525
526} 524}
527 525
528 526
529static void 527static void
530env_update_distance (void *cls, 528env_update_distance(void *cls,
531 const struct GNUNET_HELLO_Address *address, 529 const struct GNUNET_HELLO_Address *address,
532 uint32_t distance) 530 uint32_t distance)
533{ 531{
534} 532}
535 533
536 534
537static void 535static void
538setup_plugin_environment () 536setup_plugin_environment()
539{ 537{
540 env.cfg = cfg; 538 env.cfg = cfg;
541 env.cls = &env; 539 env.cls = &env;
@@ -552,8 +550,8 @@ setup_plugin_environment ()
552 550
553 551
554static int 552static int
555handle_helper_message (void *cls, 553handle_helper_message(void *cls,
556 const struct GNUNET_MessageHeader *hdr) 554 const struct GNUNET_MessageHeader *hdr)
557{ 555{
558 return GNUNET_OK; 556 return GNUNET_OK;
559} 557}
@@ -566,10 +564,10 @@ handle_helper_message (void *cls,
566 * @param c configuration to use 564 * @param c configuration to use
567 */ 565 */
568static void 566static void
569run (void *cls, 567run(void *cls,
570 char * const *args, 568 char * const *args,
571 const char *cfgfile, 569 const char *cfgfile,
572 const struct GNUNET_CONFIGURATION_Handle *c) 570 const struct GNUNET_CONFIGURATION_Handle *c)
573{ 571{
574 char * const *argv = cls; 572 char * const *argv = cls;
575 unsigned long long tneigh; 573 unsigned long long tneigh;
@@ -577,173 +575,173 @@ run (void *cls,
577 char *plugin; 575 char *plugin;
578 char *sep; 576 char *sep;
579 577
580 timeout_endbadly = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 578 timeout_endbadly = GNUNET_SCHEDULER_add_delayed(TIMEOUT,
581 &end_badly, 579 &end_badly,
582 &ok); 580 &ok);
583 cfg = c; 581 cfg = c;
584 /* parse configuration */ 582 /* parse configuration */
585 if ( (GNUNET_OK != 583 if ((GNUNET_OK !=
586 GNUNET_CONFIGURATION_get_value_number (c, 584 GNUNET_CONFIGURATION_get_value_number(c,
587 "TRANSPORT", 585 "TRANSPORT",
588 "NEIGHBOUR_LIMIT", 586 "NEIGHBOUR_LIMIT",
589 &tneigh)) || 587 &tneigh)) ||
590 (GNUNET_OK != 588 (GNUNET_OK !=
591 GNUNET_CONFIGURATION_get_value_filename (c, 589 GNUNET_CONFIGURATION_get_value_filename(c,
592 "PEER", 590 "PEER",
593 "PRIVATE_KEY", 591 "PRIVATE_KEY",
594 &keyfile))) 592 &keyfile)))
595 { 593 {
596 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 594 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
597 "Transport service is lacking key configuration settings. Exiting.\n"); 595 "Transport service is lacking key configuration settings. Exiting.\n");
598 return; 596 return;
599 } 597 }
600 598
601 if (NULL == (stats = GNUNET_STATISTICS_create ("transport", 599 if (NULL == (stats = GNUNET_STATISTICS_create("transport",
602 cfg))) 600 cfg)))
603 { 601 {
604 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 602 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
605 "Could not create statistics. Exiting.\n"); 603 "Could not create statistics. Exiting.\n");
606 GNUNET_free(keyfile); 604 GNUNET_free(keyfile);
607 end_badly_now (); 605 end_badly_now();
608 return; 606 return;
609 } 607 }
610 608
611 if (GNUNET_OK != GNUNET_DISK_file_test (HOSTKEY_FILE)) 609 if (GNUNET_OK != GNUNET_DISK_file_test(HOSTKEY_FILE))
612 { 610 {
613 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 611 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
614 "Hostkey `%s' missing. Exiting.\n", 612 "Hostkey `%s' missing. Exiting.\n",
615 HOSTKEY_FILE); 613 HOSTKEY_FILE);
616 GNUNET_free(keyfile); 614 GNUNET_free(keyfile);
617 end_badly_now (); 615 end_badly_now();
618 return; 616 return;
619 } 617 }
620 618
621 if (GNUNET_OK != 619 if (GNUNET_OK !=
622 GNUNET_DISK_directory_create_for_file (keyfile)) 620 GNUNET_DISK_directory_create_for_file(keyfile))
623 { 621 {
624 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 622 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
625 "Could not create a directory for hostkey `%s'. Exiting.\n", 623 "Could not create a directory for hostkey `%s'. Exiting.\n",
626 keyfile); 624 keyfile);
627 GNUNET_free(keyfile); 625 GNUNET_free(keyfile);
628 end_badly_now (); 626 end_badly_now();
629 return; 627 return;
630 } 628 }
631 629
632 if (GNUNET_OK != 630 if (GNUNET_OK !=
633 GNUNET_DISK_file_copy (HOSTKEY_FILE, 631 GNUNET_DISK_file_copy(HOSTKEY_FILE,
634 keyfile)) 632 keyfile))
635 { 633 {
636 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 634 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
637 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n", 635 "Could not copy hostkey `%s' to destination `%s'. Exiting.\n",
638 HOSTKEY_FILE, 636 HOSTKEY_FILE,
639 keyfile); 637 keyfile);
640 GNUNET_free(keyfile); 638 GNUNET_free(keyfile);
641 end_badly_now (); 639 end_badly_now();
642 return; 640 return;
643 } 641 }
644 642
645 max_connect_per_transport = (uint32_t) tneigh; 643 max_connect_per_transport = (uint32_t)tneigh;
646 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); 644 my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile);
647 GNUNET_free(keyfile); 645 GNUNET_free(keyfile);
648 if (NULL == my_private_key) 646 if (NULL == my_private_key)
649 { 647 {
650 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 648 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
651 "Could not access hostkey. Exiting.\n"); 649 "Could not access hostkey. Exiting.\n");
652 end_badly_now (); 650 end_badly_now();
653 return; 651 return;
654 } 652 }
655 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_identity.public_key); 653 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key, &my_identity.public_key);
656 654
657 hello = GNUNET_HELLO_create (&my_identity.public_key, NULL, NULL, GNUNET_NO); 655 hello = GNUNET_HELLO_create(&my_identity.public_key, NULL, NULL, GNUNET_NO);
658 656
659 /* load plugins... */ 657 /* load plugins... */
660 setup_plugin_environment (); 658 setup_plugin_environment();
661 659
662 GNUNET_assert(strlen (argv[0]) > strlen ("test_plugin_")); 660 GNUNET_assert(strlen(argv[0]) > strlen("test_plugin_"));
663 plugin = strstr (argv[0], "test_plugin_"); 661 plugin = strstr(argv[0], "test_plugin_");
664 sep = strrchr (argv[0], '.'); 662 sep = strrchr(argv[0], '.');
665 if (NULL == plugin) 663 if (NULL == plugin)
666 { 664 {
667 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n"); 665 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Not a valid test name\n");
668 end_badly_now (); 666 end_badly_now();
669 return; 667 return;
670 } 668 }
671 plugin += strlen ("test_plugin_"); 669 plugin += strlen("test_plugin_");
672 if (NULL != sep) 670 if (NULL != sep)
673 sep[0] = '\0'; 671 sep[0] = '\0';
674 672
675 /* Hack for WLAN: start a second helper */ 673 /* Hack for WLAN: start a second helper */
676 if (0 == strcmp (plugin, "wlan")) 674 if (0 == strcmp(plugin, "wlan"))
677 { 675 {
678 char * helper_argv[3]; 676 char * helper_argv[3];
679 helper_argv[0] = (char *) "gnunet-helper-transport-wlan-dummy"; 677 helper_argv[0] = (char *)"gnunet-helper-transport-wlan-dummy";
680 helper_argv[1] = (char *) "2"; 678 helper_argv[1] = (char *)"2";
681 helper_argv[2] = NULL; 679 helper_argv[2] = NULL;
682 suid_helper = GNUNET_HELPER_start (GNUNET_NO, 680 suid_helper = GNUNET_HELPER_start(GNUNET_NO,
683 "gnunet-helper-transport-wlan-dummy", helper_argv, 681 "gnunet-helper-transport-wlan-dummy", helper_argv,
684 &handle_helper_message, NULL, NULL ); 682 &handle_helper_message, NULL, NULL);
685 } 683 }
686 684
687 /* Loading plugin */ 685 /* Loading plugin */
688 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin); 686 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Loading transport plugin %s\n", plugin);
689 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", plugin); 687 GNUNET_asprintf(&libname, "libgnunet_plugin_transport_%s", plugin);
690 api = GNUNET_PLUGIN_load (libname, &env); 688 api = GNUNET_PLUGIN_load(libname, &env);
691 if (NULL == api) 689 if (NULL == api)
692 { 690 {
693 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 691 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
694 "Failed to load transport plugin for %s\n", plugin); 692 "Failed to load transport plugin for %s\n", plugin);
695 end_badly_now (); 693 end_badly_now();
696 return; 694 return;
697 } 695 }
698 696
699 timeout_wait = GNUNET_SCHEDULER_add_delayed (WAIT, &wait_end, NULL ); 697 timeout_wait = GNUNET_SCHEDULER_add_delayed(WAIT, &wait_end, NULL);
700 698
701 /* Check if all functions are implemented */ 699 /* Check if all functions are implemented */
702 if (NULL == api->address_pretty_printer) 700 if (NULL == api->address_pretty_printer)
703 { 701 {
704 GNUNET_break(0); 702 GNUNET_break(0);
705 end_badly_now (); 703 end_badly_now();
706 return; 704 return;
707 } 705 }
708 if (NULL == api->address_to_string) 706 if (NULL == api->address_to_string)
709 { 707 {
710 GNUNET_break(0); 708 GNUNET_break(0);
711 end_badly_now (); 709 end_badly_now();
712 return; 710 return;
713 } 711 }
714 GNUNET_assert(NULL != api->check_address); 712 GNUNET_assert(NULL != api->check_address);
715 if (NULL == api->check_address) 713 if (NULL == api->check_address)
716 { 714 {
717 GNUNET_break(0); 715 GNUNET_break(0);
718 end_badly_now (); 716 end_badly_now();
719 return; 717 return;
720 } 718 }
721 GNUNET_assert(NULL != api->disconnect_peer); 719 GNUNET_assert(NULL != api->disconnect_peer);
722 if (NULL == api->disconnect_peer) 720 if (NULL == api->disconnect_peer)
723 { 721 {
724 GNUNET_break(0); 722 GNUNET_break(0);
725 end_badly_now (); 723 end_badly_now();
726 return; 724 return;
727 } 725 }
728 GNUNET_assert(NULL != api->get_session); 726 GNUNET_assert(NULL != api->get_session);
729 if (NULL == api->get_session) 727 if (NULL == api->get_session)
730 { 728 {
731 GNUNET_break(0); 729 GNUNET_break(0);
732 end_badly_now (); 730 end_badly_now();
733 return; 731 return;
734 } 732 }
735 if (NULL == api->address_pretty_printer) 733 if (NULL == api->address_pretty_printer)
736 { 734 {
737 GNUNET_break(0); 735 GNUNET_break(0);
738 end_badly_now (); 736 end_badly_now();
739 return; 737 return;
740 } 738 }
741 if (NULL == api->string_to_address) 739 if (NULL == api->string_to_address)
742 { 740 {
743 GNUNET_break(0); 741 GNUNET_break(0);
744 end_badly_now (); 742 end_badly_now();
745 return; 743 return;
746 } 744 }
747} 745}
748 746
749 747
@@ -755,8 +753,8 @@ run (void *cls,
755 * @return 0 ok, 1 on error 753 * @return 0 ok, 1 on error
756 */ 754 */
757int 755int
758main (int argc, 756main(int argc,
759 char * const *argv) 757 char * const *argv)
760{ 758{
761 static struct GNUNET_GETOPT_CommandLineOption options[] = { 759 static struct GNUNET_GETOPT_CommandLineOption options[] = {
762 GNUNET_GETOPT_OPTION_END 760 GNUNET_GETOPT_OPTION_END
@@ -769,18 +767,18 @@ main (int argc,
769 NULL 767 NULL
770 }; 768 };
771 769
772 GNUNET_log_setup ("test-plugin-transport", 770 GNUNET_log_setup("test-plugin-transport",
773 "WARNING", 771 "WARNING",
774 NULL); 772 NULL);
775 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf", 773 GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf",
776 "GNUNET_TEST_HOME"); 774 "GNUNET_TEST_HOME");
777 ok = 1; /* set to fail */ 775 ok = 1; /* set to fail */
778 ret = 776 ret =
779 (GNUNET_OK 777 (GNUNET_OK
780 == GNUNET_PROGRAM_run (3, argv_prog, "test-plugin-transport", 778 == GNUNET_PROGRAM_run(3, argv_prog, "test-plugin-transport",
781 "testcase", options, &run, (void *) argv)) ? ok : 1; 779 "testcase", options, &run, (void *)argv)) ? ok : 1;
782 GNUNET_DISK_purge_cfg_dir ("test_plugin_transport_data.conf", 780 GNUNET_DISK_purge_cfg_dir("test_plugin_transport_data.conf",
783 "GNUNET_TEST_HOME"); 781 "GNUNET_TEST_HOME");
784 return ret; 782 return ret;
785} 783}
786 784
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 2c6ce8e5f..092935944 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_quota_compliance.c 21 * @file transport/test_quota_compliance.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -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,118 +61,117 @@ 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
122 ret = (iter * iter * iter) % 60000; 122 ret = (iter * iter * iter) % 60000;
123 ret += sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage); 123 ret += sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
124 return ret; 124 return ret;
125} 125}
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 134 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type))
135 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type))
136 return; 135 return;
137 total_bytes_recv += ntohs (hdr->header.size); 136 total_bytes_recv += ntohs(hdr->header.size);
138 137
139 { 138 {
140 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 139 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id));
141 140
142 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 141 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
143 "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",
144 receiver->no, 143 receiver->no,
145 ps, 144 ps,
146 ntohl (hdr->num), 145 ntohl(hdr->num),
147 ntohs (hdr->header.size), 146 ntohs(hdr->header.size),
148 GNUNET_i2s (sender)); 147 GNUNET_i2s(sender));
149 GNUNET_free (ps); 148 GNUNET_free(ps);
150 } 149 }
151} 150}
152 151
153 152
154static void 153static void
155measure (void *cls) 154measure(void *cls)
156{ 155{
157 static int counter; 156 static int counter;
158 157
159 measure_task = NULL; 158 measure_task = NULL;
160 counter++; 159 counter++;
161 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) 160 if ((DURATION.rel_value_us / 1000 / 1000LL) < counter)
162 { 161 {
163 fprintf (stderr, "%s", ".\n"); 162 fprintf(stderr, "%s", ".\n");
164 GNUNET_SCHEDULER_shutdown (); 163 GNUNET_SCHEDULER_shutdown();
165 return; 164 return;
166 } 165 }
167 fprintf (stderr, "%s", "."); 166 fprintf(stderr, "%s", ".");
168 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 167 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
169 &measure, 168 &measure,
170 NULL); 169 NULL);
171} 170}
172 171
173 172
174static void 173static void
175start_task (void *cls) 174start_task(void *cls)
176{ 175{
177 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 176 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
178 .num_messages = TOTAL_MSGS, 177 .num_messages = TOTAL_MSGS,
@@ -180,71 +179,71 @@ start_task (void *cls)
180 }; 179 };
181 180
182 sc.ccc = ccc; 181 sc.ccc = ccc;
183 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 182 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
184 &measure, 183 &measure,
185 NULL); 184 NULL);
186 start_time = GNUNET_TIME_absolute_get (); 185 start_time = GNUNET_TIME_absolute_get();
187 GNUNET_SCHEDULER_add_now (&GNUNET_TRANSPORT_TESTING_simple_send, 186 GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send,
188 &sc); 187 &sc);
189} 188}
190 189
191 190
192static char * 191static char *
193generate_config (const char *cfg_file, 192generate_config(const char *cfg_file,
194 unsigned long long quota_in, 193 unsigned long long quota_in,
195 unsigned long long quota_out) 194 unsigned long long quota_out)
196{ 195{
197 char *in_name; 196 char *in_name;
198 char *out_name; 197 char *out_name;
199 char *fname = NULL; 198 char *fname = NULL;
200 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); 199 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create();
201 200
202 GNUNET_assert (GNUNET_OK == 201 GNUNET_assert(GNUNET_OK ==
203 GNUNET_CONFIGURATION_load (cfg, 202 GNUNET_CONFIGURATION_load(cfg,
204 cfg_file)); 203 cfg_file));
205 GNUNET_asprintf (&fname, 204 GNUNET_asprintf(&fname,
206 "q_in_%llu_q_out_%llu_%s", 205 "q_in_%llu_q_out_%llu_%s",
207 quota_in, 206 quota_in,
208 quota_out, 207 quota_out,
209 cfg_file); 208 cfg_file);
210 GNUNET_CONFIGURATION_set_value_string (cfg, 209 GNUNET_CONFIGURATION_set_value_string(cfg,
211 "PATHS", 210 "PATHS",
212 "DEFAULTCONFIG", 211 "DEFAULTCONFIG",
213 fname); 212 fname);
214 for (int c = 0; c < GNUNET_NT_COUNT; c++) 213 for (int c = 0; c < GNUNET_NT_COUNT; c++)
215 { 214 {
216 GNUNET_asprintf (&in_name, 215 GNUNET_asprintf(&in_name,
217 "%s_QUOTA_IN", 216 "%s_QUOTA_IN",
218 GNUNET_NT_to_string (c)); 217 GNUNET_NT_to_string(c));
219 GNUNET_asprintf (&out_name, 218 GNUNET_asprintf(&out_name,
220 "%s_QUOTA_OUT", 219 "%s_QUOTA_OUT",
221 GNUNET_NT_to_string (c)); 220 GNUNET_NT_to_string(c));
222 GNUNET_CONFIGURATION_set_value_number (cfg, 221 GNUNET_CONFIGURATION_set_value_number(cfg,
223 "ats", 222 "ats",
224 in_name, 223 in_name,
225 quota_in); 224 quota_in);
226 GNUNET_CONFIGURATION_set_value_number (cfg, 225 GNUNET_CONFIGURATION_set_value_number(cfg,
227 "ats", 226 "ats",
228 out_name, 227 out_name,
229 quota_out); 228 quota_out);
230 GNUNET_free (in_name); 229 GNUNET_free(in_name);
231 GNUNET_free (out_name); 230 GNUNET_free(out_name);
232 } 231 }
233 GNUNET_assert (GNUNET_OK == 232 GNUNET_assert(GNUNET_OK ==
234 GNUNET_CONFIGURATION_write (cfg, 233 GNUNET_CONFIGURATION_write(cfg,
235 fname)); 234 fname));
236 GNUNET_CONFIGURATION_destroy (cfg); 235 GNUNET_CONFIGURATION_destroy(cfg);
237 return fname; 236 return fname;
238} 237}
239 238
240 239
241static int 240static int
242check (void *cls, 241check(void *cls,
243 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 242 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
244 const char *test_plugin_, 243 const char *test_plugin_,
245 const char *test_name_, 244 const char *test_name_,
246 unsigned int num_peers, 245 unsigned int num_peers,
247 char *cfg_files[]) 246 char *cfg_files[])
248{ 247{
249 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 248 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
250 .connect_continuation = &start_task, 249 .connect_continuation = &start_task,
@@ -255,65 +254,66 @@ check (void *cls,
255 .shutdown_task = &custom_shutdown, 254 .shutdown_task = &custom_shutdown,
256 .timeout = TIMEOUT 255 .timeout = TIMEOUT
257 }; 256 };
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 {
305 GNUNET_break (0);
306 return 1;
307 }
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])) )
312 { 304 {
313 GNUNET_DISK_directory_remove (gen_cfgs[i]); 305 GNUNET_break(0);
314 GNUNET_free (gen_cfgs[i]); 306 return 1;
307 }
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])))
312 {
313 GNUNET_DISK_directory_remove(gen_cfgs[i]);
314 GNUNET_free(gen_cfgs[i]);
315 }
315 } 316 }
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 4cc63766e..ffb6baefe 100644
--- a/src/transport/test_transport_address_switch.c
+++ b/src/transport/test_transport_address_switch.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V. 3 Copyright (C) 2009, 2010, 2011, 2016 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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,8 +62,7 @@ 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{
67 struct GNUNET_STATISTICS_Handle *stat; 66 struct GNUNET_STATISTICS_Handle *stat;
68 67
69 unsigned int addresses_avail; 68 unsigned int addresses_avail;
@@ -84,16 +83,16 @@ static unsigned long long bytes_recv_after_switch;
84 83
85 84
86static int 85static int
87stat_start_attempt_cb (void *cls, 86stat_start_attempt_cb(void *cls,
88 const char *subsystem, 87 const char *subsystem,
89 const char *name, 88 const char *name,
90 uint64_t value, 89 uint64_t value,
91 int is_persistent) 90 int is_persistent)
92{ 91{
93 struct PeerStats *stat = cls; 92 struct PeerStats *stat = cls;
94 93
95 stat->switch_attempts++; 94 stat->switch_attempts++;
96 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat); 95 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch attempted (%p)", stat);
97 bytes_recv_after_switch = 0; 96 bytes_recv_after_switch = 0;
98 bytes_sent_after_switch = 0; 97 bytes_sent_after_switch = 0;
99 98
@@ -102,26 +101,26 @@ stat_start_attempt_cb (void *cls,
102 101
103 102
104static int 103static int
105stat_success_attempt_cb (void *cls, 104stat_success_attempt_cb(void *cls,
106 const char *subsystem, 105 const char *subsystem,
107 const char *name, 106 const char *name,
108 uint64_t value, 107 uint64_t value,
109 int is_persistent) 108 int is_persistent)
110{ 109{
111 struct PeerStats *stat = cls; 110 struct PeerStats *stat = cls;
112 111
113 stat->switch_success++; 112 stat->switch_success++;
114 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat); 113 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Switch succeeded (%p)", stat);
115 return GNUNET_OK; 114 return GNUNET_OK;
116} 115}
117 116
118 117
119static int 118static int
120stat_fail_attempt_cb (void *cls, 119stat_fail_attempt_cb(void *cls,
121 const char *subsystem, 120 const char *subsystem,
122 const char *name, 121 const char *name,
123 uint64_t value, 122 uint64_t value,
124 int is_persistent) 123 int is_persistent)
125{ 124{
126 struct PeerStats *stat = cls; 125 struct PeerStats *stat = cls;
127 126
@@ -129,17 +128,17 @@ stat_fail_attempt_cb (void *cls,
129 return GNUNET_OK; 128 return GNUNET_OK;
130 129
131 stat->switch_fail++; 130 stat->switch_fail++;
132 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat); 131 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Switch failed (%p)", stat);
133 return GNUNET_OK; 132 return GNUNET_OK;
134} 133}
135 134
136 135
137static int 136static int
138stat_addresses_available (void *cls, 137stat_addresses_available(void *cls,
139 const char *subsystem, 138 const char *subsystem,
140 const char *name, 139 const char *name,
141 uint64_t value, 140 uint64_t value,
142 int is_persistent) 141 int is_persistent)
143{ 142{
144 struct PeerStats *stat = cls; 143 struct PeerStats *stat = cls;
145 144
@@ -151,9 +150,7 @@ stat_addresses_available (void *cls,
151/** 150/**
152 * List of statistics entries we care about. 151 * List of statistics entries we care about.
153 */ 152 */
154static struct WatchEntry 153static struct WatchEntry {
155{
156
157 /** 154 /**
158 * Name of the statistic we watch. 155 * Name of the statistic we watch.
159 */ 156 */
@@ -164,115 +161,115 @@ static struct WatchEntry
164 */ 161 */
165 GNUNET_STATISTICS_Iterator stat_handler; 162 GNUNET_STATISTICS_Iterator stat_handler;
166} watches[] = 163} watches[] =
167 {{"# Attempts to switch addresses", &stat_start_attempt_cb}, 164{ { "# Attempts to switch addresses", &stat_start_attempt_cb },
168 {"# Successful attempts to switch addresses", &stat_success_attempt_cb}, 165 { "# Successful attempts to switch addresses", &stat_success_attempt_cb },
169 {"# Failed attempts to switch addresses (failed to send CONNECT CONT)", 166 { "# Failed attempts to switch addresses (failed to send CONNECT CONT)",
170 &stat_fail_attempt_cb}, 167 &stat_fail_attempt_cb },
171 {"# Failed attempts to switch addresses (failed to send CONNECT)", 168 { "# Failed attempts to switch addresses (failed to send CONNECT)",
172 &stat_fail_attempt_cb}, 169 &stat_fail_attempt_cb },
173 {"# Failed attempts to switch addresses (no response)", 170 { "# Failed attempts to switch addresses (no response)",
174 &stat_fail_attempt_cb}, 171 &stat_fail_attempt_cb },
175 {"# transport addresses", &stat_addresses_available}, 172 { "# transport addresses", &stat_addresses_available },
176 {NULL, NULL}}; 173 { NULL, NULL } };
177 174
178 175
179static void 176static void
180custom_shutdown (void *cls) 177custom_shutdown(void *cls)
181{ 178{
182 int result; 179 int result;
183 180
184 if (NULL != measure_task) 181 if (NULL != measure_task)
185 { 182 {
186 GNUNET_SCHEDULER_cancel (measure_task); 183 GNUNET_SCHEDULER_cancel(measure_task);
187 measure_task = NULL; 184 measure_task = NULL;
188 } 185 }
189 if (0 == stats[0].switch_attempts + stats[1].switch_attempts) 186 if (0 == stats[0].switch_attempts + stats[1].switch_attempts)
190 { 187 {
191 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 188 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
192 "Test did not work, as peers didn't switch (flawed testcase)!\n"); 189 "Test did not work, as peers didn't switch (flawed testcase)!\n");
193 ccc->global_ret = 77; 190 ccc->global_ret = 77;
194 } 191 }
195 else 192 else
196 { 193 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 194 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
198 "Fail (timeout)! No transmission after switch! Stopping peers\n"); 195 "Fail (timeout)! No transmission after switch! Stopping peers\n");
199 ccc->global_ret = 77; /* GNUNET_SYSERR; */ 196 ccc->global_ret = 77; /* GNUNET_SYSERR; */
200 } 197 }
201 198
202 /* stop statistics */ 199 /* stop statistics */
203 for (unsigned int i = 0; i < 2; i++) 200 for (unsigned int i = 0; i < 2; i++)
204 {
205 if (NULL != stats[i].stat)
206 { 201 {
207 for (unsigned int j = 0; NULL != watches[j].stat_name; j++) 202 if (NULL != stats[i].stat)
208 GNUNET_assert (GNUNET_OK == 203 {
209 GNUNET_STATISTICS_watch_cancel (stats[i].stat, 204 for (unsigned int j = 0; NULL != watches[j].stat_name; j++)
210 "transport", 205 GNUNET_assert(GNUNET_OK ==
211 watches[j].stat_name, 206 GNUNET_STATISTICS_watch_cancel(stats[i].stat,
212 watches[j].stat_handler, 207 "transport",
213 &stats[i])); 208 watches[j].stat_name,
214 GNUNET_STATISTICS_destroy (stats[i].stat, GNUNET_NO); 209 watches[j].stat_handler,
215 stats[i].stat = NULL; 210 &stats[i]));
211 GNUNET_STATISTICS_destroy(stats[i].stat, GNUNET_NO);
212 stats[i].stat = NULL;
213 }
216 } 214 }
217 }
218 215
219 result = 0; 216 result = 0;
220 fprintf (stderr, "\n"); 217 fprintf(stderr, "\n");
221 if (stats[0].switch_attempts > 0) 218 if (stats[0].switch_attempts > 0)
222 {
223 fprintf (
224 stderr,
225 "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n",
226 stats[0].switch_attempts,
227 stats[0].switch_success,
228 stats[0].switch_fail);
229 if (stats[0].switch_success != stats[0].switch_attempts)
230 { 219 {
231 GNUNET_break (0); 220 fprintf(
232 result++; 221 stderr,
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 }
233 } 231 }
234 }
235 else if (stats[0].addresses_avail > 1) 232 else if (stats[0].addresses_avail > 1)
236 { 233 {
237 fprintf (stderr, 234 fprintf(stderr,
238 "Peer 1 had %u addresses available, but did not try to switch\n", 235 "Peer 1 had %u addresses available, but did not try to switch\n",
239 stats[0].addresses_avail); 236 stats[0].addresses_avail);
240 } 237 }
241 if (stats[1].switch_attempts > 0) 238 if (stats[1].switch_attempts > 0)
242 {
243 fprintf (
244 stderr,
245 "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n",
246 stats[1].switch_attempts,
247 stats[1].switch_success,
248 stats[1].switch_fail);
249 if (stats[1].switch_success != stats[1].switch_attempts)
250 { 239 {
251 GNUNET_break (0); 240 fprintf(
252 result++; 241 stderr,
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 }
253 } 251 }
254 }
255 else if (stats[1].addresses_avail > 1) 252 else if (stats[1].addresses_avail > 1)
256 { 253 {
257 fprintf (stderr, 254 fprintf(stderr,
258 "Peer 2 had %u addresses available, but did not try to switch\n", 255 "Peer 2 had %u addresses available, but did not try to switch\n",
259 stats[1].addresses_avail); 256 stats[1].addresses_avail);
260 } 257 }
261 258
262 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 259 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
263 (bytes_sent_after_switch == 0)) 260 (bytes_sent_after_switch == 0))
264 { 261 {
265 fprintf (stderr, "No data sent after switching!\n"); 262 fprintf(stderr, "No data sent after switching!\n");
266 GNUNET_break (0); 263 GNUNET_break(0);
267 result++; 264 result++;
268 } 265 }
269 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && 266 if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) &&
270 (bytes_recv_after_switch == 0)) 267 (bytes_recv_after_switch == 0))
271 { 268 {
272 fprintf (stderr, "No data received after switching!\n"); 269 fprintf(stderr, "No data received after switching!\n");
273 GNUNET_break (0); 270 GNUNET_break(0);
274 result++; 271 result++;
275 } 272 }
276#if 0 273#if 0
277 /* This test is not really expected to pass right now... */ 274 /* This test is not really expected to pass right now... */
278 if (0 != result) 275 if (0 != result)
@@ -282,146 +279,147 @@ custom_shutdown (void *cls)
282 279
283 280
284static void 281static void
285notify_receive (void *cls, 282notify_receive(void *cls,
286 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 283 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
287 const struct GNUNET_PeerIdentity *sender, 284 const struct GNUNET_PeerIdentity *sender,
288 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) 285 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
289{ 286{
290 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) 287 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type))
291 return; 288 return;
292 289
293 { 290 {
294 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 291 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id));
295 292
296 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 293 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
297 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n", 294 "Peer %u (`%s') got message %u of size %u from peer (`%s')\n",
298 receiver->no, 295 receiver->no,
299 ps, 296 ps,
300 (uint32_t) ntohl (hdr->num), 297 (uint32_t)ntohl(hdr->num),
301 ntohs (hdr->header.size), 298 ntohs(hdr->header.size),
302 GNUNET_i2s (sender)); 299 GNUNET_i2s(sender));
303 GNUNET_free (ps); 300 GNUNET_free(ps);
304 } 301 }
305 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && 302 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
306 (stats[0].switch_attempts == 303 (stats[0].switch_attempts ==
307 stats[0].switch_fail + stats[0].switch_success) && 304 stats[0].switch_fail + stats[0].switch_success) &&
308 (stats[1].switch_attempts == 305 (stats[1].switch_attempts ==
309 stats[1].switch_fail + stats[1].switch_success)) 306 stats[1].switch_fail + stats[1].switch_success))
310 {
311 bytes_recv_after_switch += ntohs (hdr->header.size);
312 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
313 { 307 {
314 /* A peer switched addresses and sent and received data after the 308 bytes_recv_after_switch += ntohs(hdr->header.size);
315 * switch operations */ 309 if ((bytes_sent_after_switch > 0) && (bytes_recv_after_switch > 0))
316 GNUNET_SCHEDULER_shutdown (); 310 {
311 /* A peer switched addresses and sent and received data after the
312 * switch operations */
313 GNUNET_SCHEDULER_shutdown();
314 }
317 } 315 }
318 }
319} 316}
320 317
321 318
322static void 319static void
323notify_send (void *cls) 320notify_send(void *cls)
324{ 321{
325 static uint32_t cnt; 322 static uint32_t cnt;
326 323
327 GNUNET_assert ( 324 GNUNET_assert(
328 GNUNET_OK == 325 GNUNET_OK ==
329 GNUNET_TRANSPORT_TESTING_send (ccc->p[1], 326 GNUNET_TRANSPORT_TESTING_send(ccc->p[1],
330 ccc->p[0], 327 ccc->p[0],
331 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 328 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
332 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, 329 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
333 ++cnt, 330 ++cnt,
334 &notify_send, 331 &notify_send,
335 NULL)); 332 NULL));
336 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) && 333 if (((stats[0].switch_attempts >= 1) || (stats[1].switch_attempts >= 1)) &&
337 (stats[0].switch_attempts == 334 (stats[0].switch_attempts ==
338 stats[0].switch_fail + stats[0].switch_success) && 335 stats[0].switch_fail + stats[0].switch_success) &&
339 (stats[1].switch_attempts == 336 (stats[1].switch_attempts ==
340 stats[1].switch_fail + stats[1].switch_success)) 337 stats[1].switch_fail + stats[1].switch_success))
341 { 338 {
342 bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE; 339 bytes_sent_after_switch += GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE;
343 } 340 }
344} 341}
345 342
346 343
347static void 344static void
348progress_indicator (void *cls) 345progress_indicator(void *cls)
349{ 346{
350 static int counter; 347 static int counter;
351 348
352 measure_task = NULL; 349 measure_task = NULL;
353 counter++; 350 counter++;
354 if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) 351 if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter)
355 { 352 {
356 fprintf (stderr, "%s", ".\n"); 353 fprintf(stderr, "%s", ".\n");
357 } 354 }
358 else 355 else
359 { 356 {
360 fprintf (stderr, "%s", "."); 357 fprintf(stderr, "%s", ".");
361 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 358 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
362 &progress_indicator, 359 &progress_indicator,
363 NULL); 360 NULL);
364 } 361 }
365} 362}
366 363
367 364
368static void 365static void
369connected_cb (void *cls) 366connected_cb(void *cls)
370{ 367{
371 for (unsigned int i = 0; i < 2; i++) 368 for (unsigned int i = 0; i < 2; i++)
372 {
373 stats[i].stat = GNUNET_STATISTICS_create ("transport", ccc->p[i]->cfg);
374 if (NULL == stats[i].stat)
375 { 369 {
376 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 370 stats[i].stat = GNUNET_STATISTICS_create("transport", ccc->p[i]->cfg);
377 "Fail! Could not create statistics for peers!\n"); 371 if (NULL == stats[i].stat)
378 ccc->global_ret = GNUNET_SYSERR; 372 {
379 GNUNET_SCHEDULER_shutdown (); 373 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
380 return; 374 "Fail! Could not create statistics for peers!\n");
381 } 375 ccc->global_ret = GNUNET_SYSERR;
382 for (unsigned int j = 0; NULL != watches[j].stat_name; j++) 376 GNUNET_SCHEDULER_shutdown();
383 { 377 return;
384 GNUNET_STATISTICS_watch (stats[i].stat, 378 }
385 "transport", 379 for (unsigned int j = 0; NULL != watches[j].stat_name; j++)
386 watches[j].stat_name, 380 {
387 watches[j].stat_handler, 381 GNUNET_STATISTICS_watch(stats[i].stat,
388 &stats[i]); 382 "transport",
383 watches[j].stat_name,
384 watches[j].stat_handler,
385 &stats[i]);
386 }
389 } 387 }
390 }
391 /* Show progress */ 388 /* Show progress */
392 ccc->global_ret = GNUNET_OK; 389 ccc->global_ret = GNUNET_OK;
393 measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 390 measure_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
394 &progress_indicator, 391 &progress_indicator,
395 NULL); 392 NULL);
396 /* Peers are connected, start transmit test messages */ 393 /* Peers are connected, start transmit test messages */
397 GNUNET_assert ( 394 GNUNET_assert(
398 GNUNET_OK == 395 GNUNET_OK ==
399 GNUNET_TRANSPORT_TESTING_send (ccc->p[1], 396 GNUNET_TRANSPORT_TESTING_send(ccc->p[1],
400 ccc->p[0], 397 ccc->p[0],
401 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 398 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
402 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE, 399 GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE,
403 0, 400 0,
404 &notify_send, 401 &notify_send,
405 NULL)); 402 NULL));
406} 403}
407 404
408 405
409int 406int
410main (int argc, char *argv[]) 407main(int argc, char *argv[])
411{ 408{
412 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = 409 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc =
413 {.connect_continuation = &connected_cb, 410 { .connect_continuation = &connected_cb,
414 .config_file = "test_transport_api_data.conf", 411 .config_file = "test_transport_api_data.conf",
415 .rec = &notify_receive, 412 .rec = &notify_receive,
416 .nc = &GNUNET_TRANSPORT_TESTING_log_connect, 413 .nc = &GNUNET_TRANSPORT_TESTING_log_connect,
417 .shutdown_task = &custom_shutdown, 414 .shutdown_task = &custom_shutdown,
418 .timeout = TIMEOUT}; 415 .timeout = TIMEOUT };
416
419 ccc = &my_ccc; 417 ccc = &my_ccc;
420 int ret; 418 int ret;
421 419
422 ret = GNUNET_TRANSPORT_TESTING_main (2, 420 ret = GNUNET_TRANSPORT_TESTING_main(2,
423 &GNUNET_TRANSPORT_TESTING_connect_check, 421 &GNUNET_TRANSPORT_TESTING_connect_check,
424 ccc); 422 ccc);
425 if (77 == ret) 423 if (77 == ret)
426 return 77; 424 return 77;
427 if (GNUNET_OK != ret) 425 if (GNUNET_OK != ret)
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 0b458a317..e7d2e5a7e 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api.c 21 * @file transport/test_transport_api.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -34,42 +34,42 @@
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
51 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
52 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
53 receiver->no,
54 ps,
55 ntohs (message->header.type),
56 ntohs (message->header.size),
57 GNUNET_i2s (sender));
58 GNUNET_free (ps);
59 }
60 50
61 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs (message->header.type)) && 51 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
62 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs (message->header.size))) 52 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
63 { 53 receiver->no,
64 ccc->global_ret = GNUNET_OK; 54 ps,
65 GNUNET_SCHEDULER_shutdown (); 55 ntohs(message->header.type),
56 ntohs(message->header.size),
57 GNUNET_i2s(sender));
58 GNUNET_free(ps);
66 } 59 }
60
61 if ((GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE == ntohs(message->header.type)) &&
62 (GNUNET_TRANSPORT_TESTING_LARGE_MESSAGE_SIZE == ntohs(message->header.size)))
63 {
64 ccc->global_ret = GNUNET_OK;
65 GNUNET_SCHEDULER_shutdown();
66 }
67 else 67 else
68 { 68 {
69 GNUNET_break (0); 69 GNUNET_break(0);
70 ccc->global_ret = GNUNET_SYSERR; 70 ccc->global_ret = GNUNET_SYSERR;
71 GNUNET_SCHEDULER_shutdown (); 71 GNUNET_SCHEDULER_shutdown();
72 } 72 }
73} 73}
74 74
75 75
@@ -81,8 +81,8 @@ notify_receive (void *cls,
81 * in both directions simultaneously? 81 * in both directions simultaneously?
82 */ 82 */
83static int 83static int
84test (char *argv[], 84test(char *argv[],
85 int bi_directional) 85 int bi_directional)
86{ 86{
87 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 87 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
88 .num_messages = 1 88 .num_messages = 1
@@ -101,22 +101,22 @@ test (char *argv[],
101 ccc = &my_ccc; 101 ccc = &my_ccc;
102 sc.ccc = ccc; 102 sc.ccc = ccc;
103 if (GNUNET_OK != 103 if (GNUNET_OK !=
104 GNUNET_TRANSPORT_TESTING_main (2, 104 GNUNET_TRANSPORT_TESTING_main(2,
105 &GNUNET_TRANSPORT_TESTING_connect_check, 105 &GNUNET_TRANSPORT_TESTING_connect_check,
106 ccc)) 106 ccc))
107 return 1; 107 return 1;
108 return 0; 108 return 0;
109} 109}
110 110
111 111
112int 112int
113main (int argc, 113main(int argc,
114 char *argv[]) 114 char *argv[])
115{ 115{
116 if ( (0 != test (argv, 116 if ((0 != test(argv,
117 GNUNET_NO)) || 117 GNUNET_NO)) ||
118 (0 != test (argv, 118 (0 != test(argv,
119 GNUNET_YES) ) ) 119 GNUNET_YES)))
120 return 1; 120 return 1;
121 return 0; 121 return 0;
122} 122}
diff --git a/src/transport/test_transport_api_blacklisting.c b/src/transport/test_transport_api_blacklisting.c
index f0cc9b6d2..6cf5b251b 100644
--- a/src/transport/test_transport_api_blacklisting.c
+++ b/src/transport/test_transport_api_blacklisting.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/test_transport_api_blacklisting.c 22 * @file 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,135 @@ 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(GNUNET_TIME_UNIT_SECONDS, 3),
152 &end, 152 &end,
153 NULL); 153 NULL);
154 } 154 }
155 return res; 155 return res;
156} 156}
157 157
158 158
159static void 159static void
160start_blacklist (void *cls) 160start_blacklist(void *cls)
161{ 161{
162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 162 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
163 "Starting blacklists\n"); 163 "Starting blacklists\n");
164 blacklist_p1 = GNUNET_TRANSPORT_blacklist (ccc->p[0]->cfg, 164 blacklist_p1 = GNUNET_TRANSPORT_blacklist(ccc->p[0]->cfg,
165 &blacklist_cb, 165 &blacklist_cb,
166 ccc->p[0]); 166 ccc->p[0]);
167 GNUNET_assert (NULL != blacklist_p1); 167 GNUNET_assert(NULL != blacklist_p1);
168 blacklist_p2 = GNUNET_TRANSPORT_blacklist (ccc->p[1]->cfg, 168 blacklist_p2 = GNUNET_TRANSPORT_blacklist(ccc->p[1]->cfg,
169 &blacklist_cb, 169 &blacklist_cb,
170 ccc->p[1]); 170 ccc->p[1]);
171 GNUNET_assert (NULL != blacklist_p2); 171 GNUNET_assert(NULL != blacklist_p2);
172} 172}
173 173
174 174
175int 175int
176main (int argc, 176main(int argc,
177 char *argv[]) 177 char *argv[])
178{ 178{
179 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 179 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
180 .num_messages = 1 180 .num_messages = 1
@@ -194,9 +194,9 @@ main (int argc,
194 194
195 ccc = &my_ccc; 195 ccc = &my_ccc;
196 if (GNUNET_OK != 196 if (GNUNET_OK !=
197 GNUNET_TRANSPORT_TESTING_main (2, 197 GNUNET_TRANSPORT_TESTING_main(2,
198 &GNUNET_TRANSPORT_TESTING_connect_check, 198 &GNUNET_TRANSPORT_TESTING_connect_check,
199 ccc)) 199 ccc))
200 return 1; 200 return 1;
201 return 0; 201 return 0;
202} 202}
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 8522a3a88..47e52b67e 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_disconnect.c 21 * @file transport/test_transport_api_disconnect.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -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,69 @@ 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 (message->header.size)))
96 {
97 GNUNET_SCHEDULER_add_now (&stop_peer,
98 NULL);
99 return;
100 } 93 }
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} 101}
102 102
103 103
104int 104int
105main (int argc, 105main(int argc,
106 char *argv[]) 106 char *argv[])
107{ 107{
108 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 108 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
109 .num_messages = 1 109 .num_messages = 1
@@ -118,13 +118,13 @@ main (int argc,
118 .timeout = TIMEOUT, 118 .timeout = TIMEOUT,
119 .global_ret = GNUNET_SYSERR 119 .global_ret = GNUNET_SYSERR
120 }; 120 };
121 121
122 ccc = &my_ccc; 122 ccc = &my_ccc;
123 sc.ccc = ccc; 123 sc.ccc = ccc;
124 if (GNUNET_OK != 124 if (GNUNET_OK !=
125 GNUNET_TRANSPORT_TESTING_main (2, 125 GNUNET_TRANSPORT_TESTING_main(2,
126 &GNUNET_TRANSPORT_TESTING_connect_check, 126 &GNUNET_TRANSPORT_TESTING_connect_check,
127 ccc)) 127 ccc))
128 return 1; 128 return 1;
129 return 0; 129 return 0;
130} 130}
diff --git a/src/transport/test_transport_api_limited_sockets.c b/src/transport/test_transport_api_limited_sockets.c
index d5c6934b5..a5d40479f 100644
--- a/src/transport/test_transport_api_limited_sockets.c
+++ b/src/transport/test_transport_api_limited_sockets.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_limited_sockets.c 21 * @file transport/test_transport_api_limited_sockets.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -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 2d17cca45..4661a85a2 100644
--- a/src/transport/test_transport_api_manipulation_cfg.c
+++ b/src/transport/test_transport_api_manipulation_cfg.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_manipulation_cfg.c 21 * @file transport/test_transport_api_manipulation_cfg.c
22 * @brief base test case for transport traffic manipulation implementation 22 * @brief base test case for transport traffic manipulation implementation
@@ -35,12 +35,12 @@
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
42 42
43#define TEST_RESPONSE_MESSAGE_TYPE 43#define TEST_RESPONSE_MESSAGE_TYPE
44 44
45/** 45/**
46 * Test delay, in microseconds. 46 * Test delay, in microseconds.
@@ -56,104 +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 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE:
104 duration = GNUNET_TIME_absolute_get_difference (start_request,
105 GNUNET_TIME_absolute_get());
106 if (duration.rel_value_us >= TEST_DELAY)
107 { 103 {
108 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 104 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE:
109 "Request message was delayed for %s\n", 105 duration = GNUNET_TIME_absolute_get_difference(start_request,
110 GNUNET_STRINGS_relative_time_to_string (duration, 106 GNUNET_TIME_absolute_get());
111 GNUNET_YES)); 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
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;
112 } 153 }
113 else
114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 "Request message was delayed for unexpected duration %s\n",
117 GNUNET_STRINGS_relative_time_to_string (duration,
118 GNUNET_YES));
119 ccc->global_ret = GNUNET_SYSERR;
120 GNUNET_SCHEDULER_shutdown ();
121 }
122 /* Send response */
123 GNUNET_SCHEDULER_add_now (&sendtask_response_task,
124 NULL);
125 return;
126 case GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2:
127 duration = GNUNET_TIME_absolute_get_difference(start_response,
128 GNUNET_TIME_absolute_get());
129 if (duration.rel_value_us >= TEST_DELAY)
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
132 "Response message was delayed for %s\n",
133 GNUNET_STRINGS_relative_time_to_string (duration,
134 GNUNET_YES));
135 ccc->global_ret = GNUNET_OK;
136 }
137 else
138 {
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140 "Response message was delayed for unexpected duration %s\n",
141 GNUNET_STRINGS_relative_time_to_string (duration,
142 GNUNET_YES));
143 ccc->global_ret = GNUNET_SYSERR;
144 }
145 GNUNET_SCHEDULER_shutdown ();
146 break;
147 default:
148 GNUNET_break (0);
149 break;
150 }
151} 154}
152 155
153 156
154int 157int
155main (int argc, 158main(int argc,
156 char *argv[]) 159 char *argv[])
157{ 160{
158 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 161 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
159 .num_messages = 1 162 .num_messages = 1
@@ -170,11 +173,11 @@ main (int argc,
170 173
171 ccc = &my_ccc; 174 ccc = &my_ccc;
172 sc.ccc = ccc; 175 sc.ccc = ccc;
173 start_request = GNUNET_TIME_absolute_get (); 176 start_request = GNUNET_TIME_absolute_get();
174 if (GNUNET_OK != 177 if (GNUNET_OK !=
175 GNUNET_TRANSPORT_TESTING_main (2, 178 GNUNET_TRANSPORT_TESTING_main(2,
176 &GNUNET_TRANSPORT_TESTING_connect_check, 179 &GNUNET_TRANSPORT_TESTING_connect_check,
177 ccc)) 180 ccc))
178 return 1; 181 return 1;
179 return 0; 182 return 0;
180} 183}
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c
index bf7eb1666..080d245ca 100644
--- a/src/transport/test_transport_api_manipulation_recv_tcp.c
+++ b/src/transport/test_transport_api_manipulation_recv_tcp.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_manipulation_recv_tcp.c 21 * @file transport/test_transport_api_manipulation_recv_tcp.c
22 * @brief base test case for transport traffic manipulation implementation 22 * @brief base test case for transport traffic manipulation implementation
@@ -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,133 @@ 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)
101 { 89 {
102 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 90 memset(&prop,
103 &delayed_transmit, 91 0,
104 sc); 92 sizeof(prop));
105 return; 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)
101 {
102 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
103 &delayed_transmit,
104 sc);
105 return;
106 }
106 } 107 }
107 } 108 GNUNET_TRANSPORT_TESTING_large_send(sc);
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 (message->header.size)) )
132 {
133 GNUNET_break (0);
134 ccc->global_ret = GNUNET_SYSERR;
135 GNUNET_SCHEDULER_shutdown ();
136 return;
137 } 129 }
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 138
139 if (messages_recv <= 2) 139 if (messages_recv <= 2)
140 { 140 {
141 /* Received non-delayed message */ 141 /* Received non-delayed message */
142 dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); 142 dur_normal = GNUNET_TIME_absolute_get_duration(start_normal);
143 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
144 "Received non-delayed message %u after %s\n", 144 "Received non-delayed message %u after %s\n",
145 messages_recv, 145 messages_recv,
146 GNUNET_STRINGS_relative_time_to_string (dur_normal, 146 GNUNET_STRINGS_relative_time_to_string(dur_normal,
147 GNUNET_YES)); 147 GNUNET_YES));
148 GNUNET_SCHEDULER_add_now (&sendtask, 148 GNUNET_SCHEDULER_add_now(&sendtask,
149 NULL); 149 NULL);
150 messages_recv++; 150 messages_recv++;
151 return; 151 return;
152 } 152 }
153 /* Received manipulated message */ 153 /* Received manipulated message */
154 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); 154 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed);
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 155 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
156 "Received delayed message %u after %s\n", 156 "Received delayed message %u after %s\n",
157 messages_recv, 157 messages_recv,
158 GNUNET_STRINGS_relative_time_to_string (dur_delayed, 158 GNUNET_STRINGS_relative_time_to_string(dur_delayed,
159 GNUNET_YES)); 159 GNUNET_YES));
160 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) 160 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us)
161 { 161 {
162 GNUNET_break (0); 162 GNUNET_break(0);
163 ccc->global_ret = GNUNET_SYSERR; 163 ccc->global_ret = GNUNET_SYSERR;
164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 164 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
165 "Delayed message was not delayed correctly: took only %s\n", 165 "Delayed message was not delayed correctly: took only %s\n",
166 GNUNET_STRINGS_relative_time_to_string (dur_delayed, 166 GNUNET_STRINGS_relative_time_to_string(dur_delayed,
167 GNUNET_YES)); 167 GNUNET_YES));
168 } 168 }
169 else 169 else
170 { 170 {
171 ccc->global_ret = GNUNET_OK; 171 ccc->global_ret = GNUNET_OK;
172 } 172 }
173 /* shutdown */ 173 /* shutdown */
174 GNUNET_SCHEDULER_shutdown (); 174 GNUNET_SCHEDULER_shutdown();
175} 175}
176 176
177 177
178int 178int
179main (int argc, 179main(int argc,
180 char *argv[]) 180 char *argv[])
181{ 181{
182 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 182 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
183 .connect_continuation = &sendtask, 183 .connect_continuation = &sendtask,
@@ -191,9 +191,9 @@ main (int argc,
191 191
192 ccc = &my_ccc; 192 ccc = &my_ccc;
193 if (GNUNET_OK != 193 if (GNUNET_OK !=
194 GNUNET_TRANSPORT_TESTING_main (2, 194 GNUNET_TRANSPORT_TESTING_main(2,
195 &GNUNET_TRANSPORT_TESTING_connect_check, 195 &GNUNET_TRANSPORT_TESTING_connect_check,
196 ccc)) 196 ccc))
197 return 1; 197 return 1;
198 return 0; 198 return 0;
199} 199}
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c
index 408301b0f..ea4c7621b 100644
--- a/src/transport/test_transport_api_manipulation_send_tcp.c
+++ b/src/transport/test_transport_api_manipulation_send_tcp.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_manipulation_send_tcp.c 21 * @file transport/test_transport_api_manipulation_send_tcp.c
22 * @brief base test case for transport traffic manipulation implementation 22 * @brief base test case for transport traffic manipulation implementation
@@ -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,130 @@ 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(message->header.size)))
129 { 129 {
130 GNUNET_break (0); 130 GNUNET_break(0);
131 ccc->global_ret = GNUNET_SYSERR; 131 ccc->global_ret = GNUNET_SYSERR;
132 GNUNET_SCHEDULER_shutdown (); 132 GNUNET_SCHEDULER_shutdown();
133 return; 133 return;
134 } 134 }
135 135
136 if (0 == messages_recv) 136 if (0 == messages_recv)
137 { 137 {
138 /* Received non-delayed message */ 138 /* Received non-delayed message */
139 dur_normal = GNUNET_TIME_absolute_get_duration (start_normal); 139 dur_normal = GNUNET_TIME_absolute_get_duration(start_normal);
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
141 "Received non-delayed message %u after %s\n", 141 "Received non-delayed message %u after %s\n",
142 messages_recv, 142 messages_recv,
143 GNUNET_STRINGS_relative_time_to_string (dur_normal, 143 GNUNET_STRINGS_relative_time_to_string(dur_normal,
144 GNUNET_YES)); 144 GNUNET_YES));
145 GNUNET_SCHEDULER_add_now (&sendtask, 145 GNUNET_SCHEDULER_add_now(&sendtask,
146 NULL); 146 NULL);
147 messages_recv++; 147 messages_recv++;
148 return; 148 return;
149 } 149 }
150 /* Received manipulated message */ 150 /* Received manipulated message */
151 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed); 151 dur_delayed = GNUNET_TIME_absolute_get_duration(start_delayed);
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
153 "Received delayed message %u after %s\n", 153 "Received delayed message %u after %s\n",
154 messages_recv, 154 messages_recv,
155 GNUNET_STRINGS_relative_time_to_string (dur_delayed, 155 GNUNET_STRINGS_relative_time_to_string(dur_delayed,
156 GNUNET_YES)); 156 GNUNET_YES));
157 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us) 157 if (dur_delayed.rel_value_us < GNUNET_TIME_UNIT_SECONDS.rel_value_us)
158 { 158 {
159 GNUNET_break (0); 159 GNUNET_break(0);
160 ccc->global_ret = GNUNET_SYSERR; 160 ccc->global_ret = GNUNET_SYSERR;
161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
162 "Delayed message was not delayed correctly: took only %s\n", 162 "Delayed message was not delayed correctly: took only %s\n",
163 GNUNET_STRINGS_relative_time_to_string (dur_delayed, 163 GNUNET_STRINGS_relative_time_to_string(dur_delayed,
164 GNUNET_YES)); 164 GNUNET_YES));
165 } 165 }
166 else 166 else
167 { 167 {
168 ccc->global_ret = GNUNET_OK; 168 ccc->global_ret = GNUNET_OK;
169 } 169 }
170 GNUNET_SCHEDULER_shutdown (); 170 GNUNET_SCHEDULER_shutdown();
171} 171}
172 172
173 173
174int 174int
175main (int argc, 175main(int argc,
176 char *argv[]) 176 char *argv[])
177{ 177{
178 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 178 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
179 .connect_continuation = &sendtask, 179 .connect_continuation = &sendtask,
@@ -187,9 +187,9 @@ main (int argc,
187 187
188 ccc = &my_ccc; 188 ccc = &my_ccc;
189 if (GNUNET_OK != 189 if (GNUNET_OK !=
190 GNUNET_TRANSPORT_TESTING_main (2, 190 GNUNET_TRANSPORT_TESTING_main(2,
191 &GNUNET_TRANSPORT_TESTING_connect_check, 191 &GNUNET_TRANSPORT_TESTING_connect_check,
192 ccc)) 192 ccc))
193 return 1; 193 return 1;
194 return 0; 194 return 0;
195} 195}
diff --git a/src/transport/test_transport_api_monitor_peers.c b/src/transport/test_transport_api_monitor_peers.c
index 9c3e535fe..a76ebe5ee 100644
--- a/src/transport/test_transport_api_monitor_peers.c
+++ b/src/transport/test_transport_api_monitor_peers.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_monitor_peers.c 21 * @file transport/test_transport_api_monitor_peers.c
22 * @brief base test case for transport peer monitor API 22 * @brief base test case for transport peer monitor API
@@ -28,12 +28,12 @@
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(GNUNET_TIME_UNIT_SECONDS, 30)
37 37
38#define TEST_MESSAGE_SIZE 2600 38#define TEST_MESSAGE_SIZE 2600
39 39
@@ -55,151 +55,151 @@ static int p2_c_notify;
55 55
56 56
57static void 57static void
58custom_shutdown (void *cls) 58custom_shutdown(void *cls)
59{ 59{
60 if (NULL != pmc_p1) 60 if (NULL != pmc_p1)
61 { 61 {
62 GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p1); 62 GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p1);
63 pmc_p1 = NULL; 63 pmc_p1 = NULL;
64 } 64 }
65 if (NULL != pmc_p2) 65 if (NULL != pmc_p2)
66 { 66 {
67 GNUNET_TRANSPORT_monitor_peers_cancel (pmc_p2); 67 GNUNET_TRANSPORT_monitor_peers_cancel(pmc_p2);
68 pmc_p2 = NULL; 68 pmc_p2 = NULL;
69 } 69 }
70} 70}
71 71
72 72
73static void 73static void
74notify_receive (void *cls, 74notify_receive(void *cls,
75 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 75 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
76 const struct GNUNET_PeerIdentity *sender, 76 const struct GNUNET_PeerIdentity *sender,
77 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 77 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
78{ 78{
79 char *ps = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 79 char *ps = GNUNET_strdup(GNUNET_i2s(&receiver->id));
80 80
81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 81 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
82 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n", 82 "Peer %u (`%s') received message of type %d and size %u size from peer %s!\n",
83 receiver->no, 83 receiver->no,
84 ps, 84 ps,
85 ntohs (message->header.type), 85 ntohs(message->header.type),
86 ntohs (message->header.size), 86 ntohs(message->header.size),
87 GNUNET_i2s (sender)); 87 GNUNET_i2s(sender));
88 GNUNET_free (ps); 88 GNUNET_free(ps);
89} 89}
90 90
91 91
92static void 92static void
93sendtask (void *cls) 93sendtask(void *cls)
94{ 94{
95 /* intentionally empty */ 95 /* intentionally empty */
96} 96}
97 97
98 98
99static void 99static void
100check_done () 100check_done()
101{ 101{
102 if ( (GNUNET_YES == p1_c) && 102 if ((GNUNET_YES == p1_c) &&
103 (GNUNET_YES == p2_c) && 103 (GNUNET_YES == p2_c) &&
104 p1_c_notify && 104 p1_c_notify &&
105 p2_c_notify) 105 p2_c_notify)
106 { 106 {
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
108 "Both peers state to be connected\n"); 108 "Both peers state to be connected\n");
109 ccc->global_ret = GNUNET_OK; 109 ccc->global_ret = GNUNET_OK;
110 GNUNET_SCHEDULER_shutdown (); 110 GNUNET_SCHEDULER_shutdown();
111 } 111 }
112} 112}
113 113
114 114
115static void 115static void
116notify_connect (void *cls, 116notify_connect(void *cls,
117 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 117 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
118 const struct GNUNET_PeerIdentity *other) 118 const struct GNUNET_PeerIdentity *other)
119{ 119{
120 GNUNET_TRANSPORT_TESTING_log_connect (cls, 120 GNUNET_TRANSPORT_TESTING_log_connect(cls,
121 me, 121 me,
122 other); 122 other);
123 if (0 == memcmp (other, &ccc->p[0]->id, sizeof (struct GNUNET_PeerIdentity))) 123 if (0 == memcmp(other, &ccc->p[0]->id, sizeof(struct GNUNET_PeerIdentity)))
124 { 124 {
125 p1_c_notify = GNUNET_YES; 125 p1_c_notify = GNUNET_YES;
126 } 126 }
127 if (0 == memcmp (other, &ccc->p[1]->id, sizeof (struct GNUNET_PeerIdentity))) 127 if (0 == memcmp(other, &ccc->p[1]->id, sizeof(struct GNUNET_PeerIdentity)))
128 { 128 {
129 p2_c_notify = GNUNET_YES; 129 p2_c_notify = GNUNET_YES;
130 } 130 }
131 check_done (); 131 check_done();
132} 132}
133 133
134 134
135static void 135static void
136monitor1_cb (void *cls, 136monitor1_cb(void *cls,
137 const struct GNUNET_PeerIdentity *peer, 137 const struct GNUNET_PeerIdentity *peer,
138 const struct GNUNET_HELLO_Address *address, 138 const struct GNUNET_HELLO_Address *address,
139 enum GNUNET_TRANSPORT_PeerState state, 139 enum GNUNET_TRANSPORT_PeerState state,
140 struct GNUNET_TIME_Absolute state_timeout) 140 struct GNUNET_TIME_Absolute state_timeout)
141{ 141{
142 if ((NULL == address) || (NULL == ccc->p[0])) 142 if ((NULL == address) || (NULL == ccc->p[0]))
143 return; 143 return;
144 144
145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 145 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
146 "Monitor 1: %s %s %s\n", 146 "Monitor 1: %s %s %s\n",
147 GNUNET_i2s (&address->peer), 147 GNUNET_i2s(&address->peer),
148 GNUNET_TRANSPORT_ps2s (state), 148 GNUNET_TRANSPORT_ps2s(state),
149 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 149 GNUNET_STRINGS_absolute_time_to_string(state_timeout));
150 if ( (0 == memcmp (&address->peer, &ccc->p[1]->id, sizeof (ccc->p[1]->id))) && 150 if ((0 == memcmp(&address->peer, &ccc->p[1]->id, sizeof(ccc->p[1]->id))) &&
151 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && 151 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
152 (GNUNET_NO == p1_c) ) 152 (GNUNET_NO == p1_c))
153 { 153 {
154 p1_c = GNUNET_YES; 154 p1_c = GNUNET_YES;
155 check_done (); 155 check_done();
156 } 156 }
157} 157}
158 158
159 159
160static void 160static void
161monitor2_cb (void *cls, 161monitor2_cb(void *cls,
162 const struct GNUNET_PeerIdentity *peer, 162 const struct GNUNET_PeerIdentity *peer,
163 const struct GNUNET_HELLO_Address *address, 163 const struct GNUNET_HELLO_Address *address,
164 enum GNUNET_TRANSPORT_PeerState state, 164 enum GNUNET_TRANSPORT_PeerState state,
165 struct GNUNET_TIME_Absolute state_timeout) 165 struct GNUNET_TIME_Absolute state_timeout)
166{ 166{
167 if ((NULL == address) || (NULL == ccc->p[1])) 167 if ((NULL == address) || (NULL == ccc->p[1]))
168 return; 168 return;
169 169
170 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 170 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
171 "Monitor 2: %s %s %s\n", 171 "Monitor 2: %s %s %s\n",
172 GNUNET_i2s (&address->peer), 172 GNUNET_i2s(&address->peer),
173 GNUNET_TRANSPORT_ps2s (state), 173 GNUNET_TRANSPORT_ps2s(state),
174 GNUNET_STRINGS_absolute_time_to_string(state_timeout)); 174 GNUNET_STRINGS_absolute_time_to_string(state_timeout));
175 if ( (0 == memcmp (&address->peer, &ccc->p[0]->id, sizeof (ccc->p[0]->id))) && 175 if ((0 == memcmp(&address->peer, &ccc->p[0]->id, sizeof(ccc->p[0]->id))) &&
176 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) && 176 (GNUNET_YES == GNUNET_TRANSPORT_is_connected(state)) &&
177 (GNUNET_NO == p2_c) ) 177 (GNUNET_NO == p2_c))
178 { 178 {
179 p2_c = GNUNET_YES; 179 p2_c = GNUNET_YES;
180 check_done (); 180 check_done();
181 } 181 }
182} 182}
183 183
184 184
185static void 185static void
186start_monitors (void *cls) 186start_monitors(void *cls)
187{ 187{
188 pmc_p1 = GNUNET_TRANSPORT_monitor_peers (ccc->p[0]->cfg, 188 pmc_p1 = GNUNET_TRANSPORT_monitor_peers(ccc->p[0]->cfg,
189 NULL, 189 NULL,
190 GNUNET_NO, 190 GNUNET_NO,
191 &monitor1_cb, 191 &monitor1_cb,
192 NULL); 192 NULL);
193 pmc_p2 = GNUNET_TRANSPORT_monitor_peers (ccc->p[1]->cfg, 193 pmc_p2 = GNUNET_TRANSPORT_monitor_peers(ccc->p[1]->cfg,
194 NULL, 194 NULL,
195 GNUNET_NO, 195 GNUNET_NO,
196 &monitor2_cb, 196 &monitor2_cb,
197 NULL); 197 NULL);
198} 198}
199 199
200 200
201int 201int
202main (int argc, char *argv[]) 202main(int argc, char *argv[])
203{ 203{
204 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = { 204 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext my_ccc = {
205 .pre_connect_task = &start_monitors, 205 .pre_connect_task = &start_monitors,
@@ -214,9 +214,9 @@ main (int argc, char *argv[])
214 214
215 ccc = &my_ccc; 215 ccc = &my_ccc;
216 if (GNUNET_OK != 216 if (GNUNET_OK !=
217 GNUNET_TRANSPORT_TESTING_main (2, 217 GNUNET_TRANSPORT_TESTING_main(2,
218 &GNUNET_TRANSPORT_TESTING_connect_check, 218 &GNUNET_TRANSPORT_TESTING_connect_check,
219 ccc)) 219 ccc))
220 return 1; 220 return 1;
221 return 0; 221 return 0;
222} 222}
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index a26a92880..76910a6c8 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_reliability.c 21 * @file transport/test_transport_api_reliability.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -48,7 +48,7 @@
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 * FACTOR)
52 52
53/** 53/**
54 * If we are in an "xhdr" test, the factor by which we divide 54 * If we are in an "xhdr" test, the factor by which we divide
@@ -83,7 +83,7 @@ static char bitmap[TOTAL_MSGS / 8];
83 * Get the desired message size for message number @a iter. 83 * Get the desired message size for message number @a iter.
84 */ 84 */
85static size_t 85static size_t
86get_size (unsigned int iter) 86get_size(unsigned int iter)
87{ 87{
88 size_t ret; 88 size_t ret;
89 89
@@ -91,10 +91,10 @@ get_size (unsigned int iter)
91#ifndef LINUX 91#ifndef LINUX
92 /* FreeBSD/OSX etc. Unix DGRAMs do not work 92 /* FreeBSD/OSX etc. Unix DGRAMs do not work
93 * with large messages */ 93 * with large messages */
94 if (0 == strcmp ("unix", ccc->test_plugin)) 94 if (0 == strcmp("unix", ccc->test_plugin))
95 ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024); 95 ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 1024);
96#endif 96#endif
97 ret = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000); 97 ret = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage) + (ret % 60000);
98 return ret; 98 return ret;
99} 99}
100 100
@@ -108,9 +108,9 @@ get_size (unsigned int iter)
108 * @return message size of the message 108 * @return message size of the message
109 */ 109 */
110static size_t 110static size_t
111get_size_cnt (unsigned int cnt_down) 111get_size_cnt(unsigned int cnt_down)
112{ 112{
113 size_t ret = get_size (TOTAL_MSGS / xhdr - 1 - cnt_down); 113 size_t ret = get_size(TOTAL_MSGS / xhdr - 1 - cnt_down);
114 114
115 total_bytes += ret; 115 total_bytes += ret;
116 return ret; 116 return ret;
@@ -124,19 +124,19 @@ get_size_cnt (unsigned int cnt_down)
124 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success 124 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
125 */ 125 */
126static int 126static int
127set_bit (unsigned int bitIdx) 127set_bit(unsigned int bitIdx)
128{ 128{
129 size_t arraySlot; 129 size_t arraySlot;
130 unsigned int targetBit; 130 unsigned int targetBit;
131 131
132 if (bitIdx >= sizeof (bitmap) * 8) 132 if (bitIdx >= sizeof(bitmap) * 8)
133 { 133 {
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 134 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
135 "tried to set bit %u of %u(!?!?)\n", 135 "tried to set bit %u of %u(!?!?)\n",
136 bitIdx, 136 bitIdx,
137 (unsigned int) sizeof (bitmap) * 8); 137 (unsigned int)sizeof(bitmap) * 8);
138 return GNUNET_SYSERR; 138 return GNUNET_SYSERR;
139 } 139 }
140 arraySlot = bitIdx / 8; 140 arraySlot = bitIdx / 8;
141 targetBit = (1L << (bitIdx % 8)); 141 targetBit = (1L << (bitIdx % 8));
142 bitmap[arraySlot] |= targetBit; 142 bitmap[arraySlot] |= targetBit;
@@ -152,143 +152,143 @@ set_bit (unsigned int bitIdx)
152 * @return Bit @a bit from @a map 152 * @return Bit @a bit from @a map
153 */ 153 */
154static int 154static int
155get_bit (const char *map, 155get_bit(const char *map,
156 unsigned int bit) 156 unsigned int bit)
157{ 157{
158 if (bit > TOTAL_MSGS) 158 if (bit > TOTAL_MSGS)
159 { 159 {
160 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 160 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
161 "get bit %u of %u(!?!?)\n", 161 "get bit %u of %u(!?!?)\n",
162 bit, 162 bit,
163 (unsigned int) sizeof (bitmap) * 8); 163 (unsigned int)sizeof(bitmap) * 8);
164 return 0; 164 return 0;
165 } 165 }
166 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; 166 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0;
167} 167}
168 168
169 169
170static void 170static void
171custom_shutdown (void *cls) 171custom_shutdown(void *cls)
172{ 172{
173 unsigned long long delta; 173 unsigned long long delta;
174 unsigned long long rate; 174 unsigned long long rate;
175 int ok; 175 int ok;
176 176
177 /* Calculcate statistics */ 177 /* Calculcate statistics */
178 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 178 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us;
179 if (0 == delta) 179 if (0 == delta)
180 delta = 1; 180 delta = 1;
181 rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); 181 rate = (1000LL * 1000ll * total_bytes) / (1024 * delta);
182 fprintf (stderr, 182 fprintf(stderr,
183 "\nThroughput was %llu KiBytes/s\n", 183 "\nThroughput was %llu KiBytes/s\n",
184 rate); 184 rate);
185 { 185 {
186 char *value_name; 186 char *value_name;
187 187
188 GNUNET_asprintf (&value_name, 188 GNUNET_asprintf(&value_name,
189 "unreliable_%s", 189 "unreliable_%s",
190 ccc->test_plugin); 190 ccc->test_plugin);
191 GAUGER ("TRANSPORT", 191 GAUGER("TRANSPORT",
192 value_name, 192 value_name,
193 (int) rate, 193 (int)rate,
194 "kb/s"); 194 "kb/s");
195 GNUNET_free (value_name); 195 GNUNET_free(value_name);
196 } 196 }
197 197
198 ok = 0; 198 ok = 0;
199 for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++) 199 for (unsigned int i = 0; i < TOTAL_MSGS / xhdr; i++)
200 {
201 if (get_bit (bitmap, i) == 0)
202 { 200 {
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 201 if (get_bit(bitmap, i) == 0)
204 "Did not receive message %d\n", 202 {
205 i); 203 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
206 ok = -1; 204 "Did not receive message %d\n",
205 i);
206 ok = -1;
207 }
207 } 208 }
208 }
209 if (0 != ok) 209 if (0 != ok)
210 ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */ 210 ccc->global_ret = GNUNET_SYSERR; /* fail: messages missing! */
211} 211}
212 212
213 213
214static void 214static void
215notify_receive (void *cls, 215notify_receive(void *cls,
216 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 216 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
217 const struct GNUNET_PeerIdentity *sender, 217 const struct GNUNET_PeerIdentity *sender,
218 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr) 218 const struct GNUNET_TRANSPORT_TESTING_TestMessage *hdr)
219{ 219{
220 static int n; 220 static int n;
221 unsigned int s; 221 unsigned int s;
222 char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1]; 222 char cbuf[GNUNET_MAX_MESSAGE_SIZE - 1];
223 223
224 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs (hdr->header.type)) 224 if (GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE != ntohs(hdr->header.type))
225 return; 225 return;
226 msg_recv = ntohl (hdr->num); 226 msg_recv = ntohl(hdr->num);
227 s = get_size (ntohl (hdr->num)); 227 s = get_size(ntohl(hdr->num));
228 228
229 if (ntohs (hdr->header.size) != s) 229 if (ntohs(hdr->header.size) != s)
230 { 230 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 231 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
232 "Expected message %u of size %u, got %u bytes of message %u\n", 232 "Expected message %u of size %u, got %u bytes of message %u\n",
233 (uint32_t) ntohl (hdr->num), 233 (uint32_t)ntohl(hdr->num),
234 s, 234 s,
235 ntohs (hdr->header.size), 235 ntohs(hdr->header.size),
236 (uint32_t) ntohl (hdr->num)); 236 (uint32_t)ntohl(hdr->num));
237 ccc->global_ret = GNUNET_SYSERR; 237 ccc->global_ret = GNUNET_SYSERR;
238 GNUNET_SCHEDULER_shutdown (); 238 GNUNET_SCHEDULER_shutdown();
239 return; 239 return;
240 } 240 }
241 241
242 memset (cbuf, 242 memset(cbuf,
243 ntohl (hdr->num), 243 ntohl(hdr->num),
244 s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)); 244 s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage));
245 if (0 != 245 if (0 !=
246 memcmp (cbuf, 246 memcmp(cbuf,
247 &hdr[1], 247 &hdr[1],
248 s - sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage))) 248 s - sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage)))
249 { 249 {
250 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 250 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
251 "Expected message %u with bits %u, but body did not match\n", 251 "Expected message %u with bits %u, but body did not match\n",
252 (uint32_t) ntohl (hdr->num), 252 (uint32_t)ntohl(hdr->num),
253 (unsigned char) ntohl (hdr->num)); 253 (unsigned char)ntohl(hdr->num));
254 ccc->global_ret = GNUNET_SYSERR; 254 ccc->global_ret = GNUNET_SYSERR;
255 GNUNET_SCHEDULER_shutdown (); 255 GNUNET_SCHEDULER_shutdown();
256 return; 256 return;
257 } 257 }
258#if VERBOSE 258#if VERBOSE
259 if (0 == ntohl (hdr->num) % 5) 259 if (0 == ntohl(hdr->num) % 5)
260 { 260 {
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 261 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
262 "Got message %u of size %u\n", 262 "Got message %u of size %u\n",
263 (uint32_t) ntohl (hdr->num), 263 (uint32_t)ntohl(hdr->num),
264 ntohs (hdr->header.size)); 264 ntohs(hdr->header.size));
265 } 265 }
266#endif 266#endif
267 n++; 267 n++;
268 if (GNUNET_SYSERR == set_bit (ntohl (hdr->num))) 268 if (GNUNET_SYSERR == set_bit(ntohl(hdr->num)))
269 { 269 {
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 270 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
271 "Message id %u is bigger than maxmimum number of messages %u expected\n", 271 "Message id %u is bigger than maxmimum number of messages %u expected\n",
272 (uint32_t) ntohl (hdr->num), 272 (uint32_t)ntohl(hdr->num),
273 TOTAL_MSGS / xhdr); 273 TOTAL_MSGS / xhdr);
274 } 274 }
275 if (0 == (n % (TOTAL_MSGS / xhdr / 100))) 275 if (0 == (n % (TOTAL_MSGS / xhdr / 100)))
276 { 276 {
277 fprintf (stderr, "%s", "."); 277 fprintf(stderr, "%s", ".");
278 } 278 }
279 if (n == TOTAL_MSGS / xhdr) 279 if (n == TOTAL_MSGS / xhdr)
280 { 280 {
281 /* end testcase with success */ 281 /* end testcase with success */
282 ccc->global_ret = GNUNET_OK; 282 ccc->global_ret = GNUNET_OK;
283 GNUNET_SCHEDULER_shutdown (); 283 GNUNET_SCHEDULER_shutdown();
284 } 284 }
285} 285}
286 286
287 287
288int 288int
289main (int argc, char *argv[]) 289main(int argc, char *argv[])
290{ 290{
291 if (0 == strstr (argv[0], "xhdr")) 291 if (0 == strstr(argv[0], "xhdr"))
292 xhdr = 30; 292 xhdr = 30;
293 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 293 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
294 .num_messages = TOTAL_MSGS / xhdr, 294 .num_messages = TOTAL_MSGS / xhdr,
@@ -308,11 +308,11 @@ main (int argc, char *argv[])
308 308
309 ccc = &my_ccc; 309 ccc = &my_ccc;
310 sc.ccc = ccc; 310 sc.ccc = ccc;
311 start_time = GNUNET_TIME_absolute_get (); 311 start_time = GNUNET_TIME_absolute_get();
312 if (GNUNET_OK != 312 if (GNUNET_OK !=
313 GNUNET_TRANSPORT_TESTING_main (2, 313 GNUNET_TRANSPORT_TESTING_main(2,
314 &GNUNET_TRANSPORT_TESTING_connect_check, 314 &GNUNET_TRANSPORT_TESTING_connect_check,
315 ccc)) 315 ccc))
316 return 1; 316 return 1;
317 return 0; 317 return 0;
318} 318}
diff --git a/src/transport/test_transport_api_restart_reconnect.c b/src/transport/test_transport_api_restart_reconnect.c
index 5a6c10f8a..bf9a7f9a1 100644
--- a/src/transport/test_transport_api_restart_reconnect.c
+++ b/src/transport/test_transport_api_restart_reconnect.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_restart_reconnect.c 21 * @file transport/test_transport_api_restart_reconnect.c
22 * @brief base test case for transport implementations 22 * @brief base test case for transport implementations
@@ -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,136 +47,136 @@ 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(message->header.size)))
115 {
116 if (GNUNET_NO == restarted)
117 { 115 {
118 restarted = GNUNET_YES; 116 if (GNUNET_NO == restarted)
119 fprintf (stderr, "TN: %s\n", ccc->test_name); 117 {
120 restart (ccc->p[0]); 118 restarted = GNUNET_YES;
121 if (NULL != strstr (ccc->test_name, 119 fprintf(stderr, "TN: %s\n", ccc->test_name);
122 "2peers")) 120 restart(ccc->p[0]);
123 restart (ccc->p[1]); 121 if (NULL != strstr(ccc->test_name,
124 return; 122 "2peers"))
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 }
125 } 133 }
126 else 134 else
127 { 135 {
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 136 GNUNET_break(0);
129 "Restarted peers connected and message was sent, stopping test...\n"); 137 ccc->global_ret = GNUNET_SYSERR;
130 ccc->global_ret = GNUNET_OK; 138 GNUNET_SCHEDULER_shutdown();
131 GNUNET_SCHEDULER_shutdown ();
132 } 139 }
133 }
134 else
135 {
136 GNUNET_break (0);
137 ccc->global_ret = GNUNET_SYSERR;
138 GNUNET_SCHEDULER_shutdown ();
139 }
140} 140}
141 141
142 142
143static void 143static void
144notify_connect (void *cls, 144notify_connect(void *cls,
145 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 145 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
146 const struct GNUNET_PeerIdentity *other) 146 const struct GNUNET_PeerIdentity *other)
147{ 147{
148 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 148 static struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
149 .num_messages = 1 149 .num_messages = 1
150 }; 150 };
151 151
152 sc.ccc = ccc; 152 sc.ccc = ccc;
153 GNUNET_TRANSPORT_TESTING_log_connect (cls, 153 GNUNET_TRANSPORT_TESTING_log_connect(cls,
154 me, 154 me,
155 other); 155 other);
156 if (me == ccc->p[0]) 156 if (me == ccc->p[0])
157 p1_connected = GNUNET_YES; 157 p1_connected = GNUNET_YES;
158 if (me == ccc->p[1]) 158 if (me == ccc->p[1])
159 p2_connected = GNUNET_YES; 159 p2_connected = GNUNET_YES;
160 160
161 if ( (GNUNET_YES == restarted) && 161 if ((GNUNET_YES == restarted) &&
162 (GNUNET_YES == p1_connected) && 162 (GNUNET_YES == p1_connected) &&
163 (GNUNET_YES == p2_connected) ) 163 (GNUNET_YES == p2_connected))
164 { 164 {
165 /* Peer was restarted and we received 3 connect messages (2 from first connect, 1 from reconnect) */ 165 /* 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, 166 GNUNET_SCHEDULER_add_now(&GNUNET_TRANSPORT_TESTING_simple_send,
167 &sc); 167 &sc);
168 } 168 }
169} 169}
170 170
171 171
172static void 172static void
173notify_disconnect (void *cls, 173notify_disconnect(void *cls,
174 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 174 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
175 const struct GNUNET_PeerIdentity *other) 175 const struct GNUNET_PeerIdentity *other)
176{ 176{
177 GNUNET_TRANSPORT_TESTING_log_disconnect (cls, 177 GNUNET_TRANSPORT_TESTING_log_disconnect(cls,
178 me, 178 me,
179 other); 179 other);
180 if (me == ccc->p[0]) 180 if (me == ccc->p[0])
181 p1_connected = GNUNET_NO; 181 p1_connected = GNUNET_NO;
182 if (me == ccc->p[1]) 182 if (me == ccc->p[1])
@@ -185,8 +185,8 @@ notify_disconnect (void *cls,
185 185
186 186
187int 187int
188main (int argc, 188main(int argc,
189 char *argv[]) 189 char *argv[])
190{ 190{
191 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = { 191 struct GNUNET_TRANSPORT_TESTING_SendClosure sc = {
192 .num_messages = 1 192 .num_messages = 1
@@ -205,9 +205,9 @@ main (int argc,
205 ccc = &my_ccc; 205 ccc = &my_ccc;
206 sc.ccc = ccc; 206 sc.ccc = ccc;
207 if (GNUNET_OK != 207 if (GNUNET_OK !=
208 GNUNET_TRANSPORT_TESTING_main (2, 208 GNUNET_TRANSPORT_TESTING_main(2,
209 &GNUNET_TRANSPORT_TESTING_connect_check, 209 &GNUNET_TRANSPORT_TESTING_connect_check,
210 ccc)) 210 ccc))
211 return 1; 211 return 1;
212 return 0; 212 return 0;
213} 213}
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c
index f562dd196..dd2639136 100644
--- a/src/transport/test_transport_api_timeout.c
+++ b/src/transport/test_transport_api_timeout.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_api_timeout.c 21 * @file transport/test_transport_api_timeout.c
22 * @brief test case for transport plugin implementations complying timeout 22 * @brief test case for transport plugin implementations complying timeout
@@ -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 0ecd6fda1..1d8ef3fde 100644
--- a/src/transport/test_transport_blacklisting.c
+++ b/src/transport/test_transport_blacklisting.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_blacklisting.c 22 * @file transport/transport_api_blacklisting.c
@@ -65,9 +65,9 @@ struct GNUNET_TRANSPORT_TESTING_Handle *tth;
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, 10)
71 71
72static int stage; 72static int stage;
73static int ok; 73static int ok;
@@ -80,7 +80,7 @@ static struct GNUNET_SCHEDULER_Task * timeout_task;
80static struct GNUNET_SCHEDULER_Task * stage_task; 80static struct GNUNET_SCHEDULER_Task * stage_task;
81 81
82#if VERBOSE 82#if VERBOSE
83#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 83#define OKPP do { ok++; fprintf(stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
84#else 84#else
85#define OKPP do { ok++; } while (0) 85#define OKPP do { ok++; } while (0)
86#endif 86#endif
@@ -91,99 +91,99 @@ run_stage(void *cls);
91 91
92 92
93static void 93static void
94end (void *cls) 94end(void *cls)
95{ 95{
96 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n"); 96 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Stopping\n");
97 97
98 if (die_task != NULL ) 98 if (die_task != NULL)
99 { 99 {
100 GNUNET_SCHEDULER_cancel (die_task); 100 GNUNET_SCHEDULER_cancel(die_task);
101 die_task = NULL; 101 die_task = NULL;
102 } 102 }
103 103
104 if (timeout_task != NULL ) 104 if (timeout_task != NULL)
105 { 105 {
106 GNUNET_SCHEDULER_cancel (timeout_task); 106 GNUNET_SCHEDULER_cancel(timeout_task);
107 timeout_task = NULL; 107 timeout_task = NULL;
108 } 108 }
109 109
110 if (stage_task != NULL ) 110 if (stage_task != NULL)
111 { 111 {
112 GNUNET_SCHEDULER_cancel (stage_task); 112 GNUNET_SCHEDULER_cancel(stage_task);
113 stage_task = NULL; 113 stage_task = NULL;
114 } 114 }
115 115
116 if (cc != NULL ) 116 if (cc != NULL)
117 { 117 {
118 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); 118 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
119 cc = NULL; 119 cc = NULL;
120 } 120 }
121 121
122 if (p1 != NULL ) 122 if (p1 != NULL)
123 { 123 {
124 GNUNET_TRANSPORT_TESTING_stop_peer (p1); 124 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
125 p1 = NULL; 125 p1 = NULL;
126 } 126 }
127 if (p2 != NULL ) 127 if (p2 != NULL)
128 { 128 {
129 GNUNET_TRANSPORT_TESTING_stop_peer (p2); 129 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
130 p2 = NULL; 130 p2 = NULL;
131 } 131 }
132} 132}
133 133
134 134
135static void 135static void
136end_badly (void *cls) 136end_badly(void *cls)
137{ 137{
138 die_task = NULL; 138 die_task = NULL;
139 139
140 if (timeout_task != NULL ) 140 if (timeout_task != NULL)
141 { 141 {
142 GNUNET_SCHEDULER_cancel (timeout_task); 142 GNUNET_SCHEDULER_cancel(timeout_task);
143 timeout_task = NULL; 143 timeout_task = NULL;
144 } 144 }
145 145
146 if (stage_task != NULL ) 146 if (stage_task != NULL)
147 { 147 {
148 GNUNET_SCHEDULER_cancel (stage_task); 148 GNUNET_SCHEDULER_cancel(stage_task);
149 stage_task = NULL; 149 stage_task = NULL;
150 } 150 }
151 151
152 if (cc != NULL ) 152 if (cc != NULL)
153 { 153 {
154 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); 154 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
155 cc = NULL; 155 cc = NULL;
156 } 156 }
157 if (p1 != NULL ) 157 if (p1 != NULL)
158 GNUNET_TRANSPORT_TESTING_stop_peer (p1); 158 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
159 if (p2 != NULL ) 159 if (p2 != NULL)
160 GNUNET_TRANSPORT_TESTING_stop_peer (p2); 160 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
161 161
162 ok = GNUNET_SYSERR; 162 ok = GNUNET_SYSERR;
163} 163}
164 164
165static void 165static void
166testing_connect_cb (void *cls) 166testing_connect_cb(void *cls)
167{ 167{
168 cc = NULL; 168 cc = NULL;
169 char *p1_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 169 char *p1_c = GNUNET_strdup(GNUNET_i2s(&p1->id));
170 170
171 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n", 171 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Peers connected: %u (%s) <-> %u (%s)\n",
172 p1->no, p1_c, p2->no, GNUNET_i2s (&p2->id)); 172 p1->no, p1_c, p2->no, GNUNET_i2s(&p2->id));
173 GNUNET_free(p1_c); 173 GNUNET_free(p1_c);
174 connected = GNUNET_YES; 174 connected = GNUNET_YES;
175 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL ); 175 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL);
176} 176}
177 177
178 178
179static void 179static void
180connect_timeout (void *cls) 180connect_timeout(void *cls)
181{ 181{
182 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 182 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
183 "Peers not connected, next stage\n"); 183 "Peers not connected, next stage\n");
184 timeout_task = NULL; 184 timeout_task = NULL;
185 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, 185 stage_task = GNUNET_SCHEDULER_add_now(&run_stage,
186 NULL); 186 NULL);
187} 187}
188 188
189 189
@@ -191,340 +191,339 @@ static int started;
191 191
192 192
193static void 193static void
194start_cb (void *cls) 194start_cb(void *cls)
195{ 195{
196 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 196 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
197
197 started++; 198 started++;
198 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 199 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
199 "Peer %u (`%s') started\n", 200 "Peer %u (`%s') started\n",
200 p->no, 201 p->no,
201 GNUNET_i2s_full (&p->id)); 202 GNUNET_i2s_full(&p->id));
202 203
203 if (started != 2) 204 if (started != 2)
204 return; 205 return;
205 206
206 char *sender_c = GNUNET_strdup (GNUNET_i2s (&p1->id)); 207 char *sender_c = GNUNET_strdup(GNUNET_i2s(&p1->id));
207 208
208 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 209 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
209 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 210 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n",
210 p1->no, 211 p1->no,
211 sender_c, 212 sender_c,
212 p2->no, 213 p2->no,
213 GNUNET_i2s (&p2->id)); 214 GNUNET_i2s(&p2->id));
214 GNUNET_free(sender_c); 215 GNUNET_free(sender_c);
215 216
216 cc = GNUNET_TRANSPORT_TESTING_connect_peers (p1, 217 cc = GNUNET_TRANSPORT_TESTING_connect_peers(p1,
217 p2, 218 p2,
218 &testing_connect_cb, 219 &testing_connect_cb,
219 NULL); 220 NULL);
220
221} 221}
222 222
223 223
224static int 224static int
225check_blacklist_config (const char *cfg_file, 225check_blacklist_config(const char *cfg_file,
226 struct GNUNET_PeerIdentity *peer, 226 struct GNUNET_PeerIdentity *peer,
227 struct GNUNET_PeerIdentity *bl_peer) 227 struct GNUNET_PeerIdentity *bl_peer)
228{ 228{
229 struct GNUNET_CONFIGURATION_Handle *cfg; 229 struct GNUNET_CONFIGURATION_Handle *cfg;
230 char *section; 230 char *section;
231 char *peer_str; 231 char *peer_str;
232 cfg = GNUNET_CONFIGURATION_create (); 232
233 if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg, cfg_file)) 233 cfg = GNUNET_CONFIGURATION_create();
234 { 234 if (GNUNET_OK != GNUNET_CONFIGURATION_load(cfg, cfg_file))
235 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file); 235 {
236 GNUNET_CONFIGURATION_destroy (cfg); 236 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Could not load configuration `%s'\n", cfg_file);
237 return GNUNET_SYSERR; 237 GNUNET_CONFIGURATION_destroy(cfg);
238 } 238 return GNUNET_SYSERR;
239 239 }
240 peer_str = GNUNET_strdup (GNUNET_i2s_full(peer)); 240
241 GNUNET_asprintf (&section, "transport-blacklist-%s", peer_str); 241 peer_str = GNUNET_strdup(GNUNET_i2s_full(peer));
242 242 GNUNET_asprintf(&section, "transport-blacklist-%s", peer_str);
243 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value (cfg, section, GNUNET_i2s_full(bl_peer))) 243
244 { 244 if (GNUNET_NO == GNUNET_CONFIGURATION_have_value(cfg, section, GNUNET_i2s_full(bl_peer)))
245 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 245 {
246 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n", 246 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
247 cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); 247 "Configuration `%s' does not have blacklisting section for peer `%s' blacklisting `%s'\n",
248 GNUNET_CONFIGURATION_destroy (cfg); 248 cfg_file, peer_str, GNUNET_i2s_full(bl_peer));
249 GNUNET_free (section); 249 GNUNET_CONFIGURATION_destroy(cfg);
250 GNUNET_free (peer_str); 250 GNUNET_free(section);
251 return GNUNET_SYSERR; 251 GNUNET_free(peer_str);
252 } 252 return GNUNET_SYSERR;
253 }
253 254
254 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 255 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
255 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n", 256 "Configuration `%s' does have blacklisting section for peer `%s' blacklisting `%s'\n",
256 cfg_file, peer_str, GNUNET_i2s_full(bl_peer)); 257 cfg_file, peer_str, GNUNET_i2s_full(bl_peer));
257 258
258 GNUNET_CONFIGURATION_destroy (cfg); 259 GNUNET_CONFIGURATION_destroy(cfg);
259 GNUNET_free (section); 260 GNUNET_free(section);
260 GNUNET_free (peer_str); 261 GNUNET_free(peer_str);
261 return GNUNET_OK; 262 return GNUNET_OK;
262} 263}
263 264
264 265
265static void 266static void
266run_stage (void *cls) 267run_stage(void *cls)
267{ 268{
268 stage_task = NULL; 269 stage_task = NULL;
269 if (NULL != die_task) 270 if (NULL != die_task)
270 GNUNET_SCHEDULER_cancel (die_task); 271 GNUNET_SCHEDULER_cancel(die_task);
271 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); 272 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
272 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage); 273 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Running stage %u\n", stage);
273 274
274 if (0 == stage) 275 if (0 == stage)
275 {
276 started = GNUNET_NO;
277 connected = GNUNET_NO;
278 if (0 == strcmp (test_name, "test_transport_blacklisting_no_bl"))
279 { 276 {
280 /* Try to connect peers successfully */ 277 started = GNUNET_NO;
281 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 278 connected = GNUNET_NO;
282 "test_transport_blacklisting_cfg_peer1.conf", 279 if (0 == strcmp(test_name, "test_transport_blacklisting_no_bl"))
283 1, 280 {
284 NULL, 281 /* Try to connect peers successfully */
285 NULL, 282 p1 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
286 NULL, 283 "test_transport_blacklisting_cfg_peer1.conf",
287 NULL, 284 1,
288 &start_cb, 285 NULL,
289 NULL); 286 NULL,
290 287 NULL,
291 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth, 288 NULL,
292 "test_transport_blacklisting_cfg_peer2.conf", 289 &start_cb,
293 2, 290 NULL);
294 NULL, 291
295 NULL, 292 p2 = GNUNET_TRANSPORT_TESTING_start_peer(tth,
296 NULL, 293 "test_transport_blacklisting_cfg_peer2.conf",
297 NULL, 294 2,
298 &start_cb, 295 NULL,
299 NULL); 296 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;
300 } 483 }
301 else if (0 == strcmp (test_name,
302 "test_transport_blacklisting_outbound_bl_full"))
303 {
304 const char *cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_full.conf";
305 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf";
306
307 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
308 cfg_p1,
309 1, NULL, NULL, NULL,
310 NULL,
311 &start_cb, NULL);
312 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
313 cfg_p2, 2,
314 NULL, NULL, NULL,
315 NULL,
316 &start_cb, NULL);
317
318 /* check if configuration contain correct blacklist entries */
319 if ( (GNUNET_SYSERR ==
320 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
321 (GNUNET_SYSERR ==
322 check_blacklist_config (cfg_p2, &p2->id, &p1->id)) )
323 {
324 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
325 p1 = NULL;
326 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
327 p2 = NULL;
328 ok = 1;
329 GNUNET_SCHEDULER_add_now (&end, NULL );
330 }
331 484
332 } 485 if (cc != NULL)
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 { 486 {
375 const char *cfg_p1 = "test_transport_blacklisting_cfg_peer1.conf"; 487 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
376 const char *cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_full.conf"; 488 cc = NULL;
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 } 489 }
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 490
433 } 491 if (p1 != NULL)
434 else if (0 == strcmp (test_name,
435 "test_transport_blacklisting_multiple_plugins"))
436 { 492 {
437 const char * cfg_p1 = "test_transport_blacklisting_cfg_blp_peer1_multiple_plugins.conf"; 493 GNUNET_TRANSPORT_TESTING_stop_peer(p1);
438 const char * cfg_p2 = "test_transport_blacklisting_cfg_blp_peer2_multiple_plugins.conf"; 494 p1 = NULL;
439
440 p1 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
441 cfg_p1, 1,
442 NULL,
443 NULL, NULL, NULL,
444 &start_cb, NULL);
445
446 p2 = GNUNET_TRANSPORT_TESTING_start_peer (tth,
447 cfg_p2, 2,
448 NULL,
449 NULL, NULL, NULL,
450 &start_cb, NULL);
451
452 /* check if configuration contain correct blacklist entries */
453 if ( (GNUNET_SYSERR ==
454 check_blacklist_config (cfg_p1, &p1->id, &p2->id)) ||
455 (GNUNET_SYSERR ==
456 check_blacklist_config (cfg_p2, &p2->id, &p1->id)))
457 {
458 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
459 p1 = NULL;
460 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
461 p2 = NULL;
462 ok = 1;
463 GNUNET_SCHEDULER_add_now (&end, NULL);
464 }
465 } 495 }
466 else 496 if (p2 != NULL)
467 { 497 {
468 GNUNET_break (0); 498 GNUNET_TRANSPORT_TESTING_stop_peer(p2);
469 GNUNET_SCHEDULER_add_now (&end, NULL); 499 p2 = NULL;
470 } 500 }
471 501
472 if ((NULL == p1) || (NULL == p2))
473 {
474 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start peers\n");
475 ok = 1;
476 GNUNET_SCHEDULER_add_now (&end, NULL);
477 }
478
479 timeout_task = GNUNET_SCHEDULER_add_delayed (CONNECT_TIMEOUT,
480 &connect_timeout,
481 NULL);
482 stage++;
483 return;
484 }
485
486 if (cc != NULL )
487 {
488 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc);
489 cc = NULL;
490 }
491
492 if (p1 != NULL )
493 {
494 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
495 p1 = NULL;
496 }
497 if (p2 != NULL )
498 {
499 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
500 p2 = NULL;
501 }
502
503 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n", 502 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done in stage %u: Peers %s and %s!\n",
504 stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED", 503 stage, (GNUNET_NO == started) ? "NOT STARTED" : "STARTED",
505 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED"); 504 (GNUNET_YES == connected) ? "CONNECTED" : "NOT CONNECTED");
506 505
507 if ((0 == strcmp (test_name, "test_transport_blacklisting_no_bl")) 506 if ((0 == strcmp(test_name, "test_transport_blacklisting_no_bl"))
508 || (0 == strcmp (test_name, "test_transport_blacklisting_multiple_plugins"))) 507 || (0 == strcmp(test_name, "test_transport_blacklisting_multiple_plugins")))
509 {
510 if ((GNUNET_NO != started) && (GNUNET_YES == connected))
511 ok = 0;
512 else
513 { 508 {
514 GNUNET_break(0); 509 if ((GNUNET_NO != started) && (GNUNET_YES == connected))
515 ok = 1; 510 ok = 0;
511 else
512 {
513 GNUNET_break(0);
514 ok = 1;
515 }
516 } 516 }
517 }
518 else 517 else
519 {
520 if ((GNUNET_NO != started) && (GNUNET_YES != connected))
521 ok = 0;
522 else
523 { 518 {
524 ok = 1; 519 if ((GNUNET_NO != started) && (GNUNET_YES != connected))
520 ok = 0;
521 else
522 {
523 ok = 1;
524 }
525 } 525 }
526 } 526 GNUNET_SCHEDULER_add_now(&end, NULL);
527 GNUNET_SCHEDULER_add_now (&end, NULL );
528} 527}
529 528
530static void 529static void
@@ -534,7 +533,7 @@ run(void *cls, char * const *args, const char *cfgfile,
534 connected = GNUNET_NO; 533 connected = GNUNET_NO;
535 stage = 0; 534 stage = 0;
536 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name); 535 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Running test `%s'!\n", test_name);
537 stage_task = GNUNET_SCHEDULER_add_now (&run_stage, NULL ); 536 stage_task = GNUNET_SCHEDULER_add_now(&run_stage, NULL);
538} 537}
539 538
540int 539int
@@ -542,21 +541,21 @@ main(int argc, char *argv0[])
542{ 541{
543 ok = 1; 542 ok = 1;
544 543
545 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0[0]); 544 test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0[0]);
546 545
547 GNUNET_log_setup ("test-transport-api-blacklisting", "WARNING", NULL ); 546 GNUNET_log_setup("test-transport-api-blacklisting", "WARNING", NULL);
548 547
549 static char * const argv[] = 548 static char * const argv[] =
550 { "date", "-c", "test_transport_api_data.conf", NULL }; 549 { "date", "-c", "test_transport_api_data.conf", NULL };
551 static struct GNUNET_GETOPT_CommandLineOption options[] = 550 static struct GNUNET_GETOPT_CommandLineOption options[] =
552 { GNUNET_GETOPT_OPTION_END }; 551 { GNUNET_GETOPT_OPTION_END };
553 552
554 tth = GNUNET_TRANSPORT_TESTING_init (); 553 tth = GNUNET_TRANSPORT_TESTING_init();
555 554
556 GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, argv, 555 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, argv,
557 "test-transport-api-blacklisting", "nohelp", options, &run, NULL ); 556 "test-transport-api-blacklisting", "nohelp", options, &run, NULL);
558 557
559 GNUNET_TRANSPORT_TESTING_done (tth); 558 GNUNET_TRANSPORT_TESTING_done(tth);
560 559
561 return ok; 560 return ok;
562} 561}
diff --git a/src/transport/test_transport_testing_restart.c b/src/transport/test_transport_testing_restart.c
index 4df8b2d6d..d47696018 100644
--- a/src/transport/test_transport_testing_restart.c
+++ b/src/transport/test_transport_testing_restart.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_testing_restart.c 21 * @file transport/test_transport_testing_restart.c
22 * @brief test case for transport testing library: 22 * @brief test case for transport testing library:
@@ -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,124 +39,123 @@ 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",
143 "test_transport_api_data.conf", 143 "test_transport_api_data.conf",
144 NULL 144 NULL };
145 };
146 struct GNUNET_GETOPT_CommandLineOption options[] = { 145 struct GNUNET_GETOPT_CommandLineOption options[] = {
147 GNUNET_GETOPT_OPTION_END 146 GNUNET_GETOPT_OPTION_END
148 }; 147 };
149 148
150 GNUNET_log_setup ("test_transport_testing_restart", 149 GNUNET_log_setup("test_transport_testing_restart",
151 "WARNING", 150 "WARNING",
152 NULL); 151 NULL);
153 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, 152 GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1,
154 argv_1, 153 argv_1,
155 "test_transport_testing_restart", 154 "test_transport_testing_restart",
156 "nohelp", 155 "nohelp",
157 options, 156 options,
158 &run, 157 &run,
159 NULL); 158 NULL);
160 return ret; 159 return ret;
161} 160}
162 161
diff --git a/src/transport/test_transport_testing_startstop.c b/src/transport/test_transport_testing_startstop.c
index 57b6840a5..c57b24054 100644
--- a/src/transport/test_transport_testing_startstop.c
+++ b/src/transport/test_transport_testing_startstop.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/test_transport_testing_startstop.c 21 * @file transport/test_transport_testing_startstop.c
22 * @brief test case for transport testing library: 22 * @brief test case for transport testing library:
@@ -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,98 +39,97 @@ 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",
118 "test_transport_api_data.conf", 118 "test_transport_api_data.conf",
119 NULL 119 NULL };
120 };
121 struct GNUNET_GETOPT_CommandLineOption options[] = { 120 struct GNUNET_GETOPT_CommandLineOption options[] = {
122 GNUNET_GETOPT_OPTION_END 121 GNUNET_GETOPT_OPTION_END
123 }; 122 };
124 123
125 GNUNET_log_setup ("test_transport_testing_startstop", 124 GNUNET_log_setup("test_transport_testing_startstop",
126 "WARNING", 125 "WARNING",
127 NULL); 126 NULL);
128 GNUNET_PROGRAM_run ((sizeof (argv_1) / sizeof (char *)) - 1, 127 GNUNET_PROGRAM_run((sizeof(argv_1) / sizeof(char *)) - 1,
129 argv_1, 128 argv_1,
130 "test_transport_testing_startstop", "nohelp", 129 "test_transport_testing_startstop", "nohelp",
131 options, 130 options,
132 &run, 131 &run,
133 &ret); 132 &ret);
134 133
135 return ret; 134 return ret;
136} 135}
diff --git a/src/transport/transport-testing-filenames.c b/src/transport/transport-testing-filenames.c
index 4c2fbd3f5..865907007 100644
--- a/src/transport/transport-testing-filenames.c
+++ b/src/transport/transport-testing-filenames.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport-testing-filenames.c 21 * @file transport-testing-filenames.c
22 * @brief convenience string manipulation functions for tests 22 * @brief convenience string manipulation functions for tests
@@ -33,49 +33,49 @@
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 WINDOWS 43#if WINDOWS
44 if ((strlen (pch) >= 3) && pch[1] == ':') 44 if ((strlen(pch) >= 3) && pch[1] == ':')
45 {
46 if (NULL != strstr (pch, "\\"))
47 { 45 {
48 pch = strtok (pch, "\\"); 46 if (NULL != strstr(pch, "\\"))
49 while (pch != NULL) 47 {
50 { 48 pch = strtok(pch, "\\");
51 pch = strtok (NULL, "\\"); 49 while (pch != NULL)
52 if (pch != NULL) 50 {
53 filename = pch; 51 pch = strtok(NULL, "\\");
54 } 52 if (pch != NULL)
53 filename = pch;
54 }
55 }
55 } 56 }
56 }
57 if (filename != NULL) 57 if (filename != NULL)
58 pch = filename; /* If we miss the next condition, filename = pch will 58 pch = filename; /* If we miss the next condition, filename = pch will
59 * not harm us. 59 * not harm us.
60 */ 60 */
61#endif 61#endif
62 if (NULL != strstr (pch, "/")) 62 if (NULL != strstr(pch, "/"))
63 {
64 pch = strtok (pch, "/");
65 while (pch != NULL)
66 { 63 {
67 pch = strtok (NULL, "/"); 64 pch = strtok(pch, "/");
68 if (pch != NULL) 65 while (pch != NULL)
69 { 66 {
70 filename = pch; 67 pch = strtok(NULL, "/");
71 } 68 if (pch != NULL)
69 {
70 filename = pch;
71 }
72 }
72 } 73 }
73 }
74 else 74 else
75 filename = pch; 75 filename = pch;
76 76
77 res = GNUNET_strdup (filename); 77 res = GNUNET_strdup(filename);
78 GNUNET_free (backup); 78 GNUNET_free(backup);
79 return res; 79 return res;
80} 80}
81 81
@@ -88,9 +88,9 @@ extract_filename (const char *file)
88 * @return the result 88 * @return the result
89 */ 89 */
90char * 90char *
91GNUNET_TRANSPORT_TESTING_get_test_name (const char *file) 91GNUNET_TRANSPORT_TESTING_get_test_name(const char *file)
92{ 92{
93 char *backup = extract_filename (file); 93 char *backup = extract_filename(file);
94 char *filename = backup; 94 char *filename = backup;
95 char *dotexe; 95 char *dotexe;
96 char *ret; 96 char *ret;
@@ -99,18 +99,18 @@ GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
99 return NULL; 99 return NULL;
100 100
101 /* remove "lt-" */ 101 /* remove "lt-" */
102 filename = strstr (filename, "test"); 102 filename = strstr(filename, "test");
103 if (NULL == filename) 103 if (NULL == filename)
104 { 104 {
105 GNUNET_free (backup); 105 GNUNET_free(backup);
106 return NULL; 106 return NULL;
107 } 107 }
108 108
109 /* remove ".exe" */ 109 /* remove ".exe" */
110 if (NULL != (dotexe = strstr (filename, ".exe"))) 110 if (NULL != (dotexe = strstr(filename, ".exe")))
111 dotexe[0] = '\0'; 111 dotexe[0] = '\0';
112 ret = GNUNET_strdup (filename); 112 ret = GNUNET_strdup(filename);
113 GNUNET_free (backup); 113 GNUNET_free(backup);
114 return ret; 114 return ret;
115} 115}
116 116
@@ -122,12 +122,12 @@ GNUNET_TRANSPORT_TESTING_get_test_name (const char *file)
122 * @return the result 122 * @return the result
123 */ 123 */
124char * 124char *
125GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file) 125GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file)
126{ 126{
127 char *src = extract_filename (file); 127 char *src = extract_filename(file);
128 char *split; 128 char *split;
129 129
130 split = strstr (src, "."); 130 split = strstr(src, ".");
131 if (NULL != split) 131 if (NULL != split)
132 split[0] = '\0'; 132 split[0] = '\0';
133 return src; 133 return src;
@@ -142,40 +142,40 @@ GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file)
142 * @return the result 142 * @return the result
143 */ 143 */
144char * 144char *
145GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *file, 145GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *file,
146 const char *test) 146 const char *test)
147{ 147{
148 char *filename; 148 char *filename;
149 char *dotexe; 149 char *dotexe;
150 char *e = extract_filename (file); 150 char *e = extract_filename(file);
151 char *t = extract_filename (test); 151 char *t = extract_filename(test);
152 char *ret; 152 char *ret;
153 153
154 if (NULL == e) 154 if (NULL == e)
155 goto fail; 155 goto fail;
156 /* remove "lt-" */ 156 /* remove "lt-" */
157 filename = strstr (e, "tes"); 157 filename = strstr(e, "tes");
158 if (NULL == filename) 158 if (NULL == filename)
159 goto fail; 159 goto fail;
160 /* remove ".exe" */ 160 /* remove ".exe" */
161 if (NULL != (dotexe = strstr (filename, ".exe"))) 161 if (NULL != (dotexe = strstr(filename, ".exe")))
162 dotexe[0] = '\0'; 162 dotexe[0] = '\0';
163 163
164 /* find last _ */ 164 /* find last _ */
165 filename = strstr (filename, t); 165 filename = strstr(filename, t);
166 if (NULL == filename) 166 if (NULL == filename)
167 goto fail; 167 goto fail;
168 /* copy plugin */ 168 /* copy plugin */
169 filename += strlen (t); 169 filename += strlen(t);
170 if ('\0' != *filename) 170 if ('\0' != *filename)
171 filename++; 171 filename++;
172 ret = GNUNET_strdup (filename); 172 ret = GNUNET_strdup(filename);
173 goto suc; 173 goto suc;
174fail: 174fail:
175 ret = NULL; 175 ret = NULL;
176suc: 176suc:
177 GNUNET_free (t); 177 GNUNET_free(t);
178 GNUNET_free (e); 178 GNUNET_free(e);
179 return ret; 179 return ret;
180} 180}
181 181
@@ -189,10 +189,10 @@ suc:
189 * @return the result 189 * @return the result
190 */ 190 */
191char * 191char *
192GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, 192GNUNET_TRANSPORT_TESTING_get_config_name(const char *file,
193 int count) 193 int count)
194{ 194{
195 char *filename = extract_filename (file); 195 char *filename = extract_filename(file);
196 char *backup = filename; 196 char *backup = filename;
197 char *dotexe; 197 char *dotexe;
198 char *ret; 198 char *ret;
@@ -200,20 +200,20 @@ GNUNET_TRANSPORT_TESTING_get_config_name (const char *file,
200 if (NULL == filename) 200 if (NULL == filename)
201 return NULL; 201 return NULL;
202 /* remove "lt-" */ 202 /* remove "lt-" */
203 filename = strstr (filename, "test"); 203 filename = strstr(filename, "test");
204 if (NULL == filename) 204 if (NULL == filename)
205 goto fail; 205 goto fail;
206 /* remove ".exe" */ 206 /* remove ".exe" */
207 if (NULL != (dotexe = strstr (filename, ".exe"))) 207 if (NULL != (dotexe = strstr(filename, ".exe")))
208 dotexe[0] = '\0'; 208 dotexe[0] = '\0';
209 GNUNET_asprintf (&ret, 209 GNUNET_asprintf(&ret,
210 "%s_peer%u.conf", 210 "%s_peer%u.conf",
211 filename, 211 filename,
212 count); 212 count);
213 GNUNET_free (backup); 213 GNUNET_free(backup);
214 return ret; 214 return ret;
215fail: 215fail:
216 GNUNET_free (backup); 216 GNUNET_free(backup);
217 return NULL; 217 return NULL;
218} 218}
219 219
diff --git a/src/transport/transport-testing-loggers.c b/src/transport/transport-testing-loggers.c
index 6ad181e87..5fb7f2233 100644
--- a/src/transport/transport-testing-loggers.c
+++ b/src/transport/transport-testing-loggers.c
@@ -12,12 +12,12 @@
12 WITHOUT ANY WARRANTY; without even the implied warranty of 12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Affero General Public License for more details. 14 Affero General Public License for more details.
15 15
16 You should have received a copy of the GNU Affero General Public License 16 You should have received a copy of the GNU Affero General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 SPDX-License-Identifier: AGPL3.0-or-later 19 SPDX-License-Identifier: AGPL3.0-or-later
20*/ 20 */
21/** 21/**
22 * @file transport-testing-loggers.c 22 * @file transport-testing-loggers.c
23 * @brief convenience functions for logging common events in tests 23 * @brief convenience functions for logging common events in tests
@@ -34,19 +34,19 @@
34 * @param other peer that connected. 34 * @param other peer that connected.
35 */ 35 */
36void 36void
37GNUNET_TRANSPORT_TESTING_log_connect (void *cls, 37GNUNET_TRANSPORT_TESTING_log_connect(void *cls,
38 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 38 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
39 const struct GNUNET_PeerIdentity *other) 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,19 @@ 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 GNUNET_TRANSPORT_TESTING_PeerContext *me,
64 const struct GNUNET_PeerIdentity *other) 64 const struct GNUNET_PeerIdentity *other)
65{ 65{
66 char *ps; 66 char *ps;
67 67
68 ps = GNUNET_strdup (GNUNET_i2s (&me->id)); 68 ps = GNUNET_strdup(GNUNET_i2s(&me->id));
69 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 69 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
70 "Peer `%s' disconnected from %u (%s)!\n", 70 "Peer `%s' disconnected from %u (%s)!\n",
71 GNUNET_i2s (other), 71 GNUNET_i2s(other),
72 me->no, 72 me->no,
73 ps); 73 ps);
74 GNUNET_free (ps); 74 GNUNET_free(ps);
75} 75}
76 76
77/* end of transport-testing-loggers.c */ 77/* end of transport-testing-loggers.c */
diff --git a/src/transport/transport-testing-main.c b/src/transport/transport-testing-main.c
index 6cef20ba1..7e7b0df4b 100644
--- a/src/transport/transport-testing-main.c
+++ b/src/transport/transport-testing-main.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport-testing-main.c 21 * @file transport-testing-main.c
22 * @brief convenience main function for tests 22 * @brief convenience main function for tests
@@ -28,8 +28,7 @@
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{
33 /** 32 /**
34 * Stored in a DLL. 33 * Stored in a DLL.
35 */ 34 */
@@ -59,7 +58,6 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList
59 * Peer being connected. 58 * Peer being connected.
60 */ 59 */
61 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2; 60 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2;
62
63}; 61};
64 62
65 63
@@ -69,41 +67,41 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequestList
69 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` 67 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *`
70 */ 68 */
71static void 69static void
72do_shutdown (void *cls) 70do_shutdown(void *cls)
73{ 71{
74 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 72 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
75 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl; 73 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
76 74
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 75 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
78 "Testcase shutting down\n"); 76 "Testcase shutting down\n");
79 if (NULL != ccc->shutdown_task) 77 if (NULL != ccc->shutdown_task)
80 ccc->shutdown_task (ccc->shutdown_task_cls); 78 ccc->shutdown_task(ccc->shutdown_task_cls);
81 if (NULL != ccc->timeout_task) 79 if (NULL != ccc->timeout_task)
82 { 80 {
83 GNUNET_SCHEDULER_cancel (ccc->timeout_task); 81 GNUNET_SCHEDULER_cancel(ccc->timeout_task);
84 ccc->timeout_task = NULL; 82 ccc->timeout_task = NULL;
85 } 83 }
86 if (NULL != ccc->connect_task) 84 if (NULL != ccc->connect_task)
87 { 85 {
88 GNUNET_SCHEDULER_cancel (ccc->connect_task); 86 GNUNET_SCHEDULER_cancel(ccc->connect_task);
89 ccc->connect_task = NULL; 87 ccc->connect_task = NULL;
90 } 88 }
91 while (NULL != (crl = ccc->crl_head)) 89 while (NULL != (crl = ccc->crl_head))
92 {
93 GNUNET_CONTAINER_DLL_remove (ccc->crl_head,
94 ccc->crl_tail,
95 crl);
96 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (crl->cr);
97 GNUNET_free (crl);
98 }
99 for (unsigned int i=0;i<ccc->num_peers;i++)
100 {
101 if (NULL != ccc->p[i])
102 { 90 {
103 GNUNET_TRANSPORT_TESTING_stop_peer (ccc->p[i]); 91 GNUNET_CONTAINER_DLL_remove(ccc->crl_head,
104 ccc->p[i] = NULL; 92 ccc->crl_tail,
93 crl);
94 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(crl->cr);
95 GNUNET_free(crl);
96 }
97 for (unsigned int i = 0; i < ccc->num_peers; i++)
98 {
99 if (NULL != ccc->p[i])
100 {
101 GNUNET_TRANSPORT_TESTING_stop_peer(ccc->p[i]);
102 ccc->p[i] = NULL;
103 }
105 } 104 }
106 }
107} 105}
108 106
109 107
@@ -113,15 +111,15 @@ do_shutdown (void *cls)
113 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *` 111 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *`
114 */ 112 */
115static void 113static void
116do_timeout (void *cls) 114do_timeout(void *cls)
117{ 115{
118 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 116 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
119 117
120 ccc->timeout_task = NULL; 118 ccc->timeout_task = NULL;
121 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 119 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
122 "Testcase timed out\n"); 120 "Testcase timed out\n");
123 ccc->global_ret = GNUNET_SYSERR; 121 ccc->global_ret = GNUNET_SYSERR;
124 GNUNET_SCHEDULER_shutdown (); 122 GNUNET_SCHEDULER_shutdown();
125} 123}
126 124
127 125
@@ -130,8 +128,7 @@ do_timeout (void *cls)
130 * #connect_cb, #disconnect_cb, #my_nc and #start_cb. 128 * #connect_cb, #disconnect_cb, #my_nc and #start_cb.
131 * Allows us to identify which peer this is about. 129 * Allows us to identify which peer this is about.
132 */ 130 */
133struct GNUNET_TRANSPORT_TESTING_InternalPeerContext 131struct GNUNET_TRANSPORT_TESTING_InternalPeerContext {
134{
135 /** 132 /**
136 * Overall context of the callback. 133 * Overall context of the callback.
137 */ 134 */
@@ -147,8 +144,7 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext
147/** 144/**
148 * Information tracked per connected peer. 145 * Information tracked per connected peer.
149 */ 146 */
150struct ConnectPairInfo 147struct ConnectPairInfo {
151{
152 /** 148 /**
153 * Peer this is about. 149 * Peer this is about.
154 */ 150 */
@@ -168,33 +164,33 @@ struct ConnectPairInfo
168 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *` 164 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *`
169 */ 165 */
170static void 166static void
171connect_cb (void *cls) 167connect_cb(void *cls)
172{ 168{
173 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls; 169 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl = cls;
174 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc; 170 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = crl->ccc;
175 171
176 GNUNET_CONTAINER_DLL_remove (ccc->crl_head, 172 GNUNET_CONTAINER_DLL_remove(ccc->crl_head,
177 ccc->crl_tail, 173 ccc->crl_tail,
178 crl); 174 crl);
179 { 175 {
180 char *p1_c = GNUNET_strdup (GNUNET_i2s (&crl->p1->id)); 176 char *p1_c = GNUNET_strdup(GNUNET_i2s(&crl->p1->id));
181 177
182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 178 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
183 "Peers connected: %u (%s) <-> %u (%s)\n", 179 "Peers connected: %u (%s) <-> %u (%s)\n",
184 crl->p1->no, 180 crl->p1->no,
185 p1_c, 181 p1_c,
186 crl->p2->no, 182 crl->p2->no,
187 GNUNET_i2s (&crl->p2->id)); 183 GNUNET_i2s(&crl->p2->id));
188 GNUNET_free (p1_c); 184 GNUNET_free(p1_c);
189 GNUNET_free (crl); 185 GNUNET_free(crl);
190 } 186 }
191 if (NULL == ccc->crl_head) 187 if (NULL == ccc->crl_head)
192 { 188 {
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
194 "All connections UP, launching custom test logic.\n"); 190 "All connections UP, launching custom test logic.\n");
195 GNUNET_SCHEDULER_add_now (ccc->connect_continuation, 191 GNUNET_SCHEDULER_add_now(ccc->connect_continuation,
196 ccc->connect_continuation_cls); 192 ccc->connect_continuation_cls);
197 } 193 }
198} 194}
199 195
200 196
@@ -206,14 +202,14 @@ connect_cb (void *cls)
206 * @return NULL if @a peer was not found 202 * @return NULL if @a peer was not found
207 */ 203 */
208struct GNUNET_TRANSPORT_TESTING_PeerContext * 204struct GNUNET_TRANSPORT_TESTING_PeerContext *
209GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 205GNUNET_TRANSPORT_TESTING_find_peer(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
210 const struct GNUNET_PeerIdentity *peer) 206 const struct GNUNET_PeerIdentity *peer)
211{ 207{
212 for (unsigned int i=0;i<ccc->num_peers;i++) 208 for (unsigned int i = 0; i < ccc->num_peers; i++)
213 if ( (NULL != ccc->p[i]) && 209 if ((NULL != ccc->p[i]) &&
214 (0 == memcmp (peer, 210 (0 == memcmp(peer,
215 &ccc->p[i]->id, 211 &ccc->p[i]->id,
216 sizeof (*peer))) ) 212 sizeof(*peer))))
217 return ccc->p[i]; 213 return ccc->p[i];
218 return NULL; 214 return NULL;
219} 215}
@@ -228,19 +224,19 @@ GNUNET_TRANSPORT_TESTING_find_peer (struct GNUNET_TRANSPORT_TESTING_ConnectCheck
228 * @return closure for message handlers 224 * @return closure for message handlers
229 */ 225 */
230static void * 226static void *
231my_nc (void *cls, 227my_nc(void *cls,
232 const struct GNUNET_PeerIdentity *peer, 228 const struct GNUNET_PeerIdentity *peer,
233 struct GNUNET_MQ_Handle *mq) 229 struct GNUNET_MQ_Handle *mq)
234{ 230{
235 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 231 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
236 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 232 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
237 struct ConnectPairInfo *cpi; 233 struct ConnectPairInfo *cpi;
238 234
239 if (NULL != ccc->nc) 235 if (NULL != ccc->nc)
240 ccc->nc (ccc->cls, 236 ccc->nc(ccc->cls,
241 ccc->p[ipi->off], 237 ccc->p[ipi->off],
242 peer); 238 peer);
243 cpi = GNUNET_new (struct ConnectPairInfo); 239 cpi = GNUNET_new(struct ConnectPairInfo);
244 cpi->ipi = ipi; 240 cpi->ipi = ipi;
245 cpi->sender = peer; /* valid until disconnect */ 241 cpi->sender = peer; /* valid until disconnect */
246 return cpi; 242 return cpi;
@@ -255,19 +251,19 @@ my_nc (void *cls,
255 * @param custom_cls return value from @my_nc 251 * @param custom_cls return value from @my_nc
256 */ 252 */
257static void 253static void
258my_nd (void *cls, 254my_nd(void *cls,
259 const struct GNUNET_PeerIdentity *peer, 255 const struct GNUNET_PeerIdentity *peer,
260 void *custom_cls) 256 void *custom_cls)
261{ 257{
262 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 258 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
263 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 259 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
264 struct ConnectPairInfo *cpi = custom_cls; 260 struct ConnectPairInfo *cpi = custom_cls;
265 261
266 if (NULL != ccc->nd) 262 if (NULL != ccc->nd)
267 ccc->nd (ccc->cls, 263 ccc->nd(ccc->cls,
268 ccc->p[ipi->off], 264 ccc->p[ipi->off],
269 peer); 265 peer);
270 GNUNET_free (cpi); 266 GNUNET_free(cpi);
271} 267}
272 268
273 269
@@ -279,8 +275,8 @@ my_nd (void *cls,
279 * @return #GNUNET_OK (all messages are fine) 275 * @return #GNUNET_OK (all messages are fine)
280 */ 276 */
281static int 277static int
282check_test (void *cls, 278check_test(void *cls,
283 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 279 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
284{ 280{
285 return GNUNET_OK; 281 return GNUNET_OK;
286} 282}
@@ -293,18 +289,18 @@ check_test (void *cls,
293 * @param message message we received 289 * @param message message we received
294 */ 290 */
295static void 291static void
296handle_test (void *cls, 292handle_test(void *cls,
297 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 293 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
298{ 294{
299 struct ConnectPairInfo *cpi = cls; 295 struct ConnectPairInfo *cpi = cls;
300 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; 296 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
301 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 297 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
302 298
303 if (NULL != ccc->rec) 299 if (NULL != ccc->rec)
304 ccc->rec (ccc->cls, 300 ccc->rec(ccc->cls,
305 ccc->p[ipi->off], 301 ccc->p[ipi->off],
306 cpi->sender, 302 cpi->sender,
307 message); 303 message);
308} 304}
309 305
310 306
@@ -316,8 +312,8 @@ handle_test (void *cls,
316 * @return #GNUNET_OK (all messages are fine) 312 * @return #GNUNET_OK (all messages are fine)
317 */ 313 */
318static int 314static int
319check_test2 (void *cls, 315check_test2(void *cls,
320 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 316 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
321{ 317{
322 return GNUNET_OK; 318 return GNUNET_OK;
323} 319}
@@ -330,18 +326,18 @@ check_test2 (void *cls,
330 * @param message message we received 326 * @param message message we received
331 */ 327 */
332static void 328static void
333handle_test2 (void *cls, 329handle_test2(void *cls,
334 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message) 330 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
335{ 331{
336 struct ConnectPairInfo *cpi = cls; 332 struct ConnectPairInfo *cpi = cls;
337 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi; 333 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cpi->ipi;
338 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 334 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
339 335
340 if (NULL != ccc->rec) 336 if (NULL != ccc->rec)
341 ccc->rec (ccc->cls, 337 ccc->rec(ccc->cls,
342 ccc->p[ipi->off], 338 ccc->p[ipi->off],
343 cpi->sender, 339 cpi->sender,
344 message); 340 message);
345} 341}
346 342
347 343
@@ -351,41 +347,41 @@ handle_test2 (void *cls,
351 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 347 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
352 */ 348 */
353static void 349static void
354do_connect (void *cls) 350do_connect(void *cls)
355{ 351{
356 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 352 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
357 353
358 ccc->connect_task = NULL; 354 ccc->connect_task = NULL;
359 for (unsigned int i=0;i<ccc->num_peers;i++) 355 for (unsigned int i = 0; i < ccc->num_peers; i++)
360 for (unsigned int j=(ccc->bi_directional ? 0 : i+1);j<ccc->num_peers;j++) 356 for (unsigned int j = (ccc->bi_directional ? 0 : i + 1); j < ccc->num_peers; j++)
361 {
362 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
363
364 if (i == j)
365 continue;
366 crl = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequestList);
367 GNUNET_CONTAINER_DLL_insert (ccc->crl_head,
368 ccc->crl_tail,
369 crl);
370 crl->ccc = ccc;
371 crl->p1 = ccc->p[i];
372 crl->p2 = ccc->p[j];
373 { 357 {
374 char *sender_c = GNUNET_strdup (GNUNET_i2s (&ccc->p[0]->id)); 358 struct GNUNET_TRANSPORT_TESTING_ConnectRequestList *crl;
375 359
376 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 360 if (i == j)
377 "Test tries to connect peer %u (`%s') -> peer %u (`%s')\n", 361 continue;
378 ccc->p[0]->no, 362 crl = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequestList);
379 sender_c, 363 GNUNET_CONTAINER_DLL_insert(ccc->crl_head,
380 ccc->p[1]->no, 364 ccc->crl_tail,
381 GNUNET_i2s (&ccc->p[1]->id)); 365 crl);
382 GNUNET_free (sender_c); 366 crl->ccc = ccc;
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);
383 } 384 }
384 crl->cr = GNUNET_TRANSPORT_TESTING_connect_peers (ccc->p[i],
385 ccc->p[j],
386 &connect_cb,
387 crl);
388 }
389} 385}
390 386
391 387
@@ -397,32 +393,32 @@ do_connect (void *cls)
397 * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *` 393 * @param cls our `struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *`
398 */ 394 */
399static void 395static void
400start_cb (void *cls) 396start_cb(void *cls)
401{ 397{
402 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls; 398 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext *ipi = cls;
403 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc; 399 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = ipi->ccc;
404 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off]; 400 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = ccc->p[ipi->off];
405 401
406 ccc->started++; 402 ccc->started++;
407 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 403 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
408 "Peer %u (`%s') started\n", 404 "Peer %u (`%s') started\n",
409 p->no, 405 p->no,
410 GNUNET_i2s (&p->id)); 406 GNUNET_i2s(&p->id));
411 if (ccc->started != ccc->num_peers) 407 if (ccc->started != ccc->num_peers)
412 return; 408 return;
413 if (NULL != ccc->pre_connect_task) 409 if (NULL != ccc->pre_connect_task)
414 { 410 {
415 /* Run the custom per-connect job, then give it a second to 411 /* Run the custom per-connect job, then give it a second to
416 go into effect before we continue connecting peers. */ 412 go into effect before we continue connecting peers. */
417 ccc->pre_connect_task (ccc->pre_connect_task_cls); 413 ccc->pre_connect_task(ccc->pre_connect_task_cls);
418 ccc->connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 414 ccc->connect_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
419 &do_connect, 415 &do_connect,
420 ccc); 416 ccc);
421 } 417 }
422 else 418 else
423 { 419 {
424 do_connect (ccc); 420 do_connect(ccc);
425 } 421 }
426} 422}
427 423
428 424
@@ -437,52 +433,52 @@ start_cb (void *cls)
437 * @param cfg configuration 433 * @param cfg configuration
438 */ 434 */
439static void 435static void
440connect_check_run (void *cls, 436connect_check_run(void *cls,
441 char *const *args, 437 char *const *args,
442 const char *cfgfile, 438 const char *cfgfile,
443 const struct GNUNET_CONFIGURATION_Handle *cfg) 439 const struct GNUNET_CONFIGURATION_Handle *cfg)
444{ 440{
445 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls; 441 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc = cls;
446 int ok; 442 int ok;
447 443
448 ccc->cfg = cfg; 444 ccc->cfg = cfg;
449 ccc->timeout_task = GNUNET_SCHEDULER_add_delayed (ccc->timeout, 445 ccc->timeout_task = GNUNET_SCHEDULER_add_delayed(ccc->timeout,
450 &do_timeout, 446 &do_timeout,
451 ccc); 447 ccc);
452 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 448 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
453 ccc); 449 ccc);
454 ok = GNUNET_OK; 450 ok = GNUNET_OK;
455 for (unsigned int i=0;i<ccc->num_peers;i++) 451 for (unsigned int i = 0; i < ccc->num_peers; i++)
456 { 452 {
457 struct GNUNET_MQ_MessageHandler handlers[] = { 453 struct GNUNET_MQ_MessageHandler handlers[] = {
458 GNUNET_MQ_hd_var_size (test, 454 GNUNET_MQ_hd_var_size(test,
459 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 455 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
460 struct GNUNET_TRANSPORT_TESTING_TestMessage, 456 struct GNUNET_TRANSPORT_TESTING_TestMessage,
461 NULL), 457 NULL),
462 GNUNET_MQ_hd_var_size (test2, 458 GNUNET_MQ_hd_var_size(test2,
463 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2, 459 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
464 struct GNUNET_TRANSPORT_TESTING_TestMessage, 460 struct GNUNET_TRANSPORT_TESTING_TestMessage,
465 NULL), 461 NULL),
466 GNUNET_MQ_handler_end() 462 GNUNET_MQ_handler_end()
467 }; 463 };
468 ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer (ccc->tth, 464 ccc->p[i] = GNUNET_TRANSPORT_TESTING_start_peer(ccc->tth,
469 ccc->cfg_files[i], 465 ccc->cfg_files[i],
470 i + 1, 466 i + 1,
471 handlers, 467 handlers,
472 &my_nc, 468 &my_nc,
473 &my_nd, 469 &my_nd,
474 &ccc->ip[i], 470 &ccc->ip[i],
475 &start_cb, 471 &start_cb,
476 &ccc->ip[i]); 472 &ccc->ip[i]);
477 if (NULL == ccc->p[i]) 473 if (NULL == ccc->p[i])
478 ok = GNUNET_SYSERR; 474 ok = GNUNET_SYSERR;
479 } 475 }
480 if (GNUNET_OK != ok) 476 if (GNUNET_OK != ok)
481 { 477 {
482 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 478 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
483 "Fail! Could not start peers!\n"); 479 "Fail! Could not start peers!\n");
484 GNUNET_SCHEDULER_shutdown (); 480 GNUNET_SCHEDULER_shutdown();
485 } 481 }
486} 482}
487 483
488 484
@@ -502,12 +498,12 @@ connect_check_run (void *cls,
502 * @return #GNUNET_SYSERR on error 498 * @return #GNUNET_SYSERR on error
503 */ 499 */
504int 500int
505GNUNET_TRANSPORT_TESTING_connect_check (void *cls, 501GNUNET_TRANSPORT_TESTING_connect_check(void *cls,
506 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 502 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
507 const char *test_plugin_, 503 const char *test_plugin_,
508 const char *test_name_, 504 const char *test_name_,
509 unsigned int num_peers, 505 unsigned int num_peers,
510 char *cfg_files[]) 506 char *cfg_files[])
511{ 507{
512 static struct GNUNET_GETOPT_CommandLineOption options[] = { 508 static struct GNUNET_GETOPT_CommandLineOption options[] = {
513 GNUNET_GETOPT_OPTION_END 509 GNUNET_GETOPT_OPTION_END
@@ -516,9 +512,9 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls,
516 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers]; 512 struct GNUNET_TRANSPORT_TESTING_PeerContext *p[num_peers];
517 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers]; 513 struct GNUNET_TRANSPORT_TESTING_InternalPeerContext ip[num_peers];
518 char * argv[] = { 514 char * argv[] = {
519 (char *) test_name_, 515 (char *)test_name_,
520 "-c", 516 "-c",
521 (char *) ccc->config_file, 517 (char *)ccc->config_file,
522 NULL 518 NULL
523 }; 519 };
524 520
@@ -530,19 +526,19 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls,
530 ccc->global_ret = GNUNET_OK; 526 ccc->global_ret = GNUNET_OK;
531 ccc->p = p; 527 ccc->p = p;
532 ccc->ip = ip; 528 ccc->ip = ip;
533 for (unsigned int i=0;i<num_peers;i++) 529 for (unsigned int i = 0; i < num_peers; i++)
534 { 530 {
535 ip[i].off = i; 531 ip[i].off = i;
536 ip[i].ccc = ccc; 532 ip[i].ccc = ccc;
537 } 533 }
538 if (GNUNET_OK != 534 if (GNUNET_OK !=
539 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 535 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
540 argv, 536 argv,
541 test_name_, 537 test_name_,
542 "nohelp", 538 "nohelp",
543 options, 539 options,
544 &connect_check_run, 540 &connect_check_run,
545 ccc)) 541 ccc))
546 return GNUNET_SYSERR; 542 return GNUNET_SYSERR;
547 return ccc->global_ret; 543 return ccc->global_ret;
548} 544}
@@ -559,11 +555,11 @@ GNUNET_TRANSPORT_TESTING_connect_check (void *cls,
559 * @return #GNUNET_OK on success 555 * @return #GNUNET_OK on success
560 */ 556 */
561int 557int
562GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, 558GNUNET_TRANSPORT_TESTING_main_(const char *argv0,
563 const char *filename, 559 const char *filename,
564 unsigned int num_peers, 560 unsigned int num_peers,
565 GNUNET_TRANSPORT_TESTING_CheckCallback check, 561 GNUNET_TRANSPORT_TESTING_CheckCallback check,
566 void *check_cls) 562 void *check_cls)
567{ 563{
568 struct GNUNET_TRANSPORT_TESTING_Handle *tth; 564 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
569 char *test_name; 565 char *test_name;
@@ -573,36 +569,36 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
573 int ret; 569 int ret;
574 570
575 ret = GNUNET_OK; 571 ret = GNUNET_OK;
576 test_name = GNUNET_TRANSPORT_TESTING_get_test_name (argv0); 572 test_name = GNUNET_TRANSPORT_TESTING_get_test_name(argv0);
577 GNUNET_log_setup (test_name, 573 GNUNET_log_setup(test_name,
578 "WARNING", 574 "WARNING",
579 NULL); 575 NULL);
580 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name (filename); 576 test_source = GNUNET_TRANSPORT_TESTING_get_test_source_name(filename);
581 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name (argv0, 577 test_plugin = GNUNET_TRANSPORT_TESTING_get_test_plugin_name(argv0,
582 test_source); 578 test_source);
583 for (unsigned int i=0;i<num_peers;i++) 579 for (unsigned int i = 0; i < num_peers; i++)
584 cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name (argv0, 580 cfg_names[i] = GNUNET_TRANSPORT_TESTING_get_config_name(argv0,
585 i+1); 581 i + 1);
586 tth = GNUNET_TRANSPORT_TESTING_init (); 582 tth = GNUNET_TRANSPORT_TESTING_init();
587 if (NULL == tth) 583 if (NULL == tth)
588 { 584 {
589 ret = GNUNET_SYSERR; 585 ret = GNUNET_SYSERR;
590 } 586 }
591 else 587 else
592 { 588 {
593 ret = check (check_cls, 589 ret = check(check_cls,
594 tth, 590 tth,
595 test_plugin, 591 test_plugin,
596 test_name, 592 test_name,
597 num_peers, 593 num_peers,
598 cfg_names); 594 cfg_names);
599 GNUNET_TRANSPORT_TESTING_done (tth); 595 GNUNET_TRANSPORT_TESTING_done(tth);
600 } 596 }
601 for (unsigned int i=0;i<num_peers;i++) 597 for (unsigned int i = 0; i < num_peers; i++)
602 GNUNET_free (cfg_names[i]); 598 GNUNET_free(cfg_names[i]);
603 GNUNET_free (test_source); 599 GNUNET_free(test_source);
604 GNUNET_free_non_null (test_plugin); 600 GNUNET_free_non_null(test_plugin);
605 GNUNET_free (test_name); 601 GNUNET_free(test_name);
606 return ret; 602 return ret;
607} 603}
608 604
diff --git a/src/transport/transport-testing-send.c b/src/transport/transport-testing-send.c
index cb4be57de..42735e4c1 100644
--- a/src/transport/transport-testing-send.c
+++ b/src/transport/transport-testing-send.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport-testing-send.c 21 * @file transport-testing-send.c
22 * @brief convenience transmission function for tests 22 * @brief convenience transmission function for tests
@@ -27,15 +27,15 @@
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(GNUNET_TIME_UNIT_SECONDS, 30)
31 31
32 32
33/** 33/**
34 * Return @a cx in @a cls. 34 * Return @a cx in @a cls.
35 */ 35 */
36static void 36static void
37find_cr (void *cls, 37find_cr(void *cls,
38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 38 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
39{ 39{
40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls; 40 struct GNUNET_TRANSPORT_TESTING_ConnectRequest **cr = cls;
41 41
@@ -62,72 +62,72 @@ find_cr (void *cls,
62 * #GNUNET_SYSERR if @a msize is illegal 62 * #GNUNET_SYSERR if @a msize is illegal
63 */ 63 */
64int 64int
65GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 65GNUNET_TRANSPORT_TESTING_send(struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 66 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
67 uint16_t mtype, 67 uint16_t mtype,
68 uint16_t msize, 68 uint16_t msize,
69 uint32_t num, 69 uint32_t num,
70 GNUNET_SCHEDULER_TaskCallback cont, 70 GNUNET_SCHEDULER_TaskCallback cont,
71 void *cont_cls) 71 void *cont_cls)
72{ 72{
73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr; 73 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cr;
74 struct GNUNET_MQ_Envelope *env; 74 struct GNUNET_MQ_Envelope *env;
75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test; 75 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
76 76
77 if (msize < sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage)) 77 if (msize < sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage))
78 { 78 {
79 GNUNET_break (0); 79 GNUNET_break(0);
80 return GNUNET_SYSERR; 80 return GNUNET_SYSERR;
81 } 81 }
82 cr = NULL; 82 cr = NULL;
83 GNUNET_TRANSPORT_TESTING_find_connecting_context (sender, 83 GNUNET_TRANSPORT_TESTING_find_connecting_context(sender,
84 receiver, 84 receiver,
85 &find_cr, 85 &find_cr,
86 &cr); 86 &cr);
87 if (NULL == cr) 87 if (NULL == cr)
88 GNUNET_TRANSPORT_TESTING_find_connecting_context (receiver, 88 GNUNET_TRANSPORT_TESTING_find_connecting_context(receiver,
89 sender, 89 sender,
90 &find_cr, 90 &find_cr,
91 &cr); 91 &cr);
92 if (NULL == cr) 92 if (NULL == cr)
93 {
94 GNUNET_break(0);
95 return GNUNET_NO;
96 }
97 if (NULL == cr->mq)
98 {
99 GNUNET_break(0);
100 return GNUNET_NO;
101 }
93 { 102 {
94 GNUNET_break (0); 103 char *receiver_s = GNUNET_strdup(GNUNET_i2s(&receiver->id));
95 return GNUNET_NO; 104
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);
96 } 112 }
97 if (NULL == cr->mq) 113 env = GNUNET_MQ_msg_extra(test,
98 { 114 msize - sizeof(*test),
99 GNUNET_break (0); 115 mtype);
100 return GNUNET_NO; 116 test->num = htonl(num);
101 } 117 memset(&test[1],
102 { 118 num,
103 char *receiver_s = GNUNET_strdup (GNUNET_i2s (&receiver->id)); 119 msize - sizeof(*test));
104 120 GNUNET_MQ_notify_sent(env,
105 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 121 cont,
106 "Sending message from peer %u (`%s') -> peer %u (`%s') !\n", 122 cont_cls);
107 sender->no, 123 GNUNET_MQ_send(cr->mq,
108 GNUNET_i2s (&sender->id), 124 env);
109 receiver->no,
110 receiver_s);
111 GNUNET_free (receiver_s);
112 }
113 env = GNUNET_MQ_msg_extra (test,
114 msize - sizeof (*test),
115 mtype);
116 test->num = htonl (num);
117 memset (&test[1],
118 num,
119 msize - sizeof (*test));
120 GNUNET_MQ_notify_sent (env,
121 cont,
122 cont_cls);
123 GNUNET_MQ_send (cr->mq,
124 env);
125 return GNUNET_OK; 125 return GNUNET_OK;
126} 126}
127 127
128 128
129/** 129/**
130 * Task that sends a test message from the 130 * Task that sends a test message from the
131 * first peer to the second peer. 131 * first peer to the second peer.
132 * 132 *
133 * @param ccc context which should contain at least two peers, the 133 * @param ccc context which should contain at least two peers, the
@@ -137,33 +137,33 @@ GNUNET_TRANSPORT_TESTING_send (struct GNUNET_TRANSPORT_TESTING_PeerContext *send
137 * @param cont_cls closure for @a cont 137 * @param cont_cls closure for @a cont
138 */ 138 */
139static void 139static void
140do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 140do_send(struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
141 uint16_t size, 141 uint16_t size,
142 GNUNET_SCHEDULER_TaskCallback cont, 142 GNUNET_SCHEDULER_TaskCallback cont,
143 void *cont_cls) 143 void *cont_cls)
144{ 144{
145 int ret; 145 int ret;
146 146
147 ccc->global_ret = GNUNET_SYSERR; 147 ccc->global_ret = GNUNET_SYSERR;
148 ret = GNUNET_TRANSPORT_TESTING_send (ccc->p[0], 148 ret = GNUNET_TRANSPORT_TESTING_send(ccc->p[0],
149 ccc->p[1], 149 ccc->p[1],
150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 150 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
151 size, 151 size,
152 ccc->send_num_gen++, 152 ccc->send_num_gen++,
153 cont, 153 cont,
154 cont_cls); 154 cont_cls);
155 GNUNET_assert (GNUNET_SYSERR != ret); 155 GNUNET_assert(GNUNET_SYSERR != ret);
156 if (GNUNET_NO == ret) 156 if (GNUNET_NO == ret)
157 { 157 {
158 GNUNET_break (0); 158 GNUNET_break(0);
159 ccc->global_ret = GNUNET_SYSERR; 159 ccc->global_ret = GNUNET_SYSERR;
160 GNUNET_SCHEDULER_shutdown (); 160 GNUNET_SCHEDULER_shutdown();
161 } 161 }
162} 162}
163 163
164 164
165/** 165/**
166 * Task that sends a minimalistic test message from the 166 * Task that sends a minimalistic test message from the
167 * first peer to the second peer. 167 * first peer to the second peer.
168 * 168 *
169 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 169 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
@@ -171,35 +171,35 @@ do_send (struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
171 * of which should be currently connected 171 * of which should be currently connected
172 */ 172 */
173void 173void
174GNUNET_TRANSPORT_TESTING_simple_send (void *cls) 174GNUNET_TRANSPORT_TESTING_simple_send(void *cls)
175{ 175{
176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 176 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
177 int done; 177 int done;
178 size_t msize; 178 size_t msize;
179 179
180 if (0 < sc->num_messages) 180 if (0 < sc->num_messages)
181 { 181 {
182 sc->num_messages--; 182 sc->num_messages--;
183 done = (0 == sc->num_messages); 183 done = (0 == sc->num_messages);
184 } 184 }
185 else 185 else
186 { 186 {
187 done = 0; /* infinite loop */ 187 done = 0; /* infinite loop */
188 } 188 }
189 msize = sizeof (struct GNUNET_TRANSPORT_TESTING_TestMessage); 189 msize = sizeof(struct GNUNET_TRANSPORT_TESTING_TestMessage);
190 if (NULL != sc->get_size_cb) 190 if (NULL != sc->get_size_cb)
191 msize = sc->get_size_cb (sc->num_messages); 191 msize = sc->get_size_cb(sc->num_messages);
192 /* if this was the last message, call the continuation, 192 /* if this was the last message, call the continuation,
193 otherwise call this function again */ 193 otherwise call this function again */
194 do_send (sc->ccc, 194 do_send(sc->ccc,
195 msize, 195 msize,
196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send, 196 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_simple_send,
197 done ? sc->cont_cls : sc); 197 done ? sc->cont_cls : sc);
198} 198}
199 199
200 200
201/** 201/**
202 * Task that sends a large test message from the 202 * Task that sends a large test message from the
203 * first peer to the second peer. 203 * first peer to the second peer.
204 * 204 *
205 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext` 205 * @param cls the `struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext`
@@ -207,30 +207,30 @@ GNUNET_TRANSPORT_TESTING_simple_send (void *cls)
207 * of which should be currently connected 207 * of which should be currently connected
208 */ 208 */
209void 209void
210GNUNET_TRANSPORT_TESTING_large_send (void *cls) 210GNUNET_TRANSPORT_TESTING_large_send(void *cls)
211{ 211{
212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls; 212 struct GNUNET_TRANSPORT_TESTING_SendClosure *sc = cls;
213 int done; 213 int done;
214 size_t msize; 214 size_t msize;
215 215
216 if (0 < sc->num_messages) 216 if (0 < sc->num_messages)
217 { 217 {
218 sc->num_messages--; 218 sc->num_messages--;
219 done = (0 == sc->num_messages); 219 done = (0 == sc->num_messages);
220 } 220 }
221 else 221 else
222 { 222 {
223 done = 0; /* infinite loop */ 223 done = 0; /* infinite loop */
224 } 224 }
225 msize = 2600; 225 msize = 2600;
226 if (NULL != sc->get_size_cb) 226 if (NULL != sc->get_size_cb)
227 msize = sc->get_size_cb (sc->num_messages); 227 msize = sc->get_size_cb(sc->num_messages);
228 /* if this was the last message, call the continuation, 228 /* if this was the last message, call the continuation,
229 otherwise call this function again */ 229 otherwise call this function again */
230 do_send (sc->ccc, 230 do_send(sc->ccc,
231 msize, 231 msize,
232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send, 232 done ? sc->cont : &GNUNET_TRANSPORT_TESTING_large_send,
233 done ? sc->cont_cls : sc); 233 done ? sc->cont_cls : sc);
234} 234}
235 235
236/* end of transport-testing-send.c */ 236/* end of transport-testing-send.c */
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 1ff1ec9f8..acf1645a9 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport-testing.c 21 * @file transport-testing.c
22 * @brief testing lib for transport service 22 * @brief testing lib for transport service
@@ -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,29 @@ 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 GNUNET_TRANSPORT_TESTING_PeerContext *p1,
57 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 57 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
58 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, 58 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
59 void *cb_cls) 59 void *cb_cls)
60{ 60{
61 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; 61 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
62 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 62 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
63 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 63 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
64 64
65 for (cc = tth->cc_head; NULL != cc; cc = ccn) 65 for (cc = tth->cc_head; NULL != cc; cc = ccn)
66 { 66 {
67 ccn = cc->next; 67 ccn = cc->next;
68 if ( (cc->p1 == p1) && 68 if ((cc->p1 == p1) &&
69 (cc->p2 == p2) ) 69 (cc->p2 == p2))
70 cb (cb_cls, 70 cb(cb_cls,
71 cc); 71 cc);
72 } 72 }
73} 73}
74 74
75 75
76static void 76static void
77set_p1c (void *cls, 77set_p1c(void *cls,
78 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 78 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
79{ 79{
80 int *found = cls; 80 int *found = cls;
81 81
@@ -86,8 +86,8 @@ set_p1c (void *cls,
86 86
87 87
88static void 88static void
89set_mq (void *cls, 89set_mq(void *cls,
90 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 90 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
91{ 91{
92 struct GNUNET_MQ_Handle *mq = cls; 92 struct GNUNET_MQ_Handle *mq = cls;
93 93
@@ -96,8 +96,8 @@ set_mq (void *cls,
96 96
97 97
98static void 98static void
99set_p2c (void *cls, 99set_p2c(void *cls,
100 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 100 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
101{ 101{
102 int *found = cls; 102 int *found = cls;
103 103
@@ -108,8 +108,8 @@ set_p2c (void *cls,
108 108
109 109
110static void 110static void
111clear_p1c (void *cls, 111clear_p1c(void *cls,
112 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 112 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
113{ 113{
114 int *found = cls; 114 int *found = cls;
115 115
@@ -120,8 +120,8 @@ clear_p1c (void *cls,
120 120
121 121
122static void 122static void
123clear_p2c (void *cls, 123clear_p2c(void *cls,
124 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx) 124 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cx)
125{ 125{
126 int *found = cls; 126 int *found = cls;
127 127
@@ -132,9 +132,9 @@ clear_p2c (void *cls,
132 132
133 133
134static void * 134static void *
135notify_connect (void *cls, 135notify_connect(void *cls,
136 const struct GNUNET_PeerIdentity *peer, 136 const struct GNUNET_PeerIdentity *peer,
137 struct GNUNET_MQ_Handle *mq) 137 struct GNUNET_MQ_Handle *mq)
138{ 138{
139 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 139 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
140 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 140 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -145,103 +145,103 @@ notify_connect (void *cls,
145 int found; 145 int found;
146 void *ret; 146 void *ret;
147 147
148 p2 = find_peer_context (p->tth, 148 p2 = find_peer_context(p->tth,
149 peer); 149 peer);
150 if (NULL != p->nc) 150 if (NULL != p->nc)
151 ret = p->nc (p->cb_cls, 151 ret = p->nc(p->cb_cls,
152 peer, 152 peer,
153 mq); 153 mq);
154 else 154 else
155 ret = NULL; 155 ret = NULL;
156 156
157 if (NULL != p2) 157 if (NULL != p2)
158 GNUNET_asprintf (&p2_s, 158 GNUNET_asprintf(&p2_s,
159 "%u (`%s')", 159 "%u (`%s')",
160 p2->no, 160 p2->no,
161 GNUNET_i2s (&p2->id)); 161 GNUNET_i2s(&p2->id));
162 else 162 else
163 GNUNET_asprintf (&p2_s, 163 GNUNET_asprintf(&p2_s,
164 "`%s'", 164 "`%s'",
165 GNUNET_i2s (peer)); 165 GNUNET_i2s(peer));
166 LOG (GNUNET_ERROR_TYPE_DEBUG, 166 LOG(GNUNET_ERROR_TYPE_DEBUG,
167 "Peers %s connected to peer %u (`%s')\n", 167 "Peers %s connected to peer %u (`%s')\n",
168 p2_s, 168 p2_s,
169 p->no, 169 p->no,
170 GNUNET_i2s (&p->id)); 170 GNUNET_i2s(&p->id));
171 GNUNET_free (p2_s); 171 GNUNET_free(p2_s);
172 /* update flags in connecting contexts */ 172 /* update flags in connecting contexts */
173 found = GNUNET_NO; 173 found = GNUNET_NO;
174 GNUNET_TRANSPORT_TESTING_find_connecting_context (p, 174 GNUNET_TRANSPORT_TESTING_find_connecting_context(p,
175 p2, 175 p2,
176 &set_p1c, 176 &set_p1c,
177 &found); 177 &found);
178 if (GNUNET_NO == found) 178 if (GNUNET_NO == found)
179 { 179 {
180 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 180 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
181 cc->p1 = p; 181 cc->p1 = p;
182 cc->p2 = p2; 182 cc->p2 = p2;
183 cc->p1_c = GNUNET_YES; 183 cc->p1_c = GNUNET_YES;
184 GNUNET_CONTAINER_DLL_insert (tth->cc_head, 184 GNUNET_CONTAINER_DLL_insert(tth->cc_head,
185 tth->cc_tail, 185 tth->cc_tail,
186 cc); 186 cc);
187 } 187 }
188 found = GNUNET_NO; 188 found = GNUNET_NO;
189 GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, 189 GNUNET_TRANSPORT_TESTING_find_connecting_context(p2,
190 p, 190 p,
191 &set_p2c, 191 &set_p2c,
192 &found); 192 &found);
193 if (GNUNET_NO == found) 193 if (GNUNET_NO == found)
194 { 194 {
195 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 195 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
196 cc->p1 = p2; 196 cc->p1 = p2;
197 cc->p2 = p; 197 cc->p2 = p;
198 cc->p1_c = GNUNET_YES; 198 cc->p1_c = GNUNET_YES;
199 GNUNET_CONTAINER_DLL_insert (tth->cc_head, 199 GNUNET_CONTAINER_DLL_insert(tth->cc_head,
200 tth->cc_tail, 200 tth->cc_tail,
201 cc); 201 cc);
202 } 202 }
203 GNUNET_TRANSPORT_TESTING_find_connecting_context (p, 203 GNUNET_TRANSPORT_TESTING_find_connecting_context(p,
204 p2, 204 p2,
205 &set_mq, 205 &set_mq,
206 mq); 206 mq);
207 /* update set connected flag for all requests */ 207 /* update set connected flag for all requests */
208 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 208 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
209 { 209 {
210 if (GNUNET_YES == cc->connected) 210 if (GNUNET_YES == cc->connected)
211 continue; 211 continue;
212 if ( (GNUNET_YES == cc->p1_c) && 212 if ((GNUNET_YES == cc->p1_c) &&
213 (GNUNET_YES == cc->p2_c) ) 213 (GNUNET_YES == cc->p2_c))
214 { 214 {
215 cc->connected = GNUNET_YES; 215 cc->connected = GNUNET_YES;
216 /* stop trying to connect */ 216 /* stop trying to connect */
217 if (NULL != cc->tct) 217 if (NULL != cc->tct)
218 { 218 {
219 GNUNET_SCHEDULER_cancel (cc->tct); 219 GNUNET_SCHEDULER_cancel(cc->tct);
220 cc->tct = NULL; 220 cc->tct = NULL;
221 } 221 }
222 if (NULL != cc->oh) 222 if (NULL != cc->oh)
223 { 223 {
224 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); 224 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh);
225 cc->oh = NULL; 225 cc->oh = NULL;
226 } 226 }
227 if (NULL != cc->ats_sh) 227 if (NULL != cc->ats_sh)
228 { 228 {
229 GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh); 229 GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh);
230 cc->ats_sh = NULL; 230 cc->ats_sh = NULL;
231 } 231 }
232 }
232 } 233 }
233 }
234 /* then notify application */ 234 /* then notify application */
235 for (cc = tth->cc_head; NULL != cc; cc = ccn) 235 for (cc = tth->cc_head; NULL != cc; cc = ccn)
236 {
237 ccn = cc->next;
238 if ( (GNUNET_YES == cc->connected) &&
239 (NULL != cc->cb) )
240 { 236 {
241 cc->cb (cc->cb_cls); 237 ccn = cc->next;
242 cc->cb = NULL; /* only notify once! */ 238 if ((GNUNET_YES == cc->connected) &&
239 (NULL != cc->cb))
240 {
241 cc->cb(cc->cb_cls);
242 cc->cb = NULL; /* only notify once! */
243 }
243 } 244 }
244 }
245 return ret; 245 return ret;
246} 246}
247 247
@@ -252,13 +252,13 @@ notify_connect (void *cls,
252 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` 252 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
253 */ 253 */
254static void 254static void
255offer_hello (void *cls); 255offer_hello(void *cls);
256 256
257 257
258static void 258static void
259notify_disconnect (void *cls, 259notify_disconnect(void *cls,
260 const struct GNUNET_PeerIdentity *peer, 260 const struct GNUNET_PeerIdentity *peer,
261 void *handler_cls) 261 void *handler_cls)
262{ 262{
263 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls; 263 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cls;
264 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 264 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
@@ -268,93 +268,93 @@ notify_disconnect (void *cls,
268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL; 268 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2 = NULL;
269 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 269 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
270 270
271 p2 = find_peer_context (p->tth, 271 p2 = find_peer_context(p->tth,
272 peer); 272 peer);
273 no = p->no; 273 no = p->no;
274 if (NULL != p2) 274 if (NULL != p2)
275 GNUNET_asprintf (&p2_s, 275 GNUNET_asprintf(&p2_s,
276 "%u (`%s')", 276 "%u (`%s')",
277 p2->no, 277 p2->no,
278 GNUNET_i2s (&p2->id)); 278 GNUNET_i2s(&p2->id));
279 else 279 else
280 GNUNET_asprintf (&p2_s, 280 GNUNET_asprintf(&p2_s,
281 "`%s'", 281 "`%s'",
282 GNUNET_i2s (peer)); 282 GNUNET_i2s(peer));
283 LOG (GNUNET_ERROR_TYPE_DEBUG, 283 LOG(GNUNET_ERROR_TYPE_DEBUG,
284 "Peers %s disconnected from peer %u (`%s')\n", 284 "Peers %s disconnected from peer %u (`%s')\n",
285 p2_s, 285 p2_s,
286 no, 286 no,
287 GNUNET_i2s (&p->id)); 287 GNUNET_i2s(&p->id));
288 GNUNET_free (p2_s); 288 GNUNET_free(p2_s);
289 /* notify about disconnect */ 289 /* notify about disconnect */
290 if (NULL != p->nd) 290 if (NULL != p->nd)
291 p->nd (p->cb_cls, 291 p->nd(p->cb_cls,
292 peer, 292 peer,
293 handler_cls); 293 handler_cls);
294 if (NULL == p2) 294 if (NULL == p2)
295 return; 295 return;
296 /* clear MQ, it is now invalid */ 296 /* clear MQ, it is now invalid */
297 GNUNET_TRANSPORT_TESTING_find_connecting_context (p, 297 GNUNET_TRANSPORT_TESTING_find_connecting_context(p,
298 p2, 298 p2,
299 &set_mq, 299 &set_mq,
300 NULL); 300 NULL);
301 /* update set connected flags for all requests */ 301 /* update set connected flags for all requests */
302 GNUNET_TRANSPORT_TESTING_find_connecting_context (p, 302 GNUNET_TRANSPORT_TESTING_find_connecting_context(p,
303 p2, 303 p2,
304 &clear_p1c, 304 &clear_p1c,
305 NULL); 305 NULL);
306 GNUNET_TRANSPORT_TESTING_find_connecting_context (p2, 306 GNUNET_TRANSPORT_TESTING_find_connecting_context(p2,
307 p, 307 p,
308 &clear_p2c, 308 &clear_p2c,
309 NULL); 309 NULL);
310 /* resume connectivity requests as necessary */ 310 /* resume connectivity requests as necessary */
311 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 311 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
312 { 312 {
313 if (GNUNET_NO == cc->connected) 313 if (GNUNET_NO == cc->connected)
314 continue; 314 continue;
315 if ( (GNUNET_YES != cc->p1_c) || 315 if ((GNUNET_YES != cc->p1_c) ||
316 (GNUNET_YES != cc->p2_c) ) 316 (GNUNET_YES != cc->p2_c))
317 { 317 {
318 cc->connected = GNUNET_NO; 318 cc->connected = GNUNET_NO;
319 /* start trying to connect */ 319 /* start trying to connect */
320 if ( (NULL == cc->tct) && 320 if ((NULL == cc->tct) &&
321 (NULL == cc->oh) ) 321 (NULL == cc->oh))
322 cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, 322 cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello,
323 cc); 323 cc);
324 if (NULL == cc->ats_sh) 324 if (NULL == cc->ats_sh)
325 cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats, 325 cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats,
326 &p2->id, 326 &p2->id,
327 1); 327 1);
328 }
328 } 329 }
329 }
330} 330}
331 331
332 332
333static void 333static void
334get_hello (void *cb_cls, 334get_hello(void *cb_cls,
335 const struct GNUNET_MessageHeader *message) 335 const struct GNUNET_MessageHeader *message)
336{ 336{
337 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls; 337 struct GNUNET_TRANSPORT_TESTING_PeerContext *p = cb_cls;
338 struct GNUNET_PeerIdentity hello_id; 338 struct GNUNET_PeerIdentity hello_id;
339 339
340 GNUNET_assert (GNUNET_OK == 340 GNUNET_assert(GNUNET_OK ==
341 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, 341 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)message,
342 &hello_id)); 342 &hello_id));
343 GNUNET_assert (0 == memcmp (&hello_id, 343 GNUNET_assert(0 == memcmp(&hello_id,
344 &p->id, 344 &p->id,
345 sizeof (hello_id))); 345 sizeof(hello_id)));
346 GNUNET_free_non_null (p->hello); 346 GNUNET_free_non_null(p->hello);
347 p->hello = (struct GNUNET_HELLO_Message *) GNUNET_copy_message (message); 347 p->hello = (struct GNUNET_HELLO_Message *)GNUNET_copy_message(message);
348 348
349 if (NULL != p->start_cb) 349 if (NULL != p->start_cb)
350 { 350 {
351 LOG (GNUNET_ERROR_TYPE_DEBUG, 351 LOG(GNUNET_ERROR_TYPE_DEBUG,
352 "Peer %u (`%s') successfully started\n", 352 "Peer %u (`%s') successfully started\n",
353 p->no, 353 p->no,
354 GNUNET_i2s (&p->id)); 354 GNUNET_i2s(&p->id));
355 p->start_cb (p->start_cb_cls); 355 p->start_cb(p->start_cb_cls);
356 p->start_cb = NULL; 356 p->start_cb = NULL;
357 } 357 }
358} 358}
359 359
360 360
@@ -372,42 +372,43 @@ get_hello (void *cb_cls,
372 * @return the peer context 372 * @return the peer context
373 */ 373 */
374struct GNUNET_TRANSPORT_TESTING_PeerContext * 374struct GNUNET_TRANSPORT_TESTING_PeerContext *
375GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth, 375GNUNET_TRANSPORT_TESTING_start_peer(struct GNUNET_TRANSPORT_TESTING_Handle *tth,
376 const char *cfgname, 376 const char *cfgname,
377 int peer_id, 377 int peer_id,
378 const struct GNUNET_MQ_MessageHandler *handlers, 378 const struct GNUNET_MQ_MessageHandler *handlers,
379 GNUNET_TRANSPORT_NotifyConnect nc, 379 GNUNET_TRANSPORT_NotifyConnect nc,
380 GNUNET_TRANSPORT_NotifyDisconnect nd, 380 GNUNET_TRANSPORT_NotifyDisconnect nd,
381 void *cb_cls, 381 void *cb_cls,
382 GNUNET_SCHEDULER_TaskCallback start_cb, 382 GNUNET_SCHEDULER_TaskCallback start_cb,
383 void *start_cb_cls) 383 void *start_cb_cls)
384{ 384{
385 char *emsg = NULL; 385 char *emsg = NULL;
386 struct GNUNET_TRANSPORT_TESTING_PeerContext *p; 386 struct GNUNET_TRANSPORT_TESTING_PeerContext *p;
387 struct GNUNET_PeerIdentity dummy; 387 struct GNUNET_PeerIdentity dummy;
388 unsigned int i; 388 unsigned int i;
389 389
390 if (GNUNET_NO == GNUNET_DISK_file_test (cfgname)) 390 if (GNUNET_NO == GNUNET_DISK_file_test(cfgname))
391 { 391 {
392 LOG (GNUNET_ERROR_TYPE_ERROR, 392 LOG(GNUNET_ERROR_TYPE_ERROR,
393 "File not found: `%s'\n", 393 "File not found: `%s'\n",
394 cfgname); 394 cfgname);
395 return NULL; 395 return NULL;
396 } 396 }
397 397
398 p = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_PeerContext); 398 p = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_PeerContext);
399 p->tth = tth; 399 p->tth = tth;
400 p->nc = nc; 400 p->nc = nc;
401 p->nd = nd; 401 p->nd = nd;
402 if (NULL != handlers) 402 if (NULL != handlers)
403 { 403 {
404 for (i=0;NULL != handlers[i].cb;i++) ; 404 for (i = 0; NULL != handlers[i].cb; i++)
405 p->handlers = GNUNET_new_array (i + 1, 405 ;
406 struct GNUNET_MQ_MessageHandler); 406 p->handlers = GNUNET_new_array(i + 1,
407 GNUNET_memcpy (p->handlers, 407 struct GNUNET_MQ_MessageHandler);
408 handlers, 408 GNUNET_memcpy(p->handlers,
409 i * sizeof (struct GNUNET_MQ_MessageHandler)); 409 handlers,
410 } 410 i * sizeof(struct GNUNET_MQ_MessageHandler));
411 }
411 if (NULL != cb_cls) 412 if (NULL != cb_cls)
412 p->cb_cls = cb_cls; 413 p->cb_cls = cb_cls;
413 else 414 else
@@ -417,105 +418,105 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
417 p->start_cb_cls = start_cb_cls; 418 p->start_cb_cls = start_cb_cls;
418 else 419 else
419 p->start_cb_cls = p; 420 p->start_cb_cls = p;
420 GNUNET_CONTAINER_DLL_insert (tth->p_head, 421 GNUNET_CONTAINER_DLL_insert(tth->p_head,
421 tth->p_tail, 422 tth->p_tail,
422 p); 423 p);
423 424
424 /* Create configuration and call testing lib to modify it */ 425 /* Create configuration and call testing lib to modify it */
425 p->cfg = GNUNET_CONFIGURATION_create (); 426 p->cfg = GNUNET_CONFIGURATION_create();
426 GNUNET_assert (GNUNET_OK == 427 GNUNET_assert(GNUNET_OK ==
427 GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 428 GNUNET_CONFIGURATION_load(p->cfg, cfgname));
428 if (GNUNET_SYSERR == 429 if (GNUNET_SYSERR ==
429 GNUNET_TESTING_configuration_create (tth->tl_system, 430 GNUNET_TESTING_configuration_create(tth->tl_system,
430 p->cfg)) 431 p->cfg))
431 { 432 {
432 LOG (GNUNET_ERROR_TYPE_ERROR, 433 LOG(GNUNET_ERROR_TYPE_ERROR,
433 "Testing library failed to create unique configuration based on `%s'\n", 434 "Testing library failed to create unique configuration based on `%s'\n",
434 cfgname); 435 cfgname);
435 GNUNET_CONFIGURATION_destroy (p->cfg); 436 GNUNET_CONFIGURATION_destroy(p->cfg);
436 GNUNET_free (p); 437 GNUNET_free(p);
437 return NULL; 438 return NULL;
438 } 439 }
439 440
440 p->no = peer_id; 441 p->no = peer_id;
441 /* Configure peer with configuration */ 442 /* Configure peer with configuration */
442 p->peer = GNUNET_TESTING_peer_configure (tth->tl_system, 443 p->peer = GNUNET_TESTING_peer_configure(tth->tl_system,
443 p->cfg, 444 p->cfg,
444 p->no, 445 p->no,
445 NULL, 446 NULL,
446 &emsg); 447 &emsg);
447 if (NULL == p->peer) 448 if (NULL == p->peer)
448 { 449 {
449 LOG (GNUNET_ERROR_TYPE_ERROR, 450 LOG(GNUNET_ERROR_TYPE_ERROR,
450 "Testing library failed to create unique configuration based on `%s': `%s'\n", 451 "Testing library failed to create unique configuration based on `%s': `%s'\n",
451 cfgname, 452 cfgname,
452 emsg); 453 emsg);
453 GNUNET_TRANSPORT_TESTING_stop_peer (p); 454 GNUNET_TRANSPORT_TESTING_stop_peer(p);
454 GNUNET_free_non_null (emsg); 455 GNUNET_free_non_null(emsg);
455 return NULL; 456 return NULL;
456 } 457 }
457 GNUNET_free_non_null (emsg); 458 GNUNET_free_non_null(emsg);
458 if (GNUNET_OK != GNUNET_TESTING_peer_start (p->peer)) 459 if (GNUNET_OK != GNUNET_TESTING_peer_start(p->peer))
459 { 460 {
460 LOG (GNUNET_ERROR_TYPE_ERROR, 461 LOG(GNUNET_ERROR_TYPE_ERROR,
461 "Testing library failed to create unique configuration based on `%s'\n", 462 "Testing library failed to create unique configuration based on `%s'\n",
462 cfgname); 463 cfgname);
463 GNUNET_TRANSPORT_TESTING_stop_peer (p); 464 GNUNET_TRANSPORT_TESTING_stop_peer(p);
464 return NULL; 465 return NULL;
465 } 466 }
466 467
467 memset (&dummy, 468 memset(&dummy,
468 '\0', 469 '\0',
469 sizeof (dummy)); 470 sizeof(dummy));
470 GNUNET_TESTING_peer_get_identity (p->peer, 471 GNUNET_TESTING_peer_get_identity(p->peer,
471 &p->id); 472 &p->id);
472 if (0 == memcmp (&dummy, 473 if (0 == memcmp(&dummy,
473 &p->id, 474 &p->id,
474 sizeof (struct GNUNET_PeerIdentity))) 475 sizeof(struct GNUNET_PeerIdentity)))
475 { 476 {
476 LOG (GNUNET_ERROR_TYPE_ERROR, 477 LOG(GNUNET_ERROR_TYPE_ERROR,
477 "Testing library failed to obtain peer identity for peer %u\n", 478 "Testing library failed to obtain peer identity for peer %u\n",
478 p->no); 479 p->no);
479 GNUNET_TRANSPORT_TESTING_stop_peer (p); 480 GNUNET_TRANSPORT_TESTING_stop_peer(p);
480 return NULL; 481 return NULL;
481 } 482 }
482 LOG (GNUNET_ERROR_TYPE_DEBUG, 483 LOG(GNUNET_ERROR_TYPE_DEBUG,
483 "Peer %u configured with identity `%s'\n", 484 "Peer %u configured with identity `%s'\n",
484 p->no, 485 p->no,
485 GNUNET_i2s_full (&p->id)); 486 GNUNET_i2s_full(&p->id));
486 p->tmh = GNUNET_TRANSPORT_manipulation_connect (p->cfg); 487 p->tmh = GNUNET_TRANSPORT_manipulation_connect(p->cfg);
487 p->th = GNUNET_TRANSPORT_core_connect (p->cfg, 488 p->th = GNUNET_TRANSPORT_core_connect(p->cfg,
488 NULL, 489 NULL,
489 handlers, 490 handlers,
490 p, 491 p,
491 &notify_connect, 492 &notify_connect,
492 &notify_disconnect, 493 &notify_disconnect,
493 NULL); 494 NULL);
494 if ( (NULL == p->th) || 495 if ((NULL == p->th) ||
495 (NULL == p->tmh) ) 496 (NULL == p->tmh))
496 { 497 {
497 LOG (GNUNET_ERROR_TYPE_ERROR, 498 LOG(GNUNET_ERROR_TYPE_ERROR,
498 "Failed to connect to transport service for peer `%s': `%s'\n", 499 "Failed to connect to transport service for peer `%s': `%s'\n",
499 cfgname, 500 cfgname,
500 emsg); 501 emsg);
501 GNUNET_TRANSPORT_TESTING_stop_peer (p); 502 GNUNET_TRANSPORT_TESTING_stop_peer(p);
502 return NULL; 503 return NULL;
503 } 504 }
504 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 505 p->ats = GNUNET_ATS_connectivity_init(p->cfg);
505 if (NULL == p->ats) 506 if (NULL == p->ats)
506 { 507 {
507 LOG (GNUNET_ERROR_TYPE_ERROR, 508 LOG(GNUNET_ERROR_TYPE_ERROR,
508 "Failed to connect to ATS service for peer `%s': `%s'\n", 509 "Failed to connect to ATS service for peer `%s': `%s'\n",
509 cfgname, 510 cfgname,
510 emsg); 511 emsg);
511 GNUNET_TRANSPORT_TESTING_stop_peer (p); 512 GNUNET_TRANSPORT_TESTING_stop_peer(p);
512 return NULL; 513 return NULL;
513 } 514 }
514 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 515 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
515 GNUNET_TRANSPORT_AC_ANY, 516 GNUNET_TRANSPORT_AC_ANY,
516 &get_hello, 517 &get_hello,
517 p); 518 p);
518 GNUNET_assert (NULL != p->ghh); 519 GNUNET_assert(NULL != p->ghh);
519 return p; 520 return p;
520} 521}
521 522
@@ -529,89 +530,89 @@ GNUNET_TRANSPORT_TESTING_start_peer (struct GNUNET_TRANSPORT_TESTING_Handle *tth
529 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 530 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
530 */ 531 */
531int 532int
532GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 533GNUNET_TRANSPORT_TESTING_restart_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
533 GNUNET_SCHEDULER_TaskCallback restart_cb, 534 GNUNET_SCHEDULER_TaskCallback restart_cb,
534 void *restart_cb_cls) 535 void *restart_cb_cls)
535{ 536{
536 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 537 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
537 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 538 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
538 539
539 /* shutdown */ 540 /* shutdown */
540 LOG (GNUNET_ERROR_TYPE_DEBUG, 541 LOG(GNUNET_ERROR_TYPE_DEBUG,
541 "Stopping peer %u (`%s')\n", 542 "Stopping peer %u (`%s')\n",
542 p->no, 543 p->no,
543 GNUNET_i2s (&p->id)); 544 GNUNET_i2s(&p->id));
544 if (NULL != p->ghh) 545 if (NULL != p->ghh)
545 { 546 {
546 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 547 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
547 p->ghh = NULL; 548 p->ghh = NULL;
548 } 549 }
549 if (NULL != p->th) 550 if (NULL != p->th)
550 { 551 {
551 GNUNET_TRANSPORT_core_disconnect (p->th); 552 GNUNET_TRANSPORT_core_disconnect(p->th);
552 p->th = NULL; 553 p->th = NULL;
553 } 554 }
554 if (NULL != p->tmh) 555 if (NULL != p->tmh)
555 { 556 {
556 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh); 557 GNUNET_TRANSPORT_manipulation_disconnect(p->tmh);
557 p->tmh = NULL; 558 p->tmh = NULL;
558 } 559 }
559 for (cc = p->tth->cc_head; NULL != cc; cc = ccn) 560 for (cc = p->tth->cc_head; NULL != cc; cc = ccn)
560 { 561 {
561 ccn = cc->next; 562 ccn = cc->next;
562 if ( (cc->p1 == p) || 563 if ((cc->p1 == p) ||
563 (cc->p2 == p) ) 564 (cc->p2 == p))
564 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); 565 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
565 } 566 }
566 if (NULL != p->ats) 567 if (NULL != p->ats)
567 { 568 {
568 GNUNET_ATS_connectivity_done (p->ats); 569 GNUNET_ATS_connectivity_done(p->ats);
569 p->ats = NULL; 570 p->ats = NULL;
570 } 571 }
571 if (GNUNET_SYSERR == 572 if (GNUNET_SYSERR ==
572 GNUNET_TESTING_peer_stop (p->peer)) 573 GNUNET_TESTING_peer_stop(p->peer))
573 { 574 {
574 LOG (GNUNET_ERROR_TYPE_ERROR, 575 LOG(GNUNET_ERROR_TYPE_ERROR,
575 "Failed to stop peer %u (`%s')\n", 576 "Failed to stop peer %u (`%s')\n",
576 p->no, 577 p->no,
577 GNUNET_i2s (&p->id)); 578 GNUNET_i2s(&p->id));
578 return GNUNET_SYSERR; 579 return GNUNET_SYSERR;
579 } 580 }
580 581
581 sleep (5); // YUCK! 582 sleep(5); // YUCK!
582 583
583 LOG (GNUNET_ERROR_TYPE_DEBUG, 584 LOG(GNUNET_ERROR_TYPE_DEBUG,
584 "Restarting peer %u (`%s')\n", 585 "Restarting peer %u (`%s')\n",
585 p->no, 586 p->no,
586 GNUNET_i2s (&p->id)); 587 GNUNET_i2s(&p->id));
587 /* restart */ 588 /* restart */
588 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start (p->peer)) 589 if (GNUNET_SYSERR == GNUNET_TESTING_peer_start(p->peer))
589 { 590 {
590 LOG (GNUNET_ERROR_TYPE_ERROR, 591 LOG(GNUNET_ERROR_TYPE_ERROR,
591 "Failed to restart peer %u (`%s')\n", 592 "Failed to restart peer %u (`%s')\n",
592 p->no, 593 p->no,
593 GNUNET_i2s (&p->id)); 594 GNUNET_i2s(&p->id));
594 return GNUNET_SYSERR; 595 return GNUNET_SYSERR;
595 } 596 }
596 597
597 GNUNET_assert (NULL == p->start_cb); 598 GNUNET_assert(NULL == p->start_cb);
598 p->start_cb = restart_cb; 599 p->start_cb = restart_cb;
599 p->start_cb_cls = restart_cb_cls; 600 p->start_cb_cls = restart_cb_cls;
600 601
601 p->th = GNUNET_TRANSPORT_core_connect (p->cfg, 602 p->th = GNUNET_TRANSPORT_core_connect(p->cfg,
602 NULL, 603 NULL,
603 p->handlers, 604 p->handlers,
604 p, 605 p,
605 &notify_connect, 606 &notify_connect,
606 &notify_disconnect, 607 &notify_disconnect,
607 NULL); 608 NULL);
608 GNUNET_assert (NULL != p->th); 609 GNUNET_assert(NULL != p->th);
609 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 610 p->ats = GNUNET_ATS_connectivity_init(p->cfg);
610 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 611 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
611 GNUNET_TRANSPORT_AC_ANY, 612 GNUNET_TRANSPORT_AC_ANY,
612 &get_hello, 613 &get_hello,
613 p); 614 p);
614 GNUNET_assert (NULL != p->ghh); 615 GNUNET_assert(NULL != p->ghh);
615 return GNUNET_OK; 616 return GNUNET_OK;
616} 617}
617 618
@@ -622,75 +623,75 @@ GNUNET_TRANSPORT_TESTING_restart_peer (struct GNUNET_TRANSPORT_TESTING_PeerConte
622 * @param p the peer 623 * @param p the peer
623 */ 624 */
624void 625void
625GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext *p) 626GNUNET_TRANSPORT_TESTING_stop_peer(struct GNUNET_TRANSPORT_TESTING_PeerContext *p)
626{ 627{
627 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth; 628 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p->tth;
628 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 629 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
629 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn; 630 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ccn;
630 631
631 for (cc = tth->cc_head; NULL != cc; cc = ccn) 632 for (cc = tth->cc_head; NULL != cc; cc = ccn)
632 { 633 {
633 ccn = cc->next; 634 ccn = cc->next;
634 if ( (cc->p1 == p) || 635 if ((cc->p1 == p) ||
635 (cc->p2 == p) ) 636 (cc->p2 == p))
636 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); 637 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
637 } 638 }
638 if (NULL != p->ghh) 639 if (NULL != p->ghh)
639 { 640 {
640 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 641 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
641 p->ghh = NULL; 642 p->ghh = NULL;
642 } 643 }
643 if (NULL != p->tmh) 644 if (NULL != p->tmh)
644 { 645 {
645 GNUNET_TRANSPORT_manipulation_disconnect (p->tmh); 646 GNUNET_TRANSPORT_manipulation_disconnect(p->tmh);
646 p->tmh = NULL; 647 p->tmh = NULL;
647 } 648 }
648 if (NULL != p->th) 649 if (NULL != p->th)
649 { 650 {
650 GNUNET_TRANSPORT_core_disconnect (p->th); 651 GNUNET_TRANSPORT_core_disconnect(p->th);
651 p->th = NULL; 652 p->th = NULL;
652 } 653 }
653 if (NULL != p->peer) 654 if (NULL != p->peer)
654 {
655 if (GNUNET_OK !=
656 GNUNET_TESTING_peer_stop (p->peer))
657 { 655 {
658 LOG (GNUNET_ERROR_TYPE_DEBUG, 656 if (GNUNET_OK !=
659 "Testing lib failed to stop peer %u (`%s')\n", 657 GNUNET_TESTING_peer_stop(p->peer))
660 p->no, 658 {
661 GNUNET_i2s (&p->id)); 659 LOG(GNUNET_ERROR_TYPE_DEBUG,
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;
662 } 666 }
663 GNUNET_TESTING_peer_destroy (p->peer);
664 p->peer = NULL;
665 }
666 if (NULL != p->ats) 667 if (NULL != p->ats)
667 { 668 {
668 GNUNET_ATS_connectivity_done (p->ats); 669 GNUNET_ATS_connectivity_done(p->ats);
669 p->ats = NULL; 670 p->ats = NULL;
670 } 671 }
671 if (NULL != p->hello) 672 if (NULL != p->hello)
672 { 673 {
673 GNUNET_free (p->hello); 674 GNUNET_free(p->hello);
674 p->hello = NULL; 675 p->hello = NULL;
675 } 676 }
676 if (NULL != p->cfg) 677 if (NULL != p->cfg)
677 { 678 {
678 GNUNET_CONFIGURATION_destroy (p->cfg); 679 GNUNET_CONFIGURATION_destroy(p->cfg);
679 p->cfg = NULL; 680 p->cfg = NULL;
680 } 681 }
681 if (NULL != p->handlers) 682 if (NULL != p->handlers)
682 { 683 {
683 GNUNET_free (p->handlers); 684 GNUNET_free(p->handlers);
684 p->handlers = NULL; 685 p->handlers = NULL;
685 } 686 }
686 GNUNET_CONTAINER_DLL_remove (tth->p_head, 687 GNUNET_CONTAINER_DLL_remove(tth->p_head,
687 tth->p_tail, 688 tth->p_tail,
688 p); 689 p);
689 LOG (GNUNET_ERROR_TYPE_DEBUG, 690 LOG(GNUNET_ERROR_TYPE_DEBUG,
690 "Peer %u (`%s') stopped\n", 691 "Peer %u (`%s') stopped\n",
691 p->no, 692 p->no,
692 GNUNET_i2s (&p->id)); 693 GNUNET_i2s(&p->id));
693 GNUNET_free (p); 694 GNUNET_free(p);
694} 695}
695 696
696 697
@@ -699,14 +700,14 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct GNUNET_TRANSPORT_TESTING_PeerContext
699 * transport service. 700 * transport service.
700 */ 701 */
701static void 702static void
702hello_offered (void *cls) 703hello_offered(void *cls)
703{ 704{
704 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; 705 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
705 706
706 cc->oh = NULL; 707 cc->oh = NULL;
707 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 708 cc->tct = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
708 &offer_hello, 709 &offer_hello,
709 cc); 710 cc);
710} 711}
711 712
712 713
@@ -716,7 +717,7 @@ hello_offered (void *cls)
716 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest` 717 * @param cls our `struct GNUNET_TRANSPORT_TESTING_ConnectRequest`
717 */ 718 */
718static void 719static void
719offer_hello (void *cls) 720offer_hello(void *cls)
720{ 721{
721 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls; 722 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc = cls;
722 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1; 723 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1 = cc->p1;
@@ -724,25 +725,25 @@ offer_hello (void *cls)
724 725
725 cc->tct = NULL; 726 cc->tct = NULL;
726 { 727 {
727 char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id)); 728 char *p2_s = GNUNET_strdup(GNUNET_i2s(&p2->id));
728 729
729 LOG (GNUNET_ERROR_TYPE_DEBUG, 730 LOG(GNUNET_ERROR_TYPE_DEBUG,
730 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n", 731 "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
731 p1->no, 732 p1->no,
732 GNUNET_i2s (&p1->id), 733 GNUNET_i2s(&p1->id),
733 p2->no, 734 p2->no,
734 p2_s, 735 p2_s,
735 GNUNET_HELLO_size (cc->p2->hello)); 736 GNUNET_HELLO_size(cc->p2->hello));
736 GNUNET_free (p2_s); 737 GNUNET_free(p2_s);
737 } 738 }
738 739
739 if (NULL != cc->oh) 740 if (NULL != cc->oh)
740 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); 741 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh);
741 cc->oh = 742 cc->oh =
742 GNUNET_TRANSPORT_offer_hello (cc->p1->cfg, 743 GNUNET_TRANSPORT_offer_hello(cc->p1->cfg,
743 (const struct GNUNET_MessageHeader *) cc->p2->hello, 744 (const struct GNUNET_MessageHeader *)cc->p2->hello,
744 &hello_offered, 745 &hello_offered,
745 cc); 746 cc);
746} 747}
747 748
748 749
@@ -759,10 +760,10 @@ offer_hello (void *cls)
759 * @return a connect request handle 760 * @return a connect request handle
760 */ 761 */
761struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 762struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
762GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 763GNUNET_TRANSPORT_TESTING_connect_peers(struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
763 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 764 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
764 GNUNET_SCHEDULER_TaskCallback cb, 765 GNUNET_SCHEDULER_TaskCallback cb,
765 void *cls) 766 void *cls)
766{ 767{
767 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth; 768 struct GNUNET_TRANSPORT_TESTING_Handle *tth = p1->tth;
768 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 769 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
@@ -770,16 +771,16 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont
770 771
771 ccn = NULL; 772 ccn = NULL;
772 for (cc = tth->cc_head; NULL != cc; cc = cc->next) 773 for (cc = tth->cc_head; NULL != cc; cc = cc->next)
773 {
774 if ( (cc->p1 == p1) &&
775 (cc->p2 == p2) )
776 { 774 {
777 ccn = cc; 775 if ((cc->p1 == p1) &&
778 break; 776 (cc->p2 == p2))
777 {
778 ccn = cc;
779 break;
780 }
779 } 781 }
780 }
781 782
782 cc = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_ConnectRequest); 783 cc = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_ConnectRequest);
783 cc->p1 = p1; 784 cc->p1 = p1;
784 cc->p2 = p2; 785 cc->p2 = p2;
785 cc->cb = cb; 786 cc->cb = cb;
@@ -788,22 +789,22 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont
788 else 789 else
789 cc->cb_cls = cc; 790 cc->cb_cls = cc;
790 if (NULL != ccn) 791 if (NULL != ccn)
791 { 792 {
792 cc->p1_c = ccn->p1_c; 793 cc->p1_c = ccn->p1_c;
793 cc->p2_c = ccn->p2_c; 794 cc->p2_c = ccn->p2_c;
794 cc->connected = ccn->connected; 795 cc->connected = ccn->connected;
795 } 796 }
796 GNUNET_CONTAINER_DLL_insert (tth->cc_head, 797 GNUNET_CONTAINER_DLL_insert(tth->cc_head,
797 tth->cc_tail, 798 tth->cc_tail,
798 cc); 799 cc);
799 cc->tct = GNUNET_SCHEDULER_add_now (&offer_hello, 800 cc->tct = GNUNET_SCHEDULER_add_now(&offer_hello,
800 cc); 801 cc);
801 cc->ats_sh = GNUNET_ATS_connectivity_suggest (cc->p1->ats, 802 cc->ats_sh = GNUNET_ATS_connectivity_suggest(cc->p1->ats,
802 &p2->id, 803 &p2->id,
803 1); 804 1);
804 LOG (GNUNET_ERROR_TYPE_DEBUG, 805 LOG(GNUNET_ERROR_TYPE_DEBUG,
805 "New connect request %p\n", 806 "New connect request %p\n",
806 cc); 807 cc);
807 return cc; 808 return cc;
808} 809}
809 810
@@ -816,31 +817,31 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct GNUNET_TRANSPORT_TESTING_PeerCont
816 * @param cc a connect request handle 817 * @param cc a connect request handle
817 */ 818 */
818void 819void
819GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc) 820GNUNET_TRANSPORT_TESTING_connect_peers_cancel(struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc)
820{ 821{
821 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth; 822 struct GNUNET_TRANSPORT_TESTING_Handle *tth = cc->p1->tth;
822 823
823 LOG (GNUNET_ERROR_TYPE_DEBUG, 824 LOG(GNUNET_ERROR_TYPE_DEBUG,
824 "Canceling connect request!\n"); 825 "Canceling connect request!\n");
825 if (NULL != cc->tct) 826 if (NULL != cc->tct)
826 { 827 {
827 GNUNET_SCHEDULER_cancel (cc->tct); 828 GNUNET_SCHEDULER_cancel(cc->tct);
828 cc->tct = NULL; 829 cc->tct = NULL;
829 } 830 }
830 if (NULL != cc->oh) 831 if (NULL != cc->oh)
831 { 832 {
832 GNUNET_TRANSPORT_offer_hello_cancel (cc->oh); 833 GNUNET_TRANSPORT_offer_hello_cancel(cc->oh);
833 cc->oh = NULL; 834 cc->oh = NULL;
834 } 835 }
835 if (NULL != cc->ats_sh) 836 if (NULL != cc->ats_sh)
836 { 837 {
837 GNUNET_ATS_connectivity_suggest_cancel (cc->ats_sh); 838 GNUNET_ATS_connectivity_suggest_cancel(cc->ats_sh);
838 cc->ats_sh = NULL; 839 cc->ats_sh = NULL;
839 } 840 }
840 GNUNET_CONTAINER_DLL_remove (tth->cc_head, 841 GNUNET_CONTAINER_DLL_remove(tth->cc_head,
841 tth->cc_tail, 842 tth->cc_tail,
842 cc); 843 cc);
843 GNUNET_free (cc); 844 GNUNET_free(cc);
844} 845}
845 846
846 847
@@ -850,7 +851,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers_cancel (struct GNUNET_TRANSPORT_TESTING_C
850 * @param tth transport testing handle 851 * @param tth transport testing handle
851 */ 852 */
852void 853void
853GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth) 854GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth)
854{ 855{
855 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc; 856 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc;
856 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct; 857 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *ct;
@@ -861,26 +862,26 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth)
861 return; 862 return;
862 cc = tth->cc_head; 863 cc = tth->cc_head;
863 while (NULL != cc) 864 while (NULL != cc)
864 { 865 {
865 ct = cc->next; 866 ct = cc->next;
866 LOG (GNUNET_ERROR_TYPE_ERROR, 867 LOG(GNUNET_ERROR_TYPE_ERROR,
867 "Developer forgot to cancel connect request!\n"); 868 "Developer forgot to cancel connect request!\n");
868 GNUNET_TRANSPORT_TESTING_connect_peers_cancel (cc); 869 GNUNET_TRANSPORT_TESTING_connect_peers_cancel(cc);
869 cc = ct; 870 cc = ct;
870 } 871 }
871 p = tth->p_head; 872 p = tth->p_head;
872 while (NULL != p) 873 while (NULL != p)
873 { 874 {
874 t = p->next; 875 t = p->next;
875 LOG (GNUNET_ERROR_TYPE_ERROR, 876 LOG(GNUNET_ERROR_TYPE_ERROR,
876 "Developer forgot to stop peer!\n"); 877 "Developer forgot to stop peer!\n");
877 GNUNET_TRANSPORT_TESTING_stop_peer (p); 878 GNUNET_TRANSPORT_TESTING_stop_peer(p);
878 p = t; 879 p = t;
879 } 880 }
880 GNUNET_TESTING_system_destroy (tth->tl_system, 881 GNUNET_TESTING_system_destroy(tth->tl_system,
881 GNUNET_YES); 882 GNUNET_YES);
882 883
883 GNUNET_free (tth); 884 GNUNET_free(tth);
884} 885}
885 886
886 887
@@ -890,22 +891,22 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth)
890 * @return transport testing handle 891 * @return transport testing handle
891 */ 892 */
892struct GNUNET_TRANSPORT_TESTING_Handle * 893struct GNUNET_TRANSPORT_TESTING_Handle *
893GNUNET_TRANSPORT_TESTING_init () 894GNUNET_TRANSPORT_TESTING_init()
894{ 895{
895 struct GNUNET_TRANSPORT_TESTING_Handle *tth; 896 struct GNUNET_TRANSPORT_TESTING_Handle *tth;
896 897
897 tth = GNUNET_new (struct GNUNET_TRANSPORT_TESTING_Handle); 898 tth = GNUNET_new(struct GNUNET_TRANSPORT_TESTING_Handle);
898 tth->tl_system = GNUNET_TESTING_system_create ("transport-testing", 899 tth->tl_system = GNUNET_TESTING_system_create("transport-testing",
899 NULL, 900 NULL,
900 NULL, 901 NULL,
901 NULL); 902 NULL);
902 if (NULL == tth->tl_system) 903 if (NULL == tth->tl_system)
903 { 904 {
904 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 905 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
905 "Failed to initialize testing library!\n"); 906 "Failed to initialize testing library!\n");
906 GNUNET_free (tth); 907 GNUNET_free(tth);
907 return NULL; 908 return NULL;
908 } 909 }
909 return tth; 910 return tth;
910} 911}
911 912
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 83bbf277b..fc39646b2 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport-testing.h 22 * @file transport-testing.h
@@ -51,8 +51,7 @@ 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{
56 /** 55 /**
57 * Next element in the DLL 56 * Next element in the DLL
58 */ 57 */
@@ -153,8 +152,7 @@ struct GNUNET_TRANSPORT_TESTING_PeerContext
153/** 152/**
154 * Handle for a request to connect two peers. 153 * Handle for a request to connect two peers.
155 */ 154 */
156struct GNUNET_TRANSPORT_TESTING_ConnectRequest 155struct GNUNET_TRANSPORT_TESTING_ConnectRequest {
157{
158 /** 156 /**
159 * Kept in a DLL. 157 * Kept in a DLL.
160 */ 158 */
@@ -226,8 +224,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectRequest
226/** 224/**
227 * Handle for a test run. 225 * Handle for a test run.
228 */ 226 */
229struct GNUNET_TRANSPORT_TESTING_Handle 227struct GNUNET_TRANSPORT_TESTING_Handle {
230{
231 /** 228 /**
232 * Testing library system handle 229 * Testing library system handle
233 */ 230 */
@@ -261,7 +258,7 @@ struct GNUNET_TRANSPORT_TESTING_Handle
261 * @return transport testing handle 258 * @return transport testing handle
262 */ 259 */
263struct GNUNET_TRANSPORT_TESTING_Handle * 260struct GNUNET_TRANSPORT_TESTING_Handle *
264GNUNET_TRANSPORT_TESTING_init (void); 261GNUNET_TRANSPORT_TESTING_init(void);
265 262
266 263
267/** 264/**
@@ -270,7 +267,7 @@ GNUNET_TRANSPORT_TESTING_init (void);
270 * @param tth transport testing handle 267 * @param tth transport testing handle
271 */ 268 */
272void 269void
273GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth); 270GNUNET_TRANSPORT_TESTING_done(struct GNUNET_TRANSPORT_TESTING_Handle *tth);
274 271
275 272
276/** 273/**
@@ -288,7 +285,7 @@ GNUNET_TRANSPORT_TESTING_done (struct GNUNET_TRANSPORT_TESTING_Handle *tth);
288 * @return the peer context 285 * @return the peer context
289 */ 286 */
290struct GNUNET_TRANSPORT_TESTING_PeerContext * 287struct GNUNET_TRANSPORT_TESTING_PeerContext *
291GNUNET_TRANSPORT_TESTING_start_peer ( 288GNUNET_TRANSPORT_TESTING_start_peer(
292 struct GNUNET_TRANSPORT_TESTING_Handle *tth, 289 struct GNUNET_TRANSPORT_TESTING_Handle *tth,
293 const char *cfgname, 290 const char *cfgname,
294 int peer_id, 291 int peer_id,
@@ -306,7 +303,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (
306 * @param p the peer 303 * @param p the peer
307 */ 304 */
308void 305void
309GNUNET_TRANSPORT_TESTING_stop_peer ( 306GNUNET_TRANSPORT_TESTING_stop_peer(
310 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc); 307 struct GNUNET_TRANSPORT_TESTING_PeerContext *pc);
311 308
312 309
@@ -319,7 +316,7 @@ GNUNET_TRANSPORT_TESTING_stop_peer (
319 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR 316 * @return #GNUNET_OK in success otherwise #GNUNET_SYSERR
320 */ 317 */
321int 318int
322GNUNET_TRANSPORT_TESTING_restart_peer ( 319GNUNET_TRANSPORT_TESTING_restart_peer(
323 struct GNUNET_TRANSPORT_TESTING_PeerContext *p, 320 struct GNUNET_TRANSPORT_TESTING_PeerContext *p,
324 GNUNET_SCHEDULER_TaskCallback restart_cb, 321 GNUNET_SCHEDULER_TaskCallback restart_cb,
325 void *restart_cb_cls); 322 void *restart_cb_cls);
@@ -338,7 +335,7 @@ GNUNET_TRANSPORT_TESTING_restart_peer (
338 * @return a connect request handle 335 * @return a connect request handle
339 */ 336 */
340struct GNUNET_TRANSPORT_TESTING_ConnectRequest * 337struct GNUNET_TRANSPORT_TESTING_ConnectRequest *
341GNUNET_TRANSPORT_TESTING_connect_peers ( 338GNUNET_TRANSPORT_TESTING_connect_peers(
342 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 339 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
343 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 340 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
344 GNUNET_SCHEDULER_TaskCallback cb, 341 GNUNET_SCHEDULER_TaskCallback cb,
@@ -353,7 +350,7 @@ GNUNET_TRANSPORT_TESTING_connect_peers (
353 * @param cc a connect request handle 350 * @param cc a connect request handle
354 */ 351 */
355void 352void
356GNUNET_TRANSPORT_TESTING_connect_peers_cancel ( 353GNUNET_TRANSPORT_TESTING_connect_peers_cancel(
357 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc); 354 struct GNUNET_TRANSPORT_TESTING_ConnectRequest *cc);
358 355
359 356
@@ -377,7 +374,7 @@ typedef void (*GNUNET_TRANSPORT_TESTING_ConnectContextCallback) (
377 * @param cb_cls closure for @a cb 374 * @param cb_cls closure for @a cb
378 */ 375 */
379void 376void
380GNUNET_TRANSPORT_TESTING_find_connecting_context ( 377GNUNET_TRANSPORT_TESTING_find_connecting_context(
381 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1, 378 struct GNUNET_TRANSPORT_TESTING_PeerContext *p1,
382 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2, 379 struct GNUNET_TRANSPORT_TESTING_PeerContext *p2,
383 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb, 380 GNUNET_TRANSPORT_TESTING_ConnectContextCallback cb,
@@ -413,8 +410,7 @@ struct GNUNET_TRANSPORT_TESTING_InternalPeerContext;
413 410
414 411
415GNUNET_NETWORK_STRUCT_BEGIN 412GNUNET_NETWORK_STRUCT_BEGIN
416struct GNUNET_TRANSPORT_TESTING_TestMessage 413struct GNUNET_TRANSPORT_TESTING_TestMessage {
417{
418 /** 414 /**
419 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE. 415 * Type is (usually) #GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE.
420 */ 416 */
@@ -475,9 +471,7 @@ typedef void (*GNUNET_TRANSPORT_TESTING_NotifyDisconnect) (
475 * Closure that must be passed to 471 * Closure that must be passed to
476 * #GNUNET_TRANSPORT_TESTING_connect_check. 472 * #GNUNET_TRANSPORT_TESTING_connect_check.
477 */ 473 */
478struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext 474struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext {
479{
480
481 /** 475 /**
482 * How should we continue after the connect? 476 * How should we continue after the connect?
483 */ 477 */
@@ -640,7 +634,7 @@ struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext
640 * @return NULL if @a peer was not found 634 * @return NULL if @a peer was not found
641 */ 635 */
642struct GNUNET_TRANSPORT_TESTING_PeerContext * 636struct GNUNET_TRANSPORT_TESTING_PeerContext *
643GNUNET_TRANSPORT_TESTING_find_peer ( 637GNUNET_TRANSPORT_TESTING_find_peer(
644 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc, 638 struct GNUNET_TRANSPORT_TESTING_ConnectCheckContext *ccc,
645 const struct GNUNET_PeerIdentity *peer); 639 const struct GNUNET_PeerIdentity *peer);
646 640
@@ -662,7 +656,7 @@ GNUNET_TRANSPORT_TESTING_find_peer (
662 * @return #GNUNET_SYSERR on error 656 * @return #GNUNET_SYSERR on error
663 */ 657 */
664int 658int
665GNUNET_TRANSPORT_TESTING_connect_check ( 659GNUNET_TRANSPORT_TESTING_connect_check(
666 void *cls, 660 void *cls,
667 struct GNUNET_TRANSPORT_TESTING_Handle *tth_, 661 struct GNUNET_TRANSPORT_TESTING_Handle *tth_,
668 const char *test_plugin_, 662 const char *test_plugin_,
@@ -703,11 +697,11 @@ typedef int (*GNUNET_TRANSPORT_TESTING_CheckCallback) (
703 * @return #GNUNET_OK on success 697 * @return #GNUNET_OK on success
704 */ 698 */
705int 699int
706GNUNET_TRANSPORT_TESTING_main_ (const char *argv0, 700GNUNET_TRANSPORT_TESTING_main_(const char *argv0,
707 const char *filename, 701 const char *filename,
708 unsigned int num_peers, 702 unsigned int num_peers,
709 GNUNET_TRANSPORT_TESTING_CheckCallback check, 703 GNUNET_TRANSPORT_TESTING_CheckCallback check,
710 void *check_cls); 704 void *check_cls);
711 705
712 706
713/** 707/**
@@ -719,11 +713,11 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
719 * @return #GNUNET_OK on success 713 * @return #GNUNET_OK on success
720 */ 714 */
721#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \ 715#define GNUNET_TRANSPORT_TESTING_main(num_peers, check, check_cls) \
722 GNUNET_TRANSPORT_TESTING_main_ (argv[0], \ 716 GNUNET_TRANSPORT_TESTING_main_(argv[0], \
723 __FILE__, \ 717 __FILE__, \
724 num_peers, \ 718 num_peers, \
725 check, \ 719 check, \
726 check_cls) 720 check_cls)
727 721
728/* ***************** Convenience functions for sending ********* */ 722/* ***************** Convenience functions for sending ********* */
729 723
@@ -745,7 +739,7 @@ GNUNET_TRANSPORT_TESTING_main_ (const char *argv0,
745 * #GNUNET_SYSERR if @a msize is illegal 739 * #GNUNET_SYSERR if @a msize is illegal
746 */ 740 */
747int 741int
748GNUNET_TRANSPORT_TESTING_send ( 742GNUNET_TRANSPORT_TESTING_send(
749 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender, 743 struct GNUNET_TRANSPORT_TESTING_PeerContext *sender,
750 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver, 744 struct GNUNET_TRANSPORT_TESTING_PeerContext *receiver,
751 uint16_t mtype, 745 uint16_t mtype,
@@ -771,8 +765,7 @@ GNUNET_TRANSPORT_TESTING_send (
771 * #GNUNET_TRANSPORT_TESTING_simple_send() and 765 * #GNUNET_TRANSPORT_TESTING_simple_send() and
772 * #GNUNET_TRANSPORT_TESTING_large_send(). 766 * #GNUNET_TRANSPORT_TESTING_large_send().
773 */ 767 */
774struct GNUNET_TRANSPORT_TESTING_SendClosure 768struct GNUNET_TRANSPORT_TESTING_SendClosure {
775{
776 /** 769 /**
777 * Context for the transmission. 770 * Context for the transmission.
778 */ 771 */
@@ -812,7 +805,7 @@ struct GNUNET_TRANSPORT_TESTING_SendClosure
812 * of which should be currently connected 805 * of which should be currently connected
813 */ 806 */
814void 807void
815GNUNET_TRANSPORT_TESTING_simple_send (void *cls); 808GNUNET_TRANSPORT_TESTING_simple_send(void *cls);
816 809
817/** 810/**
818 * Size of a message sent with 811 * Size of a message sent with
@@ -830,7 +823,7 @@ GNUNET_TRANSPORT_TESTING_simple_send (void *cls);
830 * of which should be currently connected 823 * of which should be currently connected
831 */ 824 */
832void 825void
833GNUNET_TRANSPORT_TESTING_large_send (void *cls); 826GNUNET_TRANSPORT_TESTING_large_send(void *cls);
834 827
835 828
836/* ********************** log-only convenience functions ************* */ 829/* ********************** log-only convenience functions ************* */
@@ -844,7 +837,7 @@ GNUNET_TRANSPORT_TESTING_large_send (void *cls);
844 * @param other peer that connected. 837 * @param other peer that connected.
845 */ 838 */
846void 839void
847GNUNET_TRANSPORT_TESTING_log_connect ( 840GNUNET_TRANSPORT_TESTING_log_connect(
848 void *cls, 841 void *cls,
849 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 842 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
850 const struct GNUNET_PeerIdentity *other); 843 const struct GNUNET_PeerIdentity *other);
@@ -858,7 +851,7 @@ GNUNET_TRANSPORT_TESTING_log_connect (
858 * @param other peer that disconnected. 851 * @param other peer that disconnected.
859 */ 852 */
860void 853void
861GNUNET_TRANSPORT_TESTING_log_disconnect ( 854GNUNET_TRANSPORT_TESTING_log_disconnect(
862 void *cls, 855 void *cls,
863 struct GNUNET_TRANSPORT_TESTING_PeerContext *me, 856 struct GNUNET_TRANSPORT_TESTING_PeerContext *me,
864 const struct GNUNET_PeerIdentity *other); 857 const struct GNUNET_PeerIdentity *other);
@@ -875,7 +868,7 @@ GNUNET_TRANSPORT_TESTING_log_disconnect (
875 * @return resulting test name 868 * @return resulting test name
876 */ 869 */
877char * 870char *
878GNUNET_TRANSPORT_TESTING_get_test_name (const char *file); 871GNUNET_TRANSPORT_TESTING_get_test_name(const char *file);
879 872
880 873
881/** 874/**
@@ -887,7 +880,7 @@ GNUNET_TRANSPORT_TESTING_get_test_name (const char *file);
887 * @return configuration name to use 880 * @return configuration name to use
888 */ 881 */
889char * 882char *
890GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count); 883GNUNET_TRANSPORT_TESTING_get_config_name(const char *file, int count);
891 884
892 885
893/** 886/**
@@ -897,8 +890,8 @@ GNUNET_TRANSPORT_TESTING_get_config_name (const char *file, int count);
897 * @return the plugin name 890 * @return the plugin name
898 */ 891 */
899char * 892char *
900GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable, 893GNUNET_TRANSPORT_TESTING_get_test_plugin_name(const char *executable,
901 const char *testname); 894 const char *testname);
902 895
903 896
904/** 897/**
@@ -909,7 +902,7 @@ GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
909 * @return the source name 902 * @return the source name
910 */ 903 */
911char * 904char *
912GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file); 905GNUNET_TRANSPORT_TESTING_get_test_source_name(const char *file);
913 906
914#endif 907#endif
915/* end of transport_testing.h */ 908/* end of transport_testing.h */
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
index ae5a65f2a..6a86f9b84 100644
--- a/src/transport/transport-testing2.c
+++ b/src/transport/transport-testing2.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport-testing2.c 22 * @file transport/transport-testing2.c
@@ -35,14 +35,13 @@
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{
46 /** 45 /**
47 * @brief Handle to the configuration 46 * @brief Handle to the configuration
48 */ 47 */
@@ -146,8 +145,7 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
146/** 145/**
147 * @brief Queue of a communicator and some context 146 * @brief Queue of a communicator and some context
148 */ 147 */
149struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue 148struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue {
150{
151 /** 149 /**
152 * @brief Handle to the TransportCommunicator 150 * @brief Handle to the TransportCommunicator
153 */ 151 */
@@ -207,8 +205,7 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue
207/** 205/**
208 * @brief Handle/Context to a single transmission 206 * @brief Handle/Context to a single transmission
209 */ 207 */
210struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission 208struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission {
211{
212}; 209};
213 210
214 211
@@ -222,16 +219,16 @@ struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission
222 * @return GNUNET_YES in case message is correct 219 * @return GNUNET_YES in case message is correct
223 */ 220 */
224static int 221static int
225check_communicator_available ( 222check_communicator_available(
226 void *cls, 223 void *cls,
227 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) 224 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
228{ 225{
229 uint16_t size; 226 uint16_t size;
230 227
231 size = ntohs (msg->header.size) - sizeof (*msg); 228 size = ntohs(msg->header.size) - sizeof(*msg);
232 if (0 == size) 229 if (0 == size)
233 return GNUNET_OK; /* receive-only communicator */ 230 return GNUNET_OK; /* receive-only communicator */
234 GNUNET_MQ_check_zero_termination (msg); 231 GNUNET_MQ_check_zero_termination(msg);
235 return GNUNET_OK; 232 return GNUNET_OK;
236} 233}
237 234
@@ -245,27 +242,27 @@ check_communicator_available (
245 * @param msg Message struct 242 * @param msg Message struct
246 */ 243 */
247static void 244static void
248handle_communicator_available ( 245handle_communicator_available(
249 void *cls, 246 void *cls,
250 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg) 247 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
251{ 248{
252 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 249 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
253 uint16_t size; 250 uint16_t size;
254 251
255 size = ntohs (msg->header.size) - sizeof (*msg); 252 size = ntohs(msg->header.size) - sizeof(*msg);
256 if (0 == size) 253 if (0 == size)
257 return; /* receive-only communicator */ 254 return; /* receive-only communicator */
258 tc_h->c_characteristics = ntohl (msg->cc); 255 tc_h->c_characteristics = ntohl(msg->cc);
259 tc_h->c_addr_prefix = GNUNET_strdup ((const char *) &msg[1]); 256 tc_h->c_addr_prefix = GNUNET_strdup((const char *)&msg[1]);
260 if (NULL != tc_h->communicator_available_cb) 257 if (NULL != tc_h->communicator_available_cb)
261 { 258 {
262 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n"); 259 LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available_cb()\n");
263 tc_h->communicator_available_cb (tc_h->cb_cls, 260 tc_h->communicator_available_cb(tc_h->cb_cls,
264 tc_h, 261 tc_h,
265 tc_h->c_characteristics, 262 tc_h->c_characteristics,
266 tc_h->c_addr_prefix); 263 tc_h->c_addr_prefix);
267 } 264 }
268 GNUNET_SERVICE_client_continue (tc_h->client); 265 GNUNET_SERVICE_client_continue(tc_h->client);
269} 266}
270 267
271 268
@@ -277,8 +274,8 @@ handle_communicator_available (
277 * @return #GNUNET_OK if message is well-formed 274 * @return #GNUNET_OK if message is well-formed
278 */ 275 */
279static int 276static int
280check_add_address (void *cls, 277check_add_address(void *cls,
281 const struct GNUNET_TRANSPORT_AddAddressMessage *msg) 278 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
282{ 279{
283 struct TransportClient *tc = cls; 280 struct TransportClient *tc = cls;
284 281
@@ -287,7 +284,7 @@ check_add_address (void *cls,
287 // GNUNET_break (0); 284 // GNUNET_break (0);
288 // return GNUNET_SYSERR; 285 // return GNUNET_SYSERR;
289 //} 286 //}
290 GNUNET_MQ_check_zero_termination (msg); 287 GNUNET_MQ_check_zero_termination(msg);
291 return GNUNET_OK; 288 return GNUNET_OK;
292} 289}
293 290
@@ -301,27 +298,27 @@ check_add_address (void *cls,
301 * @param msg Message 298 * @param msg Message
302 */ 299 */
303static void 300static void
304handle_add_address (void *cls, 301handle_add_address(void *cls,
305 const struct GNUNET_TRANSPORT_AddAddressMessage *msg) 302 const struct GNUNET_TRANSPORT_AddAddressMessage *msg)
306{ 303{
307 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 304 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
308 uint16_t size; 305 uint16_t size;
309 306
310 size = ntohs (msg->header.size) - sizeof (*msg); 307 size = ntohs(msg->header.size) - sizeof(*msg);
311 if (0 == size) 308 if (0 == size)
312 return; /* receive-only communicator */ 309 return; /* receive-only communicator */
313 tc_h->c_address = GNUNET_strdup ((const char *) &msg[1]); 310 tc_h->c_address = GNUNET_strdup((const char *)&msg[1]);
314 if (NULL != tc_h->add_address_cb) 311 if (NULL != tc_h->add_address_cb)
315 { 312 {
316 LOG (GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n"); 313 LOG(GNUNET_ERROR_TYPE_DEBUG, "calling communicator_available()\n");
317 tc_h->add_address_cb (tc_h->cb_cls, 314 tc_h->add_address_cb(tc_h->cb_cls,
318 tc_h, 315 tc_h,
319 tc_h->c_address, 316 tc_h->c_address,
320 GNUNET_TIME_relative_ntoh (msg->expiration), 317 GNUNET_TIME_relative_ntoh(msg->expiration),
321 msg->aid, 318 msg->aid,
322 ntohl (msg->nt)); 319 ntohl(msg->nt));
323 } 320 }
324 GNUNET_SERVICE_client_continue (tc_h->client); 321 GNUNET_SERVICE_client_continue(tc_h->client);
325} 322}
326 323
327 324
@@ -333,7 +330,7 @@ handle_add_address (void *cls,
333 * @return #GNUNET_OK if message is well-formed 330 * @return #GNUNET_OK if message is well-formed
334 */ 331 */
335static int 332static int
336check_incoming_msg (void *cls, 333check_incoming_msg(void *cls,
337 const struct GNUNET_TRANSPORT_IncomingMessage *msg) 334 const struct GNUNET_TRANSPORT_IncomingMessage *msg)
338{ 335{
339 //struct TransportClient *tc = cls; 336 //struct TransportClient *tc = cls;
@@ -343,7 +340,7 @@ check_incoming_msg (void *cls,
343 // GNUNET_break (0); 340 // GNUNET_break (0);
344 // return GNUNET_SYSERR; 341 // return GNUNET_SYSERR;
345 //} 342 //}
346 GNUNET_MQ_check_boxed_message (msg); 343 GNUNET_MQ_check_boxed_message(msg);
347 return GNUNET_OK; 344 return GNUNET_OK;
348} 345}
349 346
@@ -357,22 +354,23 @@ check_incoming_msg (void *cls,
357 * @param msg Message 354 * @param msg Message
358 */ 355 */
359static void 356static void
360handle_incoming_msg (void *cls, 357handle_incoming_msg(void *cls,
361 const struct GNUNET_TRANSPORT_IncomingMessage *msg) 358 const struct GNUNET_TRANSPORT_IncomingMessage *msg)
362{ 359{
363 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 360 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
364 361
365 if (NULL != tc_h->incoming_msg_cb) { 362 if (NULL != tc_h->incoming_msg_cb)
366 tc_h->incoming_msg_cb (tc_h->cb_cls, 363 {
367 tc_h, 364 tc_h->incoming_msg_cb(tc_h->cb_cls,
368 (const struct GNUNET_MessageHeader *) msg); 365 tc_h,
369 } 366 (const struct GNUNET_MessageHeader *)msg);
367 }
370 else 368 else
371 { 369 {
372 LOG (GNUNET_ERROR_TYPE_WARNING, 370 LOG(GNUNET_ERROR_TYPE_WARNING,
373 "Incoming message from communicator but no handler!\n"); 371 "Incoming message from communicator but no handler!\n");
374 } 372 }
375 GNUNET_SERVICE_client_continue (tc_h->client); 373 GNUNET_SERVICE_client_continue(tc_h->client);
376} 374}
377 375
378 376
@@ -383,16 +381,16 @@ handle_incoming_msg (void *cls,
383 * @param msg Message 381 * @param msg Message
384 */ 382 */
385static void 383static void
386handle_queue_create_ok (void *cls, 384handle_queue_create_ok(void *cls,
387 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) 385 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
388{ 386{
389 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 387 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
390 388
391 if (NULL != tc_h->queue_create_reply_cb) 389 if (NULL != tc_h->queue_create_reply_cb)
392 { 390 {
393 tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_YES); 391 tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_YES);
394 } 392 }
395 GNUNET_SERVICE_client_continue (tc_h->client); 393 GNUNET_SERVICE_client_continue(tc_h->client);
396} 394}
397 395
398 396
@@ -406,17 +404,17 @@ handle_queue_create_ok (void *cls,
406 * @param msg Message 404 * @param msg Message
407 */ 405 */
408static void 406static void
409handle_queue_create_fail ( 407handle_queue_create_fail(
410 void *cls, 408 void *cls,
411 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg) 409 const struct GNUNET_TRANSPORT_CreateQueueResponse *msg)
412{ 410{
413 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 411 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
414 412
415 if (NULL != tc_h->queue_create_reply_cb) 413 if (NULL != tc_h->queue_create_reply_cb)
416 { 414 {
417 tc_h->queue_create_reply_cb (tc_h->cb_cls, tc_h, GNUNET_NO); 415 tc_h->queue_create_reply_cb(tc_h->cb_cls, tc_h, GNUNET_NO);
418 } 416 }
419 GNUNET_SERVICE_client_continue (tc_h->client); 417 GNUNET_SERVICE_client_continue(tc_h->client);
420} 418}
421 419
422 420
@@ -427,10 +425,10 @@ handle_queue_create_fail (
427 * @param aqm the send message that was sent 425 * @param aqm the send message that was sent
428 */ 426 */
429static int 427static int
430check_add_queue_message (void *cls, 428check_add_queue_message(void *cls,
431 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm) 429 const struct GNUNET_TRANSPORT_AddQueueMessage *aqm)
432{ 430{
433 GNUNET_MQ_check_zero_termination (aqm); 431 GNUNET_MQ_check_zero_termination(aqm);
434 return GNUNET_OK; 432 return GNUNET_OK;
435} 433}
436 434
@@ -444,27 +442,27 @@ check_add_queue_message (void *cls,
444 * @param msg Message struct 442 * @param msg Message struct
445 */ 443 */
446static void 444static void
447handle_add_queue_message (void *cls, 445handle_add_queue_message(void *cls,
448 const struct GNUNET_TRANSPORT_AddQueueMessage *msg) 446 const struct GNUNET_TRANSPORT_AddQueueMessage *msg)
449{ 447{
450 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 448 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
451 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue; 449 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue;
452 450
453 tc_queue = tc_h->queue_head; 451 tc_queue = tc_h->queue_head;
454 while (tc_queue->qid != msg->qid) 452 while (tc_queue->qid != msg->qid)
455 { 453 {
456 tc_queue = tc_queue->next; 454 tc_queue = tc_queue->next;
457 } 455 }
458 GNUNET_assert (tc_queue->qid == msg->qid); 456 GNUNET_assert(tc_queue->qid == msg->qid);
459 GNUNET_assert (0 == GNUNET_memcmp (&tc_queue->peer_id, &msg->receiver)); 457 GNUNET_assert(0 == GNUNET_memcmp(&tc_queue->peer_id, &msg->receiver));
460 tc_queue->nt = msg->nt; 458 tc_queue->nt = msg->nt;
461 tc_queue->mtu = msg->mtu; 459 tc_queue->mtu = msg->mtu;
462 tc_queue->cs = msg->cs; 460 tc_queue->cs = msg->cs;
463 if (NULL != tc_h->add_queue_cb) 461 if (NULL != tc_h->add_queue_cb)
464 { 462 {
465 tc_h->add_queue_cb (tc_h->cb_cls, tc_h, tc_queue); 463 tc_h->add_queue_cb(tc_h->cb_cls, tc_h, tc_queue);
466 } 464 }
467 GNUNET_SERVICE_client_continue (tc_h->client); 465 GNUNET_SERVICE_client_continue(tc_h->client);
468} 466}
469 467
470 468
@@ -474,11 +472,11 @@ handle_add_queue_message (void *cls,
474 * @param cls Closure - Handle to the service 472 * @param cls Closure - Handle to the service
475 */ 473 */
476static void 474static void
477shutdown_service (void *cls) 475shutdown_service(void *cls)
478{ 476{
479 struct GNUNET_SERVICE_Handle *h = cls; 477 struct GNUNET_SERVICE_Handle *h = cls;
480 478
481 GNUNET_SERVICE_stop (h); 479 GNUNET_SERVICE_stop(h);
482} 480}
483 481
484 482
@@ -492,14 +490,14 @@ shutdown_service (void *cls)
492 * @return TransportCommunicator Handle 490 * @return TransportCommunicator Handle
493 */ 491 */
494static void * 492static void *
495connect_cb (void *cls, 493connect_cb(void *cls,
496 struct GNUNET_SERVICE_Client *client, 494 struct GNUNET_SERVICE_Client *client,
497 struct GNUNET_MQ_Handle *mq) 495 struct GNUNET_MQ_Handle *mq)
498{ 496{
499 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 497 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
500 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter; 498 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue_iter;
501 499
502 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n"); 500 LOG(GNUNET_ERROR_TYPE_DEBUG, "Client connected.\n");
503 tc_h->client = client; 501 tc_h->client = client;
504 tc_h->c_mq = mq; 502 tc_h->c_mq = mq;
505 503
@@ -507,14 +505,14 @@ connect_cb (void *cls,
507 return tc_h; 505 return tc_h;
508 /* Iterate over queues. They are yet to be opened. Request opening. */ 506 /* Iterate over queues. They are yet to be opened. Request opening. */
509 while (NULL != (tc_queue_iter = tc_h->queue_head)) 507 while (NULL != (tc_queue_iter = tc_h->queue_head))
510 { 508 {
511 if (NULL == tc_queue_iter->open_queue_env) 509 if (NULL == tc_queue_iter->open_queue_env)
512 continue; 510 continue;
513 /* Send the previously created mq envelope to request the creation of the 511 /* Send the previously created mq envelope to request the creation of the
514 * queue. */ 512 * queue. */
515 GNUNET_MQ_send (tc_h->c_mq, tc_queue_iter->open_queue_env); 513 GNUNET_MQ_send(tc_h->c_mq, tc_queue_iter->open_queue_env);
516 tc_queue_iter->open_queue_env = NULL; 514 tc_queue_iter->open_queue_env = NULL;
517 } 515 }
518 return tc_h; 516 return tc_h;
519} 517}
520 518
@@ -527,13 +525,13 @@ connect_cb (void *cls,
527 * @param internal_cls TransporCommmunicator Handle 525 * @param internal_cls TransporCommmunicator Handle
528 */ 526 */
529static void 527static void
530disconnect_cb (void *cls, 528disconnect_cb(void *cls,
531 struct GNUNET_SERVICE_Client *client, 529 struct GNUNET_SERVICE_Client *client,
532 void *internal_cls) 530 void *internal_cls)
533{ 531{
534 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls; 532 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h = cls;
535 533
536 LOG (GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n"); 534 LOG(GNUNET_ERROR_TYPE_DEBUG, "Client disconnected.\n");
537 tc_h->client = NULL; 535 tc_h->client = NULL;
538} 536}
539 537
@@ -546,42 +544,42 @@ disconnect_cb (void *cls,
546 * @param cfg Configuration 544 * @param cfg Configuration
547 */ 545 */
548static void 546static void
549transport_communicator_start ( 547transport_communicator_start(
550 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h) 548 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
551{ 549{
552 struct GNUNET_MQ_MessageHandler mh[] = { 550 struct GNUNET_MQ_MessageHandler mh[] = {
553 GNUNET_MQ_hd_var_size (communicator_available, 551 GNUNET_MQ_hd_var_size(communicator_available,
554 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, 552 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
555 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage, 553 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
556 &tc_h), 554 &tc_h),
557 //GNUNET_MQ_hd_var_size (communicator_backchannel, 555 //GNUNET_MQ_hd_var_size (communicator_backchannel,
558 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL, 556 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
559 // struct GNUNET_TRANSPORT_CommunicatorBackchannel, 557 // struct GNUNET_TRANSPORT_CommunicatorBackchannel,
560 // NULL), 558 // NULL),
561 GNUNET_MQ_hd_var_size (add_address, 559 GNUNET_MQ_hd_var_size(add_address,
562 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, 560 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
563 struct GNUNET_TRANSPORT_AddAddressMessage, 561 struct GNUNET_TRANSPORT_AddAddressMessage,
564 &tc_h), 562 &tc_h),
565 //GNUNET_MQ_hd_fixed_size (del_address, 563 //GNUNET_MQ_hd_fixed_size (del_address,
566 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, 564 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
567 // struct GNUNET_TRANSPORT_DelAddressMessage, 565 // struct GNUNET_TRANSPORT_DelAddressMessage,
568 // NULL), 566 // NULL),
569 GNUNET_MQ_hd_var_size (incoming_msg, 567 GNUNET_MQ_hd_var_size(incoming_msg,
570 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG, 568 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
571 struct GNUNET_TRANSPORT_IncomingMessage, 569 struct GNUNET_TRANSPORT_IncomingMessage,
572 NULL), 570 NULL),
573 GNUNET_MQ_hd_fixed_size (queue_create_ok, 571 GNUNET_MQ_hd_fixed_size(queue_create_ok,
574 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, 572 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
575 struct GNUNET_TRANSPORT_CreateQueueResponse, 573 struct GNUNET_TRANSPORT_CreateQueueResponse,
576 tc_h), 574 tc_h),
577 GNUNET_MQ_hd_fixed_size (queue_create_fail, 575 GNUNET_MQ_hd_fixed_size(queue_create_fail,
578 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, 576 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
579 struct GNUNET_TRANSPORT_CreateQueueResponse, 577 struct GNUNET_TRANSPORT_CreateQueueResponse,
580 tc_h), 578 tc_h),
581 GNUNET_MQ_hd_var_size (add_queue_message, 579 GNUNET_MQ_hd_var_size(add_queue_message,
582 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, 580 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
583 struct GNUNET_TRANSPORT_AddQueueMessage, 581 struct GNUNET_TRANSPORT_AddQueueMessage,
584 NULL), 582 NULL),
585 //GNUNET_MQ_hd_fixed_size (del_queue_message, 583 //GNUNET_MQ_hd_fixed_size (del_queue_message,
586 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, 584 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
587 // struct GNUNET_TRANSPORT_DelQueueMessage, 585 // struct GNUNET_TRANSPORT_DelQueueMessage,
@@ -593,19 +591,19 @@ transport_communicator_start (
593 }; 591 };
594 struct GNUNET_SERVICE_Handle *h; 592 struct GNUNET_SERVICE_Handle *h;
595 593
596 h = GNUNET_SERVICE_start ("transport", 594 h = GNUNET_SERVICE_start("transport",
597 tc_h->cfg, 595 tc_h->cfg,
598 &connect_cb, 596 &connect_cb,
599 &disconnect_cb, 597 &disconnect_cb,
600 tc_h, 598 tc_h,
601 mh); 599 mh);
602 if (NULL == h) 600 if (NULL == h)
603 LOG (GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n"); 601 LOG(GNUNET_ERROR_TYPE_ERROR, "Failed starting service!\n");
604 else 602 else
605 { 603 {
606 LOG (GNUNET_ERROR_TYPE_DEBUG, "Started service\n"); 604 LOG(GNUNET_ERROR_TYPE_DEBUG, "Started service\n");
607 /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h); 605 /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_service, h);
608 } 606 }
609} 607}
610 608
611 609
@@ -615,21 +613,21 @@ transport_communicator_start (
615 * @param cls Closure - Process of communicator 613 * @param cls Closure - Process of communicator
616 */ 614 */
617static void 615static void
618shutdown_communicator (void *cls) 616shutdown_communicator(void *cls)
619{ 617{
620 struct GNUNET_OS_Process *proc = cls; 618 struct GNUNET_OS_Process *proc = cls;
621 619
622 if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGTERM)) 620 if (GNUNET_OK != GNUNET_OS_process_kill(proc, SIGTERM))
623 {
624 LOG (GNUNET_ERROR_TYPE_WARNING,
625 "Error shutting down communicator with SIGERM, trying SIGKILL\n");
626 if (GNUNET_OK != GNUNET_OS_process_kill (proc, SIGKILL))
627 { 621 {
628 LOG (GNUNET_ERROR_TYPE_ERROR, 622 LOG(GNUNET_ERROR_TYPE_WARNING,
629 "Error shutting down communicator with SIGERM and SIGKILL\n"); 623 "Error shutting down communicator with SIGERM, trying 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 }
630 } 629 }
631 } 630 GNUNET_OS_process_destroy(proc);
632 GNUNET_OS_process_destroy (proc);
633} 631}
634 632
635 633
@@ -639,33 +637,33 @@ shutdown_communicator (void *cls)
639 * @param cfgname Name of the communicator 637 * @param cfgname Name of the communicator
640 */ 638 */
641static void 639static void
642communicator_start ( 640communicator_start(
643 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 641 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
644 const char *binary_name) 642 const char *binary_name)
645{ 643{
646 char *binary; 644 char *binary;
647 645
648 LOG (GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n"); 646 LOG(GNUNET_ERROR_TYPE_DEBUG, "communicator_start\n");
649 binary = GNUNET_OS_get_libexec_binary_path (binary_name); 647 binary = GNUNET_OS_get_libexec_binary_path(binary_name);
650 tc_h->c_proc = GNUNET_OS_start_process (GNUNET_YES, 648 tc_h->c_proc = GNUNET_OS_start_process(GNUNET_YES,
651 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 649 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
652 NULL, 650 NULL,
653 NULL, 651 NULL,
654 NULL, 652 NULL,
655 binary, 653 binary,
656 binary_name, 654 binary_name,
657 "-c", 655 "-c",
658 tc_h->cfg_filename, 656 tc_h->cfg_filename,
659 NULL); 657 NULL);
660 if (NULL == tc_h->c_proc) 658 if (NULL == tc_h->c_proc)
661 { 659 {
662 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!"); 660 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to start communicator!");
663 return; 661 return;
664 } 662 }
665 LOG (GNUNET_ERROR_TYPE_DEBUG, "started communicator\n"); 663 LOG(GNUNET_ERROR_TYPE_DEBUG, "started communicator\n");
666 GNUNET_free (binary); 664 GNUNET_free(binary);
667 /* TODO */ GNUNET_SCHEDULER_add_shutdown (&shutdown_communicator, 665 /* TODO */ GNUNET_SCHEDULER_add_shutdown(&shutdown_communicator,
668 tc_h->c_proc); 666 tc_h->c_proc);
669} 667}
670 668
671 669
@@ -682,34 +680,34 @@ communicator_start (
682 * @return Handle to the communicator duo 680 * @return Handle to the communicator duo
683 */ 681 */
684struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 682struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
685GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 683GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
686 const char *service_name, 684 const char *service_name,
687 const char *binary_name, 685 const char *binary_name,
688 const char *cfg_filename, 686 const char *cfg_filename,
689 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback 687 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback
690 communicator_available_cb, 688 communicator_available_cb,
691 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, 689 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
692 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, 690 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
693 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, 691 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
694 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb, 692 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
695 void *cb_cls) 693 void *cb_cls)
696{ 694{
697 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h; 695 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h;
698 696
699 tc_h = 697 tc_h =
700 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle); 698 GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle);
701 tc_h->cfg_filename = GNUNET_strdup (cfg_filename); 699 tc_h->cfg_filename = GNUNET_strdup(cfg_filename);
702 tc_h->cfg = GNUNET_CONFIGURATION_create (); 700 tc_h->cfg = GNUNET_CONFIGURATION_create();
703 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load (tc_h->cfg, cfg_filename))) 701 if ((GNUNET_SYSERR == GNUNET_CONFIGURATION_load(tc_h->cfg, cfg_filename)))
704 { 702 {
705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 703 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
706 _ ("Malformed configuration file `%s', exit ...\n"), 704 _("Malformed configuration file `%s', exit ...\n"),
707 cfg_filename); 705 cfg_filename);
708 GNUNET_free (tc_h->cfg_filename); 706 GNUNET_free(tc_h->cfg_filename);
709 GNUNET_CONFIGURATION_destroy (tc_h->cfg); 707 GNUNET_CONFIGURATION_destroy(tc_h->cfg);
710 GNUNET_free (tc_h); 708 GNUNET_free(tc_h);
711 return NULL; 709 return NULL;
712 } 710 }
713 tc_h->communicator_available_cb = communicator_available_cb; 711 tc_h->communicator_available_cb = communicator_available_cb;
714 tc_h->add_address_cb = add_address_cb; 712 tc_h->add_address_cb = add_address_cb;
715 tc_h->queue_create_reply_cb = queue_create_reply_cb; 713 tc_h->queue_create_reply_cb = queue_create_reply_cb;
@@ -718,11 +716,11 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
718 tc_h->cb_cls = cb_cls; 716 tc_h->cb_cls = cb_cls;
719 717
720 /* Start communicator part of service */ 718 /* Start communicator part of service */
721 transport_communicator_start (tc_h); 719 transport_communicator_start(tc_h);
722 720
723 /* Schedule start communicator */ 721 /* Schedule start communicator */
724 communicator_start (tc_h, 722 communicator_start(tc_h,
725 binary_name); 723 binary_name);
726 return tc_h; 724 return tc_h;
727} 725}
728 726
@@ -735,7 +733,7 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
735 * @param address For which address 733 * @param address For which address
736 */ 734 */
737void 735void
738GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue ( 736GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(
739 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 737 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
740 const struct GNUNET_PeerIdentity *peer_id, 738 const struct GNUNET_PeerIdentity *peer_id,
741 const char *address) 739 const char *address)
@@ -748,33 +746,33 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (
748 size_t alen; 746 size_t alen;
749 747
750 tc_queue = 748 tc_queue =
751 GNUNET_new (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue); 749 GNUNET_new(struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue);
752 tc_queue->tc_h = tc_h; 750 tc_queue->tc_h = tc_h;
753 prefix = GNUNET_HELLO_address_to_prefix (address); 751 prefix = GNUNET_HELLO_address_to_prefix(address);
754 if (NULL == prefix) 752 if (NULL == prefix)
755 { 753 {
756 GNUNET_break (0); /* We got an invalid address!? */ 754 GNUNET_break(0); /* We got an invalid address!? */
757 GNUNET_free (tc_queue); 755 GNUNET_free(tc_queue);
758 return; 756 return;
759 } 757 }
760 GNUNET_free (prefix); 758 GNUNET_free(prefix);
761 alen = strlen (address) + 1; 759 alen = strlen(address) + 1;
762 env = 760 env =
763 GNUNET_MQ_msg_extra (msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE); 761 GNUNET_MQ_msg_extra(msg, alen, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE);
764 msg->request_id = htonl (idgen++); 762 msg->request_id = htonl(idgen++);
765 tc_queue->qid = msg->request_id; 763 tc_queue->qid = msg->request_id;
766 msg->receiver = *peer_id; 764 msg->receiver = *peer_id;
767 tc_queue->peer_id = *peer_id; 765 tc_queue->peer_id = *peer_id;
768 memcpy (&msg[1], address, alen); 766 memcpy(&msg[1], address, alen);
769 if (NULL != tc_h->c_mq) 767 if (NULL != tc_h->c_mq)
770 { 768 {
771 GNUNET_MQ_send (tc_h->c_mq, env); 769 GNUNET_MQ_send(tc_h->c_mq, env);
772 } 770 }
773 else 771 else
774 { 772 {
775 tc_queue->open_queue_env = env; 773 tc_queue->open_queue_env = env;
776 } 774 }
777 GNUNET_CONTAINER_DLL_insert (tc_h->queue_head, tc_h->queue_tail, tc_queue); 775 GNUNET_CONTAINER_DLL_insert(tc_h->queue_head, tc_h->queue_tail, tc_queue);
778} 776}
779 777
780 778
@@ -790,10 +788,10 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (
790struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * 788struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
791GNUNET_TRANSPORT_TESTING_transport_communicator_send 789GNUNET_TRANSPORT_TESTING_transport_communicator_send
792 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, 790 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue,
793 const void *payload, 791 const void *payload,
794 size_t payload_size/*, 792 size_t payload_size /*,
795 GNUNET_TRANSPORT_TESTING_SuccessStatus cb, 793 GNUNET_TRANSPORT_TESTING_SuccessStatus cb,
796 void *cb_cls*/) 794 void *cb_cls*/)
797{ 795{
798 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t; 796 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *tc_t;
799 struct GNUNET_MessageHeader *mh; 797 struct GNUNET_MessageHeader *mh;
@@ -801,21 +799,21 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_send
801 struct GNUNET_MQ_Envelope *env; 799 struct GNUNET_MQ_Envelope *env;
802 size_t inbox_size; 800 size_t inbox_size;
803 801
804 inbox_size = sizeof (struct GNUNET_MessageHeader) + payload_size; 802 inbox_size = sizeof(struct GNUNET_MessageHeader) + payload_size;
805 mh = GNUNET_malloc (inbox_size); 803 mh = GNUNET_malloc(inbox_size);
806 mh->size = htons (inbox_size); 804 mh->size = htons(inbox_size);
807 mh->type = GNUNET_MESSAGE_TYPE_DUMMY; 805 mh->type = GNUNET_MESSAGE_TYPE_DUMMY;
808 memcpy (&mh[1], 806 memcpy(&mh[1],
809 payload, 807 payload,
810 payload_size); 808 payload_size);
811 env = GNUNET_MQ_msg_extra (msg, 809 env = GNUNET_MQ_msg_extra(msg,
812 inbox_size, 810 inbox_size,
813 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG); 811 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG);
814 msg->qid = htonl (tc_queue->qid); 812 msg->qid = htonl(tc_queue->qid);
815 msg->mid = tc_queue->mid++; 813 msg->mid = tc_queue->mid++;
816 msg->receiver = tc_queue->peer_id; 814 msg->receiver = tc_queue->peer_id;
817 memcpy (&msg[1], mh, inbox_size); 815 memcpy(&msg[1], mh, inbox_size);
818 GNUNET_free (mh); 816 GNUNET_free(mh);
819 GNUNET_MQ_send (tc_queue->tc_h->c_mq, env); 817 GNUNET_MQ_send(tc_queue->tc_h->c_mq, env);
820 return tc_t; 818 return tc_t;
821} 819}
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index fbc1927d9..8954e20d1 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport-testing2.h 22 * @file transport/transport-testing2.h
@@ -59,9 +59,9 @@ 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 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
63 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 63 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
64 char *address_prefix); 64 char *address_prefix);
65 65
66 66
67/** 67/**
@@ -76,11 +76,11 @@ typedef void
76 */ 76 */
77typedef void 77typedef void
78(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls, 78(*GNUNET_TRANSPORT_TESTING_AddAddressCallback)(void *cls,
79 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 79 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
80 const char *address, 80 const char *address,
81 struct GNUNET_TIME_Relative expiration, 81 struct GNUNET_TIME_Relative expiration,
82 uint32_t aid, 82 uint32_t aid,
83 enum GNUNET_NetworkType nt); 83 enum GNUNET_NetworkType nt);
84 84
85 85
86/** 86/**
@@ -92,8 +92,8 @@ typedef void
92 */ 92 */
93typedef void 93typedef void
94(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls, 94(*GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback)(void *cls,
95 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 95 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
96 int will_try); 96 int will_try);
97 97
98 98
99/** 99/**
@@ -105,8 +105,8 @@ typedef void
105 */ 105 */
106typedef void 106typedef void
107(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls, 107(*GNUNET_TRANSPORT_TESTING_AddQueueCallback)(void *cls,
108 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 108 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
109 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue); 109 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue);
110 110
111 111
112/** 112/**
@@ -118,8 +118,8 @@ typedef void
118 */ 118 */
119typedef void 119typedef void
120(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls, 120(*GNUNET_TRANSPORT_TESTING_IncomingMessageCallback)(void *cls,
121 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 121 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
122 const struct GNUNET_MessageHeader *msg); 122 const struct GNUNET_MessageHeader *msg);
123 123
124 124
125/** 125/**
@@ -138,16 +138,16 @@ typedef void
138 * @return Handle to the communicator duo 138 * @return Handle to the communicator duo
139 */ 139 */
140struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle * 140struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
141GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 141GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
142 const char *service_name, 142 const char *service_name,
143 const char *binary_name, 143 const char *binary_name,
144 const char *cfg_filename, 144 const char *cfg_filename,
145 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb, 145 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available_cb,
146 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb, 146 GNUNET_TRANSPORT_TESTING_AddAddressCallback add_address_cb,
147 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb, 147 GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback queue_create_reply_cb,
148 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb, 148 GNUNET_TRANSPORT_TESTING_AddQueueCallback add_queue_cb,
149 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb, 149 GNUNET_TRANSPORT_TESTING_IncomingMessageCallback incoming_message_cb,
150 void *cb_cls); 150 void *cb_cls);
151 151
152 152
153/** 153/**
@@ -160,8 +160,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
160void 160void
161GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue 161GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
162 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 162 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
163 const struct GNUNET_PeerIdentity *peer_id, 163 const struct GNUNET_PeerIdentity *peer_id,
164 const char *address); 164 const char *address);
165 165
166 166
167/** 167/**
@@ -176,8 +176,8 @@ GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
176struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission * 176struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
177GNUNET_TRANSPORT_TESTING_transport_communicator_send 177GNUNET_TRANSPORT_TESTING_transport_communicator_send
178 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue, 178 (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue,
179 const void *payload, 179 const void *payload,
180 size_t payload_size/*, 180 size_t payload_size /*,
181 GNUNET_TRANSPORT_TESTING_SuccessStatus cb, 181 GNUNET_TRANSPORT_TESTING_SuccessStatus cb,
182 void *cb_cls*/); 182 void *cb_cls*/);
183 183
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 7fe869fa8..7e2fd4739 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport.h 22 * @file 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,9 +88,7 @@ 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{
93
94 /** 92 /**
95 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START 93 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_START
96 */ 94 */
@@ -115,24 +113,20 @@ struct StartMessage
115 * Message from the transport service to the library 113 * Message from the transport service to the library
116 * informing about neighbors. 114 * informing about neighbors.
117 */ 115 */
118struct ConnectInfoMessage 116struct ConnectInfoMessage {
119{
120
121 /** 117 /**
122 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT 118 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
123 */ 119 */
124 struct GNUNET_MessageHeader header; 120 struct GNUNET_MessageHeader header;
125 121
126#if (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 122#if (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
127 defined(GNUNET_TRANSPORT_CORE_VERSION)) 123 defined(GNUNET_TRANSPORT_CORE_VERSION))
128 124
129 /** 125 /**
130 * Always zero, for alignment. 126 * Always zero, for alignment.
131 */ 127 */
132 uint32_t reserved GNUNET_PACKED; 128 uint32_t reserved GNUNET_PACKED;
133
134#else 129#else
135
136 /** 130 /**
137 * Current outbound quota for this peer 131 * Current outbound quota for this peer
138 */ 132 */
@@ -150,9 +144,7 @@ struct ConnectInfoMessage
150 * Message from the transport service to the library 144 * Message from the transport service to the library
151 * informing about disconnects. 145 * informing about disconnects.
152 */ 146 */
153struct DisconnectInfoMessage 147struct DisconnectInfoMessage {
154{
155
156 /** 148 /**
157 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT 149 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
158 */ 150 */
@@ -177,9 +169,7 @@ struct DisconnectInfoMessage
177 * 169 *
178 * NOTE: no longer used in TNG! 170 * NOTE: no longer used in TNG!
179 */ 171 */
180struct QuotaSetMessage 172struct QuotaSetMessage {
181{
182
183 /** 173 /**
184 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA 174 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
185 */ 175 */
@@ -201,9 +191,7 @@ struct QuotaSetMessage
201 * Message used to notify the transport API about a message 191 * Message used to notify the transport API about a message
202 * received from the network. The actual message follows. 192 * received from the network. The actual message follows.
203 */ 193 */
204struct InboundMessage 194struct InboundMessage {
205{
206
207 /** 195 /**
208 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV 196 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
209 */ 197 */
@@ -220,21 +208,17 @@ struct InboundMessage
220 * Message used to notify the transport API that it can 208 * Message used to notify the transport API that it can
221 * send another message to the transport service. 209 * send another message to the transport service.
222 */ 210 */
223struct SendOkMessage 211struct SendOkMessage {
224{
225
226 /** 212 /**
227 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK 213 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
228 */ 214 */
229 struct GNUNET_MessageHeader header; 215 struct GNUNET_MessageHeader header;
230 216
231#if (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 217#if (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
232 defined(GNUNET_TRANSPORT_CORE_VERSION)) 218 defined(GNUNET_TRANSPORT_CORE_VERSION))
233 219
234 uint32_t reserved GNUNET_PACKED; 220 uint32_t reserved GNUNET_PACKED;
235
236#else 221#else
237
238 /** 222 /**
239 * #GNUNET_OK if the transmission succeeded, 223 * #GNUNET_OK if the transmission succeeded,
240 * #GNUNET_SYSERR if it failed (i.e. network disconnect); 224 * #GNUNET_SYSERR if it failed (i.e. network disconnect);
@@ -253,7 +237,6 @@ struct SendOkMessage
253 * Includes plugin and protocol specific overheads. 237 * Includes plugin and protocol specific overheads.
254 */ 238 */
255 uint32_t bytes_physical GNUNET_PACKED; 239 uint32_t bytes_physical GNUNET_PACKED;
256
257#endif 240#endif
258 241
259 /** 242 /**
@@ -268,9 +251,7 @@ struct SendOkMessage
268 * send another message to the transport service. 251 * send another message to the transport service.
269 * (Used to implement flow control.) 252 * (Used to implement flow control.)
270 */ 253 */
271struct RecvOkMessage 254struct RecvOkMessage {
272{
273
274 /** 255 /**
275 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK 256 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK
276 */ 257 */
@@ -293,9 +274,7 @@ struct RecvOkMessage
293 * Message used to notify the transport service about a message 274 * Message used to notify the transport service about a message
294 * to be transmitted to another peer. The actual message follows. 275 * to be transmitted to another peer. The actual message follows.
295 */ 276 */
296struct OutboundMessage 277struct OutboundMessage {
297{
298
299 /** 278 /**
300 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND 279 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND
301 */ 280 */
@@ -306,8 +285,8 @@ struct OutboundMessage
306 */ 285 */
307 uint32_t priority GNUNET_PACKED; 286 uint32_t priority GNUNET_PACKED;
308 287
309#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 288#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
310 defined(GNUNET_TRANSPORT_CORE_VERSION)) 289 defined(GNUNET_TRANSPORT_CORE_VERSION))
311 290
312 /** 291 /**
313 * Allowed delay. 292 * Allowed delay.
@@ -322,8 +301,8 @@ struct OutboundMessage
322}; 301};
323 302
324 303
325#if ! (defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \ 304#if !(defined(GNUNET_TRANSPORT_COMMUNICATION_VERSION) || \
326 defined(GNUNET_TRANSPORT_CORE_VERSION)) 305 defined(GNUNET_TRANSPORT_CORE_VERSION))
327 306
328 307
329/** 308/**
@@ -333,9 +312,7 @@ struct OutboundMessage
333 * last message must have a @e res of #GNUNET_OK and an @e addr_len 312 * last message must have a @e res of #GNUNET_OK and an @e addr_len
334 * of zero. 313 * of zero.
335 */ 314 */
336struct AddressToStringResultMessage 315struct AddressToStringResultMessage {
337{
338
339 /** 316 /**
340 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY 317 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY
341 */ 318 */
@@ -359,9 +336,7 @@ struct AddressToStringResultMessage
359 * asking for converting a transport address to a 336 * asking for converting a transport address to a
360 * human-readable UTF-8 string. 337 * human-readable UTF-8 string.
361 */ 338 */
362struct AddressLookupMessage 339struct AddressLookupMessage {
363{
364
365 /** 340 /**
366 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING 341 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING
367 */ 342 */
@@ -398,8 +373,7 @@ struct AddressLookupMessage
398 * Memory layout: 373 * Memory layout:
399 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] 374 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
400 */ 375 */
401struct ValidationIterateResponseMessage 376struct ValidationIterateResponseMessage {
402{
403 /** 377 /**
404 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE 378 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_RESPONSE
405 */ 379 */
@@ -459,8 +433,7 @@ struct ValidationIterateResponseMessage
459 * Message from the library to the transport service 433 * Message from the library to the transport service
460 * asking for binary addresses known for a peer. 434 * asking for binary addresses known for a peer.
461 */ 435 */
462struct ValidationMonitorMessage 436struct ValidationMonitorMessage {
463{
464 /** 437 /**
465 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST 438 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_VALIDATION_REQUEST
466 */ 439 */
@@ -482,8 +455,7 @@ struct ValidationMonitorMessage
482 * Message from the library to the transport service 455 * Message from the library to the transport service
483 * asking for binary addresses known for a peer. 456 * asking for binary addresses known for a peer.
484 */ 457 */
485struct PeerMonitorMessage 458struct PeerMonitorMessage {
486{
487 /** 459 /**
488 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST 460 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST
489 */ 461 */
@@ -505,8 +477,7 @@ struct PeerMonitorMessage
505 * Message from the library to the transport service 477 * Message from the library to the transport service
506 * asking for binary addresses known for a peer. 478 * asking for binary addresses known for a peer.
507 */ 479 */
508struct TrafficMetricMessage 480struct TrafficMetricMessage {
509{
510 /** 481 /**
511 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC 482 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC
512 */ 483 */
@@ -549,8 +520,7 @@ struct TrafficMetricMessage
549 * Memory layout: 520 * Memory layout:
550 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]] 521 * [AddressIterateResponseMessage][address[addrlen]][transportname[pluginlen]]
551 */ 522 */
552struct PeerIterateResponseMessage 523struct PeerIterateResponseMessage {
553{
554 /** 524 /**
555 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE 525 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE
556 */ 526 */
@@ -597,9 +567,7 @@ struct PeerIterateResponseMessage
597 * Change in blacklisting (either request or notification, 567 * Change in blacklisting (either request or notification,
598 * depending on which direction it is going). 568 * depending on which direction it is going).
599 */ 569 */
600struct BlacklistMessage 570struct BlacklistMessage {
601{
602
603 /** 571 /**
604 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or 572 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY or
605 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY. 573 * #GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY.
@@ -622,9 +590,7 @@ struct BlacklistMessage
622/** 590/**
623 * Transport-level connection status update. 591 * Transport-level connection status update.
624 */ 592 */
625struct TransportPluginMonitorMessage 593struct TransportPluginMonitorMessage {
626{
627
628 /** 594 /**
629 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT. 595 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT.
630 */ 596 */
@@ -697,9 +663,7 @@ struct TransportPluginMonitorMessage
697 * Communicator goes online. Note which addresses it can 663 * Communicator goes online. Note which addresses it can
698 * work with. 664 * work with.
699 */ 665 */
700struct GNUNET_TRANSPORT_CommunicatorAvailableMessage 666struct GNUNET_TRANSPORT_CommunicatorAvailableMessage {
701{
702
703 /** 667 /**
704 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR. 668 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR.
705 */ 669 */
@@ -717,9 +681,7 @@ struct GNUNET_TRANSPORT_CommunicatorAvailableMessage
717/** 681/**
718 * Add address to the list. 682 * Add address to the list.
719 */ 683 */
720struct GNUNET_TRANSPORT_AddAddressMessage 684struct GNUNET_TRANSPORT_AddAddressMessage {
721{
722
723 /** 685 /**
724 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS. 686 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS.
725 */ 687 */
@@ -747,9 +709,7 @@ struct GNUNET_TRANSPORT_AddAddressMessage
747/** 709/**
748 * Remove address from the list. 710 * Remove address from the list.
749 */ 711 */
750struct GNUNET_TRANSPORT_DelAddressMessage 712struct GNUNET_TRANSPORT_DelAddressMessage {
751{
752
753 /** 713 /**
754 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS. 714 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS.
755 */ 715 */
@@ -765,9 +725,7 @@ struct GNUNET_TRANSPORT_DelAddressMessage
765/** 725/**
766 * Inform transport about an incoming message. 726 * Inform transport about an incoming message.
767 */ 727 */
768struct GNUNET_TRANSPORT_IncomingMessage 728struct GNUNET_TRANSPORT_IncomingMessage {
769{
770
771 /** 729 /**
772 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG. 730 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG.
773 */ 731 */
@@ -802,9 +760,7 @@ struct GNUNET_TRANSPORT_IncomingMessage
802 * Transport informs us about being done with an incoming message. 760 * Transport informs us about being done with an incoming message.
803 * (only sent if fc_on was set). 761 * (only sent if fc_on was set).
804 */ 762 */
805struct GNUNET_TRANSPORT_IncomingMessageAck 763struct GNUNET_TRANSPORT_IncomingMessageAck {
806{
807
808 /** 764 /**
809 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK. 765 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK.
810 */ 766 */
@@ -830,9 +786,7 @@ struct GNUNET_TRANSPORT_IncomingMessageAck
830/** 786/**
831 * Add queue to the transport 787 * Add queue to the transport
832 */ 788 */
833struct GNUNET_TRANSPORT_AddQueueMessage 789struct GNUNET_TRANSPORT_AddQueueMessage {
834{
835
836 /** 790 /**
837 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP. 791 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP.
838 */ 792 */
@@ -870,9 +824,7 @@ struct GNUNET_TRANSPORT_AddQueueMessage
870/** 824/**
871 * Remove queue, it is no longer available. 825 * Remove queue, it is no longer available.
872 */ 826 */
873struct GNUNET_TRANSPORT_DelQueueMessage 827struct GNUNET_TRANSPORT_DelQueueMessage {
874{
875
876 /** 828 /**
877 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN. 829 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN.
878 */ 830 */
@@ -893,9 +845,7 @@ struct GNUNET_TRANSPORT_DelQueueMessage
893/** 845/**
894 * Transport tells communicator that it wants a new queue. 846 * Transport tells communicator that it wants a new queue.
895 */ 847 */
896struct GNUNET_TRANSPORT_CreateQueue 848struct GNUNET_TRANSPORT_CreateQueue {
897{
898
899 /** 849 /**
900 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE. 850 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE.
901 */ 851 */
@@ -918,9 +868,7 @@ struct GNUNET_TRANSPORT_CreateQueue
918/** 868/**
919 * Communicator tells transport how queue creation went down. 869 * Communicator tells transport how queue creation went down.
920 */ 870 */
921struct GNUNET_TRANSPORT_CreateQueueResponse 871struct GNUNET_TRANSPORT_CreateQueueResponse {
922{
923
924 /** 872 /**
925 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or 873 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK or
926 * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL. 874 * #GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL.
@@ -937,9 +885,7 @@ struct GNUNET_TRANSPORT_CreateQueueResponse
937/** 885/**
938 * Inform communicator about transport's desire to send a message. 886 * Inform communicator about transport's desire to send a message.
939 */ 887 */
940struct GNUNET_TRANSPORT_SendMessageTo 888struct GNUNET_TRANSPORT_SendMessageTo {
941{
942
943 /** 889 /**
944 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG. 890 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG.
945 */ 891 */
@@ -967,9 +913,7 @@ struct GNUNET_TRANSPORT_SendMessageTo
967/** 913/**
968 * Inform transport that message was sent. 914 * Inform transport that message was sent.
969 */ 915 */
970struct GNUNET_TRANSPORT_SendMessageToAck 916struct GNUNET_TRANSPORT_SendMessageToAck {
971{
972
973 /** 917 /**
974 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK. 918 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK.
975 */ 919 */
@@ -997,8 +941,7 @@ struct GNUNET_TRANSPORT_SendMessageToAck
997 * transmission of a backchannel message with the given peer @e pid 941 * transmission of a backchannel message with the given peer @e pid
998 * and communicator. 942 * and communicator.
999 */ 943 */
1000struct GNUNET_TRANSPORT_CommunicatorBackchannel 944struct GNUNET_TRANSPORT_CommunicatorBackchannel {
1001{
1002 /** 945 /**
1003 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL 946 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL
1004 */ 947 */
@@ -1026,8 +969,7 @@ struct GNUNET_TRANSPORT_CommunicatorBackchannel
1026 * Message from transport to communicator passing along a backchannel 969 * Message from transport to communicator passing along a backchannel
1027 * message from the given peer @e pid. 970 * message from the given peer @e pid.
1028 */ 971 */
1029struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming 972struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming {
1030{
1031 /** 973 /**
1032 * Type will be 974 * Type will be
1033 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING 975 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
@@ -1052,9 +994,7 @@ struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming
1052/** 994/**
1053 * Request to start monitoring. 995 * Request to start monitoring.
1054 */ 996 */
1055struct GNUNET_TRANSPORT_MonitorStart 997struct GNUNET_TRANSPORT_MonitorStart {
1056{
1057
1058 /** 998 /**
1059 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START. 999 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START.
1060 */ 1000 */
@@ -1075,9 +1015,7 @@ struct GNUNET_TRANSPORT_MonitorStart
1075/** 1015/**
1076 * Monitoring data. 1016 * Monitoring data.
1077 */ 1017 */
1078struct GNUNET_TRANSPORT_MonitorData 1018struct GNUNET_TRANSPORT_MonitorData {
1079{
1080
1081 /** 1019 /**
1082 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA. 1020 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA.
1083 */ 1021 */
@@ -1127,9 +1065,7 @@ struct GNUNET_TRANSPORT_MonitorData
1127/** 1065/**
1128 * Request to verify address. 1066 * Request to verify address.
1129 */ 1067 */
1130struct GNUNET_TRANSPORT_AddressToVerify 1068struct GNUNET_TRANSPORT_AddressToVerify {
1131{
1132
1133 /** 1069 /**
1134 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY. 1070 * Type will be #GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_CONSIDER_VERIFY.
1135 */ 1071 */
@@ -1153,8 +1089,7 @@ struct GNUNET_TRANSPORT_AddressToVerify
1153 * Application client to TRANSPORT service: we would like to have 1089 * Application client to TRANSPORT service: we would like to have
1154 * address suggestions for this peer. 1090 * address suggestions for this peer.
1155 */ 1091 */
1156struct ExpressPreferenceMessage 1092struct ExpressPreferenceMessage {
1157{
1158 /** 1093 /**
1159 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST or 1094 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST or
1160 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL to stop 1095 * #GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL to stop
@@ -1184,9 +1119,7 @@ struct ExpressPreferenceMessage
1184 * We got an address of another peer, TRANSPORT service 1119 * We got an address of another peer, TRANSPORT service
1185 * should validate it. There is no response. 1120 * should validate it. There is no response.
1186 */ 1121 */
1187struct RequestHelloValidationMessage 1122struct RequestHelloValidationMessage {
1188{
1189
1190 /** 1123 /**
1191 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION. 1124 * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION.
1192 */ 1125 */
diff --git a/src/transport/transport_api2_application.c b/src/transport/transport_api2_application.c
index 7d790d738..8ddf48a86 100644
--- a/src/transport/transport_api2_application.c
+++ b/src/transport/transport_api2_application.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/transport_api2_application.c 21 * @file transport/transport_api2_application.c
22 * @brief enable clients to ask TRANSPORT about establishing connections to peers 22 * @brief enable clients to ask TRANSPORT about establishing connections to peers
@@ -30,14 +30,13 @@
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{
41 /** 40 /**
42 * ID of the peer for which address suggestion was requested. 41 * ID of the peer for which address suggestion was requested.
43 */ 42 */
@@ -63,9 +62,7 @@ struct GNUNET_TRANSPORT_ApplicationSuggestHandle
63/** 62/**
64 * Handle to the TRANSPORT subsystem for application management. 63 * Handle to the TRANSPORT subsystem for application management.
65 */ 64 */
66struct GNUNET_TRANSPORT_ApplicationHandle 65struct GNUNET_TRANSPORT_ApplicationHandle {
67{
68
69 /** 66 /**
70 * Our configuration. 67 * Our configuration.
71 */ 68 */
@@ -101,7 +98,7 @@ struct GNUNET_TRANSPORT_ApplicationHandle
101 * @param ch handle to use to re-connect. 98 * @param ch handle to use to re-connect.
102 */ 99 */
103static void 100static void
104reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch); 101reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch);
105 102
106 103
107/** 104/**
@@ -110,12 +107,12 @@ reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch);
110 * @param cls handle to use to re-connect. 107 * @param cls handle to use to re-connect.
111 */ 108 */
112static void 109static void
113reconnect_task (void *cls) 110reconnect_task(void *cls)
114{ 111{
115 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 112 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
116 113
117 ch->task = NULL; 114 ch->task = NULL;
118 reconnect (ch); 115 reconnect(ch);
119} 116}
120 117
121 118
@@ -125,15 +122,15 @@ reconnect_task (void *cls)
125 * @param ch our handle 122 * @param ch our handle
126 */ 123 */
127static void 124static void
128force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) 125force_reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
129{ 126{
130 if (NULL != ch->mq) 127 if (NULL != ch->mq)
131 { 128 {
132 GNUNET_MQ_destroy (ch->mq); 129 GNUNET_MQ_destroy(ch->mq);
133 ch->mq = NULL; 130 ch->mq = NULL;
134 } 131 }
135 ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff); 132 ch->backoff = GNUNET_TIME_STD_BACKOFF(ch->backoff);
136 ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff, &reconnect_task, ch); 133 ch->task = GNUNET_SCHEDULER_add_delayed(ch->backoff, &reconnect_task, ch);
137} 134}
138 135
139 136
@@ -145,14 +142,14 @@ force_reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
145 * @param error details about the error 142 * @param error details about the error
146 */ 143 */
147static void 144static void
148error_handler (void *cls, enum GNUNET_MQ_Error error) 145error_handler(void *cls, enum GNUNET_MQ_Error error)
149{ 146{
150 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 147 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
151 148
152 LOG (GNUNET_ERROR_TYPE_DEBUG, 149 LOG(GNUNET_ERROR_TYPE_DEBUG,
153 "TRANSPORT connection died (code %d), reconnecting\n", 150 "TRANSPORT connection died (code %d), reconnecting\n",
154 (int) error); 151 (int)error);
155 force_reconnect (ch); 152 force_reconnect(ch);
156} 153}
157 154
158 155
@@ -166,9 +163,9 @@ error_handler (void *cls, enum GNUNET_MQ_Error error)
166 * failure (message queue no longer exists) 163 * failure (message queue no longer exists)
167 */ 164 */
168static int 165static int
169transmit_suggestion (void *cls, 166transmit_suggestion(void *cls,
170 const struct GNUNET_PeerIdentity *peer, 167 const struct GNUNET_PeerIdentity *peer,
171 void *value) 168 void *value)
172{ 169{
173 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls; 170 struct GNUNET_TRANSPORT_ApplicationHandle *ch = cls;
174 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value; 171 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh = value;
@@ -177,11 +174,11 @@ transmit_suggestion (void *cls,
177 174
178 if (NULL == ch->mq) 175 if (NULL == ch->mq)
179 return GNUNET_SYSERR; 176 return GNUNET_SYSERR;
180 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST); 177 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST);
181 m->pk = htonl ((uint32_t) sh->pk); 178 m->pk = htonl((uint32_t)sh->pk);
182 m->bw = sh->bw; 179 m->bw = sh->bw;
183 m->peer = *peer; 180 m->peer = *peer;
184 GNUNET_MQ_send (ch->mq, ev); 181 GNUNET_MQ_send(ch->mq, ev);
185 return GNUNET_OK; 182 return GNUNET_OK;
186} 183}
187 184
@@ -192,21 +189,21 @@ transmit_suggestion (void *cls,
192 * @param ch handle to use to re-connect. 189 * @param ch handle to use to re-connect.
193 */ 190 */
194static void 191static void
195reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch) 192reconnect(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
196{ 193{
197 static const struct GNUNET_MQ_MessageHandler handlers[] = {{NULL, 0, 0}}; 194 static const struct GNUNET_MQ_MessageHandler handlers[] = { { NULL, 0, 0 } };
198 195
199 GNUNET_assert (NULL == ch->mq); 196 GNUNET_assert(NULL == ch->mq);
200 ch->mq = 197 ch->mq =
201 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch); 198 GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch);
202 if (NULL == ch->mq) 199 if (NULL == ch->mq)
203 { 200 {
204 force_reconnect (ch); 201 force_reconnect(ch);
205 return; 202 return;
206 } 203 }
207 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, 204 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests,
208 &transmit_suggestion, 205 &transmit_suggestion,
209 ch); 206 ch);
210} 207}
211 208
212 209
@@ -217,15 +214,15 @@ reconnect (struct GNUNET_TRANSPORT_ApplicationHandle *ch)
217 * @return transport application handle, NULL on error 214 * @return transport application handle, NULL on error
218 */ 215 */
219struct GNUNET_TRANSPORT_ApplicationHandle * 216struct GNUNET_TRANSPORT_ApplicationHandle *
220GNUNET_TRANSPORT_application_init ( 217GNUNET_TRANSPORT_application_init(
221 const struct GNUNET_CONFIGURATION_Handle *cfg) 218 const struct GNUNET_CONFIGURATION_Handle *cfg)
222{ 219{
223 struct GNUNET_TRANSPORT_ApplicationHandle *ch; 220 struct GNUNET_TRANSPORT_ApplicationHandle *ch;
224 221
225 ch = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationHandle); 222 ch = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationHandle);
226 ch->cfg = cfg; 223 ch->cfg = cfg;
227 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create (32, GNUNET_YES); 224 ch->sug_requests = GNUNET_CONTAINER_multipeermap_create(32, GNUNET_YES);
228 reconnect (ch); 225 reconnect(ch);
229 return ch; 226 return ch;
230} 227}
231 228
@@ -240,11 +237,11 @@ GNUNET_TRANSPORT_application_init (
240 * @return #GNUNET_OK (continue to iterate) 237 * @return #GNUNET_OK (continue to iterate)
241 */ 238 */
242static int 239static int
243free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 240free_sug_handle(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
244{ 241{
245 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value; 242 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *cur = value;
246 243
247 GNUNET_free (cur); 244 GNUNET_free(cur);
248 return GNUNET_OK; 245 return GNUNET_OK;
249} 246}
250 247
@@ -255,24 +252,24 @@ free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
255 * @param ch handle to release 252 * @param ch handle to release
256 */ 253 */
257void 254void
258GNUNET_TRANSPORT_application_done ( 255GNUNET_TRANSPORT_application_done(
259 struct GNUNET_TRANSPORT_ApplicationHandle *ch) 256 struct GNUNET_TRANSPORT_ApplicationHandle *ch)
260{ 257{
261 if (NULL != ch->mq) 258 if (NULL != ch->mq)
262 { 259 {
263 GNUNET_MQ_destroy (ch->mq); 260 GNUNET_MQ_destroy(ch->mq);
264 ch->mq = NULL; 261 ch->mq = NULL;
265 } 262 }
266 if (NULL != ch->task) 263 if (NULL != ch->task)
267 { 264 {
268 GNUNET_SCHEDULER_cancel (ch->task); 265 GNUNET_SCHEDULER_cancel(ch->task);
269 ch->task = NULL; 266 ch->task = NULL;
270 } 267 }
271 GNUNET_CONTAINER_multipeermap_iterate (ch->sug_requests, 268 GNUNET_CONTAINER_multipeermap_iterate(ch->sug_requests,
272 &free_sug_handle, 269 &free_sug_handle,
273 NULL); 270 NULL);
274 GNUNET_CONTAINER_multipeermap_destroy (ch->sug_requests); 271 GNUNET_CONTAINER_multipeermap_destroy(ch->sug_requests);
275 GNUNET_free (ch); 272 GNUNET_free(ch);
276} 273}
277 274
278 275
@@ -287,7 +284,7 @@ GNUNET_TRANSPORT_application_done (
287 * @return suggest handle, NULL if a request is already pending 284 * @return suggest handle, NULL if a request is already pending
288 */ 285 */
289struct GNUNET_TRANSPORT_ApplicationSuggestHandle * 286struct GNUNET_TRANSPORT_ApplicationSuggestHandle *
290GNUNET_TRANSPORT_application_suggest ( 287GNUNET_TRANSPORT_application_suggest(
291 struct GNUNET_TRANSPORT_ApplicationHandle *ch, 288 struct GNUNET_TRANSPORT_ApplicationHandle *ch,
292 const struct GNUNET_PeerIdentity *peer, 289 const struct GNUNET_PeerIdentity *peer,
293 enum GNUNET_MQ_PriorityPreferences pk, 290 enum GNUNET_MQ_PriorityPreferences pk,
@@ -295,22 +292,22 @@ GNUNET_TRANSPORT_application_suggest (
295{ 292{
296 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s; 293 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *s;
297 294
298 s = GNUNET_new (struct GNUNET_TRANSPORT_ApplicationSuggestHandle); 295 s = GNUNET_new(struct GNUNET_TRANSPORT_ApplicationSuggestHandle);
299 s->ch = ch; 296 s->ch = ch;
300 s->id = *peer; 297 s->id = *peer;
301 s->pk = pk; 298 s->pk = pk;
302 s->bw = bw; 299 s->bw = bw;
303 (void) GNUNET_CONTAINER_multipeermap_put ( 300 (void)GNUNET_CONTAINER_multipeermap_put(
304 ch->sug_requests, 301 ch->sug_requests,
305 &s->id, 302 &s->id,
306 s, 303 s,
307 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 304 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
308 LOG (GNUNET_ERROR_TYPE_DEBUG, 305 LOG(GNUNET_ERROR_TYPE_DEBUG,
309 "Requesting TRANSPORT to suggest address for `%s'\n", 306 "Requesting TRANSPORT to suggest address for `%s'\n",
310 GNUNET_i2s (peer)); 307 GNUNET_i2s(peer));
311 if (NULL == ch->mq) 308 if (NULL == ch->mq)
312 return s; 309 return s;
313 GNUNET_assert (GNUNET_OK == transmit_suggestion (ch, &s->id, s)); 310 GNUNET_assert(GNUNET_OK == transmit_suggestion(ch, &s->id, s));
314 return s; 311 return s;
315} 312}
316 313
@@ -321,30 +318,30 @@ GNUNET_TRANSPORT_application_suggest (
321 * @param sh handle to stop 318 * @param sh handle to stop
322 */ 319 */
323void 320void
324GNUNET_TRANSPORT_application_suggest_cancel ( 321GNUNET_TRANSPORT_application_suggest_cancel(
325 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh) 322 struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
326{ 323{
327 struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch; 324 struct GNUNET_TRANSPORT_ApplicationHandle *ch = sh->ch;
328 struct GNUNET_MQ_Envelope *ev; 325 struct GNUNET_MQ_Envelope *ev;
329 struct ExpressPreferenceMessage *m; 326 struct ExpressPreferenceMessage *m;
330 327
331 LOG (GNUNET_ERROR_TYPE_DEBUG, 328 LOG(GNUNET_ERROR_TYPE_DEBUG,
332 "Telling TRANSPORT we no longer care for an address for `%s'\n", 329 "Telling TRANSPORT we no longer care for an address for `%s'\n",
333 GNUNET_i2s (&sh->id)); 330 GNUNET_i2s(&sh->id));
334 GNUNET_assert ( 331 GNUNET_assert(
335 GNUNET_OK == 332 GNUNET_OK ==
336 GNUNET_CONTAINER_multipeermap_remove (ch->sug_requests, &sh->id, sh)); 333 GNUNET_CONTAINER_multipeermap_remove(ch->sug_requests, &sh->id, sh));
337 if (NULL == ch->mq) 334 if (NULL == ch->mq)
338 { 335 {
339 GNUNET_free (sh); 336 GNUNET_free(sh);
340 return; 337 return;
341 } 338 }
342 ev = GNUNET_MQ_msg (m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL); 339 ev = GNUNET_MQ_msg(m, GNUNET_MESSAGE_TYPE_TRANSPORT_SUGGEST_CANCEL);
343 m->pk = htonl ((uint32_t) sh->pk); 340 m->pk = htonl((uint32_t)sh->pk);
344 m->bw = sh->bw; 341 m->bw = sh->bw;
345 m->peer = sh->id; 342 m->peer = sh->id;
346 GNUNET_MQ_send (ch->mq, ev); 343 GNUNET_MQ_send(ch->mq, ev);
347 GNUNET_free (sh); 344 GNUNET_free(sh);
348} 345}
349 346
350 347
@@ -364,7 +361,7 @@ GNUNET_TRANSPORT_application_suggest_cancel (
364 * @param addr address to validate 361 * @param addr address to validate
365 */ 362 */
366void 363void
367GNUNET_TRANSPORT_application_validate ( 364GNUNET_TRANSPORT_application_validate(
368 struct GNUNET_TRANSPORT_ApplicationHandle *ch, 365 struct GNUNET_TRANSPORT_ApplicationHandle *ch,
369 const struct GNUNET_PeerIdentity *peer, 366 const struct GNUNET_PeerIdentity *peer,
370 enum GNUNET_NetworkType nt, 367 enum GNUNET_NetworkType nt,
@@ -375,23 +372,23 @@ GNUNET_TRANSPORT_application_validate (
375 size_t alen; 372 size_t alen;
376 373
377 if (NULL == ch->mq) 374 if (NULL == ch->mq)
378 { 375 {
379 GNUNET_log ( 376 GNUNET_log(
380 GNUNET_ERROR_TYPE_WARNING, 377 GNUNET_ERROR_TYPE_WARNING,
381 "Address validation for %s:%s skipped as transport is not connected\n", 378 "Address validation for %s:%s skipped as transport is not connected\n",
382 GNUNET_i2s (peer), 379 GNUNET_i2s(peer),
383 addr); 380 addr);
384 return; 381 return;
385 } 382 }
386 alen = strlen (addr) + 1; 383 alen = strlen(addr) + 1;
387 ev = 384 ev =
388 GNUNET_MQ_msg_extra (m, 385 GNUNET_MQ_msg_extra(m,
389 alen, 386 alen,
390 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION); 387 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_HELLO_VALIDATION);
391 m->peer = *peer; 388 m->peer = *peer;
392 m->nt = htonl ((uint32_t) nt); 389 m->nt = htonl((uint32_t)nt);
393 memcpy (&m[1], addr, alen); 390 memcpy(&m[1], addr, alen);
394 GNUNET_MQ_send (ch->mq, ev); 391 GNUNET_MQ_send(ch->mq, ev);
395} 392}
396 393
397 394
diff --git a/src/transport/transport_api2_communication.c b/src/transport/transport_api2_communication.c
index 8bc18845b..f9c387a87 100644
--- a/src/transport/transport_api2_communication.c
+++ b/src/transport/transport_api2_communication.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api2_communication.c 22 * @file transport/transport_api2_communication.c
@@ -42,8 +42,7 @@
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{
47 /** 46 /**
48 * Kept in a DLL. 47 * Kept in a DLL.
49 */ 48 */
@@ -80,8 +79,7 @@ struct FlowControl
80 * Information we track per message to tell the transport about 79 * Information we track per message to tell the transport about
81 * success or failures. 80 * success or failures.
82 */ 81 */
83struct AckPending 82struct AckPending {
84{
85 /** 83 /**
86 * Kept in a DLL. 84 * Kept in a DLL.
87 */ 85 */
@@ -112,8 +110,7 @@ struct AckPending
112/** 110/**
113 * Opaque handle to the transport service for communicators. 111 * Opaque handle to the transport service for communicators.
114 */ 112 */
115struct GNUNET_TRANSPORT_CommunicatorHandle 113struct GNUNET_TRANSPORT_CommunicatorHandle {
116{
117 /** 114 /**
118 * Head of DLL of addresses this communicator offers to the transport service. 115 * Head of DLL of addresses this communicator offers to the transport service.
119 */ 116 */
@@ -229,9 +226,7 @@ struct GNUNET_TRANSPORT_CommunicatorHandle
229 * Handle returned to identify the internal data structure the transport 226 * Handle returned to identify the internal data structure the transport
230 * API has created to manage a message queue to a particular peer. 227 * API has created to manage a message queue to a particular peer.
231 */ 228 */
232struct GNUNET_TRANSPORT_QueueHandle 229struct GNUNET_TRANSPORT_QueueHandle {
233{
234
235 /** 230 /**
236 * Kept in a DLL. 231 * Kept in a DLL.
237 */ 232 */
@@ -288,9 +283,7 @@ struct GNUNET_TRANSPORT_QueueHandle
288 * Internal representation of an address a communicator is 283 * Internal representation of an address a communicator is
289 * currently providing for the transport service. 284 * currently providing for the transport service.
290 */ 285 */
291struct GNUNET_TRANSPORT_AddressIdentifier 286struct GNUNET_TRANSPORT_AddressIdentifier {
292{
293
294 /** 287 /**
295 * Kept in a DLL. 288 * Kept in a DLL.
296 */ 289 */
@@ -336,7 +329,7 @@ struct GNUNET_TRANSPORT_AddressIdentifier
336 * @param ch handle to reconnect 329 * @param ch handle to reconnect
337 */ 330 */
338static void 331static void
339reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch); 332reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
340 333
341 334
342/** 335/**
@@ -346,20 +339,20 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
346 * @param ai address to add 339 * @param ai address to add
347 */ 340 */
348static void 341static void
349send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai) 342send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
350{ 343{
351 struct GNUNET_MQ_Envelope *env; 344 struct GNUNET_MQ_Envelope *env;
352 struct GNUNET_TRANSPORT_AddAddressMessage *aam; 345 struct GNUNET_TRANSPORT_AddAddressMessage *aam;
353 346
354 if (NULL == ai->ch->mq) 347 if (NULL == ai->ch->mq)
355 return; 348 return;
356 env = GNUNET_MQ_msg_extra (aam, 349 env = GNUNET_MQ_msg_extra(aam,
357 strlen (ai->address) + 1, 350 strlen(ai->address) + 1,
358 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS); 351 GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS);
359 aam->expiration = GNUNET_TIME_relative_hton (ai->expiration); 352 aam->expiration = GNUNET_TIME_relative_hton(ai->expiration);
360 aam->nt = htonl ((uint32_t) ai->nt); 353 aam->nt = htonl((uint32_t)ai->nt);
361 memcpy (&aam[1], ai->address, strlen (ai->address) + 1); 354 memcpy(&aam[1], ai->address, strlen(ai->address) + 1);
362 GNUNET_MQ_send (ai->ch->mq, env); 355 GNUNET_MQ_send(ai->ch->mq, env);
363} 356}
364 357
365 358
@@ -370,16 +363,16 @@ send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
370 * @param ai address to delete 363 * @param ai address to delete
371 */ 364 */
372static void 365static void
373send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai) 366send_del_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
374{ 367{
375 struct GNUNET_MQ_Envelope *env; 368 struct GNUNET_MQ_Envelope *env;
376 struct GNUNET_TRANSPORT_DelAddressMessage *dam; 369 struct GNUNET_TRANSPORT_DelAddressMessage *dam;
377 370
378 if (NULL == ai->ch->mq) 371 if (NULL == ai->ch->mq)
379 return; 372 return;
380 env = GNUNET_MQ_msg (dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS); 373 env = GNUNET_MQ_msg(dam, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS);
381 dam->aid = htonl (ai->aid); 374 dam->aid = htonl(ai->aid);
382 GNUNET_MQ_send (ai->ch->mq, env); 375 GNUNET_MQ_send(ai->ch->mq, env);
383} 376}
384 377
385 378
@@ -390,23 +383,23 @@ send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
390 * @param qh queue to add 383 * @param qh queue to add
391 */ 384 */
392static void 385static void
393send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) 386send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
394{ 387{
395 struct GNUNET_MQ_Envelope *env; 388 struct GNUNET_MQ_Envelope *env;
396 struct GNUNET_TRANSPORT_AddQueueMessage *aqm; 389 struct GNUNET_TRANSPORT_AddQueueMessage *aqm;
397 390
398 if (NULL == qh->ch->mq) 391 if (NULL == qh->ch->mq)
399 return; 392 return;
400 env = GNUNET_MQ_msg_extra (aqm, 393 env = GNUNET_MQ_msg_extra(aqm,
401 strlen (qh->address) + 1, 394 strlen(qh->address) + 1,
402 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP); 395 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP);
403 aqm->qid = htonl (qh->queue_id); 396 aqm->qid = htonl(qh->queue_id);
404 aqm->receiver = qh->peer; 397 aqm->receiver = qh->peer;
405 aqm->nt = htonl ((uint32_t) qh->nt); 398 aqm->nt = htonl((uint32_t)qh->nt);
406 aqm->mtu = htonl (qh->mtu); 399 aqm->mtu = htonl(qh->mtu);
407 aqm->cs = htonl ((uint32_t) qh->cs); 400 aqm->cs = htonl((uint32_t)qh->cs);
408 memcpy (&aqm[1], qh->address, strlen (qh->address) + 1); 401 memcpy(&aqm[1], qh->address, strlen(qh->address) + 1);
409 GNUNET_MQ_send (qh->ch->mq, env); 402 GNUNET_MQ_send(qh->ch->mq, env);
410} 403}
411 404
412 405
@@ -417,17 +410,17 @@ send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
417 * @param qh queue to delete 410 * @param qh queue to delete
418 */ 411 */
419static void 412static void
420send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh) 413send_del_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
421{ 414{
422 struct GNUNET_MQ_Envelope *env; 415 struct GNUNET_MQ_Envelope *env;
423 struct GNUNET_TRANSPORT_DelQueueMessage *dqm; 416 struct GNUNET_TRANSPORT_DelQueueMessage *dqm;
424 417
425 if (NULL == qh->ch->mq) 418 if (NULL == qh->ch->mq)
426 return; 419 return;
427 env = GNUNET_MQ_msg (dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN); 420 env = GNUNET_MQ_msg(dqm, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN);
428 dqm->qid = htonl (qh->queue_id); 421 dqm->qid = htonl(qh->queue_id);
429 dqm->receiver = qh->peer; 422 dqm->receiver = qh->peer;
430 GNUNET_MQ_send (qh->ch->mq, env); 423 GNUNET_MQ_send(qh->ch->mq, env);
431} 424}
432 425
433 426
@@ -440,27 +433,27 @@ send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
440 * @param ch service to disconnect from 433 * @param ch service to disconnect from
441 */ 434 */
442static void 435static void
443disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 436disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
444{ 437{
445 struct FlowControl *fcn; 438 struct FlowControl *fcn;
446 struct AckPending *apn; 439 struct AckPending *apn;
447 440
448 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn) 441 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn)
449 { 442 {
450 fcn = fc->next; 443 fcn = fc->next;
451 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc); 444 GNUNET_CONTAINER_DLL_remove(ch->fc_head, ch->fc_tail, fc);
452 fc->cb (fc->cb_cls, GNUNET_SYSERR); 445 fc->cb(fc->cb_cls, GNUNET_SYSERR);
453 GNUNET_free (fc); 446 GNUNET_free(fc);
454 } 447 }
455 for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn) 448 for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn)
456 { 449 {
457 apn = ap->next; 450 apn = ap->next;
458 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap); 451 GNUNET_CONTAINER_DLL_remove(ch->ap_head, ch->ap_tail, ap);
459 GNUNET_free (ap); 452 GNUNET_free(ap);
460 } 453 }
461 if (NULL == ch->mq) 454 if (NULL == ch->mq)
462 return; 455 return;
463 GNUNET_MQ_destroy (ch->mq); 456 GNUNET_MQ_destroy(ch->mq);
464 ch->mq = NULL; 457 ch->mq = NULL;
465} 458}
466 459
@@ -469,16 +462,16 @@ disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
469 * Function called on MQ errors. 462 * Function called on MQ errors.
470 */ 463 */
471static void 464static void
472error_handler (void *cls, enum GNUNET_MQ_Error error) 465error_handler(void *cls, enum GNUNET_MQ_Error error)
473{ 466{
474 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 467 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
475 468
476 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 469 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
477 "MQ failure %d, reconnecting to transport service.\n", 470 "MQ failure %d, reconnecting to transport service.\n",
478 error); 471 error);
479 disconnect (ch); 472 disconnect(ch);
480 /* TODO: maybe do this with exponential backoff/delay */ 473 /* TODO: maybe do this with exponential backoff/delay */
481 reconnect (ch); 474 reconnect(ch);
482} 475}
483 476
484 477
@@ -490,29 +483,29 @@ error_handler (void *cls, enum GNUNET_MQ_Error error)
490 * @param incoming_ack the ack 483 * @param incoming_ack the ack
491 */ 484 */
492static void 485static void
493handle_incoming_ack ( 486handle_incoming_ack(
494 void *cls, 487 void *cls,
495 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack) 488 const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
496{ 489{
497 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 490 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
498 491
499 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next) 492 for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next)
500 {
501 if ((fc->id == incoming_ack->fc_id) &&
502 (0 == memcmp (&fc->sender,
503 &incoming_ack->sender,
504 sizeof (struct GNUNET_PeerIdentity))))
505 { 493 {
506 GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc); 494 if ((fc->id == incoming_ack->fc_id) &&
507 fc->cb (fc->cb_cls, GNUNET_OK); 495 (0 == memcmp(&fc->sender,
508 GNUNET_free (fc); 496 &incoming_ack->sender,
509 return; 497 sizeof(struct GNUNET_PeerIdentity))))
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 }
510 } 504 }
511 } 505 GNUNET_break(0);
512 GNUNET_break (0); 506 disconnect(ch);
513 disconnect (ch);
514 /* TODO: maybe do this with exponential backoff/delay */ 507 /* TODO: maybe do this with exponential backoff/delay */
515 reconnect (ch); 508 reconnect(ch);
516} 509}
517 510
518 511
@@ -525,10 +518,10 @@ handle_incoming_ack (
525 * @return #GNUNET_OK if @a smt is well-formed 518 * @return #GNUNET_OK if @a smt is well-formed
526 */ 519 */
527static int 520static int
528check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) 521check_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
529{ 522{
530 (void) cls; 523 (void)cls;
531 GNUNET_MQ_check_zero_termination (cq); 524 GNUNET_MQ_check_zero_termination(cq);
532 return GNUNET_OK; 525 return GNUNET_OK;
533} 526}
534 527
@@ -540,26 +533,26 @@ check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
540 * @param cq the queue creation request 533 * @param cq the queue creation request
541 */ 534 */
542static void 535static void
543handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq) 536handle_create_queue(void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
544{ 537{
545 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 538 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
546 const char *addr = (const char *) &cq[1]; 539 const char *addr = (const char *)&cq[1];
547 struct GNUNET_TRANSPORT_CreateQueueResponse *cqr; 540 struct GNUNET_TRANSPORT_CreateQueueResponse *cqr;
548 struct GNUNET_MQ_Envelope *env; 541 struct GNUNET_MQ_Envelope *env;
549 542
550 if (GNUNET_OK != ch->mq_init (ch->mq_init_cls, &cq->receiver, addr)) 543 if (GNUNET_OK != ch->mq_init(ch->mq_init_cls, &cq->receiver, addr))
551 { 544 {
552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 545 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
553 "Address `%s' invalid for this communicator\n", 546 "Address `%s' invalid for this communicator\n",
554 addr); 547 addr);
555 env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL); 548 env = GNUNET_MQ_msg(cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL);
556 } 549 }
557 else 550 else
558 { 551 {
559 env = GNUNET_MQ_msg (cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK); 552 env = GNUNET_MQ_msg(cqr, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK);
560 } 553 }
561 cqr->request_id = cq->request_id; 554 cqr->request_id = cq->request_id;
562 GNUNET_MQ_send (ch->mq, env); 555 GNUNET_MQ_send(ch->mq, env);
563} 556}
564 557
565 558
@@ -572,10 +565,10 @@ handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
572 * @return #GNUNET_OK if @a smt is well-formed 565 * @return #GNUNET_OK if @a smt is well-formed
573 */ 566 */
574static int 567static int
575check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) 568check_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
576{ 569{
577 (void) cls; 570 (void)cls;
578 GNUNET_MQ_check_boxed_message (smt); 571 GNUNET_MQ_check_boxed_message(smt);
579 return GNUNET_OK; 572 return GNUNET_OK;
580} 573}
581 574
@@ -590,19 +583,19 @@ check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
590 * @param mid message that the ack is about 583 * @param mid message that the ack is about
591 */ 584 */
592static void 585static void
593send_ack (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 586send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
594 int status, 587 int status,
595 const struct GNUNET_PeerIdentity *receiver, 588 const struct GNUNET_PeerIdentity *receiver,
596 uint64_t mid) 589 uint64_t mid)
597{ 590{
598 struct GNUNET_MQ_Envelope *env; 591 struct GNUNET_MQ_Envelope *env;
599 struct GNUNET_TRANSPORT_SendMessageToAck *ack; 592 struct GNUNET_TRANSPORT_SendMessageToAck *ack;
600 593
601 env = GNUNET_MQ_msg (ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK); 594 env = GNUNET_MQ_msg(ack, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK);
602 ack->status = htonl (status); 595 ack->status = htonl(status);
603 ack->mid = mid; 596 ack->mid = mid;
604 ack->receiver = *receiver; 597 ack->receiver = *receiver;
605 GNUNET_MQ_send (ch->mq, env); 598 GNUNET_MQ_send(ch->mq, env);
606} 599}
607 600
608 601
@@ -613,14 +606,14 @@ send_ack (struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
613 * @param cls an `struct AckPending *` 606 * @param cls an `struct AckPending *`
614 */ 607 */
615static void 608static void
616send_ack_cb (void *cls) 609send_ack_cb(void *cls)
617{ 610{
618 struct AckPending *ap = cls; 611 struct AckPending *ap = cls;
619 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ap->ch; 612 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ap->ch;
620 613
621 GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap); 614 GNUNET_CONTAINER_DLL_remove(ch->ap_head, ch->ap_tail, ap);
622 send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid); 615 send_ack(ch, GNUNET_OK, &ap->receiver, ap->mid);
623 GNUNET_free (ap); 616 GNUNET_free(ap);
624} 617}
625 618
626 619
@@ -631,7 +624,7 @@ send_ack_cb (void *cls)
631 * @param smt the transmission request 624 * @param smt the transmission request
632 */ 625 */
633static void 626static void
634handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt) 627handle_send_msg(void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
635{ 628{
636 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 629 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
637 const struct GNUNET_MessageHeader *mh; 630 const struct GNUNET_MessageHeader *mh;
@@ -641,27 +634,27 @@ handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
641 634
642 for (qh = ch->queue_head; NULL != qh; qh = qh->next) 635 for (qh = ch->queue_head; NULL != qh; qh = qh->next)
643 if ((qh->queue_id == smt->qid) && 636 if ((qh->queue_id == smt->qid) &&
644 (0 == memcmp (&qh->peer, 637 (0 == memcmp(&qh->peer,
645 &smt->receiver, 638 &smt->receiver,
646 sizeof (struct GNUNET_PeerIdentity)))) 639 sizeof(struct GNUNET_PeerIdentity))))
647 break; 640 break;
648 if (NULL == qh) 641 if (NULL == qh)
649 { 642 {
650 /* queue is already gone, tell transport this one failed */ 643 /* queue is already gone, tell transport this one failed */
651 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 644 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
652 "Transmission failed, queue no longer exists.\n"); 645 "Transmission failed, queue no longer exists.\n");
653 send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid); 646 send_ack(ch, GNUNET_NO, &smt->receiver, smt->mid);
654 return; 647 return;
655 } 648 }
656 ap = GNUNET_new (struct AckPending); 649 ap = GNUNET_new(struct AckPending);
657 ap->ch = ch; 650 ap->ch = ch;
658 ap->receiver = smt->receiver; 651 ap->receiver = smt->receiver;
659 ap->mid = smt->mid; 652 ap->mid = smt->mid;
660 GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap); 653 GNUNET_CONTAINER_DLL_insert(ch->ap_head, ch->ap_tail, ap);
661 mh = (const struct GNUNET_MessageHeader *) &smt[1]; 654 mh = (const struct GNUNET_MessageHeader *)&smt[1];
662 env = GNUNET_MQ_msg_copy (mh); 655 env = GNUNET_MQ_msg_copy(mh);
663 GNUNET_MQ_notify_sent (env, &send_ack_cb, ap); 656 GNUNET_MQ_notify_sent(env, &send_ack_cb, ap);
664 GNUNET_MQ_send (qh->mq, env); 657 GNUNET_MQ_send(qh->mq, env);
665} 658}
666 659
667 660
@@ -674,12 +667,12 @@ handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
674 * @return #GNUNET_OK if @a smt is well-formed 667 * @return #GNUNET_OK if @a smt is well-formed
675 */ 668 */
676static int 669static int
677check_backchannel_incoming ( 670check_backchannel_incoming(
678 void *cls, 671 void *cls,
679 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) 672 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
680{ 673{
681 (void) cls; 674 (void)cls;
682 GNUNET_MQ_check_boxed_message (bi); 675 GNUNET_MQ_check_boxed_message(bi);
683 return GNUNET_OK; 676 return GNUNET_OK;
684} 677}
685 678
@@ -691,20 +684,20 @@ check_backchannel_incoming (
691 * @param bi the backchannel message 684 * @param bi the backchannel message
692 */ 685 */
693static void 686static void
694handle_backchannel_incoming ( 687handle_backchannel_incoming(
695 void *cls, 688 void *cls,
696 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi) 689 const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
697{ 690{
698 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls; 691 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = cls;
699 692
700 if (NULL != ch->notify_cb) 693 if (NULL != ch->notify_cb)
701 ch->notify_cb (ch->notify_cb_cls, 694 ch->notify_cb(ch->notify_cb_cls,
702 &bi->pid, 695 &bi->pid,
703 (const struct GNUNET_MessageHeader *) &bi[1]); 696 (const struct GNUNET_MessageHeader *)&bi[1]);
704 else 697 else
705 GNUNET_log ( 698 GNUNET_log(
706 GNUNET_ERROR_TYPE_INFO, 699 GNUNET_ERROR_TYPE_INFO,
707 _ ("Dropped backchanel message: handler not provided by communicator\n")); 700 _("Dropped backchanel message: handler not provided by communicator\n"));
708} 701}
709 702
710 703
@@ -714,46 +707,46 @@ handle_backchannel_incoming (
714 * @param ch handle to reconnect 707 * @param ch handle to reconnect
715 */ 708 */
716static void 709static void
717reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 710reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
718{ 711{
719 struct GNUNET_MQ_MessageHandler handlers[] = 712 struct GNUNET_MQ_MessageHandler handlers[] =
720 {GNUNET_MQ_hd_fixed_size (incoming_ack, 713 { GNUNET_MQ_hd_fixed_size(incoming_ack,
721 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, 714 GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK,
722 struct GNUNET_TRANSPORT_IncomingMessageAck, 715 struct GNUNET_TRANSPORT_IncomingMessageAck,
723 ch),
724 GNUNET_MQ_hd_var_size (create_queue,
725 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE,
726 struct GNUNET_TRANSPORT_CreateQueue,
727 ch),
728 GNUNET_MQ_hd_var_size (send_msg,
729 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG,
730 struct GNUNET_TRANSPORT_SendMessageTo,
731 ch), 716 ch),
732 GNUNET_MQ_hd_var_size ( 717 GNUNET_MQ_hd_var_size(create_queue,
733 backchannel_incoming, 718 GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE,
734 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING, 719 struct GNUNET_TRANSPORT_CreateQueue,
735 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming, 720 ch),
736 ch), 721 GNUNET_MQ_hd_var_size(send_msg,
737 GNUNET_MQ_handler_end ()}; 722 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG,
723 struct GNUNET_TRANSPORT_SendMessageTo,
724 ch),
725 GNUNET_MQ_hd_var_size(
726 backchannel_incoming,
727 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING,
728 struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming,
729 ch),
730 GNUNET_MQ_handler_end() };
738 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam; 731 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam;
739 struct GNUNET_MQ_Envelope *env; 732 struct GNUNET_MQ_Envelope *env;
740 733
741 ch->mq = 734 ch->mq =
742 GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch); 735 GNUNET_CLIENT_connect(ch->cfg, "transport", handlers, &error_handler, ch);
743 if (NULL == ch->mq) 736 if (NULL == ch->mq)
744 return; 737 return;
745 env = GNUNET_MQ_msg_extra (cam, 738 env = GNUNET_MQ_msg_extra(cam,
746 strlen (ch->addr_prefix) + 1, 739 strlen(ch->addr_prefix) + 1,
747 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR); 740 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR);
748 cam->cc = htonl ((uint32_t) ch->cc); 741 cam->cc = htonl((uint32_t)ch->cc);
749 memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1); 742 memcpy(&cam[1], ch->addr_prefix, strlen(ch->addr_prefix) + 1);
750 GNUNET_MQ_send (ch->mq, env); 743 GNUNET_MQ_send(ch->mq, env);
751 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai; 744 for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
752 ai = ai->next) 745 ai = ai->next)
753 send_add_address (ai); 746 send_add_address(ai);
754 for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh; 747 for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh;
755 qh = qh->next) 748 qh = qh->next)
756 send_add_queue (qh); 749 send_add_queue(qh);
757} 750}
758 751
759 752
@@ -776,7 +769,7 @@ reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
776 * @return NULL on error 769 * @return NULL on error
777 */ 770 */
778struct GNUNET_TRANSPORT_CommunicatorHandle * 771struct GNUNET_TRANSPORT_CommunicatorHandle *
779GNUNET_TRANSPORT_communicator_connect ( 772GNUNET_TRANSPORT_communicator_connect(
780 const struct GNUNET_CONFIGURATION_Handle *cfg, 773 const struct GNUNET_CONFIGURATION_Handle *cfg,
781 const char *config_section, 774 const char *config_section,
782 const char *addr_prefix, 775 const char *addr_prefix,
@@ -788,7 +781,7 @@ GNUNET_TRANSPORT_communicator_connect (
788{ 781{
789 struct GNUNET_TRANSPORT_CommunicatorHandle *ch; 782 struct GNUNET_TRANSPORT_CommunicatorHandle *ch;
790 783
791 ch = GNUNET_new (struct GNUNET_TRANSPORT_CommunicatorHandle); 784 ch = GNUNET_new(struct GNUNET_TRANSPORT_CommunicatorHandle);
792 ch->cfg = cfg; 785 ch->cfg = cfg;
793 ch->config_section = config_section; 786 ch->config_section = config_section;
794 ch->addr_prefix = addr_prefix; 787 ch->addr_prefix = addr_prefix;
@@ -797,18 +790,18 @@ GNUNET_TRANSPORT_communicator_connect (
797 ch->notify_cb = notify_cb; 790 ch->notify_cb = notify_cb;
798 ch->notify_cb_cls = notify_cb_cls; 791 ch->notify_cb_cls = notify_cb_cls;
799 ch->cc = cc; 792 ch->cc = cc;
800 reconnect (ch); 793 reconnect(ch);
801 if (GNUNET_OK != 794 if (GNUNET_OK !=
802 GNUNET_CONFIGURATION_get_value_number (cfg, 795 GNUNET_CONFIGURATION_get_value_number(cfg,
803 config_section, 796 config_section,
804 "MAX_QUEUE_LENGTH", 797 "MAX_QUEUE_LENGTH",
805 &ch->max_queue_length)) 798 &ch->max_queue_length))
806 ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 799 ch->max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
807 if (NULL == ch->mq) 800 if (NULL == ch->mq)
808 { 801 {
809 GNUNET_free (ch); 802 GNUNET_free(ch);
810 return NULL; 803 return NULL;
811 } 804 }
812 return ch; 805 return ch;
813} 806}
814 807
@@ -819,16 +812,16 @@ GNUNET_TRANSPORT_communicator_connect (
819 * @param ch handle returned from connect 812 * @param ch handle returned from connect
820 */ 813 */
821void 814void
822GNUNET_TRANSPORT_communicator_disconnect ( 815GNUNET_TRANSPORT_communicator_disconnect(
823 struct GNUNET_TRANSPORT_CommunicatorHandle *ch) 816 struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
824{ 817{
825 disconnect (ch); 818 disconnect(ch);
826 while (NULL != ch->ai_head) 819 while (NULL != ch->ai_head)
827 { 820 {
828 GNUNET_break (0); /* communicator forgot to remove address, warn! */ 821 GNUNET_break(0); /* communicator forgot to remove address, warn! */
829 GNUNET_TRANSPORT_communicator_address_remove (ch->ai_head); 822 GNUNET_TRANSPORT_communicator_address_remove(ch->ai_head);
830 } 823 }
831 GNUNET_free (ch); 824 GNUNET_free(ch);
832} 825}
833 826
834 827
@@ -856,7 +849,7 @@ GNUNET_TRANSPORT_communicator_disconnect (
856 * the tranport service is not yet up 849 * the tranport service is not yet up
857 */ 850 */
858int 851int
859GNUNET_TRANSPORT_communicator_receive ( 852GNUNET_TRANSPORT_communicator_receive(
860 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 853 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
861 const struct GNUNET_PeerIdentity *sender, 854 const struct GNUNET_PeerIdentity *sender,
862 const struct GNUNET_MessageHeader *msg, 855 const struct GNUNET_MessageHeader *msg,
@@ -870,41 +863,41 @@ GNUNET_TRANSPORT_communicator_receive (
870 863
871 if (NULL == ch->mq) 864 if (NULL == ch->mq)
872 return GNUNET_SYSERR; 865 return GNUNET_SYSERR;
873 if ((NULL == cb) && (GNUNET_MQ_get_length (ch->mq) >= ch->max_queue_length)) 866 if ((NULL == cb) && (GNUNET_MQ_get_length(ch->mq) >= ch->max_queue_length))
874 { 867 {
875 GNUNET_log ( 868 GNUNET_log(
876 GNUNET_ERROR_TYPE_WARNING, 869 GNUNET_ERROR_TYPE_WARNING,
877 "Dropping message: transprot is too slow, queue length %llu exceeded\n", 870 "Dropping message: transprot is too slow, queue length %llu exceeded\n",
878 ch->max_queue_length); 871 ch->max_queue_length);
879 return GNUNET_NO; 872 return GNUNET_NO;
880 } 873 }
881 874
882 msize = ntohs (msg->size); 875 msize = ntohs(msg->size);
883 env = 876 env =
884 GNUNET_MQ_msg_extra (im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG); 877 GNUNET_MQ_msg_extra(im, msize, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG);
885 if (NULL == env) 878 if (NULL == env)
886 { 879 {
887 GNUNET_break (0); 880 GNUNET_break(0);
888 return GNUNET_SYSERR; 881 return GNUNET_SYSERR;
889 } 882 }
890 im->expected_address_validity = 883 im->expected_address_validity =
891 GNUNET_TIME_relative_hton (expected_addr_validity); 884 GNUNET_TIME_relative_hton(expected_addr_validity);
892 im->sender = *sender; 885 im->sender = *sender;
893 memcpy (&im[1], msg, msize); 886 memcpy(&im[1], msg, msize);
894 if (NULL != cb) 887 if (NULL != cb)
895 { 888 {
896 struct FlowControl *fc; 889 struct FlowControl *fc;
897 890
898 im->fc_on = htonl (GNUNET_YES); 891 im->fc_on = htonl(GNUNET_YES);
899 im->fc_id = ch->fc_gen++; 892 im->fc_id = ch->fc_gen++;
900 fc = GNUNET_new (struct FlowControl); 893 fc = GNUNET_new(struct FlowControl);
901 fc->sender = *sender; 894 fc->sender = *sender;
902 fc->id = im->fc_id; 895 fc->id = im->fc_id;
903 fc->cb = cb; 896 fc->cb = cb;
904 fc->cb_cls = cb_cls; 897 fc->cb_cls = cb_cls;
905 GNUNET_CONTAINER_DLL_insert (ch->fc_head, ch->fc_tail, fc); 898 GNUNET_CONTAINER_DLL_insert(ch->fc_head, ch->fc_tail, fc);
906 } 899 }
907 GNUNET_MQ_send (ch->mq, env); 900 GNUNET_MQ_send(ch->mq, env);
908 return GNUNET_OK; 901 return GNUNET_OK;
909} 902}
910 903
@@ -929,7 +922,7 @@ GNUNET_TRANSPORT_communicator_receive (
929 * @return API handle identifying the new MQ 922 * @return API handle identifying the new MQ
930 */ 923 */
931struct GNUNET_TRANSPORT_QueueHandle * 924struct GNUNET_TRANSPORT_QueueHandle *
932GNUNET_TRANSPORT_communicator_mq_add ( 925GNUNET_TRANSPORT_communicator_mq_add(
933 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 926 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
934 const struct GNUNET_PeerIdentity *peer, 927 const struct GNUNET_PeerIdentity *peer,
935 const char *address, 928 const char *address,
@@ -940,17 +933,17 @@ GNUNET_TRANSPORT_communicator_mq_add (
940{ 933{
941 struct GNUNET_TRANSPORT_QueueHandle *qh; 934 struct GNUNET_TRANSPORT_QueueHandle *qh;
942 935
943 qh = GNUNET_new (struct GNUNET_TRANSPORT_QueueHandle); 936 qh = GNUNET_new(struct GNUNET_TRANSPORT_QueueHandle);
944 qh->ch = ch; 937 qh->ch = ch;
945 qh->peer = *peer; 938 qh->peer = *peer;
946 qh->address = GNUNET_strdup (address); 939 qh->address = GNUNET_strdup(address);
947 qh->nt = nt; 940 qh->nt = nt;
948 qh->mtu = mtu; 941 qh->mtu = mtu;
949 qh->cs = cs; 942 qh->cs = cs;
950 qh->mq = mq; 943 qh->mq = mq;
951 qh->queue_id = ch->queue_gen++; 944 qh->queue_id = ch->queue_gen++;
952 GNUNET_CONTAINER_DLL_insert (ch->queue_head, ch->queue_tail, qh); 945 GNUNET_CONTAINER_DLL_insert(ch->queue_head, ch->queue_tail, qh);
953 send_add_queue (qh); 946 send_add_queue(qh);
954 return qh; 947 return qh;
955} 948}
956 949
@@ -962,15 +955,15 @@ GNUNET_TRANSPORT_communicator_mq_add (
962 * @param qh handle for the queue that must be invalidated 955 * @param qh handle for the queue that must be invalidated
963 */ 956 */
964void 957void
965GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh) 958GNUNET_TRANSPORT_communicator_mq_del(struct GNUNET_TRANSPORT_QueueHandle *qh)
966{ 959{
967 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch; 960 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = qh->ch;
968 961
969 send_del_queue (qh); 962 send_del_queue(qh);
970 GNUNET_CONTAINER_DLL_remove (ch->queue_head, ch->queue_tail, qh); 963 GNUNET_CONTAINER_DLL_remove(ch->queue_head, ch->queue_tail, qh);
971 GNUNET_MQ_destroy (qh->mq); 964 GNUNET_MQ_destroy(qh->mq);
972 GNUNET_free (qh->address); 965 GNUNET_free(qh->address);
973 GNUNET_free (qh); 966 GNUNET_free(qh);
974} 967}
975 968
976 969
@@ -984,7 +977,7 @@ GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh)
984 * @param expiration when does the communicator forsee this address expiring? 977 * @param expiration when does the communicator forsee this address expiring?
985 */ 978 */
986struct GNUNET_TRANSPORT_AddressIdentifier * 979struct GNUNET_TRANSPORT_AddressIdentifier *
987GNUNET_TRANSPORT_communicator_address_add ( 980GNUNET_TRANSPORT_communicator_address_add(
988 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 981 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
989 const char *address, 982 const char *address,
990 enum GNUNET_NetworkType nt, 983 enum GNUNET_NetworkType nt,
@@ -992,14 +985,14 @@ GNUNET_TRANSPORT_communicator_address_add (
992{ 985{
993 struct GNUNET_TRANSPORT_AddressIdentifier *ai; 986 struct GNUNET_TRANSPORT_AddressIdentifier *ai;
994 987
995 ai = GNUNET_new (struct GNUNET_TRANSPORT_AddressIdentifier); 988 ai = GNUNET_new(struct GNUNET_TRANSPORT_AddressIdentifier);
996 ai->ch = ch; 989 ai->ch = ch;
997 ai->address = GNUNET_strdup (address); 990 ai->address = GNUNET_strdup(address);
998 ai->nt = nt; 991 ai->nt = nt;
999 ai->expiration = expiration; 992 ai->expiration = expiration;
1000 ai->aid = ch->aid_gen++; 993 ai->aid = ch->aid_gen++;
1001 GNUNET_CONTAINER_DLL_insert (ch->ai_head, ch->ai_tail, ai); 994 GNUNET_CONTAINER_DLL_insert(ch->ai_head, ch->ai_tail, ai);
1002 send_add_address (ai); 995 send_add_address(ai);
1003 return ai; 996 return ai;
1004} 997}
1005 998
@@ -1011,15 +1004,15 @@ GNUNET_TRANSPORT_communicator_address_add (
1011 * @param ai address that is no longer provided 1004 * @param ai address that is no longer provided
1012 */ 1005 */
1013void 1006void
1014GNUNET_TRANSPORT_communicator_address_remove ( 1007GNUNET_TRANSPORT_communicator_address_remove(
1015 struct GNUNET_TRANSPORT_AddressIdentifier *ai) 1008 struct GNUNET_TRANSPORT_AddressIdentifier *ai)
1016{ 1009{
1017 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ai->ch; 1010 struct GNUNET_TRANSPORT_CommunicatorHandle *ch = ai->ch;
1018 1011
1019 send_del_address (ai); 1012 send_del_address(ai);
1020 GNUNET_CONTAINER_DLL_remove (ch->ai_head, ch->ai_tail, ai); 1013 GNUNET_CONTAINER_DLL_remove(ch->ai_head, ch->ai_tail, ai);
1021 GNUNET_free (ai->address); 1014 GNUNET_free(ai->address);
1022 GNUNET_free (ai); 1015 GNUNET_free(ai);
1023} 1016}
1024 1017
1025 1018
@@ -1041,7 +1034,7 @@ GNUNET_TRANSPORT_communicator_address_remove (
1041 * notify-API to @a pid's communicator @a comm 1034 * notify-API to @a pid's communicator @a comm
1042 */ 1035 */
1043void 1036void
1044GNUNET_TRANSPORT_communicator_notify ( 1037GNUNET_TRANSPORT_communicator_notify(
1045 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 1038 struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
1046 const struct GNUNET_PeerIdentity *pid, 1039 const struct GNUNET_PeerIdentity *pid,
1047 const char *comm, 1040 const char *comm,
@@ -1049,18 +1042,18 @@ GNUNET_TRANSPORT_communicator_notify (
1049{ 1042{
1050 struct GNUNET_MQ_Envelope *env; 1043 struct GNUNET_MQ_Envelope *env;
1051 struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb; 1044 struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb;
1052 size_t slen = strlen (comm) + 1; 1045 size_t slen = strlen(comm) + 1;
1053 uint16_t mlen = ntohs (header->size); 1046 uint16_t mlen = ntohs(header->size);
1054 1047
1055 GNUNET_assert (mlen + slen + sizeof (*cb) < UINT16_MAX); 1048 GNUNET_assert(mlen + slen + sizeof(*cb) < UINT16_MAX);
1056 env = 1049 env =
1057 GNUNET_MQ_msg_extra (cb, 1050 GNUNET_MQ_msg_extra(cb,
1058 slen + mlen, 1051 slen + mlen,
1059 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL); 1052 GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL);
1060 cb->pid = *pid; 1053 cb->pid = *pid;
1061 memcpy (&cb[1], header, mlen); 1054 memcpy(&cb[1], header, mlen);
1062 memcpy (((char *) &cb[1]) + mlen, comm, slen); 1055 memcpy(((char *)&cb[1]) + mlen, comm, slen);
1063 GNUNET_MQ_send (ch->mq, env); 1056 GNUNET_MQ_send(ch->mq, env);
1064} 1057}
1065 1058
1066 1059
diff --git a/src/transport/transport_api2_core.c b/src/transport/transport_api2_core.c
index 20bbf2994..1d2d84bdf 100644
--- a/src/transport/transport_api2_core.c
+++ b/src/transport/transport_api2_core.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_core.c 22 * @file transport/transport_api_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,9 +53,7 @@
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{
58
59 /** 57 /**
60 * Identity of this neighbour. 58 * Identity of this neighbour.
61 */ 59 */
@@ -107,9 +105,7 @@ struct Neighbour
107 * Handle for the transport service (includes all of the 105 * Handle for the transport service (includes all of the
108 * state for the transport service). 106 * state for the transport service).
109 */ 107 */
110struct GNUNET_TRANSPORT_CoreHandle 108struct GNUNET_TRANSPORT_CoreHandle {
111{
112
113 /** 109 /**
114 * Closure for the callbacks. 110 * Closure for the callbacks.
115 */ 111 */
@@ -177,7 +173,7 @@ struct GNUNET_TRANSPORT_CoreHandle
177 * @param h transport service to reconnect 173 * @param h transport service to reconnect
178 */ 174 */
179static void 175static void
180disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); 176disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h);
181 177
182 178
183/** 179/**
@@ -188,10 +184,10 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h);
188 * @return NULL if no such peer entry exists 184 * @return NULL if no such peer entry exists
189 */ 185 */
190static struct Neighbour * 186static struct Neighbour *
191neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, 187neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h,
192 const struct GNUNET_PeerIdentity *peer) 188 const struct GNUNET_PeerIdentity *peer)
193{ 189{
194 return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); 190 return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer);
195} 191}
196 192
197 193
@@ -206,27 +202,27 @@ neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h,
206 * #GNUNET_NO if not. 202 * #GNUNET_NO if not.
207 */ 203 */
208static int 204static int
209neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 205neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
210{ 206{
211 struct GNUNET_TRANSPORT_CoreHandle *handle = cls; 207 struct GNUNET_TRANSPORT_CoreHandle *handle = cls;
212 struct Neighbour *n = value; 208 struct Neighbour *n = value;
213 209
214 LOG (GNUNET_ERROR_TYPE_DEBUG, 210 LOG(GNUNET_ERROR_TYPE_DEBUG,
215 "Dropping entry for neighbour `%s'.\n", 211 "Dropping entry for neighbour `%s'.\n",
216 GNUNET_i2s (key)); 212 GNUNET_i2s(key));
217 if (NULL != handle->nd_cb) 213 if (NULL != handle->nd_cb)
218 handle->nd_cb (handle->cls, &n->id, n->handlers_cls); 214 handle->nd_cb(handle->cls, &n->id, n->handlers_cls);
219 if (NULL != n->env) 215 if (NULL != n->env)
220 { 216 {
221 GNUNET_MQ_send_cancel (n->env); 217 GNUNET_MQ_send_cancel(n->env);
222 n->env = NULL; 218 n->env = NULL;
223 } 219 }
224 GNUNET_MQ_destroy (n->mq); 220 GNUNET_MQ_destroy(n->mq);
225 GNUNET_assert (NULL == n->mq); 221 GNUNET_assert(NULL == n->mq);
226 GNUNET_assert ( 222 GNUNET_assert(
227 GNUNET_YES == 223 GNUNET_YES ==
228 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); 224 GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n));
229 GNUNET_free (n); 225 GNUNET_free(n);
230 return GNUNET_YES; 226 return GNUNET_YES;
231} 227}
232 228
@@ -241,13 +237,13 @@ neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
241 * @param error error code 237 * @param error error code
242 */ 238 */
243static void 239static void
244mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 240mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
245{ 241{
246 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 242 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
247 243
248 LOG (GNUNET_ERROR_TYPE_DEBUG, 244 LOG(GNUNET_ERROR_TYPE_DEBUG,
249 "Error receiving from transport service, disconnecting temporarily.\n"); 245 "Error receiving from transport service, disconnecting temporarily.\n");
250 disconnect_and_schedule_reconnect (h); 246 disconnect_and_schedule_reconnect(h);
251} 247}
252 248
253 249
@@ -262,13 +258,13 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
262 * @param cls the `struct Neighbour` where the message was sent 258 * @param cls the `struct Neighbour` where the message was sent
263 */ 259 */
264static void 260static void
265notify_send_done (void *cls) 261notify_send_done(void *cls)
266{ 262{
267 struct Neighbour *n = cls; 263 struct Neighbour *n = cls;
268 264
269 n->awaiting_done = GNUNET_NO; 265 n->awaiting_done = GNUNET_NO;
270 n->env = NULL; 266 n->env = NULL;
271 GNUNET_MQ_impl_send_continue (n->mq); 267 GNUNET_MQ_impl_send_continue(n->mq);
272} 268}
273 269
274 270
@@ -279,18 +275,18 @@ notify_send_done (void *cls)
279 * @param n neighbour to perform transmission for 275 * @param n neighbour to perform transmission for
280 */ 276 */
281static void 277static void
282do_send (struct Neighbour *n) 278do_send(struct Neighbour *n)
283{ 279{
284 GNUNET_assert (0 < n->ready_window); 280 GNUNET_assert(0 < n->ready_window);
285 GNUNET_assert (NULL != n->env); 281 GNUNET_assert(NULL != n->env);
286 n->ready_window--; 282 n->ready_window--;
287 n->awaiting_done = GNUNET_YES; 283 n->awaiting_done = GNUNET_YES;
288 GNUNET_MQ_notify_sent (n->env, &notify_send_done, n); 284 GNUNET_MQ_notify_sent(n->env, &notify_send_done, n);
289 GNUNET_MQ_send (n->h->mq, n->env); 285 GNUNET_MQ_send(n->h->mq, n->env);
290 LOG (GNUNET_ERROR_TYPE_DEBUG, 286 LOG(GNUNET_ERROR_TYPE_DEBUG,
291 "Passed message of type %u for neighbour `%s' to TRANSPORT.\n", 287 "Passed message of type %u for neighbour `%s' to TRANSPORT.\n",
292 ntohs (GNUNET_MQ_env_get_msg (n->env)->type), 288 ntohs(GNUNET_MQ_env_get_msg(n->env)->type),
293 GNUNET_i2s (&n->id)); 289 GNUNET_i2s(&n->id));
294} 290}
295 291
296 292
@@ -305,44 +301,44 @@ do_send (struct Neighbour *n)
305 * @param impl_state state of the implementation 301 * @param impl_state state of the implementation
306 */ 302 */
307static void 303static void
308mq_send_impl (struct GNUNET_MQ_Handle *mq, 304mq_send_impl(struct GNUNET_MQ_Handle *mq,
309 const struct GNUNET_MessageHeader *msg, 305 const struct GNUNET_MessageHeader *msg,
310 void *impl_state) 306 void *impl_state)
311{ 307{
312 struct Neighbour *n = impl_state; 308 struct Neighbour *n = impl_state;
313 struct OutboundMessage *obm; 309 struct OutboundMessage *obm;
314 uint16_t msize; 310 uint16_t msize;
315 311
316 msize = ntohs (msg->size); 312 msize = ntohs(msg->size);
317 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm)) 313 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
318 { 314 {
319 GNUNET_break (0); 315 GNUNET_break(0);
320 GNUNET_MQ_impl_send_continue (mq); 316 GNUNET_MQ_impl_send_continue(mq);
321 return; 317 return;
322 } 318 }
323 LOG (GNUNET_ERROR_TYPE_DEBUG, 319 LOG(GNUNET_ERROR_TYPE_DEBUG,
324 "CORE requested transmission of message of type %u to neighbour `%s'.\n", 320 "CORE requested transmission of message of type %u to neighbour `%s'.\n",
325 ntohs (msg->type), 321 ntohs(msg->type),
326 GNUNET_i2s (&n->id)); 322 GNUNET_i2s(&n->id));
327 323
328 GNUNET_assert (NULL == n->env); 324 GNUNET_assert(NULL == n->env);
329 n->env = 325 n->env =
330 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); 326 GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
331 n->env_size = ntohs (msg->size); 327 n->env_size = ntohs(msg->size);
332 { 328 {
333 struct GNUNET_MQ_Envelope *env; 329 struct GNUNET_MQ_Envelope *env;
334 330
335 env = GNUNET_MQ_get_current_envelope (mq); 331 env = GNUNET_MQ_get_current_envelope(mq);
336 obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); 332 obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env));
337 } 333 }
338 obm->peer = n->id; 334 obm->peer = n->id;
339 if (0 == n->ready_window) 335 if (0 == n->ready_window)
340 { 336 {
341 LOG (GNUNET_ERROR_TYPE_DEBUG, 337 LOG(GNUNET_ERROR_TYPE_DEBUG,
342 "Flow control delays transmission to CORE until we see SEND_OK.\n"); 338 "Flow control delays transmission to CORE until we see SEND_OK.\n");
343 return; /* can't send yet, need to wait for SEND_OK */ 339 return; /* can't send yet, need to wait for SEND_OK */
344 } 340 }
345 do_send (n); 341 do_send(n);
346} 342}
347 343
348 344
@@ -354,11 +350,11 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
354 * @param impl_state state of the implementation 350 * @param impl_state state of the implementation
355 */ 351 */
356static void 352static void
357mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 353mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
358{ 354{
359 struct Neighbour *n = impl_state; 355 struct Neighbour *n = impl_state;
360 356
361 GNUNET_assert (mq == n->mq); 357 GNUNET_assert(mq == n->mq);
362 n->mq = NULL; 358 n->mq = NULL;
363} 359}
364 360
@@ -371,22 +367,22 @@ mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
371 * @param impl_state state specific to the implementation 367 * @param impl_state state specific to the implementation
372 */ 368 */
373static void 369static void
374mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 370mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
375{ 371{
376 struct Neighbour *n = impl_state; 372 struct Neighbour *n = impl_state;
377 373
378 n->ready_window++; 374 n->ready_window++;
379 if (GNUNET_YES == n->awaiting_done) 375 if (GNUNET_YES == n->awaiting_done)
380 { 376 {
381 GNUNET_MQ_send_cancel (n->env); 377 GNUNET_MQ_send_cancel(n->env);
382 n->env = NULL; 378 n->env = NULL;
383 n->awaiting_done = GNUNET_NO; 379 n->awaiting_done = GNUNET_NO;
384 } 380 }
385 else 381 else
386 { 382 {
387 GNUNET_assert (0 == n->ready_window); 383 GNUNET_assert(0 == n->ready_window);
388 n->env = NULL; 384 n->env = NULL;
389 } 385 }
390} 386}
391 387
392 388
@@ -399,11 +395,11 @@ mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
399 * @param error error code 395 * @param error error code
400 */ 396 */
401static void 397static void
402peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 398peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
403{ 399{
404 /* struct Neighbour *n = cls; */ 400 /* struct Neighbour *n = cls; */
405 401
406 GNUNET_break_op (0); 402 GNUNET_break_op(0);
407} 403}
408 404
409 405
@@ -414,44 +410,44 @@ peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
414 * @param cim message received 410 * @param cim message received
415 */ 411 */
416static void 412static void
417handle_connect (void *cls, const struct ConnectInfoMessage *cim) 413handle_connect(void *cls, const struct ConnectInfoMessage *cim)
418{ 414{
419 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 415 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
420 struct Neighbour *n; 416 struct Neighbour *n;
421 417
422 LOG (GNUNET_ERROR_TYPE_DEBUG, 418 LOG(GNUNET_ERROR_TYPE_DEBUG,
423 "Receiving CONNECT message for `%s'\n", 419 "Receiving CONNECT message for `%s'\n",
424 GNUNET_i2s (&cim->id)); 420 GNUNET_i2s(&cim->id));
425 n = neighbour_find (h, &cim->id); 421 n = neighbour_find(h, &cim->id);
426 if (NULL != n) 422 if (NULL != n)
427 { 423 {
428 GNUNET_break (0); 424 GNUNET_break(0);
429 disconnect_and_schedule_reconnect (h); 425 disconnect_and_schedule_reconnect(h);
430 return; 426 return;
431 } 427 }
432 n = GNUNET_new (struct Neighbour); 428 n = GNUNET_new(struct Neighbour);
433 n->id = cim->id; 429 n->id = cim->id;
434 n->h = h; 430 n->h = h;
435 n->ready_window = SEND_WINDOW_SIZE; 431 n->ready_window = SEND_WINDOW_SIZE;
436 GNUNET_assert (GNUNET_OK == 432 GNUNET_assert(GNUNET_OK ==
437 GNUNET_CONTAINER_multipeermap_put ( 433 GNUNET_CONTAINER_multipeermap_put(
438 h->neighbours, 434 h->neighbours,
439 &n->id, 435 &n->id,
440 n, 436 n,
441 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 437 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
442 438
443 n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, 439 n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl,
444 &mq_destroy_impl, 440 &mq_destroy_impl,
445 &mq_cancel_impl, 441 &mq_cancel_impl,
446 n, 442 n,
447 h->handlers, 443 h->handlers,
448 &peer_mq_error_handler, 444 &peer_mq_error_handler,
449 n); 445 n);
450 if (NULL != h->nc_cb) 446 if (NULL != h->nc_cb)
451 { 447 {
452 n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); 448 n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq);
453 GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); 449 GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls);
454 } 450 }
455} 451}
456 452
457 453
@@ -462,23 +458,23 @@ handle_connect (void *cls, const struct ConnectInfoMessage *cim)
462 * @param dim message received 458 * @param dim message received
463 */ 459 */
464static void 460static void
465handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) 461handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
466{ 462{
467 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 463 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
468 struct Neighbour *n; 464 struct Neighbour *n;
469 465
470 GNUNET_break (ntohl (dim->reserved) == 0); 466 GNUNET_break(ntohl(dim->reserved) == 0);
471 LOG (GNUNET_ERROR_TYPE_DEBUG, 467 LOG(GNUNET_ERROR_TYPE_DEBUG,
472 "Receiving DISCONNECT message for `%s'.\n", 468 "Receiving DISCONNECT message for `%s'.\n",
473 GNUNET_i2s (&dim->peer)); 469 GNUNET_i2s(&dim->peer));
474 n = neighbour_find (h, &dim->peer); 470 n = neighbour_find(h, &dim->peer);
475 if (NULL == n) 471 if (NULL == n)
476 { 472 {
477 GNUNET_break (0); 473 GNUNET_break(0);
478 disconnect_and_schedule_reconnect (h); 474 disconnect_and_schedule_reconnect(h);
479 return; 475 return;
480 } 476 }
481 GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); 477 GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n));
482} 478}
483 479
484 480
@@ -489,26 +485,26 @@ handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim)
489 * @param okm message received 485 * @param okm message received
490 */ 486 */
491static void 487static void
492handle_send_ok (void *cls, const struct SendOkMessage *okm) 488handle_send_ok(void *cls, const struct SendOkMessage *okm)
493{ 489{
494 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 490 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
495 struct Neighbour *n; 491 struct Neighbour *n;
496 492
497 LOG (GNUNET_ERROR_TYPE_DEBUG, 493 LOG(GNUNET_ERROR_TYPE_DEBUG,
498 "Receiving SEND_OK message for transmission to %s\n", 494 "Receiving SEND_OK message for transmission to %s\n",
499 GNUNET_i2s (&okm->peer)); 495 GNUNET_i2s(&okm->peer));
500 n = neighbour_find (h, &okm->peer); 496 n = neighbour_find(h, &okm->peer);
501 if (NULL == n) 497 if (NULL == n)
502 { 498 {
503 /* We should never get a 'SEND_OK' for a peer that we are not 499 /* We should never get a 'SEND_OK' for a peer that we are not
504 connected to */ 500 connected to */
505 GNUNET_break (0); 501 GNUNET_break(0);
506 disconnect_and_schedule_reconnect (h); 502 disconnect_and_schedule_reconnect(h);
507 return; 503 return;
508 } 504 }
509 n->ready_window++; 505 n->ready_window++;
510 if ((NULL != n->env) && (1 == n->ready_window)) 506 if ((NULL != n->env) && (1 == n->ready_window))
511 do_send (n); 507 do_send(n);
512} 508}
513 509
514 510
@@ -519,23 +515,23 @@ handle_send_ok (void *cls, const struct SendOkMessage *okm)
519 * @param im message received 515 * @param im message received
520 */ 516 */
521static int 517static int
522check_recv (void *cls, const struct InboundMessage *im) 518check_recv(void *cls, const struct InboundMessage *im)
523{ 519{
524 const struct GNUNET_MessageHeader *imm; 520 const struct GNUNET_MessageHeader *imm;
525 uint16_t size; 521 uint16_t size;
526 522
527 size = ntohs (im->header.size) - sizeof (*im); 523 size = ntohs(im->header.size) - sizeof(*im);
528 if (size < sizeof (struct GNUNET_MessageHeader)) 524 if (size < sizeof(struct GNUNET_MessageHeader))
529 { 525 {
530 GNUNET_break (0); 526 GNUNET_break(0);
531 return GNUNET_SYSERR; 527 return GNUNET_SYSERR;
532 } 528 }
533 imm = (const struct GNUNET_MessageHeader *) &im[1]; 529 imm = (const struct GNUNET_MessageHeader *)&im[1];
534 if (ntohs (imm->size) != size) 530 if (ntohs(imm->size) != size)
535 { 531 {
536 GNUNET_break (0); 532 GNUNET_break(0);
537 return GNUNET_SYSERR; 533 return GNUNET_SYSERR;
538 } 534 }
539 return GNUNET_OK; 535 return GNUNET_OK;
540} 536}
541 537
@@ -547,26 +543,26 @@ check_recv (void *cls, const struct InboundMessage *im)
547 * @param im message received 543 * @param im message received
548 */ 544 */
549static void 545static void
550handle_recv (void *cls, const struct InboundMessage *im) 546handle_recv(void *cls, const struct InboundMessage *im)
551{ 547{
552 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 548 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
553 const struct GNUNET_MessageHeader *imm = 549 const struct GNUNET_MessageHeader *imm =
554 (const struct GNUNET_MessageHeader *) &im[1]; 550 (const struct GNUNET_MessageHeader *)&im[1];
555 struct Neighbour *n; 551 struct Neighbour *n;
556 552
557 LOG (GNUNET_ERROR_TYPE_DEBUG, 553 LOG(GNUNET_ERROR_TYPE_DEBUG,
558 "Received message of type %u with %u bytes from `%s'.\n", 554 "Received message of type %u with %u bytes from `%s'.\n",
559 (unsigned int) ntohs (imm->type), 555 (unsigned int)ntohs(imm->type),
560 (unsigned int) ntohs (imm->size), 556 (unsigned int)ntohs(imm->size),
561 GNUNET_i2s (&im->peer)); 557 GNUNET_i2s(&im->peer));
562 n = neighbour_find (h, &im->peer); 558 n = neighbour_find(h, &im->peer);
563 if (NULL == n) 559 if (NULL == n)
564 { 560 {
565 GNUNET_break (0); 561 GNUNET_break(0);
566 disconnect_and_schedule_reconnect (h); 562 disconnect_and_schedule_reconnect(h);
567 return; 563 return;
568 } 564 }
569 GNUNET_MQ_inject_message (n->mq, imm); 565 GNUNET_MQ_inject_message(n->mq, imm);
570} 566}
571 567
572 568
@@ -576,47 +572,47 @@ handle_recv (void *cls, const struct InboundMessage *im)
576 * @param cls the handle to the transport service 572 * @param cls the handle to the transport service
577 */ 573 */
578static void 574static void
579reconnect (void *cls) 575reconnect(void *cls)
580{ 576{
581 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 577 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
582 struct GNUNET_MQ_MessageHandler handlers[] = 578 struct GNUNET_MQ_MessageHandler handlers[] =
583 {GNUNET_MQ_hd_fixed_size (connect, 579 { GNUNET_MQ_hd_fixed_size(connect,
584 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, 580 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT,
585 struct ConnectInfoMessage, 581 struct ConnectInfoMessage,
586 h), 582 h),
587 GNUNET_MQ_hd_fixed_size (disconnect, 583 GNUNET_MQ_hd_fixed_size(disconnect,
588 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, 584 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT,
589 struct DisconnectInfoMessage, 585 struct DisconnectInfoMessage,
590 h),
591 GNUNET_MQ_hd_fixed_size (send_ok,
592 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK,
593 struct SendOkMessage,
594 h),
595 GNUNET_MQ_hd_var_size (recv,
596 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV,
597 struct InboundMessage,
598 h), 586 h),
599 GNUNET_MQ_handler_end ()}; 587 GNUNET_MQ_hd_fixed_size(send_ok,
588 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK,
589 struct SendOkMessage,
590 h),
591 GNUNET_MQ_hd_var_size(recv,
592 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV,
593 struct InboundMessage,
594 h),
595 GNUNET_MQ_handler_end() };
600 struct GNUNET_MQ_Envelope *env; 596 struct GNUNET_MQ_Envelope *env;
601 struct StartMessage *s; 597 struct StartMessage *s;
602 uint32_t options; 598 uint32_t options;
603 599
604 h->reconnect_task = NULL; 600 h->reconnect_task = NULL;
605 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); 601 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
606 GNUNET_assert (NULL == h->mq); 602 GNUNET_assert(NULL == h->mq);
607 h->mq = 603 h->mq =
608 GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); 604 GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h);
609 if (NULL == h->mq) 605 if (NULL == h->mq)
610 return; 606 return;
611 env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); 607 env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START);
612 options = 0; 608 options = 0;
613 if (h->check_self) 609 if (h->check_self)
614 options |= 1; 610 options |= 1;
615 if (NULL != h->handlers) 611 if (NULL != h->handlers)
616 options |= 2; 612 options |= 2;
617 s->options = htonl (options); 613 s->options = htonl(options);
618 s->self = h->self; 614 s->self = h->self;
619 GNUNET_MQ_send (h->mq, env); 615 GNUNET_MQ_send(h->mq, env);
620} 616}
621 617
622 618
@@ -626,14 +622,14 @@ reconnect (void *cls)
626 * @param h transport service to reconnect 622 * @param h transport service to reconnect
627 */ 623 */
628static void 624static void
629disconnect (struct GNUNET_TRANSPORT_CoreHandle *h) 625disconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
630{ 626{
631 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); 627 GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h);
632 if (NULL != h->mq) 628 if (NULL != h->mq)
633 { 629 {
634 GNUNET_MQ_destroy (h->mq); 630 GNUNET_MQ_destroy(h->mq);
635 h->mq = NULL; 631 h->mq = NULL;
636 } 632 }
637} 633}
638 634
639 635
@@ -644,16 +640,16 @@ disconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
644 * @param h transport service to reconnect 640 * @param h transport service to reconnect
645 */ 641 */
646static void 642static void
647disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) 643disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
648{ 644{
649 GNUNET_assert (NULL == h->reconnect_task); 645 GNUNET_assert(NULL == h->reconnect_task);
650 disconnect (h); 646 disconnect(h);
651 LOG (GNUNET_ERROR_TYPE_DEBUG, 647 LOG(GNUNET_ERROR_TYPE_DEBUG,
652 "Scheduling task to reconnect to transport service in %s.\n", 648 "Scheduling task to reconnect to transport service in %s.\n",
653 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); 649 GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES));
654 h->reconnect_task = 650 h->reconnect_task =
655 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 651 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h);
656 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 652 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay);
657} 653}
658 654
659 655
@@ -665,12 +661,12 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
665 * @return NULL if disconnected, otherwise message queue for @a peer 661 * @return NULL if disconnected, otherwise message queue for @a peer
666 */ 662 */
667struct GNUNET_MQ_Handle * 663struct GNUNET_MQ_Handle *
668GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, 664GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle,
669 const struct GNUNET_PeerIdentity *peer) 665 const struct GNUNET_PeerIdentity *peer)
670{ 666{
671 struct Neighbour *n; 667 struct Neighbour *n;
672 668
673 n = neighbour_find (handle, peer); 669 n = neighbour_find(handle, peer);
674 if (NULL == n) 670 if (NULL == n)
675 return NULL; 671 return NULL;
676 return n->mq; 672 return n->mq;
@@ -698,21 +694,21 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
698 * @param pid which peer was the message from that was fully processed by CORE 694 * @param pid which peer was the message from that was fully processed by CORE
699 */ 695 */
700void 696void
701GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, 697GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch,
702 const struct GNUNET_PeerIdentity *pid) 698 const struct GNUNET_PeerIdentity *pid)
703{ 699{
704 struct GNUNET_MQ_Envelope *env; 700 struct GNUNET_MQ_Envelope *env;
705 struct RecvOkMessage *rok; 701 struct RecvOkMessage *rok;
706 702
707 LOG (GNUNET_ERROR_TYPE_DEBUG, 703 LOG(GNUNET_ERROR_TYPE_DEBUG,
708 "Message for %s finished CORE processing, sending RECV_OK.\n", 704 "Message for %s finished CORE processing, sending RECV_OK.\n",
709 GNUNET_i2s (pid)); 705 GNUNET_i2s(pid));
710 if (NULL == ch->mq) 706 if (NULL == ch->mq)
711 return; 707 return;
712 env = GNUNET_MQ_msg (rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); 708 env = GNUNET_MQ_msg(rok, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK);
713 rok->increase_window_delta = htonl (1); 709 rok->increase_window_delta = htonl(1);
714 rok->peer = *pid; 710 rok->peer = *pid;
715 GNUNET_MQ_send (ch->mq, env); 711 GNUNET_MQ_send(ch->mq, env);
716} 712}
717 713
718 714
@@ -730,46 +726,46 @@ GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
730 * @return NULL on error 726 * @return NULL on error
731 */ 727 */
732struct GNUNET_TRANSPORT_CoreHandle * 728struct GNUNET_TRANSPORT_CoreHandle *
733GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 729GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
734 const struct GNUNET_PeerIdentity *self, 730 const struct GNUNET_PeerIdentity *self,
735 const struct GNUNET_MQ_MessageHandler *handlers, 731 const struct GNUNET_MQ_MessageHandler *handlers,
736 void *cls, 732 void *cls,
737 GNUNET_TRANSPORT_NotifyConnect nc, 733 GNUNET_TRANSPORT_NotifyConnect nc,
738 GNUNET_TRANSPORT_NotifyDisconnect nd) 734 GNUNET_TRANSPORT_NotifyDisconnect nd)
739{ 735{
740 struct GNUNET_TRANSPORT_CoreHandle *h; 736 struct GNUNET_TRANSPORT_CoreHandle *h;
741 unsigned int i; 737 unsigned int i;
742 738
743 h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); 739 h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle);
744 if (NULL != self) 740 if (NULL != self)
745 { 741 {
746 h->self = *self; 742 h->self = *self;
747 h->check_self = GNUNET_YES; 743 h->check_self = GNUNET_YES;
748 } 744 }
749 h->cfg = cfg; 745 h->cfg = cfg;
750 h->cls = cls; 746 h->cls = cls;
751 h->nc_cb = nc; 747 h->nc_cb = nc;
752 h->nd_cb = nd; 748 h->nd_cb = nd;
753 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; 749 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
754 if (NULL != handlers) 750 if (NULL != handlers)
755 { 751 {
756 for (i = 0; NULL != handlers[i].cb; i++) 752 for (i = 0; NULL != handlers[i].cb; i++)
757 ; 753 ;
758 h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); 754 h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler);
759 GNUNET_memcpy (h->handlers, 755 GNUNET_memcpy(h->handlers,
760 handlers, 756 handlers,
761 i * sizeof (struct GNUNET_MQ_MessageHandler)); 757 i * sizeof(struct GNUNET_MQ_MessageHandler));
762 } 758 }
763 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); 759 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n");
764 reconnect (h); 760 reconnect(h);
765 if (NULL == h->mq) 761 if (NULL == h->mq)
766 { 762 {
767 GNUNET_free_non_null (h->handlers); 763 GNUNET_free_non_null(h->handlers);
768 GNUNET_free (h); 764 GNUNET_free(h);
769 return NULL; 765 return NULL;
770 } 766 }
771 h->neighbours = 767 h->neighbours =
772 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); 768 GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES);
773 return h; 769 return h;
774} 770}
775 771
@@ -781,22 +777,22 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
781 * #GNUNET_TRANSPORT_core_connect() 777 * #GNUNET_TRANSPORT_core_connect()
782 */ 778 */
783void 779void
784GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) 780GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
785{ 781{
786 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); 782 LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
787 /* this disconnects all neighbours... */ 783 /* this disconnects all neighbours... */
788 disconnect (handle); 784 disconnect(handle);
789 /* and now we stop trying to connect again... */ 785 /* and now we stop trying to connect again... */
790 if (NULL != handle->reconnect_task) 786 if (NULL != handle->reconnect_task)
791 { 787 {
792 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 788 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
793 handle->reconnect_task = NULL; 789 handle->reconnect_task = NULL;
794 } 790 }
795 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); 791 GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours);
796 handle->neighbours = NULL; 792 handle->neighbours = NULL;
797 GNUNET_free_non_null (handle->handlers); 793 GNUNET_free_non_null(handle->handlers);
798 handle->handlers = NULL; 794 handle->handlers = NULL;
799 GNUNET_free (handle); 795 GNUNET_free(handle);
800} 796}
801 797
802 798
diff --git a/src/transport/transport_api2_monitor.c b/src/transport/transport_api2_monitor.c
index 97812ff89..74624326c 100644
--- a/src/transport/transport_api2_monitor.c
+++ b/src/transport/transport_api2_monitor.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api2_monitor.c 22 * @file transport/transport_api2_monitor.c
@@ -33,8 +33,7 @@
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{
38 /** 37 /**
39 * Our configuration. 38 * Our configuration.
40 */ 39 */
@@ -73,7 +72,7 @@ struct GNUNET_TRANSPORT_MonitorContext
73 * @param mc handle to reconnect 72 * @param mc handle to reconnect
74 */ 73 */
75static void 74static void
76reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc); 75reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc);
77 76
78 77
79/** 78/**
@@ -83,17 +82,17 @@ reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc);
83 * @param ai address to delete 82 * @param ai address to delete
84 */ 83 */
85static void 84static void
86send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc) 85send_start_monitor(struct GNUNET_TRANSPORT_MonitorContext *mc)
87{ 86{
88 struct GNUNET_MQ_Envelope *env; 87 struct GNUNET_MQ_Envelope *env;
89 struct GNUNET_TRANSPORT_MonitorStart *smm; 88 struct GNUNET_TRANSPORT_MonitorStart *smm;
90 89
91 if (NULL == mc->mq) 90 if (NULL == mc->mq)
92 return; 91 return;
93 env = GNUNET_MQ_msg (smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START); 92 env = GNUNET_MQ_msg(smm, GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_START);
94 smm->one_shot = htonl ((uint32_t) mc->one_shot); 93 smm->one_shot = htonl((uint32_t)mc->one_shot);
95 smm->peer = mc->peer; 94 smm->peer = mc->peer;
96 GNUNET_MQ_send (mc->mq, env); 95 GNUNET_MQ_send(mc->mq, env);
97} 96}
98 97
99 98
@@ -103,11 +102,11 @@ send_start_monitor (struct GNUNET_TRANSPORT_MonitorContext *mc)
103 * @param mc service to disconnect from 102 * @param mc service to disconnect from
104 */ 103 */
105static void 104static void
106disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) 105disconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
107{ 106{
108 if (NULL == mc->mq) 107 if (NULL == mc->mq)
109 return; 108 return;
110 GNUNET_MQ_destroy (mc->mq); 109 GNUNET_MQ_destroy(mc->mq);
111 mc->mq = NULL; 110 mc->mq = NULL;
112} 111}
113 112
@@ -119,16 +118,16 @@ disconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
119 * @param error what error happened? 118 * @param error what error happened?
120 */ 119 */
121static void 120static void
122error_handler (void *cls, enum GNUNET_MQ_Error error) 121error_handler(void *cls, enum GNUNET_MQ_Error error)
123{ 122{
124 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 123 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
125 124
126 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 125 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
127 "MQ failure %d, reconnecting to transport service.\n", 126 "MQ failure %d, reconnecting to transport service.\n",
128 error); 127 error);
129 disconnect (mc); 128 disconnect(mc);
130 /* TODO: maybe do this with exponential backoff/delay */ 129 /* TODO: maybe do this with exponential backoff/delay */
131 reconnect (mc); 130 reconnect(mc);
132} 131}
133 132
134 133
@@ -141,10 +140,10 @@ error_handler (void *cls, enum GNUNET_MQ_Error error)
141 * @return #GNUNET_OK if @a smt is well-formed 140 * @return #GNUNET_OK if @a smt is well-formed
142 */ 141 */
143static int 142static int
144check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) 143check_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
145{ 144{
146 (void) cls; 145 (void)cls;
147 GNUNET_MQ_check_zero_termination (md); 146 GNUNET_MQ_check_zero_termination(md);
148 return GNUNET_OK; 147 return GNUNET_OK;
149} 148}
150 149
@@ -156,21 +155,21 @@ check_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
156 * @param md monitor data 155 * @param md monitor data
157 */ 156 */
158static void 157static void
159handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md) 158handle_monitor_data(void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
160{ 159{
161 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 160 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
162 struct GNUNET_TRANSPORT_MonitorInformation mi; 161 struct GNUNET_TRANSPORT_MonitorInformation mi;
163 162
164 mi.address = (const char *) &md[1]; 163 mi.address = (const char *)&md[1];
165 mi.nt = (enum GNUNET_NetworkType) ntohl (md->nt); 164 mi.nt = (enum GNUNET_NetworkType)ntohl(md->nt);
166 mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus) ntohl (md->cs); 165 mi.cs = (enum GNUNET_TRANSPORT_ConnectionStatus)ntohl(md->cs);
167 mi.num_msg_pending = ntohl (md->num_msg_pending); 166 mi.num_msg_pending = ntohl(md->num_msg_pending);
168 mi.num_bytes_pending = ntohl (md->num_bytes_pending); 167 mi.num_bytes_pending = ntohl(md->num_bytes_pending);
169 mi.last_validation = GNUNET_TIME_absolute_ntoh (md->last_validation); 168 mi.last_validation = GNUNET_TIME_absolute_ntoh(md->last_validation);
170 mi.valid_until = GNUNET_TIME_absolute_ntoh (md->valid_until); 169 mi.valid_until = GNUNET_TIME_absolute_ntoh(md->valid_until);
171 mi.next_validation = GNUNET_TIME_absolute_ntoh (md->next_validation); 170 mi.next_validation = GNUNET_TIME_absolute_ntoh(md->next_validation);
172 mi.rtt = GNUNET_TIME_relative_ntoh (md->rtt); 171 mi.rtt = GNUNET_TIME_relative_ntoh(md->rtt);
173 mc->cb (mc->cb_cls, &md->peer, &mi); 172 mc->cb(mc->cb_cls, &md->peer, &mi);
174} 173}
175 174
176 175
@@ -181,19 +180,19 @@ handle_monitor_data (void *cls, const struct GNUNET_TRANSPORT_MonitorData *md)
181 * @param me end message 180 * @param me end message
182 */ 181 */
183static void 182static void
184handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me) 183handle_monitor_end(void *cls, const struct GNUNET_MessageHeader *me)
185{ 184{
186 struct GNUNET_TRANSPORT_MonitorContext *mc = cls; 185 struct GNUNET_TRANSPORT_MonitorContext *mc = cls;
187 186
188 if (GNUNET_YES != mc->one_shot) 187 if (GNUNET_YES != mc->one_shot)
189 { 188 {
190 GNUNET_break (0); 189 GNUNET_break(0);
191 disconnect (mc); 190 disconnect(mc);
192 reconnect (mc); 191 reconnect(mc);
193 return; 192 return;
194 } 193 }
195 mc->cb (mc->cb_cls, NULL, NULL); 194 mc->cb(mc->cb_cls, NULL, NULL);
196 GNUNET_TRANSPORT_monitor_cancel (mc); 195 GNUNET_TRANSPORT_monitor_cancel(mc);
197} 196}
198 197
199 198
@@ -203,24 +202,24 @@ handle_monitor_end (void *cls, const struct GNUNET_MessageHeader *me)
203 * @param mc handle to reconnect 202 * @param mc handle to reconnect
204 */ 203 */
205static void 204static void
206reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc) 205reconnect(struct GNUNET_TRANSPORT_MonitorContext *mc)
207{ 206{
208 struct GNUNET_MQ_MessageHandler handlers[] = 207 struct GNUNET_MQ_MessageHandler handlers[] =
209 {GNUNET_MQ_hd_var_size (monitor_data, 208 { GNUNET_MQ_hd_var_size(monitor_data,
210 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA, 209 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_DATA,
211 struct GNUNET_TRANSPORT_MonitorData, 210 struct GNUNET_TRANSPORT_MonitorData,
211 mc),
212 GNUNET_MQ_hd_fixed_size(monitor_end,
213 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END,
214 struct GNUNET_MessageHeader,
212 mc), 215 mc),
213 GNUNET_MQ_hd_fixed_size (monitor_end, 216 GNUNET_MQ_handler_end() };
214 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_END,
215 struct GNUNET_MessageHeader,
216 mc),
217 GNUNET_MQ_handler_end ()};
218 217
219 mc->mq = 218 mc->mq =
220 GNUNET_CLIENT_connect (mc->cfg, "transport", handlers, &error_handler, mc); 219 GNUNET_CLIENT_connect(mc->cfg, "transport", handlers, &error_handler, mc);
221 if (NULL == mc->mq) 220 if (NULL == mc->mq)
222 return; 221 return;
223 send_start_monitor (mc); 222 send_start_monitor(mc);
224} 223}
225 224
226 225
@@ -251,27 +250,27 @@ reconnect (struct GNUNET_TRANSPORT_MonitorContext *mc)
251 * @param cb_cls closure for @a mc 250 * @param cb_cls closure for @a mc
252 */ 251 */
253struct GNUNET_TRANSPORT_MonitorContext * 252struct GNUNET_TRANSPORT_MonitorContext *
254GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg, 253GNUNET_TRANSPORT_monitor(const struct GNUNET_CONFIGURATION_Handle *cfg,
255 const struct GNUNET_PeerIdentity *peer, 254 const struct GNUNET_PeerIdentity *peer,
256 int one_shot, 255 int one_shot,
257 GNUNET_TRANSPORT_MonitorCallback cb, 256 GNUNET_TRANSPORT_MonitorCallback cb,
258 void *cb_cls) 257 void *cb_cls)
259{ 258{
260 struct GNUNET_TRANSPORT_MonitorContext *mc; 259 struct GNUNET_TRANSPORT_MonitorContext *mc;
261 260
262 mc = GNUNET_new (struct GNUNET_TRANSPORT_MonitorContext); 261 mc = GNUNET_new(struct GNUNET_TRANSPORT_MonitorContext);
263 mc->cfg = cfg; 262 mc->cfg = cfg;
264 if (NULL != peer) 263 if (NULL != peer)
265 mc->peer = *peer; 264 mc->peer = *peer;
266 mc->one_shot = one_shot; 265 mc->one_shot = one_shot;
267 mc->cb = cb; 266 mc->cb = cb;
268 mc->cb_cls = cb_cls; 267 mc->cb_cls = cb_cls;
269 reconnect (mc); 268 reconnect(mc);
270 if (NULL == mc->mq) 269 if (NULL == mc->mq)
271 { 270 {
272 GNUNET_free (mc); 271 GNUNET_free(mc);
273 return NULL; 272 return NULL;
274 } 273 }
275 return mc; 274 return mc;
276} 275}
277 276
@@ -282,10 +281,10 @@ GNUNET_TRANSPORT_monitor (const struct GNUNET_CONFIGURATION_Handle *cfg,
282 * @param pmc handle for the request to cancel 281 * @param pmc handle for the request to cancel
283 */ 282 */
284void 283void
285GNUNET_TRANSPORT_monitor_cancel (struct GNUNET_TRANSPORT_MonitorContext *mc) 284GNUNET_TRANSPORT_monitor_cancel(struct GNUNET_TRANSPORT_MonitorContext *mc)
286{ 285{
287 disconnect (mc); 286 disconnect(mc);
288 GNUNET_free (mc); 287 GNUNET_free(mc);
289} 288}
290 289
291/* end of transport_api2_monitor.c */ 290/* 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 006e81f29..d5e383914 100644
--- a/src/transport/transport_api_address_to_string.c
+++ b/src/transport/transport_api_address_to_string.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file transport/transport_api_address_to_string.c 21 * @file transport/transport_api_address_to_string.c
22 * @author Christian Grothoff 22 * @author Christian Grothoff
@@ -33,8 +33,7 @@
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{
38 /** 37 /**
39 * Function to call with the human-readable address. 38 * Function to call with the human-readable address.
40 */ 39 */
@@ -49,7 +48,6 @@ struct GNUNET_TRANSPORT_AddressToStringContext
49 * Connection to the service. 48 * Connection to the service.
50 */ 49 */
51 struct GNUNET_MQ_Handle *mq; 50 struct GNUNET_MQ_Handle *mq;
52
53}; 51};
54 52
55 53
@@ -61,35 +59,35 @@ struct GNUNET_TRANSPORT_AddressToStringContext
61 * @return #GNUNET_OK if message is well-formed 59 * @return #GNUNET_OK if message is well-formed
62 */ 60 */
63static int 61static int
64check_reply (void *cls, 62check_reply(void *cls,
65 const struct AddressToStringResultMessage *atsm) 63 const struct AddressToStringResultMessage *atsm)
66{ 64{
67 uint16_t size = ntohs (atsm->header.size) - sizeof (*atsm); 65 uint16_t size = ntohs(atsm->header.size) - sizeof(*atsm);
68 const char *address; 66 const char *address;
69 int result; 67 int result;
70 uint32_t addr_len; 68 uint32_t addr_len;
71 69
72 result = (int) ntohl (atsm->res); 70 result = (int)ntohl(atsm->res);
73 addr_len = ntohl (atsm->addr_len); 71 addr_len = ntohl(atsm->addr_len);
74 if (GNUNET_SYSERR == result) 72 if (GNUNET_SYSERR == result)
75 return GNUNET_OK; 73 return GNUNET_OK;
76 if (0 == size) 74 if (0 == size)
77 {
78 if (GNUNET_OK != result)
79 { 75 {
80 GNUNET_break (0); 76 if (GNUNET_OK != result)
77 {
78 GNUNET_break(0);
79 return GNUNET_SYSERR;
80 }
81 return GNUNET_OK;
82 }
83 address = (const char *)&atsm[1];
84 if ((addr_len > size) ||
85 (address[addr_len - 1] != '\0'))
86 {
87 /* invalid reply */
88 GNUNET_break(0);
81 return GNUNET_SYSERR; 89 return GNUNET_SYSERR;
82 } 90 }
83 return GNUNET_OK;
84 }
85 address = (const char *) &atsm[1];
86 if ( (addr_len > size) ||
87 (address[addr_len -1] != '\0') )
88 {
89 /* invalid reply */
90 GNUNET_break (0);
91 return GNUNET_SYSERR;
92 }
93 return GNUNET_OK; 91 return GNUNET_OK;
94} 92}
95 93
@@ -101,40 +99,40 @@ check_reply (void *cls,
101 * @param msg message with the human-readable address 99 * @param msg message with the human-readable address
102 */ 100 */
103static void 101static void
104handle_reply (void *cls, 102handle_reply(void *cls,
105 const struct AddressToStringResultMessage *atsm) 103 const struct AddressToStringResultMessage *atsm)
106{ 104{
107 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 105 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
108 uint16_t size = ntohs (atsm->header.size) - sizeof (*atsm); 106 uint16_t size = ntohs(atsm->header.size) - sizeof(*atsm);
109 const char *address; 107 const char *address;
110 int result; 108 int result;
111 109
112 result = (int) ntohl (atsm->res); 110 result = (int)ntohl(atsm->res);
113 if (GNUNET_SYSERR == result) 111 if (GNUNET_SYSERR == result)
114 { 112 {
115 /* expect more replies; as this is not the last 113 /* expect more replies; as this is not the last
116 call, we must pass the empty string for the address */ 114 call, we must pass the empty string for the address */
117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 115 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
118 "Address resolution failed\n"); 116 "Address resolution failed\n");
119 alucb->cb (alucb->cb_cls, 117 alucb->cb(alucb->cb_cls,
120 "", 118 "",
121 GNUNET_NO); 119 GNUNET_NO);
122 return; 120 return;
123 } 121 }
124 if (0 == size) 122 if (0 == size)
125 { 123 {
126 /* we are done (successfully, without communication errors) */ 124 /* we are done (successfully, without communication errors) */
127 alucb->cb (alucb->cb_cls, 125 alucb->cb(alucb->cb_cls,
128 NULL, 126 NULL,
129 GNUNET_OK); 127 GNUNET_OK);
130 GNUNET_TRANSPORT_address_to_string_cancel (alucb); 128 GNUNET_TRANSPORT_address_to_string_cancel(alucb);
131 return; 129 return;
132 } 130 }
133 address = (const char *) &atsm[1]; 131 address = (const char *)&atsm[1];
134 /* return normal reply to caller, also expect more replies */ 132 /* return normal reply to caller, also expect more replies */
135 alucb->cb (alucb->cb_cls, 133 alucb->cb(alucb->cb_cls,
136 address, 134 address,
137 GNUNET_OK); 135 GNUNET_OK);
138} 136}
139 137
140 138
@@ -148,17 +146,17 @@ handle_reply (void *cls,
148 * @param error error code 146 * @param error error code
149 */ 147 */
150static void 148static void
151mq_error_handler (void *cls, 149mq_error_handler(void *cls,
152 enum GNUNET_MQ_Error error) 150 enum GNUNET_MQ_Error error)
153{ 151{
154 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls; 152 struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
155 153
156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 154 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
157 "Disconnected from transport, address resolution failed\n"); 155 "Disconnected from transport, address resolution failed\n");
158 alucb->cb (alucb->cb_cls, 156 alucb->cb(alucb->cb_cls,
159 NULL, 157 NULL,
160 GNUNET_SYSERR); 158 GNUNET_SYSERR);
161 GNUNET_TRANSPORT_address_to_string_cancel (alucb); 159 GNUNET_TRANSPORT_address_to_string_cancel(alucb);
162} 160}
163 161
164 162
@@ -175,21 +173,21 @@ mq_error_handler (void *cls,
175 * @return handle to cancel the operation, NULL on error 173 * @return handle to cancel the operation, NULL on error
176 */ 174 */
177struct GNUNET_TRANSPORT_AddressToStringContext * 175struct GNUNET_TRANSPORT_AddressToStringContext *
178GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cfg, 176GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg,
179 const struct GNUNET_HELLO_Address *address, 177 const struct GNUNET_HELLO_Address *address,
180 int numeric, 178 int numeric,
181 struct GNUNET_TIME_Relative timeout, 179 struct GNUNET_TIME_Relative timeout,
182 GNUNET_TRANSPORT_AddressToStringCallback aluc, 180 GNUNET_TRANSPORT_AddressToStringCallback aluc,
183 void *aluc_cls) 181 void *aluc_cls)
184{ 182{
185 struct GNUNET_TRANSPORT_AddressToStringContext *alc 183 struct GNUNET_TRANSPORT_AddressToStringContext *alc
186 = GNUNET_new (struct GNUNET_TRANSPORT_AddressToStringContext); 184 = GNUNET_new(struct GNUNET_TRANSPORT_AddressToStringContext);
187 struct GNUNET_MQ_MessageHandler handlers[] = { 185 struct GNUNET_MQ_MessageHandler handlers[] = {
188 GNUNET_MQ_hd_var_size (reply, 186 GNUNET_MQ_hd_var_size(reply,
189 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY, 187 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY,
190 struct AddressToStringResultMessage, 188 struct AddressToStringResultMessage,
191 alc), 189 alc),
192 GNUNET_MQ_handler_end () 190 GNUNET_MQ_handler_end()
193 }; 191 };
194 size_t alen; 192 size_t alen;
195 size_t slen; 193 size_t slen;
@@ -198,49 +196,49 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
198 char *addrbuf; 196 char *addrbuf;
199 197
200 alen = address->address_length; 198 alen = address->address_length;
201 slen = strlen (address->transport_name) + 1; 199 slen = strlen(address->transport_name) + 1;
202 if ( (alen + slen >= GNUNET_MAX_MESSAGE_SIZE 200 if ((alen + slen >= GNUNET_MAX_MESSAGE_SIZE
203 - sizeof (struct AddressLookupMessage)) || 201 - sizeof(struct AddressLookupMessage)) ||
204 (alen >= GNUNET_MAX_MESSAGE_SIZE) || 202 (alen >= GNUNET_MAX_MESSAGE_SIZE) ||
205 (slen >= GNUNET_MAX_MESSAGE_SIZE) ) 203 (slen >= GNUNET_MAX_MESSAGE_SIZE))
206 { 204 {
207 GNUNET_break (0); 205 GNUNET_break(0);
208 GNUNET_free (alc); 206 GNUNET_free(alc);
209 return NULL; 207 return NULL;
210 } 208 }
211 alc->cb = aluc; 209 alc->cb = aluc;
212 alc->cb_cls = aluc_cls; 210 alc->cb_cls = aluc_cls;
213 alc->mq = GNUNET_CLIENT_connect (cfg, 211 alc->mq = GNUNET_CLIENT_connect(cfg,
214 "transport", 212 "transport",
215 handlers, 213 handlers,
216 &mq_error_handler, 214 &mq_error_handler,
217 alc); 215 alc);
218 if (NULL == alc->mq) 216 if (NULL == alc->mq)
219 { 217 {
220 GNUNET_break (0); 218 GNUNET_break(0);
221 GNUNET_free (alc); 219 GNUNET_free(alc);
222 return NULL; 220 return NULL;
223 } 221 }
224 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 222 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
225 "Client tries to resolve for peer `%s' address plugin %s len %u\n", 223 "Client tries to resolve for peer `%s' address plugin %s len %u\n",
226 GNUNET_i2s (&address->peer), 224 GNUNET_i2s(&address->peer),
227 address->transport_name, 225 address->transport_name,
228 (unsigned int) address->address_length); 226 (unsigned int)address->address_length);
229 env = GNUNET_MQ_msg_extra (msg, 227 env = GNUNET_MQ_msg_extra(msg,
230 alen + slen, 228 alen + slen,
231 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING); 229 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING);
232 msg->numeric_only = htons ((int16_t) numeric); 230 msg->numeric_only = htons((int16_t)numeric);
233 msg->addrlen = htons ((uint16_t) alen); 231 msg->addrlen = htons((uint16_t)alen);
234 msg->timeout = GNUNET_TIME_relative_hton (timeout); 232 msg->timeout = GNUNET_TIME_relative_hton(timeout);
235 addrbuf = (char *) &msg[1]; 233 addrbuf = (char *)&msg[1];
236 GNUNET_memcpy (addrbuf, 234 GNUNET_memcpy(addrbuf,
237 address->address, 235 address->address,
238 alen); 236 alen);
239 GNUNET_memcpy (&addrbuf[alen], 237 GNUNET_memcpy(&addrbuf[alen],
240 address->transport_name, 238 address->transport_name,
241 slen); 239 slen);
242 GNUNET_MQ_send (alc->mq, 240 GNUNET_MQ_send(alc->mq,
243 env); 241 env);
244 return alc; 242 return alc;
245} 243}
246 244
@@ -251,10 +249,10 @@ GNUNET_TRANSPORT_address_to_string (const struct GNUNET_CONFIGURATION_Handle *cf
251 * @param alc the context handle 249 * @param alc the context handle
252 */ 250 */
253void 251void
254GNUNET_TRANSPORT_address_to_string_cancel (struct GNUNET_TRANSPORT_AddressToStringContext *alc) 252GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
255{ 253{
256 GNUNET_MQ_destroy (alc->mq); 254 GNUNET_MQ_destroy(alc->mq);
257 GNUNET_free (alc); 255 GNUNET_free(alc);
258} 256}
259 257
260 258
diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c
index 63fee8781..f04def49d 100644
--- a/src/transport/transport_api_blacklist.c
+++ b/src/transport/transport_api_blacklist.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_blacklist.c 22 * @file transport/transport_api_blacklist.c
@@ -34,9 +34,7 @@
34/** 34/**
35 * Handle for blacklisting requests. 35 * Handle for blacklisting requests.
36 */ 36 */
37struct GNUNET_TRANSPORT_Blacklist 37struct GNUNET_TRANSPORT_Blacklist {
38{
39
40 /** 38 /**
41 * Connection to transport service. 39 * Connection to transport service.
42 */ 40 */
@@ -57,7 +55,6 @@ struct GNUNET_TRANSPORT_Blacklist
57 * Closure for @e cb. 55 * Closure for @e cb.
58 */ 56 */
59 void *cb_cls; 57 void *cb_cls;
60
61}; 58};
62 59
63 60
@@ -67,7 +64,7 @@ struct GNUNET_TRANSPORT_Blacklist
67 * @param br overall handle 64 * @param br overall handle
68 */ 65 */
69static void 66static void
70reconnect (struct GNUNET_TRANSPORT_Blacklist *br); 67reconnect(struct GNUNET_TRANSPORT_Blacklist *br);
71 68
72 69
73/** 70/**
@@ -77,21 +74,21 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
77 * @param bm query 74 * @param bm query
78 */ 75 */
79static void 76static void
80handle_query (void *cls, 77handle_query(void *cls,
81 const struct BlacklistMessage *bm) 78 const struct BlacklistMessage *bm)
82{ 79{
83 struct GNUNET_TRANSPORT_Blacklist *br = cls; 80 struct GNUNET_TRANSPORT_Blacklist *br = cls;
84 struct GNUNET_MQ_Envelope *env; 81 struct GNUNET_MQ_Envelope *env;
85 struct BlacklistMessage *res; 82 struct BlacklistMessage *res;
86 83
87 GNUNET_break (0 == ntohl (bm->is_allowed)); 84 GNUNET_break(0 == ntohl(bm->is_allowed));
88 env = GNUNET_MQ_msg (res, 85 env = GNUNET_MQ_msg(res,
89 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY); 86 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
90 res->is_allowed = htonl (br->cb (br->cb_cls, 87 res->is_allowed = htonl(br->cb(br->cb_cls,
91 &bm->peer)); 88 &bm->peer));
92 res->peer = bm->peer; 89 res->peer = bm->peer;
93 GNUNET_MQ_send (br->mq, 90 GNUNET_MQ_send(br->mq,
94 env); 91 env);
95} 92}
96 93
97/** 94/**
@@ -103,12 +100,12 @@ handle_query (void *cls,
103 * @param error error code 100 * @param error error code
104 */ 101 */
105static void 102static void
106mq_error_handler (void *cls, 103mq_error_handler(void *cls,
107 enum GNUNET_MQ_Error error) 104 enum GNUNET_MQ_Error error)
108{ 105{
109 struct GNUNET_TRANSPORT_Blacklist *br = cls; 106 struct GNUNET_TRANSPORT_Blacklist *br = cls;
110 107
111 reconnect (br); 108 reconnect(br);
112} 109}
113 110
114 111
@@ -118,31 +115,31 @@ mq_error_handler (void *cls,
118 * @param br overall handle 115 * @param br overall handle
119 */ 116 */
120static void 117static void
121reconnect (struct GNUNET_TRANSPORT_Blacklist *br) 118reconnect(struct GNUNET_TRANSPORT_Blacklist *br)
122{ 119{
123 struct GNUNET_MQ_MessageHandler handlers[] = { 120 struct GNUNET_MQ_MessageHandler handlers[] = {
124 GNUNET_MQ_hd_fixed_size (query, 121 GNUNET_MQ_hd_fixed_size(query,
125 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY, 122 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY,
126 struct BlacklistMessage, 123 struct BlacklistMessage,
127 br), 124 br),
128 GNUNET_MQ_handler_end () 125 GNUNET_MQ_handler_end()
129 }; 126 };
130 struct GNUNET_MQ_Envelope *env; 127 struct GNUNET_MQ_Envelope *env;
131 struct GNUNET_MessageHeader *req; 128 struct GNUNET_MessageHeader *req;
132 129
133 if (NULL != br->mq) 130 if (NULL != br->mq)
134 GNUNET_MQ_destroy (br->mq); 131 GNUNET_MQ_destroy(br->mq);
135 br->mq = GNUNET_CLIENT_connect (br->cfg, 132 br->mq = GNUNET_CLIENT_connect(br->cfg,
136 "transport", 133 "transport",
137 handlers, 134 handlers,
138 &mq_error_handler, 135 &mq_error_handler,
139 br); 136 br);
140 if (NULL == br->mq) 137 if (NULL == br->mq)
141 return; 138 return;
142 env = GNUNET_MQ_msg (req, 139 env = GNUNET_MQ_msg(req,
143 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT); 140 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
144 GNUNET_MQ_send (br->mq, 141 GNUNET_MQ_send(br->mq,
145 env); 142 env);
146} 143}
147 144
148 145
@@ -161,22 +158,22 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
161 * @return NULL on error, otherwise handle for cancellation 158 * @return NULL on error, otherwise handle for cancellation
162 */ 159 */
163struct GNUNET_TRANSPORT_Blacklist * 160struct GNUNET_TRANSPORT_Blacklist *
164GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg, 161GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg,
165 GNUNET_TRANSPORT_BlacklistCallback cb, 162 GNUNET_TRANSPORT_BlacklistCallback cb,
166 void *cb_cls) 163 void *cb_cls)
167{ 164{
168 struct GNUNET_TRANSPORT_Blacklist *br; 165 struct GNUNET_TRANSPORT_Blacklist *br;
169 166
170 br = GNUNET_new (struct GNUNET_TRANSPORT_Blacklist); 167 br = GNUNET_new(struct GNUNET_TRANSPORT_Blacklist);
171 br->cfg = cfg; 168 br->cfg = cfg;
172 br->cb = cb; 169 br->cb = cb;
173 br->cb_cls = cb_cls; 170 br->cb_cls = cb_cls;
174 reconnect (br); 171 reconnect(br);
175 if (NULL == br->mq) 172 if (NULL == br->mq)
176 { 173 {
177 GNUNET_free (br); 174 GNUNET_free(br);
178 return NULL; 175 return NULL;
179 } 176 }
180 return br; 177 return br;
181} 178}
182 179
@@ -188,10 +185,10 @@ GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
188 * @param br handle of the request that is to be cancelled 185 * @param br handle of the request that is to be cancelled
189 */ 186 */
190void 187void
191GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br) 188GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br)
192{ 189{
193 GNUNET_MQ_destroy (br->mq); 190 GNUNET_MQ_destroy(br->mq);
194 GNUNET_free (br); 191 GNUNET_free(br);
195} 192}
196 193
197 194
diff --git a/src/transport/transport_api_core.c b/src/transport/transport_api_core.c
index 224af5de2..d88461d5a 100644
--- a/src/transport/transport_api_core.c
+++ b/src/transport/transport_api_core.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_core.c 22 * @file 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,8 +49,7 @@
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{
54 /** 53 /**
55 * Overall transport handle. 54 * Overall transport handle.
56 */ 55 */
@@ -119,9 +118,7 @@ struct Neighbour
119 * Handle for the transport service (includes all of the 118 * Handle for the transport service (includes all of the
120 * state for the transport service). 119 * state for the transport service).
121 */ 120 */
122struct GNUNET_TRANSPORT_CoreHandle 121struct GNUNET_TRANSPORT_CoreHandle {
123{
124
125 /** 122 /**
126 * Closure for the callbacks. 123 * Closure for the callbacks.
127 */ 124 */
@@ -203,7 +200,7 @@ struct GNUNET_TRANSPORT_CoreHandle
203 * @param h transport service to reconnect 200 * @param h transport service to reconnect
204 */ 201 */
205static void 202static void
206disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h); 203disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h);
207 204
208 205
209/** 206/**
@@ -214,10 +211,10 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h);
214 * @return NULL if no such peer entry exists 211 * @return NULL if no such peer entry exists
215 */ 212 */
216static struct Neighbour * 213static struct Neighbour *
217neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, 214neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h,
218 const struct GNUNET_PeerIdentity *peer) 215 const struct GNUNET_PeerIdentity *peer)
219{ 216{
220 return GNUNET_CONTAINER_multipeermap_get (h->neighbours, peer); 217 return GNUNET_CONTAINER_multipeermap_get(h->neighbours, peer);
221} 218}
222 219
223 220
@@ -228,17 +225,17 @@ neighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h,
228 * @param cls the `struct Neighbour` that has excess bandwidth 225 * @param cls the `struct Neighbour` that has excess bandwidth
229 */ 226 */
230static void 227static void
231notify_excess_cb (void *cls) 228notify_excess_cb(void *cls)
232{ 229{
233 struct Neighbour *n = cls; 230 struct Neighbour *n = cls;
234 struct GNUNET_TRANSPORT_CoreHandle *h = n->h; 231 struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
235 232
236 LOG (GNUNET_ERROR_TYPE_DEBUG, 233 LOG(GNUNET_ERROR_TYPE_DEBUG,
237 "Notifying CORE that more bandwidth is available for %s\n", 234 "Notifying CORE that more bandwidth is available for %s\n",
238 GNUNET_i2s (&n->id)); 235 GNUNET_i2s(&n->id));
239 236
240 if (NULL != h->neb_cb) 237 if (NULL != h->neb_cb)
241 h->neb_cb (h->cls, &n->id, n->handlers_cls); 238 h->neb_cb(h->cls, &n->id, n->handlers_cls);
242} 239}
243 240
244 241
@@ -253,33 +250,33 @@ notify_excess_cb (void *cls)
253 * #GNUNET_NO if not. 250 * #GNUNET_NO if not.
254 */ 251 */
255static int 252static int
256neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 253neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
257{ 254{
258 struct GNUNET_TRANSPORT_CoreHandle *handle = cls; 255 struct GNUNET_TRANSPORT_CoreHandle *handle = cls;
259 struct Neighbour *n = value; 256 struct Neighbour *n = value;
260 257
261 LOG (GNUNET_ERROR_TYPE_DEBUG, 258 LOG(GNUNET_ERROR_TYPE_DEBUG,
262 "Dropping entry for neighbour `%s'.\n", 259 "Dropping entry for neighbour `%s'.\n",
263 GNUNET_i2s (key)); 260 GNUNET_i2s(key));
264 GNUNET_BANDWIDTH_tracker_notification_stop (&n->out_tracker); 261 GNUNET_BANDWIDTH_tracker_notification_stop(&n->out_tracker);
265 if (NULL != handle->nd_cb) 262 if (NULL != handle->nd_cb)
266 handle->nd_cb (handle->cls, &n->id, n->handlers_cls); 263 handle->nd_cb(handle->cls, &n->id, n->handlers_cls);
267 if (NULL != n->timeout_task) 264 if (NULL != n->timeout_task)
268 { 265 {
269 GNUNET_SCHEDULER_cancel (n->timeout_task); 266 GNUNET_SCHEDULER_cancel(n->timeout_task);
270 n->timeout_task = NULL; 267 n->timeout_task = NULL;
271 } 268 }
272 if (NULL != n->env) 269 if (NULL != n->env)
273 { 270 {
274 GNUNET_MQ_send_cancel (n->env); 271 GNUNET_MQ_send_cancel(n->env);
275 n->env = NULL; 272 n->env = NULL;
276 } 273 }
277 GNUNET_MQ_destroy (n->mq); 274 GNUNET_MQ_destroy(n->mq);
278 GNUNET_assert (NULL == n->mq); 275 GNUNET_assert(NULL == n->mq);
279 GNUNET_assert ( 276 GNUNET_assert(
280 GNUNET_YES == 277 GNUNET_YES ==
281 GNUNET_CONTAINER_multipeermap_remove (handle->neighbours, key, n)); 278 GNUNET_CONTAINER_multipeermap_remove(handle->neighbours, key, n));
282 GNUNET_free (n); 279 GNUNET_free(n);
283 return GNUNET_YES; 280 return GNUNET_YES;
284} 281}
285 282
@@ -294,14 +291,14 @@ neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
294 * @param error error code 291 * @param error error code
295 */ 292 */
296static void 293static void
297mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 294mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
298{ 295{
299 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 296 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
300 297
301 LOG (GNUNET_ERROR_TYPE_ERROR, 298 LOG(GNUNET_ERROR_TYPE_ERROR,
302 "Error receiving from transport service (%d), disconnecting temporarily.\n", 299 "Error receiving from transport service (%d), disconnecting temporarily.\n",
303 error); 300 error);
304 disconnect_and_schedule_reconnect (h); 301 disconnect_and_schedule_reconnect(h);
305} 302}
306 303
307 304
@@ -313,16 +310,16 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
313 * @return #GNUNET_OK if message is well-formed 310 * @return #GNUNET_OK if message is well-formed
314 */ 311 */
315static int 312static int
316check_hello (void *cls, const struct GNUNET_MessageHeader *msg) 313check_hello(void *cls, const struct GNUNET_MessageHeader *msg)
317{ 314{
318 struct GNUNET_PeerIdentity me; 315 struct GNUNET_PeerIdentity me;
319 316
320 if (GNUNET_OK != 317 if (GNUNET_OK !=
321 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me)) 318 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg, &me))
322 { 319 {
323 GNUNET_break (0); 320 GNUNET_break(0);
324 return GNUNET_SYSERR; 321 return GNUNET_SYSERR;
325 } 322 }
326 return GNUNET_OK; 323 return GNUNET_OK;
327} 324}
328 325
@@ -334,7 +331,7 @@ check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
334 * @param msg message received 331 * @param msg message received
335 */ 332 */
336static void 333static void
337handle_hello (void *cls, const struct GNUNET_MessageHeader *msg) 334handle_hello(void *cls, const struct GNUNET_MessageHeader *msg)
338{ 335{
339 /* we do not care => FIXME: signal in options to NEVER send HELLOs! */ 336 /* we do not care => FIXME: signal in options to NEVER send HELLOs! */
340} 337}
@@ -349,13 +346,13 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
349 * @param cls the `struct Neighbour` where the message was sent 346 * @param cls the `struct Neighbour` where the message was sent
350 */ 347 */
351static void 348static void
352notify_send_done_fin (void *cls) 349notify_send_done_fin(void *cls)
353{ 350{
354 struct Neighbour *n = cls; 351 struct Neighbour *n = cls;
355 352
356 n->timeout_task = NULL; 353 n->timeout_task = NULL;
357 n->is_ready = GNUNET_YES; 354 n->is_ready = GNUNET_YES;
358 GNUNET_MQ_impl_send_continue (n->mq); 355 GNUNET_MQ_impl_send_continue(n->mq);
359} 356}
360 357
361 358
@@ -368,31 +365,31 @@ notify_send_done_fin (void *cls)
368 * @param cls the `struct Neighbour` where the message was sent 365 * @param cls the `struct Neighbour` where the message was sent
369 */ 366 */
370static void 367static void
371notify_send_done (void *cls) 368notify_send_done(void *cls)
372{ 369{
373 struct Neighbour *n = cls; 370 struct Neighbour *n = cls;
374 struct GNUNET_TIME_Relative delay; 371 struct GNUNET_TIME_Relative delay;
375 372
376 n->timeout_task = NULL; 373 n->timeout_task = NULL;
377 if (NULL != n->env) 374 if (NULL != n->env)
378 { 375 {
379 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, 376 GNUNET_BANDWIDTH_tracker_consume(&n->out_tracker,
380 n->env_size + n->traffic_overhead); 377 n->env_size + n->traffic_overhead);
381 n->env = NULL; 378 n->env = NULL;
382 n->traffic_overhead = 0; 379 n->traffic_overhead = 0;
383 } 380 }
384 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); 381 delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128);
385 if (0 == delay.rel_value_us) 382 if (0 == delay.rel_value_us)
386 { 383 {
387 n->is_ready = GNUNET_YES; 384 n->is_ready = GNUNET_YES;
388 GNUNET_MQ_impl_send_continue (n->mq); 385 GNUNET_MQ_impl_send_continue(n->mq);
389 return; 386 return;
390 } 387 }
391 GNUNET_MQ_impl_send_in_flight (n->mq); 388 GNUNET_MQ_impl_send_in_flight(n->mq);
392 /* cannot send even a small message without violating 389 /* cannot send even a small message without violating
393 quota, wait a before allowing MQ to send next message */ 390 quota, wait a before allowing MQ to send next message */
394 n->timeout_task = 391 n->timeout_task =
395 GNUNET_SCHEDULER_add_delayed (delay, &notify_send_done_fin, n); 392 GNUNET_SCHEDULER_add_delayed(delay, &notify_send_done_fin, n);
396} 393}
397 394
398 395
@@ -407,44 +404,44 @@ notify_send_done (void *cls)
407 * @param impl_state state of the implementation 404 * @param impl_state state of the implementation
408 */ 405 */
409static void 406static void
410mq_send_impl (struct GNUNET_MQ_Handle *mq, 407mq_send_impl(struct GNUNET_MQ_Handle *mq,
411 const struct GNUNET_MessageHeader *msg, 408 const struct GNUNET_MessageHeader *msg,
412 void *impl_state) 409 void *impl_state)
413{ 410{
414 struct Neighbour *n = impl_state; 411 struct Neighbour *n = impl_state;
415 struct GNUNET_TRANSPORT_CoreHandle *h = n->h; 412 struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
416 struct OutboundMessage *obm; 413 struct OutboundMessage *obm;
417 uint16_t msize; 414 uint16_t msize;
418 415
419 GNUNET_assert (GNUNET_YES == n->is_ready); 416 GNUNET_assert(GNUNET_YES == n->is_ready);
420 msize = ntohs (msg->size); 417 msize = ntohs(msg->size);
421 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm)) 418 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
422 { 419 {
423 GNUNET_break (0); 420 GNUNET_break(0);
424 GNUNET_MQ_impl_send_continue (mq); 421 GNUNET_MQ_impl_send_continue(mq);
425 return; 422 return;
426 } 423 }
427 GNUNET_assert (NULL == n->env); 424 GNUNET_assert(NULL == n->env);
428 n->env = 425 n->env =
429 GNUNET_MQ_msg_nested_mh (obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg); 426 GNUNET_MQ_msg_nested_mh(obm, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, msg);
430 { 427 {
431 struct GNUNET_MQ_Envelope *env; 428 struct GNUNET_MQ_Envelope *env;
432 429
433 env = GNUNET_MQ_get_current_envelope (mq); 430 env = GNUNET_MQ_get_current_envelope(mq);
434 obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env)); 431 obm->priority = htonl((uint32_t)GNUNET_MQ_env_get_options(env));
435 } 432 }
436 obm->timeout = GNUNET_TIME_relative_hton ( 433 obm->timeout = GNUNET_TIME_relative_hton(
437 GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */ 434 GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
438 obm->peer = n->id; 435 obm->peer = n->id;
439 GNUNET_assert (NULL == n->timeout_task); 436 GNUNET_assert(NULL == n->timeout_task);
440 n->is_ready = GNUNET_NO; 437 n->is_ready = GNUNET_NO;
441 n->env_size = ntohs (msg->size); 438 n->env_size = ntohs(msg->size);
442 GNUNET_MQ_notify_sent (n->env, &notify_send_done, n); 439 GNUNET_MQ_notify_sent(n->env, &notify_send_done, n);
443 GNUNET_MQ_send (h->mq, n->env); 440 GNUNET_MQ_send(h->mq, n->env);
444 LOG (GNUNET_ERROR_TYPE_DEBUG, 441 LOG(GNUNET_ERROR_TYPE_DEBUG,
445 "Queued message of type %u for neighbour `%s'.\n", 442 "Queued message of type %u for neighbour `%s'.\n",
446 ntohs (msg->type), 443 ntohs(msg->type),
447 GNUNET_i2s (&n->id)); 444 GNUNET_i2s(&n->id));
448} 445}
449 446
450 447
@@ -456,11 +453,11 @@ mq_send_impl (struct GNUNET_MQ_Handle *mq,
456 * @param impl_state state of the implementation 453 * @param impl_state state of the implementation
457 */ 454 */
458static void 455static void
459mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 456mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
460{ 457{
461 struct Neighbour *n = impl_state; 458 struct Neighbour *n = impl_state;
462 459
463 GNUNET_assert (mq == n->mq); 460 GNUNET_assert(mq == n->mq);
464 n->mq = NULL; 461 n->mq = NULL;
465} 462}
466 463
@@ -473,16 +470,16 @@ mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
473 * @param impl_state state specific to the implementation 470 * @param impl_state state specific to the implementation
474 */ 471 */
475static void 472static void
476mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 473mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
477{ 474{
478 struct Neighbour *n = impl_state; 475 struct Neighbour *n = impl_state;
479 476
480 GNUNET_assert (GNUNET_NO == n->is_ready); 477 GNUNET_assert(GNUNET_NO == n->is_ready);
481 if (NULL != n->env) 478 if (NULL != n->env)
482 { 479 {
483 GNUNET_MQ_send_cancel (n->env); 480 GNUNET_MQ_send_cancel(n->env);
484 n->env = NULL; 481 n->env = NULL;
485 } 482 }
486 483
487 n->is_ready = GNUNET_YES; 484 n->is_ready = GNUNET_YES;
488} 485}
@@ -497,11 +494,11 @@ mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
497 * @param error error code 494 * @param error error code
498 */ 495 */
499static void 496static void
500peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 497peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
501{ 498{
502 /* struct Neighbour *n = cls; */ 499 /* struct Neighbour *n = cls; */
503 500
504 GNUNET_break_op (0); 501 GNUNET_break_op(0);
505} 502}
506 503
507 504
@@ -512,16 +509,16 @@ peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
512 * @param cls the `struct Neighbour` for which the timeout changed 509 * @param cls the `struct Neighbour` for which the timeout changed
513 */ 510 */
514static void 511static void
515outbound_bw_tracker_update (void *cls) 512outbound_bw_tracker_update(void *cls)
516{ 513{
517 struct Neighbour *n = cls; 514 struct Neighbour *n = cls;
518 struct GNUNET_TIME_Relative delay; 515 struct GNUNET_TIME_Relative delay;
519 516
520 if (NULL == n->timeout_task) 517 if (NULL == n->timeout_task)
521 return; 518 return;
522 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, 128); 519 delay = GNUNET_BANDWIDTH_tracker_get_delay(&n->out_tracker, 128);
523 GNUNET_SCHEDULER_cancel (n->timeout_task); 520 GNUNET_SCHEDULER_cancel(n->timeout_task);
524 n->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, &notify_send_done, n); 521 n->timeout_task = GNUNET_SCHEDULER_add_delayed(delay, &notify_send_done, n);
525} 522}
526 523
527 524
@@ -532,54 +529,54 @@ outbound_bw_tracker_update (void *cls)
532 * @param cim message received 529 * @param cim message received
533 */ 530 */
534static void 531static void
535handle_connect (void *cls, const struct ConnectInfoMessage *cim) 532handle_connect(void *cls, const struct ConnectInfoMessage *cim)
536{ 533{
537 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 534 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
538 struct Neighbour *n; 535 struct Neighbour *n;
539 536
540 LOG (GNUNET_ERROR_TYPE_DEBUG, 537 LOG(GNUNET_ERROR_TYPE_DEBUG,
541 "Receiving CONNECT message for `%s' with quota %u\n", 538 "Receiving CONNECT message for `%s' with quota %u\n",
542 GNUNET_i2s (&cim->id), 539 GNUNET_i2s(&cim->id),
543 ntohl (cim->quota_out.value__)); 540 ntohl(cim->quota_out.value__));
544 n = neighbour_find (h, &cim->id); 541 n = neighbour_find(h, &cim->id);
545 if (NULL != n) 542 if (NULL != n)
546 { 543 {
547 GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */ 544 GNUNET_break(0); /* FIXME: this assertion seems to fail sometimes!? */
548 disconnect_and_schedule_reconnect (h); 545 disconnect_and_schedule_reconnect(h);
549 return; 546 return;
550 } 547 }
551 n = GNUNET_new (struct Neighbour); 548 n = GNUNET_new(struct Neighbour);
552 n->id = cim->id; 549 n->id = cim->id;
553 n->h = h; 550 n->h = h;
554 n->is_ready = GNUNET_YES; 551 n->is_ready = GNUNET_YES;
555 n->traffic_overhead = 0; 552 n->traffic_overhead = 0;
556 GNUNET_BANDWIDTH_tracker_init2 (&n->out_tracker, 553 GNUNET_BANDWIDTH_tracker_init2(&n->out_tracker,
557 &outbound_bw_tracker_update, 554 &outbound_bw_tracker_update,
558 n, 555 n,
559 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 556 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
560 MAX_BANDWIDTH_CARRY_S, 557 MAX_BANDWIDTH_CARRY_S,
561 &notify_excess_cb, 558 &notify_excess_cb,
562 n); 559 n);
563 GNUNET_assert (GNUNET_OK == 560 GNUNET_assert(GNUNET_OK ==
564 GNUNET_CONTAINER_multipeermap_put ( 561 GNUNET_CONTAINER_multipeermap_put(
565 h->neighbours, 562 h->neighbours,
566 &n->id, 563 &n->id,
567 n, 564 n,
568 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 565 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
569 566
570 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, cim->quota_out); 567 GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, cim->quota_out);
571 n->mq = GNUNET_MQ_queue_for_callbacks (&mq_send_impl, 568 n->mq = GNUNET_MQ_queue_for_callbacks(&mq_send_impl,
572 &mq_destroy_impl, 569 &mq_destroy_impl,
573 &mq_cancel_impl, 570 &mq_cancel_impl,
574 n, 571 n,
575 h->handlers, 572 h->handlers,
576 &peer_mq_error_handler, 573 &peer_mq_error_handler,
577 n); 574 n);
578 if (NULL != h->nc_cb) 575 if (NULL != h->nc_cb)
579 { 576 {
580 n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq); 577 n->handlers_cls = h->nc_cb(h->cls, &n->id, n->mq);
581 GNUNET_MQ_set_handlers_closure (n->mq, n->handlers_cls); 578 GNUNET_MQ_set_handlers_closure(n->mq, n->handlers_cls);
582 } 579 }
583} 580}
584 581
585 582
@@ -590,23 +587,23 @@ handle_connect (void *cls, const struct ConnectInfoMessage *cim)
590 * @param dim message received 587 * @param dim message received
591 */ 588 */
592static void 589static void
593handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim) 590handle_disconnect(void *cls, const struct DisconnectInfoMessage *dim)
594{ 591{
595 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 592 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
596 struct Neighbour *n; 593 struct Neighbour *n;
597 594
598 GNUNET_break (ntohl (dim->reserved) == 0); 595 GNUNET_break(ntohl(dim->reserved) == 0);
599 LOG (GNUNET_ERROR_TYPE_DEBUG, 596 LOG(GNUNET_ERROR_TYPE_DEBUG,
600 "Receiving DISCONNECT message for `%s'.\n", 597 "Receiving DISCONNECT message for `%s'.\n",
601 GNUNET_i2s (&dim->peer)); 598 GNUNET_i2s(&dim->peer));
602 n = neighbour_find (h, &dim->peer); 599 n = neighbour_find(h, &dim->peer);
603 if (NULL == n) 600 if (NULL == n)
604 { 601 {
605 GNUNET_break (0); 602 GNUNET_break(0);
606 disconnect_and_schedule_reconnect (h); 603 disconnect_and_schedule_reconnect(h);
607 return; 604 return;
608 } 605 }
609 GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n)); 606 GNUNET_assert(GNUNET_YES == neighbour_delete(h, &dim->peer, n));
610} 607}
611 608
612 609
@@ -617,36 +614,36 @@ handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim)
617 * @param okm message received 614 * @param okm message received
618 */ 615 */
619static void 616static void
620handle_send_ok (void *cls, const struct SendOkMessage *okm) 617handle_send_ok(void *cls, const struct SendOkMessage *okm)
621{ 618{
622 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 619 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
623 struct Neighbour *n; 620 struct Neighbour *n;
624 uint32_t bytes_msg; 621 uint32_t bytes_msg;
625 uint32_t bytes_physical; 622 uint32_t bytes_physical;
626 623
627 bytes_msg = ntohl (okm->bytes_msg); 624 bytes_msg = ntohl(okm->bytes_msg);
628 bytes_physical = ntohl (okm->bytes_physical); 625 bytes_physical = ntohl(okm->bytes_physical);
629 LOG (GNUNET_ERROR_TYPE_DEBUG, 626 LOG(GNUNET_ERROR_TYPE_DEBUG,
630 "Receiving SEND_OK message, transmission to %s %s.\n", 627 "Receiving SEND_OK message, transmission to %s %s.\n",
631 GNUNET_i2s (&okm->peer), 628 GNUNET_i2s(&okm->peer),
632 ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); 629 ntohl(okm->success) == GNUNET_OK ? "succeeded" : "failed");
633 n = neighbour_find (h, &okm->peer); 630 n = neighbour_find(h, &okm->peer);
634 if (NULL == n) 631 if (NULL == n)
635 { 632 {
636 /* We should never get a 'SEND_OK' for a peer that we are not 633 /* We should never get a 'SEND_OK' for a peer that we are not
637 connected to */ 634 connected to */
638 GNUNET_break (0); 635 GNUNET_break(0);
639 disconnect_and_schedule_reconnect (h); 636 disconnect_and_schedule_reconnect(h);
640 return; 637 return;
641 } 638 }
642 if (bytes_physical > bytes_msg) 639 if (bytes_physical > bytes_msg)
643 { 640 {
644 LOG (GNUNET_ERROR_TYPE_DEBUG, 641 LOG(GNUNET_ERROR_TYPE_DEBUG,
645 "Overhead for %u byte message was %u\n", 642 "Overhead for %u byte message was %u\n",
646 bytes_msg, 643 bytes_msg,
647 bytes_physical - bytes_msg); 644 bytes_physical - bytes_msg);
648 n->traffic_overhead += bytes_physical - bytes_msg; 645 n->traffic_overhead += bytes_physical - bytes_msg;
649 } 646 }
650} 647}
651 648
652 649
@@ -657,23 +654,23 @@ handle_send_ok (void *cls, const struct SendOkMessage *okm)
657 * @param im message received 654 * @param im message received
658 */ 655 */
659static int 656static int
660check_recv (void *cls, const struct InboundMessage *im) 657check_recv(void *cls, const struct InboundMessage *im)
661{ 658{
662 const struct GNUNET_MessageHeader *imm; 659 const struct GNUNET_MessageHeader *imm;
663 uint16_t size; 660 uint16_t size;
664 661
665 size = ntohs (im->header.size) - sizeof (*im); 662 size = ntohs(im->header.size) - sizeof(*im);
666 if (size < sizeof (struct GNUNET_MessageHeader)) 663 if (size < sizeof(struct GNUNET_MessageHeader))
667 { 664 {
668 GNUNET_break (0); 665 GNUNET_break(0);
669 return GNUNET_SYSERR; 666 return GNUNET_SYSERR;
670 } 667 }
671 imm = (const struct GNUNET_MessageHeader *) &im[1]; 668 imm = (const struct GNUNET_MessageHeader *)&im[1];
672 if (ntohs (imm->size) != size) 669 if (ntohs(imm->size) != size)
673 { 670 {
674 GNUNET_break (0); 671 GNUNET_break(0);
675 return GNUNET_SYSERR; 672 return GNUNET_SYSERR;
676 } 673 }
677 return GNUNET_OK; 674 return GNUNET_OK;
678} 675}
679 676
@@ -685,27 +682,27 @@ check_recv (void *cls, const struct InboundMessage *im)
685 * @param im message received 682 * @param im message received
686 */ 683 */
687static void 684static void
688handle_recv (void *cls, const struct InboundMessage *im) 685handle_recv(void *cls, const struct InboundMessage *im)
689{ 686{
690 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 687 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
691 const struct GNUNET_MessageHeader *imm = 688 const struct GNUNET_MessageHeader *imm =
692 (const struct GNUNET_MessageHeader *) &im[1]; 689 (const struct GNUNET_MessageHeader *)&im[1];
693 struct Neighbour *n; 690 struct Neighbour *n;
694 691
695 LOG (GNUNET_ERROR_TYPE_DEBUG, 692 LOG(GNUNET_ERROR_TYPE_DEBUG,
696 "Received message of type %u with %u bytes from `%s'.\n", 693 "Received message of type %u with %u bytes from `%s'.\n",
697 (unsigned int) ntohs (imm->type), 694 (unsigned int)ntohs(imm->type),
698 (unsigned int) ntohs (imm->size), 695 (unsigned int)ntohs(imm->size),
699 GNUNET_i2s (&im->peer)); 696 GNUNET_i2s(&im->peer));
700 n = neighbour_find (h, &im->peer); 697 n = neighbour_find(h, &im->peer);
701 if (NULL == n) 698 if (NULL == n)
702 { 699 {
703 GNUNET_break (0); 700 GNUNET_break(0);
704 disconnect_and_schedule_reconnect (h); 701 disconnect_and_schedule_reconnect(h);
705 return; 702 return;
706 } 703 }
707 h->rom_pending++; 704 h->rom_pending++;
708 GNUNET_MQ_inject_message (n->mq, imm); 705 GNUNET_MQ_inject_message(n->mq, imm);
709} 706}
710 707
711 708
@@ -716,24 +713,24 @@ handle_recv (void *cls, const struct InboundMessage *im)
716 * @param msg message received 713 * @param msg message received
717 */ 714 */
718static void 715static void
719handle_set_quota (void *cls, const struct QuotaSetMessage *qm) 716handle_set_quota(void *cls, const struct QuotaSetMessage *qm)
720{ 717{
721 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 718 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
722 struct Neighbour *n; 719 struct Neighbour *n;
723 720
724 LOG (GNUNET_ERROR_TYPE_DEBUG, 721 LOG(GNUNET_ERROR_TYPE_DEBUG,
725 "Receiving SET_QUOTA message for `%s' with quota %u\n", 722 "Receiving SET_QUOTA message for `%s' with quota %u\n",
726 GNUNET_i2s (&qm->peer), 723 GNUNET_i2s(&qm->peer),
727 ntohl (qm->quota.value__)); 724 ntohl(qm->quota.value__));
728 n = neighbour_find (h, &qm->peer); 725 n = neighbour_find(h, &qm->peer);
729 if (NULL == n) 726 if (NULL == n)
730 { 727 {
731 GNUNET_break ( 728 GNUNET_break(
732 0); /* FIXME: julius reports this assertion fails sometimes? */ 729 0); /* FIXME: julius reports this assertion fails sometimes? */
733 disconnect_and_schedule_reconnect (h); 730 disconnect_and_schedule_reconnect(h);
734 return; 731 return;
735 } 732 }
736 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, qm->quota); 733 GNUNET_BANDWIDTH_tracker_update_quota(&n->out_tracker, qm->quota);
737} 734}
738 735
739 736
@@ -743,55 +740,55 @@ handle_set_quota (void *cls, const struct QuotaSetMessage *qm)
743 * @param cls the handle to the transport service 740 * @param cls the handle to the transport service
744 */ 741 */
745static void 742static void
746reconnect (void *cls) 743reconnect(void *cls)
747{ 744{
748 struct GNUNET_TRANSPORT_CoreHandle *h = cls; 745 struct GNUNET_TRANSPORT_CoreHandle *h = cls;
749 struct GNUNET_MQ_MessageHandler handlers[] = 746 struct GNUNET_MQ_MessageHandler handlers[] =
750 {GNUNET_MQ_hd_var_size (hello, 747 { GNUNET_MQ_hd_var_size(hello,
751 GNUNET_MESSAGE_TYPE_HELLO, 748 GNUNET_MESSAGE_TYPE_HELLO,
752 struct GNUNET_MessageHeader, 749 struct GNUNET_MessageHeader,
750 h),
751 GNUNET_MQ_hd_fixed_size(connect,
752 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT,
753 struct ConnectInfoMessage,
754 h),
755 GNUNET_MQ_hd_fixed_size(disconnect,
756 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT,
757 struct DisconnectInfoMessage,
753 h), 758 h),
754 GNUNET_MQ_hd_fixed_size (connect, 759 GNUNET_MQ_hd_fixed_size(send_ok,
755 GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, 760 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK,
756 struct ConnectInfoMessage, 761 struct SendOkMessage,
757 h),
758 GNUNET_MQ_hd_fixed_size (disconnect,
759 GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT,
760 struct DisconnectInfoMessage,
761 h),
762 GNUNET_MQ_hd_fixed_size (send_ok,
763 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK,
764 struct SendOkMessage,
765 h),
766 GNUNET_MQ_hd_var_size (recv,
767 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV,
768 struct InboundMessage,
769 h), 762 h),
770 GNUNET_MQ_hd_fixed_size (set_quota, 763 GNUNET_MQ_hd_var_size(recv,
771 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, 764 GNUNET_MESSAGE_TYPE_TRANSPORT_RECV,
772 struct QuotaSetMessage, 765 struct InboundMessage,
773 h), 766 h),
774 GNUNET_MQ_handler_end ()}; 767 GNUNET_MQ_hd_fixed_size(set_quota,
768 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA,
769 struct QuotaSetMessage,
770 h),
771 GNUNET_MQ_handler_end() };
775 struct GNUNET_MQ_Envelope *env; 772 struct GNUNET_MQ_Envelope *env;
776 struct StartMessage *s; 773 struct StartMessage *s;
777 uint32_t options; 774 uint32_t options;
778 775
779 h->reconnect_task = NULL; 776 h->reconnect_task = NULL;
780 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n"); 777 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
781 GNUNET_assert (NULL == h->mq); 778 GNUNET_assert(NULL == h->mq);
782 h->mq = 779 h->mq =
783 GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h); 780 GNUNET_CLIENT_connect(h->cfg, "transport", handlers, &mq_error_handler, h);
784 if (NULL == h->mq) 781 if (NULL == h->mq)
785 return; 782 return;
786 env = GNUNET_MQ_msg (s, GNUNET_MESSAGE_TYPE_TRANSPORT_START); 783 env = GNUNET_MQ_msg(s, GNUNET_MESSAGE_TYPE_TRANSPORT_START);
787 options = 0; 784 options = 0;
788 if (h->check_self) 785 if (h->check_self)
789 options |= 1; 786 options |= 1;
790 if (NULL != h->handlers) 787 if (NULL != h->handlers)
791 options |= 2; 788 options |= 2;
792 s->options = htonl (options); 789 s->options = htonl(options);
793 s->self = h->self; 790 s->self = h->self;
794 GNUNET_MQ_send (h->mq, env); 791 GNUNET_MQ_send(h->mq, env);
795} 792}
796 793
797 794
@@ -802,22 +799,22 @@ reconnect (void *cls)
802 * @param h transport service to reconnect 799 * @param h transport service to reconnect
803 */ 800 */
804static void 801static void
805disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h) 802disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
806{ 803{
807 GNUNET_assert (NULL == h->reconnect_task); 804 GNUNET_assert(NULL == h->reconnect_task);
808 /* Forget about all neighbours that we used to be connected to */ 805 /* Forget about all neighbours that we used to be connected to */
809 GNUNET_CONTAINER_multipeermap_iterate (h->neighbours, &neighbour_delete, h); 806 GNUNET_CONTAINER_multipeermap_iterate(h->neighbours, &neighbour_delete, h);
810 if (NULL != h->mq) 807 if (NULL != h->mq)
811 { 808 {
812 GNUNET_MQ_destroy (h->mq); 809 GNUNET_MQ_destroy(h->mq);
813 h->mq = NULL; 810 h->mq = NULL;
814 } 811 }
815 LOG (GNUNET_ERROR_TYPE_DEBUG, 812 LOG(GNUNET_ERROR_TYPE_DEBUG,
816 "Scheduling task to reconnect to transport service in %s.\n", 813 "Scheduling task to reconnect to transport service in %s.\n",
817 GNUNET_STRINGS_relative_time_to_string (h->reconnect_delay, GNUNET_YES)); 814 GNUNET_STRINGS_relative_time_to_string(h->reconnect_delay, GNUNET_YES));
818 h->reconnect_task = 815 h->reconnect_task =
819 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h); 816 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay, &reconnect, h);
820 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 817 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay);
821} 818}
822 819
823 820
@@ -829,12 +826,12 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
829 * @return NULL if disconnected, otherwise message queue for @a peer 826 * @return NULL if disconnected, otherwise message queue for @a peer
830 */ 827 */
831struct GNUNET_MQ_Handle * 828struct GNUNET_MQ_Handle *
832GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, 829GNUNET_TRANSPORT_core_get_mq(struct GNUNET_TRANSPORT_CoreHandle *handle,
833 const struct GNUNET_PeerIdentity *peer) 830 const struct GNUNET_PeerIdentity *peer)
834{ 831{
835 struct Neighbour *n; 832 struct Neighbour *n;
836 833
837 n = neighbour_find (handle, peer); 834 n = neighbour_find(handle, peer);
838 if (NULL == n) 835 if (NULL == n)
839 return NULL; 836 return NULL;
840 return n->mq; 837 return n->mq;
@@ -856,23 +853,23 @@ GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
856 * @return NULL on error 853 * @return NULL on error
857 */ 854 */
858struct GNUNET_TRANSPORT_CoreHandle * 855struct GNUNET_TRANSPORT_CoreHandle *
859GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 856GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
860 const struct GNUNET_PeerIdentity *self, 857 const struct GNUNET_PeerIdentity *self,
861 const struct GNUNET_MQ_MessageHandler *handlers, 858 const struct GNUNET_MQ_MessageHandler *handlers,
862 void *cls, 859 void *cls,
863 GNUNET_TRANSPORT_NotifyConnect nc, 860 GNUNET_TRANSPORT_NotifyConnect nc,
864 GNUNET_TRANSPORT_NotifyDisconnect nd, 861 GNUNET_TRANSPORT_NotifyDisconnect nd,
865 GNUNET_TRANSPORT_NotifyExcessBandwidth neb) 862 GNUNET_TRANSPORT_NotifyExcessBandwidth neb)
866{ 863{
867 struct GNUNET_TRANSPORT_CoreHandle *h; 864 struct GNUNET_TRANSPORT_CoreHandle *h;
868 unsigned int i; 865 unsigned int i;
869 866
870 h = GNUNET_new (struct GNUNET_TRANSPORT_CoreHandle); 867 h = GNUNET_new(struct GNUNET_TRANSPORT_CoreHandle);
871 if (NULL != self) 868 if (NULL != self)
872 { 869 {
873 h->self = *self; 870 h->self = *self;
874 h->check_self = GNUNET_YES; 871 h->check_self = GNUNET_YES;
875 } 872 }
876 h->cfg = cfg; 873 h->cfg = cfg;
877 h->cls = cls; 874 h->cls = cls;
878 h->nc_cb = nc; 875 h->nc_cb = nc;
@@ -880,24 +877,24 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
880 h->neb_cb = neb; 877 h->neb_cb = neb;
881 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO; 878 h->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
882 if (NULL != handlers) 879 if (NULL != handlers)
883 { 880 {
884 for (i = 0; NULL != handlers[i].cb; i++) 881 for (i = 0; NULL != handlers[i].cb; i++)
885 ; 882 ;
886 h->handlers = GNUNET_new_array (i + 1, struct GNUNET_MQ_MessageHandler); 883 h->handlers = GNUNET_new_array(i + 1, struct GNUNET_MQ_MessageHandler);
887 GNUNET_memcpy (h->handlers, 884 GNUNET_memcpy(h->handlers,
888 handlers, 885 handlers,
889 i * sizeof (struct GNUNET_MQ_MessageHandler)); 886 i * sizeof(struct GNUNET_MQ_MessageHandler));
890 } 887 }
891 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n"); 888 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service\n");
892 reconnect (h); 889 reconnect(h);
893 if (NULL == h->mq) 890 if (NULL == h->mq)
894 { 891 {
895 GNUNET_free_non_null (h->handlers); 892 GNUNET_free_non_null(h->handlers);
896 GNUNET_free (h); 893 GNUNET_free(h);
897 return NULL; 894 return NULL;
898 } 895 }
899 h->neighbours = 896 h->neighbours =
900 GNUNET_CONTAINER_multipeermap_create (STARTING_NEIGHBOURS_SIZE, GNUNET_YES); 897 GNUNET_CONTAINER_multipeermap_create(STARTING_NEIGHBOURS_SIZE, GNUNET_YES);
901 return h; 898 return h;
902} 899}
903 900
@@ -909,23 +906,23 @@ GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
909 * #GNUNET_TRANSPORT_core_connect() 906 * #GNUNET_TRANSPORT_core_connect()
910 */ 907 */
911void 908void
912GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle) 909GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
913{ 910{
914 LOG (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n"); 911 LOG(GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
915 /* this disconnects all neighbours... */ 912 /* this disconnects all neighbours... */
916 if (NULL == handle->reconnect_task) 913 if (NULL == handle->reconnect_task)
917 disconnect_and_schedule_reconnect (handle); 914 disconnect_and_schedule_reconnect(handle);
918 /* and now we stop trying to connect again... */ 915 /* and now we stop trying to connect again... */
919 if (NULL != handle->reconnect_task) 916 if (NULL != handle->reconnect_task)
920 { 917 {
921 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 918 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
922 handle->reconnect_task = NULL; 919 handle->reconnect_task = NULL;
923 } 920 }
924 GNUNET_CONTAINER_multipeermap_destroy (handle->neighbours); 921 GNUNET_CONTAINER_multipeermap_destroy(handle->neighbours);
925 handle->neighbours = NULL; 922 handle->neighbours = NULL;
926 GNUNET_free_non_null (handle->handlers); 923 GNUNET_free_non_null(handle->handlers);
927 handle->handlers = NULL; 924 handle->handlers = NULL;
928 GNUNET_free (handle); 925 GNUNET_free(handle);
929} 926}
930 927
931 928
@@ -950,18 +947,18 @@ GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle)
950 * @param pid which peer was the message from that was fully processed by CORE 947 * @param pid which peer was the message from that was fully processed by CORE
951 */ 948 */
952void 949void
953GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch, 950GNUNET_TRANSPORT_core_receive_continue(struct GNUNET_TRANSPORT_CoreHandle *ch,
954 const struct GNUNET_PeerIdentity *pid) 951 const struct GNUNET_PeerIdentity *pid)
955{ 952{
956 struct RecvOkMessage *rom; 953 struct RecvOkMessage *rom;
957 struct GNUNET_MQ_Envelope *env; 954 struct GNUNET_MQ_Envelope *env;
958 955
959 GNUNET_assert (ch->rom_pending > 0); 956 GNUNET_assert(ch->rom_pending > 0);
960 ch->rom_pending--; 957 ch->rom_pending--;
961 env = GNUNET_MQ_msg (rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK); 958 env = GNUNET_MQ_msg(rom, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV_OK);
962 rom->increase_window_delta = htonl (1); 959 rom->increase_window_delta = htonl(1);
963 rom->peer = *pid; 960 rom->peer = *pid;
964 GNUNET_MQ_send (ch->mq, env); 961 GNUNET_MQ_send(ch->mq, env);
965} 962}
966 963
967 964
diff --git a/src/transport/transport_api_hello_get.c b/src/transport/transport_api_hello_get.c
index a4d55b430..0f53148af 100644
--- a/src/transport/transport_api_hello_get.c
+++ b/src/transport/transport_api_hello_get.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_hello_get.c 22 * @file transport/transport_api_hello_get.c
@@ -36,9 +36,7 @@
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{
41
42 /** 40 /**
43 * Our configuration. 41 * Our configuration.
44 */ 42 */
@@ -89,22 +87,22 @@ struct GNUNET_TRANSPORT_HelloGetHandle
89 * @return #GNUNET_OK if message is well-formed 87 * @return #GNUNET_OK if message is well-formed
90 */ 88 */
91static int 89static int
92check_hello (void *cls, 90check_hello(void *cls,
93 const struct GNUNET_MessageHeader *msg) 91 const struct GNUNET_MessageHeader *msg)
94{ 92{
95 struct GNUNET_PeerIdentity me; 93 struct GNUNET_PeerIdentity me;
96 94
97 if (GNUNET_OK != 95 if (GNUNET_OK !=
98 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, 96 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)msg,
99 &me)) 97 &me))
100 { 98 {
101 GNUNET_break (0); 99 GNUNET_break(0);
102 return GNUNET_SYSERR; 100 return GNUNET_SYSERR;
103 } 101 }
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 102 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
105 "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n", 103 "Receiving (my own) HELLO message (%u bytes), I am `%s'.\n",
106 (unsigned int) ntohs (msg->size), 104 (unsigned int)ntohs(msg->size),
107 GNUNET_i2s (&me)); 105 GNUNET_i2s(&me));
108 return GNUNET_OK; 106 return GNUNET_OK;
109} 107}
110 108
@@ -116,13 +114,13 @@ check_hello (void *cls,
116 * @param msg message received 114 * @param msg message received
117 */ 115 */
118static void 116static void
119handle_hello (void *cls, 117handle_hello(void *cls,
120 const struct GNUNET_MessageHeader *msg) 118 const struct GNUNET_MessageHeader *msg)
121{ 119{
122 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; 120 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
123 121
124 ghh->rec (ghh->rec_cls, 122 ghh->rec(ghh->rec_cls,
125 msg); 123 msg);
126} 124}
127 125
128 126
@@ -133,7 +131,7 @@ handle_hello (void *cls,
133 * @param ghh transport service to reconnect 131 * @param ghh transport service to reconnect
134 */ 132 */
135static void 133static void
136schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh); 134schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
137 135
138 136
139/** 137/**
@@ -146,16 +144,16 @@ schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh);
146 * @param error error code 144 * @param error error code
147 */ 145 */
148static void 146static void
149mq_error_handler (void *cls, 147mq_error_handler(void *cls,
150 enum GNUNET_MQ_Error error) 148 enum GNUNET_MQ_Error error)
151{ 149{
152 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; 150 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
153 151
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 152 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
155 "Error receiving from transport service, disconnecting temporarily.\n"); 153 "Error receiving from transport service, disconnecting temporarily.\n");
156 GNUNET_MQ_destroy (ghh->mq); 154 GNUNET_MQ_destroy(ghh->mq);
157 ghh->mq = NULL; 155 ghh->mq = NULL;
158 schedule_reconnect (ghh); 156 schedule_reconnect(ghh);
159} 157}
160 158
161 159
@@ -165,35 +163,35 @@ mq_error_handler (void *cls,
165 * @param cls the handle to the transport service 163 * @param cls the handle to the transport service
166 */ 164 */
167static void 165static void
168reconnect (void *cls) 166reconnect(void *cls)
169{ 167{
170 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls; 168 struct GNUNET_TRANSPORT_HelloGetHandle *ghh = cls;
171 struct GNUNET_MQ_MessageHandler handlers[] = { 169 struct GNUNET_MQ_MessageHandler handlers[] = {
172 GNUNET_MQ_hd_var_size (hello, 170 GNUNET_MQ_hd_var_size(hello,
173 GNUNET_MESSAGE_TYPE_HELLO, 171 GNUNET_MESSAGE_TYPE_HELLO,
174 struct GNUNET_MessageHeader, 172 struct GNUNET_MessageHeader,
175 ghh), 173 ghh),
176 GNUNET_MQ_handler_end () 174 GNUNET_MQ_handler_end()
177 }; 175 };
178 struct GNUNET_MQ_Envelope *env; 176 struct GNUNET_MQ_Envelope *env;
179 struct StartMessage *s; 177 struct StartMessage *s;
180 178
181 ghh->reconnect_task = NULL; 179 ghh->reconnect_task = NULL;
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
183 "Connecting to transport service.\n"); 181 "Connecting to transport service.\n");
184 GNUNET_assert (NULL == ghh->mq); 182 GNUNET_assert(NULL == ghh->mq);
185 ghh->mq = GNUNET_CLIENT_connect (ghh->cfg, 183 ghh->mq = GNUNET_CLIENT_connect(ghh->cfg,
186 "transport", 184 "transport",
187 handlers, 185 handlers,
188 &mq_error_handler, 186 &mq_error_handler,
189 ghh); 187 ghh);
190 if (NULL == ghh->mq) 188 if (NULL == ghh->mq)
191 return; 189 return;
192 env = GNUNET_MQ_msg (s, 190 env = GNUNET_MQ_msg(s,
193 GNUNET_MESSAGE_TYPE_TRANSPORT_START); 191 GNUNET_MESSAGE_TYPE_TRANSPORT_START);
194 s->options = htonl (0); 192 s->options = htonl(0);
195 GNUNET_MQ_send (ghh->mq, 193 GNUNET_MQ_send(ghh->mq,
196 env); 194 env);
197} 195}
198 196
199 197
@@ -204,13 +202,13 @@ reconnect (void *cls)
204 * @param ghh transport service to reconnect 202 * @param ghh transport service to reconnect
205 */ 203 */
206static void 204static void
207schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh) 205schedule_reconnect(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
208{ 206{
209 ghh->reconnect_task = 207 ghh->reconnect_task =
210 GNUNET_SCHEDULER_add_delayed (ghh->reconnect_delay, 208 GNUNET_SCHEDULER_add_delayed(ghh->reconnect_delay,
211 &reconnect, 209 &reconnect,
212 ghh); 210 ghh);
213 ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF (ghh->reconnect_delay); 211 ghh->reconnect_delay = GNUNET_TIME_STD_BACKOFF(ghh->reconnect_delay);
214} 212}
215 213
216 214
@@ -228,24 +226,24 @@ schedule_reconnect (struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
228 * @return handle to cancel the operation 226 * @return handle to cancel the operation
229 */ 227 */
230struct GNUNET_TRANSPORT_HelloGetHandle * 228struct GNUNET_TRANSPORT_HelloGetHandle *
231GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg, 229GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg,
232 enum GNUNET_TRANSPORT_AddressClass ac, 230 enum GNUNET_TRANSPORT_AddressClass ac,
233 GNUNET_TRANSPORT_HelloUpdateCallback rec, 231 GNUNET_TRANSPORT_HelloUpdateCallback rec,
234 void *rec_cls) 232 void *rec_cls)
235{ 233{
236 struct GNUNET_TRANSPORT_HelloGetHandle *ghh; 234 struct GNUNET_TRANSPORT_HelloGetHandle *ghh;
237 235
238 ghh = GNUNET_new (struct GNUNET_TRANSPORT_HelloGetHandle); 236 ghh = GNUNET_new(struct GNUNET_TRANSPORT_HelloGetHandle);
239 ghh->rec = rec; 237 ghh->rec = rec;
240 ghh->rec_cls = rec_cls; 238 ghh->rec_cls = rec_cls;
241 ghh->cfg = cfg; 239 ghh->cfg = cfg;
242 ghh->ac = ac; 240 ghh->ac = ac;
243 reconnect (ghh); 241 reconnect(ghh);
244 if (NULL == ghh->mq) 242 if (NULL == ghh->mq)
245 { 243 {
246 GNUNET_free (ghh); 244 GNUNET_free(ghh);
247 return NULL; 245 return NULL;
248 } 246 }
249 return ghh; 247 return ghh;
250} 248}
251 249
@@ -256,19 +254,19 @@ GNUNET_TRANSPORT_hello_get (const struct GNUNET_CONFIGURATION_Handle *cfg,
256 * @param ghh handle to cancel 254 * @param ghh handle to cancel
257 */ 255 */
258void 256void
259GNUNET_TRANSPORT_hello_get_cancel (struct GNUNET_TRANSPORT_HelloGetHandle *ghh) 257GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
260{ 258{
261 if (NULL != ghh->reconnect_task) 259 if (NULL != ghh->reconnect_task)
262 { 260 {
263 GNUNET_SCHEDULER_cancel (ghh->reconnect_task); 261 GNUNET_SCHEDULER_cancel(ghh->reconnect_task);
264 ghh->reconnect_task = NULL; 262 ghh->reconnect_task = NULL;
265 } 263 }
266 if (NULL != ghh->mq) 264 if (NULL != ghh->mq)
267 { 265 {
268 GNUNET_MQ_destroy (ghh->mq); 266 GNUNET_MQ_destroy(ghh->mq);
269 ghh->mq = NULL; 267 ghh->mq = NULL;
270 } 268 }
271 GNUNET_free (ghh); 269 GNUNET_free(ghh);
272} 270}
273 271
274 272
diff --git a/src/transport/transport_api_manipulation.c b/src/transport/transport_api_manipulation.c
index 8e85a365c..c4bc96aef 100644
--- a/src/transport/transport_api_manipulation.c
+++ b/src/transport/transport_api_manipulation.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_manipulation.c 22 * @file transport/transport_api_manipulation.c
@@ -32,16 +32,14 @@
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{
44
45 /** 43 /**
46 * My client connection to the transport service. 44 * My client connection to the transport service.
47 */ 45 */
@@ -76,7 +74,7 @@ struct GNUNET_TRANSPORT_ManipulationHandle
76 * @param h transport service to reconnect 74 * @param h transport service to reconnect
77 */ 75 */
78static void 76static void
79disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h); 77disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h);
80 78
81 79
82/** 80/**
@@ -89,15 +87,15 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h
89 * @param error error code 87 * @param error error code
90 */ 88 */
91static void 89static void
92mq_error_handler (void *cls, 90mq_error_handler(void *cls,
93 enum GNUNET_MQ_Error error) 91 enum GNUNET_MQ_Error error)
94{ 92{
95 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; 93 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls;
96 94
97 LOG (GNUNET_ERROR_TYPE_DEBUG, 95 LOG(GNUNET_ERROR_TYPE_DEBUG,
98 "Error receiving from transport service, disconnecting temporarily.\n"); 96 "Error receiving from transport service, disconnecting temporarily.\n");
99 h->reconnecting = GNUNET_YES; 97 h->reconnecting = GNUNET_YES;
100 disconnect_and_schedule_reconnect (h); 98 disconnect_and_schedule_reconnect(h);
101} 99}
102 100
103 101
@@ -107,31 +105,31 @@ mq_error_handler (void *cls,
107 * @param cls the handle to the transport service 105 * @param cls the handle to the transport service
108 */ 106 */
109static void 107static void
110reconnect (void *cls) 108reconnect(void *cls)
111{ 109{
112 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls; 110 struct GNUNET_TRANSPORT_ManipulationHandle *h = cls;
113 struct GNUNET_MQ_MessageHandler handlers[] = { 111 struct GNUNET_MQ_MessageHandler handlers[] = {
114 GNUNET_MQ_handler_end () 112 GNUNET_MQ_handler_end()
115 }; 113 };
116 struct GNUNET_MQ_Envelope *env; 114 struct GNUNET_MQ_Envelope *env;
117 struct StartMessage *s; 115 struct StartMessage *s;
118 116
119 h->reconnect_task = NULL; 117 h->reconnect_task = NULL;
120 LOG (GNUNET_ERROR_TYPE_DEBUG, 118 LOG(GNUNET_ERROR_TYPE_DEBUG,
121 "Connecting to transport service.\n"); 119 "Connecting to transport service.\n");
122 GNUNET_assert (NULL == h->mq); 120 GNUNET_assert(NULL == h->mq);
123 h->reconnecting = GNUNET_NO; 121 h->reconnecting = GNUNET_NO;
124 h->mq = GNUNET_CLIENT_connect (h->cfg, 122 h->mq = GNUNET_CLIENT_connect(h->cfg,
125 "transport", 123 "transport",
126 handlers, 124 handlers,
127 &mq_error_handler, 125 &mq_error_handler,
128 h); 126 h);
129 if (NULL == h->mq) 127 if (NULL == h->mq)
130 return; 128 return;
131 env = GNUNET_MQ_msg (s, 129 env = GNUNET_MQ_msg(s,
132 GNUNET_MESSAGE_TYPE_TRANSPORT_START); 130 GNUNET_MESSAGE_TYPE_TRANSPORT_START);
133 GNUNET_MQ_send (h->mq, 131 GNUNET_MQ_send(h->mq,
134 env); 132 env);
135} 133}
136 134
137 135
@@ -142,19 +140,19 @@ reconnect (void *cls)
142 * @param h transport service to reconnect 140 * @param h transport service to reconnect
143 */ 141 */
144static void 142static void
145disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h) 143disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_ManipulationHandle *h)
146{ 144{
147 GNUNET_assert (NULL == h->reconnect_task); 145 GNUNET_assert(NULL == h->reconnect_task);
148 if (NULL != h->mq) 146 if (NULL != h->mq)
149 { 147 {
150 GNUNET_MQ_destroy (h->mq); 148 GNUNET_MQ_destroy(h->mq);
151 h->mq = NULL; 149 h->mq = NULL;
152 } 150 }
153 h->reconnect_task = 151 h->reconnect_task =
154 GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, 152 GNUNET_SCHEDULER_add_delayed(h->reconnect_delay,
155 &reconnect, 153 &reconnect,
156 h); 154 h);
157 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF (h->reconnect_delay); 155 h->reconnect_delay = GNUNET_TIME_STD_BACKOFF(h->reconnect_delay);
158} 156}
159 157
160 158
@@ -171,27 +169,27 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_ManipulationHandle *h
171 * with one message delay. 169 * with one message delay.
172 */ 170 */
173void 171void
174GNUNET_TRANSPORT_manipulation_set (struct GNUNET_TRANSPORT_ManipulationHandle *handle, 172GNUNET_TRANSPORT_manipulation_set(struct GNUNET_TRANSPORT_ManipulationHandle *handle,
175 const struct GNUNET_PeerIdentity *peer, 173 const struct GNUNET_PeerIdentity *peer,
176 const struct GNUNET_ATS_Properties *prop, 174 const struct GNUNET_ATS_Properties *prop,
177 struct GNUNET_TIME_Relative delay_in, 175 struct GNUNET_TIME_Relative delay_in,
178 struct GNUNET_TIME_Relative delay_out) 176 struct GNUNET_TIME_Relative delay_out)
179{ 177{
180 struct GNUNET_MQ_Envelope *env; 178 struct GNUNET_MQ_Envelope *env;
181 struct TrafficMetricMessage *msg; 179 struct TrafficMetricMessage *msg;
182 180
183 if (NULL == handle->mq) 181 if (NULL == handle->mq)
184 return; 182 return;
185 env = GNUNET_MQ_msg (msg, 183 env = GNUNET_MQ_msg(msg,
186 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); 184 GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC);
187 msg->reserved = htonl (0); 185 msg->reserved = htonl(0);
188 msg->peer = *peer; 186 msg->peer = *peer;
189 GNUNET_ATS_properties_hton (&msg->properties, 187 GNUNET_ATS_properties_hton(&msg->properties,
190 prop); 188 prop);
191 msg->delay_in = GNUNET_TIME_relative_hton (delay_in); 189 msg->delay_in = GNUNET_TIME_relative_hton(delay_in);
192 msg->delay_out = GNUNET_TIME_relative_hton (delay_out); 190 msg->delay_out = GNUNET_TIME_relative_hton(delay_out);
193 GNUNET_MQ_send (handle->mq, 191 GNUNET_MQ_send(handle->mq,
194 env); 192 env);
195} 193}
196 194
197 195
@@ -203,20 +201,20 @@ GNUNET_TRANSPORT_manipulation_set (struct GNUNET_TRANSPORT_ManipulationHandle *h
203 * @return NULL on error 201 * @return NULL on error
204 */ 202 */
205struct GNUNET_TRANSPORT_ManipulationHandle * 203struct GNUNET_TRANSPORT_ManipulationHandle *
206GNUNET_TRANSPORT_manipulation_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 204GNUNET_TRANSPORT_manipulation_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
207{ 205{
208 struct GNUNET_TRANSPORT_ManipulationHandle *h; 206 struct GNUNET_TRANSPORT_ManipulationHandle *h;
209 207
210 h = GNUNET_new (struct GNUNET_TRANSPORT_ManipulationHandle); 208 h = GNUNET_new(struct GNUNET_TRANSPORT_ManipulationHandle);
211 h->cfg = cfg; 209 h->cfg = cfg;
212 LOG (GNUNET_ERROR_TYPE_DEBUG, 210 LOG(GNUNET_ERROR_TYPE_DEBUG,
213 "Connecting to transport service.\n"); 211 "Connecting to transport service.\n");
214 reconnect (h); 212 reconnect(h);
215 if (NULL == h->mq) 213 if (NULL == h->mq)
216 { 214 {
217 GNUNET_free (h); 215 GNUNET_free(h);
218 return NULL; 216 return NULL;
219 } 217 }
220 return h; 218 return h;
221} 219}
222 220
@@ -227,17 +225,17 @@ GNUNET_TRANSPORT_manipulation_connect (const struct GNUNET_CONFIGURATION_Handle
227 * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect() 225 * @param handle handle to the service as returned from #GNUNET_TRANSPORT_manipulation_connect()
228 */ 226 */
229void 227void
230GNUNET_TRANSPORT_manipulation_disconnect (struct GNUNET_TRANSPORT_ManipulationHandle *handle) 228GNUNET_TRANSPORT_manipulation_disconnect(struct GNUNET_TRANSPORT_ManipulationHandle *handle)
231{ 229{
232 if (NULL == handle->reconnect_task) 230 if (NULL == handle->reconnect_task)
233 disconnect_and_schedule_reconnect (handle); 231 disconnect_and_schedule_reconnect(handle);
234 /* and now we stop trying to connect again... */ 232 /* and now we stop trying to connect again... */
235 if (NULL != handle->reconnect_task) 233 if (NULL != handle->reconnect_task)
236 { 234 {
237 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 235 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
238 handle->reconnect_task = NULL; 236 handle->reconnect_task = NULL;
239 } 237 }
240 GNUNET_free (handle); 238 GNUNET_free(handle);
241} 239}
242 240
243 241
diff --git a/src/transport/transport_api_monitor_peers.c b/src/transport/transport_api_monitor_peers.c
index ce4d9ae9e..44127eb7e 100644
--- a/src/transport/transport_api_monitor_peers.c
+++ b/src/transport/transport_api_monitor_peers.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_monitor_peers.c 22 * @file transport/transport_api_monitor_peers.c
@@ -39,8 +39,7 @@
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{
44 /** 43 /**
45 * Function to call with the binary address. 44 * Function to call with the binary address.
46 */ 45 */
@@ -90,31 +89,34 @@ struct GNUNET_TRANSPORT_PeerMonitoringContext
90 * @return #GNUNET_YES or #GNUNET_NO 89 * @return #GNUNET_YES or #GNUNET_NO
91 */ 90 */
92int 91int
93GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state) 92GNUNET_TRANSPORT_is_connected(enum GNUNET_TRANSPORT_PeerState state)
94{ 93{
95 switch (state) 94 switch (state)
96 { 95 {
97 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 96 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
98 case GNUNET_TRANSPORT_PS_INIT_ATS: 97 case GNUNET_TRANSPORT_PS_INIT_ATS:
99 case GNUNET_TRANSPORT_PS_SYN_SENT: 98 case GNUNET_TRANSPORT_PS_SYN_SENT:
100 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 99 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
101 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 100 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
102 return GNUNET_NO; 101 return GNUNET_NO;
103 case GNUNET_TRANSPORT_PS_CONNECTED: 102
104 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 103 case GNUNET_TRANSPORT_PS_CONNECTED:
105 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 104 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
106 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 105 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
107 return GNUNET_YES; 106 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
108 case GNUNET_TRANSPORT_PS_DISCONNECT: 107 return GNUNET_YES;
109 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 108
110 return GNUNET_NO; 109 case GNUNET_TRANSPORT_PS_DISCONNECT:
111 default: 110 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 111 return GNUNET_NO;
113 "Unhandled state `%s'\n", 112
114 GNUNET_TRANSPORT_ps2s (state)); 113 default:
115 GNUNET_break (0); 114 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
116 break; 115 "Unhandled state `%s'\n",
117 } 116 GNUNET_TRANSPORT_ps2s(state));
117 GNUNET_break(0);
118 break;
119 }
118 return GNUNET_SYSERR; 120 return GNUNET_SYSERR;
119} 121}
120 122
@@ -126,36 +128,47 @@ GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state)
126 * @return corresponding string 128 * @return corresponding string
127 */ 129 */
128const char * 130const char *
129GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state) 131GNUNET_TRANSPORT_ps2s(enum GNUNET_TRANSPORT_PeerState state)
130{ 132{
131 switch (state) 133 switch (state)
132 { 134 {
133 case GNUNET_TRANSPORT_PS_NOT_CONNECTED: 135 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
134 return "S_NOT_CONNECTED"; 136 return "S_NOT_CONNECTED";
135 case GNUNET_TRANSPORT_PS_INIT_ATS: 137
136 return "S_INIT_ATS"; 138 case GNUNET_TRANSPORT_PS_INIT_ATS:
137 case GNUNET_TRANSPORT_PS_SYN_SENT: 139 return "S_INIT_ATS";
138 return "S_SYN_SENT"; 140
139 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS: 141 case GNUNET_TRANSPORT_PS_SYN_SENT:
140 return "S_SYN_RECV_ATS"; 142 return "S_SYN_SENT";
141 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK: 143
142 return "S_SYN_RECV_ACK"; 144 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
143 case GNUNET_TRANSPORT_PS_CONNECTED: 145 return "S_SYN_RECV_ATS";
144 return "S_CONNECTED"; 146
145 case GNUNET_TRANSPORT_PS_RECONNECT_ATS: 147 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
146 return "S_RECONNECT_ATS"; 148 return "S_SYN_RECV_ACK";
147 case GNUNET_TRANSPORT_PS_RECONNECT_SENT: 149
148 return "S_RECONNECT_SENT"; 150 case GNUNET_TRANSPORT_PS_CONNECTED:
149 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT: 151 return "S_CONNECTED";
150 return "S_SWITCH_SYN_SENT"; 152
151 case GNUNET_TRANSPORT_PS_DISCONNECT: 153 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
152 return "S_DISCONNECT"; 154 return "S_RECONNECT_ATS";
153 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED: 155
154 return "S_DISCONNECT_FINISHED"; 156 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
155 default: 157 return "S_RECONNECT_SENT";
156 GNUNET_break (0); 158
157 return "UNDEFINED"; 159 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
158 } 160 return "S_SWITCH_SYN_SENT";
161
162 case GNUNET_TRANSPORT_PS_DISCONNECT:
163 return "S_DISCONNECT";
164
165 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
166 return "S_DISCONNECT_FINISHED";
167
168 default:
169 GNUNET_break(0);
170 return "UNDEFINED";
171 }
159} 172}
160 173
161 174
@@ -165,7 +178,7 @@ GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state)
165 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *` 178 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
166 */ 179 */
167static void 180static void
168do_peer_connect (void *cls); 181do_peer_connect(void *cls);
169 182
170 183
171/** 184/**
@@ -174,20 +187,20 @@ do_peer_connect (void *cls);
174 * @param pal_ctx our context 187 * @param pal_ctx our context
175 */ 188 */
176static void 189static void
177reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx) 190reconnect_peer_ctx(struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
178{ 191{
179 GNUNET_assert (GNUNET_NO == pal_ctx->one_shot); 192 GNUNET_assert(GNUNET_NO == pal_ctx->one_shot);
180 GNUNET_MQ_destroy (pal_ctx->mq); 193 GNUNET_MQ_destroy(pal_ctx->mq);
181 pal_ctx->mq = NULL; 194 pal_ctx->mq = NULL;
182 pal_ctx->cb (pal_ctx->cb_cls, 195 pal_ctx->cb(pal_ctx->cb_cls,
183 NULL, 196 NULL,
184 NULL, 197 NULL,
185 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 198 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
186 GNUNET_TIME_UNIT_ZERO_ABS); 199 GNUNET_TIME_UNIT_ZERO_ABS);
187 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff); 200 pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF(pal_ctx->backoff);
188 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff, 201 pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed(pal_ctx->backoff,
189 &do_peer_connect, 202 &do_peer_connect,
190 pal_ctx); 203 pal_ctx);
191} 204}
192 205
193 206
@@ -198,25 +211,25 @@ reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
198 * @param msg message from service 211 * @param msg message from service
199 */ 212 */
200static void 213static void
201handle_response_end (void *cls, 214handle_response_end(void *cls,
202 const struct GNUNET_MessageHeader *msg) 215 const struct GNUNET_MessageHeader *msg)
203{ 216{
204 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 217 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
205 218
206 if (pal_ctx->one_shot) 219 if (pal_ctx->one_shot)
207 { 220 {
208 /* iteration finished */ 221 /* iteration finished */
209 pal_ctx->cb (pal_ctx->cb_cls, 222 pal_ctx->cb(pal_ctx->cb_cls,
210 NULL, 223 NULL,
211 NULL, 224 NULL,
212 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 225 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
213 GNUNET_TIME_UNIT_ZERO_ABS); 226 GNUNET_TIME_UNIT_ZERO_ABS);
214 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx); 227 GNUNET_TRANSPORT_monitor_peers_cancel(pal_ctx);
215 return; 228 return;
216 } 229 }
217 /* not quite what we expected, reconnect */ 230 /* not quite what we expected, reconnect */
218 GNUNET_break (0); 231 GNUNET_break(0);
219 reconnect_peer_ctx (pal_ctx); 232 reconnect_peer_ctx(pal_ctx);
220} 233}
221 234
222 235
@@ -228,34 +241,34 @@ handle_response_end (void *cls,
228 * @return #GNUNET_OK if @a pir_msg is well-formed 241 * @return #GNUNET_OK if @a pir_msg is well-formed
229 */ 242 */
230static int 243static int
231check_response (void *cls, 244check_response(void *cls,
232 const struct PeerIterateResponseMessage *pir_msg) 245 const struct PeerIterateResponseMessage *pir_msg)
233{ 246{
234 uint16_t size = ntohs (pir_msg->header.size) - sizeof (*pir_msg); 247 uint16_t size = ntohs(pir_msg->header.size) - sizeof(*pir_msg);
235 size_t alen = ntohl (pir_msg->addrlen); 248 size_t alen = ntohl(pir_msg->addrlen);
236 size_t tlen = ntohl (pir_msg->pluginlen); 249 size_t tlen = ntohl(pir_msg->pluginlen);
237 const char *addr; 250 const char *addr;
238 const char *transport_name; 251 const char *transport_name;
239 252
240 if (size != tlen + alen) 253 if (size != tlen + alen)
241 { 254 {
242 GNUNET_break (0); 255 GNUNET_break(0);
243 return GNUNET_SYSERR; 256 return GNUNET_SYSERR;
244 } 257 }
245 if ( (0 == tlen) && (0 == alen) ) 258 if ((0 == tlen) && (0 == alen))
246 return GNUNET_OK; 259 return GNUNET_OK;
247 if (0 == tlen) 260 if (0 == tlen)
248 { 261 {
249 GNUNET_break (0); /* This must not happen: address without plugin */ 262 GNUNET_break(0); /* This must not happen: address without plugin */
250 return GNUNET_SYSERR; 263 return GNUNET_SYSERR;
251 } 264 }
252 addr = (const char *) &pir_msg[1]; 265 addr = (const char *)&pir_msg[1];
253 transport_name = &addr[alen]; 266 transport_name = &addr[alen];
254 if (transport_name[tlen - 1] != '\0') 267 if (transport_name[tlen - 1] != '\0')
255 { 268 {
256 GNUNET_break (0); 269 GNUNET_break(0);
257 return GNUNET_SYSERR; 270 return GNUNET_SYSERR;
258 } 271 }
259 return GNUNET_OK; 272 return GNUNET_OK;
260} 273}
261 274
@@ -267,42 +280,42 @@ check_response (void *cls,
267 * @param msg message with the human-readable address 280 * @param msg message with the human-readable address
268 */ 281 */
269static void 282static void
270handle_response (void *cls, 283handle_response(void *cls,
271 const struct PeerIterateResponseMessage *pir_msg) 284 const struct PeerIterateResponseMessage *pir_msg)
272{ 285{
273 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 286 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
274 struct GNUNET_HELLO_Address *address; 287 struct GNUNET_HELLO_Address *address;
275 size_t alen = ntohl (pir_msg->addrlen); 288 size_t alen = ntohl(pir_msg->addrlen);
276 size_t tlen = ntohl (pir_msg->pluginlen); 289 size_t tlen = ntohl(pir_msg->pluginlen);
277 const char *addr; 290 const char *addr;
278 const char *transport_name; 291 const char *transport_name;
279 292
280 if ( (0 == tlen) && 293 if ((0 == tlen) &&
281 (0 == alen) ) 294 (0 == alen))
282 { 295 {
283 /* No address available */ 296 /* No address available */
284 pal_ctx->cb (pal_ctx->cb_cls, 297 pal_ctx->cb(pal_ctx->cb_cls,
285 &pir_msg->peer, 298 &pir_msg->peer,
286 NULL, 299 NULL,
287 ntohl(pir_msg->state), 300 ntohl(pir_msg->state),
288 GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); 301 GNUNET_TIME_absolute_ntoh(pir_msg->state_timeout));
289 return; 302 return;
290 } 303 }
291 addr = (const char *) &pir_msg[1]; 304 addr = (const char *)&pir_msg[1];
292 transport_name = &addr[alen]; 305 transport_name = &addr[alen];
293 306
294 /* notify client */ 307 /* notify client */
295 address = GNUNET_HELLO_address_allocate (&pir_msg->peer, 308 address = GNUNET_HELLO_address_allocate(&pir_msg->peer,
296 transport_name, 309 transport_name,
297 addr, 310 addr,
298 alen, 311 alen,
299 ntohl (pir_msg->local_address_info)); 312 ntohl(pir_msg->local_address_info));
300 pal_ctx->cb (pal_ctx->cb_cls, 313 pal_ctx->cb(pal_ctx->cb_cls,
301 &pir_msg->peer, 314 &pir_msg->peer,
302 address, 315 address,
303 ntohl (pir_msg->state), 316 ntohl(pir_msg->state),
304 GNUNET_TIME_absolute_ntoh (pir_msg->state_timeout)); 317 GNUNET_TIME_absolute_ntoh(pir_msg->state_timeout));
305 GNUNET_HELLO_address_free (address); 318 GNUNET_HELLO_address_free(address);
306} 319}
307 320
308 321
@@ -316,23 +329,23 @@ handle_response (void *cls,
316 * @param error error code 329 * @param error error code
317 */ 330 */
318static void 331static void
319mq_error_handler (void *cls, 332mq_error_handler(void *cls,
320 enum GNUNET_MQ_Error error) 333 enum GNUNET_MQ_Error error)
321{ 334{
322 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 335 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
323 336
324 if (pal_ctx->one_shot) 337 if (pal_ctx->one_shot)
325 { 338 {
326 /* Disconnect */ 339 /* Disconnect */
327 pal_ctx->cb (pal_ctx->cb_cls, 340 pal_ctx->cb(pal_ctx->cb_cls,
328 NULL, 341 NULL,
329 NULL, 342 NULL,
330 GNUNET_TRANSPORT_PS_NOT_CONNECTED, 343 GNUNET_TRANSPORT_PS_NOT_CONNECTED,
331 GNUNET_TIME_UNIT_ZERO_ABS); 344 GNUNET_TIME_UNIT_ZERO_ABS);
332 GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx); 345 GNUNET_TRANSPORT_monitor_peers_cancel(pal_ctx);
333 return; 346 return;
334 } 347 }
335 reconnect_peer_ctx (pal_ctx); 348 reconnect_peer_ctx(pal_ctx);
336} 349}
337 350
338 351
@@ -342,37 +355,37 @@ mq_error_handler (void *cls,
342 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *` 355 * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
343 */ 356 */
344static void 357static void
345do_peer_connect (void *cls) 358do_peer_connect(void *cls)
346{ 359{
347 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls; 360 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
348 struct GNUNET_MQ_MessageHandler handlers[] = { 361 struct GNUNET_MQ_MessageHandler handlers[] = {
349 GNUNET_MQ_hd_var_size (response, 362 GNUNET_MQ_hd_var_size(response,
350 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE, 363 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE,
351 struct PeerIterateResponseMessage, 364 struct PeerIterateResponseMessage,
352 pal_ctx), 365 pal_ctx),
353 GNUNET_MQ_hd_fixed_size (response_end, 366 GNUNET_MQ_hd_fixed_size(response_end,
354 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END, 367 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_RESPONSE_END,
355 struct GNUNET_MessageHeader, 368 struct GNUNET_MessageHeader,
356 pal_ctx), 369 pal_ctx),
357 GNUNET_MQ_handler_end () 370 GNUNET_MQ_handler_end()
358 }; 371 };
359 struct PeerMonitorMessage *msg; 372 struct PeerMonitorMessage *msg;
360 struct GNUNET_MQ_Envelope *env; 373 struct GNUNET_MQ_Envelope *env;
361 374
362 pal_ctx->reconnect_task = NULL; 375 pal_ctx->reconnect_task = NULL;
363 pal_ctx->mq = GNUNET_CLIENT_connect (pal_ctx->cfg, 376 pal_ctx->mq = GNUNET_CLIENT_connect(pal_ctx->cfg,
364 "transport", 377 "transport",
365 handlers, 378 handlers,
366 &mq_error_handler, 379 &mq_error_handler,
367 pal_ctx); 380 pal_ctx);
368 if (NULL == pal_ctx->mq) 381 if (NULL == pal_ctx->mq)
369 return; 382 return;
370 env = GNUNET_MQ_msg (msg, 383 env = GNUNET_MQ_msg(msg,
371 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST); 384 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PEER_REQUEST);
372 msg->one_shot = htonl (pal_ctx->one_shot); 385 msg->one_shot = htonl(pal_ctx->one_shot);
373 msg->peer = pal_ctx->peer; 386 msg->peer = pal_ctx->peer;
374 GNUNET_MQ_send (pal_ctx->mq, 387 GNUNET_MQ_send(pal_ctx->mq,
375 env); 388 env);
376} 389}
377 390
378 391
@@ -403,14 +416,14 @@ do_peer_connect (void *cls)
403 * @param peer_callback_cls closure for @a peer_address_callback 416 * @param peer_callback_cls closure for @a peer_address_callback
404 */ 417 */
405struct GNUNET_TRANSPORT_PeerMonitoringContext * 418struct GNUNET_TRANSPORT_PeerMonitoringContext *
406GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg, 419GNUNET_TRANSPORT_monitor_peers(const struct GNUNET_CONFIGURATION_Handle *cfg,
407 const struct GNUNET_PeerIdentity *peer, 420 const struct GNUNET_PeerIdentity *peer,
408 int one_shot, 421 int one_shot,
409 GNUNET_TRANSPORT_PeerIterateCallback peer_callback, 422 GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
410 void *peer_callback_cls) 423 void *peer_callback_cls)
411{ 424{
412 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx 425 struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx
413 = GNUNET_new (struct GNUNET_TRANSPORT_PeerMonitoringContext); 426 = GNUNET_new(struct GNUNET_TRANSPORT_PeerMonitoringContext);
414 427
415 pal_ctx->cb = peer_callback; 428 pal_ctx->cb = peer_callback;
416 pal_ctx->cb_cls = peer_callback_cls; 429 pal_ctx->cb_cls = peer_callback_cls;
@@ -418,12 +431,12 @@ GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
418 if (NULL != peer) 431 if (NULL != peer)
419 pal_ctx->peer = *peer; 432 pal_ctx->peer = *peer;
420 pal_ctx->one_shot = one_shot; 433 pal_ctx->one_shot = one_shot;
421 do_peer_connect (pal_ctx); 434 do_peer_connect(pal_ctx);
422 if (NULL == pal_ctx->mq) 435 if (NULL == pal_ctx->mq)
423 { 436 {
424 GNUNET_free (pal_ctx); 437 GNUNET_free(pal_ctx);
425 return NULL; 438 return NULL;
426 } 439 }
427 return pal_ctx; 440 return pal_ctx;
428} 441}
429 442
@@ -434,19 +447,19 @@ GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
434 * @param pic handle for the request to cancel 447 * @param pic handle for the request to cancel
435 */ 448 */
436void 449void
437GNUNET_TRANSPORT_monitor_peers_cancel (struct GNUNET_TRANSPORT_PeerMonitoringContext *pic) 450GNUNET_TRANSPORT_monitor_peers_cancel(struct GNUNET_TRANSPORT_PeerMonitoringContext *pic)
438{ 451{
439 if (NULL != pic->mq) 452 if (NULL != pic->mq)
440 { 453 {
441 GNUNET_MQ_destroy (pic->mq); 454 GNUNET_MQ_destroy(pic->mq);
442 pic->mq = NULL; 455 pic->mq = NULL;
443 } 456 }
444 if (NULL != pic->reconnect_task) 457 if (NULL != pic->reconnect_task)
445 { 458 {
446 GNUNET_SCHEDULER_cancel (pic->reconnect_task); 459 GNUNET_SCHEDULER_cancel(pic->reconnect_task);
447 pic->reconnect_task = NULL; 460 pic->reconnect_task = NULL;
448 } 461 }
449 GNUNET_free (pic); 462 GNUNET_free(pic);
450} 463}
451 464
452 465
diff --git a/src/transport/transport_api_monitor_plugins.c b/src/transport/transport_api_monitor_plugins.c
index f0acc2408..12d052008 100644
--- a/src/transport/transport_api_monitor_plugins.c
+++ b/src/transport/transport_api_monitor_plugins.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_monitor_plugins.c 22 * @file transport/transport_api_monitor_plugins.c
@@ -35,9 +35,7 @@
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{
40
41 /** 39 /**
42 * Connection to the service. 40 * Connection to the service.
43 */ 41 */
@@ -73,7 +71,6 @@ struct GNUNET_TRANSPORT_PluginMonitor
73 * Task ID for reconnect. 71 * Task ID for reconnect.
74 */ 72 */
75 struct GNUNET_SCHEDULER_Task *reconnect_task; 73 struct GNUNET_SCHEDULER_Task *reconnect_task;
76
77}; 74};
78 75
79 76
@@ -81,8 +78,7 @@ struct GNUNET_TRANSPORT_PluginMonitor
81 * Abstract representation of a plugin's session. 78 * Abstract representation of a plugin's session.
82 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service. 79 * Corresponds to the `struct GNUNET_ATS_Session` within the TRANSPORT service.
83 */ 80 */
84struct GNUNET_TRANSPORT_PluginSession 81struct GNUNET_TRANSPORT_PluginSession {
85{
86 /** 82 /**
87 * Unique session identifier. 83 * Unique session identifier.
88 */ 84 */
@@ -102,7 +98,7 @@ struct GNUNET_TRANSPORT_PluginSession
102 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *` 98 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *`
103 */ 99 */
104static void 100static void
105do_plugin_connect (void *cls); 101do_plugin_connect(void *cls);
106 102
107 103
108/** 104/**
@@ -114,23 +110,23 @@ do_plugin_connect (void *cls);
114 * @return #GNUNET_OK (continue to iterate) 110 * @return #GNUNET_OK (continue to iterate)
115 */ 111 */
116static int 112static int
117free_entry (void *cls, 113free_entry(void *cls,
118 uint32_t key, 114 uint32_t key,
119 void *value) 115 void *value)
120{ 116{
121 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 117 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
122 struct GNUNET_TRANSPORT_PluginSession *ps = value; 118 struct GNUNET_TRANSPORT_PluginSession *ps = value;
123 119
124 pm->cb (pm->cb_cls, 120 pm->cb(pm->cb_cls,
125 ps, 121 ps,
126 &ps->client_ctx, 122 &ps->client_ctx,
127 NULL); 123 NULL);
128 GNUNET_break (GNUNET_YES == 124 GNUNET_break(GNUNET_YES ==
129 GNUNET_CONTAINER_multihashmap32_remove (pm->sessions, 125 GNUNET_CONTAINER_multihashmap32_remove(pm->sessions,
130 key, 126 key,
131 ps)); 127 ps));
132 GNUNET_break (NULL == ps->client_ctx); 128 GNUNET_break(NULL == ps->client_ctx);
133 GNUNET_free (ps); 129 GNUNET_free(ps);
134 return GNUNET_OK; 130 return GNUNET_OK;
135} 131}
136 132
@@ -141,17 +137,17 @@ free_entry (void *cls,
141 * @param pm our context 137 * @param pm our context
142 */ 138 */
143static void 139static void
144reconnect_plugin_ctx (struct GNUNET_TRANSPORT_PluginMonitor *pm) 140reconnect_plugin_ctx(struct GNUNET_TRANSPORT_PluginMonitor *pm)
145{ 141{
146 GNUNET_MQ_destroy (pm->mq); 142 GNUNET_MQ_destroy(pm->mq);
147 pm->mq = NULL; 143 pm->mq = NULL;
148 GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions, 144 GNUNET_CONTAINER_multihashmap32_iterate(pm->sessions,
149 &free_entry, 145 &free_entry,
150 pm); 146 pm);
151 pm->backoff = GNUNET_TIME_STD_BACKOFF (pm->backoff); 147 pm->backoff = GNUNET_TIME_STD_BACKOFF(pm->backoff);
152 pm->reconnect_task = GNUNET_SCHEDULER_add_delayed (pm->backoff, 148 pm->reconnect_task = GNUNET_SCHEDULER_add_delayed(pm->backoff,
153 &do_plugin_connect, 149 &do_plugin_connect,
154 pm); 150 pm);
155} 151}
156 152
157 153
@@ -162,18 +158,16 @@ reconnect_plugin_ctx (struct GNUNET_TRANSPORT_PluginMonitor *pm)
162 * @return 32-bit hash map index 158 * @return 32-bit hash map index
163 */ 159 */
164static uint32_t 160static uint32_t
165wrap_id (uint64_t id) 161wrap_id(uint64_t id)
166{ 162{
167 return ((uint32_t) id) ^ ((uint32_t) (id >> 32)); 163 return ((uint32_t)id) ^ ((uint32_t)(id >> 32));
168} 164}
169 165
170 166
171/** 167/**
172 * Context for #locate_by_id(). 168 * Context for #locate_by_id().
173 */ 169 */
174struct SearchContext 170struct SearchContext {
175{
176
177 /** 171 /**
178 * Result. 172 * Result.
179 */ 173 */
@@ -183,7 +177,6 @@ struct SearchContext
183 * ID to locate. 177 * ID to locate.
184 */ 178 */
185 uint64_t session_id; 179 uint64_t session_id;
186
187}; 180};
188 181
189 182
@@ -196,18 +189,18 @@ struct SearchContext
196 * @return #GNUNET_OK (continue to iterate), or #GNUNET_SYSERR (match found) 189 * @return #GNUNET_OK (continue to iterate), or #GNUNET_SYSERR (match found)
197 */ 190 */
198static int 191static int
199locate_by_id (void *cls, 192locate_by_id(void *cls,
200 uint32_t key, 193 uint32_t key,
201 void *value) 194 void *value)
202{ 195{
203 struct SearchContext *sc = cls; 196 struct SearchContext *sc = cls;
204 struct GNUNET_TRANSPORT_PluginSession *ps = value; 197 struct GNUNET_TRANSPORT_PluginSession *ps = value;
205 198
206 if (sc->session_id == ps->session_id) 199 if (sc->session_id == ps->session_id)
207 { 200 {
208 sc->ps = ps; 201 sc->ps = ps;
209 return GNUNET_SYSERR; 202 return GNUNET_SYSERR;
210 } 203 }
211 return GNUNET_OK; 204 return GNUNET_OK;
212} 205}
213 206
@@ -220,25 +213,25 @@ locate_by_id (void *cls,
220 * @return #GNUNET_Ok if message is well-formed 213 * @return #GNUNET_Ok if message is well-formed
221 */ 214 */
222static int 215static int
223check_event (void *cls, 216check_event(void *cls,
224 const struct TransportPluginMonitorMessage *tpmm) 217 const struct TransportPluginMonitorMessage *tpmm)
225{ 218{
226 const char *pname; 219 const char *pname;
227 size_t pname_len; 220 size_t pname_len;
228 size_t paddr_len; 221 size_t paddr_len;
229 222
230 pname = (const char *) &tpmm[1]; 223 pname = (const char *)&tpmm[1];
231 pname_len = ntohs (tpmm->plugin_name_len); 224 pname_len = ntohs(tpmm->plugin_name_len);
232 paddr_len = ntohs (tpmm->plugin_address_len); 225 paddr_len = ntohs(tpmm->plugin_address_len);
233 if ( (pname_len + 226 if ((pname_len +
234 paddr_len + 227 paddr_len +
235 sizeof (struct TransportPluginMonitorMessage) != ntohs (tpmm->header.size)) || 228 sizeof(struct TransportPluginMonitorMessage) != ntohs(tpmm->header.size)) ||
236 ( (0 != pname_len) && 229 ((0 != pname_len) &&
237 ('\0' != pname[pname_len - 1]) ) ) 230 ('\0' != pname[pname_len - 1])))
238 { 231 {
239 GNUNET_break (0); 232 GNUNET_break(0);
240 return GNUNET_SYSERR; 233 return GNUNET_SYSERR;
241 } 234 }
242 return GNUNET_OK; 235 return GNUNET_OK;
243} 236}
244 237
@@ -250,8 +243,8 @@ check_event (void *cls,
250 * @paramm tpmm message with event data 243 * @paramm tpmm message with event data
251 */ 244 */
252static void 245static void
253handle_event (void *cls, 246handle_event(void *cls,
254 const struct TransportPluginMonitorMessage *tpmm) 247 const struct TransportPluginMonitorMessage *tpmm)
255{ 248{
256 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 249 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
257 struct GNUNET_TRANSPORT_PluginSession *ps; 250 struct GNUNET_TRANSPORT_PluginSession *ps;
@@ -264,64 +257,63 @@ handle_event (void *cls,
264 struct GNUNET_HELLO_Address addr; 257 struct GNUNET_HELLO_Address addr;
265 struct SearchContext rv; 258 struct SearchContext rv;
266 259
267 pname = (const char *) &tpmm[1]; 260 pname = (const char *)&tpmm[1];
268 pname_len = ntohs (tpmm->plugin_name_len); 261 pname_len = ntohs(tpmm->plugin_name_len);
269 paddr_len = ntohs (tpmm->plugin_address_len); 262 paddr_len = ntohs(tpmm->plugin_address_len);
270 paddr = &pname[pname_len]; 263 paddr = &pname[pname_len];
271 ps = NULL; 264 ps = NULL;
272 ss = (enum GNUNET_TRANSPORT_SessionState) ntohs (tpmm->session_state); 265 ss = (enum GNUNET_TRANSPORT_SessionState)ntohs(tpmm->session_state);
273 if (GNUNET_TRANSPORT_SS_INIT == ss) 266 if (GNUNET_TRANSPORT_SS_INIT == ss)
274 { 267 {
275 ps = GNUNET_new (struct GNUNET_TRANSPORT_PluginSession); 268 ps = GNUNET_new(struct GNUNET_TRANSPORT_PluginSession);
276 ps->session_id = tpmm->session_id; 269 ps->session_id = tpmm->session_id;
277 (void) GNUNET_CONTAINER_multihashmap32_put (pm->sessions, 270 (void)GNUNET_CONTAINER_multihashmap32_put(pm->sessions,
278 wrap_id (tpmm->session_id), 271 wrap_id(tpmm->session_id),
279 ps, 272 ps,
280 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 273 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
281 274 }
282 }
283 else 275 else
284 { 276 {
285 rv.session_id = tpmm->session_id; 277 rv.session_id = tpmm->session_id;
286 rv.ps = NULL; 278 rv.ps = NULL;
287 (void) GNUNET_CONTAINER_multihashmap32_get_multiple (pm->sessions, 279 (void)GNUNET_CONTAINER_multihashmap32_get_multiple(pm->sessions,
288 wrap_id (tpmm->session_id), 280 wrap_id(tpmm->session_id),
289 &locate_by_id, 281 &locate_by_id,
290 &rv); 282 &rv);
291 ps = rv.ps; 283 ps = rv.ps;
292 if (NULL == ps) 284 if (NULL == ps)
293 { 285 {
294 GNUNET_break (0); 286 GNUNET_break(0);
295 reconnect_plugin_ctx (pm); 287 reconnect_plugin_ctx(pm);
296 return; 288 return;
289 }
297 } 290 }
298 }
299 info.state = ss; 291 info.state = ss;
300 info.is_inbound = (int16_t) ntohs (tpmm->is_inbound); 292 info.is_inbound = (int16_t)ntohs(tpmm->is_inbound);
301 info.num_msg_pending = ntohl (tpmm->msgs_pending); 293 info.num_msg_pending = ntohl(tpmm->msgs_pending);
302 info.num_bytes_pending = ntohl (tpmm->bytes_pending); 294 info.num_bytes_pending = ntohl(tpmm->bytes_pending);
303 info.receive_delay = GNUNET_TIME_absolute_ntoh (tpmm->delay); 295 info.receive_delay = GNUNET_TIME_absolute_ntoh(tpmm->delay);
304 info.session_timeout = GNUNET_TIME_absolute_ntoh (tpmm->timeout); 296 info.session_timeout = GNUNET_TIME_absolute_ntoh(tpmm->timeout);
305 info.address = &addr; 297 info.address = &addr;
306 addr.peer = tpmm->peer; 298 addr.peer = tpmm->peer;
307 addr.address = (0 == paddr_len) ? NULL : paddr; 299 addr.address = (0 == paddr_len) ? NULL : paddr;
308 addr.address_length = paddr_len; 300 addr.address_length = paddr_len;
309 addr.transport_name = (0 == pname_len) ? NULL : pname; 301 addr.transport_name = (0 == pname_len) ? NULL : pname;
310 addr.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE; 302 addr.local_info = GNUNET_HELLO_ADDRESS_INFO_NONE;
311 pm->cb (pm->cb_cls, 303 pm->cb(pm->cb_cls,
312 ps, 304 ps,
313 &ps->client_ctx, 305 &ps->client_ctx,
314 &info); 306 &info);
315 307
316 if (GNUNET_TRANSPORT_SS_DONE == ss) 308 if (GNUNET_TRANSPORT_SS_DONE == ss)
317 { 309 {
318 GNUNET_break (NULL == ps->client_ctx); 310 GNUNET_break(NULL == ps->client_ctx);
319 GNUNET_assert (GNUNET_YES == 311 GNUNET_assert(GNUNET_YES ==
320 GNUNET_CONTAINER_multihashmap32_remove (pm->sessions, 312 GNUNET_CONTAINER_multihashmap32_remove(pm->sessions,
321 wrap_id (tpmm->session_id), 313 wrap_id(tpmm->session_id),
322 ps)); 314 ps));
323 GNUNET_free (ps); 315 GNUNET_free(ps);
324 } 316 }
325} 317}
326 318
327 319
@@ -332,16 +324,16 @@ handle_event (void *cls,
332 * @param msg message from the service 324 * @param msg message from the service
333 */ 325 */
334static void 326static void
335handle_sync (void *cls, 327handle_sync(void *cls,
336 const struct GNUNET_MessageHeader *msg) 328 const struct GNUNET_MessageHeader *msg)
337{ 329{
338 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 330 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
339 331
340 /* we are in sync, notify callback */ 332 /* we are in sync, notify callback */
341 pm->cb (pm->cb_cls, 333 pm->cb(pm->cb_cls,
342 NULL, 334 NULL,
343 NULL, 335 NULL,
344 NULL); 336 NULL);
345} 337}
346 338
347 339
@@ -355,12 +347,12 @@ handle_sync (void *cls,
355 * @param error error code 347 * @param error error code
356 */ 348 */
357static void 349static void
358mq_error_handler (void *cls, 350mq_error_handler(void *cls,
359 enum GNUNET_MQ_Error error) 351 enum GNUNET_MQ_Error error)
360{ 352{
361 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 353 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
362 354
363 reconnect_plugin_ctx (pm); 355 reconnect_plugin_ctx(pm);
364} 356}
365 357
366 358
@@ -370,35 +362,35 @@ mq_error_handler (void *cls,
370 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *` 362 * @param cls our `struct GNUNET_TRANSPORT_PluginMonitor *`
371 */ 363 */
372static void 364static void
373do_plugin_connect (void *cls) 365do_plugin_connect(void *cls)
374{ 366{
375 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls; 367 struct GNUNET_TRANSPORT_PluginMonitor *pm = cls;
376 struct GNUNET_MQ_MessageHandler handlers[] = { 368 struct GNUNET_MQ_MessageHandler handlers[] = {
377 GNUNET_MQ_hd_var_size (event, 369 GNUNET_MQ_hd_var_size(event,
378 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT, 370 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_EVENT,
379 struct TransportPluginMonitorMessage, 371 struct TransportPluginMonitorMessage,
380 pm), 372 pm),
381 GNUNET_MQ_hd_fixed_size (sync, 373 GNUNET_MQ_hd_fixed_size(sync,
382 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC, 374 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_SYNC,
383 struct GNUNET_MessageHeader, 375 struct GNUNET_MessageHeader,
384 pm), 376 pm),
385 GNUNET_MQ_handler_end () 377 GNUNET_MQ_handler_end()
386 }; 378 };
387 struct GNUNET_MessageHeader *msg; 379 struct GNUNET_MessageHeader *msg;
388 struct GNUNET_MQ_Envelope *env; 380 struct GNUNET_MQ_Envelope *env;
389 381
390 pm->reconnect_task = NULL; 382 pm->reconnect_task = NULL;
391 pm->mq = GNUNET_CLIENT_connect (pm->cfg, 383 pm->mq = GNUNET_CLIENT_connect(pm->cfg,
392 "transport", 384 "transport",
393 handlers, 385 handlers,
394 &mq_error_handler, 386 &mq_error_handler,
395 pm); 387 pm);
396 if (NULL == pm->mq) 388 if (NULL == pm->mq)
397 return; 389 return;
398 env = GNUNET_MQ_msg (msg, 390 env = GNUNET_MQ_msg(msg,
399 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START); 391 GNUNET_MESSAGE_TYPE_TRANSPORT_MONITOR_PLUGIN_START);
400 GNUNET_MQ_send (pm->mq, 392 GNUNET_MQ_send(pm->mq,
401 env); 393 env);
402} 394}
403 395
404 396
@@ -412,23 +404,23 @@ do_plugin_connect (void *cls)
412 * @return NULL on error, otherwise handle for cancellation 404 * @return NULL on error, otherwise handle for cancellation
413 */ 405 */
414struct GNUNET_TRANSPORT_PluginMonitor * 406struct GNUNET_TRANSPORT_PluginMonitor *
415GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg, 407GNUNET_TRANSPORT_monitor_plugins(const struct GNUNET_CONFIGURATION_Handle *cfg,
416 GNUNET_TRANSPORT_SessionMonitorCallback cb, 408 GNUNET_TRANSPORT_SessionMonitorCallback cb,
417 void *cb_cls) 409 void *cb_cls)
418{ 410{
419 struct GNUNET_TRANSPORT_PluginMonitor *pm; 411 struct GNUNET_TRANSPORT_PluginMonitor *pm;
420 412
421 pm = GNUNET_new (struct GNUNET_TRANSPORT_PluginMonitor); 413 pm = GNUNET_new(struct GNUNET_TRANSPORT_PluginMonitor);
422 pm->cb = cb; 414 pm->cb = cb;
423 pm->cb_cls = cb_cls; 415 pm->cb_cls = cb_cls;
424 pm->cfg = cfg; 416 pm->cfg = cfg;
425 do_plugin_connect (pm); 417 do_plugin_connect(pm);
426 if (NULL == pm->mq) 418 if (NULL == pm->mq)
427 { 419 {
428 GNUNET_free (pm); 420 GNUNET_free(pm);
429 return NULL; 421 return NULL;
430 } 422 }
431 pm->sessions = GNUNET_CONTAINER_multihashmap32_create (128); 423 pm->sessions = GNUNET_CONTAINER_multihashmap32_create(128);
432 return pm; 424 return pm;
433} 425}
434 426
@@ -442,23 +434,23 @@ GNUNET_TRANSPORT_monitor_plugins (const struct GNUNET_CONFIGURATION_Handle *cfg,
442 * @param pm handle of the request that is to be cancelled 434 * @param pm handle of the request that is to be cancelled
443 */ 435 */
444void 436void
445GNUNET_TRANSPORT_monitor_plugins_cancel (struct GNUNET_TRANSPORT_PluginMonitor *pm) 437GNUNET_TRANSPORT_monitor_plugins_cancel(struct GNUNET_TRANSPORT_PluginMonitor *pm)
446{ 438{
447 if (NULL != pm->mq) 439 if (NULL != pm->mq)
448 { 440 {
449 GNUNET_MQ_destroy (pm->mq); 441 GNUNET_MQ_destroy(pm->mq);
450 pm->mq = NULL; 442 pm->mq = NULL;
451 } 443 }
452 if (NULL != pm->reconnect_task) 444 if (NULL != pm->reconnect_task)
453 { 445 {
454 GNUNET_SCHEDULER_cancel (pm->reconnect_task); 446 GNUNET_SCHEDULER_cancel(pm->reconnect_task);
455 pm->reconnect_task = NULL; 447 pm->reconnect_task = NULL;
456 } 448 }
457 GNUNET_CONTAINER_multihashmap32_iterate (pm->sessions, 449 GNUNET_CONTAINER_multihashmap32_iterate(pm->sessions,
458 &free_entry, 450 &free_entry,
459 pm); 451 pm);
460 GNUNET_CONTAINER_multihashmap32_destroy (pm->sessions); 452 GNUNET_CONTAINER_multihashmap32_destroy(pm->sessions);
461 GNUNET_free (pm); 453 GNUNET_free(pm);
462} 454}
463 455
464 456
diff --git a/src/transport/transport_api_offer_hello.c b/src/transport/transport_api_offer_hello.c
index c4432af93..89f8d463d 100644
--- a/src/transport/transport_api_offer_hello.c
+++ b/src/transport/transport_api_offer_hello.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/transport_api_offer_hello.c 22 * @file transport/transport_api_offer_hello.c
@@ -33,9 +33,7 @@
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{
38
39 /** 37 /**
40 * Transport service handle we use for transmission. 38 * Transport service handle we use for transmission.
41 */ 39 */
@@ -50,7 +48,6 @@ struct GNUNET_TRANSPORT_OfferHelloHandle
50 * Closure for @e cont 48 * Closure for @e cont
51 */ 49 */
52 void *cls; 50 void *cls;
53
54}; 51};
55 52
56 53
@@ -60,13 +57,13 @@ struct GNUNET_TRANSPORT_OfferHelloHandle
60 * @param cls the handle for the operation 57 * @param cls the handle for the operation
61 */ 58 */
62static void 59static void
63finished_hello (void *cls) 60finished_hello(void *cls)
64{ 61{
65 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls; 62 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh = cls;
66 63
67 if (NULL != ohh->cont) 64 if (NULL != ohh->cont)
68 ohh->cont (ohh->cls); 65 ohh->cont(ohh->cls);
69 GNUNET_TRANSPORT_offer_hello_cancel (ohh); 66 GNUNET_TRANSPORT_offer_hello_cancel(ohh);
70} 67}
71 68
72 69
@@ -78,51 +75,51 @@ finished_hello (void *cls)
78 * @param cfg configuration 75 * @param cfg configuration
79 * @param hello the hello message 76 * @param hello the hello message
80 * @param cont continuation to call when HELLO has been sent, 77 * @param cont continuation to call when HELLO has been sent,
81 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail 78 * tc reason #GNUNET_SCHEDULER_REASON_TIMEOUT for fail
82 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success 79 * tc reasong #GNUNET_SCHEDULER_REASON_READ_READY for success
83 * @param cont_cls closure for @a cont 80 * @param cont_cls closure for @a cont
84 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure, 81 * @return a `struct GNUNET_TRANSPORT_OfferHelloHandle` handle or NULL on failure,
85 * in case of failure @a cont will not be called 82 * in case of failure @a cont will not be called
86 * 83 *
87 */ 84 */
88struct GNUNET_TRANSPORT_OfferHelloHandle * 85struct GNUNET_TRANSPORT_OfferHelloHandle *
89GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg, 86GNUNET_TRANSPORT_offer_hello(const struct GNUNET_CONFIGURATION_Handle *cfg,
90 const struct GNUNET_MessageHeader *hello, 87 const struct GNUNET_MessageHeader *hello,
91 GNUNET_SCHEDULER_TaskCallback cont, 88 GNUNET_SCHEDULER_TaskCallback cont,
92 void *cont_cls) 89 void *cont_cls)
93{ 90{
94 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh 91 struct GNUNET_TRANSPORT_OfferHelloHandle *ohh
95 = GNUNET_new (struct GNUNET_TRANSPORT_OfferHelloHandle); 92 = GNUNET_new(struct GNUNET_TRANSPORT_OfferHelloHandle);
96 struct GNUNET_MQ_Envelope *env; 93 struct GNUNET_MQ_Envelope *env;
97 struct GNUNET_PeerIdentity peer; 94 struct GNUNET_PeerIdentity peer;
98 95
99 if (GNUNET_OK != 96 if (GNUNET_OK !=
100 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, 97 GNUNET_HELLO_get_id((const struct GNUNET_HELLO_Message *)hello,
101 &peer)) 98 &peer))
102 { 99 {
103 GNUNET_break (0); 100 GNUNET_break(0);
104 GNUNET_free (ohh); 101 GNUNET_free(ohh);
105 return NULL; 102 return NULL;
106 } 103 }
107 ohh->mq = GNUNET_CLIENT_connect (cfg, 104 ohh->mq = GNUNET_CLIENT_connect(cfg,
108 "transport", 105 "transport",
109 NULL, 106 NULL,
110 NULL, 107 NULL,
111 ohh); 108 ohh);
112 if (NULL == ohh->mq) 109 if (NULL == ohh->mq)
113 { 110 {
114 GNUNET_free (ohh); 111 GNUNET_free(ohh);
115 return NULL; 112 return NULL;
116 } 113 }
117 ohh->cont = cont; 114 ohh->cont = cont;
118 ohh->cls = cont_cls; 115 ohh->cls = cont_cls;
119 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); 116 GNUNET_break(ntohs(hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
120 env = GNUNET_MQ_msg_copy (hello); 117 env = GNUNET_MQ_msg_copy(hello);
121 GNUNET_MQ_notify_sent (env, 118 GNUNET_MQ_notify_sent(env,
122 &finished_hello, 119 &finished_hello,
123 ohh); 120 ohh);
124 GNUNET_MQ_send (ohh->mq, 121 GNUNET_MQ_send(ohh->mq,
125 env); 122 env);
126 return ohh; 123 return ohh;
127} 124}
128 125
@@ -133,10 +130,10 @@ GNUNET_TRANSPORT_offer_hello (const struct GNUNET_CONFIGURATION_Handle *cfg,
133 * @param ohh the handle for the operation to cancel 130 * @param ohh the handle for the operation to cancel
134 */ 131 */
135void 132void
136GNUNET_TRANSPORT_offer_hello_cancel (struct GNUNET_TRANSPORT_OfferHelloHandle *ohh) 133GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
137{ 134{
138 GNUNET_MQ_destroy (ohh->mq); 135 GNUNET_MQ_destroy(ohh->mq);
139 GNUNET_free (ohh); 136 GNUNET_free(ohh);
140} 137}
141 138
142 139