diff options
Diffstat (limited to 'src/peerinfo/test_peerinfo_api.c')
-rw-r--r-- | src/peerinfo/test_peerinfo_api.c | 96 |
1 files changed, 46 insertions, 50 deletions
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c index 460a3764d..e740f1fc9 100644 --- a/src/peerinfo/test_peerinfo_api.c +++ b/src/peerinfo/test_peerinfo_api.c | |||
@@ -53,11 +53,11 @@ check_it (void *cls, | |||
53 | unsigned int *agc = cls; | 53 | unsigned int *agc = cls; |
54 | 54 | ||
55 | if (addrlen > 0) | 55 | if (addrlen > 0) |
56 | { | 56 | { |
57 | GNUNET_assert (0 == strcmp ("peerinfotest", tname)); | 57 | GNUNET_assert (0 == strcmp ("peerinfotest", tname)); |
58 | GNUNET_assert (0 == strncmp ("Address", addr, addrlen)); | 58 | GNUNET_assert (0 == strncmp ("Address", addr, addrlen)); |
59 | (*agc) -= (1 << (addrlen - 1)); | 59 | (*agc) -= (1 << (addrlen - 1)); |
60 | } | 60 | } |
61 | return GNUNET_OK; | 61 | return GNUNET_OK; |
62 | } | 62 | } |
63 | 63 | ||
@@ -100,67 +100,63 @@ add_peer () | |||
100 | static void | 100 | static void |
101 | process (void *cls, | 101 | process (void *cls, |
102 | const struct GNUNET_PeerIdentity *peer, | 102 | const struct GNUNET_PeerIdentity *peer, |
103 | const struct GNUNET_HELLO_Message *hello, | 103 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
104 | const char * err_msg) | ||
105 | { | 104 | { |
106 | int *ok = cls; | 105 | int *ok = cls; |
107 | unsigned int agc; | 106 | unsigned int agc; |
108 | 107 | ||
109 | if (err_msg != NULL) | 108 | if (err_msg != NULL) |
110 | { | 109 | { |
111 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 110 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
112 | _("Error in communication with PEERINFO service\n")); | 111 | _("Error in communication with PEERINFO service\n")); |
113 | } | 112 | } |
114 | 113 | ||
115 | if (peer == NULL) | 114 | if (peer == NULL) |
115 | { | ||
116 | ic = NULL; | ||
117 | if ((3 == *ok) && (retries < 50)) | ||
116 | { | 118 | { |
117 | ic = NULL; | 119 | /* try again */ |
118 | if ( (3 == *ok) && | 120 | retries++; |
119 | (retries < 50) ) | 121 | add_peer (); |
120 | { | 122 | ic = GNUNET_PEERINFO_iterate (h, |
121 | /* try again */ | 123 | NULL, |
122 | retries++; | 124 | GNUNET_TIME_relative_multiply |
123 | add_peer (); | 125 | (GNUNET_TIME_UNIT_SECONDS, 15), |
124 | ic = GNUNET_PEERINFO_iterate (h, | 126 | &process, cls); |
125 | NULL, | ||
126 | GNUNET_TIME_relative_multiply | ||
127 | (GNUNET_TIME_UNIT_SECONDS, 15), | ||
128 | &process, cls); | ||
129 | return; | ||
130 | } | ||
131 | GNUNET_assert (peer == NULL); | ||
132 | GNUNET_assert (2 == *ok); | ||
133 | GNUNET_PEERINFO_disconnect (h); | ||
134 | h = NULL; | ||
135 | *ok = 0; | ||
136 | return; | 127 | return; |
137 | } | 128 | } |
129 | GNUNET_assert (peer == NULL); | ||
130 | GNUNET_assert (2 == *ok); | ||
131 | GNUNET_PEERINFO_disconnect (h); | ||
132 | h = NULL; | ||
133 | *ok = 0; | ||
134 | return; | ||
135 | } | ||
138 | if (hello != NULL) | 136 | if (hello != NULL) |
139 | { | 137 | { |
140 | GNUNET_assert (3 == *ok); | 138 | GNUNET_assert (3 == *ok); |
141 | agc = 3; | 139 | agc = 3; |
142 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); | 140 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, &agc); |
143 | GNUNET_assert (agc == 0); | 141 | GNUNET_assert (agc == 0); |
144 | *ok = 2; | 142 | *ok = 2; |
145 | } | 143 | } |
146 | } | 144 | } |
147 | 145 | ||
148 | 146 | ||
149 | static void | 147 | static void |
150 | run (void *cls, | 148 | run (void *cls, |
151 | char *const *args, | 149 | char *const *args, |
152 | const char *cfgfile, | 150 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) |
153 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
154 | { | 151 | { |
155 | cfg = c; | 152 | cfg = c; |
156 | h = GNUNET_PEERINFO_connect (cfg); | 153 | h = GNUNET_PEERINFO_connect (cfg); |
157 | GNUNET_assert (h != NULL); | 154 | GNUNET_assert (h != NULL); |
158 | add_peer (); | 155 | add_peer (); |
159 | ic = GNUNET_PEERINFO_iterate (h, | 156 | ic = GNUNET_PEERINFO_iterate (h, |
160 | NULL, | 157 | NULL, |
161 | GNUNET_TIME_relative_multiply | 158 | GNUNET_TIME_relative_multiply |
162 | (GNUNET_TIME_UNIT_SECONDS, 15), | 159 | (GNUNET_TIME_UNIT_SECONDS, 15), &process, cls); |
163 | &process, cls); | ||
164 | } | 160 | } |
165 | 161 | ||
166 | 162 | ||
@@ -169,6 +165,7 @@ check () | |||
169 | { | 165 | { |
170 | int ok = 3; | 166 | int ok = 3; |
171 | struct GNUNET_OS_Process *proc; | 167 | struct GNUNET_OS_Process *proc; |
168 | |||
172 | char *const argv[] = { "test-peerinfo-api", | 169 | char *const argv[] = { "test-peerinfo-api", |
173 | "-c", | 170 | "-c", |
174 | "test_peerinfo_api_data.conf", | 171 | "test_peerinfo_api_data.conf", |
@@ -181,20 +178,19 @@ check () | |||
181 | GNUNET_GETOPT_OPTION_END | 178 | GNUNET_GETOPT_OPTION_END |
182 | }; | 179 | }; |
183 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", | 180 | proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-peerinfo", |
184 | "gnunet-service-peerinfo", | 181 | "gnunet-service-peerinfo", |
185 | #if DEBUG_PEERINFO | 182 | #if DEBUG_PEERINFO |
186 | "-L", "DEBUG", | 183 | "-L", "DEBUG", |
187 | #endif | 184 | #endif |
188 | "-c", "test_peerinfo_api_data.conf", NULL); | 185 | "-c", "test_peerinfo_api_data.conf", NULL); |
189 | GNUNET_assert (NULL != proc); | 186 | GNUNET_assert (NULL != proc); |
190 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, | 187 | GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, |
191 | argv, "test-peerinfo-api", "nohelp", | 188 | argv, "test-peerinfo-api", "nohelp", options, &run, &ok); |
192 | options, &run, &ok); | ||
193 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) | 189 | if (0 != GNUNET_OS_process_kill (proc, SIGTERM)) |
194 | { | 190 | { |
195 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | 191 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); |
196 | ok = 1; | 192 | ok = 1; |
197 | } | 193 | } |
198 | GNUNET_OS_process_wait (proc); | 194 | GNUNET_OS_process_wait (proc); |
199 | GNUNET_OS_process_close (proc); | 195 | GNUNET_OS_process_close (proc); |
200 | proc = NULL; | 196 | proc = NULL; |