gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r10119 - in gnunet/src: core fs include peerinfo statistics


From: gnunet
Subject: [GNUnet-SVN] r10119 - in gnunet/src: core fs include peerinfo statistics transport util
Date: Fri, 22 Jan 2010 16:52:40 +0100

Author: grothoff
Date: 2010-01-22 16:52:40 +0100 (Fri, 22 Jan 2010)
New Revision: 10119

Modified:
   gnunet/src/core/core_api.c
   gnunet/src/core/gnunet-service-core.c
   gnunet/src/fs/gnunet-service-fs.c
   gnunet/src/include/gnunet_server_lib.h
   gnunet/src/peerinfo/gnunet-service-peerinfo.c
   gnunet/src/statistics/gnunet-service-statistics.c
   gnunet/src/transport/gnunet-service-transport.c
   gnunet/src/util/gnunet-service-resolver.c
   gnunet/src/util/server_tc.c
Log:
stuff

Modified: gnunet/src/core/core_api.c
===================================================================
--- gnunet/src/core/core_api.c  2010-01-22 15:14:39 UTC (rev 10118)
+++ gnunet/src/core/core_api.c  2010-01-22 15:52:40 UTC (rev 10119)
@@ -87,11 +87,16 @@
   const struct GNUNET_CORE_MessageHandler *handlers;
 
   /**
-   * Our connection to the service.
+   * Our connection to the service for notifications.
    */
-  struct GNUNET_CLIENT_Connection *client;
+  struct GNUNET_CLIENT_Connection *client_notifications;
 
   /**
+   * Our connection to the service for normal requests.
+   */
+  struct GNUNET_CLIENT_Connection *client_requests;
+
+  /**
    * Handle for our current transmission request.
    */
   struct GNUNET_CLIENT_TransmitHandle *th;
