GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
gnunet-service-dht_clients.c File Reference

GNUnet DHT service's client management code. More...

Include dependency graph for gnunet-service-dht_clients.c:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ClientQueryRecord
 Entry in the local forwarding map for a client's GET request. More...
 
struct  ClientMonitorRecord
 Struct containing parameters of monitoring requests. More...
 
struct  ClientHandle
 Struct containing information about a client, handle to connect to it, and any pending messages that need to be sent to it. More...
 
struct  FindByUniqueIdContext
 Closure for find_by_unique_id(). More...
 
struct  RemoveByUniqueIdContext
 Closure for remove_by_unique_id(). More...
 
struct  ForwardReplyContext
 Closure for forward_reply() More...
 
struct  GetActionContext
 Closure for get_action();. More...
 
struct  ResponseActionContext
 Closure for response_action(). More...
 
struct  PutActionContext
 Closure for put_action(). More...
 

Macros

#define SANITY_CHECKS   0
 Enable slow sanity checks to debug issues.
 
#define LOG_TRAFFIC(kind, ...)
 Should routing details be logged to stderr (for debugging)?
 
#define LOG(kind, ...)   GNUNET_log_from (kind, "dht-clients", __VA_ARGS__)
 
#define GDS_DHT_SERVICE_INIT(name, run)
 Define "main" method using service macro.
 

Typedefs

typedef void(* MonitorAction) (void *cls, struct ClientMonitorRecord *m)
 Function to call by for_matching_monitors().
 

Functions

static void remove_client_query_record (struct ClientQueryRecord *record)
 Free data structures associated with the given query.
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Functions with this signature are called whenever a local client is connects to us.
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 Functions with this signature are called whenever a client is disconnected on the network level.
 
static void transmit_request (struct ClientQueryRecord *cqr)
 Route the given request via the DHT.
 
static void transmit_next_request_task (void *cls)
 Task that looks at the retry_heap and transmits all of the requests on the heap that are ready for transmission.
 
static enum GNUNET_GenericReturnValue check_dht_local_put (void *cls, const struct GNUNET_DHT_ClientPutMessage *dht_msg)
 Check DHT PUT messages from the client.
 
static void cb_forwarded_dht_local_put (void *cls, enum GNUNET_GenericReturnValue forwarded)
 
static void handle_dht_local_put (void *cls, const struct GNUNET_DHT_ClientPutMessage *dht_msg)
 Handler for PUT messages.
 
static void handle_local_result (void *cls, const struct GNUNET_DATACACHE_Block *bd)
 Handle a result from local datacache for a GET operation.
 
static enum GNUNET_GenericReturnValue check_dht_local_get (void *cls, const struct GNUNET_DHT_ClientGetMessage *get)
 Check DHT GET messages from the client.
 
static void handle_dht_local_get (void *cls, const struct GNUNET_DHT_ClientGetMessage *get)
 Handler for DHT GET messages from the client.
 
static enum GNUNET_GenericReturnValue find_by_unique_id (void *cls, const struct GNUNET_HashCode *key, void *value)
 Function called for each existing DHT record for the given query.
 
static enum GNUNET_GenericReturnValue check_dht_local_get_result_seen (void *cls, const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
 Check "GET result seen" messages from the client.
 
static void handle_dht_local_get_result_seen (void *cls, const struct GNUNET_DHT_ClientGetResultSeenMessage *seen)
 Handler for "GET result seen" messages from the client.
 
static enum GNUNET_GenericReturnValue remove_by_unique_id (void *cls, const struct GNUNET_HashCode *key, void *value)
 Iterator over hash map entries that frees all entries that match the given client and unique ID.
 
static void handle_dht_local_get_stop (void *cls, const struct GNUNET_DHT_ClientGetStopMessage *dht_stop_msg)
 Handler for any generic DHT stop messages, calls the appropriate handler depending on message type (if processed locally)
 
static enum GNUNET_GenericReturnValue forward_reply (void *cls, const struct GNUNET_HashCode *query_hash, void *value)
 Iterator over hash map entries that send a given reply to each of the matching clients.
 
bool GDS_CLIENTS_handle_reply (const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path)
 Handle a reply we've received from another peer.
 
static void handle_dht_local_hello_get (void *cls, const struct GNUNET_MessageHeader *msg)
 Handler for HELLO GET message.
 
static enum GNUNET_GenericReturnValue check_dht_local_hello_offer (void *cls, const struct GNUNET_MessageHeader *hdr)
 Process a client HELLO message received from the service.
 
static void handle_dht_local_hello_offer (void *cls, const struct GNUNET_MessageHeader *msg)
 Handler for HELLO OFFER message.
 
static void handle_dht_local_monitor (void *cls, const struct GNUNET_DHT_MonitorStartStopMessage *msg)
 Handler for monitor start messages.
 
static void handle_dht_local_monitor_stop (void *cls, const struct GNUNET_DHT_MonitorStartStopMessage *msg)
 Handler for monitor stop messages.
 
static void for_matching_monitors (enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, MonitorAction cb, void *cb_cls)
 Call cb on all monitors that watch for blocks of type and key key.
 
static void get_action (void *cls, struct ClientMonitorRecord *m)
 Function called on monitors that match a GET.
 
void GDS_CLIENTS_process_get (enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, const struct GNUNET_HashCode *key)
 Check if some client is monitoring GET messages and notify them in that case.
 
static void response_action (void *cls, struct ClientMonitorRecord *m)
 Function called on monitors that match a response.
 
void GDS_CLIENTS_process_get_resp (const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_DHT_PathElement *get_path, unsigned int get_path_length)
 Check if some client is monitoring GET RESP messages and notify them in that case.
 
static void put_action (void *cls, struct ClientMonitorRecord *m)
 Function called on monitors that match a PUT.
 
void GDS_CLIENTS_process_put (const struct GNUNET_DATACACHE_Block *bd, uint32_t hop_count, uint32_t desired_replication_level)
 Check if some client is monitoring PUT messages and notify them in that case.
 
void GDS_CLIENTS_init (void)
 Initialize client subsystem.
 
void GDS_CLIENTS_stop (void)
 Shutdown client subsystem.
 
void GDS_CLIENTS_done (void)
 
void __attribute__ ((destructor))
 MINIMIZE heap size (way below 128k) since this process doesn't need much.
 

Variables

struct GNUNET_BLOCK_ContextGDS_block_context
 Our handle to the BLOCK library.
 
struct GNUNET_STATISTICS_HandleGDS_stats
 Handle for the statistics service.
 
struct GNUNET_PILS_HandleGDS_pils
 Handle for the pils service.
 
struct GNUNET_SERVICE_HandleGDS_service
 Handle for the service.
 
const struct GNUNET_CONFIGURATION_HandleGDS_cfg
 The configuration the DHT service is running with.
 
static struct ClientMonitorRecordmonitor_head
 List of active monitoring requests.
 
static struct ClientMonitorRecordmonitor_tail
 List of active monitoring requests.
 
static struct GNUNET_CONTAINER_MultiHashMapforward_map
 Hashmap for fast key based lookup, maps keys to struct ClientQueryRecord entries.
 
static struct GNUNET_CONTAINER_Heapretry_heap
 Heap with all of our client's request, sorted by retry time (earliest on top).
 
static struct GNUNET_SCHEDULER_Taskretry_task
 Task that re-transmits requests (using retry_heap).
 

Detailed Description

GNUnet DHT service's client management code.

Author
Christian Grothoff
Nathan Evans

Definition in file gnunet-service-dht_clients.c.

Macro Definition Documentation

◆ SANITY_CHECKS

#define SANITY_CHECKS   0

Enable slow sanity checks to debug issues.

0: do not check 1: check all external inputs 2: check internal computations as well

Definition at line 37 of file gnunet-service-dht_clients.c.

◆ LOG_TRAFFIC

#define LOG_TRAFFIC (   kind,
  ... 
)
Value:
GNUNET_log_from (kind, "dht-traffic", \
__VA_ARGS__)
#define GNUNET_log_from(kind, comp,...)

Should routing details be logged to stderr (for debugging)?

Definition at line 42 of file gnunet-service-dht_clients.c.

◆ LOG

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

Definition at line 45 of file gnunet-service-dht_clients.c.

◆ GDS_DHT_SERVICE_INIT

#define GDS_DHT_SERVICE_INIT (   name,
  run 
)

Define "main" method using service macro.

Parameters
namename of the service, like "dht" or "xdht"
runname of the initialization method for the service

Definition at line 1682 of file gnunet-service-dht_clients.c.

Typedef Documentation

◆ MonitorAction

typedef void(* MonitorAction) (void *cls, struct ClientMonitorRecord *m)

Function to call by for_matching_monitors().

Parameters
clsclosure
ma matching monitor

Definition at line 1348 of file gnunet-service-dht_clients.c.

Function Documentation

◆ remove_client_query_record()

static void remove_client_query_record ( struct ClientQueryRecord record)
static

Free data structures associated with the given query.

Parameters
recordrecord to remove

Definition at line 273 of file gnunet-service-dht_clients.c.

274{
275 struct ClientHandle *ch = record->ch;
276
278 ch->cqr_tail,
279 record);
282 &record->key,
283 record));
284 if (NULL != record->hnode)
286 GNUNET_array_grow (record->seen_replies,
287 record->seen_replies_count,
288 0);
290}
static struct GNUNET_CADET_Channel * ch
Channel handle.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct GNUNET_CONTAINER_MultiHashMap * forward_map
Hashmap for fast key based lookup, maps keys to struct ClientQueryRecord entries.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_remove(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Remove the given key-value pair from the map.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
@ GNUNET_YES
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_free(ptr)
Wrapper around free.
Struct containing information about a client, handle to connect to it, and any pending messages that ...

References ch, forward_map, GNUNET_array_grow, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_YES, and record().

Referenced by client_disconnect_cb(), forward_reply(), and remove_by_unique_id().

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

◆ client_connect_cb()

static void * client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Functions with this signature are called whenever a local client is connects to us.

Parameters
clsclosure (NULL for dht)
clientidentification of the client
mqmessage queue for talking to client
Returns
our struct ClientHandle for client

Definition at line 303 of file gnunet-service-dht_clients.c.

306{
307 struct ClientHandle *ch;
308
309 (void) cls;
310 ch = GNUNET_new (struct ClientHandle);
311 ch->client = client;
312 ch->mq = mq;
313 return ch;
314}
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
struct GNUNET_SERVICE_Client * client
The handle to this client.
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition cadet.h:142

References ch, ClientHandle::client, GNUNET_new, mq, and GNUNET_CADET_Channel::mq.

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_ctx 
)
static

Functions with this signature are called whenever a client is disconnected on the network level.

Parameters
clsclosure (NULL for dht)
clientidentification of the client
app_ctxour struct ClientHandle for client

Definition at line 326 of file gnunet-service-dht_clients.c.

329{
330 struct ClientHandle *ch = app_ctx;
331
332 (void) cls;
333 (void) client;
335 "Local client %p disconnects\n",
336 ch);
337 {
339
341 NULL != monitor;
342 monitor = next)
343 {
344 next = monitor->next;
345 if (monitor->ch != ch)
346 continue;
349 monitor);
351 }
352 }
353
354 {
355 struct ClientQueryRecord *cqr;
356
357 while (NULL != (cqr = ch->cqr_head))
359 }
360 GNUNET_free (ch);
361}
static int monitor
Monitor ARM activity.
Definition gnunet-arm.c:63
static struct ClientMonitorRecord * monitor_head
List of active monitoring requests.
static struct ClientMonitorRecord * monitor_tail
List of active monitoring requests.
static void remove_client_query_record(struct ClientQueryRecord *record)
Free data structures associated with the given query.
#define GNUNET_log(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG
Struct containing parameters of monitoring requests.
struct ClientMonitorRecord * next
Next element in DLL.
Entry in the local forwarding map for a client's GET request.

References ch, ClientHandle::client, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, monitor, monitor_head, monitor_tail, ClientMonitorRecord::next, and remove_client_query_record().

Here is the call graph for this function:

◆ transmit_request()

static void transmit_request ( struct ClientQueryRecord cqr)
static

Route the given request via the DHT.

This includes updating the bloom filter and retransmission times, building the P2P message and initiating the routing operation.

Parameters
cqrrequest to transmit

Definition at line 372 of file gnunet-service-dht_clients.c.

373{
374 struct GNUNET_BLOCK_Group *bg;
375 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
376
378 "# GET requests from clients injected",
379 1,
380 GNUNET_NO);
382 cqr->type,
383 NULL, /* raw data */
384 0, /* raw data size */
385 "seen-set-size",
387 NULL);
389 cqr->seen_replies,
390 cqr->seen_replies_count);
391 peer_bf
396 "Initiating GET for %s, replication %u, already have %u replies\n",
397 GNUNET_h2s (&cqr->key),
398 cqr->replication,
399 cqr->seen_replies_count);
401 cqr->msg_options,
402 cqr->replication,
403 0 /* hop count */,
404 &cqr->key,
405 cqr->xquery,
406 cqr->xquery_size,
407 bg,
408 peer_bf);
411
412 /* Exponential back-off for retries.
413 * max. is #GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD (15 min) */
416}
#define DHT_BLOOM_SIZE
Size of the bloom filter the DHT uses to filter peers.
Definition dht.h:34
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
struct GNUNET_BLOCK_Context * GDS_block_context
Our handle to the BLOCK library.
#define LOG(kind,...)
enum GNUNET_GenericReturnValue GDS_NEIGHBOURS_handle_get(enum GNUNET_BLOCK_Type type, enum GNUNET_DHT_RouteOption options, uint16_t desired_replication_level, uint16_t hop_count, const struct GNUNET_HashCode *key, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, struct GNUNET_CONTAINER_BloomFilter *peer_bf)
Perform a GET operation.
enum GNUNET_GenericReturnValue GNUNET_BLOCK_group_set_seen(struct GNUNET_BLOCK_Group *bg, const struct GNUNET_HashCode *seen_results, unsigned int seen_results_count)
Update block group to filter out the given results.
Definition block.c:365
void GNUNET_BLOCK_group_destroy(struct GNUNET_BLOCK_Group *bg)
Destroy resources used by a block group.
Definition block.c:194
struct GNUNET_BLOCK_Group * GNUNET_BLOCK_group_create(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *raw_data, size_t raw_data_size,...)
Create a new block group.
Definition block.c:249
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
#define GNUNET_CONSTANTS_BLOOMFILTER_K
K-value that must be used for the bloom filters in 'GET' queries.
@ GNUNET_NO
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
unsigned int seen_replies_count
Number of entries in seen_replies.
size_t xquery_size
Number of bytes in xquery.
struct GNUNET_TIME_Relative retry_frequency
What's the delay between re-try operations that we currently use for this request?
struct GNUNET_HashCode * seen_replies
Array of (hashes of) replies we have already seen for this request.
enum GNUNET_DHT_RouteOption msg_options
Any message options for this request.
struct GNUNET_HashCode key
The key this request was about.
enum GNUNET_BLOCK_Type type
The type for the data for the GET request.
const void * xquery
Extended query (see gnunet_block_lib.h), allocated at the end of this struct.
struct GNUNET_TIME_Absolute retry_time
What's the next time we should re-try this request?
uint32_t replication
Desired replication level.

References DHT_BLOOM_SIZE, GDS_block_context, GDS_NEIGHBOURS_handle_get(), GDS_stats, GNUNET_BLOCK_group_create(), GNUNET_BLOCK_group_destroy(), GNUNET_BLOCK_group_set_seen(), GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_STD_BACKOFF, ClientQueryRecord::key, LOG, ClientQueryRecord::msg_options, ClientQueryRecord::replication, ClientQueryRecord::retry_frequency, ClientQueryRecord::retry_time, ClientQueryRecord::seen_replies, ClientQueryRecord::seen_replies_count, ClientQueryRecord::type, ClientQueryRecord::xquery, and ClientQueryRecord::xquery_size.

Referenced by transmit_next_request_task().

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

◆ transmit_next_request_task()

static void transmit_next_request_task ( void *  cls)
static

Task that looks at the retry_heap and transmits all of the requests on the heap that are ready for transmission.

Then re-schedules itself (unless the heap is empty).

Parameters
clsunused

Definition at line 427 of file gnunet-service-dht_clients.c.

428{
429 struct ClientQueryRecord *cqr;
430
431 (void) cls;
432 retry_task = NULL;
433 while (NULL != (cqr = GNUNET_CONTAINER_heap_remove_root (retry_heap)))
434 {
435 cqr->hnode = NULL;
437 {
438 cqr->hnode
440 cqr,
445 NULL);
446 return;
447 }
448 transmit_request (cqr);
449 cqr->hnode
451 cqr,
453 }
454}
static void transmit_request(struct ClientQueryRecord *cqr)
Route the given request via the DHT.
static struct GNUNET_CONTAINER_Heap * retry_heap
Heap with all of our client's request, sorted by retry time (earliest on top).
static struct GNUNET_SCHEDULER_Task * retry_task
Task that re-transmits requests (using retry_heap).
static void transmit_next_request_task(void *cls)
Task that looks at the retry_heap and transmits all of the requests on the heap that are ready for tr...
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
struct GNUNET_CONTAINER_HeapNode * GNUNET_CONTAINER_heap_insert(struct GNUNET_CONTAINER_Heap *heap, void *element, GNUNET_CONTAINER_HeapCostType cost)
Inserts a new element into the heap.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_at(struct GNUNET_TIME_Absolute at, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run at the specified time.
Definition scheduler.c:1260
bool GNUNET_TIME_absolute_is_past(struct GNUNET_TIME_Absolute abs)
Test if abs is truly in the past (excluding now).
Definition time.c:667
struct GNUNET_CONTAINER_HeapNode * hnode
Pointer to this nodes heap location in the retry-heap (for fast removal)
uint64_t abs_value_us
The actual value.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_SCHEDULER_add_at(), GNUNET_TIME_absolute_is_past(), ClientQueryRecord::hnode, retry_heap, retry_task, ClientQueryRecord::retry_time, transmit_next_request_task(), and transmit_request().

Referenced by handle_dht_local_get(), and transmit_next_request_task().

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

◆ check_dht_local_put()

static enum GNUNET_GenericReturnValue check_dht_local_put ( void *  cls,
const struct GNUNET_DHT_ClientPutMessage dht_msg 
)
static

Check DHT PUT messages from the client.

Parameters
clsthe client we received this message from
dht_msgthe actual message received
Returns
GNUNET_OK (always)

Definition at line 465 of file gnunet-service-dht_clients.c.

467{
468 uint32_t replication_level = ntohl (dht_msg->desired_replication_level);
469
470 (void) cls;
472 {
473 GNUNET_break_op (0);
474 return GNUNET_SYSERR;
475 }
476 return GNUNET_OK;
477}
static unsigned int replication_level
Replication level option to use for publishing.
#define GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL
Maximum allowed replication level for all requests.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t desired_replication_level
Replication level for this message.
Definition dht.h:219

References GNUNET_DHT_ClientPutMessage::desired_replication_level, GNUNET_break_op, GNUNET_DHT_MAXIMUM_REPLICATION_LEVEL, GNUNET_OK, GNUNET_SYSERR, and replication_level.

◆ cb_forwarded_dht_local_put()

static void cb_forwarded_dht_local_put ( void *  cls,
enum GNUNET_GenericReturnValue  forwarded 
)
static

Definition at line 481 of file gnunet-service-dht_clients.c.

483{
484 if (GNUNET_OK != forwarded)
485 {
487 "# Local PUT requests not routed",
488 1,
489 GNUNET_NO);
490 }
491}

References GDS_stats, GNUNET_NO, GNUNET_OK, and GNUNET_STATISTICS_update().

Referenced by handle_dht_local_put().

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

◆ handle_dht_local_put()

static void handle_dht_local_put ( void *  cls,
const struct GNUNET_DHT_ClientPutMessage dht_msg 
)
static

Handler for PUT messages.

Parameters
clsthe client we received this message from
dht_msgthe actual message received

Definition at line 501 of file gnunet-service-dht_clients.c.

503{
504 struct ClientHandle *ch = cls;
505 uint16_t size = ntohs (dht_msg->header.size);
506 uint32_t replication_level
507 = ntohl (dht_msg->desired_replication_level);
508 struct GNUNET_DATACACHE_Block bd = {
509 .key = dht_msg->key,
510 .expiration_time = GNUNET_TIME_absolute_ntoh (dht_msg->expiration),
511 .data = &dht_msg[1],
512 .data_size = size - sizeof (*dht_msg),
513 .type = ntohl (dht_msg->type),
514 .ro = ntohl (dht_msg->options)
515 };
516
518 "Handling local PUT of %lu-bytes for query %s of type %u\n",
519 (unsigned long) (size - sizeof(struct GNUNET_DHT_ClientPutMessage)),
520 GNUNET_h2s (&dht_msg->key),
521 (unsigned int) bd.type);
522#if SANITY_CHECKS > 0
523 if (GNUNET_OK !=
525 bd.type,
526 bd.data,
527 bd.data_size))
528 {
529 GNUNET_break (0);
530 return;
531 }
532#endif
534 "# PUT requests received from clients",
535 1,
536 GNUNET_NO);
538 "CLIENT-PUT %s\n",
539 GNUNET_h2s_full (&dht_msg->key));
540 /* give to local clients */
542 &bd.key,
543 0, NULL /* get path */));
544
545 {
546 struct GNUNET_CONTAINER_BloomFilter *peer_bf;
547
548 peer_bf
552 /* store locally */
553 if ( (0 != (bd.ro & GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE)) ||
554 (GDS_am_closest_peer (&dht_msg->key,
555 peer_bf)))
557 /* route to other peers */
560 0 /* hop count */,
561 peer_bf,
563 NULL);
565 }
567 &bd,
568 0, /* hop count */
571}
static void cb_forwarded_dht_local_put(void *cls, enum GNUNET_GenericReturnValue forwarded)
void GDS_CLIENTS_process_put(const struct GNUNET_DATACACHE_Block *bd, uint32_t hop_count, uint32_t desired_replication_level)
Check if some client is monitoring PUT messages and notify them in that case.
bool GDS_CLIENTS_handle_reply(const struct GNUNET_DATACACHE_Block *bd, const struct GNUNET_HashCode *query_hash, unsigned int get_path_length, const struct GNUNET_DHT_PathElement *get_path)
Handle a reply we've received from another peer.
#define LOG_TRAFFIC(kind,...)
Should routing details be logged to stderr (for debugging)?
void GDS_DATACACHE_handle_put(const struct GNUNET_DATACACHE_Block *bd)
Handle a datum we've received from another peer.
enum GNUNET_GenericReturnValue GDS_am_closest_peer(const struct GNUNET_HashCode *key, const struct GNUNET_CONTAINER_BloomFilter *bloom)
Check whether my identity is closer than any known peers.
void GDS_NEIGHBOURS_handle_put(const struct GNUNET_DATACACHE_Block *bd, uint16_t desired_replication_level, uint16_t hop_count, struct GNUNET_CONTAINER_BloomFilter *bf, GDS_PutOperationCallback cb, void *cb_cls)
Perform a PUT operation.
enum GNUNET_GenericReturnValue GNUNET_BLOCK_check_block(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size)
Function called to validate a block.
Definition block.c:321
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition service.c:2434
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
static unsigned int size
Size of the "table".
Definition peer.c:68
Information about a block stored in the datacache.
enum GNUNET_BLOCK_Type type
Type of the block.
const void * data
Actual block data.
enum GNUNET_DHT_RouteOption ro
Options for routing for the block.
struct GNUNET_HashCode key
Key of the block.
size_t data_size
Number of bytes in data.
Message to insert data into the DHT, sent from clients to DHT service.
Definition dht.h:200
struct GNUNET_HashCode key
The key to store the value under.
Definition dht.h:229
uint32_t type
The type of data to insert.
Definition dht.h:209
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition dht.h:214
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT.
Definition dht.h:204
struct GNUNET_TIME_AbsoluteNBO expiration
How long should this data persist?
Definition dht.h:224

References cb_forwarded_dht_local_put(), ch, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DHT_ClientPutMessage::desired_replication_level, DHT_BLOOM_SIZE, GNUNET_DHT_ClientPutMessage::expiration, GDS_am_closest_peer(), GDS_block_context, GDS_CLIENTS_handle_reply(), GDS_CLIENTS_process_put(), GDS_DATACACHE_handle_put(), GDS_NEIGHBOURS_handle_put(), GDS_stats, GNUNET_BLOCK_check_block(), GNUNET_break, GNUNET_CONSTANTS_BLOOMFILTER_K, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), GNUNET_DHT_ClientPutMessage::header, GNUNET_DATACACHE_Block::key, GNUNET_DHT_ClientPutMessage::key, LOG, LOG_TRAFFIC, GNUNET_DHT_ClientPutMessage::options, replication_level, GNUNET_DATACACHE_Block::ro, GNUNET_MessageHeader::size, size, GNUNET_DATACACHE_Block::type, and GNUNET_DHT_ClientPutMessage::type.

Here is the call graph for this function:

◆ handle_local_result()

static void handle_local_result ( void *  cls,
const struct GNUNET_DATACACHE_Block bd 
)
static

Handle a result from local datacache for a GET operation.

Parameters
clsthe struct ClientHandle of the client doing the query
bddetails about the block that was found

Definition at line 581 of file gnunet-service-dht_clients.c.

583{
585 "Datacache provided result for query key %s\n",
586 GNUNET_h2s (&bd->key));
588 &bd->key,
589 0, NULL /* get_path */));
590}
@ GNUNET_ERROR_TYPE_INFO

References GDS_CLIENTS_handle_reply(), GNUNET_break, GNUNET_ERROR_TYPE_INFO, GNUNET_h2s(), GNUNET_log, and GNUNET_DATACACHE_Block::key.

Referenced by handle_dht_local_get().

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

◆ check_dht_local_get()

static enum GNUNET_GenericReturnValue check_dht_local_get ( void *  cls,
const struct GNUNET_DHT_ClientGetMessage get 
)
static

Check DHT GET messages from the client.

Parameters
clsthe client we received this message from
getthe actual message received
Returns
GNUNET_OK (always)

Definition at line 601 of file gnunet-service-dht_clients.c.

603{
604 (void) cls;
605 (void) get;
606 /* always well-formed */
607 return GNUNET_OK;
608}
static int get
Get DID Documement for DID Flag.
Definition gnunet-did.c:63

References get, and GNUNET_OK.

◆ handle_dht_local_get()

static void handle_dht_local_get ( void *  cls,
const struct GNUNET_DHT_ClientGetMessage get 
)
static

Handler for DHT GET messages from the client.

Parameters
clsthe client we received this message from
getthe actual message received

Definition at line 618 of file gnunet-service-dht_clients.c.

620{
621 struct ClientHandle *ch = cls;
622 struct ClientQueryRecord *cqr;
623 uint16_t size = ntohs (get->header.size);
624 const char *xquery = (const char *) &get[1];
625 size_t xquery_size = size - sizeof(struct GNUNET_DHT_ClientGetMessage);
626
628 "Received GET request for %s from local client %p, xq: %.*s\n",
629 GNUNET_h2s (&get->key),
630 ch->client,
631 (int) xquery_size,
632 xquery);
634 "# GET requests received from clients",
635 1,
636 GNUNET_NO);
638 "CLIENT-GET %s\n",
639 GNUNET_h2s_full (&get->key));
640
641 cqr = GNUNET_malloc (sizeof(struct ClientQueryRecord) + xquery_size);
642 cqr->key = get->key;
643 cqr->ch = ch;
644 cqr->xquery = (const void *) &cqr[1];
645 GNUNET_memcpy (&cqr[1],
646 xquery,
647 xquery_size);
649 cqr,
650 0);
653 cqr->unique_id = get->unique_id;
654 cqr->xquery_size = xquery_size;
655 cqr->replication = ntohl (get->desired_replication_level);
656 cqr->msg_options = ntohl (get->options);
657 cqr->type = ntohl (get->type);
659 ch->cqr_tail,
660 cqr);
662 &cqr->key,
663 cqr,
666 cqr->type,
667 0, /* hop count */
668 cqr->replication,
669 &get->key);
670 /* start remote requests */
671 if (NULL != retry_task)
674 NULL);
675 /* perform local lookup */
677 cqr->type,
678 cqr->xquery,
679 xquery_size,
680 NULL,
682 ch);
684}
void GDS_CLIENTS_process_get(enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, uint32_t hop_count, uint32_t desired_replication_level, const struct GNUNET_HashCode *key)
Check if some client is monitoring GET messages and notify them in that case.
static void handle_local_result(void *cls, const struct GNUNET_DATACACHE_Block *bd)
Handle a result from local datacache for a GET operation.
enum GNUNET_BLOCK_ReplyEvaluationResult GDS_DATACACHE_handle_get(const struct GNUNET_HashCode *key, enum GNUNET_BLOCK_Type type, const void *xquery, size_t xquery_size, struct GNUNET_BLOCK_Group *bg, GDS_DATACACHE_GetCallback gc, void *gc_cls)
Handle a GET request we've received from another peer.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_malloc(size)
Wrapper around malloc.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
struct ClientHandle * ch
Client responsible for the request.
uint64_t unique_id
The unique identifier of this request.
DHT GET message sent from clients to service.
Definition dht.h:72

References ch, ClientQueryRecord::ch, forward_map, GDS_CLIENTS_process_get(), GDS_DATACACHE_handle_get(), GDS_stats, get, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_SECONDS, handle_local_result(), ClientQueryRecord::hnode, ClientQueryRecord::key, LOG, LOG_TRAFFIC, ClientQueryRecord::msg_options, ClientQueryRecord::replication, ClientQueryRecord::retry_frequency, retry_heap, retry_task, ClientQueryRecord::retry_time, size, transmit_next_request_task(), ClientQueryRecord::type, ClientQueryRecord::unique_id, ClientQueryRecord::xquery, and ClientQueryRecord::xquery_size.

Here is the call graph for this function:

◆ find_by_unique_id()

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

Function called for each existing DHT record for the given query.

Checks if it matches the UID given in the closure and if so returns the entry as a result.

Parameters
clsthe search context
keyquery for the lookup (not used)
valuethe struct ClientQueryRecord
Returns
GNUNET_YES to continue iteration (result not yet found)

Definition at line 715 of file gnunet-service-dht_clients.c.

718{
719 struct FindByUniqueIdContext *fui_ctx = cls;
720 struct ClientQueryRecord *cqr = value;
721
722 if (cqr->unique_id != fui_ctx->unique_id)
723 return GNUNET_YES;
724 fui_ctx->cqr = cqr;
725 return GNUNET_NO;
726}
static char * value
Value of the record to add/remove.
Closure for find_by_unique_id().
uint64_t unique_id
Unique ID to look for.
struct ClientQueryRecord * cqr
Where to store the result, if found.

References FindByUniqueIdContext::cqr, GNUNET_NO, GNUNET_YES, ClientQueryRecord::unique_id, FindByUniqueIdContext::unique_id, and value.

Referenced by handle_dht_local_get_result_seen().

Here is the caller graph for this function:

◆ check_dht_local_get_result_seen()

static enum GNUNET_GenericReturnValue check_dht_local_get_result_seen ( void *  cls,
const struct GNUNET_DHT_ClientGetResultSeenMessage seen 
)
static

Check "GET result seen" messages from the client.

Parameters
clsthe client we received this message from
seenthe actual message received
Returns
GNUNET_OK if seen is well-formed

Definition at line 737 of file gnunet-service-dht_clients.c.

740{
741 uint16_t size = ntohs (seen->header.size);
742 unsigned int hash_count =
743 (size - sizeof(*seen))
744 / sizeof(struct GNUNET_HashCode);
745
746 if (size != sizeof(*seen) + hash_count * sizeof(struct GNUNET_HashCode))
747 {
748 GNUNET_break (0);
749 return GNUNET_SYSERR;
750 }
751 return GNUNET_OK;
752}
struct GNUNET_MessageHeader header
Type: GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN.
Definition dht.h:118
A 512-bit hashcode.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_DHT_ClientGetResultSeenMessage::header, GNUNET_MessageHeader::size, and size.

◆ handle_dht_local_get_result_seen()

static void handle_dht_local_get_result_seen ( void *  cls,
const struct GNUNET_DHT_ClientGetResultSeenMessage seen 
)
static

Handler for "GET result seen" messages from the client.

Parameters
clsthe client we received this message from
seenthe actual message received

Definition at line 762 of file gnunet-service-dht_clients.c.

765{
766 struct ClientHandle *ch = cls;
767 uint16_t size = ntohs (seen->header.size);
768 unsigned int hash_count = (size - sizeof(*seen))
769 / sizeof(struct GNUNET_HashCode);
770 const struct GNUNET_HashCode *hc = (const struct GNUNET_HashCode*) &seen[1];
771 struct FindByUniqueIdContext fui_ctx = {
772 .unique_id = seen->unique_id
773 };
774 unsigned int old_count;
775 struct ClientQueryRecord *cqr;
776
778 &seen->key,
780 &fui_ctx);
781 if (NULL == (cqr = fui_ctx.cqr))
782 {
783 GNUNET_break (0);
785 return;
786 }
787 /* finally, update 'seen' list */
788 old_count = cqr->seen_replies_count;
791 cqr->seen_replies_count + hash_count);
792 GNUNET_memcpy (&cqr->seen_replies[old_count],
793 hc,
794 sizeof(struct GNUNET_HashCode) * hash_count);
795}
static enum GNUNET_GenericReturnValue find_by_unique_id(void *cls, const struct GNUNET_HashCode *key, void *value)
Function called for each existing DHT record for the given query.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition service.c:2463
struct GNUNET_HashCode key
The key we are searching for (to make it easy to find the corresponding GET inside the service).
Definition dht.h:129
uint64_t unique_id
Unique ID identifying this request.
Definition dht.h:134

References ch, FindByUniqueIdContext::cqr, find_by_unique_id(), forward_map, GNUNET_array_grow, GNUNET_break, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_memcpy, GNUNET_SERVICE_client_drop(), GNUNET_DHT_ClientGetResultSeenMessage::header, GNUNET_DHT_ClientGetResultSeenMessage::key, ClientQueryRecord::seen_replies, ClientQueryRecord::seen_replies_count, GNUNET_MessageHeader::size, size, GNUNET_DHT_ClientGetResultSeenMessage::unique_id, and FindByUniqueIdContext::unique_id.

Here is the call graph for this function:

◆ remove_by_unique_id()

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

Iterator over hash map entries that frees all entries that match the given client and unique ID.

Parameters
clsunique ID and client to search for in source routes
keycurrent key code
valuevalue in the hash map, a ClientQueryRecord
Returns
GNUNET_YES (we should continue to iterate)

Definition at line 825 of file gnunet-service-dht_clients.c.

828{
829 const struct RemoveByUniqueIdContext *ctx = cls;
830 struct ClientQueryRecord *cqr = value;
831
832 if (cqr->unique_id != ctx->unique_id)
833 return GNUNET_YES;
835 "Removing client %p's record for key %s (by unique id)\n",
836 ctx->ch->client,
837 GNUNET_h2s (key));
839 return GNUNET_YES;
840}
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_FS_Handle * ctx
Closure for remove_by_unique_id().

References ctx, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_YES, key, remove_client_query_record(), ClientQueryRecord::unique_id, and value.

Referenced by handle_dht_local_get_stop().

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

◆ handle_dht_local_get_stop()

static void handle_dht_local_get_stop ( void *  cls,
const struct GNUNET_DHT_ClientGetStopMessage dht_stop_msg 
)
static

Handler for any generic DHT stop messages, calls the appropriate handler depending on message type (if processed locally)

Parameters
clsclient we received this message from
dht_stop_msgthe actual message received

Definition at line 852 of file gnunet-service-dht_clients.c.

