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_NO
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;
46 struct GNUNET_DHTLOG_TrialInfo trial_info;
51 unsigned long long sqlqueryuid;
52 unsigned long long sqlrouteuid = 0;
53 unsigned long long nodeuid = 0;
54 unsigned long long internaluid = 1010223344LL;
55 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));
62 memset (&k1, 0, sizeof (GNUNET_HashCode));
63 memset (&k2, 1, sizeof (GNUNET_HashCode));
64 memset (&trial_info, 0, sizeof (struct GNUNET_DHTLOG_TrialInfo));
65 trial_info.other_identifier = 777;
66 trial_info.num_nodes = i;
67 trial_info.topology = 5;
68 trial_info.blacklist_topology = 4;
69 trial_info.connect_topology = 3;
70 trial_info.connect_topology_option = 2;
71 trial_info.connect_topology_option_modifier = .75;
72 trial_info.topology_percentage = .25;
73 trial_info.topology_probability = .5;
76 trial_info.concurrent = 5;
77 trial_info.settle_time = 1;
78 trial_info.num_rounds = 12;
79 trial_info.malicious_getters = 0;
80 trial_info.malicious_putters = 0;
81 trial_info.malicious_droppers = 0;
82 trial_info.malicious_get_frequency = 1;
83 trial_info.malicious_put_frequency = 0;
84 trial_info.stop_closest = 1;
85 trial_info.stop_found = 0;
86 trial_info.strict_kademlia = 1;
87 trial_info.message = GNUNET_strdup ("TEST INSERT_TRIAL");
88 ret = api->insert_trial (&trial_info);
89 GNUNET_free (trial_info.message);
92 fprintf (stderr, "Insert trial succeeded!\n");
94 ret = api->insert_topology (500);
97 fprintf (stderr, "Insert topology succeeded!\n");
99 ret = api->insert_node (&nodeuid, &p1);
101 ret = api->insert_node (&nodeuid, &p2);
103 ret = api->insert_node (&nodeuid, &p3);
105 ret = api->insert_node (&nodeuid, &p4);
108 fprintf (stderr, "Insert node succeeded!\n");
110 ret = api->set_malicious (&p1);
113 fprintf (stderr, "Set malicious succeeded!\n");
115 ret = api->insert_topology (0);
118 fprintf (stderr, "Insert topology succeeded!\n");
120 ret = api->insert_extended_topology (&p1, &p2);
122 ret = api->insert_extended_topology (&p3, &p4);
125 fprintf (stderr, "Insert extended topology succeeded!\n");
127 ret = api->update_topology (101);
130 fprintf (stderr, "Update topology succeeded!\n");
132 ret = api->insert_dhtkey (&dhtkeyuid, &k1);
134 ret = api->insert_dhtkey (&dhtkeyuid, &k2);
137 fprintf (stderr, "Insert dhtkey succeeded!\n");
139 ret = api->insert_query (&sqlqueryuid, internaluid, 2, 4, 0, &p2, &k1);
142 fprintf (stderr, "Insert query succeeded!\n");
145 api->insert_route (&sqlrouteuid, sqlqueryuid, 1, 1, DHTLOG_GET, &p1, &k2,
149 api->insert_route (&sqlrouteuid, sqlqueryuid, 2, 0, DHTLOG_PUT, &p3, &k1,
153 api->insert_route (&sqlrouteuid, sqlqueryuid, 3, 1, DHTLOG_ROUTE, &p3,
157 api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3,
161 fprintf (stderr, "Insert route succeeded!\n");
165 api->insert_stat (&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
169 api->insert_stat (&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
173 fprintf (stderr, "Insert stat succeeded!\n");
175 ret = api->update_trial (787);
178 fprintf (stderr, "Update trial succeeded!\n");
180 ret = api->add_generic_stat (&p2, "nonsense", "section", 77765);
183 fprintf (stderr, "Insert generic stat succeeded!\n");
185 ret = api->insert_round (401, 507);
187 ret = api->insert_round_details (402, 507, 1123, 985);
190 fprintf (stderr, "Insert round succeeded!\n");
198 run (void *cls, char *const *args, const char *cfgfile,
199 const struct GNUNET_CONFIGURATION_Handle *cfg)
201 struct GNUNET_DHTLOG_Handle *api;
204 api = GNUNET_DHTLOG_connect (cfg);
213 GNUNET_DHTLOG_disconnect (api);
220 char *const argv[] = { "test-dhtlog-api",
222 "test_dhtlog_data.conf",
228 struct GNUNET_GETOPT_CommandLineOption options[] = {
229 GNUNET_GETOPT_OPTION_END
231 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
232 "test-dhtlog-api", "nohelp", options, &run, NULL);
234 fprintf (stderr, "Test failed with error code: %d\n", ok);
240 main (int argc, char *argv[])
244 GNUNET_log_setup ("test-datacache-api",
256 /* end of test_dhtlog.c */