GNUnet  0.16.x
Data Structures | Macros | Functions
dht_api.c File Reference

library to access the DHT service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_signatures.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_dht_service.h"
#include "dht.h"
Include dependency graph for dht_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_DHT_PutHandle
 Handle to a PUT request. More...
 
struct  GNUNET_DHT_GetHandle
 Handle to a GET request. More...
 
struct  GNUNET_DHT_MonitorHandle
 Handle to a monitoring request. More...
 
struct  GNUNET_DHT_HelloGetHandle
 Handle to get a HELLO URL from the DHT for manual bootstrapping. More...
 
struct  GNUNET_DHT_Handle
 Connection to the DHT service. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "dht-api", __VA_ARGS__)
 

Functions

static enum GNUNET_GenericReturnValue try_connect (struct GNUNET_DHT_Handle *h)
 Try to (re)connect to the DHT service. More...
 
static void send_get (struct GNUNET_DHT_GetHandle *gh)
 Send GET message for a get_handle to DHT. More...
 
static void send_get_known_results (struct GNUNET_DHT_GetHandle *gh, unsigned int transmission_offset_start)
 Send GET message(s) for indicating which results are already known for a get_handle to DHT. More...
 
static enum GNUNET_GenericReturnValue add_get_request_to_pending (void *cls, const struct GNUNET_HashCode *key, void *value)
 Add the GET request corresponding to the given route handle to the pending queue (if it is not already in there). More...
 
static void send_monitor_start (struct GNUNET_DHT_MonitorHandle *mh)
 Send GNUNET_MESSAGE_TYPE_DHT_MONITOR_START message. More...
 
static void try_reconnect (void *cls)
 Try reconnecting to the dht service. More...
 
static void do_disconnect (struct GNUNET_DHT_Handle *h)
 Try reconnecting to the DHT service. More...
 
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 creation of the message queue. More...
 
static enum GNUNET_GenericReturnValue check_monitor_get (void *cls, const struct GNUNET_DHT_MonitorGetMessage *msg)
 Verify integrity of a get monitor message from the service. More...
 
static void handle_monitor_get (void *cls, const struct GNUNET_DHT_MonitorGetMessage *msg)
 Process a get monitor message from the service. More...
 
static enum GNUNET_GenericReturnValue check_monitor_get_resp (void *cls, const struct GNUNET_DHT_MonitorGetRespMessage *msg)
 Validate a get response monitor message from the service. More...
 
static void handle_monitor_get_resp (void *cls, const struct GNUNET_DHT_MonitorGetRespMessage *msg)
 Process a get response monitor message from the service. More...
 
static enum GNUNET_GenericReturnValue check_monitor_put (void *cls, const struct GNUNET_DHT_MonitorPutMessage *msg)
 Check validity of a put monitor message from the service. More...
 
static void handle_monitor_put (void *cls, const struct GNUNET_DHT_MonitorPutMessage *msg)
 Process a put monitor message from the service. More...
 
static enum GNUNET_GenericReturnValue check_client_result (void *cls, const struct GNUNET_DHT_ClientResultMessage *msg)
 Verify that client result message received from the service is well-formed. More...
 
static enum GNUNET_GenericReturnValue process_client_result (void *cls, const struct GNUNET_HashCode *key, void *value)
 Process a given reply that might match the given request. More...
 
static void handle_client_result (void *cls, const struct GNUNET_DHT_ClientResultMessage *msg)
 Process a client result message received from the service. More...
 
static enum GNUNET_GenericReturnValue check_client_hello (void *cls, const struct GNUNET_MessageHeader *hdr)
 Process a client HELLO message received from the service. More...
 
static void handle_client_hello (void *cls, const struct GNUNET_MessageHeader *hdr)
 Process a client HELLO message received from the service. More...
 
static void handle_put_cont (void *cls)
 Process a MQ PUT transmission notification. More...
 
struct GNUNET_DHT_HandleGNUNET_DHT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
 Initialize the connection with the DHT service. More...
 
void GNUNET_DHT_disconnect (struct GNUNET_DHT_Handle *handle)
 Shutdown connection with the DHT service. More...
 
