2 This file is part of GNUnet.
3 (C) 2006, 2009 Christian Grothoff (and other contributing authors)
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.
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.
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.
21 * @file src/dht/test_dhtlog.c
22 * @brief Test of the dhtlog service
23 * @author Nathan Evans
27 #include "gnunet_util_lib.h"
28 #include "gnunet_protocols.h"
31 #define VERBOSE GNUNET_YES
35 #define CHECK(a) if (a != GNUNET_OK) return a
37 * Actual test of the service operations
40 test (struct GNUNET_DHTLOG_Handle * api)
42 struct GNUNET_PeerIdentity p1;
43 struct GNUNET_PeerIdentity p2;
44 struct GNUNET_PeerIdentity p3;
45 struct GNUNET_PeerIdentity p4;
52 unsigned long long trialuid;
53 unsigned long long sqlqueryuid;
54 unsigned long long sqlrouteuid = 0;
55 unsigned long long nodeuid = 0;
56 unsigned long long internaluid = 1010223344LL;
57 unsigned long long dhtkeyuid = 0;
58 memset (&p1.hashPubKey, 3, sizeof (GNUNET_HashCode));
59 memset (&p2.hashPubKey, 4, sizeof (GNUNET_HashCode));
60 memset (&p3.hashPubKey, 5, sizeof (GNUNET_HashCode));
61 memset (&p4.hashPubKey, 6, sizeof (GNUNET_HashCode));
63 memset (&k1, 0, sizeof (GNUNET_HashCode));
64 memset (&k2, 1, sizeof (GNUNET_HashCode));
67 api->insert_trial (&trialuid, i, 5, 4, 3, 2,
73 ret = api->insert_topology(500);
77 fprintf (stderr, "Trial uid is %llu\n", trialuid);
79 ret = api->insert_node (&nodeuid, &p1);
80 ret = api->insert_node (&nodeuid, &p2);
81 ret = api->insert_node (&nodeuid, &p3);
82 ret = api->insert_node (&nodeuid, &p4);
86 ret = api->insert_topology(0);
87 ret = api->insert_extended_topology(&p1, &p2);
88 ret = api->insert_extended_topology(&p3, &p4);
89 ret = api->update_topology(101);
91 ret = api->insert_dhtkey (&dhtkeyuid, &k1);
92 ret = api->insert_dhtkey (&dhtkeyuid, &k2);
96 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
98 fprintf (stderr, "Sql uid for dht query is %llu\n", sqlqueryuid);
101 api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
103 fprintf (stderr, "Sql uid for dht route is %llu\n", sqlrouteuid);
105 api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
107 fprintf (stderr, "Sql uid for dht route is %llu\n", sqlrouteuid);
109 api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3, &k2,
111 fprintf (stderr, "Sql uid for dht route is %llu\n", sqlrouteuid);
113 api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3, &k2,
115 fprintf (stderr, "Sql uid for dht route is %llu, ret %d\n", sqlrouteuid, ret);
117 fprintf (stderr, "Updating trial %llu with endtime of now\n", trialuid);
118 ret = api->update_trial (trialuid, 0, 0, 0);
129 struct GNUNET_SCHEDULER_Handle *sched,
132 const struct GNUNET_CONFIGURATION_Handle *cfg)
134 struct GNUNET_DHTLOG_Handle *api;
136 api = GNUNET_DHTLOG_connect (cfg);
145 GNUNET_DHTLOG_disconnect(api);
153 char *const argv[] = { "test-dhtlog-api",
155 "test_dhtlog_data.conf",
161 struct GNUNET_GETOPT_CommandLineOption options[] = {
162 GNUNET_GETOPT_OPTION_END
164 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
165 argv, "test-dhtlog-api", "nohelp",
166 options, &run, NULL);
168 fprintf (stderr, "Test failed with error code: %d\n", ok);
174 main (int argc, char *argv[])
178 GNUNET_log_setup ("test-datacache-api",
190 /* end of test_dhtlog.c */