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

API to push content from our datastore to other peers ('anonymous'-content P2P migration) More...

#include "platform.h"
#include "gnunet-service-fs.h"
#include "gnunet-service-fs_cp.h"
#include "gnunet-service-fs_indexing.h"
#include "gnunet-service-fs_push.h"
Include dependency graph for gnunet-service-fs_push.c:

Go to the source code of this file.

Data Structures

struct  MigrationReadyBlock
 Block that is ready for migration to other peers. More...
 
struct  MigrationReadyPeer
 Information about a peer waiting for migratable data. More...
 

Macros

#define MAX_MIGRATION_QUEUE   8
 Maximum number of blocks we keep in memory for migration. More...
 
#define MIGRATION_LIST_SIZE   2
 Blocks are at most migrated to this number of peers plus one, each time they are fetched from the database. More...
 
#define MIN_MIGRATION_CONTENT_LIFETIME   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
 How long must content remain valid for us to consider it for migration? If content will expire too soon, there is clearly no point in pushing it to other peers. More...
 

Functions

static void delete_migration_block (struct MigrationReadyBlock *mb)
 Delete the given migration block. More...
 
static void find_content (void *cls)
 Find content for migration to this peer. More...
 
static int transmit_content (struct MigrationReadyPeer *mrp, struct MigrationReadyBlock *block)
 Send the given block to the given peer. More...
 
static unsigned int count_targets (struct MigrationReadyBlock *block)
 Count the number of peers this block has already been forwarded to. More...
 
static long score_content (struct MigrationReadyPeer *mrp, struct MigrationReadyBlock *block)
 Check if sending this block to this peer would be a good idea. More...
 
static void consider_gathering (void)
 If the migration task is not currently running, consider (re)scheduling it with the appropriate delay. More...
 
static void gather_migration_blocks (void *cls)
 Task that is run periodically to obtain blocks for content migration. More...
 
