gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r11161 - in gnunet: . src/fs


From: gnunet
Subject: [GNUnet-SVN] r11161 - in gnunet: . src/fs
Date: Mon, 3 May 2010 15:34:45 +0200

Author: grothoff
Date: 2010-05-03 15:34:45 +0200 (Mon, 03 May 2010)
New Revision: 11161

Modified:
   gnunet/ChangeLog
   gnunet/TODO
   gnunet/src/fs/fs.c
   gnunet/src/fs/fs.h
Log:
search syncing

Modified: gnunet/ChangeLog
===================================================================
--- gnunet/ChangeLog    2010-05-03 09:58:52 UTC (rev 11160)
+++ gnunet/ChangeLog    2010-05-03 13:34:45 UTC (rev 11161)
@@ -1,6 +1,6 @@
 Sun May  2 13:49:10 CEST 2010
        Fixed problem with platform-dependence of format for IP addresses
-       in HELLOs for TCP and UDP transport. 
+       in HELLOs for TCP and UDP transport.
        Reduced address length field in HELLOs to 16 bit (was 32 bit).
        These changes break transport compatibility.
 

Modified: gnunet/TODO
===================================================================
--- gnunet/TODO 2010-05-03 09:58:52 UTC (rev 11160)
+++ gnunet/TODO 2010-05-03 13:34:45 UTC (rev 11161)
@@ -1,6 +1,8 @@
 0.9.0pre1:
 * FS: [CG]
-  - serialization and deserialization code (search, download)
+  - deserialization code (download)
+  - serialization code (download)
+  - linking of downloads to searches 
   - generate SUSPEND events (publish, unindex, search, download)
   - actually call 'sync' functions (publish, unindex, search, download)
   - persistence testing (publish, unindex)
@@ -71,6 +73,9 @@
 * FS: [CG]
   - datastore reservation (publishing)
   - location URIs (publish, search, download)
+  - utilize in-line files in meta data always (including in search results or
+    when download is triggered manually and for probes); currently the data is
+    only used when users do a general 'recursive' download
   - non-anonymous FS service (needs DHT)
     + DHT integration for search
     + CS-DHT-functions (DHT-put of LOC)

Modified: gnunet/src/fs/fs.c
===================================================================
--- gnunet/src/fs/fs.c  2010-05-03 09:58:52 UTC (rev 11160)
+++ gnunet/src/fs/fs.c  2010-05-03 13:34:45 UTC (rev 11161)
@@ -211,8 +211,6 @@
 }
 
 
-
-
 /**
  * Closure for "data_reader_file".
  */
@@ -1251,12 +1249,56 @@
  * publishing structs should already call "sync" internally,
  * so this function is likely not useful for clients.
  * 
- * @param sc the struct to sync
+ * @param key key for the search result
+ * @param sr the struct to sync
  */
 void
-GNUNET_FS_search_result_sync_ (struct SearchResult *sr)
+GNUNET_FS_search_result_sync_ (const GNUNET_HashCode *key,
+                              struct SearchResult *sr)
 {
-  /* FIXME */
+  struct GNUNET_BIO_WriteHandle *wh;
+  char *uris;
+
+  GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_chk (sr->uri)) ||
+                 (GNUNET_YES == GNUNET_FS_uri_test_loc (sr->uri)) );
+  uris = NULL;
+  if (NULL == sr->serialization)
+    sr->serialization = make_serialization_file_name (sr->sc->h,
+                                                     "search-results");
+  if (NULL == sr->serialization)
+    return;
+  wh = get_write_handle (sr->sc->h, "search-results", sr->serialization);
+  uris = GNUNET_FS_uri_to_string (sr->uri);
+  if ( (GNUNET_OK !=
+       GNUNET_BIO_write_string (wh, uris)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_meta_data (wh, sr->meta)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write (wh, key, sizeof (GNUNET_HashCode))) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int32 (wh, sr->mandatory_missing)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int32 (wh, sr->optional_support)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int32 (wh, sr->availability_success)) ||
+       (GNUNET_OK !=
+       GNUNET_BIO_write_int32 (wh, sr->availability_trials)) )
+    goto cleanup;   
+  if (GNUNET_OK !=
+      GNUNET_BIO_write_close (wh))
+    {
+      wh = NULL;
+      goto cleanup;
+    }
+  GNUNET_free_non_null (uris);
+  return;
+ cleanup:
+  GNUNET_free_non_null (uris);
+  if (wh != NULL)
+    (void)  GNUNET_BIO_write_close (wh);
+  GNUNET_FS_remove_sync_file_ (sr->sc->h, "search-results", sr->serialization);
+  GNUNET_free (sr->serialization);
+  sr->serialization = NULL;
 }
 
 
