diff options
author | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
commit | 6e599264ad13e8fc105493d74d7c11d46f8739ed (patch) | |
tree | 169bef1ecbade5a659831fb169f3ae6943af127f /src/transport/plugin_transport_tcp.c | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 1281 |
1 files changed, 565 insertions, 716 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index a0dd80617..0ea0bf460 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 | ||
@@ -86,7 +86,6 @@ void | |||
86 | LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv); | 86 | LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv); |
87 | 87 | ||
88 | 88 | ||
89 | |||
90 | /** | 89 | /** |
91 | * Function called to notify a client about the connection begin ready | 90 | * Function called to notify a client about the connection begin ready |
92 | * to queue more data. @a buf will be NULL and @a size zero if the | 91 | * to queue more data. @a buf will be NULL and @a size zero if the |
@@ -97,10 +96,9 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *srv); | |||
97 | * @param buf where the callee should write the message | 96 | * @param buf where the callee should write the message |
98 | * @return number of bytes written to @a buf | 97 | * @return number of bytes written to @a buf |
99 | */ | 98 | */ |
100 | typedef size_t | 99 | typedef size_t (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, |
101 | (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, | 100 | size_t size, |
102 | size_t size, | 101 | void *buf); |
103 | void *buf); | ||
104 | 102 | ||
105 | /** | 103 | /** |
106 | * Credentials for UNIX domain sockets. | 104 | * Credentials for UNIX domain sockets. |
@@ -127,9 +125,9 @@ struct GNUNET_CONNECTION_Credentials | |||
127 | * @param client identification of the client; NULL | 125 | * @param client identification of the client; NULL |
128 | * for the last call when the server is destroyed | 126 | * for the last call when the server is destroyed |
129 | */ | 127 | */ |
130 | typedef void | 128 | typedef void (*GNUNET_SERVER_DisconnectCallback) ( |
131 | (*GNUNET_SERVER_DisconnectCallback) (void *cls, | 129 | void *cls, |
132 | struct GNUNET_SERVER_Client *client); | 130 | struct GNUNET_SERVER_Client *client); |
133 | 131 | ||
134 | 132 | ||
135 | /** | 133 | /** |
@@ -139,11 +137,9 @@ typedef void | |||
139 | * @param cls closure | 137 | * @param cls closure |
140 | * @param client identification of the client | 138 | * @param client identification of the client |
141 | */ | 139 | */ |
142 | typedef void | 140 | typedef void (*GNUNET_SERVER_ConnectCallback) ( |
143 | (*GNUNET_SERVER_ConnectCallback) (void *cls, | 141 | void *cls, |
144 | struct GNUNET_SERVER_Client *client); | 142 | struct GNUNET_SERVER_Client *client); |
145 | |||
146 | |||
147 | 143 | ||
148 | 144 | ||
149 | /** | 145 | /** |
@@ -156,13 +152,11 @@ typedef void | |||
156 | * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR | 152 | * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR |
157 | * for unknown address family (will be denied). | 153 | * for unknown address family (will be denied). |
158 | */ | 154 | */ |
159 | typedef int | 155 | typedef int (*GNUNET_CONNECTION_AccessCheck) ( |
160 | (*GNUNET_CONNECTION_AccessCheck) (void *cls, | 156 | void *cls, |
161 | const struct | 157 | const struct GNUNET_CONNECTION_Credentials *ucred, |
162 | GNUNET_CONNECTION_Credentials * | 158 | const struct sockaddr *addr, |
163 | ucred, | 159 | socklen_t addrlen); |
164 | const struct sockaddr * addr, | ||
165 | socklen_t addrlen); | ||
166 | 160 | ||
167 | /** | 161 | /** |
168 | * Callback function for data received from the network. Note that | 162 | * Callback function for data received from the network. Note that |
@@ -176,12 +170,12 @@ typedef int | |||
176 | * @param addrlen size of addr | 170 | * @param addrlen size of addr |
177 | * @param errCode value of errno (on errors receiving) | 171 | * @param errCode value of errno (on errors receiving) |
178 | */ | 172 | */ |
179 | typedef void | 173 | typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, |
180 | (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, | 174 | const void *buf, |
181 | size_t available, | 175 | size_t available, |
182 | const struct sockaddr * addr, | 176 | const struct sockaddr *addr, |
183 | socklen_t addrlen, int errCode); | 177 | socklen_t addrlen, |
184 | 178 | int errCode); | |
185 | 179 | ||
186 | 180 | ||
187 | /** | 181 | /** |
@@ -202,9 +196,9 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); | |||
202 | * @param client handle to client the tokenzier will be used for | 196 | * @param client handle to client the tokenzier will be used for |
203 | * @return handle to custom tokenizer ('mst') | 197 | * @return handle to custom tokenizer ('mst') |
204 | */ | 198 | */ |
205 | typedef void* | 199 | typedef void *(*GNUNET_SERVER_MstCreateCallback) ( |
206 | (*GNUNET_SERVER_MstCreateCallback) (void *cls, | 200 | void *cls, |
207 | struct GNUNET_SERVER_Client *client); | 201 | struct GNUNET_SERVER_Client *client); |
208 | 202 | ||
209 | 203 | ||
210 | /** | 204 | /** |
@@ -213,9 +207,7 @@ typedef void* | |||
213 | * @param cls closure from #GNUNET_SERVER_set_callbacks | 207 | * @param cls closure from #GNUNET_SERVER_set_callbacks |
214 | * @param mst custom tokenizer handle | 208 | * @param mst custom tokenizer handle |
215 | */ | 209 | */ |
216 | typedef void | 210 | typedef void (*GNUNET_SERVER_MstDestroyCallback) (void *cls, void *mst); |
217 | (*GNUNET_SERVER_MstDestroyCallback) (void *cls, | ||
218 | void *mst); | ||
219 | 211 | ||
220 | /** | 212 | /** |
221 | * Signature of a function to receive data for a custom tokenizer. | 213 | * Signature of a function to receive data for a custom tokenizer. |
@@ -233,13 +225,14 @@ typedef void | |||
233 | * #GNUNET_NO if one_shot was set and we have another message ready | 225 | * #GNUNET_NO if one_shot was set and we have another message ready |
234 | * #GNUNET_SYSERR if the data stream is corrupt | 226 | * #GNUNET_SYSERR if the data stream is corrupt |
235 | */ | 227 | */ |
236 | typedef int | 228 | typedef int (*GNUNET_SERVER_MstReceiveCallback) ( |
237 | (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, | 229 | void *cls, |
238 | struct GNUNET_SERVER_Client *client, | 230 | void *mst, |
239 | const char *buf, | 231 | struct GNUNET_SERVER_Client *client, |
240 | size_t size, | 232 | const char *buf, |
241 | int purge, | 233 | size_t size, |
242 | int one_shot); | 234 | int purge, |
235 | int one_shot); | ||
243 | /** | 236 | /** |
244 | * Functions with this signature are called whenever a message is | 237 | * Functions with this signature are called whenever a message is |
245 | * received. | 238 | * received. |
@@ -248,10 +241,10 @@ typedef int | |||
248 | * @param client identification of the client | 241 | * @param client identification of the client |
249 | * @param message the actual message | 242 | * @param message the actual message |
250 | */ | 243 | */ |
251 | typedef void | 244 | typedef void (*GNUNET_SERVER_MessageCallback) ( |
252 | (*GNUNET_SERVER_MessageCallback) (void *cls, | 245 | void *cls, |
253 | struct GNUNET_SERVER_Client *client, | 246 | struct GNUNET_SERVER_Client *client, |
254 | const struct GNUNET_MessageHeader *message); | 247 | const struct GNUNET_MessageHeader *message); |
255 | 248 | ||
256 | /** | 249 | /** |
257 | * Message handler. Each struct specifies how to handle on particular | 250 | * Message handler. Each struct specifies how to handle on particular |
@@ -281,7 +274,6 @@ struct GNUNET_SERVER_MessageHandler | |||
281 | * if they do not have the right size. | 274 | * if they do not have the right size. |
282 | */ | 275 | */ |
283 | uint16_t expected_size; | 276 | uint16_t expected_size; |
284 | |||
285 | }; | 277 | }; |
286 | 278 | ||
287 | 279 | ||
@@ -311,7 +303,6 @@ enum LEGACY_SERVICE_Options | |||
311 | }; | 303 | }; |
312 | 304 | ||
313 | 305 | ||
314 | |||
315 | /** | 306 | /** |
316 | * Ask the server to disconnect from the given client. This is the | 307 | * Ask the server to disconnect from the given client. This is the |
317 | * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done, | 308 | * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done, |
@@ -348,10 +339,10 @@ GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, | |||
348 | * @param message the actual message | 339 | * @param message the actual message |
349 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | 340 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
350 | */ | 341 | */ |
351 | typedef int | 342 | typedef int (*GNUNET_SERVER_MessageTokenizerCallback) ( |
352 | (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, | 343 | void *cls, |
353 | void *client, | 344 | void *client, |
354 | const struct GNUNET_MessageHeader *message); | 345 | const struct GNUNET_MessageHeader *message); |
355 | 346 | ||
356 | 347 | ||
357 | /** | 348 | /** |
@@ -384,9 +375,10 @@ GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | |||
384 | int | 375 | int |
385 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | 376 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, |
386 | void *client_identity, | 377 | void *client_identity, |
387 | const char *buf, size_t size, | 378 | const char *buf, |
388 | int purge, int one_shot); | 379 | size_t size, |
389 | 380 | int purge, | |
381 | int one_shot); | ||
390 | 382 | ||
391 | 383 | ||
392 | /** | 384 | /** |
@@ -417,7 +409,7 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, | |||
417 | * @param type expected return type (i.e. 'struct Foo') | 409 | * @param type expected return type (i.e. 'struct Foo') |
418 | * @return pointer to user context of type 'type *'. | 410 | * @return pointer to user context of type 'type *'. |
419 | */ | 411 | */ |
420 | #define GNUNET_SERVER_client_get_user_context(client,type) \ | 412 | #define GNUNET_SERVER_client_get_user_context(client, type) \ |
421 | (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type)) | 413 | (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type)) |
422 | 414 | ||
423 | /** | 415 | /** |
@@ -426,11 +418,10 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, | |||
426 | * @param client client to query | 418 | * @param client client to query |
427 | * @param value pointer to user context | 419 | * @param value pointer to user context |
428 | */ | 420 | */ |
429 | #define GNUNET_SERVER_client_set_user_context(client,value) \ | 421 | #define GNUNET_SERVER_client_set_user_context(client, value) \ |
430 | GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value)) | 422 | GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value)) |
431 | 423 | ||
432 | 424 | ||
433 | |||
434 | /** | 425 | /** |
435 | * Notify us when the server has enough space to transmit | 426 | * Notify us when the server has enough space to transmit |
436 | * a message of the given size to the given client. | 427 | * a message of the given size to the given client. |
@@ -447,11 +438,12 @@ GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, | |||
447 | * NULL if we are already going to notify someone else (busy) | 438 | * NULL if we are already going to notify someone else (busy) |
448 | */ | 439 | */ |
449 | struct GNUNET_SERVER_TransmitHandle * | 440 | struct GNUNET_SERVER_TransmitHandle * |
450 | GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | 441 | GNUNET_SERVER_notify_transmit_ready ( |
451 | size_t size, | 442 | struct GNUNET_SERVER_Client *client, |
452 | struct GNUNET_TIME_Relative timeout, | 443 | size_t size, |
453 | GNUNET_CONNECTION_TransmitReadyNotify callback, | 444 | struct GNUNET_TIME_Relative timeout, |
454 | void *callback_cls); | 445 | GNUNET_CONNECTION_TransmitReadyNotify callback, |
446 | void *callback_cls); | ||
455 | 447 | ||
456 | /** | 448 | /** |
457 | * Abort transmission request. | 449 | * Abort transmission request. |
@@ -459,9 +451,8 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | |||
459 | * @param th request to abort | 451 | * @param th request to abort |
460 | */ | 452 | */ |
461 | void | 453 | void |
462 | GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th); | 454 | GNUNET_SERVER_notify_transmit_ready_cancel ( |
463 | 455 | struct GNUNET_SERVER_TransmitHandle *th); | |
464 | |||
465 | 456 | ||
466 | 457 | ||
467 | /** | 458 | /** |
@@ -495,11 +486,10 @@ GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); | |||
495 | * @param server the initialized server | 486 | * @param server the initialized server |
496 | * @param cfg configuration to use | 487 | * @param cfg configuration to use |
497 | */ | 488 | */ |
498 | typedef void | 489 | typedef void (*LEGACY_SERVICE_Main) ( |
499 | (*LEGACY_SERVICE_Main) (void *cls, | 490 | void *cls, |
500 | struct GNUNET_SERVER_Handle *server, | 491 | struct GNUNET_SERVER_Handle *server, |
501 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 492 | const struct GNUNET_CONFIGURATION_Handle *cfg); |
502 | |||
503 | 493 | ||
504 | 494 | ||
505 | /** | 495 | /** |
@@ -527,11 +517,12 @@ GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); | |||
527 | * NULL if we are already going to notify someone else (busy) | 517 | * NULL if we are already going to notify someone else (busy) |
528 | */ | 518 | */ |
529 | struct GNUNET_SERVER_TransmitHandle * | 519 | struct GNUNET_SERVER_TransmitHandle * |
530 | GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | 520 | GNUNET_SERVER_notify_transmit_ready ( |
531 | size_t size, | 521 | struct GNUNET_SERVER_Client *client, |
532 | struct GNUNET_TIME_Relative timeout, | 522 | size_t size, |
533 | GNUNET_CONNECTION_TransmitReadyNotify callback, | 523 | struct GNUNET_TIME_Relative timeout, |
534 | void *callback_cls); | 524 | GNUNET_CONNECTION_TransmitReadyNotify callback, |
525 | void *callback_cls); | ||
535 | 526 | ||
536 | 527 | ||
537 | /** | 528 | /** |
@@ -567,8 +558,6 @@ void | |||
567 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); | 558 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); |
568 | 559 | ||
569 | 560 | ||
570 | |||
571 | |||
572 | #include "tcp_connection_legacy.c" | 561 | #include "tcp_connection_legacy.c" |
573 | #include "tcp_server_mst_legacy.c" | 562 | #include "tcp_server_mst_legacy.c" |
574 | #include "tcp_server_legacy.c" | 563 | #include "tcp_server_legacy.c" |
@@ -590,7 +579,6 @@ struct WelcomeMessage | |||
590 | * Identity of the node connecting (TCP client) | 579 | * Identity of the node connecting (TCP client) |
591 | */ | 580 | */ |
592 | struct GNUNET_PeerIdentity clientIdentity; | 581 | struct GNUNET_PeerIdentity clientIdentity; |
593 | |||
594 | }; | 582 | }; |
595 | 583 | ||
596 | /** | 584 | /** |
@@ -608,7 +596,6 @@ struct TCP_NAT_ProbeMessage | |||
608 | * Identity of the sender of the message. | 596 | * Identity of the sender of the message. |
609 | */ | 597 | */ |
610 | struct GNUNET_PeerIdentity clientIdentity; | 598 | struct GNUNET_PeerIdentity clientIdentity; |
611 | |||
612 | }; | 599 | }; |
613 | GNUNET_NETWORK_STRUCT_END | 600 | GNUNET_NETWORK_STRUCT_END |
614 | 601 | ||
@@ -693,7 +680,6 @@ struct IPv4TcpAddress | |||
693 | * Port number, in network byte order. | 680 | * Port number, in network byte order. |
694 | */ | 681 | */ |
695 | uint16_t t4_port GNUNET_PACKED; | 682 | uint16_t t4_port GNUNET_PACKED; |
696 | |||
697 | }; | 683 | }; |
698 | 684 | ||
699 | /** | 685 | /** |
@@ -716,7 +702,6 @@ struct IPv6TcpAddress | |||
716 | * Port number, in network byte order. | 702 | * Port number, in network byte order. |
717 | */ | 703 | */ |
718 | uint16_t t6_port GNUNET_PACKED; | 704 | uint16_t t6_port GNUNET_PACKED; |
719 | |||
720 | }; | 705 | }; |
721 | GNUNET_NETWORK_STRUCT_END | 706 | GNUNET_NETWORK_STRUCT_END |
722 | 707 | ||
@@ -770,7 +755,6 @@ struct PendingMessage | |||
770 | * instead of just a `struct GNUNET_MessageHeader`. | 755 | * instead of just a `struct GNUNET_MessageHeader`. |
771 | */ | 756 | */ |
772 | size_t message_size; | 757 | size_t message_size; |
773 | |||
774 | }; | 758 | }; |
775 | 759 | ||
776 | /** | 760 | /** |
@@ -872,7 +856,6 @@ struct GNUNET_ATS_Session | |||
872 | * Was this session created using NAT traversal? | 856 | * Was this session created using NAT traversal? |
873 | */ | 857 | */ |
874 | int is_nat; | 858 | int is_nat; |
875 | |||
876 | }; | 859 | }; |
877 | 860 | ||
878 | 861 | ||
@@ -1045,7 +1028,6 @@ struct Plugin | |||
1045 | * rest of the world. | 1028 | * rest of the world. |
1046 | */ | 1029 | */ |
1047 | uint16_t adv_port; | 1030 | uint16_t adv_port; |
1048 | |||
1049 | }; | 1031 | }; |
1050 | 1032 | ||
1051 | 1033 | ||
@@ -1071,9 +1053,9 @@ struct Plugin | |||
1071 | */ | 1053 | */ |
1072 | static int | 1054 | static int |
1073 | get_server_addresses (const char *service_name, | 1055 | get_server_addresses (const char *service_name, |
1074 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1056 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1075 | struct sockaddr ***addrs, | 1057 | struct sockaddr ***addrs, |
1076 | socklen_t ** addr_lens) | 1058 | socklen_t **addr_lens) |
1077 | { | 1059 | { |
1078 | int disablev6; | 1060 | int disablev6; |
1079 | struct GNUNET_NETWORK_Handle *desc; | 1061 | struct GNUNET_NETWORK_Handle *desc; |
@@ -1097,8 +1079,9 @@ get_server_addresses (const char *service_name, | |||
1097 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) | 1079 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) |
1098 | { | 1080 | { |
1099 | if (GNUNET_SYSERR == | 1081 | if (GNUNET_SYSERR == |
1100 | (disablev6 = | 1082 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1101 | GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6"))) | 1083 | service_name, |
1084 | "DISABLEV6"))) | ||
1102 | return GNUNET_SYSERR; | 1085 | return GNUNET_SYSERR; |
1103 | } | 1086 | } |
1104 | else | 1087 | else |
@@ -1117,8 +1100,10 @@ get_server_addresses (const char *service_name, | |||
1117 | return GNUNET_SYSERR; | 1100 | return GNUNET_SYSERR; |
1118 | } | 1101 | } |
1119 | LOG (GNUNET_ERROR_TYPE_INFO, | 1102 | LOG (GNUNET_ERROR_TYPE_INFO, |
1120 | _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | 1103 | _ ( |
1121 | service_name, STRERROR (errno)); | 1104 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), |
1105 | service_name, | ||
1106 | strerror (errno)); | ||
1122 | disablev6 = GNUNET_YES; | 1107 | disablev6 = GNUNET_YES; |
1123 | } | 1108 | } |
1124 | else | 1109 | else |
@@ -1131,18 +1116,19 @@ get_server_addresses (const char *service_name, | |||
1131 | port = 0; | 1116 | port = 0; |
1132 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) | 1117 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) |
1133 | { | 1118 | { |
1134 | if (GNUNET_OK != | 1119 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
1135 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, | 1120 | service_name, |
1136 | "PORT", &port)) | 1121 | "PORT", |
1122 | &port)) | ||
1137 | { | 1123 | { |
1138 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1124 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1139 | _("Require valid port number for service `%s' in configuration!\n"), | 1125 | _ ("Require valid port number for service `%s' in configuration!\n"), |
1140 | service_name); | 1126 | service_name); |
1141 | } | 1127 | } |
1142 | if (port > 65535) | 1128 | if (port > 65535) |
1143 | { | 1129 | { |
1144 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1130 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1145 | _("Require valid port number for service `%s' in configuration!\n"), | 1131 | _ ("Require valid port number for service `%s' in configuration!\n"), |
1146 | service_name); | 1132 | service_name); |
1147 | return GNUNET_SYSERR; | 1133 | return GNUNET_SYSERR; |
1148 | } | 1134 | } |
@@ -1151,8 +1137,10 @@ get_server_addresses (const char *service_name, | |||
1151 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) | 1137 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) |
1152 | { | 1138 | { |
1153 | GNUNET_break (GNUNET_OK == | 1139 | GNUNET_break (GNUNET_OK == |
1154 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, | 1140 | GNUNET_CONFIGURATION_get_value_string (cfg, |
1155 | "BINDTO", &hostname)); | 1141 | service_name, |
1142 | "BINDTO", | ||
1143 | &hostname)); | ||
1156 | } | 1144 | } |
1157 | else | 1145 | else |
1158 | hostname = NULL; | 1146 | hostname = NULL; |
@@ -1162,9 +1150,10 @@ get_server_addresses (const char *service_name, | |||
1162 | #ifdef AF_UNIX | 1150 | #ifdef AF_UNIX |
1163 | if ((GNUNET_YES == | 1151 | if ((GNUNET_YES == |
1164 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && | 1152 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && |
1165 | (GNUNET_OK == | 1153 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, |
1166 | GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", | 1154 | service_name, |
1167 | &unixpath)) && | 1155 | "UNIXPATH", |
1156 | &unixpath)) && | ||
1168 | (0 < strlen (unixpath))) | 1157 | (0 < strlen (unixpath))) |
1169 | { | 1158 | { |
1170 | /* probe UNIX support */ | 1159 | /* probe UNIX support */ |
@@ -1173,12 +1162,11 @@ get_server_addresses (const char *service_name, | |||
1173 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) | 1162 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) |
1174 | { | 1163 | { |
1175 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1164 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1176 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, | 1165 | _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), |
1166 | unixpath, | ||
1177 | (unsigned long long) sizeof (s_un.sun_path)); | 1167 | (unsigned long long) sizeof (s_un.sun_path)); |
1178 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); | 1168 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); |
1179 | LOG (GNUNET_ERROR_TYPE_INFO, | 1169 | LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); |
1180 | _("Using `%s' instead\n"), | ||
1181 | unixpath); | ||
1182 | } | 1170 | } |
1183 | #ifdef LINUX | 1171 | #ifdef LINUX |
1184 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1172 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
@@ -1187,12 +1175,9 @@ get_server_addresses (const char *service_name, | |||
1187 | if (GNUNET_SYSERR == abstract) | 1175 | if (GNUNET_SYSERR == abstract) |
1188 | abstract = GNUNET_NO; | 1176 | abstract = GNUNET_NO; |
1189 | #endif | 1177 | #endif |
1190 | if ((GNUNET_YES != abstract) | 1178 | if ((GNUNET_YES != abstract) && |
1191 | && (GNUNET_OK != | 1179 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) |
1192 | GNUNET_DISK_directory_create_for_file (unixpath))) | 1180 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); |
1193 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
1194 | "mkdir", | ||
1195 | unixpath); | ||
1196 | } | 1181 | } |
1197 | if (NULL != unixpath) | 1182 | if (NULL != unixpath) |
1198 | { | 1183 | { |
@@ -1208,9 +1193,10 @@ get_server_addresses (const char *service_name, | |||
1208 | return GNUNET_SYSERR; | 1193 | return GNUNET_SYSERR; |
1209 | } | 1194 | } |
1210 | LOG (GNUNET_ERROR_TYPE_INFO, | 1195 | LOG (GNUNET_ERROR_TYPE_INFO, |
1211 | _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | 1196 | _ ( |
1197 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
1212 | service_name, | 1198 | service_name, |
1213 | STRERROR (errno)); | 1199 | strerror (errno)); |
1214 | GNUNET_free (unixpath); | 1200 | GNUNET_free (unixpath); |
1215 | unixpath = NULL; | 1201 | unixpath = NULL; |
1216 | } | 1202 | } |
@@ -1225,7 +1211,8 @@ get_server_addresses (const char *service_name, | |||
1225 | if ((0 == port) && (NULL == unixpath)) | 1211 | if ((0 == port) && (NULL == unixpath)) |
1226 | { | 1212 | { |
1227 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1213 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1228 | _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | 1214 | _ ( |
1215 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | ||
1229 | service_name); | 1216 | service_name); |
1230 | GNUNET_free_non_null (hostname); | 1217 | GNUNET_free_non_null (hostname); |
1231 | return GNUNET_SYSERR; | 1218 | return GNUNET_SYSERR; |
@@ -1256,7 +1243,7 @@ get_server_addresses (const char *service_name, | |||
1256 | (NULL == res)) | 1243 | (NULL == res)) |
1257 | { | 1244 | { |
1258 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1245 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1259 | _("Failed to resolve `%s': %s\n"), | 1246 | _ ("Failed to resolve `%s': %s\n"), |
1260 | hostname, | 1247 | hostname, |
1261 | gai_strerror (ret)); | 1248 | gai_strerror (ret)); |
1262 | GNUNET_free (hostname); | 1249 | GNUNET_free (hostname); |
@@ -1275,7 +1262,7 @@ get_server_addresses (const char *service_name, | |||
1275 | if (0 == i) | 1262 | if (0 == i) |
1276 | { | 1263 | { |
1277 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1264 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1278 | _("Failed to find %saddress for `%s'.\n"), | 1265 | _ ("Failed to find %saddress for `%s'.\n"), |
1279 | disablev6 ? "IPv4 " : "", | 1266 | disablev6 ? "IPv4 " : "", |
1280 | hostname); | 1267 | hostname); |
1281 | freeaddrinfo (res); | 1268 | freeaddrinfo (res); |
@@ -1301,11 +1288,13 @@ get_server_addresses (const char *service_name, | |||
1301 | if ((disablev6) && (AF_INET6 == pos->ai_family)) | 1288 | if ((disablev6) && (AF_INET6 == pos->ai_family)) |
1302 | continue; | 1289 | continue; |
1303 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) | 1290 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) |
1304 | continue; /* not TCP */ | 1291 | continue; /* not TCP */ |
1305 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | 1292 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) |
1306 | continue; /* huh? */ | 1293 | continue; /* huh? */ |
1307 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", | 1294 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1308 | service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | 1295 | "Service `%s' will bind to `%s'\n", |
1296 | service_name, | ||
1297 | GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | ||
1309 | if (AF_INET == pos->ai_family) | 1298 | if (AF_INET == pos->ai_family) |
1310 | { | 1299 | { |
1311 | GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); | 1300 | GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); |
@@ -1412,17 +1401,16 @@ notify_session_monitor (struct Plugin *plugin, | |||
1412 | return; | 1401 | return; |
1413 | memset (&info, 0, sizeof (info)); | 1402 | memset (&info, 0, sizeof (info)); |
1414 | info.state = state; | 1403 | info.state = state; |
1415 | info.is_inbound = GNUNET_HELLO_address_check_option (session->address, | 1404 | info.is_inbound = |
1416 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 1405 | GNUNET_HELLO_address_check_option (session->address, |
1406 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
1417 | info.num_msg_pending = session->msgs_in_queue; | 1407 | info.num_msg_pending = session->msgs_in_queue; |
1418 | info.num_bytes_pending = session->bytes_in_queue; | 1408 | info.num_bytes_pending = session->bytes_in_queue; |
1419 | if (NULL != session->receive_delay_task) | 1409 | if (NULL != session->receive_delay_task) |
1420 | info.receive_delay = session->receive_delay; | 1410 | info.receive_delay = session->receive_delay; |
1421 | info.session_timeout = session->timeout; | 1411 | info.session_timeout = session->timeout; |
1422 | info.address = session->address; | 1412 | info.address = session->address; |
1423 | plugin->sic (plugin->sic_cls, | 1413 | plugin->sic (plugin->sic_cls, session, &info); |
1424 | session, | ||
1425 | &info); | ||
1426 | } | 1414 | } |
1427 | 1415 | ||
1428 | 1416 | ||
@@ -1440,10 +1428,10 @@ notify_session_monitor (struct Plugin *plugin, | |||
1440 | */ | 1428 | */ |
1441 | static void | 1429 | static void |
1442 | tcp_nat_port_map_callback (void *cls, | 1430 | tcp_nat_port_map_callback (void *cls, |
1443 | void **app_ctx, | 1431 | void **app_ctx, |
1444 | int add_remove, | 1432 | int add_remove, |
1445 | enum GNUNET_NAT_AddressClass ac, | 1433 | enum GNUNET_NAT_AddressClass ac, |
1446 | const struct sockaddr *addr, | 1434 | const struct sockaddr *addr, |
1447 | socklen_t addrlen) | 1435 | socklen_t addrlen) |
1448 | { | 1436 | { |
1449 | struct Plugin *plugin = cls; | 1437 | struct Plugin *plugin = cls; |
@@ -1462,8 +1450,8 @@ tcp_nat_port_map_callback (void *cls, | |||
1462 | switch (addr->sa_family) | 1450 | switch (addr->sa_family) |
1463 | { | 1451 | { |
1464 | case AF_INET: | 1452 | case AF_INET: |
1465 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in)); | 1453 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); |
1466 | memset (&t4, 0, sizeof(t4)); | 1454 | memset (&t4, 0, sizeof (t4)); |
1467 | t4.options = htonl (plugin->myoptions); | 1455 | t4.options = htonl (plugin->myoptions); |
1468 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 1456 | t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
1469 | t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; | 1457 | t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; |
@@ -1477,32 +1465,30 @@ tcp_nat_port_map_callback (void *cls, | |||
1477 | #tcp_plugin_check_address() */ | 1465 | #tcp_plugin_check_address() */ |
1478 | return; | 1466 | return; |
1479 | } | 1467 | } |
1480 | GNUNET_assert(addrlen == sizeof(struct sockaddr_in6)); | 1468 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
1481 | memset (&t6, 0, sizeof(t6)); | 1469 | memset (&t6, 0, sizeof (t6)); |
1482 | GNUNET_memcpy (&t6.ipv6_addr, | 1470 | GNUNET_memcpy (&t6.ipv6_addr, |
1483 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 1471 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
1484 | sizeof(struct in6_addr)); | 1472 | sizeof (struct in6_addr)); |
1485 | t6.options = htonl (plugin->myoptions); | 1473 | t6.options = htonl (plugin->myoptions); |
1486 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; | 1474 | t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; |
1487 | arg = &t6; | 1475 | arg = &t6; |
1488 | args = sizeof (t6); | 1476 | args = sizeof (t6); |
1489 | break; | 1477 | break; |
1490 | default: | 1478 | default: |
1491 | GNUNET_break(0); | 1479 | GNUNET_break (0); |
1492 | return; | 1480 | return; |
1493 | } | 1481 | } |
1494 | /* modify our published address list */ | 1482 | /* modify our published address list */ |
1495 | GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) || | 1483 | GNUNET_assert ((args == sizeof (struct IPv4TcpAddress)) || |
1496 | (args == sizeof (struct IPv6TcpAddress))); | 1484 | (args == sizeof (struct IPv6TcpAddress))); |
1497 | /* TODO: use 'ac' here in the future... */ | 1485 | /* TODO: use 'ac' here in the future... */ |
1498 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1486 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1499 | PLUGIN_NAME, | 1487 | PLUGIN_NAME, |
1500 | arg, | 1488 | arg, |
1501 | args, | 1489 | args, |
1502 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1490 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1503 | plugin->env->notify_address (plugin->env->cls, | 1491 | plugin->env->notify_address (plugin->env->cls, add_remove, address); |
1504 | add_remove, | ||
1505 | address); | ||
1506 | GNUNET_HELLO_address_free (address); | 1492 | GNUNET_HELLO_address_free (address); |
1507 | } | 1493 | } |
1508 | 1494 | ||
@@ -1519,9 +1505,7 @@ tcp_nat_port_map_callback (void *cls, | |||
1519 | * @return string representing the same address | 1505 | * @return string representing the same address |
1520 | */ | 1506 | */ |
1521 | static const char * | 1507 | static const char * |
1522 | tcp_plugin_address_to_string (void *cls, | 1508 | tcp_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
1523 | const void *addr, | ||
1524 | size_t addrlen) | ||
1525 | { | 1509 | { |
1526 | static char rbuf[INET6_ADDRSTRLEN + 12]; | 1510 | static char rbuf[INET6_ADDRSTRLEN + 12]; |
1527 | char buf[INET6_ADDRSTRLEN]; | 1511 | char buf[INET6_ADDRSTRLEN]; |
@@ -1536,35 +1520,35 @@ tcp_plugin_address_to_string (void *cls, | |||
1536 | 1520 | ||
1537 | switch (addrlen) | 1521 | switch (addrlen) |
1538 | { | 1522 | { |
1539 | case sizeof(struct IPv6TcpAddress): | 1523 | case sizeof (struct IPv6TcpAddress): |
1540 | t6 = addr; | 1524 | t6 = addr; |
1541 | af = AF_INET6; | 1525 | af = AF_INET6; |
1542 | port = ntohs (t6->t6_port); | 1526 | port = ntohs (t6->t6_port); |
1543 | options = ntohl (t6->options); | 1527 | options = ntohl (t6->options); |
1544 | GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof(a6)); | 1528 | GNUNET_memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); |
1545 | sb = &a6; | 1529 | sb = &a6; |
1546 | break; | 1530 | break; |
1547 | case sizeof(struct IPv4TcpAddress): | 1531 | case sizeof (struct IPv4TcpAddress): |
1548 | t4 = addr; | 1532 | t4 = addr; |
1549 | af = AF_INET; | 1533 | af = AF_INET; |
1550 | port = ntohs (t4->t4_port); | 1534 | port = ntohs (t4->t4_port); |
1551 | options = ntohl (t4->options); | 1535 | options = ntohl (t4->options); |
1552 | GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof(a4)); | 1536 | GNUNET_memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); |
1553 | sb = &a4; | 1537 | sb = &a4; |
1554 | break; | 1538 | break; |
1555 | default: | 1539 | default: |
1556 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1540 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1557 | _("Unexpected address length: %u bytes\n"), | 1541 | _ ("Unexpected address length: %u bytes\n"), |
1558 | (unsigned int) addrlen); | 1542 | (unsigned int) addrlen); |
1559 | return NULL ; | 1543 | return NULL; |
1560 | } | 1544 | } |
1561 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) | 1545 | if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) |
1562 | { | 1546 | { |
1563 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1547 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); |
1564 | "inet_ntop"); | 1548 | return NULL; |
1565 | return NULL ; | ||
1566 | } | 1549 | } |
1567 | GNUNET_snprintf (rbuf, sizeof(rbuf), | 1550 | GNUNET_snprintf (rbuf, |
1551 | sizeof (rbuf), | ||
1568 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", | 1552 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", |
1569 | PLUGIN_NAME, | 1553 | PLUGIN_NAME, |
1570 | options, | 1554 | options, |
@@ -1605,25 +1589,25 @@ tcp_plugin_string_to_address (void *cls, | |||
1605 | optionstr = NULL; | 1589 | optionstr = NULL; |
1606 | if ((NULL == addr) || (0 == addrlen)) | 1590 | if ((NULL == addr) || (0 == addrlen)) |
1607 | { | 1591 | { |
1608 | GNUNET_break(0); | 1592 | GNUNET_break (0); |
1609 | return GNUNET_SYSERR; | 1593 | return GNUNET_SYSERR; |
1610 | } | 1594 | } |
1611 | if ('\0' != addr[addrlen - 1]) | 1595 | if ('\0' != addr[addrlen - 1]) |
1612 | { | 1596 | { |
1613 | GNUNET_break(0); | 1597 | GNUNET_break (0); |
1614 | return GNUNET_SYSERR; | 1598 | return GNUNET_SYSERR; |
1615 | } | 1599 | } |
1616 | if (strlen (addr) != addrlen - 1) | 1600 | if (strlen (addr) != addrlen - 1) |
1617 | { | 1601 | { |
1618 | GNUNET_break(0); | 1602 | GNUNET_break (0); |
1619 | return GNUNET_SYSERR; | 1603 | return GNUNET_SYSERR; |
1620 | } | 1604 | } |
1621 | plugin = GNUNET_strdup (addr); | 1605 | plugin = GNUNET_strdup (addr); |
1622 | optionstr = strchr (plugin, '.'); | 1606 | optionstr = strchr (plugin, '.'); |
1623 | if (NULL == optionstr) | 1607 | if (NULL == optionstr) |
1624 | { | 1608 | { |
1625 | GNUNET_break(0); | 1609 | GNUNET_break (0); |
1626 | GNUNET_free(plugin); | 1610 | GNUNET_free (plugin); |
1627 | return GNUNET_SYSERR; | 1611 | return GNUNET_SYSERR; |
1628 | } | 1612 | } |
1629 | optionstr[0] = '\0'; | 1613 | optionstr[0] = '\0'; |
@@ -1632,28 +1616,25 @@ tcp_plugin_string_to_address (void *cls, | |||
1632 | address = strchr (optionstr, '.'); | 1616 | address = strchr (optionstr, '.'); |
1633 | if (NULL == address) | 1617 | if (NULL == address) |
1634 | { | 1618 | { |
1635 | GNUNET_break(0); | 1619 | GNUNET_break (0); |
1636 | GNUNET_free(plugin); | 1620 | GNUNET_free (plugin); |
1637 | return GNUNET_SYSERR; | 1621 | return GNUNET_SYSERR; |
1638 | } | 1622 | } |
1639 | address[0] = '\0'; | 1623 | address[0] = '\0'; |
1640 | address++; | 1624 | address++; |
1641 | 1625 | ||
1642 | if (GNUNET_OK != | 1626 | if (GNUNET_OK != |
1643 | GNUNET_STRINGS_to_address_ip (address, | 1627 | GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) |
1644 | strlen (address), | ||
1645 | &socket_address)) | ||
1646 | { | 1628 | { |
1647 | GNUNET_break(0); | 1629 | GNUNET_break (0); |
1648 | GNUNET_free(plugin); | 1630 | GNUNET_free (plugin); |
1649 | return GNUNET_SYSERR; | 1631 | return GNUNET_SYSERR; |
1650 | } | 1632 | } |
1651 | 1633 | ||
1652 | GNUNET_free(plugin); | 1634 | GNUNET_free (plugin); |
1653 | switch (socket_address.ss_family) | 1635 | switch (socket_address.ss_family) |
1654 | { | 1636 | { |
1655 | case AF_INET: | 1637 | case AF_INET: { |
1656 | { | ||
1657 | struct IPv4TcpAddress *t4; | 1638 | struct IPv4TcpAddress *t4; |
1658 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; | 1639 | struct sockaddr_in *in4 = (struct sockaddr_in *) &socket_address; |
1659 | t4 = GNUNET_new (struct IPv4TcpAddress); | 1640 | t4 = GNUNET_new (struct IPv4TcpAddress); |
@@ -1661,11 +1642,10 @@ tcp_plugin_string_to_address (void *cls, | |||
1661 | t4->ipv4_addr = in4->sin_addr.s_addr; | 1642 | t4->ipv4_addr = in4->sin_addr.s_addr; |
1662 | t4->t4_port = in4->sin_port; | 1643 | t4->t4_port = in4->sin_port; |
1663 | *buf = t4; | 1644 | *buf = t4; |
1664 | *added = sizeof(struct IPv4TcpAddress); | 1645 | *added = sizeof (struct IPv4TcpAddress); |
1665 | return GNUNET_OK; | 1646 | return GNUNET_OK; |
1666 | } | 1647 | } |
1667 | case AF_INET6: | 1648 | case AF_INET6: { |
1668 | { | ||
1669 | struct IPv6TcpAddress *t6; | 1649 | struct IPv6TcpAddress *t6; |
1670 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; | 1650 | struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) &socket_address; |
1671 | t6 = GNUNET_new (struct IPv6TcpAddress); | 1651 | t6 = GNUNET_new (struct IPv6TcpAddress); |
@@ -1673,7 +1653,7 @@ tcp_plugin_string_to_address (void *cls, | |||
1673 | t6->ipv6_addr = in6->sin6_addr; | 1653 | t6->ipv6_addr = in6->sin6_addr; |
1674 | t6->t6_port = in6->sin6_port; | 1654 | t6->t6_port = in6->sin6_port; |
1675 | *buf = t6; | 1655 | *buf = t6; |
1676 | *added = sizeof(struct IPv6TcpAddress); | 1656 | *added = sizeof (struct IPv6TcpAddress); |
1677 | return GNUNET_OK; | 1657 | return GNUNET_OK; |
1678 | } | 1658 | } |
1679 | default: | 1659 | default: |
@@ -1711,8 +1691,7 @@ lookup_session_by_client (struct Plugin *plugin, | |||
1711 | * @return #GNUNET_OK on success | 1691 | * @return #GNUNET_OK on success |
1712 | */ | 1692 | */ |
1713 | static int | 1693 | static int |
1714 | tcp_plugin_disconnect_session (void *cls, | 1694 | tcp_plugin_disconnect_session (void *cls, struct GNUNET_ATS_Session *session) |
1715 | struct GNUNET_ATS_Session *session) | ||
1716 | { | 1695 | { |
1717 | struct Plugin *plugin = cls; | 1696 | struct Plugin *plugin = cls; |
1718 | struct PendingMessage *pm; | 1697 | struct PendingMessage *pm; |
@@ -1731,26 +1710,24 @@ tcp_plugin_disconnect_session (void *cls, | |||
1731 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 1710 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
1732 | } | 1711 | } |
1733 | 1712 | ||
1734 | if (GNUNET_YES == | 1713 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, |
1735 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessionmap, | 1714 | &session->target, |
1736 | &session->target, | 1715 | session)) |
1737 | session)) | ||
1738 | { | 1716 | { |
1739 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1717 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1740 | gettext_noop ("# TCP sessions active"), | 1718 | gettext_noop ("# TCP sessions active"), |
1741 | -1, | 1719 | -1, |
1742 | GNUNET_NO); | 1720 | GNUNET_NO); |
1743 | } | 1721 | } |
1744 | else | 1722 | else |
1745 | { | 1723 | { |
1746 | GNUNET_assert (GNUNET_YES == | 1724 | GNUNET_assert (GNUNET_YES == |
1747 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, | 1725 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, |
1748 | &session->target, | 1726 | &session->target, |
1749 | session)); | 1727 | session)); |
1750 | } | 1728 | } |
1751 | if (NULL != session->client) | 1729 | if (NULL != session->client) |
1752 | GNUNET_SERVER_client_set_user_context (session->client, | 1730 | GNUNET_SERVER_client_set_user_context (session->client, NULL); |
1753 | NULL); | ||
1754 | 1731 | ||
1755 | /* clean up state */ | 1732 | /* clean up state */ |
1756 | if (NULL != session->transmit_handle) | 1733 | if (NULL != session->transmit_handle) |
@@ -1772,17 +1749,19 @@ tcp_plugin_disconnect_session (void *cls, | |||
1772 | { | 1749 | { |
1773 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1750 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1774 | (NULL != pm->transmit_cont) | 1751 | (NULL != pm->transmit_cont) |
1775 | ? "Could not deliver message to `%s' at %s.\n" | 1752 | ? "Could not deliver message to `%s' at %s.\n" |
1776 | : "Could not deliver message to `%s' at %s, notifying.\n", | 1753 | : "Could not deliver message to `%s' at %s, notifying.\n", |
1777 | GNUNET_i2s (&session->target), | 1754 | GNUNET_i2s (&session->target), |
1778 | tcp_plugin_address_to_string (session->plugin, | 1755 | tcp_plugin_address_to_string (session->plugin, |
1779 | session->address->address, | 1756 | session->address->address, |
1780 | session->address->address_length)); | 1757 | session->address->address_length)); |
1781 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1758 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1782 | gettext_noop ("# bytes currently in TCP buffers"), | 1759 | gettext_noop ("# bytes currently in TCP buffers"), |
1783 | -(int64_t) pm->message_size, GNUNET_NO); | 1760 | -(int64_t) pm->message_size, |
1761 | GNUNET_NO); | ||
1784 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 1762 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
1785 | gettext_noop ("# bytes discarded by TCP (disconnect)"), | 1763 | gettext_noop ( |
1764 | "# bytes discarded by TCP (disconnect)"), | ||
1786 | pm->message_size, | 1765 | pm->message_size, |
1787 | GNUNET_NO); | 1766 | GNUNET_NO); |
1788 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 1767 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
@@ -1802,9 +1781,7 @@ tcp_plugin_disconnect_session (void *cls, | |||
1802 | } | 1781 | } |
1803 | GNUNET_assert (0 == session->msgs_in_queue); | 1782 | GNUNET_assert (0 == session->msgs_in_queue); |
1804 | GNUNET_assert (0 == session->bytes_in_queue); | 1783 | GNUNET_assert (0 == session->bytes_in_queue); |
1805 | notify_session_monitor (session->plugin, | 1784 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_DONE); |
1806 | session, | ||
1807 | GNUNET_TRANSPORT_SS_DONE); | ||
1808 | 1785 | ||
1809 | if (NULL != session->receive_delay_task) | 1786 | if (NULL != session->receive_delay_task) |
1810 | { | 1787 | { |
@@ -1855,22 +1832,18 @@ session_timeout (void *cls) | |||
1855 | { | 1832 | { |
1856 | /* not actually our turn yet, but let's at least update | 1833 | /* not actually our turn yet, but let's at least update |
1857 | the monitor, it may think we're about to die ... */ | 1834 | the monitor, it may think we're about to die ... */ |
1858 | notify_session_monitor (s->plugin, | 1835 | notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); |
1859 | s, | 1836 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); |
1860 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1861 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, | ||
1862 | &session_timeout, | ||
1863 | s); | ||
1864 | return; | 1837 | return; |
1865 | } | 1838 | } |
1866 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1839 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1867 | "Session %p was idle for %s, disconnecting\n", | 1840 | "Session %p was idle for %s, disconnecting\n", |
1868 | s, | 1841 | s, |
1869 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1842 | GNUNET_STRINGS_relative_time_to_string ( |
1870 | GNUNET_YES)); | 1843 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1844 | GNUNET_YES)); | ||
1871 | /* call session destroy function */ | 1845 | /* call session destroy function */ |
1872 | tcp_plugin_disconnect_session (s->plugin, | 1846 | tcp_plugin_disconnect_session (s->plugin, s); |
1873 | s); | ||
1874 | } | 1847 | } |
1875 | 1848 | ||
1876 | 1849 | ||
@@ -1883,7 +1856,8 @@ static void | |||
1883 | reschedule_session_timeout (struct GNUNET_ATS_Session *s) | 1856 | reschedule_session_timeout (struct GNUNET_ATS_Session *s) |
1884 | { | 1857 | { |
1885 | GNUNET_assert (NULL != s->timeout_task); | 1858 | GNUNET_assert (NULL != s->timeout_task); |
1886 | s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1859 | s->timeout = |
1860 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
1887 | } | 1861 | } |
1888 | 1862 | ||
1889 | 1863 | ||
@@ -1927,46 +1901,41 @@ create_session (struct Plugin *plugin, | |||
1927 | if (NULL != client) | 1901 | if (NULL != client) |
1928 | { | 1902 | { |
1929 | session->client = client; | 1903 | session->client = client; |
1930 | GNUNET_SERVER_client_set_user_context (client, | 1904 | GNUNET_SERVER_client_set_user_context (client, session); |
1931 | session); | ||
1932 | } | 1905 | } |
1933 | session->address = GNUNET_HELLO_address_copy (address); | 1906 | session->address = GNUNET_HELLO_address_copy (address); |
1934 | session->target = address->peer; | 1907 | session->target = address->peer; |
1935 | session->expecting_welcome = GNUNET_YES; | 1908 | session->expecting_welcome = GNUNET_YES; |
1936 | session->scope = scope; | 1909 | session->scope = scope; |
1937 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + | 1910 | pm = GNUNET_malloc (sizeof (struct PendingMessage) + |
1938 | sizeof (struct WelcomeMessage)); | 1911 | sizeof (struct WelcomeMessage)); |
1939 | pm->msg = (const char *) &pm[1]; | 1912 | pm->msg = (const char *) &pm[1]; |
1940 | pm->message_size = sizeof(struct WelcomeMessage); | 1913 | pm->message_size = sizeof (struct WelcomeMessage); |
1941 | GNUNET_memcpy (&pm[1], | 1914 | GNUNET_memcpy (&pm[1], &plugin->my_welcome, sizeof (struct WelcomeMessage)); |
1942 | &plugin->my_welcome, | ||
1943 | sizeof(struct WelcomeMessage)); | ||
1944 | pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; | 1915 | pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; |
1945 | GNUNET_STATISTICS_update (plugin->env->stats, | 1916 | GNUNET_STATISTICS_update (plugin->env->stats, |
1946 | gettext_noop ("# bytes currently in TCP buffers"), | 1917 | gettext_noop ("# bytes currently in TCP buffers"), |
1947 | pm->message_size, | 1918 | pm->message_size, |
1948 | GNUNET_NO); | 1919 | GNUNET_NO); |
1949 | GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, | 1920 | GNUNET_CONTAINER_DLL_insert (session->pending_messages_head, |
1950 | session->pending_messages_tail, | 1921 | session->pending_messages_tail, |
1951 | pm); | 1922 | pm); |
1952 | session->msgs_in_queue++; | 1923 | session->msgs_in_queue++; |
1953 | session->bytes_in_queue += pm->message_size; | 1924 | session->bytes_in_queue += pm->message_size; |
1954 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 1925 | session->timeout = |
1955 | session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 1926 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
1956 | &session_timeout, | 1927 | session->timeout_task = |
1957 | session); | 1928 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
1958 | notify_session_monitor (session->plugin, | 1929 | &session_timeout, |
1959 | session, | 1930 | session); |
1960 | GNUNET_TRANSPORT_SS_INIT); | 1931 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_INIT); |
1961 | if (GNUNET_YES != is_nat) | 1932 | if (GNUNET_YES != is_nat) |
1962 | { | 1933 | { |
1963 | GNUNET_STATISTICS_update (plugin->env->stats, | 1934 | GNUNET_STATISTICS_update (plugin->env->stats, |
1964 | gettext_noop ("# TCP sessions active"), | 1935 | gettext_noop ("# TCP sessions active"), |
1965 | 1, | 1936 | 1, |
1966 | GNUNET_NO); | 1937 | GNUNET_NO); |
1967 | notify_session_monitor (session->plugin, | 1938 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UP); |
1968 | session, | ||
1969 | GNUNET_TRANSPORT_SS_UP); | ||
1970 | } | 1939 | } |
1971 | else | 1940 | else |
1972 | { | 1941 | { |
@@ -2000,9 +1969,7 @@ process_pending_messages (struct GNUNET_ATS_Session *session); | |||
2000 | * @return number of bytes written to @a buf | 1969 | * @return number of bytes written to @a buf |
2001 | */ | 1970 | */ |
2002 | static size_t | 1971 | static size_t |
2003 | do_transmit (void *cls, | 1972 | do_transmit (void *cls, size_t size, void *buf) |
2004 | size_t size, | ||
2005 | void *buf) | ||
2006 | { | 1973 | { |
2007 | struct GNUNET_ATS_Session *session = cls; | 1974 | struct GNUNET_ATS_Session *session = cls; |
2008 | struct GNUNET_PeerIdentity pid; | 1975 | struct GNUNET_PeerIdentity pid; |
@@ -2026,8 +1993,8 @@ do_transmit (void *cls, | |||
2026 | tl = NULL; | 1993 | tl = NULL; |
2027 | ret = 0; | 1994 | ret = 0; |
2028 | now = GNUNET_TIME_absolute_get (); | 1995 | now = GNUNET_TIME_absolute_get (); |
2029 | while ( (NULL != (pos = session->pending_messages_head)) && | 1996 | while ((NULL != (pos = session->pending_messages_head)) && |
2030 | (pos->timeout.abs_value_us <= now.abs_value_us) ) | 1997 | (pos->timeout.abs_value_us <= now.abs_value_us)) |
2031 | { | 1998 | { |
2032 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, | 1999 | GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, |
2033 | session->pending_messages_tail, | 2000 | session->pending_messages_tail, |
@@ -2041,10 +2008,7 @@ do_transmit (void *cls, | |||
2041 | pos->message_size, | 2008 | pos->message_size, |
2042 | GNUNET_i2s (&session->target)); | 2009 | GNUNET_i2s (&session->target)); |
2043 | ret += pos->message_size; | 2010 | ret += pos->message_size; |
2044 | GNUNET_CONTAINER_DLL_insert_after (hd, | 2011 | GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); |
2045 | tl, | ||
2046 | tl, | ||
2047 | pos); | ||
2048 | } | 2012 | } |
2049 | /* do this call before callbacks (so that if callbacks destroy | 2013 | /* do this call before callbacks (so that if callbacks destroy |
2050 | * session, they have a chance to cancel actions done by this | 2014 | * session, they have a chance to cancel actions done by this |
@@ -2055,9 +2019,7 @@ do_transmit (void *cls, | |||
2055 | * the callbacks may abort the session */ | 2019 | * the callbacks may abort the session */ |
2056 | while (NULL != (pos = hd)) | 2020 | while (NULL != (pos = hd)) |
2057 | { | 2021 | { |
2058 | GNUNET_CONTAINER_DLL_remove (hd, | 2022 | GNUNET_CONTAINER_DLL_remove (hd, tl, pos); |
2059 | tl, | ||
2060 | pos); | ||
2061 | if (NULL != pos->transmit_cont) | 2023 | if (NULL != pos->transmit_cont) |
2062 | pos->transmit_cont (pos->transmit_cont_cls, | 2024 | pos->transmit_cont (pos->transmit_cont_cls, |
2063 | &pid, | 2025 | &pid, |
@@ -2067,10 +2029,12 @@ do_transmit (void *cls, | |||
2067 | GNUNET_free (pos); | 2029 | GNUNET_free (pos); |
2068 | } | 2030 | } |
2069 | GNUNET_STATISTICS_update (plugin->env->stats, | 2031 | GNUNET_STATISTICS_update (plugin->env->stats, |
2070 | gettext_noop ("# bytes currently in TCP buffers"), -(int64_t) ret, | 2032 | gettext_noop ("# bytes currently in TCP buffers"), |
2033 | -(int64_t) ret, | ||
2071 | GNUNET_NO); | 2034 | GNUNET_NO); |
2072 | GNUNET_STATISTICS_update (plugin->env->stats, | 2035 | GNUNET_STATISTICS_update (plugin->env->stats, |
2073 | gettext_noop ("# bytes discarded by TCP (timeout)"), | 2036 | gettext_noop ( |
2037 | "# bytes discarded by TCP (timeout)"), | ||
2074 | ret, | 2038 | ret, |
2075 | GNUNET_NO); | 2039 | GNUNET_NO); |
2076 | if (0 < ret) | 2040 | if (0 < ret) |
@@ -2095,7 +2059,7 @@ do_transmit (void *cls, | |||
2095 | session->msgs_in_queue--; | 2059 | session->msgs_in_queue--; |
2096 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); | 2060 | GNUNET_assert (pos->message_size <= session->bytes_in_queue); |
2097 | session->bytes_in_queue -= pos->message_size; | 2061 | session->bytes_in_queue -= pos->message_size; |
2098 | GNUNET_assert(size >= pos->message_size); | 2062 | GNUNET_assert (size >= pos->message_size); |
2099 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2063 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2100 | "Transmitting message of type %u size %u to peer %s at %s\n", | 2064 | "Transmitting message of type %u size %u to peer %s at %s\n", |
2101 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), | 2065 | ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), |
@@ -2105,19 +2069,13 @@ do_transmit (void *cls, | |||
2105 | session->address->address, | 2069 | session->address->address, |
2106 | session->address->address_length)); | 2070 | session->address->address_length)); |
2107 | /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ | 2071 | /* FIXME: this GNUNET_memcpy can be up to 7% of our total runtime */ |
2108 | GNUNET_memcpy (cbuf, | 2072 | GNUNET_memcpy (cbuf, pos->msg, pos->message_size); |
2109 | pos->msg, | ||
2110 | pos->message_size); | ||
2111 | cbuf += pos->message_size; | 2073 | cbuf += pos->message_size; |
2112 | ret += pos->message_size; | 2074 | ret += pos->message_size; |
2113 | size -= pos->message_size; | 2075 | size -= pos->message_size; |
2114 | GNUNET_CONTAINER_DLL_insert_tail (hd, | 2076 | GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); |
2115 | tl, | ||
2116 | pos); | ||
2117 | } | 2077 | } |
2118 | notify_session_monitor (session->plugin, | 2078 | notify_session_monitor (session->plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
2119 | session, | ||
2120 | GNUNET_TRANSPORT_SS_UPDATE); | ||
2121 | /* schedule 'continuation' before callbacks so that callbacks that | 2079 | /* schedule 'continuation' before callbacks so that callbacks that |
2122 | * cancel everything don't cause us to use a session that no longer | 2080 | * cancel everything don't cause us to use a session that no longer |
2123 | * exists... */ | 2081 | * exists... */ |
@@ -2141,7 +2099,7 @@ do_transmit (void *cls, | |||
2141 | GNUNET_assert (NULL == tl); | 2099 | GNUNET_assert (NULL == tl); |
2142 | GNUNET_STATISTICS_update (plugin->env->stats, | 2100 | GNUNET_STATISTICS_update (plugin->env->stats, |
2143 | gettext_noop ("# bytes currently in TCP buffers"), | 2101 | gettext_noop ("# bytes currently in TCP buffers"), |
2144 | - (int64_t) ret, | 2102 | -(int64_t) ret, |
2145 | GNUNET_NO); | 2103 | GNUNET_NO); |
2146 | GNUNET_STATISTICS_update (plugin->env->stats, | 2104 | GNUNET_STATISTICS_update (plugin->env->stats, |
2147 | gettext_noop ("# bytes transmitted via TCP"), | 2105 | gettext_noop ("# bytes transmitted via TCP"), |
@@ -2168,12 +2126,13 @@ process_pending_messages (struct GNUNET_ATS_Session *session) | |||
2168 | if (NULL == (pm = session->pending_messages_head)) | 2126 | if (NULL == (pm = session->pending_messages_head)) |
2169 | return; | 2127 | return; |
2170 | 2128 | ||
2171 | session->transmit_handle | 2129 | session->transmit_handle = |
2172 | = GNUNET_SERVER_notify_transmit_ready (session->client, | 2130 | GNUNET_SERVER_notify_transmit_ready (session->client, |
2173 | pm->message_size, | 2131 | pm->message_size, |
2174 | GNUNET_TIME_absolute_get_remaining (pm->timeout), | 2132 | GNUNET_TIME_absolute_get_remaining ( |
2175 | &do_transmit, | 2133 | pm->timeout), |
2176 | session); | 2134 | &do_transmit, |
2135 | session); | ||
2177 | } | 2136 | } |
2178 | 2137 | ||
2179 | 2138 | ||
@@ -2214,7 +2173,7 @@ tcp_plugin_send (void *cls, | |||
2214 | GNUNET_TRANSPORT_TransmitContinuation cont, | 2173 | GNUNET_TRANSPORT_TransmitContinuation cont, |
2215 | void *cont_cls) | 2174 | void *cont_cls) |
2216 | { | 2175 | { |
2217 | struct Plugin * plugin = cls; | 2176 | struct Plugin *plugin = cls; |
2218 | struct PendingMessage *pm; | 2177 | struct PendingMessage *pm; |
2219 | 2178 | ||
2220 | /* create new message entry */ | 2179 | /* create new message entry */ |
@@ -2265,7 +2224,8 @@ tcp_plugin_send (void *cls, | |||
2265 | "This NAT WAIT session for peer `%s' is not yet ready!\n", | 2224 | "This NAT WAIT session for peer `%s' is not yet ready!\n", |
2266 | GNUNET_i2s (&session->target)); | 2225 | GNUNET_i2s (&session->target)); |
2267 | GNUNET_STATISTICS_update (plugin->env->stats, | 2226 | GNUNET_STATISTICS_update (plugin->env->stats, |
2268 | gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, | 2227 | gettext_noop ("# bytes currently in TCP buffers"), |
2228 | msgbuf_size, | ||
2269 | GNUNET_NO); | 2229 | GNUNET_NO); |
2270 | /* append pm to pending_messages list */ | 2230 | /* append pm to pending_messages list */ |
2271 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, | 2231 | GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, |
@@ -2278,15 +2238,9 @@ tcp_plugin_send (void *cls, | |||
2278 | GNUNET_TRANSPORT_SS_HANDSHAKE); | 2238 | GNUNET_TRANSPORT_SS_HANDSHAKE); |
2279 | return msgbuf_size; | 2239 | return msgbuf_size; |
2280 | } | 2240 | } |
2281 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2241 | LOG (GNUNET_ERROR_TYPE_ERROR, "Invalid session %p\n", session); |
2282 | "Invalid session %p\n", | ||
2283 | session); | ||
2284 | if (NULL != cont) | 2242 | if (NULL != cont) |
2285 | cont (cont_cls, | 2243 | cont (cont_cls, &session->target, GNUNET_SYSERR, pm->message_size, 0); |
2286 | &session->target, | ||
2287 | GNUNET_SYSERR, | ||
2288 | pm->message_size, | ||
2289 | 0); | ||
2290 | GNUNET_break (0); | 2244 | GNUNET_break (0); |
2291 | GNUNET_free (pm); | 2245 | GNUNET_free (pm); |
2292 | return GNUNET_SYSERR; /* session does not exist here */ | 2246 | return GNUNET_SYSERR; /* session does not exist here */ |
@@ -2307,7 +2261,6 @@ struct GNUNET_ATS_SessionItCtx | |||
2307 | * Where to store the session (if we found it). | 2261 | * Where to store the session (if we found it). |
2308 | */ | 2262 | */ |
2309 | struct GNUNET_ATS_Session *result; | 2263 | struct GNUNET_ATS_Session *result; |
2310 | |||
2311 | }; | 2264 | }; |
2312 | 2265 | ||
2313 | 2266 | ||
@@ -2327,9 +2280,7 @@ session_lookup_it (void *cls, | |||
2327 | struct GNUNET_ATS_SessionItCtx *si_ctx = cls; | 2280 | struct GNUNET_ATS_SessionItCtx *si_ctx = cls; |
2328 | struct GNUNET_ATS_Session *session = value; | 2281 | struct GNUNET_ATS_Session *session = value; |
2329 | 2282 | ||
2330 | if (0 != | 2283 | if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) |
2331 | GNUNET_HELLO_address_cmp (si_ctx->address, | ||
2332 | session->address)) | ||
2333 | return GNUNET_YES; | 2284 | return GNUNET_YES; |
2334 | si_ctx->result = session; | 2285 | si_ctx->result = session; |
2335 | return GNUNET_NO; | 2286 | return GNUNET_NO; |
@@ -2353,8 +2304,7 @@ nat_connect_timeout (void *cls) | |||
2353 | tcp_plugin_address_to_string (session->plugin, | 2304 | tcp_plugin_address_to_string (session->plugin, |
2354 | session->address->address, | 2305 | session->address->address, |
2355 | session->address->address_length)); | 2306 | session->address->address_length)); |
2356 | tcp_plugin_disconnect_session (session->plugin, | 2307 | tcp_plugin_disconnect_session (session->plugin, session); |
2357 | session); | ||
2358 | } | 2308 | } |
2359 | 2309 | ||
2360 | 2310 | ||
@@ -2389,8 +2339,7 @@ delayed_done (void *cls) | |||
2389 | 2339 | ||
2390 | session->receive_delay_task = NULL; | 2340 | session->receive_delay_task = NULL; |
2391 | reschedule_session_timeout (session); | 2341 | reschedule_session_timeout (session); |
2392 | GNUNET_SERVER_receive_done (session->client, | 2342 | GNUNET_SERVER_receive_done (session->client, GNUNET_OK); |
2393 | GNUNET_OK); | ||
2394 | } | 2343 | } |
2395 | 2344 | ||
2396 | 2345 | ||
@@ -2414,13 +2363,11 @@ tcp_plugin_update_inbound_delay (void *cls, | |||
2414 | return; | 2363 | return; |
2415 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2364 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2416 | "New inbound delay %s\n", | 2365 | "New inbound delay %s\n", |
2417 | GNUNET_STRINGS_relative_time_to_string (delay, | 2366 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_NO)); |
2418 | GNUNET_NO)); | ||
2419 | session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); | 2367 | session->receive_delay = GNUNET_TIME_relative_to_absolute (delay); |
2420 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); | 2368 | GNUNET_SCHEDULER_cancel (session->receive_delay_task); |
2421 | session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, | 2369 | session->receive_delay_task = |
2422 | &delayed_done, | 2370 | GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); |
2423 | session); | ||
2424 | } | 2371 | } |
2425 | 2372 | ||
2426 | 2373 | ||
@@ -2434,8 +2381,7 @@ tcp_plugin_update_inbound_delay (void *cls, | |||
2434 | * @return the session if the address is valid, NULL otherwise | 2381 | * @return the session if the address is valid, NULL otherwise |
2435 | */ | 2382 | */ |
2436 | static struct GNUNET_ATS_Session * | 2383 | static struct GNUNET_ATS_Session * |
2437 | tcp_plugin_get_session (void *cls, | 2384 | tcp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
2438 | const struct GNUNET_HELLO_Address *address) | ||
2439 | { | 2385 | { |
2440 | struct Plugin *plugin = cls; | 2386 | struct Plugin *plugin = cls; |
2441 | struct GNUNET_ATS_Session *session = NULL; | 2387 | struct GNUNET_ATS_Session *session = NULL; |
@@ -2471,9 +2417,8 @@ tcp_plugin_get_session (void *cls, | |||
2471 | } | 2417 | } |
2472 | 2418 | ||
2473 | /* look for existing session */ | 2419 | /* look for existing session */ |
2474 | if (GNUNET_YES == | 2420 | if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, |
2475 | GNUNET_CONTAINER_multipeermap_contains (plugin->sessionmap, | 2421 | &address->peer)) |
2476 | &address->peer)) | ||
2477 | { | 2422 | { |
2478 | struct GNUNET_ATS_SessionItCtx si_ctx; | 2423 | struct GNUNET_ATS_SessionItCtx si_ctx; |
2479 | 2424 | ||
@@ -2482,7 +2427,7 @@ tcp_plugin_get_session (void *cls, | |||
2482 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, | 2427 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->sessionmap, |
2483 | &address->peer, | 2428 | &address->peer, |
2484 | &session_lookup_it, | 2429 | &session_lookup_it, |
2485 | &si_ctx); | 2430 | &si_ctx); |
2486 | if (NULL != si_ctx.result) | 2431 | if (NULL != si_ctx.result) |
2487 | { | 2432 | { |
2488 | session = si_ctx.result; | 2433 | session = si_ctx.result; |
@@ -2503,13 +2448,13 @@ tcp_plugin_get_session (void *cls, | |||
2503 | peer pair at the same time. */ | 2448 | peer pair at the same time. */ |
2504 | } | 2449 | } |
2505 | 2450 | ||
2506 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 2451 | if (addrlen == sizeof (struct IPv6TcpAddress)) |
2507 | { | 2452 | { |
2508 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 2453 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
2509 | t6 = address->address; | 2454 | t6 = address->address; |
2510 | options = t6->options; | 2455 | options = t6->options; |
2511 | af = AF_INET6; | 2456 | af = AF_INET6; |
2512 | memset (&a6, 0, sizeof(a6)); | 2457 | memset (&a6, 0, sizeof (a6)); |
2513 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2458 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2514 | a6.sin6_len = sizeof (a6); | 2459 | a6.sin6_len = sizeof (a6); |
2515 | #endif | 2460 | #endif |
@@ -2517,17 +2462,17 @@ tcp_plugin_get_session (void *cls, | |||
2517 | a6.sin6_port = t6->t6_port; | 2462 | a6.sin6_port = t6->t6_port; |
2518 | if (t6->t6_port == 0) | 2463 | if (t6->t6_port == 0) |
2519 | is_natd = GNUNET_YES; | 2464 | is_natd = GNUNET_YES; |
2520 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | 2465 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); |
2521 | sb = &a6; | 2466 | sb = &a6; |
2522 | sbs = sizeof(a6); | 2467 | sbs = sizeof (a6); |
2523 | } | 2468 | } |
2524 | else if (addrlen == sizeof(struct IPv4TcpAddress)) | 2469 | else if (addrlen == sizeof (struct IPv4TcpAddress)) |
2525 | { | 2470 | { |
2526 | GNUNET_assert(NULL != address->address); /* make static analysis happy */ | 2471 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
2527 | t4 = address->address; | 2472 | t4 = address->address; |
2528 | options = t4->options; | 2473 | options = t4->options; |
2529 | af = AF_INET; | 2474 | af = AF_INET; |
2530 | memset (&a4, 0, sizeof(a4)); | 2475 | memset (&a4, 0, sizeof (a4)); |
2531 | #if HAVE_SOCKADDR_IN_SIN_LEN | 2476 | #if HAVE_SOCKADDR_IN_SIN_LEN |
2532 | a4.sin_len = sizeof (a4); | 2477 | a4.sin_len = sizeof (a4); |
2533 | #endif | 2478 | #endif |
@@ -2537,24 +2482,22 @@ tcp_plugin_get_session (void *cls, | |||
2537 | is_natd = GNUNET_YES; | 2482 | is_natd = GNUNET_YES; |
2538 | a4.sin_addr.s_addr = t4->ipv4_addr; | 2483 | a4.sin_addr.s_addr = t4->ipv4_addr; |
2539 | sb = &a4; | 2484 | sb = &a4; |
2540 | sbs = sizeof(a4); | 2485 | sbs = sizeof (a4); |
2541 | } | 2486 | } |
2542 | else | 2487 | else |
2543 | { | 2488 | { |
2544 | GNUNET_STATISTICS_update (plugin->env->stats, | 2489 | GNUNET_STATISTICS_update ( |
2545 | gettext_noop ("# requests to create session with invalid address"), | 2490 | plugin->env->stats, |
2546 | 1, | 2491 | gettext_noop ("# requests to create session with invalid address"), |
2547 | GNUNET_NO); | 2492 | 1, |
2493 | GNUNET_NO); | ||
2548 | return NULL; | 2494 | return NULL; |
2549 | } | 2495 | } |
2550 | 2496 | ||
2551 | net_type = plugin->env->get_address_type (plugin->env->cls, | 2497 | net_type = plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
2552 | sb, | ||
2553 | sbs); | ||
2554 | GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED); | 2498 | GNUNET_break (net_type != GNUNET_NT_UNSPECIFIED); |
2555 | 2499 | ||
2556 | if ( (is_natd == GNUNET_YES) && | 2500 | if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) |
2557 | (addrlen == sizeof(struct IPv6TcpAddress)) ) | ||
2558 | { | 2501 | { |
2559 | /* NAT client only works with IPv4 addresses */ | 2502 | /* NAT client only works with IPv4 addresses */ |
2560 | return NULL; | 2503 | return NULL; |
@@ -2566,62 +2509,51 @@ tcp_plugin_get_session (void *cls, | |||
2566 | return NULL; | 2509 | return NULL; |
2567 | } | 2510 | } |
2568 | 2511 | ||
2569 | if ( (is_natd == GNUNET_YES) && | 2512 | if ((is_natd == GNUNET_YES) && |
2570 | (GNUNET_YES == | 2513 | (GNUNET_YES == |
2571 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, | 2514 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
2572 | &address->peer))) | 2515 | &address->peer))) |
2573 | { | 2516 | { |
2574 | /* Only do one NAT punch attempt per peer identity */ | 2517 | /* Only do one NAT punch attempt per peer identity */ |
2575 | return NULL; | 2518 | return NULL; |
2576 | } | 2519 | } |
2577 | 2520 | ||
2578 | if ( (is_natd == GNUNET_YES) && | 2521 | if ((is_natd == GNUNET_YES) && (NULL != plugin->nat) && |
2579 | (NULL != plugin->nat) && | 2522 | (GNUNET_NO == |
2580 | (GNUNET_NO == | 2523 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, |
2581 | GNUNET_CONTAINER_multipeermap_contains (plugin->nat_wait_conns, | 2524 | &address->peer))) |
2582 | &address->peer))) | ||
2583 | { | 2525 | { |
2584 | struct sockaddr_in local_sa; | 2526 | struct sockaddr_in local_sa; |
2585 | 2527 | ||
2586 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2528 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2587 | "Found valid IPv4 NAT address (creating session)!\n"); | 2529 | "Found valid IPv4 NAT address (creating session)!\n"); |
2588 | session = create_session (plugin, | 2530 | session = create_session (plugin, address, net_type, NULL, GNUNET_YES); |
2589 | address, | 2531 | session->nat_connection_timeout = |
2590 | net_type, | 2532 | GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, &nat_connect_timeout, session); |
2591 | NULL, | ||
2592 | GNUNET_YES); | ||
2593 | session->nat_connection_timeout = GNUNET_SCHEDULER_add_delayed (NAT_TIMEOUT, | ||
2594 | &nat_connect_timeout, | ||
2595 | session); | ||
2596 | GNUNET_assert (GNUNET_OK == | 2533 | GNUNET_assert (GNUNET_OK == |
2597 | GNUNET_CONTAINER_multipeermap_put (plugin->nat_wait_conns, | 2534 | GNUNET_CONTAINER_multipeermap_put ( |
2598 | &session->target, | 2535 | plugin->nat_wait_conns, |
2599 | session, | 2536 | &session->target, |
2600 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 2537 | session, |
2538 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
2601 | 2539 | ||
2602 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2540 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2603 | "Created NAT WAIT connection to `%s' at `%s'\n", | 2541 | "Created NAT WAIT connection to `%s' at `%s'\n", |
2604 | GNUNET_i2s (&session->target), | 2542 | GNUNET_i2s (&session->target), |
2605 | GNUNET_a2s (sb, sbs)); | 2543 | GNUNET_a2s (sb, sbs)); |
2606 | memset (&local_sa, | 2544 | memset (&local_sa, 0, sizeof (local_sa)); |
2607 | 0, | ||
2608 | sizeof (local_sa)); | ||
2609 | local_sa.sin_family = AF_INET; | 2545 | local_sa.sin_family = AF_INET; |
2610 | local_sa.sin_port = htons (plugin->open_port); | 2546 | local_sa.sin_port = htons (plugin->open_port); |
2611 | /* We leave sin_address at 0, let the kernel figure it out, | 2547 | /* We leave sin_address at 0, let the kernel figure it out, |
2612 | even if our bind() is more specific. (May want to reconsider | 2548 | even if our bind() is more specific. (May want to reconsider |
2613 | later.) */ | 2549 | later.) */ |
2614 | if (GNUNET_OK == | 2550 | if (GNUNET_OK == GNUNET_NAT_request_reversal (plugin->nat, &local_sa, &a4)) |
2615 | GNUNET_NAT_request_reversal (plugin->nat, | ||
2616 | &local_sa, | ||
2617 | &a4)) | ||
2618 | return session; | 2551 | return session; |
2619 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2552 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2620 | "Running NAT client for `%s' at `%s' failed\n", | 2553 | "Running NAT client for `%s' at `%s' failed\n", |
2621 | GNUNET_i2s (&session->target), | 2554 | GNUNET_i2s (&session->target), |
2622 | GNUNET_a2s (sb, sbs)); | 2555 | GNUNET_a2s (sb, sbs)); |
2623 | tcp_plugin_disconnect_session (plugin, | 2556 | tcp_plugin_disconnect_session (plugin, session); |
2624 | session); | ||
2625 | return NULL; | 2557 | return NULL; |
2626 | } | 2558 | } |
2627 | 2559 | ||
@@ -2638,22 +2570,22 @@ tcp_plugin_get_session (void *cls, | |||
2638 | } | 2570 | } |
2639 | else | 2571 | else |
2640 | { | 2572 | { |
2641 | if ( (GNUNET_OK != | 2573 | if ((GNUNET_OK != |
2642 | GNUNET_NETWORK_socket_setsockopt (s, | 2574 | GNUNET_NETWORK_socket_setsockopt (s, |
2643 | IPPROTO_TCP, | 2575 | IPPROTO_TCP, |
2644 | TCP_STEALTH, | 2576 | TCP_STEALTH, |
2645 | &session->target, | 2577 | &session->target, |
2646 | sizeof (struct GNUNET_PeerIdentity))) || | 2578 | sizeof ( |
2647 | (GNUNET_OK != | 2579 | struct GNUNET_PeerIdentity))) || |
2648 | GNUNET_NETWORK_socket_setsockopt (s, | 2580 | (GNUNET_OK != |
2649 | IPPROTO_TCP, | 2581 | GNUNET_NETWORK_socket_setsockopt (s, |
2650 | TCP_STEALTH_INTEGRITY, | 2582 | IPPROTO_TCP, |
2651 | &plugin->my_welcome, | 2583 | TCP_STEALTH_INTEGRITY, |
2652 | sizeof (struct WelcomeMessage))) ) | 2584 | &plugin->my_welcome, |
2585 | sizeof (struct WelcomeMessage)))) | ||
2653 | { | 2586 | { |
2654 | /* TCP STEALTH not supported by kernel */ | 2587 | /* TCP STEALTH not supported by kernel */ |
2655 | GNUNET_break (GNUNET_OK == | 2588 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
2656 | GNUNET_NETWORK_socket_close (s)); | ||
2657 | sa = NULL; | 2589 | sa = NULL; |
2658 | } | 2590 | } |
2659 | else | 2591 | else |
@@ -2685,13 +2617,13 @@ tcp_plugin_get_session (void *cls, | |||
2685 | session = create_session (plugin, | 2617 | session = create_session (plugin, |
2686 | address, | 2618 | address, |
2687 | net_type, | 2619 | net_type, |
2688 | GNUNET_SERVER_connect_socket (plugin->server, | 2620 | GNUNET_SERVER_connect_socket (plugin->server, sa), |
2689 | sa), | ||
2690 | GNUNET_NO); | 2621 | GNUNET_NO); |
2691 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 2622 | (void) GNUNET_CONTAINER_multipeermap_put ( |
2692 | &session->target, | 2623 | plugin->sessionmap, |
2693 | session, | 2624 | &session->target, |
2694 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 2625 | session, |
2626 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
2695 | /* Send TCP Welcome */ | 2627 | /* Send TCP Welcome */ |
2696 | process_pending_messages (session); | 2628 | process_pending_messages (session); |
2697 | 2629 | ||
@@ -2718,11 +2650,11 @@ session_disconnect_it (void *cls, | |||
2718 | struct GNUNET_ATS_Session *session = value; | 2650 | struct GNUNET_ATS_Session *session = value; |
2719 | 2651 | ||
2720 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 2652 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
2721 | gettext_noop ("# transport-service disconnect requests for TCP"), | 2653 | gettext_noop ( |
2654 | "# transport-service disconnect requests for TCP"), | ||
2722 | 1, | 2655 | 1, |
2723 | GNUNET_NO); | 2656 | GNUNET_NO); |
2724 | tcp_plugin_disconnect_session (plugin, | 2657 | tcp_plugin_disconnect_session (plugin, session); |
2725 | session); | ||
2726 | return GNUNET_YES; | 2658 | return GNUNET_YES; |
2727 | } | 2659 | } |
2728 | 2660 | ||
@@ -2744,8 +2676,7 @@ session_disconnect_it (void *cls, | |||
2744 | * to be cancelled | 2676 | * to be cancelled |
2745 | */ | 2677 | */ |
2746 | static void | 2678 | static void |
2747 | tcp_plugin_disconnect (void *cls, | 2679 | tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
2748 | const struct GNUNET_PeerIdentity *target) | ||
2749 | { | 2680 | { |
2750 | struct Plugin *plugin = cls; | 2681 | struct Plugin *plugin = cls; |
2751 | 2682 | ||
@@ -2774,8 +2705,7 @@ tcp_plugin_disconnect (void *cls, | |||
2774 | * @param hostname hostname part of the address | 2705 | * @param hostname hostname part of the address |
2775 | */ | 2706 | */ |
2776 | static void | 2707 | static void |
2777 | append_port (void *cls, | 2708 | append_port (void *cls, const char *hostname) |
2778 | const char *hostname) | ||
2779 | { | 2709 | { |
2780 | struct PrettyPrinterContext *ppc = cls; | 2710 | struct PrettyPrinterContext *ppc = cls; |
2781 | struct Plugin *plugin = ppc->plugin; | 2711 | struct Plugin *plugin = ppc->plugin; |
@@ -2791,9 +2721,7 @@ append_port (void *cls, | |||
2791 | GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, | 2721 | GNUNET_CONTAINER_DLL_remove (plugin->ppc_dll_head, |
2792 | plugin->ppc_dll_tail, | 2722 | plugin->ppc_dll_tail, |
2793 | ppc); | 2723 | ppc); |
2794 | ppc->asc (ppc->asc_cls, | 2724 | ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); |
2795 | NULL, | ||
2796 | GNUNET_OK); | ||
2797 | GNUNET_free (ppc); | 2725 | GNUNET_free (ppc); |
2798 | return; | 2726 | return; |
2799 | } | 2727 | } |
@@ -2811,9 +2739,7 @@ append_port (void *cls, | |||
2811 | ppc->options, | 2739 | ppc->options, |
2812 | hostname, | 2740 | hostname, |
2813 | ppc->port); | 2741 | ppc->port); |
2814 | ppc->asc (ppc->asc_cls, | 2742 | ppc->asc (ppc->asc_cls, ret, GNUNET_OK); |
2815 | ret, | ||
2816 | GNUNET_OK); | ||
2817 | GNUNET_free (ret); | 2743 | GNUNET_free (ret); |
2818 | } | 2744 | } |
2819 | 2745 | ||
@@ -2852,35 +2778,35 @@ tcp_plugin_address_pretty_printer (void *cls, | |||
2852 | uint16_t port; | 2778 | uint16_t port; |
2853 | uint32_t options; | 2779 | uint32_t options; |
2854 | 2780 | ||
2855 | if (sizeof(struct IPv6TcpAddress) == addrlen) | 2781 | if (sizeof (struct IPv6TcpAddress) == addrlen) |
2856 | { | 2782 | { |
2857 | t6 = addr; | 2783 | t6 = addr; |
2858 | memset (&a6, 0, sizeof(a6)); | 2784 | memset (&a6, 0, sizeof (a6)); |
2859 | a6.sin6_family = AF_INET6; | 2785 | a6.sin6_family = AF_INET6; |
2860 | a6.sin6_port = t6->t6_port; | 2786 | a6.sin6_port = t6->t6_port; |
2861 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | 2787 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); |
2862 | port = ntohs (t6->t6_port); | 2788 | port = ntohs (t6->t6_port); |
2863 | options = ntohl (t6->options); | 2789 | options = ntohl (t6->options); |
2864 | sb = &a6; | 2790 | sb = &a6; |
2865 | sbs = sizeof(a6); | 2791 | sbs = sizeof (a6); |
2866 | } | 2792 | } |
2867 | else if (sizeof(struct IPv4TcpAddress) == addrlen) | 2793 | else if (sizeof (struct IPv4TcpAddress) == addrlen) |
2868 | { | 2794 | { |
2869 | t4 = addr; | 2795 | t4 = addr; |
2870 | memset (&a4, 0, sizeof(a4)); | 2796 | memset (&a4, 0, sizeof (a4)); |
2871 | a4.sin_family = AF_INET; | 2797 | a4.sin_family = AF_INET; |
2872 | a4.sin_port = t4->t4_port; | 2798 | a4.sin_port = t4->t4_port; |
2873 | a4.sin_addr.s_addr = t4->ipv4_addr; | 2799 | a4.sin_addr.s_addr = t4->ipv4_addr; |
2874 | port = ntohs (t4->t4_port); | 2800 | port = ntohs (t4->t4_port); |
2875 | options = ntohl (t4->options); | 2801 | options = ntohl (t4->options); |
2876 | sb = &a4; | 2802 | sb = &a4; |
2877 | sbs = sizeof(a4); | 2803 | sbs = sizeof (a4); |
2878 | } | 2804 | } |
2879 | else | 2805 | else |
2880 | { | 2806 | { |
2881 | /* invalid address */ | 2807 | /* invalid address */ |
2882 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2808 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2883 | _("Unexpected address length: %u bytes\n"), | 2809 | _ ("Unexpected address length: %u bytes\n"), |
2884 | (unsigned int) addrlen); | 2810 | (unsigned int) addrlen); |
2885 | asc (asc_cls, NULL, GNUNET_SYSERR); | 2811 | asc (asc_cls, NULL, GNUNET_SYSERR); |
2886 | asc (asc_cls, NULL, GNUNET_OK); | 2812 | asc (asc_cls, NULL, GNUNET_OK); |
@@ -2888,7 +2814,7 @@ tcp_plugin_address_pretty_printer (void *cls, | |||
2888 | } | 2814 | } |
2889 | ppc = GNUNET_new (struct PrettyPrinterContext); | 2815 | ppc = GNUNET_new (struct PrettyPrinterContext); |
2890 | ppc->plugin = plugin; | 2816 | ppc->plugin = plugin; |
2891 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 2817 | if (addrlen == sizeof (struct IPv6TcpAddress)) |
2892 | ppc->ipv6 = GNUNET_YES; | 2818 | ppc->ipv6 = GNUNET_YES; |
2893 | else | 2819 | else |
2894 | ppc->ipv6 = GNUNET_NO; | 2820 | ppc->ipv6 = GNUNET_NO; |
@@ -2896,23 +2822,20 @@ tcp_plugin_address_pretty_printer (void *cls, | |||
2896 | ppc->asc_cls = asc_cls; | 2822 | ppc->asc_cls = asc_cls; |
2897 | ppc->port = port; | 2823 | ppc->port = port; |
2898 | ppc->options = options; | 2824 | ppc->options = options; |
2899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2825 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting DNS reverse lookup\n"); |
2900 | "Starting DNS reverse lookup\n"); | ||
2901 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, | 2826 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, |
2902 | sbs, | 2827 | sbs, |
2903 | ! numeric, | 2828 | ! numeric, |
2904 | timeout, | 2829 | timeout, |
2905 | &append_port, | 2830 | &append_port, |
2906 | ppc); | 2831 | ppc); |
2907 | if (NULL == ppc->resolver_handle) | 2832 | if (NULL == ppc->resolver_handle) |
2908 | { | 2833 | { |
2909 | GNUNET_break (0); | 2834 | GNUNET_break (0); |
2910 | GNUNET_free (ppc); | 2835 | GNUNET_free (ppc); |
2911 | return; | 2836 | return; |
2912 | } | 2837 | } |
2913 | GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, | 2838 | GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); |
2914 | plugin->ppc_dll_tail, | ||
2915 | ppc); | ||
2916 | } | 2839 | } |
2917 | 2840 | ||
2918 | 2841 | ||
@@ -2932,29 +2855,25 @@ tcp_plugin_address_pretty_printer (void *cls, | |||
2932 | * and transport, #GNUNET_SYSERR if not | 2855 | * and transport, #GNUNET_SYSERR if not |
2933 | */ | 2856 | */ |
2934 | static int | 2857 | static int |
2935 | tcp_plugin_check_address (void *cls, | 2858 | tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
2936 | const void *addr, | ||
2937 | size_t addrlen) | ||
2938 | { | 2859 | { |
2939 | struct Plugin *plugin = cls; | 2860 | struct Plugin *plugin = cls; |
2940 | const struct IPv4TcpAddress *v4; | 2861 | const struct IPv4TcpAddress *v4; |
2941 | const struct IPv6TcpAddress *v6; | 2862 | const struct IPv6TcpAddress *v6; |
2942 | 2863 | ||
2943 | if ( (addrlen != sizeof(struct IPv4TcpAddress)) && | 2864 | if ((addrlen != sizeof (struct IPv4TcpAddress)) && |
2944 | (addrlen != sizeof(struct IPv6TcpAddress)) ) | 2865 | (addrlen != sizeof (struct IPv6TcpAddress))) |
2945 | { | 2866 | { |
2946 | GNUNET_break_op (0); | 2867 | GNUNET_break_op (0); |
2947 | return GNUNET_SYSERR; | 2868 | return GNUNET_SYSERR; |
2948 | } | 2869 | } |
2949 | 2870 | ||
2950 | if (addrlen == sizeof(struct IPv4TcpAddress)) | 2871 | if (addrlen == sizeof (struct IPv4TcpAddress)) |
2951 | { | 2872 | { |
2952 | struct sockaddr_in s4; | 2873 | struct sockaddr_in s4; |
2953 | 2874 | ||
2954 | v4 = (const struct IPv4TcpAddress *) addr; | 2875 | v4 = (const struct IPv4TcpAddress *) addr; |
2955 | if (0 != memcmp (&v4->options, | 2876 | if (0 != memcmp (&v4->options, &plugin->myoptions, sizeof (uint32_t))) |
2956 | &plugin->myoptions, | ||
2957 | sizeof(uint32_t))) | ||
2958 | { | 2877 | { |
2959 | GNUNET_break (0); | 2878 | GNUNET_break (0); |
2960 | return GNUNET_SYSERR; | 2879 | return GNUNET_SYSERR; |
@@ -2968,9 +2887,7 @@ tcp_plugin_check_address (void *cls, | |||
2968 | s4.sin_addr.s_addr = v4->ipv4_addr; | 2887 | s4.sin_addr.s_addr = v4->ipv4_addr; |
2969 | 2888 | ||
2970 | if (GNUNET_OK != | 2889 | if (GNUNET_OK != |
2971 | GNUNET_NAT_test_address (plugin->nat, | 2890 | GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in))) |
2972 | &s4, | ||
2973 | sizeof (struct sockaddr_in))) | ||
2974 | return GNUNET_SYSERR; | 2891 | return GNUNET_SYSERR; |
2975 | } | 2892 | } |
2976 | else | 2893 | else |
@@ -2983,9 +2900,7 @@ tcp_plugin_check_address (void *cls, | |||
2983 | GNUNET_break_op (0); | 2900 | GNUNET_break_op (0); |
2984 | return GNUNET_SYSERR; | 2901 | return GNUNET_SYSERR; |
2985 | } | 2902 | } |
2986 | if (0 != memcmp (&v6->options, | 2903 | if (0 != memcmp (&v6->options, &plugin->myoptions, sizeof (uint32_t))) |
2987 | &plugin->myoptions, | ||
2988 | sizeof (uint32_t))) | ||
2989 | { | 2904 | { |
2990 | GNUNET_break (0); | 2905 | GNUNET_break (0); |
2991 | return GNUNET_SYSERR; | 2906 | return GNUNET_SYSERR; |
@@ -2998,10 +2913,9 @@ tcp_plugin_check_address (void *cls, | |||
2998 | s6.sin6_port = v6->t6_port; | 2913 | s6.sin6_port = v6->t6_port; |
2999 | s6.sin6_addr = v6->ipv6_addr; | 2914 | s6.sin6_addr = v6->ipv6_addr; |
3000 | 2915 | ||
3001 | if (GNUNET_OK != | 2916 | if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, |
3002 | GNUNET_NAT_test_address (plugin->nat, | 2917 | &s6, |
3003 | &s6, | 2918 | sizeof (struct sockaddr_in6))) |
3004 | sizeof(struct sockaddr_in6))) | ||
3005 | return GNUNET_SYSERR; | 2919 | return GNUNET_SYSERR; |
3006 | } | 2920 | } |
3007 | return GNUNET_OK; | 2921 | return GNUNET_OK; |
@@ -3032,29 +2946,27 @@ handle_tcp_nat_probe (void *cls, | |||
3032 | const struct sockaddr_in *s4; | 2946 | const struct sockaddr_in *s4; |
3033 | const struct sockaddr_in6 *s6; | 2947 | const struct sockaddr_in6 *s6; |
3034 | 2948 | ||
3035 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2949 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NAT probe\n"); |
3036 | "Received NAT probe\n"); | ||
3037 | /* We have received a TCP NAT probe, meaning we (hopefully) initiated | 2950 | /* We have received a TCP NAT probe, meaning we (hopefully) initiated |
3038 | * a connection to this peer by running gnunet-nat-client. This peer | 2951 | * a connection to this peer by running gnunet-nat-client. This peer |
3039 | * received the punch message and now wants us to use the new connection | 2952 | * received the punch message and now wants us to use the new connection |
3040 | * as the default for that peer. Do so and then send a WELCOME message | 2953 | * as the default for that peer. Do so and then send a WELCOME message |
3041 | * so we can really be connected! | 2954 | * so we can really be connected! |
3042 | */ | 2955 | */ |
3043 | if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage)) | 2956 | if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage)) |
3044 | { | 2957 | { |
3045 | GNUNET_break_op(0); | 2958 | GNUNET_break_op (0); |
3046 | GNUNET_SERVER_receive_done (client, | 2959 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3047 | GNUNET_SYSERR); | ||
3048 | return; | 2960 | return; |
3049 | } | 2961 | } |
3050 | 2962 | ||
3051 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; | 2963 | tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message; |
3052 | if (0 == memcmp (&tcp_nat_probe->clientIdentity, plugin->env->my_identity, | 2964 | if (0 == memcmp (&tcp_nat_probe->clientIdentity, |
3053 | sizeof(struct GNUNET_PeerIdentity))) | 2965 | plugin->env->my_identity, |
2966 | sizeof (struct GNUNET_PeerIdentity))) | ||
3054 | { | 2967 | { |
3055 | /* refuse connections from ourselves */ | 2968 | /* refuse connections from ourselves */ |
3056 | GNUNET_SERVER_receive_done (client, | 2969 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3057 | GNUNET_SYSERR); | ||
3058 | return; | 2970 | return; |
3059 | } | 2971 | } |
3060 | 2972 | ||
@@ -3062,14 +2974,11 @@ handle_tcp_nat_probe (void *cls, | |||
3062 | &tcp_nat_probe->clientIdentity); | 2974 | &tcp_nat_probe->clientIdentity); |
3063 | if (NULL == session) | 2975 | if (NULL == session) |
3064 | { | 2976 | { |
3065 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2977 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Did NOT find session for NAT probe!\n"); |
3066 | "Did NOT find session for NAT probe!\n"); | 2978 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3067 | GNUNET_SERVER_receive_done (client, | ||
3068 | GNUNET_OK); | ||
3069 | return; | 2979 | return; |
3070 | } | 2980 | } |
3071 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2981 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found session for NAT probe!\n"); |
3072 | "Found session for NAT probe!\n"); | ||
3073 | 2982 | ||
3074 | if (NULL != session->nat_connection_timeout) | 2983 | if (NULL != session->nat_connection_timeout) |
3075 | { | 2984 | { |
@@ -3077,28 +2986,24 @@ handle_tcp_nat_probe (void *cls, | |||
3077 | session->nat_connection_timeout = NULL; | 2986 | session->nat_connection_timeout = NULL; |
3078 | } | 2987 | } |
3079 | 2988 | ||
3080 | if (GNUNET_OK != | 2989 | if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3081 | GNUNET_SERVER_client_get_address (client, | ||
3082 | &vaddr, | ||
3083 | &alen)) | ||
3084 | { | 2990 | { |
3085 | GNUNET_break(0); | 2991 | GNUNET_break (0); |
3086 | GNUNET_SERVER_receive_done (client, | 2992 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3087 | GNUNET_SYSERR); | 2993 | tcp_plugin_disconnect_session (plugin, session); |
3088 | tcp_plugin_disconnect_session (plugin, | ||
3089 | session); | ||
3090 | return; | 2994 | return; |
3091 | } | 2995 | } |
3092 | GNUNET_assert (GNUNET_YES == | 2996 | GNUNET_assert ( |
3093 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, | 2997 | GNUNET_YES == |
3094 | &tcp_nat_probe->clientIdentity, | 2998 | GNUNET_CONTAINER_multipeermap_remove (plugin->nat_wait_conns, |
3095 | session)); | 2999 | &tcp_nat_probe->clientIdentity, |
3096 | GNUNET_SERVER_client_set_user_context (client, | 3000 | session)); |
3097 | session); | 3001 | GNUNET_SERVER_client_set_user_context (client, session); |
3098 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 3002 | (void) GNUNET_CONTAINER_multipeermap_put ( |
3099 | &session->target, | 3003 | plugin->sessionmap, |
3100 | session, | 3004 | &session->target, |
3101 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 3005 | session, |
3006 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
3102 | session->last_activity = GNUNET_TIME_absolute_get (); | 3007 | session->last_activity = GNUNET_TIME_absolute_get (); |
3103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3008 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3104 | "Found address `%s' for incoming connection\n", | 3009 | "Found address `%s' for incoming connection\n", |
@@ -3111,45 +3016,43 @@ handle_tcp_nat_probe (void *cls, | |||
3111 | t4->options = htonl (TCP_OPTIONS_NONE); | 3016 | t4->options = htonl (TCP_OPTIONS_NONE); |
3112 | t4->t4_port = s4->sin_port; | 3017 | t4->t4_port = s4->sin_port; |
3113 | t4->ipv4_addr = s4->sin_addr.s_addr; | 3018 | t4->ipv4_addr = s4->sin_addr.s_addr; |
3114 | session->address = GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, | 3019 | session->address = |
3115 | PLUGIN_NAME, | 3020 | GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, |
3116 | &t4, | 3021 | PLUGIN_NAME, |
3117 | sizeof(struct IPv4TcpAddress), | 3022 | &t4, |
3118 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 3023 | sizeof (struct IPv4TcpAddress), |
3024 | GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
3119 | break; | 3025 | break; |
3120 | case AF_INET6: | 3026 | case AF_INET6: |
3121 | s6 = vaddr; | 3027 | s6 = vaddr; |
3122 | t6 = GNUNET_new (struct IPv6TcpAddress); | 3028 | t6 = GNUNET_new (struct IPv6TcpAddress); |
3123 | t6->options = htonl (TCP_OPTIONS_NONE); | 3029 | t6->options = htonl (TCP_OPTIONS_NONE); |
3124 | t6->t6_port = s6->sin6_port; | 3030 | t6->t6_port = s6->sin6_port; |
3125 | GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); | 3031 | GNUNET_memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); |
3126 | session->address = GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, | 3032 | session->address = |
3127 | PLUGIN_NAME, | 3033 | GNUNET_HELLO_address_allocate (&tcp_nat_probe->clientIdentity, |
3128 | &t6, | 3034 | PLUGIN_NAME, |
3129 | sizeof(struct IPv6TcpAddress), | 3035 | &t6, |
3130 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 3036 | sizeof (struct IPv6TcpAddress), |
3037 | GNUNET_HELLO_ADDRESS_INFO_NONE); | ||
3131 | break; | 3038 | break; |
3132 | default: | 3039 | default: |
3133 | GNUNET_break_op(0); | 3040 | GNUNET_break_op (0); |
3134 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3041 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Bad address for incoming connection!\n"); |
3135 | "Bad address for incoming connection!\n"); | 3042 | GNUNET_free (vaddr); |
3136 | GNUNET_free(vaddr); | 3043 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3137 | GNUNET_SERVER_receive_done (client, | 3044 | tcp_plugin_disconnect_session (plugin, session); |
3138 | GNUNET_SYSERR); | ||
3139 | tcp_plugin_disconnect_session (plugin, | ||
3140 | session); | ||
3141 | return; | 3045 | return; |
3142 | } | 3046 | } |
3143 | GNUNET_free (vaddr); | 3047 | GNUNET_free (vaddr); |
3144 | GNUNET_break (NULL == session->client); | 3048 | GNUNET_break (NULL == session->client); |
3145 | session->client = client; | 3049 | session->client = client; |
3146 | GNUNET_STATISTICS_update (plugin->env->stats, | 3050 | GNUNET_STATISTICS_update (plugin->env->stats, |
3147 | gettext_noop ("# TCP sessions active"), | 3051 | gettext_noop ("# TCP sessions active"), |
3148 | 1, | 3052 | 1, |
3149 | GNUNET_NO); | 3053 | GNUNET_NO); |
3150 | process_pending_messages (session); | 3054 | process_pending_messages (session); |
3151 | GNUNET_SERVER_receive_done (client, | 3055 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3152 | GNUNET_OK); | ||
3153 | } | 3056 | } |
3154 | 3057 | ||
3155 | 3058 | ||
@@ -3179,13 +3082,10 @@ handle_tcp_welcome (void *cls, | |||
3179 | 3082 | ||
3180 | if (0 == memcmp (&wm->clientIdentity, | 3083 | if (0 == memcmp (&wm->clientIdentity, |
3181 | plugin->env->my_identity, | 3084 | plugin->env->my_identity, |
3182 | sizeof(struct GNUNET_PeerIdentity))) | 3085 | sizeof (struct GNUNET_PeerIdentity))) |
3183 | { | 3086 | { |
3184 | /* refuse connections from ourselves */ | 3087 | /* refuse connections from ourselves */ |
3185 | if (GNUNET_OK == | 3088 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3186 | GNUNET_SERVER_client_get_address (client, | ||
3187 | &vaddr, | ||
3188 | &alen)) | ||
3189 | { | 3089 | { |
3190 | LOG (GNUNET_ERROR_TYPE_INFO, | 3090 | LOG (GNUNET_ERROR_TYPE_INFO, |
3191 | "Received WELCOME message from my own identity `%s' on address `%s'\n", | 3091 | "Received WELCOME message from my own identity `%s' on address `%s'\n", |
@@ -3193,34 +3093,26 @@ handle_tcp_welcome (void *cls, | |||
3193 | GNUNET_a2s (vaddr, alen)); | 3093 | GNUNET_a2s (vaddr, alen)); |
3194 | GNUNET_free (vaddr); | 3094 | GNUNET_free (vaddr); |
3195 | } | 3095 | } |
3196 | GNUNET_SERVER_receive_done (client, | 3096 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3197 | GNUNET_SYSERR); | ||
3198 | return; | 3097 | return; |
3199 | } | 3098 | } |
3200 | 3099 | ||
3201 | if (GNUNET_OK == | 3100 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3202 | GNUNET_SERVER_client_get_address (client, | ||
3203 | &vaddr, | ||
3204 | &alen)) | ||
3205 | { | 3101 | { |
3206 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3102 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3207 | "Received WELCOME message from `%s' on address `%s'\n", | 3103 | "Received WELCOME message from `%s' on address `%s'\n", |
3208 | GNUNET_i2s (&wm->clientIdentity), | 3104 | GNUNET_i2s (&wm->clientIdentity), |
3209 | GNUNET_a2s (vaddr, alen)); | 3105 | GNUNET_a2s (vaddr, alen)); |
3210 | GNUNET_free (vaddr); | 3106 | GNUNET_free (vaddr); |
3211 | } | 3107 | } |
3212 | GNUNET_STATISTICS_update (plugin->env->stats, | 3108 | GNUNET_STATISTICS_update (plugin->env->stats, |
3213 | gettext_noop ("# TCP WELCOME messages received"), | 3109 | gettext_noop ("# TCP WELCOME messages received"), |
3214 | 1, | 3110 | 1, |
3215 | GNUNET_NO); | 3111 | GNUNET_NO); |
3216 | session = lookup_session_by_client (plugin, | 3112 | session = lookup_session_by_client (plugin, client); |
3217 | client); | ||
3218 | if (NULL != session) | 3113 | if (NULL != session) |
3219 | { | 3114 | { |
3220 | if (GNUNET_OK == | 3115 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3221 | GNUNET_SERVER_client_get_address (client, | ||
3222 | &vaddr, | ||
3223 | &alen)) | ||
3224 | { | 3116 | { |
3225 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3226 | "Found existing session %p for peer `%s'\n", | 3118 | "Found existing session %p for peer `%s'\n", |
@@ -3231,41 +3123,41 @@ handle_tcp_welcome (void *cls, | |||
3231 | } | 3123 | } |
3232 | else | 3124 | else |
3233 | { | 3125 | { |
3234 | if (GNUNET_OK == | 3126 | if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
3235 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | ||
3236 | { | 3127 | { |
3237 | if (alen == sizeof(struct sockaddr_in)) | 3128 | if (alen == sizeof (struct sockaddr_in)) |
3238 | { | 3129 | { |
3239 | s4 = vaddr; | 3130 | s4 = vaddr; |
3240 | memset (&t4, '\0', sizeof (t4)); | 3131 | memset (&t4, '\0', sizeof (t4)); |
3241 | t4.options = htonl (TCP_OPTIONS_NONE); | 3132 | t4.options = htonl (TCP_OPTIONS_NONE); |
3242 | t4.t4_port = s4->sin_port; | 3133 | t4.t4_port = s4->sin_port; |
3243 | t4.ipv4_addr = s4->sin_addr.s_addr; | 3134 | t4.ipv4_addr = s4->sin_addr.s_addr; |
3244 | address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, | 3135 | address = |
3245 | PLUGIN_NAME, | 3136 | GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
3246 | &t4, | 3137 | PLUGIN_NAME, |
3247 | sizeof(t4), | 3138 | &t4, |
3248 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 3139 | sizeof (t4), |
3140 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
3249 | } | 3141 | } |
3250 | else if (alen == sizeof(struct sockaddr_in6)) | 3142 | else if (alen == sizeof (struct sockaddr_in6)) |
3251 | { | 3143 | { |
3252 | s6 = vaddr; | 3144 | s6 = vaddr; |
3253 | memset (&t6, '\0', sizeof (t6)); | 3145 | memset (&t6, '\0', sizeof (t6)); |
3254 | t6.options = htonl (TCP_OPTIONS_NONE); | 3146 | t6.options = htonl (TCP_OPTIONS_NONE); |
3255 | t6.t6_port = s6->sin6_port; | 3147 | t6.t6_port = s6->sin6_port; |
3256 | GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); | 3148 | GNUNET_memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr)); |
3257 | address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, | 3149 | address = |
3258 | PLUGIN_NAME, | 3150 | GNUNET_HELLO_address_allocate (&wm->clientIdentity, |
3259 | &t6, | 3151 | PLUGIN_NAME, |
3260 | sizeof (t6), | 3152 | &t6, |
3261 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | 3153 | sizeof (t6), |
3154 | GNUNET_HELLO_ADDRESS_INFO_INBOUND); | ||
3262 | } | 3155 | } |
3263 | else | 3156 | else |
3264 | { | 3157 | { |
3265 | GNUNET_break (0); | 3158 | GNUNET_break (0); |
3266 | GNUNET_free_non_null (vaddr); | 3159 | GNUNET_free_non_null (vaddr); |
3267 | GNUNET_SERVER_receive_done (client, | 3160 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3268 | GNUNET_SYSERR); | ||
3269 | return; | 3161 | return; |
3270 | } | 3162 | } |
3271 | session = create_session (plugin, | 3163 | session = create_session (plugin, |
@@ -3281,17 +3173,19 @@ handle_tcp_welcome (void *cls, | |||
3281 | "Creating new%s session %p for peer `%s' client %p\n", | 3173 | "Creating new%s session %p for peer `%s' client %p\n", |
3282 | GNUNET_HELLO_address_check_option (session->address, | 3174 | GNUNET_HELLO_address_check_option (session->address, |
3283 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) | 3175 | GNUNET_HELLO_ADDRESS_INFO_INBOUND) |
3284 | ? " inbound" : "", | 3176 | ? " inbound" |
3177 | : "", | ||
3285 | session, | 3178 | session, |
3286 | tcp_plugin_address_to_string (plugin, | 3179 | tcp_plugin_address_to_string (plugin, |
3287 | session->address->address, | 3180 | session->address->address, |
3288 | session->address->address_length), | 3181 | session->address->address_length), |
3289 | client); | 3182 | client); |
3290 | GNUNET_free (vaddr); | 3183 | GNUNET_free (vaddr); |
3291 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->sessionmap, | 3184 | (void) GNUNET_CONTAINER_multipeermap_put ( |
3292 | &session->target, | 3185 | plugin->sessionmap, |
3293 | session, | 3186 | &session->target, |
3294 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 3187 | session, |
3188 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
3295 | /* Notify transport and ATS about new session */ | 3189 | /* Notify transport and ATS about new session */ |
3296 | plugin->env->session_start (plugin->env->cls, | 3190 | plugin->env->session_start (plugin->env->cls, |
3297 | session->address, | 3191 | session->address, |
@@ -3300,11 +3194,10 @@ handle_tcp_welcome (void *cls, | |||
3300 | } | 3194 | } |
3301 | else | 3195 | else |
3302 | { | 3196 | { |
3303 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3197 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3304 | "Did not obtain TCP socket address for incoming connection\n"); | 3198 | "Did not obtain TCP socket address for incoming connection\n"); |
3305 | GNUNET_break(0); | 3199 | GNUNET_break (0); |
3306 | GNUNET_SERVER_receive_done (client, | 3200 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3307 | GNUNET_SYSERR); | ||
3308 | return; | 3201 | return; |
3309 | } | 3202 | } |
3310 | } | 3203 | } |
@@ -3312,8 +3205,7 @@ handle_tcp_welcome (void *cls, | |||
3312 | if (GNUNET_YES != session->expecting_welcome) | 3205 | if (GNUNET_YES != session->expecting_welcome) |
3313 | { | 3206 | { |
3314 | GNUNET_break_op (0); | 3207 | GNUNET_break_op (0); |
3315 | GNUNET_SERVER_receive_done (client, | 3208 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3316 | GNUNET_SYSERR); | ||
3317 | return; | 3209 | return; |
3318 | } | 3210 | } |
3319 | session->last_activity = GNUNET_TIME_absolute_get (); | 3211 | session->last_activity = GNUNET_TIME_absolute_get (); |
@@ -3322,8 +3214,7 @@ handle_tcp_welcome (void *cls, | |||
3322 | process_pending_messages (session); | 3214 | process_pending_messages (session); |
3323 | GNUNET_SERVER_client_set_timeout (client, | 3215 | GNUNET_SERVER_client_set_timeout (client, |
3324 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 3216 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
3325 | GNUNET_SERVER_receive_done (client, | 3217 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3326 | GNUNET_OK); | ||
3327 | } | 3218 | } |
3328 | 3219 | ||
3329 | 3220 | ||
@@ -3346,12 +3237,11 @@ handle_tcp_data (void *cls, | |||
3346 | uint16_t type; | 3237 | uint16_t type; |
3347 | 3238 | ||
3348 | type = ntohs (message->type); | 3239 | type = ntohs (message->type); |
3349 | if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || | 3240 | if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || |
3350 | (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) ) | 3241 | (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) |
3351 | { | 3242 | { |
3352 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ | 3243 | /* We don't want to propagate WELCOME and NAT Probe messages up! */ |
3353 | GNUNET_SERVER_receive_done (client, | 3244 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3354 | GNUNET_OK); | ||
3355 | return; | 3245 | return; |
3356 | } | 3246 | } |
3357 | session = lookup_session_by_client (plugin, client); | 3247 | session = lookup_session_by_client (plugin, client); |
@@ -3362,18 +3252,14 @@ handle_tcp_data (void *cls, | |||
3362 | size_t alen; | 3252 | size_t alen; |
3363 | 3253 | ||
3364 | GNUNET_assert (GNUNET_OK == | 3254 | GNUNET_assert (GNUNET_OK == |
3365 | GNUNET_SERVER_client_get_address (client, | 3255 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)); |
3366 | &vaddr, | ||
3367 | &alen)); | ||
3368 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3256 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3369 | "Received unexpected %u bytes of type %u from `%s'\n", | 3257 | "Received unexpected %u bytes of type %u from `%s'\n", |
3370 | (unsigned int) ntohs (message->size), | 3258 | (unsigned int) ntohs (message->size), |
3371 | (unsigned int) ntohs (message->type), | 3259 | (unsigned int) ntohs (message->type), |
3372 | GNUNET_a2s (vaddr, | 3260 | GNUNET_a2s (vaddr, alen)); |
3373 | alen)); | 3261 | GNUNET_break_op (0); |
3374 | GNUNET_break_op(0); | 3262 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3375 | GNUNET_SERVER_receive_done (client, | ||
3376 | GNUNET_SYSERR); | ||
3377 | GNUNET_free_non_null (vaddr); | 3263 | GNUNET_free_non_null (vaddr); |
3378 | return; | 3264 | return; |
3379 | } | 3265 | } |
@@ -3383,17 +3269,14 @@ handle_tcp_data (void *cls, | |||
3383 | void *vaddr = NULL; | 3269 | void *vaddr = NULL; |
3384 | size_t alen; | 3270 | size_t alen; |
3385 | 3271 | ||
3386 | GNUNET_SERVER_client_get_address (client, | 3272 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
3387 | &vaddr, | ||
3388 | &alen); | ||
3389 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3273 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3390 | "Received unexpected %u bytes of type %u from `%s'\n", | 3274 | "Received unexpected %u bytes of type %u from `%s'\n", |
3391 | (unsigned int) ntohs (message->size), | 3275 | (unsigned int) ntohs (message->size), |
3392 | (unsigned int) ntohs (message->type), | 3276 | (unsigned int) ntohs (message->type), |
3393 | GNUNET_a2s (vaddr, alen)); | 3277 | GNUNET_a2s (vaddr, alen)); |
3394 | GNUNET_break_op(0); | 3278 | GNUNET_break_op (0); |
3395 | GNUNET_SERVER_receive_done (client, | 3279 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
3396 | GNUNET_SYSERR); | ||
3397 | GNUNET_free_non_null (vaddr); | 3280 | GNUNET_free_non_null (vaddr); |
3398 | return; | 3281 | return; |
3399 | } | 3282 | } |
@@ -3403,9 +3286,7 @@ handle_tcp_data (void *cls, | |||
3403 | void *vaddr = NULL; | 3286 | void *vaddr = NULL; |
3404 | size_t alen; | 3287 | size_t alen; |
3405 | 3288 | ||
3406 | GNUNET_SERVER_client_get_address (client, | 3289 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen); |
3407 | &vaddr, | ||
3408 | &alen); | ||
3409 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3290 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3410 | "Passing %u bytes of type %u from `%s' at %s to transport service.\n", | 3291 | "Passing %u bytes of type %u from `%s' at %s to transport service.\n", |
3411 | (unsigned int) ntohs (message->size), | 3292 | (unsigned int) ntohs (message->size), |
@@ -3420,31 +3301,27 @@ handle_tcp_data (void *cls, | |||
3420 | ntohs (message->size), | 3301 | ntohs (message->size), |
3421 | GNUNET_NO); | 3302 | GNUNET_NO); |
3422 | 3303 | ||
3423 | GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, | 3304 | GNUNET_assert ( |
3424 | &session->target, | 3305 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, |
3425 | session)); | 3306 | &session->target, |
3426 | delay = plugin->env->receive (plugin->env->cls, | 3307 | session)); |
3427 | session->address, | 3308 | delay = |
3428 | session, | 3309 | plugin->env->receive (plugin->env->cls, session->address, session, message); |
3429 | message); | ||
3430 | reschedule_session_timeout (session); | 3310 | reschedule_session_timeout (session); |
3431 | if (0 == delay.rel_value_us) | 3311 | if (0 == delay.rel_value_us) |
3432 | { | 3312 | { |
3433 | GNUNET_SERVER_receive_done (client, | 3313 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
3434 | GNUNET_OK); | ||
3435 | } | 3314 | } |
3436 | else | 3315 | else |
3437 | { | 3316 | { |
3438 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3317 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3439 | "Throttling receiving from `%s' for %s\n", | 3318 | "Throttling receiving from `%s' for %s\n", |
3440 | GNUNET_i2s (&session->target), | 3319 | GNUNET_i2s (&session->target), |
3441 | GNUNET_STRINGS_relative_time_to_string (delay, | 3320 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
3442 | GNUNET_YES)); | ||
3443 | GNUNET_SERVER_disable_receive_done_warning (client); | 3321 | GNUNET_SERVER_disable_receive_done_warning (client); |
3444 | GNUNET_assert (NULL == session->receive_delay_task); | 3322 | GNUNET_assert (NULL == session->receive_delay_task); |
3445 | session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay, | 3323 | session->receive_delay_task = |
3446 | &delayed_done, | 3324 | GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); |
3447 | session); | ||
3448 | } | 3325 | } |
3449 | } | 3326 | } |
3450 | 3327 | ||
@@ -3458,8 +3335,7 @@ handle_tcp_data (void *cls, | |||
3458 | * @param client identification of the client | 3335 | * @param client identification of the client |
3459 | */ | 3336 | */ |
3460 | static void | 3337 | static void |
3461 | connect_notify (void *cls, | 3338 | connect_notify (void *cls, struct GNUNET_SERVER_Client *client) |
3462 | struct GNUNET_SERVER_Client *client) | ||
3463 | { | 3339 | { |
3464 | struct Plugin *plugin = cls; | 3340 | struct Plugin *plugin = cls; |
3465 | 3341 | ||
@@ -3471,18 +3347,19 @@ connect_notify (void *cls, | |||
3471 | plugin->cur_connections, | 3347 | plugin->cur_connections, |
3472 | GNUNET_NO); | 3348 | GNUNET_NO); |
3473 | GNUNET_STATISTICS_update (plugin->env->stats, | 3349 | GNUNET_STATISTICS_update (plugin->env->stats, |
3474 | gettext_noop ("# TCP server connect events"), | 3350 | gettext_noop ("# TCP server connect events"), |
3475 | 1, | 3351 | 1, |
3476 | GNUNET_NO); | 3352 | GNUNET_NO); |
3477 | if (plugin->cur_connections != plugin->max_connections) | 3353 | if (plugin->cur_connections != plugin->max_connections) |
3478 | return; | 3354 | return; |
3479 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 3355 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
3480 | _("TCP connection limit reached, suspending server\n")); | 3356 | _ ("TCP connection limit reached, suspending server\n")); |
3481 | GNUNET_STATISTICS_update (plugin->env->stats, | 3357 | GNUNET_STATISTICS_update (plugin->env->stats, |
3482 | gettext_noop ("# TCP service suspended"), | 3358 | gettext_noop ("# TCP service suspended"), |
3483 | 1, | 3359 | 1, |
3484 | GNUNET_NO); | 3360 | GNUNET_NO); |
3485 | GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ | 3361 | GNUNET_SERVER_suspend ( |
3362 | plugin->server); /* Maximum number of connections rechead */ | ||
3486 | } | 3363 | } |
3487 | 3364 | ||
3488 | 3365 | ||
@@ -3495,8 +3372,7 @@ connect_notify (void *cls, | |||
3495 | * @param client identification of the client | 3372 | * @param client identification of the client |
3496 | */ | 3373 | */ |
3497 | static void | 3374 | static void |
3498 | disconnect_notify (void *cls, | 3375 | disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client) |
3499 | struct GNUNET_SERVER_Client *client) | ||
3500 | { | 3376 | { |
3501 | struct Plugin *plugin = cls; | 3377 | struct Plugin *plugin = cls; |
3502 | struct GNUNET_ATS_Session *session; | 3378 | struct GNUNET_ATS_Session *session; |
@@ -3505,8 +3381,7 @@ disconnect_notify (void *cls, | |||
3505 | return; | 3381 | return; |
3506 | GNUNET_assert (plugin->cur_connections >= 1); | 3382 | GNUNET_assert (plugin->cur_connections >= 1); |
3507 | plugin->cur_connections--; | 3383 | plugin->cur_connections--; |
3508 | session = lookup_session_by_client (plugin, | 3384 | session = lookup_session_by_client (plugin, client); |
3509 | client); | ||
3510 | if (NULL == session) | 3385 | if (NULL == session) |
3511 | return; /* unknown, nothing to do */ | 3386 | return; /* unknown, nothing to do */ |
3512 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3387 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -3529,11 +3404,11 @@ disconnect_notify (void *cls, | |||
3529 | plugin->cur_connections, | 3404 | plugin->cur_connections, |
3530 | GNUNET_NO); | 3405 | GNUNET_NO); |
3531 | GNUNET_STATISTICS_update (session->plugin->env->stats, | 3406 | GNUNET_STATISTICS_update (session->plugin->env->stats, |
3532 | gettext_noop ("# network-level TCP disconnect events"), | 3407 | gettext_noop ( |
3408 | "# network-level TCP disconnect events"), | ||
3533 | 1, | 3409 | 1, |
3534 | GNUNET_NO); | 3410 | GNUNET_NO); |
3535 | tcp_plugin_disconnect_session (plugin, | 3411 | tcp_plugin_disconnect_session (plugin, session); |
3536 | session); | ||
3537 | } | 3412 | } |
3538 | 3413 | ||
3539 | 3414 | ||
@@ -3546,9 +3421,7 @@ disconnect_notify (void *cls, | |||
3546 | * @return number of bytes copied into @a buf | 3421 | * @return number of bytes copied into @a buf |
3547 | */ | 3422 | */ |
3548 | static size_t | 3423 | static size_t |
3549 | notify_send_probe (void *cls, | 3424 | notify_send_probe (void *cls, size_t size, void *buf) |
3550 | size_t size, | ||
3551 | void *buf) | ||
3552 | { | 3425 | { |
3553 | struct TCPProbeContext *tcp_probe_ctx = cls; | 3426 | struct TCPProbeContext *tcp_probe_ctx = cls; |
3554 | struct Plugin *plugin = tcp_probe_ctx->plugin; | 3427 | struct Plugin *plugin = tcp_probe_ctx->plugin; |
@@ -3561,16 +3434,14 @@ notify_send_probe (void *cls, | |||
3561 | if (NULL == buf) | 3434 | if (NULL == buf) |
3562 | { | 3435 | { |
3563 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); | 3436 | GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock); |
3564 | GNUNET_free(tcp_probe_ctx); | 3437 | GNUNET_free (tcp_probe_ctx); |
3565 | return 0; | 3438 | return 0; |
3566 | } | 3439 | } |
3567 | GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); | 3440 | GNUNET_assert (size >= sizeof (tcp_probe_ctx->message)); |
3568 | GNUNET_memcpy (buf, | 3441 | GNUNET_memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message)); |
3569 | &tcp_probe_ctx->message, | ||
3570 | sizeof(tcp_probe_ctx->message)); | ||
3571 | GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, | 3442 | GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, |
3572 | tcp_probe_ctx->sock); | 3443 | tcp_probe_ctx->sock); |
3573 | ret = sizeof(tcp_probe_ctx->message); | 3444 | ret = sizeof (tcp_probe_ctx->message); |
3574 | GNUNET_free (tcp_probe_ctx); | 3445 | GNUNET_free (tcp_probe_ctx); |
3575 | return ret; | 3446 | return ret; |
3576 | } | 3447 | } |
@@ -3598,9 +3469,7 @@ try_connection_reversal (void *cls, | |||
3598 | * We have received an ICMP response, ostensibly from a peer | 3469 | * We have received an ICMP response, ostensibly from a peer |
3599 | * that wants to connect to us! Send a message to establish a connection. | 3470 | * that wants to connect to us! Send a message to establish a connection. |
3600 | */ | 3471 | */ |
3601 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, | 3472 | sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen); |
3602 | addr, | ||
3603 | addrlen); | ||
3604 | if (NULL == sock) | 3473 | if (NULL == sock) |
3605 | { | 3474 | { |
3606 | /* failed for some odd reason (out of sockets?); ignore attempt */ | 3475 | /* failed for some odd reason (out of sockets?); ignore attempt */ |
@@ -3608,23 +3477,23 @@ try_connection_reversal (void *cls, | |||
3608 | } | 3477 | } |
3609 | 3478 | ||
3610 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); | 3479 | tcp_probe_ctx = GNUNET_new (struct TCPProbeContext); |
3611 | tcp_probe_ctx->message.header.size | 3480 | tcp_probe_ctx->message.header.size = |
3612 | = htons (sizeof (struct TCP_NAT_ProbeMessage)); | 3481 | htons (sizeof (struct TCP_NAT_ProbeMessage)); |
3613 | tcp_probe_ctx->message.header.type | 3482 | tcp_probe_ctx->message.header.type = |
3614 | = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); | 3483 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); |
3615 | tcp_probe_ctx->message.clientIdentity | 3484 | tcp_probe_ctx->message.clientIdentity = *plugin->env->my_identity; |
3616 | = *plugin->env->my_identity; | ||
3617 | tcp_probe_ctx->plugin = plugin; | 3485 | tcp_probe_ctx->plugin = plugin; |
3618 | tcp_probe_ctx->sock = sock; | 3486 | tcp_probe_ctx->sock = sock; |
3619 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, | 3487 | GNUNET_CONTAINER_DLL_insert (plugin->probe_head, |
3620 | plugin->probe_tail, | 3488 | plugin->probe_tail, |
3621 | tcp_probe_ctx); | 3489 | tcp_probe_ctx); |
3622 | tcp_probe_ctx->transmit_handle | 3490 | tcp_probe_ctx->transmit_handle = |
3623 | = GNUNET_CONNECTION_notify_transmit_ready (sock, | 3491 | GNUNET_CONNECTION_notify_transmit_ready (sock, |
3624 | ntohs (tcp_probe_ctx->message.header.size), | 3492 | ntohs (tcp_probe_ctx->message |
3625 | GNUNET_TIME_UNIT_FOREVER_REL, | 3493 | .header.size), |
3626 | ¬ify_send_probe, | 3494 | GNUNET_TIME_UNIT_FOREVER_REL, |
3627 | tcp_probe_ctx); | 3495 | ¬ify_send_probe, |
3496 | tcp_probe_ctx); | ||
3628 | } | 3497 | } |
3629 | 3498 | ||
3630 | 3499 | ||
@@ -3636,8 +3505,7 @@ try_connection_reversal (void *cls, | |||
3636 | * @return the network type in HBO or #GNUNET_SYSERR | 3505 | * @return the network type in HBO or #GNUNET_SYSERR |
3637 | */ | 3506 | */ |
3638 | static enum GNUNET_NetworkType | 3507 | static enum GNUNET_NetworkType |
3639 | tcp_plugin_get_network (void *cls, | 3508 | tcp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) |
3640 | struct GNUNET_ATS_Session *session) | ||
3641 | { | 3509 | { |
3642 | return session->scope; | 3510 | return session->scope; |
3643 | } | 3511 | } |
@@ -3664,25 +3532,25 @@ tcp_plugin_get_network_for_address (void *cls, | |||
3664 | size_t sbs; | 3532 | size_t sbs; |
3665 | 3533 | ||
3666 | addrlen = address->address_length; | 3534 | addrlen = address->address_length; |
3667 | if (addrlen == sizeof(struct IPv6TcpAddress)) | 3535 | if (addrlen == sizeof (struct IPv6TcpAddress)) |
3668 | { | 3536 | { |
3669 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 3537 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
3670 | t6 = address->address; | 3538 | t6 = address->address; |
3671 | memset (&a6, 0, sizeof(a6)); | 3539 | memset (&a6, 0, sizeof (a6)); |
3672 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3540 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3673 | a6.sin6_len = sizeof (a6); | 3541 | a6.sin6_len = sizeof (a6); |
3674 | #endif | 3542 | #endif |
3675 | a6.sin6_family = AF_INET6; | 3543 | a6.sin6_family = AF_INET6; |
3676 | a6.sin6_port = t6->t6_port; | 3544 | a6.sin6_port = t6->t6_port; |
3677 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr)); | 3545 | GNUNET_memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr)); |
3678 | sb = &a6; | 3546 | sb = &a6; |
3679 | sbs = sizeof(a6); | 3547 | sbs = sizeof (a6); |
3680 | } | 3548 | } |
3681 | else if (addrlen == sizeof(struct IPv4TcpAddress)) | 3549 | else if (addrlen == sizeof (struct IPv4TcpAddress)) |
3682 | { | 3550 | { |
3683 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 3551 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
3684 | t4 = address->address; | 3552 | t4 = address->address; |
3685 | memset (&a4, 0, sizeof(a4)); | 3553 | memset (&a4, 0, sizeof (a4)); |
3686 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3554 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3687 | a4.sin_len = sizeof (a4); | 3555 | a4.sin_len = sizeof (a4); |
3688 | #endif | 3556 | #endif |
@@ -3690,16 +3558,14 @@ tcp_plugin_get_network_for_address (void *cls, | |||
3690 | a4.sin_port = t4->t4_port; | 3558 | a4.sin_port = t4->t4_port; |
3691 | a4.sin_addr.s_addr = t4->ipv4_addr; | 3559 | a4.sin_addr.s_addr = t4->ipv4_addr; |
3692 | sb = &a4; | 3560 | sb = &a4; |
3693 | sbs = sizeof(a4); | 3561 | sbs = sizeof (a4); |
3694 | } | 3562 | } |
3695 | else | 3563 | else |
3696 | { | 3564 | { |
3697 | GNUNET_break (0); | 3565 | GNUNET_break (0); |
3698 | return GNUNET_NT_UNSPECIFIED; | 3566 | return GNUNET_NT_UNSPECIFIED; |
3699 | } | 3567 | } |
3700 | return plugin->env->get_address_type (plugin->env->cls, | 3568 | return plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
3701 | sb, | ||
3702 | sbs); | ||
3703 | } | 3569 | } |
3704 | 3570 | ||
3705 | 3571 | ||
@@ -3720,14 +3586,10 @@ send_session_info_iter (void *cls, | |||
3720 | struct Plugin *plugin = cls; | 3586 | struct Plugin *plugin = cls; |
3721 | struct GNUNET_ATS_Session *session = value; | 3587 | struct GNUNET_ATS_Session *session = value; |
3722 | 3588 | ||
3723 | notify_session_monitor (plugin, | 3589 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
3724 | session, | ||
3725 | GNUNET_TRANSPORT_SS_INIT); | ||
3726 | /* FIXME: cannot tell if this is up or not from current | 3590 | /* FIXME: cannot tell if this is up or not from current |
3727 | session state... */ | 3591 | session state... */ |
3728 | notify_session_monitor (plugin, | 3592 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
3729 | session, | ||
3730 | GNUNET_TRANSPORT_SS_UP); | ||
3731 | return GNUNET_OK; | 3593 | return GNUNET_OK; |
3732 | } | 3594 | } |
3733 | 3595 | ||
@@ -3773,17 +3635,17 @@ tcp_plugin_setup_monitor (void *cls, | |||
3773 | void * | 3635 | void * |
3774 | libgnunet_plugin_transport_tcp_init (void *cls) | 3636 | libgnunet_plugin_transport_tcp_init (void *cls) |
3775 | { | 3637 | { |
3776 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { | 3638 | static const struct GNUNET_SERVER_MessageHandler my_handlers[] = |
3777 | { &handle_tcp_welcome, NULL, | 3639 | {{&handle_tcp_welcome, |
3640 | NULL, | ||
3778 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, | 3641 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, |
3779 | sizeof(struct WelcomeMessage) }, | 3642 | sizeof (struct WelcomeMessage)}, |
3780 | { &handle_tcp_nat_probe, NULL, | 3643 | {&handle_tcp_nat_probe, |
3644 | NULL, | ||
3781 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, | 3645 | GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, |
3782 | sizeof(struct TCP_NAT_ProbeMessage) }, | 3646 | sizeof (struct TCP_NAT_ProbeMessage)}, |
3783 | { &handle_tcp_data, NULL, | 3647 | {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, |
3784 | GNUNET_MESSAGE_TYPE_ALL, 0 }, | 3648 | {NULL, NULL, 0, 0}}; |
3785 | { NULL, NULL, 0, 0 } | ||
3786 | }; | ||
3787 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 3649 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
3788 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 3650 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
3789 | struct Plugin *plugin; | 3651 | struct Plugin *plugin; |
@@ -3794,7 +3656,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3794 | unsigned int i; | 3656 | unsigned int i; |
3795 | struct GNUNET_TIME_Relative idle_timeout; | 3657 | struct GNUNET_TIME_Relative idle_timeout; |
3796 | #ifdef TCP_STEALTH | 3658 | #ifdef TCP_STEALTH |
3797 | struct GNUNET_NETWORK_Handle *const*lsocks; | 3659 | struct GNUNET_NETWORK_Handle *const *lsocks; |
3798 | #endif | 3660 | #endif |
3799 | int ret; | 3661 | int ret; |
3800 | int ret_s; | 3662 | int ret_s; |
@@ -3814,27 +3676,28 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3814 | } | 3676 | } |
3815 | 3677 | ||
3816 | GNUNET_assert (NULL != env->cfg); | 3678 | GNUNET_assert (NULL != env->cfg); |
3817 | if (GNUNET_OK != | 3679 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3818 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 3680 | "transport-tcp", |
3819 | "transport-tcp", | 3681 | "MAX_CONNECTIONS", |
3820 | "MAX_CONNECTIONS", | 3682 | &max_connections)) |
3821 | &max_connections)) | ||
3822 | max_connections = 128; | 3683 | max_connections = 128; |
3823 | 3684 | ||
3824 | aport = 0; | 3685 | aport = 0; |
3825 | if ((GNUNET_OK != | 3686 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3826 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", | 3687 | "transport-tcp", |
3827 | "PORT", &bport)) || | 3688 | "PORT", |
3689 | &bport)) || | ||
3828 | (bport > 65535) || | 3690 | (bport > 65535) || |
3829 | ((GNUNET_OK == | 3691 | ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3830 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-tcp", | 3692 | "transport-tcp", |
3831 | "ADVERTISED-PORT", &aport)) && | 3693 | "ADVERTISED-PORT", |
3832 | (aport > 65535) )) | 3694 | &aport)) && |
3695 | (aport > 65535))) | ||
3833 | { | 3696 | { |
3834 | LOG(GNUNET_ERROR_TYPE_ERROR, | 3697 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3835 | _("Require valid port number for service `%s' in configuration!\n"), | 3698 | _ ("Require valid port number for service `%s' in configuration!\n"), |
3836 | "transport-tcp"); | 3699 | "transport-tcp"); |
3837 | return NULL ; | 3700 | return NULL; |
3838 | } | 3701 | } |
3839 | if (0 == aport) | 3702 | if (0 == aport) |
3840 | aport = bport; | 3703 | aport = bport; |
@@ -3847,8 +3710,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3847 | LEGACY_SERVICE_OPTION_NONE); | 3710 | LEGACY_SERVICE_OPTION_NONE); |
3848 | if (NULL == service) | 3711 | if (NULL == service) |
3849 | { | 3712 | { |
3850 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3713 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to start service.\n")); |
3851 | _("Failed to start service.\n")); | ||
3852 | return NULL; | 3714 | return NULL; |
3853 | } | 3715 | } |
3854 | } | 3716 | } |
@@ -3857,21 +3719,21 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3857 | 3719 | ||
3858 | api = NULL; | 3720 | api = NULL; |
3859 | plugin = GNUNET_new (struct Plugin); | 3721 | plugin = GNUNET_new (struct Plugin); |
3860 | plugin->sessionmap = GNUNET_CONTAINER_multipeermap_create (max_connections, | 3722 | plugin->sessionmap = |
3861 | GNUNET_YES); | 3723 | GNUNET_CONTAINER_multipeermap_create (max_connections, GNUNET_YES); |
3862 | plugin->max_connections = max_connections; | 3724 | plugin->max_connections = max_connections; |
3863 | plugin->open_port = bport; | 3725 | plugin->open_port = bport; |
3864 | plugin->adv_port = aport; | 3726 | plugin->adv_port = aport; |
3865 | plugin->env = env; | 3727 | plugin->env = env; |
3866 | plugin->my_welcome.header.size = htons (sizeof(struct WelcomeMessage)); | 3728 | plugin->my_welcome.header.size = htons (sizeof (struct WelcomeMessage)); |
3867 | plugin->my_welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); | 3729 | plugin->my_welcome.header.type = |
3730 | htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); | ||
3868 | plugin->my_welcome.clientIdentity = *plugin->env->my_identity; | 3731 | plugin->my_welcome.clientIdentity = *plugin->env->my_identity; |
3869 | 3732 | ||
3870 | if ( (NULL != service) && | 3733 | if ((NULL != service) && |
3871 | (GNUNET_YES == | 3734 | (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3872 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 3735 | "transport-tcp", |
3873 | "transport-tcp", | 3736 | "TCP_STEALTH"))) |
3874 | "TCP_STEALTH")) ) | ||
3875 | { | 3737 | { |
3876 | #ifdef TCP_STEALTH | 3738 | #ifdef TCP_STEALTH |
3877 | plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; | 3739 | plugin->myoptions |= TCP_OPTIONS_TCP_STEALTH; |
@@ -3880,59 +3742,57 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3880 | { | 3742 | { |
3881 | uint32_t len = sizeof (struct WelcomeMessage); | 3743 | uint32_t len = sizeof (struct WelcomeMessage); |
3882 | 3744 | ||
3883 | for (i=0;NULL!=lsocks[i];i++) | 3745 | for (i = 0; NULL != lsocks[i]; i++) |
3884 | { | 3746 | { |
3885 | if ( (GNUNET_OK != | 3747 | if ( |
3886 | GNUNET_NETWORK_socket_setsockopt (lsocks[i], | 3748 | (GNUNET_OK != |
3887 | IPPROTO_TCP, | 3749 | GNUNET_NETWORK_socket_setsockopt (lsocks[i], |
3888 | TCP_STEALTH, | 3750 | IPPROTO_TCP, |
3889 | env->my_identity, | 3751 | TCP_STEALTH, |
3890 | sizeof (struct GNUNET_PeerIdentity))) || | 3752 | env->my_identity, |
3891 | (GNUNET_OK != | 3753 | sizeof ( |
3892 | GNUNET_NETWORK_socket_setsockopt (lsocks[i], | 3754 | struct GNUNET_PeerIdentity))) || |
3893 | IPPROTO_TCP, | 3755 | (GNUNET_OK != |
3894 | TCP_STEALTH_INTEGRITY_LEN, | 3756 | GNUNET_NETWORK_socket_setsockopt (lsocks[i], |
3895 | &len, | 3757 | IPPROTO_TCP, |
3896 | sizeof (len))) ) | 3758 | TCP_STEALTH_INTEGRITY_LEN, |
3759 | &len, | ||
3760 | sizeof (len)))) | ||
3897 | { | 3761 | { |
3898 | /* TCP STEALTH not supported by kernel */ | 3762 | /* TCP STEALTH not supported by kernel */ |
3899 | GNUNET_assert (0 == i); | 3763 | GNUNET_assert (0 == i); |
3900 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3764 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3901 | _("TCP_STEALTH not supported on this platform.\n")); | 3765 | _ ("TCP_STEALTH not supported on this platform.\n")); |
3902 | goto die; | 3766 | goto die; |
3903 | } | 3767 | } |
3904 | } | 3768 | } |
3905 | } | 3769 | } |
3906 | #else | 3770 | #else |
3907 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 3771 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
3908 | _("TCP_STEALTH not supported on this platform.\n")); | 3772 | _ ("TCP_STEALTH not supported on this platform.\n")); |
3909 | goto die; | 3773 | goto die; |
3910 | #endif | 3774 | #endif |
3911 | } | 3775 | } |
3912 | 3776 | ||
3913 | if ( (NULL != service) && | 3777 | if ((NULL != service) && |
3914 | (GNUNET_SYSERR != | 3778 | (GNUNET_SYSERR != |
3915 | (ret_s = | 3779 | (ret_s = |
3916 | get_server_addresses ("transport-tcp", | 3780 | get_server_addresses ("transport-tcp", env->cfg, &addrs, &addrlens)))) |
3917 | env->cfg, | ||
3918 | &addrs, | ||
3919 | &addrlens)))) | ||
3920 | { | 3781 | { |
3921 | for (ret = ret_s-1; ret >= 0; ret--) | 3782 | for (ret = ret_s - 1; ret >= 0; ret--) |
3922 | LOG (GNUNET_ERROR_TYPE_INFO, | 3783 | LOG (GNUNET_ERROR_TYPE_INFO, |
3923 | "Binding to address `%s'\n", | 3784 | "Binding to address `%s'\n", |
3924 | GNUNET_a2s (addrs[ret], addrlens[ret])); | 3785 | GNUNET_a2s (addrs[ret], addrlens[ret])); |
3925 | plugin->nat | 3786 | plugin->nat = GNUNET_NAT_register (env->cfg, |
3926 | = GNUNET_NAT_register (env->cfg, | 3787 | "transport-tcp", |
3927 | "transport-tcp", | 3788 | IPPROTO_TCP, |
3928 | IPPROTO_TCP, | 3789 | (unsigned int) ret_s, |
3929 | (unsigned int) ret_s, | 3790 | (const struct sockaddr **) addrs, |
3930 | (const struct sockaddr **) addrs, | 3791 | addrlens, |
3931 | addrlens, | 3792 | &tcp_nat_port_map_callback, |
3932 | &tcp_nat_port_map_callback, | 3793 | &try_connection_reversal, |
3933 | &try_connection_reversal, | 3794 | plugin); |
3934 | plugin); | 3795 | for (ret = ret_s - 1; ret >= 0; ret--) |
3935 | for (ret = ret_s -1; ret >= 0; ret--) | ||
3936 | GNUNET_free (addrs[ret]); | 3796 | GNUNET_free (addrs[ret]); |
3937 | GNUNET_free_non_null (addrs); | 3797 | GNUNET_free_non_null (addrs); |
3938 | GNUNET_free_non_null (addrlens); | 3798 | GNUNET_free_non_null (addrlens); |
@@ -3941,7 +3801,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3941 | { | 3801 | { |
3942 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 3802 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, |
3943 | "transport-tcp", | 3803 | "transport-tcp", |
3944 | IPPROTO_TCP, | 3804 | IPPROTO_TCP, |
3945 | 0, | 3805 | 0, |
3946 | NULL, | 3806 | NULL, |
3947 | NULL, | 3807 | NULL, |
@@ -3972,52 +3832,44 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
3972 | } | 3832 | } |
3973 | else | 3833 | else |
3974 | { | 3834 | { |
3975 | if (GNUNET_OK != | 3835 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (env->cfg, |
3976 | GNUNET_CONFIGURATION_get_value_time (env->cfg, | 3836 | "transport-tcp", |
3977 | "transport-tcp", | 3837 | "TIMEOUT", |
3978 | "TIMEOUT", | 3838 | &idle_timeout)) |
3979 | &idle_timeout)) | ||
3980 | { | 3839 | { |
3981 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 3840 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
3982 | "transport-tcp", | 3841 | "transport-tcp", |
3983 | "TIMEOUT"); | 3842 | "TIMEOUT"); |
3984 | goto die; | 3843 | goto die; |
3985 | } | 3844 | } |
3986 | plugin->server | 3845 | plugin->server = GNUNET_SERVER_create_with_sockets (NULL, |
3987 | = GNUNET_SERVER_create_with_sockets (NULL, | 3846 | plugin, |
3988 | plugin, | 3847 | NULL, |
3989 | NULL, | 3848 | idle_timeout, |
3990 | idle_timeout, | 3849 | GNUNET_YES); |
3991 | GNUNET_YES); | ||
3992 | } | 3850 | } |
3993 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); | 3851 | plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); |
3994 | GNUNET_memcpy (plugin->handlers, | 3852 | GNUNET_memcpy (plugin->handlers, my_handlers, sizeof (my_handlers)); |
3995 | my_handlers, | 3853 | for (i = 0; |
3996 | sizeof(my_handlers)); | 3854 | i < sizeof (my_handlers) / sizeof (struct GNUNET_SERVER_MessageHandler); |
3997 | for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++) | 3855 | i++) |
3998 | plugin->handlers[i].callback_cls = plugin; | 3856 | plugin->handlers[i].callback_cls = plugin; |
3999 | 3857 | ||
4000 | GNUNET_SERVER_add_handlers (plugin->server, | 3858 | GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); |
4001 | plugin->handlers); | 3859 | GNUNET_SERVER_connect_notify (plugin->server, &connect_notify, plugin); |
4002 | GNUNET_SERVER_connect_notify (plugin->server, | 3860 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); |
4003 | &connect_notify, | 3861 | plugin->nat_wait_conns = |
4004 | plugin); | 3862 | GNUNET_CONTAINER_multipeermap_create (16, GNUNET_YES); |
4005 | GNUNET_SERVER_disconnect_notify (plugin->server, | ||
4006 | &disconnect_notify, | ||
4007 | plugin); | ||
4008 | plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, | ||
4009 | GNUNET_YES); | ||
4010 | if (0 != bport) | 3863 | if (0 != bport) |
4011 | LOG (GNUNET_ERROR_TYPE_INFO, | 3864 | LOG (GNUNET_ERROR_TYPE_INFO, |
4012 | _("TCP transport listening on port %llu\n"), | 3865 | _ ("TCP transport listening on port %llu\n"), |
4013 | bport); | 3866 | bport); |
4014 | else | 3867 | else |
4015 | LOG (GNUNET_ERROR_TYPE_INFO, | 3868 | LOG (GNUNET_ERROR_TYPE_INFO, |
4016 | _("TCP transport not listening on any port (client only)\n")); | 3869 | _ ("TCP transport not listening on any port (client only)\n")); |
4017 | if ( (aport != bport) && | 3870 | if ((aport != bport) && (0 != bport)) |
4018 | (0 != bport) ) | ||
4019 | LOG (GNUNET_ERROR_TYPE_INFO, | 3871 | LOG (GNUNET_ERROR_TYPE_INFO, |
4020 | _("TCP transport advertises itself as being on port %llu\n"), | 3872 | _ ("TCP transport advertises itself as being on port %llu\n"), |
4021 | aport); | 3873 | aport); |
4022 | /* Initially set connections to 0 */ | 3874 | /* Initially set connections to 0 */ |
4023 | GNUNET_STATISTICS_set (plugin->env->stats, | 3875 | GNUNET_STATISTICS_set (plugin->env->stats, |
@@ -4026,7 +3878,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
4026 | GNUNET_NO); | 3878 | GNUNET_NO); |
4027 | return api; | 3879 | return api; |
4028 | 3880 | ||
4029 | die: | 3881 | die: |
4030 | if (NULL != plugin->nat) | 3882 | if (NULL != plugin->nat) |
4031 | GNUNET_NAT_unregister (plugin->nat); | 3883 | GNUNET_NAT_unregister (plugin->nat); |
4032 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); | 3884 | GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap); |
@@ -4055,11 +3907,10 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
4055 | 3907 | ||
4056 | if (NULL == plugin) | 3908 | if (NULL == plugin) |
4057 | { | 3909 | { |
4058 | GNUNET_free(api); | 3910 | GNUNET_free (api); |
4059 | return NULL ; | 3911 | return NULL; |
4060 | } | 3912 | } |
4061 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3913 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down TCP plugin\n"); |
4062 | "Shutting down TCP plugin\n"); | ||
4063 | 3914 | ||
4064 | /* Removing leftover sessions */ | 3915 | /* Removing leftover sessions */ |
4065 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, | 3916 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessionmap, |
@@ -4077,9 +3928,7 @@ libgnunet_plugin_transport_tcp_done (void *cls) | |||
4077 | plugin->ppc_dll_tail, | 3928 | plugin->ppc_dll_tail, |
4078 | cur); | 3929 | cur); |
4079 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); | 3930 | GNUNET_RESOLVER_request_cancel (cur->resolver_handle); |
4080 | cur->asc (cur->asc_cls, | 3931 | cur->asc (cur->asc_cls, NULL, GNUNET_OK); |
4081 | NULL, | ||
4082 | GNUNET_OK); | ||
4083 | GNUNET_free (cur); | 3932 | GNUNET_free (cur); |
4084 | } | 3933 | } |
4085 | 3934 | ||