summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/Makefile.am6
-rw-r--r--src/util/bandwidth.c20
-rw-r--r--src/util/client.c13
-rw-r--r--src/util/helper.c2
-rw-r--r--src/util/mst.c4
-rw-r--r--src/util/resolver_api.c2
-rw-r--r--src/util/server_mst.c313
-rw-r--r--src/util/server_nc.c472
-rw-r--r--src/util/server_tc.c242
-rw-r--r--src/util/service.c10
-rw-r--r--src/util/test_client.c2
-rw-r--r--src/util/test_service.c2
12 files changed, 35 insertions, 1053 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index 2ca977065..9be572bb6 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -30,9 +30,9 @@ W32CONSOLEHELPER = gnunet-helper-w32-console
endif
if !MINGW
- TEST_CLIENT_UNIC_NC = test_client_unix.nc
+ TEST_CLIENT_UNIX_NC = test_client_unix.nc
else
- TEST_CLIENT_UNIC_NC =
+ TEST_CLIENT_UNIX_NC =
endif
if USE_COVERAGE
@@ -106,7 +106,7 @@ libgnunetutil_la_SOURCES = \
program.c \
resolver_api.c resolver.h \
scheduler.c \
- service_new.c \
+ service.c \
signal.c \
strings.c \
time.c \
diff --git a/src/util/bandwidth.c b/src/util/bandwidth.c
index a059fc738..bc0c3b9b4 100644
--- a/src/util/bandwidth.c
+++ b/src/util/bandwidth.c
@@ -184,8 +184,8 @@ update_excess (struct GNUNET_BANDWIDTH_Tracker *av)
}
/* negative current_consumption means that we have savings */
max_carry = ((uint64_t) av->available_bytes_per_s__) * av->max_carry_s__;
- if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE)
- max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE;
+ if (max_carry < GNUNET_MAX_MESSAGE_SIZE)
+ max_carry = GNUNET_MAX_MESSAGE_SIZE;
if (max_carry > INT64_MAX)
max_carry = INT64_MAX;
left_bytes = current_consumption + max_carry;
@@ -224,10 +224,10 @@ update_excess (struct GNUNET_BANDWIDTH_Tracker *av)
/**
* Initialize bandwidth tracker. Note that in addition to the
* 'max_carry_s' limit, we also always allow at least
- * #GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. So if the
+ * #GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the
* bytes-per-second limit is so small that within 'max_carry_s' not
- * even #GNUNET_SERVER_MAX_MESSAGE_SIZE is allowed to accumulate, it is
- * ignored and replaced by #GNUNET_SERVER_MAX_MESSAGE_SIZE (which is in
+ * even #GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is
+ * ignored and replaced by #GNUNET_MAX_MESSAGE_SIZE (which is in
* bytes).
*
* To stop notifications about updates and excess callbacks use
@@ -271,10 +271,10 @@ GNUNET_BANDWIDTH_tracker_init2 (struct GNUNET_BANDWIDTH_Tracker *av,
/**
* Initialize bandwidth tracker. Note that in addition to the
* 'max_carry_s' limit, we also always allow at least
- * #GNUNET_SERVER_MAX_MESSAGE_SIZE to accumulate. So if the
+ * #GNUNET_MAX_MESSAGE_SIZE to accumulate. So if the
* bytes-per-second limit is so small that within 'max_carry_s' not
- * even #GNUNET_SERVER_MAX_MESSAGE_SIZE is allowed to accumulate, it is
- * ignored and replaced by #GNUNET_SERVER_MAX_MESSAGE_SIZE (which is in
+ * even #GNUNET_MAX_MESSAGE_SIZE is allowed to accumulate, it is
+ * ignored and replaced by #GNUNET_MAX_MESSAGE_SIZE (which is in
* bytes).
*
* @param av tracker to initialize
@@ -345,8 +345,8 @@ update_tracker (struct GNUNET_BANDWIDTH_Tracker *av)
left_bytes = - av->consumption_since_last_update__;
max_carry = ((unsigned long long) av->available_bytes_per_s__) *
av->max_carry_s__;
- if (max_carry < GNUNET_SERVER_MAX_MESSAGE_SIZE)
- max_carry = GNUNET_SERVER_MAX_MESSAGE_SIZE;
+ if (max_carry < GNUNET_MAX_MESSAGE_SIZE)
+ max_carry = GNUNET_MAX_MESSAGE_SIZE;
if (max_carry > INT64_MAX)
max_carry = INT64_MAX;
if (max_carry > left_bytes)
diff --git a/src/util/client.c b/src/util/client.c
index 163ae6eb9..3d74bff33 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -35,6 +35,15 @@
#define LOG(kind,...) GNUNET_log_from (kind, "util-client",__VA_ARGS__)
+/**
+ * Timeout we use on TCP connect before trying another
+ * result from the DNS resolver. Actual value used
+ * is this value divided by the number of address families.
+ * Default is 5s.
+ */
+#define CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+
+
/**
* Internal state for a client connected to a GNUnet service.
@@ -656,7 +665,7 @@ try_connect_using_address (void *cls,
GNUNET_CONTAINER_DLL_insert (cstate->ap_head,
cstate->ap_tail,
ap);
- ap->task = GNUNET_SCHEDULER_add_write_net (GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
+ ap->task = GNUNET_SCHEDULER_add_write_net (CONNECT_RETRY_TIMEOUT,
ap->sock,
&connect_probe_continuation,
ap);
@@ -760,7 +769,7 @@ start_connect (void *cls)
cstate->dns_active
= GNUNET_RESOLVER_ip_get (cstate->hostname,
AF_UNSPEC,
- GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
+ CONNECT_RETRY_TIMEOUT,
&try_connect_using_address,
cstate);
}
diff --git a/src/util/helper.c b/src/util/helper.c
index 1a79c477a..a84b06e66 100644
--- a/src/util/helper.c
+++ b/src/util/helper.c
@@ -323,7 +323,7 @@ static void
helper_read (void *cls)
{
struct GNUNET_HELPER_Handle *h = cls;
- char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
+ char buf[GNUNET_MAX_MESSAGE_SIZE] GNUNET_ALIGN;
ssize_t t;
h->read_task = NULL;
diff --git a/src/util/mst.c b/src/util/mst.c
index 9f1d30d7a..0d90c5d10 100644
--- a/src/util/mst.c
+++ b/src/util/mst.c
@@ -90,8 +90,8 @@ GNUNET_MST_create (GNUNET_MessageTokenizerCallback cb,
struct GNUNET_MessageStreamTokenizer *ret;
ret = GNUNET_new (struct GNUNET_MessageStreamTokenizer);
- ret->hdr = GNUNET_malloc (GNUNET_SERVER_MIN_BUFFER_SIZE);
- ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE;
+ ret->hdr = GNUNET_malloc (GNUNET_MIN_MESSAGE_SIZE);
+ ret->curr_buf = GNUNET_MIN_MESSAGE_SIZE;
ret->cb = cb;
ret->cb_cls = cb_cls;
return ret;
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index f33c31f1c..0c915932c 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -876,7 +876,7 @@ GNUNET_RESOLVER_ip_get (const char *hostname,
slen = strlen (hostname) + 1;
if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
- GNUNET_SERVER_MAX_MESSAGE_SIZE)
+ GNUNET_MAX_MESSAGE_SIZE)
{
GNUNET_break (0);
return NULL;
diff --git a/src/util/server_mst.c b/src/util/server_mst.c
deleted file mode 100644
index 5155b54da..000000000
--- a/src/util/server_mst.c
+++ /dev/null
@@ -1,313 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010 GNUnet e.V.
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-/**
- * @file util/server_mst.c
- * @brief convenience functions for handling inbound message buffers
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-
-
-#if HAVE_UNALIGNED_64_ACCESS
-#define ALIGN_FACTOR 4
-#else
-#define ALIGN_FACTOR 8
-#endif
-
-#define LOG(kind,...) GNUNET_log_from (kind, "util-server-mst", __VA_ARGS__)
-
-
-/**
- * Handle to a message stream tokenizer.
- */
-struct GNUNET_SERVER_MessageStreamTokenizer
-{
-
- /**
- * Function to call on completed messages.
- */
- GNUNET_SERVER_MessageTokenizerCallback cb;
-
- /**
- * Closure for @e cb.
- */
- void *cb_cls;
-
- /**
- * Size of the buffer (starting at @e hdr).
- */
- size_t curr_buf;
-
- /**
- * How many bytes in buffer have we already processed?
- */
- size_t off;
-
- /**
- * How many bytes in buffer are valid right now?
- */
- size_t pos;
-
- /**
- * Beginning of the buffer. Typed like this to force alignment.
- */
- struct GNUNET_MessageHeader *hdr;
-
-};
-
-
-
-/**
- * Create a message stream tokenizer.
- *
- * @param cb function to call on completed messages
- * @param cb_cls closure for @a cb
- * @return handle to tokenizer
- */
-struct GNUNET_SERVER_MessageStreamTokenizer *
-GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb,
- void *cb_cls)
-{
- struct GNUNET_SERVER_MessageStreamTokenizer *ret;
-
- ret = GNUNET_new (struct GNUNET_SERVER_MessageStreamTokenizer);
- ret->hdr = GNUNET_malloc (GNUNET_SERVER_MIN_BUFFER_SIZE);
- ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE;
- ret->cb = cb;
- ret->cb_cls = cb_cls;
- return ret;
-}
-
-
-/**
- * Add incoming data to the receive buffer and call the
- * callback for all complete messages.
- *
- * @param mst tokenizer to use
- * @param client_identity ID of client for which this is a buffer
- * @param buf input data to add
- * @param size number of bytes in @a buf
- * @param purge should any excess bytes in the buffer be discarded
- * (i.e. for packet-based services like UDP)
- * @param one_shot only call callback once, keep rest of message in buffer
- * @return #GNUNET_OK if we are done processing (need more data)
- * #GNUNET_NO if @a one_shot was set and we have another message ready
- * #GNUNET_SYSERR if the data stream is corrupt
- */
-int
-GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst,
- void *client_identity,
- const char *buf, size_t size,
- int purge, int one_shot)
-{
- const struct GNUNET_MessageHeader *hdr;
- size_t delta;
- uint16_t want;
- char *ibuf;
- int need_align;
- unsigned long offset;
- int ret;
-
- GNUNET_assert (mst->off <= mst->pos);
- GNUNET_assert (mst->pos <= mst->curr_buf);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server-mst receives %u bytes with %u bytes already in private buffer\n",
- (unsigned int) size, (unsigned int) (mst->pos - mst->off));
- ret = GNUNET_OK;
- ibuf = (char *) mst->hdr;
- while (mst->pos > 0)
- {
-do_align:
- GNUNET_assert (mst->pos >= mst->off);
- if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) ||
- (0 != (mst->off % ALIGN_FACTOR)))
- {
- /* need to align or need more space */
- mst->pos -= mst->off;
- memmove (ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
- {
- delta =
- GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) -
- (mst->pos - mst->off), size);
- GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader))
- {
- if (purge)
- {
- mst->off = 0;
- mst->pos = 0;
- }
- return GNUNET_OK;
- }
- hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
- want = ntohs (hdr->size);
- if (want < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
- if ( (mst->curr_buf - mst->off < want) &&
- (mst->off > 0) )
- {
- /* can get more space by moving */
- mst->pos -= mst->off;
- memmove (ibuf, &ibuf[mst->off], mst->pos);
- mst->off = 0;
- }
- if (mst->curr_buf < want)
- {
- /* need to get more space by growing buffer */
- GNUNET_assert (0 == mst->off);
- mst->hdr = GNUNET_realloc (mst->hdr, want);
- ibuf = (char *) mst->hdr;
- mst->curr_buf = want;
- }
- hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off];
- if (mst->pos - mst->off < want)
- {
- delta = GNUNET_MIN (want - (mst->pos - mst->off), size);
- GNUNET_assert (mst->pos + delta <= mst->curr_buf);
- GNUNET_memcpy (&ibuf[mst->pos], buf, delta);
- mst->pos += delta;
- buf += delta;
- size -= delta;
- }
- if (mst->pos - mst->off < want)
- {
- if (purge)
- {
- mst->off = 0;
- mst->pos = 0;
- }
- return GNUNET_OK;
- }
- if (one_shot == GNUNET_SYSERR)
- {
- /* cannot call callback again, but return value saying that
- * we have another full message in the buffer */
- ret = GNUNET_NO;
- goto copy;
- }
- if (one_shot == GNUNET_YES)
- one_shot = GNUNET_SYSERR;
- mst->off += want;
- if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr))
- return GNUNET_SYSERR;
- if (mst->off == mst->pos)
- {
- /* reset to beginning of buffer, it's free right now! */
- mst->off = 0;
- mst->pos = 0;
- }
- }
- GNUNET_assert (0 == mst->pos);
- while (size > 0)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server-mst has %u bytes left in inbound buffer\n",
- (unsigned int) size);
- if (size < sizeof (struct GNUNET_MessageHeader))
- break;
- offset = (unsigned long) buf;
- need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO;
- if (GNUNET_NO == need_align)
- {
- /* can try to do zero-copy and process directly from original buffer */
- hdr = (const struct GNUNET_MessageHeader *) buf;
- want = ntohs (hdr->size);
- if (want < sizeof (struct GNUNET_MessageHeader))
- {
- GNUNET_break_op (0);
- mst->off = 0;
- return GNUNET_SYSERR;
- }
- if (size < want)
- break; /* or not: buffer incomplete, so copy to private buffer... */
- if (one_shot == GNUNET_SYSERR)
- {
- /* cannot call callback again, but return value saying that
- * we have another full message in the buffer */
- ret = GNUNET_NO;
- goto copy;
- }
- if (one_shot == GNUNET_YES)
- one_shot = GNUNET_SYSERR;
- if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr))
- return GNUNET_SYSERR;
- buf += want;
- size -= want;
- }
- else
- {
- /* need to copy to private buffer to align;
- * yes, we go a bit more spagetti than usual here */
- goto do_align;
- }
- }
-copy:
- if ((size > 0) && (!purge))
- {
- if (size + mst->pos > mst->curr_buf)
- {
- mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos);
- ibuf = (char *) mst->hdr;
- mst->curr_buf = size + mst->pos;
- }
- GNUNET_assert (size + mst->pos <= mst->curr_buf);
- GNUNET_memcpy (&ibuf[mst->pos], buf, size);
- mst->pos += size;
- }
- if (purge)
- {
- mst->off = 0;
- mst->pos = 0;
- }
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Server-mst leaves %u bytes in private buffer\n",
- (unsigned int) (mst->pos - mst->off));
- return ret;
-}
-
-
-/**
- * Destroys a tokenizer.
- *
- * @param mst tokenizer to destroy
- */
-void
-GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst)
-{
- GNUNET_free (mst->hdr);
- GNUNET_free (mst);
-}
-
-
-
-/* end of server_mst.c */
diff --git a/src/util/server_nc.c b/src/util/server_nc.c
deleted file mode 100644
index a95cd7f6d..000000000
--- a/src/util/server_nc.c
+++ /dev/null
@@ -1,472 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2010 GNUnet e.V.
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-/**
- * @file util/server_nc.c
- * @brief convenience functions for transmission of
- * a notification stream
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-
-#define LOG(kind,...) GNUNET_log_from (kind, "util-server-nc", __VA_ARGS__)
-
-
-/**
- * Entry in list of messages pending to be transmitted.
- */
-struct PendingMessageList
-{
-
- /**
- * This is a doubly-linked list.
- */
- struct PendingMessageList *next;
-
- /**
- * This is a doubly-linked list.
- */
- struct PendingMessageList *prev;
-
- /**
- * Message to transmit (allocated at the end of this
- * struct, do not free)
- */
- const struct GNUNET_MessageHeader *msg;
-
- /**
- * Can this message be dropped?
- */
- int can_drop;
-
-};
-
-
-/**
- * Lists of clients we manage for notifications.
- */
-struct ClientList
-{
-
- /**
- * This is a doubly linked list.
- */
- struct ClientList *next;
-
- /**
- * This is a doubly linked list.
- */
- struct ClientList *prev;
-
- /**
- * Overall context this client belongs to.
- */
- struct GNUNET_SERVER_NotificationContext *nc;
-
- /**
- * Handle to the client.
- */
- struct GNUNET_SERVER_Client *client;
-
- /**
- * Handle for pending transmission request to the client (or NULL).
- */
- struct GNUNET_SERVER_TransmitHandle *th;
-
- /**
- * Head of linked list of requests queued for transmission.
- */
- struct PendingMessageList *pending_head;
-
- /**
- * Tail of linked list of requests queued for transmission.
- */
- struct PendingMessageList *pending_tail;
-
- /**
- * Number of messages currently in the list.
- */
- unsigned int num_pending;
-
-};
-
-
-/**
- * The notification context is the key datastructure for a convenience
- * API used for transmission of notifications to the client until the
- * client disconnects (or the notification context is destroyed, in
- * which case we disconnect these clients). Essentially, all
- * (notification) messages are queued up until the client is able to
- * read them.
- */
-struct GNUNET_SERVER_NotificationContext
-{
-
- /**
- * Server we do notifications for.
- */
- struct GNUNET_SERVER_Handle *server;
-
- /**
- * Head of list of clients receiving notifications.
- */
- struct ClientList *clients_head;
-
- /**
- * Tail of list of clients receiving notifications.
- */
- struct ClientList *clients_tail;
-
- /**
- * Maximum number of optional messages to queue per client.
- */
- unsigned int queue_length;
-
-};
-
-
-/**
- * Client has disconnected, clean up.
- *
- * @param cls our `struct GNUNET_SERVER_NotificationContext *`
- * @param client handle of client that disconnected
- */
-static void
-handle_client_disconnect (void *cls,
- struct GNUNET_SERVER_Client *client)
-{
- struct GNUNET_SERVER_NotificationContext *nc = cls;
- struct ClientList *pos;
- struct PendingMessageList *pml;
-
- if (NULL == client)
- {
- nc->server = NULL;
- return;
- }
- for (pos = nc->clients_head; NULL != pos; pos = pos->next)
- if (pos->client == client)
- break;
- if (NULL == pos)
- return;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Client disconnected, cleaning up %u messages in NC queue\n",
- pos->num_pending);
- GNUNET_CONTAINER_DLL_remove (nc->clients_head,
- nc->clients_tail,
- pos);
- while (NULL != (pml = pos->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->pending_head,
- pos->pending_tail,
- pml);
- GNUNET_free (pml);
- pos->num_pending--;
- }
- if (NULL != pos->th)
- {
- GNUNET_SERVER_notify_transmit_ready_cancel (pos->th);
- pos->th = NULL;
- }
- GNUNET_SERVER_client_drop (client);
- GNUNET_assert (0 == pos->num_pending);
- GNUNET_free (pos);
-}
-
-
-/**
- * Create a new notification context.
- *
- * @param server server for which this function creates the context
- * @param queue_length maximum number of messages to keep in
- * the notification queue; optional messages are dropped
- * if the queue gets longer than this number of messages
- * @return handle to the notification context
- */
-struct GNUNET_SERVER_NotificationContext *
-GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server,
- unsigned int queue_length)
-{
- struct GNUNET_SERVER_NotificationContext *ret;
-
- ret = GNUNET_new (struct GNUNET_SERVER_NotificationContext);
- ret->server = server;
- ret->queue_length = queue_length;
- GNUNET_SERVER_disconnect_notify (server,
- &handle_client_disconnect,
- ret);
- return ret;
-}
-
-
-/**
- * Destroy the context, force disconnect for all clients.
- *
- * @param nc context to destroy.
- */
-void
-GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationContext *nc)
-{
- struct ClientList *pos;
- struct PendingMessageList *pml;
-
- while (NULL != (pos = nc->clients_head))
- {
- GNUNET_CONTAINER_DLL_remove (nc->clients_head,
- nc->clients_tail,
- pos);
- if (NULL != pos->th)
- {
- GNUNET_SERVER_notify_transmit_ready_cancel (pos->th);
- pos->th = NULL;
- }
- GNUNET_SERVER_client_drop (pos->client);
- while (NULL != (pml = pos->pending_head))
- {
- GNUNET_CONTAINER_DLL_remove (pos->pending_head,
- pos->pending_tail,
- pml);
- GNUNET_free (pml);
- pos->num_pending--;
- }
- GNUNET_assert (0 == pos->num_pending);
- GNUNET_free (pos);
- }
- if (NULL != nc->server)
- GNUNET_SERVER_disconnect_notify_cancel (nc->server,
- &handle_client_disconnect,
- nc);
- GNUNET_free (nc);
-}
-
-
-/**
- * Add a client to the notification context.
- *
- * @param nc context to modify
- * @param client client to add
- */
-void
-GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext *nc,
- struct GNUNET_SERVER_Client *client)
-{
- struct ClientList *cl;
-
- for (cl = nc->clients_head; NULL != cl; cl = cl->next)
- if (cl->client == client)
- return; /* already present */
- cl = GNUNET_new (struct ClientList);
- GNUNET_CONTAINER_DLL_insert (nc->clients_head,
- nc->clients_tail,
- cl);
- cl->nc = nc;
- cl->client = client;
- GNUNET_SERVER_client_keep (client);
-}
-
-
-/**
- * Function called to notify a client about the socket begin ready to
- * queue more data. @a buf will be NULL and @a size zero if the socket
- * was closed for writing in the meantime.
- *
- * @param cls the `struct ClientList *`
- * @param size number of bytes available in @a buf
- * @param buf where the callee should write the message
- * @return number of bytes written to buf
- */
-static size_t
-transmit_message (void *cls,
- size_t size,
- void *buf)
-{
- struct ClientList *cl = cls;
- char *cbuf = buf;
- struct PendingMessageList *pml;
- uint16_t msize;
- size_t ret;
-
- cl->th = NULL;
- if (NULL == buf)
- {
- /* 'cl' should be freed via disconnect notification shortly */
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Failed to transmit message from NC queue to client\n");
- return 0;
- }
- ret = 0;
- while (NULL != (pml = cl->pending_head))
- {
- msize = ntohs (pml->msg->size);
- if (size < msize)
- break;
- GNUNET_CONTAINER_DLL_remove (cl->pending_head,
- cl->pending_tail,
- pml);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Copying message of type %u and size %u from pending queue to transmission buffer\n",
- ntohs (pml->msg->type),
- msize);
- GNUNET_memcpy (&cbuf[ret], pml->msg, msize);
- ret += msize;
- size -= msize;
- GNUNET_free (pml);
- cl->num_pending--;
- }
- if (NULL != pml)
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Have %u messages left in NC queue, will try transmission again\n",
- cl->num_pending);
- cl->th =
- GNUNET_SERVER_notify_transmit_ready (cl->client,
- ntohs (pml->msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_message, cl);
- }
- else
- {
- GNUNET_assert (0 == cl->num_pending);
- }
- return ret;
-}
-
-
-/**
- * Send a message to a particular client.
- *
- * @param nc context to modify
- * @param client client to transmit to
- * @param msg message to send
- * @param can_drop can this message be dropped due to queue length limitations
- */
-static void
-do_unicast (struct GNUNET_SERVER_NotificationContext *nc,
- struct ClientList *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
-{
- struct PendingMessageList *pml;
- uint16_t size;
-
- if ( (client->num_pending > nc->queue_length) &&
- (GNUNET_YES == can_drop) )
- {
- LOG (GNUNET_ERROR_TYPE_INFO,
- "Dropping message of type %u and size %u due to full queue (%u entries)\n",
- ntohs (msg->type), ntohs (msg->size), (unsigned int) nc->queue_length);
- return; /* drop! */
- }
- if (client->num_pending > nc->queue_length)
- {
- /* FIXME: consider checking for other messages in the
- * queue that are 'droppable' */
- }
- client->num_pending++;
- size = ntohs (msg->size);
- pml = GNUNET_malloc (sizeof (struct PendingMessageList) + size);
- pml->msg = (const struct GNUNET_MessageHeader *) &pml[1];
- pml->can_drop = can_drop;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Adding message of type %u and size %u to pending queue (which has %u entries)\n",
- ntohs (msg->type),
- ntohs (msg->size),
- (unsigned int) nc->queue_length);
- GNUNET_memcpy (&pml[1], msg, size);
- /* append */
- GNUNET_CONTAINER_DLL_insert_tail (client->pending_head,
- client->pending_tail,
- pml);
- if (NULL == client->th)
- client->th =
- GNUNET_SERVER_notify_transmit_ready (client->client,
- ntohs (client->pending_head->
- msg->size),
- GNUNET_TIME_UNIT_FOREVER_REL,
- &transmit_message, client);
-}
-
-
-/**
- * Send a message to a particular client; must have
- * already been added to the notification context.
- *
- * @param nc context to modify
- * @param client client to transmit to
- * @param msg message to send
- * @param can_drop can this message be dropped due to queue length limitations
- */
-void
-GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationContext *nc,
- struct GNUNET_SERVER_Client *client,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
-{
- struct ClientList *pos;
-
- for (pos = nc->clients_head; NULL != pos; pos = pos->next)
- if (pos->client == client)
- break;
- GNUNET_assert (NULL != pos);
- do_unicast (nc, pos, msg, can_drop);
-}
-
-
-/**
- * Send a message to all clients of this context.
- *
- * @param nc context to modify
- * @param msg message to send
- * @param can_drop can this message be dropped due to queue length limitations
- */
-void
-GNUNET_SERVER_notification_context_broadcast (struct
- GNUNET_SERVER_NotificationContext *nc,
- const struct GNUNET_MessageHeader *msg,
- int can_drop)
-{
- struct ClientList *pos;
-
- for (pos = nc->clients_head; NULL != pos; pos = pos->next)
- do_unicast (nc, pos, msg, can_drop);
-}
-
-
-/**
- * Return active number of subscribers in this context.
- *
- * @param nc context to query
- * @return number of current subscribers
- */
-unsigned int
-GNUNET_SERVER_notification_context_get_size (struct GNUNET_SERVER_NotificationContext *nc)
-{
- unsigned int num;
- struct ClientList *pos;
-
- num = 0;
- for (pos = nc->clients_head; NULL != pos; pos = pos->next)
- num++;
- return num;
-}
-
-/* end of server_nc.c */
diff --git a/src/util/server_tc.c b/src/util/server_tc.c
deleted file mode 100644
index 8ae380a85..000000000
--- a/src/util/server_tc.c
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- This file is part of GNUnet.
- Copyright (C) 2009 GNUnet e.V.
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA.
-*/
-
-/**
- * @file util/server_tc.c
- * @brief convenience functions for transmission of
- * complex responses as a server
- * @author Christian Grothoff
- */
-
-#include "platform.h"
-#include "gnunet_util_lib.h"
-
-
-#define LOG(kind,...) GNUNET_log_from (kind, "util-server-tc", __VA_ARGS__)
-
-
-/**
- * How much buffer space do we want to have at least
- * before transmitting another increment?
- */
-#define MIN_BLOCK_SIZE 128
-
-
-
-struct GNUNET_SERVER_TransmitContext
-{
- /**
- * Which client are we transmitting to?
- */
- struct GNUNET_SERVER_Client *client;
-
- /**
- * Transmission buffer. (current offset for writing).
- */
- char *buf;
-
- /**
- * Number of bytes in buf.
- */
- size_t total;
-
- /**
- * Offset for writing in buf.
- */
- size_t off;
-
- /**
- * Timeout for this request.
- */
- struct GNUNET_TIME_Absolute timeout;
-};
-
-
-/**
- * Helper function for incremental transmission of the response.
- */
-static size_t
-transmit_response (void *cls, size_t size, void *buf)
-{
- struct GNUNET_SERVER_TransmitContext *tc = cls;
- size_t msize;
-
- if (NULL == buf)
- {
- GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
- return 0;
- }
- if (tc->total - tc->off > size)
- msize = size;
- else
- msize = tc->total - tc->off;
- GNUNET_memcpy (buf, &tc->buf[tc->off], msize);
- tc->off += msize;
- if (tc->total == tc->off)
- {
- GNUNET_SERVER_receive_done (tc->client, GNUNET_OK);
- GNUNET_SERVER_client_drop (tc->client);
- GNUNET_free_non_null (tc->buf);
- GNUNET_free (tc);
- }
- else
- {
- if (NULL ==
- GNUNET_SERVER_notify_transmit_ready (tc->client,
- GNUNET_MIN (MIN_BLOCK_SIZE,
- tc->total - tc->off),
- GNUNET_TIME_absolute_get_remaining
- (tc->timeout), &transmit_response,
- tc))
- {
- GNUNET_break (0);
- GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
- }
- }
- return msize;
-}
-
-
-/**
- * Create a new transmission context for the
- * given client.
- *
- * @param client client to create the context for.
- * @return NULL on error
- */
-struct GNUNET_SERVER_TransmitContext *
-GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client)
-{
- struct GNUNET_SERVER_TransmitContext *tc;
-
- GNUNET_assert (NULL != client);
- tc = GNUNET_new (struct GNUNET_SERVER_TransmitContext);
- GNUNET_SERVER_client_keep (client);
- tc->client = client;
- return tc;
-}
-
-
-/**
- * Append a message to the transmission context.
- * All messages in the context will be sent by
- * the transmit_context_run method.
- *
- * @param tc context to use
- * @param data what to append to the result message
- * @param length length of data
- * @param type type of the message
- */
-void
-GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext
- *tc, const void *data,
- size_t length, uint16_t type)
-{
- struct GNUNET_MessageHeader *msg;
- size_t size;
-
- GNUNET_assert (length < GNUNET_SERVER_MAX_MESSAGE_SIZE);
- size = length + sizeof (struct GNUNET_MessageHeader);
- GNUNET_assert (size > length);
- tc->buf = GNUNET_realloc (tc->buf, tc->total + size);
- msg = (struct GNUNET_MessageHeader *) &tc->buf[tc->total];
- tc->total += size;
- msg->size = htons (size);
- msg->type = htons (type);
- GNUNET_memcpy (&msg[1], data, length);
-}
-
-
-/**
- * Append a message to the transmission context.
- * All messages in the context will be sent by
- * the transmit_context_run method.
- *
- * @param tc context to use
- * @param msg message to append
- */
-void
-GNUNET_SERVER_transmit_context_append_message (struct
- GNUNET_SERVER_TransmitContext
- *tc,
- const struct GNUNET_MessageHeader
- *msg)
-{
- struct GNUNET_MessageHeader *m;
- uint16_t size;
-
- size = ntohs (msg->size);
- tc->buf = GNUNET_realloc (tc->buf, tc->total + size);
- m = (struct GNUNET_MessageHeader *) &tc->buf[tc->total];
- tc->total += size;
- GNUNET_memcpy (m, msg, size);
-}
-
-
-/**
- * Execute a transmission context. If there is
- * an error in the transmission, the #GNUNET_SERVER_receive_done()
- * method will be called with an error code (#GNUNET_SYSERR),
- * otherwise with #GNUNET_OK.
- *
- * @param tc transmission context to use
- * @param timeout when to time out and abort the transmission
- */
-void
-GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc,
- struct GNUNET_TIME_Relative timeout)
-{
- tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
- if (NULL ==
- GNUNET_SERVER_notify_transmit_ready (tc->client,
- GNUNET_MIN (MIN_BLOCK_SIZE,
- tc->total), timeout,
- &transmit_response, tc))
- {
- GNUNET_break (0);
- GNUNET_SERVER_transmit_context_destroy (tc, GNUNET_SYSERR);
- }
-}
-
-
-/**
- * Destroy a transmission context. This function must not be called
- * after 'GNUNET_SERVER_transmit_context_run'.
- *
- * @param tc transmission context to destroy
- * @param success code to give to 'GNUNET_SERVER_receive_done' for
- * the client: GNUNET_OK to keep the connection open and
- * continue to receive
- * GNUNET_NO to close the connection (normal behavior)
- * GNUNET_SYSERR to close the connection (signal
- * serious error)
- */
-void
-GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext
- *tc, int success)
-{
- GNUNET_SERVER_receive_done (tc->client, success);
- GNUNET_SERVER_client_drop (tc->client);
- GNUNET_free_non_null (tc->buf);
- GNUNET_free (tc);
-}
-
-
-/* end of server_tc.c */
diff --git a/src/util/service.c b/src/util/service.c
index b4d03c17c..800d09a42 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -1596,7 +1596,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
* dropped. Additionally, clients can be dropped at any time using
* #GNUNET_SERVICE_client_drop().
*
- * The service must be stopped using #GNUNET_SERVICE_stoP().
+ * The service must be stopped using #GNUNET_SERVICE_stop().
*
* @param service_name name of the service to run
* @param cfg configuration to use
@@ -1609,7 +1609,7 @@ teardown_service (struct GNUNET_SERVICE_Handle *sh)
* @return NULL on error
*/
struct GNUNET_SERVICE_Handle *
-GNUNET_SERVICE_starT (const char *service_name,
+GNUNET_SERVICE_start (const char *service_name,
const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_SERVICE_ConnectHandler connect_cb,
GNUNET_SERVICE_DisconnectHandler disconnect_cb,
@@ -1637,12 +1637,12 @@ GNUNET_SERVICE_starT (const char *service_name,
/**
- * Stops a service that was started with #GNUNET_SERVICE_starT().
+ * Stops a service that was started with #GNUNET_SERVICE_start().
*
* @param srv service to stop
*/
void
-GNUNET_SERVICE_stoP (struct GNUNET_SERVICE_Handle *srv)
+GNUNET_SERVICE_stop (struct GNUNET_SERVICE_Handle *srv)
{
struct GNUNET_SERVICE_Client *client;
@@ -1697,7 +1697,7 @@ GNUNET_SERVICE_stoP (struct GNUNET_SERVICE_Handle *srv)
* @return 0 on success, non-zero on error
*/
int
-GNUNET_SERVICE_ruN_ (int argc,
+GNUNET_SERVICE_run_ (int argc,
char *const *argv,
const char *service_name,
enum GNUNET_SERVICE_Options options,
diff --git a/src/util/test_client.c b/src/util/test_client.c
index f60e5b7f7..527b400b0 100644
--- a/src/util/test_client.c
+++ b/src/util/test_client.c
@@ -179,7 +179,7 @@ main (int argc,
test_argv[2] = "test_client_unix.conf";
global_ret = 1;
if (0 !=
- GNUNET_SERVICE_ruN_ (3,
+ GNUNET_SERVICE_run_ (3,
test_argv,
"test_client",
GNUNET_SERVICE_OPTION_NONE,
diff --git a/src/util/test_service.c b/src/util/test_service.c
index d2136b42f..1567c97ce 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -148,7 +148,7 @@ check (const char *sname)
sname);
global_ret = 1;
GNUNET_assert (0 ==
- GNUNET_SERVICE_ruN_ (3,
+ GNUNET_SERVICE_run_ (3,
argv,
sname,
GNUNET_SERVICE_OPTION_NONE,