gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r15205 - in gnunet: contrib src/mesh


From: gnunet
Subject: [GNUnet-SVN] r15205 - in gnunet: contrib src/mesh
Date: Wed, 11 May 2011 17:38:26 +0200

Author: bartpolot
Date: 2011-05-11 17:38:25 +0200 (Wed, 11 May 2011)
New Revision: 15205

Added:
   gnunet/src/mesh/test_mesh.conf
Modified:
   gnunet/contrib/defaults.conf
   gnunet/src/mesh/gnunet-service-mesh.c
   gnunet/src/mesh/mesh_api_new.c
   gnunet/src/mesh/test_mesh_api.c
Log:
Added mesh testing code and configuration files


Modified: gnunet/contrib/defaults.conf
===================================================================
--- gnunet/contrib/defaults.conf        2011-05-11 13:49:16 UTC (rev 15204)
+++ gnunet/contrib/defaults.conf        2011-05-11 15:38:25 UTC (rev 15205)
@@ -354,3 +354,16 @@
 
 [block]
 PLUGINS = fs dht test
+
+[mesh]
+AUTOSTART = YES
+PORT = 10511
+HOSTNAME = localhost
+HOME = $SERVICEHOME
+CONFIG = $DEFAULTCONFIG
+BINARY = gnunet-service-mesh
+ACCEPT_FROM = 127.0.0.1;
+ACCEPT_FROM6 = ::1;
+UNIXPATH = /tmp/gnunet-service-mesh.sock
+UNIX_MATCH_UID = YES
+UNIX_MATCH_GID = YES

Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c       2011-05-11 13:49:16 UTC (rev 
15204)
+++ gnunet/src/mesh/gnunet-service-mesh.c       2011-05-11 15:38:25 UTC (rev 
15205)
@@ -710,8 +710,6 @@
     /* Create new client structure */
     c = GNUNET_malloc(sizeof(struct Client));
     c->handle = client;
-    c->tunnels_head = NULL;
-    c->tunnels_tail = NULL;
     if(payload_size != 0) {
         c->messages_subscribed = GNUNET_malloc(payload_size);
         memcpy(c->messages_subscribed, &message[1], payload_size);
@@ -724,6 +722,7 @@
     GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
 
     GNUNET_SERVER_receive_done(client, GNUNET_OK);
+
 }
 
 /**
@@ -777,16 +776,6 @@
     t = GNUNET_malloc(sizeof(struct MESH_tunnel));
     t->tid = ntohl(tunnel_msg->tunnel_id);
     t->oid = myid;
-    t->peers_ready = 0;
-    t->peers_total = 0;
-    t->peers_head = NULL;
-    t->peers_tail = NULL;
-    t->paths_head = NULL;
-    t->paths_tail = NULL;
-    t->in_head = NULL;
-    t->in_tail = NULL;
-    t->out_head = NULL;
-    t->out_tail = NULL;
     t->client = c;
 
     GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
@@ -1319,7 +1308,7 @@
      struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 3 
********\n");
     GNUNET_SERVER_add_handlers (server, plugin_handlers);
     GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
     core_handle = GNUNET_CORE_connect (c,               /* Main configuration 
*/
@@ -1334,11 +1323,10 @@
                             NULL, /* Don't notify about all outbound messages 
*/
                             GNUNET_NO,    /* For header-only out notification 
*/
                             core_handlers);        /* Register these handlers 
*/
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 
********\n");
     if (core_handle == NULL) {
         GNUNET_break(0);
     }
-
     dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */
     if (dht_handle == NULL) {
         GNUNET_break(0);
@@ -1356,12 +1344,13 @@
 main (int argc, char *const *argv)
 {
     int ret;
-
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 1 
********\n");
     ret = (GNUNET_OK ==
            GNUNET_SERVICE_run (argc,
                                argv,
                                "mesh",
                                GNUNET_SERVICE_OPTION_NONE,
                                &run, NULL)) ? 0 : 1;
+GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 2 
********\n");
     return ret;
-    }
+}

Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c      2011-05-11 13:49:16 UTC (rev 15204)
+++ gnunet/src/mesh/mesh_api_new.c      2011-05-11 15:38:25 UTC (rev 15205)
@@ -137,26 +137,30 @@
     int                                 napps;
 
     if(0 == size || buf == NULL) {
-        /* TODO treat error / retry */
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer 
invalid\n");
         return 0;
     }
     if(sizeof(struct GNUNET_MessageHeader) > size) {
-        /* TODO treat error / retry */
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too 
small\n");
         return 0;
     }
