aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gns/gnunet-gns-proxy.c4
-rw-r--r--src/include/gnunet_namestore_service.h2
-rw-r--r--src/namestore/Makefile.am16
-rw-r--r--src/namestore/namestore_api.c20
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c212
5 files changed, 158 insertions, 96 deletions
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 25092dcf0..591dff04f 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1150,8 +1150,8 @@ curl_check_hdr (void *buffer, size_t size, size_t nmemb, void *cls)
1150 hdr_type, 1150 hdr_type,
1151 hdr_val); 1151 hdr_val);
1152 header = GNUNET_new (struct HttpResponseHeader); 1152 header = GNUNET_new (struct HttpResponseHeader);
1153 header->type = GNUNET_strndup (hdr_type, strlen (hdr_type)); 1153 header->type = GNUNET_strdup (hdr_type);
1154 header->value = GNUNET_strndup (hdr_val, strlen (hdr_val)); 1154 header->value = GNUNET_strdup (hdr_val);
1155 GNUNET_CONTAINER_DLL_insert (s5r->header_head, 1155 GNUNET_CONTAINER_DLL_insert (s5r->header_head,
1156 s5r->header_tail, 1156 s5r->header_tail,
1157 header); 1157 header);
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h
index 0add8852a..6d3c07f1d 100644
--- a/src/include/gnunet_namestore_service.h
+++ b/src/include/gnunet_namestore_service.h
@@ -193,7 +193,7 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h,
193 * Returns at most one result to the processor. 193 * Returns at most one result to the processor.
194 * 194 *
195 * @param h handle to the namestore 195 * @param h handle to the namestore
196 * @param zone public key of the zone to look up in, never NULL 196 * @param zone private key of the zone to look up in, never NULL
197 * @param value_zone public key of the target zone (value), never NULL 197 * @param value_zone public key of the target zone (value), never NULL
198 * @param error_cb function to call on error (i.e. disconnect) 198 * @param error_cb function to call on error (i.e. disconnect)
199 * the handle is afterwards invalid 199 * the handle is afterwards invalid
diff --git a/src/namestore/Makefile.am b/src/namestore/Makefile.am
index 4f710e116..a848d4b72 100644
--- a/src/namestore/Makefile.am
+++ b/src/namestore/Makefile.am
@@ -59,8 +59,8 @@ TESTING_TESTS = \
59 test_namestore_api_zone_iteration_specific_zone.nc \ 59 test_namestore_api_zone_iteration_specific_zone.nc \
60 test_namestore_api_zone_iteration_stop.nc \ 60 test_namestore_api_zone_iteration_stop.nc \
61 test_namestore_api_monitoring.nc \ 61 test_namestore_api_monitoring.nc \
62 test_namestore_api_monitoring_existing.nc 62 test_namestore_api_monitoring_existing.nc \
63# test_namestore_api_zone_to_name 63 test_namestore_api_zone_to_name
64endif 64endif
65 65
66# Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart 66# Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart
@@ -298,12 +298,12 @@ test_namestore_api_remove_not_existing_record_nc_LDADD = \
298 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \ 298 $(top_builddir)/src/gnsrecord/libgnunetgnsrecord.la \
299 libgnunetnamestore.la 299 libgnunetnamestore.la
300 300
301#test_namestore_api_zone_to_name_SOURCES = \ 301test_namestore_api_zone_to_name_SOURCES = \
302# test_namestore_api_zone_to_name.c 302 test_namestore_api_zone_to_name.c
303#test_namestore_api_zone_to_name_LDADD = \ 303test_namestore_api_zone_to_name_LDADD = \
304# $(top_builddir)/src/testing/libgnunettesting.la \ 304 $(top_builddir)/src/testing/libgnunettesting.la \
305# $(top_builddir)/src/util/libgnunetutil.la \ 305 $(top_builddir)/src/util/libgnunetutil.la \
306# libgnunetnamestore.la 306 libgnunetnamestore.la
307 307
308test_namestore_api_monitoring_nc_SOURCES = \ 308test_namestore_api_monitoring_nc_SOURCES = \
309 test_namestore_api_monitoring.c 309 test_namestore_api_monitoring.c
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 92068cc01..a187bd250 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -405,6 +405,7 @@ check_lookup_result (void *cls,
405 size_t name_len; 405 size_t name_len;
406 size_t rd_len; 406 size_t rd_len;
407 407
408 (void) cls;
408 rd_len = ntohs (msg->rd_len); 409 rd_len = ntohs (msg->rd_len);
409 msg_len = ntohs (msg->gns_header.header.size); 410 msg_len = ntohs (msg->gns_header.header.size);
410 name_len = ntohs (msg->name_len); 411 name_len = ntohs (msg->name_len);
@@ -517,6 +518,7 @@ check_record_result (void *cls,
517 size_t name_len; 518 size_t name_len;
518 size_t rd_len; 519 size_t rd_len;
519 520
521 (void) cls;
520 rd_len = ntohs (msg->rd_len); 522 rd_len = ntohs (msg->rd_len);
521 msg_len = ntohs (msg->gns_header.header.size); 523 msg_len = ntohs (msg->gns_header.header.size);
522 name_len = ntohs (msg->name_len); 524 name_len = ntohs (msg->name_len);
@@ -656,6 +658,7 @@ check_zone_to_name_response (void *cls,
656 size_t rd_ser_len; 658 size_t rd_ser_len;
657 const char *name_tmp; 659 const char *name_tmp;
658 660
661 (void) cls;
659 if (GNUNET_OK != ntohs (msg->res)) 662 if (GNUNET_OK != ntohs (msg->res))
660 return GNUNET_OK; 663 return GNUNET_OK;
661 name_len = ntohs (msg->name_len); 664 name_len = ntohs (msg->name_len);
@@ -771,6 +774,7 @@ mq_error_handler (void *cls,
771{ 774{
772 struct GNUNET_NAMESTORE_Handle *h = cls; 775 struct GNUNET_NAMESTORE_Handle *h = cls;
773 776
777 (void) error;
774 force_reconnect (h); 778 force_reconnect (h);
775} 779}
776 780
@@ -994,6 +998,7 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
994 size_t name_len; 998 size_t name_len;
995 uint32_t rid; 999 uint32_t rid;
996 struct RecordStoreMessage *msg; 1000 struct RecordStoreMessage *msg;
1001 ssize_t sret;
997 1002
998 name_len = strlen (label) + 1; 1003 name_len = strlen (label) + 1;
999 if (name_len > MAX_NAME_LEN) 1004 if (name_len > MAX_NAME_LEN)
@@ -1029,11 +1034,16 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h,
1029 label, 1034 label,
1030 name_len); 1035 name_len);
1031 rd_ser = &name_tmp[name_len]; 1036 rd_ser = &name_tmp[name_len];
1032 GNUNET_assert (rd_ser_len == 1037 sret = GNUNET_GNSRECORD_records_serialize (rd_count,
1033 GNUNET_GNSRECORD_records_serialize (rd_count, 1038 rd,
1034 rd, 1039 rd_ser_len,
1035 rd_ser_len, 1040 rd_ser);
1036 rd_ser)); 1041 if (0 > sret)
1042 {
1043 GNUNET_free (env);
1044 return NULL;
1045 }
1046 GNUNET_assert (rd_ser_len == (size_t) sret);
1037 LOG (GNUNET_ERROR_TYPE_DEBUG, 1047 LOG (GNUNET_ERROR_TYPE_DEBUG,
1038 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n", 1048 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1039 label, 1049 label,
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index ca33ee280..2bc7d34a3 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -37,28 +37,25 @@
37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 100)
38 38
39 39
40static struct GNUNET_NAMESTORE_Handle * nsh; 40static struct GNUNET_NAMESTORE_Handle *nsh;
41 41
42static struct GNUNET_SCHEDULER_Task * endbadly_task; 42static struct GNUNET_SCHEDULER_Task *endbadly_task;
43 43
44static struct GNUNET_CRYPTO_EcdsaPrivateKey * privkey; 44static struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
45 45
46static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey; 46static struct GNUNET_CRYPTO_EcdsaPublicKey pubkey;
47 47
48static struct GNUNET_TIME_Absolute expire; 48static struct GNUNET_CRYPTO_EcdsaPublicKey s_zone_value;
49
50static struct GNUNET_CRYPTO_ShortHashCode s_zone;
51
52static struct GNUNET_CRYPTO_ShortHashCode s_zone_value;
53 49
54static char * s_name; 50static char * s_name;
55 51
56static struct GNUNET_CRYPTO_EcdsaSignature *s_signature;
57
58static int res; 52static int res;
59 53
60static char *directory; 54static char *directory;
61 55
56static struct GNUNET_NAMESTORE_QueueEntry *qe;
57
58
62/** 59/**
63 * Re-establish the connection to the service. 60 * Re-establish the connection to the service.
64 * 61 *
@@ -67,12 +64,8 @@ static char *directory;
67static void 64static void
68endbadly (void *cls) 65endbadly (void *cls)
69{ 66{
70 if (nsh != NULL) 67 (void) cls;
71 GNUNET_NAMESTORE_disconnect (nsh); 68 GNUNET_SCHEDULER_shutdown ();
72 nsh = NULL;
73 if (privkey != NULL)
74 GNUNET_free (privkey);
75 privkey = NULL;
76 res = 1; 69 res = 1;
77} 70}
78 71
@@ -80,50 +73,69 @@ endbadly (void *cls)
80static void 73static void
81end (void *cls) 74end (void *cls)
82{ 75{
83 if (endbadly_task != NULL) 76 if (NULL != qe)
77 {
78 GNUNET_NAMESTORE_cancel (qe);
79 qe = NULL;
80 }
81 if (NULL != endbadly_task)
84 { 82 {
85 GNUNET_SCHEDULER_cancel (endbadly_task); 83 GNUNET_SCHEDULER_cancel (endbadly_task);
86 endbadly_task = NULL; 84 endbadly_task = NULL;
87 } 85 }
88 if (privkey != NULL) 86 if (NULL != privkey)
87 {
89 GNUNET_free (privkey); 88 GNUNET_free (privkey);
90 privkey = NULL; 89 privkey = NULL;
91 if (nsh != NULL) 90 }
91 if (NULL != nsh)
92 {
92 GNUNET_NAMESTORE_disconnect (nsh); 93 GNUNET_NAMESTORE_disconnect (nsh);
93 nsh = NULL; 94 nsh = NULL;
95 }
94} 96}
95 97
96 98
97static void 99static void
98zone_to_name_proc (void *cls, 100zone_to_name_proc (void *cls,
99 const struct GNUNET_CRYPTO_EcdsaPublicKey *zone_key, 101 const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
100 struct GNUNET_TIME_Absolute expire,
101 const char *n, 102 const char *n,
102 unsigned int rd_count, 103 unsigned int rd_count,
103 const struct GNUNET_GNSRECORD_Data *rd, 104 const struct GNUNET_GNSRECORD_Data *rd)
104 const struct GNUNET_CRYPTO_EcdsaSignature *signature)
105{ 105{
106 int fail = GNUNET_NO; 106 int fail = GNUNET_NO;
107 107
108 if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) 108 qe = NULL;
109 if ( (NULL == zone_key) &&
110 (NULL == n) &&
111 (0 == rd_count) &&
112 (NULL == rd) )
109 { 113 {
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
115 "No result found\n");
111 res = 1; 116 res = 1;
112 } 117 }
113 else 118 else
114 { 119 {
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found: `%s'\n", n); 120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
116 if ((n == NULL) || (0 != strcmp(n, s_name))) 121 "Result found: `%s'\n",
122 n);
123 if ( (NULL == n) ||
124 (0 != strcmp (n,
125 s_name)))
117 { 126 {
118 fail = GNUNET_YES; 127 fail = GNUNET_YES;
119 GNUNET_break (0); 128 GNUNET_break (0);
120 } 129 }
121 if (rd_count != 1) 130 if (1 != rd_count)
122 { 131 {
123 fail = GNUNET_YES; 132 fail = GNUNET_YES;
124 GNUNET_break (0); 133 GNUNET_break (0);
125 } 134 }
126 if ((zone_key == NULL) || (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)))) 135 if ( (NULL == zone_key) ||
136 (0 != memcmp (zone_key,
137 privkey,
138 sizeof (struct GNUNET_CRYPTO_EcdsaPrivateKey))))
127 { 139 {
128 fail = GNUNET_YES; 140 fail = GNUNET_YES;
129 GNUNET_break (0); 141 GNUNET_break (0);
@@ -133,29 +145,54 @@ zone_to_name_proc (void *cls,
133 else 145 else
134 res = 1; 146 res = 1;
135 } 147 }
136 GNUNET_SCHEDULER_add_now(&end, NULL); 148 GNUNET_SCHEDULER_add_now (&end,
149 NULL);
137} 150}
138 151
139 152
140static void 153static void
141put_cont (void *cls, int32_t success, const char *emsg) 154error_cb (void *cls)
155{
156 (void) cls;
157 qe = NULL;
158 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
159 "Not found!\n");
160 GNUNET_SCHEDULER_shutdown ();
161 res = 2;
162}
163
164
165static void
166put_cont (void *cls,
167 int32_t success,
168 const char *emsg)
142{ 169{
143 char *name = cls; 170 char *name = cls;
144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL"); 171
172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Name store added record for `%s': %s\n",
174 name,
175 (success == GNUNET_OK) ? "SUCCESS" : emsg);
145 if (success == GNUNET_OK) 176 if (success == GNUNET_OK)
146 { 177 {
147 res = 0; 178 res = 0;
148 179
149 /* create initial record */ 180 qe = GNUNET_NAMESTORE_zone_to_name (nsh,
150 GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); 181 privkey,
151 182 &s_zone_value,
183 &error_cb,
184 NULL,
185 &zone_to_name_proc,
186 NULL);
152 } 187 }
153 else 188 else
154 { 189 {
155 res = 1; 190 res = 1;
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
157 "Failed to put records for name `%s'\n", name); 192 "Failed to put records for name `%s'\n",
158 GNUNET_SCHEDULER_add_now(&end, NULL); 193 name);
194 GNUNET_SCHEDULER_add_now (&end,
195 NULL);
159 } 196 }
160} 197}
161 198
@@ -165,57 +202,72 @@ run (void *cls,
165 const struct GNUNET_CONFIGURATION_Handle *cfg, 202 const struct GNUNET_CONFIGURATION_Handle *cfg,
166 struct GNUNET_TESTING_Peer *peer) 203 struct GNUNET_TESTING_Peer *peer)
167{ 204{
168 struct GNUNET_TIME_Absolute et; 205 (void) cls;
169 206 (void) peer;
170 directory = NULL; 207 directory = NULL;
171 GNUNET_CONFIGURATION_get_value_string(cfg, "PATHS", "GNUNET_TEST_HOME", &directory); 208 GNUNET_assert (GNUNET_OK ==
209 GNUNET_CONFIGURATION_get_value_string (cfg,
210 "PATHS",
211 "GNUNET_TEST_HOME",
212 &directory));
172 GNUNET_DISK_directory_remove (directory); 213 GNUNET_DISK_directory_remove (directory);
173 214
174 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 215 endbadly_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
216 &endbadly,
217 NULL);
218 GNUNET_SCHEDULER_add_shutdown (&end,
219 NULL);
175 GNUNET_asprintf (&s_name, "dummy"); 220 GNUNET_asprintf (&s_name, "dummy");
176 /* load privat key */ 221 /* load privat key */
177 char *hostkey_file; 222 {
178 GNUNET_asprintf(&hostkey_file,"zonefiles%s%s",DIR_SEPARATOR_STR, 223 char *zonekey_file;
179 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey"); 224
180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_asprintf (&zonekey_file,
181 "Using zonekey file `%s'\n", 226 "zonefiles%s%s",
182 hostkey_file); 227 DIR_SEPARATOR_STR,
183 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file(hostkey_file); 228 "N0UJMP015AFUNR2BTNM3FKPBLG38913BL8IDMCO2H0A1LIB81960.zkey");
184 GNUNET_free (hostkey_file); 229 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
185 GNUNET_assert (privkey != NULL); 230 "Using zonekey file `%s'\n",
231 zonekey_file);
232 privkey = GNUNET_CRYPTO_ecdsa_key_create_from_file (zonekey_file);
233 GNUNET_free (zonekey_file);
234 }
235 GNUNET_assert (NULL != privkey);
186 /* get public key */ 236 /* get public key */
187 GNUNET_CRYPTO_ecdsa_key_get_public(privkey, &pubkey); 237 GNUNET_CRYPTO_ecdsa_key_get_public (privkey,
238 &pubkey);
188 239
189 /* zone hash */ 240 GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK,
190 GNUNET_CRYPTO_short_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey), &s_zone); 241 &s_zone_value,
191 GNUNET_CRYPTO_short_hash (s_name, strlen (s_name) + 1, &s_zone_value); 242 sizeof (s_zone_value));
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 243 {
193 "Using PKEY `%s' \n", 244 struct GNUNET_GNSRECORD_Data rd;
194 GNUNET_NAMESTORE_short_h2s (&s_zone_value)); 245
195 246 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us;
196 struct GNUNET_GNSRECORD_Data rd; 247 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY;
197 rd.expiration_time = GNUNET_TIME_absolute_get().abs_value_us; 248 rd.data_size = sizeof (s_zone_value);
198 rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; 249 rd.data = &s_zone_value;
199 rd.data_size = sizeof (struct GNUNET_CRYPTO_ShortHashCode); 250 rd.flags = 0;
200 rd.data = GNUNET_malloc(sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 251
201 rd.flags = 0; 252 nsh = GNUNET_NAMESTORE_connect (cfg);
202 GNUNET_memcpy ((char *) rd.data, &s_zone_value, sizeof (struct GNUNET_CRYPTO_ShortHashCode)); 253 GNUNET_break (NULL != nsh);
203 nsh = GNUNET_NAMESTORE_connect (cfg); 254 GNUNET_NAMESTORE_records_store (nsh,
204 GNUNET_break (NULL != nsh); 255 privkey,
205 256 s_name,
206 expire = GNUNET_TIME_absolute_get (); 257 1,
207 et.abs_value_us = rd.expiration_time; 258 &rd,
208 s_signature = GNUNET_NAMESTORE_create_signature(privkey, et, s_name, &rd, 1); 259 &put_cont,
209 GNUNET_NAMESTORE_record_put(nsh, &pubkey, s_name, expire, 1, &rd, s_signature, put_cont, NULL); 260 NULL);
210 261 }
211 GNUNET_free ((void *) rd.data);
212} 262}
213 263
214 264
215
216int 265int
217main (int argc, char *argv[]) 266main (int argc,
267 char *argv[])
218{ 268{
269 (void) argc;
270 (void) argv;
219 res = 1; 271 res = 1;
220 if (0 != 272 if (0 !=
221 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name", 273 GNUNET_TESTING_peer_run ("test-namestore-api-zone-to-name",
@@ -227,8 +279,8 @@ main (int argc, char *argv[])
227 } 279 }
228 if (NULL != directory) 280 if (NULL != directory)
229 { 281 {
230 GNUNET_DISK_directory_remove (directory); 282 GNUNET_DISK_directory_remove (directory);
231 GNUNET_free (directory); 283 GNUNET_free (directory);
232 } 284 }
233 return res; 285 return res;
234} 286}