From: Christian Grothoff Date: Fri, 15 Jan 2010 16:36:30 +0000 (+0000) Subject: making code work better with dual-stack, preparing for triple-stack X-Git-Tag: initial-import-from-subversion-38251~22962 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2ea6ea66581947fce7820357f9a260896ffd4199;p=oweals%2Fgnunet.git making code work better with dual-stack, preparing for triple-stack --- diff --git a/src/util/server.c b/src/util/server.c index 72eceac44..036c8a441 100644 --- a/src/util/server.c +++ b/src/util/server.c @@ -111,6 +111,12 @@ struct GNUNET_SERVER_Handle */ void *access_cls; + /** + * NULL-terminated array of sockets used to listen for new + * connections. + */ + struct GNUNET_NETWORK_Handle **listen_sockets; + /** * After how long should an idle connection time * out (on write). @@ -122,12 +128,6 @@ struct GNUNET_SERVER_Handle */ size_t maxbuf; - /** - * Socket used to listen for new connections. Set to - * "-1" by GNUNET_SERVER_destroy to initiate shutdown. - */ - struct GNUNET_NETWORK_Handle *listen_socket; - /** * Task scheduled to do the listening. */ @@ -265,8 +265,7 @@ struct GNUNET_SERVER_Client /** - * Scheduler says our listen socket is ready. - * Process it! + * Scheduler says our listen socket is ready. Process it! * * @param cls handle to our server for which we are processing the listen * socket @@ -280,10 +279,13 @@ process_listen_socket (void *cls, struct GNUNET_CONNECTION_Handle *sock; struct GNUNET_SERVER_Client *client; struct GNUNET_NETWORK_FDSet *r; + unsigned int i; server->listen_task = GNUNET_SCHEDULER_NO_TASK; r = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_set (r, server->listen_socket); + i = 0; + while (NULL != server->listen_sockets[i]) + GNUNET_NETWORK_fdset_set (r, server->listen_sockets[i++]); if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) { /* ignore shutdown, someone else will take care of it! */ @@ -297,27 +299,33 @@ process_listen_socket (void *cls, GNUNET_NETWORK_fdset_destroy (r); return; } - GNUNET_assert (GNUNET_NETWORK_fdset_isset - (tc->read_ready, server->listen_socket)); - sock = - GNUNET_CONNECTION_create_from_accept (tc->sched, server->access, - server->access_cls, - server->listen_socket, - server->maxbuf); - if (sock != NULL) + i = 0; + while (NULL != server->listen_sockets[i]) { + if (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_sockets[i])) + { + sock = + GNUNET_CONNECTION_create_from_accept (tc->sched, server->access, + server->access_cls, + server->listen_sockets[i], + server->maxbuf); + if (sock != NULL) + { #if DEBUG_SERVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server accepted incoming connection.\n"); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Server accepted incoming connection.\n"); #endif - client = GNUNET_SERVER_connect_socket (server, sock); - GNUNET_CONNECTION_ignore_shutdown (sock, server->clients_ignore_shutdown); - /* decrement reference count, we don't keep "client" alive */ - GNUNET_SERVER_client_drop (client); - } + client = GNUNET_SERVER_connect_socket (server, sock); + GNUNET_CONNECTION_ignore_shutdown (sock, server->clients_ignore_shutdown); + /* decrement reference count, we don't keep "client" alive */ + GNUNET_SERVER_client_drop (client); + } + } + i++; + } /* listen for more! */ server->listen_task = GNUNET_SCHEDULER_add_select (server->sched, - GNUNET_SCHEDULER_PRIORITY_HIGH, + GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, GNUNET_TIME_UNIT_FOREVER_REL, r, NULL, @@ -338,6 +346,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) const static int on = 1; struct GNUNET_NETWORK_Handle *sock; uint16_t port; + int eno; switch (serverAddr->sa_family) { @@ -348,39 +357,55 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) port = ntohs (((const struct sockaddr_in6 *) serverAddr)->sin6_port); break; default: - GNUNET_break (0); - return NULL; + port = 0; + break; } sock = GNUNET_NETWORK_socket_create (serverAddr->sa_family, SOCK_STREAM, 0); if (NULL == sock) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); + errno = 0; return NULL; - } - if (GNUNET_NETWORK_socket_setsockopt - (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) + } + if ( (port != 0) && + (GNUNET_NETWORK_socket_setsockopt + (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)) GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, - "setsockopt"); + "setsockopt"); /* bind the socket */ if (GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen) != GNUNET_OK) { - GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _ - ("`%s' failed for port %d. Is the service already running?\n"), - "bind", port); + eno = errno; + if (errno != EADDRINUSE) + { + /* we don't log 'EADDRINUSE' here since an IPv4 bind may + fail if we already took the port on IPv6; if both IPv4 and + IPv6 binds fail, then our caller will log using the + errno preserved in 'eno' */ + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); + if (port != 0) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ + ("`%s' failed for port %d (%s).\n"), + "bind", port, + (serverAddr->sa_family == AF_INET) ? "IPv4" : "IPv6"); + eno = 0; + } GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + errno = eno; return NULL; } if (GNUNET_OK != GNUNET_NETWORK_socket_listen (sock, 5)) { GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "listen"); GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); + errno = 0; return NULL; } #if DEBUG_SERVER - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Server starts to listen on port %u.\n", port); + if (port != 0) + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Server starts to listen on port %u.\n", port); #endif return sock; } @@ -392,8 +417,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) * @param sched scheduler to use * @param access function for access control * @param access_cls closure for access - * @param serverAddr address to listen on (including port), use NULL - * for internal server (no listening) + * @param serverAddr address to listen on (including port), NULL terminated array * @param socklen length of serverAddr * @param maxbuf maximum write buffer size for accepted sockets * @param idle_timeout after how long should we timeout idle connections? @@ -406,35 +430,61 @@ struct GNUNET_SERVER_Handle * GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched, GNUNET_CONNECTION_AccessCheck access, void *access_cls, - const struct sockaddr *serverAddr, - socklen_t socklen, + struct sockaddr *const *serverAddr, + const socklen_t *socklen, size_t maxbuf, struct GNUNET_TIME_Relative - idle_timeout, int require_found) + idle_timeout, + int require_found) { struct GNUNET_SERVER_Handle *ret; - struct GNUNET_NETWORK_Handle *lsock; + struct GNUNET_NETWORK_Handle **lsocks; struct GNUNET_NETWORK_FDSet *r; + unsigned int i; + unsigned int j; - lsock = NULL; - if (serverAddr != NULL) + i = 0; + while (serverAddr[i] != NULL) + i++; + if (i > 0) + { + lsocks = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle*) * (i+1)); + i = 0; + j = 0; + while (serverAddr[i] != NULL) + { + lsocks[j] = open_listen_socket (serverAddr[i], socklen[i]); + if (lsocks[j] != NULL) + j++; + i++; + } + if (j == 0) + { + if (errno != 0) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); + GNUNET_free (lsocks); + lsocks = NULL; + } + } + else { - lsock = open_listen_socket (serverAddr, socklen); - if (lsock == NULL) - return NULL; + lsocks = NULL; } ret = GNUNET_malloc (sizeof (struct GNUNET_SERVER_Handle)); ret->sched = sched; ret->maxbuf = maxbuf; ret->idle_timeout = idle_timeout; - ret->listen_socket = lsock; + ret->listen_sockets = lsocks; ret->access = access; ret->access_cls = access_cls; ret->require_found = require_found; - if (lsock != NULL) + if (lsocks != NULL) { + r = GNUNET_NETWORK_fdset_create (); - GNUNET_NETWORK_fdset_set (r, ret->listen_socket); + i = 0; + while (NULL != ret->listen_sockets[i]) + GNUNET_NETWORK_fdset_set (r, ret->listen_sockets[i++]); ret->listen_task = GNUNET_SCHEDULER_add_select (sched, GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_SCHEDULER_NO_TASK, @@ -457,6 +507,7 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) struct GNUNET_SERVER_Client *pos; struct HandlerList *hpos; struct NotifyList *npos; + unsigned int i; #if DEBUG_SERVER GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n"); @@ -466,8 +517,14 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s) GNUNET_SCHEDULER_cancel (s->sched, s->listen_task); s->listen_task = GNUNET_SCHEDULER_NO_TASK; } - GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s->listen_socket)); - s->listen_socket = NULL; + if (s->listen_sockets != NULL) + { + i = 0; + while (s->listen_sockets[i] != NULL) + GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (s->listen_sockets[i++])); + GNUNET_free (s->listen_sockets); + s->listen_sockets = NULL; + } while (s->clients != NULL) { pos = s->clients; diff --git a/src/util/service.c b/src/util/service.c index 034cff170..af17a7f3e 100644 --- a/src/util/service.c +++ b/src/util/service.c @@ -35,6 +35,8 @@ #include "gnunet_server_lib.h" #include "gnunet_service_lib.h" +#define DEBUG_SERVICE GNUNET_NO + /* ******************* access control ******************** */ /** @@ -433,9 +435,9 @@ struct GNUNET_SERVICE_Context struct GNUNET_SCHEDULER_Handle *sched; /** - * Address to bind to. + * NULL-terminated array of addresses to bind to. */ - struct sockaddr *addr; + struct sockaddr **addrs; /** * Name of our service. @@ -519,9 +521,9 @@ struct GNUNET_SERVICE_Context enum GNUNET_SERVICE_Options options; /** - * Length of addr. + * Array of the lengths of the entries in addrs. */ - socklen_t addrlen; + socklen_t * addrlens; }; @@ -766,8 +768,10 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) struct addrinfo hints; struct addrinfo *res; struct addrinfo *pos; + struct addrinfo *next; int ret; int tolerant; + unsigned int i; struct GNUNET_NETWORK_Handle *desc; if (GNUNET_CONFIGURATION_have_value (sctx->cfg, @@ -884,6 +888,12 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) if (hostname != NULL) { +#if DEBUG_SERVICE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Resolving `%s' since that is where `%s' will bind to.\n", + hostname, + sctx->serviceName); +#endif memset (&hints, 0, sizeof (struct addrinfo)); if (disablev6) hints.ai_family = AF_INET; @@ -896,13 +906,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) GNUNET_free (hostname); return GNUNET_SYSERR; } - pos = res; - while ((NULL != pos) && - (((disablev6) && - (pos->ai_family != AF_INET)) || - ((pos->ai_family != AF_INET) && (pos->ai_family != AF_INET6)))) - pos = pos->ai_next; - if (pos == NULL) + next = res; + i = 0; + while (NULL != (pos = next)) + { + next = pos->ai_next; + if ( (disablev6) && (pos->ai_family == AF_INET6)) + continue; + i++; + } + if (0 == i) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Failed to find %saddress for `%s'.\n"), @@ -911,32 +924,42 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) GNUNET_free (hostname); return GNUNET_SYSERR; } + sctx->addrs = GNUNET_malloc ((i+1) * sizeof(struct sockaddr*)); + sctx->addrlens = GNUNET_malloc ((i+1) * sizeof (socklen_t)); + i = 0; + next = res; + while (NULL != (pos = next)) + { + next = pos->ai_next; + if ( (disablev6) && (pos->ai_family == AF_INET6)) + continue; +#if DEBUG_SERVICE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Service `%s' will bind to `%s'\n", + sctx->serviceName, + GNUNET_a2s (pos->ai_addr, + pos->ai_addrlen)); +#endif + if (pos->ai_family == AF_INET) + { + GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); + sctx->addrlens[i] = pos->ai_addrlen; + sctx->addrs[i] = GNUNET_malloc (sctx->addrlens[i]); + memcpy (sctx->addrs[i], pos->ai_addr, sctx->addrlens[i]); + ((struct sockaddr_in *) sctx->addrs[i])->sin_port = htons (port); + } + else + { + GNUNET_assert (pos->ai_family == AF_INET6); + GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); + sctx->addrlens[i] = pos->ai_addrlen; + sctx->addrs[i] = GNUNET_malloc (sctx->addrlens[i]); + memcpy (sctx->addrs[i], pos->ai_addr, sctx->addrlens[i]); + ((struct sockaddr_in6 *) sctx->addrs[i])->sin6_port = htons (port); + } + i++; + } GNUNET_free (hostname); - if (pos->ai_family == AF_INET) - { - GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in)); - sctx->addrlen = pos->ai_addrlen; - sctx->addr = GNUNET_malloc (sctx->addrlen); - memcpy (sctx->addr, res->ai_addr, sctx->addrlen); - ((struct sockaddr_in *) sctx->addr)->sin_port = htons (port); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Configured to bind to %s address; %s connections to this service will fail!\n"), - "IPv4", "IPv6"); - } - else - { - GNUNET_assert (pos->ai_family == AF_INET6); - GNUNET_assert (pos->ai_addrlen == sizeof (struct sockaddr_in6)); - sctx->addrlen = pos->ai_addrlen; - sctx->addr = GNUNET_malloc (sctx->addrlen); - memcpy (sctx->addr, res->ai_addr, sctx->addrlen); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Configured to bind to %s address; %s connections to this service will fail!\n"), - "IPv6", "IPv4"); - ((struct sockaddr_in6 *) sctx->addr)->sin6_port = htons (port); - } freeaddrinfo (res); } else @@ -945,28 +968,38 @@ setup_service (struct GNUNET_SERVICE_Context *sctx) if (disablev6) { /* V4-only */ - sctx->addrlen = sizeof (struct sockaddr_in); - sctx->addr = GNUNET_malloc (sctx->addrlen); + sctx->addrs = GNUNET_malloc (2 * sizeof(struct sockaddr*)); + sctx->addrlens = GNUNET_malloc (2 * sizeof (socklen_t)); + sctx->addrlens[0] = sizeof (struct sockaddr_in); + sctx->addrs[0] = GNUNET_malloc (sctx->addrlens[0]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in *) sctx->addr)->sin_len = sctx->addrlen; + ((struct sockaddr_in *) sctx->addrs[0])->sin_len = sctx->addrlens[0]; #endif - ((struct sockaddr_in *) sctx->addr)->sin_family = AF_INET; - ((struct sockaddr_in *) sctx->addr)->sin_port = htons (port); - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _ - ("Configured to bind to %s address; %s connections to this service will fail!\n"), - "IPv4", "IPv6"); + ((struct sockaddr_in *) sctx->addrs[0])->sin_family = AF_INET; + ((struct sockaddr_in *) sctx->addrs[0])->sin_port = htons (port); } else { /* dual stack */ - sctx->addrlen = sizeof (struct sockaddr_in6); - sctx->addr = GNUNET_malloc (sctx->addrlen); + sctx->addrs = GNUNET_malloc (3 * sizeof(struct sockaddr*)); + sctx->addrlens = GNUNET_malloc (3 * sizeof (socklen_t)); + + sctx->addrlens[0] = sizeof (struct sockaddr_in6); + sctx->addrs[0] = GNUNET_malloc (sctx->addrlens[0]); +#if HAVE_SOCKADDR_IN_SIN_LEN + ((struct sockaddr_in6 *) sctx->addrs[0])->sin6_len = sctx->addrlen[0]; +#endif + ((struct sockaddr_in6 *) sctx->addrs[0])->sin6_family = AF_INET6; + ((struct sockaddr_in6 *) sctx->addrs[0])->sin6_port = htons (port); + + sctx->addrlens[1] = sizeof (struct sockaddr_in); + sctx->addrs[1] = GNUNET_malloc (sctx->addrlens[1]); #if HAVE_SOCKADDR_IN_SIN_LEN - ((struct sockaddr_in6 *) sctx->addr)->sin6_len = sctx->addrlen; + ((struct sockaddr_in *) sctx->addrs[1])->sin_len = sctx->addrlens[1]; #endif - ((struct sockaddr_in6 *) sctx->addr)->sin6_family = AF_INET6; - ((struct sockaddr_in6 *) sctx->addr)->sin6_port = htons (port); + ((struct sockaddr_in *) sctx->addrs[1])->sin_family = AF_INET; + ((struct sockaddr_in *) sctx->addrs[1])->sin_port = htons (port); + } } sctx->maxbuf = (size_t) maxbuf; @@ -1090,15 +1123,21 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sctx->server = GNUNET_SERVER_create (tc->sched, &check_access, sctx, - sctx->addr, - sctx->addrlen, + sctx->addrs, + sctx->addrlens, sctx->maxbuf, sctx->timeout, sctx->require_found); if (sctx->server == NULL) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Failed to start `%s' at `%s'\n"), - sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen)); + i = 0; + while (sctx->addrs[i] != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Failed to start `%s' at `%s'\n"), + sctx->serviceName, + GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); + i++; + } sctx->ret = GNUNET_SYSERR; return; } @@ -1123,9 +1162,15 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) sctx->ready_confirm_fd = -1; write_pid_file (sctx, getpid ()); } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - _("Service `%s' runs at %s\n"), - sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen)); + i = 0; + while (sctx->addrs[i] != NULL) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _("Service `%s' runs at %s\n"), + sctx->serviceName, + GNUNET_a2s (sctx->addrs[i], sctx->addrlens[i])); + i++; + } sctx->task (sctx->task_cls, tc->sched, sctx->server, sctx->cfg); } @@ -1295,6 +1340,7 @@ GNUNET_SERVICE_run (int argc, char *loglev; char *logfile; int do_daemonize; + unsigned int i; struct GNUNET_SERVICE_Context sctx; struct GNUNET_CONFIGURATION_Handle *cfg; struct GNUNET_GETOPT_CommandLineOption service_options[] = { @@ -1358,7 +1404,11 @@ shutdown: } GNUNET_CONFIGURATION_destroy (cfg); - GNUNET_free_non_null (sctx.addr); + i = 0; + while (sctx.addrs[i] != NULL) + GNUNET_free (sctx.addrs[i++]); + GNUNET_free_non_null (sctx.addrs); + GNUNET_free_non_null (sctx.addrlens); GNUNET_free_non_null (logfile); GNUNET_free (loglev); GNUNET_free (cfg_fn); @@ -1402,8 +1452,8 @@ GNUNET_SERVICE_start (const char *serviceName, (NULL == (sctx->server = GNUNET_SERVER_create (sched, &check_access, sctx, - sctx->addr, - sctx->addrlen, + sctx->addrs, + sctx->addrlens, sctx->maxbuf, sctx->timeout, sctx->require_found)))) @@ -1442,10 +1492,15 @@ GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx) void GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Context *sctx) { + unsigned int i; if (NULL != sctx->server) GNUNET_SERVER_destroy (sctx->server); GNUNET_free_non_null (sctx->my_handlers); - GNUNET_free_non_null (sctx->addr); + i = 0; + while (sctx->addrs[i] != NULL) + GNUNET_free (sctx->addrs[i++]); + GNUNET_free_non_null (sctx->addrs); + GNUNET_free_non_null (sctx->addrlens); GNUNET_free_non_null (sctx->v4_denied); GNUNET_free_non_null (sctx->v6_denied); GNUNET_free_non_null (sctx->v4_allowed); diff --git a/src/util/test_client.c b/src/util/test_client.c index 4811e8776..aa8b93a82 100644 --- a/src/util/test_client.c +++ b/src/util/test_client.c @@ -137,7 +137,13 @@ static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_in sa; + struct sockaddr * sap[2]; + socklen_t slens[2]; + sap[0] = (struct sockaddr*) &sa; + slens[0] = sizeof (sa); + sap[1] = NULL; + slens[1] = 0; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN sa.sin_len = sizeof (sa); @@ -147,8 +153,8 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) server = GNUNET_SERVER_create (tc->sched, NULL, NULL, - (const struct sockaddr *) &sa, - sizeof (sa), + sap, + slens, 1024, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 10000), diff --git a/src/util/test_server.c b/src/util/test_server.c index 95206c0f1..901b78a08 100644 --- a/src/util/test_server.c +++ b/src/util/test_server.c @@ -232,7 +232,13 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_in sa; struct GNUNET_MessageHeader msg; + struct sockaddr * sap[2]; + socklen_t slens[2]; + sap[0] = (struct sockaddr*) &sa; + slens[0] = sizeof (sa); + sap[1] = NULL; + slens[1] = 0; sched = tc->sched; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN @@ -243,8 +249,8 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) server = GNUNET_SERVER_create (tc->sched, NULL, NULL, - (const struct sockaddr *) &sa, - sizeof (sa), + sap, + slens, 1024, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c index 7b35647ea..76a73d348 100644 --- a/src/util/test_server_disconnect.c +++ b/src/util/test_server_disconnect.c @@ -174,7 +174,13 @@ static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_in sa; + struct sockaddr * sap[2]; + socklen_t slens[2]; + sap[0] = (struct sockaddr*) &sa; + slens[0] = sizeof (sa); + sap[1] = NULL; + slens[1] = 0; sched = tc->sched; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN @@ -185,8 +191,8 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) server = GNUNET_SERVER_create (tc->sched, NULL, NULL, - (const struct sockaddr *) &sa, - sizeof (sa), + sap, + slens, 1024, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c index f22c15300..68b842ef8 100644 --- a/src/util/test_server_with_client.c +++ b/src/util/test_server_with_client.c @@ -158,7 +158,13 @@ static void task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct sockaddr_in sa; + struct sockaddr * sap[2]; + socklen_t slens[2]; + sap[0] = (struct sockaddr*) &sa; + slens[0] = sizeof (sa); + sap[1] = NULL; + slens[1] = 0; sched = tc->sched; memset (&sa, 0, sizeof (sa)); #if HAVE_SOCKADDR_IN_SIN_LEN @@ -169,8 +175,8 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) server = GNUNET_SERVER_create (tc->sched, NULL, NULL, - (const struct sockaddr *) &sa, - sizeof (sa), + sap, + slens, 1024, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250), diff --git a/src/util/test_service.c b/src/util/test_service.c index dce66d398..a40630c64 100644 --- a/src/util/test_service.c +++ b/src/util/test_service.c @@ -76,15 +76,16 @@ build_msg (void *cls, size_t size, void *buf) return sizeof (struct GNUNET_MessageHeader); } + static void ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct GNUNET_CLIENT_Connection *client; + GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Service confirmed running\n"); sched = tc->sched; - GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE)); client = GNUNET_CLIENT_connect (tc->sched, "test_service", cfg); GNUNET_assert (client != NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,