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/peerinfo | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 1297 | ||||
-rw-r--r-- | src/peerinfo/peerinfo.h | 12 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 420 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 163 | ||||
-rw-r--r-- | src/peerinfo/perf_peerinfo_api.c | 145 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 123 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_friend_only.c | 147 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api_notify_friend_only.c | 213 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_shipped_hellos.c | 128 |
9 files changed, 1333 insertions, 1315 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 25a3fabd7..27e0337ee 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -39,19 +39,20 @@ | |||
39 | * How often do we scan the HOST_DIR for new entries? | 39 | * How often do we scan the HOST_DIR for new entries? |
40 | */ | 40 | */ |
41 | #define DATA_HOST_FREQ \ | 41 | #define DATA_HOST_FREQ \ |
42 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15) | 42 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
43 | 43 | ||
44 | /** | 44 | /** |
45 | * How often do we discard old entries in data/hosts/? | 45 | * How often do we discard old entries in data/hosts/? |
46 | */ | 46 | */ |
47 | #define DATA_HOST_CLEAN_FREQ \ | 47 | #define DATA_HOST_CLEAN_FREQ \ |
48 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 60) | 48 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) |
49 | 49 | ||
50 | 50 | ||
51 | /** | 51 | /** |
52 | * In-memory cache of known hosts. | 52 | * In-memory cache of known hosts. |
53 | */ | 53 | */ |
54 | struct HostEntry { | 54 | struct HostEntry |
55 | { | ||
55 | /** | 56 | /** |
56 | * Identity of the peer. | 57 | * Identity of the peer. |
57 | */ | 58 | */ |
@@ -72,7 +73,8 @@ struct HostEntry { | |||
72 | /** | 73 | /** |
73 | * Result of reading a file | 74 | * Result of reading a file |
74 | */ | 75 | */ |
75 | struct ReadHostFileContext { | 76 | struct ReadHostFileContext |
77 | { | ||
76 | /** | 78 | /** |
77 | * Hello for the peer (can be NULL) | 79 | * Hello for the peer (can be NULL) |
78 | */ | 80 | */ |
@@ -132,7 +134,7 @@ static struct GNUNET_SCHEDULER_Task *cron_scan; | |||
132 | * @return generated notification message | 134 | * @return generated notification message |
133 | */ | 135 | */ |
134 | static struct InfoMessage * | 136 | static struct InfoMessage * |
135 | make_info_message(const struct HostEntry *he, int include_friend_only) | 137 | make_info_message (const struct HostEntry *he, int include_friend_only) |
136 | { | 138 | { |
137 | struct InfoMessage *im; | 139 | struct InfoMessage *im; |
138 | struct GNUNET_HELLO_Message *src; | 140 | struct GNUNET_HELLO_Message *src; |
@@ -142,12 +144,12 @@ make_info_message(const struct HostEntry *he, int include_friend_only) | |||
142 | src = he->friend_only_hello; | 144 | src = he->friend_only_hello; |
143 | else | 145 | else |
144 | src = he->hello; | 146 | src = he->hello; |
145 | hs = (NULL == src) ? 0 : GNUNET_HELLO_size(src); | 147 | hs = (NULL == src) ? 0 : GNUNET_HELLO_size (src); |
146 | im = GNUNET_malloc(sizeof(struct InfoMessage) + hs); | 148 | im = GNUNET_malloc (sizeof(struct InfoMessage) + hs); |
147 | im->header.size = htons(hs + sizeof(struct InfoMessage)); | 149 | im->header.size = htons (hs + sizeof(struct InfoMessage)); |
148 | im->header.type = htons(GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 150 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
149 | im->peer = he->identity; | 151 | im->peer = he->identity; |
150 | GNUNET_memcpy(&im[1], src, hs); | 152 | GNUNET_memcpy (&im[1], src, hs); |
151 | return im; | 153 | return im; |
152 | } | 154 | } |
153 | 155 | ||
@@ -161,19 +163,19 @@ make_info_message(const struct HostEntry *he, int include_friend_only) | |||
161 | * @return #GNUNET_NO if expiration smaller than the current time | 163 | * @return #GNUNET_NO if expiration smaller than the current time |
162 | */ | 164 | */ |
163 | static int | 165 | static int |
164 | discard_expired(void *cls, | 166 | discard_expired (void *cls, |
165 | const struct GNUNET_HELLO_Address *address, | 167 | const struct GNUNET_HELLO_Address *address, |
166 | struct GNUNET_TIME_Absolute expiration) | 168 | struct GNUNET_TIME_Absolute expiration) |
167 | { | 169 | { |
168 | const struct GNUNET_TIME_Absolute *now = cls; | 170 | const struct GNUNET_TIME_Absolute *now = cls; |
169 | 171 | ||
170 | if (now->abs_value_us > expiration.abs_value_us) | 172 | if (now->abs_value_us > expiration.abs_value_us) |
171 | { | 173 | { |
172 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 174 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
173 | _("Removing expired address of transport `%s'\n"), | 175 | _ ("Removing expired address of transport `%s'\n"), |
174 | address->transport_name); | 176 | address->transport_name); |
175 | return GNUNET_NO; | 177 | return GNUNET_NO; |
176 | } | 178 | } |
177 | return GNUNET_OK; | 179 | return GNUNET_OK; |
178 | } | 180 | } |
179 | 181 | ||
@@ -187,14 +189,14 @@ discard_expired(void *cls, | |||
187 | * @return #GNUNET_OK (always) | 189 | * @return #GNUNET_OK (always) |
188 | */ | 190 | */ |
189 | static int | 191 | static int |
190 | count_addresses(void *cls, | 192 | count_addresses (void *cls, |
191 | const struct GNUNET_HELLO_Address *address, | 193 | const struct GNUNET_HELLO_Address *address, |
192 | struct GNUNET_TIME_Absolute expiration) | 194 | struct GNUNET_TIME_Absolute expiration) |
193 | { | 195 | { |
194 | unsigned int *cnt = cls; | 196 | unsigned int *cnt = cls; |
195 | 197 | ||
196 | (void)address; | 198 | (void) address; |
197 | (void)expiration; | 199 | (void) expiration; |
198 | (*cnt)++; | 200 | (*cnt)++; |
199 | return GNUNET_OK; | 201 | return GNUNET_OK; |
200 | } | 202 | } |
@@ -208,17 +210,17 @@ count_addresses(void *cls, | |||
208 | * @return filename of the form DIRECTORY/HOSTID | 210 | * @return filename of the form DIRECTORY/HOSTID |
209 | */ | 211 | */ |
210 | static char * | 212 | static char * |
211 | get_host_filename(const struct GNUNET_PeerIdentity *id) | 213 | get_host_filename (const struct GNUNET_PeerIdentity *id) |
212 | { | 214 | { |
213 | char *fn; | 215 | char *fn; |
214 | 216 | ||
215 | if (NULL == networkIdDirectory) | 217 | if (NULL == networkIdDirectory) |
216 | return NULL; | 218 | return NULL; |
217 | GNUNET_asprintf(&fn, | 219 | GNUNET_asprintf (&fn, |
218 | "%s%s%s", | 220 | "%s%s%s", |
219 | networkIdDirectory, | 221 | networkIdDirectory, |
220 | DIR_SEPARATOR_STR, | 222 | DIR_SEPARATOR_STR, |
221 | GNUNET_i2s_full(id)); | 223 | GNUNET_i2s_full (id)); |
222 | return fn; | 224 | return fn; |
223 | } | 225 | } |
224 | 226 | ||
@@ -230,24 +232,24 @@ get_host_filename(const struct GNUNET_PeerIdentity *id) | |||
230 | * @param entry entry to broadcast about | 232 | * @param entry entry to broadcast about |
231 | */ | 233 | */ |
232 | static void | 234 | static void |
233 | notify_all(struct HostEntry *entry) | 235 | notify_all (struct HostEntry *entry) |
234 | { | 236 | { |
235 | struct InfoMessage *msg_pub; | 237 | struct InfoMessage *msg_pub; |
236 | struct InfoMessage *msg_friend; | 238 | struct InfoMessage *msg_friend; |
237 | 239 | ||
238 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
239 | "Notifying all clients about peer `%s'\n", | 241 | "Notifying all clients about peer `%s'\n", |
240 | GNUNET_i2s(&entry->identity)); | 242 | GNUNET_i2s (&entry->identity)); |
241 | msg_pub = make_info_message(entry, GNUNET_NO); | 243 | msg_pub = make_info_message (entry, GNUNET_NO); |
242 | GNUNET_notification_context_broadcast(notify_list, | 244 | GNUNET_notification_context_broadcast (notify_list, |
243 | &msg_pub->header, | 245 | &msg_pub->header, |
244 | GNUNET_NO); | 246 | GNUNET_NO); |
245 | GNUNET_free(msg_pub); | 247 | GNUNET_free (msg_pub); |
246 | msg_friend = make_info_message(entry, GNUNET_YES); | 248 | msg_friend = make_info_message (entry, GNUNET_YES); |
247 | GNUNET_notification_context_broadcast(notify_friend_only_list, | 249 | GNUNET_notification_context_broadcast (notify_friend_only_list, |
248 | &msg_friend->header, | 250 | &msg_friend->header, |
249 | GNUNET_NO); | 251 | GNUNET_NO); |
250 | GNUNET_free(msg_friend); | 252 | GNUNET_free (msg_friend); |
251 | } | 253 | } |
252 | 254 | ||
253 | 255 | ||
@@ -258,8 +260,8 @@ notify_all(struct HostEntry *entry) | |||
258 | * @param hello the verified (!) hello message | 260 | * @param hello the verified (!) hello message |
259 | */ | 261 | */ |
260 | static void | 262 | static void |
261 | update_hello(const struct GNUNET_PeerIdentity *peer, | 263 | update_hello (const struct GNUNET_PeerIdentity *peer, |
262 | const struct GNUNET_HELLO_Message *hello); | 264 | const struct GNUNET_HELLO_Message *hello); |
263 | 265 | ||
264 | 266 | ||
265 | /** | 267 | /** |
@@ -274,9 +276,9 @@ update_hello(const struct GNUNET_PeerIdentity *peer, | |||
274 | * @param r ReadHostFileContext to store the resutl | 276 | * @param r ReadHostFileContext to store the resutl |
275 | */ | 277 | */ |
276 | static void | 278 | static void |
277 | read_host_file(const char *fn, | 279 | read_host_file (const char *fn, |
278 | int unlink_garbage, | 280 | int unlink_garbage, |
279 | struct ReadHostFileContext *r) | 281 | struct ReadHostFileContext *r) |
280 | { | 282 | { |
281 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; | 283 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; |
282 | ssize_t size_total; | 284 | ssize_t size_total; |
@@ -290,114 +292,114 @@ read_host_file(const char *fn, | |||
290 | r->friend_only_hello = NULL; | 292 | r->friend_only_hello = NULL; |
291 | r->hello = NULL; | 293 | r->hello = NULL; |
292 | 294 | ||
293 | if (GNUNET_YES != GNUNET_DISK_file_test(fn)) | 295 | if (GNUNET_YES != GNUNET_DISK_file_test (fn)) |
294 | return; | 296 | return; |
295 | size_total = GNUNET_DISK_fn_read(fn, buffer, sizeof(buffer)); | 297 | size_total = GNUNET_DISK_fn_read (fn, buffer, sizeof(buffer)); |
296 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
297 | "Read %d bytes from `%s'\n", | 299 | "Read %d bytes from `%s'\n", |
298 | (int)size_total, | 300 | (int) size_total, |
299 | fn); | 301 | fn); |
300 | if ((size_total < 0) || | 302 | if ((size_total < 0) || |
301 | (((size_t)size_total) < sizeof(struct GNUNET_MessageHeader))) | 303 | (((size_t) size_total) < sizeof(struct GNUNET_MessageHeader))) |
304 | { | ||
305 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
306 | _ ("Failed to parse HELLO in file `%s': %s\n"), | ||
307 | fn, | ||
308 | "File has invalid size"); | ||
309 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) && | ||
310 | (ENOENT != errno)) | ||
311 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
312 | return; | ||
313 | } | ||
314 | |||
315 | read_pos = 0; | ||
316 | while (read_pos < (size_t) size_total) | ||
317 | { | ||
318 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | ||
319 | size_hello = GNUNET_HELLO_size (hello); | ||
320 | if ((0 == size_hello) || (((size_t) size_total) - read_pos < size_hello)) | ||
302 | { | 321 | { |
303 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 322 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
304 | _("Failed to parse HELLO in file `%s': %s\n"), | 323 | _ ("Failed to parse HELLO in file `%s'\n"), |
305 | fn, | 324 | fn); |
306 | "File has invalid size"); | 325 | if (0 == read_pos) |
307 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn)) && | 326 | { |
308 | (ENOENT != errno)) | 327 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) && |
309 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 328 | (ENOENT != errno)) |
329 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
330 | } | ||
331 | else | ||
332 | { | ||
333 | if ((GNUNET_YES == unlink_garbage) && (0 != truncate (fn, read_pos)) && | ||
334 | (ENOENT != errno)) | ||
335 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "truncate", fn); | ||
336 | } | ||
310 | return; | 337 | return; |
311 | } | 338 | } |
312 | 339 | ||
313 | read_pos = 0; | 340 | now = GNUNET_TIME_absolute_get (); |
314 | while (read_pos < (size_t)size_total) | 341 | hello_clean = GNUNET_HELLO_iterate_addresses (hello, |
342 | GNUNET_YES, | ||
343 | &discard_expired, | ||
344 | &now); | ||
345 | if (NULL == hello_clean) | ||
315 | { | 346 | { |
316 | hello = (const struct GNUNET_HELLO_Message *)&buffer[read_pos]; | 347 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
317 | size_hello = GNUNET_HELLO_size(hello); | 348 | _ ("Failed to parse HELLO in file `%s'\n"), |
318 | if ((0 == size_hello) || (((size_t)size_total) - read_pos < size_hello)) | 349 | fn); |
319 | { | 350 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn)) && |
320 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 351 | (ENOENT != errno)) |
321 | _("Failed to parse HELLO in file `%s'\n"), | 352 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); |
322 | fn); | 353 | return; |
323 | if (0 == read_pos) | 354 | } |
324 | { | 355 | left = 0; |
325 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn)) && | 356 | (void) GNUNET_HELLO_iterate_addresses (hello_clean, |
326 | (ENOENT != errno)) | ||
327 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
328 | } | ||
329 | else | ||
330 | { | ||
331 | if ((GNUNET_YES == unlink_garbage) && (0 != truncate(fn, read_pos)) && | ||
332 | (ENOENT != errno)) | ||
333 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "truncate", fn); | ||
334 | } | ||
335 | return; | ||
336 | } | ||
337 | |||
338 | now = GNUNET_TIME_absolute_get(); | ||
339 | hello_clean = GNUNET_HELLO_iterate_addresses(hello, | ||
340 | GNUNET_YES, | ||
341 | &discard_expired, | ||
342 | &now); | ||
343 | if (NULL == hello_clean) | ||
344 | { | ||
345 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
346 | _("Failed to parse HELLO in file `%s'\n"), | ||
347 | fn); | ||
348 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn)) && | ||
349 | (ENOENT != errno)) | ||
350 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
351 | return; | ||
352 | } | ||
353 | left = 0; | ||
354 | (void)GNUNET_HELLO_iterate_addresses(hello_clean, | ||
355 | GNUNET_NO, | 357 | GNUNET_NO, |
356 | &count_addresses, | 358 | &count_addresses, |
357 | &left); | 359 | &left); |
358 | 360 | ||
359 | if (0 == left) | 361 | if (0 == left) |
360 | { | 362 | { |
361 | GNUNET_free(hello_clean); | 363 | GNUNET_free (hello_clean); |
362 | break; | 364 | break; |
363 | } | ||
364 | |||
365 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello_clean)) | ||
366 | { | ||
367 | if (NULL == r->hello) | ||
368 | r->hello = hello_clean; | ||
369 | else | ||
370 | { | ||
371 | GNUNET_break(0); | ||
372 | GNUNET_free(r->hello); | ||
373 | r->hello = hello_clean; | ||
374 | } | ||
375 | } | ||
376 | else | ||
377 | { | ||
378 | if (NULL == r->friend_only_hello) | ||
379 | r->friend_only_hello = hello_clean; | ||
380 | else | ||
381 | { | ||
382 | GNUNET_break(0); | ||
383 | GNUNET_free(r->friend_only_hello); | ||
384 | r->friend_only_hello = hello_clean; | ||
385 | } | ||
386 | } | ||
387 | read_pos += size_hello; | ||
388 | } | 365 | } |
389 | 366 | ||
390 | if (0 == left) | 367 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello_clean)) |
391 | { | 368 | { |
392 | /* no addresses left, remove from disk */ | 369 | if (NULL == r->hello) |
393 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink(fn))) | 370 | r->hello = hello_clean; |
394 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | 371 | else |
372 | { | ||
373 | GNUNET_break (0); | ||
374 | GNUNET_free (r->hello); | ||
375 | r->hello = hello_clean; | ||
376 | } | ||
377 | } | ||
378 | else | ||
379 | { | ||
380 | if (NULL == r->friend_only_hello) | ||
381 | r->friend_only_hello = hello_clean; | ||
382 | else | ||
383 | { | ||
384 | GNUNET_break (0); | ||
385 | GNUNET_free (r->friend_only_hello); | ||
386 | r->friend_only_hello = hello_clean; | ||
387 | } | ||
395 | } | 388 | } |
396 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 389 | read_pos += size_hello; |
397 | "Found `%s' and `%s' HELLO message in file\n", | 390 | } |
398 | (NULL != r->hello) ? "public" : "NON-public", | 391 | |
399 | (NULL != r->friend_only_hello) ? "friend only" | 392 | if (0 == left) |
400 | : "NO friend only"); | 393 | { |
394 | /* no addresses left, remove from disk */ | ||
395 | if ((GNUNET_YES == unlink_garbage) && (0 != unlink (fn))) | ||
396 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "unlink", fn); | ||
397 | } | ||
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
399 | "Found `%s' and `%s' HELLO message in file\n", | ||
400 | (NULL != r->hello) ? "public" : "NON-public", | ||
401 | (NULL != r->friend_only_hello) ? "friend only" | ||
402 | : "NO friend only"); | ||
401 | } | 403 | } |
402 | 404 | ||
403 | 405 | ||
@@ -408,44 +410,44 @@ read_host_file(const char *fn, | |||
408 | * @return the HostEntry | 410 | * @return the HostEntry |
409 | */ | 411 | */ |
410 | static struct HostEntry * | 412 | static struct HostEntry * |
411 | add_host_to_known_hosts(const struct GNUNET_PeerIdentity *identity) | 413 | add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) |
412 | { | 414 | { |
413 | struct HostEntry *entry; | 415 | struct HostEntry *entry; |
414 | struct ReadHostFileContext r; | 416 | struct ReadHostFileContext r; |
415 | char *fn; | 417 | char *fn; |
416 | 418 | ||
417 | entry = GNUNET_CONTAINER_multipeermap_get(hostmap, identity); | 419 | entry = GNUNET_CONTAINER_multipeermap_get (hostmap, identity); |
418 | if (NULL == entry) | 420 | if (NULL == entry) |
421 | { | ||
422 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
423 | "Adding new peer `%s'\n", | ||
424 | GNUNET_i2s (identity)); | ||
425 | GNUNET_STATISTICS_update (stats, | ||
426 | gettext_noop ("# peers known"), | ||
427 | 1, | ||
428 | GNUNET_NO); | ||
429 | entry = GNUNET_new (struct HostEntry); | ||
430 | entry->identity = *identity; | ||
431 | GNUNET_assert (GNUNET_OK == | ||
432 | GNUNET_CONTAINER_multipeermap_put ( | ||
433 | hostmap, | ||
434 | &entry->identity, | ||
435 | entry, | ||
436 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
437 | notify_all (entry); | ||
438 | fn = get_host_filename (identity); | ||
439 | if (NULL != fn) | ||
419 | { | 440 | { |
420 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 441 | read_host_file (fn, GNUNET_YES, &r); |
421 | "Adding new peer `%s'\n", | 442 | if (NULL != r.hello) |
422 | GNUNET_i2s(identity)); | 443 | update_hello (identity, r.hello); |
423 | GNUNET_STATISTICS_update(stats, | 444 | if (NULL != r.friend_only_hello) |
424 | gettext_noop("# peers known"), | 445 | update_hello (identity, r.friend_only_hello); |
425 | 1, | 446 | GNUNET_free_non_null (r.hello); |
426 | GNUNET_NO); | 447 | GNUNET_free_non_null (r.friend_only_hello); |
427 | entry = GNUNET_new(struct HostEntry); | 448 | GNUNET_free (fn); |
428 | entry->identity = *identity; | ||
429 | GNUNET_assert(GNUNET_OK == | ||
430 | GNUNET_CONTAINER_multipeermap_put( | ||
431 | hostmap, | ||
432 | &entry->identity, | ||
433 | entry, | ||
434 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
435 | notify_all(entry); | ||
436 | fn = get_host_filename(identity); | ||
437 | if (NULL != fn) | ||
438 | { | ||
439 | read_host_file(fn, GNUNET_YES, &r); | ||
440 | if (NULL != r.hello) | ||
441 | update_hello(identity, r.hello); | ||
442 | if (NULL != r.friend_only_hello) | ||
443 | update_hello(identity, r.friend_only_hello); | ||
444 | GNUNET_free_non_null(r.hello); | ||
445 | GNUNET_free_non_null(r.friend_only_hello); | ||
446 | GNUNET_free(fn); | ||
447 | } | ||
448 | } | 449 | } |
450 | } | ||
449 | return entry; | 451 | return entry; |
450 | } | 452 | } |
451 | 453 | ||
@@ -457,26 +459,27 @@ add_host_to_known_hosts(const struct GNUNET_PeerIdentity *identity) | |||
457 | * @param fullname name of the file to remove | 459 | * @param fullname name of the file to remove |
458 | */ | 460 | */ |
459 | static void | 461 | static void |
460 | remove_garbage(const char *fullname) | 462 | remove_garbage (const char *fullname) |
461 | { | 463 | { |
462 | if (0 == unlink(fullname)) | 464 | if (0 == unlink (fullname)) |
463 | GNUNET_log( | 465 | GNUNET_log ( |
464 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 466 | GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
465 | _( | 467 | _ ( |
466 | "File `%s' in directory `%s' does not match naming convention. Removed.\n"), | 468 | "File `%s' in directory `%s' does not match naming convention. Removed.\n"), |
467 | fullname, | 469 | fullname, |
468 | networkIdDirectory); | 470 | networkIdDirectory); |
469 | else | 471 | else |
470 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 472 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
471 | "unlink", | 473 | "unlink", |
472 | fullname); | 474 | fullname); |
473 | } | 475 | } |
474 | 476 | ||
475 | 477 | ||
476 | /** | 478 | /** |
477 | * Closure for #hosts_directory_scan_callback(). | 479 | * Closure for #hosts_directory_scan_callback(). |
478 | */ | 480 | */ |
479 | struct DirScanContext { | 481 | struct DirScanContext |
482 | { | ||
480 | /** | 483 | /** |
481 | * #GNUNET_YES if we should remove files that are broken, | 484 | * #GNUNET_YES if we should remove files that are broken, |
482 | * #GNUNET_NO if the directory we are iterating over should | 485 | * #GNUNET_NO if the directory we are iterating over should |
@@ -502,7 +505,7 @@ struct DirScanContext { | |||
502 | * @return #GNUNET_OK (continue iteration) | 505 | * @return #GNUNET_OK (continue iteration) |
503 | */ | 506 | */ |
504 | static int | 507 | static int |
505 | hosts_directory_scan_callback(void *cls, const char *fullname) | 508 | hosts_directory_scan_callback (void *cls, const char *fullname) |
506 | { | 509 | { |
507 | struct DirScanContext *dsc = cls; | 510 | struct DirScanContext *dsc = cls; |
508 | struct GNUNET_PeerIdentity identity; | 511 | struct GNUNET_PeerIdentity identity; |
@@ -512,81 +515,81 @@ hosts_directory_scan_callback(void *cls, const char *fullname) | |||
512 | struct GNUNET_PeerIdentity id_friend; | 515 | struct GNUNET_PeerIdentity id_friend; |
513 | struct GNUNET_PeerIdentity id; | 516 | struct GNUNET_PeerIdentity id; |
514 | 517 | ||
515 | if (GNUNET_YES != GNUNET_DISK_file_test(fullname)) | 518 | if (GNUNET_YES != GNUNET_DISK_file_test (fullname)) |
516 | return GNUNET_OK; /* ignore non-files */ | 519 | return GNUNET_OK; /* ignore non-files */ |
517 | 520 | ||
518 | filename = strrchr(fullname, DIR_SEPARATOR); | 521 | filename = strrchr (fullname, DIR_SEPARATOR); |
519 | if ((NULL == filename) || (1 > strlen(filename))) | 522 | if ((NULL == filename) || (1 > strlen (filename))) |
520 | filename = fullname; | 523 | filename = fullname; |
521 | else | 524 | else |
522 | filename++; | 525 | filename++; |
523 | 526 | ||
524 | read_host_file(fullname, dsc->remove_files, &r); | 527 | read_host_file (fullname, dsc->remove_files, &r); |
525 | if ((NULL == r.hello) && (NULL == r.friend_only_hello)) | 528 | if ((NULL == r.hello) && (NULL == r.friend_only_hello)) |
526 | return GNUNET_OK; | 529 | return GNUNET_OK; |
527 | if (NULL != r.friend_only_hello) | 530 | if (NULL != r.friend_only_hello) |
531 | { | ||
532 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.friend_only_hello, &id_friend)) | ||
528 | { | 533 | { |
529 | if (GNUNET_OK != GNUNET_HELLO_get_id(r.friend_only_hello, &id_friend)) | 534 | if (GNUNET_YES == dsc->remove_files) |
530 | { | 535 | remove_garbage (fullname); |
531 | if (GNUNET_YES == dsc->remove_files) | 536 | return GNUNET_OK; |
532 | remove_garbage(fullname); | ||
533 | return GNUNET_OK; | ||
534 | } | ||
535 | id = id_friend; | ||
536 | } | 537 | } |
538 | id = id_friend; | ||
539 | } | ||
537 | if (NULL != r.hello) | 540 | if (NULL != r.hello) |
541 | { | ||
542 | if (GNUNET_OK != GNUNET_HELLO_get_id (r.hello, &id_public)) | ||
538 | { | 543 | { |
539 | if (GNUNET_OK != GNUNET_HELLO_get_id(r.hello, &id_public)) | 544 | if (GNUNET_YES == dsc->remove_files) |
540 | { | 545 | remove_garbage (fullname); |
541 | if (GNUNET_YES == dsc->remove_files) | 546 | return GNUNET_OK; |
542 | remove_garbage(fullname); | ||
543 | return GNUNET_OK; | ||
544 | } | ||
545 | id = id_public; | ||
546 | } | 547 | } |
548 | id = id_public; | ||
549 | } | ||
547 | 550 | ||
548 | if ((NULL != r.hello) && (NULL != r.friend_only_hello) && | 551 | if ((NULL != r.hello) && (NULL != r.friend_only_hello) && |
549 | (0 != GNUNET_memcmp(&id_friend, &id_public))) | 552 | (0 != GNUNET_memcmp (&id_friend, &id_public))) |
553 | { | ||
554 | /* HELLOs are not for the same peer */ | ||
555 | GNUNET_break (0); | ||
556 | if (GNUNET_YES == dsc->remove_files) | ||
557 | remove_garbage (fullname); | ||
558 | return GNUNET_OK; | ||
559 | } | ||
560 | if (GNUNET_OK == | ||
561 | GNUNET_CRYPTO_eddsa_public_key_from_string (filename, | ||
562 | strlen (filename), | ||
563 | &identity.public_key)) | ||
564 | { | ||
565 | if (0 != GNUNET_memcmp (&id, &identity)) | ||
550 | { | 566 | { |
551 | /* HELLOs are not for the same peer */ | 567 | /* HELLOs are not for the same peer */ |
552 | GNUNET_break(0); | 568 | GNUNET_break (0); |
553 | if (GNUNET_YES == dsc->remove_files) | 569 | if (GNUNET_YES == dsc->remove_files) |
554 | remove_garbage(fullname); | 570 | remove_garbage (fullname); |
555 | return GNUNET_OK; | 571 | return GNUNET_OK; |
556 | } | 572 | } |
557 | if (GNUNET_OK == | 573 | } |
558 | GNUNET_CRYPTO_eddsa_public_key_from_string(filename, | ||
559 | strlen(filename), | ||
560 | &identity.public_key)) | ||
561 | { | ||
562 | if (0 != GNUNET_memcmp(&id, &identity)) | ||
563 | { | ||
564 | /* HELLOs are not for the same peer */ | ||
565 | GNUNET_break(0); | ||
566 | if (GNUNET_YES == dsc->remove_files) | ||
567 | remove_garbage(fullname); | ||
568 | return GNUNET_OK; | ||
569 | } | ||
570 | } | ||
571 | 574 | ||
572 | /* ok, found something valid, remember HELLO */ | 575 | /* ok, found something valid, remember HELLO */ |
573 | add_host_to_known_hosts(&id); | 576 | add_host_to_known_hosts (&id); |
574 | if (NULL != r.hello) | 577 | if (NULL != r.hello) |
575 | { | 578 | { |
576 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
577 | "Updating peer `%s' public HELLO \n", | 580 | "Updating peer `%s' public HELLO \n", |
578 | GNUNET_i2s(&id)); | 581 | GNUNET_i2s (&id)); |
579 | update_hello(&id, r.hello); | 582 | update_hello (&id, r.hello); |
580 | GNUNET_free(r.hello); | 583 | GNUNET_free (r.hello); |
581 | } | 584 | } |
582 | if (NULL != r.friend_only_hello) | 585 | if (NULL != r.friend_only_hello) |
583 | { | 586 | { |
584 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
585 | "Updating peer `%s' friend only HELLO \n", | 588 | "Updating peer `%s' friend only HELLO \n", |
586 | GNUNET_i2s(&id)); | 589 | GNUNET_i2s (&id)); |
587 | update_hello(&id, r.friend_only_hello); | 590 | update_hello (&id, r.friend_only_hello); |
588 | GNUNET_free(r.friend_only_hello); | 591 | GNUNET_free (r.friend_only_hello); |
589 | } | 592 | } |
590 | dsc->matched++; | 593 | dsc->matched++; |
591 | return GNUNET_OK; | 594 | return GNUNET_OK; |
592 | } | 595 | } |
@@ -598,39 +601,40 @@ hosts_directory_scan_callback(void *cls, const char *fullname) | |||
598 | * @param cls unused | 601 | * @param cls unused |
599 | */ | 602 | */ |
600 | static void | 603 | static void |
601 | cron_scan_directory_data_hosts(void *cls) | 604 | cron_scan_directory_data_hosts (void *cls) |
602 | { | 605 | { |
603 | static unsigned int retries; | 606 | static unsigned int retries; |
604 | struct DirScanContext dsc; | 607 | struct DirScanContext dsc; |
605 | 608 | ||
606 | (void)cls; | 609 | (void) cls; |
607 | cron_scan = NULL; | 610 | cron_scan = NULL; |
608 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create(networkIdDirectory)) | 611 | if (GNUNET_SYSERR == GNUNET_DISK_directory_create (networkIdDirectory)) |
609 | { | 612 | { |
610 | cron_scan = | 613 | cron_scan = |
611 | GNUNET_SCHEDULER_add_delayed_with_priority(DATA_HOST_FREQ, | 614 | GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, |
612 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 615 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
613 | &cron_scan_directory_data_hosts, | 616 | & |
614 | NULL); | 617 | cron_scan_directory_data_hosts, |
615 | return; | 618 | NULL); |
616 | } | 619 | return; |
620 | } | ||
617 | dsc.matched = 0; | 621 | dsc.matched = 0; |
618 | dsc.remove_files = GNUNET_YES; | 622 | dsc.remove_files = GNUNET_YES; |
619 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 623 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
620 | _("Scanning directory `%s'\n"), | 624 | _ ("Scanning directory `%s'\n"), |
621 | networkIdDirectory); | 625 | networkIdDirectory); |
622 | GNUNET_DISK_directory_scan(networkIdDirectory, | 626 | GNUNET_DISK_directory_scan (networkIdDirectory, |
623 | &hosts_directory_scan_callback, | 627 | &hosts_directory_scan_callback, |
624 | &dsc); | 628 | &dsc); |
625 | if ((0 == dsc.matched) && (0 == (++retries & 31))) | 629 | if ((0 == dsc.matched) && (0 == (++retries & 31))) |
626 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 630 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
627 | _("Still no peers found in `%s'!\n"), | 631 | _ ("Still no peers found in `%s'!\n"), |
628 | networkIdDirectory); | 632 | networkIdDirectory); |
629 | cron_scan = | 633 | cron_scan = |
630 | GNUNET_SCHEDULER_add_delayed_with_priority(DATA_HOST_FREQ, | 634 | GNUNET_SCHEDULER_add_delayed_with_priority (DATA_HOST_FREQ, |
631 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 635 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
632 | &cron_scan_directory_data_hosts, | 636 | &cron_scan_directory_data_hosts, |
633 | NULL); | 637 | NULL); |
634 | } | 638 | } |
635 | 639 | ||
636 | 640 | ||
@@ -642,29 +646,29 @@ cron_scan_directory_data_hosts(void *cls) | |||
642 | * @return merged HELLO | 646 | * @return merged HELLO |
643 | */ | 647 | */ |
644 | static struct GNUNET_HELLO_Message * | 648 | static struct GNUNET_HELLO_Message * |
645 | update_friend_hello(const struct GNUNET_HELLO_Message *hello, | 649 | update_friend_hello (const struct GNUNET_HELLO_Message *hello, |
646 | const struct GNUNET_HELLO_Message *friend_hello) | 650 | const struct GNUNET_HELLO_Message *friend_hello) |
647 | { | 651 | { |
648 | struct GNUNET_HELLO_Message *res; | 652 | struct GNUNET_HELLO_Message *res; |
649 | struct GNUNET_HELLO_Message *tmp; | 653 | struct GNUNET_HELLO_Message *tmp; |
650 | struct GNUNET_PeerIdentity pid; | 654 | struct GNUNET_PeerIdentity pid; |
651 | 655 | ||
652 | if (NULL != friend_hello) | 656 | if (NULL != friend_hello) |
653 | { | 657 | { |
654 | res = GNUNET_HELLO_merge(hello, friend_hello); | 658 | res = GNUNET_HELLO_merge (hello, friend_hello); |
655 | GNUNET_assert(GNUNET_YES == GNUNET_HELLO_is_friend_only(res)); | 659 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); |
656 | return res; | 660 | return res; |
657 | } | 661 | } |
658 | 662 | ||
659 | if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) | 663 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) |
660 | { | 664 | { |
661 | GNUNET_break(0); | 665 | GNUNET_break (0); |
662 | return NULL; | 666 | return NULL; |
663 | } | 667 | } |
664 | tmp = GNUNET_HELLO_create(&pid.public_key, NULL, NULL, GNUNET_YES); | 668 | tmp = GNUNET_HELLO_create (&pid.public_key, NULL, NULL, GNUNET_YES); |
665 | res = GNUNET_HELLO_merge(hello, tmp); | 669 | res = GNUNET_HELLO_merge (hello, tmp); |
666 | GNUNET_free(tmp); | 670 | GNUNET_free (tmp); |
667 | GNUNET_assert(GNUNET_YES == GNUNET_HELLO_is_friend_only(res)); | 671 | GNUNET_assert (GNUNET_YES == GNUNET_HELLO_is_friend_only (res)); |
668 | return res; | 672 | return res; |
669 | } | 673 | } |
670 | 674 | ||
@@ -676,8 +680,8 @@ update_friend_hello(const struct GNUNET_HELLO_Message *hello, | |||
676 | * @param hello the verified (!) hello message | 680 | * @param hello the verified (!) hello message |
677 | */ | 681 | */ |
678 | static void | 682 | static void |
679 | update_hello(const struct GNUNET_PeerIdentity *peer, | 683 | update_hello (const struct GNUNET_PeerIdentity *peer, |
680 | const struct GNUNET_HELLO_Message *hello) | 684 | const struct GNUNET_HELLO_Message *hello) |
681 | { | 685 | { |
682 | char *fn; | 686 | char *fn; |
683 | struct HostEntry *host; | 687 | struct HostEntry *host; |
@@ -692,144 +696,145 @@ update_hello(const struct GNUNET_PeerIdentity *peer, | |||
692 | unsigned int pos; | 696 | unsigned int pos; |
693 | char *buffer; | 697 | char *buffer; |
694 | 698 | ||
695 | host = GNUNET_CONTAINER_multipeermap_get(hostmap, peer); | 699 | host = GNUNET_CONTAINER_multipeermap_get (hostmap, peer); |
696 | GNUNET_assert(NULL != host); | 700 | GNUNET_assert (NULL != host); |
697 | 701 | ||
698 | friend_hello_type = GNUNET_HELLO_is_friend_only(hello); | 702 | friend_hello_type = GNUNET_HELLO_is_friend_only (hello); |
699 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 703 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
700 | "Updating %s HELLO for `%s'\n", | 704 | "Updating %s HELLO for `%s'\n", |
701 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | 705 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", |
702 | GNUNET_i2s(peer)); | 706 | GNUNET_i2s (peer)); |
703 | 707 | ||
704 | dest = NULL; | 708 | dest = NULL; |
705 | if (GNUNET_YES == friend_hello_type) | 709 | if (GNUNET_YES == friend_hello_type) |
706 | { | 710 | { |
707 | dest = &host->friend_only_hello; | 711 | dest = &host->friend_only_hello; |
708 | } | 712 | } |
709 | else | 713 | else |
710 | { | 714 | { |
711 | dest = &host->hello; | 715 | dest = &host->hello; |
712 | } | 716 | } |
713 | 717 | ||
714 | if (NULL == (*dest)) | 718 | if (NULL == (*dest)) |
715 | { | 719 | { |
716 | (*dest) = GNUNET_malloc(GNUNET_HELLO_size(hello)); | 720 | (*dest) = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
717 | GNUNET_memcpy((*dest), hello, GNUNET_HELLO_size(hello)); | 721 | GNUNET_memcpy ((*dest), hello, GNUNET_HELLO_size (hello)); |
718 | } | 722 | } |
719 | else | 723 | else |
724 | { | ||
725 | mrg = GNUNET_HELLO_merge ((*dest), hello); | ||
726 | delta = GNUNET_HELLO_equals (mrg, (*dest), GNUNET_TIME_absolute_get ()); | ||
727 | if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | ||
720 | { | 728 | { |
721 | mrg = GNUNET_HELLO_merge((*dest), hello); | 729 | /* no differences, just ignore the update */ |
722 | delta = GNUNET_HELLO_equals(mrg, (*dest), GNUNET_TIME_absolute_get()); | 730 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
723 | if (delta.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 731 | "No change in %s HELLO for `%s'\n", |
724 | { | 732 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", |
725 | /* no differences, just ignore the update */ | 733 | GNUNET_i2s (peer)); |
726 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 734 | GNUNET_free (mrg); |
727 | "No change in %s HELLO for `%s'\n", | 735 | return; |
728 | (GNUNET_YES == friend_hello_type) ? "friend-only" : "public", | ||
729 | GNUNET_i2s(peer)); | ||
730 | GNUNET_free(mrg); | ||
731 | return; | ||
732 | } | ||
733 | GNUNET_free((*dest)); | ||
734 | (*dest) = mrg; | ||
735 | } | 736 | } |
737 | GNUNET_free ((*dest)); | ||
738 | (*dest) = mrg; | ||
739 | } | ||
736 | 740 | ||
737 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) | 741 | if ((NULL != (host->hello)) && (GNUNET_NO == friend_hello_type)) |
738 | { | 742 | { |
739 | /* Update friend only hello */ | 743 | /* Update friend only hello */ |
740 | mrg = update_friend_hello(host->hello, host->friend_only_hello); | 744 | mrg = update_friend_hello (host->hello, host->friend_only_hello); |
741 | if (NULL != host->friend_only_hello) | 745 | if (NULL != host->friend_only_hello) |
742 | GNUNET_free(host->friend_only_hello); | 746 | GNUNET_free (host->friend_only_hello); |
743 | host->friend_only_hello = mrg; | 747 | host->friend_only_hello = mrg; |
744 | } | 748 | } |
745 | 749 | ||
746 | if (NULL != host->hello) | 750 | if (NULL != host->hello) |
747 | GNUNET_assert((GNUNET_NO == GNUNET_HELLO_is_friend_only(host->hello))); | 751 | GNUNET_assert ((GNUNET_NO == GNUNET_HELLO_is_friend_only (host->hello))); |
748 | if (NULL != host->friend_only_hello) | 752 | if (NULL != host->friend_only_hello) |
749 | GNUNET_assert( | 753 | GNUNET_assert ( |
750 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(host->friend_only_hello))); | 754 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (host->friend_only_hello))); |
751 | 755 | ||
752 | fn = get_host_filename(peer); | 756 | fn = get_host_filename (peer); |
753 | if ((NULL != fn) && (GNUNET_OK == GNUNET_DISK_directory_create_for_file(fn))) | 757 | if ((NULL != fn) && (GNUNET_OK == GNUNET_DISK_directory_create_for_file (fn))) |
754 | { | 758 | { |
755 | store_hello = GNUNET_NO; | 759 | store_hello = GNUNET_NO; |
756 | size = 0; | 760 | size = 0; |
757 | cnt = 0; | 761 | cnt = 0; |
758 | if (NULL != host->hello) | 762 | if (NULL != host->hello) |
759 | (void)GNUNET_HELLO_iterate_addresses(host->hello, | 763 | (void) GNUNET_HELLO_iterate_addresses (host->hello, |
760 | GNUNET_NO, | 764 | GNUNET_NO, |
761 | &count_addresses, | 765 | &count_addresses, |
762 | &cnt); | 766 | &cnt); |
763 | if (cnt > 0) | 767 | if (cnt > 0) |
764 | { | 768 | { |
765 | store_hello = GNUNET_YES; | 769 | store_hello = GNUNET_YES; |
766 | size += GNUNET_HELLO_size(host->hello); | 770 | size += GNUNET_HELLO_size (host->hello); |
767 | } | 771 | } |
768 | cnt = 0; | 772 | cnt = 0; |
769 | if (NULL != host->friend_only_hello) | 773 | if (NULL != host->friend_only_hello) |
770 | (void)GNUNET_HELLO_iterate_addresses(host->friend_only_hello, | 774 | (void) GNUNET_HELLO_iterate_addresses (host->friend_only_hello, |
771 | GNUNET_NO, | 775 | GNUNET_NO, |
772 | &count_addresses, | 776 | &count_addresses, |
773 | &cnt); | 777 | &cnt); |
774 | store_friend_hello = GNUNET_NO; | 778 | store_friend_hello = GNUNET_NO; |
775 | if (0 < cnt) | 779 | if (0 < cnt) |
776 | { | 780 | { |
777 | store_friend_hello = GNUNET_YES; | 781 | store_friend_hello = GNUNET_YES; |
778 | size += GNUNET_HELLO_size(host->friend_only_hello); | 782 | size += GNUNET_HELLO_size (host->friend_only_hello); |
779 | } | 783 | } |
780 | 784 | ||
781 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) | 785 | if ((GNUNET_NO == store_hello) && (GNUNET_NO == store_friend_hello)) |
782 | { | 786 | { |
783 | /* no valid addresses, don't put HELLO on disk; in fact, | 787 | /* no valid addresses, don't put HELLO on disk; in fact, |
784 | if one exists on disk, remove it */ | 788 | if one exists on disk, remove it */ |
785 | (void)unlink(fn); | 789 | (void) unlink (fn); |
786 | } | 790 | } |
791 | else | ||
792 | { | ||
793 | buffer = GNUNET_malloc (size); | ||
794 | pos = 0; | ||
795 | |||
796 | if (GNUNET_YES == store_hello) | ||
797 | { | ||
798 | GNUNET_memcpy (buffer, host->hello, GNUNET_HELLO_size (host->hello)); | ||
799 | pos += GNUNET_HELLO_size (host->hello); | ||
800 | } | ||
801 | if (GNUNET_YES == store_friend_hello) | ||
802 | { | ||
803 | GNUNET_memcpy (&buffer[pos], | ||
804 | host->friend_only_hello, | ||
805 | GNUNET_HELLO_size (host->friend_only_hello)); | ||
806 | pos += GNUNET_HELLO_size (host->friend_only_hello); | ||
807 | } | ||
808 | GNUNET_assert (pos == size); | ||
809 | |||
810 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write (fn, | ||
811 | buffer, | ||
812 | size, | ||
813 | GNUNET_DISK_PERM_USER_READ | ||
814 | | GNUNET_DISK_PERM_USER_WRITE | ||
815 | | GNUNET_DISK_PERM_GROUP_READ | ||
816 | | GNUNET_DISK_PERM_OTHER_READ)) | ||
817 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
787 | else | 818 | else |
788 | { | 819 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
789 | buffer = GNUNET_malloc(size); | 820 | "Stored %s %s HELLO in %s with total size %u\n", |
790 | pos = 0; | 821 | (GNUNET_YES == store_friend_hello) ? "friend-only" : "", |
791 | 822 | (GNUNET_YES == store_hello) ? "public" : "", | |
792 | if (GNUNET_YES == store_hello) | 823 | fn, |
793 | { | 824 | size); |
794 | GNUNET_memcpy(buffer, host->hello, GNUNET_HELLO_size(host->hello)); | 825 | GNUNET_free (buffer); |
795 | pos += GNUNET_HELLO_size(host->hello); | ||
796 | } | ||
797 | if (GNUNET_YES == store_friend_hello) | ||
798 | { | ||
799 | GNUNET_memcpy(&buffer[pos], | ||
800 | host->friend_only_hello, | ||
801 | GNUNET_HELLO_size(host->friend_only_hello)); | ||
802 | pos += GNUNET_HELLO_size(host->friend_only_hello); | ||
803 | } | ||
804 | GNUNET_assert(pos == size); | ||
805 | |||
806 | if (GNUNET_SYSERR == GNUNET_DISK_fn_write(fn, | ||
807 | buffer, | ||
808 | size, | ||
809 | GNUNET_DISK_PERM_USER_READ | | ||
810 | GNUNET_DISK_PERM_USER_WRITE | | ||
811 | GNUNET_DISK_PERM_GROUP_READ | | ||
812 | GNUNET_DISK_PERM_OTHER_READ)) | ||
813 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, "write", fn); | ||
814 | else | ||
815 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
816 | "Stored %s %s HELLO in %s with total size %u\n", | ||
817 | (GNUNET_YES == store_friend_hello) ? "friend-only" : "", | ||
818 | (GNUNET_YES == store_hello) ? "public" : "", | ||
819 | fn, | ||
820 | size); | ||
821 | GNUNET_free(buffer); | ||
822 | } | ||
823 | } | 826 | } |
824 | GNUNET_free_non_null(fn); | 827 | } |
825 | notify_all(host); | 828 | GNUNET_free_non_null (fn); |
829 | notify_all (host); | ||
826 | } | 830 | } |
827 | 831 | ||
828 | 832 | ||
829 | /** | 833 | /** |
830 | * Closure for #add_to_tc() | 834 | * Closure for #add_to_tc() |
831 | */ | 835 | */ |
832 | struct TransmitContext { | 836 | struct TransmitContext |
837 | { | ||
833 | /** | 838 | /** |
834 | * Client to transmit to | 839 | * Client to transmit to |
835 | */ | 840 | */ |
@@ -851,7 +856,7 @@ struct TransmitContext { | |||
851 | * @return #GNUNET_YES (continue to iterate) | 856 | * @return #GNUNET_YES (continue to iterate) |
852 | */ | 857 | */ |
853 | static int | 858 | static int |
854 | add_to_tc(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 859 | add_to_tc (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
855 | { | 860 | { |
856 | struct TransmitContext *tc = cls; | 861 | struct TransmitContext *tc = cls; |
857 | struct HostEntry *pos = value; | 862 | struct HostEntry *pos = value; |
@@ -862,38 +867,38 @@ add_to_tc(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
862 | hs = 0; | 867 | hs = 0; |
863 | 868 | ||
864 | if ((NULL != pos->hello) && (GNUNET_NO == tc->friend_only)) | 869 | if ((NULL != pos->hello) && (GNUNET_NO == tc->friend_only)) |
865 | { | 870 | { |
866 | /* Copy public HELLO */ | 871 | /* Copy public HELLO */ |
867 | hs = GNUNET_HELLO_size(pos->hello); | 872 | hs = GNUNET_HELLO_size (pos->hello); |
868 | GNUNET_assert(hs < GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InfoMessage)); | 873 | GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InfoMessage)); |
869 | env = GNUNET_MQ_msg_extra(im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 874 | env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
870 | GNUNET_memcpy(&im[1], pos->hello, hs); | 875 | GNUNET_memcpy (&im[1], pos->hello, hs); |
871 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 876 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
872 | "Sending public HELLO with size %u for peer `%s'\n", | 877 | "Sending public HELLO with size %u for peer `%s'\n", |
873 | hs, | 878 | hs, |
874 | GNUNET_i2s(key)); | 879 | GNUNET_i2s (key)); |
875 | } | 880 | } |
876 | else if ((NULL != pos->friend_only_hello) && (GNUNET_YES == tc->friend_only)) | 881 | else if ((NULL != pos->friend_only_hello) && (GNUNET_YES == tc->friend_only)) |
877 | { | 882 | { |
878 | /* Copy friend only HELLO */ | 883 | /* Copy friend only HELLO */ |
879 | hs = GNUNET_HELLO_size(pos->friend_only_hello); | 884 | hs = GNUNET_HELLO_size (pos->friend_only_hello); |
880 | GNUNET_assert(hs < GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InfoMessage)); | 885 | GNUNET_assert (hs < GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InfoMessage)); |
881 | env = GNUNET_MQ_msg_extra(im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 886 | env = GNUNET_MQ_msg_extra (im, hs, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
882 | GNUNET_memcpy(&im[1], pos->friend_only_hello, hs); | 887 | GNUNET_memcpy (&im[1], pos->friend_only_hello, hs); |
883 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 888 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
884 | "Sending friend-only HELLO with size %u for peer `%s'\n", | 889 | "Sending friend-only HELLO with size %u for peer `%s'\n", |
885 | hs, | 890 | hs, |
886 | GNUNET_i2s(key)); | 891 | GNUNET_i2s (key)); |
887 | } | 892 | } |
888 | else | 893 | else |
889 | { | 894 | { |
890 | env = GNUNET_MQ_msg(im, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 895 | env = GNUNET_MQ_msg (im, GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
891 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 896 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
892 | "Adding no HELLO for peer `%s'\n", | 897 | "Adding no HELLO for peer `%s'\n", |
893 | GNUNET_i2s(key)); | 898 | GNUNET_i2s (key)); |
894 | } | 899 | } |
895 | im->peer = pos->identity; | 900 | im->peer = pos->identity; |
896 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(tc->client), env); | 901 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (tc->client), env); |
897 | return GNUNET_YES; | 902 | return GNUNET_YES; |
898 | } | 903 | } |
899 | 904 | ||
@@ -906,7 +911,7 @@ add_to_tc(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
906 | * @return #GNUNET_OK (continue iteration) | 911 | * @return #GNUNET_OK (continue iteration) |
907 | */ | 912 | */ |
908 | static int | 913 | static int |
909 | discard_hosts_helper(void *cls, const char *fn) | 914 | discard_hosts_helper (void *cls, const char *fn) |
910 | { | 915 | { |
911 | struct GNUNET_TIME_Absolute *now = cls; | 916 | struct GNUNET_TIME_Absolute *now = cls; |
912 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; | 917 | char buffer[GNUNET_MAX_MESSAGE_SIZE - 1] GNUNET_ALIGN; |
@@ -921,82 +926,82 @@ discard_hosts_helper(void *cls, const char *fn) | |||
921 | char *writebuffer; | 926 | char *writebuffer; |
922 | uint64_t fsize; | 927 | uint64_t fsize; |
923 | 928 | ||
924 | if (GNUNET_OK != GNUNET_DISK_file_size(fn, &fsize, GNUNET_YES, GNUNET_YES)) | 929 | if (GNUNET_OK != GNUNET_DISK_file_size (fn, &fsize, GNUNET_YES, GNUNET_YES)) |
925 | { | 930 | { |
926 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | | 931 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
927 | GNUNET_ERROR_TYPE_BULK, | 932 | | GNUNET_ERROR_TYPE_BULK, |
928 | "fstat", | 933 | "fstat", |
929 | fn); | 934 | fn); |
930 | return GNUNET_OK; | 935 | return GNUNET_OK; |
931 | } | 936 | } |
932 | read_size = GNUNET_DISK_fn_read(fn, buffer, sizeof(buffer)); | 937 | read_size = GNUNET_DISK_fn_read (fn, buffer, sizeof(buffer)); |
933 | 938 | ||
934 | if ((read_size < (int)sizeof(struct GNUNET_MessageHeader)) || | 939 | if ((read_size < (int) sizeof(struct GNUNET_MessageHeader)) || |
935 | (fsize > GNUNET_MAX_MESSAGE_SIZE)) | 940 | (fsize > GNUNET_MAX_MESSAGE_SIZE)) |
936 | { | 941 | { |
937 | if (0 != unlink(fn)) | 942 | if (0 != unlink (fn)) |
938 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | | 943 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
939 | GNUNET_ERROR_TYPE_BULK, | 944 | | GNUNET_ERROR_TYPE_BULK, |
940 | "unlink", | 945 | "unlink", |
941 | fn); | 946 | fn); |
942 | return GNUNET_OK; | 947 | return GNUNET_OK; |
943 | } | 948 | } |
944 | 949 | ||
945 | writebuffer = GNUNET_malloc(read_size); | 950 | writebuffer = GNUNET_malloc (read_size); |
946 | read_pos = 0; | 951 | read_pos = 0; |
947 | write_pos = 0; | 952 | write_pos = 0; |
948 | while (read_pos < read_size) | 953 | while (read_pos < read_size) |
954 | { | ||
955 | /* Check each HELLO */ | ||
956 | hello = (const struct GNUNET_HELLO_Message *) &buffer[read_pos]; | ||
957 | cur_hello_size = GNUNET_HELLO_size (hello); | ||
958 | if (0 == cur_hello_size) | ||
949 | { | 959 | { |
950 | /* Check each HELLO */ | 960 | /* Invalid data, discard */ |
951 | hello = (const struct GNUNET_HELLO_Message *)&buffer[read_pos]; | 961 | if (0 != unlink (fn)) |
952 | cur_hello_size = GNUNET_HELLO_size(hello); | 962 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING |
953 | if (0 == cur_hello_size) | 963 | | GNUNET_ERROR_TYPE_BULK, |
954 | { | 964 | "unlink", |
955 | /* Invalid data, discard */ | 965 | fn); |
956 | if (0 != unlink(fn)) | 966 | GNUNET_free (writebuffer); |
957 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | | 967 | return GNUNET_OK; |
958 | GNUNET_ERROR_TYPE_BULK, | 968 | } |
959 | "unlink", | 969 | new_hello = |
960 | fn); | 970 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_YES, &discard_expired, now); |
961 | GNUNET_free(writebuffer); | 971 | cnt = 0; |
962 | return GNUNET_OK; | 972 | if (NULL != new_hello) |
963 | } | 973 | (void) GNUNET_HELLO_iterate_addresses (hello, |
964 | new_hello = | ||
965 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_YES, &discard_expired, now); | ||
966 | cnt = 0; | ||
967 | if (NULL != new_hello) | ||
968 | (void)GNUNET_HELLO_iterate_addresses(hello, | ||
969 | GNUNET_NO, | 974 | GNUNET_NO, |
970 | &count_addresses, | 975 | &count_addresses, |
971 | &cnt); | 976 | &cnt); |
972 | if ((NULL != new_hello) && (0 < cnt)) | 977 | if ((NULL != new_hello) && (0 < cnt)) |
973 | { | ||
974 | /* Store new HELLO to write it when done */ | ||
975 | new_hello_size = GNUNET_HELLO_size(new_hello); | ||
976 | GNUNET_memcpy(&writebuffer[write_pos], new_hello, new_hello_size); | ||
977 | write_pos += new_hello_size; | ||
978 | } | ||
979 | read_pos += cur_hello_size; | ||
980 | GNUNET_free_non_null(new_hello); | ||
981 | } | ||
982 | |||
983 | if (0 < write_pos) | ||
984 | { | 978 | { |
985 | GNUNET_DISK_fn_write(fn, | 979 | /* Store new HELLO to write it when done */ |
986 | writebuffer, | 980 | new_hello_size = GNUNET_HELLO_size (new_hello); |
987 | write_pos, | 981 | GNUNET_memcpy (&writebuffer[write_pos], new_hello, new_hello_size); |
988 | GNUNET_DISK_PERM_USER_READ | | 982 | write_pos += new_hello_size; |
989 | GNUNET_DISK_PERM_USER_WRITE | | ||
990 | GNUNET_DISK_PERM_GROUP_READ | | ||
991 | GNUNET_DISK_PERM_OTHER_READ); | ||
992 | } | 983 | } |
993 | else if (0 != unlink(fn)) | 984 | read_pos += cur_hello_size; |
994 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING | | 985 | GNUNET_free_non_null (new_hello); |
995 | GNUNET_ERROR_TYPE_BULK, | 986 | } |
996 | "unlink", | ||
997 | fn); | ||
998 | 987 | ||
999 | GNUNET_free(writebuffer); | 988 | if (0 < write_pos) |
989 | { | ||
990 | GNUNET_DISK_fn_write (fn, | ||
991 | writebuffer, | ||
992 | write_pos, | ||
993 | GNUNET_DISK_PERM_USER_READ | ||
994 | | GNUNET_DISK_PERM_USER_WRITE | ||
995 | | GNUNET_DISK_PERM_GROUP_READ | ||
996 | | GNUNET_DISK_PERM_OTHER_READ); | ||
997 | } | ||
998 | else if (0 != unlink (fn)) | ||
999 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | ||
1000 | | GNUNET_ERROR_TYPE_BULK, | ||
1001 | "unlink", | ||
1002 | fn); | ||
1003 | |||
1004 | GNUNET_free (writebuffer); | ||
1000 | return GNUNET_OK; | 1005 | return GNUNET_OK; |
1001 | } | 1006 | } |
1002 | 1007 | ||
@@ -1008,20 +1013,20 @@ discard_hosts_helper(void *cls, const char *fn) | |||
1008 | * @param cls unused | 1013 | * @param cls unused |
1009 | */ | 1014 | */ |
1010 | static void | 1015 | static void |
1011 | cron_clean_data_hosts(void *cls) | 1016 | cron_clean_data_hosts (void *cls) |
1012 | { | 1017 | { |
1013 | struct GNUNET_TIME_Absolute now; | 1018 | struct GNUNET_TIME_Absolute now; |
1014 | 1019 | ||
1015 | (void)cls; | 1020 | (void) cls; |
1016 | cron_clean = NULL; | 1021 | cron_clean = NULL; |
1017 | now = GNUNET_TIME_absolute_get(); | 1022 | now = GNUNET_TIME_absolute_get (); |
1018 | GNUNET_log(GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, | 1023 | GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, |
1019 | _("Cleaning up directory `%s'\n"), | 1024 | _ ("Cleaning up directory `%s'\n"), |
1020 | networkIdDirectory); | 1025 | networkIdDirectory); |
1021 | GNUNET_DISK_directory_scan(networkIdDirectory, &discard_hosts_helper, &now); | 1026 | GNUNET_DISK_directory_scan (networkIdDirectory, &discard_hosts_helper, &now); |
1022 | cron_clean = GNUNET_SCHEDULER_add_delayed(DATA_HOST_CLEAN_FREQ, | 1027 | cron_clean = GNUNET_SCHEDULER_add_delayed (DATA_HOST_CLEAN_FREQ, |
1023 | &cron_clean_data_hosts, | 1028 | &cron_clean_data_hosts, |
1024 | NULL); | 1029 | NULL); |
1025 | } | 1030 | } |
1026 | 1031 | ||
1027 | 1032 | ||
@@ -1033,16 +1038,16 @@ cron_clean_data_hosts(void *cls) | |||
1033 | * @return #GNUNET_OK if @a hello is well-formed | 1038 | * @return #GNUNET_OK if @a hello is well-formed |
1034 | */ | 1039 | */ |
1035 | static int | 1040 | static int |
1036 | check_hello(void *cls, const struct GNUNET_HELLO_Message *hello) | 1041 | check_hello (void *cls, const struct GNUNET_HELLO_Message *hello) |
1037 | { | 1042 | { |
1038 | struct GNUNET_PeerIdentity pid; | 1043 | struct GNUNET_PeerIdentity pid; |
1039 | 1044 | ||
1040 | (void)cls; | 1045 | (void) cls; |
1041 | if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) | 1046 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) |
1042 | { | 1047 | { |
1043 | GNUNET_break(0); | 1048 | GNUNET_break (0); |
1044 | return GNUNET_SYSERR; | 1049 | return GNUNET_SYSERR; |
1045 | } | 1050 | } |
1046 | return GNUNET_OK; | 1051 | return GNUNET_OK; |
1047 | } | 1052 | } |
1048 | 1053 | ||
@@ -1054,18 +1059,18 @@ check_hello(void *cls, const struct GNUNET_HELLO_Message *hello) | |||
1054 | * @param hello the actual message | 1059 | * @param hello the actual message |
1055 | */ | 1060 | */ |
1056 | static void | 1061 | static void |
1057 | handle_hello(void *cls, const struct GNUNET_HELLO_Message *hello) | 1062 | handle_hello (void *cls, const struct GNUNET_HELLO_Message *hello) |
1058 | { | 1063 | { |
1059 | struct GNUNET_SERVICE_Client *client = cls; | 1064 | struct GNUNET_SERVICE_Client *client = cls; |
1060 | struct GNUNET_PeerIdentity pid; | 1065 | struct GNUNET_PeerIdentity pid; |
1061 | 1066 | ||
1062 | GNUNET_assert(GNUNET_OK == GNUNET_HELLO_get_id(hello, &pid)); | 1067 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &pid)); |
1063 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1068 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1064 | "HELLO message received for peer `%s'\n", | 1069 | "HELLO message received for peer `%s'\n", |
1065 | GNUNET_i2s(&pid)); | 1070 | GNUNET_i2s (&pid)); |
1066 | add_host_to_known_hosts(&pid); | 1071 | add_host_to_known_hosts (&pid); |
1067 | update_hello(&pid, hello); | 1072 | update_hello (&pid, hello); |
1068 | GNUNET_SERVICE_client_continue(client); | 1073 | GNUNET_SERVICE_client_continue (client); |
1069 | } | 1074 | } |
1070 | 1075 | ||
1071 | 1076 | ||
@@ -1076,25 +1081,25 @@ handle_hello(void *cls, const struct GNUNET_HELLO_Message *hello) | |||
1076 | * @param lpm the actual message | 1081 | * @param lpm the actual message |
1077 | */ | 1082 | */ |
1078 | static void | 1083 | static void |
1079 | handle_get(void *cls, const struct ListPeerMessage *lpm) | 1084 | handle_get (void *cls, const struct ListPeerMessage *lpm) |
1080 | { | 1085 | { |
1081 | struct GNUNET_SERVICE_Client *client = cls; | 1086 | struct GNUNET_SERVICE_Client *client = cls; |
1082 | struct TransmitContext tcx; | 1087 | struct TransmitContext tcx; |
1083 | struct GNUNET_MessageHeader *msg; | 1088 | struct GNUNET_MessageHeader *msg; |
1084 | struct GNUNET_MQ_Envelope *env; | 1089 | struct GNUNET_MQ_Envelope *env; |
1085 | 1090 | ||
1086 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1091 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1087 | "GET message received for peer `%s'\n", | 1092 | "GET message received for peer `%s'\n", |
1088 | GNUNET_i2s(&lpm->peer)); | 1093 | GNUNET_i2s (&lpm->peer)); |
1089 | tcx.friend_only = ntohl(lpm->include_friend_only); | 1094 | tcx.friend_only = ntohl (lpm->include_friend_only); |
1090 | tcx.client = client; | 1095 | tcx.client = client; |
1091 | GNUNET_CONTAINER_multipeermap_get_multiple(hostmap, | 1096 | GNUNET_CONTAINER_multipeermap_get_multiple (hostmap, |
1092 | &lpm->peer, | 1097 | &lpm->peer, |
1093 | &add_to_tc, | 1098 | &add_to_tc, |
1094 | &tcx); | 1099 | &tcx); |
1095 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 1100 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
1096 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 1101 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
1097 | GNUNET_SERVICE_client_continue(client); | 1102 | GNUNET_SERVICE_client_continue (client); |
1098 | } | 1103 | } |
1099 | 1104 | ||
1100 | 1105 | ||
@@ -1105,20 +1110,20 @@ handle_get(void *cls, const struct ListPeerMessage *lpm) | |||
1105 | * @param lapm the actual message | 1110 | * @param lapm the actual message |
1106 | */ | 1111 | */ |
1107 | static void | 1112 | static void |
1108 | handle_get_all(void *cls, const struct ListAllPeersMessage *lapm) | 1113 | handle_get_all (void *cls, const struct ListAllPeersMessage *lapm) |
1109 | { | 1114 | { |
1110 | struct GNUNET_SERVICE_Client *client = cls; | 1115 | struct GNUNET_SERVICE_Client *client = cls; |
1111 | struct TransmitContext tcx; | 1116 | struct TransmitContext tcx; |
1112 | struct GNUNET_MQ_Envelope *env; | 1117 | struct GNUNET_MQ_Envelope *env; |
1113 | struct GNUNET_MessageHeader *msg; | 1118 | struct GNUNET_MessageHeader *msg; |
1114 | 1119 | ||
1115 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "GET_ALL message received\n"); | 1120 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "GET_ALL message received\n"); |
1116 | tcx.friend_only = ntohl(lapm->include_friend_only); | 1121 | tcx.friend_only = ntohl (lapm->include_friend_only); |
1117 | tcx.client = client; | 1122 | tcx.client = client; |
1118 | GNUNET_CONTAINER_multipeermap_iterate(hostmap, &add_to_tc, &tcx); | 1123 | GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx); |
1119 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 1124 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
1120 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 1125 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
1121 | GNUNET_SERVICE_client_continue(client); | 1126 | GNUNET_SERVICE_client_continue (client); |
1122 | } | 1127 | } |
1123 | 1128 | ||
1124 | 1129 | ||
@@ -1129,7 +1134,7 @@ handle_get_all(void *cls, const struct ListAllPeersMessage *lapm) | |||
1129 | * @param nm the actual message | 1134 | * @param nm the actual message |
1130 | */ | 1135 | */ |
1131 | static void | 1136 | static void |
1132 | handle_notify(void *cls, const struct NotifyMessage *nm) | 1137 | handle_notify (void *cls, const struct NotifyMessage *nm) |
1133 | { | 1138 | { |
1134 | struct GNUNET_SERVICE_Client *client = cls; | 1139 | struct GNUNET_SERVICE_Client *client = cls; |
1135 | struct GNUNET_MQ_Handle *mq; | 1140 | struct GNUNET_MQ_Handle *mq; |
@@ -1137,19 +1142,19 @@ handle_notify(void *cls, const struct NotifyMessage *nm) | |||
1137 | struct GNUNET_MQ_Envelope *env; | 1142 | struct GNUNET_MQ_Envelope *env; |
1138 | struct GNUNET_MessageHeader *msg; | 1143 | struct GNUNET_MessageHeader *msg; |
1139 | 1144 | ||
1140 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "NOTIFY message received\n"); | 1145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "NOTIFY message received\n"); |
1141 | mq = GNUNET_SERVICE_client_get_mq(client); | 1146 | mq = GNUNET_SERVICE_client_get_mq (client); |
1142 | GNUNET_SERVICE_client_mark_monitor(client); | 1147 | GNUNET_SERVICE_client_mark_monitor (client); |
1143 | if (ntohl(nm->include_friend_only)) | 1148 | if (ntohl (nm->include_friend_only)) |
1144 | GNUNET_notification_context_add(notify_friend_only_list, mq); | 1149 | GNUNET_notification_context_add (notify_friend_only_list, mq); |
1145 | else | 1150 | else |
1146 | GNUNET_notification_context_add(notify_list, mq); | 1151 | GNUNET_notification_context_add (notify_list, mq); |
1147 | tcx.friend_only = ntohl(nm->include_friend_only); | 1152 | tcx.friend_only = ntohl (nm->include_friend_only); |
1148 | tcx.client = client; | 1153 | tcx.client = client; |
1149 | GNUNET_CONTAINER_multipeermap_iterate(hostmap, &add_to_tc, &tcx); | 1154 | GNUNET_CONTAINER_multipeermap_iterate (hostmap, &add_to_tc, &tcx); |
1150 | env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); | 1155 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END); |
1151 | GNUNET_MQ_send(GNUNET_SERVICE_client_get_mq(client), env); | 1156 | GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (client), env); |
1152 | GNUNET_SERVICE_client_continue(client); | 1157 | GNUNET_SERVICE_client_continue (client); |
1153 | } | 1158 | } |
1154 | 1159 | ||
1155 | 1160 | ||
@@ -1162,12 +1167,12 @@ handle_notify(void *cls, const struct NotifyMessage *nm) | |||
1162 | * @return @a client | 1167 | * @return @a client |
1163 | */ | 1168 | */ |
1164 | static void * | 1169 | static void * |
1165 | client_connect_cb(void *cls, | 1170 | client_connect_cb (void *cls, |
1166 | struct GNUNET_SERVICE_Client *client, | 1171 | struct GNUNET_SERVICE_Client *client, |
1167 | struct GNUNET_MQ_Handle *mq) | 1172 | struct GNUNET_MQ_Handle *mq) |
1168 | { | 1173 | { |
1169 | (void)cls; | 1174 | (void) cls; |
1170 | (void)mq; | 1175 | (void) mq; |
1171 | return client; | 1176 | return client; |
1172 | } | 1177 | } |
1173 | 1178 | ||
@@ -1180,12 +1185,12 @@ client_connect_cb(void *cls, | |||
1180 | * @param app_ctx should be @a client | 1185 | * @param app_ctx should be @a client |
1181 | */ | 1186 | */ |
1182 | static void | 1187 | static void |
1183 | client_disconnect_cb(void *cls, | 1188 | client_disconnect_cb (void *cls, |
1184 | struct GNUNET_SERVICE_Client *client, | 1189 | struct GNUNET_SERVICE_Client *client, |
1185 | void *app_ctx) | 1190 | void *app_ctx) |
1186 | { | 1191 | { |
1187 | (void)cls; | 1192 | (void) cls; |
1188 | GNUNET_assert(app_ctx == client); | 1193 | GNUNET_assert (app_ctx == client); |
1189 | } | 1194 | } |
1190 | 1195 | ||
1191 | 1196 | ||
@@ -1198,15 +1203,15 @@ client_disconnect_cb(void *cls, | |||
1198 | * @return #GNUNET_YES (continue to iterate) | 1203 | * @return #GNUNET_YES (continue to iterate) |
1199 | */ | 1204 | */ |
1200 | static int | 1205 | static int |
1201 | free_host_entry(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | 1206 | free_host_entry (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
1202 | { | 1207 | { |
1203 | struct HostEntry *he = value; | 1208 | struct HostEntry *he = value; |
1204 | 1209 | ||
1205 | (void)cls; | 1210 | (void) cls; |
1206 | (void)key; | 1211 | (void) key; |
1207 | GNUNET_free_non_null(he->hello); | 1212 | GNUNET_free_non_null (he->hello); |
1208 | GNUNET_free_non_null(he->friend_only_hello); | 1213 | GNUNET_free_non_null (he->friend_only_hello); |
1209 | GNUNET_free(he); | 1214 | GNUNET_free (he); |
1210 | return GNUNET_YES; | 1215 | return GNUNET_YES; |
1211 | } | 1216 | } |
1212 | 1217 | ||
@@ -1217,36 +1222,36 @@ free_host_entry(void *cls, const struct GNUNET_PeerIdentity *key, void *value) | |||
1217 | * @param cls unused | 1222 | * @param cls unused |
1218 | */ | 1223 | */ |
1219 | static void | 1224 | static void |
1220 | shutdown_task(void *cls) | 1225 | shutdown_task (void *cls) |
1221 | { | 1226 | { |
1222 | (void)cls; | 1227 | (void) cls; |
1223 | GNUNET_notification_context_destroy(notify_list); | 1228 | GNUNET_notification_context_destroy (notify_list); |
1224 | notify_list = NULL; | 1229 | notify_list = NULL; |
1225 | GNUNET_notification_context_destroy(notify_friend_only_list); | 1230 | GNUNET_notification_context_destroy (notify_friend_only_list); |
1226 | notify_friend_only_list = NULL; | 1231 | notify_friend_only_list = NULL; |
1227 | 1232 | ||
1228 | GNUNET_CONTAINER_multipeermap_iterate(hostmap, &free_host_entry, NULL); | 1233 | GNUNET_CONTAINER_multipeermap_iterate (hostmap, &free_host_entry, NULL); |
1229 | GNUNET_CONTAINER_multipeermap_destroy(hostmap); | 1234 | GNUNET_CONTAINER_multipeermap_destroy (hostmap); |
1230 | if (NULL != stats) | 1235 | if (NULL != stats) |
1231 | { | 1236 | { |
1232 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 1237 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1233 | stats = NULL; | 1238 | stats = NULL; |
1234 | } | 1239 | } |
1235 | if (NULL != cron_clean) | 1240 | if (NULL != cron_clean) |
1236 | { | 1241 | { |
1237 | GNUNET_SCHEDULER_cancel(cron_clean); | 1242 | GNUNET_SCHEDULER_cancel (cron_clean); |
1238 | cron_clean = NULL; | 1243 | cron_clean = NULL; |
1239 | } | 1244 | } |
1240 | if (NULL != cron_scan) | 1245 | if (NULL != cron_scan) |
1241 | { | 1246 | { |
1242 | GNUNET_SCHEDULER_cancel(cron_scan); | 1247 | GNUNET_SCHEDULER_cancel (cron_scan); |
1243 | cron_scan = NULL; | 1248 | cron_scan = NULL; |
1244 | } | 1249 | } |
1245 | if (NULL != networkIdDirectory) | 1250 | if (NULL != networkIdDirectory) |
1246 | { | 1251 | { |
1247 | GNUNET_free(networkIdDirectory); | 1252 | GNUNET_free (networkIdDirectory); |
1248 | networkIdDirectory = NULL; | 1253 | networkIdDirectory = NULL; |
1249 | } | 1254 | } |
1250 | } | 1255 | } |
1251 | 1256 | ||
1252 | 1257 | ||
@@ -1258,9 +1263,9 @@ shutdown_task(void *cls) | |||
1258 | * @param service the initialized service | 1263 | * @param service the initialized service |
1259 | */ | 1264 | */ |
1260 | static void | 1265 | static void |
1261 | run(void *cls, | 1266 | run (void *cls, |
1262 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1267 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1263 | struct GNUNET_SERVICE_Handle *service) | 1268 | struct GNUNET_SERVICE_Handle *service) |
1264 | { | 1269 | { |
1265 | char *peerdir; | 1270 | char *peerdir; |
1266 | char *ip; | 1271 | char *ip; |
@@ -1268,95 +1273,95 @@ run(void *cls, | |||
1268 | int noio; | 1273 | int noio; |
1269 | int use_included; | 1274 | int use_included; |
1270 | 1275 | ||
1271 | (void)cls; | 1276 | (void) cls; |
1272 | (void)service; | 1277 | (void) service; |
1273 | hostmap = GNUNET_CONTAINER_multipeermap_create(1024, GNUNET_YES); | 1278 | hostmap = GNUNET_CONTAINER_multipeermap_create (1024, GNUNET_YES); |
1274 | stats = GNUNET_STATISTICS_create("peerinfo", cfg); | 1279 | stats = GNUNET_STATISTICS_create ("peerinfo", cfg); |
1275 | notify_list = GNUNET_notification_context_create(0); | 1280 | notify_list = GNUNET_notification_context_create (0); |
1276 | notify_friend_only_list = GNUNET_notification_context_create(0); | 1281 | notify_friend_only_list = GNUNET_notification_context_create (0); |
1277 | noio = GNUNET_CONFIGURATION_get_value_yesno(cfg, "peerinfo", "NO_IO"); | 1282 | noio = GNUNET_CONFIGURATION_get_value_yesno (cfg, "peerinfo", "NO_IO"); |
1278 | use_included = GNUNET_CONFIGURATION_get_value_yesno(cfg, | 1283 | use_included = GNUNET_CONFIGURATION_get_value_yesno (cfg, |
1279 | "peerinfo", | 1284 | "peerinfo", |
1280 | "USE_INCLUDED_HELLOS"); | 1285 | "USE_INCLUDED_HELLOS"); |
1281 | if (GNUNET_SYSERR == use_included) | 1286 | if (GNUNET_SYSERR == use_included) |
1282 | use_included = GNUNET_NO; | 1287 | use_included = GNUNET_NO; |
1283 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 1288 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
1284 | if (GNUNET_YES != noio) | 1289 | if (GNUNET_YES != noio) |
1290 | { | ||
1291 | GNUNET_assert ( | ||
1292 | GNUNET_OK == | ||
1293 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
1294 | "peerinfo", | ||
1295 | "HOSTS", | ||
1296 | &networkIdDirectory)); | ||
1297 | if (GNUNET_OK != GNUNET_DISK_directory_create (networkIdDirectory)) | ||
1285 | { | 1298 | { |
1286 | GNUNET_assert( | 1299 | GNUNET_SCHEDULER_shutdown (); |
1287 | GNUNET_OK == | 1300 | return; |
1288 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 1301 | } |
1289 | "peerinfo", | 1302 | |
1290 | "HOSTS", | 1303 | cron_scan = |
1291 | &networkIdDirectory)); | 1304 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1292 | if (GNUNET_OK != GNUNET_DISK_directory_create(networkIdDirectory)) | 1305 | &cron_scan_directory_data_hosts, |
1293 | { | 1306 | NULL); |
1294 | GNUNET_SCHEDULER_shutdown(); | 1307 | |
1295 | return; | 1308 | cron_clean = |
1296 | } | 1309 | GNUNET_SCHEDULER_add_with_priority (GNUNET_SCHEDULER_PRIORITY_IDLE, |
1297 | 1310 | &cron_clean_data_hosts, | |
1298 | cron_scan = | 1311 | NULL); |
1299 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | 1312 | if (GNUNET_YES == use_included) |
1300 | &cron_scan_directory_data_hosts, | 1313 | { |
1301 | NULL); | 1314 | ip = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR); |
1302 | 1315 | GNUNET_asprintf (&peerdir, "%shellos", ip); | |
1303 | cron_clean = | 1316 | GNUNET_free (ip); |
1304 | GNUNET_SCHEDULER_add_with_priority(GNUNET_SCHEDULER_PRIORITY_IDLE, | 1317 | |
1305 | &cron_clean_data_hosts, | 1318 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1306 | NULL); | 1319 | _ ("Importing HELLOs from `%s'\n"), |
1307 | if (GNUNET_YES == use_included) | 1320 | peerdir); |
1308 | { | 1321 | dsc.matched = 0; |
1309 | ip = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_DATADIR); | 1322 | dsc.remove_files = GNUNET_NO; |
1310 | GNUNET_asprintf(&peerdir, "%shellos", ip); | 1323 | |
1311 | GNUNET_free(ip); | 1324 | GNUNET_DISK_directory_scan (peerdir, |
1312 | 1325 | &hosts_directory_scan_callback, | |
1313 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 1326 | &dsc); |
1314 | _("Importing HELLOs from `%s'\n"), | 1327 | GNUNET_free (peerdir); |
1315 | peerdir); | 1328 | } |
1316 | dsc.matched = 0; | 1329 | else |
1317 | dsc.remove_files = GNUNET_NO; | 1330 | { |
1318 | 1331 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | |
1319 | GNUNET_DISK_directory_scan(peerdir, | 1332 | _ ("Skipping import of included HELLOs\n")); |
1320 | &hosts_directory_scan_callback, | ||
1321 | &dsc); | ||
1322 | GNUNET_free(peerdir); | ||
1323 | } | ||
1324 | else | ||
1325 | { | ||
1326 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
1327 | _("Skipping import of included HELLOs\n")); | ||
1328 | } | ||
1329 | } | 1333 | } |
1334 | } | ||
1330 | } | 1335 | } |
1331 | 1336 | ||
1332 | 1337 | ||
1333 | /** | 1338 | /** |
1334 | * Define "main" method using service macro. | 1339 | * Define "main" method using service macro. |
1335 | */ | 1340 | */ |
1336 | GNUNET_SERVICE_MAIN( | 1341 | GNUNET_SERVICE_MAIN ( |
1337 | "peerinfo", | 1342 | "peerinfo", |
1338 | GNUNET_SERVICE_OPTION_NONE, | 1343 | GNUNET_SERVICE_OPTION_NONE, |
1339 | &run, | 1344 | &run, |
1340 | &client_connect_cb, | 1345 | &client_connect_cb, |
1341 | &client_disconnect_cb, | 1346 | &client_disconnect_cb, |
1342 | NULL, | 1347 | NULL, |
1343 | GNUNET_MQ_hd_var_size(hello, | 1348 | GNUNET_MQ_hd_var_size (hello, |
1344 | GNUNET_MESSAGE_TYPE_HELLO, | 1349 | GNUNET_MESSAGE_TYPE_HELLO, |
1345 | struct GNUNET_HELLO_Message, | 1350 | struct GNUNET_HELLO_Message, |
1346 | NULL), | 1351 | NULL), |
1347 | GNUNET_MQ_hd_fixed_size(get, | 1352 | GNUNET_MQ_hd_fixed_size (get, |
1348 | GNUNET_MESSAGE_TYPE_PEERINFO_GET, | 1353 | GNUNET_MESSAGE_TYPE_PEERINFO_GET, |
1349 | struct ListPeerMessage, | 1354 | struct ListPeerMessage, |
1350 | NULL), | 1355 | NULL), |
1351 | GNUNET_MQ_hd_fixed_size(get_all, | 1356 | GNUNET_MQ_hd_fixed_size (get_all, |
1352 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, | 1357 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, |
1353 | struct ListAllPeersMessage, | 1358 | struct ListAllPeersMessage, |
1354 | NULL), | 1359 | NULL), |
1355 | GNUNET_MQ_hd_fixed_size(notify, | 1360 | GNUNET_MQ_hd_fixed_size (notify, |
1356 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, | 1361 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, |
1357 | struct NotifyMessage, | 1362 | struct NotifyMessage, |
1358 | NULL), | 1363 | NULL), |
1359 | GNUNET_MQ_handler_end()); | 1364 | GNUNET_MQ_handler_end ()); |
1360 | 1365 | ||
1361 | 1366 | ||
1362 | /* end of gnunet-service-peerinfo.c */ | 1367 | /* end of gnunet-service-peerinfo.c */ |
diff --git a/src/peerinfo/peerinfo.h b/src/peerinfo/peerinfo.h index 85501593e..69992170f 100644 --- a/src/peerinfo/peerinfo.h +++ b/src/peerinfo/peerinfo.h | |||
@@ -39,7 +39,8 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
39 | * Message requesting a listing of peers, | 39 | * Message requesting a listing of peers, |
40 | * restricted to the specified peer identity. | 40 | * restricted to the specified peer identity. |
41 | */ | 41 | */ |
42 | struct ListPeerMessage { | 42 | struct ListPeerMessage |
43 | { | ||
43 | /** | 44 | /** |
44 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET | 45 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET |
45 | */ | 46 | */ |
@@ -61,7 +62,8 @@ struct ListPeerMessage { | |||
61 | * Message requesting a listing of all peers, | 62 | * Message requesting a listing of all peers, |
62 | * restricted to the specified peer identity. | 63 | * restricted to the specified peer identity. |
63 | */ | 64 | */ |
64 | struct ListAllPeersMessage { | 65 | struct ListAllPeersMessage |
66 | { | ||
65 | /** | 67 | /** |
66 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL | 68 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL |
67 | */ | 69 | */ |
@@ -77,7 +79,8 @@ struct ListAllPeersMessage { | |||
77 | /** | 79 | /** |
78 | * Header for all communications. | 80 | * Header for all communications. |
79 | */ | 81 | */ |
80 | struct NotifyMessage { | 82 | struct NotifyMessage |
83 | { | ||
81 | /** | 84 | /** |
82 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY | 85 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY |
83 | */ | 86 | */ |
@@ -97,7 +100,8 @@ struct NotifyMessage { | |||
97 | * Check the header.size field to see if a HELLO is | 100 | * Check the header.size field to see if a HELLO is |
98 | * present. | 101 | * present. |
99 | */ | 102 | */ |
100 | struct InfoMessage { | 103 | struct InfoMessage |
104 | { | ||
101 | /** | 105 | /** |
102 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO | 106 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_INFO |
103 | */ | 107 | */ |
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index ada6f5462..52d7b4192 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -28,13 +28,14 @@ | |||
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | #include "peerinfo.h" | 29 | #include "peerinfo.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerinfo-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "peerinfo-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Context for an iteration request. | 35 | * Context for an iteration request. |
36 | */ | 36 | */ |
37 | struct GNUNET_PEERINFO_IteratorContext { | 37 | struct GNUNET_PEERINFO_IteratorContext |
38 | { | ||
38 | /** | 39 | /** |
39 | * Kept in a DLL. | 40 | * Kept in a DLL. |
40 | */ | 41 | */ |
@@ -80,7 +81,8 @@ struct GNUNET_PEERINFO_IteratorContext { | |||
80 | /** | 81 | /** |
81 | * Handle to the peerinfo service. | 82 | * Handle to the peerinfo service. |
82 | */ | 83 | */ |
83 | struct GNUNET_PEERINFO_Handle { | 84 | struct GNUNET_PEERINFO_Handle |
85 | { | ||
84 | /** | 86 | /** |
85 | * Our configuration. | 87 | * Our configuration. |
86 | */ | 88 | */ |
@@ -114,7 +116,7 @@ struct GNUNET_PEERINFO_Handle { | |||
114 | * @param h handle to the service | 116 | * @param h handle to the service |
115 | */ | 117 | */ |
116 | static void | 118 | static void |
117 | reconnect(struct GNUNET_PEERINFO_Handle *h); | 119 | reconnect (struct GNUNET_PEERINFO_Handle *h); |
118 | 120 | ||
119 | 121 | ||
120 | /** | 122 | /** |
@@ -125,18 +127,18 @@ reconnect(struct GNUNET_PEERINFO_Handle *h); | |||
125 | * establishment may happen asynchronously). | 127 | * establishment may happen asynchronously). |
126 | */ | 128 | */ |
127 | struct GNUNET_PEERINFO_Handle * | 129 | struct GNUNET_PEERINFO_Handle * |
128 | GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | 130 | GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
129 | { | 131 | { |
130 | struct GNUNET_PEERINFO_Handle *h; | 132 | struct GNUNET_PEERINFO_Handle *h; |
131 | 133 | ||
132 | h = GNUNET_new(struct GNUNET_PEERINFO_Handle); | 134 | h = GNUNET_new (struct GNUNET_PEERINFO_Handle); |
133 | h->cfg = cfg; | 135 | h->cfg = cfg; |
134 | reconnect(h); | 136 | reconnect (h); |
135 | if (NULL == h->mq) | 137 | if (NULL == h->mq) |
136 | { | 138 | { |
137 | GNUNET_free(h); | 139 | GNUNET_free (h); |
138 | return NULL; | 140 | return NULL; |
139 | } | 141 | } |
140 | return h; | 142 | return h; |
141 | } | 143 | } |
142 | 144 | ||
@@ -151,28 +153,28 @@ GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
151 | * @param h handle to disconnect | 153 | * @param h handle to disconnect |
152 | */ | 154 | */ |
153 | void | 155 | void |
154 | GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h) | 156 | GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h) |
155 | { | 157 | { |
156 | struct GNUNET_PEERINFO_IteratorContext *ic; | 158 | struct GNUNET_PEERINFO_IteratorContext *ic; |
157 | 159 | ||
158 | while (NULL != (ic = h->ic_head)) | 160 | while (NULL != (ic = h->ic_head)) |
159 | { | 161 | { |
160 | GNUNET_CONTAINER_DLL_remove(h->ic_head, | 162 | GNUNET_CONTAINER_DLL_remove (h->ic_head, |
161 | h->ic_tail, | 163 | h->ic_tail, |
162 | ic); | 164 | ic); |
163 | GNUNET_free(ic); | 165 | GNUNET_free (ic); |
164 | } | 166 | } |
165 | if (NULL != h->mq) | 167 | if (NULL != h->mq) |
166 | { | 168 | { |
167 | GNUNET_MQ_destroy(h->mq); | 169 | GNUNET_MQ_destroy (h->mq); |
168 | h->mq = NULL; | 170 | h->mq = NULL; |
169 | } | 171 | } |
170 | if (NULL != h->r_task) | 172 | if (NULL != h->r_task) |
171 | { | 173 | { |
172 | GNUNET_SCHEDULER_cancel(h->r_task); | 174 | GNUNET_SCHEDULER_cancel (h->r_task); |
173 | h->r_task = NULL; | 175 | h->r_task = NULL; |
174 | } | 176 | } |
175 | GNUNET_free(h); | 177 | GNUNET_free (h); |
176 | } | 178 | } |
177 | 179 | ||
178 | 180 | ||
@@ -182,12 +184,12 @@ GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h) | |||
182 | * @param cls the `struct GNUNET_PEERINFO_Handle *` | 184 | * @param cls the `struct GNUNET_PEERINFO_Handle *` |
183 | */ | 185 | */ |
184 | static void | 186 | static void |
185 | reconnect_task(void *cls) | 187 | reconnect_task (void *cls) |
186 | { | 188 | { |
187 | struct GNUNET_PEERINFO_Handle *h = cls; | 189 | struct GNUNET_PEERINFO_Handle *h = cls; |
188 | 190 | ||
189 | h->r_task = NULL; | 191 | h->r_task = NULL; |
190 | reconnect(h); | 192 | reconnect (h); |
191 | } | 193 | } |
192 | 194 | ||
193 | 195 | ||
@@ -197,26 +199,26 @@ reconnect_task(void *cls) | |||
197 | * @param h handle to reconnect | 199 | * @param h handle to reconnect |
198 | */ | 200 | */ |
199 | static void | 201 | static void |
200 | do_reconnect(struct GNUNET_PEERINFO_Handle *h) | 202 | do_reconnect (struct GNUNET_PEERINFO_Handle *h) |
201 | { | 203 | { |
202 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 204 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
203 | 205 | ||
204 | GNUNET_MQ_destroy(h->mq); | 206 | GNUNET_MQ_destroy (h->mq); |
205 | h->mq = NULL; | 207 | h->mq = NULL; |
206 | if (NULL != ic) | 208 | if (NULL != ic) |
207 | { | 209 | { |
208 | GNUNET_CONTAINER_DLL_remove(h->ic_head, | 210 | GNUNET_CONTAINER_DLL_remove (h->ic_head, |
209 | h->ic_tail, | 211 | h->ic_tail, |
210 | ic); | 212 | ic); |
211 | if (NULL != ic->callback) | 213 | if (NULL != ic->callback) |
212 | ic->callback(ic->callback_cls, | 214 | ic->callback (ic->callback_cls, |
213 | NULL, | 215 | NULL, |
214 | NULL, | 216 | NULL, |
215 | _("Failed to receive response from `PEERINFO' service.")); | 217 | _ ("Failed to receive response from `PEERINFO' service.")); |
216 | GNUNET_free(ic); | 218 | GNUNET_free (ic); |
217 | } | 219 | } |
218 | h->r_task = GNUNET_SCHEDULER_add_now(&reconnect_task, | 220 | h->r_task = GNUNET_SCHEDULER_add_now (&reconnect_task, |
219 | h); | 221 | h); |
220 | } | 222 | } |
221 | 223 | ||
222 | 224 | ||
@@ -228,12 +230,12 @@ do_reconnect(struct GNUNET_PEERINFO_Handle *h) | |||
228 | * @param error error code | 230 | * @param error error code |
229 | */ | 231 | */ |
230 | static void | 232 | static void |
231 | mq_error_handler(void *cls, | 233 | mq_error_handler (void *cls, |
232 | enum GNUNET_MQ_Error error) | 234 | enum GNUNET_MQ_Error error) |
233 | { | 235 | { |
234 | struct GNUNET_PEERINFO_Handle *h = cls; | 236 | struct GNUNET_PEERINFO_Handle *h = cls; |
235 | 237 | ||
236 | do_reconnect(h); | 238 | do_reconnect (h); |
237 | } | 239 | } |
238 | 240 | ||
239 | 241 | ||
@@ -247,70 +249,70 @@ mq_error_handler(void *cls, | |||
247 | * @return #GNUNET_OK if the message is OK | 249 | * @return #GNUNET_OK if the message is OK |
248 | */ | 250 | */ |
249 | static int | 251 | static int |
250 | check_info(void *cls, | 252 | check_info (void *cls, |
251 | const struct InfoMessage *im) | 253 | const struct InfoMessage *im) |
252 | { | 254 | { |
253 | struct GNUNET_PEERINFO_Handle *h = cls; | 255 | struct GNUNET_PEERINFO_Handle *h = cls; |
254 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 256 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
255 | uint16_t ms = ntohs(im->header.size) - sizeof(*im); | 257 | uint16_t ms = ntohs (im->header.size) - sizeof(*im); |
256 | 258 | ||
257 | if (0 != ntohl(im->reserved)) | 259 | if (0 != ntohl (im->reserved)) |
258 | { | 260 | { |
259 | GNUNET_break(0); | 261 | GNUNET_break (0); |
260 | return GNUNET_SYSERR; | 262 | return GNUNET_SYSERR; |
261 | } | 263 | } |
262 | if (NULL == ic) | 264 | if (NULL == ic) |
263 | { | 265 | { |
264 | /* didn't expect a response, bad */ | 266 | /* didn't expect a response, bad */ |
265 | GNUNET_break(0); | 267 | GNUNET_break (0); |
266 | return GNUNET_SYSERR; | 268 | return GNUNET_SYSERR; |
267 | } | 269 | } |
268 | if ((GNUNET_YES == ic->have_peer) && | 270 | if ((GNUNET_YES == ic->have_peer) && |
269 | (0 != GNUNET_memcmp(&ic->peer, | 271 | (0 != GNUNET_memcmp (&ic->peer, |
270 | &im->peer))) | 272 | &im->peer))) |
273 | { | ||
274 | /* bogus message (from a different iteration call?); out of sequence! */ | ||
275 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
276 | "Received HELLO for peer `%s', expected peer `%s'\n", | ||
277 | GNUNET_i2s (&im->peer), | ||
278 | GNUNET_i2s (&ic->peer)); | ||
279 | GNUNET_break (0); | ||
280 | return GNUNET_SYSERR; | ||
281 | } | ||
282 | if (ms > sizeof(struct GNUNET_MessageHeader)) | ||
283 | { | ||
284 | const struct GNUNET_HELLO_Message *hello; | ||
285 | struct GNUNET_PeerIdentity id; | ||
286 | |||
287 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
288 | if (ms != GNUNET_HELLO_size (hello)) | ||
271 | { | 289 | { |
272 | /* bogus message (from a different iteration call?); out of sequence! */ | 290 | /* malformed message */ |
273 | LOG(GNUNET_ERROR_TYPE_ERROR, | 291 | GNUNET_break (0); |
274 | "Received HELLO for peer `%s', expected peer `%s'\n", | ||
275 | GNUNET_i2s(&im->peer), | ||
276 | GNUNET_i2s(&ic->peer)); | ||
277 | GNUNET_break(0); | ||
278 | return GNUNET_SYSERR; | 292 | return GNUNET_SYSERR; |
279 | } | 293 | } |
280 | if (ms > sizeof(struct GNUNET_MessageHeader)) | 294 | if (GNUNET_OK != |
281 | { | 295 | GNUNET_HELLO_get_id (hello, |
282 | const struct GNUNET_HELLO_Message *hello; | ||
283 | struct GNUNET_PeerIdentity id; | ||
284 | |||
285 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | ||
286 | if (ms != GNUNET_HELLO_size(hello)) | ||
287 | { | ||
288 | /* malformed message */ | ||
289 | GNUNET_break(0); | ||
290 | return GNUNET_SYSERR; | ||
291 | } | ||
292 | if (GNUNET_OK != | ||
293 | GNUNET_HELLO_get_id(hello, | ||
294 | &id)) | ||
295 | { | ||
296 | /* malformed message */ | ||
297 | GNUNET_break(0); | ||
298 | return GNUNET_SYSERR; | ||
299 | } | ||
300 | if (0 != GNUNET_memcmp(&im->peer, | ||
301 | &id)) | 296 | &id)) |
302 | { | 297 | { |
303 | /* malformed message */ | 298 | /* malformed message */ |
304 | GNUNET_break(0); | 299 | GNUNET_break (0); |
305 | return GNUNET_SYSERR; | 300 | return GNUNET_SYSERR; |
306 | } | ||
307 | } | 301 | } |
308 | else if (0 != ms) | 302 | if (0 != GNUNET_memcmp (&im->peer, |
303 | &id)) | ||
309 | { | 304 | { |
310 | /* malformed message */ | 305 | /* malformed message */ |
311 | GNUNET_break(0); | 306 | GNUNET_break (0); |
312 | return GNUNET_SYSERR; | 307 | return GNUNET_SYSERR; |
313 | } | 308 | } |
309 | } | ||
310 | else if (0 != ms) | ||
311 | { | ||
312 | /* malformed message */ | ||
313 | GNUNET_break (0); | ||
314 | return GNUNET_SYSERR; | ||
315 | } | ||
314 | return GNUNET_OK; | 316 | return GNUNET_OK; |
315 | } | 317 | } |
316 | 318 | ||
@@ -322,22 +324,22 @@ check_info(void *cls, | |||
322 | * @param im message received | 324 | * @param im message received |
323 | */ | 325 | */ |
324 | static void | 326 | static void |
325 | handle_info(void *cls, | 327 | handle_info (void *cls, |
326 | const struct InfoMessage *im) | 328 | const struct InfoMessage *im) |
327 | { | 329 | { |
328 | struct GNUNET_PEERINFO_Handle *h = cls; | 330 | struct GNUNET_PEERINFO_Handle *h = cls; |
329 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 331 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
330 | const struct GNUNET_HELLO_Message *hello = NULL; | 332 | const struct GNUNET_HELLO_Message *hello = NULL; |
331 | uint16_t ms; | 333 | uint16_t ms; |
332 | 334 | ||
333 | ms = ntohs(im->header.size); | 335 | ms = ntohs (im->header.size); |
334 | if (ms > sizeof(struct InfoMessage)) | 336 | if (ms > sizeof(struct InfoMessage)) |
335 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | 337 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; |
336 | if (NULL != ic->callback) | 338 | if (NULL != ic->callback) |
337 | ic->callback(ic->callback_cls, | 339 | ic->callback (ic->callback_cls, |
338 | &im->peer, | 340 | &im->peer, |
339 | hello, | 341 | hello, |
340 | NULL); | 342 | NULL); |
341 | } | 343 | } |
342 | 344 | ||
343 | 345 | ||
@@ -347,7 +349,7 @@ handle_info(void *cls, | |||
347 | * @param h handle | 349 | * @param h handle |
348 | */ | 350 | */ |
349 | static void | 351 | static void |
350 | send_ic_request(struct GNUNET_PEERINFO_Handle *h) | 352 | send_ic_request (struct GNUNET_PEERINFO_Handle *h) |
351 | { | 353 | { |
352 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 354 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
353 | struct GNUNET_MQ_Envelope *env; | 355 | struct GNUNET_MQ_Envelope *env; |
@@ -355,35 +357,35 @@ send_ic_request(struct GNUNET_PEERINFO_Handle *h) | |||
355 | struct ListPeerMessage *lpm; | 357 | struct ListPeerMessage *lpm; |
356 | 358 | ||
357 | if (NULL == ic) | 359 | if (NULL == ic) |
358 | { | 360 | { |
359 | GNUNET_break(0); | 361 | GNUNET_break (0); |
360 | return; | 362 | return; |
361 | } | 363 | } |
362 | if (NULL == h->mq) | 364 | if (NULL == h->mq) |
363 | { | 365 | { |
364 | GNUNET_break(0); | 366 | GNUNET_break (0); |
365 | return; | 367 | return; |
366 | } | 368 | } |
367 | if (GNUNET_NO == ic->have_peer) | 369 | if (GNUNET_NO == ic->have_peer) |
368 | { | 370 | { |
369 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 371 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
370 | "Requesting list of peers from PEERINFO service\n"); | 372 | "Requesting list of peers from PEERINFO service\n"); |
371 | env = GNUNET_MQ_msg(lapm, | 373 | env = GNUNET_MQ_msg (lapm, |
372 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | 374 | GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); |
373 | lapm->include_friend_only = htonl(ic->include_friend_only); | 375 | lapm->include_friend_only = htonl (ic->include_friend_only); |
374 | } | 376 | } |
375 | else | 377 | else |
376 | { | 378 | { |
377 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 379 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
378 | "Requesting information on peer `%s' from PEERINFO service\n", | 380 | "Requesting information on peer `%s' from PEERINFO service\n", |
379 | GNUNET_i2s(&ic->peer)); | 381 | GNUNET_i2s (&ic->peer)); |
380 | env = GNUNET_MQ_msg(lpm, | 382 | env = GNUNET_MQ_msg (lpm, |
381 | GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 383 | GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
382 | lpm->include_friend_only = htonl(ic->include_friend_only); | 384 | lpm->include_friend_only = htonl (ic->include_friend_only); |
383 | lpm->peer = ic->peer; | 385 | lpm->peer = ic->peer; |
384 | } | 386 | } |
385 | GNUNET_MQ_send(h->mq, | 387 | GNUNET_MQ_send (h->mq, |
386 | env); | 388 | env); |
387 | } | 389 | } |
388 | 390 | ||
389 | 391 | ||
@@ -397,32 +399,32 @@ send_ic_request(struct GNUNET_PEERINFO_Handle *h) | |||
397 | * @param msg message received, NULL on timeout or fatal error | 399 | * @param msg message received, NULL on timeout or fatal error |
398 | */ | 400 | */ |
399 | static void | 401 | static void |
400 | handle_end_iteration(void *cls, | 402 | handle_end_iteration (void *cls, |
401 | const struct GNUNET_MessageHeader *msg) | 403 | const struct GNUNET_MessageHeader *msg) |
402 | { | 404 | { |
403 | struct GNUNET_PEERINFO_Handle *h = cls; | 405 | struct GNUNET_PEERINFO_Handle *h = cls; |
404 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; | 406 | struct GNUNET_PEERINFO_IteratorContext *ic = h->ic_head; |
405 | 407 | ||
406 | if (NULL == ic) | 408 | if (NULL == ic) |
407 | { | 409 | { |
408 | /* didn't expect a response, reconnect */ | 410 | /* didn't expect a response, reconnect */ |
409 | GNUNET_break(0); | 411 | GNUNET_break (0); |
410 | reconnect(h); | 412 | reconnect (h); |
411 | return; | 413 | return; |
412 | } | 414 | } |
413 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 415 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
414 | "Received end of list of peers from PEERINFO service\n"); | 416 | "Received end of list of peers from PEERINFO service\n"); |
415 | GNUNET_CONTAINER_DLL_remove(h->ic_head, | 417 | GNUNET_CONTAINER_DLL_remove (h->ic_head, |
416 | h->ic_tail, | 418 | h->ic_tail, |
417 | ic); | 419 | ic); |
418 | if (NULL != h->ic_head) | 420 | if (NULL != h->ic_head) |
419 | send_ic_request(h); | 421 | send_ic_request (h); |
420 | if (NULL != ic->callback) | 422 | if (NULL != ic->callback) |
421 | ic->callback(ic->callback_cls, | 423 | ic->callback (ic->callback_cls, |
422 | NULL, | 424 | NULL, |
423 | NULL, | 425 | NULL, |
424 | NULL); | 426 | NULL); |
425 | GNUNET_free(ic); | 427 | GNUNET_free (ic); |
426 | } | 428 | } |
427 | 429 | ||
428 | 430 | ||
@@ -432,37 +434,37 @@ handle_end_iteration(void *cls, | |||
432 | * @param h handle to the service | 434 | * @param h handle to the service |
433 | */ | 435 | */ |
434 | static void | 436 | static void |
435 | reconnect(struct GNUNET_PEERINFO_Handle *h) | 437 | reconnect (struct GNUNET_PEERINFO_Handle *h) |
436 | { | 438 | { |
437 | struct GNUNET_MQ_MessageHandler handlers[] = { | 439 | struct GNUNET_MQ_MessageHandler handlers[] = { |
438 | GNUNET_MQ_hd_var_size(info, | 440 | GNUNET_MQ_hd_var_size (info, |
439 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, | 441 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, |
440 | struct InfoMessage, | 442 | struct InfoMessage, |
441 | h), | 443 | h), |
442 | GNUNET_MQ_hd_fixed_size(end_iteration, | 444 | GNUNET_MQ_hd_fixed_size (end_iteration, |
443 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, | 445 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, |
444 | struct GNUNET_MessageHeader, | 446 | struct GNUNET_MessageHeader, |
445 | h), | 447 | h), |
446 | GNUNET_MQ_handler_end() | 448 | GNUNET_MQ_handler_end () |
447 | }; | 449 | }; |
448 | 450 | ||
449 | if (NULL != h->r_task) | 451 | if (NULL != h->r_task) |
450 | { | 452 | { |
451 | GNUNET_SCHEDULER_cancel(h->r_task); | 453 | GNUNET_SCHEDULER_cancel (h->r_task); |
452 | h->r_task = NULL; | 454 | h->r_task = NULL; |
453 | } | 455 | } |
454 | if (NULL != h->mq) | 456 | if (NULL != h->mq) |
455 | { | 457 | { |
456 | GNUNET_MQ_destroy(h->mq); | 458 | GNUNET_MQ_destroy (h->mq); |
457 | h->mq = NULL; | 459 | h->mq = NULL; |
458 | } | 460 | } |
459 | h->mq = GNUNET_CLIENT_connect(h->cfg, | 461 | h->mq = GNUNET_CLIENT_connect (h->cfg, |
460 | "peerinfo", | 462 | "peerinfo", |
461 | handlers, | 463 | handlers, |
462 | &mq_error_handler, | 464 | &mq_error_handler, |
463 | h); | 465 | h); |
464 | if (NULL != h->ic_head) | 466 | if (NULL != h->ic_head) |
465 | send_ic_request(h); | 467 | send_ic_request (h); |
466 | } | 468 | } |
467 | 469 | ||
468 | 470 | ||
@@ -483,29 +485,29 @@ reconnect(struct GNUNET_PEERINFO_Handle *h) | |||
483 | * @return iterator context | 485 | * @return iterator context |
484 | */ | 486 | */ |
485 | struct GNUNET_PEERINFO_IteratorContext * | 487 | struct GNUNET_PEERINFO_IteratorContext * |
486 | GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, | 488 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, |
487 | int include_friend_only, | 489 | int include_friend_only, |
488 | const struct GNUNET_PeerIdentity *peer, | 490 | const struct GNUNET_PeerIdentity *peer, |
489 | GNUNET_PEERINFO_Processor callback, | 491 | GNUNET_PEERINFO_Processor callback, |
490 | void *callback_cls) | 492 | void *callback_cls) |
491 | { | 493 | { |
492 | struct GNUNET_PEERINFO_IteratorContext *ic; | 494 | struct GNUNET_PEERINFO_IteratorContext *ic; |
493 | 495 | ||
494 | ic = GNUNET_new(struct GNUNET_PEERINFO_IteratorContext); | 496 | ic = GNUNET_new (struct GNUNET_PEERINFO_IteratorContext); |
495 | ic->h = h; | 497 | ic->h = h; |
496 | ic->include_friend_only = include_friend_only; | 498 | ic->include_friend_only = include_friend_only; |
497 | ic->callback = callback; | 499 | ic->callback = callback; |
498 | ic->callback_cls = callback_cls; | 500 | ic->callback_cls = callback_cls; |
499 | if (NULL != peer) | 501 | if (NULL != peer) |
500 | { | 502 | { |
501 | ic->have_peer = GNUNET_YES; | 503 | ic->have_peer = GNUNET_YES; |
502 | ic->peer = *peer; | 504 | ic->peer = *peer; |
503 | } | 505 | } |
504 | GNUNET_CONTAINER_DLL_insert_tail(h->ic_head, | 506 | GNUNET_CONTAINER_DLL_insert_tail (h->ic_head, |
505 | h->ic_tail, | 507 | h->ic_tail, |
506 | ic); | 508 | ic); |
507 | if (h->ic_head == ic) | 509 | if (h->ic_head == ic) |
508 | send_ic_request(h); | 510 | send_ic_request (h); |
509 | return ic; | 511 | return ic; |
510 | } | 512 | } |
511 | 513 | ||
@@ -516,17 +518,17 @@ GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, | |||
516 | * @param ic context of the iterator to cancel | 518 | * @param ic context of the iterator to cancel |
517 | */ | 519 | */ |
518 | void | 520 | void |
519 | GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic) | 521 | GNUNET_PEERINFO_iterate_cancel (struct GNUNET_PEERINFO_IteratorContext *ic) |
520 | { | 522 | { |
521 | struct GNUNET_PEERINFO_Handle *h = ic->h; | 523 | struct GNUNET_PEERINFO_Handle *h = ic->h; |
522 | 524 | ||
523 | ic->callback = NULL; | 525 | ic->callback = NULL; |
524 | if (ic == h->ic_head) | 526 | if (ic == h->ic_head) |
525 | return; | 527 | return; |
526 | GNUNET_CONTAINER_DLL_remove(h->ic_head, | 528 | GNUNET_CONTAINER_DLL_remove (h->ic_head, |
527 | h->ic_tail, | 529 | h->ic_tail, |
528 | ic); | 530 | ic); |
529 | GNUNET_free(ic); | 531 | GNUNET_free (ic); |
530 | } | 532 | } |
531 | 533 | ||
532 | 534 | ||
@@ -549,29 +551,29 @@ GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic) | |||
549 | * calling @a cont must be prevented) | 551 | * calling @a cont must be prevented) |
550 | */ | 552 | */ |
551 | struct GNUNET_MQ_Envelope * | 553 | struct GNUNET_MQ_Envelope * |
552 | GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, | 554 | GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h, |
553 | const struct GNUNET_HELLO_Message *hello, | 555 | const struct GNUNET_HELLO_Message *hello, |
554 | GNUNET_SCHEDULER_TaskCallback cont, | 556 | GNUNET_SCHEDULER_TaskCallback cont, |
555 | void *cont_cls) | 557 | void *cont_cls) |
556 | { | 558 | { |
557 | struct GNUNET_MQ_Envelope *env; | 559 | struct GNUNET_MQ_Envelope *env; |
558 | struct GNUNET_PeerIdentity peer; | 560 | struct GNUNET_PeerIdentity peer; |
559 | 561 | ||
560 | if (NULL == h->mq) | 562 | if (NULL == h->mq) |
561 | return NULL; | 563 | return NULL; |
562 | GNUNET_assert(GNUNET_OK == | 564 | GNUNET_assert (GNUNET_OK == |
563 | GNUNET_HELLO_get_id(hello, | 565 | GNUNET_HELLO_get_id (hello, |
564 | &peer)); | 566 | &peer)); |
565 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 567 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
566 | "Adding peer `%s' to PEERINFO database\n", | 568 | "Adding peer `%s' to PEERINFO database\n", |
567 | GNUNET_i2s(&peer)); | 569 | GNUNET_i2s (&peer)); |
568 | env = GNUNET_MQ_msg_copy((const struct GNUNET_MessageHeader *)hello); | 570 | env = GNUNET_MQ_msg_copy ((const struct GNUNET_MessageHeader *) hello); |
569 | if (NULL != cont) | 571 | if (NULL != cont) |
570 | GNUNET_MQ_notify_sent(env, | 572 | GNUNET_MQ_notify_sent (env, |
571 | cont, | 573 | cont, |
572 | cont_cls); | 574 | cont_cls); |
573 | GNUNET_MQ_send(h->mq, | 575 | GNUNET_MQ_send (h->mq, |
574 | env); | 576 | env); |
575 | return env; | 577 | return env; |
576 | } | 578 | } |
577 | 579 | ||
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index 130ce3a5d..778fe2344 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c | |||
@@ -29,12 +29,13 @@ | |||
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | #include "peerinfo.h" | 30 | #include "peerinfo.h" |
31 | 31 | ||
32 | #define LOG(kind, ...) GNUNET_log_from(kind, "peerinfo-api", __VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from (kind, "peerinfo-api", __VA_ARGS__) |
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Context for the info handler. | 35 | * Context for the info handler. |
36 | */ | 36 | */ |
37 | struct GNUNET_PEERINFO_NotifyContext { | 37 | struct GNUNET_PEERINFO_NotifyContext |
38 | { | ||
38 | /** | 39 | /** |
39 | * Our connection to the PEERINFO service. | 40 | * Our connection to the PEERINFO service. |
40 | */ | 41 | */ |
@@ -73,7 +74,7 @@ struct GNUNET_PEERINFO_NotifyContext { | |||
73 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` | 74 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` |
74 | */ | 75 | */ |
75 | static void | 76 | static void |
76 | reconnect(void *cls); | 77 | reconnect (void *cls); |
77 | 78 | ||
78 | 79 | ||
79 | /** | 80 | /** |
@@ -82,12 +83,12 @@ reconnect(void *cls); | |||
82 | * @param nc context to reconnect | 83 | * @param nc context to reconnect |
83 | */ | 84 | */ |
84 | static void | 85 | static void |
85 | do_reconnect(struct GNUNET_PEERINFO_NotifyContext *nc) | 86 | do_reconnect (struct GNUNET_PEERINFO_NotifyContext *nc) |
86 | { | 87 | { |
87 | GNUNET_MQ_destroy(nc->mq); | 88 | GNUNET_MQ_destroy (nc->mq); |
88 | nc->mq = NULL; | 89 | nc->mq = NULL; |
89 | nc->task = GNUNET_SCHEDULER_add_now(&reconnect, | 90 | nc->task = GNUNET_SCHEDULER_add_now (&reconnect, |
90 | nc); | 91 | nc); |
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
@@ -99,12 +100,12 @@ do_reconnect(struct GNUNET_PEERINFO_NotifyContext *nc) | |||
99 | * @param error error code | 100 | * @param error error code |
100 | */ | 101 | */ |
101 | static void | 102 | static void |
102 | mq_error_handler(void *cls, | 103 | mq_error_handler (void *cls, |
103 | enum GNUNET_MQ_Error error) | 104 | enum GNUNET_MQ_Error error) |
104 | { | 105 | { |
105 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 106 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
106 | 107 | ||
107 | do_reconnect(nc); | 108 | do_reconnect (nc); |
108 | } | 109 | } |
109 | 110 | ||
110 | 111 | ||
@@ -116,28 +117,28 @@ mq_error_handler(void *cls, | |||
116 | * @return #GNUNET_OK if the message is well-formed | 117 | * @return #GNUNET_OK if the message is well-formed |
117 | */ | 118 | */ |
118 | static int | 119 | static int |
119 | check_notification(void *cls, | 120 | check_notification (void *cls, |
120 | const struct InfoMessage *im) | 121 | const struct InfoMessage *im) |
121 | { | 122 | { |
122 | uint16_t ms = ntohs(im->header.size) - sizeof(*im); | 123 | uint16_t ms = ntohs (im->header.size) - sizeof(*im); |
123 | 124 | ||
124 | if (ms >= sizeof(struct GNUNET_MessageHeader)) | 125 | if (ms >= sizeof(struct GNUNET_MessageHeader)) |
126 | { | ||
127 | const struct GNUNET_HELLO_Message *hello; | ||
128 | |||
129 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; | ||
130 | if (ms != GNUNET_HELLO_size (hello)) | ||
125 | { | 131 | { |
126 | const struct GNUNET_HELLO_Message *hello; | 132 | GNUNET_break (0); |
127 | |||
128 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | ||
129 | if (ms != GNUNET_HELLO_size(hello)) | ||
130 | { | ||
131 | GNUNET_break(0); | ||
132 | return GNUNET_SYSERR; | ||
133 | } | ||
134 | return GNUNET_OK; | ||
135 | } | ||
136 | if (0 != ms) | ||
137 | { | ||
138 | GNUNET_break(0); | ||
139 | return GNUNET_SYSERR; | 133 | return GNUNET_SYSERR; |
140 | } | 134 | } |
135 | return GNUNET_OK; | ||
136 | } | ||
137 | if (0 != ms) | ||
138 | { | ||
139 | GNUNET_break (0); | ||
140 | return GNUNET_SYSERR; | ||
141 | } | ||
141 | return GNUNET_OK; /* odd... */ | 142 | return GNUNET_OK; /* odd... */ |
142 | } | 143 | } |
143 | 144 | ||
@@ -149,23 +150,23 @@ check_notification(void *cls, | |||
149 | * @param im message received | 150 | * @param im message received |
150 | */ | 151 | */ |
151 | static void | 152 | static void |
152 | handle_notification(void *cls, | 153 | handle_notification (void *cls, |
153 | const struct InfoMessage *im) | 154 | const struct InfoMessage *im) |
154 | { | 155 | { |
155 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 156 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
156 | const struct GNUNET_HELLO_Message *hello; | 157 | const struct GNUNET_HELLO_Message *hello; |
157 | uint16_t ms = ntohs(im->header.size) - sizeof(struct InfoMessage); | 158 | uint16_t ms = ntohs (im->header.size) - sizeof(struct InfoMessage); |
158 | 159 | ||
159 | if (0 == ms) | 160 | if (0 == ms) |
160 | return; | 161 | return; |
161 | hello = (const struct GNUNET_HELLO_Message *)&im[1]; | 162 | hello = (const struct GNUNET_HELLO_Message *) &im[1]; |
162 | LOG(GNUNET_ERROR_TYPE_DEBUG, | 163 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
163 | "Received information about peer `%s' from peerinfo database\n", | 164 | "Received information about peer `%s' from peerinfo database\n", |
164 | GNUNET_i2s(&im->peer)); | 165 | GNUNET_i2s (&im->peer)); |
165 | nc->callback(nc->callback_cls, | 166 | nc->callback (nc->callback_cls, |
166 | &im->peer, | 167 | &im->peer, |
167 | hello, | 168 | hello, |
168 | NULL); | 169 | NULL); |
169 | } | 170 | } |
170 | 171 | ||
171 | 172 | ||
@@ -179,8 +180,8 @@ handle_notification(void *cls, | |||
179 | * @param msg message received, NULL on timeout or fatal error | 180 | * @param msg message received, NULL on timeout or fatal error |
180 | */ | 181 | */ |
181 | static void | 182 | static void |
182 | handle_end_iteration(void *cls, | 183 | handle_end_iteration (void *cls, |
183 | const struct GNUNET_MessageHeader *msg) | 184 | const struct GNUNET_MessageHeader *msg) |
184 | { | 185 | { |
185 | /* these are ignored by the notify API */ | 186 | /* these are ignored by the notify API */ |
186 | } | 187 | } |
@@ -192,36 +193,36 @@ handle_end_iteration(void *cls, | |||
192 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` | 193 | * @param cls the `struct GNUNET_PEERINFO_NotifyContext *` |
193 | */ | 194 | */ |
194 | static void | 195 | static void |
195 | reconnect(void *cls) | 196 | reconnect (void *cls) |
196 | { | 197 | { |
197 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; | 198 | struct GNUNET_PEERINFO_NotifyContext *nc = cls; |
198 | struct GNUNET_MQ_MessageHandler handlers[] = { | 199 | struct GNUNET_MQ_MessageHandler handlers[] = { |
199 | GNUNET_MQ_hd_var_size(notification, | 200 | GNUNET_MQ_hd_var_size (notification, |
200 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, | 201 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO, |
201 | struct InfoMessage, | 202 | struct InfoMessage, |
202 | nc), | 203 | nc), |
203 | GNUNET_MQ_hd_fixed_size(end_iteration, | 204 | GNUNET_MQ_hd_fixed_size (end_iteration, |
204 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, | 205 | GNUNET_MESSAGE_TYPE_PEERINFO_INFO_END, |
205 | struct GNUNET_MessageHeader, | 206 | struct GNUNET_MessageHeader, |
206 | nc), | 207 | nc), |
207 | GNUNET_MQ_handler_end() | 208 | GNUNET_MQ_handler_end () |
208 | }; | 209 | }; |
209 | struct GNUNET_MQ_Envelope *env; | 210 | struct GNUNET_MQ_Envelope *env; |
210 | struct NotifyMessage *nm; | 211 | struct NotifyMessage *nm; |
211 | 212 | ||
212 | nc->task = NULL; | 213 | nc->task = NULL; |
213 | nc->mq = GNUNET_CLIENT_connect(nc->cfg, | 214 | nc->mq = GNUNET_CLIENT_connect (nc->cfg, |
214 | "peerinfo", | 215 | "peerinfo", |
215 | handlers, | 216 | handlers, |
216 | &mq_error_handler, | 217 | &mq_error_handler, |
217 | nc); | 218 | nc); |
218 | if (NULL == nc->mq) | 219 | if (NULL == nc->mq) |
219 | return; | 220 | return; |
220 | env = GNUNET_MQ_msg(nm, | 221 | env = GNUNET_MQ_msg (nm, |
221 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); | 222 | GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY); |
222 | nm->include_friend_only = htonl(nc->include_friend_only); | 223 | nm->include_friend_only = htonl (nc->include_friend_only); |
223 | GNUNET_MQ_send(nc->mq, | 224 | GNUNET_MQ_send (nc->mq, |
224 | env); | 225 | env); |
225 | } | 226 | } |
226 | 227 | ||
227 | 228 | ||
@@ -241,26 +242,26 @@ reconnect(void *cls) | |||
241 | * @return NULL on error | 242 | * @return NULL on error |
242 | */ | 243 | */ |
243 | struct GNUNET_PEERINFO_NotifyContext * | 244 | struct GNUNET_PEERINFO_NotifyContext * |
244 | GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, | 245 | GNUNET_PEERINFO_notify (const struct GNUNET_CONFIGURATION_Handle *cfg, |
245 | int include_friend_only, | 246 | int include_friend_only, |
246 | GNUNET_PEERINFO_Processor callback, | 247 | GNUNET_PEERINFO_Processor callback, |
247 | void *callback_cls) | 248 | void *callback_cls) |
248 | { | 249 | { |
249 | struct GNUNET_PEERINFO_NotifyContext *nc; | 250 | struct GNUNET_PEERINFO_NotifyContext *nc; |
250 | 251 | ||
251 | nc = GNUNET_new(struct GNUNET_PEERINFO_NotifyContext); | 252 | nc = GNUNET_new (struct GNUNET_PEERINFO_NotifyContext); |
252 | nc->cfg = cfg; | 253 | nc->cfg = cfg; |
253 | nc->callback = callback; | 254 | nc->callback = callback; |
254 | nc->callback_cls = callback_cls; | 255 | nc->callback_cls = callback_cls; |
255 | nc->include_friend_only = include_friend_only; | 256 | nc->include_friend_only = include_friend_only; |
256 | reconnect(nc); | 257 | reconnect (nc); |
257 | if (NULL == nc->mq) | 258 | if (NULL == nc->mq) |
258 | { | 259 | { |
259 | LOG(GNUNET_ERROR_TYPE_WARNING, | 260 | LOG (GNUNET_ERROR_TYPE_WARNING, |
260 | "Could not connect to PEERINFO service.\n"); | 261 | "Could not connect to PEERINFO service.\n"); |
261 | GNUNET_free(nc); | 262 | GNUNET_free (nc); |
262 | return NULL; | 263 | return NULL; |
263 | } | 264 | } |
264 | return nc; | 265 | return nc; |
265 | } | 266 | } |
266 | 267 | ||
@@ -271,19 +272,19 @@ GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
271 | * @param nc context to stop notifying | 272 | * @param nc context to stop notifying |
272 | */ | 273 | */ |
273 | void | 274 | void |
274 | GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc) | 275 | GNUNET_PEERINFO_notify_cancel (struct GNUNET_PEERINFO_NotifyContext *nc) |
275 | { | 276 | { |
276 | if (NULL != nc->mq) | 277 | if (NULL != nc->mq) |
277 | { | 278 | { |
278 | GNUNET_MQ_destroy(nc->mq); | 279 | GNUNET_MQ_destroy (nc->mq); |
279 | nc->mq = NULL; | 280 | nc->mq = NULL; |
280 | } | 281 | } |
281 | if (NULL != nc->task) | 282 | if (NULL != nc->task) |
282 | { | 283 | { |
283 | GNUNET_SCHEDULER_cancel(nc->task); | 284 | GNUNET_SCHEDULER_cancel (nc->task); |
284 | nc->task = NULL; | 285 | nc->task = NULL; |
285 | } | 286 | } |
286 | GNUNET_free(nc); | 287 | GNUNET_free (nc); |
287 | } | 288 | } |
288 | 289 | ||
289 | /* end of peerinfo_api_notify.c */ | 290 | /* end of peerinfo_api_notify.c */ |
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c index b9317478c..0c8c22345 100644 --- a/src/peerinfo/perf_peerinfo_api.c +++ b/src/peerinfo/perf_peerinfo_api.c | |||
@@ -48,40 +48,40 @@ static struct GNUNET_SCHEDULER_Task *tt; | |||
48 | 48 | ||
49 | 49 | ||
50 | static void | 50 | static void |
51 | do_shutdown(void *cls) | 51 | do_shutdown (void *cls) |
52 | { | 52 | { |
53 | if (NULL != tt) | 53 | if (NULL != tt) |
54 | { | 54 | { |
55 | GNUNET_SCHEDULER_cancel(tt); | 55 | GNUNET_SCHEDULER_cancel (tt); |
56 | tt = NULL; | 56 | tt = NULL; |
57 | } | 57 | } |
58 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) | 58 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) |
59 | if (NULL != ic[i]) | 59 | if (NULL != ic[i]) |
60 | GNUNET_PEERINFO_iterate_cancel(ic[i]); | 60 | GNUNET_PEERINFO_iterate_cancel (ic[i]); |
61 | GNUNET_PEERINFO_disconnect(h); | 61 | GNUNET_PEERINFO_disconnect (h); |
62 | h = NULL; | 62 | h = NULL; |
63 | } | 63 | } |
64 | 64 | ||
65 | 65 | ||
66 | static void | 66 | static void |
67 | do_timeout(void *cls) | 67 | do_timeout (void *cls) |
68 | { | 68 | { |
69 | tt = NULL; | 69 | tt = NULL; |
70 | GNUNET_SCHEDULER_shutdown(); | 70 | GNUNET_SCHEDULER_shutdown (); |
71 | } | 71 | } |
72 | 72 | ||
73 | 73 | ||
74 | static int | 74 | static int |
75 | check_it(void *cls, | 75 | check_it (void *cls, |
76 | const struct GNUNET_HELLO_Address *address, | 76 | const struct GNUNET_HELLO_Address *address, |
77 | struct GNUNET_TIME_Absolute expiration) | 77 | struct GNUNET_TIME_Absolute expiration) |
78 | { | 78 | { |
79 | return GNUNET_OK; | 79 | return GNUNET_OK; |
80 | } | 80 | } |
81 | 81 | ||
82 | 82 | ||
83 | static ssize_t | 83 | static ssize_t |
84 | address_generator(void *cls, size_t max, void *buf) | 84 | address_generator (void *cls, size_t max, void *buf) |
85 | { | 85 | { |
86 | size_t *agc = cls; | 86 | size_t *agc = cls; |
87 | ssize_t ret; | 87 | ssize_t ret; |
@@ -91,100 +91,101 @@ address_generator(void *cls, size_t max, void *buf) | |||
91 | if (*agc == 0) | 91 | if (*agc == 0) |
92 | return GNUNET_SYSERR; /* Done */ | 92 | return GNUNET_SYSERR; /* Done */ |
93 | 93 | ||
94 | GNUNET_asprintf(&caddress, "Address%d", *agc); | 94 | GNUNET_asprintf (&caddress, "Address%d", *agc); |
95 | address.peer = pid; | 95 | address.peer = pid; |
96 | address.address_length = strlen(caddress) + 1; | 96 | address.address_length = strlen (caddress) + 1; |
97 | address.address = caddress; | 97 | address.address = caddress; |
98 | address.transport_name = "peerinfotest"; | 98 | address.transport_name = "peerinfotest"; |
99 | ret = | 99 | ret = |
100 | GNUNET_HELLO_add_address(&address, | 100 | GNUNET_HELLO_add_address (&address, |
101 | GNUNET_TIME_relative_to_absolute | 101 | GNUNET_TIME_relative_to_absolute |
102 | (GNUNET_TIME_UNIT_HOURS), buf, max); | 102 | (GNUNET_TIME_UNIT_HOURS), buf, max); |
103 | GNUNET_free(caddress); | 103 | GNUNET_free (caddress); |
104 | *agc = 0; | 104 | *agc = 0; |
105 | return ret; | 105 | return ret; |
106 | } | 106 | } |
107 | 107 | ||
108 | 108 | ||
109 | static void | 109 | static void |
110 | add_peer(size_t i) | 110 | add_peer (size_t i) |
111 | { | 111 | { |
112 | struct GNUNET_HELLO_Message *h2; | 112 | struct GNUNET_HELLO_Message *h2; |
113 | 113 | ||
114 | memset(&pid, i, sizeof(pid)); | 114 | memset (&pid, i, sizeof(pid)); |
115 | h2 = GNUNET_HELLO_create(&pid.public_key, | 115 | h2 = GNUNET_HELLO_create (&pid.public_key, |
116 | &address_generator, | 116 | &address_generator, |
117 | &i, | 117 | &i, |
118 | GNUNET_NO); | 118 | GNUNET_NO); |
119 | GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); | 119 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); |
120 | GNUNET_free(h2); | 120 | GNUNET_free (h2); |
121 | } | 121 | } |
122 | 122 | ||
123 | 123 | ||
124 | static void | 124 | static void |
125 | process(void *cls, | 125 | process (void *cls, |
126 | const struct GNUNET_PeerIdentity *peer, | 126 | const struct GNUNET_PeerIdentity *peer, |
127 | const struct GNUNET_HELLO_Message *hello, | 127 | const struct GNUNET_HELLO_Message *hello, |
128 | const char *err_msg) | 128 | const char *err_msg) |
129 | { | 129 | { |
130 | struct GNUNET_PEERINFO_IteratorContext **icp = cls; | 130 | struct GNUNET_PEERINFO_IteratorContext **icp = cls; |
131 | 131 | ||
132 | if (NULL == peer) | 132 | if (NULL == peer) |
133 | { | 133 | { |
134 | *icp = NULL; | 134 | *icp = NULL; |
135 | return; | 135 | return; |
136 | } | 136 | } |
137 | numpeers++; | 137 | numpeers++; |
138 | if (0 && (NULL != hello)) | 138 | if (0 && (NULL != hello)) |
139 | GNUNET_HELLO_iterate_addresses(hello, | 139 | GNUNET_HELLO_iterate_addresses (hello, |
140 | GNUNET_NO, | 140 | GNUNET_NO, |
141 | &check_it, | 141 | &check_it, |
142 | NULL); | 142 | NULL); |
143 | } | 143 | } |
144 | 144 | ||
145 | 145 | ||
146 | static void | 146 | static void |
147 | run(void *cls, | 147 | run (void *cls, |
148 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 148 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
149 | struct GNUNET_TESTING_Peer *peer) | 149 | struct GNUNET_TESTING_Peer *peer) |
150 | { | 150 | { |
151 | h = GNUNET_PEERINFO_connect(cfg); | 151 | h = GNUNET_PEERINFO_connect (cfg); |
152 | GNUNET_assert(h != NULL); | 152 | GNUNET_assert (h != NULL); |
153 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) | 153 | for (unsigned int i = 0; i < NUM_REQUESTS; i++) |
154 | { | 154 | { |
155 | add_peer(i); | 155 | add_peer (i); |
156 | ic[i] = GNUNET_PEERINFO_iterate(h, | 156 | ic[i] = GNUNET_PEERINFO_iterate (h, |
157 | GNUNET_YES, | 157 | GNUNET_YES, |
158 | NULL, | 158 | NULL, |
159 | &process, | 159 | &process, |
160 | &ic[i]); | 160 | &ic[i]); |
161 | } | 161 | } |
162 | tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, | 162 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply ( |
163 | 5), | 163 | GNUNET_TIME_UNIT_SECONDS, |
164 | &do_timeout, | 164 | 5), |
165 | NULL); | 165 | &do_timeout, |
166 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | 166 | NULL); |
167 | NULL); | 167 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
168 | NULL); | ||
168 | } | 169 | } |
169 | 170 | ||
170 | 171 | ||
171 | int | 172 | int |
172 | main(int argc, | 173 | main (int argc, |
173 | char *argv[]) | 174 | char *argv[]) |
174 | { | 175 | { |
175 | if (0 != GNUNET_TESTING_service_run("perf-gnunet-peerinfo", | 176 | if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo", |
176 | "peerinfo", | 177 | "peerinfo", |
177 | "test_peerinfo_api_data.conf", | 178 | "test_peerinfo_api_data.conf", |
178 | &run, NULL)) | 179 | &run, NULL)) |
179 | return 1; | 180 | return 1; |
180 | fprintf(stderr, | 181 | fprintf (stderr, |
181 | "Received %u/%u calls before timeout\n", | 182 | "Received %u/%u calls before timeout\n", |
182 | numpeers, | 183 | numpeers, |
183 | NUM_REQUESTS * NUM_REQUESTS / 2); | 184 | NUM_REQUESTS * NUM_REQUESTS / 2); |
184 | GAUGER("PEERINFO", | 185 | GAUGER ("PEERINFO", |
185 | "Peerinfo lookups", | 186 | "Peerinfo lookups", |
186 | numpeers / 5, | 187 | numpeers / 5, |
187 | "peers/s"); | 188 | "peers/s"); |
188 | return 0; | 189 | return 0; |
189 | } | 190 | } |
190 | 191 | ||
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 4c2184904..b13b9dc57 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -43,25 +43,25 @@ static int global_ret; | |||
43 | 43 | ||
44 | 44 | ||
45 | static int | 45 | static int |
46 | check_it(void *cls, const struct GNUNET_HELLO_Address *address, | 46 | check_it (void *cls, const struct GNUNET_HELLO_Address *address, |
47 | struct GNUNET_TIME_Absolute expiration) | 47 | struct GNUNET_TIME_Absolute expiration) |
48 | { | 48 | { |
49 | unsigned int *agc = cls; | 49 | unsigned int *agc = cls; |
50 | 50 | ||
51 | if (address != NULL) | 51 | if (address != NULL) |
52 | { | 52 | { |
53 | GNUNET_assert(0 == strcmp("peerinfotest", address->transport_name)); | 53 | GNUNET_assert (0 == strcmp ("peerinfotest", address->transport_name)); |
54 | GNUNET_assert(0 == | 54 | GNUNET_assert (0 == |
55 | strncmp("Address", address->address, | 55 | strncmp ("Address", address->address, |
56 | address->address_length)); | 56 | address->address_length)); |
57 | (*agc) -= (1 << (address->address_length - 1)); | 57 | (*agc) -= (1 << (address->address_length - 1)); |
58 | } | 58 | } |
59 | return GNUNET_OK; | 59 | return GNUNET_OK; |
60 | } | 60 | } |
61 | 61 | ||
62 | 62 | ||
63 | static ssize_t | 63 | static ssize_t |
64 | address_generator(void *cls, size_t max, void *buf) | 64 | address_generator (void *cls, size_t max, void *buf) |
65 | { | 65 | { |
66 | size_t *agc = cls; | 66 | size_t *agc = cls; |
67 | ssize_t ret; | 67 | ssize_t ret; |
@@ -69,14 +69,14 @@ address_generator(void *cls, size_t max, void *buf) | |||
69 | 69 | ||
70 | if (0 == *agc) | 70 | if (0 == *agc) |
71 | return GNUNET_SYSERR; /* Done */ | 71 | return GNUNET_SYSERR; /* Done */ |
72 | memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); | 72 | memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); |
73 | address.address = "Address"; | 73 | address.address = "Address"; |
74 | address.transport_name = "peerinfotest"; | 74 | address.transport_name = "peerinfotest"; |
75 | address.address_length = *agc; | 75 | address.address_length = *agc; |
76 | ret = | 76 | ret = |
77 | GNUNET_HELLO_add_address(&address, | 77 | GNUNET_HELLO_add_address (&address, |
78 | GNUNET_TIME_relative_to_absolute | 78 | GNUNET_TIME_relative_to_absolute |
79 | (GNUNET_TIME_UNIT_HOURS), buf, max); | 79 | (GNUNET_TIME_UNIT_HOURS), buf, max); |
80 | (*agc)--; | 80 | (*agc)--; |
81 | return ret; | 81 | return ret; |
82 | } | 82 | } |
@@ -84,84 +84,85 @@ address_generator(void *cls, size_t max, void *buf) | |||
84 | struct GNUNET_PeerIdentity pid; | 84 | struct GNUNET_PeerIdentity pid; |
85 | 85 | ||
86 | static void | 86 | static void |
87 | add_peer() | 87 | add_peer () |
88 | { | 88 | { |
89 | struct GNUNET_HELLO_Message *h2; | 89 | struct GNUNET_HELLO_Message *h2; |
90 | size_t agc; | 90 | size_t agc; |
91 | 91 | ||
92 | agc = 2; | 92 | agc = 2; |
93 | memset(&pid, 32, sizeof(pid)); | 93 | memset (&pid, 32, sizeof(pid)); |
94 | h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, GNUNET_NO); | 94 | h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, |
95 | GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); | 95 | GNUNET_NO); |
96 | GNUNET_free(h2); | 96 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); |
97 | GNUNET_free (h2); | ||
97 | } | 98 | } |
98 | 99 | ||
99 | 100 | ||
100 | static void | 101 | static void |
101 | process(void *cls, const struct GNUNET_PeerIdentity *peer, | 102 | process (void *cls, const struct GNUNET_PeerIdentity *peer, |
102 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 103 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
103 | { | 104 | { |
104 | unsigned int agc; | 105 | unsigned int agc; |
105 | 106 | ||
106 | if (err_msg != NULL) | 107 | if (err_msg != NULL) |
107 | { | 108 | { |
108 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 109 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
109 | _("Error in communication with PEERINFO service\n")); | 110 | _ ("Error in communication with PEERINFO service\n")); |
110 | } | 111 | } |
111 | 112 | ||
112 | if (peer == NULL) | 113 | if (peer == NULL) |
114 | { | ||
115 | ic = NULL; | ||
116 | if ((3 == global_ret) && (retries < 50)) | ||
113 | { | 117 | { |
114 | ic = NULL; | 118 | /* try again */ |
115 | if ((3 == global_ret) && (retries < 50)) | 119 | retries++; |
116 | { | 120 | add_peer (); |
117 | /* try again */ | 121 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, NULL, |
118 | retries++; | 122 | &process, |
119 | add_peer(); | 123 | cls); |
120 | ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, NULL, | ||
121 | &process, | ||
122 | cls); | ||
123 | return; | ||
124 | } | ||
125 | GNUNET_assert(peer == NULL); | ||
126 | GNUNET_assert(2 == global_ret); | ||
127 | GNUNET_PEERINFO_disconnect(h); | ||
128 | h = NULL; | ||
129 | global_ret = 0; | ||
130 | return; | 124 | return; |
131 | } | 125 | } |
126 | GNUNET_assert (peer == NULL); | ||
127 | GNUNET_assert (2 == global_ret); | ||
128 | GNUNET_PEERINFO_disconnect (h); | ||
129 | h = NULL; | ||
130 | global_ret = 0; | ||
131 | return; | ||
132 | } | ||
132 | if (hello != NULL) | 133 | if (hello != NULL) |
133 | { | 134 | { |
134 | GNUNET_assert(3 == global_ret); | 135 | GNUNET_assert (3 == global_ret); |
135 | agc = 3; | 136 | agc = 3; |
136 | GNUNET_HELLO_iterate_addresses(hello, GNUNET_NO, | 137 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, |
137 | &check_it, &agc); | 138 | &check_it, &agc); |
138 | GNUNET_assert(agc == 0); | 139 | GNUNET_assert (agc == 0); |
139 | global_ret = 2; | 140 | global_ret = 2; |
140 | } | 141 | } |
141 | } | 142 | } |
142 | 143 | ||
143 | 144 | ||
144 | static void | 145 | static void |
145 | run(void *cls, | 146 | run (void *cls, |
146 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 147 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
147 | struct GNUNET_TESTING_Peer *peer) | 148 | struct GNUNET_TESTING_Peer *peer) |
148 | { | 149 | { |
149 | h = GNUNET_PEERINFO_connect(cfg); | 150 | h = GNUNET_PEERINFO_connect (cfg); |
150 | GNUNET_assert(NULL != h); | 151 | GNUNET_assert (NULL != h); |
151 | add_peer(); | 152 | add_peer (); |
152 | ic = GNUNET_PEERINFO_iterate(h, GNUNET_NO, &pid, | 153 | ic = GNUNET_PEERINFO_iterate (h, GNUNET_NO, &pid, |
153 | &process, cls); | 154 | &process, cls); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
157 | int | 158 | int |
158 | main(int argc, char *argv[]) | 159 | main (int argc, char *argv[]) |
159 | { | 160 | { |
160 | global_ret = 3; | 161 | global_ret = 3; |
161 | if (0 != GNUNET_TESTING_service_run("test-gnunet-peerinfo", | 162 | if (0 != GNUNET_TESTING_service_run ("test-gnunet-peerinfo", |
162 | "peerinfo", | 163 | "peerinfo", |
163 | "test_peerinfo_api_data.conf", | 164 | "test_peerinfo_api_data.conf", |
164 | &run, NULL)) | 165 | &run, NULL)) |
165 | return 1; | 166 | return 1; |
166 | return global_ret; | 167 | return global_ret; |
167 | } | 168 | } |
diff --git a/src/peerinfo/test_peerinfo_api_friend_only.c b/src/peerinfo/test_peerinfo_api_friend_only.c index a7bd69e6f..8d50cf417 100644 --- a/src/peerinfo/test_peerinfo_api_friend_only.c +++ b/src/peerinfo/test_peerinfo_api_friend_only.c | |||
@@ -46,9 +46,9 @@ static int global_ret; | |||
46 | 46 | ||
47 | 47 | ||
48 | static ssize_t | 48 | static ssize_t |
49 | address_generator(void *cls, | 49 | address_generator (void *cls, |
50 | size_t max, | 50 | size_t max, |
51 | void *buf) | 51 | void *buf) |
52 | { | 52 | { |
53 | size_t *agc = cls; | 53 | size_t *agc = cls; |
54 | ssize_t ret; | 54 | ssize_t ret; |
@@ -56,113 +56,114 @@ address_generator(void *cls, | |||
56 | 56 | ||
57 | if (0 == *agc) | 57 | if (0 == *agc) |
58 | return GNUNET_SYSERR; /* Done */ | 58 | return GNUNET_SYSERR; /* Done */ |
59 | memset(&address.peer, | 59 | memset (&address.peer, |
60 | 0, | 60 | 0, |
61 | sizeof(struct GNUNET_PeerIdentity)); | 61 | sizeof(struct GNUNET_PeerIdentity)); |
62 | address.address = "Address"; | 62 | address.address = "Address"; |
63 | address.transport_name = "peerinfotest"; | 63 | address.transport_name = "peerinfotest"; |
64 | address.address_length = *agc; | 64 | address.address_length = *agc; |
65 | ret = GNUNET_HELLO_add_address(&address, | 65 | ret = GNUNET_HELLO_add_address (&address, |
66 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), | 66 | GNUNET_TIME_relative_to_absolute ( |
67 | buf, | 67 | GNUNET_TIME_UNIT_HOURS), |
68 | max); | 68 | buf, |
69 | max); | ||
69 | (*agc)--; | 70 | (*agc)--; |
70 | return ret; | 71 | return ret; |
71 | } | 72 | } |
72 | 73 | ||
73 | 74 | ||
74 | static void | 75 | static void |
75 | add_peer() | 76 | add_peer () |
76 | { | 77 | { |
77 | struct GNUNET_HELLO_Message *h2; | 78 | struct GNUNET_HELLO_Message *h2; |
78 | size_t agc; | 79 | size_t agc; |
79 | 80 | ||
80 | agc = 2; | 81 | agc = 2; |
81 | memset(&pid, 32, sizeof(pid)); | 82 | memset (&pid, 32, sizeof(pid)); |
82 | h2 = GNUNET_HELLO_create(&pid.public_key, | 83 | h2 = GNUNET_HELLO_create (&pid.public_key, |
83 | &address_generator, | 84 | &address_generator, |
84 | &agc, | 85 | &agc, |
85 | GNUNET_YES); | 86 | GNUNET_YES); |
86 | GNUNET_PEERINFO_add_peer(h, | 87 | GNUNET_PEERINFO_add_peer (h, |
87 | h2, | 88 | h2, |
88 | NULL, | 89 | NULL, |
89 | NULL); | 90 | NULL); |
90 | GNUNET_free(h2); | 91 | GNUNET_free (h2); |
91 | } | 92 | } |
92 | 93 | ||
93 | 94 | ||
94 | static void | 95 | static void |
95 | process(void *cls, | 96 | process (void *cls, |
96 | const struct GNUNET_PeerIdentity *peer, | 97 | const struct GNUNET_PeerIdentity *peer, |
97 | const struct GNUNET_HELLO_Message *hello, | 98 | const struct GNUNET_HELLO_Message *hello, |
98 | const char *err_msg) | 99 | const char *err_msg) |
99 | { | 100 | { |
100 | if (NULL != err_msg) | 101 | if (NULL != err_msg) |
101 | { | 102 | { |
102 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 103 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
103 | "Error in communication with PEERINFO service: %s\n", | 104 | "Error in communication with PEERINFO service: %s\n", |
104 | err_msg); | 105 | err_msg); |
105 | } | 106 | } |
106 | if (NULL == peer) | 107 | if (NULL == peer) |
108 | { | ||
109 | ic = NULL; | ||
110 | if ((3 == global_ret) && (retries < 50)) | ||
107 | { | 111 | { |
108 | ic = NULL; | 112 | /* try again */ |
109 | if ((3 == global_ret) && (retries < 50)) | 113 | retries++; |
110 | { | 114 | add_peer (); |
111 | /* try again */ | 115 | ic = GNUNET_PEERINFO_iterate (h, |
112 | retries++; | 116 | GNUNET_NO, |
113 | add_peer(); | 117 | NULL, |
114 | ic = GNUNET_PEERINFO_iterate(h, | 118 | &process, |
115 | GNUNET_NO, | 119 | cls); |
116 | NULL, | ||
117 | &process, | ||
118 | cls); | ||
119 | return; | ||
120 | } | ||
121 | GNUNET_assert(peer == NULL); | ||
122 | GNUNET_PEERINFO_disconnect(h); | ||
123 | h = NULL; | ||
124 | global_ret = 0; | ||
125 | return; | 120 | return; |
126 | } | 121 | } |
122 | GNUNET_assert (peer == NULL); | ||
123 | GNUNET_PEERINFO_disconnect (h); | ||
124 | h = NULL; | ||
125 | global_ret = 0; | ||
126 | return; | ||
127 | } | ||
127 | 128 | ||
128 | if ((NULL != hello) && | 129 | if ((NULL != hello) && |
129 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))) | 130 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello))) |
130 | { | 131 | { |
131 | fprintf(stderr, | 132 | fprintf (stderr, |
132 | "Received friend-only HELLO\n"); | 133 | "Received friend-only HELLO\n"); |
133 | global_ret = 1; | 134 | global_ret = 1; |
134 | GNUNET_PEERINFO_disconnect(h); | 135 | GNUNET_PEERINFO_disconnect (h); |
135 | h = NULL; | 136 | h = NULL; |
136 | return; | 137 | return; |
137 | } | 138 | } |
138 | } | 139 | } |
139 | 140 | ||
140 | 141 | ||
141 | static void | 142 | static void |
142 | run(void *cls, | 143 | run (void *cls, |
143 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 144 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
144 | struct GNUNET_TESTING_Peer *peer) | 145 | struct GNUNET_TESTING_Peer *peer) |
145 | { | 146 | { |
146 | h = GNUNET_PEERINFO_connect(cfg); | 147 | h = GNUNET_PEERINFO_connect (cfg); |
147 | GNUNET_assert(NULL != h); | 148 | GNUNET_assert (NULL != h); |
148 | add_peer(); | 149 | add_peer (); |
149 | ic = GNUNET_PEERINFO_iterate(h, | 150 | ic = GNUNET_PEERINFO_iterate (h, |
150 | GNUNET_NO, | 151 | GNUNET_NO, |
151 | &pid, | 152 | &pid, |
152 | &process, | 153 | &process, |
153 | NULL); | 154 | NULL); |
154 | } | 155 | } |
155 | 156 | ||
156 | 157 | ||
157 | int | 158 | int |
158 | main(int argc, | 159 | main (int argc, |
159 | char *argv[]) | 160 | char *argv[]) |
160 | { | 161 | { |
161 | global_ret = 3; | 162 | global_ret = 3; |
162 | if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only", | 163 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", |
163 | "peerinfo", | 164 | "peerinfo", |
164 | "test_peerinfo_api_data.conf", | 165 | "test_peerinfo_api_data.conf", |
165 | &run, NULL)) | 166 | &run, NULL)) |
166 | return 1; | 167 | return 1; |
167 | return global_ret; | 168 | return global_ret; |
168 | } | 169 | } |
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c index 80b5883de..7c5162102 100644 --- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c +++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c | |||
@@ -34,7 +34,7 @@ | |||
34 | #include "gnunet_testing_lib.h" | 34 | #include "gnunet_testing_lib.h" |
35 | #include "peerinfo.h" | 35 | #include "peerinfo.h" |
36 | 36 | ||
37 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) | 37 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) |
38 | 38 | ||
39 | static struct GNUNET_PEERINFO_Handle *h; | 39 | static struct GNUNET_PEERINFO_Handle *h; |
40 | static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo; | 40 | static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo; |
@@ -61,55 +61,55 @@ struct GNUNET_PeerIdentity pid; | |||
61 | struct GNUNET_SCHEDULER_Task *timeout_task; | 61 | struct GNUNET_SCHEDULER_Task *timeout_task; |
62 | 62 | ||
63 | static void | 63 | static void |
64 | end_badly(void *cls) | 64 | end_badly (void *cls) |
65 | { | 65 | { |
66 | timeout_task = NULL; | 66 | timeout_task = NULL; |
67 | GNUNET_break(0); | 67 | GNUNET_break (0); |
68 | if (NULL != pnc_wo_fo) | 68 | if (NULL != pnc_wo_fo) |
69 | { | 69 | { |
70 | GNUNET_PEERINFO_notify_cancel(pnc_wo_fo); | 70 | GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); |
71 | pnc_wo_fo = NULL; | 71 | pnc_wo_fo = NULL; |
72 | } | 72 | } |
73 | if (NULL != pnc_w_fo) | 73 | if (NULL != pnc_w_fo) |
74 | { | 74 | { |
75 | GNUNET_PEERINFO_notify_cancel(pnc_w_fo); | 75 | GNUNET_PEERINFO_notify_cancel (pnc_w_fo); |
76 | pnc_w_fo = NULL; | 76 | pnc_w_fo = NULL; |
77 | } | 77 | } |
78 | if (NULL != h) | 78 | if (NULL != h) |
79 | { | 79 | { |
80 | GNUNET_PEERINFO_disconnect(h); | 80 | GNUNET_PEERINFO_disconnect (h); |
81 | h = NULL; | 81 | h = NULL; |
82 | } | 82 | } |
83 | global_ret = 255; | 83 | global_ret = 255; |
84 | } | 84 | } |
85 | 85 | ||
86 | 86 | ||
87 | static void | 87 | static void |
88 | done(void *cls) | 88 | done (void *cls) |
89 | { | 89 | { |
90 | if (NULL != pnc_w_fo) | 90 | if (NULL != pnc_w_fo) |
91 | GNUNET_PEERINFO_notify_cancel(pnc_w_fo); | 91 | GNUNET_PEERINFO_notify_cancel (pnc_w_fo); |
92 | pnc_w_fo = NULL; | 92 | pnc_w_fo = NULL; |
93 | if (NULL != pnc_wo_fo) | 93 | if (NULL != pnc_wo_fo) |
94 | GNUNET_PEERINFO_notify_cancel(pnc_wo_fo); | 94 | GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); |
95 | pnc_wo_fo = NULL; | 95 | pnc_wo_fo = NULL; |
96 | GNUNET_PEERINFO_disconnect(h); | 96 | GNUNET_PEERINFO_disconnect (h); |
97 | h = NULL; | 97 | h = NULL; |
98 | 98 | ||
99 | if (NULL != timeout_task) | 99 | if (NULL != timeout_task) |
100 | { | 100 | { |
101 | GNUNET_SCHEDULER_cancel(timeout_task); | 101 | GNUNET_SCHEDULER_cancel (timeout_task); |
102 | timeout_task = NULL; | 102 | timeout_task = NULL; |
103 | } | 103 | } |
104 | 104 | ||
105 | if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) | 105 | if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) |
106 | global_ret = 0; | 106 | global_ret = 0; |
107 | else | 107 | else |
108 | GNUNET_break(0); | 108 | GNUNET_break (0); |
109 | } | 109 | } |
110 | 110 | ||
111 | static ssize_t | 111 | static ssize_t |
112 | address_generator(void *cls, size_t max, void *buf) | 112 | address_generator (void *cls, size_t max, void *buf) |
113 | { | 113 | { |
114 | size_t *agc = cls; | 114 | size_t *agc = cls; |
115 | ssize_t ret; | 115 | ssize_t ret; |
@@ -117,137 +117,140 @@ address_generator(void *cls, size_t max, void *buf) | |||
117 | 117 | ||
118 | if (0 == *agc) | 118 | if (0 == *agc) |
119 | return GNUNET_SYSERR; /* Done */ | 119 | return GNUNET_SYSERR; /* Done */ |
120 | memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); | 120 | memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); |
121 | address.address = "Address"; | 121 | address.address = "Address"; |
122 | address.transport_name = "peerinfotest"; | 122 | address.transport_name = "peerinfotest"; |
123 | address.address_length = *agc; | 123 | address.address_length = *agc; |
124 | ret = GNUNET_HELLO_add_address(&address, | 124 | ret = GNUNET_HELLO_add_address (&address, |
125 | GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), buf, max); | 125 | GNUNET_TIME_relative_to_absolute ( |
126 | GNUNET_TIME_UNIT_HOURS), buf, max); | ||
126 | (*agc)--; | 127 | (*agc)--; |
127 | return ret; | 128 | return ret; |
128 | } | 129 | } |
129 | 130 | ||
130 | 131 | ||
131 | static void | 132 | static void |
132 | process_w_fo(void *cls, | 133 | process_w_fo (void *cls, |
133 | const struct GNUNET_PeerIdentity *peer, | 134 | const struct GNUNET_PeerIdentity *peer, |
134 | const struct GNUNET_HELLO_Message *hello, | 135 | const struct GNUNET_HELLO_Message *hello, |
135 | const char *err_msg) | 136 | const char *err_msg) |
136 | { | 137 | { |
137 | if (err_msg != NULL) | 138 | if (err_msg != NULL) |
139 | { | ||
140 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
141 | _ ("Error in communication with PEERINFO service\n")); | ||
142 | GNUNET_SCHEDULER_add_now (&done, NULL); | ||
143 | return; | ||
144 | } | ||
145 | |||
146 | if (NULL != peer) | ||
147 | { | ||
148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
149 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer), | ||
150 | (NULL != hello) ? "with" : "without"); | ||
151 | |||
152 | if (NULL == hello) | ||
153 | return; | ||
154 | |||
155 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello)) | ||
138 | { | 156 | { |
139 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 157 | GNUNET_break (0); |
140 | _("Error in communication with PEERINFO service\n")); | ||
141 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
142 | return; | 158 | return; |
143 | } | 159 | } |
144 | 160 | ||
145 | if (NULL != peer) | 161 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", |
162 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? | ||
163 | "friend only" : "public", | ||
164 | GNUNET_i2s (peer)); | ||
165 | if (0 == GNUNET_memcmp (&pid, peer)) | ||
146 | { | 166 | { |
147 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 167 | res_cb_w_fo = GNUNET_YES; |
148 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer), | 168 | GNUNET_SCHEDULER_add_now (&done, NULL); |
149 | (NULL != hello) ? "with" : "without"); | ||
150 | |||
151 | if (NULL == hello) | ||
152 | return; | ||
153 | |||
154 | if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello)) | ||
155 | { | ||
156 | GNUNET_break(0); | ||
157 | return; | ||
158 | } | ||
159 | |||
160 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", | ||
161 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend only" : "public", | ||
162 | GNUNET_i2s(peer)); | ||
163 | if (0 == GNUNET_memcmp(&pid, peer)) | ||
164 | { | ||
165 | res_cb_w_fo = GNUNET_YES; | ||
166 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
167 | } | ||
168 | return; | ||
169 | } | 169 | } |
170 | return; | ||
171 | } | ||
170 | } | 172 | } |
171 | 173 | ||
172 | static void | 174 | static void |
173 | process_wo_fo(void *cls, const struct GNUNET_PeerIdentity *peer, | 175 | process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, |
174 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 176 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
175 | { | 177 | { |
176 | if (err_msg != NULL) | 178 | if (err_msg != NULL) |
179 | { | ||
180 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
181 | _ ("Error in communication with PEERINFO service\n")); | ||
182 | GNUNET_SCHEDULER_add_now (&done, NULL); | ||
183 | return; | ||
184 | } | ||
185 | |||
186 | if (NULL != peer) | ||
187 | { | ||
188 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
189 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer), | ||
190 | (NULL != hello) ? "with" : "without"); | ||
191 | |||
192 | if (NULL == hello) | ||
193 | return; | ||
194 | |||
195 | if (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) | ||
177 | { | 196 | { |
178 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 197 | GNUNET_break (0); |
179 | _("Error in communication with PEERINFO service\n")); | ||
180 | GNUNET_SCHEDULER_add_now(&done, NULL); | ||
181 | return; | 198 | return; |
182 | } | 199 | } |
183 | 200 | ||
184 | if (NULL != peer) | 201 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", |
202 | (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? | ||
203 | "friend only" : "public", | ||
204 | GNUNET_i2s (peer)); | ||
205 | if (0 == GNUNET_memcmp (&pid, peer)) | ||
185 | { | 206 | { |
186 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 207 | GNUNET_break (0); |
187 | "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer), | 208 | res_cb_wo_fo = GNUNET_YES; |
188 | (NULL != hello) ? "with" : "without"); | ||
189 | |||
190 | if (NULL == hello) | ||
191 | return; | ||
192 | |||
193 | if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) | ||
194 | { | ||
195 | GNUNET_break(0); | ||
196 | return; | ||
197 | } | ||
198 | |||
199 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", | ||
200 | (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) ? "friend only" : "public", | ||
201 | GNUNET_i2s(peer)); | ||
202 | if (0 == GNUNET_memcmp(&pid, peer)) | ||
203 | { | ||
204 | GNUNET_break(0); | ||
205 | res_cb_wo_fo = GNUNET_YES; | ||
206 | } | ||
207 | } | 209 | } |
210 | } | ||
208 | } | 211 | } |
209 | 212 | ||
210 | 213 | ||
211 | static void | 214 | static void |
212 | add_peer() | 215 | add_peer () |
213 | { | 216 | { |
214 | struct GNUNET_HELLO_Message *h2; | 217 | struct GNUNET_HELLO_Message *h2; |
215 | size_t agc; | 218 | size_t agc; |
216 | 219 | ||
217 | agc = 2; | 220 | agc = 2; |
218 | memset(&pid, 32, sizeof(pid)); | 221 | memset (&pid, 32, sizeof(pid)); |
219 | h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, | 222 | h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, |
220 | GNUNET_YES); | 223 | GNUNET_YES); |
221 | GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); | 224 | GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); |
222 | GNUNET_free(h2); | 225 | GNUNET_free (h2); |
223 | } | 226 | } |
224 | 227 | ||
225 | 228 | ||
226 | static void | 229 | static void |
227 | run(void *cls, | 230 | run (void *cls, |
228 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 231 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
229 | struct GNUNET_TESTING_Peer *peer) | 232 | struct GNUNET_TESTING_Peer *peer) |
230 | { | 233 | { |
231 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); | 234 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); |
232 | mycfg = cfg; | 235 | mycfg = cfg; |
233 | pnc_w_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_YES, &process_w_fo, NULL); | 236 | pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL); |
234 | pnc_wo_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_NO, &process_wo_fo, NULL); | 237 | pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL); |
235 | h = GNUNET_PEERINFO_connect(cfg); | 238 | h = GNUNET_PEERINFO_connect (cfg); |
236 | GNUNET_assert(NULL != h); | 239 | GNUNET_assert (NULL != h); |
237 | add_peer(); | 240 | add_peer (); |
238 | } | 241 | } |
239 | 242 | ||
240 | 243 | ||
241 | int | 244 | int |
242 | main(int argc, char *argv[]) | 245 | main (int argc, char *argv[]) |
243 | { | 246 | { |
244 | res_cb_w_fo = GNUNET_NO; | 247 | res_cb_w_fo = GNUNET_NO; |
245 | res_cb_wo_fo = GNUNET_NO; | 248 | res_cb_wo_fo = GNUNET_NO; |
246 | global_ret = 3; | 249 | global_ret = 3; |
247 | if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only", | 250 | if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", |
248 | "peerinfo", | 251 | "peerinfo", |
249 | "test_peerinfo_api_data.conf", | 252 | "test_peerinfo_api_data.conf", |
250 | &run, NULL)) | 253 | &run, NULL)) |
251 | return 1; | 254 | return 1; |
252 | return global_ret; | 255 | return global_ret; |
253 | } | 256 | } |
diff --git a/src/peerinfo/test_peerinfo_shipped_hellos.c b/src/peerinfo/test_peerinfo_shipped_hellos.c index 36deade1e..24cc26a94 100644 --- a/src/peerinfo/test_peerinfo_shipped_hellos.c +++ b/src/peerinfo/test_peerinfo_shipped_hellos.c | |||
@@ -40,9 +40,9 @@ static int global_ret; | |||
40 | 40 | ||
41 | 41 | ||
42 | static int | 42 | static int |
43 | addr_cb(void *cls, | 43 | addr_cb (void *cls, |
44 | const struct GNUNET_HELLO_Address *address, | 44 | const struct GNUNET_HELLO_Address *address, |
45 | struct GNUNET_TIME_Absolute expiration) | 45 | struct GNUNET_TIME_Absolute expiration) |
46 | { | 46 | { |
47 | unsigned int *addr = cls; | 47 | unsigned int *addr = cls; |
48 | 48 | ||
@@ -52,90 +52,90 @@ addr_cb(void *cls, | |||
52 | 52 | ||
53 | 53 | ||
54 | static void | 54 | static void |
55 | process(void *cls, | 55 | process (void *cls, |
56 | const struct GNUNET_PeerIdentity *peer, | 56 | const struct GNUNET_PeerIdentity *peer, |
57 | const struct GNUNET_HELLO_Message *hello, | 57 | const struct GNUNET_HELLO_Message *hello, |
58 | const char *err_msg) | 58 | const char *err_msg) |
59 | { | 59 | { |
60 | static unsigned int calls = 0; | 60 | static unsigned int calls = 0; |
61 | unsigned int addr; | 61 | unsigned int addr; |
62 | 62 | ||
63 | if (NULL != err_msg) | 63 | if (NULL != err_msg) |
64 | { | ||
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
66 | "Error in communication with PEERINFO service: %s\n", | ||
67 | err_msg); | ||
68 | } | ||
69 | if (NULL != peer) | ||
70 | { | ||
71 | addr = 0; | ||
72 | if (NULL != hello) | ||
64 | { | 73 | { |
65 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 74 | GNUNET_HELLO_iterate_addresses (hello, |
66 | "Error in communication with PEERINFO service: %s\n", | 75 | GNUNET_NO, |
67 | err_msg); | 76 | &addr_cb, |
77 | &addr); | ||
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Got information about peer %s with %u addresses\n", | ||
80 | GNUNET_i2s (peer), | ||
81 | addr); | ||
82 | calls++; | ||
68 | } | 83 | } |
69 | if (NULL != peer) | 84 | else |
70 | { | 85 | { |
71 | addr = 0; | 86 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
72 | if (NULL != hello) | 87 | "Got no HELLP for peer %s\n", |
73 | { | 88 | GNUNET_i2s (peer)); |
74 | GNUNET_HELLO_iterate_addresses(hello, | ||
75 | GNUNET_NO, | ||
76 | &addr_cb, | ||
77 | &addr); | ||
78 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
79 | "Got information about peer %s with %u addresses\n", | ||
80 | GNUNET_i2s(peer), | ||
81 | addr); | ||
82 | calls++; | ||
83 | } | ||
84 | else | ||
85 | { | ||
86 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
87 | "Got no HELLP for peer %s\n", | ||
88 | GNUNET_i2s(peer)); | ||
89 | } | ||
90 | } | 89 | } |
90 | } | ||
91 | else | 91 | else |
92 | { | ||
93 | if (0 == calls) | ||
94 | { | ||
95 | fprintf (stderr, | ||
96 | "Failed: got no callbacks!\n"); | ||
97 | global_ret = 1; | ||
98 | GNUNET_PEERINFO_disconnect (h); | ||
99 | h = NULL; | ||
100 | } | ||
101 | else | ||
92 | { | 102 | { |
93 | if (0 == calls) | 103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
94 | { | 104 | "Got %u HELLOs in total\n", |
95 | fprintf(stderr, | 105 | calls); |
96 | "Failed: got no callbacks!\n"); | 106 | global_ret = 0; |
97 | global_ret = 1; | 107 | GNUNET_PEERINFO_disconnect (h); |
98 | GNUNET_PEERINFO_disconnect(h); | 108 | h = NULL; |
99 | h = NULL; | ||
100 | } | ||
101 | else | ||
102 | { | ||
103 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
104 | "Got %u HELLOs in total\n", | ||
105 | calls); | ||
106 | global_ret = 0; | ||
107 | GNUNET_PEERINFO_disconnect(h); | ||
108 | h = NULL; | ||
109 | } | ||
110 | } | 109 | } |
110 | } | ||
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | static void | 114 | static void |
115 | run(void *cls, | 115 | run (void *cls, |
116 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 116 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
117 | struct GNUNET_TESTING_Peer *peer) | 117 | struct GNUNET_TESTING_Peer *peer) |
118 | { | 118 | { |
119 | h = GNUNET_PEERINFO_connect(cfg); | 119 | h = GNUNET_PEERINFO_connect (cfg); |
120 | GNUNET_assert(NULL != h); | 120 | GNUNET_assert (NULL != h); |
121 | ic = GNUNET_PEERINFO_iterate(h, | 121 | ic = GNUNET_PEERINFO_iterate (h, |
122 | GNUNET_YES, | 122 | GNUNET_YES, |
123 | NULL, | 123 | NULL, |
124 | &process, | 124 | &process, |
125 | cls); | 125 | cls); |
126 | GNUNET_assert(NULL != ic); | 126 | GNUNET_assert (NULL != ic); |
127 | } | 127 | } |
128 | 128 | ||
129 | 129 | ||
130 | int | 130 | int |
131 | main(int argc, | 131 | main (int argc, |
132 | char *argv[]) | 132 | char *argv[]) |
133 | { | 133 | { |
134 | global_ret = 3; | 134 | global_ret = 3; |
135 | if (0 != GNUNET_TESTING_service_run("test_peerinfo_shipped_hellos", | 135 | if (0 != GNUNET_TESTING_service_run ("test_peerinfo_shipped_hellos", |
136 | "peerinfo", | 136 | "peerinfo", |
137 | "test_peerinfo_api_data.conf", | 137 | "test_peerinfo_api_data.conf", |
138 | &run, NULL)) | 138 | &run, NULL)) |
139 | return 1; | 139 | return 1; |
140 | return global_ret; | 140 | return global_ret; |
141 | } | 141 | } |