diff options
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 3540 |
1 files changed, 1777 insertions, 1763 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 80b21d86a..36ff00dd8 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -35,7 +35,7 @@ | |||
35 | #include "gnunet_transport_plugin.h" | 35 | #include "gnunet_transport_plugin.h" |
36 | #include "transport.h" | 36 | #include "transport.h" |
37 | 37 | ||
38 | #define LOG(kind, ...) GNUNET_log_from(kind, "transport-tcp", __VA_ARGS__) | 38 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-tcp", __VA_ARGS__) |
39 | 39 | ||
40 | #define PLUGIN_NAME "tcp" | 40 | #define PLUGIN_NAME "tcp" |
41 | 41 | ||
@@ -43,7 +43,7 @@ | |||
43 | * How long until we give up on establishing an NAT connection? | 43 | * How long until we give up on establishing an NAT connection? |
44 | * Must be > 4 RTT | 44 | * Must be > 4 RTT |
45 | */ | 45 | */ |
46 | #define NAT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) | 46 | #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Opaque handle that can be used to cancel | 49 | * Opaque handle that can be used to cancel |
@@ -83,7 +83,7 @@ struct LEGACY_SERVICE_Context; | |||
83 | * @param srv service to stop | 83 | * @param srv service to stop |
84 | */ | 84 | */ |
85 | void | 85 | void |
86 | LEGACY_SERVICE_stop(struct LEGACY_SERVICE_Context *srv); | 86 | LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv); |
87 | 87 | ||
88 | 88 | ||
89 | /** | 89 | /** |
@@ -103,7 +103,8 @@ typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, | |||
103 | /** | 103 | /** |
104 | * Credentials for UNIX domain sockets. | 104 | * Credentials for UNIX domain sockets. |
105 | */ | 105 | */ |
106 | struct GNUNET_CONNECTION_Credentials { | 106 | struct GNUNET_CONNECTION_Credentials |
107 | { | ||
107 | /** | 108 | /** |
108 | * UID of the other end of the connection. | 109 | * UID of the other end of the connection. |
109 | */ | 110 | */ |
@@ -185,7 +186,7 @@ typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, | |||
185 | * @param connection connection to destroy | 186 | * @param connection connection to destroy |
186 | */ | 187 | */ |
187 | void | 188 | void |
188 | GNUNET_CONNECTION_destroy(struct GNUNET_CONNECTION_Handle *connection); | 189 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); |
189 | 190 | ||
190 | 191 | ||
191 | /** | 192 | /** |
@@ -249,7 +250,8 @@ typedef void (*GNUNET_SERVER_MessageCallback) ( | |||
249 | * Message handler. Each struct specifies how to handle on particular | 250 | * Message handler. Each struct specifies how to handle on particular |
250 | * type of message received. | 251 | * type of message received. |
251 | */ | 252 | */ |
252 | struct GNUNET_SERVER_MessageHandler { | 253 | struct GNUNET_SERVER_MessageHandler |
254 | { | ||
253 | /** | 255 | /** |
254 | * Function to call for messages of "type". | 256 | * Function to call for messages of "type". |
255 | */ | 257 | */ |
@@ -278,7 +280,8 @@ struct GNUNET_SERVER_MessageHandler { | |||
278 | /** | 280 | /** |
279 | * Options for the service (bitmask). | 281 | * Options for the service (bitmask). |
280 | */ | 282 | */ |
281 | enum LEGACY_SERVICE_Options { | 283 | enum LEGACY_SERVICE_Options |
284 | { | ||
282 | /** | 285 | /** |
283 | * Use defaults. Terminates all client connections and the listen | 286 | * Use defaults. Terminates all client connections and the listen |
284 | * sockets immediately upon receiving the shutdown signal. | 287 | * sockets immediately upon receiving the shutdown signal. |
@@ -309,7 +312,7 @@ enum LEGACY_SERVICE_Options { | |||
309 | * @param client the client to disconnect from | 312 | * @param client the client to disconnect from |
310 | */ | 313 | */ |
311 | void | 314 | void |
312 | GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client); | 315 | GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); |
313 | 316 | ||
314 | /** | 317 | /** |
315 | * Return user context associated with the given client. | 318 | * Return user context associated with the given client. |
@@ -320,8 +323,8 @@ GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client); | |||
320 | * @return pointer to user context | 323 | * @return pointer to user context |
321 | */ | 324 | */ |
322 | void * | 325 | void * |
323 | GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, | 326 | GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, |
324 | size_t size); | 327 | size_t size); |
325 | 328 | ||
326 | 329 | ||
327 | /** | 330 | /** |
@@ -350,8 +353,8 @@ typedef int (*GNUNET_SERVER_MessageTokenizerCallback) ( | |||
350 | * @return handle to tokenizer | 353 | * @return handle to tokenizer |
351 | */ | 354 | */ |
352 | struct GNUNET_SERVER_MessageStreamTokenizer * | 355 | struct GNUNET_SERVER_MessageStreamTokenizer * |
353 | GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, | 356 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, |
354 | void *cb_cls); | 357 | void *cb_cls); |
355 | 358 | ||
356 | /** | 359 | /** |
357 | * Add incoming data to the receive buffer and call the | 360 | * Add incoming data to the receive buffer and call the |
@@ -370,12 +373,12 @@ GNUNET_SERVER_mst_create(GNUNET_SERVER_MessageTokenizerCallback cb, | |||
370 | * #GNUNET_SYSERR if the data stream is corrupt | 373 | * #GNUNET_SYSERR if the data stream is corrupt |
371 | */ | 374 | */ |
372 | int | 375 | int |
373 | GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, | 376 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, |
374 | void *client_identity, | 377 | void *client_identity, |
375 | const char *buf, | 378 | const char *buf, |
376 | size_t size, | 379 | size_t size, |
377 | int purge, | 380 | int purge, |
378 | int one_shot); | 381 | int one_shot); |
379 | 382 | ||
380 | 383 | ||
381 | /** | 384 | /** |
@@ -384,7 +387,7 @@ GNUNET_SERVER_mst_receive(struct GNUNET_SERVER_MessageStreamTokenizer *mst, | |||
384 | * @param mst tokenizer to destroy | 387 | * @param mst tokenizer to destroy |
385 | */ | 388 | */ |
386 | void | 389 | void |
387 | GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst); | 390 | GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst); |
388 | 391 | ||
389 | 392 | ||
390 | /** | 393 | /** |
@@ -396,9 +399,9 @@ GNUNET_SERVER_mst_destroy(struct GNUNET_SERVER_MessageStreamTokenizer *mst); | |||
396 | * @param size number of bytes in user context struct (for verification only) | 399 | * @param size number of bytes in user context struct (for verification only) |
397 | */ | 400 | */ |
398 | void | 401 | void |
399 | GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, | 402 | GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, |
400 | void *ptr, | 403 | void *ptr, |
401 | size_t size); | 404 | size_t size); |
402 | /** | 405 | /** |
403 | * Return user context associated with the given client. | 406 | * Return user context associated with the given client. |
404 | * | 407 | * |
@@ -407,7 +410,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, | |||
407 | * @return pointer to user context of type 'type *'. | 410 | * @return pointer to user context of type 'type *'. |
408 | */ | 411 | */ |
409 | #define GNUNET_SERVER_client_get_user_context(client, type) \ | 412 | #define GNUNET_SERVER_client_get_user_context(client, type) \ |
410 | (type *)GNUNET_SERVER_client_get_user_context_(client, sizeof(type)) | 413 | (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof(type)) |
411 | 414 | ||
412 | /** | 415 | /** |
413 | * Set user context to be associated with the given client. | 416 | * Set user context to be associated with the given client. |
@@ -416,7 +419,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, | |||
416 | * @param value pointer to user context | 419 | * @param value pointer to user context |
417 | */ | 420 | */ |
418 | #define GNUNET_SERVER_client_set_user_context(client, value) \ | 421 | #define GNUNET_SERVER_client_set_user_context(client, value) \ |
419 | GNUNET_SERVER_client_set_user_context_(client, value, sizeof(*value)) | 422 | GNUNET_SERVER_client_set_user_context_ (client, value, sizeof(*value)) |
420 | 423 | ||
421 | 424 | ||
422 | /** | 425 | /** |
@@ -435,7 +438,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, | |||
435 | * NULL if we are already going to notify someone else (busy) | 438 | * NULL if we are already going to notify someone else (busy) |
436 | */ | 439 | */ |
437 | struct GNUNET_SERVER_TransmitHandle * | 440 | struct GNUNET_SERVER_TransmitHandle * |
438 | GNUNET_SERVER_notify_transmit_ready( | 441 | GNUNET_SERVER_notify_transmit_ready ( |
439 | struct GNUNET_SERVER_Client *client, | 442 | struct GNUNET_SERVER_Client *client, |
440 | size_t size, | 443 | size_t size, |
441 | struct GNUNET_TIME_Relative timeout, | 444 | struct GNUNET_TIME_Relative timeout, |
@@ -448,7 +451,7 @@ GNUNET_SERVER_notify_transmit_ready( | |||
448 | * @param th request to abort | 451 | * @param th request to abort |
449 | */ | 452 | */ |
450 | void | 453 | void |
451 | GNUNET_SERVER_notify_transmit_ready_cancel( | 454 | GNUNET_SERVER_notify_transmit_ready_cancel ( |
452 | struct GNUNET_SERVER_TransmitHandle *th); | 455 | struct GNUNET_SERVER_TransmitHandle *th); |
453 | 456 | ||
454 | 457 | ||
@@ -460,7 +463,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel( | |||
460 | * @param client the client to keep | 463 | * @param client the client to keep |
461 | */ | 464 | */ |
462 | void | 465 | void |
463 | GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client); | 466 | GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); |
464 | 467 | ||
465 | 468 | ||
466 | /** | 469 | /** |
@@ -472,7 +475,7 @@ GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client); | |||
472 | * @param client the client to drop | 475 | * @param client the client to drop |
473 | */ | 476 | */ |
474 | void | 477 | void |
475 | GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client); | 478 | GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); |
476 | 479 | ||
477 | 480 | ||
478 | /** | 481 | /** |
@@ -496,7 +499,7 @@ typedef void (*LEGACY_SERVICE_Main) ( | |||
496 | * @param server server to stop accepting connections. | 499 | * @param server server to stop accepting connections. |
497 | */ | 500 | */ |
498 | void | 501 | void |
499 | GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server); | 502 | GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); |
500 | 503 | ||
501 | /** | 504 | /** |
502 | * Notify us when the server has enough space to transmit | 505 | * Notify us when the server has enough space to transmit |
@@ -514,7 +517,7 @@ GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server); | |||
514 | * NULL if we are already going to notify someone else (busy) | 517 | * NULL if we are already going to notify someone else (busy) |
515 | */ | 518 | */ |
516 | struct GNUNET_SERVER_TransmitHandle * | 519 | struct GNUNET_SERVER_TransmitHandle * |
517 | GNUNET_SERVER_notify_transmit_ready( | 520 | GNUNET_SERVER_notify_transmit_ready ( |
518 | struct GNUNET_SERVER_Client *client, | 521 | struct GNUNET_SERVER_Client *client, |
519 | size_t size, | 522 | size_t size, |
520 | struct GNUNET_TIME_Relative timeout, | 523 | struct GNUNET_TIME_Relative timeout, |
@@ -534,8 +537,8 @@ GNUNET_SERVER_notify_transmit_ready( | |||
534 | * @return the client handle | 537 | * @return the client handle |
535 | */ | 538 | */ |
536 | struct GNUNET_SERVER_Client * | 539 | struct GNUNET_SERVER_Client * |
537 | GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, | 540 | GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, |
538 | struct GNUNET_CONNECTION_Handle *connection); | 541 | struct GNUNET_CONNECTION_Handle *connection); |
539 | 542 | ||
540 | 543 | ||
541 | /** | 544 | /** |
@@ -544,7 +547,7 @@ GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, | |||
544 | * @param server server to resume accepting connections. | 547 | * @param server server to resume accepting connections. |
545 | */ | 548 | */ |
546 | void | 549 | void |
547 | GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server); | 550 | GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server); |
548 | 551 | ||
549 | /** | 552 | /** |
550 | * Free resources held by this server. | 553 | * Free resources held by this server. |
@@ -552,7 +555,7 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server); | |||
552 | * @param server server to destroy | 555 | * @param server server to destroy |
553 | */ | 556 | */ |
554 | void | 557 | void |
555 | GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server); | 558 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); |
556 | 559 | ||
557 | 560 | ||
558 | #include "tcp_connection_legacy.c" | 561 | #include "tcp_connection_legacy.c" |
@@ -565,7 +568,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
565 | /** | 568 | /** |
566 | * Initial handshake message for a session. | 569 | * Initial handshake message for a session. |
567 | */ | 570 | */ |
568 | struct WelcomeMessage { | 571 | struct WelcomeMessage |
572 | { | ||
569 | /** | 573 | /** |
570 | * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME. | 574 | * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME. |
571 | */ | 575 | */ |
@@ -581,7 +585,8 @@ struct WelcomeMessage { | |||
581 | * Basically a WELCOME message, but with the purpose | 585 | * Basically a WELCOME message, but with the purpose |
582 | * of giving the waiting peer a client handle to use | 586 | * of giving the waiting peer a client handle to use |
583 | */ | 587 | */ |
584 | struct TCP_NAT_ProbeMessage { | 588 | struct TCP_NAT_ProbeMessage |
589 | { | ||
585 | /** | 590 | /** |
586 | * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE. | 591 | * Type is #GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE. |
587 | */ | 592 | */ |
@@ -597,7 +602,8 @@ GNUNET_NETWORK_STRUCT_END | |||
597 | /** | 602 | /** |
598 | * Context for sending a NAT probe via TCP. | 603 | * Context for sending a NAT probe via TCP. |
599 | */ | 604 | */ |
600 | struct TCPProbeContext { | 605 | struct TCPProbeContext |
606 | { | ||
601 | /** | 607 | /** |
602 | * Active probes are kept in a DLL. | 608 | * Active probes are kept in a DLL. |
603 | */ | 609 | */ |
@@ -632,7 +638,8 @@ struct TCPProbeContext { | |||
632 | /** | 638 | /** |
633 | * Bits in the `options` field of TCP addresses. | 639 | * Bits in the `options` field of TCP addresses. |
634 | */ | 640 | */ |
635 | enum TcpAddressOptions { | 641 | enum TcpAddressOptions |
642 | { | ||
636 | /** | 643 | /** |
637 | * No bits set. | 644 | * No bits set. |
638 | */ | 645 | */ |
@@ -654,7 +661,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
654 | /** | 661 | /** |
655 | * Network format for IPv4 addresses. | 662 | * Network format for IPv4 addresses. |
656 | */ | 663 | */ |
657 | struct IPv4TcpAddress { | 664 | struct IPv4TcpAddress |
665 | { | ||
658 | /** | 666 | /** |
659 | * Optional options and flags for this address, | 667 | * Optional options and flags for this address, |
660 | * see `enum TcpAddressOptions` | 668 | * see `enum TcpAddressOptions` |
@@ -675,7 +683,8 @@ struct IPv4TcpAddress { | |||
675 | /** | 683 | /** |
676 | * Network format for IPv6 addresses. | 684 | * Network format for IPv6 addresses. |
677 | */ | 685 | */ |
678 | struct IPv6TcpAddress { | 686 | struct IPv6TcpAddress |
687 | { | ||
679 | /** | 688 | /** |
680 | * Optional flags for this address | 689 | * Optional flags for this address |
681 | * see `enum TcpAddressOptions` | 690 | * see `enum TcpAddressOptions` |
@@ -703,7 +712,8 @@ struct Plugin; | |||
703 | * Information kept for each message that is yet to | 712 | * Information kept for each message that is yet to |
704 | * be transmitted. | 713 | * be transmitted. |
705 | */ | 714 | */ |
706 | struct PendingMessage { | 715 | struct PendingMessage |
716 | { | ||
707 | /** | 717 | /** |
708 | * This is a doubly-linked list. | 718 | * This is a doubly-linked list. |
709 | */ | 719 | */ |
@@ -747,7 +757,8 @@ struct PendingMessage { | |||
747 | /** | 757 | /** |
748 | * Session handle for TCP connections. | 758 | * Session handle for TCP connections. |
749 | */ | 759 | */ |
750 | struct GNUNET_ATS_Session { | 760 | struct GNUNET_ATS_Session |
761 | { | ||
751 | /** | 762 | /** |
752 | * To whom are we talking to (set to our identity | 763 | * To whom are we talking to (set to our identity |
753 | * if we are still waiting for the welcome message) | 764 | * if we are still waiting for the welcome message) |
@@ -849,7 +860,8 @@ struct GNUNET_ATS_Session { | |||
849 | * Context for address to string conversion, closure | 860 | * Context for address to string conversion, closure |
850 | * for #append_port(). | 861 | * for #append_port(). |
851 | */ | 862 | */ |
852 | struct PrettyPrinterContext { | 863 | struct PrettyPrinterContext |
864 | { | ||
853 | /** | 865 | /** |
854 | * DLL | 866 | * DLL |
855 | */ | 867 | */ |
@@ -905,7 +917,8 @@ struct PrettyPrinterContext { | |||
905 | /** | 917 | /** |
906 | * Encapsulation of all of the state of the plugin. | 918 | * Encapsulation of all of the state of the plugin. |
907 | */ | 919 | */ |
908 | struct Plugin { | 920 | struct Plugin |
921 | { | ||
909 | /** | 922 | /** |
910 | * Our environment. | 923 | * Our environment. |
911 | */ | 924 | */ |
@@ -1036,10 +1049,10 @@ struct Plugin { | |||
1036 | * set to NULL). | 1049 | * set to NULL). |
1037 | */ | 1050 | */ |
1038 | static int | 1051 | static int |
1039 | get_server_addresses(const char *service_name, | 1052 | get_server_addresses (const char *service_name, |
1040 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1053 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1041 | struct sockaddr ***addrs, | 1054 | struct sockaddr ***addrs, |
1042 | socklen_t **addr_lens) | 1055 | socklen_t **addr_lens) |
1043 | { | 1056 | { |
1044 | int disablev6; | 1057 | int disablev6; |
1045 | struct GNUNET_NETWORK_Handle *desc; | 1058 | struct GNUNET_NETWORK_Handle *desc; |
@@ -1060,72 +1073,72 @@ get_server_addresses(const char *service_name, | |||
1060 | *addrs = NULL; | 1073 | *addrs = NULL; |
1061 | *addr_lens = NULL; | 1074 | *addr_lens = NULL; |
1062 | desc = NULL; | 1075 | desc = NULL; |
1063 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "DISABLEV6")) | 1076 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) |
1064 | { | 1077 | { |
1065 | if (GNUNET_SYSERR == | 1078 | if (GNUNET_SYSERR == |
1066 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 1079 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1067 | service_name, | 1080 | service_name, |
1068 | "DISABLEV6"))) | 1081 | "DISABLEV6"))) |
1069 | return GNUNET_SYSERR; | 1082 | return GNUNET_SYSERR; |
1070 | } | 1083 | } |
1071 | else | 1084 | else |
1072 | disablev6 = GNUNET_NO; | 1085 | disablev6 = GNUNET_NO; |
1073 | 1086 | ||
1074 | if (!disablev6) | 1087 | if (! disablev6) |
1088 | { | ||
1089 | /* probe IPv6 support */ | ||
1090 | desc = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_STREAM, 0); | ||
1091 | if (NULL == desc) | ||
1092 | { | ||
1093 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
1094 | (EACCES == errno)) | ||
1095 | { | ||
1096 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
1097 | return GNUNET_SYSERR; | ||
1098 | } | ||
1099 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1100 | _ ( | ||
1101 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
1102 | service_name, | ||
1103 | strerror (errno)); | ||
1104 | disablev6 = GNUNET_YES; | ||
1105 | } | ||
1106 | else | ||
1075 | { | 1107 | { |
1076 | /* probe IPv6 support */ | 1108 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); |
1077 | desc = GNUNET_NETWORK_socket_create(PF_INET6, SOCK_STREAM, 0); | 1109 | desc = NULL; |
1078 | if (NULL == desc) | ||
1079 | { | ||
1080 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
1081 | (EACCES == errno)) | ||
1082 | { | ||
1083 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
1084 | return GNUNET_SYSERR; | ||
1085 | } | ||
1086 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1087 | _( | ||
1088 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | ||
1089 | service_name, | ||
1090 | strerror(errno)); | ||
1091 | disablev6 = GNUNET_YES; | ||
1092 | } | ||
1093 | else | ||
1094 | { | ||
1095 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); | ||
1096 | desc = NULL; | ||
1097 | } | ||
1098 | } | 1110 | } |
1111 | } | ||
1099 | 1112 | ||
1100 | port = 0; | 1113 | port = 0; |
1101 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "PORT")) | 1114 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) |
1115 | { | ||
1116 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, | ||
1117 | service_name, | ||
1118 | "PORT", | ||
1119 | &port)) | ||
1102 | { | 1120 | { |
1103 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 1121 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1104 | service_name, | 1122 | _ ("Require valid port number for service `%s' in configuration!\n"), |
1105 | "PORT", | 1123 | service_name); |
1106 | &port)) | ||
1107 | { | ||
1108 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1109 | _("Require valid port number for service `%s' in configuration!\n"), | ||
1110 | service_name); | ||
1111 | } | ||
1112 | if (port > 65535) | ||
1113 | { | ||
1114 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
1115 | _("Require valid port number for service `%s' in configuration!\n"), | ||
1116 | service_name); | ||
1117 | return GNUNET_SYSERR; | ||
1118 | } | ||
1119 | } | 1124 | } |
1120 | 1125 | if (port > 65535) | |
1121 | if (GNUNET_CONFIGURATION_have_value(cfg, service_name, "BINDTO")) | ||
1122 | { | 1126 | { |
1123 | GNUNET_break(GNUNET_OK == | 1127 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1124 | GNUNET_CONFIGURATION_get_value_string(cfg, | 1128 | _ ("Require valid port number for service `%s' in configuration!\n"), |
1129 | service_name); | ||
1130 | return GNUNET_SYSERR; | ||
1131 | } | ||
1132 | } | ||
1133 | |||
1134 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) | ||
1135 | { | ||
1136 | GNUNET_break (GNUNET_OK == | ||
1137 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1125 | service_name, | 1138 | service_name, |
1126 | "BINDTO", | 1139 | "BINDTO", |
1127 | &hostname)); | 1140 | &hostname)); |
1128 | } | 1141 | } |
1129 | else | 1142 | else |
1130 | hostname = NULL; | 1143 | hostname = NULL; |
1131 | 1144 | ||
@@ -1133,232 +1146,232 @@ get_server_addresses(const char *service_name, | |||
1133 | abstract = GNUNET_NO; | 1146 | abstract = GNUNET_NO; |
1134 | #ifdef AF_UNIX | 1147 | #ifdef AF_UNIX |
1135 | if ((GNUNET_YES == | 1148 | if ((GNUNET_YES == |
1136 | GNUNET_CONFIGURATION_have_value(cfg, service_name, "UNIXPATH")) && | 1149 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && |
1137 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename(cfg, | 1150 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, |
1138 | service_name, | 1151 | service_name, |
1139 | "UNIXPATH", | 1152 | "UNIXPATH", |
1140 | &unixpath)) && | 1153 | &unixpath)) && |
1141 | (0 < strlen(unixpath))) | 1154 | (0 < strlen (unixpath))) |
1142 | { | 1155 | { |
1143 | /* probe UNIX support */ | 1156 | /* probe UNIX support */ |
1144 | struct sockaddr_un s_un; | 1157 | struct sockaddr_un s_un; |
1145 | 1158 | ||
1146 | if (strlen(unixpath) >= sizeof(s_un.sun_path)) | 1159 | if (strlen (unixpath) >= sizeof(s_un.sun_path)) |
1147 | { | 1160 | { |
1148 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1161 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1149 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), | 1162 | _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), |
1150 | unixpath, | 1163 | unixpath, |
1151 | (unsigned long long)sizeof(s_un.sun_path)); | 1164 | (unsigned long long) sizeof(s_un.sun_path)); |
1152 | unixpath = GNUNET_NETWORK_shorten_unixpath(unixpath); | 1165 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); |
1153 | LOG(GNUNET_ERROR_TYPE_INFO, _("Using `%s' instead\n"), unixpath); | 1166 | LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); |
1154 | } | 1167 | } |
1155 | #ifdef LINUX | 1168 | #ifdef LINUX |
1156 | abstract = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 1169 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1157 | "TESTING", | 1170 | "TESTING", |
1158 | "USE_ABSTRACT_SOCKETS"); | 1171 | "USE_ABSTRACT_SOCKETS"); |
1159 | if (GNUNET_SYSERR == abstract) | 1172 | if (GNUNET_SYSERR == abstract) |
1160 | abstract = GNUNET_NO; | 1173 | abstract = GNUNET_NO; |
1161 | #endif | 1174 | #endif |
1162 | if ((GNUNET_YES != abstract) && | 1175 | if ((GNUNET_YES != abstract) && |
1163 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file(unixpath))) | 1176 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) |
1164 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); | 1177 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); |
1165 | } | 1178 | } |
1166 | if (NULL != unixpath) | 1179 | if (NULL != unixpath) |
1180 | { | ||
1181 | desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | ||
1182 | if (NULL == desc) | ||
1183 | { | ||
1184 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
1185 | (EACCES == errno)) | ||
1186 | { | ||
1187 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
1188 | GNUNET_free_non_null (hostname); | ||
1189 | GNUNET_free (unixpath); | ||
1190 | return GNUNET_SYSERR; | ||
1191 | } | ||
1192 | LOG (GNUNET_ERROR_TYPE_INFO, | ||
1193 | _ ( | ||
1194 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
1195 | service_name, | ||
1196 | strerror (errno)); | ||
1197 | GNUNET_free (unixpath); | ||
1198 | unixpath = NULL; | ||
1199 | } | ||
1200 | else | ||
1167 | { | 1201 | { |
1168 | desc = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_STREAM, 0); | 1202 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); |
1169 | if (NULL == desc) | 1203 | desc = NULL; |
1170 | { | ||
1171 | if ((ENOBUFS == errno) || (ENOMEM == errno) || (ENFILE == errno) || | ||
1172 | (EACCES == errno)) | ||
1173 | { | ||
1174 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket"); | ||
1175 | GNUNET_free_non_null(hostname); | ||
1176 | GNUNET_free(unixpath); | ||
1177 | return GNUNET_SYSERR; | ||
1178 | } | ||
1179 | LOG(GNUNET_ERROR_TYPE_INFO, | ||
1180 | _( | ||
1181 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
1182 | service_name, | ||
1183 | strerror(errno)); | ||
1184 | GNUNET_free(unixpath); | ||
1185 | unixpath = NULL; | ||
1186 | } | ||
1187 | else | ||
1188 | { | ||
1189 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(desc)); | ||
1190 | desc = NULL; | ||
1191 | } | ||
1192 | } | 1204 | } |
1205 | } | ||
1193 | #endif | 1206 | #endif |
1194 | 1207 | ||
1195 | if ((0 == port) && (NULL == unixpath)) | 1208 | if ((0 == port) && (NULL == unixpath)) |
1196 | { | 1209 | { |
1197 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1210 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1198 | _( | 1211 | _ ( |
1199 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | 1212 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), |
1200 | service_name); | 1213 | service_name); |
1201 | GNUNET_free_non_null(hostname); | 1214 | GNUNET_free_non_null (hostname); |
1215 | return GNUNET_SYSERR; | ||
1216 | } | ||
1217 | if (0 == port) | ||
1218 | { | ||
1219 | saddrs = GNUNET_malloc (2 * sizeof(struct sockaddr *)); | ||
1220 | saddrlens = GNUNET_malloc (2 * sizeof(socklen_t)); | ||
1221 | add_unixpath (saddrs, saddrlens, unixpath, abstract); | ||
1222 | GNUNET_free_non_null (unixpath); | ||
1223 | GNUNET_free_non_null (hostname); | ||
1224 | *addrs = saddrs; | ||
1225 | *addr_lens = saddrlens; | ||
1226 | return 1; | ||
1227 | } | ||
1228 | |||
1229 | if (NULL != hostname) | ||
1230 | { | ||
1231 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1232 | "Resolving `%s' since that is where `%s' will bind to.\n", | ||
1233 | hostname, | ||
1234 | service_name); | ||
1235 | memset (&hints, 0, sizeof(struct addrinfo)); | ||
1236 | if (disablev6) | ||
1237 | hints.ai_family = AF_INET; | ||
1238 | hints.ai_protocol = IPPROTO_TCP; | ||
1239 | if ((0 != (ret = getaddrinfo (hostname, NULL, &hints, &res))) || | ||
1240 | (NULL == res)) | ||
1241 | { | ||
1242 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
1243 | _ ("Failed to resolve `%s': %s\n"), | ||
1244 | hostname, | ||
1245 | gai_strerror (ret)); | ||
1246 | GNUNET_free (hostname); | ||
1247 | GNUNET_free_non_null (unixpath); | ||
1202 | return GNUNET_SYSERR; | 1248 | return GNUNET_SYSERR; |
1203 | } | 1249 | } |
1204 | if (0 == port) | 1250 | next = res; |
1251 | i = 0; | ||
1252 | while (NULL != (pos = next)) | ||
1205 | { | 1253 | { |
1206 | saddrs = GNUNET_malloc(2 * sizeof(struct sockaddr *)); | 1254 | next = pos->ai_next; |
1207 | saddrlens = GNUNET_malloc(2 * sizeof(socklen_t)); | 1255 | if ((disablev6) && (pos->ai_family == AF_INET6)) |
1208 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | 1256 | continue; |
1209 | GNUNET_free_non_null(unixpath); | 1257 | i++; |
1210 | GNUNET_free_non_null(hostname); | ||
1211 | *addrs = saddrs; | ||
1212 | *addr_lens = saddrlens; | ||
1213 | return 1; | ||
1214 | } | 1258 | } |
1215 | 1259 | if (0 == i) | |
1216 | if (NULL != hostname) | ||
1217 | { | 1260 | { |
1218 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1261 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1219 | "Resolving `%s' since that is where `%s' will bind to.\n", | 1262 | _ ("Failed to find %saddress for `%s'.\n"), |
1220 | hostname, | 1263 | disablev6 ? "IPv4 " : "", |
1221 | service_name); | 1264 | hostname); |
1222 | memset(&hints, 0, sizeof(struct addrinfo)); | 1265 | freeaddrinfo (res); |
1223 | if (disablev6) | 1266 | GNUNET_free (hostname); |
1224 | hints.ai_family = AF_INET; | 1267 | GNUNET_free_non_null (unixpath); |
1225 | hints.ai_protocol = IPPROTO_TCP; | 1268 | return GNUNET_SYSERR; |
1226 | if ((0 != (ret = getaddrinfo(hostname, NULL, &hints, &res))) || | 1269 | } |
1227 | (NULL == res)) | 1270 | resi = i; |
1228 | { | 1271 | if (NULL != unixpath) |
1229 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1272 | resi++; |
1230 | _("Failed to resolve `%s': %s\n"), | 1273 | saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); |
1231 | hostname, | 1274 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); |
1232 | gai_strerror(ret)); | 1275 | i = 0; |
1233 | GNUNET_free(hostname); | 1276 | if (NULL != unixpath) |
1234 | GNUNET_free_non_null(unixpath); | 1277 | { |
1235 | return GNUNET_SYSERR; | 1278 | add_unixpath (saddrs, saddrlens, unixpath, abstract); |
1236 | } | 1279 | i++; |
1237 | next = res; | 1280 | } |
1238 | i = 0; | 1281 | next = res; |
1239 | while (NULL != (pos = next)) | 1282 | while (NULL != (pos = next)) |
1240 | { | 1283 | { |
1241 | next = pos->ai_next; | 1284 | next = pos->ai_next; |
1242 | if ((disablev6) && (pos->ai_family == AF_INET6)) | 1285 | if ((disablev6) && (AF_INET6 == pos->ai_family)) |
1243 | continue; | 1286 | continue; |
1244 | i++; | 1287 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) |
1245 | } | 1288 | continue; /* not TCP */ |
1246 | if (0 == i) | 1289 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) |
1247 | { | 1290 | continue; /* huh? */ |
1248 | LOG(GNUNET_ERROR_TYPE_ERROR, | 1291 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1249 | _("Failed to find %saddress for `%s'.\n"), | 1292 | "Service `%s' will bind to `%s'\n", |
1250 | disablev6 ? "IPv4 " : "", | 1293 | service_name, |
1251 | hostname); | 1294 | GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); |
1252 | freeaddrinfo(res); | 1295 | if (AF_INET == pos->ai_family) |
1253 | GNUNET_free(hostname); | 1296 | { |
1254 | GNUNET_free_non_null(unixpath); | 1297 | GNUNET_assert (sizeof(struct sockaddr_in) == pos->ai_addrlen); |
1255 | return GNUNET_SYSERR; | 1298 | saddrlens[i] = pos->ai_addrlen; |
1256 | } | 1299 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1257 | resi = i; | 1300 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); |
1301 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); | ||
1302 | } | ||
1303 | else | ||
1304 | { | ||
1305 | GNUNET_assert (AF_INET6 == pos->ai_family); | ||
1306 | GNUNET_assert (sizeof(struct sockaddr_in6) == pos->ai_addrlen); | ||
1307 | saddrlens[i] = pos->ai_addrlen; | ||
1308 | saddrs[i] = GNUNET_malloc (saddrlens[i]); | ||
1309 | GNUNET_memcpy (saddrs[i], pos->ai_addr, saddrlens[i]); | ||
1310 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); | ||
1311 | } | ||
1312 | i++; | ||
1313 | } | ||
1314 | GNUNET_free (hostname); | ||
1315 | freeaddrinfo (res); | ||
1316 | resi = i; | ||
1317 | } | ||
1318 | else | ||
1319 | { | ||
1320 | /* will bind against everything, just set port */ | ||
1321 | if (disablev6) | ||
1322 | { | ||
1323 | /* V4-only */ | ||
1324 | resi = 1; | ||
1258 | if (NULL != unixpath) | 1325 | if (NULL != unixpath) |
1259 | resi++; | 1326 | resi++; |
1260 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); | ||
1261 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); | ||
1262 | i = 0; | 1327 | i = 0; |
1328 | saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); | ||
1329 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); | ||
1263 | if (NULL != unixpath) | 1330 | if (NULL != unixpath) |
1264 | { | 1331 | { |
1265 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | 1332 | add_unixpath (saddrs, saddrlens, unixpath, abstract); |
1266 | i++; | 1333 | i++; |
1267 | } | 1334 | } |
1268 | next = res; | 1335 | saddrlens[i] = sizeof(struct sockaddr_in); |
1269 | while (NULL != (pos = next)) | 1336 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1270 | { | ||
1271 | next = pos->ai_next; | ||
1272 | if ((disablev6) && (AF_INET6 == pos->ai_family)) | ||
1273 | continue; | ||
1274 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) | ||
1275 | continue; /* not TCP */ | ||
1276 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | ||
1277 | continue; /* huh? */ | ||
1278 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
1279 | "Service `%s' will bind to `%s'\n", | ||
1280 | service_name, | ||
1281 | GNUNET_a2s(pos->ai_addr, pos->ai_addrlen)); | ||
1282 | if (AF_INET == pos->ai_family) | ||
1283 | { | ||
1284 | GNUNET_assert(sizeof(struct sockaddr_in) == pos->ai_addrlen); | ||
1285 | saddrlens[i] = pos->ai_addrlen; | ||
1286 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
1287 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
1288 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | ||
1289 | } | ||
1290 | else | ||
1291 | { | ||
1292 | GNUNET_assert(AF_INET6 == pos->ai_family); | ||
1293 | GNUNET_assert(sizeof(struct sockaddr_in6) == pos->ai_addrlen); | ||
1294 | saddrlens[i] = pos->ai_addrlen; | ||
1295 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
1296 | GNUNET_memcpy(saddrs[i], pos->ai_addr, saddrlens[i]); | ||
1297 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); | ||
1298 | } | ||
1299 | i++; | ||
1300 | } | ||
1301 | GNUNET_free(hostname); | ||
1302 | freeaddrinfo(res); | ||
1303 | resi = i; | ||
1304 | } | ||
1305 | else | ||
1306 | { | ||
1307 | /* will bind against everything, just set port */ | ||
1308 | if (disablev6) | ||
1309 | { | ||
1310 | /* V4-only */ | ||
1311 | resi = 1; | ||
1312 | if (NULL != unixpath) | ||
1313 | resi++; | ||
1314 | i = 0; | ||
1315 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); | ||
1316 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); | ||
1317 | if (NULL != unixpath) | ||
1318 | { | ||
1319 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | ||
1320 | i++; | ||
1321 | } | ||
1322 | saddrlens[i] = sizeof(struct sockaddr_in); | ||
1323 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | ||
1324 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1337 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1325 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[i]; | 1338 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[i]; |
1326 | #endif | 1339 | #endif |
1327 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; | 1340 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; |
1328 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | 1341 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); |
1329 | } | 1342 | } |
1330 | else | 1343 | else |
1331 | { | 1344 | { |
1332 | /* dual stack */ | 1345 | /* dual stack */ |
1333 | resi = 2; | 1346 | resi = 2; |
1334 | if (NULL != unixpath) | 1347 | if (NULL != unixpath) |
1335 | resi++; | 1348 | resi++; |
1336 | saddrs = GNUNET_malloc((resi + 1) * sizeof(struct sockaddr *)); | 1349 | saddrs = GNUNET_malloc ((resi + 1) * sizeof(struct sockaddr *)); |
1337 | saddrlens = GNUNET_malloc((resi + 1) * sizeof(socklen_t)); | 1350 | saddrlens = GNUNET_malloc ((resi + 1) * sizeof(socklen_t)); |
1338 | i = 0; | 1351 | i = 0; |
1339 | if (NULL != unixpath) | 1352 | if (NULL != unixpath) |
1340 | { | 1353 | { |
1341 | add_unixpath(saddrs, saddrlens, unixpath, abstract); | 1354 | add_unixpath (saddrs, saddrlens, unixpath, abstract); |
1342 | i++; | 1355 | i++; |
1343 | } | 1356 | } |
1344 | saddrlens[i] = sizeof(struct sockaddr_in6); | 1357 | saddrlens[i] = sizeof(struct sockaddr_in6); |
1345 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | 1358 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1346 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1359 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1347 | ((struct sockaddr_in6 *)saddrs[i])->sin6_len = saddrlens[0]; | 1360 | ((struct sockaddr_in6 *) saddrs[i])->sin6_len = saddrlens[0]; |
1348 | #endif | 1361 | #endif |
1349 | ((struct sockaddr_in6 *)saddrs[i])->sin6_family = AF_INET6; | 1362 | ((struct sockaddr_in6 *) saddrs[i])->sin6_family = AF_INET6; |
1350 | ((struct sockaddr_in6 *)saddrs[i])->sin6_port = htons(port); | 1363 | ((struct sockaddr_in6 *) saddrs[i])->sin6_port = htons (port); |
1351 | i++; | 1364 | i++; |
1352 | saddrlens[i] = sizeof(struct sockaddr_in); | 1365 | saddrlens[i] = sizeof(struct sockaddr_in); |
1353 | saddrs[i] = GNUNET_malloc(saddrlens[i]); | 1366 | saddrs[i] = GNUNET_malloc (saddrlens[i]); |
1354 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1367 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1355 | ((struct sockaddr_in *)saddrs[i])->sin_len = saddrlens[1]; | 1368 | ((struct sockaddr_in *) saddrs[i])->sin_len = saddrlens[1]; |
1356 | #endif | 1369 | #endif |
1357 | ((struct sockaddr_in *)saddrs[i])->sin_family = AF_INET; | 1370 | ((struct sockaddr_in *) saddrs[i])->sin_family = AF_INET; |
1358 | ((struct sockaddr_in *)saddrs[i])->sin_port = htons(port); | 1371 | ((struct sockaddr_in *) saddrs[i])->sin_port = htons (port); |
1359 | } | ||
1360 | } | 1372 | } |
1361 | GNUNET_free_non_null(unixpath); | 1373 | } |
1374 | GNUNET_free_non_null (unixpath); | ||
1362 | *addrs = saddrs; | 1375 | *addrs = saddrs; |
1363 | *addr_lens = saddrlens; | 1376 | *addr_lens = saddrlens; |
1364 | return resi; | 1377 | return resi; |
@@ -1375,26 +1388,26 @@ get_server_addresses(const char *service_name, | |||
1375 | * @param state new state of the session | 1388 | * @param state new state of the session |
1376 | */ | 1389 | */ |
1377 | static void | 1390 | static void |
1378 | notify_session_monitor(struct Plugin *plugin, | 1391 | notify_session_monitor (struct Plugin *plugin, |
1379 | struct GNUNET_ATS_Session *session, | 1392 | struct GNUNET_ATS_Session *session, |
1380 | enum GNUNET_TRANSPORT_SessionState state) | 1393 | enum GNUNET_TRANSPORT_SessionState state) |
1381 | { | 1394 | { |
1382 | struct GNUNET_TRANSPORT_SessionInfo info; | 1395 | struct GNUNET_TRANSPORT_SessionInfo info; |
1383 | 1396 | ||
1384 | if (NULL == plugin->sic) | 1397 | if (NULL == plugin->sic) |
1385 | return; | 1398 | return; |
1386 | memset(&info, 0, sizeof(info)); | 1399 | memset (&info, 0, sizeof(info)); |
1387 | info.state = state; | 1400 | info.state = state; |
1388 | info.is_inbound = | 1401 | info.is_inbound = |
1389 | GNUNET_HELLO_address_check_option(session->address, | 1402 | GNUNET_HELLO_address_check_option (session->address, |
1390 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 1403 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
1391 | info.num_msg_pending = session->msgs_in_queue; | 1404 | info.num_msg_pending = session->msgs_in_queue; |
1392 | info.num_bytes_pending = session->bytes_in_queue; | 1405 | info.num_bytes_pending = session->bytes_in_queue; |
1393 | if (NULL != session->receive_delay_task) | 1406 | if (NULL != session->receive_delay_task) |
1394 | info.receive_delay = session->receive_delay; | 1407 | info.receive_delay = session->receive_delay; |
1395 | info.session_timeout = session->timeout; | 1408 | info.session_timeout = session->timeout; |
1396 | info.address = session->address; | 1409 | info.address = session->address; |
1397 | plugin->sic(plugin->sic_cls, session, &info); | 1410 | plugin->sic (plugin->sic_cls, session, &info); |
1398 | } | 1411 | } |
1399 | 1412 | ||
1400 | 1413 | ||
@@ -1411,12 +1424,12 @@ notify_session_monitor(struct Plugin *plugin, | |||
1411 | * @param addrlen actual length of @a addr | 1424 | * @param addrlen actual length of @a addr |
1412 | */ | 1425 | */ |
1413 | static void | 1426 | static void |
1414 | tcp_nat_port_map_callback(void *cls, | 1427 | tcp_nat_port_map_callback (void *cls, |
1415 | void **app_ctx, | 1428 | void **app_ctx, |
1416 | int add_remove, | 1429 | int add_remove, |
1417 | enum GNUNET_NAT_AddressClass ac, | 1430 | enum GNUNET_NAT_AddressClass ac, |
1418 | const struct sockaddr *addr, | 1431 | const struct sockaddr *addr, |
1419 | socklen_t addrlen) | 1432 | socklen_t addrlen) |
1420 | { | 1433 | { |
1421 | struct Plugin *plugin = cls; | 1434 | struct Plugin *plugin = cls; |
1422 | struct GNUNET_HELLO_Address *address; | 1435 | struct GNUNET_HELLO_Address *address; |
@@ -1425,57 +1438,57 @@ tcp_nat_port_map_callback(void *cls, | |||
1425 | void *arg; | 1438 | void *arg; |
1426 | size_t args; | 1439 | size_t args; |
1427 | 1440 | ||
1428 | (void)app_ctx; | 1441 | (void) app_ctx; |
1429 | LOG(GNUNET_ERROR_TYPE_INFO, | 1442 | LOG (GNUNET_ERROR_TYPE_INFO, |
1430 | "NAT notification to %s address `%s'\n", | 1443 | "NAT notification to %s address `%s'\n", |
1431 | (GNUNET_YES == add_remove) ? "add" : "remove", | 1444 | (GNUNET_YES == add_remove) ? "add" : "remove", |
1432 | GNUNET_a2s(addr, addrlen)); | 1445 | GNUNET_a2s (addr, addrlen)); |
1433 | /* convert 'addr' to our internal format */ | 1446 | /* convert 'addr' to our internal format */ |
1434 | switch (addr->sa_family) | 1447 | switch (addr->sa_family) |
1435 | { | 1448 | { |
1436 | case AF_INET: | 1449 | case AF_INET: |
1437 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); | 1450 | GNUNET_assert (addrlen == sizeof(struct sockaddr_in)); |
1438 | memset(&t4, 0, sizeof(t4)); | 1451 | memset (&t4, 0, sizeof(t4)); |
1439 | t4.options = htonl(plugin->myoptions); | 1452 | t4.options = htonl (plugin->myoptions); |
1440 | t4.ipv4_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr; | 1453 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
1441 | t4.t4_port = ((struct sockaddr_in *)addr)->sin_port; | 1454 | t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; |
1442 | arg = &t4; | 1455 | arg = &t4; |
1443 | args = sizeof(t4); | 1456 | args = sizeof(t4); |
1444 | break; | 1457 | break; |
1445 | 1458 | ||
1446 | case AF_INET6: | 1459 | case AF_INET6: |
1447 | if (IN6_IS_ADDR_LINKLOCAL(&((struct sockaddr_in6 *)addr)->sin6_addr)) | 1460 | if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) |
1448 | { | 1461 | { |
1449 | /* skip link local, we don't allow them in | 1462 | /* skip link local, we don't allow them in |
1450 | #tcp_plugin_check_address() */ | 1463 | #tcp_plugin_check_address() */ |
1451 | return; | ||
1452 | } | ||
1453 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); | ||
1454 | memset(&t6, 0, sizeof(t6)); | ||
1455 | GNUNET_memcpy(&t6.ipv6_addr, | ||
1456 | &((struct sockaddr_in6 *)addr)->sin6_addr, | ||
1457 | sizeof(struct in6_addr)); | ||
1458 | t6.options = htonl(plugin->myoptions); | ||
1459 | t6.t6_port = ((struct sockaddr_in6 *)addr)->sin6_port; | ||
1460 | arg = &t6; | ||
1461 | args = sizeof(t6); | ||
1462 | break; | ||
1463 | |||
1464 | default: | ||
1465 | GNUNET_break(0); | ||
1466 | return; | 1464 | return; |
1467 | } | 1465 | } |
1466 | GNUNET_assert (addrlen == sizeof(struct sockaddr_in6)); | ||
1467 | memset (&t6, 0, sizeof(t6)); | ||
1468 | GNUNET_memcpy (&t6.ipv6_addr, | ||
1469 | &((struct sockaddr_in6 *) addr)->sin6_addr, | ||
1470 | sizeof(struct in6_addr)); | ||
1471 | t6.options = htonl (plugin->myoptions); | ||
1472 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | ||
1473 | arg = &t6; | ||
1474 | args = sizeof(t6); | ||
1475 | break; | ||
1476 | |||
1477 | default: | ||
1478 | GNUNET_break (0); | ||
1479 | return; | ||
1480 | } | ||
1468 | /* modify our published address list */ | 1481 | /* modify our published address list */ |
1469 | GNUNET_assert((args == sizeof(struct IPv4TcpAddress)) || | 1482 | GNUNET_assert ((args == sizeof(struct IPv4TcpAddress)) || |
1470 | (args == sizeof(struct IPv6TcpAddress))); | 1483 | (args == sizeof(struct IPv6TcpAddress))); |
1471 | /* TODO: use 'ac' here in the future... */ | 1484 | /* TODO: use 'ac' here in the future... */ |
1472 | address = GNUNET_HELLO_address_allocate(plugin->env->my_identity, | 1485 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1473 | PLUGIN_NAME, | 1486 | PLUGIN_NAME, |
1474 | arg, | 1487 | arg, |
1475 | args, | 1488 | args, |
1476 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1489 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1477 | plugin->env->notify_address(plugin->env->cls, add_remove, address); | 1490 | plugin->env->notify_address (plugin->env->cls, add_remove, address); |
1478 | GNUNET_HELLO_address_free(address); | 1491 | GNUNET_HELLO_address_free (address); |
1479 | } | 1492 | } |
1480 | 1493 | ||
1481 | 1494 | ||
@@ -1491,7 +1504,7 @@ tcp_nat_port_map_callback(void *cls, | |||
1491 | * @return string representing the same address | 1504 | * @return string representing the same address |
1492 | */ | 1505 | */ |
1493 | static const char * | 1506 | static const char * |
1494 | tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) | 1507 | tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
1495 | { | 1508 | { |
1496 | static char rbuf[INET6_ADDRSTRLEN + 12]; | 1509 | static char rbuf[INET6_ADDRSTRLEN + 12]; |
1497 | char buf[INET6_ADDRSTRLEN]; | 1510 | char buf[INET6_ADDRSTRLEN]; |
@@ -1505,43 +1518,43 @@ tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) | |||
1505 | uint32_t options; | 1518 | uint32_t options; |
1506 | 1519 | ||
1507 | switch (addrlen) | 1520 | switch (addrlen) |
1508 | { | 1521 | { |
1509 | case sizeof(struct IPv6TcpAddress): | 1522 | case sizeof(struct IPv6TcpAddress): |
1510 | t6 = addr; | 1523 | t6 = addr; |
1511 | af = AF_INET6; | 1524 | af = AF_INET6; |
1512 | port = ntohs(t6->t6_port); | 1525 | port = ntohs (t6->t6_port); |
1513 | options = ntohl(t6->options); | 1526 | options = ntohl (t6->options); |
1514 | GNUNET_memcpy(&a6, &t6->ipv6_addr, sizeof(a6)); | 1527 | GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); |
1515 | sb = &a6; | 1528 | sb = &a6; |
1516 | break; | 1529 | break; |
1517 | 1530 | ||
1518 | case sizeof(struct IPv4TcpAddress): | 1531 | case sizeof(struct IPv4TcpAddress): |
1519 | t4 = addr; | 1532 | t4 = addr; |
1520 | af = AF_INET; | 1533 | af = AF_INET; |
1521 | port = ntohs(t4->t4_port); | 1534 | port = ntohs (t4->t4_port); |
1522 | options = ntohl(t4->options); | 1535 | options = ntohl (t4->options); |
1523 | GNUNET_memcpy(&a4, &t4->ipv4_addr, sizeof(a4)); | 1536 | GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); |
1524 | sb = &a4; | 1537 | sb = &a4; |
1525 | break; | 1538 | break; |
1526 | 1539 | ||
1527 | default: | 1540 | default: |
1528 | LOG(GNUNET_ERROR_TYPE_WARNING, | 1541 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1529 | _("Unexpected address length: %u bytes\n"), | 1542 | _ ("Unexpected address length: %u bytes\n"), |
1530 | (unsigned int)addrlen); | 1543 | (unsigned int) addrlen); |
1531 | return NULL; | 1544 | return NULL; |
1532 | } | 1545 | } |
1533 | if (NULL == inet_ntop(af, sb, buf, INET6_ADDRSTRLEN)) | 1546 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) |
1534 | { | 1547 | { |
1535 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); | 1548 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
1536 | return NULL; | 1549 | return NULL; |
1537 | } | 1550 | } |
1538 | GNUNET_snprintf(rbuf, | 1551 | GNUNET_snprintf (rbuf, |
1539 | sizeof(rbuf), | 1552 | sizeof(rbuf), |
1540 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", | 1553 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", |
1541 | PLUGIN_NAME, | 1554 | PLUGIN_NAME, |
1542 | options, | 1555 | options, |
1543 | buf, | 1556 | buf, |
1544 | port); | 1557 | port); |
1545 | return rbuf; | 1558 | return rbuf; |
1546 | } | 1559 | } |
1547 | 1560 | ||
@@ -1559,11 +1572,11 @@ tcp_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) | |||
1559 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1572 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1560 | */ | 1573 | */ |
1561 | static int | 1574 | static int |
1562 | tcp_plugin_string_to_address(void *cls, | 1575 | tcp_plugin_string_to_address (void *cls, |
1563 | const char *addr, | 1576 | const char *addr, |
1564 | uint16_t addrlen, | 1577 | uint16_t addrlen, |
1565 | void **buf, | 1578 | void **buf, |
1566 | size_t *added) | 1579 | size_t *added) |
1567 | { | 1580 | { |
1568 | struct sockaddr_storage socket_address; | 1581 | struct sockaddr_storage socket_address; |
1569 | char *address; | 1582 | char *address; |
@@ -1576,57 +1589,57 @@ tcp_plugin_string_to_address(void *cls, | |||
1576 | plugin = NULL; | 1589 | plugin = NULL; |
1577 | optionstr = NULL; | 1590 | optionstr = NULL; |
1578 | if ((NULL == addr) || (0 == addrlen)) | 1591 | if ((NULL == addr) || (0 == addrlen)) |
1579 | { | 1592 | { |
1580 | GNUNET_break(0); | 1593 | GNUNET_break (0); |
1581 | return GNUNET_SYSERR; | 1594 | return GNUNET_SYSERR; |
1582 | } | 1595 | } |
1583 | if ('\0' != addr[addrlen - 1]) | 1596 | if ('\0' != addr[addrlen - 1]) |
1584 | { | 1597 | { |
1585 | GNUNET_break(0); | 1598 | GNUNET_break (0); |
1586 | return GNUNET_SYSERR; | 1599 | return GNUNET_SYSERR; |
1587 | } | 1600 | } |
1588 | if (strlen(addr) != addrlen - 1) | 1601 | if (strlen (addr) != addrlen - 1) |
1589 | { | 1602 | { |
1590 | GNUNET_break(0); | 1603 | GNUNET_break (0); |
1591 | return GNUNET_SYSERR; | 1604 | return GNUNET_SYSERR; |
1592 | } | 1605 | } |
1593 | plugin = GNUNET_strdup(addr); | 1606 | plugin = GNUNET_strdup (addr); |
1594 | optionstr = strchr(plugin, '.'); | 1607 | optionstr = strchr (plugin, '.'); |
1595 | if (NULL == optionstr) | 1608 | if (NULL == optionstr) |
1596 | { | 1609 | { |
1597 | GNUNET_break(0); | 1610 | GNUNET_break (0); |
1598 | GNUNET_free(plugin); | 1611 | GNUNET_free (plugin); |
1599 | return GNUNET_SYSERR; | 1612 | return GNUNET_SYSERR; |
1600 | } | 1613 | } |
1601 | optionstr[0] = '\0'; | 1614 | optionstr[0] = '\0'; |
1602 | optionstr++; | 1615 | optionstr++; |
1603 | options = atol(optionstr); | 1616 | options = atol (optionstr); |
1604 | address = strchr(optionstr, '.'); | 1617 | address = strchr (optionstr, '.'); |
1605 | if (NULL == address) | 1618 | if (NULL == address) |
1606 | { | 1619 | { |
1607 | GNUNET_break(0); | 1620 | GNUNET_break (0); |
1608 | GNUNET_free(plugin); | 1621 | GNUNET_free (plugin); |
1609 | return GNUNET_SYSERR; | 1622 | return GNUNET_SYSERR; |
1610 | } | 1623 | } |
1611 | address[0] = '\0'; | 1624 | address[0] = '\0'; |
1612 | address++; | 1625 | address++; |
1613 | 1626 | ||
1614 | if (GNUNET_OK != | 1627 | if (GNUNET_OK != |
1615 | GNUNET_STRINGS_to_address_ip(address, strlen(address), &socket_address)) | 1628 | GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) |
1616 | { | 1629 | { |
1617 | GNUNET_break(0); | 1630 | GNUNET_break (0); |
1618 | GNUNET_free(plugin); | 1631 | GNUNET_free (plugin); |
1619 | return GNUNET_SYSERR; | 1632 | return GNUNET_SYSERR; |
1620 | } | 1633 | } |
1621 | 1634 | ||
1622 | GNUNET_free(plugin); | 1635 | GNUNET_free (plugin); |
1623 | switch (socket_address.ss_family) | 1636 | switch (socket_address.ss_family) |
1624 | { | 1637 | { |
1625 | case AF_INET: { | 1638 | case AF_INET: { |
1626 | struct IPv4TcpAddress *t4; | 1639 | struct IPv4TcpAddress *t4; |
1627 | struct sockaddr_in *in4 = (struct sockaddr_in *)&socket_address; | 1640 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; |
1628 | t4 = GNUNET_new(struct IPv4TcpAddress); | 1641 | t4 = GNUNET_new (struct IPv4TcpAddress); |
1629 | t4->options = htonl(options); | 1642 | t4->options = htonl (options); |
1630 | t4->ipv4_addr = in4->sin_addr.s_addr; | 1643 | t4->ipv4_addr = in4->sin_addr.s_addr; |
1631 | t4->t4_port = in4->sin_port; | 1644 | t4->t4_port = in4->sin_port; |
1632 | *buf = t4; | 1645 | *buf = t4; |
@@ -1634,11 +1647,11 @@ tcp_plugin_string_to_address(void *cls, | |||
1634 | return GNUNET_OK; | 1647 | return GNUNET_OK; |
1635 | } | 1648 | } |
1636 | 1649 | ||
1637 | case AF_INET6: { | 1650 | case AF_INET6: { |
1638 | struct IPv6TcpAddress *t6; | 1651 | struct IPv6TcpAddress *t6; |
1639 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)&socket_address; | 1652 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; |
1640 | t6 = GNUNET_new(struct IPv6TcpAddress); | 1653 | t6 = GNUNET_new (struct IPv6TcpAddress); |
1641 | t6->options = htonl(options); | 1654 | t6->options = htonl (options); |
1642 | t6->ipv6_addr = in6->sin6_addr; | 1655 | t6->ipv6_addr = in6->sin6_addr; |
1643 | t6->t6_port = in6->sin6_port; | 1656 | t6->t6_port = in6->sin6_port; |
1644 | *buf = t6; | 1657 | *buf = t6; |
@@ -1646,9 +1659,9 @@ tcp_plugin_string_to_address(void *cls, | |||
1646 | return GNUNET_OK; | 1659 | return GNUNET_OK; |
1647 | } | 1660 | } |
1648 | 1661 | ||
1649 | default: | 1662 | default: |
1650 | return GNUNET_SYSERR; | 1663 | return GNUNET_SYSERR; |
1651 | } | 1664 | } |
1652 | } | 1665 | } |
1653 | 1666 | ||
1654 | 1667 | ||
@@ -1663,11 +1676,11 @@ tcp_plugin_string_to_address(void *cls, | |||
1663 | * @return NULL if no matching session exists | 1676 | * @return NULL if no matching session exists |
1664 | */ | 1677 | */ |
1665 | static struct GNUNET_ATS_Session * | 1678 | static struct GNUNET_ATS_Session * |
1666 | lookup_session_by_client(struct Plugin *plugin, | 1679 | lookup_session_by_client (struct Plugin *plugin, |
1667 | struct GNUNET_SERVER_Client *client) | 1680 | struct GNUNET_SERVER_Client *client) |
1668 | { | 1681 | { |
1669 | return GNUNET_SERVER_client_get_user_context(client, | 1682 | return GNUNET_SERVER_client_get_user_context (client, |
1670 | struct GNUNET_ATS_Session); | 1683 | struct GNUNET_ATS_Session); |
1671 | } | 1684 | } |
1672 | 1685 | ||
1673 | 1686 | ||
@@ -1681,111 +1694,111 @@ lookup_session_by_client(struct Plugin *plugin, | |||
1681 | * @return #GNUNET_OK on success | 1694 | * @return #GNUNET_OK on success |
1682 | */ | 1695 | */ |
1683 | static int | 1696 | static int |
1684 | tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session) | 1697 | tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session) |
1685 | { | 1698 | { |
1686 | struct Plugin *plugin = cls; | 1699 | struct Plugin *plugin = cls; |
1687 | struct PendingMessage *pm; | 1700 | struct PendingMessage *pm; |
1688 | 1701 | ||
1689 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1702 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1690 | "Disconnecting session of peer `%s' address `%s'\n", | 1703 | "Disconnecting session of peer `%s' address `%s'\n", |
1691 | GNUNET_i2s(&session->target), | 1704 | GNUNET_i2s (&session->target), |
1692 | tcp_plugin_address_to_string(session->plugin, | 1705 | tcp_plugin_address_to_string (session->plugin, |
1693 | session->address->address, | 1706 | session->address->address, |
1694 | session->address->address_length)); | 1707 | session->address->address_length)); |
1695 | 1708 | ||
1696 | if (NULL != session->timeout_task) | 1709 | if (NULL != session->timeout_task) |
1697 | { | 1710 | { |
1698 | GNUNET_SCHEDULER_cancel(session->timeout_task); | 1711 | GNUNET_SCHEDULER_cancel (session->timeout_task); |
1699 | session->timeout_task = NULL; | 1712 | session->timeout_task = NULL; |
1700 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 1713 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
1701 | } | 1714 | } |
1702 | 1715 | ||
1703 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove(plugin->sessionmap, | 1716 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, |
1704 | &session->target, | 1717 | &session->target, |
1705 | session)) | 1718 | session)) |
1706 | { | 1719 | { |
1707 | GNUNET_STATISTICS_update(session->plugin->env->stats, | 1720 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1708 | gettext_noop("# TCP sessions active"), | 1721 | gettext_noop ("# TCP sessions active"), |
1709 | -1, | 1722 | -1, |
1710 | GNUNET_NO); | 1723 | GNUNET_NO); |
1711 | } | 1724 | } |
1712 | else | 1725 | else |
1713 | { | 1726 | { |
1714 | GNUNET_assert(GNUNET_YES == | 1727 | GNUNET_assert (GNUNET_YES == |
1715 | GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns, | 1728 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, |
1716 | &session->target, | 1729 | &session->target, |
1717 | session)); | 1730 | session)); |
1718 | } | 1731 | } |
1719 | if (NULL != session->client) | 1732 | if (NULL != session->client) |
1720 | GNUNET_SERVER_client_set_user_context(session->client, NULL); | 1733 | GNUNET_SERVER_client_set_user_context (session->client, NULL); |
1721 | 1734 | ||
1722 | /* clean up state */ | 1735 | /* clean up state */ |
1723 | if (NULL != session->transmit_handle) | 1736 | if (NULL != session->transmit_handle) |
1724 | { | 1737 | { |
1725 | GNUNET_SERVER_notify_transmit_ready_cancel(session->transmit_handle); | 1738 | GNUNET_SERVER_notify_transmit_ready_cancel (session->transmit_handle); |
1726 | session->transmit_handle = NULL; | 1739 | session->transmit_handle = NULL; |
1727 | } | 1740 | } |
1728 | session->plugin->env->session_end(session->plugin->env->cls, | 1741 | session->plugin->env->session_end (session->plugin->env->cls, |
1729 | session->address, | 1742 | session->address, |
1730 | session); | 1743 | session); |
1731 | 1744 | ||
1732 | if (NULL != session->nat_connection_timeout) | 1745 | if (NULL != session->nat_connection_timeout) |
1733 | { | 1746 | { |
1734 | GNUNET_SCHEDULER_cancel(session->nat_connection_timeout); | 1747 | GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); |
1735 | session->nat_connection_timeout = NULL; | 1748 | session->nat_connection_timeout = NULL; |
1736 | } | 1749 | } |
1737 | 1750 | ||
1738 | while (NULL != (pm = session->pending_messages_head)) | 1751 | while (NULL != (pm = session->pending_messages_head)) |
1739 | { | 1752 | { |
1740 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1753 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1741 | (NULL != pm->transmit_cont) | 1754 | (NULL != pm->transmit_cont) |
1742 | ? "Could not deliver message to `%s' at %s.\n" | 1755 | ? "Could not deliver message to `%s' at %s.\n" |
1743 | : "Could not deliver message to `%s' at %s, notifying.\n", | 1756 | : "Could not deliver message to `%s' at %s, notifying.\n", |
1744 | GNUNET_i2s(&session->target), | 1757 | GNUNET_i2s (&session->target), |
1745 | tcp_plugin_address_to_string(session->plugin, | 1758 | tcp_plugin_address_to_string (session->plugin, |
1746 | session->address->address, | 1759 | session->address->address, |
1747 | session->address->address_length)); | 1760 | session->address->address_length)); |
1748 | GNUNET_STATISTICS_update(session->plugin->env->stats, | 1761 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1749 | gettext_noop("# bytes currently in TCP buffers"), | 1762 | gettext_noop ("# bytes currently in TCP buffers"), |
1750 | -(int64_t)pm->message_size, | 1763 | -(int64_t) pm->message_size, |
1751 | GNUNET_NO); | 1764 | GNUNET_NO); |
1752 | GNUNET_STATISTICS_update(session->plugin->env->stats, | 1765 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1753 | gettext_noop( | 1766 | gettext_noop ( |
1754 | "# bytes discarded by TCP (disconnect)"), | 1767 | "# bytes discarded by TCP (disconnect)"), |
1755 | pm->message_size, | 1768 | pm->message_size, |
1756 | GNUNET_NO); | 1769 | GNUNET_NO); |
1757 | GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, | 1770 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
1758 | session->pending_messages_tail, | 1771 | session->pending_messages_tail, |
1759 | pm); | 1772 | pm); |
1760 | GNUNET_assert(0 < session->msgs_in_queue); | 1773 | GNUNET_assert (0 < session->msgs_in_queue); |
1761 | session->msgs_in_queue--; | 1774 | session->msgs_in_queue--; |
1762 | GNUNET_assert(pm->message_size <= session->bytes_in_queue); | 1775 | GNUNET_assert (pm->message_size <= session->bytes_in_queue); |
1763 | session->bytes_in_queue -= pm->message_size; | 1776 | session->bytes_in_queue -= pm->message_size; |
1764 | if (NULL != pm->transmit_cont) | 1777 | if (NULL != pm->transmit_cont) |
1765 | pm->transmit_cont(pm->transmit_cont_cls, | 1778 | pm->transmit_cont (pm->transmit_cont_cls, |
1766 | &session->target, | 1779 | &session->target, |
1767 | GNUNET_SYSERR, | 1780 | GNUNET_SYSERR, |
1768 | pm->message_size, | 1781 | pm->message_size, |
1769 | 0); | 1782 | 0); |
1770 | GNUNET_free(pm); | 1783 | GNUNET_free (pm); |
1771 | } | 1784 | } |
1772 | GNUNET_assert(0 == session->msgs_in_queue); | 1785 | GNUNET_assert (0 == session->msgs_in_queue); |
1773 | GNUNET_assert(0 == session->bytes_in_queue); | 1786 | GNUNET_assert (0 == session->bytes_in_queue); |
1774 | notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_DONE); | 1787 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE); |
1775 | 1788 | ||
1776 | if (NULL != session->receive_delay_task) | 1789 | if (NULL != session->receive_delay_task) |
1777 | { | 1790 | { |
1778 | GNUNET_SCHEDULER_cancel(session->receive_delay_task); | 1791 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
1779 | session->receive_delay_task = NULL; | 1792 | session->receive_delay_task = NULL; |
1780 | } | 1793 | } |
1781 | if (NULL != session->client) | 1794 | if (NULL != session->client) |
1782 | { | 1795 | { |
1783 | GNUNET_SERVER_client_disconnect(session->client); | 1796 | GNUNET_SERVER_client_disconnect (session->client); |
1784 | session->client = NULL; | 1797 | session->client = NULL; |
1785 | } | 1798 | } |
1786 | GNUNET_HELLO_address_free(session->address); | 1799 | GNUNET_HELLO_address_free (session->address); |
1787 | GNUNET_assert(NULL == session->transmit_handle); | 1800 | GNUNET_assert (NULL == session->transmit_handle); |
1788 | GNUNET_free(session); | 1801 | GNUNET_free (session); |
1789 | return GNUNET_OK; | 1802 | return GNUNET_OK; |
1790 | } | 1803 | } |
1791 | 1804 | ||
@@ -1799,7 +1812,7 @@ tcp_plugin_disconnect_session(void *cls, struct GNUNET_ATS_Session *session) | |||
1799 | * @return keepalive factor | 1812 | * @return keepalive factor |
1800 | */ | 1813 | */ |
1801 | static unsigned int | 1814 | static unsigned int |
1802 | tcp_plugin_query_keepalive_factor(void *cls) | 1815 | tcp_plugin_query_keepalive_factor (void *cls) |
1803 | { | 1816 | { |
1804 | return 3; | 1817 | return 3; |
1805 | } | 1818 | } |
@@ -1811,29 +1824,29 @@ tcp_plugin_query_keepalive_factor(void *cls) | |||
1811 | * @param cls the `struct GNUNET_ATS_Session` of the idle session | 1824 | * @param cls the `struct GNUNET_ATS_Session` of the idle session |
1812 | */ | 1825 | */ |
1813 | static void | 1826 | static void |
1814 | session_timeout(void *cls) | 1827 | session_timeout (void *cls) |
1815 | { | 1828 | { |
1816 | struct GNUNET_ATS_Session *s = cls; | 1829 | struct GNUNET_ATS_Session *s = cls; |
1817 | struct GNUNET_TIME_Relative left; | 1830 | struct GNUNET_TIME_Relative left; |
1818 | 1831 | ||
1819 | s->timeout_task = NULL; | 1832 | s->timeout_task = NULL; |
1820 | left = GNUNET_TIME_absolute_get_remaining(s->timeout); | 1833 | left = GNUNET_TIME_absolute_get_remaining (s->timeout); |
1821 | if (0 != left.rel_value_us) | 1834 | if (0 != left.rel_value_us) |
1822 | { | 1835 | { |
1823 | /* not actually our turn yet, but let's at least update | 1836 | /* not actually our turn yet, but let's at least update |
1824 | the monitor, it may think we're about to die ... */ | 1837 | the monitor, it may think we're about to die ... */ |
1825 | notify_session_monitor(s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); | 1838 | notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); |
1826 | s->timeout_task = GNUNET_SCHEDULER_add_delayed(left, &session_timeout, s); | 1839 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); |
1827 | return; | 1840 | return; |
1828 | } | 1841 | } |
1829 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1842 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1830 | "Session %p was idle for %s, disconnecting\n", | 1843 | "Session %p was idle for %s, disconnecting\n", |
1831 | s, | 1844 | s, |
1832 | GNUNET_STRINGS_relative_time_to_string( | 1845 | GNUNET_STRINGS_relative_time_to_string ( |
1833 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1846 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1834 | GNUNET_YES)); | 1847 | GNUNET_YES)); |
1835 | /* call session destroy function */ | 1848 | /* call session destroy function */ |
1836 | tcp_plugin_disconnect_session(s->plugin, s); | 1849 | tcp_plugin_disconnect_session (s->plugin, s); |
1837 | } | 1850 | } |
1838 | 1851 | ||
1839 | 1852 | ||
@@ -1843,11 +1856,11 @@ session_timeout(void *cls) | |||
1843 | * @param s session to increment timeout for | 1856 | * @param s session to increment timeout for |
1844 | */ | 1857 | */ |
1845 | static void | 1858 | static void |
1846 | reschedule_session_timeout(struct GNUNET_ATS_Session *s) | 1859 | reschedule_session_timeout (struct GNUNET_ATS_Session *s) |
1847 | { | 1860 | { |
1848 | GNUNET_assert(NULL != s->timeout_task); | 1861 | GNUNET_assert (NULL != s->timeout_task); |
1849 | s->timeout = | 1862 | s->timeout = |
1850 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1863 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1851 | } | 1864 | } |
1852 | 1865 | ||
1853 | 1866 | ||
@@ -1864,75 +1877,75 @@ reschedule_session_timeout(struct GNUNET_ATS_Session *s) | |||
1864 | * @return new session object | 1877 | * @return new session object |
1865 | */ | 1878 | */ |
1866 | static struct GNUNET_ATS_Session * | 1879 | static struct GNUNET_ATS_Session * |
1867 | create_session(struct Plugin *plugin, | 1880 | create_session (struct Plugin *plugin, |
1868 | const struct GNUNET_HELLO_Address *address, | 1881 | const struct GNUNET_HELLO_Address *address, |
1869 | enum GNUNET_NetworkType scope, | 1882 | enum GNUNET_NetworkType scope, |
1870 | struct GNUNET_SERVER_Client *client, | 1883 | struct GNUNET_SERVER_Client *client, |
1871 | int is_nat) | 1884 | int is_nat) |
1872 | { | 1885 | { |
1873 | struct GNUNET_ATS_Session *session; | 1886 | struct GNUNET_ATS_Session *session; |
1874 | struct PendingMessage *pm; | 1887 | struct PendingMessage *pm; |
1875 | 1888 | ||
1876 | if (GNUNET_YES != is_nat) | 1889 | if (GNUNET_YES != is_nat) |
1877 | GNUNET_assert(NULL != client); | 1890 | GNUNET_assert (NULL != client); |
1878 | else | 1891 | else |
1879 | GNUNET_assert(NULL == client); | 1892 | GNUNET_assert (NULL == client); |
1880 | 1893 | ||
1881 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1894 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1882 | "Creating new session for peer `%s' at address %s\n", | 1895 | "Creating new session for peer `%s' at address %s\n", |
1883 | GNUNET_i2s(&address->peer), | 1896 | GNUNET_i2s (&address->peer), |
1884 | tcp_plugin_address_to_string(plugin, | 1897 | tcp_plugin_address_to_string (plugin, |
1885 | address->address, | 1898 | address->address, |
1886 | address->address_length)); | 1899 | address->address_length)); |
1887 | session = GNUNET_new(struct GNUNET_ATS_Session); | 1900 | session = GNUNET_new (struct GNUNET_ATS_Session); |
1888 | session->last_activity = GNUNET_TIME_absolute_get(); | 1901 | session->last_activity = GNUNET_TIME_absolute_get (); |
1889 | session->plugin = plugin; | 1902 | session->plugin = plugin; |
1890 | session->is_nat = is_nat; | 1903 | session->is_nat = is_nat; |
1891 | if (NULL != client) | 1904 | if (NULL != client) |
1892 | { | 1905 | { |
1893 | session->client = client; | 1906 | session->client = client; |
1894 | GNUNET_SERVER_client_set_user_context(client, session); | 1907 | GNUNET_SERVER_client_set_user_context (client, session); |
1895 | } | 1908 | } |
1896 | session->address = GNUNET_HELLO_address_copy(address); | 1909 | session->address = GNUNET_HELLO_address_copy (address); |
1897 | session->target = address->peer; | 1910 | session->target = address->peer; |
1898 | session->expecting_welcome = GNUNET_YES; | 1911 | session->expecting_welcome = GNUNET_YES; |
1899 | session->scope = scope; | 1912 | session->scope = scope; |
1900 | pm = GNUNET_malloc(sizeof(struct PendingMessage) + | 1913 | pm = GNUNET_malloc (sizeof(struct PendingMessage) |
1901 | sizeof(struct WelcomeMessage)); | 1914 | + sizeof(struct WelcomeMessage)); |
1902 | pm->msg = (const char *)&pm[1]; | 1915 | pm->msg = (const char *) &pm[1]; |
1903 | pm->message_size = sizeof(struct WelcomeMessage); | 1916 | pm->message_size = sizeof(struct WelcomeMessage); |
1904 | GNUNET_memcpy(&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage)); | 1917 | GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof(struct WelcomeMessage)); |
1905 | pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 1918 | pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
1906 | GNUNET_STATISTICS_update(plugin->env->stats, | 1919 | GNUNET_STATISTICS_update (plugin->env->stats, |
1907 | gettext_noop("# bytes currently in TCP buffers"), | 1920 | gettext_noop ("# bytes currently in TCP buffers"), |
1908 | pm->message_size, | 1921 | pm->message_size, |
1909 | GNUNET_NO); | 1922 | GNUNET_NO); |
1910 | GNUNET_CONTAINER_DLL_insert(session->pending_messages_head, | 1923 | GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, |
1911 | session->pending_messages_tail, | 1924 | session->pending_messages_tail, |
1912 | pm); | 1925 | pm); |
1913 | session->msgs_in_queue++; | 1926 | session->msgs_in_queue++; |
1914 | session->bytes_in_queue += pm->message_size; | 1927 | session->bytes_in_queue += pm->message_size; |
1915 | session->timeout = | 1928 | session->timeout = |
1916 | GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1929 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1917 | session->timeout_task = | 1930 | session->timeout_task = |
1918 | GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1931 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1919 | &session_timeout, | 1932 | &session_timeout, |
1920 | session); | 1933 | session); |
1921 | notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_INIT); | 1934 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT); |
1922 | if (GNUNET_YES != is_nat) | 1935 | if (GNUNET_YES != is_nat) |
1923 | { | 1936 | { |
1924 | GNUNET_STATISTICS_update(plugin->env->stats, | 1937 | GNUNET_STATISTICS_update (plugin->env->stats, |
1925 | gettext_noop("# TCP sessions active"), | 1938 | gettext_noop ("# TCP sessions active"), |
1926 | 1, | 1939 | 1, |
1927 | GNUNET_NO); | 1940 | GNUNET_NO); |
1928 | notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UP); | 1941 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP); |
1929 | } | 1942 | } |
1930 | else | 1943 | else |
1931 | { | 1944 | { |
1932 | notify_session_monitor(session->plugin, | 1945 | notify_session_monitor (session->plugin, |
1933 | session, | 1946 | session, |
1934 | GNUNET_TRANSPORT_SS_HANDSHAKE); | 1947 | GNUNET_TRANSPORT_SS_HANDSHAKE); |
1935 | } | 1948 | } |
1936 | return session; | 1949 | return session; |
1937 | } | 1950 | } |
1938 | 1951 | ||
@@ -1944,7 +1957,7 @@ create_session(struct Plugin *plugin, | |||
1944 | * @param session for which session should we do this | 1957 | * @param session for which session should we do this |
1945 | */ | 1958 | */ |
1946 | static void | 1959 | static void |
1947 | process_pending_messages(struct GNUNET_ATS_Session *session); | 1960 | process_pending_messages (struct GNUNET_ATS_Session *session); |
1948 | 1961 | ||
1949 | 1962 | ||
1950 | /** | 1963 | /** |
@@ -1959,7 +1972,7 @@ process_pending_messages(struct GNUNET_ATS_Session *session); | |||
1959 | * @return number of bytes written to @a buf | 1972 | * @return number of bytes written to @a buf |
1960 | */ | 1973 | */ |
1961 | static size_t | 1974 | static size_t |
1962 | do_transmit(void *cls, size_t size, void *buf) | 1975 | do_transmit (void *cls, size_t size, void *buf) |
1963 | { | 1976 | { |
1964 | struct GNUNET_ATS_Session *session = cls; | 1977 | struct GNUNET_ATS_Session *session = cls; |
1965 | struct GNUNET_PeerIdentity pid; | 1978 | struct GNUNET_PeerIdentity pid; |
@@ -1974,127 +1987,127 @@ do_transmit(void *cls, size_t size, void *buf) | |||
1974 | session->transmit_handle = NULL; | 1987 | session->transmit_handle = NULL; |
1975 | plugin = session->plugin; | 1988 | plugin = session->plugin; |
1976 | if (NULL == buf) | 1989 | if (NULL == buf) |
1977 | { | 1990 | { |
1978 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 1991 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1979 | "Timeout trying to transmit to peer `%s', discarding message queue.\n", | 1992 | "Timeout trying to transmit to peer `%s', discarding message queue.\n", |
1980 | GNUNET_i2s(&session->target)); | 1993 | GNUNET_i2s (&session->target)); |
1981 | /* timeout; cancel all messages that have already expired */ | 1994 | /* timeout; cancel all messages that have already expired */ |
1982 | hd = NULL; | 1995 | hd = NULL; |
1983 | tl = NULL; | 1996 | tl = NULL; |
1984 | ret = 0; | 1997 | ret = 0; |
1985 | now = GNUNET_TIME_absolute_get(); | 1998 | now = GNUNET_TIME_absolute_get (); |
1986 | while ((NULL != (pos = session->pending_messages_head)) && | 1999 | while ((NULL != (pos = session->pending_messages_head)) && |
1987 | (pos->timeout.abs_value_us <= now.abs_value_us)) | 2000 | (pos->timeout.abs_value_us <= now.abs_value_us)) |
1988 | { | 2001 | { |
1989 | GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, | 2002 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
1990 | session->pending_messages_tail, | 2003 | session->pending_messages_tail, |
1991 | pos); | 2004 | pos); |
1992 | GNUNET_assert(0 < session->msgs_in_queue); | 2005 | GNUNET_assert (0 < session->msgs_in_queue); |
1993 | session->msgs_in_queue--; | 2006 | session->msgs_in_queue--; |
1994 | GNUNET_assert(pos->message_size <= session->bytes_in_queue); | 2007 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); |
1995 | session->bytes_in_queue -= pos->message_size; | 2008 | session->bytes_in_queue -= pos->message_size; |
1996 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2009 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1997 | "Failed to transmit %u byte message to `%s'.\n", | 2010 | "Failed to transmit %u byte message to `%s'.\n", |
1998 | pos->message_size, | 2011 | pos->message_size, |
1999 | GNUNET_i2s(&session->target)); | 2012 | GNUNET_i2s (&session->target)); |
2000 | ret += pos->message_size; | 2013 | ret += pos->message_size; |
2001 | GNUNET_CONTAINER_DLL_insert_after(hd, tl, tl, pos); | 2014 | GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); |
2002 | } | 2015 | } |
2003 | /* do this call before callbacks (so that if callbacks destroy | 2016 | /* do this call before callbacks (so that if callbacks destroy |
2004 | * session, they have a chance to cancel actions done by this | 2017 | * session, they have a chance to cancel actions done by this |
2005 | * call) */ | 2018 | * call) */ |
2006 | process_pending_messages(session); | 2019 | process_pending_messages (session); |
2007 | pid = session->target; | 2020 | pid = session->target; |
2008 | /* no do callbacks and do not use session again since | 2021 | /* no do callbacks and do not use session again since |
2009 | * the callbacks may abort the session */ | 2022 | * the callbacks may abort the session */ |
2010 | while (NULL != (pos = hd)) | 2023 | while (NULL != (pos = hd)) |
2011 | { | 2024 | { |
2012 | GNUNET_CONTAINER_DLL_remove(hd, tl, pos); | 2025 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); |
2013 | if (NULL != pos->transmit_cont) | 2026 | if (NULL != pos->transmit_cont) |
2014 | pos->transmit_cont(pos->transmit_cont_cls, | 2027 | pos->transmit_cont (pos->transmit_cont_cls, |
2015 | &pid, | 2028 | &pid, |
2016 | GNUNET_SYSERR, | 2029 | GNUNET_SYSERR, |
2017 | pos->message_size, | 2030 | pos->message_size, |
2018 | 0); | 2031 | 0); |
2019 | GNUNET_free(pos); | 2032 | GNUNET_free (pos); |
2020 | } | 2033 | } |
2021 | GNUNET_STATISTICS_update(plugin->env->stats, | 2034 | GNUNET_STATISTICS_update (plugin->env->stats, |
2022 | gettext_noop("# bytes currently in TCP buffers"), | 2035 | gettext_noop ("# bytes currently in TCP buffers"), |
2023 | -(int64_t)ret, | 2036 | -(int64_t) ret, |
2024 | GNUNET_NO); | 2037 | GNUNET_NO); |
2025 | GNUNET_STATISTICS_update(plugin->env->stats, | 2038 | GNUNET_STATISTICS_update (plugin->env->stats, |
2026 | gettext_noop( | 2039 | gettext_noop ( |
2027 | "# bytes discarded by TCP (timeout)"), | 2040 | "# bytes discarded by TCP (timeout)"), |
2028 | ret, | 2041 | ret, |
2029 | GNUNET_NO); | 2042 | GNUNET_NO); |
2030 | if (0 < ret) | 2043 | if (0 < ret) |
2031 | notify_session_monitor(session->plugin, | 2044 | notify_session_monitor (session->plugin, |
2032 | session, | 2045 | session, |
2033 | GNUNET_TRANSPORT_SS_UPDATE); | 2046 | GNUNET_TRANSPORT_SS_UPDATE); |
2034 | return 0; | 2047 | return 0; |
2035 | } | 2048 | } |
2036 | /* copy all pending messages that would fit */ | 2049 | /* copy all pending messages that would fit */ |
2037 | ret = 0; | 2050 | ret = 0; |
2038 | cbuf = buf; | 2051 | cbuf = buf; |
2039 | hd = NULL; | 2052 | hd = NULL; |
2040 | tl = NULL; | 2053 | tl = NULL; |
2041 | while (NULL != (pos = session->pending_messages_head)) | 2054 | while (NULL != (pos = session->pending_messages_head)) |
2042 | { | 2055 | { |
2043 | if (ret + pos->message_size > size) | 2056 | if (ret + pos->message_size > size) |
2044 | break; | 2057 | break; |
2045 | GNUNET_CONTAINER_DLL_remove(session->pending_messages_head, | 2058 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
2046 | session->pending_messages_tail, | 2059 | session->pending_messages_tail, |
2047 | pos); | 2060 | pos); |
2048 | GNUNET_assert(0 < session->msgs_in_queue); | 2061 | GNUNET_assert (0 < session->msgs_in_queue); |
2049 | session->msgs_in_queue--; | 2062 | session->msgs_in_queue--; |
2050 | GNUNET_assert(pos->message_size <= session->bytes_in_queue); | 2063 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); |
2051 | session->bytes_in_queue -= pos->message_size; | 2064 | session->bytes_in_queue -= pos->message_size; |
2052 | GNUNET_assert(size >= pos->message_size); | 2065 | GNUNET_assert (size >= pos->message_size); |
2053 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2066 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2054 | "Transmitting message of type %u size %u to peer %s at %s\n", | 2067 | "Transmitting message of type %u size %u to peer %s at %s\n", |
2055 | ntohs(((struct GNUNET_MessageHeader *)pos->msg)->type), | 2068 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), |
2056 | pos->message_size, | 2069 | pos->message_size, |
2057 | GNUNET_i2s(&session->target), | 2070 | GNUNET_i2s (&session->target), |
2058 | tcp_plugin_address_to_string(session->plugin, | 2071 | tcp_plugin_address_to_string (session->plugin, |
2059 | session->address->address, | 2072 | session->address->address, |
2060 | session->address->address_length)); | 2073 | session->address->address_length)); |
2061 | /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ | 2074 | /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ |
2062 | GNUNET_memcpy(cbuf, pos->msg, pos->message_size); | 2075 | GNUNET_memcpy (cbuf, pos->msg, pos->message_size); |
2063 | cbuf += pos->message_size; | 2076 | cbuf += pos->message_size; |
2064 | ret += pos->message_size; | 2077 | ret += pos->message_size; |
2065 | size -= pos->message_size; | 2078 | size -= pos->message_size; |
2066 | GNUNET_CONTAINER_DLL_insert_tail(hd, tl, pos); | 2079 | GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); |
2067 | } | 2080 | } |
2068 | notify_session_monitor(session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); | 2081 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
2069 | /* schedule 'continuation' before callbacks so that callbacks that | 2082 | /* schedule 'continuation' before callbacks so that callbacks that |
2070 | * cancel everything don't cause us to use a session that no longer | 2083 | * cancel everything don't cause us to use a session that no longer |
2071 | * exists... */ | 2084 | * exists... */ |
2072 | process_pending_messages(session); | 2085 | process_pending_messages (session); |
2073 | session->last_activity = GNUNET_TIME_absolute_get(); | 2086 | session->last_activity = GNUNET_TIME_absolute_get (); |
2074 | pid = session->target; | 2087 | pid = session->target; |
2075 | /* we'll now call callbacks that may cancel the session; hence | 2088 | /* we'll now call callbacks that may cancel the session; hence |
2076 | * we should not use 'session' after this point */ | 2089 | * we should not use 'session' after this point */ |
2077 | while (NULL != (pos = hd)) | 2090 | while (NULL != (pos = hd)) |
2078 | { | 2091 | { |
2079 | GNUNET_CONTAINER_DLL_remove(hd, tl, pos); | 2092 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); |
2080 | if (NULL != pos->transmit_cont) | 2093 | if (NULL != pos->transmit_cont) |
2081 | pos->transmit_cont(pos->transmit_cont_cls, | 2094 | pos->transmit_cont (pos->transmit_cont_cls, |
2082 | &pid, | 2095 | &pid, |
2083 | GNUNET_OK, | 2096 | GNUNET_OK, |
2084 | pos->message_size, | 2097 | pos->message_size, |
2085 | pos->message_size); /* FIXME: include TCP overhead */ | 2098 | pos->message_size); /* FIXME: include TCP overhead */ |
2086 | GNUNET_free(pos); | 2099 | GNUNET_free (pos); |
2087 | } | 2100 | } |
2088 | GNUNET_assert(NULL == hd); | 2101 | GNUNET_assert (NULL == hd); |
2089 | GNUNET_assert(NULL == tl); | 2102 | GNUNET_assert (NULL == tl); |
2090 | GNUNET_STATISTICS_update(plugin->env->stats, | 2103 | GNUNET_STATISTICS_update (plugin->env->stats, |
2091 | gettext_noop("# bytes currently in TCP buffers"), | 2104 | gettext_noop ("# bytes currently in TCP buffers"), |
2092 | -(int64_t)ret, | 2105 | -(int64_t) ret, |
2093 | GNUNET_NO); | 2106 | GNUNET_NO); |
2094 | GNUNET_STATISTICS_update(plugin->env->stats, | 2107 | GNUNET_STATISTICS_update (plugin->env->stats, |
2095 | gettext_noop("# bytes transmitted via TCP"), | 2108 | gettext_noop ("# bytes transmitted via TCP"), |
2096 | ret, | 2109 | ret, |
2097 | GNUNET_NO); | 2110 | GNUNET_NO); |
2098 | return ret; | 2111 | return ret; |
2099 | } | 2112 | } |
2100 | 2113 | ||
@@ -2106,23 +2119,23 @@ do_transmit(void *cls, size_t size, void *buf) | |||
2106 | * @param session for which session should we do this | 2119 | * @param session for which session should we do this |
2107 | */ | 2120 | */ |
2108 | static void | 2121 | static void |
2109 | process_pending_messages(struct GNUNET_ATS_Session *session) | 2122 | process_pending_messages (struct GNUNET_ATS_Session *session) |
2110 | { | 2123 | { |
2111 | struct PendingMessage *pm; | 2124 | struct PendingMessage *pm; |
2112 | 2125 | ||
2113 | GNUNET_assert(NULL != session->client); | 2126 | GNUNET_assert (NULL != session->client); |
2114 | if (NULL != session->transmit_handle) | 2127 | if (NULL != session->transmit_handle) |
2115 | return; | 2128 | return; |
2116 | if (NULL == (pm = session->pending_messages_head)) | 2129 | if (NULL == (pm = session->pending_messages_head)) |
2117 | return; | 2130 | return; |
2118 | 2131 | ||
2119 | session->transmit_handle = | 2132 | session->transmit_handle = |
2120 | GNUNET_SERVER_notify_transmit_ready(session->client, | 2133 | GNUNET_SERVER_notify_transmit_ready (session->client, |
2121 | pm->message_size, | 2134 | pm->message_size, |
2122 | GNUNET_TIME_absolute_get_remaining( | 2135 | GNUNET_TIME_absolute_get_remaining ( |
2123 | pm->timeout), | 2136 | pm->timeout), |
2124 | &do_transmit, | 2137 | &do_transmit, |
2125 | session); | 2138 | session); |
2126 | } | 2139 | } |
2127 | 2140 | ||
2128 | 2141 | ||
@@ -2154,85 +2167,85 @@ process_pending_messages(struct GNUNET_ATS_Session *session) | |||
2154 | * and does NOT mean that the message was not transmitted (DV) | 2167 | * and does NOT mean that the message was not transmitted (DV) |
2155 | */ | 2168 | */ |
2156 | static ssize_t | 2169 | static ssize_t |
2157 | tcp_plugin_send(void *cls, | 2170 | tcp_plugin_send (void *cls, |
2158 | struct GNUNET_ATS_Session *session, | 2171 | struct GNUNET_ATS_Session *session, |
2159 | const char *msgbuf, | 2172 | const char *msgbuf, |
2160 | size_t msgbuf_size, | 2173 | size_t msgbuf_size, |
2161 | unsigned int priority, | 2174 | unsigned int priority, |
2162 | struct GNUNET_TIME_Relative to, | 2175 | struct GNUNET_TIME_Relative to, |
2163 | GNUNET_TRANSPORT_TransmitContinuation cont, | 2176 | GNUNET_TRANSPORT_TransmitContinuation cont, |
2164 | void *cont_cls) | 2177 | void *cont_cls) |
2165 | { | 2178 | { |
2166 | struct Plugin *plugin = cls; | 2179 | struct Plugin *plugin = cls; |
2167 | struct PendingMessage *pm; | 2180 | struct PendingMessage *pm; |
2168 | 2181 | ||
2169 | /* create new message entry */ | 2182 | /* create new message entry */ |
2170 | pm = GNUNET_malloc(sizeof(struct PendingMessage) + msgbuf_size); | 2183 | pm = GNUNET_malloc (sizeof(struct PendingMessage) + msgbuf_size); |
2171 | pm->msg = (const char *)&pm[1]; | 2184 | pm->msg = (const char *) &pm[1]; |
2172 | GNUNET_memcpy(&pm[1], msgbuf, msgbuf_size); | 2185 | GNUNET_memcpy (&pm[1], msgbuf, msgbuf_size); |
2173 | pm->message_size = msgbuf_size; | 2186 | pm->message_size = msgbuf_size; |
2174 | pm->timeout = GNUNET_TIME_relative_to_absolute(to); | 2187 | pm->timeout = GNUNET_TIME_relative_to_absolute (to); |
2175 | pm->transmit_cont = cont; | 2188 | pm->transmit_cont = cont; |
2176 | pm->transmit_cont_cls = cont_cls; | 2189 | pm->transmit_cont_cls = cont_cls; |
2177 | 2190 | ||
2178 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2191 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2179 | "Asked to transmit %u bytes to `%s', added message to list.\n", | 2192 | "Asked to transmit %u bytes to `%s', added message to list.\n", |
2180 | msgbuf_size, | 2193 | msgbuf_size, |
2181 | GNUNET_i2s(&session->target)); | 2194 | GNUNET_i2s (&session->target)); |
2182 | 2195 | ||
2183 | if (GNUNET_YES == | 2196 | if (GNUNET_YES == |
2184 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap, | 2197 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
2185 | &session->target, | 2198 | &session->target, |
2186 | session)) | 2199 | session)) |
2187 | { | 2200 | { |
2188 | GNUNET_assert(NULL != session->client); | 2201 | GNUNET_assert (NULL != session->client); |
2189 | GNUNET_SERVER_client_set_timeout(session->client, | 2202 | GNUNET_SERVER_client_set_timeout (session->client, |
2190 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 2203 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
2191 | GNUNET_STATISTICS_update(plugin->env->stats, | 2204 | GNUNET_STATISTICS_update (plugin->env->stats, |
2192 | gettext_noop("# bytes currently in TCP buffers"), | 2205 | gettext_noop ("# bytes currently in TCP buffers"), |
2193 | msgbuf_size, | 2206 | msgbuf_size, |
2194 | GNUNET_NO); | 2207 | GNUNET_NO); |
2195 | 2208 | ||
2196 | /* append pm to pending_messages list */ | 2209 | /* append pm to pending_messages list */ |
2197 | GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, | 2210 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, |
2198 | session->pending_messages_tail, | 2211 | session->pending_messages_tail, |
2199 | pm); | 2212 | pm); |
2200 | notify_session_monitor(session->plugin, | 2213 | notify_session_monitor (session->plugin, |
2201 | session, | 2214 | session, |
2202 | GNUNET_TRANSPORT_SS_UPDATE); | 2215 | GNUNET_TRANSPORT_SS_UPDATE); |
2203 | session->msgs_in_queue++; | 2216 | session->msgs_in_queue++; |
2204 | session->bytes_in_queue += pm->message_size; | 2217 | session->bytes_in_queue += pm->message_size; |
2205 | process_pending_messages(session); | 2218 | process_pending_messages (session); |
2206 | return msgbuf_size; | 2219 | return msgbuf_size; |
2207 | } | 2220 | } |
2208 | if (GNUNET_YES == | 2221 | if (GNUNET_YES == |
2209 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->nat_wait_conns, | 2222 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, |
2210 | &session->target, | 2223 | &session->target, |
2211 | session)) | 2224 | session)) |
2212 | { | 2225 | { |
2213 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2226 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2214 | "This NAT WAIT session for peer `%s' is not yet ready!\n", | 2227 | "This NAT WAIT session for peer `%s' is not yet ready!\n", |
2215 | GNUNET_i2s(&session->target)); | 2228 | GNUNET_i2s (&session->target)); |
2216 | GNUNET_STATISTICS_update(plugin->env->stats, | 2229 | GNUNET_STATISTICS_update (plugin->env->stats, |
2217 | gettext_noop("# bytes currently in TCP buffers"), | 2230 | gettext_noop ("# bytes currently in TCP buffers"), |
2218 | msgbuf_size, | 2231 | msgbuf_size, |
2219 | GNUNET_NO); | 2232 | GNUNET_NO); |
2220 | /* append pm to pending_messages list */ | 2233 | /* append pm to pending_messages list */ |
2221 | GNUNET_CONTAINER_DLL_insert_tail(session->pending_messages_head, | 2234 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, |
2222 | session->pending_messages_tail, | 2235 | session->pending_messages_tail, |
2223 | pm); | 2236 | pm); |
2224 | session->msgs_in_queue++; | 2237 | session->msgs_in_queue++; |
2225 | session->bytes_in_queue += pm->message_size; | 2238 | session->bytes_in_queue += pm->message_size; |
2226 | notify_session_monitor(session->plugin, | 2239 | notify_session_monitor (session->plugin, |
2227 | session, | 2240 | session, |
2228 | GNUNET_TRANSPORT_SS_HANDSHAKE); | 2241 | GNUNET_TRANSPORT_SS_HANDSHAKE); |
2229 | return msgbuf_size; | 2242 | return msgbuf_size; |
2230 | } | 2243 | } |
2231 | LOG(GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); | 2244 | LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); |
2232 | if (NULL != cont) | 2245 | if (NULL != cont) |
2233 | cont(cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); | 2246 | cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); |
2234 | GNUNET_break(0); | 2247 | GNUNET_break (0); |
2235 | GNUNET_free(pm); | 2248 | GNUNET_free (pm); |
2236 | return GNUNET_SYSERR; /* session does not exist here */ | 2249 | return GNUNET_SYSERR; /* session does not exist here */ |
2237 | } | 2250 | } |
2238 | 2251 | ||
@@ -2240,7 +2253,8 @@ tcp_plugin_send(void *cls, | |||
2240 | /** | 2253 | /** |
2241 | * Closure for #session_lookup_it(). | 2254 | * Closure for #session_lookup_it(). |
2242 | */ | 2255 | */ |
2243 | struct GNUNET_ATS_SessionItCtx { | 2256 | struct GNUNET_ATS_SessionItCtx |
2257 | { | ||
2244 | /** | 2258 | /** |
2245 | * Address we are looking for. | 2259 | * Address we are looking for. |
2246 | */ | 2260 | */ |
@@ -2262,14 +2276,14 @@ struct GNUNET_ATS_SessionItCtx { | |||
2262 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session | 2276 | * @return #GNUNET_YES to continue looking, #GNUNET_NO if we found the session |
2263 | */ | 2277 | */ |
2264 | static int | 2278 | static int |
2265 | session_lookup_it(void *cls, | 2279 | session_lookup_it (void *cls, |
2266 | const struct GNUNET_PeerIdentity *key, | 2280 | const struct GNUNET_PeerIdentity *key, |
2267 | void *value) | 2281 | void *value) |
2268 | { | 2282 | { |
2269 | struct GNUNET_ATS_SessionItCtx *si_ctx = cls; | 2283 | struct GNUNET_ATS_SessionItCtx *si_ctx = cls; |
2270 | struct GNUNET_ATS_Session *session = value; | 2284 | struct GNUNET_ATS_Session *session = value; |
2271 | 2285 | ||
2272 | if (0 != GNUNET_HELLO_address_cmp(si_ctx->address, session->address)) | 2286 | if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) |
2273 | return GNUNET_YES; | 2287 | return GNUNET_YES; |
2274 | si_ctx->result = session; | 2288 | si_ctx->result = session; |
2275 | return GNUNET_NO; | 2289 | return GNUNET_NO; |
@@ -2282,18 +2296,18 @@ session_lookup_it(void *cls, | |||
2282 | * @param cls the `struct GNUNET_ATS_Session` | 2296 | * @param cls the `struct GNUNET_ATS_Session` |
2283 | */ | 2297 | */ |
2284 | static void | 2298 | static void |
2285 | nat_connect_timeout(void *cls) | 2299 | nat_connect_timeout (void *cls) |
2286 | { | 2300 | { |
2287 | struct GNUNET_ATS_Session *session = cls; | 2301 | struct GNUNET_ATS_Session *session = cls; |
2288 | 2302 | ||
2289 | session->nat_connection_timeout = NULL; | 2303 | session->nat_connection_timeout = NULL; |
2290 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2304 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2291 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", | 2305 | "NAT WAIT connection to `%4s' at `%s' could not be established, removing session\n", |
2292 | GNUNET_i2s(&session->target), | 2306 | GNUNET_i2s (&session->target), |
2293 | tcp_plugin_address_to_string(session->plugin, | 2307 | tcp_plugin_address_to_string (session->plugin, |
2294 | session->address->address, | 2308 | session->address->address, |
2295 | session->address->address_length)); | 2309 | session->address->address_length)); |
2296 | tcp_plugin_disconnect_session(session->plugin, session); | 2310 | tcp_plugin_disconnect_session (session->plugin, session); |
2297 | } | 2311 | } |
2298 | 2312 | ||
2299 | 2313 | ||
@@ -2307,11 +2321,11 @@ nat_connect_timeout(void *cls) | |||
2307 | * @param session which session is being updated | 2321 | * @param session which session is being updated |
2308 | */ | 2322 | */ |
2309 | static void | 2323 | static void |
2310 | tcp_plugin_update_session_timeout(void *cls, | 2324 | tcp_plugin_update_session_timeout (void *cls, |
2311 | const struct GNUNET_PeerIdentity *peer, | 2325 | const struct GNUNET_PeerIdentity *peer, |
2312 | struct GNUNET_ATS_Session *session) | 2326 | struct GNUNET_ATS_Session *session) |
2313 | { | 2327 | { |
2314 | reschedule_session_timeout(session); | 2328 | reschedule_session_timeout (session); |
2315 | } | 2329 | } |
2316 | 2330 | ||
2317 | 2331 | ||
@@ -2322,13 +2336,13 @@ tcp_plugin_update_session_timeout(void *cls, | |||
2322 | * @param cls the `struct GNUNET_ATS_Session *` | 2336 | * @param cls the `struct GNUNET_ATS_Session *` |
2323 | */ | 2337 | */ |
2324 | static void | 2338 | static void |
2325 | delayed_done(void *cls) | 2339 | delayed_done (void *cls) |
2326 | { | 2340 | { |
2327 | struct GNUNET_ATS_Session *session = cls; | 2341 | struct GNUNET_ATS_Session *session = cls; |
2328 | 2342 | ||
2329 | session->receive_delay_task = NULL; | 2343 | session->receive_delay_task = NULL; |
2330 | reschedule_session_timeout(session); | 2344 | reschedule_session_timeout (session); |
2331 | GNUNET_SERVER_receive_done(session->client, GNUNET_OK); | 2345 | GNUNET_SERVER_receive_done (session->client, GNUNET_OK); |
2332 | } | 2346 | } |
2333 | 2347 | ||
2334 | 2348 | ||
@@ -2343,20 +2357,20 @@ delayed_done(void *cls) | |||
2343 | * @param delay new delay to use for receiving | 2357 | * @param delay new delay to use for receiving |
2344 | */ | 2358 | */ |
2345 | static void | 2359 | static void |
2346 | tcp_plugin_update_inbound_delay(void *cls, | 2360 | tcp_plugin_update_inbound_delay (void *cls, |
2347 | const struct GNUNET_PeerIdentity *peer, | 2361 | const struct GNUNET_PeerIdentity *peer, |
2348 | struct GNUNET_ATS_Session *session, | 2362 | struct GNUNET_ATS_Session *session, |
2349 | struct GNUNET_TIME_Relative delay) | 2363 | struct GNUNET_TIME_Relative delay) |
2350 | { | 2364 | { |
2351 | if (NULL == session->receive_delay_task) | 2365 | if (NULL == session->receive_delay_task) |
2352 | return; | 2366 | return; |
2353 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2367 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2354 | "New inbound delay %s\n", | 2368 | "New inbound delay %s\n", |
2355 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_NO)); | 2369 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO)); |
2356 | session->receive_delay = GNUNET_TIME_relative_to_absolute(delay); | 2370 | session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); |
2357 | GNUNET_SCHEDULER_cancel(session->receive_delay_task); | 2371 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
2358 | session->receive_delay_task = | 2372 | session->receive_delay_task = |
2359 | GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session); | 2373 | GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); |
2360 | } | 2374 | } |
2361 | 2375 | ||
2362 | 2376 | ||
@@ -2370,7 +2384,7 @@ tcp_plugin_update_inbound_delay(void *cls, | |||
2370 | * @return the session if the address is valid, NULL otherwise | 2384 | * @return the session if the address is valid, NULL otherwise |
2371 | */ | 2385 | */ |
2372 | static struct GNUNET_ATS_Session * | 2386 | static struct GNUNET_ATS_Session * |
2373 | tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) | 2387 | tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
2374 | { | 2388 | { |
2375 | struct Plugin *plugin = cls; | 2389 | struct Plugin *plugin = cls; |
2376 | struct GNUNET_ATS_Session *session = NULL; | 2390 | struct GNUNET_ATS_Session *session = NULL; |
@@ -2392,230 +2406,230 @@ tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) | |||
2392 | #endif | 2406 | #endif |
2393 | 2407 | ||
2394 | addrlen = address->address_length; | 2408 | addrlen = address->address_length; |
2395 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2409 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2396 | "Trying to get session for `%s' address of peer `%s'\n", | 2410 | "Trying to get session for `%s' address of peer `%s'\n", |
2397 | tcp_plugin_address_to_string(plugin, | 2411 | tcp_plugin_address_to_string (plugin, |
2398 | address->address, | 2412 | address->address, |
2399 | address->address_length), | 2413 | address->address_length), |
2400 | GNUNET_i2s(&address->peer)); | 2414 | GNUNET_i2s (&address->peer)); |
2401 | 2415 | ||
2402 | if (GNUNET_HELLO_address_check_option(address, | 2416 | if (GNUNET_HELLO_address_check_option (address, |
2403 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) | 2417 | GNUNET_HELLO_ADDRESS_INFO_INBOUND)) |
2404 | { | 2418 | { |
2405 | GNUNET_break(0); | 2419 | GNUNET_break (0); |
2406 | return NULL; | 2420 | return NULL; |
2407 | } | 2421 | } |
2408 | 2422 | ||
2409 | /* look for existing session */ | 2423 | /* look for existing session */ |
2410 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains(plugin->sessionmap, | 2424 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, |
2411 | &address->peer)) | 2425 | &address->peer)) |
2412 | { | 2426 | { |
2413 | struct GNUNET_ATS_SessionItCtx si_ctx; | 2427 | struct GNUNET_ATS_SessionItCtx si_ctx; |
2414 | 2428 | ||
2415 | si_ctx.address = address; | 2429 | si_ctx.address = address; |
2416 | si_ctx.result = NULL; | 2430 | si_ctx.result = NULL; |
2417 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap, | 2431 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, |
2418 | &address->peer, | 2432 | &address->peer, |
2419 | &session_lookup_it, | 2433 | &session_lookup_it, |
2420 | &si_ctx); | 2434 | &si_ctx); |
2421 | if (NULL != si_ctx.result) | 2435 | if (NULL != si_ctx.result) |
2422 | { | 2436 | { |
2423 | session = si_ctx.result; | 2437 | session = si_ctx.result; |
2424 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2438 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2425 | "Found existing session for `%s' address `%s'\n", | 2439 | "Found existing session for `%s' address `%s'\n", |
2426 | GNUNET_i2s(&address->peer), | 2440 | GNUNET_i2s (&address->peer), |
2427 | tcp_plugin_address_to_string(plugin, | 2441 | tcp_plugin_address_to_string (plugin, |
2428 | address->address, | 2442 | address->address, |
2429 | address->address_length)); | 2443 | address->address_length)); |
2430 | return session; | 2444 | return session; |
2431 | } | 2445 | } |
2432 | /* This is a bit of a hack, limiting TCP to never allow more than | 2446 | /* This is a bit of a hack, limiting TCP to never allow more than |
2433 | one TCP connection to any given peer at the same time. | 2447 | one TCP connection to any given peer at the same time. |
2434 | Without this, peers sometimes disagree about which of the TCP | 2448 | Without this, peers sometimes disagree about which of the TCP |
2435 | connections they should use, causing one side to believe that | 2449 | connections they should use, causing one side to believe that |
2436 | they transmit successfully, while the other receives nothing. */ | 2450 | they transmit successfully, while the other receives nothing. */ |
2437 | return NULL; /* Refuse to have more than one TCP connection per | 2451 | return NULL; /* Refuse to have more than one TCP connection per |
2438 | peer pair at the same time. */ | 2452 | peer pair at the same time. */ |
2439 | } | 2453 | } |
2440 | 2454 | ||
2441 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 2455 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
2442 | { | 2456 | { |
2443 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ | 2457 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
2444 | t6 = address->address; | 2458 | t6 = address->address; |
2445 | options = t6->options; | 2459 | options = t6->options; |
2446 | af = AF_INET6; | 2460 | af = AF_INET6; |
2447 | memset(&a6, 0, sizeof(a6)); | 2461 | memset (&a6, 0, sizeof(a6)); |
2448 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2462 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2449 | a6.sin6_len = sizeof(a6); | 2463 | a6.sin6_len = sizeof(a6); |
2450 | #endif | 2464 | #endif |
2451 | a6.sin6_family = AF_INET6; | 2465 | a6.sin6_family = AF_INET6; |
2452 | a6.sin6_port = t6->t6_port; | 2466 | a6.sin6_port = t6->t6_port; |
2453 | if (t6->t6_port == 0) | 2467 | if (t6->t6_port == 0) |
2454 | is_natd = GNUNET_YES; | 2468 | is_natd = GNUNET_YES; |
2455 | GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | 2469 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); |
2456 | sb = &a6; | 2470 | sb = &a6; |
2457 | sbs = sizeof(a6); | 2471 | sbs = sizeof(a6); |
2458 | } | 2472 | } |
2459 | else if (addrlen == sizeof(struct IPv4TcpAddress)) | 2473 | else if (addrlen == sizeof(struct IPv4TcpAddress)) |
2460 | { | 2474 | { |
2461 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ | 2475 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
2462 | t4 = address->address; | 2476 | t4 = address->address; |
2463 | options = t4->options; | 2477 | options = t4->options; |
2464 | af = AF_INET; | 2478 | af = AF_INET; |
2465 | memset(&a4, 0, sizeof(a4)); | 2479 | memset (&a4, 0, sizeof(a4)); |
2466 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2480 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2467 | a4.sin_len = sizeof(a4); | 2481 | a4.sin_len = sizeof(a4); |
2468 | #endif | 2482 | #endif |
2469 | a4.sin_family = AF_INET; | 2483 | a4.sin_family = AF_INET; |
2470 | a4.sin_port = t4->t4_port; | 2484 | a4.sin_port = t4->t4_port; |
2471 | if (t4->t4_port == 0) | 2485 | if (t4->t4_port == 0) |
2472 | is_natd = GNUNET_YES; | 2486 | is_natd = GNUNET_YES; |
2473 | a4.sin_addr.s_addr = t4->ipv4_addr; | 2487 | a4.sin_addr.s_addr = t4->ipv4_addr; |
2474 | sb = &a4; | 2488 | sb = &a4; |
2475 | sbs = sizeof(a4); | 2489 | sbs = sizeof(a4); |
2476 | } | 2490 | } |
2477 | else | 2491 | else |
2478 | { | 2492 | { |
2479 | GNUNET_STATISTICS_update( | 2493 | GNUNET_STATISTICS_update ( |
2480 | plugin->env->stats, | 2494 | plugin->env->stats, |
2481 | gettext_noop("# requests to create session with invalid address"), | 2495 | gettext_noop ("# requests to create session with invalid address"), |
2482 | 1, | 2496 | 1, |
2483 | GNUNET_NO); | 2497 | GNUNET_NO); |
2484 | return NULL; | 2498 | return NULL; |
2485 | } | 2499 | } |
2486 | 2500 | ||
2487 | net_type = plugin->env->get_address_type(plugin->env->cls, sb, sbs); | 2501 | net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
2488 | GNUNET_break(net_type != GNUNET_NT_UNSPECIFIED); | 2502 | GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED); |
2489 | 2503 | ||
2490 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) | 2504 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof(struct IPv6TcpAddress))) |
2491 | { | 2505 | { |
2492 | /* NAT client only works with IPv4 addresses */ | 2506 | /* NAT client only works with IPv4 addresses */ |
2493 | return NULL; | 2507 | return NULL; |
2494 | } | 2508 | } |
2495 | 2509 | ||
2496 | if (plugin->cur_connections >= plugin->max_connections) | 2510 | if (plugin->cur_connections >= plugin->max_connections) |
2497 | { | 2511 | { |
2498 | /* saturated */ | 2512 | /* saturated */ |
2499 | return NULL; | 2513 | return NULL; |
2500 | } | 2514 | } |
2501 | 2515 | ||
2502 | if ((is_natd == GNUNET_YES) && | 2516 | if ((is_natd == GNUNET_YES) && |
2503 | (GNUNET_YES == | 2517 | (GNUNET_YES == |
2504 | GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns, | 2518 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
2505 | &address->peer))) | 2519 | &address->peer))) |
2506 | { | 2520 | { |
2507 | /* Only do one NAT punch attempt per peer identity */ | 2521 | /* Only do one NAT punch attempt per peer identity */ |
2508 | return NULL; | 2522 | return NULL; |
2509 | } | 2523 | } |
2510 | 2524 | ||
2511 | if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && | 2525 | if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && |
2512 | (GNUNET_NO == | 2526 | (GNUNET_NO == |
2513 | GNUNET_CONTAINER_multipeermap_contains(plugin->nat_wait_conns, | 2527 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
2514 | &address->peer))) | 2528 | &address->peer))) |
2515 | { | 2529 | { |
2516 | struct sockaddr_in local_sa; | 2530 | struct sockaddr_in local_sa; |
2517 | 2531 | ||
2518 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2532 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2519 | "Found valid IPv4 NAT address (creating session)!\n"); | 2533 | "Found valid IPv4 NAT address (creating session)!\n"); |
2520 | session = create_session(plugin, address, net_type, NULL, GNUNET_YES); | 2534 | session = create_session (plugin, address, net_type, NULL, GNUNET_YES); |
2521 | session->nat_connection_timeout = | 2535 | session->nat_connection_timeout = |
2522 | GNUNET_SCHEDULER_add_delayed(NAT_TIMEOUT, &nat_connect_timeout, session); | 2536 | GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session); |
2523 | GNUNET_assert(GNUNET_OK == | 2537 | GNUNET_assert (GNUNET_OK == |
2524 | GNUNET_CONTAINER_multipeermap_put( | 2538 | GNUNET_CONTAINER_multipeermap_put ( |
2525 | plugin->nat_wait_conns, | 2539 | plugin->nat_wait_conns, |
2526 | &session->target, | 2540 | &session->target, |
2527 | session, | 2541 | session, |
2528 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2542 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
2529 | 2543 | ||
2530 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2544 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2531 | "Created NAT WAIT connection to `%s' at `%s'\n", | 2545 | "Created NAT WAIT connection to `%s' at `%s'\n", |
2532 | GNUNET_i2s(&session->target), | 2546 | GNUNET_i2s (&session->target), |
2533 | GNUNET_a2s(sb, sbs)); | 2547 | GNUNET_a2s (sb, sbs)); |
2534 | memset(&local_sa, 0, sizeof(local_sa)); | 2548 | memset (&local_sa, 0, sizeof(local_sa)); |
2535 | local_sa.sin_family = AF_INET; | 2549 | local_sa.sin_family = AF_INET; |
2536 | local_sa.sin_port = htons(plugin->open_port); | 2550 | local_sa.sin_port = htons (plugin->open_port); |
2537 | /* We leave sin_address at 0, let the kernel figure it out, | 2551 | /* We leave sin_address at 0, let the kernel figure it out, |
2538 | even if our bind() is more specific. (May want to reconsider | 2552 | even if our bind() is more specific. (May want to reconsider |
2539 | later.) */ | 2553 | later.) */ |
2540 | if (GNUNET_OK == GNUNET_NAT_request_reversal(plugin->nat, &local_sa, &a4)) | 2554 | if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4)) |
2541 | return session; | 2555 | return session; |
2542 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2556 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2543 | "Running NAT client for `%s' at `%s' failed\n", | 2557 | "Running NAT client for `%s' at `%s' failed\n", |
2544 | GNUNET_i2s(&session->target), | 2558 | GNUNET_i2s (&session->target), |
2545 | GNUNET_a2s(sb, sbs)); | 2559 | GNUNET_a2s (sb, sbs)); |
2546 | tcp_plugin_disconnect_session(plugin, session); | 2560 | tcp_plugin_disconnect_session (plugin, session); |
2547 | return NULL; | 2561 | return NULL; |
2548 | } | 2562 | } |
2549 | 2563 | ||
2550 | /* create new outbound session */ | 2564 | /* create new outbound session */ |
2551 | if (0 != (options & TCP_OPTIONS_TCP_STEALTH)) | 2565 | if (0 != (options & TCP_OPTIONS_TCP_STEALTH)) |
2552 | { | 2566 | { |
2553 | #ifdef TCP_STEALTH | 2567 | #ifdef TCP_STEALTH |
2554 | s = GNUNET_NETWORK_socket_create(af, SOCK_STREAM, 0); | 2568 | s = GNUNET_NETWORK_socket_create (af, SOCK_STREAM, 0); |
2555 | if (NULL == s) | 2569 | if (NULL == s) |
2556 | { | 2570 | { |
2557 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 2571 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
2558 | "socket"); | 2572 | "socket"); |
2559 | sa = NULL; | 2573 | sa = NULL; |
2560 | } | 2574 | } |
2575 | else | ||
2576 | { | ||
2577 | if ((GNUNET_OK != | ||
2578 | GNUNET_NETWORK_socket_setsockopt (s, | ||
2579 | IPPROTO_TCP, | ||
2580 | TCP_STEALTH, | ||
2581 | &session->target, | ||
2582 | sizeof( | ||
2583 | struct GNUNET_PeerIdentity))) || | ||
2584 | (GNUNET_OK != | ||
2585 | GNUNET_NETWORK_socket_setsockopt (s, | ||
2586 | IPPROTO_TCP, | ||
2587 | TCP_STEALTH_INTEGRITY, | ||
2588 | &plugin->my_welcome, | ||
2589 | sizeof(struct WelcomeMessage)))) | ||
2590 | { | ||
2591 | /* TCP STEALTH not supported by kernel */ | ||
2592 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); | ||
2593 | sa = NULL; | ||
2594 | } | ||
2561 | else | 2595 | else |
2562 | { | 2596 | { |
2563 | if ((GNUNET_OK != | 2597 | sa = GNUNET_CONNECTION_connect_socket (s, sb, sbs); |
2564 | GNUNET_NETWORK_socket_setsockopt(s, | 2598 | } |
2565 | IPPROTO_TCP, | 2599 | } |
2566 | TCP_STEALTH, | ||
2567 | &session->target, | ||
2568 | sizeof( | ||
2569 | struct GNUNET_PeerIdentity))) || | ||
2570 | (GNUNET_OK != | ||
2571 | GNUNET_NETWORK_socket_setsockopt(s, | ||
2572 | IPPROTO_TCP, | ||
2573 | TCP_STEALTH_INTEGRITY, | ||
2574 | &plugin->my_welcome, | ||
2575 | sizeof(struct WelcomeMessage)))) | ||
2576 | { | ||
2577 | /* TCP STEALTH not supported by kernel */ | ||
2578 | GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(s)); | ||
2579 | sa = NULL; | ||
2580 | } | ||
2581 | else | ||
2582 | { | ||
2583 | sa = GNUNET_CONNECTION_connect_socket(s, sb, sbs); | ||
2584 | } | ||
2585 | } | ||
2586 | #else | 2600 | #else |
2587 | sa = NULL; | 2601 | sa = NULL; |
2588 | #endif | 2602 | #endif |
2589 | } | 2603 | } |
2590 | else | 2604 | else |
2591 | { | 2605 | { |
2592 | sa = GNUNET_CONNECTION_create_from_sockaddr(af, sb, sbs); | 2606 | sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); |
2593 | } | 2607 | } |
2594 | if (NULL == sa) | 2608 | if (NULL == sa) |
2595 | { | 2609 | { |
2596 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2610 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2597 | "Failed to create connection to `%s' at `%s'\n", | 2611 | "Failed to create connection to `%s' at `%s'\n", |
2598 | GNUNET_i2s(&address->peer), | 2612 | GNUNET_i2s (&address->peer), |
2599 | GNUNET_a2s(sb, sbs)); | 2613 | GNUNET_a2s (sb, sbs)); |
2600 | return NULL; | 2614 | return NULL; |
2601 | } | 2615 | } |
2602 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2616 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2603 | "Asked to transmit to `%s', creating fresh session using address `%s'.\n", | 2617 | "Asked to transmit to `%s', creating fresh session using address `%s'.\n", |
2604 | GNUNET_i2s(&address->peer), | 2618 | GNUNET_i2s (&address->peer), |
2605 | GNUNET_a2s(sb, sbs)); | 2619 | GNUNET_a2s (sb, sbs)); |
2606 | 2620 | ||
2607 | session = create_session(plugin, | 2621 | session = create_session (plugin, |
2608 | address, | 2622 | address, |
2609 | net_type, | 2623 | net_type, |
2610 | GNUNET_SERVER_connect_socket(plugin->server, sa), | 2624 | GNUNET_SERVER_connect_socket (plugin->server, sa), |
2611 | GNUNET_NO); | 2625 | GNUNET_NO); |
2612 | (void)GNUNET_CONTAINER_multipeermap_put( | 2626 | (void) GNUNET_CONTAINER_multipeermap_put ( |
2613 | plugin->sessionmap, | 2627 | plugin->sessionmap, |
2614 | &session->target, | 2628 | &session->target, |
2615 | session, | 2629 | session, |
2616 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2630 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2617 | /* Send TCP Welcome */ | 2631 | /* Send TCP Welcome */ |
2618 | process_pending_messages(session); | 2632 | process_pending_messages (session); |
2619 | 2633 | ||
2620 | return session; | 2634 | return session; |
2621 | } | 2635 | } |
@@ -2632,19 +2646,19 @@ tcp_plugin_get_session(void *cls, const struct GNUNET_HELLO_Address *address) | |||
2632 | * @return #GNUNET_YES (continue to iterate) | 2646 | * @return #GNUNET_YES (continue to iterate) |
2633 | */ | 2647 | */ |
2634 | static int | 2648 | static int |
2635 | session_disconnect_it(void *cls, | 2649 | session_disconnect_it (void *cls, |
2636 | const struct GNUNET_PeerIdentity *key, | 2650 | const struct GNUNET_PeerIdentity *key, |
2637 | void *value) | 2651 | void *value) |
2638 | { | 2652 | { |
2639 | struct Plugin *plugin = cls; | 2653 | struct Plugin *plugin = cls; |
2640 | struct GNUNET_ATS_Session *session = value; | 2654 | struct GNUNET_ATS_Session *session = value; |
2641 | 2655 | ||
2642 | GNUNET_STATISTICS_update(session->plugin->env->stats, | 2656 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
2643 | gettext_noop( | 2657 | gettext_noop ( |
2644 | "# transport-service disconnect requests for TCP"), | 2658 | "# transport-service disconnect requests for TCP"), |
2645 | 1, | 2659 | 1, |
2646 | GNUNET_NO); | 2660 | GNUNET_NO); |
2647 | tcp_plugin_disconnect_session(plugin, session); | 2661 | tcp_plugin_disconnect_session (plugin, session); |
2648 | return GNUNET_YES; | 2662 | return GNUNET_YES; |
2649 | } | 2663 | } |
2650 | 2664 | ||
@@ -2666,21 +2680,21 @@ session_disconnect_it(void *cls, | |||
2666 | * to be cancelled | 2680 | * to be cancelled |
2667 | */ | 2681 | */ |
2668 | static void | 2682 | static void |
2669 | tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) | 2683 | tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
2670 | { | 2684 | { |
2671 | struct Plugin *plugin = cls; | 2685 | struct Plugin *plugin = cls; |
2672 | 2686 | ||
2673 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 2687 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2674 | "Disconnecting peer `%s'\n", | 2688 | "Disconnecting peer `%s'\n", |
2675 | GNUNET_i2s(target)); | 2689 | GNUNET_i2s (target)); |
2676 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->sessionmap, | 2690 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, |
2677 | target, | 2691 | target, |
2678 | &session_disconnect_it, | 2692 | &session_disconnect_it, |
2679 | plugin); | 2693 | plugin); |
2680 | GNUNET_CONTAINER_multipeermap_get_multiple(plugin->nat_wait_conns, | 2694 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->nat_wait_conns, |
2681 | target, | 2695 | target, |
2682 | &session_disconnect_it, | 2696 | &session_disconnect_it, |
2683 | plugin); | 2697 | plugin); |
2684 | } | 2698 | } |
2685 | 2699 | ||
2686 | 2700 | ||
@@ -2695,42 +2709,42 @@ tcp_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) | |||
2695 | * @param hostname hostname part of the address | 2709 | * @param hostname hostname part of the address |
2696 | */ | 2710 | */ |
2697 | static void | 2711 | static void |
2698 | append_port(void *cls, const char *hostname) | 2712 | append_port (void *cls, const char *hostname) |
2699 | { | 2713 | { |
2700 | struct PrettyPrinterContext *ppc = cls; | 2714 | struct PrettyPrinterContext *ppc = cls; |
2701 | struct Plugin *plugin = ppc->plugin; | 2715 | struct Plugin *plugin = ppc->plugin; |
2702 | char *ret; | 2716 | char *ret; |
2703 | 2717 | ||
2704 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 2718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2705 | "append_port called with hostname `%s'\n", | 2719 | "append_port called with hostname `%s'\n", |
2706 | hostname); | 2720 | hostname); |
2707 | if (NULL == hostname) | 2721 | if (NULL == hostname) |
2708 | { | 2722 | { |
2709 | /* Final call, done */ | 2723 | /* Final call, done */ |
2710 | ppc->resolver_handle = NULL; | 2724 | ppc->resolver_handle = NULL; |
2711 | GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, | 2725 | GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, |
2712 | plugin->ppc_dll_tail, | 2726 | plugin->ppc_dll_tail, |
2713 | ppc); | 2727 | ppc); |
2714 | ppc->asc(ppc->asc_cls, NULL, GNUNET_OK); | 2728 | ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); |
2715 | GNUNET_free(ppc); | 2729 | GNUNET_free (ppc); |
2716 | return; | 2730 | return; |
2717 | } | 2731 | } |
2718 | if (GNUNET_YES == ppc->ipv6) | 2732 | if (GNUNET_YES == ppc->ipv6) |
2719 | GNUNET_asprintf(&ret, | 2733 | GNUNET_asprintf (&ret, |
2720 | "%s.%u.[%s]:%d", | 2734 | "%s.%u.[%s]:%d", |
2721 | PLUGIN_NAME, | 2735 | PLUGIN_NAME, |
2722 | ppc->options, | 2736 | ppc->options, |
2723 | hostname, | 2737 | hostname, |
2724 | ppc->port); | 2738 | ppc->port); |
2725 | else | 2739 | else |
2726 | GNUNET_asprintf(&ret, | 2740 | GNUNET_asprintf (&ret, |
2727 | "%s.%u.%s:%d", | 2741 | "%s.%u.%s:%d", |
2728 | PLUGIN_NAME, | 2742 | PLUGIN_NAME, |
2729 | ppc->options, | 2743 | ppc->options, |
2730 | hostname, | 2744 | hostname, |
2731 | ppc->port); | 2745 | ppc->port); |
2732 | ppc->asc(ppc->asc_cls, ret, GNUNET_OK); | 2746 | ppc->asc (ppc->asc_cls, ret, GNUNET_OK); |
2733 | GNUNET_free(ret); | 2747 | GNUNET_free (ret); |
2734 | } | 2748 | } |
2735 | 2749 | ||
2736 | 2750 | ||
@@ -2748,14 +2762,14 @@ append_port(void *cls, const char *hostname) | |||
2748 | * @param asc_cls closure for @a asc | 2762 | * @param asc_cls closure for @a asc |
2749 | */ | 2763 | */ |
2750 | static void | 2764 | static void |
2751 | tcp_plugin_address_pretty_printer(void *cls, | 2765 | tcp_plugin_address_pretty_printer (void *cls, |
2752 | const char *type, | 2766 | const char *type, |
2753 | const void *addr, | 2767 | const void *addr, |
2754 | size_t addrlen, | 2768 | size_t addrlen, |
2755 | int numeric, | 2769 | int numeric, |
2756 | struct GNUNET_TIME_Relative timeout, | 2770 | struct GNUNET_TIME_Relative timeout, |
2757 | GNUNET_TRANSPORT_AddressStringCallback asc, | 2771 | GNUNET_TRANSPORT_AddressStringCallback asc, |
2758 | void *asc_cls) | 2772 | void *asc_cls) |
2759 | { | 2773 | { |
2760 | struct Plugin *plugin = cls; | 2774 | struct Plugin *plugin = cls; |
2761 | struct PrettyPrinterContext *ppc; | 2775 | struct PrettyPrinterContext *ppc; |
@@ -2769,40 +2783,40 @@ tcp_plugin_address_pretty_printer(void *cls, | |||
2769 | uint32_t options; | 2783 | uint32_t options; |
2770 | 2784 | ||
2771 | if (sizeof(struct IPv6TcpAddress) == addrlen) | 2785 | if (sizeof(struct IPv6TcpAddress) == addrlen) |
2772 | { | 2786 | { |
2773 | t6 = addr; | 2787 | t6 = addr; |
2774 | memset(&a6, 0, sizeof(a6)); | 2788 | memset (&a6, 0, sizeof(a6)); |
2775 | a6.sin6_family = AF_INET6; | 2789 | a6.sin6_family = AF_INET6; |
2776 | a6.sin6_port = t6->t6_port; | 2790 | a6.sin6_port = t6->t6_port; |
2777 | GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | 2791 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); |
2778 | port = ntohs(t6->t6_port); | 2792 | port = ntohs (t6->t6_port); |
2779 | options = ntohl(t6->options); | 2793 | options = ntohl (t6->options); |
2780 | sb = &a6; | 2794 | sb = &a6; |
2781 | sbs = sizeof(a6); | 2795 | sbs = sizeof(a6); |
2782 | } | 2796 | } |
2783 | else if (sizeof(struct IPv4TcpAddress) == addrlen) | 2797 | else if (sizeof(struct IPv4TcpAddress) == addrlen) |
2784 | { | 2798 | { |
2785 | t4 = addr; | 2799 | t4 = addr; |
2786 | memset(&a4, 0, sizeof(a4)); | 2800 | memset (&a4, 0, sizeof(a4)); |
2787 | a4.sin_family = AF_INET; | 2801 | a4.sin_family = AF_INET; |
2788 | a4.sin_port = t4->t4_port; | 2802 | a4.sin_port = t4->t4_port; |
2789 | a4.sin_addr.s_addr = t4->ipv4_addr; | 2803 | a4.sin_addr.s_addr = t4->ipv4_addr; |
2790 | port = ntohs(t4->t4_port); | 2804 | port = ntohs (t4->t4_port); |
2791 | options = ntohl(t4->options); | 2805 | options = ntohl (t4->options); |
2792 | sb = &a4; | 2806 | sb = &a4; |
2793 | sbs = sizeof(a4); | 2807 | sbs = sizeof(a4); |
2794 | } | 2808 | } |
2795 | else | 2809 | else |
2796 | { | 2810 | { |
2797 | /* invalid address */ | 2811 | /* invalid address */ |
2798 | LOG(GNUNET_ERROR_TYPE_WARNING, | 2812 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2799 | _("Unexpected address length: %u bytes\n"), | 2813 | _ ("Unexpected address length: %u bytes\n"), |
2800 | (unsigned int)addrlen); | 2814 | (unsigned int) addrlen); |
2801 | asc(asc_cls, NULL, GNUNET_SYSERR); | 2815 | asc (asc_cls, NULL, GNUNET_SYSERR); |
2802 | asc(asc_cls, NULL, GNUNET_OK); | 2816 | asc (asc_cls, NULL, GNUNET_OK); |
2803 | return; | 2817 | return; |
2804 | } | 2818 | } |
2805 | ppc = GNUNET_new(struct PrettyPrinterContext); | 2819 | ppc = GNUNET_new (struct PrettyPrinterContext); |
2806 | ppc->plugin = plugin; | 2820 | ppc->plugin = plugin; |
2807 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 2821 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
2808 | ppc->ipv6 = GNUNET_YES; | 2822 | ppc->ipv6 = GNUNET_YES; |
@@ -2812,20 +2826,20 @@ tcp_plugin_address_pretty_printer(void *cls, | |||
2812 | ppc->asc_cls = asc_cls; | 2826 | ppc->asc_cls = asc_cls; |
2813 | ppc->port = port; | 2827 | ppc->port = port; |
2814 | ppc->options = options; | 2828 | ppc->options = options; |
2815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); | 2829 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); |
2816 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get(sb, | 2830 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, |
2817 | sbs, | 2831 | sbs, |
2818 | !numeric, | 2832 | ! numeric, |
2819 | timeout, | 2833 | timeout, |
2820 | &append_port, | 2834 | &append_port, |
2821 | ppc); | 2835 | ppc); |
2822 | if (NULL == ppc->resolver_handle) | 2836 | if (NULL == ppc->resolver_handle) |
2823 | { | 2837 | { |
2824 | GNUNET_break(0); | 2838 | GNUNET_break (0); |
2825 | GNUNET_free(ppc); | 2839 | GNUNET_free (ppc); |
2826 | return; | 2840 | return; |
2827 | } | 2841 | } |
2828 | GNUNET_CONTAINER_DLL_insert(plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); | 2842 | GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); |
2829 | } | 2843 | } |
2830 | 2844 | ||
2831 | 2845 | ||
@@ -2845,7 +2859,7 @@ tcp_plugin_address_pretty_printer(void *cls, | |||
2845 | * and transport, #GNUNET_SYSERR if not | 2859 | * and transport, #GNUNET_SYSERR if not |
2846 | */ | 2860 | */ |
2847 | static int | 2861 | static int |
2848 | tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) | 2862 | tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
2849 | { | 2863 | { |
2850 | struct Plugin *plugin = cls; | 2864 | struct Plugin *plugin = cls; |
2851 | const struct IPv4TcpAddress *v4; | 2865 | const struct IPv4TcpAddress *v4; |
@@ -2853,61 +2867,61 @@ tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) | |||
2853 | 2867 | ||
2854 | if ((addrlen != sizeof(struct IPv4TcpAddress)) && | 2868 | if ((addrlen != sizeof(struct IPv4TcpAddress)) && |
2855 | (addrlen != sizeof(struct IPv6TcpAddress))) | 2869 | (addrlen != sizeof(struct IPv6TcpAddress))) |
2856 | { | 2870 | { |
2857 | GNUNET_break_op(0); | 2871 | GNUNET_break_op (0); |
2858 | return GNUNET_SYSERR; | 2872 | return GNUNET_SYSERR; |
2859 | } | 2873 | } |
2860 | 2874 | ||
2861 | if (addrlen == sizeof(struct IPv4TcpAddress)) | 2875 | if (addrlen == sizeof(struct IPv4TcpAddress)) |
2862 | { | 2876 | { |
2863 | struct sockaddr_in s4; | 2877 | struct sockaddr_in s4; |
2864 | 2878 | ||
2865 | v4 = (const struct IPv4TcpAddress *)addr; | 2879 | v4 = (const struct IPv4TcpAddress *) addr; |
2866 | if (0 != memcmp(&v4->options, &plugin->myoptions, sizeof(uint32_t))) | 2880 | if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof(uint32_t))) |
2867 | { | 2881 | { |
2868 | GNUNET_break(0); | 2882 | GNUNET_break (0); |
2869 | return GNUNET_SYSERR; | 2883 | return GNUNET_SYSERR; |
2870 | } | 2884 | } |
2871 | memset(&s4, 0, sizeof(s4)); | 2885 | memset (&s4, 0, sizeof(s4)); |
2872 | s4.sin_family = AF_INET; | 2886 | s4.sin_family = AF_INET; |
2873 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2887 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2874 | s4.sin_len = sizeof(s4); | 2888 | s4.sin_len = sizeof(s4); |
2875 | #endif | 2889 | #endif |
2876 | s4.sin_port = v4->t4_port; | 2890 | s4.sin_port = v4->t4_port; |
2877 | s4.sin_addr.s_addr = v4->ipv4_addr; | 2891 | s4.sin_addr.s_addr = v4->ipv4_addr; |
2878 | 2892 | ||
2879 | if (GNUNET_OK != | 2893 | if (GNUNET_OK != |
2880 | GNUNET_NAT_test_address(plugin->nat, &s4, sizeof(struct sockaddr_in))) | 2894 | GNUNET_NAT_test_address (plugin->nat, &s4, sizeof(struct sockaddr_in))) |
2881 | return GNUNET_SYSERR; | 2895 | return GNUNET_SYSERR; |
2882 | } | 2896 | } |
2883 | else | 2897 | else |
2884 | { | 2898 | { |
2885 | struct sockaddr_in6 s6; | 2899 | struct sockaddr_in6 s6; |
2886 | 2900 | ||
2887 | v6 = (const struct IPv6TcpAddress *)addr; | 2901 | v6 = (const struct IPv6TcpAddress *) addr; |
2888 | if (IN6_IS_ADDR_LINKLOCAL(&v6->ipv6_addr)) | 2902 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
2889 | { | 2903 | { |
2890 | GNUNET_break_op(0); | 2904 | GNUNET_break_op (0); |
2891 | return GNUNET_SYSERR; | 2905 | return GNUNET_SYSERR; |
2892 | } | 2906 | } |
2893 | if (0 != memcmp(&v6->options, &plugin->myoptions, sizeof(uint32_t))) | 2907 | if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof(uint32_t))) |
2894 | { | 2908 | { |
2895 | GNUNET_break(0); | 2909 | GNUNET_break (0); |
2896 | return GNUNET_SYSERR; | 2910 | return GNUNET_SYSERR; |
2897 | } | 2911 | } |
2898 | memset(&s6, 0, sizeof(s6)); | 2912 | memset (&s6, 0, sizeof(s6)); |
2899 | s6.sin6_family = AF_INET6; | 2913 | s6.sin6_family = AF_INET6; |
2900 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2914 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2901 | s6.sin6_len = sizeof(s6); | 2915 | s6.sin6_len = sizeof(s6); |
2902 | #endif | 2916 | #endif |
2903 | s6.sin6_port = v6->t6_port; | 2917 | s6.sin6_port = v6->t6_port; |
2904 | s6.sin6_addr = v6->ipv6_addr; | 2918 | s6.sin6_addr = v6->ipv6_addr; |
2905 | 2919 | ||
2906 | if (GNUNET_OK != GNUNET_NAT_test_address(plugin->nat, | 2920 | if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, |
2907 | &s6, | 2921 | &s6, |
2908 | sizeof(struct sockaddr_in6))) | 2922 | sizeof(struct sockaddr_in6))) |
2909 | return GNUNET_SYSERR; | 2923 | return GNUNET_SYSERR; |
2910 | } | 2924 | } |
2911 | return GNUNET_OK; | 2925 | return GNUNET_OK; |
2912 | } | 2926 | } |
2913 | 2927 | ||
@@ -2922,9 +2936,9 @@ tcp_plugin_check_address(void *cls, const void *addr, size_t addrlen) | |||
2922 | * @param message the actual message | 2936 | * @param message the actual message |
2923 | */ | 2937 | */ |
2924 | static void | 2938 | static void |
2925 | handle_tcp_nat_probe(void *cls, | 2939 | handle_tcp_nat_probe (void *cls, |
2926 | struct GNUNET_SERVER_Client *client, | 2940 | struct GNUNET_SERVER_Client *client, |
2927 | const struct GNUNET_MessageHeader *message) | 2941 | const struct GNUNET_MessageHeader *message) |
2928 | { | 2942 | { |
2929 | struct Plugin *plugin = cls; | 2943 | struct Plugin *plugin = cls; |
2930 | struct GNUNET_ATS_Session *session; | 2944 | struct GNUNET_ATS_Session *session; |
@@ -2936,115 +2950,115 @@ handle_tcp_nat_probe(void *cls, | |||
2936 | const struct sockaddr_in *s4; | 2950 | const struct sockaddr_in *s4; |
2937 | const struct sockaddr_in6 *s6; | 2951 | const struct sockaddr_in6 *s6; |
2938 | 2952 | ||
2939 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); | 2953 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); |
2940 | /* We have received a TCP NAT probe, meaning we (hopefully) initiated | 2954 | /* We have received a TCP NAT probe, meaning we (hopefully) initiated |
2941 | * a connection to this peer by running gnunet-nat-client. This peer | 2955 | * a connection to this peer by running gnunet-nat-client. This peer |
2942 | * received the punch message and now wants us to use the new connection | 2956 | * received the punch message and now wants us to use the new connection |
2943 | * as the default for that peer. Do so and then send a WELCOME message | 2957 | * as the default for that peer. Do so and then send a WELCOME message |
2944 | * so we can really be connected! | 2958 | * so we can really be connected! |
2945 | */ | 2959 | */ |
2946 | if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage)) | 2960 | if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage)) |
2947 | { | 2961 | { |
2948 | GNUNET_break_op(0); | 2962 | GNUNET_break_op (0); |
2949 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2963 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2950 | return; | 2964 | return; |
2951 | } | 2965 | } |
2952 | 2966 | ||
2953 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *)message; | 2967 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; |
2954 | if (0 == memcmp(&tcp_nat_probe->clientIdentity, | 2968 | if (0 == memcmp (&tcp_nat_probe->clientIdentity, |
2955 | plugin->env->my_identity, | 2969 | plugin->env->my_identity, |
2956 | sizeof(struct GNUNET_PeerIdentity))) | 2970 | sizeof(struct GNUNET_PeerIdentity))) |
2957 | { | 2971 | { |
2958 | /* refuse connections from ourselves */ | 2972 | /* refuse connections from ourselves */ |
2959 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2973 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2960 | return; | 2974 | return; |
2961 | } | 2975 | } |
2962 | 2976 | ||
2963 | session = GNUNET_CONTAINER_multipeermap_get(plugin->nat_wait_conns, | 2977 | session = GNUNET_CONTAINER_multipeermap_get (plugin->nat_wait_conns, |
2964 | &tcp_nat_probe->clientIdentity); | 2978 | &tcp_nat_probe->clientIdentity); |
2965 | if (NULL == session) | 2979 | if (NULL == session) |
2966 | { | 2980 | { |
2967 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); | 2981 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); |
2968 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 2982 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2969 | return; | 2983 | return; |
2970 | } | 2984 | } |
2971 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); | 2985 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); |
2972 | 2986 | ||
2973 | if (NULL != session->nat_connection_timeout) | 2987 | if (NULL != session->nat_connection_timeout) |
2974 | { | 2988 | { |
2975 | GNUNET_SCHEDULER_cancel(session->nat_connection_timeout); | 2989 | GNUNET_SCHEDULER_cancel (session->nat_connection_timeout); |
2976 | session->nat_connection_timeout = NULL; | 2990 | session->nat_connection_timeout = NULL; |
2977 | } | 2991 | } |
2978 | 2992 | ||
2979 | if (GNUNET_OK != GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) | 2993 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
2980 | { | 2994 | { |
2981 | GNUNET_break(0); | 2995 | GNUNET_break (0); |
2982 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 2996 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2983 | tcp_plugin_disconnect_session(plugin, session); | 2997 | tcp_plugin_disconnect_session (plugin, session); |
2984 | return; | 2998 | return; |
2985 | } | 2999 | } |
2986 | GNUNET_assert( | 3000 | GNUNET_assert ( |
2987 | GNUNET_YES == | 3001 | GNUNET_YES == |
2988 | GNUNET_CONTAINER_multipeermap_remove(plugin->nat_wait_conns, | 3002 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, |
2989 | &tcp_nat_probe->clientIdentity, | 3003 | &tcp_nat_probe->clientIdentity, |
2990 | session)); | 3004 | session)); |
2991 | GNUNET_SERVER_client_set_user_context(client, session); | 3005 | GNUNET_SERVER_client_set_user_context (client, session); |
2992 | (void)GNUNET_CONTAINER_multipeermap_put( | 3006 | (void) GNUNET_CONTAINER_multipeermap_put ( |
2993 | plugin->sessionmap, | 3007 | plugin->sessionmap, |
2994 | &session->target, | 3008 | &session->target, |
2995 | session, | 3009 | session, |
2996 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 3010 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
2997 | session->last_activity = GNUNET_TIME_absolute_get(); | 3011 | session->last_activity = GNUNET_TIME_absolute_get (); |
2998 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3012 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2999 | "Found address `%s' for incoming connection\n", | 3013 | "Found address `%s' for incoming connection\n", |
3000 | GNUNET_a2s(vaddr, alen)); | 3014 | GNUNET_a2s (vaddr, alen)); |
3001 | switch (((const struct sockaddr *)vaddr)->sa_family) | 3015 | switch (((const struct sockaddr *) vaddr)->sa_family) |
3002 | { | 3016 | { |
3003 | case AF_INET: | 3017 | case AF_INET: |
3004 | s4 = vaddr; | 3018 | s4 = vaddr; |
3005 | t4 = GNUNET_new(struct IPv4TcpAddress); | 3019 | t4 = GNUNET_new (struct IPv4TcpAddress); |
3006 | t4->options = htonl(TCP_OPTIONS_NONE); | 3020 | t4->options = htonl (TCP_OPTIONS_NONE); |
3007 | t4->t4_port = s4->sin_port; | 3021 | t4->t4_port = s4->sin_port; |
3008 | t4->ipv4_addr = s4->sin_addr.s_addr; | 3022 | t4->ipv4_addr = s4->sin_addr.s_addr; |
3009 | session->address = | 3023 | session->address = |
3010 | GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity, | 3024 | GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, |
3011 | PLUGIN_NAME, | 3025 | PLUGIN_NAME, |
3012 | &t4, | 3026 | &t4, |
3013 | sizeof(struct IPv4TcpAddress), | 3027 | sizeof(struct IPv4TcpAddress), |
3014 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 3028 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
3015 | break; | 3029 | break; |
3016 | 3030 | ||
3017 | case AF_INET6: | 3031 | case AF_INET6: |
3018 | s6 = vaddr; | 3032 | s6 = vaddr; |
3019 | t6 = GNUNET_new(struct IPv6TcpAddress); | 3033 | t6 = GNUNET_new (struct IPv6TcpAddress); |
3020 | t6->options = htonl(TCP_OPTIONS_NONE); | 3034 | t6->options = htonl (TCP_OPTIONS_NONE); |
3021 | t6->t6_port = s6->sin6_port; | 3035 | t6->t6_port = s6->sin6_port; |
3022 | GNUNET_memcpy(&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); | 3036 | GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); |
3023 | session->address = | 3037 | session->address = |
3024 | GNUNET_HELLO_address_allocate(&tcp_nat_probe->clientIdentity, | 3038 | GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, |
3025 | PLUGIN_NAME, | 3039 | PLUGIN_NAME, |
3026 | &t6, | 3040 | &t6, |
3027 | sizeof(struct IPv6TcpAddress), | 3041 | sizeof(struct IPv6TcpAddress), |
3028 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 3042 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
3029 | break; | 3043 | break; |
3030 | 3044 | ||
3031 | default: | 3045 | default: |
3032 | GNUNET_break_op(0); | 3046 | GNUNET_break_op (0); |
3033 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); | 3047 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); |
3034 | GNUNET_free(vaddr); | 3048 | GNUNET_free (vaddr); |
3035 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 3049 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3036 | tcp_plugin_disconnect_session(plugin, session); | 3050 | tcp_plugin_disconnect_session (plugin, session); |
3037 | return; | 3051 | return; |
3038 | } | 3052 | } |
3039 | GNUNET_free(vaddr); | 3053 | GNUNET_free (vaddr); |
3040 | GNUNET_break(NULL == session->client); | 3054 | GNUNET_break (NULL == session->client); |
3041 | session->client = client; | 3055 | session->client = client; |
3042 | GNUNET_STATISTICS_update(plugin->env->stats, | 3056 | GNUNET_STATISTICS_update (plugin->env->stats, |
3043 | gettext_noop("# TCP sessions active"), | 3057 | gettext_noop ("# TCP sessions active"), |
3044 | 1, | 3058 | 1, |
3045 | GNUNET_NO); | 3059 | GNUNET_NO); |
3046 | process_pending_messages(session); | 3060 | process_pending_messages (session); |
3047 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 3061 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3048 | } | 3062 | } |
3049 | 3063 | ||
3050 | 3064 | ||
@@ -3057,12 +3071,12 @@ handle_tcp_nat_probe(void *cls, | |||
3057 | * @param message the actual message | 3071 | * @param message the actual message |
3058 | */ | 3072 | */ |
3059 | static void | 3073 | static void |
3060 | handle_tcp_welcome(void *cls, | 3074 | handle_tcp_welcome (void *cls, |
3061 | struct GNUNET_SERVER_Client *client, | 3075 | struct GNUNET_SERVER_Client *client, |
3062 | const struct GNUNET_MessageHeader *message) | 3076 | const struct GNUNET_MessageHeader *message) |
3063 | { | 3077 | { |
3064 | struct Plugin *plugin = cls; | 3078 | struct Plugin *plugin = cls; |
3065 | const struct WelcomeMessage *wm = (const struct WelcomeMessage *)message; | 3079 | const struct WelcomeMessage *wm = (const struct WelcomeMessage *) message; |
3066 | struct GNUNET_HELLO_Address *address; | 3080 | struct GNUNET_HELLO_Address *address; |
3067 | struct GNUNET_ATS_Session *session; | 3081 | struct GNUNET_ATS_Session *session; |
3068 | size_t alen; | 3082 | size_t alen; |
@@ -3072,141 +3086,141 @@ handle_tcp_welcome(void *cls, | |||
3072 | const struct sockaddr_in *s4; | 3086 | const struct sockaddr_in *s4; |
3073 | const struct sockaddr_in6 *s6; | 3087 | const struct sockaddr_in6 *s6; |
3074 | 3088 | ||
3075 | if (0 == memcmp(&wm->clientIdentity, | 3089 | if (0 == memcmp (&wm->clientIdentity, |
3076 | plugin->env->my_identity, | 3090 | plugin->env->my_identity, |
3077 | sizeof(struct GNUNET_PeerIdentity))) | 3091 | sizeof(struct GNUNET_PeerIdentity))) |
3092 | { | ||
3093 | /* refuse connections from ourselves */ | ||
3094 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
3078 | { | 3095 | { |
3079 | /* refuse connections from ourselves */ | 3096 | LOG (GNUNET_ERROR_TYPE_INFO, |
3080 | if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) | 3097 | "Received WELCOME message from my own identity `%s' on address `%s'\n", |
3081 | { | 3098 | GNUNET_i2s (&wm->clientIdentity), |
3082 | LOG(GNUNET_ERROR_TYPE_INFO, | 3099 | GNUNET_a2s (vaddr, alen)); |
3083 | "Received WELCOME message from my own identity `%s' on address `%s'\n", | 3100 | GNUNET_free (vaddr); |
3084 | GNUNET_i2s(&wm->clientIdentity), | ||
3085 | GNUNET_a2s(vaddr, alen)); | ||
3086 | GNUNET_free(vaddr); | ||
3087 | } | ||
3088 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
3089 | return; | ||
3090 | } | 3101 | } |
3102 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3103 | return; | ||
3104 | } | ||
3091 | 3105 | ||
3092 | if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) | 3106 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3093 | { | 3107 | { |
3094 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3108 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3095 | "Received WELCOME message from `%s' on address `%s'\n", | 3109 | "Received WELCOME message from `%s' on address `%s'\n", |
3096 | GNUNET_i2s(&wm->clientIdentity), | 3110 | GNUNET_i2s (&wm->clientIdentity), |
3097 | GNUNET_a2s(vaddr, alen)); | 3111 | GNUNET_a2s (vaddr, alen)); |
3098 | GNUNET_free(vaddr); | 3112 | GNUNET_free (vaddr); |
3099 | } | 3113 | } |
3100 | GNUNET_STATISTICS_update(plugin->env->stats, | 3114 | GNUNET_STATISTICS_update (plugin->env->stats, |
3101 | gettext_noop("# TCP WELCOME messages received"), | 3115 | gettext_noop ("# TCP WELCOME messages received"), |
3102 | 1, | 3116 | 1, |
3103 | GNUNET_NO); | 3117 | GNUNET_NO); |
3104 | session = lookup_session_by_client(plugin, client); | 3118 | session = lookup_session_by_client (plugin, client); |
3105 | if (NULL != session) | 3119 | if (NULL != session) |
3120 | { | ||
3121 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
3106 | { | 3122 | { |
3107 | if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) | 3123 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3108 | { | 3124 | "Found existing session %p for peer `%s'\n", |
3109 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3125 | session, |
3110 | "Found existing session %p for peer `%s'\n", | 3126 | GNUNET_a2s (vaddr, alen)); |
3111 | session, | 3127 | GNUNET_free (vaddr); |
3112 | GNUNET_a2s(vaddr, alen)); | ||
3113 | GNUNET_free(vaddr); | ||
3114 | } | ||
3115 | } | 3128 | } |
3129 | } | ||
3116 | else | 3130 | else |
3117 | { | 3131 | { |
3118 | if (GNUNET_OK == GNUNET_SERVER_client_get_address(client, &vaddr, &alen)) | 3132 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3119 | { | 3133 | { |
3120 | if (alen == sizeof(struct sockaddr_in)) | 3134 | if (alen == sizeof(struct sockaddr_in)) |
3121 | { | 3135 | { |
3122 | s4 = vaddr; | 3136 | s4 = vaddr; |
3123 | memset(&t4, '\0', sizeof(t4)); | 3137 | memset (&t4, '\0', sizeof(t4)); |
3124 | t4.options = htonl(TCP_OPTIONS_NONE); | 3138 | t4.options = htonl (TCP_OPTIONS_NONE); |
3125 | t4.t4_port = s4->sin_port; | 3139 | t4.t4_port = s4->sin_port; |
3126 | t4.ipv4_addr = s4->sin_addr.s_addr; | 3140 | t4.ipv4_addr = s4->sin_addr.s_addr; |
3127 | address = | 3141 | address = |
3128 | GNUNET_HELLO_address_allocate(&wm->clientIdentity, | 3142 | GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
3129 | PLUGIN_NAME, | 3143 | PLUGIN_NAME, |
3130 | &t4, | 3144 | &t4, |
3131 | sizeof(t4), | 3145 | sizeof(t4), |
3132 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 3146 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
3133 | } | 3147 | } |
3134 | else if (alen == sizeof(struct sockaddr_in6)) | 3148 | else if (alen == sizeof(struct sockaddr_in6)) |
3135 | { | 3149 | { |
3136 | s6 = vaddr; | 3150 | s6 = vaddr; |
3137 | memset(&t6, '\0', sizeof(t6)); | 3151 | memset (&t6, '\0', sizeof(t6)); |
3138 | t6.options = htonl(TCP_OPTIONS_NONE); | 3152 | t6.options = htonl (TCP_OPTIONS_NONE); |
3139 | t6.t6_port = s6->sin6_port; | 3153 | t6.t6_port = s6->sin6_port; |
3140 | GNUNET_memcpy(&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); | 3154 | GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); |
3141 | address = | 3155 | address = |
3142 | GNUNET_HELLO_address_allocate(&wm->clientIdentity, | 3156 | GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
3143 | PLUGIN_NAME, | 3157 | PLUGIN_NAME, |
3144 | &t6, | 3158 | &t6, |
3145 | sizeof(t6), | 3159 | sizeof(t6), |
3146 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 3160 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); |
3147 | } | 3161 | } |
3148 | else | ||
3149 | { | ||
3150 | GNUNET_break(0); | ||
3151 | GNUNET_free_non_null(vaddr); | ||
3152 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
3153 | return; | ||
3154 | } | ||
3155 | session = create_session(plugin, | ||
3156 | address, | ||
3157 | plugin->env->get_address_type(plugin->env->cls, | ||
3158 | vaddr, | ||
3159 | alen), | ||
3160 | client, | ||
3161 | GNUNET_NO); | ||
3162 | GNUNET_break(GNUNET_NT_UNSPECIFIED != session->scope); | ||
3163 | GNUNET_HELLO_address_free(address); | ||
3164 | LOG(GNUNET_ERROR_TYPE_DEBUG, | ||
3165 | "Creating new%s session %p for peer `%s' client %p\n", | ||
3166 | GNUNET_HELLO_address_check_option(session->address, | ||
3167 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) | ||
3168 | ? " inbound" | ||
3169 | : "", | ||
3170 | session, | ||
3171 | tcp_plugin_address_to_string(plugin, | ||
3172 | session->address->address, | ||
3173 | session->address->address_length), | ||
3174 | client); | ||
3175 | GNUNET_free(vaddr); | ||
3176 | (void)GNUNET_CONTAINER_multipeermap_put( | ||
3177 | plugin->sessionmap, | ||
3178 | &session->target, | ||
3179 | session, | ||
3180 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
3181 | /* Notify transport and ATS about new session */ | ||
3182 | plugin->env->session_start(plugin->env->cls, | ||
3183 | session->address, | ||
3184 | session, | ||
3185 | session->scope); | ||
3186 | } | ||
3187 | else | 3162 | else |
3188 | { | 3163 | { |
3189 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3164 | GNUNET_break (0); |
3190 | "Did not obtain TCP socket address for incoming connection\n"); | 3165 | GNUNET_free_non_null (vaddr); |
3191 | GNUNET_break(0); | 3166 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3192 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 3167 | return; |
3193 | return; | 3168 | } |
3194 | } | 3169 | session = create_session (plugin, |
3170 | address, | ||
3171 | plugin->env->get_address_type (plugin->env->cls, | ||
3172 | vaddr, | ||
3173 | alen), | ||
3174 | client, | ||
3175 | GNUNET_NO); | ||
3176 | GNUNET_break (GNUNET_NT_UNSPECIFIED != session->scope); | ||
3177 | GNUNET_HELLO_address_free (address); | ||
3178 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
3179 | "Creating new%s session %p for peer `%s' client %p\n", | ||
3180 | GNUNET_HELLO_address_check_option (session->address, | ||
3181 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) | ||
3182 | ? " inbound" | ||
3183 | : "", | ||
3184 | session, | ||
3185 | tcp_plugin_address_to_string (plugin, | ||
3186 | session->address->address, | ||
3187 | session->address->address_length), | ||
3188 | client); | ||
3189 | GNUNET_free (vaddr); | ||
3190 | (void) GNUNET_CONTAINER_multipeermap_put ( | ||
3191 | plugin->sessionmap, | ||
3192 | &session->target, | ||
3193 | session, | ||
3194 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
3195 | /* Notify transport and ATS about new session */ | ||
3196 | plugin->env->session_start (plugin->env->cls, | ||
3197 | session->address, | ||
3198 | session, | ||
3199 | session->scope); | ||
3200 | } | ||
3201 | else | ||
3202 | { | ||
3203 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
3204 | "Did not obtain TCP socket address for incoming connection\n"); | ||
3205 | GNUNET_break (0); | ||
3206 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
3207 | return; | ||
3195 | } | 3208 | } |
3209 | } | ||
3196 | 3210 | ||
3197 | if (GNUNET_YES != session->expecting_welcome) | 3211 | if (GNUNET_YES != session->expecting_welcome) |
3198 | { | 3212 | { |
3199 | GNUNET_break_op(0); | 3213 | GNUNET_break_op (0); |
3200 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 3214 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3201 | return; | 3215 | return; |
3202 | } | 3216 | } |
3203 | session->last_activity = GNUNET_TIME_absolute_get(); | 3217 | session->last_activity = GNUNET_TIME_absolute_get (); |
3204 | session->expecting_welcome = GNUNET_NO; | 3218 | session->expecting_welcome = GNUNET_NO; |
3205 | 3219 | ||
3206 | process_pending_messages(session); | 3220 | process_pending_messages (session); |
3207 | GNUNET_SERVER_client_set_timeout(client, | 3221 | GNUNET_SERVER_client_set_timeout (client, |
3208 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 3222 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
3209 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 3223 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3210 | } | 3224 | } |
3211 | 3225 | ||
3212 | 3226 | ||
@@ -3219,102 +3233,102 @@ handle_tcp_welcome(void *cls, | |||
3219 | * @param message the actual message | 3233 | * @param message the actual message |
3220 | */ | 3234 | */ |
3221 | static void | 3235 | static void |
3222 | handle_tcp_data(void *cls, | 3236 | handle_tcp_data (void *cls, |
3223 | struct GNUNET_SERVER_Client *client, | 3237 | struct GNUNET_SERVER_Client *client, |
3224 | const struct GNUNET_MessageHeader *message) | 3238 | const struct GNUNET_MessageHeader *message) |
3225 | { | 3239 | { |
3226 | struct Plugin *plugin = cls; | 3240 | struct Plugin *plugin = cls; |
3227 | struct GNUNET_ATS_Session *session; | 3241 | struct GNUNET_ATS_Session *session; |
3228 | struct GNUNET_TIME_Relative delay; | 3242 | struct GNUNET_TIME_Relative delay; |
3229 | uint16_t type; | 3243 | uint16_t type; |
3230 | 3244 | ||
3231 | type = ntohs(message->type); | 3245 | type = ntohs (message->type); |
3232 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || | 3246 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || |
3233 | (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) | 3247 | (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) |
3234 | { | 3248 | { |
3235 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ | 3249 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ |
3236 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 3250 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3237 | return; | 3251 | return; |
3238 | } | 3252 | } |
3239 | session = lookup_session_by_client(plugin, client); | 3253 | session = lookup_session_by_client (plugin, client); |
3240 | if (NULL == session) | 3254 | if (NULL == session) |
3241 | { | 3255 | { |
3242 | /* No inbound session found */ | 3256 | /* No inbound session found */ |
3243 | void *vaddr = NULL; | 3257 | void *vaddr = NULL; |
3244 | size_t alen; | 3258 | size_t alen; |
3245 | 3259 | ||
3246 | GNUNET_assert(GNUNET_OK == | 3260 | GNUNET_assert (GNUNET_OK == |
3247 | GNUNET_SERVER_client_get_address(client, &vaddr, &alen)); | 3261 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)); |
3248 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3262 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3249 | "Received unexpected %u bytes of type %u from `%s'\n", | 3263 | "Received unexpected %u bytes of type %u from `%s'\n", |
3250 | (unsigned int)ntohs(message->size), | 3264 | (unsigned int) ntohs (message->size), |
3251 | (unsigned int)ntohs(message->type), | 3265 | (unsigned int) ntohs (message->type), |
3252 | GNUNET_a2s(vaddr, alen)); | 3266 | GNUNET_a2s (vaddr, alen)); |
3253 | GNUNET_break_op(0); | 3267 | GNUNET_break_op (0); |
3254 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 3268 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3255 | GNUNET_free_non_null(vaddr); | 3269 | GNUNET_free_non_null (vaddr); |
3256 | return; | 3270 | return; |
3257 | } | 3271 | } |
3258 | if (GNUNET_YES == session->expecting_welcome) | 3272 | if (GNUNET_YES == session->expecting_welcome) |
3259 | { | 3273 | { |
3260 | /* Session is expecting WELCOME message */ | 3274 | /* Session is expecting WELCOME message */ |
3261 | void *vaddr = NULL; | 3275 | void *vaddr = NULL; |
3262 | size_t alen; | 3276 | size_t alen; |
3263 | 3277 | ||
3264 | GNUNET_SERVER_client_get_address(client, &vaddr, &alen); | 3278 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
3265 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3279 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3266 | "Received unexpected %u bytes of type %u from `%s'\n", | 3280 | "Received unexpected %u bytes of type %u from `%s'\n", |
3267 | (unsigned int)ntohs(message->size), | 3281 | (unsigned int) ntohs (message->size), |
3268 | (unsigned int)ntohs(message->type), | 3282 | (unsigned int) ntohs (message->type), |
3269 | GNUNET_a2s(vaddr, alen)); | 3283 | GNUNET_a2s (vaddr, alen)); |
3270 | GNUNET_break_op(0); | 3284 | GNUNET_break_op (0); |
3271 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 3285 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3272 | GNUNET_free_non_null(vaddr); | 3286 | GNUNET_free_non_null (vaddr); |
3273 | return; | 3287 | return; |
3274 | } | 3288 | } |
3275 | 3289 | ||
3276 | session->last_activity = GNUNET_TIME_absolute_get(); | 3290 | session->last_activity = GNUNET_TIME_absolute_get (); |
3277 | { | 3291 | { |
3278 | void *vaddr = NULL; | 3292 | void *vaddr = NULL; |
3279 | size_t alen; | 3293 | size_t alen; |
3280 | 3294 | ||
3281 | GNUNET_SERVER_client_get_address(client, &vaddr, &alen); | 3295 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
3282 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3296 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3283 | "Passing %u bytes of type %u from `%s' at %s to transport service.\n", | 3297 | "Passing %u bytes of type %u from `%s' at %s to transport service.\n", |
3284 | (unsigned int)ntohs(message->size), | 3298 | (unsigned int) ntohs (message->size), |
3285 | (unsigned int)ntohs(message->type), | 3299 | (unsigned int) ntohs (message->type), |
3286 | GNUNET_i2s(&session->target), | 3300 | GNUNET_i2s (&session->target), |
3287 | GNUNET_a2s(vaddr, alen)); | 3301 | GNUNET_a2s (vaddr, alen)); |
3288 | GNUNET_free_non_null(vaddr); | 3302 | GNUNET_free_non_null (vaddr); |
3289 | } | 3303 | } |
3290 | 3304 | ||
3291 | GNUNET_STATISTICS_update(plugin->env->stats, | 3305 | GNUNET_STATISTICS_update (plugin->env->stats, |
3292 | gettext_noop("# bytes received via TCP"), | 3306 | gettext_noop ("# bytes received via TCP"), |
3293 | ntohs(message->size), | 3307 | ntohs (message->size), |
3294 | GNUNET_NO); | 3308 | GNUNET_NO); |
3295 | 3309 | ||
3296 | GNUNET_assert( | 3310 | GNUNET_assert ( |
3297 | GNUNET_CONTAINER_multipeermap_contains_value(plugin->sessionmap, | 3311 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
3298 | &session->target, | 3312 | &session->target, |
3299 | session)); | 3313 | session)); |
3300 | delay = | 3314 | delay = |
3301 | plugin->env->receive(plugin->env->cls, session->address, session, message); | 3315 | plugin->env->receive (plugin->env->cls, session->address, session, message); |
3302 | reschedule_session_timeout(session); | 3316 | reschedule_session_timeout (session); |
3303 | if (0 == delay.rel_value_us) | 3317 | if (0 == delay.rel_value_us) |
3304 | { | 3318 | { |
3305 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 3319 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3306 | } | 3320 | } |
3307 | else | 3321 | else |
3308 | { | 3322 | { |
3309 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3323 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3310 | "Throttling receiving from `%s' for %s\n", | 3324 | "Throttling receiving from `%s' for %s\n", |
3311 | GNUNET_i2s(&session->target), | 3325 | GNUNET_i2s (&session->target), |
3312 | GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES)); | 3326 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
3313 | GNUNET_SERVER_disable_receive_done_warning(client); | 3327 | GNUNET_SERVER_disable_receive_done_warning (client); |
3314 | GNUNET_assert(NULL == session->receive_delay_task); | 3328 | GNUNET_assert (NULL == session->receive_delay_task); |
3315 | session->receive_delay_task = | 3329 | session->receive_delay_task = |
3316 | GNUNET_SCHEDULER_add_delayed(delay, &delayed_done, session); | 3330 | GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); |
3317 | } | 3331 | } |
3318 | } | 3332 | } |
3319 | 3333 | ||
3320 | 3334 | ||
@@ -3327,30 +3341,30 @@ handle_tcp_data(void *cls, | |||
3327 | * @param client identification of the client | 3341 | * @param client identification of the client |
3328 | */ | 3342 | */ |
3329 | static void | 3343 | static void |
3330 | connect_notify(void *cls, struct GNUNET_SERVER_Client *client) | 3344 | connect_notify (void *cls, struct GNUNET_SERVER_Client *client) |
3331 | { | 3345 | { |
3332 | struct Plugin *plugin = cls; | 3346 | struct Plugin *plugin = cls; |
3333 | 3347 | ||
3334 | if (NULL == client) | 3348 | if (NULL == client) |
3335 | return; | 3349 | return; |
3336 | plugin->cur_connections++; | 3350 | plugin->cur_connections++; |
3337 | GNUNET_STATISTICS_set(plugin->env->stats, | 3351 | GNUNET_STATISTICS_set (plugin->env->stats, |
3338 | gettext_noop("# TCP server connections active"), | 3352 | gettext_noop ("# TCP server connections active"), |
3339 | plugin->cur_connections, | 3353 | plugin->cur_connections, |
3340 | GNUNET_NO); | 3354 | GNUNET_NO); |
3341 | GNUNET_STATISTICS_update(plugin->env->stats, | 3355 | GNUNET_STATISTICS_update (plugin->env->stats, |
3342 | gettext_noop("# TCP server connect events"), | 3356 | gettext_noop ("# TCP server connect events"), |
3343 | 1, | 3357 | 1, |
3344 | GNUNET_NO); | 3358 | GNUNET_NO); |
3345 | if (plugin->cur_connections != plugin->max_connections) | 3359 | if (plugin->cur_connections != plugin->max_connections) |
3346 | return; | 3360 | return; |
3347 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 3361 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3348 | _("TCP connection limit reached, suspending server\n")); | 3362 | _ ("TCP connection limit reached, suspending server\n")); |
3349 | GNUNET_STATISTICS_update(plugin->env->stats, | 3363 | GNUNET_STATISTICS_update (plugin->env->stats, |
3350 | gettext_noop("# TCP service suspended"), | 3364 | gettext_noop ("# TCP service suspended"), |
3351 | 1, | 3365 | 1, |
3352 | GNUNET_NO); | 3366 | GNUNET_NO); |
3353 | GNUNET_SERVER_suspend( | 3367 | GNUNET_SERVER_suspend ( |
3354 | plugin->server); /* Maximum number of connections rechead */ | 3368 | plugin->server); /* Maximum number of connections rechead */ |
3355 | } | 3369 | } |
3356 | 3370 | ||
@@ -3364,43 +3378,43 @@ connect_notify(void *cls, struct GNUNET_SERVER_Client *client) | |||
3364 | * @param client identification of the client | 3378 | * @param client identification of the client |
3365 | */ | 3379 | */ |
3366 | static void | 3380 | static void |
3367 | disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client) | 3381 | disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) |
3368 | { | 3382 | { |
3369 | struct Plugin *plugin = cls; | 3383 | struct Plugin *plugin = cls; |
3370 | struct GNUNET_ATS_Session *session; | 3384 | struct GNUNET_ATS_Session *session; |
3371 | 3385 | ||
3372 | if (NULL == client) | 3386 | if (NULL == client) |
3373 | return; | 3387 | return; |
3374 | GNUNET_assert(plugin->cur_connections >= 1); | 3388 | GNUNET_assert (plugin->cur_connections >= 1); |
3375 | plugin->cur_connections--; | 3389 | plugin->cur_connections--; |
3376 | session = lookup_session_by_client(plugin, client); | 3390 | session = lookup_session_by_client (plugin, client); |
3377 | if (NULL == session) | 3391 | if (NULL == session) |
3378 | return; /* unknown, nothing to do */ | 3392 | return; /* unknown, nothing to do */ |
3379 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3393 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3380 | "Destroying session of `%s' with %s due to network-level disconnect.\n", | 3394 | "Destroying session of `%s' with %s due to network-level disconnect.\n", |
3381 | GNUNET_i2s(&session->target), | 3395 | GNUNET_i2s (&session->target), |
3382 | tcp_plugin_address_to_string(session->plugin, | 3396 | tcp_plugin_address_to_string (session->plugin, |
3383 | session->address->address, | 3397 | session->address->address, |
3384 | session->address->address_length)); | 3398 | session->address->address_length)); |
3385 | 3399 | ||
3386 | if (plugin->cur_connections == plugin->max_connections) | 3400 | if (plugin->cur_connections == plugin->max_connections) |
3387 | { | 3401 | { |
3388 | GNUNET_STATISTICS_update(session->plugin->env->stats, | 3402 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
3389 | gettext_noop("# TCP service resumed"), | 3403 | gettext_noop ("# TCP service resumed"), |
3390 | 1, | 3404 | 1, |
3391 | GNUNET_NO); | 3405 | GNUNET_NO); |
3392 | GNUNET_SERVER_resume(plugin->server); /* Resume server */ | 3406 | GNUNET_SERVER_resume (plugin->server); /* Resume server */ |
3393 | } | 3407 | } |
3394 | GNUNET_STATISTICS_set(plugin->env->stats, | 3408 | GNUNET_STATISTICS_set (plugin->env->stats, |
3395 | gettext_noop("# TCP server connections active"), | 3409 | gettext_noop ("# TCP server connections active"), |
3396 | plugin->cur_connections, | 3410 | plugin->cur_connections, |
3397 | GNUNET_NO); | 3411 | GNUNET_NO); |
3398 | GNUNET_STATISTICS_update(session->plugin->env->stats, | 3412 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
3399 | gettext_noop( | 3413 | gettext_noop ( |
3400 | "# network-level TCP disconnect events"), | 3414 | "# network-level TCP disconnect events"), |
3401 | 1, | 3415 | 1, |
3402 | GNUNET_NO); | 3416 | GNUNET_NO); |
3403 | tcp_plugin_disconnect_session(plugin, session); | 3417 | tcp_plugin_disconnect_session (plugin, session); |
3404 | } | 3418 | } |
3405 | 3419 | ||
3406 | 3420 | ||
@@ -3413,28 +3427,28 @@ disconnect_notify(void *cls, struct GNUNET_SERVER_Client *client) | |||
3413 | * @return number of bytes copied into @a buf | 3427 | * @return number of bytes copied into @a buf |
3414 | */ | 3428 | */ |
3415 | static size_t | 3429 | static size_t |
3416 | notify_send_probe(void *cls, size_t size, void *buf) | 3430 | notify_send_probe (void *cls, size_t size, void *buf) |
3417 | { | 3431 | { |
3418 | struct TCPProbeContext *tcp_probe_ctx = cls; | 3432 | struct TCPProbeContext *tcp_probe_ctx = cls; |
3419 | struct Plugin *plugin = tcp_probe_ctx->plugin; | 3433 | struct Plugin *plugin = tcp_probe_ctx->plugin; |
3420 | size_t ret; | 3434 | size_t ret; |
3421 | 3435 | ||
3422 | tcp_probe_ctx->transmit_handle = NULL; | 3436 | tcp_probe_ctx->transmit_handle = NULL; |
3423 | GNUNET_CONTAINER_DLL_remove(plugin->probe_head, | 3437 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, |
3424 | plugin->probe_tail, | 3438 | plugin->probe_tail, |
3425 | tcp_probe_ctx); | 3439 | tcp_probe_ctx); |
3426 | if (NULL == buf) | 3440 | if (NULL == buf) |
3427 | { | 3441 | { |
3428 | GNUNET_CONNECTION_destroy(tcp_probe_ctx->sock); | 3442 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); |
3429 | GNUNET_free(tcp_probe_ctx); | 3443 | GNUNET_free (tcp_probe_ctx); |
3430 | return 0; | 3444 | return 0; |
3431 | } | 3445 | } |
3432 | GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); | 3446 | GNUNET_assert (size >= sizeof(tcp_probe_ctx->message)); |
3433 | GNUNET_memcpy(buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); | 3447 | GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); |
3434 | GNUNET_SERVER_connect_socket(tcp_probe_ctx->plugin->server, | 3448 | GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, |
3435 | tcp_probe_ctx->sock); | 3449 | tcp_probe_ctx->sock); |
3436 | ret = sizeof(tcp_probe_ctx->message); | 3450 | ret = sizeof(tcp_probe_ctx->message); |
3437 | GNUNET_free(tcp_probe_ctx); | 3451 | GNUNET_free (tcp_probe_ctx); |
3438 | return ret; | 3452 | return ret; |
3439 | } | 3453 | } |
3440 | 3454 | ||
@@ -3449,9 +3463,9 @@ notify_send_probe(void *cls, size_t size, void *buf) | |||
3449 | * @param addrlen number of bytes in @a addr | 3463 | * @param addrlen number of bytes in @a addr |
3450 | */ | 3464 | */ |
3451 | static void | 3465 | static void |
3452 | try_connection_reversal(void *cls, | 3466 | try_connection_reversal (void *cls, |
3453 | const struct sockaddr *addr, | 3467 | const struct sockaddr *addr, |
3454 | socklen_t addrlen) | 3468 | socklen_t addrlen) |
3455 | { | 3469 | { |
3456 | struct Plugin *plugin = cls; | 3470 | struct Plugin *plugin = cls; |
3457 | struct GNUNET_CONNECTION_Handle *sock; | 3471 | struct GNUNET_CONNECTION_Handle *sock; |
@@ -3461,31 +3475,31 @@ try_connection_reversal(void *cls, | |||
3461 | * We have received an ICMP response, ostensibly from a peer | 3475 | * We have received an ICMP response, ostensibly from a peer |
3462 | * that wants to connect to us! Send a message to establish a connection. | 3476 | * that wants to connect to us! Send a message to establish a connection. |
3463 | */ | 3477 | */ |
3464 | sock = GNUNET_CONNECTION_create_from_sockaddr(AF_INET, addr, addrlen); | 3478 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); |
3465 | if (NULL == sock) | 3479 | if (NULL == sock) |
3466 | { | 3480 | { |
3467 | /* failed for some odd reason (out of sockets?); ignore attempt */ | 3481 | /* failed for some odd reason (out of sockets?); ignore attempt */ |
3468 | return; | 3482 | return; |
3469 | } | 3483 | } |
3470 | 3484 | ||
3471 | tcp_probe_ctx = GNUNET_new(struct TCPProbeContext); | 3485 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); |
3472 | tcp_probe_ctx->message.header.size = | 3486 | tcp_probe_ctx->message.header.size = |
3473 | htons(sizeof(struct TCP_NAT_ProbeMessage)); | 3487 | htons (sizeof(struct TCP_NAT_ProbeMessage)); |
3474 | tcp_probe_ctx->message.header.type = | 3488 | tcp_probe_ctx->message.header.type = |
3475 | htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); | 3489 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); |
3476 | tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity; | 3490 | tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity; |
3477 | tcp_probe_ctx->plugin = plugin; | 3491 | tcp_probe_ctx->plugin = plugin; |
3478 | tcp_probe_ctx->sock = sock; | 3492 | tcp_probe_ctx->sock = sock; |
3479 | GNUNET_CONTAINER_DLL_insert(plugin->probe_head, | 3493 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, |
3480 | plugin->probe_tail, | 3494 | plugin->probe_tail, |
3481 | tcp_probe_ctx); | 3495 | tcp_probe_ctx); |
3482 | tcp_probe_ctx->transmit_handle = | 3496 | tcp_probe_ctx->transmit_handle = |
3483 | GNUNET_CONNECTION_notify_transmit_ready(sock, | 3497 | GNUNET_CONNECTION_notify_transmit_ready (sock, |
3484 | ntohs(tcp_probe_ctx->message | 3498 | ntohs (tcp_probe_ctx->message |
3485 | .header.size), | 3499 | .header.size), |
3486 | GNUNET_TIME_UNIT_FOREVER_REL, | 3500 | GNUNET_TIME_UNIT_FOREVER_REL, |
3487 | ¬ify_send_probe, | 3501 | ¬ify_send_probe, |
3488 | tcp_probe_ctx); | 3502 | tcp_probe_ctx); |
3489 | } | 3503 | } |
3490 | 3504 | ||
3491 | 3505 | ||
@@ -3497,7 +3511,7 @@ try_connection_reversal(void *cls, | |||
3497 | * @return the network type in HBO or #GNUNET_SYSERR | 3511 | * @return the network type in HBO or #GNUNET_SYSERR |
3498 | */ | 3512 | */ |
3499 | static enum GNUNET_NetworkType | 3513 | static enum GNUNET_NetworkType |
3500 | tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) | 3514 | tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) |
3501 | { | 3515 | { |
3502 | return session->scope; | 3516 | return session->scope; |
3503 | } | 3517 | } |
@@ -3511,8 +3525,8 @@ tcp_plugin_get_network(void *cls, struct GNUNET_ATS_Session *session) | |||
3511 | * @return the network type | 3525 | * @return the network type |
3512 | */ | 3526 | */ |
3513 | static enum GNUNET_NetworkType | 3527 | static enum GNUNET_NetworkType |
3514 | tcp_plugin_get_network_for_address(void *cls, | 3528 | tcp_plugin_get_network_for_address (void *cls, |
3515 | const struct GNUNET_HELLO_Address *address) | 3529 | const struct GNUNET_HELLO_Address *address) |
3516 | { | 3530 | { |
3517 | struct Plugin *plugin = cls; | 3531 | struct Plugin *plugin = cls; |
3518 | size_t addrlen; | 3532 | size_t addrlen; |
@@ -3525,39 +3539,39 @@ tcp_plugin_get_network_for_address(void *cls, | |||
3525 | 3539 | ||
3526 | addrlen = address->address_length; | 3540 | addrlen = address->address_length; |
3527 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 3541 | if (addrlen == sizeof(struct IPv6TcpAddress)) |
3528 | { | 3542 | { |
3529 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ | 3543 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
3530 | t6 = address->address; | 3544 | t6 = address->address; |
3531 | memset(&a6, 0, sizeof(a6)); | 3545 | memset (&a6, 0, sizeof(a6)); |
3532 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3546 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3533 | a6.sin6_len = sizeof(a6); | 3547 | a6.sin6_len = sizeof(a6); |
3534 | #endif | 3548 | #endif |
3535 | a6.sin6_family = AF_INET6; | 3549 | a6.sin6_family = AF_INET6; |
3536 | a6.sin6_port = t6->t6_port; | 3550 | a6.sin6_port = t6->t6_port; |
3537 | GNUNET_memcpy(&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | 3551 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); |
3538 | sb = &a6; | 3552 | sb = &a6; |
3539 | sbs = sizeof(a6); | 3553 | sbs = sizeof(a6); |
3540 | } | 3554 | } |
3541 | else if (addrlen == sizeof(struct IPv4TcpAddress)) | 3555 | else if (addrlen == sizeof(struct IPv4TcpAddress)) |
3542 | { | 3556 | { |
3543 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ | 3557 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
3544 | t4 = address->address; | 3558 | t4 = address->address; |
3545 | memset(&a4, 0, sizeof(a4)); | 3559 | memset (&a4, 0, sizeof(a4)); |
3546 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3560 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3547 | a4.sin_len = sizeof(a4); | 3561 | a4.sin_len = sizeof(a4); |
3548 | #endif | 3562 | #endif |
3549 | a4.sin_family = AF_INET; | 3563 | a4.sin_family = AF_INET; |
3550 | a4.sin_port = t4->t4_port; | 3564 | a4.sin_port = t4->t4_port; |
3551 | a4.sin_addr.s_addr = t4->ipv4_addr; | 3565 | a4.sin_addr.s_addr = t4->ipv4_addr; |
3552 | sb = &a4; | 3566 | sb = &a4; |
3553 | sbs = sizeof(a4); | 3567 | sbs = sizeof(a4); |
3554 | } | 3568 | } |
3555 | else | 3569 | else |
3556 | { | 3570 | { |
3557 | GNUNET_break(0); | 3571 | GNUNET_break (0); |
3558 | return GNUNET_NT_UNSPECIFIED; | 3572 | return GNUNET_NT_UNSPECIFIED; |
3559 | } | 3573 | } |
3560 | return plugin->env->get_address_type(plugin->env->cls, sb, sbs); | 3574 | return plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
3561 | } | 3575 | } |
3562 | 3576 | ||
3563 | 3577 | ||
@@ -3571,17 +3585,17 @@ tcp_plugin_get_network_for_address(void *cls, | |||
3571 | * @return #GNUNET_OK (continue to iterate) | 3585 | * @return #GNUNET_OK (continue to iterate) |
3572 | */ | 3586 | */ |
3573 | static int | 3587 | static int |
3574 | send_session_info_iter(void *cls, | 3588 | send_session_info_iter (void *cls, |
3575 | const struct GNUNET_PeerIdentity *peer, | 3589 | const struct GNUNET_PeerIdentity *peer, |
3576 | void *value) | 3590 | void *value) |
3577 | { | 3591 | { |
3578 | struct Plugin *plugin = cls; | 3592 | struct Plugin *plugin = cls; |
3579 | struct GNUNET_ATS_Session *session = value; | 3593 | struct GNUNET_ATS_Session *session = value; |
3580 | 3594 | ||
3581 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_INIT); | 3595 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
3582 | /* FIXME: cannot tell if this is up or not from current | 3596 | /* FIXME: cannot tell if this is up or not from current |
3583 | session state... */ | 3597 | session state... */ |
3584 | notify_session_monitor(plugin, session, GNUNET_TRANSPORT_SS_UP); | 3598 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
3585 | return GNUNET_OK; | 3599 | return GNUNET_OK; |
3586 | } | 3600 | } |
3587 | 3601 | ||
@@ -3599,22 +3613,22 @@ send_session_info_iter(void *cls, | |||
3599 | * @param sic_cls closure for @a sic | 3613 | * @param sic_cls closure for @a sic |
3600 | */ | 3614 | */ |
3601 | static void | 3615 | static void |
3602 | tcp_plugin_setup_monitor(void *cls, | 3616 | tcp_plugin_setup_monitor (void *cls, |
3603 | GNUNET_TRANSPORT_SessionInfoCallback sic, | 3617 | GNUNET_TRANSPORT_SessionInfoCallback sic, |
3604 | void *sic_cls) | 3618 | void *sic_cls) |
3605 | { | 3619 | { |
3606 | struct Plugin *plugin = cls; | 3620 | struct Plugin *plugin = cls; |
3607 | 3621 | ||
3608 | plugin->sic = sic; | 3622 | plugin->sic = sic; |
3609 | plugin->sic_cls = sic_cls; | 3623 | plugin->sic_cls = sic_cls; |
3610 | if (NULL != sic) | 3624 | if (NULL != sic) |
3611 | { | 3625 | { |
3612 | GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, | 3626 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
3613 | &send_session_info_iter, | 3627 | &send_session_info_iter, |
3614 | plugin); | 3628 | plugin); |
3615 | /* signal end of first iteration */ | 3629 | /* signal end of first iteration */ |
3616 | sic(sic_cls, NULL, NULL); | 3630 | sic (sic_cls, NULL, NULL); |
3617 | } | 3631 | } |
3618 | } | 3632 | } |
3619 | 3633 | ||
3620 | 3634 | ||
@@ -3625,7 +3639,7 @@ tcp_plugin_setup_monitor(void *cls, | |||
3625 | * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error | 3639 | * @return the `struct GNUNET_TRANSPORT_PluginFunctions *` or NULL on error |
3626 | */ | 3640 | */ |
3627 | void * | 3641 | void * |
3628 | libgnunet_plugin_transport_tcp_init(void *cls) | 3642 | libgnunet_plugin_transport_tcp_init (void *cls) |
3629 | { | 3643 | { |
3630 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = | 3644 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = |
3631 | { { &handle_tcp_welcome, | 3645 | { { &handle_tcp_welcome, |
@@ -3633,9 +3647,9 @@ libgnunet_plugin_transport_tcp_init(void *cls) | |||
3633 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, | 3647 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, |
3634 | sizeof(struct WelcomeMessage) }, | 3648 | sizeof(struct WelcomeMessage) }, |
3635 | { &handle_tcp_nat_probe, | 3649 | { &handle_tcp_nat_probe, |
3636 | NULL, | 3650 | NULL, |
3637 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, | 3651 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, |
3638 | sizeof(struct TCP_NAT_ProbeMessage) }, | 3652 | sizeof(struct TCP_NAT_ProbeMessage) }, |
3639 | { &handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0 }, | 3653 | { &handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0 }, |
3640 | { NULL, NULL, 0, 0 } }; | 3654 | { NULL, NULL, 0, 0 } }; |
3641 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 3655 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
@@ -3657,152 +3671,152 @@ libgnunet_plugin_transport_tcp_init(void *cls) | |||
3657 | socklen_t *addrlens; | 3671 | socklen_t *addrlens; |
3658 | 3672 | ||
3659 | if (NULL == env->receive) | 3673 | if (NULL == env->receive) |
3660 | { | 3674 | { |
3661 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully | 3675 | /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully |
3662 | initialze the plugin or the API */ | 3676 | initialze the plugin or the API */ |
3663 | api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); | 3677 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3664 | api->cls = NULL; | 3678 | api->cls = NULL; |
3665 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; | 3679 | api->address_pretty_printer = &tcp_plugin_address_pretty_printer; |
3666 | api->address_to_string = &tcp_plugin_address_to_string; | 3680 | api->address_to_string = &tcp_plugin_address_to_string; |
3667 | api->string_to_address = &tcp_plugin_string_to_address; | 3681 | api->string_to_address = &tcp_plugin_string_to_address; |
3668 | return api; | 3682 | return api; |
3669 | } | 3683 | } |
3670 | 3684 | ||
3671 | GNUNET_assert(NULL != env->cfg); | 3685 | GNUNET_assert (NULL != env->cfg); |
3672 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, | 3686 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3673 | "transport-tcp", | 3687 | "transport-tcp", |
3674 | "MAX_CONNECTIONS", | 3688 | "MAX_CONNECTIONS", |
3675 | &max_connections)) | 3689 | &max_connections)) |
3676 | max_connections = 128; | 3690 | max_connections = 128; |
3677 | 3691 | ||
3678 | aport = 0; | 3692 | aport = 0; |
3679 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(env->cfg, | 3693 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3680 | "transport-tcp", | ||
3681 | "PORT", | ||
3682 | &bport)) || | ||
3683 | (bport > 65535) || | ||
3684 | ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(env->cfg, | ||
3685 | "transport-tcp", | 3694 | "transport-tcp", |
3686 | "ADVERTISED-PORT", | 3695 | "PORT", |
3687 | &aport)) && | 3696 | &bport)) || |
3697 | (bport > 65535) || | ||
3698 | ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg, | ||
3699 | "transport-tcp", | ||
3700 | "ADVERTISED-PORT", | ||
3701 | &aport)) && | ||
3688 | (aport > 65535))) | 3702 | (aport > 65535))) |
3689 | { | 3703 | { |
3690 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3704 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3691 | _("Require valid port number for service `%s' in configuration!\n"), | 3705 | _ ("Require valid port number for service `%s' in configuration!\n"), |
3692 | "transport-tcp"); | 3706 | "transport-tcp"); |
3693 | return NULL; | 3707 | return NULL; |
3694 | } | 3708 | } |
3695 | if (0 == aport) | 3709 | if (0 == aport) |
3696 | aport = bport; | 3710 | aport = bport; |
3697 | if (0 == bport) | 3711 | if (0 == bport) |
3698 | aport = 0; | 3712 | aport = 0; |
3699 | if (0 != bport) | 3713 | if (0 != bport) |
3714 | { | ||
3715 | service = LEGACY_SERVICE_start ("transport-tcp", | ||
3716 | env->cfg, | ||
3717 | LEGACY_SERVICE_OPTION_NONE); | ||
3718 | if (NULL == service) | ||
3700 | { | 3719 | { |
3701 | service = LEGACY_SERVICE_start("transport-tcp", | 3720 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n")); |
3702 | env->cfg, | 3721 | return NULL; |
3703 | LEGACY_SERVICE_OPTION_NONE); | ||
3704 | if (NULL == service) | ||
3705 | { | ||
3706 | LOG(GNUNET_ERROR_TYPE_WARNING, _("Failed to start service.\n")); | ||
3707 | return NULL; | ||
3708 | } | ||
3709 | } | 3722 | } |
3723 | } | ||
3710 | else | 3724 | else |
3711 | service = NULL; | 3725 | service = NULL; |
3712 | 3726 | ||
3713 | api = NULL; | 3727 | api = NULL; |
3714 | plugin = GNUNET_new(struct Plugin); | 3728 | plugin = GNUNET_new (struct Plugin); |
3715 | plugin->sessionmap = | 3729 | plugin->sessionmap = |
3716 | GNUNET_CONTAINER_multipeermap_create(max_connections, GNUNET_YES); | 3730 | GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); |
3717 | plugin->max_connections = max_connections; | 3731 | plugin->max_connections = max_connections; |
3718 | plugin->open_port = bport; | 3732 | plugin->open_port = bport; |
3719 | plugin->adv_port = aport; | 3733 | plugin->adv_port = aport; |
3720 | plugin->env = env; | 3734 | plugin->env = env; |
3721 | plugin->my_welcome.header.size = htons(sizeof(struct WelcomeMessage)); | 3735 | plugin->my_welcome.header.size = htons (sizeof(struct WelcomeMessage)); |
3722 | plugin->my_welcome.header.type = | 3736 | plugin->my_welcome.header.type = |
3723 | htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); | 3737 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); |
3724 | plugin->my_welcome.clientIdentity = *plugin->env->my_identity; | 3738 | plugin->my_welcome.clientIdentity = *plugin->env->my_identity; |
3725 | 3739 | ||
3726 | if ((NULL != service) && | 3740 | if ((NULL != service) && |
3727 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(env->cfg, | 3741 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3728 | "transport-tcp", | 3742 | "transport-tcp", |
3729 | "TCP_STEALTH"))) | 3743 | "TCP_STEALTH"))) |
3730 | { | 3744 | { |
3731 | #ifdef TCP_STEALTH | 3745 | #ifdef TCP_STEALTH |
3732 | plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; | 3746 | plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; |
3733 | lsocks = LEGACY_SERVICE_get_listen_sockets(service); | 3747 | lsocks = LEGACY_SERVICE_get_listen_sockets (service); |
3734 | if (NULL != lsocks) | 3748 | if (NULL != lsocks) |
3749 | { | ||
3750 | uint32_t len = sizeof(struct WelcomeMessage); | ||
3751 | |||
3752 | for (i = 0; NULL != lsocks[i]; i++) | ||
3753 | { | ||
3754 | if ( | ||
3755 | (GNUNET_OK != | ||
3756 | GNUNET_NETWORK_socket_setsockopt (lsocks[i], | ||
3757 | IPPROTO_TCP, | ||
3758 | TCP_STEALTH, | ||
3759 | env->my_identity, | ||
3760 | sizeof( | ||
3761 | struct GNUNET_PeerIdentity))) || | ||
3762 | (GNUNET_OK != | ||
3763 | GNUNET_NETWORK_socket_setsockopt (lsocks[i], | ||
3764 | IPPROTO_TCP, | ||
3765 | TCP_STEALTH_INTEGRITY_LEN, | ||
3766 | &len, | ||
3767 | sizeof(len)))) | ||
3735 | { | 3768 | { |
3736 | uint32_t len = sizeof(struct WelcomeMessage); | 3769 | /* TCP STEALTH not supported by kernel */ |
3737 | 3770 | GNUNET_assert (0 == i); | |
3738 | for (i = 0; NULL != lsocks[i]; i++) | 3771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3739 | { | 3772 | _ ("TCP_STEALTH not supported on this platform.\n")); |
3740 | if ( | 3773 | goto die; |
3741 | (GNUNET_OK != | ||
3742 | GNUNET_NETWORK_socket_setsockopt(lsocks[i], | ||
3743 | IPPROTO_TCP, | ||
3744 | TCP_STEALTH, | ||
3745 | env->my_identity, | ||
3746 | sizeof( | ||
3747 | struct GNUNET_PeerIdentity))) || | ||
3748 | (GNUNET_OK != | ||
3749 | GNUNET_NETWORK_socket_setsockopt(lsocks[i], | ||
3750 | IPPROTO_TCP, | ||
3751 | TCP_STEALTH_INTEGRITY_LEN, | ||
3752 | &len, | ||
3753 | sizeof(len)))) | ||
3754 | { | ||
3755 | /* TCP STEALTH not supported by kernel */ | ||
3756 | GNUNET_assert(0 == i); | ||
3757 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
3758 | _("TCP_STEALTH not supported on this platform.\n")); | ||
3759 | goto die; | ||
3760 | } | ||
3761 | } | ||
3762 | } | 3774 | } |
3775 | } | ||
3776 | } | ||
3763 | #else | 3777 | #else |
3764 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 3778 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3765 | _("TCP_STEALTH not supported on this platform.\n")); | 3779 | _ ("TCP_STEALTH not supported on this platform.\n")); |
3766 | goto die; | 3780 | goto die; |
3767 | #endif | 3781 | #endif |
3768 | } | 3782 | } |
3769 | 3783 | ||
3770 | if ((NULL != service) && | 3784 | if ((NULL != service) && |
3771 | (GNUNET_SYSERR != | 3785 | (GNUNET_SYSERR != |
3772 | (ret_s = | 3786 | (ret_s = |
3773 | get_server_addresses("transport-tcp", env->cfg, &addrs, &addrlens)))) | 3787 | get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens)))) |
3774 | { | 3788 | { |
3775 | for (ret = ret_s - 1; ret >= 0; ret--) | 3789 | for (ret = ret_s - 1; ret >= 0; ret--) |
3776 | LOG(GNUNET_ERROR_TYPE_INFO, | 3790 | LOG (GNUNET_ERROR_TYPE_INFO, |
3777 | "Binding to address `%s'\n", | 3791 | "Binding to address `%s'\n", |
3778 | GNUNET_a2s(addrs[ret], addrlens[ret])); | 3792 | GNUNET_a2s (addrs[ret], addrlens[ret])); |
3779 | plugin->nat = GNUNET_NAT_register(env->cfg, | 3793 | plugin->nat = GNUNET_NAT_register (env->cfg, |
3780 | "transport-tcp", | 3794 | "transport-tcp", |
3781 | IPPROTO_TCP, | 3795 | IPPROTO_TCP, |
3782 | (unsigned int)ret_s, | 3796 | (unsigned int) ret_s, |
3783 | (const struct sockaddr **)addrs, | 3797 | (const struct sockaddr **) addrs, |
3784 | addrlens, | 3798 | addrlens, |
3785 | &tcp_nat_port_map_callback, | 3799 | &tcp_nat_port_map_callback, |
3786 | &try_connection_reversal, | 3800 | &try_connection_reversal, |
3787 | plugin); | 3801 | plugin); |
3788 | for (ret = ret_s - 1; ret >= 0; ret--) | 3802 | for (ret = ret_s - 1; ret >= 0; ret--) |
3789 | GNUNET_free(addrs[ret]); | 3803 | GNUNET_free (addrs[ret]); |
3790 | GNUNET_free_non_null(addrs); | 3804 | GNUNET_free_non_null (addrs); |
3791 | GNUNET_free_non_null(addrlens); | 3805 | GNUNET_free_non_null (addrlens); |
3792 | } | 3806 | } |
3793 | else | 3807 | else |
3794 | { | 3808 | { |
3795 | plugin->nat = GNUNET_NAT_register(plugin->env->cfg, | 3809 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, |
3796 | "transport-tcp", | 3810 | "transport-tcp", |
3797 | IPPROTO_TCP, | 3811 | IPPROTO_TCP, |
3798 | 0, | 3812 | 0, |
3799 | NULL, | 3813 | NULL, |
3800 | NULL, | 3814 | NULL, |
3801 | NULL, | 3815 | NULL, |
3802 | &try_connection_reversal, | 3816 | &try_connection_reversal, |
3803 | plugin); | 3817 | plugin); |
3804 | } | 3818 | } |
3805 | api = GNUNET_new(struct GNUNET_TRANSPORT_PluginFunctions); | 3819 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
3806 | api->cls = plugin; | 3820 | api->cls = plugin; |
3807 | api->send = &tcp_plugin_send; | 3821 | api->send = &tcp_plugin_send; |
3808 | api->get_session = &tcp_plugin_get_session; | 3822 | api->get_session = &tcp_plugin_get_session; |
@@ -3820,65 +3834,65 @@ libgnunet_plugin_transport_tcp_init(void *cls) | |||
3820 | api->setup_monitor = &tcp_plugin_setup_monitor; | 3834 | api->setup_monitor = &tcp_plugin_setup_monitor; |
3821 | plugin->service = service; | 3835 | plugin->service = service; |
3822 | if (NULL != service) | 3836 | if (NULL != service) |
3823 | { | 3837 | { |
3824 | plugin->server = LEGACY_SERVICE_get_server(service); | 3838 | plugin->server = LEGACY_SERVICE_get_server (service); |
3825 | } | 3839 | } |
3826 | else | 3840 | else |
3841 | { | ||
3842 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg, | ||
3843 | "transport-tcp", | ||
3844 | "TIMEOUT", | ||
3845 | &idle_timeout)) | ||
3827 | { | 3846 | { |
3828 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time(env->cfg, | 3847 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3829 | "transport-tcp", | 3848 | "transport-tcp", |
3830 | "TIMEOUT", | 3849 | "TIMEOUT"); |
3831 | &idle_timeout)) | 3850 | goto die; |
3832 | { | ||
3833 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | ||
3834 | "transport-tcp", | ||
3835 | "TIMEOUT"); | ||
3836 | goto die; | ||
3837 | } | ||
3838 | plugin->server = GNUNET_SERVER_create_with_sockets(NULL, | ||
3839 | plugin, | ||
3840 | NULL, | ||
3841 | idle_timeout, | ||
3842 | GNUNET_YES); | ||
3843 | } | 3851 | } |
3844 | plugin->handlers = GNUNET_malloc(sizeof(my_handlers)); | 3852 | plugin->server = GNUNET_SERVER_create_with_sockets (NULL, |
3845 | GNUNET_memcpy(plugin->handlers, my_handlers, sizeof(my_handlers)); | 3853 | plugin, |
3854 | NULL, | ||
3855 | idle_timeout, | ||
3856 | GNUNET_YES); | ||
3857 | } | ||
3858 | plugin->handlers = GNUNET_malloc (sizeof(my_handlers)); | ||
3859 | GNUNET_memcpy (plugin->handlers, my_handlers, sizeof(my_handlers)); | ||
3846 | for (i = 0; | 3860 | for (i = 0; |
3847 | i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); | 3861 | i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler); |
3848 | i++) | 3862 | i++) |
3849 | plugin->handlers[i].callback_cls = plugin; | 3863 | plugin->handlers[i].callback_cls = plugin; |
3850 | 3864 | ||
3851 | GNUNET_SERVER_add_handlers(plugin->server, plugin->handlers); | 3865 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); |
3852 | GNUNET_SERVER_connect_notify(plugin->server, &connect_notify, plugin); | 3866 | GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin); |
3853 | GNUNET_SERVER_disconnect_notify(plugin->server, &disconnect_notify, plugin); | 3867 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); |
3854 | plugin->nat_wait_conns = | 3868 | plugin->nat_wait_conns = |
3855 | GNUNET_CONTAINER_multipeermap_create(16, GNUNET_YES); | 3869 | GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); |
3856 | if (0 != bport) | 3870 | if (0 != bport) |
3857 | LOG(GNUNET_ERROR_TYPE_INFO, | 3871 | LOG (GNUNET_ERROR_TYPE_INFO, |
3858 | _("TCP transport listening on port %llu\n"), | 3872 | _ ("TCP transport listening on port %llu\n"), |
3859 | bport); | 3873 | bport); |
3860 | else | 3874 | else |
3861 | LOG(GNUNET_ERROR_TYPE_INFO, | 3875 | LOG (GNUNET_ERROR_TYPE_INFO, |
3862 | _("TCP transport not listening on any port (client only)\n")); | 3876 | _ ("TCP transport not listening on any port (client only)\n")); |
3863 | if ((aport != bport) && (0 != bport)) | 3877 | if ((aport != bport) && (0 != bport)) |
3864 | LOG(GNUNET_ERROR_TYPE_INFO, | 3878 | LOG (GNUNET_ERROR_TYPE_INFO, |
3865 | _("TCP transport advertises itself as being on port %llu\n"), | 3879 | _ ("TCP transport advertises itself as being on port %llu\n"), |
3866 | aport); | 3880 | aport); |
3867 | /* Initially set connections to 0 */ | 3881 | /* Initially set connections to 0 */ |
3868 | GNUNET_STATISTICS_set(plugin->env->stats, | 3882 | GNUNET_STATISTICS_set (plugin->env->stats, |
3869 | gettext_noop("# TCP sessions active"), | 3883 | gettext_noop ("# TCP sessions active"), |
3870 | 0, | 3884 | 0, |
3871 | GNUNET_NO); | 3885 | GNUNET_NO); |
3872 | return api; | 3886 | return api; |
3873 | 3887 | ||
3874 | die: | 3888 | die: |
3875 | if (NULL != plugin->nat) | 3889 | if (NULL != plugin->nat) |
3876 | GNUNET_NAT_unregister(plugin->nat); | 3890 | GNUNET_NAT_unregister (plugin->nat); |
3877 | GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap); | 3891 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); |
3878 | if (NULL != service) | 3892 | if (NULL != service) |
3879 | LEGACY_SERVICE_stop(service); | 3893 | LEGACY_SERVICE_stop (service); |
3880 | GNUNET_free(plugin); | 3894 | GNUNET_free (plugin); |
3881 | GNUNET_free_non_null(api); | 3895 | GNUNET_free_non_null (api); |
3882 | return NULL; | 3896 | return NULL; |
3883 | } | 3897 | } |
3884 | 3898 | ||
@@ -3890,7 +3904,7 @@ die: | |||
3890 | * @return NULL | 3904 | * @return NULL |
3891 | */ | 3905 | */ |
3892 | void * | 3906 | void * |
3893 | libgnunet_plugin_transport_tcp_done(void *cls) | 3907 | libgnunet_plugin_transport_tcp_done (void *cls) |
3894 | { | 3908 | { |
3895 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 3909 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
3896 | struct Plugin *plugin = api->cls; | 3910 | struct Plugin *plugin = api->cls; |
@@ -3899,52 +3913,52 @@ libgnunet_plugin_transport_tcp_done(void *cls) | |||
3899 | struct PrettyPrinterContext *next; | 3913 | struct PrettyPrinterContext *next; |
3900 | 3914 | ||
3901 | if (NULL == plugin) | 3915 | if (NULL == plugin) |
3902 | { | 3916 | { |
3903 | GNUNET_free(api); | 3917 | GNUNET_free (api); |
3904 | return NULL; | 3918 | return NULL; |
3905 | } | 3919 | } |
3906 | LOG(GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); | 3920 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); |
3907 | 3921 | ||
3908 | /* Removing leftover sessions */ | 3922 | /* Removing leftover sessions */ |
3909 | GNUNET_CONTAINER_multipeermap_iterate(plugin->sessionmap, | 3923 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
3910 | &session_disconnect_it, | 3924 | &session_disconnect_it, |
3911 | plugin); | 3925 | plugin); |
3912 | /* Removing leftover NAT sessions */ | 3926 | /* Removing leftover NAT sessions */ |
3913 | GNUNET_CONTAINER_multipeermap_iterate(plugin->nat_wait_conns, | 3927 | GNUNET_CONTAINER_multipeermap_iterate (plugin->nat_wait_conns, |
3914 | &session_disconnect_it, | 3928 | &session_disconnect_it, |
3915 | plugin); | 3929 | plugin); |
3916 | 3930 | ||
3917 | for (cur = plugin->ppc_dll_head; NULL != cur; cur = next) | 3931 | for (cur = plugin->ppc_dll_head; NULL != cur; cur = next) |
3918 | { | 3932 | { |
3919 | next = cur->next; | 3933 | next = cur->next; |
3920 | GNUNET_CONTAINER_DLL_remove(plugin->ppc_dll_head, | 3934 | GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, |
3921 | plugin->ppc_dll_tail, | 3935 | plugin->ppc_dll_tail, |
3922 | cur); | 3936 | cur); |
3923 | GNUNET_RESOLVER_request_cancel(cur->resolver_handle); | 3937 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
3924 | cur->asc(cur->asc_cls, NULL, GNUNET_OK); | 3938 | cur->asc (cur->asc_cls, NULL, GNUNET_OK); |
3925 | GNUNET_free(cur); | 3939 | GNUNET_free (cur); |
3926 | } | 3940 | } |
3927 | 3941 | ||
3928 | if (NULL != plugin->service) | 3942 | if (NULL != plugin->service) |
3929 | LEGACY_SERVICE_stop(plugin->service); | 3943 | LEGACY_SERVICE_stop (plugin->service); |
3930 | else | 3944 | else |
3931 | GNUNET_SERVER_destroy(plugin->server); | 3945 | GNUNET_SERVER_destroy (plugin->server); |
3932 | GNUNET_free(plugin->handlers); | 3946 | GNUNET_free (plugin->handlers); |
3933 | if (NULL != plugin->nat) | 3947 | if (NULL != plugin->nat) |
3934 | GNUNET_NAT_unregister(plugin->nat); | 3948 | GNUNET_NAT_unregister (plugin->nat); |
3935 | while (NULL != (tcp_probe = plugin->probe_head)) | 3949 | while (NULL != (tcp_probe = plugin->probe_head)) |
3936 | { | 3950 | { |
3937 | GNUNET_CONTAINER_DLL_remove(plugin->probe_head, | 3951 | GNUNET_CONTAINER_DLL_remove (plugin->probe_head, |
3938 | plugin->probe_tail, | 3952 | plugin->probe_tail, |
3939 | tcp_probe); | 3953 | tcp_probe); |
3940 | GNUNET_CONNECTION_destroy(tcp_probe->sock); | 3954 | GNUNET_CONNECTION_destroy (tcp_probe->sock); |
3941 | GNUNET_free(tcp_probe); | 3955 | GNUNET_free (tcp_probe); |
3942 | } | 3956 | } |
3943 | GNUNET_CONTAINER_multipeermap_destroy(plugin->nat_wait_conns); | 3957 | GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns); |
3944 | GNUNET_CONTAINER_multipeermap_destroy(plugin->sessionmap); | 3958 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); |
3945 | GNUNET_break(0 == plugin->cur_connections); | 3959 | GNUNET_break (0 == plugin->cur_connections); |
3946 | GNUNET_free(plugin); | 3960 | GNUNET_free (plugin); |
3947 | GNUNET_free(api); | 3961 | GNUNET_free (api); |
3948 | return NULL; | 3962 | return NULL; |
3949 | } | 3963 | } |
3950 | 3964 | ||