static void
try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  connect_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect,
                                    NULL);
  GNUNET_TRANSPORT_try_connect (p1.th, &p2.id, NULL, NULL); /*FIXME TRY_CONNECT change */
  GNUNET_TRANSPORT_try_connect (p2.th, &p1.id, NULL, NULL); /*FIXME TRY_CONNECT change */
}
Exemplo n.º 2
0
static void
try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct ConnectingContext *cc = cls;
  struct PeerContext *p1 = cc->p1;
  struct PeerContext *p2 = cc->p2;

  cc->tct = GNUNET_SCHEDULER_NO_TASK;
  if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
    return;

  GNUNET_assert (cc != NULL);
  GNUNET_assert (cc->p1 != NULL);
  GNUNET_assert (cc->p2 != NULL);

  char *p2_s = GNUNET_strdup (GNUNET_i2s (&p2->id));

  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "transport-testing",
                   "Asking peer %u (`%s') to connect peer %u (`%s'), providing HELLO with %u bytes\n",
                   p1->no, GNUNET_i2s (&p1->id), p2->no, p2_s,
                   GNUNET_HELLO_size (cc->p2->hello));
  GNUNET_free (p2_s);

  GNUNET_TRANSPORT_offer_hello (cc->th_p1,
                                (const struct GNUNET_MessageHeader *) cc->
                                p2->hello, NULL, NULL);
  GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */

  cc->tct =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &try_connect, cc);
}
static void
reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct PeerContext *p = cls;

  reconnect_task = GNUNET_SCHEDULER_NO_TASK;
  GNUNET_TRANSPORT_try_connect (p1->th, &p2->id, NULL, NULL); /*FIXME TRY_CONNECT change */
  reconnect_task =
      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &reconnect, p);
}
Exemplo n.º 4
0
static void
connect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
    if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
    {
        con_task = GNUNET_SCHEDULER_NO_TASK;
        return;
    }
    con_task =
        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &connect_task,
                                      NULL);
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Asking transport (1) to connect to peer `%4s'\n",
                GNUNET_i2s (&p2.id));
    GNUNET_TRANSPORT_try_connect (p1.th, &p2.id, NULL, NULL); /*FIXME TRY_CONNECT change */
}
Exemplo n.º 5
0
void try_connect_cb (void *cls,
                     const int result)
{
  static int retries = 0;
  if (GNUNET_OK == result)
  {
      tc_handle = NULL;
      return;
  }
  retries ++;
  if (retries < 10)
    tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL);
  else
  {
    FPRINTF (stderr, "%s", _("Failed to send connect request to transport service\n"));
    if (GNUNET_SCHEDULER_NO_TASK != end)
      GNUNET_SCHEDULER_cancel (end);
    ret = 1;
    end = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
    return;
  }
}
/**
 * Try to connect to the specified peer.
 *
 * @param pos peer to connect to
 */
static void
attempt_connect (struct Peer *pos)
{
  struct GNUNET_TIME_Relative rem;

  if ((connection_count >= target_connection_count) &&
      (friend_count >= minimum_friend_count))
    return;
  if (GNUNET_YES == pos->is_connected)
    return;
  if (GNUNET_OK != is_connection_allowed (pos))
    return;
  if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0)
    return;
  if (GNUNET_YES == pos->is_friend)
    rem = GREYLIST_AFTER_ATTEMPT_FRIEND;
  else
    rem = GREYLIST_AFTER_ATTEMPT;
  rem = GNUNET_TIME_relative_multiply (rem, connection_count);
  rem = GNUNET_TIME_relative_divide (rem, target_connection_count);
  if (pos->connect_attempts > 30)
    pos->connect_attempts = 30;
  rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts));
  rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN);
  rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX);
  pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem);
  if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
    GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
  pos->greylist_clean_task =
      GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking  to connect to `%s'\n",
              GNUNET_i2s (&pos->pid));
  GNUNET_STATISTICS_update (stats,
                            gettext_noop
                            ("# connect requests issued to transport"), 1,
                            GNUNET_NO);
  GNUNET_TRANSPORT_try_connect (transport, &pos->pid, NULL, NULL); /*FIXME TRY_CONNECT change */
}
Exemplo n.º 7
0
static void
testservice_task (void *cls,
                  const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  int counter = 0;
  ret = 1;

  if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
  {
      FPRINTF (stderr, _("Service `%s' is not running\n"), "transport");
      return;
  }

  if ((NULL != cpid) && (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (cpid, &pid.hashPubKey)))
  {
      FPRINTF (stderr, _("Failed to parse peer identity `%s'\n"), cpid);
      return;
  }

  counter = benchmark_send + benchmark_receive + iterate_connections +
            monitor_connections + monitor_connects + try_connect;

  if (1 < counter)
  {
    FPRINTF (stderr, _("Multiple operations given. Please choose only one operation: %s, %s, %s, %s, %s, %s\n"),
             "connect", "benchmark send", "benchmark receive", "information", "monitor", "events");
    return;
  }
  if (0 == counter)
  {
    FPRINTF (stderr, _("No operation given. Please choose one operation: %s, %s, %s, %s, %s, %s\n"),
             "connect", "benchmark send", "benchmark receive", "information", "monitor", "events");
    return;
  }

  if (try_connect) /* -C: Connect to peer */
  {
    if (NULL == cpid)
    {
      FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
               "-C", "-p");
      ret = 1;
      return;
    }
    handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
                                       &notify_receive,
                                       &notify_connect,
                                       &notify_disconnect);
    if (NULL == handle)
    {
        FPRINTF (stderr, "%s", _("Failed to connect to transport service\n"));
        ret = 1;
        return;
    }
    tc_handle = GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL);
    if (NULL == tc_handle)
    {
        FPRINTF (stderr, "%s", _("Failed to send request to transport service\n"));
        ret = 1;
        return;
    }
    op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
                                               &operation_timeout, NULL);

  }
  else if (benchmark_send) /* -s: Benchmark sending */
  {
    if (NULL == cpid)
    {
      FPRINTF (stderr, _("Option `%s' makes no sense without option `%s'.\n"),
               "-s", "-p");
      ret = 1;
      return;
    }
    handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL,
                                       &notify_receive,
                                       &notify_connect,
                                       &notify_disconnect);
    if (NULL == handle)
    {
        FPRINTF (stderr, "%s", _("Failed to connect to transport service\n"));
        ret = 1;
        return;
    }
    tc_handle =  GNUNET_TRANSPORT_try_connect (handle, &pid, try_connect_cb, NULL);
    if (NULL == tc_handle)
    {
        FPRINTF (stderr, "%s", _("Failed to send request to transport service\n"));
        ret = 1;
        return;
    }
    start_time = GNUNET_TIME_absolute_get ();
    op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
                                               &operation_timeout, NULL);
  }
  else if (benchmark_receive) /* -b: Benchmark receiving */
  {
    handle =
        GNUNET_TRANSPORT_connect (cfg, NULL, NULL, &notify_receive,
                                  NULL, NULL);
    if (NULL == handle)
    {
        FPRINTF (stderr, "%s", _("Failed to connect to transport service\n"));
        ret = 1;
        return;
    }
    if (verbosity > 0)
      FPRINTF (stdout, "%s", _("Starting to receive benchmark data\n"));
    start_time = GNUNET_TIME_absolute_get ();

  }
  else if (iterate_connections) /* -i: List all active addresses once */
  {
    peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO);
    address_resolution_in_progress = GNUNET_YES;
    pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg,
                                                (NULL == cpid) ? NULL : &pid,
                                                GNUNET_YES,
                                                TIMEOUT,
                                                &process_address, (void *) cfg);
    op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT,
                                               &operation_timeout, NULL);
  }
  else if (monitor_connections) /* -m: List all active addresses continously */
  {
    peers = GNUNET_CONTAINER_multihashmap_create (20, GNUNET_NO);
    address_resolution_in_progress = GNUNET_YES;
    pic = GNUNET_TRANSPORT_peer_get_active_addresses (cfg,
                                                (NULL == cpid) ? NULL : &pid,
                                                GNUNET_NO,
                                                TIMEOUT,
                                                &process_address, (void *) cfg);
  }
  else if (monitor_connects) /* -e : Monitor (dis)connect events continously */
  {
    monitor_connect_counter = 0;
    handle = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL,
                                       &monitor_notify_connect,
                                       &monitor_notify_disconnect);
    if (NULL == handle)
    {
      FPRINTF (stderr, "%s", _("Failed to connect to transport service\n"));
      ret = 1;
      return;
    }
    ret = 0;
  }
  else
  {
    GNUNET_break (0);
    return;
  }

  end = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                      &shutdown_task,
                                      NULL);

}