gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r22643 - gnunet/src/mesh
Date: Fri, 13 Jul 2012 19:42:17 +0200

Author: bartpolot
Date: 2012-07-13 19:42:17 +0200 (Fri, 13 Jul 2012)
New Revision: 22643

Modified:
   gnunet/src/mesh/gnunet-service-mesh_new.c
   gnunet/src/mesh/test_mesh_regex.c
Log:
- fix for a periodic accepting state, some refactoring

Modified: gnunet/src/mesh/gnunet-service-mesh_new.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh_new.c   2012-07-13 17:36:45 UTC (rev 
22642)
+++ gnunet/src/mesh/gnunet-service-mesh_new.c   2012-07-13 17:42:17 UTC (rev 
22643)
@@ -804,11 +804,31 @@
                         size_t size, const void *data);
 
 
-/******************************************************************************/
-/************************         ITERATORS        
****************************/
-/******************************************************************************/
+/**
+ * Function to process DHT string to regex matching.
+ * Called on each result obtained for the DHT search.
+ *
+ * @param cls closure (search context)
+ * @param exp when will this value expire
+ * @param key key of the result
+ * @param get_path path of the get request (not used)
+ * @param get_path_length lenght of get_path (not used)
+ * @param put_path path of the put request (not used)
+ * @param put_path_length length of the put_path (not used)
+ * @param type type of the result
+ * @param size number of bytes in data
+ * @param data pointer to the result data
+ */
+static void
+dht_get_string_accept_handler (void *cls, struct GNUNET_TIME_Absolute exp,
+                               const struct GNUNET_HashCode * key,
+                               const struct GNUNET_PeerIdentity *get_path,
+                               unsigned int get_path_length,
+                               const struct GNUNET_PeerIdentity *put_path,
+                               unsigned int put_path_length,
+                               enum GNUNET_BLOCK_Type type,
+                               size_t size, const void *data);
 
-/* FIXME move iterators here */
 
 /**
  * Iterator over edges in a regex block retrieved from the DHT.
@@ -825,14 +845,32 @@
                      const char *token,
                      size_t len,
                      const struct GNUNET_HashCode *key);
+
+
 /**
- * Iterator over hash map entries.
+ * Find a path to a peer that offers a regex servcie compatible
+ * with a given string.
+ * 
+ * @param key The key of the accepting state.
+ * @param ctx Context containing info about the string, tunnel, etc.
+ */
+static void
+regex_find_path (const struct GNUNET_HashCode *key,
+                 struct MeshRegexSearchContext *ctx);
+
+/******************************************************************************/
+/************************         ITERATORS        
****************************/
+/******************************************************************************/
+
+/* FIXME move iterators here */
+
+/**
+ * Iterator over found existing mesh regex blocks that match an ongoing search.
  *
  * @param cls closure
  * @param key current key code
  * @param value value in the hash map
- * @return GNUNET_YES if we should continue to
- *         iterate,
+ * @return GNUNET_YES if we should continue to iterate,
  *         GNUNET_NO if not.
  */
 static int
@@ -843,7 +881,20 @@
   struct MeshRegexBlock *block = value;
   struct MeshRegexSearchContext *ctx = cls;
 
-  // block was checked when stored, no need to check again
+  if (GNUNET_YES == ntohl(block->accepting) &&
+      ctx->position == strlen (ctx->info->description))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* Found accepting known block\n");
+    regex_find_path (key, ctx);
+    return GNUNET_YES; // We found an accept state!
+  }
+  else
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "* %u, %u, [%u]\n",
+                ctx->position, strlen(ctx->info->description),
+                ntohl(block->accepting));
+
+  }
   (void) GNUNET_MESH_regex_block_iterate (block, SIZE_MAX,
                                           &regex_edge_iterator, ctx);
 
@@ -882,6 +933,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*     ctlen : %u\n", current_len);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*     tklen : %u\n", len);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*     tk[0] : %c\n", token[0]);
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*     nextk : %s\n", GNUNET_h2s(key));
   if (len > current_len)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "*     Token too long, END\n");
@@ -894,7 +946,7 @@
   }
   new_ctx = GNUNET_malloc (sizeof (struct MeshRegexSearchContext));
   new_ctx->info = info;
-  new_ctx->position += ctx->position + len;
+  new_ctx->position = ctx->position + len;
   GNUNET_array_append (info->contexts, info->n_contexts, new_ctx);
   if (GNUNET_YES ==
       GNUNET_CONTAINER_multihashmap_contains(info->dht_get_handles, key))
@@ -1096,7 +1148,37 @@
 
 }
 
