aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-07-21 08:11:00 +0000
committerNathan S. Evans <evans@in.tum.de>2010-07-21 08:11:00 +0000
commit3eee645835d7ae3f2fbe838cd2af55836b3997ae (patch)
treedf6c1a4ab18e35f4c2890f4d1769380e4a5aa3c3 /src
parent2ce3fe43765aa23863954bf9667dc896c7205531 (diff)
downloadgnunet-3eee645835d7ae3f2fbe838cd2af55836b3997ae.tar.gz
gnunet-3eee645835d7ae3f2fbe838cd2af55836b3997ae.zip
missing file
Diffstat (limited to 'src')
-rw-r--r--src/dht/test_dhtlog.c195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/dht/test_dhtlog.c b/src/dht/test_dhtlog.c
new file mode 100644
index 000000000..39404983c
--- /dev/null
+++ b/src/dht/test_dhtlog.c
@@ -0,0 +1,195 @@
1/*
2 This file is part of GNUnet.
3 (C) 2006, 2009 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/*
21 * @file src/dht/test_dhtlog.c
22 * @brief Test of the dhtlog service
23 * @author Nathan Evans
24 */
25
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_protocols.h"
29#include "dhtlog.h"
30
31#define VERBOSE GNUNET_YES
32
33static int ok;
34
35/**
36 * Actual test of the service operations
37 */
38static int
39test (struct GNUNET_DHTLOG_Handle * api)
40{
41 struct GNUNET_PeerIdentity p1;
42 struct GNUNET_PeerIdentity p2;
43 struct GNUNET_PeerIdentity p3;
44 struct GNUNET_PeerIdentity p4;
45
46 GNUNET_HashCode k1;
47 GNUNET_HashCode k2;
48
49 int ret;
50 unsigned int i = 42;
51 unsigned long long trialuid;
52 unsigned long long sqlqueryuid;
53 unsigned long long sqlrouteuid = 0;
54 unsigned long long nodeuid = 0;
55 unsigned long long internaluid = 1010223344LL;
56 unsigned long long dhtkeyuid = 0;
57 memset (&p1.hashPubKey, 3, sizeof (GNUNET_HashCode));
58 memset (&p2.hashPubKey, 4, sizeof (GNUNET_HashCode));
59 memset (&p3.hashPubKey, 5, sizeof (GNUNET_HashCode));
60 memset (&p4.hashPubKey, 6, sizeof (GNUNET_HashCode));
61
62 memset (&k1, 0, sizeof (GNUNET_HashCode));
63 memset (&k2, 1, sizeof (GNUNET_HashCode));
64
65 ret =
66 api->insert_trial (&trialuid, i, 5, 4, 3, 2,
67 .75, .25, .5, 42, 14,
68 5, 1, 12, 0, 0, 0,
69 "TEST INSERT TRIAL");
70
71 if (ret != GNUNET_OK)
72 {
73 return ret;
74 }
75
76 fprintf (stderr, "Trial uid is %llu\n", trialuid);
77
78 ret = api->insert_node (&nodeuid, &p1);
79 ret = api->insert_node (&nodeuid, &p2);
80 ret = api->insert_node (&nodeuid, &p3);
81 ret = api->insert_node (&nodeuid, &p4);
82
83 if (ret != GNUNET_OK)
84 {
85 fprintf (stderr, "received ret value of %d\n", ret);
86 return ret;
87 }
88
89 ret = api->insert_dhtkey (&dhtkeyuid, &k1);
90 ret = api->insert_dhtkey (&dhtkeyuid, &k2);
91
92 if (ret != GNUNET_OK)
93 {
94 fprintf (stderr, "received ret value of %d\n", ret);
95 return ret;
96 }
97
98 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
99
100 fprintf (stderr, "Sql uid for dht query is %llu\n", sqlqueryuid);
101
102 ret =
103 api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
104 &p4, &p3);
105 fprintf (stderr, "Sql uid for dht route is %llu\n", sqlrouteuid);
106 ret =
107 api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
108 &p4, &p2);
109 fprintf (stderr, "Sql uid for dht route is %llu\n", sqlrouteuid);
110 ret =
111 api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3, &k2,
112 &p2, NULL);
113 fprintf (stderr, "Sql uid for dht route is %llu\n", sqlrouteuid);
114 ret =
115 api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3, &k2,
116 NULL, NULL);
117 fprintf (stderr, "Sql uid for dht route is %llu, ret %d\n", sqlrouteuid, ret);
118 sleep (1);
119 fprintf (stderr, "Updating trial %llu with endtime of now\n", trialuid);
120 ret = api->update_trial (trialuid, 0, 0, 0);
121
122 if (ret != GNUNET_OK)
123 {
124 return ret;
125 }
126
127 return 0;
128}
129
130
131
132static void
133run (void *cls,
134 struct GNUNET_SCHEDULER_Handle *sched,
135 char *const *args,
136 const char *cfgfile,
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
138{
139 struct GNUNET_DHTLOG_Handle *api;
140 ok = 0;
141 api = GNUNET_DHTLOG_connect (cfg);
142
143 if (api == NULL)
144 {
145 ok = 1;
146 return;
147 }
148 ok = test(api);
149
150 GNUNET_DHTLOG_disconnect(api);
151 GNUNET_free(api);
152}
153
154
155static int
156check ()
157{
158 char *const argv[] = { "test-dhtlog-api",
159 "-c",
160 "test_dhtlog_data.conf",
161#if VERBOSE
162 "-L", "DEBUG",
163#endif
164 NULL
165 };
166 struct GNUNET_GETOPT_CommandLineOption options[] = {
167 GNUNET_GETOPT_OPTION_END
168 };
169 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
170 argv, "test-dhtlog-api", "nohelp",
171 options, &run, NULL);
172 if (ok != 0)
173 fprintf (stderr, "Test failed with error code: %d\n", ok);
174 return ok;
175}
176
177
178int
179main (int argc, char *argv[])
180{
181 int ret;
182
183 GNUNET_log_setup ("test-datacache-api",
184#if VERBOSE
185 "DEBUG",
186#else
187 "WARNING",
188#endif
189 NULL);
190 ret = check ();
191
192 return ret;
193}
194
195/* end of test_dhtlog.c */