gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r15228 - gnunet/src/mesh
Date: Fri, 13 May 2011 00:21:16 +0200

Author: bartpolot
Date: 2011-05-13 00:21:16 +0200 (Fri, 13 May 2011)
New Revision: 15228

Modified:
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh.h
   gnunet/src/mesh/mesh_api_new.c
   gnunet/src/mesh/mesh_protocol.h
   gnunet/src/mesh/test_mesh_api.c
Log:
WiP


Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-05-12 17:52:38 UTC (rev 
15227)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-05-12 22:21:16 UTC (rev 
15228)
@@ -657,8 +657,7 @@
                                         + (p->length
                                         * sizeof (struct GNUNET_PeerIdentity)),
                                       &send_core_create_path_for_peer,
-                                      peer_info
-                                     );
+                                      peer_info);
     return;
 }
 
@@ -676,9 +675,13 @@
     struct MeshClient   *c, *next;
     struct MESH_tunnel  *t;
 
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "MESH: client disconnected\n");
     c = clients_head;
     while (NULL != c) {
         if (c->handle == client) {
+            GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "MESH: cleaning client structures\n");
             GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
             while (NULL != (t = c->tunnels_head)) {
                 destroy_tunnel(c, t);
@@ -710,8 +713,10 @@
     struct MeshClient           *c;
     unsigned int                payload_size;
 
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "MESH: new client connected\n");
     /* Check data sanity */
-    payload_size = message->size - sizeof(struct GNUNET_MessageHeader);
+    payload_size = ntohs(message->size) - sizeof(struct GNUNET_MessageHeader);
     if (0 != payload_size % sizeof(GNUNET_MESH_ApplicationType)) {
         GNUNET_break(0);
         GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
@@ -728,6 +733,8 @@
         c->messages_subscribed = NULL;
     }
     c->subscription_counter = payload_size/sizeof(GNUNET_MESH_ApplicationType);
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "MESH:  client has %u subscriptions\n", 
c->subscription_counter);
 
     /* Insert new client in DLL */
     GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);

Modified: gnunet/src/mesh/mesh.h
===================================================================
--- gnunet/src/mesh/mesh.h      2011-05-12 17:52:38 UTC (rev 15227)
+++ gnunet/src/mesh/mesh.h      2011-05-12 22:21:16 UTC (rev 15228)
@@ -76,8 +76,8 @@
      *       sizeof(MESH_ApplicationType) * applications
      */
     struct GNUNET_MessageHeader header;
-    uint16_t                    types;
-    uint16_t                    applications;
+    uint16_t                    types           GNUNET_PACKED;
+    uint16_t                    applications    GNUNET_PACKED;
 };
 
 

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-05-12 17:52:38 UTC (rev 15227)
+++ gnunet/src/mesh/mesh_api_new.c      2011-05-12 22:21:16 UTC (rev 15228)
@@ -133,34 +133,35 @@
  * @return number of bytes written to buf
  */
 static size_t 
-send_connect_packet (void *cls, size_t size, void *buf) {
+send_connect_packet (void *cls, size_t size, void *buf)
+{
     struct GNUNET_MESH_Handle           *h = cls;
     struct GNUNET_MESH_ClientConnect    *msg;
     uint16_t                            *types;
-    int                                 ntypes;
+    uint16_t                            ntypes;
     GNUNET_MESH_ApplicationType         *apps;
-    int                                 napps;
+    uint16_t                            napps;
 
     h->th = NULL;
     if (0 == size || buf == NULL) {
         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                    "Send: buffer size 0 or buffer invalid\n");
+                    "Send connect packet: buffer size 0 or buffer invalid\n");
        // FIXME: disconnect, reconnect, retry!
         return 0;
     }
     if (sizeof(struct GNUNET_MessageHeader) > size) {
         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                    "Send: buffer size too small\n");
+                    "Send connect packet: buffer size too small\n");
        // FIXME: disconnect, reconnect, retry!
         return 0;
     }
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Sending into %lu bytes buffer\n",
+                "Send connect packet: %lu bytes buffer\n",
                 size);
     msg = (struct GNUNET_MESH_ClientConnect *) buf;
-    msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
+    msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT);
 
-    for(ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) {
+    for (ntypes = 0, types = NULL; h->message_handlers[ntypes].type; ntypes++) 
{
         types = GNUNET_realloc(types, sizeof(uint16_t) * (ntypes + 1));
         types[ntypes] = h->message_handlers[ntypes].type;
     }
@@ -172,20 +173,24 @@
         apps[napps] = h->applications[napps];
     }
 
-    msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
-                        sizeof(uint16_t) * ntypes +
-                        sizeof(GNUNET_MESH_ApplicationType) * napps;
-    if(msg->header.size > size) {
-        /* TODO treat error / retry */
-        return 0;
-    }
+    msg->header.size = htons(sizeof(struct GNUNET_MESH_ClientConnect) +
+                             sizeof(uint16_t) * ntypes +
+                             sizeof(GNUNET_MESH_ApplicationType) * napps);
 
     memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
     memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
            apps,
            sizeof(GNUNET_MESH_ApplicationType) * napps);
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                "Sent %lu bytes long message %d types and %d apps\n",
+                ntohs(msg->header.size),
+                ntypes,
+                napps
+               );
+    msg->applications = htons(napps);
+    msg->types = htons(ntypes);
 
-    return msg->header.size;
+    return ntohs(msg->header.size);
 }
 
 

