GNUnet  0.20.0
gnunet-service-fs_put.c File Reference

API to PUT zero-anonymity index data from our datastore into the DHT. More...

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

Go to the source code of this file.

Data Structures

struct  PutOperator
 Context for each zero-anonymity iterator. More...
 

Macros

#define MAX_DHT_PUT_FREQ
 How often do we at most PUT content into the DHT? More...
 
#define DEFAULT_PUT_REPLICATION   5
 How many replicas do we try to create per PUT? More...
 

Functions

static void gather_dht_put_blocks (void *cls)
 Task that is run periodically to obtain blocks for DHT PUTs. More...
 
static void schedule_next_put (struct PutOperator *po)
 Calculate when to run the next PUT operation and schedule it. More...
 
static void delay_dht_put_blocks (void *cls)
 Continuation called after DHT PUT operation has finished. More...
 
static void delay_dht_put_task (void *cls)
 Task that is run periodically to obtain blocks for DHT PUTs. More...
 
static void process_dht_put_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)
 Store content in DHT. More...
 
void GSF_put_init_ ()
 Setup the module. More...
 
void GSF_put_done_ ()
 Shutdown the module. More...
 

Variables

static struct PutOperator operators []
 ANY-terminated list of our operators (one per type of block that we're putting into the DHT). More...
 

Detailed Description

API to PUT zero-anonymity index data from our datastore into the DHT.

Author
Christian Grothoff

Definition in file gnunet-service-fs_put.c.

Macro Definition Documentation

◆ MAX_DHT_PUT_FREQ

#define MAX_DHT_PUT_FREQ
Value:
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:484

How often do we at most PUT content into the DHT?

Definition at line 34 of file gnunet-service-fs_put.c.

◆ DEFAULT_PUT_REPLICATION

#define DEFAULT_PUT_REPLICATION   5

How many replicas do we try to create per PUT?

Definition at line 40 of file gnunet-service-fs_put.c.

Function Documentation

◆ gather_dht_put_blocks()

static void gather_dht_put_blocks ( void *  cls)
static

Task that is run periodically to obtain blocks for DHT PUTs.

Parameters
clstype of blocks to gather

Definition at line 222 of file gnunet-service-fs_put.c.

223 {
224  struct PutOperator *po = cls;
225 
226  po->dht_task = NULL;
227  po->dht_qe =
229  po->next_uid,
230  0,
231  UINT_MAX,
232  po->dht_put_type,
234  po);
235  if (NULL == po->dht_qe)
237 }
struct GNUNET_DATASTORE_Handle * GSF_dsh
Our connection to the datastore.
static void delay_dht_put_task(void *cls)
Task that is run periodically to obtain blocks for DHT PUTs.
static void process_dht_put_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)
Store content in DHT.
struct GNUNET_DATASTORE_QueueEntry * GNUNET_DATASTORE_get_zero_anonymity(struct GNUNET_DATASTORE_Handle *h, uint64_t next_uid, unsigned int queue_priority, unsigned int max_queue_size, enum GNUNET_BLOCK_Type type, GNUNET_DATASTORE_DatumProcessor proc, void *proc_cls)
Get a single zero-anonymity value from the datastore.
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:1299
Context for each zero-anonymity iterator.
enum GNUNET_BLOCK_Type dht_put_type
Type we request from the datastore.
struct GNUNET_SCHEDULER_Task * dht_task
ID of task that collects blocks for DHT PUTs.
uint64_t next_uid
Next UID to request when iterating the database.
struct GNUNET_DATASTORE_QueueEntry * dht_qe
Request to datastore for DHT PUTs (or NULL).

References delay_dht_put_task(), PutOperator::dht_put_type, PutOperator::dht_qe, PutOperator::dht_task, GNUNET_DATASTORE_get_zero_anonymity(), GNUNET_SCHEDULER_add_now(), GSF_dsh, PutOperator::next_uid, and process_dht_put_content().

Referenced by GSF_put_init_(), and schedule_next_put().

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

◆ schedule_next_put()

static void schedule_next_put ( struct PutOperator po)
static

Calculate when to run the next PUT operation and schedule it.

Parameters
poput operator to schedule

Definition at line 111 of file gnunet-service-fs_put.c.

112 {
114 
115  if (po->zero_anonymity_count_estimate > 0)
116  {
117  delay =
121  }
122  else
123  {
124  /* if we have NO zero-anonymity content yet, wait 5 minutes for some to
125  * (hopefully) appear */
127  }
128  po->dht_task =
130 }
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static void gather_dht_put_blocks(void *cls)
Task that is run periodically to obtain blocks for DHT PUTs.
#define MAX_DHT_PUT_FREQ
How often do we at most PUT content into the DHT?
#define GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY
Default republication frequency for stored data in the DHT.
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:1272
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition: time.c:343
#define GNUNET_TIME_UNIT_MINUTES
One minute.
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:550
Time for relative time used by GNUnet, in microseconds.
uint64_t zero_anonymity_count_estimate
How many entries with zero anonymity of our type do we currently estimate to have in the database?

