summaryrefslogtreecommitdiff
path: root/src/psyc/test_psyc.c
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2014-05-29 16:35:55 +0000
committerGabor X Toth <*@tg-x.net>2014-05-29 16:35:55 +0000
commit9955561e1b204ccf23fbf841f409bd3ef79be88c (patch)
tree0271c23ae9f1dad72266a0e6073d696e5afca027 /src/psyc/test_psyc.c
parenta5877668ba805c5e0efe622e6ce4c58ff5609bf9 (diff)
downloadgnunet-9955561e1b204ccf23fbf841f409bd3ef79be88c.tar.gz
gnunet-9955561e1b204ccf23fbf841f409bd3ef79be88c.zip
psyc, multicast: reorg code, use new client manager & psyc util lib
Diffstat (limited to 'src/psyc/test_psyc.c')
-rw-r--r--src/psyc/test_psyc.c129
1 files changed, 65 insertions, 64 deletions
diff --git a/src/psyc/test_psyc.c b/src/psyc/test_psyc.c
index 35e80868c..6468b8a2b 100644
--- a/src/psyc/test_psyc.c
+++ b/src/psyc/test_psyc.c
@@ -68,6 +68,7 @@ struct TransmitClosure
68 struct GNUNET_PSYC_MasterTransmitHandle *mst_tmit; 68 struct GNUNET_PSYC_MasterTransmitHandle *mst_tmit;
69 struct GNUNET_PSYC_SlaveTransmitHandle *slv_tmit; 69 struct GNUNET_PSYC_SlaveTransmitHandle *slv_tmit;
70 struct GNUNET_ENV_Environment *env; 70 struct GNUNET_ENV_Environment *env;
71 struct GNUNET_ENV_Modifier *mod;
71 char *data[16]; 72 char *data[16];
72 const char *mod_value; 73 const char *mod_value;
73 size_t mod_value_size; 74 size_t mod_value_size;
@@ -79,7 +80,7 @@ struct TransmitClosure
79 80
80struct TransmitClosure *tmit; 81struct TransmitClosure *tmit;
81 82
82static int join_req_count; 83static uint8_t join_req_count;
83 84
84enum 85enum
85{ 86{
@@ -183,7 +184,7 @@ master_message_cb (void *cls, uint64_t message_id, uint32_t flags,
183 184
184 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 185 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
185 "Master got message part of type %u and size %u " 186 "Master got message part of type %u and size %u "
186 "belonging to message ID %llu with flags %xu\n", 187 "belonging to message ID %llu with flags %x\n",
187 type, size, message_id, flags); 188 type, size, message_id, flags);
188 189
189 switch (test) 190 switch (test)
@@ -227,7 +228,7 @@ slave_message_cb (void *cls, uint64_t message_id, uint32_t flags,
227 228
228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
229 "Slave got message part of type %u and size %u " 230 "Slave got message part of type %u and size %u "
230 "belonging to message ID %llu with flags %xu\n", 231 "belonging to message ID %llu with flags %x\n",
231 type, size, message_id, flags); 232 type, size, message_id, flags);
232 233
233 switch (test) 234 switch (test)
@@ -256,6 +257,48 @@ transmit_resume (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
256 257
257 258
258static int 259static int
260tmit_notify_data (void *cls, uint16_t *data_size, void *data)
261{
262 struct TransmitClosure *tmit = cls;
263 if (0 == tmit->data_count)
264 {
265 *data_size = 0;
266 return GNUNET_YES;
267 }
268
269 uint16_t size = strlen (tmit->data[tmit->n]);
270 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
271 "Transmit notify data: %u bytes available, "
272 "processing fragment %u/%u (size %u).\n",
273 *data_size, tmit->n + 1, tmit->data_count, size);
274 if (*data_size < size)
275 {
276 *data_size = 0;
277 GNUNET_assert (0);
278 return GNUNET_SYSERR;
279 }
280
281 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
282 {
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
284 tmit->paused = GNUNET_YES;
285 GNUNET_SCHEDULER_add_delayed (
286 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
287 tmit->data_delay[tmit->n]),
288 &transmit_resume, tmit);
289 *data_size = 0;
290 return GNUNET_NO;
291 }
292 tmit->paused = GNUNET_NO;
293
294 *data_size = size;
295 memcpy (data, tmit->data[tmit->n], size);
296
297 return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
298}
299
300
301static int
259tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper, 302tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper,
260 uint32_t *full_value_size) 303 uint32_t *full_value_size)
261{ 304{
@@ -265,41 +308,39 @@ tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper,
265 "%u modifiers left to process.\n", 308 "%u modifiers left to process.\n",
266 *data_size, GNUNET_ENV_environment_get_count (tmit->env)); 309 *data_size, GNUNET_ENV_environment_get_count (tmit->env));
267 310
268 enum GNUNET_ENV_Operator op = 0;
269 const char *name = NULL;
270 const char *value = NULL;
271 uint16_t name_size = 0; 311 uint16_t name_size = 0;
272 size_t value_size = 0; 312 size_t value_size = 0;
313 const char *value = NULL;
273 314
274 if (NULL != oper) 315 if (NULL != oper && NULL != tmit->mod)
275 { /* New modifier */ 316 { /* New modifier */
276 if (GNUNET_NO == GNUNET_ENV_environment_shift (tmit->env, &op, &name, 317 tmit->mod = tmit->mod->next;
277 (void *) &value, &value_size)) 318 if (NULL == tmit->mod)
278 { /* No more modifiers, continue with data */ 319 { /* No more modifiers, continue with data */
279 *data_size = 0; 320 *data_size = 0;
280 return GNUNET_YES; 321 return GNUNET_YES;
281 } 322 }
282 323
283 GNUNET_assert (value_size < UINT32_MAX); 324 GNUNET_assert (tmit->mod->value_size < UINT32_MAX);
284 *full_value_size = value_size; 325 *full_value_size = tmit->mod->value_size;
285 *oper = op; 326 *oper = tmit->mod->oper;
286 name_size = strlen (name); 327 name_size = strlen (tmit->mod->name);
287 328
288 if (name_size + 1 + value_size <= *data_size) 329 if (name_size + 1 + tmit->mod->value_size <= *data_size)
289 { 330 {
290 *data_size = name_size + 1 + value_size; 331 *data_size = name_size + 1 + tmit->mod->value_size;
291 } 332 }
292 else 333 else
293 { 334 {
294 tmit->mod_value_size = value_size; 335 tmit->mod_value_size = tmit->mod->value_size;
295 value_size = *data_size - name_size - 1; 336 value_size = *data_size - name_size - 1;
296 tmit->mod_value_size -= value_size; 337 tmit->mod_value_size -= value_size;
297 tmit->mod_value = value + value_size; 338 tmit->mod_value = tmit->mod->value + value_size;
298 } 339 }
299 340
300 memcpy (data, name, name_size); 341 memcpy (data, tmit->mod->name, name_size);
301 ((char *)data)[name_size] = '\0'; 342 ((char *)data)[name_size] = '\0';
302 memcpy ((char *)data + name_size + 1, value, value_size); 343 memcpy ((char *)data + name_size + 1, tmit->mod->value, value_size);
303 } 344 }
304 else if (NULL != tmit->mod_value && 0 < tmit->mod_value_size) 345 else if (NULL != tmit->mod_value && 0 < tmit->mod_value_size)
305 { /* Modifier continuation */ 346 { /* Modifier continuation */
@@ -333,48 +374,6 @@ tmit_notify_mod (void *cls, uint16_t *data_size, void *data, uint8_t *oper,
333} 374}
334 375
335 376
336static int
337tmit_notify_data (void *cls, uint16_t *data_size, void *data)
338{
339 struct TransmitClosure *tmit = cls;
340 if (0 == tmit->data_count)
341 {
342 *data_size = 0;
343 return GNUNET_YES;
344 }
345
346 uint16_t size = strlen (tmit->data[tmit->n]);
347 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
348 "Transmit notify data: %u bytes available, "
349 "processing fragment %u/%u (size %u).\n",
350 *data_size, tmit->n + 1, tmit->data_count, size);
351 if (*data_size < size)
352 {
353 *data_size = 0;
354 GNUNET_assert (0);
355 return GNUNET_SYSERR;
356 }
357
358 if (GNUNET_YES != tmit->paused && 0 < tmit->data_delay[tmit->n])
359 {
360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmission paused.\n");
361 tmit->paused = GNUNET_YES;
362 GNUNET_SCHEDULER_add_delayed (
363 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
364 tmit->data_delay[tmit->n]),
365 &transmit_resume, tmit);
366 *data_size = 0;
367 return GNUNET_NO;
368 }
369 tmit->paused = GNUNET_NO;
370
371 *data_size = size;
372 memcpy (data, tmit->data[tmit->n], size);
373
374 return ++tmit->n < tmit->data_count ? GNUNET_NO : GNUNET_YES;
375}
376
377
378static void 377static void
379slave_join (); 378slave_join ();
380 379
@@ -388,7 +387,7 @@ join_decision_cb (void *cls, int is_admitted,
388 387
389 if (GNUNET_YES != is_admitted) 388 if (GNUNET_YES != is_admitted)
390 { /* First join request is refused, retry. */ 389 { /* First join request is refused, retry. */
391 //GNUNET_assert (1 == join_req_count); 390 GNUNET_assert (1 == join_req_count);
392 slave_join (); 391 slave_join ();
393 return; 392 return;
394 } 393 }
@@ -403,6 +402,7 @@ join_decision_cb (void *cls, int is_admitted,
403 "_abc", "abc def", 7); 402 "_abc", "abc def", 7);
404 GNUNET_ENV_environment_add (tmit->env, GNUNET_ENV_OP_ASSIGN, 403 GNUNET_ENV_environment_add (tmit->env, GNUNET_ENV_OP_ASSIGN,
405 "_abc_def", "abc def ghi", 11); 404 "_abc_def", "abc def ghi", 11);
405 tmit->mod = GNUNET_ENV_environment_head (tmit->env);
406 tmit->n = 0; 406 tmit->n = 0;
407 tmit->data[0] = "slave test"; 407 tmit->data[0] = "slave test";
408 tmit->data_count = 1; 408 tmit->data_count = 1;
@@ -421,8 +421,8 @@ join_request_cb (void *cls, const struct GNUNET_CRYPTO_EddsaPublicKey *slave_key
421 struct GNUNET_HashCode slave_key_hash; 421 struct GNUNET_HashCode slave_key_hash;
422 GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash); 422 GNUNET_CRYPTO_hash (slave_key, sizeof (*slave_key), &slave_key_hash);
423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 423 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
424 "Got join request from %s.\n", 424 "Got join request #%u from %s.\n",
425 GNUNET_h2s (&slave_key_hash)); 425 join_req_count, GNUNET_h2s (&slave_key_hash));
426 426
427 /* Reject first request */ 427 /* Reject first request */
428 int is_admitted = (0 < join_req_count++) ? GNUNET_YES : GNUNET_NO; 428 int is_admitted = (0 < join_req_count++) ? GNUNET_YES : GNUNET_NO;
@@ -493,6 +493,7 @@ master_transmit ()
493 name_cont, val_cont, 493 name_cont, val_cont,
494 GNUNET_PSYC_MODIFIER_MAX_PAYLOAD - name_cont_size 494 GNUNET_PSYC_MODIFIER_MAX_PAYLOAD - name_cont_size
495 + GNUNET_PSYC_MOD_CONT_MAX_PAYLOAD); 495 + GNUNET_PSYC_MOD_CONT_MAX_PAYLOAD);
496 tmit->mod = GNUNET_ENV_environment_head (tmit->env);
496 tmit->data[0] = "foo"; 497 tmit->data[0] = "foo";
497 tmit->data[1] = GNUNET_malloc (GNUNET_PSYC_DATA_MAX_PAYLOAD + 1); 498 tmit->data[1] = GNUNET_malloc (GNUNET_PSYC_DATA_MAX_PAYLOAD + 1);
498 for (i = 0; i < GNUNET_PSYC_DATA_MAX_PAYLOAD; i++) 499 for (i = 0; i < GNUNET_PSYC_DATA_MAX_PAYLOAD; i++)