+/**
+ * Find a path to a peer that offers a regex servcie compatible
+ * with a given string.
+ * 
+ * @param key The key of the accepting state.
+ * @param ctx Context containing info about the string, tunnel, etc.
+ */
+static void
+regex_find_path (const struct GNUNET_HashCode *key,
+                 struct MeshRegexSearchContext *ctx)
+{
+  struct GNUNET_DHT_GetHandle *get_h;
 
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n");
+  get_h = GNUNET_DHT_get_start (dht_handle,    /* handle */
+                                GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT, /* type */
+                                key,     /* key to search */
+                                DHT_REPLICATION_LEVEL, /* replication level */
+                                GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
+                                GNUNET_DHT_RO_RECORD_ROUTE,
+                                NULL,       /* xquery */ // FIXME BLOOMFILTER
+                                0,     /* xquery bits */ // FIXME BLOOMFILTER 
SIZE
+                                &dht_get_string_accept_handler, ctx);
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_CONTAINER_multihashmap_put(ctx->info->dht_get_handles,
+                                                  key,
+                                                  get_h,
+                                                  
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+}
+
+
 
/******************************************************************************/
 /************************    PERIODIC FUNCTIONS    
****************************/
 
/******************************************************************************/
@@ -4025,7 +4107,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received a path ACK msg [%s]\n",
               GNUNET_i2s (&my_full_id));
   msg = (struct GNUNET_MESH_PathACK *) message;
-  t = tunnel_get (&msg->oid, msg->tid);
+  t = tunnel_get (&msg->oid, ntohl(msg->tid));
   if (NULL == t)
   {
     /* TODO notify that we don't know the tunnel */
@@ -4396,7 +4478,8 @@
                                const struct GNUNET_PeerIdentity *get_path,
                                unsigned int get_path_length,
                                const struct GNUNET_PeerIdentity *put_path,
-                               unsigned int put_path_length, enum 
GNUNET_BLOCK_Type type,
+                               unsigned int put_path_length,
+                               enum GNUNET_BLOCK_Type type,
                                size_t size, const void *data)
 {
   const struct MeshRegexAccept *block = data;
@@ -4490,22 +4573,7 @@
   {
     if (GNUNET_YES == ntohl (block->accepting))
     {
-      struct GNUNET_DHT_GetHandle *get_h;
-      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found peer by service\n");
-      get_h = GNUNET_DHT_get_start (dht_handle,    /* handle */
-                                    GNUNET_BLOCK_TYPE_MESH_REGEX_ACCEPT, /* 
type */
-                                    key,     /* key to search */
-                                    DHT_REPLICATION_LEVEL, /* replication 
level */
-                                    GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE |
-                                    GNUNET_DHT_RO_RECORD_ROUTE,
-                                    NULL,       /* xquery */ // FIXME 
BLOOMFILTER
-                                    0,     /* xquery bits */ // FIXME 
BLOOMFILTER SIZE
-                                    &dht_get_string_accept_handler, ctx);
-      GNUNET_break (GNUNET_OK ==
-                    GNUNET_CONTAINER_multihashmap_put(info->dht_get_handles,
-                                                      key,
-                                                      get_h,
-                                                      
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+      regex_find_path(key, ctx);
     }
     else
     {

Modified: gnunet/src/mesh/test_mesh_regex.c
===================================================================
--- gnunet/src/mesh/test_mesh_regex.c   2012-07-13 17:36:45 UTC (rev 22642)
+++ gnunet/src/mesh/test_mesh_regex.c   2012-07-13 17:42:17 UTC (rev 22643)
@@ -50,7 +50,7 @@
 /**
  * How many connects have happened.
  */
-static int connected_peers;
+static int regex_peers;
 
 /**
  * Be verbose
@@ -286,7 +286,7 @@
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "Peer connected: %s\n",
               GNUNET_i2s (peer));
-  connected_peers++;
+  regex_peers++;
  
   GNUNET_MESH_notify_transmit_ready(t[i], 0, 0,
                                     GNUNET_TIME_UNIT_FOREVER_REL,
@@ -432,7 +432,7 @@
                             NULL,
                             handlers,
                             &app);
-  connected_peers = 0;
+  regex_peers = 0;
   for (i = 0; i < MESH_REGEX_PEERS; i++)
   {
     ok[i] = GNUNET_NO;
@@ -601,11 +601,11 @@
                   i, strings[i]);
     }
   }
-  if (GNUNET_OK != result || connected_peers != MESH_REGEX_PEERS)
+  if (GNUNET_OK != result || regex_peers != MESH_REGEX_PEERS)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "test: FAILED! %u connected peers\n",
-                connected_peers);
+                regex_peers);
     return 1;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: success\n");




reply via email to

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