GNUnet  0.10.x
Data Structures | Typedefs | Enumerations | Functions
gnunet-service-fs_pr.h File Reference

API to handle pending requests. More...

#include "gnunet-service-fs.h"
Include dependency graph for gnunet-service-fs_pr.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  GSF_PendingRequestData
 Public data (in the sense of not encapsulated within 'gnunet-service-fs_pr', not in the sense of network-wide known) associated with each pending request. More...
 

Typedefs

typedef void(* GSF_PendingRequestReplyHandler) (void *cls, enum GNUNET_BLOCK_EvaluationResult eval, struct GSF_PendingRequest *pr, uint32_t reply_anonymity_level, struct GNUNET_TIME_Absolute expiration, struct GNUNET_TIME_Absolute last_transmission, enum GNUNET_BLOCK_Type type, const void *data, size_t data_len)
 Handle a reply to a pending request. More...
 
typedef int(* GSF_PendingRequestIterator) (void *cls, const struct GNUNET_HashCode *key, struct GSF_PendingRequest *pr)
 Signature of function called on each request. More...
 
typedef void(* GSF_LocalLookupContinuation) (void *cls, struct GSF_PendingRequest *pr, enum GNUNET_BLOCK_EvaluationResult result)
 Function to be called after we're done processing replies from the local lookup. More...
 

Enumerations

enum  GSF_PendingRequestOptions {
  GSF_PRO_DEFAULTS = 0, GSF_PRO_LOCAL_ONLY = 1, GSF_PRO_FORWARD_ONLY = 2, GSF_PRO_REQUEST_NEVER_EXPIRES = 4,
  GSF_PRO_BLOOMFILTER_FULL_REFRESH = 8, GSF_PRO_PRIORITY_UNLIMITED = 16, GSF_PRO_LOCAL_REQUEST
}
 Options for pending requests (bits to be ORed). More...
 

Functions

struct GSF_PendingRequestGSF_pending_request_create_ (enum GSF_PendingRequestOptions options, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *query, const struct GNUNET_PeerIdentity *target, const char *bf_data, size_t bf_size, uint32_t mingle, uint32_t anonymity_level, uint32_t priority, int32_t ttl, GNUNET_PEER_Id sender_pid, GNUNET_PEER_Id origin_pid, const struct GNUNET_HashCode *replies_seen, unsigned int replies_seen_count, GSF_PendingRequestReplyHandler rh, void *rh_cls)
 Create a new pending request. More...
 
void GSF_pending_request_update_ (struct GSF_PendingRequest *pr, const struct GNUNET_HashCode *replies_seen, unsigned int replies_seen_count)
 Update a given pending request with additional replies that have been seen. More...
 
struct GSF_PendingRequestDataGSF_pending_request_get_data_ (struct GSF_PendingRequest *pr)
 Obtain the public data associated with a pending request. More...
 
int GSF_pending_request_test_active_ (struct GSF_PendingRequest *pr)
 Check if the given request is still active. More...
 
int GSF_pending_request_is_compatible_ (struct GSF_PendingRequest *pra, struct GSF_PendingRequest *prb)
 Test if two pending requests are compatible (would generate the same query modulo filters and should thus be processed jointly). More...
 
struct GNUNET_MQ_EnvelopeGSF_pending_request_get_message_ (struct GSF_PendingRequest *pr)
 Generate the message corresponding to the given pending request for transmission to other peers. More...
 
void GSF_pending_request_cancel_ (struct GSF_PendingRequest *pr, int full_cleanup)
 Explicitly cancel a pending request. More...
 
void GSF_iterate_pending_requests_ (GSF_PendingRequestIterator it, void *cls)
 Iterate over all pending requests. More...
 
void handle_p2p_put (void *cls, const struct PutMessage *put)
 Handle P2P "CONTENT" message. More...
 
void GSF_dht_lookup_ (struct GSF_PendingRequest *pr)
 Consider looking up the data in the DHT (anonymity-level permitting). More...
 
void GSF_cadet_lookup_ (struct GSF_PendingRequest *pr)
 Consider downloading via cadet (if possible) More...
 
void GSF_local_lookup_ (struct GSF_PendingRequest *pr, GSF_LocalLookupContinuation cont, void *cont_cls)
 Look up the request in the local datastore. More...
 
int GSF_pending_request_test_target_ (struct GSF_PendingRequest *pr, const struct GNUNET_PeerIdentity *target)
 Is the given target a legitimate peer for forwarding the given request? More...
 
void GSF_pending_request_init_ (void)
 Setup the subsystem. More...
 
void GSF_pending_request_done_ (void)
 Shutdown the subsystem. More...
 

Detailed Description

API to handle pending requests.

Author
Christian Grothoff

Definition in file gnunet-service-fs_pr.h.

Typedef Documentation

◆ GSF_PendingRequestReplyHandler

typedef void(* GSF_PendingRequestReplyHandler) (void *cls, enum GNUNET_BLOCK_EvaluationResult eval, struct GSF_PendingRequest *pr, uint32_t reply_anonymity_level, struct GNUNET_TIME_Absolute expiration, struct GNUNET_TIME_Absolute last_transmission, enum GNUNET_BLOCK_Type type, const void *data, size_t data_len)

Handle a reply to a pending request.

Also called if a request expires (then with data == NULL). The handler may be called many times (depending on the request type), but will not be called during or after a call to GSF_pending_request_cancel and will also not be called anymore after a call signalling expiration.

Parameters
clsuser-specified closure
evalevaluation of the result
prhandle to the original pending request
reply_anonymity_levelanonymity level for the reply, UINT32_MAX for "unknown"
expirationwhen does data expire?
last_transmissionthe last time we've tried to get this block (FOREVER if unknown)
typetype of the block
dataresponse data, NULL on request expiration
data_lennumber of bytes in data

Definition at line 189 of file gnunet-service-fs_pr.h.

◆ GSF_PendingRequestIterator

typedef int(* GSF_PendingRequestIterator) (void *cls, const struct GNUNET_HashCode *key, struct GSF_PendingRequest *pr)

Signature of function called on each request.

(Note: 'subtype' of GNUNET_CONTAINER_HashMapIterator).

Parameters
clsclosure
keyquery for the request
prhandle to the pending request
Returns
GNUNET_YES to continue to iterate

Definition at line 321 of file gnunet-service-fs_pr.h.

◆ GSF_LocalLookupContinuation

typedef void(* GSF_LocalLookupContinuation) (void *cls, struct GSF_PendingRequest *pr, enum GNUNET_BLOCK_EvaluationResult result)

Function to be called after we're done processing replies from the local lookup.

Parameters
clsclosure
prthe pending request we were processing
resultfinal datastore lookup result

Definition at line 378 of file gnunet-service-fs_pr.h.

Enumeration Type Documentation

◆ GSF_PendingRequestOptions

Options for pending requests (bits to be ORed).

Enumerator
GSF_PRO_DEFAULTS 

No special options (P2P-default).

GSF_PRO_LOCAL_ONLY 

Request must only be processed locally.

GSF_PRO_FORWARD_ONLY 

Request must only be forwarded (no routing)

GSF_PRO_REQUEST_NEVER_EXPIRES 

Request persists indefinitely (no expiration).

GSF_PRO_BLOOMFILTER_FULL_REFRESH 

Request is allowed to refresh bloomfilter and change mingle value.

GSF_PRO_PRIORITY_UNLIMITED 

Request priority is allowed to be exceeded.

GSF_PRO_LOCAL_REQUEST 

Option mask for typical local requests.

Definition at line 35 of file gnunet-service-fs_pr.h.

36 {
37 
41  GSF_PRO_DEFAULTS = 0,
42 
47 
52 
57 
62 
67 
73 };
Request is allowed to refresh bloomfilter and change mingle value.
No special options (P2P-default).
Request priority is allowed to be exceeded.
Request persists indefinitely (no expiration).
Request must only be processed locally.
Option mask for typical local requests.
Request must only be forwarded (no routing)

Function Documentation

◆ GSF_pending_request_create_()

struct GSF_PendingRequest* GSF_pending_request_create_ ( enum GSF_PendingRequestOptions  options,
enum GNUNET_BLOCK_Type  type,
const struct GNUNET_HashCode query,
const struct GNUNET_PeerIdentity target,
const char *  bf_data,
size_t  bf_size,
uint32_t  mingle,
uint32_t  anonymity_level,
uint32_t  priority,
int32_t  ttl,
GNUNET_PEER_Id  sender_pid,
GNUNET_PEER_Id  origin_pid,
const struct GNUNET_HashCode replies_seen,
unsigned int  replies_seen_count,
GSF_PendingRequestReplyHandler  rh,
void *  rh_cls 
)

Create a new pending request.

Parameters
optionsrequest options
typetype of the block that is being requested
querykey for the lookup
targetpreferred target for the request, NULL for none
bf_dataraw data for bloom filter for known replies, can be NULL
bf_sizenumber of bytes in bf_data
minglemingle value for bf
anonymity_leveldesired anonymity level
prioritymaximum outgoing cummulative request priority to use
ttlcurrent time-to-live for the request
sender_pidpeer ID to use for the sender when forwarding, 0 for none; reference counter is taken over by this function
origin_pidpeer ID of origin of query (do not loop back)
replies_seenhash codes of known local replies
replies_seen_countsize of the 'replies_seen' array
rhhandle to call when we get a reply
rh_clsclosure for rh
Returns
handle for the new pending request
Parameters
optionsrequest options
typetype of the block that is being requested
querykey for the lookup
targetpreferred target for the request, NULL for none
bf_dataraw data for bloom filter for known replies, can be NULL
bf_sizenumber of bytes in bf_data
minglemingle value for bf
anonymity_leveldesired anonymity level
prioritymaximum outgoing cummulative request priority to use
ttlcurrent time-to-live for the request
sender_pidpeer ID to use for the sender when forwarding, 0 for none
origin_pidpeer ID of origin of query (do not loop back)
replies_seenhash codes of known local replies
replies_seen_countsize of the replies_seen array
rhhandle to call when we get a reply
rh_clsclosure for rh
Returns
handle for the new pending request

Definition at line 300 of file gnunet-service-fs_pr.c.

