aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c3631
1 files changed, 1812 insertions, 1819 deletions
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