diff options
-rw-r--r-- | src/peerstore/Makefile.am | 2 | ||||
-rw-r--r-- | src/peerstore/gnunet-peerstore.c | 40 | ||||
-rw-r--r-- | src/peerstore/gnunet-service-peerstore.c | 15 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api.c | 67 | ||||
-rw-r--r-- | src/peerstore/test_peerstore_api_data.conf | 12 |
5 files changed, 40 insertions, 96 deletions
diff --git a/src/peerstore/Makefile.am b/src/peerstore/Makefile.am index 40072836c..4c4c84ed1 100644 --- a/src/peerstore/Makefile.am +++ b/src/peerstore/Makefile.am | |||
@@ -72,5 +72,7 @@ endif | |||
72 | test_peerstore_api_SOURCES = \ | 72 | test_peerstore_api_SOURCES = \ |
73 | test_peerstore_api.c | 73 | test_peerstore_api.c |
74 | test_peerstore_api_LDADD = \ | 74 | test_peerstore_api_LDADD = \ |
75 | $(top_builddir)/src/peerstore/libgnunetpeerstore.la \ | ||
76 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
75 | $(top_builddir)/src/util/libgnunetutil.la | 77 | $(top_builddir)/src/util/libgnunetutil.la |
76 | 78 | ||
diff --git a/src/peerstore/gnunet-peerstore.c b/src/peerstore/gnunet-peerstore.c index 9b26cf36c..ec2af0a4f 100644 --- a/src/peerstore/gnunet-peerstore.c +++ b/src/peerstore/gnunet-peerstore.c | |||
@@ -29,11 +29,6 @@ | |||
29 | 29 | ||
30 | static int ret; | 30 | static int ret; |
31 | 31 | ||
32 | /** | ||
33 | * option '-t' | ||
34 | */ | ||
35 | static int test; | ||
36 | |||
37 | /* | 32 | /* |
38 | * Handle to PEERSTORE service | 33 | * Handle to PEERSTORE service |
39 | */ | 34 | */ |
@@ -56,17 +51,6 @@ shutdown_task (void *cls, | |||
56 | } | 51 | } |
57 | } | 52 | } |
58 | 53 | ||
59 | void test_cont(void *cls, const char *emsg) | ||
60 | { | ||
61 | char *req = cls; | ||
62 | |||
63 | printf("Received a response to request: %s\n", req); | ||
64 | if(NULL != emsg) | ||
65 | { | ||
66 | printf("Response: %s\n", emsg); | ||
67 | } | ||
68 | } | ||
69 | |||
70 | /** | 54 | /** |
71 | * Main function that will be run by the scheduler. | 55 | * Main function that will be run by the scheduler. |
72 | * | 56 | * |
@@ -88,27 +72,6 @@ run (void *cls, | |||
88 | NULL); | 72 | NULL); |
89 | peerstore_handle = GNUNET_PEERSTORE_connect(cfg); | 73 | peerstore_handle = GNUNET_PEERSTORE_connect(cfg); |
90 | GNUNET_assert(NULL != peerstore_handle); | 74 | GNUNET_assert(NULL != peerstore_handle); |
91 | if(GNUNET_YES == test) | ||
92 | { | ||
93 | struct GNUNET_PeerIdentity pid; | ||
94 | memset (&pid, 32, sizeof (pid)); | ||
95 | GNUNET_PEERSTORE_store(peerstore_handle, | ||
96 | &pid, | ||
97 | "subsub", | ||
98 | "value", | ||
99 | 5, | ||
100 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
101 | &test_cont, | ||
102 | "Req1"); | ||
103 | GNUNET_PEERSTORE_store(peerstore_handle, | ||
104 | &pid, | ||
105 | "subsub", | ||
106 | "value", | ||
107 | 5, | ||
108 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
109 | &test_cont, | ||
110 | "Req2"); | ||
111 | } | ||
112 | 75 | ||
113 | ret = 0; | 76 | ret = 0; |
114 | } | 77 | } |
@@ -124,9 +87,6 @@ int | |||
124 | main (int argc, char *const *argv) | 87 | main (int argc, char *const *argv) |
125 | { | 88 | { |
126 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 89 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
127 | {'t', "test", NULL, | ||
128 | gettext_noop("TESTING"), | ||
129 | 0, &GNUNET_GETOPT_set_one, &test}, | ||
130 | GNUNET_GETOPT_OPTION_END | 90 | GNUNET_GETOPT_OPTION_END |
131 | }; | 91 | }; |
132 | return (GNUNET_OK == | 92 | return (GNUNET_OK == |
diff --git a/src/peerstore/gnunet-service-peerstore.c b/src/peerstore/gnunet-service-peerstore.c index 35eee01b1..d3f87c4bc 100644 --- a/src/peerstore/gnunet-service-peerstore.c +++ b/src/peerstore/gnunet-service-peerstore.c | |||
@@ -100,21 +100,6 @@ void handle_store (void *cls, | |||
100 | sub_system, | 100 | sub_system, |
101 | GNUNET_i2s (&sreqm->peer)); | 101 | GNUNET_i2s (&sreqm->peer)); |
102 | //TODO: do the actual storage | 102 | //TODO: do the actual storage |
103 | //create a fake response for testing | ||
104 | char *response = "This is a response"; | ||
105 | uint16_t resp_size = strlen(response); | ||
106 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
107 | msg_size = sizeof(struct StoreResponseMessage) + resp_size; | ||
108 | sresm = malloc(msg_size); | ||
109 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sending a response to client of size: %u, response size: %u\n", msg_size, resp_size); | ||
110 | sresm->header.type = htons(GNUNET_MESSAGE_TYPE_PEERSTORE_STORE_RESULT); | ||
111 | sresm->header.size = htons(msg_size); | ||
112 | sresm->success = htons(GNUNET_NO); | ||
113 | sresm->emsg_size = htons(resp_size); | ||
114 | char *msg_ptr = (char *)&sresm[1]; | ||
115 | memcpy(msg_ptr, response, resp_size); | ||
116 | GNUNET_SERVER_transmit_context_append_message(tc, (struct GNUNET_MessageHeader *)sresm); | ||
117 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | ||
118 | } | 103 | } |
119 | 104 | ||
120 | /** | 105 | /** |
diff --git a/src/peerstore/test_peerstore_api.c b/src/peerstore/test_peerstore_api.c index 8bb973f74..51251d72a 100644 --- a/src/peerstore/test_peerstore_api.c +++ b/src/peerstore/test_peerstore_api.c | |||
@@ -23,62 +23,47 @@ | |||
23 | */ | 23 | */ |
24 | #include "platform.h" | 24 | #include "platform.h" |
25 | #include "gnunet_util_lib.h" | 25 | #include "gnunet_util_lib.h" |
26 | #include "gnunet_testing_lib.h" | ||
26 | #include "gnunet_peerstore_service.h" | 27 | #include "gnunet_peerstore_service.h" |
27 | 28 | ||
28 | |||
29 | static int ok = 1; | 29 | static int ok = 1; |
30 | 30 | ||
31 | struct GNUNET_PEERSTORE_Handle *h; | ||
31 | 32 | ||
32 | static void | 33 | static void |
33 | run (void *cls, | 34 | run (void *cls, |
34 | char *const *args, | 35 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
35 | const char *cfgfile, | 36 | struct GNUNET_TESTING_Peer *peer) |
36 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
37 | { | ||
38 | ok = 0; | ||
39 | } | ||
40 | |||
41 | |||
42 | static int | ||
43 | check () | ||
44 | { | 37 | { |
45 | char *const argv[] = { "test-peerstore-api", NULL }; | 38 | struct GNUNET_PeerIdentity pid; |
46 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 39 | char *val = "peerstore-test-value"; |
47 | GNUNET_GETOPT_OPTION_END | 40 | size_t val_size = strlen(val); |
48 | }; | ||
49 | struct GNUNET_OS_Process *proc; | ||
50 | char *path = GNUNET_OS_get_libexec_binary_path ( "gnunet-service-peerstore"); | ||
51 | if (NULL == path) | ||
52 | { | ||
53 | fprintf (stderr, "Service executable not found `%s'\n", "gnunet-service-peerstore"); | ||
54 | return -1; | ||
55 | } | ||
56 | 41 | ||
57 | proc = GNUNET_OS_start_process (GNUNET_NO, GNUNET_OS_INHERIT_STD_ALL, NULL, | 42 | ok = 0; |
58 | NULL, NULL, path, "gnunet-service-peerstore", NULL); | 43 | memset (&pid, 32, sizeof (pid)); |
44 | h = GNUNET_PEERSTORE_connect(cfg); | ||
45 | GNUNET_assert(NULL != h); | ||
46 | GNUNET_PEERSTORE_store(h, | ||
47 | &pid, | ||
48 | "peerstore-test", | ||
49 | val, | ||
50 | val_size, | ||
51 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
52 | NULL, | ||
53 | NULL); | ||
54 | GNUNET_PEERSTORE_disconnect(h); | ||
59 | 55 | ||
60 | GNUNET_free (path); | ||
61 | GNUNET_assert (NULL != proc); | ||
62 | GNUNET_PROGRAM_run (1, argv, "test-peerstore-api", "nohelp", | ||
63 | options, &run, &ok); | ||
64 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | ||
65 | { | ||
66 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
67 | ok = 1; | ||
68 | } | ||
69 | GNUNET_OS_process_wait (proc); | ||
70 | GNUNET_OS_process_destroy (proc); | ||
71 | return ok; | ||
72 | } | 56 | } |
73 | 57 | ||
74 | |||
75 | int | 58 | int |
76 | main (int argc, char *argv[]) | 59 | main (int argc, char *argv[]) |
77 | { | 60 | { |
78 | GNUNET_log_setup ("test_statistics_api", | 61 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerstore", |
79 | "WARNING", | 62 | "peerstore", |
80 | NULL); | 63 | "test_peerstore_api_data.conf", |
81 | return check (); | 64 | &run, NULL)) |
65 | return 1; | ||
66 | return ok; | ||
82 | } | 67 | } |
83 | 68 | ||
84 | /* end of test_peerstore_api.c */ | 69 | /* end of test_peerstore_api.c */ |
diff --git a/src/peerstore/test_peerstore_api_data.conf b/src/peerstore/test_peerstore_api_data.conf new file mode 100644 index 000000000..376e9861c --- /dev/null +++ b/src/peerstore/test_peerstore_api_data.conf | |||
@@ -0,0 +1,12 @@ | |||
1 | [PATHS] | ||
2 | GNUNET_TEST_HOME = /tmp/test-gnunet-peerstore | ||
3 | |||
4 | [peerstore] | ||
5 | AUTOSTART = YES | ||
6 | BINARY = gnunet-service-peerstore | ||
7 | UNIXPATH = /tmp/gnunet-service-peerstore.sock | ||
8 | HOME = $SERVICEHOME | ||
9 | DATABASE = sqlite | ||
10 | |||
11 | [peerstore-sqlite] | ||
12 | FILENAME = $GNUNET_TEST_HOME/gnunet-peerstore-sqlite.db | ||