aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-04-03 11:45:16 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-04-03 11:45:16 +0000
commit8bc672c50f7c98af110bfbcdda2e1e7e7fd49d69 (patch)
treeecc39fcade3862f98ef268471736d06072ef8329 /src/gns
parent83b8b3435ec2c06b8d4057648b077f9e8830a270 (diff)
downloadgnunet-8bc672c50f7c98af110bfbcdda2e1e7e7fd49d69.tar.gz
gnunet-8bc672c50f7c98af110bfbcdda2e1e7e7fd49d69.zip
-array of fixes, finally finished test
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/Makefile.am28
-rw-r--r--src/gns/gnunet-service-gns.c38
-rw-r--r--src/gns/gnunet-service-gns_resolver.c1
-rw-r--r--src/gns/gnunet-service-gns_resolver.h2
-rw-r--r--src/gns/plugin_block_gns.c16
-rw-r--r--src/gns/test_gns_dht_threepeer.c341
6 files changed, 255 insertions, 171 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 7c0cb3f31..cbf4a02bb 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -39,8 +39,8 @@ check_PROGRAMS = \
39 test_gns_simple_zkey_lookup \ 39 test_gns_simple_zkey_lookup \
40 test_gns_dht_delegated_lookup \ 40 test_gns_dht_delegated_lookup \
41 test_gns_pseu_shorten \ 41 test_gns_pseu_shorten \
42 test_gns_max_queries 42 test_gns_max_queries \
43# test_gns_dht_threepeer 43 test_gns_dht_threepeer
44 44
45 45
46# test_gns_simple_lookup 46# test_gns_simple_lookup
@@ -51,18 +51,18 @@ check_PROGRAMS = \
51plugin_LTLIBRARIES = \ 51plugin_LTLIBRARIES = \
52 libgnunet_plugin_block_gns.la 52 libgnunet_plugin_block_gns.la
53 53
54#test_gns_dht_threepeer_SOURCES = \ 54test_gns_dht_threepeer_SOURCES = \
55# test_gns_dht_threepeer.c 55 test_gns_dht_threepeer.c
56#test_gns_dht_threepeer_LDADD = \ 56test_gns_dht_threepeer_LDADD = \
57# $(top_builddir)/src/util/libgnunetutil.la \ 57 $(top_builddir)/src/util/libgnunetutil.la \
58# $(top_builddir)/src/namestore/libgnunetnamestore.la \ 58 $(top_builddir)/src/namestore/libgnunetnamestore.la \
59# $(top_builddir)/src/gns/libgnunetgns.la \ 59 $(top_builddir)/src/gns/libgnunetgns.la \
60# $(top_builddir)/src/testing/libgnunettesting.la 60 $(top_builddir)/src/testing/libgnunettesting.la
61#test_gns_dht_threepeer_DEPENDENCIES = \ 61test_gns_dht_threepeer_DEPENDENCIES = \
62# $(top_builddir)/src/util/libgnunetutil.la \ 62 $(top_builddir)/src/util/libgnunetutil.la \
63# $(top_builddir)/src/namestore/libgnunetnamestore.la \ 63 $(top_builddir)/src/namestore/libgnunetnamestore.la \
64# $(top_builddir)/src/gns/libgnunetgns.la \ 64 $(top_builddir)/src/gns/libgnunetgns.la \
65# $(top_builddir)/src/testing/libgnunettesting.la 65 $(top_builddir)/src/testing/libgnunettesting.la
66 66
67test_gns_simple_lookup_SOURCES = \ 67test_gns_simple_lookup_SOURCES = \
68 test_gns_simple_lookup.c 68 test_gns_simple_lookup.c
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 970e001c9..c2ea2a44d 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -142,6 +142,11 @@ struct GNUNET_CRYPTO_ShortHashCode zone_hash;
142 */ 142 */
143static int num_public_records = 3600; 143static int num_public_records = 3600;
144 144
145/**
146 * update interval in seconds
147 */
148static unsigned long long int dht_max_update_interval;
149
145/* dht update interval FIXME define? */ 150/* dht update interval FIXME define? */
146static struct GNUNET_TIME_Relative dht_update_interval; 151static struct GNUNET_TIME_Relative dht_update_interval;
147 152
@@ -253,11 +258,11 @@ put_gns_record(void *cls,
253 { 258 {
254 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 259 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
255 "Zone iteration finished. Rescheduling put in %ds\n", 260 "Zone iteration finished. Rescheduling put in %ds\n",
256 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL); 261 dht_max_update_interval);
257 zone_update_taskid = GNUNET_SCHEDULER_add_delayed ( 262 zone_update_taskid = GNUNET_SCHEDULER_add_delayed (
258 GNUNET_TIME_relative_multiply( 263 GNUNET_TIME_relative_multiply(
259 GNUNET_TIME_UNIT_SECONDS, 264 GNUNET_TIME_UNIT_SECONDS,
260 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL 265 dht_max_update_interval
261 ), 266 ),
262 &update_zone_dht_start, 267 &update_zone_dht_start,
263 NULL); 268 NULL);
@@ -324,6 +329,9 @@ put_gns_record(void *cls,
324 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 329 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
325 "putting records for %s under key: %s with size %d\n", 330 "putting records for %s under key: %s with size %d\n",
326 name, (char*)&xor_hash_string, rd_payload_length); 331 name, (char*)&xor_hash_string, rd_payload_length);
332
333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
334 "DHT req to %d\n", DHT_OPERATION_TIMEOUT.rel_value);
327 335
328 GNUNET_DHT_put (dht_handle, &xor_hash, 336 GNUNET_DHT_put (dht_handle, &xor_hash,
329 DHT_GNS_REPLICATION_LEVEL, 337 DHT_GNS_REPLICATION_LEVEL,
@@ -363,20 +371,20 @@ update_zone_dht_start(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
363 { 371 {
364 dht_update_interval = GNUNET_TIME_relative_multiply( 372 dht_update_interval = GNUNET_TIME_relative_multiply(
365 GNUNET_TIME_UNIT_SECONDS, 373 GNUNET_TIME_UNIT_SECONDS,
366 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL); 374 dht_max_update_interval);
367 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 375 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
368 "No records in db. Adjusted DHT update interval to %ds\n", 376 "No records in db. Adjusted DHT update interval to %ds\n",
369 GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL); 377 dht_max_update_interval);
370 } 378 }
371 else 379 else
372 { 380 {
373 381
374 dht_update_interval = GNUNET_TIME_relative_multiply( 382 dht_update_interval = GNUNET_TIME_relative_multiply(
375 GNUNET_TIME_UNIT_SECONDS, 383 GNUNET_TIME_UNIT_SECONDS,
376 (3600/num_public_records)); 384 (dht_max_update_interval/num_public_records));
377 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 385 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
378 "Adjusted DHT update interval to %ds!\n", 386 "Adjusted DHT update interval to %ds!\n",
379 (3600/num_public_records)); 387 (dht_max_update_interval/num_public_records));
380 } 388 }
381 389
382 /* start counting again */ 390 /* start counting again */
@@ -567,6 +575,7 @@ static void handle_get_authority(void *cls,
567 char name[MAX_DNS_NAME_LENGTH]; 575 char name[MAX_DNS_NAME_LENGTH];
568 char* nameptr = name; 576 char* nameptr = name;
569 577
578
570 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage)) 579 if (ntohs (message->size) < sizeof (struct GNUNET_GNS_ClientGetAuthMessage))
571 { 580 {
572 GNUNET_break_op (0); 581 GNUNET_break_op (0);
@@ -819,6 +828,18 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
819 828
820 } 829 }
821 830
831 dht_max_update_interval = GNUNET_GNS_DHT_MAX_UPDATE_INTERVAL;
832
833 if (GNUNET_OK ==
834 GNUNET_CONFIGURATION_get_value_number (c, "gns",
835 "DHT_MAX_UPDATE_INTERVAL",
836 &dht_max_update_interval))
837 {
838 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
839 "DHT zone update interval: %d\n",
840 dht_max_update_interval);
841 }
842
822 if (GNUNET_OK == 843 if (GNUNET_OK ==
823 GNUNET_CONFIGURATION_get_value_number (c, "gns", 844 GNUNET_CONFIGURATION_get_value_number (c, "gns",
824 "MAX_PARALLEL_BACKGROUND_QUERIES", 845 "MAX_PARALLEL_BACKGROUND_QUERIES",
@@ -854,7 +875,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
854 * handle to the dht 875 * handle to the dht
855 */ 876 */
856 dht_handle = GNUNET_DHT_connect(c, 877 dht_handle = GNUNET_DHT_connect(c,
857 max_parallel_bg_queries); //FIXME get ht_len from cfg 878 //max_parallel_bg_queries); //FIXME get ht_len from cfg
879 1024);
858 880
859 if (NULL == dht_handle) 881 if (NULL == dht_handle)
860 { 882 {
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index 964afb4f4..57fbef8b2 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -38,7 +38,6 @@
38#include "gns.h" 38#include "gns.h"
39#include "gnunet-service-gns_resolver.h" 39#include "gnunet-service-gns_resolver.h"
40 40
41#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3)
42#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT 41#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
43#define DHT_GNS_REPLICATION_LEVEL 5 42#define DHT_GNS_REPLICATION_LEVEL 5
44#define MAX_DNS_LABEL_LENGTH 63 43#define MAX_DNS_LABEL_LENGTH 63
diff --git a/src/gns/gnunet-service-gns_resolver.h b/src/gns/gnunet-service-gns_resolver.h
index 17d0a7221..44c10fc52 100644
--- a/src/gns/gnunet-service-gns_resolver.h
+++ b/src/gns/gnunet-service-gns_resolver.h
@@ -4,7 +4,7 @@
4#include "gns.h" 4#include "gns.h"
5#include "gnunet_dht_service.h" 5#include "gnunet_dht_service.h"
6 6
7#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) 7#define DHT_OPERATION_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
8#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \ 8#define GNUNET_GNS_DEFAULT_LOOKUP_TIMEOUT \
9 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 9 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
10#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT 10#define DHT_LOOKUP_TIMEOUT DHT_OPERATION_TIMEOUT
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index 46ce1249d..9d9513a09 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -215,16 +215,22 @@ block_plugin_gns_get_key (void *cls, enum GNUNET_BLOCK_Type type,
215{ 215{
216 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 216 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
217 return GNUNET_SYSERR; 217 return GNUNET_SYSERR;
218 GNUNET_HashCode name_hash; 218 struct GNUNET_CRYPTO_ShortHashCode name_hash;
219 GNUNET_HashCode pkey_hash; 219 struct GNUNET_CRYPTO_ShortHashCode pkey_hash;
220 GNUNET_HashCode name_hash_double;
221 GNUNET_HashCode pkey_hash_double;
222
220 struct GNSNameRecordBlock *nrb = (struct GNSNameRecordBlock *)block; 223 struct GNSNameRecordBlock *nrb = (struct GNSNameRecordBlock *)block;
221 224
222 GNUNET_CRYPTO_hash(&nrb[1], strlen((char*)&nrb[1]), &name_hash); 225 GNUNET_CRYPTO_short_hash(&nrb[1], strlen((char*)&nrb[1]), &name_hash);
223 GNUNET_CRYPTO_hash(&nrb->public_key, 226 GNUNET_CRYPTO_short_hash(&nrb->public_key,
224 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 227 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
225 &pkey_hash); 228 &pkey_hash);
229
230 GNUNET_CRYPTO_short_hash_double(&name_hash, &name_hash_double);
231 GNUNET_CRYPTO_short_hash_double(&pkey_hash, &pkey_hash_double);
226 232
227 GNUNET_CRYPTO_hash_xor(&name_hash, &pkey_hash, key); 233 GNUNET_CRYPTO_hash_xor(&name_hash_double, &pkey_hash_double, key);
228 234
229 return GNUNET_OK; 235 return GNUNET_OK;
230} 236}
diff --git a/src/gns/test_gns_dht_threepeer.c b/src/gns/test_gns_dht_threepeer.c
index 7d8ed6c6b..04cbc2b81 100644
--- a/src/gns/test_gns_dht_threepeer.c
+++ b/src/gns/test_gns_dht_threepeer.c
@@ -43,12 +43,16 @@
43 43
44/* Timeout for entire testcase */ 44/* Timeout for entire testcase */
45#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80) 45#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 80)
46#define ZONE_PUT_WAIT_TIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
46 47
47/* If number of peers not in config file, use this number */ 48/* If number of peers not in config file, use this number */
48#define DEFAULT_NUM_PEERS 2 49#define DEFAULT_NUM_PEERS 2
49 50
50#define TEST_DOMAIN "www.buddy.bob.gnunet" 51#define TEST_DOMAIN "www.buddy.bob.gnunet"
51#define TEST_IP "1.1.1.1" 52#define TEST_IP "1.1.1.1"
53#define TEST_DAVE_PSEU "hagbard"
54#define TEST_NUM_PEERS 3
55#define TEST_NUM_CON 3
52 56
53/* Globals */ 57/* Globals */
54 58
@@ -101,43 +105,27 @@ static int ok;
101 105
102int bob_online, alice_online, dave_online; 106int bob_online, alice_online, dave_online;
103 107
104struct GNUNET_CONFIGURATION_Handle *cfg_alice; 108struct GNUNET_CONFIGURATION_Handle *alice_cfg;
105struct GNUNET_CONFIGURATION_Handle *cfg_bob; 109struct GNUNET_CONFIGURATION_Handle *cfg_bob;
106struct GNUNET_CONFIGURATION_Handle *cfg_dave; 110struct GNUNET_CONFIGURATION_Handle *cfg_dave;
107 111
108/** 112struct GNUNET_CRYPTO_ShortHashCode bob_hash;
109 * Check whether peers successfully shut down. 113struct GNUNET_CRYPTO_ShortHashCode dave_hash;
110 */ 114struct GNUNET_TESTING_Daemon *alice_daemon;
111void 115struct GNUNET_TESTING_Daemon *bob_daemon;
112shutdown_callback (void *cls, const char *emsg) 116struct GNUNET_TESTING_Daemon *dave_daemon;
113{ 117
114 if (emsg != NULL) 118struct GNUNET_TESTING_PeerGroup *pg;
115 { 119struct GNUNET_GNS_Handle *gh;
116 if (ok == 0)
117 ok = 2;
118 }
119}
120 120
121/** 121/**
122 * Function scheduled to be run on the successful completion of this 122 * Function scheduled to be run on the successful completion of this
123 * testcase. Specifically, called when our get request completes. 123 * testcase. Specifically, called when our get request completes.
124 */ 124 */
125static void 125static void
126finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 126finish_testing (void *cls, const char *emsg)
127{ 127{
128 ok = 0; 128 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test finished! (ret=%d)\n", ok);
129 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down alice!\n");
130 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL,
131 GNUNET_YES, GNUNET_NO);
132 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down bob!\n");
133 GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &shutdown_callback, NULL,
134 GNUNET_YES, GNUNET_NO);
135 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down dave\n");
136 GNUNET_TESTING_daemon_stop (d3, TIMEOUT, &shutdown_callback, NULL,
137 GNUNET_YES, GNUNET_NO);
138 GNUNET_DISK_file_copy ("testdb/sqlite-alice.db.bak",
139 "testdb/sqlite-alice.db.bak");
140 GNUNET_SCHEDULER_cancel(die_task);
141} 129}
142 130
143/** 131/**
@@ -147,16 +135,7 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
147static void 135static void
148end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 136end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
149{ 137{
150 if (d1 != NULL) 138 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &finish_testing, NULL);
151 GNUNET_TESTING_daemon_stop (d1, TIMEOUT, &shutdown_callback, NULL,
152 GNUNET_YES, GNUNET_NO);
153 if (d2 != NULL)
154 GNUNET_TESTING_daemon_stop (d2, TIMEOUT, &shutdown_callback, NULL,
155 GNUNET_YES, GNUNET_NO);
156;
157 if (d3 != NULL)
158 GNUNET_TESTING_daemon_stop (d3, TIMEOUT, &shutdown_callback, NULL,
159 GNUNET_YES, GNUNET_NO);
160} 139}
161 140
162/** 141/**
@@ -173,33 +152,58 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
173 ok = 1; 152 ok = 1;
174} 153}
175 154
155
176static void 156static void
177commence_testing(void) 157on_lookup_result(void *cls, uint32_t rd_count,
158 const struct GNUNET_NAMESTORE_RecordData *rd)
178{ 159{
179 struct hostent *he; 160 int i;
180 struct in_addr a; 161 char* string_val;
181 char* addr; 162 const char* typename;
182
183 he = gethostbyname (TEST_DOMAIN);
184 163
185 if (he) 164 if (rd_count == 0)
186 { 165 {
187 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name); 166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
188 while (*he->h_addr_list) 167 "Lookup failed!\n");
168 ok = 2;
169 }
170 else
171 {
172 ok = 1;
173 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
174 for (i=0; i<rd_count; i++)
189 { 175 {
190 bcopy(*he->h_addr_list++, (char *) &a, sizeof(a)); 176 typename = GNUNET_NAMESTORE_number_to_typename (rd[i].record_type);
191 addr = inet_ntoa(a); 177 string_val = GNUNET_NAMESTORE_value_to_string(rd[i].record_type,
192 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); 178 rd[i].data,
193 if (strcmp(addr, TEST_IP) == 0) 179 rd[i].data_size);
180 printf("Got %s record: %s\n", typename, string_val);
181 if (0 == strcmp(string_val, TEST_IP))
182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
184 "%s correctly resolved to %s!\n", TEST_DOMAIN, string_val);
194 ok = 0; 185 ok = 0;
186 }
195 } 187 }
196 } 188 }
197 else 189 GNUNET_GNS_disconnect(gh);
198 ok = 1; 190 GNUNET_SCHEDULER_cancel(die_task);
199 //do lookup here 191 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &finish_testing, NULL);
200 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 192 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down!\n");
201 (GNUNET_TIME_UNIT_SECONDS, 30), 193
202 &finish_testing, NULL); 194}
195
196static void
197commence_testing(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198{
199
200
201 gh = GNUNET_GNS_connect(alice_cfg);
202
203 GNUNET_GNS_lookup(gh, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
204 &on_lookup_result, TEST_DOMAIN);
205 die_task =
206 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from lookup");
203} 207}
204 208
205 209
@@ -213,7 +217,7 @@ commence_testing(void)
213 * failure (peers failed to connect). 217 * failure (peers failed to connect).
214 */ 218 */
215void 219void
216notify_connect (void *cls, const struct GNUNET_PeerIdentity *first, 220daemon_connected (void *cls, const struct GNUNET_PeerIdentity *first,
217 const struct GNUNET_PeerIdentity *second, uint32_t distance, 221 const struct GNUNET_PeerIdentity *second, uint32_t distance,
218 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 222 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
219 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 223 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
@@ -248,9 +252,10 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *first,
248 total_connections); 252 total_connections);
249#endif 253#endif
250 GNUNET_SCHEDULER_cancel (die_task); 254 GNUNET_SCHEDULER_cancel (die_task);
251 die_task = 255 //die_task =
252 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from connect"); 256 // GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, "from connect");
253 commence_testing(); 257
258 //commence_testing();
254 259
255 } 260 }
256 else if (total_connections + failed_connections == expected_connections) 261 else if (total_connections + failed_connections == expected_connections)
@@ -260,96 +265,154 @@ notify_connect (void *cls, const struct GNUNET_PeerIdentity *first,
260 GNUNET_SCHEDULER_add_now (&end_badly, 265 GNUNET_SCHEDULER_add_now (&end_badly,
261 "from topology_callback (too many failed connections)"); 266 "from topology_callback (too many failed connections)");
262 } 267 }
263 else
264 {
265 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting peers dave, bob\n");
266 GNUNET_TESTING_daemons_connect (d3, d2, TIMEOUT, 5, 1,
267 &notify_connect, NULL);
268 }
269} 268}
270 269
271/** 270void
272 * Set up some data, and call API PUT function 271all_connected(void *cls, const char *emsg)
273 */
274static void
275connect_ab (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
276{ 272{
277 273 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
278 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting peers alice, bob\n"); 274 "Created all connections! Starting next phase of testing.\n");
279 GNUNET_TESTING_daemons_connect (d1, d2, TIMEOUT, 5, 1, 275 GNUNET_SCHEDULER_add_delayed (ZONE_PUT_WAIT_TIME, &commence_testing, NULL);
280 &notify_connect, NULL);
281} 276}
282 277
278void
279ns_create_cont(void *cls, int32_t s, const char *emsg)
280{
281 GNUNET_NAMESTORE_disconnect((struct GNUNET_NAMESTORE_Handle *)cls, 0);
282}
283 283
284static void 284static void
285dave_started (void *cls, const struct GNUNET_PeerIdentity *id, 285daemon_started (void *cls, const struct GNUNET_PeerIdentity *id,
286 const struct GNUNET_CONFIGURATION_Handle *cfg, 286 const struct GNUNET_CONFIGURATION_Handle *cfg,
287 struct GNUNET_TESTING_Daemon *d, const char *emsg) 287 struct GNUNET_TESTING_Daemon *d, const char *emsg)
288{ 288{
289 if (emsg != NULL) 289 struct GNUNET_NAMESTORE_Handle *ns;
290 char* keyfile;
291 struct GNUNET_CRYPTO_RsaPrivateKey *key;
292 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey;
293 struct in_addr *web;
294 struct GNUNET_NAMESTORE_RecordData rd;
295
296 rd.flags = GNUNET_NAMESTORE_RF_AUTHORITY | GNUNET_NAMESTORE_RF_NONE;
297 rd.expiration = GNUNET_TIME_UNIT_FOREVER_ABS;
298
299 if (NULL == dave_daemon)
290 { 300 {
291 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 301 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
292 "Failed to start daemon with error: `%s'\n", emsg); 302 "ZONEKEY",
303 &keyfile))
304 {
305 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
306 ok = -1;
307 return;
308 }
309 dave_daemon = d;
310
311 key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
312
313 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is now dave\n");
314 ns = GNUNET_NAMESTORE_connect(cfg);
315
316 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
317 GNUNET_CRYPTO_short_hash(&pkey, sizeof(pkey), &dave_hash);
318
319 web = GNUNET_malloc(sizeof(struct in_addr));
320 GNUNET_assert(1 == inet_pton (AF_INET, TEST_IP, web));
321 rd.data_size = sizeof(struct in_addr);
322 rd.data = web;
323 rd.record_type = GNUNET_GNS_RECORD_TYPE_A;
324
325 GNUNET_NAMESTORE_record_create (ns, key, "www", &rd, NULL, NULL);
326
327 rd.data_size = strlen(TEST_DAVE_PSEU);
328 rd.data = TEST_DAVE_PSEU;
329 rd.record_type = GNUNET_GNS_RECORD_PSEU;
330
331 GNUNET_NAMESTORE_record_create (ns, key, "+", &rd, ns_create_cont, ns);
332
333 GNUNET_CRYPTO_rsa_key_free(key);
334 GNUNET_free(keyfile);
335 GNUNET_free(web);
336
293 return; 337 return;
294 } 338 }
295 GNUNET_assert (id != NULL);
296 339
297 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 340
298 (GNUNET_TIME_UNIT_SECONDS, 2), 341 if (NULL == bob_daemon)
299 &connect_ab, NULL); 342 {
300} 343 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
344 "ZONEKEY",
345 &keyfile))
346 {
347 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
348 ok = -1;
349 return;
350 }
351 bob_daemon = d;
301 352
353 key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
302 354
355 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is now bob\n");
356 ns = GNUNET_NAMESTORE_connect(cfg);
357
358 GNUNET_CRYPTO_rsa_key_get_public (key, &pkey);
359 GNUNET_CRYPTO_short_hash(&pkey, sizeof(pkey), &bob_hash);
360
361 rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
362 rd.data = &dave_hash;
363 rd.record_type = GNUNET_GNS_RECORD_PKEY;
364
365 GNUNET_NAMESTORE_record_create (ns, key, "buddy", &rd, ns_create_cont, ns);
366
367 GNUNET_CRYPTO_rsa_key_free(key);
368 GNUNET_free(keyfile);
303 369
304static void
305bob_started (void *cls, const struct GNUNET_PeerIdentity *id,
306 const struct GNUNET_CONFIGURATION_Handle *cfg,
307 struct GNUNET_TESTING_Daemon *d, const char *emsg)
308{
309 if (emsg != NULL)
310 {
311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
312 "Failed to start daemon with error: `%s'\n", emsg);
313 return; 370 return;
314 } 371 }
315 GNUNET_assert (id != NULL); 372
316 373
317 //Start bob 374
318 d3 = GNUNET_TESTING_daemon_start(cfg_dave, TIMEOUT, GNUNET_NO, NULL, NULL, 0, 375 if (NULL == alice_daemon)
319 NULL, NULL, NULL, &dave_started, NULL); 376 {
320 377
321} 378 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, "gns",
379 "ZONEKEY",
380 &keyfile))
381 {
382 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to get key from cfg\n");
383 ok = -1;
384 return;
385 }
386 alice_daemon = d;
387 alice_cfg = cfg;
322 388
389 key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
323 390
391 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is now alice\n");
392 ns = GNUNET_NAMESTORE_connect(cfg);
393
394 rd.data_size = sizeof(struct GNUNET_CRYPTO_ShortHashCode);
395 rd.data = &bob_hash;
396 rd.record_type = GNUNET_GNS_RECORD_PKEY;
324 397
325/** 398 GNUNET_NAMESTORE_record_create (ns, key, "bob", &rd, ns_create_cont, ns);
326 * Callback which is called whenever a peer is started (as a result of the 399
327 * GNUNET_TESTING_daemons_start call. 400 GNUNET_CRYPTO_rsa_key_free(key);
328 * 401 GNUNET_free(keyfile);
329 * @param cls closure argument given to GNUNET_TESTING_daemons_start 402
330 * @param id the GNUNET_PeerIdentity of the started peer 403 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
331 * @param cfg the configuration for this specific peer (needed to connect 404 GNUNET_TESTING_TOPOLOGY_OPTION_ALL,
332 * to the DHT) 405 0,
333 * @param d the handle to the daemon started 406 TIMEOUT,
334 * @param emsg NULL if peer started, non-NULL on error 407 3,
335 */ 408 &all_connected, NULL);
336static void
337alice_started (void *cls, const struct GNUNET_PeerIdentity *id,
338 const struct GNUNET_CONFIGURATION_Handle *cfg,
339 struct GNUNET_TESTING_Daemon *d, const char *emsg)
340{
341 if (emsg != NULL)
342 {
343 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
344 "Failed to start daemon with error: `%s'\n", emsg);
345 return; 409 return;
410
346 } 411 }
347 GNUNET_assert (id != NULL); 412
348
349 //Start bob
350 d2 = GNUNET_TESTING_daemon_start(cfg_bob, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
351 NULL, NULL, NULL, &bob_started, NULL);
352 413
414
415 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "This is a random guy\n");
353} 416}
354 417
355static void 418static void
@@ -366,6 +429,8 @@ run (void *cls, char *const *args, const char *cfgfile,
366 return; 429 return;
367 } 430 }
368 431
432 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "starting\n");
433
369 /* Get number of peers to start from configuration (should be two) */ 434 /* Get number of peers to start from configuration (should be two) */
370 if (GNUNET_SYSERR == 435 if (GNUNET_SYSERR ==
371 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers", 436 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
@@ -375,22 +440,14 @@ run (void *cls, char *const *args, const char *cfgfile,
375 /* Set peers_left so we know when all peers started */ 440 /* Set peers_left so we know when all peers started */
376 peers_left = num_peers; 441 peers_left = num_peers;
377 442
378 /** 443 bob_daemon = NULL;
379 * Modify some config options for peers 444 dave_daemon = NULL;
380 */ 445 alice_daemon = NULL;
381 cfg_alice = GNUNET_CONFIGURATION_create();
382 GNUNET_CONFIGURATION_load (cfg_alice, "test_gns_dht_alice.conf");
383 446
384 cfg_bob = GNUNET_CONFIGURATION_create(); 447 pg = GNUNET_TESTING_daemons_start (cfg, TEST_NUM_PEERS, TEST_NUM_CON,
385 GNUNET_CONFIGURATION_load (cfg_bob, "test_gns_dht_bob.conf"); 448 TEST_NUM_CON, TIMEOUT, NULL, NULL, &daemon_started, NULL,
449 &daemon_connected, NULL, NULL);
386 450
387 cfg_dave = GNUNET_CONFIGURATION_create();
388 GNUNET_CONFIGURATION_load (cfg_dave, "test_gns_dht_dave.conf");
389
390 GNUNET_CONFIGURATION_load (cfg_alice, "test_gns_dht_alice.conf");
391 GNUNET_CONFIGURATION_load (cfg_bob, "test_gns_dht_bob.conf");
392 GNUNET_CONFIGURATION_load (cfg_dave, "test_gns_dht_dave.conf");
393
394 /* Set up a task to end testing if peer start fails */ 451 /* Set up a task to end testing if peer start fails */
395 die_task = 452 die_task =
396 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, 453 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly,
@@ -402,8 +459,8 @@ run (void *cls, char *const *args, const char *cfgfile,
402 expected_connections = 2; 459 expected_connections = 2;
403 460
404 /* Start alice */ 461 /* Start alice */
405 d1 = GNUNET_TESTING_daemon_start(cfg_alice, TIMEOUT, GNUNET_NO, NULL, NULL, 0, 462 //d1 = GNUNET_TESTING_daemon_start(cfg_alice, TIMEOUT, GNUNET_NO, NULL, NULL, 0,
406 NULL, NULL, NULL, &alice_started, NULL); 463 // NULL, NULL, NULL, &alice_started, NULL);
407 464
408 465
409 466
@@ -418,7 +475,7 @@ check ()
418 /* Arguments for GNUNET_PROGRAM_run */ 475 /* Arguments for GNUNET_PROGRAM_run */
419 char *const argv[] = { "test-gns-twopeer", /* Name to give running binary */ 476 char *const argv[] = { "test-gns-twopeer", /* Name to give running binary */
420 "-c", 477 "-c",
421 "test_gns_twopeer.conf", /* Config file to use */ 478 "test_gns_dht_default.conf", /* Config file to use */
422#if VERBOSE 479#if VERBOSE
423 "-L", "DEBUG", 480 "-L", "DEBUG",
424#endif 481#endif