aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-03-14 15:49:17 +0000
committerBart Polot <bart@net.in.tum.de>2014-03-14 15:49:17 +0000
commit8a2cf86b930408cecb00ddce0180d9707e11a802 (patch)
tree198728bdd2fcde2d0f2c4920194a5ffac52b55db /src
parent3bbb7996efbbf9fa82abfd71ee0e3c62d7181e35 (diff)
downloadgnunet-8a2cf86b930408cecb00ddce0180d9707e11a802.tar.gz
gnunet-8a2cf86b930408cecb00ddce0180d9707e11a802.zip
- refactor
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-mesh-profiler.c60
1 files changed, 14 insertions, 46 deletions
diff --git a/src/mesh/gnunet-mesh-profiler.c b/src/mesh/gnunet-mesh-profiler.c
index b95b6f4ab..e4e1cebef 100644
--- a/src/mesh/gnunet-mesh-profiler.c
+++ b/src/mesh/gnunet-mesh-profiler.c
@@ -354,26 +354,14 @@ finish_profiler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
354/** 354/**
355 * Transmit ready callback. 355 * Transmit ready callback.
356 * 356 *
357 * @param cls Closure (unused). 357 * @param cls Closure (peer for PING, NULL for PONG).
358 * @param size Size of the tranmist buffer.
359 * @param buf Pointer to the beginning of the buffer.
360 *
361 * @return Number of bytes written to buf.
362 */
363static size_t
364tmt_ping_rdy (void *cls, size_t size, void *buf);
365
366/**
367 * Transmit ready callback.
368 *
369 * @param cls Closure (unused).
370 * @param size Size of the tranmist buffer. 358 * @param size Size of the tranmist buffer.
371 * @param buf Pointer to the beginning of the buffer. 359 * @param buf Pointer to the beginning of the buffer.
372 * 360 *
373 * @return Number of bytes written to buf. 361 * @return Number of bytes written to buf.
374 */ 362 */
375static size_t 363static size_t
376tmt_pong_rdy (void *cls, size_t size, void *buf); 364tmt_rdy (void *cls, size_t size, void *buf);
377 365
378 366
379/** 367/**
@@ -396,7 +384,7 @@ ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
396 384
397 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO, 385 GNUNET_MESH_notify_transmit_ready (peer->ch, GNUNET_NO,
398 GNUNET_TIME_UNIT_FOREVER_REL, 386 GNUNET_TIME_UNIT_FOREVER_REL,
399 size_payload, &tmt_ping_rdy, peer); 387 size_payload, &tmt_rdy, peer);
400} 388}
401 389
402/** 390/**
@@ -410,19 +398,19 @@ pong (struct GNUNET_MESH_Channel *channel)
410{ 398{
411 GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO, 399 GNUNET_MESH_notify_transmit_ready (channel, GNUNET_NO,
412 GNUNET_TIME_UNIT_FOREVER_REL, 400 GNUNET_TIME_UNIT_FOREVER_REL,
413 size_payload, &tmt_pong_rdy, NULL); 401 size_payload, &tmt_rdy, NULL);
414} 402}
415 403
416 404
417/** 405/**
418 * Transmit ready callback 406 * Transmit ready callback
419 * 407 *
420 * @param cls Closure (unused). 408 * @param cls Closure (peer for PING, NULL for PONG).
421 * @param size Size of the buffer we have. 409 * @param size Size of the buffer we have.
422 * @param buf Buffer to copy data to. 410 * @param buf Buffer to copy data to.
423 */ 411 */
424size_t 412static size_t
425tmt_ping_rdy (void *cls, size_t size, void *buf) 413tmt_rdy (void *cls, size_t size, void *buf)
426{ 414{
427 struct MeshPeer *peer = (struct MeshPeer *) cls; 415 struct MeshPeer *peer = (struct MeshPeer *) cls;
428 struct GNUNET_MessageHeader *msg = buf; 416 struct GNUNET_MessageHeader *msg = buf;
@@ -432,15 +420,20 @@ tmt_ping_rdy (void *cls, size_t size, void *buf)
432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n"); 420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tmt_rdy called, filling buffer\n");
433 if (size < size_payload || NULL == buf) 421 if (size < size_payload || NULL == buf)
434 { 422 {
435 GNUNET_break (ok >= ok_goal - 2); 423 GNUNET_break (0);
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437 "size %u, buf %p, data_sent %u, data_received %u\n", 425 "size %u, buf %p, data_sent %u, data_received %u\n",
438 size, buf, peer->data_sent, peer->data_received); 426 size, buf, peer->data_sent, peer->data_received);
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok %u, ok goal %u\n", ok, ok_goal);
440 427
441 return 0; 428 return 0;
442 } 429 }
443 msg->size = htons (size); 430 msg->size = htons (size);
431 if (NULL == peer)
432 {
433 msg->type = htons (PONG);
434 return sizeof (*msg);
435 }
436
444 msg->type = htons (PING); 437 msg->type = htons (PING);
445 data = (uint32_t *) &msg[1]; 438 data = (uint32_t *) &msg[1];
446 *data = htonl (peer->data_sent); 439 *data = htonl (peer->data_sent);
@@ -464,31 +457,6 @@ tmt_ping_rdy (void *cls, size_t size, void *buf)
464 457
465 458
466/** 459/**
467 * Transmit ready callback
468 *
469 * @param cls Closure (unused).
470 * @param size Size of the buffer we have.
471 * @param buf Buffer to copy data to.
472 */
473size_t
474tmt_pong_rdy (void *cls, size_t size, void *buf)
475{
476 struct GNUNET_MessageHeader *msg = buf;
477 size_t size_payload = sizeof (struct GNUNET_MessageHeader);
478
479 if (size < size_payload || NULL == buf)
480 {
481 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Cannot send PONG\n");
482 return 0;
483 }
484 msg->size = htons (size_payload);
485 msg->type = htons (PONG);
486
487 return size_payload;
488}
489
490
491/**
492 * Function is called whenever a PING message is received. 460 * Function is called whenever a PING message is received.
493 * 461 *
494 * @param cls closure (peer #, set from GNUNET_MESH_connect) 462 * @param cls closure (peer #, set from GNUNET_MESH_connect)