summaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_put.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/gnunet-service-fs_put.c')
-rw-r--r--src/fs/gnunet-service-fs_put.c170
1 files changed, 86 insertions, 84 deletions
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c
index deba91a0c..335496119 100644
--- a/src/fs/gnunet-service-fs_put.c
+++ b/src/fs/gnunet-service-fs_put.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * How often do we at most PUT content into the DHT? 32 * How often do we at most PUT content into the DHT?
33 */ 33 */
34#define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 34#define MAX_DHT_PUT_FREQ GNUNET_TIME_relative_multiply ( \
35 GNUNET_TIME_UNIT_SECONDS, 5)
35 36
36/** 37/**
37 * How many replicas do we try to create per PUT? 38 * How many replicas do we try to create per PUT?
@@ -42,7 +43,8 @@
42/** 43/**
43 * Context for each zero-anonymity iterator. 44 * Context for each zero-anonymity iterator.
44 */ 45 */
45struct PutOperator { 46struct PutOperator
47{
46 /** 48 /**
47 * Request to datastore for DHT PUTs (or NULL). 49 * Request to datastore for DHT PUTs (or NULL).
48 */ 50 */
@@ -61,7 +63,7 @@ struct PutOperator {
61 /** 63 /**
62 * ID of task that collects blocks for DHT PUTs. 64 * ID of task that collects blocks for DHT PUTs.
63 */ 65 */
64 struct GNUNET_SCHEDULER_Task * dht_task; 66 struct GNUNET_SCHEDULER_Task *dht_task;
65 67
66 /** 68 /**
67 * How many entires with zero anonymity of our type do we currently 69 * How many entires with zero anonymity of our type do we currently
@@ -98,7 +100,7 @@ static struct PutOperator operators[] = {
98 * @param tc scheduler context (unused) 100 * @param tc scheduler context (unused)
99 */ 101 */
100static void 102static void
101gather_dht_put_blocks(void *cls); 103gather_dht_put_blocks (void *cls);
102 104
103 105
104/** 106/**
@@ -107,25 +109,25 @@ gather_dht_put_blocks(void *cls);
107 * @param po put operator to schedule 109 * @param po put operator to schedule
108 */ 110 */
109static void 111static void
110schedule_next_put(struct PutOperator *po) 112schedule_next_put (struct PutOperator *po)
111{ 113{
112 struct GNUNET_TIME_Relative delay; 114 struct GNUNET_TIME_Relative delay;
113 115
114 if (po->zero_anonymity_count_estimate > 0) 116 if (po->zero_anonymity_count_estimate > 0)
115 { 117 {
116 delay = 118 delay =
117 GNUNET_TIME_relative_divide(GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, 119 GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY,
118 po->zero_anonymity_count_estimate); 120 po->zero_anonymity_count_estimate);
119 delay = GNUNET_TIME_relative_min(delay, MAX_DHT_PUT_FREQ); 121 delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ);
120 } 122 }
121 else 123 else
122 { 124 {
123 /* if we have NO zero-anonymity content yet, wait 5 minutes for some to 125 /* if we have NO zero-anonymity content yet, wait 5 minutes for some to
124 * (hopefully) appear */ 126 * (hopefully) appear */
125 delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5); 127 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5);
126 } 128 }
127 po->dht_task = 129 po->dht_task =
128 GNUNET_SCHEDULER_add_delayed(delay, &gather_dht_put_blocks, po); 130 GNUNET_SCHEDULER_add_delayed (delay, &gather_dht_put_blocks, po);
129} 131}
130 132
131 133
@@ -135,12 +137,12 @@ schedule_next_put(struct PutOperator *po)
135 * @param cls type of blocks to gather 137 * @param cls type of blocks to gather
136 */ 138 */
137static void 139static void
138delay_dht_put_blocks(void *cls) 140delay_dht_put_blocks (void *cls)
139{ 141{
140 struct PutOperator *po = cls; 142 struct PutOperator *po = cls;
141 143
142 po->dht_put = NULL; 144 po->dht_put = NULL;
143 schedule_next_put(po); 145 schedule_next_put (po);
144} 146}
145 147
146 148
@@ -150,12 +152,12 @@ delay_dht_put_blocks(void *cls)
150 * @param cls type of blocks to gather 152 * @param cls type of blocks to gather
151 */ 153 */
152static void 154static void
153delay_dht_put_task(void *cls) 155delay_dht_put_task (void *cls)
154{ 156{
155 struct PutOperator *po = cls; 157 struct PutOperator *po = cls;
156 158
157 po->dht_task = NULL; 159 po->dht_task = NULL;
158 schedule_next_put(po); 160 schedule_next_put (po);
159} 161}
160 162
161 163
@@ -175,45 +177,45 @@ delay_dht_put_task(void *cls)
175 * maybe 0 if no unique identifier is available 177 * maybe 0 if no unique identifier is available
176 */ 178 */
177static void 179static void
178process_dht_put_content(void *cls, 180process_dht_put_content (void *cls,
179 const struct GNUNET_HashCode * key, 181 const struct GNUNET_HashCode *key,
180 size_t size, 182 size_t size,
181 const void *data, 183 const void *data,
182 enum GNUNET_BLOCK_Type type, 184 enum GNUNET_BLOCK_Type type,
183 uint32_t priority, 185 uint32_t priority,
184 uint32_t anonymity, 186 uint32_t anonymity,
185 uint32_t replication, 187 uint32_t replication,
186 struct GNUNET_TIME_Absolute expiration, 188 struct GNUNET_TIME_Absolute expiration,
187 uint64_t uid) 189 uint64_t uid)
188{ 190{
189 struct PutOperator *po = cls; 191 struct PutOperator *po = cls;
190 192
191 po->dht_qe = NULL; 193 po->dht_qe = NULL;
192 if (key == NULL) 194 if (key == NULL)
193 { 195 {
194 po->zero_anonymity_count_estimate = po->result_count; 196 po->zero_anonymity_count_estimate = po->result_count;
195 po->result_count = 0; 197 po->result_count = 0;
196 po->next_uid = 0; 198 po->next_uid = 0;
197 po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); 199 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po);
198 return; 200 return;
199 } 201 }
200 po->result_count++; 202 po->result_count++;
201 po->next_uid = uid + 1; 203 po->next_uid = uid + 1;
202 po->zero_anonymity_count_estimate = 204 po->zero_anonymity_count_estimate =
203 GNUNET_MAX(po->result_count, po->zero_anonymity_count_estimate); 205 GNUNET_MAX (po->result_count, po->zero_anonymity_count_estimate);
204 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
205 "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s(key), 207 "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key),
206 type); 208 type);
207 po->dht_put = GNUNET_DHT_put(GSF_dht, 209 po->dht_put = GNUNET_DHT_put (GSF_dht,
208 key, 210 key,
209 DEFAULT_PUT_REPLICATION, 211 DEFAULT_PUT_REPLICATION,
210 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 212 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
211 type, 213 type,
212 size, 214 size,
213 data, 215 data,
214 expiration, 216 expiration,
215 &delay_dht_put_blocks, 217 &delay_dht_put_blocks,
216 po); 218 po);
217} 219}
218 220
219 221
@@ -223,21 +225,21 @@ process_dht_put_content(void *cls,
223 * @param cls type of blocks to gather 225 * @param cls type of blocks to gather
224 */ 226 */
225static void 227static void
226gather_dht_put_blocks(void *cls) 228gather_dht_put_blocks (void *cls)
227{ 229{
228 struct PutOperator *po = cls; 230 struct PutOperator *po = cls;
229 231
230 po->dht_task = NULL; 232 po->dht_task = NULL;
231 po->dht_qe = 233 po->dht_qe =
232 GNUNET_DATASTORE_get_zero_anonymity(GSF_dsh, 234 GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh,
233 po->next_uid, 235 po->next_uid,
234 0, 236 0,
235 UINT_MAX, 237 UINT_MAX,
236 po->dht_put_type, 238 po->dht_put_type,
237 &process_dht_put_content, 239 &process_dht_put_content,
238 po); 240 po);
239 if (NULL == po->dht_qe) 241 if (NULL == po->dht_qe)
240 po->dht_task = GNUNET_SCHEDULER_add_now(&delay_dht_put_task, po); 242 po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po);
241} 243}
242 244
243 245
@@ -245,17 +247,17 @@ gather_dht_put_blocks(void *cls)
245 * Setup the module. 247 * Setup the module.
246 */ 248 */
247void 249void
248GSF_put_init_() 250GSF_put_init_ ()
249{ 251{
250 unsigned int i; 252 unsigned int i;
251 253
252 i = 0; 254 i = 0;
253 while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) 255 while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY)
254 { 256 {
255 operators[i].dht_task = 257 operators[i].dht_task =
256 GNUNET_SCHEDULER_add_now(&gather_dht_put_blocks, &operators[i]); 258 GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]);
257 i++; 259 i++;
258 } 260 }
259} 261}
260 262
261 263
@@ -263,31 +265,31 @@ GSF_put_init_()
263 * Shutdown the module. 265 * Shutdown the module.
264 */ 266 */
265void 267void
266GSF_put_done_() 268GSF_put_done_ ()
267{ 269{
268 struct PutOperator *po; 270 struct PutOperator *po;
269 unsigned int i; 271 unsigned int i;
270 272
271 i = 0; 273 i = 0;
272 while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) 274 while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY)
275 {
276 if (NULL != po->dht_task)
277 {
278 GNUNET_SCHEDULER_cancel (po->dht_task);
279 po->dht_task = NULL;
280 }
281 if (NULL != po->dht_put)
282 {
283 GNUNET_DHT_put_cancel (po->dht_put);
284 po->dht_put = NULL;
285 }
286 if (NULL != po->dht_qe)
273 { 287 {
274 if (NULL != po->dht_task) 288 GNUNET_DATASTORE_cancel (po->dht_qe);
275 { 289 po->dht_qe = NULL;
276 GNUNET_SCHEDULER_cancel(po->dht_task);
277 po->dht_task = NULL;
278 }
279 if (NULL != po->dht_put)
280 {
281 GNUNET_DHT_put_cancel(po->dht_put);
282 po->dht_put = NULL;
283 }
284 if (NULL != po->dht_qe)
285 {
286 GNUNET_DATASTORE_cancel(po->dht_qe);
287 po->dht_qe = NULL;
288 }
289 i++;
290 } 290 }
291 i++;
292 }
291} 293}
292 294
293/* end of gnunet-service-fs_put.c */ 295/* end of gnunet-service-fs_put.c */