diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-01-18 09:45:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-01-18 09:45:40 +0000 |
commit | 260b2ebb0662c22d14f2482700c2211acb22b0d8 (patch) | |
tree | 94d4e3038d42cd9e8a0967407087c06ab6795811 /src/peerinfo | |
parent | 51ff626cb5d373cb7c066ad182af230f71c3ae01 (diff) | |
download | gnunet-260b2ebb0662c22d14f2482700c2211acb22b0d8.tar.gz gnunet-260b2ebb0662c22d14f2482700c2211acb22b0d8.zip |
peerinfo fixes
Diffstat (limited to 'src/peerinfo')
-rw-r--r-- | src/peerinfo/gnunet-service-peerinfo.c | 1 | ||||
-rw-r--r-- | src/peerinfo/peerinfo_api.c | 12 | ||||
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 99 |
3 files changed, 81 insertions, 31 deletions
diff --git a/src/peerinfo/gnunet-service-peerinfo.c b/src/peerinfo/gnunet-service-peerinfo.c index 30723be0b..f0d8b0606 100644 --- a/src/peerinfo/gnunet-service-peerinfo.c +++ b/src/peerinfo/gnunet-service-peerinfo.c | |||
@@ -563,6 +563,7 @@ bind_address (const struct GNUNET_PeerIdentity *peer, | |||
563 | host->hello = mrg; | 563 | host->hello = mrg; |
564 | } | 564 | } |
565 | fn = get_host_filename (peer); | 565 | fn = get_host_filename (peer); |
566 | GNUNET_DISK_directory_create_for_file (fn); | ||
566 | GNUNET_DISK_fn_write (fn, | 567 | GNUNET_DISK_fn_write (fn, |
567 | host->hello, | 568 | host->hello, |
568 | GNUNET_HELLO_size (host->hello), | 569 | GNUNET_HELLO_size (host->hello), |
diff --git a/src/peerinfo/peerinfo_api.c b/src/peerinfo/peerinfo_api.c index f3479ab7b..0f95a421a 100644 --- a/src/peerinfo/peerinfo_api.c +++ b/src/peerinfo/peerinfo_api.c | |||
@@ -103,6 +103,12 @@ GNUNET_PEERINFO_add_peer (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
103 | return; | 103 | return; |
104 | } | 104 | } |
105 | hs = GNUNET_HELLO_size (hello); | 105 | hs = GNUNET_HELLO_size (hello); |
106 | #if DEBUG_PEERINFO | ||
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
108 | "Size of `%s' is %u bytes\n", | ||
109 | "HELLO", | ||
110 | (unsigned int) GNUNET_HELLO_size (hello)); | ||
111 | #endif | ||
106 | pam = GNUNET_malloc (sizeof (struct PeerAddMessage) + hs); | 112 | pam = GNUNET_malloc (sizeof (struct PeerAddMessage) + hs); |
107 | pam->header.size = htons (hs + sizeof (struct PeerAddMessage)); | 113 | pam->header.size = htons (hs + sizeof (struct PeerAddMessage)); |
108 | pam->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_ADD); | 114 | pam->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_ADD); |
@@ -213,6 +219,12 @@ info_handler (void *cls, const struct GNUNET_MessageHeader *msg) | |||
213 | "Received information about peer `%s' from peerinfo database\n", | 219 | "Received information about peer `%s' from peerinfo database\n", |
214 | GNUNET_i2s (&im->peer)); | 220 | GNUNET_i2s (&im->peer)); |
215 | #endif | 221 | #endif |
222 | #if DEBUG_PEERINFO | ||
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
224 | "Size of `%s' is %u bytes\n", | ||
225 | "HELLO", | ||
226 | (unsigned int) GNUNET_HELLO_size (hello)); | ||
227 | #endif | ||
216 | ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust)); | 228 | ic->callback (ic->callback_cls, &im->peer, hello, ntohl (im->trust)); |
217 | GNUNET_CLIENT_receive (ic->client, | 229 | GNUNET_CLIENT_receive (ic->client, |
218 | &info_handler, | 230 | &info_handler, |
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 4cbbb7bf6..0b5230eb6 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -34,7 +34,13 @@ | |||
34 | #include "gnunet_peerinfo_service.h" | 34 | #include "gnunet_peerinfo_service.h" |
35 | #include "gnunet_program_lib.h" | 35 | #include "gnunet_program_lib.h" |
36 | #include "gnunet_time_lib.h" | 36 | #include "gnunet_time_lib.h" |
37 | #include "peerinfo.h" | ||
37 | 38 | ||
39 | static struct GNUNET_SCHEDULER_Handle *sched; | ||
40 | |||
41 | static const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
42 | |||
43 | static unsigned int retries; | ||
38 | 44 | ||
39 | static int | 45 | static int |
40 | check_it (void *cls, | 46 | check_it (void *cls, |
@@ -54,6 +60,41 @@ check_it (void *cls, | |||
54 | } | 60 | } |
55 | 61 | ||
56 | 62 | ||
63 | static size_t | ||
64 | address_generator (void *cls, size_t max, void *buf) | ||
65 | { | ||
66 | size_t *agc = cls; | ||
67 | size_t ret; | ||
68 | |||
69 | if (0 == *agc) | ||
70 | return 0; | ||
71 | ret = GNUNET_HELLO_add_address ("peerinfotest", | ||
72 | GNUNET_TIME_relative_to_absolute | ||
73 | (GNUNET_TIME_UNIT_HOURS), "Address", *agc, | ||
74 | buf, max); | ||
75 | (*agc)--; | ||
76 | return ret; | ||
77 | } | ||
78 | |||
79 | |||
80 | static void | ||
81 | add_peer () | ||
82 | { | ||
83 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | ||
84 | struct GNUNET_PeerIdentity pid; | ||
85 | struct GNUNET_HELLO_Message *h2; | ||
86 | size_t agc; | ||
87 | |||
88 | agc = 2; | ||
89 | memset (&pkey, 32, sizeof (pkey)); | ||
90 | GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); | ||
91 | h2 = GNUNET_HELLO_create (&pkey, &address_generator, &agc); | ||
92 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, h2); | ||
93 | GNUNET_free (h2); | ||
94 | |||
95 | } | ||
96 | |||
97 | |||
57 | static void | 98 | static void |
58 | process (void *cls, | 99 | process (void *cls, |
59 | const struct GNUNET_PeerIdentity *peer, | 100 | const struct GNUNET_PeerIdentity *peer, |
@@ -64,6 +105,21 @@ process (void *cls, | |||
64 | 105 | ||
65 | if (peer == NULL) | 106 | if (peer == NULL) |
66 | { | 107 | { |
108 | if ( (3 == *ok) && | ||
109 | (retries < 5) ) | ||
110 | { | ||
111 | /* try again */ | ||
112 | retries++; | ||
113 | add_peer (); | ||
114 | GNUNET_PEERINFO_iterate (cfg, | ||
115 | sched, | ||
116 | NULL, | ||
117 | 0, | ||
118 | GNUNET_TIME_relative_multiply | ||
119 | (GNUNET_TIME_UNIT_SECONDS, 15), | ||
120 | &process, cls); | ||
121 | return; | ||
122 | } | ||
67 | GNUNET_assert (peer == NULL); | 123 | GNUNET_assert (peer == NULL); |
68 | GNUNET_assert (2 == *ok); | 124 | GNUNET_assert (2 == *ok); |
69 | GNUNET_assert (trust == 0); | 125 | GNUNET_assert (trust == 0); |
@@ -82,48 +138,22 @@ process (void *cls, | |||
82 | } | 138 | } |
83 | 139 | ||
84 | 140 | ||
85 | static size_t | ||
86 | address_generator (void *cls, size_t max, void *buf) | ||
87 | { | ||
88 | size_t *agc = cls; | ||
89 | size_t ret; | ||
90 | |||
91 | if (0 == *agc) | ||
92 | return 0; | ||
93 | ret = GNUNET_HELLO_add_address ("peerinfotest", | ||
94 | GNUNET_TIME_relative_to_absolute | ||
95 | (GNUNET_TIME_UNIT_HOURS), "Address", *agc, | ||
96 | buf, max); | ||
97 | (*agc)--; | ||
98 | return ret; | ||
99 | } | ||
100 | |||
101 | |||
102 | static void | 141 | static void |
103 | run (void *cls, | 142 | run (void *cls, |
104 | struct GNUNET_SCHEDULER_Handle *sched, | 143 | struct GNUNET_SCHEDULER_Handle *s, |
105 | char *const *args, | 144 | char *const *args, |
106 | const char *cfgfile, | 145 | const char *cfgfile, |
107 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 146 | const struct GNUNET_CONFIGURATION_Handle *c) |
108 | { | 147 | { |
109 | struct GNUNET_HELLO_Message *hello; | 148 | sched = s; |
110 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded pkey; | 149 | cfg = c; |
111 | size_t agc; | 150 | add_peer (); |
112 | struct GNUNET_PeerIdentity pid; | ||
113 | |||
114 | memset (&pkey, 32, sizeof (pkey)); | ||
115 | GNUNET_CRYPTO_hash (&pkey, sizeof (pkey), &pid.hashPubKey); | ||
116 | agc = 2; | ||
117 | hello = GNUNET_HELLO_create (&pkey, &address_generator, &agc); | ||
118 | GNUNET_assert (hello != NULL); | ||
119 | GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello); | ||
120 | GNUNET_PEERINFO_iterate (cfg, | 151 | GNUNET_PEERINFO_iterate (cfg, |
121 | sched, | 152 | sched, |
122 | NULL, | 153 | NULL, |
123 | 0, | 154 | 0, |
124 | GNUNET_TIME_relative_multiply | 155 | GNUNET_TIME_relative_multiply |
125 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); | 156 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); |
126 | GNUNET_free (hello); | ||
127 | } | 157 | } |
128 | 158 | ||
129 | 159 | ||
@@ -167,6 +197,13 @@ main (int argc, char *argv[]) | |||
167 | { | 197 | { |
168 | int ret = 0; | 198 | int ret = 0; |
169 | 199 | ||
200 | GNUNET_log_setup ("test_peerinfo_api", | ||
201 | #if DEBUG_PEERINFO | ||
202 | "DEBUG", | ||
203 | #else | ||
204 | "WARNING", | ||
205 | #endif | ||
206 | NULL); | ||
170 | ret = check (); | 207 | ret = check (); |
171 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo"); | 208 | GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-peerinfo"); |
172 | return ret; | 209 | return ret; |