References GNUNET_TIME_Absolute::abs_value_us, anonymity_level, GSF_PendingRequestData::anonymity_level, GSF_PendingRequest::bg, gettext_noop, GNUNET_assert, GNUNET_BLOCK_EVALUATION_REQUEST_VALID, GNUNET_BLOCK_group_create(), GNUNET_BLOCK_TYPE_ANY, GNUNET_BLOCK_TYPE_FS_UBLOCK, GNUNET_CONTAINER_heap_get_size(), GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_peek(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_new_array, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_subtract(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, GSF_block_ctx, GSF_pending_request_cancel_(), GSF_PRO_BLOOMFILTER_FULL_REFRESH, GSF_PRO_FORWARD_ONLY, GSF_PRO_REQUEST_NEVER_EXPIRES, GSF_stats, GSF_PendingRequest::hnode, max_pending_requests, options, GSF_PendingRequestData::options, GSF_PendingRequest::origin_pid, GSF_PendingRequestData::original_priority, GSF_PendingRequestData::priority, GSF_PendingRequest::public_data, GSF_PendingRequestData::query, refresh_bloomfilter(), GSF_PendingRequest::replies_seen, GSF_PendingRequest::replies_seen_count, GSF_PendingRequest::replies_seen_size, GSF_PendingRequest::rh, GSF_PendingRequest::rh_cls, GSF_PendingRequest::sender_pid, GSF_PendingRequestData::start_time, GSF_PendingRequestData::target, GSF_PendingRequestData::ttl, type, and GSF_PendingRequestData::type.

Referenced by handle_client_start_search(), and handle_p2p_get().

316 {
317  struct GSF_PendingRequest *pr;
318  struct GSF_PendingRequest *dpr;
319  size_t extra;
320  struct GNUNET_HashCode *eptr;
321 
323  "Creating request handle for `%s' of type %d\n",
324  GNUNET_h2s (query),
325  type);
326 #if INSANE_STATISTICS
328  gettext_noop ("# Pending requests created"),
329  1,
330  GNUNET_NO);
331 #endif
332  extra = 0;
333  if (NULL != target)
334  extra += sizeof (struct GNUNET_PeerIdentity);
335  pr = GNUNET_malloc (sizeof (struct GSF_PendingRequest) + extra);
336  pr->public_data.query = *query;
337  eptr = (struct GNUNET_HashCode *) &pr[1];
338  if (NULL != target)
339  {
340  pr->public_data.target = (struct GNUNET_PeerIdentity *) eptr;
341  GNUNET_memcpy (eptr, target, sizeof (struct GNUNET_PeerIdentity));
342  }
344  pr->public_data.priority = priority;
345  pr->public_data.original_priority = priority;
347  pr->public_data.type = type;
349  pr->sender_pid = sender_pid;
350  pr->origin_pid = origin_pid;
351  pr->rh = rh;
352  pr->rh_cls = rh_cls;
353  GNUNET_assert ((sender_pid != 0) || (0 == (options & GSF_PRO_FORWARD_ONLY)));
354  if (ttl >= 0)
357  else
361  (uint32_t) (-ttl)));
362  if (replies_seen_count > 0)
363  {
364  pr->replies_seen_size = replies_seen_count;
365  pr->replies_seen =
368  replies_seen,
369  replies_seen_count * sizeof (struct GNUNET_HashCode));
370  pr->replies_seen_count = replies_seen_count;
371  }
372  if ((NULL != bf_data) &&
374  {
376  pr->public_data.type,
377  mingle,
378  bf_data,
379  bf_size,
380  "seen-set-size",
381  0,
382  NULL);
383  }
384  else if ((replies_seen_count > 0) &&
386  {
388  }
390  &pr->public_data.query,
391  pr,
394  {
396  pr,
398  /* make sure we don't track too many requests */
401  {
403  GNUNET_assert (NULL != dpr);
404  if (pr == dpr)
405  break; /* let the request live briefly... */
406  if (NULL != dpr->rh)
407  dpr->rh (dpr->rh_cls,
409  dpr,
410  UINT32_MAX,
414  NULL,
415  0);
417  }
418  }
420  gettext_noop ("# Pending requests active"),
421  1,
422  GNUNET_NO);
423  return pr;
424 }
const struct GNUNET_PeerIdentity * target
Identity of a peer hosting the content, otherwise NULl.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:419
Request is allowed to refresh bloomfilter and change mingle value.
Any type of block, used as a wildcard when searching.
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
struct GNUNET_TIME_Absolute ttl
Current TTL for the request.
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:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_TIME_UNIT_SECONDS
One second.
uint32_t anonymity_level
Desired anonymity level.
static struct GNUNET_CONTAINER_Heap * requests_by_expiration_heap
Heap with the request that will expire next at the top.
static struct GNUNET_CONTAINER_MultiHashMap * pr_map
All pending requests, ordered by the query.
struct GSF_PendingRequestData public_data
Public data for the request.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_TIME_Absolute start_time
When did we start with the request.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static void refresh_bloomfilter(enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr)
Recalculate our bloom filter for filtering replies.
uint64_t abs_value_us
The actual value.
static unsigned int anonymity_level
Anonymity level option to use for publishing.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GNUNET_HashCode query
Primary query hash for this request.
unsigned int replies_seen_count
Number of valid entries in the 'replies_seen' array.
Request persists indefinitely (no expiration).
GNUNET_PEER_Id origin_pid
Identity of the peer that we should never forward this query to since it originated this query (0 for...
#define GNUNET_memcpy(dst, src, n)
static unsigned long long max_pending_requests
Maximum number of requests (from other peers, overall) that we're willing to have pending at any give...
struct GNUNET_BLOCK_Context * GSF_block_ctx
Our block context.
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
void * rh_cls
Closure for rh.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:439
enum GNUNET_BLOCK_Type type
Type of the requested block.
Type of a block representing any type of search result (universal).
A 512-bit hashcode.
GSF_PendingRequestReplyHandler rh
Function to call if we encounter a reply.
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.
uint32_t original_priority
Priority that this request (originally) had for us.
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.
struct GNUNET_BLOCK_Group * GNUNET_BLOCK_group_create(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, uint32_t nonce, const void *raw_data, size_t raw_data_size,...)
Create a new block group.
Definition: block.c:290
Allow multiple values with the same key.
unsigned int replies_seen_size
Length of the 'replies_seen' array.
The identity of the host (wraps the signing key of the peer).
enum GSF_PendingRequestOptions options
Options for the request.
Request must only be forwarded (no routing)
struct GNUNET_BLOCK_Group * bg
Block group for filtering replies we've already seen.
#define GNUNET_log(kind,...)
struct GNUNET_CONTAINER_HeapNode * hnode
Entry for this pending request in the expiration heap, or NULL.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t priority
Priority that this request (still) has for us.
An active request.
void GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, int full_cleanup)
Explicitly cancel a pending request.
Query is valid, no reply given.
GNUNET_PEER_Id sender_pid
Identity of the peer that we should use for the 'sender' (recipient of the response) when forwarding ...
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_HashCode * replies_seen
Array of hash codes of replies we've already seen.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_pending_request_update_()

void GSF_pending_request_update_ ( struct GSF_PendingRequest pr,
const struct GNUNET_HashCode replies_seen,
unsigned int  replies_seen_count 
)

Update a given pending request with additional replies that have been seen.

Parameters
prrequest to update
replies_seenhash codes of replies that we've seen
replies_seen_countsize of the replies_seen array
prrequest to update
replies_seenhash codes of replies that we've seen
replies_seen_countsize of the replies_seen array

Definition at line 470 of file gnunet-service-fs_pr.c.

References GSF_PendingRequest::bg, GSF_PendingRequest::gh, GNUNET_array_grow, GNUNET_BLOCK_group_set_seen(), GNUNET_break, GNUNET_DHT_get_filter_known_results(), GNUNET_memcpy, GNUNET_OK, GSF_PRO_BLOOMFILTER_FULL_REFRESH, GSF_PendingRequestData::options, GSF_PendingRequest::public_data, refresh_bloomfilter(), GSF_PendingRequest::replies_seen, GSF_PendingRequest::replies_seen_count, GSF_PendingRequest::replies_seen_size, and GSF_PendingRequestData::type.

Referenced by handle_client_start_search(), and process_reply().

473 {
474  if (replies_seen_count + pr->replies_seen_count < pr->replies_seen_count)
475  return; /* integer overflow */
477  {
478  /* we're responsible for the BF, full refresh */
479  if (replies_seen_count + pr->replies_seen_count > pr->replies_seen_size)
481  pr->replies_seen_size,
482  replies_seen_count + pr->replies_seen_count);
484  replies_seen,
485  sizeof (struct GNUNET_HashCode) * replies_seen_count);
486  pr->replies_seen_count += replies_seen_count;
488  }
489  else
490  {
491  if (NULL == pr->bg)
492  {
493  /* we're not the initiator, but the initiator did not give us
494  * any bloom-filter, so we need to create one on-the-fly */
496  }
497  else
498  {
501  replies_seen,
502  pr->replies_seen_count));
503  }
504  }
505  if (NULL != pr->gh)
507  replies_seen_count,
508  replies_seen);
509 }
Request is allowed to refresh bloomfilter and change mingle value.
struct GSF_PendingRequestData public_data
Public data for the request.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void refresh_bloomfilter(enum GNUNET_BLOCK_Type type, struct GSF_PendingRequest *pr)
Recalculate our bloom filter for filtering replies.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
unsigned int replies_seen_count
Number of valid entries in the &#39;replies_seen&#39; array.
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_memcpy(dst, src, n)
enum GNUNET_BLOCK_Type type
Type of the requested block.
A 512-bit hashcode.
struct GNUNET_DHT_GetHandle * gh
DHT request handle for this request (or NULL for none).
void GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, unsigned int num_results, const struct GNUNET_HashCode *results)
Tell the DHT not to return any of the following known results to this client.
Definition: dht_api.c:1131
unsigned int replies_seen_size
Length of the &#39;replies_seen&#39; array.
enum GSF_PendingRequestOptions options
Options for the request.
struct GNUNET_BLOCK_Group * bg
Block group for filtering replies we&#39;ve already seen.
struct GNUNET_HashCode * replies_seen
Array of hash codes of replies we&#39;ve already seen.
int 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:410
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_pending_request_get_data_()

struct GSF_PendingRequestData* GSF_pending_request_get_data_ ( struct GSF_PendingRequest pr)

Obtain the public data associated with a pending request.

Parameters
prpending request
Returns
associated public data

Definition at line 433 of file gnunet-service-fs_pr.c.

References GSF_PendingRequest::public_data.

Referenced by client_response_handler(), free_pending_request(), get_latest(), get_rp_key(), GSF_plan_add_(), GSF_plan_notify_peer_disconnect_(), GSF_plan_notify_request_done_(), handle_client_start_search(), handle_p2p_get(), handle_p2p_reply(), merge_pr(), peer_request_destroy(), plan(), start_p2p_processing(), and test_exist_cb().

434 {
435  return &pr->public_data;
436 }
struct GSF_PendingRequestData public_data
Public data for the request.
Here is the caller graph for this function:

◆ GSF_pending_request_test_active_()

int GSF_pending_request_test_active_ ( struct GSF_PendingRequest pr)

Check if the given request is still active.

Parameters
prpending request
Returns
GNUNET_YES if the request is still active

Definition at line 1845 of file gnunet-service-fs_pr.c.

References GNUNET_NO, GNUNET_YES, and GSF_PendingRequest::rh.

Referenced by consider_peer_for_forwarding(), get_latest(), GSF_consider_forwarding(), GSF_plan_add_(), and merge_pr().

1846 {
1847  return (NULL != pr->rh) ? GNUNET_YES : GNUNET_NO;
1848 }
#define GNUNET_NO
Definition: gnunet_common.h:81
GSF_PendingRequestReplyHandler rh
Function to call if we encounter a reply.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ GSF_pending_request_is_compatible_()

int GSF_pending_request_is_compatible_ ( struct GSF_PendingRequest pra,
struct GSF_PendingRequest prb 
)

Test if two pending requests are compatible (would generate the same query modulo filters and should thus be processed jointly).

Parameters
praa pending request
prbanother pending request
Returns
GNUNET_OK if the requests are compatible

Definition at line 449 of file gnunet-service-fs_pr.c.

References GNUNET_NO, GNUNET_OK, GSF_PendingRequest::public_data, GSF_PendingRequestData::query, and GSF_PendingRequestData::type.

Referenced by merge_pr().

451 {
452  if ((pra->public_data.type != prb->public_data.type) ||
453  (0 != memcmp (&pra->public_data.query,
454  &prb->public_data.query,
455  sizeof (struct GNUNET_HashCode))))
456  return GNUNET_NO;
457  return GNUNET_OK;
458 }
struct GSF_PendingRequestData public_data
Public data for the request.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HashCode query
Primary query hash for this request.
enum GNUNET_BLOCK_Type type
Type of the requested block.
A 512-bit hashcode.
Here is the caller graph for this function:

◆ GSF_pending_request_get_message_()

struct GNUNET_MQ_Envelope* GSF_pending_request_get_message_ ( struct GSF_PendingRequest pr)

Generate the message corresponding to the given pending request for transmission to other peers.

Parameters
prrequest to generate the message for
Returns
envelope with the request message

Definition at line 520 of file gnunet-service-fs_pr.c.

References GNUNET_TIME_Absolute::abs_value_us, GSF_PendingRequest::bg, env, GetMessage::filter_mutator, GET_MESSAGE_BIT_RETURN_TO, GET_MESSAGE_BIT_TRANSMIT_TO, GNUNET_BLOCK_group_serialize(), GNUNET_break, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_FS_GET, GNUNET_MQ_msg_extra, GNUNET_OK, GNUNET_PEER_resolve(), GNUNET_TIME_absolute_get(), GNUNET_YES, GSF_PRO_FORWARD_ONLY, GetMessage::hash_bitmap, GSF_PendingRequestData::num_transmissions, GSF_PendingRequestData::options, GetMessage::priority, GSF_PendingRequestData::priority, GSF_PendingRequest::public_data, GetMessage::query, GSF_PendingRequestData::query, GSF_PendingRequestData::respect_offered, GSF_PendingRequest::sender_pid, GSF_PendingRequestData::target, GetMessage::ttl, GSF_PendingRequestData::ttl, GSF_PendingRequestData::type, and GetMessage::type.

Referenced by schedule_peer_transmission().

