void
GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
      "Slave [%u]: Received PING from [%u], sending PONG\n", p->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 == top->test_core)
  {
    GNUNET_assert (NULL == p->cth);

    p->cth
      = GNUNET_CORE_notify_transmit_ready (p->me->ch, GNUNET_NO,
                                           GNUNET_CORE_PRIO_BEST_EFFORT,
                                           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 (p->me->th, &p->dest->id,
        TEST_MESSAGE_SIZE, GNUNET_TIME_UNIT_MINUTES, &comm_send_pong_ready,
        p);
  }
}
/**
 * Notify of all peer1's peers, once peer 2 is found, schedule connect
 * to peer two for message send.
 *
 * @param cls closure
 * @param peer peer identity this notification is about
 * @param atsi performance data for the connection
 * @param atsi_count number of ATS information included
 */
static void
connect_notify_peer2 (void *cls, const struct GNUNET_PeerIdentity *peer,
                      const struct GNUNET_ATS_Information *atsi,
                      unsigned int atsi_count)
{
  struct TestMessageContext *pos = cls;

  if (0 == memcmp (&pos->peer1->id, peer, sizeof (struct GNUNET_PeerIdentity)))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Core connection from `%s' to `%4s' verfied, sending message!\n",
                GNUNET_i2s (&pos->peer2->id), GNUNET_h2s (&peer->hashPubKey));
    if (NULL ==
        GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
                                           TIMEOUT, &pos->peer2->id,
                                           sizeof (struct GNUNET_TestMessage),
                                           &transmit_ready, pos))
    {
      /* This probably shouldn't happen, but it does (timing issue?) */
      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
                  GNUNET_i2s (&pos->peer2->id));
      transmit_ready_failed++;
      total_other_expected_messages--;
    }
    else
    {
      transmit_ready_scheduled++;
    }
  }
}
static void
comm_schedule_send (void *cls,
                    const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct BenchmarkPartner *p = cls;

  p->tg->send_task = GNUNET_SCHEDULER_NO_TASK;
  p->last_message_sent = GNUNET_TIME_absolute_get();
  if (GNUNET_YES == top->test_core)
  {
    p->cth = GNUNET_CORE_notify_transmit_ready (p->me->ch, GNUNET_NO,
                                                GNUNET_CORE_PRIO_BEST_EFFORT,
                                                GNUNET_TIME_UNIT_MINUTES,
                                                &p->dest->id,
                                                TEST_MESSAGE_SIZE,
                                                &send_ping_ready_cb, p);
  }
  else
  {
    p->tth = GNUNET_TRANSPORT_notify_transmit_ready (p->me->th,
                                                     &p->dest->id,
                                                     TEST_MESSAGE_SIZE,
                                                     GNUNET_TIME_UNIT_MINUTES,
                                                     &send_ping_ready_cb, p);
  }
}
static void
init_notify_peer2 (void *cls, struct GNUNET_CORE_Handle *server,
                   const struct GNUNET_PeerIdentity *my_identity)
{
  struct TestMessageContext *pos = cls;

  total_server_connections++;

  pos->peer2connected = GNUNET_YES;
  if (pos->peer1notified == GNUNET_YES) /* Peer 1 has been notified of connection to peer 2 */
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
                GNUNET_i2s (my_identity),
                GNUNET_h2s (&pos->peer1->id.hashPubKey));
    if (NULL ==
        GNUNET_CORE_notify_transmit_ready (pos->peer1handle, GNUNET_YES, 0,
                                           TIMEOUT, &pos->peer2->id,
                                           sizeof (struct GNUNET_TestMessage),
                                           &transmit_ready, pos))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
                  GNUNET_i2s (&pos->peer2->id));
      transmit_ready_failed++;
    }
    else
    {
      transmit_ready_scheduled++;
    }
  }
}
Exemple #5
0
/**
 * Signature of functions implementing the
 * sending functionality of a message queue.
 *
 * @param mq the message queue
 * @param msg the message to send
 * @param impl_state state of the implementation
 */
static void
core_mq_send (struct GNUNET_MQ_Handle *mq,
              const struct GNUNET_MessageHeader *msg,
              void *impl_state)
{
  struct CoreMQState *mqs = impl_state;
  GNUNET_assert (NULL == mqs->th);
  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "core-mq", "Sending queued message (size %u)\n",
             ntohs (msg->size));
  mqs->th = GNUNET_CORE_notify_transmit_ready (mqs->core, GNUNET_YES, 0,
                                               GNUNET_TIME_UNIT_FOREVER_REL,
                                               &mqs->target,
                                               ntohs (msg->size), core_mq_ntr, mq);
}
static size_t
transmit_ready (void *cls, size_t size, void *buf)
{
  char *cbuf = buf;
  struct TestMessage hdr;
  unsigned int ret;

  p1.nth = NULL;
  GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
  if (buf == NULL)
  {
    if ((p1.ch != NULL) && (p1.connect_status == 1))
      GNUNET_break (NULL !=
                    (p1.nth =
                     GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO,
                                                        GNUNET_CORE_PRIO_BEST_EFFORT,
                                                        FAST_TIMEOUT, &p2.id,
                                                        MESSAGESIZE,
                                                        &transmit_ready, &p1)));
    return 0;
  }
  GNUNET_assert (tr_n < TOTAL_MSGS);
  ret = 0;
  GNUNET_assert (size >= MESSAGESIZE);
  GNUNET_assert (buf != NULL);
  cbuf = buf;
  do
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Sending message %u of size %u at offset %u\n", tr_n,
                MESSAGESIZE, ret);
    hdr.header.size = htons (MESSAGESIZE);
    hdr.header.type = htons (MTYPE);
    hdr.num = htonl (tr_n);
    memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
    ret += sizeof (struct TestMessage);
    memset (&cbuf[ret], tr_n, MESSAGESIZE - sizeof (struct TestMessage));
    ret += MESSAGESIZE - sizeof (struct TestMessage);
    tr_n++;
    if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
      break;                    /* sometimes pack buffer full, sometimes not */
  }
  while (size - ret >= MESSAGESIZE);
  GNUNET_SCHEDULER_cancel (err_task);
  err_task =
      GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);

  total_bytes_sent += ret;
  return ret;
}
static void
connect_cb (void *cls, const struct GNUNET_PeerIdentity *peer)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connected to peer %s.\n",
              GNUNET_i2s (peer));
  if (0 == memcmp (peer, &myself, sizeof (struct GNUNET_PeerIdentity)))
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Connected to myself; sending message!\n");
    GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES, 0,
                                       GNUNET_TIME_UNIT_FOREVER_REL, peer,
                                       sizeof (struct GNUNET_MessageHeader),
                                       send_message, NULL);
  }
}
/**
 * Method called whenever a given peer connects.
 *
 * @param cls closure
 * @param peer peer identity this notification is about
 */
static void
connect_handler (void *cls,
                 const struct GNUNET_PeerIdentity *peer)
{
  size_t size;
  struct GNUNET_CORE_TransmitHandle *th;

  if (! advertising)
    return;
  if (NULL == hostlist_uri)
    return;
  size = strlen (hostlist_uri) + 1;
  if (size + sizeof (struct GNUNET_MessageHeader) >=
      GNUNET_SERVER_MAX_MESSAGE_SIZE)
  {
    GNUNET_break (0);
    return;
  }
  size += sizeof (struct GNUNET_MessageHeader);
  if (NULL == core)
  {
    GNUNET_break (0);
    return;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Asked CORE to transmit advertisement message with a size of %u bytes to peer `%s'\n",
              size,
              GNUNET_i2s (peer));
  if (NULL ==
      (th = GNUNET_CORE_notify_transmit_ready (core, GNUNET_YES,
                                               GNUNET_CORE_PRIO_BEST_EFFORT,
                                               GNUNET_ADV_TIMEOUT,
                                               peer,
                                               size,
                                               &adv_transmit_ready,
                                               (void *) peer)) )
  {
    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                _("Advertisement message could not be queued by core\n"));
  }
  GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multipeermap_put (advertisements,
                                                    peer,
                                                    th,
                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
}
Exemple #9
0
/**
 * @brief This function initiates the transmission of the next message.
 *
 * \latexonly \\ \\ \endlatexonly
 * \em Detailed \em description \n
 * This function initiates the transmission of the next message. In order to do that it dequeues the message from the
 * output queue and calls the appropriate GNUnet function for the transmission of the message. The function is implemented as a GNUnet task; this is done in order to decouple it from the
 * transmit_ready() function call (see above).
 *
 * @param cls the GNUnet closure (not used)
 * @param tc the GNUnet task context (not used)
 */
static void gnunet_search_flooding_transmit_next(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) {
	if(!queue_get_length(gnunet_search_flooding_message_queue))
		return;

	struct gnunet_search_flooding_queued_message *msg = (struct gnunet_search_flooding_queued_message*) queue_dequeue(
			gnunet_search_flooding_message_queue);

	struct GNUNET_TIME_Relative max_delay = GNUNET_TIME_relative_get_minute_();
	struct GNUNET_TIME_Relative gct = GNUNET_TIME_relative_add(max_delay, GNUNET_TIME_relative_get_second_());

	GNUNET_CORE_notify_transmit_ready(gnunet_search_flooding_core_handle, 0, 0, max_delay, msg->peer, msg->size,
			&gnunet_search_flooding_notify_transmit_ready, msg->buffer);

	/*
	 * Todo: Save and free...
	 */
	GNUNET_SCHEDULER_add_delayed(gct, &gnunet_search_flooding_queued_message_free_task, msg);
}
static int
process_mtype (void *cls, const struct GNUNET_PeerIdentity *peer,
               const struct GNUNET_MessageHeader *message)
{
  static int n;
  const struct TestMessage *hdr;

  hdr = (const struct TestMessage *) message;
  if (MTYPE != ntohs (message->type))
    return GNUNET_SYSERR;
  if (ntohs (message->size) != MESSAGESIZE)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Expected message %u of size %u, got %u bytes of message %u\n",
                n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num));
    GNUNET_SCHEDULER_cancel (err_task);
    err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
    return GNUNET_SYSERR;
  }
  if (ntohl (hdr->num) != n)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Expected message %u of size %u, got %u bytes of message %u\n",
                n, MESSAGESIZE, ntohs (message->size), ntohl (hdr->num));
    GNUNET_SCHEDULER_cancel (err_task);
    err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
    return GNUNET_SYSERR;
  }
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got message %u of size %u\n",
              ntohl (hdr->num), ntohs (message->size));
  n++;
  if (0 == (n % 10))
    FPRINTF (stderr, "%s",  ".");


  if (running == GNUNET_YES)
    GNUNET_break (NULL !=
                  GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO,
                                                     GNUNET_CORE_PRIO_BEST_EFFORT,
                                                     FAST_TIMEOUT, &p2.id,
                                                     MESSAGESIZE,
                                                     &transmit_ready, &p1));
  return GNUNET_OK;
}
static void
schedule_transmisson (struct NodeComCtx *e_ctx)
{
  if (NULL != e_ctx->n->cth)
    return;

  e_ctx->n->cth = GNUNET_CORE_notify_transmit_ready (ch, GNUNET_NO,
                                                     GNUNET_CORE_PRIO_BEST_EFFORT,
                                                     FAST_TIMEOUT,
						     &e_ctx->n->id, e_ctx->size,
						     transmit_read_wrapper, e_ctx);
  if (NULL == e_ctx->n->cth)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
		_("Cannot send message to peer `%s' for experiment `%s'\n"),
		GNUNET_i2s(&e_ctx->n->id), e_ctx->e->name);
    GNUNET_free (e_ctx);
  }
}
/**
 * Method called whenever a given peer connects.
 *
 * @param cls closure
 * @param peer peer identity this notification is about
 * @param atsi performance data for the connection
 */
static void
connect_notify_peers (void *cls, const struct GNUNET_PeerIdentity *peer,
                      const struct GNUNET_ATS_Information *atsi)
{
  struct TestMessageContext *pos = cls;

  if (0 == memcmp (peer, &pos->peer2->id, sizeof (struct GNUNET_PeerIdentity)))
  {
    pos->peer1notified = GNUNET_YES;
#if VERBOSE > 1
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Peer `%s' notified of connection to peer `%s'\n",
                GNUNET_i2s (&pos->peer1->id), GNUNET_h2s (&peer->hashPubKey));
#endif
  }
  else
    return;

  if (pos->peer2connected == GNUNET_YES)        /* Already connected and notified of connection, send message! */
  {
#if VERBOSE > 1
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Scheduling message send to peer `%s' from peer `%s' (init_notify_peer2)\n",
                GNUNET_i2s (&pos->peer2->id),
                GNUNET_h2s (&pos->peer1->id.hashPubKey));
