gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r16664 - gnunet/src/mesh


From: gnunet
Subject: [GNUnet-SVN] r16664 - gnunet/src/mesh
Date: Thu, 1 Sep 2011 00:21:25 +0200

Author: bartpolot
Date: 2011-09-01 00:21:25 +0200 (Thu, 01 Sep 2011)
New Revision: 16664

Modified:
   gnunet/src/mesh/mesh_api.c
   gnunet/src/mesh/mesh_api_new.c
Log:
WiP

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2011-08-31 21:11:36 UTC (rev 16663)
+++ gnunet/src/mesh/mesh_api.c  2011-08-31 22:21:25 UTC (rev 16664)
@@ -200,6 +200,7 @@
 
   struct peer_list_element *element = cls;
   struct GNUNET_MESH_Handle *handle = element->handle;
+
   element->hello = NULL;
   struct GNUNET_MessageHeader *hdr = buf;
 
@@ -216,22 +217,30 @@
   return sent;
 }
 
-void schedule_hello_message(void* cls, const struct 
GNUNET_SCHEDULER_TaskContext* tctx)
+void
+schedule_hello_message (void *cls,
+                        const struct GNUNET_SCHEDULER_TaskContext *tctx)
 {
   struct peer_list_element *element = cls;
+
   element->sched = GNUNET_SCHEDULER_NO_TASK;
 
   if ((tctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
-      return;
+    return;
 
   if (element->hello == NULL)
-    element->hello = GNUNET_CORE_notify_transmit_ready (element->handle->core, 
GNUNET_NO, 42,
-                                                           
GNUNET_TIME_UNIT_SECONDS, &element->peer,
-                                                           sizeof (struct 
GNUNET_MessageHeader) +
-                                                           
element->handle->hello_message_size,
-                                                           
&send_hello_message, element);
+    element->hello =
+        GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 
42,
+                                           GNUNET_TIME_UNIT_SECONDS,
+                                           &element->peer,
+                                           sizeof (struct GNUNET_MessageHeader)
+                                           +
+                                           element->handle->hello_message_size,
+                                           &send_hello_message, element);
 
-  element->sched = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, 
schedule_hello_message, cls);
+  element->sched =
+      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+                                    schedule_hello_message, cls);
 }
 
 
@@ -257,7 +266,7 @@
   element->handle = handle;
 
   /* Send a hello to this peer */
-  element->sched = GNUNET_SCHEDULER_add_now(schedule_hello_message, element);
+  element->sched = GNUNET_SCHEDULER_add_now (schedule_hello_message, element);
 
   if (NULL != atsi)
     memcpy (&element->atsi, atsi,
@@ -327,8 +336,8 @@
                                    tail);
       GNUNET_free (tail);
     }
-    GNUNET_CORE_notify_transmit_ready_cancel(element->hello);
-    GNUNET_SCHEDULER_cancel(element->sched);
+    GNUNET_CORE_notify_transmit_ready_cancel (element->hello);
+    GNUNET_SCHEDULER_cancel (element->sched);
     GNUNET_free (element);
   }
 
@@ -885,8 +894,8 @@
                                    tail);
       GNUNET_free (tail);
     }
-    GNUNET_CORE_notify_transmit_ready_cancel(element->hello);
-    GNUNET_SCHEDULER_cancel(element->sched);
+    GNUNET_CORE_notify_transmit_ready_cancel (element->hello);
+    GNUNET_SCHEDULER_cancel (element->sched);
     GNUNET_free (element);
     element = next;
   }
@@ -912,4 +921,4 @@
   GNUNET_free (handle);
 }
 
-/* end of mesh_api.c */
+/* end of mesh_api.c */
\ No newline at end of file

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-08-31 21:11:36 UTC (rev 16663)
+++ gnunet/src/mesh/mesh_api_new.c      2011-08-31 22:21:25 UTC (rev 16664)
@@ -651,8 +651,8 @@
 
 /**
  * Auxiliary function to send an already constructed packet to the service.
- * Takes care of creating a new queue element and calling the tmt_rdy function
- * if necessary.
+ * Takes care of creating a new queue element, copying the message and
+ * calling the tmt_rdy function if necessary.
  * @param h mesh handle
  * @param msg message to transmit
  */
@@ -732,12 +732,14 @@
   h->message_handlers = handlers;
   h->applications = stypes;
   h->next_tid = GNUNET_MESH_LOCAL_TUNNEL_ID_MARK;
+
   /* count handlers and apps, calculate size */
   for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
   for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
   size = sizeof (struct GNUNET_MESH_ClientConnect);
   size += h->n_handlers * sizeof (uint16_t);
   size += h->n_applications * sizeof (GNUNET_MESH_ApplicationType);
+
   {
     char buf[size];
 
@@ -826,16 +828,16 @@
 GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun)
 {
   struct GNUNET_MESH_Handle *h;
-  struct GNUNET_MESH_TunnelMessage *msg;
+  struct GNUNET_MESH_TunnelMessage msg;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
   h = tun->mesh;
-  msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_TunnelMessage));
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
-  msg->header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
-  msg->tunnel_id = htonl (tun->tid);
+
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
+  msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
+  msg.tunnel_id = htonl (tun->tid);
   GNUNET_free (tun);
-  send_packet (h, &msg->header);
+  send_packet (h, &msg.header);
 }
 
 
@@ -852,7 +854,7 @@
                                       struct GNUNET_TIME_Relative timeout,
                                       const struct GNUNET_PeerIdentity *peer)
 {
-  struct GNUNET_MESH_PeerControl *msg;
+  struct GNUNET_MESH_PeerControl msg;
   GNUNET_PEER_Id peer_id;
   unsigned int i;
 
@@ -870,14 +872,14 @@
   tunnel->peers =
       GNUNET_realloc (tunnel->peers, tunnel->npeers * sizeof (GNUNET_PEER_Id));
   tunnel->peers[tunnel->npeers - 1] = peer_id;
-  msg = GNUNET_malloc (sizeof (struct GNUNET_MESH_PeerControl));
-  msg->header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
-  msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
-  msg->tunnel_id = htonl (tunnel->tid);
-  msg->timeout =
+
+  msg.header.size = htons (sizeof (struct GNUNET_MESH_PeerControl));
+  msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD);
+  msg.tunnel_id = htonl (tunnel->tid);
+  msg.timeout =
       GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (timeout));
-  memcpy (&msg->peer, peer, sizeof (struct GNUNET_PeerIdentity));
-  send_packet (tunnel->mesh, &msg->header);
+  msg.peer = *peer;
+  send_packet (tunnel->mesh, &msg.header);
 //   tunnel->connect_handler (tunnel->cls, peer, NULL); FIXME call this later
 //   TODO: remember timeout
   return;




reply via email to

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