aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-05 17:31:35 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-05 17:31:35 +0000
commit65ffaca5903a9cb31050b8bd378f1bf4647b2549 (patch)
tree157328b1b4c3310b8ce2549565baf08a3ec973e8 /src
parent61e42c16dc624c29cd343c3630314d058779ea0a (diff)
downloadgnunet-65ffaca5903a9cb31050b8bd378f1bf4647b2549.tar.gz
gnunet-65ffaca5903a9cb31050b8bd378f1bf4647b2549.zip
- changes
Diffstat (limited to 'src')
-rw-r--r--src/namestore/gnunet-service-namestore.c20
-rw-r--r--src/namestore/namestore_api.c54
-rw-r--r--src/namestore/test_namestore_api.conf2
-rw-r--r--src/namestore/test_namestore_api_create_update.c2
-rw-r--r--src/namestore/test_namestore_api_lookup_specific_type.c2
-rw-r--r--src/namestore/test_namestore_api_zone_to_name.c86
6 files changed, 136 insertions, 30 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index a3f77dabb..40f3c477a 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -1086,7 +1086,7 @@ handle_zone_to_name_it (void *cls,
1086 int32_t contains_sig = 0; 1086 int32_t contains_sig = 0;
1087 size_t msg_size = 0; 1087 size_t msg_size = 0;
1088 1088
1089 char *rd_ser; 1089 char *rd_ser = NULL;
1090 char *name_tmp; 1090 char *name_tmp;
1091 char *rd_tmp; 1091 char *rd_tmp;
1092 char *sig_tmp; 1092 char *sig_tmp;
@@ -1094,7 +1094,7 @@ handle_zone_to_name_it (void *cls,
1094 if ((zone_key != NULL) && (name != NULL)) 1094 if ((zone_key != NULL) && (name != NULL))
1095 { 1095 {
1096 /* found result */ 1096 /* found result */
1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name ist \n"); 1097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Found results: name is `%s', has %u records\n", name, rd_count);
1098 res = GNUNET_YES; 1098 res = GNUNET_YES;
1099 name_len = strlen (name); 1099 name_len = strlen (name);
1100 } 1100 }
@@ -1109,7 +1109,7 @@ handle_zone_to_name_it (void *cls,
1109 if (rd_count > 0) 1109 if (rd_count > 0)
1110 { 1110 {
1111 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd); 1111 rd_ser_len = GNUNET_NAMESTORE_records_get_size (rd_count, rd);
1112 char rd_ser[rd_ser_len]; 1112 rd_ser = GNUNET_malloc (rd_ser_len);
1113 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser); 1113 GNUNET_NAMESTORE_records_serialize(rd_count, rd, rd_ser_len, rd_ser);
1114 } 1114 }
1115 else 1115 else
@@ -1120,6 +1120,8 @@ handle_zone_to_name_it (void *cls,
1120 else 1120 else
1121 contains_sig = GNUNET_NO; 1121 contains_sig = GNUNET_NO;
1122 1122
1123
1124
1123 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature); 1125 msg_size = sizeof (struct ZoneToNameResponseMessage) + name_len + rd_ser_len + contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature);
1124 ztnr_msg = GNUNET_malloc (msg_size); 1126 ztnr_msg = GNUNET_malloc (msg_size);
1125 1127
@@ -1136,17 +1138,21 @@ handle_zone_to_name_it (void *cls,
1136 ztnr_msg->rd_count = htons (rd_count); 1138 ztnr_msg->rd_count = htons (rd_count);
1137 ztnr_msg->name_len = htons (name_len); 1139 ztnr_msg->name_len = htons (name_len);
1138 ztnr_msg->contains_sig = htons (contains_sig); 1140 ztnr_msg->contains_sig = htons (contains_sig);
1141 ztnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
1139 if (zone_key != NULL) 1142 if (zone_key != NULL)
1140 ztnr_msg->zone_key = *zone_key; 1143 ztnr_msg->zone_key = *zone_key;
1141 else 1144 else
1142 memset (&ztnr_msg->zone_key, '\0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1145 memset (&ztnr_msg->zone_key, '\0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1143 1146
1144 memcpy (&name_tmp, name, name_len); 1147 memcpy (name_tmp, name, name_len);
1145 memcpy (&rd_tmp, &rd_ser, rd_ser_len); 1148
1146 memcpy (&sig_tmp, signature, contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature)); 1149 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name is `%s', has %u records, rd ser len %u msg_size %u\n", name, rd_count, rd_ser_len, msg_size);
1150 memcpy (rd_tmp, rd_ser, rd_ser_len);
1151 memcpy (sig_tmp, signature, contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature));
1147 1152
1148 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, (const struct GNUNET_MessageHeader *) ztnr_msg, GNUNET_NO); 1153 GNUNET_SERVER_notification_context_unicast (snc, ztn_ctx->nc->client, (const struct GNUNET_MessageHeader *) ztnr_msg, GNUNET_NO);
1149 GNUNET_free (ztnr_msg); 1154 GNUNET_free (ztnr_msg);
1155 GNUNET_free_non_null (rd_ser);
1150} 1156}
1151 1157
1152 1158
@@ -1192,7 +1198,7 @@ static void handle_zone_to_name (void *cls,
1192 ztn_ctx.nc = nc; 1198 ztn_ctx.nc = nc;
1193 1199
1194 char * z_tmp = strdup (GNUNET_h2s (&ztn_msg->zone)); 1200 char * z_tmp = strdup (GNUNET_h2s (&ztn_msg->zone));
1195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s''\n", 1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up name for zone `%s' in zone `%s'\n",
1196 z_tmp, 1202 z_tmp,
1197 GNUNET_h2s (&ztn_msg->value_zone)); 1203 GNUNET_h2s (&ztn_msg->value_zone));
1198 GNUNET_free (z_tmp); 1204 GNUNET_free (z_tmp);
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 10c4132f6..9634b6d4d 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -478,20 +478,54 @@ handle_zone_to_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
478 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 478 struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
479 int res = ntohs (msg->res); 479 int res = ntohs (msg->res);
480 480
481 switch (res) { 481 struct GNUNET_TIME_Absolute expire;
482 case GNUNET_SYSERR: 482 size_t name_len;
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n"); 483 size_t rd_ser_len;
484 if (qe->proc != NULL) 484 unsigned int rd_count;
485 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 0, NULL, NULL); 485 int have_signature;
486 break; 486
487 case GNUNET_NO: 487 char * name_tmp;
488 char * rd_tmp;
489 struct GNUNET_CRYPTO_RsaSignature* sig_tmp;
490
491 if (res == GNUNET_SYSERR)
492 {
493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "An error occured during zone to name operation\n");
494 if (qe->proc != NULL)
495 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 0, NULL, NULL);
496 }
497 else if (res == GNUNET_NO)
498 {
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n"); 499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has no result for zone to name mapping \n");
489 if (qe->proc != NULL) 500 if (qe->proc != NULL)
490 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 0, NULL, NULL); 501 qe->proc (qe->proc_cls, NULL, GNUNET_TIME_absolute_get_zero(), NULL, 0, NULL, NULL);
491 break;
492 default:
493 break;
494 } 502 }
503 else if (res == GNUNET_YES)
504 {
505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Namestore has result for zone to name mapping \n");
506
507 name_len = ntohs (msg->name_len);
508 rd_count = ntohs (msg->rd_count);
509 rd_ser_len = ntohs (msg->rd_len);
510 have_signature = ntohl (msg->contains_sig);
511 expire = GNUNET_TIME_absolute_ntoh(msg->expire);
512
513 name_tmp = (char *) &msg[1];
514 rd_tmp = &name_tmp[name_len];
515 if (have_signature == GNUNET_YES)
516 sig_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[rd_ser_len];
517 else
518 sig_tmp = NULL;
519
520 struct GNUNET_NAMESTORE_RecordData rd[rd_count];
521 GNUNET_NAMESTORE_records_deserialize(rd_ser_len, rd_tmp, rd_count, rd);
522
523 if (qe->proc != NULL)
524 qe->proc (qe->proc_cls, &msg->zone_key, expire, name_tmp, rd_count, rd, sig_tmp);
525
526 }
527 else
528 GNUNET_break_op (0);
495 529
496 /* Operation done, remove */ 530 /* Operation done, remove */
497 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); 531 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf
index c437b414a..f4cd32dbd 100644
--- a/src/namestore/test_namestore_api.conf
+++ b/src/namestore/test_namestore_api.conf
@@ -4,7 +4,7 @@ DEFAULTSERVICES = namestore
4UNIXPATH = /tmp/gnunet-p1-service-arm.sock 4UNIXPATH = /tmp/gnunet-p1-service-arm.sock
5 5
6[namestore] 6[namestore]
7PREFIX = valgrind --leak-check=full 7#PREFIX = valgrind --leak-check=full
8AUTOSTART = YES 8AUTOSTART = YES
9UNIXPATH = /tmp/gnunet-service-namestore.sock 9UNIXPATH = /tmp/gnunet-service-namestore.sock
10UNIX_MATCH_UID = YES 10UNIX_MATCH_UID = YES
diff --git a/src/namestore/test_namestore_api_create_update.c b/src/namestore/test_namestore_api_create_update.c
index 737c64a3d..ca2cde10c 100644
--- a/src/namestore/test_namestore_api_create_update.c
+++ b/src/namestore/test_namestore_api_create_update.c
@@ -325,7 +325,7 @@ create_updated_cont (void *cls, int32_t success, const char *emsg)
325 if (success == GNUNET_NO) 325 if (success == GNUNET_NO)
326 { 326 {
327 res = 0; 327 res = 0;
328 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updated record for name `%s'\n", name); 328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updated record for name `%s'\n", name);
329 } 329 }
330 else if (success == GNUNET_OK) 330 else if (success == GNUNET_OK)
331 { 331 {
diff --git a/src/namestore/test_namestore_api_lookup_specific_type.c b/src/namestore/test_namestore_api_lookup_specific_type.c
index 8ffa9ca2c..3f2098858 100644
--- a/src/namestore/test_namestore_api_lookup_specific_type.c
+++ b/src/namestore/test_namestore_api_lookup_specific_type.c
@@ -258,7 +258,7 @@ put_cont (void *cls, int32_t success, const char *emsg)
258 if (success == GNUNET_OK) 258 if (success == GNUNET_OK)
259 { 259 {
260 res = 0; 260 res = 0;
261 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Looking up non-existing record type %u for name `%s'\n", TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, name); 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up non-existing record type %u for name `%s'\n", TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, name);
262 GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, &name_lookup_non_existing_record_type, NULL); 262 GNUNET_NAMESTORE_lookup_record (nsh, &s_zone, name, TEST_RECORD_LOOKUP_TYPE_NOT_EXISTING, &name_lookup_non_existing_record_type, NULL);
263 } 263 }
264 else 264 else
diff --git a/src/namestore/test_namestore_api_zone_to_name.c b/src/namestore/test_namestore_api_zone_to_name.c
index 387d58272..bd03987d5 100644
--- a/src/namestore/test_namestore_api_zone_to_name.c
+++ b/src/namestore/test_namestore_api_zone_to_name.c
@@ -29,6 +29,11 @@
29 29
30#define VERBOSE GNUNET_NO 30#define VERBOSE GNUNET_NO
31 31
32#define RECORDS 5
33#define TEST_RECORD_TYPE 1234
34#define TEST_RECORD_DATALEN 123
35#define TEST_RECORD_DATA 'a'
36
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33 38
34static struct GNUNET_NAMESTORE_Handle * nsh; 39static struct GNUNET_NAMESTORE_Handle * nsh;
@@ -39,9 +44,16 @@ static struct GNUNET_OS_Process *arm;
39static struct GNUNET_CRYPTO_RsaPrivateKey * privkey; 44static struct GNUNET_CRYPTO_RsaPrivateKey * privkey;
40static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey; 45static struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pubkey;
41 46
47struct GNUNET_TIME_Absolute expire;
48
42static GNUNET_HashCode s_zone; 49static GNUNET_HashCode s_zone;
43static GNUNET_HashCode s_zone_value; 50static GNUNET_HashCode s_zone_value;
44 51
52char * s_name;
53
54struct GNUNET_NAMESTORE_RecordData *s_rd;
55struct GNUNET_CRYPTO_RsaSignature *s_signature;
56
45static int res; 57static int res;
46 58
47static void 59static void
@@ -123,17 +135,37 @@ void zone_to_name_proc (void *cls,
123 const struct GNUNET_NAMESTORE_RecordData *rd, 135 const struct GNUNET_NAMESTORE_RecordData *rd,
124 const struct GNUNET_CRYPTO_RsaSignature *signature) 136 const struct GNUNET_CRYPTO_RsaSignature *signature)
125{ 137{
126 if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL)) 138 int fail = GNUNET_NO;
139
140 if ((zone_key == NULL) && (n == NULL) && (rd_count == 0) && (rd == NULL) && (signature == NULL))
141 {
142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n");
143 res = 1;
144 }
145 else
146 {
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found: `%s'\n", n);
148 if (0 != strcmp(n, s_name))
127 { 149 {
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No result found\n"); 150 fail = GNUNET_YES;
129 res = 0; 151 GNUNET_break (0);
130 } 152 }
131 else 153 if (rd_count != 1)
132 { 154 {
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Result found\n"); 155 fail = GNUNET_YES;
134 res = 0; 156 GNUNET_break (0);
135 } 157 }
136 GNUNET_SCHEDULER_add_now(&end, NULL); 158 if (0 != memcmp (zone_key, &pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
159 {
160 fail = GNUNET_YES;
161 GNUNET_break (0);
162 }
163 if (fail == GNUNET_NO)
164 res = 0;
165 else
166 res = 1;
167 }
168 GNUNET_SCHEDULER_add_now(&end, NULL);
137} 169}
138 170
139 171
@@ -155,6 +187,28 @@ delete_existing_db (const struct GNUNET_CONFIGURATION_Handle *cfg)
155 187
156} 188}
157 189
190
191void
192put_cont (void *cls, int32_t success, const char *emsg)
193{
194 char *name = cls;
195 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Name store added record for `%s': %s\n", name, (success == GNUNET_OK) ? "SUCCESS" : "FAIL");
196 if (success == GNUNET_OK)
197 {
198 res = 0;
199
200 /* create initial record */
201 GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL);
202
203 }
204 else
205 {
206 res = 1;
207 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to put records for name `%s'\n", name);
208 GNUNET_SCHEDULER_add_now(&end, NULL);
209 }
210}
211
158static void 212static void
159run (void *cls, char *const *args, const char *cfgfile, 213run (void *cls, char *const *args, const char *cfgfile,
160 const struct GNUNET_CONFIGURATION_Handle *cfg) 214 const struct GNUNET_CONFIGURATION_Handle *cfg)
@@ -162,6 +216,8 @@ run (void *cls, char *const *args, const char *cfgfile,
162 delete_existing_db(cfg); 216 delete_existing_db(cfg);
163 217
164 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); 218 endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL);
219 GNUNET_asprintf(&s_name, "dummy.dummy.gnunet");
220
165 221
166 /* load privat key */ 222 /* load privat key */
167 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey"); 223 privkey = GNUNET_CRYPTO_rsa_key_create_from_file("hostkey");
@@ -171,7 +227,14 @@ run (void *cls, char *const *args, const char *cfgfile,
171 227
172 /* zone hash */ 228 /* zone hash */
173 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone); 229 GNUNET_CRYPTO_hash (&pubkey, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), &s_zone);
174 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &s_zone_value); 230 GNUNET_CRYPTO_hash (s_name, strlen (s_name) + 1, &s_zone_value);
231
232 struct GNUNET_NAMESTORE_RecordData rd;
233 rd.expiration = GNUNET_TIME_absolute_get();
234 rd.record_type = GNUNET_NAMESTORE_TYPE_PKEY;
235 rd.data_size = sizeof (GNUNET_HashCode);
236 rd.data = GNUNET_malloc(sizeof (GNUNET_HashCode));
237 memcpy ((char *) rd.data, &s_zone_value, sizeof (GNUNET_HashCode));
175 238
176 start_arm (cfgfile); 239 start_arm (cfgfile);
177 GNUNET_assert (arm != NULL); 240 GNUNET_assert (arm != NULL);
@@ -179,8 +242,11 @@ run (void *cls, char *const *args, const char *cfgfile,
179 nsh = GNUNET_NAMESTORE_connect (cfg); 242 nsh = GNUNET_NAMESTORE_connect (cfg);
180 GNUNET_break (NULL != nsh); 243 GNUNET_break (NULL != nsh);
181 244
182 /* create initial record */ 245 expire = GNUNET_TIME_absolute_get ();
183 GNUNET_NAMESTORE_zone_to_name (nsh, &s_zone, &s_zone_value, zone_to_name_proc, NULL); 246 s_signature = GNUNET_NAMESTORE_create_signature(privkey, s_name, &rd, 1);
247 GNUNET_NAMESTORE_record_put(nsh, &pubkey, s_name, expire, 1, &rd, s_signature, put_cont, NULL);
248
249 GNUNET_free ((void *) rd.data);
184} 250}
185 251
186static int 252static int