- 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;
-}
-
-
-/**
- * Called to open a connection to the peer's ATS performance
- *
- * @param cls peer context
- * @param cfg configuration of the peer to connect to; will be available until
- * GNUNET_TESTBED_operation_done() is called on the operation returned
- * from GNUNET_TESTBED_service_connect()
- * @return service handle to return in 'op_result', NULL on error
- */
-static void *
-core_connect_adapter (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct BenchmarkPeer *peer = cls;
-
- static const struct GNUNET_CORE_MessageHandler handlers[] = {
- {&core_handle_ping, TEST_MESSAGE_TYPE_PING, 0},
- {&core_handle_pong, TEST_MESSAGE_TYPE_PONG, 0},
- {NULL, 0, 0}
- };
-
- peer->ch = GNUNET_CORE_connect(cfg, peer, NULL,
- core_connect_cb, core_disconnect_cb,
- NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
- if (NULL == peer->ch)
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to create core connection \n");
- return peer->ch;
-}