struct GNUNET_DHT_PutHandleGNUNET_DHT_put (struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const void *data, struct GNUNET_TIME_Absolute exp, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
 Perform a PUT operation storing data in the DHT. More...
 
void GNUNET_DHT_put_cancel (struct GNUNET_DHT_PutHandle *ph)
 Cancels a DHT PUT operation. More...
 
struct GNUNET_DHT_GetHandleGNUNET_DHT_get_start (struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
 Perform an asynchronous GET operation on the DHT identified. More...
 
void GNUNET_DHT_get_filter_known_results (struct GNUNET_DHT_GetHandle *get_handle, unsigned int num_results, const struct GNUNET_HashCode *results)
 Tell the DHT not to return any of the following known results to this client. More...
 
void GNUNET_DHT_get_stop (struct GNUNET_DHT_GetHandle *get_handle)
 Stop async DHT-get. More...
 
struct GNUNET_DHT_MonitorHandleGNUNET_DHT_monitor_start (struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, GNUNET_DHT_MonitorGetCB get_cb, GNUNET_DHT_MonitorGetRespCB get_resp_cb, GNUNET_DHT_MonitorPutCB put_cb, void *cb_cls)
 Start monitoring the local DHT service. More...
 
void GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *mh)
 Stop monitoring. More...
 
char * GNUNET_DHT_pp2s (const struct GNUNET_DHT_PathElement *path, unsigned int path_len)
 Convert a peer path to a human-readable string. More...
 
unsigned int GNUNET_DHT_verify_path (const void *data, size_t data_size, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_DHT_PathElement *put_path, unsigned int put_path_len, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_len, const struct GNUNET_PeerIdentity *me)
 Verify signatures on a path consisting of put_path and get_path in reverse order (starting at the last element of the get_path). More...
 
struct GNUNET_DHT_HelloGetHandleGNUNET_DHT_hello_get (struct GNUNET_DHT_Handle *dht_handle, GNUNET_DHT_HelloGetCallback cb, void *cb_cls)
 Obtain HELLO URL of the DHT identified by dht_handle. More...
 
void GNUNET_DHT_hello_get_cancel (struct GNUNET_DHT_HelloGetHandle *hgh)
 Cancel hello get operation. More...
 
void GNUNET_DHT_hello_offer (struct GNUNET_DHT_Handle *dht_handle, const char *url, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
 Offer HELLO URL of the DHT identified by dht_handle. More...
 

Detailed Description

library to access the DHT service

Author
Christian Grothoff
Nathan Evans

Definition in file dht_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "dht-api", __VA_ARGS__)

Definition at line 38 of file dht_api.c.

Function Documentation

◆ try_connect()

static enum GNUNET_GenericReturnValue try_connect ( struct GNUNET_DHT_Handle h)
static

Try to (re)connect to the DHT service.

Parameters
hDHT handle to reconnect
Returns
GNUNET_YES on success, GNUNET_NO on failure.

Definition at line 923 of file dht_api.c.

946 {
948  GNUNET_MQ_hd_var_size (monitor_get,
951  h),
952  GNUNET_MQ_hd_var_size (monitor_get_resp,
955  h),
956  GNUNET_MQ_hd_var_size (monitor_put,
959  h),
960  GNUNET_MQ_hd_var_size (client_result,
963  h),
964  GNUNET_MQ_hd_var_size (client_hello,
966  struct GNUNET_MessageHeader,
967  h),
969  };
970 
971  if (NULL != h->mq)
972  return GNUNET_OK;
974  "dht",
975  handlers,
977  h);
978  if (NULL == h->mq)
979  {
981  "Failed to connect to the DHT service!\n");
982  return GNUNET_NO;
983  }
984  return GNUNET_YES;
985 }
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...
Definition: dht_api.c:519
#define LOG(kind,...)
Definition: dht_api.c:38
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
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.
Definition: client.c:1066
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET
Receive information about transiting GETs.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP
Receive information about transiting GET responses.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
Receive information about transiting PUTs.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT
Service returns result to client.
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL
HELLO URL send between client and service (in either direction).
struct GNUNET_MQ_Handle * mq
Our connection to the ARM service.
Definition: arm_api.c:107
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Definition: arm_api.c:112
Reply to a GET send from the service to a client.
Definition: dht.h:144
Message to monitor get requests going through peer, DHT service -> clients.
Definition: dht.h:324
Message to monitor get results going through peer, DHT service -> clients.
Definition: dht.h:368
Message to monitor put requests going through peer, DHT service -> clients.
Definition: dht.h:229
Message handler for a specific message type.
Header for all communications.

Referenced by GNUNET_DHT_connect(), and try_reconnect().

Here is the caller graph for this function:

◆ send_get()

static void send_get ( struct GNUNET_DHT_GetHandle gh)
static

Send GET message for a get_handle to DHT.

Parameters
ghGET to generate messages for.

Definition at line 318 of file dht_api.c.

319 {
320  struct GNUNET_DHT_Handle *h = gh->dht_handle;
321  struct GNUNET_MQ_Envelope *env;
322  struct GNUNET_DHT_ClientGetMessage *get_msg;
323 
324  env = GNUNET_MQ_msg_extra (get_msg,
325  gh->xquery_size,
327  get_msg->options = htonl ((uint32_t) gh->options);
328  get_msg->desired_replication_level = htonl (gh->desired_replication_level);
329  get_msg->type = htonl (gh->type);
330  get_msg->key = gh->key;
331  get_msg->unique_id = gh->unique_id;
332  GNUNET_memcpy (&get_msg[1],
333  &gh[1],
334  gh->xquery_size);
335  GNUNET_MQ_send (h->mq,
336  env);
337 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:302
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:52
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET
Client wants to lookup item in DHT.
DHT GET message sent from clients to service.
Definition: dht.h:72
uint64_t unique_id
Unique ID identifying this request, if 0 then the client will not expect a response.
Definition: dht.h:103
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition: dht.h:81
struct GNUNET_HashCode key
The key to search for.
Definition: dht.h:97
uint32_t type
The type for the data for the GET request; actually an 'enum GNUNET_BLOCK_Type'.
Definition: dht.h:92
uint32_t desired_replication_level
Replication level for this message.
Definition: dht.h:86
Connection to the DHT service.
Definition: dht_api.c:237

References GNUNET_DHT_ClientGetMessage::desired_replication_level, env, gh, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), h, GNUNET_DHT_ClientGetMessage::key, GNUNET_ARM_Handle::mq, GNUNET_DHT_ClientGetMessage::options, GNUNET_DHT_ClientGetMessage::type, and GNUNET_DHT_ClientGetMessage::unique_id.

Referenced by GNUNET_DHT_get_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_get_known_results()

static void send_get_known_results ( struct GNUNET_DHT_GetHandle gh,
unsigned int  transmission_offset_start 
)
static

Send GET message(s) for indicating which results are already known for a get_handle to DHT.

Complex as we need to send the list of known results, which means we may need multiple messages to block known results from the result set.

Parameters
ghGET to generate messages for
transmission_offset_startat which offset should we start?

Definition at line 350 of file dht_api.c.

352 {
353  struct GNUNET_DHT_Handle *h = gh->dht_handle;
354  struct GNUNET_MQ_Envelope *env;
356  unsigned int delta;
357  unsigned int max;
358  unsigned int transmission_offset;
359 
360  max = (GNUNET_MAX_MESSAGE_SIZE - sizeof(*msg))
361  / sizeof(struct GNUNET_HashCode);
362  transmission_offset = transmission_offset_start;
363  while (transmission_offset < gh->seen_results_end)
364  {
365  delta = gh->seen_results_end - transmission_offset;
366  if (delta > max)
367  delta = max;
369  delta * sizeof(struct GNUNET_HashCode),
371  msg->key = gh->key;
372  msg->unique_id = gh->unique_id;
373  GNUNET_memcpy (&msg[1],
374  &gh->seen_results[transmission_offset],
375  sizeof(struct GNUNET_HashCode) * delta);
376  GNUNET_MQ_send (h->mq,
377  env);
378  transmission_offset += delta;
379  }
380 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN
Certain results are already known to the client, filter those.
#define max(x, y)
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:35
DHT GET RESULTS KNOWN message sent from clients to service.
Definition: dht.h:114
A 512-bit hashcode.

Referenced by GNUNET_DHT_get_filter_known_results().

Here is the caller graph for this function:

◆ add_get_request_to_pending()

static enum GNUNET_GenericReturnValue add_get_request_to_pending ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Add the GET request corresponding to the given route handle to the pending queue (if it is not already in there).

Parameters
clsthe struct GNUNET_DHT_Handle *
keykey for the request (not used)
valuethe struct GNUNET_DHT_GetHandle *
Returns
GNUNET_YES (always)

Definition at line 350 of file dht_api.c.

396 {
397  struct GNUNET_DHT_Handle *handle = cls;
398  struct GNUNET_DHT_GetHandle *gh = value;
399 
401  "Retransmitting request related to %s to DHT %p\n",
402  GNUNET_h2s (key),
403  handle);
404  send_get (gh);
406  return GNUNET_YES;
407 }
static void send_get(struct GNUNET_DHT_GetHandle *gh)
Send GET message for a get_handle to DHT.
Definition: dht_api.c:318
static void send_get_known_results(struct GNUNET_DHT_GetHandle *gh, unsigned int transmission_offset_start)
Send GET message(s) for indicating which results are already known for a get_handle to DHT.
Definition: dht_api.c:350
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static char * value
Value of the record to add/remove.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
Handle to a GET request.
Definition: dht_api.c:81

References delta, env, gh, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), h, max, GNUNET_ARM_Handle::mq, and msg.

Referenced by try_reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_monitor_start()

static void send_monitor_start ( struct GNUNET_DHT_MonitorHandle mh)
static

Send GNUNET_MESSAGE_TYPE_DHT_MONITOR_START message.

Parameters
mhmonitor handle to generate start message for

Definition at line 416 of file dht_api.c.

417 {
418  struct GNUNET_DHT_Handle *h = mh->dht_handle;
419  struct GNUNET_MQ_Envelope *env;
421 
422  env = GNUNET_MQ_msg (m,
424  m->type = htonl (mh->type);
425  m->get = htons (NULL != mh->get_cb);
426  m->get_resp = htons (NULL != mh->get_resp_cb);
427  m->put = htons (NULL != mh->put_cb);
428  if (NULL != mh->key)
429  {
430  m->filter_key = htons (1);
431  m->key = *mh->key;
432  }
433  GNUNET_MQ_send (h->mq,
434  env);
435 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_START
Request information about transiting messages.
Message to request monitoring messages, clients -> DHT service.
Definition: dht.h:281

References env, GNUNET_MESSAGE_TYPE_DHT_MONITOR_START, GNUNET_MQ_msg, GNUNET_MQ_send(), h, m, mh, and GNUNET_ARM_Handle::mq.

Referenced by GNUNET_DHT_monitor_start(), and try_reconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_reconnect()

static void try_reconnect ( void *  cls)
static

Try reconnecting to the dht service.

Parameters
clsa struct GNUNET_DHT_Handle

Definition at line 444 of file dht_api.c.

445 {
446  struct GNUNET_DHT_Handle *h = cls;
448 
450  "Reconnecting with DHT %p\n",
451  h);
452  h->retry_time = GNUNET_TIME_STD_BACKOFF (h->retry_time);
453  h->reconnect_task = NULL;
454  if (GNUNET_YES != try_connect (h))
455  {
457  "DHT reconnect failed!\n");
459  = GNUNET_SCHEDULER_add_delayed (h->retry_time,
460  &try_reconnect,
461  h);
462  return;
463  }
464  GNUNET_CONTAINER_multihashmap_iterate (h->active_requests,
466  h);
467  for (mh = h->monitor_head; NULL != mh; mh = mh->next)
469 }
static enum GNUNET_GenericReturnValue try_connect(struct GNUNET_DHT_Handle *h)
Try to (re)connect to the DHT service.
Definition: dht_api.c:945
static void try_reconnect(void *cls)
Try reconnecting to the dht service.
Definition: dht_api.c:444
static enum GNUNET_GenericReturnValue add_get_request_to_pending(void *cls, const struct GNUNET_HashCode *key, void *value)
Add the GET request corresponding to the given route handle to the pending queue (if it is not alread...
Definition: dht_api.c:393
static void send_monitor_start(struct GNUNET_DHT_MonitorHandle *mh)
Send GNUNET_MESSAGE_TYPE_DHT_MONITOR_START message.
Definition: dht_api.c:416
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
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.
Definition: scheduler.c:1254
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the reconnect task (if any).
Definition: arm_api.c:147
Handle to a monitoring request.
Definition: dht_api.c:151

References add_get_request_to_pending(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, h, LOG, mh, GNUNET_ARM_Handle::reconnect_task, send_monitor_start(), and try_connect().

Referenced by do_disconnect().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_disconnect()

static void do_disconnect ( struct GNUNET_DHT_Handle h)
static

Try reconnecting to the DHT service.

Parameters
hhandle to dht to (possibly) disconnect and reconnect

Definition at line 478 of file dht_api.c.

479 {
480  struct GNUNET_DHT_PutHandle *ph;
482  void *cont_cls;
483 
484  if (NULL == h->mq)
485  return;
487  h->mq = NULL;
489  "Disconnecting from DHT service, will try to reconnect in %s\n",
491  GNUNET_YES));
492  /* notify client about all PUTs that (may) have failed due to disconnect */
493  while (NULL != (ph = h->put_head))
494  {
495  cont = ph->cont;
496  cont_cls = ph->cont_cls;
497  ph->env = NULL;
499  if (NULL != cont)
500  cont (cont_cls);
501  }
502  GNUNET_assert (NULL == h->reconnect_task);
504  = GNUNET_SCHEDULER_add_delayed (h->retry_time,
505  &try_reconnect,
506  h);
507 }
static struct GNUNET_ATS_PerformanceHandle * ph
ATS performance handle used.
Definition: gnunet-ats.c:116
#define GNUNET_log(kind,...)
void GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
Cancels a DHT PUT operation.
Definition: dht_api.c:1098
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:685
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
Handle to a PUT request.
Definition: dht_api.c:45
void * cont_cls
Closure for cont.
Definition: dht_api.c:69
GNUNET_SCHEDULER_TaskCallback cont
Continuation to call when done.
Definition: dht_api.c:59

