WiP
authorBart Polot <bart@net.in.tum.de>
Wed, 31 Aug 2011 22:21:25 +0000 (22:21 +0000)
committerBart Polot <bart@net.in.tum.de>
Wed, 31 Aug 2011 22:21:25 +0000 (22:21 +0000)
src/mesh/mesh_api.c
src/mesh/mesh_api_new.c

index 5ea4789b82f7a86edcd8108ee68f7e273ec8dcae..61559362187cb43993f12f9dd410e0a301bc0109 100644 (file)
@@ -200,6 +200,7 @@ send_hello_message (void *cls, size_t size, void *buf)
 
   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 @@ send_hello_message (void *cls, size_t size, void *buf)
   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->sched = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, schedule_hello_message, cls);
+    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);
 }
 
 
@@ -257,7 +266,7 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
   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 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
                                    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 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
                                    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_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
   GNUNET_free (handle);
 }
 
-/* end of mesh_api.c */
+/* end of mesh_api.c */
\ No newline at end of file
index 23ade23796e947f23b35bfecec79071906f89b5b..cd385b01de8818b644076bbcc32eb5a4977c9a47 100644 (file)
@@ -651,8 +651,8 @@ send_raw (void *cls, size_t size, void *buf)
 
 /**
  * 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 @@ GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
   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 @@ void
 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 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
                                       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 @@ GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
   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;