コード例 #1
0
static void
end ()
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
  if (die_task != GNUNET_SCHEDULER_NO_TASK)
  {
    GNUNET_SCHEDULER_cancel (die_task);
    die_task = GNUNET_SCHEDULER_NO_TASK;
  }
  if (NULL != atsh)
  GNUNET_ATS_scheduling_done (atsh);
  if (phal != NULL)
    GNUNET_ATS_performance_list_addresses_cancel (phal);
  phal = NULL;
  if (ph != NULL)
    GNUNET_ATS_performance_done (ph);
  ph = NULL;

  GNUNET_free_non_null (p0_addresses[0].addr);
  GNUNET_free_non_null (p0_addresses[1].addr);
  GNUNET_free_non_null (p1_addresses[0].addr);
  GNUNET_free_non_null (p1_addresses[1].addr);

  ret = 0;
}
コード例 #2
0
void all_addresses_peer_cb (void *cls,
                      const struct
                      GNUNET_HELLO_Address *
                      address,
                      struct
                      GNUNET_BANDWIDTH_Value32NBO
                      bandwidth_out,
                      struct
                      GNUNET_BANDWIDTH_Value32NBO
                      bandwidth_in,
                      const struct
                      GNUNET_ATS_Information *
                      ats, uint32_t ats_count)
{
  static int cb = 0;
  int fail = GNUNET_NO;

  if (address != NULL)
  {
      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
          "Callback for peer `%s'  address `%s'\n",
           GNUNET_i2s (&address->peer), address->address);

    if (0 != memcmp (&address->peer, &p[1].id,
                     sizeof (struct GNUNET_PeerIdentity)))
    {
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
            "Stage %i:  Received address for wrong peer\n", stage);
        GNUNET_ATS_performance_list_addresses_cancel (phal);
        fail = GNUNET_YES;
        ret = 4;
    }
    cb ++;
  }

  if ((NULL == address) || (fail))
  {
      phal = NULL;
      if ((2 == cb) && (GNUNET_NO == fail))
      {
        /* Received all addresses + terminator cb, next stage */
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %i:  SUCCESS\n", stage);
        GNUNET_SCHEDULER_add_now (&test_performance_api, NULL);
        return;
      }
      else
      {
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %i:  FAIL\n", stage);
        GNUNET_SCHEDULER_add_now (&end, NULL);
        ret = 5;
        return;
      }
  }
}
コード例 #3
0
ファイル: test_ats_lib.c プロジェクト: muggenhor/GNUnet
/**
 * Function called from #GNUNET_ATS_performance_list_addresses when
 * we process a #CMD_LIST_ADDRESSES command.
 *
 * @param cls the `struct Command` that caused the call
 * @param address the address, NULL if ATS service was disconnected
 * @param address_active #GNUNET_YES if this address is actively used
 *        to maintain a connection to a peer;
 *        #GNUNET_NO if the address is not actively used;
 *        #GNUNET_SYSERR if this address is no longer available for ATS
 * @param bandwidth_out assigned outbound bandwidth for the connection
 * @param bandwidth_in assigned inbound bandwidth for the connection
 * @param prop performance data for the address
 */