References GNUNET_DHT_PutHandle::cont, GNUNET_DHT_PutHandle::cont_cls, GNUNET_assert, GNUNET_DHT_put_cancel(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, h, GNUNET_ARM_Handle::mq, ph, GNUNET_ARM_Handle::reconnect_task, and try_reconnect().

Referenced by check_monitor_get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_DHT_Handle *
errorerror code

Definition at line 519 of file dht_api.c.

521 {
522  struct GNUNET_DHT_Handle *h = cls;
523 
524  do_disconnect (h);
525 }
static void do_disconnect(struct GNUNET_DHT_Handle *h)
Try reconnecting to the DHT service.
Definition: dht_api.c:478

◆ check_monitor_get()

static enum GNUNET_GenericReturnValue check_monitor_get ( void *  cls,
const struct GNUNET_DHT_MonitorGetMessage msg 
)
static

Verify integrity of a get monitor message from the service.

Parameters
clsThe DHT handle.
msgMonitor get message from the service.
Returns
GNUNET_OK if everything went fine, GNUNET_SYSERR if the message is malformed.

Definition at line 519 of file dht_api.c.

539 {
540  uint32_t plen = ntohl (msg->get_path_length);
541  uint16_t msize = ntohs (msg->header.size) - sizeof(*msg);
542 
543  if ((plen > UINT16_MAX) ||
544  (plen * sizeof(struct GNUNET_DHT_PathElement) != msize))
545  {
546  GNUNET_break (0);
547  return GNUNET_SYSERR;
548  }
549  return GNUNET_OK;
550 }
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.

References do_disconnect(), and h.

Here is the call graph for this function:

◆ handle_monitor_get()

static void handle_monitor_get ( void *  cls,
const struct GNUNET_DHT_MonitorGetMessage msg 
)
static

Process a get monitor message from the service.

Parameters
clsThe DHT handle.
msgMonitor get message from the service.

Definition at line 560 of file dht_api.c.

562 {
563  struct GNUNET_DHT_Handle *handle = cls;
564 
565  for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head;
566  NULL != mh;
567  mh = mh->next)
568  {
569  if (NULL == mh->get_cb)
570  continue;
571  if (((GNUNET_BLOCK_TYPE_ANY == mh->type) ||
572  (mh->type == ntohl (msg->type))) &&
573  ((NULL == mh->key) ||
574  (0 == memcmp (mh->key,
575  &msg->key,
576  sizeof(struct GNUNET_HashCode)))))
577  mh->get_cb (mh->cb_cls,
578  ntohl (msg->options),
579  (enum GNUNET_BLOCK_Type) ntohl (msg->type),
580  ntohl (msg->hop_count),
581  ntohl (msg->desired_replication_level),
582  ntohl (msg->get_path_length),
583  (struct GNUNET_DHT_PathElement *) &msg[1],
584  &msg->key);
585  }
586 }
GNUNET_BLOCK_Type
WARNING: This header is generated! In order to add DHT block types, you must register them in GANA,...
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.

◆ check_monitor_get_resp()

static enum GNUNET_GenericReturnValue check_monitor_get_resp ( void *  cls,
const struct GNUNET_DHT_MonitorGetRespMessage msg 
)
static

Validate a get response monitor message from the service.

Parameters
clsThe DHT handle.
msgmonitor get response message from the service
Returns
GNUNET_OK if everything went fine, GNUNET_SYSERR if the message is malformed.

Definition at line 560 of file dht_api.c.

600 {
601  size_t msize = ntohs (msg->header.size) - sizeof(*msg);
602  uint32_t getl = ntohl (msg->get_path_length);
603  uint32_t putl = ntohl (msg->put_path_length);
604 
605  if ((getl + putl < getl) ||
606  ((msize / sizeof(struct GNUNET_DHT_PathElement)) < getl + putl))
607  {
608  GNUNET_break (0);
609  return GNUNET_SYSERR;
610  }
611  return GNUNET_OK;
612 }

