diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-04-26 16:56:00 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-04-26 16:56:00 +0000 |
commit | 4757258de33285fed2aa318c374dcdbf586c29f0 (patch) | |
tree | 283fa337cdaa54fbb3bbf08c937fdb6467c2b5d1 /src/fs/gnunet-service-fs_put.c | |
parent | 506d42b2ba6eb104e64fd0c8889ea7233a9b96b3 (diff) | |
download | gnunet-4757258de33285fed2aa318c374dcdbf586c29f0.tar.gz gnunet-4757258de33285fed2aa318c374dcdbf586c29f0.zip |
-fixing #2277
Diffstat (limited to 'src/fs/gnunet-service-fs_put.c')
-rw-r--r-- | src/fs/gnunet-service-fs_put.c | 74 |
1 files changed, 60 insertions, 14 deletions
diff --git a/src/fs/gnunet-service-fs_put.c b/src/fs/gnunet-service-fs_put.c index 3ac67136a..463acc02d 100644 --- a/src/fs/gnunet-service-fs_put.c +++ b/src/fs/gnunet-service-fs_put.c | |||
@@ -33,6 +33,11 @@ | |||
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 (GNUNET_TIME_UNIT_SECONDS, 5) |
35 | 35 | ||
36 | /** | ||
37 | * How many replicas do we try to create per PUT? | ||
38 | */ | ||
39 | #define DEFAULT_PUT_REPLICATION 5 | ||
40 | |||
36 | 41 | ||
37 | /** | 42 | /** |
38 | * Context for each zero-anonymity iterator. | 43 | * Context for each zero-anonymity iterator. |
@@ -51,6 +56,11 @@ struct PutOperator | |||
51 | enum GNUNET_BLOCK_Type dht_put_type; | 56 | enum GNUNET_BLOCK_Type dht_put_type; |
52 | 57 | ||
53 | /** | 58 | /** |
59 | * Handle to PUT operation. | ||
60 | */ | ||
61 | struct GNUNET_DHT_PutHandle *dht_put; | ||
62 | |||
63 | /** | ||
54 | * ID of task that collects blocks for DHT PUTs. | 64 | * ID of task that collects blocks for DHT PUTs. |
55 | */ | 65 | */ |
56 | GNUNET_SCHEDULER_TaskIdentifier dht_task; | 66 | GNUNET_SCHEDULER_TaskIdentifier dht_task; |
@@ -92,20 +102,15 @@ gather_dht_put_blocks (void *cls, | |||
92 | 102 | ||
93 | 103 | ||
94 | /** | 104 | /** |
95 | * Task that is run periodically to obtain blocks for DHT PUTs. | 105 | * Calculate when to run the next PUT operation and schedule it. |
96 | * | 106 | * |
97 | * @param cls type of blocks to gather | 107 | * @param po put operator to schedule |
98 | * @param tc scheduler context (unused) | ||
99 | */ | 108 | */ |
100 | static void | 109 | static void |
101 | delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 110 | schedule_next_put (struct PutOperator *po) |
102 | { | 111 | { |
103 | struct PutOperator *po = cls; | ||
104 | struct GNUNET_TIME_Relative delay; | 112 | struct GNUNET_TIME_Relative delay; |
105 | 113 | ||
106 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; | ||
107 | if (tc != NULL && 0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
108 | return; | ||
109 | if (po->zero_anonymity_count_estimate > 0) | 114 | if (po->zero_anonymity_count_estimate > 0) |
110 | { | 115 | { |
111 | delay = | 116 | delay = |
@@ -125,6 +130,42 @@ delay_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
125 | 130 | ||
126 | 131 | ||
127 | /** | 132 | /** |
133 | * Continuation called after DHT PUT operation has finished. | ||
134 | * | ||
135 | * @param cls type of blocks to gather | ||
136 | * @param success GNUNET_OK if the PUT was transmitted, | ||
137 | * GNUNET_NO on timeout, | ||
138 | * GNUNET_SYSERR on disconnect from service | ||
139 | * after the PUT message was transmitted | ||
140 | * (so we don't know if it was received or not) | ||
141 | */ | ||
142 | static void | ||
143 | delay_dht_put_blocks (void *cls, int success) | ||
144 | { | ||
145 | struct PutOperator *po = cls; | ||
146 | |||
147 | po->dht_put = NULL; | ||
148 | schedule_next_put (po); | ||
149 | } | ||
150 | |||
151 | |||
152 | /** | ||
153 | * Task that is run periodically to obtain blocks for DHT PUTs. | ||
154 | * | ||
155 | * @param cls type of blocks to gather | ||
156 | * @param tc scheduler context | ||
157 | */ | ||
158 | static void | ||
159 | delay_dht_put_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
160 | { | ||
161 | struct PutOperator *po = cls; | ||
162 | |||
163 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; | ||
164 | schedule_next_put (po); | ||
165 | } | ||
166 | |||
167 | |||
168 | /** | ||
128 | * Store content in DHT. | 169 | * Store content in DHT. |
129 | * | 170 | * |
130 | * @param cls closure | 171 | * @param cls closure |
@@ -151,7 +192,7 @@ process_dht_put_content (void *cls, const GNUNET_HashCode * key, size_t size, | |||
151 | { | 192 | { |
152 | po->zero_anonymity_count_estimate = po->current_offset - 1; | 193 | po->zero_anonymity_count_estimate = po->current_offset - 1; |
153 | po->current_offset = 0; | 194 | po->current_offset = 0; |
154 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po); | 195 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); |
155 | return; | 196 | return; |
156 | } | 197 | } |
157 | po->zero_anonymity_count_estimate = | 198 | po->zero_anonymity_count_estimate = |
@@ -159,10 +200,10 @@ process_dht_put_content (void *cls, const GNUNET_HashCode * key, size_t size, | |||
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 200 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), | 201 | "Retrieved block `%s' of type %u for DHT PUT\n", GNUNET_h2s (key), |
161 | type); | 202 | type); |
162 | GNUNET_DHT_put (GSF_dht, key, 5 /* DEFAULT_PUT_REPLICATION */ , | 203 | po->dht_put = GNUNET_DHT_put (GSF_dht, key, DEFAULT_PUT_REPLICATION, |
163 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, type, size, data, | 204 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, type, size, data, |
164 | expiration, GNUNET_TIME_UNIT_FOREVER_REL, | 205 | expiration, GNUNET_TIME_UNIT_FOREVER_REL, |
165 | &delay_dht_put_blocks, po); | 206 | &delay_dht_put_blocks, po); |
166 | } | 207 | } |
167 | 208 | ||
168 | 209 | ||
@@ -187,7 +228,7 @@ gather_dht_put_blocks (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
187 | po->dht_put_type, | 228 | po->dht_put_type, |
188 | &process_dht_put_content, po); | 229 | &process_dht_put_content, po); |
189 | if (NULL == po->dht_qe) | 230 | if (NULL == po->dht_qe) |
190 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_blocks, po); | 231 | po->dht_task = GNUNET_SCHEDULER_add_now (&delay_dht_put_task, po); |
191 | } | 232 | } |
192 | 233 | ||
193 | 234 | ||
@@ -226,6 +267,11 @@ GSF_put_done_ () | |||
226 | GNUNET_SCHEDULER_cancel (po->dht_task); | 267 | GNUNET_SCHEDULER_cancel (po->dht_task); |
227 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; | 268 | po->dht_task = GNUNET_SCHEDULER_NO_TASK; |
228 | } | 269 | } |
270 | if (NULL != po->dht_put) | ||
271 | { | ||
272 | GNUNET_DHT_put_cancel (po->dht_put); | ||
273 | po->dht_put = NULL; | ||
274 | } | ||
229 | if (NULL != po->dht_qe) | 275 | if (NULL != po->dht_qe) |
230 | { | 276 | { |
231 | GNUNET_DATASTORE_cancel (po->dht_qe); | 277 | GNUNET_DATASTORE_cancel (po->dht_qe); |