References delay, PutOperator::dht_task, gather_dht_put_blocks(), GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_min(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_UNIT_MINUTES, MAX_DHT_PUT_FREQ, and PutOperator::zero_anonymity_count_estimate.

Referenced by delay_dht_put_blocks(), and delay_dht_put_task().

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

◆ delay_dht_put_blocks()

static void delay_dht_put_blocks ( void *  cls)
static

Continuation called after DHT PUT operation has finished.

Parameters
clstype of blocks to gather

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

140 {
141  struct PutOperator *po = cls;
142 
143  po->dht_put = NULL;
144  schedule_next_put (po);
145 }
static void schedule_next_put(struct PutOperator *po)
Calculate when to run the next PUT operation and schedule it.
struct GNUNET_DHT_PutHandle * dht_put
Handle to PUT operation.

References PutOperator::dht_put, and schedule_next_put().

Referenced by process_dht_put_content().

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

◆ delay_dht_put_task()

static void delay_dht_put_task ( void *  cls)
static

Task that is run periodically to obtain blocks for DHT PUTs.

Parameters
clstype of blocks to gather

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

155 {
156  struct PutOperator *po = cls;
157 
158  po->dht_task = NULL;
159  schedule_next_put (po);
160 }

References PutOperator::dht_task, and schedule_next_put().

Referenced by gather_dht_put_blocks(), and process_dht_put_content().

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

◆ process_dht_put_content()

static void process_dht_put_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

Store content in DHT.

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 179 of file gnunet-service-fs_put.c.

189 {
190  struct PutOperator *po = cls;
191 
192  po->dht_qe = NULL;
193  if (key == NULL)
194  {
196  po->result_count = 0;
197  po->next_uid = 0;
199  return;
200  }
201  po->result_count++;
202  po->next_uid = uid + 1;
206  "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key),
207  type);
209  key,
212  type,
213  size,
214  data,
215  expiration,
217  po);
218 }
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
struct GNUNET_HashCode key
The key used in the DHT.
uint32_t data
The data value.
struct GNUNET_DHT_Handle * GSF_dht
Handle for DHT operations.
static void delay_dht_put_blocks(void *cls)
Continuation called after DHT PUT operation has finished.
#define DEFAULT_PUT_REPLICATION
How many replicas do we try to create per PUT?
struct GNUNET_DHT_PutHandle * GNUNET_DHT_put(struct GNUNET_DHT_Handle *handle, const struct GNUNET_HashCode *key, uint32_t desired_replication_level, enum GNUNET_DHT_RouteOption options, enum GNUNET_BLOCK_Type type, size_t size, const void *data, struct GNUNET_TIME_Absolute exp, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Perform a PUT operation storing data in the DHT.
Definition: dht_api.c:1090
@ GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE
Each peer along the way should process the request (otherwise only peers locally closest to the key w...
#define GNUNET_log(kind,...)
#define GNUNET_MAX(a, b)
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
static unsigned int size
Size of the "table".
Definition: peer.c:68
uint64_t result_count
Count of results received from the database.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model

References data, DEFAULT_PUT_REPLICATION, delay_dht_put_blocks(), delay_dht_put_task(), PutOperator::dht_put, PutOperator::dht_qe, PutOperator::dht_task, expiration, GNUNET_DHT_put(), GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_MAX, GNUNET_SCHEDULER_add_now(), GSF_dht, key, PutOperator::next_uid, PutOperator::result_count, size, type, and PutOperator::zero_anonymity_count_estimate.

Referenced by gather_dht_put_blocks().

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

◆ GSF_put_init_()

void GSF_put_init_ ( void  )

Setup the module.

Definition at line 244 of file gnunet-service-fs_put.c.

245 {
246  unsigned int i;
247 
248  i = 0;
249  while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY)
250  {
251  operators[i].dht_task =
253  i++;
254  }
255 }
@ GNUNET_BLOCK_TYPE_ANY
Identifier for any block.
static struct PutOperator operators[]
ANY-terminated list of our operators (one per type of block that we're putting into the DHT).

References PutOperator::dht_put_type, PutOperator::dht_task, gather_dht_put_blocks(), GNUNET_BLOCK_TYPE_ANY, GNUNET_SCHEDULER_add_now(), and operators.

Referenced by run().

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

◆ GSF_put_done_()

void GSF_put_done_ ( void  )

Shutdown the module.

Definition at line 262 of file gnunet-service-fs_put.c.

263 {
264  struct PutOperator *po;
265  unsigned int i;
266 
267  i = 0;
268  while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY)
269  {
270  if (NULL != po->dht_task)
271  {
273  po->dht_task = NULL;
274  }
275  if (NULL != po->dht_put)
276  {
278  po->dht_put = NULL;
279  }
280  if (NULL != po->dht_qe)
281  {
283  po->dht_qe = NULL;
284  }
285  i++;
286  }
287 }
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
void GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
Cancels a DHT PUT operation.
Definition: dht_api.c:1148
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975

References PutOperator::dht_put, PutOperator::dht_put_type, PutOperator::dht_qe, PutOperator::dht_task, GNUNET_BLOCK_TYPE_ANY, GNUNET_DATASTORE_cancel(), GNUNET_DHT_put_cancel(), GNUNET_SCHEDULER_cancel(), and operators.

Referenced by shutdown_task().

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

Variable Documentation

◆ operators

struct PutOperator operators[]
static
Initial value:
= {
{ NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0 },
{ NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 }
}
@ GNUNET_BLOCK_TYPE_FS_UBLOCK
Type of a block representing any type of search result (universal).

ANY-terminated list of our operators (one per type of block that we're putting into the DHT).

Definition at line 1 of file gnunet-service-fs_put.c.

Referenced by GSF_put_done_(), and GSF_put_init_().