#endif
    if (NULL ==
        GNUNET_CORE_notify_transmit_ready (pos->peer1handle, 0, timeout,
                                           &pos->peer2->id,
                                           sizeof (struct GNUNET_TestMessage),
                                           &transmit_ready, pos))
    {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
                  GNUNET_i2s (&pos->peer2->id));
      transmit_ready_failed++;
    }
    else
    {
      transmit_ready_scheduled++;
    }
  }
}
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer,
                const struct GNUNET_ATS_Information *atsi,
                unsigned int atsi_count)
{
    struct PeerContext *pc = cls;

    if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
        return;
    GNUNET_assert (pc->connect_status == 0);
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Encrypted connection established to peer `%4s'\n",
                GNUNET_i2s (peer));
    if (GNUNET_SCHEDULER_NO_TASK != con_task)
    {
        GNUNET_SCHEDULER_cancel (con_task);
        con_task = GNUNET_SCHEDULER_NO_TASK;
    }
    pc->connect_status = 1;
    if (pc == &p1)
    {
        GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                    "Asking core (1) for transmission to peer `%4s'\n",
                    GNUNET_i2s (&p2.id));
        if (NULL ==
                GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_YES, 0,
                        GNUNET_TIME_relative_multiply
                        (GNUNET_TIME_UNIT_SECONDS, 145),
                        &p2.id,
                        sizeof (struct GNUNET_MessageHeader),
                        &transmit_ready, &p1))
        {
            GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                        "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
                        GNUNET_i2s (&p2.id));
        }
    }
}
static void
connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer)
{
  struct PeerContext *pc = cls;

  if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity)))
    return;                     /* loopback */
  GNUNET_assert (pc->connect_status == 0);
  pc->connect_status = 1;
  if (pc == &p1)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Encrypted connection established to peer `%4s'\n",
                GNUNET_i2s (peer));
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Asking core (1) for transmission to peer `%4s'\n",
                GNUNET_i2s (&p2.id));
    if (err_task != NULL)
      GNUNET_SCHEDULER_cancel (err_task);
    err_task =
        GNUNET_SCHEDULER_add_delayed (TIMEOUT, &terminate_task_error, NULL);
    start_time = GNUNET_TIME_absolute_get ();
    running = GNUNET_YES;
    measure_task =
        GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, &measurement_stop,
                                      NULL);

    GNUNET_break (NULL !=
                  (p1.nth =
                   GNUNET_CORE_notify_transmit_ready (p1.ch, GNUNET_NO,
                                                      GNUNET_CORE_PRIO_BEST_EFFORT,
                                                      TIMEOUT, &p2.id,
                                                      MESSAGESIZE,
                                                      &transmit_ready, &p1)));
  }
}
/**
 * Calculate when we would like to send the next HELLO to this
 * peer and ask for it.
 *
 * @param cls for which peer to schedule the HELLO
 * @param tc task context
 */
static void
schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct Peer *pl = cls;
  struct FindAdvHelloContext fah;
  size_t next_want;
  struct GNUNET_TIME_Relative delay;

  pl->hello_delay_task = GNUNET_SCHEDULER_NO_TASK;
  GNUNET_assert (GNUNET_YES == pl->is_connected);
  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
    return;                     /* we're out of here */
  if (pl->hello_req != NULL)
    return;                     /* did not finish sending the previous one */
  /* find applicable HELLOs */
  fah.peer = pl;
  fah.result = NULL;
  fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
  fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
  GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah);
  pl->hello_delay_task =
      GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl);
  if (fah.result == NULL)
    return;
  next_want = GNUNET_HELLO_size (fah.result->hello);
  delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed);
  if (delay.rel_value == 0)
  {
    /* now! */
    pl->hello_req =
        GNUNET_CORE_notify_transmit_ready (handle, GNUNET_YES, 0,
                                           GNUNET_CONSTANTS_SERVICE_TIMEOUT,
                                           &pl->pid, next_want,
                                           &hello_advertising_ready, pl);
  }
}