GNUnet  0.10.x
Functions
gnunet-service-dht_routing.h File Reference

GNUnet DHT tracking of requests for routing replies. More...

#include "gnunet_util_lib.h"
#include "gnunet_block_lib.h"
#include "gnunet_dht_service.h"
Include dependency graph for gnunet-service-dht_routing.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void GDS_ROUTING_process (enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration_time, const struct GNUNET_HashCode *key, unsigned int put_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *get_path, const void *data, size_t data_size)
 Handle a reply (route to origin). More...
 
void GDS_ROUTING_add (const struct GNUNET_PeerIdentity *sender, enum GNUNET_BLOCK_Type type, struct GNUNET_BLOCK_Group *bg, enum GNUNET_DHT_RouteOption options, const struct GNUNET_HashCode *key, const void *xquery, size_t xquery_size)
 Add a new entry to our routing table. More...
 
void GDS_ROUTING_init (void)
 Initialize routing subsystem. More...
 
void GDS_ROUTING_done (void)
 Shutdown routing subsystem. More...
 

Detailed Description

GNUnet DHT tracking of requests for routing replies.

Author
Christian Grothoff

Definition in file gnunet-service-dht_routing.h.

Function Documentation

◆ GDS_ROUTING_process()

void GDS_ROUTING_process ( enum GNUNET_BLOCK_Type  type,
struct GNUNET_TIME_Absolute  expiration_time,
const struct GNUNET_HashCode key,
unsigned int  put_path_length,
const struct GNUNET_PeerIdentity put_path,
unsigned int  get_path_length,
const struct GNUNET_PeerIdentity get_path,
const void *  data,
size_t  data_size 
)

Handle a reply (route to origin).

Only forwards the reply back to other peers waiting for it. Does not do local caching or forwarding to local clients. Essentially calls GDS_NEIGHBOURS_handle_reply() for all peers that sent us a matching request recently.

Parameters
typetype of the block
expiration_timewhen does the content expire
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers the original PUT traversed (if tracked)
get_path_lengthnumber of entries in get_path
get_pathpeers this reply has traversed so far (if tracked)
datapayload of the reply
data_sizenumber of bytes in data

Only forwards the reply back to other peers waiting for it. Does not do local caching or forwarding to local clients. Essentially calls GDS_NEIGHBOURS_handle_reply for all peers that sent us a matching request recently.

Parameters
typetype of the block
expiration_timewhen does the content expire
keykey for the content
put_path_lengthnumber of entries in put_path
put_pathpeers the original PUT traversed (if tracked)
get_path_lengthnumber of entries in get_path
get_pathpeers this reply has traversed so far (if tracked)
datapayload of the reply
data_sizenumber of bytes in data

Definition at line 290 of file gnunet-service-dht_routing.c.

References data, ProcessContext::data, ProcessContext::data_size, data_size, ProcessContext::expiration_time, ProcessContext::get_path, ProcessContext::get_path_length, GNUNET_break, GNUNET_CONTAINER_multihashmap_get_multiple(), process(), ProcessContext::put_path, ProcessContext::put_path_length, RecentRequest::type, and ProcessContext::type.

Referenced by process_reply_with_path().

299 {
300  struct ProcessContext pc;
301 
302  pc.type = type;
303  pc.expiration_time = expiration_time;
304  pc.put_path_length = put_path_length;
305  pc.put_path = put_path;
306  pc.get_path_length = get_path_length;
307  pc.get_path = get_path;
308  pc.data = data;
309  pc.data_size = data_size;
310  if (NULL == data)
311  {
312  /* Some apps might have an 'empty' reply as a valid reply; however,
313  'process' will call GNUNET_BLOCK_evaluate' which treats a 'NULL'
314  reply as request-validation (but we need response-validation).
315  So we set 'data' to a 0-byte non-NULL value just to be sure */
316  GNUNET_break (0 == data_size);
317  pc.data_size = 0;
318  pc.data = ""; /* something not null */
319  }
321  key,
322  &process,
323  &pc);
324 }
struct GNUNET_TIME_Absolute expiration_time
Expiration time of the result.
static int process(void *cls, const struct GNUNET_HashCode *key, void *value)
Forward the result to the given peer if it matches the request.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
const struct GNUNET_PeerIdentity * get_path
Path of the reply.
unsigned int put_path_length
Number of entries in put_path.
unsigned int get_path_length
Number of entries in get_path.
Closure for the 'process' function.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
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.
static struct GNUNET_CONTAINER_MultiHashMap * recent_map
Recently seen requests by key.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
const struct GNUNET_PeerIdentity * put_path
Path of the original PUT.
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_ROUTING_add()

void GDS_ROUTING_add ( const struct GNUNET_PeerIdentity sender,
enum GNUNET_BLOCK_Type  type,
struct GNUNET_BLOCK_Group bg,
enum GNUNET_DHT_RouteOption  options,
const struct GNUNET_HashCode key,
const void *  xquery,
size_t  xquery_size 
)

Add a new entry to our routing table.

Parameters
senderpeer that originated the request
typetype of the block
bgblock group to evaluate replies, henceforth owned by routing
optionsoptions for processing
keykey for the content
xqueryextended query
xquery_sizenumber of bytes in xquery
senderpeer that originated the request
typetype of the block
optionsoptions for processing
keykey for the content
xqueryextended query
xquery_sizenumber of bytes in xquery
reply_bfbloomfilter to filter duplicates
reply_bf_mutatormutator for reply_bf

Definition at line 401 of file gnunet-service-dht_routing.c.

References RecentRequest::bg, DHT_MAX_RECENT, expire_oldest_entry(), GDS_stats, gettext_noop, GNUNET_CONTAINER_heap_get_size(), GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), RecentRequest::heap_node, RecentRequest::key, RecentRequest::options, RecentRequest::peer, try_combine_recent(), RecentRequest::type, RecentRequest::xquery, and RecentRequest::xquery_size.

Referenced by handle_dht_p2p_get().

408 {
409  struct RecentRequest *recent_req;
410 
414  gettext_noop ("# Entries added to routing table"),
415  1,
416  GNUNET_NO);
417  recent_req = GNUNET_malloc (sizeof (struct RecentRequest) + xquery_size);
418  recent_req->peer = *sender;
419  recent_req->key = *key;
420  recent_req->bg = bg;
421  recent_req->type = type;
422  recent_req->options = options;
423  recent_req->xquery = &recent_req[1];
424  GNUNET_memcpy (&recent_req[1],
425  xquery,
426  xquery_size);
427  recent_req->xquery_size = xquery_size;
428  if (GNUNET_SYSERR ==
430  key,
432  recent_req))
433  {
436  ("# DHT requests combined"),
437  1, GNUNET_NO);
438  return;
439  }
440  recent_req->heap_node
442  recent_req,
443  GNUNET_TIME_absolute_get ().abs_value_us);
445  key,
446  recent_req,
448 }
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
Information we keep about all recent GET requests so that we can route replies.
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_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_HashCode key
Key of this request.
#define DHT_MAX_RECENT
Number of requests we track at most (for routing replies).
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
enum GNUNET_BLOCK_Type type
Type of the requested block.
#define GNUNET_memcpy(dst, src, n)
enum GNUNET_DHT_RouteOption options
Request options.
static struct GNUNET_CONTAINER_Heap * recent_heap
Recent requests by time inserted.
static void expire_oldest_entry()
Remove the oldest entry from the DHT routing table.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
unsigned int GNUNET_CONTAINER_heap_get_size(const struct GNUNET_CONTAINER_Heap *heap)
Get the current size of the heap.
struct GNUNET_BLOCK_Group * bg
Block group for filtering replies.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int 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.
Allow multiple values with the same key.
struct GNUNET_PeerIdentity peer
The peer this request was received from.
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.
static struct GNUNET_CONTAINER_MultiHashMap * recent_map
Recently seen requests by key.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
const void * xquery
extended query (see gnunet_block_lib.h).
static int try_combine_recent(void *cls, const struct GNUNET_HashCode *key, void *value)
Try to combine multiple recent requests for the same value (if they come from the same peer)...
struct GNUNET_CONTAINER_HeapNode * heap_node
Position of this node in the min heap.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define gettext_noop(String)
Definition: gettext.h:69
size_t xquery_size
Number of bytes in xquery.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_ROUTING_init()

void GDS_ROUTING_init ( void  )

Initialize routing subsystem.

Definition at line 455 of file gnunet-service-dht_routing.c.

References DHT_MAX_RECENT, GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multihashmap_create(), and GNUNET_NO.

Referenced by run().

456 {
459 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define DHT_MAX_RECENT
Number of requests we track at most (for routing replies).
static struct GNUNET_CONTAINER_Heap * recent_heap
Recent requests by time inserted.
Heap with the minimum cost at the root.
struct GNUNET_CONTAINER_Heap * GNUNET_CONTAINER_heap_create(enum GNUNET_CONTAINER_HeapOrder order)
Create a new heap.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
static struct GNUNET_CONTAINER_MultiHashMap * recent_map
Recently seen requests by key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_ROUTING_done()

void GDS_ROUTING_done ( void  )

Shutdown routing subsystem.

Definition at line 466 of file gnunet-service-dht_routing.c.

References expire_oldest_entry(), GNUNET_assert, GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_heap_get_size(), GNUNET_CONTAINER_multihashmap_destroy(), and GNUNET_CONTAINER_multihashmap_size().

Referenced by shutdown_task().

467 {
472  recent_heap = NULL;
475  recent_map = NULL;
476 }
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_Heap * recent_heap
Recent requests by time inserted.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
static void expire_oldest_entry()
Remove the oldest entry from the DHT routing table.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
unsigned int GNUNET_CONTAINER_heap_get_size(const struct GNUNET_CONTAINER_Heap *heap)
Get the current size of the heap.
static struct GNUNET_CONTAINER_MultiHashMap * recent_map
Recently seen requests by key.
Here is the call graph for this function:
Here is the caller graph for this function: