diff options
Diffstat (limited to 'src/fs/gnunet-service-fs_put.c')
-rw-r--r-- | src/fs/gnunet-service-fs_put.c | 149 |
1 files changed, 70 insertions, 79 deletions
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index b15207ce8..e67bf0c04 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c | |||
@@ -54,7 +54,7 @@ struct PutOperator | |||
54 | * ID of task that collects blocks for DHT PUTs. | 54 | * ID of task that collects blocks for DHT PUTs. |
55 | */ | 55 | */ |
56 | GNUNET_SCHEDULER_TaskIdentifier dht_task; | 56 | GNUNET_SCHEDULER_TaskIdentifier dht_task; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * How many entires with zero anonymity of our type do we currently | 59 | * How many entires with zero anonymity of our type do we currently |
60 | * estimate to have in the database? | 60 | * estimate to have in the database? |
@@ -72,13 +72,12 @@ struct PutOperator | |||
72 | * ANY-terminated list of our operators (one per type | 72 | * ANY-terminated list of our operators (one per type |
73 | * of block that we're putting into the DHT). | 73 | * of block that we're putting into the DHT). |
74 | */ | 74 | */ |
75 | static struct PutOperator operators[] = | 75 | static struct PutOperator operators[] = { |
76 | { | 76 | {NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0}, |
77 | { NULL, GNUNET_BLOCK_TYPE_FS_KBLOCK, 0, 0, 0 }, | 77 | {NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0}, |
78 | { NULL, GNUNET_BLOCK_TYPE_FS_SBLOCK, 0, 0, 0 }, | 78 | {NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0}, |
79 | { NULL, GNUNET_BLOCK_TYPE_FS_NBLOCK, 0, 0, 0 }, | 79 | {NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0} |
80 | { NULL, GNUNET_BLOCK_TYPE_ANY, 0, 0, 0 } | 80 | }; |
81 | }; | ||
82 | 81 | ||
83 | 82 | ||
84 | /** | 83 | /** |
@@ -89,7 +88,7 @@ static struct PutOperator operators[] = | |||
89 | */ | 88 | */ |
90 | static void | 89 | static void |
91 | gather_dht_put_blocks (void *cls, | 90 | gather_dht_put_blocks (void *cls, |
92 | const struct GNUNET_SCHEDULER_TaskContext *tc); | 91 | const struct GNUNET_SCHEDULER_TaskContext *tc); |
93 | 92 | ||
94 | 93 | ||
95 | /** | 94 | /** |
@@ -99,8 +98,7 @@ gather_dht_put_blocks (void *cls, | |||
99 | * @param tc scheduler context (unused) | 98 | * @param tc scheduler context (unused) |
100 | */ | 99 | */ |
101 | static void | 100 | static void |
102 | delay_dht_put_blocks (void *cls, | 101 | delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
103 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
104 | { | 102 | { |
105 | struct PutOperator *po = cls; | 103 | struct PutOperator *po = cls; |
106 | struct GNUNET_TIME_Relative delay; | 104 | struct GNUNET_TIME_Relative delay; |
@@ -109,21 +107,19 @@ delay_dht_put_blocks (void *cls, | |||
109 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 107 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
110 | return; | 108 | return; |
111 | if (po->zero_anonymity_count_estimate > 0) | 109 | if (po->zero_anonymity_count_estimate > 0) |
112 | { | 110 | { |
113 | delay = GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, | 111 | delay = GNUNET_TIME_relative_divide (GNUNET_DHT_DEFAULT_REPUBLISH_FREQUENCY, |
114 | po->zero_anonymity_count_estimate); | 112 | po->zero_anonymity_count_estimate); |
115 | delay = GNUNET_TIME_relative_min (delay, | 113 | delay = GNUNET_TIME_relative_min (delay, MAX_DHT_PUT_FREQ); |
116 | MAX_DHT_PUT_FREQ); | 114 | } |
117 | } | ||
118 | else | 115 | else |
119 | { | 116 | { |
120 | /* if we have NO zero-anonymity content yet, wait 5 minutes for some to | 117 | /* if we have NO zero-anonymity content yet, wait 5 minutes for some to |
121 | (hopefully) appear */ | 118 | * (hopefully) appear */ |
122 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); | 119 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5); |
123 | } | 120 | } |
124 | po->dht_task = GNUNET_SCHEDULER_add_delayed (delay, | 121 | po->dht_task = GNUNET_SCHEDULER_add_delayed (delay, |
125 | &gather_dht_put_blocks, | 122 | &gather_dht_put_blocks, po); |
126 | po); | ||
127 | } | 123 | } |
128 | 124 | ||
129 | 125 | ||
@@ -143,45 +139,40 @@ delay_dht_put_blocks (void *cls, | |||
143 | */ | 139 | */ |
144 | static void | 140 | static void |
145 | process_dht_put_content (void *cls, | 141 | process_dht_put_content (void *cls, |
146 | const GNUNET_HashCode * key, | 142 | const GNUNET_HashCode * key, |
147 | size_t size, | 143 | size_t size, |
148 | const void *data, | 144 | const void *data, |
149 | enum GNUNET_BLOCK_Type type, | 145 | enum GNUNET_BLOCK_Type type, |
150 | uint32_t priority, | 146 | uint32_t priority, |
151 | uint32_t anonymity, | 147 | uint32_t anonymity, |
152 | struct GNUNET_TIME_Absolute | 148 | struct GNUNET_TIME_Absolute expiration, uint64_t uid) |
153 | expiration, uint64_t uid) | 149 | { |
154 | { | ||
155 | struct PutOperator *po = cls; | 150 | struct PutOperator *po = cls; |
156 | 151 | ||
157 | po->dht_qe = NULL; | 152 | po->dht_qe = NULL; |
158 | if (key == NULL) | 153 | if (key == NULL) |
159 | { | 154 | { |
160 | po->zero_anonymity_count_estimate = po->current_offset - 1; | 155 | po->zero_anonymity_count_estimate = po->current_offset - 1; |
161 | po->current_offset = 0; | 156 | po->current_offset = 0; |
162 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, | 157 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po); |
163 | po); | 158 | return; |
164 | return; | 159 | } |
165 | } | ||
166 | po->zero_anonymity_count_estimate = GNUNET_MAX (po->current_offset, | 160 | po->zero_anonymity_count_estimate = GNUNET_MAX (po->current_offset, |
167 | po->zero_anonymity_count_estimate); | 161 | po->zero_anonymity_count_estimate); |
168 | #if DEBUG_FS | 162 | #if DEBUG_FS |
169 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 163 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
170 | "Retrieved block `%s' of type %u for DHT PUT\n", | 164 | "Retrieved block `%s' of type %u for DHT PUT\n", |
171 | GNUNET_h2s (key), | 165 | GNUNET_h2s (key), type); |
172 | type); | ||
173 | #endif | 166 | #endif |
174 | GNUNET_DHT_put (GSF_dht, | 167 | GNUNET_DHT_put (GSF_dht, |
175 | key, | 168 | key, |
176 | DEFAULT_PUT_REPLICATION, | 169 | DEFAULT_PUT_REPLICATION, |
177 | GNUNET_DHT_RO_NONE, | 170 | GNUNET_DHT_RO_NONE, |
178 | type, | 171 | type, |
179 | size, | 172 | size, |
180 | data, | 173 | data, |
181 | expiration, | 174 | expiration, |
182 | GNUNET_TIME_UNIT_FOREVER_REL, | 175 | GNUNET_TIME_UNIT_FOREVER_REL, &delay_dht_put_blocks, po); |
183 | &delay_dht_put_blocks, | ||
184 | po); | ||
185 | } | 176 | } |
186 | 177 | ||
187 | 178 | ||
@@ -192,23 +183,22 @@ process_dht_put_content (void *cls, | |||
192 | * @param tc scheduler context (unused) | 183 | * @param tc scheduler context (unused) |
193 | */ | 184 | */ |
194 | static void | 185 | static void |
195 | gather_dht_put_blocks (void *cls, | 186 | gather_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
196 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
197 | { | 187 | { |
198 | struct PutOperator *po = cls; | 188 | struct PutOperator *po = cls; |
199 | 189 | ||
200 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; | 190 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; |
201 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 191 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
202 | return; | 192 | return; |
203 | po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, | 193 | po->dht_qe = GNUNET_DATASTORE_get_zero_anonymity (GSF_dsh, |
204 | po->current_offset++, | 194 | po->current_offset++, |
205 | 0, UINT_MAX, | 195 | 0, UINT_MAX, |
206 | GNUNET_TIME_UNIT_FOREVER_REL, | 196 | GNUNET_TIME_UNIT_FOREVER_REL, |
207 | po->dht_put_type, | 197 | po->dht_put_type, |
208 | &process_dht_put_content, po); | 198 | &process_dht_put_content, |
199 | po); | ||
209 | if (NULL == po->dht_qe) | 200 | if (NULL == po->dht_qe) |
210 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, | 201 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po); |
211 | po); | ||
212 | } | 202 | } |
213 | 203 | ||
214 | 204 | ||
@@ -222,10 +212,11 @@ GSF_put_init_ () | |||
222 | 212 | ||
223 | i = 0; | 213 | i = 0; |
224 | while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) | 214 | while (operators[i].dht_put_type != GNUNET_BLOCK_TYPE_ANY) |
225 | { | 215 | { |
226 | operators[i].dht_task = GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]); | 216 | operators[i].dht_task = |
227 | i++; | 217 | GNUNET_SCHEDULER_add_now (&gather_dht_put_blocks, &operators[i]); |
228 | } | 218 | i++; |
219 | } | ||
229 | } | 220 | } |
230 | 221 | ||
231 | 222 | ||
@@ -240,19 +231,19 @@ GSF_put_done_ () | |||
240 | 231 | ||
241 | i = 0; | 232 | i = 0; |
242 | while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) | 233 | while ((po = &operators[i])->dht_put_type != GNUNET_BLOCK_TYPE_ANY) |
234 | { | ||
235 | if (GNUNET_SCHEDULER_NO_TASK != po->dht_task) | ||
236 | { | ||
237 | GNUNET_SCHEDULER_cancel (po->dht_task); | ||
238 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; | ||
239 | } | ||
240 | if (NULL != po->dht_qe) | ||
243 | { | 241 | { |
244 | if (GNUNET_SCHEDULER_NO_TASK != po->dht_task) | 242 | GNUNET_DATASTORE_cancel (po->dht_qe); |
245 | { | 243 | po->dht_qe = NULL; |
246 | GNUNET_SCHEDULER_cancel (po->dht_task); | ||
247 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; | ||
248 | } | ||
249 | if (NULL != po->dht_qe) | ||
250 | { | ||
251 | GNUNET_DATASTORE_cancel (po->dht_qe); | ||
252 | po->dht_qe = NULL; | ||
253 | } | ||
254 | i++; | ||
255 | } | 244 | } |
245 | i++; | ||
246 | } | ||
256 | } | 247 | } |
257 | 248 | ||
258 | /* end of gnunet-service-fs_put.c */ | 249 | /* end of gnunet-service-fs_put.c */ |