diff options
author | xrs <xrs@mail36.net> | 2017-02-12 01:44:00 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2017-02-12 01:44:00 +0100 |
commit | 8a30704ad0aa3aeafb88478c461394460076a3af (patch) | |
tree | 3a07d4665767bef58c70e4b3ba749b855fda2722 | |
parent | 16f20246b1b73d428e4bcea5562a4cc1d3542d6f (diff) | |
download | gnunet-8a30704ad0aa3aeafb88478c461394460076a3af.tar.gz gnunet-8a30704ad0aa3aeafb88478c461394460076a3af.zip |
set up multicast group with origin and member
-rw-r--r-- | src/multicast/test_multicast_multipeer.c | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c index 591aa56f8..bb3ae447c 100644 --- a/src/multicast/test_multicast_multipeer.c +++ b/src/multicast/test_multicast_multipeer.c | |||
@@ -37,12 +37,16 @@ | |||
37 | 37 | ||
38 | static struct GNUNET_TESTBED_Operation *op0; | 38 | static struct GNUNET_TESTBED_Operation *op0; |
39 | static struct GNUNET_TESTBED_Operation *op1; | 39 | static struct GNUNET_TESTBED_Operation *op1; |
40 | static struct GNUNET_TESTBED_Operation *pi_op0; | ||
41 | static struct GNUNET_TESTBED_Operation *pi_op1; | ||
42 | |||
40 | static struct GNUNET_TESTBED_Peer **peers; | 43 | static struct GNUNET_TESTBED_Peer **peers; |
41 | const struct GNUNET_PeerIdentity *peer_id_origin; | 44 | const struct GNUNET_PeerIdentity *peer_id[2]; |
42 | 45 | ||
43 | static struct GNUNET_SCHEDULER_Task *timeout_tid; | 46 | static struct GNUNET_SCHEDULER_Task *timeout_tid; |
44 | 47 | ||
45 | static struct GNUNET_MULTICAST_Origin *origin; | 48 | static struct GNUNET_MULTICAST_Origin *origin; |
49 | static struct GNUNET_MULTICAST_Member *member; | ||
46 | 50 | ||
47 | struct GNUNET_CRYPTO_EddsaPrivateKey *group_key; | 51 | struct GNUNET_CRYPTO_EddsaPrivateKey *group_key; |
48 | struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; | 52 | struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; |
@@ -82,6 +86,16 @@ shutdown_task (void *cls) | |||
82 | GNUNET_TESTBED_operation_done (op1); | 86 | GNUNET_TESTBED_operation_done (op1); |
83 | op1 = NULL; | 87 | op1 = NULL; |
84 | } | 88 | } |
89 | if (NULL != pi_op0) | ||
90 | { | ||
91 | GNUNET_TESTBED_operation_done (pi_op0); | ||
92 | pi_op0 = NULL; | ||
93 | } | ||
94 | if (NULL != pi_op1) | ||
95 | { | ||
96 | GNUNET_TESTBED_operation_done (pi_op1); | ||
97 | pi_op1 = NULL; | ||
98 | } | ||
85 | if (NULL != timeout_tid) | 99 | if (NULL != timeout_tid) |
86 | { | 100 | { |
87 | GNUNET_SCHEDULER_cancel (timeout_tid); | 101 | GNUNET_SCHEDULER_cancel (timeout_tid); |
@@ -108,7 +122,7 @@ member_join_request (void *cls, | |||
108 | struct GNUNET_MULTICAST_JoinHandle *jh) | 122 | struct GNUNET_MULTICAST_JoinHandle *jh) |
109 | { | 123 | { |
110 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
111 | "Member sent a join request."); | 125 | "Member sent a join request.\n"); |
112 | 126 | ||
113 | } | 127 | } |
114 | 128 | ||
@@ -122,29 +136,31 @@ member_join_decision (void *cls, | |||
122 | const struct GNUNET_MessageHeader *join_msg) | 136 | const struct GNUNET_MessageHeader *join_msg) |
123 | { | 137 | { |
124 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
125 | "Member received a decision from origin: ..."); | 139 | "Member received a decision from origin: %s\n", (GNUNET_YES == is_admitted)?"accepted":"rejected"); |
126 | 140 | ||
141 | result = GNUNET_OK; | ||
142 | GNUNET_SCHEDULER_shutdown (); | ||
127 | } | 143 | } |
128 | 144 | ||
129 | static void | 145 | static void |
130 | member_replay_frag () | 146 | member_replay_frag () |
131 | { | 147 | { |
132 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 148 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
133 | "member replay frag..."); | 149 | "member replay frag...\n"); |
134 | } | 150 | } |
135 | 151 | ||
136 | static void | 152 | static void |
137 | member_replay_msg () | 153 | member_replay_msg () |
138 | { | 154 | { |
139 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 155 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
140 | "member replay msg..."); | 156 | "member replay msg...\n"); |
141 | } | 157 | } |
142 | 158 | ||
143 | static void | 159 | static void |
144 | member_message () | 160 | member_message () |
145 | { | 161 | { |
146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
147 | "member message..."); | 163 | "member message...\n"); |
148 | } | 164 | } |
149 | 165 | ||
150 | static void | 166 | static void |
@@ -153,8 +169,29 @@ origin_join_request (void *cls, | |||
153 | const struct GNUNET_MessageHeader *join_msg, | 169 | const struct GNUNET_MessageHeader *join_msg, |
154 | struct GNUNET_MULTICAST_JoinHandle *jh) | 170 | struct GNUNET_MULTICAST_JoinHandle *jh) |
155 | { | 171 | { |
172 | struct GNUNET_MessageHeader *join_resp; | ||
173 | |||
174 | uint8_t data_size = ntohs (join_msg->size); | ||
175 | |||
176 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
177 | "Dizzy: Mh, got a join request...\n"); | ||
156 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
157 | "yey, got a join request. Let's see who it is."); | 179 | "'%s'\n", (char *)&join_msg[1]); |
180 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
181 | "Dizzy: Oh, it's Bird! Let's get him in.\n"); | ||
182 | |||
183 | char data[] = "Hi, Bird. Come in!"; | ||
184 | data_size = strlen (data) + 1; | ||
185 | join_resp = GNUNET_malloc (sizeof (join_resp) + data_size); | ||
186 | join_resp->size = htons (sizeof (join_resp) + data_size); | ||
187 | join_resp->type = htons (123); | ||
188 | GNUNET_memcpy (&join_resp[1], data, data_size); | ||
189 | |||
190 | GNUNET_MULTICAST_join_decision (jh, | ||
191 | GNUNET_YES, | ||
192 | 0, | ||
193 | NULL, | ||
194 | join_resp); | ||
158 | 195 | ||
159 | result = GNUNET_OK; | 196 | result = GNUNET_OK; |
160 | } | 197 | } |
@@ -166,7 +203,7 @@ origin_replay_frag (void *cls, | |||
166 | uint64_t flags, | 203 | uint64_t flags, |
167 | struct GNUNET_MULTICAST_ReplayHandle *rh) | 204 | struct GNUNET_MULTICAST_ReplayHandle *rh) |
168 | { | 205 | { |
169 | 206 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay fraq msg\n"); | |
170 | } | 207 | } |
171 | 208 | ||
172 | static void | 209 | static void |
@@ -193,6 +230,7 @@ static void | |||
193 | origin_message (void *cls, | 230 | origin_message (void *cls, |
194 | const struct GNUNET_MULTICAST_MessageHeader *msg) | 231 | const struct GNUNET_MULTICAST_MessageHeader *msg) |
195 | { | 232 | { |
233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin message msg\n"); | ||
196 | } | 234 | } |
197 | 235 | ||
198 | 236 | ||
@@ -202,7 +240,7 @@ service_connect1 (void *cls, | |||
202 | void *ca_result, | 240 | void *ca_result, |
203 | const char *emsg) | 241 | const char *emsg) |
204 | { | 242 | { |
205 | struct GNUNET_MULTICAST_Member *member = ca_result; | 243 | member = ca_result; |
206 | 244 | ||
207 | if (NULL != member) | 245 | if (NULL != member) |
208 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n"); | 246 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n"); |
@@ -215,7 +253,9 @@ multicast_da1 (void *cls, | |||
215 | void * op_result) | 253 | void * op_result) |
216 | { | 254 | { |
217 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 255 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
218 | "disconnecting from multicast service of member\n"); | 256 | "Member parting from multicast group\n"); |
257 | |||
258 | GNUNET_MULTICAST_member_part (member, NULL, NULL); | ||
219 | } | 259 | } |
220 | 260 | ||
221 | 261 | ||
@@ -229,17 +269,20 @@ multicast_ca1 (void *cls, | |||
229 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | 269 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); |
230 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | 270 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); |
231 | 271 | ||
232 | char data[] = "Hello Mr. Smith!"; | 272 | char data[] = "Whut's up, Dizzy!"; |
233 | uint8_t data_size = strlen (data) + 1; | 273 | uint8_t data_size = strlen (data) + 1; |
234 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); | 274 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); |
235 | join_msg->size = htons (sizeof (join_msg) + data_size); | 275 | join_msg->size = htons (sizeof (join_msg) + data_size); |
236 | join_msg->type = htons (123); | 276 | join_msg->type = htons (123); |
237 | GNUNET_memcpy (&join_msg[1], data, data_size); | 277 | GNUNET_memcpy (&join_msg[1], data, data_size); |
238 | 278 | ||
279 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
280 | "Members tries to join multicast group\n"); | ||
281 | |||
239 | return GNUNET_MULTICAST_member_join (cfg, | 282 | return GNUNET_MULTICAST_member_join (cfg, |
240 | &group_pub_key, | 283 | &group_pub_key, |
241 | member_key, | 284 | member_key, |
242 | peer_id_origin, | 285 | peer_id[0], |
243 | 0, | 286 | 0, |
244 | NULL, | 287 | NULL, |
245 | join_msg, /* join message */ | 288 | join_msg, /* join message */ |
@@ -258,18 +301,22 @@ peer_information_cb (void *cls, | |||
258 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | 301 | const struct GNUNET_TESTBED_PeerInformation *pinfo, |
259 | const char *emsg) | 302 | const char *emsg) |
260 | { | 303 | { |
304 | int i = (int) cls; | ||
305 | |||
261 | if (NULL == pinfo) { | 306 | if (NULL == pinfo) { |
262 | result = GNUNET_SYSERR; | 307 | result = GNUNET_SYSERR; |
263 | GNUNET_SCHEDULER_shutdown (); | 308 | GNUNET_SCHEDULER_shutdown (); |
264 | } | 309 | } |
265 | 310 | ||
266 | peer_id_origin = pinfo->result.id; | 311 | peer_id[i] = pinfo->result.id; |
267 | 312 | ||
268 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 313 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
269 | "Got peer information of origin (%s)\n", GNUNET_i2s(pinfo->result.id)); | 314 | "Got peer information of %s (%s)\n", (0==i)?"origin":"member" ,GNUNET_i2s(pinfo->result.id)); |
270 | 315 | ||
271 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 316 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
272 | "Create member peer\n"); | 317 | "Create member peer\n"); |
318 | |||
319 | if (0 == i) { | ||
273 | /* connect to multicast service of member */ | 320 | /* connect to multicast service of member */ |
274 | op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ | 321 | op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ |
275 | peers[1], /* The peer whose service to connect to */ | 322 | peers[1], /* The peer whose service to connect to */ |
@@ -282,6 +329,7 @@ peer_information_cb (void *cls, | |||
282 | multicast_da1, /* callback to be called when closing the | 329 | multicast_da1, /* callback to be called when closing the |
283 | opened service connection */ | 330 | opened service connection */ |
284 | NULL); /* closure for the above two callbacks */ | 331 | NULL); /* closure for the above two callbacks */ |
332 | } | ||
285 | } | 333 | } |
286 | 334 | ||
287 | /** | 335 | /** |
@@ -300,16 +348,21 @@ service_connect0 (void *cls, | |||
300 | void *ca_result, | 348 | void *ca_result, |
301 | const char *emsg) | 349 | const char *emsg) |
302 | { | 350 | { |
303 | struct GNUNET_MULTICAST_Origin *origin = ca_result; | 351 | origin = ca_result; |
304 | 352 | ||
305 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 353 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
306 | "Connected to multicast service of origin\n"); | 354 | "Connected to multicast service of origin\n"); |
307 | 355 | ||
308 | // Get GNUnet identity of origin | 356 | // Get GNUnet identity of origin |
309 | op0 = GNUNET_TESTBED_peer_get_information (peers[0], | 357 | pi_op0 = GNUNET_TESTBED_peer_get_information (peers[0], |
310 | GNUNET_TESTBED_PIT_IDENTITY, | 358 | GNUNET_TESTBED_PIT_IDENTITY, |
311 | peer_information_cb, | 359 | peer_information_cb, |
312 | NULL); | 360 | (void *) 0); |
361 | // Get GNUnet identity of member | ||
362 | pi_op1 = GNUNET_TESTBED_peer_get_information (peers[1], | ||
363 | GNUNET_TESTBED_PIT_IDENTITY, | ||
364 | peer_information_cb, | ||
365 | (void *) 1); | ||
313 | 366 | ||
314 | /* Connection to service successful. Here we'd usually do something with | 367 | /* Connection to service successful. Here we'd usually do something with |
315 | * the service. */ | 368 | * the service. */ |
@@ -346,8 +399,9 @@ multicast_da0 (void *cls, | |||
346 | void *op_result) | 399 | void *op_result) |
347 | { | 400 | { |
348 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 401 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
349 | "disconnecting from multicast service of origin\n"); | 402 | "Origin closes multicast group\n"); |
350 | 403 | ||
404 | GNUNET_MULTICAST_origin_stop (origin, NULL, NULL); | ||
351 | } | 405 | } |
352 | 406 | ||
353 | 407 | ||
@@ -399,7 +453,7 @@ testbed_master (void *cls, | |||
399 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ | 453 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ |
400 | 454 | ||
401 | /* Schedule the shutdown task with a delay of a few Seconds */ | 455 | /* Schedule the shutdown task with a delay of a few Seconds */ |
402 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | 456 | timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 40), |
403 | &timeout_task, NULL); | 457 | &timeout_task, NULL); |
404 | } | 458 | } |
405 | 459 | ||