855{
856 struct ClientHandle *ch = cls;
858
860 "# GET STOP requests received from clients",
861 1,
862 GNUNET_NO);
864 "Received GET STOP request for %s from local client %p\n",
865 GNUNET_h2s (&dht_stop_msg->key),
866 ch->client);
867 ctx.ch = ch;
868 ctx.unique_id = dht_stop_msg->unique_id;
870 &dht_stop_msg->key,
872 &ctx);
874}
static enum GNUNET_GenericReturnValue remove_by_unique_id(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries that frees all entries that match the given client and unique ID.
uint64_t unique_id
Unique ID identifying this request.
Definition dht.h:58
struct GNUNET_HashCode key
Key of this request.
Definition dht.h:63

References ch, ctx, forward_map, GDS_stats, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_NO, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GNUNET_DHT_ClientGetStopMessage::key, LOG, remove_by_unique_id(), and GNUNET_DHT_ClientGetStopMessage::unique_id.

Here is the call graph for this function:

◆ forward_reply()

static enum GNUNET_GenericReturnValue forward_reply ( void *  cls,
const struct GNUNET_HashCode query_hash,
void *  value 
)
static

Iterator over hash map entries that send a given reply to each of the matching clients.

With some tricky recycling of the buffer.

Parameters
clsthe struct ForwardReplyContext
query_hashhash of the query for which this may be a reply
valuevalue in the hash map, a ClientQueryRecord
Returns
GNUNET_YES (we should continue to iterate), if the result is mal-formed, GNUNET_NO

Definition at line 912 of file gnunet-service-dht_clients.c.

915{
916 struct ForwardReplyContext *frc = cls;
918 const struct GNUNET_DATACACHE_Block *bd = frc->bd;
919 struct GNUNET_MQ_Envelope *env;
920 struct GNUNET_DHT_ClientResultMessage *reply;
922 bool do_free;
923 struct GNUNET_HashCode ch;
924 struct GNUNET_DHT_PathElement *paths;
925 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
926 size_t xsize = bd->data_size;
927
929 "CLIENT-RESULT %s\n",
930 GNUNET_h2s_full (&bd->key));
931 if ( (record->type != GNUNET_BLOCK_TYPE_ANY) &&
932 (record->type != bd->type) )
933 {
935 "Record type mismatch, not passing request for key %s to local client\n",
936 GNUNET_h2s (&bd->key));
938 "# Key match, type mismatches in REPLY to CLIENT",
939 1,
940 GNUNET_NO);
941 return GNUNET_YES; /* type mismatch */
942 }
943 if ( (0 == (record->msg_options & GNUNET_DHT_RO_FIND_APPROXIMATE)) &&
944 (0 != GNUNET_memcmp (&bd->key,
945 query_hash)) )
946 {
948 "# Inexact key match, but exact match required",
949 1,
950 GNUNET_NO);
951 return GNUNET_YES; /* type mismatch */
952 }
954 bd->data_size,
955 &ch);
956 for (unsigned int i = 0; i < record->seen_replies_count; i++)
957 if (0 ==
958 GNUNET_memcmp (&record->seen_replies[i],
959 &ch))
960 {
962 "Duplicate reply, not passing request for key %s to local client\n",
963 GNUNET_h2s (&bd->key));
965 "# Duplicate REPLIES to CLIENT request dropped",
966 1,
967 GNUNET_NO);
968 return GNUNET_YES; /* duplicate */
969 }
970 eval
972 record->type,
973 NULL,
974 &bd->key,
975 record->xquery,
976 record->xquery_size,
977 bd->data,
978 bd->data_size);
980 "Evaluation result is %d for key %s for local client's query\n",
981 (int) eval,
982 GNUNET_h2s (&bd->key));
983 switch (eval)
984 {
986 do_free = true;
987 break;
990 GNUNET_array_append (record->seen_replies,
991 record->seen_replies_count,
992 ch);
993 do_free = false;
994 break;
996 /* should be impossible to encounter here */
997 GNUNET_break (0);
998 return GNUNET_YES;
1000 return GNUNET_YES;
1001 default:
1002 GNUNET_break (0);
1003 return GNUNET_NO;
1004 }
1006 "# RESULTS queued for clients",
1007 1,
1008 GNUNET_NO);
1009 xsize += (frc->get_path_length + bd->put_path_length)
1010 * sizeof(struct GNUNET_DHT_PathElement);
1011 if (truncated)
1012 xsize += sizeof (struct GNUNET_PeerIdentity);
1013
1014#if SUPER_REDUNDANT_CHECK
1015 {
1016 const struct GNUNET_PeerIdentity *my_identity;
1018 GNUNET_assert (NULL != my_identity);
1019 GNUNET_break (0 ==
1021 bd->data_size,
1022 bd->expiration_time,
1023 truncated
1024 ? &bd->trunc_peer
1025 : NULL,
1026 bd->put_path,
1027 bd->put_path_length,
1028 frc->get_path,
1029 frc->get_path_length,
1030 my_identity));
1031 }
1032#endif
1033
1034 env = GNUNET_MQ_msg_extra (reply,
1035 xsize,
1037 reply->type = htonl (bd->type);
1038 reply->options = htonl (bd->ro);
1039 reply->get_path_length = htonl (frc->get_path_length);
1040 reply->put_path_length = htonl (bd->put_path_length);
1041 reply->unique_id = record->unique_id;
1043 reply->key = *query_hash;
1044 if (truncated)
1045 {
1046 void *tgt = &reply[1];
1047
1048 GNUNET_memcpy (tgt,
1049 &bd->trunc_peer,
1050 sizeof (struct GNUNET_PeerIdentity));
1051 paths = (struct GNUNET_DHT_PathElement *)
1052 (tgt + sizeof (struct GNUNET_PeerIdentity));
1053 }
1054 else
1055 {
1056 paths = (struct GNUNET_DHT_PathElement *) &reply[1];
1057 }
1058 GNUNET_memcpy (paths,
1059 bd->put_path,
1060 sizeof(struct GNUNET_DHT_PathElement)
1061 * bd->put_path_length);
1062 GNUNET_memcpy (&paths[bd->put_path_length],
1063 frc->get_path,
1064 sizeof(struct GNUNET_DHT_PathElement)
1065 * frc->get_path_length);
1066 GNUNET_memcpy (&paths[frc->get_path_length + bd->put_path_length],
1067 bd->data,
1068 bd->data_size);
1070 "Sending reply to query %s for client %p\n",
1071 GNUNET_h2s (query_hash),
1072 record->ch->client);
1073 GNUNET_MQ_send (record->ch->mq,
1074 env);
1075 if (GNUNET_YES == do_free)
1077 return GNUNET_YES;
1078}
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_PILS_Handle * GDS_pils
Handle for the pils service.
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
enum GNUNET_BLOCK_ReplyEvaluationResult GNUNET_BLOCK_check_reply(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *group, const struct GNUNET_HashCode *query, const void *xquery, size_t xquery_size, const void *reply_block, size_t reply_block_size)
Function called to validate if a reply is good for a particular query.
Definition block.c:339
GNUNET_BLOCK_ReplyEvaluationResult
Possible ways for how a block may relate to a query.
@ GNUNET_BLOCK_REPLY_OK_MORE
Valid result, and there may be more.
@ GNUNET_BLOCK_REPLY_OK_DUPLICATE
Valid result, but suppressed because it is a duplicate.
@ GNUNET_BLOCK_REPLY_OK_LAST
Last possible valid result.
@ GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED
Specified block type not supported by any plugin.
@ GNUNET_BLOCK_REPLY_IRRELEVANT
Block does not match xquery (valid result, not relevant for the request)
unsigned int GNUNET_DHT_verify_path(const void *data, size_t data_size, struct GNUNET_TIME_Absolute exp_time, const struct GNUNET_PeerIdentity *trunc_peer, 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 las...
Definition dht_api.c:1355
@ GNUNET_DHT_RO_TRUNCATED
Flag set if the path was truncated.
@ GNUNET_DHT_RO_FIND_APPROXIMATE
Approximate results are fine.
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_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_array_append(arr, len, element)
Append an element to an array (growing the array by one).
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:305
#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_MESSAGE_TYPE_DHT_CLIENT_RESULT
Service returns result to client.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition time.c:636
Closure for forward_reply()
const struct GNUNET_DATACACHE_Block * bd
Block details.
const struct GNUNET_DHT_PathElement * get_path
GET path taken.
unsigned int get_path_length
Number of entries in get_path.
const struct GNUNET_DHT_PathElement * put_path
PUT path taken by the block, array of peer identities.
struct GNUNET_PeerIdentity trunc_peer
If the path was truncated, this is the peer ID at which the path was truncated.
unsigned int put_path_length
Length of the put_path array.
struct GNUNET_TIME_Absolute expiration_time
When does the block expire?
Reply to a GET send from the service to a client.
Definition dht.h:144
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:169
uint64_t unique_id
Unique ID of the matching GET request.
Definition dht.h:180
struct GNUNET_TIME_AbsoluteNBO expiration
When does this entry expire?
Definition dht.h:185
struct GNUNET_HashCode key
The key that was searched for.
Definition dht.h:190
uint32_t type
The type for the data.
Definition dht.h:153
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition dht.h:163
uint32_t get_path_length
The number of peer identities recorded from the storage location to this peer.
Definition dht.h:175
A (signed) path tracking a block's flow through the DHT is represented by an array of path elements,...
The identity of the host (wraps the signing key of the peer).

References ForwardReplyContext::bd, ch, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, env, GNUNET_DHT_ClientResultMessage::expiration, GNUNET_DATACACHE_Block::expiration_time, GDS_block_context, GDS_pils, GDS_stats, ForwardReplyContext::get_path, GNUNET_DHT_ClientResultMessage::get_path_length, ForwardReplyContext::get_path_length, GNUNET_array_append, GNUNET_assert, GNUNET_BLOCK_check_reply(), GNUNET_BLOCK_REPLY_IRRELEVANT, GNUNET_BLOCK_REPLY_OK_DUPLICATE, GNUNET_BLOCK_REPLY_OK_LAST, GNUNET_BLOCK_REPLY_OK_MORE, GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED, GNUNET_BLOCK_TYPE_ANY, GNUNET_break, GNUNET_CRYPTO_hash(), GNUNET_DHT_RO_FIND_APPROXIMATE, GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_memcmp, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_CLIENT_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_PILS_get_identity(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_YES, GNUNET_DATACACHE_Block::key, GNUNET_DHT_ClientResultMessage::key, LOG, LOG_TRAFFIC, my_identity, GNUNET_DHT_ClientResultMessage::options, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DHT_ClientResultMessage::put_path_length, record(), remove_client_query_record(), GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, GNUNET_DATACACHE_Block::type, GNUNET_DHT_ClientResultMessage::type, GNUNET_DHT_ClientResultMessage::unique_id, and value.

Referenced by GDS_CLIENTS_handle_reply().

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

◆ GDS_CLIENTS_handle_reply()

bool GDS_CLIENTS_handle_reply ( const struct GNUNET_DATACACHE_Block bd,
const struct GNUNET_HashCode query_hash,
unsigned int  get_path_length,
const struct GNUNET_DHT_PathElement get_path 
)

Handle a reply we've received from another peer.

If the reply matches any of our pending queries, forward it to the respective client(s).

Parameters
bdblock details
query_hashhash of the original query, might not match key in bd
get_path_lengthnumber of entries in get_path
get_pathpath the reply has taken
Returns
true on success, false on failures

Definition at line 1082 of file gnunet-service-dht_clients.c.

1086{
1087 struct ForwardReplyContext frc;
1088 size_t msize = sizeof (struct GNUNET_DHT_ClientResultMessage)
1089 + bd->data_size
1091 * sizeof(struct GNUNET_DHT_PathElement);
1092#if SANITY_CHECKS > 1
1093 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1094#endif
1095
1096 if (msize >= GNUNET_MAX_MESSAGE_SIZE)
1097 {
1098 GNUNET_break (0);
1099 return false;
1100 }
1101#if SANITY_CHECKS > 1
1102 {
1103 const struct GNUNET_PeerIdentity *my_identity;
1105 GNUNET_assert (NULL != my_identity);
1106 if (0 !=
1108 bd->data_size,
1109 bd->expiration_time,
1110 truncated
1111 ? &bd->trunc_peer
1112 : NULL,
1113 bd->put_path,
1114 bd->put_path_length,
1115 get_path,
1116 get_path_length,
1117 my_identity))
1118 {
1119 GNUNET_break (0);
1120 return false;
1121 }
1122 }
1123#endif
1124 frc.bd = bd;
1125 frc.get_path = get_path;
1126 frc.get_path_length = get_path_length;
1128 "Forwarding reply for query hash %s with GPL %u and PPL %u to client\n",
1129 GNUNET_h2s (query_hash),
1130 get_path_length,
1131 bd->put_path_length);
1132 if (0 ==
1134 query_hash,
1136 &frc))
1137 {
1139 "No matching client for reply for query %s\n",
1140 GNUNET_h2s (query_hash));
1142 "# REPLIES ignored for CLIENTS (no match)",
1143 1,
1144 GNUNET_NO);
1145 }
1146 return true;
1147}
static size_t data_size
Number of bytes in data.
static enum GNUNET_GenericReturnValue forward_reply(void *cls, const struct GNUNET_HashCode *query_hash, void *value)
Iterator over hash map entries that send a given reply to each of the matching clients.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...

