diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-22 17:30:57 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-22 17:30:57 +0000 |
commit | 45f0267ad9a0e19c0445e0a2e228aab438bf517f (patch) | |
tree | 1da50ae350985750660db5f14ba291dce9dea116 /src/transport/test_plugin_transport_udp.c | |
parent | 07632b2d9509b0e425967cbc80d2abd6ffc81c9d (diff) | |
download | gnunet-45f0267ad9a0e19c0445e0a2e228aab438bf517f.tar.gz gnunet-45f0267ad9a0e19c0445e0a2e228aab438bf517f.zip |
Diffstat (limited to 'src/transport/test_plugin_transport_udp.c')
-rw-r--r-- | src/transport/test_plugin_transport_udp.c | 94 |
1 files changed, 10 insertions, 84 deletions
diff --git a/src/transport/test_plugin_transport_udp.c b/src/transport/test_plugin_transport_udp.c index bb75126bb..9474cf730 100644 --- a/src/transport/test_plugin_transport_udp.c +++ b/src/transport/test_plugin_transport_udp.c | |||
@@ -95,10 +95,11 @@ static int ok; | |||
95 | */ | 95 | */ |
96 | static void | 96 | static void |
97 | receive (void *cls, | 97 | receive (void *cls, |
98 | struct GNUNET_TIME_Relative | 98 | const struct GNUNET_PeerIdentity * peer, |
99 | latency, | 99 | const struct GNUNET_MessageHeader * message, |
100 | const struct GNUNET_PeerIdentity | 100 | uint32_t distance, |
101 | *peer, const struct GNUNET_MessageHeader *message) | 101 | const char *sender_address, |
102 | size_t sender_address_len) | ||
102 | { | 103 | { |
103 | /* do nothing */ | 104 | /* do nothing */ |
104 | } | 105 | } |
@@ -127,82 +128,12 @@ unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
127 | if (my_private_key != NULL) | 128 | if (my_private_key != NULL) |
128 | GNUNET_CRYPTO_rsa_key_free (my_private_key); | 129 | GNUNET_CRYPTO_rsa_key_free (my_private_key); |
129 | 130 | ||
131 | ok = 0; | ||
130 | } | 132 | } |
131 | 133 | ||
132 | |||
133 | static void | ||
134 | unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
135 | { | ||
136 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
137 | unload_plugins (NULL, cfg); | ||
138 | } | ||
139 | |||
140 | |||
141 | static GNUNET_SCHEDULER_TaskIdentifier validation_timeout_task; | ||
142 | |||
143 | |||
144 | static void | ||
145 | validation_notification (void *cls, | ||
146 | const char *name, | ||
147 | const struct GNUNET_PeerIdentity *peer, | ||
148 | uint32_t challenge, const char *sender_addr) | ||
149 | { | ||
150 | struct sockaddr_storage *addr = (struct sockaddr_storage *) sender_addr; | ||
151 | |||
152 | if (validation_timeout_task != GNUNET_SCHEDULER_NO_TASK) | ||
153 | { | ||
154 | GNUNET_SCHEDULER_cancel (sched, validation_timeout_task); | ||
155 | validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
156 | } | ||
157 | |||
158 | switch (addr->ss_family) | ||
159 | { | ||
160 | case AF_INET: | ||
161 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
162 | ("got address %s\n"), | ||
163 | GNUNET_a2s ((struct sockaddr *) addr, | ||
164 | INET_ADDRSTRLEN)); | ||
165 | case AF_INET6: | ||
166 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
167 | ("got address %s\n"), | ||
168 | GNUNET_a2s ((struct sockaddr *) addr, | ||
169 | INET6_ADDRSTRLEN)); | ||
170 | } | ||
171 | |||
172 | |||
173 | GNUNET_assert (challenge == 42); | ||
174 | |||
175 | ok = 0; /* if the last test succeeded, report success */ | ||
176 | |||
177 | GNUNET_SCHEDULER_add_continuation (sched, | ||
178 | &unload_task, | ||
179 | (void *) cfg, | ||
180 | GNUNET_SCHEDULER_REASON_PREREQ_DONE); | ||
181 | } | ||
182 | |||
183 | |||
184 | static void | ||
185 | validation_failed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
186 | { | ||
187 | validation_timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
188 | GNUNET_break (0); /* output error */ | ||
189 | /* the "validation_notification" was not called | ||
190 | in a timely fashion; we should set an error | ||
191 | code for main and shut down */ | ||
192 | unload_plugins (NULL, cfg); | ||
193 | } | ||
194 | |||
195 | |||
196 | /** | 134 | /** |
197 | * Simple example test that invokes | 135 | * Simple example test that invokes |
198 | * the "validate" function of the plugin | 136 | * the check_address function of the plugin. |
199 | * and tries to see if the plugin would | ||
200 | * succeed to validate its own address. | ||
201 | * (This test is not well-written since | ||
202 | * we hand-compile the address which | ||
203 | * kind-of works for TCP but would not | ||
204 | * work for other plugins; we should ask | ||
205 | * the plugin about its address instead...). | ||
206 | */ | 137 | */ |
207 | /* FIXME: won't work on IPv6 enabled systems where IPv4 mapping | 138 | /* FIXME: won't work on IPv6 enabled systems where IPv4 mapping |
208 | * isn't enabled (eg. FreeBSD > 4) | 139 | * isn't enabled (eg. FreeBSD > 4) |
@@ -220,12 +151,10 @@ test_validation () | |||
220 | soaddr.sin_port = htons (2368 /* FIXME: get from config! */ ); | 151 | soaddr.sin_port = htons (2368 /* FIXME: get from config! */ ); |
221 | soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | 152 | soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
222 | 153 | ||
223 | /* add job to catch failure (timeout) */ | 154 | api->check_address(api->cls, |
224 | validation_timeout_task = | 155 | &soaddr, sizeof (soaddr)); |
225 | GNUNET_SCHEDULER_add_delayed (sched, TIMEOUT, &validation_failed, NULL); | ||
226 | 156 | ||
227 | api->validate (api->cls, | 157 | unload_plugins(env.cls, env.cfg); |
228 | &my_identity, 42, TIMEOUT, &soaddr, sizeof (soaddr)); | ||
229 | } | 158 | } |
230 | 159 | ||
231 | 160 | ||
@@ -234,13 +163,10 @@ setup_plugin_environment () | |||
234 | { | 163 | { |
235 | env.cfg = cfg; | 164 | env.cfg = cfg; |
236 | env.sched = sched; | 165 | env.sched = sched; |
237 | env.my_public_key = &my_public_key; | ||
238 | env.my_private_key = my_private_key; | ||
239 | env.my_identity = &my_identity; | 166 | env.my_identity = &my_identity; |
240 | env.cls = &env; | 167 | env.cls = &env; |
241 | env.receive = &receive; | 168 | env.receive = &receive; |
242 | env.notify_address = ¬ify_address; | 169 | env.notify_address = ¬ify_address; |
243 | env.notify_validation = &validation_notification; | ||
244 | env.max_connections = max_connect_per_transport; | 170 | env.max_connections = max_connect_per_transport; |
245 | } | 171 | } |
246 | 172 | ||