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;
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;
56 memset (&p1.hashPubKey, 3, sizeof (GNUNET_HashCode));
57 memset (&p2.hashPubKey, 4, sizeof (GNUNET_HashCode));
58 memset (&p3.hashPubKey, 5, sizeof (GNUNET_HashCode));
59 memset (&p4.hashPubKey, 6, sizeof (GNUNET_HashCode));
61 memset (&k1, 0, sizeof (GNUNET_HashCode));
62 memset (&k2, 1, sizeof (GNUNET_HashCode));
63 memset(&trial_info, 0, sizeof(struct GNUNET_DHTLOG_TrialInfo));
64 trial_info.other_identifier = 777;
65 trial_info.num_nodes = i;
66 trial_info.topology = 5;
67 trial_info.blacklist_topology = 4;
68 trial_info.connect_topology = 3;
69 trial_info.connect_topology_option = 2;
70 trial_info.connect_topology_option_modifier = .75;
71 trial_info.topology_percentage = .25;
72 trial_info.topology_probability = .5;
75 trial_info.concurrent = 5;
76 trial_info.settle_time = 1;
77 trial_info.num_rounds = 12;
78 trial_info.malicious_getters = 0;
79 trial_info.malicious_putters = 0;
80 trial_info.malicious_droppers = 0;
81 trial_info.malicious_get_frequency = 1;
82 trial_info.malicious_put_frequency = 0;
83 trial_info.stop_closest = 1;
84 trial_info.stop_found = 0;
85 trial_info.strict_kademlia = 1;
86 trial_info.message = GNUNET_strdup("TEST INSERT_TRIAL");
88 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, &k2,
157 api->insert_route (&sqlrouteuid, sqlqueryuid, 4, 7, DHTLOG_ROUTE, &p3, &k2,
161 fprintf(stderr, "Insert route succeeded!\n");
164 ret = api->insert_stat(&p1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17);
166 ret = api->insert_stat(&p2, 12, 23, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27);
169 fprintf(stderr, "Insert stat succeeded!\n");
171 ret = api->update_trial (787);
174 fprintf(stderr, "Update trial succeeded!\n");
176 ret = api->add_generic_stat (&p2, "nonsense", "section", 77765);
179 fprintf(stderr, "Insert generic stat succeeded!\n");
181 ret = api->insert_round(401, 507);
184 fprintf(stderr, "Insert round succeeded!\n");
195 const struct GNUNET_CONFIGURATION_Handle *cfg)
197 struct GNUNET_DHTLOG_Handle *api;
199 api = GNUNET_DHTLOG_connect (cfg);
208 GNUNET_DHTLOG_disconnect(api);
215 char *const argv[] = { "test-dhtlog-api",
217 "test_dhtlog_data.conf",
223 struct GNUNET_GETOPT_CommandLineOption options[] = {
224 GNUNET_GETOPT_OPTION_END
226 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
227 argv, "test-dhtlog-api", "nohelp",
228 options, &run, NULL);
230 fprintf (stderr, "Test failed with error code: %d\n", ok);
236 main (int argc, char *argv[])
240 GNUNET_log_setup ("test-datacache-api",
252 /* end of test_dhtlog.c */