@@ -263,10 +268,10 @@
 static void
 reconnect (struct GNUNET_CORE_Handle *h)
 {
-  GNUNET_CLIENT_disconnect (h->client);
+  GNUNET_CLIENT_disconnect (h->client_notifications);
   h->currently_down = GNUNET_YES;
-  h->client = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
-  h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+  h->client_notifications = GNUNET_CLIENT_connect (h->sched, "core", h->cfg);
+  h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
                                                sizeof (struct InitMessage) +
                                                sizeof (uint16_t) * h->hcnt,
                                                GNUNET_TIME_UNIT_SECONDS,
@@ -346,6 +351,7 @@
 trigger_next_request (struct GNUNET_CORE_Handle *h)
 {
   struct GNUNET_CORE_TransmitHandle *th;
+
   if (h->currently_down)
     return;                     /* connection temporarily down */
   if (NULL == (th = h->pending_head))
@@ -356,7 +362,7 @@
       GNUNET_SCHEDULER_cancel (h->sched, th->timeout_task);
       th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
     }
-  h->th = GNUNET_CLIENT_notify_transmit_ready (h->client,
+  h->th = GNUNET_CLIENT_notify_transmit_ready (h->client_requests,
                                                th->msize,
                                                
GNUNET_TIME_absolute_get_remaining
                                                (th->timeout), 
@@ -367,20 +373,19 @@
 
 
 /**
- * Handler for most messages received from the core.
+ * Handler for notification messages received from the core.
  *
  * @param cls our "struct GNUNET_CORE_Handle"
  * @param msg the message received from the core service
  */
 static void
-main_handler (void *cls, const struct GNUNET_MessageHeader *msg)
+main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_CORE_Handle *h = cls;
   unsigned int hpos;
   const struct ConnectNotifyMessage *cnm;
   const struct DisconnectNotifyMessage *dnm;
   const struct NotifyTrafficMessage *ntm;
-  const struct ConfigurationInfoMessage *cim;
   const struct GNUNET_MessageHeader *em;
   uint16_t msize;
   uint16_t et;
@@ -524,38 +529,15 @@
                          GNUNET_TIME_relative_ntoh (ntm->latency),
                          ntohl (ntm->distance));
       break;
-    case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
-      if (msize != sizeof (struct ConfigurationInfoMessage))
-        {
-          GNUNET_break (0);
-          break;
-        }
-      if (NULL == h->submitted)
-        break;
-      cim = (const struct ConfigurationInfoMessage *) msg;
-
-      /* process configuration data */
-      if (h->submitted->info != NULL)
-        h->submitted->info (h->submitted->info_cls,
-                            &h->submitted->peer,
-                            ntohl (cim->bpm_in),
-                            ntohl (cim->bpm_out),
-                            (int) ntohl (cim->reserved_amount),
-                            cim->preference);
-      /* done, clean up! */      
-      GNUNET_CORE_notify_transmit_ready_cancel (h->submitted); // HUH?
-      trigger_next_request (h);
-      break;
     default:
       GNUNET_break (0);
       break;
     }
-  GNUNET_CLIENT_receive (h->client,
-                         &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
+  GNUNET_CLIENT_receive (h->client_notifications,
+                         &main_notify_handler, h, 
GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 
-
 /**
  * Function called when we are ready to transmit our
  * "START" message (or when this operation timed out).
@@ -606,8 +588,8 @@
 #endif
   h->currently_down = GNUNET_NO;
   trigger_next_request (h);
-  GNUNET_CLIENT_receive (h->client,
-                         &main_handler, h, GNUNET_TIME_UNIT_FOREVER_REL);
+  GNUNET_CLIENT_receive (h->client_notifications,
+                         &main_notify_handler, h, 
GNUNET_TIME_UNIT_FOREVER_REL);
   if (NULL != (init = h->init))
     {
       /* mark so we don't call init on reconnect */
@@ -710,7 +692,7 @@
   ts = (uint16_t *) & init[1];
   for (hpos = 0; hpos < h->hcnt; hpos++)
     ts[hpos] = htons (h->handlers[hpos].type);
-  GNUNET_CLIENT_receive (h->client,
+  GNUNET_CLIENT_receive (h->client_notifications,
                          &init_reply_handler,
                          h,
                          GNUNET_TIME_absolute_get_remaining
@@ -774,8 +756,8 @@
   h->inbound_hdr_only = inbound_hdr_only;
   h->outbound_hdr_only = outbound_hdr_only;
   h->handlers = handlers;
-  h->client = GNUNET_CLIENT_connect (sched, "core", cfg);
-  if (h->client == NULL)
+  h->client_notifications = GNUNET_CLIENT_connect (sched, "core", cfg);
+  if (h->client_notifications == NULL)
     {
       GNUNET_free (h);
       return NULL;
@@ -793,7 +775,7 @@
               timeout.value);
 #endif
   h->th =
-    GNUNET_CLIENT_notify_transmit_ready (h->client,
+    GNUNET_CLIENT_notify_transmit_ready (h->client_notifications,
                                          sizeof (struct InitMessage) +
                                          sizeof (uint16_t) * h->hcnt, timeout,
                                         GNUNET_YES,
@@ -816,7 +798,9 @@
     GNUNET_CORE_notify_transmit_ready_cancel (handle->solicit_transmit_req);
   if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
     GNUNET_SCHEDULER_cancel (handle->sched, handle->reconnect_task);
-  GNUNET_CLIENT_disconnect (handle->client);
+  GNUNET_CLIENT_disconnect (handle->client_notifications);
+  if (handle->client_requests != NULL)
+    GNUNET_CLIENT_disconnect (handle->client_requests);
   GNUNET_free_non_null (handle->solicit_buffer);
   GNUNET_free (handle);
 }

Modified: gnunet/src/core/gnunet-service-core.c
===================================================================
--- gnunet/src/core/gnunet-service-core.c       2010-01-22 15:14:39 UTC (rev 
10118)
+++ gnunet/src/core/gnunet-service-core.c       2010-01-22 15:52:40 UTC (rev 
10119)
@@ -539,31 +539,6 @@
 
 
 /**
- * Events are messages for clients.  The struct
- * itself is followed by the actual message.
- */
-struct Event
-{
-  /**
-   * This is a linked list.
-   */
-  struct Event *next;
-
-  /**
-   * Size of the message.
-   */
-  size_t size;
-
-  /**
-   * Could this event be dropped if this queue
-   * is getting too large? (NOT YET USED!)
-   */
-  int can_drop;
-
-};
-
-
-/**
  * Data structure for each client connected to the core service.
  */
 struct Client
@@ -579,23 +554,6 @@
   struct GNUNET_SERVER_Client *client_handle;
 
   /**
-   * Linked list of messages we still need to deliver to
-   * this client.
-   */
-  struct Event *event_head;
-
-  /**
-   * Tail of the linked list of events.
-   */
-  struct Event *event_tail;
-
-  /**
-   * Current transmit handle, NULL if no transmission request
-   * is pending.
-   */
-  struct GNUNET_CONNECTION_TransmitHandle *th;
-
-  /**
    * Array of the types of messages this peer cares
    * about (with "tcnt" entries).  Allocated as part
    * of this client struct, do not free!
@@ -658,6 +616,11 @@
 static struct Client *clients;
 
 /**
+ * Context for notifications we need to send to our clients.
+ */
+static struct GNUNET_SERVER_NotificationContext *notifier;
+
+/**
  * We keep neighbours in a linked list (for now).
  */
 static struct Neighbour *neighbours;
@@ -762,110 +725,6 @@
 
 
 /**
- * Find the entry for the given client.
- *
- * @param client handle for the client
- * @return NULL if we are not connected, otherwise the
- *         client's struct.
- */
-static struct Client *
-find_client (const struct GNUNET_SERVER_Client *client)
-{
-  struct Client *ret;
-
-  ret = clients;
-  while ((ret != NULL) && (client != ret->client_handle))
-    ret = ret->next;
-  return ret;
-}
-
-
-/**
- * If necessary, initiate a request with the server to
- * transmit messages from the queue of the given client.
- * @param client who to transfer messages to
- */
-static void request_transmit (struct Client *client);
-
-
-/**
- * Client is ready to receive data, provide it.
- *
- * @param cls closure
- * @param size number of bytes available in buf
- * @param buf where the callee should write the message
- * @return number of bytes written to buf
- */
-static size_t
-do_client_transmit (void *cls, size_t size, void *buf)
-{
-  struct Client *client = cls;
-  struct Event *e;
-  char *tgt;
-  size_t ret;
-
-  client->th = NULL;
-#if DEBUG_CORE_CLIENT
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Client ready to receive %u bytes.\n", size);
-#endif
-  if (buf == NULL)
-    {
-#if DEBUG_CORE
-      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                  "Failed to transmit data to client (disconnect)?\n");
-#endif
-      return 0;                 /* we'll surely get a disconnect soon... */
-    }
-  tgt = buf;
-  ret = 0;
-  while ((NULL != (e = client->event_head)) && (e->size <= size))
-    {
-      memcpy (&tgt[ret], &e[1], e->size);
-      size -= e->size;
-      ret += e->size;
-      client->event_head = e->next;
-      GNUNET_free (e);
-    }
-  GNUNET_assert (ret > 0);
-  if (client->event_head == NULL)
-    client->event_tail = NULL;
-#if DEBUG_CORE_CLIENT
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Transmitting %u bytes to client\n", ret);
-#endif
-  request_transmit (client);
-  return ret;
-}
-
-
-/**
- * If necessary, initiate a request with the server to
- * transmit messages from the queue of the given client.
- * @param client who to transfer messages to
- */
-static void
-request_transmit (struct Client *client)
-{
-
-  if (NULL != client->th)
-    return;                     /* already pending */
-  if (NULL == client->event_head)
-    return;                     /* no more events pending */
-#if DEBUG_CORE_CLIENT
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Asking server to transmit %u bytes to client\n",
-              client->event_head->size);
-#endif
-  client->th
-    = GNUNET_SERVER_notify_transmit_ready (client->client_handle,
-                                           client->event_head->size,
-                                           GNUNET_TIME_UNIT_FOREVER_REL,
-                                           &do_client_transmit, client);
-}
-
-
-/**
  * Send a message to one of our clients.
  *
  * @param client target for the message
@@ -875,51 +734,28 @@
  */
 static void
 send_to_client (struct Client *client,
-                const struct GNUNET_MessageHeader *msg, int can_drop)
+                const struct GNUNET_MessageHeader *msg, 
+               int can_drop)
 {
-  struct Event *e;
-  unsigned int queue_size;
-  uint16_t msize;
-
 #if DEBUG_CORE_CLIENT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Preparing to send message of type %u to client.\n",
               ntohs (msg->type));
-#endif
-  queue_size = 0;
-  e = client->event_head;
-  while (e != NULL)
-    {
-      queue_size++;
-      e = e->next;
-    }
-  if ( (queue_size >= MAX_CLIENT_QUEUE_SIZE) &&
-       (can_drop == GNUNET_YES) )
-    {
-#if DEBUG_CORE
-      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                 "Too many messages in queue for the client, dropping the new 
message.\n");
-#endif
-      return;
-    }
-
-  msize = ntohs (msg->size);
-  e = GNUNET_malloc (sizeof (struct Event) + msize);
-  /* append */
-  if (client->event_tail != NULL)
-    client->event_tail->next = e;
-  else
-    client->event_head = e;
-  client->event_tail = e;
-  e->can_drop = can_drop;
-  e->size = msize;
-  memcpy (&e[1], msg, msize);
-  request_transmit (client);
+#endif  
+  GNUNET_SERVER_notification_context_unicast (notifier,
+                                             client->client_handle,
+                                             msg,
+                                             can_drop);
 }
 
 
 /**
- * Send a message to all of our current clients.
+ * Send a message to all of our current clients that have
+ * the right options set.
+ * 
+ * @param msg message to multicast
+ * @param can_drop can this message be discarded if the queue is too long
+ * @param options mask to use 
  */
 static void
 send_to_all_clients (const struct GNUNET_MessageHeader *msg, 
@@ -978,6 +814,7 @@
       GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
       return;
     }
+  GNUNET_SERVER_notification_context_add (notifier, client);
   im = (const struct InitMessage *) message;
   types = (const uint16_t *) &im[1];
   msize -= sizeof (struct InitMessage);
@@ -1017,7 +854,6 @@
       send_to_client (c, &cnm.header, GNUNET_NO);
       n = n->next;
     }
-  GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
 
 
@@ -1032,7 +868,6 @@
 {
   struct Client *pos;
   struct Client *prev;
-  struct Event *e;
 
   if (client == NULL)
     return;
@@ -1050,13 +885,6 @@
             clients = pos->next;
           else
             prev->next = pos->next;
-          if (pos->th != NULL)
-            GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
-         while (NULL != (e = pos->event_head))
-           {
-             pos->event_head = e->next;
-             GNUNET_free (e);
-           }
           GNUNET_free (pos);
           return;
         }
@@ -1072,15 +900,15 @@
  */
 static void
 handle_client_request_info (void *cls,
-                                 struct GNUNET_SERVER_Client *client,
-                                 const struct GNUNET_MessageHeader *message)
+                           struct GNUNET_SERVER_Client *client,
+                           const struct GNUNET_MessageHeader *message)
 {
   const struct RequestInfoMessage *rcm;
   struct Neighbour *n;
   struct ConfigurationInfoMessage cim;
-  struct Client *c;
   int reserv;
   unsigned long long old_preference;
+  struct GNUNET_SERVER_TransmitContext *tc;
 
 #if DEBUG_CORE_CLIENT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1128,17 +956,15 @@
   cim.header.size = htons (sizeof (struct ConfigurationInfoMessage));
   cim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO);
   cim.peer = rcm->peer;