References ForwardReplyContext::bd, GNUNET_DATACACHE_Block::data, data_size, GNUNET_DATACACHE_Block::data_size, GNUNET_DATACACHE_Block::expiration_time, forward_map, forward_reply(), GDS_pils, GDS_stats, ForwardReplyContext::get_path, GNUNET_DHT_ClientResultMessage::get_path_length, ForwardReplyContext::get_path_length, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_DHT_RO_TRUNCATED, GNUNET_DHT_verify_path(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_NO, GNUNET_PILS_get_identity(), GNUNET_STATISTICS_update(), LOG, my_identity, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DHT_ClientResultMessage::put_path_length, GNUNET_DATACACHE_Block::ro, and GNUNET_DATACACHE_Block::trunc_peer.

Referenced by handle_dht_local_put(), handle_dht_p2p_put(), handle_local_result(), and process_reply_with_path().

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

◆ handle_dht_local_hello_get()

static void handle_dht_local_hello_get ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handler for HELLO GET message.

Reply to client with a URL of our HELLO.

Parameters
clsthe client we received this message from
msgthe actual message received

Definition at line 1162 of file gnunet-service-dht_clients.c.

1164{
1165 struct ClientHandle *ch = cls;
1166 const struct GNUNET_PeerIdentity *my_identity;
1167 struct GNUNET_HELLO_Parser *p;
1168 struct GNUNET_MessageHeader *hdr;
1169 struct GNUNET_MQ_Envelope *env;
1170
1172
1173 if (NULL != GDS_my_hello)
1175 else
1176 p = NULL;
1177
1179 "Handling request from local client for my HELLO\n");
1180
1181 if (NULL != p)
1182 {
1183 char *url;
1184 size_t slen;
1185
1187 slen = strlen (url) + 1;
1188
1189 env = GNUNET_MQ_msg_extra (hdr,
1190 slen,
1192 memcpy (&hdr[1],
1193 url,
1194 slen);
1195 GNUNET_free (url);
1197 }
1198 else
1199 {
1201 ;
1202 }
1203
1205 env);
1207}
struct GNUNET_MessageHeader * GDS_my_hello
Our HELLO.
static struct GNUNET_Process * p
Helper process we started.
Definition gnunet-uri.c:38
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:380
char * GNUNET_HELLO_parser_to_url(const struct GNUNET_HELLO_Parser *parser)
Generate GNUnet HELLO URI from a parser.
Definition hello-uri.c:839
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg, const struct GNUNET_PeerIdentity *pid)
Parse msg.
Definition hello-uri.c:416
#define GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL
HELLO URL send between client and service (in either direction).
Context for parsing HELLOs.
Definition hello-uri.c:233
Header for all communications.

References ch, env, GDS_my_hello, GDS_pils, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_msg(), GNUNET_HELLO_parser_to_url(), GNUNET_log, GNUNET_MESSAGE_TYPE_DHT_CLIENT_HELLO_URL, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_PILS_get_identity(), GNUNET_SERVICE_client_continue(), GNUNET_CADET_Channel::mq, my_identity, and p.

Here is the call graph for this function:

◆ check_dht_local_hello_offer()

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

Process a client HELLO message received from the service.

Parameters
clsthe client we received this message from
hdrHELLO URL message from the service.
Returns
GNUNET_OK if hdr is well-formed

Definition at line 1218 of file gnunet-service-dht_clients.c.

1220{
1221 uint16_t len = ntohs (hdr->size);
1222 const char *buf = (const char *) &hdr[1];
1223
1224 (void) cls;
1225 if ('\0' != buf[len - sizeof (*hdr) - 1])
1226 {
1227 GNUNET_break (0);
1228 return GNUNET_SYSERR;
1229 }
1230 return GNUNET_OK;
1231}

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, and GNUNET_MessageHeader::size.

◆ handle_dht_local_hello_offer()

static void handle_dht_local_hello_offer ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Handler for HELLO OFFER message.

Try to use the HELLO to connect to another peer.

Parameters
clsthe client we received this message from
msgthe actual message received

Definition at line 1242 of file gnunet-service-dht_clients.c.

1244{
1245 struct ClientHandle *ch = cls;
1246 const char *url = (const char *) &msg[1];
1247 struct GNUNET_HELLO_Parser *b;
1248
1250 "Local client provided HELLO URL %s\n",
1251 url);
1253 if (NULL == b)
1254 {
1255 GNUNET_break (0);
1257 return;
1258 }
1262 NULL);
1264}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
void GDS_try_connect(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Callback function used to extract URIs from a builder.
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_iterate(const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a parser.
Definition hello-uri.c:1011
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_url(const char *url)
Parse GNUnet HELLO url.
Definition hello-uri.c:699

References ch, GDS_try_connect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_url(), GNUNET_HELLO_parser_iterate(), GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), and msg.

Here is the call graph for this function:

◆ handle_dht_local_monitor()

static void handle_dht_local_monitor ( void *  cls,
const struct GNUNET_DHT_MonitorStartStopMessage msg 
)
static

Handler for monitor start messages.

Parameters
clsthe client we received this message from
msgthe actual message received

Definition at line 1278 of file gnunet-service-dht_clients.c.

1280{
1281 struct ClientHandle *ch = cls;
1282 struct ClientMonitorRecord *r;
1283
1284 r = GNUNET_new (struct ClientMonitorRecord);
1285 r->ch = ch;
1286 r->type = ntohl (msg->type);
1287 r->get = ntohs (msg->get);
1288 r->get_resp = ntohs (msg->get_resp);
1289 r->put = ntohs (msg->put);
1290 if (0 != ntohs (msg->filter_key))
1291 r->key = msg->key;
1294 r);
1296}
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t put
Flag whether to notify about PUT messages.
struct ClientHandle * ch
Client to notify of these requests.
enum GNUNET_BLOCK_Type type
Type of blocks that are of interest.
int16_t get
Flag whether to notify about GET messages.
struct GNUNET_HashCode key
Key of data of interest.
int16_t get_resp
Flag whether to notify about GET_REPONSE messages.

References ch, ClientMonitorRecord::ch, ClientMonitorRecord::get, ClientMonitorRecord::get_resp, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_SERVICE_client_continue(), ClientMonitorRecord::key, monitor_head, monitor_tail, msg, ClientMonitorRecord::put, GNUNET_MessageHeader::type, and ClientMonitorRecord::type.

Here is the call graph for this function:

◆ handle_dht_local_monitor_stop()

static void handle_dht_local_monitor_stop ( void *  cls,
const struct GNUNET_DHT_MonitorStartStopMessage msg 
)
static

Handler for monitor stop messages.

Parameters
clsthe client we received this message from
msgthe actual message received

Definition at line 1306 of file gnunet-service-dht_clients.c.

1309{
1310 struct ClientHandle *ch = cls;
1311
1313 for (struct ClientMonitorRecord *r = monitor_head;
1314 NULL != r;
1315 r = r->next)
1316 {
1317 bool keys_match;
1318
1319 keys_match =
1320 (GNUNET_is_zero (&r->key))
1321 ? (0 == ntohs (msg->filter_key))
1322 : ( (0 != ntohs (msg->filter_key)) &&
1323 (! GNUNET_memcmp (&r->key,
1324 &msg->key)) );
1325 if ( (ch == r->ch) &&
1326 (ntohl (msg->type) == r->type) &&
1327 (r->get == msg->get) &&
1328 (r->get_resp == msg->get_resp) &&
1329 (r->put == msg->put) &&
1330 keys_match)
1331 {
1334 r);
1335 GNUNET_free (r);
1336 return; /* Delete only ONE entry */
1337 }
1338 }
1339}
#define GNUNET_is_zero(a)
Check that memory in a is all zeros.

References ch, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_is_zero, GNUNET_memcmp, GNUNET_SERVICE_client_continue(), monitor_head, monitor_tail, msg, ClientMonitorRecord::next, and GNUNET_MessageHeader::type.

