- if (NULL == (p = find_partner (me, peer)))
- return;
-
- id = GNUNET_strdup (GNUNET_i2s (&me->id));
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s disconnected from %s \n", id,
- GNUNET_i2s (peer));
- GNUNET_assert(me->core_connections > 0);
- me->core_connections--;
-
- if ((GNUNET_YES == state.benchmarking)
- && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master)))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "%s disconnected from %s while benchmarking \n", id, GNUNET_i2s (peer));
- if (NULL != p->tth)
- {
- GNUNET_TRANSPORT_notify_transmit_ready_cancel (p->tth);
- p->tth = NULL;
- }
- if (NULL != p->cth)
- {
- GNUNET_CORE_notify_transmit_ready_cancel (p->cth);
- p->cth = NULL;
- }
- }
- GNUNET_free(id);
-}
-
-static size_t
-comm_send_pong_ready (void *cls, size_t size, void *buf)
-{
- static char msgbuf[TEST_MESSAGE_SIZE];
- struct BenchmarkPartner *p = cls;
- struct GNUNET_MessageHeader *msg;
-
- if (GNUNET_YES == test_core)
- p->cth = NULL;
- else
- p->tth = NULL;
-
- p->messages_sent++;
- p->bytes_sent += TEST_MESSAGE_SIZE;
- p->me->total_messages_sent++;
- p->me->total_bytes_sent += TEST_MESSAGE_SIZE;
-
- 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);
-
- return TEST_MESSAGE_SIZE;
-}
-
-static int
-comm_handle_ping (void *cls, const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
-
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPartner *p = NULL;
-
- if (NULL == (p = find_partner(me, other)))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Slave [%u]: Received PING from [%u], sending PONG\n", me->no,
- p->dest->no);
-
- p->messages_received++;
- p->bytes_received += TEST_MESSAGE_SIZE;
- p->me->total_messages_received++;
- p->me->total_bytes_received += TEST_MESSAGE_SIZE;
-
- if (GNUNET_YES == test_core)
- {
- GNUNET_assert (NULL == p->cth);
- p->cth = GNUNET_CORE_notify_transmit_ready (me->ch, GNUNET_NO, 0,
- GNUNET_TIME_UNIT_MINUTES, &p->dest->id, TEST_MESSAGE_SIZE,
- &comm_send_pong_ready, p);
- }
- else
- {
- GNUNET_assert (NULL == p->tth);
- p->tth = GNUNET_TRANSPORT_notify_transmit_ready (me->th, &p->dest->id,
- TEST_MESSAGE_SIZE, 0, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
- p);
- }
- return GNUNET_OK;
-}
-
-static int
-comm_handle_pong (void *cls, const struct GNUNET_PeerIdentity *other,
- const struct GNUNET_MessageHeader *message)
-{
- struct BenchmarkPeer *me = cls;
- struct BenchmarkPartner *p = NULL;
-
- if (NULL == (p = find_partner (me, other)))
- {
- GNUNET_break(0);
- return GNUNET_SYSERR;
- }
-
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "Master [%u]: Received PONG from [%u], next message\n", me->no,
- p->dest->no);
-
- p->messages_received++;
- p->bytes_received += TEST_MESSAGE_SIZE;
- p->me->total_messages_received++;
- p->me->total_bytes_received += TEST_MESSAGE_SIZE;
- p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent,
- GNUNET_TIME_absolute_get()).rel_value_us;
-
- comm_schedule_send (p);
- return GNUNET_OK;
-}
-
-static void *
-core_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct BenchmarkPeer *me = cls;
-
- static const struct GNUNET_CORE_MessageHandler handlers[] = { {
- &comm_handle_ping, TEST_MESSAGE_TYPE_PING, 0 }, { &comm_handle_pong,
- TEST_MESSAGE_TYPE_PONG, 0 }, { NULL, 0, 0 } };
-
- me->ch = GNUNET_CORE_connect (cfg, me, NULL, comm_connect_cb,
- comm_disconnect_cb, NULL, GNUNET_NO, NULL, GNUNET_NO, handlers);
- if (NULL == me->ch)
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create core connection \n");
- return me->ch;
-}
-
-static void
-core_disconnect_adapter (void *cls, void *op_result)
-{
- struct BenchmarkPeer *me = cls;
-
- GNUNET_CORE_disconnect (me->ch);
- me->ch = NULL;
-}
-
-static void
-comm_connect_completion_cb (void *cls, struct GNUNET_TESTBED_Operation *op,
- void *ca_result, const char *emsg)
-{
- static int comm_done = 0;
- if ((NULL != emsg) || (NULL == ca_result))
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initialization failed, shutdown\n"));
- GNUNET_break(0);
- if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
- GNUNET_SCHEDULER_cancel (shutdown_task);
- shutdown_task = GNUNET_SCHEDULER_add_now (do_shutdown, NULL );
- return;
- }
- comm_done++;
-
- if (comm_done == num_slaves + num_masters)
- {
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Connected to all %s services\n",
- (GNUNET_YES == test_core) ? "CORE" : "TRANSPORT");
- state.connected_COMM_service = GNUNET_YES;
- GNUNET_SCHEDULER_add_now (&do_connect_peers, NULL );
- }
-}
-
-static void
-transport_recv_cb (void *cls,
- const struct GNUNET_PeerIdentity * peer,
- const struct GNUNET_MessageHeader * message)
-{
- if (TEST_MESSAGE_SIZE != ntohs (message->size) ||
- (TEST_MESSAGE_TYPE_PING != ntohs (message->type) &&
- TEST_MESSAGE_TYPE_PONG != ntohs (message->type)))
- {
- return;
- }
- if (TEST_MESSAGE_TYPE_PING == ntohs (message->type))
- comm_handle_ping (cls, peer, message);
-
- if (TEST_MESSAGE_TYPE_PONG == ntohs (message->type))
- comm_handle_pong (cls, peer, message);
-}
-
-
-static void *
-transport_connect_adapter (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
-{
- struct BenchmarkPeer *me = cls;
-
- me->th = GNUNET_TRANSPORT_connect (cfg, &me->id, me, &transport_recv_cb,
- &comm_connect_cb, &comm_disconnect_cb);
- if (NULL == me->th)
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Failed to create transport connection \n");
- return me->th;
-}
-
-static void
-transport_disconnect_adapter (void *cls, void *op_result)
-{
- struct BenchmarkPeer *me = cls;
-
- GNUNET_TRANSPORT_disconnect (me->th);
- me->th = NULL;