diff options
Diffstat (limited to 'src/util/server.c')
-rw-r--r-- | src/util/server.c | 77 |
1 files changed, 28 insertions, 49 deletions
diff --git a/src/util/server.c b/src/util/server.c index 935cf04f8..504391bc7 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -381,9 +381,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
381 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 381 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
382 | if (port != 0) | 382 | if (port != 0) |
383 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 383 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
384 | _ | 384 | _("`%s' failed for port %d (%s).\n"), "bind", port, |
385 | ("`%s' failed for port %d (%s).\n"), | ||
386 | "bind", port, | ||
387 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); | 385 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); |
388 | eno = 0; | 386 | eno = 0; |
389 | } | 387 | } |
@@ -391,15 +389,12 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
391 | { | 389 | { |
392 | if (port != 0) | 390 | if (port != 0) |
393 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 391 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
394 | _ | 392 | _("`%s' failed for port %d (%s): address already in use\n"), |
395 | ("`%s' failed for port %d (%s): address already in use\n"), | ||
396 | "bind", port, | 393 | "bind", port, |
397 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); | 394 | (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); |
398 | else if (serverAddr->sa_family == AF_UNIX) | 395 | else if (serverAddr->sa_family == AF_UNIX) |
399 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 396 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
400 | _ | 397 | _("`%s' failed for `%s': address already in use\n"), "bind", |
401 | ("`%s' failed for `%s': address already in use\n"), | ||
402 | "bind", | ||
403 | ((const struct sockaddr_un *) serverAddr)->sun_path); | 398 | ((const struct sockaddr_un *) serverAddr)->sun_path); |
404 | 399 | ||
405 | } | 400 | } |
@@ -483,12 +478,11 @@ GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access, | |||
483 | * (typically, "port" already in use) | 478 | * (typically, "port" already in use) |
484 | */ | 479 | */ |
485 | struct GNUNET_SERVER_Handle * | 480 | struct GNUNET_SERVER_Handle * |
486 | GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, | 481 | GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, void *access_cls, |
487 | void *access_cls, | ||
488 | struct sockaddr *const *serverAddr, | 482 | struct sockaddr *const *serverAddr, |
489 | const socklen_t * socklen, | 483 | const socklen_t * socklen, |
490 | struct GNUNET_TIME_Relative | 484 | struct GNUNET_TIME_Relative idle_timeout, |
491 | idle_timeout, int require_found) | 485 | int require_found) |
492 | { | 486 | { |
493 | struct GNUNET_NETWORK_Handle **lsocks; | 487 | struct GNUNET_NETWORK_Handle **lsocks; |
494 | unsigned int i; | 488 | unsigned int i; |
@@ -521,8 +515,7 @@ GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access, | |||
521 | { | 515 | { |
522 | lsocks = NULL; | 516 | lsocks = NULL; |
523 | } | 517 | } |
524 | return GNUNET_SERVER_create_with_sockets (access, access_cls, | 518 | return GNUNET_SERVER_create_with_sockets (access, access_cls, lsocks, |
525 | lsocks, | ||
526 | idle_timeout, require_found); | 519 | idle_timeout, require_found); |
527 | } | 520 | } |
528 | 521 | ||
@@ -610,17 +603,17 @@ warn_no_receive_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
610 | { | 603 | { |
611 | struct GNUNET_SERVER_Client *client = cls; | 604 | struct GNUNET_SERVER_Client *client = cls; |
612 | 605 | ||
613 | client->warn_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | 606 | client->warn_task = |
614 | &warn_no_receive_done, | 607 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
615 | client); | 608 | &warn_no_receive_done, client); |
616 | if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 609 | if (0 == (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) |
617 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 610 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
618 | _ | 611 | _ |
619 | ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), | 612 | ("Processing code for message of type %u did not call GNUNET_SERVER_receive_done after %llums\n"), |
620 | (unsigned int) client->warn_type, | 613 | (unsigned int) client->warn_type, |
621 | (unsigned long long) | 614 | (unsigned long long) GNUNET_TIME_absolute_get_duration (client-> |
622 | GNUNET_TIME_absolute_get_duration | 615 | warn_start). |
623 | (client->warn_start).rel_value); | 616 | rel_value); |
624 | } | 617 | } |
625 | 618 | ||
626 | 619 | ||
@@ -737,11 +730,9 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, | |||
737 | * @param addrlen length of addr | 730 | * @param addrlen length of addr |
738 | * @param errCode code indicating errors receiving, 0 for success | 731 | * @param errCode code indicating errors receiving, 0 for success |
739 | */ | 732 | */ |
740 | static void | 733 | static void process_incoming (void *cls, const void *buf, size_t available, |
741 | process_incoming (void *cls, | 734 | const struct sockaddr *addr, socklen_t addrlen, |
742 | const void *buf, | 735 | int errCode); |
743 | size_t available, | ||
744 | const struct sockaddr *addr, socklen_t addrlen, int errCode); | ||
745 | 736 | ||
746 | 737 | ||
747 | /** | 738 | /** |
@@ -760,8 +751,7 @@ process_incoming (void *cls, | |||
760 | static void | 751 | static void |
761 | process_mst (struct GNUNET_SERVER_Client *client, int ret) | 752 | process_mst (struct GNUNET_SERVER_Client *client, int ret) |
762 | { | 753 | { |
763 | while ((ret != GNUNET_SYSERR) && | 754 | while ((ret != GNUNET_SYSERR) && (client->server != NULL) && |
764 | (client->server != NULL) && | ||
765 | (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) | 755 | (GNUNET_YES != client->shutdown_now) && (0 == client->suspended)) |
766 | { | 756 | { |
767 | if (ret == GNUNET_OK) | 757 | if (ret == GNUNET_OK) |
@@ -774,8 +764,8 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) | |||
774 | #endif | 764 | #endif |
775 | GNUNET_CONNECTION_receive (client->connection, | 765 | GNUNET_CONNECTION_receive (client->connection, |
776 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, | 766 | GNUNET_SERVER_MAX_MESSAGE_SIZE - 1, |
777 | client->idle_timeout, | 767 | client->idle_timeout, &process_incoming, |
778 | &process_incoming, client); | 768 | client); |
779 | break; | 769 | break; |
780 | } | 770 | } |
781 | #if DEBUG_SERVER | 771 | #if DEBUG_SERVER |
@@ -817,9 +807,7 @@ process_mst (struct GNUNET_SERVER_Client *client, int ret) | |||
817 | * @param errCode code indicating errors receiving, 0 for success | 807 | * @param errCode code indicating errors receiving, 0 for success |
818 | */ | 808 | */ |
819 | static void | 809 | static void |
820 | process_incoming (void *cls, | 810 | process_incoming (void *cls, const void *buf, size_t available, |
821 | const void *buf, | ||
822 | size_t available, | ||
823 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | 811 | const struct sockaddr *addr, socklen_t addrlen, int errCode) |
824 | { | 812 | { |
825 | struct GNUNET_SERVER_Client *client = cls; | 813 | struct GNUNET_SERVER_Client *client = cls; |
@@ -834,8 +822,7 @@ process_incoming (void *cls, | |||
834 | end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); | 822 | end = GNUNET_TIME_absolute_add (client->last_activity, client->idle_timeout); |
835 | 823 | ||
836 | if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && | 824 | if ((buf == NULL) && (available == 0) && (addr == NULL) && (errCode == 0) && |
837 | (client->shutdown_now != GNUNET_YES) && | 825 | (client->shutdown_now != GNUNET_YES) && (server != NULL) && |
838 | (server != NULL) && | ||
839 | (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && | 826 | (GNUNET_YES == GNUNET_CONNECTION_check (client->connection)) && |
840 | (end.abs_value > now.abs_value)) | 827 | (end.abs_value > now.abs_value)) |
841 | { | 828 | { |
@@ -852,10 +839,7 @@ process_incoming (void *cls, | |||
852 | &process_incoming, client); | 839 | &process_incoming, client); |
853 | return; | 840 | return; |
854 | } | 841 | } |
855 | if ((buf == NULL) || | 842 | if ((buf == NULL) || (available == 0) || (errCode != 0) || (server == NULL) || |
856 | (available == 0) || | ||
857 | (errCode != 0) || | ||
858 | (server == NULL) || | ||
859 | (client->shutdown_now == GNUNET_YES) || | 843 | (client->shutdown_now == GNUNET_YES) || |
860 | (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) | 844 | (GNUNET_YES != GNUNET_CONNECTION_check (client->connection))) |
861 | { | 845 | { |
@@ -864,8 +848,7 @@ process_incoming (void *cls, | |||
864 | return; | 848 | return; |
865 | } | 849 | } |
866 | #if DEBUG_SERVER | 850 | #if DEBUG_SERVER |
867 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server receives %u bytes from `%s'.\n", |
868 | "Server receives %u bytes from `%s'.\n", | ||
869 | (unsigned int) available, GNUNET_a2s (addr, addrlen)); | 852 | (unsigned int) available, GNUNET_a2s (addr, addrlen)); |
870 | #endif | 853 | #endif |
871 | GNUNET_SERVER_client_keep (client); | 854 | GNUNET_SERVER_client_keep (client); |
@@ -928,8 +911,7 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
928 | * @param message the actual message | 911 | * @param message the actual message |
929 | */ | 912 | */ |
930 | static void | 913 | static void |
931 | client_message_tokenizer_callback (void *cls, | 914 | client_message_tokenizer_callback (void *cls, void *client, |
932 | void *client, | ||
933 | const struct GNUNET_MessageHeader *message) | 915 | const struct GNUNET_MessageHeader *message) |
934 | { | 916 | { |
935 | struct GNUNET_SERVER_Handle *server = cls; | 917 | struct GNUNET_SERVER_Handle *server = cls; |
@@ -963,17 +945,15 @@ client_message_tokenizer_callback (void *cls, | |||
963 | * "client_drop" on the return value eventually) | 945 | * "client_drop" on the return value eventually) |
964 | */ | 946 | */ |
965 | struct GNUNET_SERVER_Client * | 947 | struct GNUNET_SERVER_Client * |
966 | GNUNET_SERVER_connect_socket (struct | 948 | GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, |
967 | GNUNET_SERVER_Handle | ||
968 | *server, | ||
969 | struct GNUNET_CONNECTION_Handle *connection) | 949 | struct GNUNET_CONNECTION_Handle *connection) |
970 | { | 950 | { |
971 | struct GNUNET_SERVER_Client *client; | 951 | struct GNUNET_SERVER_Client *client; |
972 | 952 | ||
973 | client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); | 953 | client = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Client)); |
974 | client->connection = connection; | 954 | client->connection = connection; |
975 | client->mst = GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, | 955 | client->mst = |
976 | server); | 956 | GNUNET_SERVER_mst_create (&client_message_tokenizer_callback, server); |
977 | client->reference_count = 1; | 957 | client->reference_count = 1; |
978 | client->server = server; | 958 | client->server = server; |
979 | client->last_activity = GNUNET_TIME_absolute_get (); | 959 | client->last_activity = GNUNET_TIME_absolute_get (); |
@@ -1274,8 +1254,7 @@ GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | |||
1274 | { | 1254 | { |
1275 | client->callback_cls = callback_cls; | 1255 | client->callback_cls = callback_cls; |
1276 | client->callback = callback; | 1256 | client->callback = callback; |
1277 | return GNUNET_CONNECTION_notify_transmit_ready (client->connection, | 1257 | return GNUNET_CONNECTION_notify_transmit_ready (client->connection, size, |
1278 | size, | ||
1279 | timeout, | 1258 | timeout, |
1280 | &transmit_ready_callback_wrapper, | 1259 | &transmit_ready_callback_wrapper, |
1281 | client); | 1260 | client); |