aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-30 13:21:19 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-30 13:21:19 +0000
commitf5eaab80bfdbe04703096554f442dcbfa970b745 (patch)
tree31559f26ba20d6a2cf63b85973985841ce65ba78 /src
parentd5d4f7845deb59deeb7a7664cbd78b3c09601b59 (diff)
downloadgnunet-f5eaab80bfdbe04703096554f442dcbfa970b745.tar.gz
gnunet-f5eaab80bfdbe04703096554f442dcbfa970b745.zip
twopeer dht test, mostly for class
Diffstat (limited to 'src')
-rw-r--r--src/dht/Makefile.am14
-rw-r--r--src/dht/dht.h2
-rw-r--r--src/dht/gnunet-service-dht.c29
-rw-r--r--src/dht/test_dht_twopeer.c297
-rw-r--r--src/dht/test_dht_twopeer_data.conf77
5 files changed, 413 insertions, 6 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 1677cf465..d463d232f 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -60,17 +60,25 @@ gnunet_dht_put_LDADD = \
60 $(top_builddir)/src/util/libgnunetutil.la 60 $(top_builddir)/src/util/libgnunetutil.la
61 61
62check_PROGRAMS = \ 62check_PROGRAMS = \
63 test_dht_api 63 test_dht_api \
64 test_dht_twopeer
64 65
65TESTS = $(check_PROGRAMS) $(check_SCRIPTS) 66TESTS = test_dht_api $(check_SCRIPTS)
66 67
67test_dht_api_SOURCES = \ 68test_dht_api_SOURCES = \
68 test_dht_api.c 69 test_dht_api.c
69test_dht_api_LDADD = \ 70test_dht_api_LDADD = \
70 $(top_builddir)/src/util/libgnunetutil.la \ 71 $(top_builddir)/src/util/libgnunetutil.la \
71 $(top_builddir)/src/hello/libgnunethello.la \ 72 $(top_builddir)/src/hello/libgnunethello.la \
73 $(top_builddir)/src/dht/libgnunetdht.la
74
75test_dht_twopeer_SOURCES = \
76 test_dht_twopeer.c
77test_dht_twopeer_LDADD = \
78 $(top_builddir)/src/util/libgnunetutil.la \
79 $(top_builddir)/src/testing/libgnunettesting.la \
72 $(top_builddir)/src/dht/libgnunetdht.la 80 $(top_builddir)/src/dht/libgnunetdht.la
73 81
74EXTRA_DIST = \ 82EXTRA_DIST = \
75 test_dht_api_data.conf 83 test_dht_api_data.conf
76 84
diff --git a/src/dht/dht.h b/src/dht/dht.h
index 93ac9fa69..56a334b2a 100644
--- a/src/dht/dht.h
+++ b/src/dht/dht.h
@@ -27,7 +27,7 @@
27#ifndef DHT_H_ 27#ifndef DHT_H_
28#define DHT_H_ 28#define DHT_H_
29 29
30#define DEBUG_DHT GNUNET_NO 30#define DEBUG_DHT GNUNET_YES
31 31
32typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls, 32typedef void (*GNUNET_DHT_MessageReceivedHandler) (void *cls,
33 const struct GNUNET_MessageHeader 33 const struct GNUNET_MessageHeader
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index 8c7e66920..a2e0f4db7 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -70,6 +70,11 @@ static struct GNUNET_TRANSPORT_Handle *transport_handle;
70static struct GNUNET_PeerIdentity my_identity; 70static struct GNUNET_PeerIdentity my_identity;
71 71
72/** 72/**
73 * Short id of the peer, for printing
74 */
75static char *my_short_id;
76
77/**
73 * Our HELLO 78 * Our HELLO
74 */ 79 */
75static struct GNUNET_MessageHeader *my_hello; 80static struct GNUNET_MessageHeader *my_hello;
@@ -704,6 +709,8 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
704 GNUNET_CORE_disconnect (coreAPI); 709 GNUNET_CORE_disconnect (coreAPI);
705 if (datacache != NULL) 710 if (datacache != NULL)
706 GNUNET_DATACACHE_destroy (datacache); 711 GNUNET_DATACACHE_destroy (datacache);
712 if (my_short_id != NULL)
713 GNUNET_free(my_short_id);
707} 714}
708 715
709 716
@@ -740,6 +747,7 @@ core_init (void *cls,
740#endif 747#endif
741 /* Copy our identity so we can use it */ 748 /* Copy our identity so we can use it */
742 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity)); 749 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity));
750 my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity));
743 /* Set the server to local variable */ 751 /* Set the server to local variable */
744 coreAPI = server; 752 coreAPI = server;
745} 753}
@@ -758,6 +766,24 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
758 {NULL, 0, 0} 766 {NULL, 0, 0}
759}; 767};
760 768
769/**
770 * Method called whenever a peer connects.
771 *
772 * @param cls closure
773 * @param peer peer identity this notification is about
774 * @param latency reported latency of the connection with peer
775 * @param distance reported distance (DV) to peer
776 */
777void handle_core_connect (void *cls,
778 const struct GNUNET_PeerIdentity * peer,
779 struct GNUNET_TIME_Relative latency,
780 uint32_t distance)
781{
782#if DEBUG_DHT
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
784 "%s:%s Receives core connect message for peer %s distance %d!\n", my_short_id, "dht", GNUNET_i2s(peer), distance);
785#endif
786}
761 787
762/** 788/**
763 * Process dht requests. 789 * Process dht requests.
@@ -782,7 +808,7 @@ run (void *cls,
782 GNUNET_TIME_UNIT_FOREVER_REL, 808 GNUNET_TIME_UNIT_FOREVER_REL,
783 NULL, /* FIXME: anything we want to pass around? */ 809 NULL, /* FIXME: anything we want to pass around? */
784 &core_init, /* Call core_init once connected */ 810 &core_init, /* Call core_init once connected */
785 NULL, /* Don't care about connects */ 811 &handle_core_connect, /* Don't care about connects */
786 NULL, /* Don't care about disconnects */ 812 NULL, /* Don't care about disconnects */
787 NULL, /* Don't want notified about all incoming messages */ 813 NULL, /* Don't want notified about all incoming messages */
788 GNUNET_NO, /* For header only inbound notification */ 814 GNUNET_NO, /* For header only inbound notification */
@@ -802,7 +828,6 @@ run (void *cls,
802 &shutdown_task, NULL); 828 &shutdown_task, NULL);
803} 829}
804 830
805
806/** 831/**
807 * The main function for the dht service. 832 * The main function for the dht service.
808 * 833 *
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c
new file mode 100644
index 000000000..3890b7699
--- /dev/null
+++ b/src/dht/test_dht_twopeer.c
@@ -0,0 +1,297 @@
1/*
2 This file is part of GNUnet.
3 (C) 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 dht/test_dht_twopeer.c
22 * @brief base testcase for testing DHT service with
23 * two running peers
24 */
25#include "platform.h"
26#include "gnunet_testing_lib.h"
27#include "gnunet_core_service.h"
28#include "gnunet_dht_service.h"
29
30/* DEFINES */
31#define VERBOSE GNUNET_YES
32
33#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
34
35#define DEFAULT_NUM_PEERS 2
36
37/* Structs */
38/* ... */
39
40/* Globals */
41static char *test_directory;
42
43static unsigned int expected_connections;
44
45static unsigned long long peers_left;
46
47static struct GNUNET_TESTING_PeerGroup *pg;
48
49static struct GNUNET_SCHEDULER_Handle *sched;
50
51static unsigned long long num_peers;
52
53static unsigned int total_connections;
54
55static unsigned int failed_connections;
56
57GNUNET_SCHEDULER_TaskIdentifier die_task;
58
59static int ok;
60
61/**
62 * Check whether peers successfully shut down.
63 */
64void shutdown_callback (void *cls,
65 const char *emsg)
66{
67 if (emsg != NULL)
68 {
69 if (ok == 0)
70 ok = 2;
71 }
72}
73
74static void
75finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
76{
77 GNUNET_assert (pg != NULL);
78 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
79 ok = 0;
80}
81
82static void
83end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
84{
85 if (pg != NULL)
86 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
87 ok = 1;
88}
89
90void
91topology_callback (void *cls,
92 const struct GNUNET_PeerIdentity *first,
93 const struct GNUNET_PeerIdentity *second,
94 uint32_t distance,
95 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
96 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
97 struct GNUNET_TESTING_Daemon *first_daemon,
98 struct GNUNET_TESTING_Daemon *second_daemon,
99 const char *emsg)
100{
101 if (emsg == NULL)
102 {
103 total_connections++;
104#if VERBOSE
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
106 first_daemon->shortname,
107 second_daemon->shortname,
108 distance);
109#endif
110 }
111#if VERBOSE
112 else
113 {
114 failed_connections++;
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
116 first_daemon->shortname,
117 second_daemon->shortname, emsg);
118 }
119#endif
120
121 if (total_connections == expected_connections)
122 {
123#if VERBOSE
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Created %d total connections, which is our target number! Starting next phase of testing.\n",
126 total_connections);
127#endif
128 GNUNET_SCHEDULER_cancel (sched, die_task);
129 die_task = GNUNET_SCHEDULER_NO_TASK;
130 //GNUNET_SCHEDULER_add_now (sched, &next_phase, NULL);
131 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
132 }
133 else if (total_connections + failed_connections == expected_connections)
134 {
135 GNUNET_SCHEDULER_cancel (sched, die_task);
136 die_task = GNUNET_SCHEDULER_add_now (sched,
137 &end_badly, "from topology_callback (too many failed connections)");
138 }
139 else
140 {
141#if VERBOSE
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
143 "Have %d total connections, %d failed connections, Want %d\n",
144 total_connections, failed_connections, expected_connections);
145#endif
146 }
147}
148
149static void
150connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
151{
152 expected_connections = -1;
153 if ((pg != NULL) && (peers_left == 0))
154 {
155 expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0);
156#if VERBOSE
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "Have %d expected connections\n", expected_connections);
159#endif
160 }
161
162 GNUNET_SCHEDULER_cancel (sched, die_task);
163 if (expected_connections == GNUNET_SYSERR)
164 {
165 die_task = GNUNET_SCHEDULER_add_now (sched,
166 &end_badly, "from connect topology (bad return)");
167 }
168
169 die_task = GNUNET_SCHEDULER_add_delayed (sched,
170 TIMEOUT,
171 &end_badly, "from connect topology (timeout)");
172}
173
174static void
175peers_started_callback (void *cls,
176 const struct GNUNET_PeerIdentity *id,
177 const struct GNUNET_CONFIGURATION_Handle *cfg,
178 struct GNUNET_TESTING_Daemon *d, const char *emsg)
179{
180 if (emsg != NULL)
181 {
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
183 emsg);
184 return;
185 }
186 GNUNET_assert (id != NULL);
187#if VERBOSE
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
189 (num_peers - peers_left) + 1, num_peers);
190#endif
191
192 //GNUNET_DHT_connect();
193 peers_left--;
194
195 if (peers_left == 0)
196 {
197#if VERBOSE
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "All %d daemons started, now creating topology!\n",
200 num_peers);
201#endif
202 GNUNET_SCHEDULER_cancel (sched, die_task);
203 /* Set up task in case topology creation doesn't finish
204 * within a reasonable amount of time */
205 die_task = GNUNET_SCHEDULER_add_delayed (sched,
206 GNUNET_TIME_relative_multiply
207 (GNUNET_TIME_UNIT_MINUTES, 5),
208 &end_badly, "from peers_started_callback");
209
210 GNUNET_SCHEDULER_add_now(sched, &connect_topology, NULL);
211 ok = 0;
212 }
213}
214
215static void
216run (void *cls,
217 struct GNUNET_SCHEDULER_Handle *s,
218 char *const *args,
219 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
220{
221 sched = s;
222 ok = 1;
223
224 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
225 {
226 ok = 404;
227 return;
228 }
229
230 if (GNUNET_SYSERR ==
231 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
232 &num_peers))
233 num_peers = DEFAULT_NUM_PEERS;
234
235 peers_left = num_peers;
236
237 /* Set up a task to end testing if peer start fails */
238 die_task = GNUNET_SCHEDULER_add_delayed (sched,
239 TIMEOUT,
240 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
241
242 pg = GNUNET_TESTING_daemons_start (sched, cfg,
243 num_peers, TIMEOUT, NULL, NULL, &peers_started_callback, NULL,
244 &topology_callback, NULL, NULL);
245
246}
247
248static int
249check ()
250{
251 int ret;
252 char *const argv[] = {"test-dht-twopeer",
253 "-c",
254 "test_dht_twopeer_data.conf",
255#if VERBOSE
256 "-L", "DEBUG",
257#endif
258 NULL
259 };
260 struct GNUNET_GETOPT_CommandLineOption options[] = {
261 GNUNET_GETOPT_OPTION_END
262 };
263 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
264 argv, "test-dht-twopeer", "nohelp",
265 options, &run, &ok);
266 if (ret != GNUNET_OK)
267 {
268 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dht-twopeer': Failed with error code %d\n", ret);
269 }
270 return ok;
271}
272
273int
274main (int argc, char *argv[])
275{
276 int ret;
277
278 GNUNET_log_setup ("test-dht-twopeer",
279#if VERBOSE
280 "DEBUG",
281#else
282 "WARNING",
283#endif
284 NULL);
285 ret = check ();
286 /**
287 * Need to remove base directory, subdirectories taken care
288 * of by the testing framework.
289 */
290 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
291 {
292 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
293 }
294 return ret;
295}
296
297/* end of test_dht_twopeer.c */
diff --git a/src/dht/test_dht_twopeer_data.conf b/src/dht/test_dht_twopeer_data.conf
new file mode 100644
index 000000000..c0640847b
--- /dev/null
+++ b/src/dht/test_dht_twopeer_data.conf
@@ -0,0 +1,77 @@
1[fs]
2ACCEPT_FROM6 = ::1;
3ACCEPT_FROM = 127.0.0.1;
4BINARY = gnunet-service-fs
5CONFIG = $DEFAULTCONFIG
6HOME = $SERVICEHOME
7HOSTNAME = localhost
8PORT = 2094
9INDEXDB = $SERVICEHOME/idxinfo.lst
10
11[dht]
12#AUTOSTART = YES
13DEBUG = YES
14AUTOSTART = YES
15ACCEPT_FROM6 = ::1;
16ACCEPT_FROM = 127.0.0.1;
17BINARY = gnunet-service-dht
18#BINARY = /root/documents/research/gnunet/gnunet-ng/src/dht/.libs/gnunet-service-dht
19#PREFIX = xterm -T dvservice -e gdb --args
20OPTIONS=""
21CONFIG = $DEFAULTCONFIG
22HOME = $SERVICEHOME
23HOSTNAME = localhost
24PORT = 2100
25
26[dhtcache]
27QUOTA = 1000000
28DATABASE = sqlite
29
30[transport]
31PLUGINS = tcp
32DEBUG = NO
33ACCEPT_FROM6 = ::1;
34ACCEPT_FROM = 127.0.0.1;
35NEIGHBOUR_LIMIT = 50
36BINARY = gnunet-service-transport
37CONFIG = $DEFAULTCONFIG
38HOME = $SERVICEHOME
39HOSTNAME = localhost
40PORT = 12365
41
42[core]
43TOTAL_QUOTA_OUT = 3932160
44TOTAL_QUOTA_IN = 3932160
45ACCEPT_FROM6 = ::1;
46ACCEPT_FROM = 127.0.0.1;
47BINARY = gnunet-service-core
48CONFIG = $DEFAULTCONFIG
49HOME = $SERVICEHOME
50HOSTNAME = localhost
51PORT = 12092
52
53[arm]
54DEFAULTSERVICES = core dht
55ACCEPT_FROM6 = ::1;
56ACCEPT_FROM = 127.0.0.1;
57BINARY = gnunet-service-arm
58CONFIG = $DEFAULTCONFIG
59HOME = $SERVICEHOME
60HOSTNAME = localhost
61PORT = 12366
62DEBUG = YES
63
64[transport-tcp]
65TIMEOUT = 300000
66PORT = 12368
67
68[TESTING]
69WEAKRANDOM = YES
70
71[gnunetd]
72HOSTKEY = $SERVICEHOME/.hostkey
73
74[PATHS]
75DEFAULTCONFIG = test_dht_twopeer_data.conf
76SERVICEHOME = /tmp/test-dht-twopeer/
77