static void
info_cb (void *cls,
         const struct GNUNET_HELLO_Address *address,
         int address_active,
         struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
         struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
         const struct GNUNET_ATS_Properties *prop)
{
  struct Command *c = cls;
  struct CommandListAddresses *cmd = &c->details.list_addresses;

  if (NULL == address)
  {
    cmd->alh = NULL;
    /* we are done with the iteration, continue to execute */
    if ( (cmd->calls < cmd->min_calls) &&
         (cmd->active_calls < cmd->min_active_calls) )
    {
      GNUNET_SCHEDULER_shutdown ();
      return;
    }
    off++;
    run_interpreter ();
    return;
  }
  switch (address_active)
  {
  case GNUNET_YES:
    cmd->active_calls++;
    cmd->calls++;
    break;
  case GNUNET_NO:
    cmd->calls++;
    break;
  case GNUNET_SYSERR:
    return;
  }
  if ( (cmd->calls > cmd->max_calls) &&
       (cmd->active_calls < cmd->max_active_calls) )
  {
    GNUNET_break (0);
    GNUNET_ATS_performance_list_addresses_cancel (cmd->alh);
    cmd->alh = NULL;
    GNUNET_SCHEDULER_shutdown ();
    return;
  }
}
コード例 #4
0
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  die_task = GNUNET_SCHEDULER_NO_TASK;

  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout in stage %u\n", stage);

  if (NULL != atsh)
  GNUNET_ATS_scheduling_done (atsh);
  if (phal != NULL)
    GNUNET_ATS_performance_list_addresses_cancel (phal);
  phal = NULL;
  if (ph != NULL)
    GNUNET_ATS_performance_done (ph);
  ph = NULL;

  GNUNET_free_non_null (p0_addresses[0].addr);
  GNUNET_free_non_null (p0_addresses[1].addr);
  GNUNET_free_non_null (p1_addresses[0].addr);
  GNUNET_free_non_null (p1_addresses[1].addr);

  ret = GNUNET_SYSERR;
}
コード例 #5
0
ファイル: gnunet-ats.c プロジェクト: schanzen/gnunet-mirror
void end (void *cls,
          const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  struct PendingResolutions * pr;
  struct PendingResolutions * next;
  unsigned int pending;

  if (NULL != alh)
  {
      GNUNET_ATS_performance_list_addresses_cancel (alh);
      alh = NULL;
  }

  if (NULL != ph)
  {
    GNUNET_ATS_performance_done (ph);
    ph = NULL;
  }

  pending = 0;
  next = head;
  while (NULL != (pr = next))
  {
      next = pr->next;
      GNUNET_CONTAINER_DLL_remove (head, tail, pr);
      GNUNET_TRANSPORT_address_to_string_cancel (pr->tats_ctx);
      GNUNET_free (pr->address);
      GNUNET_free (pr);
      pending ++;
  }
  if (0 < pending)
    fprintf (stderr, _("%u address resolutions had a timeout\n"), pending);

  fprintf (stderr, _("ATS returned results for %u addresses\n"), results);
  ret = 0;
}
コード例 #6
0
void all_active_addresses_cb (void *cls,
                      const struct
                      GNUNET_HELLO_Address *
                      address,
                      struct
                      GNUNET_BANDWIDTH_Value32NBO
                      bandwidth_out,
                      struct
                      GNUNET_BANDWIDTH_Value32NBO
                      bandwidth_in,
                      const struct
                      GNUNET_ATS_Information *
                      ats, uint32_t ats_count)
{
  static int cb = 0;
  int fail = GNUNET_NO;

  if (address != NULL)
  {
    if (0 == memcmp (&address->peer, &p[0].id,
                     sizeof (struct GNUNET_PeerIdentity)))
    {
        if (0 == strcmp(address->address, s_ha[0]->address))
        {
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Callback for peer 0 suggested address %s\n",
              s_ha[0]->address);
          cb ++;
        }
        else
        {
          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
              "Expected callback for peer 0 address `%s', got address `%s'!\n",
              s_ha[0]->address, address->address);
          GNUNET_ATS_performance_list_addresses_cancel (phal);
          fail = GNUNET_YES;
        }
    }

    if (0 == memcmp (&address->peer, &p[1].id,
                     sizeof (struct GNUNET_PeerIdentity)))
    {
        if (0 == strcmp(address->address, s_ha[1]->address))
        {
          GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Callback for peer 1 suggested address %s\n",
              s_ha[1]->address);
          cb ++;
        }
        else
        {
          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
              "Expected callback for peer 1 address `%s', got address `%s'!\n",
              s_ha[1]->address, address->address);
          GNUNET_ATS_performance_list_addresses_cancel (phal);
          fail = GNUNET_YES;
        }
    }
  }
  if ((address == NULL) || (GNUNET_YES == fail))
  {
      phal = NULL;
      if ((2 == cb) && (GNUNET_NO == fail))
      {
        /* Received all addresses + terminator cb, next stage */
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Stage %i:  SUCCESS\n", stage);
        GNUNET_SCHEDULER_add_now (&test_performance_api, NULL);
        return;
      }
      else
      {
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Stage %i:  FAIL\n", stage);
        GNUNET_SCHEDULER_add_now (&end, NULL);
        ret = 5;
        return;
      }
  }
}