Modified: gnunet/src/mesh/mesh_protocol.h
===================================================================
--- gnunet/src/mesh/mesh_protocol.h     2011-05-12 17:52:38 UTC (rev 15227)
+++ gnunet/src/mesh/mesh_protocol.h     2011-05-12 22:21:16 UTC (rev 15228)
@@ -55,18 +55,18 @@
      * Global id of the tunnel this path belongs to,
      * unique in conjunction with the origin.
      */
-    uint32_t tid GNUNET_PACKED;
+    uint32_t                    tid GNUNET_PACKED;
 
     /**
      * Information about speed requirements.  If the tunnel cannot sustain the 
      * minimum bandwidth, packets are to be dropped.
      */
-    uint32_t speed_min GNUNET_PACKED;
+    uint32_t                    speed_min GNUNET_PACKED;
 
     /**
      * 64-bit alignment.
      */
-    uint32_t reserved GNUNET_PACKED;
+    uint32_t                    reserved GNUNET_PACKED;
 
     /**
      * path_length structs defining the *whole* path from the origin [0] to the
@@ -88,12 +88,12 @@
     /**
      * TID of the tunnel
      */
-    uint32_t tid GNUNET_PACKED;
+    uint32_t                    tid GNUNET_PACKED;
 
     /**
      * OID of the tunnel
      */
-    struct GNUNET_PeerIdentity oid;
+    struct GNUNET_PeerIdentity  oid;
 
     /**
      * Payload follows
@@ -114,17 +114,17 @@
     /**
      * TID of the tunnel
      */
-    uint32_t tid GNUNET_PACKED;
+    uint32_t                    tid GNUNET_PACKED;
 
     /**
      * OID of the tunnel
      */
-    struct GNUNET_PeerIdentity oid;
+    struct GNUNET_PeerIdentity  oid;
 
     /**
      * Destination.
      */
-    struct GNUNET_PeerIdentity destination;
+    struct GNUNET_PeerIdentity  destination;
 
     /**
      * Payload follows
@@ -145,17 +145,17 @@
     /**
      * TID of the tunnel
      */
-    uint32_t tid GNUNET_PACKED;
+    uint32_t                    tid GNUNET_PACKED;
 
     /**
      * OID of the tunnel
      */
-    struct GNUNET_PeerIdentity oid;
+    struct GNUNET_PeerIdentity  oid;
 
     /**
      * Sender of the message.
      */
-    struct GNUNET_PeerIdentity sender;
+    struct GNUNET_PeerIdentity  sender;
 
     /**
      * Payload follows
@@ -175,17 +175,17 @@
     /**
      * TID of the tunnel
      */
-    uint32_t tid GNUNET_PACKED;
+    uint32_t                    tid GNUNET_PACKED;
 
     /**
      * OID of the tunnel
      */
-    struct GNUNET_PeerIdentity oid;
+    struct GNUNET_PeerIdentity  oid;
 
     /**
      * Slowest link down the path (above minimum speed requirement).
      */
-    uint32_t speed_min;
+    uint32_t                    speed_min;
 
 };
 

Modified: gnunet/src/mesh/test_mesh_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_api.c     2011-05-12 17:52:38 UTC (rev 15227)
+++ gnunet/src/mesh/test_mesh_api.c     2011-05-12 22:21:16 UTC (rev 15228)
@@ -11,42 +11,47 @@
 
 static struct GNUNET_MESH_Handle           *mesh;
 
-static struct GNUNET_DHT_Handle            *dht;
-
 static void
-  do_shutdown (void *cls,
-              const struct GNUNET_SCHEDULER_TaskContext *tc)
+do_shutdown (void *cls,
+             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
-  if (NULL != mesh)
-    GNUNET_MESH_disconnect (mesh);
-    if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
+    if (NULL != mesh) {
+        GNUNET_MESH_disconnect (mesh);
+    }
+    if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+    }
     GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
     GNUNET_OS_process_close (arm_pid);
 }
 
 
 static void
+error_shutdown (void *cls,
+                const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+    if (NULL != mesh) {
+        GNUNET_MESH_disconnect (mesh);
+    }
+    if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM)) {
+        GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
+    }
+    GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (arm_pid));
+    GNUNET_OS_process_close (arm_pid);
+}
+
+static void
 run (void *cls,
      char *const *args,
      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) {
     GNUNET_MESH_ApplicationType         app;
-    // char                                buffer[2048];
 
-
     arm_pid = GNUNET_OS_start_process (NULL, NULL,
                                        "gnunet-service-arm",
                                        "gnunet-service-arm",
                                        "-L", "DEBUG",
                                        "-c", "test_mesh.conf",
                                        NULL);
-    dht = GNUNET_DHT_connect(cfg, 100);
-    if(NULL == dht) {
-        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
-    } else {
-        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
-    }
-
     app = 0;
     mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
     if(NULL == mesh) {
@@ -56,15 +61,13 @@
     }
 
     /* do real test work here */
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                 &do_shutdown,
-                                 NULL);
+    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(
+                                    GNUNET_TIME_UNIT_SECONDS, 5),
+                                  &do_shutdown,
+                                  NULL);
 }
 
 
-
-
-
 int main (int argc, char *argv[]) {
     int ret;
     char *const argv2[] = {"test-mesh-api",
@@ -80,7 +83,9 @@
                         argv2, "test-mesh-api", "nohelp",
                         options, &run, NULL);
     if (ret != GNUNET_OK) {
-        GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "test-mesh-api': Failed with 
error code %d\n", ret);
+        GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
+                   "test-mesh-api': Failed with error code %d\n", ret);
+        return 1;
     }
     return 0;
 }




reply via email to

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