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