References GNUNET_BLOCK_TYPE_ANY, handle, mh, msg, and GNUNET_MessageHeader::type.

◆ handle_monitor_get_resp()

static void handle_monitor_get_resp ( void *  cls,
const struct GNUNET_DHT_MonitorGetRespMessage msg 
)
static

Process a get response monitor message from the service.

Parameters
clsThe DHT handle.
msgmonitor get response message from the service

Definition at line 622 of file dht_api.c.

624 {
625  struct GNUNET_DHT_Handle *handle = cls;
626  size_t msize = ntohs (msg->header.size) - sizeof(*msg);
627  const struct GNUNET_DHT_PathElement *path;
628  uint32_t getl = ntohl (msg->get_path_length);
629  uint32_t putl = ntohl (msg->put_path_length);
630 
631 
632  path = (const struct GNUNET_DHT_PathElement *) &msg[1];
633  for (struct GNUNET_DHT_MonitorHandle *mh = handle->monitor_head;
634  NULL != mh;
635  mh = mh->next)
636  {
637  if (NULL == mh->get_resp_cb)
638  continue;
639  if (((GNUNET_BLOCK_TYPE_ANY == mh->type) ||
640  (mh->type == ntohl (msg->type))) &&
641  ((NULL == mh->key) ||
642  (0 == memcmp (mh->key,
643  &msg->key,
644  sizeof(struct GNUNET_HashCode)))))
645  mh->get_resp_cb (mh->cb_cls,
646  (enum GNUNET_BLOCK_Type) ntohl (msg->type),
647  &path[putl],
648  getl,
649  path,
650  putl,
651  GNUNET_TIME_absolute_ntoh (msg->expiration_time),
652  &msg->key,
653  (const void *) &path[getl + putl],
654  msize - sizeof(struct GNUNET_DHT_PathElement) * (putl
655  + getl));
656  }
657 }
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:736

◆ check_monitor_put()

static enum GNUNET_GenericReturnValue check_monitor_put ( void *  cls,
const struct GNUNET_DHT_MonitorPutMessage msg 
)
static

Check validity of a put monitor message from the service.

Parameters
clsThe DHT handle.
msgMonitor put message from the service.
Returns
GNUNET_OK if everything went fine, GNUNET_SYSERR if the message is malformed.

Definition at line 622 of file dht_api.c.

671 {
672  size_t msize;
673  uint32_t putl;
674 
675  msize = ntohs (msg->header.size) - sizeof(*msg);
676  putl = ntohl (msg->put_path_length);
677  if ((msize / sizeof(struct GNUNET_DHT_PathElement)) < putl)
678  {
679  GNUNET_break (0);
680  return GNUNET_SYSERR;
681  }
682  return GNUNET_OK;
683 }

References GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_absolute_ntoh(), handle, mh, msg, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Here is the call graph for this function:

◆ handle_monitor_put()

static void handle_monitor_put ( void *  cls,
const struct GNUNET_DHT_MonitorPutMessage msg 
)
static

Process a put monitor message from the service.

Parameters
clsThe DHT handle.
msgMonitor put message from the service.

Definition at line 693 of file dht_api.c.

695 {
696  struct GNUNET_DHT_Handle *handle = cls;
697  size_t msize = ntohs (msg->header.size) - sizeof(*msg);
698  uint32_t putl = ntohl (msg->put_path_length);
699  const struct GNUNET_DHT_PathElement *path;
701 
702  path = (const struct GNUNET_DHT_PathElement *) &msg[1];
703  for (mh = handle->monitor_head; NULL != mh; mh = mh->next)
704  {
705  if (NULL == mh->put_cb)
706  continue;
707  if (((GNUNET_BLOCK_TYPE_ANY == mh->type) ||
708  (mh->type == ntohl (msg->type))) &&
709  ((NULL == mh->key) ||
710  (0 == memcmp (mh->key,
711  &msg->key,
712  sizeof(struct GNUNET_HashCode)))))
713  mh->put_cb (mh->cb_cls,
714  ntohl (msg->options),
715  (enum GNUNET_BLOCK_Type) ntohl (msg->type),
716  ntohl (msg->hop_count),
717  ntohl (msg->desired_replication_level),
718  putl,
719  path,
720  GNUNET_TIME_absolute_ntoh (msg->expiration_time),
721  &msg->key,
722  (const void *) &path[putl],
723  msize - sizeof(struct GNUNET_DHT_PathElement) * putl);
724  }
725 }

◆ check_client_result()

