GNUnet 0.21.1
gnunet-service-fs_pe.c File Reference

API to manage query plan. More...

Include dependency graph for gnunet-service-fs_pe.c:

Go to the source code of this file.

Data Structures

struct  GSF_PendingRequestPlanBijection
 M:N binding of plans to pending requests. More...
 
struct  GSF_RequestPlan
 Information we keep per request per peer. More...
 
struct  PeerPlan
 Transmission plan for a peer. More...
 
struct  MergeContext
 Closure for merge_pr(). More...
 

Macros

#define INSANE_STATISTICS   GNUNET_NO
 Collect an instance number of statistics? May cause excessive IPC. More...
 
#define N   ((double) 128.0)
 

Functions

static const struct GNUNET_HashCodeget_rp_key (struct GSF_RequestPlan *rp)
 Return the query (key in the plan_map) for the given request plan. More...
 
static void plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
 Insert the given request plan into the heap with the appropriate weight. More...
 
struct GSF_PendingRequestget_latest (const struct GSF_RequestPlan *rp)
 Get the pending request with the highest TTL from the given plan. More...
 
static void schedule_peer_transmission (void *cls)
 Figure out when and how to transmit to the given peer. More...
 
static int merge_pr (void *cls, const struct GNUNET_HashCode *query, void *element)
 Iterator that checks if an equivalent request is already present for this peer. More...
 
void GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
 Create a new query plan entry. More...
 
void GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
 Notify the plan about a peer being no longer available; destroy all entries associated with this peer. More...
 
int GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlanBijection *pr_head, struct GSF_ConnectedPeer *sender, struct GNUNET_TIME_Absolute *result)
 Get the last transmission attempt time for the request plan list referenced by pr_head, that was sent to sender. More...
 
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. More...
 
void GSF_plan_init ()
 Initialize plan subsystem. More...
 
void GSF_plan_done ()
 Shutdown plan subsystem. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMapplans
 Hash map from peer identities to PeerPlans. More...
 
static unsigned long long total_delay
 Sum of all transmission counters (equals total delay for all plan entries). More...
 
static unsigned long long plan_count
 Number of plan entries. More...
 

Detailed Description

API to manage query plan.

Author
Christian Grothoff

Definition in file gnunet-service-fs_pe.c.

Macro Definition Documentation

◆ INSANE_STATISTICS

#define INSANE_STATISTICS   GNUNET_NO

Collect an instance number of statistics? May cause excessive IPC.

Definition at line 35 of file gnunet-service-fs_pe.c.

◆ N

#define N   ((double) 128.0)

Function Documentation

◆ get_rp_key()

static const struct GNUNET_HashCode * get_rp_key ( struct GSF_RequestPlan rp)
static

Return the query (key in the plan_map) for the given request plan.

Note that this key may change as there can be multiple pending requests for the same key and we just return one of them; this particular one might complete while another one might still be active, hence the lifetime of the returned hash code is NOT necessarily identical to that of the struct GSF_RequestPlan given.

Parameters
rpa request plan
Returns
the associated query

Definition at line 233 of file gnunet-service-fs_pe.c.

234{
235 return &GSF_pending_request_get_data_ (rp->pe_head->pr)->query;
236}
static char * rp
Relying party.
struct GSF_PendingRequestData * GSF_pending_request_get_data_(struct GSF_PendingRequest *pr)
Obtain the public data associated with a pending request.
struct GNUNET_HashCode query
Primary query hash for this request.

References GSF_pending_request_get_data_(), GSF_PendingRequestData::query, and rp.

Referenced by GSF_plan_add_(), GSF_plan_notify_peer_disconnect_(), and plan().

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

◆ plan()

static void plan ( struct PeerPlan pp,
struct GSF_RequestPlan rp 
)
static

Insert the given request plan into the heap with the appropriate weight.

Parameters
ppassociated peer's plan
rprequest to plan

Running average delay we currently impose.

Definition at line 246 of file gnunet-service-fs_pe.c.

248{
249#define N ((double) 128.0)
253 static double avg_delay;
254
255 struct GSF_PendingRequestData *prd;
256 struct GNUNET_TIME_Relative delay;
257
258 GNUNET_assert (rp->pp == pp);
260 gettext_noop ("# average retransmission delay (ms)"),
261 total_delay * 1000LL / plan_count, GNUNET_NO);
262 prd = GSF_pending_request_get_data_ (rp->pe_head->pr);
263
264 if (rp->transmission_counter < 8)
265 delay =
267 rp->transmission_counter);
268 else if (rp->transmission_counter < 32)
269 delay =
271 8
272 + (1LL << (rp->transmission_counter - 8)));
273 else
274 delay =
276 8 + (1LL << 24));
277 delay.rel_value_us =
279 delay.rel_value_us + 1);
280 /* Add 0.01 to avg_delay to avoid division-by-zero later */
281 avg_delay = (((avg_delay * (N - 1.0)) + delay.rel_value_us) / N) + 0.01;
282
283 /*
284 * For the priority, we need to consider a few basic rules:
285 * 1) if we just started requesting (delay is small), we should
286 * virtually always have a priority of zero.
287 * 2) for requests with average latency, our priority should match
288 * the average priority observed on the network
289 * 3) even the longest-running requests should not be WAY out of
290 * the observed average (thus we bound by a factor of 2)
291 * 4) we add +1 to the observed average priority to avoid everyone
292 * staying put at zero (2 * 0 = 0...).
293 *
294 * Using the specific calculation below, we get:
295 *
296 * delay = 0 => priority = 0;
297 * delay = avg delay => priority = running-average-observed-priority;
298 * delay >> avg_delay => priority = 2 * running-average-observed-priority;
299 *
300 * which satisfies all of the rules above.
301 *
302 * Note: M_PI_4 = PI/4 = arctan(1)
303 */rp->priority =
305 + 1.0) * atan (delay.rel_value_us / avg_delay)) / M_PI_4;
306 /* Note: usage of 'round' and 'atan' requires -lm */
307
308 if (rp->transmission_counter != 0)
309 delay.rel_value_us += TTL_DECREMENT * 1000;
311 "Considering (re)transmission number %u in %s\n",
312 (unsigned int) rp->transmission_counter,
314 GNUNET_YES));
315 rp->earliest_transmission = GNUNET_TIME_relative_to_absolute (delay);
317 "Earliest (re)transmission for `%s' in %us\n",
318 GNUNET_h2s (&prd->query),
319 rp->transmission_counter);
320 GNUNET_assert (rp->hn == NULL);
322 rp->earliest_transmission).rel_value_us)
324 rp,
325 rp->priority);
326 else
327 rp->hn =
329 rp,
330 rp->earliest_transmission.abs_value_us);
333 get_rp_key (rp),
334 rp));
335#undef N
336}
#define gettext_noop(String)
Definition: gettext.h:70
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
double GSF_current_priorities
Typical priorities we're seeing from other peers right now.
#define TTL_DECREMENT
By which amount do we decrement the TTL for simple forwarding / indirection of the query; in milli-se...
#define N
static unsigned long long plan_count
Number of plan entries.
static unsigned long long total_delay
Sum of all transmission counters (equals total delay for all plan entries).
static const struct GNUNET_HashCode * get_rp_key(struct GSF_RequestPlan *rp)
Return the query (key in the plan_map) for the given request plan.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains_value(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, const void *value)
Check if the map contains the given value under the given key.
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.
#define GNUNET_log(kind,...)
@ GNUNET_YES
@ GNUNET_NO
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:405
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:570
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
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:484
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Public data (in the sense of not encapsulated within 'gnunet-service-fs_pr', not in the sense of netw...
struct GNUNET_CONTAINER_Heap * priority_heap
Heap with pending queries (struct GSF_RequestPlan), higher weights mean higher priority.
struct GNUNET_CONTAINER_MultiHashMap * plan_map
Map of queries to plan entries.
struct GNUNET_CONTAINER_Heap * delay_heap
Heap with pending queries (struct GSF_RequestPlan), by transmission time, lowest first.

References PeerPlan::delay_heap, get_rp_key(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_contains_value(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_SECONDS, GNUNET_YES, GSF_current_priorities, GSF_pending_request_get_data_(), GSF_stats, N, plan_count, PeerPlan::plan_map, PeerPlan::priority_heap, GSF_PendingRequestData::query, GNUNET_TIME_Relative::rel_value_us, rp, total_delay, and TTL_DECREMENT.

Referenced by GSF_plan_add_(), and schedule_peer_transmission().

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

◆ get_latest()

struct GSF_PendingRequest * get_latest ( const struct GSF_RequestPlan rp)

Get the pending request with the highest TTL from the given plan.

Parameters
rpplan to investigate
Returns
pending request with highest TTL

Definition at line 346 of file gnunet-service-fs_pe.c.

347{
348 struct GSF_PendingRequest *ret;
350 const struct GSF_PendingRequestData *rprd;
351 const struct GSF_PendingRequestData *prd;
352
353 bi = rp->pe_head;
354 if (NULL == bi)
355 return NULL; /* should never happen */
356 ret = bi->pr;
358 for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE)
359 {
363 if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us)
364 {
365 ret = bi->pr;
366 rprd = prd;
367 }
368 }
369 return ret;
370}
static int ret
Final status code.
Definition: gnunet-arm.c:94
int GSF_pending_request_test_active_(struct GSF_PendingRequest *pr)
Check if the given request is still active.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
uint64_t abs_value_us
The actual value.
struct GNUNET_TIME_Absolute ttl
Current TTL for the request.
M:N binding of plans to pending requests.
struct GSF_PendingRequest * pr
Associated pending request (identifies request details and one of the origins of the request).
struct GSF_PendingRequestPlanBijection * next_PE
This is a doubly-linked list.
An active request.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_break, GNUNET_YES, GSF_pending_request_get_data_(), GSF_pending_request_test_active_(), GSF_PendingRequestPlanBijection::next_PE, GSF_PendingRequestPlanBijection::pr, ret, rp, and GSF_PendingRequestData::ttl.

Referenced by merge_pr(), and schedule_peer_transmission().

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

◆ schedule_peer_transmission()

static void schedule_peer_transmission ( void *  cls)
static

Figure out when and how to transmit to the given peer.

Parameters
clsthe struct PeerPlan

Definition at line 379 of file gnunet-service-fs_pe.c.

380{
381 struct PeerPlan *pp = cls;
382 struct GSF_RequestPlan *rp;
383 struct GNUNET_TIME_Relative delay;
384
385 if (NULL != pp->task)
386 {
387 pp->task = NULL;
388 }
389 else
390 {
391 GNUNET_assert (NULL != pp->env);
392 pp->env = NULL;
393 }
394 /* move ready requests to priority queue */
395 while ((NULL != (rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap))) &&
397 (rp->earliest_transmission).rel_value_us))
398 {
401 rp,
402 rp->priority);
403 }
405 {
406 /* priority heap (still) empty, check for delay... */
408 if (NULL == rp)
409 {
411 "No active requests for plan %p.\n",
412 pp);
413 return; /* both queues empty */
414 }
415 delay = GNUNET_TIME_absolute_get_remaining (rp->earliest_transmission);
417 "Sleeping for %s before retrying requests on plan %p.\n",
419 GNUNET_YES),
420 pp);
422 gettext_noop ("# delay heap timeout (ms)"),
423 delay.rel_value_us / 1000LL, GNUNET_NO);
424
425 pp->task
426 = GNUNET_SCHEDULER_add_at (rp->earliest_transmission,
428 pp);
429 return;
430 }
431#if INSANE_STATISTICS
433 gettext_noop ("# query plans executed"),
434 1,
435 GNUNET_NO);
436#endif
437 /* process from priority heap */
440 "Executing query plan %p\n",
441 rp);
442 GNUNET_assert (NULL != rp);
443 rp->hn = NULL;
444 rp->last_transmission = GNUNET_TIME_absolute_get ();
445 rp->transmission_counter++;
446 total_delay++;
448 "Executing plan %p executed %u times, planning retransmission\n",
449 rp,
450 rp->transmission_counter);
451 GNUNET_assert (NULL == pp->env);
455 pp);
458 rp->priority,
459 pp->env);
462 "# query messages sent to other peers"),
463 1,
464 GNUNET_NO);
465 plan (pp,
466 rp);
467}
void GSF_peer_transmit_(struct GSF_ConnectedPeer *cp, int is_query, uint32_t priority, struct GNUNET_MQ_Envelope *env)
Transmit a message to the given peer as soon as possible.
static void schedule_peer_transmission(void *cls)
Figure out when and how to transmit to the given peer.
static void plan(struct PeerPlan *pp, struct GSF_RequestPlan *rp)
Insert the given request plan into the heap with the appropriate weight.
struct GSF_PendingRequest * get_latest(const struct GSF_RequestPlan *rp)
Get the pending request with the highest TTL from the given plan.
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.
void * GNUNET_CONTAINER_heap_peek(const struct GNUNET_CONTAINER_Heap *heap)
Get element stored at the root of heap.
void * GNUNET_CONTAINER_heap_remove_root(struct GNUNET_CONTAINER_Heap *heap)
Remove root of the heap.
unsigned int GNUNET_CONTAINER_heap_get_size(const struct GNUNET_CONTAINER_Heap *heap)
Get the current size of the heap.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:638
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:1255
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_absolute_get(void)
Get the current time.
Definition: time.c:111
Information we keep per request per peer.
Transmission plan for a peer.
struct GNUNET_SCHEDULER_Task * task
Current task for executing the plan.
struct GSF_ConnectedPeer * cp
Peer for which this is the plan.
struct GNUNET_MQ_Envelope * env
Current message under transmission for the plan.

References PeerPlan::cp, PeerPlan::delay_heap, PeerPlan::env, get_latest(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_heap_get_size(), GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_peek(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MQ_notify_sent(), GNUNET_NO, GNUNET_SCHEDULER_add_at(), GNUNET_STATISTICS_set(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GSF_peer_transmit_(), GSF_pending_request_get_message_(), GSF_stats, plan(), PeerPlan::priority_heap, GNUNET_TIME_Relative::rel_value_us, rp, schedule_peer_transmission(), PeerPlan::task, and total_delay.

Referenced by GSF_plan_add_(), and schedule_peer_transmission().

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

◆ merge_pr()

static int merge_pr ( void *  cls,
const struct GNUNET_HashCode query,
void *  element 
)
static

Iterator that checks if an equivalent request is already present for this peer.

Parameters
clsclosure
querythe query
elementrequest plan stored at the node
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not (merge success)

Definition at line 498 of file gnunet-service-fs_pe.c.

501{
502 struct MergeContext *mpr = cls;
503 struct GSF_RequestPlan *rp = element;
504 struct GSF_PendingRequestData *prd;
506 struct GSF_PendingRequest *latest;
507
510 if (GNUNET_OK !=
512 rp->pe_head->pr))
513 return GNUNET_YES;
514 /* merge new request with existing request plan */
516 bi->rp = rp;
517 bi->pr = mpr->pr;
520 prd->pr_head,
521 prd->pr_tail,
522 bi);
524 rp->pe_head,
525 rp->pe_tail,
526 bi);
527 mpr->merged = GNUNET_YES;
528#if INSANE_STATISTICS
530 gettext_noop ("# requests merged"),
531 1,
532 GNUNET_NO);
533#endif
534 latest = get_latest (rp);
535 if (GSF_pending_request_get_data_ (latest)->ttl.abs_value_us <
536 prd->ttl.abs_value_us)
537 {
538#if INSANE_STATISTICS
540 gettext_noop ("# requests refreshed"),
541 1,
542 GNUNET_NO);
543#endif
544 rp->transmission_counter = 0; /* reset */
545 }
546 return GNUNET_NO;
547}
static struct GNUNET_TIME_Relative ttl
Current record $TTL to use.
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 ...
#define GNUNET_CONTAINER_MDLL_insert(mdll, head, tail, element)
Insert an element at the head of a MDLL.
@ GNUNET_OK
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GSF_PendingRequestPlanBijection * pr_head
Fields for the plan module to track a DLL with the request.
struct GSF_PendingRequestPlanBijection * pr_tail
Fields for the plan module to track a DLL with the request.
struct GSF_RequestPlan * rp
Associated request plan (tells us one of the peers that we plan to forward the request to).
Closure for merge_pr().
int merged
Set to GNUNET_YES if we succeeded to merge.
struct GSF_PendingRequest * pr
Request we are trying to merge.

References GNUNET_TIME_Absolute::abs_value_us, get_latest(), gettext_noop, GNUNET_break, GNUNET_CONTAINER_MDLL_insert, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, GSF_pending_request_get_data_(), GSF_pending_request_is_compatible_(), GSF_pending_request_test_active_(), GSF_stats, MergeContext::merged, GSF_PendingRequestPlanBijection::pr, MergeContext::pr, GSF_PendingRequestData::pr_head, GSF_PendingRequestData::pr_tail, rp, GSF_PendingRequestPlanBijection::rp, ttl, and GSF_PendingRequestData::ttl.

Referenced by GSF_plan_add_().

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

◆ GSF_plan_add_()

void GSF_plan_add_ ( struct GSF_ConnectedPeer cp,
struct GSF_PendingRequest pr 
)

Create a new query plan entry.

Parameters
cppeer with the entry
prrequest with the entry

Definition at line 557 of file gnunet-service-fs_pe.c.

559{
560 const struct GNUNET_PeerIdentity *id;
561 struct PeerPlan *pp;
562 struct GSF_PendingRequestData *prd;
563 struct GSF_RequestPlan *rp;
565 struct MergeContext mpc;
566
569 GNUNET_assert (NULL != cp);
572 if (NULL == pp)
573 {
574 pp = GNUNET_new (struct PeerPlan);
576 pp->priority_heap =
578 pp->delay_heap =
580 pp->cp = cp;
583 id,
584 pp,
587 pp);
588 }
589 mpc.merged = GNUNET_NO;
590 mpc.pr = pr;
593 &prd->query,
594 &merge_pr,
595 &mpc);
596 if (GNUNET_NO != mpc.merged)
597 return;
598 plan_count++;
600 gettext_noop ("# query plan entries"),
601 1,
602 GNUNET_NO);
604 "Planning transmission of query `%s' to peer `%s'\n",
605 GNUNET_h2s (&prd->query),
606 GNUNET_i2s (id));
607 rp = GNUNET_new (struct GSF_RequestPlan);
609 bi->rp = rp;
610 bi->pr = pr;
612 prd->pr_head,
613 prd->pr_tail,
614 bi);
616 rp->pe_head,
617 rp->pe_tail,
618 bi);
619 rp->pp = pp;
622 get_rp_key (rp),
623 rp,
625 plan (pp,
626 rp);
627}
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
const struct GNUNET_PeerIdentity * GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp)
Obtain the identity of a connected peer.
static int merge_pr(void *cls, const struct GNUNET_HashCode *query, void *element)
Iterator that checks if an equivalent request is already present for this peer.
static struct GNUNET_CONTAINER_MultiPeerMap * plans
Hash map from peer identities to PeerPlans.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
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.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
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.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
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.
@ GNUNET_CONTAINER_HEAP_ORDER_MAX
Heap with the maximum cost at the root.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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:1305
The identity of the host (wraps the signing key of the peer).

References PeerPlan::cp, PeerPlan::delay_heap, get_rp_key(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MAX, GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_MDLL_insert, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_update(), GNUNET_YES, GSF_connected_peer_get_identity2_(), GSF_pending_request_get_data_(), GSF_pending_request_test_active_(), GSF_stats, id, merge_pr(), MergeContext::merged, plan(), plan_count, PeerPlan::plan_map, plans, GSF_PendingRequestPlanBijection::pr, MergeContext::pr, GSF_PendingRequestData::pr_head, GSF_PendingRequestData::pr_tail, PeerPlan::priority_heap, GSF_PendingRequestData::query, rp, GSF_PendingRequestPlanBijection::rp, schedule_peer_transmission(), and PeerPlan::task.

Referenced by consider_peer_for_forwarding(), and consider_request_for_forwarding().

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

◆ GSF_plan_notify_peer_disconnect_()

void GSF_plan_notify_peer_disconnect_ ( const struct GSF_ConnectedPeer cp)

Notify the plan about a peer being no longer available; destroy all entries associated with this peer.

Parameters
cpconnected peer

Definition at line 637 of file gnunet-service-fs_pe.c.

638{
639 const struct GNUNET_PeerIdentity *id;
640 struct PeerPlan *pp;
641 struct GSF_RequestPlan *rp;
642 struct GSF_PendingRequestData *prd;
644
647 if (NULL == pp)
648 return; /* nothing was ever planned for this peer */
651 pp));
652 if (NULL != pp->task)
653 {
655 pp->task = NULL;
656 }
657 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)))
658 {
661 get_rp_key (rp),
662 rp));
663 while (NULL != (bi = rp->pe_head))
664 {
666 rp->pe_head,
667 rp->pe_tail,
668 bi);
671 prd->pr_head,
672 prd->pr_tail,
673 bi);
674 GNUNET_free (bi);
675 }
676 plan_count--;
677 GNUNET_free (rp);
678 }
680 while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->delay_heap)))
681 {
684 get_rp_key (rp),
685 rp));
686 while (NULL != (bi = rp->pe_head))
687 {
690 rp->pe_head,
691 rp->pe_tail,
692 bi);
694 prd->pr_head,
695 prd->pr_tail,
696 bi);
697 GNUNET_free (bi);
698 }
699 plan_count--;
700 GNUNET_free (rp);
701 }
703 gettext_noop ("# query plan entries"),
705 GNUNET_NO);
708 GNUNET_free (pp);
709}
#define GNUNET_CONTAINER_MDLL_remove(mdll, head, tail, element)
Remove an element from a MDLL.
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_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
void GNUNET_CONTAINER_heap_destroy(struct GNUNET_CONTAINER_Heap *heap)
Destroys the heap.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981

References PeerPlan::delay_heap, get_rp_key(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_heap_remove_root(), GNUNET_CONTAINER_MDLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_YES, GSF_connected_peer_get_identity2_(), GSF_pending_request_get_data_(), GSF_stats, id, plan_count, PeerPlan::plan_map, plans, GSF_PendingRequestPlanBijection::pr, GSF_PendingRequestData::pr_head, GSF_PendingRequestData::pr_tail, PeerPlan::priority_heap, rp, and PeerPlan::task.

Referenced by GSF_peer_disconnect_handler().

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

◆ GSF_request_plan_reference_get_last_transmission_()

int GSF_request_plan_reference_get_last_transmission_ ( struct GSF_PendingRequestPlanBijection pr_head,
struct GSF_ConnectedPeer sender,
struct GNUNET_TIME_Absolute result 
)

Get the last transmission attempt time for the request plan list referenced by pr_head, that was sent to sender.

Get the last transmission attempt time for the request plan list referenced by 'rpr_head', that was sent to 'sender'.

Parameters
pr_headrequest plan reference list to check.
senderthe peer that we've sent the request to.
resultthe timestamp to fill, set to GNUNET_TIME_UNIT_FOREVER_ABS if never transmitted
Returns
GNUNET_YES if result was changed, GNUNET_NO otherwise.

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

729{
731
732 for (bi = pr_head; NULL != bi; bi = bi->next_PR)
733 {
734 if (bi->rp->pp->cp == sender)
735 {
736 if (0 == bi->rp->last_transmission.abs_value_us)
738 else
740 return GNUNET_YES;
741 }
742 }
743 return GNUNET_NO;
744}
static int result
Global testing status.
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
struct GSF_PendingRequestPlanBijection * next_PR
This is a doubly-linked list.
struct PeerPlan * pp
The transmission plan for a peer that this request is associated with.
struct GNUNET_TIME_Absolute last_transmission
When was the last time we transmitted this request to this peer? 0 for never.

References GNUNET_TIME_Absolute::abs_value_us, PeerPlan::cp, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_YES, GSF_RequestPlan::last_transmission, GSF_PendingRequestPlanBijection::next_PR, GSF_RequestPlan::pp, result, and GSF_PendingRequestPlanBijection::rp.

Referenced by process_reply().

Here is the caller graph for this function:

◆ GSF_plan_notify_request_done_()

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.

Parameters
prrequest that is done

Definition at line 754 of file gnunet-service-fs_pe.c.

755{
756 struct GSF_RequestPlan *rp;
757 struct GSF_PendingRequestData *prd;
759
761 while (NULL != (bi = prd->pr_head))
762 {
763 rp = bi->rp;
765 prd->pr_head,
766 prd->pr_tail,
767 bi);
769 rp->pe_head,
770 rp->pe_tail,
771 bi);
772 GNUNET_assert (bi->pr == pr);
773 if (NULL == rp->pe_head)
774 {
776 plan_count--;
779 &prd->query,
780 rp));
781 GNUNET_free (rp);
782 }
783 GNUNET_free (bi);
784 }
786 gettext_noop ("# query plan entries"),
788 GNUNET_NO);
789}
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.

References gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_MDLL_remove, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_set(), GNUNET_YES, GSF_pending_request_get_data_(), GSF_stats, plan_count, GSF_PendingRequestPlanBijection::pr, GSF_PendingRequestData::pr_head, GSF_PendingRequestData::pr_tail, GSF_PendingRequestData::query, rp, and GSF_PendingRequestPlanBijection::rp.

Referenced by clean_request(), and GSF_pending_request_cancel_().

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

◆ GSF_plan_init()

void GSF_plan_init ( void  )

Initialize plan subsystem.

Definition at line 796 of file gnunet-service-fs_pe.c.

797{
799 GNUNET_YES);
800}
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).

References GNUNET_CONTAINER_multipeermap_create(), GNUNET_YES, and plans.

Referenced by run().

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

◆ GSF_plan_done()

void GSF_plan_done ( void  )

Shutdown plan subsystem.

Definition at line 807 of file gnunet-service-fs_pe.c.

808{
811}
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_size(), and plans.

Referenced by shutdown_task().

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

Variable Documentation

◆ plans

struct GNUNET_CONTAINER_MultiPeerMap* plans
static

Hash map from peer identities to PeerPlans.

Definition at line 207 of file gnunet-service-fs_pe.c.

Referenced by GSF_plan_add_(), GSF_plan_done(), GSF_plan_init(), and GSF_plan_notify_peer_disconnect_().

◆ total_delay

unsigned long long total_delay
static

Sum of all transmission counters (equals total delay for all plan entries).

Definition at line 212 of file gnunet-service-fs_pe.c.

Referenced by plan(), and schedule_peer_transmission().

◆ plan_count

unsigned long long plan_count
static

Number of plan entries.

Definition at line 217 of file gnunet-service-fs_pe.c.

Referenced by GSF_plan_add_(), GSF_plan_notify_peer_disconnect_(), GSF_plan_notify_request_done_(), and plan().