static void process_migration_content (void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
 Process content offered for migration. More...
 
void GSF_push_start_ (struct GSF_ConnectedPeer *peer)
 A peer connected to us. More...
 
void GSF_push_stop_ (struct GSF_ConnectedPeer *peer)
 A peer disconnected from us. More...
 
void GSF_push_init_ ()
 Setup the module. More...
 
void GSF_push_done_ ()
 Shutdown the module. More...
 

Variables

static struct MigrationReadyBlockmig_head
 Head of linked list of blocks that can be migrated. More...
 
static struct MigrationReadyBlockmig_tail
 Tail of linked list of blocks that can be migrated. More...
 
static struct MigrationReadyPeerpeer_head
 Head of linked list of peers. More...
 
static struct MigrationReadyPeerpeer_tail
 Tail of linked list of peers. More...
 
static struct GNUNET_DATASTORE_QueueEntrymig_qe
 Request to datastore for migration (or NULL). More...
 
static struct GNUNET_SCHEDULER_Taskmig_task
 ID of task that collects blocks for migration. More...
 
static struct GNUNET_TIME_Relative min_migration_delay
 What is the maximum frequency at which we are allowed to poll the datastore for migration content? More...
 
static unsigned int mig_size
 Size of the doubly-linked list of migration blocks. More...
 
static int enabled
 Is this module enabled? More...
 
static int value_found
 Did we find anything in the datastore? More...
 

Detailed Description

API to push content from our datastore to other peers ('anonymous'-content P2P migration)

Author
Christian Grothoff

Definition in file gnunet-service-fs_push.c.

Macro Definition Documentation

◆ MAX_MIGRATION_QUEUE

#define MAX_MIGRATION_QUEUE   8

Maximum number of blocks we keep in memory for migration.

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

Referenced by consider_gathering(), find_content(), gather_migration_blocks(), and process_migration_content().

◆ MIGRATION_LIST_SIZE

#define MIGRATION_LIST_SIZE   2

Blocks are at most migrated to this number of peers plus one, each time they are fetched from the database.

Definition at line 43 of file gnunet-service-fs_push.c.

Referenced by count_targets(), delete_migration_block(), score_content(), and transmit_content().

◆ MIN_MIGRATION_CONTENT_LIFETIME

#define MIN_MIGRATION_CONTENT_LIFETIME   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)

How long must content remain valid for us to consider it for migration? If content will expire too soon, there is clearly no point in pushing it to other peers.

This value gives the threshold for migration. Note that if this value is increased, the migration testcase may need to be adjusted as well (especially the CONTENT_LIFETIME in fs_test_lib.c).

Definition at line 52 of file gnunet-service-fs_push.c.

Referenced by process_migration_content().

Function Documentation

◆ delete_migration_block()

static void delete_migration_block ( struct MigrationReadyBlock mb)
static

Delete the given migration block.

Parameters
mbblock to delete

Definition at line 189 of file gnunet-service-fs_push.c.

References find_content(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_PEER_decrement_rcs(), mig_size, MIGRATION_LIST_SIZE, and MigrationReadyBlock::target_list.

Referenced by find_content(), GSF_push_done_(), and transmit_content().

190 {
192  mig_tail,
193  mb);
196  mig_size--;
197  GNUNET_free (mb);
198 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define MIGRATION_LIST_SIZE
Blocks are at most migrated to this number of peers plus one, each time they are fetched from the dat...
static struct MigrationReadyBlock * mig_head
Head of linked list of blocks that can be migrated.
static struct MigrationReadyBlock * mig_tail
Tail of linked list of blocks that can be migrated.
GNUNET_PEER_Id target_list[2]
Peers we already forwarded this block to.
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
static unsigned int mig_size
Size of the doubly-linked list of migration blocks.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_content()

static void find_content ( void *  cls)
static

Find content for migration to this peer.

Parameters
clsa struct MigrationReadyPeer *
clspeer to find content for

Definition at line 334 of file gnunet-service-fs_push.c.

References consider_gathering(), count_targets(), delete_migration_block(), MigrationReadyPeer::env, gather_migration_blocks(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, MAX_MIGRATION_QUEUE, mig_head, mig_size, MigrationReadyBlock::next, score_content(), and transmit_content().

Referenced by delete_migration_block(), GSF_push_start_(), and transmit_content().

335 {
336  struct MigrationReadyPeer *mrp = cls;
337  struct MigrationReadyBlock *pos;
338  long score;
339  long best_score;
340  struct MigrationReadyBlock *best;
341 
342  mrp->env = NULL;
343  best = NULL;
344  best_score = -1;
345  pos = mig_head;
346  while (NULL != pos)
347  {
348  score = score_content (mrp, pos);
349  if (score > best_score)
350  {
351  best_score = score;
352  best = pos;
353  }
354  pos = pos->next;
355  }
356  if (NULL == best)
357  {
359  {
361  "No content found for pushing, waiting for queue to fill\n");
362  return; /* will fill up eventually... */
363  }
365  "No suitable content found, purging content from full queue\n");
366  /* failed to find migration target AND
367  * queue is full, purge most-forwarded
368  * block from queue to make room for more */
369  pos = mig_head;
370  while (NULL != pos)
371  {
372  score = count_targets (pos);
373  if (score >= best_score)
374  {
375  best_score = score;
376  best = pos;
377  }
378  pos = pos->next;
379  }
380  GNUNET_assert (NULL != best);
381  delete_migration_block (best);
383  return;
384  }
386  "Preparing to push best content to peer\n");
387  transmit_content (mrp,
388  best);
389 }
static long score_content(struct MigrationReadyPeer *mrp, struct MigrationReadyBlock *block)
Check if sending this block to this peer would be a good idea.
#define MAX_MIGRATION_QUEUE
Maximum number of blocks we keep in memory for migration.
struct GNUNET_MQ_Envelope * env
Envelope of the currently pushed message.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Information about a peer waiting for migratable data.
static int transmit_content(struct MigrationReadyPeer *mrp, struct MigrationReadyBlock *block)
Send the given block to the given peer.
static struct MigrationReadyBlock * mig_head
Head of linked list of blocks that can be migrated.
Block that is ready for migration to other peers.
static void delete_migration_block(struct MigrationReadyBlock *mb)
Delete the given migration block.
static void consider_gathering(void)
If the migration task is not currently running, consider (re)scheduling it with the appropriate delay...
struct MigrationReadyBlock * next
This is a doubly-linked list.
static unsigned int mig_size
Size of the doubly-linked list of migration blocks.
#define GNUNET_log(kind,...)
static unsigned int count_targets(struct MigrationReadyBlock *block)
Count the number of peers this block has already been forwarded to.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transmit_content()

static int transmit_content ( struct MigrationReadyPeer mrp,
struct MigrationReadyBlock block 
)
static

Send the given block to the given peer.

Parameters
peertarget peer
blockthe block
Returns
GNUNET_YES if the block was deleted (!)

Definition at line 218 of file gnunet-service-fs_push.c.

References delete_migration_block(), MigrationReadyPeer::env, MigrationReadyBlock::expiration, PutMessage::expiration, find_content(), GNUNET_assert, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_FS_PUT, GNUNET_MQ_msg_extra, GNUNET_MQ_notify_sent(), GNUNET_NO, GNUNET_PEER_change_rc(), GNUNET_TIME_absolute_hton(), GNUNET_YES, GSF_get_peer_performance_data_(), GSF_peer_transmit_(), MIGRATION_LIST_SIZE, msg, MigrationReadyPeer::peer, GSF_PeerPerformanceData::pid, ret, MigrationReadyBlock::size, MigrationReadyBlock::target_list, MigrationReadyBlock::type, and PutMessage::type.

Referenced by find_content(), and process_migration_content().

220 {
221  struct PutMessage *msg;
222  unsigned int i;
223  struct GSF_PeerPerformanceData *ppd;
224  int ret;
225 
227  GNUNET_assert (NULL == mrp->env);
228  mrp->env = GNUNET_MQ_msg_extra (msg,
229  block->size,
231  msg->type = htonl (block->type);
233  GNUNET_memcpy (&msg[1],
234  &block[1],
235  block->size);
236  for (i = 0; i < MIGRATION_LIST_SIZE; i++)
237  {
238  if (block->target_list[i] == 0)
239  {
240  block->target_list[i] = ppd->pid;
242  1);
243  break;
244  }
245  }
246  if (MIGRATION_LIST_SIZE == i)
247  {
248  delete_migration_block (block);
249  ret = GNUNET_YES;
250  }
251  else
252  {
253  ret = GNUNET_NO;
254  }
256  &find_content,
257  mrp);
258  GSF_peer_transmit_ (mrp->peer,
259  GNUNET_NO,
260  0 /* priority */ ,
261  mrp->env);
262  return ret;
263 }
#define MIGRATION_LIST_SIZE
Blocks are at most migrated to this number of peers plus one, each time they are fetched from the dat...
struct GSF_ConnectedPeer * peer
Handle to peer.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Envelope of the currently pushed message.
Response from FS service with a result for a previous FS search.
Definition: fs.h:336
struct GNUNET_TIME_AbsoluteNBO expiration
When does this result expire?
Definition: fs.h:352
struct GNUNET_TIME_Absolute expiration
When does this block expire?
#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.
#define GNUNET_NO
Definition: gnunet_common.h:81
enum GNUNET_BLOCK_Type type
Type of the block.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static void delete_migration_block(struct MigrationReadyBlock *mb)
Delete the given migration block.
GNUNET_PEER_Id target_list[2]
Peers we already forwarded this block to.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
#define GNUNET_memcpy(dst, src, n)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore...
Definition: mq.c:774
struct GSF_PeerPerformanceData * GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp)
Return the performance data record for the given peer.
uint32_t type
Type of the block (in big endian).
Definition: fs.h:347
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
Performance data kept for a peer.
void GNUNET_PEER_change_rc(GNUNET_PEER_Id id, int delta)
Change the reference counter of an interned PID.
Definition: peer.c:198
#define GNUNET_YES
Definition: gnunet_common.h:80
static void find_content(void *cls)
Find content for migration to this peer.
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.
size_t size
Size of the block.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ count_targets()

static unsigned int count_targets ( struct MigrationReadyBlock block)
static

Count the number of peers this block has already been forwarded to.

Parameters
blockthe block
Returns
number of times block was forwarded

Definition at line 274 of file gnunet-service-fs_push.c.

References MIGRATION_LIST_SIZE, and MigrationReadyBlock::target_list.

Referenced by find_content().

275 {
276  unsigned int i;
277 
278  for (i = 0; i < MIGRATION_LIST_SIZE; i++)
279  if (block->target_list[i] == 0)
280  return i;
281  return i;
282 }
#define MIGRATION_LIST_SIZE
Blocks are at most migrated to this number of peers plus one, each time they are fetched from the dat...
GNUNET_PEER_Id target_list[2]
Peers we already forwarded this block to.
Here is the caller graph for this function:

◆ score_content()

static long score_content ( struct MigrationReadyPeer mrp,
struct MigrationReadyBlock block 
)
static

Check if sending this block to this peer would be a good idea.

Parameters
mrptarget peer
blockthe block
Returns
score (>= 0: feasible, negative: infeasible)

Definition at line 294 of file gnunet-service-fs_push.c.

References consider_gathering(), GNUNET_assert, GNUNET_CRYPTO_hash(), GNUNET_CRYPTO_hash_distance_u32(), GNUNET_PEER_resolve(), GSF_get_peer_performance_data_(), MIGRATION_LIST_SIZE, MigrationReadyPeer::peer, GSF_PeerPerformanceData::pid, MigrationReadyBlock::query, and MigrationReadyBlock::target_list.

Referenced by find_content().

296 {
297  unsigned int i;
298  struct GSF_PeerPerformanceData *ppd;
299  struct GNUNET_PeerIdentity id;
300  struct GNUNET_HashCode hc;
301  uint32_t dist;
302 
304  for (i = 0; i < MIGRATION_LIST_SIZE; i++)
305  if (block->target_list[i] == ppd->pid)
306  return -1;
307  GNUNET_assert (0 != ppd->pid);
308  GNUNET_PEER_resolve (ppd->pid,
309  &id);
310  GNUNET_CRYPTO_hash (&id,
311  sizeof (struct GNUNET_PeerIdentity),
312  &hc);
313  dist = GNUNET_CRYPTO_hash_distance_u32 (&block->query,
314  &hc);
315  /* closer distance, higher score: */
316  return UINT32_MAX - dist;
317 }
#define MIGRATION_LIST_SIZE
Blocks are at most migrated to this number of peers plus one, each time they are fetched from the dat...
struct GSF_ConnectedPeer * peer
Handle to peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct GNUNET_IDENTITY_Handle * id
Handle to identity service.
uint32_t GNUNET_CRYPTO_hash_distance_u32(const struct GNUNET_HashCode *a, const struct GNUNET_HashCode *b)
Compute the distance between 2 hashcodes.
Definition: crypto_hash.c:121
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:226
GNUNET_PEER_Id target_list[2]
Peers we already forwarded this block to.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
struct GSF_PeerPerformanceData * GSF_get_peer_performance_data_(struct GSF_ConnectedPeer *cp)
Return the performance data record for the given peer.
A 512-bit hashcode.
GNUNET_PEER_Id pid
The peer&#39;s identity (interned version).
The identity of the host (wraps the signing key of the peer).
Performance data kept for a peer.
struct GNUNET_HashCode query
Query for the block.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ consider_gathering()

static void consider_gathering ( void  )
static

If the migration task is not currently running, consider (re)scheduling it with the appropriate delay.

Definition at line 407 of file gnunet-service-fs_push.c.

References gather_migration_blocks(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_max(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_SECONDS, GSF_dsh, MAX_MIGRATION_QUEUE, mig_size, min_migration_delay, and value_found.

Referenced by find_content(), gather_migration_blocks(), GSF_push_init_(), process_migration_content(), and score_content().

408 {
410 
411  if (NULL == GSF_dsh)
412  return;
413  if (NULL != mig_qe)
414  return;
415  if (NULL != mig_task)
416  return;
418  return;
420  mig_size);
425  if (GNUNET_NO == value_found)
426  {
427  /* wait at least 5s if the datastore is empty */
430  5));
431  }
433  "Scheduling gathering task (queue size: %u)\n",
434  mig_size);
437  NULL);
438 }
#define MAX_MIGRATION_QUEUE
Maximum number of blocks we keep in memory for migration.
static struct GNUNET_DATASTORE_QueueEntry * mig_qe
Request to datastore for migration (or NULL).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:286
#define GNUNET_TIME_UNIT_SECONDS
One second.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_SCHEDULER_Task * mig_task
ID of task that collects blocks for migration.
static struct GNUNET_TIME_Relative min_migration_delay
What is the maximum frequency at which we are allowed to poll the datastore for migration content...
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_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
static int value_found
Did we find anything in the datastore?
struct GNUNET_DATASTORE_Handle * GSF_dsh
Our connection to the datastore.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static unsigned int mig_size
Size of the doubly-linked list of migration blocks.
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:525
static void gather_migration_blocks(void *cls)
Task that is run periodically to obtain blocks for content migration.
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:

◆ gather_migration_blocks()

static void gather_migration_blocks ( void *  cls)
static

Task that is run periodically to obtain blocks for content migration.

Parameters
clsunused

Definition at line 542 of file gnunet-service-fs_push.c.

References consider_gathering(), GNUNET_DATASTORE_get_for_replication(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GSF_dsh, MAX_MIGRATION_QUEUE, mig_size, process_migration_content(), and value_found.

Referenced by consider_gathering(), and find_content().

543 {
544  mig_task = NULL;
546  return;
547  if (NULL == GSF_dsh)
548  return;
550  "Asking datastore for content for replication (queue size: %u)\n",
551  mig_size);
554  0,
555  UINT_MAX,
557  NULL);
558  if (NULL == mig_qe)
560 }
#define MAX_MIGRATION_QUEUE
Maximum number of blocks we keep in memory for migration.
static struct GNUNET_DATASTORE_QueueEntry * mig_qe
Request to datastore for migration (or NULL).
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_SCHEDULER_Task * mig_task
ID of task that collects blocks for migration.
static void consider_gathering(void)
If the migration task is not currently running, consider (re)scheduling it with the appropriate delay...
static int value_found
Did we find anything in the datastore?
struct GNUNET_DATASTORE_Handle * GSF_dsh
Our connection to the datastore.
static void process_migration_content(void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Process content offered for migration.
static unsigned int mig_size
Size of the doubly-linked list of migration blocks.
#define GNUNET_log(kind,...)
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_get_for_replication(struct GNUNET_DATASTORE_Handle *h, unsigned int queue_priority, unsigned int max_queue_size, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
Get a random value from the datastore for content replication.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_migration_content()

static void process_migration_content ( void *  cls,
const struct GNUNET_HashCode key,
size_t  size,
const void *  data,
enum GNUNET_BLOCK_Type  type,
uint32_t  priority,
uint32_t  anonymity,
uint32_t  replication,
struct GNUNET_TIME_Absolute  expiration,
uint64_t  uid 
)
static

Process content offered for migration.

Parameters
clsclosure
keykey for the content
sizenumber of bytes in data
datacontent stored
typetype of the content
prioritypriority of the content
anonymityanonymity-level for the content
replicationreplication-level for the content
expirationexpiration time for the content
uidunique identifier for the datum; maybe 0 if no unique identifier is available

Definition at line 457 of file gnunet-service-fs_push.c.

References consider_gathering(), MigrationReadyPeer::env, MigrationReadyBlock::expiration, GNUNET_BLOCK_TYPE_FS_ONDEMAND, GNUNET_CONTAINER_DLL_insert_after, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FS_handle_on_demand_block(), GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, GSF_connected_peer_get_identity2_(), key, MAX_MIGRATION_QUEUE, mig_size, MIN_MIGRATION_CONTENT_LIFETIME, MigrationReadyPeer::next, MigrationReadyPeer::peer, MigrationReadyBlock::query, MigrationReadyBlock::size, transmit_content(), MigrationReadyBlock::type, and value_found.

Referenced by gather_migration_blocks().

467 {
468  struct MigrationReadyBlock *mb;
469  struct MigrationReadyPeer *pos;
470 
471  mig_qe = NULL;
472  if (NULL == key)
473  {
475  "No content found for migration...\n");
477  return;
478  }
480  if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us <
481  MIN_MIGRATION_CONTENT_LIFETIME.rel_value_us)
482  {
483  /* content will expire soon, don't bother */
485  return;
486  }
488  {
489  if (GNUNET_OK !=
491  size,
492  data,
493  type,
494  priority,
495  anonymity,
496  replication,
497  expiration,
498  uid,
500  NULL))
502  return;
503  }
505  "Retrieved block `%s' of type %u for migration (queue size: %u/%u)\n",
506  GNUNET_h2s (key),
507  type, mig_size + 1,
509  mb = GNUNET_malloc (sizeof (struct MigrationReadyBlock) + size);
510  mb->query = *key;
511  mb->expiration = expiration;
512  mb->size = size;
513  mb->type = type;
514  GNUNET_memcpy (&mb[1], data, size);
516  mig_tail,
517  mig_tail,
518  mb);
519  mig_size++;
520  for (pos = peer_head; NULL != pos; pos = pos->next)
521  {
523  "Preparing to push best content to peer %s\n",
525  if ( (NULL == pos->env) &&
526  (GNUNET_YES == transmit_content (pos,
527  mb)) ) {
528  break; /* 'mb' was freed! */
529  }
530  }
532 }
struct GSF_ConnectedPeer * peer
Handle to peer.
#define MAX_MIGRATION_QUEUE
Maximum number of blocks we keep in memory for migration.
struct GNUNET_MQ_Envelope * env
Envelope of the currently pushed message.
static char * expiration
Credential TTL.
static struct GNUNET_DATASTORE_QueueEntry * mig_qe
Request to datastore for migration (or NULL).
struct GNUNET_TIME_Absolute expiration
When does this block expire?
static unsigned int replication
Information about a peer waiting for migratable data.
static int transmit_content(struct MigrationReadyPeer *mrp, struct MigrationReadyBlock *block)
Send the given block to the given peer.
enum GNUNET_BLOCK_Type type
Type of the block.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct MigrationReadyBlock * mig_head
Head of linked list of blocks that can be migrated.
Block that is ready for migration to other peers.
static struct MigrationReadyBlock * mig_tail
Tail of linked list of blocks that can be migrated.
Type of a block representing a block to be encoded on demand from disk.
static void consider_gathering(void)
If the migration task is not currently running, consider (re)scheduling it with the appropriate delay...
#define MIN_MIGRATION_CONTENT_LIFETIME
How long must content remain valid for us to consider it for migration? If content will expire too so...
#define GNUNET_memcpy(dst, src, n)
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
static int value_found
Did we find anything in the datastore?
struct MigrationReadyPeer * next
This is a doubly-linked list.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
static void process_migration_content(void *cls, const struct GNUNET_HashCode *key, size_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid)
Process content offered for migration.
static unsigned int mig_size
Size of the doubly-linked list of migration blocks.
const struct GNUNET_PeerIdentity * GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp)
Obtain the identity of a connected peer.
#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
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
static unsigned int anonymity
struct GNUNET_HashCode query
Query for the block.
int GNUNET_FS_handle_on_demand_block(const struct GNUNET_HashCode *key, uint32_t size, const void *data, enum GNUNET_BLOCK_Type type, uint32_t priority, uint32_t anonymity, uint32_t replication, struct GNUNET_TIME_Absolute expiration, uint64_t uid, GNUNET_DATASTORE_DatumProcessor cont, void *cont_cls)
We&#39;ve received an on-demand encoded block from the datastore.
uint32_t data
The data value.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static struct MigrationReadyPeer * peer_head
Head of linked list of peers.
size_t size
Size of the block.
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_push_start_()

void GSF_push_start_ ( struct GSF_ConnectedPeer peer)

A peer connected to us.

A peer connected to us or we are now again allowed to push content.

Start pushing content to this peer.

Parameters
peerhandle for the peer that connected

Definition at line 570 of file gnunet-service-fs_push.c.

References enabled, find_content(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_YES, GSF_connected_peer_get_identity2_(), MigrationReadyPeer::next, peer, and MigrationReadyPeer::peer.

Referenced by peer_respect_cb(), and revive_migration().

571 {
572  struct MigrationReadyPeer *mrp;
573 
574  if (GNUNET_YES != enabled)
575  return;
576  for (mrp = peer_head; NULL != mrp; mrp = mrp->next)
577  if (mrp->peer == peer)
578  break;
579  if (NULL != mrp)
580  {
581  /* same peer added twice, must not happen */
582  GNUNET_break (0);
583  return;
584  }
585 
587  "Adding peer %s to list for pushing\n",
589 
590  mrp = GNUNET_new (struct MigrationReadyPeer);
591  mrp->peer = peer;
592  find_content (mrp);
594  peer_tail,
595  mrp);
596 }
struct GSF_ConnectedPeer * peer
Handle to peer.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
static struct MigrationReadyPeer * peer_tail
Tail of linked list of peers.
Information about a peer waiting for migratable data.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int enabled
Is this module enabled?
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MigrationReadyPeer * next
This is a doubly-linked list.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
const struct GNUNET_PeerIdentity * GSF_connected_peer_get_identity2_(const struct GSF_ConnectedPeer *cp)
Obtain the identity of a connected peer.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
static void find_content(void *cls)
Find content for migration to this peer.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static struct MigrationReadyPeer * peer_head
Head of linked list of peers.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_push_stop_()

void GSF_push_stop_ ( struct GSF_ConnectedPeer peer)

A peer disconnected from us.

A peer disconnected from us or asked us to stop pushing content for a while.

Stop pushing content to this peer.

Parameters
peerhandle for the peer that disconnected

Definition at line 606 of file gnunet-service-fs_push.c.

References MigrationReadyPeer::env, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_send_cancel(), MigrationReadyPeer::next, and MigrationReadyPeer::peer.

Referenced by GSF_peer_disconnect_handler(), and handle_p2p_migration_stop().

607 {
608  struct MigrationReadyPeer *pos;
609 
610  for (pos = peer_head; NULL != pos; pos = pos->next)
611  if (pos->peer == peer)
612  break;
613  if (NULL == pos)
614  return;
615  if (NULL != pos->env)
616  GNUNET_MQ_send_cancel (pos->env);
618  peer_tail,
619  pos);
620  GNUNET_free (pos);
621 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GSF_ConnectedPeer * peer
Handle to peer.
struct GNUNET_MQ_Envelope * env
Envelope of the currently pushed message.
static struct MigrationReadyPeer * peer_tail
Tail of linked list of peers.
Information about a peer waiting for migratable data.
struct MigrationReadyPeer * next
This is a doubly-linked list.
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:916
static struct MigrationReadyPeer * peer_head
Head of linked list of peers.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_push_init_()

void GSF_push_init_ ( void  )

Setup the module.

Definition at line 628 of file gnunet-service-fs_push.c.

References _, consider_gathering(), enabled, GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log_config_invalid(), GNUNET_OK, GNUNET_YES, GSF_cfg, and min_migration_delay.

Referenced by run().

629 {
630  enabled =
632  "FS",
633  "CONTENT_PUSHING");
634  if (GNUNET_YES != enabled)
635  return;
636 
637  if (GNUNET_OK !=
639  "fs",
640  "MIN_MIGRATION_DELAY",
642  {
644  "fs",
645  "MIN_MIGRATION_DELAY",
646  _("time required, content pushing disabled"));
647  return;
648  }
650 }
int GNUNET_CONFIGURATION_get_value_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
static int enabled
Is this module enabled?
static struct GNUNET_TIME_Relative min_migration_delay
What is the maximum frequency at which we are allowed to poll the datastore for migration content...
const struct GNUNET_CONFIGURATION_Handle * GSF_cfg
Our configuration.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void consider_gathering(void)
If the migration task is not currently running, consider (re)scheduling it with the appropriate delay...
#define GNUNET_YES
Definition: gnunet_common.h:80
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSF_push_done_()

void GSF_push_done_ ( void  )

Shutdown the module.

Definition at line 657 of file gnunet-service-fs_push.c.

References delete_migration_block(), GNUNET_assert, GNUNET_DATASTORE_cancel(), GNUNET_SCHEDULER_cancel(), and mig_size.

Referenced by shutdown_task().

658 {
659  if (NULL != mig_task)
660  {
662  mig_task = NULL;
663  }
664  if (NULL != mig_qe)
665  {
667  mig_qe = NULL;
668  }
669  while (NULL != mig_head)
671  GNUNET_assert (0 == mig_size);
672 }
static struct GNUNET_DATASTORE_QueueEntry * mig_qe
Request to datastore for migration (or NULL).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static struct MigrationReadyBlock * mig_head
Head of linked list of blocks that can be migrated.
static struct GNUNET_SCHEDULER_Task * mig_task
ID of task that collects blocks for migration.
static void delete_migration_block(struct MigrationReadyBlock *mb)
Delete the given migration block.
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
static unsigned int mig_size
Size of the doubly-linked list of migration blocks.
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:

Variable Documentation

◆ mig_head

struct MigrationReadyBlock* mig_head
static

Head of linked list of blocks that can be migrated.

Definition at line 134 of file gnunet-service-fs_push.c.

Referenced by find_content().

◆ mig_tail

struct MigrationReadyBlock* mig_tail
static

Tail of linked list of blocks that can be migrated.

Definition at line 139 of file gnunet-service-fs_push.c.

◆ peer_head

struct MigrationReadyPeer* peer_head
static

Head of linked list of peers.

Definition at line 144 of file gnunet-service-fs_push.c.

◆ peer_tail

struct MigrationReadyPeer* peer_tail
static

Tail of linked list of peers.

Definition at line 149 of file gnunet-service-fs_push.c.

◆ mig_qe

struct GNUNET_DATASTORE_QueueEntry* mig_qe
static

Request to datastore for migration (or NULL).

Definition at line 154 of file gnunet-service-fs_push.c.

◆ mig_task

struct GNUNET_SCHEDULER_Task* mig_task
static

ID of task that collects blocks for migration.

Definition at line 159 of file gnunet-service-fs_push.c.

◆ min_migration_delay

struct GNUNET_TIME_Relative min_migration_delay
static

What is the maximum frequency at which we are allowed to poll the datastore for migration content?

Definition at line 165 of file gnunet-service-fs_push.c.

Referenced by consider_gathering(), and GSF_push_init_().

◆ mig_size

unsigned int mig_size
static

Size of the doubly-linked list of migration blocks.

Definition at line 170 of file gnunet-service-fs_push.c.

Referenced by consider_gathering(), delete_migration_block(), find_content(), gather_migration_blocks(), GSF_push_done_(), and process_migration_content().

◆ enabled

int enabled
static

Is this module enabled?

Definition at line 175 of file gnunet-service-fs_push.c.

Referenced by GSF_push_init_(), and GSF_push_start_().

◆ value_found

int value_found
static

Did we find anything in the datastore?

Definition at line 180 of file gnunet-service-fs_push.c.

Referenced by consider_gathering(), gather_migration_blocks(), and process_migration_content().