diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-07-07 06:27:10 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-07-07 06:27:10 +0000 |
commit | ac2de52a5de68f6f4f13b7aa01a481869fffc6aa (patch) | |
tree | 856c9f0b2f55f8cae99f3c7b3bf22beaecbf58da /src/peerinfo | |
parent | c1a3c11f8665432d9db6d549c28c0329668e66af (diff) | |
download | gnunet-ac2de52a5de68f6f4f13b7aa01a481869fffc6aa.tar.gz gnunet-ac2de52a5de68f6f4f13b7aa01a481869fffc6aa.zip |
hacks from trip
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 181 | ||||
-rw-r--r-- | src/peerinfo/peerinfo.h | 37 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 40 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api_notify.c | 2 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 5 |
5 files changed, 33 insertions, 232 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 692f71e9b..ee8749955 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -23,7 +23,7 @@ | |||
23 | * @brief maintains list of known peers | 23 | * @brief maintains list of known peers |
24 | * | 24 | * |
25 | * Code to maintain the list of currently known hosts (in memory | 25 | * Code to maintain the list of currently known hosts (in memory |
26 | * structure of data/hosts/ and data/credit/). | 26 | * structure of data/hosts/). |
27 | * | 27 | * |
28 | * @author Christian Grothoff | 28 | * @author Christian Grothoff |
29 | * | 29 | * |
@@ -46,11 +46,6 @@ | |||
46 | #define DATA_HOST_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) | 46 | #define DATA_HOST_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * How often do we flush trust values to disk? | ||
50 | */ | ||
51 | #define TRUST_FLUSH_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) | ||
52 | |||
53 | /** | ||
54 | * How often do we discard old entries in data/hosts/? | 49 | * How often do we discard old entries in data/hosts/? |
55 | */ | 50 | */ |
56 | #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) | 51 | #define DATA_HOST_CLEAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 60) |
@@ -76,16 +71,6 @@ struct HostEntry | |||
76 | */ | 71 | */ |
77 | struct GNUNET_HELLO_Message *hello; | 72 | struct GNUNET_HELLO_Message *hello; |
78 | 73 | ||
79 | /** | ||
80 | * Trust rating for this peer | ||
81 | */ | ||
82 | uint32_t trust; | ||
83 | |||
84 | /** | ||
85 | * Trust rating for this peer on disk. | ||
86 | */ | ||
87 | uint32_t disk_trust; | ||
88 | |||
89 | }; | 74 | }; |
90 | 75 | ||
91 | 76 | ||
@@ -105,11 +90,6 @@ static struct GNUNET_SERVER_NotificationContext *notify_list; | |||
105 | static char *networkIdDirectory; | 90 | static char *networkIdDirectory; |
106 | 91 | ||
107 | /** | 92 | /** |
108 | * Where do we store trust information? | ||
109 | */ | ||
110 | static char *trustDirectory; | ||
111 | |||
112 | /** | ||
113 | * Handle for reporting statistics. | 93 | * Handle for reporting statistics. |
114 | */ | 94 | */ |
115 | static struct GNUNET_STATISTICS_Handle *stats; | 95 | static struct GNUNET_STATISTICS_Handle *stats; |
@@ -129,7 +109,6 @@ make_info_message (const struct HostEntry *he) | |||
129 | im = GNUNET_malloc (sizeof (struct InfoMessage) + hs); | 109 | im = GNUNET_malloc (sizeof (struct InfoMessage) + hs); |
130 | im->header.size = htons (hs + sizeof (struct InfoMessage)); | 110 | im->header.size = htons (hs + sizeof (struct InfoMessage)); |
131 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 111 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
132 | im->trust = htonl (he->trust); | ||
133 | im->peer = he->identity; | 112 | im->peer = he->identity; |
134 | if (he->hello != NULL) | 113 | if (he->hello != NULL) |
135 | memcpy (&im[1], he->hello, hs); | 114 | memcpy (&im[1], he->hello, hs); |
@@ -184,25 +163,7 @@ get_host_filename (const struct GNUNET_PeerIdentity *id) | |||
184 | 163 | ||
185 | 164 | ||
186 | /** | 165 | /** |
187 | * Get the filename under which we would store the GNUNET_HELLO_Message | 166 | * Find the host entry for the given peer. FIXME: replace by hash map! |
188 | * for the given host and protocol. | ||
189 | * @return filename of the form DIRECTORY/HOSTID | ||
190 | */ | ||
191 | static char * | ||
192 | get_trust_filename (const struct GNUNET_PeerIdentity *id) | ||
193 | { | ||
194 | struct GNUNET_CRYPTO_HashAsciiEncoded fil; | ||
195 | char *fn; | ||
196 | |||
197 | GNUNET_CRYPTO_hash_to_enc (&id->hashPubKey, &fil); | ||
198 | GNUNET_asprintf (&fn, "%s%s%s", trustDirectory, DIR_SEPARATOR_STR, &fil); | ||
199 | return fn; | ||
200 | } | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Find the host entry for the given peer. Call | ||
205 | * only when synchronized! | ||
206 | * @return NULL if not found | 167 | * @return NULL if not found |
207 | */ | 168 | */ |
208 | static struct HostEntry * | 169 | static struct HostEntry * |
@@ -247,13 +208,12 @@ static void | |||
247 | add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | 208 | add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) |
248 | { | 209 | { |
249 | struct HostEntry *entry; | 210 | struct HostEntry *entry; |
250 | char *fn; | ||
251 | uint32_t trust; | ||
252 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; | 211 | char buffer[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; |
253 | const struct GNUNET_HELLO_Message *hello; | 212 | const struct GNUNET_HELLO_Message *hello; |
254 | struct GNUNET_HELLO_Message *hello_clean; | 213 | struct GNUNET_HELLO_Message *hello_clean; |
255 | int size; | 214 | int size; |
256 | struct GNUNET_TIME_Absolute now; | 215 | struct GNUNET_TIME_Absolute now; |
216 | char *fn; | ||
257 | 217 | ||
258 | entry = lookup_host_entry (identity); | 218 | entry = lookup_host_entry (identity); |
259 | if (entry != NULL) | 219 | if (entry != NULL) |
@@ -264,11 +224,6 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
264 | GNUNET_NO); | 224 | GNUNET_NO); |
265 | entry = GNUNET_malloc (sizeof (struct HostEntry)); | 225 | entry = GNUNET_malloc (sizeof (struct HostEntry)); |
266 | entry->identity = *identity; | 226 | entry->identity = *identity; |
267 | fn = get_trust_filename (identity); | ||
268 | if ((GNUNET_DISK_file_test (fn) == GNUNET_YES) && | ||
269 | (sizeof (trust) == GNUNET_DISK_fn_read (fn, &trust, sizeof (trust)))) | ||
270 | entry->disk_trust = entry->trust = ntohl (trust); | ||
271 | GNUNET_free (fn); | ||
272 | 227 | ||
273 | fn = get_host_filename (identity); | 228 | fn = get_host_filename (identity); |
274 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) | 229 | if (GNUNET_DISK_file_test (fn) == GNUNET_YES) |
@@ -302,56 +257,6 @@ add_host_to_known_hosts (const struct GNUNET_PeerIdentity *identity) | |||
302 | 257 | ||
303 | 258 | ||
304 | /** | 259 | /** |
305 | * Increase the host credit by a value. | ||
306 | * | ||
307 | * @param hostId is the identity of the host | ||
308 | * @param value is the int value by which the | ||
309 | * host credit is to be increased or decreased | ||
310 | * @returns the actual change in trust (positive or negative) | ||
311 | */ | ||
312 | static int | ||
313 | change_host_trust (const struct GNUNET_PeerIdentity *hostId, int value) | ||
314 | { | ||
315 | struct HostEntry *host; | ||
316 | unsigned int old_trust; | ||
317 | |||
318 | if (value == 0) | ||
319 | return 0; | ||
320 | host = lookup_host_entry (hostId); | ||
321 | if (host == NULL) | ||
322 | { | ||
323 | add_host_to_known_hosts (hostId); | ||
324 | host = lookup_host_entry (hostId); | ||
325 | } | ||
326 | GNUNET_assert (host != NULL); | ||
327 | old_trust = host->trust; | ||
328 | if (value > 0) | ||
329 | { | ||
330 | if (host->trust + value < host->trust) | ||
331 | { | ||
332 | value = UINT32_MAX - host->trust; | ||
333 | host->trust = UINT32_MAX; | ||
334 | } | ||
335 | else | ||
336 | host->trust += value; | ||
337 | } | ||
338 | else | ||
339 | { | ||
340 | if (host->trust < -value) | ||
341 | { | ||
342 | value = -host->trust; | ||
343 | host->trust = 0; | ||
344 | } | ||
345 | else | ||
346 | host->trust += value; | ||
347 | } | ||
348 | if (host->trust != old_trust) | ||
349 | notify_all (host); | ||
350 | return value; | ||
351 | } | ||
352 | |||
353 | |||
354 | /** | ||
355 | * Remove a file that should not be there. LOG | 260 | * Remove a file that should not be there. LOG |
356 | * success or failure. | 261 | * success or failure. |
357 | */ | 262 | */ |
@@ -480,16 +385,14 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
480 | 385 | ||
481 | /** | 386 | /** |
482 | * Do transmit info either for only the host matching the given | 387 | * Do transmit info either for only the host matching the given |
483 | * argument or for all known hosts and change their trust values by | 388 | * argument or for all known hosts. |
484 | * the given delta. | ||
485 | * | 389 | * |
486 | * @param only NULL to hit all hosts, otherwise specifies a particular target | 390 | * @param only NULL to hit all hosts, otherwise specifies a particular target |
487 | * @param trust_change how much should the trust be changed | ||
488 | * @param client who is making the request (and will thus receive our confirmation) | 391 | * @param client who is making the request (and will thus receive our confirmation) |
489 | */ | 392 | */ |
490 | static void | 393 | static void |
491 | send_to_each_host (const struct GNUNET_PeerIdentity *only, | 394 | send_to_each_host (const struct GNUNET_PeerIdentity *only, |
492 | int trust_change, struct GNUNET_SERVER_Client *client) | 395 | struct GNUNET_SERVER_Client *client) |
493 | { | 396 | { |
494 | struct HostEntry *pos; | 397 | struct HostEntry *pos; |
495 | struct InfoMessage *im; | 398 | struct InfoMessage *im; |
@@ -508,7 +411,6 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, | |||
508 | memcmp (only, &pos->identity, | 411 | memcmp (only, &pos->identity, |
509 | sizeof (struct GNUNET_PeerIdentity)))) | 412 | sizeof (struct GNUNET_PeerIdentity)))) |
510 | { | 413 | { |
511 | change_host_trust (&pos->identity, trust_change); | ||
512 | hs = 0; | 414 | hs = 0; |
513 | im = (struct InfoMessage *) buf; | 415 | im = (struct InfoMessage *) buf; |
514 | if (pos->hello != NULL) | 416 | if (pos->hello != NULL) |
@@ -522,7 +424,7 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, | |||
522 | } | 424 | } |
523 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); | 425 | im->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_INFO); |
524 | im->header.size = htons (sizeof (struct InfoMessage) + hs); | 426 | im->header.size = htons (sizeof (struct InfoMessage) + hs); |
525 | im->trust = htonl (pos->trust); | 427 | im->reserved = htonl (0); |
526 | im->peer = pos->identity; | 428 | im->peer = pos->identity; |
527 | GNUNET_SERVER_transmit_context_append_message (tc, | 429 | GNUNET_SERVER_transmit_context_append_message (tc, |
528 | &im->header); | 430 | &im->header); |
@@ -542,58 +444,6 @@ send_to_each_host (const struct GNUNET_PeerIdentity *only, | |||
542 | 444 | ||
543 | 445 | ||
544 | /** | 446 | /** |
545 | * Write host-trust information to a file - flush the buffer entry! | ||
546 | * Assumes synchronized access. | ||
547 | */ | ||
548 | static void | ||
549 | flush_trust (struct HostEntry *host) | ||
550 | { | ||
551 | char *fn; | ||
552 | uint32_t trust; | ||
553 | |||
554 | if (host->trust == host->disk_trust) | ||
555 | return; /* unchanged */ | ||
556 | fn = get_trust_filename (&host->identity); | ||
557 | if (host->trust == 0) | ||
558 | { | ||
559 | if ((0 != UNLINK (fn)) && (errno != ENOENT)) | ||
560 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING | | ||
561 | GNUNET_ERROR_TYPE_BULK, "unlink", fn); | ||
562 | } | ||
563 | else | ||
564 | { | ||
565 | trust = htonl (host->trust); | ||
566 | if (sizeof(uint32_t) == GNUNET_DISK_fn_write (fn, &trust, | ||
567 | sizeof(uint32_t), | ||
568 | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE | ||
569 | | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_OTHER_READ)) | ||
570 | host->disk_trust = host->trust; | ||
571 | } | ||
572 | GNUNET_free (fn); | ||
573 | } | ||
574 | |||
575 | /** | ||
576 | * Call this method periodically to scan data/hosts for new hosts. | ||
577 | */ | ||
578 | static void | ||
579 | cron_flush_trust (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
580 | { | ||
581 | struct HostEntry *pos; | ||
582 | |||
583 | pos = hosts; | ||
584 | while (pos != NULL) | ||
585 | { | ||
586 | flush_trust (pos); | ||
587 | pos = pos->next; | ||
588 | } | ||
589 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
590 | return; | ||
591 | GNUNET_SCHEDULER_add_delayed (tc->sched, | ||
592 | TRUST_FLUSH_FREQ, &cron_flush_trust, NULL); | ||
593 | } | ||
594 | |||
595 | |||
596 | /** | ||
597 | * @brief delete expired HELLO entries in data/hosts/ | 447 | * @brief delete expired HELLO entries in data/hosts/ |
598 | */ | 448 | */ |
599 | static int | 449 | static int |
@@ -711,7 +561,7 @@ handle_get (void *cls, | |||
711 | "GET", | 561 | "GET", |
712 | GNUNET_i2s (&lpm->peer)); | 562 | GNUNET_i2s (&lpm->peer)); |
713 | #endif | 563 | #endif |
714 | send_to_each_host (&lpm->peer, ntohl (lpm->trust_change), client); | 564 | send_to_each_host (&lpm->peer, client); |
715 | } | 565 | } |
716 | 566 | ||
717 | 567 | ||
@@ -727,15 +577,12 @@ handle_get_all (void *cls, | |||
727 | struct GNUNET_SERVER_Client *client, | 577 | struct GNUNET_SERVER_Client *client, |
728 | const struct GNUNET_MessageHeader *message) | 578 | const struct GNUNET_MessageHeader *message) |
729 | { | 579 | { |
730 | const struct ListAllPeersMessage *lpm; | ||
731 | |||
732 | lpm = (const struct ListAllPeersMessage *) message; | ||
733 | #if DEBUG_PEERINFO | 580 | #if DEBUG_PEERINFO |
734 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 581 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
735 | "`%s' message received\n", | 582 | "`%s' message received\n", |
736 | "GET_ALL"); | 583 | "GET_ALL"); |
737 | #endif | 584 | #endif |
738 | send_to_each_host (NULL, ntohl (lpm->trust_change), client); | 585 | send_to_each_host (NULL, client); |
739 | } | 586 | } |
740 | 587 | ||
741 | 588 | ||
@@ -814,7 +661,7 @@ run (void *cls, | |||
814 | {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, | 661 | {&handle_get, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET, |
815 | sizeof (struct ListPeerMessage)}, | 662 | sizeof (struct ListPeerMessage)}, |
816 | {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, | 663 | {&handle_get_all, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL, |
817 | sizeof (struct ListAllPeersMessage)}, | 664 | sizeof (struct GNUNET_MessageHeader)}, |
818 | {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, | 665 | {&handle_notify, NULL, GNUNET_MESSAGE_TYPE_PEERINFO_NOTIFY, |
819 | sizeof (struct GNUNET_MessageHeader)}, | 666 | sizeof (struct GNUNET_MessageHeader)}, |
820 | {NULL, NULL, 0, 0} | 667 | {NULL, NULL, 0, 0} |
@@ -826,20 +673,11 @@ run (void *cls, | |||
826 | "peerinfo", | 673 | "peerinfo", |
827 | "HOSTS", | 674 | "HOSTS", |
828 | &networkIdDirectory)); | 675 | &networkIdDirectory)); |
829 | GNUNET_assert (GNUNET_OK == | ||
830 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
831 | "peerinfo", | ||
832 | "TRUST", | ||
833 | &trustDirectory)); | ||
834 | GNUNET_DISK_directory_create (networkIdDirectory); | 676 | GNUNET_DISK_directory_create (networkIdDirectory); |
835 | GNUNET_DISK_directory_create (trustDirectory); | ||
836 | GNUNET_SCHEDULER_add_with_priority (sched, | 677 | GNUNET_SCHEDULER_add_with_priority (sched, |
837 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 678 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
838 | &cron_scan_directory_data_hosts, NULL); | 679 | &cron_scan_directory_data_hosts, NULL); |
839 | GNUNET_SCHEDULER_add_with_priority (sched, | 680 | GNUNET_SCHEDULER_add_with_priority (sched, |
840 | GNUNET_SCHEDULER_PRIORITY_HIGH, | ||
841 | &cron_flush_trust, NULL); | ||
842 | GNUNET_SCHEDULER_add_with_priority (sched, | ||
843 | GNUNET_SCHEDULER_PRIORITY_IDLE, | 681 | GNUNET_SCHEDULER_PRIORITY_IDLE, |
844 | &cron_clean_data_hosts, NULL); | 682 | &cron_clean_data_hosts, NULL); |
845 | GNUNET_SCHEDULER_add_delayed (sched, | 683 | GNUNET_SCHEDULER_add_delayed (sched, |
@@ -868,7 +706,6 @@ main (int argc, char *const *argv) | |||
868 | GNUNET_SERVICE_OPTION_NONE, | 706 | GNUNET_SERVICE_OPTION_NONE, |
869 | &run, NULL)) ? 0 : 1; | 707 | &run, NULL)) ? 0 : 1; |
870 | GNUNET_free_non_null (networkIdDirectory); | 708 | GNUNET_free_non_null (networkIdDirectory); |
871 | GNUNET_free_non_null (trustDirectory); | ||
872 | return ret; | 709 | return ret; |
873 | } | 710 | } |
874 | 711 | ||
diff --git a/src/peerinfo/peerinfo.h b/src/peerinfo/peerinfo.h index d8d645b13..87860097a 100644 --- a/src/peerinfo/peerinfo.h +++ b/src/peerinfo/peerinfo.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2009, 2010 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -31,8 +31,7 @@ | |||
31 | 31 | ||
32 | /** | 32 | /** |
33 | * Message requesting a listing of all known peers, | 33 | * Message requesting a listing of all known peers, |
34 | * possibly modified by the specified trust value | 34 | * possibly restricted to the specified peer identity. |
35 | * and restricted to the specified peer identity. | ||
36 | */ | 35 | */ |
37 | struct ListPeerMessage | 36 | struct ListPeerMessage |
38 | { | 37 | { |
@@ -43,10 +42,9 @@ struct ListPeerMessage | |||
43 | struct GNUNET_MessageHeader header; | 42 | struct GNUNET_MessageHeader header; |
44 | 43 | ||
45 | /** | 44 | /** |
46 | * How much to change the trust in each returned peer, | 45 | * Always zero. |
47 | * in network byte order. | ||
48 | */ | 46 | */ |
49 | int32_t trust_change GNUNET_PACKED; | 47 | uint32_t reserved GNUNET_PACKED; |
50 | 48 | ||
51 | /** | 49 | /** |
52 | * Restrict to peers with this identity (optional | 50 | * Restrict to peers with this identity (optional |
@@ -58,28 +56,6 @@ struct ListPeerMessage | |||
58 | 56 | ||
59 | 57 | ||
60 | /** | 58 | /** |
61 | * Message requesting a listing of all known peers, | ||
62 | * possibly modified by the specified trust value | ||
63 | * and restricted to the specified peer identity. | ||
64 | */ | ||
65 | struct ListAllPeersMessage | ||
66 | { | ||
67 | |||
68 | /** | ||
69 | * Type will be GNUNET_MESSAGE_TYPE_PEERINFO_GET | ||
70 | */ | ||
71 | struct GNUNET_MessageHeader header; | ||
72 | |||
73 | /** | ||
74 | * How much to change the trust in each returned peer, | ||
75 | * in network byte order. | ||
76 | */ | ||
77 | int32_t trust_change GNUNET_PACKED; | ||
78 | |||
79 | }; | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Message used to inform the client about | 59 | * Message used to inform the client about |
84 | * a particular peer; this message is optionally followed | 60 | * a particular peer; this message is optionally followed |
85 | * by a HELLO message for the respective peer (if available). | 61 | * by a HELLO message for the respective peer (if available). |
@@ -95,10 +71,9 @@ struct InfoMessage | |||
95 | struct GNUNET_MessageHeader header; | 71 | struct GNUNET_MessageHeader header; |
96 | 72 | ||
97 | /** | 73 | /** |
98 | * Amount of trust we now have in the peer, | 74 | * Always zero. |
99 | * in network byte order. | ||
100 | */ | 75 | */ |
101 | uint32_t trust GNUNET_PACKED; | 76 | uint32_t reserved GNUNET_PACKED; |
102 | 77 | ||
103 | /** | 78 | /** |
104 | * About which peer are we talking here? | 79 | * About which peer are we talking here? |
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index a1eeeb220..1f382f096 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2001, 2002, 2004, 2005, 2007, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2001, 2002, 2004, 2005, 2007, 2009, 2010 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -397,7 +397,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
397 | GNUNET_SCHEDULER_cancel (ic->h->sched, | 397 | GNUNET_SCHEDULER_cancel (ic->h->sched, |
398 | ic->timeout_task); | 398 | ic->timeout_task); |
399 | if (ic->callback != NULL) | 399 | if (ic->callback != NULL) |
400 | ic->callback (ic->callback_cls, NULL, NULL, 1); | 400 | ic->callback (ic->callback_cls, NULL, NULL); |
401 | GNUNET_free (ic); | 401 | GNUNET_free (ic); |
402 | return; | 402 | return; |
403 | } | 403 | } |
@@ -413,7 +413,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
413 | GNUNET_SCHEDULER_cancel (ic->h->sched, | 413 | GNUNET_SCHEDULER_cancel (ic->h->sched, |
414 | ic->timeout_task); | 414 | ic->timeout_task); |
415 | if (ic->callback != NULL) | 415 | if (ic->callback != NULL) |
416 | ic->callback (ic->callback_cls, NULL, NULL, 0); | 416 | ic->callback (ic->callback_cls, NULL, NULL); |
417 | GNUNET_free (ic); | 417 | GNUNET_free (ic); |
418 | return; | 418 | return; |
419 | } | 419 | } |
@@ -428,7 +428,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
428 | GNUNET_SCHEDULER_cancel (ic->h->sched, | 428 | GNUNET_SCHEDULER_cancel (ic->h->sched, |
429 | ic->timeout_task); | 429 | ic->timeout_task); |
430 | if (ic->callback != NULL) | 430 | if (ic->callback != NULL) |
431 | ic->callback (ic->callback_cls, NULL, NULL, 2); | 431 | ic->callback (ic->callback_cls, NULL, NULL); |
432 | GNUNET_free (ic); | 432 | GNUNET_free (ic); |
433 | return; | 433 | return; |
434 | } | 434 | } |
@@ -446,7 +446,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
446 | GNUNET_SCHEDULER_cancel (ic->h->sched, | 446 | GNUNET_SCHEDULER_cancel (ic->h->sched, |
447 | ic->timeout_task); | 447 | ic->timeout_task); |
448 | if (ic->callback != NULL) | 448 | if (ic->callback != NULL) |
449 | ic->callback (ic->callback_cls, NULL, NULL, 2); | 449 | ic->callback (ic->callback_cls, NULL, NULL); |
450 | GNUNET_free (ic); | 450 | GNUNET_free (ic); |
451 | return; | 451 | return; |
452 | } | 452 | } |
@@ -461,7 +461,7 @@ peerinfo_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
461 | #endif | 461 | #endif |
462 | ic->h->in_receive = GNUNET_YES; | 462 | ic->h->in_receive = GNUNET_YES; |
463 | if (ic->callback != NULL) | 463 | if (ic->callback != NULL) |
464 | ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust)); | 464 | ic->callback (ic->callback_cls, &im->peer, hello); |
465 | GNUNET_CLIENT_receive (ic->h->client, | 465 | GNUNET_CLIENT_receive (ic->h->client, |
466 | &peerinfo_handler, | 466 | &peerinfo_handler, |
467 | ic, | 467 | ic, |
@@ -497,7 +497,7 @@ iterator_start_receive (void *cls, | |||
497 | reconnect (ic->h); | 497 | reconnect (ic->h); |
498 | trigger_transmit (ic->h); | 498 | trigger_transmit (ic->h); |
499 | if (ic->callback != NULL) | 499 | if (ic->callback != NULL) |
500 | ic->callback (ic->callback_cls, NULL, NULL, 1); | 500 | ic->callback (ic->callback_cls, NULL, NULL); |
501 | GNUNET_free (ic); | 501 | GNUNET_free (ic); |
502 | return; | 502 | return; |
503 | } | 503 | } |
@@ -536,7 +536,7 @@ signal_timeout (void *cls, | |||
536 | GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, | 536 | GNUNET_CONTAINER_DLL_remove (ic->h->tq_head, |
537 | ic->h->tq_tail, | 537 | ic->h->tq_tail, |
538 | ic->tqe); | 538 | ic->tqe); |
539 | ic->callback (ic->callback_cls, NULL, NULL, 1); | 539 | ic->callback (ic->callback_cls, NULL, NULL); |
540 | ic->callback = NULL; | 540 | ic->callback = NULL; |
541 | if (ic->in_receive) | 541 | if (ic->in_receive) |
542 | return; | 542 | return; |
@@ -551,16 +551,11 @@ signal_timeout (void *cls, | |||
551 | * host and then finally once with a NULL pointer. After that final | 551 | * host and then finally once with a NULL pointer. After that final |
552 | * invocation, the iterator context must no longer be used. | 552 | * invocation, the iterator context must no longer be used. |
553 | * | 553 | * |
554 | * Note that the last call can be triggered by timeout or by simply | 554 | * Instead of calling this function with 'peer == NULL' it is often |
555 | * being done; however, the trust argument will be set to zero if we | 555 | * better to use 'GNUNET_PEERINFO_notify'. |
556 | * are done, 1 if we timed out and 2 for fatal error. | ||
557 | * | ||
558 | * Instead of calling this function with 'peer == NULL' and 'trust == | ||
559 | * 0', it is often better to use 'GNUNET_PEERINFO_notify'. | ||
560 | * | 556 | * |
561 | * @param h handle to the peerinfo service | 557 | * @param h handle to the peerinfo service |
562 | * @param peer restrict iteration to this peer only (can be NULL) | 558 | * @param peer restrict iteration to this peer only (can be NULL) |
563 | * @param trust_delta how much to change the trust in all matching peers | ||
564 | * @param timeout how long to wait until timing out | 559 | * @param timeout how long to wait until timing out |
565 | * @param callback the method to call for each peer | 560 | * @param callback the method to call for each peer |
566 | * @param callback_cls closure for callback | 561 | * @param callback_cls closure for callback |
@@ -570,12 +565,11 @@ signal_timeout (void *cls, | |||
570 | struct GNUNET_PEERINFO_IteratorContext * | 565 | struct GNUNET_PEERINFO_IteratorContext * |
571 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | 566 | GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, |
572 | const struct GNUNET_PeerIdentity *peer, | 567 | const struct GNUNET_PeerIdentity *peer, |
573 | int trust_delta, | ||
574 | struct GNUNET_TIME_Relative timeout, | 568 | struct GNUNET_TIME_Relative timeout, |
575 | GNUNET_PEERINFO_Processor callback, | 569 | GNUNET_PEERINFO_Processor callback, |
576 | void *callback_cls) | 570 | void *callback_cls) |
577 | { | 571 | { |
578 | struct ListAllPeersMessage *lapm; | 572 | struct GNUNET_MessageHeader *lapm; |
579 | struct ListPeerMessage *lpm; | 573 | struct ListPeerMessage *lpm; |
580 | struct GNUNET_PEERINFO_IteratorContext *ic; | 574 | struct GNUNET_PEERINFO_IteratorContext *ic; |
581 | struct TransmissionQueueEntry *tqe; | 575 | struct TransmissionQueueEntry *tqe; |
@@ -587,12 +581,11 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
587 | "Requesting list of peers from PEERINFO service\n"); | 581 | "Requesting list of peers from PEERINFO service\n"); |
588 | #endif | 582 | #endif |
589 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + | 583 | tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + |
590 | sizeof (struct ListAllPeersMessage)); | 584 | sizeof (struct GNUNET_MessageHeader)); |
591 | tqe->size = sizeof (struct ListAllPeersMessage); | 585 | tqe->size = sizeof (struct GNUNET_MessageHeader); |
592 | lapm = (struct ListAllPeersMessage *) &tqe[1]; | 586 | lapm = (struct GNUNET_MessageHeader *) &tqe[1]; |
593 | lapm->header.size = htons (sizeof (struct ListAllPeersMessage)); | 587 | lapm->size = htons (sizeof (struct GNUNET_MessageHeader)); |
594 | lapm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); | 588 | lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL); |
595 | lapm->trust_change = htonl (trust_delta); | ||
596 | } | 589 | } |
597 | else | 590 | else |
598 | { | 591 | { |
@@ -607,7 +600,6 @@ GNUNET_PEERINFO_iterate (struct GNUNET_PEERINFO_Handle *h, | |||
607 | lpm = (struct ListPeerMessage *) &tqe[1]; | 600 | lpm = (struct ListPeerMessage *) &tqe[1]; |
608 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); | 601 | lpm->header.size = htons (sizeof (struct ListPeerMessage)); |
609 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); | 602 | lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET); |
610 | lpm->trust_change = htonl (trust_delta); | ||
611 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 603 | memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
612 | } | 604 | } |
613 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); | 605 | ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext)); |
diff --git a/src/peerinfo/peerinfo_api_notify.c b/src/peerinfo/peerinfo_api_notify.c index 04e8baea0..c7a9c6145 100644 --- a/src/peerinfo/peerinfo_api_notify.c +++ b/src/peerinfo/peerinfo_api_notify.c | |||
@@ -142,7 +142,7 @@ process_notification (void *cls, | |||
142 | "Received information about peer `%s' from peerinfo database\n", | 142 | "Received information about peer `%s' from peerinfo database\n", |
143 | GNUNET_i2s (&im->peer)); | 143 | GNUNET_i2s (&im->peer)); |
144 | #endif | 144 | #endif |
145 | nc->callback (nc->callback_cls, &im->peer, hello, ntohl (im->trust)); | 145 | nc->callback (nc->callback_cls, &im->peer, hello); |
146 | receive_notifications (nc); | 146 | receive_notifications (nc); |
147 | } | 147 | } |
148 | 148 | ||
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index dd931f4bc..47304d549 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -102,7 +102,7 @@ add_peer () | |||
102 | static void | 102 | static void |
103 | process (void *cls, | 103 | process (void *cls, |
104 | const struct GNUNET_PeerIdentity *peer, | 104 | const struct GNUNET_PeerIdentity *peer, |
105 | const struct GNUNET_HELLO_Message *hello, uint32_t trust) | 105 | const struct GNUNET_HELLO_Message *hello) |
106 | { | 106 | { |
107 | int *ok = cls; | 107 | int *ok = cls; |
108 | unsigned int agc; | 108 | unsigned int agc; |
@@ -118,7 +118,6 @@ process (void *cls, | |||
118 | add_peer (); | 118 | add_peer (); |
119 | ic = GNUNET_PEERINFO_iterate (h, | 119 | ic = GNUNET_PEERINFO_iterate (h, |
120 | NULL, | 120 | NULL, |
121 | 0, | ||
122 | GNUNET_TIME_relative_multiply | 121 | GNUNET_TIME_relative_multiply |
123 | (GNUNET_TIME_UNIT_SECONDS, 15), | 122 | (GNUNET_TIME_UNIT_SECONDS, 15), |
124 | &process, cls); | 123 | &process, cls); |
@@ -126,7 +125,6 @@ process (void *cls, | |||
126 | } | 125 | } |
127 | GNUNET_assert (peer == NULL); | 126 | GNUNET_assert (peer == NULL); |
128 | GNUNET_assert (2 == *ok); | 127 | GNUNET_assert (2 == *ok); |
129 | GNUNET_assert (trust == 0); | ||
130 | GNUNET_PEERINFO_disconnect (h); | 128 | GNUNET_PEERINFO_disconnect (h); |
131 | h = NULL; | 129 | h = NULL; |
132 | *ok = 0; | 130 | *ok = 0; |
@@ -156,7 +154,6 @@ run (void *cls, | |||
156 | add_peer (); | 154 | add_peer (); |
157 | ic = GNUNET_PEERINFO_iterate (h, | 155 | ic = GNUNET_PEERINFO_iterate (h, |
158 | NULL, | 156 | NULL, |
159 | 0, | ||
160 | GNUNET_TIME_relative_multiply | 157 | GNUNET_TIME_relative_multiply |
161 | (GNUNET_TIME_UNIT_SECONDS, 15), | 158 | (GNUNET_TIME_UNIT_SECONDS, 15), |
162 | &process, cls); | 159 | &process, cls); |