521 {
522  struct GNUNET_MQ_Envelope *env;
523  struct GetMessage *gm;
524  struct GNUNET_PeerIdentity *ext;
525  unsigned int k;
526  uint32_t bm;
527  uint32_t prio;
528  size_t bf_size;
529  struct GNUNET_TIME_Absolute now;
530  int64_t ttl;
531  int do_route;
532  void *bf_data;
533  uint32_t bf_nonce;
534 
536  "Building request message for `%s' of type %d\n",
538  pr->public_data.type);
539  k = 0;
540  bm = 0;
541  do_route = (0 == (pr->public_data.options & GSF_PRO_FORWARD_ONLY));
542  if ((! do_route) && (pr->sender_pid == 0))
543  {
544  GNUNET_break (0);
545  do_route = GNUNET_YES;
546  }
547  if (! do_route)
548  {
550  k++;
551  }
552  if (NULL != pr->public_data.target)
553  {
555  k++;
556  }
557  if (GNUNET_OK !=
558  GNUNET_BLOCK_group_serialize (pr->bg, &bf_nonce, &bf_data, &bf_size))
559  {
560  bf_size = 0;
561  bf_data = NULL;
562  }
563  env = GNUNET_MQ_msg_extra (gm,
564  bf_size + k * sizeof (struct GNUNET_PeerIdentity),
566  gm->type = htonl (pr->public_data.type);
567  if (do_route)
569  pr->public_data.priority + 1);
570  else
571  prio = 0;
572  pr->public_data.priority -= prio;
574  pr->public_data.respect_offered += prio;
575  gm->priority = htonl (prio);
576  now = GNUNET_TIME_absolute_get ();
577  ttl = (int64_t) (pr->public_data.ttl.abs_value_us - now.abs_value_us);
578  gm->ttl = htonl (ttl / 1000LL / 1000LL);
579  gm->filter_mutator = htonl (bf_nonce);
580  gm->hash_bitmap = htonl (bm);
581  gm->query = pr->public_data.query;
582  ext = (struct GNUNET_PeerIdentity *) &gm[1];
583  k = 0;
584  if (! do_route)
585  GNUNET_PEER_resolve (pr->sender_pid, &ext[k++]);
586  if (NULL != pr->public_data.target)
587  ext[k++] = *pr->public_data.target;
588  GNUNET_memcpy (&ext[k], bf_data, bf_size);
589  GNUNET_free_non_null (bf_data);
590  return env;
591 }
const struct GNUNET_PeerIdentity * target
Identity of a peer hosting the content, otherwise NULl.
uint32_t num_transmissions
Counter for how often this request has been transmitted (estimate, because we might have the same req...
#define GET_MESSAGE_BIT_TRANSMIT_TO
The peer identity of a peer that had claimed to have the content previously is included (can be used ...
int32_t ttl
Relative time to live in MILLISECONDS (network byte order)
uint32_t priority
How important is this request (network byte order)
struct GNUNET_TIME_Absolute ttl
Current TTL for the request.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
struct GSF_PendingRequestData public_data
Public data for the request.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:226
uint64_t abs_value_us
The actual value.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint32_t filter_mutator
The content hash should be mutated using this value before checking against the bloomfilter (used to ...
struct GNUNET_HashCode query
Primary query hash for this request.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
#define GNUNET_memcpy(dst, src, n)
Message to the datastore service asking about specific content.
Definition: datastore.h:143
uint32_t hash_bitmap
Which of the optional hash codes are present at the end of the message? See GET_MESSAGE_BIT_xx consta...
struct GNUNET_HashCode query
Hashcodes of the file(s) we&#39;re looking for.
#define GET_MESSAGE_BIT_RETURN_TO
The peer identity of a peer waiting for the reply is included (used if the response should be transmi...
uint32_t respect_offered
How much respect did we (in total) offer for this request so far (estimate, because we might have the...
enum GNUNET_BLOCK_Type type
Type of the requested block.
int GNUNET_BLOCK_group_serialize(struct GNUNET_BLOCK_Group *bg, uint32_t *nonce, void **raw_data, size_t *raw_data_size)
Serialize state of a block group.
Definition: block.c:181
uint32_t type
Desired content type.
Definition: datastore.h:153
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
The identity of the host (wraps the signing key of the peer).
enum GSF_PendingRequestOptions options
Options for the request.
Request must only be forwarded (no routing)
struct GNUNET_BLOCK_Group * bg
Block group for filtering replies we&#39;ve already seen.
#define GNUNET_log(kind,...)
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t priority
Priority that this request (still) has for us.
#define GNUNET_MESSAGE_TYPE_FS_GET
P2P request for content (one FS to another).
GNUNET_PEER_Id sender_pid
Identity of the peer that we should use for the &#39;sender&#39; (recipient of the response) when forwarding ...
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_pending_request_cancel_()

void GSF_pending_request_cancel_ ( struct GSF_PendingRequest pr,
int  full_cleanup 
)

Explicitly cancel a pending request.

Parameters
prrequest to cancel
full_cleanupfully purge the request

Definition at line 669 of file gnunet-service-fs_pr.c.

References GSF_PendingRequest::cadet_request, GSF_PendingRequest::cadet_retry_count, CADET_RETRY_MAX, clean_request(), GSF_PendingRequest::gh, GNUNET_assert, GNUNET_DATASTORE_cancel(), GNUNET_DHT_get_stop(), GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_YES, GSF_cadet_query_cancel(), GSF_plan_notify_request_done_(), GSF_PendingRequest::llc_cont, GSF_PendingRequest::llc_cont_cls, GSF_PendingRequest::local_result, GSF_PendingRequest::public_data, GSF_PendingRequest::qe, GSF_PendingRequestData::query, GSF_PendingRequest::rh, and GSF_PendingRequest::warn_task.

Referenced by cancel_pending_request(), client_request_destroy(), GSF_pending_request_create_(), and test_exist_cb().

670 {
672 
673  if (NULL == pr_map)
674  return; /* already cleaned up! */
675  if (GNUNET_NO == full_cleanup)
676  {
677  /* make request inactive (we're no longer interested in more results),
678  * but do NOT remove from our data-structures, we still need it there
679  * to prevent the request from looping */
680  pr->rh = NULL;
681  if (NULL != pr->cadet_request)
682  {
685  pr->cadet_request = NULL;
686  }
687  if (NULL != (cont = pr->llc_cont))
688  {
689  pr->llc_cont = NULL;
690  cont (pr->llc_cont_cls, pr, pr->local_result);
691  }
693  if (NULL != pr->qe)
694  {
696  pr->qe = NULL;
697  }
698  if (NULL != pr->gh)
699  {
700  GNUNET_DHT_get_stop (pr->gh);
701  pr->gh = NULL;
702  }
703  if (NULL != pr->warn_task)
704  {
706  pr->warn_task = NULL;
707  }
708  return;
709  }
711  clean_request (NULL, &pr->public_data.query, pr));
712 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_SCHEDULER_Task * warn_task
Task that warns us if the local datastore lookup takes too long.
static struct GNUNET_CONTAINER_MultiHashMap * pr_map
All pending requests, ordered by the query.
struct GSF_PendingRequestData public_data
Public data for the request.
#define GNUNET_NO
Definition: gnunet_common.h:81
GSF_LocalLookupContinuation llc_cont
Function to call upon completion of the local get request, or NULL for none.
struct GNUNET_HashCode query
Primary query hash for this request.
void(* GSF_LocalLookupContinuation)(void *cls, struct GSF_PendingRequest *pr, enum GNUNET_BLOCK_EvaluationResult result)
Function to be called after we&#39;re done processing replies from the local lookup.
enum GNUNET_BLOCK_EvaluationResult local_result
Last result from the local datastore lookup evaluation.
void * llc_cont_cls
Closure for llc_cont.
GSF_PendingRequestReplyHandler rh
Function to call if we encounter a reply.
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1160
struct GNUNET_DHT_GetHandle * gh
DHT request handle for this request (or NULL for none).
void GSF_plan_notify_request_done_(struct GSF_PendingRequest *pr)
Notify the plan about a request being done; destroy all entries associated with this request...
#define CADET_RETRY_MAX
If obtaining a block via cadet fails, how often do we retry it before giving up for good (and stickin...
unsigned int cadet_retry_count
How often have we retried this request via &#39;cadet&#39;? (used to bound overall retries).
static int clean_request(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator to free pending requests.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
struct GNUNET_DATASTORE_QueueEntry * qe
Datastore queue entry for this request (or NULL for none).
void GSF_cadet_query_cancel(struct GSF_CadetRequest *sr)
Cancel an active request; must not be called after &#39;proc&#39; was calld.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GSF_CadetRequest * cadet_request
Cadet request handle for this request (or NULL for none).
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_iterate_pending_requests_()

void GSF_iterate_pending_requests_ ( GSF_PendingRequestIterator  it,
void *  cls 
)

Iterate over all pending requests.

Parameters
itfunction to call for each request
clsclosure for it
itfunction to call for each request
clsclosure for it

Definition at line 722 of file gnunet-service-fs_pr.c.

References GNUNET_CONTAINER_multihashmap_iterate().

Referenced by GSF_peer_connect_handler().

723 {
725  pr_map,
727  cls);
728 }
int(* GNUNET_CONTAINER_MulitHashMapIteratorCallback)(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator over hash map entries.
static struct GNUNET_CONTAINER_MultiHashMap * pr_map
All pending requests, ordered by the query.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_p2p_put()

void handle_p2p_put ( void *  cls,
const struct PutMessage put 
)

Handle P2P "CONTENT" message.

Checks that the message is well-formed and then checks if there are any pending requests for this content and possibly passes it on (to local clients or other peers). Does NOT perform migration (content caching at this peer).

Parameters
clsthe other peer involved (sender)
putthe actual message

Checks that the message is well-formed and then checks if there are any pending requests for this content and possibly passes it on (to local clients or other peers). Does NOT perform migration (content caching at this peer).

Parameters
clsthe other peer involved
putthe actual message

Definition at line 1716 of file gnunet-service-fs_pr.c.

References active_to_migration, ProcessReplyClosure::anonymity_level, CONTENT_BANDWIDTH_VALUE, ProcessReplyClosure::data, ProcessReplyClosure::eo, expiration, PutMessage::expiration, ProcessReplyClosure::expiration, gettext_noop, GNUNET_assert, GNUNET_BLOCK_EO_NONE, GNUNET_BLOCK_get_key(), GNUNET_break_op, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_DATASTORE_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_LOAD_get_load(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PEER_resolve(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_min(), GNUNET_TIME_absolute_ntoh(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_TIME_UNIT_YEARS, GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_YES, GSF_block_ctx, GSF_block_peer_migration_(), GSF_connected_peer_change_preference_(), GSF_cover_content_count, GSF_dsh, GSF_get_peer_performance_data_(), GSF_stats, PutMessage::header, MAX_DATASTORE_QUEUE, PutMigrationContext::origin, peer, pid, ProcessReplyClosure::priority, process_reply(), put_migration_continuation(), ProcessReplyClosure::request_found, PutMigrationContext::requested, GSF_PeerPerformanceData::respect, ProcessReplyClosure::sender, GNUNET_MessageHeader::size, ProcessReplyClosure::size, PutMigrationContext::start, test_put_load_too_high(), type, PutMessage::type, and ProcessReplyClosure::type.

1717 {
1718  struct GSF_ConnectedPeer *cp = cls;
1719  uint16_t msize;
1720  size_t dsize;
1721  enum GNUNET_BLOCK_Type type;
1723  struct GNUNET_HashCode query;
1724  struct ProcessReplyClosure prq;
1725  struct GNUNET_TIME_Relative block_time;
1726  double putl;
1727  struct PutMigrationContext *pmc;
1728 
1730  "Received P2P PUT from %s\n",
1733  msize = ntohs (put->header.size);
1734  dsize = msize - sizeof (struct PutMessage);
1735  type = ntohl (put->type);
1737  /* do not allow migrated content to live longer than 1 year */
1740  expiration);
1741  if (GNUNET_OK !=
1742  GNUNET_BLOCK_get_key (GSF_block_ctx, type, &put[1], dsize, &query))
1743  {
1744  GNUNET_break_op (0);
1745  return;
1746  }
1748  gettext_noop ("# GAP PUT messages received"),
1749  1,
1750  GNUNET_NO);
1751  /* now, lookup 'query' */
1752  prq.data = (const void *) &put[1];
1753  prq.sender = cp;
1754  prq.size = dsize;
1755  prq.type = type;
1756  prq.expiration = expiration;
1757  prq.priority = 0;
1758  prq.anonymity_level = UINT32_MAX;
1759  prq.request_found = GNUNET_NO;
1760  prq.eo = GNUNET_BLOCK_EO_NONE;
1762  &query,
1763  &process_reply,
1764  &prq);
1765  if (NULL != cp)
1766  {
1769  1000 * prq.priority);
1770  GSF_get_peer_performance_data_ (cp)->respect += prq.priority;
1771  }
1772  if ((GNUNET_YES == active_to_migration) && (NULL != cp) &&
1773  (GNUNET_NO == test_put_load_too_high (prq.priority)))
1774  {
1776  "Replicating result for query `%s' with priority %u\n",
1777  GNUNET_h2s (&query),
1778  prq.priority);
1779  pmc = GNUNET_new (struct PutMigrationContext);
1780  pmc->start = GNUNET_TIME_absolute_get ();
1781  pmc->requested = prq.request_found;
1784  &pmc->origin);
1785  if (NULL == GNUNET_DATASTORE_put (GSF_dsh,
1786  0,
1787  &query,
1788  dsize,
1789  &put[1],
1790  type,
1791  prq.priority,
1792  1 /* anonymity */,
1793  0 /* replication */,
1794  expiration,
1795  1 + prq.priority,
1798  pmc))
1799  {
1801  GNUNET_SYSERR,
1803  NULL);
1804  }
1805  }
1806  else if (NULL != cp)
1807  {
1809  "Choosing not to keep content `%s' (%d/%d)\n",
1810  GNUNET_h2s (&query),
1812  test_put_load_too_high (prq.priority));
1813  }
1815  if ((NULL != cp) && (GNUNET_NO == prq.request_found) &&
1817  (putl > 2.5 * (1 + prq.priority))))
1818  {
1821  block_time = GNUNET_TIME_relative_multiply (
1824  (unsigned int) (60000 * putl * putl)));
1825  GNUNET_log (
1827  "Asking to stop migration for %s because of load %f and events %d/%d\n",
1829  putl,
1831  (GNUNET_NO == prq.request_found));
1833  GNUNET_TIME_relative_to_absolute (block_time));
1834  }
1835 }
void GSF_connected_peer_change_preference_(struct GSF_ConnectedPeer *cp, uint64_t pref)
Notify core about a preference we have for the given peer (to allocate more resources towards it)...
static char * expiration
Credential TTL.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:670
#define GNUNET_TIME_UNIT_ZERO_ABS
Absolute time zero.
Response from FS service with a result for a previous FS search.
Definition: fs.h:336
struct GNUNET_TIME_AbsoluteNBO expiration
When does this result expire?
Definition: fs.h:352
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_put(struct GNUNET_DATASTORE_Handle *h, uint32_t rid, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the datastore.
Closure for process_reply() function.
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:245
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void put_migration_continuation(void *cls, int success, struct GNUNET_TIME_Absolute min_expiration, const char *msg)
Continuation called to notify client about result of the operation.
double GNUNET_LOAD_get_load(struct GNUNET_LOAD_Value *load)
Get the current load.
Definition: load.c:202
static struct GNUNET_CONTAINER_MultiHashMap * pr_map
All pending requests, ordered by the query.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:81
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Default behavior.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static int test_put_load_too_high(uint32_t priority)
Test if the DATABASE (PUT) load on this peer is too high to even consider processing the query at all...
static int process_reply(void *cls, const struct GNUNET_HashCode *key, void *value)
We have received a reply; handle it!
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:226
int GNUNET_BLOCK_get_key(struct GNUNET_BLOCK_Context *ctx, enum GNUNET_BLOCK_Type type, const void *block, size_t block_size, struct GNUNET_HashCode *key)
Function called to obtain the key for a block.
Definition: block.c:379
struct GNUNET_TIME_Absolute start
Start time for the operation.
uint32_t respect
Respect rating for this peer.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GSF_PeerPerformanceData * GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp)
Return the performance data record for the given peer.
struct GNUNET_BLOCK_Context * GSF_block_ctx
Our block context.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:439
#define CONTENT_BANDWIDTH_VALUE
Bandwidth value of a 0-priority content (must be fairly high compared to query since content is typic...
struct GNUNET_MessageHeader header
Message type will be GNUNET_MESSAGE_TYPE_FS_PUT.
Definition: fs.h:342
A 512-bit hashcode.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_DATASTORE_Handle * GSF_dsh
Our connection to the datastore.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
int requested
GNUNET_YES if we had a matching request for this block, GNUNET_NO if not.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint32_t type
Type of the block (in big endian).
Definition: fs.h:347
static struct GNUNET_LOAD_Value * datastore_put_load
Datastore &#39;PUT&#39; load tracking.
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.
#define MAX_DATASTORE_QUEUE
Maximum size of the datastore queue for P2P operations.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min(struct GNUNET_TIME_Absolute t1, struct GNUNET_TIME_Absolute t2)
Return the minimum of two absolute time values.
Definition: time.c:302
struct GNUNET_PeerIdentity origin
Request origin.
#define GNUNET_TIME_UNIT_YEARS
One year (365 days).
#define GNUNET_log(kind,...)
Context for put_migration_continuation().
A connected peer.
unsigned int GSF_cover_content_count
How many content messages have we received &#39;recently&#39; that have not yet been claimed as cover traffic...
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
void GSF_block_peer_migration_(struct GSF_ConnectedPeer *cp, struct GNUNET_TIME_Absolute block_time)
Ask a peer to stop migrating data to us until the given point in time.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
static int active_to_migration
Are we allowed to migrate content to this peer.
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ GSF_dht_lookup_()

void GSF_dht_lookup_ ( struct GSF_PendingRequest pr)

Consider looking up the data in the DHT (anonymity-level permitting).

Parameters
prthe pending request to process

Definition at line 1169 of file gnunet-service-fs_pr.c.

References GSF_PendingRequestData::anonymity_level, buf, DHT_GET_REPLICATION, GSF_PendingRequest::gh, GNUNET_ALIGN, GNUNET_assert, GNUNET_DHT_get_filter_known_results(), GNUNET_DHT_get_start(), GNUNET_DHT_get_stop(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_memcpy, GNUNET_PEER_resolve(), GSF_dht, GSF_PRO_FORWARD_ONLY, handle_dht_reply(), GSF_PendingRequestData::options, GSF_PendingRequest::public_data, GSF_PendingRequestData::query, GSF_PendingRequest::replies_seen, GSF_PendingRequest::replies_seen_count, GSF_PendingRequest::sender_pid, and GSF_PendingRequestData::type.

Referenced by process_reply(), and start_p2p_processing().

1170 {
1171  const void *xquery;
1172  size_t xquery_size;
1173  struct GNUNET_PeerIdentity pi;
1174  char buf[sizeof (struct GNUNET_HashCode) * 2] GNUNET_ALIGN;
1175 
1176  if (0 != pr->public_data.anonymity_level)
1177  return;
1178  if (NULL != pr->gh)
1179  {
1180  GNUNET_DHT_get_stop (pr->gh);
1181  pr->gh = NULL;
1182  }
1183  xquery = NULL;
1184  xquery_size = 0;
1185  if (0 != (pr->public_data.options & GSF_PRO_FORWARD_ONLY))
1186  {
1187  GNUNET_assert (0 != pr->sender_pid);
1189  GNUNET_memcpy (&buf[xquery_size], &pi, sizeof (struct GNUNET_PeerIdentity));
1190  xquery_size += sizeof (struct GNUNET_PeerIdentity);
1191  }
1193  pr->public_data.type,
1194  &pr->public_data.query,
1197  xquery,
1198  xquery_size,
1200  pr);
1201  if ((NULL != pr->gh) && (0 != pr->replies_seen_count))
1203  pr->replies_seen_count,
1204  pr->replies_seen);
1205 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t anonymity_level
Desired anonymity level.
struct GSF_PendingRequestData public_data
Public data for the request.
struct GNUNET_DHT_Handle * GSF_dht
Handle for DHT operations.
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:226
struct GNUNET_HashCode query
Primary query hash for this request.
unsigned int replies_seen_count
Number of valid entries in the &#39;replies_seen&#39; array.
#define GNUNET_memcpy(dst, src, n)
static char buf[2048]
enum GNUNET_BLOCK_Type type
Type of the requested block.
A 512-bit hashcode.
void GNUNET_DHT_get_stop(struct GNUNET_DHT_GetHandle *get_handle)
Stop async DHT-get.
Definition: dht_api.c:1160
struct GNUNET_DHT_GetHandle * gh
DHT request handle for this request (or NULL for none).
void GNUNET_DHT_get_filter_known_results(struct GNUNET_DHT_GetHandle *get_handle, unsigned int num_results, const struct GNUNET_HashCode *results)
Tell the DHT not to return any of the following known results to this client.
Definition: dht_api.c:1131
#define DHT_GET_REPLICATION
Desired replication level for GETs.
The identity of the host (wraps the signing key of the peer).
enum GSF_PendingRequestOptions options
Options for the request.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
Request must only be forwarded (no routing)
struct GNUNET_DHT_GetHandle * GNUNET_DHT_get_start(struct GNUNET_DHT_Handle *handle, enum GNUNET_BLOCK_Type type, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, const void *xquery, size_t xquery_size, GNUNET_DHT_GetIterator iter, void *iter_cls)
Perform an asynchronous GET operation on the DHT identified.
Definition: dht_api.c:1072
static void handle_dht_reply(void *cls, struct GNUNET_TIME_Absolute exp, const struct GNUNET_HashCode *key, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length, enum GNUNET_BLOCK_Type type, size_t size, const void *data)
Iterator called on each result obtained for a DHT operation that expects a reply. ...
GNUNET_PEER_Id sender_pid
Identity of the peer that we should use for the &#39;sender&#39; (recipient of the response) when forwarding ...
Each peer along the way should look at &#39;enc&#39; (otherwise only the k-peers closest to the key should lo...
struct GNUNET_HashCode * replies_seen
Array of hash codes of replies we&#39;ve already seen.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_cadet_lookup_()

void GSF_cadet_lookup_ ( struct GSF_PendingRequest pr)

Consider downloading via cadet (if possible)

Parameters
prthe pending request to process

Definition at line 1279 of file gnunet-service-fs_pr.c.

References GSF_PendingRequestData::anonymity_level, cadet_reply_proc(), GSF_PendingRequest::cadet_request, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GSF_cadet_query(), GSF_PendingRequest::public_data, GSF_PendingRequestData::query, GSF_PendingRequestData::target, and GSF_PendingRequestData::type.

Referenced by start_p2p_processing().

1280 {
1281  if (0 != pr->public_data.anonymity_level)
1282  return;
1283  if (0 == pr->public_data.target)
1284  {
1286  "Cannot do cadet-based download, target peer not known\n");
1287  return;
1288  }
1289  if (NULL != pr->cadet_request)
1290  return;
1292  &pr->public_data.query,
1293  pr->public_data.type,
1295  pr);
1296 }
const struct GNUNET_PeerIdentity * target
Identity of a peer hosting the content, otherwise NULl.
struct GSF_CadetRequest * GSF_cadet_query(const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *query, enum GNUNET_BLOCK_Type type, GSF_CadetReplyProcessor proc, void *proc_cls)
Look for a block by directly contacting a particular peer.
uint32_t anonymity_level
Desired anonymity level.
struct GSF_PendingRequestData public_data
Public data for the request.
struct GNUNET_HashCode query
Primary query hash for this request.
enum GNUNET_BLOCK_Type type
Type of the requested block.
static void cadet_reply_proc(void *cls, enum GNUNET_BLOCK_Type type, struct GNUNET_TIME_Absolute expiration, size_t data_size, const void *data)
Function called with a reply from the cadet.
#define GNUNET_log(kind,...)
struct GSF_CadetRequest * cadet_request
Cadet request handle for this request (or NULL for none).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_local_lookup_()

void GSF_local_lookup_ ( struct GSF_PendingRequest pr,
GSF_LocalLookupContinuation  cont,
void *  cont_cls 
)

Look up the request in the local datastore.

Parameters
prthe pending request to process
contfunction to call at the end
cont_clsclosure for cont

Definition at line 1687 of file gnunet-service-fs_pr.c.

References GSF_PendingRequest::cadet_request, gettext_noop, GSF_PendingRequest::gh, GNUNET_assert, GNUNET_NO, GNUNET_STATISTICS_update(), GSF_stats, GSF_PendingRequest::llc_cont, GSF_PendingRequest::llc_cont_cls, and start_local_query().

Referenced by handle_client_start_search(), and handle_p2p_get().

1690 {
1691  GNUNET_assert (NULL == pr->gh);
1692  GNUNET_assert (NULL == pr->cadet_request);
1693  GNUNET_assert (NULL == pr->llc_cont);
1694  pr->llc_cont = cont;
1695  pr->llc_cont_cls = cont_cls;
1696 #if INSANE_STATISTICS
1698  gettext_noop ("# Datastore lookups initiated"),
1699  1,
1700  GNUNET_NO);
1701 #endif
1702  start_local_query (pr, 0 /* next_uid */, true /* random */);
1703 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
GSF_LocalLookupContinuation llc_cont
Function to call upon completion of the local get request, or NULL for none.
static void start_local_query(struct GSF_PendingRequest *pr, uint64_t next_uid, bool random)
void * llc_cont_cls
Closure for llc_cont.
struct GNUNET_DHT_GetHandle * gh
DHT request handle for this request (or NULL for none).
struct GSF_CadetRequest * cadet_request
Cadet request handle for this request (or NULL for none).
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_pending_request_test_target_()

int GSF_pending_request_test_target_ ( struct GSF_PendingRequest pr,
const struct GNUNET_PeerIdentity target 
)

Is the given target a legitimate peer for forwarding the given request?

Parameters
prrequest
target
Returns
GNUNET_YES if this request could be forwarded to the given peer

Definition at line 1665 of file gnunet-service-fs_pr.c.

References GNUNET_NO, GNUNET_PEER_resolve(), GNUNET_YES, and GSF_PendingRequest::origin_pid.

Referenced by consider_peer_for_forwarding(), and consider_request_for_forwarding().

1667 {
1668  struct GNUNET_PeerIdentity pi;
1669 
1670  if (0 == pr->origin_pid)
1671  return GNUNET_YES;
1673  return (0 == memcmp (&pi, target, sizeof (struct GNUNET_PeerIdentity)))
1674  ? GNUNET_NO
1675  : GNUNET_YES;
1676 }
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:226
GNUNET_PEER_Id origin_pid
Identity of the peer that we should never forward this query to since it originated this query (0 for...
The identity of the host (wraps the signing key of the peer).
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_pending_request_init_()

void GSF_pending_request_init_ ( void  )

Setup the subsystem.

Definition at line 1855 of file gnunet-service-fs_pr.c.

References active_to_migration, DATASTORE_LOAD_AUTODECLINE, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_INFO, GNUNET_LOAD_value_init(), GNUNET_log_config_missing(), GNUNET_OK, GNUNET_YES, GSF_cfg, and max_pending_requests.

Referenced by run().

1856 {
1857  if (GNUNET_OK !=
1859  "fs",
1860  "MAX_PENDING_REQUESTS",
1862  {
1864  "fs",
1865  "MAX_PENDING_REQUESTS");
1866  }
1868  GNUNET_CONFIGURATION_get_value_yesno (GSF_cfg, "FS", "CONTENT_CACHING");
1873 }
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
struct GNUNET_LOAD_Value * GNUNET_LOAD_value_init(struct GNUNET_TIME_Relative autodecline)
Create a new load value.
Definition: load.c:125
static struct GNUNET_CONTAINER_Heap * requests_by_expiration_heap
Heap with the request that will expire next at the top.
static struct GNUNET_CONTAINER_MultiHashMap * pr_map
All pending requests, ordered by the query.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
const struct GNUNET_CONFIGURATION_Handle * GSF_cfg
Our configuration.
static unsigned long long max_pending_requests
Maximum number of requests (from other peers, overall) that we&#39;re willing to have pending at any give...
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
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.
static struct GNUNET_LOAD_Value * datastore_put_load
Datastore &#39;PUT&#39; load tracking.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
#define DATASTORE_LOAD_AUTODECLINE
At what frequency should our datastore load decrease automatically (since if we don&#39;t use it...
static int active_to_migration
Are we allowed to migrate content to this peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_pending_request_done_()

void GSF_pending_request_done_ ( void  )

Shutdown the subsystem.

Definition at line 1880 of file gnunet-service-fs_pr.c.

References clean_request(), GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), and GNUNET_LOAD_value_free.

Referenced by shutdown_task().

1881 {
1884  pr_map = NULL;
1888  datastore_put_load = NULL;
1889 }
static struct GNUNET_CONTAINER_Heap * requests_by_expiration_heap
Heap with the request that will expire next at the top.
static struct GNUNET_CONTAINER_MultiHashMap * pr_map
All pending requests, ordered by the query.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
static int clean_request(void *cls, const struct GNUNET_HashCode *key, void *value)
Iterator to free pending requests.
static struct GNUNET_LOAD_Value * datastore_put_load
Datastore &#39;PUT&#39; load tracking.
#define GNUNET_LOAD_value_free(lv)
Free a load value.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function: