aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-12 13:12:37 +0000
committerMartin Schanzenbach <mschanzenbach@posteo.de>2012-03-12 13:12:37 +0000
commit00eda546242086cee3dc920e2f82a7b5be3e0999 (patch)
tree16675854d0259c061b1c40056f6c79655cee2b9b /src
parentc5c2121206bf094d18bff9d7835a01c39c0a8348 (diff)
downloadgnunet-00eda546242086cee3dc920e2f82a7b5be3e0999.tar.gz
gnunet-00eda546242086cee3dc920e2f82a7b5be3e0999.zip
-bugfixes, tests
Diffstat (limited to 'src')
-rw-r--r--src/gns/Makefile.am29
-rw-r--r--src/gns/gns_api.c2
-rw-r--r--src/gns/gnunet-service-gns.c2
-rw-r--r--src/gns/plugin_block_gns.c24
-rw-r--r--src/gns/test_gns_dht_delegated_lookup.c75
-rw-r--r--src/namestore/namestore_common.c2
6 files changed, 91 insertions, 43 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am
index 9aafedf16..08da0a8e2 100644
--- a/src/gns/Makefile.am
+++ b/src/gns/Makefile.am
@@ -30,7 +30,8 @@ check_PROGRAMS = \
30 test_gns_simple_shorten \ 30 test_gns_simple_shorten \
31 test_gns_simple_get_authority \ 31 test_gns_simple_get_authority \
32 test_gns_simple_lookup \ 32 test_gns_simple_lookup \
33 test_gns_simple_delegated_lookup 33 test_gns_simple_delegated_lookup \
34 test_gns_dht_delegated_lookup
34 35
35 36
36# test_gns_simple_lookup 37# test_gns_simple_lookup
@@ -78,18 +79,20 @@ test_gns_simple_delegated_lookup_DEPENDENCIES = \
78 $(top_builddir)/src/gns/libgnunetgns.la \ 79 $(top_builddir)/src/gns/libgnunetgns.la \
79 $(top_builddir)/src/testing/libgnunettesting.la 80 $(top_builddir)/src/testing/libgnunettesting.la
80 81
81#test_gns_dht_delegated_lookup_SOURCES = \ 82test_gns_dht_delegated_lookup_SOURCES = \
82# test_gns_dht_delegated_lookup.c 83 test_gns_dht_delegated_lookup.c
83#test_gns_dht_delegated_lookup_LDADD = \ 84test_gns_dht_delegated_lookup_LDADD = \
84# $(top_builddir)/src/util/libgnunetutil.la \ 85 $(top_builddir)/src/util/libgnunetutil.la \
85# $(top_builddir)/src/namestore/libgnunetnamestore.la \ 86 $(top_builddir)/src/namestore/libgnunetnamestore.la \
86# $(top_builddir)/src/dht/libgnunetdht.la \ 87 $(top_builddir)/src/dht/libgnunetdht.la \
87# $(top_builddir)/src/testing/libgnunettesting.la 88 $(top_builddir)/src/gns/libgnunetgns.la \
88#test_gns_dht_delegated_lookup_DEPENDENCIES = \ 89 $(top_builddir)/src/testing/libgnunettesting.la
89# $(top_builddir)/src/util/libgnunetutil.la \ 90test_gns_dht_delegated_lookup_DEPENDENCIES = \
90# $(top_builddir)/src/namestore/libgnunetnamestore.la \ 91 $(top_builddir)/src/util/libgnunetutil.la \
91# $(top_builddir)/src/dht/libgnunetdht.la \ 92 $(top_builddir)/src/namestore/libgnunetnamestore.la \
92# $(top_builddir)/src/testing/libgnunettesting.la 93 $(top_builddir)/src/dht/libgnunetdht.la \
94 $(top_builddir)/src/gns/libgnunetgns.la \
95 $(top_builddir)/src/testing/libgnunettesting.la
93 96
94test_gns_simple_shorten_SOURCES = \ 97test_gns_simple_shorten_SOURCES = \
95 test_gns_simple_shorten.c 98 test_gns_simple_shorten.c
diff --git a/src/gns/gns_api.c b/src/gns/gns_api.c
index d15f1908e..d6709a96e 100644
--- a/src/gns/gns_api.c
+++ b/src/gns/gns_api.c
@@ -636,7 +636,7 @@ GNUNET_GNS_lookup (struct GNUNET_GNS_Handle *handle,
636 } 636 }
637 637
638 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1; 638 msize = sizeof (struct GNUNET_GNS_ClientLookupMessage) + strlen(name) + 1;
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to shorten %s in GNS\n", name); 639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to lookup %s in GNS\n", name);
640 640
641 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry)); 641 qe = GNUNET_malloc(sizeof (struct GNUNET_GNS_QueueEntry));
642 qe->gns_handle = handle; 642 qe->gns_handle = handle;
diff --git a/src/gns/gnunet-service-gns.c b/src/gns/gnunet-service-gns.c
index 09054d2b9..480d6bea9 100644
--- a/src/gns/gnunet-service-gns.c
+++ b/src/gns/gnunet-service-gns.c
@@ -863,6 +863,8 @@ process_delegation_result_dht(void* cls,
863 int rd_size; 863 int rd_size;
864 GNUNET_HashCode zone, name_hash; 864 GNUNET_HashCode zone, name_hash;
865 865
866 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Got DHT result\n");
867
866 if (data == NULL) 868 if (data == NULL)
867 return; 869 return;
868 870
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c
index 4c8ab3eb9..329088280 100644
--- a/src/gns/plugin_block_gns.c
+++ b/src/gns/plugin_block_gns.c
@@ -75,6 +75,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
75 uint32_t record_xquery; 75 uint32_t record_xquery;
76 unsigned int record_match; 76 unsigned int record_match;
77 77
78 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
79 "BLOCK_TEST\n");
80
78 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) 81 if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD)
79 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; 82 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
80 if (reply_block_size == 0) 83 if (reply_block_size == 0)
@@ -90,6 +93,15 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
90 93
91 GNUNET_CRYPTO_hash_xor(&pkey_hash, &name_hash, &query_key); 94 GNUNET_CRYPTO_hash_xor(&pkey_hash, &name_hash, &query_key);
92 95
96 struct GNUNET_CRYPTO_HashAsciiEncoded xor_exp;
97 struct GNUNET_CRYPTO_HashAsciiEncoded xor_got;
98 GNUNET_CRYPTO_hash_to_enc (&query_key, &xor_exp);
99 GNUNET_CRYPTO_hash_to_enc (query, &xor_got);
100
101 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
102 "BLOCK_TEST for %s got %s expected %s\n",
103 name, (char*) &xor_got, (char*) &xor_exp);
104
93 /* Check query key against public key */ 105 /* Check query key against public key */
94 if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key)) 106 if (0 != GNUNET_CRYPTO_hash_cmp(query, &query_key))
95 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 107 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
@@ -124,6 +136,9 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
124 { 136 {
125 137
126 exp = GNUNET_TIME_absolute_min (exp, rd[i].expiration); 138 exp = GNUNET_TIME_absolute_min (exp, rd[i].expiration);
139
140 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
141 "Got record of size %d\n", rd[i].data_size);
127 142
128 if ((record_xquery != 0) 143 if ((record_xquery != 0)
129 && (rd[i].record_type == record_xquery)) 144 && (rd[i].record_type == record_xquery))
@@ -131,6 +146,10 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
131 record_match++; 146 record_match++;
132 } 147 }
133 } 148 }
149
150 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
151 "Verifying signature of %d records for name %s\n",
152 rd_count, name);
134 153
135 if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key, 154 if (GNUNET_OK != GNUNET_NAMESTORE_verify_signature (&nrb->public_key,
136 exp, 155 exp,
@@ -144,9 +163,12 @@ block_plugin_gns_evaluate (void *cls, enum GNUNET_BLOCK_Type type,
144 } 163 }
145 } 164 }
146 165
147 //No record matches query
148 if ((record_xquery != 0) && (record_match == 0)) 166 if ((record_xquery != 0) && (record_match == 0))
167 {
168 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
169 "No record matches query!\n");
149 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; 170 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
171 }
150 172
151 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n"); 173 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Records match\n");
152 174
diff --git a/src/gns/test_gns_dht_delegated_lookup.c b/src/gns/test_gns_dht_delegated_lookup.c
index dc73c7b58..6fc4a42bb 100644
--- a/src/gns/test_gns_dht_delegated_lookup.c
+++ b/src/gns/test_gns_dht_delegated_lookup.c
@@ -83,6 +83,8 @@ static int ok;
83 83
84static struct GNUNET_NAMESTORE_Handle *namestore_handle; 84static struct GNUNET_NAMESTORE_Handle *namestore_handle;
85 85
86static struct GNUNET_GNS_Handle *gns_handle;
87
86static struct GNUNET_DHT_Handle *dht_handle; 88static struct GNUNET_DHT_Handle *dht_handle;
87 89
88const struct GNUNET_CONFIGURATION_Handle *cfg; 90const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -108,42 +110,39 @@ shutdown_callback (void *cls, const char *emsg)
108 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); 110 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok);
109} 111}
110 112
111/** 113
112 * Function scheduled to be run on the successful start of services
113 * tries to look up the dns record for TEST_DOMAIN
114 */
115static void 114static void
116finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 115on_lookup_result(void *cls, uint32_t rd_count,
116 const struct GNUNET_NAMESTORE_RecordData *rd)
117{ 117{
118 struct hostent *he;
119 struct in_addr a; 118 struct in_addr a;
119 int i;
120 char* addr; 120 char* addr;
121 121
122 GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); 122 if (rd_count == 0)
123 GNUNET_DHT_disconnect(dht_handle);
124
125 he = gethostbyname (TEST_DOMAIN);
126
127 if (!he)
128 { 123 {
129 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
130 "gethostbyname failed, rp_filtering?\n"); 125 "Lookup failed, rp_filtering?\n");
131 ok = 2; 126 ok = 2;
132 } 127 }
133 else 128 else
134 { 129 {
135 ok = 1; 130 ok = 1;
136 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name); 131 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
137 while (*he->h_addr_list) 132 for (i=0; i<rd_count; i++)
138 { 133 {
139 memcpy(&a, *he->h_addr_list++, sizeof(a)); 134 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
140 addr = inet_ntoa(a); 135 if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
141 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
142 if (0 == strcmp(addr, TEST_IP))
143 { 136 {
144 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 137 memcpy(&a, rd[i].data, sizeof(a));
138 addr = inet_ntoa(a);
139 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
140 if (0 == strcmp(addr, TEST_IP))
141 {
142 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
145 "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); 143 "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
146 ok = 0; 144 ok = 0;
145 }
147 } 146 }
148 else 147 else
149 { 148 {
@@ -156,6 +155,28 @@ finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 GNUNET_YES, GNUNET_NO); 155 GNUNET_YES, GNUNET_NO);
157} 156}
158 157
158
159/**
160 * Function scheduled to be run on the successful start of services
161 * tries to look up the dns record for TEST_DOMAIN
162 */
163static void
164commence_testing (void *cls, int32_t success, const char *emsg)
165{
166 GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
167
168 gns_handle = GNUNET_GNS_connect(cfg);
169
170 if (NULL == gns_handle)
171 {
172 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
173 "Failed to connect to GNS!\n");
174 }
175
176 GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
177 &on_lookup_result, TEST_DOMAIN);
178}
179
159/** 180/**
160 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut 181 * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut
161 * down the peers without freeing memory associated with GET request. 182 * down the peers without freeing memory associated with GET request.
@@ -214,7 +235,7 @@ put_dht(void *cls, int32_t success, const char *emsg)
214 nrb->public_key = bob_pkey; 235 nrb->public_key = bob_pkey;
215 nrb->rd_count = htonl(1); 236 nrb->rd_count = htonl(1);
216 memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1); 237 memset(&nrb[1], 0, strlen(TEST_RECORD_NAME) + 1);
217 memcpy(&nrb[1], TEST_RECORD_NAME, strlen(TEST_RECORD_NAME)); 238 strcpy(&nrb[1], TEST_RECORD_NAME);
218 nrb_data = (char*)&nrb[1]; 239 nrb_data = (char*)&nrb[1];
219 nrb_data += strlen(TEST_RECORD_NAME) + 1; 240 nrb_data += strlen(TEST_RECORD_NAME) + 1;
220 241
@@ -247,7 +268,7 @@ put_dht(void *cls, int32_t success, const char *emsg)
247 NULL, 268 NULL,
248 NULL); 269 NULL);
249 GNUNET_free (nrb); 270 GNUNET_free (nrb);
250 GNUNET_SCHEDULER_add_delayed(TIMEOUT, &finish_testing, NULL); 271 GNUNET_SCHEDULER_add_delayed(TIMEOUT, &commence_testing, NULL);
251} 272}
252 273
253static void 274static void
@@ -345,7 +366,7 @@ check ()
345 int ret; 366 int ret;
346 367
347 /* Arguments for GNUNET_PROGRAM_run */ 368 /* Arguments for GNUNET_PROGRAM_run */
348 char *const argv[] = { "test-gns-simple-lookup", /* Name to give running binary */ 369 char *const argv[] = { "test-gns-dht-delegated-lookup", /* Name to give running binary */
349 "-c", 370 "-c",
350 "test_gns_simple_lookup.conf", /* Config file to use */ 371 "test_gns_simple_lookup.conf", /* Config file to use */
351#if VERBOSE 372#if VERBOSE
@@ -359,12 +380,12 @@ check ()
359 /* Run the run function as a new program */ 380 /* Run the run function as a new program */
360 ret = 381 ret =
361 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv, 382 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, argv,
362 "test-gns-simple-lookup", "nohelp", options, &run, 383 "test-gns-dht-delegated-lookup", "nohelp", options, &run,
363 &ok); 384 &ok);
364 if (ret != GNUNET_OK) 385 if (ret != GNUNET_OK)
365 { 386 {
366 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 387 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
367 "`test-gns-simple-lookup': Failed with error code %d\n", ret); 388 "`test-gns-dht-delegated-lookup': Failed with error code %d\n", ret);
368 } 389 }
369 return ok; 390 return ok;
370} 391}
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c
index b8236edf0..72a2625ae 100644
--- a/src/namestore/namestore_common.c
+++ b/src/namestore/namestore_common.c
@@ -86,7 +86,7 @@ GNUNET_NAMESTORE_records_get_size (unsigned int rd_count,
86 ret = sizeof (struct NetworkRecord) * rd_count; 86 ret = sizeof (struct NetworkRecord) * rd_count;
87 for (i=0;i<rd_count;i++) 87 for (i=0;i<rd_count;i++)
88 { 88 {
89 GNUNET_assert (ret + rd[i].data_size >= ret); 89 GNUNET_assert ((ret + rd[i].data_size) >= ret);
90 ret += rd[i].data_size; 90 ret += rd[i].data_size;
91 } 91 }
92 return ret; 92 return ret;