static enum GNUNET_GenericReturnValue check_client_result ( void *  cls,
const struct GNUNET_DHT_ClientResultMessage msg 
)
static

Verify that client result message received from the service is well-formed.

Parameters
clsThe DHT handle.
msgMonitor put message from the service.
Returns
GNUNET_OK if everything went fine, GNUNET_SYSERR if the message is malformed.

Definition at line 693 of file dht_api.c.

739 {
740  size_t msize = ntohs (msg->header.size) - sizeof(*msg);
741  uint32_t put_path_length = ntohl (msg->put_path_length);
742  uint32_t get_path_length = ntohl (msg->get_path_length);
743  size_t meta_length;
744 
745  meta_length =
746  sizeof(struct GNUNET_DHT_PathElement) * (get_path_length + put_path_length);
747  if ((msize < meta_length) ||
748  (get_path_length >
750  (put_path_length >
752  {
753  GNUNET_break (0);
754  return GNUNET_SYSERR;
755  }
756  return GNUNET_OK;
757 }

References GNUNET_BLOCK_TYPE_ANY, GNUNET_TIME_absolute_ntoh(), handle, mh, msg, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Here is the call graph for this function:

◆ process_client_result()

static enum GNUNET_GenericReturnValue process_client_result ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Process a given reply that might match the given request.

Parameters
clsthe struct GNUNET_DHT_ClientResultMessage
keyquery of the request
valuethe struct GNUNET_DHT_GetHandle of a request matching the same key
Returns
GNUNET_YES to continue to iterate over all results

Definition at line 693 of file dht_api.c.

772 {
773  const struct GNUNET_DHT_ClientResultMessage *crm = cls;
775  size_t msize = ntohs (crm->header.size) - sizeof(*crm);
776  uint16_t type = ntohl (crm->type);
777  uint32_t put_path_length = ntohl (crm->put_path_length);
778  uint32_t get_path_length = ntohl (crm->get_path_length);
779  const struct GNUNET_DHT_PathElement *put_path
780  = (const struct GNUNET_DHT_PathElement *) &crm[1];
781  const struct GNUNET_DHT_PathElement *get_path
782  = &put_path[put_path_length];
783  const void *data
784  = &get_path[get_path_length];
785  size_t meta_length
786  = sizeof(struct GNUNET_DHT_PathElement) * (get_path_length
787  + put_path_length);
788  size_t data_length
789  = msize - meta_length;
790  struct GNUNET_HashCode hc;
791 
792  if (crm->unique_id != get_handle->unique_id)
793  {
794  /* UID mismatch */
796  "Ignoring reply for %s: UID mismatch: %llu/%llu\n",
797  GNUNET_h2s (key),
798  (unsigned long long) crm->unique_id,
799  (unsigned long long) get_handle->unique_id);
800  return GNUNET_YES;
801  }
803  (get_handle->type != type) )
804  {
805  /* type mismatch */
806  GNUNET_break (0);
807  return GNUNET_YES;
808  }
809 
810  {
811  char *pp;
812  char *gp;
813 
814  gp = GNUNET_DHT_pp2s (get_path,
815  get_path_length);
816  pp = GNUNET_DHT_pp2s (put_path,
817  put_path_length);
819  "Giving %u byte reply for %s to application (GP: %s, PP: %s)\n",
820  (unsigned int) data_length,
821  GNUNET_h2s (key),
822  gp,
823  pp);
824  GNUNET_free (gp);
825  GNUNET_free (pp);
826  }
827  /* remember that we've seen this result */
829  data_length,
830  &hc);
834  get_handle->seen_results_size * 2 + 1);
836  /* no need to block it explicitly, service already knows about it! */
839  key,
840  get_path,
841  get_path_length,
842  put_path,
843  put_path_length,
844  type,
845  data_length,
846  data);
847  return GNUNET_YES;
848 }
static struct GNUNET_DHT_GetHandle * get_handle
Handle for the get request.
uint32_t data
The data value.
char * GNUNET_DHT_pp2s(const struct GNUNET_DHT_PathElement *path, unsigned int path_len)
Convert a peer path to a human-readable string.
Definition: dht_api.c:1280
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t put_path_length
Number of peers recorded in the outgoing path from source to the storgage location of this message.
Definition: dht.h:159
uint64_t unique_id
Unique ID of the matching GET request.
Definition: dht.h:170
struct GNUNET_TIME_AbsoluteNBO expiration
When does this entry expire?
Definition: dht.h:175
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT.
Definition: dht.h:148
uint32_t type
The type for the data.
Definition: dht.h:153
uint32_t get_path_length
The number of peer identities recorded from the storage location to this peer.
Definition: dht.h:165
GNUNET_DHT_GetIterator iter
Iterator to call on data receipt.
Definition: dht_api.c:85
enum GNUNET_BLOCK_Type type
Type of the block we are looking for.
Definition: dht_api.c:126
void * iter_cls
Closure for iter.
Definition: dht_api.c:90
unsigned int seen_results_end
Offset into the seen_results array marking the end of the positions that are actually used.
Definition: dht_api.c:143
struct GNUNET_HashCode * seen_results
Array of hash codes over the results that we have already seen.
Definition: dht_api.c:101
uint64_t unique_id
Unique identifier for this request (for key collisions).
Definition: dht_api.c:111
unsigned int seen_results_size
Size of the seen_results array.
Definition: dht_api.c:137
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

