summaryrefslogtreecommitdiff
path: root/src/transport/tcp_server_legacy.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/tcp_server_legacy.c')
-rw-r--r--src/transport/tcp_server_legacy.c1256
1 files changed, 637 insertions, 619 deletions
diff --git a/src/transport/tcp_server_legacy.c b/src/transport/tcp_server_legacy.c
index f2d5386ff..1a1d493cd 100644
--- a/src/transport/tcp_server_legacy.c
+++ b/src/transport/tcp_server_legacy.c
@@ -28,13 +28,18 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_protocols.h" 29#include "gnunet_protocols.h"
30 30
31#define LOG_STRERROR_FILE(kind, syscall, filename) GNUNET_log_from_strerror_file(kind, "util-server", syscall, filename) 31#define LOG_STRERROR_FILE(kind, syscall, \
32 filename) GNUNET_log_from_strerror_file (kind, \
33 "util-server", \
34 syscall, \
35 filename)
32 36
33 37
34/** 38/**
35 * List of arrays of message handlers. 39 * List of arrays of message handlers.
36 */ 40 */
37struct HandlerList { 41struct HandlerList
42{
38 /** 43 /**
39 * This is a linked list. 44 * This is a linked list.
40 */ 45 */
@@ -50,7 +55,8 @@ struct HandlerList {
50/** 55/**
51 * List of arrays of message handlers. 56 * List of arrays of message handlers.
52 */ 57 */
53struct NotifyList { 58struct NotifyList
59{
54 /** 60 /**
55 * This is a doubly linked list. 61 * This is a doubly linked list.
56 */ 62 */
@@ -76,7 +82,8 @@ struct NotifyList {
76/** 82/**
77 * @brief handle for a server 83 * @brief handle for a server
78 */ 84 */
79struct GNUNET_SERVER_Handle { 85struct GNUNET_SERVER_Handle
86{
80 /** 87 /**
81 * List of handlers for incoming messages. 88 * List of handlers for incoming messages.
82 */ 89 */
@@ -137,7 +144,7 @@ struct GNUNET_SERVER_Handle {
137 /** 144 /**
138 * Task scheduled to do the listening. 145 * Task scheduled to do the listening.
139 */ 146 */
140 struct GNUNET_SCHEDULER_Task * listen_task; 147 struct GNUNET_SCHEDULER_Task *listen_task;
141 148
142 /** 149 /**
143 * Alternative function to create a MST instance. 150 * Alternative function to create a MST instance.
@@ -179,7 +186,8 @@ struct GNUNET_SERVER_Handle {
179/** 186/**
180 * Handle server returns for aborting transmission to a client. 187 * Handle server returns for aborting transmission to a client.
181 */ 188 */
182struct GNUNET_SERVER_TransmitHandle { 189struct GNUNET_SERVER_TransmitHandle
190{
183 /** 191 /**
184 * Function to call to get the message. 192 * Function to call to get the message.
185 */ 193 */
@@ -200,7 +208,8 @@ struct GNUNET_SERVER_TransmitHandle {
200/** 208/**
201 * @brief handle for a client of the server 209 * @brief handle for a client of the server
202 */ 210 */
203struct GNUNET_SERVER_Client { 211struct GNUNET_SERVER_Client
212{
204 /** 213 /**
205 * This is a doubly linked list. 214 * This is a doubly linked list.
206 */ 215 */
@@ -235,12 +244,12 @@ struct GNUNET_SERVER_Client {
235 /** 244 /**
236 * ID of task used to restart processing. 245 * ID of task used to restart processing.
237 */ 246 */
238 struct GNUNET_SCHEDULER_Task * restart_task; 247 struct GNUNET_SCHEDULER_Task *restart_task;
239 248
240 /** 249 /**
241 * Task that warns about missing calls to #GNUNET_SERVER_receive_done. 250 * Task that warns about missing calls to #GNUNET_SERVER_receive_done.
242 */ 251 */
243 struct GNUNET_SCHEDULER_Task * warn_task; 252 struct GNUNET_SCHEDULER_Task *warn_task;
244 253
245 /** 254 /**
246 * Time when the warn task was started. 255 * Time when the warn task was started.
@@ -338,13 +347,13 @@ struct GNUNET_SERVER_Client {
338 * @return pointer to user context 347 * @return pointer to user context
339 */ 348 */
340void * 349void *
341GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client, 350GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client,
342 size_t size) 351 size_t size)
343{ 352{
344 if ((0 == client->user_context_size) && 353 if ((0 == client->user_context_size) &&
345 (NULL == client->user_context)) 354 (NULL == client->user_context))
346 return NULL; /* never set */ 355 return NULL; /* never set */
347 GNUNET_assert(size == client->user_context_size); 356 GNUNET_assert (size == client->user_context_size);
348 return client->user_context; 357 return client->user_context;
349} 358}
350 359
@@ -358,16 +367,16 @@ GNUNET_SERVER_client_get_user_context_(struct GNUNET_SERVER_Client *client,
358 * @param size number of bytes in user context struct (for verification only) 367 * @param size number of bytes in user context struct (for verification only)
359 */ 368 */
360void 369void
361GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client, 370GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client,
362 void *ptr, 371 void *ptr,
363 size_t size) 372 size_t size)
364{ 373{
365 if (NULL == ptr) 374 if (NULL == ptr)
366 { 375 {
367 client->user_context_size = 0; 376 client->user_context_size = 0;
368 client->user_context = ptr; 377 client->user_context = ptr;
369 return; 378 return;
370 } 379 }
371 client->user_context_size = size; 380 client->user_context_size = size;
372 client->user_context = ptr; 381 client->user_context = ptr;
373} 382}
@@ -380,7 +389,7 @@ GNUNET_SERVER_client_set_user_context_(struct GNUNET_SERVER_Client *client,
380 * socket 389 * socket
381 */ 390 */
382static void 391static void
383process_listen_socket(void *cls) 392process_listen_socket (void *cls)
384{ 393{
385 struct GNUNET_SERVER_Handle *server = cls; 394 struct GNUNET_SERVER_Handle *server = cls;
386 const struct GNUNET_SCHEDULER_TaskContext *tc; 395 const struct GNUNET_SCHEDULER_TaskContext *tc;
@@ -388,27 +397,27 @@ process_listen_socket(void *cls)
388 unsigned int i; 397 unsigned int i;
389 398
390 server->listen_task = NULL; 399 server->listen_task = NULL;
391 tc = GNUNET_SCHEDULER_get_task_context(); 400 tc = GNUNET_SCHEDULER_get_task_context ();
392 for (i = 0; NULL != server->listen_sockets[i]; i++) 401 for (i = 0; NULL != server->listen_sockets[i]; i++)
402 {
403 if (GNUNET_NETWORK_fdset_isset (tc->read_ready,
404 server->listen_sockets[i]))
393 { 405 {
394 if (GNUNET_NETWORK_fdset_isset(tc->read_ready, 406 sock =
395 server->listen_sockets[i])) 407 GNUNET_CONNECTION_create_from_accept (server->access_cb,
396 { 408 server->access_cb_cls,
397 sock = 409 server->listen_sockets[i]);
398 GNUNET_CONNECTION_create_from_accept(server->access_cb, 410 if (NULL != sock)
399 server->access_cb_cls, 411 {
400 server->listen_sockets[i]); 412 LOG (GNUNET_ERROR_TYPE_DEBUG,
401 if (NULL != sock) 413 "Server accepted incoming connection.\n");
402 { 414 (void) GNUNET_SERVER_connect_socket (server,
403 LOG(GNUNET_ERROR_TYPE_DEBUG, 415 sock);
404 "Server accepted incoming connection.\n"); 416 }
405 (void)GNUNET_SERVER_connect_socket(server,
406 sock);
407 }
408 }
409 } 417 }
418 }
410 /* listen for more! */ 419 /* listen for more! */
411 GNUNET_SERVER_resume(server); 420 GNUNET_SERVER_resume (server);
412} 421}
413 422
414 423
@@ -420,90 +429,90 @@ process_listen_socket(void *cls)
420 * @return NULL on error, otherwise the listen socket 429 * @return NULL on error, otherwise the listen socket
421 */ 430 */
422static struct GNUNET_NETWORK_Handle * 431static struct GNUNET_NETWORK_Handle *
423open_listen_socket(const struct sockaddr *server_addr, 432open_listen_socket (const struct sockaddr *server_addr,
424 socklen_t socklen) 433 socklen_t socklen)
425{ 434{
426 struct GNUNET_NETWORK_Handle *sock; 435 struct GNUNET_NETWORK_Handle *sock;
427 uint16_t port; 436 uint16_t port;
428 int eno; 437 int eno;
429 438
430 switch (server_addr->sa_family) 439 switch (server_addr->sa_family)
431 { 440 {
432 case AF_INET: 441 case AF_INET:
433 port = ntohs(((const struct sockaddr_in *)server_addr)->sin_port); 442 port = ntohs (((const struct sockaddr_in *) server_addr)->sin_port);
434 break; 443 break;
435 444
436 case AF_INET6: 445 case AF_INET6:
437 port = ntohs(((const struct sockaddr_in6 *)server_addr)->sin6_port); 446 port = ntohs (((const struct sockaddr_in6 *) server_addr)->sin6_port);
438 break; 447 break;
439 448
440 case AF_UNIX: 449 case AF_UNIX:
441 port = 0; 450 port = 0;
442 break; 451 break;
443 452
444 default: 453 default:
445 GNUNET_break(0); 454 GNUNET_break (0);
446 port = 0; 455 port = 0;
447 break; 456 break;
448 } 457 }
449 sock = GNUNET_NETWORK_socket_create(server_addr->sa_family, SOCK_STREAM, 0); 458 sock = GNUNET_NETWORK_socket_create (server_addr->sa_family, SOCK_STREAM, 0);
450 if (NULL == sock) 459 if (NULL == sock)
451 { 460 {
452 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "socket"); 461 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "socket");
453 errno = 0; 462 errno = 0;
454 return NULL; 463 return NULL;
455 } 464 }
456 /* bind the socket */ 465 /* bind the socket */
457 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(sock, server_addr, socklen)) 466 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, server_addr, socklen))
467 {
468 eno = errno;
469 if (EADDRINUSE != errno)
458 { 470 {
459 eno = errno; 471 /* we don't log 'EADDRINUSE' here since an IPv4 bind may
460 if (EADDRINUSE != errno) 472 * fail if we already took the port on IPv6; if both IPv4 and
461 { 473 * IPv6 binds fail, then our caller will log using the
462 /* we don't log 'EADDRINUSE' here since an IPv4 bind may 474 * errno preserved in 'eno' */
463 * fail if we already took the port on IPv6; if both IPv4 and 475 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
464 * IPv6 binds fail, then our caller will log using the 476 "bind");
465 * errno preserved in 'eno' */ 477 if (0 != port)
466 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, 478 LOG (GNUNET_ERROR_TYPE_ERROR,
467 "bind"); 479 _ ("`%s' failed for port %d (%s).\n"),
468 if (0 != port) 480 "bind",
469 LOG(GNUNET_ERROR_TYPE_ERROR, 481 port,
470 _("`%s' failed for port %d (%s).\n"), 482 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
471 "bind", 483 eno = 0;
472 port,
473 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
474 eno = 0;
475 }
476 else
477 {
478 if (0 != port)
479 LOG(GNUNET_ERROR_TYPE_WARNING,
480 _("`%s' failed for port %d (%s): address already in use\n"),
481 "bind", port,
482 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
483 else if (AF_UNIX == server_addr->sa_family)
484 {
485 LOG(GNUNET_ERROR_TYPE_WARNING,
486 _("`%s' failed for `%s': address already in use\n"),
487 "bind",
488 GNUNET_a2s(server_addr, socklen));
489 }
490 }
491 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock));
492 errno = eno;
493 return NULL;
494 } 484 }
495 if (GNUNET_OK != GNUNET_NETWORK_socket_listen(sock, 5)) 485 else
496 { 486 {
497 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, 487 if (0 != port)
498 "listen"); 488 LOG (GNUNET_ERROR_TYPE_WARNING,
499 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(sock)); 489 _ ("`%s' failed for port %d (%s): address already in use\n"),
500 errno = 0; 490 "bind", port,
501 return NULL; 491 (AF_INET == server_addr->sa_family) ? "IPv4" : "IPv6");
492 else if (AF_UNIX == server_addr->sa_family)
493 {
494 LOG (GNUNET_ERROR_TYPE_WARNING,
495 _ ("`%s' failed for `%s': address already in use\n"),
496 "bind",
497 GNUNET_a2s (server_addr, socklen));
498 }
502 } 499 }
500 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
501 errno = eno;
502 return NULL;
503 }
504 if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5))
505 {
506 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
507 "listen");
508 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
509 errno = 0;
510 return NULL;
511 }
503 if (0 != port) 512 if (0 != port)
504 LOG(GNUNET_ERROR_TYPE_DEBUG, 513 LOG (GNUNET_ERROR_TYPE_DEBUG,
505 "Server starts to listen on port %u.\n", 514 "Server starts to listen on port %u.\n",
506 port); 515 port);
507 return sock; 516 return sock;
508} 517}
509 518
@@ -521,22 +530,22 @@ open_listen_socket(const struct sockaddr *server_addr,
521 * (typically, "port" already in use) 530 * (typically, "port" already in use)
522 */ 531 */
523struct GNUNET_SERVER_Handle * 532struct GNUNET_SERVER_Handle *
524GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb, 533GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb,
525 void *access_cb_cls, 534 void *access_cb_cls,
526 struct GNUNET_NETWORK_Handle **lsocks, 535 struct GNUNET_NETWORK_Handle **lsocks,
527 struct GNUNET_TIME_Relative idle_timeout, 536 struct GNUNET_TIME_Relative idle_timeout,
528 int require_found) 537 int require_found)
529{ 538{
530 struct GNUNET_SERVER_Handle *server; 539 struct GNUNET_SERVER_Handle *server;
531 540
532 server = GNUNET_new(struct GNUNET_SERVER_Handle); 541 server = GNUNET_new (struct GNUNET_SERVER_Handle);
533 server->idle_timeout = idle_timeout; 542 server->idle_timeout = idle_timeout;
534 server->listen_sockets = lsocks; 543 server->listen_sockets = lsocks;
535 server->access_cb = access_cb; 544 server->access_cb = access_cb;
536 server->access_cb_cls = access_cb_cls; 545 server->access_cb_cls = access_cb_cls;
537 server->require_found = require_found; 546 server->require_found = require_found;
538 if (NULL != lsocks) 547 if (NULL != lsocks)
539 GNUNET_SERVER_resume(server); 548 GNUNET_SERVER_resume (server);
540 return server; 549 return server;
541} 550}
542 551
@@ -555,12 +564,12 @@ GNUNET_SERVER_create_with_sockets(GNUNET_CONNECTION_AccessCheck access_cb,
555 * (typically, "port" already in use) 564 * (typically, "port" already in use)
556 */ 565 */
557struct GNUNET_SERVER_Handle * 566struct GNUNET_SERVER_Handle *
558GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb, 567GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb,
559 void *access_cb_cls, 568 void *access_cb_cls,
560 struct sockaddr *const *server_addr, 569 struct sockaddr *const *server_addr,
561 const socklen_t * socklen, 570 const socklen_t *socklen,
562 struct GNUNET_TIME_Relative idle_timeout, 571 struct GNUNET_TIME_Relative idle_timeout,
563 int require_found) 572 int require_found)
564{ 573{
565 struct GNUNET_NETWORK_Handle **lsocks; 574 struct GNUNET_NETWORK_Handle **lsocks;
566 unsigned int i; 575 unsigned int i;
@@ -572,48 +581,48 @@ GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb,
572 while (NULL != server_addr[i]) 581 while (NULL != server_addr[i])
573 i++; 582 i++;
574 if (i > 0) 583 if (i > 0)
584 {
585 lsocks = GNUNET_malloc (sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1));
586 i = 0;
587 j = 0;
588 while (NULL != server_addr[i])
575 { 589 {
576 lsocks = GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (i + 1)); 590 seen = 0;
577 i = 0; 591 for (k = 0; k < i; k++)
578 j = 0; 592 if ((socklen[k] == socklen[i]) &&
579 while (NULL != server_addr[i]) 593 (0 == memcmp (server_addr[k], server_addr[i], socklen[i])))
580 { 594 {
581 seen = 0; 595 seen = 1;
582 for (k = 0; k < i; k++) 596 break;
583 if ((socklen[k] == socklen[i]) &&
584 (0 == memcmp(server_addr[k], server_addr[i], socklen[i])))
585 {
586 seen = 1;
587 break;
588 }
589 if (0 != seen)
590 {
591 /* duplicate address, skip */
592 i++;
593 continue;
594 }
595 lsocks[j] = open_listen_socket(server_addr[i], socklen[i]);
596 if (NULL != lsocks[j])
597 j++;
598 i++;
599 }
600 if (0 == j)
601 {
602 if (0 != errno)
603 LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "bind");
604 GNUNET_free(lsocks);
605 lsocks = NULL;
606 } 597 }
598 if (0 != seen)
599 {
600 /* duplicate address, skip */
601 i++;
602 continue;
603 }
604 lsocks[j] = open_listen_socket (server_addr[i], socklen[i]);
605 if (NULL != lsocks[j])
606 j++;
607 i++;
607 } 608 }
608 else 609 if (0 == j)
609 { 610 {
611 if (0 != errno)
612 LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "bind");
613 GNUNET_free (lsocks);
610 lsocks = NULL; 614 lsocks = NULL;
611 } 615 }
612 return GNUNET_SERVER_create_with_sockets(access_cb, 616 }
613 access_cb_cls, 617 else
614 lsocks, 618 {
615 idle_timeout, 619 lsocks = NULL;
616 require_found); 620 }
621 return GNUNET_SERVER_create_with_sockets (access_cb,
622 access_cb_cls,
623 lsocks,
624 idle_timeout,
625 require_found);
617} 626}
618 627
619 628
@@ -630,10 +639,10 @@ GNUNET_SERVER_create(GNUNET_CONNECTION_AccessCheck access_cb,
630 * @param client the client to set the 'monitor' flag on 639 * @param client the client to set the 'monitor' flag on
631 */ 640 */
632void 641void
633GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client) 642GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client)
634{ 643{
635 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
636 "Marking client as monitor!\n"); 645 "Marking client as monitor!\n");
637 client->is_monitor = GNUNET_YES; 646 client->is_monitor = GNUNET_YES;
638} 647}
639 648
@@ -645,11 +654,11 @@ GNUNET_SERVER_client_mark_monitor(struct GNUNET_SERVER_Client *client)
645 * @param cls the `struct GNUNET_SERVER_Handle *` to destroy 654 * @param cls the `struct GNUNET_SERVER_Handle *` to destroy
646 */ 655 */
647static void 656static void
648do_destroy(void *cls) 657do_destroy (void *cls)
649{ 658{
650 struct GNUNET_SERVER_Handle *server = cls; 659 struct GNUNET_SERVER_Handle *server = cls;
651 660
652 GNUNET_SERVER_destroy(server); 661 GNUNET_SERVER_destroy (server);
653} 662}
654 663
655 664
@@ -660,7 +669,7 @@ do_destroy(void *cls)
660 * @param server server to test for full shutdown 669 * @param server server to test for full shutdown
661 */ 670 */
662static void 671static void
663test_monitor_clients(struct GNUNET_SERVER_Handle *server) 672test_monitor_clients (struct GNUNET_SERVER_Handle *server)
664{ 673{
665 struct GNUNET_SERVER_Client *client; 674 struct GNUNET_SERVER_Client *client;
666 675
@@ -671,7 +680,7 @@ test_monitor_clients(struct GNUNET_SERVER_Handle *server)
671 return; 680 return;
672 /* not done yet */ 681 /* not done yet */
673 server->in_soft_shutdown = GNUNET_SYSERR; 682 server->in_soft_shutdown = GNUNET_SYSERR;
674 (void)GNUNET_SCHEDULER_add_now(&do_destroy, server); 683 (void) GNUNET_SCHEDULER_add_now (&do_destroy, server);
675} 684}
676 685
677 686
@@ -681,13 +690,13 @@ test_monitor_clients(struct GNUNET_SERVER_Handle *server)
681 * @param server server to stop accepting connections. 690 * @param server server to stop accepting connections.
682 */ 691 */
683void 692void
684GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server) 693GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server)
685{ 694{
686 if (NULL != server->listen_task) 695 if (NULL != server->listen_task)
687 { 696 {
688 GNUNET_SCHEDULER_cancel(server->listen_task); 697 GNUNET_SCHEDULER_cancel (server->listen_task);
689 server->listen_task = NULL; 698 server->listen_task = NULL;
690 } 699 }
691} 700}
692 701
693 702
@@ -697,7 +706,7 @@ GNUNET_SERVER_suspend(struct GNUNET_SERVER_Handle *server)
697 * @param server server to stop accepting connections. 706 * @param server server to stop accepting connections.
698 */ 707 */
699void 708void
700GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server) 709GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server)
701{ 710{
702 struct GNUNET_NETWORK_FDSet *r; 711 struct GNUNET_NETWORK_FDSet *r;
703 unsigned int i; 712 unsigned int i;
@@ -707,25 +716,26 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
707 if (NULL == server->listen_sockets[0]) 716 if (NULL == server->listen_sockets[0])
708 return; /* nothing to do, no listen sockets! */ 717 return; /* nothing to do, no listen sockets! */
709 if (NULL == server->listen_sockets[1]) 718 if (NULL == server->listen_sockets[1])
710 { 719 {
711 /* simplified method: no fd set needed; this is then much simpler 720 /* simplified method: no fd set needed; this is then much simpler
712 and much more efficient */ 721 and much more efficient */
713 server->listen_task = 722 server->listen_task =
714 GNUNET_SCHEDULER_add_read_net_with_priority(GNUNET_TIME_UNIT_FOREVER_REL, 723 GNUNET_SCHEDULER_add_read_net_with_priority (GNUNET_TIME_UNIT_FOREVER_REL,
715 GNUNET_SCHEDULER_PRIORITY_HIGH, 724 GNUNET_SCHEDULER_PRIORITY_HIGH,
716 server->listen_sockets[0], 725 server->listen_sockets[0],
717 &process_listen_socket, server); 726 &process_listen_socket,
718 return; 727 server);
719 } 728 return;
720 r = GNUNET_NETWORK_fdset_create(); 729 }
730 r = GNUNET_NETWORK_fdset_create ();
721 i = 0; 731 i = 0;
722 while (NULL != server->listen_sockets[i]) 732 while (NULL != server->listen_sockets[i])
723 GNUNET_NETWORK_fdset_set(r, server->listen_sockets[i++]); 733 GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]);
724 server->listen_task = 734 server->listen_task =
725 GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_HIGH, 735 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_HIGH,
726 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, 736 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
727 &process_listen_socket, server); 737 &process_listen_socket, server);
728 GNUNET_NETWORK_fdset_destroy(r); 738 GNUNET_NETWORK_fdset_destroy (r);
729} 739}
730 740
731 741
@@ -736,29 +746,29 @@ GNUNET_SERVER_resume(struct GNUNET_SERVER_Handle *server)
736 * @param server server to stop listening on 746 * @param server server to stop listening on
737 */ 747 */
738void 748void
739GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server) 749GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server)
740{ 750{
741 unsigned int i; 751 unsigned int i;
742 752
743 LOG(GNUNET_ERROR_TYPE_DEBUG, 753 LOG (GNUNET_ERROR_TYPE_DEBUG,
744 "Server in soft shutdown\n"); 754 "Server in soft shutdown\n");
745 if (NULL != server->listen_task) 755 if (NULL != server->listen_task)
746 { 756 {
747 GNUNET_SCHEDULER_cancel(server->listen_task); 757 GNUNET_SCHEDULER_cancel (server->listen_task);
748 server->listen_task = NULL; 758 server->listen_task = NULL;
749 } 759 }
750 if (NULL != server->listen_sockets) 760 if (NULL != server->listen_sockets)
751 { 761 {
752 i = 0; 762 i = 0;
753 while (NULL != server->listen_sockets[i]) 763 while (NULL != server->listen_sockets[i])
754 GNUNET_break(GNUNET_OK == 764 GNUNET_break (GNUNET_OK ==
755 GNUNET_NETWORK_socket_close(server->listen_sockets[i++])); 765 GNUNET_NETWORK_socket_close (server->listen_sockets[i++]));
756 GNUNET_free(server->listen_sockets); 766 GNUNET_free (server->listen_sockets);
757 server->listen_sockets = NULL; 767 server->listen_sockets = NULL;
758 } 768 }
759 if (GNUNET_NO == server->in_soft_shutdown) 769 if (GNUNET_NO == server->in_soft_shutdown)
760 server->in_soft_shutdown = GNUNET_YES; 770 server->in_soft_shutdown = GNUNET_YES;
761 test_monitor_clients(server); 771 test_monitor_clients (server);
762} 772}
763 773
764 774
@@ -768,54 +778,54 @@ GNUNET_SERVER_stop_listening(struct GNUNET_SERVER_Handle *server)
768 * @param server server to destroy 778 * @param server server to destroy
769 */ 779 */
770void 780void
771GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server) 781GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server)
772{ 782{
773 struct HandlerList *hpos; 783 struct HandlerList *hpos;
774 struct NotifyList *npos; 784 struct NotifyList *npos;
775 unsigned int i; 785 unsigned int i;
776 786
777 LOG(GNUNET_ERROR_TYPE_DEBUG, 787 LOG (GNUNET_ERROR_TYPE_DEBUG,
778 "Server shutting down.\n"); 788 "Server shutting down.\n");
779 if (NULL != server->listen_task) 789 if (NULL != server->listen_task)
780 { 790 {
781 GNUNET_SCHEDULER_cancel(server->listen_task); 791 GNUNET_SCHEDULER_cancel (server->listen_task);
782 server->listen_task = NULL; 792 server->listen_task = NULL;
783 } 793 }
784 if (NULL != server->listen_sockets) 794 if (NULL != server->listen_sockets)
785 { 795 {
786 i = 0; 796 i = 0;
787 while (NULL != server->listen_sockets[i]) 797 while (NULL != server->listen_sockets[i])
788 GNUNET_break(GNUNET_OK == 798 GNUNET_break (GNUNET_OK ==
789 GNUNET_NETWORK_socket_close(server->listen_sockets[i++])); 799 GNUNET_NETWORK_socket_close (server->listen_sockets[i++]));
790 GNUNET_free(server->listen_sockets); 800 GNUNET_free (server->listen_sockets);
791 server->listen_sockets = NULL; 801 server->listen_sockets = NULL;
792 } 802 }
793 while (NULL != server->clients_head) 803 while (NULL != server->clients_head)
794 GNUNET_SERVER_client_disconnect(server->clients_head); 804 GNUNET_SERVER_client_disconnect (server->clients_head);
795 while (NULL != (hpos = server->handlers)) 805 while (NULL != (hpos = server->handlers))
796 { 806 {
797 server->handlers = hpos->next; 807 server->handlers = hpos->next;
798 GNUNET_free(hpos); 808 GNUNET_free (hpos);
799 } 809 }
800 while (NULL != (npos = server->disconnect_notify_list_head)) 810 while (NULL != (npos = server->disconnect_notify_list_head))
801 { 811 {
802 npos->callback(npos->callback_cls, 812 npos->callback (npos->callback_cls,
803 NULL); 813 NULL);
804 GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head, 814 GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head,
805 server->disconnect_notify_list_tail, 815 server->disconnect_notify_list_tail,
806 npos); 816 npos);
807 GNUNET_free(npos); 817 GNUNET_free (npos);
808 } 818 }
809 while (NULL != (npos = server->connect_notify_list_head)) 819 while (NULL != (npos = server->connect_notify_list_head))
810 { 820 {
811 npos->callback(npos->callback_cls, 821 npos->callback (npos->callback_cls,
812 NULL); 822 NULL);
813 GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head, 823 GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head,
814 server->connect_notify_list_tail, 824 server->connect_notify_list_tail,
815 npos); 825 npos);
816 GNUNET_free(npos); 826 GNUNET_free (npos);
817 } 827 }
818 GNUNET_free(server); 828 GNUNET_free (server);
819} 829}
820 830
821 831
@@ -833,12 +843,12 @@ GNUNET_SERVER_destroy(struct GNUNET_SERVER_Handle *server)
833 * (or server is destroyed). 843 * (or server is destroyed).
834 */ 844 */
835void 845void
836GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server, 846GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server,
837 const struct GNUNET_SERVER_MessageHandler *handlers) 847 const struct GNUNET_SERVER_MessageHandler *handlers)
838{ 848{
839 struct HandlerList *p; 849 struct HandlerList *p;
840 850
841 p = GNUNET_new(struct HandlerList); 851 p = GNUNET_new (struct HandlerList);
842 p->handlers = handlers; 852 p->handlers = handlers;
843 p->next = server->handlers; 853 p->next = server->handlers;
844 server->handlers = p; 854 server->handlers = p;
@@ -856,11 +866,11 @@ GNUNET_SERVER_add_handlers(struct GNUNET_SERVER_Handle *server,
856 * @param cls closure for @a create, @a receive, @a destroy 866 * @param cls closure for @a create, @a receive, @a destroy
857 */ 867 */
858void 868void
859GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server, 869GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server,
860 GNUNET_SERVER_MstCreateCallback create, 870 GNUNET_SERVER_MstCreateCallback create,
861 GNUNET_SERVER_MstDestroyCallback destroy, 871 GNUNET_SERVER_MstDestroyCallback destroy,
862 GNUNET_SERVER_MstReceiveCallback receive, 872 GNUNET_SERVER_MstReceiveCallback receive,
863 void *cls) 873 void *cls)
864{ 874{
865 server->mst_create = create; 875 server->mst_create = create;
866 server->mst_destroy = destroy; 876 server->mst_destroy = destroy;
@@ -875,19 +885,21 @@ GNUNET_SERVER_set_callbacks(struct GNUNET_SERVER_Handle *server,
875 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from 885 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from
876 */ 886 */
877static void 887static void
878warn_no_receive_done(void *cls) 888warn_no_receive_done (void *cls)
879{ 889{
880 struct GNUNET_SERVER_Client *client = cls; 890 struct GNUNET_SERVER_Client *client = cls;
881 891
882 GNUNET_break(0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */ 892 GNUNET_break (0 != client->warn_type); /* type should never be 0 here, as we don't use 0 */
883 client->warn_task = 893 client->warn_task =
884 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 894 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
885 &warn_no_receive_done, client); 895 &warn_no_receive_done, client);
886 LOG(GNUNET_ERROR_TYPE_WARNING, 896 LOG (GNUNET_ERROR_TYPE_WARNING,
887 _("Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"), 897 _ (
888 (unsigned int)client->warn_type, 898 "Processing code for message of type %u did not call `GNUNET_SERVER_receive_done' after %s\n"),
889 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_duration(client->warn_start), 899 (unsigned int) client->warn_type,
890 GNUNET_YES)); 900 GNUNET_STRINGS_relative_time_to_string (
901 GNUNET_TIME_absolute_get_duration (client->warn_start),
902 GNUNET_YES));
891} 903}
892 904
893 905
@@ -899,13 +911,13 @@ warn_no_receive_done(void *cls)
899 * @param client client for which to disable the warning 911 * @param client client for which to disable the warning
900 */ 912 */
901void 913void
902GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client) 914GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client *client)
903{ 915{
904 if (NULL != client->warn_task) 916 if (NULL != client->warn_task)
905 { 917 {
906 GNUNET_SCHEDULER_cancel(client->warn_task); 918 GNUNET_SCHEDULER_cancel (client->warn_task);
907 client->warn_task = NULL; 919 client->warn_task = NULL;
908 } 920 }
909} 921}
910 922
911 923
@@ -925,9 +937,9 @@ GNUNET_SERVER_disable_receive_done_warning(struct GNUNET_SERVER_Client *client)
925 * client should be shut down 937 * client should be shut down
926 */ 938 */
927int 939int
928GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server, 940GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
929 struct GNUNET_SERVER_Client *sender, 941 struct GNUNET_SERVER_Client *sender,
930 const struct GNUNET_MessageHeader *message) 942 const struct GNUNET_MessageHeader *message)
931{ 943{
932 struct HandlerList *pos; 944 struct HandlerList *pos;
933 const struct GNUNET_SERVER_MessageHandler *mh; 945 const struct GNUNET_SERVER_MessageHandler *mh;
@@ -936,62 +948,62 @@ GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server,
936 uint16_t size; 948 uint16_t size;
937 int found; 949 int found;
938 950
939 type = ntohs(message->type); 951 type = ntohs (message->type);
940 size = ntohs(message->size); 952 size = ntohs (message->size);
941 LOG(GNUNET_ERROR_TYPE_INFO, 953 LOG (GNUNET_ERROR_TYPE_INFO,
942 "Received message of type %u and size %u from client\n", 954 "Received message of type %u and size %u from client\n",
943 type, size); 955 type, size);
944 found = GNUNET_NO; 956 found = GNUNET_NO;
945 for (pos = server->handlers; NULL != pos; pos = pos->next) 957 for (pos = server->handlers; NULL != pos; pos = pos->next)
958 {
959 i = 0;
960 while (pos->handlers[i].callback != NULL)
946 { 961 {
947 i = 0; 962 mh = &pos->handlers[i];
948 while (pos->handlers[i].callback != NULL) 963 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
964 {
965 if ((0 != mh->expected_size) && (mh->expected_size != size))
949 { 966 {
950 mh = &pos->handlers[i];
951 if ((mh->type == type) || (mh->type == GNUNET_MESSAGE_TYPE_ALL))
952 {
953 if ((0 != mh->expected_size) && (mh->expected_size != size))
954 {
955#if GNUNET8_NETWORK_IS_DEAD 967#if GNUNET8_NETWORK_IS_DEAD
956 LOG(GNUNET_ERROR_TYPE_WARNING, 968 LOG (GNUNET_ERROR_TYPE_WARNING,
957 "Expected %u bytes for message of type %u, got %u\n", 969 "Expected %u bytes for message of type %u, got %u\n",
958 mh->expected_size, mh->type, size); 970 mh->expected_size, mh->type, size);
959 GNUNET_break_op(0); 971 GNUNET_break_op (0);
960#else 972#else
961 LOG(GNUNET_ERROR_TYPE_DEBUG, 973 LOG (GNUNET_ERROR_TYPE_DEBUG,
962 "Expected %u bytes for message of type %u, got %u\n", 974 "Expected %u bytes for message of type %u, got %u\n",
963 mh->expected_size, mh->type, size); 975 mh->expected_size, mh->type, size);
964#endif 976#endif
965 return GNUNET_SYSERR; 977 return GNUNET_SYSERR;
966 }
967 if (NULL != sender)
968 {
969 if ((0 == sender->suspended) &&
970 (NULL == sender->warn_task))
971 {
972 GNUNET_break(0 != type); /* type should never be 0 here, as we don't use 0 */
973 sender->warn_start = GNUNET_TIME_absolute_get();
974 sender->warn_task =
975 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
976 &warn_no_receive_done,
977 sender);
978 sender->warn_type = type;
979 }
980 sender->suspended++;
981 }
982 mh->callback(mh->callback_cls, sender, message);
983 found = GNUNET_YES;
984 }
985 i++;
986 } 978 }
979 if (NULL != sender)
980 {
981 if ((0 == sender->suspended) &&
982 (NULL == sender->warn_task))
983 {
984 GNUNET_break (0 != type); /* type should never be 0 here, as we don't use 0 */
985 sender->warn_start = GNUNET_TIME_absolute_get ();
986 sender->warn_task =
987 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
988 &warn_no_receive_done,
989 sender);
990 sender->warn_type = type;
991 }
992 sender->suspended++;
993 }
994 mh->callback (mh->callback_cls, sender, message);
995 found = GNUNET_YES;
996 }
997 i++;
987 } 998 }
999 }
988 if (GNUNET_NO == found) 1000 if (GNUNET_NO == found)
989 { 1001 {
990 LOG(GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 1002 LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
991 "Received message of unknown type %d\n", type); 1003 "Received message of unknown type %d\n", type);
992 if (GNUNET_YES == server->require_found) 1004 if (GNUNET_YES == server->require_found)
993 return GNUNET_SYSERR; 1005 return GNUNET_SYSERR;
994 } 1006 }
995 return GNUNET_OK; 1007 return GNUNET_OK;
996} 1008}
997 1009
@@ -1007,12 +1019,12 @@ GNUNET_SERVER_inject(struct GNUNET_SERVER_Handle *server,
1007 * @param errCode code indicating errors receiving, 0 for success 1019 * @param errCode code indicating errors receiving, 0 for success
1008 */ 1020 */
1009static void 1021static void
1010process_incoming(void *cls, 1022process_incoming (void *cls,
1011 const void *buf, 1023 const void *buf,
1012 size_t available, 1024 size_t available,
1013 const struct sockaddr *addr, 1025 const struct sockaddr *addr,
1014 socklen_t addrlen, 1026 socklen_t addrlen,
1015 int errCode); 1027 int errCode);
1016 1028
1017 1029
1018/** 1030/**
@@ -1029,52 +1041,53 @@ process_incoming(void *cls,
1029 * #GNUNET_SYSERR if we should instantly abort due to error in a previous step 1041 * #GNUNET_SYSERR if we should instantly abort due to error in a previous step
1030 */ 1042 */
1031static void 1043static void
1032process_mst(struct GNUNET_SERVER_Client *client, 1044process_mst (struct GNUNET_SERVER_Client *client,
1033 int ret) 1045 int ret)
1034{ 1046{
1035 while ((GNUNET_SYSERR != ret) && (NULL != client->server) && 1047 while ((GNUNET_SYSERR != ret) && (NULL != client->server) &&
1036 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) 1048 (GNUNET_YES != client->shutdown_now) && (0 == client->suspended))
1049 {
1050 if (GNUNET_OK == ret)
1037 { 1051 {
1038 if (GNUNET_OK == ret) 1052 LOG (GNUNET_ERROR_TYPE_DEBUG,
1039 { 1053 "Server re-enters receive loop, timeout: %s.\n",
1040 LOG(GNUNET_ERROR_TYPE_DEBUG, 1054 GNUNET_STRINGS_relative_time_to_string (client->idle_timeout,
1041 "Server re-enters receive loop, timeout: %s.\n", 1055 GNUNET_YES));
1042 GNUNET_STRINGS_relative_time_to_string(client->idle_timeout, GNUNET_YES)); 1056 client->receive_pending = GNUNET_YES;
1043 client->receive_pending = GNUNET_YES; 1057 if (GNUNET_OK !=
1044 if (GNUNET_OK != 1058 GNUNET_CONNECTION_receive (client->connection,
1045 GNUNET_CONNECTION_receive(client->connection, 1059 GNUNET_MAX_MESSAGE_SIZE - 1,
1046 GNUNET_MAX_MESSAGE_SIZE - 1, 1060 client->idle_timeout,
1047 client->idle_timeout, 1061 &process_incoming,
1048 &process_incoming, 1062 client))
1049 client)) 1063 return;
1050 return; 1064 break;
1051 break;
1052 }
1053 LOG(GNUNET_ERROR_TYPE_DEBUG,
1054 "Server processes additional messages instantly.\n");
1055 if (NULL != client->server->mst_receive)
1056 ret =
1057 client->server->mst_receive(client->server->mst_cls, client->mst,
1058 client, NULL, 0, GNUNET_NO, GNUNET_YES);
1059 else
1060 ret =
1061 GNUNET_SERVER_mst_receive(client->mst, client, NULL, 0, GNUNET_NO,
1062 GNUNET_YES);
1063 } 1065 }
1064 LOG(GNUNET_ERROR_TYPE_DEBUG, 1066 LOG (GNUNET_ERROR_TYPE_DEBUG,
1065 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n", 1067 "Server processes additional messages instantly.\n");
1066 ret, client->server, 1068 if (NULL != client->server->mst_receive)
1067 client->shutdown_now, 1069 ret =
1068 client->suspended); 1070 client->server->mst_receive (client->server->mst_cls, client->mst,
1071 client, NULL, 0, GNUNET_NO, GNUNET_YES);
1072 else
1073 ret =
1074 GNUNET_SERVER_mst_receive (client->mst, client, NULL, 0, GNUNET_NO,
1075 GNUNET_YES);
1076 }
1077 LOG (GNUNET_ERROR_TYPE_DEBUG,
1078 "Server leaves instant processing loop: ret = %d, server = %p, shutdown = %d, suspended = %u\n",
1079 ret, client->server,
1080 client->shutdown_now,
1081 client->suspended);
1069 if (GNUNET_NO == ret) 1082 if (GNUNET_NO == ret)
1070 { 1083 {
1071 LOG(GNUNET_ERROR_TYPE_DEBUG, 1084 LOG (GNUNET_ERROR_TYPE_DEBUG,
1072 "Server has more data pending but is suspended.\n"); 1085 "Server has more data pending but is suspended.\n");
1073 client->receive_pending = GNUNET_SYSERR; /* data pending */ 1086 client->receive_pending = GNUNET_SYSERR; /* data pending */
1074 } 1087 }
1075 if ((GNUNET_SYSERR == ret) || 1088 if ((GNUNET_SYSERR == ret) ||
1076 (GNUNET_YES == client->shutdown_now)) 1089 (GNUNET_YES == client->shutdown_now))
1077 GNUNET_SERVER_client_disconnect(client); 1090 GNUNET_SERVER_client_disconnect (client);
1078} 1091}
1079 1092
1080 1093
@@ -1089,12 +1102,12 @@ process_mst(struct GNUNET_SERVER_Client *client,
1089 * @param errCode code indicating errors receiving, 0 for success 1102 * @param errCode code indicating errors receiving, 0 for success
1090 */ 1103 */
1091static void 1104static void
1092process_incoming(void *cls, 1105process_incoming (void *cls,
1093 const void *buf, 1106 const void *buf,
1094 size_t available, 1107 size_t available,
1095 const struct sockaddr *addr, 1108 const struct sockaddr *addr,
1096 socklen_t addrlen, 1109 socklen_t addrlen,
1097 int errCode) 1110 int errCode)
1098{ 1111{
1099 struct GNUNET_SERVER_Client *client = cls; 1112 struct GNUNET_SERVER_Client *client = cls;
1100 struct GNUNET_SERVER_Handle *server = client->server; 1113 struct GNUNET_SERVER_Handle *server = client->server;
@@ -1102,11 +1115,11 @@ process_incoming(void *cls,
1102 struct GNUNET_TIME_Absolute now; 1115 struct GNUNET_TIME_Absolute now;
1103 int ret; 1116 int ret;
1104 1117
1105 GNUNET_assert(GNUNET_YES == client->receive_pending); 1118 GNUNET_assert (GNUNET_YES == client->receive_pending);
1106 client->receive_pending = GNUNET_NO; 1119 client->receive_pending = GNUNET_NO;
1107 now = GNUNET_TIME_absolute_get(); 1120 now = GNUNET_TIME_absolute_get ();
1108 end = GNUNET_TIME_absolute_add(client->last_activity, 1121 end = GNUNET_TIME_absolute_add (client->last_activity,
1109 client->idle_timeout); 1122 client->idle_timeout);
1110 1123
1111 if ((NULL == buf) && 1124 if ((NULL == buf) &&
1112 (0 == available) && 1125 (0 == available) &&
@@ -1114,70 +1127,70 @@ process_incoming(void *cls,
1114 (0 == errCode) && 1127 (0 == errCode) &&
1115 (GNUNET_YES != client->shutdown_now) && 1128 (GNUNET_YES != client->shutdown_now) &&
1116 (NULL != server) && 1129 (NULL != server) &&
1117 (GNUNET_YES == GNUNET_CONNECTION_check(client->connection)) && 1130 (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) &&
1118 (end.abs_value_us > now.abs_value_us)) 1131 (end.abs_value_us > now.abs_value_us))
1119 { 1132 {
1120 /* wait longer, timeout changed (i.e. due to us sending) */ 1133 /* wait longer, timeout changed (i.e. due to us sending) */
1121 LOG(GNUNET_ERROR_TYPE_DEBUG, 1134 LOG (GNUNET_ERROR_TYPE_DEBUG,
1122 "Receive time out, but no disconnect due to sending (%p)\n", 1135 "Receive time out, but no disconnect due to sending (%p)\n",
1123 client); 1136 client);
1124 client->receive_pending = GNUNET_YES; 1137 client->receive_pending = GNUNET_YES;
1125 GNUNET_CONNECTION_receive(client->connection, 1138 GNUNET_CONNECTION_receive (client->connection,
1126 GNUNET_MAX_MESSAGE_SIZE - 1, 1139 GNUNET_MAX_MESSAGE_SIZE - 1,
1127 GNUNET_TIME_absolute_get_remaining(end), 1140 GNUNET_TIME_absolute_get_remaining (end),
1128 &process_incoming, 1141 &process_incoming,
1129 client); 1142 client);
1130 return; 1143 return;
1131 } 1144 }
1132 if ((NULL == buf) || 1145 if ((NULL == buf) ||
1133 (0 == available) || 1146 (0 == available) ||
1134 (0 != errCode) || 1147 (0 != errCode) ||
1135 (NULL == server) || 1148 (NULL == server) ||
1136 (GNUNET_YES == client->shutdown_now) || 1149 (GNUNET_YES == client->shutdown_now) ||
1137 (GNUNET_YES != GNUNET_CONNECTION_check(client->connection))) 1150 (GNUNET_YES != GNUNET_CONNECTION_check (client->connection)))
1138 { 1151 {
1139 /* other side closed connection, error connecting, etc. */ 1152 /* other side closed connection, error connecting, etc. */
1140 LOG(GNUNET_ERROR_TYPE_DEBUG, 1153 LOG (GNUNET_ERROR_TYPE_DEBUG,
1141 "Failed to connect or other side closed connection (%p)\n", 1154 "Failed to connect or other side closed connection (%p)\n",
1142 client); 1155 client);
1143 GNUNET_SERVER_client_disconnect(client); 1156 GNUNET_SERVER_client_disconnect (client);
1144 return; 1157 return;
1145 } 1158 }
1146 LOG(GNUNET_ERROR_TYPE_DEBUG, 1159 LOG (GNUNET_ERROR_TYPE_DEBUG,
1147 "Server receives %u bytes from `%s'.\n", 1160 "Server receives %u bytes from `%s'.\n",
1148 (unsigned int)available, 1161 (unsigned int) available,
1149 GNUNET_a2s(addr, addrlen)); 1162 GNUNET_a2s (addr, addrlen));
1150 GNUNET_SERVER_client_keep(client); 1163 GNUNET_SERVER_client_keep (client);
1151 client->last_activity = now; 1164 client->last_activity = now;
1152 1165
1153 if (NULL != server->mst_receive) 1166 if (NULL != server->mst_receive)
1154 { 1167 {
1155 ret = client->server->mst_receive(client->server->mst_cls, 1168 ret = client->server->mst_receive (client->server->mst_cls,
1156 client->mst, 1169 client->mst,
1157 client, 1170 client,
1158 buf, 1171 buf,
1159 available, 1172 available,
1160 GNUNET_NO, 1173 GNUNET_NO,
1161 GNUNET_YES); 1174 GNUNET_YES);
1162 } 1175 }
1163 else if (NULL != client->mst) 1176 else if (NULL != client->mst)
1164 { 1177 {
1165 ret = 1178 ret =
1166 GNUNET_SERVER_mst_receive(client->mst, 1179 GNUNET_SERVER_mst_receive (client->mst,
1167 client, 1180 client,
1168 buf, 1181 buf,
1169 available, 1182 available,
1170 GNUNET_NO, 1183 GNUNET_NO,
1171 GNUNET_YES); 1184 GNUNET_YES);
1172 } 1185 }
1173 else 1186 else
1174 { 1187 {
1175 GNUNET_break(0); 1188 GNUNET_break (0);
1176 return; 1189 return;
1177 } 1190 }
1178 process_mst(client, 1191 process_mst (client,
1179 ret); 1192 ret);
1180 GNUNET_SERVER_client_drop(client); 1193 GNUNET_SERVER_client_drop (client);
1181} 1194}
1182 1195
1183 1196
@@ -1188,30 +1201,30 @@ process_incoming(void *cls,
1188 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from 1201 * @param cls our `struct GNUNET_SERVER_Client *` to process more requests from
1189 */ 1202 */
1190static void 1203static void
1191restart_processing(void *cls) 1204restart_processing (void *cls)
1192{ 1205{
1193 struct GNUNET_SERVER_Client *client = cls; 1206 struct GNUNET_SERVER_Client *client = cls;
1194 1207
1195 GNUNET_assert(GNUNET_YES != client->shutdown_now); 1208 GNUNET_assert (GNUNET_YES != client->shutdown_now);
1196 client->restart_task = NULL; 1209 client->restart_task = NULL;
1197 if (GNUNET_NO == client->receive_pending) 1210 if (GNUNET_NO == client->receive_pending)
1198 { 1211 {
1199 LOG(GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n"); 1212 LOG (GNUNET_ERROR_TYPE_DEBUG, "Server begins to read again from client.\n");
1200 client->receive_pending = GNUNET_YES; 1213 client->receive_pending = GNUNET_YES;
1201 GNUNET_CONNECTION_receive(client->connection, 1214 GNUNET_CONNECTION_receive (client->connection,
1202 GNUNET_MAX_MESSAGE_SIZE - 1, 1215 GNUNET_MAX_MESSAGE_SIZE - 1,
1203 client->idle_timeout, 1216 client->idle_timeout,
1204 &process_incoming, 1217 &process_incoming,
1205 client); 1218 client);
1206 return; 1219 return;
1207 } 1220 }
1208 LOG(GNUNET_ERROR_TYPE_DEBUG, 1221 LOG (GNUNET_ERROR_TYPE_DEBUG,
1209 "Server continues processing messages still in the buffer.\n"); 1222 "Server continues processing messages still in the buffer.\n");
1210 GNUNET_SERVER_client_keep(client); 1223 GNUNET_SERVER_client_keep (client);
1211 client->receive_pending = GNUNET_NO; 1224 client->receive_pending = GNUNET_NO;
1212 process_mst(client, 1225 process_mst (client,
1213 GNUNET_NO); 1226 GNUNET_NO);
1214 GNUNET_SERVER_client_drop(client); 1227 GNUNET_SERVER_client_drop (client);
1215} 1228}
1216 1229
1217 1230
@@ -1226,25 +1239,25 @@ restart_processing(void *cls)
1226 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing 1239 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
1227 */ 1240 */
1228static int 1241static int
1229client_message_tokenizer_callback(void *cls, 1242client_message_tokenizer_callback (void *cls,
1230 void *client, 1243 void *client,
1231 const struct GNUNET_MessageHeader *message) 1244 const struct GNUNET_MessageHeader *message)
1232{ 1245{
1233 struct GNUNET_SERVER_Handle *server = cls; 1246 struct GNUNET_SERVER_Handle *server = cls;
1234 struct GNUNET_SERVER_Client *sender = client; 1247 struct GNUNET_SERVER_Client *sender = client;
1235 int ret; 1248 int ret;
1236 1249
1237 LOG(GNUNET_ERROR_TYPE_DEBUG, 1250 LOG (GNUNET_ERROR_TYPE_DEBUG,
1238 "Tokenizer gives server message of type %u and size %u from client\n", 1251 "Tokenizer gives server message of type %u and size %u from client\n",
1239 ntohs(message->type), ntohs(message->size)); 1252 ntohs (message->type), ntohs (message->size));
1240 sender->in_process_client_buffer = GNUNET_YES; 1253 sender->in_process_client_buffer = GNUNET_YES;
1241 ret = GNUNET_SERVER_inject(server, sender, message); 1254 ret = GNUNET_SERVER_inject (server, sender, message);
1242 sender->in_process_client_buffer = GNUNET_NO; 1255 sender->in_process_client_buffer = GNUNET_NO;
1243 if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now)) 1256 if ((GNUNET_OK != ret) || (GNUNET_YES == sender->shutdown_now))
1244 { 1257 {
1245 GNUNET_SERVER_client_disconnect(sender); 1258 GNUNET_SERVER_client_disconnect (sender);
1246 return GNUNET_SYSERR; 1259 return GNUNET_SYSERR;
1247 } 1260 }
1248 return GNUNET_OK; 1261 return GNUNET_OK;
1249} 1262}
1250 1263
@@ -1261,37 +1274,37 @@ client_message_tokenizer_callback(void *cls,
1261 * @return the client handle 1274 * @return the client handle
1262 */ 1275 */
1263struct GNUNET_SERVER_Client * 1276struct GNUNET_SERVER_Client *
1264GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server, 1277GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server,
1265 struct GNUNET_CONNECTION_Handle *connection) 1278 struct GNUNET_CONNECTION_Handle *connection)
1266{ 1279{
1267 struct GNUNET_SERVER_Client *client; 1280 struct GNUNET_SERVER_Client *client;
1268 struct NotifyList *n; 1281 struct NotifyList *n;
1269 1282
1270 client = GNUNET_new(struct GNUNET_SERVER_Client); 1283 client = GNUNET_new (struct GNUNET_SERVER_Client);
1271 client->connection = connection; 1284 client->connection = connection;
1272 client->server = server; 1285 client->server = server;
1273 client->last_activity = GNUNET_TIME_absolute_get(); 1286 client->last_activity = GNUNET_TIME_absolute_get ();
1274 client->idle_timeout = server->idle_timeout; 1287 client->idle_timeout = server->idle_timeout;
1275 GNUNET_CONTAINER_DLL_insert(server->clients_head, 1288 GNUNET_CONTAINER_DLL_insert (server->clients_head,
1276 server->clients_tail, 1289 server->clients_tail,
1277 client); 1290 client);
1278 if (NULL != server->mst_create) 1291 if (NULL != server->mst_create)
1279 client->mst = 1292 client->mst =
1280 server->mst_create(server->mst_cls, client); 1293 server->mst_create (server->mst_cls, client);
1281 else 1294 else
1282 client->mst = 1295 client->mst =
1283 GNUNET_SERVER_mst_create(&client_message_tokenizer_callback, 1296 GNUNET_SERVER_mst_create (&client_message_tokenizer_callback,
1284 server); 1297 server);
1285 GNUNET_assert(NULL != client->mst); 1298 GNUNET_assert (NULL != client->mst);
1286 for (n = server->connect_notify_list_head; NULL != n; n = n->next) 1299 for (n = server->connect_notify_list_head; NULL != n; n = n->next)
1287 n->callback(n->callback_cls, client); 1300 n->callback (n->callback_cls, client);
1288 client->receive_pending = GNUNET_YES; 1301 client->receive_pending = GNUNET_YES;
1289 if (GNUNET_SYSERR == 1302 if (GNUNET_SYSERR ==
1290 GNUNET_CONNECTION_receive(client->connection, 1303 GNUNET_CONNECTION_receive (client->connection,
1291 GNUNET_MAX_MESSAGE_SIZE - 1, 1304 GNUNET_MAX_MESSAGE_SIZE - 1,
1292 client->idle_timeout, 1305 client->idle_timeout,
1293 &process_incoming, 1306 &process_incoming,
1294 client)) 1307 client))
1295 return NULL; 1308 return NULL;
1296 return client; 1309 return client;
1297} 1310}
@@ -1306,8 +1319,8 @@ GNUNET_SERVER_connect_socket(struct GNUNET_SERVER_Handle *server,
1306 * @param timeout new timeout for activities on the socket 1319 * @param timeout new timeout for activities on the socket
1307 */ 1320 */
1308void 1321void
1309GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client, 1322GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client,
1310 struct GNUNET_TIME_Relative timeout) 1323 struct GNUNET_TIME_Relative timeout)
1311{ 1324{
1312 client->idle_timeout = timeout; 1325 client->idle_timeout = timeout;
1313} 1326}
@@ -1321,7 +1334,7 @@ GNUNET_SERVER_client_set_timeout(struct GNUNET_SERVER_Client *client,
1321 * @param client the client to keep 1334 * @param client the client to keep
1322 */ 1335 */
1323void 1336void
1324GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client) 1337GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client)
1325{ 1338{
1326 client->reference_count++; 1339 client->reference_count++;
1327} 1340}
@@ -1336,12 +1349,12 @@ GNUNET_SERVER_client_keep(struct GNUNET_SERVER_Client *client)
1336 * @param client the client to drop 1349 * @param client the client to drop
1337 */ 1350 */
1338void 1351void
1339GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client) 1352GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client)
1340{ 1353{
1341 GNUNET_assert(client->reference_count > 0); 1354 GNUNET_assert (client->reference_count > 0);
1342 client->reference_count--; 1355 client->reference_count--;
1343 if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count)) 1356 if ((GNUNET_YES == client->shutdown_now) && (0 == client->reference_count))
1344 GNUNET_SERVER_client_disconnect(client); 1357 GNUNET_SERVER_client_disconnect (client);
1345} 1358}
1346 1359
1347 1360
@@ -1354,10 +1367,10 @@ GNUNET_SERVER_client_drop(struct GNUNET_SERVER_Client *client)
1354 * @return #GNUNET_OK on success 1367 * @return #GNUNET_OK on success
1355 */ 1368 */
1356int 1369int
1357GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client, 1370GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1358 void **addr, size_t * addrlen) 1371 void **addr, size_t *addrlen)
1359{ 1372{
1360 return GNUNET_CONNECTION_get_address(client->connection, addr, addrlen); 1373 return GNUNET_CONNECTION_get_address (client->connection, addr, addrlen);
1361} 1374}
1362 1375
1363 1376
@@ -1372,18 +1385,18 @@ GNUNET_SERVER_client_get_address(struct GNUNET_SERVER_Client *client,
1372 * @param callback_cls closure for @a callback 1385 * @param callback_cls closure for @a callback
1373 */ 1386 */
1374void 1387void
1375GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server, 1388GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server,
1376 GNUNET_SERVER_DisconnectCallback callback, 1389 GNUNET_SERVER_DisconnectCallback callback,
1377 void *callback_cls) 1390 void *callback_cls)
1378{ 1391{
1379 struct NotifyList *n; 1392 struct NotifyList *n;
1380 1393
1381 n = GNUNET_new(struct NotifyList); 1394 n = GNUNET_new (struct NotifyList);
1382 n->callback = callback; 1395 n->callback = callback;
1383 n->callback_cls = callback_cls; 1396 n->callback_cls = callback_cls;
1384 GNUNET_CONTAINER_DLL_insert(server->disconnect_notify_list_head, 1397 GNUNET_CONTAINER_DLL_insert (server->disconnect_notify_list_head,
1385 server->disconnect_notify_list_tail, 1398 server->disconnect_notify_list_tail,
1386 n); 1399 n);
1387} 1400}
1388 1401
1389 1402
@@ -1401,21 +1414,21 @@ GNUNET_SERVER_disconnect_notify(struct GNUNET_SERVER_Handle *server,
1401 * @param callback_cls closure for @a callback 1414 * @param callback_cls closure for @a callback
1402 */ 1415 */
1403void 1416void
1404GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server, 1417GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server,
1405 GNUNET_SERVER_ConnectCallback callback, 1418 GNUNET_SERVER_ConnectCallback callback,
1406 void *callback_cls) 1419 void *callback_cls)
1407{ 1420{
1408 struct NotifyList *n; 1421 struct NotifyList *n;
1409 struct GNUNET_SERVER_Client *client; 1422 struct GNUNET_SERVER_Client *client;
1410 1423
1411 n = GNUNET_new(struct NotifyList); 1424 n = GNUNET_new (struct NotifyList);
1412 n->callback = callback; 1425 n->callback = callback;
1413 n->callback_cls = callback_cls; 1426 n->callback_cls = callback_cls;
1414 GNUNET_CONTAINER_DLL_insert(server->connect_notify_list_head, 1427 GNUNET_CONTAINER_DLL_insert (server->connect_notify_list_head,
1415 server->connect_notify_list_tail, 1428 server->connect_notify_list_tail,
1416 n); 1429 n);
1417 for (client = server->clients_head; NULL != client; client = client->next) 1430 for (client = server->clients_head; NULL != client; client = client->next)
1418 callback(callback_cls, client); 1431 callback (callback_cls, client);
1419} 1432}
1420 1433
1421 1434
@@ -1427,9 +1440,10 @@ GNUNET_SERVER_connect_notify(struct GNUNET_SERVER_Handle *server,
1427 * @param callback_cls closure for @a callback 1440 * @param callback_cls closure for @a callback
1428 */ 1441 */
1429void 1442void
1430GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server, 1443GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1431 GNUNET_SERVER_DisconnectCallback callback, 1444 GNUNET_SERVER_DisconnectCallback
1432 void *callback_cls) 1445 callback,
1446 void *callback_cls)
1433{ 1447{
1434 struct NotifyList *pos; 1448 struct NotifyList *pos;
1435 1449
@@ -1437,14 +1451,14 @@ GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1437 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1451 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1438 break; 1452 break;
1439 if (NULL == pos) 1453 if (NULL == pos)
1440 { 1454 {
1441 GNUNET_break(0); 1455 GNUNET_break (0);
1442 return; 1456 return;
1443 } 1457 }
1444 GNUNET_CONTAINER_DLL_remove(server->disconnect_notify_list_head, 1458 GNUNET_CONTAINER_DLL_remove (server->disconnect_notify_list_head,
1445 server->disconnect_notify_list_tail, 1459 server->disconnect_notify_list_tail,
1446 pos); 1460 pos);
1447 GNUNET_free(pos); 1461 GNUNET_free (pos);
1448} 1462}
1449 1463
1450 1464
@@ -1456,9 +1470,9 @@ GNUNET_SERVER_disconnect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1456 * @param callback_cls closure for @a callback 1470 * @param callback_cls closure for @a callback
1457 */ 1471 */
1458void 1472void
1459GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server, 1473GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server,
1460 GNUNET_SERVER_ConnectCallback callback, 1474 GNUNET_SERVER_ConnectCallback callback,
1461 void *callback_cls) 1475 void *callback_cls)
1462{ 1476{
1463 struct NotifyList *pos; 1477 struct NotifyList *pos;
1464 1478
@@ -1466,14 +1480,14 @@ GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1466 if ((pos->callback == callback) && (pos->callback_cls == callback_cls)) 1480 if ((pos->callback == callback) && (pos->callback_cls == callback_cls))
1467 break; 1481 break;
1468 if (NULL == pos) 1482 if (NULL == pos)
1469 { 1483 {
1470 GNUNET_break(0); 1484 GNUNET_break (0);
1471 return; 1485 return;
1472 } 1486 }
1473 GNUNET_CONTAINER_DLL_remove(server->connect_notify_list_head, 1487 GNUNET_CONTAINER_DLL_remove (server->connect_notify_list_head,
1474 server->connect_notify_list_tail, 1488 server->connect_notify_list_tail,
1475 pos); 1489 pos);
1476 GNUNET_free(pos); 1490 GNUNET_free (pos);
1477} 1491}
1478 1492
1479 1493
@@ -1486,86 +1500,86 @@ GNUNET_SERVER_connect_notify_cancel(struct GNUNET_SERVER_Handle *server,
1486 * @param client the client to disconnect from 1500 * @param client the client to disconnect from
1487 */ 1501 */
1488void 1502void
1489GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client) 1503GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client)
1490{ 1504{
1491 struct GNUNET_SERVER_Handle *server = client->server; 1505 struct GNUNET_SERVER_Handle *server = client->server;
1492 struct NotifyList *n; 1506 struct NotifyList *n;
1493 1507
1494 LOG(GNUNET_ERROR_TYPE_DEBUG, 1508 LOG (GNUNET_ERROR_TYPE_DEBUG,
1495 "Client is being disconnected from the server.\n"); 1509 "Client is being disconnected from the server.\n");
1496 if (NULL != client->restart_task) 1510 if (NULL != client->restart_task)
1497 { 1511 {
1498 GNUNET_SCHEDULER_cancel(client->restart_task); 1512 GNUNET_SCHEDULER_cancel (client->restart_task);
1499 client->restart_task = NULL; 1513 client->restart_task = NULL;
1500 } 1514 }
1501 if (NULL != client->warn_task) 1515 if (NULL != client->warn_task)
1502 { 1516 {
1503 GNUNET_SCHEDULER_cancel(client->warn_task); 1517 GNUNET_SCHEDULER_cancel (client->warn_task);
1504 client->warn_task = NULL; 1518 client->warn_task = NULL;
1505 } 1519 }
1506 if (GNUNET_YES == client->receive_pending) 1520 if (GNUNET_YES == client->receive_pending)
1507 { 1521 {
1508 GNUNET_CONNECTION_receive_cancel(client->connection); 1522 GNUNET_CONNECTION_receive_cancel (client->connection);
1509 client->receive_pending = GNUNET_NO; 1523 client->receive_pending = GNUNET_NO;
1510 } 1524 }
1511 client->shutdown_now = GNUNET_YES; 1525 client->shutdown_now = GNUNET_YES;
1512 client->reference_count++; /* make sure nobody else clean up client... */ 1526 client->reference_count++; /* make sure nobody else clean up client... */
1513 if ((NULL != client->mst) && 1527 if ((NULL != client->mst) &&
1514 (NULL != server)) 1528 (NULL != server))
1515 { 1529 {
1516 GNUNET_CONTAINER_DLL_remove(server->clients_head, 1530 GNUNET_CONTAINER_DLL_remove (server->clients_head,
1517 server->clients_tail, 1531 server->clients_tail,
1518 client); 1532 client);
1519 if (NULL != server->mst_destroy) 1533 if (NULL != server->mst_destroy)
1520 server->mst_destroy(server->mst_cls, 1534 server->mst_destroy (server->mst_cls,
1521 client->mst); 1535 client->mst);
1522 else 1536 else
1523 GNUNET_SERVER_mst_destroy(client->mst); 1537 GNUNET_SERVER_mst_destroy (client->mst);
1524 client->mst = NULL; 1538 client->mst = NULL;
1525 for (n = server->disconnect_notify_list_head; NULL != n; n = n->next) 1539 for (n = server->disconnect_notify_list_head; NULL != n; n = n->next)
1526 n->callback(n->callback_cls, 1540 n->callback (n->callback_cls,
1527 client); 1541 client);
1528 } 1542 }
1529 client->reference_count--; 1543 client->reference_count--;
1530 if (client->reference_count > 0) 1544 if (client->reference_count > 0)
1531 { 1545 {
1532 LOG(GNUNET_ERROR_TYPE_DEBUG, 1546 LOG (GNUNET_ERROR_TYPE_DEBUG,
1533 "RC of %p still positive, not destroying everything.\n", 1547 "RC of %p still positive, not destroying everything.\n",
1534 client); 1548 client);
1535 client->server = NULL; 1549 client->server = NULL;
1536 return; 1550 return;
1537 } 1551 }
1538 if (GNUNET_YES == client->in_process_client_buffer) 1552 if (GNUNET_YES == client->in_process_client_buffer)
1539 { 1553 {
1540 LOG(GNUNET_ERROR_TYPE_DEBUG, 1554 LOG (GNUNET_ERROR_TYPE_DEBUG,
1541 "Still processing inputs of %p, not destroying everything.\n", 1555 "Still processing inputs of %p, not destroying everything.\n",
1542 client); 1556 client);
1543 return; 1557 return;
1544 } 1558 }
1545 LOG(GNUNET_ERROR_TYPE_DEBUG, 1559 LOG (GNUNET_ERROR_TYPE_DEBUG,
1546 "RC of %p now zero, destroying everything.\n", 1560 "RC of %p now zero, destroying everything.\n",
1547 client); 1561 client);
1548 if (GNUNET_YES == client->persist) 1562 if (GNUNET_YES == client->persist)
1549 GNUNET_CONNECTION_persist_(client->connection); 1563 GNUNET_CONNECTION_persist_ (client->connection);
1550 if (NULL != client->th.cth) 1564 if (NULL != client->th.cth)
1551 GNUNET_SERVER_notify_transmit_ready_cancel(&client->th); 1565 GNUNET_SERVER_notify_transmit_ready_cancel (&client->th);
1552 GNUNET_CONNECTION_destroy(client->connection); 1566 GNUNET_CONNECTION_destroy (client->connection);
1553 /* need to cancel again, as it might have been re-added 1567 /* need to cancel again, as it might have been re-added
1554 in the meantime (i.e. during callbacks) */ 1568 in the meantime (i.e. during callbacks) */
1555 if (NULL != client->warn_task) 1569 if (NULL != client->warn_task)
1556 { 1570 {
1557 GNUNET_SCHEDULER_cancel(client->warn_task); 1571 GNUNET_SCHEDULER_cancel (client->warn_task);
1558 client->warn_task = NULL; 1572 client->warn_task = NULL;
1559 } 1573 }
1560 if (GNUNET_YES == client->receive_pending) 1574 if (GNUNET_YES == client->receive_pending)
1561 { 1575 {
1562 GNUNET_CONNECTION_receive_cancel(client->connection); 1576 GNUNET_CONNECTION_receive_cancel (client->connection);
1563 client->receive_pending = GNUNET_NO; 1577 client->receive_pending = GNUNET_NO;
1564 } 1578 }
1565 GNUNET_free(client); 1579 GNUNET_free (client);
1566 /* we might be in soft-shutdown, test if we're done */ 1580 /* we might be in soft-shutdown, test if we're done */
1567 if (NULL != server) 1581 if (NULL != server)
1568 test_monitor_clients(server); 1582 test_monitor_clients (server);
1569} 1583}
1570 1584
1571 1585
@@ -1578,9 +1592,9 @@ GNUNET_SERVER_client_disconnect(struct GNUNET_SERVER_Client *client)
1578 * @return #GNUNET_OK on success 1592 * @return #GNUNET_OK on success
1579 */ 1593 */
1580int 1594int
1581GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client) 1595GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client)
1582{ 1596{
1583 return GNUNET_CONNECTION_disable_corking(client->connection); 1597 return GNUNET_CONNECTION_disable_corking (client->connection);
1584} 1598}
1585 1599
1586 1600
@@ -1594,7 +1608,7 @@ GNUNET_SERVER_client_disable_corking(struct GNUNET_SERVER_Client *client)
1594 * @return number of bytes actually transmitted 1608 * @return number of bytes actually transmitted
1595 */ 1609 */
1596static size_t 1610static size_t
1597transmit_ready_callback_wrapper(void *cls, size_t size, void *buf) 1611transmit_ready_callback_wrapper (void *cls, size_t size, void *buf)
1598{ 1612{
1599 struct GNUNET_SERVER_Client *client = cls; 1613 struct GNUNET_SERVER_Client *client = cls;
1600 GNUNET_CONNECTION_TransmitReadyNotify callback; 1614 GNUNET_CONNECTION_TransmitReadyNotify callback;
@@ -1602,8 +1616,8 @@ transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
1602 client->th.cth = NULL; 1616 client->th.cth = NULL;
1603 callback = client->th.callback; 1617 callback = client->th.callback;
1604 client->th.callback = NULL; 1618 client->th.callback = NULL;
1605 client->last_activity = GNUNET_TIME_absolute_get(); 1619 client->last_activity = GNUNET_TIME_absolute_get ();
1606 return callback(client->th.callback_cls, size, buf); 1620 return callback (client->th.callback_cls, size, buf);
1607} 1621}
1608 1622
1609 1623
@@ -1623,20 +1637,23 @@ transmit_ready_callback_wrapper(void *cls, size_t size, void *buf)
1623 * NULL if we are already going to notify someone else (busy) 1637 * NULL if we are already going to notify someone else (busy)
1624 */ 1638 */
1625struct GNUNET_SERVER_TransmitHandle * 1639struct GNUNET_SERVER_TransmitHandle *
1626GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client, 1640GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client,
1627 size_t size, 1641 size_t size,
1628 struct GNUNET_TIME_Relative timeout, 1642 struct GNUNET_TIME_Relative timeout,
1629 GNUNET_CONNECTION_TransmitReadyNotify callback, 1643 GNUNET_CONNECTION_TransmitReadyNotify
1630 void *callback_cls) 1644 callback,
1645 void *callback_cls)
1631{ 1646{
1632 if (NULL != client->th.callback) 1647 if (NULL != client->th.callback)
1633 return NULL; 1648 return NULL;
1634 client->th.callback_cls = callback_cls; 1649 client->th.callback_cls = callback_cls;
1635 client->th.callback = callback; 1650 client->th.callback = callback;
1636 client->th.cth = GNUNET_CONNECTION_notify_transmit_ready(client->connection, size, 1651 client->th.cth = GNUNET_CONNECTION_notify_transmit_ready (client->connection,
1637 timeout, 1652 size,
1638 &transmit_ready_callback_wrapper, 1653 timeout,
1639 client); 1654 &
1655 transmit_ready_callback_wrapper,
1656 client);
1640 return &client->th; 1657 return &client->th;
1641} 1658}
1642 1659
@@ -1647,9 +1664,10 @@ GNUNET_SERVER_notify_transmit_ready(struct GNUNET_SERVER_Client *client,
1647 * @param th request to abort 1664 * @param th request to abort
1648 */ 1665 */
1649void 1666void
1650GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *th) 1667GNUNET_SERVER_notify_transmit_ready_cancel (struct
1668 GNUNET_SERVER_TransmitHandle *th)
1651{ 1669{
1652 GNUNET_CONNECTION_notify_transmit_ready_cancel(th->cth); 1670 GNUNET_CONNECTION_notify_transmit_ready_cancel (th->cth);
1653 th->cth = NULL; 1671 th->cth = NULL;
1654 th->callback = NULL; 1672 th->callback = NULL;
1655} 1673}
@@ -1662,7 +1680,7 @@ GNUNET_SERVER_notify_transmit_ready_cancel(struct GNUNET_SERVER_TransmitHandle *
1662 * @param client the client to set the persistent flag on 1680 * @param client the client to set the persistent flag on
1663 */ 1681 */
1664void 1682void
1665GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client) 1683GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client)
1666{ 1684{
1667 client->persist = GNUNET_YES; 1685 client->persist = GNUNET_YES;
1668} 1686}
@@ -1681,50 +1699,50 @@ GNUNET_SERVER_client_persist_(struct GNUNET_SERVER_Client *client)
1681 * serious error) 1699 * serious error)
1682 */ 1700 */
1683void 1701void
1684GNUNET_SERVER_receive_done(struct GNUNET_SERVER_Client *client, 1702GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client,
1685 int success) 1703 int success)
1686{ 1704{
1687 if (NULL == client) 1705 if (NULL == client)
1688 return; 1706 return;
1689 GNUNET_assert(client->suspended > 0); 1707 GNUNET_assert (client->suspended > 0);
1690 client->suspended--; 1708 client->suspended--;
1691 if (GNUNET_OK != success) 1709 if (GNUNET_OK != success)
1692 { 1710 {
1693 LOG(GNUNET_ERROR_TYPE_DEBUG, 1711 LOG (GNUNET_ERROR_TYPE_DEBUG,
1694 "GNUNET_SERVER_receive_done called with failure indication\n"); 1712 "GNUNET_SERVER_receive_done called with failure indication\n");
1695 if ((client->reference_count > 0) || (client->suspended > 0)) 1713 if ((client->reference_count > 0) || (client->suspended > 0))
1696 client->shutdown_now = GNUNET_YES; 1714 client->shutdown_now = GNUNET_YES;
1697 else 1715 else
1698 GNUNET_SERVER_client_disconnect(client); 1716 GNUNET_SERVER_client_disconnect (client);
1699 return; 1717 return;
1700 } 1718 }
1701 if (client->suspended > 0) 1719 if (client->suspended > 0)
1702 { 1720 {
1703 LOG(GNUNET_ERROR_TYPE_DEBUG, 1721 LOG (GNUNET_ERROR_TYPE_DEBUG,
1704 "GNUNET_SERVER_receive_done called, but more clients pending\n"); 1722 "GNUNET_SERVER_receive_done called, but more clients pending\n");
1705 return; 1723 return;
1706 } 1724 }
1707 if (NULL != client->warn_task) 1725 if (NULL != client->warn_task)
1708 { 1726 {
1709 GNUNET_SCHEDULER_cancel(client->warn_task); 1727 GNUNET_SCHEDULER_cancel (client->warn_task);
1710 client->warn_task = NULL; 1728 client->warn_task = NULL;
1711 } 1729 }
1712 if (GNUNET_YES == client->in_process_client_buffer) 1730 if (GNUNET_YES == client->in_process_client_buffer)
1713 { 1731 {
1714 LOG(GNUNET_ERROR_TYPE_DEBUG, 1732 LOG (GNUNET_ERROR_TYPE_DEBUG,
1715 "GNUNET_SERVER_receive_done called while still in processing loop\n"); 1733 "GNUNET_SERVER_receive_done called while still in processing loop\n");
1716 return; 1734 return;
1717 } 1735 }
1718 if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now)) 1736 if ((NULL == client->server) || (GNUNET_YES == client->shutdown_now))
1719 { 1737 {
1720 GNUNET_SERVER_client_disconnect(client); 1738 GNUNET_SERVER_client_disconnect (client);
1721 return; 1739 return;
1722 } 1740 }
1723 LOG(GNUNET_ERROR_TYPE_DEBUG, 1741 LOG (GNUNET_ERROR_TYPE_DEBUG,
1724 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n"); 1742 "GNUNET_SERVER_receive_done causes restart in reading from the socket\n");
1725 GNUNET_assert(NULL == client->restart_task); 1743 GNUNET_assert (NULL == client->restart_task);
1726 client->restart_task = GNUNET_SCHEDULER_add_now(&restart_processing, 1744 client->restart_task = GNUNET_SCHEDULER_add_now (&restart_processing,
1727 client); 1745 client);
1728} 1746}
1729 1747
1730 1748