diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-12 10:32:05 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2012-03-12 10:32:05 +0000 |
commit | d656d0f85549e69a05490286b1ed5d7b06abede8 (patch) | |
tree | d6db5644268b0a09868f1ae3bc596160911ef5d1 /src | |
parent | f178ee5c79255d00eec5ed421d2e503b8d176fd0 (diff) | |
download | gnunet-d656d0f85549e69a05490286b1ed5d7b06abede8.tar.gz gnunet-d656d0f85549e69a05490286b1ed5d7b06abede8.zip |
-new test
Diffstat (limited to 'src')
-rw-r--r-- | src/gns/Makefile.am | 25 | ||||
-rw-r--r-- | src/gns/test_gns_simple_delegated_lookup.c | 69 |
2 files changed, 59 insertions, 35 deletions
diff --git a/src/gns/Makefile.am b/src/gns/Makefile.am index 912468774..8d7b9bb4a 100644 --- a/src/gns/Makefile.am +++ b/src/gns/Makefile.am | |||
@@ -28,7 +28,8 @@ bin_PROGRAMS = \ | |||
28 | 28 | ||
29 | check_PROGRAMS = \ | 29 | check_PROGRAMS = \ |
30 | test_gns_simple_shorten \ | 30 | test_gns_simple_shorten \ |
31 | test_gns_simple_lookup | 31 | test_gns_simple_lookup \ |
32 | test_gns_simple_delegated_lookup | ||
32 | 33 | ||
33 | 34 | ||
34 | # test_gns_simple_lookup | 35 | # test_gns_simple_lookup |
@@ -63,16 +64,18 @@ test_gns_simple_lookup_DEPENDENCIES = \ | |||
63 | $(top_builddir)/src/gns/libgnunetgns.la \ | 64 | $(top_builddir)/src/gns/libgnunetgns.la \ |
64 | $(top_builddir)/src/testing/libgnunettesting.la | 65 | $(top_builddir)/src/testing/libgnunettesting.la |
65 | 66 | ||
66 | #test_gns_simple_delegated_lookup_SOURCES = \ | 67 | test_gns_simple_delegated_lookup_SOURCES = \ |
67 | # test_gns_simple_delegated_lookup.c | 68 | test_gns_simple_delegated_lookup.c |
68 | #test_gns_simple_delegated_lookup_LDADD = \ | 69 | test_gns_simple_delegated_lookup_LDADD = \ |
69 | # $(top_builddir)/src/util/libgnunetutil.la \ | 70 | $(top_builddir)/src/util/libgnunetutil.la \ |
70 | # $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 71 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
71 | # $(top_builddir)/src/testing/libgnunettesting.la | 72 | $(top_builddir)/src/gns/libgnunetgns.la \ |
72 | #test_gns_simple_delegated_lookup_DEPENDENCIES = \ | 73 | $(top_builddir)/src/testing/libgnunettesting.la |
73 | # $(top_builddir)/src/util/libgnunetutil.la \ | 74 | test_gns_simple_delegated_lookup_DEPENDENCIES = \ |
74 | # $(top_builddir)/src/namestore/libgnunetnamestore.la \ | 75 | $(top_builddir)/src/util/libgnunetutil.la \ |
75 | # $(top_builddir)/src/testing/libgnunettesting.la | 76 | $(top_builddir)/src/namestore/libgnunetnamestore.la \ |
77 | $(top_builddir)/src/gns/libgnunetgns.la \ | ||
78 | $(top_builddir)/src/testing/libgnunettesting.la | ||
76 | 79 | ||
77 | #test_gns_dht_delegated_lookup_SOURCES = \ | 80 | #test_gns_dht_delegated_lookup_SOURCES = \ |
78 | # test_gns_dht_delegated_lookup.c | 81 | # test_gns_dht_delegated_lookup.c |
diff --git a/src/gns/test_gns_simple_delegated_lookup.c b/src/gns/test_gns_simple_delegated_lookup.c index 8e6e7753d..b80f2bbf0 100644 --- a/src/gns/test_gns_simple_delegated_lookup.c +++ b/src/gns/test_gns_simple_delegated_lookup.c | |||
@@ -80,6 +80,8 @@ static int ok; | |||
80 | 80 | ||
81 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; | 81 | static struct GNUNET_NAMESTORE_Handle *namestore_handle; |
82 | 82 | ||
83 | static struct GNUNET_GNS_Handle *gns_handle; | ||
84 | |||
83 | const struct GNUNET_CONFIGURATION_Handle *cfg; | 85 | const struct GNUNET_CONFIGURATION_Handle *cfg; |
84 | 86 | ||
85 | /** | 87 | /** |
@@ -98,43 +100,38 @@ shutdown_callback (void *cls, const char *emsg) | |||
98 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); | 100 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "done(ret=%d)!\n", ok); |
99 | } | 101 | } |
100 | 102 | ||
101 | /** | ||
102 | * Function scheduled to be run on the successful start of services | ||
103 | * tries to look up the dns record for TEST_DOMAIN | ||
104 | */ | ||
105 | static void | 103 | static void |
106 | finish_testing (void *cls, int32_t success, const char *emsg) | 104 | on_lookup_result(void *cls, uint32_t rd_count, |
105 | const struct GNUNET_NAMESTORE_RecordData *rd) | ||
107 | { | 106 | { |
108 | struct hostent *he; | ||
109 | struct in_addr a; | 107 | struct in_addr a; |
108 | int i; | ||
110 | char* addr; | 109 | char* addr; |
111 | 110 | ||
112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 111 | if (rd_count == 0) |
113 | "disconnecting from namestore\n"); | ||
114 | GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); | ||
115 | |||
116 | he = gethostbyname (TEST_DOMAIN); | ||
117 | |||
118 | if (!he) | ||
119 | { | 112 | { |
120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 113 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
121 | "gethostbyname failed, rp_filtering?\n"); | 114 | "Lookup failed, rp_filtering?\n"); |
122 | ok = 2; | 115 | ok = 2; |
123 | } | 116 | } |
124 | else | 117 | else |
125 | { | 118 | { |
126 | ok = 1; | 119 | ok = 1; |
127 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", he->h_name); | 120 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "name: %s\n", (char*)cls); |
128 | while (*he->h_addr_list) | 121 | for (i=0; i<rd_count; i++) |
129 | { | 122 | { |
130 | memcpy(&a, *he->h_addr_list++, sizeof(a)); | 123 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "type: %d\n", rd[i].record_type); |
131 | addr = inet_ntoa(a); | 124 | if (rd[i].record_type == GNUNET_GNS_RECORD_TYPE_A) |
132 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | ||
133 | if (0 == strcmp(addr, TEST_IP)) | ||
134 | { | 125 | { |
135 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 126 | memcpy(&a, rd[i].data, sizeof(a)); |
127 | addr = inet_ntoa(a); | ||
128 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "address: %s\n", addr); | ||
129 | if (0 == strcmp(addr, TEST_IP)) | ||
130 | { | ||
131 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
136 | "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); | 132 | "%s correctly resolved to %s!\n", TEST_DOMAIN, addr); |
137 | ok = 0; | 133 | ok = 0; |
134 | } | ||
138 | } | 135 | } |
139 | else | 136 | else |
140 | { | 137 | { |
@@ -147,6 +144,28 @@ finish_testing (void *cls, int32_t success, const char *emsg) | |||
147 | GNUNET_YES, GNUNET_NO); | 144 | GNUNET_YES, GNUNET_NO); |
148 | } | 145 | } |
149 | 146 | ||
147 | |||
148 | /** | ||
149 | * Function scheduled to be run on the successful start of services | ||
150 | * tries to look up the dns record for TEST_DOMAIN | ||
151 | */ | ||
152 | static void | ||
153 | commence_testing (void *cls, int32_t success, const char *emsg) | ||
154 | { | ||
155 | GNUNET_NAMESTORE_disconnect(namestore_handle, GNUNET_YES); | ||
156 | |||
157 | gns_handle = GNUNET_GNS_connect(cfg); | ||
158 | |||
159 | if (NULL == gns_handle) | ||
160 | { | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
162 | "Failed to connect to GNS!\n"); | ||
163 | } | ||
164 | |||
165 | GNUNET_GNS_lookup(gns_handle, TEST_DOMAIN, GNUNET_GNS_RECORD_TYPE_A, | ||
166 | &on_lookup_result, TEST_DOMAIN); | ||
167 | } | ||
168 | |||
150 | /** | 169 | /** |
151 | * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut | 170 | * Continuation for the GNUNET_DHT_get_stop call, so that we don't shut |
152 | * down the peers without freeing memory associated with GET request. | 171 | * down the peers without freeing memory associated with GET request. |
@@ -236,7 +255,9 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | |||
236 | rd.data_size = sizeof(struct in_addr); | 255 | rd.data_size = sizeof(struct in_addr); |
237 | rd.data = web; | 256 | rd.data = web; |
238 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; | 257 | rd.record_type = GNUNET_DNSPARSER_TYPE_A; |
239 | sig = GNUNET_NAMESTORE_create_signature(bob_key, TEST_RECORD_NAME, | 258 | sig = GNUNET_NAMESTORE_create_signature(bob_key, |
259 | GNUNET_TIME_absolute_get_forever(), | ||
260 | TEST_RECORD_NAME, | ||
240 | &rd, 1); | 261 | &rd, 1); |
241 | 262 | ||
242 | GNUNET_NAMESTORE_record_put (namestore_handle, | 263 | GNUNET_NAMESTORE_record_put (namestore_handle, |
@@ -246,7 +267,7 @@ do_lookup(void *cls, const struct GNUNET_PeerIdentity *id, | |||
246 | 1, | 267 | 1, |
247 | &rd, | 268 | &rd, |
248 | sig, | 269 | sig, |
249 | &finish_testing, | 270 | &commence_testing, |
250 | NULL); | 271 | NULL); |
251 | 272 | ||
252 | } | 273 | } |