+
     msg = (struct GNUNET_MESH_ClientConnect *) buf;
     h = (struct GNUNET_MESH_Handle *) cls;
     msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
+
     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;
     }
+
     for(napps = 0, apps = NULL; h->applications[napps]; napps++) {
         apps = GNUNET_realloc(apps,
                               sizeof(GNUNET_MESH_ApplicationType) *
                                 (napps + 1));
         apps[napps] = h->applications[napps];
     }
+
     msg->header.size = sizeof(struct GNUNET_MESH_ClientConnect) +
                         sizeof(uint16_t) * ntypes +
                         sizeof(GNUNET_MESH_ApplicationType) * napps;
@@ -164,15 +168,37 @@
         /* TODO treat error / retry */
         return 0;
     }
+
     memcpy(&msg[1], types, sizeof(uint16_t) * ntypes);
     memcpy(&msg[1] + sizeof(uint16_t) * ntypes,
            apps,
            sizeof(GNUNET_MESH_ApplicationType) * napps);
+
     return msg->header.size;
 }
 
+/**
+ * Type of a function to call when we receive a message
+ * from the service.
+ *
+ * @param cls closure
+ * @param msg message received, NULL on timeout or fatal error
+ */
+void msg_received (void *cls,
+                                              const struct
+                                              GNUNET_MessageHeader * msg) {
+    uint16_t t;
+    if(msg != NULL){
+        t = ntohs(msg->type);
+    } else {
+        t = 0;
+    }
+    GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+               "received a message from mesh (of size %d)\n",
+               t);
+    return;
+}
 
-
 /**
  * Connect to the mesh service.
  *
@@ -199,21 +225,23 @@
 
     h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
 
-
     h->cleaner = cleaner;
     h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
+    GNUNET_CLIENT_receive (h->mesh,
+                         &msg_received,
+                         h, 
+                         GNUNET_TIME_UNIT_FOREVER_REL);
     if(h->mesh == NULL) {
         GNUNET_free(h);
         return NULL;
     }
+
     h->cls = cls;
     h->message_handlers = handlers;
     h->applications = stypes;
 
     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++);
-    h->n_handlers--;
-    h->n_applications--;
 
     size = sizeof(struct GNUNET_MESH_ClientConnect);
     size += h->n_handlers * sizeof(uint16_t);
@@ -221,8 +249,8 @@
 
     GNUNET_CLIENT_notify_transmit_ready(h->mesh,
                                         size,
-                                        GNUNET_TIME_relative_get_forever(),
-                                        GNUNET_YES,
+                                        GNUNET_TIME_relative_multiply 
(GNUNET_TIME_UNIT_SECONDS, 10),
+                                        GNUNET_NO,
                                         &send_connect_packet,
                                         (void *)h);
 
@@ -236,7 +264,7 @@
  * @param handle connection to mesh to disconnect
  */
 void GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) {
-    
+
     GNUNET_free(handle);
     return;
 }

Added: gnunet/src/mesh/test_mesh.conf
===================================================================
--- gnunet/src/mesh/test_mesh.conf                              (rev 0)
+++ gnunet/src/mesh/test_mesh.conf      2011-05-11 15:38:25 UTC (rev 15205)
@@ -0,0 +1,59 @@
+[fs]
+AUTOSTART = NO
+
+[resolver]
+AUTOSTART = NO
+
+[mesh]
+DEBUG = YES
+AUTOSTART = YES
+ACCEPT_FROM = 127.0.0.1;
+HOSTNAME = localhost
+PORT = 10511
+
+[dht]
+DEBUG = NO
+AUTOSTART = YES
+ACCEPT_FROM6 = ::1;
+ACCEPT_FROM = 127.0.0.1;
+HOSTNAME = localhost
+PORT = 2100
+
+[block]
+plugins = dht test
+
+[dhtcache]
+QUOTA = 1000000
+DATABASE = sqlite
+
+[transport]
+PLUGINS = tcp
+DEBUG = NO
+ACCEPT_FROM6 = ::1;
+ACCEPT_FROM = 127.0.0.1;
+NEIGHBOUR_LIMIT = 50
+PORT = 12365
+
+[core]
+TOTAL_QUOTA_OUT = 3932160
+TOTAL_QUOTA_IN = 3932160
+PORT = 12092
+
+[arm]
+DEFAULTSERVICES = core
+PORT = 12366
+DEBUG = NO
+
+[transport-tcp]
+TIMEOUT = 300000
+PORT = 12368
+
+[TESTING]
+WEAKRANDOM = YES
+
+[gnunetd]
+HOSTKEY = $SERVICEHOME/.hostkey
+
+[PATHS]
+DEFAULTCONFIG = test_mesh.conf
+SERVICEHOME = /tmp/test-mesh/

