diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-24 17:05:33 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-24 17:05:33 +0000 |
commit | 95c9e40b4153361d1e6e45f99659759a8f0f14de (patch) | |
tree | 992b8830de7a7062a39bd369900fcf8c9f85adc7 | |
parent | 0c7a03ffdb1388ac0caf90a22f9b1e93b6befa8f (diff) | |
download | gnunet-95c9e40b4153361d1e6e45f99659759a8f0f14de.tar.gz gnunet-95c9e40b4153361d1e6e45f99659759a8f0f14de.zip |
- lookup API send recv
-rw-r--r-- | src/namestore/gnunet-service-namestore.c | 167 | ||||
-rw-r--r-- | src/namestore/namestore.h | 28 | ||||
-rw-r--r-- | src/namestore/namestore_api.c | 80 | ||||
-rw-r--r-- | src/namestore/test_namestore_api.c | 9 | ||||
-rw-r--r-- | src/namestore/test_namestore_api.conf | 1 |
5 files changed, 257 insertions, 28 deletions
diff --git a/src/namestore/gnunet-service-namestore.c b/src/namestore/gnunet-service-namestore.c index 58830b304..e4f7a2b37 100644 --- a/src/namestore/gnunet-service-namestore.c +++ b/src/namestore/gnunet-service-namestore.c | |||
@@ -93,18 +93,21 @@ cleanup_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
93 | 93 | ||
94 | struct GNUNET_NAMESTORE_Operation * no; | 94 | struct GNUNET_NAMESTORE_Operation * no; |
95 | struct GNUNET_NAMESTORE_Client * nc; | 95 | struct GNUNET_NAMESTORE_Client * nc; |
96 | struct GNUNET_NAMESTORE_Client * next; | ||
96 | 97 | ||
97 | for (nc = client_head; nc != NULL; nc = nc->next) | 98 | for (nc = client_head; nc != NULL; nc = next) |
98 | { | 99 | { |
100 | next = nc->next; | ||
99 | for (no = nc->op_head; no != NULL; no = no->next) | 101 | for (no = nc->op_head; no != NULL; no = no->next) |
100 | { | 102 | { |
101 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); | 103 | GNUNET_CONTAINER_DLL_remove (nc->op_head, nc->op_tail, no); |
102 | GNUNET_free (no); | 104 | GNUNET_free (no); |
103 | } | 105 | } |
104 | } | ||
105 | 106 | ||
106 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); | 107 | GNUNET_CONTAINER_DLL_remove (client_head, client_tail, nc); |
107 | GNUNET_free (nc); | 108 | GNUNET_free (nc); |
109 | |||
110 | } | ||
108 | 111 | ||
109 | GNUNET_SERVER_notification_context_destroy (snc); | 112 | GNUNET_SERVER_notification_context_destroy (snc); |
110 | snc = NULL; | 113 | snc = NULL; |
@@ -175,15 +178,139 @@ static void handle_start (void *cls, | |||
175 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 178 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
176 | } | 179 | } |
177 | 180 | ||
181 | struct LookupNameContext | ||
182 | { | ||
183 | struct GNUNET_NAMESTORE_Client *nc; | ||
184 | uint32_t id; | ||
185 | uint32_t record_type; | ||
186 | }; | ||
187 | |||
188 | |||
189 | static void | ||
190 | handle_lookup_name_it (void *cls, | ||
191 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key, | ||
192 | struct GNUNET_TIME_Absolute expire, | ||
193 | const char *name, | ||
194 | unsigned int rd_count, | ||
195 | const struct GNUNET_NAMESTORE_RecordData *rd, | ||
196 | const struct GNUNET_CRYPTO_RsaSignature *signature) | ||
197 | { | ||
198 | /* send response */ | ||
199 | struct LookupNameContext *lnc = cls; | ||
200 | struct LookupNameResponseMessage *lnr_msg; | ||
201 | |||
202 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key_tmp; | ||
203 | struct GNUNET_NAMESTORE_RecordData * rd_tmp; | ||
204 | char *name_tmp; | ||
205 | struct GNUNET_CRYPTO_RsaSignature *signature_tmp; | ||
206 | |||
207 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE"); | ||
208 | |||
209 | size_t r_size = 0; | ||
210 | |||
211 | size_t name_len = 0; | ||
212 | if (NULL != name) | ||
213 | name_len = strlen(name) + 1; | ||
214 | |||
215 | int copied_elements = 0; | ||
216 | int contains_signature = 0; | ||
217 | int c; | ||
218 | |||
219 | /* count records to copy */ | ||
220 | if (rd_count != 0) | ||
221 | { | ||
222 | if (lnc->record_type != 0) | ||
223 | { | ||
224 | /* special record type needed */ | ||
225 | for (c = 0; c < rd_count; c ++) | ||
226 | if (rd[c].record_type == lnc->record_type) | ||
227 | copied_elements++; /* found matching record */ | ||
228 | } | ||
229 | else | ||
230 | copied_elements = rd_count; | ||
231 | } | ||
232 | |||
233 | if ((copied_elements == rd_count) && (signature != NULL)) | ||
234 | contains_signature = GNUNET_YES; | ||
235 | |||
236 | r_size = sizeof (struct LookupNameResponseMessage) + | ||
237 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | ||
238 | name_len + | ||
239 | copied_elements * sizeof (struct GNUNET_NAMESTORE_RecordData) + | ||
240 | contains_signature * sizeof (struct GNUNET_CRYPTO_RsaSignature); | ||
241 | |||
242 | lnr_msg = GNUNET_malloc (r_size); | ||
243 | |||
244 | lnr_msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); | ||
245 | lnr_msg->header.size = ntohs (r_size); | ||
246 | lnr_msg->op_id = htonl (lnc->id); | ||
247 | lnr_msg->rc_count = htonl (copied_elements); | ||
248 | lnr_msg->name_len = htons (name_len); | ||
249 | lnr_msg->expire = GNUNET_TIME_absolute_hton(expire); | ||
250 | lnr_msg->contains_sig = htons (contains_signature); | ||
251 | |||
252 | |||
253 | zone_key_tmp = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &lnr_msg[1]; | ||
254 | name_tmp = (char *) &zone_key_tmp[1]; | ||
255 | rd_tmp = (struct GNUNET_NAMESTORE_RecordData *) &name_tmp[name_len]; | ||
256 | signature_tmp = (struct GNUNET_CRYPTO_RsaSignature *) &rd_tmp[copied_elements]; | ||
257 | |||
258 | if (zone_key != NULL) | ||
259 | memcpy (zone_key_tmp, zone_key, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
260 | else | ||
261 | { | ||
262 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy; | ||
263 | memset (&dummy, '0', sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
264 | memcpy (zone_key_tmp, &dummy, sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); | ||
265 | } | ||
266 | memcpy (name_tmp, name, name_len); | ||
267 | /* copy records */ | ||
268 | copied_elements = 0; | ||
269 | if (rd_count != 0) | ||
270 | { | ||
271 | if (lnc->record_type != 0) | ||
272 | { | ||
273 | /* special record type needed */ | ||
274 | for (c = 0; c < rd_count; c ++) | ||
275 | if (rd[c].record_type == lnc->record_type) | ||
276 | { | ||
277 | /* found matching record */ | ||
278 | memcpy (&rd_tmp[copied_elements], &rd[c], rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
279 | copied_elements++; | ||
280 | } | ||
281 | } | ||
282 | else | ||
283 | memcpy (rd_tmp, rd, rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData)); | ||
284 | } | ||
285 | |||
286 | if (GNUNET_YES == contains_signature) | ||
287 | memcpy (signature_tmp, signature, sizeof (struct GNUNET_CRYPTO_RsaSignature)); | ||
288 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "DONE `%s' message\n", "NAMESTORE_LOOKUP_NAME_RESPONSE"); | ||
289 | GNUNET_SERVER_notification_context_unicast (snc, lnc->nc->client, (const struct GNUNET_MessageHeader *) lnr_msg, GNUNET_NO); | ||
290 | |||
291 | GNUNET_free (lnr_msg); | ||
292 | } | ||
293 | |||
178 | static void handle_lookup_name (void *cls, | 294 | static void handle_lookup_name (void *cls, |
179 | struct GNUNET_SERVER_Client * client, | 295 | struct GNUNET_SERVER_Client * client, |
180 | const struct GNUNET_MessageHeader * message) | 296 | const struct GNUNET_MessageHeader * message) |
181 | { | 297 | { |
182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME"); | 298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "NAMESTORE_LOOKUP_NAME"); |
183 | 299 | struct LookupNameContext lnc; | |
184 | struct GNUNET_NAMESTORE_Client *nc; | 300 | struct GNUNET_NAMESTORE_Client *nc; |
301 | GNUNET_HashCode name_hash; | ||
302 | size_t name_len; | ||
303 | char * name; | ||
185 | uint32_t id = 0; | 304 | uint32_t id = 0; |
186 | size_t r_size = 0; | 305 | uint32_t type = 0; |
306 | |||
307 | |||
308 | if (ntohs (message->size) < sizeof (struct LookupNameMessage)) | ||
309 | { | ||
310 | GNUNET_break_op (0); | ||
311 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
312 | return; | ||
313 | } | ||
187 | 314 | ||
188 | nc = client_lookup(client); | 315 | nc = client_lookup(client); |
189 | if (nc == NULL) | 316 | if (nc == NULL) |
@@ -195,18 +322,28 @@ static void handle_lookup_name (void *cls, | |||
195 | 322 | ||
196 | struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message; | 323 | struct LookupNameMessage * ln_msg = (struct LookupNameMessage *) message; |
197 | id = ntohl (ln_msg->op_id); | 324 | id = ntohl (ln_msg->op_id); |
325 | name_len = ntohl (ln_msg->name_len); | ||
326 | type = ntohl (ln_msg->record_type); | ||
198 | 327 | ||
199 | /* do the actual lookup */ | 328 | if ((name_len == 0) || (name_len > 256)) |
329 | { | ||
330 | GNUNET_break_op (0); | ||
331 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
332 | return; | ||
333 | } | ||
200 | 334 | ||
201 | /* send response */ | 335 | name = GNUNET_malloc (name_len); |
202 | struct LookupNameResponseMessage lnr_msg; | 336 | memcpy (name, &ln_msg[1], name_len); |
203 | r_size = sizeof (struct LookupNameResponseMessage); | 337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Looking up record for name `%s'\n", name); |
338 | GNUNET_CRYPTO_hash(name, name_len-1, &name_hash); | ||
339 | GNUNET_free (name); | ||
204 | 340 | ||
205 | lnr_msg.header.type = ntohs (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE); | 341 | /* do the actual lookup */ |
206 | lnr_msg.header.size = ntohs (r_size); | 342 | lnc.id = id; |
207 | lnr_msg.op_id = htonl (id); | 343 | lnc.nc = nc; |
344 | lnc.record_type = type; | ||
345 | GSN_database->iterate_records(GSN_database->cls, &ln_msg->zone, &ln_msg->zone, 0, &handle_lookup_name_it, &lnc); | ||
208 | 346 | ||
209 | GNUNET_SERVER_notification_context_unicast (snc, nc->client, (const struct GNUNET_MessageHeader *) &lnr_msg, GNUNET_NO); | ||
210 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 347 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
211 | } | 348 | } |
212 | 349 | ||
@@ -230,7 +367,7 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
230 | {&handle_start, NULL, | 367 | {&handle_start, NULL, |
231 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, | 368 | GNUNET_MESSAGE_TYPE_NAMESTORE_START, sizeof (struct StartMessage)}, |
232 | {&handle_lookup_name, NULL, | 369 | {&handle_lookup_name, NULL, |
233 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, sizeof (struct LookupNameMessage)}, | 370 | GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME, 0}, |
234 | {NULL, NULL, 0, 0} | 371 | {NULL, NULL, 0, 0} |
235 | }; | 372 | }; |
236 | 373 | ||
diff --git a/src/namestore/namestore.h b/src/namestore/namestore.h index 27d36d78b..143f233d4 100644 --- a/src/namestore/namestore.h +++ b/src/namestore/namestore.h | |||
@@ -66,6 +66,8 @@ struct GenericMessage | |||
66 | }; | 66 | }; |
67 | GNUNET_NETWORK_STRUCT_END | 67 | GNUNET_NETWORK_STRUCT_END |
68 | 68 | ||
69 | |||
70 | |||
69 | GNUNET_NETWORK_STRUCT_BEGIN | 71 | GNUNET_NETWORK_STRUCT_BEGIN |
70 | /** | 72 | /** |
71 | * Connect to namestore service | 73 | * Connect to namestore service |
@@ -81,11 +83,28 @@ struct LookupNameMessage | |||
81 | * Operation ID in NBO | 83 | * Operation ID in NBO |
82 | */ | 84 | */ |
83 | uint32_t op_id; | 85 | uint32_t op_id; |
86 | |||
87 | /* The zone */ | ||
88 | GNUNET_HashCode zone; | ||
89 | |||
90 | /* Requested record type */ | ||
91 | uint32_t record_type; | ||
92 | |||
93 | /* Requested record type */ | ||
94 | uint32_t name_len; | ||
84 | }; | 95 | }; |
85 | GNUNET_NETWORK_STRUCT_END | 96 | GNUNET_NETWORK_STRUCT_END |
86 | 97 | ||
98 | |||
99 | |||
87 | GNUNET_NETWORK_STRUCT_BEGIN | 100 | GNUNET_NETWORK_STRUCT_BEGIN |
88 | 101 | ||
102 | /** | ||
103 | * Lookup response | ||
104 | * Memory layout: | ||
105 | * [struct LookupNameResponseMessage][struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded][char *name][rc_count * struct GNUNET_NAMESTORE_RecordData][struct GNUNET_CRYPTO_RsaSignature] | ||
106 | */ | ||
107 | |||
89 | struct LookupNameResponseMessage | 108 | struct LookupNameResponseMessage |
90 | { | 109 | { |
91 | /** | 110 | /** |
@@ -97,6 +116,15 @@ struct LookupNameResponseMessage | |||
97 | * Operation ID in NBO | 116 | * Operation ID in NBO |
98 | */ | 117 | */ |
99 | uint32_t op_id; | 118 | uint32_t op_id; |
119 | |||
120 | struct GNUNET_TIME_AbsoluteNBO expire; | ||
121 | |||
122 | uint16_t name_len; | ||
123 | |||
124 | uint16_t contains_sig; | ||
125 | |||
126 | /* Requested record type */ | ||
127 | uint32_t rc_count; | ||
100 | }; | 128 | }; |
101 | 129 | ||
102 | 130 | ||
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 0e269f4aa..811c0b2d0 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -196,23 +196,59 @@ handle_lookup_name_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
196 | "LOOKUP_NAME_RESPONSE"); | 196 | "LOOKUP_NAME_RESPONSE"); |
197 | 197 | ||
198 | struct GNUNET_NAMESTORE_Handle *nsh = qe->nsh; | 198 | struct GNUNET_NAMESTORE_Handle *nsh = qe->nsh; |
199 | 199 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key; | |
200 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *zone_key = NULL; | 200 | char *name; |
201 | struct GNUNET_TIME_Absolute expire = GNUNET_TIME_absolute_get_forever(); | 201 | struct GNUNET_NAMESTORE_RecordData *rd = NULL; |
202 | const char *name = ""; | 202 | struct GNUNET_CRYPTO_RsaSignature *signature = NULL; |
203 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded dummy; | ||
204 | struct GNUNET_TIME_Absolute expire; | ||
203 | unsigned int rd_count = 0; | 205 | unsigned int rd_count = 0; |
204 | const struct GNUNET_NAMESTORE_RecordData *rd = NULL; | 206 | size_t msg_len = 0; |
205 | const struct GNUNET_CRYPTO_RsaSignature *signature = NULL; | 207 | size_t name_len = 0; |
208 | int contains_sig = GNUNET_NO; | ||
209 | |||
210 | rd_count = ntohl (msg->rc_count); | ||
211 | msg_len = ntohs (msg->header.size); | ||
212 | name_len = ntohs (msg->name_len); | ||
213 | contains_sig = ntohs (msg->contains_sig); | ||
214 | expire = GNUNET_TIME_absolute_ntoh(msg->expire); | ||
215 | |||
216 | if (msg_len != sizeof (struct LookupNameResponseMessage) + | ||
217 | sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded) + | ||
218 | name_len + | ||
219 | rd_count * sizeof (struct GNUNET_NAMESTORE_RecordData) + | ||
220 | contains_sig * sizeof (struct GNUNET_CRYPTO_RsaSignature)) | ||
221 | { | ||
222 | GNUNET_break_op (0); | ||
223 | return; | ||
224 | } | ||
225 | |||
226 | zone_key = (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *) &msg[1]; | ||
227 | name = (char *) &zone_key[1]; | ||
228 | rd = (struct GNUNET_NAMESTORE_RecordData *) &name[name_len]; | ||
206 | 229 | ||
207 | /* TODO: extract real values */ | 230 | /* reset values if values not contained */ |
231 | if (contains_sig == GNUNET_NO) | ||
232 | signature = NULL; | ||
233 | else | ||
234 | signature = (struct GNUNET_CRYPTO_RsaSignature *) &rd[rd_count]; | ||
235 | if (rd_count == 0) | ||
236 | rd = NULL; | ||
237 | if (name_len == 0) | ||
238 | name = NULL; | ||
208 | 239 | ||
209 | /* Lookup complete, remove queue entry */ | 240 | memset (&dummy, '0', sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); |
210 | GNUNET_CONTAINER_DLL_remove (nsh->op_head, nsh->op_tail, qe); | 241 | if (0 == memcmp (zone_key, &dummy, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) |
242 | zone_key = NULL; | ||
211 | 243 | ||
212 | /* Notify */ | ||
213 | if (qe->proc != NULL) | 244 | if (qe->proc != NULL) |
245 | { | ||
214 | qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature); | 246 | qe->proc (qe->proc_cls, zone_key, expire, name, rd_count, rd, signature); |
247 | } | ||
215 | 248 | ||
249 | |||
250 | /* Operation done, remove */ | ||
251 | GNUNET_CONTAINER_DLL_remove(nsh->op_head, nsh->op_tail, qe); | ||
216 | GNUNET_free (qe); | 252 | GNUNET_free (qe); |
217 | 253 | ||
218 | } | 254 | } |
@@ -283,6 +319,11 @@ process_namestore_message (void *cls, const struct GNUNET_MessageHeader *msg) | |||
283 | /* handle different message type */ | 319 | /* handle different message type */ |
284 | switch (type) { | 320 | switch (type) { |
285 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE: | 321 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPONSE: |
322 | if (size < sizeof (struct LookupNameResponseMessage)) | ||
323 | { | ||
324 | GNUNET_break_op (0); | ||
325 | break; | ||
326 | } | ||
286 | handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) msg, size); | 327 | handle_lookup_name_response (qe, (struct LookupNameResponseMessage *) msg, size); |
287 | break; | 328 | break; |
288 | default: | 329 | default: |
@@ -724,9 +765,20 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
724 | struct GNUNET_NAMESTORE_QueueEntry *qe; | 765 | struct GNUNET_NAMESTORE_QueueEntry *qe; |
725 | struct PendingMessage *pe; | 766 | struct PendingMessage *pe; |
726 | size_t msg_size = 0; | 767 | size_t msg_size = 0; |
768 | size_t name_len = 0; | ||
727 | uint32_t id = 0; | 769 | uint32_t id = 0; |
728 | 770 | ||
729 | GNUNET_assert (NULL != h); | 771 | GNUNET_assert (NULL != h); |
772 | GNUNET_assert (NULL != zone); | ||
773 | GNUNET_assert (NULL != name); | ||
774 | |||
775 | name_len = strlen (name) + 1; | ||
776 | if ((name_len == 0) || (name_len > 256)) | ||
777 | { | ||
778 | GNUNET_break (0); | ||
779 | return NULL; | ||
780 | } | ||
781 | |||
730 | id = get_op_id(h); | 782 | id = get_op_id(h); |
731 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); | 783 | qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry)); |
732 | qe->nsh = h; | 784 | qe->nsh = h; |
@@ -736,7 +788,7 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
736 | GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe); | 788 | GNUNET_CONTAINER_DLL_insert(h->op_head, h->op_tail, qe); |
737 | 789 | ||
738 | /* set msg_size*/ | 790 | /* set msg_size*/ |
739 | msg_size = sizeof (struct LookupNameMessage); | 791 | msg_size = sizeof (struct LookupNameMessage) + name_len; |
740 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); | 792 | pe = GNUNET_malloc(sizeof (struct PendingMessage) + msg_size); |
741 | 793 | ||
742 | /* create msg here */ | 794 | /* create msg here */ |
@@ -747,6 +799,12 @@ GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h, | |||
747 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); | 799 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME); |
748 | msg->header.size = htons (msg_size); | 800 | msg->header.size = htons (msg_size); |
749 | msg->op_id = htonl (id); | 801 | msg->op_id = htonl (id); |
802 | msg->record_type = htonl (record_type); | ||
803 | msg->zone = *zone; | ||
804 | msg->name_len = htonl (name_len); | ||
805 | memcpy (&msg[1], name, name_len); | ||
806 | |||
807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' message for name `%s'\n", "NAMESTORE_LOOKUP_NAME", name); | ||
750 | 808 | ||
751 | /* transmit message */ | 809 | /* transmit message */ |
752 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); | 810 | GNUNET_CONTAINER_DLL_insert (h->pending_head, h->pending_tail, pe); |
diff --git a/src/namestore/test_namestore_api.c b/src/namestore/test_namestore_api.c index 335bbbfba..a72530d13 100644 --- a/src/namestore/test_namestore_api.c +++ b/src/namestore/test_namestore_api.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | #define VERBOSE GNUNET_EXTRA_LOGGING | 28 | #define VERBOSE GNUNET_EXTRA_LOGGING |
29 | 29 | ||
30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | 30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
31 | 31 | ||
32 | static struct GNUNET_NAMESTORE_Handle * nsh; | 32 | static struct GNUNET_NAMESTORE_Handle * nsh; |
33 | 33 | ||
@@ -112,6 +112,7 @@ void name_lookup_proc (void *cls, | |||
112 | const struct GNUNET_NAMESTORE_RecordData *rd, | 112 | const struct GNUNET_NAMESTORE_RecordData *rd, |
113 | const struct GNUNET_CRYPTO_RsaSignature *signature) | 113 | const struct GNUNET_CRYPTO_RsaSignature *signature) |
114 | { | 114 | { |
115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "name_lookup_proc %p `%s' %i %p %p\n", zone_key, name, rd_count, rd, signature); | ||
115 | res = 0; | 116 | res = 0; |
116 | GNUNET_SCHEDULER_add_now(&end, NULL); | 117 | GNUNET_SCHEDULER_add_now(&end, NULL); |
117 | } | 118 | } |
@@ -122,13 +123,17 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
122 | { | 123 | { |
123 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); | 124 | endbadly_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT,endbadly, NULL); |
124 | 125 | ||
126 | GNUNET_HashCode zone; | ||
127 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &zone); | ||
128 | char * name = "dummy.dummy.gnunet"; | ||
129 | |||
125 | start_arm (cfgfile); | 130 | start_arm (cfgfile); |
126 | GNUNET_assert (arm != NULL); | 131 | GNUNET_assert (arm != NULL); |
127 | 132 | ||
128 | nsh = GNUNET_NAMESTORE_connect (cfg); | 133 | nsh = GNUNET_NAMESTORE_connect (cfg); |
129 | GNUNET_break (NULL != nsh); | 134 | GNUNET_break (NULL != nsh); |
130 | 135 | ||
131 | GNUNET_NAMESTORE_lookup_record (nsh, NULL, NULL, 0, &name_lookup_proc, NULL); | 136 | GNUNET_NAMESTORE_lookup_record (nsh, &zone, name, 0, &name_lookup_proc, NULL); |
132 | } | 137 | } |
133 | 138 | ||
134 | static int | 139 | static int |
diff --git a/src/namestore/test_namestore_api.conf b/src/namestore/test_namestore_api.conf index be93cb962..1683d13cf 100644 --- a/src/namestore/test_namestore_api.conf +++ b/src/namestore/test_namestore_api.conf | |||
@@ -4,6 +4,7 @@ DEFAULTSERVICES = namestore | |||
4 | UNIXPATH = /tmp/gnunet-p1-service-arm.sock | 4 | UNIXPATH = /tmp/gnunet-p1-service-arm.sock |
5 | 5 | ||
6 | [namestore] | 6 | [namestore] |
7 | PREFIX = valgrind --leak-check=full | ||
7 | AUTOSTART = YES | 8 | AUTOSTART = YES |
8 | UNIXPATH = /tmp/gnunet-service-namestore.sock | 9 | UNIXPATH = /tmp/gnunet-service-namestore.sock |
9 | UNIX_MATCH_UID = YES | 10 | UNIX_MATCH_UID = YES |