GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-service-fs_cp.c File Reference

API to handle 'connected peers'. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_load_lib.h"
#include "gnunet-service-fs.h"
#include "gnunet-service-fs_cp.h"
#include "gnunet-service-fs_pe.h"
#include "gnunet-service-fs_pr.h"
#include "gnunet-service-fs_push.h"
#include "gnunet_peerstore_service.h"
Include dependency graph for gnunet-service-fs_cp.c:

Go to the source code of this file.

Data Structures

struct  GSF_PeerTransmitHandle
 Handle to cancel a transmission request. More...
 
struct  GSF_DelayedHandle
 Handle for an entry in our delay list. More...
 
struct  PeerRequest
 Information per peer and request. More...
 
struct  GSF_ConnectedPeer
 A connected peer. More...
 
struct  TestExistClosure
 Closure for test_exist_cb(). More...
 
struct  IterationContext
 Closure for call_iterator(). More...
 

Macros

#define RUNAVG_DELAY_N   16
 Ratio for moving average delay calculation. More...
 
#define RESPECT_FLUSH_FREQ   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 How often do we flush respect values to disk? More...
 
#define REPLY_TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 2)
 After how long do we discard a reply? More...
 
#define INSANE_STATISTICS   GNUNET_NO
 Collect an instane number of statistics? May cause excessive IPC. More...
 
#define N   ((double)128.0)
 

Functions

void GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id, struct GNUNET_TIME_Relative latency)
 Update the latency information kept for the given peer. More...
 
struct GSF_PeerPerformanceDataGSF_get_peer_performance_data_ (struct GSF_ConnectedPeer *cp)
 Return the performance data record for the given peer. More...
 
static void peer_transmit (struct GSF_ConnectedPeer *cp)
 Core is ready to transmit to a peer, get the message. More...
 
static void ats_reserve_callback (void *cls, const struct GNUNET_PeerIdentity *peer, int32_t amount, struct GNUNET_TIME_Relative res_delay)
 Function called by core upon success or failure of our bandwidth reservation request. More...
 
static void schedule_transmission (struct GSF_PeerTransmitHandle *pth)
 If ready (bandwidth reserved), try to schedule transmission via core for the given handle. More...
 
static void retry_reservation (void *cls)
 (re)try to reserve bandwidth from the given peer. More...
 
