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