-  c = find_client (client);
-  if (c == NULL)
-    {
-      GNUNET_break (0);
-      return;
-    }
+
 #if DEBUG_CORE_CLIENT
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Sending `%s' message to client.\n", "CONFIGURATION_INFO");
 #endif
-  send_to_client (c, &cim.header, GNUNET_NO);
+  tc = GNUNET_SERVER_transmit_context_create (client);
+  GNUNET_SERVER_transmit_context_append_message (tc, &cim.header);
+  GNUNET_SERVER_transmit_context_run (tc,
+                                     GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 
@@ -3252,6 +3078,8 @@
       neighbour_count--;
       free_neighbour (n);
     }
+  GNUNET_SERVER_notification_context_destroy (notifier);
+  notifier = NULL;
   while (NULL != (c = clients))
     handle_client_disconnect (NULL, c->client_handle);
   if (my_private_key != NULL)
@@ -3281,7 +3109,7 @@
   char *keyfile;
 
   sched = s;
-  cfg = c;
+  cfg = c;  
   /* parse configuration */
   if (
        (GNUNET_OK !=
@@ -3330,6 +3158,7 @@
                       sizeof (my_public_key), &my_identity.hashPubKey);
   /* setup notification */
   server = serv;
+  notifier = GNUNET_SERVER_notification_context_create (server, 0);
   GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
   /* setup transport connection */
   transport = GNUNET_TRANSPORT_connect (sched,

Modified: gnunet/src/fs/gnunet-service-fs.c
===================================================================
--- gnunet/src/fs/gnunet-service-fs.c   2010-01-22 15:14:39 UTC (rev 10118)
+++ gnunet/src/fs/gnunet-service-fs.c   2010-01-22 15:52:40 UTC (rev 10119)
@@ -961,9 +961,9 @@
                  ii->filename,
                  (const char*) GNUNET_CONTAINER_multihashmap_get (ifm,
                                                                   
&ii->file_id));
-      GNUNET_SERVER_transmit_context_append (ii->tc,
-                                            NULL, 0,
-                                            
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
+      GNUNET_SERVER_transmit_context_append_data (ii->tc,
+                                                 NULL, 0,
+                                                 
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
       GNUNET_SERVER_transmit_context_run (ii->tc,
                                          GNUNET_TIME_UNIT_MINUTES);
       GNUNET_free (ii);
@@ -972,9 +972,9 @@
   ii->next = indexed_files;
   indexed_files = ii;
   write_index_list ();
-  GNUNET_SERVER_transmit_context_append (ii->tc,
-                                        NULL, 0,
-                                        GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
+  GNUNET_SERVER_transmit_context_append_data (ii->tc,
+                                             NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_FS_INDEX_START_OK);
   GNUNET_SERVER_transmit_context_run (ii->tc,
                                      GNUNET_TIME_UNIT_MINUTES);
   ii->tc = NULL;
@@ -1009,9 +1009,9 @@
                  "Wanted `%s'\n",
                  GNUNET_h2s (&ii->file_id));
 #endif