Referenced by check_client_hello().

Here is the caller graph for this function:

◆ handle_client_result()

static void handle_client_result ( void *  cls,
const struct GNUNET_DHT_ClientResultMessage msg 
)
static

Process a client result message received from the service.

Parameters
clsThe DHT handle.
msgMonitor put message from the service.

Definition at line 858 of file dht_api.c.

860 {
861  struct GNUNET_DHT_Handle *handle = cls;
862 
864  &msg->key,
866  (void *) msg);
867 }
static enum GNUNET_GenericReturnValue process_client_result(void *cls, const struct GNUNET_HashCode *key, void *value)
Process a given reply that might match the given request.
Definition: dht_api.c:769
int GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.

◆ check_client_hello()

static enum GNUNET_GenericReturnValue check_client_hello ( void *  cls,
const struct GNUNET_MessageHeader hdr 
)
static

Process a client HELLO message received from the service.

Parameters
clsThe DHT handle.
hdrHELLO URL message from the service.
Returns
GNUNET_OK if hdr is well-formed

Definition at line 858 of file dht_api.c.

880 {
881  uint16_t len = ntohs (hdr->size);
882  const char *buf = (const char *) &hdr[1];
883 
884  (void) cls;
885  if ('\0' != buf[len - sizeof (*hdr) - 1])
886  {
887  GNUNET_break (0);
888  return GNUNET_SYSERR;
889  }
890  return GNUNET_OK;
891 }
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
static char buf[2048]

References GNUNET_CONTAINER_multihashmap_get_multiple(), handle, msg, and process_client_result().

Here is the call graph for this function:

◆ handle_client_hello()

static void handle_client_hello ( void *  cls,
const struct GNUNET_MessageHeader hdr 
)
static

Process a client HELLO message received from the service.

Parameters
clsThe DHT handle.
hdrHELLO URL message from the service.

Definition at line 901 of file dht_api.c.

903 {
904  struct GNUNET_DHT_Handle *handle = cls;
905  const char *url = (const char *) &hdr[1];
906  struct GNUNET_DHT_HelloGetHandle *hgh;
907 
908  while (NULL != (hgh = handle->hgh_head))
909  {
910  hgh->cb (hgh->cb_cls,
911  url);
913  }
914 }
void GNUNET_DHT_hello_get_cancel(struct GNUNET_DHT_HelloGetHandle *hgh)
Cancel hello get operation.
Definition: dht_api.c:1401
Handle to get a HELLO URL from the DHT for manual bootstrapping.
Definition: dht_api.c:203
GNUNET_DHT_HelloGetCallback cb
Function to call with the result.
Definition: dht_api.c:218
void * cb_cls
Closure for cb.
Definition: dht_api.c:223

References GNUNET_DHT_HelloGetHandle::cb, GNUNET_DHT_HelloGetHandle::cb_cls, GNUNET_DHT_hello_get_cancel(), and handle.

Here is the call graph for this function:

◆ handle_put_cont()

static void handle_put_cont ( void *  cls)
static

Process a MQ PUT transmission notification.

Parameters
clsThe DHT handle.

Definition at line 923 of file dht_api.c.

924 {
925  struct GNUNET_DHT_PutHandle *ph = cls;
927  void *cont_cls;
928 
929  cont = ph->cont;
930  cont_cls = ph->cont_cls;
931  ph->env = NULL;
933  if (NULL != cont)
934  cont (cont_cls);
935 }

References GNUNET_DHT_PutHandle::cont, GNUNET_DHT_PutHandle::cont_cls, GNUNET_DHT_put_cancel(), and ph.

Referenced by GNUNET_DHT_put().

Here is the call graph for this function:
Here is the caller graph for this function: