gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r16727 - in gnunet/src: include mesh


From: gnunet
Subject: [GNUnet-SVN] r16727 - in gnunet/src: include mesh
Date: Wed, 7 Sep 2011 18:24:54 +0200

Author: bartpolot
Date: 2011-09-07 18:24:53 +0200 (Wed, 07 Sep 2011)
New Revision: 16727

Modified:
   gnunet/src/include/gnunet_mesh_service_new.h
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api.c
   gnunet/src/mesh/mesh_api_new.c
   gnunet/src/mesh/test_mesh_api.c
   gnunet/src/mesh/test_mesh_local.c
Log:
Changed documentation, type names and code formatting
Extended test_local


Modified: gnunet/src/include/gnunet_mesh_service_new.h
===================================================================
--- gnunet/src/include/gnunet_mesh_service_new.h        2011-09-07 16:16:00 UTC 
(rev 16726)
+++ gnunet/src/include/gnunet_mesh_service_new.h        2011-09-07 16:24:53 UTC 
(rev 16727)
@@ -113,16 +113,14 @@
  * @param tunnel new handle to the tunnel
  * @param initiator peer that started the tunnel
  * @param atsi performance information for the tunnel
- * @return initial tunnel context for the tunnel (can be NULL -- that's not an 
error)
+ * @return initial tunnel context for the tunnel
+ *         (can be NULL -- that's not an error)
  */
-typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) (void *cls,
-                                                               struct 
GNUNET_MESH_Tunnel * tunnel,
-                                                               const struct
-                                                               
GNUNET_PeerIdentity *
-                                                               initiator,
-                                                               const struct
-                                                               
GNUNET_TRANSPORT_ATS_Information *
-                                                               atsi);
+typedef void* (GNUNET_MESH_InboundTunnelNotificationHandler) (
+    void *cls,
+    struct GNUNET_MESH_Tunnel * tunnel,
+    const struct GNUNET_PeerIdentity * initiator,
+    const struct GNUNET_TRANSPORT_ATS_Information * atsi);
 
 
 /**
@@ -166,7 +164,8 @@
  */
 struct GNUNET_MESH_Handle *
 GNUNET_MESH_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
-                     unsigned int queue_size, void *cls,
+                     unsigned int queue_size,
+                     void *cls,
                      GNUNET_MESH_InboundTunnelNotificationHandler new_tunnel,
                      GNUNET_MESH_TunnelEndHandler cleaner,
                      const struct GNUNET_MESH_MessageHandler *handlers,
@@ -188,10 +187,9 @@
  * @param cls closure
  * @param peer peer identity the tunnel stopped working with
  */
-typedef void (*GNUNET_MESH_TunnelDisconnectHandler) (void *cls,
-                                                     const struct
-                                                     GNUNET_PeerIdentity *
-                                                     peer);
+typedef void (*GNUNET_MESH_PeerDisconnectHandler) (
+    void *cls,
+    const struct GNUNET_PeerIdentity * peer);
 
 
 /**
@@ -202,12 +200,10 @@
  * @param peer peer identity the tunnel was created to, NULL on timeout
  * @param atsi performance data for the connection
  */
-typedef void (*GNUNET_MESH_TunnelConnectHandler) (void *cls,
-                                                  const struct
-                                                  GNUNET_PeerIdentity * peer,
-                                                  const struct
-                                                  
GNUNET_TRANSPORT_ATS_Information
-                                                  * atsi);
+typedef void (*GNUNET_MESH_PeerConnectHandler) (
+    void *cls,
+    const struct GNUNET_PeerIdentity * peer,
+    const struct GNUNET_TRANSPORT_ATS_Information * atsi);
 
 
 
@@ -222,18 +218,19 @@
  * @param handler_cls closure for connect/disconnect handlers
  */
 struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
-                           GNUNET_MESH_TunnelConnectHandler connect_handler,
-                           GNUNET_MESH_TunnelDisconnectHandler
-                           disconnect_handler, void *handler_cls);
+GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, 
+                           void *tunnel_ctx,
+                           GNUNET_MESH_PeerConnectHandler connect_handler,
+                           GNUNET_MESH_PeerDisconnectHandler 
disconnect_handler,
+                           void *handler_cls);
 
 /**
  * Destroy an existing tunnel.
  *
- * @param tun tunnel handle
+ * @param tunnel tunnel handle
  */
 void
-GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tun);
+GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel);
 
 
 /**
@@ -300,7 +297,8 @@
  *         memory); if NULL is returned, "notify" will NOT be called.
  */
 struct GNUNET_MESH_TransmitHandle *
-GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel, int cork,
+GNUNET_MESH_notify_transmit_ready (struct GNUNET_MESH_Tunnel *tunnel,
+                                   int cork,
                                    uint32_t priority,
                                    struct GNUNET_TIME_Relative maxdelay,
                                    const struct GNUNET_PeerIdentity *target,

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-09-07 16:16:00 UTC (rev 
16726)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-09-07 16:24:53 UTC (rev 
16727)
@@ -790,14 +790,14 @@
   {
     r = GNUNET_SYSERR;
   }
-  GNUNET_CONTAINER_multihashmap_destroy(t->peers);
+  GNUNET_CONTAINER_multihashmap_destroy (t->peers);
   q = t->queue_head;
   while (NULL != q)
   {
     if (NULL != q->data)
-      GNUNET_free(q->data);
+      GNUNET_free (q->data);
     qn = q->next;
-    GNUNET_free(q);
+    GNUNET_free (q);
     q = qn;
     /* TODO cancel core transmit ready in case it was active */
   }
@@ -2027,24 +2027,24 @@
       /* deregister clients applications */
       for (i = 0; i < c->app_counter; i++)
       {
-       for (j = 0; j < n_apps; j++)
-       {
-         if (c->apps[i] == applications[j] && 0 == --applications_rc[j])
-         {
-           applications[j] = applications[n_apps - 1];
-           GNUNET_array_grow(applications, n_apps, n_apps - 1);
-           n_apps++;
-           applications_rc[j] = applications_rc[n_apps - 1];
-           GNUNET_array_grow(applications_rc, n_apps, n_apps - 1);
+        for (j = 0; j < n_apps; j++)
+        {
+          if (c->apps[i] == applications[j] && 0 == --applications_rc[j])
+          {
+            applications[j] = applications[n_apps - 1];
+            GNUNET_array_grow (applications, n_apps, n_apps - 1);
+            n_apps++;
+            applications_rc[j] = applications_rc[n_apps - 1];
+            GNUNET_array_grow (applications_rc, n_apps, n_apps - 1);
 
-         }
-         break;
-       }
+          }
+          break;
+        }
       }
       GNUNET_free (c->apps);
       if (0 == n_apps)
       {
-       GNUNET_SCHEDULER_cancel (announce_applications_task);
+        GNUNET_SCHEDULER_cancel (announce_applications_task);
       }
     }
     if (0 != c->type_counter)
@@ -2125,9 +2125,9 @@
     if (!known)
     {
       /* Register previously unknown application */
-      GNUNET_array_append(applications, n_apps, c->apps[i]);
+      GNUNET_array_append (applications, n_apps, c->apps[i]);
       n_apps--;
-      GNUNET_array_append(applications_rc, n_apps, 1);
+      GNUNET_array_append (applications_rc, n_apps, 1);
       if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
       {
         announce_applications_task =

Modified: gnunet/src/mesh/mesh_api.c
===================================================================
--- gnunet/src/mesh/mesh_api.c  2011-09-07 16:16:00 UTC (rev 16726)
+++ gnunet/src/mesh/mesh_api.c  2011-09-07 16:24:53 UTC (rev 16727)
@@ -921,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-09-07 16:16:00 UTC (rev 16726)
+++ gnunet/src/mesh/mesh_api_new.c      2011-09-07 16:24:53 UTC (rev 16727)
@@ -242,12 +242,12 @@
     /**
      * Callback to execute when peers connect to the tunnel
      */
-  GNUNET_MESH_TunnelConnectHandler connect_handler;
+  GNUNET_MESH_PeerConnectHandler connect_handler;
 
     /**
      * Callback to execute when peers disconnect from the tunnel
      */
-  GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
+  GNUNET_MESH_PeerDisconnectHandler disconnect_handler;
 
     /**
      * Closure for the connect/disconnect handlers
@@ -380,7 +380,7 @@
 
   if (NULL == t)
   {
-    GNUNET_break(0);
+    GNUNET_break (0);
     return;
   }
   h = t->mesh;
@@ -390,16 +390,16 @@
     if (th->tunnel == t)
     {
       aux = th->next;
-      GNUNET_CONTAINER_DLL_remove(h->th_head, h->th_tail, th);
+      GNUNET_CONTAINER_DLL_remove (h->th_head, h->th_tail, th);
       if (NULL == h->th_head && NULL != h->th)
       {
-        GNUNET_CLIENT_notify_transmit_ready_cancel(h->th);
+        GNUNET_CLIENT_notify_transmit_ready_cancel (h->th);
         h->th = NULL;
       }
       if (NULL != th->notify)
-          th->notify(th->notify_cls, 0, NULL);
+        th->notify (th->notify_cls, 0, NULL);
       if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task)
-          GNUNET_SCHEDULER_cancel(th->timeout_task);
+        GNUNET_SCHEDULER_cancel (th->timeout_task);
       GNUNET_free (th);
       th = aux;
     }
@@ -420,7 +420,7 @@
     GNUNET_free (t->peers[i]);
   }
   if (t->npeers > 0)
-      GNUNET_free (t->peers);
+    GNUNET_free (t->peers);
   if (NULL != h->cleaner && 0 != t->owner)
     h->cleaner (h->cls, t, t->ctx);
   if (0 != t->owner)
@@ -608,9 +608,11 @@
   h->client = GNUNET_CLIENT_connect ("mesh", h->cfg);
   if (h->client == NULL)
   {
-    GNUNET_SCHEDULER_add_delayed(h->reconnect_time, &reconnect_cbk, h);
-    h->reconnect_time = GNUNET_TIME_relative_min(GNUNET_TIME_UNIT_HOURS,
-        GNUNET_TIME_relative_multiply(h->reconnect_time, 2));
+    GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
+    h->reconnect_time =
+        GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_HOURS,
+                                  GNUNET_TIME_relative_multiply
+                                  (h->reconnect_time, 2));
     GNUNET_break (0);
     return GNUNET_NO;
   }
@@ -668,9 +670,10 @@
 reconnect_cbk (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_MESH_Handle *h = cls;
+
   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
     return;
-  reconnect(h);
+  reconnect (h);
 }
 
 
@@ -686,7 +689,7 @@
  */
 static void
 process_tunnel_created (struct GNUNET_MESH_Handle *h,
-                       const struct GNUNET_MESH_TunnelNotification *msg)
+                        const struct GNUNET_MESH_TunnelNotification *msg)
 {
   struct GNUNET_MESH_Tunnel *t;
   struct GNUNET_TRANSPORT_ATS_Information atsi;
@@ -712,7 +715,7 @@
   {
     atsi.type = 0;
     atsi.value = 0;
-    t->ctx = h->new_tunnel(h->cls, t, &msg->peer, &atsi);
+    t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi);
   }
   GNUNET_CONTAINER_DLL_insert (h->tunnels_head, h->tunnels_tail, t);
   return;
@@ -737,15 +740,15 @@
 
   if (NULL == t)
   {
-    GNUNET_break(0);
+    GNUNET_break (0);
     return;
   }
   if (0 == t->owner)
   {
-    GNUNET_break(0);
+    GNUNET_break (0);
   }
 
-  destroy_tunnel(t);
+  destroy_tunnel (t);
   return;
 }
 
@@ -775,7 +778,7 @@
   t = retrieve_tunnel (h, ntohl (msg->tunnel_id));
   if (NULL == t)
   {
-    GNUNET_break(0);
+    GNUNET_break (0);
     return;
   }
   id = GNUNET_PEER_search (&msg->peer);
@@ -854,7 +857,7 @@
     GNUNET_break (0);
     return;
   }
-  type = ntohs(payload->type);
+  type = ntohs (payload->type);
   for (i = 0; i < h->n_handlers; i++)
   {
     handler = &h->message_handlers[i];
@@ -969,9 +972,9 @@
   {
 #if DEBUG
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh:     type: %u\n",
-                ntohs (((struct GNUNET_MessageHeader *)&th[1])->type));
+                ntohs (((struct GNUNET_MessageHeader *) &th[1])->type));
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh:     size: %u\n",
-                ntohs (((struct GNUNET_MessageHeader *)&th[1])->size));
+                ntohs (((struct GNUNET_MessageHeader *) &th[1])->size));
 #endif
     if (NULL != th->notify)
     {
@@ -988,7 +991,7 @@
           mc.header.size = htons (sizeof (mc) + th->size);
           mc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
           mc.tid = htonl (th->tunnel->tid);
-          memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity)); /* myself 
*/
+          memset (&mc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
           memcpy (cbuf, &mc, sizeof (mc));
           psize = th->size + sizeof (mc);
         }
@@ -1006,7 +1009,7 @@
           uc.header.size = htons (sizeof (uc) + th->size);
           uc.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST);
           uc.tid = htonl (th->tunnel->tid);
-          memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity));     /* 
myself */
+          memset (&uc.oid, 0, sizeof (struct GNUNET_PeerIdentity));
           GNUNET_PEER_resolve (th->target, &uc.destination);
           memcpy (cbuf, &uc, sizeof (uc));
           psize = th->size + sizeof (uc);
@@ -1210,9 +1213,9 @@
  */
 struct GNUNET_MESH_Tunnel *
 GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h, void *tunnel_ctx,
-                           GNUNET_MESH_TunnelConnectHandler connect_handler,
-                           GNUNET_MESH_TunnelDisconnectHandler
-                           disconnect_handler, void *handler_cls)
+                           GNUNET_MESH_PeerConnectHandler connect_handler,
+                           GNUNET_MESH_PeerDisconnectHandler 
disconnect_handler,
+                           void *handler_cls)
 {
   struct GNUNET_MESH_Tunnel *t;
   struct GNUNET_MESH_TunnelMessage msg;
@@ -1237,21 +1240,21 @@
  * @param tun tunnel handle
  */
 void
-GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *t)
+GNUNET_MESH_tunnel_destroy (struct GNUNET_MESH_Tunnel *tunnel)
 {
   struct GNUNET_MESH_Handle *h;
   struct GNUNET_MESH_TunnelMessage msg;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
-  h = t->mesh;
+  h = tunnel->mesh;
 
-  if (0 != t->owner)
-    GNUNET_PEER_change_rc (t->owner, -1);
+  if (0 != tunnel->owner)
+    GNUNET_PEER_change_rc (tunnel->owner, -1);
 
   msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
   msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
-  msg.tunnel_id = htonl (t->tid);
-  destroy_tunnel (t);
+  msg.tunnel_id = htonl (tunnel->tid);
+  destroy_tunnel (tunnel);
   send_packet (h, &msg.header);
 }
 
@@ -1401,7 +1404,7 @@
   uint32_t least_priority;
   size_t overhead;
 
-  GNUNET_assert(NULL != notify);
+  GNUNET_assert (NULL != notify);
   if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
       tunnel->npackets > 0)
   {
@@ -1422,16 +1425,16 @@
     }
     if (NULL == least_priority_th)
       return NULL;
-    GNUNET_assert(NULL != least_priority_th->notify); /* Cant be a cntrl msg */
-    least_priority_th->notify(notify_cls, 0, NULL);
+    /* Can't be a control message */
+    GNUNET_assert (NULL != least_priority_th->notify);
+    least_priority_th->notify (notify_cls, 0, NULL);
     least_priority_th->tunnel->npackets--;
     tunnel->mesh->npackets--;
-    GNUNET_CONTAINER_DLL_remove(tunnel->mesh->th_head,
-                                tunnel->mesh->th_tail,
-                                least_priority_th);
+    GNUNET_CONTAINER_DLL_remove (tunnel->mesh->th_head, tunnel->mesh->th_tail,
+                                 least_priority_th);
     if (GNUNET_SCHEDULER_NO_TASK != least_priority_th->timeout_task)
-      GNUNET_SCHEDULER_cancel(least_priority_th->timeout_task);
-    GNUNET_free(least_priority_th);
+      GNUNET_SCHEDULER_cancel (least_priority_th->timeout_task);
+    GNUNET_free (least_priority_th);
   }
   tunnel->npackets++;
   tunnel->mesh->npackets++;
