gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33243 - gnunet/src/peerstore


From: gnunet
Subject: [GNUnet-SVN] r33243 - gnunet/src/peerstore
Date: Mon, 12 May 2014 13:41:33 +0200

Author: otarabai
Date: 2014-05-12 13:41:33 +0200 (Mon, 12 May 2014)
New Revision: 33243

Added:
   gnunet/src/peerstore/test_peerstore_api_data.conf
Modified:
   gnunet/src/peerstore/Makefile.am
   gnunet/src/peerstore/gnunet-peerstore.c
   gnunet/src/peerstore/gnunet-service-peerstore.c
   gnunet/src/peerstore/test_peerstore_api.c
Log:
PEERSTORE cleanup and api test


Modified: gnunet/src/peerstore/Makefile.am
===================================================================
--- gnunet/src/peerstore/Makefile.am    2014-05-12 11:05:40 UTC (rev 33242)
+++ gnunet/src/peerstore/Makefile.am    2014-05-12 11:41:33 UTC (rev 33243)
@@ -72,5 +72,7 @@
 test_peerstore_api_SOURCES = \
  test_peerstore_api.c
 test_peerstore_api_LDADD = \
+  $(top_builddir)/src/peerstore/libgnunetpeerstore.la  \
+  $(top_builddir)/src/testing/libgnunettesting.la \
   $(top_builddir)/src/util/libgnunetutil.la  
 

Modified: gnunet/src/peerstore/gnunet-peerstore.c
===================================================================
--- gnunet/src/peerstore/gnunet-peerstore.c     2014-05-12 11:05:40 UTC (rev 
33242)
+++ gnunet/src/peerstore/gnunet-peerstore.c     2014-05-12 11:41:33 UTC (rev 
33243)
@@ -29,11 +29,6 @@
 
 static int ret;
 
-/**
- * option '-t'
- */
-static int test;
-
 /*
  * Handle to PEERSTORE service
  */
@@ -56,17 +51,6 @@
   }
 }
 
-void test_cont(void *cls, const char *emsg)
-{
-  char *req = cls;
-
-  printf("Received a response to request: %s\n", req);
-  if(NULL != emsg)
-  {
-    printf("Response: %s\n", emsg);
-  }
-}
-
 /**
  * Main function that will be run by the scheduler.
  *
@@ -88,27 +72,6 @@
                                   NULL);
   peerstore_handle = GNUNET_PEERSTORE_connect(cfg);
   GNUNET_assert(NULL != peerstore_handle);
-  if(GNUNET_YES == test)
-  {
-    struct GNUNET_PeerIdentity pid;
-    memset (&pid, 32, sizeof (pid));
-    GNUNET_PEERSTORE_store(peerstore_handle,
-        &pid,
-        "subsub",
-        "value",
-        5,
-        GNUNET_TIME_UNIT_FOREVER_REL,
-        &test_cont,
-        "Req1");
-    GNUNET_PEERSTORE_store(peerstore_handle,
-            &pid,
-            "subsub",
-            "value",
-            5,
-            GNUNET_TIME_UNIT_FOREVER_REL,
-            &test_cont,
-            "Req2");
-  }
 
   ret = 0;
 }
@@ -124,9 +87,6 @@
 main (int argc, char *const *argv)
 {
   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
-    {'t', "test", NULL,
-        gettext_noop("TESTING"),
-    0, &GNUNET_GETOPT_set_one, &test},
     GNUNET_GETOPT_OPTION_END
   };
   return (GNUNET_OK ==

Modified: gnunet/src/peerstore/gnunet-service-peerstore.c
===================================================================
--- gnunet/src/peerstore/gnunet-service-peerstore.c     2014-05-12 11:05:40 UTC 
(rev 33242)
+++ gnunet/src/peerstore/gnunet-service-peerstore.c     2014-05-12 11:41:33 UTC 
(rev 33243)
@@ -100,21 +100,6 @@
       sub_system,
       GNUNET_i2s (&sreqm->peer));
   //TODO: do the actual storage
-  //create a fake response for testing
-  char *response = "This is a response";
-  uint16_t resp_size = strlen(response);
-  tc = GNUNET_SERVER_transmit_context_create (client);
-  msg_size = sizeof(struct StoreResponseMessage) + resp_size;
-  sresm = malloc(msg_size);
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending a response to client of size: 
%u, response size: %u\n", msg_size, resp_size);
-  sresm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT);
-  sresm->header.size = htons(msg_size);
-  sresm->success = htons(GNUNET_NO);
-  sresm->emsg_size = htons(resp_size);
-  char *msg_ptr = (char *)&sresm[1];
-  memcpy(msg_ptr, response, resp_size);
-  GNUNET_SERVER_transmit_context_append_message(tc, (struct 
GNUNET_MessageHeader *)sresm);
-  GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
 }
 
 /**

Modified: gnunet/src/peerstore/test_peerstore_api.c
===================================================================
--- gnunet/src/peerstore/test_peerstore_api.c   2014-05-12 11:05:40 UTC (rev 
33242)
+++ gnunet/src/peerstore/test_peerstore_api.c   2014-05-12 11:41:33 UTC (rev 
33243)
@@ -23,62 +23,47 @@
  */
 #include "platform.h"
 #include "gnunet_util_lib.h"
+#include "gnunet_testing_lib.h"
 #include "gnunet_peerstore_service.h"
 
-
 static int ok = 1;
 
+struct GNUNET_PEERSTORE_Handle *h;
 
 static void
 run (void *cls,
-     char *const *args,
-     const char *cfgfile,
-     const struct GNUNET_CONFIGURATION_Handle *cfg)
+    const struct GNUNET_CONFIGURATION_Handle *cfg,
+    struct GNUNET_TESTING_Peer *peer)
 {
+  struct GNUNET_PeerIdentity pid;
+  char *val = "peerstore-test-value";
+  size_t val_size = strlen(val);
+
   ok = 0;
-}
+  memset (&pid, 32, sizeof (pid));
+  h = GNUNET_PEERSTORE_connect(cfg);
+  GNUNET_assert(NULL != h);
+  GNUNET_PEERSTORE_store(h,
+      &pid,
+      "peerstore-test",
+      val,
+      val_size,
+      GNUNET_TIME_UNIT_FOREVER_REL,
+      NULL,
+      NULL);
+  GNUNET_PEERSTORE_disconnect(h);
 
-
-static int
-check ()
-{
-  char *const argv[] = { "test-peerstore-api", NULL };
-  struct GNUNET_GETOPT_CommandLineOption options[] = {
-    GNUNET_GETOPT_OPTION_END
-  };
-  struct GNUNET_OS_Process *proc;
-  char *path = GNUNET_OS_get_libexec_binary_path ( "gnunet-service-peerstore");
-  if (NULL == path)
-  {
-               fprintf (stderr, "Service executable not found `%s'\n", 
"gnunet-service-peerstore");
-               return -1;
-  }
-
-  proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL,
-      NULL, NULL, path, "gnunet-service-peerstore", NULL);
-
-  GNUNET_free (path);
-  GNUNET_assert (NULL != proc);
-  GNUNET_PROGRAM_run (1, argv, "test-peerstore-api", "nohelp",
-                      options, &run, &ok);
-  if (0 != GNUNET_OS_process_kill (proc, SIGTERM))
-    {
-      GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
-      ok = 1;
-    }
-  GNUNET_OS_process_wait (proc);
-  GNUNET_OS_process_destroy (proc);
-  return ok;
 }
 
-
 int
 main (int argc, char *argv[])
 {
-  GNUNET_log_setup ("test_statistics_api", 
-                   "WARNING",
-                   NULL);
-  return check ();
+  if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore",
+                 "peerstore",
+                 "test_peerstore_api_data.conf",
+                 &run, NULL))
+    return 1;
+  return ok;
 }
 
 /* end of test_peerstore_api.c */

Added: gnunet/src/peerstore/test_peerstore_api_data.conf
===================================================================
--- gnunet/src/peerstore/test_peerstore_api_data.conf                           
(rev 0)
+++ gnunet/src/peerstore/test_peerstore_api_data.conf   2014-05-12 11:41:33 UTC 
(rev 33243)
@@ -0,0 +1,12 @@
+[PATHS]
+GNUNET_TEST_HOME = /tmp/test-gnunet-peerstore
+
+[peerstore]
+AUTOSTART = YES
+BINARY = gnunet-service-peerstore
+UNIXPATH = /tmp/gnunet-service-peerstore.sock
+HOME = $SERVICEHOME
+DATABASE = sqlite
+
+[peerstore-sqlite]
+FILENAME = $GNUNET_TEST_HOME/gnunet-peerstore-sqlite.db




reply via email to

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