Here is the call graph for this function:

◆ for_matching_monitors()

static void for_matching_monitors ( enum GNUNET_BLOCK_Type  type,
const struct GNUNET_HashCode key,
MonitorAction  cb,
void *  cb_cls 
)
static

Call cb on all monitors that watch for blocks of type and key key.

Parameters
typethe type to match
keythe key to match
cbfunction to call
cb_clsclosure for cb

Definition at line 1363 of file gnunet-service-dht_clients.c.

1367{
1368 struct ClientHandle **cl = NULL;
1369 unsigned int cl_size = 0;
1370
1371 for (struct ClientMonitorRecord *m = monitor_head;
1372 NULL != m;
1373 m = m->next)
1374 {
1375 bool found = false;
1376
1377 if ( (GNUNET_BLOCK_TYPE_ANY != m->type) &&
1378 (m->type != type) )
1379 continue;
1380 if ( (! GNUNET_is_zero (&m->key)) &&
1381 (0 ==
1383 &m->key)) )
1384 continue;
1385 /* Don't send duplicates */
1386 for (unsigned i = 0; i < cl_size; i++)
1387 if (cl[i] == m->ch)
1388 {
1389 found = true;
1390 break;
1391 }
1392 if (found)
1393 continue;
1395 cl_size,
1396 m->ch);
1397 cb (cb_cls,
1398 m);
1399 }
1400 GNUNET_free (cl);
1401}
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition gnunet-arm.c:103
static uint32_t type
Type string converted to DNS type value.

References GNUNET_array_append, GNUNET_BLOCK_TYPE_ANY, GNUNET_free, GNUNET_is_zero, GNUNET_memcmp, key, m, monitor_head, and type.

Referenced by GDS_CLIENTS_process_get(), GDS_CLIENTS_process_get_resp(), and GDS_CLIENTS_process_put().

Here is the caller graph for this function:

◆ get_action()

static void get_action ( void *  cls,
struct ClientMonitorRecord m 
)
static

Function called on monitors that match a GET.

Sends the GET notification to the monitor.

Parameters
clsa struct GetActionContext
ma matching monitor

Definition at line 1426 of file gnunet-service-dht_clients.c.

1428{
1429 struct GetActionContext *gac = cls;
1430 struct GNUNET_MQ_Envelope *env;
1431 struct GNUNET_DHT_MonitorGetMessage *mmsg;
1432
1433 env = GNUNET_MQ_msg (mmsg,
1435 mmsg->options = htonl (gac->options);
1436 mmsg->type = htonl (gac->type);
1437 mmsg->hop_count = htonl (gac->hop_count);
1439 mmsg->key = *gac->key;
1440 GNUNET_MQ_send (m->ch->mq,
1441 env);
1442}
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET
Receive information about transiting GETs.
struct GNUNET_MQ_Handle * mq
Our control connection to the ARM service.
Message to monitor get requests going through peer, DHT service -> clients.
Definition dht.h:334
uint32_t hop_count
Hop count.
Definition dht.h:353
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition dht.h:343
uint32_t desired_replication_level
Replication level for this message.
Definition dht.h:358
struct GNUNET_HashCode key
The key to store the value under.
Definition dht.h:368
uint32_t type
The type of data in the request.
Definition dht.h:348
Closure for get_action();.
const struct GNUNET_HashCode * key
enum GNUNET_DHT_RouteOption options
enum GNUNET_BLOCK_Type type

References GNUNET_DHT_MonitorGetMessage::desired_replication_level, GetActionContext::desired_replication_level, env, GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_DHT_MonitorGetMessage::hop_count, GetActionContext::hop_count, GNUNET_DHT_MonitorGetMessage::key, GetActionContext::key, m, GNUNET_ARM_MonitorHandle::mq, GNUNET_DHT_MonitorGetMessage::options, GetActionContext::options, GNUNET_DHT_MonitorGetMessage::type, and GetActionContext::type.

Referenced by GDS_CLIENTS_process_get().

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

◆ GDS_CLIENTS_process_get()

void GDS_CLIENTS_process_get ( enum GNUNET_DHT_RouteOption  options,
enum GNUNET_BLOCK_Type  type,
uint32_t  hop_count,
uint32_t  desired_replication_level,
const struct GNUNET_HashCode key 
)

Check if some client is monitoring GET messages and notify them in that case.

If tracked, path should include the local peer.

Parameters
optionsOptions, for instance RecordRoute, DemultiplexEverywhere.
typeThe type of data in the request.
hop_countHop count so far.
desired_replication_levelDesired replication level.
keyKey of the requested data.

Definition at line 1446 of file gnunet-service-dht_clients.c.

1451{
1452 struct GetActionContext gac = {
1453 .options = options,
1454 .type = type,
1455 .hop_count = hop_count,
1456 .desired_replication_level = desired_replication_level,
1457 .key = key
1458 };
1459
1461 key,
1462 &get_action,
1463 &gac);
1464}
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
static void for_matching_monitors(enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, MonitorAction cb, void *cb_cls)
Call cb on all monitors that watch for blocks of type and key key.
static void get_action(void *cls, struct ClientMonitorRecord *m)
Function called on monitors that match a GET.

References GetActionContext::desired_replication_level, for_matching_monitors(), get_action(), GetActionContext::hop_count, key, options, GetActionContext::options, and type.

Referenced by cb_handle_dht_p2p_get_local_result(), and handle_dht_local_get().

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

◆ response_action()

static void response_action ( void *  cls,
struct ClientMonitorRecord m 
)
static

Function called on monitors that match a response.

Sends the response notification to the monitor.

Parameters
clsa struct ResponseActionContext
ma matching monitor

Definition at line 1486 of file gnunet-service-dht_clients.c.

1488{
1489 const struct ResponseActionContext *resp_ctx = cls;
1490 const struct GNUNET_DATACACHE_Block *bd = resp_ctx->bd;
1491 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1492 struct GNUNET_MQ_Envelope *env;
1494 struct GNUNET_DHT_PathElement *path;
1495 size_t msize;
1496
1497 msize = bd->data_size;
1498 msize += (resp_ctx->get_path_length + bd->put_path_length)
1499 * sizeof(struct GNUNET_DHT_PathElement);
1500 if (truncated)
1501 msize += sizeof (struct GNUNET_PeerIdentity);
1502 env = GNUNET_MQ_msg_extra (mmsg,
1503 msize,
1505 mmsg->type = htonl (bd->type);
1506 mmsg->put_path_length = htonl (bd->put_path_length);
1507 mmsg->get_path_length = htonl (resp_ctx->get_path_length);
1509 mmsg->key = bd->key;
1510 if (truncated)
1511 {
1512 void *tgt = &mmsg[1];
1513
1514 GNUNET_memcpy (tgt,
1515 &bd->trunc_peer,
1516 sizeof (struct GNUNET_PeerIdentity));
1517 path = (struct GNUNET_DHT_PathElement *)
1518 (tgt + sizeof (struct GNUNET_PeerIdentity));
1519 }
1520 else
1521 {
1522 path = (struct GNUNET_DHT_PathElement *) &mmsg[1];
1523 }
1524 GNUNET_memcpy (path,
1525 bd->put_path,
1526 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement));
1527 GNUNET_memcpy (path,
1528 resp_ctx->get_path,
1529 resp_ctx->get_path_length
1530 * sizeof(struct GNUNET_DHT_PathElement));
1531 GNUNET_memcpy (&path[resp_ctx->get_path_length],
1532 bd->data,
1533 bd->data_size);
1534 GNUNET_MQ_send (m->ch->mq,
1535 env);
1536}
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP
Receive information about transiting GET responses.
Message to monitor get results going through peer, DHT service -> clients.
Definition dht.h:377
struct GNUNET_HashCode key
The key of the corresponding GET request.
Definition dht.h:416
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the content expire?
Definition dht.h:411
uint32_t type
Content type.
Definition dht.h:386
uint32_t get_path_length
Length of the GET path that follows (if tracked).
Definition dht.h:406
uint32_t put_path_length
Length of the PUT path that follows (if tracked).
Definition dht.h:401
Closure for response_action().
const struct GNUNET_DHT_PathElement * get_path
const struct GNUNET_DATACACHE_Block * bd

References ResponseActionContext::bd, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, env, GNUNET_DATACACHE_Block::expiration_time, GNUNET_DHT_MonitorGetRespMessage::expiration_time, ResponseActionContext::get_path, GNUNET_DHT_MonitorGetRespMessage::get_path_length, ResponseActionContext::get_path_length, GNUNET_DHT_RO_TRUNCATED, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_MONITOR_GET_RESP, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_TIME_absolute_hton(), GNUNET_DATACACHE_Block::key, GNUNET_DHT_MonitorGetRespMessage::key, m, GNUNET_ARM_MonitorHandle::mq, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DHT_MonitorGetRespMessage::put_path_length, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, GNUNET_DATACACHE_Block::type, and GNUNET_DHT_MonitorGetRespMessage::type.

Referenced by GDS_CLIENTS_process_get_resp().

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

◆ GDS_CLIENTS_process_get_resp()

void GDS_CLIENTS_process_get_resp ( const struct GNUNET_DATACACHE_Block bd,
const struct GNUNET_DHT_PathElement get_path,
unsigned int  get_path_length 
)

Check if some client is monitoring GET RESP messages and notify them in that case.

Parameters
bdblock details
get_pathPeers on GET path (or NULL if not recorded).
get_path_lengthnumber of entries in get_path.

Definition at line 1540 of file gnunet-service-dht_clients.c.

