#include "block_dns.h"
#include "gnunet_signatures.h"
#include "gnunet_namestore_service.h"
+#include "gnunet_resolver_service.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_gns_service.h"
-/* DEFINES */
-#define VERBOSE GNUNET_YES
-
/* Timeout for entire testcase */
#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 20)
/* Global return value (0 for success, anything else for failure) */
static int ok;
+static int resolver_working;
+
static struct GNUNET_NAMESTORE_Handle *namestore_handle;
static struct GNUNET_GNS_Handle *gns_handle;
+static struct GNUNET_RESOLVER_RequestHandle *resolver_handle;
+
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
if (rd_count == 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup failed, rp_filtering?\n");
+ "Lookup failed\n");
ok = 2;
}
else
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)
+ if (rd[i].record_type == GNUNET_GNS_RECORD_A)
{
memcpy(&a, rd[i].data, sizeof(a));
addr = inet_ntoa(a);
if (rd_count == 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup failed, rp_filtering?\n");
+ "Lookup failed\n");
ok = 2;
}
else
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)
+ if (rd[i].record_type == GNUNET_GNS_RECORD_A)
{
memcpy(&a, rd[i].data, sizeof(a));
addr = inet_ntoa(a);
}
}
- GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ALT2, GNUNET_GNS_RECORD_TYPE_A,
+ GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ALT2, GNUNET_GNS_RECORD_A,
GNUNET_YES,
NULL,
&on_lookup_result_alt2, TEST_DOMAIN_ALT2);
if (rd_count == 0)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Lookup failed, rp_filtering?\n");
+ "Lookup failed\n");
ok = 2;
}
else
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)
+ if (rd[i].record_type == GNUNET_GNS_RECORD_A)
{
memcpy(&a, rd[i].data, sizeof(a));
addr = inet_ntoa(a);
}
}
- GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ALT, GNUNET_GNS_RECORD_TYPE_A,
+ GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN_ALT, GNUNET_GNS_RECORD_A,
GNUNET_YES,
NULL,
&on_lookup_result_alt, TEST_DOMAIN_ALT);
}
-/**
- * Function scheduled to be run on the successful start of services
- * tries to look up the dns record for TEST_DOMAIN
- */
static void
-commence_testing (void *cls, int32_t success, const char *emsg)
+start_lookup (void)
{
+
-
- GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES);
-
- gns_handle = GNUNET_GNS_connect(cfg);
+ GNUNET_NAMESTORE_disconnect (namestore_handle);
+ gns_handle = GNUNET_GNS_connect (cfg);
if (NULL == gns_handle)
{
ok = 2;
}
- GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A,
- GNUNET_YES,
- NULL,
- &on_lookup_result, TEST_DOMAIN);
+ GNUNET_GNS_lookup (gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_A,
+ GNUNET_YES,
+ NULL,
+ &on_lookup_result, TEST_DOMAIN);
+}
+
+
+static void
+handle_dns_test (void *cls,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ struct sockaddr_in* sai;
+
+ if (NULL == addr)
+ {
+ /* end of results */
+ if (GNUNET_YES != resolver_working)
+ {
+ ok = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "System resolver not working. Test inconclusive!\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Shutting down peer1!\n");
+ GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
+ return;
+ }
+ start_lookup ();
+ return;
+ }
+
+ if (addrlen == sizeof (struct sockaddr_in))
+ {
+ sai = (struct sockaddr_in*) addr;
+ if (0 == strcmp (TEST_IP, inet_ntoa (sai->sin_addr)))
+ resolver_working = GNUNET_YES;
+ }
+}
+
+
+
+
+/**
+ * Function scheduled to be run on the successful start of services
+ * tries to look up the dns record for TEST_DOMAIN
+ */
+static void
+commence_testing (void *cls, int32_t success, const char *emsg)
+{
+
+ resolver_working = GNUNET_NO;
+
+ GNUNET_RESOLVER_connect (cfg);
+ resolver_handle = GNUNET_RESOLVER_ip_get (TEST_RECORD_NS,
+ AF_INET,
+ TIMEOUT,
+ &handle_dns_test,
+ NULL);
}
static void
end_badly_cont (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
-
+ if (resolver_handle != NULL)
+ GNUNET_RESOLVER_request_cancel (resolver_handle);
if (pg != NULL)
GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
GNUNET_SCHEDULER_cancel (die_task);
rd.data_size = strlen (TEST_RECORD_NS);
rd.data = TEST_RECORD_NS;
- rd.record_type = GNUNET_GNS_RECORD_TYPE_NS;
+ rd.record_type = GNUNET_GNS_RECORD_NS;
GNUNET_NAMESTORE_record_create (namestore_handle,
alice_key,
char *const argv[] = { "test-gns-ns-lookup", /* Name to give running binary */
"-c",
"test_gns_simple_lookup.conf", /* Config file to use */
-#if VERBOSE
- "-L", "DEBUG",
-#endif
NULL
};
struct GNUNET_GETOPT_CommandLineOption options[] = {
int ret;
GNUNET_log_setup ("test-gns-simple-lookup",
-#if VERBOSE
- "DEBUG",
-#else
"WARNING",
-#endif
NULL);
ret = check ();
/**