aboutsummaryrefslogtreecommitdiff
path: root/src/multicast
diff options
context:
space:
mode:
authorxrs <xrs@mail36.net>2017-01-25 20:26:58 +0100
committerxrs <xrs@mail36.net>2017-01-25 21:13:39 +0100
commite76078deb931e473565a0d718f837d60e1b9caf8 (patch)
tree7a20c1ca43c6df15236738868bcbde2bf81c3a92 /src/multicast
parent90a06febf7b54540ac8bdf3c9ae89c062c1f2466 (diff)
downloadgnunet-e76078deb931e473565a0d718f837d60e1b9caf8.tar.gz
gnunet-e76078deb931e473565a0d718f837d60e1b9caf8.zip
multicast: test simple join between two peers
Diffstat (limited to 'src/multicast')
-rw-r--r--src/multicast/test_multicast_multipeer.c321
1 files changed, 228 insertions, 93 deletions
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c
index 3edf0153e..792b49c49 100644
--- a/src/multicast/test_multicast_multipeer.c
+++ b/src/multicast/test_multicast_multipeer.c
@@ -35,16 +35,19 @@
35 35
36#define NUM_PEERS 2 36#define NUM_PEERS 2
37 37
38static struct GNUNET_TESTBED_Operation *peer0; 38static struct GNUNET_TESTBED_Operation *op0;
39static struct GNUNET_TESTBED_Operation *peer1; 39static struct GNUNET_TESTBED_Operation *op1;
40static struct GNUNET_TESTBED_Peer **peers;
40 41
41static struct GNUNET_SCHEDULER_Task *timeout_tid; 42static struct GNUNET_SCHEDULER_Task *timeout_tid;
42 43
44static struct GNUNET_MULTICAST_Origin *origin;
45
43struct GNUNET_CRYPTO_EddsaPrivateKey *group_key; 46struct GNUNET_CRYPTO_EddsaPrivateKey *group_key;
44struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key; 47struct GNUNET_CRYPTO_EddsaPublicKey group_pub_key;
45 48
46struct GNUNET_CRYPTO_EcdsaPrivateKey *member1_key; 49struct GNUNET_CRYPTO_EcdsaPrivateKey *member_key;
47struct GNUNET_CRYPTO_EcdsaPublicKey member1_pub_key; 50struct GNUNET_CRYPTO_EcdsaPublicKey member_pub_key;
48 51
49 52
50enum 53enum
@@ -68,10 +71,15 @@ static int result;
68static void 71static void
69shutdown_task (void *cls) 72shutdown_task (void *cls)
70{ 73{
71 if (NULL != peer0) 74 if (NULL != op0)
75 {
76 GNUNET_TESTBED_operation_done (op0);
77 op0 = NULL;
78 }
79 if (NULL != op1)
72 { 80 {
73 GNUNET_TESTBED_operation_done (peer0); 81 GNUNET_TESTBED_operation_done (op1);
74 peer0 = NULL; 82 op1 = NULL;
75 } 83 }
76 if (NULL != timeout_tid) 84 if (NULL != timeout_tid)
77 { 85 {
@@ -91,111 +99,179 @@ timeout_task (void *cls)
91 GNUNET_SCHEDULER_shutdown (); 99 GNUNET_SCHEDULER_shutdown ();
92} 100}
93 101
94
95static void 102static void
96origin_recv_replay_msg (void *cls, 103pi_cb (void *cls,
97 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, 104 struct GNUNET_TESTBED_Operation *op,
98 uint64_t message_id, 105 const struct GNUNET_TESTBED_PeerInformation *pinfo,
99 uint64_t fragment_offset, 106 const char *emsg)
100 uint64_t flags,
101 struct GNUNET_MULTICAST_ReplayHandle *rh)
102{ 107{
103 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
104 "Test #%u: origin_recv_replay_msg()\n", test);
105 GNUNET_assert (0);
106} 108}
107 109
110static void
111member_join_request (void *cls,
112 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
113 const struct GNUNET_MessageHeader *join_msg,
114 struct GNUNET_MULTICAST_JoinHandle *jh)
115{
116 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
117 "Member sent a join request.");
118
119}
108 120
109static void 121
110member_recv_replay_msg (void *cls, 122static void
111 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key, 123member_join_decision (void *cls,
112 uint64_t message_id, 124 int is_admitted,
113 uint64_t fragment_offset, 125 const struct GNUNET_PeerIdentity *peer,
114 uint64_t flags, 126 uint16_t relay_count,
115 struct GNUNET_MULTICAST_ReplayHandle *rh) 127 const struct GNUNET_PeerIdentity *relays,
128 const struct GNUNET_MessageHeader *join_msg)
116{ 129{
117 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 130 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
118 "Test #%u: member_recv_replay_msg()\n", test); 131 "Member received a decision from origin: ...");
119 GNUNET_assert (0); 132
120} 133}
121 134
135static void
136member_replay_frag ()
137{
138 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
139 "member replay frag...");
140}
122 141
123static void 142static void
124origin_recv_replay_frag (void *cls, 143member_replay_msg ()
125 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_key,
126 uint64_t fragment_id,
127 uint64_t flags,
128 struct GNUNET_MULTICAST_ReplayHandle *rh)
129{ 144{
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 145 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
131 "Test #%u: origin_recv_replay_frag()" 146 "member replay msg...");
132 " - fragment_id=%" PRIu64 " flags=%" PRIu64 "\n",
133 test, fragment_id, flags);
134} 147}
135 148
149static void
150member_message ()
151{
152 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
153 "member message...");
154}
136 155
137/** 156static void
138 * Test: origin receives join request 157origin_join_request (void *cls,
139 */ 158 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
140static void 159 const struct GNUNET_MessageHeader *join_msg,
141origin_recv_join_request (void *cls, 160 struct GNUNET_MULTICAST_JoinHandle *jh)
142 const struct GNUNET_CRYPTO_EcdsaPublicKey *mem_key,
143 const struct GNUNET_MessageHeader *join_msg,
144 struct GNUNET_MULTICAST_JoinHandle *jh)
145{ 161{
146 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 162 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
147 "Test #%u: origin_recv_join_request()\n", test); 163 "yey, got a join request. Let's see who it is.");
164
165 result = GNUNET_OK;
148} 166}
149 167
168static void
169origin_replay_frag (void *cls,
170 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
171 uint64_t fragment_id,
172 uint64_t flags,
173 struct GNUNET_MULTICAST_ReplayHandle *rh)
174{
175
176}
150 177
151static void 178static void
152origin_recv_request (void *cls, 179origin_replay_msg (void *cls,
153 const struct GNUNET_MULTICAST_RequestHeader *req) 180 const struct GNUNET_CRYPTO_EcdsaPublicKey *member_pub_key,
181 uint64_t message_id,
182 uint64_t fragment_offset,
183 uint64_t flags,
184 struct GNUNET_MULTICAST_ReplayHandle *rh)
154{ 185{
155 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 186
156 "Test #%u: origin_recv_request()\n", 187 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin replay msg\n");
157 test);
158} 188}
159 189
190static void
191origin_request (void *cls,
192 const struct GNUNET_MULTICAST_RequestHeader *req)
193{
194 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "origin request msg\n");
195
196}
160 197
161static void 198static void
162origin_recv_message (void *cls, 199origin_message (void *cls,
163 const struct GNUNET_MULTICAST_MessageHeader *msg) 200 const struct GNUNET_MULTICAST_MessageHeader *msg)
164{ 201{
165 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
166 "Test #%u: origin_recv_message()\n",
167 test);
168} 202}
169 203
170 204
171static void 205static void
172service_close_peer0 (void *cls, 206service_connect1 (void *cls,
173 void *op_result) 207 struct GNUNET_TESTBED_Operation *op,
208 void *ca_result,
209 const char *emsg)
174{ 210{
175 struct GNUNET_MULTICAST_Origin *orig = op_result; 211 struct GNUNET_MULTICAST_Member *member = ca_result;
176 212
177 GNUNET_MULTICAST_origin_stop (orig, NULL, NULL); 213 if (NULL != member)
214 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connected to multicast service of member\n");
215 else
216 result = GNUNET_SYSERR;
217}
218
219static void
220multicast_da1 (void *cls,
221 void * op_result)
222{
223 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
224 "disconnecting from multicast service of member\n");
178} 225}
179 226
180 227
181/**
182 * Function run when service multicast has started and is providing us
183 * with a configuration file.
184 */
185static void * 228static void *
186service_conf_peer0 (void *cls, 229multicast_ca1 (void *cls,
187 const struct GNUNET_CONFIGURATION_Handle *cfg) 230 const struct GNUNET_CONFIGURATION_Handle *cfg)
188{ 231{
189 group_key = GNUNET_CRYPTO_eddsa_key_create (); 232 struct GNUNET_MessageHeader *join_msg;
190 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); 233 const struct GNUNET_PeerIdentity *peer_id_origin;
191 234 struct GNUNET_HashCode pub_hash;
192 return GNUNET_MULTICAST_origin_start (cfg, group_key, 0, 235
193 origin_recv_join_request, 236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connecting to multicast service of member...\n");
194 origin_recv_replay_frag, 237
195 origin_recv_replay_msg, 238 // Get members keys
196 origin_recv_request, 239 member_key = GNUNET_CRYPTO_ecdsa_key_create ();
197 origin_recv_message, 240 GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key);
198 NULL); 241
242 // Get GNUnet identity of origin
243 peer_id_origin = GNUNET_TESTBED_peer_get_information (peers[0],
244 GNUNET_TESTBED_PIT_IDENTITY,
245 pi_cb,
246 NULL);
247
248 GNUNET_assert(NULL != peer_id_origin);
249
250 GNUNET_CRYPTO_hash (&peer_id_origin, sizeof (peer_id_origin), &pub_hash);
251 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
252 "member: id of origin is %s\n",
253 GNUNET_h2s (&pub_hash));
254
255 char data[] = "Hello Mr. Smith!";
256 uint8_t data_size = strlen (data) + 1;
257 join_msg = GNUNET_malloc (sizeof (join_msg) + data_size);
258 join_msg->size = htons (sizeof (join_msg) + data_size);
259 join_msg->type = htons (123);
260 GNUNET_memcpy (&join_msg[1], data, data_size);
261
262 return GNUNET_MULTICAST_member_join (cfg,
263 &group_pub_key,
264 member_key,
265 peer_id_origin,
266 0,
267 NULL,
268 join_msg, /* join message */
269 member_join_request,
270 member_join_decision,
271 member_replay_frag,
272 member_replay_msg,
273 member_message,
274 NULL);
199} 275}
200 276
201 277
@@ -210,20 +286,58 @@ service_conf_peer0 (void *cls,
210 * connect to the DHT. 286 * connect to the DHT.
211 */ 287 */
212static void 288static void
213service_connect_peer0 (void *cls, 289service_connect0 (void *cls,
214 struct GNUNET_TESTBED_Operation *op, 290 struct GNUNET_TESTBED_Operation *op,
215 void *ca_result, 291 void *ca_result,
216 const char *emsg) 292 const char *emsg)
217{ 293{
218 struct GNUNET_MULTICAST_Origin *orig = ca_result; 294 struct GNUNET_MULTICAST_Origin *origin = ca_result;
295
296 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
297 "connected to multicast service of origin\n");
219 298
220 /* Connection to service successful. Here we'd usually do something with 299 /* Connection to service successful. Here we'd usually do something with
221 * the service. */ 300 * the service. */
222 result = GNUNET_OK; 301 result = GNUNET_OK;
223 GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */ 302 //GNUNET_SCHEDULER_shutdown (); /* Also kills the testbed */
224} 303}
225 304
226 305
306
307/**
308 * Function run when service multicast has started and is providing us
309 * with a configuration file.
310 */
311static void *
312multicast_ca0 (void *cls,
313 const struct GNUNET_CONFIGURATION_Handle *cfg)
314{
315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
316 "connecting to multicast service of origin...\n");
317
318 group_key = GNUNET_CRYPTO_eddsa_key_create ();
319 GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key);
320
321 return GNUNET_MULTICAST_origin_start (cfg,
322 group_key,
323 0,
324 origin_join_request,
325 origin_replay_frag,
326 origin_replay_msg,
327 origin_request,
328 origin_message,
329 NULL);
330}
331
332static void
333multicast_da0 (void *cls,
334 void *op_result)
335{
336 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
337 "disconnecting from multicast service of origin\n");
338
339}
340
227/** 341/**
228 * Main function inovked from TESTBED once all of the 342 * Main function inovked from TESTBED once all of the
229 * peers are up and running. This one then connects 343 * peers are up and running. This one then connects
@@ -241,31 +355,52 @@ service_connect_peer0 (void *cls,
241 * @param links_failed number of links testbed was unable to establish 355 * @param links_failed number of links testbed was unable to establish
242 */ 356 */
243static void 357static void
244run (void *cls, 358testbed_master (void *cls,
245 struct GNUNET_TESTBED_RunHandle *h, 359 struct GNUNET_TESTBED_RunHandle *h,
246 unsigned int num_peers, 360 unsigned int num_peers,
247 struct GNUNET_TESTBED_Peer **peers, 361 struct GNUNET_TESTBED_Peer **p,
248 unsigned int links_succeeded, 362 unsigned int links_succeeded,
249 unsigned int links_failed) 363 unsigned int links_failed)
250{ 364{
251 /* Testbed is ready with peers running and connected in a pre-defined overlay 365 /* Testbed is ready with peers running and connected in a pre-defined overlay
252 topology (FIXME) */ 366 topology (FIXME) */
367
368 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
369 "connected to testbed_master()\n");
370
371 peers = p;
253 372
254 /* connect to a peers service */ 373 /* connect to a peers service */
255 peer0 = GNUNET_TESTBED_service_connect 374 op0 = GNUNET_TESTBED_service_connect
256 (NULL, /* Closure for operation */ 375 (NULL, /* Closure for operation */
257 peers[0], /* The peer whose service to connect to */ 376 peers[0], /* The peer whose service to connect to */
258 "multicast", /* The name of the service */ 377 "multicast", /* The name of the service */
259 &service_connect_peer0, /* callback to call after a handle to service 378 service_connect0, /* callback to call after a handle to service
379 is opened */
380 NULL, /* closure for the above callback */
381 multicast_ca0, /* callback to call with peer's configuration;
382 this should open the needed service connection */
383 multicast_da0, /* callback to be called when closing the
384 opened service connection */
385 NULL); /* closure for the above two callbacks */
386
387 op1 = GNUNET_TESTBED_service_connect
388 (NULL, /* Closure for operation */
389 peers[1], /* The peer whose service to connect to */
390 "multicast", /* The name of the service */
391 service_connect1, /* callback to call after a handle to service
260 is opened */ 392 is opened */
261 NULL, /* closure for the above callback */ 393 NULL, /* closure for the above callback */
262 &service_conf_peer0, /* callback to call with peer's configuration; 394 multicast_ca1, /* callback to call with peer's configuration;
263 this should open the needed service connection */ 395 this should open the needed service connection */
264 &service_close_peer0, /* callback to be called when closing the 396 multicast_da1, /* callback to be called when closing the
265 opened service connection */ 397 opened service connection */
266 NULL); /* closure for the above two callbacks */ 398 NULL); /* closure for the above two callbacks */
267 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 399
268 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 400 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */
401
402 /* Schedule the shutdown task with a delay of a few 1econds */
403 timeout_tid = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3),
269 &timeout_task, NULL); 404 &timeout_task, NULL);
270} 405}
271 406
@@ -283,7 +418,7 @@ main (int argc, char *argv[])
283 0LL, /* Event mask - set to 0 for no event notifications */ 418 0LL, /* Event mask - set to 0 for no event notifications */
284 NULL, /* Controller event callback */ 419 NULL, /* Controller event callback */
285 NULL, /* Closure for controller event callback */ 420 NULL, /* Closure for controller event callback */
286 run, /* continuation callback to be called when testbed setup is complete */ 421 testbed_master, /* continuation callback to be called when testbed setup is complete */
287 NULL); /* Closure for the test_master callback */ 422 NULL); /* Closure for the test_master callback */
288 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) ) 423 if ( (GNUNET_OK != ret) || (GNUNET_OK != result) )
289 return 1; 424 return 1;