2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file gns/namestore_stub_api.c
23 * @brief stub library to access the NAMESTORE service
24 * @author Martin Schanzenbach
28 #include "gnunet_util_lib.h"
29 #include "gnunet_constants.h"
30 #include "gnunet_arm_service.h"
31 #include "gnunet_namestore_service.h"
33 #define DEBUG_GNS_API GNUNET_EXTRA_LOGGING
35 #define LOG(kind,...) GNUNET_log_from (kind, "gns-api",__VA_ARGS__)
40 struct GNUNET_NAMESTORE_QueueEntry
42 char *data; /*stub data pointer*/
46 * Connection to the NAMESTORE service.
48 struct GNUNET_NAMESTORE_Handle
52 * Configuration to use.
54 const struct GNUNET_CONFIGURATION_Handle *cfg;
57 * Socket (if available).
59 struct GNUNET_CLIENT_Connection *client;
62 * Currently pending transmission request (or NULL).
64 struct GNUNET_CLIENT_TransmitHandle *th;
66 /* dll to use for records */
67 struct GNUNET_NAMESTORE_SimpleRecord * records_head;
68 struct GNUNET_NAMESTORE_SimpleRecord * records_tail;
72 struct GNUNET_NAMESTORE_ZoneIterator
74 struct GNUNET_NAMESTORE_Handle *handle;
77 struct GNUNET_NAMESTORE_SimpleRecord
82 struct GNUNET_NAMESTORE_SimpleRecord *next;
87 struct GNUNET_NAMESTORE_SimpleRecord *prev;
90 const GNUNET_HashCode *zone;
92 struct GNUNET_TIME_Absolute expiration;
93 enum GNUNET_NAMESTORE_RecordFlags flags;
99 * Initialize the connection with the NAMESTORE service.
101 * @param cfg configuration to use
102 * @return handle to the GNS service, or NULL on error
104 struct GNUNET_NAMESTORE_Handle *
105 GNUNET_NAMESTORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
107 struct GNUNET_NAMESTORE_Handle *handle;
109 handle = GNUNET_malloc (sizeof (struct GNUNET_NAMESTORE_Handle));
116 * Shutdown connection with the NAMESTORE service.
118 * @param handle handle of the NAMESTORE connection to stop
121 GNUNET_NAMESTORE_disconnect (struct GNUNET_NAMESTORE_Handle *handle, int drop)
127 * Store an item in the namestore. If the item is already present,
128 * the expiration time is updated to the max of the existing time and
129 * the new time. The operation must fail if there is no matching
130 * entry in the signature tree.
132 * @param h handle to the namestore
133 * @param zone hash of the public key of the zone
134 * @param name name that is being mapped (at most 255 characters long)
135 * @param record_type type of the record (A, AAAA, PKEY, etc.)
136 * @param expiration expiration time for the content
137 * @param flags flags for the content
138 * @param data_size number of bytes in data
139 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
140 * GNS specification for GNS extensions)
141 * @param cont continuation to call when done
142 * @param cont_cls closure for cont
143 * @return handle to abort the request
145 struct GNUNET_NAMESTORE_QueueEntry *
146 GNUNET_NAMESTORE_record_put (struct GNUNET_NAMESTORE_Handle *h,
147 const GNUNET_HashCode *zone,
149 uint32_t record_type,
150 struct GNUNET_TIME_Absolute expiration,
151 enum GNUNET_NAMESTORE_RecordFlags flags,
154 GNUNET_NAMESTORE_ContinuationWithStatus cont,
157 struct GNUNET_NAMESTORE_QueueEntry *qe;
158 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
160 struct GNUNET_NAMESTORE_SimpleRecord *sr;
161 sr = GNUNET_malloc(sizeof(struct GNUNET_NAMESTORE_SimpleRecord));
163 sr->record_type = record_type;
164 sr->expiration = expiration;
166 sr->data_size = data_size;
168 GNUNET_CONTAINER_DLL_insert(h->records_head, h->records_tail, sr);
173 * Store a signature in the namestore.
175 * @param h handle to the namestore
176 * @param zone hash of the public key of the zone
177 * @param name name that is being mapped (at most 255 characters long)
178 * @param record_type type of the record (A, AAAA, PKEY, etc.)
179 * @param expiration expiration time for the content
180 * @param flags flags for the content
181 * @param data_size number of bytes in data
182 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and
183 * GNS specification for GNS extensions)
184 * @param cont continuation to call when done
185 * @param cont_cls closure for cont
186 * @return handle to abort the request
188 struct GNUNET_NAMESTORE_QueueEntry *
189 GNUNET_NAMESTORE_signature_put (struct GNUNET_NAMESTORE_Handle *h,
190 const GNUNET_HashCode *zone,
192 struct GNUNET_CRYPTO_RsaSignature sig,
193 GNUNET_NAMESTORE_ContinuationWithStatus cont,
196 struct GNUNET_NAMESTORE_QueueEntry *qe;
197 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
203 * Explicitly remove some content from the database. The
204 * "cont"inuation will be called with status "GNUNET_OK" if content
205 * was removed, "GNUNET_NO" if no matching entry was found and
206 * "GNUNET_SYSERR" on all other types of errors.
208 * @param h handle to the namestore
209 * @param zone hash of the public key of the zone
210 * @param name name that is being mapped (at most 255 characters long)
211 * @param record_type type of the record (A, AAAA, PKEY, etc.)
212 * @param size number of bytes in data
213 * @param data content stored
214 * @param cont continuation to call when done
215 * @param cont_cls closure for cont
216 * @return handle to abort the request
218 struct GNUNET_NAMESTORE_QueueEntry *
219 GNUNET_NAMESTORE_record_remove (struct GNUNET_NAMESTORE_Handle *h,
220 const GNUNET_HashCode *zone,
222 uint32_t record_type,
225 GNUNET_NAMESTORE_ContinuationWithStatus cont,
228 struct GNUNET_NAMESTORE_QueueEntry *qe;
229 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
231 struct GNUNET_NAMESTORE_SimpleRecord *iter;
232 for (iter=h->records_head; iter != NULL; iter=iter->next)
234 if (strcmp ( iter->name, name ) &&
235 iter->record_type == record_type &&
236 GNUNET_CRYPTO_hash_cmp (iter->zone, zone))
240 GNUNET_CONTAINER_DLL_remove(h->records_head,
248 * Get a result for a particular key from the namestore. The processor
249 * will only be called once.
251 * @param h handle to the namestore
252 * @param zone zone to look up a record from
253 * @param name name to look up
254 * @param record_type desired record type
255 * @param proc function to call on each matching value;
256 * will be called once with a NULL value at the end
257 * @param proc_cls closure for proc
258 * @return a handle that can be used to
261 struct GNUNET_NAMESTORE_QueueEntry *
262 GNUNET_NAMESTORE_lookup_record (struct GNUNET_NAMESTORE_Handle *h,
263 const GNUNET_HashCode *zone,
265 uint32_t record_type,
266 GNUNET_NAMESTORE_RecordProcessor proc, void *proc_cls)
268 struct GNUNET_NAMESTORE_QueueEntry *qe;
269 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
271 struct GNUNET_NAMESTORE_SimpleRecord *iter;
272 for (iter=h->records_head; iter != NULL; iter=iter->next)
274 if (strcmp(iter->name, name))
277 if (iter->record_type != record_type)
280 proc(proc_cls, iter->zone, iter->name, iter->record_type,
283 iter->data_size /*size*/,
284 iter->data /* data */);
286 proc(proc_cls, zone, name, record_type,
287 GNUNET_TIME_absolute_get_forever(), 0, 0, NULL); /*TERMINATE*/
292 struct GNUNET_NAMESTORE_QueueEntry *
293 GNUNET_NAMESTORE_lookup_signature (struct GNUNET_NAMESTORE_Handle *h,
294 const GNUNET_HashCode *zone,
296 GNUNET_NAMESTORE_SignatureProcessor proc,
304 * Get the hash of a record (what will be signed in the Stree for
307 * @param zone hash of the public key of the zone
308 * @param name name that is being mapped (at most 255 characters long)
309 * @param record_type type of the record (A, AAAA, PKEY, etc.)
310 * @param expiration expiration time for the content
311 * @param flags flags for the content
312 * @param data_size number of bytes in data
313 * @param data value, semantics depend on 'record_type' (see RFCs for DNS and.
314 * GNS specification for GNS extensions)
315 * @param record_hash hash of the record (set)
318 GNUNET_NAMESTORE_record_hash (struct GNUNET_NAMESTORE_Handle *h,
319 const GNUNET_HashCode *zone,
321 uint32_t record_type,
322 struct GNUNET_TIME_Absolute expiration,
323 enum GNUNET_NAMESTORE_RecordFlags flags,
326 GNUNET_HashCode *record_hash)
328 char* teststring = "namestore-stub";
329 GNUNET_CRYPTO_hash(teststring, strlen(teststring), record_hash);
334 * Get all records of a zone.
336 * @param h handle to the namestore
337 * @param zone zone to access
338 * @param proc function to call on a random value; it
339 * will be called repeatedly with a value (if available)
340 * and always once at the end with a zone and name of NULL.
341 * @param proc_cls closure for proc
342 * @return a handle that can be used to
345 struct GNUNET_NAMESTORE_QueueEntry *
346 GNUNET_NAMESTORE_zone_transfer (struct GNUNET_NAMESTORE_Handle *h,
347 const GNUNET_HashCode *zone,
348 GNUNET_NAMESTORE_RecordProcessor proc,
351 struct GNUNET_NAMESTORE_QueueEntry *qe;
352 qe = GNUNET_malloc(sizeof (struct GNUNET_NAMESTORE_QueueEntry));
356 struct GNUNET_NAMESTORE_ZoneIterator *
357 GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h,
358 const GNUNET_HashCode *zone,
359 GNUNET_NAMESTORE_RecordProcessor proc,
363 GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it);
366 GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it);
369 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe);
373 * Cancel a namestore operation. The final callback from the
374 * operation must not have been done yet.
376 * @param qe operation to cancel
379 GNUNET_NAMESTORE_cancel (struct GNUNET_NAMESTORE_QueueEntry *qe)
388 /* end of namestore_stub_api.c */