diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-16 21:52:04 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-16 21:52:04 +0000 |
commit | dbc823a07a03e1085172038125b0edf15b0dc6fe (patch) | |
tree | 4e7c3bf60ce83e801c69a6566ea36d514b571cba /src/namestore/namestore_api.c | |
parent | eec0e5088ec9437f5c0cf9d3ffef87603ad2777a (diff) | |
download | gnunet-dbc823a07a03e1085172038125b0edf15b0dc6fe.tar.gz gnunet-dbc823a07a03e1085172038125b0edf15b0dc6fe.zip |
-finishing split of namestore into namestore and namecache (#3065) -- in theory; in practice, somehow something broke badly, so the tests are now failing
Diffstat (limited to 'src/namestore/namestore_api.c')
-rw-r--r-- | src/namestore/namestore_api.c | 216 |
1 files changed, 0 insertions, 216 deletions
diff --git a/src/namestore/namestore_api.c b/src/namestore/namestore_api.c index 03e40ca17..efdc3005b 100644 --- a/src/namestore/namestore_api.c +++ b/src/namestore/namestore_api.c | |||
@@ -83,16 +83,6 @@ struct GNUNET_NAMESTORE_QueueEntry | |||
83 | void *proc_cls; | 83 | void *proc_cls; |
84 | 84 | ||
85 | /** | 85 | /** |
86 | * Function to call with the blocks we get back; or NULL. | ||
87 | */ | ||
88 | GNUNET_GNSRECORD_BlockProcessor block_proc; | ||
89 | |||
90 | /** | ||
91 | * Closure for @e block_proc. | ||
92 | */ | ||
93 | void *block_proc_cls; | ||
94 | |||
95 | /** | ||
96 | * The operation id this zone iteration operation has | 86 | * The operation id this zone iteration operation has |
97 | */ | 87 | */ |
98 | uint32_t op_id; | 88 | uint32_t op_id; |
@@ -259,91 +249,6 @@ force_reconnect (struct GNUNET_NAMESTORE_Handle *h); | |||
259 | 249 | ||
260 | /** | 250 | /** |
261 | * Handle an incoming message of type | 251 | * Handle an incoming message of type |
262 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE. | ||
263 | * | ||
264 | * @param qe the respective entry in the message queue | ||
265 | * @param msg the message we received | ||
266 | * @param size the message size | ||
267 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and we did NOT notify the client | ||
268 | */ | ||
269 | static int | ||
270 | handle_lookup_block_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
271 | const struct LookupBlockResponseMessage *msg, | ||
272 | size_t size) | ||
273 | { | ||
274 | struct GNUNET_GNSRECORD_Block *block; | ||
275 | char buf[size + sizeof (struct GNUNET_GNSRECORD_Block) | ||
276 | - sizeof (struct LookupBlockResponseMessage)]; | ||
277 | |||
278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
279 | "Received `%s'\n", | ||
280 | "LOOKUP_BLOCK_RESPONSE"); | ||
281 | if (0 == GNUNET_TIME_absolute_ntoh (msg->expire).abs_value_us) | ||
282 | { | ||
283 | /* no match found */ | ||
284 | if (NULL != qe->block_proc) | ||
285 | qe->block_proc (qe->block_proc_cls, NULL); | ||
286 | return GNUNET_OK; | ||
287 | } | ||
288 | |||
289 | block = (struct GNUNET_GNSRECORD_Block *) buf; | ||
290 | block->signature = msg->signature; | ||
291 | block->derived_key = msg->derived_key; | ||
292 | block->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_GNS_RECORD_SIGN); | ||
293 | block->purpose.size = htonl (size - sizeof (struct LookupBlockResponseMessage) + | ||
294 | sizeof (struct GNUNET_TIME_AbsoluteNBO) + | ||
295 | sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose)); | ||
296 | block->expiration_time = msg->expire; | ||
297 | memcpy (&block[1], | ||
298 | &msg[1], | ||
299 | size - sizeof (struct LookupBlockResponseMessage)); | ||
300 | if (GNUNET_OK != | ||
301 | GNUNET_GNSRECORD_block_verify (block)) | ||
302 | { | ||
303 | GNUNET_break (0); | ||
304 | return GNUNET_SYSERR; | ||
305 | } | ||
306 | if (NULL != qe->block_proc) | ||
307 | qe->block_proc (qe->block_proc_cls, block); | ||
308 | else | ||
309 | GNUNET_break (0); | ||
310 | return GNUNET_OK; | ||
311 | } | ||
312 | |||
313 | |||
314 | /** | ||
315 | * Handle an incoming message of type | ||
316 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE | ||
317 | * | ||
318 | * @param qe the respective entry in the message queue | ||
319 | * @param msg the message we received | ||
320 | * @param size the message size | ||
321 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error and we did NOT notify the client | ||
322 | */ | ||
323 | static int | ||
324 | handle_block_cache_response (struct GNUNET_NAMESTORE_QueueEntry *qe, | ||
325 | const struct BlockCacheResponseMessage *msg, | ||
326 | size_t size) | ||
327 | { | ||
328 | int res; | ||
329 | |||
330 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
331 | "Received `%s'\n", | ||
332 | "BLOCK_CACHE_RESPONSE"); | ||
333 | res = ntohl (msg->op_result); | ||
334 | /* TODO: add actual error message from namestore to response... */ | ||
335 | if (NULL != qe->cont) | ||
336 | qe->cont (qe->cont_cls, | ||
337 | res, | ||
338 | (GNUNET_OK == res) ? | ||
339 | NULL | ||
340 | : _("Namestore failed to cache block")); | ||
341 | return GNUNET_OK; | ||
342 | } | ||
343 | |||
344 | |||
345 | /** | ||
346 | * Handle an incoming message of type | ||
347 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE | 252 | * #GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE |
348 | * | 253 | * |
349 | * @param qe the respective entry in the message queue | 254 | * @param qe the respective entry in the message queue |
@@ -536,20 +441,6 @@ manage_record_operations (struct GNUNET_NAMESTORE_QueueEntry *qe, | |||
536 | /* handle different message type */ | 441 | /* handle different message type */ |
537 | switch (type) | 442 | switch (type) |
538 | { | 443 | { |
539 | case GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK_RESPONSE: | ||
540 | if (size < sizeof (struct LookupBlockResponseMessage)) | ||
541 | { | ||
542 | GNUNET_break (0); | ||
543 | return GNUNET_SYSERR; | ||
544 | } | ||
545 | return handle_lookup_block_response (qe, (const struct LookupBlockResponseMessage *) msg, size); | ||
546 | case GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE_RESPONSE: | ||
547 | if (size != sizeof (struct BlockCacheResponseMessage)) | ||
548 | { | ||
549 | GNUNET_break (0); | ||
550 | return GNUNET_SYSERR; | ||
551 | } | ||
552 | return handle_block_cache_response (qe, (const struct BlockCacheResponseMessage *) msg, size); | ||
553 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE: | 444 | case GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE: |
554 | if (size != sizeof (struct RecordStoreResponseMessage)) | 445 | if (size != sizeof (struct RecordStoreResponseMessage)) |
555 | { | 446 | { |
@@ -1010,64 +901,6 @@ GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *h) | |||
1010 | 901 | ||
1011 | /** | 902 | /** |
1012 | * Store an item in the namestore. If the item is already present, | 903 | * Store an item in the namestore. If the item is already present, |
1013 | * it is replaced with the new record. | ||
1014 | * | ||
1015 | * @param h handle to the namestore | ||
1016 | * @param block block to store | ||
1017 | * @param cont continuation to call when done | ||
1018 | * @param cont_cls closure for cont | ||
1019 | * @return handle to abort the request | ||
1020 | */ | ||
1021 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1022 | GNUNET_NAMESTORE_block_cache (struct GNUNET_NAMESTORE_Handle *h, | ||
1023 | const struct GNUNET_GNSRECORD_Block *block, | ||
1024 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
1025 | void *cont_cls) | ||
1026 | { | ||
1027 | struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
1028 | struct PendingMessage *pe; | ||
1029 | struct BlockCacheMessage *msg; | ||
1030 | uint32_t rid; | ||
1031 | size_t blen; | ||
1032 | size_t msg_size; | ||
1033 | |||
1034 | GNUNET_assert (NULL != h); | ||
1035 | blen = ntohl (block->purpose.size) | ||
1036 | - sizeof (struct GNUNET_TIME_AbsoluteNBO) | ||
1037 | - sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose); | ||
1038 | rid = get_op_id (h); | ||
1039 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | ||
1040 | qe->nsh = h; | ||
1041 | qe->cont = cont; | ||
1042 | qe->cont_cls = cont_cls; | ||
1043 | qe->op_id = rid; | ||
1044 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | ||
1045 | |||
1046 | /* setup msg */ | ||
1047 | msg_size = sizeof (struct BlockCacheMessage) + blen; | ||
1048 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); | ||
1049 | pe->size = msg_size; | ||
1050 | msg = (struct BlockCacheMessage *) &pe[1]; | ||
1051 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_BLOCK_CACHE); | ||
1052 | msg->gns_header.header.size = htons (msg_size); | ||
1053 | msg->gns_header.r_id = htonl (rid); | ||
1054 | msg->expire = block->expiration_time; | ||
1055 | msg->signature = block->signature; | ||
1056 | msg->derived_key = block->derived_key; | ||
1057 | memcpy (&msg[1], &block[1], blen); | ||
1058 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1059 | "Sending `%s' message with size %u and expiration %s\n", | ||
1060 | "NAMESTORE_BLOCK_CACHE", | ||
1061 | (unsigned int) msg_size, | ||
1062 | GNUNET_STRINGS_absolute_time_to_string (GNUNET_TIME_absolute_ntoh (msg->expire))); | ||
1063 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | ||
1064 | do_transmit (h); | ||
1065 | return qe; | ||
1066 | } | ||
1067 | |||
1068 | |||
1069 | /** | ||
1070 | * Store an item in the namestore. If the item is already present, | ||
1071 | * it is replaced with the new record. Use an empty array to | 904 | * it is replaced with the new record. Use an empty array to |
1072 | * remove all records under the given name. | 905 | * remove all records under the given name. |
1073 | * | 906 | * |
@@ -1149,55 +982,6 @@ GNUNET_NAMESTORE_records_store (struct GNUNET_NAMESTORE_Handle *h, | |||
1149 | 982 | ||
1150 | 983 | ||
1151 | /** | 984 | /** |
1152 | * Get a result for a particular key from the namestore. The processor | ||
1153 | * will only be called once. | ||
1154 | * | ||
1155 | * @param h handle to the namestore | ||
1156 | * @param derived_hash hash of zone key combined with name to lookup | ||
1157 | * @param proc function to call on the matching block, or with | ||
1158 | * NULL if there is no matching block | ||
1159 | * @param proc_cls closure for proc | ||
1160 | * @return a handle that can be used to cancel | ||
1161 | */ | ||
1162 | struct GNUNET_NAMESTORE_QueueEntry * | ||
1163 | GNUNET_NAMESTORE_lookup_block (struct GNUNET_NAMESTORE_Handle *h, | ||
1164 | const struct GNUNET_HashCode *derived_hash, | ||
1165 | GNUNET_GNSRECORD_BlockProcessor proc, void *proc_cls) | ||
1166 | { | ||
1167 | struct GNUNET_NAMESTORE_QueueEntry *qe; | ||
1168 | struct PendingMessage *pe; | ||
1169 | struct LookupBlockMessage *msg; | ||
1170 | size_t msg_size; | ||
1171 | uint32_t rid; | ||
1172 | |||
1173 | GNUNET_assert (NULL != h); | ||
1174 | GNUNET_assert (NULL != derived_hash); | ||
1175 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1176 | "Looking for block under %s\n", | ||
1177 | GNUNET_h2s (derived_hash)); | ||
1178 | rid = get_op_id(h); | ||
1179 | qe = GNUNET_new (struct GNUNET_NAMESTORE_QueueEntry); | ||
1180 | qe->nsh = h; | ||
1181 | qe->block_proc = proc; | ||
1182 | qe->block_proc_cls = proc_cls; | ||
1183 | qe->op_id = rid; | ||
1184 | GNUNET_CONTAINER_DLL_insert_tail (h->op_head, h->op_tail, qe); | ||
1185 | |||
1186 | msg_size = sizeof (struct LookupBlockMessage); | ||
1187 | pe = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size); | ||
1188 | pe->size = msg_size; | ||
1189 | msg = (struct LookupBlockMessage *) &pe[1]; | ||
1190 | msg->gns_header.header.type = htons (GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_BLOCK); | ||
1191 | msg->gns_header.header.size = htons (msg_size); | ||
1192 | msg->gns_header.r_id = htonl (rid); | ||
1193 | msg->query = *derived_hash; | ||
1194 | GNUNET_CONTAINER_DLL_insert_tail (h->pending_head, h->pending_tail, pe); | ||
1195 | do_transmit (h); | ||
1196 | return qe; | ||
1197 | } | ||
1198 | |||
1199 | |||
1200 | /** | ||
1201 | * Look for an existing PKEY delegation record for a given public key. | 985 | * Look for an existing PKEY delegation record for a given public key. |
1202 | * Returns at most one result to the processor. | 986 | * Returns at most one result to the processor. |
1203 | * | 987 | * |