static void peer_respect_cb (void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
 Function called by PEERSTORE with peer respect record. More...
 
static int consider_peer_for_forwarding (void *cls, const struct GNUNET_HashCode *key, struct GSF_PendingRequest *pr)
 Function called for each pending request whenever a new peer connects, giving us a chance to decide about submitting the existing request to the new peer. More...
 
void * GSF_peer_connect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 A peer connected to us. More...
 
static void revive_migration (void *cls)
 It may be time to re-start migrating content to this peer. More...
 
struct GSF_ConnectedPeerGSF_peer_get_ (const struct GNUNET_PeerIdentity *peer)
 Get a handle for a connected peer. More...
 
void handle_p2p_migration_stop (void *cls, const struct MigrationStopMessage *msm)
 Handle P2P GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message. More...
 
static void free_pending_request (struct PeerRequest *peerreq)
 Free resources associated with the given peer request. More...
 
static int cancel_pending_request (void *cls, const struct GNUNET_HashCode *query, void *value)
 Cancel all requests associated with the peer. More...
 
static void peer_request_destroy (void *cls)
 Free the given request. More...
 
static void transmit_delayed_now (void *cls)
 The artificial delay is over, transmit the message now. More...
 
static struct GNUNET_TIME_Relative get_randomized_delay ()
 Get the randomized delay a response should be subjected to. More...
 
static void handle_p2p_reply (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...
 
static int change_peer_respect (struct GSF_ConnectedPeer *cp, int value)
 Increase the peer's respect by a value. More...
 
static int32_t bound_priority (uint32_t prio_in, struct GSF_ConnectedPeer *cp)
 We've received a request with the specified priority. More...
 
static int32_t bound_ttl (int32_t ttl_in, uint32_t prio)
 The priority level imposes a bound on the maximum value for the ttl that can be requested. More...
 
static int test_exist_cb (void *cls, const struct GNUNET_HashCode *hc, void *value)
 Test if the query already exists. More...
 
void handle_p2p_get (void *cls, const struct GetMessage *gm)
 Handle P2P "QUERY" message. More...
 
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. More...
 
void GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp, struct GNUNET_TIME_Absolute request_time, uint32_t request_priority)
 Report on receiving a reply; update the performance record of the given peer. More...
 
void GSF_peer_update_responder_client_ (struct GSF_ConnectedPeer *cp, struct GSF_LocalClient *initiator_client)
 Report on receiving a reply in response to an initiating client. More...
 
void GSF_peer_update_responder_peer_ (struct GSF_ConnectedPeer *cp, const struct GSF_ConnectedPeer *initiator_peer)
 Report on receiving a reply in response to an initiating peer. More...
 
static int flush_respect (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Write peer-respect information to a file - flush the buffer entry! More...
 
void GSF_peer_disconnect_handler (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 A peer disconnected from us. More...
 
static int call_iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Function that calls the callback for each peer. More...
 
void GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it, void *it_cls)
 Iterate over all connected peers. More...
 
void GSF_connected_peer_get_identity_ (const struct GSF_ConnectedPeer *cp, struct GNUNET_PeerIdentity *id)
 Obtain the identity of a connected peer. More...
 
const struct GNUNET_PeerIdentityGSF_connected_peer_get_identity2_ (const struct GSF_ConnectedPeer *cp)
 Obtain the identity of a connected peer. More...
 
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. More...
 
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). More...
 
static void cron_flush_respect (void *cls)
 Call this method periodically to flush respect information to disk. More...
 
void GSF_connected_peer_init_ ()
 Initialize peer management subsystem. More...
 
void GSF_connected_peer_done_ ()
 Shutdown peer management subsystem. More...
 
static int clean_local_client (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator to remove references to LC entry. More...
 
void GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc)
 Notification that a local client disconnected. More...
 

Variables

static struct GNUNET_CONTAINER_MultiPeerMapcp_map
 Map from peer identities to struct GSF_ConnectPeer entries. More...
 
static struct GNUNET_PEERSTORE_Handlepeerstore
 Handle to peerstore service. More...
 
static struct GNUNET_SCHEDULER_Taskfr_task
 Task used to flush respect values to disk. More...
 

Detailed Description

API to handle 'connected peers'.

Author
Christian Grothoff

Definition in file gnunet-service-fs_cp.c.

Macro Definition Documentation

◆ RUNAVG_DELAY_N

#define RUNAVG_DELAY_N   16

Ratio for moving average delay calculation.

The previous average goes in with a factor of (n-1) into the calculation. Must be > 0.

Definition at line 41 of file gnunet-service-fs_cp.c.

Referenced by GSF_peer_update_performance_().

◆ RESPECT_FLUSH_FREQ

#define RESPECT_FLUSH_FREQ   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)

How often do we flush respect values to disk?

Definition at line 46 of file gnunet-service-fs_cp.c.

Referenced by cron_flush_respect().

◆ REPLY_TIMEOUT

After how long do we discard a reply?

Definition at line 51 of file gnunet-service-fs_cp.c.

◆ INSANE_STATISTICS

#define INSANE_STATISTICS   GNUNET_NO

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

Definition at line 56 of file gnunet-service-fs_cp.c.

◆ N

#define N   ((double)128.0)

Referenced by bound_priority(), and try_old_ax_keys().

Function Documentation

◆ GSF_update_peer_latency_()

void GSF_update_peer_latency_ ( const struct GNUNET_PeerIdentity id,
struct GNUNET_TIME_Relative  latency 
)

Update the latency information kept for the given peer.

Parameters
idpeer record to update
latencycurrent latency value

Definition at line 308 of file gnunet-service-fs_cp.c.

References GSF_PeerTransmitHandle::cp, GNUNET_LOAD_value_set_decline(), GSF_peer_get_(), GSF_ConnectedPeer::ppd, and GSF_PeerPerformanceData::transmission_delay.

Referenced by update_latencies().

310 {
311  struct GSF_ConnectedPeer *cp;
312 
313  cp = GSF_peer_get_ (id);
314  if (NULL == cp)
315  return; /* we're not yet connected at the core level, ignore */
317  latency);
318 }
struct GNUNET_LOAD_Value * transmission_delay
How long does it typically take for us to transmit a message to this peer? (delay between the request...
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
struct GSF_ConnectedPeer * GSF_peer_get_(const struct GNUNET_PeerIdentity *peer)
Get a handle for a connected peer.
A connected peer.
void GNUNET_LOAD_value_set_decline(struct GNUNET_LOAD_Value *load, struct GNUNET_TIME_Relative autodecline)
Change the value by which the load automatically declines.
Definition: load.c:143
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_get_peer_performance_data_()

struct GSF_PeerPerformanceData* GSF_get_peer_performance_data_ ( struct GSF_ConnectedPeer cp)

Return the performance data record for the given peer.

Parameters
cppeer to query
Returns
performance data record for the peer

Definition at line 328 of file gnunet-service-fs_cp.c.

References ats_reserve_callback(), GSF_PeerTransmitHandle::cp, peer, peer_transmit(), and GSF_ConnectedPeer::ppd.

Referenced by handle_p2p_put(), put_migration_continuation(), score_content(), and transmit_content().

329 {
330  return &cp->ppd;
331 }
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_transmit()

static void peer_transmit ( struct GSF_ConnectedPeer cp)
static

Core is ready to transmit to a peer, get the message.

Parameters
cpwhich peer to send a message to

Definition at line 412 of file gnunet-service-fs_cp.c.

References GSF_PeerTransmitHandle::env, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_LOAD_update(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, GSF_PeerTransmitHandle::is_query, GSF_PeerPerformanceData::last_request_times, GSF_ConnectedPeer::last_request_times_off, MAX_QUEUE_PER_PEER, GSF_ConnectedPeer::mq, GSF_PeerPerformanceData::pending_queries, GSF_PeerPerformanceData::pending_replies, GSF_ConnectedPeer::ppd, GSF_ConnectedPeer::pth_head, GSF_ConnectedPeer::pth_tail, GNUNET_TIME_Relative::rel_value_us, schedule_transmission(), GSF_PeerPerformanceData::transmission_delay, and GSF_PeerTransmitHandle::transmission_request_start_time.

Referenced by ats_reserve_callback(), GSF_get_peer_performance_data_(), and schedule_transmission().

413 {
414  struct GSF_PeerTransmitHandle *pth = cp->pth_head;
415  struct GSF_PeerTransmitHandle *pos;
416 
417  if (NULL == pth)
418  return;
420  cp->pth_tail,
421  pth);
422  if (GNUNET_YES == pth->is_query)
423  {
427  GNUNET_assert (0 < cp->ppd.pending_queries--);
428  }
429  else if (GNUNET_NO == pth->is_query)
430  {
431  GNUNET_assert (0 < cp->ppd.pending_replies--);
432  }
436  GNUNET_MQ_send (cp->mq,
437  pth->env);
438  GNUNET_free (pth);
439  if (NULL != (pos = cp->pth_head))
440  {
441  GNUNET_assert (pos != pth);
442  schedule_transmission (pos);
443  }
444 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
unsigned int pending_queries
Number of pending queries (replies are not counted)
int is_query
GNUNET_YES if this is a query, GNUNET_NO for content.
uint64_t rel_value_us
The actual value.
struct GNUNET_LOAD_Value * transmission_delay
How long does it typically take for us to transmit a message to this peer? (delay between the request...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GSF_PeerTransmitHandle * pth_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
void GNUNET_LOAD_update(struct GNUNET_LOAD_Value *load, uint64_t data)
Update the current load.
Definition: load.c:238
unsigned int pending_replies
Number of pending replies (queries are not counted)
static void schedule_transmission(struct GSF_PeerTransmitHandle *pth)
If ready (bandwidth reserved), try to schedule transmission via core for the given handle...
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_MQ_Envelope * env
Envelope with the actual message.
unsigned int last_request_times_off
Current offset into last_request_times ring buffer.
struct GNUNET_TIME_Absolute last_request_times[24]
Transmission times for the last MAX_QUEUE_PER_PEER requests for this peer.
struct GSF_PeerTransmitHandle * pth_tail
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
struct GNUNET_MQ_Handle * mq
Handle for an active request for transmission to this peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
struct GNUNET_TIME_Absolute transmission_request_start_time
Time when this transmission request was issued.
#define MAX_QUEUE_PER_PEER
Maximum number of outgoing messages we queue per peer.
#define GNUNET_free(ptr)
Wrapper around free.
Handle to cancel a transmission request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ats_reserve_callback()

static void ats_reserve_callback ( void *  cls,
const struct GNUNET_PeerIdentity peer,
int32_t  amount,
struct GNUNET_TIME_Relative  res_delay 
)
static

Function called by core upon success or failure of our bandwidth reservation request.

Parameters
clsthe struct GSF_ConnectedPeer of the peer for which we made the request
peeridentifies the peer
amountset to the amount that was actually reserved or unreserved; either the full requested amount or zero (no partial reservations)
res_delayif the reservation could not be satisfied (amount was 0), how long should the client wait until re-trying?

Definition at line 479 of file gnunet-service-fs_cp.c.

References GSF_ConnectedPeer::did_reserve, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, peer_transmit(), GSF_ConnectedPeer::pth_head, GSF_ConnectedPeer::rc, GSF_ConnectedPeer::rc_delay_task, and retry_reservation().

Referenced by GSF_get_peer_performance_data_(), GSF_peer_connect_handler(), retry_reservation(), and schedule_transmission().

483 {
484  struct GSF_ConnectedPeer *cp = cls;
485  struct GSF_PeerTransmitHandle *pth;
486 
488  "Reserved %d bytes / need to wait %s for reservation\n",
489  (int) amount,
491  cp->rc = NULL;
492  if (0 == amount)
493  {
494  cp->rc_delay_task =
495  GNUNET_SCHEDULER_add_delayed (res_delay,
497  cp);
498  return;
499  }
500  cp->did_reserve = GNUNET_YES;
501  pth = cp->pth_head;
502  if (NULL != pth)
503  {
504  /* reservation success, try transmission now! */
505  peer_transmit (cp);
506  }
507 }
struct GSF_PeerTransmitHandle * pth_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
struct GNUNET_SCHEDULER_Task * rc_delay_task
Task scheduled if we need to retry bandwidth reservation later.
int did_reserve
GNUNET_YES if we did successfully reserve 32k bandwidth, GNUNET_NO if not.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GNUNET_ATS_ReservationContext * rc
Context of our GNUNET_ATS_reserve_bandwidth call (or NULL).
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
static void peer_transmit(struct GSF_ConnectedPeer *cp)
Core is ready to transmit to a peer, get the message.
static void retry_reservation(void *cls)
(re)try to reserve bandwidth from the given peer.
#define GNUNET_log(kind,...)
A connected peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
Handle to cancel a transmission request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_transmission()

static void schedule_transmission ( struct GSF_PeerTransmitHandle pth)
static

If ready (bandwidth reserved), try to schedule transmission via core for the given handle.

Parameters
pthtransmission handle to schedule

Definition at line 367 of file gnunet-service-fs_cp.c.

References ats_reserve_callback(), GSF_PeerTransmitHandle::cp, DBLOCK_SIZE, GNUNET_assert, GNUNET_ATS_performance_change_preference(), GNUNET_ATS_PREFERENCE_BANDWIDTH, GNUNET_ATS_PREFERENCE_END, GNUNET_ATS_reserve_bandwidth(), GNUNET_NO, GNUNET_PEER_resolve(), GNUNET_YES, GSF_ats, GSF_PeerTransmitHandle::is_query, peer_transmit(), and GSF_PeerTransmitHandle::was_reserved.

Referenced by GSF_peer_transmit_(), and peer_transmit().

368 {
369  struct GSF_ConnectedPeer *cp;
370  struct GNUNET_PeerIdentity target;
371 
372  cp = pth->cp;
373  GNUNET_assert (0 != cp->ppd.pid);
374  GNUNET_PEER_resolve (cp->ppd.pid, &target);
375 
376  if (0 != cp->inc_preference)
377  {
379  &target,
381  (double) cp->inc_preference,
383  cp->inc_preference = 0;
384  }
385 
386  if ( (GNUNET_YES == pth->is_query) &&
387  (GNUNET_YES != pth->was_reserved) )
388  {
389  /* query, need reservation */
390  if (GNUNET_YES != cp->did_reserve)
391  return; /* not ready */
392  cp->did_reserve = GNUNET_NO;
393  /* reservation already done! */
394  pth->was_reserved = GNUNET_YES;
396  &target,
397  DBLOCK_SIZE,
399  cp);
400  return;
401  }
402  peer_transmit (cp);
403 }
int is_query
GNUNET_YES if this is a query, GNUNET_NO for content.
static void ats_reserve_callback(void *cls, const struct GNUNET_PeerIdentity *peer, int32_t amount, struct GNUNET_TIME_Relative res_delay)
Function called by core upon success or failure of our bandwidth reservation request.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_ATS_PerformanceHandle * GSF_ats
Handle to ATS service.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GSF_ConnectedPeer * cp
Peer this request targets.
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
End of preference list.
struct GNUNET_ATS_ReservationContext * GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int32_t amount, GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
Reserve inbound bandwidth from the given peer.
static void peer_transmit(struct GSF_ConnectedPeer *cp)
Core is ready to transmit to a peer, get the message.
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
int was_reserved
Did we get a reservation already?
The identity of the host (wraps the signing key of the peer).
void GNUNET_ATS_performance_change_preference(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer,...)
Change preferences for the given peer.
Change the peer&#39;s bandwidth value (value per byte of bandwidth in the goal function) to the given amo...
A connected 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:

◆ retry_reservation()

static void retry_reservation ( void *  cls)
static

(re)try to reserve bandwidth from the given peer.

Parameters
clsthe struct GSF_ConnectedPeer to reserve from

Definition at line 453 of file gnunet-service-fs_cp.c.

References ats_reserve_callback(), DBLOCK_SIZE, GNUNET_ATS_reserve_bandwidth(), GNUNET_PEER_resolve(), GSF_ats, GSF_PeerPerformanceData::pid, GSF_ConnectedPeer::ppd, GSF_ConnectedPeer::rc, and GSF_ConnectedPeer::rc_delay_task.

Referenced by ats_reserve_callback().

454 {
455  struct GSF_ConnectedPeer *cp = cls;
456  struct GNUNET_PeerIdentity target;
457 
458  GNUNET_PEER_resolve (cp->ppd.pid, &target);
459  cp->rc_delay_task = NULL;
460  cp->rc =
462  &target,
463  DBLOCK_SIZE,
464  &ats_reserve_callback, cp);
465 }
static void ats_reserve_callback(void *cls, const struct GNUNET_PeerIdentity *peer, int32_t amount, struct GNUNET_TIME_Relative res_delay)
Function called by core upon success or failure of our bandwidth reservation request.
struct GNUNET_ATS_PerformanceHandle * GSF_ats
Handle to ATS service.
struct GNUNET_SCHEDULER_Task * rc_delay_task
Task scheduled if we need to retry bandwidth reservation later.
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_ATS_ReservationContext * GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int32_t amount, GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
Reserve inbound bandwidth from the given peer.
struct GNUNET_ATS_ReservationContext * rc
Context of our GNUNET_ATS_reserve_bandwidth call (or NULL).
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
#define DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
The identity of the host (wraps the signing key of the peer).
A connected peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_respect_cb()

static void peer_respect_cb ( void *  cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  emsg 
)
static

Function called by PEERSTORE with peer respect record.

Parameters
clshandle to connected peer entry
recordpeerstore record information
emsgerror message, or NULL if no errors

Definition at line 518 of file gnunet-service-fs_cp.c.

References GSF_ConnectedPeer::disk_respect, GNUNET_assert, GNUNET_PEERSTORE_iterate_cancel(), GSF_push_start_(), GSF_ConnectedPeer::ppd, GSF_PeerPerformanceData::respect, GSF_ConnectedPeer::respect_iterate_req, GNUNET_PEERSTORE_Record::value, and GNUNET_PEERSTORE_Record::value_size.

Referenced by GSF_peer_connect_handler().

521 {
522  struct GSF_ConnectedPeer *cp = cls;
523 
524  GNUNET_assert (NULL != cp->respect_iterate_req);
525  if ( (NULL != record) &&
526  (sizeof (cp->disk_respect) == record->value_size))
527  {
528  cp->disk_respect = *((uint32_t *)record->value);
529  cp->ppd.respect += *((uint32_t *)record->value);
530  }
531  GSF_push_start_ (cp);
532  if (NULL != record)
534  cp->respect_iterate_req = NULL;
535 }
size_t value_size
Size of value BLOB.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t disk_respect
Respect rating for this peer on disk.
void * value
Record value BLOB.
uint32_t respect
Respect rating for this peer.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
void GSF_push_start_(struct GSF_ConnectedPeer *peer)
A peer connected to us.
struct GNUNET_PEERSTORE_IterateContext * respect_iterate_req
Handle to the PEERSTORE iterate request for peer respect value.
A connected peer.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ consider_peer_for_forwarding()

static int consider_peer_for_forwarding ( void *  cls,
const struct GNUNET_HashCode key,
struct GSF_PendingRequest pr 
)
static

Function called for each pending request whenever a new peer connects, giving us a chance to decide about submitting the existing request to the new peer.

Parameters
clsthe struct GSF_ConnectedPeer of the new peer
keyquery for the request
prhandle to the pending request
Returns
GNUNET_YES to continue to iterate

Definition at line 549 of file gnunet-service-fs_cp.c.

References gettext_noop, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, GSF_connected_peer_get_identity_(), GSF_pending_request_test_active_(), GSF_pending_request_test_target_(), GSF_plan_add_(), and GSF_stats.

Referenced by GSF_peer_connect_handler().

552 {
553  struct GSF_ConnectedPeer *cp = cls;
554  struct GNUNET_PeerIdentity pid;
555 
556  if (GNUNET_YES !=
558  return GNUNET_YES; /* request is not actually active, skip! */
560  if (GNUNET_YES !=
562  {
564  gettext_noop ("# Loopback routes suppressed"),
565  1,
566  GNUNET_NO);
567  return GNUNET_YES;
568  }
569  GSF_plan_add_ (cp, pr);
570  return GNUNET_YES;
571 }
void GSF_plan_add_(struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
Create a new query plan entry.
void GSF_connected_peer_get_identity_(const struct GSF_ConnectedPeer *cp, struct GNUNET_PeerIdentity *id)
Obtain the identity of a connected peer.
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.
int GSF_pending_request_test_active_(struct GSF_PendingRequest *pr)
Check if the given request is still active.
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?
The identity of the host (wraps the signing key of the peer).
A connected peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#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_peer_connect_handler()

void* GSF_peer_connect_handler ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq 
)

A peer connected to us.

Setup the connected peer records.

Parameters
clsNULL
peeridentity of peer that connected
mqmessage queue for talking to peer
Returns
our internal handle for the peer

Definition at line 584 of file gnunet-service-fs_cp.c.

References ats_reserve_callback(), consider_peer_for_forwarding(), GSF_PeerTransmitHandle::cp, DBLOCK_SIZE, gettext_noop, GNUNET_ATS_reserve_bandwidth(), GNUNET_break, GNUNET_CONTAINER_multihashmap_create(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_LOAD_value_init(), GNUNET_log, GNUNET_memcmp, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PEER_intern(), GNUNET_PEERSTORE_iterate(), GNUNET_STATISTICS_set(), GNUNET_TIME_UNIT_ZERO, GNUNET_YES, GSF_ats, GSF_connected_peer_get_identity2_(), GSF_iterate_pending_requests_(), GSF_my_id, GSF_stats, mq, GSF_ConnectedPeer::mq, peer, GSF_PeerPerformanceData::peer, peer_respect_cb(), GSF_PeerPerformanceData::pid, GSF_ConnectedPeer::ppd, GSF_ConnectedPeer::rc, GSF_ConnectedPeer::request_map, GSF_ConnectedPeer::respect_iterate_req, and GSF_PeerPerformanceData::transmission_delay.

Referenced by main_init().

587 {
588  struct GSF_ConnectedPeer *cp;
589 
590  if (0 ==
592  peer))
593  return NULL;
595  "Connected to peer %s\n",
596  GNUNET_i2s (peer));
597  cp = GNUNET_new (struct GSF_ConnectedPeer);
598  cp->ppd.pid = GNUNET_PEER_intern (peer);
599  cp->ppd.peer = peer;
600  cp->mq = mq;
602  cp->rc =
604  peer,
605  DBLOCK_SIZE,
606  &ats_reserve_callback, cp);
608  GNUNET_YES);
612  cp,
615  gettext_noop ("# peers connected"),
617  GNUNET_NO);
620  "fs",
621  peer,
622  "respect",
624  cp);
626  cp);
627  return cp;
628 }
struct GNUNET_CONTAINER_MultiHashMap * request_map
Active requests from this neighbour, map of query to struct PeerRequest.
static void ats_reserve_callback(void *cls, const struct GNUNET_PeerIdentity *peer, int32_t amount, struct GNUNET_TIME_Relative res_delay)
Function called by core upon success or failure of our bandwidth reservation request.
struct GNUNET_LOAD_Value * GNUNET_LOAD_value_init(struct GNUNET_TIME_Relative autodecline)
Create a new load value.
Definition: load.c:125
struct GNUNET_PEERSTORE_IterateContext * GNUNET_PEERSTORE_iterate(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Iterate over records matching supplied key information.
struct GNUNET_LOAD_Value * transmission_delay
How long does it typically take for us to transmit a message to this peer? (delay between the request...
const struct GNUNET_PeerIdentity * peer
The peer&#39;s identity (pointer).
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
struct GNUNET_ATS_PerformanceHandle * GSF_ats
Handle to ATS service.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:81
#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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_ATS_ReservationContext * GNUNET_ATS_reserve_bandwidth(struct GNUNET_ATS_PerformanceHandle *ph, const struct GNUNET_PeerIdentity *peer, int32_t amount, GNUNET_ATS_ReservationCallback rcb, void *rcb_cls)
Reserve inbound bandwidth from the given peer.
struct GNUNET_ATS_ReservationContext * rc
Context of our GNUNET_ATS_reserve_bandwidth call (or NULL).
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
struct GNUNET_PeerIdentity GSF_my_id
Identity of this peer.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to peerstore service.
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 DBLOCK_SIZE
Size of the individual blocks used for file-sharing.
Definition: fs.h:40
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
void GSF_iterate_pending_requests_(GSF_PendingRequestIterator it, void *cls)
Iterate over all pending requests.
static void peer_respect_cb(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *emsg)
Function called by PEERSTORE with peer respect record.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
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.
static int consider_peer_for_forwarding(void *cls, const struct GNUNET_HashCode *key, struct GSF_PendingRequest *pr)
Function called for each pending request whenever a new peer connects, giving us a chance to decide a...
const struct GNUNET_PeerIdentity * GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp)
Obtain the identity of a connected peer.
struct GNUNET_MQ_Handle * mq
Handle for an active request for transmission to this peer.
struct GNUNET_PEERSTORE_IterateContext * respect_iterate_req
Handle to the PEERSTORE iterate request for peer respect value.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
A connected peer.
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
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition: peer.c:107
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ revive_migration()

static void revive_migration ( void *  cls)
static

It may be time to re-start migrating content to this peer.

Check, and if so, restart migration.

Parameters
clsthe struct GSF_ConnectedPeer

Definition at line 638 of file gnunet-service-fs_cp.c.

References GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_absolute_get_remaining(), GSF_push_start_(), GSF_ConnectedPeer::mig_revive_task, GSF_PeerPerformanceData::migration_blocked_until, GSF_ConnectedPeer::ppd, and GNUNET_TIME_Relative::rel_value_us.

Referenced by handle_p2p_migration_stop().

639 {
640  struct GSF_ConnectedPeer *cp = cls;
641  struct GNUNET_TIME_Relative bt;
642 
643  cp->mig_revive_task = NULL;
645  if (0 != bt.rel_value_us)
646  {
647  /* still time left... */
648  cp->mig_revive_task =
650  return;
651  }
652  GSF_push_start_ (cp);
653 }
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
static void revive_migration(void *cls)
It may be time to re-start migrating content to this peer.
void GSF_push_start_(struct GSF_ConnectedPeer *peer)
A peer connected to us.
struct GNUNET_SCHEDULER_Task * mig_revive_task
Task scheduled to revive migration to this peer.
struct GNUNET_TIME_Absolute migration_blocked_until
Point in time until which this peer does not want us to migrate content to it.
A connected peer.
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:331
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_peer_get_()

struct GSF_ConnectedPeer* GSF_peer_get_ ( const struct GNUNET_PeerIdentity peer)

Get a handle for a connected peer.

Parameters
peerpeer's identity
Returns
NULL if the peer is not currently connected

Definition at line 663 of file gnunet-service-fs_cp.c.

References GNUNET_CONTAINER_multipeermap_get().

Referenced by GSF_update_peer_latency_(), handle_p2p_get(), and put_migration_continuation().

664 {
665  if (NULL == cp_map)
666  return NULL;
668 }
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_p2p_migration_stop()

void handle_p2p_migration_stop ( void *  cls,
const struct MigrationStopMessage msm 
)

Handle P2P GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP message.

Parameters
clsclosure, the struct GSF_ConnectedPeer
msmthe actual message

Definition at line 678 of file gnunet-service-fs_cp.c.

References _, MigrationStopMessage::duration, gettext_noop, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_relative_ntoh(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, GSF_push_stop_(), GSF_stats, GSF_ConnectedPeer::mig_revive_task, GSF_PeerPerformanceData::migration_blocked_until, GSF_PeerPerformanceData::peer, GSF_ConnectedPeer::ppd, GSF_ConnectedPeer::respect_iterate_req, and revive_migration().

680 {
681  struct GSF_ConnectedPeer *cp = cls;
682  struct GNUNET_TIME_Relative bt;
683 
685  gettext_noop ("# migration stop messages received"),
686  1, GNUNET_NO);
689  _("Migration of content to peer `%s' blocked for %s\n"),
690  GNUNET_i2s (cp->ppd.peer),
693  if ( (NULL == cp->mig_revive_task) &&
694  (NULL == cp->respect_iterate_req) )
695  {
696  GSF_push_stop_ (cp);
697  cp->mig_revive_task =
699  &revive_migration, cp);
700  }
701 }
void GSF_push_stop_(struct GSF_ConnectedPeer *peer)
A peer disconnected from us.
const struct GNUNET_PeerIdentity * peer
The peer&#39;s identity (pointer).
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
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
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
static void revive_migration(void *cls)
It may be time to re-start migrating content to this peer.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:638
struct GNUNET_TIME_RelativeNBO duration
How long should the block last?
struct GNUNET_SCHEDULER_Task * mig_revive_task
Task scheduled to revive migration to this peer.
struct GNUNET_TIME_Absolute migration_blocked_until
Point in time until which this peer does not want us to migrate content to it.
struct GNUNET_PEERSTORE_IterateContext * respect_iterate_req
Handle to the PEERSTORE iterate request for peer respect value.
#define GNUNET_log(kind,...)
A connected peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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:

◆ free_pending_request()

static void free_pending_request ( struct PeerRequest peerreq)
static

Free resources associated with the given peer request.

Parameters
peerreqrequest to free

Definition at line 710 of file gnunet-service-fs_cp.c.

References PeerRequest::cp, gettext_noop, GNUNET_break, GNUNET_CONTAINER_multihashmap_remove(), GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, GSF_pending_request_get_data_(), GSF_stats, PeerRequest::kill_task, PeerRequest::pr, GSF_PendingRequestData::query, and GSF_ConnectedPeer::request_map.

Referenced by cancel_pending_request(), handle_p2p_reply(), and test_exist_cb().

711 {
712  struct GSF_ConnectedPeer *cp = peerreq->cp;
713  struct GSF_PendingRequestData *prd;
714 
715  prd = GSF_pending_request_get_data_ (peerreq->pr);
716  if (NULL != peerreq->kill_task)
717  {
719  peerreq->kill_task = NULL;
720  }
722  gettext_noop ("# P2P searches active"),
723  -1,
724  GNUNET_NO);
727  &prd->query,
728  peerreq));
729  GNUNET_free (peerreq);
730 }
struct GNUNET_CONTAINER_MultiHashMap * request_map
Active requests from this neighbour, map of query to struct PeerRequest.
struct GSF_PendingRequest * pr
Handle to generic request (generic: from peer or local client).
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.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HashCode query
Primary query hash for this request.
Public data (in the sense of not encapsulated within &#39;gnunet-service-fs_pr&#39;, not in the sense of netw...
int 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.
struct GSF_ConnectedPeer * cp
Which specific peer issued this request?
struct GNUNET_SCHEDULER_Task * kill_task
Task for asynchronous stopping of this request.
struct GSF_PendingRequestData * GSF_pending_request_get_data_(struct GSF_PendingRequest *pr)
Obtain the public data associated with a pending request.
A connected peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
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:

◆ cancel_pending_request()

static int cancel_pending_request ( void *  cls,
const struct GNUNET_HashCode query,
void *  value 
)
static

Cancel all requests associated with the peer.

Parameters
clsunused
queryhash code of the request
valuethe struct GSF_PendingRequest
Returns
GNUNET_YES (continue to iterate)

Definition at line 742 of file gnunet-service-fs_cp.c.

References free_pending_request(), GNUNET_NO, GNUNET_OK, GSF_pending_request_cancel_(), PeerRequest::pr, and value.

Referenced by GSF_peer_disconnect_handler(), and peer_request_destroy().

745 {
746  struct PeerRequest *peerreq = value;
747  struct GSF_PendingRequest *pr = peerreq->pr;
748 
749  free_pending_request (peerreq);
751  GNUNET_NO);
752  return GNUNET_OK;
753 }
Information per peer and request.
struct GSF_PendingRequest * pr
Handle to generic request (generic: from peer or local client).
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void free_pending_request(struct PeerRequest *peerreq)
Free resources associated with the given peer request.
static char * value
Value of the record to add/remove.
An active request.
void GSF_pending_request_cancel_(struct GSF_PendingRequest *pr, int full_cleanup)
Explicitly cancel a pending request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_request_destroy()

static void peer_request_destroy ( void *  cls)
static

Free the given request.

Parameters
clsthe request to free

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

References cancel_pending_request(), GSF_pending_request_get_data_(), PeerRequest::kill_task, PeerRequest::pr, and GSF_PendingRequestData::query.

Referenced by handle_p2p_reply().

763 {
764  struct PeerRequest *peerreq = cls;
765  struct GSF_PendingRequest *pr = peerreq->pr;
766  struct GSF_PendingRequestData *prd;
767 
768  peerreq->kill_task = NULL;
771  &prd->query,
772  peerreq);
773 }
Information per peer and request.
static int cancel_pending_request(void *cls, const struct GNUNET_HashCode *query, void *value)
Cancel all requests associated with the peer.
struct GSF_PendingRequest * pr
Handle to generic request (generic: from peer or local client).
struct GNUNET_HashCode query
Primary query hash for this request.
Public data (in the sense of not encapsulated within &#39;gnunet-service-fs_pr&#39;, not in the sense of netw...
struct GNUNET_SCHEDULER_Task * kill_task
Task for asynchronous stopping of this request.
struct GSF_PendingRequestData * GSF_pending_request_get_data_(struct GSF_PendingRequest *pr)
Obtain the public data associated with a pending request.
An active request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_delayed_now()

static void transmit_delayed_now ( void *  cls)
static

The artificial delay is over, transmit the message now.

Parameters
clsthe struct GSF_DelayedHandle with the message

Definition at line 782 of file gnunet-service-fs_cp.c.

References GSF_DelayedHandle::cp, GSF_ConnectedPeer::delay_queue_size, GSF_ConnectedPeer::delayed_head, GSF_ConnectedPeer::delayed_tail, GSF_DelayedHandle::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, and GSF_peer_transmit_().

Referenced by handle_p2p_reply().

783 {
784  struct GSF_DelayedHandle *dh = cls;
785  struct GSF_ConnectedPeer *cp = dh->cp;
786 
788  cp->delayed_tail,
789  dh);
790  cp->delay_queue_size--;
791  GSF_peer_transmit_ (cp,
792  GNUNET_NO,
793  UINT32_MAX,
794  dh->env);
795  GNUNET_free (dh);
796 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Handle for an entry in our delay list.
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.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GSF_DelayedHandle * delayed_tail
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
struct GSF_DelayedHandle * delayed_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
unsigned int delay_queue_size
Number of entries in delayed_head DLL.
struct GSF_ConnectedPeer * cp
Peer this transmission belongs to.
A connected peer.
struct GNUNET_MQ_Envelope * env
Envelope of the message that was delayed.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_randomized_delay()

static struct GNUNET_TIME_Relative get_randomized_delay ( )
static

Get the randomized delay a response should be subjected to.

Returns
desired delay

Definition at line 805 of file gnunet-service-fs_cp.c.

References gettext_noop, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MILLISECONDS, GSF_avg_latency, GSF_stats, GNUNET_TIME_Relative::rel_value_us, and ret.

Referenced by handle_p2p_reply().

806 {
807  struct GNUNET_TIME_Relative ret;
808 
809  ret =
813  2 * GSF_avg_latency.rel_value_us + 1));
814 #if INSANE_STATISTICS
817  ("# artificial delays introduced (ms)"),
818  ret.rel_value_us / 1000LL, GNUNET_NO);
819 #endif
820  return ret;
821 }
uint64_t rel_value_us
The actual value.
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
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.
static int ret
Final status code.
Definition: gnunet-arm.c:89
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 GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Relative GSF_avg_latency
Running average of the observed latency to other peers (round trip).
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
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:
Here is the caller graph for this function:

◆ handle_p2p_reply()

static void handle_p2p_reply ( 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 
)
static

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
clsstruct PeerRequest this is an answer for
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_transmissionwhen did we last transmit a request for this block
typetype of the block
dataresponse data, NULL on request expiration
data_lennumber of bytes in data

Definition at line 843 of file gnunet-service-fs_cp.c.

References GSF_PeerTransmitHandle::cp, GSF_DelayedHandle::cp, PeerRequest::cp, GSF_ConnectedPeer::delay_queue_size, GSF_DelayedHandle::delay_task, GSF_ConnectedPeer::delayed_head, GSF_ConnectedPeer::delayed_tail, GSF_PeerTransmitHandle::env, GSF_DelayedHandle::env, PutMessage::expiration, free_pending_request(), get_randomized_delay(), gettext_noop, GNUNET_assert, GNUNET_BLOCK_EVALUATION_OK_LAST, GNUNET_BLOCK_TYPE_ANY, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_FS_PUT, GNUNET_MQ_msg_extra, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_hton(), GNUNET_YES, GSF_cover_content_count, GSF_enable_randomized_delays, GSF_peer_transmit_(), GSF_pending_request_get_data_(), GSF_stats, PeerRequest::kill_task, GSF_DelayedHandle::msize, peer_request_destroy(), pm, PeerRequest::pr, GSF_PendingRequestData::query, transmit_delayed_now(), GSF_PendingRequestData::type, and PutMessage::type.

Referenced by handle_p2p_get().

852 {
853  struct PeerRequest *peerreq = cls;
854  struct GSF_ConnectedPeer *cp = peerreq->cp;
855  struct GSF_PendingRequestData *prd;
856  struct GNUNET_MQ_Envelope *env;
857  struct PutMessage *pm;
858  size_t msize;
859 
860  GNUNET_assert (data_len + sizeof (struct PutMessage) <
862  GNUNET_assert (peerreq->pr == pr);
864  if (NULL == data)
865  {
866  free_pending_request (peerreq);
867  return;
868  }
870  if ((prd->type != type) && (GNUNET_BLOCK_TYPE_ANY != prd->type))
871  {
874  ("# replies dropped due to type mismatch"),
875  1, GNUNET_NO);
876  return;
877  }
879  "Transmitting result for query `%s' to peer\n",
880  GNUNET_h2s (&prd->query));
882  gettext_noop ("# replies received for other peers"),
883  1, GNUNET_NO);
884  msize = sizeof (struct PutMessage) + data_len;
885  if (msize >= GNUNET_MAX_MESSAGE_SIZE)
886  {
887  GNUNET_break (0);
888  return;
889  }
890  if ((UINT32_MAX != reply_anonymity_level) && (reply_anonymity_level > 1))
891  {
892  if (reply_anonymity_level - 1 > GSF_cover_content_count)
893  {
896  ("# replies dropped due to insufficient cover traffic"),
897  1, GNUNET_NO);
898  return;
899  }
900  GSF_cover_content_count -= (reply_anonymity_level - 1);
901  }
902 
903  env = GNUNET_MQ_msg_extra (pm,
904  data_len,
906  pm->type = htonl (type);
907  pm->expiration = GNUNET_TIME_absolute_hton (expiration);
908  GNUNET_memcpy (&pm[1],
909  data,
910  data_len);
911  if ( (UINT32_MAX != reply_anonymity_level) &&
912  (0 != reply_anonymity_level) &&
914  {
915  struct GSF_DelayedHandle *dh;
916 
917  dh = GNUNET_new (struct GSF_DelayedHandle);
918  dh->cp = cp;
919  dh->env = env;
920  dh->msize = msize;
922  cp->delayed_tail,
923  dh);
924  cp->delay_queue_size++;
925  dh->delay_task =
928  dh);
929  }
930  else
931  {
932  GSF_peer_transmit_ (cp,
933  GNUNET_NO,
934  UINT32_MAX,
935  env);
936  }
938  return;
939  if (NULL == peerreq->kill_task)
940  {
943  ("# P2P searches destroyed due to ultimate reply"),
944  1,
945  GNUNET_NO);
946  peerreq->kill_task =
948  peerreq);
949  }
950 }
int GSF_enable_randomized_delays
Are we introducing randomized delays for better anonymity?
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
Any type of block, used as a wildcard when searching.
Response from FS service with a result for a previous FS search.
Definition: fs.h:336
Information per peer and request.
struct GNUNET_TIME_AbsoluteNBO expiration
When does this result expire?
Definition: fs.h:352
size_t msize
Size of the message.
Handle for an entry in our delay list.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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.
struct GSF_PendingRequest * pr
Handle to generic request (generic: from peer or local client).
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_new(type)
Allocate a struct or union of the given type.
struct GSF_DelayedHandle * delayed_tail
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_HashCode query
Primary query hash for this request.
static void free_pending_request(struct PeerRequest *peerreq)
Free resources associated with the given peer request.
static struct GNUNET_TIME_Relative get_randomized_delay()
Get the randomized delay a response should be subjected to.
Public data (in the sense of not encapsulated within &#39;gnunet-service-fs_pr&#39;, not in the sense of netw...
#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
static void peer_request_destroy(void *cls)
Free the given request.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GSF_DelayedHandle * delayed_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
#define GNUNET_memcpy(dst, src, n)
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:1273
Last possible valid result.
enum GNUNET_BLOCK_Type type
Type of the requested block.
struct GNUNET_SCHEDULER_Task * delay_task
Task for the delay.
struct GSF_ConnectedPeer * cp
Which specific peer issued this request?
unsigned int delay_queue_size
Number of entries in delayed_head DLL.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_SCHEDULER_Task * kill_task
Task for asynchronous stopping of this request.
uint32_t type
Type of the block (in big endian).
Definition: fs.h:347
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GSF_PendingRequestData * GSF_pending_request_get_data_(struct GSF_PendingRequest *pr)
Obtain the public data associated with a pending request.
struct GSF_ConnectedPeer * cp
Peer this transmission belongs to.
#define GNUNET_log(kind,...)
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...
struct GNUNET_MQ_Envelope * env
Envelope of the message that was delayed.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t data
The data value.
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:654
#define GNUNET_MESSAGE_TYPE_FS_PUT
P2P response with content or active migration of content.
static void transmit_delayed_now(void *cls)
The artificial delay is over, transmit the message now.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ change_peer_respect()

static int change_peer_respect ( struct GSF_ConnectedPeer cp,
int  value 
)
static

Increase the peer's respect by a value.

Parameters
cpwhich peer to change the respect value on
valueis the int value by which the peer's credit is to be increased or decreased
Returns
the actual change in respect (positive or negative)

Definition at line 962 of file gnunet-service-fs_cp.c.

References GNUNET_assert, GSF_ConnectedPeer::ppd, GSF_PeerPerformanceData::respect, and value.

Referenced by bound_priority().

963 {
964  if (0 == value)
965  return 0;
966  GNUNET_assert (NULL != cp);
967  if (value > 0)
968  {
969  if (cp->ppd.respect + value < cp->ppd.respect)
970  {
971  value = UINT32_MAX - cp->ppd.respect;
972  cp->ppd.respect = UINT32_MAX;
973  }
974  else
975  cp->ppd.respect += value;
976  }
977  else
978  {
979  if (cp->ppd.respect < -value)
980  {
981  value = -cp->ppd.respect;
982  cp->ppd.respect = 0;
983  }
984  else
985  cp->ppd.respect += value;
986  }
987  return value;
988 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static char * value
Value of the record to add/remove.
uint32_t respect
Respect rating for this peer.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
Here is the caller graph for this function:

◆ bound_priority()

static int32_t bound_priority ( uint32_t  prio_in,
struct GSF_ConnectedPeer cp 
)
static

We've received a request with the specified priority.

Bound it according to how much we respect the given peer.

Parameters
prio_inrequested priority
cpthe peer making the request
Returns
effective priority

Definition at line 1000 of file gnunet-service-fs_cp.c.

References change_peer_respect(), gettext_noop, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, GSF_current_priorities, GSF_stats, GSF_test_get_load_too_high_(), N, and ret.

Referenced by handle_p2p_get().

1002 {
1003 #define N ((double)128.0)
1004  uint32_t ret;
1005  double rret;
1006  int ld;
1007 
1008  ld = GSF_test_get_load_too_high_ (0);
1009  if (GNUNET_SYSERR == ld)
1010  {
1011 #if INSANE_STATISTICS
1013  gettext_noop
1014  ("# requests done for free (low load)"), 1,
1015  GNUNET_NO);
1016 #endif
1017  return 0; /* excess resources */
1018  }
1019  if (prio_in > INT32_MAX)
1020  prio_in = INT32_MAX;
1021  ret = -change_peer_respect (cp, -(int) prio_in);
1022  if (ret > 0)
1023  {
1024  if (ret > GSF_current_priorities + N)
1025  rret = GSF_current_priorities + N;
1026  else
1027  rret = ret;
1028  GSF_current_priorities = (GSF_current_priorities * (N - 1) + rret) / N;
1029  }
1030  if ((GNUNET_YES == ld) && (ret > 0))
1031  {
1032  /* try with charging */
1033  ld = GSF_test_get_load_too_high_ (ret);
1034  }
1035  if (GNUNET_YES == ld)
1036  {
1038  gettext_noop
1039  ("# request dropped, priority insufficient"), 1,
1040  GNUNET_NO);
1041  /* undo charge */
1042  change_peer_respect (cp, (int) ret);
1043  return -1; /* not enough resources */
1044  }
1045  else
1046  {
1048  gettext_noop
1049  ("# requests done for a price (normal load)"), 1,
1050  GNUNET_NO);
1051  }
1052 #undef N
1053  return ret;
1054 }
double GSF_current_priorities
Typical priorities we&#39;re seeing from other peers right now.
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.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
int GSF_test_get_load_too_high_(uint32_t priority)
Test if the DATABASE (GET) load on this peer is too high to even consider processing the query at all...
static int change_peer_respect(struct GSF_ConnectedPeer *cp, int value)
Increase the peer&#39;s respect by a value.
#define N
#define GNUNET_YES
Definition: gnunet_common.h:80
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ bound_ttl()

static int32_t bound_ttl ( int32_t  ttl_in,
uint32_t  prio 
)
static

The priority level imposes a bound on the maximum value for the ttl that can be requested.

Parameters
ttl_inrequested ttl
priogiven priority
Returns
ttl_in if ttl_in is below the limit, otherwise the ttl-limit for the given prio

Definition at line 1067 of file gnunet-service-fs_cp.c.

References TTL_DECREMENT.

Referenced by handle_p2p_get().

1069 {
1070  unsigned long long allowed;
1071 
1072  if (ttl_in <= 0)
1073  return ttl_in;
1074  allowed = ((unsigned long long) prio) * TTL_DECREMENT / 1000;
1075  if (ttl_in > allowed)
1076  {
1077  if (allowed >= (1 << 30))
1078  return 1 << 30;
1079  return allowed;
1080  }
1081  return ttl_in;
1082 }
#define TTL_DECREMENT
By which amount do we decrement the TTL for simple forwarding / indirection of the query; in milli-se...
Here is the caller graph for this function:

◆ test_exist_cb()

static int test_exist_cb ( void *  cls,
const struct GNUNET_HashCode hc,
void *  value 
)
static

Test if the query already exists.

If so, merge it, otherwise keep finished at GNUNET_NO.

Parameters
clsour struct TestExistClosure
hcthe key of the query
valuethe existing struct PeerRequest.
Returns
GNUNET_YES to continue to iterate, GNUNET_NO if we successfully merged

Definition at line 1125 of file gnunet-service-fs_cp.c.

References GNUNET_TIME_Absolute::abs_value_us, TestExistClosure::finished, free_pending_request(), gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_YES, GSF_pending_request_cancel_(), GSF_pending_request_get_data_(), GSF_stats, PeerRequest::pr, GSF_PendingRequestData::priority, TestExistClosure::priority, GSF_PendingRequestData::ttl, TestExistClosure::ttl, GSF_PendingRequestData::type, TestExistClosure::type, and value.

Referenced by handle_p2p_get().

1128 {
1129  struct TestExistClosure *tec = cls;
1130  struct PeerRequest *peerreq = value;
1131  struct GSF_PendingRequest *pr;
1132  struct GSF_PendingRequestData *prd;
1133 
1134  pr = peerreq->pr;
1135  prd = GSF_pending_request_get_data_ (pr);
1136  if (prd->type != tec->type)
1137  return GNUNET_YES;
1138  if (prd->ttl.abs_value_us >=
1139  GNUNET_TIME_absolute_get ().abs_value_us + tec->ttl * 1000LL)
1140  {
1141  /* existing request has higher TTL, drop new one! */
1142  prd->priority += tec->priority;
1144  "Have existing request with higher TTL, dropping new request.\n");
1146  gettext_noop
1147  ("# requests dropped due to higher-TTL request"),
1148  1, GNUNET_NO);
1149  tec->finished = GNUNET_YES;
1150  return GNUNET_NO;
1151  }
1152  /* existing request has lower TTL, drop old one! */
1153  tec->priority += prd->priority;
1154  free_pending_request (peerreq);
1156  GNUNET_YES);
1157  return GNUNET_NO;
1158 }
Information per peer and request.
struct GNUNET_TIME_Absolute ttl
Current TTL for the request.
struct GSF_PendingRequest * pr
Handle to generic request (generic: from peer or local client).
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.
uint64_t abs_value_us
The actual value.
static void free_pending_request(struct PeerRequest *peerreq)
Free resources associated with the given peer request.
Public data (in the sense of not encapsulated within &#39;gnunet-service-fs_pr&#39;, not in the sense of netw...
enum GNUNET_BLOCK_Type type
Type of the incoming request.
static char * value
Value of the record to add/remove.
Closure for test_exist_cb().
enum GNUNET_BLOCK_Type type
Type of the requested block.
int finished
Set to GNUNET_YES if we are done handling the query.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
int32_t ttl
Relative TTL of the incoming request.
struct GSF_PendingRequestData * GSF_pending_request_get_data_(struct GSF_PendingRequest *pr)
Obtain the public data associated with a pending request.
int32_t priority
Priority of the incoming request.
#define GNUNET_log(kind,...)
#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.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_p2p_get()

void handle_p2p_get ( void *  cls,
const struct GetMessage gm 
)

Handle P2P "QUERY" message.

Creates the pending request entry and sets up all of the data structures to that we will process replies properly. Does not initiate forwarding or local database lookups.

Parameters
clsthe other peer involved (sender of the message)
gmthe GET message

Definition at line 1171 of file gnunet-service-fs_cp.c.

References bound_priority(), bound_ttl(), GSF_PeerTransmitHandle::cp, PeerRequest::cp, GSF_ConnectedPeer::delay_queue_size, GetMessage::filter_mutator, TestExistClosure::finished, GET_MESSAGE_BIT_RETURN_TO, GET_MESSAGE_BIT_TRANSMIT_TO, gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_CONSTANTS_MAX_CORK_DELAY, GNUNET_CONTAINER_multihashmap_get_multiple(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_i2s(), GNUNET_LOAD_get_average(), GNUNET_LOAD_get_load(), GNUNET_log, GNUNET_MQ_get_length(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_PEER_intern(), GNUNET_STATISTICS_update(), GNUNET_YES, GSF_consider_forwarding(), GSF_cover_query_count, GSF_local_lookup_(), GSF_peer_get_(), GSF_pending_request_create_(), GSF_pending_request_get_data_(), GSF_PRO_DEFAULTS, GSF_PRO_FORWARD_ONLY, GSF_rt_entry_lifetime, GSF_stats, handle_p2p_reply(), GSF_PendingRequestData::has_started, GetMessage::hash_bitmap, GetMessage::header, MAX_QUEUE_PER_PEER, GSF_ConnectedPeer::mq, options, GSF_PeerPerformanceData::peer, GSF_PeerPerformanceData::pending_replies, GSF_ConnectedPeer::ppd, PeerRequest::pr, GetMessage::priority, TestExistClosure::priority, GetMessage::query, GSF_PendingRequestData::query, GSF_ConnectedPeer::request_map, GNUNET_MessageHeader::size, test_exist_cb(), GSF_PeerPerformanceData::transmission_delay, GetMessage::ttl, TestExistClosure::ttl, TTL_DECREMENT, GetMessage::type, and TestExistClosure::type.

1173 {
1174  struct GSF_ConnectedPeer *cps = cls;
1175  struct PeerRequest *peerreq;
1176  struct GSF_PendingRequest *pr;
1177  struct GSF_ConnectedPeer *cp;
1178  const struct GNUNET_PeerIdentity *target;
1180  uint16_t msize;
1181  unsigned int bits;
1182  const struct GNUNET_PeerIdentity *opt;
1183  uint32_t bm;
1184  size_t bfsize;
1185  uint32_t ttl_decrement;
1186  struct TestExistClosure tec;
1187  GNUNET_PEER_Id spid;
1188  const struct GSF_PendingRequestData *prd;
1189 
1190  msize = ntohs (gm->header.size);
1191  tec.type = ntohl (gm->type);
1192  bm = ntohl (gm->hash_bitmap);
1193  bits = 0;
1194  while (bm > 0)
1195  {
1196  if (1 == (bm & 1))
1197  bits++;
1198  bm >>= 1;
1199  }
1200  opt = (const struct GNUNET_PeerIdentity *) &gm[1];
1201  bfsize = msize - sizeof (struct GetMessage) - bits * sizeof (struct GNUNET_PeerIdentity);
1203  gettext_noop
1204  ("# GET requests received (from other peers)"),
1205  1,
1206  GNUNET_NO);
1208  bm = ntohl (gm->hash_bitmap);
1209  bits = 0;
1210  if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1211  cp = GSF_peer_get_ (&opt[bits++]);
1212  else
1213  cp = cps;
1214  if (NULL == cp)
1215  {
1216  if (0 != (bm & GET_MESSAGE_BIT_RETURN_TO))
1218  "Failed to find RETURN-TO peer `%s' in connection set. Dropping query.\n",
1219  GNUNET_i2s (&opt[bits - 1]));
1220 
1221  else
1223  "Failed to find peer `%s' in connection set. Dropping query.\n",
1224  GNUNET_i2s (cps->ppd.peer));
1226  gettext_noop
1227  ("# requests dropped due to missing reverse route"),
1228  1,
1229  GNUNET_NO);
1230  return;
1231  }
1232  unsigned int queue_size = GNUNET_MQ_get_length (cp->mq);
1233  queue_size += cp->ppd.pending_replies + cp->delay_queue_size;
1234  if (queue_size > MAX_QUEUE_PER_PEER)
1235  {
1237  "Peer `%s' has too many replies queued already. Dropping query.\n",
1238  GNUNET_i2s (cps->ppd.peer));
1240  gettext_noop ("# requests dropped due to full reply queue"),
1241  1,
1242  GNUNET_NO);
1243  return;
1244  }
1245  /* note that we can really only check load here since otherwise
1246  * peers could find out that we are overloaded by not being
1247  * disconnected after sending us a malformed query... */
1248  tec.priority = bound_priority (ntohl (gm->priority),
1249  cps);
1250  if (tec.priority < 0)
1251  {
1253  "Dropping query from `%s', this peer is too busy.\n",
1254  GNUNET_i2s (cps->ppd.peer));
1255  return;
1256  }
1258  "Received request for `%s' of type %u from peer `%s' with flags %u\n",
1259  GNUNET_h2s (&gm->query),
1260  (unsigned int) tec.type,
1261  GNUNET_i2s (cps->ppd.peer),
1262  (unsigned int) bm);
1263  target =
1264  (0 !=
1265  (bm & GET_MESSAGE_BIT_TRANSMIT_TO)) ? (&opt[bits++]) : NULL;
1266  options = GSF_PRO_DEFAULTS;
1267  spid = 0;
1268  if ((GNUNET_LOAD_get_load (cp->ppd.transmission_delay) > 3 * (1 + tec.priority))
1270  GNUNET_CONSTANTS_MAX_CORK_DELAY.rel_value_us * 2 +
1272  {
1273  /* don't have BW to send to peer, or would likely take longer than we have for it,
1274  * so at best indirect the query */
1275  tec.priority = 0;
1276  options |= GSF_PRO_FORWARD_ONLY;
1277  spid = GNUNET_PEER_intern (cps->ppd.peer);
1278  GNUNET_assert (0 != spid);
1279  }
1280  tec.ttl = bound_ttl (ntohl (gm->ttl),
1281  tec.priority);
1282  /* decrement ttl (always) */
1283  ttl_decrement =
1285  TTL_DECREMENT);
1286  if ( (tec.ttl < 0) &&
1287  (((int32_t) (tec.ttl - ttl_decrement)) > 0) )
1288  {
1290  "Dropping query from `%s' due to TTL underflow (%d - %u).\n",
1291  GNUNET_i2s (cps->ppd.peer),
1292  tec.ttl,
1293  ttl_decrement);
1295  gettext_noop
1296  ("# requests dropped due TTL underflow"), 1,
1297  GNUNET_NO);
1298  /* integer underflow => drop (should be very rare)! */
1299  return;
1300  }
1301  tec.ttl -= ttl_decrement;
1302 
1303  /* test if the request already exists */
1304  tec.finished = GNUNET_NO;
1306  &gm->query,
1307  &test_exist_cb,
1308  &tec);
1309  if (GNUNET_YES == tec.finished)
1310  return; /* merged into existing request, we're done */
1311 
1312  peerreq = GNUNET_new (struct PeerRequest);
1313  peerreq->cp = cp;
1314  pr = GSF_pending_request_create_ (options,
1315  tec.type,
1316  &gm->query,
1317  target,
1318  (bfsize > 0)
1319  ? (const char *) &opt[bits]
1320  : NULL,
1321  bfsize,
1322  ntohl (gm->filter_mutator),
1323  1 /* anonymity */,
1324  (uint32_t) tec.priority,
1325  tec.ttl,
1326  spid,
1327  GNUNET_PEER_intern (cps->ppd.peer),
1328  NULL, 0, /* replies_seen */
1330  peerreq);
1331  GNUNET_assert (NULL != pr);
1332  prd = GSF_pending_request_get_data_ (pr);
1333  peerreq->pr = pr;
1336  &prd->query,
1337  peerreq,
1340  gettext_noop ("# P2P query messages received and processed"),
1341  1,
1342  GNUNET_NO);
1344  gettext_noop ("# P2P searches active"),
1345  1,
1346  GNUNET_NO);
1348  GSF_local_lookup_ (pr,
1350  NULL);
1351 }
struct GNUNET_CONTAINER_MultiHashMap * request_map
Active requests from this neighbour, map of query to struct PeerRequest.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_DATASTORE_GET.
Definition: datastore.h:148
static int32_t bound_priority(uint32_t prio_in, struct GSF_ConnectedPeer *cp)
We&#39;ve received a request with the specified priority.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
Information per peer and request.
#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_LOAD_Value * transmission_delay
How long does it typically take for us to transmit a message to this peer? (delay between the request...
const struct GNUNET_PeerIdentity * peer
The peer&#39;s identity (pointer).
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.
No special options (P2P-default).
struct GSF_PendingRequest * pr
Handle to generic request (generic: from peer or local client).
double GNUNET_LOAD_get_load(struct GNUNET_LOAD_Value *load)
Get the current load.
Definition: load.c:202
static void handle_p2p_reply(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.
unsigned int GSF_cover_query_count
How many query messages have we received &#39;recently&#39; that have not yet been claimed as cover traffic...
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:81
double GNUNET_LOAD_get_average(struct GNUNET_LOAD_Value *load)
Get the average value given to update so far.
Definition: load.c:217
#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).
static int test_exist_cb(void *cls, const struct GNUNET_HashCode *hc, void *value)
Test if the query already exists.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
#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.
Public data (in the sense of not encapsulated within &#39;gnunet-service-fs_pr&#39;, not in the sense of netw...
static int32_t bound_ttl(int32_t ttl_in, uint32_t prio)
The priority level imposes a bound on the maximum value for the ttl that can be requested.
unsigned int GNUNET_PEER_Id
A GNUNET_PEER_Id is simply a shorter version of a "struct GNUNET_PeerIdentifier" that can be used ins...
unsigned int pending_replies
Number of pending replies (queries are not counted)
Message to the datastore service asking about specific content.
Definition: datastore.h:143
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:335
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 GSF_PeerPerformanceData ppd
Performance data for this peer.
struct GNUNET_HashCode query
Hashcodes of the file(s) we&#39;re looking for.
struct GSF_ConnectedPeer * GSF_peer_get_(const struct GNUNET_PeerIdentity *peer)
Get a handle for a connected peer.
#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...
void GSF_local_lookup_(struct GSF_PendingRequest *pr, GSF_LocalLookupContinuation cont, void *cont_cls)
Look up the request in the local datastore.
Closure for test_exist_cb().
uint32_t type
Desired content type.
Definition: datastore.h:153
struct GSF_ConnectedPeer * cp
Which specific peer issued this request?
unsigned int delay_queue_size
Number of entries in delayed_head DLL.
void GSF_consider_forwarding(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.
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
Allow multiple values with the same key.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_LOAD_Value * GSF_rt_entry_lifetime
How long do requests typically stay in the routing table?
struct GSF_PendingRequestData * GSF_pending_request_get_data_(struct GSF_PendingRequest *pr)
Obtain the public data associated with a pending request.
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.
Request must only be forwarded (no routing)
struct GNUNET_MQ_Handle * mq
Handle for an active request for transmission to this peer.
#define GNUNET_log(kind,...)
#define TTL_DECREMENT
By which amount do we decrement the TTL for simple forwarding / indirection of the query; in milli-se...
A connected peer.
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.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define MAX_QUEUE_PER_PEER
Maximum number of outgoing messages we queue per peer.
An active request.
#define GNUNET_CONSTANTS_MAX_CORK_DELAY
How long do we delay messages to get larger packet sizes (CORKing)?
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int has_started
Has this request been started yet (local/p2p operations)? Or are we still constructing it...
GSF_PendingRequestOptions
Options for pending requests (bits to be ORed).
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
GNUNET_PEER_Id GNUNET_PEER_intern(const struct GNUNET_PeerIdentity *pid)
Intern an peer identity.
Definition: peer.c:107
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

◆ GSF_peer_transmit_()

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.

If the peer disconnects before the transmission can happen, the callback is invoked with a NULL buffer.

Parameters
cptarget peer
is_queryis this a query (GNUNET_YES) or content (GNUNET_NO) or neither (GNUNET_SYSERR)
priorityhow important is this request?
timeoutwhen does this request timeout
sizenumber of bytes we would like to send to the peer
envmessage to send

Definition at line 1367 of file gnunet-service-fs_cp.c.

References GSF_PeerTransmitHandle::cp, GSF_PeerTransmitHandle::env, GNUNET_CONTAINER_DLL_insert_after, GNUNET_new, GNUNET_NO, GNUNET_TIME_absolute_get(), GNUNET_YES, GSF_PeerTransmitHandle::is_query, GSF_PeerTransmitHandle::next, GSF_PeerPerformanceData::pending_queries, GSF_PeerPerformanceData::pending_replies, GSF_ConnectedPeer::ppd, GSF_PeerTransmitHandle::prev, GSF_PeerTransmitHandle::priority, GSF_ConnectedPeer::pth_head, GSF_ConnectedPeer::pth_tail, schedule_transmission(), and GSF_PeerTransmitHandle::transmission_request_start_time.

Referenced by GSF_block_peer_migration_(), handle_p2p_reply(), schedule_peer_transmission(), transmit_content(), and transmit_delayed_now().

1371 {
1372  struct GSF_PeerTransmitHandle *pth;
1373  struct GSF_PeerTransmitHandle *pos;
1374  struct GSF_PeerTransmitHandle *prev;
1375 
1376  pth = GNUNET_new (struct GSF_PeerTransmitHandle);
1378  pth->env = env;
1379  pth->is_query = is_query;
1380  pth->priority = priority;
1381  pth->cp = cp;
1382  /* insertion sort (by priority, descending) */
1383  prev = NULL;
1384  pos = cp->pth_head;
1385  while ((NULL != pos) && (pos->priority > priority))
1386  {
1387  prev = pos;
1388  pos = pos->next;
1389  }
1391  cp->pth_tail,
1392  prev,
1393  pth);
1394  if (GNUNET_YES == is_query)
1395  cp->ppd.pending_queries++;
1396  else if (GNUNET_NO == is_query)
1397  cp->ppd.pending_replies++;
1398  schedule_transmission (pth);
1399 }
unsigned int pending_queries
Number of pending queries (replies are not counted)
int is_query
GNUNET_YES if this is a query, GNUNET_NO for content.
struct GSF_PeerTransmitHandle * next
Kept in a doubly-linked list.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GSF_PeerTransmitHandle * pth_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
struct GSF_ConnectedPeer * cp
Peer this request targets.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
unsigned int pending_replies
Number of pending replies (queries are not counted)
static void schedule_transmission(struct GSF_PeerTransmitHandle *pth)
If ready (bandwidth reserved), try to schedule transmission via core for the given handle...
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
uint32_t priority
Priority of this request.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_MQ_Envelope * env
Envelope with the actual message.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GSF_PeerTransmitHandle * prev
Kept in a doubly-linked list.
struct GSF_PeerTransmitHandle * pth_tail
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TIME_Absolute transmission_request_start_time
Time when this transmission request was issued.
Handle to cancel a transmission request.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_peer_update_performance_()

void GSF_peer_update_performance_ ( struct GSF_ConnectedPeer cp,
struct GNUNET_TIME_Absolute  request_time,
uint32_t  request_priority 
)

Report on receiving a reply; update the performance record of the given peer.

Parameters
cpresponding peer (will be updated)
request_timetime at which the original query was transmitted
request_prioritypriority of the original request

Definition at line 1410 of file gnunet-service-fs_cp.c.

References GSF_PeerPerformanceData::avg_priority, GSF_PeerPerformanceData::avg_reply_delay, GNUNET_TIME_absolute_get_duration(), GSF_ConnectedPeer::ppd, GNUNET_TIME_Relative::rel_value_us, and RUNAVG_DELAY_N.

Referenced by update_request_performance_data().

1413 {
1414  struct GNUNET_TIME_Relative delay;
1415 
1416  delay = GNUNET_TIME_absolute_get_duration (request_time);
1419  delay.rel_value_us) / RUNAVG_DELAY_N;
1420  cp->ppd.avg_priority =
1421  (cp->ppd.avg_priority * (RUNAVG_DELAY_N - 1) +
1422  request_priority) / RUNAVG_DELAY_N;
1423 }
uint64_t rel_value_us
The actual value.
#define RUNAVG_DELAY_N
Ratio for moving average delay calculation.
double avg_priority
Average priority of successful replies.
struct GNUNET_TIME_Relative avg_reply_delay
Average delay between sending the peer a request and getting a reply (only calculated over the reques...
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
Time for relative time used by GNUnet, in microseconds.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_peer_update_responder_client_()

void GSF_peer_update_responder_client_ ( struct GSF_ConnectedPeer cp,
struct GSF_LocalClient initiator_client 
)

Report on receiving a reply in response to an initiating client.

Remember that this peer is good for this client.

Parameters
cpresponding peer (will be updated)
initiator_clientlocal client on responsible for query

Definition at line 1434 of file gnunet-service-fs_cp.c.

References CS2P_SUCCESS_LIST_SIZE, GSF_PeerPerformanceData::last_client_replies, GSF_ConnectedPeer::last_client_replies_woff, and GSF_ConnectedPeer::ppd.

1436 {
1438  CS2P_SUCCESS_LIST_SIZE] = initiator_client;
1439 }
#define CS2P_SUCCESS_LIST_SIZE
Length of the CS-2-P success tracker.
unsigned int last_client_replies_woff
Which offset in last_client_replies will be updated next? (we go round-robin).
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
struct GSF_LocalClient * last_client_replies[8]
List of the last clients for which this peer successfully answered a query.

◆ GSF_peer_update_responder_peer_()

void GSF_peer_update_responder_peer_ ( struct GSF_ConnectedPeer cp,
const struct GSF_ConnectedPeer initiator_peer 
)

Report on receiving a reply in response to an initiating peer.

Remember that this peer is good for this initiating peer.

Parameters
cpresponding peer (will be updated)
initiator_peerother peer responsible for query

Definition at line 1450 of file gnunet-service-fs_cp.c.

References GNUNET_PEER_change_rc(), GSF_PeerPerformanceData::last_p2p_replies, GSF_ConnectedPeer::last_p2p_replies_woff, P2P_SUCCESS_LIST_SIZE, GSF_PeerPerformanceData::pid, and GSF_ConnectedPeer::ppd.

1452 {
1453  unsigned int woff;
1454 
1456  GNUNET_PEER_change_rc (cp->ppd.last_p2p_replies[woff], -1);
1457  cp->ppd.last_p2p_replies[woff] = initiator_peer->ppd.pid;
1458  GNUNET_PEER_change_rc (initiator_peer->ppd.pid, 1);
1459  cp->last_p2p_replies_woff = (woff + 1) % P2P_SUCCESS_LIST_SIZE;
1460 }
#define P2P_SUCCESS_LIST_SIZE
Length of the P2P success tracker.
unsigned int last_p2p_replies_woff
Which offset in last_p2p_replies will be updated next? (we go round-robin).
GNUNET_PEER_Id last_p2p_replies[8]
List of the last PIDs for which this peer successfully answered a query; We use 0 to indicate no succ...
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:198
Here is the call graph for this function:

◆ flush_respect()

static int flush_respect ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Write peer-respect information to a file - flush the buffer entry!

Parameters
clsunused
keypeer identity
valuethe struct GSF_ConnectedPeer to flush
Returns
GNUNET_OK to continue iteration

Definition at line 1472 of file gnunet-service-fs_cp.c.

References GSF_ConnectedPeer::disk_respect, GNUNET_assert, GNUNET_OK, GNUNET_PEER_resolve(), GNUNET_PEERSTORE_store(), GNUNET_PEERSTORE_STOREOPTION_REPLACE, GNUNET_TIME_UNIT_FOREVER_ABS, GSF_PeerPerformanceData::pid, GSF_ConnectedPeer::ppd, GSF_PeerPerformanceData::respect, and value.

Referenced by cron_flush_respect(), GSF_connected_peer_done_(), and GSF_peer_disconnect_handler().

1475 {
1476  struct GSF_ConnectedPeer *cp = value;
1477  struct GNUNET_PeerIdentity pid;
1478 
1479  if (cp->ppd.respect == cp->disk_respect)
1480  return GNUNET_OK; /* unchanged */
1481  GNUNET_assert (0 != cp->ppd.pid);
1482  GNUNET_PEER_resolve (cp->ppd.pid, &pid);
1483  GNUNET_PEERSTORE_store (peerstore, "fs", &pid, "respect", &cp->ppd.respect,
1484  sizeof (cp->ppd.respect),
1487  NULL,
1488  NULL);
1489  return GNUNET_OK;
1490 }
Delete any previous values for the given key before storing the given value.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint32_t disk_respect
Respect rating for this peer on disk.
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
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static char * value
Value of the record to add/remove.
uint32_t respect
Respect rating for this peer.
struct GNUNET_PEERSTORE_StoreContext * GNUNET_PEERSTORE_store(struct GNUNET_PEERSTORE_Handle *h, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, const void *value, size_t size, struct GNUNET_TIME_Absolute expiry, enum GNUNET_PEERSTORE_StoreOption options, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Store a new entry in the PEERSTORE.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to peerstore service.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
The identity of the host (wraps the signing key of the peer).
A connected peer.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_peer_disconnect_handler()

void GSF_peer_disconnect_handler ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)

A peer disconnected from us.

Tear down the connected peer record.

Parameters
clsunused
peeridentity of peer that disconnected
internal_clsthe corresponding struct GSF_ConnectedPeer

Definition at line 1502 of file gnunet-service-fs_cp.c.

References cancel_pending_request(), GSF_ConnectedPeer::delay_queue_size, GSF_DelayedHandle::delay_task, GSF_ConnectedPeer::delayed_head, GSF_ConnectedPeer::delayed_tail, GSF_DelayedHandle::env, flush_respect(), gettext_noop, GNUNET_assert, GNUNET_ATS_reserve_bandwidth_cancel(), GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_free, GNUNET_LOAD_value_free, GNUNET_MQ_discard(), GNUNET_NO, GNUNET_PEER_change_rc(), GNUNET_PEER_decrement_rcs(), GNUNET_PEERSTORE_iterate_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_YES, GSF_plan_notify_peer_disconnect_(), GSF_push_stop_(), GSF_stats, GSF_PeerTransmitHandle::is_query, GSF_PeerPerformanceData::last_p2p_replies, GSF_ConnectedPeer::mig_revive_task, P2P_SUCCESS_LIST_SIZE, GSF_PeerPerformanceData::pending_queries, GSF_PeerPerformanceData::pending_replies, GSF_PeerPerformanceData::pid, GSF_ConnectedPeer::ppd, GSF_ConnectedPeer::pth_head, GSF_ConnectedPeer::pth_tail, GSF_ConnectedPeer::rc, GSF_ConnectedPeer::rc_delay_task, GSF_ConnectedPeer::request_map, GSF_ConnectedPeer::respect_iterate_req, and GSF_PeerPerformanceData::transmission_delay.

Referenced by main_init().

1505 {
1506  struct GSF_ConnectedPeer *cp = internal_cls;
1507  struct GSF_PeerTransmitHandle *pth;
1508  struct GSF_DelayedHandle *dh;
1509 
1510  if (NULL == cp)
1511  return; /* must have been disconnect from core with
1512  * 'peer' == my_id, ignore */
1513  flush_respect (NULL,
1514  peer,
1515  cp);
1518  peer,
1519  cp));
1521  gettext_noop ("# peers connected"),
1523  GNUNET_NO);
1524  if (NULL != cp->respect_iterate_req)
1525  {
1527  cp->respect_iterate_req = NULL;
1528  }
1529  if (NULL != cp->rc)
1530  {
1532  cp->rc = NULL;
1533  }
1534  if (NULL != cp->rc_delay_task)
1535  {
1537  cp->rc_delay_task = NULL;
1538  }
1541  cp);
1543  cp->request_map = NULL;
1548  memset (cp->ppd.last_p2p_replies,
1549  0,
1550  sizeof (cp->ppd.last_p2p_replies));
1551  GSF_push_stop_ (cp);
1552  while (NULL != (pth = cp->pth_head))
1553  {
1555  cp->pth_tail,
1556  pth);
1557  if (GNUNET_YES == pth->is_query)
1558  GNUNET_assert (0 < cp->ppd.pending_queries--);
1559  else if (GNUNET_NO == pth->is_query)
1560  GNUNET_assert (0 < cp->ppd.pending_replies--);
1561  GNUNET_free (pth);
1562  }
1563  while (NULL != (dh = cp->delayed_head))
1564  {
1566  cp->delayed_tail,
1567  dh);
1568  GNUNET_MQ_discard (dh->env);
1569  cp->delay_queue_size--;
1571  GNUNET_free (dh);
1572  }
1573  GNUNET_PEER_change_rc (cp->ppd.pid, -1);
1574  if (NULL != cp->mig_revive_task)
1575  {
1577  cp->mig_revive_task = NULL;
1578  }
1579  GNUNET_break (0 == cp->ppd.pending_queries);
1580  GNUNET_break (0 == cp->ppd.pending_replies);
1581  GNUNET_free (cp);
1582 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GNUNET_CONTAINER_MultiHashMap * request_map
Active requests from this neighbour, map of query to struct PeerRequest.
unsigned int pending_queries
Number of pending queries (replies are not counted)
#define P2P_SUCCESS_LIST_SIZE
Length of the P2P success tracker.
int is_query
GNUNET_YES if this is a query, GNUNET_NO for content.
void GSF_push_stop_(struct GSF_ConnectedPeer *peer)
A peer disconnected from us.
static int cancel_pending_request(void *cls, const struct GNUNET_HashCode *query, void *value)
Cancel all requests associated with the peer.
Handle for an entry in our delay list.
struct GNUNET_LOAD_Value * transmission_delay
How long does it typically take for us to transmit a message to this peer? (delay between the request...
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
int 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.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GSF_PeerTransmitHandle * pth_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
struct GNUNET_SCHEDULER_Task * rc_delay_task
Task scheduled if we need to retry bandwidth reservation later.
struct GSF_DelayedHandle * delayed_tail
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GSF_DelayedHandle * delayed_head
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
unsigned int pending_replies
Number of pending replies (queries are not counted)
struct GNUNET_ATS_ReservationContext * rc
Context of our GNUNET_ATS_reserve_bandwidth call (or NULL).
GNUNET_PEER_Id last_p2p_replies[8]
List of the last PIDs for which this peer successfully answered a query; We use 0 to indicate no succ...
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_PEER_decrement_rcs(const GNUNET_PEER_Id *ids, unsigned int count)
Decrement multiple RCs of peer identities by one.
Definition: peer.c:163
void GNUNET_MQ_discard(struct GNUNET_MQ_Envelope *mqm)
Discard the message queue message, free all allocated resources.
Definition: mq.c:321
struct GNUNET_SCHEDULER_Task * delay_task
Task for the delay.
unsigned int delay_queue_size
Number of entries in delayed_head DLL.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
struct GNUNET_SCHEDULER_Task * mig_revive_task
Task scheduled to revive migration to this peer.
void GNUNET_ATS_reserve_bandwidth_cancel(struct GNUNET_ATS_ReservationContext *rc)
Cancel request for reserving bandwidth.
struct GSF_PeerTransmitHandle * pth_tail
Messages (replies, queries, content migration) we would like to send to this peer in the near future...
#define GNUNET_LOAD_value_free(lv)
Free a load value.
struct GNUNET_PEERSTORE_IterateContext * respect_iterate_req
Handle to the PEERSTORE iterate request for peer respect value.
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:198
A connected peer.
void GNUNET_PEERSTORE_iterate_cancel(struct GNUNET_PEERSTORE_IterateContext *ic)
Cancel an iterate request Please do not call after the iterate request is done.
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...
static int flush_respect(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Write peer-respect information to a file - flush the buffer entry!
struct GNUNET_MQ_Envelope * env
Envelope of the message that was delayed.
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
Handle to cancel a transmission request.
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:

◆ call_iterator()

static int call_iterator ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Function that calls the callback for each peer.

Parameters
clsthe struct IterationContext *
keyidentity of the peer
valuethe struct GSF_ConnectedPeer *
Returns
GNUNET_YES to continue iteration

Definition at line 1611 of file gnunet-service-fs_cp.c.

References GNUNET_YES, IterationContext::it, IterationContext::it_cls, GSF_ConnectedPeer::ppd, and value.

Referenced by GSF_iterate_connected_peers_().

1614 {
1615  struct IterationContext *ic = cls;
1616  struct GSF_ConnectedPeer *cp = value;
1617 
1618  ic->it (ic->it_cls,
1619  key, cp,
1620  &cp->ppd);
1621  return GNUNET_YES;
1622 }
Closure for call_iterator().
GSF_ConnectedPeerIterator it
Function to call on each entry.
static char * value
Value of the record to add/remove.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
void * it_cls
Closure for it.
A connected peer.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ GSF_iterate_connected_peers_()

void GSF_iterate_connected_peers_ ( GSF_ConnectedPeerIterator  it,
void *  it_cls 
)

Iterate over all connected peers.

Parameters
itfunction to call for each peer
it_clsclosure for it

Definition at line 1632 of file gnunet-service-fs_cp.c.

References call_iterator(), GNUNET_CONTAINER_multipeermap_iterate(), IterationContext::it, and IterationContext::it_cls.

Referenced by GSF_consider_forwarding().

1634 {
1635  struct IterationContext ic;
1636 
1637  ic.it = it;
1638  ic.it_cls = it_cls;
1640  &call_iterator,
1641  &ic);
1642 }
static int call_iterator(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Function that calls the callback for each peer.
Closure for call_iterator().
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
GSF_ConnectedPeerIterator it
Function to call on each entry.
void * it_cls
Closure for it.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator 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:

◆ GSF_connected_peer_get_identity_()

void GSF_connected_peer_get_identity_ ( const struct GSF_ConnectedPeer cp,
struct GNUNET_PeerIdentity id 
)

Obtain the identity of a connected peer.

Parameters
cppeer to get identity of
ididentity to set (written to)

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

References GNUNET_assert, GNUNET_PEER_resolve(), GSF_PeerPerformanceData::pid, and GSF_ConnectedPeer::ppd.

Referenced by consider_peer_for_forwarding().

1654 {
1655  GNUNET_assert (0 != cp->ppd.pid);
1656  GNUNET_PEER_resolve (cp->ppd.pid, id);
1657 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 GSF_PeerPerformanceData ppd
Performance data for this peer.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_connected_peer_get_identity2_()

const struct GNUNET_PeerIdentity* GSF_connected_peer_get_identity2_ ( const struct GSF_ConnectedPeer cp)

Obtain the identity of a connected peer.

Parameters
cppeer to get identity of
Returns
reference to peer identity, valid until peer disconnects (!)

Definition at line 1667 of file gnunet-service-fs_cp.c.

References GNUNET_assert, GNUNET_PEER_resolve2(), GSF_PeerPerformanceData::pid, and GSF_ConnectedPeer::ppd.

Referenced by GSF_peer_connect_handler(), GSF_plan_add_(), GSF_plan_notify_peer_disconnect_(), GSF_push_start_(), and process_migration_content().

1668 {
1669  GNUNET_assert (0 != cp->ppd.pid);
1670  return GNUNET_PEER_resolve2 (cp->ppd.pid);
1671 }
const struct GNUNET_PeerIdentity * GNUNET_PEER_resolve2(GNUNET_PEER_Id id)
Convert an interned PID to a normal peer identity.
Definition: peer.c:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_block_peer_migration_()

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.

Parameters
cppeer to ask
block_timeuntil when to block

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

References GNUNET_TIME_Absolute::abs_value_us, MigrationStopMessage::duration, GSF_PeerTransmitHandle::env, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP, GNUNET_MQ_msg, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_hton(), GNUNET_YES, GSF_peer_transmit_(), GSF_stats, GSF_ConnectedPeer::last_migration_block, and MigrationStopMessage::reserved.

Referenced by handle_p2p_put(), and put_migration_continuation().

1684 {
1685  struct GNUNET_MQ_Envelope *env;
1686  struct MigrationStopMessage *msm;
1687 
1688  if (cp->last_migration_block.abs_value_us > block_time.abs_value_us)
1689  {
1691  "Migration already blocked for another %s\n",
1694  return; /* already blocked */
1695  }
1696  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to stop migration for %s\n",
1698  GNUNET_YES));
1699  cp->last_migration_block = block_time;
1700  env = GNUNET_MQ_msg (msm,
1702  msm->reserved = htonl (0);
1703  msm->duration
1705  (cp->last_migration_block));
1707  gettext_noop ("# migration stop messages sent"),
1708  1,
1709  GNUNET_NO);
1710  GSF_peer_transmit_ (cp,
1711  GNUNET_SYSERR,
1712  UINT32_MAX,
1713  env);
1714 }
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.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_STATISTICS_Handle * GSF_stats
Handle for reporting statistics.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_TIME_Absolute last_migration_block
Time until when we blocked this peer from migrating data to us.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
uint64_t abs_value_us
The actual value.
uint32_t reserved
Always zero.
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
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:622
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Message send by a peer that wants to be excluded from migration for a while.
struct GNUNET_TIME_RelativeNBO duration
How long should the block last?
#define GNUNET_MESSAGE_TYPE_FS_MIGRATION_STOP
Peer asks us to stop migrating content towards it for a while.
#define GNUNET_log(kind,...)
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:331
#define GNUNET_YES
Definition: gnunet_common.h:80
#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_connected_peer_change_preference_()

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).

The change will be communicated the next time we reserve bandwidth with core (not instantly).

Parameters
cppeer to reserve bandwidth from
prefpreference change

Definition at line 1727 of file gnunet-service-fs_cp.c.

References GSF_ConnectedPeer::inc_preference.

Referenced by handle_p2p_put().

1729 {
1730  cp->inc_preference += pref;
1731 }
uint64_t inc_preference
Increase in traffic preference still to be submitted to the core service for this peer...
Here is the caller graph for this function:

◆ cron_flush_respect()

static void cron_flush_respect ( void *  cls)
static

Call this method periodically to flush respect information to disk.

Parameters
clsclosure, not used

Definition at line 1740 of file gnunet-service-fs_cp.c.

References flush_respect(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_SCHEDULER_add_delayed_with_priority(), GNUNET_SCHEDULER_PRIORITY_HIGH, and RESPECT_FLUSH_FREQ.

Referenced by GSF_connected_peer_init_().

1741 {
1742  fr_task = NULL;
1744  &flush_respect,
1745  NULL);
1748  &cron_flush_respect, NULL);
1749 }
Run with high priority (important requests).
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1178
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
static struct GNUNET_SCHEDULER_Task * fr_task
Task used to flush respect values to disk.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define RESPECT_FLUSH_FREQ
How often do we flush respect values to disk?
static void cron_flush_respect(void *cls)
Call this method periodically to flush respect information to disk.
static int flush_respect(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Write peer-respect information to a file - flush the buffer entry!
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_connected_peer_init_()

void GSF_connected_peer_init_ ( void  )

Initialize peer management subsystem.

Definition at line 1756 of file gnunet-service-fs_cp.c.

References cron_flush_respect(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_PEERSTORE_connect(), GNUNET_SCHEDULER_add_with_priority(), GNUNET_SCHEDULER_PRIORITY_HIGH, GNUNET_YES, and GSF_cfg.

Referenced by run().

1757 {
1761  &cron_flush_respect, NULL);
1762 }
Run with high priority (important requests).
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
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).
const struct GNUNET_CONFIGURATION_Handle * GSF_cfg
Our configuration.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1200
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to peerstore service.
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
static struct GNUNET_SCHEDULER_Task * fr_task
Task used to flush respect values to disk.
static void cron_flush_respect(void *cls)
Call this method periodically to flush respect information to disk.
#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_connected_peer_done_()

void GSF_connected_peer_done_ ( void  )

Shutdown peer management subsystem.

Definition at line 1769 of file gnunet-service-fs_cp.c.

References flush_respect(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_PEERSTORE_disconnect(), GNUNET_SCHEDULER_cancel(), and GNUNET_YES.

Referenced by shutdown_task().

1770 {
1772  &flush_respect,
1773  NULL);
1775  fr_task = NULL;
1777  cp_map = NULL;
1779  GNUNET_YES);
1780 
1781 }
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to peerstore service.
static struct GNUNET_SCHEDULER_Task * fr_task
Task used to flush respect values to disk.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int flush_respect(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Write peer-respect information to a file - flush the buffer entry!
#define GNUNET_YES
Definition: gnunet_common.h:80
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:

◆ clean_local_client()

static int clean_local_client ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Iterator to remove references to LC entry.

Parameters
clsthe struct GSF_LocalClient * to look for
keycurrent key code
valuevalue in the hash map (peer entry)
Returns
GNUNET_YES (we should continue to iterate)

Definition at line 1793 of file gnunet-service-fs_cp.c.

References CS2P_SUCCESS_LIST_SIZE, GNUNET_YES, GSF_PeerPerformanceData::last_client_replies, GSF_ConnectedPeer::ppd, and value.

Referenced by GSF_handle_local_client_disconnect_().

1796 {
1797  const struct GSF_LocalClient *lc = cls;
1798  struct GSF_ConnectedPeer *cp = value;
1799  unsigned int i;
1800 
1801  for (i = 0; i < CS2P_SUCCESS_LIST_SIZE; i++)
1802  if (cp->ppd.last_client_replies[i] == lc)
1803  cp->ppd.last_client_replies[i] = NULL;
1804  return GNUNET_YES;
1805 }
#define CS2P_SUCCESS_LIST_SIZE
Length of the CS-2-P success tracker.
A local client.
static char * value
Value of the record to add/remove.
struct GSF_PeerPerformanceData ppd
Performance data for this peer.
A connected peer.
struct GSF_LocalClient * last_client_replies[8]
List of the last clients for which this peer successfully answered a query.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ GSF_handle_local_client_disconnect_()

void GSF_handle_local_client_disconnect_ ( const struct GSF_LocalClient lc)

Notification that a local client disconnected.

Clean up all of our references to the given handle.

Parameters
lchandle to the local client (henceforth invalid)

Definition at line 1815 of file gnunet-service-fs_cp.c.

References clean_local_client(), and GNUNET_CONTAINER_multipeermap_iterate().

1816 {
1817  if (NULL == cp_map)
1818  return; /* already cleaned up */
1821  (void *) lc);
1822 }
static struct GNUNET_CONTAINER_MultiPeerMap * cp_map
Map from peer identities to struct GSF_ConnectPeer entries.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int clean_local_client(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator to remove references to LC entry.
Here is the call graph for this function:

Variable Documentation

◆ cp_map

struct GNUNET_CONTAINER_MultiPeerMap* cp_map
static

Map from peer identities to struct GSF_ConnectPeer entries.

Definition at line 288 of file gnunet-service-fs_cp.c.

◆ peerstore

struct GNUNET_PEERSTORE_Handle* peerstore
static

Handle to peerstore service.

Definition at line 293 of file gnunet-service-fs_cp.c.

◆ fr_task

struct GNUNET_SCHEDULER_Task* fr_task
static

Task used to flush respect values to disk.

Definition at line 298 of file gnunet-service-fs_cp.c.