GNUnet  0.10.x
gnunet-service-fs_put.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
26 #include "platform.h"
27 #include "gnunet-service-fs.h"
28 #include "gnunet-service-fs_put.h"
29 
30 
34 #define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
35 
39 #define DEFAULT_PUT_REPLICATION 5
40 
41 
45 struct PutOperator {
50 
55 
60 
65 
71 
75  uint64_t result_count;
76 
80  uint64_t next_uid;
81 };
82 
83 
88 static struct PutOperator operators[] = {
89  { NULL, GNUNET_BLOCK_TYPE_FS_UBLOCK, 0, 0, 0 },
90  { NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 }
91 };
92 
93 
100 static void
101 gather_dht_put_blocks(void *cls);
102 
103 
109 static void
111 {
112  struct GNUNET_TIME_Relative delay;
113 
114  if (po->zero_anonymity_count_estimate > 0)
115  {
116  delay =
120  }
121  else
122  {
123  /* if we have NO zero-anonymity content yet, wait 5 minutes for some to
124  * (hopefully) appear */
126  }
127  po->dht_task =
129 }
130 
131 
137 static void
139 {
140  struct PutOperator *po = cls;
141 
142  po->dht_put = NULL;
143  schedule_next_put(po);
144 }
145 
146 
152 static void
154 {
155  struct PutOperator *po = cls;
156 
157  po->dht_task = NULL;
158  schedule_next_put(po);
159 }
160 
161 
177 static void
179  const struct GNUNET_HashCode * key,
180  size_t size,
181  const void *data,
182  enum GNUNET_BLOCK_Type type,
183  uint32_t priority,
184  uint32_t anonymity,
185  uint32_t replication,
187  uint64_t uid)
188 {
189  struct PutOperator *po = cls;
190 
191  po->dht_qe = NULL;
192  if (key == NULL)
193  {
195  po->result_count = 0;
196  po->next_uid = 0;
198  return;
199  }
200  po->result_count++;
201  po->next_uid = uid + 1;
205  "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s(key),
206  type);
208  key,
211  type,
212  size,
213  data,
214  expiration,
216  po);
217 }
218 
219 
225 static void
227 {
228  struct PutOperator *po = cls;
229 
230  po->dht_task = NULL;
231  po->dht_qe =
233  po->next_uid,
234  0,
235  UINT_MAX,
236  po->dht_put_type,
238  po);
239  if (NULL == po->dht_qe)
241 }
242 
243 
247 void
249 {
250  unsigned int i;
251 
252  i = 0;
253  while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY)
254  {
255  operators[i].dht_task =
257  i++;
258  }
259 }
260 
261 
265 void
267 {
268  struct PutOperator *po;
269  unsigned int i;
270 
271  i = 0;
272  while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY)
273  {
274  if (NULL != po->dht_task)
275  {
277  po->dht_task = NULL;
278  }
279  if (NULL != po->dht_put)
280  {
282  po->dht_put = NULL;
283  }
284  if (NULL != po->dht_qe)
285  {
287  po->dht_qe = NULL;
288  }
289  i++;
290  }
291 }
292 
293 /* end of gnunet-service-fs_put.c */
uint64_t next_uid
Next UID to request when iterating the database.
static char * expiration
Credential TTL.
void GNUNET_DHT_put_cancel(struct GNUNET_DHT_PutHandle *ph)
Cancels a DHT PUT operation.
Definition: dht_api.c:1030
Any type of block, used as a wildcard when searching.
enum GNUNET_BLOCK_Type dht_put_type
Type we request from the datastore.
GNUNET_BLOCK_Type
Blocks in the datastore and the datacache must have a unique type.
void GSF_put_done_()
Shutdown the module.
#define DEFAULT_PUT_REPLICATION
How many replicas do we try to create per PUT?
#define GNUNET_TIME_UNIT_MINUTES
One minute.
static void gather_dht_put_blocks(void *cls)
Task that is run periodically to obtain blocks for DHT PUTs.
static unsigned int replication
struct GNUNET_DHT_Handle * GSF_dht
Handle for DHT operations.
shared data structures of gnunet-service-fs.c
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_SCHEDULER_Task * dht_task
ID of task that collects blocks for DHT PUTs.
#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:1237
Entry in our priority queue.
Definition: datastore_api.c:96
static void schedule_next_put(struct PutOperator *po)
Calculate when to run the next PUT operation and schedule it.
static void delay_dht_put_task(void *cls)
Task that is run periodically to obtain blocks for DHT PUTs.
#define GNUNET_MAX(a, b)
Definition: gnunet_common.h:82
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:1264
struct GNUNET_DATASTORE_QueueEntry * dht_qe
Request to datastore for DHT PUTs (or NULL).
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:440
support for putting content into the DHT
uint64_t result_count
Count of results received from the database.
Context for each zero-anonymity iterator.
Type of a block representing any type of search result (universal).
A 512-bit hashcode.
struct GNUNET_DATASTORE_Handle * GSF_dsh
Our connection to the datastore.
uint64_t zero_anonymity_count_estimate
How many entires with zero anonymity of our type do we currently estimate to have in the database...
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:272
struct GNUNET_HashCode key
The key used in the DHT.
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:961
static unsigned int size
Size of the "table".
Definition: peer.c:66
struct GNUNET_DHT_PutHandle * dht_put
Handle to PUT operation.
#define MAX_DHT_PUT_FREQ
How often do we at most PUT content into the DHT?
static struct PutOperator operators[]
ANY-terminated list of our operators (one per type of block that we&#39;re putting into the DHT)...
void GNUNET_DATASTORE_cancel(struct GNUNET_DATASTORE_QueueEntry *qe)
Cancel a datastore operation.
Handle to a PUT request.
Definition: dht_api.c:43
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:131
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
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
Time for absolute times used by GNUnet, in microseconds.
static unsigned int anonymity
static void delay_dht_put_blocks(void *cls)
Continuation called after DHT PUT operation has finished.
uint32_t data
The data value.
Each peer along the way should look at &#39;enc&#39; (otherwise only the k-peers closest to the key should lo...
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.
void GSF_put_init_()
Setup the module.
Time for relative time used by GNUnet, in microseconds.
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956