aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-02-28 18:00:07 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-02-28 18:00:07 +0000
commit88c500a043b51a228bd1c513948115dfb0e182d9 (patch)
tree87581b06c30fb9cdb9b70d6062f5a9dc3e3f0bd0 /src
parentd7dc5581d2f8901ade0a50110531548eb3b39485 (diff)
downloadgnunet-88c500a043b51a228bd1c513948115dfb0e182d9.tar.gz
gnunet-88c500a043b51a228bd1c513948115dfb0e182d9.zip
- more changes
Diffstat (limited to 'src')
-rw-r--r--src/namestore/gnunet-service-namestore.c87
-rw-r--r--src/namestore/namestore.h15
-rw-r--r--src/namestore/namestore_api.c16
-rw-r--r--src/namestore/namestore_common.c19
4 files changed, 102 insertions, 35 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c
index 92eb218b9..3640e678b 100644
--- a/src/namestore/gnunet-service-namestore.c
+++ b/src/namestore/gnunet-service-namestore.c
@@ -208,8 +208,11 @@ handle_lookup_name_it (void *cls,
208 struct LookupNameResponseMessage *lnr_msg; 208 struct LookupNameResponseMessage *lnr_msg;
209 209
210 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp; 210 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp;
211 struct GNUNET_NAMESTORE_RecordData * rd_tmp; 211 struct GNUNET_NAMESTORE_RecordData *rd_selected = NULL;
212 char *rd_tmp;
212 char *name_tmp; 213 char *name_tmp;
214 char *rd_ser;
215 size_t rd_ser_len;
213 struct GNUNET_CRYPTO_RsaSignature *signature_tmp; 216 struct GNUNET_CRYPTO_RsaSignature *signature_tmp;
214 217
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE"); 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE");
@@ -233,18 +236,46 @@ handle_lookup_name_it (void *cls,
233 for (c = 0; c < rd_count; c ++) 236 for (c = 0; c < rd_count; c ++)
234 if (rd[c].record_type == lnc->record_type) 237 if (rd[c].record_type == lnc->record_type)
235 copied_elements++; /* found matching record */ 238 copied_elements++; /* found matching record */
239 rd_selected = GNUNET_malloc (copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData));
240 copied_elements = 0;
241 for (c = 0; c < rd_count; c ++)
242 {
243 if (rd[c].record_type == lnc->record_type)
244 {
245 /* found matching record */
246 memcpy (&rd_selected[copied_elements], &rd[c], sizeof (struct GNUNET_NAMESTORE_RecordData));
247 copied_elements++;
248 }
249 }
236 } 250 }
237 else 251 else
252 {
238 copied_elements = rd_count; 253 copied_elements = rd_count;
254 rd_selected = (struct GNUNET_NAMESTORE_RecordData *) rd;
255 }
256
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NAMESTORE_LOOKUP_NAME_RESPONSE: %p %u\n", rd_selected, copied_elements);
258 rd_ser_len = GNUNET_NAMESTORE_records_serialize(&rd_ser, copied_elements, rd_selected);
259 }
260 else
261 {
262 /* No results */
263 copied_elements = 0;
264 rd_selected = NULL;
265 rd_ser = NULL;
266 rd_ser_len = 0;
239 } 267 }
240 268
241 if ((copied_elements == rd_count) && (signature != NULL)) 269 if ((copied_elements == rd_count) && (signature != NULL))
242 contains_signature = GNUNET_YES; 270 contains_signature = GNUNET_YES;
243 271
272 if (rd_selected != rd)
273 GNUNET_free (rd_selected);
274
244 r_size = sizeof (struct LookupNameResponseMessage) + 275 r_size = sizeof (struct LookupNameResponseMessage) +
245 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 276 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
246 name_len + 277 name_len +
247 copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData) + 278 rd_ser_len +
248 contains_signature * sizeof (struct GNUNET_CRYPTO_RsaSignature); 279 contains_signature * sizeof (struct GNUNET_CRYPTO_RsaSignature);
249 280
250 lnr_msg = GNUNET_malloc (r_size); 281 lnr_msg = GNUNET_malloc (r_size);
@@ -252,16 +283,15 @@ handle_lookup_name_it (void *cls,
252 lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); 283 lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE);
253 lnr_msg->header.size = ntohs (r_size); 284 lnr_msg->header.size = ntohs (r_size);
254 lnr_msg->op_id = htonl (lnc->id); 285 lnr_msg->op_id = htonl (lnc->id);
255 lnr_msg->rc_count = htonl (copied_elements); 286 lnr_msg->rd_len = htonl (rd_ser_len);
256 lnr_msg->name_len = htons (name_len); 287 lnr_msg->name_len = htons (name_len);
257 lnr_msg->expire = GNUNET_TIME_absolute_hton(expire); 288 lnr_msg->expire = GNUNET_TIME_absolute_hton(expire);
258 lnr_msg->contains_sig = htons (contains_signature); 289 lnr_msg->contains_sig = htons (contains_signature);
259 290
260
261 zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &lnr_msg[1]; 291 zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &lnr_msg[1];
262 name_tmp = (char *) &zone_key_tmp[1]; 292 name_tmp = (char *) &zone_key_tmp[1];
263 rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len]; 293 rd_tmp = &name_tmp[name_len];
264 signature_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[copied_elements]; 294 signature_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[rd_ser_len];
265 295
266 if (zone_key != NULL) 296 if (zone_key != NULL)
267 memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 297 memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
@@ -272,24 +302,8 @@ handle_lookup_name_it (void *cls,
272 memcpy (zone_key_tmp, &dummy, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 302 memcpy (zone_key_tmp, &dummy, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
273 } 303 }
274 memcpy (name_tmp, name, name_len); 304 memcpy (name_tmp, name, name_len);
275 /* copy records */ 305 memcpy (rd_tmp, rd_ser, rd_ser_len);
276 copied_elements = 0; 306 GNUNET_free_non_null (rd_ser);
277 if (rd_count != 0)
278 {
279 if (lnc->record_type != 0)
280 {
281 /* special record type needed */
282 for (c = 0; c < rd_count; c ++)
283 if (rd[c].record_type == lnc->record_type)
284 {
285 /* found matching record */
286 memcpy (&rd_tmp[copied_elements], &rd[c], rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
287 copied_elements++;
288 }
289 }
290 else
291 memcpy (rd_tmp, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData));
292 }
293 307
294 if (GNUNET_YES == contains_signature) 308 if (GNUNET_YES == contains_signature)
295 memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); 309 memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature));
@@ -428,6 +442,8 @@ static void handle_record_put (void *cls,
428 rd_count, rd, 442 rd_count, rd,
429 signature); 443 signature);
430 444
445 GNUNET_NAMESTORE_records_free (rd_count, rd);
446
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n", 447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Putting record for name `%s': %s\n",
432 name, (res == GNUNET_OK) ? "OK" : "FAIL"); 448 name, (res == GNUNET_OK) ? "OK" : "FAIL");
433 449
@@ -595,7 +611,7 @@ struct ZoneIterationProcResult
595 int have_name; 611 int have_name;
596 char name[256]; 612 char name[256];
597 613
598 unsigned int rd_count; 614 size_t rd_ser_len;
599 char *rd_ser; 615 char *rd_ser;
600}; 616};
601 617
@@ -628,8 +644,6 @@ void zone_iteration_proc (void *cls,
628 else 644 else
629 zipr->have_name = GNUNET_NO; 645 zipr->have_name = GNUNET_NO;
630 646
631 zipr->rd_count = rd_count;
632
633 if (signature != NULL) 647 if (signature != NULL)
634 { 648 {
635 zipr->signature = *signature; 649 zipr->signature = *signature;
@@ -641,6 +655,7 @@ void zone_iteration_proc (void *cls,
641 if ((rd_count > 0) && (rd != NULL)) 655 if ((rd_count > 0) && (rd != NULL))
642 { 656 {
643 len = GNUNET_NAMESTORE_records_serialize (&zipr->rd_ser, rd_count, rd); 657 len = GNUNET_NAMESTORE_records_serialize (&zipr->rd_ser, rd_count, rd);
658 zipr->rd_ser_len = len;
644 } 659 }
645} 660}
646 661
@@ -674,12 +689,30 @@ static void handle_iteration_start (void *cls,
674 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi); 689 GNUNET_CONTAINER_DLL_insert (nc->op_head, nc->op_tail, zi);
675 690
676 res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr); 691 res = GSN_database->iterate_records (GSN_database->cls, &zis_msg->zone, NULL, zi->offset , &zone_iteration_proc, &zipr);
692 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "iterate_records result %u\n", res);
693 switch (res) {
694 case GNUNET_OK:
695 /* GNUNET_OK on success */
696
697 break;
698 case GNUNET_SYSERR:
699 /* GNUNET_SYSERR on error */
700 break;
701 case GNUNET_NO:
702 /* GNUNET_NO if there were no results, */
703 break;
704 default:
705 break;
706 }
707
708
677 709
678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE"); 710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "ZONE_ITERATION_RESPONSE");
679 zir_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE); 711 zir_msg.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_RESPONSE);
680 zir_msg.op_id = htonl(zi->op_id); 712 zir_msg.op_id = htonl(zi->op_id);
681 zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage)); 713 zir_msg.header.size = htons (sizeof (struct ZoneIterationResponseMessage));
682 714
715
683 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO); 716 GNUNET_SERVER_notification_context_unicast (snc, zi->client->client, (const struct GNUNET_MessageHeader *) &zir_msg, GNUNET_NO);
684 717
685 718
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h
index 22fc860eb..14a13801a 100644
--- a/src/namestore/namestore.h
+++ b/src/namestore/namestore.h
@@ -51,6 +51,9 @@ GNUNET_NAMESTORE_records_serialize (char ** dest,
51int 51int
52GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest, char *src, size_t len); 52GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest, char *src, size_t len);
53 53
54void
55GNUNET_NAMESTORE_records_free (unsigned int rd_count, struct GNUNET_NAMESTORE_RecordData *rd);
56
54/** 57/**
55 * A GNS record serialized for network transmission. 58 * A GNS record serialized for network transmission.
56 * layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data] 59 * layout is [struct GNUNET_NAMESTORE_NetworkRecord][char[data_size] data]
@@ -168,7 +171,7 @@ struct LookupNameResponseMessage
168 uint16_t contains_sig; 171 uint16_t contains_sig;
169 172
170 /* Requested record type */ 173 /* Requested record type */
171 uint32_t rc_count; 174 uint32_t rd_len;
172}; 175};
173GNUNET_NETWORK_STRUCT_END 176GNUNET_NETWORK_STRUCT_END
174 177
@@ -416,6 +419,16 @@ struct ZoneIterationResponseMessage
416 * Operation ID in NBO 419 * Operation ID in NBO
417 */ 420 */
418 uint32_t op_id; 421 uint32_t op_id;
422
423 struct GNUNET_TIME_AbsoluteNBO expire;
424
425 uint16_t name_len;
426
427 uint16_t contains_sig;
428
429 /* Record data length */
430 uint16_t rd_len;
431
419}; 432};
420GNUNET_NETWORK_STRUCT_END 433GNUNET_NETWORK_STRUCT_END
421 434
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c
index 1d41399c6..943ede519 100644
--- a/src/namestore/namestore_api.c
+++ b/src/namestore/namestore_api.c
@@ -200,16 +200,18 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
200 struct GNUNET_NAMESTORE_Handle *h = qe->nsh; 200 struct GNUNET_NAMESTORE_Handle *h = qe->nsh;
201 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key; 201 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key;
202 char *name; 202 char *name;
203 char * rd_tmp;
203 struct GNUNET_NAMESTORE_RecordData *rd = NULL; 204 struct GNUNET_NAMESTORE_RecordData *rd = NULL;
204 struct GNUNET_CRYPTO_RsaSignature *signature = NULL; 205 struct GNUNET_CRYPTO_RsaSignature *signature = NULL;
205 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy; 206 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy;
206 struct GNUNET_TIME_Absolute expire; 207 struct GNUNET_TIME_Absolute expire;
207 unsigned int rd_count = 0;
208 size_t msg_len = 0; 208 size_t msg_len = 0;
209 size_t name_len = 0; 209 size_t name_len = 0;
210 size_t rd_len = 0;
210 int contains_sig = GNUNET_NO; 211 int contains_sig = GNUNET_NO;
212 int rd_count = 0;
211 213
212 rd_count = ntohl (msg->rc_count); 214 rd_len = ntohs (msg->rd_len);
213 msg_len = ntohs (msg->header.size); 215 msg_len = ntohs (msg->header.size);
214 name_len = ntohs (msg->name_len); 216 name_len = ntohs (msg->name_len);
215 contains_sig = ntohs (msg->contains_sig); 217 contains_sig = ntohs (msg->contains_sig);
@@ -218,7 +220,7 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
218 if (msg_len != sizeof (struct LookupNameResponseMessage) + 220 if (msg_len != sizeof (struct LookupNameResponseMessage) +
219 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + 221 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) +
220 name_len + 222 name_len +
221 rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData) + 223 rd_len +
222 contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature)) 224 contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature))
223 { 225 {
224 GNUNET_break_op (0); 226 GNUNET_break_op (0);
@@ -227,13 +229,14 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
227 229
228 zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &msg[1]; 230 zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &msg[1];
229 name = (char *) &zone_key[1]; 231 name = (char *) &zone_key[1];
230 rd = (struct GNUNET_NAMESTORE_RecordData *) &name[name_len]; 232 rd_tmp = &name[name_len];
233 rd_count = GNUNET_NAMESTORE_records_deserialize(&rd, rd_tmp, rd_len);
231 234
232 /* reset values if values not contained */ 235 /* reset values if values not contained */
233 if (contains_sig == GNUNET_NO) 236 if (contains_sig == GNUNET_NO)
234 signature = NULL; 237 signature = NULL;
235 else 238 else
236 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rd[rd_count]; 239 signature = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[rd_len];
237 if (rd_count == 0) 240 if (rd_count == 0)
238 rd = NULL; 241 rd = NULL;
239 if (name_len == 0) 242 if (name_len == 0)
@@ -247,6 +250,9 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe,
247 { 250 {
248 qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature); 251 qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature);
249 } 252 }
253
254 GNUNET_NAMESTORE_records_free(rd_count, rd);
255
250 /* Operation done, remove */ 256 /* Operation done, remove */
251 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe); 257 GNUNET_CONTAINER_DLL_remove(h->op_head, h->op_tail, qe);
252 GNUNET_free (qe); 258 GNUNET_free (qe);
diff --git a/src/namestore/namestore_common.c b/src/namestore/namestore_common.c
index 37f0eab0b..711230351 100644
--- a/src/namestore/namestore_common.c
+++ b/src/namestore/namestore_common.c
@@ -55,6 +55,7 @@ GNUNET_NAMESTORE_records_serialize (char ** dest,
55 int c = 0; 55 int c = 0;
56 int offset; 56 int offset;
57 57
58 GNUNET_assert (rd != NULL);
58 59
59 size_t total_len = rd_count * sizeof (struct GNUNET_NAMESTORE_NetworkRecord); 60 size_t total_len = rd_count * sizeof (struct GNUNET_NAMESTORE_NetworkRecord);
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Struct size: %u\n", total_len); 61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Struct size: %u\n", total_len);
@@ -94,6 +95,18 @@ GNUNET_NAMESTORE_records_serialize (char ** dest,
94 return total_len; 95 return total_len;
95} 96}
96 97
98void
99GNUNET_NAMESTORE_records_free (unsigned int rd_count, struct GNUNET_NAMESTORE_RecordData *rd)
100{
101 int c;
102 if ((rd == NULL) || (rd_count == 0))
103 return;
104
105 for (c = 0; c < rd_count; c++)
106 GNUNET_free_non_null ((void *) rd[c].data);
107 GNUNET_free (rd);
108}
109
97 110
98/** 111/**
99 * Deserialize an array of GNUNET_NAMESTORE_RecordData *rd after transmission 112 * Deserialize an array of GNUNET_NAMESTORE_RecordData *rd after transmission
@@ -142,8 +155,10 @@ GNUNET_NAMESTORE_records_deserialize ( struct GNUNET_NAMESTORE_RecordData **dest
142 d[c].record_type = ntohl (nr->record_type); 155 d[c].record_type = ntohl (nr->record_type);
143 d[c].flags = ntohl (nr->flags); 156 d[c].flags = ntohl (nr->flags);
144 d[c].data_size = ntohl (nr->data_size); 157 d[c].data_size = ntohl (nr->data_size);
145 d[c].data = GNUNET_malloc (d[c].data_size); 158 if (d[c].data_size > 0)
146 GNUNET_assert (d[c].data != NULL); 159 d[c].data = GNUNET_malloc (d[c].data_size);
160 else
161 d[c].data = NULL;
147 162
148 offset += sizeof (struct GNUNET_NAMESTORE_NetworkRecord); 163 offset += sizeof (struct GNUNET_NAMESTORE_NetworkRecord);
149 memcpy((char *) d[c].data, &src[offset], d[c].data_size); 164 memcpy((char *) d[c].data, &src[offset], d[c].data_size);