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 | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 8 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-udp.c | 4 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-unix.c | 2 | ||||
-rw-r--r-- | src/transport/gnunet-helper-transport-wlan-dummy.c | 36 | ||||
-rw-r--r-- | src/transport/gnunet-transport-profiler.c | 42 | ||||
-rw-r--r-- | src/transport/gnunet-transport.c | 50 | ||||
-rw-r--r-- | src/transport/plugin_transport_smtp.c | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 1281 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 1187 | ||||
-rw-r--r-- | src/transport/plugin_transport_unix.c | 453 | ||||
-rw-r--r-- | src/transport/tcp_connection_legacy.c | 421 | ||||
-rw-r--r-- | src/transport/tcp_service_legacy.c | 458 | ||||
-rw-r--r-- | src/transport/test_plugin_hostkey | bin | 914 -> 915 bytes | |||
-rw-r--r-- | src/transport/test_quota_compliance.c | 6 | ||||
-rw-r--r-- | src/transport/test_transport_address_switch.c | 18 | ||||
-rw-r--r-- | src/transport/test_transport_api_reliability.c | 4 | ||||
-rw-r--r-- | src/transport/test_transport_api_timeout.c | 4 | ||||
-rw-r--r-- | src/transport/test_transport_blacklisting.c | 2 |
18 files changed, 1761 insertions, 2219 deletions
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 576c20278..c883166c6 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -1103,7 +1103,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | |||
1103 | char *colon; | 1103 | char *colon; |
1104 | char *cp; | 1104 | char *cp; |
1105 | 1105 | ||
1106 | if (1 == SSCANF (bindto, "%u%1s", &port, dummy)) | 1106 | if (1 == sscanf (bindto, "%u%1s", &port, dummy)) |
1107 | { | 1107 | { |
1108 | /* interpreting value as just a PORT number */ | 1108 | /* interpreting value as just a PORT number */ |
1109 | if (port > UINT16_MAX) | 1109 | if (port > UINT16_MAX) |
@@ -1146,7 +1146,7 @@ tcp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | |||
1146 | /* interpet value after colon as port */ | 1146 | /* interpet value after colon as port */ |
1147 | *colon = '\0'; | 1147 | *colon = '\0'; |
1148 | colon++; | 1148 | colon++; |
1149 | if (1 == SSCANF (colon, "%u%1s", &port, dummy)) | 1149 | if (1 == sscanf (colon, "%u%1s", &port, dummy)) |
1150 | { | 1150 | { |
1151 | /* interpreting value as just a PORT number */ | 1151 | /* interpreting value as just a PORT number */ |
1152 | if (port > UINT16_MAX) | 1152 | if (port > UINT16_MAX) |
@@ -1877,7 +1877,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
1877 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1877 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1878 | "socket(%d) failed: %s", | 1878 | "socket(%d) failed: %s", |
1879 | in->sa_family, | 1879 | in->sa_family, |
1880 | STRERROR (errno)); | 1880 | strerror (errno)); |
1881 | GNUNET_free (in); | 1881 | GNUNET_free (in); |
1882 | return GNUNET_SYSERR; | 1882 | return GNUNET_SYSERR; |
1883 | } | 1883 | } |
@@ -1886,7 +1886,7 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) | |||
1886 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1886 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1887 | "connect to `%s' failed: %s", | 1887 | "connect to `%s' failed: %s", |
1888 | address, | 1888 | address, |
1889 | STRERROR (errno)); | 1889 | strerror (errno)); |
1890 | GNUNET_NETWORK_socket_close (sock); | 1890 | GNUNET_NETWORK_socket_close (sock); |
1891 | GNUNET_free (in); | 1891 | GNUNET_free (in); |
1892 | return GNUNET_SYSERR; | 1892 | return GNUNET_SYSERR; |
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c index 68635b5bf..2c8893d75 100644 --- a/src/transport/gnunet-communicator-udp.c +++ b/src/transport/gnunet-communicator-udp.c | |||
@@ -1725,7 +1725,7 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | |||
1725 | char *colon; | 1725 | char *colon; |
1726 | char *cp; | 1726 | char *cp; |
1727 | 1727 | ||
1728 | if (1 == SSCANF (bindto, "%u%1s", &port, dummy)) | 1728 | if (1 == sscanf (bindto, "%u%1s", &port, dummy)) |
1729 | { | 1729 | { |
1730 | /* interpreting value as just a PORT number */ | 1730 | /* interpreting value as just a PORT number */ |
1731 | if (port > UINT16_MAX) | 1731 | if (port > UINT16_MAX) |
@@ -1768,7 +1768,7 @@ udp_address_to_sockaddr (const char *bindto, socklen_t *sock_len) | |||
1768 | /* interpet value after colon as port */ | 1768 | /* interpet value after colon as port */ |
1769 | *colon = '\0'; | 1769 | *colon = '\0'; |
1770 | colon++; | 1770 | colon++; |
1771 | if (1 == SSCANF (colon, "%u%1s", &port, dummy)) | 1771 | if (1 == sscanf (colon, "%u%1s", &port, dummy)) |
1772 | { | 1772 | { |
1773 | /* interpreting value as just a PORT number */ | 1773 | /* interpreting value as just a PORT number */ |
1774 | if (port > UINT16_MAX) | 1774 | if (port > UINT16_MAX) |
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c index 1d5029f20..cb1fbc230 100644 --- a/src/transport/gnunet-communicator-unix.c +++ b/src/transport/gnunet-communicator-unix.c | |||
@@ -430,7 +430,7 @@ resend: | |||
430 | GNUNET_i2s (&queue->target), | 430 | GNUNET_i2s (&queue->target), |
431 | (int) sent, | 431 | (int) sent, |
432 | (unsigned int) msg_size, | 432 | (unsigned int) msg_size, |
433 | (sent < 0) ? STRERROR (errno) : "ok"); | 433 | (sent < 0) ? strerror (errno) : "ok"); |
434 | if (-1 != sent) | 434 | if (-1 != sent) |
435 | { | 435 | { |
436 | GNUNET_STATISTICS_update (stats, | 436 | GNUNET_STATISTICS_update (stats, |
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c index dbd9014cb..c7ed1b903 100644 --- a/src/transport/gnunet-helper-transport-wlan-dummy.c +++ b/src/transport/gnunet-helper-transport-wlan-dummy.c | |||
@@ -140,13 +140,13 @@ stdin_send (void *cls, | |||
140 | if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || | 140 | if ( (GNUNET_MESSAGE_TYPE_WLAN_DATA_TO_HELPER != ntohs (hdr->type)) || |
141 | (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) | 141 | (sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage) > sendsize) ) |
142 | { | 142 | { |
143 | FPRINTF (stderr, "%s", "Received malformed message\n"); | 143 | fprintf (stderr, "%s", "Received malformed message\n"); |
144 | exit (1); | 144 | exit (1); |
145 | } | 145 | } |
146 | payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); | 146 | payload_size = sendsize - sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage); |
147 | if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) | 147 | if ((payload_size + sizeof (struct GNUNET_TRANSPORT_WLAN_RadiotapReceiveMessage) + write_pout->size) > MAXLINE * 2) |
148 | { | 148 | { |
149 | FPRINTF (stderr, "%s", "Packet too big for buffer\n"); | 149 | fprintf (stderr, "%s", "Packet too big for buffer\n"); |
150 | exit (1); | 150 | exit (1); |
151 | } | 151 | } |
152 | memset (&newheader, 0, sizeof (newheader)); | 152 | memset (&newheader, 0, sizeof (newheader)); |
@@ -184,7 +184,7 @@ file_in_send (void *cls, | |||
184 | sendsize = ntohs (hdr->size); | 184 | sendsize = ntohs (hdr->size); |
185 | if ((sendsize + write_std->size) > MAXLINE * 2) | 185 | if ((sendsize + write_std->size) > MAXLINE * 2) |
186 | { | 186 | { |
187 | FPRINTF (stderr, "%s", "Packet too big for buffer\n"); | 187 | fprintf (stderr, "%s", "Packet too big for buffer\n"); |
188 | exit (1); | 188 | exit (1); |
189 | } | 189 | } |
190 | GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize); | 190 | GNUNET_memcpy (write_std->buf + write_std->size, hdr, sendsize); |
@@ -227,7 +227,7 @@ main (int argc, char *argv[]) | |||
227 | if ( (2 != argc) || | 227 | if ( (2 != argc) || |
228 | ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) | 228 | ((0 != strcmp (argv[1], "1")) && (0 != strcmp (argv[1], "2"))) ) |
229 | { | 229 | { |
230 | FPRINTF (stderr, | 230 | fprintf (stderr, |
231 | "%s", | 231 | "%s", |
232 | "This program must be started with the operating mode (1 or 2) as the only argument.\n"); | 232 | "This program must be started with the operating mode (1 or 2) as the only argument.\n"); |
233 | return 1; | 233 | return 1; |
@@ -238,7 +238,7 @@ main (int argc, char *argv[]) | |||
238 | if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || | 238 | if ( (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE1)) || |
239 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) | 239 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (FIFO_FILE2)) ) |
240 | { | 240 | { |
241 | FPRINTF (stderr, | 241 | fprintf (stderr, |
242 | "Failed to create directory for file `%s'\n", | 242 | "Failed to create directory for file `%s'\n", |
243 | FIFO_FILE1); | 243 | FIFO_FILE1); |
244 | return 1; | 244 | return 1; |
@@ -249,7 +249,7 @@ main (int argc, char *argv[]) | |||
249 | { | 249 | { |
250 | erg = mkfifo (FIFO_FILE1, 0666); | 250 | erg = mkfifo (FIFO_FILE1, 0666); |
251 | if ( (0 != erg) && (EEXIST != errno) ) | 251 | if ( (0 != erg) && (EEXIST != errno) ) |
252 | FPRINTF (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, | 252 | fprintf (stderr, "Error in mkfifo(%s): %s\n", FIFO_FILE1, |
253 | strerror (errno)); | 253 | strerror (errno)); |
254 | } | 254 | } |
255 | } | 255 | } |
@@ -259,7 +259,7 @@ main (int argc, char *argv[]) | |||
259 | { | 259 | { |
260 | GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); | 260 | GNUNET_break (0 == (erg = mkfifo (FIFO_FILE2, 0666))); |
261 | if ( (0 != erg) && (EEXIST != errno) ) | 261 | if ( (0 != erg) && (EEXIST != errno) ) |
262 | FPRINTF (stderr, | 262 | fprintf (stderr, |
263 | "Error in mkfifo(%s): %s\n", | 263 | "Error in mkfifo(%s): %s\n", |
264 | FIFO_FILE2, | 264 | FIFO_FILE2, |
265 | strerror (errno)); | 265 | strerror (errno)); |
@@ -272,7 +272,7 @@ main (int argc, char *argv[]) | |||
272 | fpin = fopen (FIFO_FILE1, "r"); | 272 | fpin = fopen (FIFO_FILE1, "r"); |
273 | if (NULL == fpin) | 273 | if (NULL == fpin) |
274 | { | 274 | { |
275 | FPRINTF (stderr, | 275 | fprintf (stderr, |
276 | "fopen of read FIFO_FILE1 failed: %s\n", | 276 | "fopen of read FIFO_FILE1 failed: %s\n", |
277 | STRERROR (errno)); | 277 | STRERROR (errno)); |
278 | goto end; | 278 | goto end; |
@@ -284,7 +284,7 @@ main (int argc, char *argv[]) | |||
284 | } | 284 | } |
285 | if (NULL == fpout) | 285 | if (NULL == fpout) |
286 | { | 286 | { |
287 | FPRINTF (stderr, | 287 | fprintf (stderr, |
288 | "fopen of write FIFO_FILE2 failed: %s\n", | 288 | "fopen of write FIFO_FILE2 failed: %s\n", |
289 | STRERROR (errno)); | 289 | STRERROR (errno)); |
290 | goto end; | 290 | goto end; |
@@ -300,7 +300,7 @@ main (int argc, char *argv[]) | |||
300 | } | 300 | } |
301 | if (NULL == fpout) | 301 | if (NULL == fpout) |
302 | { | 302 | { |
303 | FPRINTF (stderr, | 303 | fprintf (stderr, |
304 | "fopen of write FIFO_FILE1 failed: %s\n", | 304 | "fopen of write FIFO_FILE1 failed: %s\n", |
305 | STRERROR (errno)); | 305 | STRERROR (errno)); |
306 | goto end; | 306 | goto end; |
@@ -308,7 +308,7 @@ main (int argc, char *argv[]) | |||
308 | fpin = fopen (FIFO_FILE2, "r"); | 308 | fpin = fopen (FIFO_FILE2, "r"); |
309 | if (NULL == fpin) | 309 | if (NULL == fpin) |
310 | { | 310 | { |
311 | FPRINTF (stderr, | 311 | fprintf (stderr, |
312 | "fopen of read FIFO_FILE2 failed: %s\n", | 312 | "fopen of read FIFO_FILE2 failed: %s\n", |
313 | STRERROR (errno)); | 313 | STRERROR (errno)); |
314 | goto end; | 314 | goto end; |
@@ -319,7 +319,7 @@ main (int argc, char *argv[]) | |||
319 | GNUNET_assert (fpin >= 0); | 319 | GNUNET_assert (fpin >= 0); |
320 | if (fdpin >= FD_SETSIZE) | 320 | if (fdpin >= FD_SETSIZE) |
321 | { | 321 | { |
322 | FPRINTF (stderr, | 322 | fprintf (stderr, |
323 | "File fdpin number too large (%d > %u)\n", | 323 | "File fdpin number too large (%d > %u)\n", |
324 | fdpin, | 324 | fdpin, |
325 | (unsigned int) FD_SETSIZE); | 325 | (unsigned int) FD_SETSIZE); |
@@ -331,7 +331,7 @@ main (int argc, char *argv[]) | |||
331 | 331 | ||
332 | if (fdpout >= FD_SETSIZE) | 332 | if (fdpout >= FD_SETSIZE) |
333 | { | 333 | { |
334 | FPRINTF (stderr, | 334 | fprintf (stderr, |
335 | "File fdpout number too large (%d > %u)\n", | 335 | "File fdpout number too large (%d > %u)\n", |
336 | fdpout, | 336 | fdpout, |
337 | (unsigned int) FD_SETSIZE); | 337 | (unsigned int) FD_SETSIZE); |
@@ -395,7 +395,7 @@ main (int argc, char *argv[]) | |||
395 | continue; | 395 | continue; |
396 | if (0 > retval) | 396 | if (0 > retval) |
397 | { | 397 | { |
398 | FPRINTF (stderr, "select failed: %s\n", STRERROR (errno)); | 398 | fprintf (stderr, "select failed: %s\n", STRERROR (errno)); |
399 | closeprog = 1; | 399 | closeprog = 1; |
400 | break; | 400 | break; |
401 | } | 401 | } |
@@ -408,7 +408,7 @@ main (int argc, char *argv[]) | |||
408 | if (0 > ret) | 408 | if (0 > ret) |
409 | { | 409 | { |
410 | closeprog = 1; | 410 | closeprog = 1; |
411 | FPRINTF (stderr, "Write ERROR to STDOUT_FILENO: %s\n", | 411 | fprintf (stderr, "Write ERROR to STDOUT_FILENO: %s\n", |
412 | STRERROR (errno)); | 412 | STRERROR (errno)); |
413 | break; | 413 | break; |
414 | } | 414 | } |
@@ -433,7 +433,7 @@ main (int argc, char *argv[]) | |||
433 | if (0 > ret) | 433 | if (0 > ret) |
434 | { | 434 | { |
435 | closeprog = 1; | 435 | closeprog = 1; |
436 | FPRINTF (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); | 436 | fprintf (stderr, "Write ERROR to fdpout failed: %s\n", STRERROR (errno)); |
437 | } | 437 | } |
438 | else | 438 | else |
439 | { | 439 | { |
@@ -454,7 +454,7 @@ main (int argc, char *argv[]) | |||
454 | if (0 > readsize) | 454 | if (0 > readsize) |
455 | { | 455 | { |
456 | closeprog = 1; | 456 | closeprog = 1; |
457 | FPRINTF (stderr, "Error reading from STDIN_FILENO: %s\n", | 457 | fprintf (stderr, "Error reading from STDIN_FILENO: %s\n", |
458 | STRERROR (errno)); | 458 | STRERROR (errno)); |
459 | } | 459 | } |
460 | else if (0 < readsize) | 460 | else if (0 < readsize) |
@@ -477,7 +477,7 @@ main (int argc, char *argv[]) | |||
477 | if (0 > readsize) | 477 | if (0 > readsize) |
478 | { | 478 | { |
479 | closeprog = 1; | 479 | closeprog = 1; |
480 | FPRINTF (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); | 480 | fprintf (stderr, "Error reading from fdpin: %s\n", STRERROR (errno)); |
481 | break; | 481 | break; |
482 | } | 482 | } |
483 | else if (0 < readsize) | 483 | else if (0 < readsize) |
diff --git a/src/transport/gnunet-transport-profiler.c b/src/transport/gnunet-transport-profiler.c index 89f5b4108..d4f8589d1 100644 --- a/src/transport/gnunet-transport-profiler.c +++ b/src/transport/gnunet-transport-profiler.c | |||
@@ -195,7 +195,7 @@ shutdown_task (void *cls) | |||
195 | } | 195 | } |
196 | 196 | ||
197 | if (verbosity > 0) | 197 | if (verbosity > 0) |
198 | FPRINTF (stdout, "\n"); | 198 | fprintf (stdout, "\n"); |
199 | 199 | ||
200 | /* Output format: | 200 | /* Output format: |
201 | * All time values in ms | 201 | * All time values in ms |
@@ -216,7 +216,7 @@ shutdown_task (void *cls) | |||
216 | icur->rate = ((benchmark_count * benchmark_size) / 1024) / | 216 | icur->rate = ((benchmark_count * benchmark_size) / 1024) / |
217 | ((float) icur->dur.rel_value_us / (1000 * 1000)); | 217 | ((float) icur->dur.rel_value_us / (1000 * 1000)); |
218 | if (verbosity > 0) | 218 | if (verbosity > 0) |
219 | FPRINTF (stdout, | 219 | fprintf (stdout, |
220 | _ ("%llu B in %llu ms == %.2f KB/s!\n"), | 220 | _ ("%llu B in %llu ms == %.2f KB/s!\n"), |
221 | ((long long unsigned int) benchmark_count * benchmark_size), | 221 | ((long long unsigned int) benchmark_count * benchmark_size), |
222 | ((long long unsigned int) icur->dur.rel_value_us / 1000), | 222 | ((long long unsigned int) icur->dur.rel_value_us / 1000), |
@@ -252,7 +252,7 @@ shutdown_task (void *cls) | |||
252 | stddev_duration = sqrtf (stddev_duration); | 252 | stddev_duration = sqrtf (stddev_duration); |
253 | 253 | ||
254 | /* Output */ | 254 | /* Output */ |
255 | FPRINTF (stdout, | 255 | fprintf (stdout, |
256 | "%u;%u;%llu;%llu;%.2f;%.2f", | 256 | "%u;%u;%llu;%llu;%.2f;%.2f", |
257 | benchmark_count, | 257 | benchmark_count, |
258 | benchmark_size, | 258 | benchmark_size, |
@@ -267,7 +267,7 @@ shutdown_task (void *cls) | |||
267 | inext = icur->next; | 267 | inext = icur->next; |
268 | GNUNET_CONTAINER_DLL_remove (ihead, itail, icur); | 268 | GNUNET_CONTAINER_DLL_remove (ihead, itail, icur); |
269 | 269 | ||
270 | FPRINTF (stdout, | 270 | fprintf (stdout, |
271 | ";%llu;%.2f", | 271 | ";%llu;%.2f", |
272 | (long long unsigned int) (icur->dur.rel_value_us / 1000), | 272 | (long long unsigned int) (icur->dur.rel_value_us / 1000), |
273 | icur->rate); | 273 | icur->rate); |
@@ -279,14 +279,14 @@ shutdown_task (void *cls) | |||
279 | if (benchmark_receive) | 279 | if (benchmark_receive) |
280 | { | 280 | { |
281 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 281 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
282 | FPRINTF (stdout, | 282 | fprintf (stdout, |
283 | "Received %llu bytes/s (%llu bytes in %s)\n", | 283 | "Received %llu bytes/s (%llu bytes in %s)\n", |
284 | 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), | 284 | 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), |
285 | traffic_received, | 285 | traffic_received, |
286 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); | 286 | GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_YES)); |
287 | } | 287 | } |
288 | #endif | 288 | #endif |
289 | FPRINTF (stdout, "\n"); | 289 | fprintf (stdout, "\n"); |
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
@@ -326,7 +326,7 @@ send_msg (void *cls) | |||
326 | } | 326 | } |
327 | GNUNET_MQ_send (mq, env); | 327 | GNUNET_MQ_send (mq, env); |
328 | if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) | 328 | if ((verbosity > 0) && (0 == itail->msgs_sent % 10)) |
329 | FPRINTF (stdout, "."); | 329 | fprintf (stdout, "."); |
330 | } | 330 | } |
331 | 331 | ||
332 | 332 | ||
@@ -343,7 +343,7 @@ iteration_start () | |||
343 | GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); | 343 | GNUNET_CONTAINER_DLL_insert_tail (ihead, itail, icur); |
344 | icur->start = GNUNET_TIME_absolute_get (); | 344 | icur->start = GNUNET_TIME_absolute_get (); |
345 | if (verbosity > 0) | 345 | if (verbosity > 0) |
346 | FPRINTF ( | 346 | fprintf ( |
347 | stdout, | 347 | stdout, |
348 | "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", | 348 | "\nStarting benchmark, starting to send %u messages in %u byte blocks\n", |
349 | benchmark_count, | 349 | benchmark_count, |
@@ -385,12 +385,12 @@ notify_connect (void *cls, | |||
385 | { | 385 | { |
386 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) | 386 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
387 | { | 387 | { |
388 | FPRINTF (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid)); | 388 | fprintf (stdout, "Connected to different peer `%s'\n", GNUNET_i2s (&pid)); |
389 | return NULL; | 389 | return NULL; |
390 | } | 390 | } |
391 | 391 | ||
392 | if (verbosity > 0) | 392 | if (verbosity > 0) |
393 | FPRINTF (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid)); | 393 | fprintf (stdout, "Successfully connected to `%s'\n", GNUNET_i2s (&pid)); |
394 | mq = m; | 394 | mq = m; |
395 | iteration_start (); | 395 | iteration_start (); |
396 | return NULL; | 396 | return NULL; |
@@ -415,7 +415,7 @@ notify_disconnect (void *cls, | |||
415 | mq = NULL; | 415 | mq = NULL; |
416 | if (GNUNET_YES == benchmark_running) | 416 | if (GNUNET_YES == benchmark_running) |
417 | { | 417 | { |
418 | FPRINTF (stdout, | 418 | fprintf (stdout, |
419 | "Disconnected from peer `%s' while benchmarking\n", | 419 | "Disconnected from peer `%s' while benchmarking\n", |
420 | GNUNET_i2s (&pid)); | 420 | GNUNET_i2s (&pid)); |
421 | return; | 421 | return; |
@@ -449,7 +449,7 @@ handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) | |||
449 | if (! benchmark_receive) | 449 | if (! benchmark_receive) |
450 | return; | 450 | return; |
451 | if (verbosity > 0) | 451 | if (verbosity > 0) |
452 | FPRINTF (stdout, | 452 | fprintf (stdout, |
453 | "Received %u bytes\n", | 453 | "Received %u bytes\n", |
454 | (unsigned int) ntohs (message->size)); | 454 | (unsigned int) ntohs (message->size)); |
455 | } | 455 | } |
@@ -461,7 +461,7 @@ blacklist_cb (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
461 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) | 461 | if (0 != memcmp (&pid, peer, sizeof (struct GNUNET_PeerIdentity))) |
462 | { | 462 | { |
463 | if (verbosity > 0) | 463 | if (verbosity > 0) |
464 | FPRINTF (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer)); | 464 | fprintf (stdout, "Denying connection to `%s'\n", GNUNET_i2s (peer)); |
465 | return GNUNET_SYSERR; | 465 | return GNUNET_SYSERR; |
466 | } | 466 | } |
467 | return GNUNET_OK; | 467 | return GNUNET_OK; |
@@ -494,26 +494,26 @@ run (void *cls, | |||
494 | ret = 1; | 494 | ret = 1; |
495 | if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) | 495 | if (GNUNET_MAX_MESSAGE_SIZE <= benchmark_size) |
496 | { | 496 | { |
497 | FPRINTF (stderr, "Message size too big!\n"); | 497 | fprintf (stderr, "Message size too big!\n"); |
498 | return; | 498 | return; |
499 | } | 499 | } |
500 | 500 | ||
501 | if (NULL == cpid) | 501 | if (NULL == cpid) |
502 | { | 502 | { |
503 | FPRINTF (stderr, "No peer identity given\n"); | 503 | fprintf (stderr, "No peer identity given\n"); |
504 | return; | 504 | return; |
505 | } | 505 | } |
506 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, | 506 | if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (cpid, |
507 | strlen (cpid), | 507 | strlen (cpid), |
508 | &pid.public_key)) | 508 | &pid.public_key)) |
509 | { | 509 | { |
510 | FPRINTF (stderr, "Failed to parse peer identity `%s'\n", cpid); | 510 | fprintf (stderr, "Failed to parse peer identity `%s'\n", cpid); |
511 | return; | 511 | return; |
512 | } | 512 | } |
513 | if (1 == benchmark_send) | 513 | if (1 == benchmark_send) |
514 | { | 514 | { |
515 | if (verbosity > 0) | 515 | if (verbosity > 0) |
516 | FPRINTF (stderr, | 516 | fprintf (stderr, |
517 | "Trying to send %u messages with size %u to peer `%s'\n", | 517 | "Trying to send %u messages with size %u to peer `%s'\n", |
518 | benchmark_count, | 518 | benchmark_count, |
519 | benchmark_size, | 519 | benchmark_size, |
@@ -521,20 +521,20 @@ run (void *cls, | |||
521 | } | 521 | } |
522 | else if (1 == benchmark_receive) | 522 | else if (1 == benchmark_receive) |
523 | { | 523 | { |
524 | FPRINTF (stderr, | 524 | fprintf (stderr, |
525 | "Trying to receive messages from peer `%s'\n", | 525 | "Trying to receive messages from peer `%s'\n", |
526 | GNUNET_i2s (&pid)); | 526 | GNUNET_i2s (&pid)); |
527 | } | 527 | } |
528 | else | 528 | else |
529 | { | 529 | { |
530 | FPRINTF (stderr, "No operation given\n"); | 530 | fprintf (stderr, "No operation given\n"); |
531 | return; | 531 | return; |
532 | } | 532 | } |
533 | 533 | ||
534 | ats = GNUNET_ATS_connectivity_init (cfg); | 534 | ats = GNUNET_ATS_connectivity_init (cfg); |
535 | if (NULL == ats) | 535 | if (NULL == ats) |
536 | { | 536 | { |
537 | FPRINTF (stderr, "Failed to connect to ATS service\n"); | 537 | fprintf (stderr, "Failed to connect to ATS service\n"); |
538 | ret = 1; | 538 | ret = 1; |
539 | return; | 539 | return; |
540 | } | 540 | } |
@@ -548,7 +548,7 @@ run (void *cls, | |||
548 | NULL); | 548 | NULL); |
549 | if (NULL == handle) | 549 | if (NULL == handle) |
550 | { | 550 | { |
551 | FPRINTF (stderr, "Failed to connect to transport service\n"); | 551 | fprintf (stderr, "Failed to connect to transport service\n"); |
552 | GNUNET_ATS_connectivity_done (ats); | 552 | GNUNET_ATS_connectivity_done (ats); |
553 | ats = NULL; | 553 | ats = NULL; |
554 | ret = 1; | 554 | ret = 1; |
diff --git a/src/transport/gnunet-transport.c b/src/transport/gnunet-transport.c index 36c8fc451..ebc3f402d 100644 --- a/src/transport/gnunet-transport.c +++ b/src/transport/gnunet-transport.c | |||
@@ -402,7 +402,7 @@ shutdown_task (void *cls) | |||
402 | if (benchmark_send) | 402 | if (benchmark_send) |
403 | { | 403 | { |
404 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 404 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
405 | FPRINTF (stdout, | 405 | fprintf (stdout, |
406 | _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"), | 406 | _ ("Transmitted %llu bytes/s (%llu bytes in %s)\n"), |
407 | 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), | 407 | 1000LL * 1000LL * traffic_sent / (1 + duration.rel_value_us), |
408 | traffic_sent, | 408 | traffic_sent, |
@@ -411,7 +411,7 @@ shutdown_task (void *cls) | |||
411 | if (benchmark_receive) | 411 | if (benchmark_receive) |
412 | { | 412 | { |
413 | duration = GNUNET_TIME_absolute_get_duration (start_time); | 413 | duration = GNUNET_TIME_absolute_get_duration (start_time); |
414 | FPRINTF (stdout, | 414 | fprintf (stdout, |
415 | _ ("Received %llu bytes/s (%llu bytes in %s)\n"), | 415 | _ ("Received %llu bytes/s (%llu bytes in %s)\n"), |
416 | 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), | 416 | 1000LL * 1000LL * traffic_received / (1 + duration.rel_value_us), |
417 | traffic_received, | 417 | traffic_received, |
@@ -451,7 +451,7 @@ operation_timeout (void *cls) | |||
451 | op_timeout = NULL; | 451 | op_timeout = NULL; |
452 | if ((benchmark_send) || (benchmark_receive)) | 452 | if ((benchmark_send) || (benchmark_receive)) |
453 | { | 453 | { |
454 | FPRINTF (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); | 454 | fprintf (stdout, _ ("Failed to connect to `%s'\n"), GNUNET_i2s_full (&pid)); |
455 | GNUNET_SCHEDULER_shutdown (); | 455 | GNUNET_SCHEDULER_shutdown (); |
456 | ret = 1; | 456 | ret = 1; |
457 | return; | 457 | return; |
@@ -462,7 +462,7 @@ operation_timeout (void *cls) | |||
462 | while (NULL != (cur = next)) | 462 | while (NULL != (cur = next)) |
463 | { | 463 | { |
464 | next = cur->next; | 464 | next = cur->next; |
465 | FPRINTF (stdout, | 465 | fprintf (stdout, |
466 | _ ("Failed to resolve address for peer `%s'\n"), | 466 | _ ("Failed to resolve address for peer `%s'\n"), |
467 | GNUNET_i2s (&cur->addrcp->peer)); | 467 | GNUNET_i2s (&cur->addrcp->peer)); |
468 | 468 | ||
@@ -472,7 +472,7 @@ operation_timeout (void *cls) | |||
472 | GNUNET_free (cur->addrcp); | 472 | GNUNET_free (cur->addrcp); |
473 | GNUNET_free (cur); | 473 | GNUNET_free (cur); |
474 | } | 474 | } |
475 | FPRINTF (stdout, | 475 | fprintf (stdout, |
476 | "%s", | 476 | "%s", |
477 | _ ("Failed to list connections, timeout occurred\n")); | 477 | _ ("Failed to list connections, timeout occurred\n")); |
478 | GNUNET_SCHEDULER_shutdown (); | 478 | GNUNET_SCHEDULER_shutdown (); |
@@ -500,7 +500,7 @@ do_send (void *cls) | |||
500 | traffic_sent += BLOCKSIZE * 1024; | 500 | traffic_sent += BLOCKSIZE * 1024; |
501 | GNUNET_MQ_notify_sent (env, &do_send, mq); | 501 | GNUNET_MQ_notify_sent (env, &do_send, mq); |
502 | if (verbosity > 0) | 502 | if (verbosity > 0) |
503 | FPRINTF (stdout, | 503 | fprintf (stdout, |
504 | _ ("Transmitting %u bytes\n"), | 504 | _ ("Transmitting %u bytes\n"), |
505 | (unsigned int) BLOCKSIZE * 1024); | 505 | (unsigned int) BLOCKSIZE * 1024); |
506 | GNUNET_MQ_send (mq, env); | 506 | GNUNET_MQ_send (mq, env); |
@@ -531,7 +531,7 @@ notify_connect (void *cls, | |||
531 | op_timeout = NULL; | 531 | op_timeout = NULL; |
532 | } | 532 | } |
533 | if (verbosity > 0) | 533 | if (verbosity > 0) |
534 | FPRINTF ( | 534 | fprintf ( |
535 | stdout, | 535 | stdout, |
536 | _ ( | 536 | _ ( |
537 | "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), | 537 | "Successfully connected to `%s', starting to send benchmark data in %u Kb blocks\n"), |
@@ -562,7 +562,7 @@ notify_disconnect (void *cls, | |||
562 | return; /* not about target peer */ | 562 | return; /* not about target peer */ |
563 | if (! benchmark_send) | 563 | if (! benchmark_send) |
564 | return; /* not transmitting */ | 564 | return; /* not transmitting */ |
565 | FPRINTF (stdout, | 565 | fprintf (stdout, |
566 | _ ("Disconnected from peer `%s' while benchmarking\n"), | 566 | _ ("Disconnected from peer `%s' while benchmarking\n"), |
567 | GNUNET_i2s (&pid)); | 567 | GNUNET_i2s (&pid)); |
568 | } | 568 | } |
@@ -586,7 +586,7 @@ monitor_notify_connect (void *cls, | |||
586 | const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); | 586 | const char *now_str = GNUNET_STRINGS_absolute_time_to_string (now); |
587 | 587 | ||
588 | monitor_connect_counter++; | 588 | monitor_connect_counter++; |
589 | FPRINTF (stdout, | 589 | fprintf (stdout, |
590 | _ ("%24s: %-17s %4s (%u connections in total)\n"), | 590 | _ ("%24s: %-17s %4s (%u connections in total)\n"), |
591 | now_str, | 591 | now_str, |
592 | _ ("Connected to"), | 592 | _ ("Connected to"), |
@@ -615,7 +615,7 @@ monitor_notify_disconnect (void *cls, | |||
615 | GNUNET_assert (monitor_connect_counter > 0); | 615 | GNUNET_assert (monitor_connect_counter > 0); |
616 | monitor_connect_counter--; | 616 | monitor_connect_counter--; |
617 | 617 | ||
618 | FPRINTF (stdout, | 618 | fprintf (stdout, |
619 | _ ("%24s: %-17s %4s (%u connections in total)\n"), | 619 | _ ("%24s: %-17s %4s (%u connections in total)\n"), |
620 | now_str, | 620 | now_str, |
621 | _ ("Disconnected from"), | 621 | _ ("Disconnected from"), |
@@ -650,7 +650,7 @@ handle_dummy (void *cls, const struct GNUNET_MessageHeader *message) | |||
650 | if (! benchmark_receive) | 650 | if (! benchmark_receive) |
651 | return; | 651 | return; |
652 | if (verbosity > 0) | 652 | if (verbosity > 0) |
653 | FPRINTF (stdout, | 653 | fprintf (stdout, |
654 | _ ("Received %u bytes\n"), | 654 | _ ("Received %u bytes\n"), |
655 | (unsigned int) ntohs (message->size)); | 655 | (unsigned int) ntohs (message->size)); |
656 | if (0 == traffic_received) | 656 | if (0 == traffic_received) |
@@ -686,7 +686,7 @@ print_info (const struct GNUNET_PeerIdentity *id, | |||
686 | if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || | 686 | if (((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) || |
687 | (GNUNET_YES == monitor_connections)) | 687 | (GNUNET_YES == monitor_connections)) |
688 | { | 688 | { |
689 | FPRINTF (stdout, | 689 | fprintf (stdout, |
690 | _ ("Peer `%s': %s %s in state `%s' until %s\n"), | 690 | _ ("Peer `%s': %s %s in state `%s' until %s\n"), |
691 | GNUNET_i2s (id), | 691 | GNUNET_i2s (id), |
692 | (NULL == transport) ? "<none>" : transport, | 692 | (NULL == transport) ? "<none>" : transport, |
@@ -698,7 +698,7 @@ print_info (const struct GNUNET_PeerIdentity *id, | |||
698 | (GNUNET_TRANSPORT_is_connected (state))) | 698 | (GNUNET_TRANSPORT_is_connected (state))) |
699 | { | 699 | { |
700 | /* Only connected peers, skip state */ | 700 | /* Only connected peers, skip state */ |
701 | FPRINTF (stdout, | 701 | fprintf (stdout, |
702 | _ ("Peer `%s': %s %s\n"), | 702 | _ ("Peer `%s': %s %s\n"), |
703 | GNUNET_i2s (id), | 703 | GNUNET_i2s (id), |
704 | transport, | 704 | transport, |
@@ -732,7 +732,7 @@ process_peer_string (void *cls, const char *address, int res) | |||
732 | { | 732 | { |
733 | if (GNUNET_SYSERR == res) | 733 | if (GNUNET_SYSERR == res) |
734 | { | 734 | { |
735 | FPRINTF ( | 735 | fprintf ( |
736 | stderr, | 736 | stderr, |
737 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", | 737 | "Failed to convert address for peer `%s' plugin `%s' length %u to string \n", |
738 | GNUNET_i2s (&rc->addrcp->peer), | 738 | GNUNET_i2s (&rc->addrcp->peer), |
@@ -1094,7 +1094,7 @@ process_peer_monitoring_cb (void *cls, | |||
1094 | 1094 | ||
1095 | if (NULL == peer) | 1095 | if (NULL == peer) |
1096 | { | 1096 | { |
1097 | FPRINTF (stdout, | 1097 | fprintf (stdout, |
1098 | "%s", | 1098 | "%s", |
1099 | _ ( | 1099 | _ ( |
1100 | "Monitor disconnected from transport service. Reconnecting.\n")); | 1100 | "Monitor disconnected from transport service. Reconnecting.\n")); |
@@ -1189,7 +1189,7 @@ run (void *cls, | |||
1189 | 1189 | ||
1190 | if (1 < counter) | 1190 | if (1 < counter) |
1191 | { | 1191 | { |
1192 | FPRINTF ( | 1192 | fprintf ( |
1193 | stderr, | 1193 | stderr, |
1194 | _ ( | 1194 | _ ( |
1195 | "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), | 1195 | "Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s %s\n"), |
@@ -1204,7 +1204,7 @@ run (void *cls, | |||
1204 | } | 1204 | } |
1205 | if (0 == counter) | 1205 | if (0 == counter) |
1206 | { | 1206 | { |
1207 | FPRINTF ( | 1207 | fprintf ( |
1208 | stderr, | 1208 | stderr, |
1209 | _ ( | 1209 | _ ( |
1210 | "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), | 1210 | "No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s, %s\n"), |
@@ -1222,7 +1222,7 @@ run (void *cls, | |||
1222 | { | 1222 | { |
1223 | if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) | 1223 | if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) |
1224 | { | 1224 | { |
1225 | FPRINTF (stderr, | 1225 | fprintf (stderr, |
1226 | _ ("Option `%s' makes no sense without option `%s'.\n"), | 1226 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
1227 | "-D", | 1227 | "-D", |
1228 | "-p"); | 1228 | "-p"); |
@@ -1232,14 +1232,14 @@ run (void *cls, | |||
1232 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); | 1232 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_cb, NULL); |
1233 | if (NULL == blacklist) | 1233 | if (NULL == blacklist) |
1234 | { | 1234 | { |
1235 | FPRINTF (stderr, | 1235 | fprintf (stderr, |
1236 | "%s", | 1236 | "%s", |
1237 | _ ( | 1237 | _ ( |
1238 | "Failed to connect to transport service for disconnection\n")); | 1238 | "Failed to connect to transport service for disconnection\n")); |
1239 | ret = 1; | 1239 | ret = 1; |
1240 | return; | 1240 | return; |
1241 | } | 1241 | } |
1242 | FPRINTF (stdout, | 1242 | fprintf (stdout, |
1243 | "%s", | 1243 | "%s", |
1244 | _ ("Blacklisting request in place, stop with CTRL-C\n")); | 1244 | _ ("Blacklisting request in place, stop with CTRL-C\n")); |
1245 | } | 1245 | } |
@@ -1247,7 +1247,7 @@ run (void *cls, | |||
1247 | { | 1247 | { |
1248 | if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) | 1248 | if (0 == memcmp (&zero_pid, &pid, sizeof (pid))) |
1249 | { | 1249 | { |
1250 | FPRINTF (stderr, | 1250 | fprintf (stderr, |
1251 | _ ("Option `%s' makes no sense without option `%s'.\n"), | 1251 | _ ("Option `%s' makes no sense without option `%s'.\n"), |
1252 | "-s", | 1252 | "-s", |
1253 | "-p"); | 1253 | "-p"); |
@@ -1263,7 +1263,7 @@ run (void *cls, | |||
1263 | NULL); | 1263 | NULL); |
1264 | if (NULL == handle) | 1264 | if (NULL == handle) |
1265 | { | 1265 | { |
1266 | FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); | 1266 | fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); |
1267 | ret = 1; | 1267 | ret = 1; |
1268 | return; | 1268 | return; |
1269 | } | 1269 | } |
@@ -1289,12 +1289,12 @@ run (void *cls, | |||
1289 | NULL); | 1289 | NULL); |
1290 | if (NULL == handle) | 1290 | if (NULL == handle) |
1291 | { | 1291 | { |
1292 | FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); | 1292 | fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); |
1293 | ret = 1; | 1293 | ret = 1; |
1294 | return; | 1294 | return; |
1295 | } | 1295 | } |
1296 | if (verbosity > 0) | 1296 | if (verbosity > 0) |
1297 | FPRINTF (stdout, "%s", _ ("Starting to receive benchmark data\n")); | 1297 | fprintf (stdout, "%s", _ ("Starting to receive benchmark data\n")); |
1298 | start_time = GNUNET_TIME_absolute_get (); | 1298 | start_time = GNUNET_TIME_absolute_get (); |
1299 | } | 1299 | } |
1300 | else if (iterate_connections) /* -i: List information about peers once */ | 1300 | else if (iterate_connections) /* -i: List information about peers once */ |
@@ -1335,7 +1335,7 @@ run (void *cls, | |||
1335 | NULL); | 1335 | NULL); |
1336 | if (NULL == handle) | 1336 | if (NULL == handle) |
1337 | { | 1337 | { |
1338 | FPRINTF (stderr, "%s", _ ("Failed to connect to transport service\n")); | 1338 | fprintf (stderr, "%s", _ ("Failed to connect to transport service\n")); |
1339 | ret = 1; | 1339 | ret = 1; |
1340 | return; | 1340 | return; |
1341 | } | 1341 | } |
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c index 705c91b85..1c61f07d7 100644 --- a/src/transport/plugin_transport_smtp.c +++ b/src/transport/plugin_transport_smtp.c | |||
@@ -667,7 +667,7 @@ inittransport_smtp (struct GNUNET_CoreAPIForTransport * core) | |||
667 | stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); | 667 | stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); |
668 | } | 668 | } |
669 | GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", &pipename); | 669 | GNUNET_GC_get_configuration_value_filename (core_api->cfg, "SMTP", "PIPE", &pipename); |
670 | UNLINK (pipename); | 670 | unlink (pipename); |
671 | if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) | 671 | if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) |
672 | { | 672 | { |
673 | GNUNET_GE_LOG_STRERROR (ectx, | 673 | GNUNET_GE_LOG_STRERROR (ectx, |
@@ -722,7 +722,7 @@ donetransport_smtp () | |||
722 | } | 722 | } |
723 | GNUNET_mutex_destroy (lock); | 723 | GNUNET_mutex_destroy (lock); |
724 | lock = NULL; | 724 | lock = NULL; |
725 | UNLINK (pipename); | 725 | unlink (pipename); |
726 | GNUNET_free (pipename); | 726 | GNUNET_free (pipename); |
727 | pipename = NULL; | 727 | pipename = NULL; |
728 | GNUNET_free (email); | 728 | GNUNET_free (email); |
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 | ||
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index b05192e06..1d34cdd1a 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -40,12 +40,13 @@ | |||
40 | #include "gnunet_transport_plugin.h" | 40 | #include "gnunet_transport_plugin.h" |
41 | #include "transport.h" | 41 | #include "transport.h" |
42 | 42 | ||
43 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) | 43 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-udp", __VA_ARGS__) |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * After how much inactivity should a UDP session time out? | 46 | * After how much inactivity should a UDP session time out? |
47 | */ | 47 | */ |
48 | #define UDP_SESSION_TIME_OUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | 48 | #define UDP_SESSION_TIME_OUT \ |
49 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) | ||
49 | 50 | ||
50 | /** | 51 | /** |
51 | * Number of messages we can defragment in parallel. We only really | 52 | * Number of messages we can defragment in parallel. We only really |
@@ -86,7 +87,6 @@ struct UDPMessage | |||
86 | * What is the identity of the sender | 87 | * What is the identity of the sender |
87 | */ | 88 | */ |
88 | struct GNUNET_PeerIdentity sender; | 89 | struct GNUNET_PeerIdentity sender; |
89 | |||
90 | }; | 90 | }; |
91 | 91 | ||
92 | 92 | ||
@@ -144,7 +144,6 @@ struct PrettyPrinterContext | |||
144 | * Port to add after the IP address. | 144 | * Port to add after the IP address. |
145 | */ | 145 | */ |
146 | uint16_t port; | 146 | uint16_t port; |
147 | |||
148 | }; | 147 | }; |
149 | 148 | ||
150 | 149 | ||
@@ -248,7 +247,6 @@ struct GNUNET_ATS_Session | |||
248 | }; | 247 | }; |
249 | 248 | ||
250 | 249 | ||
251 | |||
252 | /** | 250 | /** |
253 | * Data structure to track defragmentation contexts based | 251 | * Data structure to track defragmentation contexts based |
254 | * on the source of the UDP traffic. | 252 | * on the source of the UDP traffic. |
@@ -374,7 +372,6 @@ struct UDP_FragmentationContext | |||
374 | * Bytes used to send all fragments on wire including UDP overhead | 372 | * Bytes used to send all fragments on wire including UDP overhead |
375 | */ | 373 | */ |
376 | size_t on_wire_size; | 374 | size_t on_wire_size; |
377 | |||
378 | }; | 375 | }; |
379 | 376 | ||
380 | 377 | ||
@@ -388,10 +385,9 @@ struct UDP_FragmentationContext | |||
388 | * #GNUNET_SYSERR if the target disconnected | 385 | * #GNUNET_SYSERR if the target disconnected |
389 | * or we had a timeout or other trouble sending | 386 | * or we had a timeout or other trouble sending |
390 | */ | 387 | */ |
391 | typedef void | 388 | typedef void (*QueueContinuation) (void *cls, |
392 | (*QueueContinuation) (void *cls, | 389 | struct UDP_MessageWrapper *udpw, |
393 | struct UDP_MessageWrapper *udpw, | 390 | int result); |
394 | int result); | ||
395 | 391 | ||
396 | 392 | ||
397 | /** | 393 | /** |
@@ -474,7 +470,6 @@ struct UDP_MessageWrapper | |||
474 | * Payload size of original message. | 470 | * Payload size of original message. |
475 | */ | 471 | */ |
476 | size_t payload_size; | 472 | size_t payload_size; |
477 | |||
478 | }; | 473 | }; |
479 | 474 | ||
480 | 475 | ||
@@ -501,7 +496,6 @@ struct UDP_ACK_Message | |||
501 | * What is the identity of the sender | 496 | * What is the identity of the sender |
502 | */ | 497 | */ |
503 | struct GNUNET_PeerIdentity sender; | 498 | struct GNUNET_PeerIdentity sender; |
504 | |||
505 | }; | 499 | }; |
506 | 500 | ||
507 | GNUNET_NETWORK_STRUCT_END | 501 | GNUNET_NETWORK_STRUCT_END |
@@ -529,9 +523,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
529 | return; | 523 | return; |
530 | if (GNUNET_YES == session->in_destroy) | 524 | if (GNUNET_YES == session->in_destroy) |
531 | return; /* already destroyed, just RC>0 left-over actions */ | 525 | return; /* already destroyed, just RC>0 left-over actions */ |
532 | memset (&info, | 526 | memset (&info, 0, sizeof (info)); |
533 | 0, | ||
534 | sizeof (info)); | ||
535 | info.state = state; | 527 | info.state = state; |
536 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ | 528 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ |
537 | info.num_msg_pending = session->msgs_in_queue; | 529 | info.num_msg_pending = session->msgs_in_queue; |
@@ -541,9 +533,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
541 | to receive from others) */ | 533 | to receive from others) */ |
542 | info.session_timeout = session->timeout; | 534 | info.session_timeout = session->timeout; |
543 | info.address = session->address; | 535 | info.address = session->address; |
544 | plugin->sic (plugin->sic_cls, | 536 | plugin->sic (plugin->sic_cls, session, &info); |
545 | session, | ||
546 | &info); | ||
547 | } | 537 | } |
548 | 538 | ||
549 | 539 | ||
@@ -563,12 +553,8 @@ send_session_info_iter (void *cls, | |||
563 | struct Plugin *plugin = cls; | 553 | struct Plugin *plugin = cls; |
564 | struct GNUNET_ATS_Session *session = value; | 554 | struct GNUNET_ATS_Session *session = value; |
565 | 555 | ||
566 | notify_session_monitor (plugin, | 556 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
567 | session, | 557 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
568 | GNUNET_TRANSPORT_SS_INIT); | ||
569 | notify_session_monitor (plugin, | ||
570 | session, | ||
571 | GNUNET_TRANSPORT_SS_UP); | ||
572 | return GNUNET_OK; | 558 | return GNUNET_OK; |
573 | } | 559 | } |
574 | 560 | ||
@@ -600,9 +586,7 @@ udp_plugin_setup_monitor (void *cls, | |||
600 | &send_session_info_iter, | 586 | &send_session_info_iter, |
601 | plugin); | 587 | plugin); |
602 | /* signal end of first iteration */ | 588 | /* signal end of first iteration */ |
603 | sic (sic_cls, | 589 | sic (sic_cls, NULL, NULL); |
604 | NULL, | ||
605 | NULL); | ||
606 | } | 590 | } |
607 | } | 591 | } |
608 | 592 | ||
@@ -625,9 +609,7 @@ free_session (struct GNUNET_ATS_Session *s) | |||
625 | } | 609 | } |
626 | if (NULL != s->frag_ctx) | 610 | if (NULL != s->frag_ctx) |
627 | { | 611 | { |
628 | GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, | 612 | GNUNET_FRAGMENT_context_destroy (s->frag_ctx->frag, NULL, NULL); |
629 | NULL, | ||
630 | NULL); | ||
631 | GNUNET_free (s->frag_ctx); | 613 | GNUNET_free (s->frag_ctx); |
632 | s->frag_ctx = NULL; | 614 | s->frag_ctx = NULL; |
633 | } | 615 | } |
@@ -663,8 +645,7 @@ udp_query_keepalive_factor (void *cls) | |||
663 | * @return the network type | 645 | * @return the network type |
664 | */ | 646 | */ |
665 | static enum GNUNET_NetworkType | 647 | static enum GNUNET_NetworkType |
666 | udp_plugin_get_network (void *cls, | 648 | udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) |
667 | struct GNUNET_ATS_Session *session) | ||
668 | { | 649 | { |
669 | return session->scope; | 650 | return session->scope; |
670 | } | 651 | } |
@@ -691,25 +672,25 @@ udp_plugin_get_network_for_address (void *cls, | |||
691 | size_t sbs; | 672 | size_t sbs; |
692 | 673 | ||
693 | addrlen = address->address_length; | 674 | addrlen = address->address_length; |
694 | if (addrlen == sizeof(struct IPv6UdpAddress)) | 675 | if (addrlen == sizeof (struct IPv6UdpAddress)) |
695 | { | 676 | { |
696 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 677 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
697 | u6 = address->address; | 678 | u6 = address->address; |
698 | memset (&a6, 0, sizeof(a6)); | 679 | memset (&a6, 0, sizeof (a6)); |
699 | #if HAVE_SOCKADDR_IN_SIN_LEN | 680 | #if HAVE_SOCKADDR_IN_SIN_LEN |
700 | a6.sin6_len = sizeof (a6); | 681 | a6.sin6_len = sizeof (a6); |
701 | #endif | 682 | #endif |
702 | a6.sin6_family = AF_INET6; | 683 | a6.sin6_family = AF_INET6; |
703 | a6.sin6_port = u6->u6_port; | 684 | a6.sin6_port = u6->u6_port; |
704 | GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr)); | 685 | GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr)); |
705 | sb = &a6; | 686 | sb = &a6; |
706 | sbs = sizeof(a6); | 687 | sbs = sizeof (a6); |
707 | } | 688 | } |
708 | else if (addrlen == sizeof(struct IPv4UdpAddress)) | 689 | else if (addrlen == sizeof (struct IPv4UdpAddress)) |
709 | { | 690 | { |
710 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ | 691 | GNUNET_assert (NULL != address->address); /* make static analysis happy */ |
711 | u4 = address->address; | 692 | u4 = address->address; |
712 | memset (&a4, 0, sizeof(a4)); | 693 | memset (&a4, 0, sizeof (a4)); |
713 | #if HAVE_SOCKADDR_IN_SIN_LEN | 694 | #if HAVE_SOCKADDR_IN_SIN_LEN |
714 | a4.sin_len = sizeof (a4); | 695 | a4.sin_len = sizeof (a4); |
715 | #endif | 696 | #endif |
@@ -717,16 +698,14 @@ udp_plugin_get_network_for_address (void *cls, | |||
717 | a4.sin_port = u4->u4_port; | 698 | a4.sin_port = u4->u4_port; |
718 | a4.sin_addr.s_addr = u4->ipv4_addr; | 699 | a4.sin_addr.s_addr = u4->ipv4_addr; |
719 | sb = &a4; | 700 | sb = &a4; |
720 | sbs = sizeof(a4); | 701 | sbs = sizeof (a4); |
721 | } | 702 | } |
722 | else | 703 | else |
723 | { | 704 | { |
724 | GNUNET_break (0); | 705 | GNUNET_break (0); |
725 | return GNUNET_NT_UNSPECIFIED; | 706 | return GNUNET_NT_UNSPECIFIED; |
726 | } | 707 | } |
727 | return plugin->env->get_address_type (plugin->env->cls, | 708 | return plugin->env->get_address_type (plugin->env->cls, sb, sbs); |
728 | sb, | ||
729 | sbs); | ||
730 | } | 709 | } |
731 | 710 | ||
732 | 711 | ||
@@ -767,8 +746,7 @@ schedule_select_v4 (struct Plugin *plugin) | |||
767 | struct UDP_MessageWrapper *udpw; | 746 | struct UDP_MessageWrapper *udpw; |
768 | struct UDP_MessageWrapper *min_udpw; | 747 | struct UDP_MessageWrapper *min_udpw; |
769 | 748 | ||
770 | if ( (GNUNET_YES == plugin->enable_ipv4) && | 749 | if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4)) |
771 | (NULL != plugin->sockv4) ) | ||
772 | { | 750 | { |
773 | /* Find a message ready to send: | 751 | /* Find a message ready to send: |
774 | * Flow delay from other peer is expired or not set (0) */ | 752 | * Flow delay from other peer is expired or not set (0) */ |
@@ -804,11 +782,11 @@ schedule_select_v4 (struct Plugin *plugin) | |||
804 | GNUNET_i2s (&min_udpw->session->target)); | 782 | GNUNET_i2s (&min_udpw->session->target)); |
805 | } | 783 | } |
806 | } | 784 | } |
807 | plugin->select_task_v4 | 785 | plugin->select_task_v4 = |
808 | = GNUNET_SCHEDULER_add_read_net (min_delay, | 786 | GNUNET_SCHEDULER_add_read_net (min_delay, |
809 | plugin->sockv4, | 787 | plugin->sockv4, |
810 | &udp_plugin_select_v4, | 788 | &udp_plugin_select_v4, |
811 | plugin); | 789 | plugin); |
812 | } | 790 | } |
813 | } | 791 | } |
814 | 792 | ||
@@ -826,8 +804,7 @@ schedule_select_v6 (struct Plugin *plugin) | |||
826 | struct UDP_MessageWrapper *udpw; | 804 | struct UDP_MessageWrapper *udpw; |
827 | struct UDP_MessageWrapper *min_udpw; | 805 | struct UDP_MessageWrapper *min_udpw; |
828 | 806 | ||
829 | if ( (GNUNET_YES == plugin->enable_ipv6) && | 807 | if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6)) |
830 | (NULL != plugin->sockv6) ) | ||
831 | { | 808 | { |
832 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; | 809 | min_delay = GNUNET_TIME_UNIT_FOREVER_REL; |
833 | min_udpw = NULL; | 810 | min_udpw = NULL; |
@@ -861,11 +838,11 @@ schedule_select_v6 (struct Plugin *plugin) | |||
861 | GNUNET_i2s (&min_udpw->session->target)); | 838 | GNUNET_i2s (&min_udpw->session->target)); |
862 | } | 839 | } |
863 | } | 840 | } |
864 | plugin->select_task_v6 | 841 | plugin->select_task_v6 = |
865 | = GNUNET_SCHEDULER_add_read_net (min_delay, | 842 | GNUNET_SCHEDULER_add_read_net (min_delay, |
866 | plugin->sockv6, | 843 | plugin->sockv6, |
867 | &udp_plugin_select_v6, | 844 | &udp_plugin_select_v6, |
868 | plugin); | 845 | plugin); |
869 | } | 846 | } |
870 | } | 847 | } |
871 | 848 | ||
@@ -885,9 +862,7 @@ schedule_select_v6 (struct Plugin *plugin) | |||
885 | * @return string representing the same address | 862 | * @return string representing the same address |
886 | */ | 863 | */ |
887 | const char * | 864 | const char * |
888 | udp_address_to_string (void *cls, | 865 | udp_address_to_string (void *cls, const void *addr, size_t addrlen) |
889 | const void *addr, | ||
890 | size_t addrlen) | ||
891 | { | 866 | { |
892 | static char rbuf[INET6_ADDRSTRLEN + 10]; | 867 | static char rbuf[INET6_ADDRSTRLEN + 10]; |
893 | char buf[INET6_ADDRSTRLEN]; | 868 | char buf[INET6_ADDRSTRLEN]; |
@@ -906,7 +881,7 @@ udp_address_to_string (void *cls, | |||
906 | return NULL; | 881 | return NULL; |
907 | } | 882 | } |
908 | 883 | ||
909 | if (addrlen == sizeof(struct IPv6UdpAddress)) | 884 | if (addrlen == sizeof (struct IPv6UdpAddress)) |
910 | { | 885 | { |
911 | t6 = addr; | 886 | t6 = addr; |
912 | af = AF_INET6; | 887 | af = AF_INET6; |
@@ -915,7 +890,7 @@ udp_address_to_string (void *cls, | |||
915 | a6 = t6->ipv6_addr; | 890 | a6 = t6->ipv6_addr; |
916 | sb = &a6; | 891 | sb = &a6; |
917 | } | 892 | } |
918 | else if (addrlen == sizeof(struct IPv4UdpAddress)) | 893 | else if (addrlen == sizeof (struct IPv4UdpAddress)) |
919 | { | 894 | { |
920 | t4 = addr; | 895 | t4 = addr; |
921 | af = AF_INET; | 896 | af = AF_INET; |
@@ -929,15 +904,10 @@ udp_address_to_string (void *cls, | |||
929 | GNUNET_break_op (0); | 904 | GNUNET_break_op (0); |
930 | return NULL; | 905 | return NULL; |
931 | } | 906 | } |
932 | inet_ntop (af, | 907 | inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); |
933 | sb, | ||
934 | buf, | ||
935 | INET6_ADDRSTRLEN); | ||
936 | GNUNET_snprintf (rbuf, | 908 | GNUNET_snprintf (rbuf, |
937 | sizeof(rbuf), | 909 | sizeof (rbuf), |
938 | (af == AF_INET6) | 910 | (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u", |
939 | ? "%s.%u.[%s]:%u" | ||
940 | : "%s.%u.%s:%u", | ||
941 | PLUGIN_NAME, | 911 | PLUGIN_NAME, |
942 | options, | 912 | options, |
943 | buf, | 913 | buf, |
@@ -1012,44 +982,42 @@ udp_string_to_address (void *cls, | |||
1012 | address++; | 982 | address++; |
1013 | 983 | ||
1014 | if (GNUNET_OK != | 984 | if (GNUNET_OK != |
1015 | GNUNET_STRINGS_to_address_ip (address, | 985 | GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address)) |
1016 | strlen (address), | ||
1017 | &socket_address)) | ||
1018 | { | 986 | { |
1019 | GNUNET_break (0); | 987 | GNUNET_break (0); |
1020 | GNUNET_free (plugin); | 988 | GNUNET_free (plugin); |
1021 | return GNUNET_SYSERR; | 989 | return GNUNET_SYSERR; |
1022 | } | 990 | } |
1023 | GNUNET_free(plugin); | 991 | GNUNET_free (plugin); |
1024 | 992 | ||
1025 | switch (socket_address.ss_family) | 993 | switch (socket_address.ss_family) |
1026 | { | 994 | { |
1027 | case AF_INET: | 995 | case AF_INET: { |
1028 | { | 996 | struct IPv4UdpAddress *u4; |
1029 | struct IPv4UdpAddress *u4; | 997 | const struct sockaddr_in *in4 = |
1030 | const struct sockaddr_in *in4 = (const struct sockaddr_in *) &socket_address; | 998 | (const struct sockaddr_in *) &socket_address; |
1031 | 999 | ||
1032 | u4 = GNUNET_new (struct IPv4UdpAddress); | 1000 | u4 = GNUNET_new (struct IPv4UdpAddress); |
1033 | u4->options = htonl (options); | 1001 | u4->options = htonl (options); |
1034 | u4->ipv4_addr = in4->sin_addr.s_addr; | 1002 | u4->ipv4_addr = in4->sin_addr.s_addr; |
1035 | u4->u4_port = in4->sin_port; | 1003 | u4->u4_port = in4->sin_port; |
1036 | *buf = u4; | 1004 | *buf = u4; |
1037 | *added = sizeof (struct IPv4UdpAddress); | 1005 | *added = sizeof (struct IPv4UdpAddress); |
1038 | return GNUNET_OK; | 1006 | return GNUNET_OK; |
1039 | } | 1007 | } |
1040 | case AF_INET6: | 1008 | case AF_INET6: { |
1041 | { | 1009 | struct IPv6UdpAddress *u6; |
1042 | struct IPv6UdpAddress *u6; | 1010 | const struct sockaddr_in6 *in6 = |
1043 | const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) &socket_address; | 1011 | (const struct sockaddr_in6 *) &socket_address; |
1044 | 1012 | ||
1045 | u6 = GNUNET_new (struct IPv6UdpAddress); | 1013 | u6 = GNUNET_new (struct IPv6UdpAddress); |
1046 | u6->options = htonl (options); | 1014 | u6->options = htonl (options); |
1047 | u6->ipv6_addr = in6->sin6_addr; | 1015 | u6->ipv6_addr = in6->sin6_addr; |
1048 | u6->u6_port = in6->sin6_port; | 1016 | u6->u6_port = in6->sin6_port; |
1049 | *buf = u6; | 1017 | *buf = u6; |
1050 | *added = sizeof (struct IPv6UdpAddress); | 1018 | *added = sizeof (struct IPv6UdpAddress); |
1051 | return GNUNET_OK; | 1019 | return GNUNET_OK; |
1052 | } | 1020 | } |
1053 | default: | 1021 | default: |
1054 | GNUNET_break (0); | 1022 | GNUNET_break (0); |
1055 | return GNUNET_SYSERR; | 1023 | return GNUNET_SYSERR; |
@@ -1064,8 +1032,7 @@ udp_string_to_address (void *cls, | |||
1064 | * @param hostname result from DNS resolver | 1032 | * @param hostname result from DNS resolver |
1065 | */ | 1033 | */ |
1066 | static void | 1034 | static void |
1067 | append_port (void *cls, | 1035 | append_port (void *cls, const char *hostname) |
1068 | const char *hostname) | ||
1069 | { | 1036 | { |
1070 | struct PrettyPrinterContext *ppc = cls; | 1037 | struct PrettyPrinterContext *ppc = cls; |
1071 | struct Plugin *plugin = ppc->plugin; | 1038 | struct Plugin *plugin = ppc->plugin; |
@@ -1078,9 +1045,7 @@ append_port (void *cls, | |||
1078 | plugin->ppc_dll_tail, | 1045 | plugin->ppc_dll_tail, |
1079 | ppc); | 1046 | ppc); |
1080 | ppc->resolver_handle = NULL; | 1047 | ppc->resolver_handle = NULL; |
1081 | ppc->asc (ppc->asc_cls, | 1048 | ppc->asc (ppc->asc_cls, NULL, GNUNET_OK); |
1082 | NULL, | ||
1083 | GNUNET_OK); | ||
1084 | GNUNET_free (ppc); | 1049 | GNUNET_free (ppc); |
1085 | return; | 1050 | return; |
1086 | } | 1051 | } |
@@ -1098,9 +1063,7 @@ append_port (void *cls, | |||
1098 | ppc->options, | 1063 | ppc->options, |
1099 | hostname, | 1064 | hostname, |
1100 | ppc->port); | 1065 | ppc->port); |
1101 | ppc->asc (ppc->asc_cls, | 1066 | ppc->asc (ppc->asc_cls, ret, GNUNET_OK); |
1102 | ret, | ||
1103 | GNUNET_OK); | ||
1104 | GNUNET_free (ret); | 1067 | GNUNET_free (ret); |
1105 | } | 1068 | } |
1106 | 1069 | ||
@@ -1140,12 +1103,10 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1140 | uint16_t port; | 1103 | uint16_t port; |
1141 | uint32_t options; | 1104 | uint32_t options; |
1142 | 1105 | ||
1143 | if (addrlen == sizeof(struct IPv6UdpAddress)) | 1106 | if (addrlen == sizeof (struct IPv6UdpAddress)) |
1144 | { | 1107 | { |
1145 | u6 = addr; | 1108 | u6 = addr; |
1146 | memset (&a6, | 1109 | memset (&a6, 0, sizeof (a6)); |
1147 | 0, | ||
1148 | sizeof (a6)); | ||
1149 | a6.sin6_family = AF_INET6; | 1110 | a6.sin6_family = AF_INET6; |
1150 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1111 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1151 | a6.sin6_len = sizeof (a6); | 1112 | a6.sin6_len = sizeof (a6); |
@@ -1160,9 +1121,7 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1160 | else if (addrlen == sizeof (struct IPv4UdpAddress)) | 1121 | else if (addrlen == sizeof (struct IPv4UdpAddress)) |
1161 | { | 1122 | { |
1162 | u4 = addr; | 1123 | u4 = addr; |
1163 | memset (&a4, | 1124 | memset (&a4, 0, sizeof (a4)); |
1164 | 0, | ||
1165 | sizeof(a4)); | ||
1166 | a4.sin_family = AF_INET; | 1125 | a4.sin_family = AF_INET; |
1167 | #if HAVE_SOCKADDR_IN_SIN_LEN | 1126 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1168 | a4.sin_len = sizeof (a4); | 1127 | a4.sin_len = sizeof (a4); |
@@ -1172,18 +1131,14 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1172 | port = ntohs (u4->u4_port); | 1131 | port = ntohs (u4->u4_port); |
1173 | options = ntohl (u4->options); | 1132 | options = ntohl (u4->options); |
1174 | sb = (const struct sockaddr *) &a4; | 1133 | sb = (const struct sockaddr *) &a4; |
1175 | sbs = sizeof(a4); | 1134 | sbs = sizeof (a4); |
1176 | } | 1135 | } |
1177 | else | 1136 | else |
1178 | { | 1137 | { |
1179 | /* invalid address */ | 1138 | /* invalid address */ |
1180 | GNUNET_break_op (0); | 1139 | GNUNET_break_op (0); |
1181 | asc (asc_cls, | 1140 | asc (asc_cls, NULL, GNUNET_SYSERR); |
1182 | NULL, | 1141 | asc (asc_cls, NULL, GNUNET_OK); |
1183 | GNUNET_SYSERR); | ||
1184 | asc (asc_cls, | ||
1185 | NULL, | ||
1186 | GNUNET_OK); | ||
1187 | return; | 1142 | return; |
1188 | } | 1143 | } |
1189 | ppc = GNUNET_new (struct PrettyPrinterContext); | 1144 | ppc = GNUNET_new (struct PrettyPrinterContext); |
@@ -1196,16 +1151,13 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1196 | ppc->ipv6 = GNUNET_YES; | 1151 | ppc->ipv6 = GNUNET_YES; |
1197 | else | 1152 | else |
1198 | ppc->ipv6 = GNUNET_NO; | 1153 | ppc->ipv6 = GNUNET_NO; |
1199 | GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, | 1154 | GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc); |
1200 | plugin->ppc_dll_tail, | 1155 | ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb, |
1201 | ppc); | 1156 | sbs, |
1202 | ppc->resolver_handle | 1157 | ! numeric, |
1203 | = GNUNET_RESOLVER_hostname_get (sb, | 1158 | timeout, |
1204 | sbs, | 1159 | &append_port, |
1205 | ! numeric, | 1160 | ppc); |
1206 | timeout, | ||
1207 | &append_port, | ||
1208 | ppc); | ||
1209 | } | 1161 | } |
1210 | 1162 | ||
1211 | 1163 | ||
@@ -1219,11 +1171,9 @@ udp_plugin_address_pretty_printer (void *cls, | |||
1219 | * @return #GNUNET_OK if port is either our open or advertised port | 1171 | * @return #GNUNET_OK if port is either our open or advertised port |
1220 | */ | 1172 | */ |
1221 | static int | 1173 | static int |
1222 | check_port (const struct Plugin *plugin, | 1174 | check_port (const struct Plugin *plugin, uint16_t in_port) |
1223 | uint16_t in_port) | ||
1224 | { | 1175 | { |
1225 | if ( (plugin->port == in_port) || | 1176 | if ((plugin->port == in_port) || (plugin->aport == in_port)) |
1226 | (plugin->aport == in_port) ) | ||
1227 | return GNUNET_OK; | 1177 | return GNUNET_OK; |
1228 | return GNUNET_SYSERR; | 1178 | return GNUNET_SYSERR; |
1229 | } | 1179 | } |
@@ -1245,21 +1195,18 @@ check_port (const struct Plugin *plugin, | |||
1245 | * and transport, #GNUNET_SYSERR if not | 1195 | * and transport, #GNUNET_SYSERR if not |
1246 | */ | 1196 | */ |
1247 | static int | 1197 | static int |
1248 | udp_plugin_check_address (void *cls, | 1198 | udp_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
1249 | const void *addr, | ||
1250 | size_t addrlen) | ||
1251 | { | 1199 | { |
1252 | struct Plugin *plugin = cls; | 1200 | struct Plugin *plugin = cls; |
1253 | const struct IPv4UdpAddress *v4; | 1201 | const struct IPv4UdpAddress *v4; |
1254 | const struct IPv6UdpAddress *v6; | 1202 | const struct IPv6UdpAddress *v6; |
1255 | 1203 | ||
1256 | if (sizeof(struct IPv4UdpAddress) == addrlen) | 1204 | if (sizeof (struct IPv4UdpAddress) == addrlen) |
1257 | { | 1205 | { |
1258 | struct sockaddr_in s4; | 1206 | struct sockaddr_in s4; |
1259 | 1207 | ||
1260 | v4 = (const struct IPv4UdpAddress *) addr; | 1208 | v4 = (const struct IPv4UdpAddress *) addr; |
1261 | if (GNUNET_OK != check_port (plugin, | 1209 | if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port))) |
1262 | ntohs (v4->u4_port))) | ||
1263 | return GNUNET_SYSERR; | 1210 | return GNUNET_SYSERR; |
1264 | memset (&s4, 0, sizeof (s4)); | 1211 | memset (&s4, 0, sizeof (s4)); |
1265 | s4.sin_family = AF_INET; | 1212 | s4.sin_family = AF_INET; |
@@ -1270,12 +1217,10 @@ udp_plugin_check_address (void *cls, | |||
1270 | s4.sin_addr.s_addr = v4->ipv4_addr; | 1217 | s4.sin_addr.s_addr = v4->ipv4_addr; |
1271 | 1218 | ||
1272 | if (GNUNET_OK != | 1219 | if (GNUNET_OK != |
1273 | GNUNET_NAT_test_address (plugin->nat, | 1220 | GNUNET_NAT_test_address (plugin->nat, &s4, sizeof (struct sockaddr_in))) |
1274 | &s4, | ||
1275 | sizeof (struct sockaddr_in))) | ||
1276 | return GNUNET_SYSERR; | 1221 | return GNUNET_SYSERR; |
1277 | } | 1222 | } |
1278 | else if (sizeof(struct IPv6UdpAddress) == addrlen) | 1223 | else if (sizeof (struct IPv6UdpAddress) == addrlen) |
1279 | { | 1224 | { |
1280 | struct sockaddr_in6 s6; | 1225 | struct sockaddr_in6 s6; |
1281 | 1226 | ||
@@ -1290,10 +1235,9 @@ udp_plugin_check_address (void *cls, | |||
1290 | s6.sin6_port = v6->u6_port; | 1235 | s6.sin6_port = v6->u6_port; |
1291 | s6.sin6_addr = v6->ipv6_addr; | 1236 | s6.sin6_addr = v6->ipv6_addr; |
1292 | 1237 | ||
1293 | if (GNUNET_OK != | 1238 | if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat, |
1294 | GNUNET_NAT_test_address (plugin->nat, | 1239 | &s6, |
1295 | &s6, | 1240 | sizeof (struct sockaddr_in6))) |
1296 | sizeof(struct sockaddr_in6))) | ||
1297 | return GNUNET_SYSERR; | 1241 | return GNUNET_SYSERR; |
1298 | } | 1242 | } |
1299 | else | 1243 | else |
@@ -1319,9 +1263,9 @@ udp_plugin_check_address (void *cls, | |||
1319 | */ | 1263 | */ |
1320 | static void | 1264 | static void |
1321 | udp_nat_port_map_callback (void *cls, | 1265 | udp_nat_port_map_callback (void *cls, |
1322 | void **app_ctx, | 1266 | void **app_ctx, |
1323 | int add_remove, | 1267 | int add_remove, |
1324 | enum GNUNET_NAT_AddressClass ac, | 1268 | enum GNUNET_NAT_AddressClass ac, |
1325 | const struct sockaddr *addr, | 1269 | const struct sockaddr *addr, |
1326 | socklen_t addrlen) | 1270 | socklen_t addrlen) |
1327 | { | 1271 | { |
@@ -1334,50 +1278,42 @@ udp_nat_port_map_callback (void *cls, | |||
1334 | 1278 | ||
1335 | (void) app_ctx; | 1279 | (void) app_ctx; |
1336 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1280 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1337 | (GNUNET_YES == add_remove) | 1281 | (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n" |
1338 | ? "NAT notification to add address `%s'\n" | 1282 | : "NAT notification to remove address `%s'\n", |
1339 | : "NAT notification to remove address `%s'\n", | 1283 | GNUNET_a2s (addr, addrlen)); |
1340 | GNUNET_a2s (addr, | ||
1341 | addrlen)); | ||
1342 | /* convert 'address' to our internal format */ | 1284 | /* convert 'address' to our internal format */ |
1343 | switch (addr->sa_family) | 1285 | switch (addr->sa_family) |
1344 | { | 1286 | { |
1345 | case AF_INET: | 1287 | case AF_INET: { |
1346 | { | 1288 | const struct sockaddr_in *i4; |
1347 | const struct sockaddr_in *i4; | 1289 | |
1348 | 1290 | GNUNET_assert (sizeof (struct sockaddr_in) == addrlen); | |
1349 | GNUNET_assert (sizeof(struct sockaddr_in) == addrlen); | 1291 | i4 = (const struct sockaddr_in *) addr; |
1350 | i4 = (const struct sockaddr_in *) addr; | 1292 | if (0 == ntohs (i4->sin_port)) |
1351 | if (0 == ntohs (i4->sin_port)) | 1293 | return; /* Port = 0 means unmapped, ignore these for UDP. */ |
1352 | return; /* Port = 0 means unmapped, ignore these for UDP. */ | 1294 | memset (&u4, 0, sizeof (u4)); |
1353 | memset (&u4, | 1295 | u4.options = htonl (plugin->myoptions); |
1354 | 0, | 1296 | u4.ipv4_addr = i4->sin_addr.s_addr; |
1355 | sizeof(u4)); | 1297 | u4.u4_port = i4->sin_port; |
1356 | u4.options = htonl (plugin->myoptions); | 1298 | arg = &u4; |
1357 | u4.ipv4_addr = i4->sin_addr.s_addr; | 1299 | args = sizeof (struct IPv4UdpAddress); |
1358 | u4.u4_port = i4->sin_port; | 1300 | break; |
1359 | arg = &u4; | 1301 | } |
1360 | args = sizeof (struct IPv4UdpAddress); | 1302 | case AF_INET6: { |
1361 | break; | 1303 | const struct sockaddr_in6 *i6; |
1362 | } | 1304 | |
1363 | case AF_INET6: | 1305 | GNUNET_assert (sizeof (struct sockaddr_in6) == addrlen); |
1364 | { | 1306 | i6 = (const struct sockaddr_in6 *) addr; |
1365 | const struct sockaddr_in6 *i6; | 1307 | if (0 == ntohs (i6->sin6_port)) |
1366 | 1308 | return; /* Port = 0 means unmapped, ignore these for UDP. */ | |
1367 | GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen); | 1309 | memset (&u6, 0, sizeof (u6)); |
1368 | i6 = (const struct sockaddr_in6 *) addr; | 1310 | u6.options = htonl (plugin->myoptions); |
1369 | if (0 == ntohs (i6->sin6_port)) | 1311 | u6.ipv6_addr = i6->sin6_addr; |
1370 | return; /* Port = 0 means unmapped, ignore these for UDP. */ | 1312 | u6.u6_port = i6->sin6_port; |
1371 | memset (&u6, | 1313 | arg = &u6; |
1372 | 0, | 1314 | args = sizeof (struct IPv6UdpAddress); |
1373 | sizeof(u6)); | 1315 | break; |
1374 | u6.options = htonl (plugin->myoptions); | 1316 | } |
1375 | u6.ipv6_addr = i6->sin6_addr; | ||
1376 | u6.u6_port = i6->sin6_port; | ||
1377 | arg = &u6; | ||
1378 | args = sizeof (struct IPv6UdpAddress); | ||
1379 | break; | ||
1380 | } | ||
1381 | default: | 1317 | default: |
1382 | GNUNET_break (0); | 1318 | GNUNET_break (0); |
1383 | return; | 1319 | return; |
@@ -1389,9 +1325,7 @@ udp_nat_port_map_callback (void *cls, | |||
1389 | arg, | 1325 | arg, |
1390 | args, | 1326 | args, |
1391 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1327 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1392 | plugin->env->notify_address (plugin->env->cls, | 1328 | plugin->env->notify_address (plugin->env->cls, add_remove, address); |
1393 | add_remove, | ||
1394 | address); | ||
1395 | GNUNET_HELLO_address_free (address); | 1329 | GNUNET_HELLO_address_free (address); |
1396 | } | 1330 | } |
1397 | 1331 | ||
@@ -1425,15 +1359,12 @@ struct GNUNET_ATS_SessionCompareContext | |||
1425 | * @return #GNUNET_NO if we found the session, #GNUNET_OK if not | 1359 | * @return #GNUNET_NO if we found the session, #GNUNET_OK if not |
1426 | */ | 1360 | */ |
1427 | static int | 1361 | static int |
1428 | session_cmp_it (void *cls, | 1362 | session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
1429 | const struct GNUNET_PeerIdentity *key, | ||
1430 | void *value) | ||
1431 | { | 1363 | { |
1432 | struct GNUNET_ATS_SessionCompareContext *cctx = cls; | 1364 | struct GNUNET_ATS_SessionCompareContext *cctx = cls; |
1433 | struct GNUNET_ATS_Session *s = value; | 1365 | struct GNUNET_ATS_Session *s = value; |
1434 | 1366 | ||
1435 | if (0 == GNUNET_HELLO_address_cmp (s->address, | 1367 | if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address)) |
1436 | cctx->address)) | ||
1437 | { | 1368 | { |
1438 | GNUNET_assert (GNUNET_NO == s->in_destroy); | 1369 | GNUNET_assert (GNUNET_NO == s->in_destroy); |
1439 | cctx->res = s; | 1370 | cctx->res = s; |
@@ -1466,7 +1397,7 @@ udp_plugin_lookup_session (void *cls, | |||
1466 | GNUNET_break (0); | 1397 | GNUNET_break (0); |
1467 | return NULL; | 1398 | return NULL; |
1468 | } | 1399 | } |
1469 | if (sizeof(struct IPv4UdpAddress) == address->address_length) | 1400 | if (sizeof (struct IPv4UdpAddress) == address->address_length) |
1470 | { | 1401 | { |
1471 | if (NULL == plugin->sockv4) | 1402 | if (NULL == plugin->sockv4) |
1472 | return NULL; | 1403 | return NULL; |
@@ -1477,7 +1408,7 @@ udp_plugin_lookup_session (void *cls, | |||
1477 | return NULL; | 1408 | return NULL; |
1478 | } | 1409 | } |
1479 | } | 1410 | } |
1480 | else if (sizeof(struct IPv6UdpAddress) == address->address_length) | 1411 | else if (sizeof (struct IPv6UdpAddress) == address->address_length) |
1481 | { | 1412 | { |
1482 | if (NULL == plugin->sockv6) | 1413 | if (NULL == plugin->sockv6) |
1483 | return NULL; | 1414 | return NULL; |
@@ -1509,9 +1440,7 @@ udp_plugin_lookup_session (void *cls, | |||
1509 | &cctx); | 1440 | &cctx); |
1510 | if (NULL == cctx.res) | 1441 | if (NULL == cctx.res) |
1511 | return NULL; | 1442 | return NULL; |
1512 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1443 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res); |
1513 | "Found existing session %p\n", | ||
1514 | cctx.res); | ||
1515 | return cctx.res; | 1444 | return cctx.res; |
1516 | } | 1445 | } |
1517 | 1446 | ||
@@ -1534,7 +1463,6 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *s) | |||
1534 | } | 1463 | } |
1535 | 1464 | ||
1536 | 1465 | ||
1537 | |||
1538 | /** | 1466 | /** |
1539 | * Function that will be called whenever the transport service wants to | 1467 | * Function that will be called whenever the transport service wants to |
1540 | * notify the plugin that a session is still active and in use and | 1468 | * notify the plugin that a session is still active and in use and |
@@ -1575,8 +1503,7 @@ udp_plugin_update_session_timeout (void *cls, | |||
1575 | * @param udpw message wrapper to dequeue | 1503 | * @param udpw message wrapper to dequeue |
1576 | */ | 1504 | */ |
1577 | static void | 1505 | static void |
1578 | dequeue (struct Plugin *plugin, | 1506 | dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) |
1579 | struct UDP_MessageWrapper *udpw) | ||
1580 | { | 1507 | { |
1581 | struct GNUNET_ATS_Session *session = udpw->session; | 1508 | struct GNUNET_ATS_Session *session = udpw->session; |
1582 | 1509 | ||
@@ -1588,7 +1515,7 @@ dequeue (struct Plugin *plugin, | |||
1588 | { | 1515 | { |
1589 | GNUNET_STATISTICS_update (plugin->env->stats, | 1516 | GNUNET_STATISTICS_update (plugin->env->stats, |
1590 | "# UDP, total bytes in send buffers", | 1517 | "# UDP, total bytes in send buffers", |
1591 | - (long long) udpw->msg_size, | 1518 | -(long long) udpw->msg_size, |
1592 | GNUNET_NO); | 1519 | GNUNET_NO); |
1593 | plugin->bytes_in_buffer -= udpw->msg_size; | 1520 | plugin->bytes_in_buffer -= udpw->msg_size; |
1594 | } | 1521 | } |
@@ -1596,13 +1523,14 @@ dequeue (struct Plugin *plugin, | |||
1596 | "# UDP, total messages in send buffers", | 1523 | "# UDP, total messages in send buffers", |
1597 | -1, | 1524 | -1, |
1598 | GNUNET_NO); | 1525 | GNUNET_NO); |
1599 | if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length) | 1526 | if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) |
1600 | { | 1527 | { |
1601 | GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, | 1528 | GNUNET_CONTAINER_DLL_remove (plugin->ipv4_queue_head, |
1602 | plugin->ipv4_queue_tail, | 1529 | plugin->ipv4_queue_tail, |
1603 | udpw); | 1530 | udpw); |
1604 | } | 1531 | } |
1605 | else if (sizeof(struct IPv6UdpAddress) == udpw->session->address->address_length) | 1532 | else if (sizeof (struct IPv6UdpAddress) == |
1533 | udpw->session->address->address_length) | ||
1606 | { | 1534 | { |
1607 | GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, | 1535 | GNUNET_CONTAINER_DLL_remove (plugin->ipv6_queue_head, |
1608 | plugin->ipv6_queue_tail, | 1536 | plugin->ipv6_queue_tail, |
@@ -1627,8 +1555,7 @@ dequeue (struct Plugin *plugin, | |||
1627 | * @param udpw message wrapper to queue | 1555 | * @param udpw message wrapper to queue |
1628 | */ | 1556 | */ |
1629 | static void | 1557 | static void |
1630 | enqueue (struct Plugin *plugin, | 1558 | enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw) |
1631 | struct UDP_MessageWrapper *udpw) | ||
1632 | { | 1559 | { |
1633 | struct GNUNET_ATS_Session *session = udpw->session; | 1560 | struct GNUNET_ATS_Session *session = udpw->session; |
1634 | 1561 | ||
@@ -1656,11 +1583,12 @@ enqueue (struct Plugin *plugin, | |||
1656 | GNUNET_NO); | 1583 | GNUNET_NO); |
1657 | if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) | 1584 | if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) |
1658 | { | 1585 | { |
1659 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_queue_head, | 1586 | GNUNET_CONTAINER_DLL_insert (plugin->ipv4_queue_head, |
1660 | plugin->ipv4_queue_tail, | 1587 | plugin->ipv4_queue_tail, |
1661 | udpw); | 1588 | udpw); |
1662 | } | 1589 | } |
1663 | else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length) | 1590 | else if (sizeof (struct IPv6UdpAddress) == |
1591 | udpw->session->address->address_length) | ||
1664 | { | 1592 | { |
1665 | GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, | 1593 | GNUNET_CONTAINER_DLL_insert (plugin->ipv6_queue_head, |
1666 | plugin->ipv6_queue_tail, | 1594 | plugin->ipv6_queue_tail, |
@@ -1693,8 +1621,7 @@ enqueue (struct Plugin *plugin, | |||
1693 | * #GNUNET_SYSERR if the transmission failed | 1621 | * #GNUNET_SYSERR if the transmission failed |
1694 | */ | 1622 | */ |
1695 | static void | 1623 | static void |
1696 | fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, | 1624 | fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result) |
1697 | int result) | ||
1698 | { | 1625 | { |
1699 | struct Plugin *plugin = frag_ctx->plugin; | 1626 | struct Plugin *plugin = frag_ctx->plugin; |
1700 | struct GNUNET_ATS_Session *s = frag_ctx->session; | 1627 | struct GNUNET_ATS_Session *s = frag_ctx->session; |
@@ -1717,16 +1644,14 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, | |||
1717 | { | 1644 | { |
1718 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1645 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1719 | "Fragmented message acknowledged after %s (expected at %s)\n", | 1646 | "Fragmented message acknowledged after %s (expected at %s)\n", |
1720 | GNUNET_STRINGS_relative_time_to_string (delay, | 1647 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), |
1721 | GNUNET_YES), | ||
1722 | GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); | 1648 | GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); |
1723 | } | 1649 | } |
1724 | else | 1650 | else |
1725 | { | 1651 | { |
1726 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1652 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1727 | "Fragmented message acknowledged after %s (expected at %s)\n", | 1653 | "Fragmented message acknowledged after %s (expected at %s)\n", |
1728 | GNUNET_STRINGS_relative_time_to_string (delay, | 1654 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), |
1729 | GNUNET_YES), | ||
1730 | GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); | 1655 | GNUNET_STRINGS_absolute_time_to_string (frag_ctx->next_frag_time)); |
1731 | } | 1656 | } |
1732 | 1657 | ||
@@ -1751,10 +1676,11 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, | |||
1751 | "# UDP, fragmented msgs, bytes payload, sent, success", | 1676 | "# UDP, fragmented msgs, bytes payload, sent, success", |
1752 | s->frag_ctx->payload_size, | 1677 | s->frag_ctx->payload_size, |
1753 | GNUNET_NO); | 1678 | GNUNET_NO); |
1754 | GNUNET_STATISTICS_update (plugin->env->stats, | 1679 | GNUNET_STATISTICS_update ( |
1755 | "# UDP, fragmented msgs, bytes overhead, sent, success", | 1680 | plugin->env->stats, |
1756 | overhead, | 1681 | "# UDP, fragmented msgs, bytes overhead, sent, success", |
1757 | GNUNET_NO); | 1682 | overhead, |
1683 | GNUNET_NO); | ||
1758 | GNUNET_STATISTICS_update (plugin->env->stats, | 1684 | GNUNET_STATISTICS_update (plugin->env->stats, |
1759 | "# UDP, total, bytes overhead, sent", | 1685 | "# UDP, total, bytes overhead, sent", |
1760 | overhead, | 1686 | overhead, |
@@ -1786,41 +1712,35 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, | |||
1786 | 1712 | ||
1787 | /* Remove remaining fragments from queue, no need to transmit those | 1713 | /* Remove remaining fragments from queue, no need to transmit those |
1788 | any longer. */ | 1714 | any longer. */ |
1789 | if (s->address->address_length == sizeof(struct IPv6UdpAddress)) | 1715 | if (s->address->address_length == sizeof (struct IPv6UdpAddress)) |
1790 | { | 1716 | { |
1791 | udpw = plugin->ipv6_queue_head; | 1717 | udpw = plugin->ipv6_queue_head; |
1792 | while (NULL != udpw) | 1718 | while (NULL != udpw) |
1793 | { | 1719 | { |
1794 | tmp = udpw->next; | 1720 | tmp = udpw->next; |
1795 | if ( (udpw->frag_ctx != NULL) && | 1721 | if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx)) |
1796 | (udpw->frag_ctx == frag_ctx) ) | ||
1797 | { | 1722 | { |
1798 | dequeue (plugin, | 1723 | dequeue (plugin, udpw); |
1799 | udpw); | 1724 | GNUNET_free (udpw); |
1800 | GNUNET_free (udpw); | ||
1801 | } | 1725 | } |
1802 | udpw = tmp; | 1726 | udpw = tmp; |
1803 | } | 1727 | } |
1804 | } | 1728 | } |
1805 | if (s->address->address_length == sizeof(struct IPv4UdpAddress)) | 1729 | if (s->address->address_length == sizeof (struct IPv4UdpAddress)) |
1806 | { | 1730 | { |
1807 | udpw = plugin->ipv4_queue_head; | 1731 | udpw = plugin->ipv4_queue_head; |
1808 | while (NULL != udpw) | 1732 | while (NULL != udpw) |
1809 | { | 1733 | { |
1810 | tmp = udpw->next; | 1734 | tmp = udpw->next; |
1811 | if ( (NULL != udpw->frag_ctx) && | 1735 | if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx)) |
1812 | (udpw->frag_ctx == frag_ctx) ) | ||
1813 | { | 1736 | { |
1814 | dequeue (plugin, | 1737 | dequeue (plugin, udpw); |
1815 | udpw); | ||
1816 | GNUNET_free (udpw); | 1738 | GNUNET_free (udpw); |
1817 | } | 1739 | } |
1818 | udpw = tmp; | 1740 | udpw = tmp; |
1819 | } | 1741 | } |
1820 | } | 1742 | } |
1821 | notify_session_monitor (s->plugin, | 1743 | notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); |
1822 | s, | ||
1823 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1824 | GNUNET_FRAGMENT_context_destroy (frag_ctx->frag, | 1744 | GNUNET_FRAGMENT_context_destroy (frag_ctx->frag, |
1825 | &s->last_expected_msg_delay, | 1745 | &s->last_expected_msg_delay, |
1826 | &s->last_expected_ack_delay); | 1746 | &s->last_expected_ack_delay); |
@@ -1838,9 +1758,7 @@ fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, | |||
1838 | * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1758 | * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1839 | */ | 1759 | */ |
1840 | static void | 1760 | static void |
1841 | qc_fragment_sent (void *cls, | 1761 | qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) |
1842 | struct UDP_MessageWrapper *udpw, | ||
1843 | int result) | ||
1844 | { | 1762 | { |
1845 | struct Plugin *plugin = cls; | 1763 | struct Plugin *plugin = cls; |
1846 | 1764 | ||
@@ -1856,10 +1774,11 @@ qc_fragment_sent (void *cls, | |||
1856 | "# UDP, fragmented msgs, fragments, sent, success", | 1774 | "# UDP, fragmented msgs, fragments, sent, success", |
1857 | 1, | 1775 | 1, |
1858 | GNUNET_NO); | 1776 | GNUNET_NO); |
1859 | GNUNET_STATISTICS_update (plugin->env->stats, | 1777 | GNUNET_STATISTICS_update ( |
1860 | "# UDP, fragmented msgs, fragments bytes, sent, success", | 1778 | plugin->env->stats, |
1861 | udpw->msg_size, | 1779 | "# UDP, fragmented msgs, fragments bytes, sent, success", |
1862 | GNUNET_NO); | 1780 | udpw->msg_size, |
1781 | GNUNET_NO); | ||
1863 | } | 1782 | } |
1864 | else | 1783 | else |
1865 | { | 1784 | { |
@@ -1867,16 +1786,16 @@ qc_fragment_sent (void *cls, | |||
1867 | "Failed to transmit fragment of message with %u bytes to %s\n", | 1786 | "Failed to transmit fragment of message with %u bytes to %s\n", |
1868 | (unsigned int) udpw->payload_size, | 1787 | (unsigned int) udpw->payload_size, |
1869 | GNUNET_i2s (&udpw->session->target)); | 1788 | GNUNET_i2s (&udpw->session->target)); |
1870 | fragmented_message_done (udpw->frag_ctx, | 1789 | fragmented_message_done (udpw->frag_ctx, GNUNET_SYSERR); |
1871 | GNUNET_SYSERR); | ||
1872 | GNUNET_STATISTICS_update (plugin->env->stats, | 1790 | GNUNET_STATISTICS_update (plugin->env->stats, |
1873 | "# UDP, fragmented msgs, fragments, sent, failure", | 1791 | "# UDP, fragmented msgs, fragments, sent, failure", |
1874 | 1, | 1792 | 1, |
1875 | GNUNET_NO); | 1793 | GNUNET_NO); |
1876 | GNUNET_STATISTICS_update (plugin->env->stats, | 1794 | GNUNET_STATISTICS_update ( |
1877 | "# UDP, fragmented msgs, fragments bytes, sent, failure", | 1795 | plugin->env->stats, |
1878 | udpw->msg_size, | 1796 | "# UDP, fragmented msgs, fragments bytes, sent, failure", |
1879 | GNUNET_NO); | 1797 | udpw->msg_size, |
1798 | GNUNET_NO); | ||
1880 | } | 1799 | } |
1881 | } | 1800 | } |
1882 | 1801 | ||
@@ -1891,8 +1810,7 @@ qc_fragment_sent (void *cls, | |||
1891 | * @param msg the message that was created | 1810 | * @param msg the message that was created |
1892 | */ | 1811 | */ |
1893 | static void | 1812 | static void |
1894 | enqueue_fragment (void *cls, | 1813 | enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg) |
1895 | const struct GNUNET_MessageHeader *msg) | ||
1896 | { | 1814 | { |
1897 | struct UDP_FragmentationContext *frag_ctx = cls; | 1815 | struct UDP_FragmentationContext *frag_ctx = cls; |
1898 | struct Plugin *plugin = frag_ctx->plugin; | 1816 | struct Plugin *plugin = frag_ctx->plugin; |
@@ -1900,9 +1818,7 @@ enqueue_fragment (void *cls, | |||
1900 | struct GNUNET_ATS_Session *session = frag_ctx->session; | 1818 | struct GNUNET_ATS_Session *session = frag_ctx->session; |
1901 | size_t msg_len = ntohs (msg->size); | 1819 | size_t msg_len = ntohs (msg->size); |
1902 | 1820 | ||
1903 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1821 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len); |
1904 | "Enqueuing fragment with %u bytes\n", | ||
1905 | msg_len); | ||
1906 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); | 1822 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len); |
1907 | udpw->session = session; | 1823 | udpw->session = session; |
1908 | udpw->msg_buf = (char *) &udpw[1]; | 1824 | udpw->msg_buf = (char *) &udpw[1]; |
@@ -1911,17 +1827,14 @@ enqueue_fragment (void *cls, | |||
1911 | udpw->timeout = frag_ctx->timeout; | 1827 | udpw->timeout = frag_ctx->timeout; |
1912 | udpw->start_time = frag_ctx->start_time; | 1828 | udpw->start_time = frag_ctx->start_time; |
1913 | udpw->transmission_time = frag_ctx->next_frag_time; | 1829 | udpw->transmission_time = frag_ctx->next_frag_time; |
1914 | frag_ctx->next_frag_time | 1830 | frag_ctx->next_frag_time = |
1915 | = GNUNET_TIME_absolute_add (frag_ctx->next_frag_time, | 1831 | GNUNET_TIME_absolute_add (frag_ctx->next_frag_time, |
1916 | frag_ctx->flow_delay_from_other_peer); | 1832 | frag_ctx->flow_delay_from_other_peer); |
1917 | udpw->frag_ctx = frag_ctx; | 1833 | udpw->frag_ctx = frag_ctx; |
1918 | udpw->qc = &qc_fragment_sent; | 1834 | udpw->qc = &qc_fragment_sent; |
1919 | udpw->qc_cls = plugin; | 1835 | udpw->qc_cls = plugin; |
1920 | GNUNET_memcpy (udpw->msg_buf, | 1836 | GNUNET_memcpy (udpw->msg_buf, msg, msg_len); |
1921 | msg, | 1837 | enqueue (plugin, udpw); |
1922 | msg_len); | ||
1923 | enqueue (plugin, | ||
1924 | udpw); | ||
1925 | if (session->address->address_length == sizeof (struct IPv4UdpAddress)) | 1838 | if (session->address->address_length == sizeof (struct IPv4UdpAddress)) |
1926 | schedule_select_v4 (plugin); | 1839 | schedule_select_v4 (plugin); |
1927 | else | 1840 | else |
@@ -1938,9 +1851,7 @@ enqueue_fragment (void *cls, | |||
1938 | * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure | 1851 | * @param result #GNUNET_OK on success, #GNUNET_SYSERR on failure |
1939 | */ | 1852 | */ |
1940 | static void | 1853 | static void |
1941 | qc_message_sent (void *cls, | 1854 | qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) |
1942 | struct UDP_MessageWrapper *udpw, | ||
1943 | int result) | ||
1944 | { | 1855 | { |
1945 | struct Plugin *plugin = cls; | 1856 | struct Plugin *plugin = cls; |
1946 | size_t overhead; | 1857 | size_t overhead; |
@@ -1958,15 +1869,13 @@ qc_message_sent (void *cls, | |||
1958 | { | 1869 | { |
1959 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1870 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1960 | "Message sent via UDP with delay of %s\n", | 1871 | "Message sent via UDP with delay of %s\n", |
1961 | GNUNET_STRINGS_relative_time_to_string (delay, | 1872 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
1962 | GNUNET_YES)); | ||
1963 | } | 1873 | } |
1964 | else | 1874 | else |
1965 | { | 1875 | { |
1966 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1876 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1967 | "Message sent via UDP with delay of %s\n", | 1877 | "Message sent via UDP with delay of %s\n", |
1968 | GNUNET_STRINGS_relative_time_to_string (delay, | 1878 | GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES)); |
1969 | GNUNET_YES)); | ||
1970 | } | 1879 | } |
1971 | udpw->cont (udpw->cont_cls, | 1880 | udpw->cont (udpw->cont_cls, |
1972 | &udpw->session->target, | 1881 | &udpw->session->target, |
@@ -1980,14 +1889,16 @@ qc_message_sent (void *cls, | |||
1980 | "# UDP, unfragmented msgs, messages, sent, success", | 1889 | "# UDP, unfragmented msgs, messages, sent, success", |
1981 | 1, | 1890 | 1, |
1982 | GNUNET_NO); | 1891 | GNUNET_NO); |
1983 | GNUNET_STATISTICS_update (plugin->env->stats, | 1892 | GNUNET_STATISTICS_update ( |
1984 | "# UDP, unfragmented msgs, bytes payload, sent, success", | 1893 | plugin->env->stats, |
1985 | udpw->payload_size, | 1894 | "# UDP, unfragmented msgs, bytes payload, sent, success", |
1986 | GNUNET_NO); | 1895 | udpw->payload_size, |
1987 | GNUNET_STATISTICS_update (plugin->env->stats, | 1896 | GNUNET_NO); |
1988 | "# UDP, unfragmented msgs, bytes overhead, sent, success", | 1897 | GNUNET_STATISTICS_update ( |
1989 | overhead, | 1898 | plugin->env->stats, |
1990 | GNUNET_NO); | 1899 | "# UDP, unfragmented msgs, bytes overhead, sent, success", |
1900 | overhead, | ||
1901 | GNUNET_NO); | ||
1991 | GNUNET_STATISTICS_update (plugin->env->stats, | 1902 | GNUNET_STATISTICS_update (plugin->env->stats, |
1992 | "# UDP, total, bytes overhead, sent", | 1903 | "# UDP, total, bytes overhead, sent", |
1993 | overhead, | 1904 | overhead, |
@@ -2003,14 +1914,16 @@ qc_message_sent (void *cls, | |||
2003 | "# UDP, unfragmented msgs, messages, sent, failure", | 1914 | "# UDP, unfragmented msgs, messages, sent, failure", |
2004 | 1, | 1915 | 1, |
2005 | GNUNET_NO); | 1916 | GNUNET_NO); |
2006 | GNUNET_STATISTICS_update (plugin->env->stats, | 1917 | GNUNET_STATISTICS_update ( |
2007 | "# UDP, unfragmented msgs, bytes payload, sent, failure", | 1918 | plugin->env->stats, |
2008 | udpw->payload_size, | 1919 | "# UDP, unfragmented msgs, bytes payload, sent, failure", |
2009 | GNUNET_NO); | 1920 | udpw->payload_size, |
2010 | GNUNET_STATISTICS_update (plugin->env->stats, | 1921 | GNUNET_NO); |
2011 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", | 1922 | GNUNET_STATISTICS_update ( |
2012 | overhead, | 1923 | plugin->env->stats, |
2013 | GNUNET_NO); | 1924 | "# UDP, unfragmented msgs, bytes overhead, sent, failure", |
1925 | overhead, | ||
1926 | GNUNET_NO); | ||
2014 | } | 1927 | } |
2015 | } | 1928 | } |
2016 | 1929 | ||
@@ -2053,18 +1966,18 @@ udp_plugin_send (void *cls, | |||
2053 | void *cont_cls) | 1966 | void *cont_cls) |
2054 | { | 1967 | { |
2055 | struct Plugin *plugin = cls; | 1968 | struct Plugin *plugin = cls; |
2056 | size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage); | 1969 | size_t udpmlen = msgbuf_size + sizeof (struct UDPMessage); |
2057 | struct UDP_FragmentationContext *frag_ctx; | 1970 | struct UDP_FragmentationContext *frag_ctx; |
2058 | struct UDP_MessageWrapper *udpw; | 1971 | struct UDP_MessageWrapper *udpw; |
2059 | struct UDPMessage *udp; | 1972 | struct UDPMessage *udp; |
2060 | char mbuf[udpmlen] GNUNET_ALIGN; | 1973 | char mbuf[udpmlen] GNUNET_ALIGN; |
2061 | struct GNUNET_TIME_Relative latency; | 1974 | struct GNUNET_TIME_Relative latency; |
2062 | 1975 | ||
2063 | if ( (sizeof(struct IPv6UdpAddress) == s->address->address_length) && | 1976 | if ((sizeof (struct IPv6UdpAddress) == s->address->address_length) && |
2064 | (NULL == plugin->sockv6) ) | 1977 | (NULL == plugin->sockv6)) |
2065 | return GNUNET_SYSERR; | 1978 | return GNUNET_SYSERR; |
2066 | if ( (sizeof(struct IPv4UdpAddress) == s->address->address_length) && | 1979 | if ((sizeof (struct IPv4UdpAddress) == s->address->address_length) && |
2067 | (NULL == plugin->sockv4) ) | 1980 | (NULL == plugin->sockv4)) |
2068 | return GNUNET_SYSERR; | 1981 | return GNUNET_SYSERR; |
2069 | if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) | 1982 | if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE) |
2070 | { | 1983 | { |
@@ -2112,22 +2025,19 @@ udp_plugin_send (void *cls, | |||
2112 | udpw->start_time = GNUNET_TIME_absolute_get (); | 2025 | udpw->start_time = GNUNET_TIME_absolute_get (); |
2113 | udpw->timeout = GNUNET_TIME_relative_to_absolute (to); | 2026 | udpw->timeout = GNUNET_TIME_relative_to_absolute (to); |
2114 | udpw->transmission_time = s->last_transmit_time; | 2027 | udpw->transmission_time = s->last_transmit_time; |
2115 | s->last_transmit_time | 2028 | s->last_transmit_time = |
2116 | = GNUNET_TIME_absolute_add (s->last_transmit_time, | 2029 | GNUNET_TIME_absolute_add (s->last_transmit_time, |
2117 | s->flow_delay_from_other_peer); | 2030 | s->flow_delay_from_other_peer); |
2118 | udpw->cont = cont; | 2031 | udpw->cont = cont; |
2119 | udpw->cont_cls = cont_cls; | 2032 | udpw->cont_cls = cont_cls; |
2120 | udpw->frag_ctx = NULL; | 2033 | udpw->frag_ctx = NULL; |
2121 | udpw->qc = &qc_message_sent; | 2034 | udpw->qc = &qc_message_sent; |
2122 | udpw->qc_cls = plugin; | 2035 | udpw->qc_cls = plugin; |
2123 | GNUNET_memcpy (udpw->msg_buf, | 2036 | GNUNET_memcpy (udpw->msg_buf, udp, sizeof (struct UDPMessage)); |
2124 | udp, | 2037 | GNUNET_memcpy (&udpw->msg_buf[sizeof (struct UDPMessage)], |
2125 | sizeof (struct UDPMessage)); | 2038 | msgbuf, |
2126 | GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)], | 2039 | msgbuf_size); |
2127 | msgbuf, | 2040 | enqueue (plugin, udpw); |
2128 | msgbuf_size); | ||
2129 | enqueue (plugin, | ||
2130 | udpw); | ||
2131 | GNUNET_STATISTICS_update (plugin->env->stats, | 2041 | GNUNET_STATISTICS_update (plugin->env->stats, |
2132 | "# UDP, unfragmented messages queued total", | 2042 | "# UDP, unfragmented messages queued total", |
2133 | 1, | 2043 | 1, |
@@ -2146,9 +2056,7 @@ udp_plugin_send (void *cls, | |||
2146 | /* fragmented message */ | 2056 | /* fragmented message */ |
2147 | if (NULL != s->frag_ctx) | 2057 | if (NULL != s->frag_ctx) |
2148 | return GNUNET_SYSERR; | 2058 | return GNUNET_SYSERR; |
2149 | GNUNET_memcpy (&udp[1], | 2059 | GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size); |
2150 | msgbuf, | ||
2151 | msgbuf_size); | ||
2152 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); | 2060 | frag_ctx = GNUNET_new (struct UDP_FragmentationContext); |
2153 | frag_ctx->plugin = plugin; | 2061 | frag_ctx->plugin = plugin; |
2154 | frag_ctx->session = s; | 2062 | frag_ctx->session = s; |
@@ -2156,12 +2064,12 @@ udp_plugin_send (void *cls, | |||
2156 | frag_ctx->cont_cls = cont_cls; | 2064 | frag_ctx->cont_cls = cont_cls; |
2157 | frag_ctx->start_time = GNUNET_TIME_absolute_get (); | 2065 | frag_ctx->start_time = GNUNET_TIME_absolute_get (); |
2158 | frag_ctx->next_frag_time = s->last_transmit_time; | 2066 | frag_ctx->next_frag_time = s->last_transmit_time; |
2159 | frag_ctx->flow_delay_from_other_peer | 2067 | frag_ctx->flow_delay_from_other_peer = |
2160 | = GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer, | 2068 | GNUNET_TIME_relative_divide (s->flow_delay_from_other_peer, |
2161 | 1 + (msgbuf_size / | 2069 | 1 + (msgbuf_size / UDP_MTU)); |
2162 | UDP_MTU)); | ||
2163 | frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to); | 2070 | frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to); |
2164 | frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */ | 2071 | frag_ctx->payload_size = |
2072 | msgbuf_size; /* unfragmented message size without UDP overhead */ | ||
2165 | frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ | 2073 | frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */ |
2166 | frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, | 2074 | frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, |
2167 | UDP_MTU, | 2075 | UDP_MTU, |
@@ -2177,15 +2085,13 @@ udp_plugin_send (void *cls, | |||
2177 | if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) | 2085 | if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) |
2178 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2086 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2179 | "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", | 2087 | "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", |
2180 | GNUNET_STRINGS_relative_time_to_string (latency, | 2088 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), |
2181 | GNUNET_YES), | ||
2182 | GNUNET_i2s (&s->target), | 2089 | GNUNET_i2s (&s->target), |
2183 | (unsigned int) s->msgs_in_queue); | 2090 | (unsigned int) s->msgs_in_queue); |
2184 | else | 2091 | else |
2185 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2092 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2186 | "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", | 2093 | "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n", |
2187 | GNUNET_STRINGS_relative_time_to_string (latency, | 2094 | GNUNET_STRINGS_relative_time_to_string (latency, GNUNET_YES), |
2188 | GNUNET_YES), | ||
2189 | GNUNET_i2s (&s->target), | 2095 | GNUNET_i2s (&s->target), |
2190 | (unsigned int) s->msgs_in_queue); | 2096 | (unsigned int) s->msgs_in_queue); |
2191 | 2097 | ||
@@ -2202,9 +2108,7 @@ udp_plugin_send (void *cls, | |||
2202 | frag_ctx->payload_size, | 2108 | frag_ctx->payload_size, |
2203 | GNUNET_NO); | 2109 | GNUNET_NO); |
2204 | } | 2110 | } |
2205 | notify_session_monitor (s->plugin, | 2111 | notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); |
2206 | s, | ||
2207 | GNUNET_TRANSPORT_SS_UPDATE); | ||
2208 | return udpmlen; | 2112 | return udpmlen; |
2209 | } | 2113 | } |
2210 | 2114 | ||
@@ -2236,7 +2140,6 @@ struct FindReceiveContext | |||
2236 | * Number of bytes in @e udp_addr. | 2140 | * Number of bytes in @e udp_addr. |
2237 | */ | 2141 | */ |
2238 | size_t udp_addr_len; | 2142 | size_t udp_addr_len; |
2239 | |||
2240 | }; | 2143 | }; |
2241 | 2144 | ||
2242 | 2145 | ||
@@ -2259,10 +2162,8 @@ find_receive_context (void *cls, | |||
2259 | struct FindReceiveContext *frc = cls; | 2162 | struct FindReceiveContext *frc = cls; |
2260 | struct DefragContext *e = element; | 2163 | struct DefragContext *e = element; |
2261 | 2164 | ||
2262 | if ( (frc->udp_addr_len == e->udp_addr_len) && | 2165 | if ((frc->udp_addr_len == e->udp_addr_len) && |
2263 | (0 == memcmp (frc->udp_addr, | 2166 | (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len))) |
2264 | e->udp_addr, | ||
2265 | frc->udp_addr_len)) ) | ||
2266 | { | 2167 | { |
2267 | frc->rc = e; | 2168 | frc->rc = e; |
2268 | return GNUNET_NO; | 2169 | return GNUNET_NO; |
@@ -2280,8 +2181,7 @@ find_receive_context (void *cls, | |||
2280 | * @return #GNUNET_OK on success | 2181 | * @return #GNUNET_OK on success |
2281 | */ | 2182 | */ |
2282 | static int | 2183 | static int |
2283 | udp_disconnect_session (void *cls, | 2184 | udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s) |
2284 | struct GNUNET_ATS_Session *s) | ||
2285 | { | 2185 | { |
2286 | struct Plugin *plugin = cls; | 2186 | struct Plugin *plugin = cls; |
2287 | struct UDP_MessageWrapper *udpw; | 2187 | struct UDP_MessageWrapper *udpw; |
@@ -2304,13 +2204,11 @@ udp_disconnect_session (void *cls, | |||
2304 | if (NULL != s->frag_ctx) | 2204 | if (NULL != s->frag_ctx) |
2305 | { | 2205 | { |
2306 | /* Remove fragmented message due to disconnect */ | 2206 | /* Remove fragmented message due to disconnect */ |
2307 | fragmented_message_done (s->frag_ctx, | 2207 | fragmented_message_done (s->frag_ctx, GNUNET_SYSERR); |
2308 | GNUNET_SYSERR); | ||
2309 | } | 2208 | } |
2310 | GNUNET_assert (GNUNET_YES == | 2209 | GNUNET_assert ( |
2311 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, | 2210 | GNUNET_YES == |
2312 | &s->target, | 2211 | GNUNET_CONTAINER_multipeermap_remove (plugin->sessions, &s->target, s)); |
2313 | s)); | ||
2314 | frc.rc = NULL; | 2212 | frc.rc = NULL; |
2315 | frc.udp_addr = s->address->address; | 2213 | frc.udp_addr = s->address->address; |
2316 | frc.udp_addr_len = s->address->address_length; | 2214 | frc.udp_addr_len = s->address->address_length; |
@@ -2336,11 +2234,8 @@ udp_disconnect_session (void *cls, | |||
2336 | next = udpw->next; | 2234 | next = udpw->next; |
2337 | if (udpw->session == s) | 2235 | if (udpw->session == s) |
2338 | { | 2236 | { |
2339 | dequeue (plugin, | 2237 | dequeue (plugin, udpw); |
2340 | udpw); | 2238 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
2341 | udpw->qc (udpw->qc_cls, | ||
2342 | udpw, | ||
2343 | GNUNET_SYSERR); | ||
2344 | GNUNET_free (udpw); | 2239 | GNUNET_free (udpw); |
2345 | } | 2240 | } |
2346 | } | 2241 | } |
@@ -2350,16 +2245,12 @@ udp_disconnect_session (void *cls, | |||
2350 | next = udpw->next; | 2245 | next = udpw->next; |
2351 | if (udpw->session == s) | 2246 | if (udpw->session == s) |
2352 | { | 2247 | { |
2353 | dequeue (plugin, | 2248 | dequeue (plugin, udpw); |
2354 | udpw); | 2249 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
2355 | udpw->qc (udpw->qc_cls, | ||
2356 | udpw, | ||
2357 | GNUNET_SYSERR); | ||
2358 | GNUNET_free (udpw); | 2250 | GNUNET_free (udpw); |
2359 | } | 2251 | } |
2360 | } | 2252 | } |
2361 | if ( (NULL != s->frag_ctx) && | 2253 | if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont)) |
2362 | (NULL != s->frag_ctx->cont) ) | ||
2363 | { | 2254 | { |
2364 | /* The 'frag_ctx' itself will be freed in #free_session() a bit | 2255 | /* The 'frag_ctx' itself will be freed in #free_session() a bit |
2365 | later, as it might be in use right now */ | 2256 | later, as it might be in use right now */ |
@@ -2372,12 +2263,8 @@ udp_disconnect_session (void *cls, | |||
2372 | s->frag_ctx->payload_size, | 2263 | s->frag_ctx->payload_size, |
2373 | s->frag_ctx->on_wire_size); | 2264 | s->frag_ctx->on_wire_size); |
2374 | } | 2265 | } |
2375 | notify_session_monitor (s->plugin, | 2266 | notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_DONE); |
2376 | s, | 2267 | plugin->env->session_end (plugin->env->cls, s->address, s); |
2377 | GNUNET_TRANSPORT_SS_DONE); | ||
2378 | plugin->env->session_end (plugin->env->cls, | ||
2379 | s->address, | ||
2380 | s); | ||
2381 | GNUNET_STATISTICS_set (plugin->env->stats, | 2268 | GNUNET_STATISTICS_set (plugin->env->stats, |
2382 | "# UDP sessions active", | 2269 | "# UDP sessions active", |
2383 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), | 2270 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), |
@@ -2409,17 +2296,17 @@ read_process_ack (struct Plugin *plugin, | |||
2409 | struct GNUNET_TIME_Relative flow_delay; | 2296 | struct GNUNET_TIME_Relative flow_delay; |
2410 | 2297 | ||
2411 | /* check message format */ | 2298 | /* check message format */ |
2412 | if (ntohs (msg->size) | 2299 | if (ntohs (msg->size) < |
2413 | < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader)) | 2300 | sizeof (struct UDP_ACK_Message) + sizeof (struct GNUNET_MessageHeader)) |
2414 | { | 2301 | { |
2415 | GNUNET_break_op (0); | 2302 | GNUNET_break_op (0); |
2416 | return; | 2303 | return; |
2417 | } | 2304 | } |
2418 | udp_ack = (const struct UDP_ACK_Message *) msg; | 2305 | udp_ack = (const struct UDP_ACK_Message *) msg; |
2419 | ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; | 2306 | ack = (const struct GNUNET_MessageHeader *) &udp_ack[1]; |
2420 | if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message)) | 2307 | if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDP_ACK_Message)) |
2421 | { | 2308 | { |
2422 | GNUNET_break_op(0); | 2309 | GNUNET_break_op (0); |
2423 | return; | 2310 | return; |
2424 | } | 2311 | } |
2425 | 2312 | ||
@@ -2429,8 +2316,7 @@ read_process_ack (struct Plugin *plugin, | |||
2429 | udp_addr, | 2316 | udp_addr, |
2430 | udp_addr_len, | 2317 | udp_addr_len, |
2431 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 2318 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
2432 | s = udp_plugin_lookup_session (plugin, | 2319 | s = udp_plugin_lookup_session (plugin, address); |
2433 | address); | ||
2434 | if (NULL == s) | 2320 | if (NULL == s) |
2435 | { | 2321 | { |
2436 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2322 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -2461,39 +2347,32 @@ read_process_ack (struct Plugin *plugin, | |||
2461 | LOG (GNUNET_ERROR_TYPE_INFO, | 2347 | LOG (GNUNET_ERROR_TYPE_INFO, |
2462 | "Asked to disconnect UDP session of %s\n", | 2348 | "Asked to disconnect UDP session of %s\n", |
2463 | GNUNET_i2s (&udp_ack->sender)); | 2349 | GNUNET_i2s (&udp_ack->sender)); |
2464 | udp_disconnect_session (plugin, | 2350 | udp_disconnect_session (plugin, s); |
2465 | s); | ||
2466 | return; | 2351 | return; |
2467 | } | 2352 | } |
2468 | flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); | 2353 | flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay); |
2469 | if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) | 2354 | if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) |
2470 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2355 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2471 | "We received a sending delay of %s for %s\n", | 2356 | "We received a sending delay of %s for %s\n", |
2472 | GNUNET_STRINGS_relative_time_to_string (flow_delay, | 2357 | GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), |
2473 | GNUNET_YES), | ||
2474 | GNUNET_i2s (&udp_ack->sender)); | 2358 | GNUNET_i2s (&udp_ack->sender)); |
2475 | else | 2359 | else |
2476 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2360 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2477 | "We received a sending delay of %s for %s\n", | 2361 | "We received a sending delay of %s for %s\n", |
2478 | GNUNET_STRINGS_relative_time_to_string (flow_delay, | 2362 | GNUNET_STRINGS_relative_time_to_string (flow_delay, GNUNET_YES), |
2479 | GNUNET_YES), | ||
2480 | GNUNET_i2s (&udp_ack->sender)); | 2363 | GNUNET_i2s (&udp_ack->sender)); |
2481 | /* Flow delay is for the reassembled packet, however, our delay | 2364 | /* Flow delay is for the reassembled packet, however, our delay |
2482 | is per packet, so we need to adjust: */ | 2365 | is per packet, so we need to adjust: */ |
2483 | s->flow_delay_from_other_peer = flow_delay; | 2366 | s->flow_delay_from_other_peer = flow_delay; |
2484 | 2367 | ||
2485 | /* Handle ACK */ | 2368 | /* Handle ACK */ |
2486 | if (GNUNET_OK != | 2369 | if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, ack)) |
2487 | GNUNET_FRAGMENT_process_ack (s->frag_ctx->frag, | ||
2488 | ack)) | ||
2489 | { | 2370 | { |
2490 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2371 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2491 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", | 2372 | "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", |
2492 | (unsigned int) ntohs (msg->size), | 2373 | (unsigned int) ntohs (msg->size), |
2493 | GNUNET_i2s (&udp_ack->sender), | 2374 | GNUNET_i2s (&udp_ack->sender), |
2494 | udp_address_to_string (plugin, | 2375 | udp_address_to_string (plugin, udp_addr, udp_addr_len)); |
2495 | udp_addr, | ||
2496 | udp_addr_len)); | ||
2497 | /* Expect more ACKs to arrive */ | 2376 | /* Expect more ACKs to arrive */ |
2498 | return; | 2377 | return; |
2499 | } | 2378 | } |
@@ -2502,11 +2381,8 @@ read_process_ack (struct Plugin *plugin, | |||
2502 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2381 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2503 | "Message from %s at %s full ACK'ed\n", | 2382 | "Message from %s at %s full ACK'ed\n", |
2504 | GNUNET_i2s (&udp_ack->sender), | 2383 | GNUNET_i2s (&udp_ack->sender), |
2505 | udp_address_to_string (plugin, | 2384 | udp_address_to_string (plugin, udp_addr, udp_addr_len)); |
2506 | udp_addr, | 2385 | fragmented_message_done (s->frag_ctx, GNUNET_OK); |
2507 | udp_addr_len)); | ||
2508 | fragmented_message_done (s->frag_ctx, | ||
2509 | GNUNET_OK); | ||
2510 | } | 2386 | } |
2511 | 2387 | ||
2512 | 2388 | ||
@@ -2528,11 +2404,8 @@ process_inbound_tokenized_messages (void *cls, | |||
2528 | if (GNUNET_YES == session->in_destroy) | 2404 | if (GNUNET_YES == session->in_destroy) |
2529 | return GNUNET_OK; | 2405 | return GNUNET_OK; |
2530 | reschedule_session_timeout (session); | 2406 | reschedule_session_timeout (session); |
2531 | session->flow_delay_for_other_peer | 2407 | session->flow_delay_for_other_peer = |
2532 | = plugin->env->receive (plugin->env->cls, | 2408 | plugin->env->receive (plugin->env->cls, session->address, session, hdr); |
2533 | session->address, | ||
2534 | session, | ||
2535 | hdr); | ||
2536 | return GNUNET_OK; | 2409 | return GNUNET_OK; |
2537 | } | 2410 | } |
2538 | 2411 | ||
@@ -2552,8 +2425,7 @@ disconnect_and_free_it (void *cls, | |||
2552 | { | 2425 | { |
2553 | struct Plugin *plugin = cls; | 2426 | struct Plugin *plugin = cls; |
2554 | 2427 | ||
2555 | udp_disconnect_session (plugin, | 2428 | udp_disconnect_session (plugin, value); |
2556 | value); | ||
2557 | return GNUNET_OK; | 2429 | return GNUNET_OK; |
2558 | } | 2430 | } |
2559 | 2431 | ||
@@ -2567,8 +2439,7 @@ disconnect_and_free_it (void *cls, | |||
2567 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed | 2439 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the operation failed |
2568 | */ | 2440 | */ |
2569 | static void | 2441 | static void |
2570 | udp_disconnect (void *cls, | 2442 | udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) |
2571 | const struct GNUNET_PeerIdentity *target) | ||
2572 | { | 2443 | { |
2573 | struct Plugin *plugin = cls; | 2444 | struct Plugin *plugin = cls; |
2574 | 2445 | ||
@@ -2600,12 +2471,8 @@ session_timeout (void *cls) | |||
2600 | { | 2471 | { |
2601 | /* not actually our turn yet, but let's at least update | 2472 | /* not actually our turn yet, but let's at least update |
2602 | the monitor, it may think we're about to die ... */ | 2473 | the monitor, it may think we're about to die ... */ |
2603 | notify_session_monitor (s->plugin, | 2474 | notify_session_monitor (s->plugin, s, GNUNET_TRANSPORT_SS_UPDATE); |
2604 | s, | 2475 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, &session_timeout, s); |
2605 | GNUNET_TRANSPORT_SS_UPDATE); | ||
2606 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (left, | ||
2607 | &session_timeout, | ||
2608 | s); | ||
2609 | return; | 2476 | return; |
2610 | } | 2477 | } |
2611 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2478 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2614,8 +2481,7 @@ session_timeout (void *cls) | |||
2614 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, | 2481 | GNUNET_STRINGS_relative_time_to_string (UDP_SESSION_TIME_OUT, |
2615 | GNUNET_YES)); | 2482 | GNUNET_YES)); |
2616 | /* call session destroy function */ | 2483 | /* call session destroy function */ |
2617 | udp_disconnect_session (plugin, | 2484 | udp_disconnect_session (plugin, s); |
2618 | s); | ||
2619 | } | 2485 | } |
2620 | 2486 | ||
2621 | 2487 | ||
@@ -2639,21 +2505,19 @@ udp_plugin_create_session (void *cls, | |||
2639 | struct GNUNET_ATS_Session *s; | 2505 | struct GNUNET_ATS_Session *s; |
2640 | 2506 | ||
2641 | s = GNUNET_new (struct GNUNET_ATS_Session); | 2507 | s = GNUNET_new (struct GNUNET_ATS_Session); |
2642 | s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, | 2508 | s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, s); |
2643 | s); | ||
2644 | s->plugin = plugin; | 2509 | s->plugin = plugin; |
2645 | s->address = GNUNET_HELLO_address_copy (address); | 2510 | s->address = GNUNET_HELLO_address_copy (address); |
2646 | s->target = address->peer; | 2511 | s->target = address->peer; |
2647 | s->last_transmit_time = GNUNET_TIME_absolute_get (); | 2512 | s->last_transmit_time = GNUNET_TIME_absolute_get (); |
2648 | s->last_expected_ack_delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 2513 | s->last_expected_ack_delay = |
2649 | 250); | 2514 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250); |
2650 | s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; | 2515 | s->last_expected_msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; |
2651 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; | 2516 | s->flow_delay_from_other_peer = GNUNET_TIME_UNIT_ZERO; |
2652 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; | 2517 | s->flow_delay_for_other_peer = GNUNET_TIME_UNIT_ZERO; |
2653 | s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); | 2518 | s->timeout = GNUNET_TIME_relative_to_absolute (UDP_SESSION_TIME_OUT); |
2654 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, | 2519 | s->timeout_task = |
2655 | &session_timeout, | 2520 | GNUNET_SCHEDULER_add_delayed (UDP_SESSION_TIME_OUT, &session_timeout, s); |
2656 | s); | ||
2657 | s->scope = network_type; | 2521 | s->scope = network_type; |
2658 | 2522 | ||
2659 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2523 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -2663,18 +2527,16 @@ udp_plugin_create_session (void *cls, | |||
2663 | udp_address_to_string (plugin, | 2527 | udp_address_to_string (plugin, |
2664 | address->address, | 2528 | address->address, |
2665 | address->address_length)); | 2529 | address->address_length)); |
2666 | GNUNET_assert (GNUNET_OK == | 2530 | GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_put ( |
2667 | GNUNET_CONTAINER_multipeermap_put (plugin->sessions, | 2531 | plugin->sessions, |
2668 | &s->target, | 2532 | &s->target, |
2669 | s, | 2533 | s, |
2670 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); | 2534 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); |
2671 | GNUNET_STATISTICS_set (plugin->env->stats, | 2535 | GNUNET_STATISTICS_set (plugin->env->stats, |
2672 | "# UDP sessions active", | 2536 | "# UDP sessions active", |
2673 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), | 2537 | GNUNET_CONTAINER_multipeermap_size (plugin->sessions), |
2674 | GNUNET_NO); | 2538 | GNUNET_NO); |
2675 | notify_session_monitor (plugin, | 2539 | notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_INIT); |
2676 | s, | ||
2677 | GNUNET_TRANSPORT_SS_INIT); | ||
2678 | return s; | 2540 | return s; |
2679 | } | 2541 | } |
2680 | 2542 | ||
@@ -2688,8 +2550,7 @@ udp_plugin_create_session (void *cls, | |||
2688 | * @return the session or NULL of max connections exceeded | 2550 | * @return the session or NULL of max connections exceeded |
2689 | */ | 2551 | */ |
2690 | static struct GNUNET_ATS_Session * | 2552 | static struct GNUNET_ATS_Session * |
2691 | udp_plugin_get_session (void *cls, | 2553 | udp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
2692 | const struct GNUNET_HELLO_Address *address) | ||
2693 | { | 2554 | { |
2694 | struct Plugin *plugin = cls; | 2555 | struct Plugin *plugin = cls; |
2695 | struct GNUNET_ATS_Session *s; | 2556 | struct GNUNET_ATS_Session *s; |
@@ -2702,14 +2563,13 @@ udp_plugin_get_session (void *cls, | |||
2702 | GNUNET_break (0); | 2563 | GNUNET_break (0); |
2703 | return NULL; | 2564 | return NULL; |
2704 | } | 2565 | } |
2705 | if ( (address->address_length != sizeof(struct IPv4UdpAddress)) && | 2566 | if ((address->address_length != sizeof (struct IPv4UdpAddress)) && |
2706 | (address->address_length != sizeof(struct IPv6UdpAddress)) ) | 2567 | (address->address_length != sizeof (struct IPv6UdpAddress))) |
2707 | { | 2568 | { |
2708 | GNUNET_break_op (0); | 2569 | GNUNET_break_op (0); |
2709 | return NULL; | 2570 | return NULL; |
2710 | } | 2571 | } |
2711 | if (NULL != (s = udp_plugin_lookup_session (cls, | 2572 | if (NULL != (s = udp_plugin_lookup_session (cls, address))) |
2712 | address))) | ||
2713 | return s; | 2573 | return s; |
2714 | 2574 | ||
2715 | /* need to create new session */ | 2575 | /* need to create new session */ |
@@ -2746,9 +2606,7 @@ udp_plugin_get_session (void *cls, | |||
2746 | sizeof (v6)); | 2606 | sizeof (v6)); |
2747 | } | 2607 | } |
2748 | GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); | 2608 | GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); |
2749 | return udp_plugin_create_session (cls, | 2609 | return udp_plugin_create_session (cls, address, network_type); |
2750 | address, | ||
2751 | network_type); | ||
2752 | } | 2610 | } |
2753 | 2611 | ||
2754 | 2612 | ||
@@ -2774,13 +2632,13 @@ process_udp_message (struct Plugin *plugin, | |||
2774 | GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); | 2632 | GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type); |
2775 | if (0 != ntohl (msg->reserved)) | 2633 | if (0 != ntohl (msg->reserved)) |
2776 | { | 2634 | { |
2777 | GNUNET_break_op(0); | 2635 | GNUNET_break_op (0); |
2778 | return; | 2636 | return; |
2779 | } | 2637 | } |
2780 | if (ntohs (msg->header.size) | 2638 | if (ntohs (msg->header.size) < |
2781 | < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage)) | 2639 | sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) |
2782 | { | 2640 | { |
2783 | GNUNET_break_op(0); | 2641 | GNUNET_break_op (0); |
2784 | return; | 2642 | return; |
2785 | } | 2643 | } |
2786 | 2644 | ||
@@ -2789,32 +2647,22 @@ process_udp_message (struct Plugin *plugin, | |||
2789 | udp_addr, | 2647 | udp_addr, |
2790 | udp_addr_len, | 2648 | udp_addr_len, |
2791 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 2649 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
2792 | if (NULL == | 2650 | if (NULL == (s = udp_plugin_lookup_session (plugin, address))) |
2793 | (s = udp_plugin_lookup_session (plugin, | ||
2794 | address))) | ||
2795 | { | 2651 | { |
2796 | s = udp_plugin_create_session (plugin, | 2652 | s = udp_plugin_create_session (plugin, address, network_type); |
2797 | address, | 2653 | plugin->env->session_start (plugin->env->cls, address, s, s->scope); |
2798 | network_type); | 2654 | notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UP); |
2799 | plugin->env->session_start (plugin->env->cls, | ||
2800 | address, | ||
2801 | s, | ||
2802 | s->scope); | ||
2803 | notify_session_monitor (plugin, | ||
2804 | s, | ||
2805 | GNUNET_TRANSPORT_SS_UP); | ||
2806 | } | 2655 | } |
2807 | GNUNET_free (address); | 2656 | GNUNET_free (address); |
2808 | 2657 | ||
2809 | s->rc++; | 2658 | s->rc++; |
2810 | GNUNET_MST_from_buffer (s->mst, | 2659 | GNUNET_MST_from_buffer (s->mst, |
2811 | (const char *) &msg[1], | 2660 | (const char *) &msg[1], |
2812 | ntohs (msg->header.size) - sizeof(struct UDPMessage), | 2661 | ntohs (msg->header.size) - sizeof (struct UDPMessage), |
2813 | GNUNET_YES, | 2662 | GNUNET_YES, |
2814 | GNUNET_NO); | 2663 | GNUNET_NO); |
2815 | s->rc--; | 2664 | s->rc--; |
2816 | if ( (0 == s->rc) && | 2665 | if ((0 == s->rc) && (GNUNET_YES == s->in_destroy)) |
2817 | (GNUNET_YES == s->in_destroy) ) | ||
2818 | free_session (s); | 2666 | free_session (s); |
2819 | } | 2667 | } |
2820 | 2668 | ||
@@ -2826,8 +2674,7 @@ process_udp_message (struct Plugin *plugin, | |||
2826 | * @param msg the message | 2674 | * @param msg the message |
2827 | */ | 2675 | */ |
2828 | static void | 2676 | static void |
2829 | fragment_msg_proc (void *cls, | 2677 | fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg) |
2830 | const struct GNUNET_MessageHeader *msg) | ||
2831 | { | 2678 | { |
2832 | struct DefragContext *dc = cls; | 2679 | struct DefragContext *dc = cls; |
2833 | const struct UDPMessage *um; | 2680 | const struct UDPMessage *um; |
@@ -2837,7 +2684,7 @@ fragment_msg_proc (void *cls, | |||
2837 | GNUNET_break_op (0); | 2684 | GNUNET_break_op (0); |
2838 | return; | 2685 | return; |
2839 | } | 2686 | } |
2840 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) | 2687 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) |
2841 | { | 2688 | { |
2842 | GNUNET_break_op (0); | 2689 | GNUNET_break_op (0); |
2843 | return; | 2690 | return; |
@@ -2863,9 +2710,7 @@ fragment_msg_proc (void *cls, | |||
2863 | * #GNUNET_SYSERR if we failed to send the ACK | 2710 | * #GNUNET_SYSERR if we failed to send the ACK |
2864 | */ | 2711 | */ |
2865 | static void | 2712 | static void |
2866 | ack_message_sent (void *cls, | 2713 | ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result) |
2867 | struct UDP_MessageWrapper *udpw, | ||
2868 | int result) | ||
2869 | { | 2714 | { |
2870 | struct Plugin *plugin = cls; | 2715 | struct Plugin *plugin = cls; |
2871 | 2716 | ||
@@ -2894,13 +2739,11 @@ ack_message_sent (void *cls, | |||
2894 | * @param msg ack to transmit | 2739 | * @param msg ack to transmit |
2895 | */ | 2740 | */ |
2896 | static void | 2741 | static void |
2897 | ack_proc (void *cls, | 2742 | ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg) |
2898 | uint32_t id, | ||
2899 | const struct GNUNET_MessageHeader *msg) | ||
2900 | { | 2743 | { |
2901 | struct DefragContext *rc = cls; | 2744 | struct DefragContext *rc = cls; |
2902 | struct Plugin *plugin = rc->plugin; | 2745 | struct Plugin *plugin = rc->plugin; |
2903 | size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size); | 2746 | size_t msize = sizeof (struct UDP_ACK_Message) + ntohs (msg->size); |
2904 | struct UDP_ACK_Message *udp_ack; | 2747 | struct UDP_ACK_Message *udp_ack; |
2905 | uint32_t delay; | 2748 | uint32_t delay; |
2906 | struct UDP_MessageWrapper *udpw; | 2749 | struct UDP_MessageWrapper *udpw; |
@@ -2922,16 +2765,13 @@ ack_proc (void *cls, | |||
2922 | rc->udp_addr, | 2765 | rc->udp_addr, |
2923 | rc->udp_addr_len, | 2766 | rc->udp_addr_len, |
2924 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 2767 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
2925 | s = udp_plugin_lookup_session (plugin, | 2768 | s = udp_plugin_lookup_session (plugin, address); |
2926 | address); | ||
2927 | GNUNET_HELLO_address_free (address); | 2769 | GNUNET_HELLO_address_free (address); |
2928 | if (NULL == s) | 2770 | if (NULL == s) |
2929 | { | 2771 | { |
2930 | LOG (GNUNET_ERROR_TYPE_ERROR, | 2772 | LOG (GNUNET_ERROR_TYPE_ERROR, |
2931 | "Trying to transmit ACK to peer `%s' but no session found!\n", | 2773 | "Trying to transmit ACK to peer `%s' but no session found!\n", |
2932 | udp_address_to_string (plugin, | 2774 | udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len)); |
2933 | rc->udp_addr, | ||
2934 | rc->udp_addr_len)); | ||
2935 | GNUNET_CONTAINER_heap_remove_node (rc->hnode); | 2775 | GNUNET_CONTAINER_heap_remove_node (rc->hnode); |
2936 | GNUNET_DEFRAGMENT_context_destroy (rc->defrag); | 2776 | GNUNET_DEFRAGMENT_context_destroy (rc->defrag); |
2937 | GNUNET_free (rc); | 2777 | GNUNET_free (rc); |
@@ -2950,9 +2790,7 @@ ack_proc (void *cls, | |||
2950 | delay = UINT32_MAX - 1; /* largest value we can communicate */ | 2790 | delay = UINT32_MAX - 1; /* largest value we can communicate */ |
2951 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2791 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2952 | "Sending ACK to `%s' including delay of %s\n", | 2792 | "Sending ACK to `%s' including delay of %s\n", |
2953 | udp_address_to_string (plugin, | 2793 | udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len), |
2954 | rc->udp_addr, | ||
2955 | rc->udp_addr_len), | ||
2956 | GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, | 2794 | GNUNET_STRINGS_relative_time_to_string (s->flow_delay_for_other_peer, |
2957 | GNUNET_YES)); | 2795 | GNUNET_YES)); |
2958 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); | 2796 | udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize); |
@@ -2969,14 +2807,9 @@ ack_proc (void *cls, | |||
2969 | udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); | 2807 | udp_ack->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); |
2970 | udp_ack->delay = htonl (delay); | 2808 | udp_ack->delay = htonl (delay); |
2971 | udp_ack->sender = *plugin->env->my_identity; | 2809 | udp_ack->sender = *plugin->env->my_identity; |
2972 | GNUNET_memcpy (&udp_ack[1], | 2810 | GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size)); |
2973 | msg, | 2811 | enqueue (plugin, udpw); |
2974 | ntohs (msg->size)); | 2812 | notify_session_monitor (plugin, s, GNUNET_TRANSPORT_SS_UPDATE); |
2975 | enqueue (plugin, | ||
2976 | udpw); | ||
2977 | notify_session_monitor (plugin, | ||
2978 | s, | ||
2979 | GNUNET_TRANSPORT_SS_UPDATE); | ||
2980 | if (s->address->address_length == sizeof (struct IPv4UdpAddress)) | 2813 | if (s->address->address_length == sizeof (struct IPv4UdpAddress)) |
2981 | schedule_select_v4 (plugin); | 2814 | schedule_select_v4 (plugin); |
2982 | else | 2815 | else |
@@ -3019,46 +2852,41 @@ read_process_fragment (struct Plugin *plugin, | |||
3019 | { | 2852 | { |
3020 | /* Create a new defragmentation context */ | 2853 | /* Create a new defragmentation context */ |
3021 | d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len); | 2854 | d_ctx = GNUNET_malloc (sizeof (struct DefragContext) + udp_addr_len); |
3022 | GNUNET_memcpy (&d_ctx[1], | 2855 | GNUNET_memcpy (&d_ctx[1], udp_addr, udp_addr_len); |
3023 | udp_addr, | ||
3024 | udp_addr_len); | ||
3025 | d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1]; | 2856 | d_ctx->udp_addr = (const union UdpAddress *) &d_ctx[1]; |
3026 | d_ctx->udp_addr_len = udp_addr_len; | 2857 | d_ctx->udp_addr_len = udp_addr_len; |
3027 | d_ctx->network_type = network_type; | 2858 | d_ctx->network_type = network_type; |
3028 | d_ctx->plugin = plugin; | 2859 | d_ctx->plugin = plugin; |
3029 | d_ctx->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, | 2860 | d_ctx->defrag = |
3030 | UDP_MTU, | 2861 | GNUNET_DEFRAGMENT_context_create (plugin->env->stats, |
3031 | UDP_MAX_MESSAGES_IN_DEFRAG, | 2862 | UDP_MTU, |
3032 | d_ctx, | 2863 | UDP_MAX_MESSAGES_IN_DEFRAG, |
3033 | &fragment_msg_proc, | 2864 | d_ctx, |
3034 | &ack_proc); | 2865 | &fragment_msg_proc, |
2866 | &ack_proc); | ||
3035 | d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, | 2867 | d_ctx->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrag_ctxs, |
3036 | d_ctx, | 2868 | d_ctx, |
3037 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); | 2869 | (GNUNET_CONTAINER_HeapCostType) |
2870 | now.abs_value_us); | ||
3038 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2871 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3039 | "Created new defragmentation context for %u-byte fragment from `%s'\n", | 2872 | "Created new defragmentation context for %u-byte fragment from `%s'\n", |
3040 | (unsigned int) ntohs (msg->size), | 2873 | (unsigned int) ntohs (msg->size), |
3041 | udp_address_to_string (plugin, | 2874 | udp_address_to_string (plugin, udp_addr, udp_addr_len)); |
3042 | udp_addr, | ||
3043 | udp_addr_len)); | ||
3044 | } | 2875 | } |
3045 | else | 2876 | else |
3046 | { | 2877 | { |
3047 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2878 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3048 | "Found existing defragmentation context for %u-byte fragment from `%s'\n", | 2879 | "Found existing defragmentation context for %u-byte fragment from `%s'\n", |
3049 | (unsigned int) ntohs (msg->size), | 2880 | (unsigned int) ntohs (msg->size), |
3050 | udp_address_to_string (plugin, | 2881 | udp_address_to_string (plugin, udp_addr, udp_addr_len)); |
3051 | udp_addr, | ||
3052 | udp_addr_len)); | ||
3053 | } | 2882 | } |
3054 | 2883 | ||
3055 | if (GNUNET_OK == | 2884 | if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, msg)) |
3056 | GNUNET_DEFRAGMENT_process_fragment (d_ctx->defrag, | ||
3057 | msg)) | ||
3058 | { | 2885 | { |
3059 | /* keep this 'rc' from expiring */ | 2886 | /* keep this 'rc' from expiring */ |
3060 | GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, | 2887 | GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, |
3061 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); | 2888 | (GNUNET_CONTAINER_HeapCostType) |
2889 | now.abs_value_us); | ||
3062 | } | 2890 | } |
3063 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > | 2891 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > |
3064 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) | 2892 | UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG) |
@@ -3083,8 +2911,7 @@ read_process_fragment (struct Plugin *plugin, | |||
3083 | * @param rsock socket to read from | 2911 | * @param rsock socket to read from |
3084 | */ | 2912 | */ |
3085 | static void | 2913 | static void |
3086 | udp_select_read (struct Plugin *plugin, | 2914 | udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) |
3087 | struct GNUNET_NETWORK_Handle *rsock) | ||
3088 | { | 2915 | { |
3089 | socklen_t fromlen; | 2916 | socklen_t fromlen; |
3090 | struct sockaddr_storage addr; | 2917 | struct sockaddr_storage addr; |
@@ -3101,9 +2928,7 @@ udp_select_read (struct Plugin *plugin, | |||
3101 | enum GNUNET_NetworkType network_type; | 2928 | enum GNUNET_NetworkType network_type; |
3102 | 2929 | ||
3103 | fromlen = sizeof (addr); | 2930 | fromlen = sizeof (addr); |
3104 | memset (&addr, | 2931 | memset (&addr, 0, sizeof (addr)); |
3105 | 0, | ||
3106 | sizeof(addr)); | ||
3107 | size = GNUNET_NETWORK_socket_recvfrom (rsock, | 2932 | size = GNUNET_NETWORK_socket_recvfrom (rsock, |
3108 | buf, | 2933 | buf, |
3109 | sizeof (buf), | 2934 | sizeof (buf), |
@@ -3121,15 +2946,14 @@ udp_select_read (struct Plugin *plugin, | |||
3121 | * error indicates a previous send operation resulted in an ICMP Port | 2946 | * error indicates a previous send operation resulted in an ICMP Port |
3122 | * Unreachable message. | 2947 | * Unreachable message. |
3123 | */ | 2948 | */ |
3124 | if ( (-1 == size) && | 2949 | if ((-1 == size) && (ECONNRESET == errno)) |
3125 | (ECONNRESET == errno) ) | ||
3126 | return; | 2950 | return; |
3127 | #endif | 2951 | #endif |
3128 | if (-1 == size) | 2952 | if (-1 == size) |
3129 | { | 2953 | { |
3130 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2954 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3131 | "UDP failed to receive data: %s\n", | 2955 | "UDP failed to receive data: %s\n", |
3132 | STRERROR (errno)); | 2956 | strerror (errno)); |
3133 | /* Connection failure or something. Not a protocol violation. */ | 2957 | /* Connection failure or something. Not a protocol violation. */ |
3134 | return; | 2958 | return; |
3135 | } | 2959 | } |
@@ -3137,19 +2961,18 @@ udp_select_read (struct Plugin *plugin, | |||
3137 | /* Check if this is a STUN packet */ | 2961 | /* Check if this is a STUN packet */ |
3138 | if (GNUNET_NO != | 2962 | if (GNUNET_NO != |
3139 | GNUNET_NAT_stun_handle_packet (plugin->nat, | 2963 | GNUNET_NAT_stun_handle_packet (plugin->nat, |
3140 | (const struct sockaddr *) &addr, | 2964 | (const struct sockaddr *) &addr, |
3141 | fromlen, | 2965 | fromlen, |
3142 | buf, | 2966 | buf, |
3143 | size)) | 2967 | size)) |
3144 | return; /* was STUN, do not process further */ | 2968 | return; /* was STUN, do not process further */ |
3145 | 2969 | ||
3146 | if (size < sizeof(struct GNUNET_MessageHeader)) | 2970 | if (size < sizeof (struct GNUNET_MessageHeader)) |
3147 | { | 2971 | { |
3148 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2972 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3149 | "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", | 2973 | "UDP got %u bytes from %s, which is not enough for a GNUnet message header\n", |
3150 | (unsigned int ) size, | 2974 | (unsigned int) size, |
3151 | GNUNET_a2s (sa, | 2975 | GNUNET_a2s (sa, fromlen)); |
3152 | fromlen)); | ||
3153 | /* _MAY_ be a connection failure (got partial message) */ | 2976 | /* _MAY_ be a connection failure (got partial message) */ |
3154 | /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ | 2977 | /* But it _MAY_ also be that the other side uses non-GNUnet protocol. */ |
3155 | GNUNET_break_op (0); | 2978 | GNUNET_break_op (0); |
@@ -3160,16 +2983,14 @@ udp_select_read (struct Plugin *plugin, | |||
3160 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2983 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3161 | "UDP received %u-byte message from `%s' type %u\n", | 2984 | "UDP received %u-byte message from `%s' type %u\n", |
3162 | (unsigned int) size, | 2985 | (unsigned int) size, |
3163 | GNUNET_a2s (sa, | 2986 | GNUNET_a2s (sa, fromlen), |
3164 | fromlen), | ||
3165 | ntohs (msg->type)); | 2987 | ntohs (msg->type)); |
3166 | if (size != ntohs (msg->size)) | 2988 | if (size != ntohs (msg->size)) |
3167 | { | 2989 | { |
3168 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2990 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3169 | "UDP malformed message (size %u) header from %s\n", | 2991 | "UDP malformed message (size %u) header from %s\n", |
3170 | (unsigned int) size, | 2992 | (unsigned int) size, |
3171 | GNUNET_a2s (sa, | 2993 | GNUNET_a2s (sa, fromlen)); |
3172 | fromlen)); | ||
3173 | GNUNET_break_op (0); | 2994 | GNUNET_break_op (0); |
3174 | return; | 2995 | return; |
3175 | } | 2996 | } |
@@ -3177,9 +2998,7 @@ udp_select_read (struct Plugin *plugin, | |||
3177 | "# UDP, total bytes received", | 2998 | "# UDP, total bytes received", |
3178 | size, | 2999 | size, |
3179 | GNUNET_NO); | 3000 | GNUNET_NO); |
3180 | network_type = plugin->env->get_address_type (plugin->env->cls, | 3001 | network_type = plugin->env->get_address_type (plugin->env->cls, sa, fromlen); |
3181 | sa, | ||
3182 | fromlen); | ||
3183 | switch (sa->sa_family) | 3002 | switch (sa->sa_family) |
3184 | { | 3003 | { |
3185 | case AF_INET: | 3004 | case AF_INET: |
@@ -3215,9 +3034,9 @@ udp_select_read (struct Plugin *plugin, | |||
3215 | network_type); | 3034 | network_type); |
3216 | return; | 3035 | return; |
3217 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: | 3036 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: |
3218 | if (ntohs (msg->size) < sizeof(struct UDPMessage)) | 3037 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) |
3219 | { | 3038 | { |
3220 | GNUNET_break_op(0); | 3039 | GNUNET_break_op (0); |
3221 | return; | 3040 | return; |
3222 | } | 3041 | } |
3223 | process_udp_message (plugin, | 3042 | process_udp_message (plugin, |
@@ -3227,20 +3046,13 @@ udp_select_read (struct Plugin *plugin, | |||
3227 | network_type); | 3046 | network_type); |
3228 | return; | 3047 | return; |
3229 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: | 3048 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: |
3230 | read_process_ack (plugin, | 3049 | read_process_ack (plugin, msg, int_addr, int_addr_len); |
3231 | msg, | ||
3232 | int_addr, | ||
3233 | int_addr_len); | ||
3234 | return; | 3050 | return; |
3235 | case GNUNET_MESSAGE_TYPE_FRAGMENT: | 3051 | case GNUNET_MESSAGE_TYPE_FRAGMENT: |
3236 | read_process_fragment (plugin, | 3052 | read_process_fragment (plugin, msg, int_addr, int_addr_len, network_type); |
3237 | msg, | ||
3238 | int_addr, | ||
3239 | int_addr_len, | ||
3240 | network_type); | ||
3241 | return; | 3053 | return; |
3242 | default: | 3054 | default: |
3243 | GNUNET_break_op(0); | 3055 | GNUNET_break_op (0); |
3244 | return; | 3056 | return; |
3245 | } | 3057 | } |
3246 | } | 3058 | } |
@@ -3265,9 +3077,8 @@ remove_timeout_messages_and_select (struct Plugin *plugin, | |||
3265 | int removed; | 3077 | int removed; |
3266 | 3078 | ||
3267 | removed = GNUNET_NO; | 3079 | removed = GNUNET_NO; |
3268 | udpw = (sock == plugin->sockv4) | 3080 | udpw = (sock == plugin->sockv4) ? plugin->ipv4_queue_head |
3269 | ? plugin->ipv4_queue_head | 3081 | : plugin->ipv6_queue_head; |
3270 | : plugin->ipv6_queue_head; | ||
3271 | while (NULL != udpw) | 3082 | while (NULL != udpw) |
3272 | { | 3083 | { |
3273 | session = udpw->session; | 3084 | session = udpw->session; |
@@ -3277,11 +3088,8 @@ remove_timeout_messages_and_select (struct Plugin *plugin, | |||
3277 | { | 3088 | { |
3278 | /* Message timed out */ | 3089 | /* Message timed out */ |
3279 | removed = GNUNET_YES; | 3090 | removed = GNUNET_YES; |
3280 | dequeue (plugin, | 3091 | dequeue (plugin, udpw); |
3281 | udpw); | 3092 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
3282 | udpw->qc (udpw->qc_cls, | ||
3283 | udpw, | ||
3284 | GNUNET_SYSERR); | ||
3285 | GNUNET_free (udpw); | 3093 | GNUNET_free (udpw); |
3286 | 3094 | ||
3287 | if (sock == plugin->sockv4) | 3095 | if (sock == plugin->sockv4) |
@@ -3321,9 +3129,8 @@ remove_timeout_messages_and_select (struct Plugin *plugin, | |||
3321 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3129 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3322 | "Message for peer `%s' (%u bytes) is delayed for %s\n", | 3130 | "Message for peer `%s' (%u bytes) is delayed for %s\n", |
3323 | GNUNET_i2s (&udpw->session->target), | 3131 | GNUNET_i2s (&udpw->session->target), |
3324 | udpw->payload_size, | 3132 | udpw->payload_size, |
3325 | GNUNET_STRINGS_relative_time_to_string (remaining, | 3133 | GNUNET_STRINGS_relative_time_to_string (remaining, GNUNET_YES)); |
3326 | GNUNET_YES)); | ||
3327 | udpw = udpw->next; | 3134 | udpw = udpw->next; |
3328 | } | 3135 | } |
3329 | } | 3136 | } |
@@ -3353,13 +3160,9 @@ analyze_send_error (struct Plugin *plugin, | |||
3353 | { | 3160 | { |
3354 | enum GNUNET_NetworkType type; | 3161 | enum GNUNET_NetworkType type; |
3355 | 3162 | ||
3356 | type = plugin->env->get_address_type (plugin->env->cls, | 3163 | type = plugin->env->get_address_type (plugin->env->cls, sa, slen); |
3357 | sa, | 3164 | if (((GNUNET_NT_LAN == type) || (GNUNET_NT_WAN == type)) && |
3358 | slen); | 3165 | ((ENETUNREACH == errno) || (ENETDOWN == errno))) |
3359 | if ( ( (GNUNET_NT_LAN == type) || | ||
3360 | (GNUNET_NT_WAN == type) ) && | ||
3361 | ( (ENETUNREACH == errno) || | ||
3362 | (ENETDOWN == errno) ) ) | ||
3363 | { | 3166 | { |
3364 | if (slen == sizeof (struct sockaddr_in)) | 3167 | if (slen == sizeof (struct sockaddr_in)) |
3365 | { | 3168 | { |
@@ -3368,10 +3171,9 @@ analyze_send_error (struct Plugin *plugin, | |||
3368 | * This indicates we do not have connectivity | 3171 | * This indicates we do not have connectivity |
3369 | */ | 3172 | */ |
3370 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 3173 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
3371 | _("UDP could not transmit message to `%s': " | 3174 | _ ("UDP could not transmit message to `%s': " |
3372 | "Network seems down, please check your network configuration\n"), | 3175 | "Network seems down, please check your network configuration\n"), |
3373 | GNUNET_a2s (sa, | 3176 | GNUNET_a2s (sa, slen)); |
3374 | slen)); | ||
3375 | } | 3177 | } |
3376 | if (slen == sizeof (struct sockaddr_in6)) | 3178 | if (slen == sizeof (struct sockaddr_in6)) |
3377 | { | 3179 | { |
@@ -3382,7 +3184,8 @@ analyze_send_error (struct Plugin *plugin, | |||
3382 | * connectivity | 3184 | * connectivity |
3383 | */ | 3185 | */ |
3384 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 3186 | LOG (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
3385 | _("UDP could not transmit IPv6 message! " | 3187 | _ ( |
3188 | "UDP could not transmit IPv6 message! " | ||
3386 | "Please check your network configuration and disable IPv6 if your " | 3189 | "Please check your network configuration and disable IPv6 if your " |
3387 | "connection does not have a global IPv6 address\n")); | 3190 | "connection does not have a global IPv6 address\n")); |
3388 | } | 3191 | } |
@@ -3391,9 +3194,8 @@ analyze_send_error (struct Plugin *plugin, | |||
3391 | { | 3194 | { |
3392 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3195 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3393 | "UDP could not transmit message to `%s': `%s'\n", | 3196 | "UDP could not transmit message to `%s': `%s'\n", |
3394 | GNUNET_a2s (sa, | 3197 | GNUNET_a2s (sa, slen), |
3395 | slen), | 3198 | strerror (error)); |
3396 | STRERROR (error)); | ||
3397 | } | 3199 | } |
3398 | } | 3200 | } |
3399 | 3201 | ||
@@ -3406,8 +3208,7 @@ analyze_send_error (struct Plugin *plugin, | |||
3406 | * @param sock which socket (v4/v6) to send on | 3208 | * @param sock which socket (v4/v6) to send on |
3407 | */ | 3209 | */ |
3408 | static void | 3210 | static void |
3409 | udp_select_send (struct Plugin *plugin, | 3211 | udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock) |
3410 | struct GNUNET_NETWORK_Handle *sock) | ||
3411 | { | 3212 | { |
3412 | ssize_t sent; | 3213 | ssize_t sent; |
3413 | socklen_t slen; | 3214 | socklen_t slen; |
@@ -3419,15 +3220,13 @@ udp_select_send (struct Plugin *plugin, | |||
3419 | struct UDP_MessageWrapper *udpw; | 3220 | struct UDP_MessageWrapper *udpw; |
3420 | 3221 | ||
3421 | /* Find message(s) to send */ | 3222 | /* Find message(s) to send */ |
3422 | while (NULL != (udpw = remove_timeout_messages_and_select (plugin, | 3223 | while (NULL != (udpw = remove_timeout_messages_and_select (plugin, sock))) |
3423 | sock))) | ||
3424 | { | 3224 | { |
3425 | if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length) | 3225 | if (sizeof (struct IPv4UdpAddress) == |
3226 | udpw->session->address->address_length) | ||
3426 | { | 3227 | { |
3427 | u4 = udpw->session->address->address; | 3228 | u4 = udpw->session->address->address; |
3428 | memset (&a4, | 3229 | memset (&a4, 0, sizeof (a4)); |
3429 | 0, | ||
3430 | sizeof(a4)); | ||
3431 | a4.sin_family = AF_INET; | 3230 | a4.sin_family = AF_INET; |
3432 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3231 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3433 | a4.sin_len = sizeof (a4); | 3232 | a4.sin_len = sizeof (a4); |
@@ -3437,12 +3236,11 @@ udp_select_send (struct Plugin *plugin, | |||
3437 | a = (const struct sockaddr *) &a4; | 3236 | a = (const struct sockaddr *) &a4; |
3438 | slen = sizeof (a4); | 3237 | slen = sizeof (a4); |
3439 | } | 3238 | } |
3440 | else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length) | 3239 | else if (sizeof (struct IPv6UdpAddress) == |
3240 | udpw->session->address->address_length) | ||
3441 | { | 3241 | { |
3442 | u6 = udpw->session->address->address; | 3242 | u6 = udpw->session->address->address; |
3443 | memset (&a6, | 3243 | memset (&a6, 0, sizeof (a6)); |
3444 | 0, | ||
3445 | sizeof(a6)); | ||
3446 | a6.sin6_family = AF_INET6; | 3244 | a6.sin6_family = AF_INET6; |
3447 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3245 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3448 | a6.sin6_len = sizeof (a6); | 3246 | a6.sin6_len = sizeof (a6); |
@@ -3455,11 +3253,8 @@ udp_select_send (struct Plugin *plugin, | |||
3455 | else | 3253 | else |
3456 | { | 3254 | { |
3457 | GNUNET_break (0); | 3255 | GNUNET_break (0); |
3458 | dequeue (plugin, | 3256 | dequeue (plugin, udpw); |
3459 | udpw); | 3257 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
3460 | udpw->qc (udpw->qc_cls, | ||
3461 | udpw, | ||
3462 | GNUNET_SYSERR); | ||
3463 | notify_session_monitor (plugin, | 3258 | notify_session_monitor (plugin, |
3464 | udpw->session, | 3259 | udpw->session, |
3465 | GNUNET_TRANSPORT_SS_UPDATE); | 3260 | GNUNET_TRANSPORT_SS_UPDATE); |
@@ -3471,21 +3266,15 @@ udp_select_send (struct Plugin *plugin, | |||
3471 | udpw->msg_size, | 3266 | udpw->msg_size, |
3472 | a, | 3267 | a, |
3473 | slen); | 3268 | slen); |
3474 | udpw->session->last_transmit_time | 3269 | udpw->session->last_transmit_time = |
3475 | = GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (), | 3270 | GNUNET_TIME_absolute_max (GNUNET_TIME_absolute_get (), |
3476 | udpw->session->last_transmit_time); | 3271 | udpw->session->last_transmit_time); |
3477 | dequeue (plugin, | 3272 | dequeue (plugin, udpw); |
3478 | udpw); | ||
3479 | if (GNUNET_SYSERR == sent) | 3273 | if (GNUNET_SYSERR == sent) |
3480 | { | 3274 | { |
3481 | /* Failure */ | 3275 | /* Failure */ |
3482 | analyze_send_error (plugin, | 3276 | analyze_send_error (plugin, a, slen, errno); |
3483 | a, | 3277 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
3484 | slen, | ||
3485 | errno); | ||
3486 | udpw->qc (udpw->qc_cls, | ||
3487 | udpw, | ||
3488 | GNUNET_SYSERR); | ||
3489 | GNUNET_STATISTICS_update (plugin->env->stats, | 3278 | GNUNET_STATISTICS_update (plugin->env->stats, |
3490 | "# UDP, total, bytes, sent, failure", | 3279 | "# UDP, total, bytes, sent, failure", |
3491 | sent, | 3280 | sent, |
@@ -3502,10 +3291,9 @@ udp_select_send (struct Plugin *plugin, | |||
3502 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", | 3291 | "UDP transmitted %u-byte message to `%s' `%s' (%d: %s)\n", |
3503 | (unsigned int) (udpw->msg_size), | 3292 | (unsigned int) (udpw->msg_size), |
3504 | GNUNET_i2s (&udpw->session->target), | 3293 | GNUNET_i2s (&udpw->session->target), |
3505 | GNUNET_a2s (a, | 3294 | GNUNET_a2s (a, slen), |
3506 | slen), | 3295 | (int) sent, |
3507 | (int ) sent, | 3296 | (sent < 0) ? strerror (errno) : "ok"); |
3508 | (sent < 0) ? STRERROR (errno) : "ok"); | ||
3509 | GNUNET_STATISTICS_update (plugin->env->stats, | 3297 | GNUNET_STATISTICS_update (plugin->env->stats, |
3510 | "# UDP, total, bytes, sent, success", | 3298 | "# UDP, total, bytes, sent, success", |
3511 | sent, | 3299 | sent, |
@@ -3516,13 +3304,9 @@ udp_select_send (struct Plugin *plugin, | |||
3516 | GNUNET_NO); | 3304 | GNUNET_NO); |
3517 | if (NULL != udpw->frag_ctx) | 3305 | if (NULL != udpw->frag_ctx) |
3518 | udpw->frag_ctx->on_wire_size += udpw->msg_size; | 3306 | udpw->frag_ctx->on_wire_size += udpw->msg_size; |
3519 | udpw->qc (udpw->qc_cls, | 3307 | udpw->qc (udpw->qc_cls, udpw, GNUNET_OK); |
3520 | udpw, | ||
3521 | GNUNET_OK); | ||
3522 | } | 3308 | } |
3523 | notify_session_monitor (plugin, | 3309 | notify_session_monitor (plugin, udpw->session, GNUNET_TRANSPORT_SS_UPDATE); |
3524 | udpw->session, | ||
3525 | GNUNET_TRANSPORT_SS_UPDATE); | ||
3526 | GNUNET_free (udpw); | 3310 | GNUNET_free (udpw); |
3527 | } | 3311 | } |
3528 | } | 3312 | } |
@@ -3549,12 +3333,9 @@ udp_plugin_select_v4 (void *cls) | |||
3549 | return; | 3333 | return; |
3550 | tc = GNUNET_SCHEDULER_get_task_context (); | 3334 | tc = GNUNET_SCHEDULER_get_task_context (); |
3551 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && | 3335 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && |
3552 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 3336 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4))) |
3553 | plugin->sockv4))) | 3337 | udp_select_read (plugin, plugin->sockv4); |
3554 | udp_select_read (plugin, | 3338 | udp_select_send (plugin, plugin->sockv4); |
3555 | plugin->sockv4); | ||
3556 | udp_select_send (plugin, | ||
3557 | plugin->sockv4); | ||
3558 | schedule_select_v4 (plugin); | 3339 | schedule_select_v4 (plugin); |
3559 | } | 3340 | } |
3560 | 3341 | ||
@@ -3576,14 +3357,11 @@ udp_plugin_select_v6 (void *cls) | |||
3576 | if (NULL == plugin->sockv6) | 3357 | if (NULL == plugin->sockv6) |
3577 | return; | 3358 | return; |
3578 | tc = GNUNET_SCHEDULER_get_task_context (); | 3359 | tc = GNUNET_SCHEDULER_get_task_context (); |
3579 | if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && | 3360 | if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) && |
3580 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 3361 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6))) |
3581 | plugin->sockv6)) ) | 3362 | udp_select_read (plugin, plugin->sockv6); |
3582 | udp_select_read (plugin, | 3363 | |
3583 | plugin->sockv6); | 3364 | udp_select_send (plugin, plugin->sockv6); |
3584 | |||
3585 | udp_select_send (plugin, | ||
3586 | plugin->sockv6); | ||
3587 | schedule_select_v6 (plugin); | 3365 | schedule_select_v6 (plugin); |
3588 | } | 3366 | } |
3589 | 3367 | ||
@@ -3618,20 +3396,16 @@ setup_sockets (struct Plugin *plugin, | |||
3618 | eno = EINVAL; | 3396 | eno = EINVAL; |
3619 | if (GNUNET_YES == plugin->enable_ipv6) | 3397 | if (GNUNET_YES == plugin->enable_ipv6) |
3620 | { | 3398 | { |
3621 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, | 3399 | plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); |
3622 | SOCK_DGRAM, | ||
3623 | 0); | ||
3624 | if (NULL == plugin->sockv6) | 3400 | if (NULL == plugin->sockv6) |
3625 | { | 3401 | { |
3626 | LOG (GNUNET_ERROR_TYPE_INFO, | 3402 | LOG (GNUNET_ERROR_TYPE_INFO, |
3627 | _("Disabling IPv6 since it is not supported on this system!\n")); | 3403 | _ ("Disabling IPv6 since it is not supported on this system!\n")); |
3628 | plugin->enable_ipv6 = GNUNET_NO; | 3404 | plugin->enable_ipv6 = GNUNET_NO; |
3629 | } | 3405 | } |
3630 | else | 3406 | else |
3631 | { | 3407 | { |
3632 | memset (&server_addrv6, | 3408 | memset (&server_addrv6, 0, sizeof (struct sockaddr_in6)); |
3633 | 0, | ||
3634 | sizeof(struct sockaddr_in6)); | ||
3635 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3409 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3636 | server_addrv6.sin6_len = sizeof (struct sockaddr_in6); | 3410 | server_addrv6.sin6_len = sizeof (struct sockaddr_in6); |
3637 | #endif | 3411 | #endif |
@@ -3642,10 +3416,9 @@ setup_sockets (struct Plugin *plugin, | |||
3642 | server_addrv6.sin6_addr = in6addr_any; | 3416 | server_addrv6.sin6_addr = in6addr_any; |
3643 | 3417 | ||
3644 | if (0 == plugin->port) /* autodetect */ | 3418 | if (0 == plugin->port) /* autodetect */ |
3645 | server_addrv6.sin6_port | 3419 | server_addrv6.sin6_port = htons ( |
3646 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, | 3420 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + |
3647 | 33537) | 3421 | 32000); |
3648 | + 32000); | ||
3649 | else | 3422 | else |
3650 | server_addrv6.sin6_port = htons (plugin->port); | 3423 | server_addrv6.sin6_port = htons (plugin->port); |
3651 | addrlen = sizeof (struct sockaddr_in6); | 3424 | addrlen = sizeof (struct sockaddr_in6); |
@@ -3654,15 +3427,12 @@ setup_sockets (struct Plugin *plugin, | |||
3654 | tries = 0; | 3427 | tries = 0; |
3655 | while (tries < 10) | 3428 | while (tries < 10) |
3656 | { | 3429 | { |
3657 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 3430 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3658 | "Binding to IPv6 `%s'\n", | 3431 | "Binding to IPv6 `%s'\n", |
3659 | GNUNET_a2s (server_addr, | 3432 | GNUNET_a2s (server_addr, addrlen)); |
3660 | addrlen)); | ||
3661 | /* binding */ | 3433 | /* binding */ |
3662 | if (GNUNET_OK == | 3434 | if (GNUNET_OK == |
3663 | GNUNET_NETWORK_socket_bind (plugin->sockv6, | 3435 | GNUNET_NETWORK_socket_bind (plugin->sockv6, server_addr, addrlen)) |
3664 | server_addr, | ||
3665 | addrlen)) | ||
3666 | break; | 3436 | break; |
3667 | eno = errno; | 3437 | eno = errno; |
3668 | if (0 != plugin->port) | 3438 | if (0 != plugin->port) |
@@ -3671,10 +3441,9 @@ setup_sockets (struct Plugin *plugin, | |||
3671 | break; /* bind failed on specific port */ | 3441 | break; /* bind failed on specific port */ |
3672 | } | 3442 | } |
3673 | /* autodetect */ | 3443 | /* autodetect */ |
3674 | server_addrv6.sin6_port | 3444 | server_addrv6.sin6_port = htons ( |
3675 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, | 3445 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + |
3676 | 33537) | 3446 | 32000); |
3677 | + 32000); | ||
3678 | tries++; | 3447 | tries++; |
3679 | } | 3448 | } |
3680 | if (tries >= 10) | 3449 | if (tries >= 10) |
@@ -3691,8 +3460,7 @@ setup_sockets (struct Plugin *plugin, | |||
3691 | { | 3460 | { |
3692 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3461 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3693 | "IPv6 UDP socket created listinging at %s\n", | 3462 | "IPv6 UDP socket created listinging at %s\n", |
3694 | GNUNET_a2s (server_addr, | 3463 | GNUNET_a2s (server_addr, addrlen)); |
3695 | addrlen)); | ||
3696 | addrs[sockets_created] = server_addr; | 3464 | addrs[sockets_created] = server_addr; |
3697 | addrlens[sockets_created] = addrlen; | 3465 | addrlens[sockets_created] = addrlen; |
3698 | sockets_created++; | 3466 | sockets_created++; |
@@ -3700,32 +3468,26 @@ setup_sockets (struct Plugin *plugin, | |||
3700 | else | 3468 | else |
3701 | { | 3469 | { |
3702 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3470 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3703 | _("Failed to bind UDP socket to %s: %s\n"), | 3471 | _ ("Failed to bind UDP socket to %s: %s\n"), |
3704 | GNUNET_a2s (server_addr, | 3472 | GNUNET_a2s (server_addr, addrlen), |
3705 | addrlen), | 3473 | strerror (eno)); |
3706 | STRERROR (eno)); | ||
3707 | } | 3474 | } |
3708 | } | 3475 | } |
3709 | } | 3476 | } |
3710 | 3477 | ||
3711 | /* Create IPv4 socket */ | 3478 | /* Create IPv4 socket */ |
3712 | eno = EINVAL; | 3479 | eno = EINVAL; |
3713 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, | 3480 | plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); |
3714 | SOCK_DGRAM, | ||
3715 | 0); | ||
3716 | if (NULL == plugin->sockv4) | 3481 | if (NULL == plugin->sockv4) |
3717 | { | 3482 | { |
3718 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 3483 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); |
3719 | "socket"); | ||
3720 | LOG (GNUNET_ERROR_TYPE_INFO, | 3484 | LOG (GNUNET_ERROR_TYPE_INFO, |
3721 | _("Disabling IPv4 since it is not supported on this system!\n")); | 3485 | _ ("Disabling IPv4 since it is not supported on this system!\n")); |
3722 | plugin->enable_ipv4 = GNUNET_NO; | 3486 | plugin->enable_ipv4 = GNUNET_NO; |
3723 | } | 3487 | } |
3724 | else | 3488 | else |
3725 | { | 3489 | { |
3726 | memset (&server_addrv4, | 3490 | memset (&server_addrv4, 0, sizeof (struct sockaddr_in)); |
3727 | 0, | ||
3728 | sizeof(struct sockaddr_in)); | ||
3729 | #if HAVE_SOCKADDR_IN_SIN_LEN | 3491 | #if HAVE_SOCKADDR_IN_SIN_LEN |
3730 | server_addrv4.sin_len = sizeof (struct sockaddr_in); | 3492 | server_addrv4.sin_len = sizeof (struct sockaddr_in); |
3731 | #endif | 3493 | #endif |
@@ -3737,10 +3499,8 @@ setup_sockets (struct Plugin *plugin, | |||
3737 | 3499 | ||
3738 | if (0 == plugin->port) | 3500 | if (0 == plugin->port) |
3739 | /* autodetect */ | 3501 | /* autodetect */ |
3740 | server_addrv4.sin_port | 3502 | server_addrv4.sin_port = htons ( |
3741 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, | 3503 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); |
3742 | 33537) | ||
3743 | + 32000); | ||
3744 | else | 3504 | else |
3745 | server_addrv4.sin_port = htons (plugin->port); | 3505 | server_addrv4.sin_port = htons (plugin->port); |
3746 | 3506 | ||
@@ -3752,14 +3512,11 @@ setup_sockets (struct Plugin *plugin, | |||
3752 | { | 3512 | { |
3753 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3513 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3754 | "Binding to IPv4 `%s'\n", | 3514 | "Binding to IPv4 `%s'\n", |
3755 | GNUNET_a2s (server_addr, | 3515 | GNUNET_a2s (server_addr, addrlen)); |
3756 | addrlen)); | ||
3757 | 3516 | ||
3758 | /* binding */ | 3517 | /* binding */ |
3759 | if (GNUNET_OK == | 3518 | if (GNUNET_OK == |
3760 | GNUNET_NETWORK_socket_bind (plugin->sockv4, | 3519 | GNUNET_NETWORK_socket_bind (plugin->sockv4, server_addr, addrlen)) |
3761 | server_addr, | ||
3762 | addrlen)) | ||
3763 | break; | 3520 | break; |
3764 | eno = errno; | 3521 | eno = errno; |
3765 | if (0 != plugin->port) | 3522 | if (0 != plugin->port) |
@@ -3769,10 +3526,8 @@ setup_sockets (struct Plugin *plugin, | |||
3769 | } | 3526 | } |
3770 | 3527 | ||
3771 | /* autodetect */ | 3528 | /* autodetect */ |
3772 | server_addrv4.sin_port | 3529 | server_addrv4.sin_port = htons ( |
3773 | = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, | 3530 | GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); |
3774 | 33537) | ||
3775 | + 32000); | ||
3776 | tries++; | 3531 | tries++; |
3777 | } | 3532 | } |
3778 | if (tries >= 10) | 3533 | if (tries >= 10) |
@@ -3790,8 +3545,7 @@ setup_sockets (struct Plugin *plugin, | |||
3790 | { | 3545 | { |
3791 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3546 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3792 | "IPv4 socket created on port %s\n", | 3547 | "IPv4 socket created on port %s\n", |
3793 | GNUNET_a2s (server_addr, | 3548 | GNUNET_a2s (server_addr, addrlen)); |
3794 | addrlen)); | ||
3795 | addrs[sockets_created] = server_addr; | 3549 | addrs[sockets_created] = server_addr; |
3796 | addrlens[sockets_created] = addrlen; | 3550 | addrlens[sockets_created] = addrlen; |
3797 | sockets_created++; | 3551 | sockets_created++; |
@@ -3799,24 +3553,22 @@ setup_sockets (struct Plugin *plugin, | |||
3799 | else | 3553 | else |
3800 | { | 3554 | { |
3801 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3555 | LOG (GNUNET_ERROR_TYPE_ERROR, |
3802 | _("Failed to bind UDP socket to %s: %s\n"), | 3556 | _ ("Failed to bind UDP socket to %s: %s\n"), |
3803 | GNUNET_a2s (server_addr, | 3557 | GNUNET_a2s (server_addr, addrlen), |
3804 | addrlen), | 3558 | strerror (eno)); |
3805 | STRERROR (eno)); | ||
3806 | } | 3559 | } |
3807 | } | 3560 | } |
3808 | 3561 | ||
3809 | if (0 == sockets_created) | 3562 | if (0 == sockets_created) |
3810 | { | 3563 | { |
3811 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3564 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UDP sockets\n")); |
3812 | _("Failed to open UDP sockets\n")); | ||
3813 | return 0; /* No sockets created, return */ | 3565 | return 0; /* No sockets created, return */ |
3814 | } | 3566 | } |
3815 | schedule_select_v4 (plugin); | 3567 | schedule_select_v4 (plugin); |
3816 | schedule_select_v6 (plugin); | 3568 | schedule_select_v6 (plugin); |
3817 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 3569 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, |
3818 | "transport-udp", | 3570 | "transport-udp", |
3819 | IPPROTO_UDP, | 3571 | IPPROTO_UDP, |
3820 | sockets_created, | 3572 | sockets_created, |
3821 | addrs, | 3573 | addrs, |
3822 | addrlens, | 3574 | addrlens, |
@@ -3869,64 +3621,55 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3869 | 3621 | ||
3870 | /* Get port number: port == 0 : autodetect a port, | 3622 | /* Get port number: port == 0 : autodetect a port, |
3871 | * > 0 : use this port, not given : 2086 default */ | 3623 | * > 0 : use this port, not given : 2086 default */ |
3872 | if (GNUNET_OK != | 3624 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3873 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 3625 | "transport-udp", |
3874 | "transport-udp", | 3626 | "PORT", |
3875 | "PORT", | 3627 | &port)) |
3876 | &port)) | ||
3877 | port = 2086; | 3628 | port = 2086; |
3878 | if (port > 65535) | 3629 | if (port > 65535) |
3879 | { | 3630 | { |
3880 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 3631 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3881 | "transport-udp", | 3632 | "transport-udp", |
3882 | "PORT", | 3633 | "PORT", |
3883 | _("must be in [0,65535]")); | 3634 | _ ("must be in [0,65535]")); |
3884 | return NULL; | 3635 | return NULL; |
3885 | } | 3636 | } |
3886 | if (GNUNET_OK != | 3637 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3887 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 3638 | "transport-udp", |
3888 | "transport-udp", | 3639 | "ADVERTISED_PORT", |
3889 | "ADVERTISED_PORT", | 3640 | &aport)) |
3890 | &aport)) | ||
3891 | aport = port; | 3641 | aport = port; |
3892 | if (aport > 65535) | 3642 | if (aport > 65535) |
3893 | { | 3643 | { |
3894 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 3644 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3895 | "transport-udp", | 3645 | "transport-udp", |
3896 | "ADVERTISED_PORT", | 3646 | "ADVERTISED_PORT", |
3897 | _("must be in [0,65535]")); | 3647 | _ ("must be in [0,65535]")); |
3898 | return NULL; | 3648 | return NULL; |
3899 | } | 3649 | } |
3900 | 3650 | ||
3901 | if (GNUNET_YES == | 3651 | if (GNUNET_YES == |
3902 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 3652 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, "nat", "DISABLEV6")) |
3903 | "nat", | ||
3904 | "DISABLEV6")) | ||
3905 | enable_v6 = GNUNET_NO; | 3653 | enable_v6 = GNUNET_NO; |
3906 | else | 3654 | else |
3907 | enable_v6 = GNUNET_YES; | 3655 | enable_v6 = GNUNET_YES; |
3908 | 3656 | ||
3909 | have_bind4 = GNUNET_NO; | 3657 | have_bind4 = GNUNET_NO; |
3910 | memset (&server_addrv4, | 3658 | memset (&server_addrv4, 0, sizeof (server_addrv4)); |
3911 | 0, | 3659 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, |
3912 | sizeof (server_addrv4)); | 3660 | "transport-udp", |
3913 | if (GNUNET_YES == | 3661 | "BINDTO", |
3914 | GNUNET_CONFIGURATION_get_value_string (env->cfg, | 3662 | &bind4_address)) |
3915 | "transport-udp", | ||
3916 | "BINDTO", | ||
3917 | &bind4_address)) | ||
3918 | { | 3663 | { |
3919 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3664 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3920 | "Binding UDP plugin to specific address: `%s'\n", | 3665 | "Binding UDP plugin to specific address: `%s'\n", |
3921 | bind4_address); | 3666 | bind4_address); |
3922 | if (1 != inet_pton (AF_INET, | 3667 | if (1 != inet_pton (AF_INET, bind4_address, &server_addrv4.sin_addr)) |
3923 | bind4_address, | ||
3924 | &server_addrv4.sin_addr)) | ||
3925 | { | 3668 | { |
3926 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 3669 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3927 | "transport-udp", | 3670 | "transport-udp", |
3928 | "BINDTO", | 3671 | "BINDTO", |
3929 | _("must be valid IPv4 address")); | 3672 | _ ("must be valid IPv4 address")); |
3930 | GNUNET_free (bind4_address); | 3673 | GNUNET_free (bind4_address); |
3931 | return NULL; | 3674 | return NULL; |
3932 | } | 3675 | } |
@@ -3934,26 +3677,21 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3934 | } | 3677 | } |
3935 | GNUNET_free_non_null (bind4_address); | 3678 | GNUNET_free_non_null (bind4_address); |
3936 | have_bind6 = GNUNET_NO; | 3679 | have_bind6 = GNUNET_NO; |
3937 | memset (&server_addrv6, | 3680 | memset (&server_addrv6, 0, sizeof (server_addrv6)); |
3938 | 0, | 3681 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg, |
3939 | sizeof (server_addrv6)); | 3682 | "transport-udp", |
3940 | if (GNUNET_YES == | 3683 | "BINDTO6", |
3941 | GNUNET_CONFIGURATION_get_value_string (env->cfg, | 3684 | &bind6_address)) |
3942 | "transport-udp", | ||
3943 | "BINDTO6", | ||
3944 | &bind6_address)) | ||
3945 | { | 3685 | { |
3946 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3686 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3947 | "Binding udp plugin to specific address: `%s'\n", | 3687 | "Binding udp plugin to specific address: `%s'\n", |
3948 | bind6_address); | 3688 | bind6_address); |
3949 | if (1 != inet_pton (AF_INET6, | 3689 | if (1 != inet_pton (AF_INET6, bind6_address, &server_addrv6.sin6_addr)) |
3950 | bind6_address, | ||
3951 | &server_addrv6.sin6_addr)) | ||
3952 | { | 3690 | { |
3953 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, | 3691 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
3954 | "transport-udp", | 3692 | "transport-udp", |
3955 | "BINDTO6", | 3693 | "BINDTO6", |
3956 | _("must be valid IPv6 address")); | 3694 | _ ("must be valid IPv6 address")); |
3957 | GNUNET_free (bind6_address); | 3695 | GNUNET_free (bind6_address); |
3958 | return NULL; | 3696 | return NULL; |
3959 | } | 3697 | } |
@@ -3967,9 +3705,10 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3967 | if (enable_broadcasting == GNUNET_SYSERR) | 3705 | if (enable_broadcasting == GNUNET_SYSERR) |
3968 | enable_broadcasting = GNUNET_NO; | 3706 | enable_broadcasting = GNUNET_NO; |
3969 | 3707 | ||
3970 | enable_broadcasting_recv = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 3708 | enable_broadcasting_recv = |
3971 | "transport-udp", | 3709 | GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
3972 | "BROADCAST_RECEIVE"); | 3710 | "transport-udp", |
3711 | "BROADCAST_RECEIVE"); | ||
3973 | if (enable_broadcasting_recv == GNUNET_SYSERR) | 3712 | if (enable_broadcasting_recv == GNUNET_SYSERR) |
3974 | enable_broadcasting_recv = GNUNET_YES; | 3713 | enable_broadcasting_recv = GNUNET_YES; |
3975 | 3714 | ||
@@ -3979,14 +3718,12 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3979 | "BROADCAST_INTERVAL", | 3718 | "BROADCAST_INTERVAL", |
3980 | &interval)) | 3719 | &interval)) |
3981 | { | 3720 | { |
3982 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | 3721 | interval = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); |
3983 | 10); | ||
3984 | } | 3722 | } |
3985 | if (GNUNET_OK != | 3723 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (env->cfg, |
3986 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 3724 | "transport-udp", |
3987 | "transport-udp", | 3725 | "MAX_BPS", |
3988 | "MAX_BPS", | 3726 | &udp_max_bps)) |
3989 | &udp_max_bps)) | ||
3990 | { | 3727 | { |
3991 | /* 50 MB/s == infinity for practical purposes */ | 3728 | /* 50 MB/s == infinity for practical purposes */ |
3992 | udp_max_bps = 1024 * 1024 * 50; | 3729 | udp_max_bps = 1024 * 1024 * 50; |
@@ -4001,23 +3738,21 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
4001 | p->enable_broadcasting = enable_broadcasting; | 3738 | p->enable_broadcasting = enable_broadcasting; |
4002 | p->enable_broadcasting_receiving = enable_broadcasting_recv; | 3739 | p->enable_broadcasting_receiving = enable_broadcasting_recv; |
4003 | p->env = env; | 3740 | p->env = env; |
4004 | p->sessions = GNUNET_CONTAINER_multipeermap_create (16, | 3741 | p->sessions = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); |
4005 | GNUNET_NO); | 3742 | p->defrag_ctxs = |
4006 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 3743 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
4007 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, | 3744 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, |
4008 | NULL, | 3745 | NULL, |
4009 | NULL, | 3746 | NULL, |
4010 | GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), | 3747 | GNUNET_BANDWIDTH_value_init ( |
3748 | (uint32_t) udp_max_bps), | ||
4011 | 30); | 3749 | 30); |
4012 | res = setup_sockets (p, | 3750 | res = setup_sockets (p, |
4013 | (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, | 3751 | (GNUNET_YES == have_bind6) ? &server_addrv6 : NULL, |
4014 | (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); | 3752 | (GNUNET_YES == have_bind4) ? &server_addrv4 : NULL); |
4015 | if ( (0 == res) || | 3753 | if ((0 == res) || ((NULL == p->sockv4) && (NULL == p->sockv6))) |
4016 | ( (NULL == p->sockv4) && | ||
4017 | (NULL == p->sockv6) ) ) | ||
4018 | { | 3754 | { |
4019 | LOG (GNUNET_ERROR_TYPE_ERROR, | 3755 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Failed to create UDP network sockets\n")); |
4020 | _("Failed to create UDP network sockets\n")); | ||
4021 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); | 3756 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); |
4022 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); | 3757 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); |
4023 | if (NULL != p->nat) | 3758 | if (NULL != p->nat) |
@@ -4027,9 +3762,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
4027 | } | 3762 | } |
4028 | 3763 | ||
4029 | /* Setup broadcasting and receiving beacons */ | 3764 | /* Setup broadcasting and receiving beacons */ |
4030 | setup_broadcast (p, | 3765 | setup_broadcast (p, &server_addrv6, &server_addrv4); |
4031 | &server_addrv6, | ||
4032 | &server_addrv4); | ||
4033 | 3766 | ||
4034 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 3767 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
4035 | api->cls = p; | 3768 | api->cls = p; |
@@ -4108,14 +3841,12 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
4108 | } | 3841 | } |
4109 | if (NULL != plugin->sockv4) | 3842 | if (NULL != plugin->sockv4) |
4110 | { | 3843 | { |
4111 | GNUNET_break (GNUNET_OK == | 3844 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); |
4112 | GNUNET_NETWORK_socket_close (plugin->sockv4)); | ||
4113 | plugin->sockv4 = NULL; | 3845 | plugin->sockv4 = NULL; |
4114 | } | 3846 | } |
4115 | if (NULL != plugin->sockv6) | 3847 | if (NULL != plugin->sockv6) |
4116 | { | 3848 | { |
4117 | GNUNET_break (GNUNET_OK == | 3849 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); |
4118 | GNUNET_NETWORK_socket_close (plugin->sockv6)); | ||
4119 | plugin->sockv6 = NULL; | 3850 | plugin->sockv6 = NULL; |
4120 | } | 3851 | } |
4121 | if (NULL != plugin->nat) | 3852 | if (NULL != plugin->nat) |
@@ -4133,20 +3864,14 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
4133 | } | 3864 | } |
4134 | while (NULL != (udpw = plugin->ipv4_queue_head)) | 3865 | while (NULL != (udpw = plugin->ipv4_queue_head)) |
4135 | { | 3866 | { |
4136 | dequeue (plugin, | 3867 | dequeue (plugin, udpw); |
4137 | udpw); | 3868 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
4138 | udpw->qc (udpw->qc_cls, | ||
4139 | udpw, | ||
4140 | GNUNET_SYSERR); | ||
4141 | GNUNET_free (udpw); | 3869 | GNUNET_free (udpw); |
4142 | } | 3870 | } |
4143 | while (NULL != (udpw = plugin->ipv6_queue_head)) | 3871 | while (NULL != (udpw = plugin->ipv6_queue_head)) |
4144 | { | 3872 | { |
4145 | dequeue (plugin, | 3873 | dequeue (plugin, udpw); |
4146 | udpw); | 3874 | udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR); |
4147 | udpw->qc (udpw->qc_cls, | ||
4148 | udpw, | ||
4149 | GNUNET_SYSERR); | ||
4150 | GNUNET_free (udpw); | 3875 | GNUNET_free (udpw); |
4151 | } | 3876 | } |
4152 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, | 3877 | GNUNET_CONTAINER_multipeermap_iterate (plugin->sessions, |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index 5d095236d..2c408ebf5 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -68,9 +68,10 @@ enum UNIX_ADDRESS_OPTIONS | |||
68 | /** | 68 | /** |
69 | * How long until we give up on transmitting the welcome message? | 69 | * How long until we give up on transmitting the welcome message? |
70 | */ | 70 | */ |
71 | #define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 71 | #define HOSTNAME_RESOLVE_TIMEOUT \ |
72 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
72 | 73 | ||
73 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-unix",__VA_ARGS__) | 74 | #define LOG(kind, ...) GNUNET_log_from (kind, "transport-unix", __VA_ARGS__) |
74 | 75 | ||
75 | 76 | ||
76 | GNUNET_NETWORK_STRUCT_BEGIN | 77 | GNUNET_NETWORK_STRUCT_BEGIN |
@@ -108,7 +109,6 @@ struct UNIXMessage | |||
108 | * What is the identity of the sender (GNUNET_hash of public key) | 109 | * What is the identity of the sender (GNUNET_hash of public key) |
109 | */ | 110 | */ |
110 | struct GNUNET_PeerIdentity sender; | 111 | struct GNUNET_PeerIdentity sender; |
111 | |||
112 | }; | 112 | }; |
113 | 113 | ||
114 | GNUNET_NETWORK_STRUCT_END | 114 | GNUNET_NETWORK_STRUCT_END |
@@ -218,13 +218,12 @@ struct GNUNET_ATS_Session | |||
218 | /** | 218 | /** |
219 | * Session timeout task. | 219 | * Session timeout task. |
220 | */ | 220 | */ |
221 | struct GNUNET_SCHEDULER_Task * timeout_task; | 221 | struct GNUNET_SCHEDULER_Task *timeout_task; |
222 | 222 | ||
223 | /** | 223 | /** |
224 | * Number of messages we currently have in our write queue. | 224 | * Number of messages we currently have in our write queue. |
225 | */ | 225 | */ |
226 | unsigned int msgs_in_queue; | 226 | unsigned int msgs_in_queue; |
227 | |||
228 | }; | 227 | }; |
229 | 228 | ||
230 | 229 | ||
@@ -255,17 +254,17 @@ struct Plugin | |||
255 | /** | 254 | /** |
256 | * ID of task used to update our addresses when one expires. | 255 | * ID of task used to update our addresses when one expires. |
257 | */ | 256 | */ |
258 | struct GNUNET_SCHEDULER_Task * address_update_task; | 257 | struct GNUNET_SCHEDULER_Task *address_update_task; |
259 | 258 | ||
260 | /** | 259 | /** |
261 | * ID of read task | 260 | * ID of read task |
262 | */ | 261 | */ |
263 | struct GNUNET_SCHEDULER_Task * read_task; | 262 | struct GNUNET_SCHEDULER_Task *read_task; |
264 | 263 | ||
265 | /** | 264 | /** |
266 | * ID of write task | 265 | * ID of write task |
267 | */ | 266 | */ |
268 | struct GNUNET_SCHEDULER_Task * write_task; | 267 | struct GNUNET_SCHEDULER_Task *write_task; |
269 | 268 | ||
270 | /** | 269 | /** |
271 | * Number of bytes we currently have in our write queues. | 270 | * Number of bytes we currently have in our write queues. |
@@ -321,7 +320,6 @@ struct Plugin | |||
321 | * Are we using an abstract UNIX domain socket? | 320 | * Are we using an abstract UNIX domain socket? |
322 | */ | 321 | */ |
323 | int is_abstract; | 322 | int is_abstract; |
324 | |||
325 | }; | 323 | }; |
326 | 324 | ||
327 | 325 | ||
@@ -352,9 +350,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
352 | to receive from others) */ | 350 | to receive from others) */ |
353 | info.session_timeout = session->timeout; | 351 | info.session_timeout = session->timeout; |
354 | info.address = session->address; | 352 | info.address = session->address; |
355 | plugin->sic (plugin->sic_cls, | 353 | plugin->sic (plugin->sic_cls, session, &info); |
356 | session, | ||
357 | &info); | ||
358 | } | 354 | } |
359 | 355 | ||
360 | 356 | ||
@@ -370,9 +366,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
370 | * @return string representing the same address | 366 | * @return string representing the same address |
371 | */ | 367 | */ |
372 | static const char * | 368 | static const char * |
373 | unix_plugin_address_to_string (void *cls, | 369 | unix_plugin_address_to_string (void *cls, const void *addr, size_t addrlen) |
374 | const void *addr, | ||
375 | size_t addrlen) | ||
376 | { | 370 | { |
377 | static char rbuf[1024]; | 371 | static char rbuf[1024]; |
378 | struct UnixAddress *ua = (struct UnixAddress *) addr; | 372 | struct UnixAddress *ua = (struct UnixAddress *) addr; |
@@ -382,25 +376,25 @@ unix_plugin_address_to_string (void *cls, | |||
382 | 376 | ||
383 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) | 377 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) |
384 | { | 378 | { |
385 | GNUNET_break(0); | 379 | GNUNET_break (0); |
386 | return NULL; | 380 | return NULL; |
387 | } | 381 | } |
388 | addrstr = (char *) &ua[1]; | 382 | addrstr = (char *) &ua[1]; |
389 | addr_str_len = ntohl (ua->addrlen); | 383 | addr_str_len = ntohl (ua->addrlen); |
390 | 384 | ||
391 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) | 385 | if (addr_str_len != addrlen - sizeof (struct UnixAddress)) |
392 | { | 386 | { |
393 | GNUNET_break(0); | 387 | GNUNET_break (0); |
394 | return NULL; | 388 | return NULL; |
395 | } | 389 | } |
396 | if ('\0' != addrstr[addr_str_len - 1]) | 390 | if ('\0' != addrstr[addr_str_len - 1]) |
397 | { | 391 | { |
398 | GNUNET_break(0); | 392 | GNUNET_break (0); |
399 | return NULL; | 393 | return NULL; |
400 | } | 394 | } |
401 | if (strlen (addrstr) + 1 != addr_str_len) | 395 | if (strlen (addrstr) + 1 != addr_str_len) |
402 | { | 396 | { |
403 | GNUNET_break(0); | 397 | GNUNET_break (0); |
404 | return NULL; | 398 | return NULL; |
405 | } | 399 | } |
406 | 400 | ||
@@ -430,8 +424,7 @@ unix_plugin_address_to_string (void *cls, | |||
430 | * @return #GNUNET_OK on success | 424 | * @return #GNUNET_OK on success |
431 | */ | 425 | */ |
432 | static int | 426 | static int |
433 | unix_plugin_session_disconnect (void *cls, | 427 | unix_plugin_session_disconnect (void *cls, struct GNUNET_ATS_Session *session) |
434 | struct GNUNET_ATS_Session *session) | ||
435 | { | 428 | { |
436 | struct Plugin *plugin = cls; | 429 | struct Plugin *plugin = cls; |
437 | struct UNIXMessageWrapper *msgw; | 430 | struct UNIXMessageWrapper *msgw; |
@@ -443,9 +436,7 @@ unix_plugin_session_disconnect (void *cls, | |||
443 | unix_plugin_address_to_string (NULL, | 436 | unix_plugin_address_to_string (NULL, |
444 | session->address->address, | 437 | session->address->address, |
445 | session->address->address_length)); | 438 | session->address->address_length)); |
446 | plugin->env->session_end (plugin->env->cls, | 439 | plugin->env->session_end (plugin->env->cls, session->address, session); |
447 | session->address, | ||
448 | session); | ||
449 | next = plugin->msg_head; | 440 | next = plugin->msg_head; |
450 | while (NULL != next) | 441 | while (NULL != next) |
451 | { | 442 | { |
@@ -453,9 +444,7 @@ unix_plugin_session_disconnect (void *cls, | |||
453 | next = msgw->next; | 444 | next = msgw->next; |
454 | if (msgw->session != session) | 445 | if (msgw->session != session) |
455 | continue; | 446 | continue; |
456 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 447 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
457 | plugin->msg_tail, | ||
458 | msgw); | ||
459 | session->msgs_in_queue--; | 448 | session->msgs_in_queue--; |
460 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 449 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
461 | session->bytes_in_queue -= msgw->msgsize; | 450 | session->bytes_in_queue -= msgw->msgsize; |
@@ -465,27 +454,27 @@ unix_plugin_session_disconnect (void *cls, | |||
465 | msgw->cont (msgw->cont_cls, | 454 | msgw->cont (msgw->cont_cls, |
466 | &msgw->session->target, | 455 | &msgw->session->target, |
467 | GNUNET_SYSERR, | 456 | GNUNET_SYSERR, |
468 | msgw->payload, 0); | 457 | msgw->payload, |
458 | 0); | ||
469 | GNUNET_free (msgw->msg); | 459 | GNUNET_free (msgw->msg); |
470 | GNUNET_free (msgw); | 460 | GNUNET_free (msgw); |
471 | } | 461 | } |
472 | GNUNET_assert (GNUNET_YES == | 462 | GNUNET_assert (GNUNET_YES == |
473 | GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, | 463 | GNUNET_CONTAINER_multipeermap_remove (plugin->session_map, |
474 | &session->target, | 464 | &session->target, |
475 | session)); | 465 | session)); |
476 | GNUNET_STATISTICS_set (plugin->env->stats, | 466 | GNUNET_STATISTICS_set (plugin->env->stats, |
477 | "# UNIX sessions active", | 467 | "# UNIX sessions active", |
478 | GNUNET_CONTAINER_multipeermap_size (plugin->session_map), | 468 | GNUNET_CONTAINER_multipeermap_size ( |
479 | GNUNET_NO); | 469 | plugin->session_map), |
470 | GNUNET_NO); | ||
480 | if (NULL != session->timeout_task) | 471 | if (NULL != session->timeout_task) |
481 | { | 472 | { |
482 | GNUNET_SCHEDULER_cancel (session->timeout_task); | 473 | GNUNET_SCHEDULER_cancel (session->timeout_task); |
483 | session->timeout_task = NULL; | 474 | session->timeout_task = NULL; |
484 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; | 475 | session->timeout = GNUNET_TIME_UNIT_ZERO_ABS; |
485 | } | 476 | } |
486 | notify_session_monitor (plugin, | 477 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_DONE); |
487 | session, | ||
488 | GNUNET_TRANSPORT_SS_DONE); | ||
489 | GNUNET_HELLO_address_free (session->address); | 478 | GNUNET_HELLO_address_free (session->address); |
490 | GNUNET_break (0 == session->bytes_in_queue); | 479 | GNUNET_break (0 == session->bytes_in_queue); |
491 | GNUNET_break (0 == session->msgs_in_queue); | 480 | GNUNET_break (0 == session->msgs_in_queue); |
@@ -514,16 +503,16 @@ session_timeout (void *cls) | |||
514 | notify_session_monitor (session->plugin, | 503 | notify_session_monitor (session->plugin, |
515 | session, | 504 | session, |
516 | GNUNET_TRANSPORT_SS_UPDATE); | 505 | GNUNET_TRANSPORT_SS_UPDATE); |
517 | session->timeout_task = GNUNET_SCHEDULER_add_delayed (left, | 506 | session->timeout_task = |
518 | &session_timeout, | 507 | GNUNET_SCHEDULER_add_delayed (left, &session_timeout, session); |
519 | session); | ||
520 | return; | 508 | return; |
521 | } | 509 | } |
522 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 510 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
523 | "Session %p was idle for %s, disconnecting\n", | 511 | "Session %p was idle for %s, disconnecting\n", |
524 | session, | 512 | session, |
525 | GNUNET_STRINGS_relative_time_to_string (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 513 | GNUNET_STRINGS_relative_time_to_string ( |
526 | GNUNET_YES)); | 514 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
515 | GNUNET_YES)); | ||
527 | unix_plugin_session_disconnect (session->plugin, session); | 516 | unix_plugin_session_disconnect (session->plugin, session); |
528 | } | 517 | } |
529 | 518 | ||
@@ -539,7 +528,8 @@ static void | |||
539 | reschedule_session_timeout (struct GNUNET_ATS_Session *session) | 528 | reschedule_session_timeout (struct GNUNET_ATS_Session *session) |
540 | { | 529 | { |
541 | GNUNET_assert (NULL != session->timeout_task); | 530 | GNUNET_assert (NULL != session->timeout_task); |
542 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 531 | session->timeout = |
532 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
543 | } | 533 | } |
544 | 534 | ||
545 | 535 | ||
@@ -551,13 +541,12 @@ reschedule_session_timeout (struct GNUNET_ATS_Session *session) | |||
551 | * @return converted unix path | 541 | * @return converted unix path |
552 | */ | 542 | */ |
553 | static struct sockaddr_un * | 543 | static struct sockaddr_un * |
554 | unix_address_to_sockaddr (const char *unixpath, | 544 | unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) |
555 | socklen_t *sock_len) | ||
556 | { | 545 | { |
557 | struct sockaddr_un *un; | 546 | struct sockaddr_un *un; |
558 | size_t slen; | 547 | size_t slen; |
559 | 548 | ||
560 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 549 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
561 | un = GNUNET_new (struct sockaddr_un); | 550 | un = GNUNET_new (struct sockaddr_un); |
562 | un->sun_family = AF_UNIX; | 551 | un->sun_family = AF_UNIX; |
563 | slen = strlen (unixpath); | 552 | slen = strlen (unixpath); |
@@ -601,14 +590,13 @@ struct LookupCtx | |||
601 | */ | 590 | */ |
602 | static int | 591 | static int |
603 | lookup_session_it (void *cls, | 592 | lookup_session_it (void *cls, |
604 | const struct GNUNET_PeerIdentity * key, | 593 | const struct GNUNET_PeerIdentity *key, |
605 | void *value) | 594 | void *value) |
606 | { | 595 | { |
607 | struct LookupCtx *lctx = cls; | 596 | struct LookupCtx *lctx = cls; |
608 | struct GNUNET_ATS_Session *session = value; | 597 | struct GNUNET_ATS_Session *session = value; |
609 | 598 | ||
610 | if (0 == GNUNET_HELLO_address_cmp (lctx->address, | 599 | if (0 == GNUNET_HELLO_address_cmp (lctx->address, session->address)) |
611 | session->address)) | ||
612 | { | 600 | { |
613 | lctx->res = session; | 601 | lctx->res = session; |
614 | return GNUNET_NO; | 602 | return GNUNET_NO; |
@@ -633,8 +621,9 @@ lookup_session (struct Plugin *plugin, | |||
633 | lctx.address = address; | 621 | lctx.address = address; |
634 | lctx.res = NULL; | 622 | lctx.res = NULL; |
635 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 623 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, |
636 | &address->peer, | 624 | &address->peer, |
637 | &lookup_session_it, &lctx); | 625 | &lookup_session_it, |
626 | &lctx); | ||
638 | return lctx.res; | 627 | return lctx.res; |
639 | } | 628 | } |
640 | 629 | ||
@@ -707,16 +696,15 @@ unix_real_send (void *cls, | |||
707 | } | 696 | } |
708 | 697 | ||
709 | /* Prepare address */ | 698 | /* Prepare address */ |
710 | unixpath = (const char *) &addr[1]; | 699 | unixpath = (const char *) &addr[1]; |
711 | if (NULL == (un = unix_address_to_sockaddr (unixpath, | 700 | if (NULL == (un = unix_address_to_sockaddr (unixpath, &un_len))) |
712 | &un_len))) | ||
713 | { | 701 | { |
714 | GNUNET_break (0); | 702 | GNUNET_break (0); |
715 | return -1; | 703 | return -1; |
716 | } | 704 | } |
717 | 705 | ||
718 | if ((GNUNET_YES == plugin->is_abstract) && | 706 | if ((GNUNET_YES == plugin->is_abstract) && |
719 | (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl(addr->options) )) ) | 707 | (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & ntohl (addr->options)))) |
720 | { | 708 | { |
721 | un->sun_path[0] = '\0'; | 709 | un->sun_path[0] = '\0'; |
722 | } | 710 | } |
@@ -729,8 +717,7 @@ resend: | |||
729 | un_len); | 717 | un_len); |
730 | if (GNUNET_SYSERR == sent) | 718 | if (GNUNET_SYSERR == sent) |
731 | { | 719 | { |
732 | if ( (EAGAIN == errno) || | 720 | if ((EAGAIN == errno) || (ENOBUFS == errno)) |
733 | (ENOBUFS == errno) ) | ||
734 | { | 721 | { |
735 | GNUNET_free (un); | 722 | GNUNET_free (un); |
736 | return RETRY; /* We have to retry later */ | 723 | return RETRY; /* We have to retry later */ |
@@ -741,7 +728,10 @@ resend: | |||
741 | socklen_t len = sizeof (size); | 728 | socklen_t len = sizeof (size); |
742 | 729 | ||
743 | GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) | 730 | GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *) |
744 | send_handle, SOL_SOCKET, SO_SNDBUF, &size, | 731 | send_handle, |
732 | SOL_SOCKET, | ||
733 | SO_SNDBUF, | ||
734 | &size, | ||
745 | &len); | 735 | &len); |
746 | if (size < msgbuf_size) | 736 | if (size < msgbuf_size) |
747 | { | 737 | { |
@@ -752,9 +742,12 @@ resend: | |||
752 | (unsigned int) msgbuf_size); | 742 | (unsigned int) msgbuf_size); |
753 | size = ((msgbuf_size / 1000) + 2) * 1000; | 743 | size = ((msgbuf_size / 1000) + 2) * 1000; |
754 | if (GNUNET_OK == | 744 | if (GNUNET_OK == |
755 | GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) send_handle, | 745 | GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle *) |
756 | SOL_SOCKET, SO_SNDBUF, | 746 | send_handle, |
757 | &size, sizeof (size))) | 747 | SOL_SOCKET, |
748 | SO_SNDBUF, | ||
749 | &size, | ||
750 | sizeof (size))) | ||
758 | goto resend; /* Increased buffer size, retry sending */ | 751 | goto resend; /* Increased buffer size, retry sending */ |
759 | else | 752 | else |
760 | { | 753 | { |
@@ -778,9 +771,9 @@ resend: | |||
778 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 771 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
779 | "UNIX transmitted %u-byte message to %s (%d: %s)\n", | 772 | "UNIX transmitted %u-byte message to %s (%d: %s)\n", |
780 | (unsigned int) msgbuf_size, | 773 | (unsigned int) msgbuf_size, |
781 | GNUNET_a2s ((const struct sockaddr *)un, un_len), | 774 | GNUNET_a2s ((const struct sockaddr *) un, un_len), |
782 | (int) sent, | 775 | (int) sent, |
783 | (sent < 0) ? STRERROR (errno) : "ok"); | 776 | (sent < 0) ? strerror (errno) : "ok"); |
784 | GNUNET_free (un); | 777 | GNUNET_free (un); |
785 | return sent; | 778 | return sent; |
786 | } | 779 | } |
@@ -794,8 +787,7 @@ resend: | |||
794 | * @return the network type in HBO or #GNUNET_SYSERR | 787 | * @return the network type in HBO or #GNUNET_SYSERR |
795 | */ | 788 | */ |
796 | static enum GNUNET_NetworkType | 789 | static enum GNUNET_NetworkType |
797 | unix_plugin_get_network (void *cls, | 790 | unix_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session) |
798 | struct GNUNET_ATS_Session *session) | ||
799 | { | 791 | { |
800 | GNUNET_assert (NULL != session); | 792 | GNUNET_assert (NULL != session); |
801 | return GNUNET_NT_LOOPBACK; | 793 | return GNUNET_NT_LOOPBACK; |
@@ -827,19 +819,18 @@ unix_plugin_get_network_for_address (void *cls, | |||
827 | * @return the session or NULL of max connections exceeded | 819 | * @return the session or NULL of max connections exceeded |
828 | */ | 820 | */ |
829 | static struct GNUNET_ATS_Session * | 821 | static struct GNUNET_ATS_Session * |
830 | unix_plugin_get_session (void *cls, | 822 | unix_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address) |
831 | const struct GNUNET_HELLO_Address *address) | ||
832 | { | 823 | { |
833 | struct Plugin *plugin = cls; | 824 | struct Plugin *plugin = cls; |
834 | struct GNUNET_ATS_Session *session; | 825 | struct GNUNET_ATS_Session *session; |
835 | struct UnixAddress *ua; | 826 | struct UnixAddress *ua; |
836 | char * addrstr; | 827 | char *addrstr; |
837 | uint32_t addr_str_len; | 828 | uint32_t addr_str_len; |
838 | uint32_t addr_option; | 829 | uint32_t addr_option; |
839 | 830 | ||
840 | ua = (struct UnixAddress *) address->address; | 831 | ua = (struct UnixAddress *) address->address; |
841 | if ((NULL == address->address) || (0 == address->address_length) || | 832 | if ((NULL == address->address) || (0 == address->address_length) || |
842 | (sizeof (struct UnixAddress) > address->address_length)) | 833 | (sizeof (struct UnixAddress) > address->address_length)) |
843 | { | 834 | { |
844 | GNUNET_break (0); | 835 | GNUNET_break (0); |
845 | return NULL; | 836 | return NULL; |
@@ -848,8 +839,8 @@ unix_plugin_get_session (void *cls, | |||
848 | addr_str_len = ntohl (ua->addrlen); | 839 | addr_str_len = ntohl (ua->addrlen); |
849 | addr_option = ntohl (ua->options); | 840 | addr_option = ntohl (ua->options); |
850 | 841 | ||
851 | if ( (0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && | 842 | if ((0 != (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS & addr_option)) && |
852 | (GNUNET_NO == plugin->is_abstract)) | 843 | (GNUNET_NO == plugin->is_abstract)) |
853 | { | 844 | { |
854 | return NULL; | 845 | return NULL; |
855 | } | 846 | } |
@@ -871,13 +862,12 @@ unix_plugin_get_session (void *cls, | |||
871 | } | 862 | } |
872 | 863 | ||
873 | /* Check if a session for this address already exists */ | 864 | /* Check if a session for this address already exists */ |
874 | if (NULL != (session = lookup_session (plugin, | 865 | if (NULL != (session = lookup_session (plugin, address))) |
875 | address))) | 866 | { |
876 | { | ||
877 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 867 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
878 | "Found existing session %p for address `%s'\n", | 868 | "Found existing session %p for address `%s'\n", |
879 | session, | 869 | session, |
880 | unix_plugin_address_to_string (NULL, | 870 | unix_plugin_address_to_string (NULL, |
881 | address->address, | 871 | address->address, |
882 | address->address_length)); | 872 | address->address_length)); |
883 | return session; | 873 | return session; |
@@ -888,29 +878,30 @@ unix_plugin_get_session (void *cls, | |||
888 | session->target = address->peer; | 878 | session->target = address->peer; |
889 | session->address = GNUNET_HELLO_address_copy (address); | 879 | session->address = GNUNET_HELLO_address_copy (address); |
890 | session->plugin = plugin; | 880 | session->plugin = plugin; |
891 | session->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | 881 | session->timeout = |
892 | session->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, | 882 | GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); |
893 | &session_timeout, | 883 | session->timeout_task = |
894 | session); | 884 | GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, |
885 | &session_timeout, | ||
886 | session); | ||
895 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 887 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
896 | "Creating a new session %p for address `%s'\n", | 888 | "Creating a new session %p for address `%s'\n", |
897 | session, | 889 | session, |
898 | unix_plugin_address_to_string (NULL, | 890 | unix_plugin_address_to_string (NULL, |
899 | address->address, | 891 | address->address, |
900 | address->address_length)); | 892 | address->address_length)); |
901 | (void) GNUNET_CONTAINER_multipeermap_put (plugin->session_map, | 893 | (void) GNUNET_CONTAINER_multipeermap_put ( |
902 | &address->peer, session, | 894 | plugin->session_map, |
903 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 895 | &address->peer, |
896 | session, | ||
897 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | ||
904 | GNUNET_STATISTICS_set (plugin->env->stats, | 898 | GNUNET_STATISTICS_set (plugin->env->stats, |
905 | "# UNIX sessions active", | 899 | "# UNIX sessions active", |
906 | GNUNET_CONTAINER_multipeermap_size (plugin->session_map), | 900 | GNUNET_CONTAINER_multipeermap_size ( |
907 | GNUNET_NO); | 901 | plugin->session_map), |
908 | notify_session_monitor (plugin, | 902 | GNUNET_NO); |
909 | session, | 903 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
910 | GNUNET_TRANSPORT_SS_INIT); | 904 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
911 | notify_session_monitor (plugin, | ||
912 | session, | ||
913 | GNUNET_TRANSPORT_SS_UP); | ||
914 | return session; | 905 | return session; |
915 | } | 906 | } |
916 | 907 | ||
@@ -967,15 +958,17 @@ unix_demultiplexer (struct Plugin *plugin, | |||
967 | "Received message from %s\n", | 958 | "Received message from %s\n", |
968 | unix_plugin_address_to_string (NULL, ua, ua_len)); | 959 | unix_plugin_address_to_string (NULL, ua, ua_len)); |
969 | GNUNET_STATISTICS_update (plugin->env->stats, | 960 | GNUNET_STATISTICS_update (plugin->env->stats, |
970 | "# bytes received via UNIX", | 961 | "# bytes received via UNIX", |
971 | ntohs (currhdr->size), | 962 | ntohs (currhdr->size), |
972 | GNUNET_NO); | 963 | GNUNET_NO); |
973 | 964 | ||
974 | /* Look for existing session */ | 965 | /* Look for existing session */ |
975 | address = GNUNET_HELLO_address_allocate (sender, | 966 | address = GNUNET_HELLO_address_allocate ( |
976 | PLUGIN_NAME, | 967 | sender, |
977 | ua, ua_len, | 968 | PLUGIN_NAME, |
978 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ | 969 | ua, |
970 | ua_len, | ||
971 | GNUNET_HELLO_ADDRESS_INFO_NONE); /* UNIX does not have "inbound" sessions */ | ||
979 | session = lookup_session (plugin, address); | 972 | session = lookup_session (plugin, address); |
980 | if (NULL == session) | 973 | if (NULL == session) |
981 | { | 974 | { |
@@ -991,10 +984,7 @@ unix_demultiplexer (struct Plugin *plugin, | |||
991 | reschedule_session_timeout (session); | 984 | reschedule_session_timeout (session); |
992 | } | 985 | } |
993 | GNUNET_HELLO_address_free (address); | 986 | GNUNET_HELLO_address_free (address); |
994 | plugin->env->receive (plugin->env->cls, | 987 | plugin->env->receive (plugin->env->cls, session->address, session, currhdr); |
995 | session->address, | ||
996 | session, | ||
997 | currhdr); | ||
998 | } | 988 | } |
999 | 989 | ||
1000 | 990 | ||
@@ -1024,23 +1014,23 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1024 | addrlen = sizeof (un); | 1014 | addrlen = sizeof (un); |
1025 | memset (&un, 0, sizeof (un)); | 1015 | memset (&un, 0, sizeof (un)); |
1026 | ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, | 1016 | ret = GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, |
1027 | buf, sizeof (buf), | 1017 | buf, |
1018 | sizeof (buf), | ||
1028 | (struct sockaddr *) &un, | 1019 | (struct sockaddr *) &un, |
1029 | &addrlen); | 1020 | &addrlen); |
1030 | if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) | 1021 | if ((GNUNET_SYSERR == ret) && ((errno == EAGAIN) || (errno == ENOBUFS))) |
1031 | return; | 1022 | return; |
1032 | if (GNUNET_SYSERR == ret) | 1023 | if (GNUNET_SYSERR == ret) |
1033 | { | 1024 | { |
1034 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, | 1025 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); |
1035 | "recvfrom"); | ||
1036 | return; | 1026 | return; |
1037 | } | 1027 | } |
1038 | else | 1028 | else |
1039 | { | 1029 | { |
1040 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1030 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1041 | "Read %d bytes from socket %s\n", | 1031 | "Read %d bytes from socket %s\n", |
1042 | (int) ret, | 1032 | (int) ret, |
1043 | un.sun_path); | 1033 | un.sun_path); |
1044 | } | 1034 | } |
1045 | 1035 | ||
1046 | GNUNET_assert (AF_UNIX == (un.sun_family)); | 1036 | GNUNET_assert (AF_UNIX == (un.sun_family)); |
@@ -1053,12 +1043,12 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1053 | 1043 | ||
1054 | ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; | 1044 | ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; |
1055 | ua = GNUNET_malloc (ua_len); | 1045 | ua = GNUNET_malloc (ua_len); |
1056 | ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); | 1046 | ua->addrlen = htonl (strlen (&un.sun_path[0]) + 1); |
1057 | GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); | 1047 | GNUNET_memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); |
1058 | if (is_abstract) | 1048 | if (is_abstract) |
1059 | ua->options = htonl(UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); | 1049 | ua->options = htonl (UNIX_OPTIONS_USE_ABSTRACT_SOCKETS); |
1060 | else | 1050 | else |
1061 | ua->options = htonl(UNIX_OPTIONS_NONE); | 1051 | ua->options = htonl (UNIX_OPTIONS_NONE); |
1062 | 1052 | ||
1063 | msg = (struct UNIXMessage *) buf; | 1053 | msg = (struct UNIXMessage *) buf; |
1064 | csize = ntohs (msg->header.size); | 1054 | csize = ntohs (msg->header.size); |
@@ -1069,9 +1059,7 @@ unix_plugin_do_read (struct Plugin *plugin) | |||
1069 | return; | 1059 | return; |
1070 | } | 1060 | } |
1071 | msgbuf = (char *) &msg[1]; | 1061 | msgbuf = (char *) &msg[1]; |
1072 | GNUNET_memcpy (&sender, | 1062 | GNUNET_memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); |
1073 | &msg->sender, | ||
1074 | sizeof (struct GNUNET_PeerIdentity)); | ||
1075 | offset = 0; | 1063 | offset = 0; |
1076 | tsize = csize - sizeof (struct UNIXMessage); | 1064 | tsize = csize - sizeof (struct UNIXMessage); |
1077 | while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) | 1065 | while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) |
@@ -1113,11 +1101,9 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1113 | /* Message has a timeout */ | 1101 | /* Message has a timeout */ |
1114 | did_delete = GNUNET_YES; | 1102 | did_delete = GNUNET_YES; |
1115 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1103 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1116 | "Timeout for message with %u bytes \n", | 1104 | "Timeout for message with %u bytes \n", |
1117 | (unsigned int) msgw->msgsize); | 1105 | (unsigned int) msgw->msgsize); |
1118 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 1106 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
1119 | plugin->msg_tail, | ||
1120 | msgw); | ||
1121 | session = msgw->session; | 1107 | session = msgw->session; |
1122 | session->msgs_in_queue--; | 1108 | session->msgs_in_queue--; |
1123 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1109 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
@@ -1125,28 +1111,26 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1125 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); | 1111 | GNUNET_assert (plugin->bytes_in_queue >= msgw->msgsize); |
1126 | plugin->bytes_in_queue -= msgw->msgsize; | 1112 | plugin->bytes_in_queue -= msgw->msgsize; |
1127 | GNUNET_STATISTICS_set (plugin->env->stats, | 1113 | GNUNET_STATISTICS_set (plugin->env->stats, |
1128 | "# bytes currently in UNIX buffers", | 1114 | "# bytes currently in UNIX buffers", |
1129 | plugin->bytes_in_queue, | 1115 | plugin->bytes_in_queue, |
1130 | GNUNET_NO); | 1116 | GNUNET_NO); |
1131 | GNUNET_STATISTICS_update (plugin->env->stats, | 1117 | GNUNET_STATISTICS_update (plugin->env->stats, |
1132 | "# UNIX bytes discarded", | 1118 | "# UNIX bytes discarded", |
1133 | msgw->msgsize, | 1119 | msgw->msgsize, |
1134 | GNUNET_NO); | 1120 | GNUNET_NO); |
1135 | if (NULL != msgw->cont) | 1121 | if (NULL != msgw->cont) |
1136 | msgw->cont (msgw->cont_cls, | 1122 | msgw->cont (msgw->cont_cls, |
1137 | &msgw->session->target, | 1123 | &msgw->session->target, |
1138 | GNUNET_SYSERR, | 1124 | GNUNET_SYSERR, |
1139 | msgw->payload, | 1125 | msgw->payload, |
1140 | 0); | 1126 | 0); |
1141 | GNUNET_free (msgw->msg); | 1127 | GNUNET_free (msgw->msg); |
1142 | GNUNET_free (msgw); | 1128 | GNUNET_free (msgw); |
1143 | } | 1129 | } |
1144 | if (NULL == msgw) | 1130 | if (NULL == msgw) |
1145 | { | 1131 | { |
1146 | if (GNUNET_YES == did_delete) | 1132 | if (GNUNET_YES == did_delete) |
1147 | notify_session_monitor (plugin, | 1133 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1148 | session, | ||
1149 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1150 | return; /* Nothing to send at the moment */ | 1134 | return; /* Nothing to send at the moment */ |
1151 | } | 1135 | } |
1152 | session = msgw->session; | 1136 | session = msgw->session; |
@@ -1160,20 +1144,18 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1160 | msgw->session->address->address, | 1144 | msgw->session->address->address, |
1161 | msgw->session->address->address_length, | 1145 | msgw->session->address->address_length, |
1162 | msgw->payload, | 1146 | msgw->payload, |
1163 | msgw->cont, msgw->cont_cls); | 1147 | msgw->cont, |
1148 | msgw->cont_cls); | ||
1164 | if (RETRY == sent) | 1149 | if (RETRY == sent) |
1165 | { | 1150 | { |
1166 | GNUNET_STATISTICS_update (plugin->env->stats, | 1151 | GNUNET_STATISTICS_update (plugin->env->stats, |
1167 | "# UNIX retry attempts", | 1152 | "# UNIX retry attempts", |
1168 | 1, GNUNET_NO); | 1153 | 1, |
1169 | notify_session_monitor (plugin, | 1154 | GNUNET_NO); |
1170 | session, | 1155 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1171 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1172 | return; | 1156 | return; |
1173 | } | 1157 | } |
1174 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 1158 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
1175 | plugin->msg_tail, | ||
1176 | msgw); | ||
1177 | session->msgs_in_queue--; | 1159 | session->msgs_in_queue--; |
1178 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1160 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
1179 | session->bytes_in_queue -= msgw->msgsize; | 1161 | session->bytes_in_queue -= msgw->msgsize; |
@@ -1181,10 +1163,9 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1181 | plugin->bytes_in_queue -= msgw->msgsize; | 1163 | plugin->bytes_in_queue -= msgw->msgsize; |
1182 | GNUNET_STATISTICS_set (plugin->env->stats, | 1164 | GNUNET_STATISTICS_set (plugin->env->stats, |
1183 | "# bytes currently in UNIX buffers", | 1165 | "# bytes currently in UNIX buffers", |
1184 | plugin->bytes_in_queue, GNUNET_NO); | 1166 | plugin->bytes_in_queue, |
1185 | notify_session_monitor (plugin, | 1167 | GNUNET_NO); |
1186 | session, | 1168 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1187 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1188 | if (GNUNET_SYSERR == sent) | 1169 | if (GNUNET_SYSERR == sent) |
1189 | { | 1170 | { |
1190 | /* failed and no retry */ | 1171 | /* failed and no retry */ |
@@ -1192,11 +1173,12 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1192 | msgw->cont (msgw->cont_cls, | 1173 | msgw->cont (msgw->cont_cls, |
1193 | &msgw->session->target, | 1174 | &msgw->session->target, |
1194 | GNUNET_SYSERR, | 1175 | GNUNET_SYSERR, |
1195 | msgw->payload, 0); | 1176 | msgw->payload, |
1177 | 0); | ||
1196 | GNUNET_STATISTICS_update (plugin->env->stats, | 1178 | GNUNET_STATISTICS_update (plugin->env->stats, |
1197 | "# UNIX bytes discarded", | 1179 | "# UNIX bytes discarded", |
1198 | msgw->msgsize, | 1180 | msgw->msgsize, |
1199 | GNUNET_NO); | 1181 | GNUNET_NO); |
1200 | GNUNET_free (msgw->msg); | 1182 | GNUNET_free (msgw->msg); |
1201 | GNUNET_free (msgw); | 1183 | GNUNET_free (msgw); |
1202 | return; | 1184 | return; |
@@ -1204,15 +1186,15 @@ unix_plugin_do_write (struct Plugin *plugin) | |||
1204 | /* successfully sent bytes */ | 1186 | /* successfully sent bytes */ |
1205 | GNUNET_break (sent > 0); | 1187 | GNUNET_break (sent > 0); |
1206 | GNUNET_STATISTICS_update (plugin->env->stats, | 1188 | GNUNET_STATISTICS_update (plugin->env->stats, |
1207 | "# bytes transmitted via UNIX", | 1189 | "# bytes transmitted via UNIX", |
1208 | msgw->msgsize, | 1190 | msgw->msgsize, |
1209 | GNUNET_NO); | 1191 | GNUNET_NO); |
1210 | if (NULL != msgw->cont) | 1192 | if (NULL != msgw->cont) |
1211 | msgw->cont (msgw->cont_cls, | 1193 | msgw->cont (msgw->cont_cls, |
1212 | &msgw->session->target, | 1194 | &msgw->session->target, |
1213 | GNUNET_OK, | 1195 | GNUNET_OK, |
1214 | msgw->payload, | 1196 | msgw->payload, |
1215 | msgw->msgsize); | 1197 | msgw->msgsize); |
1216 | GNUNET_free (msgw->msg); | 1198 | GNUNET_free (msgw->msg); |
1217 | GNUNET_free (msgw); | 1199 | GNUNET_free (msgw); |
1218 | } | 1200 | } |
@@ -1237,7 +1219,8 @@ unix_plugin_select_read (void *cls) | |||
1237 | plugin->read_task = | 1219 | plugin->read_task = |
1238 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1220 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1239 | plugin->unix_sock.desc, | 1221 | plugin->unix_sock.desc, |
1240 | &unix_plugin_select_read, plugin); | 1222 | &unix_plugin_select_read, |
1223 | plugin); | ||
1241 | } | 1224 | } |
1242 | 1225 | ||
1243 | 1226 | ||
@@ -1262,7 +1245,8 @@ unix_plugin_select_write (void *cls) | |||
1262 | plugin->write_task = | 1245 | plugin->write_task = |
1263 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1246 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1264 | plugin->unix_sock.desc, | 1247 | plugin->unix_sock.desc, |
1265 | &unix_plugin_select_write, plugin); | 1248 | &unix_plugin_select_write, |
1249 | plugin); | ||
1266 | } | 1250 | } |
1267 | 1251 | ||
1268 | 1252 | ||
@@ -1310,13 +1294,13 @@ unix_plugin_send (void *cls, | |||
1310 | 1294 | ||
1311 | if (GNUNET_OK != | 1295 | if (GNUNET_OK != |
1312 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, | 1296 | GNUNET_CONTAINER_multipeermap_contains_value (plugin->session_map, |
1313 | &session->target, | 1297 | &session->target, |
1314 | session)) | 1298 | session)) |
1315 | { | 1299 | { |
1316 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1300 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1317 | "Invalid session for peer `%s' `%s'\n", | 1301 | "Invalid session for peer `%s' `%s'\n", |
1318 | GNUNET_i2s (&session->target), | 1302 | GNUNET_i2s (&session->target), |
1319 | unix_plugin_address_to_string (NULL, | 1303 | unix_plugin_address_to_string (NULL, |
1320 | session->address->address, | 1304 | session->address->address, |
1321 | session->address->address_length)); | 1305 | session->address->address_length)); |
1322 | GNUNET_break (0); | 1306 | GNUNET_break (0); |
@@ -1333,16 +1317,16 @@ unix_plugin_send (void *cls, | |||
1333 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); | 1317 | message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); |
1334 | message->header.size = htons (ssize); | 1318 | message->header.size = htons (ssize); |
1335 | message->header.type = htons (0); | 1319 | message->header.type = htons (0); |
1336 | GNUNET_memcpy (&message->sender, plugin->env->my_identity, | 1320 | GNUNET_memcpy (&message->sender, |
1337 | sizeof (struct GNUNET_PeerIdentity)); | 1321 | plugin->env->my_identity, |
1322 | sizeof (struct GNUNET_PeerIdentity)); | ||
1338 | GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); | 1323 | GNUNET_memcpy (&message[1], msgbuf, msgbuf_size); |
1339 | wrapper = GNUNET_new (struct UNIXMessageWrapper); | 1324 | wrapper = GNUNET_new (struct UNIXMessageWrapper); |
1340 | wrapper->msg = message; | 1325 | wrapper->msg = message; |
1341 | wrapper->msgsize = ssize; | 1326 | wrapper->msgsize = ssize; |
1342 | wrapper->payload = msgbuf_size; | 1327 | wrapper->payload = msgbuf_size; |
1343 | wrapper->priority = priority; | 1328 | wrapper->priority = priority; |
1344 | wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), | 1329 | wrapper->timeout = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), to); |
1345 | to); | ||
1346 | wrapper->cont = cont; | 1330 | wrapper->cont = cont; |
1347 | wrapper->cont_cls = cont_cls; | 1331 | wrapper->cont_cls = cont_cls; |
1348 | wrapper->session = session; | 1332 | wrapper->session = session; |
@@ -1353,17 +1337,16 @@ unix_plugin_send (void *cls, | |||
1353 | session->bytes_in_queue += ssize; | 1337 | session->bytes_in_queue += ssize; |
1354 | session->msgs_in_queue++; | 1338 | session->msgs_in_queue++; |
1355 | GNUNET_STATISTICS_set (plugin->env->stats, | 1339 | GNUNET_STATISTICS_set (plugin->env->stats, |
1356 | "# bytes currently in UNIX buffers", | 1340 | "# bytes currently in UNIX buffers", |
1357 | plugin->bytes_in_queue, | 1341 | plugin->bytes_in_queue, |
1358 | GNUNET_NO); | 1342 | GNUNET_NO); |
1359 | notify_session_monitor (plugin, | 1343 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UPDATE); |
1360 | session, | ||
1361 | GNUNET_TRANSPORT_SS_UPDATE); | ||
1362 | if (NULL == plugin->write_task) | 1344 | if (NULL == plugin->write_task) |
1363 | plugin->write_task = | 1345 | plugin->write_task = |
1364 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1346 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1365 | plugin->unix_sock.desc, | 1347 | plugin->unix_sock.desc, |
1366 | &unix_plugin_select_write, plugin); | 1348 | &unix_plugin_select_write, |
1349 | plugin); | ||
1367 | return ssize; | 1350 | return ssize; |
1368 | } | 1351 | } |
1369 | 1352 | ||
@@ -1381,15 +1364,14 @@ unix_transport_server_start (void *cls) | |||
1381 | struct sockaddr_un *un; | 1364 | struct sockaddr_un *un; |
1382 | socklen_t un_len; | 1365 | socklen_t un_len; |
1383 | 1366 | ||
1384 | un = unix_address_to_sockaddr (plugin->unix_socket_path, | 1367 | un = unix_address_to_sockaddr (plugin->unix_socket_path, &un_len); |
1385 | &un_len); | ||
1386 | if (GNUNET_YES == plugin->is_abstract) | 1368 | if (GNUNET_YES == plugin->is_abstract) |
1387 | { | 1369 | { |
1388 | plugin->unix_socket_path[0] = '@'; | 1370 | plugin->unix_socket_path[0] = '@'; |
1389 | un->sun_path[0] = '\0'; | 1371 | un->sun_path[0] = '\0'; |
1390 | } | 1372 | } |
1391 | plugin->unix_sock.desc = | 1373 | plugin->unix_sock.desc = |
1392 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); | 1374 | GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); |
1393 | if (NULL == plugin->unix_sock.desc) | 1375 | if (NULL == plugin->unix_sock.desc) |
1394 | { | 1376 | { |
1395 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 1377 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
@@ -1400,33 +1382,32 @@ unix_transport_server_start (void *cls) | |||
1400 | { | 1382 | { |
1401 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) | 1383 | if (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path)) |
1402 | { | 1384 | { |
1403 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot create path to `%s'\n"), | 1385 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1404 | un->sun_path); | 1386 | _ ("Cannot create path to `%s'\n"), |
1387 | un->sun_path); | ||
1405 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | 1388 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); |
1406 | plugin->unix_sock.desc = NULL; | 1389 | plugin->unix_sock.desc = NULL; |
1407 | GNUNET_free (un); | 1390 | GNUNET_free (un); |
1408 | return GNUNET_SYSERR; | 1391 | return GNUNET_SYSERR; |
1409 | } | 1392 | } |
1410 | } | 1393 | } |
1411 | if (GNUNET_OK != | 1394 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, |
1412 | GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, | 1395 | (const struct sockaddr *) un, |
1413 | (const struct sockaddr *) un, un_len)) | 1396 | un_len)) |
1414 | { | 1397 | { |
1415 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 1398 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
1416 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot bind to `%s'\n"), | 1399 | LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Cannot bind to `%s'\n"), un->sun_path); |
1417 | un->sun_path); | ||
1418 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | 1400 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); |
1419 | plugin->unix_sock.desc = NULL; | 1401 | plugin->unix_sock.desc = NULL; |
1420 | GNUNET_free (un); | 1402 | GNUNET_free (un); |
1421 | return GNUNET_SYSERR; | 1403 | return GNUNET_SYSERR; |
1422 | } | 1404 | } |
1423 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1405 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", plugin->unix_socket_path); |
1424 | "Bound to `%s'\n", | ||
1425 | plugin->unix_socket_path); | ||
1426 | plugin->read_task = | 1406 | plugin->read_task = |
1427 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 1407 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
1428 | plugin->unix_sock.desc, | 1408 | plugin->unix_sock.desc, |
1429 | &unix_plugin_select_read, plugin); | 1409 | &unix_plugin_select_read, |
1410 | plugin); | ||
1430 | GNUNET_free (un); | 1411 | GNUNET_free (un); |
1431 | return 1; | 1412 | return 1; |
1432 | } | 1413 | } |
@@ -1449,18 +1430,15 @@ unix_transport_server_start (void *cls) | |||
1449 | * | 1430 | * |
1450 | */ | 1431 | */ |
1451 | static int | 1432 | static int |
1452 | unix_plugin_check_address (void *cls, | 1433 | unix_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
1453 | const void *addr, | ||
1454 | size_t addrlen) | ||
1455 | { | 1434 | { |
1456 | struct Plugin* plugin = cls; | 1435 | struct Plugin *plugin = cls; |
1457 | const struct UnixAddress *ua = addr; | 1436 | const struct UnixAddress *ua = addr; |
1458 | char *addrstr; | 1437 | char *addrstr; |
1459 | size_t addr_str_len; | 1438 | size_t addr_str_len; |
1460 | 1439 | ||
1461 | if ( (NULL == addr) || | 1440 | if ((NULL == addr) || (0 == addrlen) || |
1462 | (0 == addrlen) || | 1441 | (sizeof (struct UnixAddress) > addrlen)) |
1463 | (sizeof (struct UnixAddress) > addrlen) ) | ||
1464 | { | 1442 | { |
1465 | GNUNET_break (0); | 1443 | GNUNET_break (0); |
1466 | return GNUNET_SYSERR; | 1444 | return GNUNET_SYSERR; |
@@ -1479,7 +1457,7 @@ unix_plugin_check_address (void *cls, | |||
1479 | } | 1457 | } |
1480 | 1458 | ||
1481 | if (0 == strcmp (plugin->unix_socket_path, addrstr)) | 1459 | if (0 == strcmp (plugin->unix_socket_path, addrstr)) |
1482 | return GNUNET_OK; | 1460 | return GNUNET_OK; |
1483 | return GNUNET_SYSERR; | 1461 | return GNUNET_SYSERR; |
1484 | } | 1462 | } |
1485 | 1463 | ||
@@ -1499,7 +1477,8 @@ unix_plugin_check_address (void *cls, | |||
1499 | * @param asc_cls closure for @a asc | 1477 | * @param asc_cls closure for @a asc |
1500 | */ | 1478 | */ |
1501 | static void | 1479 | static void |
1502 | unix_plugin_address_pretty_printer (void *cls, const char *type, | 1480 | unix_plugin_address_pretty_printer (void *cls, |
1481 | const char *type, | ||
1503 | const void *addr, | 1482 | const void *addr, |
1504 | size_t addrlen, | 1483 | size_t addrlen, |
1505 | int numeric, | 1484 | int numeric, |
@@ -1509,15 +1488,11 @@ unix_plugin_address_pretty_printer (void *cls, const char *type, | |||
1509 | { | 1488 | { |
1510 | const char *ret; | 1489 | const char *ret; |
1511 | 1490 | ||
1512 | if ( (NULL != addr) && (addrlen > 0)) | 1491 | if ((NULL != addr) && (addrlen > 0)) |
1513 | ret = unix_plugin_address_to_string (NULL, | 1492 | ret = unix_plugin_address_to_string (NULL, addr, addrlen); |
1514 | addr, | ||
1515 | addrlen); | ||
1516 | else | 1493 | else |
1517 | ret = NULL; | 1494 | ret = NULL; |
1518 | asc (asc_cls, | 1495 | asc (asc_cls, ret, (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); |
1519 | ret, | ||
1520 | (NULL == ret) ? GNUNET_SYSERR : GNUNET_OK); | ||
1521 | asc (asc_cls, NULL, GNUNET_OK); | 1496 | asc (asc_cls, NULL, GNUNET_OK); |
1522 | } | 1497 | } |
1523 | 1498 | ||
@@ -1538,7 +1513,8 @@ static int | |||
1538 | unix_plugin_string_to_address (void *cls, | 1513 | unix_plugin_string_to_address (void *cls, |
1539 | const char *addr, | 1514 | const char *addr, |
1540 | uint16_t addrlen, | 1515 | uint16_t addrlen, |
1541 | void **buf, size_t *added) | 1516 | void **buf, |
1517 | size_t *added) | ||
1542 | { | 1518 | { |
1543 | struct UnixAddress *ua; | 1519 | struct UnixAddress *ua; |
1544 | char *address; | 1520 | char *address; |
@@ -1587,7 +1563,7 @@ unix_plugin_string_to_address (void *cls, | |||
1587 | } | 1563 | } |
1588 | address[0] = '\0'; | 1564 | address[0] = '\0'; |
1589 | address++; | 1565 | address++; |
1590 | if (0 != strcmp(plugin, PLUGIN_NAME)) | 1566 | if (0 != strcmp (plugin, PLUGIN_NAME)) |
1591 | { | 1567 | { |
1592 | GNUNET_break (0); | 1568 | GNUNET_break (0); |
1593 | GNUNET_free (plugin); | 1569 | GNUNET_free (plugin); |
@@ -1624,9 +1600,11 @@ address_notification (void *cls) | |||
1624 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | 1600 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; |
1625 | ua = GNUNET_malloc (len); | 1601 | ua = GNUNET_malloc (len); |
1626 | ua->options = htonl (plugin->myoptions); | 1602 | ua->options = htonl (plugin->myoptions); |
1627 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | 1603 | ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); |
1628 | unix_path = (char *) &ua[1]; | 1604 | unix_path = (char *) &ua[1]; |
1629 | GNUNET_memcpy (unix_path, plugin->unix_socket_path, strlen (plugin->unix_socket_path) + 1); | 1605 | GNUNET_memcpy (unix_path, |
1606 | plugin->unix_socket_path, | ||
1607 | strlen (plugin->unix_socket_path) + 1); | ||
1630 | 1608 | ||
1631 | plugin->address_update_task = NULL; | 1609 | plugin->address_update_task = NULL; |
1632 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1610 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
@@ -1634,9 +1612,7 @@ address_notification (void *cls) | |||
1634 | ua, | 1612 | ua, |
1635 | len, | 1613 | len, |
1636 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1614 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1637 | plugin->env->notify_address (plugin->env->cls, | 1615 | plugin->env->notify_address (plugin->env->cls, GNUNET_YES, address); |
1638 | GNUNET_YES, | ||
1639 | address); | ||
1640 | GNUNET_free (ua); | 1616 | GNUNET_free (ua); |
1641 | GNUNET_free (address); | 1617 | GNUNET_free (address); |
1642 | } | 1618 | } |
@@ -1652,8 +1628,8 @@ address_notification (void *cls) | |||
1652 | */ | 1628 | */ |
1653 | static int | 1629 | static int |
1654 | get_session_delete_it (void *cls, | 1630 | get_session_delete_it (void *cls, |
1655 | const struct GNUNET_PeerIdentity *key, | 1631 | const struct GNUNET_PeerIdentity *key, |
1656 | void *value) | 1632 | void *value) |
1657 | { | 1633 | { |
1658 | struct Plugin *plugin = cls; | 1634 | struct Plugin *plugin = cls; |
1659 | struct GNUNET_ATS_Session *session = value; | 1635 | struct GNUNET_ATS_Session *session = value; |
@@ -1677,8 +1653,9 @@ unix_plugin_peer_disconnect (void *cls, | |||
1677 | struct Plugin *plugin = cls; | 1653 | struct Plugin *plugin = cls; |
1678 | 1654 | ||
1679 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, | 1655 | GNUNET_CONTAINER_multipeermap_get_multiple (plugin->session_map, |
1680 | target, | 1656 | target, |
1681 | &get_session_delete_it, plugin); | 1657 | &get_session_delete_it, |
1658 | plugin); | ||
1682 | } | 1659 | } |
1683 | 1660 | ||
1684 | 1661 | ||
@@ -1699,12 +1676,8 @@ send_session_info_iter (void *cls, | |||
1699 | struct Plugin *plugin = cls; | 1676 | struct Plugin *plugin = cls; |
1700 | struct GNUNET_ATS_Session *session = value; | 1677 | struct GNUNET_ATS_Session *session = value; |
1701 | 1678 | ||
1702 | notify_session_monitor (plugin, | 1679 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_INIT); |
1703 | session, | 1680 | notify_session_monitor (plugin, session, GNUNET_TRANSPORT_SS_UP); |
1704 | GNUNET_TRANSPORT_SS_INIT); | ||
1705 | notify_session_monitor (plugin, | ||
1706 | session, | ||
1707 | GNUNET_TRANSPORT_SS_UP); | ||
1708 | return GNUNET_OK; | 1681 | return GNUNET_OK; |
1709 | } | 1682 | } |
1710 | 1683 | ||
@@ -1786,9 +1759,10 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1786 | 1759 | ||
1787 | /* Initialize my flags */ | 1760 | /* Initialize my flags */ |
1788 | #ifdef LINUX | 1761 | #ifdef LINUX |
1789 | plugin->is_abstract = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 1762 | plugin->is_abstract = |
1790 | "testing", | 1763 | GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, |
1791 | "USE_ABSTRACT_SOCKETS"); | 1764 | "testing", |
1765 | "USE_ABSTRACT_SOCKETS"); | ||
1792 | #endif | 1766 | #endif |
1793 | plugin->myoptions = UNIX_OPTIONS_NONE; | 1767 | plugin->myoptions = UNIX_OPTIONS_NONE; |
1794 | if (GNUNET_YES == plugin->is_abstract) | 1768 | if (GNUNET_YES == plugin->is_abstract) |
@@ -1812,16 +1786,15 @@ libgnunet_plugin_transport_unix_init (void *cls) | |||
1812 | sockets_created = unix_transport_server_start (plugin); | 1786 | sockets_created = unix_transport_server_start (plugin); |
1813 | if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) | 1787 | if ((0 == sockets_created) || (GNUNET_SYSERR == sockets_created)) |
1814 | { | 1788 | { |
1815 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1789 | LOG (GNUNET_ERROR_TYPE_WARNING, _ ("Failed to open UNIX listen socket\n")); |
1816 | _("Failed to open UNIX listen socket\n")); | ||
1817 | GNUNET_free (api); | 1790 | GNUNET_free (api); |
1818 | GNUNET_free (plugin->unix_socket_path); | 1791 | GNUNET_free (plugin->unix_socket_path); |
1819 | GNUNET_free (plugin); | 1792 | GNUNET_free (plugin); |
1820 | return NULL; | 1793 | return NULL; |
1821 | } | 1794 | } |
1822 | plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1795 | plugin->session_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1823 | plugin->address_update_task = GNUNET_SCHEDULER_add_now (&address_notification, | 1796 | plugin->address_update_task = |
1824 | plugin); | 1797 | GNUNET_SCHEDULER_add_now (&address_notification, plugin); |
1825 | return api; | 1798 | return api; |
1826 | } | 1799 | } |
1827 | 1800 | ||
@@ -1838,7 +1811,7 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1838 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 1811 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
1839 | struct Plugin *plugin = api->cls; | 1812 | struct Plugin *plugin = api->cls; |
1840 | struct GNUNET_HELLO_Address *address; | 1813 | struct GNUNET_HELLO_Address *address; |
1841 | struct UNIXMessageWrapper * msgw; | 1814 | struct UNIXMessageWrapper *msgw; |
1842 | struct UnixAddress *ua; | 1815 | struct UnixAddress *ua; |
1843 | size_t len; | 1816 | size_t len; |
1844 | struct GNUNET_ATS_Session *session; | 1817 | struct GNUNET_ATS_Session *session; |
@@ -1851,26 +1824,23 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1851 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; | 1824 | len = sizeof (struct UnixAddress) + strlen (plugin->unix_socket_path) + 1; |
1852 | ua = GNUNET_malloc (len); | 1825 | ua = GNUNET_malloc (len); |
1853 | ua->options = htonl (plugin->myoptions); | 1826 | ua->options = htonl (plugin->myoptions); |
1854 | ua->addrlen = htonl(strlen (plugin->unix_socket_path) + 1); | 1827 | ua->addrlen = htonl (strlen (plugin->unix_socket_path) + 1); |
1855 | GNUNET_memcpy (&ua[1], | 1828 | GNUNET_memcpy (&ua[1], |
1856 | plugin->unix_socket_path, | 1829 | plugin->unix_socket_path, |
1857 | strlen (plugin->unix_socket_path) + 1); | 1830 | strlen (plugin->unix_socket_path) + 1); |
1858 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1831 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1859 | PLUGIN_NAME, | 1832 | PLUGIN_NAME, |
1860 | ua, len, | 1833 | ua, |
1834 | len, | ||
1861 | GNUNET_HELLO_ADDRESS_INFO_NONE); | 1835 | GNUNET_HELLO_ADDRESS_INFO_NONE); |
1862 | plugin->env->notify_address (plugin->env->cls, | 1836 | plugin->env->notify_address (plugin->env->cls, GNUNET_NO, address); |
1863 | GNUNET_NO, | ||
1864 | address); | ||
1865 | 1837 | ||
1866 | GNUNET_free (address); | 1838 | GNUNET_free (address); |
1867 | GNUNET_free (ua); | 1839 | GNUNET_free (ua); |
1868 | 1840 | ||
1869 | while (NULL != (msgw = plugin->msg_head)) | 1841 | while (NULL != (msgw = plugin->msg_head)) |
1870 | { | 1842 | { |
1871 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, | 1843 | GNUNET_CONTAINER_DLL_remove (plugin->msg_head, plugin->msg_tail, msgw); |
1872 | plugin->msg_tail, | ||
1873 | msgw); | ||
1874 | session = msgw->session; | 1844 | session = msgw->session; |
1875 | session->msgs_in_queue--; | 1845 | session->msgs_in_queue--; |
1876 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); | 1846 | GNUNET_assert (session->bytes_in_queue >= msgw->msgsize); |
@@ -1881,7 +1851,8 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1881 | msgw->cont (msgw->cont_cls, | 1851 | msgw->cont (msgw->cont_cls, |
1882 | &msgw->session->target, | 1852 | &msgw->session->target, |
1883 | GNUNET_SYSERR, | 1853 | GNUNET_SYSERR, |
1884 | msgw->payload, 0); | 1854 | msgw->payload, |
1855 | 0); | ||
1885 | GNUNET_free (msgw->msg); | 1856 | GNUNET_free (msgw->msg); |
1886 | GNUNET_free (msgw); | 1857 | GNUNET_free (msgw); |
1887 | } | 1858 | } |
@@ -1908,7 +1879,7 @@ libgnunet_plugin_transport_unix_done (void *cls) | |||
1908 | plugin->unix_sock.desc = NULL; | 1879 | plugin->unix_sock.desc = NULL; |
1909 | } | 1880 | } |
1910 | GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, | 1881 | GNUNET_CONTAINER_multipeermap_iterate (plugin->session_map, |
1911 | &get_session_delete_it, | 1882 | &get_session_delete_it, |
1912 | plugin); | 1883 | plugin); |
1913 | GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); | 1884 | GNUNET_CONTAINER_multipeermap_destroy (plugin->session_map); |
1914 | GNUNET_break (0 == plugin->bytes_in_queue); | 1885 | GNUNET_break (0 == plugin->bytes_in_queue); |
diff --git a/src/transport/tcp_connection_legacy.c b/src/transport/tcp_connection_legacy.c index cfb088361..999e8827a 100644 --- a/src/transport/tcp_connection_legacy.c +++ b/src/transport/tcp_connection_legacy.c | |||
@@ -41,11 +41,12 @@ | |||
41 | * is this value divided by the number of address families. | 41 | * is this value divided by the number of address families. |
42 | * Default is 5s. | 42 | * Default is 5s. |
43 | */ | 43 | */ |
44 | #define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 44 | #define CONNECT_RETRY_TIMEOUT \ |
45 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
45 | 46 | ||
46 | 47 | ||
47 | 48 | #define LOG_STRERROR(kind, syscall) \ | |
48 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall) | 49 | GNUNET_log_from_strerror (kind, "util-connection", syscall) |
49 | 50 | ||
50 | 51 | ||
51 | /** | 52 | /** |
@@ -78,14 +79,13 @@ struct GNUNET_CONNECTION_TransmitHandle | |||
78 | /** | 79 | /** |
79 | * Task called on timeout. | 80 | * Task called on timeout. |
80 | */ | 81 | */ |
81 | struct GNUNET_SCHEDULER_Task * timeout_task; | 82 | struct GNUNET_SCHEDULER_Task *timeout_task; |
82 | 83 | ||
83 | /** | 84 | /** |
84 | * At what number of bytes available in the | 85 | * At what number of bytes available in the |
85 | * write buffer should the notify method be called? | 86 | * write buffer should the notify method be called? |
86 | */ | 87 | */ |
87 | size_t notify_size; | 88 | size_t notify_size; |
88 | |||
89 | }; | 89 | }; |
90 | 90 | ||
91 | 91 | ||
@@ -129,7 +129,7 @@ struct AddressProbe | |||
129 | /** | 129 | /** |
130 | * Task waiting for the connection to finish connecting. | 130 | * Task waiting for the connection to finish connecting. |
131 | */ | 131 | */ |
132 | struct GNUNET_SCHEDULER_Task * task; | 132 | struct GNUNET_SCHEDULER_Task *task; |
133 | }; | 133 | }; |
134 | 134 | ||
135 | 135 | ||
@@ -263,7 +263,6 @@ struct GNUNET_CONNECTION_Handle | |||
263 | * Handle to subsequent connection after proxy handshake completes, | 263 | * Handle to subsequent connection after proxy handshake completes, |
264 | */ | 264 | */ |
265 | struct GNUNET_CONNECTION_Handle *proxy_handshake; | 265 | struct GNUNET_CONNECTION_Handle *proxy_handshake; |
266 | |||
267 | }; | 266 | }; |
268 | 267 | ||
269 | 268 | ||
@@ -357,9 +356,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
357 | 356 | ||
358 | addrlen = sizeof (addr); | 357 | addrlen = sizeof (addr); |
359 | sock = | 358 | sock = |
360 | GNUNET_NETWORK_socket_accept (lsock, | 359 | GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); |
361 | (struct sockaddr *) &addr, | ||
362 | &addrlen); | ||
363 | if (NULL == sock) | 360 | if (NULL == sock) |
364 | { | 361 | { |
365 | if (EAGAIN != errno) | 362 | if (EAGAIN != errno) |
@@ -375,8 +372,7 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
375 | 372 | ||
376 | sa = (struct sockaddr *) addr; | 373 | sa = (struct sockaddr *) addr; |
377 | v6 = (struct sockaddr_in6 *) addr; | 374 | v6 = (struct sockaddr_in6 *) addr; |
378 | if ( (AF_INET6 == sa->sa_family) && | 375 | if ((AF_INET6 == sa->sa_family) && (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr))) |
379 | (IN6_IS_ADDR_V4MAPPED (&v6->sin6_addr)) ) | ||
380 | { | 376 | { |
381 | /* convert to V4 address */ | 377 | /* convert to V4 address */ |
382 | v4 = GNUNET_new (struct sockaddr_in); | 378 | v4 = GNUNET_new (struct sockaddr_in); |
@@ -386,9 +382,9 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
386 | v4->sin_len = (u_char) sizeof (struct sockaddr_in); | 382 | v4->sin_len = (u_char) sizeof (struct sockaddr_in); |
387 | #endif | 383 | #endif |
388 | GNUNET_memcpy (&v4->sin_addr, | 384 | GNUNET_memcpy (&v4->sin_addr, |
389 | &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - | 385 | &((char *) &v6->sin6_addr)[sizeof (struct in6_addr) - |
390 | sizeof (struct in_addr)], | 386 | sizeof (struct in_addr)], |
391 | sizeof (struct in_addr)); | 387 | sizeof (struct in_addr)); |
392 | v4->sin_port = v6->sin6_port; | 388 | v4->sin_port = v6->sin6_port; |
393 | uaddr = v4; | 389 | uaddr = v4; |
394 | addrlen = sizeof (struct sockaddr_in); | 390 | addrlen = sizeof (struct sockaddr_in); |
@@ -403,21 +399,18 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
403 | { | 399 | { |
404 | #if HAVE_GETPEEREID | 400 | #if HAVE_GETPEEREID |
405 | /* most BSDs */ | 401 | /* most BSDs */ |
406 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), | 402 | if (0 == getpeereid (GNUNET_NETWORK_get_fd (sock), &gc.uid, &gc.gid)) |
407 | &gc.uid, | ||
408 | &gc.gid)) | ||
409 | gcp = &gc; | 403 | gcp = &gc; |
410 | #else | 404 | #else |
411 | #ifdef SO_PEERCRED | 405 | #ifdef SO_PEERCRED |
412 | /* largely traditional GNU/Linux */ | 406 | /* largely traditional GNU/Linux */ |
413 | olen = sizeof (uc); | 407 | olen = sizeof (uc); |
414 | if ( (0 == | 408 | if ((0 == getsockopt (GNUNET_NETWORK_get_fd (sock), |
415 | getsockopt (GNUNET_NETWORK_get_fd (sock), | 409 | SOL_SOCKET, |
416 | SOL_SOCKET, | 410 | SO_PEERCRED, |
417 | SO_PEERCRED, | 411 | &uc, |
418 | &uc, | 412 | &olen)) && |
419 | &olen)) && | 413 | (olen == sizeof (uc))) |
420 | (olen == sizeof (uc)) ) | ||
421 | { | 414 | { |
422 | gc.uid = uc.uid; | 415 | gc.uid = uc.uid; |
423 | gc.gid = uc.gid; | 416 | gc.gid = uc.gid; |
@@ -441,20 +434,15 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
441 | #endif | 434 | #endif |
442 | } | 435 | } |
443 | 436 | ||
444 | if ( (NULL != access_cb) && | 437 | if ((NULL != access_cb) && |
445 | (GNUNET_YES != (aret = access_cb (access_cb_cls, | 438 | (GNUNET_YES != (aret = access_cb (access_cb_cls, gcp, uaddr, addrlen)))) |
446 | gcp, | ||
447 | uaddr, | ||
448 | addrlen))) ) | ||
449 | { | 439 | { |
450 | if (GNUNET_NO == aret) | 440 | if (GNUNET_NO == aret) |
451 | LOG (GNUNET_ERROR_TYPE_INFO, | 441 | LOG (GNUNET_ERROR_TYPE_INFO, |
452 | _("Access denied to `%s'\n"), | 442 | _ ("Access denied to `%s'\n"), |
453 | GNUNET_a2s (uaddr, | 443 | GNUNET_a2s (uaddr, addrlen)); |
454 | addrlen)); | ||
455 | GNUNET_break (GNUNET_OK == | 444 | GNUNET_break (GNUNET_OK == |
456 | GNUNET_NETWORK_socket_shutdown (sock, | 445 | GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); |
457 | SHUT_RDWR)); | ||
458 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); | 446 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); |
459 | GNUNET_free (uaddr); | 447 | GNUNET_free (uaddr); |
460 | return NULL; | 448 | return NULL; |
@@ -466,9 +454,8 @@ GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | |||
466 | connection->addrlen = addrlen; | 454 | connection->addrlen = addrlen; |
467 | connection->sock = sock; | 455 | connection->sock = sock; |
468 | LOG (GNUNET_ERROR_TYPE_INFO, | 456 | LOG (GNUNET_ERROR_TYPE_INFO, |
469 | _("Accepting connection from `%s': %p\n"), | 457 | _ ("Accepting connection from `%s': %p\n"), |
470 | GNUNET_a2s (uaddr, | 458 | GNUNET_a2s (uaddr, addrlen), |
471 | addrlen), | ||
472 | connection); | 459 | connection); |
473 | return connection; | 460 | return connection; |
474 | } | 461 | } |
@@ -503,14 +490,13 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, | |||
503 | * @param errcode error code to send | 490 | * @param errcode error code to send |
504 | */ | 491 | */ |
505 | static void | 492 | static void |
506 | signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, | 493 | signal_receive_error (struct GNUNET_CONNECTION_Handle *connection, int errcode) |
507 | int errcode) | ||
508 | { | 494 | { |
509 | GNUNET_CONNECTION_Receiver receiver; | 495 | GNUNET_CONNECTION_Receiver receiver; |
510 | 496 | ||
511 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 497 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
512 | "Receive encounters error (%s), connection closed (%p)\n", | 498 | "Receive encounters error (%s), connection closed (%p)\n", |
513 | STRERROR (errcode), | 499 | strerror (errcode), |
514 | connection); | 500 | connection); |
515 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 501 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
516 | connection->receiver = NULL; | 502 | connection->receiver = NULL; |
@@ -549,21 +535,18 @@ signal_receive_timeout (struct GNUNET_CONNECTION_Handle *connection) | |||
549 | * @param ecode error code (errno) | 535 | * @param ecode error code (errno) |
550 | */ | 536 | */ |
551 | static void | 537 | static void |
552 | signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | 538 | signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, int ecode) |
553 | int ecode) | ||
554 | { | 539 | { |
555 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 540 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
556 | 541 | ||
557 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 542 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
558 | "Transmission encounterd error (%s), connection closed (%p)\n", | 543 | "Transmission encounterd error (%s), connection closed (%p)\n", |
559 | STRERROR (ecode), | 544 | strerror (ecode), |
560 | connection); | 545 | connection); |
561 | if (NULL != connection->sock) | 546 | if (NULL != connection->sock) |
562 | { | 547 | { |
563 | (void) GNUNET_NETWORK_socket_shutdown (connection->sock, | 548 | (void) GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR); |
564 | SHUT_RDWR); | 549 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); |
565 | GNUNET_break (GNUNET_OK == | ||
566 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
567 | connection->sock = NULL; | 550 | connection->sock = NULL; |
568 | GNUNET_assert (NULL == connection->write_task); | 551 | GNUNET_assert (NULL == connection->write_task); |
569 | } | 552 | } |
@@ -576,12 +559,10 @@ signal_transmit_error (struct GNUNET_CONNECTION_Handle *connection, | |||
576 | return; | 559 | return; |
577 | } | 560 | } |
578 | if (NULL == connection->nth.notify_ready) | 561 | if (NULL == connection->nth.notify_ready) |
579 | return; /* nobody to tell about it */ | 562 | return; /* nobody to tell about it */ |
580 | notify = connection->nth.notify_ready; | 563 | notify = connection->nth.notify_ready; |
581 | connection->nth.notify_ready = NULL; | 564 | connection->nth.notify_ready = NULL; |
582 | notify (connection->nth.notify_ready_cls, | 565 | notify (connection->nth.notify_ready_cls, 0, NULL); |
583 | 0, | ||
584 | NULL); | ||
585 | } | 566 | } |
586 | 567 | ||
587 | 568 | ||
@@ -597,7 +578,7 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
597 | LOG (GNUNET_ERROR_TYPE_INFO, | 578 | LOG (GNUNET_ERROR_TYPE_INFO, |
598 | "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", | 579 | "Failed to establish TCP connection to `%s:%u', no further addresses to try.\n", |
599 | connection->hostname, | 580 | connection->hostname, |
600 | connection->port); | 581 | connection->port); |
601 | GNUNET_break (NULL == connection->ap_head); | 582 | GNUNET_break (NULL == connection->ap_head); |
602 | GNUNET_break (NULL == connection->ap_tail); | 583 | GNUNET_break (NULL == connection->ap_tail); |
603 | GNUNET_break (GNUNET_NO == connection->dns_active); | 584 | GNUNET_break (GNUNET_NO == connection->dns_active); |
@@ -608,15 +589,13 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
608 | /* signal errors for jobs that used to wait on the connection */ | 589 | /* signal errors for jobs that used to wait on the connection */ |
609 | connection->destroy_later = 1; | 590 | connection->destroy_later = 1; |
610 | if (NULL != connection->receiver) | 591 | if (NULL != connection->receiver) |
611 | signal_receive_error (connection, | 592 | signal_receive_error (connection, ECONNREFUSED); |
612 | ECONNREFUSED); | ||
613 | if (NULL != connection->nth.notify_ready) | 593 | if (NULL != connection->nth.notify_ready) |
614 | { | 594 | { |
615 | GNUNET_assert (NULL != connection->nth.timeout_task); | 595 | GNUNET_assert (NULL != connection->nth.timeout_task); |
616 | GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); | 596 | GNUNET_SCHEDULER_cancel (connection->nth.timeout_task); |
617 | connection->nth.timeout_task = NULL; | 597 | connection->nth.timeout_task = NULL; |
618 | signal_transmit_error (connection, | 598 | signal_transmit_error (connection, ECONNREFUSED); |
619 | ECONNREFUSED); | ||
620 | } | 599 | } |
621 | if (-1 == connection->destroy_later) | 600 | if (-1 == connection->destroy_later) |
622 | { | 601 | { |
@@ -658,21 +637,21 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
658 | { | 637 | { |
659 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 638 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
660 | "Connection to `%s' succeeded! (%p)\n", | 639 | "Connection to `%s' succeeded! (%p)\n", |
661 | GNUNET_a2s (connection->addr, | 640 | GNUNET_a2s (connection->addr, connection->addrlen), |
662 | connection->addrlen), | ||
663 | connection); | 641 | connection); |
664 | /* trigger jobs that waited for the connection */ | 642 | /* trigger jobs that waited for the connection */ |
665 | if (NULL != connection->receiver) | 643 | if (NULL != connection->receiver) |
666 | { | 644 | { |
667 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 645 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
668 | "Connection succeeded, starting with receiving data (%p)\n", | 646 | "Connection succeeded, starting with receiving data (%p)\n", |
669 | connection); | 647 | connection); |
670 | GNUNET_assert (NULL == connection->read_task); | 648 | GNUNET_assert (NULL == connection->read_task); |
671 | connection->read_task = | 649 | connection->read_task = |
672 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 650 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( |
673 | (connection->receive_timeout), | 651 | connection->receive_timeout), |
674 | connection->sock, | 652 | connection->sock, |
675 | &receive_ready, connection); | 653 | &receive_ready, |
654 | connection); | ||
676 | } | 655 | } |
677 | if (NULL != connection->nth.notify_ready) | 656 | if (NULL != connection->nth.notify_ready) |
678 | { | 657 | { |
@@ -684,9 +663,11 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *connection) | |||
684 | connection->nth.timeout_task = NULL; | 663 | connection->nth.timeout_task = NULL; |
685 | GNUNET_assert (connection->write_task == NULL); | 664 | GNUNET_assert (connection->write_task == NULL); |
686 | connection->write_task = | 665 | connection->write_task = |
687 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 666 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( |
688 | (connection->nth.transmit_timeout), connection->sock, | 667 | connection->nth.transmit_timeout), |
689 | &transmit_ready, connection); | 668 | connection->sock, |
669 | &transmit_ready, | ||
670 | connection); | ||
690 | } | 671 | } |
691 | } | 672 | } |
692 | 673 | ||
@@ -708,28 +689,24 @@ connect_probe_continuation (void *cls) | |||
708 | socklen_t len; | 689 | socklen_t len; |
709 | 690 | ||
710 | GNUNET_assert (NULL != ap->sock); | 691 | GNUNET_assert (NULL != ap->sock); |
711 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, | 692 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, ap); |
712 | connection->ap_tail, | ||
713 | ap); | ||
714 | len = sizeof (error); | 693 | len = sizeof (error); |
715 | errno = 0; | 694 | errno = 0; |
716 | error = 0; | 695 | error = 0; |
717 | tc = GNUNET_SCHEDULER_get_task_context (); | 696 | tc = GNUNET_SCHEDULER_get_task_context (); |
718 | if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || | 697 | if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || |
719 | (GNUNET_OK != | 698 | (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock, |
720 | GNUNET_NETWORK_socket_getsockopt (ap->sock, | 699 | SOL_SOCKET, |
721 | SOL_SOCKET, | 700 | SO_ERROR, |
722 | SO_ERROR, | 701 | &error, |
723 | &error, | 702 | &len)) || |
724 | &len)) || | 703 | (0 != error)) |
725 | (0 != error) ) | ||
726 | { | 704 | { |
727 | GNUNET_break (GNUNET_OK == | 705 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); |
728 | GNUNET_NETWORK_socket_close (ap->sock)); | ||
729 | GNUNET_free (ap); | 706 | GNUNET_free (ap); |
730 | if ( (NULL == connection->ap_head) && | 707 | if ((NULL == connection->ap_head) && |
731 | (GNUNET_NO == connection->dns_active) && | 708 | (GNUNET_NO == connection->dns_active) && |
732 | (NULL == connection->proxy_handshake) ) | 709 | (NULL == connection->proxy_handshake)) |
733 | connect_fail_continuation (connection); | 710 | connect_fail_continuation (connection); |
734 | return; | 711 | return; |
735 | } | 712 | } |
@@ -745,9 +722,7 @@ connect_probe_continuation (void *cls) | |||
745 | { | 722 | { |
746 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 723 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
747 | GNUNET_SCHEDULER_cancel (pos->task); | 724 | GNUNET_SCHEDULER_cancel (pos->task); |
748 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, | 725 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); |
749 | connection->ap_tail, | ||
750 | pos); | ||
751 | GNUNET_free (pos); | 726 | GNUNET_free (pos); |
752 | } | 727 | } |
753 | connect_success_continuation (connection); | 728 | connect_success_continuation (connection); |
@@ -774,14 +749,13 @@ try_connect_using_address (void *cls, | |||
774 | if (NULL == addr) | 749 | if (NULL == addr) |
775 | { | 750 | { |
776 | connection->dns_active = NULL; | 751 | connection->dns_active = NULL; |
777 | if ((NULL == connection->ap_head) && | 752 | if ((NULL == connection->ap_head) && (NULL == connection->sock) && |
778 | (NULL == connection->sock) && | ||
779 | (NULL == connection->proxy_handshake)) | 753 | (NULL == connection->proxy_handshake)) |
780 | connect_fail_continuation (connection); | 754 | connect_fail_continuation (connection); |
781 | return; | 755 | return; |
782 | } | 756 | } |
783 | if (NULL != connection->sock) | 757 | if (NULL != connection->sock) |
784 | return; /* already connected */ | 758 | return; /* already connected */ |
785 | GNUNET_assert (NULL == connection->addr); | 759 | GNUNET_assert (NULL == connection->addr); |
786 | /* try to connect */ | 760 | /* try to connect */ |
787 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 761 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -807,23 +781,20 @@ try_connect_using_address (void *cls, | |||
807 | default: | 781 | default: |
808 | GNUNET_break (0); | 782 | GNUNET_break (0); |
809 | GNUNET_free (ap); | 783 | GNUNET_free (ap); |
810 | return; /* not supported by us */ | 784 | return; /* not supported by us */ |
811 | } | 785 | } |
812 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, | 786 | ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); |
813 | SOCK_STREAM, 0); | ||
814 | if (NULL == ap->sock) | 787 | if (NULL == ap->sock) |
815 | { | 788 | { |
816 | GNUNET_free (ap); | 789 | GNUNET_free (ap); |
817 | return; /* not supported by OS */ | 790 | return; /* not supported by OS */ |
818 | } | 791 | } |
819 | LOG (GNUNET_ERROR_TYPE_INFO, | 792 | LOG (GNUNET_ERROR_TYPE_INFO, |
820 | "Trying to connect to `%s' (%p)\n", | 793 | "Trying to connect to `%s' (%p)\n", |
821 | GNUNET_a2s (ap->addr, ap->addrlen), | 794 | GNUNET_a2s (ap->addr, ap->addrlen), |
822 | connection); | 795 | connection); |
823 | if ((GNUNET_OK != | 796 | if ((GNUNET_OK != |
824 | GNUNET_NETWORK_socket_connect (ap->sock, | 797 | GNUNET_NETWORK_socket_connect (ap->sock, ap->addr, ap->addrlen)) && |
825 | ap->addr, | ||
826 | ap->addrlen)) && | ||
827 | (EINPROGRESS != errno)) | 798 | (EINPROGRESS != errno)) |
828 | { | 799 | { |
829 | /* maybe refused / unsupported address, try next */ | 800 | /* maybe refused / unsupported address, try next */ |
@@ -836,14 +807,16 @@ try_connect_using_address (void *cls, | |||
836 | delay = CONNECT_RETRY_TIMEOUT; | 807 | delay = CONNECT_RETRY_TIMEOUT; |
837 | if (NULL != connection->nth.notify_ready) | 808 | if (NULL != connection->nth.notify_ready) |
838 | delay = GNUNET_TIME_relative_min (delay, | 809 | delay = GNUNET_TIME_relative_min (delay, |
839 | GNUNET_TIME_absolute_get_remaining (connection->nth.transmit_timeout)); | 810 | GNUNET_TIME_absolute_get_remaining ( |
811 | connection->nth.transmit_timeout)); | ||
840 | if (NULL != connection->receiver) | 812 | if (NULL != connection->receiver) |
841 | delay = GNUNET_TIME_relative_min (delay, | 813 | delay = GNUNET_TIME_relative_min (delay, |
842 | GNUNET_TIME_absolute_get_remaining (connection->receive_timeout)); | 814 | GNUNET_TIME_absolute_get_remaining ( |
815 | connection->receive_timeout)); | ||
843 | ap->task = GNUNET_SCHEDULER_add_write_net (delay, | 816 | ap->task = GNUNET_SCHEDULER_add_write_net (delay, |
844 | ap->sock, | 817 | ap->sock, |
845 | &connect_probe_continuation, | 818 | &connect_probe_continuation, |
846 | ap); | 819 | ap); |
847 | } | 820 | } |
848 | 821 | ||
849 | 822 | ||
@@ -858,25 +831,25 @@ try_connect_using_address (void *cls, | |||
858 | * @return the connection handle | 831 | * @return the connection handle |
859 | */ | 832 | */ |
860 | struct GNUNET_CONNECTION_Handle * | 833 | struct GNUNET_CONNECTION_Handle * |
861 | GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, | 834 | GNUNET_CONNECTION_create_from_connect ( |
862 | const char *hostname, | 835 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
863 | uint16_t port) | 836 | const char *hostname, |
837 | uint16_t port) | ||
864 | { | 838 | { |
865 | struct GNUNET_CONNECTION_Handle *connection; | 839 | struct GNUNET_CONNECTION_Handle *connection; |
866 | 840 | ||
867 | GNUNET_assert (0 < strlen (hostname)); /* sanity check */ | 841 | GNUNET_assert (0 < strlen (hostname)); /* sanity check */ |
868 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); | 842 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); |
869 | connection->cfg = cfg; | 843 | connection->cfg = cfg; |
870 | connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; | 844 | connection->write_buffer_size = GNUNET_MIN_MESSAGE_SIZE; |
871 | connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); | 845 | connection->write_buffer = GNUNET_malloc (connection->write_buffer_size); |
872 | connection->port = port; | 846 | connection->port = port; |
873 | connection->hostname = GNUNET_strdup (hostname); | 847 | connection->hostname = GNUNET_strdup (hostname); |
874 | connection->dns_active = | 848 | connection->dns_active = GNUNET_RESOLVER_ip_get (connection->hostname, |
875 | GNUNET_RESOLVER_ip_get (connection->hostname, | 849 | AF_UNSPEC, |
876 | AF_UNSPEC, | 850 | CONNECT_RETRY_TIMEOUT, |
877 | CONNECT_RETRY_TIMEOUT, | 851 | &try_connect_using_address, |
878 | &try_connect_using_address, | 852 | connection); |
879 | connection); | ||
880 | return connection; | 853 | return connection; |
881 | } | 854 | } |
882 | 855 | ||
@@ -891,14 +864,15 @@ GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | |||
891 | * @return the connection handle, NULL on systems without UNIX support | 864 | * @return the connection handle, NULL on systems without UNIX support |
892 | */ | 865 | */ |
893 | struct GNUNET_CONNECTION_Handle * | 866 | struct GNUNET_CONNECTION_Handle * |
894 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURATION_Handle *cfg, | 867 | GNUNET_CONNECTION_create_from_connect_to_unixpath ( |
895 | const char *unixpath) | 868 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
869 | const char *unixpath) | ||
896 | { | 870 | { |
897 | #ifdef AF_UNIX | 871 | #ifdef AF_UNIX |
898 | struct GNUNET_CONNECTION_Handle *connection; | 872 | struct GNUNET_CONNECTION_Handle *connection; |
899 | struct sockaddr_un *un; | 873 | struct sockaddr_un *un; |
900 | 874 | ||
901 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 875 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
902 | un = GNUNET_new (struct sockaddr_un); | 876 | un = GNUNET_new (struct sockaddr_un); |
903 | un->sun_family = AF_UNIX; | 877 | un->sun_family = AF_UNIX; |
904 | GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); | 878 | GNUNET_strlcpy (un->sun_path, unixpath, sizeof (un->sun_path)); |
@@ -907,7 +881,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
907 | int abstract; | 881 | int abstract; |
908 | 882 | ||
909 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 883 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
910 | "TESTING", | 884 | "TESTING", |
911 | "USE_ABSTRACT_SOCKETS"); | 885 | "USE_ABSTRACT_SOCKETS"); |
912 | if (GNUNET_YES == abstract) | 886 | if (GNUNET_YES == abstract) |
913 | un->sun_path[0] = '\0'; | 887 | un->sun_path[0] = '\0'; |
@@ -924,9 +898,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
924 | connection->hostname = NULL; | 898 | connection->hostname = NULL; |
925 | connection->addr = (struct sockaddr *) un; | 899 | connection->addr = (struct sockaddr *) un; |
926 | connection->addrlen = sizeof (struct sockaddr_un); | 900 | connection->addrlen = sizeof (struct sockaddr_un); |
927 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, | 901 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
928 | SOCK_STREAM, | ||
929 | 0); | ||
930 | if (NULL == connection->sock) | 902 | if (NULL == connection->sock) |
931 | { | 903 | { |
932 | GNUNET_free (connection->addr); | 904 | GNUNET_free (connection->addr); |
@@ -934,15 +906,13 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct GNUNET_CONFIGURA | |||
934 | GNUNET_free (connection); | 906 | GNUNET_free (connection); |
935 | return NULL; | 907 | return NULL; |
936 | } | 908 | } |
937 | if ( (GNUNET_OK != | 909 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (connection->sock, |
938 | GNUNET_NETWORK_socket_connect (connection->sock, | 910 | connection->addr, |
939 | connection->addr, | 911 | connection->addrlen)) && |
940 | connection->addrlen)) && | 912 | (EINPROGRESS != errno)) |
941 | (EINPROGRESS != errno) ) | ||
942 | { | 913 | { |
943 | /* Just return; we expect everything to work eventually so don't fail HARD */ | 914 | /* Just return; we expect everything to work eventually so don't fail HARD */ |
944 | GNUNET_break (GNUNET_OK == | 915 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (connection->sock)); |
945 | GNUNET_NETWORK_socket_close (connection->sock)); | ||
946 | connection->sock = NULL; | 916 | connection->sock = NULL; |
947 | return connection; | 917 | return connection; |
948 | } | 918 | } |
@@ -971,17 +941,14 @@ GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, | |||
971 | { | 941 | { |
972 | struct GNUNET_CONNECTION_Handle *connection; | 942 | struct GNUNET_CONNECTION_Handle *connection; |
973 | 943 | ||
974 | if ( (GNUNET_OK != | 944 | if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && |
975 | GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && | 945 | (EINPROGRESS != errno)) |
976 | (EINPROGRESS != errno) ) | ||
977 | { | 946 | { |
978 | /* maybe refused / unsupported address, try next */ | 947 | /* maybe refused / unsupported address, try next */ |
979 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, | 948 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "connect"); |
980 | "connect"); | ||
981 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 949 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
982 | "Attempt to connect to `%s' failed\n", | 950 | "Attempt to connect to `%s' failed\n", |
983 | GNUNET_a2s (serv_addr, | 951 | GNUNET_a2s (serv_addr, addrlen)); |
984 | addrlen)); | ||
985 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); | 952 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s)); |
986 | return NULL; | 953 | return NULL; |
987 | } | 954 | } |
@@ -1018,13 +985,10 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
1018 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); | 985 | s = GNUNET_NETWORK_socket_create (af_family, SOCK_STREAM, 0); |
1019 | if (NULL == s) | 986 | if (NULL == s) |
1020 | { | 987 | { |
1021 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 988 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, "socket"); |
1022 | "socket"); | ||
1023 | return NULL; | 989 | return NULL; |
1024 | } | 990 | } |
1025 | return GNUNET_CONNECTION_connect_socket (s, | 991 | return GNUNET_CONNECTION_connect_socket (s, serv_addr, addrlen); |
1026 | serv_addr, | ||
1027 | addrlen); | ||
1028 | } | 992 | } |
1029 | 993 | ||
1030 | 994 | ||
@@ -1039,12 +1003,10 @@ GNUNET_CONNECTION_create_from_sockaddr (int af_family, | |||
1039 | int | 1003 | int |
1040 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) | 1004 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection) |
1041 | { | 1005 | { |
1042 | if ((NULL != connection->ap_head) || | 1006 | if ((NULL != connection->ap_head) || (NULL != connection->dns_active) || |
1043 | (NULL != connection->dns_active) || | ||
1044 | (NULL != connection->proxy_handshake)) | 1007 | (NULL != connection->proxy_handshake)) |
1045 | return GNUNET_YES; /* still trying to connect */ | 1008 | return GNUNET_YES; /* still trying to connect */ |
1046 | if ( (0 != connection->destroy_later) || | 1009 | if ((0 != connection->destroy_later) || (NULL == connection->sock)) |
1047 | (NULL == connection->sock) ) | ||
1048 | return GNUNET_NO; | 1010 | return GNUNET_NO; |
1049 | return GNUNET_YES; | 1011 | return GNUNET_YES; |
1050 | } | 1012 | } |
@@ -1067,9 +1029,7 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1067 | connection->destroy_later = -1; | 1029 | connection->destroy_later = -1; |
1068 | return; | 1030 | return; |
1069 | } | 1031 | } |
1070 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1032 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Shutting down connection (%p)\n", connection); |
1071 | "Shutting down connection (%p)\n", | ||
1072 | connection); | ||
1073 | GNUNET_assert (NULL == connection->nth.notify_ready); | 1033 | GNUNET_assert (NULL == connection->nth.notify_ready); |
1074 | GNUNET_assert (NULL == connection->receiver); | 1034 | GNUNET_assert (NULL == connection->receiver); |
1075 | if (NULL != connection->write_task) | 1035 | if (NULL != connection->write_task) |
@@ -1098,27 +1058,21 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1098 | { | 1058 | { |
1099 | /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ | 1059 | /* GNUNET_CONNECTION_destroy (connection->proxy_handshake); */ |
1100 | connection->proxy_handshake->destroy_later = -1; | 1060 | connection->proxy_handshake->destroy_later = -1; |
1101 | connection->proxy_handshake = NULL; /* Not leaked ??? */ | 1061 | connection->proxy_handshake = NULL; /* Not leaked ??? */ |
1102 | } | 1062 | } |
1103 | while (NULL != (pos = connection->ap_head)) | 1063 | while (NULL != (pos = connection->ap_head)) |
1104 | { | 1064 | { |
1105 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); | 1065 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (pos->sock)); |
1106 | GNUNET_SCHEDULER_cancel (pos->task); | 1066 | GNUNET_SCHEDULER_cancel (pos->task); |
1107 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, | 1067 | GNUNET_CONTAINER_DLL_remove (connection->ap_head, connection->ap_tail, pos); |
1108 | connection->ap_tail, | ||
1109 | pos); | ||
1110 | GNUNET_free (pos); | 1068 | GNUNET_free (pos); |
1111 | } | 1069 | } |
1112 | if ( (NULL != connection->sock) && | 1070 | if ((NULL != connection->sock) && (GNUNET_YES != connection->persist)) |
1113 | (GNUNET_YES != connection->persist) ) | ||
1114 | { | 1071 | { |
1115 | if ((GNUNET_OK != | 1072 | if ((GNUNET_OK != |
1116 | GNUNET_NETWORK_socket_shutdown (connection->sock, | 1073 | GNUNET_NETWORK_socket_shutdown (connection->sock, SHUT_RDWR)) && |
1117 | SHUT_RDWR)) && | 1074 | (ENOTCONN != errno) && (ECONNRESET != errno)) |
1118 | (ENOTCONN != errno) && | 1075 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "shutdown"); |
1119 | (ECONNRESET != errno) ) | ||
1120 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, | ||
1121 | "shutdown"); | ||
1122 | } | 1076 | } |
1123 | if (NULL != connection->sock) | 1077 | if (NULL != connection->sock) |
1124 | { | 1078 | { |
@@ -1129,7 +1083,8 @@ GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection) | |||
1129 | } | 1083 | } |
1130 | else | 1084 | else |
1131 | { | 1085 | { |
1132 | GNUNET_NETWORK_socket_free_memory_only_ (connection->sock); /* at least no memory leak (we deliberately | 1086 | GNUNET_NETWORK_socket_free_memory_only_ ( |
1087 | connection->sock); /* at least no memory leak (we deliberately | ||
1133 | * leak the socket in this special case) ... */ | 1088 | * leak the socket in this special case) ... */ |
1134 | } | 1089 | } |
1135 | } | 1090 | } |
@@ -1160,12 +1115,12 @@ receive_ready (void *cls) | |||
1160 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) | 1115 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) |
1161 | { | 1116 | { |
1162 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1117 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1163 | "Receive from `%s' encounters error: timeout (%s, %p)\n", | 1118 | "Receive from `%s' encounters error: timeout (%s, %p)\n", |
1164 | GNUNET_a2s (connection->addr, | 1119 | GNUNET_a2s (connection->addr, connection->addrlen), |
1165 | connection->addrlen), | 1120 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration ( |
1166 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (connection->receive_timeout), | 1121 | connection->receive_timeout), |
1167 | GNUNET_YES), | 1122 | GNUNET_YES), |
1168 | connection); | 1123 | connection); |
1169 | signal_receive_timeout (connection); | 1124 | signal_receive_timeout (connection); |
1170 | return; | 1125 | return; |
1171 | } | 1126 | } |
@@ -1175,12 +1130,9 @@ receive_ready (void *cls) | |||
1175 | signal_receive_error (connection, ECONNREFUSED); | 1130 | signal_receive_error (connection, ECONNREFUSED); |
1176 | return; | 1131 | return; |
1177 | } | 1132 | } |
1178 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 1133 | GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, connection->sock)); |
1179 | connection->sock)); | ||
1180 | RETRY: | 1134 | RETRY: |
1181 | ret = GNUNET_NETWORK_socket_recv (connection->sock, | 1135 | ret = GNUNET_NETWORK_socket_recv (connection->sock, buffer, connection->max); |
1182 | buffer, | ||
1183 | connection->max); | ||
1184 | if (-1 == ret) | 1136 | if (-1 == ret) |
1185 | { | 1137 | { |
1186 | if (EINTR == errno) | 1138 | if (EINTR == errno) |
@@ -1192,8 +1144,7 @@ RETRY: | |||
1192 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", | 1144 | "receive_ready read %u/%u bytes from `%s' (%p)!\n", |
1193 | (unsigned int) ret, | 1145 | (unsigned int) ret, |
1194 | connection->max, | 1146 | connection->max, |
1195 | GNUNET_a2s (connection->addr, | 1147 | GNUNET_a2s (connection->addr, connection->addrlen), |
1196 | connection->addrlen), | ||
1197 | connection); | 1148 | connection); |
1198 | GNUNET_assert (NULL != (receiver = connection->receiver)); | 1149 | GNUNET_assert (NULL != (receiver = connection->receiver)); |
1199 | connection->receiver = NULL; | 1150 | connection->receiver = NULL; |
@@ -1238,22 +1189,18 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, | |||
1238 | if (NULL != connection->sock) | 1189 | if (NULL != connection->sock) |
1239 | { | 1190 | { |
1240 | connection->read_task = | 1191 | connection->read_task = |
1241 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining | 1192 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_absolute_get_remaining ( |
1242 | (connection->receive_timeout), | 1193 | connection->receive_timeout), |
1243 | connection->sock, | 1194 | connection->sock, |
1244 | &receive_ready, | 1195 | &receive_ready, |
1245 | connection); | 1196 | connection); |
1246 | return GNUNET_OK; | 1197 | return GNUNET_OK; |
1247 | } | 1198 | } |
1248 | if ((NULL == connection->dns_active) && | 1199 | if ((NULL == connection->dns_active) && (NULL == connection->ap_head) && |
1249 | (NULL == connection->ap_head) && | ||
1250 | (NULL == connection->proxy_handshake)) | 1200 | (NULL == connection->proxy_handshake)) |
1251 | { | 1201 | { |
1252 | connection->receiver = NULL; | 1202 | connection->receiver = NULL; |
1253 | receiver (receiver_cls, | 1203 | receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); |
1254 | NULL, 0, | ||
1255 | NULL, 0, | ||
1256 | ETIMEDOUT); | ||
1257 | return GNUNET_SYSERR; | 1204 | return GNUNET_SYSERR; |
1258 | } | 1205 | } |
1259 | return GNUNET_OK; | 1206 | return GNUNET_OK; |
@@ -1297,13 +1244,11 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1297 | size_t size; | 1244 | size_t size; |
1298 | GNUNET_CONNECTION_TransmitReadyNotify notify; | 1245 | GNUNET_CONNECTION_TransmitReadyNotify notify; |
1299 | 1246 | ||
1300 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, "process_notify is running\n"); |
1301 | "process_notify is running\n"); | ||
1302 | GNUNET_assert (NULL == connection->write_task); | 1248 | GNUNET_assert (NULL == connection->write_task); |
1303 | if (NULL == (notify = connection->nth.notify_ready)) | 1249 | if (NULL == (notify = connection->nth.notify_ready)) |
1304 | { | 1250 | { |
1305 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1251 | LOG (GNUNET_ERROR_TYPE_DEBUG, "No one to notify\n"); |
1306 | "No one to notify\n"); | ||
1307 | return GNUNET_NO; | 1252 | return GNUNET_NO; |
1308 | } | 1253 | } |
1309 | used = connection->write_buffer_off - connection->write_buffer_pos; | 1254 | used = connection->write_buffer_off - connection->write_buffer_pos; |
@@ -1311,8 +1256,7 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1311 | size = connection->nth.notify_size; | 1256 | size = connection->nth.notify_size; |
1312 | if (size > avail) | 1257 | if (size > avail) |
1313 | { | 1258 | { |
1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1259 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Not enough buffer\n"); |
1315 | "Not enough buffer\n"); | ||
1316 | return GNUNET_NO; | 1260 | return GNUNET_NO; |
1317 | } | 1261 | } |
1318 | connection->nth.notify_ready = NULL; | 1262 | connection->nth.notify_ready = NULL; |
@@ -1327,9 +1271,9 @@ process_notify (struct GNUNET_CONNECTION_Handle *connection) | |||
1327 | } | 1271 | } |
1328 | avail = connection->write_buffer_size - connection->write_buffer_off; | 1272 | avail = connection->write_buffer_size - connection->write_buffer_off; |
1329 | GNUNET_assert (avail >= size); | 1273 | GNUNET_assert (avail >= size); |
1330 | size = | 1274 | size = notify (connection->nth.notify_ready_cls, |
1331 | notify (connection->nth.notify_ready_cls, avail, | 1275 | avail, |
1332 | &connection->write_buffer[connection->write_buffer_off]); | 1276 | &connection->write_buffer[connection->write_buffer_off]); |
1333 | GNUNET_assert (size <= avail); | 1277 | GNUNET_assert (size <= avail); |
1334 | if (0 != size) | 1278 | if (0 != size) |
1335 | connection->write_buffer_off += size; | 1279 | connection->write_buffer_off += size; |
@@ -1358,15 +1302,12 @@ transmit_timeout (void *cls) | |||
1358 | "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", | 1302 | "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", |
1359 | connection->hostname, | 1303 | connection->hostname, |
1360 | connection->port, | 1304 | connection->port, |
1361 | GNUNET_a2s (connection->addr, | 1305 | GNUNET_a2s (connection->addr, connection->addrlen), |
1362 | connection->addrlen), | ||
1363 | connection); | 1306 | connection); |
1364 | notify = connection->nth.notify_ready; | 1307 | notify = connection->nth.notify_ready; |
1365 | GNUNET_assert (NULL != notify); | 1308 | GNUNET_assert (NULL != notify); |
1366 | connection->nth.notify_ready = NULL; | 1309 | connection->nth.notify_ready = NULL; |
1367 | notify (connection->nth.notify_ready_cls, | 1310 | notify (connection->nth.notify_ready_cls, 0, NULL); |
1368 | 0, | ||
1369 | NULL); | ||
1370 | } | 1311 | } |
1371 | 1312 | ||
1372 | 1313 | ||
@@ -1393,9 +1334,7 @@ connect_error (void *cls) | |||
1393 | connection->write_task = NULL; | 1334 | connection->write_task = NULL; |
1394 | notify = connection->nth.notify_ready; | 1335 | notify = connection->nth.notify_ready; |
1395 | connection->nth.notify_ready = NULL; | 1336 | connection->nth.notify_ready = NULL; |
1396 | notify (connection->nth.notify_ready_cls, | 1337 | notify (connection->nth.notify_ready_cls, 0, NULL); |
1397 | 0, | ||
1398 | NULL); | ||
1399 | } | 1338 | } |
1400 | 1339 | ||
1401 | 1340 | ||
@@ -1413,9 +1352,7 @@ transmit_ready (void *cls) | |||
1413 | ssize_t ret; | 1352 | ssize_t ret; |
1414 | size_t have; | 1353 | size_t have; |
1415 | 1354 | ||
1416 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1355 | LOG (GNUNET_ERROR_TYPE_DEBUG, "transmit_ready running (%p).\n", connection); |
1417 | "transmit_ready running (%p).\n", | ||
1418 | connection); | ||
1419 | GNUNET_assert (NULL != connection->write_task); | 1356 | GNUNET_assert (NULL != connection->write_task); |
1420 | connection->write_task = NULL; | 1357 | connection->write_task = NULL; |
1421 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1358 | GNUNET_assert (NULL == connection->nth.timeout_task); |
@@ -1424,8 +1361,7 @@ transmit_ready (void *cls) | |||
1424 | { | 1361 | { |
1425 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1362 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1426 | "Transmit to `%s' fails, time out reached (%p).\n", | 1363 | "Transmit to `%s' fails, time out reached (%p).\n", |
1427 | GNUNET_a2s (connection->addr, | 1364 | GNUNET_a2s (connection->addr, connection->addrlen), |
1428 | connection->addrlen), | ||
1429 | connection); | 1365 | connection); |
1430 | notify = connection->nth.notify_ready; | 1366 | notify = connection->nth.notify_ready; |
1431 | GNUNET_assert (NULL != notify); | 1367 | GNUNET_assert (NULL != notify); |
@@ -1441,8 +1377,7 @@ transmit_ready (void *cls) | |||
1441 | * Hence retry. */ | 1377 | * Hence retry. */ |
1442 | goto SCHEDULE_WRITE; | 1378 | goto SCHEDULE_WRITE; |
1443 | } | 1379 | } |
1444 | if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, | 1380 | if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, connection->sock)) |
1445 | connection->sock)) | ||
1446 | { | 1381 | { |
1447 | GNUNET_assert (NULL == connection->write_task); | 1382 | GNUNET_assert (NULL == connection->write_task); |
1448 | /* special circumstances (in particular, shutdown): not yet ready | 1383 | /* special circumstances (in particular, shutdown): not yet ready |
@@ -1454,7 +1389,7 @@ transmit_ready (void *cls) | |||
1454 | (connection->write_buffer_size < connection->nth.notify_size)) | 1389 | (connection->write_buffer_size < connection->nth.notify_size)) |
1455 | { | 1390 | { |
1456 | connection->write_buffer = | 1391 | connection->write_buffer = |
1457 | GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); | 1392 | GNUNET_realloc (connection->write_buffer, connection->nth.notify_size); |
1458 | connection->write_buffer_size = connection->nth.notify_size; | 1393 | connection->write_buffer_size = connection->nth.notify_size; |
1459 | } | 1394 | } |
1460 | process_notify (connection); | 1395 | process_notify (connection); |
@@ -1465,13 +1400,15 @@ transmit_ready (void *cls) | |||
1465 | return; | 1400 | return; |
1466 | } | 1401 | } |
1467 | GNUNET_assert (have <= connection->write_buffer_size); | 1402 | GNUNET_assert (have <= connection->write_buffer_size); |
1468 | GNUNET_assert (have + connection->write_buffer_pos <= connection->write_buffer_size); | 1403 | GNUNET_assert (have + connection->write_buffer_pos <= |
1404 | connection->write_buffer_size); | ||
1469 | GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); | 1405 | GNUNET_assert (connection->write_buffer_pos <= connection->write_buffer_size); |
1470 | RETRY: | 1406 | RETRY: |
1471 | ret = | 1407 | ret = |
1472 | GNUNET_NETWORK_socket_send (connection->sock, | 1408 | GNUNET_NETWORK_socket_send (connection->sock, |
1473 | &connection->write_buffer[connection->write_buffer_pos], | 1409 | &connection |
1474 | have); | 1410 | ->write_buffer[connection->write_buffer_pos], |
1411 | have); | ||
1475 | if (-1 == ret) | 1412 | if (-1 == ret) |
1476 | { | 1413 | { |
1477 | if (EINTR == errno) | 1414 | if (EINTR == errno) |
@@ -1488,8 +1425,7 @@ RETRY: | |||
1488 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", | 1425 | "Connection transmitted %u/%u bytes to `%s' (%p)\n", |
1489 | (unsigned int) ret, | 1426 | (unsigned int) ret, |
1490 | have, | 1427 | have, |
1491 | GNUNET_a2s (connection->addr, | 1428 | GNUNET_a2s (connection->addr, connection->addrlen), |
1492 | connection->addrlen), | ||
1493 | connection); | 1429 | connection); |
1494 | connection->write_buffer_pos += ret; | 1430 | connection->write_buffer_pos += ret; |
1495 | if (connection->write_buffer_pos == connection->write_buffer_off) | 1431 | if (connection->write_buffer_pos == connection->write_buffer_off) |
@@ -1498,25 +1434,25 @@ RETRY: | |||
1498 | connection->write_buffer_pos = 0; | 1434 | connection->write_buffer_pos = 0; |
1499 | connection->write_buffer_off = 0; | 1435 | connection->write_buffer_off = 0; |
1500 | } | 1436 | } |
1501 | if ( (0 == connection->write_buffer_off) && | 1437 | if ((0 == connection->write_buffer_off) && |
1502 | (NULL == connection->nth.notify_ready) ) | 1438 | (NULL == connection->nth.notify_ready)) |
1503 | return; /* all data sent! */ | 1439 | return; /* all data sent! */ |
1504 | /* not done writing, schedule more */ | 1440 | /* not done writing, schedule more */ |
1505 | SCHEDULE_WRITE: | 1441 | SCHEDULE_WRITE: |
1506 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1442 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1507 | "Re-scheduling transmit_ready (more to do) (%p).\n", | 1443 | "Re-scheduling transmit_ready (more to do) (%p).\n", |
1508 | connection); | 1444 | connection); |
1509 | have = connection->write_buffer_off - connection->write_buffer_pos; | 1445 | have = connection->write_buffer_off - connection->write_buffer_pos; |
1510 | GNUNET_assert ( (NULL != connection->nth.notify_ready) || | 1446 | GNUNET_assert ((NULL != connection->nth.notify_ready) || (have > 0)); |
1511 | (have > 0) ); | ||
1512 | if (NULL == connection->write_task) | 1447 | if (NULL == connection->write_task) |
1513 | connection->write_task = | 1448 | connection->write_task = |
1514 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == | 1449 | GNUNET_SCHEDULER_add_write_net ((connection->nth.notify_ready == NULL) |
1515 | NULL) ? GNUNET_TIME_UNIT_FOREVER_REL : | 1450 | ? GNUNET_TIME_UNIT_FOREVER_REL |
1516 | GNUNET_TIME_absolute_get_remaining | 1451 | : GNUNET_TIME_absolute_get_remaining ( |
1517 | (connection->nth.transmit_timeout), | 1452 | connection->nth.transmit_timeout), |
1518 | connection->sock, | 1453 | connection->sock, |
1519 | &transmit_ready, connection); | 1454 | &transmit_ready, |
1455 | connection); | ||
1520 | } | 1456 | } |
1521 | 1457 | ||
1522 | 1458 | ||
@@ -1535,11 +1471,12 @@ SCHEDULE_WRITE: | |||
1535 | * NULL if we are already going to notify someone else (busy) | 1471 | * NULL if we are already going to notify someone else (busy) |
1536 | */ | 1472 | */ |
1537 | struct GNUNET_CONNECTION_TransmitHandle * | 1473 | struct GNUNET_CONNECTION_TransmitHandle * |
1538 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, | 1474 | GNUNET_CONNECTION_notify_transmit_ready ( |
1539 | size_t size, | 1475 | struct GNUNET_CONNECTION_Handle *connection, |
1540 | struct GNUNET_TIME_Relative timeout, | 1476 | size_t size, |
1541 | GNUNET_CONNECTION_TransmitReadyNotify notify, | 1477 | struct GNUNET_TIME_Relative timeout, |
1542 | void *notify_cls) | 1478 | GNUNET_CONNECTION_TransmitReadyNotify notify, |
1479 | void *notify_cls) | ||
1543 | { | 1480 | { |
1544 | if (NULL != connection->nth.notify_ready) | 1481 | if (NULL != connection->nth.notify_ready) |
1545 | { | 1482 | { |
@@ -1557,15 +1494,13 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1557 | connection->nth.notify_size = size; | 1494 | connection->nth.notify_size = size; |
1558 | connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); | 1495 | connection->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); |
1559 | GNUNET_assert (NULL == connection->nth.timeout_task); | 1496 | GNUNET_assert (NULL == connection->nth.timeout_task); |
1560 | if ((NULL == connection->sock) && | 1497 | if ((NULL == connection->sock) && (NULL == connection->ap_head) && |
1561 | (NULL == connection->ap_head) && | 1498 | (NULL == connection->dns_active) && (NULL == connection->proxy_handshake)) |
1562 | (NULL == connection->dns_active) && | ||
1563 | (NULL == connection->proxy_handshake)) | ||
1564 | { | 1499 | { |
1565 | if (NULL != connection->write_task) | 1500 | if (NULL != connection->write_task) |
1566 | GNUNET_SCHEDULER_cancel (connection->write_task); | 1501 | GNUNET_SCHEDULER_cancel (connection->write_task); |
1567 | connection->write_task = GNUNET_SCHEDULER_add_now (&connect_error, | 1502 | connection->write_task = |
1568 | connection); | 1503 | GNUNET_SCHEDULER_add_now (&connect_error, connection); |
1569 | return &connection->nth; | 1504 | return &connection->nth; |
1570 | } | 1505 | } |
1571 | if (NULL != connection->write_task) | 1506 | if (NULL != connection->write_task) |
@@ -1577,10 +1512,11 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1577 | "Scheduling transmission (%p).\n", | 1512 | "Scheduling transmission (%p).\n", |
1578 | connection); | 1513 | connection); |
1579 | connection->write_task = | 1514 | connection->write_task = |
1580 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining | 1515 | GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_absolute_get_remaining ( |
1581 | (connection->nth.transmit_timeout), | 1516 | connection->nth.transmit_timeout), |
1582 | connection->sock, | 1517 | connection->sock, |
1583 | &transmit_ready, connection); | 1518 | &transmit_ready, |
1519 | connection); | ||
1584 | return &connection->nth; | 1520 | return &connection->nth; |
1585 | } | 1521 | } |
1586 | /* not yet connected, wait for connection */ | 1522 | /* not yet connected, wait for connection */ |
@@ -1588,9 +1524,7 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1588 | "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", | 1524 | "Need to wait to schedule transmission for connection, adding timeout task (%p).\n", |
1589 | connection); | 1525 | connection); |
1590 | connection->nth.timeout_task = | 1526 | connection->nth.timeout_task = |
1591 | GNUNET_SCHEDULER_add_delayed (timeout, | 1527 | GNUNET_SCHEDULER_add_delayed (timeout, &transmit_timeout, connection); |
1592 | &transmit_timeout, | ||
1593 | connection); | ||
1594 | return &connection->nth; | 1528 | return &connection->nth; |
1595 | } | 1529 | } |
1596 | 1530 | ||
@@ -1601,7 +1535,8 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connec | |||
1601 | * @param th notification to cancel | 1535 | * @param th notification to cancel |
1602 | */ | 1536 | */ |
1603 | void | 1537 | void |
1604 | GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_TransmitHandle *th) | 1538 | GNUNET_CONNECTION_notify_transmit_ready_cancel ( |
1539 | struct GNUNET_CONNECTION_TransmitHandle *th) | ||
1605 | { | 1540 | { |
1606 | GNUNET_assert (NULL != th->notify_ready); | 1541 | GNUNET_assert (NULL != th->notify_ready); |
1607 | th->notify_ready = NULL; | 1542 | th->notify_ready = NULL; |
@@ -1625,9 +1560,11 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct GNUNET_CONNECTION_Transmi | |||
1625 | * @return connection to be proxied | 1560 | * @return connection to be proxied |
1626 | */ | 1561 | */ |
1627 | struct GNUNET_CONNECTION_Handle * | 1562 | struct GNUNET_CONNECTION_Handle * |
1628 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph) | 1563 | GNUNET_CONNECTION_create_proxied_from_handshake ( |
1564 | struct GNUNET_CONNECTION_Handle *cph) | ||
1629 | { | 1565 | { |
1630 | struct GNUNET_CONNECTION_Handle *proxied = GNUNET_CONNECTION_create_from_existing (NULL); | 1566 | struct GNUNET_CONNECTION_Handle *proxied = |
1567 | GNUNET_CONNECTION_create_from_existing (NULL); | ||
1631 | 1568 | ||
1632 | proxied->proxy_handshake = cph; | 1569 | proxied->proxy_handshake = cph; |
1633 | return proxied; | 1570 | return proxied; |
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c index 19508a39f..e59fa4a1c 100644 --- a/src/transport/tcp_service_legacy.c +++ b/src/transport/tcp_service_legacy.c | |||
@@ -224,7 +224,6 @@ struct LEGACY_SERVICE_Context | |||
224 | * Our options. | 224 | * Our options. |
225 | */ | 225 | */ |
226 | enum LEGACY_SERVICE_Options options; | 226 | enum LEGACY_SERVICE_Options options; |
227 | |||
228 | }; | 227 | }; |
229 | 228 | ||
230 | 229 | ||
@@ -247,7 +246,7 @@ write_test (void *cls, size_t size, void *buf) | |||
247 | if (size < sizeof (struct GNUNET_MessageHeader)) | 246 | if (size < sizeof (struct GNUNET_MessageHeader)) |
248 | { | 247 | { |
249 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 248 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
250 | return 0; /* client disconnected */ | 249 | return 0; /* client disconnected */ |
251 | } | 250 | } |
252 | msg = (struct GNUNET_MessageHeader *) buf; | 251 | msg = (struct GNUNET_MessageHeader *) buf; |
253 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); | 252 | msg->type = htons (GNUNET_MESSAGE_TYPE_TEST); |
@@ -265,7 +264,8 @@ write_test (void *cls, size_t size, void *buf) | |||
265 | * @param message the actual message | 264 | * @param message the actual message |
266 | */ | 265 | */ |
267 | static void | 266 | static void |
268 | handle_test (void *cls, struct GNUNET_SERVER_Client *client, | 267 | handle_test (void *cls, |
268 | struct GNUNET_SERVER_Client *client, | ||
269 | const struct GNUNET_MessageHeader *message) | 269 | const struct GNUNET_MessageHeader *message) |
270 | { | 270 | { |
271 | /* simply bounce message back to acknowledge */ | 271 | /* simply bounce message back to acknowledge */ |
@@ -273,7 +273,8 @@ handle_test (void *cls, struct GNUNET_SERVER_Client *client, | |||
273 | GNUNET_SERVER_notify_transmit_ready (client, | 273 | GNUNET_SERVER_notify_transmit_ready (client, |
274 | sizeof (struct GNUNET_MessageHeader), | 274 | sizeof (struct GNUNET_MessageHeader), |
275 | GNUNET_TIME_UNIT_FOREVER_REL, | 275 | GNUNET_TIME_UNIT_FOREVER_REL, |
276 | &write_test, client)) | 276 | &write_test, |
277 | client)) | ||
277 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 278 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
278 | } | 279 | } |
279 | 280 | ||
@@ -283,11 +284,12 @@ handle_test (void *cls, struct GNUNET_SERVER_Client *client, | |||
283 | * "callback_cls" fields will be replaced with the specific service | 284 | * "callback_cls" fields will be replaced with the specific service |
284 | * struct. | 285 | * struct. |
285 | */ | 286 | */ |
286 | static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { | 287 | static const struct GNUNET_SERVER_MessageHandler defhandlers[] = |
287 | {&handle_test, NULL, GNUNET_MESSAGE_TYPE_TEST, | 288 | {{&handle_test, |
288 | sizeof (struct GNUNET_MessageHeader)}, | 289 | NULL, |
289 | {NULL, NULL, 0, 0} | 290 | GNUNET_MESSAGE_TYPE_TEST, |
290 | }; | 291 | sizeof (struct GNUNET_MessageHeader)}, |
292 | {NULL, NULL, 0, 0}}; | ||
291 | 293 | ||
292 | 294 | ||
293 | /* ****************** service core routines ************** */ | 295 | /* ****************** service core routines ************** */ |
@@ -304,8 +306,10 @@ static const struct GNUNET_SERVER_MessageHandler defhandlers[] = { | |||
304 | * for unknown address family (will be denied). | 306 | * for unknown address family (will be denied). |
305 | */ | 307 | */ |
306 | static int | 308 | static int |
307 | check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, | 309 | check_access (void *cls, |
308 | const struct sockaddr *addr, socklen_t addrlen) | 310 | const struct GNUNET_CONNECTION_Credentials *uc, |
311 | const struct sockaddr *addr, | ||
312 | socklen_t addrlen) | ||
309 | { | 313 | { |
310 | struct LEGACY_SERVICE_Context *sctx = cls; | 314 | struct LEGACY_SERVICE_Context *sctx = cls; |
311 | const struct sockaddr_in *i4; | 315 | const struct sockaddr_in *i4; |
@@ -319,32 +323,33 @@ check_access (void *cls, const struct GNUNET_CONNECTION_Credentials *uc, | |||
319 | i4 = (const struct sockaddr_in *) addr; | 323 | i4 = (const struct sockaddr_in *) addr; |
320 | ret = ((NULL == sctx->v4_allowed) || | 324 | ret = ((NULL == sctx->v4_allowed) || |
321 | (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && | 325 | (check_ipv4_listed (sctx->v4_allowed, &i4->sin_addr))) && |
322 | ((NULL == sctx->v4_denied) || | 326 | ((NULL == sctx->v4_denied) || |
323 | (!check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); | 327 | (! check_ipv4_listed (sctx->v4_denied, &i4->sin_addr))); |
324 | break; | 328 | break; |
325 | case AF_INET6: | 329 | case AF_INET6: |
326 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); | 330 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); |
327 | i6 = (const struct sockaddr_in6 *) addr; | 331 | i6 = (const struct sockaddr_in6 *) addr; |
328 | ret = ((NULL == sctx->v6_allowed) || | 332 | ret = ((NULL == sctx->v6_allowed) || |
329 | (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && | 333 | (check_ipv6_listed (sctx->v6_allowed, &i6->sin6_addr))) && |
330 | ((NULL == sctx->v6_denied) || | 334 | ((NULL == sctx->v6_denied) || |
331 | (!check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); | 335 | (! check_ipv6_listed (sctx->v6_denied, &i6->sin6_addr))); |
332 | break; | 336 | break; |
333 | #ifndef WINDOWS | 337 | #ifndef WINDOWS |
334 | case AF_UNIX: | 338 | case AF_UNIX: |
335 | ret = GNUNET_OK; /* controlled using file-system ACL now */ | 339 | ret = GNUNET_OK; /* controlled using file-system ACL now */ |
336 | break; | 340 | break; |
337 | #endif | 341 | #endif |
338 | default: | 342 | default: |
339 | LOG (GNUNET_ERROR_TYPE_WARNING, _("Unknown address family %d\n"), | 343 | LOG (GNUNET_ERROR_TYPE_WARNING, |
344 | _ ("Unknown address family %d\n"), | ||
340 | addr->sa_family); | 345 | addr->sa_family); |
341 | return GNUNET_SYSERR; | 346 | return GNUNET_SYSERR; |
342 | } | 347 | } |
343 | if (GNUNET_OK != ret) | 348 | if (GNUNET_OK != ret) |
344 | { | 349 | { |
345 | LOG (GNUNET_ERROR_TYPE_WARNING, | 350 | LOG (GNUNET_ERROR_TYPE_WARNING, |
346 | _("Access from `%s' denied to service `%s'\n"), | 351 | _ ("Access from `%s' denied to service `%s'\n"), |
347 | GNUNET_a2s (addr, addrlen), | 352 | GNUNET_a2s (addr, addrlen), |
348 | sctx->service_name); | 353 | sctx->service_name); |
349 | } | 354 | } |
350 | return ret; | 355 | return ret; |
@@ -363,9 +368,10 @@ get_pid_file_name (struct LEGACY_SERVICE_Context *sctx) | |||
363 | { | 368 | { |
364 | char *pif; | 369 | char *pif; |
365 | 370 | ||
366 | if (GNUNET_OK != | 371 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, |
367 | GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name, | 372 | sctx->service_name, |
368 | "PIDFILE", &pif)) | 373 | "PIDFILE", |
374 | &pif)) | ||
369 | return NULL; | 375 | return NULL; |
370 | return pif; | 376 | return pif; |
371 | } | 377 | } |
@@ -387,7 +393,7 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, | |||
387 | { | 393 | { |
388 | char *opt; | 394 | char *opt; |
389 | 395 | ||
390 | if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) | 396 | if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) |
391 | { | 397 | { |
392 | *ret = NULL; | 398 | *ret = NULL; |
393 | return GNUNET_OK; | 399 | return GNUNET_OK; |
@@ -395,12 +401,15 @@ process_acl4 (struct GNUNET_STRINGS_IPv4NetworkPolicy **ret, | |||
395 | GNUNET_break (GNUNET_OK == | 401 | GNUNET_break (GNUNET_OK == |
396 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, | 402 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, |
397 | sctx->service_name, | 403 | sctx->service_name, |
398 | option, &opt)); | 404 | option, |
405 | &opt)); | ||
399 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt))) | 406 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv4_policy (opt))) |
400 | { | 407 | { |
401 | LOG (GNUNET_ERROR_TYPE_WARNING, | 408 | LOG (GNUNET_ERROR_TYPE_WARNING, |
402 | _("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), | 409 | _ ("Could not parse IPv4 network specification `%s' for `%s:%s'\n"), |
403 | opt, sctx->service_name, option); | 410 | opt, |
411 | sctx->service_name, | ||
412 | option); | ||
404 | GNUNET_free (opt); | 413 | GNUNET_free (opt); |
405 | return GNUNET_SYSERR; | 414 | return GNUNET_SYSERR; |
406 | } | 415 | } |
@@ -425,7 +434,7 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, | |||
425 | { | 434 | { |
426 | char *opt; | 435 | char *opt; |
427 | 436 | ||
428 | if (!GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) | 437 | if (! GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, option)) |
429 | { | 438 | { |
430 | *ret = NULL; | 439 | *ret = NULL; |
431 | return GNUNET_OK; | 440 | return GNUNET_OK; |
@@ -433,12 +442,15 @@ process_acl6 (struct GNUNET_STRINGS_IPv6NetworkPolicy **ret, | |||
433 | GNUNET_break (GNUNET_OK == | 442 | GNUNET_break (GNUNET_OK == |
434 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, | 443 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, |
435 | sctx->service_name, | 444 | sctx->service_name, |
436 | option, &opt)); | 445 | option, |
446 | &opt)); | ||
437 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt))) | 447 | if (NULL == (*ret = GNUNET_STRINGS_parse_ipv6_policy (opt))) |
438 | { | 448 | { |
439 | LOG (GNUNET_ERROR_TYPE_WARNING, | 449 | LOG (GNUNET_ERROR_TYPE_WARNING, |
440 | _("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), | 450 | _ ("Could not parse IPv6 network specification `%s' for `%s:%s'\n"), |
441 | opt, sctx->service_name, option); | 451 | opt, |
452 | sctx->service_name, | ||
453 | option); | ||
442 | GNUNET_free (opt); | 454 | GNUNET_free (opt); |
443 | return GNUNET_SYSERR; | 455 | return GNUNET_SYSERR; |
444 | } | 456 | } |
@@ -507,10 +519,11 @@ add_unixpath (struct sockaddr **saddrs, | |||
507 | * set to NULL). | 519 | * set to NULL). |
508 | */ | 520 | */ |
509 | int | 521 | int |
510 | LEGACY_SERVICE_get_server_addresses (const char *service_name, | 522 | LEGACY_SERVICE_get_server_addresses ( |
511 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 523 | const char *service_name, |
512 | struct sockaddr ***addrs, | 524 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
513 | socklen_t ** addr_lens) | 525 | struct sockaddr ***addrs, |
526 | socklen_t **addr_lens) | ||
514 | { | 527 | { |
515 | int disablev6; | 528 | int disablev6; |
516 | struct GNUNET_NETWORK_Handle *desc; | 529 | struct GNUNET_NETWORK_Handle *desc; |
@@ -534,8 +547,9 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
534 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) | 547 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "DISABLEV6")) |
535 | { | 548 | { |
536 | if (GNUNET_SYSERR == | 549 | if (GNUNET_SYSERR == |
537 | (disablev6 = | 550 | (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
538 | GNUNET_CONFIGURATION_get_value_yesno (cfg, service_name, "DISABLEV6"))) | 551 | service_name, |
552 | "DISABLEV6"))) | ||
539 | return GNUNET_SYSERR; | 553 | return GNUNET_SYSERR; |
540 | } | 554 | } |
541 | else | 555 | else |
@@ -554,8 +568,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
554 | return GNUNET_SYSERR; | 568 | return GNUNET_SYSERR; |
555 | } | 569 | } |
556 | LOG (GNUNET_ERROR_TYPE_INFO, | 570 | LOG (GNUNET_ERROR_TYPE_INFO, |
557 | _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), | 571 | _ ( |
558 | service_name, STRERROR (errno)); | 572 | "Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), |
573 | service_name, | ||
574 | strerror (errno)); | ||
559 | disablev6 = GNUNET_YES; | 575 | disablev6 = GNUNET_YES; |
560 | } | 576 | } |
561 | else | 577 | else |
@@ -568,18 +584,19 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
568 | port = 0; | 584 | port = 0; |
569 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) | 585 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "PORT")) |
570 | { | 586 | { |
571 | if (GNUNET_OK != | 587 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
572 | GNUNET_CONFIGURATION_get_value_number (cfg, service_name, | 588 | service_name, |
573 | "PORT", &port)) | 589 | "PORT", |
590 | &port)) | ||
574 | { | 591 | { |
575 | LOG (GNUNET_ERROR_TYPE_ERROR, | 592 | LOG (GNUNET_ERROR_TYPE_ERROR, |
576 | _("Require valid port number for service `%s' in configuration!\n"), | 593 | _ ("Require valid port number for service `%s' in configuration!\n"), |
577 | service_name); | 594 | service_name); |
578 | } | 595 | } |
579 | if (port > 65535) | 596 | if (port > 65535) |
580 | { | 597 | { |
581 | LOG (GNUNET_ERROR_TYPE_ERROR, | 598 | LOG (GNUNET_ERROR_TYPE_ERROR, |
582 | _("Require valid port number for service `%s' in configuration!\n"), | 599 | _ ("Require valid port number for service `%s' in configuration!\n"), |
583 | service_name); | 600 | service_name); |
584 | return GNUNET_SYSERR; | 601 | return GNUNET_SYSERR; |
585 | } | 602 | } |
@@ -588,8 +605,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
588 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) | 605 | if (GNUNET_CONFIGURATION_have_value (cfg, service_name, "BINDTO")) |
589 | { | 606 | { |
590 | GNUNET_break (GNUNET_OK == | 607 | GNUNET_break (GNUNET_OK == |
591 | GNUNET_CONFIGURATION_get_value_string (cfg, service_name, | 608 | GNUNET_CONFIGURATION_get_value_string (cfg, |
592 | "BINDTO", &hostname)); | 609 | service_name, |
610 | "BINDTO", | ||
611 | &hostname)); | ||
593 | } | 612 | } |
594 | else | 613 | else |
595 | hostname = NULL; | 614 | hostname = NULL; |
@@ -599,9 +618,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
599 | #ifdef AF_UNIX | 618 | #ifdef AF_UNIX |
600 | if ((GNUNET_YES == | 619 | if ((GNUNET_YES == |
601 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && | 620 | GNUNET_CONFIGURATION_have_value (cfg, service_name, "UNIXPATH")) && |
602 | (GNUNET_OK == | 621 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_filename (cfg, |
603 | GNUNET_CONFIGURATION_get_value_filename (cfg, service_name, "UNIXPATH", | 622 | service_name, |
604 | &unixpath)) && | 623 | "UNIXPATH", |
624 | &unixpath)) && | ||
605 | (0 < strlen (unixpath))) | 625 | (0 < strlen (unixpath))) |
606 | { | 626 | { |
607 | /* probe UNIX support */ | 627 | /* probe UNIX support */ |
@@ -610,12 +630,11 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
610 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) | 630 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) |
611 | { | 631 | { |
612 | LOG (GNUNET_ERROR_TYPE_WARNING, | 632 | LOG (GNUNET_ERROR_TYPE_WARNING, |
613 | _("UNIXPATH `%s' too long, maximum length is %llu\n"), unixpath, | 633 | _ ("UNIXPATH `%s' too long, maximum length is %llu\n"), |
634 | unixpath, | ||
614 | (unsigned long long) sizeof (s_un.sun_path)); | 635 | (unsigned long long) sizeof (s_un.sun_path)); |
615 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); | 636 | unixpath = GNUNET_NETWORK_shorten_unixpath (unixpath); |
616 | LOG (GNUNET_ERROR_TYPE_INFO, | 637 | LOG (GNUNET_ERROR_TYPE_INFO, _ ("Using `%s' instead\n"), unixpath); |
617 | _("Using `%s' instead\n"), | ||
618 | unixpath); | ||
619 | } | 638 | } |
620 | #ifdef LINUX | 639 | #ifdef LINUX |
621 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 640 | abstract = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
@@ -624,12 +643,9 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
624 | if (GNUNET_SYSERR == abstract) | 643 | if (GNUNET_SYSERR == abstract) |
625 | abstract = GNUNET_NO; | 644 | abstract = GNUNET_NO; |
626 | #endif | 645 | #endif |
627 | if ((GNUNET_YES != abstract) | 646 | if ((GNUNET_YES != abstract) && |
628 | && (GNUNET_OK != | 647 | (GNUNET_OK != GNUNET_DISK_directory_create_for_file (unixpath))) |
629 | GNUNET_DISK_directory_create_for_file (unixpath))) | 648 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkdir", unixpath); |
630 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
631 | "mkdir", | ||
632 | unixpath); | ||
633 | } | 649 | } |
634 | if (NULL != unixpath) | 650 | if (NULL != unixpath) |
635 | { | 651 | { |
@@ -645,9 +661,10 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
645 | return GNUNET_SYSERR; | 661 | return GNUNET_SYSERR; |
646 | } | 662 | } |
647 | LOG (GNUNET_ERROR_TYPE_INFO, | 663 | LOG (GNUNET_ERROR_TYPE_INFO, |
648 | _("Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | 664 | _ ( |
665 | "Disabling UNIX domain socket support for service `%s', failed to create UNIX domain socket: %s\n"), | ||
649 | service_name, | 666 | service_name, |
650 | STRERROR (errno)); | 667 | strerror (errno)); |
651 | GNUNET_free (unixpath); | 668 | GNUNET_free (unixpath); |
652 | unixpath = NULL; | 669 | unixpath = NULL; |
653 | } | 670 | } |
@@ -662,7 +679,8 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
662 | if ((0 == port) && (NULL == unixpath)) | 679 | if ((0 == port) && (NULL == unixpath)) |
663 | { | 680 | { |
664 | LOG (GNUNET_ERROR_TYPE_ERROR, | 681 | LOG (GNUNET_ERROR_TYPE_ERROR, |
665 | _("Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | 682 | _ ( |
683 | "Have neither PORT nor UNIXPATH for service `%s', but one is required\n"), | ||
666 | service_name); | 684 | service_name); |
667 | GNUNET_free_non_null (hostname); | 685 | GNUNET_free_non_null (hostname); |
668 | return GNUNET_SYSERR; | 686 | return GNUNET_SYSERR; |
@@ -693,7 +711,7 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
693 | (NULL == res)) | 711 | (NULL == res)) |
694 | { | 712 | { |
695 | LOG (GNUNET_ERROR_TYPE_ERROR, | 713 | LOG (GNUNET_ERROR_TYPE_ERROR, |
696 | _("Failed to resolve `%s': %s\n"), | 714 | _ ("Failed to resolve `%s': %s\n"), |
697 | hostname, | 715 | hostname, |
698 | gai_strerror (ret)); | 716 | gai_strerror (ret)); |
699 | GNUNET_free (hostname); | 717 | GNUNET_free (hostname); |
@@ -712,7 +730,7 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
712 | if (0 == i) | 730 | if (0 == i) |
713 | { | 731 | { |
714 | LOG (GNUNET_ERROR_TYPE_ERROR, | 732 | LOG (GNUNET_ERROR_TYPE_ERROR, |
715 | _("Failed to find %saddress for `%s'.\n"), | 733 | _ ("Failed to find %saddress for `%s'.\n"), |
716 | disablev6 ? "IPv4 " : "", | 734 | disablev6 ? "IPv4 " : "", |
717 | hostname); | 735 | hostname); |
718 | freeaddrinfo (res); | 736 | freeaddrinfo (res); |
@@ -738,11 +756,13 @@ LEGACY_SERVICE_get_server_addresses (const char *service_name, | |||
738 | if ((disablev6) && (AF_INET6 == pos->ai_family)) | 756 | if ((disablev6) && (AF_INET6 == pos->ai_family)) |
739 | continue; | 757 | continue; |
740 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) | 758 | if ((IPPROTO_TCP != pos->ai_protocol) && (0 != pos->ai_protocol)) |
741 | continue; /* not TCP */ | 759 | continue; /* not TCP */ |
742 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) | 760 | if ((SOCK_STREAM != pos->ai_socktype) && (0 != pos->ai_socktype)) |
743 | continue; /* huh? */ | 761 | continue; /* huh? */ |
744 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Service `%s' will bind to `%s'\n", | 762 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
745 | service_name, GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | 763 | "Service `%s' will bind to `%s'\n", |
764 | service_name, | ||
765 | GNUNET_a2s (pos->ai_addr, pos->ai_addrlen)); | ||
746 | if (AF_INET == pos->ai_family) | 766 | if (AF_INET == pos->ai_family) |
747 | { | 767 | { |
748 | GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); | 768 | GNUNET_assert (sizeof (struct sockaddr_in) == pos->ai_addrlen); |
@@ -854,7 +874,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | |||
854 | * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) | 874 | * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) |
855 | */ | 875 | */ |
856 | lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10); | 876 | lsocks_pipe = (HANDLE) strtoul (env_buf, NULL, 10); |
857 | if ( (0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) | 877 | if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) |
858 | return GNUNET_NO; | 878 | return GNUNET_NO; |
859 | fail = 1; | 879 | fail = 1; |
860 | do | 880 | do |
@@ -867,7 +887,7 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | |||
867 | if ((0 == ret) || (sizeof (count) != rd) || (0 == count)) | 887 | if ((0 == ret) || (sizeof (count) != rd) || (0 == count)) |
868 | break; | 888 | break; |
869 | sctx->lsocks = | 889 | sctx->lsocks = |
870 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1)); | 890 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (count + 1)); |
871 | 891 | ||
872 | fail2 = 1; | 892 | fail2 = 1; |
873 | for (i = 0; i < count; i++) | 893 | for (i = 0; i < count; i++) |
@@ -877,12 +897,17 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | |||
877 | SOCKET s; | 897 | SOCKET s; |
878 | 898 | ||
879 | ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL); | 899 | ret = ReadFile (lsocks_pipe, &size, sizeof (size), &rd, NULL); |
880 | if ( (0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size) ) | 900 | if ((0 == ret) || (sizeof (size) != rd) || (sizeof (pi) != size)) |
881 | break; | 901 | break; |
882 | ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL); | 902 | ret = ReadFile (lsocks_pipe, &pi, sizeof (pi), &rd, NULL); |
883 | if ( (0 == ret) || (sizeof (pi) != rd)) | 903 | if ((0 == ret) || (sizeof (pi) != rd)) |
884 | break; | 904 | break; |
885 | s = WSASocketA (pi.iAddressFamily, pi.iSocketType, pi.iProtocol, &pi, 0, WSA_FLAG_OVERLAPPED); | 905 | s = WSASocketA (pi.iAddressFamily, |
906 | pi.iSocketType, | ||
907 | pi.iProtocol, | ||
908 | &pi, | ||
909 | 0, | ||
910 | WSA_FLAG_OVERLAPPED); | ||
886 | sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s); | 911 | sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native (s); |
887 | if (NULL == sctx->lsocks[i]) | 912 | if (NULL == sctx->lsocks[i]) |
888 | break; | 913 | break; |
@@ -893,15 +918,14 @@ receive_sockets_from_parent (struct LEGACY_SERVICE_Context *sctx) | |||
893 | break; | 918 | break; |
894 | sctx->lsocks[count] = NULL; | 919 | sctx->lsocks[count] = NULL; |
895 | fail = 0; | 920 | fail = 0; |
896 | } | 921 | } while (fail); |
897 | while (fail); | ||
898 | 922 | ||
899 | CloseHandle (lsocks_pipe); | 923 | CloseHandle (lsocks_pipe); |
900 | 924 | ||
901 | if (fail) | 925 | if (fail) |
902 | { | 926 | { |
903 | LOG (GNUNET_ERROR_TYPE_ERROR, | 927 | LOG (GNUNET_ERROR_TYPE_ERROR, |
904 | _("Could not access a pre-bound socket, will try to bind myself\n")); | 928 | _ ("Could not access a pre-bound socket, will try to bind myself\n")); |
905 | for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) | 929 | for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) |
906 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i])); | 930 | GNUNET_break (0 == GNUNET_NETWORK_socket_close (sctx->lsocks[i])); |
907 | GNUNET_free_non_null (sctx->lsocks); | 931 | GNUNET_free_non_null (sctx->lsocks); |
@@ -943,15 +967,19 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
943 | int flags; | 967 | int flags; |
944 | #endif | 968 | #endif |
945 | 969 | ||
946 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, "TIMEOUT")) | 970 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, |
971 | sctx->service_name, | ||
972 | "TIMEOUT")) | ||
947 | { | 973 | { |
948 | if (GNUNET_OK != | 974 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (sctx->cfg, |
949 | GNUNET_CONFIGURATION_get_value_time (sctx->cfg, sctx->service_name, | 975 | sctx->service_name, |
950 | "TIMEOUT", &idleout)) | 976 | "TIMEOUT", |
977 | &idleout)) | ||
951 | { | 978 | { |
952 | LOG (GNUNET_ERROR_TYPE_ERROR, | 979 | LOG (GNUNET_ERROR_TYPE_ERROR, |
953 | _("Specified value for `%s' of service `%s' is invalid\n"), | 980 | _ ("Specified value for `%s' of service `%s' is invalid\n"), |
954 | "TIMEOUT", sctx->service_name); | 981 | "TIMEOUT", |
982 | sctx->service_name); | ||
955 | return GNUNET_SYSERR; | 983 | return GNUNET_SYSERR; |
956 | } | 984 | } |
957 | sctx->timeout = idleout; | 985 | sctx->timeout = idleout; |
@@ -959,17 +987,19 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
959 | else | 987 | else |
960 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 988 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
961 | 989 | ||
962 | if (GNUNET_CONFIGURATION_have_value | 990 | if (GNUNET_CONFIGURATION_have_value (sctx->cfg, |
963 | (sctx->cfg, sctx->service_name, "TOLERANT")) | 991 | sctx->service_name, |
992 | "TOLERANT")) | ||
964 | { | 993 | { |
965 | if (GNUNET_SYSERR == | 994 | if (GNUNET_SYSERR == |
966 | (tolerant = | 995 | (tolerant = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, |
967 | GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name, | 996 | sctx->service_name, |
968 | "TOLERANT"))) | 997 | "TOLERANT"))) |
969 | { | 998 | { |
970 | LOG (GNUNET_ERROR_TYPE_ERROR, | 999 | LOG (GNUNET_ERROR_TYPE_ERROR, |
971 | _("Specified value for `%s' of service `%s' is invalid\n"), | 1000 | _ ("Specified value for `%s' of service `%s' is invalid\n"), |
972 | "TOLERANT", sctx->service_name); | 1001 | "TOLERANT", |
1002 | sctx->service_name); | ||
973 | return GNUNET_SYSERR; | 1003 | return GNUNET_SYSERR; |
974 | } | 1004 | } |
975 | } | 1005 | } |
@@ -979,11 +1009,11 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
979 | #ifndef MINGW | 1009 | #ifndef MINGW |
980 | errno = 0; | 1010 | errno = 0; |
981 | if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && | 1011 | if ((NULL != (nfds = getenv ("LISTEN_FDS"))) && |
982 | (1 == SSCANF (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && | 1012 | (1 == sscanf (nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && |
983 | (cnt + 4 < FD_SETSIZE)) | 1013 | (cnt + 4 < FD_SETSIZE)) |
984 | { | 1014 | { |
985 | sctx->lsocks = | 1015 | sctx->lsocks = |
986 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); | 1016 | GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle *) * (cnt + 1)); |
987 | while (0 < cnt--) | 1017 | while (0 < cnt--) |
988 | { | 1018 | { |
989 | flags = fcntl (3 + cnt, F_GETFD); | 1019 | flags = fcntl (3 + cnt, F_GETFD); |
@@ -992,8 +1022,8 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
992 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) | 1022 | (sctx->lsocks[cnt] = GNUNET_NETWORK_socket_box_native (3 + cnt)))) |
993 | { | 1023 | { |
994 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1024 | LOG (GNUNET_ERROR_TYPE_ERROR, |
995 | _ | 1025 | _ ( |
996 | ("Could not access pre-bound socket %u, will try to bind myself\n"), | 1026 | "Could not access pre-bound socket %u, will try to bind myself\n"), |
997 | (unsigned int) 3 + cnt); | 1027 | (unsigned int) 3 + cnt); |
998 | cnt++; | 1028 | cnt++; |
999 | while (sctx->lsocks[cnt] != NULL) | 1029 | while (sctx->lsocks[cnt] != NULL) |
@@ -1014,17 +1044,18 @@ setup_service (struct LEGACY_SERVICE_Context *sctx) | |||
1014 | #endif | 1044 | #endif |
1015 | 1045 | ||
1016 | if ((NULL == sctx->lsocks) && | 1046 | if ((NULL == sctx->lsocks) && |
1017 | (GNUNET_SYSERR == | 1047 | (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses (sctx->service_name, |
1018 | LEGACY_SERVICE_get_server_addresses (sctx->service_name, sctx->cfg, | 1048 | sctx->cfg, |
1019 | &sctx->addrs, &sctx->addrlens))) | 1049 | &sctx->addrs, |
1050 | &sctx->addrlens))) | ||
1020 | return GNUNET_SYSERR; | 1051 | return GNUNET_SYSERR; |
1021 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; | 1052 | sctx->require_found = tolerant ? GNUNET_NO : GNUNET_YES; |
1022 | sctx->match_uid = | 1053 | sctx->match_uid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, |
1023 | GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name, | 1054 | sctx->service_name, |
1024 | "UNIX_MATCH_UID"); | 1055 | "UNIX_MATCH_UID"); |
1025 | sctx->match_gid = | 1056 | sctx->match_gid = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, |
1026 | GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, sctx->service_name, | 1057 | sctx->service_name, |
1027 | "UNIX_MATCH_GID"); | 1058 | "UNIX_MATCH_GID"); |
1028 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); | 1059 | process_acl4 (&sctx->v4_denied, sctx, "REJECT_FROM"); |
1029 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); | 1060 | process_acl4 (&sctx->v4_allowed, sctx, "ACCEPT_FROM"); |
1030 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); | 1061 | process_acl6 (&sctx->v6_denied, sctx, "REJECT_FROM6"); |
@@ -1046,9 +1077,10 @@ get_user_name (struct LEGACY_SERVICE_Context *sctx) | |||
1046 | { | 1077 | { |
1047 | char *un; | 1078 | char *un; |
1048 | 1079 | ||
1049 | if (GNUNET_OK != | 1080 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, |
1050 | GNUNET_CONFIGURATION_get_value_filename (sctx->cfg, sctx->service_name, | 1081 | sctx->service_name, |
1051 | "USERNAME", &un)) | 1082 | "USERNAME", |
1083 | &un)) | ||
1052 | return NULL; | 1084 | return NULL; |
1053 | return un; | 1085 | return un; |
1054 | } | 1086 | } |
@@ -1071,14 +1103,14 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | |||
1071 | int len; | 1103 | int len; |
1072 | 1104 | ||
1073 | if (NULL == (pif = get_pid_file_name (sctx))) | 1105 | if (NULL == (pif = get_pid_file_name (sctx))) |
1074 | return GNUNET_OK; /* no file desired */ | 1106 | return GNUNET_OK; /* no file desired */ |
1075 | user = get_user_name (sctx); | 1107 | user = get_user_name (sctx); |
1076 | rdir = GNUNET_strdup (pif); | 1108 | rdir = GNUNET_strdup (pif); |
1077 | len = strlen (rdir); | 1109 | len = strlen (rdir); |
1078 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) | 1110 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) |
1079 | len--; | 1111 | len--; |
1080 | rdir[len] = '\0'; | 1112 | rdir[len] = '\0'; |
1081 | if (0 != ACCESS (rdir, F_OK)) | 1113 | if (0 != access (rdir, F_OK)) |
1082 | { | 1114 | { |
1083 | /* we get to create a directory -- and claim it | 1115 | /* we get to create a directory -- and claim it |
1084 | * as ours! */ | 1116 | * as ours! */ |
@@ -1086,7 +1118,7 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | |||
1086 | if ((NULL != user) && (0 < strlen (user))) | 1118 | if ((NULL != user) && (0 < strlen (user))) |
1087 | GNUNET_DISK_file_change_owner (rdir, user); | 1119 | GNUNET_DISK_file_change_owner (rdir, user); |
1088 | } | 1120 | } |
1089 | if (0 != ACCESS (rdir, W_OK | X_OK)) | 1121 | if (0 != access (rdir, W_OK | X_OK)) |
1090 | { | 1122 | { |
1091 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); | 1123 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "access", rdir); |
1092 | GNUNET_free (rdir); | 1124 | GNUNET_free (rdir); |
@@ -1095,7 +1127,7 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | |||
1095 | return GNUNET_SYSERR; | 1127 | return GNUNET_SYSERR; |
1096 | } | 1128 | } |
1097 | GNUNET_free (rdir); | 1129 | GNUNET_free (rdir); |
1098 | pidfd = FOPEN (pif, "w"); | 1130 | pidfd = fopen (pif, "w"); |
1099 | if (NULL == pidfd) | 1131 | if (NULL == pidfd) |
1100 | { | 1132 | { |
1101 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); | 1133 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "fopen", pif); |
@@ -1103,9 +1135,9 @@ write_pid_file (struct LEGACY_SERVICE_Context *sctx, pid_t pid) | |||
1103 | GNUNET_free_non_null (user); | 1135 | GNUNET_free_non_null (user); |
1104 | return GNUNET_SYSERR; | 1136 | return GNUNET_SYSERR; |
1105 | } | 1137 | } |
1106 | if (0 > FPRINTF (pidfd, "%u", pid)) | 1138 | if (0 > fprintf (pidfd, "%u", pid)) |
1107 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); | 1139 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "fprintf", pif); |
1108 | GNUNET_break (0 == FCLOSE (pidfd)); | 1140 | GNUNET_break (0 == fclose (pidfd)); |
1109 | if ((NULL != user) && (0 < strlen (user))) | 1141 | if ((NULL != user) && (0 < strlen (user))) |
1110 | GNUNET_DISK_file_change_owner (pif, user); | 1142 | GNUNET_DISK_file_change_owner (pif, user); |
1111 | GNUNET_free_non_null (user); | 1143 | GNUNET_free_non_null (user); |
@@ -1146,29 +1178,37 @@ service_task (void *cls) | |||
1146 | 1178 | ||
1147 | GNUNET_RESOLVER_connect (sctx->cfg); | 1179 | GNUNET_RESOLVER_connect (sctx->cfg); |
1148 | if (NULL != sctx->lsocks) | 1180 | if (NULL != sctx->lsocks) |
1149 | sctx->server | 1181 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, |
1150 | = GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, | 1182 | sctx, |
1151 | sctx->timeout, sctx->require_found); | 1183 | sctx->lsocks, |
1184 | sctx->timeout, | ||
1185 | sctx->require_found); | ||
1152 | else | 1186 | else |
1153 | sctx->server | 1187 | sctx->server = GNUNET_SERVER_create (&check_access, |
1154 | = GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, | 1188 | sctx, |
1155 | sctx->timeout, sctx->require_found); | 1189 | sctx->addrs, |
1190 | sctx->addrlens, | ||
1191 | sctx->timeout, | ||
1192 | sctx->require_found); | ||
1156 | if (NULL == sctx->server) | 1193 | if (NULL == sctx->server) |
1157 | { | 1194 | { |
1158 | if (NULL != sctx->addrs) | 1195 | if (NULL != sctx->addrs) |
1159 | for (i = 0; NULL != sctx->addrs[i]; i++) | 1196 | for (i = 0; NULL != sctx->addrs[i]; i++) |
1160 | LOG (GNUNET_ERROR_TYPE_INFO, | 1197 | LOG (GNUNET_ERROR_TYPE_INFO, |
1161 | _("Failed to start `%s' at `%s'\n"), | 1198 | _ ("Failed to start `%s' at `%s'\n"), |
1162 | sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | 1199 | sctx->service_name, |
1200 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | ||
1163 | sctx->ret = GNUNET_SYSERR; | 1201 | sctx->ret = GNUNET_SYSERR; |
1164 | return; | 1202 | return; |
1165 | } | 1203 | } |
1166 | #ifndef WINDOWS | 1204 | #ifndef WINDOWS |
1167 | if (NULL != sctx->addrs) | 1205 | if (NULL != sctx->addrs) |
1168 | for (i = 0; NULL != sctx->addrs[i]; i++) | 1206 | for (i = 0; NULL != sctx->addrs[i]; i++) |
1169 | if ((AF_UNIX == sctx->addrs[i]->sa_family) | 1207 | if ((AF_UNIX == sctx->addrs[i]->sa_family) && |
1170 | && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) | 1208 | ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) |
1171 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path, | 1209 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) |
1210 | sctx->addrs[i]) | ||
1211 | ->sun_path, | ||
1172 | sctx->match_uid, | 1212 | sctx->match_uid, |
1173 | sctx->match_gid); | 1213 | sctx->match_gid); |
1174 | #endif | 1214 | #endif |
@@ -1178,8 +1218,7 @@ service_task (void *cls) | |||
1178 | { | 1218 | { |
1179 | /* install a task that will kill the server | 1219 | /* install a task that will kill the server |
1180 | * process if the scheduler ever gets a shutdown signal */ | 1220 | * process if the scheduler ever gets a shutdown signal */ |
1181 | sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | 1221 | sctx->shutdown_task = GNUNET_SCHEDULER_add_shutdown (&shutdown_task, sctx); |
1182 | sctx); | ||
1183 | } | 1222 | } |
1184 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); | 1223 | sctx->my_handlers = GNUNET_malloc (sizeof (defhandlers)); |
1185 | GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); | 1224 | GNUNET_memcpy (sctx->my_handlers, defhandlers, sizeof (defhandlers)); |
@@ -1189,8 +1228,8 @@ service_task (void *cls) | |||
1189 | GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); | 1228 | GNUNET_SERVER_add_handlers (sctx->server, sctx->my_handlers); |
1190 | if (-1 != sctx->ready_confirm_fd) | 1229 | if (-1 != sctx->ready_confirm_fd) |
1191 | { | 1230 | { |
1192 | GNUNET_break (1 == WRITE (sctx->ready_confirm_fd, ".", 1)); | 1231 | GNUNET_break (1 == write (sctx->ready_confirm_fd, ".", 1)); |
1193 | GNUNET_break (0 == CLOSE (sctx->ready_confirm_fd)); | 1232 | GNUNET_break (0 == close (sctx->ready_confirm_fd)); |
1194 | sctx->ready_confirm_fd = -1; | 1233 | sctx->ready_confirm_fd = -1; |
1195 | write_pid_file (sctx, getpid ()); | 1234 | write_pid_file (sctx, getpid ()); |
1196 | } | 1235 | } |
@@ -1199,8 +1238,10 @@ service_task (void *cls) | |||
1199 | i = 0; | 1238 | i = 0; |
1200 | while (NULL != sctx->addrs[i]) | 1239 | while (NULL != sctx->addrs[i]) |
1201 | { | 1240 | { |
1202 | LOG (GNUNET_ERROR_TYPE_INFO, _("Service `%s' runs at %s\n"), | 1241 | LOG (GNUNET_ERROR_TYPE_INFO, |
1203 | sctx->service_name, GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | 1242 | _ ("Service `%s' runs at %s\n"), |
1243 | sctx->service_name, | ||
1244 | GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); | ||
1204 | i++; | 1245 | i++; |
1205 | } | 1246 | } |
1206 | } | 1247 | } |
@@ -1222,7 +1263,7 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx) | |||
1222 | int nullfd; | 1263 | int nullfd; |
1223 | int filedes[2]; | 1264 | int filedes[2]; |
1224 | 1265 | ||
1225 | if (0 != PIPE (filedes)) | 1266 | if (0 != pipe (filedes)) |
1226 | { | 1267 | { |
1227 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 1268 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "pipe"); |
1228 | return GNUNET_SYSERR; | 1269 | return GNUNET_SYSERR; |
@@ -1238,9 +1279,9 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx) | |||
1238 | /* Parent */ | 1279 | /* Parent */ |
1239 | char c; | 1280 | char c; |
1240 | 1281 | ||
1241 | GNUNET_break (0 == CLOSE (filedes[1])); | 1282 | GNUNET_break (0 == close (filedes[1])); |
1242 | c = 'X'; | 1283 | c = 'X'; |
1243 | if (1 != READ (filedes[0], &c, sizeof (char))) | 1284 | if (1 != read (filedes[0], &c, sizeof (char))) |
1244 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); | 1285 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "read"); |
1245 | fflush (stdout); | 1286 | fflush (stdout); |
1246 | switch (c) | 1287 | switch (c) |
@@ -1248,33 +1289,34 @@ detach_terminal (struct LEGACY_SERVICE_Context *sctx) | |||
1248 | case '.': | 1289 | case '.': |
1249 | exit (0); | 1290 | exit (0); |
1250 | case 'I': | 1291 | case 'I': |
1251 | LOG (GNUNET_ERROR_TYPE_INFO, _("Service process failed to initialize\n")); | 1292 | LOG (GNUNET_ERROR_TYPE_INFO, |
1293 | _ ("Service process failed to initialize\n")); | ||
1252 | break; | 1294 | break; |
1253 | case 'S': | 1295 | case 'S': |
1254 | LOG (GNUNET_ERROR_TYPE_INFO, | 1296 | LOG (GNUNET_ERROR_TYPE_INFO, |
1255 | _("Service process could not initialize server function\n")); | 1297 | _ ("Service process could not initialize server function\n")); |
1256 | break; | 1298 | break; |
1257 | case 'X': | 1299 | case 'X': |
1258 | LOG (GNUNET_ERROR_TYPE_INFO, | 1300 | LOG (GNUNET_ERROR_TYPE_INFO, |
1259 | _("Service process failed to report status\n")); | 1301 | _ ("Service process failed to report status\n")); |
1260 | break; | 1302 | break; |
1261 | } | 1303 | } |
1262 | exit (1); /* child reported error */ | 1304 | exit (1); /* child reported error */ |
1263 | } | 1305 | } |
1264 | GNUNET_break (0 == CLOSE (0)); | 1306 | GNUNET_break (0 == close (0)); |
1265 | GNUNET_break (0 == CLOSE (1)); | 1307 | GNUNET_break (0 == close (1)); |
1266 | GNUNET_break (0 == CLOSE (filedes[0])); | 1308 | GNUNET_break (0 == close (filedes[0])); |
1267 | nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND); | 1309 | nullfd = open ("/dev/null", O_RDWR | O_APPEND); |
1268 | if (nullfd < 0) | 1310 | if (nullfd < 0) |
1269 | return GNUNET_SYSERR; | 1311 | return GNUNET_SYSERR; |
1270 | /* set stdin/stdout to /dev/null */ | 1312 | /* set stdin/stdout to /dev/null */ |
1271 | if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) | 1313 | if ((dup2 (nullfd, 0) < 0) || (dup2 (nullfd, 1) < 0)) |
1272 | { | 1314 | { |
1273 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); | 1315 | LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "dup2"); |
1274 | (void) CLOSE (nullfd); | 1316 | (void) close (nullfd); |
1275 | return GNUNET_SYSERR; | 1317 | return GNUNET_SYSERR; |
1276 | } | 1318 | } |
1277 | (void) CLOSE (nullfd); | 1319 | (void) close (nullfd); |
1278 | /* Detach from controlling terminal */ | 1320 | /* Detach from controlling terminal */ |
1279 | pid = setsid (); | 1321 | pid = setsid (); |
1280 | if (-1 == pid) | 1322 | if (-1 == pid) |
@@ -1301,7 +1343,7 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx) | |||
1301 | char *user; | 1343 | char *user; |
1302 | 1344 | ||
1303 | if (NULL == (user = get_user_name (sctx))) | 1345 | if (NULL == (user = get_user_name (sctx))) |
1304 | return GNUNET_OK; /* keep */ | 1346 | return GNUNET_OK; /* keep */ |
1305 | #ifndef MINGW | 1347 | #ifndef MINGW |
1306 | struct passwd *pws; | 1348 | struct passwd *pws; |
1307 | 1349 | ||
@@ -1310,8 +1352,9 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx) | |||
1310 | if (NULL == pws) | 1352 | if (NULL == pws) |
1311 | { | 1353 | { |
1312 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1354 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1313 | _("Cannot obtain information about user `%s': %s\n"), user, | 1355 | _ ("Cannot obtain information about user `%s': %s\n"), |
1314 | errno == 0 ? _("No such user") : STRERROR (errno)); | 1356 | user, |
1357 | errno == 0 ? _ ("No such user") : strerror (errno)); | ||
1315 | GNUNET_free (user); | 1358 | GNUNET_free (user); |
1316 | return GNUNET_SYSERR; | 1359 | return GNUNET_SYSERR; |
1317 | } | 1360 | } |
@@ -1324,8 +1367,10 @@ set_user_id (struct LEGACY_SERVICE_Context *sctx) | |||
1324 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || | 1367 | if ((0 != setregid (pws->pw_gid, pws->pw_gid)) || |
1325 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) | 1368 | (0 != setreuid (pws->pw_uid, pws->pw_uid))) |
1326 | { | 1369 | { |
1327 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Cannot change user/group to `%s': %s\n"), | 1370 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1328 | user, STRERROR (errno)); | 1371 | _ ("Cannot change user/group to `%s': %s\n"), |
1372 | user, | ||
1373 | strerror (errno)); | ||
1329 | GNUNET_free (user); | 1374 | GNUNET_free (user); |
1330 | return GNUNET_SYSERR; | 1375 | return GNUNET_SYSERR; |
1331 | } | 1376 | } |
@@ -1347,8 +1392,8 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx) | |||
1347 | char *pif = get_pid_file_name (sctx); | 1392 | char *pif = get_pid_file_name (sctx); |
1348 | 1393 | ||
1349 | if (NULL == pif) | 1394 | if (NULL == pif) |
1350 | return; /* no PID file */ | 1395 | return; /* no PID file */ |
1351 | if (0 != UNLINK (pif)) | 1396 | if (0 != unlink (pif)) |
1352 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); | 1397 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", pif); |
1353 | GNUNET_free (pif); | 1398 | GNUNET_free (pif); |
1354 | } | 1399 | } |
@@ -1368,13 +1413,19 @@ pid_file_delete (struct LEGACY_SERVICE_Context *sctx) | |||
1368 | * if we shutdown nicely | 1413 | * if we shutdown nicely |
1369 | */ | 1414 | */ |
1370 | int | 1415 | int |
1371 | LEGACY_SERVICE_run (int argc, char *const *argv, | 1416 | LEGACY_SERVICE_run (int argc, |
1417 | char *const *argv, | ||
1372 | const char *service_name, | 1418 | const char *service_name, |
1373 | enum LEGACY_SERVICE_Options options, | 1419 | enum LEGACY_SERVICE_Options options, |
1374 | LEGACY_SERVICE_Main task, | 1420 | LEGACY_SERVICE_Main task, |
1375 | void *task_cls) | 1421 | void *task_cls) |
1376 | { | 1422 | { |
1377 | #define HANDLE_ERROR do { GNUNET_break (0); goto shutdown; } while (0) | 1423 | #define HANDLE_ERROR \ |
1424 | do \ | ||
1425 | { \ | ||
1426 | GNUNET_break (0); \ | ||
1427 | goto shutdown; \ | ||
1428 | } while (0) | ||
1378 | 1429 | ||
1379 | int err; | 1430 | int err; |
1380 | int ret; | 1431 | int ret; |
@@ -1391,18 +1442,18 @@ LEGACY_SERVICE_run (int argc, char *const *argv, | |||
1391 | struct GNUNET_CONFIGURATION_Handle *cfg; | 1442 | struct GNUNET_CONFIGURATION_Handle *cfg; |
1392 | const char *xdg; | 1443 | const char *xdg; |
1393 | 1444 | ||
1394 | struct GNUNET_GETOPT_CommandLineOption service_options[] = { | 1445 | struct GNUNET_GETOPT_CommandLineOption service_options[] = |
1395 | GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn), | 1446 | {GNUNET_GETOPT_option_cfgfile (&opt_cfg_fn), |
1396 | GNUNET_GETOPT_option_flag ('d', | 1447 | GNUNET_GETOPT_option_flag ('d', |
1397 | "daemonize", | 1448 | "daemonize", |
1398 | gettext_noop ("do daemonize (detach from terminal)"), | 1449 | gettext_noop ( |
1399 | &do_daemonize), | 1450 | "do daemonize (detach from terminal)"), |
1400 | GNUNET_GETOPT_option_help (NULL), | 1451 | &do_daemonize), |
1401 | GNUNET_GETOPT_option_loglevel (&loglev), | 1452 | GNUNET_GETOPT_option_help (NULL), |
1402 | GNUNET_GETOPT_option_logfile (&logfile), | 1453 | GNUNET_GETOPT_option_loglevel (&loglev), |
1403 | GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), | 1454 | GNUNET_GETOPT_option_logfile (&logfile), |
1404 | GNUNET_GETOPT_OPTION_END | 1455 | GNUNET_GETOPT_option_version (PACKAGE_VERSION " " VCS_VERSION), |
1405 | }; | 1456 | GNUNET_GETOPT_OPTION_END}; |
1406 | err = 1; | 1457 | err = 1; |
1407 | do_daemonize = 0; | 1458 | do_daemonize = 0; |
1408 | logfile = NULL; | 1459 | logfile = NULL; |
@@ -1445,7 +1496,7 @@ LEGACY_SERVICE_run (int argc, char *const *argv, | |||
1445 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) | 1496 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, opt_cfg_fn)) |
1446 | { | 1497 | { |
1447 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1498 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1448 | _("Malformed configuration file `%s', exit ...\n"), | 1499 | _ ("Malformed configuration file `%s', exit ...\n"), |
1449 | opt_cfg_fn); | 1500 | opt_cfg_fn); |
1450 | goto shutdown; | 1501 | goto shutdown; |
1451 | } | 1502 | } |
@@ -1455,13 +1506,13 @@ LEGACY_SERVICE_run (int argc, char *const *argv, | |||
1455 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) | 1506 | if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, NULL)) |
1456 | { | 1507 | { |
1457 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1508 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1458 | _("Malformed configuration, exit ...\n")); | 1509 | _ ("Malformed configuration, exit ...\n")); |
1459 | goto shutdown; | 1510 | goto shutdown; |
1460 | } | 1511 | } |
1461 | if (0 != strcmp (opt_cfg_fn, cfg_fn)) | 1512 | if (0 != strcmp (opt_cfg_fn, cfg_fn)) |
1462 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1513 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1463 | _("Could not access configuration file `%s'\n"), | 1514 | _ ("Could not access configuration file `%s'\n"), |
1464 | opt_cfg_fn); | 1515 | opt_cfg_fn); |
1465 | } | 1516 | } |
1466 | if (GNUNET_OK != setup_service (&sctx)) | 1517 | if (GNUNET_OK != setup_service (&sctx)) |
1467 | goto shutdown; | 1518 | goto shutdown; |
@@ -1473,12 +1524,14 @@ LEGACY_SERVICE_run (int argc, char *const *argv, | |||
1473 | "Service `%s' runs with configuration from `%s'\n", | 1524 | "Service `%s' runs with configuration from `%s'\n", |
1474 | service_name, | 1525 | service_name, |
1475 | opt_cfg_fn); | 1526 | opt_cfg_fn); |
1476 | if ((GNUNET_OK == | 1527 | if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, |
1477 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", | 1528 | "TESTING", |
1478 | "SKEW_OFFSET", &skew_offset)) && | 1529 | "SKEW_OFFSET", |
1479 | (GNUNET_OK == | 1530 | &skew_offset)) && |
1480 | GNUNET_CONFIGURATION_get_value_number (sctx.cfg, "TESTING", | 1531 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (sctx.cfg, |
1481 | "SKEW_VARIANCE", &skew_variance))) | 1532 | "TESTING", |
1533 | "SKEW_VARIANCE", | ||
1534 | &skew_variance))) | ||
1482 | { | 1535 | { |
1483 | clock_offset = skew_offset - skew_variance; | 1536 | clock_offset = skew_offset - skew_variance; |
1484 | GNUNET_TIME_set_offset (clock_offset); | 1537 | GNUNET_TIME_set_offset (clock_offset); |
@@ -1495,21 +1548,21 @@ LEGACY_SERVICE_run (int argc, char *const *argv, | |||
1495 | shutdown: | 1548 | shutdown: |
1496 | if (-1 != sctx.ready_confirm_fd) | 1549 | if (-1 != sctx.ready_confirm_fd) |
1497 | { | 1550 | { |
1498 | if (1 != WRITE (sctx.ready_confirm_fd, err ? "I" : "S", 1)) | 1551 | if (1 != write (sctx.ready_confirm_fd, err ? "I" : "S", 1)) |
1499 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); | 1552 | LOG_STRERROR (GNUNET_ERROR_TYPE_WARNING, "write"); |
1500 | GNUNET_break (0 == CLOSE (sctx.ready_confirm_fd)); | 1553 | GNUNET_break (0 == close (sctx.ready_confirm_fd)); |
1501 | } | 1554 | } |
1502 | #if HAVE_MALLINFO | 1555 | #if HAVE_MALLINFO |
1503 | { | 1556 | { |
1504 | char *counter; | 1557 | char *counter; |
1505 | 1558 | ||
1506 | if ( (GNUNET_YES == | 1559 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx.cfg, |
1507 | GNUNET_CONFIGURATION_have_value (sctx.cfg, service_name, | 1560 | service_name, |
1508 | "GAUGER_HEAP")) && | 1561 | "GAUGER_HEAP")) && |
1509 | (GNUNET_OK == | 1562 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx.cfg, |
1510 | GNUNET_CONFIGURATION_get_value_string (sctx.cfg, service_name, | 1563 | service_name, |
1511 | "GAUGER_HEAP", | 1564 | "GAUGER_HEAP", |
1512 | &counter)) ) | 1565 | &counter))) |
1513 | { | 1566 | { |
1514 | struct mallinfo mi; | 1567 | struct mallinfo mi; |
1515 | 1568 | ||
@@ -1551,13 +1604,13 @@ shutdown: | |||
1551 | struct LEGACY_SERVICE_Context * | 1604 | struct LEGACY_SERVICE_Context * |
1552 | LEGACY_SERVICE_start (const char *service_name, | 1605 | LEGACY_SERVICE_start (const char *service_name, |
1553 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1606 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1554 | enum LEGACY_SERVICE_Options options) | 1607 | enum LEGACY_SERVICE_Options options) |
1555 | { | 1608 | { |
1556 | int i; | 1609 | int i; |
1557 | struct LEGACY_SERVICE_Context *sctx; | 1610 | struct LEGACY_SERVICE_Context *sctx; |
1558 | 1611 | ||
1559 | sctx = GNUNET_new (struct LEGACY_SERVICE_Context); | 1612 | sctx = GNUNET_new (struct LEGACY_SERVICE_Context); |
1560 | sctx->ready_confirm_fd = -1; /* no daemonizing */ | 1613 | sctx->ready_confirm_fd = -1; /* no daemonizing */ |
1561 | sctx->ret = GNUNET_OK; | 1614 | sctx->ret = GNUNET_OK; |
1562 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; | 1615 | sctx->timeout = GNUNET_TIME_UNIT_FOREVER_REL; |
1563 | sctx->service_name = service_name; | 1616 | sctx->service_name = service_name; |
@@ -1571,13 +1624,18 @@ LEGACY_SERVICE_start (const char *service_name, | |||
1571 | return NULL; | 1624 | return NULL; |
1572 | } | 1625 | } |
1573 | if (NULL != sctx->lsocks) | 1626 | if (NULL != sctx->lsocks) |
1574 | sctx->server = | 1627 | sctx->server = GNUNET_SERVER_create_with_sockets (&check_access, |
1575 | GNUNET_SERVER_create_with_sockets (&check_access, sctx, sctx->lsocks, | 1628 | sctx, |
1576 | sctx->timeout, sctx->require_found); | 1629 | sctx->lsocks, |
1630 | sctx->timeout, | ||
1631 | sctx->require_found); | ||
1577 | else | 1632 | else |
1578 | sctx->server = | 1633 | sctx->server = GNUNET_SERVER_create (&check_access, |
1579 | GNUNET_SERVER_create (&check_access, sctx, sctx->addrs, sctx->addrlens, | 1634 | sctx, |
1580 | sctx->timeout, sctx->require_found); | 1635 | sctx->addrs, |
1636 | sctx->addrlens, | ||
1637 | sctx->timeout, | ||
1638 | sctx->require_found); | ||
1581 | 1639 | ||
1582 | if (NULL == sctx->server) | 1640 | if (NULL == sctx->server) |
1583 | { | 1641 | { |
@@ -1587,9 +1645,11 @@ LEGACY_SERVICE_start (const char *service_name, | |||
1587 | #ifndef WINDOWS | 1645 | #ifndef WINDOWS |
1588 | if (NULL != sctx->addrs) | 1646 | if (NULL != sctx->addrs) |
1589 | for (i = 0; NULL != sctx->addrs[i]; i++) | 1647 | for (i = 0; NULL != sctx->addrs[i]; i++) |
1590 | if ((AF_UNIX == sctx->addrs[i]->sa_family) | 1648 | if ((AF_UNIX == sctx->addrs[i]->sa_family) && |
1591 | && ('\0' != ((const struct sockaddr_un *)sctx->addrs[i])->sun_path[0])) | 1649 | ('\0' != ((const struct sockaddr_un *) sctx->addrs[i])->sun_path[0])) |
1592 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *)sctx->addrs[i])->sun_path, | 1650 | GNUNET_DISK_fix_permissions (((const struct sockaddr_un *) |
1651 | sctx->addrs[i]) | ||
1652 | ->sun_path, | ||
1593 | sctx->match_uid, | 1653 | sctx->match_uid, |
1594 | sctx->match_gid); | 1654 | sctx->match_gid); |
1595 | #endif | 1655 | #endif |
@@ -1624,7 +1684,7 @@ LEGACY_SERVICE_get_server (struct LEGACY_SERVICE_Context *ctx) | |||
1624 | * @return NULL if there are no listen sockets, otherwise NULL-terminated | 1684 | * @return NULL if there are no listen sockets, otherwise NULL-terminated |
1625 | * array of listen sockets. | 1685 | * array of listen sockets. |
1626 | */ | 1686 | */ |
1627 | struct GNUNET_NETWORK_Handle *const* | 1687 | struct GNUNET_NETWORK_Handle *const * |
1628 | LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) | 1688 | LEGACY_SERVICE_get_listen_sockets (struct LEGACY_SERVICE_Context *ctx) |
1629 | { | 1689 | { |
1630 | return ctx->lsocks; | 1690 | return ctx->lsocks; |
@@ -1645,13 +1705,13 @@ LEGACY_SERVICE_stop (struct LEGACY_SERVICE_Context *sctx) | |||
1645 | { | 1705 | { |
1646 | char *counter; | 1706 | char *counter; |
1647 | 1707 | ||
1648 | if ( (GNUNET_YES == | 1708 | if ((GNUNET_YES == GNUNET_CONFIGURATION_have_value (sctx->cfg, |
1649 | GNUNET_CONFIGURATION_have_value (sctx->cfg, sctx->service_name, | 1709 | sctx->service_name, |
1650 | "GAUGER_HEAP")) && | 1710 | "GAUGER_HEAP")) && |
1651 | (GNUNET_OK == | 1711 | (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (sctx->cfg, |
1652 | GNUNET_CONFIGURATION_get_value_string (sctx->cfg, sctx->service_name, | 1712 | sctx->service_name, |
1653 | "GAUGER_HEAP", | 1713 | "GAUGER_HEAP", |
1654 | &counter)) ) | 1714 | &counter))) |
1655 | { | 1715 | { |
1656 | struct mallinfo mi; | 1716 | struct mallinfo mi; |
1657 | 1717 | ||
diff --git a/src/transport/test_plugin_hostkey b/src/transport/test_plugin_hostkey index 13f1dc9b3..e7b1ad012 100644 --- a/src/transport/test_plugin_hostkey +++ b/src/transport/test_plugin_hostkey | |||
Binary files differ | |||
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c index 0c94fa5c9..2c6ce8e5f 100644 --- a/src/transport/test_quota_compliance.c +++ b/src/transport/test_quota_compliance.c | |||
@@ -71,7 +71,7 @@ report () | |||
71 | delta = 1; | 71 | delta = 1; |
72 | datarate = (total_bytes_recv * 1000 * 1000) / delta; | 72 | datarate = (total_bytes_recv * 1000 * 1000) / delta; |
73 | 73 | ||
74 | FPRINTF (stderr, | 74 | fprintf (stderr, |
75 | "Throughput was %llu b/s\n", | 75 | "Throughput was %llu b/s\n", |
76 | datarate); | 76 | datarate); |
77 | ccc->global_ret = GNUNET_OK; | 77 | ccc->global_ret = GNUNET_OK; |
@@ -160,11 +160,11 @@ measure (void *cls) | |||
160 | counter++; | 160 | counter++; |
161 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) | 161 | if ((DURATION.rel_value_us / 1000 / 1000LL) < counter) |
162 | { | 162 | { |
163 | FPRINTF (stderr, "%s", ".\n"); | 163 | fprintf (stderr, "%s", ".\n"); |
164 | GNUNET_SCHEDULER_shutdown (); | 164 | GNUNET_SCHEDULER_shutdown (); |
165 | return; | 165 | return; |
166 | } | 166 | } |
167 | FPRINTF (stderr, "%s", "."); | 167 | fprintf (stderr, "%s", "."); |
168 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 168 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
169 | &measure, | 169 | &measure, |
170 | NULL); | 170 | NULL); |
diff --git a/src/transport/test_transport_address_switch.c b/src/transport/test_transport_address_switch.c index 98f1170ff..4cc63766e 100644 --- a/src/transport/test_transport_address_switch.c +++ b/src/transport/test_transport_address_switch.c | |||
@@ -217,10 +217,10 @@ custom_shutdown (void *cls) | |||
217 | } | 217 | } |
218 | 218 | ||
219 | result = 0; | 219 | result = 0; |
220 | FPRINTF (stderr, "\n"); | 220 | fprintf (stderr, "\n"); |
221 | if (stats[0].switch_attempts > 0) | 221 | if (stats[0].switch_attempts > 0) |
222 | { | 222 | { |
223 | FPRINTF ( | 223 | fprintf ( |
224 | stderr, | 224 | stderr, |
225 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", | 225 | "Peer 1 tried %u times to switch and succeeded %u times, failed %u times\n", |
226 | stats[0].switch_attempts, | 226 | stats[0].switch_attempts, |
@@ -234,13 +234,13 @@ custom_shutdown (void *cls) | |||
234 | } | 234 | } |
235 | else if (stats[0].addresses_avail > 1) | 235 | else if (stats[0].addresses_avail > 1) |
236 | { | 236 | { |
237 | FPRINTF (stderr, | 237 | fprintf (stderr, |
238 | "Peer 1 had %u addresses available, but did not try to switch\n", | 238 | "Peer 1 had %u addresses available, but did not try to switch\n", |
239 | stats[0].addresses_avail); | 239 | stats[0].addresses_avail); |
240 | } | 240 | } |
241 | if (stats[1].switch_attempts > 0) | 241 | if (stats[1].switch_attempts > 0) |
242 | { | 242 | { |
243 | FPRINTF ( | 243 | fprintf ( |
244 | stderr, | 244 | stderr, |
245 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", | 245 | "Peer 2 tried %u times to switch and succeeded %u times, failed %u times\n", |
246 | stats[1].switch_attempts, | 246 | stats[1].switch_attempts, |
@@ -254,7 +254,7 @@ custom_shutdown (void *cls) | |||
254 | } | 254 | } |
255 | else if (stats[1].addresses_avail > 1) | 255 | else if (stats[1].addresses_avail > 1) |
256 | { | 256 | { |
257 | FPRINTF (stderr, | 257 | fprintf (stderr, |
258 | "Peer 2 had %u addresses available, but did not try to switch\n", | 258 | "Peer 2 had %u addresses available, but did not try to switch\n", |
259 | stats[1].addresses_avail); | 259 | stats[1].addresses_avail); |
260 | } | 260 | } |
@@ -262,14 +262,14 @@ custom_shutdown (void *cls) | |||
262 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && | 262 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
263 | (bytes_sent_after_switch == 0)) | 263 | (bytes_sent_after_switch == 0)) |
264 | { | 264 | { |
265 | FPRINTF (stderr, "No data sent after switching!\n"); | 265 | fprintf (stderr, "No data sent after switching!\n"); |
266 | GNUNET_break (0); | 266 | GNUNET_break (0); |
267 | result++; | 267 | result++; |
268 | } | 268 | } |
269 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && | 269 | if (((stats[0].switch_attempts > 0) || (stats[1].switch_attempts > 0)) && |
270 | (bytes_recv_after_switch == 0)) | 270 | (bytes_recv_after_switch == 0)) |
271 | { | 271 | { |
272 | FPRINTF (stderr, "No data received after switching!\n"); | 272 | fprintf (stderr, "No data received after switching!\n"); |
273 | GNUNET_break (0); | 273 | GNUNET_break (0); |
274 | result++; | 274 | result++; |
275 | } | 275 | } |
@@ -353,11 +353,11 @@ progress_indicator (void *cls) | |||
353 | counter++; | 353 | counter++; |
354 | if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) | 354 | if ((TIMEOUT.rel_value_us / 1000 / 1000LL) < counter) |
355 | { | 355 | { |
356 | FPRINTF (stderr, "%s", ".\n"); | 356 | fprintf (stderr, "%s", ".\n"); |
357 | } | 357 | } |
358 | else | 358 | else |
359 | { | 359 | { |
360 | FPRINTF (stderr, "%s", "."); | 360 | fprintf (stderr, "%s", "."); |
361 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 361 | measure_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
362 | &progress_indicator, | 362 | &progress_indicator, |
363 | NULL); | 363 | NULL); |
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c index 8442b92e8..a26a92880 100644 --- a/src/transport/test_transport_api_reliability.c +++ b/src/transport/test_transport_api_reliability.c | |||
@@ -179,7 +179,7 @@ custom_shutdown (void *cls) | |||
179 | if (0 == delta) | 179 | if (0 == delta) |
180 | delta = 1; | 180 | delta = 1; |
181 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); | 181 | rate = (1000LL* 1000ll * total_bytes) / (1024 * delta); |
182 | FPRINTF (stderr, | 182 | fprintf (stderr, |
183 | "\nThroughput was %llu KiBytes/s\n", | 183 | "\nThroughput was %llu KiBytes/s\n", |
184 | rate); | 184 | rate); |
185 | { | 185 | { |
@@ -274,7 +274,7 @@ notify_receive (void *cls, | |||
274 | } | 274 | } |
275 | if (0 == (n % (TOTAL_MSGS / xhdr / 100))) | 275 | if (0 == (n % (TOTAL_MSGS / xhdr / 100))) |
276 | { | 276 | { |
277 | FPRINTF (stderr, "%s", "."); | 277 | fprintf (stderr, "%s", "."); |
278 | } | 278 | } |
279 | if (n == TOTAL_MSGS / xhdr) | 279 | if (n == TOTAL_MSGS / xhdr) |
280 | { | 280 | { |
diff --git a/src/transport/test_transport_api_timeout.c b/src/transport/test_transport_api_timeout.c index a00e0aeb6..f562dd196 100644 --- a/src/transport/test_transport_api_timeout.c +++ b/src/transport/test_transport_api_timeout.c | |||
@@ -120,13 +120,13 @@ timer (void *cls) | |||
120 | if (time_running.rel_value_us == | 120 | if (time_running.rel_value_us == |
121 | GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us) | 121 | GNUNET_TIME_relative_max (time_running, WAIT).rel_value_us) |
122 | { | 122 | { |
123 | FPRINTF (stderr, "%s", "100%%\n"); | 123 | fprintf (stderr, "%s", "100%%\n"); |
124 | shutdown_flag = GNUNET_YES; | 124 | shutdown_flag = GNUNET_YES; |
125 | GNUNET_SCHEDULER_shutdown (); | 125 | GNUNET_SCHEDULER_shutdown (); |
126 | } | 126 | } |
127 | else | 127 | else |
128 | { | 128 | { |
129 | FPRINTF (stderr, | 129 | fprintf (stderr, |
130 | "%u%%..", | 130 | "%u%%..", |
131 | percentage); | 131 | percentage); |
132 | timer_task = | 132 | timer_task = |
diff --git a/src/transport/test_transport_blacklisting.c b/src/transport/test_transport_blacklisting.c index 1cd244115..0ecd6fda1 100644 --- a/src/transport/test_transport_blacklisting.c +++ b/src/transport/test_transport_blacklisting.c | |||
@@ -80,7 +80,7 @@ static struct GNUNET_SCHEDULER_Task * timeout_task; | |||
80 | static struct GNUNET_SCHEDULER_Task * stage_task; | 80 | static struct GNUNET_SCHEDULER_Task * stage_task; |
81 | 81 | ||
82 | #if VERBOSE | 82 | #if VERBOSE |
83 | #define OKPP do { ok++; FPRINTF (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 83 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
84 | #else | 84 | #else |
85 | #define OKPP do { ok++; } while (0) | 85 | #define OKPP do { ok++; } while (0) |
86 | #endif | 86 | #endif |