1543{
1544 struct ResponseActionContext rac = {
1545 .bd = bd,
1546 .get_path = get_path,
1547 .get_path_length = get_path_length
1548 };
1549
1551 &bd->key,
1553 &rac);
1554}
static void response_action(void *cls, struct ClientMonitorRecord *m)
Function called on monitors that match a response.

References ResponseActionContext::bd, for_matching_monitors(), ResponseActionContext::get_path, ResponseActionContext::get_path_length, GNUNET_DATACACHE_Block::key, response_action(), and GNUNET_DATACACHE_Block::type.

Referenced by process_reply_with_path().

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

◆ put_action()

static void put_action ( void *  cls,
struct ClientMonitorRecord m 
)
static

Function called on monitors that match a PUT.

Sends the PUT notification to the monitor.

Parameters
clsa struct PutActionContext
ma matching monitor

Definition at line 1576 of file gnunet-service-dht_clients.c.

1578{
1579 const struct PutActionContext *put_ctx = cls;
1580 const struct GNUNET_DATACACHE_Block *bd = put_ctx->bd;
1581 bool truncated = (0 != (bd->ro & GNUNET_DHT_RO_TRUNCATED));
1582 struct GNUNET_MQ_Envelope *env;
1583 struct GNUNET_DHT_MonitorPutMessage *mmsg;
1584 struct GNUNET_DHT_PathElement *msg_path;
1585 size_t msize;
1586
1587 msize = bd->data_size
1588 + bd->put_path_length
1589 * sizeof(struct GNUNET_DHT_PathElement);
1590 if (truncated)
1591 msize += sizeof (struct GNUNET_PeerIdentity);
1592 env = GNUNET_MQ_msg_extra (mmsg,
1593 msize,
1595 mmsg->options = htonl (bd->ro);
1596 mmsg->type = htonl (bd->type);
1597 mmsg->hop_count = htonl (put_ctx->hop_count);
1599 mmsg->put_path_length = htonl (bd->put_path_length);
1600 mmsg->key = bd->key;
1602 if (truncated)
1603 {
1604 void *tgt = &mmsg[1];
1605
1606 GNUNET_memcpy (tgt,
1607 &bd->trunc_peer,
1608 sizeof (struct GNUNET_PeerIdentity));
1609 msg_path = (struct GNUNET_DHT_PathElement *)
1610 (tgt + sizeof (struct GNUNET_PeerIdentity));
1611 }
1612 else
1613 {
1614 msg_path = (struct GNUNET_DHT_PathElement *) &mmsg[1];
1615 }
1616 GNUNET_memcpy (msg_path,
1617 bd->put_path,
1618 bd->put_path_length * sizeof(struct GNUNET_DHT_PathElement));
1619 GNUNET_memcpy (&msg_path[bd->put_path_length],
1620 bd->data,
1621 bd->data_size);
1622 GNUNET_MQ_send (m->ch->mq,
1623 env);
1624}
#define GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT
Receive information about transiting PUTs.
Message to monitor put requests going through peer, DHT service -> clients.
Definition dht.h:239
uint32_t options
Message options, actually an 'enum GNUNET_DHT_RouteOption' value.
Definition dht.h:248
struct GNUNET_TIME_AbsoluteNBO expiration_time
How long should this data persist?
Definition dht.h:274
uint32_t desired_replication_level
Replication level for this message.
Definition dht.h:263
struct GNUNET_HashCode key
The key to store the value under.
Definition dht.h:279
uint32_t hop_count
Hop count so far.
Definition dht.h:258
uint32_t type
The type of data in the request.
Definition dht.h:253
uint32_t put_path_length
Number of peers recorded in the outgoing path from source to the storage location of this message.
Definition dht.h:269
Closure for put_action().
const struct GNUNET_DATACACHE_Block * bd

References PutActionContext::bd, GNUNET_DATACACHE_Block::data, GNUNET_DATACACHE_Block::data_size, GNUNET_DHT_MonitorPutMessage::desired_replication_level, PutActionContext::desired_replication_level, env, GNUNET_DATACACHE_Block::expiration_time, GNUNET_DHT_MonitorPutMessage::expiration_time, GNUNET_DHT_RO_TRUNCATED, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_DHT_MONITOR_PUT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_TIME_absolute_hton(), GNUNET_DHT_MonitorPutMessage::hop_count, PutActionContext::hop_count, GNUNET_DATACACHE_Block::key, GNUNET_DHT_MonitorPutMessage::key, m, GNUNET_ARM_MonitorHandle::mq, GNUNET_DHT_MonitorPutMessage::options, GNUNET_DATACACHE_Block::put_path, GNUNET_DATACACHE_Block::put_path_length, GNUNET_DHT_MonitorPutMessage::put_path_length, GNUNET_DATACACHE_Block::ro, GNUNET_DATACACHE_Block::trunc_peer, GNUNET_DATACACHE_Block::type, and GNUNET_DHT_MonitorPutMessage::type.

Referenced by GDS_CLIENTS_process_put().

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

◆ GDS_CLIENTS_process_put()

void GDS_CLIENTS_process_put ( const struct GNUNET_DATACACHE_Block bd,
uint32_t  hop_count,
uint32_t  desired_replication_level 
)

Check if some client is monitoring PUT messages and notify them in that case.

The path should include our own peer ID (if recorded).

Parameters
bddetails about the block
hop_countHop count so far.
desired_replication_levelDesired replication level.

Definition at line 1628 of file gnunet-service-dht_clients.c.

1631{
1632 struct PutActionContext put_ctx = {
1633 .bd = bd,
1634 .hop_count = hop_count,
1635 .desired_replication_level = desired_replication_level
1636 };
1637
1639 &bd->key,
1640 &put_action,
1641 &put_ctx);
1642}
static void put_action(void *cls, struct ClientMonitorRecord *m)
Function called on monitors that match a PUT.

References PutActionContext::bd, PutActionContext::desired_replication_level, for_matching_monitors(), PutActionContext::hop_count, GNUNET_DATACACHE_Block::key, put_action(), and GNUNET_DATACACHE_Block::type.

Referenced by cb_forwarded_dht_p2p_put(), and handle_dht_local_put().

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

◆ GDS_CLIENTS_init()

void GDS_CLIENTS_init ( void  )

Initialize client subsystem.

Definition at line 1652 of file gnunet-service-dht_clients.c.

1653{
1656 GNUNET_YES);
1659}
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
@ GNUNET_CONTAINER_HEAP_ORDER_MIN
Heap with the minimum cost at the root.

References forward_map, GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multihashmap_create(), GNUNET_YES, and retry_heap.

Referenced by run().

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

◆ GDS_CLIENTS_stop()

void GDS_CLIENTS_stop ( void  )

Shutdown client subsystem.

Definition at line 1666 of file gnunet-service-dht_clients.c.

1667{
1668 if (NULL != retry_task)
1669 {
1671 retry_task = NULL;
1672 }
1673}

References GNUNET_SCHEDULER_cancel(), and retry_task.

Referenced by shutdown_task().

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

◆ GDS_CLIENTS_done()

void GDS_CLIENTS_done ( void  )

◆ __attribute__()

void __attribute__ ( (destructor)  )

MINIMIZE heap size (way below 128k) since this process doesn't need much.

Definition at line 1730 of file gnunet-service-dht_clients.c.

1732{
1733 if (NULL != retry_heap)
1734 {
1737 retry_heap = NULL;
1738 }
1739 if (NULL != forward_map)
1740 {
1743 forward_map = NULL;
1744 }
1745}
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
unsigned int GNUNET_CONTAINER_heap_get_size(const struct GNUNET_CONTAINER_Heap *heap)
Get the current size of the heap.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.

References forward_map, GNUNET_assert, GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_heap_get_size(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_size(), and retry_heap.

Here is the call graph for this function:

Variable Documentation

◆ GDS_block_context

◆ GDS_stats

◆ GDS_pils

◆ GDS_service

struct GNUNET_SERVICE_Handle* GDS_service

Handle for the service.

Definition at line 234 of file gnunet-service-dht_clients.c.

Referenced by run().

◆ GDS_cfg

const struct GNUNET_CONFIGURATION_Handle* GDS_cfg

The configuration the DHT service is running with.

Configuration we use.

Definition at line 239 of file gnunet-service-dht_clients.c.

Referenced by GDS_DATACACHE_init(), GDS_NEIGHBOURS_init(), load_underlay(), pid_change_cb(), and run().

◆ monitor_head

struct ClientMonitorRecord* monitor_head
static

List of active monitoring requests.

Definition at line 244 of file gnunet-service-dht_clients.c.

Referenced by client_disconnect_cb(), for_matching_monitors(), handle_dht_local_monitor(), and handle_dht_local_monitor_stop().

◆ monitor_tail

struct ClientMonitorRecord* monitor_tail
static

List of active monitoring requests.

Definition at line 249 of file gnunet-service-dht_clients.c.

Referenced by client_disconnect_cb(), handle_dht_local_monitor(), and handle_dht_local_monitor_stop().

◆ forward_map

◆ retry_heap

struct GNUNET_CONTAINER_Heap* retry_heap
static

Heap with all of our client's request, sorted by retry time (earliest on top).

Definition at line 259 of file gnunet-service-dht_clients.c.

Referenced by __attribute__(), GDS_CLIENTS_init(), handle_dht_local_get(), and transmit_next_request_task().

◆ retry_task

struct GNUNET_SCHEDULER_Task* retry_task
static

Task that re-transmits requests (using retry_heap).

Definition at line 264 of file gnunet-service-dht_clients.c.

Referenced by GDS_CLIENTS_stop(), handle_dht_local_get(), and transmit_next_request_task().