diff options
author | xrs <xrs@mail36.net> | 2017-03-13 20:35:18 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2017-03-13 20:35:18 +0100 |
commit | 9f68c9e7d383061abbc81d1590abf25cde2305fe (patch) | |
tree | 971a0188e84878f43c2074def4ac3531c73acba6 /src/multicast/test_multicast_2peers.c | |
parent | 501c1f7794be6e8a2ea15200dbdadd4c066edb89 (diff) | |
parent | 8691934f57063bfa5032f4e34836ecbcb3d761e9 (diff) | |
download | gnunet-9f68c9e7d383061abbc81d1590abf25cde2305fe.tar.gz gnunet-9f68c9e7d383061abbc81d1590abf25cde2305fe.zip |
Merge branch 'master' of ssh://gnunet.org/gnunet
Conflicts:
src/multicast/test_multicast_2peers.c
Diffstat (limited to 'src/multicast/test_multicast_2peers.c')
-rw-r--r-- | src/multicast/test_multicast_2peers.c | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/src/multicast/test_multicast_2peers.c b/src/multicast/test_multicast_2peers.c index 9d1f42063..8ce4d585f 100644 --- a/src/multicast/test_multicast_2peers.c +++ b/src/multicast/test_multicast_2peers.c | |||
@@ -20,7 +20,7 @@ | |||
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file multicast/test_multicast_2peers.c | 22 | * @file multicast/test_multicast_2peers.c |
23 | * @brief Tests for the Multicast API with two peers doing the ping | 23 | * @brief Tests for the Multicast API with two peers doing the ping |
24 | * pong test. | 24 | * pong test. |
25 | * @author xrs | 25 | * @author xrs |
26 | */ | 26 | */ |
@@ -118,16 +118,17 @@ member_join_request (void *cls, | |||
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | int notify (void *cls, | 121 | static int |
122 | size_t *data_size, | 122 | notify (void *cls, |
123 | void *data) | 123 | size_t *data_size, |
124 | void *data) | ||
124 | { | 125 | { |
125 | 126 | ||
126 | char text[] = "ping"; | 127 | char text[] = "ping"; |
127 | *data_size = strlen(text)+1; | 128 | *data_size = strlen(text)+1; |
128 | GNUNET_memcpy(data, text, *data_size); | 129 | GNUNET_memcpy(data, text, *data_size); |
129 | 130 | ||
130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
131 | "Member sents message to origin: %s\n", text); | 132 | "Member sents message to origin: %s\n", text); |
132 | 133 | ||
133 | return GNUNET_YES; | 134 | return GNUNET_YES; |
@@ -142,26 +143,30 @@ member_join_decision (void *cls, | |||
142 | const struct GNUNET_PeerIdentity *relays, | 143 | const struct GNUNET_PeerIdentity *relays, |
143 | const struct GNUNET_MessageHeader *join_msg) | 144 | const struct GNUNET_MessageHeader *join_msg) |
144 | { | 145 | { |
145 | struct GNUNET_MULTICAST_MemberTransmitHandle *req; | 146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
146 | 147 | "Member received a decision from origin: %s\n", | |
147 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 148 | (GNUNET_YES == is_admitted) |
148 | "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); | 149 | ? "accepted" |
149 | 150 | : "rejected"); | |
151 | |||
150 | if (GNUNET_YES == is_admitted) | 152 | if (GNUNET_YES == is_admitted) |
151 | { | 153 | { |
154 | struct GNUNET_MULTICAST_MemberTransmitHandle *req; | ||
155 | |||
156 | // FIXME: move to MQ-style API! | ||
152 | req = GNUNET_MULTICAST_member_to_origin (member, | 157 | req = GNUNET_MULTICAST_member_to_origin (member, |
153 | 0, | 158 | 0, |
154 | notify, | 159 | ¬ify, |
155 | NULL); | 160 | NULL); |
156 | } | 161 | } |
157 | } | 162 | } |
158 | 163 | ||
159 | 164 | ||
160 | static void | 165 | static void |
161 | member_message (void *cls, | 166 | member_message (void *cls, |
162 | const struct GNUNET_MULTICAST_MessageHeader *msg) | 167 | const struct GNUNET_MULTICAST_MessageHeader *msg) |
163 | { | 168 | { |
164 | if (0 != strncmp ("pong", (char *)&msg[1], 4)) | 169 | if (0 != strncmp ("pong", (char *)&msg[1], 4)) |
165 | { | 170 | { |
166 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "member did not receive pong\n"); | 171 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "member did not receive pong\n"); |
167 | result = GNUNET_SYSERR; | 172 | result = GNUNET_SYSERR; |
@@ -187,19 +192,19 @@ origin_join_request (void *cls, | |||
187 | 192 | ||
188 | uint8_t data_size = ntohs (join_msg->size); | 193 | uint8_t data_size = ntohs (join_msg->size); |
189 | 194 | ||
190 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 195 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
191 | "origin got a join request...\n"); | 196 | "origin got a join request...\n"); |
192 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 197 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
193 | "origin receives: '%s'\n", (char *)&join_msg[1]); | 198 | "origin receives: '%s'\n", (char *)&join_msg[1]); |
194 | 199 | ||
195 | char data[] = "Come in!"; | 200 | const char data[] = "Come in!"; |
196 | data_size = strlen (data) + 1; | 201 | data_size = strlen (data) + 1; |
197 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); | 202 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); |
198 | join_resp->size = htons (sizeof (join_resp) + data_size); | 203 | join_resp->size = htons (sizeof (join_resp) + data_size); |
199 | join_resp->type = htons (123); | 204 | join_resp->type = htons (123); |
200 | GNUNET_memcpy (&join_resp[1], data, data_size); | 205 | GNUNET_memcpy (&join_resp[1], data, data_size); |
201 | 206 | ||
202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 207 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
203 | "origin sends: '%s'\n", data); | 208 | "origin sends: '%s'\n", data); |
204 | 209 | ||
205 | GNUNET_MULTICAST_join_decision (jh, | 210 | GNUNET_MULTICAST_join_decision (jh, |
@@ -207,23 +212,23 @@ origin_join_request (void *cls, | |||
207 | 0, | 212 | 0, |
208 | NULL, | 213 | NULL, |
209 | join_resp); | 214 | join_resp); |
210 | 215 | GNUNET_free (join_resp); | |
211 | result = GNUNET_OK; | 216 | result = GNUNET_OK; |
212 | } | 217 | } |
213 | 218 | ||
214 | 219 | ||
215 | int | 220 | int |
216 | origin_notify (void *cls, | 221 | origin_notify (void *cls, |
217 | size_t *data_size, | 222 | size_t *data_size, |
218 | void *data) | 223 | void *data) |
219 | { | 224 | { |
220 | char text[] = "pong"; | 225 | char text[] = "pong"; |
221 | *data_size = strlen(text)+1; | 226 | *data_size = strlen(text)+1; |
222 | memcpy(data, text, *data_size); | 227 | memcpy(data, text, *data_size); |
223 | 228 | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); | 229 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin sends (to all): %s\n", text); |
225 | 230 | ||
226 | return GNUNET_YES; | 231 | return GNUNET_YES; |
227 | } | 232 | } |
228 | 233 | ||
229 | 234 | ||
@@ -232,8 +237,8 @@ origin_request (void *cls, | |||
232 | const struct GNUNET_MULTICAST_RequestHeader *req) | 237 | const struct GNUNET_MULTICAST_RequestHeader *req) |
233 | { | 238 | { |
234 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]); | 239 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin receives: %s\n", (char *)&req[1]); |
235 | 240 | ||
236 | if (0 != strncmp ("ping", (char *)&req[1], 4)) | 241 | if (0 != strncmp ("ping", (char *)&req[1], 4)) |
237 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); | 242 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "origin didn't reveice a correct request"); |
238 | 243 | ||
239 | GNUNET_MULTICAST_origin_to_all (origin, | 244 | GNUNET_MULTICAST_origin_to_all (origin, |
@@ -246,7 +251,7 @@ origin_request (void *cls, | |||
246 | 251 | ||
247 | static void | 252 | static void |
248 | origin_message (void *cls, | 253 | origin_message (void *cls, |
249 | const struct GNUNET_MULTICAST_MessageHeader *msg) | 254 | const struct GNUNET_MULTICAST_MessageHeader *msg) |
250 | { | 255 | { |
251 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); | 256 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); |
252 | } | 257 | } |
@@ -288,11 +293,12 @@ multicast_ca1 (void *cls, | |||
288 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 293 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
289 | { | 294 | { |
290 | struct GNUNET_MessageHeader *join_msg; | 295 | struct GNUNET_MessageHeader *join_msg; |
296 | void *ret; | ||
291 | 297 | ||
292 | // Get members keys | 298 | // Get members keys |
293 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | 299 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); |
294 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | 300 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); |
295 | 301 | ||
296 | char data[] = "Hi, can I enter?"; | 302 | char data[] = "Hi, can I enter?"; |
297 | uint8_t data_size = strlen (data) + 1; | 303 | uint8_t data_size = strlen (data) + 1; |
298 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); | 304 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); |
@@ -303,7 +309,7 @@ multicast_ca1 (void *cls, | |||
303 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 309 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
304 | "Members tries to join multicast group\n"); | 310 | "Members tries to join multicast group\n"); |
305 | 311 | ||
306 | return GNUNET_MULTICAST_member_join (cfg, | 312 | ret = GNUNET_MULTICAST_member_join (cfg, |
307 | &group_pub_key, | 313 | &group_pub_key, |
308 | member_key, | 314 | member_key, |
309 | peer_id[0], | 315 | peer_id[0], |
@@ -316,6 +322,8 @@ multicast_ca1 (void *cls, | |||
316 | NULL, /* no test for member_replay_msg */ | 322 | NULL, /* no test for member_replay_msg */ |
317 | member_message, | 323 | member_message, |
318 | NULL); | 324 | NULL); |
325 | GNUNET_free (join_msg); | ||
326 | return ret; | ||
319 | } | 327 | } |
320 | 328 | ||
321 | 329 | ||
@@ -327,7 +335,7 @@ peer_information_cb (void *cls, | |||
327 | { | 335 | { |
328 | int i = (int) (long) cls; | 336 | int i = (int) (long) cls; |
329 | 337 | ||
330 | if (NULL == pinfo) | 338 | if (NULL == pinfo) |
331 | { | 339 | { |
332 | result = GNUNET_SYSERR; | 340 | result = GNUNET_SYSERR; |
333 | GNUNET_SCHEDULER_shutdown (); | 341 | GNUNET_SCHEDULER_shutdown (); |
@@ -341,7 +349,7 @@ peer_information_cb (void *cls, | |||
341 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 349 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
342 | "Create member peer\n"); | 350 | "Create member peer\n"); |
343 | 351 | ||
344 | if (0 == i) | 352 | if (0 == i) |
345 | { | 353 | { |
346 | /* connect to multicast service of member */ | 354 | /* connect to multicast service of member */ |
347 | op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ | 355 | op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ |