diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/cadet/gnunet-service-cadet_dht.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/cadet/gnunet-service-cadet_dht.c')
-rw-r--r-- | src/cadet/gnunet-service-cadet_dht.c | 303 |
1 files changed, 153 insertions, 150 deletions
diff --git a/src/cadet/gnunet-service-cadet_dht.c b/src/cadet/gnunet-service-cadet_dht.c index c208c7f29..3bb86cae4 100644 --- a/src/cadet/gnunet-service-cadet_dht.c +++ b/src/cadet/gnunet-service-cadet_dht.c | |||
@@ -40,23 +40,26 @@ | |||
40 | * notifications when our HELLO is ready, so this is just the maximum | 40 | * notifications when our HELLO is ready, so this is just the maximum |
41 | * we wait for the first notification. | 41 | * we wait for the first notification. |
42 | */ | 42 | */ |
43 | #define STARTUP_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) | 43 | #define STARTUP_DELAY GNUNET_TIME_relative_multiply ( \ |
44 | GNUNET_TIME_UNIT_MILLISECONDS, 500) | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * How long do we wait after we get an updated HELLO before publishing? | 47 | * How long do we wait after we get an updated HELLO before publishing? |
47 | * Allows for the HELLO to be updated again quickly, for example in | 48 | * Allows for the HELLO to be updated again quickly, for example in |
48 | * case multiple addresses changed and we got a partial update. | 49 | * case multiple addresses changed and we got a partial update. |
49 | */ | 50 | */ |
50 | #define CHANGE_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100) | 51 | #define CHANGE_DELAY GNUNET_TIME_relative_multiply ( \ |
52 | GNUNET_TIME_UNIT_MILLISECONDS, 100) | ||
51 | 53 | ||
52 | 54 | ||
53 | #define LOG(level, ...) GNUNET_log_from(level, "cadet-dht", __VA_ARGS__) | 55 | #define LOG(level, ...) GNUNET_log_from (level, "cadet-dht", __VA_ARGS__) |
54 | 56 | ||
55 | 57 | ||
56 | /** | 58 | /** |
57 | * Handle for DHT searches. | 59 | * Handle for DHT searches. |
58 | */ | 60 | */ |
59 | struct GCD_search_handle { | 61 | struct GCD_search_handle |
62 | { | ||
60 | /** | 63 | /** |
61 | * DHT_GET handle. | 64 | * DHT_GET handle. |
62 | */ | 65 | */ |
@@ -107,35 +110,35 @@ static struct GNUNET_TIME_Relative announce_delay; | |||
107 | * @param data pointer to the result data | 110 | * @param data pointer to the result data |
108 | */ | 111 | */ |
109 | static void | 112 | static void |
110 | dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp, | 113 | dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, |
111 | const struct GNUNET_HashCode *key, | 114 | const struct GNUNET_HashCode *key, |
112 | const struct GNUNET_PeerIdentity *get_path, | 115 | const struct GNUNET_PeerIdentity *get_path, |
113 | unsigned int get_path_length, | 116 | unsigned int get_path_length, |
114 | const struct GNUNET_PeerIdentity *put_path, | 117 | const struct GNUNET_PeerIdentity *put_path, |
115 | unsigned int put_path_length, | 118 | unsigned int put_path_length, |
116 | enum GNUNET_BLOCK_Type type, | 119 | enum GNUNET_BLOCK_Type type, |
117 | size_t size, | 120 | size_t size, |
118 | const void *data) | 121 | const void *data) |
119 | { | 122 | { |
120 | const struct GNUNET_HELLO_Message *hello = data; | 123 | const struct GNUNET_HELLO_Message *hello = data; |
121 | struct CadetPeer *peer; | 124 | struct CadetPeer *peer; |
122 | 125 | ||
123 | GCPP_try_path_from_dht(get_path, | 126 | GCPP_try_path_from_dht (get_path, |
124 | get_path_length, | 127 | get_path_length, |
125 | put_path, | 128 | put_path, |
126 | put_path_length); | 129 | put_path_length); |
127 | if ((size >= sizeof(struct GNUNET_HELLO_Message)) && | 130 | if ((size >= sizeof(struct GNUNET_HELLO_Message)) && |
128 | (ntohs(hello->header.size) == size) && | 131 | (ntohs (hello->header.size) == size) && |
129 | (size == GNUNET_HELLO_size(hello))) | 132 | (size == GNUNET_HELLO_size (hello))) |
130 | { | 133 | { |
131 | peer = GCP_get(&put_path[0], | 134 | peer = GCP_get (&put_path[0], |
132 | GNUNET_YES); | 135 | GNUNET_YES); |
133 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 136 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
134 | "Got HELLO for %s\n", | 137 | "Got HELLO for %s\n", |
135 | GCP_2s(peer)); | 138 | GCP_2s (peer)); |
136 | GCP_set_hello(peer, | 139 | GCP_set_hello (peer, |
137 | hello); | 140 | hello); |
138 | } | 141 | } |
139 | } | 142 | } |
140 | 143 | ||
141 | 144 | ||
@@ -145,7 +148,7 @@ dht_get_id_handler(void *cls, struct GNUNET_TIME_Absolute exp, | |||
145 | * @param cls closure | 148 | * @param cls closure |
146 | */ | 149 | */ |
147 | static void | 150 | static void |
148 | announce_id(void *cls) | 151 | announce_id (void *cls) |
149 | { | 152 | { |
150 | struct GNUNET_HashCode phash; | 153 | struct GNUNET_HashCode phash; |
151 | const struct GNUNET_HELLO_Message *hello; | 154 | const struct GNUNET_HELLO_Message *hello; |
@@ -153,58 +156,58 @@ announce_id(void *cls) | |||
153 | struct GNUNET_TIME_Absolute expiration; | 156 | struct GNUNET_TIME_Absolute expiration; |
154 | struct GNUNET_TIME_Relative next_put; | 157 | struct GNUNET_TIME_Relative next_put; |
155 | 158 | ||
156 | hello = GCH_get_mine(); | 159 | hello = GCH_get_mine (); |
157 | size = (NULL != hello) ? GNUNET_HELLO_size(hello) : 0; | 160 | size = (NULL != hello) ? GNUNET_HELLO_size (hello) : 0; |
158 | if (0 == size) | 161 | if (0 == size) |
159 | { | 162 | { |
160 | expiration = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), | 163 | expiration = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), |
161 | announce_delay); | 164 | announce_delay); |
162 | announce_delay = GNUNET_TIME_STD_BACKOFF(announce_delay); | 165 | announce_delay = GNUNET_TIME_STD_BACKOFF (announce_delay); |
163 | } | 166 | } |
164 | else | 167 | else |
165 | { | 168 | { |
166 | expiration = GNUNET_HELLO_get_last_expiration(hello); | 169 | expiration = GNUNET_HELLO_get_last_expiration (hello); |
167 | announce_delay = GNUNET_TIME_UNIT_SECONDS; | 170 | announce_delay = GNUNET_TIME_UNIT_SECONDS; |
168 | } | 171 | } |
169 | 172 | ||
170 | /* Call again in id_announce_time, unless HELLO expires first, | 173 | /* Call again in id_announce_time, unless HELLO expires first, |
171 | * but wait at least 1s. */ | 174 | * but wait at least 1s. */ |
172 | next_put | 175 | next_put |
173 | = GNUNET_TIME_absolute_get_remaining(expiration); | 176 | = GNUNET_TIME_absolute_get_remaining (expiration); |
174 | next_put | 177 | next_put |
175 | = GNUNET_TIME_relative_min(next_put, | 178 | = GNUNET_TIME_relative_min (next_put, |
176 | id_announce_time); | 179 | id_announce_time); |
177 | next_put | 180 | next_put |
178 | = GNUNET_TIME_relative_max(next_put, | 181 | = GNUNET_TIME_relative_max (next_put, |
179 | GNUNET_TIME_UNIT_SECONDS); | 182 | GNUNET_TIME_UNIT_SECONDS); |
180 | announce_id_task | 183 | announce_id_task |
181 | = GNUNET_SCHEDULER_add_delayed(next_put, | 184 | = GNUNET_SCHEDULER_add_delayed (next_put, |
182 | &announce_id, | 185 | &announce_id, |
183 | cls); | 186 | cls); |
184 | GNUNET_STATISTICS_update(stats, | 187 | GNUNET_STATISTICS_update (stats, |
185 | "# DHT announce", | 188 | "# DHT announce", |
186 | 1, | 189 | 1, |
187 | GNUNET_NO); | 190 | GNUNET_NO); |
188 | memset(&phash, | 191 | memset (&phash, |
189 | 0, | 192 | 0, |
190 | sizeof(phash)); | 193 | sizeof(phash)); |
191 | GNUNET_memcpy(&phash, | 194 | GNUNET_memcpy (&phash, |
192 | &my_full_id, | 195 | &my_full_id, |
193 | sizeof(my_full_id)); | 196 | sizeof(my_full_id)); |
194 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 197 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
195 | "Announcing my HELLO (%u bytes) in the DHT\n", | 198 | "Announcing my HELLO (%u bytes) in the DHT\n", |
196 | size); | 199 | size); |
197 | GNUNET_DHT_put(dht_handle, /* DHT handle */ | 200 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
198 | &phash, /* Key to use */ | 201 | &phash, /* Key to use */ |
199 | dht_replication_level, /* Replication level */ | 202 | dht_replication_level, /* Replication level */ |
200 | GNUNET_DHT_RO_RECORD_ROUTE | 203 | GNUNET_DHT_RO_RECORD_ROUTE |
201 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ | 204 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, /* DHT options */ |
202 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ | 205 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* Block type */ |
203 | size, /* Size of the data */ | 206 | size, /* Size of the data */ |
204 | (const char *)hello, /* Data itself */ | 207 | (const char *) hello, /* Data itself */ |
205 | expiration, /* Data expiration */ | 208 | expiration, /* Data expiration */ |
206 | NULL, /* Continuation */ | 209 | NULL, /* Continuation */ |
207 | NULL); /* Continuation closure */ | 210 | NULL); /* Continuation closure */ |
208 | } | 211 | } |
209 | 212 | ||
210 | 213 | ||
@@ -213,15 +216,15 @@ announce_id(void *cls) | |||
213 | * changes. Re-triggers the DHT PUT immediately. | 216 | * changes. Re-triggers the DHT PUT immediately. |
214 | */ | 217 | */ |
215 | void | 218 | void |
216 | GCD_hello_update() | 219 | GCD_hello_update () |
217 | { | 220 | { |
218 | if (NULL == announce_id_task) | 221 | if (NULL == announce_id_task) |
219 | return; /* too early */ | 222 | return; /* too early */ |
220 | GNUNET_SCHEDULER_cancel(announce_id_task); | 223 | GNUNET_SCHEDULER_cancel (announce_id_task); |
221 | announce_id_task | 224 | announce_id_task |
222 | = GNUNET_SCHEDULER_add_delayed(CHANGE_DELAY, | 225 | = GNUNET_SCHEDULER_add_delayed (CHANGE_DELAY, |
223 | &announce_id, | 226 | &announce_id, |
224 | NULL); | 227 | NULL); |
225 | } | 228 | } |
226 | 229 | ||
227 | 230 | ||
@@ -231,42 +234,42 @@ GCD_hello_update() | |||
231 | * @param c Configuration. | 234 | * @param c Configuration. |
232 | */ | 235 | */ |
233 | void | 236 | void |
234 | GCD_init(const struct GNUNET_CONFIGURATION_Handle *c) | 237 | GCD_init (const struct GNUNET_CONFIGURATION_Handle *c) |
235 | { | 238 | { |
236 | if (GNUNET_OK != | 239 | if (GNUNET_OK != |
237 | GNUNET_CONFIGURATION_get_value_number(c, | 240 | GNUNET_CONFIGURATION_get_value_number (c, |
238 | "CADET", | 241 | "CADET", |
239 | "DHT_REPLICATION_LEVEL", | 242 | "DHT_REPLICATION_LEVEL", |
240 | &dht_replication_level)) | 243 | &dht_replication_level)) |
241 | { | 244 | { |
242 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_WARNING, | 245 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, |
243 | "CADET", | 246 | "CADET", |
244 | "DHT_REPLICATION_LEVEL", | 247 | "DHT_REPLICATION_LEVEL", |
245 | "USING DEFAULT"); | 248 | "USING DEFAULT"); |
246 | dht_replication_level = 3; | 249 | dht_replication_level = 3; |
247 | } | 250 | } |
248 | 251 | ||
249 | if (GNUNET_OK != | 252 | if (GNUNET_OK != |
250 | GNUNET_CONFIGURATION_get_value_time(c, | 253 | GNUNET_CONFIGURATION_get_value_time (c, |
251 | "CADET", | 254 | "CADET", |
252 | "ID_ANNOUNCE_TIME", | 255 | "ID_ANNOUNCE_TIME", |
253 | &id_announce_time)) | 256 | &id_announce_time)) |
254 | { | 257 | { |
255 | GNUNET_log_config_invalid(GNUNET_ERROR_TYPE_ERROR, | 258 | GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, |
256 | "CADET", | 259 | "CADET", |
257 | "ID_ANNOUNCE_TIME", | 260 | "ID_ANNOUNCE_TIME", |
258 | "MISSING"); | 261 | "MISSING"); |
259 | GNUNET_SCHEDULER_shutdown(); | 262 | GNUNET_SCHEDULER_shutdown (); |
260 | return; | 263 | return; |
261 | } | 264 | } |
262 | 265 | ||
263 | dht_handle = GNUNET_DHT_connect(c, | 266 | dht_handle = GNUNET_DHT_connect (c, |
264 | 64); | 267 | 64); |
265 | GNUNET_break(NULL != dht_handle); | 268 | GNUNET_break (NULL != dht_handle); |
266 | announce_delay = GNUNET_TIME_UNIT_SECONDS; | 269 | announce_delay = GNUNET_TIME_UNIT_SECONDS; |
267 | announce_id_task = GNUNET_SCHEDULER_add_delayed(STARTUP_DELAY, | 270 | announce_id_task = GNUNET_SCHEDULER_add_delayed (STARTUP_DELAY, |
268 | &announce_id, | 271 | &announce_id, |
269 | NULL); | 272 | NULL); |
270 | } | 273 | } |
271 | 274 | ||
272 | 275 | ||
@@ -274,18 +277,18 @@ GCD_init(const struct GNUNET_CONFIGURATION_Handle *c) | |||
274 | * Shut down the DHT subsystem. | 277 | * Shut down the DHT subsystem. |
275 | */ | 278 | */ |
276 | void | 279 | void |
277 | GCD_shutdown(void) | 280 | GCD_shutdown (void) |
278 | { | 281 | { |
279 | if (NULL != dht_handle) | 282 | if (NULL != dht_handle) |
280 | { | 283 | { |
281 | GNUNET_DHT_disconnect(dht_handle); | 284 | GNUNET_DHT_disconnect (dht_handle); |
282 | dht_handle = NULL; | 285 | dht_handle = NULL; |
283 | } | 286 | } |
284 | if (NULL != announce_id_task) | 287 | if (NULL != announce_id_task) |
285 | { | 288 | { |
286 | GNUNET_SCHEDULER_cancel(announce_id_task); | 289 | GNUNET_SCHEDULER_cancel (announce_id_task); |
287 | announce_id_task = NULL; | 290 | announce_id_task = NULL; |
288 | } | 291 | } |
289 | } | 292 | } |
290 | 293 | ||
291 | 294 | ||
@@ -296,37 +299,37 @@ GCD_shutdown(void) | |||
296 | * @return handle to abort search | 299 | * @return handle to abort search |
297 | */ | 300 | */ |
298 | struct GCD_search_handle * | 301 | struct GCD_search_handle * |
299 | GCD_search(const struct GNUNET_PeerIdentity *peer_id) | 302 | GCD_search (const struct GNUNET_PeerIdentity *peer_id) |
300 | { | 303 | { |
301 | struct GNUNET_HashCode phash; | 304 | struct GNUNET_HashCode phash; |
302 | struct GCD_search_handle *h; | 305 | struct GCD_search_handle *h; |
303 | 306 | ||
304 | GNUNET_STATISTICS_update(stats, | 307 | GNUNET_STATISTICS_update (stats, |
305 | "# DHT search", | 308 | "# DHT search", |
306 | 1, | 309 | 1, |
307 | GNUNET_NO); | 310 | GNUNET_NO); |
308 | memset(&phash, | 311 | memset (&phash, |
309 | 0, | 312 | 0, |
310 | sizeof(phash)); | 313 | sizeof(phash)); |
311 | GNUNET_memcpy(&phash, | 314 | GNUNET_memcpy (&phash, |
312 | peer_id, | 315 | peer_id, |
313 | sizeof(*peer_id)); | 316 | sizeof(*peer_id)); |
314 | 317 | ||
315 | h = GNUNET_new(struct GCD_search_handle); | 318 | h = GNUNET_new (struct GCD_search_handle); |
316 | h->dhtget = GNUNET_DHT_get_start(dht_handle, /* handle */ | 319 | h->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ |
317 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */ | 320 | GNUNET_BLOCK_TYPE_DHT_HELLO, /* type */ |
318 | &phash, /* key to search */ | 321 | &phash, /* key to search */ |
319 | dht_replication_level, /* replication level */ | 322 | dht_replication_level, /* replication level */ |
320 | GNUNET_DHT_RO_RECORD_ROUTE | | 323 | GNUNET_DHT_RO_RECORD_ROUTE |
321 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | 324 | | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, |
322 | NULL, /* xquery */ | 325 | NULL, /* xquery */ |
323 | 0, /* xquery bits */ | 326 | 0, /* xquery bits */ |
324 | &dht_get_id_handler, | 327 | &dht_get_id_handler, |
325 | h); | 328 | h); |
326 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 329 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
327 | "Starting DHT GET for peer %s (%p)\n", | 330 | "Starting DHT GET for peer %s (%p)\n", |
328 | GNUNET_i2s(peer_id), | 331 | GNUNET_i2s (peer_id), |
329 | h); | 332 | h); |
330 | return h; | 333 | return h; |
331 | } | 334 | } |
332 | 335 | ||
@@ -337,13 +340,13 @@ GCD_search(const struct GNUNET_PeerIdentity *peer_id) | |||
337 | * @param h handle to search to stop | 340 | * @param h handle to search to stop |
338 | */ | 341 | */ |
339 | void | 342 | void |
340 | GCD_search_stop(struct GCD_search_handle *h) | 343 | GCD_search_stop (struct GCD_search_handle *h) |
341 | { | 344 | { |
342 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 345 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
343 | "Stopping DHT GET %p\n", | 346 | "Stopping DHT GET %p\n", |
344 | h); | 347 | h); |
345 | GNUNET_DHT_get_stop(h->dhtget); | 348 | GNUNET_DHT_get_stop (h->dhtget); |
346 | GNUNET_free(h); | 349 | GNUNET_free (h); |
347 | } | 350 | } |
348 | 351 | ||
349 | /* end of gnunet-service-cadet_dht.c */ | 352 | /* end of gnunet-service-cadet_dht.c */ |