aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-30 15:58:44 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-30 15:58:44 +0000
commit444781955f83b5d541d7ee4556bcf864f4a2d38a (patch)
tree44544465306c79f36b0aa6e8e988385440d8532a
parentf5eaab80bfdbe04703096554f442dcbfa970b745 (diff)
downloadgnunet-444781955f83b5d541d7ee4556bcf864f4a2d38a.tar.gz
gnunet-444781955f83b5d541d7ee4556bcf864f4a2d38a.zip
two peer start, connect, ensure core connect message made it to the dht, disconnect, stop peers
-rw-r--r--src/dht/dht_api.c16
-rw-r--r--src/dht/gnunet-service-dht.c17
-rw-r--r--src/dht/test_dht_api_peer1.conf2
-rw-r--r--src/dht/test_dht_twopeer.c175
-rw-r--r--src/dht/test_dht_twopeer_data.conf2
5 files changed, 166 insertions, 46 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 2d54eeb9c..c4229a344 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -46,8 +46,6 @@
46 46
47#define DEBUG_DHT_API GNUNET_NO 47#define DEBUG_DHT_API GNUNET_NO
48 48
49#define DEFAULT_DHT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
50
51struct PendingMessage 49struct PendingMessage
52{ 50{
53 /** 51 /**
@@ -548,7 +546,7 @@ finish_retransmission (struct GNUNET_DHT_Handle *handle, int code)
548 */ 546 */
549void 547void
550service_message_handler (void *cls, 548service_message_handler (void *cls,
551 const struct GNUNET_MessageHeader *msg) 549 const struct GNUNET_MessageHeader *msg)
552{ 550{
553 struct GNUNET_DHT_Handle *handle = cls; 551 struct GNUNET_DHT_Handle *handle = cls;
554 struct GNUNET_DHT_RouteResultMessage *dht_msg; 552 struct GNUNET_DHT_RouteResultMessage *dht_msg;
@@ -567,9 +565,12 @@ service_message_handler (void *cls,
567#endif 565#endif
568 GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES); 566 GNUNET_CLIENT_disconnect (handle->client, GNUNET_YES);
569 handle->client = GNUNET_CLIENT_connect (handle->sched, 567 handle->client = GNUNET_CLIENT_connect (handle->sched,
570 "dht", 568 "dht",
571 handle->cfg); 569 handle->cfg);
572 570 if (handle->current != NULL)
571 {
572 finish(handle, GNUNET_SYSERR); /* If there was a current message, kill it! */
573 }
573 if (GNUNET_CONTAINER_multihashmap_iterate(handle->outstanding_requests, &retransmit_iterator, handle) > 0) 574 if (GNUNET_CONTAINER_multihashmap_iterate(handle->outstanding_requests, &retransmit_iterator, handle) > 0)
574 { 575 {
575 handle->retransmit_stage = DHT_RETRANSMITTING; 576 handle->retransmit_stage = DHT_RETRANSMITTING;
@@ -992,10 +993,9 @@ GNUNET_DHT_route_stop (struct GNUNET_DHT_RouteHandle *route_handle,
992 route_handle->uid); 993 route_handle->uid);
993#endif 994#endif
994 message->unique_id = GNUNET_htonll (route_handle->uid); 995 message->unique_id = GNUNET_htonll (route_handle->uid);
995 GNUNET_assert (route_handle->dht_handle->current == NULL);
996 pending = GNUNET_malloc (sizeof (struct PendingMessage)); 996 pending = GNUNET_malloc (sizeof (struct PendingMessage));
997 pending->msg = (struct GNUNET_MessageHeader *) message; 997 pending->msg = (struct GNUNET_MessageHeader *) message;
998 pending->timeout = DEFAULT_DHT_TIMEOUT; 998 pending->timeout = GNUNET_TIME_relative_get_forever();
999 pending->cont = cont; 999 pending->cont = cont;
1000 pending->cont_cls = cont_cls; 1000 pending->cont_cls = cont_cls;
1001 pending->unique_id = 0; /* When finished is called, free pending->msg */ 1001 pending->unique_id = 0; /* When finished is called, free pending->msg */
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index a2e0f4db7..c918a808a 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -779,10 +779,27 @@ void handle_core_connect (void *cls,
779 struct GNUNET_TIME_Relative latency, 779 struct GNUNET_TIME_Relative latency,
780 uint32_t distance) 780 uint32_t distance)
781{ 781{
782 int ret;
783 char *data;
784 size_t data_size = 42;
785 data = GNUNET_malloc (data_size);
786 memset (data, 43, data_size);
787
782#if DEBUG_DHT 788#if DEBUG_DHT
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 789 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); 790 "%s:%s Receives core connect message for peer %s distance %d!\n", my_short_id, "dht", GNUNET_i2s(peer), distance);
785#endif 791#endif
792 if (datacache != NULL)
793 {
794 ret = GNUNET_DATACACHE_put (datacache, &peer->hashPubKey, data_size,
795 data, 130,
796 GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
797 GNUNET_TIME_UNIT_MINUTES));
798#if DEBUG_DHT
799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
800 "%s Inserting data %s, type %d into datacache, return value was %d\n", my_short_id, GNUNET_h2s(&peer->hashPubKey), 130, ret);
801#endif
802 }
786} 803}
787 804
788/** 805/**
diff --git a/src/dht/test_dht_api_peer1.conf b/src/dht/test_dht_api_peer1.conf
index c02567efd..5b12c23e1 100644
--- a/src/dht/test_dht_api_peer1.conf
+++ b/src/dht/test_dht_api_peer1.conf
@@ -9,7 +9,7 @@ PORT = 2094
9INDEXDB = $SERVICEHOME/idxinfo.lst 9INDEXDB = $SERVICEHOME/idxinfo.lst
10 10
11[dht] 11[dht]
12DEBUG = NO 12DEBUG = YES
13AUTOSTART = YES 13AUTOSTART = YES
14ACCEPT_FROM6 = ::1; 14ACCEPT_FROM6 = ::1;
15ACCEPT_FROM = 127.0.0.1; 15ACCEPT_FROM = 127.0.0.1;
diff --git a/src/dht/test_dht_twopeer.c b/src/dht/test_dht_twopeer.c
index 3890b7699..c1472210e 100644
--- a/src/dht/test_dht_twopeer.c
+++ b/src/dht/test_dht_twopeer.c
@@ -35,11 +35,21 @@
35#define DEFAULT_NUM_PEERS 2 35#define DEFAULT_NUM_PEERS 2
36 36
37/* Structs */ 37/* Structs */
38/* ... */ 38
39struct PeerGetContext
40{
41 struct GNUNET_PeerIdentity *peer;
42
43 struct GNUNET_DHT_Handle *dht_handle;
44
45 struct GNUNET_DHT_GetHandle *get_handle;
46};
39 47
40/* Globals */ 48/* Globals */
41static char *test_directory; 49static char *test_directory;
42 50
51static struct PeerGetContext curr_get_ctx;
52
43static unsigned int expected_connections; 53static unsigned int expected_connections;
44 54
45static unsigned long long peers_left; 55static unsigned long long peers_left;
@@ -50,6 +60,10 @@ static struct GNUNET_SCHEDULER_Handle *sched;
50 60
51static unsigned long long num_peers; 61static unsigned long long num_peers;
52 62
63static unsigned int total_gets;
64
65static unsigned int gets_succeeded;
66
53static unsigned int total_connections; 67static unsigned int total_connections;
54 68
55static unsigned int failed_connections; 69static unsigned int failed_connections;
@@ -58,6 +72,14 @@ GNUNET_SCHEDULER_TaskIdentifier die_task;
58 72
59static int ok; 73static int ok;
60 74
75static struct GNUNET_PeerIdentity peer1id;
76
77static struct GNUNET_PeerIdentity peer2id;
78
79static struct GNUNET_DHT_Handle *peer1dht;
80
81static struct GNUNET_DHT_Handle *peer2dht;
82
61/** 83/**
62 * Check whether peers successfully shut down. 84 * Check whether peers successfully shut down.
63 */ 85 */
@@ -75,18 +97,95 @@ static void
75finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 97finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
76{ 98{
77 GNUNET_assert (pg != NULL); 99 GNUNET_assert (pg != NULL);
100 GNUNET_assert (peer1dht != NULL);
101 GNUNET_assert (peer2dht != NULL);
102 GNUNET_DHT_disconnect(peer1dht);
103 GNUNET_DHT_disconnect(peer2dht);
78 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 104 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
79 ok = 0; 105 ok = 0;
80} 106}
81 107
82static void 108static void
83end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc) 109end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
84{ 110{
111 if (peer1dht != NULL)
112 GNUNET_DHT_disconnect(peer1dht);
113
114 if (peer2dht != NULL)
115 GNUNET_DHT_disconnect(peer2dht);
116
85 if (pg != NULL) 117 if (pg != NULL)
86 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 118 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
119}
120
121static void
122end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
123{
124 if (curr_get_ctx.get_handle != NULL)
125 {
126 GNUNET_DHT_get_stop(curr_get_ctx.get_handle, &end_badly_cont, NULL);
127 }
128
87 ok = 1; 129 ok = 1;
88} 130}
89 131
132/* Forward declaration */
133static void
134do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc);
135
136/**
137 * Iterator called on each result obtained for a DHT
138 * operation that expects a reply
139 *
140 * @param cls closure
141 * @param exp when will this value expire
142 * @param key key of the result
143 * @param type type of the result
144 * @param size number of bytes in data
145 * @param data pointer to the result data
146 */
147void get_result_iterator (void *cls,
148 struct GNUNET_TIME_Absolute exp,
149 const GNUNET_HashCode * key,
150 uint32_t type,
151 uint32_t size,
152 const void *data)
153{
154 struct PeerGetContext *get_context = cls;
155 if (0 != memcmp(&get_context->peer->hashPubKey, key, sizeof (GNUNET_HashCode)))
156 {
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key returned is not the same key as was searched for!\n");
158 GNUNET_SCHEDULER_cancel(sched, die_task);
159 GNUNET_SCHEDULER_add_now(sched, &end_badly, "key mismatch in get response!\n");
160 return;
161 }
162
163 if (get_context->peer == &peer2id)
164 {
165 get_context->peer = &peer1id;
166 get_context->dht_handle = peer2dht;
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received first correct GET request response!\n");
168 GNUNET_DHT_get_stop(get_context->get_handle, &do_get, get_context);
169 }
170 else
171 {
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received second correct GET request response!\n");
173 GNUNET_SCHEDULER_cancel(sched, die_task);
174 GNUNET_DHT_get_stop(get_context->get_handle, &finish_testing, NULL);
175 }
176
177
178}
179
180static void
181do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
182{
183 struct PeerGetContext *get_context = cls;
184
185 get_context->get_handle = GNUNET_DHT_get_start(get_context->dht_handle, GNUNET_TIME_relative_get_forever(), 130, &get_context->peer->hashPubKey, &get_result_iterator, get_context, NULL, NULL);
186}
187
188
90void 189void
91topology_callback (void *cls, 190topology_callback (void *cls,
92 const struct GNUNET_PeerIdentity *first, 191 const struct GNUNET_PeerIdentity *first,
@@ -126,23 +225,19 @@ topology_callback (void *cls,
126 total_connections); 225 total_connections);
127#endif 226#endif
128 GNUNET_SCHEDULER_cancel (sched, die_task); 227 GNUNET_SCHEDULER_cancel (sched, die_task);
129 die_task = GNUNET_SCHEDULER_NO_TASK; 228 die_task = GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT,
130 //GNUNET_SCHEDULER_add_now (sched, &next_phase, NULL); 229 &end_badly, "from test gets");
131 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL); 230
231 curr_get_ctx.dht_handle = peer1dht;
232 curr_get_ctx.peer = &peer2id;
233 GNUNET_SCHEDULER_add_now (sched, &do_get, &curr_get_ctx);
234 //GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2), &do_get, &curr_get_ctx);
132 } 235 }
133 else if (total_connections + failed_connections == expected_connections) 236 else if (total_connections + failed_connections == expected_connections)
134 { 237 {
135 GNUNET_SCHEDULER_cancel (sched, die_task); 238 GNUNET_SCHEDULER_cancel (sched, die_task);
136 die_task = GNUNET_SCHEDULER_add_now (sched, 239 die_task = GNUNET_SCHEDULER_add_now (sched,
137 &end_badly, "from topology_callback (too many failed connections)"); 240 &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 } 241 }
147} 242}
148 243
@@ -151,20 +246,13 @@ connect_topology (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
151{ 246{
152 expected_connections = -1; 247 expected_connections = -1;
153 if ((pg != NULL) && (peers_left == 0)) 248 if ((pg != NULL) && (peers_left == 0))
154 { 249 expected_connections = GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE, GNUNET_TESTING_TOPOLOGY_OPTION_ALL, 0.0);
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 250
162 GNUNET_SCHEDULER_cancel (sched, die_task); 251 GNUNET_SCHEDULER_cancel (sched, die_task);
163 if (expected_connections == GNUNET_SYSERR) 252 if (expected_connections == GNUNET_SYSERR)
164 { 253 die_task = GNUNET_SCHEDULER_add_now (sched,
165 die_task = GNUNET_SCHEDULER_add_now (sched, 254 &end_badly, "from connect topology (bad return)");
166 &end_badly, "from connect topology (bad return)"); 255
167 }
168 256
169 die_task = GNUNET_SCHEDULER_add_delayed (sched, 257 die_task = GNUNET_SCHEDULER_add_delayed (sched,
170 TIMEOUT, 258 TIMEOUT,
@@ -179,32 +267,47 @@ peers_started_callback (void *cls,
179{ 267{
180 if (emsg != NULL) 268 if (emsg != NULL)
181 { 269 {
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n", 270 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to start daemon with error: `%s'\n",
183 emsg); 271 emsg);
184 return; 272 return;
185 } 273 }
186 GNUNET_assert (id != NULL); 274 GNUNET_assert (id != NULL);
187#if VERBOSE 275 if (peers_left == num_peers)
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n", 276 {
189 (num_peers - peers_left) + 1, num_peers); 277 memcpy(&peer1id, id, sizeof(struct GNUNET_PeerIdentity));
190#endif 278 peer1dht = GNUNET_DHT_connect(sched, cfg, 100);
279 if (peer1dht == NULL)
280 {
281 GNUNET_SCHEDULER_cancel (sched, die_task);
282 GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n");
283 }
284 }
285 else
286 {
287 memcpy(&peer2id, id, sizeof(struct GNUNET_PeerIdentity));
288 peer2dht = GNUNET_DHT_connect(sched, cfg, 100);
289 if (peer2dht == NULL)
290 {
291 GNUNET_SCHEDULER_cancel (sched, die_task);
292 GNUNET_SCHEDULER_add_now(sched, &end_badly, "Failed to get dht handle!\n");
293 }
294 }
295
191 296
192 //GNUNET_DHT_connect();
193 peers_left--; 297 peers_left--;
194 298
195 if (peers_left == 0) 299 if (peers_left == 0)
196 { 300 {
197#if VERBOSE 301#if VERBOSE
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 302 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "All %d daemons started, now creating topology!\n", 303 "All %d daemons started, now connecting peers!\n",
200 num_peers); 304 num_peers);
201#endif 305#endif
202 GNUNET_SCHEDULER_cancel (sched, die_task); 306 GNUNET_SCHEDULER_cancel (sched, die_task);
203 /* Set up task in case topology creation doesn't finish 307 /* Set up task in case topology creation doesn't finish
204 * within a reasonable amount of time */ 308 * within a reasonable amount of time */
205 die_task = GNUNET_SCHEDULER_add_delayed (sched, 309 die_task = GNUNET_SCHEDULER_add_delayed (sched,
206 GNUNET_TIME_relative_multiply 310 TIMEOUT,
207 (GNUNET_TIME_UNIT_MINUTES, 5),
208 &end_badly, "from peers_started_callback"); 311 &end_badly, "from peers_started_callback");
209 312
210 GNUNET_SCHEDULER_add_now(sched, &connect_topology, NULL); 313 GNUNET_SCHEDULER_add_now(sched, &connect_topology, NULL);
@@ -219,7 +322,6 @@ run (void *cls,
219 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 322 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
220{ 323{
221 sched = s; 324 sched = s;
222 ok = 1;
223 325
224 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory)) 326 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
225 { 327 {
@@ -233,7 +335,8 @@ run (void *cls,
233 num_peers = DEFAULT_NUM_PEERS; 335 num_peers = DEFAULT_NUM_PEERS;
234 336
235 peers_left = num_peers; 337 peers_left = num_peers;
236 338 total_gets = num_peers;
339 gets_succeeded = 0;
237 /* Set up a task to end testing if peer start fails */ 340 /* Set up a task to end testing if peer start fails */
238 die_task = GNUNET_SCHEDULER_add_delayed (sched, 341 die_task = GNUNET_SCHEDULER_add_delayed (sched,
239 TIMEOUT, 342 TIMEOUT,
diff --git a/src/dht/test_dht_twopeer_data.conf b/src/dht/test_dht_twopeer_data.conf
index c0640847b..4ea86e82a 100644
--- a/src/dht/test_dht_twopeer_data.conf
+++ b/src/dht/test_dht_twopeer_data.conf
@@ -10,7 +10,7 @@ INDEXDB = $SERVICEHOME/idxinfo.lst
10 10
11[dht] 11[dht]
12#AUTOSTART = YES 12#AUTOSTART = YES
13DEBUG = YES 13DEBUG = NO
14AUTOSTART = YES 14AUTOSTART = YES
15ACCEPT_FROM6 = ::1; 15ACCEPT_FROM6 = ::1;
16ACCEPT_FROM = 127.0.0.1; 16ACCEPT_FROM = 127.0.0.1;