- id = GNUNET_strdup (GNUNET_i2s (&p->id));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "%s disconnected from %s \n", id, GNUNET_i2s (peer));
- GNUNET_assert (p->core_connections > 0);
- p->core_connections --;
-
- if ((GNUNET_YES == state.benchmarking) &&
- ((GNUNET_YES == p->master) || (GNUNET_YES == t->master)))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
- }
-
- GNUNET_free (id);
-}
-
-static size_t
-core_send_echo_queued_ready (void *cls, size_t size, void *buf);
-
-static size_t
-core_send_echo_ready (void *cls, size_t size, void *buf)
-{
- static char msgbuf[TEST_MESSAGE_SIZE];
- struct BenchmarkPeer *bp = cls;
- struct GNUNET_MessageHeader *msg;
-
- bp->cth = NULL;
-
- msg = (struct GNUNET_MessageHeader *) &msgbuf;
- memset (&msgbuf, 'a', TEST_MESSAGE_SIZE);
- msg->type = htons (TEST_MESSAGE_TYPE_PONG);
- msg->size = htons (TEST_MESSAGE_SIZE);
- memcpy (buf, msg, TEST_MESSAGE_SIZE);
-
- /* send echo */
- if (NULL != bp->p_head)
- bp->cth = GNUNET_CORE_notify_transmit_ready (bp->ch,
- GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
- &bp->p_head->target,
- TEST_MESSAGE_SIZE, &core_send_echo_queued_ready, bp);
-
- return TEST_MESSAGE_SIZE;
-}
-
-static size_t
-core_send_echo_queued_ready (void *cls, size_t size, void *buf)
-{
- struct BenchmarkPeer *bp = cls;
- struct PendingMessages *pm;
- GNUNET_assert (NULL != bp->p_head);
-
- pm = bp->p_head;
- GNUNET_CONTAINER_DLL_remove (bp->p_head, bp->p_tail, pm);
- GNUNET_free (pm);
-
-
- return core_send_echo_ready (cls, size, buf);
-
-}
-
-
-static int
-core_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPeer *remote;
- struct PendingMessages *pm;
-
- remote = find_peer (other);
-
- if (NULL == remote)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (NULL != me->cth)
- {
- pm = GNUNET_malloc (sizeof (struct PendingMessages));
- pm->target = (*other);
- GNUNET_CONTAINER_DLL_insert_tail (me->p_head, me->p_tail, pm);
- return GNUNET_OK;
- }
-
- if (GNUNET_NO == remote->master)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
-
- me->messages_received ++;
- /* send echo */
- me->cth = GNUNET_CORE_notify_transmit_ready (me->ch,
- GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
- &remote->id,
- TEST_MESSAGE_SIZE, &core_send_echo_ready, me);
- return GNUNET_OK;
-}
-
-static int
-core_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPeer *remote;
- struct BenchmarkPeer *next;
-
- remote = find_peer (other);
-
- if (NULL == remote)
- {
- GNUNET_break (0);
- return GNUNET_SYSERR;
- }
-
- if (NULL != me->cth)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
-
- if (GNUNET_YES == remote->master)
- {
- GNUNET_break (0);
- return GNUNET_OK;
- }
- me->messages_received ++;
- next = get_next (me);
- if (0 == memcmp(&remote->id, &me->destination->id, sizeof (struct GNUNET_PeerIdentity)))
- me->partner_msg = GNUNET_YES;
- me->cth = GNUNET_CORE_notify_transmit_ready (me->ch,
- GNUNET_NO, 0, GNUNET_TIME_UNIT_MINUTES,
- &next->id,
- TEST_MESSAGE_SIZE, &core_send_ready, me);
-
- return GNUNET_OK;
-}