@@ -1272,6 +1314,9 @@
 GNUNET_FS_search_sync_ (struct GNUNET_FS_SearchContext *sc)
 {  
   struct GNUNET_BIO_WriteHandle *wh;
+  struct GNUNET_FS_SearchContext *scc;
+  char *uris;
+  char in_pause;
 
   if (NULL == sc->serialization)
     sc->serialization = make_serialization_file_name (sc->h,
@@ -1279,38 +1324,50 @@
   if (NULL == sc->serialization)
     return;
   wh = get_write_handle (sc->h, "search", sc->serialization);
-#if 0
+  GNUNET_assert ( (GNUNET_YES == GNUNET_FS_uri_test_ksk (sc->uri)) ||
+                 (GNUNET_YES == GNUNET_FS_uri_test_sks (sc->uri)) );
+  uris = GNUNET_FS_uri_to_string (sc->uri);
+  in_pause = (sc->task != GNUNET_SCHEDULER_NO_TASK) ? 'r' : '\0';
   if ( (GNUNET_OK !=
-       GNUNET_BIO_write_string (wh, pc->nid)) ||
+       GNUNET_BIO_write_string (wh, uris)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_write_string (wh, pc->nuid)) ||
+       GNUNET_BIO_write_int64 (wh, sc->start_time.value)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_write_int32 (wh, pc->options)) ||
+       GNUNET_BIO_write_string (wh, sc->emsg)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_write_int32 (wh, pc->all_done)) ||
+       GNUNET_BIO_write_int32 (wh, (uint32_t) sc->options)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_write_string (wh, pc->fi->serialization)) ||
+       GNUNET_BIO_write (wh, &in_pause, sizeof (in_pause))) ||
        (GNUNET_OK !=
-       GNUNET_BIO_write_string (wh, (pc->fi_pos == NULL) ? NULL : 
pc->fi_pos->serialization)) ||
-       (GNUNET_OK !=
-       GNUNET_BIO_write_string (wh, (pc->namespace == NULL) ? NULL : 
pc->namespace->name)) )
-   {
-     (void) GNUNET_BIO_write_close (wh);
-     GNUNET_FS_remove_sync_file_ (pc->h, "publish", pc->serialization);
-     GNUNET_free (pc->serialization);
-     pc->serialization = NULL;
-     return;
-   }
-#endif
-  /* FIXME: do search-specific serialization here! */
+       GNUNET_BIO_write_int32 (wh, sc->anonymity)) )
+    goto cleanup;          
+  GNUNET_free (uris);
+  uris = NULL;
+  scc = sc->child_head;
+  while (NULL != scc)
+    {
+      if (scc->serialization == NULL)
+       break;
+      if (GNUNET_OK !=
+         GNUNET_BIO_write_string (wh, scc->serialization))
+       goto cleanup;
+      scc = scc->next;
+    }
+  GNUNET_BIO_write_string (wh, NULL);
   if (GNUNET_OK !=
       GNUNET_BIO_write_close (wh))
     {
-      GNUNET_FS_remove_sync_file_ (sc->h, "search", sc->serialization);
-      GNUNET_free (sc->serialization);
-      sc->serialization = NULL;
-      return;     
-    }  
+      wh = NULL;
+      goto cleanup;
+    }
+  return;
+ cleanup:
+  if (wh != NULL)
+    (void) GNUNET_BIO_write_close (wh);
+  GNUNET_free_non_null (uris);
+  GNUNET_FS_remove_sync_file_ (sc->h, "search", sc->serialization);
+  GNUNET_free (sc->serialization);
+  sc->serialization = NULL;
 }
 
 
@@ -1332,8 +1389,6 @@
 }
 
 
-
-
 /**
  * Function called with a filename of serialized unindexing operation
  * to deserialize.
@@ -1610,6 +1665,41 @@
 
 
 /**
+ * Free memory allocated by the search context and its children
+ *
+ * @param sc search context to free
+ */
+static void
+free_search_context (struct GNUNET_FS_SearchContext *sc)
+{
+  struct GNUNET_FS_SearchContext *scc;
+
+  while (NULL != (scc = sc->child_head))
+    {
+      GNUNET_CONTAINER_DLL_remove (sc->child_head,
+                                  sc->child_tail,
+                                  scc);      
+      free_search_context (scc);
+    }
+  GNUNET_free_non_null (sc->emsg);
+  if (sc->serialization != NULL)
+    GNUNET_FS_remove_sync_file_ (sc->h, "search", sc->serialization);
+  /* FIXME: remove 'pbuf' directory with search results as well! */
+  GNUNET_free_non_null (sc->serialization);
+  if (sc->uri != NULL)
+    GNUNET_FS_uri_destroy (sc->uri);
+  if (sc->master_result_map != NULL)
+    {
+      GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
+                                            &free_result,
+                                            sc);
+      GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
+    }
+  GNUNET_free (sc);
+}
+
+
+/**
  * Deserialize a search. 
  *
  * @param h overall context
@@ -1624,6 +1714,8 @@
                    const char *serialization)
 {
   struct GNUNET_FS_SearchContext *sc;
+  struct GNUNET_FS_SearchContext *scc;
+  struct GNUNET_BIO_ReadHandle *rhc;
   char pbuf[32];
   struct GNUNET_FS_ProgressInfo pi;
   char *emsg;
@@ -1634,7 +1726,6 @@
   char in_pause;
 
   uris = NULL;
-  child_ser = NULL;
   emsg = NULL;
   sc = GNUNET_malloc (sizeof (struct GNUNET_FS_SearchContext));
   sc->parent = parent;
@@ -1648,8 +1739,6 @@
        (GNUNET_OK !=
        GNUNET_BIO_read_int64 (rh, &sc->start_time.value)) ||
        (GNUNET_OK !=
-       GNUNET_BIO_read_string (rh, "child-serialization", &child_ser, 32)) ||
-       (GNUNET_OK !=
        GNUNET_BIO_read_string (rh, "search-emsg", &sc->emsg, 10*1024)) ||
        (GNUNET_OK !=
        GNUNET_BIO_read_int32 (rh, &options)) ||
@@ -1679,9 +1768,33 @@
          GNUNET_FS_search_start_searching_ (sc))
        goto cleanup;
     }
-  if (child_ser != NULL)
+  while (1)
     {
-      /* FIXME: deserialize child-search! */
+      if ( (GNUNET_OK !=
+           GNUNET_BIO_read_string (rh, "child-serialization", &child_ser, 32)))
+       goto cleanup;
+      if (child_ser == NULL)
+       break;    
+      rhc = get_read_handle (h, "search-children", child_ser);
+      if (rhc != NULL)
+       {
+         scc = deserialize_search (h, rhc, sc, child_ser);
+         if (scc != NULL)          
+           GNUNET_CONTAINER_DLL_insert (sc->child_head,
+                                        sc->child_tail,
+                                        scc);      
+         emsg = NULL;
+         if (GNUNET_OK !=
+             GNUNET_BIO_read_close (rhc, &emsg))
+           {
+             GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                         _("Failed to resume sub-search `%s': %s\n"),
+                         child_ser,
+                         emsg);
+             GNUNET_free (emsg);
+           }
+       }    
+      GNUNET_free (child_ser);  
     }
   if (parent != NULL)
     GNUNET_CONTAINER_DLL_insert (parent->child_head,
@@ -1692,28 +1805,25 @@
   pi.value.search.specifics.resume.is_paused = ('\0' == in_pause) ? GNUNET_NO 
: GNUNET_YES;
   sc->client_info = GNUNET_FS_search_make_status_ (&pi,
                                                   sc);
+  scc = sc->child_head;
+  while (NULL != scc)
+    {
+      pi.status = GNUNET_FS_STATUS_SEARCH_RESUME;
+      pi.value.search.specifics.resume.message = scc->emsg;
+      pi.value.search.specifics.resume.is_paused = ('\0' == in_pause) ? 
GNUNET_NO : GNUNET_YES;
+      scc->client_info = GNUNET_FS_search_make_status_ (&pi,
+                                                       scc);
+
+      scc = scc->next;
+    }
   GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
                                         &signal_result_resume,
                                         sc);
+  GNUNET_free (uris);
   return sc;
  cleanup:
-  GNUNET_free_non_null (child_ser);
-  GNUNET_free_non_null (sc->emsg);
   GNUNET_free_non_null (emsg);
-  if (sc->serialization != NULL)
-    GNUNET_FS_remove_sync_file_ (h, "search", sc->serialization);
-  /* FIXME: remove 'pbuf' directory with search results as well! */
-  GNUNET_free_non_null (sc->serialization);
-  if (sc->uri != NULL)
-    GNUNET_FS_uri_destroy (sc->uri);
-  if (sc->master_result_map != NULL)
-    {
-      GNUNET_CONTAINER_multihashmap_iterate (sc->master_result_map,
-                                            &free_result,
-                                            sc);
-      GNUNET_CONTAINER_multihashmap_destroy (sc->master_result_map);
-    }
-  GNUNET_free (sc);
+  free_search_context (sc);
   GNUNET_free_non_null (uris);
   return NULL;
 }

Modified: gnunet/src/fs/fs.h
===================================================================
--- gnunet/src/fs/fs.h  2010-05-03 09:58:52 UTC (rev 11160)
+++ gnunet/src/fs/fs.h  2010-05-03 13:34:45 UTC (rev 11161)
@@ -880,10 +880,12 @@
  * publishing structs should already call "sync" internally,
  * so this function is likely not useful for clients.
  * 
- * @param sc the struct to sync
+ * @param key key for the search result
+ * @param sr the struct to sync
  */
 void
-GNUNET_FS_search_result_sync_ (struct SearchResult *sr);
+GNUNET_FS_search_result_sync_ (const GNUNET_HashCode *key,
+                              struct SearchResult *sr);
 
 
 /**





reply via email to

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