-      GNUNET_SERVER_transmit_context_append (ii->tc,
-                                            NULL, 0,
-                                            
GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
+      GNUNET_SERVER_transmit_context_append_data (ii->tc,
+                                                 NULL, 0,
+                                                 
GNUNET_MESSAGE_TYPE_FS_INDEX_START_FAILED);
       GNUNET_SERVER_transmit_context_run (ii->tc,
                                          GNUNET_TIME_UNIT_MINUTES);
       GNUNET_free (ii);
@@ -1110,17 +1110,13 @@
   char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
   size_t slen;
   const char *fn;
-  struct GNUNET_MessageHeader *msg;
   struct IndexInfo *pos;
 
   tc = GNUNET_SERVER_transmit_context_create (client);
   iim = (struct IndexInfoMessage*) buf;
-  msg = &iim->header;
   pos = indexed_files;
   while (NULL != pos)
     {
-      iim->reserved = 0;
-      iim->file_id = pos->file_id;
       fn = pos->filename;
       slen = strlen (fn) + 1;
       if (slen + sizeof (struct IndexInfoMessage) > 
@@ -1129,18 +1125,18 @@
          GNUNET_break (0);
          break;
        }
+      iim->header.type = htons (GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+      iim->header.size = htons (slen + sizeof (struct IndexInfoMessage));
+      iim->reserved = 0;
+      iim->file_id = pos->file_id;
       memcpy (&iim[1], fn, slen);
-      GNUNET_SERVER_transmit_context_append
-       (tc,
-        &msg[1],
-        sizeof (struct IndexInfoMessage) 
-        - sizeof (struct GNUNET_MessageHeader) + slen,
-        GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_ENTRY);
+      GNUNET_SERVER_transmit_context_append_message (tc,
+                                                    &iim->header);
       pos = pos->next;
     }
-  GNUNET_SERVER_transmit_context_append (tc,
-                                        NULL, 0,
-                                        GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
+  GNUNET_SERVER_transmit_context_append_data (tc,
+                                             NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_FS_INDEX_LIST_END);
   GNUNET_SERVER_transmit_context_run (tc,
                                      GNUNET_TIME_UNIT_MINUTES);
 }
@@ -1198,9 +1194,9 @@
   if (GNUNET_YES == found)    
     write_index_list ();
   tc = GNUNET_SERVER_transmit_context_create (client);
-  GNUNET_SERVER_transmit_context_append (tc,
-                                        NULL, 0,
-                                        GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
+  GNUNET_SERVER_transmit_context_append_data (tc,
+                                             NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_FS_UNINDEX_OK);
   GNUNET_SERVER_transmit_context_run (tc,
                                      GNUNET_TIME_UNIT_MINUTES);
 }

Modified: gnunet/src/include/gnunet_server_lib.h
===================================================================
--- gnunet/src/include/gnunet_server_lib.h      2010-01-22 15:14:39 UTC (rev 
10118)
+++ gnunet/src/include/gnunet_server_lib.h      2010-01-22 15:52:40 UTC (rev 
10119)
@@ -492,11 +492,25 @@
  * @param type type of the message
  */
 void
-GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext
-                                       *tc, const void *data, size_t length,
-                                       uint16_t type);
+GNUNET_SERVER_transmit_context_append_data (struct 
GNUNET_SERVER_TransmitContext
+                                           *tc, const void *data, size_t 
length,
+                                           uint16_t type);
 
+
 /**
+ * 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);
+
+
+/**
  * Execute a transmission context.  If there is
  * an error in the transmission, the receive_done
  * method will be called with an error code (GNUNET_SYSERR),

Modified: gnunet/src/peerinfo/gnunet-service-peerinfo.c
===================================================================
--- gnunet/src/peerinfo/gnunet-service-peerinfo.c       2010-01-22 15:14:39 UTC 
(rev 10118)
+++ gnunet/src/peerinfo/gnunet-service-peerinfo.c       2010-01-22 15:52:40 UTC 
(rev 10119)
@@ -470,7 +470,6 @@
 {
   struct HostEntry *pos;
   struct InfoMessage *im;
-  const struct GNUNET_MessageHeader *end;
   uint16_t hs;
   char buf[GNUNET_SERVER_MAX_MESSAGE_SIZE];
   struct GNUNET_SERVER_TransmitContext *tc;
@@ -487,6 +486,8 @@
           change_host_trust (&pos->identity, trust_change);
           hs = 0;
           im = (struct InfoMessage *) buf;
+         im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+         im->header.size = htons (sizeof (struct InfoMessage) + hs);
           if (pos->hello != NULL)
             {
               hs = GNUNET_HELLO_size (pos->hello);
@@ -497,19 +498,13 @@
             }
           im->trust = htonl (pos->trust);
           im->peer = pos->identity;
-          end = &im->header;
-          GNUNET_SERVER_transmit_context_append (tc,
-                                                 &end[1],
-                                                 hs +
-                                                 sizeof (struct InfoMessage) -
-                                                 sizeof (struct
-                                                         GNUNET_MessageHeader),
-                                                 
GNUNET_MESSAGE_TYPE_PEERINFO_INFO);
+          GNUNET_SERVER_transmit_context_append_message (tc,
+                                                        &im->header);
         }
       pos = pos->next;
     }
-  GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
-                                         
GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
+  GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 

Modified: gnunet/src/statistics/gnunet-service-statistics.c
===================================================================
--- gnunet/src/statistics/gnunet-service-statistics.c   2010-01-22 15:14:39 UTC 
(rev 10118)
+++ gnunet/src/statistics/gnunet-service-statistics.c   2010-01-22 15:52:40 UTC 
(rev 10119)
@@ -218,16 +218,15 @@
           const struct StatsEntry *e)
 {
   struct GNUNET_STATISTICS_ReplyMessage *m;
-  struct GNUNET_MessageHeader *h;
   size_t size;
-  uint16_t msize;
 
   size =
     sizeof (struct GNUNET_STATISTICS_ReplyMessage) + strlen (e->service) + 1 +
     strlen (e->name) + 1;
   GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
-  msize = size - sizeof (struct GNUNET_MessageHeader);
   m = GNUNET_malloc (size);
+  m->header.type = htons (GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
+  m->header.size = htons (size);
   m->uid = htonl (e->uid);
   if (e->persistent)
     m->uid |= htonl (GNUNET_STATISTICS_PERSIST_BIT);
@@ -241,11 +240,7 @@
               "Transmitting value for `%s:%s': %llu\n",
               e->service, e->name, e->value);
 #endif
-  h = &m->header;
-  GNUNET_SERVER_transmit_context_append (tc,
-                                         &h[1],
-                                         msize,
-                                         GNUNET_MESSAGE_TYPE_STATISTICS_VALUE);
+  GNUNET_SERVER_transmit_context_append_message (tc, &m->header);
   GNUNET_free (m);
 }
 
@@ -303,8 +298,8 @@
         transmit (tc, pos);
       pos = pos->next;
     }
-  GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
-                                         GNUNET_MESSAGE_TYPE_STATISTICS_END);
+  GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_STATISTICS_END);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 

Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c     2010-01-22 15:14:39 UTC 
(rev 10118)
+++ gnunet/src/transport/gnunet-service-transport.c     2010-01-22 15:52:40 UTC 
(rev 10119)
@@ -2587,8 +2587,8 @@
     slen = 0;
   else
     slen = strlen (address) + 1;
-  GNUNET_SERVER_transmit_context_append (tc, address, slen,
-                                         
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+  GNUNET_SERVER_transmit_context_append_data (tc, address, slen,
+                                             
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
   if (NULL == address)
     GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
@@ -2644,8 +2644,8 @@
   if (NULL == lsPlugin)
     {
       tc = GNUNET_SERVER_transmit_context_create (client);
-      GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
-                                             
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
+      GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+                                                 
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
       GNUNET_SERVER_transmit_context_run (tc, rtimeout);
       return;
     }

Modified: gnunet/src/util/gnunet-service-resolver.c
===================================================================
--- gnunet/src/util/gnunet-service-resolver.c   2010-01-22 15:14:39 UTC (rev 
10118)
+++ gnunet/src/util/gnunet-service-resolver.c   2010-01-22 15:52:40 UTC (rev 
10119)
@@ -227,12 +227,12 @@
     }
   tc = GNUNET_SERVER_transmit_context_create (client);
   if (cache->addr != NULL)
-    GNUNET_SERVER_transmit_context_append (tc,
-                                           cache->addr,
-                                           strlen (cache->addr) + 1,
-                                           
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
-  GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
-                                         
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+    GNUNET_SERVER_transmit_context_append_data (tc,
+                                               cache->addr,
+                                               strlen (cache->addr) + 1,
+                                               
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+  GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
@@ -280,10 +280,10 @@
   pos = result;
   while (pos != NULL)
     {
-      GNUNET_SERVER_transmit_context_append (tc,
-                                             result->ai_addr,
-                                             result->ai_addrlen,
-                                             
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+      GNUNET_SERVER_transmit_context_append_data (tc,
+                                                 result->ai_addr,
+                                                 result->ai_addrlen,
+                                                 
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
       pos = pos->ai_next;
     }
   freeaddrinfo (result);
@@ -327,10 +327,10 @@
       memset (&a4, 0, sizeof (a4));
       a4.sin_family = AF_INET;
       memcpy (&a4.sin_addr, hp->h_addr_list[0], hp->h_length);
-      GNUNET_SERVER_transmit_context_append (tc,
-                                             &a4,
-                                             sizeof (a4),
-                                             
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+      GNUNET_SERVER_transmit_context_append_data (tc,
+                                                 &a4,
+                                                 sizeof (a4),
+                                                 
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
     }
   else
     {
@@ -338,10 +338,10 @@
       memset (&a6, 0, sizeof (a6));
       a6.sin6_family = AF_INET6;
       memcpy (&a6.sin6_addr, hp->h_addr_list[0], hp->h_length);
-      GNUNET_SERVER_transmit_context_append (tc,
-                                             &a6,
-                                             sizeof (a6),
-                                             
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+      GNUNET_SERVER_transmit_context_append_data (tc,
+                                                 &a6,
+                                                 sizeof (a6),
+                                                 
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
     }
   return GNUNET_OK;
 }
@@ -372,10 +372,10 @@
   memset (&addr, 0, sizeof (addr));
   addr.sin_family = AF_INET;
   memcpy (&addr.sin_addr, hp->h_addr_list[0], hp->h_length);
-  GNUNET_SERVER_transmit_context_append (tc,
-                                         &addr,
-                                         sizeof (addr),
-                                         
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+  GNUNET_SERVER_transmit_context_append_data (tc,
+                                             &addr,
+                                             sizeof (addr),
+                                             
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
   return GNUNET_OK;
 }
 #endif
@@ -409,8 +409,8 @@
   if ((ret == GNUNET_NO) && ((domain == AF_UNSPEC) || (domain == PF_INET)))
     gethostbyname_resolve (tc, hostname);
 #endif
-  GNUNET_SERVER_transmit_context_append (tc, NULL, 0,
-                                         
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
+  GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
+                                             
GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE);
   GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 

Modified: gnunet/src/util/server_tc.c
===================================================================
--- gnunet/src/util/server_tc.c 2010-01-22 15:14:39 UTC (rev 10118)
+++ gnunet/src/util/server_tc.c 2010-01-22 15:52:40 UTC (rev 10119)
@@ -149,9 +149,9 @@
  * @param type type of the message
  */
 void
-GNUNET_SERVER_transmit_context_append (struct GNUNET_SERVER_TransmitContext
-                                       *tc, const void *data, size_t length,
-                                       uint16_t type)
+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;
@@ -169,6 +169,29 @@
 
 
 /**
+ * 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;
+  memcpy (m, msg, size);
+}
+
+
+/**
  * Execute a transmission context.  If there is
  * an error in the transmission, the receive_done
  * method will be called with an error code (GNUNET_SYSERR),





reply via email to

[Prev in Thread] Current Thread [Next in Thread]