41 #define LOG(kind, ...) GNUNET_log_from (kind, "namestore-api", __VA_ARGS__)
47 #define NAMESTORE_DELAY_TOLERANCE GNUNET_TIME_UNIT_MINUTES
265 if (
qe->op_id == rid)
283 for (ze =
h->z_head; ze != NULL; ze = ze->
next)
284 if (ze->
op_id == rid)
303 if (NULL !=
qe->timeout_task)
336 check_rd (
size_t rd_len,
const void *rd_buf,
unsigned int rd_count)
366 msg_len = ntohs (
msg->gns_header.header.
size);
367 emsg_len = ntohs (
msg->emsg_len);
368 if (0 != ntohs (
msg->reserved))
378 emsg = (
const char *) &
msg[1];
379 if ((0 != emsg_len) && (
'\0' != emsg[emsg_len - 1]))
405 emsg = (
const char *) &
msg[1];
406 res = ntohl (
msg->op_result);
408 "Received RECORD_STORE_RESPONSE with result %d\n",
437 rd_len = ntohs (
msg->rd_len);
438 msg_len = ntohs (
msg->gns_header.header.
size);
439 name_len = ntohs (
msg->name_len);
440 exp_msg_len =
sizeof(*msg) + name_len + rd_len;
441 if (msg_len != exp_msg_len)
447 if ((name_len > 0) && (
'\0' !=
name[name_len - 1]))
454 if (0 != ntohs (
msg->rd_count))
481 unsigned int rd_count;
482 int16_t found = (int16_t) ntohs (
msg->found);
489 rd_len = ntohs (
msg->rd_len);
490 rd_count = ntohs (
msg->rd_count);
491 name_len = ntohs (
msg->name_len);
496 if (NULL !=
qe->proc)
497 qe->proc (
qe->proc_cls, &
msg->private_key,
name, 0, NULL);
503 if (NULL !=
qe->error_cb)
504 qe->error_cb (
qe->error_cb_cls);
509 rd_tmp = &
name[name_len];
518 if (NULL !=
qe->proc)
519 qe->proc (
qe->proc_cls,
523 (rd_count > 0) ? rd : NULL);
547 rd_len = ntohs (
msg->rd_len);
548 msg_len = ntohs (
msg->gns_header.header.
size);
549 name_len = ntohs (
msg->name_len);
550 if (0 != ntohs (
msg->reserved))
561 if ((0 == name_len) || (
'\0' !=
name[name_len - 1]))
592 unsigned int rd_count;
595 rd_len = ntohs (
msg->rd_len);
596 rd_count = ntohs (
msg->rd_count);
597 name_len = ntohs (
msg->name_len);
600 if ((NULL == ze) && (NULL ==
qe))
602 if ((NULL != ze) && (NULL !=
qe))
609 rd_tmp = &
name[name_len];
620 if (NULL !=
qe->proc)
621 qe->proc (
qe->proc_cls,
625 (rd_count > 0) ? rd : NULL);
631 if (NULL != ze->
proc)
657 if ((NULL == ze) && (NULL ==
qe))
659 if ((NULL != ze) && (NULL !=
qe))
692 const char *name_tmp;
697 name_len = ntohs (
msg->name_len);
698 rd_ser_len = ntohs (
msg->rd_len);
699 if (ntohs (
msg->gns_header.header.
size) !=
705 name_tmp = (
const char *) &
msg[1];
706 if ((name_len > 0) && (
'\0' != name_tmp[name_len - 1]))
711 return check_rd (rd_ser_len, &name_tmp[name_len], ntohs (
msg->rd_count));
731 unsigned int rd_count;
732 const char *name_tmp;
740 "Response queue already gone...\n");
748 "An error occurred during zone to name operation\n");
753 "Namestore has no result for zone to name mapping \n");
754 if (NULL !=
qe->proc)
755 qe->proc (
qe->proc_cls, &
msg->zone, NULL, 0, NULL);
761 "Namestore has result for zone to name mapping \n");
762 name_len = ntohs (
msg->name_len);
763 rd_count = ntohs (
msg->rd_count);
764 rd_ser_len = ntohs (
msg->rd_len);
765 name_tmp = (
const char *) &
msg[1];
766 rd_tmp = &name_tmp[name_len];
776 if (NULL !=
qe->proc)
777 qe->proc (
qe->proc_cls, &
msg->zone, name_tmp, rd_count, rd);
789 if (NULL !=
qe->error_cb)
790 qe->error_cb (
qe->error_cb_cls);
852 for (it =
h->z_head; NULL != it; it = it->
next)
893 while (NULL != (ze =
h->z_head))
899 while (NULL != (
qe =
h->op_head))
901 if (NULL !=
qe->error_cb)
902 qe->error_cb (
qe->error_cb_cls);
906 "failure in communication with namestore service");
926 return h->last_op_id_used++;
967 while (NULL != (
q =
h->op_head))
973 while (NULL != (z =
h->z_head))
1003 qe->timeout_task = NULL;
1005 "Did not receive response from namestore after %s!\n",
1022 unsigned int rd_count,
1049 if (rd_ser_len > UINT16_MAX)
1066 msg->gns_header.r_id = htonl (rid);
1069 msg->rd_len = htons (rd_ser_len);
1070 msg->reserved = ntohs (0);
1073 name_tmp = (
char *) &
msg[1];
1077 if ((0 > sret) || (sret != rd_ser_len))
1085 "Sending NAMESTORE_RECORD_STORE message for name `%s' with %u records\n",
1094 "Delaying NAMESTORE_RECORD_STORE message as namestore is not ready!\n");
1111 unsigned int rd_count,
1135 if (1 == (
label_len = strlen (label) + 1))
1144 qe->error_cb_cls = error_cb_cls;
1146 qe->proc_cls = rm_cls;
1153 msg->gns_header.r_id = htonl (
qe->op_id);
1202 qe->error_cb_cls = error_cb_cls;
1204 qe->proc_cls = proc_cls;
1209 msg->gns_header.r_id = htonl (rid);
1270 msg->gns_header.r_id = htonl (rid);
1298 "Sending ZONE_ITERATION_NEXT message with limit %llu\n",
1299 (
unsigned long long) limit);
1301 msg->gns_header.r_id = htonl (it->
op_id);
1324 msg->gns_header.r_id = htonl (it->
op_id);
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static void error_cb(void *cls)
Function called if lookup fails.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_DATASTORE_QueueEntry * qe
Current operation.
static char * pkey
Public key of the zone to look in, in ASCII.
static char * zone
Name of the zone being managed.
static struct GNUNET_REVOCATION_Query * q
Handle for revocation query.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
cryptographic primitives for GNUnet
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
GNUNET_NETWORK_STRUCT_END ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_replace(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
TODO: Experimental API will replace API above.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_select(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
TODO experimental API.
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT).
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_lookup(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor rm, void *rm_cls)
Lookup an item in the namestore.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record.
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
void(* GNUNET_NAMESTORE_ContinuationWithStatus)(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_commit(struct GNUNET_NAMESTORE_Handle *h, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls)
Commit a namestore transaction.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
void(* GNUNET_NAMESTORE_RecordMonitor)(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the connection with the NAMESTORE service.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_begin(struct GNUNET_NAMESTORE_Handle *h, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls)
New API draft.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_transaction_abort(struct GNUNET_NAMESTORE_Handle *h, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls)
Begin rollback all actions in a transaction.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
Look for an existing PKEY delegation record for a given public key.
void GNUNET_NAMESTORE_zone_iteration_stop(struct GNUNET_NAMESTORE_ZoneIterator *it)
Stops iteration and releases the namestore handle for further calls.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END
Service to client: end of list of results.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE
Service to client: result of zone-to-name lookup.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE
Service to client: result of store operation.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_NEXT
Client to service: next record(s) in iteration please.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_START
Client to service: please start iteration; receives "GNUNET_MESSAGE_TYPE_NAMESTORE_LOOKUP_NAME_RESPON...
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_ITERATION_STOP
Client to service: stop iterating.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE
Service to client: lookup label.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE
Client to service: store records (as authority)
#define GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME
Client to service: "reverse" lookup for zone name based on zone key.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP
Client to service: lookup label.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define MAX_NAME_LEN
Maximum length of any name, including 0-termination.
common internal definitions for namestore service
static void handle_zone_to_name_response(void *cls, const struct ZoneToNameResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
static int check_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Check validity of an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
static struct GNUNET_NAMESTORE_QueueEntry * find_qe(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the queue entry that matches the rid.
#define NAMESTORE_DELAY_TOLERANCE
We grant the namestore up to 1 minute of latency, if it is slower than that, store queries will fail.
static void free_qe(struct GNUNET_NAMESTORE_QueueEntry *qe)
Free qe.
static void handle_record_store_response(void *cls, const struct RecordStoreResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.
static void warn_delay(void *cls)
Task launched to warn the user that the namestore is excessively slow and that a query was thus dropp...
static int check_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
static void handle_record_result_end(void *cls, const struct GNUNET_NAMESTORE_Header *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT_END.
static void free_ze(struct GNUNET_NAMESTORE_ZoneIterator *ze)
Free ze.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static int check_rd(size_t rd_len, const void *rd_buf, unsigned int rd_count)
Check that rd_buf of length rd_len contains rd_count records.
static int check_zone_to_name_response(void *cls, const struct ZoneToNameResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_TO_NAME_RESPONSE.
static void handle_lookup_result(void *cls, const struct LabelLookupResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_LOOKUP_RESPONSE.
static void reconnect(struct GNUNET_NAMESTORE_Handle *h)
Reconnect to namestore service.
static void force_reconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from service and then reconnect.
static int check_record_store_response(void *cls, const struct RecordStoreResponseMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_STORE_RESPONSE.
static struct GNUNET_NAMESTORE_ZoneIterator * find_zi(struct GNUNET_NAMESTORE_Handle *h, uint32_t rid)
Find the zone iteration entry that matches the rid.
static uint32_t get_op_id(struct GNUNET_NAMESTORE_Handle *h)
Get a fresh operation id to distinguish between namestore requests.
static void handle_record_result(void *cls, const struct RecordResultMessage *msg)
Handle an incoming message of type GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
static void reconnect_task(void *cls)
Re-establish the connection to the service.
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
struct GNUNET_DATASTORE_Handle * h
Handle to the master context.
struct GNUNET_MQ_Envelope * env
Envelope of the request to transmit, NULL after transmission.
struct GNUNET_DATASTORE_QueueEntry * next
This is a linked list.
GNUNET_DATASTORE_ContinuationWithStatus cont
Function to call after transmission of the request.
void * cont_cls
Closure for cont.
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
Handle to a message queue.
Message handler for a specific message type.
Connection to the NAMESTORE service.
uint32_t last_op_id_used
The last operation id used for a NAMESTORE operation.
struct GNUNET_NAMESTORE_ZoneIterator * z_head
Head of pending namestore zone iterator entries.
struct GNUNET_NAMESTORE_QueueEntry * op_tail
Tail of pending namestore queue entries.
struct GNUNET_SCHEDULER_Task * reconnect_task
Reconnect task.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
struct GNUNET_NAMESTORE_QueueEntry * op_head
Head of pending namestore queue entries.
struct GNUNET_TIME_Relative reconnect_delay
Delay introduced before we reconnect.
struct GNUNET_NAMESTORE_ZoneIterator * z_tail
Tail of pending namestore zone iterator entries.
int reconnect
Should we reconnect to service due to some serious error?
struct GNUNET_MQ_Handle * mq
Connection to the service (if available).
An QueueEntry used to store information for a pending NAMESTORE record operation.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
struct GNUNET_NAMESTORE_QueueEntry * prev
Kept in a DLL.
uint32_t op_id
The operation id this zone iteration operation has.
void * error_cb_cls
Closure for error_cb.
GNUNET_NAMESTORE_RecordMonitor proc
Function to call with the records we get back; or NULL.
struct GNUNET_NAMESTORE_QueueEntry * next
Kept in a DLL.
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
GNUNET_NAMESTORE_ContinuationWithStatus cont
Continuation to call.
struct GNUNET_SCHEDULER_Task * timeout_task
Task scheduled to warn us if the namestore is way too slow.
void * cont_cls
Closure for cont.
void * proc_cls
Closure for proc.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
Handle for a zone iterator operation.
void * finish_cb_cls
Closure for error_cb.
void * error_cb_cls
Closure for error_cb.
struct GNUNET_NAMESTORE_ZoneIterator * next
Kept in a DLL.
struct GNUNET_NAMESTORE_Handle * h
Main handle to access the namestore.
void * proc_cls
Closure for proc.
uint32_t op_id
The operation id this zone iteration operation has.
struct GNUNET_IDENTITY_PrivateKey zone
Private key of the zone.
GNUNET_NAMESTORE_RecordMonitor proc
The continuation to call with the results.
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
struct GNUNET_MQ_Envelope * env
Envelope of the message to send to the service, if not yet sent.
GNUNET_SCHEDULER_TaskCallback finish_cb
Function to call on completion.
struct GNUNET_NAMESTORE_ZoneIterator * prev
Kept in a DLL.
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
uint32_t label_len
Length of the name.
Record is returned from the namestore (as authority).
Store a record to the namestore (as authority).
uint16_t rd_count
Number of records contained.
uint16_t name_len
Name length.
Response to a record storage request.
Ask for next result of zone iteration for the given operation.
Start a zone iteration for the given zone.
Stop zone iteration for the given operation.
Lookup a name for a zone hash.
struct GNUNET_IDENTITY_PublicKey value_zone
The public key of the target zone.
Respone for zone to name lookup.