@@ -1440,10 +1443,10 @@
   th->priority = priority;
   th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
   th->target = GNUNET_PEER_intern (target);
-  overhead =
-      (NULL ==
-       target) ? sizeof (struct GNUNET_MESH_Multicast) : sizeof (struct
-                                                                 
GNUNET_MESH_Unicast);
+  if (NULL == target)
+    overhead = sizeof (struct GNUNET_MESH_Multicast);
+  else
+    overhead = sizeof (struct GNUNET_MESH_Unicast);
   th->size = notify_size + overhead;
   th->notify = notify;
   th->notify_cls = notify_cls;

Modified: gnunet/src/mesh/test_mesh_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_api.c     2011-09-07 16:16:00 UTC (rev 16726)
+++ gnunet/src/mesh/test_mesh_api.c     2011-09-07 16:24:53 UTC (rev 16727)
@@ -121,8 +121,7 @@
     GNUNET_MESH_tunnel_destroy (t);
   }
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown,
-                                NULL);
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &do_shutdown, NULL);
 }
 
 

Modified: gnunet/src/mesh/test_mesh_local.c
===================================================================
--- gnunet/src/mesh/test_mesh_local.c   2011-09-07 16:16:00 UTC (rev 16726)
+++ gnunet/src/mesh/test_mesh_local.c   2011-09-07 16:24:53 UTC (rev 16727)
@@ -41,6 +41,15 @@
 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
 static GNUNET_SCHEDULER_TaskIdentifier test_task;
 
+static struct GNUNET_MESH_MessageHandler handlers1[] = {
+  {&callback, 1, 0},
+  {NULL, 0, 0}
+};
+
+static struct GNUNET_MESH_MessageHandler handlers2[] = { {NULL, 0, 0} };
+
+
+
 /**
  * Function is called whenever a message is received.
  *
@@ -59,17 +68,39 @@
           const struct GNUNET_MessageHeader *message,
           const struct GNUNET_TRANSPORT_ATS_Information *atsi)
 {
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Data callback\n");
   return GNUNET_OK;
 }
 
-static struct GNUNET_MESH_MessageHandler handlers1[] = {
-    {&callback, 1, 0},
-    {NULL, 0, 0}
-};
 
-static struct GNUNET_MESH_MessageHandler handlers2[] = {{NULL, 0, 0}};
+/**
+ * Method called whenever another peer has added us to a tunnel
+ * the other peer initiated.
+ *
+ * @param cls closure
+ * @param tunnel new handle to the tunnel
+ * @param initiator peer that started the tunnel
+ * @param atsi performance information for the tunnel
+ * @return initial tunnel context for the tunnel (can be NULL -- that's not an 
error)
+ */
+static void *
+inbound_tunnel (void *cls, struct GNUNET_MESH_Tunnel *tunnel,
+                const struct GNUNET_PeerIdentity *initiator,
+                const structGNUNET_TRANSPORT_ATS_Information * atsi)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: \n");
+  return NULL;
+}
 
 
+
+
+
+
+
+
+
+
 static void
 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
@@ -116,8 +147,7 @@
   struct GNUNET_CONFIGURATION_Handle *cfg = cls;
   static const GNUNET_MESH_ApplicationType app1[] =
       { 1, 2, 3, 4, 5, 6, 7, 8, 0 };
-  static const GNUNET_MESH_ApplicationType app2[] =
-      { 0 };
+  static const GNUNET_MESH_ApplicationType app2[] = { 0 };
 
   test_task = (GNUNET_SCHEDULER_TaskIdentifier) 0;
   mesh_peer_1 = GNUNET_MESH_connect (cfg, 10, 1, NULL, NULL, handlers1, app1);
@@ -135,10 +165,8 @@
   t_1 = GNUNET_MESH_tunnel_create (mesh_peer_1, NULL, NULL, NULL, 1);
 //   t_2 = GNUNET_MESH_tunnel_create (mesh_peer_2, NULL, NULL, NULL, 2);
 
-  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
-                                    GNUNET_TIME_UNIT_SECONDS,
-                                    2),
-                                &do_shutdown,
+  GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                (GNUNET_TIME_UNIT_SECONDS, 2), &do_shutdown,
                                 NULL);
 }
 




reply via email to

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