Modified: gnunet/src/mesh/test_mesh_api.c
===================================================================
--- gnunet/src/mesh/test_mesh_api.c     2011-05-11 13:49:16 UTC (rev 15204)
+++ gnunet/src/mesh/test_mesh_api.c     2011-05-11 15:38:25 UTC (rev 15205)
@@ -7,6 +7,7 @@
     {NULL, 0, 0}
 };
 
+
 static void
 run (void *cls,
      char *const *args,
@@ -14,38 +15,31 @@
     struct GNUNET_OS_Process            *arm_pid;
     struct GNUNET_MESH_Handle           *mesh;
     struct GNUNET_DHT_Handle            *dht;
-//     struct GNUNET_MESH_Tunnel           *t;
+    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_dht_api_data.conf",
+                                       "-c", "test_mesh.conf",
                                        NULL);
-//     sleep(1);
-//     printf("%d\n", fopen( "test_mesh.conf", "r"));
-//     GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, 
"test_mesh.conf"));
-    //printf("%d\n", GNUNET_CONFIGURATION_load (cfg, NULL));
-//     printf("%d\n", GNUNET_CONFIGURATION_load (cfg, 
"test_dht_api_data.conf"));
     dht = GNUNET_DHT_connect(cfg, 100);
     if(NULL == dht) {
-//         fprintf(stderr, "Couldn't connect to dht :(\n");
-//         return 1; // succeed anyway
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to dht :(\n");
     } else {
-//         fprintf(stderr, "YAY! CONNECTED TO DHT :D\n");
+        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO DHT :D\n");
     }
-//     mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, NULL);
-//     if(NULL == mesh) {
-//         fprintf(stderr, "Couldn't connect to mesh :(\n");
-//         return 1; // succeed anyway
-//     } else {
-//         fprintf(stderr, "YAY! CONNECTED TO MESH :D\n");
-//     }
-//     mesh = realloc(mesh, 0); // don't complain about *mesh
-//     printf("MESH TEST\n");
-//     t = GNUNET_MESH_tunnel_create(mesh, );
 
+    app = 0;
+    mesh = GNUNET_MESH_connect(cfg, NULL, NULL, handlers, &app);
+    if(NULL == mesh) {
+        GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Couldn't connect to mesh :(\n");
+    } else {
+        GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "YAY! CONNECTED TO MESH :D\n");
+    }
+
     /* do real test work here */
     if (0 != GNUNET_OS_process_kill (arm_pid, SIGTERM))
         GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
@@ -55,33 +49,24 @@
     return;
 }
 
-static int
-check ()
-{
-  int ret;
-  char *const argv[] = {"test-mesh-api",
-    "-c",
-    "test_dht_api_data.conf",
-#if VERBOSE
-    "-L", "DEBUG",
-#endif
-    NULL
-  };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
-                      argv, "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);
-    }
-  return GNUNET_OK;
-}
 
+
 int main (int argc, char *argv[]) {
-    if(GNUNET_OK == check())
-        return 0;
-    else return 1;
+    int ret;
+    char *const argv2[] = {"test-mesh-api",
+        "-c", "test_mesh.conf",
+        "-L", "DEBUG",
+        NULL
+    };
+    struct GNUNET_GETOPT_CommandLineOption options[] = {
+        GNUNET_GETOPT_OPTION_END
+    };
+      GNUNET_log_setup ("test-dht-api","DEBUG", NULL);
+    ret = GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1,
+                        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);
+    }
+    return 0;
 }




reply via email to

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