Пример #1
0
/**
 * Check if the get_handle is being used, if so stop the request.  Either
 * way, schedule the end_badly_cont function which actually shuts down the
 * test.
 */
static void
end_badly (void *cls, 
	   const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  if (NULL != nsqe)
  {
    GNUNET_NAMESTORE_cancel (nsqe);
    nsqe = NULL;
  }
  if (NULL != lr)
  {
    GNUNET_GNS_cancel_lookup_request (lr);
    lr = NULL;
  }
  if (NULL != gns_handle)
  {
    GNUNET_GNS_disconnect (gns_handle);
    gns_handle = NULL;
  }

  if (NULL != namestore_handle)
  {
    GNUNET_NAMESTORE_disconnect (namestore_handle);
    namestore_handle = NULL;
  }
  GNUNET_break (0);
  GNUNET_SCHEDULER_shutdown ();
  ok = 1;
}
static void shutdown_task (void *cls,
                           const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_GNS_disconnect(gns_handle);
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer!\n");
  GNUNET_SCHEDULER_shutdown ();
}
/**
 * Check if the get_handle is being used, if so stop the request.  Either
 * way, schedule the end_badly_cont function which actually shuts down the
 * test.
 */
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  die_task = GNUNET_SCHEDULER_NO_TASK;
  int c;

  if (GNUNET_SCHEDULER_NO_TASK != wait_task)
  {
      GNUNET_SCHEDULER_cancel (wait_task);
      wait_task = GNUNET_SCHEDULER_NO_TASK;
  }

  for (c = 0; c < 3; c++)
  {
    if (NULL != nh[c])
    {
      GNUNET_NAMESTORE_disconnect(nh[c]);
      nh[c] = NULL;
    }

    if (NULL != get_cfg_ops[c])
    {
        GNUNET_TESTBED_operation_done(get_cfg_ops[c]);
        get_cfg_ops[c] = NULL;
    }
    if (NULL != cfg_handles[c])
    {
      GNUNET_CONFIGURATION_destroy (cfg_handles[c]);
      cfg_handles[c] = NULL;
    }
  }
  if (NULL != topology_op)
  {
    GNUNET_TESTBED_operation_done (topology_op);
    topology_op = NULL;
  }
  if (NULL != lookup_handle)
  {
    GNUNET_GNS_cancel_lookup_request (lookup_handle);
    lookup_handle = NULL;
  }
  if (NULL != gh)
  {
    GNUNET_GNS_disconnect(gh);
    gh = NULL;
  }
  
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test failed \n");
  GNUNET_SCHEDULER_shutdown ();
  ok = 1;
}
/**
 * Check if the get_handle is being used, if so stop the request.  Either
 * way, schedule the end_badly_cont function which actually shuts down the
 * test.
 */
static void
end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  die_task = GNUNET_SCHEDULER_NO_TASK;
  if (NULL != gns_handle)
  {
    GNUNET_GNS_disconnect (gns_handle);
    gns_handle = NULL;
  }
  if (NULL != namestore_handle)
  {
    GNUNET_NAMESTORE_disconnect (namestore_handle);
    namestore_handle = NULL;
  }
  GNUNET_break (0);
  GNUNET_SCHEDULER_shutdown ();
  ok = 1;
}
static void
on_lookup_result(void *cls, uint32_t rd_count,
                 const struct GNUNET_NAMESTORE_RecordData *rd)
{
  struct in_addr a;
  int i;
  char* addr;
  
  if (rd_count == 0)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                "Lookup failed, rp_filtering?\n");
    ok = 2;
  }
  else
  {
    ok = 1;
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
    for (i=0; i<rd_count; i++)
    {
      GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
      if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
      {
        memcpy(&a, rd[i].data, sizeof(a));
        addr = inet_ntoa(a);
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
        if (0 == strcmp(addr, TEST_IP))
        {
          GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                    "ZKEY correctly resolved to %s!\n", addr);
          ok = 0;
        }
      }
      else
      {
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "No resolution!\n");
      }
    }
  }
  GNUNET_GNS_disconnect(gns_handle);
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
  GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}
static void
end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
  GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Finished\n");
  int c;
  if (GNUNET_SCHEDULER_NO_TASK != die_task)
  {
      GNUNET_SCHEDULER_cancel (die_task);
      die_task = GNUNET_SCHEDULER_NO_TASK;
  }

  for (c = 0; c < 3; c++)
  {
    if (NULL != nh[c])
    {
      GNUNET_NAMESTORE_disconnect(nh[c]);
      nh[c] = NULL;
    }
    if (NULL != cfg_handles[c])
    {
      GNUNET_CONFIGURATION_destroy (cfg_handles[c]);
      cfg_handles[c] = NULL;
    }
  }

  if (NULL != gh)
  {
    GNUNET_GNS_disconnect(gh);
    gh = NULL;
  }

  if (0 == ok)
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test ended successful\n");
  else
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Test failed\n");
  GNUNET_SCHEDULER_shutdown ();
}
static void
on_lookup_result(void *cls, uint32_t rd_count,
                 const struct GNUNET_NAMESTORE_RecordData *rd)
{
    struct in_addr a;
    int i;
    char* addr;
    int mx_found = 0;
    int ip_found = 0;
    uint16_t mx_preference;
    char* mx;

    if (rd_count == 0)
    {
        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                    "Lookup failed, rp_filtering?\n");
        ok = 2;
    }
    else
    {
        ok = 1;
        GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls);
        for (i=0; i<rd_count; i++)
        {
            GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type);
            if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A)
            {
                memcpy(&a, rd[i].data, sizeof(a));
                addr = inet_ntoa(a);
                GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr);
                if (0 == strcmp(addr, TEST_IP))
                {
                    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                                "%s correctly resolved to %s!\n", TEST_DOMAIN, addr);
                    ip_found = 1;
                }
            }
            else if (rd[i].record_type == GNUNET_GNS_RECORD_MX)
            {
                mx = (char*)rd[i].data+sizeof(uint16_t);
                mx_preference = *(uint16_t*)rd[i].data;
                GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                            "Got MX %s with preference %d\n", mx, mx_preference);
                if (0 == strcmp(mx, TEST_EXPECTED_MX))
                {
                    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                                "%s correctly resolved to %s!\n", TEST_DOMAIN,
                                TEST_EXPECTED_MX);
                    mx_found = 1;
                }
            }
        }
    }

    if (ip_found && mx_found)
    {
        GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                    "Test succeeded!\n");
        ok = 0;
    }

    if (!ip_found && mx_found)
    {
        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                    "Test partially succeeded: A record not passed along!(NOT IMPLEMENTED)\n");
        ok = 0;
    }

    GNUNET_GNS_disconnect(gns_handle);
    GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
    GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
}