aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport-new.c324
-rw-r--r--src/transport/gnunet-service-transport.c5612
-rw-r--r--src/transport/gnunet-service-transport_ats.c1826
-rw-r--r--src/transport/gnunet-service-transport_ats.h273
-rw-r--r--src/transport/gnunet-service-transport_blacklist.c611
-rw-r--r--src/transport/gnunet-service-transport_blacklist.h43
-rw-r--r--src/transport/gnunet-service-transport_clients.c533
-rw-r--r--src/transport/gnunet-service-transport_clients.h12
-rw-r--r--src/transport/gnunet-service-transport_hello.c143
-rw-r--r--src/transport/gnunet-service-transport_hello.h28
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c579
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h68
-rw-r--r--src/transport/gnunet-service-transport_plugins.c111
-rw-r--r--src/transport/gnunet-service-transport_plugins.h18
-rw-r--r--src/transport/gnunet-service-transport_validation.c688
-rw-r--r--src/transport/gnunet-service-transport_validation.h45
-rw-r--r--src/transport/gnunet-transport-certificate-creation.c46
-rw-r--r--src/transport/gnunet-transport-list-connections.c23
-rw-r--r--src/transport/gnunet-transport-wlan-helper.c1103
-rw-r--r--src/transport/gnunet-transport-wlan-helper.h3
-rw-r--r--src/transport/ieee80211_radiotap.h164
-rw-r--r--src/transport/perf_transport_ats.c213
-rw-r--r--src/transport/plugin_transport_http.c3934
-rw-r--r--src/transport/plugin_transport_smtp.c568
-rw-r--r--src/transport/plugin_transport_tcp.c1679
-rw-r--r--src/transport/plugin_transport_template.c21
-rw-r--r--src/transport/plugin_transport_udp.c1228
-rw-r--r--src/transport/plugin_transport_unix.c582
-rw-r--r--src/transport/plugin_transport_wlan.c2517
-rw-r--r--src/transport/plugin_transport_wlan.h54
-rw-r--r--src/transport/test_plugin_transport.c52
-rw-r--r--src/transport/test_plugin_transport_http.c1163
-rw-r--r--src/transport/test_plugin_transport_https.c937
-rw-r--r--src/transport/test_plugin_transport_udp.c57
-rw-r--r--src/transport/test_plugin_transport_wlan_dummy.c559
-rw-r--r--src/transport/test_quota_compliance.c910
-rw-r--r--src/transport/test_transport_api.c228
-rw-r--r--src/transport/test_transport_api_disconnect.c208
-rw-r--r--src/transport/test_transport_api_multiaddress.c185
-rw-r--r--src/transport/test_transport_api_reliability.c416
-rw-r--r--src/transport/test_transport_api_unreliability.c753
-rw-r--r--src/transport/test_transport_ats.c137
-rw-r--r--src/transport/test_transport_ats_multiple_peers.c991
-rw-r--r--src/transport/test_transport_testing.c61
-rw-r--r--src/transport/transport-testing.c178
-rw-r--r--src/transport/transport-testing.h32
-rw-r--r--src/transport/transport.h2
-rw-r--r--src/transport/transport_api.c860
-rw-r--r--src/transport/transport_api_address_iterate.c75
-rw-r--r--src/transport/transport_api_address_lookup.c89
-rw-r--r--src/transport/transport_api_blacklist.c97
-rw-r--r--src/transport/transport_api_peer_address_lookup.c80
-rw-r--r--src/transport/wlan/byteorder.h827
-rw-r--r--src/transport/wlan/crctable_osdep.h99
-rw-r--r--src/transport/wlan/helper_common.c82
-rw-r--r--src/transport/wlan/helper_common.h6
-rw-r--r--src/transport/wlan/ieee80211.h532
-rw-r--r--src/transport/wlan/ieee80211_radiotap.h150
-rw-r--r--src/transport/wlan/loopback_helper.h3
-rw-r--r--src/transport/wlan/radiotap-parser.c360
-rw-r--r--src/transport/wlan/radiotap-parser.h31
61 files changed, 16303 insertions, 16906 deletions
diff --git a/src/transport/gnunet-service-transport-new.c b/src/transport/gnunet-service-transport-new.c
index 3cc1191fd..8ceffd86c 100644
--- a/src/transport/gnunet-service-transport-new.c
+++ b/src/transport/gnunet-service-transport-new.c
@@ -86,17 +86,16 @@ struct GNUNET_ATS_Handle *GST_ats;
86 */ 86 */
87static void 87static void
88transmit_our_hello (void *cls, 88transmit_our_hello (void *cls,
89 const struct GNUNET_PeerIdentity *target, 89 const struct GNUNET_PeerIdentity *target,
90 const struct GNUNET_TRANSPORT_ATS_Information *ats, 90 const struct GNUNET_TRANSPORT_ATS_Information *ats,
91 uint32_t ats_count) 91 uint32_t ats_count)
92{ 92{
93 const struct GNUNET_MessageHeader *hello = cls; 93 const struct GNUNET_MessageHeader *hello = cls;
94 94
95 GST_neighbours_send (target, 95 GST_neighbours_send (target,
96 (const char*) hello, 96 (const char *) hello,
97 ntohs (hello->size), 97 ntohs (hello->size),
98 GST_HELLO_ADDRESS_EXPIRATION, 98 GST_HELLO_ADDRESS_EXPIRATION, NULL, NULL);
99 NULL, NULL);
100} 99}
101 100
102 101
@@ -107,12 +106,10 @@ transmit_our_hello (void *cls,
107 * @param hello new HELLO 106 * @param hello new HELLO
108 */ 107 */
109static void 108static void
110process_hello_update (void *cls, 109process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello)
111 const struct GNUNET_MessageHeader *hello)
112{ 110{
113 GST_clients_broadcast (hello, GNUNET_NO); 111 GST_clients_broadcast (hello, GNUNET_NO);
114 GST_neighbours_iterate (&transmit_our_hello, 112 GST_neighbours_iterate (&transmit_our_hello, (void *) hello);
115 (void*) hello);
116} 113}
117 114
118 115
@@ -127,11 +124,10 @@ process_hello_update (void *cls,
127 */ 124 */
128static void 125static void
129try_connect_if_allowed (void *cls, 126try_connect_if_allowed (void *cls,
130 const struct GNUNET_PeerIdentity *peer, 127 const struct GNUNET_PeerIdentity *peer, int result)
131 int result)
132{ 128{
133 if (GNUNET_OK != result) 129 if (GNUNET_OK != result)
134 return; /* not allowed */ 130 return; /* not allowed */
135 GST_neighbours_try_connect (peer); 131 GST_neighbours_try_connect (peer);
136} 132}
137 133
@@ -159,14 +155,14 @@ try_connect_if_allowed (void *cls,
159 * @return how long the plugin should wait until receiving more data 155 * @return how long the plugin should wait until receiving more data
160 * (plugins that do not support this, can ignore the return value) 156 * (plugins that do not support this, can ignore the return value)
161 */ 157 */
162static struct GNUNET_TIME_Relative 158static struct GNUNET_TIME_Relative
163plugin_env_receive_callback (void *cls, 159plugin_env_receive_callback (void *cls,
164 const struct GNUNET_PeerIdentity *peer, 160 const struct GNUNET_PeerIdentity *peer,
165 const struct GNUNET_MessageHeader *message, 161 const struct GNUNET_MessageHeader *message,
166 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count, 162 const struct GNUNET_TRANSPORT_ATS_Information *ats,
167 struct Session *session, 163 uint32_t ats_count, struct Session *session,
168 const char *sender_address, 164 const char *sender_address,
169 uint16_t sender_address_len) 165 uint16_t sender_address_len)
170{ 166{
171 const char *plugin_name = cls; 167 const char *plugin_name = cls;
172 int do_forward; 168 int do_forward;
@@ -176,80 +172,72 @@ plugin_env_receive_callback (void *cls,
176 172
177 ret = GNUNET_TIME_UNIT_ZERO; 173 ret = GNUNET_TIME_UNIT_ZERO;
178 if (NULL != message) 174 if (NULL != message)
175 {
176 type = ntohs (message->type);
177 switch (type)
179 { 178 {
180 type = ntohs (message->type); 179 case GNUNET_MESSAGE_TYPE_HELLO:
181 switch (type) 180 GST_validation_handle_hello (message);
182 { 181 break;
183 case GNUNET_MESSAGE_TYPE_HELLO: 182 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
184 GST_validation_handle_hello (message);
185 break;
186 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
187#if DEBUG_TRANSPORT 183#if DEBUG_TRANSPORT
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
189 "Processing `%s' from `%s'\n", 185 "Processing `%s' from `%s'\n",
190 "PING", 186 "PING",
191 (sender_address != NULL) 187 (sender_address != NULL)
192 ? GST_plugins_a2s (plugin_name, 188 ? GST_plugins_a2s (plugin_name,
193 sender_address, 189 sender_address,
194 sender_address_len) 190 sender_address_len) : "<inbound>");
195 : "<inbound>");
196#endif 191#endif
197 GST_validation_handle_ping (peer, 192 GST_validation_handle_ping (peer,
198 message, 193 message,
199 plugin_name, 194 plugin_name,
200 session, 195 session, sender_address, sender_address_len);
201 sender_address, sender_address_len); 196 break;
202 break; 197 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
203 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
204#if DEBUG_TRANSPORT 198#if DEBUG_TRANSPORT
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
206 "Processing `%s' from `%s'\n", 200 "Processing `%s' from `%s'\n",
207 "PONG", 201 "PONG",
208 (sender_address != NULL) 202 (sender_address != NULL)
209 ? GST_plugins_a2s (plugin_name, 203 ? GST_plugins_a2s (plugin_name,
210 sender_address, 204 sender_address,
211 sender_address_len) 205 sender_address_len) : "<inbound>");
212 : "<inbound>");
213#endif 206#endif
214 GST_validation_handle_pong (peer, 207 GST_validation_handle_pong (peer, message);
215 message); 208 break;
216 break; 209 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT:
217 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: 210 (void) GST_blacklist_test_allowed (peer,
218 (void) GST_blacklist_test_allowed (peer, 211 NULL, &try_connect_if_allowed, NULL);
219 NULL, 212 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred
220 &try_connect_if_allowed, NULL); 213 * way to communicate with this peer (other peer switched transport) */
221 /* TODO: if 'session != NULL', maybe notify ATS that this is now the preferred 214 break;
222 way to communicate with this peer (other peer switched transport) */ 215 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT:
223 break; 216 /* TODO: do some validation to prevent an attacker from sending
224 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: 217 * a fake disconnect message... */
225 /* TODO: do some validation to prevent an attacker from sending 218 GST_neighbours_force_disconnect (peer);
226 a fake disconnect message... */ 219 break;
227 GST_neighbours_force_disconnect (peer); 220 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE:
228 break; 221 GST_neighbours_keepalive (peer);
229 case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_KEEPALIVE: 222 break;
230 GST_neighbours_keepalive (peer); 223 default:
231 break; 224 /* should be payload */
232 default: 225 do_forward = GNUNET_SYSERR;
233 /* should be payload */ 226 ret = GST_neighbours_calculate_receive_delay (peer,
234 do_forward = GNUNET_SYSERR; 227 (message == NULL)
235 ret = GST_neighbours_calculate_receive_delay (peer, 228 ? 0
236 (message == NULL) 229 : ntohs (message->size),
237 ? 0 230 &do_forward);
238 : ntohs (message->size), 231 if (do_forward == GNUNET_YES)
239 &do_forward); 232 GST_clients_broadcast (message, GNUNET_YES);
240 if (do_forward == GNUNET_YES) 233 break;
241 GST_clients_broadcast (message, GNUNET_YES);
242 break;
243 }
244 } 234 }
245 GNUNET_ATS_address_update (GST_ats, 235 }
246 peer, 236 GNUNET_ATS_address_update (GST_ats, peer, GNUNET_TIME_absolute_get (), /* valid at least until right now... */
247 GNUNET_TIME_absolute_get (), /* valid at least until right now... */ 237 plugin_name,
248 plugin_name, 238 session,
249 session, 239 sender_address,
250 sender_address, 240 sender_address_len, ats, ats_count);
251 sender_address_len,
252 ats, ats_count);
253 241
254 return ret; 242 return ret;
255} 243}
@@ -266,18 +254,14 @@ plugin_env_receive_callback (void *cls,
266 * the specific address format depends on the transport 254 * the specific address format depends on the transport
267 * @param addrlen length of the address 255 * @param addrlen length of the address
268 */ 256 */
269static void 257static void
270plugin_env_address_change_notification (void *cls, 258plugin_env_address_change_notification (void *cls,
271 int add_remove, 259 int add_remove,
272 const void *addr, 260 const void *addr, size_t addrlen)
273 size_t addrlen)
274{ 261{
275 const char *plugin_name = cls; 262 const char *plugin_name = cls;
276 263
277 GST_hello_modify_addresses (add_remove, 264 GST_hello_modify_addresses (add_remove, plugin_name, addr, addrlen);
278 plugin_name,
279 addr,
280 addrlen);
281} 265}
282 266
283 267
@@ -296,11 +280,10 @@ plugin_env_address_change_notification (void *cls,
296 */ 280 */
297static void 281static void
298plugin_env_session_end (void *cls, 282plugin_env_session_end (void *cls,
299 const struct GNUNET_PeerIdentity *peer, 283 const struct GNUNET_PeerIdentity *peer,
300 struct Session *session) 284 struct Session *session)
301{ 285{
302 GST_neighbours_session_terminated (peer, 286 GST_neighbours_session_terminated (peer, session);
303 session);
304} 287}
305 288
306 289
@@ -319,23 +302,20 @@ plugin_env_session_end (void *cls,
319 * @param plugin_addr_len number of bytes in addr 302 * @param plugin_addr_len number of bytes in addr
320 * @param bandwidth assigned outbound bandwidth for the connection 303 * @param bandwidth assigned outbound bandwidth for the connection
321 */ 304 */
322static void 305static void
323ats_request_address_change (void *cls, 306ats_request_address_change (void *cls,
324 const struct GNUNET_PeerIdentity *peer, 307 const struct GNUNET_PeerIdentity *peer,
325 const char *plugin_name, 308 const char *plugin_name,
326 struct Session *session, 309 struct Session *session,
327 const void *plugin_addr, 310 const void *plugin_addr,
328 size_t plugin_addr_len, 311 size_t plugin_addr_len,
329 struct GNUNET_BANDWIDTH_Value32NBO bandwidth) 312 struct GNUNET_BANDWIDTH_Value32NBO bandwidth)
330{ 313{
331 GST_neighbours_switch_to_address (peer, 314 GST_neighbours_switch_to_address (peer,
332 plugin_name, 315 plugin_name,
333 plugin_addr, 316 plugin_addr,
334 plugin_addr_len, 317 plugin_addr_len, session, NULL, 0);
335 session, 318 GST_neighbours_set_incoming_quota (peer, bandwidth);
336 NULL, 0);
337 GST_neighbours_set_incoming_quota (peer,
338 bandwidth);
339} 319}
340 320
341 321
@@ -350,23 +330,24 @@ ats_request_address_change (void *cls,
350 */ 330 */
351static void 331static void
352neighbours_connect_notification (void *cls, 332neighbours_connect_notification (void *cls,
353 const struct GNUNET_PeerIdentity * peer, 333 const struct GNUNET_PeerIdentity *peer,
354 const struct GNUNET_TRANSPORT_ATS_Information *ats, 334 const struct GNUNET_TRANSPORT_ATS_Information
355 uint32_t ats_count) 335 *ats, uint32_t ats_count)
356{ 336{
357 char buf[sizeof(struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)]; 337 char buf[sizeof (struct ConnectInfoMessage) +
358 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage*) buf; 338 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)];
339 struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
359 struct GNUNET_TRANSPORT_ATS_Information *atsm = &connect_msg->ats; 340 struct GNUNET_TRANSPORT_ATS_Information *atsm = &connect_msg->ats;
360 341
361 connect_msg->header.size = htons (sizeof (buf)); 342 connect_msg->header.size = htons (sizeof (buf));
362 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 343 connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
363 connect_msg->ats_count = htonl (ats_count); 344 connect_msg->ats_count = htonl (ats_count);
364 connect_msg->id = *peer; 345 connect_msg->id = *peer;
365 memcpy (&connect_msg->ats, ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information)); 346 memcpy (&connect_msg->ats, ats,
347 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
366 atsm[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 348 atsm[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
367 atsm[ats_count].value = htonl (0); 349 atsm[ats_count].value = htonl (0);
368 GST_clients_broadcast (&connect_msg->header, 350 GST_clients_broadcast (&connect_msg->header, GNUNET_NO);
369 GNUNET_NO);
370} 351}
371 352
372 353
@@ -379,7 +360,7 @@ neighbours_connect_notification (void *cls,
379 */ 360 */
380static void 361static void
381neighbours_disconnect_notification (void *cls, 362neighbours_disconnect_notification (void *cls,
382 const struct GNUNET_PeerIdentity *peer) 363 const struct GNUNET_PeerIdentity *peer)
383{ 364{
384 struct DisconnectInfoMessage disconnect_msg; 365 struct DisconnectInfoMessage disconnect_msg;
385 366
@@ -387,8 +368,7 @@ neighbours_disconnect_notification (void *cls,
387 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 368 disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
388 disconnect_msg.reserved = htonl (0); 369 disconnect_msg.reserved = htonl (0);
389 disconnect_msg.peer = *peer; 370 disconnect_msg.peer = *peer;
390 GST_clients_broadcast (&disconnect_msg.header, 371 GST_clients_broadcast (&disconnect_msg.header, GNUNET_NO);
391 GNUNET_NO);
392} 372}
393 373
394 374
@@ -400,32 +380,32 @@ neighbours_disconnect_notification (void *cls,
400 * @param tc task context (unused) 380 * @param tc task context (unused)
401 */ 381 */
402static void 382static void
403shutdown_task (void *cls, 383shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
404 const struct GNUNET_SCHEDULER_TaskContext *tc) 384{
405{
406 GST_validation_stop (); 385 GST_validation_stop ();
407 GST_neighbours_stop (); 386 GST_neighbours_stop ();
408 GNUNET_ATS_shutdown (GST_ats); GST_ats = NULL; 387 GNUNET_ATS_shutdown (GST_ats);
388 GST_ats = NULL;
409 GST_clients_stop (); 389 GST_clients_stop ();
410 GST_blacklist_stop (); 390 GST_blacklist_stop ();
411 GST_plugins_unload (); 391 GST_plugins_unload ();
412 GST_hello_stop (); 392 GST_hello_stop ();
413 393
414 if (GST_peerinfo != NULL) 394 if (GST_peerinfo != NULL)
415 { 395 {
416 GNUNET_PEERINFO_disconnect (GST_peerinfo); 396 GNUNET_PEERINFO_disconnect (GST_peerinfo);
417 GST_peerinfo = NULL; 397 GST_peerinfo = NULL;
418 } 398 }
419 if (GST_stats != NULL) 399 if (GST_stats != NULL)
420 { 400 {
421 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO); 401 GNUNET_STATISTICS_destroy (GST_stats, GNUNET_NO);
422 GST_stats = NULL; 402 GST_stats = NULL;
423 } 403 }
424 if (GST_my_private_key != NULL) 404 if (GST_my_private_key != NULL)
425 { 405 {
426 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key); 406 GNUNET_CRYPTO_rsa_key_free (GST_my_private_key);
427 GST_my_private_key = NULL; 407 GST_my_private_key = NULL;
428 } 408 }
429} 409}
430 410
431 411
@@ -447,24 +427,23 @@ run (void *cls,
447 GST_cfg = c; 427 GST_cfg = c;
448 if (GNUNET_OK != 428 if (GNUNET_OK !=
449 GNUNET_CONFIGURATION_get_value_filename (c, 429 GNUNET_CONFIGURATION_get_value_filename (c,
450 "GNUNETD", 430 "GNUNETD", "HOSTKEY", &keyfile))
451 "HOSTKEY", &keyfile)) 431 {
452 { 432 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 433 _
454 _ 434 ("Transport service is lacking key configuration settings. Exiting.\n"));
455 ("Transport service is lacking key configuration settings. Exiting.\n")); 435 GNUNET_SCHEDULER_shutdown ();
456 GNUNET_SCHEDULER_shutdown (); 436 return;
457 return; 437 }
458 }
459 GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 438 GST_my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
460 GNUNET_free (keyfile); 439 GNUNET_free (keyfile);
461 if (GST_my_private_key == NULL) 440 if (GST_my_private_key == NULL)
462 { 441 {
463 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 442 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
464 _("Transport service could not access hostkey. Exiting.\n")); 443 _("Transport service could not access hostkey. Exiting.\n"));
465 GNUNET_SCHEDULER_shutdown (); 444 GNUNET_SCHEDULER_shutdown ();
466 return; 445 return;
467 } 446 }
468 GST_stats = GNUNET_STATISTICS_create ("transport", c); 447 GST_stats = GNUNET_STATISTICS_create ("transport", c);
469 GST_peerinfo = GNUNET_PEERINFO_connect (c); 448 GST_peerinfo = GNUNET_PEERINFO_connect (c);
470 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key); 449 GNUNET_CRYPTO_rsa_key_get_public (GST_my_private_key, &GST_my_public_key);
@@ -473,25 +452,23 @@ run (void *cls,
473 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 452 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
474 &shutdown_task, NULL); 453 &shutdown_task, NULL);
475 if (GST_peerinfo == NULL) 454 if (GST_peerinfo == NULL)
476 { 455 {
477 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 456 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
478 _("Could not access PEERINFO service. Exiting.\n")); 457 _("Could not access PEERINFO service. Exiting.\n"));
479 GNUNET_SCHEDULER_shutdown (); 458 GNUNET_SCHEDULER_shutdown ();
480 return; 459 return;
481 } 460 }
482 461
483 /* start subsystems */ 462 /* start subsystems */
484 GST_hello_start (&process_hello_update, NULL); 463 GST_hello_start (&process_hello_update, NULL);
485 GST_blacklist_start (server); 464 GST_blacklist_start (server);
486 GST_plugins_load (&plugin_env_receive_callback, 465 GST_plugins_load (&plugin_env_receive_callback,
487 &plugin_env_address_change_notification, 466 &plugin_env_address_change_notification,
488 &plugin_env_session_end); 467 &plugin_env_session_end);
489 GST_ats = GNUNET_ATS_init (GST_cfg, 468 GST_ats = GNUNET_ATS_init (GST_cfg, &ats_request_address_change, NULL);
490 &ats_request_address_change,
491 NULL);
492 GST_neighbours_start (NULL, 469 GST_neighbours_start (NULL,
493 &neighbours_connect_notification, 470 &neighbours_connect_notification,
494 &neighbours_disconnect_notification); 471 &neighbours_disconnect_notification);
495 GST_clients_start (server); 472 GST_clients_start (server);
496 GST_validation_start (); 473 GST_validation_start ();
497} 474}
@@ -511,8 +488,7 @@ main (int argc, char *const *argv)
511 GNUNET_SERVICE_run (argc, 488 GNUNET_SERVICE_run (argc,
512 argv, 489 argv,
513 "transport", 490 "transport",
514 GNUNET_SERVICE_OPTION_NONE, 491 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
515 &run, NULL)) ? 0 : 1;
516} 492}
517 493
518/* end of file gnunet-service-transport-new.c */ 494/* end of file gnunet-service-transport-new.c */
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index cf02d14b2..4f962d117 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -178,9 +178,9 @@ struct ForeignAddressList
178 */ 178 */
179 struct Session *session; 179 struct Session *session;
180 180
181 struct ATS_ressource_entry * ressources; 181 struct ATS_ressource_entry *ressources;
182 182
183 struct ATS_quality_entry * quality; 183 struct ATS_quality_entry *quality;
184 184
185 /** 185 /**
186 * What was the last latency observed for this address, plugin and peer? 186 * What was the last latency observed for this address, plugin and peer?
@@ -325,7 +325,7 @@ struct TransportPlugin
325 */ 325 */
326 int rebuild; 326 int rebuild;
327 327
328 struct ATS_plugin * rc; 328 struct ATS_plugin *rc;
329 329
330 /** 330 /**
331 * Hashmap of blacklisted peers for this particular transport. 331 * Hashmap of blacklisted peers for this particular transport.
@@ -735,7 +735,7 @@ struct CheckHelloValidatedContext;
735/** 735/**
736 * Entry in map of all HELLOs awaiting validation. 736 * Entry in map of all HELLOs awaiting validation.
737 */ 737 */
738struct ValidationEntry 738struct ValidationEntry
739{ 739{
740 740
741 /** 741 /**
@@ -929,10 +929,12 @@ static struct ATS_Handle *ats;
929 * Time of last ats execution 929 * Time of last ats execution
930 */ 930 */
931struct GNUNET_TIME_Absolute last_ats_execution; 931struct GNUNET_TIME_Absolute last_ats_execution;
932
932/** 933/**
933 * Minimum interval between two ATS executions 934 * Minimum interval between two ATS executions
934 */ 935 */
935struct GNUNET_TIME_Relative ats_minimum_interval; 936struct GNUNET_TIME_Relative ats_minimum_interval;
937
936/** 938/**
937 * Regular interval when ATS execution is triggered 939 * Regular interval when ATS execution is triggered
938 */ 940 */
@@ -961,8 +963,8 @@ static void disconnect_neighbour (struct NeighbourMapEntry *n, int check);
961 */ 963 */
962static void try_transmission_to_peer (struct NeighbourMapEntry *n); 964static void try_transmission_to_peer (struct NeighbourMapEntry *n);
963 965
964struct ForeignAddressList * get_preferred_ats_address ( 966struct ForeignAddressList *get_preferred_ats_address (struct NeighbourMapEntry
965 struct NeighbourMapEntry *n); 967 *n);
966 968
967/** 969/**
968 * Find an entry in the neighbour list for a particular peer. 970 * Find an entry in the neighbour list for a particular peer.
@@ -975,11 +977,14 @@ find_neighbour (const struct GNUNET_PeerIdentity *key)
975 return GNUNET_CONTAINER_multihashmap_get (neighbours, &key->hashPubKey); 977 return GNUNET_CONTAINER_multihashmap_get (neighbours, &key->hashPubKey);
976} 978}
977 979
978static int update_addr_value (struct ForeignAddressList *fal, uint32_t value , int ats_index) 980static int
981update_addr_value (struct ForeignAddressList *fal, uint32_t value,
982 int ats_index)
979{ 983{
980 int c; 984 int c;
981 int set = GNUNET_NO; 985 int set = GNUNET_NO;
982 for (c=0; c<available_quality_metrics; c++) 986
987 for (c = 0; c < available_quality_metrics; c++)
983 { 988 {
984 if (ats_index == qm[c].atis_index) 989 if (ats_index == qm[c].atis_index)
985 { 990 {
@@ -994,7 +999,7 @@ static int update_addr_value (struct ForeignAddressList *fal, uint32_t value , i
994 } 999 }
995 if (set == GNUNET_NO) 1000 if (set == GNUNET_NO)
996 { 1001 {
997 for (c=0; c<available_ressources; c++) 1002 for (c = 0; c < available_ressources; c++)
998 { 1003 {
999 if (ats_index == ressources[c].atis_index) 1004 if (ats_index == ressources[c].atis_index)
1000 { 1005 {
@@ -1010,16 +1015,19 @@ static int update_addr_value (struct ForeignAddressList *fal, uint32_t value , i
1010} 1015}
1011 1016
1012static int 1017static int
1013update_addr_ats (struct ForeignAddressList *fal, 1018update_addr_ats (struct ForeignAddressList *fal,
1014 const struct GNUNET_TRANSPORT_ATS_Information *ats_data, 1019 const struct GNUNET_TRANSPORT_ATS_Information *ats_data,
1015 int ats_count) 1020 int ats_count)
1016{ 1021{
1017 int c1, set; 1022 int c1, set;
1023
1018 set = GNUNET_NO; 1024 set = GNUNET_NO;
1019 for (c1=0; c1<ats_count; c1++) 1025 for (c1 = 0; c1 < ats_count; c1++)
1020 { 1026 {
1021 set = update_addr_value(fal, ntohl(ats_data[c1].value), ntohl(ats_data[c1].type)); 1027 set =
1022 } 1028 update_addr_value (fal, ntohl (ats_data[c1].value),
1029 ntohl (ats_data[c1].type));
1030 }
1023 return set; 1031 return set;
1024} 1032}
1025 1033
@@ -1032,6 +1040,7 @@ static struct TransportPlugin *
1032find_transport (const char *short_name) 1040find_transport (const char *short_name)
1033{ 1041{
1034 struct TransportPlugin *head = plugins; 1042 struct TransportPlugin *head = plugins;
1043
1035 while ((head != NULL) && (0 != strcmp (short_name, head->short_name))) 1044 while ((head != NULL) && (0 != strcmp (short_name, head->short_name)))
1036 head = head->next; 1045 head = head->next;
1037 return head; 1046 return head;
@@ -1046,49 +1055,51 @@ find_transport (const char *short_name)
1046 * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not 1055 * @return GNUNET_YES if the peer is blacklisted, GNUNET_NO if not
1047 */ 1056 */
1048static int 1057static int
1049is_blacklisted (const struct GNUNET_PeerIdentity *peer, struct TransportPlugin *plugin) 1058is_blacklisted (const struct GNUNET_PeerIdentity *peer,
1059 struct TransportPlugin *plugin)
1050{ 1060{
1051 1061
1052 if (plugin->blacklist != NULL) 1062 if (plugin->blacklist != NULL)
1063 {
1064 if (GNUNET_CONTAINER_multihashmap_contains
1065 (plugin->blacklist, &peer->hashPubKey) == GNUNET_YES)
1053 { 1066 {
1054 if (GNUNET_CONTAINER_multihashmap_contains (plugin->blacklist, &peer->hashPubKey) == GNUNET_YES)
1055 {
1056#if DEBUG_BLACKLIST 1067#if DEBUG_BLACKLIST
1057 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1068 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1058 "Peer `%s:%s' is blacklisted!\n", 1069 "Peer `%s:%s' is blacklisted!\n",
1059 plugin->short_name, GNUNET_i2s (peer)); 1070 plugin->short_name, GNUNET_i2s (peer));
1060#endif 1071#endif
1061 if (stats != NULL) 1072 if (stats != NULL)
1062 GNUNET_STATISTICS_update (stats, "# blacklisted peers refused", 1, GNUNET_NO); 1073 GNUNET_STATISTICS_update (stats, "# blacklisted peers refused", 1,
1063 return GNUNET_YES; 1074 GNUNET_NO);
1064 } 1075 return GNUNET_YES;
1065 } 1076 }
1077 }
1066 1078
1067 return GNUNET_NO; 1079 return GNUNET_NO;
1068} 1080}
1069 1081
1070 1082
1071static void 1083static void
1072add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer, 1084add_peer_to_blacklist (struct GNUNET_PeerIdentity *peer, char *transport_name)
1073 char *transport_name)
1074{ 1085{
1075 struct TransportPlugin *plugin; 1086 struct TransportPlugin *plugin;
1076 1087
1077 plugin = find_transport(transport_name); 1088 plugin = find_transport (transport_name);
1078 if (plugin == NULL) /* Nothing to do */ 1089 if (plugin == NULL) /* Nothing to do */
1079 return; 1090 return;
1080#if DEBUG_TRANSPORT 1091#if DEBUG_TRANSPORT
1081 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1082 "Adding peer `%s' with plugin `%s' to blacklist\n", 1093 "Adding peer `%s' with plugin `%s' to blacklist\n",
1083 GNUNET_i2s (peer), 1094 GNUNET_i2s (peer), transport_name);
1084 transport_name);
1085#endif 1095#endif
1086 if (plugin->blacklist == NULL) 1096 if (plugin->blacklist == NULL)
1087 plugin->blacklist = GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE); 1097 plugin->blacklist =
1088 GNUNET_assert(plugin->blacklist != NULL); 1098 GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE);
1089 GNUNET_CONTAINER_multihashmap_put(plugin->blacklist, &peer->hashPubKey, 1099 GNUNET_assert (plugin->blacklist != NULL);
1090 NULL, 1100 GNUNET_CONTAINER_multihashmap_put (plugin->blacklist, &peer->hashPubKey,
1091 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 1101 NULL,
1102 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1092} 1103}
1093 1104
1094 1105
@@ -1115,145 +1126,148 @@ read_blacklist_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
1115 if (GNUNET_OK != 1126 if (GNUNET_OK !=
1116 GNUNET_CONFIGURATION_get_value_filename (cfg, 1127 GNUNET_CONFIGURATION_get_value_filename (cfg,
1117 "TRANSPORT", 1128 "TRANSPORT",
1118 "BLACKLIST_FILE", 1129 "BLACKLIST_FILE", &fn))
1119 &fn)) 1130 {
1120 {
1121#if DEBUG_TRANSPORT 1131#if DEBUG_TRANSPORT
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "Option `%s' in section `%s' not specified!\n", 1133 "Option `%s' in section `%s' not specified!\n",
1124 "BLACKLIST_FILE", 1134 "BLACKLIST_FILE", "TRANSPORT");
1125 "TRANSPORT");
1126#endif 1135#endif
1127 return; 1136 return;
1128 } 1137 }
1129 if (GNUNET_OK != GNUNET_DISK_file_test (fn)) 1138 if (GNUNET_OK != GNUNET_DISK_file_test (fn))
1130 GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ 1139 GNUNET_DISK_fn_write (fn, NULL, 0, GNUNET_DISK_PERM_USER_READ
1131 | GNUNET_DISK_PERM_USER_WRITE); 1140 | GNUNET_DISK_PERM_USER_WRITE);
1132 if (0 != STAT (fn, &frstat)) 1141 if (0 != STAT (fn, &frstat))
1133 { 1142 {
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1135 _("Could not read blacklist file `%s'\n"), fn); 1144 _("Could not read blacklist file `%s'\n"), fn);
1136 GNUNET_free (fn); 1145 GNUNET_free (fn);
1137 return; 1146 return;
1138 } 1147 }
1139 if (frstat.st_size == 0) 1148 if (frstat.st_size == 0)
1140 { 1149 {
1141#if DEBUG_TRANSPORT 1150#if DEBUG_TRANSPORT
1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1143 _("Blacklist file `%s' is empty.\n"), 1152 _("Blacklist file `%s' is empty.\n"), fn);
1144 fn);
1145#endif 1153#endif
1146 GNUNET_free (fn); 1154 GNUNET_free (fn);
1147 return; 1155 return;
1148 } 1156 }
1149 /* FIXME: use mmap */ 1157 /* FIXME: use mmap */
1150 data = GNUNET_malloc_large (frstat.st_size); 1158 data = GNUNET_malloc_large (frstat.st_size);
1151 GNUNET_assert(data != NULL); 1159 GNUNET_assert (data != NULL);
1152 if (frstat.st_size != 1160 if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size))
1153 GNUNET_DISK_fn_read (fn, data, frstat.st_size)) 1161 {
1154 { 1162 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1155 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1163 _("Failed to read blacklist from `%s'\n"), fn);
1156 _("Failed to read blacklist from `%s'\n"), fn); 1164 GNUNET_free (fn);
1157 GNUNET_free (fn); 1165 GNUNET_free (data);
1158 GNUNET_free (data); 1166 return;
1159 return; 1167 }
1160 }
1161 entries_found = 0; 1168 entries_found = 0;
1162 pos = 0; 1169 pos = 0;
1163 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos])) 1170 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
1164 pos++; 1171 pos++;
1165 while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) && 1172 while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
1166 (pos <= frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded))) 1173 (pos <=
1167 { 1174 frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
1168 colon_pos = pos; 1175 {
1169 while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') && !isspace ( (unsigned char) data[colon_pos])) 1176 colon_pos = pos;
1170 colon_pos++; 1177 while ((colon_pos < frstat.st_size) && (data[colon_pos] != ':') &&
1178 !isspace ((unsigned char) data[colon_pos]))
1179 colon_pos++;
1171 1180
1172 if (colon_pos >= frstat.st_size) 1181 if (colon_pos >= frstat.st_size)
1173 { 1182 {
1174 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1183 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1175 _("Syntax error in blacklist file at offset %llu, giving up!\n"), 1184 _
1176 (unsigned long long) colon_pos); 1185 ("Syntax error in blacklist file at offset %llu, giving up!\n"),
1177 GNUNET_free (fn); 1186 (unsigned long long) colon_pos);
1178 GNUNET_free (data); 1187 GNUNET_free (fn);
1179 return; 1188 GNUNET_free (data);
1180 } 1189 return;
1190 }
1181 1191
1182 if (isspace( (unsigned char) data[colon_pos])) 1192 if (isspace ((unsigned char) data[colon_pos]))
1183 { 1193 {
1184 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1194 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1185 _("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), 1195 _
1186 (unsigned long long) colon_pos); 1196 ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
1187 pos = colon_pos; 1197 (unsigned long long) colon_pos);
1188 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos])) 1198 pos = colon_pos;
1189 pos++; 1199 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
1190 continue; 1200 pos++;
1191 } 1201 continue;
1192 tsize = colon_pos - pos; 1202 }
1193 if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || (tsize == 0)) 1203 tsize = colon_pos - pos;
1194 { 1204 if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) ||
1195 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1205 (tsize == 0))
1196 _("Syntax error in blacklist file at offset %llu, giving up!\n"), 1206 {
1197 (unsigned long long) colon_pos); 1207 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1198 GNUNET_free (fn); 1208 _
1199 GNUNET_free (data); 1209 ("Syntax error in blacklist file at offset %llu, giving up!\n"),
1200 return; 1210 (unsigned long long) colon_pos);
1201 } 1211 GNUNET_free (fn);
1212 GNUNET_free (data);
1213 return;
1214 }
1202 1215
1203 if (tsize < 1) 1216 if (tsize < 1)
1204 continue; 1217 continue;
1205 1218
1206 transport_name = GNUNET_malloc(tsize + 1); 1219 transport_name = GNUNET_malloc (tsize + 1);
1207 memcpy(transport_name, &data[pos], tsize); 1220 memcpy (transport_name, &data[pos], tsize);
1208 pos = colon_pos + 1; 1221 pos = colon_pos + 1;
1209#if DEBUG_TRANSPORT 1222#if DEBUG_TRANSPORT
1210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1211 "Read transport name %s in blacklist file.\n", 1224 "Read transport name %s in blacklist file.\n", transport_name);
1212 transport_name);
1213#endif 1225#endif
1214 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 1226 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
1215 if (!isspace ( (unsigned char) enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) 1227 if (!isspace
1216 { 1228 ((unsigned char)
1217 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1229 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
1218 _("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), 1230 {
1219 (unsigned long long) pos); 1231 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1220 pos++; 1232 _
1221 while ((pos < frstat.st_size) && (!isspace ( (unsigned char) data[pos]))) 1233 ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
1222 pos++; 1234 (unsigned long long) pos);
1223 GNUNET_free_non_null(transport_name); 1235 pos++;
1224 continue; 1236 while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos])))
1225 }
1226 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
1227 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
1228 {
1229 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1230 _("Syntax error in blacklist file at offset %llu, skipping bytes `%s'.\n"),
1231 (unsigned long long) pos,
1232 &enc);
1233 }
1234 else
1235 {
1236 if (0 != memcmp (&pid,
1237 &my_identity,
1238 sizeof (struct GNUNET_PeerIdentity)))
1239 {
1240 entries_found++;
1241 add_peer_to_blacklist (&pid,
1242 transport_name);
1243 }
1244 else
1245 {
1246 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1247 _("Found myself `%s' in blacklist (useless, ignored)\n"),
1248 GNUNET_i2s (&pid));
1249 }
1250 }
1251 pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
1252 GNUNET_free_non_null(transport_name);
1253 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
1254 pos++; 1237 pos++;
1238 GNUNET_free_non_null (transport_name);
1239 continue;
1240 }
1241 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
1242 if (GNUNET_OK !=
1243 GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
1244 {
1245 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1246 _
1247 ("Syntax error in blacklist file at offset %llu, skipping bytes `%s'.\n"),
1248 (unsigned long long) pos, &enc);
1255 } 1249 }
1256 GNUNET_STATISTICS_update (stats, "# Transport entries blacklisted", entries_found, GNUNET_NO); 1250 else
1251 {
1252 if (0 != memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
1253 {
1254 entries_found++;
1255 add_peer_to_blacklist (&pid, transport_name);
1256 }
1257 else
1258 {
1259 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1260 _("Found myself `%s' in blacklist (useless, ignored)\n"),
1261 GNUNET_i2s (&pid));
1262 }
1263 }
1264 pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
1265 GNUNET_free_non_null (transport_name);
1266 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
1267 pos++;
1268 }
1269 GNUNET_STATISTICS_update (stats, "# Transport entries blacklisted",
1270 entries_found, GNUNET_NO);
1257 GNUNET_free (data); 1271 GNUNET_free (data);
1258 GNUNET_free (fn); 1272 GNUNET_free (fn);
1259} 1273}
@@ -1281,57 +1295,56 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
1281 1295
1282 client->th = NULL; 1296 client->th = NULL;
1283 if (buf == NULL) 1297 if (buf == NULL)
1284 { 1298 {
1285#if DEBUG_TRANSPORT 1299#if DEBUG_TRANSPORT
1286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1287 "Transmission to client failed, closing connection.\n"); 1301 "Transmission to client failed, closing connection.\n");
1288#endif 1302#endif
1289 /* fatal error with client, free message queue! */ 1303 /* fatal error with client, free message queue! */
1290 while (NULL != (q = client->message_queue_head)) 1304 while (NULL != (q = client->message_queue_head))
1291 { 1305 {
1292 GNUNET_STATISTICS_update (stats, 1306 GNUNET_STATISTICS_update (stats,
1293 gettext_noop ("# bytes discarded (could not transmit to client)"), 1307 gettext_noop
1294 ntohs (((const struct GNUNET_MessageHeader*)&q[1])->size), 1308 ("# bytes discarded (could not transmit to client)"),
1295 GNUNET_NO); 1309 ntohs (((const struct GNUNET_MessageHeader *)
1296 GNUNET_CONTAINER_DLL_remove (client->message_queue_head, 1310 &q[1])->size), GNUNET_NO);
1297 client->message_queue_tail, 1311 GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
1298 q); 1312 client->message_queue_tail, q);
1299 GNUNET_free (q); 1313 GNUNET_free (q);
1300 }
1301 client->message_count = 0;
1302 return 0;
1303 } 1314 }
1315 client->message_count = 0;
1316 return 0;
1317 }
1304 cbuf = buf; 1318 cbuf = buf;
1305 tsize = 0; 1319 tsize = 0;
1306 while (NULL != (q = client->message_queue_head)) 1320 while (NULL != (q = client->message_queue_head))
1307 { 1321 {
1308 msg = (const struct GNUNET_MessageHeader *) &q[1]; 1322 msg = (const struct GNUNET_MessageHeader *) &q[1];
1309 msize = ntohs (msg->size); 1323 msize = ntohs (msg->size);
1310 if (msize + tsize > size) 1324 if (msize + tsize > size)
1311 break; 1325 break;
1312#if DEBUG_TRANSPORT 1326#if DEBUG_TRANSPORT
1313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1314 "Transmitting message of type %u to client.\n", 1328 "Transmitting message of type %u to client.\n",
1315 ntohs (msg->type)); 1329 ntohs (msg->type));
1316#endif 1330#endif
1317 GNUNET_CONTAINER_DLL_remove (client->message_queue_head, 1331 GNUNET_CONTAINER_DLL_remove (client->message_queue_head,
1318 client->message_queue_tail, 1332 client->message_queue_tail, q);
1319 q); 1333 memcpy (&cbuf[tsize], msg, msize);
1320 memcpy (&cbuf[tsize], msg, msize); 1334 tsize += msize;
1321 tsize += msize; 1335 GNUNET_free (q);
1322 GNUNET_free (q); 1336 client->message_count--;
1323 client->message_count--; 1337 }
1324 }
1325 if (NULL != q) 1338 if (NULL != q)
1326 { 1339 {
1327 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 1340 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
1328 client->th = GNUNET_SERVER_notify_transmit_ready (client->client, 1341 client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
1329 msize, 1342 msize,
1330 GNUNET_TIME_UNIT_FOREVER_REL, 1343 GNUNET_TIME_UNIT_FOREVER_REL,
1331 &transmit_to_client_callback, 1344 &transmit_to_client_callback,
1332 client); 1345 client);
1333 GNUNET_assert (client->th != NULL); 1346 GNUNET_assert (client->th != NULL);
1334 } 1347 }
1335 return tsize; 1348 return tsize;
1336} 1349}
1337 1350
@@ -1344,10 +1357,8 @@ transmit_to_client_callback (void *cls, size_t size, void *buf)
1344 * @param addr_len number of bytes in addr 1357 * @param addr_len number of bytes in addr
1345 * @return NULL on error, otherwise address string 1358 * @return NULL on error, otherwise address string
1346 */ 1359 */
1347static const char* 1360static const char *
1348a2s (const char *plugin, 1361a2s (const char *plugin, const void *addr, uint16_t addr_len)
1349 const void *addr,
1350 uint16_t addr_len)
1351{ 1362{
1352 struct TransportPlugin *p; 1363 struct TransportPlugin *p;
1353 1364
@@ -1356,9 +1367,7 @@ a2s (const char *plugin,
1356 p = find_transport (plugin); 1367 p = find_transport (plugin);
1357 if ((p == NULL) || (addr_len == 0) || (addr == NULL)) 1368 if ((p == NULL) || (addr_len == 0) || (addr == NULL))
1358 return NULL; 1369 return NULL;
1359 return p->api->address_to_string (NULL, 1370 return p->api->address_to_string (NULL, addr, addr_len);
1360 addr,
1361 addr_len);
1362} 1371}
1363 1372
1364 1373
@@ -1373,9 +1382,7 @@ a2s (const char *plugin,
1373 * @return GNUNET_YES (always) 1382 * @return GNUNET_YES (always)
1374 */ 1383 */
1375static int 1384static int
1376abort_validation (void *cls, 1385abort_validation (void *cls, const GNUNET_HashCode * key, void *value)
1377 const GNUNET_HashCode * key,
1378 void *value)
1379{ 1386{
1380 struct ValidationEntry *va = value; 1387 struct ValidationEntry *va = value;
1381 1388
@@ -1383,17 +1390,15 @@ abort_validation (void *cls,
1383 GNUNET_SCHEDULER_cancel (va->timeout_task); 1390 GNUNET_SCHEDULER_cancel (va->timeout_task);
1384 GNUNET_free (va->transport_name); 1391 GNUNET_free (va->transport_name);
1385 if (va->chvc != NULL) 1392 if (va->chvc != NULL)
1393 {
1394 va->chvc->ve_count--;
1395 if (va->chvc->ve_count == 0)
1386 { 1396 {
1387 va->chvc->ve_count--; 1397 GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, va->chvc);
1388 if (va->chvc->ve_count == 0) 1398 GNUNET_free (va->chvc);
1389 {
1390 GNUNET_CONTAINER_DLL_remove (chvc_head,
1391 chvc_tail,
1392 va->chvc);
1393 GNUNET_free (va->chvc);
1394 }
1395 va->chvc = NULL;
1396 } 1399 }
1400 va->chvc = NULL;
1401 }
1397 GNUNET_free (va); 1402 GNUNET_free (va);
1398 return GNUNET_YES; 1403 return GNUNET_YES;
1399} 1404}
@@ -1406,24 +1411,23 @@ abort_validation (void *cls,
1406 * @param tc scheduler context (unused) 1411 * @param tc scheduler context (unused)
1407 */ 1412 */
1408static void 1413static void
1409timeout_hello_validation (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1414timeout_hello_validation (void *cls,
1415 const struct GNUNET_SCHEDULER_TaskContext *tc)
1410{ 1416{
1411 struct ValidationEntry *va = cls; 1417 struct ValidationEntry *va = cls;
1412 struct GNUNET_PeerIdentity pid; 1418 struct GNUNET_PeerIdentity pid;
1413 1419
1414 va->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1420 va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1415 GNUNET_STATISTICS_update (stats, 1421 GNUNET_STATISTICS_update (stats,
1416 gettext_noop ("# address validation timeouts"), 1422 gettext_noop ("# address validation timeouts"),
1417 1, 1423 1, GNUNET_NO);
1418 GNUNET_NO);
1419 GNUNET_CRYPTO_hash (&va->publicKey, 1424 GNUNET_CRYPTO_hash (&va->publicKey,
1420 sizeof (struct 1425 sizeof (struct
1421 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 1426 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
1422 &pid.hashPubKey); 1427 &pid.hashPubKey);
1423 GNUNET_break (GNUNET_OK == 1428 GNUNET_break (GNUNET_OK ==
1424 GNUNET_CONTAINER_multihashmap_remove (validation_map, 1429 GNUNET_CONTAINER_multihashmap_remove (validation_map,
1425 &pid.hashPubKey, 1430 &pid.hashPubKey, va));
1426 va));
1427 abort_validation (NULL, NULL, va); 1431 abort_validation (NULL, NULL, va);
1428} 1432}
1429 1433
@@ -1450,43 +1454,40 @@ transmit_to_client (struct TransportClient *client,
1450 * freed in client_disconnect_notification 1454 * freed in client_disconnect_notification
1451 */ 1455 */
1452 if (client->client == NULL) 1456 if (client->client == NULL)
1453 { 1457 {
1454 GNUNET_break (0); 1458 GNUNET_break (0);
1455 return; 1459 return;
1456 } 1460 }
1457 1461
1458 if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop)) 1462 if ((client->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
1459 { 1463 {
1460 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1464 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1461 _ 1465 _
1462 ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"), 1466 ("Dropping message of type %u and size %u, have %u messages pending (%u is the soft limit)\n"),
1463 ntohs (msg->type), 1467 ntohs (msg->type),
1464 ntohs (msg->size), 1468 ntohs (msg->size), client->message_count, MAX_PENDING);
1465 client->message_count, 1469 GNUNET_STATISTICS_update (stats,
1466 MAX_PENDING); 1470 gettext_noop
1467 GNUNET_STATISTICS_update (stats, 1471 ("# messages dropped due to slow client"), 1,
1468 gettext_noop ("# messages dropped due to slow client"), 1472 GNUNET_NO);
1469 1, 1473 return;
1470 GNUNET_NO); 1474 }
1471 return;
1472 }
1473 msize = ntohs (msg->size); 1475 msize = ntohs (msg->size);
1474 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 1476 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
1475 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); 1477 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
1476 memcpy (&q[1], msg, msize); 1478 memcpy (&q[1], msg, msize);
1477 GNUNET_CONTAINER_DLL_insert_tail (client->message_queue_head, 1479 GNUNET_CONTAINER_DLL_insert_tail (client->message_queue_head,
1478 client->message_queue_tail, 1480 client->message_queue_tail, q);
1479 q);
1480 client->message_count++; 1481 client->message_count++;
1481 if (client->th == NULL) 1482 if (client->th == NULL)
1482 { 1483 {
1483 client->th = GNUNET_SERVER_notify_transmit_ready (client->client, 1484 client->th = GNUNET_SERVER_notify_transmit_ready (client->client,
1484 msize, 1485 msize,
1485 GNUNET_TIME_UNIT_FOREVER_REL, 1486 GNUNET_TIME_UNIT_FOREVER_REL,
1486 &transmit_to_client_callback, 1487 &transmit_to_client_callback,
1487 client); 1488 client);
1488 GNUNET_assert (client->th != NULL); 1489 GNUNET_assert (client->th != NULL);
1489 } 1490 }
1490} 1491}
1491 1492
1492 1493
@@ -1501,9 +1502,8 @@ transmit_to_client (struct TransportClient *client,
1501 */ 1502 */
1502static void 1503static void
1503transmit_send_ok (struct TransportClient *client, 1504transmit_send_ok (struct TransportClient *client,
1504 struct NeighbourMapEntry *n, 1505 struct NeighbourMapEntry *n,
1505 const struct GNUNET_PeerIdentity *target, 1506 const struct GNUNET_PeerIdentity *target, int result)
1506 int result)
1507{ 1507{
1508 struct SendOkMessage send_ok_msg; 1508 struct SendOkMessage send_ok_msg;
1509 1509
@@ -1513,7 +1513,8 @@ transmit_send_ok (struct TransportClient *client,
1513 if (n != NULL) 1513 if (n != NULL)
1514 send_ok_msg.latency = GNUNET_TIME_relative_hton (n->latency); 1514 send_ok_msg.latency = GNUNET_TIME_relative_hton (n->latency);
1515 else 1515 else
1516 send_ok_msg.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL); 1516 send_ok_msg.latency =
1517 GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
1517 send_ok_msg.peer = *target; 1518 send_ok_msg.peer = *target;
1518 transmit_to_client (client, &send_ok_msg.header, GNUNET_NO); 1519 transmit_to_client (client, &send_ok_msg.header, GNUNET_NO);
1519} 1520}
@@ -1526,8 +1527,7 @@ transmit_send_ok (struct TransportClient *client,
1526 * 1527 *
1527 * @param fal address to set to 'connected' 1528 * @param fal address to set to 'connected'
1528 */ 1529 */
1529static void 1530static void mark_address_connected (struct ForeignAddressList *fal);
1530mark_address_connected (struct ForeignAddressList *fal);
1531 1531
1532 1532
1533 1533
@@ -1537,7 +1537,7 @@ mark_address_connected (struct ForeignAddressList *fal);
1537 */ 1537 */
1538static void 1538static void
1539retry_transmission_task (void *cls, 1539retry_transmission_task (void *cls,
1540 const struct GNUNET_SCHEDULER_TaskContext *tc) 1540 const struct GNUNET_SCHEDULER_TaskContext *tc)
1541{ 1541{
1542 struct NeighbourMapEntry *n = cls; 1542 struct NeighbourMapEntry *n = cls;
1543 1543
@@ -1569,67 +1569,62 @@ transmit_send_continuation (void *cls,
1569 struct NeighbourMapEntry *n; 1569 struct NeighbourMapEntry *n;
1570 1570
1571 GNUNET_STATISTICS_update (stats, 1571 GNUNET_STATISTICS_update (stats,
1572 gettext_noop ("# bytes pending with plugins"), 1572 gettext_noop ("# bytes pending with plugins"),
1573 - (int64_t) mq->message_buf_size, 1573 -(int64_t) mq->message_buf_size, GNUNET_NO);
1574 GNUNET_NO);
1575 if (result == GNUNET_OK) 1574 if (result == GNUNET_OK)
1576 { 1575 {
1577 GNUNET_STATISTICS_update (stats, 1576 GNUNET_STATISTICS_update (stats,
1578 gettext_noop ("# bytes successfully transmitted by plugins"), 1577 gettext_noop
1579 mq->message_buf_size, 1578 ("# bytes successfully transmitted by plugins"),
1580 GNUNET_NO); 1579 mq->message_buf_size, GNUNET_NO);
1581 } 1580 }
1582 else 1581 else
1582 {
1583 GNUNET_STATISTICS_update (stats,
1584 gettext_noop
1585 ("# bytes with transmission failure by plugins"),
1586 mq->message_buf_size, GNUNET_NO);
1587 }
1588 if (mq->specific_address != NULL)
1589 {
1590 if (result == GNUNET_OK)
1583 { 1591 {
1584 GNUNET_STATISTICS_update (stats, 1592 mq->specific_address->timeout =
1585 gettext_noop ("# bytes with transmission failure by plugins"), 1593 GNUNET_TIME_relative_to_absolute
1586 mq->message_buf_size, 1594 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1587 GNUNET_NO); 1595 if (mq->specific_address->validated == GNUNET_YES)
1596 mark_address_connected (mq->specific_address);
1588 } 1597 }
1589 if (mq->specific_address != NULL) 1598 else
1590 { 1599 {
1591 if (result == GNUNET_OK) 1600 if (mq->specific_address->connected == GNUNET_YES)
1592 { 1601 {
1593 mq->specific_address->timeout =
1594 GNUNET_TIME_relative_to_absolute
1595 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1596 if (mq->specific_address->validated == GNUNET_YES)
1597 mark_address_connected (mq->specific_address);
1598 }
1599 else
1600 {
1601 if (mq->specific_address->connected == GNUNET_YES)
1602 {
1603#if DEBUG_TRANSPORT 1602#if DEBUG_TRANSPORT
1604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1605 "Marking address `%s' as no longer connected (due to transmission problem)\n", 1604 "Marking address `%s' as no longer connected (due to transmission problem)\n",
1606 a2s (mq->specific_address->ready_list->plugin->short_name, 1605 a2s (mq->specific_address->ready_list->plugin->short_name,
1607 mq->specific_address->addr, 1606 mq->specific_address->addr,
1608 mq->specific_address->addrlen)); 1607 mq->specific_address->addrlen));
1609#endif 1608#endif
1610 GNUNET_STATISTICS_update (stats, 1609 GNUNET_STATISTICS_update (stats,
1611 gettext_noop ("# connected addresses"), 1610 gettext_noop ("# connected addresses"),
1612 -1, 1611 -1, GNUNET_NO);
1613 GNUNET_NO); 1612 mq->specific_address->connected = GNUNET_NO;
1614 mq->specific_address->connected = GNUNET_NO; 1613 }
1615 }
1616 }
1617 if (! mq->internal_msg)
1618 mq->specific_address->in_transmit = GNUNET_NO;
1619 } 1614 }
1615 if (!mq->internal_msg)
1616 mq->specific_address->in_transmit = GNUNET_NO;
1617 }
1620 n = find_neighbour (&mq->neighbour_id); 1618 n = find_neighbour (&mq->neighbour_id);
1621 if (mq->client != NULL) 1619 if (mq->client != NULL)
1622 transmit_send_ok (mq->client, n, target, result); 1620 transmit_send_ok (mq->client, n, target, result);
1623 GNUNET_assert (n != NULL); 1621 GNUNET_assert (n != NULL);
1624 GNUNET_CONTAINER_DLL_remove (n->cont_head, 1622 GNUNET_CONTAINER_DLL_remove (n->cont_head, n->cont_tail, mq);
1625 n->cont_tail,
1626 mq);
1627 GNUNET_free (mq); 1623 GNUNET_free (mq);
1628 if (result == GNUNET_OK) 1624 if (result == GNUNET_OK)
1629 try_transmission_to_peer (n); 1625 try_transmission_to_peer (n);
1630 else if (GNUNET_SCHEDULER_NO_TASK == n->retry_task) 1626 else if (GNUNET_SCHEDULER_NO_TASK == n->retry_task)
1631 n->retry_task = GNUNET_SCHEDULER_add_now (&retry_transmission_task, 1627 n->retry_task = GNUNET_SCHEDULER_add_now (&retry_transmission_task, n);
1632 n);
1633} 1628}
1634 1629
1635 1630
@@ -1649,81 +1644,73 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1649 int force_address; 1644 int force_address;
1650 1645
1651 if (n->messages_head == NULL) 1646 if (n->messages_head == NULL)
1652 { 1647 {
1653#if DEBUG_TRANSPORT 1648#if DEBUG_TRANSPORT
1654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1649 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1655 "Transmission queue for `%4s' is empty\n", 1650 "Transmission queue for `%4s' is empty\n", GNUNET_i2s (&n->id));
1656 GNUNET_i2s (&n->id));
1657#endif 1651#endif
1658 return; /* nothing to do */ 1652 return; /* nothing to do */
1659 } 1653 }
1660 rl = NULL; 1654 rl = NULL;
1661 mq = n->messages_head; 1655 mq = n->messages_head;
1662 force_address = GNUNET_YES; 1656 force_address = GNUNET_YES;
1663 if (mq->specific_address == NULL) 1657 if (mq->specific_address == NULL)
1664 { 1658 {
1665 /* TODO: ADD ATS */ 1659 /* TODO: ADD ATS */
1666 mq->specific_address = get_preferred_ats_address(n); 1660 mq->specific_address = get_preferred_ats_address (n);
1667 GNUNET_STATISTICS_update (stats, 1661 GNUNET_STATISTICS_update (stats,
1668 gettext_noop ("# transport selected peer address freely"), 1662 gettext_noop
1669 1, 1663 ("# transport selected peer address freely"), 1,
1670 GNUNET_NO); 1664 GNUNET_NO);
1671 force_address = GNUNET_NO; 1665 force_address = GNUNET_NO;
1672 } 1666 }
1673 if (mq->specific_address == NULL) 1667 if (mq->specific_address == NULL)
1668 {
1669 GNUNET_STATISTICS_update (stats,
1670 gettext_noop
1671 ("# transport failed to selected peer address"),
1672 1, GNUNET_NO);
1673 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
1674 if (timeout.rel_value == 0)
1674 { 1675 {
1675 GNUNET_STATISTICS_update (stats,
1676 gettext_noop ("# transport failed to selected peer address"),
1677 1,
1678 GNUNET_NO);
1679 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
1680 if (timeout.rel_value == 0)
1681 {
1682#if DEBUG_TRANSPORT 1676#if DEBUG_TRANSPORT
1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1684 "No destination address available to transmit message of size %u to peer `%4s'\n", 1678 "No destination address available to transmit message of size %u to peer `%4s'\n",
1685 mq->message_buf_size, 1679 mq->message_buf_size, GNUNET_i2s (&mq->neighbour_id));
1686 GNUNET_i2s (&mq->neighbour_id));
1687#endif 1680#endif
1688 GNUNET_STATISTICS_update (stats,
1689 gettext_noop ("# bytes in message queue for other peers"),
1690 - (int64_t) mq->message_buf_size,
1691 GNUNET_NO);
1692 GNUNET_STATISTICS_update (stats,
1693 gettext_noop ("# bytes discarded (no destination address available)"),
1694 mq->message_buf_size,
1695 GNUNET_NO);
1696 if (mq->client != NULL)
1697 transmit_send_ok (mq->client, n, &n->id, GNUNET_NO);
1698 GNUNET_CONTAINER_DLL_remove (n->messages_head,
1699 n->messages_tail,
1700 mq);
1701 GNUNET_free (mq);
1702 return; /* nobody ready */
1703 }
1704 GNUNET_STATISTICS_update (stats, 1681 GNUNET_STATISTICS_update (stats,
1705 gettext_noop ("# message delivery deferred (no address)"), 1682 gettext_noop
1706 1, 1683 ("# bytes in message queue for other peers"),
1707 GNUNET_NO); 1684 -(int64_t) mq->message_buf_size, GNUNET_NO);
1708 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK) 1685 GNUNET_STATISTICS_update (stats,
1709 GNUNET_SCHEDULER_cancel (n->retry_task); 1686 gettext_noop
1710 n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout, 1687 ("# bytes discarded (no destination address available)"),
1711 &retry_transmission_task, 1688 mq->message_buf_size, GNUNET_NO);
1712 n); 1689 if (mq->client != NULL)
1690 transmit_send_ok (mq->client, n, &n->id, GNUNET_NO);
1691 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
1692 GNUNET_free (mq);
1693 return; /* nobody ready */
1694 }
1695 GNUNET_STATISTICS_update (stats,
1696 gettext_noop
1697 ("# message delivery deferred (no address)"), 1,
1698 GNUNET_NO);
1699 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
1700 GNUNET_SCHEDULER_cancel (n->retry_task);
1701 n->retry_task = GNUNET_SCHEDULER_add_delayed (timeout,
1702 &retry_transmission_task, n);
1713#if DEBUG_TRANSPORT 1703#if DEBUG_TRANSPORT
1714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1715 "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n", 1705 "No validated destination address available to transmit message of size %u to peer `%4s', will wait %llums to find an address.\n",
1716 mq->message_buf_size, 1706 mq->message_buf_size,
1717 GNUNET_i2s (&mq->neighbour_id), 1707 GNUNET_i2s (&mq->neighbour_id), timeout.rel_value);
1718 timeout.rel_value);
1719#endif 1708#endif
1720 /* FIXME: might want to trigger peerinfo lookup here 1709 /* FIXME: might want to trigger peerinfo lookup here
1721 (unless that's already pending...) */ 1710 * (unless that's already pending...) */
1722 return; 1711 return;
1723 } 1712 }
1724 GNUNET_CONTAINER_DLL_remove (n->messages_head, 1713 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
1725 n->messages_tail,
1726 mq);
1727 if (mq->specific_address->connected == GNUNET_NO) 1714 if (mq->specific_address->connected == GNUNET_NO)
1728 mq->specific_address->connect_attempts++; 1715 mq->specific_address->connect_attempts++;
1729 rl = mq->specific_address->ready_list; 1716 rl = mq->specific_address->ready_list;
@@ -1735,45 +1722,38 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
1735 "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n", 1722 "Sending message of size %u for `%4s' to `%s' via plugin `%s'\n",
1736 mq->message_buf_size, 1723 mq->message_buf_size,
1737 GNUNET_i2s (&n->id), 1724 GNUNET_i2s (&n->id),
1738 (mq->specific_address->addr != NULL) 1725 (mq->specific_address->addr != NULL)
1739 ? a2s (mq->plugin->short_name, 1726 ? a2s (mq->plugin->short_name,
1740 mq->specific_address->addr, 1727 mq->specific_address->addr,
1741 mq->specific_address->addrlen) 1728 mq->specific_address->addrlen)
1742 : "<inbound>", 1729 : "<inbound>", rl->plugin->short_name);
1743 rl->plugin->short_name);
1744#endif 1730#endif
1745 GNUNET_STATISTICS_update (stats, 1731 GNUNET_STATISTICS_update (stats,
1746 gettext_noop ("# bytes in message queue for other peers"), 1732 gettext_noop
1747 - (int64_t) mq->message_buf_size, 1733 ("# bytes in message queue for other peers"),
1748 GNUNET_NO); 1734 -(int64_t) mq->message_buf_size, GNUNET_NO);
1749 GNUNET_STATISTICS_update (stats, 1735 GNUNET_STATISTICS_update (stats,
1750 gettext_noop ("# bytes pending with plugins"), 1736 gettext_noop ("# bytes pending with plugins"),
1751 mq->message_buf_size, 1737 mq->message_buf_size, GNUNET_NO);
1752 GNUNET_NO);
1753 1738
1754 GNUNET_CONTAINER_DLL_insert (n->cont_head, 1739 GNUNET_CONTAINER_DLL_insert (n->cont_head, n->cont_tail, mq);
1755 n->cont_tail,
1756 mq);
1757 1740
1758 ret = rl->plugin->api->send (rl->plugin->api->cls, 1741 ret = rl->plugin->api->send (rl->plugin->api->cls,
1759 &mq->neighbour_id, 1742 &mq->neighbour_id,
1760 mq->message_buf, 1743 mq->message_buf,
1761 mq->message_buf_size, 1744 mq->message_buf_size,
1762 mq->priority, 1745 mq->priority,
1763 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1746 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1764 mq->specific_address->session, 1747 mq->specific_address->session,
1765 mq->specific_address->addr, 1748 mq->specific_address->addr,
1766 mq->specific_address->addrlen, 1749 mq->specific_address->addrlen,
1767 force_address, 1750 force_address, &transmit_send_continuation, mq);
1768 &transmit_send_continuation, mq);
1769 if (ret == -1) 1751 if (ret == -1)
1770 { 1752 {
1771 /* failure, but 'send' would not call continuation in this case, 1753 /* failure, but 'send' would not call continuation in this case,
1772 so we need to do it here! */ 1754 * so we need to do it here! */
1773 transmit_send_continuation (mq, 1755 transmit_send_continuation (mq, &mq->neighbour_id, GNUNET_SYSERR);
1774 &mq->neighbour_id, 1756 }
1775 GNUNET_SYSERR);
1776 }
1777} 1757}
1778 1758
1779 1759
@@ -1794,7 +1774,7 @@ static void
1794transmit_to_peer (struct TransportClient *client, 1774transmit_to_peer (struct TransportClient *client,
1795 struct ForeignAddressList *peer_address, 1775 struct ForeignAddressList *peer_address,
1796 unsigned int priority, 1776 unsigned int priority,
1797 struct GNUNET_TIME_Relative timeout, 1777 struct GNUNET_TIME_Relative timeout,
1798 const char *message_buf, 1778 const char *message_buf,
1799 size_t message_buf_size, 1779 size_t message_buf_size,
1800 int is_internal, struct NeighbourMapEntry *neighbour) 1780 int is_internal, struct NeighbourMapEntry *neighbour)
@@ -1803,46 +1783,45 @@ transmit_to_peer (struct TransportClient *client,
1803 1783
1804#if EXTRA_CHECKS 1784#if EXTRA_CHECKS
1805 if (client != NULL) 1785 if (client != NULL)
1786 {
1787 /* check for duplicate submission */
1788 mq = neighbour->messages_head;
1789 while (NULL != mq)
1806 { 1790 {
1807 /* check for duplicate submission */ 1791 if (mq->client == client)
1808 mq = neighbour->messages_head; 1792 {
1809 while (NULL != mq) 1793 /* client transmitted to same peer twice
1810 { 1794 * before getting SEND_OK! */
1811 if (mq->client == client) 1795 GNUNET_break (0);
1812 { 1796 return;
1813 /* client transmitted to same peer twice 1797 }
1814 before getting SEND_OK! */ 1798 mq = mq->next;
1815 GNUNET_break (0);
1816 return;
1817 }
1818 mq = mq->next;
1819 }
1820 } 1799 }
1800 }
1821#endif 1801#endif
1822 GNUNET_STATISTICS_update (stats, 1802 GNUNET_STATISTICS_update (stats,
1823 gettext_noop ("# bytes in message queue for other peers"), 1803 gettext_noop
1824 message_buf_size, 1804 ("# bytes in message queue for other peers"),
1825 GNUNET_NO); 1805 message_buf_size, GNUNET_NO);
1826 mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size); 1806 mq = GNUNET_malloc (sizeof (struct MessageQueue) + message_buf_size);
1827 mq->specific_address = peer_address; 1807 mq->specific_address = peer_address;
1828 mq->client = client; 1808 mq->client = client;
1829 /* FIXME: this memcpy can be up to 7% of our total runtime! */ 1809 /* FIXME: this memcpy can be up to 7% of our total runtime! */
1830 memcpy (&mq[1], message_buf, message_buf_size); 1810 memcpy (&mq[1], message_buf, message_buf_size);
1831 mq->message_buf = (const char*) &mq[1]; 1811 mq->message_buf = (const char *) &mq[1];
1832 mq->message_buf_size = message_buf_size; 1812 mq->message_buf_size = message_buf_size;
1833 memcpy(&mq->neighbour_id, &neighbour->id, sizeof(struct GNUNET_PeerIdentity)); 1813 memcpy (&mq->neighbour_id, &neighbour->id,
1814 sizeof (struct GNUNET_PeerIdentity));
1834 mq->internal_msg = is_internal; 1815 mq->internal_msg = is_internal;
1835 mq->priority = priority; 1816 mq->priority = priority;
1836 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1817 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1837 if (is_internal) 1818 if (is_internal)
1838 GNUNET_CONTAINER_DLL_insert (neighbour->messages_head, 1819 GNUNET_CONTAINER_DLL_insert (neighbour->messages_head,
1839 neighbour->messages_tail, 1820 neighbour->messages_tail, mq);
1840 mq);
1841 else 1821 else
1842 GNUNET_CONTAINER_DLL_insert_after (neighbour->messages_head, 1822 GNUNET_CONTAINER_DLL_insert_after (neighbour->messages_head,
1843 neighbour->messages_tail, 1823 neighbour->messages_tail,
1844 neighbour->messages_tail, 1824 neighbour->messages_tail, mq);
1845 mq);
1846 try_transmission_to_peer (neighbour); 1825 try_transmission_to_peer (neighbour);
1847} 1826}
1848 1827
@@ -1863,62 +1842,56 @@ transmit_plain_ping (struct NeighbourMapEntry *n)
1863 struct TransportPlugin *plugin; 1842 struct TransportPlugin *plugin;
1864 struct ForeignAddressList *fal; 1843 struct ForeignAddressList *fal;
1865 1844
1866 if (! n->public_key_valid) 1845 if (!n->public_key_valid)
1867 { 1846 {
1868 /* This should not happen since the other peer 1847 /* This should not happen since the other peer
1869 should send us a HELLO prior to sending his 1848 * should send us a HELLO prior to sending his
1870 PING */ 1849 * PING */
1871 GNUNET_break_op (0); 1850 GNUNET_break_op (0);
1872 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1873 "Could not transmit plain PING to `%s': public key not known\n", 1852 "Could not transmit plain PING to `%s': public key not known\n",
1874 GNUNET_i2s (&n->id)); 1853 GNUNET_i2s (&n->id));
1875 return; 1854 return;
1876 } 1855 }
1877 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1878 "Looking for addresses to transmit plain PING to `%s'\n", 1857 "Looking for addresses to transmit plain PING to `%s'\n",
1879 GNUNET_i2s (&n->id)); 1858 GNUNET_i2s (&n->id));
1880 for (rl = n->plugins; rl != NULL; rl = rl->next) 1859 for (rl = n->plugins; rl != NULL; rl = rl->next)
1860 {
1861 plugin = rl->plugin;
1862 for (fal = rl->addresses; fal != NULL; fal = fal->next)
1881 { 1863 {
1882 plugin = rl->plugin; 1864 if (!fal->connected)
1883 for (fal = rl->addresses; fal != NULL; fal = fal->next) 1865 continue;
1884 { 1866 ve = GNUNET_malloc (sizeof (struct ValidationEntry));
1885 if (! fal->connected) 1867 ve->transport_name = GNUNET_strdup (plugin->short_name);
1886 continue; 1868 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
1887 ve = GNUNET_malloc (sizeof (struct ValidationEntry)); 1869 UINT_MAX);
1888 ve->transport_name = GNUNET_strdup (plugin->short_name); 1870 ve->send_time = GNUNET_TIME_absolute_get ();
1889 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 1871 ve->session = fal->session;
1890 UINT_MAX); 1872 memcpy (&ve->publicKey,
1891 ve->send_time = GNUNET_TIME_absolute_get(); 1873 &n->publicKey,
1892 ve->session = fal->session; 1874 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1893 memcpy(&ve->publicKey, 1875 ve->timeout_task =
1894 &n->publicKey, 1876 GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
1895 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1877 &timeout_hello_validation, ve);
1896 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT, 1878 GNUNET_CONTAINER_multihashmap_put (validation_map, &n->id.hashPubKey, ve,
1897 &timeout_hello_validation, 1879 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
1898 ve); 1880 ping.header.size = htons (sizeof (struct TransportPingMessage));
1899 GNUNET_CONTAINER_multihashmap_put (validation_map, 1881 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
1900 &n->id.hashPubKey, 1882 ping.challenge = htonl (ve->challenge);
1901 ve, 1883 memcpy (&ping.target, &n->id, sizeof (struct GNUNET_PeerIdentity));
1902 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 1884 GNUNET_STATISTICS_update (stats,
1903 ping.header.size = htons(sizeof(struct TransportPingMessage)); 1885 gettext_noop
1904 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 1886 ("# PING without HELLO messages sent"), 1,
1905 ping.challenge = htonl(ve->challenge); 1887 GNUNET_NO);
1906 memcpy(&ping.target, &n->id, sizeof(struct GNUNET_PeerIdentity)); 1888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s'\n",
1907 GNUNET_STATISTICS_update (stats, 1889 GNUNET_i2s (&n->id));
1908 gettext_noop ("# PING without HELLO messages sent"), 1890 transmit_to_peer (NULL, fal, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1909 1, 1891 HELLO_VERIFICATION_TIMEOUT, (const char *) &ping,
1910 GNUNET_NO); 1892 sizeof (ping), GNUNET_YES, n);
1911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1912 "Transmitting plain PING to `%s'\n",
1913 GNUNET_i2s (&n->id));
1914 transmit_to_peer (NULL,
1915 fal,
1916 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1917 HELLO_VERIFICATION_TIMEOUT,
1918 (const char*) &ping, sizeof (ping),
1919 GNUNET_YES, n);
1920 }
1921 } 1893 }
1894 }
1922} 1895}
1923 1896
1924 1897
@@ -1930,7 +1903,7 @@ transmit_plain_ping (struct NeighbourMapEntry *n)
1930 * @param fal address to set to 'connected' 1903 * @param fal address to set to 'connected'
1931 */ 1904 */
1932static void 1905static void
1933mark_address_connected(struct ForeignAddressList *fal) 1906mark_address_connected (struct ForeignAddressList *fal)
1934{ 1907{
1935 struct ForeignAddressList *pos; 1908 struct ForeignAddressList *pos;
1936 struct ForeignAddressList *inbound; 1909 struct ForeignAddressList *inbound;
@@ -1938,92 +1911,102 @@ mark_address_connected(struct ForeignAddressList *fal)
1938 1911
1939 GNUNET_assert (GNUNET_YES == fal->validated); 1912 GNUNET_assert (GNUNET_YES == fal->validated);
1940 if (fal->connected == GNUNET_YES) 1913 if (fal->connected == GNUNET_YES)
1941 return; /* nothing to do */ 1914 return; /* nothing to do */
1942 inbound = NULL; 1915 inbound = NULL;
1943 outbound = NULL; 1916 outbound = NULL;
1944 1917
1945 pos = fal->ready_list->addresses; 1918 pos = fal->ready_list->addresses;
1946 while (pos != NULL) 1919 while (pos != NULL)
1947 { 1920 {
1948 /* Already have inbound address, and this is also an inbound address, don't switch!! */ 1921 /* Already have inbound address, and this is also an inbound address, don't switch!! */
1949 if ( (GNUNET_YES == pos->connected) && 1922 if ((GNUNET_YES == pos->connected) &&
1950 (0 == pos->addrlen) && 1923 (0 == pos->addrlen) && (0 == fal->addrlen))
1951 (0 == fal->addrlen) ) 1924 return;
1952 return; 1925 if ((0 == pos->addrlen) && (GNUNET_YES == pos->connected))
1953 if ( (0 == pos->addrlen) && 1926 inbound = pos;
1954 (GNUNET_YES == pos->connected) ) 1927 pos = pos->next;
1955 inbound = pos; 1928 }
1956 pos = pos->next;
1957 }
1958 1929
1959 pos = fal->ready_list->addresses; 1930 pos = fal->ready_list->addresses;
1960 while (pos != NULL) 1931 while (pos != NULL)
1961 { 1932 {
1962 /* Already have outbound address, and this is also an outbound address, don't switch!! */ 1933 /* Already have outbound address, and this is also an outbound address, don't switch!! */
1963 if ( (GNUNET_YES == pos->connected) && 1934 if ((GNUNET_YES == pos->connected) &&
1964 (0 < pos->addrlen) && 1935 (0 < pos->addrlen) && (0 < fal->addrlen))
1965 (0 < fal->addrlen) ) 1936 return;
1966 return; 1937 if ((0 < pos->addrlen) && (GNUNET_YES == pos->connected))
1967 if ( (0 < pos->addrlen) && (GNUNET_YES == pos->connected) ) 1938 outbound = pos;
1968 outbound = pos; 1939 pos = pos->next;
1969 pos = pos->next; 1940 }
1970 }
1971 1941
1972#if DEBUG_INBOUND 1942#if DEBUG_INBOUND
1973 if (inbound != NULL) 1943 if (inbound != NULL)
1974 fprintf(stderr, "Peer: %s, have inbound connection.\n", GNUNET_i2s(&my_identity)); 1944 fprintf (stderr, "Peer: %s, have inbound connection.\n",
1945 GNUNET_i2s (&my_identity));
1975 if (outbound != NULL) 1946 if (outbound != NULL)
1976 fprintf(stderr, "Peer: %s, have outbound connection.\n", GNUNET_i2s(&my_identity)); 1947 fprintf (stderr, "Peer: %s, have outbound connection.\n",
1948 GNUNET_i2s (&my_identity));
1977#endif 1949#endif
1978 1950
1979 /* Have an inbound connection to this peer which is valid; our id is lower, ignore outbound connection! */ 1951 /* Have an inbound connection to this peer which is valid; our id is lower, ignore outbound connection! */
1980 if ((inbound != NULL) && (0 != fal->addrlen) && (1 1952 if ((inbound != NULL) && (0 != fal->addrlen) && (1
1981 == GNUNET_CRYPTO_hash_xorcmp (&inbound->ready_list->neighbour->id.hashPubKey, 1953 ==
1982 &my_identity.hashPubKey, &null_hash))) 1954 GNUNET_CRYPTO_hash_xorcmp
1983 { 1955 (&inbound->
1956 ready_list->neighbour->id.
1957 hashPubKey,
1958 &my_identity.hashPubKey,
1959 &null_hash)))
1960 {
1984#if DEBUG_INBOUND 1961#if DEBUG_INBOUND
1985 fprintf(stderr, "Peer: %s, had inbound connection, ignoring outbound!\n", GNUNET_i2s(&my_identity)); 1962 fprintf (stderr, "Peer: %s, had inbound connection, ignoring outbound!\n",
1963 GNUNET_i2s (&my_identity));
1986#endif 1964#endif
1987 return; 1965 return;
1988 } 1966 }
1989 else if ((outbound != NULL) && (0 == fal->addrlen) && ((-1 1967 else if ((outbound != NULL) && (0 == fal->addrlen) && ((-1
1990 == GNUNET_CRYPTO_hash_xorcmp (&outbound->ready_list->neighbour->id.hashPubKey, 1968 ==
1991 &my_identity.hashPubKey, &null_hash)))) 1969 GNUNET_CRYPTO_hash_xorcmp
1992 { 1970 (&outbound->ready_list->neighbour->
1971 id.hashPubKey,
1972 &my_identity.hashPubKey,
1973 &null_hash))))
1974 {
1993#if DEBUG_INBOUND 1975#if DEBUG_INBOUND
1994 fprintf(stderr, "Peer: %s, have outbound connection, ignoring inbound!\n", GNUNET_i2s(&my_identity)); 1976 fprintf (stderr, "Peer: %s, have outbound connection, ignoring inbound!\n",
1977 GNUNET_i2s (&my_identity));
1995#endif 1978#endif
1996 return; 1979 return;
1997 } 1980 }
1998 1981
1999 pos = fal->ready_list->addresses; 1982 pos = fal->ready_list->addresses;
2000 while (pos != NULL) 1983 while (pos != NULL)
1984 {
1985 if ((GNUNET_YES == pos->connected) && (0 < pos->addrlen))
2001 { 1986 {
2002 if ((GNUNET_YES == pos->connected) && (0 < pos->addrlen))
2003 {
2004#if DEBUG_TRANSPORT 1987#if DEBUG_TRANSPORT
2005 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1988 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2006 "Marking address `%s' as no longer connected (due to connect on other address)\n", 1989 "Marking address `%s' as no longer connected (due to connect on other address)\n",
2007 a2s (pos->ready_list->plugin->short_name, pos->addr, 1990 a2s (pos->ready_list->plugin->short_name, pos->addr,
2008 pos->addrlen)); 1991 pos->addrlen));
2009#endif 1992#endif
2010#if DEBUG_INBOUND 1993#if DEBUG_INBOUND
2011 fprintf(stderr, 1994 fprintf (stderr,
2012 "Peer: %s, setting %s connection to disconnected.\n", 1995 "Peer: %s, setting %s connection to disconnected.\n",
2013 GNUNET_i2s(&my_identity), 1996 GNUNET_i2s (&my_identity),
2014 (0 == pos->addrlen) ? "INBOUND" : "OUTBOUND"); 1997 (0 == pos->addrlen) ? "INBOUND" : "OUTBOUND");
2015#endif 1998#endif
2016 pos->connected = GNUNET_NO; 1999 pos->connected = GNUNET_NO;
2017 GNUNET_STATISTICS_update (stats, 2000 GNUNET_STATISTICS_update (stats,
2018 gettext_noop ("# connected addresses"), -1, 2001 gettext_noop ("# connected addresses"), -1,
2019 GNUNET_NO); 2002 GNUNET_NO);
2020 }
2021 pos = pos->next;
2022 } 2003 }
2004 pos = pos->next;
2005 }
2023 GNUNET_assert (GNUNET_NO == fal->connected); 2006 GNUNET_assert (GNUNET_NO == fal->connected);
2024 fal->connected = GNUNET_YES; 2007 fal->connected = GNUNET_YES;
2025 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"), 2008 GNUNET_STATISTICS_update (stats, gettext_noop ("# connected addresses"),
2026 1, GNUNET_NO); 2009 1, GNUNET_NO);
2027} 2010}
2028 2011
2029 2012
@@ -2037,7 +2020,7 @@ mark_address_connected(struct ForeignAddressList *fal)
2037 * @return selected address, NULL if we have none 2020 * @return selected address, NULL if we have none
2038 */ 2021 */
2039struct ForeignAddressList * 2022struct ForeignAddressList *
2040find_ready_address(struct NeighbourMapEntry *neighbour) 2023find_ready_address (struct NeighbourMapEntry *neighbour)
2041{ 2024{
2042 struct ReadyList *head = neighbour->plugins; 2025 struct ReadyList *head = neighbour->plugins;
2043 struct ForeignAddressList *addresses; 2026 struct ForeignAddressList *addresses;
@@ -2049,95 +2032,93 @@ find_ready_address(struct NeighbourMapEntry *neighbour)
2049 2032
2050 best_address = NULL; 2033 best_address = NULL;
2051 while (head != NULL) 2034 while (head != NULL)
2035 {
2036 addresses = head->addresses;
2037 while (addresses != NULL)
2052 { 2038 {
2053 addresses = head->addresses; 2039 if ((addresses->timeout.abs_value < now.abs_value) &&
2054 while (addresses != NULL) 2040 (addresses->connected == GNUNET_YES))
2055 { 2041 {
2056 if ( (addresses->timeout.abs_value < now.abs_value) &&
2057 (addresses->connected == GNUNET_YES) )
2058 {
2059#if DEBUG_TRANSPORT 2042#if DEBUG_TRANSPORT
2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2061 "Marking long-time inactive connection to `%4s' as down.\n", 2044 "Marking long-time inactive connection to `%4s' as down.\n",
2062 GNUNET_i2s (&neighbour->id)); 2045 GNUNET_i2s (&neighbour->id));
2063#endif 2046#endif
2064 GNUNET_STATISTICS_update (stats, 2047 GNUNET_STATISTICS_update (stats,
2065 gettext_noop ("# connected addresses"), 2048 gettext_noop ("# connected addresses"),
2066 -1, 2049 -1, GNUNET_NO);
2067 GNUNET_NO); 2050 addresses->connected = GNUNET_NO;
2068 addresses->connected = GNUNET_NO; 2051 }
2069 } 2052 addresses = addresses->next;
2070 addresses = addresses->next; 2053 }
2071 }
2072 2054
2073 addresses = head->addresses; 2055 addresses = head->addresses;
2074 while (addresses != NULL) 2056 while (addresses != NULL)
2075 { 2057 {
2076#if DEBUG_TRANSPORT 2058#if DEBUG_TRANSPORT
2077 if (addresses->addr != NULL) 2059 if (addresses->addr != NULL)
2078 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2079 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n", 2061 "Have address `%s' for peer `%4s' (status: %d, %d, %d, %u, %llums, %u)\n",
2080 a2s (head->plugin->short_name, 2062 a2s (head->plugin->short_name,
2081 addresses->addr, 2063 addresses->addr,
2082 addresses->addrlen), 2064 addresses->addrlen),
2083 GNUNET_i2s (&neighbour->id), 2065 GNUNET_i2s (&neighbour->id),
2084 addresses->connected, 2066 addresses->connected,
2085 addresses->in_transmit, 2067 addresses->in_transmit,
2086 addresses->validated, 2068 addresses->validated,
2087 addresses->connect_attempts, 2069 addresses->connect_attempts,
2088 (unsigned long long) addresses->timeout.abs_value, 2070 (unsigned long long) addresses->timeout.abs_value,
2089 (unsigned int) addresses->distance); 2071 (unsigned int) addresses->distance);
2090#endif 2072#endif
2091 if (0==strcmp(head->plugin->short_name,"unix")) 2073 if (0 == strcmp (head->plugin->short_name, "unix"))
2092 { 2074 {
2093 if ( (unix_address == NULL) || 2075 if ((unix_address == NULL) ||
2094 ( (unix_address != NULL) && 2076 ((unix_address != NULL) &&
2095 (addresses->latency.rel_value < unix_address->latency.rel_value) ) ) 2077 (addresses->latency.rel_value < unix_address->latency.rel_value)))
2096 unix_address = addresses; 2078 unix_address = addresses;
2097 } 2079 }
2098 if ( ( (best_address == NULL) || 2080 if (((best_address == NULL) ||
2099 (addresses->connected == GNUNET_YES) || 2081 (addresses->connected == GNUNET_YES) ||
2100 (best_address->connected == GNUNET_NO) ) && 2082 (best_address->connected == GNUNET_NO)) &&
2101 (addresses->in_transmit == GNUNET_NO) && 2083 (addresses->in_transmit == GNUNET_NO) &&
2102 ( (best_address == NULL) || 2084 ((best_address == NULL) ||
2103 (addresses->latency.rel_value < best_address->latency.rel_value)) ) 2085 (addresses->latency.rel_value < best_address->latency.rel_value)))
2104 best_address = addresses; 2086 best_address = addresses;
2105 /* FIXME: also give lower-latency addresses that are not 2087 /* FIXME: also give lower-latency addresses that are not
2106 connected a chance some times... */ 2088 * connected a chance some times... */
2107 addresses = addresses->next; 2089 addresses = addresses->next;
2108 } 2090 }
2109 if (unix_address != NULL) 2091 if (unix_address != NULL)
2110 break; 2092 break;
2111 head = head->next; 2093 head = head->next;
2112 } 2094 }
2113 if (unix_address != NULL) 2095 if (unix_address != NULL)
2114 { 2096 {
2115 best_address = unix_address; 2097 best_address = unix_address;
2116#if DEBUG_TRANSPORT 2098#if DEBUG_TRANSPORT
2117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2099 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2118 "Found UNIX address, forced this address\n"); 2100 "Found UNIX address, forced this address\n");
2119#endif 2101#endif
2120 } 2102 }
2121 if (best_address != NULL) 2103 if (best_address != NULL)
2122 { 2104 {
2123#if DEBUG_TRANSPORT 2105#if DEBUG_TRANSPORT
2124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2125 "Best address found (`%s') has latency of %llu ms.\n", 2107 "Best address found (`%s') has latency of %llu ms.\n",
2126 (best_address->addrlen > 0) 2108 (best_address->addrlen > 0)
2127 ? a2s (best_address->ready_list->plugin->short_name, 2109 ? a2s (best_address->ready_list->plugin->short_name,
2128 best_address->addr, 2110 best_address->addr,
2129 best_address->addrlen) 2111 best_address->addrlen)
2130 : "<inbound>", 2112 : "<inbound>", best_address->latency.rel_value);
2131 best_address->latency.rel_value);
2132#endif 2113#endif
2133 } 2114 }
2134 else 2115 else
2135 { 2116 {
2136 GNUNET_STATISTICS_update (stats, 2117 GNUNET_STATISTICS_update (stats,
2137 gettext_noop ("# transmission attempts failed (no address)"), 2118 gettext_noop
2138 1, 2119 ("# transmission attempts failed (no address)"),
2139 GNUNET_NO); 2120 1, GNUNET_NO);
2140 } 2121 }
2141 2122
2142 return best_address; 2123 return best_address;
2143} 2124}
@@ -2164,15 +2145,15 @@ address_generator (void *cls, size_t max, void *buf)
2164 size_t ret; 2145 size_t ret;
2165 2146
2166 while ((gc->addr_pos == NULL) && (gc->plug_pos != NULL)) 2147 while ((gc->addr_pos == NULL) && (gc->plug_pos != NULL))
2167 { 2148 {
2168 gc->plug_pos = gc->plug_pos->next; 2149 gc->plug_pos = gc->plug_pos->next;
2169 gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL; 2150 gc->addr_pos = (gc->plug_pos != NULL) ? gc->plug_pos->addresses : NULL;
2170 } 2151 }
2171 if (NULL == gc->plug_pos) 2152 if (NULL == gc->plug_pos)
2172 { 2153 {
2173 2154
2174 return 0; 2155 return 0;
2175 } 2156 }
2176 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name, 2157 ret = GNUNET_HELLO_add_address (gc->plug_pos->short_name,
2177 gc->expiration, 2158 gc->expiration,
2178 &gc->addr_pos[1], 2159 &gc->addr_pos[1],
@@ -2184,9 +2165,7 @@ address_generator (void *cls, size_t max, void *buf)
2184 2165
2185 2166
2186static int 2167static int
2187transmit_our_hello_if_pong (void *cls, 2168transmit_our_hello_if_pong (void *cls, const GNUNET_HashCode * key, void *value)
2188 const GNUNET_HashCode *key,
2189 void *value)
2190{ 2169{
2191 struct NeighbourMapEntry *npos = value; 2170 struct NeighbourMapEntry *npos = value;
2192 2171
@@ -2194,18 +2173,16 @@ transmit_our_hello_if_pong (void *cls,
2194 return GNUNET_OK; 2173 return GNUNET_OK;
2195#if DEBUG_TRANSPORT 2174#if DEBUG_TRANSPORT
2196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2197 "Transmitting updated `%s' to neighbour `%4s'\n", 2176 "Transmitting updated `%s' to neighbour `%4s'\n",
2198 "HELLO", GNUNET_i2s (&npos->id)); 2177 "HELLO", GNUNET_i2s (&npos->id));
2199#endif 2178#endif
2200 GNUNET_STATISTICS_update (stats, 2179 GNUNET_STATISTICS_update (stats,
2201 gettext_noop ("# transmitted my HELLO to other peers"), 2180 gettext_noop
2202 1, 2181 ("# transmitted my HELLO to other peers"), 1,
2203 GNUNET_NO); 2182 GNUNET_NO);
2204 transmit_to_peer (NULL, NULL, 0, 2183 transmit_to_peer (NULL, NULL, 0, HELLO_ADDRESS_EXPIRATION,
2205 HELLO_ADDRESS_EXPIRATION, 2184 (const char *) our_hello, GNUNET_HELLO_size (our_hello),
2206 (const char *) our_hello, 2185 GNUNET_NO, npos);
2207 GNUNET_HELLO_size(our_hello),
2208 GNUNET_NO, npos);
2209 return GNUNET_OK; 2186 return GNUNET_OK;
2210} 2187}
2211 2188
@@ -2218,8 +2195,7 @@ transmit_our_hello_if_pong (void *cls,
2218 * @param tc scheduler context 2195 * @param tc scheduler context
2219 */ 2196 */
2220static void 2197static void
2221refresh_hello_task (void *cls, 2198refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2222 const struct GNUNET_SCHEDULER_TaskContext *tc)
2223{ 2199{
2224 struct GNUNET_HELLO_Message *hello; 2200 struct GNUNET_HELLO_Message *hello;
2225 struct TransportClient *cpos; 2201 struct TransportClient *cpos;
@@ -2232,29 +2208,26 @@ refresh_hello_task (void *cls,
2232 hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc); 2208 hello = GNUNET_HELLO_create (&my_public_key, &address_generator, &gc);
2233#if DEBUG_TRANSPORT 2209#if DEBUG_TRANSPORT
2234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 2210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
2235 "Refreshed my `%s', new size is %d\n", "HELLO", GNUNET_HELLO_size(hello)); 2211 "Refreshed my `%s', new size is %d\n", "HELLO",
2212 GNUNET_HELLO_size (hello));
2236#endif 2213#endif
2237 GNUNET_STATISTICS_update (stats, 2214 GNUNET_STATISTICS_update (stats,
2238 gettext_noop ("# refreshed my HELLO"), 2215 gettext_noop ("# refreshed my HELLO"),
2239 1, 2216 1, GNUNET_NO);
2240 GNUNET_NO);
2241 cpos = clients; 2217 cpos = clients;
2242 while (cpos != NULL) 2218 while (cpos != NULL)
2243 { 2219 {
2244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting my HELLO to client!\n");
2245 "Transmitting my HELLO to client!\n"); 2221 transmit_to_client (cpos,
2246 transmit_to_client (cpos, 2222 (const struct GNUNET_MessageHeader *) hello, GNUNET_NO);
2247 (const struct GNUNET_MessageHeader *) hello, 2223 cpos = cpos->next;
2248 GNUNET_NO); 2224 }
2249 cpos = cpos->next;
2250 }
2251 2225
2252 GNUNET_free_non_null (our_hello); 2226 GNUNET_free_non_null (our_hello);
2253 our_hello = hello; 2227 our_hello = hello;
2254 GNUNET_PEERINFO_add_peer (peerinfo, our_hello); 2228 GNUNET_PEERINFO_add_peer (peerinfo, our_hello);
2255 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 2229 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
2256 &transmit_our_hello_if_pong, 2230 &transmit_our_hello_if_pong, NULL);
2257 NULL);
2258} 2231}
2259 2232
2260 2233
@@ -2266,14 +2239,11 @@ static void
2266refresh_hello () 2239refresh_hello ()
2267{ 2240{
2268#if DEBUG_TRANSPORT_HELLO 2241#if DEBUG_TRANSPORT_HELLO
2269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2242 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "refresh_hello() called!\n");
2270 "refresh_hello() called!\n");
2271#endif 2243#endif
2272 if (hello_task != GNUNET_SCHEDULER_NO_TASK) 2244 if (hello_task != GNUNET_SCHEDULER_NO_TASK)
2273 return; 2245 return;
2274 hello_task 2246 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, NULL);
2275 = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
2276 NULL);
2277} 2247}
2278 2248
2279 2249
@@ -2287,9 +2257,7 @@ refresh_hello ()
2287 * @return GNUNET_YES (we should continue to iterate) 2257 * @return GNUNET_YES (we should continue to iterate)
2288 */ 2258 */
2289static int 2259static int
2290remove_session_validations (void *cls, 2260remove_session_validations (void *cls, const GNUNET_HashCode * key, void *value)
2291 const GNUNET_HashCode * key,
2292 void *value)
2293{ 2261{
2294 struct Session *session = cls; 2262 struct Session *session = cls;
2295 struct ValidationEntry *ve = value; 2263 struct ValidationEntry *ve = value;
@@ -2313,34 +2281,32 @@ remove_session_validations (void *cls,
2313 * @param nl neighbour that was disconnected 2281 * @param nl neighbour that was disconnected
2314 */ 2282 */
2315static void 2283static void
2316try_fast_reconnect (struct TransportPlugin *p, 2284try_fast_reconnect (struct TransportPlugin *p, struct NeighbourMapEntry *nl)
2317 struct NeighbourMapEntry *nl)
2318{ 2285{
2319 /* FIXME-MW: fast reconnect / transport switching not implemented... */ 2286 /* FIXME-MW: fast reconnect / transport switching not implemented... */
2320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2287 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "try_fast_reconnect not implemented!\n");
2321 "try_fast_reconnect not implemented!\n");
2322 /* Note: the idea here is to hide problems with transports (or 2288 /* Note: the idea here is to hide problems with transports (or
2323 switching between plugins) from the core to eliminate the need to 2289 * switching between plugins) from the core to eliminate the need to
2324 re-negotiate session keys and the like; OTOH, we should tell core 2290 * re-negotiate session keys and the like; OTOH, we should tell core
2325 quickly (much faster than timeout) `if a connection was lost and 2291 * quickly (much faster than timeout) `if a connection was lost and
2326 could not be re-established (i.e. other peer went down or is 2292 * could not be re-established (i.e. other peer went down or is
2327 unable / refuses to communicate); 2293 * unable / refuses to communicate);
2328 2294 *
2329 So we should consider: 2295 * So we should consider:
2330 1) ideally: our own willingness / need to connect 2296 * 1) ideally: our own willingness / need to connect
2331 2) prior failures to connect to this peer (by plugin) 2297 * 2) prior failures to connect to this peer (by plugin)
2332 3) ideally: reasons why other peer terminated (as far as knowable) 2298 * 3) ideally: reasons why other peer terminated (as far as knowable)
2333 2299 *
2334 Most importantly, it must be POSSIBLE for another peer to terminate 2300 * Most importantly, it must be POSSIBLE for another peer to terminate
2335 a connection for a while (without us instantly re-establishing it). 2301 * a connection for a while (without us instantly re-establishing it).
2336 Similarly, if another peer is gone we should quickly notify CORE. 2302 * Similarly, if another peer is gone we should quickly notify CORE.
2337 OTOH, if there was a minor glitch (i.e. crash of gnunet-service-transport 2303 * OTOH, if there was a minor glitch (i.e. crash of gnunet-service-transport
2338 on the other end), we should reconnect in such a way that BOTH CORE 2304 * on the other end), we should reconnect in such a way that BOTH CORE
2339 services never even notice. 2305 * services never even notice.
2340 Furthermore, the same mechanism (or small variation) could be used 2306 * Furthermore, the same mechanism (or small variation) could be used
2341 to switch to a better-performing plugin (ATS). 2307 * to switch to a better-performing plugin (ATS).
2342 2308 *
2343 Finally, this needs to be tested throughly... */ 2309 * Finally, this needs to be tested throughly... */
2344 2310
2345 /* 2311 /*
2346 * GNUNET_NO in the call below makes transport disconnect the peer, 2312 * GNUNET_NO in the call below makes transport disconnect the peer,
@@ -2355,12 +2321,12 @@ try_fast_reconnect (struct TransportPlugin *p,
2355#if DEBUG_TRANSPORT 2321#if DEBUG_TRANSPORT
2356#endif 2322#endif
2357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2323 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2358 "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&nl->id), 2324 "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&nl->id),
2359 "try_fast_reconnect"); 2325 "try_fast_reconnect");
2360 2326
2361 GNUNET_STATISTICS_update (stats, 2327 GNUNET_STATISTICS_update (stats,
2362 gettext_noop ("# disconnects due to try_fast_reconnect"), 2328 gettext_noop
2363 1, 2329 ("# disconnects due to try_fast_reconnect"), 1,
2364 GNUNET_NO); 2330 GNUNET_NO);
2365#if DISCONNECT || 1 2331#if DISCONNECT || 1
2366 disconnect_neighbour (nl, GNUNET_YES); 2332 disconnect_neighbour (nl, GNUNET_YES);
@@ -2380,9 +2346,9 @@ try_fast_reconnect (struct TransportPlugin *p,
2380 * @param session which session is being destoyed 2346 * @param session which session is being destoyed
2381 */ 2347 */
2382static void 2348static void
2383plugin_env_session_end (void *cls, 2349plugin_env_session_end (void *cls,
2384 const struct GNUNET_PeerIdentity *peer, 2350 const struct GNUNET_PeerIdentity *peer,
2385 struct Session *session) 2351 struct Session *session)
2386{ 2352{
2387 struct TransportPlugin *p = cls; 2353 struct TransportPlugin *p = cls;
2388 struct NeighbourMapEntry *nl; 2354 struct NeighbourMapEntry *nl;
@@ -2392,119 +2358,116 @@ plugin_env_session_end (void *cls,
2392 2358
2393#if DEBUG_TRANSPORT 2359#if DEBUG_TRANSPORT
2394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2395 "Session ended with peer `%4s', %s\n", 2361 "Session ended with peer `%4s', %s\n",
2396 GNUNET_i2s(peer), 2362 GNUNET_i2s (peer), "plugin_env_session_end");
2397 "plugin_env_session_end");
2398#endif 2363#endif
2399 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 2364 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
2400 &remove_session_validations, 2365 &remove_session_validations, session);
2401 session);
2402 nl = find_neighbour (peer); 2366 nl = find_neighbour (peer);
2403 if (nl == NULL) 2367 if (nl == NULL)
2404 { 2368 {
2405#if DEBUG_TRANSPORT 2369#if DEBUG_TRANSPORT
2406 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2407 "No neighbour record found for peer `%4s'\n", 2371 "No neighbour record found for peer `%4s'\n",
2408 GNUNET_i2s(peer)); 2372 GNUNET_i2s (peer));
2409#endif 2373#endif
2410 return; /* was never marked as connected */ 2374 return; /* was never marked as connected */
2411 } 2375 }
2412 rl = nl->plugins; 2376 rl = nl->plugins;
2413 while (rl != NULL) 2377 while (rl != NULL)
2414 { 2378 {
2415 if (rl->plugin == p) 2379 if (rl->plugin == p)
2416 break; 2380 break;
2417 rl = rl->next; 2381 rl = rl->next;
2418 } 2382 }
2419 if (rl == NULL) 2383 if (rl == NULL)
2420 { 2384 {
2421#if DEBUG_TRANSPORT 2385#if DEBUG_TRANSPORT
2422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2423 "Plugin was associated with peer `%4s'\n", 2387 "Plugin was associated with peer `%4s'\n", GNUNET_i2s (peer));
2424 GNUNET_i2s(peer));
2425#endif 2388#endif
2426 GNUNET_STATISTICS_update (stats, 2389 GNUNET_STATISTICS_update (stats,
2427 gettext_noop ("# disconnects due to session end"), 2390 gettext_noop ("# disconnects due to session end"),
2428 1, 2391 1, GNUNET_NO);
2429 GNUNET_NO); 2392 disconnect_neighbour (nl, GNUNET_YES);
2430 disconnect_neighbour (nl, GNUNET_YES); 2393 return;
2431 return; 2394 }
2432 }
2433 prev = NULL; 2395 prev = NULL;
2434 pos = rl->addresses; 2396 pos = rl->addresses;
2435 while ( (pos != NULL) && 2397 while ((pos != NULL) && (pos->session != session))
2436 (pos->session != session) ) 2398 {
2437 { 2399 prev = pos;
2438 prev = pos; 2400 pos = pos->next;
2439 pos = pos->next; 2401 }
2440 }
2441 if (pos == NULL) 2402 if (pos == NULL)
2442 { 2403 {
2443#if DEBUG_TRANSPORT 2404#if DEBUG_TRANSPORT
2444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2445 "Session was never marked as ready for peer `%4s'\n", 2406 "Session was never marked as ready for peer `%4s'\n",
2446 GNUNET_i2s(peer)); 2407 GNUNET_i2s (peer));
2447#endif 2408#endif
2448 2409
2449 int validations_pending = GNUNET_CONTAINER_multihashmap_contains (validation_map, &peer->hashPubKey); 2410 int validations_pending =
2411 GNUNET_CONTAINER_multihashmap_contains (validation_map,
2412 &peer->hashPubKey);
2450 2413
2451 /* No session was marked as ready, but we have pending validations so do not disconnect from neighbour */ 2414 /* No session was marked as ready, but we have pending validations so do not disconnect from neighbour */
2452 if (validations_pending ==GNUNET_YES) 2415 if (validations_pending == GNUNET_YES)
2453 { 2416 {
2454#if DEBUG_TRANSPORT 2417#if DEBUG_TRANSPORT
2455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2456 "Not disconnecting from peer `%4s due to pending address validations\n", GNUNET_i2s(peer)); 2419 "Not disconnecting from peer `%4s due to pending address validations\n",
2420 GNUNET_i2s (peer));
2457#endif 2421#endif
2458 return; 2422 return;
2459 } 2423 }
2460 2424
2461 //FIXME: This conflicts with inbound tcp connections and tcp nat ... debugging in progress 2425 //FIXME: This conflicts with inbound tcp connections and tcp nat ... debugging in progress
2462 GNUNET_STATISTICS_update (stats, 2426 GNUNET_STATISTICS_update (stats,
2463 gettext_noop ("# disconnects due to unready session"), 2427 gettext_noop
2464 1, 2428 ("# disconnects due to unready session"), 1,
2465 GNUNET_NO); 2429 GNUNET_NO);
2466 2430
2467 disconnect_neighbour (nl, GNUNET_YES); 2431 disconnect_neighbour (nl, GNUNET_YES);
2468 return; /* was never marked as connected */ 2432 return; /* was never marked as connected */
2469 } 2433 }
2470 pos->session = NULL; 2434 pos->session = NULL;
2471 if (GNUNET_YES == pos->connected) 2435 if (GNUNET_YES == pos->connected)
2472 { 2436 {
2473 pos->connected = GNUNET_NO; 2437 pos->connected = GNUNET_NO;
2474 GNUNET_STATISTICS_update (stats, 2438 GNUNET_STATISTICS_update (stats,
2475 gettext_noop ("# connected addresses"), 2439 gettext_noop ("# connected addresses"),
2476 -1, 2440 -1, GNUNET_NO);
2477 GNUNET_NO); 2441 }
2478 }
2479 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task) 2442 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
2480 { 2443 {
2481 GNUNET_SCHEDULER_cancel (pos->revalidate_task); 2444 GNUNET_SCHEDULER_cancel (pos->revalidate_task);
2482 pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK; 2445 pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
2483 } 2446 }
2484 2447
2485 if (pos->addrlen != 0) 2448 if (pos->addrlen != 0)
2449 {
2450 if (nl->received_pong != GNUNET_NO)
2486 { 2451 {
2487 if (nl->received_pong != GNUNET_NO) 2452 GNUNET_STATISTICS_update (stats,
2488 { 2453 gettext_noop
2489 GNUNET_STATISTICS_update (stats, 2454 ("# try_fast_reconnect thanks to plugin_env_session_end"),
2490 gettext_noop ("# try_fast_reconnect thanks to plugin_env_session_end"), 2455 1, GNUNET_NO);
2491 1, 2456 if (GNUNET_YES == pos->connected)
2492 GNUNET_NO); 2457 try_fast_reconnect (p, nl);
2493 if (GNUNET_YES == pos->connected)
2494 try_fast_reconnect (p, nl);
2495 }
2496 else
2497 {
2498 GNUNET_STATISTICS_update (stats,
2499 gettext_noop ("# disconnects due to missing pong"),
2500 1,
2501 GNUNET_NO);
2502 /* FIXME this is never true?! See: line 2416*/
2503 if (GNUNET_YES == pos->connected)
2504 disconnect_neighbour (nl, GNUNET_YES);
2505 }
2506 return;
2507 } 2458 }
2459 else
2460 {
2461 GNUNET_STATISTICS_update (stats,
2462 gettext_noop
2463 ("# disconnects due to missing pong"), 1,
2464 GNUNET_NO);
2465 /* FIXME this is never true?! See: line 2416 */
2466 if (GNUNET_YES == pos->connected)
2467 disconnect_neighbour (nl, GNUNET_YES);
2468 }
2469 return;
2470 }
2508 2471
2509 /* was inbound connection, free 'pos' */ 2472 /* was inbound connection, free 'pos' */
2510 if (prev == NULL) 2473 if (prev == NULL)
@@ -2512,59 +2475,56 @@ plugin_env_session_end (void *cls,
2512 else 2475 else
2513 prev->next = pos->next; 2476 prev->next = pos->next;
2514 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task) 2477 if (GNUNET_SCHEDULER_NO_TASK != pos->revalidate_task)
2515 { 2478 {
2516 GNUNET_SCHEDULER_cancel (pos->revalidate_task); 2479 GNUNET_SCHEDULER_cancel (pos->revalidate_task);
2517 pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK; 2480 pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
2518 } 2481 }
2519 GNUNET_free_non_null (pos->ressources); 2482 GNUNET_free_non_null (pos->ressources);
2520 GNUNET_free_non_null (pos->quality); 2483 GNUNET_free_non_null (pos->quality);
2521#if HAVE_LIBGLPK 2484#if HAVE_LIBGLPK
2522 ats_modify_problem_state (ats, ATS_MODIFIED); 2485 ats_modify_problem_state (ats, ATS_MODIFIED);
2523#endif 2486#endif
2524 if (GNUNET_YES != pos->connected) 2487 if (GNUNET_YES != pos->connected)
2525 { 2488 {
2526 /* nothing else to do, connection was never up... */ 2489 /* nothing else to do, connection was never up... */
2527 GNUNET_free (pos); 2490 GNUNET_free (pos);
2528 return; 2491 return;
2529 } 2492 }
2530 pos->connected = GNUNET_NO; 2493 pos->connected = GNUNET_NO;
2531 GNUNET_STATISTICS_update (stats, 2494 GNUNET_STATISTICS_update (stats,
2532 gettext_noop ("# connected addresses"), 2495 gettext_noop ("# connected addresses"),
2533 -1, 2496 -1, GNUNET_NO);
2534 GNUNET_NO);
2535 GNUNET_free (pos); 2497 GNUNET_free (pos);
2536 2498
2537 if (nl->received_pong == GNUNET_NO) 2499 if (nl->received_pong == GNUNET_NO)
2538 { 2500 {
2539 GNUNET_STATISTICS_update (stats, 2501 GNUNET_STATISTICS_update (stats,
2540 gettext_noop ("# disconnects due to NO pong"), 2502 gettext_noop ("# disconnects due to NO pong"),
2541 1, 2503 1, GNUNET_NO);
2542 GNUNET_NO); 2504 disconnect_neighbour (nl, GNUNET_YES);
2543 disconnect_neighbour (nl, GNUNET_YES); 2505 return; /* nothing to do, never connected... */
2544 return; /* nothing to do, never connected... */ 2506 }
2545 }
2546 /* check if we have any validated addresses left */ 2507 /* check if we have any validated addresses left */
2547 pos = rl->addresses; 2508 pos = rl->addresses;
2548 while (pos != NULL) 2509 while (pos != NULL)
2510 {
2511 if (GNUNET_YES == pos->validated)
2549 { 2512 {
2550 if (GNUNET_YES == pos->validated) 2513 GNUNET_STATISTICS_update (stats,
2551 { 2514 gettext_noop
2552 GNUNET_STATISTICS_update (stats, 2515 ("# try_fast_reconnect thanks to validated_address"),
2553 gettext_noop ("# try_fast_reconnect thanks to validated_address"), 2516 1, GNUNET_NO);
2554 1, 2517 try_fast_reconnect (p, nl);
2555 GNUNET_NO); 2518 return;
2556 try_fast_reconnect (p, nl);
2557 return;
2558 }
2559 pos = pos->next;
2560 } 2519 }
2520 pos = pos->next;
2521 }
2561 /* no valid addresses left, signal disconnect! */ 2522 /* no valid addresses left, signal disconnect! */
2562 2523
2563#if DEBUG_TRANSPORT 2524#if DEBUG_TRANSPORT
2564 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2565 "Disconnecting peer `%4s', %s\n", 2526 "Disconnecting peer `%4s', %s\n",
2566 GNUNET_i2s(peer), 2527 GNUNET_i2s (peer), "plugin_env_session_end");
2567 "plugin_env_session_end");
2568#endif 2528#endif
2569 /* FIXME: This doesn't mean there are no addresses left for this PEER, 2529 /* FIXME: This doesn't mean there are no addresses left for this PEER,
2570 * it means there aren't any left for this PLUGIN/PEER combination! So 2530 * it means there aren't any left for this PLUGIN/PEER combination! So
@@ -2574,8 +2534,8 @@ plugin_env_session_end (void *cls,
2574 * --NE 2534 * --NE
2575 */ 2535 */
2576 GNUNET_STATISTICS_update (stats, 2536 GNUNET_STATISTICS_update (stats,
2577 gettext_noop ("# disconnects due to plugin_env_session_end"), 2537 gettext_noop
2578 1, 2538 ("# disconnects due to plugin_env_session_end"), 1,
2579 GNUNET_NO); 2539 GNUNET_NO);
2580 disconnect_neighbour (nl, GNUNET_YES); 2540 disconnect_neighbour (nl, GNUNET_YES);
2581} 2541}
@@ -2594,9 +2554,7 @@ plugin_env_session_end (void *cls,
2594 */ 2554 */
2595static void 2555static void
2596plugin_env_notify_address (void *cls, 2556plugin_env_notify_address (void *cls,
2597 int add_remove, 2557 int add_remove, const void *addr, size_t addrlen)
2598 const void *addr,
2599 size_t addrlen)
2600{ 2558{
2601 struct TransportPlugin *p = cls; 2559 struct TransportPlugin *p = cls;
2602 struct OwnAddressList *al; 2560 struct OwnAddressList *al;
@@ -2605,37 +2563,34 @@ plugin_env_notify_address (void *cls,
2605 GNUNET_assert (p->api != NULL); 2563 GNUNET_assert (p->api != NULL);
2606#if DEBUG_TRANSPORT 2564#if DEBUG_TRANSPORT
2607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2608 (add_remove == GNUNET_YES) 2566 (add_remove == GNUNET_YES)
2609 ? "Adding `%s':%s to the set of our addresses\n" 2567 ? "Adding `%s':%s to the set of our addresses\n"
2610 : "Removing `%s':%s from the set of our addresses\n", 2568 : "Removing `%s':%s from the set of our addresses\n",
2611 a2s (p->short_name, 2569 a2s (p->short_name, addr, addrlen), p->short_name);
2612 addr, addrlen),
2613 p->short_name);
2614#endif 2570#endif
2615 GNUNET_assert (addr != NULL); 2571 GNUNET_assert (addr != NULL);
2616 if (GNUNET_NO == add_remove) 2572 if (GNUNET_NO == add_remove)
2573 {
2574 prev = NULL;
2575 al = p->addresses;
2576 while (al != NULL)
2617 { 2577 {
2618 prev = NULL; 2578 if ((addrlen == al->addrlen) && (0 == memcmp (addr, &al[1], addrlen)))
2619 al = p->addresses; 2579 {
2620 while (al != NULL) 2580 if (prev == NULL)
2621 { 2581 p->addresses = al->next;
2622 if ( (addrlen == al->addrlen) && 2582 else
2623 (0 == memcmp (addr, &al[1], addrlen)) ) 2583 prev->next = al->next;
2624 { 2584 GNUNET_free (al);
2625 if (prev == NULL) 2585 refresh_hello ();
2626 p->addresses = al->next; 2586 return;
2627 else 2587 }
2628 prev->next = al->next; 2588 prev = al;
2629 GNUNET_free (al); 2589 al = al->next;
2630 refresh_hello ();
2631 return;
2632 }
2633 prev = al;
2634 al = al->next;
2635 }
2636 GNUNET_break (0);
2637 return;
2638 } 2590 }
2591 GNUNET_break (0);
2592 return;
2593 }
2639 al = GNUNET_malloc (sizeof (struct OwnAddressList) + addrlen); 2594 al = GNUNET_malloc (sizeof (struct OwnAddressList) + addrlen);
2640 al->next = p->addresses; 2595 al->next = p->addresses;
2641 p->addresses = al; 2596 p->addresses = al;
@@ -2650,38 +2605,35 @@ plugin_env_notify_address (void *cls,
2650 */ 2605 */
2651static void 2606static void
2652notify_clients_connect (const struct GNUNET_PeerIdentity *peer, 2607notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
2653 struct GNUNET_TIME_Relative latency, 2608 struct GNUNET_TIME_Relative latency, uint32_t distance)
2654 uint32_t distance)
2655{ 2609{
2656 struct ConnectInfoMessage * cim; 2610 struct ConnectInfoMessage *cim;
2657 struct TransportClient *cpos; 2611 struct TransportClient *cpos;
2658 uint32_t ats_count; 2612 uint32_t ats_count;
2659 size_t size; 2613 size_t size;
2660 2614
2661 if (0 == memcmp (peer, 2615 if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
2662 &my_identity, 2616 {
2663 sizeof (struct GNUNET_PeerIdentity))) 2617 GNUNET_break (0);
2664 { 2618 return;
2665 GNUNET_break (0); 2619 }
2666 return;
2667 }
2668#if DEBUG_TRANSPORT 2620#if DEBUG_TRANSPORT
2669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2670 "Notifying clients about connection with `%s'\n", 2622 "Notifying clients about connection with `%s'\n",
2671 GNUNET_i2s (peer)); 2623 GNUNET_i2s (peer));
2672#endif 2624#endif
2673 GNUNET_STATISTICS_update (stats, 2625 GNUNET_STATISTICS_update (stats,
2674 gettext_noop ("# peers connected"), 2626 gettext_noop ("# peers connected"), 1, GNUNET_NO);
2675 1,
2676 GNUNET_NO);
2677 2627
2678 ats_count = 2; 2628 ats_count = 2;
2679 size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 2629 size =
2630 sizeof (struct ConnectInfoMessage) +
2631 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
2680 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 2632 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
2681 cim = GNUNET_malloc (size); 2633 cim = GNUNET_malloc (size);
2682 cim->header.size = htons (size); 2634 cim->header.size = htons (size);
2683 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 2635 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
2684 cim->ats_count = htonl(2); 2636 cim->ats_count = htonl (2);
2685 (&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 2637 (&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
2686 (&cim->ats)[0].value = htonl (distance); 2638 (&cim->ats)[0].value = htonl (distance);
2687 (&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); 2639 (&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
@@ -2692,18 +2644,18 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer,
2692 2644
2693 /* notify ats about connecting peer */ 2645 /* notify ats about connecting peer */
2694 if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO)) 2646 if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO))
2695 { 2647 {
2696#if HAVE_LIBGLPK 2648#if HAVE_LIBGLPK
2697 ats_modify_problem_state(ats, ATS_MODIFIED); 2649 ats_modify_problem_state (ats, ATS_MODIFIED);
2698 ats_calculate_bandwidth_distribution (ats); 2650 ats_calculate_bandwidth_distribution (ats);
2699#endif 2651#endif
2700 } 2652 }
2701 cpos = clients; 2653 cpos = clients;
2702 while (cpos != NULL) 2654 while (cpos != NULL)
2703 { 2655 {
2704 transmit_to_client (cpos, &cim->header, GNUNET_NO); 2656 transmit_to_client (cpos, &cim->header, GNUNET_NO);
2705 cpos = cpos->next; 2657 cpos = cpos->next;
2706 } 2658 }
2707 GNUNET_free (cim); 2659 GNUNET_free (cim);
2708} 2660}
2709 2661
@@ -2717,22 +2669,18 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
2717 struct DisconnectInfoMessage dim; 2669 struct DisconnectInfoMessage dim;
2718 struct TransportClient *cpos; 2670 struct TransportClient *cpos;
2719 2671
2720 if (0 == memcmp (peer, 2672 if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
2721 &my_identity, 2673 {
2722 sizeof (struct GNUNET_PeerIdentity))) 2674 GNUNET_break (0);
2723 { 2675 return;
2724 GNUNET_break (0); 2676 }
2725 return;
2726 }
2727#if DEBUG_TRANSPORT 2677#if DEBUG_TRANSPORT
2728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2729 "Notifying clients about lost connection to `%s'\n", 2679 "Notifying clients about lost connection to `%s'\n",
2730 GNUNET_i2s (peer)); 2680 GNUNET_i2s (peer));
2731#endif 2681#endif
2732 GNUNET_STATISTICS_update (stats, 2682 GNUNET_STATISTICS_update (stats,
2733 gettext_noop ("# peers connected"), 2683 gettext_noop ("# peers connected"), -1, GNUNET_NO);
2734 -1,
2735 GNUNET_NO);
2736 dim.header.size = htons (sizeof (struct DisconnectInfoMessage)); 2684 dim.header.size = htons (sizeof (struct DisconnectInfoMessage));
2737 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT); 2685 dim.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
2738 dim.reserved = htonl (0); 2686 dim.reserved = htonl (0);
@@ -2742,17 +2690,17 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
2742 if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO)) 2690 if ((ats != NULL) && (shutdown_in_progress == GNUNET_NO))
2743 { 2691 {
2744#if HAVE_LIBGLPK 2692#if HAVE_LIBGLPK
2745 ats_modify_problem_state(ats, ATS_MODIFIED); 2693 ats_modify_problem_state (ats, ATS_MODIFIED);
2746 ats_calculate_bandwidth_distribution (ats); 2694 ats_calculate_bandwidth_distribution (ats);
2747#endif 2695#endif
2748 } 2696 }
2749 2697
2750 cpos = clients; 2698 cpos = clients;
2751 while (cpos != NULL) 2699 while (cpos != NULL)
2752 { 2700 {
2753 transmit_to_client (cpos, &dim.header, GNUNET_NO); 2701 transmit_to_client (cpos, &dim.header, GNUNET_NO);
2754 cpos = cpos->next; 2702 cpos = cpos->next;
2755 } 2703 }
2756} 2704}
2757 2705
2758 2706
@@ -2770,36 +2718,33 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
2770 * @return NULL if no such entry exists 2718 * @return NULL if no such entry exists
2771 */ 2719 */
2772static struct ForeignAddressList * 2720static struct ForeignAddressList *
2773find_peer_address(struct NeighbourMapEntry *neighbour, 2721find_peer_address (struct NeighbourMapEntry *neighbour,
2774 const char *tname, 2722 const char *tname,
2775 struct Session *session, 2723 struct Session *session, const char *addr, uint16_t addrlen)
2776 const char *addr,
2777 uint16_t addrlen)
2778{ 2724{
2779 struct ReadyList *head; 2725 struct ReadyList *head;
2780 struct ForeignAddressList *pos; 2726 struct ForeignAddressList *pos;
2781 2727
2782 head = neighbour->plugins; 2728 head = neighbour->plugins;
2783 while (head != NULL) 2729 while (head != NULL)
2784 { 2730 {
2785 if (0 == strcmp (tname, head->plugin->short_name)) 2731 if (0 == strcmp (tname, head->plugin->short_name))
2786 break; 2732 break;
2787 head = head->next; 2733 head = head->next;
2788 } 2734 }
2789 if (head == NULL) 2735 if (head == NULL)
2790 return NULL; 2736 return NULL;
2791 pos = head->addresses; 2737 pos = head->addresses;
2792 while ( (pos != NULL) && 2738 while ((pos != NULL) &&
2793 ( (pos->addrlen != addrlen) || 2739 ((pos->addrlen != addrlen) ||
2794 (memcmp(pos->addr, addr, addrlen) != 0) ) ) 2740 (memcmp (pos->addr, addr, addrlen) != 0)))
2795 { 2741 {
2796 if ( (session != NULL) && 2742 if ((session != NULL) && (pos->session == session))
2797 (pos->session == session) ) 2743 return pos;
2798 return pos; 2744 pos = pos->next;
2799 pos = pos->next; 2745 }
2800 } 2746 if ((session != NULL) && (pos != NULL))
2801 if ( (session != NULL) && (pos != NULL) ) 2747 pos->session = session; /* learn it! */
2802 pos->session = session; /* learn it! */
2803 return pos; 2748 return pos;
2804} 2749}
2805 2750
@@ -2817,10 +2762,8 @@ find_peer_address(struct NeighbourMapEntry *neighbour,
2817 */ 2762 */
2818static struct ForeignAddressList * 2763static struct ForeignAddressList *
2819add_peer_address (struct NeighbourMapEntry *neighbour, 2764add_peer_address (struct NeighbourMapEntry *neighbour,
2820 const char *tname, 2765 const char *tname,
2821 struct Session *session, 2766 struct Session *session, const char *addr, uint16_t addrlen)
2822 const char *addr,
2823 uint16_t addrlen)
2824{ 2767{
2825 struct ReadyList *head; 2768 struct ReadyList *head;
2826 struct ForeignAddressList *ret; 2769 struct ForeignAddressList *ret;
@@ -2832,73 +2775,78 @@ add_peer_address (struct NeighbourMapEntry *neighbour,
2832 head = neighbour->plugins; 2775 head = neighbour->plugins;
2833 2776
2834 while (head != NULL) 2777 while (head != NULL)
2835 { 2778 {
2836 if (0 == strcmp (tname, head->plugin->short_name)) 2779 if (0 == strcmp (tname, head->plugin->short_name))
2837 break; 2780 break;
2838 head = head->next; 2781 head = head->next;
2839 } 2782 }
2840 if (head == NULL) 2783 if (head == NULL)
2841 return NULL; 2784 return NULL;
2842 ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen); 2785 ret = GNUNET_malloc (sizeof (struct ForeignAddressList) + addrlen);
2843 ret->session = session; 2786 ret->session = session;
2844 if ((addrlen > 0) && (addr != NULL)) 2787 if ((addrlen > 0) && (addr != NULL))
2788 {
2789 ret->addr = (const char *) &ret[1];
2790 memcpy (&ret[1], addr, addrlen);
2791 }
2792 else
2793 {
2794 ret->addr = NULL;
2795 }
2796
2797 ret->ressources =
2798 GNUNET_malloc (available_ressources *
2799 sizeof (struct ATS_ressource_entry));
2800 for (c = 0; c < available_ressources; c++)
2801 {
2802 struct ATS_ressource_entry *r = ret->ressources;
2803
2804 r[c].index = c;
2805 r[c].atis_index = ressources[c].atis_index;
2806 if (0 == strcmp (neighbour->plugins->plugin->short_name, "unix"))
2845 { 2807 {
2846 ret->addr = (const char*) &ret[1]; 2808 r[c].c = ressources[c].c_unix;
2847 memcpy (&ret[1], addr, addrlen);
2848 } 2809 }
2849 else 2810 else if (0 == strcmp (neighbour->plugins->plugin->short_name, "udp"))
2850 { 2811 {
2851 ret->addr = NULL; 2812 r[c].c = ressources[c].c_udp;
2852 } 2813 }
2853 2814 else if (0 == strcmp (neighbour->plugins->plugin->short_name, "tcp"))
2854 ret->ressources = GNUNET_malloc(available_ressources * sizeof (struct ATS_ressource_entry));
2855 for (c=0; c<available_ressources; c++)
2856 { 2815 {
2857 struct ATS_ressource_entry *r = ret->ressources; 2816 r[c].c = ressources[c].c_tcp;
2858 r[c].index = c; 2817 }
2859 r[c].atis_index = ressources[c].atis_index; 2818 else if (0 == strcmp (neighbour->plugins->plugin->short_name, "http"))
2860 if (0 == strcmp(neighbour->plugins->plugin->short_name,"unix")) 2819 {
2861 { 2820 r[c].c = ressources[c].c_http;
2862 r[c].c = ressources[c].c_unix; 2821 }
2863 } 2822 else if (0 == strcmp (neighbour->plugins->plugin->short_name, "https"))
2864 else if (0 == strcmp(neighbour->plugins->plugin->short_name,"udp")) 2823 {
2865 { 2824 r[c].c = ressources[c].c_https;
2866 r[c].c = ressources[c].c_udp;
2867 }
2868 else if (0 == strcmp(neighbour->plugins->plugin->short_name,"tcp"))
2869 {
2870 r[c].c = ressources[c].c_tcp;
2871 }
2872 else if (0 == strcmp(neighbour->plugins->plugin->short_name,"http"))
2873 {
2874 r[c].c = ressources[c].c_http;
2875 }
2876 else if (0 == strcmp(neighbour->plugins->plugin->short_name,"https"))
2877 {
2878 r[c].c = ressources[c].c_https;
2879 }
2880 else if (0 == strcmp(neighbour->plugins->plugin->short_name,"wlan"))
2881 {
2882 r[c].c = ressources[c].c_wlan;
2883 }
2884 else
2885 {
2886 r[c].c = ressources[c].c_default;
2887 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2888 "Assigning default cost to peer `%s' addr plugin `%s'! This should not happen!\n",
2889 GNUNET_i2s(&neighbour->id),
2890 neighbour->plugins->plugin->short_name);
2891 }
2892 } 2825 }
2826 else if (0 == strcmp (neighbour->plugins->plugin->short_name, "wlan"))
2827 {
2828 r[c].c = ressources[c].c_wlan;
2829 }
2830 else
2831 {
2832 r[c].c = ressources[c].c_default;
2833 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2834 "Assigning default cost to peer `%s' addr plugin `%s'! This should not happen!\n",
2835 GNUNET_i2s (&neighbour->id),
2836 neighbour->plugins->plugin->short_name);
2837 }
2838 }
2893 2839
2894 ret->quality = GNUNET_malloc (available_quality_metrics * sizeof (struct ATS_quality_entry)); 2840 ret->quality =
2841 GNUNET_malloc (available_quality_metrics *
2842 sizeof (struct ATS_quality_entry));
2895 ret->addrlen = addrlen; 2843 ret->addrlen = addrlen;
2896 ret->expires = GNUNET_TIME_relative_to_absolute 2844 ret->expires = GNUNET_TIME_relative_to_absolute
2897 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2845 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2898 ret->latency = GNUNET_TIME_relative_get_forever(); 2846 ret->latency = GNUNET_TIME_relative_get_forever ();
2899 ret->distance = -1; 2847 ret->distance = -1;
2900 ret->timeout = GNUNET_TIME_relative_to_absolute 2848 ret->timeout = GNUNET_TIME_relative_to_absolute
2901 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 2849 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
2902 ret->ready_list = head; 2850 ret->ready_list = head;
2903 ret->next = head->addresses; 2851 ret->next = head->addresses;
2904 head->addresses = ret; 2852 head->addresses = ret;
@@ -2936,8 +2884,7 @@ struct AddValidatedAddressContext
2936 * end of the iteration. 2884 * end of the iteration.
2937 */ 2885 */
2938static size_t 2886static size_t
2939add_validated_address (void *cls, 2887add_validated_address (void *cls, size_t max, void *buf)
2940 size_t max, void *buf)
2941{ 2888{
2942 struct AddValidatedAddressContext *avac = cls; 2889 struct AddValidatedAddressContext *avac = cls;
2943 const struct ValidationEntry *ve = avac->ve; 2890 const struct ValidationEntry *ve = avac->ve;
@@ -2946,11 +2893,9 @@ add_validated_address (void *cls,
2946 return 0; 2893 return 0;
2947 avac->done = GNUNET_YES; 2894 avac->done = GNUNET_YES;
2948 return GNUNET_HELLO_add_address (ve->transport_name, 2895 return GNUNET_HELLO_add_address (ve->transport_name,
2949 GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION), 2896 GNUNET_TIME_relative_to_absolute
2950 ve->addr, 2897 (HELLO_ADDRESS_EXPIRATION), ve->addr,
2951 ve->addrlen, 2898 ve->addrlen, buf, max);
2952 buf,
2953 max);
2954} 2899}
2955 2900
2956 2901
@@ -3000,36 +2945,31 @@ struct CheckAddressExistsClosure
3000 * iterate (mismatch), GNUNET_NO if not (entry matched) 2945 * iterate (mismatch), GNUNET_NO if not (entry matched)
3001 */ 2946 */
3002static int 2947static int
3003check_address_exists (void *cls, 2948check_address_exists (void *cls, const GNUNET_HashCode * key, void *value)
3004 const GNUNET_HashCode * key,
3005 void *value)
3006{ 2949{
3007 struct CheckAddressExistsClosure *caec = cls; 2950 struct CheckAddressExistsClosure *caec = cls;
3008 struct ValidationEntry *ve = value; 2951 struct ValidationEntry *ve = value;
3009 2952
3010 if ( (0 == strcmp (caec->tname, 2953 if ((0 == strcmp (caec->tname,
3011 ve->transport_name)) && 2954 ve->transport_name)) &&
3012 (caec->addrlen == ve->addrlen) && 2955 (caec->addrlen == ve->addrlen) &&
3013 (0 == memcmp (caec->addr, 2956 (0 == memcmp (caec->addr, ve->addr, caec->addrlen)))
3014 ve->addr, 2957 {
3015 caec->addrlen)) ) 2958 caec->exists = GNUNET_YES;
3016 { 2959 return GNUNET_NO;
3017 caec->exists = GNUNET_YES; 2960 }
3018 return GNUNET_NO; 2961 if ((ve->session != NULL) && (caec->session == ve->session))
3019 } 2962 {
3020 if ( (ve->session != NULL) && 2963 caec->exists = GNUNET_YES;
3021 (caec->session == ve->session) ) 2964 return GNUNET_NO;
3022 { 2965 }
3023 caec->exists = GNUNET_YES;
3024 return GNUNET_NO;
3025 }
3026 return GNUNET_YES; 2966 return GNUNET_YES;
3027} 2967}
3028 2968
3029 2969
3030static void 2970static void
3031neighbour_timeout_task (void *cls, 2971neighbour_timeout_task (void *cls,
3032 const struct GNUNET_SCHEDULER_TaskContext *tc) 2972 const struct GNUNET_SCHEDULER_TaskContext *tc)
3033{ 2973{
3034 struct NeighbourMapEntry *n = cls; 2974 struct NeighbourMapEntry *n = cls;
3035 2975
@@ -3038,9 +2978,8 @@ neighbour_timeout_task (void *cls,
3038 "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id)); 2978 "Neighbour `%4s' has timed out!\n", GNUNET_i2s (&n->id));
3039#endif 2979#endif
3040 GNUNET_STATISTICS_update (stats, 2980 GNUNET_STATISTICS_update (stats,
3041 gettext_noop ("# disconnects due to timeout"), 2981 gettext_noop ("# disconnects due to timeout"),
3042 1, 2982 1, GNUNET_NO);
3043 GNUNET_NO);
3044 n->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2983 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
3045 disconnect_neighbour (n, GNUNET_NO); 2984 disconnect_neighbour (n, GNUNET_NO);
3046} 2985}
@@ -3052,8 +2991,7 @@ neighbour_timeout_task (void *cls,
3052 * 2991 *
3053 * @param fal address to PING 2992 * @param fal address to PING
3054 */ 2993 */
3055static void 2994static void schedule_next_ping (struct ForeignAddressList *fal);
3056schedule_next_ping (struct ForeignAddressList *fal);
3057 2995
3058 2996
3059/** 2997/**
@@ -3069,77 +3007,71 @@ schedule_next_ping (struct ForeignAddressList *fal);
3069 */ 3007 */
3070static int 3008static int
3071add_to_foreign_address_list (void *cls, 3009add_to_foreign_address_list (void *cls,
3072 const char *tname, 3010 const char *tname,
3073 struct GNUNET_TIME_Absolute expiration, 3011 struct GNUNET_TIME_Absolute expiration,
3074 const void *addr, 3012 const void *addr, uint16_t addrlen)
3075 uint16_t addrlen)
3076{ 3013{
3077 struct NeighbourMapEntry *n = cls; 3014 struct NeighbourMapEntry *n = cls;
3078 struct ForeignAddressList *fal; 3015 struct ForeignAddressList *fal;
3079 int try; 3016 int try;
3080 3017
3081 GNUNET_STATISTICS_update (stats, 3018 GNUNET_STATISTICS_update (stats,
3082 gettext_noop ("# valid peer addresses returned by PEERINFO"), 3019 gettext_noop
3083 1, 3020 ("# valid peer addresses returned by PEERINFO"), 1,
3084 GNUNET_NO); 3021 GNUNET_NO);
3085 try = GNUNET_NO; 3022 try = GNUNET_NO;
3086 fal = find_peer_address (n, tname, NULL, addr, addrlen); 3023 fal = find_peer_address (n, tname, NULL, addr, addrlen);
3087 if (fal == NULL) 3024 if (fal == NULL)
3088 { 3025 {
3089#if DEBUG_TRANSPORT_HELLO 3026#if DEBUG_TRANSPORT_HELLO
3090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3091 "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n", 3028 "Adding address `%s' (%s) for peer `%4s' due to PEERINFO data for %llums.\n",
3092 a2s (tname, addr, addrlen), 3029 a2s (tname, addr, addrlen),
3093 tname, 3030 tname, GNUNET_i2s (&n->id), expiration.abs_value);
3094 GNUNET_i2s (&n->id),
3095 expiration.abs_value);
3096#endif 3031#endif
3097 fal = add_peer_address (n, tname, NULL, addr, addrlen); 3032 fal = add_peer_address (n, tname, NULL, addr, addrlen);
3098 if (fal == NULL) 3033 if (fal == NULL)
3099 { 3034 {
3100 GNUNET_STATISTICS_update (stats, 3035 GNUNET_STATISTICS_update (stats,
3101 gettext_noop ("# previously validated addresses lacking transport"), 3036 gettext_noop
3102 1, 3037 ("# previously validated addresses lacking transport"),
3103 GNUNET_NO); 3038 1, GNUNET_NO);
3104 }
3105 else
3106 {
3107 fal->expires = GNUNET_TIME_absolute_max (expiration,
3108 fal->expires);
3109 schedule_next_ping (fal);
3110 }
3111 try = GNUNET_YES;
3112 } 3039 }
3113 else 3040 else
3114 { 3041 {
3115 fal->expires = GNUNET_TIME_absolute_max (expiration, 3042 fal->expires = GNUNET_TIME_absolute_max (expiration, fal->expires);
3116 fal->expires); 3043 schedule_next_ping (fal);
3117 } 3044 }
3045 try = GNUNET_YES;
3046 }
3047 else
3048 {
3049 fal->expires = GNUNET_TIME_absolute_max (expiration, fal->expires);
3050 }
3118 if (fal == NULL) 3051 if (fal == NULL)
3119 { 3052 {
3120#if DEBUG_TRANSPORT 3053#if DEBUG_TRANSPORT
3121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3122 "Failed to add new address for `%4s'\n", 3055 "Failed to add new address for `%4s'\n", GNUNET_i2s (&n->id));
3123 GNUNET_i2s (&n->id));
3124#endif 3056#endif
3125 return GNUNET_OK; 3057 return GNUNET_OK;
3126 } 3058 }
3127 if (fal->validated == GNUNET_NO) 3059 if (fal->validated == GNUNET_NO)
3128 { 3060 {
3129 fal->validated = GNUNET_YES; 3061 fal->validated = GNUNET_YES;
3130 GNUNET_STATISTICS_update (stats, 3062 GNUNET_STATISTICS_update (stats,
3131 gettext_noop ("# peer addresses considered valid"), 3063 gettext_noop
3132 1, 3064 ("# peer addresses considered valid"), 1,
3133 GNUNET_NO); 3065 GNUNET_NO);
3134 } 3066 }
3135 if (try == GNUNET_YES) 3067 if (try == GNUNET_YES)
3136 { 3068 {
3137#if DEBUG_TRANSPORT 3069#if DEBUG_TRANSPORT
3138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3139 "Have new addresses, will try to trigger transmissions.\n"); 3071 "Have new addresses, will try to trigger transmissions.\n");
3140#endif 3072#endif
3141 try_transmission_to_peer (n); 3073 try_transmission_to_peer (n);
3142 } 3074 }
3143 return GNUNET_OK; 3075 return GNUNET_OK;
3144} 3076}
3145 3077
@@ -3155,47 +3087,43 @@ add_to_foreign_address_list (void *cls,
3155 */ 3087 */
3156static void 3088static void
3157add_hello_for_peer (void *cls, 3089add_hello_for_peer (void *cls,
3158 const struct GNUNET_PeerIdentity *peer, 3090 const struct GNUNET_PeerIdentity *peer,
3159 const struct GNUNET_HELLO_Message *h, 3091 const struct GNUNET_HELLO_Message *h, const char *err_msg)
3160 const char *err_msg)
3161{ 3092{
3162 struct NeighbourMapEntry *n = cls; 3093 struct NeighbourMapEntry *n = cls;
3163 3094
3164 if (err_msg != NULL) 3095 if (err_msg != NULL)
3165 { 3096 {
3166#if DEBUG_TRANSPORT 3097#if DEBUG_TRANSPORT
3167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3168 _("Error in communication with PEERINFO service: %s\n"), 3099 _("Error in communication with PEERINFO service: %s\n"),
3169 err_msg); 3100 err_msg);
3170#endif 3101#endif
3171 /* return; */ 3102 /* return; */
3172 } 3103 }
3173 if (peer == NULL) 3104 if (peer == NULL)
3174 { 3105 {
3175 GNUNET_STATISTICS_update (stats, 3106 GNUNET_STATISTICS_update (stats,
3176 gettext_noop ("# outstanding peerinfo iterate requests"), 3107 gettext_noop
3177 -1, 3108 ("# outstanding peerinfo iterate requests"), -1,
3178 GNUNET_NO); 3109 GNUNET_NO);
3179 n->piter = NULL; 3110 n->piter = NULL;
3180 return; 3111 return;
3181 } 3112 }
3182 if (h == NULL) 3113 if (h == NULL)
3183 return; /* no HELLO available */ 3114 return; /* no HELLO available */
3184#if DEBUG_TRANSPORT 3115#if DEBUG_TRANSPORT
3185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3116 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3186 "Peerinfo had `%s' message for peer `%4s', adding existing addresses.\n", 3117 "Peerinfo had `%s' message for peer `%4s', adding existing addresses.\n",
3187 "HELLO", 3118 "HELLO", GNUNET_i2s (peer));
3188 GNUNET_i2s (peer));
3189#endif 3119#endif
3190 if (GNUNET_YES != n->public_key_valid) 3120 if (GNUNET_YES != n->public_key_valid)
3191 { 3121 {
3192 GNUNET_HELLO_get_key (h, &n->publicKey); 3122 GNUNET_HELLO_get_key (h, &n->publicKey);
3193 n->public_key_valid = GNUNET_YES; 3123 n->public_key_valid = GNUNET_YES;
3194 } 3124 }
3195 GNUNET_HELLO_iterate_addresses (h, 3125 GNUNET_HELLO_iterate_addresses (h,
3196 GNUNET_NO, 3126 GNUNET_NO, &add_to_foreign_address_list, n);
3197 &add_to_foreign_address_list,
3198 n);
3199} 3127}
3200 3128
3201 3129
@@ -3209,79 +3137,73 @@ add_hello_for_peer (void *cls,
3209 * @return the new neighbour list entry 3137 * @return the new neighbour list entry
3210 */ 3138 */
3211static struct NeighbourMapEntry * 3139static struct NeighbourMapEntry *
3212setup_new_neighbour (const struct GNUNET_PeerIdentity *peer, 3140setup_new_neighbour (const struct GNUNET_PeerIdentity *peer, int do_hello)
3213 int do_hello)
3214{ 3141{
3215 struct NeighbourMapEntry *n; 3142 struct NeighbourMapEntry *n;
3216 struct TransportPlugin *tp; 3143 struct TransportPlugin *tp;
3217 struct ReadyList *rl; 3144 struct ReadyList *rl;
3218 3145
3219 GNUNET_assert (0 != memcmp (peer, 3146 GNUNET_assert (0 != memcmp (peer,
3220 &my_identity, 3147 &my_identity,
3221 sizeof (struct GNUNET_PeerIdentity))); 3148 sizeof (struct GNUNET_PeerIdentity)));
3222#if DEBUG_TRANSPORT 3149#if DEBUG_TRANSPORT
3223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3150 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3224 "Setting up state for neighbour `%4s'\n", 3151 "Setting up state for neighbour `%4s'\n", GNUNET_i2s (peer));
3225 GNUNET_i2s (peer));
3226#endif 3152#endif
3227 GNUNET_STATISTICS_update (stats, 3153 GNUNET_STATISTICS_update (stats,
3228 gettext_noop ("# active neighbours"), 3154 gettext_noop ("# active neighbours"), 1, GNUNET_NO);
3229 1,
3230 GNUNET_NO);
3231 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 3155 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
3232 n->id = *peer; 3156 n->id = *peer;
3233 n->peer_timeout = 3157 n->peer_timeout =
3234 GNUNET_TIME_relative_to_absolute 3158 GNUNET_TIME_relative_to_absolute
3235 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 3159 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
3236 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 3160 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
3237 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 3161 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
3238 MAX_BANDWIDTH_CARRY_S); 3162 MAX_BANDWIDTH_CARRY_S);
3239 tp = plugins; 3163 tp = plugins;
3240 while (tp != NULL) 3164 while (tp != NULL)
3165 {
3166 if ((tp->api->send != NULL) && (!is_blacklisted (peer, tp)))
3241 { 3167 {
3242 if ((tp->api->send != NULL) && (!is_blacklisted(peer, tp))) 3168 rl = GNUNET_malloc (sizeof (struct ReadyList));
3243 { 3169 rl->neighbour = n;
3244 rl = GNUNET_malloc (sizeof (struct ReadyList)); 3170 rl->next = n->plugins;
3245 rl->neighbour = n; 3171 n->plugins = rl;
3246 rl->next = n->plugins; 3172 rl->plugin = tp;
3247 n->plugins = rl; 3173 rl->addresses = NULL;
3248 rl->plugin = tp;
3249 rl->addresses = NULL;
3250 }
3251 tp = tp->next;
3252 } 3174 }
3175 tp = tp->next;
3176 }
3253 n->latency = GNUNET_TIME_UNIT_FOREVER_REL; 3177 n->latency = GNUNET_TIME_UNIT_FOREVER_REL;
3254 n->distance = -1; 3178 n->distance = -1;
3255 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 3179 n->timeout_task =
3256 &neighbour_timeout_task, n); 3180 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
3257 GNUNET_CONTAINER_multihashmap_put (neighbours, 3181 &neighbour_timeout_task, n);
3258 &n->id.hashPubKey, 3182 GNUNET_CONTAINER_multihashmap_put (neighbours, &n->id.hashPubKey, n,
3259 n, 3183 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3260 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
3261 if (do_hello) 3184 if (do_hello)
3262 { 3185 {
3263 GNUNET_STATISTICS_update (stats, 3186 GNUNET_STATISTICS_update (stats,
3264 gettext_noop ("# peerinfo new neighbor iterate requests"), 3187 gettext_noop
3265 1, 3188 ("# peerinfo new neighbor iterate requests"), 1,
3266 GNUNET_NO); 3189 GNUNET_NO);
3267 GNUNET_STATISTICS_update (stats, 3190 GNUNET_STATISTICS_update (stats,
3268 gettext_noop ("# outstanding peerinfo iterate requests"), 3191 gettext_noop
3269 1, 3192 ("# outstanding peerinfo iterate requests"), 1,
3270 GNUNET_NO); 3193 GNUNET_NO);
3271 n->piter = GNUNET_PEERINFO_iterate (peerinfo, peer, 3194 n->piter =
3272 GNUNET_TIME_UNIT_FOREVER_REL, 3195 GNUNET_PEERINFO_iterate (peerinfo, peer, GNUNET_TIME_UNIT_FOREVER_REL,
3273 &add_hello_for_peer, n); 3196 &add_hello_for_peer, n);
3274 3197
3275 GNUNET_STATISTICS_update (stats, 3198 GNUNET_STATISTICS_update (stats,
3276 gettext_noop ("# HELLO's sent to new neighbors"), 3199 gettext_noop ("# HELLO's sent to new neighbors"),
3277 1, 3200 1, GNUNET_NO);
3278 GNUNET_NO); 3201 if (NULL != our_hello)
3279 if (NULL != our_hello) 3202 transmit_to_peer (NULL, NULL, 0,
3280 transmit_to_peer (NULL, NULL, 0, 3203 HELLO_ADDRESS_EXPIRATION,
3281 HELLO_ADDRESS_EXPIRATION, 3204 (const char *) our_hello, GNUNET_HELLO_size (our_hello),
3282 (const char *) our_hello, GNUNET_HELLO_size(our_hello), 3205 GNUNET_NO, n);
3283 GNUNET_NO, n); 3206 }
3284 }
3285 return n; 3207 return n;
3286} 3208}
3287 3209
@@ -3293,8 +3215,7 @@ setup_new_neighbour (const struct GNUNET_PeerIdentity *peer,
3293 * @param cls closure 3215 * @param cls closure
3294 * @param n NULL if communication is not acceptable 3216 * @param n NULL if communication is not acceptable
3295 */ 3217 */
3296typedef void (*SetupContinuation)(void *cls, 3218typedef void (*SetupContinuation) (void *cls, struct NeighbourMapEntry * n);
3297 struct NeighbourMapEntry *n);
3298 3219
3299 3220
3300/** 3221/**
@@ -3409,8 +3330,7 @@ static struct BlacklistCheck *bc_tail;
3409 * @param tc unused 3330 * @param tc unused
3410 */ 3331 */
3411static void 3332static void
3412do_blacklist_check (void *cls, 3333do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
3413 const struct GNUNET_SCHEDULER_TaskContext *tc);
3414 3334
3415/** 3335/**
3416 * Transmit blacklist query to the client. 3336 * Transmit blacklist query to the client.
@@ -3421,9 +3341,7 @@ do_blacklist_check (void *cls,
3421 * @return number of bytes copied to buf 3341 * @return number of bytes copied to buf
3422 */ 3342 */
3423static size_t 3343static size_t
3424transmit_blacklist_message (void *cls, 3344transmit_blacklist_message (void *cls, size_t size, void *buf)
3425 size_t size,
3426 void *buf)
3427{ 3345{
3428 struct BlacklistCheck *bc = cls; 3346 struct BlacklistCheck *bc = cls;
3429 struct Blacklisters *bl; 3347 struct Blacklisters *bl;
@@ -3431,19 +3349,18 @@ transmit_blacklist_message (void *cls,
3431 3349
3432 bc->th = NULL; 3350 bc->th = NULL;
3433 if (size == 0) 3351 if (size == 0)
3434 { 3352 {
3435 GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK); 3353 GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
3436 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 3354 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
3437 bc); 3355 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3438 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3356 "Failed to send blacklist test for peer `%s' to client\n",
3439 "Failed to send blacklist test for peer `%s' to client\n", 3357 GNUNET_i2s (&bc->peer));
3440 GNUNET_i2s (&bc->peer)); 3358 return 0;
3441 return 0; 3359 }
3442 }
3443#if DEBUG_TRANSPORT 3360#if DEBUG_TRANSPORT
3444 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3445 "Sending blacklist test for peer `%s' to client\n", 3362 "Sending blacklist test for peer `%s' to client\n",
3446 GNUNET_i2s (&bc->peer)); 3363 GNUNET_i2s (&bc->peer));
3447#endif 3364#endif
3448 bl = bc->bl_pos; 3365 bl = bc->bl_pos;
3449 bm.header.size = htons (sizeof (struct BlacklistMessage)); 3366 bm.header.size = htons (sizeof (struct BlacklistMessage));
@@ -3463,8 +3380,7 @@ transmit_blacklist_message (void *cls,
3463 * @param tc unused 3380 * @param tc unused
3464 */ 3381 */
3465static void 3382static void
3466do_blacklist_check (void *cls, 3383do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3467 const struct GNUNET_SCHEDULER_TaskContext *tc)
3468{ 3384{
3469 struct BlacklistCheck *bc = cls; 3385 struct BlacklistCheck *bc = cls;
3470 struct Blacklisters *bl; 3386 struct Blacklisters *bl;
@@ -3472,26 +3388,26 @@ do_blacklist_check (void *cls,
3472 bc->task = GNUNET_SCHEDULER_NO_TASK; 3388 bc->task = GNUNET_SCHEDULER_NO_TASK;
3473 bl = bc->bl_pos; 3389 bl = bc->bl_pos;
3474 if (bl == NULL) 3390 if (bl == NULL)
3475 { 3391 {
3476#if DEBUG_TRANSPORT 3392#if DEBUG_TRANSPORT
3477 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3478 "No blacklist clients active, will now setup neighbour record for peer `%s'\n", 3394 "No blacklist clients active, will now setup neighbour record for peer `%s'\n",
3479 GNUNET_i2s (&bc->peer)); 3395 GNUNET_i2s (&bc->peer));
3480#endif 3396#endif
3481 bc->cont (bc->cont_cls, 3397 bc->cont (bc->cont_cls, setup_new_neighbour (&bc->peer, bc->do_hello));
3482 setup_new_neighbour (&bc->peer, bc->do_hello)); 3398 GNUNET_free (bc);
3483 GNUNET_free (bc); 3399 return;
3484 return; 3400 }
3485 }
3486 if (bl->bc == NULL) 3401 if (bl->bc == NULL)
3487 { 3402 {
3488 bl->bc = bc; 3403 bl->bc = bc;
3489 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client, 3404 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
3490 sizeof (struct BlacklistMessage), 3405 sizeof (struct
3491 GNUNET_TIME_UNIT_FOREVER_REL, 3406 BlacklistMessage),
3492 &transmit_blacklist_message, 3407 GNUNET_TIME_UNIT_FOREVER_REL,
3493 bc); 3408 &transmit_blacklist_message,
3494 } 3409 bc);
3410 }
3495} 3411}
3496 3412
3497 3413
@@ -3509,33 +3425,31 @@ do_blacklist_check (void *cls,
3509 */ 3425 */
3510static void 3426static void
3511setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer, 3427setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
3512 int do_hello, 3428 int do_hello,
3513 SetupContinuation cont, 3429 SetupContinuation cont, void *cont_cls)
3514 void *cont_cls)
3515{ 3430{
3516 struct NeighbourMapEntry *n; 3431 struct NeighbourMapEntry *n;
3517 struct BlacklistCheck *bc; 3432 struct BlacklistCheck *bc;
3518 3433
3519 n = find_neighbour(peer); 3434 n = find_neighbour (peer);
3520 if (n != NULL) 3435 if (n != NULL)
3521 { 3436 {
3522#if DEBUG_TRANSPORT 3437#if DEBUG_TRANSPORT
3523 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 3438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3524 "Neighbour record exists for peer `%s'\n", 3439 "Neighbour record exists for peer `%s'\n", GNUNET_i2s (peer));
3525 GNUNET_i2s(peer));
3526#endif 3440#endif
3527 if (cont != NULL) 3441 if (cont != NULL)
3528 cont (cont_cls, n); 3442 cont (cont_cls, n);
3529 return; 3443 return;
3530 } 3444 }
3531 if (bl_head == NULL) 3445 if (bl_head == NULL)
3532 { 3446 {
3533 if (cont != NULL) 3447 if (cont != NULL)
3534 cont (cont_cls, setup_new_neighbour (peer, do_hello)); 3448 cont (cont_cls, setup_new_neighbour (peer, do_hello));
3535 else 3449 else
3536 setup_new_neighbour(peer, do_hello); 3450 setup_new_neighbour (peer, do_hello);
3537 return; 3451 return;
3538 } 3452 }
3539 bc = GNUNET_malloc (sizeof (struct BlacklistCheck)); 3453 bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
3540 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); 3454 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
3541 bc->peer = *peer; 3455 bc->peer = *peer;
@@ -3543,8 +3457,7 @@ setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
3543 bc->cont = cont; 3457 bc->cont = cont;
3544 bc->cont_cls = cont_cls; 3458 bc->cont_cls = cont_cls;
3545 bc->bl_pos = bl_head; 3459 bc->bl_pos = bl_head;
3546 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 3460 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
3547 bc);
3548} 3461}
3549 3462
3550 3463
@@ -3556,24 +3469,22 @@ setup_peer_check_blacklist (const struct GNUNET_PeerIdentity *peer,
3556 * @param n NULL if we need to disconnect 3469 * @param n NULL if we need to disconnect
3557 */ 3470 */
3558static void 3471static void
3559confirm_or_drop_neighbour (void *cls, 3472confirm_or_drop_neighbour (void *cls, struct NeighbourMapEntry *n)
3560 struct NeighbourMapEntry *n)
3561{ 3473{
3562 struct NeighbourMapEntry * orig = cls; 3474 struct NeighbourMapEntry *orig = cls;
3563 3475
3564 if (n == NULL) 3476 if (n == NULL)
3565 { 3477 {
3566#if DEBUG_TRANSPORT 3478#if DEBUG_TRANSPORT
3567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3568 "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&orig->id), 3480 "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&orig->id),
3569 "confirm_or_drop_neighboUr"); 3481 "confirm_or_drop_neighboUr");
3570#endif 3482#endif
3571 GNUNET_STATISTICS_update (stats, 3483 GNUNET_STATISTICS_update (stats,
3572 gettext_noop ("# disconnects due to blacklist"), 3484 gettext_noop ("# disconnects due to blacklist"),
3573 1, 3485 1, GNUNET_NO);
3574 GNUNET_NO); 3486 disconnect_neighbour (orig, GNUNET_NO);
3575 disconnect_neighbour (orig, GNUNET_NO); 3487 }
3576 }
3577} 3488}
3578 3489
3579 3490
@@ -3586,15 +3497,13 @@ struct TestConnectionContext
3586 3497
3587 3498
3588static int 3499static int
3589test_connection_ok (void *cls, 3500test_connection_ok (void *cls, const GNUNET_HashCode * key, void *value)
3590 const GNUNET_HashCode *key,
3591 void *value)
3592{ 3501{
3593 struct TestConnectionContext *tcc = cls; 3502 struct TestConnectionContext *tcc = cls;
3594 struct NeighbourMapEntry *n = value; 3503 struct NeighbourMapEntry *n = value;
3595 struct BlacklistCheck *bc; 3504 struct BlacklistCheck *bc;
3596 3505
3597 3506
3598 bc = GNUNET_malloc (sizeof (struct BlacklistCheck)); 3507 bc = GNUNET_malloc (sizeof (struct BlacklistCheck));
3599 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc); 3508 GNUNET_CONTAINER_DLL_insert (bc_head, bc_tail, bc);
3600 bc->peer = n->id; 3509 bc->peer = n->id;
@@ -3603,13 +3512,12 @@ test_connection_ok (void *cls,
3603 bc->cont_cls = n; 3512 bc->cont_cls = n;
3604 bc->bl_pos = tcc->bl; 3513 bc->bl_pos = tcc->bl;
3605 if (GNUNET_YES == tcc->first) 3514 if (GNUNET_YES == tcc->first)
3606 { 3515 {
3607 /* all would wait for the same client, no need to 3516 /* all would wait for the same client, no need to
3608 create more than just the first task right now */ 3517 * create more than just the first task right now */
3609 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 3518 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
3610 bc); 3519 tcc->first = GNUNET_NO;
3611 tcc->first = GNUNET_NO; 3520 }
3612 }
3613 return GNUNET_OK; 3521 return GNUNET_OK;
3614} 3522}
3615 3523
@@ -3623,23 +3531,23 @@ test_connection_ok (void *cls,
3623 */ 3531 */
3624static void 3532static void
3625handle_blacklist_init (void *cls, 3533handle_blacklist_init (void *cls,
3626 struct GNUNET_SERVER_Client *client, 3534 struct GNUNET_SERVER_Client *client,
3627 const struct GNUNET_MessageHeader *message) 3535 const struct GNUNET_MessageHeader *message)
3628{ 3536{
3629 struct Blacklisters *bl; 3537 struct Blacklisters *bl;
3630 struct TestConnectionContext tcc; 3538 struct TestConnectionContext tcc;
3631 3539
3632 bl = bl_head; 3540 bl = bl_head;
3633 while (bl != NULL) 3541 while (bl != NULL)
3542 {
3543 if (bl->client == client)
3634 { 3544 {
3635 if (bl->client == client) 3545 GNUNET_break (0);
3636 { 3546 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3637 GNUNET_break (0); 3547 return;
3638 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3639 return;
3640 }
3641 bl = bl->next;
3642 } 3548 }
3549 bl = bl->next;
3550 }
3643 bl = GNUNET_malloc (sizeof (struct Blacklisters)); 3551 bl = GNUNET_malloc (sizeof (struct Blacklisters));
3644 bl->client = client; 3552 bl->client = client;
3645 GNUNET_SERVER_client_keep (client); 3553 GNUNET_SERVER_client_keep (client);
@@ -3647,9 +3555,7 @@ handle_blacklist_init (void *cls,
3647 /* confirm that all existing connections are OK! */ 3555 /* confirm that all existing connections are OK! */
3648 tcc.bl = bl; 3556 tcc.bl = bl;
3649 tcc.first = GNUNET_YES; 3557 tcc.first = GNUNET_YES;
3650 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 3558 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &test_connection_ok, &tcc);
3651 &test_connection_ok,
3652 &tcc);
3653} 3559}
3654 3560
3655 3561
@@ -3662,59 +3568,55 @@ handle_blacklist_init (void *cls,
3662 */ 3568 */
3663static void 3569static void
3664handle_blacklist_reply (void *cls, 3570handle_blacklist_reply (void *cls,
3665 struct GNUNET_SERVER_Client *client, 3571 struct GNUNET_SERVER_Client *client,
3666 const struct GNUNET_MessageHeader *message) 3572 const struct GNUNET_MessageHeader *message)
3667{ 3573{
3668 const struct BlacklistMessage *msg = (const struct BlacklistMessage*) message; 3574 const struct BlacklistMessage *msg =
3575 (const struct BlacklistMessage *) message;
3669 struct Blacklisters *bl; 3576 struct Blacklisters *bl;
3670 struct BlacklistCheck *bc; 3577 struct BlacklistCheck *bc;
3671 3578
3672 bl = bl_head; 3579 bl = bl_head;
3673 while ( (bl != NULL) && 3580 while ((bl != NULL) && (bl->client != client))
3674 (bl->client != client) )
3675 bl = bl->next; 3581 bl = bl->next;
3676 if (bl == NULL) 3582 if (bl == NULL)
3677 { 3583 {
3678#if DEBUG_TRANSPORT 3584#if DEBUG_TRANSPORT
3679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3585 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client disconnected\n");
3680 "Blacklist client disconnected\n");
3681#endif 3586#endif
3682 /* FIXME: other error handling here!? */ 3587 /* FIXME: other error handling here!? */
3683 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 3588 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
3684 return; 3589 return;
3685 } 3590 }
3686 bc = bl->bc; 3591 bc = bl->bc;
3687 bl->bc = NULL; 3592 bl->bc = NULL;
3688 if (ntohl (msg->is_allowed) == GNUNET_SYSERR) 3593 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
3689 { 3594 {
3690#if DEBUG_TRANSPORT 3595#if DEBUG_TRANSPORT
3691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3692 "Blacklist check failed, peer not allowed\n"); 3597 "Blacklist check failed, peer not allowed\n");
3693#endif 3598#endif
3694 bc->cont (bc->cont_cls, NULL); 3599 bc->cont (bc->cont_cls, NULL);
3695 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); 3600 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
3696 GNUNET_free (bc); 3601 GNUNET_free (bc);
3697 } 3602 }
3698 else 3603 else
3699 { 3604 {
3700#if DEBUG_TRANSPORT 3605#if DEBUG_TRANSPORT
3701 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3702 "Blacklist check succeeded, continuing with checks\n"); 3607 "Blacklist check succeeded, continuing with checks\n");
3703#endif 3608#endif
3704 bc->bl_pos = bc->bl_pos->next; 3609 bc->bl_pos = bc->bl_pos->next;
3705 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 3610 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
3706 bc); 3611 }
3707 }
3708 /* check if any other bc's are waiting for this blacklister */ 3612 /* check if any other bc's are waiting for this blacklister */
3709 bc = bc_head; 3613 bc = bc_head;
3710 while (bc != NULL) 3614 while (bc != NULL)
3711 { 3615 {
3712 if ( (bc->bl_pos == bl) && 3616 if ((bc->bl_pos == bl) && (GNUNET_SCHEDULER_NO_TASK == bc->task))
3713 (GNUNET_SCHEDULER_NO_TASK == bc->task) ) 3617 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
3714 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 3618 bc = bc->next;
3715 bc); 3619 }
3716 bc = bc->next;
3717 }
3718} 3620}
3719 3621
3720 3622
@@ -3725,8 +3627,7 @@ handle_blacklist_reply (void *cls,
3725 * @param tc task context 3627 * @param tc task context
3726 */ 3628 */
3727static void 3629static void
3728send_periodic_ping (void *cls, 3630send_periodic_ping (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3729 const struct GNUNET_SCHEDULER_TaskContext *tc)
3730{ 3631{
3731 struct ForeignAddressList *peer_address = cls; 3632 struct ForeignAddressList *peer_address = cls;
3732 struct TransportPlugin *tp; 3633 struct TransportPlugin *tp;
@@ -3734,23 +3635,23 @@ send_periodic_ping (void *cls,
3734 struct NeighbourMapEntry *neighbour; 3635 struct NeighbourMapEntry *neighbour;
3735 struct TransportPingMessage ping; 3636 struct TransportPingMessage ping;
3736 struct CheckAddressExistsClosure caec; 3637 struct CheckAddressExistsClosure caec;
3737 char * message_buf; 3638 char *message_buf;
3738 uint16_t hello_size; 3639 uint16_t hello_size;
3739 size_t slen; 3640 size_t slen;
3740 size_t tsize; 3641 size_t tsize;
3741 3642
3742 peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK; 3643 peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
3743 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 3644 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
3744 return; 3645 return;
3745 GNUNET_assert (peer_address != NULL); 3646 GNUNET_assert (peer_address != NULL);
3746 tp = peer_address->ready_list->plugin; 3647 tp = peer_address->ready_list->plugin;
3747 neighbour = peer_address->ready_list->neighbour; 3648 neighbour = peer_address->ready_list->neighbour;
3748 if (GNUNET_YES != neighbour->public_key_valid) 3649 if (GNUNET_YES != neighbour->public_key_valid)
3749 { 3650 {
3750 /* no public key yet, try again later */ 3651 /* no public key yet, try again later */
3751 schedule_next_ping (peer_address); 3652 schedule_next_ping (peer_address);
3752 return; 3653 return;
3753 } 3654 }
3754 caec.addr = peer_address->addr; 3655 caec.addr = peer_address->addr;
3755 caec.addrlen = peer_address->addrlen; 3656 caec.addrlen = peer_address->addrlen;
3756 caec.tname = tp->short_name; 3657 caec.tname = tp->short_name;
@@ -3758,43 +3659,40 @@ send_periodic_ping (void *cls,
3758 caec.exists = GNUNET_NO; 3659 caec.exists = GNUNET_NO;
3759 3660
3760 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 3661 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
3761 &check_address_exists, 3662 &check_address_exists, &caec);
3762 &caec);
3763 if (caec.exists == GNUNET_YES) 3663 if (caec.exists == GNUNET_YES)
3764 { 3664 {
3765 /* During validation attempts we will likely trigger the other 3665 /* During validation attempts we will likely trigger the other
3766 peer trying to validate our address which in turn will cause 3666 * peer trying to validate our address which in turn will cause
3767 it to send us its HELLO, so we expect to hit this case rather 3667 * it to send us its HELLO, so we expect to hit this case rather
3768 frequently. Only print something if we are very verbose. */ 3668 * frequently. Only print something if we are very verbose. */
3769#if DEBUG_TRANSPORT > 1 3669#if DEBUG_TRANSPORT > 1
3770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3771 "Some validation of address `%s' via `%s' for peer `%4s' already in progress.\n", 3671 "Some validation of address `%s' via `%s' for peer `%4s' already in progress.\n",
3772 (peer_address->addr != NULL) 3672 (peer_address->addr != NULL)
3773 ? a2s (tp->short_name, 3673 ? a2s (tp->short_name,
3774 peer_address->addr, 3674 peer_address->addr,
3775 peer_address->addrlen) 3675 peer_address->addrlen)
3776 : "<inbound>", 3676 : "<inbound>", tp->short_name, GNUNET_i2s (&neighbour->id));
3777 tp->short_name,
3778 GNUNET_i2s (&neighbour->id));
3779#endif 3677#endif
3780 schedule_next_ping (peer_address); 3678 schedule_next_ping (peer_address);
3781 return; 3679 return;
3782 } 3680 }
3783 va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen); 3681 va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen);
3784 va->transport_name = GNUNET_strdup (tp->short_name); 3682 va->transport_name = GNUNET_strdup (tp->short_name);
3785 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 3683 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
3786 UINT_MAX); 3684 UINT_MAX);
3787 va->send_time = GNUNET_TIME_absolute_get(); 3685 va->send_time = GNUNET_TIME_absolute_get ();
3788 va->session = peer_address->session; 3686 va->session = peer_address->session;
3789 if (peer_address->addr != NULL) 3687 if (peer_address->addr != NULL)
3790 { 3688 {
3791 va->addr = (const void*) &va[1]; 3689 va->addr = (const void *) &va[1];
3792 memcpy (&va[1], peer_address->addr, peer_address->addrlen); 3690 memcpy (&va[1], peer_address->addr, peer_address->addrlen);
3793 va->addrlen = peer_address->addrlen; 3691 va->addrlen = peer_address->addrlen;
3794 } 3692 }
3795 memcpy(&va->publicKey, 3693 memcpy (&va->publicKey,
3796 &neighbour->publicKey, 3694 &neighbour->publicKey,
3797 sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 3695 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
3798 3696
3799 va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT, 3697 va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
3800 &timeout_hello_validation, 3698 &timeout_hello_validation,
@@ -3805,83 +3703,75 @@ send_periodic_ping (void *cls,
3805 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 3703 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
3806 3704
3807 if (peer_address->validated != GNUNET_YES) 3705 if (peer_address->validated != GNUNET_YES)
3808 hello_size = GNUNET_HELLO_size(our_hello); 3706 hello_size = GNUNET_HELLO_size (our_hello);
3809 else 3707 else
3810 hello_size = 0; 3708 hello_size = 0;
3811 3709
3812 tsize = sizeof(struct TransportPingMessage) + hello_size; 3710 tsize = sizeof (struct TransportPingMessage) + hello_size;
3813 3711
3814 if (peer_address->addr != NULL) 3712 if (peer_address->addr != NULL)
3815 { 3713 {
3816 slen = strlen (tp->short_name) + 1; 3714 slen = strlen (tp->short_name) + 1;
3817 tsize += slen + peer_address->addrlen; 3715 tsize += slen + peer_address->addrlen;
3818 } 3716 }
3819 else 3717 else
3820 { 3718 {
3821 slen = 0; /* make gcc happy */ 3719 slen = 0; /* make gcc happy */
3822 } 3720 }
3823 message_buf = GNUNET_malloc(tsize); 3721 message_buf = GNUNET_malloc (tsize);
3824 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 3722 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
3825 ping.challenge = htonl(va->challenge); 3723 ping.challenge = htonl (va->challenge);
3826 memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity)); 3724 memcpy (&ping.target, &neighbour->id, sizeof (struct GNUNET_PeerIdentity));
3827 if (peer_address->validated != GNUNET_YES) 3725 if (peer_address->validated != GNUNET_YES)
3828 { 3726 {
3829 memcpy(message_buf, our_hello, hello_size); 3727 memcpy (message_buf, our_hello, hello_size);
3830 } 3728 }
3831 3729
3832 if (peer_address->addr != NULL) 3730 if (peer_address->addr != NULL)
3833 { 3731 {
3834 ping.header.size = htons(sizeof(struct TransportPingMessage) + 3732 ping.header.size = htons (sizeof (struct TransportPingMessage) +
3835 peer_address->addrlen + 3733 peer_address->addrlen + slen);
3836 slen); 3734 memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)],
3837 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)], 3735 tp->short_name, slen);
3838 tp->short_name, 3736 memcpy (&message_buf
3839 slen); 3737 [hello_size + sizeof (struct TransportPingMessage) + slen],
3840 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) + slen], 3738 peer_address->addr, peer_address->addrlen);
3841 peer_address->addr, 3739 }
3842 peer_address->addrlen);
3843 }
3844 else 3740 else
3845 { 3741 {
3846 ping.header.size = htons(sizeof(struct TransportPingMessage)); 3742 ping.header.size = htons (sizeof (struct TransportPingMessage));
3847 } 3743 }
3848 3744
3849 memcpy(&message_buf[hello_size], 3745 memcpy (&message_buf[hello_size],
3850 &ping, 3746 &ping, sizeof (struct TransportPingMessage));
3851 sizeof(struct TransportPingMessage));
3852 3747
3853#if DEBUG_TRANSPORT_REVALIDATION 3748#if DEBUG_TRANSPORT_REVALIDATION
3854 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3855 "Performing re-validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s'\n", 3750 "Performing re-validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s'\n",
3856 (peer_address->addr != NULL) 3751 (peer_address->addr != NULL)
3857 ? a2s (peer_address->plugin->short_name, 3752 ? a2s (peer_address->plugin->short_name,
3858 peer_address->addr, 3753 peer_address->addr,
3859 peer_address->addrlen) 3754 peer_address->addrlen)
3860 : "<inbound>", 3755 : "<inbound>",
3861 tp->short_name, 3756 tp->short_name,
3862 GNUNET_i2s (&neighbour->id), 3757 GNUNET_i2s (&neighbour->id), "HELLO", hello_size, "PING");
3863 "HELLO", hello_size,
3864 "PING");
3865#endif 3758#endif
3866 if (peer_address->validated != GNUNET_YES) 3759 if (peer_address->validated != GNUNET_YES)
3867 GNUNET_STATISTICS_update (stats, 3760 GNUNET_STATISTICS_update (stats,
3868 gettext_noop ("# PING with HELLO messages sent"), 3761 gettext_noop ("# PING with HELLO messages sent"),
3869 1, 3762 1, GNUNET_NO);
3870 GNUNET_NO);
3871 else 3763 else
3872 GNUNET_STATISTICS_update (stats, 3764 GNUNET_STATISTICS_update (stats,
3873 gettext_noop ("# PING without HELLO messages sent"), 3765 gettext_noop
3874 1, 3766 ("# PING without HELLO messages sent"), 1,
3875 GNUNET_NO); 3767 GNUNET_NO);
3876 GNUNET_STATISTICS_update (stats, 3768 GNUNET_STATISTICS_update (stats,
3877 gettext_noop ("# PING messages sent for re-validation"), 3769 gettext_noop
3878 1, 3770 ("# PING messages sent for re-validation"), 1,
3879 GNUNET_NO); 3771 GNUNET_NO);
3880 transmit_to_peer (NULL, peer_address, 3772 transmit_to_peer (NULL, peer_address, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
3881 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 3773 HELLO_VERIFICATION_TIMEOUT, message_buf, tsize, GNUNET_YES,
3882 HELLO_VERIFICATION_TIMEOUT, 3774 neighbour);
3883 message_buf, tsize,
3884 GNUNET_YES, neighbour);
3885 GNUNET_free (message_buf); 3775 GNUNET_free (message_buf);
3886 schedule_next_ping (peer_address); 3776 schedule_next_ping (peer_address);
3887} 3777}
@@ -3899,37 +3789,36 @@ schedule_next_ping (struct ForeignAddressList *fal)
3899 struct GNUNET_TIME_Relative delay; 3789 struct GNUNET_TIME_Relative delay;
3900 3790
3901 if (fal->revalidate_task != GNUNET_SCHEDULER_NO_TASK) 3791 if (fal->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
3902 { 3792 {
3903 GNUNET_SCHEDULER_cancel(fal->revalidate_task); 3793 GNUNET_SCHEDULER_cancel (fal->revalidate_task);
3904 fal->revalidate_task = GNUNET_SCHEDULER_NO_TASK; 3794 fal->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
3905 } 3795 }
3906 delay = GNUNET_TIME_absolute_get_remaining (fal->expires); 3796 delay = GNUNET_TIME_absolute_get_remaining (fal->expires);
3907 delay.rel_value /= 2; /* do before expiration */ 3797 delay.rel_value /= 2; /* do before expiration */
3908 delay = GNUNET_TIME_relative_min (delay, 3798 delay = GNUNET_TIME_relative_min (delay, LATENCY_EVALUATION_MAX_DELAY);
3909 LATENCY_EVALUATION_MAX_DELAY);
3910 if (GNUNET_YES != fal->estimated) 3799 if (GNUNET_YES != fal->estimated)
3911 { 3800 {
3912 delay = GNUNET_TIME_UNIT_ZERO; 3801 delay = GNUNET_TIME_UNIT_ZERO;
3913 fal->estimated = GNUNET_YES; 3802 fal->estimated = GNUNET_YES;
3914 } 3803 }
3915 3804
3916 if (GNUNET_YES == fal->connected) 3805 if (GNUNET_YES == fal->connected)
3917 { 3806 {
3918 delay = GNUNET_TIME_relative_min (delay, 3807 delay = GNUNET_TIME_relative_min (delay,
3919 CONNECTED_LATENCY_EVALUATION_MAX_DELAY); 3808 CONNECTED_LATENCY_EVALUATION_MAX_DELAY);
3920 } 3809 }
3921 /* FIXME: also adjust delay based on how close the last 3810 /* FIXME: also adjust delay based on how close the last
3922 observed latency is to the latency of the best alternative */ 3811 * observed latency is to the latency of the best alternative */
3923 /* bound how fast we can go */ 3812 /* bound how fast we can go */
3924 delay = GNUNET_TIME_relative_max (delay, 3813 delay = GNUNET_TIME_relative_max (delay, GNUNET_TIME_UNIT_SECONDS);
3925 GNUNET_TIME_UNIT_SECONDS);
3926 /* randomize a bit (to avoid doing all at the same time) */ 3814 /* randomize a bit (to avoid doing all at the same time) */
3927 delay.rel_value += GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000); 3815 delay.rel_value +=
3816 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
3928 3817
3929 GNUNET_assert (fal->revalidate_task == GNUNET_SCHEDULER_NO_TASK); 3818 GNUNET_assert (fal->revalidate_task == GNUNET_SCHEDULER_NO_TASK);
3930 fal->revalidate_task = GNUNET_SCHEDULER_add_delayed(delay, 3819 fal->revalidate_task = GNUNET_SCHEDULER_add_delayed (delay,
3931 &send_periodic_ping, 3820 &send_periodic_ping,
3932 fal); 3821 fal);
3933} 3822}
3934 3823
3935 3824
@@ -3944,7 +3833,7 @@ schedule_next_ping (struct ForeignAddressList *fal)
3944 */ 3833 */
3945static void 3834static void
3946handle_payload_message (const struct GNUNET_MessageHeader *message, 3835handle_payload_message (const struct GNUNET_MessageHeader *message,
3947 struct NeighbourMapEntry *n) 3836 struct NeighbourMapEntry *n)
3948{ 3837{
3949 struct InboundMessage *im; 3838 struct InboundMessage *im;
3950 struct TransportClient *cpos; 3839 struct TransportClient *cpos;
@@ -3952,66 +3841,64 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
3952 3841
3953 msize = ntohs (message->size); 3842 msize = ntohs (message->size);
3954 if (n->received_pong == GNUNET_NO) 3843 if (n->received_pong == GNUNET_NO)
3955 { 3844 {
3956#if DEBUG_TRANSPORT 3845#if DEBUG_TRANSPORT
3957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3846 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3958 "Received message of type %u and size %u from `%4s', but no pong yet!\n", 3847 "Received message of type %u and size %u from `%4s', but no pong yet!\n",
3959 ntohs (message->type), 3848 ntohs (message->type),
3960 ntohs (message->size), 3849 ntohs (message->size), GNUNET_i2s (&n->id));
3961 GNUNET_i2s (&n->id));
3962#endif 3850#endif
3963 GNUNET_free_non_null (n->pre_connect_message_buffer); 3851 GNUNET_free_non_null (n->pre_connect_message_buffer);
3964 n->pre_connect_message_buffer = GNUNET_malloc (msize); 3852 n->pre_connect_message_buffer = GNUNET_malloc (msize);
3965 memcpy (n->pre_connect_message_buffer, message, msize); 3853 memcpy (n->pre_connect_message_buffer, message, msize);
3966 return; 3854 return;
3967 } 3855 }
3968 3856
3969#if DEBUG_TRANSPORT 3857#if DEBUG_TRANSPORT
3970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3971 "Received message of type %u and size %u from `%4s', sending to all clients.\n", 3859 "Received message of type %u and size %u from `%4s', sending to all clients.\n",
3972 ntohs (message->type), 3860 ntohs (message->type),
3973 ntohs (message->size), 3861 ntohs (message->size), GNUNET_i2s (&n->id));
3974 GNUNET_i2s (&n->id));
3975#endif 3862#endif
3976 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 3863 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
3977 (ssize_t) msize)) 3864 (ssize_t) msize))
3978 { 3865 {
3979 n->quota_violation_count++; 3866 n->quota_violation_count++;
3980#if DEBUG_TRANSPORT 3867#if DEBUG_TRANSPORT
3981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3982 "Bandwidth quota (%u b/s) violation detected (total of %u).\n", 3869 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
3983 n->in_tracker.available_bytes_per_s__, 3870 n->in_tracker.available_bytes_per_s__,
3984 n->quota_violation_count); 3871 n->quota_violation_count);
3985#endif 3872#endif
3986 /* Discount 32k per violation */ 3873 /* Discount 32k per violation */
3987 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 3874 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
3988 - 32 * 1024); 3875 }
3989 }
3990 else 3876 else
3877 {
3878 if (n->quota_violation_count > 0)
3991 { 3879 {
3992 if (n->quota_violation_count > 0) 3880 /* try to add 32k back */
3993 { 3881 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
3994 /* try to add 32k back */ 3882 n->quota_violation_count--;
3995 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
3996 32 * 1024);
3997 n->quota_violation_count--;
3998 }
3999 } 3883 }
3884 }
4000 GNUNET_STATISTICS_update (stats, 3885 GNUNET_STATISTICS_update (stats,
4001 gettext_noop ("# payload received from other peers"), 3886 gettext_noop
4002 msize, 3887 ("# payload received from other peers"), msize,
4003 GNUNET_NO); 3888 GNUNET_NO);
4004 /* transmit message to all clients */ 3889 /* transmit message to all clients */
4005 uint32_t ats_count = 2; 3890 uint32_t ats_count = 2;
4006 size_t size = sizeof (struct InboundMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + msize; 3891 size_t size =
3892 sizeof (struct InboundMessage) +
3893 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + msize;
4007 if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE) 3894 if (size > GNUNET_SERVER_MAX_MESSAGE_SIZE)
4008 GNUNET_break(0); 3895 GNUNET_break (0);
4009 3896
4010 im = GNUNET_malloc (size); 3897 im = GNUNET_malloc (size);
4011 im->header.size = htons (size); 3898 im->header.size = htons (size);
4012 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV); 3899 im->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_RECV);
4013 im->peer = n->id; 3900 im->peer = n->id;
4014 im->ats_count = htonl(ats_count); 3901 im->ats_count = htonl (ats_count);
4015 /* Setting ATS data */ 3902 /* Setting ATS data */
4016 (&(im->ats))[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 3903 (&(im->ats))[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
4017 (&(im->ats))[0].value = htonl (n->distance); 3904 (&(im->ats))[0].value = htonl (n->distance);
@@ -4020,13 +3907,13 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
4020 (&(im->ats))[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 3907 (&(im->ats))[ats_count].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
4021 (&(im->ats))[ats_count].value = htonl (0); 3908 (&(im->ats))[ats_count].value = htonl (0);
4022 3909
4023 memcpy (&((&(im->ats))[ats_count+1]), message, msize); 3910 memcpy (&((&(im->ats))[ats_count + 1]), message, msize);
4024 cpos = clients; 3911 cpos = clients;
4025 while (cpos != NULL) 3912 while (cpos != NULL)
4026 { 3913 {
4027 transmit_to_client (cpos, &im->header, GNUNET_YES); 3914 transmit_to_client (cpos, &im->header, GNUNET_YES);
4028 cpos = cpos->next; 3915 cpos = cpos->next;
4029 } 3916 }
4030 GNUNET_free (im); 3917 GNUNET_free (im);
4031} 3918}
4032 3919
@@ -4042,14 +3929,12 @@ handle_payload_message (const struct GNUNET_MessageHeader *message,
4042 * iterate (mismatch), GNUNET_NO if not (entry matched) 3929 * iterate (mismatch), GNUNET_NO if not (entry matched)
4043 */ 3930 */
4044static int 3931static int
4045check_pending_validation (void *cls, 3932check_pending_validation (void *cls, const GNUNET_HashCode * key, void *value)
4046 const GNUNET_HashCode * key,
4047 void *value)
4048{ 3933{
4049 const struct TransportPongMessage *pong = cls; 3934 const struct TransportPongMessage *pong = cls;
4050 struct ValidationEntry *ve = value; 3935 struct ValidationEntry *ve = value;
4051 struct AddValidatedAddressContext avac; 3936 struct AddValidatedAddressContext avac;
4052 unsigned int challenge = ntohl(pong->challenge); 3937 unsigned int challenge = ntohl (pong->challenge);
4053 struct GNUNET_HELLO_Message *hello; 3938 struct GNUNET_HELLO_Message *hello;
4054 struct GNUNET_PeerIdentity target; 3939 struct GNUNET_PeerIdentity target;
4055 struct NeighbourMapEntry *n; 3940 struct NeighbourMapEntry *n;
@@ -4064,217 +3949,201 @@ check_pending_validation (void *cls,
4064 3949
4065 ps = ntohs (pong->header.size); 3950 ps = ntohs (pong->header.size);
4066 if (ps < sizeof (struct TransportPongMessage)) 3951 if (ps < sizeof (struct TransportPongMessage))
3952 {
3953 GNUNET_break_op (0);
3954 return GNUNET_NO;
3955 }
3956 addr = (const char *) &pong[1];
3957 slen = strlen (ve->transport_name) + 1;
3958 if ((ps - sizeof (struct TransportPongMessage) < slen) ||
3959 (ve->challenge != challenge) ||
3960 (addr[slen - 1] != '\0') ||
3961 (0 != strcmp (addr, ve->transport_name)) ||
3962 (ntohl (pong->purpose.size)
3963 != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
3964 sizeof (uint32_t) +
3965 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
3966 sizeof (struct GNUNET_PeerIdentity) + ps -
3967 sizeof (struct TransportPongMessage)))
3968 {
3969 return GNUNET_YES;
3970 }
3971
3972 alen = ps - sizeof (struct TransportPongMessage) - slen;
3973 switch (ntohl (pong->purpose.purpose))
3974 {
3975 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN:
3976 if ((ve->addrlen + slen != ntohl (pong->addrlen)) ||
3977 (0 != memcmp (&addr[slen], ve->addr, ve->addrlen)))
3978 {
3979 return GNUNET_YES; /* different entry, keep trying! */
3980 }
3981 if (0 != memcmp (&pong->pid, key, sizeof (struct GNUNET_PeerIdentity)))
4067 { 3982 {
4068 GNUNET_break_op (0); 3983 GNUNET_break_op (0);
4069 return GNUNET_NO; 3984 return GNUNET_NO;
4070 } 3985 }
4071 addr = (const char*) &pong[1]; 3986 if (GNUNET_OK !=
4072 slen = strlen (ve->transport_name) + 1; 3987 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
4073 if ( (ps - sizeof (struct TransportPongMessage) < slen) || 3988 &pong->purpose,
4074 (ve->challenge != challenge) || 3989 &pong->signature, &ve->publicKey))
4075 (addr[slen-1] != '\0') ||
4076 (0 != strcmp (addr, ve->transport_name)) ||
4077 (ntohl (pong->purpose.size)
4078 != sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
4079 sizeof (uint32_t) +
4080 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
4081 sizeof (struct GNUNET_PeerIdentity) + ps - sizeof (struct TransportPongMessage)) )
4082 { 3990 {
4083 return GNUNET_YES; 3991 GNUNET_break_op (0);
3992 return GNUNET_NO;
4084 } 3993 }
4085 3994
4086 alen = ps - sizeof (struct TransportPongMessage) - slen;
4087 switch (ntohl (pong->purpose.purpose))
4088 {
4089 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN:
4090 if ( (ve->addrlen + slen != ntohl (pong->addrlen)) ||
4091 (0 != memcmp (&addr[slen],
4092 ve->addr,
4093 ve->addrlen)) )
4094 {
4095 return GNUNET_YES; /* different entry, keep trying! */
4096 }
4097 if (0 != memcmp (&pong->pid,
4098 key,
4099 sizeof (struct GNUNET_PeerIdentity)))
4100 {
4101 GNUNET_break_op (0);
4102 return GNUNET_NO;
4103 }
4104 if (GNUNET_OK !=
4105 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
4106 &pong->purpose,
4107 &pong->signature,
4108 &ve->publicKey))
4109 {
4110 GNUNET_break_op (0);
4111 return GNUNET_NO;
4112 }
4113
4114#if DEBUG_TRANSPORT
4115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4116 "Confirmed validity of address, peer `%4s' has address `%s' (%s).\n",
4117 GNUNET_h2s (key),
4118 a2s (ve->transport_name,
4119 (const struct sockaddr *) ve->addr,
4120 ve->addrlen),
4121 ve->transport_name);
4122#endif
4123 break;
4124 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
4125 if (0 != memcmp (&pong->pid,
4126 &my_identity,
4127 sizeof (struct GNUNET_PeerIdentity)))
4128 {
4129 char * peer;
4130
4131 GNUNET_asprintf(&peer, "%s",GNUNET_i2s (&pong->pid));
4132#if DEBUG_TRANSPORT 3995#if DEBUG_TRANSPORT
4133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4134 "Received PONG for different identity: I am `%s', PONG identity: `%s'\n", 3997 "Confirmed validity of address, peer `%4s' has address `%s' (%s).\n",
4135 GNUNET_i2s (&my_identity), 3998 GNUNET_h2s (key),
4136 peer ); 3999 a2s (ve->transport_name,
4137#endif 4000 (const struct sockaddr *) ve->addr,
4138 GNUNET_free (peer); 4001 ve->addrlen), ve->transport_name);
4139 return GNUNET_NO;
4140 }
4141 if (ve->addrlen != 0)
4142 {
4143 /* must have been for a different validation entry */
4144 return GNUNET_YES;
4145 }
4146 tp = find_transport (ve->transport_name);
4147 if (tp == NULL)
4148 {
4149 GNUNET_break (0);
4150 return GNUNET_YES;
4151 }
4152 oal = tp->addresses;
4153 while (NULL != oal)
4154 {
4155 if ( (oal->addrlen == alen) &&
4156 (0 == memcmp (&oal[1],
4157 &addr[slen],
4158 alen)) )
4159 break;
4160 oal = oal->next;
4161 }
4162 if (oal == NULL)
4163 {
4164 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4165 _("Not accepting PONG from `%s' with address `%s' since I cannot confirm using this address.\n"),
4166 GNUNET_i2s (&pong->pid),
4167 a2s (ve->transport_name,
4168 &addr[slen],
4169 alen));
4170 /* FIXME: since the sender of the PONG currently uses the
4171 wrong address (see FIMXE there!), we cannot run a
4172 proper check here... */
4173#if FIXME_URGENT
4174 return GNUNET_NO;
4175#endif 4002#endif
4176 } 4003 break;
4177 if (GNUNET_OK != 4004 case GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING:
4178 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING, 4005 if (0 != memcmp (&pong->pid,
4179 &pong->purpose, 4006 &my_identity, sizeof (struct GNUNET_PeerIdentity)))
4180 &pong->signature, 4007 {
4181 &ve->publicKey)) 4008 char *peer;
4182 {
4183 GNUNET_break_op (0);
4184 return GNUNET_NO;
4185 }
4186 4009
4010 GNUNET_asprintf (&peer, "%s", GNUNET_i2s (&pong->pid));
4187#if DEBUG_TRANSPORT 4011#if DEBUG_TRANSPORT
4188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4012 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4189 "Confirmed that peer `%4s' is talking to us using address `%s' (%s) for us.\n", 4013 "Received PONG for different identity: I am `%s', PONG identity: `%s'\n",
4190 GNUNET_h2s (key), 4014 GNUNET_i2s (&my_identity), peer);
4191 a2s (ve->transport_name,
4192 &addr[slen],
4193 alen),
4194 ve->transport_name);
4195#endif 4015#endif
4196 break; 4016 GNUNET_free (peer);
4197 default:
4198 GNUNET_break_op (0);
4199 return GNUNET_NO; 4017 return GNUNET_NO;
4200 } 4018 }
4201 if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0) 4019 if (ve->addrlen != 0)
4202 { 4020 {
4203 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4021 /* must have been for a different validation entry */
4204 _("Received expired signature. Check system time.\n")); 4022 return GNUNET_YES;
4023 }
4024 tp = find_transport (ve->transport_name);
4025 if (tp == NULL)
4026 {
4027 GNUNET_break (0);
4028 return GNUNET_YES;
4029 }
4030 oal = tp->addresses;
4031 while (NULL != oal)
4032 {
4033 if ((oal->addrlen == alen) && (0 == memcmp (&oal[1], &addr[slen], alen)))
4034 break;
4035 oal = oal->next;
4036 }
4037 if (oal == NULL)
4038 {
4039 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4040 _
4041 ("Not accepting PONG from `%s' with address `%s' since I cannot confirm using this address.\n"),
4042 GNUNET_i2s (&pong->pid), a2s (ve->transport_name, &addr[slen],
4043 alen));
4044 /* FIXME: since the sender of the PONG currently uses the
4045 * wrong address (see FIMXE there!), we cannot run a
4046 * proper check here... */
4047#if FIXME_URGENT
4205 return GNUNET_NO; 4048 return GNUNET_NO;
4049#endif
4206 } 4050 }
4051 if (GNUNET_OK !=
4052 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING,
4053 &pong->purpose,
4054 &pong->signature, &ve->publicKey))
4055 {
4056 GNUNET_break_op (0);
4057 return GNUNET_NO;
4058 }
4059
4060#if DEBUG_TRANSPORT
4061 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4062 "Confirmed that peer `%4s' is talking to us using address `%s' (%s) for us.\n",
4063 GNUNET_h2s (key),
4064 a2s (ve->transport_name,
4065 &addr[slen], alen), ve->transport_name);
4066#endif
4067 break;
4068 default:
4069 GNUNET_break_op (0);
4070 return GNUNET_NO;
4071 }
4072 if (GNUNET_TIME_absolute_get_remaining
4073 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
4074 {
4075 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4076 _("Received expired signature. Check system time.\n"));
4077 return GNUNET_NO;
4078 }
4207 GNUNET_STATISTICS_update (stats, 4079 GNUNET_STATISTICS_update (stats,
4208 gettext_noop ("# address validation successes"), 4080 gettext_noop ("# address validation successes"),
4209 1, 4081 1, GNUNET_NO);
4210 GNUNET_NO);
4211 /* create the updated HELLO */ 4082 /* create the updated HELLO */
4212 GNUNET_CRYPTO_hash (&ve->publicKey, 4083 GNUNET_CRYPTO_hash (&ve->publicKey,
4213 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 4084 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4214 &target.hashPubKey); 4085 &target.hashPubKey);
4215 if (ve->addr != NULL) 4086 if (ve->addr != NULL)
4216 { 4087 {
4217 avac.done = GNUNET_NO; 4088 avac.done = GNUNET_NO;
4218 avac.ve = ve; 4089 avac.ve = ve;
4219 hello = GNUNET_HELLO_create (&ve->publicKey, 4090 hello = GNUNET_HELLO_create (&ve->publicKey, &add_validated_address, &avac);
4220 &add_validated_address, 4091 GNUNET_PEERINFO_add_peer (peerinfo, hello);
4221 &avac); 4092 GNUNET_free (hello);
4222 GNUNET_PEERINFO_add_peer (peerinfo, 4093 }
4223 hello);
4224 GNUNET_free (hello);
4225 }
4226 n = find_neighbour (&target); 4094 n = find_neighbour (&target);
4227 if (n != NULL) 4095 if (n != NULL)
4096 {
4097 n->publicKey = ve->publicKey;
4098 n->public_key_valid = GNUNET_YES;
4099 fal = add_peer_address (n,
4100 ve->transport_name,
4101 ve->session, ve->addr, ve->addrlen);
4102 GNUNET_assert (fal != NULL);
4103 fal->expires = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
4104 fal->validated = GNUNET_YES;
4105 mark_address_connected (fal);
4106 GNUNET_STATISTICS_update (stats,
4107 gettext_noop
4108 ("# peer addresses considered valid"), 1,
4109 GNUNET_NO);
4110 fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
4111 update_addr_value (fal,
4112 GNUNET_TIME_absolute_get_duration (ve->
4113 send_time).rel_value,
4114 GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
4115
4116 schedule_next_ping (fal);
4117 if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
4118 n->latency = fal->latency;
4119 else
4120 n->latency.rel_value =
4121 (fal->latency.rel_value + n->latency.rel_value) / 2;
4122
4123 n->distance = fal->distance;
4124 if (GNUNET_NO == n->received_pong)
4125 {
4126 n->received_pong = GNUNET_YES;
4127 notify_clients_connect (&target, n->latency, n->distance);
4128 if (NULL != (prem = n->pre_connect_message_buffer))
4129 {
4130 n->pre_connect_message_buffer = NULL;
4131 handle_payload_message (prem, n);
4132 GNUNET_free (prem);
4133 }
4134 }
4135 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
4228 { 4136 {
4229 n->publicKey = ve->publicKey; 4137 GNUNET_SCHEDULER_cancel (n->retry_task);
4230 n->public_key_valid = GNUNET_YES; 4138 n->retry_task = GNUNET_SCHEDULER_NO_TASK;
4231 fal = add_peer_address (n, 4139 try_transmission_to_peer (n);
4232 ve->transport_name,
4233 ve->session,
4234 ve->addr,
4235 ve->addrlen);
4236 GNUNET_assert (fal != NULL);
4237 fal->expires = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
4238 fal->validated = GNUNET_YES;
4239 mark_address_connected (fal);
4240 GNUNET_STATISTICS_update (stats,
4241 gettext_noop ("# peer addresses considered valid"),
4242 1,
4243 GNUNET_NO);
4244 fal->latency = GNUNET_TIME_absolute_get_duration (ve->send_time);
4245 update_addr_value (fal, GNUNET_TIME_absolute_get_duration (ve->send_time).rel_value, GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
4246
4247 schedule_next_ping (fal);
4248 if (n->latency.rel_value == GNUNET_TIME_UNIT_FOREVER_REL.rel_value)
4249 n->latency = fal->latency;
4250 else
4251 n->latency.rel_value = (fal->latency.rel_value + n->latency.rel_value) / 2;
4252
4253 n->distance = fal->distance;
4254 if (GNUNET_NO == n->received_pong)
4255 {
4256 n->received_pong = GNUNET_YES;
4257 notify_clients_connect (&target, n->latency, n->distance);
4258 if (NULL != (prem = n->pre_connect_message_buffer))
4259 {
4260 n->pre_connect_message_buffer = NULL;
4261 handle_payload_message (prem, n);
4262 GNUNET_free (prem);
4263 }
4264 }
4265 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
4266 {
4267 GNUNET_SCHEDULER_cancel (n->retry_task);
4268 n->retry_task = GNUNET_SCHEDULER_NO_TASK;
4269 try_transmission_to_peer (n);
4270 }
4271 } 4140 }
4141 }
4272 4142
4273 /* clean up validation entry */ 4143 /* clean up validation entry */
4274 GNUNET_assert (GNUNET_YES == 4144 GNUNET_assert (GNUNET_YES ==
4275 GNUNET_CONTAINER_multihashmap_remove (validation_map, 4145 GNUNET_CONTAINER_multihashmap_remove (validation_map,
4276 key, 4146 key, ve));
4277 ve));
4278 abort_validation (NULL, NULL, ve); 4147 abort_validation (NULL, NULL, ve);
4279 return GNUNET_NO; 4148 return GNUNET_NO;
4280} 4149}
@@ -4298,51 +4167,44 @@ check_pending_validation (void *cls,
4298static void 4167static void
4299handle_pong (void *cls, const struct GNUNET_MessageHeader *message, 4168handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
4300 const struct GNUNET_PeerIdentity *peer, 4169 const struct GNUNET_PeerIdentity *peer,
4301 const char *sender_address, 4170 const char *sender_address, size_t sender_address_len)
4302 size_t sender_address_len)
4303{ 4171{
4304 if (0 == memcmp (peer, 4172 if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
4305 &my_identity, 4173 {
4306 sizeof (struct GNUNET_PeerIdentity))) 4174 /* PONG send to self, ignore */
4307 { 4175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4308 /* PONG send to self, ignore */ 4176 "Receiving `%s' message from myself\n", "PONG");
4309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4177 return;
4310 "Receiving `%s' message from myself\n", 4178 }
4311 "PONG");
4312 return;
4313 }
4314#if DEBUG_TRANSPORT > 1 4179#if DEBUG_TRANSPORT > 1
4315 /* we get tons of these that just get discarded, only log 4180 /* we get tons of these that just get discarded, only log
4316 if we are quite verbose */ 4181 * if we are quite verbose */
4317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4318 "Receiving `%s' message from `%4s'.\n", "PONG", 4183 "Receiving `%s' message from `%4s'.\n", "PONG",
4319 GNUNET_i2s (peer)); 4184 GNUNET_i2s (peer));
4320#endif 4185#endif
4321 GNUNET_STATISTICS_update (stats, 4186 GNUNET_STATISTICS_update (stats,
4322 gettext_noop ("# PONG messages received"), 4187 gettext_noop ("# PONG messages received"),
4323 1, 4188 1, GNUNET_NO);
4324 GNUNET_NO);
4325 if (GNUNET_SYSERR != 4189 if (GNUNET_SYSERR !=
4326 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, 4190 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
4327 &peer->hashPubKey, 4191 &peer->hashPubKey,
4328 &check_pending_validation, 4192 &check_pending_validation,
4329 (void*) message)) 4193 (void *) message))
4330 { 4194 {
4331 /* This is *expected* to happen a lot since we send 4195 /* This is *expected* to happen a lot since we send
4332 PONGs to *all* known addresses of the sender of 4196 * PONGs to *all* known addresses of the sender of
4333 the PING, so most likely we get multiple PONGs 4197 * the PING, so most likely we get multiple PONGs
4334 per PING, and all but the first PONG will end up 4198 * per PING, and all but the first PONG will end up
4335 here. So really we should not print anything here 4199 * here. So really we should not print anything here
4336 unless we want to be very, very verbose... */ 4200 * unless we want to be very, very verbose... */
4337#if DEBUG_TRANSPORT > 2 4201#if DEBUG_TRANSPORT > 2
4338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4339 "Received `%s' message from `%4s' but have no record of a matching `%s' message. Ignoring.\n", 4203 "Received `%s' message from `%4s' but have no record of a matching `%s' message. Ignoring.\n",
4340 "PONG", 4204 "PONG", GNUNET_i2s (peer), "PING");
4341 GNUNET_i2s (peer),
4342 "PING");
4343#endif 4205#endif
4344 return; 4206 return;
4345 } 4207 }
4346 4208
4347} 4209}
4348 4210
@@ -4354,92 +4216,86 @@ handle_pong (void *cls, const struct GNUNET_MessageHeader *message,
4354 * @param neighbour neighbour to validate, NULL if validation failed 4216 * @param neighbour neighbour to validate, NULL if validation failed
4355 */ 4217 */
4356static void 4218static void
4357transmit_hello_and_ping (void *cls, 4219transmit_hello_and_ping (void *cls, struct NeighbourMapEntry *neighbour)
4358 struct NeighbourMapEntry *neighbour)
4359{ 4220{
4360 struct ValidationEntry *va = cls; 4221 struct ValidationEntry *va = cls;
4361 struct ForeignAddressList *peer_address; 4222 struct ForeignAddressList *peer_address;
4362 struct TransportPingMessage ping; 4223 struct TransportPingMessage ping;
4363 uint16_t hello_size; 4224 uint16_t hello_size;
4364 size_t tsize; 4225 size_t tsize;
4365 char * message_buf; 4226 char *message_buf;
4366 struct GNUNET_PeerIdentity id; 4227 struct GNUNET_PeerIdentity id;
4367 size_t slen; 4228 size_t slen;
4368 4229
4369 GNUNET_CRYPTO_hash (&va->publicKey, 4230 GNUNET_CRYPTO_hash (&va->publicKey,
4370 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 4231 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4371 &id.hashPubKey); 4232 &id.hashPubKey);
4372 if (neighbour == NULL) 4233 if (neighbour == NULL)
4373 { 4234 {
4374 /* FIXME: stats... */ 4235 /* FIXME: stats... */
4375 GNUNET_break (GNUNET_OK == 4236 GNUNET_break (GNUNET_OK ==
4376 GNUNET_CONTAINER_multihashmap_remove (validation_map, 4237 GNUNET_CONTAINER_multihashmap_remove (validation_map,
4377 &id.hashPubKey, 4238 &id.hashPubKey, va));
4378 va)); 4239 abort_validation (NULL, NULL, va);
4379 abort_validation (NULL, NULL, va); 4240 return;
4380 return; 4241 }
4381 }
4382 neighbour->publicKey = va->publicKey; 4242 neighbour->publicKey = va->publicKey;
4383 neighbour->public_key_valid = GNUNET_YES; 4243 neighbour->public_key_valid = GNUNET_YES;
4384 peer_address = add_peer_address (neighbour, 4244 peer_address = add_peer_address (neighbour,
4385 va->transport_name, NULL, 4245 va->transport_name, NULL,
4386 (const void*) &va[1], 4246 (const void *) &va[1], va->addrlen);
4387 va->addrlen);
4388 if (peer_address == NULL) 4247 if (peer_address == NULL)
4389 { 4248 {
4390 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 4249 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
4391 "Failed to add peer `%4s' for plugin `%s'\n", 4250 "Failed to add peer `%4s' for plugin `%s'\n",
4392 GNUNET_i2s (&neighbour->id), 4251 GNUNET_i2s (&neighbour->id), va->transport_name);
4393 va->transport_name); 4252 GNUNET_break (GNUNET_OK ==
4394 GNUNET_break (GNUNET_OK == 4253 GNUNET_CONTAINER_multihashmap_remove (validation_map,
4395 GNUNET_CONTAINER_multihashmap_remove (validation_map, 4254 &id.hashPubKey, va));
4396 &id.hashPubKey, 4255 abort_validation (NULL, NULL, va);
4397 va)); 4256 return;
4398 abort_validation (NULL, NULL, va); 4257 }
4399 return;
4400 }
4401 if (NULL == our_hello) 4258 if (NULL == our_hello)
4402 refresh_hello_task (NULL, NULL); 4259 refresh_hello_task (NULL, NULL);
4403 hello_size = GNUNET_HELLO_size(our_hello); 4260 hello_size = GNUNET_HELLO_size (our_hello);
4404 slen = strlen(va->transport_name) + 1; 4261 slen = strlen (va->transport_name) + 1;
4405 tsize = sizeof(struct TransportPingMessage) + hello_size + va->addrlen + slen; 4262 tsize =
4406 message_buf = GNUNET_malloc(tsize); 4263 sizeof (struct TransportPingMessage) + hello_size + va->addrlen + slen;
4407 ping.challenge = htonl(va->challenge); 4264 message_buf = GNUNET_malloc (tsize);
4408 ping.header.size = htons(sizeof(struct TransportPingMessage) + slen + va->addrlen); 4265 ping.challenge = htonl (va->challenge);
4409 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 4266 ping.header.size =
4410 memcpy(&ping.target, &neighbour->id, sizeof(struct GNUNET_PeerIdentity)); 4267 htons (sizeof (struct TransportPingMessage) + slen + va->addrlen);
4411 memcpy(message_buf, our_hello, hello_size); 4268 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
4412 memcpy(&message_buf[hello_size], 4269 memcpy (&ping.target, &neighbour->id, sizeof (struct GNUNET_PeerIdentity));
4413 &ping, 4270 memcpy (message_buf, our_hello, hello_size);
4414 sizeof(struct TransportPingMessage)); 4271 memcpy (&message_buf[hello_size],
4415 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage)], 4272 &ping, sizeof (struct TransportPingMessage));
4416 va->transport_name, 4273 memcpy (&message_buf[hello_size + sizeof (struct TransportPingMessage)],
4417 slen); 4274 va->transport_name, slen);
4418 memcpy(&message_buf[hello_size + sizeof (struct TransportPingMessage) + slen], 4275 memcpy (&message_buf
4419 &va[1], 4276 [hello_size + sizeof (struct TransportPingMessage) + slen], &va[1],
4420 va->addrlen); 4277 va->addrlen);
4421#if DEBUG_TRANSPORT 4278#if DEBUG_TRANSPORT
4422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4423 "Performing validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s' (%u bytes)\n", 4280 "Performing validation of address `%s' via `%s' for peer `%4s' sending `%s' (%u bytes) and `%s' (%u bytes)\n",
4424 (va->addrlen == 0) 4281 (va->addrlen == 0)
4425 ? "<inbound>" 4282 ? "<inbound>"
4426 : a2s (va->transport_name, 4283 : a2s (va->transport_name,
4427 (const void*) &va[1], va->addrlen), 4284 (const void *) &va[1], va->addrlen),
4428 va->transport_name, 4285 va->transport_name,
4429 GNUNET_i2s (&neighbour->id), 4286 GNUNET_i2s (&neighbour->id),
4430 "HELLO", hello_size, 4287 "HELLO", hello_size,
4431 "PING", sizeof (struct TransportPingMessage) + va->addrlen + slen); 4288 "PING",
4289 sizeof (struct TransportPingMessage) + va->addrlen + slen);
4432#endif 4290#endif
4433 4291
4434 GNUNET_STATISTICS_update (stats, 4292 GNUNET_STATISTICS_update (stats,
4435 gettext_noop ("# PING messages sent for initial validation"), 4293 gettext_noop
4436 1, 4294 ("# PING messages sent for initial validation"), 1,
4437 GNUNET_NO); 4295 GNUNET_NO);
4438 transmit_to_peer (NULL, peer_address, 4296 transmit_to_peer (NULL, peer_address, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
4439 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 4297 HELLO_VERIFICATION_TIMEOUT, message_buf, tsize, GNUNET_YES,
4440 HELLO_VERIFICATION_TIMEOUT, 4298 neighbour);
4441 message_buf, tsize,
4442 GNUNET_YES, neighbour);
4443 GNUNET_free (message_buf); 4299 GNUNET_free (message_buf);
4444} 4300}
4445 4301
@@ -4460,8 +4316,7 @@ static int
4460run_validation (void *cls, 4316run_validation (void *cls,
4461 const char *tname, 4317 const char *tname,
4462 struct GNUNET_TIME_Absolute expiration, 4318 struct GNUNET_TIME_Absolute expiration,
4463 const void *addr, 4319 const void *addr, uint16_t addrlen)
4464 uint16_t addrlen)
4465{ 4320{
4466 struct CheckHelloValidatedContext *chvc = cls; 4321 struct CheckHelloValidatedContext *chvc = cls;
4467 struct GNUNET_PeerIdentity id; 4322 struct GNUNET_PeerIdentity id;
@@ -4474,57 +4329,53 @@ run_validation (void *cls,
4474 GNUNET_assert (addr != NULL); 4329 GNUNET_assert (addr != NULL);
4475 4330
4476 GNUNET_STATISTICS_update (stats, 4331 GNUNET_STATISTICS_update (stats,
4477 gettext_noop ("# peer addresses scheduled for validation"), 4332 gettext_noop
4478 1, 4333 ("# peer addresses scheduled for validation"), 1,
4479 GNUNET_NO); 4334 GNUNET_NO);
4480 tp = find_transport (tname); 4335 tp = find_transport (tname);
4481 if (tp == NULL) 4336 if (tp == NULL)
4482 { 4337 {
4483 GNUNET_log (GNUNET_ERROR_TYPE_INFO | 4338 GNUNET_log (GNUNET_ERROR_TYPE_INFO |
4484 GNUNET_ERROR_TYPE_BULK, 4339 GNUNET_ERROR_TYPE_BULK,
4485 _ 4340 _
4486 ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"), 4341 ("Transport `%s' not loaded, will not try to validate peer address using this transport.\n"),
4487 tname); 4342 tname);
4488 GNUNET_STATISTICS_update (stats, 4343 GNUNET_STATISTICS_update (stats,
4489 gettext_noop ("# peer addresses not validated (plugin not available)"), 4344 gettext_noop
4490 1, 4345 ("# peer addresses not validated (plugin not available)"),
4491 GNUNET_NO); 4346 1, GNUNET_NO);
4492 return GNUNET_OK; 4347 return GNUNET_OK;
4493 } 4348 }
4494 /* check if this is one of our own addresses */ 4349 /* check if this is one of our own addresses */
4495 oal = tp->addresses; 4350 oal = tp->addresses;
4496 while (NULL != oal) 4351 while (NULL != oal)
4352 {
4353 if ((oal->addrlen == addrlen) && (0 == memcmp (&oal[1], addr, addrlen)))
4497 { 4354 {
4498 if ( (oal->addrlen == addrlen) && 4355 /* not plausible, this address is equivalent to our own address! */
4499 (0 == memcmp (&oal[1], 4356 GNUNET_STATISTICS_update (stats,
4500 addr, 4357 gettext_noop
4501 addrlen)) ) 4358 ("# peer addresses not validated (loopback)"),
4502 { 4359 1, GNUNET_NO);
4503 /* not plausible, this address is equivalent to our own address! */ 4360 return GNUNET_OK;
4504 GNUNET_STATISTICS_update (stats,
4505 gettext_noop ("# peer addresses not validated (loopback)"),
4506 1,
4507 GNUNET_NO);
4508 return GNUNET_OK;
4509 }
4510 oal = oal->next;
4511 } 4361 }
4362 oal = oal->next;
4363 }
4512 GNUNET_HELLO_get_key (chvc->hello, &pk); 4364 GNUNET_HELLO_get_key (chvc->hello, &pk);
4513 GNUNET_CRYPTO_hash (&pk, 4365 GNUNET_CRYPTO_hash (&pk,
4514 sizeof (struct 4366 sizeof (struct
4515 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 4367 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4516 &id.hashPubKey); 4368 &id.hashPubKey);
4517 4369
4518 if (is_blacklisted(&id, tp)) 4370 if (is_blacklisted (&id, tp))
4519 { 4371 {
4520#if DEBUG_TRANSPORT 4372#if DEBUG_TRANSPORT
4521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4522 "Attempted to validate blacklisted peer `%s' using `%s'!\n", 4374 "Attempted to validate blacklisted peer `%s' using `%s'!\n",
4523 GNUNET_i2s(&id), 4375 GNUNET_i2s (&id), tname);
4524 tname);
4525#endif 4376#endif
4526 return GNUNET_OK; 4377 return GNUNET_OK;
4527 } 4378 }
4528 4379
4529 caec.addr = addr; 4380 caec.addr = addr;
4530 caec.addrlen = addrlen; 4381 caec.addrlen = addrlen;
@@ -4532,49 +4383,43 @@ run_validation (void *cls,
4532 caec.tname = tname; 4383 caec.tname = tname;
4533 caec.exists = GNUNET_NO; 4384 caec.exists = GNUNET_NO;
4534 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 4385 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
4535 &check_address_exists, 4386 &check_address_exists, &caec);
4536 &caec);
4537 if (caec.exists == GNUNET_YES) 4387 if (caec.exists == GNUNET_YES)
4538 { 4388 {
4539 /* During validation attempts we will likely trigger the other 4389 /* During validation attempts we will likely trigger the other
4540 peer trying to validate our address which in turn will cause 4390 * peer trying to validate our address which in turn will cause
4541 it to send us its HELLO, so we expect to hit this case rather 4391 * it to send us its HELLO, so we expect to hit this case rather
4542 frequently. Only print something if we are very verbose. */ 4392 * frequently. Only print something if we are very verbose. */
4543#if DEBUG_TRANSPORT > 1 4393#if DEBUG_TRANSPORT > 1
4544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4545 "Validation of address `%s' via `%s' for peer `%4s' already in progress.\n", 4395 "Validation of address `%s' via `%s' for peer `%4s' already in progress.\n",
4546 a2s (tname, addr, addrlen), 4396 a2s (tname, addr, addrlen), tname, GNUNET_i2s (&id));
4547 tname,
4548 GNUNET_i2s (&id));
4549#endif 4397#endif
4550 GNUNET_STATISTICS_update (stats, 4398 GNUNET_STATISTICS_update (stats,
4551 gettext_noop ("# peer addresses not validated (in progress)"), 4399 gettext_noop
4552 1, 4400 ("# peer addresses not validated (in progress)"),
4553 GNUNET_NO); 4401 1, GNUNET_NO);
4554 return GNUNET_OK; 4402 return GNUNET_OK;
4555 } 4403 }
4556 va = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen); 4404 va = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
4557 va->chvc = chvc; 4405 va->chvc = chvc;
4558 chvc->ve_count++; 4406 chvc->ve_count++;
4559 va->transport_name = GNUNET_strdup (tname); 4407 va->transport_name = GNUNET_strdup (tname);
4560 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 4408 va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
4561 UINT_MAX); 4409 UINT_MAX);
4562 va->send_time = GNUNET_TIME_absolute_get(); 4410 va->send_time = GNUNET_TIME_absolute_get ();
4563 va->addr = (const void*) &va[1]; 4411 va->addr = (const void *) &va[1];
4564 memcpy (&va[1], addr, addrlen); 4412 memcpy (&va[1], addr, addrlen);
4565 va->addrlen = addrlen; 4413 va->addrlen = addrlen;
4566 GNUNET_HELLO_get_key (chvc->hello, 4414 GNUNET_HELLO_get_key (chvc->hello, &va->publicKey);
4567 &va->publicKey);
4568 va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT, 4415 va->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_VERIFICATION_TIMEOUT,
4569 &timeout_hello_validation, 4416 &timeout_hello_validation,
4570 va); 4417 va);
4571 GNUNET_CONTAINER_multihashmap_put (validation_map, 4418 GNUNET_CONTAINER_multihashmap_put (validation_map,
4572 &id.hashPubKey, 4419 &id.hashPubKey,
4573 va, 4420 va,
4574 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 4421 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
4575 setup_peer_check_blacklist (&id, GNUNET_NO, 4422 setup_peer_check_blacklist (&id, GNUNET_NO, &transmit_hello_and_ping, va);
4576 &transmit_hello_and_ping,
4577 va);
4578 return GNUNET_OK; 4423 return GNUNET_OK;
4579} 4424}
4580 4425
@@ -4601,111 +4446,98 @@ check_hello_validated (void *cls,
4601 struct NeighbourMapEntry *n; 4446 struct NeighbourMapEntry *n;
4602 4447
4603 if (err_msg != NULL) 4448 if (err_msg != NULL)
4604 { 4449 {
4605#if DEBUG_TRANSPORT 4450#if DEBUG_TRANSPORT
4606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4607 _("Error in communication with PEERINFO service: %s\n"), 4452 _("Error in communication with PEERINFO service: %s\n"),
4608 err_msg); 4453 err_msg);
4609#endif 4454#endif
4610 /* return; */ 4455 /* return; */
4611 } 4456 }
4612 4457
4613 if (peer == NULL) 4458 if (peer == NULL)
4614 { 4459 {
4615 GNUNET_STATISTICS_update (stats, 4460 GNUNET_STATISTICS_update (stats,
4616 gettext_noop ("# outstanding peerinfo iterate requests"), 4461 gettext_noop
4617 -1, 4462 ("# outstanding peerinfo iterate requests"), -1,
4618 GNUNET_NO); 4463 GNUNET_NO);
4619 chvc->piter = NULL; 4464 chvc->piter = NULL;
4620 if (GNUNET_NO == chvc->hello_known) 4465 if (GNUNET_NO == chvc->hello_known)
4621 { 4466 {
4622 /* notify PEERINFO about the peer now, so that we at least 4467 /* notify PEERINFO about the peer now, so that we at least
4623 have the public key if some other component needs it */ 4468 * have the public key if some other component needs it */
4624 GNUNET_HELLO_get_key (chvc->hello, &pk); 4469 GNUNET_HELLO_get_key (chvc->hello, &pk);
4625 GNUNET_CRYPTO_hash (&pk, 4470 GNUNET_CRYPTO_hash (&pk,
4626 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 4471 sizeof (struct
4627 &target.hashPubKey); 4472 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4628 plain_hello = GNUNET_HELLO_create (&pk, 4473 &target.hashPubKey);
4629 NULL, 4474 plain_hello = GNUNET_HELLO_create (&pk, NULL, NULL);
4630 NULL); 4475 GNUNET_PEERINFO_add_peer (peerinfo, plain_hello);
4631 GNUNET_PEERINFO_add_peer (peerinfo, plain_hello); 4476 GNUNET_free (plain_hello);
4632 GNUNET_free (plain_hello);
4633#if DEBUG_TRANSPORT_HELLO 4477#if DEBUG_TRANSPORT_HELLO
4634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4635 "PEERINFO had no `%s' message for peer `%4s', full validation needed.\n", 4479 "PEERINFO had no `%s' message for peer `%4s', full validation needed.\n",
4636 "HELLO", 4480 "HELLO", GNUNET_i2s (&target));
4637 GNUNET_i2s (&target));
4638#endif 4481#endif
4639 GNUNET_STATISTICS_update (stats, 4482 GNUNET_STATISTICS_update (stats,
4640 gettext_noop ("# new HELLOs requiring full validation"), 4483 gettext_noop
4641 1, 4484 ("# new HELLOs requiring full validation"), 1,
4642 GNUNET_NO); 4485 GNUNET_NO);
4643 GNUNET_HELLO_iterate_addresses (chvc->hello, 4486 GNUNET_HELLO_iterate_addresses (chvc->hello, GNUNET_NO, &run_validation,
4644 GNUNET_NO, 4487 chvc);
4645 &run_validation, 4488 }
4646 chvc); 4489 else
4647 } 4490 {
4648 else 4491 GNUNET_STATISTICS_update (stats,
4649 { 4492 gettext_noop ("# duplicate HELLO (peer known)"),
4650 GNUNET_STATISTICS_update (stats, 4493 1, GNUNET_NO);
4651 gettext_noop ("# duplicate HELLO (peer known)"), 4494 }
4652 1, 4495 chvc->ve_count--;
4653 GNUNET_NO); 4496 if (chvc->ve_count == 0)
4654 } 4497 {
4655 chvc->ve_count--; 4498 GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc);
4656 if (chvc->ve_count == 0) 4499 GNUNET_free (chvc);
4657 {
4658 GNUNET_CONTAINER_DLL_remove (chvc_head,
4659 chvc_tail,
4660 chvc);
4661 GNUNET_free (chvc);
4662 }
4663 return;
4664 } 4500 }
4501 return;
4502 }
4665 if (h == NULL) 4503 if (h == NULL)
4666 return; 4504 return;
4667#if DEBUG_TRANSPORT_HELLO 4505#if DEBUG_TRANSPORT_HELLO
4668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4669 "PEERINFO had `%s' message for peer `%4s', validating only new addresses.\n", 4507 "PEERINFO had `%s' message for peer `%4s', validating only new addresses.\n",
4670 "HELLO", 4508 "HELLO", GNUNET_i2s (peer));
4671 GNUNET_i2s (peer));
4672#endif 4509#endif
4673 chvc->hello_known = GNUNET_YES; 4510 chvc->hello_known = GNUNET_YES;
4674 n = find_neighbour (peer); 4511 n = find_neighbour (peer);
4675 if (n != NULL) 4512 if (n != NULL)
4676 { 4513 {
4677#if DEBUG_TRANSPORT_HELLO 4514#if DEBUG_TRANSPORT_HELLO
4678 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4679 "Calling hello_iterate_addresses for %s!\n", 4516 "Calling hello_iterate_addresses for %s!\n", GNUNET_i2s (peer));
4680 GNUNET_i2s (peer));
4681#endif 4517#endif
4682 GNUNET_HELLO_iterate_addresses (h, 4518 GNUNET_HELLO_iterate_addresses (h,
4683 GNUNET_NO, 4519 GNUNET_NO, &add_to_foreign_address_list, n);
4684 &add_to_foreign_address_list, 4520 try_transmission_to_peer (n);
4685 n); 4521 }
4686 try_transmission_to_peer (n);
4687 }
4688 else 4522 else
4689 { 4523 {
4690#if DEBUG_TRANSPORT_HELLO 4524#if DEBUG_TRANSPORT_HELLO
4691 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4525 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4692 "No existing neighbor record for %s!\n", 4526 "No existing neighbor record for %s!\n", GNUNET_i2s (peer));
4693 GNUNET_i2s (peer));
4694#endif 4527#endif
4695 GNUNET_STATISTICS_update (stats, 4528 GNUNET_STATISTICS_update (stats,
4696 gettext_noop ("# no existing neighbour record (validating HELLO)"), 4529 gettext_noop
4697 1, 4530 ("# no existing neighbour record (validating HELLO)"),
4698 GNUNET_NO); 4531 1, GNUNET_NO);
4699 } 4532 }
4700 GNUNET_STATISTICS_update (stats, 4533 GNUNET_STATISTICS_update (stats,
4701 gettext_noop ("# HELLO validations (update case)"), 4534 gettext_noop ("# HELLO validations (update case)"),
4702 1, 4535 1, GNUNET_NO);
4703 GNUNET_NO);
4704 GNUNET_HELLO_iterate_new_addresses (chvc->hello, 4536 GNUNET_HELLO_iterate_new_addresses (chvc->hello,
4705 h, 4537 h,
4706 GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME), 4538 GNUNET_TIME_relative_to_absolute
4707 &run_validation, 4539 (HELLO_REVALIDATION_START_TIME),
4708 chvc); 4540 &run_validation, chvc);
4709} 4541}
4710 4542
4711 4543
@@ -4726,6 +4558,7 @@ process_hello (struct TransportPlugin *plugin,
4726 struct CheckHelloValidatedContext *chvc; 4558 struct CheckHelloValidatedContext *chvc;
4727 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey; 4559 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded publicKey;
4728 struct NeighbourMapEntry *n; 4560 struct NeighbourMapEntry *n;
4561
4729#if DEBUG_TRANSPORT_HELLO > 2 4562#if DEBUG_TRANSPORT_HELLO > 2
4730 char *my_id; 4563 char *my_id;
4731#endif 4564#endif
@@ -4733,27 +4566,25 @@ process_hello (struct TransportPlugin *plugin,
4733 hsize = ntohs (message->size); 4566 hsize = ntohs (message->size);
4734 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_HELLO) || 4567 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_HELLO) ||
4735 (hsize < sizeof (struct GNUNET_MessageHeader))) 4568 (hsize < sizeof (struct GNUNET_MessageHeader)))
4736 { 4569 {
4737 GNUNET_break (0); 4570 GNUNET_break (0);
4738 return GNUNET_SYSERR; 4571 return GNUNET_SYSERR;
4739 } 4572 }
4740 GNUNET_STATISTICS_update (stats, 4573 GNUNET_STATISTICS_update (stats,
4741 gettext_noop ("# HELLOs received for validation"), 4574 gettext_noop ("# HELLOs received for validation"),
4742 1, 4575 1, GNUNET_NO);
4743 GNUNET_NO);
4744 4576
4745 hello = (const struct GNUNET_HELLO_Message *) message; 4577 hello = (const struct GNUNET_HELLO_Message *) message;
4746 if (GNUNET_OK != GNUNET_HELLO_get_key (hello, &publicKey)) 4578 if (GNUNET_OK != GNUNET_HELLO_get_key (hello, &publicKey))
4747 { 4579 {
4748#if DEBUG_TRANSPORT_HELLO 4580#if DEBUG_TRANSPORT_HELLO
4749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4581 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4750 "Unable to get public key from `%s' for `%4s'!\n", 4582 "Unable to get public key from `%s' for `%4s'!\n",
4751 "HELLO", 4583 "HELLO", GNUNET_i2s (&target));
4752 GNUNET_i2s (&target));
4753#endif 4584#endif
4754 GNUNET_break_op (0); 4585 GNUNET_break_op (0);
4755 return GNUNET_SYSERR; 4586 return GNUNET_SYSERR;
4756 } 4587 }
4757 GNUNET_CRYPTO_hash (&publicKey, 4588 GNUNET_CRYPTO_hash (&publicKey,
4758 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded), 4589 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
4759 &target.hashPubKey); 4590 &target.hashPubKey);
@@ -4761,111 +4592,103 @@ process_hello (struct TransportPlugin *plugin,
4761#if DEBUG_TRANSPORT_HELLO 4592#if DEBUG_TRANSPORT_HELLO
4762 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4763 "Received `%s' message for `%4s'\n", 4594 "Received `%s' message for `%4s'\n",
4764 "HELLO", 4595 "HELLO", GNUNET_i2s (&target));
4765 GNUNET_i2s (&target));
4766#endif 4596#endif
4767 if (0 == memcmp (&my_identity, 4597 if (0 == memcmp (&my_identity, &target, sizeof (struct GNUNET_PeerIdentity)))
4768 &target, 4598 {
4769 sizeof (struct GNUNET_PeerIdentity))) 4599 GNUNET_STATISTICS_update (stats,
4770 { 4600 gettext_noop
4771 GNUNET_STATISTICS_update (stats, 4601 ("# HELLOs ignored for validation (is my own HELLO)"),
4772 gettext_noop ("# HELLOs ignored for validation (is my own HELLO)"), 4602 1, GNUNET_NO);
4773 1, 4603 return GNUNET_OK;
4774 GNUNET_NO); 4604 }
4775 return GNUNET_OK;
4776 }
4777 n = find_neighbour (&target); 4605 n = find_neighbour (&target);
4778 if ( (NULL != n) && 4606 if ((NULL != n) && (!n->public_key_valid))
4779 (! n->public_key_valid) ) 4607 {
4780 { 4608 GNUNET_HELLO_get_key (hello, &n->publicKey);
4781 GNUNET_HELLO_get_key (hello, &n->publicKey); 4609 n->public_key_valid = GNUNET_YES;
4782 n->public_key_valid = GNUNET_YES; 4610 }
4783 }
4784 4611
4785 /* check if load is too high before doing expensive stuff */ 4612 /* check if load is too high before doing expensive stuff */
4786 if (GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_BACKGROUND) > MAX_HELLO_LOAD) 4613 if (GNUNET_SCHEDULER_get_load (GNUNET_SCHEDULER_PRIORITY_BACKGROUND) >
4787 { 4614 MAX_HELLO_LOAD)
4788 GNUNET_STATISTICS_update (stats, 4615 {
4789 gettext_noop ("# HELLOs ignored due to high load"), 4616 GNUNET_STATISTICS_update (stats,
4790 1, 4617 gettext_noop
4791 GNUNET_NO); 4618 ("# HELLOs ignored due to high load"), 1,
4619 GNUNET_NO);
4792#if DEBUG_TRANSPORT_HELLO 4620#if DEBUG_TRANSPORT_HELLO
4793 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4794 "Ignoring `%s' for `%4s', load too high.\n", 4622 "Ignoring `%s' for `%4s', load too high.\n",
4795 "HELLO", 4623 "HELLO", GNUNET_i2s (&target));
4796 GNUNET_i2s (&target));
4797#endif 4624#endif
4798 return GNUNET_OK; 4625 return GNUNET_OK;
4799 } 4626 }
4800 4627
4801 4628
4802 chvc = chvc_head; 4629 chvc = chvc_head;
4803 while (NULL != chvc) 4630 while (NULL != chvc)
4631 {
4632 if (GNUNET_HELLO_equals (hello,
4633 chvc->hello,
4634 GNUNET_TIME_absolute_get ()).abs_value > 0)
4804 { 4635 {
4805 if (GNUNET_HELLO_equals (hello,
4806 chvc->hello,
4807 GNUNET_TIME_absolute_get ()).abs_value > 0)
4808 {
4809#if DEBUG_TRANSPORT_HELLO > 2 4636#if DEBUG_TRANSPORT_HELLO > 2
4810 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4811 "Received duplicate `%s' message for `%4s'; ignored\n", 4638 "Received duplicate `%s' message for `%4s'; ignored\n",
4812 "HELLO", 4639 "HELLO", GNUNET_i2s (&target));
4813 GNUNET_i2s (&target));
4814#endif 4640#endif
4815 return GNUNET_OK; /* validation already pending */ 4641 return GNUNET_OK; /* validation already pending */
4816 }
4817 if (GNUNET_HELLO_size (hello) == GNUNET_HELLO_size (chvc->hello))
4818 GNUNET_break (0 != memcmp (hello, chvc->hello,
4819 GNUNET_HELLO_size(hello)));
4820 chvc = chvc->next;
4821 } 4642 }
4643 if (GNUNET_HELLO_size (hello) == GNUNET_HELLO_size (chvc->hello))
4644 GNUNET_break (0 != memcmp (hello, chvc->hello,
4645 GNUNET_HELLO_size (hello)));
4646 chvc = chvc->next;
4647 }
4822 4648
4823#if BREAK_TESTS 4649#if BREAK_TESTS
4824 struct NeighbourMapEntry *temp_neighbor = find_neighbour(&target); 4650 struct NeighbourMapEntry *temp_neighbor = find_neighbour (&target);
4651
4825 if ((NULL != temp_neighbor)) 4652 if ((NULL != temp_neighbor))
4826 { 4653 {
4827 fprintf(stderr, "Already know peer, ignoring hello\n"); 4654 fprintf (stderr, "Already know peer, ignoring hello\n");
4828 return GNUNET_OK; 4655 return GNUNET_OK;
4829 } 4656 }
4830#endif 4657#endif
4831 4658
4832#if DEBUG_TRANSPORT_HELLO > 2 4659#if DEBUG_TRANSPORT_HELLO > 2
4833 if (plugin != NULL) 4660 if (plugin != NULL)
4834 { 4661 {
4835#if DEBUG_TRANSPORT 4662#if DEBUG_TRANSPORT
4836 my_id = GNUNET_strdup(GNUNET_i2s(plugin->env.my_identity)); 4663 my_id = GNUNET_strdup (GNUNET_i2s (plugin->env.my_identity));
4837 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4838 "%s: Starting validation of `%s' message for `%4s' via '%s' of size %u\n", 4665 "%s: Starting validation of `%s' message for `%4s' via '%s' of size %u\n",
4839 my_id, 4666 my_id,
4840 "HELLO", 4667 "HELLO",
4841 GNUNET_i2s (&target), 4668 GNUNET_i2s (&target),
4842 plugin->short_name, 4669 plugin->short_name, GNUNET_HELLO_size (hello));
4843 GNUNET_HELLO_size(hello)); 4670 GNUNET_free (my_id);
4844 GNUNET_free (my_id);
4845#endif 4671#endif
4846 } 4672 }
4847#endif 4673#endif
4848 chvc = GNUNET_malloc (sizeof (struct CheckHelloValidatedContext) + hsize); 4674 chvc = GNUNET_malloc (sizeof (struct CheckHelloValidatedContext) + hsize);
4849 chvc->ve_count = 1; 4675 chvc->ve_count = 1;
4850 chvc->hello = (const struct GNUNET_HELLO_Message *) &chvc[1]; 4676 chvc->hello = (const struct GNUNET_HELLO_Message *) &chvc[1];
4851 memcpy (&chvc[1], hello, hsize); 4677 memcpy (&chvc[1], hello, hsize);
4852 GNUNET_CONTAINER_DLL_insert (chvc_head, 4678 GNUNET_CONTAINER_DLL_insert (chvc_head, chvc_tail, chvc);
4853 chvc_tail,
4854 chvc);
4855 /* finally, check if HELLO was previously validated 4679 /* finally, check if HELLO was previously validated
4856 (continuation will then schedule actual validation) */ 4680 * (continuation will then schedule actual validation) */
4857 GNUNET_STATISTICS_update (stats, 4681 GNUNET_STATISTICS_update (stats,
4858 gettext_noop ("# peerinfo process hello iterate requests"), 4682 gettext_noop
4859 1, 4683 ("# peerinfo process hello iterate requests"), 1,
4860 GNUNET_NO); 4684 GNUNET_NO);
4861 GNUNET_STATISTICS_update (stats, 4685 GNUNET_STATISTICS_update (stats,
4862 gettext_noop ("# outstanding peerinfo iterate requests"), 4686 gettext_noop
4863 1, 4687 ("# outstanding peerinfo iterate requests"), 1,
4864 GNUNET_NO); 4688 GNUNET_NO);
4865 chvc->piter = GNUNET_PEERINFO_iterate (peerinfo, 4689 chvc->piter =
4866 &target, 4690 GNUNET_PEERINFO_iterate (peerinfo, &target, HELLO_VERIFICATION_TIMEOUT,
4867 HELLO_VERIFICATION_TIMEOUT, 4691 &check_hello_validated, chvc);
4868 &check_hello_validated, chvc);
4869 return GNUNET_OK; 4692 return GNUNET_OK;
4870} 4693}
4871 4694
@@ -4894,144 +4717,134 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
4894 if (GNUNET_YES == n->in_disconnect) 4717 if (GNUNET_YES == n->in_disconnect)
4895 return; 4718 return;
4896 if (GNUNET_YES == check) 4719 if (GNUNET_YES == check)
4720 {
4721 rpos = n->plugins;
4722 while (NULL != rpos)
4897 { 4723 {
4898 rpos = n->plugins; 4724 peer_addresses = rpos->addresses;
4899 while (NULL != rpos) 4725 while (peer_addresses != NULL)
4726 {
4727 /* Do not disconnect if: an address is connected or an inbound address exists */
4728 if ((GNUNET_YES == peer_addresses->connected) ||
4729 (peer_addresses->addrlen == 0))
4900 { 4730 {
4901 peer_addresses = rpos->addresses;
4902 while (peer_addresses != NULL)
4903 {
4904 /* Do not disconnect if: an address is connected or an inbound address exists */
4905 if ((GNUNET_YES == peer_addresses->connected) || (peer_addresses->addrlen == 0))
4906 {
4907#if DEBUG_TRANSPORT 4731#if DEBUG_TRANSPORT
4908 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4909 "NOT Disconnecting from `%4s', still have live address `%s'!\n", 4733 "NOT Disconnecting from `%4s', still have live address `%s'!\n",
4910 GNUNET_i2s (&n->id), 4734 GNUNET_i2s (&n->id),
4911 a2s (peer_addresses->ready_list->plugin->short_name, 4735 a2s (peer_addresses->ready_list->plugin->short_name,
4912 peer_addresses->addr, 4736 peer_addresses->addr, peer_addresses->addrlen));
4913 peer_addresses->addrlen));
4914#endif 4737#endif
4915 return; /* still connected */ 4738 return; /* still connected */
4916 }
4917 peer_addresses = peer_addresses->next;
4918 }
4919 rpos = rpos->next;
4920 } 4739 }
4740 peer_addresses = peer_addresses->next;
4741 }
4742 rpos = rpos->next;
4921 } 4743 }
4744 }
4922#if DEBUG_TRANSPORT 4745#if DEBUG_TRANSPORT
4923 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 4746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
4924 "Disconnecting from `%4s'\n", 4747 "Disconnecting from `%4s'\n", GNUNET_i2s (&n->id));
4925 GNUNET_i2s (&n->id));
4926#endif 4748#endif
4927 n->in_disconnect = GNUNET_YES; /* prevent recursive entry */ 4749 n->in_disconnect = GNUNET_YES; /* prevent recursive entry */
4928 4750
4929 /* notify all clients about disconnect */ 4751 /* notify all clients about disconnect */
4930 if (GNUNET_YES == n->received_pong) 4752 if (GNUNET_YES == n->received_pong)
4931 { 4753 {
4932 n->received_pong = GNUNET_NO; 4754 n->received_pong = GNUNET_NO;
4933 notify_clients_disconnect (&n->id); 4755 notify_clients_disconnect (&n->id);
4934 } 4756 }
4935#if HAVE_LIBGLPK 4757#if HAVE_LIBGLPK
4936 ats_modify_problem_state(ats, ATS_MODIFIED); 4758 ats_modify_problem_state (ats, ATS_MODIFIED);
4937#endif 4759#endif
4938 /* clean up all plugins, cancel connections and pending transmissions */ 4760 /* clean up all plugins, cancel connections and pending transmissions */
4939 while (NULL != (rpos = n->plugins)) 4761 while (NULL != (rpos = n->plugins))
4762 {
4763 n->plugins = rpos->next;
4764 rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id);
4765 while (rpos->addresses != NULL)
4940 { 4766 {
4941 n->plugins = rpos->next; 4767 peer_pos = rpos->addresses;
4942 rpos->plugin->api->disconnect (rpos->plugin->api->cls, &n->id); 4768 rpos->addresses = peer_pos->next;
4943 while (rpos->addresses != NULL) 4769 if (peer_pos->connected == GNUNET_YES)
4944 { 4770 {
4945 peer_pos = rpos->addresses; 4771 GNUNET_STATISTICS_update (stats,
4946 rpos->addresses = peer_pos->next; 4772 gettext_noop ("# connected addresses"),
4947 if (peer_pos->connected == GNUNET_YES) 4773 -1, GNUNET_NO);
4948 { 4774 peer_pos->connected = GNUNET_NO;
4949 GNUNET_STATISTICS_update (stats, 4775 }
4950 gettext_noop ("# connected addresses"), 4776 if (GNUNET_YES == peer_pos->validated)
4951 -1, 4777 GNUNET_STATISTICS_update (stats,
4952 GNUNET_NO); 4778 gettext_noop
4953 peer_pos->connected = GNUNET_NO; 4779 ("# peer addresses considered valid"), -1,
4954 } 4780 GNUNET_NO);
4955 if (GNUNET_YES == peer_pos->validated) 4781 if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task)
4956 GNUNET_STATISTICS_update (stats, 4782 {
4957 gettext_noop ("# peer addresses considered valid"), 4783 GNUNET_SCHEDULER_cancel (peer_pos->revalidate_task);
4958 -1, 4784 peer_pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
4959 GNUNET_NO); 4785 }
4960 if (GNUNET_SCHEDULER_NO_TASK != peer_pos->revalidate_task) 4786 GNUNET_free (peer_pos->ressources);
4961 { 4787 peer_pos->ressources = NULL;
4962 GNUNET_SCHEDULER_cancel (peer_pos->revalidate_task); 4788 GNUNET_free (peer_pos->quality);
4963 peer_pos->revalidate_task = GNUNET_SCHEDULER_NO_TASK; 4789 peer_pos->ressources = NULL;
4964 } 4790 GNUNET_free (peer_pos);
4965 GNUNET_free (peer_pos->ressources);
4966 peer_pos->ressources = NULL;
4967 GNUNET_free (peer_pos->quality);
4968 peer_pos->ressources = NULL;
4969 GNUNET_free (peer_pos);
4970 }
4971 GNUNET_free (rpos);
4972 } 4791 }
4792 GNUNET_free (rpos);
4793 }
4973 4794
4974 /* free all messages on the queue */ 4795 /* free all messages on the queue */
4975 while (NULL != (mq = n->messages_head)) 4796 while (NULL != (mq = n->messages_head))
4976 { 4797 {
4977 GNUNET_STATISTICS_update (stats, 4798 GNUNET_STATISTICS_update (stats,
4978 gettext_noop ("# bytes in message queue for other peers"), 4799 gettext_noop
4979 - (int64_t) mq->message_buf_size, 4800 ("# bytes in message queue for other peers"),
4980 GNUNET_NO); 4801 -(int64_t) mq->message_buf_size, GNUNET_NO);
4981 GNUNET_STATISTICS_update (stats, 4802 GNUNET_STATISTICS_update (stats,
4982 gettext_noop ("# bytes discarded due to disconnect"), 4803 gettext_noop
4983 mq->message_buf_size, 4804 ("# bytes discarded due to disconnect"),
4984 GNUNET_NO); 4805 mq->message_buf_size, GNUNET_NO);
4985 GNUNET_CONTAINER_DLL_remove (n->messages_head, 4806 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
4986 n->messages_tail, 4807 GNUNET_assert (0 == memcmp (&mq->neighbour_id,
4987 mq); 4808 &n->id, sizeof (struct GNUNET_PeerIdentity)));
4988 GNUNET_assert (0 == memcmp(&mq->neighbour_id, 4809 GNUNET_free (mq);
4989 &n->id, 4810 }
4990 sizeof(struct GNUNET_PeerIdentity)));
4991 GNUNET_free (mq);
4992 }
4993 4811
4994 while (NULL != (mq = n->cont_head)) 4812 while (NULL != (mq = n->cont_head))
4995 { 4813 {
4996 4814
4997 GNUNET_CONTAINER_DLL_remove (n->cont_head, 4815 GNUNET_CONTAINER_DLL_remove (n->cont_head, n->cont_tail, mq);
4998 n->cont_tail, 4816 GNUNET_assert (0 == memcmp (&mq->neighbour_id,
4999 mq); 4817 &n->id, sizeof (struct GNUNET_PeerIdentity)));
5000 GNUNET_assert (0 == memcmp(&mq->neighbour_id, 4818 GNUNET_free (mq);
5001 &n->id, 4819 }
5002 sizeof(struct GNUNET_PeerIdentity)));
5003 GNUNET_free (mq);
5004 }
5005 4820
5006 if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK) 4821 if (n->timeout_task != GNUNET_SCHEDULER_NO_TASK)
5007 { 4822 {
5008 GNUNET_SCHEDULER_cancel (n->timeout_task); 4823 GNUNET_SCHEDULER_cancel (n->timeout_task);
5009 n->timeout_task = GNUNET_SCHEDULER_NO_TASK; 4824 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
5010 } 4825 }
5011 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK) 4826 if (n->retry_task != GNUNET_SCHEDULER_NO_TASK)
5012 { 4827 {
5013 GNUNET_SCHEDULER_cancel (n->retry_task); 4828 GNUNET_SCHEDULER_cancel (n->retry_task);
5014 n->retry_task = GNUNET_SCHEDULER_NO_TASK; 4829 n->retry_task = GNUNET_SCHEDULER_NO_TASK;
5015 } 4830 }
5016 if (n->piter != NULL) 4831 if (n->piter != NULL)
5017 { 4832 {
5018 GNUNET_PEERINFO_iterate_cancel (n->piter); 4833 GNUNET_PEERINFO_iterate_cancel (n->piter);
5019 GNUNET_STATISTICS_update (stats, 4834 GNUNET_STATISTICS_update (stats,
5020 gettext_noop ("# outstanding peerinfo iterate requests"), 4835 gettext_noop
5021 -1, 4836 ("# outstanding peerinfo iterate requests"), -1,
5022 GNUNET_NO); 4837 GNUNET_NO);
5023 n->piter = NULL; 4838 n->piter = NULL;
5024 } 4839 }
5025 4840
5026 GNUNET_assert (GNUNET_OK == 4841 GNUNET_assert (GNUNET_OK ==
5027 GNUNET_CONTAINER_multihashmap_remove (neighbours, 4842 GNUNET_CONTAINER_multihashmap_remove (neighbours,
5028 &n->id.hashPubKey, 4843 &n->id.hashPubKey, n));
5029 n));
5030 /* finally, free n itself */ 4844 /* finally, free n itself */
5031 GNUNET_STATISTICS_update (stats, 4845 GNUNET_STATISTICS_update (stats,
5032 gettext_noop ("# active neighbours"), 4846 gettext_noop ("# active neighbours"),
5033 -1, 4847 -1, GNUNET_NO);
5034 GNUNET_NO);
5035 GNUNET_free_non_null (n->pre_connect_message_buffer); 4848 GNUNET_free_non_null (n->pre_connect_message_buffer);
5036 GNUNET_free (n); 4849 GNUNET_free (n);
5037} 4850}
@@ -5043,13 +4856,12 @@ disconnect_neighbour (struct NeighbourMapEntry *n, int check)
5043 */ 4856 */
5044static int 4857static int
5045handle_ping (void *cls, const struct GNUNET_MessageHeader *message, 4858handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5046 const struct GNUNET_PeerIdentity *peer, 4859 const struct GNUNET_PeerIdentity *peer,
5047 struct Session *session, 4860 struct Session *session,
5048 const char *sender_address, 4861 const char *sender_address, uint16_t sender_address_len)
5049 uint16_t sender_address_len)
5050{ 4862{
5051 struct TransportPlugin *plugin = cls; 4863 struct TransportPlugin *plugin = cls;
5052 struct SessionHeader *session_header = (struct SessionHeader*) session; 4864 struct SessionHeader *session_header = (struct SessionHeader *) session;
5053 struct TransportPingMessage *ping; 4865 struct TransportPingMessage *ping;
5054 struct TransportPongMessage *pong; 4866 struct TransportPongMessage *pong;
5055 struct NeighbourMapEntry *n; 4867 struct NeighbourMapEntry *n;
@@ -5062,266 +4874,252 @@ handle_ping (void *cls, const struct GNUNET_MessageHeader *message,
5062 int did_pong; 4874 int did_pong;
5063 4875
5064 if (ntohs (message->size) < sizeof (struct TransportPingMessage)) 4876 if (ntohs (message->size) < sizeof (struct TransportPingMessage))
5065 { 4877 {
5066 GNUNET_break_op (0); 4878 GNUNET_break_op (0);
5067 return GNUNET_SYSERR; 4879 return GNUNET_SYSERR;
5068 } 4880 }
5069 4881
5070 ping = (struct TransportPingMessage *) message; 4882 ping = (struct TransportPingMessage *) message;
5071 if (0 != memcmp (&ping->target, 4883 if (0 != memcmp (&ping->target,
5072 plugin->env.my_identity, 4884 plugin->env.my_identity,
5073 sizeof (struct GNUNET_PeerIdentity))) 4885 sizeof (struct GNUNET_PeerIdentity)))
5074 { 4886 {
5075#if DEBUG_TRANSPORT 4887#if DEBUG_TRANSPORT
5076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5077 _("Received `%s' message from `%s' destined for `%s' which is not me!\n"), 4889 _
5078 "PING", 4890 ("Received `%s' message from `%s' destined for `%s' which is not me!\n"),
5079 (sender_address != NULL) 4891 "PING", (sender_address != NULL) ? a2s (plugin->short_name,
5080 ? a2s (plugin->short_name, 4892 (const struct sockaddr
5081 (const struct sockaddr *)sender_address, 4893 *) sender_address,
5082 sender_address_len) 4894 sender_address_len) :
5083 : "<inbound>", 4895 "<inbound>", GNUNET_i2s (&ping->target));
5084 GNUNET_i2s (&ping->target));
5085#endif 4896#endif
5086 return GNUNET_SYSERR; 4897 return GNUNET_SYSERR;
5087 } 4898 }
5088#if DEBUG_PING_PONG 4899#if DEBUG_PING_PONG
5089 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 4900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
5090 "Processing `%s' from `%s'\n", 4901 "Processing `%s' from `%s'\n",
5091 "PING", 4902 "PING",
5092 (sender_address != NULL) 4903 (sender_address != NULL)
5093 ? a2s (plugin->short_name, 4904 ? a2s (plugin->short_name,
5094 (const struct sockaddr *)sender_address, 4905 (const struct sockaddr *) sender_address,
5095 sender_address_len) 4906 sender_address_len) : "<inbound>");
5096 : "<inbound>");
5097#endif 4907#endif
5098 GNUNET_STATISTICS_update (stats, 4908 GNUNET_STATISTICS_update (stats,
5099 gettext_noop ("# PING messages received"), 4909 gettext_noop ("# PING messages received"),
5100 1, 4910 1, GNUNET_NO);
5101 GNUNET_NO); 4911 addr = (const char *) &ping[1];
5102 addr = (const char*) &ping[1];
5103 alen = ntohs (message->size) - sizeof (struct TransportPingMessage); 4912 alen = ntohs (message->size) - sizeof (struct TransportPingMessage);
5104 slen = strlen (plugin->short_name) + 1; 4913 slen = strlen (plugin->short_name) + 1;
5105 if (alen == 0) 4914 if (alen == 0)
4915 {
4916 /* peer wants to confirm that we have an outbound connection to him */
4917 if (session == NULL)
5106 { 4918 {
5107 /* peer wants to confirm that we have an outbound connection to him */ 4919 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
5108 if (session == NULL) 4920 _
5109 { 4921 ("Refusing to create PONG since I do not have a session with `%s'.\n"),
5110 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 4922 GNUNET_i2s (peer));
5111 _("Refusing to create PONG since I do not have a session with `%s'.\n"), 4923 return GNUNET_SYSERR;
5112 GNUNET_i2s (peer)); 4924 }
5113 return GNUNET_SYSERR; 4925 /* FIXME-urg: the use of 'sender_address' in the code below is doubly-wrong:
5114 } 4926 * 1) it is NULL when we need to have a real value
5115 /* FIXME-urg: the use of 'sender_address' in the code below is doubly-wrong: 4927 * 2) it is documented to be the address of the sender (source-IP), where
5116 1) it is NULL when we need to have a real value 4928 * what we actually want is our LISTEN IP (what we 'bound' to); which we don't even
5117 2) it is documented to be the address of the sender (source-IP), where 4929 * have...
5118 what we actually want is our LISTEN IP (what we 'bound' to); which we don't even 4930 */
5119 have... 4931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5120 */ 4932 "Creating PONG indicating that we received a connection at our address `%s' from `%s'.\n",
5121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4933 a2s (plugin->short_name,
5122 "Creating PONG indicating that we received a connection at our address `%s' from `%s'.\n", 4934 sender_address, sender_address_len), GNUNET_i2s (peer));
5123 a2s (plugin->short_name, 4935
5124 sender_address, 4936 pong =
5125 sender_address_len), 4937 GNUNET_malloc (sizeof (struct TransportPongMessage) +
5126 GNUNET_i2s (peer)); 4938 sender_address_len + slen);
5127 4939 pong->header.size =
5128 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + sender_address_len + slen); 4940 htons (sizeof (struct TransportPongMessage) + sender_address_len +
5129 pong->header.size = htons (sizeof (struct TransportPongMessage) + sender_address_len + slen); 4941 slen);
5130 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 4942 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
5131 pong->purpose.size = 4943 pong->purpose.size =
5132 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 4944 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
5133 sizeof (uint32_t) + 4945 sizeof (uint32_t) +
5134 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 4946 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
5135 sizeof (struct GNUNET_PeerIdentity) + sender_address_len + slen); 4947 sizeof (struct GNUNET_PeerIdentity) + sender_address_len + slen);
5136 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING); 4948 pong->purpose.purpose =
5137 pong->challenge = ping->challenge; 4949 htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_USING);
5138 pong->addrlen = htonl(sender_address_len + slen); 4950 pong->challenge = ping->challenge;
5139 memcpy(&pong->pid, 4951 pong->addrlen = htonl (sender_address_len + slen);
5140 peer, 4952 memcpy (&pong->pid, peer, sizeof (struct GNUNET_PeerIdentity));
5141 sizeof(struct GNUNET_PeerIdentity)); 4953 memcpy (&pong[1], plugin->short_name, slen);
5142 memcpy (&pong[1], 4954 if ((sender_address != NULL) && (sender_address_len > 0))
5143 plugin->short_name, 4955 memcpy (&((char *) &pong[1])[slen], sender_address, sender_address_len);
5144 slen); 4956 if (GNUNET_TIME_absolute_get_remaining
5145 if ((sender_address!=NULL) && (sender_address_len > 0)) 4957 (session_header->pong_sig_expires).rel_value <
5146 memcpy (&((char*)&pong[1])[slen], 4958 PONG_SIGNATURE_LIFETIME.rel_value / 4)
5147 sender_address, 4959 {
5148 sender_address_len); 4960 /* create / update cached sig */
5149 if (GNUNET_TIME_absolute_get_remaining (session_header->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4)
5150 {
5151 /* create / update cached sig */
5152#if DEBUG_TRANSPORT 4961#if DEBUG_TRANSPORT
5153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5154 "Creating PONG signature to indicate active connection.\n"); 4963 "Creating PONG signature to indicate active connection.\n");
5155#endif 4964#endif
5156 session_header->pong_sig_expires = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); 4965 session_header->pong_sig_expires =
5157 pong->expiration = GNUNET_TIME_absolute_hton (session_header->pong_sig_expires); 4966 GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
5158 GNUNET_assert (GNUNET_OK == 4967 pong->expiration =
5159 GNUNET_CRYPTO_rsa_sign (my_private_key, 4968 GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
5160 &pong->purpose, 4969 GNUNET_assert (GNUNET_OK ==
5161 &session_header->pong_signature)); 4970 GNUNET_CRYPTO_rsa_sign (my_private_key, &pong->purpose,
5162 } 4971 &session_header->pong_signature));
5163 else 4972 }
5164 { 4973 else
5165 pong->expiration = GNUNET_TIME_absolute_hton (session_header->pong_sig_expires); 4974 {
5166 } 4975 pong->expiration =
5167 memcpy (&pong->signature, 4976 GNUNET_TIME_absolute_hton (session_header->pong_sig_expires);
5168 &session_header->pong_signature, 4977 }
5169 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 4978 memcpy (&pong->signature,
4979 &session_header->pong_signature,
4980 sizeof (struct GNUNET_CRYPTO_RsaSignature));
5170 4981
5171 4982
5172 } 4983 }
5173 else 4984 else
4985 {
4986 /* peer wants to confirm that this is one of our addresses */
4987 addr += slen;
4988 alen -= slen;
4989 if (GNUNET_OK != plugin->api->check_address (plugin->api->cls, addr, alen))
4990 {
4991 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
4992 _
4993 ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
4994 a2s (plugin->short_name, addr, alen));
4995 return GNUNET_NO;
4996 }
4997 oal = plugin->addresses;
4998 while (NULL != oal)
5174 { 4999 {
5175 /* peer wants to confirm that this is one of our addresses */ 5000 if ((oal->addrlen == alen) && (0 == memcmp (addr, &oal[1], alen)))
5176 addr += slen; 5001 break;
5177 alen -= slen; 5002 oal = oal->next;
5178 if (GNUNET_OK != 5003 }
5179 plugin->api->check_address (plugin->api->cls, 5004 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
5180 addr, 5005 pong->header.size =
5181 alen)) 5006 htons (sizeof (struct TransportPongMessage) + alen + slen);
5182 { 5007 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
5183 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 5008 pong->purpose.size =
5184 _("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), 5009 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
5185 a2s (plugin->short_name, 5010 sizeof (uint32_t) +
5186 addr, 5011 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
5187 alen)); 5012 sizeof (struct GNUNET_PeerIdentity) + alen + slen);
5188 return GNUNET_NO; 5013 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
5189 } 5014 pong->challenge = ping->challenge;
5190 oal = plugin->addresses; 5015 pong->addrlen = htonl (alen + slen);
5191 while (NULL != oal) 5016 memcpy (&pong->pid, &my_identity, sizeof (struct GNUNET_PeerIdentity));
5192 { 5017 memcpy (&pong[1], plugin->short_name, slen);
5193 if ( (oal->addrlen == alen) && 5018 memcpy (&((char *) &pong[1])[slen], addr, alen);
5194 (0 == memcmp (addr, 5019 if ((oal != NULL) &&
5195 &oal[1], 5020 (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).rel_value <
5196 alen)) ) 5021 PONG_SIGNATURE_LIFETIME.rel_value / 4))
5197 break; 5022 {
5198 oal = oal->next; 5023 /* create / update cached sig */
5199 }
5200 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
5201 pong->header.size = htons (sizeof (struct TransportPongMessage) + alen + slen);
5202 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
5203 pong->purpose.size =
5204 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
5205 sizeof (uint32_t) +
5206 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
5207 sizeof (struct GNUNET_PeerIdentity) + alen + slen);
5208 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
5209 pong->challenge = ping->challenge;
5210 pong->addrlen = htonl(alen + slen);
5211 memcpy(&pong->pid,
5212 &my_identity,
5213 sizeof(struct GNUNET_PeerIdentity));
5214 memcpy (&pong[1], plugin->short_name, slen);
5215 memcpy (&((char*)&pong[1])[slen], addr, alen);
5216 if ( (oal != NULL) &&
5217 (GNUNET_TIME_absolute_get_remaining (oal->pong_sig_expires).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) )
5218 {
5219 /* create / update cached sig */
5220#if DEBUG_TRANSPORT 5024#if DEBUG_TRANSPORT
5221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5222 "Creating PONG signature to indicate ownership.\n"); 5026 "Creating PONG signature to indicate ownership.\n");
5223#endif 5027#endif
5224 oal->pong_sig_expires = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); 5028 oal->pong_sig_expires =
5225 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires); 5029 GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
5226 GNUNET_assert (GNUNET_OK == 5030 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
5227 GNUNET_CRYPTO_rsa_sign (my_private_key, 5031 GNUNET_assert (GNUNET_OK ==
5228 &pong->purpose, 5032 GNUNET_CRYPTO_rsa_sign (my_private_key,
5229 &oal->pong_signature)); 5033 &pong->purpose,
5230 memcpy (&pong->signature, 5034 &oal->pong_signature));
5231 &oal->pong_signature, 5035 memcpy (&pong->signature,
5232 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 5036 &oal->pong_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature));
5233 } 5037 }
5234 else if (oal == NULL) 5038 else if (oal == NULL)
5235 { 5039 {
5236 /* not using cache (typically DV-only) */ 5040 /* not using cache (typically DV-only) */
5237 pong->expiration = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME)); 5041 pong->expiration =
5238 GNUNET_assert (GNUNET_OK == 5042 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute
5239 GNUNET_CRYPTO_rsa_sign (my_private_key, 5043 (PONG_SIGNATURE_LIFETIME));
5240 &pong->purpose, 5044 GNUNET_assert (GNUNET_OK ==
5241 &pong->signature)); 5045 GNUNET_CRYPTO_rsa_sign (my_private_key, &pong->purpose,
5242 } 5046 &pong->signature));
5243 else 5047 }
5244 { 5048 else
5245 /* can used cached version */ 5049 {
5246 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires); 5050 /* can used cached version */
5247 memcpy (&pong->signature, 5051 pong->expiration = GNUNET_TIME_absolute_hton (oal->pong_sig_expires);
5248 &oal->pong_signature, 5052 memcpy (&pong->signature,
5249 sizeof (struct GNUNET_CRYPTO_RsaSignature)); 5053 &oal->pong_signature, sizeof (struct GNUNET_CRYPTO_RsaSignature));
5250 }
5251 } 5054 }
5252 n = find_neighbour(peer); 5055 }
5056 n = find_neighbour (peer);
5253 GNUNET_assert (n != NULL); 5057 GNUNET_assert (n != NULL);
5254 did_pong = GNUNET_NO; 5058 did_pong = GNUNET_NO;
5255 /* first try reliable response transmission */ 5059 /* first try reliable response transmission */
5256 rl = n->plugins; 5060 rl = n->plugins;
5257 while (rl != NULL) 5061 while (rl != NULL)
5258 { 5062 {
5259 fal = rl->addresses; 5063 fal = rl->addresses;
5260 while (fal != NULL) 5064 while (fal != NULL)
5261 { 5065 {
5262 if (-1 != rl->plugin->api->send (rl->plugin->api->cls, 5066 if (-1 != rl->plugin->api->send (rl->plugin->api->cls,
5263 peer, 5067 peer,
5264 (const char*) pong, 5068 (const char *) pong,
5265 ntohs (pong->header.size), 5069 ntohs (pong->header.size),
5266 TRANSPORT_PONG_PRIORITY, 5070 TRANSPORT_PONG_PRIORITY,
5267 HELLO_VERIFICATION_TIMEOUT, 5071 HELLO_VERIFICATION_TIMEOUT,
5268 fal->session, 5072 fal->session,
5269 fal->addr, 5073 fal->addr,
5270 fal->addrlen, 5074 fal->addrlen, GNUNET_SYSERR, NULL, NULL))
5271 GNUNET_SYSERR, 5075 {
5272 NULL, NULL)) 5076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5273 { 5077 "Transmitted PONG to `%s' via reliable mechanism\n",
5274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5078 GNUNET_i2s (peer));
5275 "Transmitted PONG to `%s' via reliable mechanism\n", 5079 /* done! */
5276 GNUNET_i2s (peer)); 5080 GNUNET_STATISTICS_update (stats,
5277 /* done! */ 5081 gettext_noop
5278 GNUNET_STATISTICS_update (stats, 5082 ("# PONGs unicast via reliable transport"), 1,
5279 gettext_noop ("# PONGs unicast via reliable transport"), 5083 GNUNET_NO);
5280 1, 5084 GNUNET_free (pong);
5281 GNUNET_NO); 5085 return GNUNET_OK;
5282 GNUNET_free (pong); 5086 }
5283 return GNUNET_OK; 5087 did_pong = GNUNET_YES;
5284 } 5088 fal = fal->next;
5285 did_pong = GNUNET_YES;
5286 fal = fal->next;
5287 }
5288 rl = rl->next;
5289 } 5089 }
5090 rl = rl->next;
5091 }
5290 /* no reliable method found, do multicast */ 5092 /* no reliable method found, do multicast */
5291 GNUNET_STATISTICS_update (stats, 5093 GNUNET_STATISTICS_update (stats,
5292 gettext_noop ("# PONGs multicast to all available addresses"), 5094 gettext_noop
5293 1, 5095 ("# PONGs multicast to all available addresses"), 1,
5294 GNUNET_NO); 5096 GNUNET_NO);
5295 rl = n->plugins; 5097 rl = n->plugins;
5296 while (rl != NULL) 5098 while (rl != NULL)
5099 {
5100 fal = rl->addresses;
5101 while (fal != NULL)
5297 { 5102 {
5298 fal = rl->addresses; 5103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5299 while (fal != NULL) 5104 "Transmitting PONG to `%s' via unreliable mechanism `%s':%s\n",
5300 { 5105 GNUNET_i2s (peer),
5301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5106 a2s (rl->plugin->short_name,
5302 "Transmitting PONG to `%s' via unreliable mechanism `%s':%s\n", 5107 fal->addr, fal->addrlen), rl->plugin->short_name);
5303 GNUNET_i2s (peer), 5108 transmit_to_peer (NULL, fal,
5304 a2s (rl->plugin->short_name, 5109 TRANSPORT_PONG_PRIORITY,
5305 fal->addr, 5110 HELLO_VERIFICATION_TIMEOUT,
5306 fal->addrlen), 5111 (const char *) pong,
5307 rl->plugin->short_name); 5112 ntohs (pong->header.size), GNUNET_YES, n);
5308 transmit_to_peer(NULL, fal, 5113 did_pong = GNUNET_YES;
5309 TRANSPORT_PONG_PRIORITY, 5114 fal = fal->next;
5310 HELLO_VERIFICATION_TIMEOUT, 5115 }
5311 (const char *)pong, 5116 rl = rl->next;
5312 ntohs(pong->header.size), 5117 }
5313 GNUNET_YES, 5118 GNUNET_free (pong);
5314 n);
5315 did_pong = GNUNET_YES;
5316 fal = fal->next;
5317 }
5318 rl = rl->next;
5319 }
5320 GNUNET_free(pong);
5321 if (GNUNET_YES != did_pong) 5119 if (GNUNET_YES != did_pong)
5322 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 5120 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
5323 _("Could not send PONG to `%s': no address available\n"), 5121 _("Could not send PONG to `%s': no address available\n"),
5324 GNUNET_i2s (peer)); 5122 GNUNET_i2s (peer));
5325 return GNUNET_OK; 5123 return GNUNET_OK;
5326} 5124}
5327 5125
@@ -5350,8 +5148,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5350 const struct GNUNET_TRANSPORT_ATS_Information *ats_data, 5148 const struct GNUNET_TRANSPORT_ATS_Information *ats_data,
5351 uint32_t ats_count, 5149 uint32_t ats_count,
5352 struct Session *session, 5150 struct Session *session,
5353 const char *sender_address, 5151 const char *sender_address, uint16_t sender_address_len)
5354 uint16_t sender_address_len)
5355{ 5152{
5356 struct TransportPlugin *plugin = cls; 5153 struct TransportPlugin *plugin = cls;
5357 struct ReadyList *service_context; 5154 struct ReadyList *service_context;
@@ -5362,14 +5159,12 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5362 uint32_t distance; 5159 uint32_t distance;
5363 int c; 5160 int c;
5364 5161
5365 if (0 == memcmp (peer, 5162 if (0 == memcmp (peer, &my_identity, sizeof (struct GNUNET_PeerIdentity)))
5366 &my_identity, 5163 {
5367 sizeof (struct GNUNET_PeerIdentity))) 5164 /* refuse to receive from myself */
5368 { 5165 GNUNET_break (0);
5369 /* refuse to receive from myself */ 5166 return GNUNET_TIME_UNIT_FOREVER_REL;
5370 GNUNET_break (0); 5167 }
5371 return GNUNET_TIME_UNIT_FOREVER_REL;
5372 }
5373 if (is_blacklisted (peer, plugin)) 5168 if (is_blacklisted (peer, plugin))
5374 return GNUNET_TIME_UNIT_FOREVER_REL; 5169 return GNUNET_TIME_UNIT_FOREVER_REL;
5375 n = find_neighbour (peer); 5170 n = find_neighbour (peer);
@@ -5382,157 +5177,160 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
5382 peer_address = NULL; 5177 peer_address = NULL;
5383 distance = 1; 5178 distance = 1;
5384 5179
5385 for (c=0; c<ats_count; c++) 5180 for (c = 0; c < ats_count; c++)
5386 if (ntohl(ats_data[c].type) == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) 5181 if (ntohl (ats_data[c].type) == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
5387 distance = ntohl(ats_data[c].value); 5182 distance = ntohl (ats_data[c].value);
5388 5183
5389 5184
5390 if (message != NULL) 5185 if (message != NULL)
5391 { 5186 {
5392 if ( (session != NULL) || 5187 if ((session != NULL) || (sender_address != NULL))
5393 (sender_address != NULL) ) 5188 peer_address = add_peer_address (n,
5394 peer_address = add_peer_address (n, 5189 plugin->short_name,
5395 plugin->short_name, 5190 session,
5396 session, 5191 sender_address, sender_address_len);
5397 sender_address, 5192 if (peer_address != NULL)
5398 sender_address_len); 5193 {
5399 if (peer_address != NULL) 5194 update_addr_ats (peer_address, ats_data, ats_count);
5400 { 5195 update_addr_value (peer_address, distance,
5401 update_addr_ats(peer_address, ats_data, ats_count); 5196 GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
5402 update_addr_value(peer_address, distance, GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 5197
5403 5198 peer_address->distance = distance;
5404 peer_address->distance = distance; 5199 if (GNUNET_YES == peer_address->validated)
5405 if (GNUNET_YES == peer_address->validated) 5200 {
5406 { 5201 mark_address_connected (peer_address);
5407 mark_address_connected (peer_address); 5202 schedule_next_ping (peer_address);
5408 schedule_next_ping (peer_address); 5203 }
5409 } 5204 else
5410 else 5205 {
5411 {
5412#if DEBUG_TRANSPORT 5206#if DEBUG_TRANSPORT
5413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5414 "New address is unvalidated, trying to validate it now\n"); 5208 "New address is unvalidated, trying to validate it now\n");
5415#endif 5209#endif
5416 if (peer_address->revalidate_task != GNUNET_SCHEDULER_NO_TASK) 5210 if (peer_address->revalidate_task != GNUNET_SCHEDULER_NO_TASK)
5417 { 5211 {
5418 GNUNET_SCHEDULER_cancel (peer_address->revalidate_task); 5212 GNUNET_SCHEDULER_cancel (peer_address->revalidate_task);
5419 peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK; 5213 peer_address->revalidate_task = GNUNET_SCHEDULER_NO_TASK;
5420 } 5214 }
5421 peer_address->revalidate_task = GNUNET_SCHEDULER_add_now (&send_periodic_ping, peer_address); 5215 peer_address->revalidate_task =
5422 5216 GNUNET_SCHEDULER_add_now (&send_periodic_ping, peer_address);
5423 }
5424 peer_address->timeout
5425 = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
5426 }
5427 /* update traffic received amount ... */
5428 msize = ntohs (message->size);
5429 5217
5218 }
5219 peer_address->timeout
5220 =
5221 GNUNET_TIME_relative_to_absolute
5222 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
5223 }
5224 /* update traffic received amount ... */
5225 msize = ntohs (message->size);
5226
5227 GNUNET_STATISTICS_update (stats,
5228 gettext_noop
5229 ("# bytes received from other peers"), msize,
5230 GNUNET_NO);
5231 n->distance = distance;
5232 n->peer_timeout =
5233 GNUNET_TIME_relative_to_absolute
5234 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
5235 GNUNET_SCHEDULER_cancel (n->timeout_task);
5236 n->timeout_task =
5237 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
5238 &neighbour_timeout_task, n);
5239 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
5240 {
5241 /* dropping message due to frequent inbound volume violations! */
5242 GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
5243 GNUNET_ERROR_TYPE_BULK,
5244 _
5245 ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"),
5246 n->in_tracker.available_bytes_per_s__,
5247 n->quota_violation_count);
5430 GNUNET_STATISTICS_update (stats, 5248 GNUNET_STATISTICS_update (stats,
5431 gettext_noop ("# bytes received from other peers"), 5249 gettext_noop
5432 msize, 5250 ("# bandwidth quota violations by other peers"),
5433 GNUNET_NO); 5251 1, GNUNET_NO);
5434 n->distance = distance; 5252 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
5435 n->peer_timeout = 5253 }
5436 GNUNET_TIME_relative_to_absolute 5254 if ((ntohs (message->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ATS) &&
5437 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 5255 (ntohs (message->size) ==
5438 GNUNET_SCHEDULER_cancel (n->timeout_task); 5256 (sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t))))
5439 n->timeout_task = 5257 {
5440 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
5441 &neighbour_timeout_task, n);
5442 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
5443 {
5444 /* dropping message due to frequent inbound volume violations! */
5445 GNUNET_log (GNUNET_ERROR_TYPE_WARNING |
5446 GNUNET_ERROR_TYPE_BULK,
5447 _
5448 ("Dropping incoming message due to repeated bandwidth quota (%u b/s) violations (total of %u).\n"),
5449 n->in_tracker.available_bytes_per_s__,
5450 n->quota_violation_count);
5451 GNUNET_STATISTICS_update (stats,
5452 gettext_noop ("# bandwidth quota violations by other peers"),
5453 1,
5454 GNUNET_NO);
5455 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
5456 }
5457 if ((ntohs(message->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ATS) &&
5458 (ntohs(message->size) == (sizeof (struct GNUNET_MessageHeader) + sizeof (uint32_t))))
5459 {
5460#if HAVE_LIBGLPK 5258#if HAVE_LIBGLPK
5461 uint32_t value = ntohl(*((uint32_t *) &message[1])); 5259 uint32_t value = ntohl (*((uint32_t *) & message[1]));
5462 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_MESSAGE_TYPE_TRANSPORT_ATS: %i \n", value); 5260
5463 /* Force ressource and quality update */ 5261 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GNUNET_MESSAGE_TYPE_TRANSPORT_ATS: %i \n", value);
5464 if ((value == 4) && (ats != NULL)) 5262 /* Force ressource and quality update */
5465 ats_modify_problem_state(ats, ATS_QUALITY_COST_UPDATED); 5263 if ((value == 4) && (ats != NULL))
5466 /* Force cost update */ 5264 ats_modify_problem_state (ats, ATS_QUALITY_COST_UPDATED);
5467 if ((value == 3) && (ats != NULL)) 5265 /* Force cost update */
5468 ats_modify_problem_state(ats, ATS_COST_UPDATED); 5266 if ((value == 3) && (ats != NULL))
5469 /* Force quality update */ 5267 ats_modify_problem_state (ats, ATS_COST_UPDATED);
5470 if ((value == 2) && (ats != NULL)) 5268 /* Force quality update */
5471 ats_modify_problem_state(ats, ATS_QUALITY_UPDATED); 5269 if ((value == 2) && (ats != NULL))
5472 /* Force full rebuild */ 5270 ats_modify_problem_state (ats, ATS_QUALITY_UPDATED);
5473 if ((value == 1) && (ats != NULL)) 5271 /* Force full rebuild */
5474 ats_modify_problem_state(ats, ATS_MODIFIED); 5272 if ((value == 1) && (ats != NULL))
5273 ats_modify_problem_state (ats, ATS_MODIFIED);
5475#endif 5274#endif
5476 } 5275 }
5477 5276
5478#if DEBUG_PING_PONG 5277#if DEBUG_PING_PONG
5479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5278 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5480 "Received message of type %u and size %u from `%4s', sending to all clients.\n", 5279 "Received message of type %u and size %u from `%4s', sending to all clients.\n",
5481 ntohs (message->type), 5280 ntohs (message->type),
5482 ntohs (message->size), 5281 ntohs (message->size), GNUNET_i2s (peer));
5483 GNUNET_i2s (peer));
5484#endif 5282#endif
5485 switch (ntohs (message->type)) 5283 switch (ntohs (message->type))
5486 { 5284 {
5487 case GNUNET_MESSAGE_TYPE_HELLO: 5285 case GNUNET_MESSAGE_TYPE_HELLO:
5488 GNUNET_STATISTICS_update (stats, 5286 GNUNET_STATISTICS_update (stats,
5489 gettext_noop ("# HELLO messages received from other peers"), 5287 gettext_noop
5490 1, 5288 ("# HELLO messages received from other peers"),
5491 GNUNET_NO); 5289 1, GNUNET_NO);
5492 process_hello (plugin, message); 5290 process_hello (plugin, message);
5493 break; 5291 break;
5494 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING: 5292 case GNUNET_MESSAGE_TYPE_TRANSPORT_PING:
5495 handle_ping (plugin, message, peer, session, sender_address, sender_address_len); 5293 handle_ping (plugin, message, peer, session, sender_address,
5496 if (GNUNET_YES != n->received_pong) 5294 sender_address_len);
5497 transmit_plain_ping (n); 5295 if (GNUNET_YES != n->received_pong)
5498 break; 5296 transmit_plain_ping (n);
5499 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: 5297 break;
5500 handle_pong (plugin, message, peer, sender_address, sender_address_len); 5298 case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG:
5501 break; 5299 handle_pong (plugin, message, peer, sender_address, sender_address_len);
5502 case GNUNET_MESSAGE_TYPE_TRANSPORT_ATS: 5300 break;
5503 break; 5301 case GNUNET_MESSAGE_TYPE_TRANSPORT_ATS:
5504 default: 5302 break;
5505 handle_payload_message (message, n); 5303 default:
5506 break; 5304 handle_payload_message (message, n);
5507 } 5305 break;
5508 } 5306 }
5307 }
5509 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0); 5308 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
5510 if (ret.rel_value > 0) 5309 if (ret.rel_value > 0)
5511 { 5310 {
5512#if DEBUG_TRANSPORT 5311#if DEBUG_TRANSPORT
5513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5514 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n", 5313 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n",
5515 (unsigned long long) n->in_tracker.consumption_since_last_update__, 5314 (unsigned long long) n->
5516 (unsigned int) n->in_tracker.available_bytes_per_s__, 5315 in_tracker.consumption_since_last_update__,
5517 (unsigned long long) ret.rel_value); 5316 (unsigned int) n->in_tracker.available_bytes_per_s__,
5317 (unsigned long long) ret.rel_value);
5518#endif 5318#endif
5519 GNUNET_STATISTICS_update (stats, 5319 GNUNET_STATISTICS_update (stats,
5520 gettext_noop ("# ms throttling suggested"), 5320 gettext_noop ("# ms throttling suggested"),
5521 (int64_t) ret.rel_value, 5321 (int64_t) ret.rel_value, GNUNET_NO);
5522 GNUNET_NO); 5322 }
5523 }
5524 return ret; 5323 return ret;
5525} 5324}
5526 5325
5527 5326
5528static int 5327static int
5529notify_client_about_neighbour (void *cls, 5328notify_client_about_neighbour (void *cls,
5530 const GNUNET_HashCode *key, 5329 const GNUNET_HashCode * key, void *value)
5531 void *value)
5532{ 5330{
5533 struct TransportClient *c = cls; 5331 struct TransportClient *c = cls;
5534 struct NeighbourMapEntry *n = value; 5332 struct NeighbourMapEntry *n = value;
5535 struct ConnectInfoMessage * cim; 5333 struct ConnectInfoMessage *cim;
5536 uint32_t ats_count; 5334 uint32_t ats_count;
5537 size_t size; 5335 size_t size;
5538 5336
@@ -5540,23 +5338,25 @@ notify_client_about_neighbour (void *cls,
5540 return GNUNET_OK; 5338 return GNUNET_OK;
5541 5339
5542 ats_count = 2; 5340 ats_count = 2;
5543 size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 5341 size =
5342 sizeof (struct ConnectInfoMessage) +
5343 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
5544 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 5344 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
5545 cim = GNUNET_malloc (size); 5345 cim = GNUNET_malloc (size);
5546 cim->header.size = htons (size); 5346 cim->header.size = htons (size);
5547 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 5347 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
5548 cim->ats_count = htonl(ats_count); 5348 cim->ats_count = htonl (ats_count);
5549 (&(cim->ats))[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 5349 (&(cim->ats))[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
5550 (&(cim->ats))[2].value = htonl (0); 5350 (&(cim->ats))[2].value = htonl (0);
5551 if (GNUNET_YES == n->received_pong) 5351 if (GNUNET_YES == n->received_pong)
5552 { 5352 {
5553 (&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 5353 (&cim->ats)[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
5554 (&cim->ats)[0].value = htonl (n->distance); 5354 (&cim->ats)[0].value = htonl (n->distance);
5555 (&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); 5355 (&cim->ats)[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
5556 (&cim->ats)[1].value = htonl ((uint32_t) n->latency.rel_value); 5356 (&cim->ats)[1].value = htonl ((uint32_t) n->latency.rel_value);
5557 cim->id = n->id; 5357 cim->id = n->id;
5558 transmit_to_client (c, &cim->header, GNUNET_NO); 5358 transmit_to_client (c, &cim->header, GNUNET_NO);
5559 } 5359 }
5560 GNUNET_free (cim); 5360 GNUNET_free (cim);
5561 return GNUNET_OK; 5361 return GNUNET_OK;
5562} 5362}
@@ -5578,60 +5378,59 @@ handle_start (void *cls,
5578 const struct StartMessage *start; 5378 const struct StartMessage *start;
5579 struct TransportClient *c; 5379 struct TransportClient *c;
5580 5380
5581 start = (const struct StartMessage*) message; 5381 start = (const struct StartMessage *) message;
5582#if DEBUG_TRANSPORT 5382#if DEBUG_TRANSPORT
5583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5584 "Received `%s' request from client\n", "START"); 5384 "Received `%s' request from client\n", "START");
5585#endif 5385#endif
5586 c = clients; 5386 c = clients;
5587 while (c != NULL) 5387 while (c != NULL)
5388 {
5389 if (c->client == client)
5588 { 5390 {
5589 if (c->client == client) 5391 /* client already on our list! */
5590 { 5392 GNUNET_break (0);
5591 /* client already on our list! */
5592 GNUNET_break (0);
5593 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5594 return;
5595 }
5596 c = c->next;
5597 }
5598 if ( (GNUNET_NO != ntohl (start->do_check)) &&
5599 (0 != memcmp (&start->self,
5600 &my_identity,
5601 sizeof (struct GNUNET_PeerIdentity))) )
5602 {
5603 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5604 _("Rejecting control connection from peer `%s', which is not me!\n"),
5605 GNUNET_i2s (&start->self));
5606 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5393 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5607 return; 5394 return;
5608 } 5395 }
5396 c = c->next;
5397 }
5398 if ((GNUNET_NO != ntohl (start->do_check)) &&
5399 (0 != memcmp (&start->self,
5400 &my_identity, sizeof (struct GNUNET_PeerIdentity))))
5401 {
5402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5403 _
5404 ("Rejecting control connection from peer `%s', which is not me!\n"),
5405 GNUNET_i2s (&start->self));
5406 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5407 return;
5408 }
5609 c = GNUNET_malloc (sizeof (struct TransportClient)); 5409 c = GNUNET_malloc (sizeof (struct TransportClient));
5610 c->next = clients; 5410 c->next = clients;
5611 clients = c; 5411 clients = c;
5612 c->client = client; 5412 c->client = client;
5613 if (our_hello != NULL) 5413 if (our_hello != NULL)
5614 { 5414 {
5615#if DEBUG_TRANSPORT 5415#if DEBUG_TRANSPORT
5616 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5617 "Sending our own `%s' to new client\n", "HELLO"); 5417 "Sending our own `%s' to new client\n", "HELLO");
5618#endif 5418#endif
5619 transmit_to_client (c, 5419 transmit_to_client (c,
5620 (const struct GNUNET_MessageHeader *) our_hello, 5420 (const struct GNUNET_MessageHeader *) our_hello,
5621 GNUNET_NO); 5421 GNUNET_NO);
5622 /* tell new client about all existing connections */ 5422 /* tell new client about all existing connections */
5623 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 5423 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
5624 &notify_client_about_neighbour, 5424 &notify_client_about_neighbour, c);
5625 c); 5425 }
5626 }
5627 else 5426 else
5628 { 5427 {
5629#if DEBUG_TRANSPORT_HELLO 5428#if DEBUG_TRANSPORT_HELLO
5630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5429 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5631 "No HELLO created yet, will transmit HELLO to client later!\n"); 5430 "No HELLO created yet, will transmit HELLO to client later!\n");
5632#endif 5431#endif
5633 refresh_hello (); 5432 refresh_hello ();
5634 } 5433 }
5635 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5434 GNUNET_SERVER_receive_done (client, GNUNET_OK);
5636} 5435}
5637 5436
@@ -5651,9 +5450,8 @@ handle_hello (void *cls,
5651 int ret; 5450 int ret;
5652 5451
5653 GNUNET_STATISTICS_update (stats, 5452 GNUNET_STATISTICS_update (stats,
5654 gettext_noop ("# HELLOs received from clients"), 5453 gettext_noop ("# HELLOs received from clients"),
5655 1, 5454 1, GNUNET_NO);
5656 GNUNET_NO);
5657 ret = process_hello (NULL, message); 5455 ret = process_hello (NULL, message);
5658 GNUNET_SERVER_receive_done (client, ret); 5456 GNUNET_SERVER_receive_done (client, ret);
5659} 5457}
@@ -5694,8 +5492,7 @@ struct TransmitClientMessageContext
5694 * @param n destination, or NULL on error (in that case, drop the message) 5492 * @param n destination, or NULL on error (in that case, drop the message)
5695 */ 5493 */
5696static void 5494static void
5697transmit_client_message (void *cls, 5495transmit_client_message (void *cls, struct NeighbourMapEntry *n)
5698 struct NeighbourMapEntry *n)
5699{ 5496{
5700 struct TransmitClientMessageContext *tcmc = cls; 5497 struct TransmitClientMessageContext *tcmc = cls;
5701 struct TransportClient *tc; 5498 struct TransportClient *tc;
@@ -5705,12 +5502,11 @@ transmit_client_message (void *cls,
5705 tc = tc->next; 5502 tc = tc->next;
5706 5503
5707 if (n != NULL) 5504 if (n != NULL)
5708 { 5505 {
5709 transmit_to_peer (tc, NULL, tcmc->priority, 5506 transmit_to_peer (tc, NULL, tcmc->priority,
5710 GNUNET_TIME_absolute_get_remaining (tcmc->timeout), 5507 GNUNET_TIME_absolute_get_remaining (tcmc->timeout),
5711 (char *)&tcmc[1], 5508 (char *) &tcmc[1], tcmc->msize, GNUNET_NO, n);
5712 tcmc->msize, GNUNET_NO, n); 5509 }
5713 }
5714 GNUNET_SERVER_receive_done (tcmc->client, GNUNET_OK); 5510 GNUNET_SERVER_receive_done (tcmc->client, GNUNET_OK);
5715 GNUNET_SERVER_client_drop (tcmc->client); 5511 GNUNET_SERVER_client_drop (tcmc->client);
5716 GNUNET_free (tcmc); 5512 GNUNET_free (tcmc);
@@ -5738,36 +5534,34 @@ handle_send (void *cls,
5738 size = ntohs (message->size); 5534 size = ntohs (message->size);
5739 if (size < 5535 if (size <
5740 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader)) 5536 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
5741 { 5537 {
5742 GNUNET_break (0); 5538 GNUNET_break (0);
5743 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5539 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5744 return; 5540 return;
5745 } 5541 }
5746 GNUNET_STATISTICS_update (stats, 5542 GNUNET_STATISTICS_update (stats,
5747 gettext_noop ("# payload received for other peers"), 5543 gettext_noop ("# payload received for other peers"),
5748 size, 5544 size, GNUNET_NO);
5749 GNUNET_NO);
5750 obm = (const struct OutboundMessage *) message; 5545 obm = (const struct OutboundMessage *) message;
5751 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 5546 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
5752 msize = size - sizeof (struct OutboundMessage); 5547 msize = size - sizeof (struct OutboundMessage);
5753#if DEBUG_TRANSPORT 5548#if DEBUG_TRANSPORT
5754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5755 "Received `%s' request from client with target `%4s' and message of type %u and size %u\n", 5550 "Received `%s' request from client with target `%4s' and message of type %u and size %u\n",
5756 "SEND", GNUNET_i2s (&obm->peer), 5551 "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
5757 ntohs (obmm->type),
5758 msize);
5759#endif 5552#endif
5760 tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize); 5553 tcmc = GNUNET_malloc (sizeof (struct TransmitClientMessageContext) + msize);
5761 tcmc->client = client; 5554 tcmc->client = client;
5762 tcmc->priority = ntohl (obm->priority); 5555 tcmc->priority = ntohl (obm->priority);
5763 tcmc->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh (obm->timeout)); 5556 tcmc->timeout =
5557 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_ntoh
5558 (obm->timeout));
5764 tcmc->msize = msize; 5559 tcmc->msize = msize;
5765 /* FIXME: this memcpy can be up to 7% of our total runtime */ 5560 /* FIXME: this memcpy can be up to 7% of our total runtime */
5766 memcpy (&tcmc[1], obmm, msize); 5561 memcpy (&tcmc[1], obmm, msize);
5767 GNUNET_SERVER_client_keep (client); 5562 GNUNET_SERVER_client_keep (client);
5768 setup_peer_check_blacklist (&obm->peer, GNUNET_YES, 5563 setup_peer_check_blacklist (&obm->peer, GNUNET_YES,
5769 &transmit_client_message, 5564 &transmit_client_message, tcmc);
5770 tcmc);
5771} 5565}
5772 5566
5773 5567
@@ -5784,19 +5578,18 @@ handle_request_connect (void *cls,
5784 const struct GNUNET_MessageHeader *message) 5578 const struct GNUNET_MessageHeader *message)
5785{ 5579{
5786 const struct TransportRequestConnectMessage *trcm = 5580 const struct TransportRequestConnectMessage *trcm =
5787 (const struct TransportRequestConnectMessage *) message; 5581 (const struct TransportRequestConnectMessage *) message;
5788 5582
5789 GNUNET_STATISTICS_update (stats, 5583 GNUNET_STATISTICS_update (stats,
5790 gettext_noop ("# REQUEST CONNECT messages received"), 5584 gettext_noop
5791 1, 5585 ("# REQUEST CONNECT messages received"), 1,
5792 GNUNET_NO); 5586 GNUNET_NO);
5793#if DEBUG_TRANSPORT 5587#if DEBUG_TRANSPORT
5794 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 5588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5795 "Received a request connect message for peer `%s'\n", 5589 "Received a request connect message for peer `%s'\n",
5796 GNUNET_i2s(&trcm->peer)); 5590 GNUNET_i2s (&trcm->peer));
5797#endif 5591#endif
5798 setup_peer_check_blacklist (&trcm->peer, GNUNET_YES, 5592 setup_peer_check_blacklist (&trcm->peer, GNUNET_YES, NULL, NULL);
5799 NULL, NULL);
5800 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5593 GNUNET_SERVER_receive_done (client, GNUNET_OK);
5801} 5594}
5802 5595
@@ -5813,47 +5606,43 @@ handle_set_quota (void *cls,
5813 struct GNUNET_SERVER_Client *client, 5606 struct GNUNET_SERVER_Client *client,
5814 const struct GNUNET_MessageHeader *message) 5607 const struct GNUNET_MessageHeader *message)
5815{ 5608{
5816 const struct QuotaSetMessage *qsm = 5609 const struct QuotaSetMessage *qsm = (const struct QuotaSetMessage *) message;
5817 (const struct QuotaSetMessage *) message;
5818 struct NeighbourMapEntry *n; 5610 struct NeighbourMapEntry *n;
5819 5611
5820 GNUNET_STATISTICS_update (stats, 5612 GNUNET_STATISTICS_update (stats,
5821 gettext_noop ("# SET QUOTA messages received"), 5613 gettext_noop ("# SET QUOTA messages received"),
5822 1, 5614 1, GNUNET_NO);
5823 GNUNET_NO);
5824 n = find_neighbour (&qsm->peer); 5615 n = find_neighbour (&qsm->peer);
5825 if (n == NULL) 5616 if (n == NULL)
5826 { 5617 {
5827 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5618 GNUNET_SERVER_receive_done (client, GNUNET_OK);
5828 GNUNET_STATISTICS_update (stats, 5619 GNUNET_STATISTICS_update (stats,
5829 gettext_noop ("# SET QUOTA messages ignored (no such peer)"), 5620 gettext_noop
5830 1, 5621 ("# SET QUOTA messages ignored (no such peer)"),
5831 GNUNET_NO); 5622 1, GNUNET_NO);
5832 return; 5623 return;
5833 } 5624 }
5834#if DEBUG_TRANSPORT 5625#if DEBUG_TRANSPORT
5835 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5836 "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n", 5627 "Received `%s' request (new quota %u, old quota %u) from client for peer `%4s'\n",
5837 "SET_QUOTA", 5628 "SET_QUOTA",
5838 (unsigned int) ntohl (qsm->quota.value__), 5629 (unsigned int) ntohl (qsm->quota.value__),
5839 (unsigned int) n->in_tracker.available_bytes_per_s__, 5630 (unsigned int) n->in_tracker.available_bytes_per_s__,
5840 GNUNET_i2s (&qsm->peer)); 5631 GNUNET_i2s (&qsm->peer));
5841#endif 5632#endif
5842 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, 5633 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, qsm->quota);
5843 qsm->quota);
5844 if (0 == ntohl (qsm->quota.value__)) 5634 if (0 == ntohl (qsm->quota.value__))
5845 { 5635 {
5846#if DEBUG_TRANSPORT 5636#if DEBUG_TRANSPORT
5847 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5848 "Disconnecting peer `%4s', %s\n", GNUNET_i2s(&n->id), 5638 "Disconnecting peer `%4s', %s\n", GNUNET_i2s (&n->id),
5849 "SET_QUOTA"); 5639 "SET_QUOTA");
5850#endif 5640#endif
5851 GNUNET_STATISTICS_update (stats, 5641 GNUNET_STATISTICS_update (stats,
5852 gettext_noop ("# disconnects due to quota of 0"), 5642 gettext_noop ("# disconnects due to quota of 0"),
5853 1, 5643 1, GNUNET_NO);
5854 GNUNET_NO); 5644 disconnect_neighbour (n, GNUNET_NO);
5855 disconnect_neighbour (n, GNUNET_NO); 5645 }
5856 }
5857 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5646 GNUNET_SERVER_receive_done (client, GNUNET_OK);
5858} 5647}
5859 5648
@@ -5872,17 +5661,17 @@ transmit_address_to_client (void *cls, const char *address)
5872 size_t slen; 5661 size_t slen;
5873 5662
5874 if (NULL != address) 5663 if (NULL != address)
5875 { 5664 {
5876 slen = strlen (address) + 1; 5665 slen = strlen (address) + 1;
5877 GNUNET_SERVER_transmit_context_append_data (tc, address, slen, 5666 GNUNET_SERVER_transmit_context_append_data (tc, address, slen,
5878 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 5667 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
5879 } 5668 }
5880 else 5669 else
5881 { 5670 {
5882 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 5671 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
5883 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 5672 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
5884 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 5673 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
5885 } 5674 }
5886} 5675}
5887 5676
5888 5677
@@ -5909,45 +5698,46 @@ handle_address_lookup (void *cls,
5909 5698
5910 size = ntohs (message->size); 5699 size = ntohs (message->size);
5911 if (size < sizeof (struct AddressLookupMessage)) 5700 if (size < sizeof (struct AddressLookupMessage))
5912 { 5701 {
5913 GNUNET_break_op (0); 5702 GNUNET_break_op (0);
5914 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5703 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5915 return; 5704 return;
5916 } 5705 }
5917 alum = (const struct AddressLookupMessage *) message; 5706 alum = (const struct AddressLookupMessage *) message;
5918 uint32_t addressLen = ntohl (alum->addrlen); 5707 uint32_t addressLen = ntohl (alum->addrlen);
5708
5919 if (size <= sizeof (struct AddressLookupMessage) + addressLen) 5709 if (size <= sizeof (struct AddressLookupMessage) + addressLen)
5920 { 5710 {
5921 GNUNET_break_op (0); 5711 GNUNET_break_op (0);
5922 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5712 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5923 return; 5713 return;
5924 } 5714 }
5925 address = (const char *) &alum[1]; 5715 address = (const char *) &alum[1];
5926 nameTransport = (const char *) &address[addressLen]; 5716 nameTransport = (const char *) &address[addressLen];
5927 if (nameTransport 5717 if (nameTransport
5928 [size - sizeof (struct AddressLookupMessage) - addressLen - 1] != '\0') 5718 [size - sizeof (struct AddressLookupMessage) - addressLen - 1] != '\0')
5929 { 5719 {
5930 GNUNET_break_op (0); 5720 GNUNET_break_op (0);
5931 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5721 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5932 return; 5722 return;
5933 } 5723 }
5934 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); 5724 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
5935 numeric = ntohl (alum->numeric_only); 5725 numeric = ntohl (alum->numeric_only);
5936 lsPlugin = find_transport (nameTransport); 5726 lsPlugin = find_transport (nameTransport);
5937 if (NULL == lsPlugin) 5727 if (NULL == lsPlugin)
5938 { 5728 {
5939 tc = GNUNET_SERVER_transmit_context_create (client); 5729 tc = GNUNET_SERVER_transmit_context_create (client);
5940 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 5730 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
5941 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 5731 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
5942 GNUNET_SERVER_transmit_context_run (tc, rtimeout); 5732 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
5943 return; 5733 return;
5944 } 5734 }
5945 GNUNET_SERVER_disable_receive_done_warning (client); 5735 GNUNET_SERVER_disable_receive_done_warning (client);
5946 tc = GNUNET_SERVER_transmit_context_create (client); 5736 tc = GNUNET_SERVER_transmit_context_create (client);
5947 lsPlugin->api->address_pretty_printer (lsPlugin->api->cls, 5737 lsPlugin->api->address_pretty_printer (lsPlugin->api->cls,
5948 nameTransport, 5738 nameTransport,
5949 address, addressLen, 5739 address, addressLen,
5950 numeric, 5740 numeric,
5951 rtimeout, 5741 rtimeout,
5952 &transmit_address_to_client, tc); 5742 &transmit_address_to_client, tc);
5953} 5743}
@@ -5961,8 +5751,8 @@ handle_address_lookup (void *cls,
5961 */ 5751 */
5962static void 5752static void
5963handle_peer_address_lookup (void *cls, 5753handle_peer_address_lookup (void *cls,
5964 struct GNUNET_SERVER_Client *client, 5754 struct GNUNET_SERVER_Client *client,
5965 const struct GNUNET_MessageHeader *message) 5755 const struct GNUNET_MessageHeader *message)
5966{ 5756{
5967 const struct PeerAddressLookupMessage *peer_address_lookup; 5757 const struct PeerAddressLookupMessage *peer_address_lookup;
5968 struct NeighbourMapEntry *neighbor_iterator; 5758 struct NeighbourMapEntry *neighbor_iterator;
@@ -5977,11 +5767,11 @@ handle_peer_address_lookup (void *cls,
5977 5767
5978 size = ntohs (message->size); 5768 size = ntohs (message->size);
5979 if (size < sizeof (struct PeerAddressLookupMessage)) 5769 if (size < sizeof (struct PeerAddressLookupMessage))
5980 { 5770 {
5981 GNUNET_break_op (0); 5771 GNUNET_break_op (0);
5982 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5772 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
5983 return; 5773 return;
5984 } 5774 }
5985 peer_address_lookup = (const struct PeerAddressLookupMessage *) message; 5775 peer_address_lookup = (const struct PeerAddressLookupMessage *) message;
5986 5776
5987 rtimeout = GNUNET_TIME_relative_ntoh (peer_address_lookup->timeout); 5777 rtimeout = GNUNET_TIME_relative_ntoh (peer_address_lookup->timeout);
@@ -5990,56 +5780,54 @@ handle_peer_address_lookup (void *cls,
5990 5780
5991 /* Found no neighbor matching this peer id (shouldn't be possible, but...) */ 5781 /* Found no neighbor matching this peer id (shouldn't be possible, but...) */
5992 if (neighbor_iterator == NULL) 5782 if (neighbor_iterator == NULL)
5993 { 5783 {
5994 GNUNET_break(0); 5784 GNUNET_break (0);
5995 tc = GNUNET_SERVER_transmit_context_create (client); 5785 tc = GNUNET_SERVER_transmit_context_create (client);
5996 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 5786 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
5997 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 5787 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
5998 GNUNET_SERVER_transmit_context_run (tc, rtimeout); 5788 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
5999 return; 5789 return;
6000 } 5790 }
6001 5791
6002 ready_iterator = neighbor_iterator->plugins; 5792 ready_iterator = neighbor_iterator->plugins;
6003 GNUNET_SERVER_disable_receive_done_warning (client); 5793 GNUNET_SERVER_disable_receive_done_warning (client);
6004 tc = GNUNET_SERVER_transmit_context_create (client); 5794 tc = GNUNET_SERVER_transmit_context_create (client);
6005 while(ready_iterator != NULL) 5795 while (ready_iterator != NULL)
5796 {
5797 foreign_address_iterator = ready_iterator->addresses;
5798 while (foreign_address_iterator != NULL)
6006 { 5799 {
6007 foreign_address_iterator = ready_iterator->addresses; 5800 transport_plugin = foreign_address_iterator->ready_list->plugin;
6008 while (foreign_address_iterator != NULL) 5801 if (foreign_address_iterator->addr != NULL)
6009 { 5802 {
6010 transport_plugin = foreign_address_iterator->ready_list->plugin; 5803 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
6011 if (foreign_address_iterator->addr != NULL) 5804 a2s (transport_plugin->short_name,
6012 { 5805 foreign_address_iterator->addr,
6013 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", 5806 foreign_address_iterator->addrlen),
6014 a2s (transport_plugin->short_name, 5807 (foreign_address_iterator->connected
6015 foreign_address_iterator->addr, 5808 == GNUNET_YES) ? "CONNECTED"
6016 foreign_address_iterator->addrlen), 5809 : "DISCONNECTED",
6017 (foreign_address_iterator->connected 5810 (foreign_address_iterator->validated
6018 == GNUNET_YES) ? "CONNECTED" 5811 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
6019 : "DISCONNECTED", 5812 transmit_address_to_client (tc, addr_buf);
6020 (foreign_address_iterator->validated 5813 GNUNET_free (addr_buf);
6021 == GNUNET_YES) ? "VALIDATED" 5814 }
6022 : "UNVALIDATED"); 5815 else if (foreign_address_iterator->addrlen == 0)
6023 transmit_address_to_client(tc, addr_buf); 5816 {
6024 GNUNET_free (addr_buf); 5817 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", "<inbound>",
6025 } 5818 (foreign_address_iterator->connected
6026 else if (foreign_address_iterator->addrlen == 0) 5819 == GNUNET_YES) ? "CONNECTED"
6027 { 5820 : "DISCONNECTED",
6028 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", "<inbound>", 5821 (foreign_address_iterator->validated
6029 (foreign_address_iterator->connected 5822 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
6030 == GNUNET_YES) ? "CONNECTED" 5823 transmit_address_to_client (tc, addr_buf);
6031 : "DISCONNECTED", 5824 GNUNET_free (addr_buf);
6032 (foreign_address_iterator->validated 5825 }
6033 == GNUNET_YES) ? "VALIDATED" 5826
6034 : "UNVALIDATED"); 5827 foreign_address_iterator = foreign_address_iterator->next;
6035 transmit_address_to_client (tc, addr_buf);
6036 GNUNET_free (addr_buf);
6037 }
6038
6039 foreign_address_iterator = foreign_address_iterator->next;
6040 }
6041 ready_iterator = ready_iterator->next;
6042 } 5828 }
5829 ready_iterator = ready_iterator->next;
5830 }
6043 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 5831 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
6044 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 5832 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
6045 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 5833 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -6048,9 +5836,7 @@ handle_peer_address_lookup (void *cls,
6048 5836
6049 5837
6050static int 5838static int
6051output_addresses (void *cls, 5839output_addresses (void *cls, const GNUNET_HashCode * key, void *value)
6052 const GNUNET_HashCode *key,
6053 void *value)
6054{ 5840{
6055 struct GNUNET_SERVER_TransmitContext *tc = cls; 5841 struct GNUNET_SERVER_TransmitContext *tc = cls;
6056 struct NeighbourMapEntry *neighbor_iterator = value; 5842 struct NeighbourMapEntry *neighbor_iterator = value;
@@ -6061,46 +5847,44 @@ output_addresses (void *cls,
6061 5847
6062 ready_iterator = neighbor_iterator->plugins; 5848 ready_iterator = neighbor_iterator->plugins;
6063 while (ready_iterator != NULL) 5849 while (ready_iterator != NULL)
5850 {
5851 foreign_address_iterator = ready_iterator->addresses;
5852 while (foreign_address_iterator != NULL)
6064 { 5853 {
6065 foreign_address_iterator = ready_iterator->addresses; 5854 transport_plugin = foreign_address_iterator->ready_list->plugin;
6066 while (foreign_address_iterator != NULL) 5855 if (foreign_address_iterator->addr != NULL)
6067 { 5856 {
6068 transport_plugin = foreign_address_iterator->ready_list->plugin; 5857 GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
6069 if (foreign_address_iterator->addr != NULL) 5858 GNUNET_i2s (&neighbor_iterator->id),
6070 { 5859 a2s (transport_plugin->short_name,
6071 GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s", 5860 foreign_address_iterator->addr,
6072 GNUNET_i2s(&neighbor_iterator->id), 5861 foreign_address_iterator->addrlen),
6073 a2s (transport_plugin->short_name, 5862 (foreign_address_iterator->connected
6074 foreign_address_iterator->addr, 5863 == GNUNET_YES) ? "CONNECTED"
6075 foreign_address_iterator->addrlen), 5864 : "DISCONNECTED",
6076 (foreign_address_iterator->connected 5865 (foreign_address_iterator->validated
6077 == GNUNET_YES) ? "CONNECTED" 5866 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
6078 : "DISCONNECTED", 5867 transmit_address_to_client (tc, addr_buf);
6079 (foreign_address_iterator->validated 5868 GNUNET_free (addr_buf);
6080 == GNUNET_YES) ? "VALIDATED" 5869 }
6081 : "UNVALIDATED"); 5870 else if (foreign_address_iterator->addrlen == 0)
6082 transmit_address_to_client (tc, addr_buf); 5871 {
6083 GNUNET_free (addr_buf); 5872 GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s",
6084 } 5873 GNUNET_i2s (&neighbor_iterator->id),
6085 else if (foreign_address_iterator->addrlen == 0) 5874 "<inbound>",
6086 { 5875 (foreign_address_iterator->connected
6087 GNUNET_asprintf (&addr_buf, "%s:%s --- %s, %s", 5876 == GNUNET_YES) ? "CONNECTED"
6088 GNUNET_i2s (&neighbor_iterator->id), 5877 : "DISCONNECTED",
6089 "<inbound>", 5878 (foreign_address_iterator->validated
6090 (foreign_address_iterator->connected 5879 == GNUNET_YES) ? "VALIDATED" : "UNVALIDATED");
6091 == GNUNET_YES) ? "CONNECTED" 5880 transmit_address_to_client (tc, addr_buf);
6092 : "DISCONNECTED", 5881 GNUNET_free (addr_buf);
6093 (foreign_address_iterator->validated 5882 }
6094 == GNUNET_YES) ? "VALIDATED" 5883
6095 : "UNVALIDATED"); 5884 foreign_address_iterator = foreign_address_iterator->next;
6096 transmit_address_to_client (tc, addr_buf);
6097 GNUNET_free (addr_buf);
6098 }
6099
6100 foreign_address_iterator = foreign_address_iterator->next;
6101 }
6102 ready_iterator = ready_iterator->next;
6103 } 5885 }
5886 ready_iterator = ready_iterator->next;
5887 }
6104 return GNUNET_OK; 5888 return GNUNET_OK;
6105} 5889}
6106 5890
@@ -6122,16 +5906,14 @@ handle_address_iterate (void *cls,
6122 5906
6123 size = ntohs (message->size); 5907 size = ntohs (message->size);
6124 if (size < sizeof (struct AddressIterateMessage)) 5908 if (size < sizeof (struct AddressIterateMessage))
6125 { 5909 {
6126 GNUNET_break_op (0); 5910 GNUNET_break_op (0);
6127 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5911 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6128 return; 5912 return;
6129 } 5913 }
6130 GNUNET_SERVER_disable_receive_done_warning (client); 5914 GNUNET_SERVER_disable_receive_done_warning (client);
6131 tc = GNUNET_SERVER_transmit_context_create (client); 5915 tc = GNUNET_SERVER_transmit_context_create (client);
6132 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 5916 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &output_addresses, tc);
6133 &output_addresses,
6134 tc);
6135 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 5917 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
6136 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 5918 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
6137 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 5919 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -6141,7 +5923,7 @@ handle_address_iterate (void *cls,
6141static const struct GNUNET_MessageHeader * 5923static const struct GNUNET_MessageHeader *
6142do_get_our_hello () 5924do_get_our_hello ()
6143{ 5925{
6144 return (const struct GNUNET_MessageHeader*) our_hello; 5926 return (const struct GNUNET_MessageHeader *) our_hello;
6145} 5927}
6146 5928
6147 5929
@@ -6167,8 +5949,7 @@ create_environment (struct TransportPlugin *plug)
6167 * Start the specified transport (load the plugin). 5949 * Start the specified transport (load the plugin).
6168 */ 5950 */
6169static void 5951static void
6170start_transport (struct GNUNET_SERVER_Handle *server, 5952start_transport (struct GNUNET_SERVER_Handle *server, const char *name)
6171 const char *name)
6172{ 5953{
6173 struct TransportPlugin *plug; 5954 struct TransportPlugin *plug;
6174 char *libname; 5955 char *libname;
@@ -6184,31 +5965,29 @@ start_transport (struct GNUNET_SERVER_Handle *server,
6184 plugins = plug; 5965 plugins = plug;
6185 plug->api = GNUNET_PLUGIN_load (libname, &plug->env); 5966 plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
6186 if (plug->api == NULL) 5967 if (plug->api == NULL)
6187 { 5968 {
6188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 5969 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6189 _("Failed to load transport plugin for `%s'\n"), name); 5970 _("Failed to load transport plugin for `%s'\n"), name);
6190 GNUNET_free (plug->short_name); 5971 GNUNET_free (plug->short_name);
6191 plugins = plug->next; 5972 plugins = plug->next;
6192 GNUNET_free (libname); 5973 GNUNET_free (libname);
6193 GNUNET_free (plug); 5974 GNUNET_free (plug);
6194 } 5975 }
6195} 5976}
6196 5977
6197 5978
6198static int 5979static int
6199null_mq_client_pointers (void *cls, 5980null_mq_client_pointers (void *cls, const GNUNET_HashCode * key, void *value)
6200 const GNUNET_HashCode *key,
6201 void *value)
6202{ 5981{
6203 struct TransportClient *pos = cls; 5982 struct TransportClient *pos = cls;
6204 struct NeighbourMapEntry *n = value; 5983 struct NeighbourMapEntry *n = value;
6205 struct MessageQueue *mq; 5984 struct MessageQueue *mq;
6206 5985
6207 for (mq = n->messages_head; mq != NULL; mq = mq->next) 5986 for (mq = n->messages_head; mq != NULL; mq = mq->next)
6208 { 5987 {
6209 if (mq->client == pos) 5988 if (mq->client == pos)
6210 mq->client = NULL; /* do not use anymore! */ 5989 mq->client = NULL; /* do not use anymore! */
6211 } 5990 }
6212 return GNUNET_OK; 5991 return GNUNET_OK;
6213} 5992}
6214 5993
@@ -6221,8 +6000,7 @@ null_mq_client_pointers (void *cls,
6221 * @param client identification of the client 6000 * @param client identification of the client
6222 */ 6001 */
6223static void 6002static void
6224client_disconnect_notification (void *cls, 6003client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
6225 struct GNUNET_SERVER_Client *client)
6226{ 6004{
6227 struct TransportClient *pos; 6005 struct TransportClient *pos;
6228 struct TransportClient *prev; 6006 struct TransportClient *prev;
@@ -6239,89 +6017,81 @@ client_disconnect_notification (void *cls,
6239 /* clean up blacklister */ 6017 /* clean up blacklister */
6240 bl = bl_head; 6018 bl = bl_head;
6241 while (bl != NULL) 6019 while (bl != NULL)
6020 {
6021 if (bl->client == client)
6242 { 6022 {
6243 if (bl->client == client) 6023 bc = bc_head;
6244 { 6024 while (bc != NULL)
6245 bc = bc_head; 6025 {
6246 while (bc != NULL) 6026 if (bc->bl_pos == bl)
6247 { 6027 {
6248 if (bc->bl_pos == bl) 6028 bc->bl_pos = bl->next;
6249 { 6029 if (bc->th != NULL)
6250 bc->bl_pos = bl->next; 6030 {
6251 if (bc->th != NULL) 6031 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
6252 { 6032 bc->th = NULL;
6253 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th); 6033 }
6254 bc->th = NULL; 6034 if (bc->task == GNUNET_SCHEDULER_NO_TASK)
6255 } 6035 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
6256 if (bc->task == GNUNET_SCHEDULER_NO_TASK) 6036 break;
6257 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 6037 }
6258 bc); 6038 bc = bc->next;
6259 break; 6039 }
6260 } 6040 GNUNET_CONTAINER_DLL_remove (bl_head, bl_tail, bl);
6261 bc = bc->next; 6041 GNUNET_SERVER_client_drop (bl->client);
6262 } 6042 GNUNET_free (bl);
6263 GNUNET_CONTAINER_DLL_remove (bl_head, 6043 break;
6264 bl_tail,
6265 bl);
6266 GNUNET_SERVER_client_drop (bl->client);
6267 GNUNET_free (bl);
6268 break;
6269 }
6270 bl = bl->next;
6271 } 6044 }
6045 bl = bl->next;
6046 }
6272 /* clean up 'normal' clients */ 6047 /* clean up 'normal' clients */
6273 prev = NULL; 6048 prev = NULL;
6274 pos = clients; 6049 pos = clients;
6275 while ((pos != NULL) && (pos->client != client)) 6050 while ((pos != NULL) && (pos->client != client))
6276 { 6051 {
6277 prev = pos; 6052 prev = pos;
6278 pos = pos->next; 6053 pos = pos->next;
6279 } 6054 }
6280 if (pos == NULL) 6055 if (pos == NULL)
6281 return; 6056 return;
6282 while (NULL != (mqe = pos->message_queue_head)) 6057 while (NULL != (mqe = pos->message_queue_head))
6283 { 6058 {
6284 GNUNET_CONTAINER_DLL_remove (pos->message_queue_head, 6059 GNUNET_CONTAINER_DLL_remove (pos->message_queue_head,
6285 pos->message_queue_tail, 6060 pos->message_queue_tail, mqe);
6286 mqe); 6061 pos->message_count--;
6287 pos->message_count--; 6062 GNUNET_free (mqe);
6288 GNUNET_free (mqe); 6063 }
6289 }
6290 if (NULL != neighbours) 6064 if (NULL != neighbours)
6291 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 6065 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
6292 &null_mq_client_pointers, 6066 &null_mq_client_pointers, pos);
6293 pos);
6294 if (prev == NULL) 6067 if (prev == NULL)
6295 clients = pos->next; 6068 clients = pos->next;
6296 else 6069 else
6297 prev->next = pos->next; 6070 prev->next = pos->next;
6298 if (GNUNET_YES == pos->tcs_pending) 6071 if (GNUNET_YES == pos->tcs_pending)
6299 { 6072 {
6300 pos->client = NULL; 6073 pos->client = NULL;
6301 return; 6074 return;
6302 } 6075 }
6303 if (pos->th != NULL) 6076 if (pos->th != NULL)
6304 { 6077 {
6305 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th); 6078 GNUNET_CONNECTION_notify_transmit_ready_cancel (pos->th);
6306 pos->th = NULL; 6079 pos->th = NULL;
6307 } 6080 }
6308 GNUNET_break (0 == pos->message_count); 6081 GNUNET_break (0 == pos->message_count);
6309 GNUNET_free (pos); 6082 GNUNET_free (pos);
6310} 6083}
6311 6084
6312 6085
6313static int 6086static int
6314disconnect_all_neighbours (void *cls, 6087disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
6315 const GNUNET_HashCode *key,
6316 void *value)
6317{ 6088{
6318 struct NeighbourMapEntry *n = value; 6089 struct NeighbourMapEntry *n = value;
6319 6090
6320#if DEBUG_TRANSPORT 6091#if DEBUG_TRANSPORT
6321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6092 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6322 "Disconnecting peer `%4s', %s\n", 6093 "Disconnecting peer `%4s', %s\n",
6323 GNUNET_i2s(&n->id), 6094 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
6324 "SHUTDOWN_TASK");
6325#endif 6095#endif
6326 disconnect_neighbour (n, GNUNET_NO); 6096 disconnect_neighbour (n, GNUNET_NO);
6327 return GNUNET_OK; 6097 return GNUNET_OK;
@@ -6344,44 +6114,42 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6344 6114
6345 shutdown_in_progress = GNUNET_YES; 6115 shutdown_in_progress = GNUNET_YES;
6346 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 6116 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
6347 &disconnect_all_neighbours, 6117 &disconnect_all_neighbours, NULL);
6348 NULL);
6349#if DEBUG_TRANSPORT 6118#if DEBUG_TRANSPORT
6350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6351 "Transport service is unloading plugins...\n"); 6120 "Transport service is unloading plugins...\n");
6352#endif 6121#endif
6353 while (NULL != (plug = plugins)) 6122 while (NULL != (plug = plugins))
6123 {
6124 if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK)
6354 { 6125 {
6355 if (plug->address_update_task != GNUNET_SCHEDULER_NO_TASK) 6126 GNUNET_SCHEDULER_cancel (plug->address_update_task);
6356 { 6127 plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
6357 GNUNET_SCHEDULER_cancel (plug->address_update_task);
6358 plug->address_update_task = GNUNET_SCHEDULER_NO_TASK;
6359 }
6360 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
6361 GNUNET_free (plug->lib_name);
6362 GNUNET_free (plug->short_name);
6363 while (NULL != (al = plug->addresses))
6364 {
6365 plug->addresses = al->next;
6366 GNUNET_free (al);
6367 }
6368 plugins = plug->next;
6369 GNUNET_free (plug);
6370 } 6128 }
6129 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
6130 GNUNET_free (plug->lib_name);
6131 GNUNET_free (plug->short_name);
6132 while (NULL != (al = plug->addresses))
6133 {
6134 plug->addresses = al->next;
6135 GNUNET_free (al);
6136 }
6137 plugins = plug->next;
6138 GNUNET_free (plug);
6139 }
6371 if (my_private_key != NULL) 6140 if (my_private_key != NULL)
6372 GNUNET_CRYPTO_rsa_key_free (my_private_key); 6141 GNUNET_CRYPTO_rsa_key_free (my_private_key);
6373 GNUNET_free_non_null (our_hello); 6142 GNUNET_free_non_null (our_hello);
6374 6143
6375 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 6144 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
6376 &abort_validation, 6145 &abort_validation, NULL);
6377 NULL);
6378 GNUNET_CONTAINER_multihashmap_destroy (validation_map); 6146 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6379 validation_map = NULL; 6147 validation_map = NULL;
6380 6148
6381 6149
6382 if (ats_task != GNUNET_SCHEDULER_NO_TASK) 6150 if (ats_task != GNUNET_SCHEDULER_NO_TASK)
6383 { 6151 {
6384 GNUNET_SCHEDULER_cancel(ats_task); 6152 GNUNET_SCHEDULER_cancel (ats_task);
6385 ats_task = GNUNET_SCHEDULER_NO_TASK; 6153 ats_task = GNUNET_SCHEDULER_NO_TASK;
6386 } 6154 }
6387#if HAVE_LIBGLPK 6155#if HAVE_LIBGLPK
@@ -6391,41 +6159,41 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6391 6159
6392 /* free 'chvc' data structure */ 6160 /* free 'chvc' data structure */
6393 while (NULL != (chvc = chvc_head)) 6161 while (NULL != (chvc = chvc_head))
6162 {
6163 chvc_head = chvc->next;
6164 if (chvc->piter != NULL)
6394 { 6165 {
6395 chvc_head = chvc->next; 6166 GNUNET_PEERINFO_iterate_cancel (chvc->piter);
6396 if (chvc->piter != NULL) 6167 GNUNET_STATISTICS_update (stats,
6397 { 6168 gettext_noop
6398 GNUNET_PEERINFO_iterate_cancel (chvc->piter); 6169 ("# outstanding peerinfo iterate requests"), -1,
6399 GNUNET_STATISTICS_update (stats, 6170 GNUNET_NO);
6400 gettext_noop ("# outstanding peerinfo iterate requests"), 6171 chvc->ve_count--;
6401 -1,
6402 GNUNET_NO);
6403 chvc->ve_count --;
6404 }
6405 else
6406 GNUNET_break (0);
6407 GNUNET_assert (chvc->ve_count == 0);
6408 GNUNET_free (chvc);
6409 } 6172 }
6173 else
6174 GNUNET_break (0);
6175 GNUNET_assert (chvc->ve_count == 0);
6176 GNUNET_free (chvc);
6177 }
6410 chvc_tail = NULL; 6178 chvc_tail = NULL;
6411 6179
6412 if (stats != NULL) 6180 if (stats != NULL)
6413 { 6181 {
6414 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 6182 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6415 stats = NULL; 6183 stats = NULL;
6416 } 6184 }
6417 if (peerinfo != NULL) 6185 if (peerinfo != NULL)
6418 { 6186 {
6419 GNUNET_PEERINFO_disconnect (peerinfo); 6187 GNUNET_PEERINFO_disconnect (peerinfo);
6420 peerinfo = NULL; 6188 peerinfo = NULL;
6421 } 6189 }
6422 if (GNUNET_SCHEDULER_NO_TASK != hello_task) 6190 if (GNUNET_SCHEDULER_NO_TASK != hello_task)
6423 { 6191 {
6424 GNUNET_SCHEDULER_cancel (hello_task); 6192 GNUNET_SCHEDULER_cancel (hello_task);
6425 hello_task = GNUNET_SCHEDULER_NO_TASK; 6193 hello_task = GNUNET_SCHEDULER_NO_TASK;
6426 } 6194 }
6427 /* Can we assume those are gone by now, or do we need to clean up 6195 /* Can we assume those are gone by now, or do we need to clean up
6428 explicitly!? */ 6196 * explicitly!? */
6429 GNUNET_break (bl_head == NULL); 6197 GNUNET_break (bl_head == NULL);
6430 GNUNET_break (bc_head == NULL); 6198 GNUNET_break (bc_head == NULL);
6431 GNUNET_CONTAINER_multihashmap_destroy (neighbours); 6199 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
@@ -6433,17 +6201,17 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6433} 6201}
6434 6202
6435 6203
6436void ats_result_cb () 6204void
6205ats_result_cb ()
6437{ 6206{
6438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n");
6439 "ATS Result callback\n");
6440} 6208}
6441 6209
6442 6210
6443#if HAVE_LIBGLPK 6211#if HAVE_LIBGLPK
6444struct AtsBuildContext 6212struct AtsBuildContext
6445{ 6213{
6446 struct ATS_mechanism * mechanisms; 6214 struct ATS_mechanism *mechanisms;
6447 struct ATS_peer *peers; 6215 struct ATS_peer *peers;
6448 int c_peers; 6216 int c_peers;
6449 int c_mechs; 6217 int c_mechs;
@@ -6451,70 +6219,70 @@ struct AtsBuildContext
6451 6219
6452 6220
6453static int 6221static int
6454find_and_count_addresses (void *cls, 6222find_and_count_addresses (void *cls, const GNUNET_HashCode * key, void *value)
6455 const GNUNET_HashCode *key,
6456 void *value)
6457{ 6223{
6458 struct AtsBuildContext *abc = cls; 6224 struct AtsBuildContext *abc = cls;
6459 struct NeighbourMapEntry *next = value; 6225 struct NeighbourMapEntry *next = value;
6460 int found_addresses = GNUNET_NO; 6226 int found_addresses = GNUNET_NO;
6461 6227
6462 struct ReadyList *r_next = next->plugins; 6228 struct ReadyList *r_next = next->plugins;
6229
6463 while (r_next != NULL) 6230 while (r_next != NULL)
6231 {
6232 struct ForeignAddressList *a_next = r_next->addresses;
6233
6234 while (a_next != NULL)
6464 { 6235 {
6465 struct ForeignAddressList * a_next = r_next->addresses; 6236 abc->c_mechs++;
6466 while (a_next != NULL) 6237 found_addresses = GNUNET_YES;
6467 { 6238 a_next = a_next->next;
6468 abc->c_mechs++;
6469 found_addresses = GNUNET_YES;
6470 a_next = a_next->next;
6471 }
6472 r_next = r_next->next;
6473 } 6239 }
6474 if (found_addresses) 6240 r_next = r_next->next;
6241 }
6242 if (found_addresses)
6475 abc->c_peers++; 6243 abc->c_peers++;
6476 return GNUNET_OK; 6244 return GNUNET_OK;
6477} 6245}
6478 6246
6479 6247
6480static int 6248static int
6481setup_ats_problem (void *cls, 6249setup_ats_problem (void *cls, const GNUNET_HashCode * key, void *value)
6482 const GNUNET_HashCode *key,
6483 void *value)
6484{ 6250{
6485 struct AtsBuildContext *abc = cls; 6251 struct AtsBuildContext *abc = cls;
6486 struct NeighbourMapEntry *next = value; 6252 struct NeighbourMapEntry *next = value;
6487 6253
6488 int found_addresses = GNUNET_NO; 6254 int found_addresses = GNUNET_NO;
6489 struct ReadyList *r_next = next->plugins; 6255 struct ReadyList *r_next = next->plugins;
6256
6490 while (r_next != NULL) 6257 while (r_next != NULL)
6258 {
6259 struct ForeignAddressList *a_next = r_next->addresses;
6260
6261 while (a_next != NULL)
6491 { 6262 {
6492 struct ForeignAddressList * a_next = r_next->addresses; 6263 if (found_addresses == GNUNET_NO)
6493 while (a_next != NULL) 6264 {
6494 { 6265 abc->peers[abc->c_peers].peer = next->id;
6495 if (found_addresses == GNUNET_NO) 6266 abc->peers[abc->c_peers].m_head = NULL;
6496 { 6267 abc->peers[abc->c_peers].m_tail = NULL;
6497 abc->peers[abc->c_peers].peer = next->id; 6268 abc->peers[abc->c_peers].f = 1.0 / abc->c_mechs;
6498 abc->peers[abc->c_peers].m_head = NULL; 6269 }
6499 abc->peers[abc->c_peers].m_tail = NULL; 6270 abc->mechanisms[abc->c_mechs].addr = a_next;
6500 abc->peers[abc->c_peers].f = 1.0 / abc->c_mechs; 6271 abc->mechanisms[abc->c_mechs].col_index = abc->c_mechs;
6501 } 6272 abc->mechanisms[abc->c_mechs].peer = &abc->peers[abc->c_peers];
6502 abc->mechanisms[abc->c_mechs].addr = a_next; 6273 abc->mechanisms[abc->c_mechs].next = NULL;
6503 abc->mechanisms[abc->c_mechs].col_index = abc->c_mechs; 6274 abc->mechanisms[abc->c_mechs].plugin = r_next->plugin;
6504 abc->mechanisms[abc->c_mechs].peer = &abc->peers[abc->c_peers]; 6275 abc->mechanisms[abc->c_mechs].ressources = a_next->ressources;
6505 abc->mechanisms[abc->c_mechs].next = NULL; 6276 abc->mechanisms[abc->c_mechs].quality = a_next->quality;
6506 abc->mechanisms[abc->c_mechs].plugin = r_next->plugin; 6277 GNUNET_CONTAINER_DLL_insert_tail (abc->peers[abc->c_peers].m_head,
6507 abc->mechanisms[abc->c_mechs].ressources = a_next->ressources; 6278 abc->peers[abc->c_peers].m_tail,
6508 abc->mechanisms[abc->c_mechs].quality = a_next->quality; 6279 &abc->mechanisms[abc->c_mechs]);
6509 GNUNET_CONTAINER_DLL_insert_tail(abc->peers[abc->c_peers].m_head, 6280 found_addresses = GNUNET_YES;
6510 abc->peers[abc->c_peers].m_tail, 6281 abc->c_mechs++;
6511 &abc->mechanisms[abc->c_mechs]); 6282 a_next = a_next->next;
6512 found_addresses = GNUNET_YES; 6283 }
6513 abc->c_mechs++; 6284 r_next = r_next->next;
6514 a_next = a_next->next; 6285 }
6515 }
6516 r_next = r_next->next;
6517 }
6518 if (found_addresses == GNUNET_YES) 6286 if (found_addresses == GNUNET_YES)
6519 abc->c_peers++; 6287 abc->c_peers++;
6520 return GNUNET_OK; 6288 return GNUNET_OK;
@@ -6522,43 +6290,40 @@ setup_ats_problem (void *cls,
6522 6290
6523 6291
6524static void 6292static void
6525create_ats_information ( struct ATS_peer **p, 6293create_ats_information (struct ATS_peer **p,
6526 int * c_p, 6294 int *c_p, struct ATS_mechanism **m, int *c_m)
6527 struct ATS_mechanism ** m,
6528 int * c_m )
6529{ 6295{
6530 struct AtsBuildContext abc; 6296 struct AtsBuildContext abc;
6531 6297
6532#if VERBOSE_ATS 6298#if VERBOSE_ATS
6533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6534 "ATS requires clean address information\n"); 6300 "ATS requires clean address information\n");
6535#endif 6301#endif
6536 abc.c_peers = 0; 6302 abc.c_peers = 0;
6537 abc.c_mechs = 0; 6303 abc.c_mechs = 0;
6538 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 6304 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
6539 &find_and_count_addresses, 6305 &find_and_count_addresses, &abc);
6540 &abc);
6541#if VERBOSE_ATS 6306#if VERBOSE_ATS
6542 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6543 "Found %u peers with % u transport mechanisms\n", c_peers, c_mechs); 6308 "Found %u peers with % u transport mechanisms\n", c_peers,
6309 c_mechs);
6544#endif 6310#endif
6545 6311
6546 if ( (abc.c_peers == 0) && (abc.c_mechs == 0) ) 6312 if ((abc.c_peers == 0) && (abc.c_mechs == 0))
6547 { 6313 {
6548 *p = NULL; 6314 *p = NULL;
6549 (*c_p) = 0; 6315 (*c_p) = 0;
6550 *m = NULL; 6316 *m = NULL;
6551 (*c_m) = 0; 6317 (*c_m) = 0;
6552 return; 6318 return;
6553 } 6319 }
6554 6320
6555 abc.mechanisms = GNUNET_malloc((1+abc.c_mechs) * sizeof (struct ATS_mechanism)); 6321 abc.mechanisms =
6556 abc.peers = GNUNET_malloc((1+abc.c_peers) * sizeof (struct ATS_peer)); 6322 GNUNET_malloc ((1 + abc.c_mechs) * sizeof (struct ATS_mechanism));
6323 abc.peers = GNUNET_malloc ((1 + abc.c_peers) * sizeof (struct ATS_peer));
6557 abc.c_mechs = 1; 6324 abc.c_mechs = 1;
6558 abc.c_peers = 1; 6325 abc.c_peers = 1;
6559 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 6326 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &setup_ats_problem, &abc);
6560 &setup_ats_problem,
6561 &abc);
6562 abc.c_mechs--; 6327 abc.c_mechs--;
6563 abc.c_peers--; 6328 abc.c_peers--;
6564 (*c_m) = abc.c_mechs; 6329 (*c_m) = abc.c_mechs;
@@ -6569,27 +6334,29 @@ create_ats_information ( struct ATS_peer **p,
6569 6334
6570 6335
6571static void 6336static void
6572schedule_ats (void *cls, 6337schedule_ats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
6573 const struct GNUNET_SCHEDULER_TaskContext *tc)
6574{ 6338{
6575 struct ATS_Handle *ats = (struct ATS_Handle *) cls; 6339 struct ATS_Handle *ats = (struct ATS_Handle *) cls;
6576 if (ats==NULL) 6340
6341 if (ats == NULL)
6577 return; 6342 return;
6578 6343
6579 ats_task = GNUNET_SCHEDULER_NO_TASK; 6344 ats_task = GNUNET_SCHEDULER_NO_TASK;
6580 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 6345 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
6581 return; 6346 return;
6582 6347
6583 if (shutdown_in_progress == GNUNET_YES) 6348 if (shutdown_in_progress == GNUNET_YES)
6584 return; 6349 return;
6585 6350
6586 struct GNUNET_TIME_Relative delta = 6351 struct GNUNET_TIME_Relative delta =
6587 GNUNET_TIME_absolute_get_difference (last_ats_execution, GNUNET_TIME_absolute_get()); 6352 GNUNET_TIME_absolute_get_difference (last_ats_execution,
6353 GNUNET_TIME_absolute_get ());
6354
6588 if (delta.rel_value < ats_minimum_interval.rel_value) 6355 if (delta.rel_value < ats_minimum_interval.rel_value)
6589 { 6356 {
6590#if DEBUG_ATS 6357#if DEBUG_ATS
6591 GNUNET_log (GNUNET_ERROR_TYPE_BULK, 6358 GNUNET_log (GNUNET_ERROR_TYPE_BULK,
6592 "Minimum time between cycles not reached\n"); 6359 "Minimum time between cycles not reached\n");
6593#endif 6360#endif
6594 return; 6361 return;
6595 } 6362 }
@@ -6600,19 +6367,19 @@ schedule_ats (void *cls,
6600#if HAVE_LIBGLPK 6367#if HAVE_LIBGLPK
6601 ats_calculate_bandwidth_distribution (ats); 6368 ats_calculate_bandwidth_distribution (ats);
6602#endif 6369#endif
6603 last_ats_execution = GNUNET_TIME_absolute_get(); 6370 last_ats_execution = GNUNET_TIME_absolute_get ();
6604 6371
6605 ats_task = GNUNET_SCHEDULER_add_delayed (ats_regular_interval, 6372 ats_task = GNUNET_SCHEDULER_add_delayed (ats_regular_interval,
6606 &schedule_ats, ats); 6373 &schedule_ats, ats);
6607} 6374}
6608#endif 6375#endif
6609 6376
6610 6377
6611struct ForeignAddressList * get_preferred_ats_address ( 6378struct ForeignAddressList *
6612 struct NeighbourMapEntry *n) 6379get_preferred_ats_address (struct NeighbourMapEntry *n)
6613{ 6380{
6614 // TODO get ATS prefered address 6381 // TODO get ATS prefered address
6615 return find_ready_address(n); 6382 return find_ready_address (n);
6616} 6383}
6617 6384
6618/** 6385/**
@@ -6635,7 +6402,8 @@ run (void *cls,
6635 {&handle_send, NULL, 6402 {&handle_send, NULL,
6636 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0}, 6403 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
6637 {&handle_request_connect, NULL, 6404 {&handle_request_connect, NULL,
6638 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof(struct TransportRequestConnectMessage)}, 6405 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
6406 sizeof (struct TransportRequestConnectMessage)},
6639 {&handle_set_quota, NULL, 6407 {&handle_set_quota, NULL,
6640 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)}, 6408 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
6641 {&handle_address_lookup, NULL, 6409 {&handle_address_lookup, NULL,
@@ -6648,9 +6416,11 @@ run (void *cls,
6648 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, 6416 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
6649 0}, 6417 0},
6650 {&handle_blacklist_init, NULL, 6418 {&handle_blacklist_init, NULL,
6651 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, 6419 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
6420 sizeof (struct GNUNET_MessageHeader)},
6652 {&handle_blacklist_reply, NULL, 6421 {&handle_blacklist_reply, NULL,
6653 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct BlacklistMessage)}, 6422 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
6423 sizeof (struct BlacklistMessage)},
6654 {NULL, NULL, 0, 0} 6424 {NULL, NULL, 0, 0}
6655 }; 6425 };
6656 char *plugs; 6426 char *plugs;
@@ -6674,61 +6444,60 @@ run (void *cls,
6674 GNUNET_CONFIGURATION_get_value_filename (c, 6444 GNUNET_CONFIGURATION_get_value_filename (c,
6675 "GNUNETD", 6445 "GNUNETD",
6676 "HOSTKEY", &keyfile))) 6446 "HOSTKEY", &keyfile)))
6447 {
6448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6449 _
6450 ("Transport service is lacking key configuration settings. Exiting.\n"));
6451 GNUNET_SCHEDULER_shutdown ();
6452 if (stats != NULL)
6677 { 6453 {
6678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6454 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6679 _ 6455 stats = NULL;
6680 ("Transport service is lacking key configuration settings. Exiting.\n"));
6681 GNUNET_SCHEDULER_shutdown ();
6682 if (stats != NULL)
6683 {
6684 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6685 stats = NULL;
6686 }
6687 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6688 validation_map = NULL;
6689 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
6690 neighbours = NULL;
6691 return;
6692 } 6456 }
6457 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6458 validation_map = NULL;
6459 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
6460 neighbours = NULL;
6461 return;
6462 }
6693 6463
6694 max_connect_per_transport = (uint32_t) tneigh; 6464 max_connect_per_transport = (uint32_t) tneigh;
6695 peerinfo = GNUNET_PEERINFO_connect (cfg); 6465 peerinfo = GNUNET_PEERINFO_connect (cfg);
6696 if (peerinfo == NULL) 6466 if (peerinfo == NULL)
6467 {
6468 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6469 _("Could not access PEERINFO service. Exiting.\n"));
6470 GNUNET_SCHEDULER_shutdown ();
6471 if (stats != NULL)
6697 { 6472 {
6698 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6473 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6699 _("Could not access PEERINFO service. Exiting.\n")); 6474 stats = NULL;
6700 GNUNET_SCHEDULER_shutdown ();
6701 if (stats != NULL)
6702 {
6703 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6704 stats = NULL;
6705 }
6706 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6707 validation_map = NULL;
6708 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
6709 neighbours = NULL;
6710 GNUNET_free (keyfile);
6711 return;
6712 } 6475 }
6476 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6477 validation_map = NULL;
6478 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
6479 neighbours = NULL;
6480 GNUNET_free (keyfile);
6481 return;
6482 }
6713 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 6483 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
6714 GNUNET_free (keyfile); 6484 GNUNET_free (keyfile);
6715 if (my_private_key == NULL) 6485 if (my_private_key == NULL)
6486 {
6487 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6488 _("Transport service could not access hostkey. Exiting.\n"));
6489 GNUNET_SCHEDULER_shutdown ();
6490 if (stats != NULL)
6716 { 6491 {
6717 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6492 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6718 _ 6493 stats = NULL;
6719 ("Transport service could not access hostkey. Exiting.\n"));
6720 GNUNET_SCHEDULER_shutdown ();
6721 if (stats != NULL)
6722 {
6723 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
6724 stats = NULL;
6725 }
6726 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6727 validation_map = NULL;
6728 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
6729 neighbours = NULL;
6730 return;
6731 } 6494 }
6495 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
6496 validation_map = NULL;
6497 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
6498 neighbours = NULL;
6499 return;
6500 }
6732 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 6501 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
6733 GNUNET_CRYPTO_hash (&my_public_key, 6502 GNUNET_CRYPTO_hash (&my_public_key,
6734 sizeof (my_public_key), &my_identity.hashPubKey); 6503 sizeof (my_public_key), &my_identity.hashPubKey);
@@ -6738,20 +6507,19 @@ run (void *cls,
6738 /* load plugins... */ 6507 /* load plugins... */
6739 no_transports = 1; 6508 no_transports = 1;
6740 if (GNUNET_OK == 6509 if (GNUNET_OK ==
6741 GNUNET_CONFIGURATION_get_value_string (c, 6510 GNUNET_CONFIGURATION_get_value_string (c, "TRANSPORT", "PLUGINS", &plugs))
6742 "TRANSPORT", "PLUGINS", &plugs)) 6511 {
6512 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
6513 _("Starting transport plugins `%s'\n"), plugs);
6514 pos = strtok (plugs, " ");
6515 while (pos != NULL)
6743 { 6516 {
6744 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6517 start_transport (server, pos);
6745 _("Starting transport plugins `%s'\n"), plugs); 6518 no_transports = 0;
6746 pos = strtok (plugs, " "); 6519 pos = strtok (NULL, " ");
6747 while (pos != NULL)
6748 {
6749 start_transport (server, pos);
6750 no_transports = 0;
6751 pos = strtok (NULL, " ");
6752 }
6753 GNUNET_free (plugs);
6754 } 6520 }
6521 GNUNET_free (plugs);
6522 }
6755 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 6523 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
6756 &shutdown_task, NULL); 6524 &shutdown_task, NULL);
6757 if (no_transports) 6525 if (no_transports)
@@ -6759,8 +6527,9 @@ run (void *cls,
6759 6527
6760 /* Initializing ATS */ 6528 /* Initializing ATS */
6761 int co; 6529 int co;
6762 char * section; 6530 char *section;
6763 unsigned long long value; 6531 unsigned long long value;
6532
6764#if HAVE_LIBGLPK 6533#if HAVE_LIBGLPK
6765 double D = 1.0; 6534 double D = 1.0;
6766 double U = 1.0; 6535 double U = 1.0;
@@ -6773,39 +6542,35 @@ run (void *cls,
6773 ats_regular_interval = ATS_EXEC_INTERVAL; 6542 ats_regular_interval = ATS_EXEC_INTERVAL;
6774 6543
6775 /* loading cost ressources */ 6544 /* loading cost ressources */
6776 for (co=0; co<available_ressources; co++) 6545 for (co = 0; co < available_ressources; co++)
6777 { 6546 {
6778 GNUNET_asprintf(&section,"%s_UP",ressources[co].cfg_param); 6547 GNUNET_asprintf (&section, "%s_UP", ressources[co].cfg_param);
6779 if (GNUNET_CONFIGURATION_have_value(cfg, "transport", section)) 6548 if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section))
6780 { 6549 {
6781 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, 6550 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg,
6782 "transport", 6551 "transport",
6783 section, 6552 section, &value))
6784 &value))
6785 { 6553 {
6786#if DEBUG_ATS 6554#if DEBUG_ATS
6787 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6555 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6788 "Found ressource cost: [%s] = %llu\n", 6556 "Found ressource cost: [%s] = %llu\n", section, value);
6789 section, value);
6790#endif 6557#endif
6791 ressources[co].c_max = value; 6558 ressources[co].c_max = value;
6792 } 6559 }
6793 } 6560 }
6794 GNUNET_free (section); 6561 GNUNET_free (section);
6795 GNUNET_asprintf(&section,"%s_DOWN",ressources[co].cfg_param); 6562 GNUNET_asprintf (&section, "%s_DOWN", ressources[co].cfg_param);
6796 if (GNUNET_CONFIGURATION_have_value(cfg, "transport", section)) 6563 if (GNUNET_CONFIGURATION_have_value (cfg, "transport", section))
6797 { 6564 {
6798 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, 6565 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (cfg,
6799 "transport", 6566 "transport",
6800 section, 6567 section, &value))
6801 &value))
6802 { 6568 {
6803#if DEBUG_ATS 6569#if DEBUG_ATS
6804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 6570 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
6805 "Found ressource cost: [%s] = %llu\n", 6571 "Found ressource cost: [%s] = %llu\n", section, value);
6806 section, value);
6807#endif 6572#endif
6808 ressources[co].c_min = value; 6573 ressources[co].c_min = value;
6809 } 6574 }
6810 } 6575 }
6811 GNUNET_free (section); 6576 GNUNET_free (section);
@@ -6813,32 +6578,28 @@ run (void *cls,
6813#if HAVE_LIBGLPK 6578#if HAVE_LIBGLPK
6814 ats = ats_init (D, U, R, v_b_min, v_n_min, 6579 ats = ats_init (D, U, R, v_b_min, v_n_min,
6815 ATS_MAX_ITERATIONS, ATS_MAX_EXEC_DURATION, 6580 ATS_MAX_ITERATIONS, ATS_MAX_EXEC_DURATION,
6816 &create_ats_information, 6581 &create_ats_information, ats_result_cb);
6817 ats_result_cb); 6582 ats_set_logging_options (ats, stats, cfg);
6818 ats_set_logging_options (ats,
6819 stats,
6820 cfg);
6821 GNUNET_break (GNUNET_OK == 6583 GNUNET_break (GNUNET_OK ==
6822 GNUNET_CONFIGURATION_get_value_time (cfg, 6584 GNUNET_CONFIGURATION_get_value_time (cfg,
6823 "transport", 6585 "transport",
6824 "ATS_EXEC_INTERVAL", 6586 "ATS_EXEC_INTERVAL",
6825 &ats_regular_interval)); 6587 &ats_regular_interval));
6826 GNUNET_break (GNUNET_OK == 6588 GNUNET_break (GNUNET_OK ==
6827 GNUNET_CONFIGURATION_get_value_time (cfg, 6589 GNUNET_CONFIGURATION_get_value_time (cfg,
6828 "transport", 6590 "transport",
6829 "ATS_MIN_INTERVAL", 6591 "ATS_MIN_INTERVAL",
6830 &ats_minimum_interval)); 6592 &ats_minimum_interval));
6831 if (ats != NULL) 6593 if (ats != NULL)
6832 ats_task = GNUNET_SCHEDULER_add_now (&schedule_ats, ats); 6594 ats_task = GNUNET_SCHEDULER_add_now (&schedule_ats, ats);
6833#endif 6595#endif
6834 6596
6835 6597
6836#if DEBUG_TRANSPORT 6598#if DEBUG_TRANSPORT
6837 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6599 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport service ready.\n"));
6838 _("Transport service ready.\n"));
6839#endif 6600#endif
6840 /* If we have a blacklist file, read from it */ 6601 /* If we have a blacklist file, read from it */
6841 read_blacklist_file(cfg); 6602 read_blacklist_file (cfg);
6842 /* process client requests */ 6603 /* process client requests */
6843 GNUNET_SERVER_add_handlers (server, handlers); 6604 GNUNET_SERVER_add_handlers (server, handlers);
6844} 6605}
@@ -6854,13 +6615,12 @@ run (void *cls,
6854int 6615int
6855main (int argc, char *const *argv) 6616main (int argc, char *const *argv)
6856{ 6617{
6857 a2s (NULL, NULL, 0); /* make compiler happy */ 6618 a2s (NULL, NULL, 0); /* make compiler happy */
6858 return (GNUNET_OK == 6619 return (GNUNET_OK ==
6859 GNUNET_SERVICE_run (argc, 6620 GNUNET_SERVICE_run (argc,
6860 argv, 6621 argv,
6861 "transport", 6622 "transport",
6862 GNUNET_SERVICE_OPTION_NONE, 6623 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
6863 &run, NULL)) ? 0 : 1;
6864} 6624}
6865 6625
6866/* end of gnunet-service-transport.c */ 6626/* end of gnunet-service-transport.c */
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index df425bfb0..34d1791b9 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -41,133 +41,136 @@
41 41
42#ifndef GLP_PROB_DEFINED 42#ifndef GLP_PROB_DEFINED
43#define GLP_PROB_DEFINED 43#define GLP_PROB_DEFINED
44 typedef struct { double _opaque_prob[100]; } glp_prob; 44typedef struct
45{
46 double _opaque_prob[100];
47} glp_prob;
45#endif 48#endif
46 49
47typedef struct 50typedef struct
48{ /* integer optimizer control parameters */ 51{ /* integer optimizer control parameters */
49 int msg_lev; /* message level (see glp_smcp) */ 52 int msg_lev; /* message level (see glp_smcp) */
50 int br_tech; /* branching technique: */ 53 int br_tech; /* branching technique: */
51#define GLP_BR_FFV 1 /* first fractional variable */ 54#define GLP_BR_FFV 1 /* first fractional variable */
52#define GLP_BR_LFV 2 /* last fractional variable */ 55#define GLP_BR_LFV 2 /* last fractional variable */
53#define GLP_BR_MFV 3 /* most fractional variable */ 56#define GLP_BR_MFV 3 /* most fractional variable */
54#define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */ 57#define GLP_BR_DTH 4 /* heuristic by Driebeck and Tomlin */
55#define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */ 58#define GLP_BR_PCH 5 /* hybrid pseudocost heuristic */
56 int bt_tech; /* backtracking technique: */ 59 int bt_tech; /* backtracking technique: */
57#define GLP_BT_DFS 1 /* depth first search */ 60#define GLP_BT_DFS 1 /* depth first search */
58#define GLP_BT_BFS 2 /* breadth first search */ 61#define GLP_BT_BFS 2 /* breadth first search */
59#define GLP_BT_BLB 3 /* best local bound */ 62#define GLP_BT_BLB 3 /* best local bound */
60#define GLP_BT_BPH 4 /* best projection heuristic */ 63#define GLP_BT_BPH 4 /* best projection heuristic */
61 double tol_int; /* mip.tol_int */ 64 double tol_int; /* mip.tol_int */
62 double tol_obj; /* mip.tol_obj */ 65 double tol_obj; /* mip.tol_obj */
63 int tm_lim; /* mip.tm_lim (milliseconds) */ 66 int tm_lim; /* mip.tm_lim (milliseconds) */
64 int out_frq; /* mip.out_frq (milliseconds) */ 67 int out_frq; /* mip.out_frq (milliseconds) */
65 int out_dly; /* mip.out_dly (milliseconds) */ 68 int out_dly; /* mip.out_dly (milliseconds) */
66 /* mip.cb_func */ 69 /* mip.cb_func */
67 void *cb_info; /* mip.cb_info */ 70 void *cb_info; /* mip.cb_info */
68 int cb_size; /* mip.cb_size */ 71 int cb_size; /* mip.cb_size */
69 int pp_tech; /* preprocessing technique: */ 72 int pp_tech; /* preprocessing technique: */
70#define GLP_PP_NONE 0 /* disable preprocessing */ 73#define GLP_PP_NONE 0 /* disable preprocessing */
71#define GLP_PP_ROOT 1 /* preprocessing only on root level */ 74#define GLP_PP_ROOT 1 /* preprocessing only on root level */
72#define GLP_PP_ALL 2 /* preprocessing on all levels */ 75#define GLP_PP_ALL 2 /* preprocessing on all levels */
73 double mip_gap; /* relative MIP gap tolerance */ 76 double mip_gap; /* relative MIP gap tolerance */
74 int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */ 77 int mir_cuts; /* MIR cuts (GLP_ON/GLP_OFF) */
75 int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */ 78 int gmi_cuts; /* Gomory's cuts (GLP_ON/GLP_OFF) */
76 int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */ 79 int cov_cuts; /* cover cuts (GLP_ON/GLP_OFF) */
77 int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */ 80 int clq_cuts; /* clique cuts (GLP_ON/GLP_OFF) */
78 int presolve; /* enable/disable using MIP presolver */ 81 int presolve; /* enable/disable using MIP presolver */
79 int binarize; /* try to binarize integer variables */ 82 int binarize; /* try to binarize integer variables */
80 int fp_heur; /* feasibility pump heuristic */ 83 int fp_heur; /* feasibility pump heuristic */
81#if 1 /* 28/V-2010 */ 84#if 1 /* 28/V-2010 */
82 int alien; /* use alien solver */ 85 int alien; /* use alien solver */
83#endif 86#endif
84 double foo_bar[29]; /* (reserved) */ 87 double foo_bar[29]; /* (reserved) */
85} glp_iocp; 88} glp_iocp;
86 89
87typedef struct 90typedef struct
88{ /* simplex method control parameters */ 91{ /* simplex method control parameters */
89 int msg_lev; /* message level: */ 92 int msg_lev; /* message level: */
90#define GLP_MSG_OFF 0 /* no output */ 93#define GLP_MSG_OFF 0 /* no output */
91#define GLP_MSG_ERR 1 /* warning and error messages only */ 94#define GLP_MSG_ERR 1 /* warning and error messages only */
92#define GLP_MSG_ON 2 /* normal output */ 95#define GLP_MSG_ON 2 /* normal output */
93#define GLP_MSG_ALL 3 /* full output */ 96#define GLP_MSG_ALL 3 /* full output */
94#define GLP_MSG_DBG 4 /* debug output */ 97#define GLP_MSG_DBG 4 /* debug output */
95 int meth; /* simplex method option: */ 98 int meth; /* simplex method option: */
96#define GLP_PRIMAL 1 /* use primal simplex */ 99#define GLP_PRIMAL 1 /* use primal simplex */
97#define GLP_DUALP 2 /* use dual; if it fails, use primal */ 100#define GLP_DUALP 2 /* use dual; if it fails, use primal */
98#define GLP_DUAL 3 /* use dual simplex */ 101#define GLP_DUAL 3 /* use dual simplex */
99 int pricing; /* pricing technique: */ 102 int pricing; /* pricing technique: */
100#define GLP_PT_STD 0x11 /* standard (Dantzig rule) */ 103#define GLP_PT_STD 0x11 /* standard (Dantzig rule) */
101#define GLP_PT_PSE 0x22 /* projected steepest edge */ 104#define GLP_PT_PSE 0x22 /* projected steepest edge */
102 int r_test; /* ratio test technique: */ 105 int r_test; /* ratio test technique: */
103#define GLP_RT_STD 0x11 /* standard (textbook) */ 106#define GLP_RT_STD 0x11 /* standard (textbook) */
104#define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */ 107#define GLP_RT_HAR 0x22 /* two-pass Harris' ratio test */
105 double tol_bnd; /* spx.tol_bnd */ 108 double tol_bnd; /* spx.tol_bnd */
106 double tol_dj; /* spx.tol_dj */ 109 double tol_dj; /* spx.tol_dj */
107 double tol_piv; /* spx.tol_piv */ 110 double tol_piv; /* spx.tol_piv */
108 double obj_ll; /* spx.obj_ll */ 111 double obj_ll; /* spx.obj_ll */
109 double obj_ul; /* spx.obj_ul */ 112 double obj_ul; /* spx.obj_ul */
110 int it_lim; /* spx.it_lim */ 113 int it_lim; /* spx.it_lim */
111 int tm_lim; /* spx.tm_lim (milliseconds) */ 114 int tm_lim; /* spx.tm_lim (milliseconds) */
112 int out_frq; /* spx.out_frq */ 115 int out_frq; /* spx.out_frq */
113 int out_dly; /* spx.out_dly (milliseconds) */ 116 int out_dly; /* spx.out_dly (milliseconds) */
114 int presolve; /* enable/disable using LP presolver */ 117 int presolve; /* enable/disable using LP presolver */
115 double foo_bar[36]; /* (reserved) */ 118 double foo_bar[36]; /* (reserved) */
116} glp_smcp; 119} glp_smcp;
117 120
118/* optimization direction flag: */ 121/* optimization direction flag: */
119#define GLP_MIN 1 /* minimization */ 122#define GLP_MIN 1 /* minimization */
120#define GLP_MAX 2 /* maximization */ 123#define GLP_MAX 2 /* maximization */
121 124
122/* kind of structural variable: */ 125/* kind of structural variable: */
123#define GLP_CV 1 /* continuous variable */ 126#define GLP_CV 1 /* continuous variable */
124#define GLP_IV 2 /* integer variable */ 127#define GLP_IV 2 /* integer variable */
125#define GLP_BV 3 /* binary variable */ 128#define GLP_BV 3 /* binary variable */
126 129
127/* type of auxiliary/structural variable: */ 130/* type of auxiliary/structural variable: */
128#define GLP_FR 1 /* free variable */ 131#define GLP_FR 1 /* free variable */
129#define GLP_LO 2 /* variable with lower bound */ 132#define GLP_LO 2 /* variable with lower bound */
130#define GLP_UP 3 /* variable with upper bound */ 133#define GLP_UP 3 /* variable with upper bound */
131#define GLP_DB 4 /* double-bounded variable */ 134#define GLP_DB 4 /* double-bounded variable */
132#define GLP_FX 5 /* fixed variable */ 135#define GLP_FX 5 /* fixed variable */
133 136
134/* solution indicator: */ 137/* solution indicator: */
135#define GLP_SOL 1 /* basic solution */ 138#define GLP_SOL 1 /* basic solution */
136#define GLP_IPT 2 /* interior-point solution */ 139#define GLP_IPT 2 /* interior-point solution */
137#define GLP_MIP 3 /* mixed integer solution */ 140#define GLP_MIP 3 /* mixed integer solution */
138 141
139/* solution status: */ 142/* solution status: */
140#define GLP_UNDEF 1 /* solution is undefined */ 143#define GLP_UNDEF 1 /* solution is undefined */
141#define GLP_FEAS 2 /* solution is feasible */ 144#define GLP_FEAS 2 /* solution is feasible */
142#define GLP_INFEAS 3 /* solution is infeasible */ 145#define GLP_INFEAS 3 /* solution is infeasible */
143#define GLP_NOFEAS 4 /* no feasible solution exists */ 146#define GLP_NOFEAS 4 /* no feasible solution exists */
144#define GLP_OPT 5 /* solution is optimal */ 147#define GLP_OPT 5 /* solution is optimal */
145#define GLP_UNBND 6 /* solution is unbounded */ 148#define GLP_UNBND 6 /* solution is unbounded */
146 149
147/* return codes: */ 150/* return codes: */
148#define GLP_EBADB 0x01 /* invalid basis */ 151#define GLP_EBADB 0x01 /* invalid basis */
149#define GLP_ESING 0x02 /* singular matrix */ 152#define GLP_ESING 0x02 /* singular matrix */
150#define GLP_ECOND 0x03 /* ill-conditioned matrix */ 153#define GLP_ECOND 0x03 /* ill-conditioned matrix */
151#define GLP_EBOUND 0x04 /* invalid bounds */ 154#define GLP_EBOUND 0x04 /* invalid bounds */
152#define GLP_EFAIL 0x05 /* solver failed */ 155#define GLP_EFAIL 0x05 /* solver failed */
153#define GLP_EOBJLL 0x06 /* objective lower limit reached */ 156#define GLP_EOBJLL 0x06 /* objective lower limit reached */
154#define GLP_EOBJUL 0x07 /* objective upper limit reached */ 157#define GLP_EOBJUL 0x07 /* objective upper limit reached */
155#define GLP_EITLIM 0x08 /* iteration limit exceeded */ 158#define GLP_EITLIM 0x08 /* iteration limit exceeded */
156#define GLP_ETMLIM 0x09 /* time limit exceeded */ 159#define GLP_ETMLIM 0x09 /* time limit exceeded */
157#define GLP_ENOPFS 0x0A /* no primal feasible solution */ 160#define GLP_ENOPFS 0x0A /* no primal feasible solution */
158#define GLP_ENODFS 0x0B /* no dual feasible solution */ 161#define GLP_ENODFS 0x0B /* no dual feasible solution */
159#define GLP_EROOT 0x0C /* root LP optimum not provided */ 162#define GLP_EROOT 0x0C /* root LP optimum not provided */
160#define GLP_ESTOP 0x0D /* search terminated by application */ 163#define GLP_ESTOP 0x0D /* search terminated by application */
161#define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */ 164#define GLP_EMIPGAP 0x0E /* relative mip gap tolerance reached */
162#define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */ 165#define GLP_ENOFEAS 0x0F /* no primal/dual feasible solution */
163#define GLP_ENOCVG 0x10 /* no convergence */ 166#define GLP_ENOCVG 0x10 /* no convergence */
164#define GLP_EINSTAB 0x11 /* numerical instability */ 167#define GLP_EINSTAB 0x11 /* numerical instability */
165#define GLP_EDATA 0x12 /* invalid data */ 168#define GLP_EDATA 0x12 /* invalid data */
166#define GLP_ERANGE 0x13 /* result out of range */ 169#define GLP_ERANGE 0x13 /* result out of range */
167 170
168/* enable/disable flag: */ 171/* enable/disable flag: */
169#define GLP_ON 1 /* enable something */ 172#define GLP_ON 1 /* enable something */
170#define GLP_OFF 0 /* disable something */ 173#define GLP_OFF 0 /* disable something */
171 174
172#endif 175#endif
173 176
@@ -176,10 +179,11 @@ typedef struct
176 */ 179 */
177 180
178 181
179void * _lp_create_prob ( void ) 182void *
183_lp_create_prob (void)
180{ 184{
181#if HAVE_LIBGLPK 185#if HAVE_LIBGLPK
182 return glp_create_prob( ); 186 return glp_create_prob ();
183#else 187#else
184 // Function not implemented 188 // Function not implemented
185 GNUNET_break (0); 189 GNUNET_break (0);
@@ -187,7 +191,8 @@ void * _lp_create_prob ( void )
187 return NULL; 191 return NULL;
188} 192}
189 193
190void _lp_set_obj_dir (glp_prob *P, int dir) 194void
195_lp_set_obj_dir (glp_prob *P, int dir)
191{ 196{
192#if HAVE_LIBGLPK 197#if HAVE_LIBGLPK
193 return glp_set_obj_dir (P, dir); 198 return glp_set_obj_dir (P, dir);
@@ -197,20 +202,22 @@ void _lp_set_obj_dir (glp_prob *P, int dir)
197#endif 202#endif
198} 203}
199 204
200void _lp_set_prob_name (glp_prob *P, const char *name) 205void
206_lp_set_prob_name (glp_prob *P, const char *name)
201{ 207{
202#if HAVE_LIBGLPK 208#if HAVE_LIBGLPK
203 glp_set_prob_name(P, name); 209 glp_set_prob_name (P, name);
204#else 210#else
205 // Function not implemented 211 // Function not implemented
206 GNUNET_break (0); 212 GNUNET_break (0);
207#endif 213#endif
208} 214}
209 215
210int _lp_add_cols (glp_prob *P, int ncs) 216int
217_lp_add_cols (glp_prob *P, int ncs)
211{ 218{
212#if HAVE_LIBGLPK 219#if HAVE_LIBGLPK
213 return glp_add_cols(P, ncs); 220 return glp_add_cols (P, ncs);
214#else 221#else
215 // Function not implemented 222 // Function not implemented
216 GNUNET_break (0); 223 GNUNET_break (0);
@@ -218,7 +225,8 @@ int _lp_add_cols (glp_prob *P, int ncs)
218 return 0; 225 return 0;
219} 226}
220 227
221int _lp_add_rows (glp_prob *P, int nrs) 228int
229_lp_add_rows (glp_prob *P, int nrs)
222{ 230{
223#if HAVE_LIBGLPK 231#if HAVE_LIBGLPK
224 return glp_add_rows (P, nrs); 232 return glp_add_rows (P, nrs);
@@ -230,27 +238,30 @@ int _lp_add_rows (glp_prob *P, int nrs)
230} 238}
231 239
232 240
233void _lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub) 241void
242_lp_set_row_bnds (glp_prob *P, int i, int type, double lb, double ub)
234{ 243{
235#if HAVE_LIBGLPK 244#if HAVE_LIBGLPK
236 glp_set_row_bnds(P, i , type, lb, ub); 245 glp_set_row_bnds (P, i, type, lb, ub);
237#else 246#else
238 // Function not implemented 247 // Function not implemented
239 GNUNET_break (0); 248 GNUNET_break (0);
240#endif 249#endif
241} 250}
242 251
243void _lp_init_smcp (void * parm) 252void
253_lp_init_smcp (void *parm)
244{ 254{
245#if HAVE_LIBGLPK 255#if HAVE_LIBGLPK
246 glp_init_smcp(parm); 256 glp_init_smcp (parm);
247#else 257#else
248 // Function not implemented 258 // Function not implemented
249 GNUNET_break (0); 259 GNUNET_break (0);
250#endif 260#endif
251} 261}
252 262
253void _lp_set_col_name (glp_prob *P, int j, const char *name) 263void
264_lp_set_col_name (glp_prob *P, int j, const char *name)
254{ 265{
255#if HAVE_LIBGLPK 266#if HAVE_LIBGLPK
256 glp_set_col_name (P, j, name); 267 glp_set_col_name (P, j, name);
@@ -260,28 +271,30 @@ void _lp_set_col_name (glp_prob *P, int j, const char *name)
260#endif 271#endif
261} 272}
262 273
263void _lp_set_col_bnds (glp_prob *P, int j, int type, double lb, 274void
264 double ub) 275_lp_set_col_bnds (glp_prob *P, int j, int type, double lb, double ub)
265{ 276{
266#if HAVE_LIBGLPK 277#if HAVE_LIBGLPK
267 glp_set_col_bnds(P, j, type, lb, ub); 278 glp_set_col_bnds (P, j, type, lb, ub);
268#else 279#else
269 // Function not implemented 280 // Function not implemented
270 GNUNET_break (0); 281 GNUNET_break (0);
271#endif 282#endif
272} 283}
273 284
274void _lp_set_obj_coef(glp_prob *P, int j, double coef) 285void
286_lp_set_obj_coef (glp_prob *P, int j, double coef)
275{ 287{
276#if HAVE_LIBGLPK 288#if HAVE_LIBGLPK
277 glp_set_obj_coef(P, j, coef); 289 glp_set_obj_coef (P, j, coef);
278#else 290#else
279 // Function not implemented 291 // Function not implemented
280 GNUNET_break (0); 292 GNUNET_break (0);
281#endif 293#endif
282} 294}
283 295
284void _lp_delete_prob (void * P) 296void
297_lp_delete_prob (void *P)
285{ 298{
286#if HAVE_LIBGLPK 299#if HAVE_LIBGLPK
287 glp_delete_prob (P); 300 glp_delete_prob (P);
@@ -291,7 +304,8 @@ void _lp_delete_prob (void * P)
291#endif 304#endif
292} 305}
293 306
294static int _lp_simplex(glp_prob *P, void *parm) 307static int
308_lp_simplex (glp_prob *P, void *parm)
295{ 309{
296#if HAVE_LIBGLPK 310#if HAVE_LIBGLPK
297 return glp_simplex (P, parm); 311 return glp_simplex (P, parm);
@@ -302,19 +316,21 @@ static int _lp_simplex(glp_prob *P, void *parm)
302 return 0; 316 return 0;
303} 317}
304 318
305static void _lp_load_matrix (glp_prob *P, int ne, const int ia[], 319static void
306 const int ja[], const double ar[]) 320_lp_load_matrix (glp_prob *P, int ne, const int ia[],
321 const int ja[], const double ar[])
307{ 322{
308#if HAVE_LIBGLPK 323#if HAVE_LIBGLPK
309 glp_load_matrix(P, ne, ia, ja, ar); 324 glp_load_matrix (P, ne, ia, ja, ar);
310#else 325#else
311 // Function not implemented 326 // Function not implemented
312 GNUNET_break (0); 327 GNUNET_break (0);
313#endif 328#endif
314} 329}
315 330
316static void _lp_set_mat_row (glp_prob *P, int i, int len, const int ind[], 331static void
317 const double val[]) 332_lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
333 const double val[])
318{ 334{
319#if HAVE_LIBGLPK 335#if HAVE_LIBGLPK
320 glp_set_mat_row (P, i, len, ind, val); 336 glp_set_mat_row (P, i, len, ind, val);
@@ -324,10 +340,11 @@ static void _lp_set_mat_row (glp_prob *P, int i, int len, const int ind[],
324#endif 340#endif
325} 341}
326 342
327static int _lp_write_lp (glp_prob *P, const void *parm, const char *fname) 343static int
344_lp_write_lp (glp_prob *P, const void *parm, const char *fname)
328{ 345{
329#if HAVE_LIBGLPK 346#if HAVE_LIBGLPK
330 return glp_write_lp ( P, parm, fname); 347 return glp_write_lp (P, parm, fname);
331#else 348#else
332 // Function not implemented 349 // Function not implemented
333 GNUNET_break (0); 350 GNUNET_break (0);
@@ -335,7 +352,8 @@ static int _lp_write_lp (glp_prob *P, const void *parm, const char *fname)
335 return 0; 352 return 0;
336} 353}
337 354
338static void _lp_init_iocp (void *parm) 355static void
356_lp_init_iocp (void *parm)
339{ 357{
340#if HAVE_LIBGLPK 358#if HAVE_LIBGLPK
341 glp_init_iocp (parm); 359 glp_init_iocp (parm);
@@ -345,7 +363,8 @@ static void _lp_init_iocp (void *parm)
345#endif 363#endif
346} 364}
347 365
348static int _lp_intopt (glp_prob *P, const void *parm) 366static int
367_lp_intopt (glp_prob *P, const void *parm)
349{ 368{
350#if HAVE_LIBGLPK 369#if HAVE_LIBGLPK
351 return glp_intopt (P, parm); 370 return glp_intopt (P, parm);
@@ -356,7 +375,8 @@ static int _lp_intopt (glp_prob *P, const void *parm)
356 return 0; 375 return 0;
357} 376}
358 377
359static int _lp_get_status (glp_prob *P) 378static int
379_lp_get_status (glp_prob *P)
360{ 380{
361#if HAVE_LIBGLPK 381#if HAVE_LIBGLPK
362 return glp_get_status (P); 382 return glp_get_status (P);
@@ -367,7 +387,8 @@ static int _lp_get_status (glp_prob *P)
367 return 0; 387 return 0;
368} 388}
369 389
370static int _lp_mip_status (glp_prob *P) 390static int
391_lp_mip_status (glp_prob *P)
371{ 392{
372#if HAVE_LIBGLPK 393#if HAVE_LIBGLPK
373 return glp_mip_status (P); 394 return glp_mip_status (P);
@@ -378,7 +399,8 @@ static int _lp_mip_status (glp_prob *P)
378 return 0; 399 return 0;
379} 400}
380 401
381static void _lp_set_col_kind (glp_prob *P, int j, int kind) 402static void
403_lp_set_col_kind (glp_prob *P, int j, int kind)
382{ 404{
383#if HAVE_LIBGLPK 405#if HAVE_LIBGLPK
384 glp_set_col_kind (P, j, kind); 406 glp_set_col_kind (P, j, kind);
@@ -388,7 +410,8 @@ static void _lp_set_col_kind (glp_prob *P, int j, int kind)
388#endif 410#endif
389} 411}
390 412
391static void _lp_free_env (void) 413static void
414_lp_free_env (void)
392{ 415{
393#if HAVE_LIBGLPK 416#if HAVE_LIBGLPK
394 glp_free_env (); 417 glp_free_env ();
@@ -398,7 +421,8 @@ static void _lp_free_env (void)
398#endif 421#endif
399} 422}
400 423
401static const char * _lp_get_col_name ( glp_prob *P, int j) 424static const char *
425_lp_get_col_name (glp_prob *P, int j)
402{ 426{
403#if HAVE_LIBGLPK 427#if HAVE_LIBGLPK
404 return glp_get_col_name (P, j); 428 return glp_get_col_name (P, j);
@@ -409,7 +433,8 @@ static const char * _lp_get_col_name ( glp_prob *P, int j)
409 return NULL; 433 return NULL;
410} 434}
411 435
412static double _lp_mip_obj_val (glp_prob *P) 436static double
437_lp_mip_obj_val (glp_prob *P)
413{ 438{
414#if HAVE_LIBGLPK 439#if HAVE_LIBGLPK
415 return glp_mip_obj_val (P); 440 return glp_mip_obj_val (P);
@@ -421,10 +446,11 @@ static double _lp_mip_obj_val (glp_prob *P)
421} 446}
422 447
423 448
424static double _lp_get_col_prim (glp_prob *P, int j) 449static double
450_lp_get_col_prim (glp_prob *P, int j)
425{ 451{
426#if HAVE_LIBGLPK 452#if HAVE_LIBGLPK
427 return glp_get_col_prim (P , j); 453 return glp_get_col_prim (P, j);
428#else 454#else
429 // Function not implemented 455 // Function not implemented
430 GNUNET_break (0); 456 GNUNET_break (0);
@@ -432,7 +458,8 @@ static double _lp_get_col_prim (glp_prob *P, int j)
432 return 0.0; 458 return 0.0;
433} 459}
434 460
435static int _lp_print_sol(glp_prob *P, const char *fname) 461static int
462_lp_print_sol (glp_prob *P, const char *fname)
436{ 463{
437#if HAVE_LIBGLPK 464#if HAVE_LIBGLPK
438#else 465#else
@@ -447,24 +474,27 @@ static int _lp_print_sol(glp_prob *P, const char *fname)
447 */ 474 */
448 475
449static void _dummy2 (); 476static void _dummy2 ();
450static void _dummy () 477static void
478_dummy ()
451{ 479{
452 return; 480 return;
453 _lp_get_col_name (NULL, 0); 481 _lp_get_col_name (NULL, 0);
454 _lp_mip_obj_val (NULL); 482 _lp_mip_obj_val (NULL);
455 _lp_get_col_prim (NULL, 0); 483 _lp_get_col_prim (NULL, 0);
456 _lp_set_mat_row(NULL,0,0,NULL,NULL); 484 _lp_set_mat_row (NULL, 0, 0, NULL, NULL);
457 _dummy2(); 485 _dummy2 ();
458} 486}
459 487
460 488
461 489
462static void _dummy2 () 490static void
491_dummy2 ()
463{ 492{
464 ats_modify_problem_state (NULL, 0); 493 ats_modify_problem_state (NULL, 0);
465 qm[1].atis_index = 0; 494 qm[1].atis_index = 0;
466 _dummy(); 495 _dummy ();
467 int t = ATS_COST_UPDATED + ATS_MODIFIED + ATS_NEW; 496 int t = ATS_COST_UPDATED + ATS_MODIFIED + ATS_NEW;
497
468 t++; 498 t++;
469} 499}
470 500
@@ -479,19 +509,20 @@ static void _dummy2 ()
479 * @return 509 * @return
480 */ 510 */
481 511
482struct ATS_Handle * ats_init (double D, 512struct ATS_Handle *
483 double U, 513ats_init (double D,
484 double R, 514 double U,
485 int v_b_min, 515 double R,
486 int v_n_min, 516 int v_b_min,
487 int max_iterations, 517 int v_n_min,
488 struct GNUNET_TIME_Relative max_duration, 518 int max_iterations,
489 GNUNET_TRANSPORT_ATS_AddressNotification address_not, 519 struct GNUNET_TIME_Relative max_duration,
490 GNUNET_TRANSPORT_ATS_ResultCallback res_cb) 520 GNUNET_TRANSPORT_ATS_AddressNotification address_not,
521 GNUNET_TRANSPORT_ATS_ResultCallback res_cb)
491{ 522{
492 struct ATS_Handle * ats = NULL; 523 struct ATS_Handle *ats = NULL;
493 524
494 ats = GNUNET_malloc(sizeof (struct ATS_Handle)); 525 ats = GNUNET_malloc (sizeof (struct ATS_Handle));
495 526
496 ats->prob = NULL; 527 ats->prob = NULL;
497 528
@@ -507,7 +538,7 @@ struct ATS_Handle * ats_init (double D,
507 ats->v_b_min = v_b_min; 538 ats->v_b_min = v_b_min;
508 ats->v_n_min = v_n_min; 539 ats->v_n_min = v_n_min;
509 ats->dump_min_peers = 0; 540 ats->dump_min_peers = 0;
510 ats->dump_min_addr = 0; 541 ats->dump_min_addr = 0;
511 ats->dump_overwrite = GNUNET_NO; 542 ats->dump_overwrite = GNUNET_NO;
512 ats->mechanisms = NULL; 543 ats->mechanisms = NULL;
513 ats->peers = NULL; 544 ats->peers = NULL;
@@ -529,181 +560,165 @@ struct ATS_Handle * ats_init (double D,
529 * @param stat result struct 560 * @param stat result struct
530 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used 561 * @return GNUNET_SYSERR if glpk is not available, number of mechanisms used
531 */ 562 */
532int ats_create_problem (struct ATS_Handle *ats, 563int
533 struct ATS_internals *stat, 564ats_create_problem (struct ATS_Handle *ats,
534 struct ATS_peer *peers, 565 struct ATS_internals *stat,
535 int c_p, 566 struct ATS_peer *peers,
536 struct ATS_mechanism *mechanisms, 567 int c_p, struct ATS_mechanism *mechanisms, int c_m)
537 int c_m)
538{ 568{
539 if ((c_p == 0) || (c_m == 0)) 569 if ((c_p == 0) || (c_m == 0))
540 return GNUNET_SYSERR; 570 return GNUNET_SYSERR;
541 571
542 ats->prob = _lp_create_prob(); 572 ats->prob = _lp_create_prob ();
543 573
544 int c; 574 int c;
545 int c_c_ressources = available_ressources; 575 int c_c_ressources = available_ressources;
546 int c_q_metrics = available_quality_metrics; 576 int c_q_metrics = available_quality_metrics;
547 577
548 double M = VERY_BIG_DOUBLE_VALUE; 578 double M = VERY_BIG_DOUBLE_VALUE;
549 double Q[c_q_metrics+1]; 579 double Q[c_q_metrics + 1];
550 for (c=1; c<=c_q_metrics; c++) 580
581 for (c = 1; c <= c_q_metrics; c++)
551 { 582 {
552 Q[c] = 1; 583 Q[c] = 1;
553 } 584 }
554 585
555 if (ats->v_n_min > c_p) 586 if (ats->v_n_min > c_p)
556 ats->v_n_min = c_p; 587 ats->v_n_min = c_p;
557#if VERBOSE_ATS 588#if VERBOSE_ATS
558 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating problem with: %i peers, %i mechanisms, %i resource entries, %i quality metrics \n", 589 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
559 c_p, 590 "Creating problem with: %i peers, %i mechanisms, %i resource entries, %i quality metrics \n",
560 c_m, 591 c_p, c_m, c_c_ressources, c_q_metrics);
561 c_c_ressources,
562 c_q_metrics);
563#endif 592#endif
564 593
565 int size = 1 + 3 + 10 *c_m + c_p + 594 int size = 1 + 3 + 10 * c_m + c_p +
566 (c_q_metrics*c_m)+ c_q_metrics + c_c_ressources * c_m ; 595 (c_q_metrics * c_m) + c_q_metrics + c_c_ressources * c_m;
567 int row_index; 596 int row_index;
568 int array_index=1; 597 int array_index = 1;
569 int * ia = GNUNET_malloc (size * sizeof (int)); 598 int *ia = GNUNET_malloc (size * sizeof (int));
570 int * ja = GNUNET_malloc (size * sizeof (int)); 599 int *ja = GNUNET_malloc (size * sizeof (int));
571 double * ar = GNUNET_malloc(size* sizeof (double)); 600 double *ar = GNUNET_malloc (size * sizeof (double));
572 601
573 _lp_set_prob_name (ats->prob, "gnunet ats bandwidth distribution"); 602 _lp_set_prob_name (ats->prob, "gnunet ats bandwidth distribution");
574 _lp_set_obj_dir(ats->prob, GLP_MAX); 603 _lp_set_obj_dir (ats->prob, GLP_MAX);
575 604
576 /* adding columns */ 605 /* adding columns */
577 char * name; 606 char *name;
578 _lp_add_cols(ats->prob, 2 * c_m); 607
608 _lp_add_cols (ats->prob, 2 * c_m);
579 /* adding b_t cols */ 609 /* adding b_t cols */
580 for (c=1; c <= c_m; c++) 610 for (c = 1; c <= c_m; c++)
581 { 611 {
582 GNUNET_asprintf(&name, 612 GNUNET_asprintf (&name,
583 "p_%s_b%i",GNUNET_i2s(&(mechanisms[c].peer->peer)), c); 613 "p_%s_b%i", GNUNET_i2s (&(mechanisms[c].peer->peer)), c);
584 _lp_set_col_name(ats->prob, c, name); 614 _lp_set_col_name (ats->prob, c, name);
585 GNUNET_free (name); 615 GNUNET_free (name);
586 _lp_set_col_bnds(ats->prob, c, GLP_LO, 0.0, 0.0); 616 _lp_set_col_bnds (ats->prob, c, GLP_LO, 0.0, 0.0);
587 _lp_set_col_kind(ats->prob, c, GLP_CV); 617 _lp_set_col_kind (ats->prob, c, GLP_CV);
588 _lp_set_obj_coef(ats->prob, c, 0); 618 _lp_set_obj_coef (ats->prob, c, 0);
589 } 619 }
590 620
591 /* adding n_t cols */ 621 /* adding n_t cols */
592 for (c=c_m+1; c <= 2*c_m; c++) 622 for (c = c_m + 1; c <= 2 * c_m; c++)
593 { 623 {
594 GNUNET_asprintf(&name, 624 GNUNET_asprintf (&name,
595 "p_%s_n%i",GNUNET_i2s(&(mechanisms[c-c_m].peer->peer)),(c-c_m)); 625 "p_%s_n%i", GNUNET_i2s (&(mechanisms[c - c_m].peer->peer)),
596 _lp_set_col_name(ats->prob, c, name); 626 (c - c_m));
627 _lp_set_col_name (ats->prob, c, name);
597 GNUNET_free (name); 628 GNUNET_free (name);
598 _lp_set_col_bnds(ats->prob, c, GLP_DB, 0.0, 1.0); 629 _lp_set_col_bnds (ats->prob, c, GLP_DB, 0.0, 1.0);
599 _lp_set_col_kind(ats->prob, c, GLP_IV); 630 _lp_set_col_kind (ats->prob, c, GLP_IV);
600 _lp_set_obj_coef(ats->prob, c, 0); 631 _lp_set_obj_coef (ats->prob, c, 0);
601 } 632 }
602 633
603 /* feasibility constraints */ 634 /* feasibility constraints */
604 /* Constraint 1: one address per peer*/ 635 /* Constraint 1: one address per peer */
605 row_index = 1; 636 row_index = 1;
606 637
607 _lp_add_rows(ats->prob, c_p); 638 _lp_add_rows (ats->prob, c_p);
608 639
609 for (c=1; c<=c_p; c++) 640 for (c = 1; c <= c_p; c++)
610 { 641 {
611#if VERBOSE_ATS 642#if VERBOSE_ATS
612 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
613 row_index);
614#endif 644#endif
615 645
616 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 1.0, 1.0); 646 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 1.0, 1.0);
617 struct ATS_mechanism *m = peers[c].m_head; 647 struct ATS_mechanism *m = peers[c].m_head;
618 while (m!=NULL) 648
619 { 649 while (m != NULL)
620 ia[array_index] = row_index; 650 {
621 ja[array_index] = (c_m + m->col_index); 651 ia[array_index] = row_index;
622 ar[array_index] = 1; 652 ja[array_index] = (c_m + m->col_index);
653 ar[array_index] = 1;
623#if VERBOSE_ATS 654#if VERBOSE_ATS
624 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 655 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
625 array_index, 656 array_index,
626 ia[array_index], 657 ia[array_index], ja[array_index], ar[array_index]);
627 ja[array_index], 658#endif
628 ar[array_index]); 659 array_index++;
629#endif 660 m = m->next;
630 array_index++; 661 }
631 m = m->next; 662 row_index++;
632 }
633 row_index++;
634 } 663 }
635 664
636 /* Constraint 2: only active mechanism gets bandwidth assigned */ 665 /* Constraint 2: only active mechanism gets bandwidth assigned */
637 _lp_add_rows(ats->prob, c_m); 666 _lp_add_rows (ats->prob, c_m);
638 for (c=1; c<=c_m; c++) 667 for (c = 1; c <= c_m; c++)
639 { 668 {
640 /* b_t - n_t * M <= 0 */ 669 /* b_t - n_t * M <= 0 */
641#if VERBOSE_ATS 670#if VERBOSE_ATS
642 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 671 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
643 row_index);
644#endif 672#endif
645 _lp_set_row_bnds(ats->prob, row_index, GLP_UP, 0.0, 0.0); 673 _lp_set_row_bnds (ats->prob, row_index, GLP_UP, 0.0, 0.0);
646 ia[array_index] = row_index; 674 ia[array_index] = row_index;
647 ja[array_index] = mechanisms[c].col_index; 675 ja[array_index] = mechanisms[c].col_index;
648 ar[array_index] = 1; 676 ar[array_index] = 1;
649#if VERBOSE_ATS 677#if VERBOSE_ATS
650 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
651 array_index, 679 array_index, ia[array_index], ja[array_index], ar[array_index]);
652 ia[array_index], 680#endif
653 ja[array_index], 681 array_index++;
654 ar[array_index]); 682 ia[array_index] = row_index;
655#endif 683 ja[array_index] = c_m + mechanisms[c].col_index;
656 array_index++; 684 ar[array_index] = -M;
657 ia[array_index] = row_index;
658 ja[array_index] = c_m + mechanisms[c].col_index;
659 ar[array_index] = -M;
660#if VERBOSE_ATS 685#if VERBOSE_ATS
661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
662 array_index, 687 array_index, ia[array_index], ja[array_index], ar[array_index]);
663 ia[array_index], 688#endif
664 ja[array_index], 689 array_index++;
665 ar[array_index]); 690 row_index++;
666#endif
667 array_index++;
668 row_index ++;
669 } 691 }
670 692
671 /* Constraint 3: minimum bandwidth*/ 693 /* Constraint 3: minimum bandwidth */
672 _lp_add_rows(ats->prob, c_m); 694 _lp_add_rows (ats->prob, c_m);
673 695
674 for (c=1; c<=c_m; c++) 696 for (c = 1; c <= c_m; c++)
675 { 697 {
676 /* b_t - n_t * b_min <= 0 */ 698 /* b_t - n_t * b_min <= 0 */
677#if VERBOSE_ATS 699#if VERBOSE_ATS
678 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
679 row_index);
680#endif 701#endif
681#if HAVE_LIBGLPK 702#if HAVE_LIBGLPK
682 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0); 703 _lp_set_row_bnds (ats->prob, row_index, GLP_LO, 0.0, 0.0);
683#endif 704#endif
684 ia[array_index] = row_index; 705 ia[array_index] = row_index;
685 ja[array_index] = mechanisms[c].col_index; 706 ja[array_index] = mechanisms[c].col_index;
686 ar[array_index] = 1; 707 ar[array_index] = 1;
687#if VERBOSE_ATS 708#if VERBOSE_ATS
688 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 709 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
689 array_index, 710 array_index, ia[array_index], ja[array_index], ar[array_index]);
690 ia[array_index], 711#endif
691 ja[array_index], 712 array_index++;
692 ar[array_index]); 713 ia[array_index] = row_index;
693#endif 714 ja[array_index] = c_m + mechanisms[c].col_index;
694 array_index++; 715 ar[array_index] = -ats->v_b_min;
695 ia[array_index] = row_index;
696 ja[array_index] = c_m + mechanisms[c].col_index;
697 ar[array_index] = -ats->v_b_min;
698#if VERBOSE_ATS 716#if VERBOSE_ATS
699 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 717 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
700 array_index, 718 array_index, ia[array_index], ja[array_index], ar[array_index]);
701 ia[array_index], 719#endif
702 ja[array_index], 720 array_index++;
703 ar[array_index]); 721 row_index++;
704#endif
705 array_index++;
706 row_index ++;
707 } 722 }
708 int c2; 723 int c2;
709 724
@@ -711,69 +726,63 @@ int ats_create_problem (struct ATS_Handle *ats,
711 /* V cr: bt * ct_r <= cr_max 726 /* V cr: bt * ct_r <= cr_max
712 * */ 727 * */
713 728
714 _lp_add_rows(ats->prob, available_ressources); 729 _lp_add_rows (ats->prob, available_ressources);
715 730
716 double ct_max = VERY_BIG_DOUBLE_VALUE; 731 double ct_max = VERY_BIG_DOUBLE_VALUE;
717 double ct_min = 0.0; 732 double ct_min = 0.0;
718 733
719 stat->begin_cr = array_index; 734 stat->begin_cr = array_index;
720 735
721 for (c=0; c<available_ressources; c++) 736 for (c = 0; c < available_ressources; c++)
722 { 737 {
723 ct_max = ressources[c].c_max; 738 ct_max = ressources[c].c_max;
724 ct_min = ressources[c].c_min; 739 ct_min = ressources[c].c_min;
725#if VERBOSE_ATS 740#if VERBOSE_ATS
726 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n", 741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
727 row_index, 742 row_index, ct_min, ct_max);
728 ct_min,
729 ct_max);
730#endif 743#endif
731#if HAVE_LIBGLPK 744#if HAVE_LIBGLPK
732 _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max); 745 _lp_set_row_bnds (ats->prob, row_index, GLP_DB, ct_min, ct_max);
733#endif 746#endif
734 for (c2=1; c2<=c_m; c2++) 747 for (c2 = 1; c2 <= c_m; c2++)
735 { 748 {
736 double value = 0; 749 double value = 0;
737 ia[array_index] = row_index; 750
738 ja[array_index] = c2; 751 ia[array_index] = row_index;
739 value = mechanisms[c2].ressources[c].c; 752 ja[array_index] = c2;
740 ar[array_index] = value; 753 value = mechanisms[c2].ressources[c].c;
754 ar[array_index] = value;
741#if VERBOSE_ATS 755#if VERBOSE_ATS
742 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
743 array_index, ia[array_index], 757 array_index, ia[array_index],
744 ja[array_index], 758 ja[array_index], ar[array_index]);
745 ar[array_index]);
746#endif 759#endif
747 array_index++; 760 array_index++;
748 } 761 }
749 row_index ++; 762 row_index++;
750 } 763 }
751 stat->end_cr = array_index--; 764 stat->end_cr = array_index--;
752 765
753 /* Constraint 5: min number of connections*/ 766 /* Constraint 5: min number of connections */
754 _lp_add_rows(ats->prob, 1); 767 _lp_add_rows (ats->prob, 1);
755 768
756 for (c=1; c<=c_m; c++) 769 for (c = 1; c <= c_m; c++)
757 { 770 {
758 // b_t - n_t * b_min >= 0 771 // b_t - n_t * b_min >= 0
759#if VERBOSE_ATS 772#if VERBOSE_ATS
760 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 773 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
761 row_index);
762#endif 774#endif
763 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0); 775 _lp_set_row_bnds (ats->prob, row_index, GLP_LO, ats->v_n_min, 0.0);
764 ia[array_index] = row_index; 776 ia[array_index] = row_index;
765 ja[array_index] = c_m + mechanisms[c].col_index; 777 ja[array_index] = c_m + mechanisms[c].col_index;
766 ar[array_index] = 1; 778 ar[array_index] = 1;
767#if VERBOSE_ATS 779#if VERBOSE_ATS
768 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 780 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
769 array_index, 781 array_index, ia[array_index], ja[array_index], ar[array_index]);
770 ia[array_index],
771 ja[array_index],
772 ar[array_index]);
773#endif 782#endif
774 array_index++; 783 array_index++;
775 } 784 }
776 row_index ++; 785 row_index++;
777 786
778 // optimisation constraints 787 // optimisation constraints
779 788
@@ -781,29 +790,27 @@ int ats_create_problem (struct ATS_Handle *ats,
781 790
782 // Constraint 6: optimize for diversity 791 // Constraint 6: optimize for diversity
783 int col_d; 792 int col_d;
784 col_d = _lp_add_cols(ats->prob, 1);
785 793
786 _lp_set_col_name(ats->prob, col_d, "d"); 794 col_d = _lp_add_cols (ats->prob, 1);
787 _lp_set_obj_coef(ats->prob, col_d, ats->D); 795
788 _lp_set_col_bnds(ats->prob, col_d, GLP_LO, 0.0, 0.0); 796 _lp_set_col_name (ats->prob, col_d, "d");
789 _lp_add_rows(ats->prob, 1); 797 _lp_set_obj_coef (ats->prob, col_d, ats->D);
790 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 798 _lp_set_col_bnds (ats->prob, col_d, GLP_LO, 0.0, 0.0);
799 _lp_add_rows (ats->prob, 1);
800 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
791 801
792 stat->col_d = col_d; 802 stat->col_d = col_d;
793#if VERBOSE_ATS 803#if VERBOSE_ATS
794 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); 804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
795#endif 805#endif
796 for (c=1; c<=c_m; c++) 806 for (c = 1; c <= c_m; c++)
797 { 807 {
798 ia[array_index] = row_index; 808 ia[array_index] = row_index;
799 ja[array_index] = c_m + mechanisms[c].col_index; 809 ja[array_index] = c_m + mechanisms[c].col_index;
800 ar[array_index] = 1; 810 ar[array_index] = 1;
801#if VERBOSE_ATS 811#if VERBOSE_ATS
802 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 812 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
803 array_index, 813 array_index, ia[array_index], ja[array_index], ar[array_index]);
804 ia[array_index],
805 ja[array_index],
806 ar[array_index]);
807#endif 814#endif
808 array_index++; 815 array_index++;
809 } 816 }
@@ -812,122 +819,120 @@ int ats_create_problem (struct ATS_Handle *ats,
812 ar[array_index] = -1; 819 ar[array_index] = -1;
813#if VERBOSE_ATS 820#if VERBOSE_ATS
814 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
815 array_index, 822 array_index, ia[array_index], ja[array_index], ar[array_index]);
816 ia[array_index],
817 ja[array_index],
818 ar[array_index]);
819#endif 823#endif
820 array_index++; 824 array_index++;
821 row_index ++; 825 row_index++;
822 826
823 // Constraint 7: optimize for quality 827 // Constraint 7: optimize for quality
824 int col_qm; 828 int col_qm;
825 col_qm = _lp_add_cols(ats->prob, c_q_metrics); 829
830 col_qm = _lp_add_cols (ats->prob, c_q_metrics);
826 831
827 stat->col_qm = col_qm; 832 stat->col_qm = col_qm;
828 //GNUNET_assert (col_qm == (2*c_mechs) + 3 + 1); 833 //GNUNET_assert (col_qm == (2*c_mechs) + 3 + 1);
829 for (c=0; c< c_q_metrics; c++) 834 for (c = 0; c < c_q_metrics; c++)
830 { 835 {
831 GNUNET_asprintf(&name, "Q_%s",qm[c].name); 836 GNUNET_asprintf (&name, "Q_%s", qm[c].name);
832 _lp_set_col_name (ats->prob, col_qm + c, name); 837 _lp_set_col_name (ats->prob, col_qm + c, name);
833 _lp_set_col_bnds (ats->prob, col_qm + c, GLP_LO, 0.0, 0.0); 838 _lp_set_col_bnds (ats->prob, col_qm + c, GLP_LO, 0.0, 0.0);
834 GNUNET_free (name); 839 GNUNET_free (name);
835 _lp_set_obj_coef (ats->prob, col_qm + c, Q[c]); 840 _lp_set_obj_coef (ats->prob, col_qm + c, Q[c]);
836 } 841 }
837 842
838 _lp_add_rows(ats->prob, available_quality_metrics); 843 _lp_add_rows (ats->prob, available_quality_metrics);
839 844
840 stat->begin_qm = row_index; 845 stat->begin_qm = row_index;
841 for (c=1; c <= c_q_metrics; c++) 846 for (c = 1; c <= c_q_metrics; c++)
842 { 847 {
843#if VERBOSE_ATS 848#if VERBOSE_ATS
844 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", 849 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
845 row_index);
846#endif 850#endif
847 double value = 1; 851 double value = 1;
848 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 852
849 for (c2=1; c2<=c_m; c2++) 853 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
854 for (c2 = 1; c2 <= c_m; c2++)
855 {
856 ia[array_index] = row_index;
857 ja[array_index] = c2;
858 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
850 { 859 {
851 ia[array_index] = row_index; 860 double v0 = 0, v1 = 0, v2 = 0;
852 ja[array_index] = c2; 861
853 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) 862 v0 = mechanisms[c2].quality[c - 1].values[0];
854 { 863 if (v1 < 1)
855 double v0 = 0, v1 = 0, v2 = 0; 864 v0 = 0.1;
856 v0 = mechanisms[c2].quality[c-1].values[0]; 865 v1 = mechanisms[c2].quality[c - 1].values[1];
857 if (v1 < 1) v0 = 0.1; 866 if (v1 < 1)
858 v1 = mechanisms[c2].quality[c-1].values[1]; 867 v0 = 0.1;
859 if (v1 < 1) v0 = 0.1; 868 v2 = mechanisms[c2].quality[c - 1].values[2];
860 v2 = mechanisms[c2].quality[c-1].values[2]; 869 if (v1 < 1)
861 if (v1 < 1) v0 = 0.1; 870 v0 = 0.1;
862 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0); 871 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
863 value = 1; 872 value = 1;
864 }
865 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
866 {
867 double v0 = 0, v1 = 0, v2 = 0;
868 v0 = mechanisms[c2].quality[c-1].values[0];
869 if (v0 < 1) v0 = 1;
870 v1 = mechanisms[c2].quality[c-1].values[1];
871 if (v1 < 1) v1 = 1;
872 v2 = mechanisms[c2].quality[c-1].values[2];
873 if (v2 < 1) v2 = 1;
874 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
875 if (value >= 1)
876 value = (double) 10 / value;
877 else
878 value = 10;
879 }
880 ar[array_index] = (mechanisms[c2].peer->f) * value ;
881#if VERBOSE_ATS
882 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
883 array_index,
884 qm[c-1].name,
885 ia[array_index],
886 ja[array_index],
887 ar[array_index]);
888#endif
889 array_index++;
890 } 873 }
891 ia[array_index] = row_index; 874 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
892 ja[array_index] = col_qm + c - 1; 875 {
893 ar[array_index] = -1; 876 double v0 = 0, v1 = 0, v2 = 0;
877
878 v0 = mechanisms[c2].quality[c - 1].values[0];
879 if (v0 < 1)
880 v0 = 1;
881 v1 = mechanisms[c2].quality[c - 1].values[1];
882 if (v1 < 1)
883 v1 = 1;
884 v2 = mechanisms[c2].quality[c - 1].values[2];
885 if (v2 < 1)
886 v2 = 1;
887 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
888 if (value >= 1)
889 value = (double) 10 / value;
890 else
891 value = 10;
892 }
893 ar[array_index] = (mechanisms[c2].peer->f) * value;
894#if VERBOSE_ATS 894#if VERBOSE_ATS
895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 895 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
896 array_index, 896 array_index,
897 ia[array_index], 897 qm[c - 1].name,
898 ja[array_index], 898 ia[array_index], ja[array_index], ar[array_index]);
899 ar[array_index]);
900#endif 899#endif
901 array_index++; 900 array_index++;
902 row_index++; 901 }
902 ia[array_index] = row_index;
903 ja[array_index] = col_qm + c - 1;
904 ar[array_index] = -1;
905#if VERBOSE_ATS
906 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
907 array_index, ia[array_index], ja[array_index], ar[array_index]);
908#endif
909 array_index++;
910 row_index++;
903 } 911 }
904 stat->end_qm = row_index-1; 912 stat->end_qm = row_index - 1;
905 913
906 // Constraint 8: optimize bandwidth utility 914 // Constraint 8: optimize bandwidth utility
907 int col_u; 915 int col_u;
908 916
909 col_u = _lp_add_cols(ats->prob, 1); 917 col_u = _lp_add_cols (ats->prob, 1);
910 918
911 _lp_set_col_name(ats->prob, col_u, "u"); 919 _lp_set_col_name (ats->prob, col_u, "u");
912 _lp_set_obj_coef(ats->prob, col_u, ats->U); 920 _lp_set_obj_coef (ats->prob, col_u, ats->U);
913 _lp_set_col_bnds(ats->prob, col_u, GLP_LO, 0.0, 0.0); 921 _lp_set_col_bnds (ats->prob, col_u, GLP_LO, 0.0, 0.0);
914 _lp_add_rows(ats->prob, 1); 922 _lp_add_rows (ats->prob, 1);
915 stat->col_u = col_u; 923 stat->col_u = col_u;
916#if VERBOSE_ATS 924#if VERBOSE_ATS
917 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index); 925 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
918#endif 926#endif
919 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 927 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
920 for (c=1; c<=c_m; c++) 928 for (c = 1; c <= c_m; c++)
921 { 929 {
922 ia[array_index] = row_index; 930 ia[array_index] = row_index;
923 ja[array_index] = c; 931 ja[array_index] = c;
924 ar[array_index] = mechanisms[c].peer->f; 932 ar[array_index] = mechanisms[c].peer->f;
925#if VERBOSE_ATS 933#if VERBOSE_ATS
926 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 934 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
927 array_index, 935 array_index, ia[array_index], ja[array_index], ar[array_index]);
928 ia[array_index],
929 ja[array_index],
930 ar[array_index]);
931#endif 936#endif
932 array_index++; 937 array_index++;
933 } 938 }
@@ -936,40 +941,37 @@ int ats_create_problem (struct ATS_Handle *ats,
936 ar[array_index] = -1; 941 ar[array_index] = -1;
937#if VERBOSE_ATS 942#if VERBOSE_ATS
938 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 943 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
939 array_index, ia[array_index], 944 array_index, ia[array_index], ja[array_index], ar[array_index]);
940 ja[array_index],
941 ar[array_index]);
942#endif 945#endif
943 946
944 array_index++; 947 array_index++;
945 row_index ++; 948 row_index++;
946 949
947 // Constraint 9: optimize relativity 950 // Constraint 9: optimize relativity
948 int col_r; 951 int col_r;
949 952
950 col_r = _lp_add_cols(ats->prob, 1); 953 col_r = _lp_add_cols (ats->prob, 1);
951 954
952 _lp_set_col_name(ats->prob, col_r, "r"); 955 _lp_set_col_name (ats->prob, col_r, "r");
953 _lp_set_obj_coef(ats->prob, col_r, ats->R); 956 _lp_set_obj_coef (ats->prob, col_r, ats->R);
954 _lp_set_col_bnds(ats->prob, col_r, GLP_LO, 0.0, 0.0); 957 _lp_set_col_bnds (ats->prob, col_r, GLP_LO, 0.0, 0.0);
955 _lp_add_rows(ats->prob, c_p); 958 _lp_add_rows (ats->prob, c_p);
956 959
957 stat->col_r = col_r; 960 stat->col_r = col_r;
958 for (c=1; c<=c_p; c++) 961 for (c = 1; c <= c_p; c++)
959 { 962 {
960 _lp_set_row_bnds(ats->prob, row_index, GLP_LO, 0.0, 0.0); 963 _lp_set_row_bnds (ats->prob, row_index, GLP_LO, 0.0, 0.0);
961 struct ATS_mechanism *m = peers[c].m_head; 964 struct ATS_mechanism *m = peers[c].m_head;
962 while (m!=NULL) 965
966 while (m != NULL)
963 { 967 {
964 ia[array_index] = row_index; 968 ia[array_index] = row_index;
965 ja[array_index] = m->col_index; 969 ja[array_index] = m->col_index;
966 ar[array_index] = 1 / mechanisms[c].peer->f; 970 ar[array_index] = 1 / mechanisms[c].peer->f;
967#if VERBOSE_ATS 971#if VERBOSE_ATS
968 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
969 array_index, 973 array_index,
970 ia[array_index], 974 ia[array_index], ja[array_index], ar[array_index]);
971 ja[array_index],
972 ar[array_index]);
973#endif 975#endif
974 array_index++; 976 array_index++;
975 m = m->next; 977 m = m->next;
@@ -979,17 +981,14 @@ int ats_create_problem (struct ATS_Handle *ats,
979 ar[array_index] = -1; 981 ar[array_index] = -1;
980#if VERBOSE_ATS 982#if VERBOSE_ATS
981 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
982 array_index, 984 array_index, ia[array_index], ja[array_index], ar[array_index]);
983 ia[array_index],
984 ja[array_index],
985 ar[array_index]);
986#endif 985#endif
987 array_index++; 986 array_index++;
988 row_index++; 987 row_index++;
989 } 988 }
990 989
991 /* Loading the matrix */ 990 /* Loading the matrix */
992 _lp_load_matrix(ats->prob, array_index-1, ia, ja, ar); 991 _lp_load_matrix (ats->prob, array_index - 1, ia, ja, ar);
993 992
994 stat->c_mechs = c_m; 993 stat->c_mechs = c_m;
995 stat->c_peers = c_p; 994 stat->c_peers = c_p;
@@ -1005,30 +1004,31 @@ int ats_create_problem (struct ATS_Handle *ats,
1005} 1004}
1006 1005
1007 1006
1008void ats_delete_problem (struct ATS_Handle * ats) 1007void
1008ats_delete_problem (struct ATS_Handle *ats)
1009{ 1009{
1010#if DEBUG_ATS 1010#if DEBUG_ATS
1011 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting problem\n"); 1011 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Deleting problem\n");
1012#endif 1012#endif
1013 int c; 1013 int c;
1014 1014
1015 for (c=0; c< (ats->internal).c_mechs; c++) 1015 for (c = 0; c < (ats->internal).c_mechs; c++)
1016 GNUNET_free_non_null (ats->mechanisms[c].rc); 1016 GNUNET_free_non_null (ats->mechanisms[c].rc);
1017 if (ats->mechanisms!=NULL) 1017 if (ats->mechanisms != NULL)
1018 { 1018 {
1019 GNUNET_free(ats->mechanisms); 1019 GNUNET_free (ats->mechanisms);
1020 ats->mechanisms = NULL; 1020 ats->mechanisms = NULL;
1021 } 1021 }
1022 1022
1023 if (ats->peers!=NULL) 1023 if (ats->peers != NULL)
1024 { 1024 {
1025 GNUNET_free(ats->peers); 1025 GNUNET_free (ats->peers);
1026 ats->peers = NULL; 1026 ats->peers = NULL;
1027 } 1027 }
1028 1028
1029 if (ats->prob != NULL) 1029 if (ats->prob != NULL)
1030 { 1030 {
1031 _lp_delete_prob(ats->prob); 1031 _lp_delete_prob (ats->prob);
1032 ats->prob = NULL; 1032 ats->prob = NULL;
1033 } 1033 }
1034 1034
@@ -1042,13 +1042,14 @@ void ats_delete_problem (struct ATS_Handle * ats)
1042 ats->internal.valid = GNUNET_SYSERR; 1042 ats->internal.valid = GNUNET_SYSERR;
1043} 1043}
1044 1044
1045void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s) 1045void
1046ats_modify_problem_state (struct ATS_Handle *ats, enum ATS_problem_state s)
1046{ 1047{
1047 if (ats == NULL) 1048 if (ats == NULL)
1048 return; 1049 return;
1049 switch (s) 1050 switch (s)
1050 { 1051 {
1051 case ATS_NEW : 1052 case ATS_NEW:
1052 ats->internal.recreate_problem = GNUNET_NO; 1053 ats->internal.recreate_problem = GNUNET_NO;
1053 ats->internal.modified_quality = GNUNET_NO; 1054 ats->internal.modified_quality = GNUNET_NO;
1054 ats->internal.modified_resources = GNUNET_NO; 1055 ats->internal.modified_resources = GNUNET_NO;
@@ -1056,10 +1057,10 @@ void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s
1056 case ATS_MODIFIED: 1057 case ATS_MODIFIED:
1057 ats->internal.recreate_problem = GNUNET_YES; 1058 ats->internal.recreate_problem = GNUNET_YES;
1058 break; 1059 break;
1059 case ATS_QUALITY_UPDATED : 1060 case ATS_QUALITY_UPDATED:
1060 ats->internal.modified_quality = GNUNET_YES; 1061 ats->internal.modified_quality = GNUNET_YES;
1061 break; 1062 break;
1062 case ATS_COST_UPDATED : 1063 case ATS_COST_UPDATED:
1063 ats->internal.modified_resources = GNUNET_YES; 1064 ats->internal.modified_resources = GNUNET_YES;
1064 break; 1065 break;
1065 case ATS_QUALITY_COST_UPDATED: 1066 case ATS_QUALITY_COST_UPDATED:
@@ -1074,12 +1075,12 @@ void ats_modify_problem_state (struct ATS_Handle * ats, enum ATS_problem_state s
1074 1075
1075} 1076}
1076 1077
1077void ats_solve_problem (struct ATS_Handle * ats, 1078void
1078 unsigned int max_it, 1079ats_solve_problem (struct ATS_Handle *ats,
1079 unsigned int max_dur, 1080 unsigned int max_it,
1080 unsigned int c_peers, 1081 unsigned int max_dur,
1081 unsigned int c_mechs, 1082 unsigned int c_peers,
1082 struct ATS_internals *stat) 1083 unsigned int c_mechs, struct ATS_internals *stat)
1083{ 1084{
1084 int result = GNUNET_SYSERR; 1085 int result = GNUNET_SYSERR;
1085 int lp_solution = GNUNET_SYSERR; 1086 int lp_solution = GNUNET_SYSERR;
@@ -1088,7 +1089,8 @@ void ats_solve_problem (struct ATS_Handle * ats,
1088 // Solving simplex 1089 // Solving simplex
1089 1090
1090 glp_smcp opt_lp; 1091 glp_smcp opt_lp;
1091 _lp_init_smcp(&opt_lp); 1092
1093 _lp_init_smcp (&opt_lp);
1092#if VERBOSE_ATS 1094#if VERBOSE_ATS
1093 opt_lp.msg_lev = GLP_MSG_ALL; 1095 opt_lp.msg_lev = GLP_MSG_ALL;
1094#else 1096#else
@@ -1100,20 +1102,20 @@ void ats_solve_problem (struct ATS_Handle * ats,
1100 opt_lp.tm_lim = max_dur; 1102 opt_lp.tm_lim = max_dur;
1101 1103
1102 if (ats->internal.recreate_problem == GNUNET_YES) 1104 if (ats->internal.recreate_problem == GNUNET_YES)
1103 opt_lp.presolve = GLP_ON; 1105 opt_lp.presolve = GLP_ON;
1104 1106
1105 result = _lp_simplex(ats->prob, &opt_lp); 1107 result = _lp_simplex (ats->prob, &opt_lp);
1106 lp_solution = _lp_get_status (ats->prob); 1108 lp_solution = _lp_get_status (ats->prob);
1107 1109
1108 if ((result == GLP_ETMLIM) || (result == GLP_EITLIM)) 1110 if ((result == GLP_ETMLIM) || (result == GLP_EITLIM))
1109 { 1111 {
1110 ats->internal.valid = GNUNET_NO; 1112 ats->internal.valid = GNUNET_NO;
1111 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1112 "ATS exceeded time or iteration limit!\n"); 1114 "ATS exceeded time or iteration limit!\n");
1113 return; 1115 return;
1114 } 1116 }
1115 1117
1116 if (ats_evaluate_results(result, lp_solution, "LP") == GNUNET_YES) 1118 if (ats_evaluate_results (result, lp_solution, "LP") == GNUNET_YES)
1117 { 1119 {
1118 stat->valid = GNUNET_YES; 1120 stat->valid = GNUNET_YES;
1119 } 1121 }
@@ -1121,36 +1123,37 @@ void ats_solve_problem (struct ATS_Handle * ats,
1121 { 1123 {
1122 ats->internal.simplex_rerun_required = GNUNET_YES; 1124 ats->internal.simplex_rerun_required = GNUNET_YES;
1123 opt_lp.presolve = GLP_ON; 1125 opt_lp.presolve = GLP_ON;
1124 result = _lp_simplex(ats->prob, &opt_lp); 1126 result = _lp_simplex (ats->prob, &opt_lp);
1125 lp_solution = _lp_get_status (ats->prob); 1127 lp_solution = _lp_get_status (ats->prob);
1126 1128
1127 // TODO: Remove if this does not appear until release 1129 // TODO: Remove if this does not appear until release
1128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "" 1130 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, ""
1129 "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", 1131 "EXECUTED SIMPLEX WITH PRESOLVER! %i \n", lp_solution);
1130 lp_solution);
1131 1132
1132 if (ats_evaluate_results(result, lp_solution, "LP") != GNUNET_YES) 1133 if (ats_evaluate_results (result, lp_solution, "LP") != GNUNET_YES)
1133 { 1134 {
1134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1135 "After execution simplex with presolver: STILL INVALID!\n"); 1136 "After execution simplex with presolver: STILL INVALID!\n");
1136 char * filename; 1137 char *filename;
1137 GNUNET_asprintf (&filename, 1138
1138 "ats_mlp_p%i_m%i_%llu.mlp", 1139 GNUNET_asprintf (&filename,
1139 ats->internal.c_peers, 1140 "ats_mlp_p%i_m%i_%llu.mlp",
1140 ats->internal.c_mechs, 1141 ats->internal.c_peers,
1141 GNUNET_TIME_absolute_get().abs_value); 1142 ats->internal.c_mechs,
1142 _lp_write_lp ((void *)ats->prob, NULL, filename); 1143 GNUNET_TIME_absolute_get ().abs_value);
1143 GNUNET_free (filename); 1144 _lp_write_lp ((void *) ats->prob, NULL, filename);
1144 stat->valid = GNUNET_NO; 1145 GNUNET_free (filename);
1145 ats->internal.recreate_problem = GNUNET_YES; 1146 stat->valid = GNUNET_NO;
1146 return; 1147 ats->internal.recreate_problem = GNUNET_YES;
1148 return;
1147 } 1149 }
1148 stat->valid = GNUNET_YES; 1150 stat->valid = GNUNET_YES;
1149 } 1151 }
1150 1152
1151 // Solving mlp 1153 // Solving mlp
1152 glp_iocp opt_mlp; 1154 glp_iocp opt_mlp;
1153 _lp_init_iocp(&opt_mlp); 1155
1156 _lp_init_iocp (&opt_mlp);
1154 // maximum duration 1157 // maximum duration
1155 opt_mlp.tm_lim = max_dur; 1158 opt_mlp.tm_lim = max_dur;
1156 // output level 1159 // output level
@@ -1161,342 +1164,351 @@ void ats_solve_problem (struct ATS_Handle * ats,
1161#endif 1164#endif
1162 1165
1163 result = _lp_intopt (ats->prob, &opt_mlp); 1166 result = _lp_intopt (ats->prob, &opt_mlp);
1164 mlp_solution = _lp_mip_status (ats->prob); 1167 mlp_solution = _lp_mip_status (ats->prob);
1165 stat->solution = mlp_solution; 1168 stat->solution = mlp_solution;
1166 1169
1167 if (ats_evaluate_results(result, mlp_solution, "MLP") == GNUNET_YES) 1170 if (ats_evaluate_results (result, mlp_solution, "MLP") == GNUNET_YES)
1168 { 1171 {
1169 stat->valid = GNUNET_YES; 1172 stat->valid = GNUNET_YES;
1170 } 1173 }
1171 else 1174 else
1172 { 1175 {
1173 // TODO: Remove if this does not appear until release 1176 // TODO: Remove if this does not appear until release
1174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1177 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1175 "MLP solution for %i peers, %i mechs is invalid: %i\n", 1178 "MLP solution for %i peers, %i mechs is invalid: %i\n",
1176 ats->internal.c_peers, 1179 ats->internal.c_peers, ats->internal.c_mechs, mlp_solution);
1177 ats->internal.c_mechs, 1180 stat->valid = GNUNET_NO;
1178 mlp_solution);
1179 stat->valid = GNUNET_NO;
1180 } 1181 }
1181 1182
1182#if VERBOSE_ATS 1183#if VERBOSE_ATS
1183 if (_lp_get_col_prim(ats->prob,2*c_mechs+1) != 1) 1184 if (_lp_get_col_prim (ats->prob, 2 * c_mechs + 1) != 1)
1184 {
1185 int c;
1186 for (c=1; c<= available_quality_metrics; c++ )
1187 { 1185 {
1186 int c;
1187
1188 for (c = 1; c <= available_quality_metrics; c++)
1189 {
1190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1191 _lp_get_col_name (ats->prob, 2 * c_mechs + 3 + c),
1192 _lp_get_col_prim (ats->prob, 2 * c_mechs + 3 + c));
1193 }
1188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1189 _lp_get_col_name(ats->prob,2*c_mechs+3+c), 1195 _lp_get_col_name (ats->prob, 2 * c_mechs + 1),
1190 _lp_get_col_prim(ats->prob,2*c_mechs+3+c)); 1196 _lp_get_col_prim (ats->prob, 2 * c_mechs + 1));
1191 } 1197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1198 _lp_get_col_name (ats->prob, 2 * c_mechs + 2),
1193 _lp_get_col_name(ats->prob,2*c_mechs+1), 1199 _lp_get_col_prim (ats->prob, 2 * c_mechs + 2));
1194 _lp_get_col_prim(ats->prob,2*c_mechs+1)); 1200 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n",
1195 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1201 _lp_get_col_name (ats->prob, 2 * c_mechs + 3),
1196 _lp_get_col_name(ats->prob,2*c_mechs+2), 1202 _lp_get_col_prim (ats->prob, 2 * c_mechs + 3));
1197 _lp_get_col_prim(ats->prob,2*c_mechs+2)); 1203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "objective value: %f\n",
1198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s %f\n", 1204 _lp_mip_obj_val (ats->prob));
1199 _lp_get_col_name(ats->prob,2*c_mechs+3),
1200 _lp_get_col_prim(ats->prob,2*c_mechs+3));
1201 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "objective value: %f\n",
1202 _lp_mip_obj_val(ats->prob));
1203 } 1205 }
1204#endif 1206#endif
1205} 1207}
1206 1208
1207 1209
1208void ats_shutdown (struct ATS_Handle * ats) 1210void
1211ats_shutdown (struct ATS_Handle *ats)
1209{ 1212{
1210#if DEBUG_ATS 1213#if DEBUG_ATS
1211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS shutdown\n"); 1214 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ATS shutdown\n");
1212#endif 1215#endif
1213 ats_delete_problem (ats); 1216 ats_delete_problem (ats);
1214 _lp_free_env(); 1217 _lp_free_env ();
1215 1218
1216 GNUNET_free (ats); 1219 GNUNET_free (ats);
1217} 1220}
1218 1221
1219void ats_update_problem_qm (struct ATS_Handle * ats) 1222void
1223ats_update_problem_qm (struct ATS_Handle *ats)
1220{ 1224{
1221 int array_index; 1225 int array_index;
1222 int row_index; 1226 int row_index;
1223 int c, c2; 1227 int c, c2;
1224 int c_q_metrics = available_quality_metrics; 1228 int c_q_metrics = available_quality_metrics;
1225 1229
1226 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1230 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1227 available_quality_metrics) * sizeof (int)); 1231 available_quality_metrics) * sizeof (int));
1228 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1232 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1229 available_quality_metrics) * sizeof (double)); 1233 available_quality_metrics) * sizeof (double));
1230#if DEBUG_ATS 1234#if DEBUG_ATS
1231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n"); 1235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1232#endif 1236#endif
1233 row_index = ats->internal.begin_qm; 1237 row_index = ats->internal.begin_qm;
1238
1239 for (c = 1; c <= c_q_metrics; c++)
1240 {
1241 array_index = 1;
1242 double value = 1;
1234 1243
1235 for (c=1; c <= c_q_metrics; c++)
1236 {
1237 array_index = 1;
1238 double value = 1;
1239#if VERBOSE_ATS
1240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n",row_index);
1241#endif
1242 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0);
1243 for (c2=1; c2<=ats->internal.c_mechs; c2++)
1244 {
1245 ja[array_index] = c2;
1246 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1247 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1248
1249 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
1250 {
1251 double v0 = 0, v1 = 0, v2 = 0;
1252
1253 v0 = ats->mechanisms[c2].quality[c-1].values[0];
1254 if (v1 < 1) v0 = 0.1;
1255 v1 = ats->mechanisms[c2].quality[c-1].values[1];
1256 if (v1 < 1) v0 = 0.1;
1257 v2 = ats->mechanisms[c2].quality[c-1].values[2];
1258 if (v1 < 1) v0 = 0.1;
1259 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
1260 //value = 1;
1261 }
1262 if (qm[c-1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
1263 {
1264 double v0 = 0, v1 = 0, v2 = 0;
1265 v0 = ats->mechanisms[c2].quality[c-1].values[0];
1266 if (v0 < 1) v0 = 1;
1267 v1 = ats->mechanisms[c2].quality[c-1].values[1];
1268 if (v1 < 1) v1 = 1;
1269 v2 = ats->mechanisms[c2].quality[c-1].values[2];
1270 if (v2 < 1) v2 = 1;
1271 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
1272 if (value >= 1)
1273 value = (double) 10 / value;
1274 else
1275 value = 10;
1276 }
1277 ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
1278#if VERBOSE_ATS 1244#if VERBOSE_ATS
1279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n", 1245 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] \n", row_index);
1280 array_index, 1246#endif
1281 qm[c-1].name, 1247 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
1282 row_index, 1248 for (c2 = 1; c2 <= ats->internal.c_mechs; c2++)
1283 ja[array_index], 1249 {
1284 ar[array_index]); 1250 ja[array_index] = c2;
1285#endif 1251 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1286 array_index++; 1252 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1287 }
1288 ja[array_index] = ats->internal.col_qm + c - 1;
1289 ar[array_index] = -1;
1290 1253
1254 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY)
1255 {
1256 double v0 = 0, v1 = 0, v2 = 0;
1257
1258 v0 = ats->mechanisms[c2].quality[c - 1].values[0];
1259 if (v1 < 1)
1260 v0 = 0.1;
1261 v1 = ats->mechanisms[c2].quality[c - 1].values[1];
1262 if (v1 < 1)
1263 v0 = 0.1;
1264 v2 = ats->mechanisms[c2].quality[c - 1].values[2];
1265 if (v1 < 1)
1266 v0 = 0.1;
1267 value = 100.0 / ((v0 + 2 * v1 + 3 * v2) / 6.0);
1268 //value = 1;
1269 }
1270 if (qm[c - 1].atis_index == GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE)
1271 {
1272 double v0 = 0, v1 = 0, v2 = 0;
1273
1274 v0 = ats->mechanisms[c2].quality[c - 1].values[0];
1275 if (v0 < 1)
1276 v0 = 1;
1277 v1 = ats->mechanisms[c2].quality[c - 1].values[1];
1278 if (v1 < 1)
1279 v1 = 1;
1280 v2 = ats->mechanisms[c2].quality[c - 1].values[2];
1281 if (v2 < 1)
1282 v2 = 1;
1283 value = (v0 + 2 * v1 + 3 * v2) / 6.0;
1284 if (value >= 1)
1285 value = (double) 10 / value;
1286 else
1287 value = 10;
1288 }
1289 ar[array_index] = (ats->mechanisms[c2].peer->f) * value;
1291#if VERBOSE_ATS 1290#if VERBOSE_ATS
1292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 1291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: %s [%i,%i]=%f \n",
1293 array_index, 1292 array_index,
1294 row_index, 1293 qm[c - 1].name, row_index, ja[array_index], ar[array_index]);
1295 ja[array_index], 1294#endif
1296 ar[array_index]); 1295 array_index++;
1297#endif
1298 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1299 array_index = 1;
1300 row_index++;
1301 } 1296 }
1302 GNUNET_free_non_null (ja); 1297 ja[array_index] = ats->internal.col_qm + c - 1;
1303 GNUNET_free_non_null (ar); 1298 ar[array_index] = -1;
1299
1300#if VERBOSE_ATS
1301 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
1302 array_index, row_index, ja[array_index], ar[array_index]);
1303#endif
1304 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1305 array_index = 1;
1306 row_index++;
1307 }
1308 GNUNET_free_non_null (ja);
1309 GNUNET_free_non_null (ar);
1304 1310
1305} 1311}
1306 1312
1307 1313
1308void 1314void
1309ats_calculate_bandwidth_distribution (struct ATS_Handle * ats) 1315ats_calculate_bandwidth_distribution (struct ATS_Handle *ats)
1310{ 1316{
1311 struct GNUNET_TIME_Absolute start; 1317 struct GNUNET_TIME_Absolute start;
1312 struct GNUNET_TIME_Relative creation; 1318 struct GNUNET_TIME_Relative creation;
1313 struct GNUNET_TIME_Relative solving; 1319 struct GNUNET_TIME_Relative solving;
1314 int c_m; 1320 int c_m;
1315 int c_p; 1321 int c_p;
1316 char *text = "unmodified"; 1322 char *text = "unmodified";
1317 1323
1318#if FIXME_WACHS 1324#if FIXME_WACHS
1319 int dur; 1325 int dur;
1320 if (INT_MAX < ats->max_exec_duration.rel_value) 1326
1321 dur = INT_MAX; 1327 if (INT_MAX < ats->max_exec_duration.rel_value)
1322 else 1328 dur = INT_MAX;
1323 dur = (int) ats->max_exec_duration.rel_value; 1329 else
1330 dur = (int) ats->max_exec_duration.rel_value;
1324#endif 1331#endif
1325 1332
1326 ats->internal.simplex_rerun_required = GNUNET_NO; 1333 ats->internal.simplex_rerun_required = GNUNET_NO;
1327 start = GNUNET_TIME_absolute_get(); 1334 start = GNUNET_TIME_absolute_get ();
1328 if ((ats->internal.recreate_problem == GNUNET_YES) || 1335 if ((ats->internal.recreate_problem == GNUNET_YES) ||
1329 (ats->prob==NULL) || 1336 (ats->prob == NULL) || (ats->internal.valid == GNUNET_NO))
1330 (ats->internal.valid == GNUNET_NO)) 1337 {
1331 { 1338 text = "new";
1332 text = "new"; 1339 ats->internal.recreate_problem = GNUNET_YES;
1333 ats->internal.recreate_problem = GNUNET_YES; 1340 ats_delete_problem (ats);
1334 ats_delete_problem (ats); 1341 ats->addr_notification (&ats->peers, &c_p, &ats->mechanisms, &c_m);
1335 ats->addr_notification(&ats->peers , &c_p, &ats->mechanisms, &c_m);
1336#if DEBUG_ATS 1342#if DEBUG_ATS
1337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1338 "Service returned: %i peer, %i mechs\n", 1344 "Service returned: %i peer, %i mechs\n", c_p, c_m);
1339 c_p,
1340 c_m);
1341#endif 1345#endif
1342 ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms, c_m); 1346 ats_create_problem (ats, &ats->internal, ats->peers, c_p, ats->mechanisms,
1347 c_m);
1343 1348
1344 1349
1345#if DEBUG_ATS 1350#if DEBUG_ATS
1346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1347 "Peers/Addresses were modified... new problem: %i peer, %i mechs\n", 1352 "Peers/Addresses were modified... new problem: %i peer, %i mechs\n",
1348 ats->internal.c_peers, 1353 ats->internal.c_peers, ats->internal.c_mechs);
1349 ats->internal.c_mechs);
1350#endif 1354#endif
1351 } 1355 }
1352 1356
1353 else if ((ats->internal.recreate_problem == GNUNET_NO) && 1357 else if ((ats->internal.recreate_problem == GNUNET_NO) &&
1354 (ats->internal.modified_resources == GNUNET_YES) && 1358 (ats->internal.modified_resources == GNUNET_YES) &&
1355 (ats->internal.valid == GNUNET_YES)) 1359 (ats->internal.valid == GNUNET_YES))
1356 { 1360 {
1357 text = "modified resources"; 1361 text = "modified resources";
1358 ats_update_problem_cr (ats); 1362 ats_update_problem_cr (ats);
1359 } 1363 }
1360 else if ((ats->internal.recreate_problem == GNUNET_NO) && 1364 else if ((ats->internal.recreate_problem == GNUNET_NO) &&
1361 (ats->internal.modified_quality == GNUNET_YES) && 1365 (ats->internal.modified_quality == GNUNET_YES) &&
1362 (ats->internal.valid == GNUNET_YES)) 1366 (ats->internal.valid == GNUNET_YES))
1363 { 1367 {
1364 text = "modified quality"; 1368 text = "modified quality";
1365 ats_update_problem_qm (ats); 1369 ats_update_problem_qm (ats);
1366 //ats_update_problem_qm_TEST (); 1370 //ats_update_problem_qm_TEST ();
1367 } 1371 }
1368#if DEBUG_ATS 1372#if DEBUG_ATS
1369 else GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text); 1373 else
1374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem is %s\n", text);
1370#endif 1375#endif
1371 1376
1372 creation = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); 1377 creation =
1373 start = GNUNET_TIME_absolute_get(); 1378 GNUNET_TIME_absolute_get_difference (start, GNUNET_TIME_absolute_get ());
1379 start = GNUNET_TIME_absolute_get ();
1374 1380
1375 ats->internal.solution = GLP_UNDEF; 1381 ats->internal.solution = GLP_UNDEF;
1376 if (ats->internal.valid == GNUNET_YES) 1382 if (ats->internal.valid == GNUNET_YES)
1377 { 1383 {
1378 ats_solve_problem(ats, 1384 ats_solve_problem (ats,
1379 ats->max_iterations, 1385 ats->max_iterations,
1380 ats->max_exec_duration.rel_value, 1386 ats->max_exec_duration.rel_value,
1381 ats->internal.c_peers, 1387 ats->internal.c_peers,
1382 ats->internal.c_mechs, 1388 ats->internal.c_mechs, &ats->internal);
1383 &ats->internal); 1389 }
1384 } 1390 solving =
1385 solving = GNUNET_TIME_absolute_get_difference(start,GNUNET_TIME_absolute_get()); 1391 GNUNET_TIME_absolute_get_difference (start, GNUNET_TIME_absolute_get ());
1386 1392
1387 if (ats->internal.valid == GNUNET_YES) 1393 if (ats->internal.valid == GNUNET_YES)
1388 { 1394 {
1389 /* Telling about new distribution*/ 1395 /* Telling about new distribution */
1390 ats->result_cb (); 1396 ats->result_cb ();
1397
1398 int msg_type = GNUNET_ERROR_TYPE_DEBUG;
1391 1399
1392 int msg_type = GNUNET_ERROR_TYPE_DEBUG;
1393#if DEBUG_ATS 1400#if DEBUG_ATS
1394 msg_type = GNUNET_ERROR_TYPE_ERROR; 1401 msg_type = GNUNET_ERROR_TYPE_ERROR;
1395#endif 1402#endif
1396 GNUNET_log (msg_type, 1403 GNUNET_log (msg_type,
1397 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n", 1404 "MLP %s: creation time: %llu, execution time: %llu, %i peers, %i mechanisms, simplex rerun: %s, solution %s\n",
1398 text, 1405 text,
1399 creation.rel_value, 1406 creation.rel_value,
1400 solving.rel_value, 1407 solving.rel_value,
1401 ats->internal.c_peers, 1408 ats->internal.c_peers,
1402 ats->internal.c_mechs, 1409 ats->internal.c_mechs,
1403 (ats->internal.simplex_rerun_required == GNUNET_NO) ? "NO" : "YES", 1410 (ats->internal.simplex_rerun_required ==
1404 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID"); 1411 GNUNET_NO) ? "NO" : "YES",
1405 ats->successful_executions ++; 1412 (ats->internal.solution == 5) ? "OPTIMAL" : "INVALID");
1413 ats->successful_executions++;
1414 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1415 ats->successful_executions, GNUNET_NO);
1416
1417 if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob == NULL))
1418 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_NEW, GNUNET_NO);
1419 else if ((ats->internal.modified_resources == GNUNET_YES) &&
1420 (ats->internal.modified_quality == GNUNET_NO))
1421 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED,
1422 GNUNET_NO);
1423 else if ((ats->internal.modified_resources == GNUNET_NO) &&
1424 (ats->internal.modified_quality == GNUNET_YES) &&
1425 (ats->internal.simplex_rerun_required == GNUNET_NO))
1426 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED,
1427 GNUNET_NO);
1428 else if ((ats->internal.modified_resources == GNUNET_YES) &&
1429 (ats->internal.modified_quality == GNUNET_YES) &&
1430 (ats->internal.simplex_rerun_required == GNUNET_NO))
1431 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_COST_UPDATED,
1432 GNUNET_NO);
1433 else if (ats->internal.simplex_rerun_required == GNUNET_NO)
1434 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED,
1435 GNUNET_NO);
1436 }
1437 else
1438 {
1439 if (ats->internal.c_peers != 0)
1440 {
1441 ats->invalid_executions++;
1442 GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
1443 ats->invalid_executions, GNUNET_NO);
1444 }
1445 else
1446 {
1406 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions", 1447 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1407 ats->successful_executions, 1448 ats->successful_executions, GNUNET_NO);
1408 GNUNET_NO); 1449 }
1409 1450 }
1410 if ((ats->internal.recreate_problem == GNUNET_YES) || (ats->prob==NULL)) 1451
1411 GNUNET_STATISTICS_set (ats->stats, "ATS state",ATS_NEW, GNUNET_NO); 1452 GNUNET_STATISTICS_set (ats->stats,
1412 else if ((ats->internal.modified_resources == GNUNET_YES) && 1453 "ATS duration", solving.rel_value + creation.rel_value,
1413 (ats->internal.modified_quality == GNUNET_NO)) 1454 GNUNET_NO);
1414 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_COST_UPDATED, GNUNET_NO); 1455 GNUNET_STATISTICS_set (ats->stats, "ATS mechanisms", ats->internal.c_mechs,
1415 else if ((ats->internal.modified_resources == GNUNET_NO) && 1456 GNUNET_NO);
1416 (ats->internal.modified_quality == GNUNET_YES) && 1457 GNUNET_STATISTICS_set (ats->stats, "ATS peers", ats->internal.c_peers,
1417 (ats->internal.simplex_rerun_required == GNUNET_NO)) 1458 GNUNET_NO);
1418 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_UPDATED, GNUNET_NO); 1459 GNUNET_STATISTICS_set (ats->stats, "ATS solution", ats->internal.solution,
1419 else if ((ats->internal.modified_resources == GNUNET_YES) && 1460 GNUNET_NO);
1420 (ats->internal.modified_quality == GNUNET_YES) && 1461 GNUNET_STATISTICS_set (ats->stats, "ATS timestamp", start.abs_value,
1421 (ats->internal.simplex_rerun_required == GNUNET_NO)) 1462 GNUNET_NO);
1422 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_QUALITY_COST_UPDATED, GNUNET_NO); 1463
1423 else if (ats->internal.simplex_rerun_required == GNUNET_NO) 1464 if ((ats->save_mlp == GNUNET_YES) &&
1424 GNUNET_STATISTICS_set (ats->stats, "ATS state", ATS_UNMODIFIED, GNUNET_NO); 1465 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1466 (ats->internal.c_mechs >= ats->dump_min_addr))
1467 {
1468 char *filename;
1469
1470 if (ats->dump_overwrite == GNUNET_NO)
1471 {
1472 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp",
1473 ats->internal.c_peers,
1474 ats->internal.c_mechs,
1475 text, GNUNET_TIME_absolute_get ().abs_value);
1476 _lp_write_lp ((void *) ats->prob, NULL, filename);
1425 } 1477 }
1426 else 1478 else
1427 { 1479 {
1428 if (ats->internal.c_peers != 0) 1480 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp",
1429 { 1481 ats->internal.c_peers, ats->internal.c_mechs);
1430 ats->invalid_executions ++; 1482 _lp_write_lp ((void *) ats->prob, NULL, filename);
1431 GNUNET_STATISTICS_set (ats->stats, "# ATS invalid executions",
1432 ats->invalid_executions, GNUNET_NO);
1433 }
1434 else
1435 {
1436 GNUNET_STATISTICS_set (ats->stats, "# ATS successful executions",
1437 ats->successful_executions, GNUNET_NO);
1438 }
1439 } 1483 }
1484 GNUNET_free (filename);
1485 }
1486 if ((ats->save_solution == GNUNET_YES) &&
1487 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1488 (ats->internal.c_mechs >= ats->dump_min_addr))
1489 {
1490 char *filename;
1440 1491
1441 GNUNET_STATISTICS_set (ats->stats, 1492 if (ats->dump_overwrite == GNUNET_NO)
1442 "ATS duration", solving.rel_value + creation.rel_value, GNUNET_NO);
1443 GNUNET_STATISTICS_set (ats->stats,
1444 "ATS mechanisms", ats->internal.c_mechs, GNUNET_NO);
1445 GNUNET_STATISTICS_set (ats->stats,
1446 "ATS peers", ats->internal.c_peers, GNUNET_NO);
1447 GNUNET_STATISTICS_set (ats->stats,
1448 "ATS solution", ats->internal.solution, GNUNET_NO);
1449 GNUNET_STATISTICS_set (ats->stats,
1450 "ATS timestamp", start.abs_value, GNUNET_NO);
1451
1452 if ((ats->save_mlp == GNUNET_YES) &&
1453 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1454 (ats->internal.c_mechs >= ats->dump_min_addr))
1455 { 1493 {
1456 char * filename; 1494 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
1457 if (ats->dump_overwrite == GNUNET_NO) 1495 ats->internal.c_peers,
1458 { 1496 ats->internal.c_mechs,
1459 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.mlp", 1497 text, GNUNET_TIME_absolute_get ().abs_value);
1460 ats->internal.c_peers, 1498 _lp_print_sol (ats->prob, filename);
1461 ats->internal.c_mechs,
1462 text,
1463 GNUNET_TIME_absolute_get().abs_value);
1464 _lp_write_lp ((void *) ats->prob, NULL, filename);
1465 }
1466 else
1467 {
1468 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.mlp",
1469 ats->internal.c_peers, ats->internal.c_mechs );
1470 _lp_write_lp ((void *) ats->prob, NULL, filename);
1471 }
1472 GNUNET_free (filename);
1473 } 1499 }
1474 if ((ats->save_solution == GNUNET_YES) && 1500 else
1475 (ats->internal.c_mechs >= ats->dump_min_peers) &&
1476 (ats->internal.c_mechs >= ats->dump_min_addr))
1477 { 1501 {
1478 char * filename; 1502 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol",
1479 if (ats->dump_overwrite == GNUNET_NO) 1503 ats->internal.c_peers, ats->internal.c_mechs);
1480 { 1504 _lp_print_sol (ats->prob, filename);
1481 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i_%s_%llu.sol",
1482 ats->internal.c_peers,
1483 ats->internal.c_mechs,
1484 text,
1485 GNUNET_TIME_absolute_get().abs_value);
1486 _lp_print_sol (ats->prob, filename);
1487 }
1488 else
1489 {
1490 GNUNET_asprintf (&filename, "ats_mlp_p%i_m%i.sol",
1491 ats->internal.c_peers, ats->internal.c_mechs);
1492 _lp_print_sol (ats->prob, filename);
1493 }
1494 GNUNET_free (filename);
1495 } 1505 }
1506 GNUNET_free (filename);
1507 }
1496 1508
1497 ats->internal.recreate_problem = GNUNET_NO; 1509 ats->internal.recreate_problem = GNUNET_NO;
1498 ats->internal.modified_resources = GNUNET_NO; 1510 ats->internal.modified_resources = GNUNET_NO;
1499 ats->internal.modified_quality = GNUNET_NO; 1511 ats->internal.modified_quality = GNUNET_NO;
1500} 1512}
1501 1513
1502/** 1514/**
@@ -1508,198 +1520,188 @@ ats_calculate_bandwidth_distribution (struct ATS_Handle * ats)
1508 * valid 1520 * valid
1509 */ 1521 */
1510 1522
1511int ats_evaluate_results (int result, int solution, char * problem) 1523int
1524ats_evaluate_results (int result, int solution, char *problem)
1512{ 1525{
1513 int cont = GNUNET_NO; 1526 int cont = GNUNET_NO;
1527
1514#if DEBUG_ATS || VERBOSE_ATS 1528#if DEBUG_ATS || VERBOSE_ATS
1515 int error_kind = GNUNET_ERROR_TYPE_DEBUG; 1529 int error_kind = GNUNET_ERROR_TYPE_DEBUG;
1516#endif 1530#endif
1517#if VERBOSE_ATS 1531#if VERBOSE_ATS
1518 error_kind = GNUNET_ERROR_TYPE_ERROR; 1532 error_kind = GNUNET_ERROR_TYPE_ERROR;
1519#endif 1533#endif
1520 switch (result) { 1534 switch (result)
1521 case GNUNET_SYSERR : /* GNUNET problem, not GLPK related */ 1535 {
1536 case GNUNET_SYSERR: /* GNUNET problem, not GLPK related */
1522#if DEBUG_ATS || VERBOSE_ATS 1537#if DEBUG_ATS || VERBOSE_ATS
1523 GNUNET_log (error_kind, 1538 GNUNET_log (error_kind, "%s, GLPK solving not executed\n", problem);
1524 "%s, GLPK solving not executed\n", problem);
1525#endif 1539#endif
1526 break; 1540 break;
1527 case GLP_ESTOP : /* search terminated by application */ 1541 case GLP_ESTOP: /* search terminated by application */
1528#if DEBUG_ATS || VERBOSE_ATS 1542#if DEBUG_ATS || VERBOSE_ATS
1529 GNUNET_log (error_kind, 1543 GNUNET_log (error_kind, "%s , Search terminated by application\n", problem);
1530 "%s , Search terminated by application\n", problem);
1531#endif 1544#endif
1532 break; 1545 break;
1533 case GLP_EITLIM : /* iteration limit exceeded */ 1546 case GLP_EITLIM: /* iteration limit exceeded */
1534#if DEBUG_ATS || VERBOSE_ATS 1547#if DEBUG_ATS || VERBOSE_ATS
1535 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1548 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1536 "%s Iteration limit exceeded\n", problem); 1549 "%s Iteration limit exceeded\n", problem);
1537#endif 1550#endif
1538 break; 1551 break;
1539 case GLP_ETMLIM : /* time limit exceeded */ 1552 case GLP_ETMLIM: /* time limit exceeded */
1540#if DEBUG_ATS || VERBOSE_ATS 1553#if DEBUG_ATS || VERBOSE_ATS
1541 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1554 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "%s Time limit exceeded\n", problem);
1542 "%s Time limit exceeded\n", problem);
1543#endif 1555#endif
1544 break; 1556 break;
1545 case GLP_ENOPFS : /* no primal feasible solution */ 1557 case GLP_ENOPFS: /* no primal feasible solution */
1546 case GLP_ENODFS : /* no dual feasible solution */ 1558 case GLP_ENODFS: /* no dual feasible solution */
1547#if DEBUG_ATS || VERBOSE_ATS 1559#if DEBUG_ATS || VERBOSE_ATS
1548 GNUNET_log (error_kind, 1560 GNUNET_log (error_kind, "%s No feasible solution\n", problem);
1549 "%s No feasible solution\n", problem); 1561#endif
1550#endif 1562 break;
1551 break; 1563 case GLP_EBADB: /* invalid basis */
1552 case GLP_EBADB : /* invalid basis */ 1564 case GLP_ESING: /* singular matrix */
1553 case GLP_ESING : /* singular matrix */ 1565 case GLP_ECOND: /* ill-conditioned matrix */
1554 case GLP_ECOND : /* ill-conditioned matrix */ 1566 case GLP_EBOUND: /* invalid bounds */
1555 case GLP_EBOUND : /* invalid bounds */ 1567 case GLP_EFAIL: /* solver failed */
1556 case GLP_EFAIL : /* solver failed */ 1568 case GLP_EOBJLL: /* objective lower limit reached */
1557 case GLP_EOBJLL : /* objective lower limit reached */ 1569 case GLP_EOBJUL: /* objective upper limit reached */
1558 case GLP_EOBJUL : /* objective upper limit reached */ 1570 case GLP_EROOT: /* root LP optimum not provided */
1559 case GLP_EROOT : /* root LP optimum not provided */
1560#if DEBUG_ATS || VERBOSE_ATS 1571#if DEBUG_ATS || VERBOSE_ATS
1561 GNUNET_log (error_kind, 1572 GNUNET_log (error_kind, "%s Invalid Input data: %i\n", problem, result);
1562 "%s Invalid Input data: %i\n",
1563 problem, result);
1564#endif 1573#endif
1565 break; 1574 break;
1566 case 0: 1575 case 0:
1567#if DEBUG_ATS || VERBOSE_ATS 1576#if DEBUG_ATS || VERBOSE_ATS
1568 GNUNET_log (error_kind, 1577 GNUNET_log (error_kind, "%s Problem has been solved\n", problem);
1569 "%s Problem has been solved\n", problem);
1570#endif 1578#endif
1571 break; 1579 break;
1572 } 1580 }
1573 1581
1574 switch (solution) { 1582 switch (solution)
1575 case GLP_UNDEF: 1583 {
1584 case GLP_UNDEF:
1576#if DEBUG_ATS || VERBOSE_ATS 1585#if DEBUG_ATS || VERBOSE_ATS
1577 GNUNET_log (error_kind, 1586 GNUNET_log (error_kind, "%s solution is undefined\n", problem);
1578 "%s solution is undefined\n", problem);
1579#endif 1587#endif
1580 break; 1588 break;
1581 case GLP_OPT: 1589 case GLP_OPT:
1582#if DEBUG_ATS || VERBOSE_ATS 1590#if DEBUG_ATS || VERBOSE_ATS
1583 GNUNET_log (error_kind, 1591 GNUNET_log (error_kind, "%s solution is optimal\n", problem);
1584 "%s solution is optimal\n", problem);
1585#endif 1592#endif
1586 cont=GNUNET_YES; 1593 cont = GNUNET_YES;
1587 break; 1594 break;
1588 case GLP_FEAS: 1595 case GLP_FEAS:
1589#if DEBUG_ATS || VERBOSE_ATS 1596#if DEBUG_ATS || VERBOSE_ATS
1590 GNUNET_log (error_kind, 1597 GNUNET_log (error_kind,
1591 "%s solution is %s feasible, however, its optimality (or non-optimality) has not been proven\n", 1598 "%s solution is %s feasible, however, its optimality (or non-optimality) has not been proven\n",
1592 problem, (0==strcmp(problem,"LP")?"":"integer")); 1599 problem, (0 == strcmp (problem, "LP") ? "" : "integer"));
1593#endif 1600#endif
1594 cont=GNUNET_YES; 1601 cont = GNUNET_YES;
1595 break; 1602 break;
1596 case GLP_NOFEAS: 1603 case GLP_NOFEAS:
1597#if DEBUG_ATS || VERBOSE_ATS 1604#if DEBUG_ATS || VERBOSE_ATS
1598 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n", 1605 GNUNET_log (error_kind, "%s problem has no %sfeasible solution\n",
1599 problem, (0==strcmp(problem,"LP")?"":"integer ")); 1606 problem, (0 == strcmp (problem, "LP") ? "" : "integer "));
1600#endif 1607#endif
1601 break; 1608 break;
1602 case GLP_INFEAS: 1609 case GLP_INFEAS:
1603#if DEBUG_ATS || VERBOSE_ATS 1610#if DEBUG_ATS || VERBOSE_ATS
1604 GNUNET_log (error_kind, "%s problem is infeasible \n", problem); 1611 GNUNET_log (error_kind, "%s problem is infeasible \n", problem);
1605#endif 1612#endif
1606 break; 1613 break;
1607 case GLP_UNBND: 1614 case GLP_UNBND:
1608#if DEBUG_ATS || VERBOSE_ATS 1615#if DEBUG_ATS || VERBOSE_ATS
1609 GNUNET_log (error_kind, "%s problem is unbounded \n", problem); 1616 GNUNET_log (error_kind, "%s problem is unbounded \n", problem);
1610#endif 1617#endif
1611 default: 1618 default:
1612 break; 1619 break;
1613 } 1620 }
1614return cont; 1621 return cont;
1615} 1622}
1616 1623
1617void ats_update_problem_cr (struct ATS_Handle * ats) 1624void
1625ats_update_problem_cr (struct ATS_Handle *ats)
1618{ 1626{
1619 int array_index; 1627 int array_index;
1620 int row_index; 1628 int row_index;
1621 int c, c2; 1629 int c, c2;
1622 double ct_max, ct_min; 1630 double ct_max, ct_min;
1623
1624 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1625 available_quality_metrics) * sizeof (int));
1626 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 +
1627 available_quality_metrics) * sizeof (double));
1628
1629 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1630 row_index = ats->internal.begin_cr;
1631 array_index = 1;
1632 1631
1633 for (c=0; c<available_ressources; c++) 1632 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1634 { 1633 available_quality_metrics) * sizeof (int));
1635 ct_max = ressources[c].c_max; 1634 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1636 ct_min = ressources[c].c_min; 1635 available_quality_metrics) * sizeof (double));
1636
1637 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Updating problem quality metrics\n");
1638 row_index = ats->internal.begin_cr;
1639 array_index = 1;
1640
1641 for (c = 0; c < available_ressources; c++)
1642 {
1643 ct_max = ressources[c].c_max;
1644 ct_min = ressources[c].c_min;
1637#if VERBOSE_ATS 1645#if VERBOSE_ATS
1638 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n", 1646 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "bounds [row]=[%i] %f..%f\n",
1639 row_index, 1647 row_index, ct_min, ct_max);
1640 ct_min,
1641 ct_max);
1642#endif 1648#endif
1643 _lp_set_row_bnds(ats->prob, row_index, GLP_DB, ct_min, ct_max); 1649 _lp_set_row_bnds (ats->prob, row_index, GLP_DB, ct_min, ct_max);
1644 for (c2=1; c2<=ats->internal.c_mechs; c2++) 1650 for (c2 = 1; c2 <= ats->internal.c_mechs; c2++)
1645 { 1651 {
1646 double value = 0; 1652 double value = 0;
1647 GNUNET_assert (ats->mechanisms[c2].addr != NULL); 1653
1648 GNUNET_assert (ats->mechanisms[c2].peer != NULL); 1654 GNUNET_assert (ats->mechanisms[c2].addr != NULL);
1655 GNUNET_assert (ats->mechanisms[c2].peer != NULL);
1649 1656
1650 ja[array_index] = c2; 1657 ja[array_index] = c2;
1651 value = ats->mechanisms[c2].ressources[c].c; 1658 value = ats->mechanisms[c2].ressources[c].c;
1652 ar[array_index] = value; 1659 ar[array_index] = value;
1653#if VERBOSE_ATS 1660#if VERBOSE_ATS
1654 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n", 1661 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "[index]=[%i]: [%i,%i]=%f \n",
1655 array_index, 1662 array_index, row_index, ja[array_index], ar[array_index]);
1656 row_index,
1657 ja[array_index],
1658 ar[array_index]);
1659#endif 1663#endif
1660 array_index++; 1664 array_index++;
1661 }
1662 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1663 row_index ++;
1664 } 1665 }
1665 GNUNET_free_non_null (ja); 1666 _lp_set_mat_row (ats->prob, row_index, array_index, ja, ar);
1666 GNUNET_free_non_null (ar); 1667 row_index++;
1668 }
1669 GNUNET_free_non_null (ja);
1670 GNUNET_free_non_null (ar);
1667 1671
1668} 1672}
1669 1673
1670void ats_set_logging_options (struct ATS_Handle * ats, 1674void
1671 struct GNUNET_STATISTICS_Handle * stats, 1675ats_set_logging_options (struct ATS_Handle *ats,
1672 const struct GNUNET_CONFIGURATION_Handle *cfg) 1676 struct GNUNET_STATISTICS_Handle *stats,
1677 const struct GNUNET_CONFIGURATION_Handle *cfg)
1673{ 1678{
1674 int minimum_addresses; 1679 int minimum_addresses;
1675 int minimum_peers; 1680 int minimum_peers;
1676 int overwrite_dump; 1681 int overwrite_dump;
1677 int log_solution; 1682 int log_solution;
1678 int log_problem; 1683 int log_problem;
1679 unsigned long long value; 1684 unsigned long long value;
1680 1685
1681 if (ats == NULL) 1686 if (ats == NULL)
1682 return; 1687 return;
1683 log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1688 log_problem = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1684 "transport", 1689 "transport", "DUMP_MLP");
1685 "DUMP_MLP");
1686 log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1690 log_solution = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1687 "transport", 1691 "transport",
1688 "DUMP_SOLUTION"); 1692 "DUMP_SOLUTION");
1689 overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1693 overwrite_dump = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1690 "transport", 1694 "transport",
1691 "DUMP_OVERWRITE"); 1695 "DUMP_OVERWRITE");
1692 if (GNUNET_OK == 1696 if (GNUNET_OK ==
1693 GNUNET_CONFIGURATION_get_value_number(cfg, 1697 GNUNET_CONFIGURATION_get_value_number (cfg,
1694 "transport", 1698 "transport",
1695 "DUMP_MIN_PEERS", 1699 "DUMP_MIN_PEERS", &value))
1696 &value))
1697 minimum_peers = (int) value; 1700 minimum_peers = (int) value;
1698 if (GNUNET_OK == 1701 if (GNUNET_OK ==
1699 GNUNET_CONFIGURATION_get_value_number(cfg, 1702 GNUNET_CONFIGURATION_get_value_number (cfg,
1700 "transport", 1703 "transport",
1701 "DUMP_MIN_ADDRS", 1704 "DUMP_MIN_ADDRS", &value))
1702 &value))
1703 minimum_addresses = (int) value; 1705 minimum_addresses = (int) value;
1704 1706
1705 1707
@@ -1712,64 +1714,58 @@ void ats_set_logging_options (struct ATS_Handle * ats,
1712} 1714}
1713 1715
1714#if 0 1716#if 0
1715static void ats_update_problem_qm_TEST () 1717static void
1718ats_update_problem_qm_TEST ()
1716{ 1719{
1717 int row_index; 1720 int row_index;
1718 int c 1721 int c int c2;
1719 int c2; 1722 int c_old;
1720 int c_old; 1723 int changed = 0;
1721 int changed = 0; 1724
1722 1725 int old_ja[ats->internal.c_mechs + 2];
1723 int old_ja[ats->internal.c_mechs + 2]; 1726 double old_ar[ats->internal.c_mechs + 2];
1724 double old_ar[ats->internal.c_mechs + 2]; 1727
1725 1728 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1726 int *ja = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1729 available_quality_metrics) * sizeof (int));
1727 available_quality_metrics) * sizeof (int)); 1730 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs * 2 + 3 +
1728 double *ar = GNUNET_malloc ((1 + ats->internal.c_mechs*2 + 3 + 1731 available_quality_metrics) * sizeof (double));
1729 available_quality_metrics) * sizeof (double));
1730#if DEBUG_ATS 1732#if DEBUG_ATS
1731 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1732 "Updating problem quality metrics TEST\n"); 1734 "Updating problem quality metrics TEST\n");
1733#endif 1735#endif
1734 if (ats->internal.begin_qm >0) 1736 if (ats->internal.begin_qm > 0)
1735 row_index = ats->internal.begin_qm; 1737 row_index = ats->internal.begin_qm;
1736 else 1738 else
1737 return; 1739 return;
1738 for (c=0; c<available_quality_metrics; c++) 1740 for (c = 0; c < available_quality_metrics; c++)
1741 {
1742 c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar);
1743 _lp_set_row_bnds (ats->prob, row_index, GLP_FX, 0.0, 0.0);
1744 for (c2 = 1; c2 <= c_old; c2++)
1739 { 1745 {
1740 c_old = _lp_get_mat_row (ats->prob, row_index, old_ja, old_ar); 1746 ja[c2] = old_ja[c2];
1741 _lp_set_row_bnds(ats->prob, row_index, GLP_FX, 0.0, 0.0); 1747 if ((changed < 3) && (c2 > 2) && (old_ar[c2] != -1))
1742 for (c2=1; c2<=c_old; c2++)
1743 { 1748 {
1744 ja[c2] = old_ja[c2]; 1749 ar[c2] = old_ar[c2] + 5 - changed;
1745 if ((changed < 3) && (c2>2) && (old_ar[c2] != -1)) 1750 changed++;
1746 { 1751 }
1747 ar[c2] = old_ar[c2] + 5 - changed; 1752 else
1748 changed ++; 1753 ar[c2] = old_ar[c2];
1749 }
1750 else
1751 ar[c2] = old_ar[c2];
1752#if VERBOSE_ATS 1754#if VERBOSE_ATS
1753 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1755 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1754 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n", 1756 "[index]=[%i]: old [%i,%i]=%f new [%i,%i]=%f\n",
1755 c2, 1757 c2,
1756 row_index, 1758 row_index, old_ja[c2], old_ar[c2], row_index, ja[c2], ar[c2]);
1757 old_ja[c2], 1759#endif
1758 old_ar[c2],
1759 row_index,
1760 ja[c2],
1761 ar[c2]);
1762#endif
1763 }
1764 _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
1765 row_index ++;
1766 } 1760 }
1767 GNUNET_free_non_null (ja); 1761 _lp_set_mat_row (ats->prob, row_index, c_old, ja, ar);
1768 GNUNET_free_non_null (ar); 1762 row_index++;
1763 }
1764 GNUNET_free_non_null (ja);
1765 GNUNET_free_non_null (ar);
1769} 1766}
1770#endif 1767#endif
1771 1768
1772 1769
1773 1770
1774/* end of transport_ats.c */ 1771/* end of transport_ats.c */
1775
diff --git a/src/transport/gnunet-service-transport_ats.h b/src/transport/gnunet-service-transport_ats.h
index 5226c24df..d1d789b5f 100644
--- a/src/transport/gnunet-service-transport_ats.h
+++ b/src/transport/gnunet-service-transport_ats.h
@@ -68,10 +68,8 @@ struct ATS_mechanism;
68struct ATS_peer; 68struct ATS_peer;
69 69
70typedef void (*GNUNET_TRANSPORT_ATS_AddressNotification) 70typedef void (*GNUNET_TRANSPORT_ATS_AddressNotification)
71 (struct ATS_peer **peers, 71 (struct ATS_peer ** peers,
72 int * c_p, 72 int *c_p, struct ATS_mechanism ** mechanisms, int *c_m);
73 struct ATS_mechanism ** mechanisms,
74 int * c_m );
75 73
76typedef void (*GNUNET_TRANSPORT_ATS_ResultCallback) (void); 74typedef void (*GNUNET_TRANSPORT_ATS_ResultCallback) (void);
77 75
@@ -119,192 +117,192 @@ struct ATS_internals
119 * result of last GLPK run 117 * result of last GLPK run
120 * 5 == OPTIMAL 118 * 5 == OPTIMAL
121 */ 119 */
122 int solution; 120 int solution;
123 121
124 /** 122 /**
125 * Ressource costs or quality metrics changed 123 * Ressource costs or quality metrics changed
126 * update problem before solving 124 * update problem before solving
127 */ 125 */
128 int modified_resources; 126 int modified_resources;
129 127
130 /** 128 /**
131 * Ressource costs or quality metrics changed, update matrix 129 * Ressource costs or quality metrics changed, update matrix
132 * update problem before solving 130 * update problem before solving
133 */ 131 */
134 int modified_quality; 132 int modified_quality;
135 133
136 /** 134 /**
137 * Peers have connected or disconnected 135 * Peers have connected or disconnected
138 * problem has to be recreated 136 * problem has to be recreated
139 */ 137 */
140 int recreate_problem; 138 int recreate_problem;
141 139
142 /** 140 /**
143 * Was the available basis invalid and we needed to rerun simplex? 141 * Was the available basis invalid and we needed to rerun simplex?
144 */ 142 */
145 int simplex_rerun_required; 143 int simplex_rerun_required;
146 144
147 /** 145 /**
148 * is problem currently valid and can it be solved 146 * is problem currently valid and can it be solved
149 */ 147 */
150 int valid; 148 int valid;
151 149
152 /** 150 /**
153 * Number of transport mechanisms in the problem 151 * Number of transport mechanisms in the problem
154 */ 152 */
155 int c_mechs; 153 int c_mechs;
156 154
157 /** 155 /**
158 * Number of transport mechanisms in the problem 156 * Number of transport mechanisms in the problem
159 */ 157 */
160 int c_peers; 158 int c_peers;
161 159
162 /** 160 /**
163 * row index where quality related rows start 161 * row index where quality related rows start
164 */ 162 */
165 int begin_qm; 163 int begin_qm;
166 164
167 /** 165 /**
168 * row index where quality related rows end 166 * row index where quality related rows end
169 */ 167 */
170 int end_qm; 168 int end_qm;
171 169
172 /** 170 /**
173 * row index where ressource cost related rows start 171 * row index where ressource cost related rows start
174 */ 172 */
175 int begin_cr; 173 int begin_cr;
176 174
177 /** 175 /**
178 * row index where ressource cost related rows end 176 * row index where ressource cost related rows end
179 */ 177 */
180 int end_cr; 178 int end_cr;
181 179
182 /** 180 /**
183 * column index for objective function value d 181 * column index for objective function value d
184 */ 182 */
185 int col_d; 183 int col_d;
186 184
187 /** 185 /**
188 * column index for objective function value u 186 * column index for objective function value u
189 */ 187 */
190 int col_u; 188 int col_u;
191 189
192 /** 190 /**
193 * column index for objective function value r 191 * column index for objective function value r
194 */ 192 */
195 int col_r; 193 int col_r;
196 194
197 /** 195 /**
198 * column index for objective function value quality metrics 196 * column index for objective function value quality metrics
199 */ 197 */
200 int col_qm; 198 int col_qm;
201 199
202 /** 200 /**
203 * column index for objective function value cost ressources 201 * column index for objective function value cost ressources
204 */ 202 */
205 int col_cr; 203 int col_cr;
206}; 204};
207 205
208struct ATS_Handle 206struct ATS_Handle
209{ 207{
210 /* 208 /*
211 * Callback functions 209 * Callback functions
212 */ 210 */
213 211
214 GNUNET_TRANSPORT_ATS_AddressNotification addr_notification; 212 GNUNET_TRANSPORT_ATS_AddressNotification addr_notification;
215 213
216 GNUNET_TRANSPORT_ATS_ResultCallback result_cb; 214 GNUNET_TRANSPORT_ATS_ResultCallback result_cb;
217 215
218 216
219 /** 217 /**
220 * Statistics handle 218 * Statistics handle
221 */ 219 */
222 struct GNUNET_STATISTICS_Handle *stats; 220 struct GNUNET_STATISTICS_Handle *stats;
223 221
224 /** 222 /**
225 * Maximum execution time per calculation 223 * Maximum execution time per calculation
226 */ 224 */
227 struct GNUNET_TIME_Relative max_exec_duration; 225 struct GNUNET_TIME_Relative max_exec_duration;
228 226
229 /** 227 /**
230 * GLPK (MLP) problem object 228 * GLPK (MLP) problem object
231 */ 229 */
232#if HAVE_LIBGLPK 230#if HAVE_LIBGLPK
233 231
234 glp_prob *prob; 232 glp_prob *prob;
235#else 233#else
236 void * prob; 234 void *prob;
237#endif 235#endif
238 236
239 /** 237 /**
240 * Internal information state of the GLPK problem 238 * Internal information state of the GLPK problem
241 */ 239 */
242 struct ATS_internals internal; 240 struct ATS_internals internal;
243 241
244 /** 242 /**
245 * mechanisms used in current problem 243 * mechanisms used in current problem
246 * needed for problem modification 244 * needed for problem modification
247 */ 245 */
248 struct ATS_mechanism * mechanisms; 246 struct ATS_mechanism *mechanisms;
249 247
250 /** 248 /**
251 * peers used in current problem 249 * peers used in current problem
252 * needed for problem modification 250 * needed for problem modification
253 */ 251 */
254 struct ATS_peer * peers; 252 struct ATS_peer *peers;
255 253
256 /** 254 /**
257 * State of the MLP problem 255 * State of the MLP problem
258 * value of ATS_problem_state 256 * value of ATS_problem_state
259 * 257 *
260 */ 258 */
261 int state; 259 int state;
262 260
263 /** 261 /**
264 * number of successful executions 262 * number of successful executions
265 */ 263 */
266 int successful_executions; 264 int successful_executions;
267 265
268 /** 266 /**
269 * number with an invalid result 267 * number with an invalid result
270 */ 268 */
271 int invalid_executions; 269 int invalid_executions;
272 270
273 /** 271 /**
274 * Maximum number of LP iterations per calculation 272 * Maximum number of LP iterations per calculation
275 */ 273 */
276 int max_iterations; 274 int max_iterations;
277 275
278 276
279 /* 277 /*
280 * ATS configuration 278 * ATS configuration
281 */ 279 */
282 280
283 281
284 /** 282 /**
285 * Diversity weight 283 * Diversity weight
286 */ 284 */
287 double D; 285 double D;
288 286
289 /** 287 /**
290 * Utility weight 288 * Utility weight
291 */ 289 */
292 double U; 290 double U;
293 291
294 /** 292 /**
295 * Relativity weight 293 * Relativity weight
296 */ 294 */
297 double R; 295 double R;
298 296
299 /** 297 /**
300 * Minimum bandwidth per peer 298 * Minimum bandwidth per peer
301 */ 299 */
302 int v_b_min; 300 int v_b_min;
303 301
304 /** 302 /**
305 * Minimum number of connections per peer 303 * Minimum number of connections per peer
306 */ 304 */
307 int v_n_min; 305 int v_n_min;
308 306
309 307
310 /** 308 /**
@@ -315,104 +313,104 @@ struct ATS_Handle
315 /** 313 /**
316 * Dump problem to a file? 314 * Dump problem to a file?
317 */ 315 */
318 int save_mlp; 316 int save_mlp;
319 317
320 /** 318 /**
321 * Dump solution to a file 319 * Dump solution to a file
322 */ 320 */
323 int save_solution; 321 int save_solution;
324 322
325 /** 323 /**
326 * Dump solution when minimum peers: 324 * Dump solution when minimum peers:
327 */ 325 */
328 int dump_min_peers; 326 int dump_min_peers;
329 327
330 /** 328 /**
331 * Dump solution when minimum addresses: 329 * Dump solution when minimum addresses:
332 */ 330 */
333 int dump_min_addr; 331 int dump_min_addr;
334 332
335 /** 333 /**
336 * Dump solution overwrite file: 334 * Dump solution overwrite file:
337 */ 335 */
338 int dump_overwrite; 336 int dump_overwrite;
339}; 337};
340 338
341struct ATS_mechanism 339struct ATS_mechanism
342{ 340{
343 struct ATS_mechanism * prev; 341 struct ATS_mechanism *prev;
344 struct ATS_mechanism * next; 342 struct ATS_mechanism *next;
345 struct ForeignAddressList * addr; 343 struct ForeignAddressList *addr;
346 struct ATS_quality_entry * quality; 344 struct ATS_quality_entry *quality;
347 struct ATS_ressource_entry * ressources; 345 struct ATS_ressource_entry *ressources;
348 struct TransportPlugin * plugin; 346 struct TransportPlugin *plugin;
349 struct ATS_peer * peer; 347 struct ATS_peer *peer;
350 int col_index; 348 int col_index;
351 int id; 349 int id;
352 struct ATS_ressource_cost * rc; 350 struct ATS_ressource_cost *rc;
353}; 351};
354 352
355struct ATS_peer 353struct ATS_peer
356{ 354{
357 struct GNUNET_PeerIdentity peer; 355 struct GNUNET_PeerIdentity peer;
358 356
359 struct ATS_mechanism * m_head; 357 struct ATS_mechanism *m_head;
360 struct ATS_mechanism * m_tail; 358 struct ATS_mechanism *m_tail;
361 359
362 /* preference value f */ 360 /* preference value f */
363 double f; 361 double f;
364 362
365 //struct NeighbourList * n; 363 //struct NeighbourList * n;
366}; 364};
367 365
368struct ATS_ressource 366struct ATS_ressource
369{ 367{
370 /* index in ressources array */ 368 /* index in ressources array */
371 int index; 369 int index;
372 /* depending ATSi parameter to calculcate limits */ 370 /* depending ATSi parameter to calculcate limits */
373 int atis_index; 371 int atis_index;
374 /* cfg option to load limits */ 372 /* cfg option to load limits */
375 char * cfg_param; 373 char *cfg_param;
376 /* lower bound */ 374 /* lower bound */
377 double c_min; 375 double c_min;
378 /* upper bound */ 376 /* upper bound */
379 double c_max; 377 double c_max;
380 378
381 /* cofficients for the specific plugins */ 379 /* cofficients for the specific plugins */
382 double c_unix; 380 double c_unix;
383 double c_tcp; 381 double c_tcp;
384 double c_udp; 382 double c_udp;
385 double c_http; 383 double c_http;
386 double c_https; 384 double c_https;
387 double c_wlan; 385 double c_wlan;
388 double c_default; 386 double c_default;
389}; 387};
390 388
391 389
392struct ATS_ressource_entry 390struct ATS_ressource_entry
393{ 391{
394 /* index in ressources array */ 392 /* index in ressources array */
395 int index; 393 int index;
396 /* depending ATSi parameter to calculcate limits */ 394 /* depending ATSi parameter to calculcate limits */
397 int atis_index; 395 int atis_index;
398 /* lower bound */ 396 /* lower bound */
399 double c; 397 double c;
400}; 398};
401 399
402 400
403struct ATS_quality_metric 401struct ATS_quality_metric
404{ 402{
405 int index; 403 int index;
406 int atis_index; 404 int atis_index;
407 char * name; 405 char *name;
408}; 406};
409 407
410struct ATS_quality_entry 408struct ATS_quality_entry
411{ 409{
412 int index; 410 int index;
413 int atsi_index; 411 int atsi_index;
414 uint32_t values[3]; 412 uint32_t values[3];
415 int current; 413 int current;
416}; 414};
417 415
418/* 416/*
@@ -420,12 +418,11 @@ struct ATS_quality_entry
420 */ 418 */
421 419
422 420
423static struct ATS_ressource ressources[] = 421static struct ATS_ressource ressources[] = {
424{ 422 /* FIXME: the coefficients for the specific plugins */
425 /* FIXME: the coefficients for the specific plugins */ 423 {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3},
426 {1, 7, "LAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 1, 3}, 424 {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3},
427 {2, 7, "WAN_BW_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 1, 1, 2, 2, 2, 3}, 425 {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
428 {3, 4, "WLAN_ENERGY_LIMIT", 0, VERY_BIG_DOUBLE_VALUE, 0, 0, 0, 0, 0, 2, 1}
429/* 426/*
430 {4, 4, "COST_ENERGY_CONSUMPTION", VERY_BIG_DOUBLE_VALUE}, 427 {4, 4, "COST_ENERGY_CONSUMPTION", VERY_BIG_DOUBLE_VALUE},
431 {5, 5, "COST_CONNECT", VERY_BIG_DOUBLE_VALUE}, 428 {5, 5, "COST_CONNECT", VERY_BIG_DOUBLE_VALUE},
@@ -439,8 +436,7 @@ static struct ATS_ressource ressources[] =
439 * ATS quality metrics 436 * ATS quality metrics
440 */ 437 */
441 438
442static struct ATS_quality_metric qm[] = 439static struct ATS_quality_metric qm[] = {
443{
444 {1, 1028, "QUALITY_NET_DISTANCE"}, 440 {1, 1028, "QUALITY_NET_DISTANCE"},
445 {2, 1034, "QUALITY_NET_DELAY"}, 441 {2, 1034, "QUALITY_NET_DELAY"},
446}; 442};
@@ -451,61 +447,50 @@ static struct ATS_quality_metric qm[] =
451/* 447/*
452 * ATS functions 448 * ATS functions
453 */ 449 */
454struct ATS_Handle * 450struct ATS_Handle *ats_init (double D,
455ats_init (double D, 451 double U,
456 double U, 452 double R,
457 double R, 453 int v_b_min,
458 int v_b_min, 454 int v_n_min,
459 int v_n_min, 455 int max_iterations,
460 int max_iterations, 456 struct GNUNET_TIME_Relative max_duration,
461 struct GNUNET_TIME_Relative max_duration, 457 GNUNET_TRANSPORT_ATS_AddressNotification
462 GNUNET_TRANSPORT_ATS_AddressNotification address_not, 458 address_not,
463 GNUNET_TRANSPORT_ATS_ResultCallback res_cb); 459 GNUNET_TRANSPORT_ATS_ResultCallback res_cb);
464 460
465void 461void ats_shutdown (struct ATS_Handle *ats);
466ats_shutdown (struct ATS_Handle * ats);
467 462
468void 463void ats_delete_problem (struct ATS_Handle *ats);
469ats_delete_problem (struct ATS_Handle * ats);
470 464
471int 465int
472ats_create_problem (struct ATS_Handle *ats, 466ats_create_problem (struct ATS_Handle *ats,
473 struct ATS_internals *stat, 467 struct ATS_internals *stat,
474 struct ATS_peer *peers, 468 struct ATS_peer *peers,
475 int c_p, 469 int c_p, struct ATS_mechanism *mechanisms, int c_m);
476 struct ATS_mechanism *mechanisms,
477 int c_m);
478 470
479void ats_modify_problem_state (struct ATS_Handle * ats, 471void ats_modify_problem_state (struct ATS_Handle *ats,
480 enum ATS_problem_state s); 472 enum ATS_problem_state s);
481 473
482void 474void ats_calculate_bandwidth_distribution (struct ATS_Handle *ats);
483ats_calculate_bandwidth_distribution (struct ATS_Handle * ats);
484 475
485void 476void
486ats_solve_problem (struct ATS_Handle * ats, 477ats_solve_problem (struct ATS_Handle *ats,
487 unsigned int max_it, 478 unsigned int max_it,
488 unsigned int max_dur, 479 unsigned int max_dur,
489 unsigned int c_peers, 480 unsigned int c_peers,
490 unsigned int c_mechs, 481 unsigned int c_mechs, struct ATS_internals *stat);
491 struct ATS_internals *stat);
492 482
493int 483int ats_evaluate_results (int result, int solution, char *problem);
494ats_evaluate_results (int result,
495 int solution,
496 char * problem);
497 484
498void 485void ats_update_problem_qm (struct ATS_Handle *ats);
499ats_update_problem_qm (struct ATS_Handle * ats);
500 486
501void 487void ats_update_problem_cr (struct ATS_Handle *ats);
502ats_update_problem_cr (struct ATS_Handle * ats);
503 488
504 489
505void 490void
506ats_set_logging_options (struct ATS_Handle * ats, 491ats_set_logging_options (struct ATS_Handle *ats,
507 struct GNUNET_STATISTICS_Handle *stats, 492 struct GNUNET_STATISTICS_Handle *stats,
508 const struct GNUNET_CONFIGURATION_Handle *cfg); 493 const struct GNUNET_CONFIGURATION_Handle *cfg);
509 494
510#endif 495#endif
511/* end of file gnunet-service-transport_ats.h */ 496/* end of file gnunet-service-transport_ats.h */
diff --git a/src/transport/gnunet-service-transport_blacklist.c b/src/transport/gnunet-service-transport_blacklist.c
index 4738cdc0f..7720e467f 100644
--- a/src/transport/gnunet-service-transport_blacklist.c
+++ b/src/transport/gnunet-service-transport_blacklist.c
@@ -162,8 +162,7 @@ static struct GNUNET_CONTAINER_MultiHashMap *blacklist;
162 * @param tc unused 162 * @param tc unused
163 */ 163 */
164static void 164static void
165do_blacklist_check (void *cls, 165do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
166 const struct GNUNET_SCHEDULER_TaskContext *tc);
167 166
168 167
169/** 168/**
@@ -174,8 +173,7 @@ do_blacklist_check (void *cls,
174 * @param client identification of the client 173 * @param client identification of the client
175 */ 174 */
176static void 175static void
177client_disconnect_notification (void *cls, 176client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
178 struct GNUNET_SERVER_Client *client)
179{ 177{
180 struct Blacklisters *bl; 178 struct Blacklisters *bl;
181 struct GST_BlacklistCheck *bc; 179 struct GST_BlacklistCheck *bc;
@@ -183,31 +181,28 @@ client_disconnect_notification (void *cls,
183 if (client == NULL) 181 if (client == NULL)
184 return; 182 return;
185 for (bl = bl_head; bl != NULL; bl = bl->next) 183 for (bl = bl_head; bl != NULL; bl = bl->next)
184 {
185 if (bl->client != client)
186 continue;
187 for (bc = bc_head; bc != NULL; bc = bc->next)
186 { 188 {
187 if (bl->client != client) 189 if (bc->bl_pos != bl)
188 continue; 190 continue;
189 for (bc = bc_head; bc != NULL; bc = bc->next) 191 bc->bl_pos = bl->next;
190 { 192 if (bc->th != NULL)
191 if (bc->bl_pos != bl) 193 {
192 continue; 194 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
193 bc->bl_pos = bl->next; 195 bc->th = NULL;
194 if (bc->th != NULL) 196 }
195 { 197 if (bc->task == GNUNET_SCHEDULER_NO_TASK)
196 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th); 198 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
197 bc->th = NULL;
198 }
199 if (bc->task == GNUNET_SCHEDULER_NO_TASK)
200 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check,
201 bc);
202 break;
203 }
204 GNUNET_CONTAINER_DLL_remove (bl_head,
205 bl_tail,
206 bl);
207 GNUNET_SERVER_client_drop (bl->client);
208 GNUNET_free (bl);
209 break; 199 break;
210 } 200 }
201 GNUNET_CONTAINER_DLL_remove (bl_head, bl_tail, bl);
202 GNUNET_SERVER_client_drop (bl->client);
203 GNUNET_free (bl);
204 break;
205 }
211} 206}
212 207
213 208
@@ -234,153 +229,152 @@ read_blacklist_file ()
234 if (GNUNET_OK != 229 if (GNUNET_OK !=
235 GNUNET_CONFIGURATION_get_value_filename (GST_cfg, 230 GNUNET_CONFIGURATION_get_value_filename (GST_cfg,
236 "TRANSPORT", 231 "TRANSPORT",
237 "BLACKLIST_FILE", 232 "BLACKLIST_FILE", &fn))
238 &fn)) 233 {
239 {
240#if DEBUG_TRANSPORT 234#if DEBUG_TRANSPORT
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Option `%s' in section `%s' not specified!\n", 236 "Option `%s' in section `%s' not specified!\n",
243 "BLACKLIST_FILE", 237 "BLACKLIST_FILE", "TRANSPORT");
244 "TRANSPORT");
245#endif 238#endif
246 return; 239 return;
247 } 240 }
248 if (GNUNET_OK != GNUNET_DISK_file_test (fn)) 241 if (GNUNET_OK != GNUNET_DISK_file_test (fn))
249 GNUNET_DISK_fn_write (fn, NULL, 0, 242 GNUNET_DISK_fn_write (fn, NULL, 0,
250 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 243 GNUNET_DISK_PERM_USER_READ |
244 GNUNET_DISK_PERM_USER_WRITE);
251 if (0 != STAT (fn, &frstat)) 245 if (0 != STAT (fn, &frstat))
252 { 246 {
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 247 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 _("Could not read blacklist file `%s'\n"), 248 _("Could not read blacklist file `%s'\n"), fn);
255 fn); 249 GNUNET_free (fn);
256 GNUNET_free (fn); 250 return;
257 return; 251 }
258 }
259 if (frstat.st_size == 0) 252 if (frstat.st_size == 0)
260 { 253 {
261#if DEBUG_TRANSPORT 254#if DEBUG_TRANSPORT
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
263 _("Blacklist file `%s' is empty.\n"), 256 _("Blacklist file `%s' is empty.\n"), fn);
264 fn);
265#endif 257#endif
266 GNUNET_free (fn); 258 GNUNET_free (fn);
267 return; 259 return;
268 } 260 }
269 /* FIXME: use mmap */ 261 /* FIXME: use mmap */
270 data = GNUNET_malloc_large (frstat.st_size); 262 data = GNUNET_malloc_large (frstat.st_size);
271 GNUNET_assert(data != NULL); 263 GNUNET_assert (data != NULL);
272 if (frstat.st_size != 264 if (frstat.st_size != GNUNET_DISK_fn_read (fn, data, frstat.st_size))
273 GNUNET_DISK_fn_read (fn, data, frstat.st_size)) 265 {
266 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
267 _("Failed to read blacklist from `%s'\n"), fn);
268 GNUNET_free (fn);
269 GNUNET_free (data);
270 return;
271 }
272 entries_found = 0;
273 pos = 0;
274 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
275 pos++;
276 while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
277 (pos <=
278 frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
279 {
280 colon_pos = pos;
281 while ((colon_pos < frstat.st_size) &&
282 (data[colon_pos] != ':') &&
283 (!isspace ((unsigned char) data[colon_pos])))
284 colon_pos++;
285 if (colon_pos >= frstat.st_size)
274 { 286 {
275 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 287 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
276 _("Failed to read blacklist from `%s'\n"), 288 _
277 fn); 289 ("Syntax error in blacklist file at offset %llu, giving up!\n"),
290 (unsigned long long) colon_pos);
278 GNUNET_free (fn); 291 GNUNET_free (fn);
279 GNUNET_free (data); 292 GNUNET_free (data);
280 return; 293 return;
281 } 294 }
282 entries_found = 0; 295
283 pos = 0; 296 if (isspace ((unsigned char) data[colon_pos]))
284 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
285 pos++;
286 while ((frstat.st_size >= sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)) &&
287 (pos <= frstat.st_size - sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)))
288 { 297 {
289 colon_pos = pos; 298 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
290 while ( (colon_pos < frstat.st_size) && 299 _
291 (data[colon_pos] != ':') && 300 ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
292 (! isspace ( (unsigned char) data[colon_pos])) ) 301 (unsigned long long) colon_pos);
293 colon_pos++; 302 pos = colon_pos;
294 if (colon_pos >= frstat.st_size) 303 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
295 { 304 pos++;
296 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 305 continue;
297 _("Syntax error in blacklist file at offset %llu, giving up!\n"), 306 }
298 (unsigned long long) colon_pos); 307 tsize = colon_pos - pos;
299 GNUNET_free (fn); 308 if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) ||
300 GNUNET_free (data); 309 (tsize == 0))
301 return; 310 {
302 } 311 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
303 312 _
304 if (isspace( (unsigned char) data[colon_pos])) 313 ("Syntax error in blacklist file at offset %llu, giving up!\n"),
305 { 314 (unsigned long long) colon_pos);
306 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 315 GNUNET_free (fn);
307 _("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), 316 GNUNET_free (data);
308 (unsigned long long) colon_pos); 317 return;
309 pos = colon_pos; 318 }
310 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
311 pos++;
312 continue;
313 }
314 tsize = colon_pos - pos;
315 if ((pos >= frstat.st_size) || (pos + tsize >= frstat.st_size) || (tsize == 0))
316 {
317 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
318 _("Syntax error in blacklist file at offset %llu, giving up!\n"),
319 (unsigned long long) colon_pos);
320 GNUNET_free (fn);
321 GNUNET_free (data);
322 return;
323 }
324
325 if (tsize < 1)
326 continue;
327 319
328 transport_name = GNUNET_malloc(tsize + 1); 320 if (tsize < 1)
329 memcpy(transport_name, &data[pos], tsize); 321 continue;
330 pos = colon_pos + 1; 322
323 transport_name = GNUNET_malloc (tsize + 1);
324 memcpy (transport_name, &data[pos], tsize);
325 pos = colon_pos + 1;
331#if DEBUG_TRANSPORT 326#if DEBUG_TRANSPORT
332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
333 "Read transport name `%s' in blacklist file.\n", 328 "Read transport name `%s' in blacklist file.\n",
334 transport_name); 329 transport_name);
335#endif 330#endif
336 memcpy (&enc, 331 memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded));
337 &data[pos], 332 if (!isspace
338 sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); 333 ((unsigned char)
339 if (! isspace ( (unsigned char) enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) 334 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1]))
340 { 335 {
341 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 336 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
342 _("Syntax error in blacklist file at offset %llu, skipping bytes.\n"), 337 _
343 (unsigned long long) pos); 338 ("Syntax error in blacklist file at offset %llu, skipping bytes.\n"),
344 pos++; 339 (unsigned long long) pos);
345 while ((pos < frstat.st_size) && (!isspace ( (unsigned char) data[pos]))) 340 pos++;
346 pos++; 341 while ((pos < frstat.st_size) && (!isspace ((unsigned char) data[pos])))
347 GNUNET_free_non_null(transport_name);
348 continue;
349 }
350 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
351 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
352 {
353 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
354 _("Syntax error in blacklist file at offset %llu, skipping bytes `%s'.\n"),
355 (unsigned long long) pos,
356 &enc);
357 }
358 else
359 {
360 if (0 != memcmp (&pid,
361 &GST_my_identity,
362 sizeof (struct GNUNET_PeerIdentity)))
363 {
364 entries_found++;
365 GST_blacklist_add_peer (&pid,
366 transport_name);
367 }
368 else
369 {
370 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
371 _("Found myself `%s' in blacklist (useless, ignored)\n"),
372 GNUNET_i2s (&pid));
373 }
374 }
375 pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
376 GNUNET_free_non_null(transport_name);
377 while ((pos < frstat.st_size) && isspace ( (unsigned char) data[pos]))
378 pos++; 342 pos++;
343 GNUNET_free_non_null (transport_name);
344 continue;
345 }
346 enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1] = '\0';
347 if (GNUNET_OK !=
348 GNUNET_CRYPTO_hash_from_string ((char *) &enc, &pid.hashPubKey))
349 {
350 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
351 _
352 ("Syntax error in blacklist file at offset %llu, skipping bytes `%s'.\n"),
353 (unsigned long long) pos, &enc);
379 } 354 }
380 GNUNET_STATISTICS_update (GST_stats, 355 else
381 "# Transport entries blacklisted", 356 {
382 entries_found, 357 if (0 != memcmp (&pid,
383 GNUNET_NO); 358 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
359 {
360 entries_found++;
361 GST_blacklist_add_peer (&pid, transport_name);
362 }
363 else
364 {
365 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
366 _("Found myself `%s' in blacklist (useless, ignored)\n"),
367 GNUNET_i2s (&pid));
368 }
369 }
370 pos = pos + sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded);
371 GNUNET_free_non_null (transport_name);
372 while ((pos < frstat.st_size) && isspace ((unsigned char) data[pos]))
373 pos++;
374 }
375 GNUNET_STATISTICS_update (GST_stats,
376 "# Transport entries blacklisted",
377 entries_found, GNUNET_NO);
384 GNUNET_free (data); 378 GNUNET_free (data);
385 GNUNET_free (fn); 379 GNUNET_free (fn);
386} 380}
@@ -396,8 +390,7 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server)
396{ 390{
397 read_blacklist_file (); 391 read_blacklist_file ();
398 GNUNET_SERVER_disconnect_notify (server, 392 GNUNET_SERVER_disconnect_notify (server,
399 &client_disconnect_notification, 393 &client_disconnect_notification, NULL);
400 NULL);
401} 394}
402 395
403 396
@@ -410,9 +403,7 @@ GST_blacklist_start (struct GNUNET_SERVER_Handle *server)
410 * @return GNUNET_OK (continue to iterate) 403 * @return GNUNET_OK (continue to iterate)
411 */ 404 */
412static int 405static int
413free_blacklist_entry (void *cls, 406free_blacklist_entry (void *cls, const GNUNET_HashCode * key, void *value)
414 const GNUNET_HashCode *key,
415 void *value)
416{ 407{
417 char *be = value; 408 char *be = value;
418 409
@@ -428,13 +419,12 @@ void
428GST_blacklist_stop () 419GST_blacklist_stop ()
429{ 420{
430 if (NULL != blacklist) 421 if (NULL != blacklist)
431 { 422 {
432 GNUNET_CONTAINER_multihashmap_iterate (blacklist, 423 GNUNET_CONTAINER_multihashmap_iterate (blacklist,
433 &free_blacklist_entry, 424 &free_blacklist_entry, NULL);
434 NULL); 425 GNUNET_CONTAINER_multihashmap_destroy (blacklist);
435 GNUNET_CONTAINER_multihashmap_destroy (blacklist); 426 blacklist = NULL;
436 blacklist = NULL; 427 }
437 }
438} 428}
439 429
440 430
@@ -447,9 +437,7 @@ GST_blacklist_stop ()
447 * @return number of bytes copied to buf 437 * @return number of bytes copied to buf
448 */ 438 */
449static size_t 439static size_t
450transmit_blacklist_message (void *cls, 440transmit_blacklist_message (void *cls, size_t size, void *buf)
451 size_t size,
452 void *buf)
453{ 441{
454 struct GST_BlacklistCheck *bc = cls; 442 struct GST_BlacklistCheck *bc = cls;
455 struct Blacklisters *bl; 443 struct Blacklisters *bl;
@@ -457,19 +445,18 @@ transmit_blacklist_message (void *cls,
457 445
458 bc->th = NULL; 446 bc->th = NULL;
459 if (size == 0) 447 if (size == 0)
460 { 448 {
461 GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK); 449 GNUNET_assert (bc->task == GNUNET_SCHEDULER_NO_TASK);
462 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 450 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
463 bc); 451 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
464 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 452 "Failed to send blacklist test for peer `%s' to client\n",
465 "Failed to send blacklist test for peer `%s' to client\n", 453 GNUNET_i2s (&bc->peer));
466 GNUNET_i2s (&bc->peer)); 454 return 0;
467 return 0; 455 }
468 }
469#if DEBUG_TRANSPORT 456#if DEBUG_TRANSPORT
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 "Sending blacklist test for peer `%s' to client\n", 458 "Sending blacklist test for peer `%s' to client\n",
472 GNUNET_i2s (&bc->peer)); 459 GNUNET_i2s (&bc->peer));
473#endif 460#endif
474 bl = bc->bl_pos; 461 bl = bc->bl_pos;
475 bm.header.size = htons (sizeof (struct BlacklistMessage)); 462 bm.header.size = htons (sizeof (struct BlacklistMessage));
@@ -490,8 +477,7 @@ transmit_blacklist_message (void *cls,
490 * @param tc unused 477 * @param tc unused
491 */ 478 */
492static void 479static void
493do_blacklist_check (void *cls, 480do_blacklist_check (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
494 const struct GNUNET_SCHEDULER_TaskContext *tc)
495{ 481{
496 struct GST_BlacklistCheck *bc = cls; 482 struct GST_BlacklistCheck *bc = cls;
497 struct Blacklisters *bl; 483 struct Blacklisters *bl;
@@ -499,27 +485,25 @@ do_blacklist_check (void *cls,
499 bc->task = GNUNET_SCHEDULER_NO_TASK; 485 bc->task = GNUNET_SCHEDULER_NO_TASK;
500 bl = bc->bl_pos; 486 bl = bc->bl_pos;
501 if (bl == NULL) 487 if (bl == NULL)
502 { 488 {
503#if DEBUG_TRANSPORT 489#if DEBUG_TRANSPORT
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
505 "No other blacklist clients active, will allow neighbour `%s'\n", 491 "No other blacklist clients active, will allow neighbour `%s'\n",
506 GNUNET_i2s (&bc->peer)); 492 GNUNET_i2s (&bc->peer));
507#endif 493#endif
508 bc->cont (bc->cont_cls, 494 bc->cont (bc->cont_cls, &bc->peer, GNUNET_OK);
509 &bc->peer, 495 GNUNET_free (bc);
510 GNUNET_OK); 496 return;
511 GNUNET_free (bc); 497 }
512 return; 498 if ((bl->bc != NULL) || (bl->waiting_for_reply != GNUNET_NO))
513 } 499 return; /* someone else busy with this client */
514 if ( (bl->bc != NULL) ||
515 (bl->waiting_for_reply != GNUNET_NO) )
516 return; /* someone else busy with this client */
517 bl->bc = bc; 500 bl->bc = bc;
518 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client, 501 bc->th = GNUNET_SERVER_notify_transmit_ready (bl->client,
519 sizeof (struct BlacklistMessage), 502 sizeof (struct
520 GNUNET_TIME_UNIT_FOREVER_REL, 503 BlacklistMessage),
521 &transmit_blacklist_message, 504 GNUNET_TIME_UNIT_FOREVER_REL,
522 bc); 505 &transmit_blacklist_message,
506 bc);
523} 507}
524 508
525 509
@@ -534,15 +518,13 @@ do_blacklist_check (void *cls,
534 */ 518 */
535static void 519static void
536confirm_or_drop_neighbour (void *cls, 520confirm_or_drop_neighbour (void *cls,
537 const struct GNUNET_PeerIdentity *peer, 521 const struct GNUNET_PeerIdentity *peer, int allowed)
538 int allowed)
539{ 522{
540 if (GNUNET_OK == allowed) 523 if (GNUNET_OK == allowed)
541 return; /* we're done */ 524 return; /* we're done */
542 GNUNET_STATISTICS_update (GST_stats, 525 GNUNET_STATISTICS_update (GST_stats,
543 gettext_noop ("# disconnects due to blacklist"), 526 gettext_noop ("# disconnects due to blacklist"),
544 1, 527 1, GNUNET_NO);
545 GNUNET_NO);
546 GST_neighbours_force_disconnect (peer); 528 GST_neighbours_force_disconnect (peer);
547} 529}
548 530
@@ -554,7 +536,7 @@ struct TestConnectionContext
554{ 536{
555 /** 537 /**
556 * Is this the first neighbour we're checking? 538 * Is this the first neighbour we're checking?
557 */ 539 */
558 int first; 540 int first;
559 541
560 /** 542 /**
@@ -575,9 +557,9 @@ struct TestConnectionContext
575 */ 557 */
576static void 558static void
577test_connection_ok (void *cls, 559test_connection_ok (void *cls,
578 const struct GNUNET_PeerIdentity *neighbour, 560 const struct GNUNET_PeerIdentity *neighbour,
579 const struct GNUNET_TRANSPORT_ATS_Information *ats, 561 const struct GNUNET_TRANSPORT_ATS_Information *ats,
580 uint32_t ats_count) 562 uint32_t ats_count)
581{ 563{
582 struct TestConnectionContext *tcc = cls; 564 struct TestConnectionContext *tcc = cls;
583 struct GST_BlacklistCheck *bc; 565 struct GST_BlacklistCheck *bc;
@@ -589,13 +571,12 @@ test_connection_ok (void *cls,
589 bc->cont_cls = NULL; 571 bc->cont_cls = NULL;
590 bc->bl_pos = tcc->bl; 572 bc->bl_pos = tcc->bl;
591 if (GNUNET_YES == tcc->first) 573 if (GNUNET_YES == tcc->first)
592 { 574 {
593 /* all would wait for the same client, no need to 575 /* all would wait for the same client, no need to
594 create more than just the first task right now */ 576 * create more than just the first task right now */
595 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 577 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
596 bc); 578 tcc->first = GNUNET_NO;
597 tcc->first = GNUNET_NO; 579 }
598 }
599} 580}
600 581
601 582
@@ -611,23 +592,23 @@ test_connection_ok (void *cls,
611 */ 592 */
612void 593void
613GST_blacklist_handle_init (void *cls, 594GST_blacklist_handle_init (void *cls,
614 struct GNUNET_SERVER_Client *client, 595 struct GNUNET_SERVER_Client *client,
615 const struct GNUNET_MessageHeader *message) 596 const struct GNUNET_MessageHeader *message)
616{ 597{
617 struct Blacklisters *bl; 598 struct Blacklisters *bl;
618 struct TestConnectionContext tcc; 599 struct TestConnectionContext tcc;
619 600
620 bl = bl_head; 601 bl = bl_head;
621 while (bl != NULL) 602 while (bl != NULL)
603 {
604 if (bl->client == client)
622 { 605 {
623 if (bl->client == client) 606 GNUNET_break (0);
624 { 607 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
625 GNUNET_break (0); 608 return;
626 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
627 return;
628 }
629 bl = bl->next;
630 } 609 }
610 bl = bl->next;
611 }
631 bl = GNUNET_malloc (sizeof (struct Blacklisters)); 612 bl = GNUNET_malloc (sizeof (struct Blacklisters));
632 bl->client = client; 613 bl->client = client;
633 GNUNET_SERVER_client_keep (client); 614 GNUNET_SERVER_client_keep (client);
@@ -636,8 +617,7 @@ GST_blacklist_handle_init (void *cls,
636 /* confirm that all existing connections are OK! */ 617 /* confirm that all existing connections are OK! */
637 tcc.bl = bl; 618 tcc.bl = bl;
638 tcc.first = GNUNET_YES; 619 tcc.first = GNUNET_YES;
639 GST_neighbours_iterate (&test_connection_ok, 620 GST_neighbours_iterate (&test_connection_ok, &tcc);
640 &tcc);
641} 621}
642 622
643 623
@@ -650,65 +630,61 @@ GST_blacklist_handle_init (void *cls,
650 */ 630 */
651void 631void
652GST_blacklist_handle_reply (void *cls, 632GST_blacklist_handle_reply (void *cls,
653 struct GNUNET_SERVER_Client *client, 633 struct GNUNET_SERVER_Client *client,
654 const struct GNUNET_MessageHeader *message) 634 const struct GNUNET_MessageHeader *message)
655{ 635{
656 const struct BlacklistMessage *msg = (const struct BlacklistMessage*) message; 636 const struct BlacklistMessage *msg =
637 (const struct BlacklistMessage *) message;
657 struct Blacklisters *bl; 638 struct Blacklisters *bl;
658 struct GST_BlacklistCheck *bc; 639 struct GST_BlacklistCheck *bc;
659 640
660 bl = bl_head; 641 bl = bl_head;
661 while ( (bl != NULL) && 642 while ((bl != NULL) && (bl->client != client))
662 (bl->client != client) )
663 bl = bl->next; 643 bl = bl->next;
664 if (bl == NULL) 644 if (bl == NULL)
665 { 645 {
666#if DEBUG_TRANSPORT 646#if DEBUG_TRANSPORT
667 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist client disconnected\n");
668 "Blacklist client disconnected\n");
669#endif 648#endif
670 /* FIXME: other error handling here!? */ 649 /* FIXME: other error handling here!? */
671 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 650 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
672 return; 651 return;
673 } 652 }
674 bc = bl->bc; 653 bc = bl->bc;
675 bl->bc = NULL; 654 bl->bc = NULL;
676 bl->waiting_for_reply = GNUNET_NO; 655 bl->waiting_for_reply = GNUNET_NO;
677 if (NULL != bc) 656 if (NULL != bc)
657 {
658 /* only run this if the blacklist check has not been
659 * cancelled in the meantime... */
660 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
678 { 661 {
679 /* only run this if the blacklist check has not been
680 cancelled in the meantime... */
681 if (ntohl (msg->is_allowed) == GNUNET_SYSERR)
682 {
683#if DEBUG_TRANSPORT 662#if DEBUG_TRANSPORT
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
685 "Blacklist check failed, peer not allowed\n"); 664 "Blacklist check failed, peer not allowed\n");
686#endif 665#endif
687 bc->cont (bc->cont_cls, &bc->peer, GNUNET_NO); 666 bc->cont (bc->cont_cls, &bc->peer, GNUNET_NO);
688 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); 667 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
689 GNUNET_free (bc); 668 GNUNET_free (bc);
690 } 669 }
691 else 670 else
692 { 671 {
693#if DEBUG_TRANSPORT 672#if DEBUG_TRANSPORT
694 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 673 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
695 "Blacklist check succeeded, continuing with checks\n"); 674 "Blacklist check succeeded, continuing with checks\n");
696#endif 675#endif
697 bc->bl_pos = bc->bl_pos->next; 676 bc->bl_pos = bc->bl_pos->next;
698 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 677 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
699 bc);
700 }
701 } 678 }
679 }
702 /* check if any other bc's are waiting for this blacklister */ 680 /* check if any other bc's are waiting for this blacklister */
703 bc = bc_head; 681 bc = bc_head;
704 for (bc = bc_head; bc != NULL; bc = bc->next) 682 for (bc = bc_head; bc != NULL; bc = bc->next)
705 if ( (bc->bl_pos == bl) && 683 if ((bc->bl_pos == bl) && (GNUNET_SCHEDULER_NO_TASK == bc->task))
706 (GNUNET_SCHEDULER_NO_TASK == bc->task) ) 684 {
707 { 685 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
708 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 686 break;
709 bc); 687 }
710 break;
711 }
712} 688}
713 689
714 690
@@ -720,20 +696,19 @@ GST_blacklist_handle_reply (void *cls,
720 */ 696 */
721void 697void
722GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, 698GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
723 const char *transport_name) 699 const char *transport_name)
724{ 700{
725#if DEBUG_TRANSPORT 701#if DEBUG_TRANSPORT
726 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
727 "Adding peer `%s' with plugin `%s' to blacklist\n", 703 "Adding peer `%s' with plugin `%s' to blacklist\n",
728 GNUNET_i2s (peer), 704 GNUNET_i2s (peer), transport_name);
729 transport_name);
730#endif 705#endif
731 if (blacklist == NULL) 706 if (blacklist == NULL)
732 blacklist = GNUNET_CONTAINER_multihashmap_create(TRANSPORT_BLACKLIST_HT_SIZE); 707 blacklist =
733 GNUNET_CONTAINER_multihashmap_put (blacklist, 708 GNUNET_CONTAINER_multihashmap_create (TRANSPORT_BLACKLIST_HT_SIZE);
734 &peer->hashPubKey, 709 GNUNET_CONTAINER_multihashmap_put (blacklist, &peer->hashPubKey,
735 GNUNET_strdup (transport_name), 710 GNUNET_strdup (transport_name),
736 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 711 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
737} 712}
738 713
739 714
@@ -747,16 +722,13 @@ GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
747 * @return GNUNET_OK if the entry does not match, GNUNET_NO if it matches 722 * @return GNUNET_OK if the entry does not match, GNUNET_NO if it matches
748 */ 723 */
749static int 724static int
750test_blacklisted (void *cls, 725test_blacklisted (void *cls, const GNUNET_HashCode * key, void *value)
751 const GNUNET_HashCode *key,
752 void *value)
753{ 726{
754 const char *transport_name = cls; 727 const char *transport_name = cls;
755 char *be = value; 728 char *be = value;
756 729
757 if (0 == strcmp (transport_name, 730 if (0 == strcmp (transport_name, be))
758 be)) 731 return GNUNET_NO; /* abort iteration! */
759 return GNUNET_NO; /* abort iteration! */
760 return GNUNET_OK; 732 return GNUNET_OK;
761} 733}
762 734
@@ -773,36 +745,34 @@ test_blacklisted (void *cls,
773 */ 745 */
774struct GST_BlacklistCheck * 746struct GST_BlacklistCheck *
775GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, 747GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
776 const char *transport_name, 748 const char *transport_name,
777 GST_BlacklistTestContinuation cont, 749 GST_BlacklistTestContinuation cont, void *cont_cls)
778 void *cont_cls)
779{ 750{
780 struct GST_BlacklistCheck *bc; 751 struct GST_BlacklistCheck *bc;
781 752
782 if ( (blacklist != NULL) && 753 if ((blacklist != NULL) &&
783 (GNUNET_SYSERR == 754 (GNUNET_SYSERR ==
784 GNUNET_CONTAINER_multihashmap_get_multiple (blacklist, 755 GNUNET_CONTAINER_multihashmap_get_multiple (blacklist,
785 &peer->hashPubKey, 756 &peer->hashPubKey,
786 &test_blacklisted, 757 &test_blacklisted,
787 (void*) transport_name)) ) 758 (void *) transport_name)))
788 { 759 {
789 /* disallowed by config, disapprove instantly */ 760 /* disallowed by config, disapprove instantly */
790 GNUNET_STATISTICS_update (GST_stats, 761 GNUNET_STATISTICS_update (GST_stats,
791 gettext_noop ("# disconnects due to blacklist"), 762 gettext_noop ("# disconnects due to blacklist"),
792 1, 763 1, GNUNET_NO);
793 GNUNET_NO); 764 if (cont != NULL)
794 if (cont != NULL) 765 cont (cont_cls, peer, GNUNET_NO);
795 cont (cont_cls, peer, GNUNET_NO); 766 return NULL;
796 return NULL; 767 }
797 }
798 768
799 if (bl_head == NULL) 769 if (bl_head == NULL)
800 { 770 {
801 /* no blacklist clients, approve instantly */ 771 /* no blacklist clients, approve instantly */
802 if (cont != NULL) 772 if (cont != NULL)
803 cont (cont_cls, peer, GNUNET_OK); 773 cont (cont_cls, peer, GNUNET_OK);
804 return NULL; 774 return NULL;
805 } 775 }
806 776
807 /* need to query blacklist clients */ 777 /* need to query blacklist clients */
808 bc = GNUNET_malloc (sizeof (struct GST_BlacklistCheck)); 778 bc = GNUNET_malloc (sizeof (struct GST_BlacklistCheck));
@@ -811,11 +781,10 @@ GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer,
811 bc->cont = cont; 781 bc->cont = cont;
812 bc->cont_cls = cont_cls; 782 bc->cont_cls = cont_cls;
813 bc->bl_pos = bl_head; 783 bc->bl_pos = bl_head;
814 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, 784 bc->task = GNUNET_SCHEDULER_add_now (&do_blacklist_check, bc);
815 bc);
816 return bc; 785 return bc;
817} 786}
818 787
819 788
820/** 789/**
821 * Cancel a blacklist check. 790 * Cancel a blacklist check.
@@ -827,25 +796,25 @@ GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc)
827{ 796{
828 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc); 797 GNUNET_CONTAINER_DLL_remove (bc_head, bc_tail, bc);
829 if (bc->bl_pos != NULL) 798 if (bc->bl_pos != NULL)
799 {
800 if (bc->bl_pos->bc == bc)
830 { 801 {
831 if (bc->bl_pos->bc == bc) 802 /* we're at the head of the queue, remove us! */
832 { 803 bc->bl_pos->bc = NULL;
833 /* we're at the head of the queue, remove us! */
834 bc->bl_pos->bc = NULL;
835 }
836 } 804 }
805 }
837 if (GNUNET_SCHEDULER_NO_TASK != bc->task) 806 if (GNUNET_SCHEDULER_NO_TASK != bc->task)
838 { 807 {
839 GNUNET_SCHEDULER_cancel (bc->task); 808 GNUNET_SCHEDULER_cancel (bc->task);
840 bc->task = GNUNET_SCHEDULER_NO_TASK; 809 bc->task = GNUNET_SCHEDULER_NO_TASK;
841 } 810 }
842 if (NULL != bc->th) 811 if (NULL != bc->th)
843 { 812 {
844 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th); 813 GNUNET_CONNECTION_notify_transmit_ready_cancel (bc->th);
845 bc->th = NULL; 814 bc->th = NULL;
846 } 815 }
847 GNUNET_free (bc); 816 GNUNET_free (bc);
848} 817}
849 818
850 819
851/* end of file gnunet-service-transport_blacklist.c */ 820/* end of file gnunet-service-transport_blacklist.c */
diff --git a/src/transport/gnunet-service-transport_blacklist.h b/src/transport/gnunet-service-transport_blacklist.h
index 26309818d..4823d055d 100644
--- a/src/transport/gnunet-service-transport_blacklist.h
+++ b/src/transport/gnunet-service-transport_blacklist.h
@@ -34,15 +34,13 @@
34 * 34 *
35 * @param server server used to accept clients from 35 * @param server server used to accept clients from
36 */ 36 */
37void 37void GST_blacklist_start (struct GNUNET_SERVER_Handle *server);
38GST_blacklist_start (struct GNUNET_SERVER_Handle *server);
39 38
40 39
41/** 40/**
42 * Stop blacklist subsystem. 41 * Stop blacklist subsystem.
43 */ 42 */
44void 43void GST_blacklist_stop (void);
45GST_blacklist_stop (void);
46 44
47 45
48/** 46/**
@@ -56,8 +54,8 @@ GST_blacklist_stop (void);
56 */ 54 */
57void 55void
58GST_blacklist_handle_init (void *cls, 56GST_blacklist_handle_init (void *cls,
59 struct GNUNET_SERVER_Client *client, 57 struct GNUNET_SERVER_Client *client,
60 const struct GNUNET_MessageHeader *message); 58 const struct GNUNET_MessageHeader *message);
61 59
62/** 60/**
63 * A blacklisting client has sent us reply. Process it. 61 * A blacklisting client has sent us reply. Process it.
@@ -68,8 +66,8 @@ GST_blacklist_handle_init (void *cls,
68 */ 66 */
69void 67void
70GST_blacklist_handle_reply (void *cls, 68GST_blacklist_handle_reply (void *cls,
71 struct GNUNET_SERVER_Client *client, 69 struct GNUNET_SERVER_Client *client,
72 const struct GNUNET_MessageHeader *message); 70 const struct GNUNET_MessageHeader *message);
73 71
74/** 72/**
75 * Add the given peer to the blacklist (for the given transport). 73 * Add the given peer to the blacklist (for the given transport).
@@ -79,14 +77,14 @@ GST_blacklist_handle_reply (void *cls,
79 */ 77 */
80void 78void
81GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer, 79GST_blacklist_add_peer (const struct GNUNET_PeerIdentity *peer,
82 const char *transport_name); 80 const char *transport_name);
83 81
84 82
85/** 83/**
86 * Handle to an active blacklist check. 84 * Handle to an active blacklist check.
87 */ 85 */
88struct GST_BlacklistCheck; 86struct GST_BlacklistCheck;
89 87
90 88
91/** 89/**
92 * Continuation called from a blacklist test. 90 * Continuation called from a blacklist test.
@@ -96,9 +94,9 @@ struct GST_BlacklistCheck;
96 * @param result GNUNET_OK if the connection is allowed, 94 * @param result GNUNET_OK if the connection is allowed,
97 * GNUNET_NO if not 95 * GNUNET_NO if not
98 */ 96 */
99typedef void (*GST_BlacklistTestContinuation)(void *cls, 97typedef void (*GST_BlacklistTestContinuation) (void *cls,
100 const struct GNUNET_PeerIdentity *peer, 98 const struct GNUNET_PeerIdentity
101 int result); 99 * peer, int result);
102 100
103 101
104/** 102/**
@@ -111,20 +109,21 @@ typedef void (*GST_BlacklistTestContinuation)(void *cls,
111 * @return handle to the blacklist check, NULL if the decision 109 * @return handle to the blacklist check, NULL if the decision
112 * was made instantly and 'cont' was already called 110 * was made instantly and 'cont' was already called
113 */ 111 */
114struct GST_BlacklistCheck * 112struct GST_BlacklistCheck *GST_blacklist_test_allowed (const struct
115GST_blacklist_test_allowed (const struct GNUNET_PeerIdentity *peer, 113 GNUNET_PeerIdentity
116 const char *transport_name, 114 *peer,
117 GST_BlacklistTestContinuation cont, 115 const char
118 void *cont_cls); 116 *transport_name,
119 117 GST_BlacklistTestContinuation
118 cont, void *cont_cls);
119
120 120
121/** 121/**
122 * Cancel a blacklist check. 122 * Cancel a blacklist check.
123 * 123 *
124 * @param bc check to cancel 124 * @param bc check to cancel
125 */ 125 */
126void 126void GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
127GST_blacklist_test_cancel (struct GST_BlacklistCheck *bc);
128 127
129#endif 128#endif
130/* end of file gnunet-service-transport_blacklist.h */ 129/* end of file gnunet-service-transport_blacklist.h */
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index ca686057d..542e3e00b 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -134,13 +134,13 @@ lookup_client (struct GNUNET_SERVER_Client *client)
134{ 134{
135 struct TransportClient *tc; 135 struct TransportClient *tc;
136 136
137 tc = clients_head; 137 tc = clients_head;
138 while (tc != NULL) 138 while (tc != NULL)
139 { 139 {
140 if (tc->client == client) 140 if (tc->client == client)
141 return tc; 141 return tc;
142 tc = tc->next; 142 tc = tc->next;
143 } 143 }
144 return NULL; 144 return NULL;
145} 145}
146 146
@@ -155,12 +155,10 @@ static struct TransportClient *
155setup_client (struct GNUNET_SERVER_Client *client) 155setup_client (struct GNUNET_SERVER_Client *client)
156{ 156{
157 struct TransportClient *tc; 157 struct TransportClient *tc;
158 158
159 tc = GNUNET_malloc (sizeof (struct TransportClient)); 159 tc = GNUNET_malloc (sizeof (struct TransportClient));
160 tc->client = client; 160 tc->client = client;
161 GNUNET_CONTAINER_DLL_insert (clients_head, 161 GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, tc);
162 clients_tail,
163 tc);
164 return tc; 162 return tc;
165} 163}
166 164
@@ -176,9 +174,7 @@ setup_client (struct GNUNET_SERVER_Client *client)
176 * @return number of bytes written to buf 174 * @return number of bytes written to buf
177 */ 175 */
178static size_t 176static size_t
179transmit_to_client_callback (void *cls, 177transmit_to_client_callback (void *cls, size_t size, void *buf)
180 size_t size,
181 void *buf)
182{ 178{
183 struct TransportClient *tc = cls; 179 struct TransportClient *tc = cls;
184 struct ClientMessageQueueEntry *q; 180 struct ClientMessageQueueEntry *q;
@@ -189,46 +185,43 @@ transmit_to_client_callback (void *cls,
189 185
190 tc->th = NULL; 186 tc->th = NULL;
191 if (buf == NULL) 187 if (buf == NULL)
192 { 188 {
193#if DEBUG_TRANSPORT 189#if DEBUG_TRANSPORT
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Transmission to client failed, closing connection.\n"); 191 "Transmission to client failed, closing connection.\n");
196#endif 192#endif
197 return 0; 193 return 0;
198 } 194 }
199 cbuf = buf; 195 cbuf = buf;
200 tsize = 0; 196 tsize = 0;
201 while (NULL != (q = tc->message_queue_head)) 197 while (NULL != (q = tc->message_queue_head))
202 { 198 {
203 msg = (const struct GNUNET_MessageHeader *) &q[1]; 199 msg = (const struct GNUNET_MessageHeader *) &q[1];
204 msize = ntohs (msg->size); 200 msize = ntohs (msg->size);
205 if (msize + tsize > size) 201 if (msize + tsize > size)
206 break; 202 break;
207#if DEBUG_TRANSPORT 203#if DEBUG_TRANSPORT
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
209 "Transmitting message of type %u to client.\n", 205 "Transmitting message of type %u to client.\n",
210 ntohs (msg->type)); 206 ntohs (msg->type));
211#endif 207#endif
212 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 208 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
213 tc->message_queue_tail, 209 tc->message_queue_tail, q);
214 q); 210 tc->message_count--;
215 tc->message_count--; 211 memcpy (&cbuf[tsize], msg, msize);
216 memcpy (&cbuf[tsize], 212 GNUNET_free (q);
217 msg, 213 tsize += msize;
218 msize); 214 }
219 GNUNET_free (q);
220 tsize += msize;
221 }
222 if (NULL != q) 215 if (NULL != q)
223 { 216 {
224 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 217 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
225 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 218 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
226 msize, 219 msize,
227 GNUNET_TIME_UNIT_FOREVER_REL, 220 GNUNET_TIME_UNIT_FOREVER_REL,
228 &transmit_to_client_callback, 221 &transmit_to_client_callback,
229 tc); 222 tc);
230 GNUNET_assert (tc->th != NULL); 223 GNUNET_assert (tc->th != NULL);
231 } 224 }
232 return tsize; 225 return tsize;
233} 226}
234 227
@@ -242,43 +235,39 @@ transmit_to_client_callback (void *cls,
242 */ 235 */
243static void 236static void
244unicast (struct TransportClient *tc, 237unicast (struct TransportClient *tc,
245 const struct GNUNET_MessageHeader *msg, 238 const struct GNUNET_MessageHeader *msg, int may_drop)
246 int may_drop)
247{ 239{
248 struct ClientMessageQueueEntry *q; 240 struct ClientMessageQueueEntry *q;
249 uint16_t msize; 241 uint16_t msize;
250 242
251 if ( (tc->message_count >= MAX_PENDING) && 243 if ((tc->message_count >= MAX_PENDING) && (GNUNET_YES == may_drop))
252 (GNUNET_YES == may_drop) ) 244 {
253 { 245 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
254 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 246 _
255 _("Dropping message of type %u and size %u, have %u/%u messages pending\n"), 247 ("Dropping message of type %u and size %u, have %u/%u messages pending\n"),
256 ntohs (msg->type), 248 ntohs (msg->type), ntohs (msg->size), tc->message_count,
257 ntohs (msg->size), 249 MAX_PENDING);
258 tc->message_count, 250 GNUNET_STATISTICS_update (GST_stats,
259 MAX_PENDING); 251 gettext_noop
260 GNUNET_STATISTICS_update (GST_stats, 252 ("# messages dropped due to slow client"), 1,
261 gettext_noop ("# messages dropped due to slow client"), 253 GNUNET_NO);
262 1, 254 return;
263 GNUNET_NO); 255 }
264 return;
265 }
266 msize = ntohs (msg->size); 256 msize = ntohs (msg->size);
267 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader)); 257 GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
268 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize); 258 q = GNUNET_malloc (sizeof (struct ClientMessageQueueEntry) + msize);
269 memcpy (&q[1], msg, msize); 259 memcpy (&q[1], msg, msize);
270 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head, 260 GNUNET_CONTAINER_DLL_insert_tail (tc->message_queue_head,
271 tc->message_queue_tail, 261 tc->message_queue_tail, q);
272 q);
273 tc->message_count++; 262 tc->message_count++;
274 if (tc->th != NULL) 263 if (tc->th != NULL)
275 return; 264 return;
276 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client, 265 tc->th = GNUNET_SERVER_notify_transmit_ready (tc->client,
277 msize, 266 msize,
278 GNUNET_TIME_UNIT_FOREVER_REL, 267 GNUNET_TIME_UNIT_FOREVER_REL,
279 &transmit_to_client_callback, 268 &transmit_to_client_callback,
280 tc); 269 tc);
281 GNUNET_assert (tc->th != NULL); 270 GNUNET_assert (tc->th != NULL);
282} 271}
283 272
284 273
@@ -290,8 +279,7 @@ unicast (struct TransportClient *tc,
290 * @param client identification of the client 279 * @param client identification of the client
291 */ 280 */
292static void 281static void
293client_disconnect_notification (void *cls, 282client_disconnect_notification (void *cls, struct GNUNET_SERVER_Client *client)
294 struct GNUNET_SERVER_Client *client)
295{ 283{
296 struct TransportClient *tc; 284 struct TransportClient *tc;
297 struct ClientMessageQueueEntry *mqe; 285 struct ClientMessageQueueEntry *mqe;
@@ -306,21 +294,18 @@ client_disconnect_notification (void *cls,
306 "Client disconnected, cleaning up.\n"); 294 "Client disconnected, cleaning up.\n");
307#endif 295#endif
308 while (NULL != (mqe = tc->message_queue_head)) 296 while (NULL != (mqe = tc->message_queue_head))
309 { 297 {
310 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head, 298 GNUNET_CONTAINER_DLL_remove (tc->message_queue_head,
311 tc->message_queue_tail, 299 tc->message_queue_tail, mqe);
312 mqe); 300 tc->message_count--;
313 tc->message_count--; 301 GNUNET_free (mqe);
314 GNUNET_free (mqe); 302 }
315 } 303 GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, tc);
316 GNUNET_CONTAINER_DLL_remove (clients_head,
317 clients_tail,
318 tc);
319 if (tc->th != NULL) 304 if (tc->th != NULL)
320 { 305 {
321 GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th); 306 GNUNET_CONNECTION_notify_transmit_ready_cancel (tc->th);
322 tc->th = NULL; 307 tc->th = NULL;
323 } 308 }
324 GNUNET_break (0 == tc->message_count); 309 GNUNET_break (0 == tc->message_count);
325 GNUNET_free (tc); 310 GNUNET_free (tc);
326} 311}
@@ -337,24 +322,25 @@ client_disconnect_notification (void *cls,
337 */ 322 */
338static void 323static void
339notify_client_about_neighbour (void *cls, 324notify_client_about_neighbour (void *cls,
340 const struct GNUNET_PeerIdentity *peer, 325 const struct GNUNET_PeerIdentity *peer,
341 const struct GNUNET_TRANSPORT_ATS_Information *ats, 326 const struct GNUNET_TRANSPORT_ATS_Information
342 uint32_t ats_count) 327 *ats, uint32_t ats_count)
343{ 328{
344 struct TransportClient *tc = cls; 329 struct TransportClient *tc = cls;
345 struct ConnectInfoMessage *cim; 330 struct ConnectInfoMessage *cim;
346 size_t size; 331 size_t size;
347 332
348 size = sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information); 333 size =
334 sizeof (struct ConnectInfoMessage) +
335 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information);
349 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE); 336 GNUNET_assert (size < GNUNET_SERVER_MAX_MESSAGE_SIZE);
350 cim = GNUNET_malloc (size); 337 cim = GNUNET_malloc (size);
351 cim->header.size = htons (size); 338 cim->header.size = htons (size);
352 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 339 cim->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
353 cim->ats_count = htonl(ats_count); 340 cim->ats_count = htonl (ats_count);
354 cim->id = *peer; 341 cim->id = *peer;
355 memcpy (&cim->ats, 342 memcpy (&cim->ats,
356 ats, 343 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
357 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
358 unicast (tc, &cim->header, GNUNET_NO); 344 unicast (tc, &cim->header, GNUNET_NO);
359 GNUNET_free (cim); 345 GNUNET_free (cim);
360} 346}
@@ -371,35 +357,35 @@ notify_client_about_neighbour (void *cls,
371 */ 357 */
372static void 358static void
373clients_handle_start (void *cls, 359clients_handle_start (void *cls,
374 struct GNUNET_SERVER_Client *client, 360 struct GNUNET_SERVER_Client *client,
375 const struct GNUNET_MessageHeader *message) 361 const struct GNUNET_MessageHeader *message)
376{ 362{
377 const struct StartMessage *start; 363 const struct StartMessage *start;
378 struct TransportClient *tc; 364 struct TransportClient *tc;
379 365
380 tc = lookup_client (client); 366 tc = lookup_client (client);
381 if (tc != NULL) 367 if (tc != NULL)
382 { 368 {
383 /* got 'start' twice from the same client, not allowed */ 369 /* got 'start' twice from the same client, not allowed */
384 GNUNET_break (0); 370 GNUNET_break (0);
385 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 371 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
386 return; 372 return;
387 } 373 }
388 start = (const struct StartMessage*) message; 374 start = (const struct StartMessage *) message;
389 if ( (GNUNET_NO != ntohl (start->do_check)) && 375 if ((GNUNET_NO != ntohl (start->do_check)) &&
390 (0 != memcmp (&start->self, 376 (0 != memcmp (&start->self,
391 &GST_my_identity, 377 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))))
392 sizeof (struct GNUNET_PeerIdentity))) ) 378 {
393 { 379 /* client thinks this is a different peer, reject */
394 /* client thinks this is a different peer, reject */ 380 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
395 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 381 _
396 _("Rejecting control connection from peer `%s', which is not me!\n"), 382 ("Rejecting control connection from peer `%s', which is not me!\n"),
397 GNUNET_i2s (&start->self)); 383 GNUNET_i2s (&start->self));
398 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 384 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
399 return; 385 return;
400 } 386 }
401 tc = setup_client (client); 387 tc = setup_client (client);
402 unicast (tc, GST_hello_get(), GNUNET_NO); 388 unicast (tc, GST_hello_get (), GNUNET_NO);
403 GST_neighbours_iterate (&notify_client_about_neighbour, tc); 389 GST_neighbours_iterate (&notify_client_about_neighbour, tc);
404 GNUNET_SERVER_receive_done (client, GNUNET_OK); 390 GNUNET_SERVER_receive_done (client, GNUNET_OK);
405} 391}
@@ -414,8 +400,8 @@ clients_handle_start (void *cls,
414 */ 400 */
415static void 401static void
416clients_handle_hello (void *cls, 402clients_handle_hello (void *cls,
417 struct GNUNET_SERVER_Client *client, 403 struct GNUNET_SERVER_Client *client,
418 const struct GNUNET_MessageHeader *message) 404 const struct GNUNET_MessageHeader *message)
419{ 405{
420 GST_validation_handle_hello (message); 406 GST_validation_handle_hello (message);
421 GNUNET_SERVER_receive_done (client, GNUNET_OK); 407 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -447,8 +433,7 @@ struct SendTransmitContinuationContext
447 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected 433 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
448 */ 434 */
449static void 435static void
450handle_send_transmit_continuation (void *cls, 436handle_send_transmit_continuation (void *cls, int success)
451 int success)
452{ 437{
453 struct SendTransmitContinuationContext *stcc = cls; 438 struct SendTransmitContinuationContext *stcc = cls;
454 struct SendOkMessage send_ok_msg; 439 struct SendOkMessage send_ok_msg;
@@ -456,9 +441,10 @@ handle_send_transmit_continuation (void *cls,
456 send_ok_msg.header.size = htons (sizeof (send_ok_msg)); 441 send_ok_msg.header.size = htons (sizeof (send_ok_msg));
457 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK); 442 send_ok_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
458 send_ok_msg.success = htonl (success); 443 send_ok_msg.success = htonl (success);
459 send_ok_msg.latency = GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL); 444 send_ok_msg.latency =
445 GNUNET_TIME_relative_hton (GNUNET_TIME_UNIT_FOREVER_REL);
460 send_ok_msg.peer = stcc->target; 446 send_ok_msg.peer = stcc->target;
461 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO); 447 GST_clients_unicast (stcc->client, &send_ok_msg.header, GNUNET_NO);
462 GNUNET_SERVER_client_drop (stcc->client); 448 GNUNET_SERVER_client_drop (stcc->client);
463 GNUNET_free (stcc); 449 GNUNET_free (stcc);
464} 450}
@@ -473,8 +459,8 @@ handle_send_transmit_continuation (void *cls,
473 */ 459 */
474static void 460static void
475clients_handle_send (void *cls, 461clients_handle_send (void *cls,
476 struct GNUNET_SERVER_Client *client, 462 struct GNUNET_SERVER_Client *client,
477 const struct GNUNET_MessageHeader *message) 463 const struct GNUNET_MessageHeader *message)
478{ 464{
479 const struct OutboundMessage *obm; 465 const struct OutboundMessage *obm;
480 const struct GNUNET_MessageHeader *obmm; 466 const struct GNUNET_MessageHeader *obmm;
@@ -483,56 +469,52 @@ clients_handle_send (void *cls,
483 uint16_t msize; 469 uint16_t msize;
484 470
485 size = ntohs (message->size); 471 size = ntohs (message->size);
486 if (size < sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader)) 472 if (size <
487 { 473 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
488 GNUNET_break (0); 474 {
489 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 475 GNUNET_break (0);
490 return; 476 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
491 } 477 return;
478 }
492 obm = (const struct OutboundMessage *) message; 479 obm = (const struct OutboundMessage *) message;
493 obmm = (const struct GNUNET_MessageHeader *) &obm[1]; 480 obmm = (const struct GNUNET_MessageHeader *) &obm[1];
494 msize = size - sizeof (struct OutboundMessage); 481 msize = size - sizeof (struct OutboundMessage);
495 if (msize < sizeof (struct GNUNET_MessageHeader)) 482 if (msize < sizeof (struct GNUNET_MessageHeader))
496 { 483 {
497 GNUNET_break (0); 484 GNUNET_break (0);
498 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 485 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
499 return; 486 return;
500 } 487 }
501 GNUNET_STATISTICS_update (GST_stats, 488 GNUNET_STATISTICS_update (GST_stats,
502 gettext_noop ("# bytes payload received for other peers"), 489 gettext_noop
503 msize, 490 ("# bytes payload received for other peers"), msize,
504 GNUNET_NO); 491 GNUNET_NO);
505#if DEBUG_TRANSPORT 492#if DEBUG_TRANSPORT
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n", 494 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n",
508 "SEND", 495 "SEND", GNUNET_i2s (&obm->peer), ntohs (obmm->type), msize);
509 GNUNET_i2s (&obm->peer),
510 ntohs (obmm->type),
511 msize);
512#endif 496#endif
513 if (GNUNET_NO == 497 if (GNUNET_NO == GST_neighbours_test_connected (&obm->peer))
514 GST_neighbours_test_connected (&obm->peer)) 498 {
515 { 499 /* not connected, not allowed to send; can happen due to asynchronous operations */
516 /* not connected, not allowed to send; can happen due to asynchronous operations */ 500 GNUNET_STATISTICS_update (GST_stats,
517 GNUNET_STATISTICS_update (GST_stats, 501 gettext_noop
518 gettext_noop ("# bytes payload dropped (other peer was not connected)"), 502 ("# bytes payload dropped (other peer was not connected)"),
519 msize, 503 msize, GNUNET_NO);
520 GNUNET_NO); 504 GNUNET_SERVER_receive_done (client, GNUNET_OK);
521 GNUNET_SERVER_receive_done (client, GNUNET_OK); 505 return;
522 return; 506 }
523 }
524 GNUNET_SERVER_receive_done (client, GNUNET_OK); 507 GNUNET_SERVER_receive_done (client, GNUNET_OK);
525 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext)); 508 stcc = GNUNET_malloc (sizeof (struct SendTransmitContinuationContext));
526 stcc->target = obm->peer; 509 stcc->target = obm->peer;
527 stcc->client = client; 510 stcc->client = client;
528 GNUNET_SERVER_client_keep (client); 511 GNUNET_SERVER_client_keep (client);
529 GST_neighbours_send (&obm->peer, 512 GST_neighbours_send (&obm->peer,
530 obmm, msize, 513 obmm, msize,
531 GNUNET_TIME_relative_ntoh (obm->timeout), 514 GNUNET_TIME_relative_ntoh (obm->timeout),
532 &handle_send_transmit_continuation, 515 &handle_send_transmit_continuation, stcc);
533 stcc);
534} 516}
535 517
536 518
537/** 519/**
538 * Try to initiate a connection to the given peer if the blacklist 520 * Try to initiate a connection to the given peer if the blacklist
@@ -545,11 +527,10 @@ clients_handle_send (void *cls,
545 */ 527 */
546static void 528static void
547try_connect_if_allowed (void *cls, 529try_connect_if_allowed (void *cls,
548 const struct GNUNET_PeerIdentity *peer, 530 const struct GNUNET_PeerIdentity *peer, int result)
549 int result)
550{ 531{
551 if (GNUNET_OK != result) 532 if (GNUNET_OK != result)
552 return; /* not allowed */ 533 return; /* not allowed */
553 GST_neighbours_try_connect (peer); 534 GST_neighbours_try_connect (peer);
554} 535}
555 536
@@ -563,23 +544,23 @@ try_connect_if_allowed (void *cls,
563 */ 544 */
564static void 545static void
565clients_handle_request_connect (void *cls, 546clients_handle_request_connect (void *cls,
566 struct GNUNET_SERVER_Client *client, 547 struct GNUNET_SERVER_Client *client,
567 const struct GNUNET_MessageHeader *message) 548 const struct GNUNET_MessageHeader *message)
568{ 549{
569 const struct TransportRequestConnectMessage *trcm = 550 const struct TransportRequestConnectMessage *trcm =
570 (const struct TransportRequestConnectMessage *) message; 551 (const struct TransportRequestConnectMessage *) message;
571 552
572 GNUNET_STATISTICS_update (GST_stats, 553 GNUNET_STATISTICS_update (GST_stats,
573 gettext_noop ("# REQUEST CONNECT messages received"), 554 gettext_noop
574 1, 555 ("# REQUEST CONNECT messages received"), 1,
575 GNUNET_NO); 556 GNUNET_NO);
576#if DEBUG_TRANSPORT 557#if DEBUG_TRANSPORT
577 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
578 "Received a request connect message for peer `%s'\n", 559 "Received a request connect message for peer `%s'\n",
579 GNUNET_i2s(&trcm->peer)); 560 GNUNET_i2s (&trcm->peer));
580#endif 561#endif
581 (void) GST_blacklist_test_allowed (&trcm->peer, NULL, 562 (void) GST_blacklist_test_allowed (&trcm->peer, NULL,
582 &try_connect_if_allowed, NULL); 563 &try_connect_if_allowed, NULL);
583 GNUNET_SERVER_receive_done (client, GNUNET_OK); 564 GNUNET_SERVER_receive_done (client, GNUNET_OK);
584} 565}
585 566
@@ -593,25 +574,23 @@ clients_handle_request_connect (void *cls,
593 */ 574 */
594static void 575static void
595clients_handle_set_quota (void *cls, 576clients_handle_set_quota (void *cls,
596 struct GNUNET_SERVER_Client *client, 577 struct GNUNET_SERVER_Client *client,
597 const struct GNUNET_MessageHeader *message) 578 const struct GNUNET_MessageHeader *message)
598{ 579{
599 const struct QuotaSetMessage *qsm; 580 const struct QuotaSetMessage *qsm;
600 581
601 qsm = (const struct QuotaSetMessage *) message; 582 qsm = (const struct QuotaSetMessage *) message;
602 GNUNET_STATISTICS_update (GST_stats, 583 GNUNET_STATISTICS_update (GST_stats,
603 gettext_noop ("# SET QUOTA messages received"), 584 gettext_noop ("# SET QUOTA messages received"),
604 1, 585 1, GNUNET_NO);
605 GNUNET_NO); 586#if DEBUG_TRANSPORT
606#if DEBUG_TRANSPORT
607 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
608 "Received `%s' request (new quota %u) from client for peer `%4s'\n", 588 "Received `%s' request (new quota %u) from client for peer `%4s'\n",
609 "SET_QUOTA", 589 "SET_QUOTA",
610 (unsigned int) ntohl (qsm->quota.value__), 590 (unsigned int) ntohl (qsm->quota.value__),
611 GNUNET_i2s (&qsm->peer)); 591 GNUNET_i2s (&qsm->peer));
612#endif 592#endif
613 GST_neighbours_set_incoming_quota (&qsm->peer, 593 GST_neighbours_set_incoming_quota (&qsm->peer, qsm->quota);
614 qsm->quota);
615 GNUNET_SERVER_receive_done (client, GNUNET_OK); 594 GNUNET_SERVER_receive_done (client, GNUNET_OK);
616} 595}
617 596
@@ -624,22 +603,20 @@ clients_handle_set_quota (void *cls,
624 * @param address the resolved name, NULL to indicate the last response 603 * @param address the resolved name, NULL to indicate the last response
625 */ 604 */
626static void 605static void
627transmit_address_to_client (void *cls, 606transmit_address_to_client (void *cls, const char *address)
628 const char *address)
629{ 607{
630 struct GNUNET_SERVER_TransmitContext *tc = cls; 608 struct GNUNET_SERVER_TransmitContext *tc = cls;
631 609
632 if (NULL == address) 610 if (NULL == address)
633 { 611 {
634 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 612 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
635 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 613 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
636 GNUNET_SERVER_transmit_context_run (tc, 614 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
637 GNUNET_TIME_UNIT_FOREVER_REL); 615 return;
638 return; 616 }
639 } 617 GNUNET_SERVER_transmit_context_append_data (tc,
640 GNUNET_SERVER_transmit_context_append_data (tc, 618 address, strlen (address) + 1,
641 address, strlen (address) + 1, 619 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
642 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
643} 620}
644 621
645 622
@@ -652,8 +629,8 @@ transmit_address_to_client (void *cls,
652 */ 629 */
653static void 630static void
654clients_handle_address_lookup (void *cls, 631clients_handle_address_lookup (void *cls,
655 struct GNUNET_SERVER_Client *client, 632 struct GNUNET_SERVER_Client *client,
656 const struct GNUNET_MessageHeader *message) 633 const struct GNUNET_MessageHeader *message)
657{ 634{
658 const struct AddressLookupMessage *alum; 635 const struct AddressLookupMessage *alum;
659 struct GNUNET_TRANSPORT_PluginFunctions *papi; 636 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -667,46 +644,45 @@ clients_handle_address_lookup (void *cls,
667 644
668 size = ntohs (message->size); 645 size = ntohs (message->size);
669 if (size < sizeof (struct AddressLookupMessage)) 646 if (size < sizeof (struct AddressLookupMessage))
670 { 647 {
671 GNUNET_break (0); 648 GNUNET_break (0);
672 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 649 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
673 return; 650 return;
674 } 651 }
675 alum = (const struct AddressLookupMessage *) message; 652 alum = (const struct AddressLookupMessage *) message;
676 address_len = ntohl (alum->addrlen); 653 address_len = ntohl (alum->addrlen);
677 if (size <= sizeof (struct AddressLookupMessage) + address_len) 654 if (size <= sizeof (struct AddressLookupMessage) + address_len)
678 { 655 {
679 GNUNET_break (0); 656 GNUNET_break (0);
680 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 657 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
681 return; 658 return;
682 } 659 }
683 address = (const char *) &alum[1]; 660 address = (const char *) &alum[1];
684 plugin_name = (const char *) &address[address_len]; 661 plugin_name = (const char *) &address[address_len];
685 if (plugin_name 662 if (plugin_name
686 [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0') 663 [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0')
687 { 664 {
688 GNUNET_break (0); 665 GNUNET_break (0);
689 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 666 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
690 return; 667 return;
691 } 668 }
692 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); 669 rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout);
693 numeric = ntohl (alum->numeric_only); 670 numeric = ntohl (alum->numeric_only);
694 tc = GNUNET_SERVER_transmit_context_create (client); 671 tc = GNUNET_SERVER_transmit_context_create (client);
695 papi = GST_plugins_find (plugin_name); 672 papi = GST_plugins_find (plugin_name);
696 if (NULL == papi) 673 if (NULL == papi)
697 { 674 {
698 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 675 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
699 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 676 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
700 GNUNET_SERVER_transmit_context_run (tc, rtimeout); 677 GNUNET_SERVER_transmit_context_run (tc, rtimeout);
701 return; 678 return;
702 } 679 }
703 GNUNET_SERVER_disable_receive_done_warning (client); 680 GNUNET_SERVER_disable_receive_done_warning (client);
704 papi->address_pretty_printer (papi->cls, 681 papi->address_pretty_printer (papi->cls,
705 plugin_name, 682 plugin_name,
706 address, address_len, 683 address, address_len,
707 numeric, 684 numeric,
708 rtimeout, 685 rtimeout, &transmit_address_to_client, tc);
709 &transmit_address_to_client, tc);
710} 686}
711 687
712 688
@@ -726,28 +702,26 @@ clients_handle_address_lookup (void *cls,
726 */ 702 */
727static void 703static void
728send_address_to_client (void *cls, 704send_address_to_client (void *cls,
729 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, 705 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
730 const struct GNUNET_PeerIdentity *target, 706 *public_key, const struct GNUNET_PeerIdentity *target,
731 struct GNUNET_TIME_Absolute valid_until, 707 struct GNUNET_TIME_Absolute valid_until,
732 struct GNUNET_TIME_Absolute validation_block, 708 struct GNUNET_TIME_Absolute validation_block,
733 const char *plugin_name, 709 const char *plugin_name, const void *plugin_address,
734 const void *plugin_address, 710 size_t plugin_address_len)
735 size_t plugin_address_len)
736{ 711{
737 struct GNUNET_SERVER_TransmitContext *tc = cls; 712 struct GNUNET_SERVER_TransmitContext *tc = cls;
738 char *addr_buf; 713 char *addr_buf;
739 714
740 /* FIXME: move to a binary format!!! */ 715 /* FIXME: move to a binary format!!! */
741 GNUNET_asprintf (&addr_buf, "%s --- %s, %s", 716 GNUNET_asprintf (&addr_buf, "%s --- %s, %s",
742 GST_plugins_a2s (plugin_name, 717 GST_plugins_a2s (plugin_name,
743 plugin_address, 718 plugin_address,
744 plugin_address_len), 719 plugin_address_len),
745 (GNUNET_YES == GST_neighbours_test_connected (target)) 720 (GNUNET_YES == GST_neighbours_test_connected (target))
746 ? "CONNECTED" 721 ? "CONNECTED"
747 : "DISCONNECTED", 722 : "DISCONNECTED",
748 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value > 0) 723 (GNUNET_TIME_absolute_get_remaining (valid_until).rel_value >
749 ? "VALIDATED" 724 0) ? "VALIDATED" : "UNVALIDATED");
750 : "UNVALIDATED");
751 transmit_address_to_client (tc, addr_buf); 725 transmit_address_to_client (tc, addr_buf);
752 GNUNET_free (addr_buf); 726 GNUNET_free (addr_buf);
753} 727}
@@ -764,8 +738,8 @@ send_address_to_client (void *cls,
764 */ 738 */
765static void 739static void
766clients_handle_peer_address_lookup (void *cls, 740clients_handle_peer_address_lookup (void *cls,
767 struct GNUNET_SERVER_Client *client, 741 struct GNUNET_SERVER_Client *client,
768 const struct GNUNET_MessageHeader *message) 742 const struct GNUNET_MessageHeader *message)
769{ 743{
770 const struct PeerAddressLookupMessage *peer_address_lookup; 744 const struct PeerAddressLookupMessage *peer_address_lookup;
771 struct GNUNET_SERVER_TransmitContext *tc; 745 struct GNUNET_SERVER_TransmitContext *tc;
@@ -774,13 +748,11 @@ clients_handle_peer_address_lookup (void *cls,
774 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0); 748 GNUNET_break (ntohl (peer_address_lookup->reserved) == 0);
775 tc = GNUNET_SERVER_transmit_context_create (client); 749 tc = GNUNET_SERVER_transmit_context_create (client);
776 GST_validation_get_addresses (&peer_address_lookup->peer, 750 GST_validation_get_addresses (&peer_address_lookup->peer,
777 &send_address_to_client, 751 &send_address_to_client, tc);
778 tc);
779 GNUNET_SERVER_transmit_context_append_data (tc, 752 GNUNET_SERVER_transmit_context_append_data (tc,
780 NULL, 0, 753 NULL, 0,
781 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 754 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
782 GNUNET_SERVER_transmit_context_run (tc, 755 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
783 GNUNET_TIME_UNIT_FOREVER_REL);
784} 756}
785 757
786 758
@@ -794,18 +766,17 @@ clients_handle_peer_address_lookup (void *cls,
794 */ 766 */
795static void 767static void
796output_addresses (void *cls, 768output_addresses (void *cls,
797 const struct GNUNET_PeerIdentity *neighbour, 769 const struct GNUNET_PeerIdentity *neighbour,
798 const struct GNUNET_TRANSPORT_ATS_Information *ats, 770 const struct GNUNET_TRANSPORT_ATS_Information *ats,
799 uint32_t ats_count) 771 uint32_t ats_count)
800{ 772{
801 struct GNUNET_SERVER_TransmitContext *tc = cls; 773 struct GNUNET_SERVER_TransmitContext *tc = cls;
802 char *addr_buf; 774 char *addr_buf;
803 775
804 /* FIXME: move to a binary format!!! */ 776 /* FIXME: move to a binary format!!! */
805 GNUNET_asprintf (&addr_buf, 777 GNUNET_asprintf (&addr_buf,
806 "%s: %s", 778 "%s: %s",
807 GNUNET_i2s(neighbour), 779 GNUNET_i2s (neighbour), GST_plugins_a2s ("FIXME", NULL, 0));
808 GST_plugins_a2s ("FIXME", NULL, 0));
809 transmit_address_to_client (tc, addr_buf); 780 transmit_address_to_client (tc, addr_buf);
810 GNUNET_free (addr_buf); 781 GNUNET_free (addr_buf);
811} 782}
@@ -821,15 +792,14 @@ output_addresses (void *cls,
821 */ 792 */
822static void 793static void
823clients_handle_address_iterate (void *cls, 794clients_handle_address_iterate (void *cls,
824 struct GNUNET_SERVER_Client *client, 795 struct GNUNET_SERVER_Client *client,
825 const struct GNUNET_MessageHeader *message) 796 const struct GNUNET_MessageHeader *message)
826{ 797{
827 struct GNUNET_SERVER_TransmitContext *tc; 798 struct GNUNET_SERVER_TransmitContext *tc;
828 799
829 GNUNET_SERVER_disable_receive_done_warning (client); 800 GNUNET_SERVER_disable_receive_done_warning (client);
830 tc = GNUNET_SERVER_transmit_context_create (client); 801 tc = GNUNET_SERVER_transmit_context_create (client);
831 GST_neighbours_iterate (&output_addresses, 802 GST_neighbours_iterate (&output_addresses, tc);
832 tc);
833 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, 803 GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
834 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 804 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
835 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); 805 GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL);
@@ -841,30 +811,35 @@ clients_handle_address_iterate (void *cls,
841 * 811 *
842 * @param server server used to accept clients from. 812 * @param server server used to accept clients from.
843 */ 813 */
844void 814void
845GST_clients_start (struct GNUNET_SERVER_Handle *server) 815GST_clients_start (struct GNUNET_SERVER_Handle *server)
846{ 816{
847 static const struct GNUNET_SERVER_MessageHandler handlers[] = { 817 static const struct GNUNET_SERVER_MessageHandler handlers[] = {
848 { &clients_handle_start, NULL, 818 {&clients_handle_start, NULL,
849 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)}, 819 GNUNET_MESSAGE_TYPE_TRANSPORT_START, sizeof (struct StartMessage)},
850 { &clients_handle_hello, NULL, 820 {&clients_handle_hello, NULL,
851 GNUNET_MESSAGE_TYPE_HELLO, 0}, 821 GNUNET_MESSAGE_TYPE_HELLO, 0},
852 { &clients_handle_send, NULL, 822 {&clients_handle_send, NULL,
853 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND , 0}, 823 GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, 0},
854 { &clients_handle_request_connect, NULL, 824 {&clients_handle_request_connect, NULL,
855 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT, sizeof (struct TransportRequestConnectMessage)}, 825 GNUNET_MESSAGE_TYPE_TRANSPORT_REQUEST_CONNECT,
856 { &clients_handle_set_quota, NULL, 826 sizeof (struct TransportRequestConnectMessage)},
857 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)}, 827 {&clients_handle_set_quota, NULL,
858 { &clients_handle_address_lookup, NULL, 828 GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA, sizeof (struct QuotaSetMessage)},
859 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP , 0}, 829 {&clients_handle_address_lookup, NULL,
860 { &clients_handle_peer_address_lookup, NULL, 830 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP, 0},
861 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP, sizeof (struct PeerAddressLookupMessage)}, 831 {&clients_handle_peer_address_lookup, NULL,
862 { &clients_handle_address_iterate, NULL, 832 GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP,
863 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE, sizeof (struct GNUNET_MessageHeader)}, 833 sizeof (struct PeerAddressLookupMessage)},
864 { &GST_blacklist_handle_init, NULL, 834 {&clients_handle_address_iterate, NULL,
865 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT, sizeof (struct GNUNET_MessageHeader)}, 835 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE,
866 { &GST_blacklist_handle_reply, NULL, 836 sizeof (struct GNUNET_MessageHeader)},
867 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY, sizeof (struct BlacklistMessage)}, 837 {&GST_blacklist_handle_init, NULL,
838 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT,
839 sizeof (struct GNUNET_MessageHeader)},
840 {&GST_blacklist_handle_reply, NULL,
841 GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY,
842 sizeof (struct BlacklistMessage)},
868 {NULL, NULL, 0, 0} 843 {NULL, NULL, 0, 0}
869 }; 844 };
870 GNUNET_SERVER_add_handlers (server, handlers); 845 GNUNET_SERVER_add_handlers (server, handlers);
@@ -890,8 +865,7 @@ GST_clients_stop ()
890 * @param may_drop GNUNET_YES if the message can be dropped 865 * @param may_drop GNUNET_YES if the message can be dropped
891 */ 866 */
892void 867void
893GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, 868GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop)
894 int may_drop)
895{ 869{
896 struct TransportClient *tc; 870 struct TransportClient *tc;
897 871
@@ -909,8 +883,7 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
909 */ 883 */
910void 884void
911GST_clients_unicast (struct GNUNET_SERVER_Client *client, 885GST_clients_unicast (struct GNUNET_SERVER_Client *client,
912 const struct GNUNET_MessageHeader *msg, 886 const struct GNUNET_MessageHeader *msg, int may_drop)
913 int may_drop)
914{ 887{
915 struct TransportClient *tc; 888 struct TransportClient *tc;
916 889
diff --git a/src/transport/gnunet-service-transport_clients.h b/src/transport/gnunet-service-transport_clients.h
index a9ee55279..7c79eec15 100644
--- a/src/transport/gnunet-service-transport_clients.h
+++ b/src/transport/gnunet-service-transport_clients.h
@@ -35,15 +35,13 @@
35 * 35 *
36 * @param server server used to accept clients from. 36 * @param server server used to accept clients from.
37 */ 37 */
38void 38void GST_clients_start (struct GNUNET_SERVER_Handle *server);
39GST_clients_start (struct GNUNET_SERVER_Handle *server);
40 39
41 40
42/** 41/**
43 * Stop processing clients. 42 * Stop processing clients.
44 */ 43 */
45void 44void GST_clients_stop (void);
46GST_clients_stop (void);
47 45
48 46
49/** 47/**
@@ -53,8 +51,7 @@ GST_clients_stop (void);
53 * @param may_drop GNUNET_YES if the message can be dropped 51 * @param may_drop GNUNET_YES if the message can be dropped
54 */ 52 */
55void 53void
56GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, 54GST_clients_broadcast (const struct GNUNET_MessageHeader *msg, int may_drop);
57 int may_drop);
58 55
59 56
60/** 57/**
@@ -66,8 +63,7 @@ GST_clients_broadcast (const struct GNUNET_MessageHeader *msg,
66 */ 63 */
67void 64void
68GST_clients_unicast (struct GNUNET_SERVER_Client *client, 65GST_clients_unicast (struct GNUNET_SERVER_Client *client,
69 const struct GNUNET_MessageHeader *msg, 66 const struct GNUNET_MessageHeader *msg, int may_drop);
70 int may_drop);
71 67
72 68
73 69
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index f05c0836a..a2d0d966c 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -90,7 +90,7 @@ static GST_HelloCallback hello_cb;
90 90
91/** 91/**
92 * Closure for 'hello_cb'. 92 * Closure for 'hello_cb'.
93 */ 93 */
94static void *hello_cb_cls; 94static void *hello_cb_cls;
95 95
96/** 96/**
@@ -118,7 +118,7 @@ struct GeneratorContext
118 * Where are we in the DLL? 118 * Where are we in the DLL?
119 */ 119 */
120 struct OwnAddressList *addr_pos; 120 struct OwnAddressList *addr_pos;
121 121
122 /** 122 /**
123 * When do addresses expire? 123 * When do addresses expire?
124 */ 124 */
@@ -140,12 +140,11 @@ address_generator (void *cls, size_t max, void *buf)
140 size_t ret; 140 size_t ret;
141 141
142 if (NULL == gc->addr_pos) 142 if (NULL == gc->addr_pos)
143 return 0; 143 return 0;
144 ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, 144 ret = GNUNET_HELLO_add_address (gc->addr_pos->plugin_name,
145 gc->expiration, 145 gc->expiration,
146 &gc->addr_pos[1], 146 &gc->addr_pos[1],
147 gc->addr_pos->addrlen, 147 gc->addr_pos->addrlen, buf, max);
148 buf, max);
149 gc->addr_pos = gc->addr_pos->next; 148 gc->addr_pos = gc->addr_pos->next;
150 return ret; 149 return ret;
151} 150}
@@ -159,34 +158,30 @@ address_generator (void *cls, size_t max, void *buf)
159 * @param tc scheduler context 158 * @param tc scheduler context
160 */ 159 */
161static void 160static void
162refresh_hello_task (void *cls, 161refresh_hello_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
163 const struct GNUNET_SCHEDULER_TaskContext *tc)
164{ 162{
165 struct GeneratorContext gc; 163 struct GeneratorContext gc;
166 164
167 hello_task = GNUNET_SCHEDULER_NO_TASK; 165 hello_task = GNUNET_SCHEDULER_NO_TASK;
168 gc.addr_pos = oal_head; 166 gc.addr_pos = oal_head;
169 gc.expiration = GNUNET_TIME_relative_to_absolute (GST_HELLO_ADDRESS_EXPIRATION); 167 gc.expiration =
168 GNUNET_TIME_relative_to_absolute (GST_HELLO_ADDRESS_EXPIRATION);
170 GNUNET_free (our_hello); 169 GNUNET_free (our_hello);
171 our_hello = GNUNET_HELLO_create (&GST_my_public_key, 170 our_hello = GNUNET_HELLO_create (&GST_my_public_key, &address_generator, &gc);
172 &address_generator,
173 &gc);
174#if DEBUG_TRANSPORT 171#if DEBUG_TRANSPORT
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
176 "Refreshed my `%s', new size is %d\n", "HELLO", 173 "Refreshed my `%s', new size is %d\n", "HELLO",
177 GNUNET_HELLO_size(our_hello)); 174 GNUNET_HELLO_size (our_hello));
178#endif 175#endif
179 GNUNET_STATISTICS_update (GST_stats, 176 GNUNET_STATISTICS_update (GST_stats,
180 gettext_noop ("# refreshed my HELLO"), 177 gettext_noop ("# refreshed my HELLO"),
181 1, 178 1, GNUNET_NO);
182 GNUNET_NO);
183 if (NULL != hello_cb) 179 if (NULL != hello_cb)
184 hello_cb (hello_cb_cls, GST_hello_get()); 180 hello_cb (hello_cb_cls, GST_hello_get ());
185 GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello); 181 GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello);
186 hello_task 182 hello_task
187 = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, 183 = GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD,
188 &refresh_hello_task, 184 &refresh_hello_task, NULL);
189 NULL);
190 185
191} 186}
192 187
@@ -200,9 +195,7 @@ refresh_hello ()
200{ 195{
201 if (hello_task != GNUNET_SCHEDULER_NO_TASK) 196 if (hello_task != GNUNET_SCHEDULER_NO_TASK)
202 GNUNET_SCHEDULER_cancel (hello_task); 197 GNUNET_SCHEDULER_cancel (hello_task);
203 hello_task 198 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, NULL);
204 = GNUNET_SCHEDULER_add_now (&refresh_hello_task,
205 NULL);
206} 199}
207 200
208 201
@@ -212,14 +205,12 @@ refresh_hello ()
212 * @param cb function to call whenever our HELLO changes 205 * @param cb function to call whenever our HELLO changes
213 * @param cb_cls closure for cb 206 * @param cb_cls closure for cb
214 */ 207 */
215void 208void
216GST_hello_start (GST_HelloCallback cb, 209GST_hello_start (GST_HelloCallback cb, void *cb_cls)
217 void *cb_cls)
218{ 210{
219 hello_cb = cb; 211 hello_cb = cb;
220 hello_cb_cls = cb_cls; 212 hello_cb_cls = cb_cls;
221 our_hello = GNUNET_HELLO_create (&GST_my_public_key, 213 our_hello = GNUNET_HELLO_create (&GST_my_public_key, NULL, NULL);
222 NULL, NULL);
223 refresh_hello (); 214 refresh_hello ();
224} 215}
225 216
@@ -233,15 +224,15 @@ GST_hello_stop ()
233 hello_cb = NULL; 224 hello_cb = NULL;
234 hello_cb_cls = NULL; 225 hello_cb_cls = NULL;
235 if (GNUNET_SCHEDULER_NO_TASK != hello_task) 226 if (GNUNET_SCHEDULER_NO_TASK != hello_task)
236 { 227 {
237 GNUNET_SCHEDULER_cancel (hello_task); 228 GNUNET_SCHEDULER_cancel (hello_task);
238 hello_task = GNUNET_SCHEDULER_NO_TASK; 229 hello_task = GNUNET_SCHEDULER_NO_TASK;
239 } 230 }
240 if (NULL != our_hello) 231 if (NULL != our_hello)
241 { 232 {
242 GNUNET_free (our_hello); 233 GNUNET_free (our_hello);
243 our_hello = NULL; 234 our_hello = NULL;
244 } 235 }
245} 236}
246 237
247 238
@@ -253,7 +244,7 @@ GST_hello_stop ()
253const struct GNUNET_MessageHeader * 244const struct GNUNET_MessageHeader *
254GST_hello_get () 245GST_hello_get ()
255{ 246{
256 return (struct GNUNET_MessageHeader*) our_hello; 247 return (struct GNUNET_MessageHeader *) our_hello;
257} 248}
258 249
259 250
@@ -267,45 +258,39 @@ GST_hello_get ()
267 */ 258 */
268void 259void
269GST_hello_modify_addresses (int addremove, 260GST_hello_modify_addresses (int addremove,
270 const char *plugin_name, 261 const char *plugin_name,
271 const void *plugin_address, 262 const void *plugin_address,
272 size_t plugin_address_len) 263 size_t plugin_address_len)
273{ 264{
274 struct OwnAddressList *al; 265 struct OwnAddressList *al;
275 266
276#if DEBUG_TRANSPORT 267#if DEBUG_TRANSPORT
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 (add_remove == GNUNET_YES) 269 (add_remove == GNUNET_YES)
279 ? "Adding `%s':%s to the set of our addresses\n" 270 ? "Adding `%s':%s to the set of our addresses\n"
280 : "Removing `%s':%s from the set of our addresses\n", 271 : "Removing `%s':%s from the set of our addresses\n",
281 GST_plugins_a2s (plugin_name, 272 GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name);
282 addr, addrlen),
283 p->short_name);
284#endif 273#endif
285 GNUNET_assert (plugin_address != NULL); 274 GNUNET_assert (plugin_address != NULL);
286 if (GNUNET_NO == addremove) 275 if (GNUNET_NO == addremove)
287 { 276 {
288 for (al = oal_head; al != NULL; al = al->next) 277 for (al = oal_head; al != NULL; al = al->next)
289 if ( (plugin_address_len == al->addrlen) && 278 if ((plugin_address_len == al->addrlen) &&
290 (0 == strcmp (al->plugin_name, plugin_name)) && 279 (0 == strcmp (al->plugin_name, plugin_name)) &&
291 (0 == memcmp (plugin_address, &al[1], plugin_address_len)) ) 280 (0 == memcmp (plugin_address, &al[1], plugin_address_len)))
292 { 281 {
293 GNUNET_CONTAINER_DLL_remove (oal_head, 282 GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al);
294 oal_tail, 283 GNUNET_free (al->plugin_name);
295 al); 284 GNUNET_free (al);
296 GNUNET_free (al->plugin_name); 285 refresh_hello ();
297 GNUNET_free (al); 286 return;
298 refresh_hello (); 287 }
299 return; 288 /* address to be removed not found!? */
300 } 289 GNUNET_break (0);
301 /* address to be removed not found!? */ 290 return;
302 GNUNET_break (0); 291 }
303 return;
304 }
305 al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len); 292 al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len);
306 GNUNET_CONTAINER_DLL_insert (oal_head, 293 GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al);
307 oal_tail,
308 al);
309 al->plugin_name = GNUNET_strdup (plugin_name); 294 al->plugin_name = GNUNET_strdup (plugin_name);
310 al->addrlen = plugin_address_len; 295 al->addrlen = plugin_address_len;
311 memcpy (&al[1], plugin_address, plugin_address_len); 296 memcpy (&al[1], plugin_address, plugin_address_len);
@@ -327,22 +312,22 @@ GST_hello_modify_addresses (int addremove,
327 */ 312 */
328int 313int
329GST_hello_test_address (const char *plugin_name, 314GST_hello_test_address (const char *plugin_name,
330 const void *plugin_address, 315 const void *plugin_address,
331 size_t plugin_address_len, 316 size_t plugin_address_len,
332 struct GNUNET_CRYPTO_RsaSignature **sig, 317 struct GNUNET_CRYPTO_RsaSignature **sig,
333 struct GNUNET_TIME_Absolute **sig_expiration) 318 struct GNUNET_TIME_Absolute **sig_expiration)
334{ 319{
335 struct OwnAddressList *al; 320 struct OwnAddressList *al;
336 321
337 for (al = oal_head; al != NULL; al = al->next) 322 for (al = oal_head; al != NULL; al = al->next)
338 if ( (plugin_address_len == al->addrlen) && 323 if ((plugin_address_len == al->addrlen) &&
339 (0 == strcmp (al->plugin_name, plugin_name)) && 324 (0 == strcmp (al->plugin_name, plugin_name)) &&
340 (0 == memcmp (plugin_address, &al[1], plugin_address_len)) ) 325 (0 == memcmp (plugin_address, &al[1], plugin_address_len)))
341 { 326 {
342 *sig = &al->pong_signature; 327 *sig = &al->pong_signature;
343 *sig_expiration = &al->pong_sig_expires; 328 *sig_expiration = &al->pong_sig_expires;
344 return GNUNET_YES; 329 return GNUNET_YES;
345 } 330 }
346 *sig = NULL; 331 *sig = NULL;
347 *sig_expiration = NULL; 332 *sig_expiration = NULL;
348 return GNUNET_NO; 333 return GNUNET_NO;
diff --git a/src/transport/gnunet-service-transport_hello.h b/src/transport/gnunet-service-transport_hello.h
index 7b86d62d0..8aac2838a 100644
--- a/src/transport/gnunet-service-transport_hello.h
+++ b/src/transport/gnunet-service-transport_hello.h
@@ -45,8 +45,8 @@
45 * @param cls closure 45 * @param cls closure
46 * @param hello updated HELLO 46 * @param hello updated HELLO
47 */ 47 */
48typedef void (*GST_HelloCallback)(void *cls, 48typedef void (*GST_HelloCallback) (void *cls,
49 const struct GNUNET_MessageHeader *hello); 49 const struct GNUNET_MessageHeader * hello);
50 50
51 51
52/** 52/**
@@ -55,16 +55,13 @@ typedef void (*GST_HelloCallback)(void *cls,
55 * @param cb function to call whenever our HELLO changes 55 * @param cb function to call whenever our HELLO changes
56 * @param cb_cls closure for cb 56 * @param cb_cls closure for cb
57 */ 57 */
58void 58void GST_hello_start (GST_HelloCallback cb, void *cb_cls);
59GST_hello_start (GST_HelloCallback cb,
60 void *cb_cls);
61 59
62 60
63/** 61/**
64 * Shutdown the HELLO module. 62 * Shutdown the HELLO module.
65 */ 63 */
66void 64void GST_hello_stop (void);
67GST_hello_stop (void);
68 65
69 66
70/** 67/**
@@ -72,8 +69,7 @@ GST_hello_stop (void);
72 * 69 *
73 * @return our HELLO message 70 * @return our HELLO message
74 */ 71 */
75const struct GNUNET_MessageHeader * 72const struct GNUNET_MessageHeader *GST_hello_get (void);
76GST_hello_get (void);
77 73
78 74
79/** 75/**
@@ -86,9 +82,9 @@ GST_hello_get (void);
86 */ 82 */
87void 83void
88GST_hello_modify_addresses (int addremove, 84GST_hello_modify_addresses (int addremove,
89 const char *plugin_name, 85 const char *plugin_name,
90 const void *plugin_address, 86 const void *plugin_address,
91 size_t plugin_address_len); 87 size_t plugin_address_len);
92 88
93 89
94/** 90/**
@@ -105,10 +101,10 @@ GST_hello_modify_addresses (int addremove,
105 */ 101 */
106int 102int
107GST_hello_test_address (const char *plugin_name, 103GST_hello_test_address (const char *plugin_name,
108 const void *plugin_address, 104 const void *plugin_address,
109 size_t plugin_address_len, 105 size_t plugin_address_len,
110 struct GNUNET_CRYPTO_RsaSignature **sig, 106 struct GNUNET_CRYPTO_RsaSignature **sig,
111 struct GNUNET_TIME_Absolute **sig_expiration); 107 struct GNUNET_TIME_Absolute **sig_expiration);
112 108
113 109
114#endif 110#endif
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 604112560..386894d48 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -152,7 +152,7 @@ struct NeighbourMapEntry
152 * Address used for communicating with the peer, NULL for inbound connections. 152 * Address used for communicating with the peer, NULL for inbound connections.
153 */ 153 */
154 void *addr; 154 void *addr;
155 155
156 /** 156 /**
157 * Number of bytes in 'addr'. 157 * Number of bytes in 'addr'.
158 */ 158 */
@@ -236,8 +236,7 @@ static GNUNET_TRANSPORT_NotifyDisconnect disconnect_notify_cb;
236static struct NeighbourMapEntry * 236static struct NeighbourMapEntry *
237lookup_neighbour (const struct GNUNET_PeerIdentity *pid) 237lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
238{ 238{
239 return GNUNET_CONTAINER_multihashmap_get (neighbours, 239 return GNUNET_CONTAINER_multihashmap_get (neighbours, &pid->hashPubKey);
240 &pid->hashPubKey);
241} 240}
242 241
243 242
@@ -248,8 +247,7 @@ lookup_neighbour (const struct GNUNET_PeerIdentity *pid)
248 * @param tc scheduler context 247 * @param tc scheduler context
249 */ 248 */
250static void 249static void
251transmission_task (void *cls, 250transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
252 const struct GNUNET_SCHEDULER_TaskContext *tc);
253 251
254 252
255/** 253/**
@@ -261,25 +259,23 @@ transmission_task (void *cls,
261 */ 259 */
262static void 260static void
263transmit_send_continuation (void *cls, 261transmit_send_continuation (void *cls,
264 const struct GNUNET_PeerIdentity *receiver, 262 const struct GNUNET_PeerIdentity *receiver,
265 int success) 263 int success)
266{ 264{
267 struct MessageQueue *mq; 265 struct MessageQueue *mq;
268 struct NeighbourMapEntry *n; 266 struct NeighbourMapEntry *n;
269 267
270 mq = cls; 268 mq = cls;
271 n = mq->n; 269 n = mq->n;
272 if (NULL != n) 270 if (NULL != n)
273 { 271 {
274 GNUNET_assert (n->is_active == mq); 272 GNUNET_assert (n->is_active == mq);
275 n->is_active = NULL; 273 n->is_active = NULL;
276 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK); 274 GNUNET_assert (n->transmission_task == GNUNET_SCHEDULER_NO_TASK);
277 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, 275 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
278 n); 276 }
279 }
280 if (NULL != mq->cont) 277 if (NULL != mq->cont)
281 mq->cont (mq->cont_cls, 278 mq->cont (mq->cont_cls, success);
282 success);
283 GNUNET_free (mq); 279 GNUNET_free (mq);
284} 280}
285 281
@@ -299,52 +295,45 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
299 struct GNUNET_TRANSPORT_PluginFunctions *papi; 295 struct GNUNET_TRANSPORT_PluginFunctions *papi;
300 296
301 if (n->is_active != NULL) 297 if (n->is_active != NULL)
302 return; /* transmission already pending */ 298 return; /* transmission already pending */
303 if (n->transmission_task != GNUNET_SCHEDULER_NO_TASK) 299 if (n->transmission_task != GNUNET_SCHEDULER_NO_TASK)
304 return; /* currently waiting for bandwidth */ 300 return; /* currently waiting for bandwidth */
305 mq = n->messages_head; 301 mq = n->messages_head;
306 while (NULL != (mq = n->messages_head)) 302 while (NULL != (mq = n->messages_head))
307 { 303 {
308 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout); 304 timeout = GNUNET_TIME_absolute_get_remaining (mq->timeout);
309 if (timeout.rel_value > 0) 305 if (timeout.rel_value > 0)
310 break; 306 break;
311 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); /* timeout */ 307 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR); /* timeout */
312 } 308 }
313 if (NULL == mq) 309 if (NULL == mq)
314 return; /* no more messages */ 310 return; /* no more messages */
315 311
316 papi = GST_plugins_find (n->plugin_name); 312 papi = GST_plugins_find (n->plugin_name);
317 if (papi == NULL) 313 if (papi == NULL)
318 { 314 {
319 GNUNET_break (0); 315 GNUNET_break (0);
320 return; 316 return;
321 } 317 }
322 GNUNET_CONTAINER_DLL_remove (n->messages_head, 318 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
323 n->messages_tail,
324 mq);
325 n->is_active = mq; 319 n->is_active = mq;
326 mq->n = n; 320 mq->n = n;
327 ret = papi->send (papi->cls, 321 ret = papi->send (papi->cls,
328 &n->id, 322 &n->id,
329 mq->message_buf, 323 mq->message_buf,
330 mq->message_buf_size, 324 mq->message_buf_size,
331 0 /* priority -- remove from plugin API? */, 325 0 /* priority -- remove from plugin API? */ ,
332 timeout, 326 timeout,
333 n->session, 327 n->session,
334 n->addr, 328 n->addr,
335 n->addrlen, 329 n->addrlen, GNUNET_YES, &transmit_send_continuation, mq);
336 GNUNET_YES,
337 &transmit_send_continuation, mq);
338 if (ret == -1) 330 if (ret == -1)
339 { 331 {
340 /* failure, but 'send' would not call continuation in this case, 332 /* failure, but 'send' would not call continuation in this case,
341 so we need to do it here! */ 333 * so we need to do it here! */
342 transmit_send_continuation (mq, 334 transmit_send_continuation (mq, &n->id, GNUNET_SYSERR);
343 &n->id, 335 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
344 GNUNET_SYSERR); 336 }
345 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task,
346 n);
347 }
348} 337}
349 338
350 339
@@ -355,8 +344,7 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
355 * @param tc scheduler context 344 * @param tc scheduler context
356 */ 345 */
357static void 346static void
358transmission_task (void *cls, 347transmission_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
359 const struct GNUNET_SCHEDULER_TaskContext *tc)
360{ 348{
361 struct NeighbourMapEntry *n = cls; 349 struct NeighbourMapEntry *n = cls;
362 350
@@ -372,10 +360,10 @@ transmission_task (void *cls,
372 * @param connect_cb function to call if we connect to a peer 360 * @param connect_cb function to call if we connect to a peer
373 * @param disconnect_cb function to call if we disconnect from a peer 361 * @param disconnect_cb function to call if we disconnect from a peer
374 */ 362 */
375void 363void
376GST_neighbours_start (void *cls, 364GST_neighbours_start (void *cls,
377 GNUNET_TRANSPORT_NotifyConnect connect_cb, 365 GNUNET_TRANSPORT_NotifyConnect connect_cb,
378 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb) 366 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
379{ 367{
380 callback_cls = cls; 368 callback_cls = cls;
381 connect_notify_cb = connect_cb; 369 connect_notify_cb = connect_cb;
@@ -398,57 +386,51 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
398 return; 386 return;
399 n->in_disconnect = GNUNET_YES; 387 n->in_disconnect = GNUNET_YES;
400 while (NULL != (mq = n->messages_head)) 388 while (NULL != (mq = n->messages_head))
401 { 389 {
402 GNUNET_CONTAINER_DLL_remove (n->messages_head, 390 GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
403 n->messages_tail, 391 mq->cont (mq->cont_cls, GNUNET_SYSERR);
404 mq); 392 GNUNET_free (mq);
405 mq->cont (mq->cont_cls, GNUNET_SYSERR); 393 }
406 GNUNET_free (mq);
407 }
408 if (NULL != n->is_active) 394 if (NULL != n->is_active)
409 { 395 {
410 n->is_active->n = NULL; 396 n->is_active->n = NULL;
411 n->is_active = NULL; 397 n->is_active = NULL;
412 } 398 }
413 if (GNUNET_YES == n->is_connected) 399 if (GNUNET_YES == n->is_connected)
414 { 400 {
415 n->is_connected = GNUNET_NO; 401 n->is_connected = GNUNET_NO;
416 disconnect_notify_cb (callback_cls, 402 disconnect_notify_cb (callback_cls, &n->id);
417 &n->id); 403 }
418 }
419 GNUNET_assert (GNUNET_YES == 404 GNUNET_assert (GNUNET_YES ==
420 GNUNET_CONTAINER_multihashmap_remove (neighbours, 405 GNUNET_CONTAINER_multihashmap_remove (neighbours,
421 &n->id.hashPubKey, 406 &n->id.hashPubKey, n));
422 n));
423 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task) 407 if (GNUNET_SCHEDULER_NO_TASK != n->timeout_task)
424 { 408 {
425 GNUNET_SCHEDULER_cancel (n->timeout_task); 409 GNUNET_SCHEDULER_cancel (n->timeout_task);
426 n->timeout_task = GNUNET_SCHEDULER_NO_TASK; 410 n->timeout_task = GNUNET_SCHEDULER_NO_TASK;
427 } 411 }
428 if (GNUNET_SCHEDULER_NO_TASK != n->transmission_task) 412 if (GNUNET_SCHEDULER_NO_TASK != n->transmission_task)
429 { 413 {
430 GNUNET_SCHEDULER_cancel (n->timeout_task); 414 GNUNET_SCHEDULER_cancel (n->timeout_task);
431 n->transmission_task = GNUNET_SCHEDULER_NO_TASK; 415 n->transmission_task = GNUNET_SCHEDULER_NO_TASK;
432 } 416 }
433 if (NULL != n->asc) 417 if (NULL != n->asc)
434 { 418 {
435 GNUNET_ATS_suggest_address_cancel (n->asc); 419 GNUNET_ATS_suggest_address_cancel (n->asc);
436 n->asc = NULL; 420 n->asc = NULL;
437 } 421 }
438 GNUNET_array_grow (n->ats, 422 GNUNET_array_grow (n->ats, n->ats_count, 0);
439 n->ats_count,
440 0);
441 if (NULL != n->plugin_name) 423 if (NULL != n->plugin_name)
442 { 424 {
443 GNUNET_free (n->plugin_name); 425 GNUNET_free (n->plugin_name);
444 n->plugin_name = NULL; 426 n->plugin_name = NULL;
445 } 427 }
446 if (NULL != n->addr) 428 if (NULL != n->addr)
447 { 429 {
448 GNUNET_free (n->addr); 430 GNUNET_free (n->addr);
449 n->addr = NULL; 431 n->addr = NULL;
450 n->addrlen = 0; 432 n->addrlen = 0;
451 } 433 }
452 n->session = NULL; 434 n->session = NULL;
453 GNUNET_free (n); 435 GNUNET_free (n);
454} 436}
@@ -462,7 +444,7 @@ disconnect_neighbour (struct NeighbourMapEntry *n)
462 */ 444 */
463static void 445static void
464neighbour_timeout_task (void *cls, 446neighbour_timeout_task (void *cls,
465 const struct GNUNET_SCHEDULER_TaskContext *tc) 447 const struct GNUNET_SCHEDULER_TaskContext *tc)
466{ 448{
467 struct NeighbourMapEntry *n = cls; 449 struct NeighbourMapEntry *n = cls;
468 450
@@ -479,17 +461,14 @@ neighbour_timeout_task (void *cls,
479 * @param value the 'struct NeighbourMapEntry' of the neighbour 461 * @param value the 'struct NeighbourMapEntry' of the neighbour
480 */ 462 */
481static int 463static int
482disconnect_all_neighbours (void *cls, 464disconnect_all_neighbours (void *cls, const GNUNET_HashCode * key, void *value)
483 const GNUNET_HashCode *key,
484 void *value)
485{ 465{
486 struct NeighbourMapEntry *n = value; 466 struct NeighbourMapEntry *n = value;
487 467
488#if DEBUG_TRANSPORT 468#if DEBUG_TRANSPORT
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 469 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 "Disconnecting peer `%4s', %s\n", 470 "Disconnecting peer `%4s', %s\n",
491 GNUNET_i2s(&n->id), 471 GNUNET_i2s (&n->id), "SHUTDOWN_TASK");
492 "SHUTDOWN_TASK");
493#endif 472#endif
494 disconnect_neighbour (n); 473 disconnect_neighbour (n);
495 return GNUNET_OK; 474 return GNUNET_OK;
@@ -503,8 +482,7 @@ void
503GST_neighbours_stop () 482GST_neighbours_stop ()
504{ 483{
505 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 484 GNUNET_CONTAINER_multihashmap_iterate (neighbours,
506 &disconnect_all_neighbours, 485 &disconnect_all_neighbours, NULL);
507 NULL);
508 GNUNET_CONTAINER_multihashmap_destroy (neighbours); 486 GNUNET_CONTAINER_multihashmap_destroy (neighbours);
509 neighbours = NULL; 487 neighbours = NULL;
510 callback_cls = NULL; 488 callback_cls = NULL;
@@ -528,46 +506,42 @@ GST_neighbours_stop ()
528 */ 506 */
529void 507void
530GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, 508GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
531 const char *plugin_name, 509 const char *plugin_name,
532 const void *address, 510 const void *address,
533 size_t address_len, 511 size_t address_len,
534 struct Session *session, 512 struct Session *session,
535 const struct GNUNET_TRANSPORT_ATS_Information *ats, 513 const struct GNUNET_TRANSPORT_ATS_Information
536 uint32_t ats_count) 514 *ats, uint32_t ats_count)
537{ 515{
538 struct NeighbourMapEntry *n; 516 struct NeighbourMapEntry *n;
539 struct GNUNET_MessageHeader connect_msg; 517 struct GNUNET_MessageHeader connect_msg;
540 518
541 n = lookup_neighbour (peer); 519 n = lookup_neighbour (peer);
542 if (NULL == n) 520 if (NULL == n)
543 { 521 {
544 GNUNET_break (0); 522 GNUNET_break (0);
545 return; 523 return;
546 } 524 }
547 GNUNET_free_non_null (n->addr); 525 GNUNET_free_non_null (n->addr);
548 n->addr = GNUNET_malloc (address_len); 526 n->addr = GNUNET_malloc (address_len);
549 memcpy (n->addr, address, address_len); 527 memcpy (n->addr, address, address_len);
550 n->addrlen = address_len; 528 n->addrlen = address_len;
551 n->session = session; 529 n->session = session;
552 GNUNET_array_grow (n->ats, 530 GNUNET_array_grow (n->ats, n->ats_count, ats_count);
553 n->ats_count,
554 ats_count);
555 memcpy (n->ats, 531 memcpy (n->ats,
556 ats, 532 ats, ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
557 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information));
558 GNUNET_free_non_null (n->plugin_name); 533 GNUNET_free_non_null (n->plugin_name);
559 n->plugin_name = GNUNET_strdup (plugin_name); 534 n->plugin_name = GNUNET_strdup (plugin_name);
560 GNUNET_SCHEDULER_cancel (n->timeout_task); 535 GNUNET_SCHEDULER_cancel (n->timeout_task);
561 n->timeout_task = 536 n->timeout_task =
562 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 537 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
563 &neighbour_timeout_task, n); 538 &neighbour_timeout_task, n);
564 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 539 connect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
565 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 540 connect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
566 GST_neighbours_send (peer, 541 GST_neighbours_send (peer,
567 &connect_msg, 542 &connect_msg,
568 sizeof (connect_msg), 543 sizeof (connect_msg),
569 GNUNET_TIME_UNIT_FOREVER_REL, 544 GNUNET_TIME_UNIT_FOREVER_REL, NULL, NULL);
570 NULL, NULL);
571} 545}
572 546
573 547
@@ -585,30 +559,25 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
585 */ 559 */
586static void 560static void
587try_connect_using_address (void *cls, 561try_connect_using_address (void *cls,
588 const struct GNUNET_PeerIdentity *target, 562 const struct GNUNET_PeerIdentity *target,
589 const char *plugin_name, 563 const char *plugin_name,
590 const void *plugin_address, 564 const void *plugin_address,
591 size_t plugin_address_len, 565 size_t plugin_address_len,
592 struct GNUNET_BANDWIDTH_Value32NBO bandwidth, 566 struct GNUNET_BANDWIDTH_Value32NBO bandwidth,
593 const struct GNUNET_TRANSPORT_ATS_Information *ats, 567 const struct GNUNET_TRANSPORT_ATS_Information *ats,
594 uint32_t ats_count) 568 uint32_t ats_count)
595{ 569{
596 struct NeighbourMapEntry *n = cls; 570 struct NeighbourMapEntry *n = cls;
597 571
598 n->asc = NULL; 572 n->asc = NULL;
599 GST_neighbours_switch_to_address (target, 573 GST_neighbours_switch_to_address (target,
600 plugin_name, 574 plugin_name,
601 plugin_address, 575 plugin_address,
602 plugin_address_len, 576 plugin_address_len, NULL, ats, ats_count);
603 NULL,
604 ats, ats_count);
605 if (GNUNET_YES == n->is_connected) 577 if (GNUNET_YES == n->is_connected)
606 return; 578 return;
607 n->is_connected = GNUNET_YES; 579 n->is_connected = GNUNET_YES;
608 connect_notify_cb (callback_cls, 580 connect_notify_cb (callback_cls, target, n->ats, n->ats_count);
609 target,
610 n->ats,
611 n->ats_count);
612} 581}
613 582
614 583
@@ -623,33 +592,30 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
623 struct NeighbourMapEntry *n; 592 struct NeighbourMapEntry *n;
624 593
625 GNUNET_assert (0 != memcmp (target, 594 GNUNET_assert (0 != memcmp (target,
626 &GST_my_identity, 595 &GST_my_identity,
627 sizeof (struct GNUNET_PeerIdentity))); 596 sizeof (struct GNUNET_PeerIdentity)));
628 n = lookup_neighbour (target); 597 n = lookup_neighbour (target);
629 if ( (NULL != n) && 598 if ((NULL != n) && (GNUNET_YES == n->is_connected))
630 (GNUNET_YES == n->is_connected) ) 599 return; /* already connected */
631 return; /* already connected */
632 if (n == NULL) 600 if (n == NULL)
633 { 601 {
634 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry)); 602 n = GNUNET_malloc (sizeof (struct NeighbourMapEntry));
635 n->id = *target; 603 n->id = *target;
636 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker, 604 GNUNET_BANDWIDTH_tracker_init (&n->in_tracker,
637 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 605 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
638 MAX_BANDWIDTH_CARRY_S); 606 MAX_BANDWIDTH_CARRY_S);
639 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 607 n->timeout_task =
640 &neighbour_timeout_task, n); 608 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
641 GNUNET_assert (GNUNET_OK == 609 &neighbour_timeout_task, n);
642 GNUNET_CONTAINER_multihashmap_put (neighbours, 610 GNUNET_assert (GNUNET_OK ==
643 &n->id.hashPubKey, 611 GNUNET_CONTAINER_multihashmap_put (neighbours,
644 n, 612 &n->id.hashPubKey, n,
645 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 613 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
646 } 614 }
647 if (n->asc != NULL) 615 if (n->asc != NULL)
648 return; /* already trying */ 616 return; /* already trying */
649 n->asc = GNUNET_ATS_suggest_address (GST_ats, 617 n->asc = GNUNET_ATS_suggest_address (GST_ats,
650 target, 618 target, &try_connect_using_address, n);
651 &try_connect_using_address,
652 n);
653} 619}
654 620
655 621
@@ -665,9 +631,8 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
665 struct NeighbourMapEntry *n; 631 struct NeighbourMapEntry *n;
666 632
667 n = lookup_neighbour (target); 633 n = lookup_neighbour (target);
668 if ( (NULL == n) || 634 if ((NULL == n) || (n->is_connected == GNUNET_YES))
669 (n->is_connected == GNUNET_YES) ) 635 return GNUNET_NO; /* not connected */
670 return GNUNET_NO; /* not connected */
671 return GNUNET_YES; 636 return GNUNET_YES;
672} 637}
673 638
@@ -680,7 +645,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
680 */ 645 */
681void 646void
682GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, 647GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
683 struct Session *session) 648 struct Session *session)
684{ 649{
685 struct NeighbourMapEntry *n; 650 struct NeighbourMapEntry *n;
686 651
@@ -688,24 +653,23 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
688 if (NULL == n) 653 if (NULL == n)
689 return; 654 return;
690 if (session != n->session) 655 if (session != n->session)
691 return; /* doesn't affect us */ 656 return; /* doesn't affect us */
692 n->session = NULL; 657 n->session = NULL;
693 if (GNUNET_YES != n->is_connected) 658 if (GNUNET_YES != n->is_connected)
694 return; /* not connected anymore anyway, shouldn't matter */ 659 return; /* not connected anymore anyway, shouldn't matter */
695 /* try QUICKLY to re-establish a connection, reduce timeout! */ 660 /* try QUICKLY to re-establish a connection, reduce timeout! */
696 if (NULL != n->ats) 661 if (NULL != n->ats)
697 { 662 {
698 /* how can this be!? */ 663 /* how can this be!? */
699 GNUNET_break (0); 664 GNUNET_break (0);
700 return; 665 return;
701 } 666 }
702 GNUNET_SCHEDULER_cancel (n->timeout_task); 667 GNUNET_SCHEDULER_cancel (n->timeout_task);
703 n->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 668 n->timeout_task =
704 &neighbour_timeout_task, n); 669 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
705 n->asc = GNUNET_ATS_suggest_address (GST_ats, 670 &neighbour_timeout_task, n);
706 peer, 671 n->asc =
707 &try_connect_using_address, 672 GNUNET_ATS_suggest_address (GST_ats, peer, &try_connect_using_address, n);
708 n);
709} 673}
710 674
711 675
@@ -721,48 +685,42 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
721 */ 685 */
722void 686void
723GST_neighbours_send (const struct GNUNET_PeerIdentity *target, 687GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
724 const void *msg, 688 const void *msg,
725 size_t msg_size, 689 size_t msg_size,
726 struct GNUNET_TIME_Relative timeout, 690 struct GNUNET_TIME_Relative timeout,
727 GST_NeighbourSendContinuation cont, 691 GST_NeighbourSendContinuation cont, void *cont_cls)
728 void *cont_cls)
729{ 692{
730 struct NeighbourMapEntry *n; 693 struct NeighbourMapEntry *n;
731 struct MessageQueue *mq; 694 struct MessageQueue *mq;
732 695
733 n = lookup_neighbour (target); 696 n = lookup_neighbour (target);
734 if ( (n == NULL) || 697 if ((n == NULL) || (GNUNET_YES != n->is_connected))
735 (GNUNET_YES != n->is_connected) ) 698 {
736 { 699 GNUNET_STATISTICS_update (GST_stats,
737 GNUNET_STATISTICS_update (GST_stats, 700 gettext_noop
738 gettext_noop ("# SET QUOTA messages ignored (no such peer)"), 701 ("# SET QUOTA messages ignored (no such peer)"),
739 1, 702 1, GNUNET_NO);
740 GNUNET_NO); 703 if (NULL != cont)
741 if (NULL != cont) 704 cont (cont_cls, GNUNET_SYSERR);
742 cont (cont_cls, 705 return;
743 GNUNET_SYSERR); 706 }
744 return;
745 }
746 GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader)); 707 GNUNET_assert (msg_size >= sizeof (struct GNUNET_MessageHeader));
747 GNUNET_STATISTICS_update (GST_stats, 708 GNUNET_STATISTICS_update (GST_stats,
748 gettext_noop ("# bytes in message queue for other peers"), 709 gettext_noop
749 msg_size, 710 ("# bytes in message queue for other peers"),
750 GNUNET_NO); 711 msg_size, GNUNET_NO);
751 mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size); 712 mq = GNUNET_malloc (sizeof (struct MessageQueue) + msg_size);
752 mq->cont = cont; 713 mq->cont = cont;
753 mq->cont_cls = cont_cls; 714 mq->cont_cls = cont_cls;
754 /* FIXME: this memcpy can be up to 7% of our total runtime! */ 715 /* FIXME: this memcpy can be up to 7% of our total runtime! */
755 memcpy (&mq[1], msg, msg_size); 716 memcpy (&mq[1], msg, msg_size);
756 mq->message_buf = (const char*) &mq[1]; 717 mq->message_buf = (const char *) &mq[1];
757 mq->message_buf_size = msg_size; 718 mq->message_buf_size = msg_size;
758 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); 719 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
759 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, 720 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
760 n->messages_tail, 721 if ((GNUNET_SCHEDULER_NO_TASK == n->transmission_task) &&
761 mq); 722 (NULL == n->is_active))
762 if ( (GNUNET_SCHEDULER_NO_TASK == n->transmission_task) && 723 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task, n);
763 (NULL == n->is_active) )
764 n->transmission_task = GNUNET_SCHEDULER_add_now (&transmission_task,
765 n);
766} 724}
767 725
768 726
@@ -778,68 +736,64 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
778 * @return how long to wait before reading more from this sender 736 * @return how long to wait before reading more from this sender
779 */ 737 */
780struct GNUNET_TIME_Relative 738struct GNUNET_TIME_Relative
781GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender, 739GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
782 ssize_t size, 740 *sender, ssize_t size, int *do_forward)
783 int *do_forward)
784{ 741{
785 struct NeighbourMapEntry *n; 742 struct NeighbourMapEntry *n;
786 struct GNUNET_TIME_Relative ret; 743 struct GNUNET_TIME_Relative ret;
787 744
788 n = lookup_neighbour (sender); 745 n = lookup_neighbour (sender);
789 if (n == NULL) 746 if (n == NULL)
790 { 747 {
791 *do_forward = GNUNET_NO; 748 *do_forward = GNUNET_NO;
792 return GNUNET_TIME_UNIT_ZERO; 749 return GNUNET_TIME_UNIT_ZERO;
793 } 750 }
794 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 751 if (GNUNET_YES == GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, size))
795 size)) 752 {
796 { 753 n->quota_violation_count++;
797 n->quota_violation_count++;
798#if DEBUG_TRANSPORT 754#if DEBUG_TRANSPORT
799 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
800 "Bandwidth quota (%u b/s) violation detected (total of %u).\n", 756 "Bandwidth quota (%u b/s) violation detected (total of %u).\n",
801 n->in_tracker.available_bytes_per_s__, 757 n->in_tracker.available_bytes_per_s__,
802 n->quota_violation_count); 758 n->quota_violation_count);
803#endif 759#endif
804 /* Discount 32k per violation */ 760 /* Discount 32k per violation */
805 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 761 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, -32 * 1024);
806 - 32 * 1024); 762 }
807 }
808 else 763 else
764 {
765 if (n->quota_violation_count > 0)
809 { 766 {
810 if (n->quota_violation_count > 0) 767 /* try to add 32k back */
811 { 768 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker, 32 * 1024);
812 /* try to add 32k back */ 769 n->quota_violation_count--;
813 GNUNET_BANDWIDTH_tracker_consume (&n->in_tracker,
814 32 * 1024);
815 n->quota_violation_count--;
816 }
817 } 770 }
771 }
818 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD) 772 if (n->quota_violation_count > QUOTA_VIOLATION_DROP_THRESHOLD)
819 { 773 {
820 GNUNET_STATISTICS_update (GST_stats, 774 GNUNET_STATISTICS_update (GST_stats,
821 gettext_noop ("# bandwidth quota violations by other peers"), 775 gettext_noop
822 1, 776 ("# bandwidth quota violations by other peers"),
823 GNUNET_NO); 777 1, GNUNET_NO);
824 *do_forward = GNUNET_NO; 778 *do_forward = GNUNET_NO;
825 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT; 779 return GNUNET_CONSTANTS_QUOTA_VIOLATION_TIMEOUT;
826 } 780 }
827 *do_forward = GNUNET_YES; 781 *do_forward = GNUNET_YES;
828 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0); 782 ret = GNUNET_BANDWIDTH_tracker_get_delay (&n->in_tracker, 0);
829 if (ret.rel_value > 0) 783 if (ret.rel_value > 0)
830 { 784 {
831#if DEBUG_TRANSPORT 785#if DEBUG_TRANSPORT
832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
833 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n", 787 "Throttling read (%llu bytes excess at %u b/s), waiting %llu ms before reading more.\n",
834 (unsigned long long) n->in_tracker.consumption_since_last_update__, 788 (unsigned long long) n->
835 (unsigned int) n->in_tracker.available_bytes_per_s__, 789 in_tracker.consumption_since_last_update__,
836 (unsigned long long) ret.rel_value); 790 (unsigned int) n->in_tracker.available_bytes_per_s__,
791 (unsigned long long) ret.rel_value);
837#endif 792#endif
838 GNUNET_STATISTICS_update (GST_stats, 793 GNUNET_STATISTICS_update (GST_stats,
839 gettext_noop ("# ms throttling suggested"), 794 gettext_noop ("# ms throttling suggested"),
840 (int64_t) ret.rel_value, 795 (int64_t) ret.rel_value, GNUNET_NO);
841 GNUNET_NO); 796 }
842 }
843 return ret; 797 return ret;
844} 798}
845 799
@@ -857,17 +811,17 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
857 811
858 n = lookup_neighbour (neighbour); 812 n = lookup_neighbour (neighbour);
859 if (NULL == n) 813 if (NULL == n)
860 { 814 {
861 GNUNET_STATISTICS_update (GST_stats, 815 GNUNET_STATISTICS_update (GST_stats,
862 gettext_noop ("# KEEPALIVE messages discarded (not connected)"), 816 gettext_noop
863 1, 817 ("# KEEPALIVE messages discarded (not connected)"),
864 GNUNET_NO); 818 1, GNUNET_NO);
865 return; 819 return;
866 } 820 }
867 GNUNET_SCHEDULER_cancel (n->timeout_task); 821 GNUNET_SCHEDULER_cancel (n->timeout_task);
868 n->timeout_task = 822 n->timeout_task =
869 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 823 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
870 &neighbour_timeout_task, n); 824 &neighbour_timeout_task, n);
871} 825}
872 826
873 827
@@ -879,33 +833,30 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour)
879 */ 833 */
880void 834void
881GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour, 835GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
882 struct GNUNET_BANDWIDTH_Value32NBO quota) 836 struct GNUNET_BANDWIDTH_Value32NBO quota)
883{ 837{
884 struct NeighbourMapEntry *n; 838 struct NeighbourMapEntry *n;
885 839
886 n = lookup_neighbour (neighbour); 840 n = lookup_neighbour (neighbour);
887 if (n == NULL) 841 if (n == NULL)
888 { 842 {
889 GNUNET_STATISTICS_update (GST_stats, 843 GNUNET_STATISTICS_update (GST_stats,
890 gettext_noop ("# SET QUOTA messages ignored (no such peer)"), 844 gettext_noop
891 1, 845 ("# SET QUOTA messages ignored (no such peer)"),
892 GNUNET_NO); 846 1, GNUNET_NO);
893 return; 847 return;
894 } 848 }
895 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, 849 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker, quota);
896 quota);
897 if (0 != ntohl (quota.value__)) 850 if (0 != ntohl (quota.value__))
898 return; 851 return;
899#if DEBUG_TRANSPORT 852#if DEBUG_TRANSPORT
900 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
901 "Disconnecting peer `%4s' due to `%s'\n", 854 "Disconnecting peer `%4s' due to `%s'\n",
902 GNUNET_i2s(&n->id), 855 GNUNET_i2s (&n->id), "SET_QUOTA");
903 "SET_QUOTA");
904#endif 856#endif
905 GNUNET_STATISTICS_update (GST_stats, 857 GNUNET_STATISTICS_update (GST_stats,
906 gettext_noop ("# disconnects due to quota of 0"), 858 gettext_noop ("# disconnects due to quota of 0"),
907 1, 859 1, GNUNET_NO);
908 GNUNET_NO);
909 disconnect_neighbour (n); 860 disconnect_neighbour (n);
910} 861}
911 862
@@ -936,20 +887,15 @@ struct IteratorContext
936 * @return GNUNET_OK (continue to iterate) 887 * @return GNUNET_OK (continue to iterate)
937 */ 888 */
938static int 889static int
939neighbours_iterate (void *cls, 890neighbours_iterate (void *cls, const GNUNET_HashCode * key, void *value)
940 const GNUNET_HashCode *key,
941 void *value)
942{ 891{
943 struct IteratorContext *ic = cls; 892 struct IteratorContext *ic = cls;
944 struct NeighbourMapEntry *n = value; 893 struct NeighbourMapEntry *n = value;
945 894
946 if (GNUNET_YES != n->is_connected) 895 if (GNUNET_YES != n->is_connected)
947 return GNUNET_OK; 896 return GNUNET_OK;
948 GNUNET_assert (n->ats_count > 0); 897 GNUNET_assert (n->ats_count > 0);
949 ic->cb (ic->cb_cls, 898 ic->cb (ic->cb_cls, &n->id, n->ats, n->ats_count - 1);
950 &n->id,
951 n->ats,
952 n->ats_count - 1);
953 return GNUNET_OK; 899 return GNUNET_OK;
954} 900}
955 901
@@ -961,16 +907,13 @@ neighbours_iterate (void *cls,
961 * @param cb_cls closure for cb 907 * @param cb_cls closure for cb
962 */ 908 */
963void 909void
964GST_neighbours_iterate (GST_NeighbourIterator cb, 910GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls)
965 void *cb_cls)
966{ 911{
967 struct IteratorContext ic; 912 struct IteratorContext ic;
968 913
969 ic.cb = cb; 914 ic.cb = cb;
970 ic.cb_cls = cb_cls; 915 ic.cb_cls = cb_cls;
971 GNUNET_CONTAINER_multihashmap_iterate (neighbours, 916 GNUNET_CONTAINER_multihashmap_iterate (neighbours, &neighbours_iterate, &ic);
972 &neighbours_iterate,
973 &ic);
974} 917}
975 918
976 919
@@ -987,27 +930,23 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
987 struct GNUNET_MessageHeader disconnect_msg; 930 struct GNUNET_MessageHeader disconnect_msg;
988 931
989 n = lookup_neighbour (target); 932 n = lookup_neighbour (target);
990 if (NULL == n) 933 if (NULL == n)
991 return; /* not active */ 934 return; /* not active */
992 if (GNUNET_YES == n->is_connected) 935 if (GNUNET_YES == n->is_connected)
993 { 936 {
994 /* we're actually connected, send DISCONNECT message */ 937 /* we're actually connected, send DISCONNECT message */
995 disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 938 disconnect_msg.size = htons (sizeof (struct GNUNET_MessageHeader));
996 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT); 939 disconnect_msg.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
997 papi = GST_plugins_find (n->plugin_name); 940 papi = GST_plugins_find (n->plugin_name);
998 if (papi != NULL) 941 if (papi != NULL)
999 papi->send (papi->cls, 942 papi->send (papi->cls,
1000 target, 943 target,
1001 (const void*) &disconnect_msg, 944 (const void *) &disconnect_msg,
1002 sizeof (struct GNUNET_MessageHeader), 945 sizeof (struct GNUNET_MessageHeader),
1003 UINT32_MAX /* priority */, 946 UINT32_MAX /* priority */ ,
1004 GNUNET_TIME_UNIT_FOREVER_REL, 947 GNUNET_TIME_UNIT_FOREVER_REL,
1005 n->session, 948 n->session, n->addr, n->addrlen, GNUNET_YES, NULL, NULL);
1006 n->addr, 949 }
1007 n->addrlen,
1008 GNUNET_YES,
1009 NULL, NULL);
1010 }
1011 disconnect_neighbour (n); 950 disconnect_neighbour (n);
1012} 951}
1013 952
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index a99cd1e96..c263c33d9 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -43,17 +43,16 @@
43 * @param connect_cb function to call if we connect to a peer 43 * @param connect_cb function to call if we connect to a peer
44 * @param disconnect_cb function to call if we disconnect from a peer 44 * @param disconnect_cb function to call if we disconnect from a peer
45 */ 45 */
46void 46void
47GST_neighbours_start (void *cls, 47GST_neighbours_start (void *cls,
48 GNUNET_TRANSPORT_NotifyConnect connect_cb, 48 GNUNET_TRANSPORT_NotifyConnect connect_cb,
49 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb); 49 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb);
50 50
51 51
52/** 52/**
53 * Cleanup the neighbours subsystem. 53 * Cleanup the neighbours subsystem.
54 */ 54 */
55void 55void GST_neighbours_stop (void);
56GST_neighbours_stop (void);
57 56
58 57
59/** 58/**
@@ -61,8 +60,7 @@ GST_neighbours_stop (void);
61 * 60 *
62 * @param target peer to try to connect to 61 * @param target peer to try to connect to
63 */ 62 */
64void 63void GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
65GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
66 64
67 65
68/** 66/**
@@ -71,8 +69,7 @@ GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
71 * @param target peer to test 69 * @param target peer to test
72 * @return GNUNET_YES if we are connected, GNUNET_NO if not 70 * @return GNUNET_YES if we are connected, GNUNET_NO if not
73 */ 71 */
74int 72int GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
75GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
76 73
77 74
78/** 75/**
@@ -81,8 +78,7 @@ GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
81 * @param cls closure 78 * @param cls closure
82 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected 79 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
83 */ 80 */
84typedef void (*GST_NeighbourSendContinuation)(void *cls, 81typedef void (*GST_NeighbourSendContinuation) (void *cls, int success);
85 int success);
86 82
87 83
88/** 84/**
@@ -97,11 +93,10 @@ typedef void (*GST_NeighbourSendContinuation)(void *cls,
97 */ 93 */
98void 94void
99GST_neighbours_send (const struct GNUNET_PeerIdentity *target, 95GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
100 const void *msg, 96 const void *msg,
101 size_t msg_size, 97 size_t msg_size,
102 struct GNUNET_TIME_Relative timeout, 98 struct GNUNET_TIME_Relative timeout,
103 GST_NeighbourSendContinuation cont, 99 GST_NeighbourSendContinuation cont, void *cont_cls);
104 void *cont_cls);
105 100
106 101
107/** 102/**
@@ -116,9 +111,8 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
116 * @return how long to wait before reading more from this sender 111 * @return how long to wait before reading more from this sender
117 */ 112 */
118struct GNUNET_TIME_Relative 113struct GNUNET_TIME_Relative
119GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender, 114GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity
120 ssize_t size, 115 *sender, ssize_t size, int *do_forward);
121 int *do_forward);
122 116
123 117
124/** 118/**
@@ -127,8 +121,7 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
127 * 121 *
128 * @param neighbour neighbour to keep alive 122 * @param neighbour neighbour to keep alive
129 */ 123 */
130void 124void GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
131GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
132 125
133 126
134/** 127/**
@@ -139,7 +132,7 @@ GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
139 */ 132 */
140void 133void
141GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour, 134GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
142 struct GNUNET_BANDWIDTH_Value32NBO quota); 135 struct GNUNET_BANDWIDTH_Value32NBO quota);
143 136
144 137
145/** 138/**
@@ -147,8 +140,7 @@ GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
147 * 140 *
148 * @param target peer to disconnect from 141 * @param target peer to disconnect from
149 */ 142 */
150void 143void GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
151GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
152 144
153 145
154/** 146/**
@@ -159,10 +151,12 @@ GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
159 * @param ats performance data 151 * @param ats performance data
160 * @param ats_count number of entries in ats (excluding 0-termination) 152 * @param ats_count number of entries in ats (excluding 0-termination)
161 */ 153 */
162typedef void (*GST_NeighbourIterator)(void *cls, 154typedef void (*GST_NeighbourIterator) (void *cls,
163 const struct GNUNET_PeerIdentity *neighbour, 155 const struct GNUNET_PeerIdentity *
164 const struct GNUNET_TRANSPORT_ATS_Information *ats, 156 neighbour,
165 uint32_t ats_count); 157 const struct
158 GNUNET_TRANSPORT_ATS_Information * ats,
159 uint32_t ats_count);
166 160
167 161
168/** 162/**
@@ -171,9 +165,7 @@ typedef void (*GST_NeighbourIterator)(void *cls,
171 * @param cb function to call 165 * @param cb function to call
172 * @param cb_cls closure for cb 166 * @param cb_cls closure for cb
173 */ 167 */
174void 168void GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls);
175GST_neighbours_iterate (GST_NeighbourIterator cb,
176 void *cb_cls);
177 169
178 170
179/** 171/**
@@ -184,7 +176,7 @@ GST_neighbours_iterate (GST_NeighbourIterator cb,
184 */ 176 */
185void 177void
186GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, 178GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
187 struct Session *session); 179 struct Session *session);
188 180
189 181
190/** 182/**
@@ -202,12 +194,12 @@ GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
202 */ 194 */
203void 195void
204GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, 196GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
205 const char *plugin_name, 197 const char *plugin_name,
206 const void *address, 198 const void *address,
207 size_t address_len, 199 size_t address_len,
208 struct Session *session, 200 struct Session *session,
209 const struct GNUNET_TRANSPORT_ATS_Information *ats, 201 const struct GNUNET_TRANSPORT_ATS_Information
210 uint32_t ats_count); 202 *ats, uint32_t ats_count);
211 203
212 204
213#endif 205#endif
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index 7fcc6f80d..87901d2cc 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -90,10 +90,10 @@ static struct TransportPlugin *plugins_tail;
90 * @param traffic_cb function to call for flow control 90 * @param traffic_cb function to call for flow control
91 * @param session_end_cb function to call when a session was terminated 91 * @param session_end_cb function to call when a session was terminated
92 */ 92 */
93void 93void
94GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 94GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
95 GNUNET_TRANSPORT_AddressNotification address_cb, 95 GNUNET_TRANSPORT_AddressNotification address_cb,
96 GNUNET_TRANSPORT_SessionEnd session_end_cb) 96 GNUNET_TRANSPORT_SessionEnd session_end_cb)
97{ 97{
98 struct TransportPlugin *plug; 98 struct TransportPlugin *plug;
99 unsigned long long tneigh; 99 unsigned long long tneigh;
@@ -103,57 +103,48 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
103 103
104 if (GNUNET_OK != 104 if (GNUNET_OK !=
105 GNUNET_CONFIGURATION_get_value_number (GST_cfg, 105 GNUNET_CONFIGURATION_get_value_number (GST_cfg,
106 "TRANSPORT", 106 "TRANSPORT",
107 "NEIGHBOUR_LIMIT", 107 "NEIGHBOUR_LIMIT", &tneigh))
108 &tneigh)) 108 {
109 { 109 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 110 _("Transport service is lacking NEIGHBOUR_LIMIT option.\n"));
111 _("Transport service is lacking NEIGHBOUR_LIMIT option.\n")); 111 return;
112 return; 112 }
113 }
114 if (GNUNET_OK != 113 if (GNUNET_OK !=
115 GNUNET_CONFIGURATION_get_value_string (GST_cfg, 114 GNUNET_CONFIGURATION_get_value_string (GST_cfg,
116 "TRANSPORT", "PLUGINS", &plugs)) 115 "TRANSPORT", "PLUGINS", &plugs))
117 return; 116 return;
118 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 117 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
119 _("Starting transport plugins `%s'\n"), 118 _("Starting transport plugins `%s'\n"), plugs);
120 plugs);
121 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " ")) 119 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
122 { 120 {
123 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 121 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
124 _("Loading `%s' transport plugin\n"), pos); 122 _("Loading `%s' transport plugin\n"), pos);
125 GNUNET_asprintf (&libname, 123 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
126 "libgnunet_plugin_transport_%s", 124 plug = GNUNET_malloc (sizeof (struct TransportPlugin));
127 pos); 125 plug->short_name = GNUNET_strdup (pos);
128 plug = GNUNET_malloc (sizeof (struct TransportPlugin)); 126 plug->lib_name = libname;
129 plug->short_name = GNUNET_strdup (pos); 127 plug->env.cfg = GST_cfg;
130 plug->lib_name = libname; 128 plug->env.my_identity = &GST_my_identity;
131 plug->env.cfg = GST_cfg; 129 plug->env.get_our_hello = &GST_hello_get;
132 plug->env.my_identity = &GST_my_identity; 130 plug->env.cls = plug->short_name;
133 plug->env.get_our_hello = &GST_hello_get; 131 plug->env.receive = recv_cb;
134 plug->env.cls = plug->short_name; 132 plug->env.notify_address = address_cb;
135 plug->env.receive = recv_cb; 133 plug->env.session_end = session_end_cb;
136 plug->env.notify_address = address_cb; 134 plug->env.max_connections = tneigh;
137 plug->env.session_end = session_end_cb; 135 plug->env.stats = GST_stats;
138 plug->env.max_connections = tneigh; 136 GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
139 plug->env.stats = GST_stats; 137 plug->api = GNUNET_PLUGIN_load (libname, &plug->env);
140 GNUNET_CONTAINER_DLL_insert (plugins_head, 138 if (plug->api == NULL)
141 plugins_tail, 139 {
142 plug); 140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
143 plug->api = GNUNET_PLUGIN_load (libname, &plug->env); 141 _("Failed to load transport plugin for `%s'\n"), pos);
144 if (plug->api == NULL) 142 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
145 { 143 GNUNET_free (plug->short_name);
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 144 GNUNET_free (plug->lib_name);
147 _("Failed to load transport plugin for `%s'\n"), 145 GNUNET_free (plug);
148 pos);
149 GNUNET_CONTAINER_DLL_remove (plugins_head,
150 plugins_tail,
151 plug);
152 GNUNET_free (plug->short_name);
153 GNUNET_free (plug->lib_name);
154 GNUNET_free (plug);
155 }
156 } 146 }
147 }
157 GNUNET_free (plugs); 148 GNUNET_free (plugs);
158} 149}
159 150
@@ -167,15 +158,13 @@ GST_plugins_unload ()
167 struct TransportPlugin *plug; 158 struct TransportPlugin *plug;
168 159
169 while (NULL != (plug = plugins_head)) 160 while (NULL != (plug = plugins_head))
170 { 161 {
171 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api)); 162 GNUNET_break (NULL == GNUNET_PLUGIN_unload (plug->lib_name, plug->api));
172 GNUNET_free (plug->lib_name); 163 GNUNET_free (plug->lib_name);
173 GNUNET_free (plug->short_name); 164 GNUNET_free (plug->short_name);
174 GNUNET_CONTAINER_DLL_remove (plugins_head, 165 GNUNET_CONTAINER_DLL_remove (plugins_head, plugins_tail, plug);
175 plugins_tail, 166 GNUNET_free (plug);
176 plug); 167 }
177 GNUNET_free (plug);
178 }
179} 168}
180 169
181 170
@@ -208,20 +197,16 @@ GST_plugins_find (const char *name)
208 * @return statically allocated (!) human-readable address 197 * @return statically allocated (!) human-readable address
209 */ 198 */
210const char * 199const char *
211GST_plugins_a2s (const char *name, 200GST_plugins_a2s (const char *name, const void *addr, size_t addrlen)
212 const void *addr,
213 size_t addrlen)
214{ 201{
215 struct GNUNET_TRANSPORT_PluginFunctions *api; 202 struct GNUNET_TRANSPORT_PluginFunctions *api;
216 203
217 if (name == NULL) 204 if (name == NULL)
218 return NULL; 205 return NULL;
219 api = GST_plugins_find (name); 206 api = GST_plugins_find (name);
220 if ( (api == NULL) || (addrlen == 0) || (addr == NULL) ) 207 if ((api == NULL) || (addrlen == 0) || (addr == NULL))
221 return NULL; 208 return NULL;
222 return api->address_to_string (NULL, 209 return api->address_to_string (NULL, addr, addrlen);
223 addr,
224 addrlen);
225} 210}
226 211
227 212
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
index 2852ab4bb..f3f46e342 100644
--- a/src/transport/gnunet-service-transport_plugins.h
+++ b/src/transport/gnunet-service-transport_plugins.h
@@ -42,17 +42,16 @@
42 * @param address_cb function to call when our public addresses changed 42 * @param address_cb function to call when our public addresses changed
43 * @param session_end_cb function to call when a session was terminated 43 * @param session_end_cb function to call when a session was terminated
44 */ 44 */
45void 45void
46GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 46GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
47 GNUNET_TRANSPORT_AddressNotification address_cb, 47 GNUNET_TRANSPORT_AddressNotification address_cb,
48 GNUNET_TRANSPORT_SessionEnd session_end_cb); 48 GNUNET_TRANSPORT_SessionEnd session_end_cb);
49 49
50 50
51/** 51/**
52 * Unload all plugins 52 * Unload all plugins
53 */ 53 */
54void 54void GST_plugins_unload (void);
55GST_plugins_unload (void);
56 55
57 56
58/** 57/**
@@ -61,8 +60,7 @@ GST_plugins_unload (void);
61 * @param name name of the plugin 60 * @param name name of the plugin
62 * @return the plugin's API, NULL if the plugin is not loaded 61 * @return the plugin's API, NULL if the plugin is not loaded
63 */ 62 */
64struct GNUNET_TRANSPORT_PluginFunctions * 63struct GNUNET_TRANSPORT_PluginFunctions *GST_plugins_find (const char *name);
65GST_plugins_find (const char *name);
66 64
67 65
68/** 66/**
@@ -74,10 +72,8 @@ GST_plugins_find (const char *name);
74 * @param addrlen number of bytes in 'addr' 72 * @param addrlen number of bytes in 'addr'
75 * @return statically allocated (!) human-readable address 73 * @return statically allocated (!) human-readable address
76 */ 74 */
77const char * 75const char *GST_plugins_a2s (const char *name,
78GST_plugins_a2s (const char *name, 76 const void *addr, size_t addrlen);
79 const void *addr,
80 size_t addrlen);
81 77
82 78
83#endif 79#endif
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 86c51c729..f618a2b1a 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -66,12 +66,12 @@
66 66
67/** 67/**
68 * Priority to use for PINGs 68 * Priority to use for PINGs
69 */ 69 */
70#define PING_PRIORITY 2 70#define PING_PRIORITY 2
71 71
72/** 72/**
73 * Priority to use for PONGs 73 * Priority to use for PONGs
74 */ 74 */
75#define PONG_PRIORITY 4 75#define PONG_PRIORITY 4
76 76
77 77
@@ -154,7 +154,7 @@ struct TransportPongMessage
154/** 154/**
155 * Information about an address under validation 155 * Information about an address under validation
156 */ 156 */
157struct ValidationEntry 157struct ValidationEntry
158{ 158{
159 159
160 /** 160 /**
@@ -176,7 +176,7 @@ struct ValidationEntry
176 /** 176 /**
177 * Public key of the peer. 177 * Public key of the peer.
178 */ 178 */
179 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; 179 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
180 180
181 /** 181 /**
182 * The identity of the peer. 182 * The identity of the peer.
@@ -206,7 +206,7 @@ struct ValidationEntry
206 * otherwise a time in the future if we're currently denying re-validation 206 * otherwise a time in the future if we're currently denying re-validation
207 */ 207 */
208 struct GNUNET_TIME_Absolute validation_block; 208 struct GNUNET_TIME_Absolute validation_block;
209 209
210 /** 210 /**
211 * Challenge number we used. 211 * Challenge number we used.
212 */ 212 */
@@ -277,7 +277,7 @@ struct ValidationEntryMatchContext
277 * Where to store the result? 277 * Where to store the result?
278 */ 278 */
279 struct ValidationEntry *ve; 279 struct ValidationEntry *ve;
280 280
281 /** 281 /**
282 * Transport name we're looking for. 282 * Transport name we're looking for.
283 */ 283 */
@@ -305,20 +305,18 @@ struct ValidationEntryMatchContext
305 * GNUNET_NO if the entry does match 305 * GNUNET_NO if the entry does match
306 */ 306 */
307static int 307static int
308validation_entry_match (void *cls, 308validation_entry_match (void *cls, const GNUNET_HashCode * key, void *value)
309 const GNUNET_HashCode *key,
310 void *value)
311{ 309{
312 struct ValidationEntryMatchContext *vemc = cls; 310 struct ValidationEntryMatchContext *vemc = cls;
313 struct ValidationEntry *ve = value; 311 struct ValidationEntry *ve = value;
314 312
315 if ( (ve->addrlen == vemc->addrlen) && 313 if ((ve->addrlen == vemc->addrlen) &&
316 (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) && 314 (0 == memcmp (ve->addr, vemc->addr, ve->addrlen)) &&
317 (0 == strcmp (ve->transport_name, vemc->transport_name)) ) 315 (0 == strcmp (ve->transport_name, vemc->transport_name)))
318 { 316 {
319 vemc->ve = ve; 317 vemc->ve = ve;
320 return GNUNET_NO; 318 return GNUNET_NO;
321 } 319 }
322 return GNUNET_YES; 320 return GNUNET_YES;
323} 321}
324 322
@@ -340,11 +338,9 @@ validation_entry_match (void *cls,
340 * if we don't have an existing entry and no public key was given 338 * if we don't have an existing entry and no public key was given
341 */ 339 */
342static struct ValidationEntry * 340static struct ValidationEntry *
343find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, 341find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
344 const struct GNUNET_PeerIdentity *neighbour, 342 *public_key, const struct GNUNET_PeerIdentity *neighbour,
345 const char *tname, 343 const char *tname, const char *addr, size_t addrlen)
346 const char *addr,
347 size_t addrlen)
348{ 344{
349 struct ValidationEntryMatchContext vemc; 345 struct ValidationEntryMatchContext vemc;
350 struct ValidationEntry *ve; 346 struct ValidationEntry *ve;
@@ -354,26 +350,25 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub
354 vemc.addr = addr; 350 vemc.addr = addr;
355 vemc.addrlen = addrlen; 351 vemc.addrlen = addrlen;
356 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, 352 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
357 &neighbour->hashPubKey, 353 &neighbour->hashPubKey,
358 &validation_entry_match, 354 &validation_entry_match, &vemc);
359 &vemc);
360 if (NULL != (ve = vemc.ve)) 355 if (NULL != (ve = vemc.ve))
361 return ve; 356 return ve;
362 if (public_key == NULL) 357 if (public_key == NULL)
363 return NULL; 358 return NULL;
364 ve = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen); 359 ve = GNUNET_malloc (sizeof (struct ValidationEntry) + addrlen);
365 ve->transport_name = GNUNET_strdup (tname); 360 ve->transport_name = GNUNET_strdup (tname);
366 ve->addr = (void*) &ve[1]; 361 ve->addr = (void *) &ve[1];
367 ve->public_key = *public_key; 362 ve->public_key = *public_key;
368 ve->pid = *neighbour; 363 ve->pid = *neighbour;
369 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 364 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
370 UINT32_MAX); 365 UINT32_MAX);
371 memcpy (&ve[1], addr, addrlen); 366 memcpy (&ve[1], addr, addrlen);
372 ve->addrlen = addrlen; 367 ve->addrlen = addrlen;
373 GNUNET_CONTAINER_multihashmap_put (validation_map, 368 GNUNET_CONTAINER_multihashmap_put (validation_map,
374 &neighbour->hashPubKey, 369 &neighbour->hashPubKey,
375 ve, 370 ve,
376 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 371 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
377 return ve; 372 return ve;
378} 373}
379 374
@@ -391,10 +386,9 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub
391 */ 386 */
392static int 387static int
393add_valid_address (void *cls, 388add_valid_address (void *cls,
394 const char *tname, 389 const char *tname,
395 struct GNUNET_TIME_Absolute expiration, 390 struct GNUNET_TIME_Absolute expiration,
396 const void *addr, 391 const void *addr, uint16_t addrlen)
397 uint16_t addrlen)
398{ 392{
399 const struct GNUNET_HELLO_Message *hello = cls; 393 const struct GNUNET_HELLO_Message *hello = cls;
400 struct ValidationEntry *ve; 394 struct ValidationEntry *ve;
@@ -402,26 +396,20 @@ add_valid_address (void *cls,
402 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key; 396 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
403 397
404 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 398 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
405 return GNUNET_OK; /* expired */ 399 return GNUNET_OK; /* expired */
406 if ( (GNUNET_OK != 400 if ((GNUNET_OK !=
407 GNUNET_HELLO_get_id (hello, &pid)) || 401 GNUNET_HELLO_get_id (hello, &pid)) ||
408 (GNUNET_OK != 402 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key)))
409 GNUNET_HELLO_get_key (hello, &public_key)) ) 403 {
410 { 404 GNUNET_break (0);
411 GNUNET_break (0); 405 return GNUNET_OK; /* invalid HELLO !? */
412 return GNUNET_OK; /* invalid HELLO !? */ 406 }
413 }
414 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); 407 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
415 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, 408 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
416 expiration);
417 GNUNET_ATS_address_update (GST_ats, 409 GNUNET_ATS_address_update (GST_ats,
418 &pid, 410 &pid,
419 ve->valid_until, 411 ve->valid_until,
420 tname, 412 tname, NULL, addr, addrlen, NULL, 0);
421 NULL,
422 addr,
423 addrlen,
424 NULL, 0);
425 return GNUNET_OK; 413 return GNUNET_OK;
426} 414}
427 415
@@ -436,31 +424,29 @@ add_valid_address (void *cls,
436 */ 424 */
437static void 425static void
438process_peerinfo_hello (void *cls, 426process_peerinfo_hello (void *cls,
439 const struct GNUNET_PeerIdentity *peer, 427 const struct GNUNET_PeerIdentity *peer,
440 const struct GNUNET_HELLO_Message *hello, 428 const struct GNUNET_HELLO_Message *hello,
441 const char *err_msg) 429 const char *err_msg)
442{ 430{
443 GNUNET_assert (NULL != peer); 431 GNUNET_assert (NULL != peer);
444 if (NULL == hello) 432 if (NULL == hello)
445 return; 433 return;
446 GNUNET_assert (NULL == 434 GNUNET_assert (NULL ==
447 GNUNET_HELLO_iterate_addresses (hello, 435 GNUNET_HELLO_iterate_addresses (hello,
448 GNUNET_NO, 436 GNUNET_NO,
449 &add_valid_address, 437 &add_valid_address,
450 (void*) hello)); 438 (void *) hello));
451} 439}
452 440
453 441
454/** 442/**
455 * Start the validation subsystem. 443 * Start the validation subsystem.
456 */ 444 */
457void 445void
458GST_validation_start () 446GST_validation_start ()
459{ 447{
460 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE); 448 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
461 pnc = GNUNET_PEERINFO_notify (GST_cfg, 449 pnc = GNUNET_PEERINFO_notify (GST_cfg, &process_peerinfo_hello, NULL);
462 &process_peerinfo_hello,
463 NULL);
464} 450}
465 451
466 452
@@ -473,27 +459,24 @@ GST_validation_start ()
473 * @return GNUNET_YES (continue to iterate) 459 * @return GNUNET_YES (continue to iterate)
474 */ 460 */
475static int 461static int
476cleanup_validation_entry (void *cls, 462cleanup_validation_entry (void *cls, const GNUNET_HashCode * key, void *value)
477 const GNUNET_HashCode *key,
478 void *value)
479{ 463{
480 struct ValidationEntry *ve = value; 464 struct ValidationEntry *ve = value;
481 465
482 if (NULL != ve->bc) 466 if (NULL != ve->bc)
483 { 467 {
484 GST_blacklist_test_cancel (ve->bc); 468 GST_blacklist_test_cancel (ve->bc);
485 ve->bc = NULL; 469 ve->bc = NULL;
486 } 470 }
487 GNUNET_break (GNUNET_OK == 471 GNUNET_break (GNUNET_OK ==
488 GNUNET_CONTAINER_multihashmap_remove (validation_map, 472 GNUNET_CONTAINER_multihashmap_remove (validation_map,
489 &ve->pid.hashPubKey, 473 &ve->pid.hashPubKey, ve));
490 ve));
491 GNUNET_free (ve->transport_name); 474 GNUNET_free (ve->transport_name);
492 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) 475 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
493 { 476 {
494 GNUNET_SCHEDULER_cancel (ve->timeout_task); 477 GNUNET_SCHEDULER_cancel (ve->timeout_task);
495 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK; 478 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
496 } 479 }
497 GNUNET_free (ve); 480 GNUNET_free (ve);
498 return GNUNET_OK; 481 return GNUNET_OK;
499} 482}
@@ -508,17 +491,14 @@ GST_validation_stop ()
508 struct CheckHelloValidatedContext *chvc; 491 struct CheckHelloValidatedContext *chvc;
509 492
510 GNUNET_CONTAINER_multihashmap_iterate (validation_map, 493 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
511 &cleanup_validation_entry, 494 &cleanup_validation_entry, NULL);
512 NULL);
513 GNUNET_CONTAINER_multihashmap_destroy (validation_map); 495 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
514 validation_map = NULL; 496 validation_map = NULL;
515 while (NULL != (chvc = chvc_head)) 497 while (NULL != (chvc = chvc_head))
516 { 498 {
517 GNUNET_CONTAINER_DLL_remove (chvc_head, 499 GNUNET_CONTAINER_DLL_remove (chvc_head, chvc_tail, chvc);
518 chvc_tail, 500 GNUNET_free (chvc);
519 chvc); 501 }
520 GNUNET_free (chvc);
521 }
522 GNUNET_PEERINFO_notify_cancel (pnc); 502 GNUNET_PEERINFO_notify_cancel (pnc);
523} 503}
524 504
@@ -530,16 +510,15 @@ GST_validation_stop ()
530 * @param tc scheduler context (unused) 510 * @param tc scheduler context (unused)
531 */ 511 */
532static void 512static void
533timeout_hello_validation (void *cls, 513timeout_hello_validation (void *cls,
534 const struct GNUNET_SCHEDULER_TaskContext *tc) 514 const struct GNUNET_SCHEDULER_TaskContext *tc)
535{ 515{
536 struct ValidationEntry *ve = cls; 516 struct ValidationEntry *ve = cls;
537 517
538 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK; 518 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
539 GNUNET_STATISTICS_update (GST_stats, 519 GNUNET_STATISTICS_update (GST_stats,
540 gettext_noop ("# address records discarded"), 520 gettext_noop ("# address records discarded"),
541 1, 521 1, GNUNET_NO);
542 GNUNET_NO);
543 cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve); 522 cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve);
544} 523}
545 524
@@ -561,13 +540,12 @@ timeout_hello_validation (void *cls,
561 */ 540 */
562static void 541static void
563multicast_pong (void *cls, 542multicast_pong (void *cls,
564 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, 543 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
565 const struct GNUNET_PeerIdentity *target, 544 *public_key, const struct GNUNET_PeerIdentity *target,
566 struct GNUNET_TIME_Absolute valid_until, 545 struct GNUNET_TIME_Absolute valid_until,
567 struct GNUNET_TIME_Absolute validation_block, 546 struct GNUNET_TIME_Absolute validation_block,
568 const char *plugin_name, 547 const char *plugin_name, const void *plugin_address,
569 const void *plugin_address, 548 size_t plugin_address_len)
570 size_t plugin_address_len)
571{ 549{
572 struct TransportPongMessage *pong = cls; 550 struct TransportPongMessage *pong = cls;
573 struct GNUNET_TRANSPORT_PluginFunctions *papi; 551 struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -576,16 +554,14 @@ multicast_pong (void *cls,
576 if (papi == NULL) 554 if (papi == NULL)
577 return; 555 return;
578 (void) papi->send (papi->cls, 556 (void) papi->send (papi->cls,
579 target, 557 target,
580 (const char*) pong, 558 (const char *) pong,
581 ntohs (pong->header.size), 559 ntohs (pong->header.size),
582 PONG_PRIORITY, 560 PONG_PRIORITY,
583 HELLO_REVALIDATION_START_TIME, 561 HELLO_REVALIDATION_START_TIME,
584 NULL, 562 NULL,
585 plugin_address, 563 plugin_address,
586 plugin_address_len, 564 plugin_address_len, GNUNET_YES, NULL, NULL);
587 GNUNET_YES,
588 NULL, NULL);
589} 565}
590 566
591 567
@@ -602,11 +578,11 @@ multicast_pong (void *cls,
602 */ 578 */
603void 579void
604GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, 580GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
605 const struct GNUNET_MessageHeader *hdr, 581 const struct GNUNET_MessageHeader *hdr,
606 const char *plugin_name, 582 const char *plugin_name,
607 struct Session *session, 583 struct Session *session,
608 const void *sender_address, 584 const void *sender_address,
609 size_t sender_address_len) 585 size_t sender_address_len)
610{ 586{
611 const struct TransportPingMessage *ping; 587 const struct TransportPingMessage *ping;
612 struct TransportPongMessage *pong; 588 struct TransportPongMessage *pong;
@@ -620,124 +596,113 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
620 ssize_t ret; 596 ssize_t ret;
621 597
622 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage)) 598 if (ntohs (hdr->size) < sizeof (struct TransportPingMessage))
623 { 599 {
624 GNUNET_break_op (0); 600 GNUNET_break_op (0);
625 return; 601 return;
626 } 602 }
627 ping = (const struct TransportPingMessage *) hdr; 603 ping = (const struct TransportPingMessage *) hdr;
628 if (0 != memcmp (&ping->target, 604 if (0 != memcmp (&ping->target,
629 &GST_my_identity, 605 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity)))
630 sizeof (struct GNUNET_PeerIdentity))) 606 {
631 { 607 GNUNET_break_op (0);
632 GNUNET_break_op (0); 608 return;
633 return; 609 }
634 }
635 GNUNET_STATISTICS_update (GST_stats, 610 GNUNET_STATISTICS_update (GST_stats,
636 gettext_noop ("# PING messages received"), 611 gettext_noop ("# PING messages received"),
637 1, 612 1, GNUNET_NO);
638 GNUNET_NO); 613 addr = (const char *) &ping[1];
639 addr = (const char*) &ping[1];
640 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage); 614 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
641 /* peer wants to confirm that this is one of our addresses, this is what is 615 /* peer wants to confirm that this is one of our addresses, this is what is
642 used for address validation */ 616 * used for address validation */
643 617
644 addrend = memchr (addr, '\0', alen); 618 addrend = memchr (addr, '\0', alen);
645 if (NULL == addrend) 619 if (NULL == addrend)
646 { 620 {
647 GNUNET_break_op (0); 621 GNUNET_break_op (0);
648 return; 622 return;
649 } 623 }
650 addrend++; 624 addrend++;
651 slen = strlen(addr); 625 slen = strlen (addr);
652 alen -= slen; 626 alen -= slen;
653 627
654 if (GNUNET_YES != 628 if (GNUNET_YES !=
655 GST_hello_test_address (addr, 629 GST_hello_test_address (addr, addrend, alen, &sig_cache, &sig_cache_exp))
656 addrend, 630 {
657 alen, 631 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
658 &sig_cache, 632 _
659 &sig_cache_exp)) 633 ("Not confirming PING with address `%s' since I cannot confirm having this address.\n"),
660 { 634 GST_plugins_a2s (addr, addrend, alen));
661 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 635 return;
662 _("Not confirming PING with address `%s' since I cannot confirm having this address.\n"), 636 }
663 GST_plugins_a2s (addr, 637
664 addrend,
665 alen));
666 return;
667 }
668
669 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen); 638 pong = GNUNET_malloc (sizeof (struct TransportPongMessage) + alen + slen);
670 pong->header.size = htons (sizeof (struct TransportPongMessage) + alen + slen); 639 pong->header.size =
640 htons (sizeof (struct TransportPongMessage) + alen + slen);
671 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 641 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
672 pong->purpose.size = 642 pong->purpose.size =
673 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 643 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
674 sizeof (uint32_t) + 644 sizeof (uint32_t) +
675 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 645 sizeof (struct GNUNET_TIME_AbsoluteNBO) + alen + slen);
676 alen + slen);
677 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 646 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
678 pong->challenge = ping->challenge; 647 pong->challenge = ping->challenge;
679 pong->addrlen = htonl(alen + slen); 648 pong->addrlen = htonl (alen + slen);
680 memcpy (&pong[1], addr, slen); 649 memcpy (&pong[1], addr, slen);
681 memcpy (&((char*)&pong[1])[slen], addrend, alen); 650 memcpy (&((char *) &pong[1])[slen], addrend, alen);
682 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value < PONG_SIGNATURE_LIFETIME.rel_value / 4) 651 if (GNUNET_TIME_absolute_get_remaining (*sig_cache_exp).rel_value <
683 { 652 PONG_SIGNATURE_LIFETIME.rel_value / 4)
684 /* create / update cached sig */ 653 {
654 /* create / update cached sig */
685#if DEBUG_TRANSPORT 655#if DEBUG_TRANSPORT
686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
687 "Creating PONG signature to indicate ownership.\n"); 657 "Creating PONG signature to indicate ownership.\n");
688#endif 658#endif
689 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); 659 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
690 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); 660 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
691 GNUNET_assert (GNUNET_OK == 661 GNUNET_assert (GNUNET_OK ==
692 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, 662 GNUNET_CRYPTO_rsa_sign (GST_my_private_key,
693 &pong->purpose, 663 &pong->purpose, sig_cache));
694 sig_cache)); 664 }
695 }
696 else 665 else
697 { 666 {
698 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); 667 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
699 } 668 }
700 pong->signature = *sig_cache; 669 pong->signature = *sig_cache;
701 670
702 /* first see if the session we got this PING from can be used to transmit 671 /* first see if the session we got this PING from can be used to transmit
703 a response reliably */ 672 * a response reliably */
704 papi = GST_plugins_find (plugin_name); 673 papi = GST_plugins_find (plugin_name);
705 if (papi == NULL) 674 if (papi == NULL)
706 ret = -1; 675 ret = -1;
707 else 676 else
708 ret = papi->send (papi->cls, 677 ret = papi->send (papi->cls,
709 sender, 678 sender,
710 (const char*) pong, 679 (const char *) pong,
711 ntohs (pong->header.size), 680 ntohs (pong->header.size),
712 PONG_PRIORITY, 681 PONG_PRIORITY,
713 HELLO_REVALIDATION_START_TIME, 682 HELLO_REVALIDATION_START_TIME,
714 session, 683 session,
715 sender_address, 684 sender_address,
716 sender_address_len, 685 sender_address_len, GNUNET_SYSERR, NULL, NULL);
717 GNUNET_SYSERR,
718 NULL, NULL);
719 if (ret != -1) 686 if (ret != -1)
720 { 687 {
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Transmitted PONG to `%s' via reliable mechanism\n", 689 "Transmitted PONG to `%s' via reliable mechanism\n",
723 GNUNET_i2s (sender)); 690 GNUNET_i2s (sender));
724 /* done! */ 691 /* done! */
725 GNUNET_STATISTICS_update (GST_stats, 692 GNUNET_STATISTICS_update (GST_stats,
726 gettext_noop ("# PONGs unicast via reliable transport"), 693 gettext_noop
727 1, 694 ("# PONGs unicast via reliable transport"), 1,
728 GNUNET_NO); 695 GNUNET_NO);
729 GNUNET_free (pong); 696 GNUNET_free (pong);
730 return; 697 return;
731 } 698 }
732 699
733 /* no reliable method found, try transmission via all known addresses */ 700 /* no reliable method found, try transmission via all known addresses */
734 GNUNET_STATISTICS_update (GST_stats, 701 GNUNET_STATISTICS_update (GST_stats,
735 gettext_noop ("# PONGs multicast to all available addresses"), 702 gettext_noop
736 1, 703 ("# PONGs multicast to all available addresses"), 1,
737 GNUNET_NO); 704 GNUNET_NO);
738 GST_validation_get_addresses (sender, 705 GST_validation_get_addresses (sender, &multicast_pong, pong);
739 &multicast_pong,
740 pong);
741 GNUNET_free (pong); 706 GNUNET_free (pong);
742} 707}
743 708
@@ -749,7 +714,7 @@ struct ValidateAddressContext
749{ 714{
750 /** 715 /**
751 * Hash of the public key of the peer whose address is being validated. 716 * Hash of the public key of the peer whose address is being validated.
752 */ 717 */
753 struct GNUNET_PeerIdentity pid; 718 struct GNUNET_PeerIdentity pid;
754 719
755 /** 720 /**
@@ -769,8 +734,7 @@ struct ValidateAddressContext
769 */ 734 */
770static void 735static void
771transmit_ping_if_allowed (void *cls, 736transmit_ping_if_allowed (void *cls,
772 const struct GNUNET_PeerIdentity *pid, 737 const struct GNUNET_PeerIdentity *pid, int result)
773 int result)
774{ 738{
775 struct ValidationEntry *ve = cls; 739 struct ValidationEntry *ve = cls;
776 struct TransportPingMessage ping; 740 struct TransportPingMessage ping;
@@ -783,63 +747,55 @@ transmit_ping_if_allowed (void *cls,
783 747
784 ve->bc = NULL; 748 ve->bc = NULL;
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
786 "Transmitting plain PING to `%s'\n", 750 "Transmitting plain PING to `%s'\n", GNUNET_i2s (pid));
787 GNUNET_i2s (pid)); 751 ping.header.size = htons (sizeof (struct TransportPingMessage));
788 ping.header.size = htons(sizeof(struct TransportPingMessage)); 752 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
789 ping.header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 753 ping.challenge = htonl (ve->challenge);
790 ping.challenge = htonl(ve->challenge);
791 ping.target = *pid; 754 ping.target = *pid;
792 755
793 slen = strlen(ve->transport_name) + 1; 756 slen = strlen (ve->transport_name) + 1;
794 hello = GST_hello_get (); 757 hello = GST_hello_get ();
795 hsize = ntohs (hello->size); 758 hsize = ntohs (hello->size);
796 tsize = sizeof(struct TransportPingMessage) + ve->addrlen + slen + hsize; 759 tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize;
797 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 760 if (tsize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
798 { 761 {
799 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 762 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
800 _("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"), 763 _
801 "HELLO", 764 ("Not transmitting `%s' with `%s', message too big (%u bytes!). This should not happen.\n"),
802 "PING", 765 "HELLO", "PING", (unsigned int) tsize);
803 (unsigned int) tsize); 766 /* message too big (!?), get rid of HELLO */
804 /* message too big (!?), get rid of HELLO */ 767 hsize = 0;
805 hsize = 0; 768 tsize = sizeof (struct TransportPingMessage) + ve->addrlen + slen + hsize;
806 tsize = sizeof(struct TransportPingMessage) + ve->addrlen + slen + hsize; 769 }
807 }
808 { 770 {
809 char message_buf[tsize]; 771 char message_buf[tsize];
810 772
811 memcpy(message_buf, hello, hsize); 773 memcpy (message_buf, hello, hsize);
812 memcpy(&message_buf[hsize], &ping, sizeof (struct TransportPingMessage)); 774 memcpy (&message_buf[hsize], &ping, sizeof (struct TransportPingMessage));
813 memcpy(&message_buf[sizeof (struct TransportPingMessage) + hsize], 775 memcpy (&message_buf[sizeof (struct TransportPingMessage) + hsize],
814 ve->transport_name, 776 ve->transport_name, slen);
815 slen); 777 memcpy (&message_buf[sizeof (struct TransportPingMessage) + slen + hsize],
816 memcpy(&message_buf[sizeof (struct TransportPingMessage) + slen + hsize], 778 ve->addr, ve->addrlen);
817 ve->addr,
818 ve->addrlen);
819 papi = GST_plugins_find (ve->transport_name); 779 papi = GST_plugins_find (ve->transport_name);
820 if (papi == NULL) 780 if (papi == NULL)
821 ret = -1; 781 ret = -1;
822 else 782 else
823 ret = papi->send (papi->cls, 783 ret = papi->send (papi->cls,
824 pid, 784 pid,
825 message_buf, 785 message_buf,
826 tsize, 786 tsize,
827 PING_PRIORITY, 787 PING_PRIORITY,
828 HELLO_REVALIDATION_START_TIME, 788 HELLO_REVALIDATION_START_TIME, NULL /* no session */ ,
829 NULL /* no session */, 789 ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL);
830 ve->addr,
831 ve->addrlen,
832 GNUNET_YES,
833 NULL, NULL);
834 } 790 }
835 if (-1 != ret) 791 if (-1 != ret)
836 { 792 {
837 ve->send_time = GNUNET_TIME_absolute_get (); 793 ve->send_time = GNUNET_TIME_absolute_get ();
838 GNUNET_STATISTICS_update (GST_stats, 794 GNUNET_STATISTICS_update (GST_stats,
839 gettext_noop ("# PING without HELLO messages sent"), 795 gettext_noop
840 1, 796 ("# PING without HELLO messages sent"), 1,
841 GNUNET_NO); 797 GNUNET_NO);
842 } 798 }
843} 799}
844 800
845 801
@@ -856,10 +812,9 @@ transmit_ping_if_allowed (void *cls,
856 */ 812 */
857static int 813static int
858validate_address (void *cls, 814validate_address (void *cls,
859 const char *tname, 815 const char *tname,
860 struct GNUNET_TIME_Absolute expiration, 816 struct GNUNET_TIME_Absolute expiration,
861 const void *addr, 817 const void *addr, uint16_t addrlen)
862 uint16_t addrlen)
863{ 818{
864 const struct ValidateAddressContext *vac = cls; 819 const struct ValidateAddressContext *vac = cls;
865 const struct GNUNET_PeerIdentity *pid = &vac->pid; 820 const struct GNUNET_PeerIdentity *pid = &vac->pid;
@@ -867,23 +822,21 @@ validate_address (void *cls,
867 struct GST_BlacklistCheck *bc; 822 struct GST_BlacklistCheck *bc;
868 823
869 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 824 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
870 return GNUNET_OK; /* expired */ 825 return GNUNET_OK; /* expired */
871 ve = find_validation_entry (&vac->public_key, pid, tname, addr, addrlen); 826 ve = find_validation_entry (&vac->public_key, pid, tname, addr, addrlen);
872 if (GNUNET_TIME_absolute_get_remaining (ve->validation_block).rel_value > 0) 827 if (GNUNET_TIME_absolute_get_remaining (ve->validation_block).rel_value > 0)
873 return GNUNET_OK; /* blocked */ 828 return GNUNET_OK; /* blocked */
874 if ( (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) && 829 if ((GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) &&
875 (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0) ) 830 (GNUNET_TIME_absolute_get_remaining (ve->valid_until).rel_value > 0))
876 return GNUNET_OK; /* revalidation task already scheduled & still valid */ 831 return GNUNET_OK; /* revalidation task already scheduled & still valid */
877 ve->validation_block = GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME); 832 ve->validation_block =
833 GNUNET_TIME_relative_to_absolute (HELLO_REVALIDATION_START_TIME);
878 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) 834 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
879 GNUNET_SCHEDULER_cancel (ve->timeout_task); 835 GNUNET_SCHEDULER_cancel (ve->timeout_task);
880 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (HELLO_REVALIDATION_START_TIME, 836 ve->timeout_task =
881 &timeout_hello_validation, 837 GNUNET_SCHEDULER_add_delayed (HELLO_REVALIDATION_START_TIME,
882 ve); 838 &timeout_hello_validation, ve);
883 bc = GST_blacklist_test_allowed (pid, 839 bc = GST_blacklist_test_allowed (pid, tname, &transmit_ping_if_allowed, ve);
884 tname,
885 &transmit_ping_if_allowed,
886 ve);
887 if (NULL != bc) 840 if (NULL != bc)
888 ve->bc = bc; 841 ve->bc = bc;
889 return GNUNET_OK; 842 return GNUNET_OK;
@@ -897,8 +850,7 @@ validate_address (void *cls,
897 * @param tc scheduler context (unused) 850 * @param tc scheduler context (unused)
898 */ 851 */
899static void 852static void
900revalidate_address (void *cls, 853revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
901 const struct GNUNET_SCHEDULER_TaskContext *tc)
902{ 854{
903 struct ValidationEntry *ve = cls; 855 struct ValidationEntry *ve = cls;
904 struct GNUNET_TIME_Relative delay; 856 struct GNUNET_TIME_Relative delay;
@@ -907,24 +859,20 @@ revalidate_address (void *cls,
907 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK; 859 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
908 delay = GNUNET_TIME_absolute_get_remaining (ve->validation_block); 860 delay = GNUNET_TIME_absolute_get_remaining (ve->validation_block);
909 if (delay.rel_value > 0) 861 if (delay.rel_value > 0)
910 { 862 {
911 /* should wait a bit longer */ 863 /* should wait a bit longer */
912 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, 864 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay,
913 &revalidate_address, 865 &revalidate_address, ve);
914 ve); 866 return;
915 return; 867 }
916 }
917 GNUNET_STATISTICS_update (GST_stats, 868 GNUNET_STATISTICS_update (GST_stats,
918 gettext_noop ("# address revalidations started"), 869 gettext_noop ("# address revalidations started"),
919 1, 870 1, GNUNET_NO);
920 GNUNET_NO);
921 vac.pid = ve->pid; 871 vac.pid = ve->pid;
922 vac.public_key = ve->public_key; 872 vac.public_key = ve->public_key;
923 validate_address (&vac, 873 validate_address (&vac,
924 ve->transport_name, 874 ve->transport_name,
925 ve->valid_until, 875 ve->valid_until, ve->addr, (uint16_t) ve->addrlen);
926 ve->addr,
927 (uint16_t) ve->addrlen);
928} 876}
929 877
930 878
@@ -936,18 +884,13 @@ revalidate_address (void *cls,
936 * @param buf where to add the address 884 * @param buf where to add the address
937 */ 885 */
938static size_t 886static size_t
939add_valid_peer_address (void *cls, 887add_valid_peer_address (void *cls, size_t max, void *buf)
940 size_t max,
941 void *buf)
942{ 888{
943 struct ValidationEntry *ve = cls; 889 struct ValidationEntry *ve = cls;
944 890
945 return GNUNET_HELLO_add_address (ve->transport_name, 891 return GNUNET_HELLO_add_address (ve->transport_name,
946 ve->valid_until, 892 ve->valid_until,
947 ve->addr, 893 ve->addr, ve->addrlen, buf, max);
948 ve->addrlen,
949 buf,
950 max);
951} 894}
952 895
953 896
@@ -960,7 +903,7 @@ add_valid_peer_address (void *cls,
960 */ 903 */
961void 904void
962GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, 905GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
963 const struct GNUNET_MessageHeader *hdr) 906 const struct GNUNET_MessageHeader *hdr)
964{ 907{
965 const struct TransportPongMessage *pong; 908 const struct TransportPongMessage *pong;
966 struct ValidationEntry *ve; 909 struct ValidationEntry *ve;
@@ -973,97 +916,78 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
973 struct GNUNET_HELLO_Message *hello; 916 struct GNUNET_HELLO_Message *hello;
974 917
975 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage)) 918 if (ntohs (hdr->size) < sizeof (struct TransportPongMessage))
976 { 919 {
977 GNUNET_break_op (0); 920 GNUNET_break_op (0);
978 return; 921 return;
979 } 922 }
980 GNUNET_STATISTICS_update (GST_stats, 923 GNUNET_STATISTICS_update (GST_stats,
981 gettext_noop ("# PONG messages received"), 924 gettext_noop ("# PONG messages received"),
982 1, 925 1, GNUNET_NO);
983 GNUNET_NO);
984 pong = (const struct TransportPongMessage *) hdr; 926 pong = (const struct TransportPongMessage *) hdr;
985 addr = (const char*) &pong[1]; 927 addr = (const char *) &pong[1];
986 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); 928 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
987 addrend = memchr (addr, '\0', alen); 929 addrend = memchr (addr, '\0', alen);
988 if (NULL == addrend) 930 if (NULL == addrend)
989 { 931 {
990 GNUNET_break_op (0); 932 GNUNET_break_op (0);
991 return; 933 return;
992 } 934 }
993 addrend++; 935 addrend++;
994 slen = strlen(addr); 936 slen = strlen (addr);
995 alen -= slen; 937 alen -= slen;
996 ve = find_validation_entry (NULL, 938 ve = find_validation_entry (NULL, sender, addr, addrend, alen);
997 sender,
998 addr,
999 addrend,
1000 alen);
1001 if (NULL == ve) 939 if (NULL == ve)
1002 { 940 {
1003 GNUNET_STATISTICS_update (GST_stats, 941 GNUNET_STATISTICS_update (GST_stats,
1004 gettext_noop ("# PONGs dropped, no matching pending validation"), 942 gettext_noop
1005 1, 943 ("# PONGs dropped, no matching pending validation"),
1006 GNUNET_NO); 944 1, GNUNET_NO);
1007 return; 945 return;
1008 } 946 }
1009 /* now check that PONG is well-formed */ 947 /* now check that PONG is well-formed */
1010 if (0 != memcmp (&ve->pid, 948 if (0 != memcmp (&ve->pid, sender, sizeof (struct GNUNET_PeerIdentity)))
1011 sender, 949 {
1012 sizeof (struct GNUNET_PeerIdentity))) 950 GNUNET_break_op (0);
1013 { 951 return;
1014 GNUNET_break_op (0); 952 }
1015 return; 953
1016 } 954 if (GNUNET_TIME_absolute_get_remaining
1017 955 (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0)
1018 if (GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_ntoh (pong->expiration)).rel_value == 0) 956 {
1019 { 957 GNUNET_STATISTICS_update (GST_stats,
1020 GNUNET_STATISTICS_update (GST_stats, 958 gettext_noop
1021 gettext_noop ("# PONGs dropped, signature expired"), 959 ("# PONGs dropped, signature expired"), 1,
1022 1, 960 GNUNET_NO);
1023 GNUNET_NO); 961 return;
1024 return; 962 }
1025 }
1026 if (GNUNET_OK != 963 if (GNUNET_OK !=
1027 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, 964 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1028 &pong->purpose, 965 &pong->purpose,
1029 &pong->signature, 966 &pong->signature, &ve->public_key))
1030 &ve->public_key)) 967 {
1031 { 968 GNUNET_break_op (0);
1032 GNUNET_break_op (0); 969 return;
1033 return; 970 }
1034 } 971
1035
1036 /* validity achieved, remember it! */ 972 /* validity achieved, remember it! */
1037 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 973 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
1038 GNUNET_ATS_address_update (GST_ats, 974 GNUNET_ATS_address_update (GST_ats, &ve->pid, ve->valid_until, ve->transport_name, NULL, ve->addr, ve->addrlen, NULL, 0); /* FIXME: compute and add latency here... */
1039 &ve->pid,
1040 ve->valid_until,
1041 ve->transport_name,
1042 NULL,
1043 ve->addr,
1044 ve->addrlen,
1045 NULL, 0); /* FIXME: compute and add latency here... */
1046 975
1047 /* build HELLO to store in PEERINFO */ 976 /* build HELLO to store in PEERINFO */
1048 hello = GNUNET_HELLO_create (&ve->public_key, 977 hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve);
1049 &add_valid_peer_address, 978 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello);
1050 ve);
1051 GNUNET_PEERINFO_add_peer (GST_peerinfo,
1052 hello);
1053 GNUNET_free (hello); 979 GNUNET_free (hello);
1054 980
1055 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task) 981 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
1056 GNUNET_SCHEDULER_cancel (ve->timeout_task); 982 GNUNET_SCHEDULER_cancel (ve->timeout_task);
1057 983
1058 /* randomly delay by up to 1h to avoid synchronous validations */ 984 /* randomly delay by up to 1h to avoid synchronous validations */
1059 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 985 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 60 * 60);
1060 60 * 60);
1061 delay = GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME, 986 delay = GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME,
1062 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 987 GNUNET_TIME_relative_multiply
1063 rdelay)); 988 (GNUNET_TIME_UNIT_SECONDS, rdelay));
1064 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, 989 ve->timeout_task =
1065 &revalidate_address, 990 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
1066 ve);
1067} 991}
1068 992
1069 993
@@ -1076,23 +1000,22 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1076void 1000void
1077GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello) 1001GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1078{ 1002{
1079 const struct GNUNET_HELLO_Message* hm = (const struct GNUNET_HELLO_Message*) hello; 1003 const struct GNUNET_HELLO_Message *hm =
1004 (const struct GNUNET_HELLO_Message *) hello;
1080 struct ValidateAddressContext vac; 1005 struct ValidateAddressContext vac;
1081 1006
1082 if ( (GNUNET_OK != 1007 if ((GNUNET_OK !=
1083 GNUNET_HELLO_get_id (hm, &vac.pid)) || 1008 GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1084 (GNUNET_OK != 1009 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
1085 GNUNET_HELLO_get_key (hm, &vac.public_key)) ) 1010 {
1086 { 1011 /* malformed HELLO */
1087 /* malformed HELLO */ 1012 GNUNET_break (0);
1088 GNUNET_break (0); 1013 return;
1089 return; 1014 }
1090 }
1091 GNUNET_assert (NULL == 1015 GNUNET_assert (NULL ==
1092 GNUNET_HELLO_iterate_addresses (hm, 1016 GNUNET_HELLO_iterate_addresses (hm,
1093 GNUNET_NO, 1017 GNUNET_NO,
1094 &validate_address, 1018 &validate_address, &vac));
1095 &vac));
1096} 1019}
1097 1020
1098 1021
@@ -1123,21 +1046,16 @@ struct IteratorContext
1123 * @return GNUNET_OK (continue to iterate) 1046 * @return GNUNET_OK (continue to iterate)
1124 */ 1047 */
1125static int 1048static int
1126iterate_addresses (void *cls, 1049iterate_addresses (void *cls, const GNUNET_HashCode * key, void *value)
1127 const GNUNET_HashCode *key,
1128 void *value)
1129{ 1050{
1130 struct IteratorContext *ic = cls; 1051 struct IteratorContext *ic = cls;
1131 struct ValidationEntry *ve = value; 1052 struct ValidationEntry *ve = value;
1132 1053
1133 ic->cb (ic->cb_cls, 1054 ic->cb (ic->cb_cls,
1134 &ve->public_key, 1055 &ve->public_key,
1135 &ve->pid, 1056 &ve->pid,
1136 ve->valid_until, 1057 ve->valid_until,
1137 ve->validation_block, 1058 ve->validation_block, ve->transport_name, ve->addr, ve->addrlen);
1138 ve->transport_name,
1139 ve->addr,
1140 ve->addrlen);
1141 return GNUNET_OK; 1059 return GNUNET_OK;
1142} 1060}
1143 1061
@@ -1156,17 +1074,15 @@ iterate_addresses (void *cls,
1156 */ 1074 */
1157void 1075void
1158GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, 1076GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1159 GST_ValidationAddressCallback cb, 1077 GST_ValidationAddressCallback cb, void *cb_cls)
1160 void *cb_cls)
1161{ 1078{
1162 struct IteratorContext ic; 1079 struct IteratorContext ic;
1163 1080
1164 ic.cb = cb; 1081 ic.cb = cb;
1165 ic.cb_cls = cb_cls; 1082 ic.cb_cls = cb_cls;
1166 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map, 1083 GNUNET_CONTAINER_multihashmap_get_multiple (validation_map,
1167 &target->hashPubKey, 1084 &target->hashPubKey,
1168 &iterate_addresses, 1085 &iterate_addresses, &ic);
1169 &ic);
1170} 1086}
1171 1087
1172 1088
diff --git a/src/transport/gnunet-service-transport_validation.h b/src/transport/gnunet-service-transport_validation.h
index 73d346678..bdf8bd9ed 100644
--- a/src/transport/gnunet-service-transport_validation.h
+++ b/src/transport/gnunet-service-transport_validation.h
@@ -34,15 +34,13 @@
34/** 34/**
35 * Start the validation subsystem. 35 * Start the validation subsystem.
36 */ 36 */
37void 37void GST_validation_start (void);
38GST_validation_start (void);
39 38
40 39
41/** 40/**
42 * Stop the validation subsystem. 41 * Stop the validation subsystem.
43 */ 42 */
44void 43void GST_validation_stop (void);
45GST_validation_stop (void);
46 44
47 45
48/** 46/**
@@ -58,11 +56,11 @@ GST_validation_stop (void);
58 */ 56 */
59void 57void
60GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, 58GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
61 const struct GNUNET_MessageHeader *hdr, 59 const struct GNUNET_MessageHeader *hdr,
62 const char *plugin_name, 60 const char *plugin_name,
63 struct Session *session, 61 struct Session *session,
64 const void *sender_address, 62 const void *sender_address,
65 size_t sender_address_len); 63 size_t sender_address_len);
66 64
67 65
68/** 66/**
@@ -74,7 +72,7 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
74 */ 72 */
75void 73void
76GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender, 74GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
77 const struct GNUNET_MessageHeader *hdr); 75 const struct GNUNET_MessageHeader *hdr);
78 76
79 77
80/** 78/**
@@ -83,8 +81,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
83 * 81 *
84 * @param hello the HELLO we received 82 * @param hello the HELLO we received
85 */ 83 */
86void 84void GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
87GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
88 85
89 86
90/** 87/**
@@ -103,14 +100,19 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello);
103 * @param plugin_address binary address 100 * @param plugin_address binary address
104 * @param plugin_address_len length of address 101 * @param plugin_address_len length of address
105 */ 102 */
106typedef void (*GST_ValidationAddressCallback)(void *cls, 103typedef void (*GST_ValidationAddressCallback) (void *cls,
107 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *public_key, 104 const struct
108 const struct GNUNET_PeerIdentity *target, 105 GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
109 struct GNUNET_TIME_Absolute valid_until, 106 * public_key,
110 struct GNUNET_TIME_Absolute validation_block, 107 const struct GNUNET_PeerIdentity
111 const char *plugin_name, 108 * target,
112 const void *plugin_address, 109 struct GNUNET_TIME_Absolute
113 size_t plugin_address_len); 110 valid_until,
111 struct GNUNET_TIME_Absolute
112 validation_block,
113 const char *plugin_name,
114 const void *plugin_address,
115 size_t plugin_address_len);
114 116
115 117
116/** 118/**
@@ -124,8 +126,7 @@ typedef void (*GST_ValidationAddressCallback)(void *cls,
124 */ 126 */
125void 127void
126GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, 128GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
127 GST_ValidationAddressCallback cb, 129 GST_ValidationAddressCallback cb, void *cb_cls);
128 void *cb_cls);
129 130
130 131
131#endif 132#endif
diff --git a/src/transport/gnunet-transport-certificate-creation.c b/src/transport/gnunet-transport-certificate-creation.c
index 258c9e69a..a63c21c60 100644
--- a/src/transport/gnunet-transport-certificate-creation.c
+++ b/src/transport/gnunet-transport-certificate-creation.c
@@ -29,20 +29,19 @@
29#include "gnunet_os_lib.h" 29#include "gnunet_os_lib.h"
30 30
31 31
32static void 32static void
33removecerts (const char *file1, 33removecerts (const char *file1, const char *file2)
34 const char *file2)
35{ 34{
36 if (GNUNET_DISK_file_test (file1) == GNUNET_YES) 35 if (GNUNET_DISK_file_test (file1) == GNUNET_YES)
37 { 36 {
38 CHMOD (file1, S_IWUSR | S_IRUSR); 37 CHMOD (file1, S_IWUSR | S_IRUSR);
39 REMOVE (file1); 38 REMOVE (file1);
40 } 39 }
41 if (GNUNET_DISK_file_test (file2) == GNUNET_YES) 40 if (GNUNET_DISK_file_test (file2) == GNUNET_YES)
42 { 41 {
43 CHMOD (file2, S_IWUSR | S_IRUSR); 42 CHMOD (file2, S_IWUSR | S_IRUSR);
44 REMOVE (file2); 43 REMOVE (file2);
45 } 44 }
46} 45}
47 46
48 47
@@ -54,27 +53,26 @@ main (int argc, char **argv)
54 if (argc != 3) 53 if (argc != 3)
55 return 1; 54 return 1;
56 removecerts (argv[1], argv[2]); 55 removecerts (argv[1], argv[2]);
57 close (2); /* eliminate stderr */ 56 close (2); /* eliminate stderr */
58 /* Create RSA Private Key */ 57 /* Create RSA Private Key */
59 /* openssl genrsa -out $1 1024 2> /dev/null */ 58 /* openssl genrsa -out $1 1024 2> /dev/null */
60 openssl = GNUNET_OS_start_process (NULL, NULL, 59 openssl = GNUNET_OS_start_process (NULL, NULL,
61 "openssl", 60 "openssl",
62 "openssl", 61 "openssl",
63 "genrsa", "-out", argv[1], "1024", 62 "genrsa", "-out", argv[1], "1024", NULL);
64 NULL);
65 if (openssl == NULL) 63 if (openssl == NULL)
66 return 2; 64 return 2;
67 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK); 65 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
68 GNUNET_OS_process_close (openssl); 66 GNUNET_OS_process_close (openssl);
69 67
70 /* Create a self-signed certificate in batch mode using rsa key*/ 68 /* Create a self-signed certificate in batch mode using rsa key */
71 /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */ 69 /* openssl req -batch -days 365 -out $2 -new -x509 -key $1 2> /dev/null */
72 openssl = GNUNET_OS_start_process (NULL, NULL, 70 openssl = GNUNET_OS_start_process (NULL, NULL,
73 "openssl", 71 "openssl",
74 "openssl", 72 "openssl",
75 "req", "-batch", "-days", "365", 73 "req", "-batch", "-days", "365",
76 "-out", argv[2], "-new", "-x509", "-key", argv[1], 74 "-out", argv[2], "-new", "-x509", "-key",
77 NULL); 75 argv[1], NULL);
78 if (openssl == NULL) 76 if (openssl == NULL)
79 return 3; 77 return 3;
80 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK); 78 GNUNET_assert (GNUNET_OS_process_wait (openssl) == GNUNET_OK);
diff --git a/src/transport/gnunet-transport-list-connections.c b/src/transport/gnunet-transport-list-connections.c
index 39950467d..d68d2fedf 100644
--- a/src/transport/gnunet-transport-list-connections.c
+++ b/src/transport/gnunet-transport-list-connections.c
@@ -41,7 +41,7 @@
41static int no_resolve; 41static int no_resolve;
42 42
43#if VERBOSE 43#if VERBOSE
44 static unsigned int connection_count; 44static unsigned int connection_count;
45#endif 45#endif
46 46
47static const struct GNUNET_CONFIGURATION_Handle *cfg; 47static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -53,14 +53,13 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
53 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string 53 * @param address NULL on error, otherwise 0-terminated printable UTF-8 string
54 */ 54 */
55static void 55static void
56process_address (void *cls, 56process_address (void *cls, const char *address)
57 const char *address)
58{ 57{
59#if VERBOSE 58#if VERBOSE
60 connection_count++; 59 connection_count++;
61#endif 60#endif
62 if (address != NULL) 61 if (address != NULL)
63 fprintf(stdout, "%s\n", address); 62 fprintf (stdout, "%s\n", address);
64} 63}
65 64
66 65
@@ -75,18 +74,15 @@ process_address (void *cls,
75static void 74static void
76run (void *cls, 75run (void *cls,
77 char *const *args, 76 char *const *args,
78 const char *cfgfile, 77 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
79 const struct GNUNET_CONFIGURATION_Handle *c)
80{ 78{
81 79
82 cfg = c; 80 cfg = c;
83 if (args[0] != NULL) 81 if (args[0] != NULL)
84 { 82 {
85 fprintf (stderr, 83 fprintf (stderr, _("Invalid command line argument `%s'\n"), args[0]);
86 _("Invalid command line argument `%s'\n"), 84 return;
87 args[0]); 85 }
88 return;
89 }
90 86
91 GNUNET_TRANSPORT_address_iterate (cfg, 87 GNUNET_TRANSPORT_address_iterate (cfg,
92 GNUNET_TIME_UNIT_MINUTES, 88 GNUNET_TIME_UNIT_MINUTES,
@@ -114,7 +110,8 @@ main (int argc, char *const *argv)
114 GNUNET_PROGRAM_run (argc, 110 GNUNET_PROGRAM_run (argc,
115 argv, 111 argv,
116 "gnunet-list-connections", 112 "gnunet-list-connections",
117 gettext_noop ("Print information about connected peers."), 113 gettext_noop
114 ("Print information about connected peers."),
118 options, &run, NULL)) ? 0 : 1; 115 options, &run, NULL)) ? 0 : 1;
119} 116}
120 117
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c
index a00b28854..1cfcf2c4e 100644
--- a/src/transport/gnunet-transport-wlan-helper.c
+++ b/src/transport/gnunet-transport-wlan-helper.c
@@ -108,11 +108,11 @@ struct Hardware_Infos
108}; 108};
109 109
110// FIXME: inline? 110// FIXME: inline?
111int getChannelFromFrequency(int frequency); 111int getChannelFromFrequency (int frequency);
112 112
113// FIXME: make nice... 113// FIXME: make nice...
114static unsigned long 114static unsigned long
115calc_crc_osdep(unsigned char * buf, int len) 115calc_crc_osdep (unsigned char *buf, int len)
116{ 116{
117 unsigned long crc = 0xFFFFFFFF; 117 unsigned long crc = 0xFFFFFFFF;
118 118
@@ -126,44 +126,46 @@ calc_crc_osdep(unsigned char * buf, int len)
126 126
127// FIXME: make nice... 127// FIXME: make nice...
128static int 128static int
129check_crc_buf_osdep(unsigned char *buf, int len) 129check_crc_buf_osdep (unsigned char *buf, int len)
130{ 130{
131 unsigned long crc; 131 unsigned long crc;
132 132
133 if (0 > len) 133 if (0 > len)
134 return 0; 134 return 0;
135 135
136 crc = calc_crc_osdep(buf, len); 136 crc = calc_crc_osdep (buf, len);
137 buf += len; 137 buf += len;
138 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc 138 return (((crc) & 0xFF) == buf[0] && ((crc >> 8) & 0xFF) == buf[1] && ((crc
139 >> 16) & 0xFF) == buf[2] && ((crc >> 24) & 0xFF) == buf[3]); 139 >> 16)
140 & 0xFF)
141 == buf[2] && ((crc >> 24) & 0xFF) == buf[3]);
140} 142}
141 143
142 144
143// FIXME: make nice... 145// FIXME: make nice...
144static int 146static int
145linux_get_channel(struct Hardware_Infos *dev) 147linux_get_channel (struct Hardware_Infos *dev)
146{ 148{
147 struct iwreq wrq; 149 struct iwreq wrq;
148 int fd, frequency; 150 int fd, frequency;
149 int chan = 0; 151 int chan = 0;
150 152
151 memset(&wrq, 0, sizeof(struct iwreq)); 153 memset (&wrq, 0, sizeof (struct iwreq));
152 154
153 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ ); 155 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
154 156
155 fd = dev->fd_raw; 157 fd = dev->fd_raw;
156 if (0 > ioctl(fd, SIOCGIWFREQ, &wrq)) 158 if (0 > ioctl (fd, SIOCGIWFREQ, &wrq))
157 return (-1); 159 return (-1);
158 160
159 frequency = wrq.u.freq.m; 161 frequency = wrq.u.freq.m;
160 if (100000000 < frequency ) 162 if (100000000 < frequency)
161 frequency /= 100000; 163 frequency /= 100000;
162 else if (1000000 < frequency ) 164 else if (1000000 < frequency)
163 frequency /= 1000; 165 frequency /= 1000;
164 166
165 if (1000 < frequency) 167 if (1000 < frequency)
166 chan = getChannelFromFrequency(frequency); 168 chan = getChannelFromFrequency (frequency);
167 else 169 else
168 chan = frequency; 170 chan = frequency;
169 171
@@ -173,10 +175,8 @@ linux_get_channel(struct Hardware_Infos *dev)
173 175
174// FIXME: make nice... 176// FIXME: make nice...
175static ssize_t 177static ssize_t
176linux_read (struct Hardware_Infos *dev, 178linux_read (struct Hardware_Infos *dev, unsigned char *buf, /* FIXME: void*? */
177 unsigned char *buf, /* FIXME: void*? */ 179 size_t buf_size, struct Radiotap_rx *ri)
178 size_t buf_size,
179 struct Radiotap_rx *ri)
180{ 180{
181 unsigned char tmpbuf[buf_size]; 181 unsigned char tmpbuf[buf_size];
182 ssize_t caplen; 182 ssize_t caplen;
@@ -184,178 +184,175 @@ linux_read (struct Hardware_Infos *dev,
184 184
185 n = got_signal = got_noise = got_channel = fcs_removed = 0; 185 n = got_signal = got_noise = got_channel = fcs_removed = 0;
186 186
187 caplen = read(dev->fd_raw, tmpbuf, buf_size); 187 caplen = read (dev->fd_raw, tmpbuf, buf_size);
188 if (0 > caplen) 188 if (0 > caplen)
189 {
190 if (EAGAIN == errno)
191 return 0;
192 fprintf (stderr, "Failed to read from RAW socket: %s\n", strerror (errno));
193 return -1;
194 }
195
196 memset (buf, 0, buf_size);
197 memset (ri, 0, sizeof (*ri));
198
199 switch (dev->arptype_in)
200 {
201 case ARPHRD_IEEE80211_PRISM:
202 {
203 /* skip the prism header */
204 if (tmpbuf[7] == 0x40)
189 { 205 {
190 if (EAGAIN == errno) 206 /* prism54 uses a different format */
191 return 0; 207 ri->ri_power = tmpbuf[0x33];
192 fprintf (stderr, 208 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
193 "Failed to read from RAW socket: %s\n", 209 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
194 strerror (errno)); 210 got_signal = 1;
195 return -1; 211 got_noise = 1;
212 n = 0x40;
213 }
214 else
215 {
216 ri->ri_mactime = *(u_int64_t *) (tmpbuf + 0x5C - 48);
217 ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
218 ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
219 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
220 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
221 got_channel = 1;
222 got_signal = 1;
223 got_noise = 1;
224 n = *(int *) (tmpbuf + 4);
196 } 225 }
197 226
198 memset(buf, 0, buf_size); 227 if (n < 8 || n >= caplen)
199 memset(ri, 0, sizeof(*ri)); 228 return (0);
229 }
230 break;
200 231
201 switch (dev->arptype_in) 232 case ARPHRD_IEEE80211_FULL:
233 {
234 struct ieee80211_radiotap_iterator iterator;
235 struct ieee80211_radiotap_header *rthdr;
236
237 rthdr = (struct ieee80211_radiotap_header *) tmpbuf;
238
239 if (ieee80211_radiotap_iterator_init (&iterator, rthdr, caplen) < 0)
240 return (0);
241
242 /* go through the radiotap arguments we have been given
243 * by the driver
244 */
245
246 while (ieee80211_radiotap_iterator_next (&iterator) >= 0)
202 { 247 {
203 case ARPHRD_IEEE80211_PRISM:
204 {
205 /* skip the prism header */
206 if (tmpbuf[7] == 0x40)
207 {
208 /* prism54 uses a different format */
209 ri->ri_power = tmpbuf[0x33];
210 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x33 + 12);
211 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x33 + 24)) * 500000;
212 got_signal = 1;
213 got_noise = 1;
214 n = 0x40;
215 }
216 else
217 {
218 ri->ri_mactime = *(u_int64_t*) (tmpbuf + 0x5C - 48);
219 ri->ri_channel = *(unsigned int *) (tmpbuf + 0x5C - 36);
220 ri->ri_power = *(unsigned int *) (tmpbuf + 0x5C);
221 ri->ri_noise = *(unsigned int *) (tmpbuf + 0x5C + 12);
222 ri->ri_rate = (*(unsigned int *) (tmpbuf + 0x5C + 24)) * 500000;
223 got_channel = 1;
224 got_signal = 1;
225 got_noise = 1;
226 n = *(int *) (tmpbuf + 4);
227 }
228
229 if (n < 8 || n >= caplen)
230 return (0);
231 }
232 break;
233 248
234 case ARPHRD_IEEE80211_FULL: 249 switch (iterator.this_arg_index)
235 { 250 {
236 struct ieee80211_radiotap_iterator iterator; 251
237 struct ieee80211_radiotap_header *rthdr; 252 case IEEE80211_RADIOTAP_TSFT:
238 253 ri->ri_mactime = le64_to_cpu (*((uint64_t *) iterator.this_arg));
239 rthdr = (struct ieee80211_radiotap_header *) tmpbuf; 254 break;
240 255
241 if (ieee80211_radiotap_iterator_init(&iterator, rthdr, caplen) < 0) 256 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL:
242 return (0); 257 if (!got_signal)
243 258 {
244 /* go through the radiotap arguments we have been given 259 if (*iterator.this_arg < 127)
245 * by the driver 260 ri->ri_power = *iterator.this_arg;
246 */ 261 else
247 262 ri->ri_power = *iterator.this_arg - 255;
248 while (ieee80211_radiotap_iterator_next(&iterator) >= 0) 263
249 { 264 got_signal = 1;
250 265 }
251 switch (iterator.this_arg_index) 266 break;
252 { 267
253 268 case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
254 case IEEE80211_RADIOTAP_TSFT: 269 if (!got_signal)
255 ri->ri_mactime = le64_to_cpu(*((uint64_t*) iterator.this_arg)); 270 {
256 break; 271 if (*iterator.this_arg < 127)
257 272 ri->ri_power = *iterator.this_arg;
258 case IEEE80211_RADIOTAP_DBM_ANTSIGNAL: 273 else
259 if (!got_signal) 274 ri->ri_power = *iterator.this_arg - 255;
260 { 275
261 if (*iterator.this_arg < 127) 276 got_signal = 1;
262 ri->ri_power = *iterator.this_arg; 277 }
263 else 278 break;
264 ri->ri_power = *iterator.this_arg - 255; 279
265 280 case IEEE80211_RADIOTAP_DBM_ANTNOISE:
266 got_signal = 1; 281 if (!got_noise)
267 } 282 {
268 break; 283 if (*iterator.this_arg < 127)
269 284 ri->ri_noise = *iterator.this_arg;
270 case IEEE80211_RADIOTAP_DB_ANTSIGNAL: 285 else
271 if (!got_signal) 286 ri->ri_noise = *iterator.this_arg - 255;
272 { 287
273 if (*iterator.this_arg < 127) 288 got_noise = 1;
274 ri->ri_power = *iterator.this_arg; 289 }
275 else 290 break;
276 ri->ri_power = *iterator.this_arg - 255; 291
277 292 case IEEE80211_RADIOTAP_DB_ANTNOISE:
278 got_signal = 1; 293 if (!got_noise)
279 } 294 {
280 break; 295 if (*iterator.this_arg < 127)
281 296 ri->ri_noise = *iterator.this_arg;
282 case IEEE80211_RADIOTAP_DBM_ANTNOISE: 297 else
283 if (!got_noise) 298 ri->ri_noise = *iterator.this_arg - 255;
284 { 299
285 if (*iterator.this_arg < 127) 300 got_noise = 1;
286 ri->ri_noise = *iterator.this_arg; 301 }
287 else 302 break;
288 ri->ri_noise = *iterator.this_arg - 255; 303
289 304 case IEEE80211_RADIOTAP_ANTENNA:
290 got_noise = 1; 305 ri->ri_antenna = *iterator.this_arg;
291 } 306 break;
292 break; 307
293 308 case IEEE80211_RADIOTAP_CHANNEL:
294 case IEEE80211_RADIOTAP_DB_ANTNOISE: 309 ri->ri_channel = *iterator.this_arg;
295 if (!got_noise) 310 got_channel = 1;
296 { 311 break;
297 if (*iterator.this_arg < 127) 312
298 ri->ri_noise = *iterator.this_arg; 313 case IEEE80211_RADIOTAP_RATE:
299 else 314 ri->ri_rate = (*iterator.this_arg) * 500000;
300 ri->ri_noise = *iterator.this_arg - 255; 315 break;
301 316
302 got_noise = 1; 317 case IEEE80211_RADIOTAP_FLAGS:
303 } 318 /* is the CRC visible at the end?
304 break; 319 * remove
305 320 */
306 case IEEE80211_RADIOTAP_ANTENNA: 321 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
307 ri->ri_antenna = *iterator.this_arg; 322 {
308 break; 323 fcs_removed = 1;
309 324 caplen -= 4;
310 case IEEE80211_RADIOTAP_CHANNEL: 325 }
311 ri->ri_channel = *iterator.this_arg; 326
312 got_channel = 1; 327 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
313 break; 328 return (0);
314 329
315 case IEEE80211_RADIOTAP_RATE: 330 break;
316 ri->ri_rate = (*iterator.this_arg) * 500000;
317 break;
318
319 case IEEE80211_RADIOTAP_FLAGS:
320 /* is the CRC visible at the end?
321 * remove
322 */
323 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS)
324 {
325 fcs_removed = 1;
326 caplen -= 4;
327 }
328
329 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_RX_BADFCS)
330 return (0);
331
332 break;
333 }
334 }
335 n = le16_to_cpu(rthdr->it_len);
336 if (n <= 0 || n >= caplen)
337 return 0;
338 } 331 }
339 break;
340 case ARPHRD_IEEE80211:
341 /* do nothing? */
342 break;
343 default:
344 errno = ENOTSUP;
345 return -1;
346 } 332 }
333 n = le16_to_cpu (rthdr->it_len);
334 if (n <= 0 || n >= caplen)
335 return 0;
336 }
337 break;
338 case ARPHRD_IEEE80211:
339 /* do nothing? */
340 break;
341 default:
342 errno = ENOTSUP;
343 return -1;
344 }
347 345
348 caplen -= n; 346 caplen -= n;
349 347
350 //detect fcs at the end, even if the flag wasn't set and remove it 348 //detect fcs at the end, even if the flag wasn't set and remove it
351 if ( (0 == fcs_removed) && 349 if ((0 == fcs_removed) && (1 == check_crc_buf_osdep (tmpbuf + n, caplen - 4)))
352 (1 == check_crc_buf_osdep(tmpbuf + n, caplen - 4)) ) 350 {
353 { 351 caplen -= 4;
354 caplen -= 4; 352 }
355 } 353 memcpy (buf, tmpbuf + n, caplen);
356 memcpy(buf, tmpbuf + n, caplen); 354 if (!got_channel)
357 if (! got_channel) 355 ri->ri_channel = linux_get_channel (dev);
358 ri->ri_channel = linux_get_channel(dev);
359 356
360 return caplen; 357 return caplen;
361} 358}
@@ -373,122 +370,108 @@ openraw (struct Hardware_Infos *dev)
373 struct sockaddr_ll sll; 370 struct sockaddr_ll sll;
374 371
375 /* find the interface index */ 372 /* find the interface index */
376 memset(&ifr, 0, sizeof(ifr)); 373 memset (&ifr, 0, sizeof (ifr));
377 strncpy(ifr.ifr_name, dev->iface, IFNAMSIZ); 374 strncpy (ifr.ifr_name, dev->iface, IFNAMSIZ);
378 if (-1 == ioctl(dev->fd_raw, SIOCGIFINDEX, &ifr)) 375 if (-1 == ioctl (dev->fd_raw, SIOCGIFINDEX, &ifr))
379 { 376 {
380 fprintf (stderr, 377 fprintf (stderr,
381 "Line: 381 ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n", 378 "Line: 381 ioctl(SIOCGIFINDEX) on interface `%.*s' failed: %s\n",
382 IFNAMSIZ, 379 IFNAMSIZ, dev->iface, strerror (errno));
383 dev->iface, 380 return 1;
384 strerror (errno)); 381 }
385 return 1;
386 }
387 382
388 /* lookup the hardware type */ 383 /* lookup the hardware type */
389 memset (&sll, 0, sizeof(sll)); 384 memset (&sll, 0, sizeof (sll));
390 sll.sll_family = AF_PACKET; 385 sll.sll_family = AF_PACKET;
391 sll.sll_ifindex = ifr.ifr_ifindex; 386 sll.sll_ifindex = ifr.ifr_ifindex;
392 sll.sll_protocol = htons(ETH_P_ALL); 387 sll.sll_protocol = htons (ETH_P_ALL);
393 if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr)) 388 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
394 { 389 {
395 fprintf (stderr, 390 fprintf (stderr,
396 "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", 391 "ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
397 IFNAMSIZ, 392 IFNAMSIZ, dev->iface, strerror (errno));
398 dev->iface, 393 return 1;
399 strerror (errno)); 394 }
400 return 1;
401 }
402 395
403 /* lookup iw mode */ 396 /* lookup iw mode */
404 memset(&wrq, 0, sizeof(struct iwreq)); 397 memset (&wrq, 0, sizeof (struct iwreq));
405 strncpy(wrq.ifr_name, dev->iface, IFNAMSIZ); 398 strncpy (wrq.ifr_name, dev->iface, IFNAMSIZ);
406 if (-1 == ioctl(dev->fd_raw, SIOCGIWMODE, &wrq)) 399 if (-1 == ioctl (dev->fd_raw, SIOCGIWMODE, &wrq))
407 { 400 {
408 /* most probably not supported (ie for rtap ipw interface) * 401 /* most probably not supported (ie for rtap ipw interface) *
409 * so just assume its correctly set... */ 402 * so just assume its correctly set... */
410 wrq.u.mode = IW_MODE_MONITOR; 403 wrq.u.mode = IW_MODE_MONITOR;
411 } 404 }
412 405
413 if ( ( (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && 406 if (((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
414 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 407 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
415 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) ) || 408 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL)) ||
416 (wrq.u.mode != IW_MODE_MONITOR) ) 409 (wrq.u.mode != IW_MODE_MONITOR))
417 { 410 {
418 fprintf (stderr, 411 fprintf (stderr,
419 "Error: interface `%.*s' is not in monitor mode\n", 412 "Error: interface `%.*s' is not in monitor mode\n",
420 IFNAMSIZ, 413 IFNAMSIZ, dev->iface);
421 dev->iface); 414 return 1;
422 return 1; 415 }
423 }
424 416
425 /* Is interface st to up, broadcast & running ? */ 417 /* Is interface st to up, broadcast & running ? */
426 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags) 418 if ((ifr.ifr_flags | IFF_UP | IFF_BROADCAST | IFF_RUNNING) != ifr.ifr_flags)
427 { 419 {
428 /* Bring interface up*/ 420 /* Bring interface up */
429 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING; 421 ifr.ifr_flags |= IFF_UP | IFF_BROADCAST | IFF_RUNNING;
430 422
431 if (-1 == ioctl(dev->fd_raw, SIOCSIFFLAGS, &ifr)) 423 if (-1 == ioctl (dev->fd_raw, SIOCSIFFLAGS, &ifr))
432 {
433 fprintf (stderr,
434 "Line: 434 ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
435 IFNAMSIZ,
436 dev->iface,
437 strerror (errno));
438 return 1;
439 }
440 }
441
442 /* bind the raw socket to the interface */
443 if (-1 == bind(dev->fd_raw, (struct sockaddr *) &sll, sizeof(sll)))
444 { 424 {
445 fprintf (stderr, 425 fprintf (stderr,
446 "Failed to bind interface `%.*s': %s\n", 426 "Line: 434 ioctl(SIOCSIFFLAGS) on interface `%.*s' failed: %s\n",
447 IFNAMSIZ, 427 IFNAMSIZ, dev->iface, strerror (errno));
448 dev->iface,
449 strerror (errno));
450 return 1; 428 return 1;
451 } 429 }
430 }
431
432 /* bind the raw socket to the interface */
433 if (-1 == bind (dev->fd_raw, (struct sockaddr *) &sll, sizeof (sll)))
434 {
435 fprintf (stderr,
436 "Failed to bind interface `%.*s': %s\n",
437 IFNAMSIZ, dev->iface, strerror (errno));
438 return 1;
439 }
452 440
453 /* lookup the hardware type */ 441 /* lookup the hardware type */
454 if (-1 == ioctl(dev->fd_raw, SIOCGIFHWADDR, &ifr)) 442 if (-1 == ioctl (dev->fd_raw, SIOCGIFHWADDR, &ifr))
455 { 443 {
456 fprintf (stderr, 444 fprintf (stderr,
457 "Line: 457 ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n", 445 "Line: 457 ioctl(SIOCGIFHWADDR) on interface `%.*s' failed: %s\n",
458 IFNAMSIZ, 446 IFNAMSIZ, dev->iface, strerror (errno));
459 dev->iface, 447 return 1;
460 strerror (errno)); 448 }
461 return 1;
462 }
463 449
464 memcpy (dev->pl_mac, 450 memcpy (dev->pl_mac, ifr.ifr_hwaddr.sa_data, MAC_ADDR_SIZE);
465 ifr.ifr_hwaddr.sa_data,
466 MAC_ADDR_SIZE);
467 dev->arptype_in = ifr.ifr_hwaddr.sa_family; 451 dev->arptype_in = ifr.ifr_hwaddr.sa_family;
468 if ( (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) && 452 if ((ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211) &&
469 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) && 453 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_PRISM) &&
470 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL) ) 454 (ifr.ifr_hwaddr.sa_family != ARPHRD_IEEE80211_FULL))
471 { 455 {
472 fprintf (stderr, 456 fprintf (stderr,
473 "Unsupported hardware link type %d on interface `%.*s'\n", 457 "Unsupported hardware link type %d on interface `%.*s'\n",
474 ifr.ifr_hwaddr.sa_family, 458 ifr.ifr_hwaddr.sa_family, IFNAMSIZ, dev->iface);
475 IFNAMSIZ, 459 return 1;
476 dev->iface); 460 }
477 return 1;
478 }
479 461
480 /* enable promiscuous mode */ 462 /* enable promiscuous mode */
481 memset(&mr, 0, sizeof(mr)); 463 memset (&mr, 0, sizeof (mr));
482 mr.mr_ifindex = sll.sll_ifindex; 464 mr.mr_ifindex = sll.sll_ifindex;
483 mr.mr_type = PACKET_MR_PROMISC; 465 mr.mr_type = PACKET_MR_PROMISC;
484 if (0 != setsockopt(dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr, sizeof(mr))) 466 if (0 !=
485 { 467 setsockopt (dev->fd_raw, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mr,
486 fprintf (stderr, 468 sizeof (mr)))
487 "Failed to enable promiscuous mode on interface `%.*s'\n", 469 {
488 IFNAMSIZ, 470 fprintf (stderr,
489 dev->iface); 471 "Failed to enable promiscuous mode on interface `%.*s'\n",
490 return 1; 472 IFNAMSIZ, dev->iface);
491 } 473 return 1;
474 }
492 475
493 return 0; 476 return 0;
494} 477}
@@ -497,52 +480,43 @@ openraw (struct Hardware_Infos *dev)
497 * @return 0 on success 480 * @return 0 on success
498 */ 481 */
499static int 482static int
500wlaninit (struct Hardware_Infos *dev, 483wlaninit (struct Hardware_Infos *dev, const char *iface)
501 const char *iface)
502{ 484{
503 char strbuf[512]; 485 char strbuf[512];
504 struct stat sbuf; 486 struct stat sbuf;
505 int ret; 487 int ret;
506 488
507 dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); 489 dev->fd_raw = socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL));
508 if (0 > dev->fd_raw) 490 if (0 > dev->fd_raw)
509 { 491 {
510 fprintf (stderr, 492 fprintf (stderr, "Failed to create raw socket: %s\n", strerror (errno));
511 "Failed to create raw socket: %s\n", 493 return 1;
512 strerror (errno)); 494 }
513 return 1;
514 }
515 if (dev->fd_raw >= FD_SETSIZE) 495 if (dev->fd_raw >= FD_SETSIZE)
516 { 496 {
517 fprintf (stderr, 497 fprintf (stderr,
518 "File descriptor too large for select (%d > %d)\n", 498 "File descriptor too large for select (%d > %d)\n",
519 dev->fd_raw, 499 dev->fd_raw, FD_SETSIZE);
520 FD_SETSIZE); 500 close (dev->fd_raw);
521 close (dev->fd_raw); 501 return 1;
522 return 1; 502 }
523 }
524 503
525 /* mac80211 stack detection */ 504 /* mac80211 stack detection */
526 ret = snprintf(strbuf, 505 ret = snprintf (strbuf,
527 sizeof(strbuf), 506 sizeof (strbuf),
528 "/sys/class/net/%s/phy80211/subsystem", 507 "/sys/class/net/%s/phy80211/subsystem", iface);
529 iface); 508 if ((ret < 0) || (ret >= sizeof (strbuf)) || (0 != stat (strbuf, &sbuf)))
530 if ( (ret < 0) || 509 {
531 (ret >= sizeof (strbuf)) || 510 fprintf (stderr, "Did not find 802.11 interface `%s'. Exiting.\n", iface);
532 (0 != stat(strbuf, &sbuf)) ) 511 close (dev->fd_raw);
533 { 512 return 1;
534 fprintf(stderr, 513 }
535 "Did not find 802.11 interface `%s'. Exiting.\n", 514 strncpy (dev->iface, iface, IFNAMSIZ);
536 iface); 515 if (0 != openraw (dev))
537 close (dev->fd_raw); 516 {
538 return 1; 517 close (dev->fd_raw);
539 } 518 return 1;
540 strncpy(dev->iface, iface, IFNAMSIZ); 519 }
541 if (0 != openraw(dev))
542 {
543 close(dev->fd_raw);
544 return 1;
545 }
546 return 0; 520 return 0;
547} 521}
548 522
@@ -555,14 +529,14 @@ wlaninit (struct Hardware_Infos *dev,
555 * @return 0 if mac belongs to us, 1 if mac is for another target 529 * @return 0 if mac belongs to us, 1 if mac is for another target
556 */ 530 */
557static int 531static int
558mac_test (const struct ieee80211_frame *u8aIeeeHeader, 532mac_test (const struct ieee80211_frame *u8aIeeeHeader,
559 const struct Hardware_Infos *dev) 533 const struct Hardware_Infos *dev)
560{ 534{
561 if (0 != memcmp(u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE)) 535 if (0 != memcmp (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE))
562 return 1; 536 return 1;
563 if (0 == memcmp(u8aIeeeHeader->i_addr1, dev->pl_mac, MAC_ADDR_SIZE)) 537 if (0 == memcmp (u8aIeeeHeader->i_addr1, dev->pl_mac, MAC_ADDR_SIZE))
564 return 0; 538 return 0;
565 if (0 == memcmp(u8aIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE)) 539 if (0 == memcmp (u8aIeeeHeader->i_addr1, &bc_all_mac, MAC_ADDR_SIZE))
566 return 0; 540 return 0;
567 return 1; 541 return 1;
568} 542}
@@ -574,17 +548,13 @@ mac_test (const struct ieee80211_frame *u8aIeeeHeader,
574 * @param dev pointer to the Hardware_Infos struct 548 * @param dev pointer to the Hardware_Infos struct
575 */ 549 */
576static void 550static void
577mac_set (struct ieee80211_frame *u8aIeeeHeader, 551mac_set (struct ieee80211_frame *u8aIeeeHeader,
578 const struct Hardware_Infos * dev) 552 const struct Hardware_Infos *dev)
579{ 553{
580 u8aIeeeHeader->i_fc[0] = 0x08; 554 u8aIeeeHeader->i_fc[0] = 0x08;
581 u8aIeeeHeader->i_fc[1] = 0x00; 555 u8aIeeeHeader->i_fc[1] = 0x00;
582 memcpy(u8aIeeeHeader->i_addr2, 556 memcpy (u8aIeeeHeader->i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
583 dev->pl_mac, 557 memcpy (u8aIeeeHeader->i_addr3, &mac_bssid, MAC_ADDR_SIZE);
584 MAC_ADDR_SIZE);
585 memcpy(u8aIeeeHeader->i_addr3,
586 &mac_bssid,
587 MAC_ADDR_SIZE);
588 558
589} 559}
590 560
@@ -597,138 +567,140 @@ struct RadioTapheader
597}; 567};
598 568
599static void 569static void
600stdin_send_hw (void *cls, 570stdin_send_hw (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
601 void *client,
602 const struct GNUNET_MessageHeader *hdr)
603{ 571{
604 struct Hardware_Infos * dev = cls; 572 struct Hardware_Infos *dev = cls;
605 struct sendbuf *write_pout = &dev->write_pout; 573 struct sendbuf *write_pout = &dev->write_pout;
606 struct Radiotap_Send * header = (struct Radiotap_Send *) &hdr[1]; 574 struct Radiotap_Send *header = (struct Radiotap_Send *) &hdr[1];
607 struct ieee80211_frame * wlanheader; 575 struct ieee80211_frame *wlanheader;
608 size_t sendsize; 576 size_t sendsize;
609 577
610 // struct? // FIXME: make nice... 578 // struct? // FIXME: make nice...
611 struct RadioTapheader rtheader; 579 struct RadioTapheader rtheader;
580
612 rtheader.header.it_version = 0; 581 rtheader.header.it_version = 0;
613 rtheader.header.it_len = htole16(0x0c); 582 rtheader.header.it_len = htole16 (0x0c);
614 rtheader.header.it_present = htole32(0x00008004); 583 rtheader.header.it_present = htole32 (0x00008004);
615 rtheader.rate = 0x00; 584 rtheader.rate = 0x00;
616 rtheader.txflags = htole16(IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ); 585 rtheader.txflags =
586 htole16 (IEEE80211_RADIOTAP_F_TX_NOACK | IEEE80211_RADIOTAP_F_TX_NOSEQ);
617 587
618 /* { 0x00, 0x00, <-- radiotap version 588 /* { 0x00, 0x00, <-- radiotap version
619 0x0c, 0x00, <- radiotap header length 589 * 0x0c, 0x00, <- radiotap header length
620 0x04, 0x80, 0x00, 0x00, <-- bitmap 590 * 0x04, 0x80, 0x00, 0x00, <-- bitmap
621 0x00, <-- rate 591 * 0x00, <-- rate
622 0x00, <-- padding for natural alignment 592 * 0x00, <-- padding for natural alignment
623 0x18, 0x00, <-- TX flags 593 * 0x18, 0x00, <-- TX flags
624 };*/ 594 * }; */
625 595
626 sendsize = ntohs(hdr->size); 596 sendsize = ntohs (hdr->size);
627 if (sendsize < sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader)) 597 if (sendsize <
628 { 598 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader))
629 fprintf(stderr, 599 {
630 "Function stdin_send_hw: mailformed packet (too small)\n"); 600 fprintf (stderr, "Function stdin_send_hw: mailformed packet (too small)\n");
631 exit (1); 601 exit (1);
632 } 602 }
633 sendsize -= sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader); 603 sendsize -=
604 sizeof (struct Radiotap_Send) + sizeof (struct GNUNET_MessageHeader);
634 605
635 if (MAXLINE < sendsize) 606 if (MAXLINE < sendsize)
636 { 607 {
637 fprintf(stderr, 608 fprintf (stderr, "Function stdin_send_hw: Packet too big for buffer\n");
638 "Function stdin_send_hw: Packet too big for buffer\n"); 609 exit (1);
639 exit(1); 610 }
640 } 611 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
641 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) 612 {
642 { 613 fprintf (stderr, "Function stdin_send: wrong packet type\n");
643 fprintf(stderr, "Function stdin_send: wrong packet type\n"); 614 exit (1);
644 exit(1); 615 }
645 } 616
646 617 rtheader.header.it_len = htole16 (sizeof (rtheader));
647 rtheader.header.it_len = htole16(sizeof(rtheader));
648 rtheader.rate = header->rate; 618 rtheader.rate = header->rate;
649 memcpy(write_pout->buf, &rtheader, sizeof(rtheader)); 619 memcpy (write_pout->buf, &rtheader, sizeof (rtheader));
650 memcpy(write_pout->buf + sizeof(rtheader), &header[1], sendsize); 620 memcpy (write_pout->buf + sizeof (rtheader), &header[1], sendsize);
651 /* payload contains MAC address, but we don't trust it, so we'll 621 /* payload contains MAC address, but we don't trust it, so we'll
652 overwrite it with OUR MAC address again to prevent mischief */ 622 * overwrite it with OUR MAC address again to prevent mischief */
653 wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof(rtheader)); 623 wlanheader = (struct ieee80211_frame *) (write_pout->buf + sizeof (rtheader));
654 mac_set(wlanheader, dev); 624 mac_set (wlanheader, dev);
655 write_pout->size = sendsize + sizeof(rtheader); 625 write_pout->size = sendsize + sizeof (rtheader);
656} 626}
657 627
658#if 0 628#if 0
659static int 629static int
660maketest(unsigned char * buf, struct Hardware_Infos * dev) 630maketest (unsigned char *buf, struct Hardware_Infos *dev)
661{ 631{
662 uint16_t * tmp16; 632 uint16_t *tmp16;
663 static uint16_t seqenz = 0; 633 static uint16_t seqenz = 0;
664 static int first = 0; 634 static int first = 0;
665 635
666 const int rate = 11000000; 636 const int rate = 11000000;
667 static const char 637 static const char
668 txt[] = 638 txt[] =
669 "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211"; 639 "Hallo1Hallo2 Hallo3 Hallo4...998877665544332211Hallo1Hallo2 Hallo3 Hallo4...998877665544332211";
670 640
671 unsigned char u8aRadiotap[] = 641 unsigned char u8aRadiotap[] = { 0x00, 0x00, // <-- radiotap version
672 { 0x00, 0x00, // <-- radiotap version 642 0x00, 0x00, // <- radiotap header length
673 0x00, 0x00, // <- radiotap header length 643 0x04, 0x80, 0x02, 0x00, // <-- bitmap
674 0x04, 0x80, 0x02, 0x00, // <-- bitmap 644 0x00, // <-- rate
675 0x00, // <-- rate 645 0x00, // <-- padding for natural alignment
676 0x00, // <-- padding for natural alignment 646 0x10, 0x00, // <-- TX flags
677 0x10, 0x00, // <-- TX flags 647 0x04 //retries
678 0x04 //retries 648 };
679 };
680 649
681 /*uint8_t u8aRadiotap[] = 650 /*uint8_t u8aRadiotap[] =
682 { 651 * {
683 0x00, 0x00, // <-- radiotap version 652 * 0x00, 0x00, // <-- radiotap version
684 0x19, 0x00, // <- radiotap header length 653 * 0x19, 0x00, // <- radiotap header length
685 0x6f, 0x08, 0x00, 0x00, // <-- bitmap 654 * 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
686 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp 655 * 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
687 0x00, // <-- flags (Offset +0x10) 656 * 0x00, // <-- flags (Offset +0x10)
688 0x6c, // <-- rate (0ffset +0x11) 657 * 0x6c, // <-- rate (0ffset +0x11)
689 0x71, 0x09, 0xc0, 0x00, // <-- channel 658 * 0x71, 0x09, 0xc0, 0x00, // <-- channel
690 0xde, // <-- antsignal 659 * 0xde, // <-- antsignal
691 0x00, // <-- antnoise 660 * 0x00, // <-- antnoise
692 0x01, // <-- antenna 661 * 0x01, // <-- antenna
693 };*/ 662 * }; */
694 663
695 u8aRadiotap[8] = (rate / 500000); 664 u8aRadiotap[8] = (rate / 500000);
696 u8aRadiotap[2] = htole16(sizeof(u8aRadiotap)); 665 u8aRadiotap[2] = htole16 (sizeof (u8aRadiotap));
697 666
698 static struct ieee80211_frame u8aIeeeHeader; 667 static struct ieee80211_frame u8aIeeeHeader;
699 668
700 uint8_t u8aIeeeHeader_def[] = 669 uint8_t u8aIeeeHeader_def[] = { 0x08, 0x00, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
701 { 0x08, 0x00, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0; 670 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
702 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data 671 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
703 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS; 672 0x00, 0x00, // Duration/ID
704 0x00, 0x00, // Duration/ID 673
705 674 //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver
706 //0x00, 0x1f, 0x3f, 0xd1, 0x8e, 0xe6, // mac1 - in this case receiver 675 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver
707 0x00, 0x1d, 0xe0, 0xb0, 0x17, 0xdf, // mac1 - in this case receiver 676 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender
708 0xC0, 0x3F, 0x0E, 0x44, 0x2D, 0x51, // mac2 - in this case sender 677 //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4,
709 //0x02, 0x1d, 0xe0, 0x00, 0x01, 0xc4, 678 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
710 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid 679 0x10, 0x86, //Sequence Control
711 0x10, 0x86, //Sequence Control 680 };
712 };
713 if (0 == first) 681 if (0 == first)
714 { 682 {
715 memcpy(&u8aIeeeHeader, u8aIeeeHeader_def, sizeof(struct ieee80211_frame)); 683 memcpy (&u8aIeeeHeader, u8aIeeeHeader_def, sizeof (struct ieee80211_frame));
716 memcpy(u8aIeeeHeader.i_addr2, dev->pl_mac, MAC_ADDR_SIZE); 684 memcpy (u8aIeeeHeader.i_addr2, dev->pl_mac, MAC_ADDR_SIZE);
717 first = 1; 685 first = 1;
718 } 686 }
719 687
720 tmp16 = (uint16_t*) u8aIeeeHeader.i_dur; 688 tmp16 = (uint16_t *) u8aIeeeHeader.i_dur;
721 *tmp16 689 *tmp16
722 = (uint16_t) htole16((sizeof(txt) + sizeof(struct ieee80211_frame) * 1000000) / rate + 290); 690 =
723 tmp16 = (uint16_t*) u8aIeeeHeader.i_seq; 691 (uint16_t)
724 *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16(seqenz) 692 htole16 ((sizeof (txt) +
725 << IEEE80211_SEQ_SEQ_SHIFT); 693 sizeof (struct ieee80211_frame) * 1000000) / rate + 290);
694 tmp16 = (uint16_t *) u8aIeeeHeader.i_seq;
695 *tmp16 = (*tmp16 & IEEE80211_SEQ_FRAG_MASK) | (htole16 (seqenz)
696 << IEEE80211_SEQ_SEQ_SHIFT);
726 seqenz++; 697 seqenz++;
727 698
728 memcpy(buf, u8aRadiotap, sizeof(u8aRadiotap)); 699 memcpy (buf, u8aRadiotap, sizeof (u8aRadiotap));
729 memcpy(buf + sizeof(u8aRadiotap), &u8aIeeeHeader, sizeof(u8aIeeeHeader)); 700 memcpy (buf + sizeof (u8aRadiotap), &u8aIeeeHeader, sizeof (u8aIeeeHeader));
730 memcpy(buf + sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader), txt, sizeof(txt)); 701 memcpy (buf + sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader), txt,
731 return sizeof(u8aRadiotap) + sizeof(u8aIeeeHeader) + sizeof(txt); 702 sizeof (txt));
703 return sizeof (u8aRadiotap) + sizeof (u8aIeeeHeader) + sizeof (txt);
732 704
733} 705}
734#endif 706#endif
@@ -742,21 +714,20 @@ maketest(unsigned char * buf, struct Hardware_Infos * dev)
742 */ 714 */
743// FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file) 715// FIXME: use 'struct MacAddress' for 'mac' (everywhere in this file)
744static int 716static int
745send_mac_to_plugin(char * buffer, uint8_t * mac) 717send_mac_to_plugin (char *buffer, uint8_t * mac)
746{ 718{
747 struct Wlan_Helper_Control_Message macmsg; 719 struct Wlan_Helper_Control_Message macmsg;
748 720
749 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); 721 macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
750 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 722 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
751 memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress)); 723 memcpy (macmsg.mac.mac, mac, sizeof (struct MacAddress));
752 memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message)); 724 memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
753 return sizeof(struct Wlan_Helper_Control_Message); 725 return sizeof (struct Wlan_Helper_Control_Message);
754} 726}
755 727
756 728
757static int 729static int
758hardwaremode (int argc, 730hardwaremode (int argc, char *argv[])
759 char *argv[])
760{ 731{
761 uid_t uid; 732 uid_t uid;
762 struct Hardware_Infos dev; 733 struct Hardware_Infos dev;
@@ -768,18 +739,16 @@ hardwaremode (int argc,
768 fd_set wfds; 739 fd_set wfds;
769 int retval; 740 int retval;
770 int stdin_open; 741 int stdin_open;
771 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; 742 struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
772 743
773 if (0 != wlaninit(&dev, argv[1])) 744 if (0 != wlaninit (&dev, argv[1]))
774 return 1; 745 return 1;
775 uid = getuid(); 746 uid = getuid ();
776 if (0 != setresuid(uid, uid, uid)) 747 if (0 != setresuid (uid, uid, uid))
777 { 748 {
778 fprintf(stderr, 749 fprintf (stderr, "Failed to setresuid: %s\n", strerror (errno));
779 "Failed to setresuid: %s\n", 750 /* not critical, continue anyway */
780 strerror(errno)); 751 }
781 /* not critical, continue anyway */
782 }
783 752
784 dev.write_pout.size = 0; 753 dev.write_pout.size = 0;
785 dev.write_pout.pos = 0; 754 dev.write_pout.pos = 0;
@@ -787,162 +756,148 @@ hardwaremode (int argc,
787 756
788 /* send mac to STDOUT first */ 757 /* send mac to STDOUT first */
789 write_std.pos = 0; 758 write_std.pos = 0;
790 write_std.size = send_mac_to_plugin((char *) &write_std.buf, dev.pl_mac); 759 write_std.size = send_mac_to_plugin ((char *) &write_std.buf, dev.pl_mac);
791 stdin_open = 1; 760 stdin_open = 1;
792 761
793 while (1) 762 while (1)
763 {
764 maxfd = -1;
765 FD_ZERO (&rfds);
766 if ((0 == dev.write_pout.size) && (1 == stdin_open))
794 { 767 {
795 maxfd = -1; 768 FD_SET (STDIN_FILENO, &rfds);
796 FD_ZERO (&rfds); 769 maxfd = MAX (maxfd, STDIN_FILENO);
797 if ( (0 == dev.write_pout.size) && 770 }
798 (1 == stdin_open) ) 771 if (0 == write_std.size)
799 { 772 {
800 FD_SET (STDIN_FILENO, &rfds); 773 FD_SET (dev.fd_raw, &rfds);
801 maxfd = MAX (maxfd, STDIN_FILENO); 774 maxfd = MAX (maxfd, dev.fd_raw);
802 } 775 }
803 if (0 == write_std.size) 776 FD_ZERO (&wfds);
804 { 777 if (0 < write_std.size)
805 FD_SET (dev.fd_raw, &rfds); 778 {
806 maxfd = MAX(maxfd, dev.fd_raw); 779 FD_SET (STDOUT_FILENO, &wfds);
807 } 780 maxfd = MAX (maxfd, STDOUT_FILENO);
808 FD_ZERO(&wfds); 781 }
809 if (0 < write_std.size) 782 if (0 < dev.write_pout.size)
810 { 783 {
811 FD_SET (STDOUT_FILENO, &wfds); 784 FD_SET (dev.fd_raw, &wfds);
812 maxfd = MAX(maxfd, STDOUT_FILENO); 785 maxfd = MAX (maxfd, dev.fd_raw);
813 } 786 }
814 if (0 < dev.write_pout.size) 787 retval = select (maxfd + 1, &rfds, &wfds, NULL, NULL);
815 { 788 if ((-1 == retval) && (EINTR == errno))
816 FD_SET(dev.fd_raw, &wfds); 789 continue;
817 maxfd = MAX(maxfd, dev.fd_raw); 790 if (0 > retval)
818 } 791 {
819 retval = select(maxfd + 1, &rfds, &wfds, NULL, NULL); 792 fprintf (stderr, "select failed: %s\n", strerror (errno));
820 if ( (-1 == retval) && 793 break;
821 (EINTR == errno) ) 794 }
822 continue;
823 if (0 > retval)
824 {
825 fprintf(stderr,
826 "select failed: %s\n",
827 strerror(errno));
828 break;
829 }
830 795
831 if (FD_ISSET(STDOUT_FILENO, &wfds)) 796 if (FD_ISSET (STDOUT_FILENO, &wfds))
832 { 797 {
833 ret = write(STDOUT_FILENO, 798 ret = write (STDOUT_FILENO,
834 write_std.buf + write_std.pos, 799 write_std.buf + write_std.pos,
835 write_std.size - write_std.pos); 800 write_std.size - write_std.pos);
836 if (0 > ret) 801 if (0 > ret)
837 { 802 {
838 fprintf (stderr, 803 fprintf (stderr, "Failed to write to STDOUT: %s\n", strerror (errno));
839 "Failed to write to STDOUT: %s\n", 804 break;
840 strerror (errno)); 805 }
841 break; 806 write_std.pos += ret;
842 } 807 if (write_std.pos == write_std.size)
843 write_std.pos += ret; 808 {
844 if (write_std.pos == write_std.size) 809 write_std.pos = 0;
845 { 810 write_std.size = 0;
846 write_std.pos = 0; 811 }
847 write_std.size = 0; 812 }
848 }
849 }
850
851 if (FD_ISSET(dev.fd_raw, &wfds))
852 {
853 ret = write (dev.fd_raw,
854 dev.write_pout.buf,
855 dev.write_pout.size);
856 if (0 > ret)
857 {
858 fprintf (stderr,
859 "Line %u: Failed to write to WLAN device: %s, Message-Size: %u\n",__LINE__,
860 strerror (errno), dev.write_pout.size);
861 break;
862 }
863 dev.write_pout.pos += ret;
864 if ( (dev.write_pout.pos != dev.write_pout.size) &&
865 (ret != 0) )
866 {
867 fprintf(stderr,
868 "Line %u: Write error, partial send: %u/%u\n",__LINE__,
869 dev.write_pout.pos, dev.write_pout.size);
870 break;
871 }
872 if (dev.write_pout.pos == dev.write_pout.size)
873 {
874 dev.write_pout.pos = 0;
875 dev.write_pout.size = 0;
876 }
877 }
878 813
879 if (FD_ISSET(STDIN_FILENO, &rfds)) 814 if (FD_ISSET (dev.fd_raw, &wfds))
880 { 815 {
881 ret = read(STDIN_FILENO, readbuf, sizeof(readbuf)); 816 ret = write (dev.fd_raw, dev.write_pout.buf, dev.write_pout.size);
882 if (0 > ret) 817 if (0 > ret)
883 { 818 {
884 fprintf(stderr, 819 fprintf (stderr,
885 "Read error from STDIN: %s\n", 820 "Line %u: Failed to write to WLAN device: %s, Message-Size: %u\n",
886 strerror (errno)); 821 __LINE__, strerror (errno), dev.write_pout.size);
887 break; 822 break;
888 } 823 }
889 if (0 == ret) 824 dev.write_pout.pos += ret;
890 { 825 if ((dev.write_pout.pos != dev.write_pout.size) && (ret != 0))
891 /* stop reading... */ 826 {
892 stdin_open = 0; 827 fprintf (stderr,
893 } 828 "Line %u: Write error, partial send: %u/%u\n", __LINE__,
894 GNUNET_SERVER_mst_receive (stdin_mst, NULL, 829 dev.write_pout.pos, dev.write_pout.size);
895 readbuf, ret, 830 break;
896 GNUNET_NO, GNUNET_NO); 831 }
897 } 832 if (dev.write_pout.pos == dev.write_pout.size)
833 {
834 dev.write_pout.pos = 0;
835 dev.write_pout.size = 0;
836 }
837 }
898 838
899 if (FD_ISSET(dev.fd_raw, &rfds)) 839 if (FD_ISSET (STDIN_FILENO, &rfds))
900 { 840 {
901 struct GNUNET_MessageHeader * header; 841 ret = read (STDIN_FILENO, readbuf, sizeof (readbuf));
902 struct Radiotap_rx * rxinfo; 842 if (0 > ret)
903 struct ieee80211_frame * datastart; 843 {
904 844 fprintf (stderr, "Read error from STDIN: %s\n", strerror (errno));
905 header = (struct GNUNET_MessageHeader *) write_std.buf; 845 break;
906 rxinfo = (struct Radiotap_rx *) &header[1]; 846 }
907 datastart = (struct ieee80211_frame *) &rxinfo[1]; 847 if (0 == ret)
908 ret = linux_read (&dev, 848 {
909 (unsigned char *) datastart, 849 /* stop reading... */
910 sizeof(write_std.buf) - sizeof(struct Radiotap_rx) - sizeof(struct GNUNET_MessageHeader), 850 stdin_open = 0;
911 rxinfo); 851 }
912 if (0 > ret) 852 GNUNET_SERVER_mst_receive (stdin_mst, NULL,
913 { 853 readbuf, ret, GNUNET_NO, GNUNET_NO);
914 fprintf(stderr, 854 }
915 "Read error from raw socket: %s\n",
916 strerror(errno));
917 break;
918 }
919 if ( (0 < ret) &&
920 (0 == mac_test(datastart, &dev)) )
921 {
922 write_std.size = ret + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx);
923 header->size = htons(write_std.size);
924 header->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
925 }
926 }
927 855
856 if (FD_ISSET (dev.fd_raw, &rfds))
857 {
858 struct GNUNET_MessageHeader *header;
859 struct Radiotap_rx *rxinfo;
860 struct ieee80211_frame *datastart;
861
862 header = (struct GNUNET_MessageHeader *) write_std.buf;
863 rxinfo = (struct Radiotap_rx *) &header[1];
864 datastart = (struct ieee80211_frame *) &rxinfo[1];
865 ret = linux_read (&dev,
866 (unsigned char *) datastart,
867 sizeof (write_std.buf) - sizeof (struct Radiotap_rx) -
868 sizeof (struct GNUNET_MessageHeader), rxinfo);
869 if (0 > ret)
870 {
871 fprintf (stderr, "Read error from raw socket: %s\n", strerror (errno));
872 break;
873 }
874 if ((0 < ret) && (0 == mac_test (datastart, &dev)))
875 {
876 write_std.size =
877 ret + sizeof (struct GNUNET_MessageHeader) +
878 sizeof (struct Radiotap_rx);
879 header->size = htons (write_std.size);
880 header->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
881 }
928 } 882 }
883
884 }
929 /* Error handling, try to clean up a bit at least */ 885 /* Error handling, try to clean up a bit at least */
930 GNUNET_SERVER_mst_destroy(stdin_mst); 886 GNUNET_SERVER_mst_destroy (stdin_mst);
931 close (dev.fd_raw); 887 close (dev.fd_raw);
932 return 1; 888 return 1;
933} 889}
934 890
935int 891int
936main(int argc, char *argv[]) 892main (int argc, char *argv[])
937{ 893{
938 if (2 != argc) 894 if (2 != argc)
939 { 895 {
940 fprintf (stderr, 896 fprintf (stderr,
941 "This program must be started with the interface as argument.\nThis program was compiled at ----- %s ----\n", __TIMESTAMP__ ); 897 "This program must be started with the interface as argument.\nThis program was compiled at ----- %s ----\n",
942 fprintf (stderr, 898 __TIMESTAMP__);
943 "Usage: interface-name\n" 899 fprintf (stderr, "Usage: interface-name\n" "\n");
944 "\n"); 900 return 1;
945 return 1; 901 }
946 } 902 return hardwaremode (argc, argv);
947 return hardwaremode(argc , argv);
948} 903}
diff --git a/src/transport/gnunet-transport-wlan-helper.h b/src/transport/gnunet-transport-wlan-helper.h
index 9cdff24e2..0c708f912 100644
--- a/src/transport/gnunet-transport-wlan-helper.h
+++ b/src/transport/gnunet-transport-wlan-helper.h
@@ -23,7 +23,7 @@
23 * @brief common internal definitions for the wlan mediator 23 * @brief common internal definitions for the wlan mediator
24 * @author David Brodski 24 * @author David Brodski
25 */ 25 */
26 26
27#ifndef gnunet_wlan_H 27#ifndef gnunet_wlan_H
28#define gnunet_wlan_H 28#define gnunet_wlan_H
29 29
@@ -72,4 +72,3 @@ struct sendbuf
72 72
73 73
74#endif /* gnunet_wlan_H */ 74#endif /* gnunet_wlan_H */
75
diff --git a/src/transport/ieee80211_radiotap.h b/src/transport/ieee80211_radiotap.h
index 91d197995..ed1cd69dd 100644
--- a/src/transport/ieee80211_radiotap.h
+++ b/src/transport/ieee80211_radiotap.h
@@ -61,25 +61,26 @@
61 * The radio capture header precedes the 802.11 header. 61 * The radio capture header precedes the 802.11 header.
62 * All data in the header is little endian on all platforms. 62 * All data in the header is little endian on all platforms.
63 */ 63 */
64struct ieee80211_radiotap_header { 64struct ieee80211_radiotap_header
65 u8 it_version; /* Version 0. Only increases 65{
66 * for drastic changes, 66 u8 it_version; /* Version 0. Only increases
67 * introduction of compatible 67 * for drastic changes,
68 * new fields does not count. 68 * introduction of compatible
69 */ 69 * new fields does not count.
70 u8 it_pad; 70 */
71 __le16 it_len; /* length of the whole 71 u8 it_pad;
72 * header in bytes, including 72 __le16 it_len; /* length of the whole
73 * it_version, it_pad, 73 * header in bytes, including
74 * it_len, and data fields. 74 * it_version, it_pad,
75 */ 75 * it_len, and data fields.
76 __le32 it_present; /* A bitmap telling which 76 */
77 * fields are present. Set bit 31 77 __le32 it_present; /* A bitmap telling which
78 * (0x80000000) to extend the 78 * fields are present. Set bit 31
79 * bitmap by another 32 bits. 79 * (0x80000000) to extend the
80 * Additional extensions are made 80 * bitmap by another 32 bits.
81 * by setting bit 31. 81 * Additional extensions are made
82 */ 82 * by setting bit 31.
83 */
83} __packed; 84} __packed;
84 85
85/* Name Data type Units 86/* Name Data type Units
@@ -179,71 +180,72 @@ struct ieee80211_radiotap_header {
179 * Number of unicast retries a transmitted frame used. 180 * Number of unicast retries a transmitted frame used.
180 * 181 *
181 */ 182 */
182enum ieee80211_radiotap_type { 183enum ieee80211_radiotap_type
183 IEEE80211_RADIOTAP_TSFT = 0, 184{
184 IEEE80211_RADIOTAP_FLAGS = 1, 185 IEEE80211_RADIOTAP_TSFT = 0,
185 IEEE80211_RADIOTAP_RATE = 2, 186 IEEE80211_RADIOTAP_FLAGS = 1,
186 IEEE80211_RADIOTAP_CHANNEL = 3, 187 IEEE80211_RADIOTAP_RATE = 2,
187 IEEE80211_RADIOTAP_FHSS = 4, 188 IEEE80211_RADIOTAP_CHANNEL = 3,
188 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, 189 IEEE80211_RADIOTAP_FHSS = 4,
189 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, 190 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
190 IEEE80211_RADIOTAP_LOCK_QUALITY = 7, 191 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
191 IEEE80211_RADIOTAP_TX_ATTENUATION = 8, 192 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
192 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, 193 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
193 IEEE80211_RADIOTAP_DBM_TX_POWER = 10, 194 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
194 IEEE80211_RADIOTAP_ANTENNA = 11, 195 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
195 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, 196 IEEE80211_RADIOTAP_ANTENNA = 11,
196 IEEE80211_RADIOTAP_DB_ANTNOISE = 13, 197 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
197 IEEE80211_RADIOTAP_RX_FLAGS = 14, 198 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
198 IEEE80211_RADIOTAP_TX_FLAGS = 15, 199 IEEE80211_RADIOTAP_RX_FLAGS = 14,
199 IEEE80211_RADIOTAP_RTS_RETRIES = 16, 200 IEEE80211_RADIOTAP_TX_FLAGS = 15,
200 IEEE80211_RADIOTAP_DATA_RETRIES = 17, 201 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
202 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
201 203
202 /* valid in every it_present bitmap, even vendor namespaces */ 204 /* valid in every it_present bitmap, even vendor namespaces */
203 IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29, 205 IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE = 29,
204 IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30, 206 IEEE80211_RADIOTAP_VENDOR_NAMESPACE = 30,
205 IEEE80211_RADIOTAP_EXT = 31 207 IEEE80211_RADIOTAP_EXT = 31
206}; 208};
207 209
208/* Channel flags. */ 210/* Channel flags. */
209#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */ 211#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
210#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ 212#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
211#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ 213#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
212#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */ 214#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
213#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ 215#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
214#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ 216#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
215#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ 217#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
216#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ 218#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
217 219
218/* For IEEE80211_RADIOTAP_FLAGS */ 220/* For IEEE80211_RADIOTAP_FLAGS */
219#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received 221#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
220 * during CFP 222 * during CFP
221 */ 223 */
222#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received 224#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
223 * with short 225 * with short
224 * preamble 226 * preamble
225 */ 227 */
226#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received 228#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
227 * with WEP encryption 229 * with WEP encryption
228 */ 230 */
229#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received 231#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
230 * with fragmentation 232 * with fragmentation
231 */ 233 */
232#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ 234#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
233#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between 235#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
234 * 802.11 header and payload 236 * 802.11 header and payload
235 * (to 32-bit boundary) 237 * (to 32-bit boundary)
236 */ 238 */
237#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */ 239#define IEEE80211_RADIOTAP_F_BADFCS 0x40 /* bad FCS */
238 240
239/* For IEEE80211_RADIOTAP_RX_FLAGS */ 241/* For IEEE80211_RADIOTAP_RX_FLAGS */
240#define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */ 242#define IEEE80211_RADIOTAP_F_RX_BADPLCP 0x0002 /* frame has bad PLCP */
241 243
242/* For IEEE80211_RADIOTAP_TX_FLAGS */ 244/* For IEEE80211_RADIOTAP_TX_FLAGS */
243#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive 245#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
244 * retries */ 246 * retries */
245#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ 247#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
246#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ 248#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
247 249
248/* Ugly macro to convert literal channel numbers into their mhz equivalents 250/* Ugly macro to convert literal channel numbers into their mhz equivalents
249 * There are certianly some conditions that will break this (like feeding it '30') 251 * There are certianly some conditions that will break this (like feeding it '30')
@@ -254,18 +256,20 @@ enum ieee80211_radiotap_type {
254 ((x) + 1000) * 5) 256 ((x) + 1000) * 5)
255 257
256/* helpers */ 258/* helpers */
257static inline u16 get_unaligned_le16(const u8 *p) 259static inline u16
260get_unaligned_le16 (const u8 *p)
258{ 261{
259 return p[0] | p[1] << 8; 262 return p[0] | p[1] << 8;
260} 263}
261 264
262 265
263static inline int ieee80211_get_radiotap_len(unsigned char *data) 266static inline int
267ieee80211_get_radiotap_len (unsigned char *data)
264{ 268{
265 struct ieee80211_radiotap_header *hdr = 269 struct ieee80211_radiotap_header *hdr =
266 (struct ieee80211_radiotap_header *)data; 270 (struct ieee80211_radiotap_header *) data;
267 271
268 return get_unaligned_le16( (const u8 *) &hdr->it_len); 272 return get_unaligned_le16 ((const u8 *) &hdr->it_len);
269} 273}
270 274
271#endif /* IEEE80211_RADIOTAP_H */ 275#endif /* IEEE80211_RADIOTAP_H */
diff --git a/src/transport/perf_transport_ats.c b/src/transport/perf_transport_ats.c
index 3f8950a8a..df1ebe950 100644
--- a/src/transport/perf_transport_ats.c
+++ b/src/transport/perf_transport_ats.c
@@ -40,48 +40,51 @@ static uint64_t sim_with_opt_avg;
40static uint64_t mlp_no_opt_avg; 40static uint64_t mlp_no_opt_avg;
41static uint64_t mlp_with_opt_avg; 41static uint64_t mlp_with_opt_avg;
42 42
43static glp_prob * prob; 43static glp_prob *prob;
44 44
45static struct GNUNET_TIME_Absolute start; 45static struct GNUNET_TIME_Absolute start;
46static struct GNUNET_TIME_Absolute end; 46static struct GNUNET_TIME_Absolute end;
47 47
48static void 48static void
49solve_mlp(int presolve) 49solve_mlp (int presolve)
50{ 50{
51 int result, solution; 51 int result, solution;
52 glp_iocp opt_mlp; 52 glp_iocp opt_mlp;
53 53
54 glp_init_iocp(&opt_mlp); 54 glp_init_iocp (&opt_mlp);
55 opt_mlp.msg_lev = GLP_MSG_OFF; 55 opt_mlp.msg_lev = GLP_MSG_OFF;
56 opt_mlp.presolve = GLP_OFF; 56 opt_mlp.presolve = GLP_OFF;
57 57
58 result = glp_intopt (prob, &opt_mlp); 58 result = glp_intopt (prob, &opt_mlp);
59 solution = glp_mip_status (prob); 59 solution = glp_mip_status (prob);
60 GNUNET_assert ((solution == 5) && (result==0)); 60 GNUNET_assert ((solution == 5) && (result == 0));
61} 61}
62 62
63static void 63static void
64solve_lp(int presolve) 64solve_lp (int presolve)
65{ 65{
66 int result; 66 int result;
67 int solution; 67 int solution;
68 68
69 glp_smcp opt_lp; 69 glp_smcp opt_lp;
70 glp_init_smcp(&opt_lp);
71 70
72 opt_lp.msg_lev = GLP_MSG_OFF; 71 glp_init_smcp (&opt_lp);
73 if (presolve==GNUNET_YES) opt_lp.presolve = GLP_ON;
74 else opt_lp.presolve = GLP_OFF;
75 72
76 result = glp_simplex(prob, &opt_lp); 73 opt_lp.msg_lev = GLP_MSG_OFF;
77 solution = glp_get_status (prob); 74 if (presolve == GNUNET_YES)
78 GNUNET_assert ((solution == 5) && (result==0)); 75 opt_lp.presolve = GLP_ON;
76 else
77 opt_lp.presolve = GLP_OFF;
78
79 result = glp_simplex (prob, &opt_lp);
80 solution = glp_get_status (prob);
81 GNUNET_assert ((solution == 5) && (result == 0));
79} 82}
80 83
81#if 0 84#if 0
82/* Modify quality constraint */ 85/* Modify quality constraint */
83static void 86static void
84modify_qm(int start, int length, int values_to_change) 87modify_qm (int start, int length, int values_to_change)
85{ 88{
86 //int * ind = GNUNET_malloc (length * sizeof (int)); 89 //int * ind = GNUNET_malloc (length * sizeof (int));
87 //double *val = GNUNET_malloc (length * sizeof (double)); 90 //double *val = GNUNET_malloc (length * sizeof (double));
@@ -89,15 +92,16 @@ modify_qm(int start, int length, int values_to_change)
89 double val[1000]; 92 double val[1000];
90 93
91 int res = 0; 94 int res = 0;
92 int c = start, c2=1; 95 int c = start, c2 = 1;
93 while (c<=(start+values_to_change)) 96
97 while (c <= (start + values_to_change))
94 { 98 {
95 res = glp_get_mat_row(prob, c, ind, val); 99 res = glp_get_mat_row (prob, c, ind, val);
96 100
97 printf("%i %i \n", c, res); 101 printf ("%i %i \n", c, res);
98 for (c2=0; c2<res; c2++) 102 for (c2 = 0; c2 < res; c2++)
99 { 103 {
100 printf("%i = %f \n", ind[c2], val[c2]); 104 printf ("%i = %f \n", ind[c2], val[c2]);
101 } 105 }
102 c++; 106 c++;
103 } 107 }
@@ -107,162 +111,158 @@ modify_qm(int start, int length, int values_to_change)
107 111
108 112
109 113
110static void 114static void
111bench_simplex_optimization(char * file, int executions) 115bench_simplex_optimization (char *file, int executions)
112{ 116{
113 int c; 117 int c;
114 int res; 118 int res;
115 119
116 prob = glp_create_prob(); 120 prob = glp_create_prob ();
117 res = glp_read_lp(prob, NULL, file); 121 res = glp_read_lp (prob, NULL, file);
118 if (res != 0) 122 if (res != 0)
119 { 123 {
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 124 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
121 "Problem file `%s' not found\n", file);
122 ret = 1; 125 ret = 1;
123 return; 126 return;
124 } 127 }
125 128
126 solve_lp(GNUNET_YES); 129 solve_lp (GNUNET_YES);
127 130
128 for (c=0; c<executions;c++) 131 for (c = 0; c < executions; c++)
129 { 132 {
130 start = GNUNET_TIME_absolute_get(); 133 start = GNUNET_TIME_absolute_get ();
131 solve_lp(GNUNET_NO); 134 solve_lp (GNUNET_NO);
132 end = GNUNET_TIME_absolute_get(); 135 end = GNUNET_TIME_absolute_get ();
133 136
134 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value; 137 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
135 138
136 sim_with_opt_avg += exec_time[c]; 139 sim_with_opt_avg += exec_time[c];
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
138 "Simplex /w optimization iterations %i: %llu \n", c, exec_time[c]); 141 "Simplex /w optimization iterations %i: %llu \n", c,
142 exec_time[c]);
139 } 143 }
140 144
141 glp_delete_prob(prob); 145 glp_delete_prob (prob);
142} 146}
143 147
144 148
145static void 149static void
146bench_simplex_no_optimization(char * file, int executions) 150bench_simplex_no_optimization (char *file, int executions)
147{ 151{
148 int c; 152 int c;
149 int res; 153 int res;
150 154
151 prob = glp_create_prob(); 155 prob = glp_create_prob ();
152 res = glp_read_lp(prob, NULL, file); 156 res = glp_read_lp (prob, NULL, file);
153 if (res != 0) 157 if (res != 0)
154 { 158 {
155 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
156 "Problem file `%s' not found\n", file);
157 ret = 1; 160 ret = 1;
158 return; 161 return;
159 } 162 }
160 163
161 for (c=0; c<executions;c++) 164 for (c = 0; c < executions; c++)
162 { 165 {
163 start = GNUNET_TIME_absolute_get(); 166 start = GNUNET_TIME_absolute_get ();
164 solve_lp(GNUNET_YES); 167 solve_lp (GNUNET_YES);
165 end = GNUNET_TIME_absolute_get(); 168 end = GNUNET_TIME_absolute_get ();
166 169
167 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value; 170 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
168 171
169 sim_no_opt_avg += exec_time[c]; 172 sim_no_opt_avg += exec_time[c];
170 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
171 "Simplex iterations %i: %llu \n", 174 "Simplex iterations %i: %llu \n", c, exec_time[c]);
172 c, exec_time[c]);
173 } 175 }
174 176
175 glp_delete_prob(prob); 177 glp_delete_prob (prob);
176} 178}
177 179
178static void 180static void
179bench_mlp_no_optimization(char * file, int executions) 181bench_mlp_no_optimization (char *file, int executions)
180{ 182{
181 int c; 183 int c;
182 int res; 184 int res;
183 185
184 prob = glp_create_prob(); 186 prob = glp_create_prob ();
185 res = glp_read_lp(prob, NULL, file); 187 res = glp_read_lp (prob, NULL, file);
186 if (res != 0) 188 if (res != 0)
187 { 189 {
188 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
189 "Problem file `%s' not found\n", file);
190 ret = 1; 191 ret = 1;
191 return; 192 return;
192 } 193 }
193 for (c=0; c<executions;c++) 194 for (c = 0; c < executions; c++)
194 { 195 {
195 start = GNUNET_TIME_absolute_get(); 196 start = GNUNET_TIME_absolute_get ();
196 solve_lp(GNUNET_YES); 197 solve_lp (GNUNET_YES);
197 solve_mlp (GNUNET_NO); 198 solve_mlp (GNUNET_NO);
198 end = GNUNET_TIME_absolute_get(); 199 end = GNUNET_TIME_absolute_get ();
199 200
200 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value; 201 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
201 202
202 mlp_no_opt_avg += exec_time[c]; 203 mlp_no_opt_avg += exec_time[c];
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
204 "MLP iterations no optimization %i: %llu \n", 205 "MLP iterations no optimization %i: %llu \n", c, exec_time[c]);
205 c, exec_time[c]);
206 } 206 }
207 207
208 glp_delete_prob(prob); 208 glp_delete_prob (prob);
209} 209}
210 210
211 211
212static void 212static void
213bench_mlp_with_optimization(char * file, int executions, int changes) 213bench_mlp_with_optimization (char *file, int executions, int changes)
214{ 214{
215 int c; 215 int c;
216 int res; 216 int res;
217 217
218 prob = glp_create_prob(); 218 prob = glp_create_prob ();
219 res = glp_read_lp(prob, NULL, file); 219 res = glp_read_lp (prob, NULL, file);
220 if (res != 0) 220 if (res != 0)
221 { 221 {
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem file `%s' not found\n", file);
223 "Problem file `%s' not found\n", file);
224 ret = 1; 223 ret = 1;
225 return; 224 return;
226 } 225 }
227 226
228 solve_lp(GNUNET_YES); 227 solve_lp (GNUNET_YES);
229 228
230 for (c=0; c<executions;c++) 229 for (c = 0; c < executions; c++)
231 { 230 {
232 start = GNUNET_TIME_absolute_get(); 231 start = GNUNET_TIME_absolute_get ();
233 //modify_qm(906, 0, 0); 232 //modify_qm(906, 0, 0);
234 solve_lp(GNUNET_NO); 233 solve_lp (GNUNET_NO);
235 solve_mlp (GNUNET_NO); 234 solve_mlp (GNUNET_NO);
236 end = GNUNET_TIME_absolute_get(); 235 end = GNUNET_TIME_absolute_get ();
237 236
238 exec_time[c] = GNUNET_TIME_absolute_get_difference(start, end).rel_value; 237 exec_time[c] = GNUNET_TIME_absolute_get_difference (start, end).rel_value;
239 238
240 mlp_with_opt_avg += exec_time[c]; 239 mlp_with_opt_avg += exec_time[c];
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 240 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "MLP /w optimization iterations %i: %llu \n", 241 "MLP /w optimization iterations %i: %llu \n", c, exec_time[c]);
243 c, exec_time[c]);
244 } 242 }
245 243
246 glp_delete_prob(prob); 244 glp_delete_prob (prob);
247} 245}
248 246
249#if 0 247#if 0
250void modify_cr (int start, int length, int count) 248void
249modify_cr (int start, int length, int count)
251{ 250{
252 //int * ind = GNUNET_malloc (length * sizeof (int)); 251 //int * ind = GNUNET_malloc (length * sizeof (int));
253 //double *val = GNUNET_malloc (length * sizeof (double)); 252 //double *val = GNUNET_malloc (length * sizeof (double));
254 int ind[500]; 253 int ind[500];
255 double val[500]; 254 double val[500];
256 int res = 0; 255 int res = 0;
257 int c = start, c2=1; 256 int c = start, c2 = 1;
258 while (c<=(start+count)) 257
258 while (c <= (start + count))
259 { 259 {
260 res = glp_get_mat_row(prob, c, ind, val); 260 res = glp_get_mat_row (prob, c, ind, val);
261 261
262 printf("row index: %i non-zero elements: %i \n", c, res); 262 printf ("row index: %i non-zero elements: %i \n", c, res);
263 for (c2=1; c2<=res; c2++) 263 for (c2 = 1; c2 <= res; c2++)
264 { 264 {
265 printf("%i = %f ", ind[c2], val[c2]); 265 printf ("%i = %f ", ind[c2], val[c2]);
266 } 266 }
267 c++; 267 c++;
268 printf ("\n----\n"); 268 printf ("\n----\n");
@@ -272,7 +272,8 @@ void modify_cr (int start, int length, int count)
272#endif 272#endif
273 273
274 274
275int main (int argc, char *argv[]) 275int
276main (int argc, char *argv[])
276{ 277{
277 278
278 GNUNET_log_setup ("perf-transport-ats", 279 GNUNET_log_setup ("perf-transport-ats",
@@ -283,6 +284,7 @@ int main (int argc, char *argv[])
283#endif 284#endif
284 NULL); 285 NULL);
285 int nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND); 286 int nullfd = OPEN ("/dev/null", O_RDWR | O_APPEND);
287
286 if (nullfd < 0) 288 if (nullfd < 0)
287 return GNUNET_SYSERR; 289 return GNUNET_SYSERR;
288 if (dup2 (nullfd, 1) < 0) 290 if (dup2 (nullfd, 1) < 0)
@@ -293,7 +295,7 @@ int main (int argc, char *argv[])
293 } 295 }
294 296
295 297
296 char * file = "ats_mlp_p100_m400.problem"; 298 char *file = "ats_mlp_p100_m400.problem";
297 299
298 bench_simplex_no_optimization (file, executions); 300 bench_simplex_no_optimization (file, executions);
299 bench_simplex_optimization (file, executions); 301 bench_simplex_optimization (file, executions);
@@ -305,33 +307,32 @@ int main (int argc, char *argv[])
305 307
306 // -> 400 addresses 308 // -> 400 addresses
307 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 309 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
308 "Simplex, no optimization, average per address: %f\n", 310 "Simplex, no optimization, average per address: %f\n",
309 ((double) sim_no_opt_avg / EXECS) / 400); 311 ((double) sim_no_opt_avg / EXECS) / 400);
310 GAUGER ("TRANSPORT","GLPK simplex no optimization", 312 GAUGER ("TRANSPORT", "GLPK simplex no optimization",
311 ((double) sim_no_opt_avg / EXECS) / 400, "ms/address"); 313 ((double) sim_no_opt_avg / EXECS) / 400, "ms/address");
312 314
313 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 315 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
314 "Simplex, with optimization, average per address: %f\n", 316 "Simplex, with optimization, average per address: %f\n",
315 ((double) sim_with_opt_avg / EXECS) / 400); 317 ((double) sim_with_opt_avg / EXECS) / 400);
316 GAUGER ("TRANSPORT", 318 GAUGER ("TRANSPORT",
317 "GLPK simplex, 100 peers 400 addresses with optimization", 319 "GLPK simplex, 100 peers 400 addresses with optimization",
318 ((double) sim_with_opt_avg / EXECS) / 400, "ms/address"); 320 ((double) sim_with_opt_avg / EXECS) / 400, "ms/address");
319 321
320 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 322 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
321 "MLP no optimization average per address: %f\n", 323 "MLP no optimization average per address: %f\n",
322 ((double) mlp_no_opt_avg / EXECS) / 400); 324 ((double) mlp_no_opt_avg / EXECS) / 400);
323 GAUGER ("TRANSPORT","GLPK MLP 100 peers 400 addresses no optimization", 325 GAUGER ("TRANSPORT", "GLPK MLP 100 peers 400 addresses no optimization",
324 ((double) mlp_no_opt_avg / EXECS) / 400, "ms/address"); 326 ((double) mlp_no_opt_avg / EXECS) / 400, "ms/address");
325 327
326 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 328 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
327 "MLP optimization average per address: %f\n", 329 "MLP optimization average per address: %f\n",
328 ((double) mlp_with_opt_avg/ EXECS) / 400); 330 ((double) mlp_with_opt_avg / EXECS) / 400);
329 GAUGER ("TRANSPORT", 331 GAUGER ("TRANSPORT",
330 "GLPK MLP 100 peers 400 addresses with optimization", 332 "GLPK MLP 100 peers 400 addresses with optimization",
331 ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address"); 333 ((double) mlp_with_opt_avg / EXECS) / 400, "ms/address");
332 (void) CLOSE (nullfd); 334 (void) CLOSE (nullfd);
333 return ret; 335 return ret;
334} 336}
335 337
336/* end of perf_transport_ats.c*/ 338/* end of perf_transport_ats.c*/
337
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c
index e63549784..0c856e4ab 100644
--- a/src/transport/plugin_transport_http.c
+++ b/src/transport/plugin_transport_http.c
@@ -114,14 +114,14 @@ struct IPv4HttpAddressWrapper
114 /** 114 /**
115 * Linked list next 115 * Linked list next
116 */ 116 */
117 struct IPv4HttpAddressWrapper * next; 117 struct IPv4HttpAddressWrapper *next;
118 118
119 /** 119 /**
120 * Linked list previous 120 * Linked list previous
121 */ 121 */
122 struct IPv4HttpAddressWrapper * prev; 122 struct IPv4HttpAddressWrapper *prev;
123 123
124 struct IPv4HttpAddress * addr; 124 struct IPv4HttpAddress *addr;
125}; 125};
126 126
127/** 127/**
@@ -149,14 +149,14 @@ struct IPv6HttpAddressWrapper
149 /** 149 /**
150 * Linked list next 150 * Linked list next
151 */ 151 */
152 struct IPv6HttpAddressWrapper * next; 152 struct IPv6HttpAddressWrapper *next;
153 153
154 /** 154 /**
155 * Linked list previous 155 * Linked list previous
156 */ 156 */
157 struct IPv6HttpAddressWrapper * prev; 157 struct IPv6HttpAddressWrapper *prev;
158 158
159 struct IPv6HttpAddress * addr; 159 struct IPv6HttpAddress *addr;
160}; 160};
161 161
162/** 162/**
@@ -167,12 +167,12 @@ struct HTTP_Message
167 /** 167 /**
168 * next pointer for double linked list 168 * next pointer for double linked list
169 */ 169 */
170 struct HTTP_Message * next; 170 struct HTTP_Message *next;
171 171
172 /** 172 /**
173 * previous pointer for double linked list 173 * previous pointer for double linked list
174 */ 174 */
175 struct HTTP_Message * prev; 175 struct HTTP_Message *prev;
176 176
177 /** 177 /**
178 * buffer containing data to send 178 * buffer containing data to send
@@ -219,13 +219,13 @@ struct HTTP_PeerContext
219 * Linked list of connections with this peer 219 * Linked list of connections with this peer
220 * head 220 * head
221 */ 221 */
222 struct Session * head; 222 struct Session *head;
223 223
224 /** 224 /**
225 * Linked list of connections with this peer 225 * Linked list of connections with this peer
226 * tail 226 * tail
227 */ 227 */
228 struct Session * tail; 228 struct Session *tail;
229 229
230 /** 230 /**
231 * id for next session 231 * id for next session
@@ -235,7 +235,7 @@ struct HTTP_PeerContext
235 /** 235 /**
236 * Last session used to send data 236 * Last session used to send data
237 */ 237 */
238 struct Session * last_session; 238 struct Session *last_session;
239 239
240 /** 240 /**
241 * The task resetting inbound quota delay 241 * The task resetting inbound quota delay
@@ -259,17 +259,17 @@ struct Session
259 /** 259 /**
260 * next session in linked list 260 * next session in linked list
261 */ 261 */
262 struct Session * next; 262 struct Session *next;
263 263
264 /** 264 /**
265 * previous session in linked list 265 * previous session in linked list
266 */ 266 */
267 struct Session * prev; 267 struct Session *prev;
268 268
269 /** 269 /**
270 * address of this session 270 * address of this session
271 */ 271 */
272 void * addr; 272 void *addr;
273 273
274 /** 274 /**
275 * address length 275 * address length
@@ -279,24 +279,24 @@ struct Session
279 /** 279 /**
280 * target url 280 * target url
281 */ 281 */
282 char * url; 282 char *url;
283 283
284 /** 284 /**
285 * Message queue for outbound messages 285 * Message queue for outbound messages
286 * head of queue 286 * head of queue
287 */ 287 */
288 struct HTTP_Message * pending_msgs_head; 288 struct HTTP_Message *pending_msgs_head;
289 289
290 /** 290 /**
291 * Message queue for outbound messages 291 * Message queue for outbound messages
292 * tail of queue 292 * tail of queue
293 */ 293 */
294 struct HTTP_Message * pending_msgs_tail; 294 struct HTTP_Message *pending_msgs_tail;
295 295
296 /** 296 /**
297 * partner peer this connection belongs to 297 * partner peer this connection belongs to
298 */ 298 */
299 struct HTTP_PeerContext * peercontext; 299 struct HTTP_PeerContext *peercontext;
300 300
301 /** 301 /**
302 * message stream tokenizer for incoming data 302 * message stream tokenizer for incoming data
@@ -352,14 +352,14 @@ struct Session
352 * outbound session: CURL * 352 * outbound session: CURL *
353 * inbound session: mhd_connection * 353 * inbound session: mhd_connection *
354 */ 354 */
355 void * send_endpoint; 355 void *send_endpoint;
356 356
357 /** 357 /**
358 * entity managing recieving data 358 * entity managing recieving data
359 * outbound session: CURL * 359 * outbound session: CURL *
360 * inbound session: mhd_connection * 360 * inbound session: mhd_connection *
361 */ 361 */
362 void * recv_endpoint; 362 void *recv_endpoint;
363 363
364 /** 364 /**
365 * Current queue size 365 * Current queue size
@@ -423,7 +423,7 @@ struct Plugin
423 /** 423 /**
424 * cURL Multihandle 424 * cURL Multihandle
425 */ 425 */
426 CURLM * multi_handle; 426 CURLM *multi_handle;
427 427
428 /** 428 /**
429 * Our handle to the NAT module. 429 * Our handle to the NAT module.
@@ -433,22 +433,22 @@ struct Plugin
433 /** 433 /**
434 * ipv4 DLL head 434 * ipv4 DLL head
435 */ 435 */
436 struct IPv4HttpAddressWrapper * ipv4_addr_head; 436 struct IPv4HttpAddressWrapper *ipv4_addr_head;
437 437
438 /** 438 /**
439 * ipv4 DLL tail 439 * ipv4 DLL tail
440 */ 440 */
441 struct IPv4HttpAddressWrapper * ipv4_addr_tail; 441 struct IPv4HttpAddressWrapper *ipv4_addr_tail;
442 442
443 /** 443 /**
444 * ipv6 DLL head 444 * ipv6 DLL head
445 */ 445 */
446 struct IPv6HttpAddressWrapper * ipv6_addr_head; 446 struct IPv6HttpAddressWrapper *ipv6_addr_head;
447 447
448 /** 448 /**
449 * ipv6 DLL tail 449 * ipv6 DLL tail
450 */ 450 */
451 struct IPv6HttpAddressWrapper * ipv6_addr_tail; 451 struct IPv6HttpAddressWrapper *ipv6_addr_tail;
452 452
453 /** 453 /**
454 * Our ASCII encoded, hashed peer identity 454 * Our ASCII encoded, hashed peer identity
@@ -459,17 +459,17 @@ struct Plugin
459 /** 459 /**
460 * IPv4 Address the plugin binds to 460 * IPv4 Address the plugin binds to
461 */ 461 */
462 struct sockaddr_in * bind4_address; 462 struct sockaddr_in *bind4_address;
463 463
464 /** 464 /**
465 * IPv6 Address the plugins binds to 465 * IPv6 Address the plugins binds to
466 */ 466 */
467 struct sockaddr_in6 * bind6_address; 467 struct sockaddr_in6 *bind6_address;
468 468
469 /** 469 /**
470 * Hostname to bind to 470 * Hostname to bind to
471 */ 471 */
472 char * bind_hostname; 472 char *bind_hostname;
473 473
474 /** 474 /**
475 * Is IPv4 enabled? 475 * Is IPv4 enabled?
@@ -499,18 +499,18 @@ struct Plugin
499 /** 499 /**
500 * Closure passed by MHD to the mhd_logger function 500 * Closure passed by MHD to the mhd_logger function
501 */ 501 */
502 void * mhd_log; 502 void *mhd_log;
503 503
504 /* only needed for HTTPS plugin */ 504 /* only needed for HTTPS plugin */
505#if BUILD_HTTPS 505#if BUILD_HTTPS
506 /* The certificate MHD uses as an \0 terminated string */ 506 /* The certificate MHD uses as an \0 terminated string */
507 char * cert; 507 char *cert;
508 508
509 /* The private key MHD uses as an \0 terminated string */ 509 /* The private key MHD uses as an \0 terminated string */
510 char * key; 510 char *key;
511 511
512 /* crypto init string */ 512 /* crypto init string */
513 char * crypto_init; 513 char *crypto_init;
514#endif 514#endif
515}; 515};
516 516
@@ -547,22 +547,25 @@ struct PrettyPrinterContext
547 * @param addrlen length of the address 547 * @param addrlen length of the address
548 * @return string representing the same address 548 * @return string representing the same address
549 */ 549 */
550static const char* 550static const char *http_plugin_address_to_string (void *cls,
551http_plugin_address_to_string (void *cls, 551 const void *addr,
552 const void *addr, 552 size_t addrlen);
553 size_t addrlen);
554 553
555 554
556/** 555/**
557 * Call MHD to process pending ipv4 requests and then go back 556 * Call MHD to process pending ipv4 requests and then go back
558 * and schedule the next run. 557 * and schedule the next run.
559 */ 558 */
560static void http_server_daemon_v4_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 559static void http_server_daemon_v4_run (void *cls,
560 const struct GNUNET_SCHEDULER_TaskContext
561 *tc);
561/** 562/**
562 * Call MHD to process pending ipv6 requests and then go back 563 * Call MHD to process pending ipv6 requests and then go back
563 * and schedule the next run. 564 * and schedule the next run.
564 */ 565 */
565static void http_server_daemon_v6_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 566static void http_server_daemon_v6_run (void *cls,
567 const struct GNUNET_SCHEDULER_TaskContext
568 *tc);
566 569
567/** 570/**
568 * Function setting up curl handle and selecting message to send 571 * Function setting up curl handle and selecting message to send
@@ -586,12 +589,13 @@ static int curl_schedule (struct Plugin *plugin);
586 * @param cls plugin as closure 589 * @param cls plugin as closure
587 * @param tc task context 590 * @param tc task context
588 */ 591 */
589static void reset_inbound_quota_delay (void *cls, 592static void
590 const struct GNUNET_SCHEDULER_TaskContext *tc) 593reset_inbound_quota_delay (void *cls,
594 const struct GNUNET_SCHEDULER_TaskContext *tc)
591{ 595{
592 struct HTTP_PeerContext * pc = cls; 596 struct HTTP_PeerContext *pc = cls;
593 597
594 GNUNET_assert(cls != NULL); 598 GNUNET_assert (cls != NULL);
595 pc->reset_task = GNUNET_SCHEDULER_NO_TASK; 599 pc->reset_task = GNUNET_SCHEDULER_NO_TASK;
596 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 600 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
597 return; 601 return;
@@ -607,18 +611,16 @@ static void reset_inbound_quota_delay (void *cls,
607 * @param id session id 611 * @param id session id
608 * @return the created url 612 * @return the created url
609 */ 613 */
610static char * 614static char *
611create_url(struct Plugin *plugin, 615create_url (struct Plugin *plugin, const void *addr, size_t addrlen, size_t id)
612 const void * addr, size_t addrlen,
613 size_t id)
614{ 616{
615 char *url = NULL; 617 char *url = NULL;
616 char *addr_str = (char *) http_plugin_address_to_string(NULL, addr, addrlen); 618 char *addr_str = (char *) http_plugin_address_to_string (NULL, addr, addrlen);
617 619
618 GNUNET_assert ((addr!=NULL) && (addrlen != 0)); 620 GNUNET_assert ((addr != NULL) && (addrlen != 0));
619 GNUNET_asprintf(&url, 621 GNUNET_asprintf (&url,
620 "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str, 622 "%s://%s/%s;%u", PROTOCOL_PREFIX, addr_str,
621 (char *) (&plugin->my_ascii_hash_ident),id); 623 (char *) (&plugin->my_ascii_hash_ident), id);
622 return url; 624 return url;
623} 625}
624 626
@@ -629,14 +631,12 @@ create_url(struct Plugin *plugin,
629 * @param msg message 631 * @param msg message
630 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success 632 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
631 */ 633 */
632static int 634static int
633remove_http_message (struct Session * ps, 635remove_http_message (struct Session *ps, struct HTTP_Message *msg)
634 struct HTTP_Message * msg)
635{ 636{
636 GNUNET_CONTAINER_DLL_remove(ps->pending_msgs_head, 637 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head,
637 ps->pending_msgs_tail, 638 ps->pending_msgs_tail, msg);
638 msg); 639 GNUNET_free (msg);
639 GNUNET_free(msg);
640 return GNUNET_OK; 640 return GNUNET_OK;
641} 641}
642 642
@@ -647,59 +647,56 @@ remove_http_message (struct Session * ps,
647 * @param value the peer context 647 * @param value the peer context
648 * @return GNUNET_YES on success 648 * @return GNUNET_YES on success
649 */ 649 */
650static int 650static int
651remove_peer_context_Iterator (void *cls, 651remove_peer_context_Iterator (void *cls,
652 const GNUNET_HashCode *key, 652 const GNUNET_HashCode * key, void *value)
653 void *value)
654{ 653{
655 struct Plugin *plugin = cls; 654 struct Plugin *plugin = cls;
656 struct HTTP_PeerContext * pc = value; 655 struct HTTP_PeerContext *pc = value;
657 struct Session * ps = pc->head; 656 struct Session *ps = pc->head;
658 struct Session * tmp = NULL; 657 struct Session *tmp = NULL;
659 struct HTTP_Message * msg = NULL; 658 struct HTTP_Message *msg = NULL;
660 struct HTTP_Message * msg_tmp = NULL; 659 struct HTTP_Message *msg_tmp = NULL;
661 660
662#if DEBUG_HTTP 661#if DEBUG_HTTP
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 662 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
664 "Freeing context for peer `%s'\n", 663 "Freeing context for peer `%s'\n", GNUNET_i2s (&pc->identity));
665 GNUNET_i2s(&pc->identity));
666#endif 664#endif
667 GNUNET_assert (GNUNET_YES == 665 GNUNET_assert (GNUNET_YES ==
668 GNUNET_CONTAINER_multihashmap_remove (plugin->peers, 666 GNUNET_CONTAINER_multihashmap_remove (plugin->peers,
669 &pc->identity.hashPubKey, 667 &pc->identity.hashPubKey,
670 pc)); 668 pc));
671 while (ps!=NULL) 669 while (ps != NULL)
670 {
671 plugin->env->session_end (plugin, &pc->identity, ps);
672 tmp = ps->next;
673
674 GNUNET_free_non_null (ps->addr);
675 GNUNET_free (ps->url);
676 if (ps->msgtok != NULL)
677 GNUNET_SERVER_mst_destroy (ps->msgtok);
678
679 msg = ps->pending_msgs_head;
680 while (msg != NULL)
672 { 681 {
673 plugin->env->session_end(plugin, &pc->identity, ps); 682 msg_tmp = msg->next;
674 tmp = ps->next; 683 GNUNET_free (msg);
675 684 msg = msg_tmp;
676 GNUNET_free_non_null (ps->addr); 685 }
677 GNUNET_free(ps->url); 686 if (ps->direction == OUTBOUND)
678 if (ps->msgtok != NULL) 687 {
679 GNUNET_SERVER_mst_destroy (ps->msgtok); 688 if (ps->send_endpoint != NULL)
680 689 curl_easy_cleanup (ps->send_endpoint);
681 msg = ps->pending_msgs_head; 690 if (ps->recv_endpoint != NULL)
682 while (msg!=NULL) 691 curl_easy_cleanup (ps->recv_endpoint);
683 {
684 msg_tmp = msg->next;
685 GNUNET_free(msg);
686 msg = msg_tmp;
687 }
688 if (ps->direction==OUTBOUND)
689 {
690 if (ps->send_endpoint!=NULL)
691 curl_easy_cleanup(ps->send_endpoint);
692 if (ps->recv_endpoint!=NULL)
693 curl_easy_cleanup(ps->recv_endpoint);
694 }
695 GNUNET_free(ps);
696 ps=tmp;
697 } 692 }
698 GNUNET_free(pc); 693 GNUNET_free (ps);
694 ps = tmp;
695 }
696 GNUNET_free (pc);
699 GNUNET_STATISTICS_update (plugin->env->stats, 697 GNUNET_STATISTICS_update (plugin->env->stats,
700 gettext_noop ("# HTTP peers active"), 698 gettext_noop ("# HTTP peers active"),
701 -1, 699 -1, GNUNET_NO);
702 GNUNET_NO);
703 return GNUNET_YES; 700 return GNUNET_YES;
704} 701}
705 702
@@ -712,115 +709,114 @@ remove_peer_context_Iterator (void *cls,
712 * @param call_msg_cont_result result to call message continuations with 709 * @param call_msg_cont_result result to call message continuations with
713 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success 710 * @return GNUNET_SYSERR if msg not found, GNUNET_OK on success
714 */ 711 */
715static int 712static int
716remove_session (struct HTTP_PeerContext * pc, 713remove_session (struct HTTP_PeerContext *pc,
717 struct Session * ps, 714 struct Session *ps, int call_msg_cont, int call_msg_cont_result)
718 int call_msg_cont,
719 int call_msg_cont_result)
720{ 715{
721 struct HTTP_Message * msg; 716 struct HTTP_Message *msg;
722 struct Plugin * plugin = ps->peercontext->plugin; 717 struct Plugin *plugin = ps->peercontext->plugin;
723 718
724#if DEBUG_CONNECTIONS 719#if DEBUG_CONNECTIONS
725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
726 "Connection %X: removing %s session %X with id %u\n", 721 "Connection %X: removing %s session %X with id %u\n",
727 ps, 722 ps,
728 (ps->direction == INBOUND) 723 (ps->direction == INBOUND)
729 ? "inbound" 724 ? "inbound" : "outbound", ps, ps->session_id);
730 : "outbound", 725#endif
731 ps, ps->session_id); 726 plugin->env->session_end (plugin, &pc->identity, ps);
732#endif
733 plugin->env->session_end(plugin, &pc->identity, ps);
734 GNUNET_free_non_null (ps->addr); 727 GNUNET_free_non_null (ps->addr);
735 GNUNET_SERVER_mst_destroy (ps->msgtok); 728 GNUNET_SERVER_mst_destroy (ps->msgtok);
736 GNUNET_free(ps->url); 729 GNUNET_free (ps->url);
737 if (ps->direction==INBOUND) 730 if (ps->direction == INBOUND)
731 {
732 if (ps->recv_endpoint != NULL)
738 { 733 {
739 if (ps->recv_endpoint != NULL) 734 curl_easy_cleanup (ps->recv_endpoint);
740 { 735 ps->recv_endpoint = NULL;
741 curl_easy_cleanup(ps->recv_endpoint); 736 }
742 ps->recv_endpoint = NULL; 737 if (ps->send_endpoint != NULL)
743 } 738 {
744 if (ps->send_endpoint != NULL) 739 curl_easy_cleanup (ps->send_endpoint);
745 { 740 ps->send_endpoint = NULL;
746 curl_easy_cleanup(ps->send_endpoint);
747 ps->send_endpoint = NULL;
748 }
749 } 741 }
750 742 }
743
751 msg = ps->pending_msgs_head; 744 msg = ps->pending_msgs_head;
752 while (msg!=NULL) 745 while (msg != NULL)
746 {
747 if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont != NULL))
753 { 748 {
754 if ((call_msg_cont == GNUNET_YES) && (msg->transmit_cont!=NULL)) 749 msg->transmit_cont (msg->transmit_cont_cls,
755 { 750 &pc->identity, call_msg_cont_result);
756 msg->transmit_cont (msg->transmit_cont_cls,
757 &pc->identity,
758 call_msg_cont_result);
759 }
760 GNUNET_CONTAINER_DLL_remove(ps->pending_msgs_head,
761 ps->pending_msgs_head,
762 msg);
763 GNUNET_free(msg);
764 msg = ps->pending_msgs_head;
765 } 751 }
766 752 GNUNET_CONTAINER_DLL_remove (ps->pending_msgs_head,
767 GNUNET_CONTAINER_DLL_remove(pc->head,pc->tail,ps); 753 ps->pending_msgs_head, msg);
768 GNUNET_free(ps); 754 GNUNET_free (msg);
755 msg = ps->pending_msgs_head;
756 }
757
758 GNUNET_CONTAINER_DLL_remove (pc->head, pc->tail, ps);
759 GNUNET_free (ps);
769 ps = NULL; 760 ps = NULL;
770 761
771 /* no sessions left remove peer */ 762 /* no sessions left remove peer */
772 if (pc->head==NULL) 763 if (pc->head == NULL)
773 { 764 {
774#if DEBUG_HTTP 765#if DEBUG_HTTP
775 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
776 "No sessions left for peer `%s', removing context\n", 767 "No sessions left for peer `%s', removing context\n",
777 GNUNET_i2s(&pc->identity)); 768 GNUNET_i2s (&pc->identity));
778#endif 769#endif
779 remove_peer_context_Iterator(plugin, &pc->identity.hashPubKey, pc); 770 remove_peer_context_Iterator (plugin, &pc->identity.hashPubKey, pc);
780 } 771 }
781 772
782 return GNUNET_OK; 773 return GNUNET_OK;
783} 774}
784 775
785 776
786#if 0 777#if 0
787static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) 778static int
779check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
788{ 780{
789 uint32_t res = 0; 781 uint32_t res = 0;
790 int local = GNUNET_NO; 782 int local = GNUNET_NO;
791 int af = addr->sa_family; 783 int af = addr->sa_family;
792 switch (af) 784
793 { 785 switch (af)
794 case AF_INET: 786 {
795 { 787 case AF_INET:
796 uint32_t netmask = 0x7F000000; 788 {
797 uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr); 789 uint32_t netmask = 0x7F000000;
798 res = (address >> 24) ^ (netmask >> 24); 790 uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
799 if (res != 0) 791
800 local = GNUNET_NO; 792 res = (address >> 24) ^ (netmask >> 24);
801 else 793 if (res != 0)
802 local = GNUNET_YES; 794 local = GNUNET_NO;
795 else
796 local = GNUNET_YES;
803#if DEBUG_HTTP 797#if DEBUG_HTTP
804 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
805 "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); 799 "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen),
800 (local == GNUNET_YES) ? "local" : "global");
806#endif 801#endif
807 break; 802 break;
808 } 803 }
809 case AF_INET6: 804 case AF_INET6:
810 { 805 {
811 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) || 806 if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
812 IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) 807 IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
813 local = GNUNET_YES; 808 local = GNUNET_YES;
814 else 809 else
815 local = GNUNET_NO; 810 local = GNUNET_NO;
816#if DEBUG_HTTP 811#if DEBUG_HTTP
817 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
818 "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); 813 "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen),
814 (local == GNUNET_YES) ? "local" : "global");
819#endif 815#endif
820 break; 816 break;
821 } 817 }
822 } 818 }
823 return local; 819 return local;
824} 820}
825 821
826 822
@@ -842,99 +838,103 @@ process_interfaces (void *cls,
842 const struct sockaddr *addr, socklen_t addrlen) 838 const struct sockaddr *addr, socklen_t addrlen)
843{ 839{
844 struct Plugin *plugin = cls; 840 struct Plugin *plugin = cls;
845 struct IPv4HttpAddress * t4; 841 struct IPv4HttpAddress *t4;
846 struct IPv6HttpAddress * t6; 842 struct IPv6HttpAddress *t6;
847 int af; 843 int af;
848 844
849 if (plugin->use_localaddresses == GNUNET_NO) 845 if (plugin->use_localaddresses == GNUNET_NO)
850 { 846 {
851 if (GNUNET_YES == check_localaddress (addr, addrlen)) 847 if (GNUNET_YES == check_localaddress (addr, addrlen))
852 { 848 {
853#if DEBUG_HTTP 849#if DEBUG_HTTP
854 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 850 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
855 PROTOCOL_PREFIX, 851 PROTOCOL_PREFIX,
856 "Not notifying transport of address `%s' (local address)\n", 852 "Not notifying transport of address `%s' (local address)\n",
857 GNUNET_a2s (addr, addrlen)); 853 GNUNET_a2s (addr, addrlen));
858#endif 854#endif
859 return GNUNET_OK; 855 return GNUNET_OK;
860 } 856 }
861 } 857 }
862 858
863 859
864 GNUNET_assert(cls !=NULL); 860 GNUNET_assert (cls != NULL);
865 af = addr->sa_family; 861 af = addr->sa_family;
866 if ((af == AF_INET) && 862 if ((af == AF_INET) &&
867 (plugin->use_ipv4 == GNUNET_YES) && 863 (plugin->use_ipv4 == GNUNET_YES) && (plugin->bind6_address == NULL))
868 (plugin->bind6_address == NULL) ) { 864 {
869 865
870 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr; 866 struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
871 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
872 // Not skipping loopback addresses
873 867
868 t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
869 // Not skipping loopback addresses
874 870
875 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 871
876 t4->port = htons (plugin->port_inbound); 872 t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
877 if (plugin->bind4_address != NULL) { 873 t4->port = htons (plugin->port_inbound);
878 if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) 874 if (plugin->bind4_address != NULL)
879 { 875 {
880 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, 876 if (0 ==
881 plugin->ipv4_addr_tail,t4); 877 memcmp (&plugin->bind4_address->sin_addr, &bnd_cmp,
882 plugin->env->notify_address(plugin->env->cls, 878 sizeof (struct in_addr)))
883 GNUNET_YES, 879 {
884 t4, sizeof (struct IPv4HttpAddress)); 880 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
885 return GNUNET_OK; 881 plugin->ipv4_addr_tail, t4);
886 } 882 plugin->env->notify_address (plugin->env->cls,
887 GNUNET_free (t4); 883 GNUNET_YES,
888 return GNUNET_OK; 884 t4, sizeof (struct IPv4HttpAddress));
885 return GNUNET_OK;
889 } 886 }
890 else 887 GNUNET_free (t4);
891 { 888 return GNUNET_OK;
892 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, 889 }
893 plugin->ipv4_addr_tail, 890 else
894 t4); 891 {
895 plugin->env->notify_address(plugin->env->cls, 892 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
896 GNUNET_YES, 893 plugin->ipv4_addr_tail, t4);
897 t4, sizeof (struct IPv4HttpAddress)); 894 plugin->env->notify_address (plugin->env->cls,
898 return GNUNET_OK; 895 GNUNET_YES,
899 } 896 t4, sizeof (struct IPv4HttpAddress));
900 } 897 return GNUNET_OK;
901 if ((af == AF_INET6) && 898 }
902 (plugin->use_ipv6 == GNUNET_YES) && 899 }
903 (plugin->bind4_address == NULL) ) { 900 if ((af == AF_INET6) &&
904 901 (plugin->use_ipv6 == GNUNET_YES) && (plugin->bind4_address == NULL))
905 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr; 902 {
906
907 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
908 GNUNET_assert(t6 != NULL);
909
910 if (plugin->bind6_address != NULL) {
911 if (0 == memcmp(&plugin->bind6_address->sin6_addr,
912 &bnd_cmp6,
913 sizeof (struct in6_addr))) {
914 memcpy (&t6->ipv6_addr,
915 &((struct sockaddr_in6 *) addr)->sin6_addr,
916 sizeof (struct in6_addr));
917 t6->port = htons (plugin->port_inbound);
918 plugin->env->notify_address(plugin->env->cls,
919 GNUNET_YES,
920 t6, sizeof (struct IPv6HttpAddress));
921 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,
922 plugin->ipv6_addr_tail,
923 t6);
924 return GNUNET_OK;
925 }
926 GNUNET_free (t6);
927 return GNUNET_OK;
928 }
929 memcpy (&t6->ipv6_addr,
930 &((struct sockaddr_in6 *) addr)->sin6_addr,
931 sizeof (struct in6_addr));
932 t6->port = htons (plugin->port_inbound);
933 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
934 903
935 plugin->env->notify_address(plugin->env->cls, 904 struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
936 GNUNET_YES, 905
937 t6, sizeof (struct IPv6HttpAddress)); 906 t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
907 GNUNET_assert (t6 != NULL);
908
909 if (plugin->bind6_address != NULL)
910 {
911 if (0 == memcmp (&plugin->bind6_address->sin6_addr,
912 &bnd_cmp6, sizeof (struct in6_addr)))
913 {
914 memcpy (&t6->ipv6_addr,
915 &((struct sockaddr_in6 *) addr)->sin6_addr,
916 sizeof (struct in6_addr));
917 t6->port = htons (plugin->port_inbound);
918 plugin->env->notify_address (plugin->env->cls,
919 GNUNET_YES,
920 t6, sizeof (struct IPv6HttpAddress));
921 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
922 plugin->ipv6_addr_tail, t6);
923 return GNUNET_OK;
924 }
925 GNUNET_free (t6);
926 return GNUNET_OK;
927 }
928 memcpy (&t6->ipv6_addr,
929 &((struct sockaddr_in6 *) addr)->sin6_addr,
930 sizeof (struct in6_addr));
931 t6->port = htons (plugin->port_inbound);
932 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
933 t6);
934
935 plugin->env->notify_address (plugin->env->cls,
936 GNUNET_YES,
937 t6, sizeof (struct IPv6HttpAddress));
938 } 938 }
939 return GNUNET_OK; 939 return GNUNET_OK;
940} 940}
@@ -946,69 +946,62 @@ process_interfaces (void *cls,
946 * @param fmt format string 946 * @param fmt format string
947 * @param ap list of arguments 947 * @param ap list of arguments
948 */ 948 */
949static void 949static void
950mhd_logger (void * arg, 950mhd_logger (void *arg, const char *fmt, va_list ap)
951 const char * fmt,
952 va_list ap)
953{ 951{
954 char text[1024]; 952 char text[1024];
955 953
956 vsnprintf(text, sizeof(text), fmt, ap); 954 vsnprintf (text, sizeof (text), fmt, ap);
957 va_end(ap); 955 va_end (ap);
958 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 956 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MHD: %s\n", text);
959 "MHD: %s\n",
960 text);
961} 957}
962 958
963 959
964static void 960static void
965mhd_termination_cb (void *cls, 961mhd_termination_cb (void *cls,
966 struct MHD_Connection * connection, 962 struct MHD_Connection *connection, void **httpSessionCache)
967 void **httpSessionCache)
968{ 963{
969 struct Session * ps = *httpSessionCache; 964 struct Session *ps = *httpSessionCache;
965
970 if (ps == NULL) 966 if (ps == NULL)
971 return; 967 return;
972 struct HTTP_PeerContext * pc = ps->peercontext; 968 struct HTTP_PeerContext *pc = ps->peercontext;
973 struct Plugin *plugin = cls; 969 struct Plugin *plugin = cls;
974 970
975 GNUNET_assert (cls != NULL); 971 GNUNET_assert (cls != NULL);
976 plugin->current_connections--; 972 plugin->current_connections--;
977 973
978 if (connection==ps->recv_endpoint) 974 if (connection == ps->recv_endpoint)
979 { 975 {
980#if DEBUG_CONNECTIONS 976#if DEBUG_CONNECTIONS
981 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 977 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
982 "Connection %X: inbound connection from peer `%s' was terminated\n", 978 "Connection %X: inbound connection from peer `%s' was terminated\n",
983 ps, 979 ps, GNUNET_i2s (&pc->identity));
984 GNUNET_i2s(&pc->identity));
985#endif 980#endif
986 ps->recv_active = GNUNET_NO; 981 ps->recv_active = GNUNET_NO;
987 ps->recv_connected = GNUNET_NO; 982 ps->recv_connected = GNUNET_NO;
988 ps->recv_endpoint = NULL; 983 ps->recv_endpoint = NULL;
989 } 984 }
990 if (connection==ps->send_endpoint) 985 if (connection == ps->send_endpoint)
991 { 986 {
992 ps->send_active = GNUNET_NO; 987 ps->send_active = GNUNET_NO;
993 ps->send_connected = GNUNET_NO; 988 ps->send_connected = GNUNET_NO;
994 ps->send_endpoint = NULL; 989 ps->send_endpoint = NULL;
995#if DEBUG_CONNECTIONS 990#if DEBUG_CONNECTIONS
996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 991 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
997 "Connection %X: outbound connection from peer `%s' was terminated\n", 992 "Connection %X: outbound connection from peer `%s' was terminated\n",
998 ps, 993 ps, GNUNET_i2s (&pc->identity));
999 GNUNET_i2s(&pc->identity));
1000#endif 994#endif
1001 } 995 }
1002 996
1003 /* if both connections disconnected, remove session */ 997 /* if both connections disconnected, remove session */
1004 if ( (ps->send_connected == GNUNET_NO) && 998 if ((ps->send_connected == GNUNET_NO) && (ps->recv_connected == GNUNET_NO))
1005 (ps->recv_connected == GNUNET_NO) )
1006 { 999 {
1007 GNUNET_STATISTICS_update (pc->plugin->env->stats, 1000 GNUNET_STATISTICS_update (pc->plugin->env->stats,
1008 gettext_noop ("# HTTP inbound sessions for peers active"), 1001 gettext_noop
1009 -1, 1002 ("# HTTP inbound sessions for peers active"), -1,
1010 GNUNET_NO); 1003 GNUNET_NO);
1011 remove_session(pc,ps,GNUNET_YES,GNUNET_SYSERR); 1004 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
1012 } 1005 }
1013} 1006}
1014 1007
@@ -1019,54 +1012,52 @@ mhd_termination_cb (void *cls,
1019 * @param client clien 1012 * @param client clien
1020 * @param message the message to be forwarded to transport service 1013 * @param message the message to be forwarded to transport service
1021 */ 1014 */
1022static void 1015static void
1023mhd_write_mst_cb (void *cls, 1016mhd_write_mst_cb (void *cls,
1024 void *client, 1017 void *client, const struct GNUNET_MessageHeader *message)
1025 const struct GNUNET_MessageHeader *message)
1026{ 1018{
1027 struct Session *ps = cls; 1019 struct Session *ps = cls;
1028 struct HTTP_PeerContext *pc; 1020 struct HTTP_PeerContext *pc;
1029 struct GNUNET_TIME_Relative delay; 1021 struct GNUNET_TIME_Relative delay;
1030 1022
1031 GNUNET_assert(ps != NULL); 1023 GNUNET_assert (ps != NULL);
1032 pc = ps->peercontext; 1024 pc = ps->peercontext;
1033 GNUNET_assert(pc != NULL); 1025 GNUNET_assert (pc != NULL);
1034#if DEBUG_HTTP 1026#if DEBUG_HTTP
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1027 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1036 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1028 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1037 ps, 1029 ps,
1038 ntohs(message->type), 1030 ntohs (message->type),
1039 ntohs(message->size), 1031 ntohs (message->size),
1040 GNUNET_i2s(&(ps->peercontext)->identity), 1032 GNUNET_i2s (&(ps->peercontext)->identity),
1041 http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); 1033 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1042#endif 1034#endif
1043 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1035 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1036
1044 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 1037 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1045 distance[0].value = htonl (1); 1038 distance[0].value = htonl (1);
1046 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1039 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1047 distance[1].value = htonl (0); 1040 distance[1].value = htonl (0);
1048 delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls, 1041 delay = pc->plugin->env->receive (ps->peercontext->plugin->env->cls,
1049 &pc->identity, 1042 &pc->identity,
1050 message, 1043 message,
1051 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 1044 (const struct
1052 2, 1045 GNUNET_TRANSPORT_ATS_Information *)
1053 ps, 1046 &distance, 2, ps, NULL, 0);
1054 NULL,
1055 0);
1056 pc->delay = delay; 1047 pc->delay = delay;
1057 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) 1048 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
1058 GNUNET_SCHEDULER_cancel (pc->reset_task); 1049 GNUNET_SCHEDULER_cancel (pc->reset_task);
1059 1050
1060 if (delay.rel_value > 0) 1051 if (delay.rel_value > 0)
1061 { 1052 {
1062#if DEBUG_HTTP 1053#if DEBUG_HTTP
1063 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1054 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1064 "Connection %X: Inbound quota management: delay next read for %llu ms \n", 1055 "Connection %X: Inbound quota management: delay next read for %llu ms \n",
1065 ps, 1056 ps, delay.rel_value);
1066 delay.rel_value);
1067#endif 1057#endif
1068 pc->reset_task = GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc); 1058 pc->reset_task =
1069 } 1059 GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc);
1060 }
1070} 1061}
1071 1062
1072 1063
@@ -1080,19 +1071,19 @@ mhd_write_mst_cb (void *cls,
1080 * 1071 *
1081 */ 1072 */
1082static int 1073static int
1083mhd_accept_cb (void *cls, 1074mhd_accept_cb (void *cls, const struct sockaddr *addr, socklen_t addr_len)
1084 const struct sockaddr *addr,
1085 socklen_t addr_len)
1086{ 1075{
1087 struct Plugin *plugin = cls; 1076 struct Plugin *plugin = cls;
1077
1088 GNUNET_assert (cls != NULL); 1078 GNUNET_assert (cls != NULL);
1089 1079
1090 if (plugin->max_connect_per_transport > plugin->current_connections) 1080 if (plugin->max_connect_per_transport > plugin->current_connections)
1091 { 1081 {
1092 plugin->current_connections ++; 1082 plugin->current_connections++;
1093 return MHD_YES; 1083 return MHD_YES;
1094 } 1084 }
1095 else return MHD_NO; 1085 else
1086 return MHD_NO;
1096} 1087}
1097 1088
1098 1089
@@ -1107,55 +1098,52 @@ mhd_accept_cb (void *cls,
1107static ssize_t 1098static ssize_t
1108mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max) 1099mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1109{ 1100{
1110 struct Session * ps = cls; 1101 struct Session *ps = cls;
1111 struct HTTP_PeerContext * pc; 1102 struct HTTP_PeerContext *pc;
1112 struct HTTP_Message * msg; 1103 struct HTTP_Message *msg;
1113 int bytes_read = 0; 1104 int bytes_read = 0;
1114 1105
1115 GNUNET_assert (ps!=NULL); 1106 GNUNET_assert (ps != NULL);
1116 1107
1117 pc = ps->peercontext; 1108 pc = ps->peercontext;
1118 msg = ps->pending_msgs_tail; 1109 msg = ps->pending_msgs_tail;
1119 if (ps->send_force_disconnect==GNUNET_YES) 1110 if (ps->send_force_disconnect == GNUNET_YES)
1120 { 1111 {
1121#if DEBUG_CONNECTIONS 1112#if DEBUG_CONNECTIONS
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "Connection %X: outbound forced to disconnect\n", 1114 "Connection %X: outbound forced to disconnect\n", ps);
1124 ps);
1125#endif 1115#endif
1126 return -1; 1116 return -1;
1117 }
1118
1119 if (msg != NULL)
1120 {
1121 /* sending */
1122 if ((msg->size - msg->pos) <= max)
1123 {
1124 memcpy (buf, &msg->buf[msg->pos], (msg->size - msg->pos));
1125 bytes_read = msg->size - msg->pos;
1126 msg->pos += (msg->size - msg->pos);
1127 } 1127 }
1128 1128 else
1129 if (msg!=NULL)
1130 { 1129 {
1131 /* sending */ 1130 memcpy (buf, &msg->buf[msg->pos], max);
1132 if ((msg->size-msg->pos) <= max) 1131 msg->pos += max;
1133 { 1132 bytes_read = max;
1134 memcpy(buf,&msg->buf[msg->pos],(msg->size-msg->pos));
1135 bytes_read = msg->size-msg->pos;
1136 msg->pos+=(msg->size-msg->pos);
1137 }
1138 else
1139 {
1140 memcpy(buf,&msg->buf[msg->pos],max);
1141 msg->pos+=max;
1142 bytes_read = max;
1143 }
1144
1145 /* removing message */
1146 if (msg->pos==msg->size)
1147 {
1148 if (NULL!=msg->transmit_cont)
1149 msg->transmit_cont (msg->transmit_cont_cls,&pc->identity,GNUNET_OK);
1150 ps->queue_length_cur -= msg->size;
1151 remove_http_message(ps,msg);
1152 }
1153 } 1133 }
1134
1135 /* removing message */
1136 if (msg->pos == msg->size)
1137 {
1138 if (NULL != msg->transmit_cont)
1139 msg->transmit_cont (msg->transmit_cont_cls, &pc->identity, GNUNET_OK);
1140 ps->queue_length_cur -= msg->size;
1141 remove_http_message (ps, msg);
1142 }
1143 }
1154#if DEBUG_CONNECTIONS 1144#if DEBUG_CONNECTIONS
1155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1156 "Connection %X: MHD has sent %u bytes\n", 1146 "Connection %X: MHD has sent %u bytes\n", ps, bytes_read);
1157 ps,
1158 bytes_read);
1159#endif 1147#endif
1160 return bytes_read; 1148 return bytes_read;
1161} 1149}
@@ -1170,21 +1158,20 @@ mhd_send_callback (void *cls, uint64_t pos, char *buf, size_t max)
1170 */ 1158 */
1171static int 1159static int
1172mhd_access_cb (void *cls, 1160mhd_access_cb (void *cls,
1173 struct MHD_Connection *mhd_connection, 1161 struct MHD_Connection *mhd_connection,
1174 const char *url, 1162 const char *url,
1175 const char *method, 1163 const char *method,
1176 const char *version, 1164 const char *version,
1177 const char *upload_data, 1165 const char *upload_data,
1178 size_t * upload_data_size, 1166 size_t * upload_data_size, void **httpSessionCache)
1179 void **httpSessionCache)
1180{ 1167{
1181 struct Plugin *plugin = cls; 1168 struct Plugin *plugin = cls;
1182 struct MHD_Response *response; 1169 struct MHD_Response *response;
1183 const union MHD_ConnectionInfo * conn_info; 1170 const union MHD_ConnectionInfo *conn_info;
1184 const struct sockaddr *client_addr; 1171 const struct sockaddr *client_addr;
1185 const struct sockaddr_in *addrin; 1172 const struct sockaddr_in *addrin;
1186 const struct sockaddr_in6 *addrin6; 1173 const struct sockaddr_in6 *addrin6;
1187 char address[INET6_ADDRSTRLEN+14]; 1174 char address[INET6_ADDRSTRLEN + 14];
1188 struct GNUNET_PeerIdentity pi_in; 1175 struct GNUNET_PeerIdentity pi_in;
1189 size_t id_num = 0; 1176 size_t id_num = 0;
1190 struct IPv4HttpAddress ipv4addr; 1177 struct IPv4HttpAddress ipv4addr;
@@ -1193,251 +1180,259 @@ mhd_access_cb (void *cls,
1193 struct Session *ps = NULL; 1180 struct Session *ps = NULL;
1194 struct Session *ps_tmp = NULL; 1181 struct Session *ps_tmp = NULL;
1195 int res = GNUNET_NO; 1182 int res = GNUNET_NO;
1196 void * addr = NULL; 1183 void *addr = NULL;
1197 size_t addr_len = 0 ; 1184 size_t addr_len = 0;
1198 1185
1199 GNUNET_assert(cls !=NULL); 1186 GNUNET_assert (cls != NULL);
1200 1187
1201 if (NULL == *httpSessionCache) 1188 if (NULL == *httpSessionCache)
1189 {
1190 /* check url for peer identity , if invalid send HTTP 404 */
1191 size_t len = strlen (&url[1]);
1192 char *peer = GNUNET_malloc (104 + 1);
1193
1194 if ((len > 104) && (url[104] == ';'))
1202 { 1195 {
1203 /* check url for peer identity , if invalid send HTTP 404*/ 1196 char *id = GNUNET_malloc ((len - 104) + 1);
1204 size_t len = strlen(&url[1]); 1197
1205 char * peer = GNUNET_malloc(104+1); 1198 strcpy (id, &url[105]);
1206 1199 memcpy (peer, &url[1], 103);
1207 if ( (len>104) && (url[104]==';')) 1200 peer[103] = '\0';
1208 { 1201 id_num = strtoul (id, NULL, 10);
1209 char * id = GNUNET_malloc((len-104)+1); 1202 GNUNET_free (id);
1210 strcpy(id,&url[105]);
1211 memcpy(peer,&url[1],103);
1212 peer[103] = '\0';
1213 id_num = strtoul ( id, NULL , 10);
1214 GNUNET_free(id);
1215 } 1203 }
1216 res = GNUNET_CRYPTO_hash_from_string (peer, &(pi_in.hashPubKey)); 1204 res = GNUNET_CRYPTO_hash_from_string (peer, &(pi_in.hashPubKey));
1217 GNUNET_free(peer); 1205 GNUNET_free (peer);
1218 if ( GNUNET_SYSERR == res ) 1206 if (GNUNET_SYSERR == res)
1219 { 1207 {
1220 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE), 1208 response = MHD_create_response_from_data (strlen (HTTP_ERROR_RESPONSE),
1221 HTTP_ERROR_RESPONSE, 1209 HTTP_ERROR_RESPONSE,
1222 MHD_NO, MHD_NO); 1210 MHD_NO, MHD_NO);
1223 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response); 1211 res = MHD_queue_response (mhd_connection, MHD_HTTP_NOT_FOUND, response);
1224 MHD_destroy_response (response); 1212 MHD_destroy_response (response);
1225#if DEBUG_CONNECTIONS 1213#if DEBUG_CONNECTIONS
1226 if (res == MHD_YES) 1214 if (res == MHD_YES)
1227 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1228 "Peer has no valid ident, sent HTTP 1.1/404\n"); 1216 "Peer has no valid ident, sent HTTP 1.1/404\n");
1229 else 1217 else
1230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1231 "Peer has no valid ident, could not send error\n"); 1219 "Peer has no valid ident, could not send error\n");
1232#endif 1220#endif
1233 return res; 1221 return res;
1234 }
1235 } 1222 }
1223 }
1236 else 1224 else
1225 {
1226 ps = *httpSessionCache;
1227 pc = ps->peercontext;
1228 }
1229
1230 if (NULL == *httpSessionCache)
1231 {
1232 /* get peer context */
1233 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &pi_in.hashPubKey);
1234 /* Peer unknown */
1235 if (pc == NULL)
1237 { 1236 {
1238 ps = *httpSessionCache; 1237 pc = GNUNET_malloc (sizeof (struct HTTP_PeerContext));
1239 pc = ps->peercontext; 1238 pc->plugin = plugin;
1239 pc->session_id_counter = 1;
1240 pc->last_session = NULL;
1241 memcpy (&pc->identity, &pi_in, sizeof (struct GNUNET_PeerIdentity));
1242 GNUNET_CONTAINER_multihashmap_put (plugin->peers,
1243 &pc->identity.hashPubKey,
1244 pc,
1245 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
1246 GNUNET_STATISTICS_update (plugin->env->stats,
1247 gettext_noop ("# HTTP peers active"),
1248 1, GNUNET_NO);
1249 }
1250
1251 conn_info =
1252 MHD_get_connection_info (mhd_connection,
1253 MHD_CONNECTION_INFO_CLIENT_ADDRESS);
1254 /* Incoming IPv4 connection */
1255 /* cast required for legacy MHD API < 0.9.6 */
1256 client_addr = (const struct sockaddr *) conn_info->client_addr;
1257 if (AF_INET == client_addr->sa_family)
1258 {
1259 addrin = (const struct sockaddr_in *) client_addr;
1260 inet_ntop (addrin->sin_family, &(addrin->sin_addr), address,
1261 INET_ADDRSTRLEN);
1262 memcpy (&ipv4addr.ipv4_addr, &(addrin->sin_addr),
1263 sizeof (struct in_addr));
1264 ipv4addr.port = addrin->sin_port;
1265 addr = &ipv4addr;
1266 addr_len = sizeof (struct IPv4HttpAddress);
1267 }
1268 /* Incoming IPv6 connection */
1269 if (AF_INET6 == client_addr->sa_family)
1270 {
1271 addrin6 = (const struct sockaddr_in6 *) client_addr;
1272 inet_ntop (addrin6->sin6_family, &(addrin6->sin6_addr), address,
1273 INET6_ADDRSTRLEN);
1274 memcpy (&ipv6addr.ipv6_addr, &(addrin6->sin6_addr),
1275 sizeof (struct in6_addr));
1276 ipv6addr.port = addrin6->sin6_port;
1277 addr = &ipv6addr;
1278 addr_len = sizeof (struct IPv6HttpAddress);
1240 } 1279 }
1241 1280
1242 if (NULL == *httpSessionCache) 1281 GNUNET_assert (addr != NULL);
1282 GNUNET_assert (addr_len != 0);
1283
1284 ps = NULL;
1285 /* only inbound sessions here */
1286
1287 ps_tmp = pc->head;
1288 while (ps_tmp != NULL)
1243 { 1289 {
1244 /* get peer context */ 1290 if ((ps_tmp->direction == INBOUND) && (ps_tmp->session_id == id_num) &&
1245 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &pi_in.hashPubKey); 1291 (id_num != 0))
1246 /* Peer unknown */ 1292 {
1247 if (pc==NULL) 1293 if ((ps_tmp->recv_force_disconnect != GNUNET_YES) &&
1248 { 1294 (ps_tmp->send_force_disconnect != GNUNET_YES))
1249 pc = GNUNET_malloc(sizeof (struct HTTP_PeerContext)); 1295 ps = ps_tmp;
1250 pc->plugin = plugin; 1296 break;
1251 pc->session_id_counter=1; 1297 }
1252 pc->last_session = NULL; 1298 ps_tmp = ps_tmp->next;
1253 memcpy(&pc->identity, &pi_in, sizeof(struct GNUNET_PeerIdentity)); 1299 }
1254 GNUNET_CONTAINER_multihashmap_put(plugin->peers, 1300
1255 &pc->identity.hashPubKey, 1301 if (ps == NULL)
1256 pc, 1302 {
1257 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 1303 ps = GNUNET_malloc (sizeof (struct Session));
1258 GNUNET_STATISTICS_update (plugin->env->stats, 1304 ps->addr = GNUNET_malloc (addr_len);
1259 gettext_noop ("# HTTP peers active"), 1305 memcpy (ps->addr, addr, addr_len);
1260 1, 1306 ps->addrlen = addr_len;
1261 GNUNET_NO); 1307 ps->direction = INBOUND;
1262 } 1308 ps->pending_msgs_head = NULL;
1263 1309 ps->pending_msgs_tail = NULL;
1264 conn_info = MHD_get_connection_info(mhd_connection, MHD_CONNECTION_INFO_CLIENT_ADDRESS ); 1310 ps->send_connected = GNUNET_NO;
1265 /* Incoming IPv4 connection */ 1311 ps->send_active = GNUNET_NO;
1266 /* cast required for legacy MHD API < 0.9.6 */ 1312 ps->recv_connected = GNUNET_NO;
1267 client_addr = (const struct sockaddr *) conn_info->client_addr; 1313 ps->recv_active = GNUNET_NO;
1268 if ( AF_INET == client_addr->sa_family) 1314 ps->peercontext = pc;
1269 { 1315 ps->session_id = id_num;
1270 addrin = (const struct sockaddr_in*) client_addr; 1316 ps->queue_length_cur = 0;
1271 inet_ntop(addrin->sin_family, &(addrin->sin_addr),address,INET_ADDRSTRLEN); 1317 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
1272 memcpy(&ipv4addr.ipv4_addr,&(addrin->sin_addr),sizeof(struct in_addr)); 1318 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
1273 ipv4addr.port = addrin->sin_port; 1319 GNUNET_CONTAINER_DLL_insert (pc->head, pc->tail, ps);
1274 addr = &ipv4addr; 1320 GNUNET_STATISTICS_update (plugin->env->stats,
1275 addr_len = sizeof(struct IPv4HttpAddress); 1321 gettext_noop
1276 } 1322 ("# HTTP inbound sessions for peers active"), 1,
1277 /* Incoming IPv6 connection */ 1323 GNUNET_NO);
1278 if ( AF_INET6 == client_addr->sa_family) 1324 }
1279 { 1325
1280 addrin6 = (const struct sockaddr_in6 *) client_addr; 1326 *httpSessionCache = ps;
1281 inet_ntop(addrin6->sin6_family, &(addrin6->sin6_addr),address,INET6_ADDRSTRLEN); 1327 if (ps->msgtok == NULL)
1282 memcpy(&ipv6addr.ipv6_addr,&(addrin6->sin6_addr),sizeof(struct in6_addr)); 1328 ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
1283 ipv6addr.port = addrin6->sin6_port;
1284 addr = &ipv6addr;
1285 addr_len = sizeof(struct IPv6HttpAddress);
1286 }
1287
1288 GNUNET_assert (addr != NULL);
1289 GNUNET_assert (addr_len != 0);
1290
1291 ps = NULL;
1292 /* only inbound sessions here */
1293
1294 ps_tmp = pc->head;
1295 while (ps_tmp!=NULL)
1296 {
1297 if ((ps_tmp->direction==INBOUND) && (ps_tmp->session_id == id_num) && (id_num!=0))
1298 {
1299 if ((ps_tmp->recv_force_disconnect!=GNUNET_YES) && (ps_tmp->send_force_disconnect!=GNUNET_YES))
1300 ps=ps_tmp;
1301 break;
1302 }
1303 ps_tmp=ps_tmp->next;
1304 }
1305
1306 if (ps==NULL)
1307 {
1308 ps = GNUNET_malloc(sizeof (struct Session));
1309 ps->addr = GNUNET_malloc(addr_len);
1310 memcpy(ps->addr,addr,addr_len);
1311 ps->addrlen = addr_len;
1312 ps->direction=INBOUND;
1313 ps->pending_msgs_head = NULL;
1314 ps->pending_msgs_tail = NULL;
1315 ps->send_connected=GNUNET_NO;
1316 ps->send_active=GNUNET_NO;
1317 ps->recv_connected=GNUNET_NO;
1318 ps->recv_active=GNUNET_NO;
1319 ps->peercontext=pc;
1320 ps->session_id =id_num;
1321 ps->queue_length_cur = 0;
1322 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
1323 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
1324 GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
1325 GNUNET_STATISTICS_update (plugin->env->stats,
1326 gettext_noop ("# HTTP inbound sessions for peers active"),
1327 1,
1328 GNUNET_NO);
1329 }
1330
1331 *httpSessionCache = ps;
1332 if (ps->msgtok==NULL)
1333 ps->msgtok = GNUNET_SERVER_mst_create (&mhd_write_mst_cb, ps);
1334#if DEBUG_HTTP 1329#if DEBUG_HTTP
1335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1336 "Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n", 1331 "Connection %X: HTTP Daemon has new an incoming `%s' request from peer `%s' (`%s')\n",
1337 ps, 1332 ps,
1338 method, 1333 method,
1339 GNUNET_i2s(&pc->identity), 1334 GNUNET_i2s (&pc->identity),
1340 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen)); 1335 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1341#endif 1336#endif
1342 } 1337 }
1343 1338
1344 /* Is it a PUT or a GET request */ 1339 /* Is it a PUT or a GET request */
1345 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method)) 1340 if (0 == strcmp (MHD_HTTP_METHOD_PUT, method))
1341 {
1342 if (ps->recv_force_disconnect == GNUNET_YES)
1346 { 1343 {
1347 if (ps->recv_force_disconnect == GNUNET_YES)
1348 {
1349#if DEBUG_CONNECTIONS
1350 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1351 "Connection %X: inbound connection was forced to disconnect\n",ps);
1352#endif
1353 ps->recv_active = GNUNET_NO;
1354 return MHD_NO;
1355 }
1356 if ((*upload_data_size == 0) && (ps->recv_active==GNUNET_NO))
1357 {
1358 ps->recv_endpoint = mhd_connection;
1359 ps->recv_connected = GNUNET_YES;
1360 ps->recv_active = GNUNET_YES;
1361 ps->recv_force_disconnect = GNUNET_NO;
1362#if DEBUG_CONNECTIONS
1363 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1364 "Connection %X: inbound PUT connection connected\n",ps);
1365#endif
1366 return MHD_YES;
1367 }
1368
1369 /* Transmission of all data complete */
1370 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
1371 {
1372 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
1373 HTTP_PUT_RESPONSE,
1374 MHD_NO, MHD_NO);
1375 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1376#if DEBUG_CONNECTIONS 1344#if DEBUG_CONNECTIONS
1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1378 "Connection %X: Sent HTTP/1.1: 200 OK as PUT Response\n", 1346 "Connection %X: inbound connection was forced to disconnect\n",
1379 ps); 1347 ps);
1380#endif 1348#endif
1381 MHD_destroy_response (response); 1349 ps->recv_active = GNUNET_NO;
1382 ps->recv_active=GNUNET_NO; 1350 return MHD_NO;
1383 return MHD_YES;
1384 }
1385
1386 /* Recieving data */
1387 if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES))
1388 {
1389 if (pc->delay.rel_value == 0)
1390 {
1391#if DEBUG_HTTP
1392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1393 "Connection %X: PUT with %u bytes forwarded to MST\n",
1394 ps, *upload_data_size);
1395#endif
1396 res = GNUNET_SERVER_mst_receive(ps->msgtok, ps,
1397 upload_data, *upload_data_size,
1398 GNUNET_NO, GNUNET_NO);
1399 (*upload_data_size) = 0;
1400 }
1401 else
1402 {
1403#if DEBUG_HTTP
1404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1405 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n",
1406 ps,
1407 ps->peercontext->delay.rel_value);
1408#endif
1409 }
1410 return MHD_YES;
1411 }
1412 else
1413 return MHD_NO;
1414 } 1351 }
1415 if ( 0 == strcmp (MHD_HTTP_METHOD_GET, method) ) 1352 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_NO))
1416 { 1353 {
1417 if (ps->send_force_disconnect == GNUNET_YES) 1354 ps->recv_endpoint = mhd_connection;
1418 { 1355 ps->recv_connected = GNUNET_YES;
1356 ps->recv_active = GNUNET_YES;
1357 ps->recv_force_disconnect = GNUNET_NO;
1419#if DEBUG_CONNECTIONS 1358#if DEBUG_CONNECTIONS
1420 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1421 "Connection %X: outbound connection was forced to disconnect\n", 1360 "Connection %X: inbound PUT connection connected\n", ps);
1422 ps);
1423#endif 1361#endif
1424 ps->send_active = GNUNET_NO; 1362 return MHD_YES;
1425 return MHD_NO; 1363 }
1426 } 1364
1427 ps->send_connected = GNUNET_YES; 1365 /* Transmission of all data complete */
1428 ps->send_active = GNUNET_YES; 1366 if ((*upload_data_size == 0) && (ps->recv_active == GNUNET_YES))
1429 ps->send_endpoint = mhd_connection; 1367 {
1430 ps->send_force_disconnect = GNUNET_NO; 1368 response = MHD_create_response_from_data (strlen (HTTP_PUT_RESPONSE),
1369 HTTP_PUT_RESPONSE,
1370 MHD_NO, MHD_NO);
1371 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1431#if DEBUG_CONNECTIONS 1372#if DEBUG_CONNECTIONS
1432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1433 "Connection %X: inbound GET connection connected\n", 1374 "Connection %X: Sent HTTP/1.1: 200 OK as PUT Response\n", ps);
1434 ps);
1435#endif 1375#endif
1436 response = MHD_create_response_from_callback(-1,32 * 1024, &mhd_send_callback, ps, NULL);
1437 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1438 MHD_destroy_response (response); 1376 MHD_destroy_response (response);
1377 ps->recv_active = GNUNET_NO;
1439 return MHD_YES; 1378 return MHD_YES;
1440 } 1379 }
1380
1381 /* Recieving data */
1382 if ((*upload_data_size > 0) && (ps->recv_active == GNUNET_YES))
1383 {
1384 if (pc->delay.rel_value == 0)
1385 {
1386#if DEBUG_HTTP
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Connection %X: PUT with %u bytes forwarded to MST\n",
1389 ps, *upload_data_size);
1390#endif
1391 res = GNUNET_SERVER_mst_receive (ps->msgtok, ps,
1392 upload_data, *upload_data_size,
1393 GNUNET_NO, GNUNET_NO);
1394 (*upload_data_size) = 0;
1395 }
1396 else
1397 {
1398#if DEBUG_HTTP
1399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1400 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n",
1401 ps, ps->peercontext->delay.rel_value);
1402#endif
1403 }
1404 return MHD_YES;
1405 }
1406 else
1407 return MHD_NO;
1408 }
1409 if (0 == strcmp (MHD_HTTP_METHOD_GET, method))
1410 {
1411 if (ps->send_force_disconnect == GNUNET_YES)
1412 {
1413#if DEBUG_CONNECTIONS
1414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1415 "Connection %X: outbound connection was forced to disconnect\n",
1416 ps);
1417#endif
1418 ps->send_active = GNUNET_NO;
1419 return MHD_NO;
1420 }
1421 ps->send_connected = GNUNET_YES;
1422 ps->send_active = GNUNET_YES;
1423 ps->send_endpoint = mhd_connection;
1424 ps->send_force_disconnect = GNUNET_NO;
1425#if DEBUG_CONNECTIONS
1426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1427 "Connection %X: inbound GET connection connected\n", ps);
1428#endif
1429 response =
1430 MHD_create_response_from_callback (-1, 32 * 1024, &mhd_send_callback,
1431 ps, NULL);
1432 res = MHD_queue_response (mhd_connection, MHD_HTTP_OK, response);
1433 MHD_destroy_response (response);
1434 return MHD_YES;
1435 }
1441 return MHD_NO; 1436 return MHD_NO;
1442} 1437}
1443 1438
@@ -1451,7 +1446,7 @@ mhd_access_cb (void *cls,
1451 */ 1446 */
1452static GNUNET_SCHEDULER_TaskIdentifier 1447static GNUNET_SCHEDULER_TaskIdentifier
1453http_server_daemon_prepare (struct Plugin *plugin, 1448http_server_daemon_prepare (struct Plugin *plugin,
1454 struct MHD_Daemon *daemon_handle) 1449 struct MHD_Daemon *daemon_handle)
1455{ 1450{
1456 GNUNET_SCHEDULER_TaskIdentifier ret; 1451 GNUNET_SCHEDULER_TaskIdentifier ret;
1457 fd_set rs; 1452 fd_set rs;
@@ -1466,19 +1461,14 @@ http_server_daemon_prepare (struct Plugin *plugin,
1466 struct GNUNET_TIME_Relative tv; 1461 struct GNUNET_TIME_Relative tv;
1467 1462
1468 ret = GNUNET_SCHEDULER_NO_TASK; 1463 ret = GNUNET_SCHEDULER_NO_TASK;
1469 FD_ZERO(&rs); 1464 FD_ZERO (&rs);
1470 FD_ZERO(&ws); 1465 FD_ZERO (&ws);
1471 FD_ZERO(&es); 1466 FD_ZERO (&es);
1472 wrs = GNUNET_NETWORK_fdset_create (); 1467 wrs = GNUNET_NETWORK_fdset_create ();
1473 wes = GNUNET_NETWORK_fdset_create (); 1468 wes = GNUNET_NETWORK_fdset_create ();
1474 wws = GNUNET_NETWORK_fdset_create (); 1469 wws = GNUNET_NETWORK_fdset_create ();
1475 max = -1; 1470 max = -1;
1476 GNUNET_assert (MHD_YES == 1471 GNUNET_assert (MHD_YES == MHD_get_fdset (daemon_handle, &rs, &ws, &es, &max));
1477 MHD_get_fdset (daemon_handle,
1478 &rs,
1479 &ws,
1480 &es,
1481 &max));
1482 haveto = MHD_get_timeout (daemon_handle, &timeout); 1472 haveto = MHD_get_timeout (daemon_handle, &timeout);
1483 if (haveto == MHD_YES) 1473 if (haveto == MHD_YES)
1484 tv.rel_value = (uint64_t) timeout; 1474 tv.rel_value = (uint64_t) timeout;
@@ -1488,37 +1478,33 @@ http_server_daemon_prepare (struct Plugin *plugin,
1488 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1); 1478 GNUNET_NETWORK_fdset_copy_native (wws, &ws, max + 1);
1489 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1); 1479 GNUNET_NETWORK_fdset_copy_native (wes, &es, max + 1);
1490 if (daemon_handle == plugin->http_server_daemon_v4) 1480 if (daemon_handle == plugin->http_server_daemon_v4)
1481 {
1482 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
1491 { 1483 {
1492 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 1484 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v4);
1493 { 1485 plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
1494 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v4);
1495 plugin->http_server_daemon_v4 = GNUNET_SCHEDULER_NO_TASK;
1496 }
1497
1498 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1499 GNUNET_SCHEDULER_NO_TASK,
1500 tv,
1501 wrs,
1502 wws,
1503 &http_server_daemon_v4_run,
1504 plugin);
1505 } 1486 }
1487
1488 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1489 GNUNET_SCHEDULER_NO_TASK,
1490 tv,
1491 wrs,
1492 wws, &http_server_daemon_v4_run, plugin);
1493 }
1506 if (daemon_handle == plugin->http_server_daemon_v6) 1494 if (daemon_handle == plugin->http_server_daemon_v6)
1495 {
1496 if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
1507 { 1497 {
1508 if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) 1498 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v6);
1509 { 1499 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1510 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v6);
1511 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1512 }
1513
1514 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1515 GNUNET_SCHEDULER_NO_TASK,
1516 tv,
1517 wrs,
1518 wws,
1519 &http_server_daemon_v6_run,
1520 plugin);
1521 } 1500 }
1501
1502 ret = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1503 GNUNET_SCHEDULER_NO_TASK,
1504 tv,
1505 wrs,
1506 wws, &http_server_daemon_v6_run, plugin);
1507 }
1522 GNUNET_NETWORK_fdset_destroy (wrs); 1508 GNUNET_NETWORK_fdset_destroy (wrs);
1523 GNUNET_NETWORK_fdset_destroy (wws); 1509 GNUNET_NETWORK_fdset_destroy (wws);
1524 GNUNET_NETWORK_fdset_destroy (wes); 1510 GNUNET_NETWORK_fdset_destroy (wes);
@@ -1532,39 +1518,40 @@ http_server_daemon_prepare (struct Plugin *plugin,
1532 * @param cls plugin as closure 1518 * @param cls plugin as closure
1533 * @param tc task context 1519 * @param tc task context
1534 */ 1520 */
1535static void 1521static void
1536http_server_daemon_v4_run (void *cls, 1522http_server_daemon_v4_run (void *cls,
1537 const struct GNUNET_SCHEDULER_TaskContext *tc) 1523 const struct GNUNET_SCHEDULER_TaskContext *tc)
1538{ 1524{
1539 struct Plugin *plugin = cls; 1525 struct Plugin *plugin = cls;
1540 1526
1541#if DEBUG_SCHEDULING 1527#if DEBUG_SCHEDULING
1542 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1528 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1544 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_READ_READY\n"); 1530 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_READ_READY\n");
1545 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1531 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n"); 1533 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n");
1548 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1534 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1549 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1535 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1550 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n"); 1536 "http_server_daemon_v4_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n");
1551 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP)) 1537 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
1552 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1553 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_STARTUP\n"); 1539 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_STARTUP\n");
1554 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1540 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1555 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1556 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n"); 1542 "http_server_daemon_v4_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
1557#endif 1543#endif
1558 1544
1559 GNUNET_assert(cls !=NULL); 1545 GNUNET_assert (cls != NULL);
1560 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK; 1546 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
1561 1547
1562 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1548 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1563 return; 1549 return;
1564 1550
1565 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v4)); 1551 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v4));
1566 plugin->http_server_task_v4 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4); 1552 plugin->http_server_task_v4 =
1567 } 1553 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4);
1554}
1568 1555
1569 1556
1570/** 1557/**
@@ -1573,92 +1560,95 @@ http_server_daemon_v4_run (void *cls,
1573 * @param cls plugin as closure 1560 * @param cls plugin as closure
1574 * @param tc task context 1561 * @param tc task context
1575 */ 1562 */
1576static void 1563static void
1577http_server_daemon_v6_run (void *cls, 1564http_server_daemon_v6_run (void *cls,
1578 const struct GNUNET_SCHEDULER_TaskContext *tc) 1565 const struct GNUNET_SCHEDULER_TaskContext *tc)
1579{ 1566{
1580 struct Plugin *plugin = cls; 1567 struct Plugin *plugin = cls;
1581 1568
1582#if DEBUG_SCHEDULING 1569#if DEBUG_SCHEDULING
1583 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) 1570 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1585 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_READ_READY\n"); 1572 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_READ_READY\n");
1586 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) 1573 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY))
1587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1588 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n"); 1575 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_WRITE_READY\n");
1589 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1576 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1590 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1591 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n"); 1578 "http_server_daemon_v6_run: GNUNET_SCHEDULER_REASON_TIMEOUT\n");
1592 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP)) 1579 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_STARTUP))
1593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1594 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_STARTUP\n"); 1581 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_STARTUP\n");
1595 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1582 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1597 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n"); 1584 "http_server_daemon_v6_run: GGNUNET_SCHEDULER_REASON_SHUTDOWN\n");
1598#endif 1585#endif
1599 1586
1600 GNUNET_assert(cls !=NULL); 1587 GNUNET_assert (cls != NULL);
1601 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; 1588 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
1602 1589
1603 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1590 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1604 return; 1591 return;
1605 1592
1606 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v6)); 1593 GNUNET_assert (MHD_YES == MHD_run (plugin->http_server_daemon_v6));
1607 plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); 1594 plugin->http_server_task_v6 =
1595 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
1608} 1596}
1609 1597
1610 1598
1611static size_t 1599static size_t
1612curl_get_header_cb( void *ptr, 1600curl_get_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
1613 size_t size, size_t nmemb,
1614 void *stream)
1615{ 1601{
1616 struct Session * ps = stream; 1602 struct Session *ps = stream;
1617 1603
1618 long http_result = 0; 1604 long http_result = 0;
1619 int res; 1605 int res;
1606
1620 /* Getting last http result code */ 1607 /* Getting last http result code */
1621 GNUNET_assert(NULL!=ps); 1608 GNUNET_assert (NULL != ps);
1622 if (ps->recv_connected==GNUNET_NO) 1609 if (ps->recv_connected == GNUNET_NO)
1610 {
1611 res =
1612 curl_easy_getinfo (ps->recv_endpoint, CURLINFO_RESPONSE_CODE,
1613 &http_result);
1614 if (CURLE_OK == res)
1623 { 1615 {
1624 res = curl_easy_getinfo(ps->recv_endpoint, CURLINFO_RESPONSE_CODE, &http_result); 1616 if (http_result == 200)
1625 if (CURLE_OK == res) 1617 {
1626 { 1618 ps->recv_connected = GNUNET_YES;
1627 if (http_result == 200) 1619 ps->recv_active = GNUNET_YES;
1628 {
1629 ps->recv_connected = GNUNET_YES;
1630 ps->recv_active = GNUNET_YES;
1631#if DEBUG_CONNECTIONS 1620#if DEBUG_CONNECTIONS
1632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Connection %X: connected to recieve data\n",ps); 1621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1622 "Connection %X: connected to recieve data\n", ps);
1633#endif 1623#endif
1634 // Calling send_check_connections again since receive is established 1624 // Calling send_check_connections again since receive is established
1635 send_check_connections (ps->peercontext->plugin, ps); 1625 send_check_connections (ps->peercontext->plugin, ps);
1636 } 1626 }
1637 }
1638 } 1627 }
1639 1628 }
1629
1640#if DEBUG_CURL 1630#if DEBUG_CURL
1641 char * tmp; 1631 char *tmp;
1642 size_t len = size * nmemb; 1632 size_t len = size * nmemb;
1633
1643 tmp = NULL; 1634 tmp = NULL;
1644 if ((size * nmemb) < SIZE_MAX) 1635 if ((size * nmemb) < SIZE_MAX)
1645 tmp = GNUNET_malloc (len+1); 1636 tmp = GNUNET_malloc (len + 1);
1646 1637
1647 if ((tmp != NULL) && (len > 0)) 1638 if ((tmp != NULL) && (len > 0))
1639 {
1640 memcpy (tmp, ptr, len);
1641 if (len >= 2)
1648 { 1642 {
1649 memcpy(tmp,ptr,len); 1643 if (tmp[len - 2] == 13)
1650 if (len>=2) 1644 tmp[len - 2] = '\0';
1651 {
1652 if (tmp[len-2] == 13)
1653 tmp[len-2]= '\0';
1654 }
1655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1656 "Connection %X: Header: %s\n",
1657 ps, tmp);
1658 } 1645 }
1646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1647 "Connection %X: Header: %s\n", ps, tmp);
1648 }
1659 GNUNET_free_non_null (tmp); 1649 GNUNET_free_non_null (tmp);
1660#endif 1650#endif
1661 1651
1662 return size * nmemb; 1652 return size * nmemb;
1663} 1653}
1664 1654
@@ -1672,59 +1662,56 @@ curl_get_header_cb( void *ptr,
1672 * @param stream closure set by user 1662 * @param stream closure set by user
1673 * @return bytes read by function 1663 * @return bytes read by function
1674 */ 1664 */
1675static size_t 1665static size_t
1676curl_put_header_cb(void *ptr, 1666curl_put_header_cb (void *ptr, size_t size, size_t nmemb, void *stream)
1677 size_t size,
1678 size_t nmemb,
1679 void *stream)
1680{ 1667{
1681 struct Session * ps = stream; 1668 struct Session *ps = stream;
1682 1669
1683 char * tmp; 1670 char *tmp;
1684 size_t len = size * nmemb; 1671 size_t len = size * nmemb;
1685 long http_result = 0; 1672 long http_result = 0;
1686 int res; 1673 int res;
1687 1674
1688 /* Getting last http result code */ 1675 /* Getting last http result code */
1689 GNUNET_assert(NULL!=ps); 1676 GNUNET_assert (NULL != ps);
1690 res = curl_easy_getinfo (ps->send_endpoint, CURLINFO_RESPONSE_CODE, &http_result); 1677 res =
1678 curl_easy_getinfo (ps->send_endpoint, CURLINFO_RESPONSE_CODE,
1679 &http_result);
1691 if (CURLE_OK == res) 1680 if (CURLE_OK == res)
1681 {
1682 if ((http_result == 100) && (ps->send_connected == GNUNET_NO))
1692 { 1683 {
1693 if ((http_result == 100) && (ps->send_connected==GNUNET_NO)) 1684 ps->send_connected = GNUNET_YES;
1694 { 1685 ps->send_active = GNUNET_YES;
1695 ps->send_connected = GNUNET_YES;
1696 ps->send_active = GNUNET_YES;
1697#if DEBUG_CONNECTIONS 1686#if DEBUG_CONNECTIONS
1698 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1699 "Connection %X: connected to send data\n", 1688 "Connection %X: connected to send data\n", ps);
1700 ps); 1689#endif
1701#endif 1690 }
1702 } 1691 if ((http_result == 200) && (ps->send_connected == GNUNET_YES))
1703 if ((http_result == 200) && (ps->send_connected==GNUNET_YES)) 1692 {
1704 { 1693 ps->send_connected = GNUNET_NO;
1705 ps->send_connected = GNUNET_NO; 1694 ps->send_active = GNUNET_NO;
1706 ps->send_active = GNUNET_NO;
1707#if DEBUG_CONNECTIONS 1695#if DEBUG_CONNECTIONS
1708 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1709 "Connection %X: sending disconnected\n", 1697 "Connection %X: sending disconnected\n", ps);
1710 ps);
1711#endif 1698#endif
1712 }
1713 } 1699 }
1714 1700 }
1701
1715 tmp = NULL; 1702 tmp = NULL;
1716 if ((size * nmemb) < SIZE_MAX) 1703 if ((size * nmemb) < SIZE_MAX)
1717 tmp = GNUNET_malloc (len+1); 1704 tmp = GNUNET_malloc (len + 1);
1718 1705
1719 if ((tmp != NULL) && (len > 0)) 1706 if ((tmp != NULL) && (len > 0))
1707 {
1708 memcpy (tmp, ptr, len);
1709 if (len >= 2)
1720 { 1710 {
1721 memcpy(tmp,ptr,len); 1711 if (tmp[len - 2] == 13)
1722 if (len>=2) 1712 tmp[len - 2] = '\0';
1723 {
1724 if (tmp[len-2] == 13)
1725 tmp[len-2]= '\0';
1726 }
1727 } 1713 }
1714 }
1728 GNUNET_free_non_null (tmp); 1715 GNUNET_free_non_null (tmp);
1729 return size * nmemb; 1716 return size * nmemb;
1730} 1717}
@@ -1738,123 +1725,119 @@ curl_put_header_cb(void *ptr,
1738 * @param ptr source pointer, passed to the libcurl handle 1725 * @param ptr source pointer, passed to the libcurl handle
1739 * @return bytes written to stream 1726 * @return bytes written to stream
1740 */ 1727 */
1741static size_t 1728static size_t
1742curl_send_cb(void *stream, 1729curl_send_cb (void *stream, size_t size, size_t nmemb, void *ptr)
1743 size_t size, size_t nmemb,
1744 void *ptr)
1745{ 1730{
1746 struct Session * ps = ptr; 1731 struct Session *ps = ptr;
1747 struct HTTP_Message * msg = ps->pending_msgs_tail; 1732 struct HTTP_Message *msg = ps->pending_msgs_tail;
1748 size_t bytes_sent; 1733 size_t bytes_sent;
1749 size_t len; 1734 size_t len;
1750 1735
1751 if (ps->send_active == GNUNET_NO) 1736 if (ps->send_active == GNUNET_NO)
1752 return CURL_READFUNC_PAUSE; 1737 return CURL_READFUNC_PAUSE;
1753 if ( (ps->pending_msgs_tail == NULL) && 1738 if ((ps->pending_msgs_tail == NULL) && (ps->send_active == GNUNET_YES))
1754 (ps->send_active == GNUNET_YES) ) 1739 {
1755 {
1756#if DEBUG_CONNECTIONS 1740#if DEBUG_CONNECTIONS
1757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1758 "Connection %X: No Message to send, pausing connection\n", 1742 "Connection %X: No Message to send, pausing connection\n", ps);
1759 ps);
1760#endif 1743#endif
1761 ps->send_active = GNUNET_NO; 1744 ps->send_active = GNUNET_NO;
1762 return CURL_READFUNC_PAUSE; 1745 return CURL_READFUNC_PAUSE;
1763 } 1746 }
1764 1747
1765 GNUNET_assert (msg!=NULL); 1748 GNUNET_assert (msg != NULL);
1766 1749
1767 /* data to send */ 1750 /* data to send */
1768 if (msg->pos < msg->size) 1751 if (msg->pos < msg->size)
1752 {
1753 /* data fit in buffer */
1754 if ((msg->size - msg->pos) <= (size * nmemb))
1769 { 1755 {
1770 /* data fit in buffer */ 1756 len = (msg->size - msg->pos);
1771 if ((msg->size - msg->pos) <= (size * nmemb)) 1757 memcpy (stream, &msg->buf[msg->pos], len);
1772 { 1758 msg->pos += len;
1773 len = (msg->size - msg->pos); 1759 bytes_sent = len;
1774 memcpy(stream, &msg->buf[msg->pos], len);
1775 msg->pos += len;
1776 bytes_sent = len;
1777 }
1778 else
1779 {
1780 len = size*nmemb;
1781 memcpy(stream, &msg->buf[msg->pos], len);
1782 msg->pos += len;
1783 bytes_sent = len;
1784 }
1785 } 1760 }
1786 /* no data to send */ 1761 else
1787 else
1788 { 1762 {
1789 bytes_sent = 0; 1763 len = size * nmemb;
1764 memcpy (stream, &msg->buf[msg->pos], len);
1765 msg->pos += len;
1766 bytes_sent = len;
1790 } 1767 }
1791 1768 }
1792 if ( msg->pos == msg->size) 1769 /* no data to send */
1793 { 1770 else
1771 {
1772 bytes_sent = 0;
1773 }
1774
1775 if (msg->pos == msg->size)
1776 {
1794#if DEBUG_CONNECTIONS 1777#if DEBUG_CONNECTIONS
1795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1796 "Connection %X: Message with %u bytes sent, removing message from queue\n", 1779 "Connection %X: Message with %u bytes sent, removing message from queue\n",
1797 ps, 1780 ps, msg->pos);
1798 msg->pos); 1781#endif
1799#endif 1782 /* Calling transmit continuation */
1800 /* Calling transmit continuation */ 1783 if (NULL != ps->pending_msgs_tail->transmit_cont)
1801 if (NULL != ps->pending_msgs_tail->transmit_cont) 1784 msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls,
1802 msg->transmit_cont (ps->pending_msgs_tail->transmit_cont_cls, 1785 &(ps->peercontext)->identity, GNUNET_OK);
1803 &(ps->peercontext)->identity, 1786 ps->queue_length_cur -= msg->size;
1804 GNUNET_OK); 1787 remove_http_message (ps, msg);
1805 ps->queue_length_cur -= msg->size; 1788 }
1806 remove_http_message(ps, msg);
1807 }
1808 return bytes_sent; 1789 return bytes_sent;
1809} 1790}
1810 1791
1811 1792
1812static void 1793static void
1813curl_receive_mst_cb (void *cls, 1794curl_receive_mst_cb (void *cls,
1814 void *client, 1795 void *client, const struct GNUNET_MessageHeader *message)
1815 const struct GNUNET_MessageHeader *message)
1816{ 1796{
1817 struct Session *ps = cls; 1797 struct Session *ps = cls;
1818 struct GNUNET_TIME_Relative delay; 1798 struct GNUNET_TIME_Relative delay;
1819 GNUNET_assert(ps != NULL); 1799
1800 GNUNET_assert (ps != NULL);
1820 1801
1821 struct HTTP_PeerContext *pc = ps->peercontext; 1802 struct HTTP_PeerContext *pc = ps->peercontext;
1822 GNUNET_assert(pc != NULL); 1803
1804 GNUNET_assert (pc != NULL);
1823#if DEBUG_HTTP 1805#if DEBUG_HTTP
1824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1825 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n", 1807 "Connection %X: Forwarding message to transport service, type %u and size %u from `%s' (`%s')\n",
1826 ps, 1808 ps,
1827 ntohs(message->type), 1809 ntohs (message->type),
1828 ntohs(message->size), 1810 ntohs (message->size),
1829 GNUNET_i2s(&(pc->identity)), 1811 GNUNET_i2s (&(pc->identity)),
1830 http_plugin_address_to_string(NULL,ps->addr,ps->addrlen)); 1812 http_plugin_address_to_string (NULL, ps->addr, ps->addrlen));
1831#endif 1813#endif
1832 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1814 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1815
1833 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 1816 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1834 distance[0].value = htonl (1); 1817 distance[0].value = htonl (1);
1835 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1818 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1836 distance[1].value = htonl (0); 1819 distance[1].value = htonl (0);
1837 1820
1838 delay = pc->plugin->env->receive (pc->plugin->env->cls, 1821 delay = pc->plugin->env->receive (pc->plugin->env->cls,
1839 &pc->identity, 1822 &pc->identity,
1840 message, 1823 message,
1841 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, 1824 (const struct
1842 ps, 1825 GNUNET_TRANSPORT_ATS_Information *)
1843 ps->addr, 1826 &distance, 2, ps, ps->addr, ps->addrlen);
1844 ps->addrlen);
1845 pc->delay = delay; 1827 pc->delay = delay;
1846 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK) 1828 if (pc->reset_task != GNUNET_SCHEDULER_NO_TASK)
1847 GNUNET_SCHEDULER_cancel (pc->reset_task); 1829 GNUNET_SCHEDULER_cancel (pc->reset_task);
1848 1830
1849 if (delay.rel_value > 0) 1831 if (delay.rel_value > 0)
1850 { 1832 {
1851#if DEBUG_HTTP 1833#if DEBUG_HTTP
1852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1853 "Connection %X: Inbound quota management: delay next read for %llu ms\n", 1835 "Connection %X: Inbound quota management: delay next read for %llu ms\n",
1854 ps, delay.rel_value); 1836 ps, delay.rel_value);
1855#endif 1837#endif
1856 pc->reset_task = GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc); 1838 pc->reset_task =
1857 } 1839 GNUNET_SCHEDULER_add_delayed (delay, &reset_inbound_quota_delay, pc);
1840 }
1858} 1841}
1859 1842
1860 1843
@@ -1867,163 +1850,171 @@ curl_receive_mst_cb (void *cls,
1867* @param ptr destination pointer, passed to the libcurl handle 1850* @param ptr destination pointer, passed to the libcurl handle
1868* @return bytes read from stream 1851* @return bytes read from stream
1869*/ 1852*/
1870static size_t 1853static size_t
1871curl_receive_cb( void *stream, size_t size, size_t nmemb, void *ptr) 1854curl_receive_cb (void *stream, size_t size, size_t nmemb, void *ptr)
1872{ 1855{
1873 struct Session * ps = ptr; 1856 struct Session *ps = ptr;
1874 1857
1875 if (ps->peercontext->delay.rel_value > 0) 1858 if (ps->peercontext->delay.rel_value > 0)
1876 { 1859 {
1877#if DEBUG_HTTP 1860#if DEBUG_HTTP
1878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1879 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n", 1862 "Connection %X: no inbound bandwidth available! Next read was delayed for %llu ms\n",
1880 ps, ps->peercontext->delay.rel_value); 1863 ps, ps->peercontext->delay.rel_value);
1881#endif 1864#endif
1882 return 0; 1865 return 0;
1883 } 1866 }
1884#if DEBUG_CONNECTIONS 1867#if DEBUG_CONNECTIONS
1885 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1868 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1886 "Connection %X: %u bytes received\n", 1869 "Connection %X: %u bytes received\n", ps, size * nmemb);
1887 ps, size*nmemb);
1888#endif 1870#endif
1889 GNUNET_SERVER_mst_receive(ps->msgtok, ps, 1871 GNUNET_SERVER_mst_receive (ps->msgtok, ps,
1890 stream, size*nmemb, 1872 stream, size * nmemb, GNUNET_NO, GNUNET_NO);
1891 GNUNET_NO, GNUNET_NO);
1892 return (size * nmemb); 1873 return (size * nmemb);
1893} 1874}
1894 1875
1895 1876
1896static void 1877static void
1897curl_handle_finished (struct Plugin *plugin) 1878curl_handle_finished (struct Plugin *plugin)
1898{ 1879{
1899 struct Session *ps = NULL; 1880 struct Session *ps = NULL;
1900 struct HTTP_PeerContext *pc = NULL; 1881 struct HTTP_PeerContext *pc = NULL;
1901 struct CURLMsg *msg; 1882 struct CURLMsg *msg;
1902 struct HTTP_Message * cur_msg = NULL; 1883 struct HTTP_Message *cur_msg = NULL;
1903 int msgs_in_queue; 1884 int msgs_in_queue;
1904 char * tmp; 1885 char *tmp;
1905 long http_result; 1886 long http_result;
1906 1887
1907 do 1888 do
1908 { 1889 {
1909 msg = curl_multi_info_read (plugin->multi_handle, &msgs_in_queue); 1890 msg = curl_multi_info_read (plugin->multi_handle, &msgs_in_queue);
1910 if ((msgs_in_queue == 0) || (msg == NULL)) 1891 if ((msgs_in_queue == 0) || (msg == NULL))
1911 break; 1892 break;
1912 /* get session for affected curl handle */ 1893 /* get session for affected curl handle */
1913 GNUNET_assert ( msg->easy_handle != NULL ); 1894 GNUNET_assert (msg->easy_handle != NULL);
1914 curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &tmp); 1895 curl_easy_getinfo (msg->easy_handle, CURLINFO_PRIVATE, &tmp);
1915 ps = (struct Session *) tmp; 1896 ps = (struct Session *) tmp;
1916 GNUNET_assert ( ps != NULL ); 1897 GNUNET_assert (ps != NULL);
1917 pc = ps->peercontext; 1898 pc = ps->peercontext;
1918 GNUNET_assert ( pc != NULL ); 1899 GNUNET_assert (pc != NULL);
1919 switch (msg->msg) 1900 switch (msg->msg)
1920 { 1901 {
1921 case CURLMSG_DONE: 1902 case CURLMSG_DONE:
1922 if ( (msg->data.result != CURLE_OK) && 1903 if ((msg->data.result != CURLE_OK) &&
1923 (msg->data.result != CURLE_GOT_NOTHING) ) 1904 (msg->data.result != CURLE_GOT_NOTHING))
1924 { 1905 {
1925 /* sending msg failed*/ 1906 /* sending msg failed */
1926 if (msg->easy_handle == ps->send_endpoint) 1907 if (msg->easy_handle == ps->send_endpoint)
1927 { 1908 {
1928#if DEBUG_CONNECTIONS 1909#if DEBUG_CONNECTIONS
1929 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1910 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1930 _("Connection %X: HTTP PUT to peer `%s' (`%s') failed: `%s' `%s'\n"), 1911 _
1931 ps, 1912 ("Connection %X: HTTP PUT to peer `%s' (`%s') failed: `%s' `%s'\n"),
1932 GNUNET_i2s(&pc->identity), 1913 ps, GNUNET_i2s (&pc->identity),
1933 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 1914 http_plugin_address_to_string (NULL, ps->addr,
1934 "curl_multi_perform", 1915 ps->addrlen),
1935 curl_easy_strerror (msg->data.result)); 1916 "curl_multi_perform",
1936#endif 1917 curl_easy_strerror (msg->data.result));
1937 ps->send_connected = GNUNET_NO; 1918#endif
1938 ps->send_active = GNUNET_NO; 1919 ps->send_connected = GNUNET_NO;
1939 curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint); 1920 ps->send_active = GNUNET_NO;
1940 while (ps->pending_msgs_tail != NULL) 1921 curl_multi_remove_handle (plugin->multi_handle, ps->send_endpoint);
1941 { 1922 while (ps->pending_msgs_tail != NULL)
1942 cur_msg = ps->pending_msgs_tail; 1923 {
1943 if ( NULL != cur_msg->transmit_cont) 1924 cur_msg = ps->pending_msgs_tail;
1944 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_SYSERR); 1925 if (NULL != cur_msg->transmit_cont)
1945 ps->queue_length_cur -= cur_msg->size; 1926 cur_msg->transmit_cont (cur_msg->transmit_cont_cls, &pc->identity,
1946 remove_http_message(ps,cur_msg); 1927 GNUNET_SYSERR);
1947 } 1928 ps->queue_length_cur -= cur_msg->size;
1948 } 1929 remove_http_message (ps, cur_msg);
1949 /* GET connection failed */ 1930 }
1950 if (msg->easy_handle == ps->recv_endpoint) 1931 }
1951 { 1932 /* GET connection failed */
1933 if (msg->easy_handle == ps->recv_endpoint)
1934 {
1952#if DEBUG_CONNECTIONS 1935#if DEBUG_CONNECTIONS
1953 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 1936 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1954 _("Connection %X: HTTP GET to peer `%s' (`%s') failed: `%s' `%s'\n"), 1937 _
1955 ps, 1938 ("Connection %X: HTTP GET to peer `%s' (`%s') failed: `%s' `%s'\n"),
1956 GNUNET_i2s(&pc->identity), 1939 ps, GNUNET_i2s (&pc->identity),
1957 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 1940 http_plugin_address_to_string (NULL, ps->addr,
1958 "curl_multi_perform", 1941 ps->addrlen),
1959 curl_easy_strerror (msg->data.result)); 1942 "curl_multi_perform",
1960#endif 1943 curl_easy_strerror (msg->data.result));
1961 ps->recv_connected = GNUNET_NO; 1944#endif
1962 ps->recv_active = GNUNET_NO; 1945 ps->recv_connected = GNUNET_NO;
1963 curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint); 1946 ps->recv_active = GNUNET_NO;
1964 } 1947 curl_multi_remove_handle (plugin->multi_handle, ps->recv_endpoint);
1965 } 1948 }
1966 else 1949 }
1967 { 1950 else
1968 if (msg->easy_handle == ps->send_endpoint) 1951 {
1969 { 1952 if (msg->easy_handle == ps->send_endpoint)
1970 GNUNET_assert (CURLE_OK == curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &http_result)); 1953 {
1954 GNUNET_assert (CURLE_OK ==
1955 curl_easy_getinfo (msg->easy_handle,
1956 CURLINFO_RESPONSE_CODE,
1957 &http_result));
1971#if DEBUG_CONNECTIONS 1958#if DEBUG_CONNECTIONS
1972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1959 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1973 "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n", 1960 "Connection %X: HTTP PUT connection to peer `%s' (`%s') was closed with HTTP code %u\n",
1974 ps, 1961 ps,
1975 GNUNET_i2s(&pc->identity), 1962 GNUNET_i2s (&pc->identity),
1976 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 1963 http_plugin_address_to_string (NULL, ps->addr,
1977 http_result); 1964 ps->addrlen), http_result);
1978#endif 1965#endif
1979 /* Calling transmit continuation */ 1966 /* Calling transmit continuation */
1980 while (ps->pending_msgs_tail != NULL) 1967 while (ps->pending_msgs_tail != NULL)
1981 { 1968 {
1982 cur_msg = ps->pending_msgs_tail; 1969 cur_msg = ps->pending_msgs_tail;
1983 if ( NULL != cur_msg->transmit_cont) 1970 if (NULL != cur_msg->transmit_cont)
1984 { 1971 {
1985 /* HTTP 1xx : Last message before here was informational */ 1972 /* HTTP 1xx : Last message before here was informational */
1986 if ((http_result >=100) && (http_result < 200)) 1973 if ((http_result >= 100) && (http_result < 200))
1987 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_OK); 1974 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
1988 /* HTTP 2xx: successful operations */ 1975 &pc->identity, GNUNET_OK);
1989 if ((http_result >=200) && (http_result < 300)) 1976 /* HTTP 2xx: successful operations */
1990 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_OK); 1977 if ((http_result >= 200) && (http_result < 300))
1991 /* HTTP 3xx..5xx: error */ 1978 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
1992 if ((http_result >=300) && (http_result < 600)) 1979 &pc->identity, GNUNET_OK);
1993 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,&pc->identity,GNUNET_SYSERR); 1980 /* HTTP 3xx..5xx: error */
1994 } 1981 if ((http_result >= 300) && (http_result < 600))
1995 ps->queue_length_cur -= cur_msg->size; 1982 cur_msg->transmit_cont (cur_msg->transmit_cont_cls,
1996 remove_http_message(ps,cur_msg); 1983 &pc->identity, GNUNET_SYSERR);
1997 } 1984 }
1998 1985 ps->queue_length_cur -= cur_msg->size;
1999 ps->send_connected = GNUNET_NO; 1986 remove_http_message (ps, cur_msg);
2000 ps->send_active = GNUNET_NO; 1987 }
2001 curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint); 1988
2002 } 1989 ps->send_connected = GNUNET_NO;
2003 if (msg->easy_handle == ps->recv_endpoint) 1990 ps->send_active = GNUNET_NO;
2004 { 1991 curl_multi_remove_handle (plugin->multi_handle, ps->send_endpoint);
1992 }
1993 if (msg->easy_handle == ps->recv_endpoint)
1994 {
2005#if DEBUG_CONNECTIONS 1995#if DEBUG_CONNECTIONS
2006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2007 "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n", 1997 "Connection %X: HTTP GET connection to peer `%s' (`%s') was closed with HTTP code %u\n",
2008 ps, 1998 ps,
2009 GNUNET_i2s(&pc->identity), 1999 GNUNET_i2s (&pc->identity),
2010 http_plugin_address_to_string(NULL, ps->addr, ps->addrlen), 2000 http_plugin_address_to_string (NULL, ps->addr,
2011 http_result); 2001 ps->addrlen), http_result);
2012#endif 2002#endif
2013 ps->recv_connected = GNUNET_NO; 2003 ps->recv_connected = GNUNET_NO;
2014 ps->recv_active = GNUNET_NO; 2004 ps->recv_active = GNUNET_NO;
2015 curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint); 2005 curl_multi_remove_handle (plugin->multi_handle, ps->recv_endpoint);
2016 } 2006 }
2017 plugin->current_connections--; 2007 plugin->current_connections--;
2018 } 2008 }
2019 if ((ps->recv_connected == GNUNET_NO) && (ps->send_connected == GNUNET_NO)) 2009 if ((ps->recv_connected == GNUNET_NO) &&
2020 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR); 2010 (ps->send_connected == GNUNET_NO))
2021 break; 2011 remove_session (pc, ps, GNUNET_YES, GNUNET_SYSERR);
2022 default: 2012 break;
2023 break; 2013 default:
2024 } 2014 break;
2025 } 2015 }
2026 while ( (msgs_in_queue > 0) ); 2016 }
2017 while ((msgs_in_queue > 0));
2027} 2018}
2028 2019
2029 2020
@@ -2032,29 +2023,29 @@ curl_handle_finished (struct Plugin *plugin)
2032 * @param cls plugin as closure 2023 * @param cls plugin as closure
2033 * @param tc gnunet scheduler task context 2024 * @param tc gnunet scheduler task context
2034 */ 2025 */
2035static void curl_perform (void *cls, 2026static void
2036 const struct GNUNET_SCHEDULER_TaskContext *tc) 2027curl_perform (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2037{ 2028{
2038 struct Plugin *plugin = cls; 2029 struct Plugin *plugin = cls;
2039 static unsigned int handles_last_run; 2030 static unsigned int handles_last_run;
2040 int running; 2031 int running;
2041 CURLMcode mret; 2032 CURLMcode mret;
2042 2033
2043 GNUNET_assert(cls !=NULL); 2034 GNUNET_assert (cls != NULL);
2044 2035
2045 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2036 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2046 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 2037 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2047 return; 2038 return;
2048 do 2039 do
2049 { 2040 {
2050 running = 0; 2041 running = 0;
2051 mret = curl_multi_perform (plugin->multi_handle, &running); 2042 mret = curl_multi_perform (plugin->multi_handle, &running);
2052 if ((running < handles_last_run) && (running>0)) 2043 if ((running < handles_last_run) && (running > 0))
2053 curl_handle_finished(plugin); 2044 curl_handle_finished (plugin);
2054 handles_last_run = running; 2045 handles_last_run = running;
2055 } 2046 }
2056 while (mret == CURLM_CALL_MULTI_PERFORM); 2047 while (mret == CURLM_CALL_MULTI_PERFORM);
2057 curl_schedule(plugin); 2048 curl_schedule (plugin);
2058} 2049}
2059 2050
2060 2051
@@ -2064,8 +2055,8 @@ static void curl_perform (void *cls,
2064 * @param plugin plugin as closure 2055 * @param plugin plugin as closure
2065 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok 2056 * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok
2066 */ 2057 */
2067static int 2058static int
2068curl_schedule(struct Plugin *plugin) 2059curl_schedule (struct Plugin *plugin)
2069{ 2060{
2070 fd_set rs; 2061 fd_set rs;
2071 fd_set ws; 2062 fd_set ws;
@@ -2077,48 +2068,50 @@ curl_schedule(struct Plugin *plugin)
2077 CURLMcode mret; 2068 CURLMcode mret;
2078 2069
2079 /* Cancel previous scheduled task */ 2070 /* Cancel previous scheduled task */
2080 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 2071 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2081 { 2072 {
2082 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 2073 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2083 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2074 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2084 } 2075 }
2085 2076
2086 max = -1; 2077 max = -1;
2087 FD_ZERO (&rs); 2078 FD_ZERO (&rs);
2088 FD_ZERO (&ws); 2079 FD_ZERO (&ws);
2089 FD_ZERO (&es); 2080 FD_ZERO (&es);
2090 mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max); 2081 mret = curl_multi_fdset (plugin->multi_handle, &rs, &ws, &es, &max);
2091 if (mret != CURLM_OK) 2082 if (mret != CURLM_OK)
2092 { 2083 {
2093 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2084 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2094 _("%s failed at %s:%d: `%s'\n"), 2085 _("%s failed at %s:%d: `%s'\n"),
2095 "curl_multi_fdset", __FILE__, __LINE__, 2086 "curl_multi_fdset", __FILE__, __LINE__,
2096 curl_multi_strerror (mret)); 2087 curl_multi_strerror (mret));
2097 return GNUNET_SYSERR; 2088 return GNUNET_SYSERR;
2098 } 2089 }
2099 mret = curl_multi_timeout (plugin->multi_handle, &to); 2090 mret = curl_multi_timeout (plugin->multi_handle, &to);
2100 if (mret != CURLM_OK) 2091 if (mret != CURLM_OK)
2101 { 2092 {
2102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2093 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2103 _("%s failed at %s:%d: `%s'\n"), 2094 _("%s failed at %s:%d: `%s'\n"),
2104 "curl_multi_timeout", __FILE__, __LINE__, 2095 "curl_multi_timeout", __FILE__, __LINE__,
2105 curl_multi_strerror (mret)); 2096 curl_multi_strerror (mret));
2106 return GNUNET_SYSERR; 2097 return GNUNET_SYSERR;
2107 } 2098 }
2108 2099
2109 grs = GNUNET_NETWORK_fdset_create (); 2100 grs = GNUNET_NETWORK_fdset_create ();
2110 gws = GNUNET_NETWORK_fdset_create (); 2101 gws = GNUNET_NETWORK_fdset_create ();
2111 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 2102 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
2112 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 2103 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
2113 plugin->http_curl_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 2104 plugin->http_curl_task =
2114 GNUNET_SCHEDULER_NO_TASK, 2105 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
2115 (to == -1) 2106 GNUNET_SCHEDULER_NO_TASK,
2116 ? GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 2107 (to ==
2117 : GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, to), 2108 -1) ?
2118 grs, 2109 GNUNET_TIME_relative_multiply
2119 gws, 2110 (GNUNET_TIME_UNIT_SECONDS,
2120 &curl_perform, 2111 5) :
2121 plugin); 2112 GNUNET_TIME_relative_multiply
2113 (GNUNET_TIME_UNIT_MILLISECONDS, to), grs,
2114 gws, &curl_perform, plugin);
2122 GNUNET_NETWORK_fdset_destroy (gws); 2115 GNUNET_NETWORK_fdset_destroy (gws);
2123 GNUNET_NETWORK_fdset_destroy (grs); 2116 GNUNET_NETWORK_fdset_destroy (grs);
2124 return GNUNET_OK; 2117 return GNUNET_OK;
@@ -2135,28 +2128,24 @@ curl_schedule(struct Plugin *plugin)
2135 * @param cls closure 2128 * @param cls closure
2136 * @return 0 2129 * @return 0
2137 */ 2130 */
2138static int 2131static int
2139curl_logger (CURL * curl, 2132curl_logger (CURL * curl,
2140 curl_infotype type, 2133 curl_infotype type, char *data, size_t size, void *cls)
2141 char * data, size_t size,
2142 void * cls)
2143{ 2134{
2144 if (type == CURLINFO_TEXT) 2135 if (type == CURLINFO_TEXT)
2136 {
2137 char text[size + 2];
2138
2139 memcpy (text, data, size);
2140 if (text[size - 1] == '\n')
2141 text[size] = '\0';
2142 else
2145 { 2143 {
2146 char text[size+2]; 2144 text[size] = '\n';
2147 memcpy(text,data,size); 2145 text[size + 1] = '\0';
2148 if (text[size-1] == '\n')
2149 text[size] = '\0';
2150 else
2151 {
2152 text[size] = '\n';
2153 text[size+1] = '\0';
2154 }
2155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2156 "CURL: Connection %X - %s",
2157 cls,
2158 text);
2159 } 2146 }
2147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CURL: Connection %X - %s", cls, text);
2148 }
2160 return 0; 2149 return 0;
2161} 2150}
2162#endif 2151#endif
@@ -2169,184 +2158,203 @@ curl_logger (CURL * curl,
2169 * @param ps session 2158 * @param ps session
2170 * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok 2159 * @return GNUNET_SYSERR on failure, GNUNET_NO if connecting, GNUNET_YES if ok
2171 */ 2160 */
2172static int 2161static int
2173send_check_connections (struct Plugin *plugin, 2162send_check_connections (struct Plugin *plugin, struct Session *ps)
2174 struct Session *ps)
2175{ 2163{
2176 CURLMcode mret; 2164 CURLMcode mret;
2177 struct GNUNET_TIME_Relative timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; 2165 struct GNUNET_TIME_Relative timeout =
2166 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
2178 2167
2179 if ((ps->direction == OUTBOUND) && (plugin->current_connections < plugin->max_connect_per_transport)) 2168 if ((ps->direction == OUTBOUND) &&
2169 (plugin->current_connections < plugin->max_connect_per_transport))
2170 {
2171 /* RECV DIRECTION */
2172 /* Check if session is connected to receive data, otherwise connect to peer */
2173
2174 if (ps->recv_connected == GNUNET_NO)
2180 { 2175 {
2181 /* RECV DIRECTION */ 2176 int fresh = GNUNET_NO;
2182 /* Check if session is connected to receive data, otherwise connect to peer */ 2177
2183 2178 if (ps->recv_endpoint == NULL)
2184 if (ps->recv_connected == GNUNET_NO) 2179 {
2185 { 2180 fresh = GNUNET_YES;
2186 int fresh = GNUNET_NO; 2181 ps->recv_endpoint = curl_easy_init ();
2187 if (ps->recv_endpoint == NULL) 2182 }
2188 {
2189 fresh = GNUNET_YES;
2190 ps->recv_endpoint = curl_easy_init();
2191 }
2192#if DEBUG_CURL 2183#if DEBUG_CURL
2193 curl_easy_setopt(ps->recv_endpoint, CURLOPT_VERBOSE, 1L); 2184 curl_easy_setopt (ps->recv_endpoint, CURLOPT_VERBOSE, 1L);
2194 curl_easy_setopt(ps->recv_endpoint, CURLOPT_DEBUGFUNCTION , &curl_logger); 2185 curl_easy_setopt (ps->recv_endpoint, CURLOPT_DEBUGFUNCTION, &curl_logger);
2195 curl_easy_setopt(ps->recv_endpoint, CURLOPT_DEBUGDATA , ps->recv_endpoint); 2186 curl_easy_setopt (ps->recv_endpoint, CURLOPT_DEBUGDATA,
2187 ps->recv_endpoint);
2196#endif 2188#endif
2197#if BUILD_HTTPS 2189#if BUILD_HTTPS
2198 curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 2190 curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSLVERSION,
2199 curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSL_VERIFYPEER, 0); 2191 CURL_SSLVERSION_TLSv1);
2200 curl_easy_setopt(ps->recv_endpoint, CURLOPT_SSL_VERIFYHOST, 0); 2192 curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
2201#endif 2193 curl_easy_setopt (ps->recv_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
2202 curl_easy_setopt(ps->recv_endpoint, CURLOPT_URL, ps->url); 2194#endif
2203 curl_easy_setopt(ps->recv_endpoint, CURLOPT_HEADERFUNCTION, &curl_get_header_cb); 2195 curl_easy_setopt (ps->recv_endpoint, CURLOPT_URL, ps->url);
2204 curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEHEADER, ps); 2196 curl_easy_setopt (ps->recv_endpoint, CURLOPT_HEADERFUNCTION,
2205 curl_easy_setopt(ps->recv_endpoint, CURLOPT_READFUNCTION, curl_send_cb); 2197 &curl_get_header_cb);
2206 curl_easy_setopt(ps->recv_endpoint, CURLOPT_READDATA, ps); 2198 curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEHEADER, ps);
2207 curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb); 2199 curl_easy_setopt (ps->recv_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
2208 curl_easy_setopt(ps->recv_endpoint, CURLOPT_WRITEDATA, ps); 2200 curl_easy_setopt (ps->recv_endpoint, CURLOPT_READDATA, ps);
2209 curl_easy_setopt(ps->recv_endpoint, CURLOPT_TIMEOUT, (long) timeout.rel_value); 2201 curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEFUNCTION,
2210 curl_easy_setopt(ps->recv_endpoint, CURLOPT_PRIVATE, ps); 2202 curl_receive_cb);
2211 curl_easy_setopt(ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); 2203 curl_easy_setopt (ps->recv_endpoint, CURLOPT_WRITEDATA, ps);
2212 curl_easy_setopt(ps->recv_endpoint, CURLOPT_BUFFERSIZE, 2*GNUNET_SERVER_MAX_MESSAGE_SIZE); 2204 curl_easy_setopt (ps->recv_endpoint, CURLOPT_TIMEOUT,
2205 (long) timeout.rel_value);
2206 curl_easy_setopt (ps->recv_endpoint, CURLOPT_PRIVATE, ps);
2207 curl_easy_setopt (ps->recv_endpoint, CURLOPT_CONNECTTIMEOUT,
2208 HTTP_CONNECT_TIMEOUT);
2209 curl_easy_setopt (ps->recv_endpoint, CURLOPT_BUFFERSIZE,
2210 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
2213#if CURL_TCP_NODELAY 2211#if CURL_TCP_NODELAY
2214 curl_easy_setopt(ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1); 2212 curl_easy_setopt (ps->recv_endpoint, CURLOPT_TCP_NODELAY, 1);
2215#endif 2213#endif
2216 if (fresh==GNUNET_YES) 2214 if (fresh == GNUNET_YES)
2217 { 2215 {
2218 mret = curl_multi_add_handle(plugin->multi_handle, ps->recv_endpoint); 2216 mret = curl_multi_add_handle (plugin->multi_handle, ps->recv_endpoint);
2219 if (mret != CURLM_OK) 2217 if (mret != CURLM_OK)
2220 { 2218 {
2221 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2219 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2222 _("Connection: %X: %s failed at %s:%d: `%s'\n"), 2220 _("Connection: %X: %s failed at %s:%d: `%s'\n"),
2223 ps, 2221 ps,
2224 "curl_multi_add_handle", __FILE__, __LINE__, 2222 "curl_multi_add_handle", __FILE__, __LINE__,
2225 curl_multi_strerror (mret)); 2223 curl_multi_strerror (mret));
2226 return GNUNET_SYSERR; 2224 return GNUNET_SYSERR;
2227 } 2225 }
2228 } 2226 }
2229 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 2227 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2230 { 2228 {
2231 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 2229 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2232 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2230 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2233 } 2231 }
2234 plugin->current_connections ++; 2232 plugin->current_connections++;
2235 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin); 2233 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2236 } 2234 }
2237 2235
2238 /* waiting for receive direction */ 2236 /* waiting for receive direction */
2239 if (ps->recv_connected==GNUNET_NO) 2237 if (ps->recv_connected == GNUNET_NO)
2240 return GNUNET_NO; 2238 return GNUNET_NO;
2241 2239
2242 /* SEND DIRECTION */ 2240 /* SEND DIRECTION */
2243 /* Check if session is connected to send data, otherwise connect to peer */ 2241 /* Check if session is connected to send data, otherwise connect to peer */
2244 if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint!= NULL)) 2242 if ((ps->send_connected == GNUNET_YES) && (ps->send_endpoint != NULL))
2245 { 2243 {
2246 if (ps->send_active == GNUNET_YES) 2244 if (ps->send_active == GNUNET_YES)
2247 { 2245 {
2248#if DEBUG_CONNECTIONS 2246#if DEBUG_CONNECTIONS
2249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2250 "Connection %X: outbound active, enqueueing message\n", 2248 "Connection %X: outbound active, enqueueing message\n", ps);
2251 ps); 2249#endif
2252#endif 2250 return GNUNET_YES;
2253 return GNUNET_YES; 2251 }
2254 } 2252 if (ps->send_active == GNUNET_NO)
2255 if (ps->send_active == GNUNET_NO) 2253 {
2256 {
2257#if DEBUG_CONNECTIONS 2254#if DEBUG_CONNECTIONS
2258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2259 "Connection %X: outbound paused, unpausing existing connection and enqueueing message\n", 2256 "Connection %X: outbound paused, unpausing existing connection and enqueueing message\n",
2260 ps); 2257 ps);
2261#endif 2258#endif
2262 if (CURLE_OK == curl_easy_pause(ps->send_endpoint,CURLPAUSE_CONT)) 2259 if (CURLE_OK == curl_easy_pause (ps->send_endpoint, CURLPAUSE_CONT))
2263 { 2260 {
2264 ps->send_active=GNUNET_YES; 2261 ps->send_active = GNUNET_YES;
2265 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 2262 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2266 { 2263 {
2267 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 2264 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2268 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 2265 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2269 } 2266 }
2270 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin); 2267 plugin->http_curl_task =
2271 return GNUNET_YES; 2268 GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2272 } 2269 return GNUNET_YES;
2273 else 2270 }
2274 return GNUNET_SYSERR; 2271 else
2275 } 2272 return GNUNET_SYSERR;
2276 } 2273 }
2277 /* not connected, initiate connection */ 2274 }
2278 if ((ps->send_connected==GNUNET_NO) && (plugin->current_connections < plugin->max_connect_per_transport)) 2275 /* not connected, initiate connection */
2279 { 2276 if ((ps->send_connected == GNUNET_NO) &&
2280 int fresh = GNUNET_NO; 2277 (plugin->current_connections < plugin->max_connect_per_transport))
2281 if (NULL == ps->send_endpoint) 2278 {
2282 { 2279 int fresh = GNUNET_NO;
2283 ps->send_endpoint = curl_easy_init(); 2280
2284 fresh = GNUNET_YES; 2281 if (NULL == ps->send_endpoint)
2285 } 2282 {
2286 GNUNET_assert (ps->send_endpoint != NULL); 2283 ps->send_endpoint = curl_easy_init ();
2287 GNUNET_assert (NULL != ps->pending_msgs_tail); 2284 fresh = GNUNET_YES;
2285 }
2286 GNUNET_assert (ps->send_endpoint != NULL);
2287 GNUNET_assert (NULL != ps->pending_msgs_tail);
2288#if DEBUG_CONNECTIONS 2288#if DEBUG_CONNECTIONS
2289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2290 "Connection %X: outbound not connected, initiating connection\n", 2290 "Connection %X: outbound not connected, initiating connection\n",
2291 ps); 2291 ps);
2292#endif 2292#endif
2293 ps->send_active = GNUNET_NO; 2293 ps->send_active = GNUNET_NO;
2294 2294
2295#if DEBUG_CURL 2295#if DEBUG_CURL
2296 curl_easy_setopt(ps->send_endpoint, CURLOPT_VERBOSE, 1L); 2296 curl_easy_setopt (ps->send_endpoint, CURLOPT_VERBOSE, 1L);
2297 curl_easy_setopt(ps->send_endpoint, CURLOPT_DEBUGFUNCTION , &curl_logger); 2297 curl_easy_setopt (ps->send_endpoint, CURLOPT_DEBUGFUNCTION, &curl_logger);
2298 curl_easy_setopt(ps->send_endpoint, CURLOPT_DEBUGDATA , ps->send_endpoint); 2298 curl_easy_setopt (ps->send_endpoint, CURLOPT_DEBUGDATA,
2299 ps->send_endpoint);
2299#endif 2300#endif
2300#if BUILD_HTTPS 2301#if BUILD_HTTPS
2301 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 2302 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSLVERSION,
2302 curl_easy_setopt(ps->send_endpoint, CURLOPT_SSL_VERIFYPEER, 0); 2303 CURL_SSLVERSION_TLSv1);
2303 curl_easy_setopt(ps->send_endpoint, CURLOPT_SSL_VERIFYHOST, 0); 2304 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSL_VERIFYPEER, 0);
2304#endif 2305 curl_easy_setopt (ps->send_endpoint, CURLOPT_SSL_VERIFYHOST, 0);
2305 curl_easy_setopt(ps->send_endpoint, CURLOPT_URL, ps->url); 2306#endif
2306 curl_easy_setopt(ps->send_endpoint, CURLOPT_PUT, 1L); 2307 curl_easy_setopt (ps->send_endpoint, CURLOPT_URL, ps->url);
2307 curl_easy_setopt(ps->send_endpoint, CURLOPT_HEADERFUNCTION, &curl_put_header_cb); 2308 curl_easy_setopt (ps->send_endpoint, CURLOPT_PUT, 1L);
2308 curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEHEADER, ps); 2309 curl_easy_setopt (ps->send_endpoint, CURLOPT_HEADERFUNCTION,
2309 curl_easy_setopt(ps->send_endpoint, CURLOPT_READFUNCTION, curl_send_cb); 2310 &curl_put_header_cb);
2310 curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps); 2311 curl_easy_setopt (ps->send_endpoint, CURLOPT_WRITEHEADER, ps);
2311 curl_easy_setopt(ps->send_endpoint, CURLOPT_WRITEFUNCTION, curl_receive_cb); 2312 curl_easy_setopt (ps->send_endpoint, CURLOPT_READFUNCTION, curl_send_cb);
2312 curl_easy_setopt(ps->send_endpoint, CURLOPT_READDATA, ps); 2313 curl_easy_setopt (ps->send_endpoint, CURLOPT_READDATA, ps);
2313 curl_easy_setopt(ps->send_endpoint, CURLOPT_TIMEOUT, (long) timeout.rel_value); 2314 curl_easy_setopt (ps->send_endpoint, CURLOPT_WRITEFUNCTION,
2314 curl_easy_setopt(ps->send_endpoint, CURLOPT_PRIVATE, ps); 2315 curl_receive_cb);
2315 curl_easy_setopt(ps->send_endpoint, CURLOPT_CONNECTTIMEOUT, HTTP_CONNECT_TIMEOUT); 2316 curl_easy_setopt (ps->send_endpoint, CURLOPT_READDATA, ps);
2316 curl_easy_setopt(ps->send_endpoint, CURLOPT_BUFFERSIZE, 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE); 2317 curl_easy_setopt (ps->send_endpoint, CURLOPT_TIMEOUT,
2318 (long) timeout.rel_value);
2319 curl_easy_setopt (ps->send_endpoint, CURLOPT_PRIVATE, ps);
2320 curl_easy_setopt (ps->send_endpoint, CURLOPT_CONNECTTIMEOUT,
2321 HTTP_CONNECT_TIMEOUT);
2322 curl_easy_setopt (ps->send_endpoint, CURLOPT_BUFFERSIZE,
2323 2 * GNUNET_SERVER_MAX_MESSAGE_SIZE);
2317#if CURL_TCP_NODELAY 2324#if CURL_TCP_NODELAY
2318 curl_easy_setopt(ps->send_endpoint, CURLOPT_TCP_NODELAY, 1); 2325 curl_easy_setopt (ps->send_endpoint, CURLOPT_TCP_NODELAY, 1);
2319#endif 2326#endif
2320 if (fresh==GNUNET_YES) 2327 if (fresh == GNUNET_YES)
2321 { 2328 {
2322 mret = curl_multi_add_handle(plugin->multi_handle, ps->send_endpoint); 2329 mret = curl_multi_add_handle (plugin->multi_handle, ps->send_endpoint);
2323 if (mret != CURLM_OK) 2330 if (mret != CURLM_OK)
2324 { 2331 {
2325 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 2332 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2326 _("Connection: %X: %s failed at %s:%d: `%s'\n"), 2333 _("Connection: %X: %s failed at %s:%d: `%s'\n"),
2327 ps, 2334 ps,
2328 "curl_multi_add_handle", __FILE__, __LINE__, 2335 "curl_multi_add_handle", __FILE__, __LINE__,
2329 curl_multi_strerror (mret)); 2336 curl_multi_strerror (mret));
2330 return GNUNET_SYSERR; 2337 return GNUNET_SYSERR;
2331 } 2338 }
2332 } 2339 }
2333 }
2334 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2335 {
2336 GNUNET_SCHEDULER_cancel(plugin->http_curl_task);
2337 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2338 }
2339 plugin->current_connections++;
2340 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2341 return GNUNET_YES;
2342 } 2340 }
2343 if (ps->direction == INBOUND) 2341 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
2344 { 2342 {
2345 GNUNET_assert (NULL != ps->pending_msgs_tail); 2343 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
2346 if ((ps->recv_connected==GNUNET_YES) && (ps->send_connected==GNUNET_YES) && 2344 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
2347 (ps->recv_force_disconnect==GNUNET_NO) && (ps->recv_force_disconnect==GNUNET_NO))
2348 return GNUNET_YES;
2349 } 2345 }
2346 plugin->current_connections++;
2347 plugin->http_curl_task = GNUNET_SCHEDULER_add_now (&curl_perform, plugin);
2348 return GNUNET_YES;
2349 }
2350 if (ps->direction == INBOUND)
2351 {
2352 GNUNET_assert (NULL != ps->pending_msgs_tail);
2353 if ((ps->recv_connected == GNUNET_YES) && (ps->send_connected == GNUNET_YES)
2354 && (ps->recv_force_disconnect == GNUNET_NO) &&
2355 (ps->recv_force_disconnect == GNUNET_NO))
2356 return GNUNET_YES;
2357 }
2350 return GNUNET_SYSERR; 2358 return GNUNET_SYSERR;
2351} 2359}
2352 2360
@@ -2362,130 +2370,129 @@ send_check_connections (struct Plugin *plugin,
2362 * @return selected session 2370 * @return selected session
2363 * 2371 *
2364 */ 2372 */
2365static struct Session * 2373static struct Session *
2366send_select_session (struct HTTP_PeerContext *pc, 2374send_select_session (struct HTTP_PeerContext *pc,
2367 const void * addr, size_t addrlen, 2375 const void *addr, size_t addrlen,
2368 int force_address, 2376 int force_address, struct Session *session)
2369 struct Session * session)
2370{ 2377{
2371 struct Session * tmp = NULL; 2378 struct Session *tmp = NULL;
2372 int addr_given = GNUNET_NO; 2379 int addr_given = GNUNET_NO;
2373 2380
2374 if ((addr!=NULL) && (addrlen>0)) 2381 if ((addr != NULL) && (addrlen > 0))
2375 addr_given = GNUNET_YES; 2382 addr_given = GNUNET_YES;
2376 2383
2377 if (force_address == GNUNET_YES) 2384 if (force_address == GNUNET_YES)
2385 {
2386 /* check session given as argument */
2387 if ((session != NULL) && (addr_given == GNUNET_YES))
2378 { 2388 {
2379 /* check session given as argument */ 2389 if (0 == memcmp (session->addr, addr, addrlen))
2380 if ((session != NULL) && (addr_given == GNUNET_YES)) 2390 {
2381 { 2391 /* connection can not be used, since it is disconnected */
2382 if (0 == memcmp(session->addr, addr, addrlen)) 2392 if ((session->recv_force_disconnect == GNUNET_NO) &&
2383 { 2393 (session->send_force_disconnect == GNUNET_NO))
2384 /* connection can not be used, since it is disconnected */ 2394 {
2385 if ( (session->recv_force_disconnect==GNUNET_NO) &&
2386 (session->send_force_disconnect==GNUNET_NO) )
2387 {
2388#if DEBUG_SESSION_SELECTION 2395#if DEBUG_SESSION_SELECTION
2389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2396 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2390 "Session %X selected: Using session passed by transport to send to forced address \n", 2397 "Session %X selected: Using session passed by transport to send to forced address \n",
2391 session); 2398 session);
2392#endif 2399#endif
2393 return session; 2400 return session;
2394 } 2401 }
2395 } 2402 }
2396 } 2403 }
2397 /* check last session used */ 2404 /* check last session used */
2398 if ((pc->last_session != NULL)&& (addr_given == GNUNET_YES)) 2405 if ((pc->last_session != NULL) && (addr_given == GNUNET_YES))
2399 { 2406 {
2400 if (0 == memcmp(pc->last_session->addr, addr, addrlen)) 2407 if (0 == memcmp (pc->last_session->addr, addr, addrlen))
2401 { 2408 {
2402 /* connection can not be used, since it is disconnected */ 2409 /* connection can not be used, since it is disconnected */
2403 if ( (pc->last_session->recv_force_disconnect==GNUNET_NO) && 2410 if ((pc->last_session->recv_force_disconnect == GNUNET_NO) &&
2404 (pc->last_session->send_force_disconnect==GNUNET_NO) ) 2411 (pc->last_session->send_force_disconnect == GNUNET_NO))
2405 { 2412 {
2406#if DEBUG_SESSION_SELECTION 2413#if DEBUG_SESSION_SELECTION
2407 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2414 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2408 "Session %X selected: Using last session used to send to forced address \n", 2415 "Session %X selected: Using last session used to send to forced address \n",
2409 pc->last_session); 2416 pc->last_session);
2410#endif 2417#endif
2411 return pc->last_session; 2418 return pc->last_session;
2412 } 2419 }
2413 } 2420 }
2414 } 2421 }
2415 /* find session in existing sessions */ 2422 /* find session in existing sessions */
2416 tmp = pc->head; 2423 tmp = pc->head;
2417 while ((tmp!=NULL) && (addr_given == GNUNET_YES)) 2424 while ((tmp != NULL) && (addr_given == GNUNET_YES))
2418 { 2425 {
2419 if (0 == memcmp(tmp->addr, addr, addrlen)) 2426 if (0 == memcmp (tmp->addr, addr, addrlen))
2420 { 2427 {
2421 /* connection can not be used, since it is disconnected */ 2428 /* connection can not be used, since it is disconnected */
2422 if ( (tmp->recv_force_disconnect==GNUNET_NO) && 2429 if ((tmp->recv_force_disconnect == GNUNET_NO) &&
2423 (tmp->send_force_disconnect==GNUNET_NO) ) 2430 (tmp->send_force_disconnect == GNUNET_NO))
2424 { 2431 {
2425#if DEBUG_SESSION_SELECTION 2432#if DEBUG_SESSION_SELECTION
2426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2427 "Session %X selected: Using existing session to send to forced address \n", 2434 "Session %X selected: Using existing session to send to forced address \n",
2428 session); 2435 session);
2429#endif 2436#endif
2430 return session; 2437 return session;
2431 } 2438 }
2432 } 2439 }
2433 tmp=tmp->next; 2440 tmp = tmp->next;
2434 }
2435 /* no session to use */
2436 return NULL;
2437 } 2441 }
2442 /* no session to use */
2443 return NULL;
2444 }
2438 if ((force_address == GNUNET_NO) || (force_address == GNUNET_SYSERR)) 2445 if ((force_address == GNUNET_NO) || (force_address == GNUNET_SYSERR))
2446 {
2447 /* check session given as argument */
2448 if (session != NULL)
2439 { 2449 {
2440 /* check session given as argument */ 2450 /* connection can not be used, since it is disconnected */
2441 if (session != NULL) 2451 if ((session->recv_force_disconnect == GNUNET_NO) &&
2442 { 2452 (session->send_force_disconnect == GNUNET_NO))
2443 /* connection can not be used, since it is disconnected */ 2453 {
2444 if ( (session->recv_force_disconnect==GNUNET_NO) &&
2445 (session->send_force_disconnect==GNUNET_NO) )
2446 {
2447#if DEBUG_SESSION_SELECTION 2454#if DEBUG_SESSION_SELECTION
2448 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2449 "Session %X selected: Using session passed by transport to send not-forced address\n", 2456 "Session %X selected: Using session passed by transport to send not-forced address\n",
2450 session); 2457 session);
2451#endif 2458#endif
2452 return session; 2459 return session;
2453 } 2460 }
2454 } 2461 }
2455 /* check last session used */ 2462 /* check last session used */
2456 if (pc->last_session != NULL) 2463 if (pc->last_session != NULL)
2457 { 2464 {
2458 /* connection can not be used, since it is disconnected */ 2465 /* connection can not be used, since it is disconnected */
2459 if ( (pc->last_session->recv_force_disconnect==GNUNET_NO) && 2466 if ((pc->last_session->recv_force_disconnect == GNUNET_NO) &&
2460 (pc->last_session->send_force_disconnect==GNUNET_NO) ) 2467 (pc->last_session->send_force_disconnect == GNUNET_NO))
2461 { 2468 {
2462#if DEBUG_SESSION_SELECTION 2469#if DEBUG_SESSION_SELECTION
2463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2464 "Session %X selected: Using last session to send to not-forced address\n", 2471 "Session %X selected: Using last session to send to not-forced address\n",
2465 pc->last_session); 2472 pc->last_session);
2466#endif 2473#endif
2467 return pc->last_session; 2474 return pc->last_session;
2468 } 2475 }
2469 } 2476 }
2470 /* find session in existing sessions */ 2477 /* find session in existing sessions */
2471 tmp = pc->head; 2478 tmp = pc->head;
2472 while (tmp!=NULL) 2479 while (tmp != NULL)
2473 { 2480 {
2474 /* connection can not be used, since it is disconnected */ 2481 /* connection can not be used, since it is disconnected */
2475 if ( (tmp->recv_force_disconnect==GNUNET_NO) && 2482 if ((tmp->recv_force_disconnect == GNUNET_NO) &&
2476 (tmp->send_force_disconnect==GNUNET_NO) ) 2483 (tmp->send_force_disconnect == GNUNET_NO))
2477 { 2484 {
2478#if DEBUG_SESSION_SELECTION 2485#if DEBUG_SESSION_SELECTION
2479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2480 "Session %X selected: Using existing session to send to not-forced address\n", 2487 "Session %X selected: Using existing session to send to not-forced address\n",
2481 tmp); 2488 tmp);
2482#endif 2489#endif
2483 return tmp; 2490 return tmp;
2484 } 2491 }
2485 tmp=tmp->next; 2492 tmp = tmp->next;
2486 }
2487 return NULL;
2488 } 2493 }
2494 return NULL;
2495 }
2489 return NULL; 2496 return NULL;
2490} 2497}
2491 2498
@@ -2537,117 +2544,112 @@ http_plugin_send (void *cls,
2537 const void *addr, 2544 const void *addr,
2538 size_t addrlen, 2545 size_t addrlen,
2539 int force_address, 2546 int force_address,
2540 GNUNET_TRANSPORT_TransmitContinuation cont, 2547 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
2541 void *cont_cls)
2542{ 2548{
2543 struct Plugin *plugin = cls; 2549 struct Plugin *plugin = cls;
2544 struct HTTP_Message *msg; 2550 struct HTTP_Message *msg;
2545 struct HTTP_PeerContext * pc; 2551 struct HTTP_PeerContext *pc;
2546 struct Session * ps = NULL; 2552 struct Session *ps = NULL;
2547 2553
2548 GNUNET_assert(cls !=NULL); 2554 GNUNET_assert (cls != NULL);
2549 2555
2550#if DEBUG_HTTP 2556#if DEBUG_HTTP
2551 char * force; 2557 char *force;
2552 2558
2553 if (force_address == GNUNET_YES) 2559 if (force_address == GNUNET_YES)
2554 GNUNET_asprintf(&force, "forced addr."); 2560 GNUNET_asprintf (&force, "forced addr.");
2555 else if (force_address == GNUNET_NO) 2561 else if (force_address == GNUNET_NO)
2556 GNUNET_asprintf(&force, "any addr."); 2562 GNUNET_asprintf (&force, "any addr.");
2557 else if (force_address == GNUNET_SYSERR) 2563 else if (force_address == GNUNET_SYSERR)
2558 GNUNET_asprintf(&force,"reliable bi-direc. address addr."); 2564 GNUNET_asprintf (&force, "reliable bi-direc. address addr.");
2559 else 2565 else
2560 GNUNET_assert (0); 2566 GNUNET_assert (0);
2561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2562 "Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n", 2568 "Transport tells me to send %u bytes to `%s' using %s (%s) and session: %X\n",
2563 msgbuf_size, 2569 msgbuf_size,
2564 GNUNET_i2s(target), 2570 GNUNET_i2s (target),
2565 force, 2571 force,
2566 http_plugin_address_to_string(NULL, addr, addrlen), 2572 http_plugin_address_to_string (NULL, addr, addrlen), session);
2567 session); 2573 GNUNET_free (force);
2568 GNUNET_free(force);
2569#endif 2574#endif
2570 2575
2571 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey); 2576 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
2572 /* Peer unknown */ 2577 /* Peer unknown */
2573 if (pc==NULL) 2578 if (pc == NULL)
2574 { 2579 {
2575 pc = GNUNET_malloc(sizeof (struct HTTP_PeerContext)); 2580 pc = GNUNET_malloc (sizeof (struct HTTP_PeerContext));
2576 pc->plugin = plugin; 2581 pc->plugin = plugin;
2577 pc->session_id_counter=1; 2582 pc->session_id_counter = 1;
2578 pc->last_session = NULL; 2583 pc->last_session = NULL;
2579 memcpy(&pc->identity, target, sizeof(struct GNUNET_PeerIdentity)); 2584 memcpy (&pc->identity, target, sizeof (struct GNUNET_PeerIdentity));
2580 GNUNET_CONTAINER_multihashmap_put (plugin->peers, 2585 GNUNET_CONTAINER_multihashmap_put (plugin->peers,
2581 &pc->identity.hashPubKey, 2586 &pc->identity.hashPubKey,
2582 pc, 2587 pc,
2583 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 2588 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
2584 GNUNET_STATISTICS_update (plugin->env->stats, 2589 GNUNET_STATISTICS_update (plugin->env->stats,
2585 gettext_noop ("# HTTP peers active"), 2590 gettext_noop ("# HTTP peers active"),
2586 1, 2591 1, GNUNET_NO);
2587 GNUNET_NO); 2592 }
2588 }
2589 ps = send_select_session (pc, addr, addrlen, force_address, session); 2593 ps = send_select_session (pc, addr, addrlen, force_address, session);
2590 /* session not existing, but address forced -> creating new session */ 2594 /* session not existing, but address forced -> creating new session */
2591 if (ps==NULL) 2595 if (ps == NULL)
2596 {
2597 if ((addr != NULL) && (addrlen != 0))
2592 { 2598 {
2593 if ((addr!=NULL) && (addrlen!=0)) 2599 ps = GNUNET_malloc (sizeof (struct Session));
2594 {
2595 ps = GNUNET_malloc(sizeof (struct Session));
2596#if DEBUG_SESSION_SELECTION 2600#if DEBUG_SESSION_SELECTION
2597 if (force_address == GNUNET_YES) 2601 if (force_address == GNUNET_YES)
2598 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2599 "No existing connection & forced address: creating new session %X to peer %s\n", 2603 "No existing connection & forced address: creating new session %X to peer %s\n",
2600 ps, GNUNET_i2s(target)); 2604 ps, GNUNET_i2s (target));
2601 if (force_address != GNUNET_YES) 2605 if (force_address != GNUNET_YES)
2602 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2606 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2603 "No existing connection: creating new session %X to peer %s\n", 2607 "No existing connection: creating new session %X to peer %s\n",
2604 ps, GNUNET_i2s(target)); 2608 ps, GNUNET_i2s (target));
2605#endif
2606 ps->addr = GNUNET_malloc(addrlen);
2607 memcpy(ps->addr,addr,addrlen);
2608 ps->addrlen = addrlen;
2609 ps->direction=OUTBOUND;
2610 ps->recv_connected = GNUNET_NO;
2611 ps->recv_force_disconnect = GNUNET_NO;
2612 ps->send_connected = GNUNET_NO;
2613 ps->send_force_disconnect = GNUNET_NO;
2614 ps->pending_msgs_head = NULL;
2615 ps->pending_msgs_tail = NULL;
2616 ps->peercontext = pc;
2617 ps->session_id = pc->session_id_counter;
2618 ps->queue_length_cur = 0;
2619 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
2620 pc->session_id_counter++;
2621 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
2622 if (ps->msgtok == NULL)
2623 ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
2624 GNUNET_CONTAINER_DLL_insert(pc->head,pc->tail,ps);
2625 GNUNET_STATISTICS_update (plugin->env->stats,
2626 gettext_noop ("# HTTP outbound sessions for peers active"),
2627 1,
2628 GNUNET_NO);
2629 }
2630 else
2631 {
2632#if DEBUG_HTTP
2633 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2634 "No existing session found & and no address given: no way to send this message to peer `%s'!\n",
2635 GNUNET_i2s(target));
2636#endif 2609#endif
2637 return GNUNET_SYSERR; 2610 ps->addr = GNUNET_malloc (addrlen);
2638 } 2611 memcpy (ps->addr, addr, addrlen);
2612 ps->addrlen = addrlen;
2613 ps->direction = OUTBOUND;
2614 ps->recv_connected = GNUNET_NO;
2615 ps->recv_force_disconnect = GNUNET_NO;
2616 ps->send_connected = GNUNET_NO;
2617 ps->send_force_disconnect = GNUNET_NO;
2618 ps->pending_msgs_head = NULL;
2619 ps->pending_msgs_tail = NULL;
2620 ps->peercontext = pc;
2621 ps->session_id = pc->session_id_counter;
2622 ps->queue_length_cur = 0;
2623 ps->queue_length_max = GNUNET_SERVER_MAX_MESSAGE_SIZE;
2624 pc->session_id_counter++;
2625 ps->url = create_url (plugin, ps->addr, ps->addrlen, ps->session_id);
2626 if (ps->msgtok == NULL)
2627 ps->msgtok = GNUNET_SERVER_mst_create (&curl_receive_mst_cb, ps);
2628 GNUNET_CONTAINER_DLL_insert (pc->head, pc->tail, ps);
2629 GNUNET_STATISTICS_update (plugin->env->stats,
2630 gettext_noop
2631 ("# HTTP outbound sessions for peers active"),
2632 1, GNUNET_NO);
2639 } 2633 }
2640 2634 else
2641 if (msgbuf_size >= (ps->queue_length_max - ps->queue_length_cur))
2642 { 2635 {
2636#if DEBUG_HTTP
2643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2644 "Queue %X full: %u bytes in queue available, message with %u is too big\n", 2638 "No existing session found & and no address given: no way to send this message to peer `%s'!\n",
2645 ps, 2639 GNUNET_i2s (target));
2646 (ps->queue_length_max - ps->queue_length_cur), 2640#endif
2647 msgbuf_size); 2641 return GNUNET_SYSERR;
2648 //return GNUNET_SYSERR;
2649 } 2642 }
2650 2643 }
2644
2645 if (msgbuf_size >= (ps->queue_length_max - ps->queue_length_cur))
2646 {
2647 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2648 "Queue %X full: %u bytes in queue available, message with %u is too big\n",
2649 ps, (ps->queue_length_max - ps->queue_length_cur), msgbuf_size);
2650 //return GNUNET_SYSERR;
2651 }
2652
2651 /* create msg */ 2653 /* create msg */
2652 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size); 2654 msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
2653 msg->next = NULL; 2655 msg->next = NULL;
@@ -2656,16 +2658,15 @@ http_plugin_send (void *cls,
2656 msg->buf = (char *) &msg[1]; 2658 msg->buf = (char *) &msg[1];
2657 msg->transmit_cont = cont; 2659 msg->transmit_cont = cont;
2658 msg->transmit_cont_cls = cont_cls; 2660 msg->transmit_cont_cls = cont_cls;
2659 memcpy (msg->buf,msgbuf, msgbuf_size); 2661 memcpy (msg->buf, msgbuf, msgbuf_size);
2660 GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head, 2662 GNUNET_CONTAINER_DLL_insert (ps->pending_msgs_head,
2661 ps->pending_msgs_tail, 2663 ps->pending_msgs_tail, msg);
2662 msg);
2663 ps->queue_length_cur += msgbuf_size; 2664 ps->queue_length_cur += msgbuf_size;
2664 if (send_check_connections (plugin, ps) == GNUNET_SYSERR) 2665 if (send_check_connections (plugin, ps) == GNUNET_SYSERR)
2665 return GNUNET_SYSERR; 2666 return GNUNET_SYSERR;
2666 if (force_address != GNUNET_YES) 2667 if (force_address != GNUNET_YES)
2667 pc->last_session = ps; 2668 pc->last_session = ps;
2668 if (pc->last_session==NULL) 2669 if (pc->last_session == NULL)
2669 pc->last_session = ps; 2670 pc->last_session = ps;
2670 return msg->size; 2671 return msg->size;
2671} 2672}
@@ -2680,49 +2681,48 @@ http_plugin_send (void *cls,
2680 * @param target peer from which to disconnect 2681 * @param target peer from which to disconnect
2681 */ 2682 */
2682static void 2683static void
2683http_plugin_disconnect (void *cls, 2684http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
2684 const struct GNUNET_PeerIdentity *target)
2685{ 2685{
2686 struct Plugin *plugin = cls; 2686 struct Plugin *plugin = cls;
2687 struct HTTP_PeerContext *pc = NULL; 2687 struct HTTP_PeerContext *pc = NULL;
2688 struct Session *ps = NULL; 2688 struct Session *ps = NULL;
2689 2689
2690 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey); 2690 pc = GNUNET_CONTAINER_multihashmap_get (plugin->peers, &target->hashPubKey);
2691 if (pc==NULL) 2691 if (pc == NULL)
2692 return; 2692 return;
2693 ps = pc->head; 2693 ps = pc->head;
2694 while (ps!=NULL) 2694 while (ps != NULL)
2695 {
2696 /* Telling transport that session is getting disconnected */
2697 plugin->env->session_end (plugin, target, ps);
2698 if (ps->direction == OUTBOUND)
2695 { 2699 {
2696 /* Telling transport that session is getting disconnected */ 2700 if (ps->send_endpoint != NULL)
2697 plugin->env->session_end(plugin, target, ps); 2701 {
2698 if (ps->direction==OUTBOUND) 2702 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint));
2699 { 2703 //curl_easy_cleanup(ps->send_endpoint);
2700 if (ps->send_endpoint!=NULL) 2704 //ps->send_endpoint=NULL;
2701 { 2705 ps->send_force_disconnect = GNUNET_YES;
2702 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->send_endpoint)); 2706 }
2703 //curl_easy_cleanup(ps->send_endpoint); 2707 if (ps->recv_endpoint != NULL)
2704 //ps->send_endpoint=NULL; 2708 {
2705 ps->send_force_disconnect = GNUNET_YES; 2709 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint));
2706 } 2710 //curl_easy_cleanup(ps->recv_endpoint);
2707 if (ps->recv_endpoint!=NULL) 2711 //ps->recv_endpoint=NULL;
2708 { 2712 ps->recv_force_disconnect = GNUNET_YES;
2709 //GNUNET_assert(CURLM_OK == curl_multi_remove_handle(plugin->multi_handle,ps->recv_endpoint)); 2713 }
2710 //curl_easy_cleanup(ps->recv_endpoint);
2711 //ps->recv_endpoint=NULL;
2712 ps->recv_force_disconnect = GNUNET_YES;
2713 }
2714 }
2715 if (ps->direction==INBOUND)
2716 {
2717 ps->recv_force_disconnect = GNUNET_YES;
2718 ps->send_force_disconnect = GNUNET_YES;
2719 }
2720 while (ps->pending_msgs_head!=NULL)
2721 remove_http_message(ps, ps->pending_msgs_head);
2722 ps->recv_active = GNUNET_NO;
2723 ps->send_active = GNUNET_NO;
2724 ps=ps->next;
2725 } 2714 }
2715 if (ps->direction == INBOUND)
2716 {
2717 ps->recv_force_disconnect = GNUNET_YES;
2718 ps->send_force_disconnect = GNUNET_YES;
2719 }
2720 while (ps->pending_msgs_head != NULL)
2721 remove_http_message (ps, ps->pending_msgs_head);
2722 ps->recv_active = GNUNET_NO;
2723 ps->send_active = GNUNET_NO;
2724 ps = ps->next;
2725 }
2726} 2726}
2727 2727
2728 2728
@@ -2739,11 +2739,11 @@ append_port (void *cls, const char *hostname)
2739 char *ret; 2739 char *ret;
2740 2740
2741 if (hostname == NULL) 2741 if (hostname == NULL)
2742 { 2742 {
2743 ppc->asc (ppc->asc_cls, NULL); 2743 ppc->asc (ppc->asc_cls, NULL);
2744 GNUNET_free (ppc); 2744 GNUNET_free (ppc);
2745 return; 2745 return;
2746 } 2746 }
2747 GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port); 2747 GNUNET_asprintf (&ret, "%s://%s:%d", PROTOCOL_PREFIX, hostname, ppc->port);
2748 2748
2749 ppc->asc (ppc->asc_cls, ret); 2749 ppc->asc (ppc->asc_cls, ret);
@@ -2768,61 +2768,57 @@ append_port (void *cls, const char *hostname)
2768 */ 2768 */
2769static void 2769static void
2770http_plugin_address_pretty_printer (void *cls, 2770http_plugin_address_pretty_printer (void *cls,
2771 const char *type, 2771 const char *type,
2772 const void *addr, 2772 const void *addr,
2773 size_t addrlen, 2773 size_t addrlen,
2774 int numeric, 2774 int numeric,
2775 struct GNUNET_TIME_Relative timeout, 2775 struct GNUNET_TIME_Relative timeout,
2776 GNUNET_TRANSPORT_AddressStringCallback 2776 GNUNET_TRANSPORT_AddressStringCallback
2777 asc, void *asc_cls) 2777 asc, void *asc_cls)
2778{ 2778{
2779 struct PrettyPrinterContext *ppc; 2779 struct PrettyPrinterContext *ppc;
2780 const void *sb; 2780 const void *sb;
2781 size_t sbs; 2781 size_t sbs;
2782 struct sockaddr_in a4; 2782 struct sockaddr_in a4;
2783 struct sockaddr_in6 a6; 2783 struct sockaddr_in6 a6;
2784 const struct IPv4HttpAddress *t4; 2784 const struct IPv4HttpAddress *t4;
2785 const struct IPv6HttpAddress *t6; 2785 const struct IPv6HttpAddress *t6;
2786 uint16_t port; 2786 uint16_t port;
2787 2787
2788 if (addrlen == sizeof (struct IPv6HttpAddress)) 2788 if (addrlen == sizeof (struct IPv6HttpAddress))
2789 { 2789 {
2790 t6 = addr; 2790 t6 = addr;
2791 memset (&a6, 0, sizeof (a6)); 2791 memset (&a6, 0, sizeof (a6));
2792 a6.sin6_family = AF_INET6; 2792 a6.sin6_family = AF_INET6;
2793 a6.sin6_port = t6->port; 2793 a6.sin6_port = t6->port;
2794 memcpy (&a6.sin6_addr, 2794 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
2795 &t6->ipv6_addr, 2795 port = ntohs (t6->port);
2796 sizeof (struct in6_addr)); 2796 sb = &a6;
2797 port = ntohs (t6->port); 2797 sbs = sizeof (a6);
2798 sb = &a6; 2798 }
2799 sbs = sizeof (a6);
2800 }
2801 else if (addrlen == sizeof (struct IPv4HttpAddress)) 2799 else if (addrlen == sizeof (struct IPv4HttpAddress))
2802 { 2800 {
2803 t4 = addr; 2801 t4 = addr;
2804 memset (&a4, 0, sizeof (a4)); 2802 memset (&a4, 0, sizeof (a4));
2805 a4.sin_family = AF_INET; 2803 a4.sin_family = AF_INET;
2806 a4.sin_port = t4->port; 2804 a4.sin_port = t4->port;
2807 a4.sin_addr.s_addr = t4->ipv4_addr; 2805 a4.sin_addr.s_addr = t4->ipv4_addr;
2808 port = ntohs (t4->ipv4_addr); 2806 port = ntohs (t4->ipv4_addr);
2809 sb = &a4; 2807 sb = &a4;
2810 sbs = sizeof (a4); 2808 sbs = sizeof (a4);
2811 } 2809 }
2812 else 2810 else
2813 { 2811 {
2814 /* invalid address */ 2812 /* invalid address */
2815 GNUNET_break_op (0); 2813 GNUNET_break_op (0);
2816 asc (asc_cls, NULL); 2814 asc (asc_cls, NULL);
2817 return; 2815 return;
2818 } 2816 }
2819 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 2817 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
2820 ppc->asc = asc; 2818 ppc->asc = asc;
2821 ppc->asc_cls = asc_cls; 2819 ppc->asc_cls = asc_cls;
2822 ppc->port = port; 2820 ppc->port = port;
2823 GNUNET_RESOLVER_hostname_get (sb, 2821 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
2824 sbs,
2825 !numeric, timeout, &append_port, ppc);
2826} 2822}
2827 2823
2828 2824
@@ -2840,8 +2836,7 @@ http_plugin_address_pretty_printer (void *cls,
2840 * and transport 2836 * and transport
2841 */ 2837 */
2842static int 2838static int
2843http_plugin_address_suggested (void *cls, 2839http_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
2844 const void *addr, size_t addrlen)
2845{ 2840{
2846 struct Plugin *plugin = cls; 2841 struct Plugin *plugin = cls;
2847 struct IPv4HttpAddress *v4; 2842 struct IPv4HttpAddress *v4;
@@ -2849,52 +2844,59 @@ http_plugin_address_suggested (void *cls,
2849 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head; 2844 struct IPv4HttpAddressWrapper *w_tv4 = plugin->ipv4_addr_head;
2850 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head; 2845 struct IPv6HttpAddressWrapper *w_tv6 = plugin->ipv6_addr_head;
2851 2846
2852 GNUNET_assert(cls !=NULL); 2847 GNUNET_assert (cls != NULL);
2853 if ((addrlen != sizeof (struct IPv4HttpAddress)) && 2848 if ((addrlen != sizeof (struct IPv4HttpAddress)) &&
2854 (addrlen != sizeof (struct IPv6HttpAddress))) 2849 (addrlen != sizeof (struct IPv6HttpAddress)))
2855 return GNUNET_SYSERR; 2850 return GNUNET_SYSERR;
2856 if (addrlen == sizeof (struct IPv4HttpAddress)) 2851 if (addrlen == sizeof (struct IPv4HttpAddress))
2852 {
2853 v4 = (struct IPv4HttpAddress *) addr;
2854 if (plugin->bind4_address != NULL)
2857 { 2855 {
2858 v4 = (struct IPv4HttpAddress *) addr; 2856 if (0 ==
2859 if (plugin->bind4_address!=NULL) 2857 memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr,
2860 { 2858 sizeof (uint32_t)))
2861 if (0 == memcmp (&plugin->bind4_address->sin_addr, &v4->ipv4_addr, sizeof(uint32_t)))
2862 return GNUNET_OK;
2863 else
2864 return GNUNET_SYSERR;
2865 }
2866 while (w_tv4!=NULL)
2867 {
2868 if (0==memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr, sizeof(uint32_t)))
2869 break;
2870 w_tv4 = w_tv4->next;
2871 }
2872 if (w_tv4 != NULL)
2873 return GNUNET_OK; 2859 return GNUNET_OK;
2874 else 2860 else
2875 return GNUNET_SYSERR; 2861 return GNUNET_SYSERR;
2862 }
2863 while (w_tv4 != NULL)
2864 {
2865 if (0 ==
2866 memcmp (&w_tv4->addr->ipv4_addr, &v4->ipv4_addr, sizeof (uint32_t)))
2867 break;
2868 w_tv4 = w_tv4->next;
2876 } 2869 }
2870 if (w_tv4 != NULL)
2871 return GNUNET_OK;
2872 else
2873 return GNUNET_SYSERR;
2874 }
2877 if (addrlen == sizeof (struct IPv6HttpAddress)) 2875 if (addrlen == sizeof (struct IPv6HttpAddress))
2876 {
2877 v6 = (struct IPv6HttpAddress *) addr;
2878 if (plugin->bind6_address != NULL)
2878 { 2879 {
2879 v6 = (struct IPv6HttpAddress *) addr; 2880 if (0 ==
2880 if (plugin->bind6_address!=NULL) 2881 memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr,
2881 { 2882 sizeof (struct in6_addr)))
2882 if (0 == memcmp (&plugin->bind6_address->sin6_addr, &v6->ipv6_addr, sizeof(struct in6_addr)))
2883 return GNUNET_OK;
2884 else
2885 return GNUNET_SYSERR;
2886 }
2887 while (w_tv6!=NULL)
2888 {
2889 if (0 == memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr, sizeof(struct in6_addr)))
2890 break;
2891 w_tv6 = w_tv6->next;
2892 }
2893 if (w_tv6 !=NULL)
2894 return GNUNET_OK; 2883 return GNUNET_OK;
2895 else 2884 else
2896 return GNUNET_SYSERR; 2885 return GNUNET_SYSERR;
2886 }
2887 while (w_tv6 != NULL)
2888 {
2889 if (0 ==
2890 memcmp (&w_tv6->addr->ipv6_addr, &v6->ipv6_addr,
2891 sizeof (struct in6_addr)))
2892 break;
2893 w_tv6 = w_tv6->next;
2897 } 2894 }
2895 if (w_tv6 != NULL)
2896 return GNUNET_OK;
2897 else
2898 return GNUNET_SYSERR;
2899 }
2898 return GNUNET_SYSERR; 2900 return GNUNET_SYSERR;
2899} 2901}
2900 2902
@@ -2910,50 +2912,44 @@ http_plugin_address_suggested (void *cls,
2910 * @param addrlen length of the address 2912 * @param addrlen length of the address
2911 * @return string representing the same address 2913 * @return string representing the same address
2912 */ 2914 */
2913static const char* 2915static const char *
2914http_plugin_address_to_string (void *cls, 2916http_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
2915 const void *addr,
2916 size_t addrlen)
2917{ 2917{
2918 const struct IPv4HttpAddress *t4; 2918 const struct IPv4HttpAddress *t4;
2919 const struct IPv6HttpAddress *t6; 2919 const struct IPv6HttpAddress *t6;
2920 struct sockaddr_in a4; 2920 struct sockaddr_in a4;
2921 struct sockaddr_in6 a6; 2921 struct sockaddr_in6 a6;
2922 char * address; 2922 char *address;
2923 static char rbuf[INET6_ADDRSTRLEN + 13]; 2923 static char rbuf[INET6_ADDRSTRLEN + 13];
2924 uint16_t port; 2924 uint16_t port;
2925 int res; 2925 int res;
2926 2926
2927 if (addrlen == sizeof (struct IPv6HttpAddress)) 2927 if (addrlen == sizeof (struct IPv6HttpAddress))
2928 { 2928 {
2929 address = GNUNET_malloc (INET6_ADDRSTRLEN); 2929 address = GNUNET_malloc (INET6_ADDRSTRLEN);
2930 t6 = addr; 2930 t6 = addr;
2931 a6.sin6_addr = t6->ipv6_addr; 2931 a6.sin6_addr = t6->ipv6_addr;
2932 inet_ntop(AF_INET6, &(a6.sin6_addr),address,INET6_ADDRSTRLEN); 2932 inet_ntop (AF_INET6, &(a6.sin6_addr), address, INET6_ADDRSTRLEN);
2933 port = ntohs(t6->port); 2933 port = ntohs (t6->port);
2934 } 2934 }
2935 else if (addrlen == sizeof (struct IPv4HttpAddress)) 2935 else if (addrlen == sizeof (struct IPv4HttpAddress))
2936 { 2936 {
2937 address = GNUNET_malloc (INET_ADDRSTRLEN); 2937 address = GNUNET_malloc (INET_ADDRSTRLEN);
2938 t4 = addr; 2938 t4 = addr;
2939 a4.sin_addr.s_addr = t4->ipv4_addr; 2939 a4.sin_addr.s_addr = t4->ipv4_addr;
2940 inet_ntop(AF_INET, &(a4.sin_addr),address,INET_ADDRSTRLEN); 2940 inet_ntop (AF_INET, &(a4.sin_addr), address, INET_ADDRSTRLEN);
2941 port = ntohs(t4->port); 2941 port = ntohs (t4->port);
2942 } 2942 }
2943 else 2943 else
2944 { 2944 {
2945 /* invalid address */ 2945 /* invalid address */
2946 return NULL; 2946 return NULL;
2947 } 2947 }
2948 2948
2949 res = GNUNET_snprintf (rbuf, 2949 res = GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", address, port);
2950 sizeof (rbuf),
2951 "%s:%u",
2952 address,
2953 port);
2954 2950
2955 GNUNET_free (address); 2951 GNUNET_free (address);
2956 GNUNET_assert(res != 0); 2952 GNUNET_assert (res != 0);
2957 return rbuf; 2953 return rbuf;
2958} 2954}
2959 2955
@@ -2968,23 +2964,21 @@ http_plugin_address_to_string (void *cls,
2968 */ 2964 */
2969static void 2965static void
2970try_connection_reversal (void *cls, 2966try_connection_reversal (void *cls,
2971 const struct sockaddr *addr, 2967 const struct sockaddr *addr, socklen_t addrlen)
2972 socklen_t addrlen)
2973{ 2968{
2974 2969
2975} 2970}
2976 2971
2977static void 2972static void
2978tcp_nat_cb_add_addr (void *cls, 2973tcp_nat_cb_add_addr (void *cls,
2979 int add_remove, 2974 int add_remove,
2980 const struct sockaddr *addr, 2975 const struct sockaddr *addr, socklen_t addrlen)
2981 socklen_t addrlen)
2982{ 2976{
2983 struct Plugin *plugin = cls; 2977 struct Plugin *plugin = cls;
2984 struct IPv4HttpAddress * t4 = NULL; 2978 struct IPv4HttpAddress *t4 = NULL;
2985 struct IPv4HttpAddressWrapper * w_t4 = NULL; 2979 struct IPv4HttpAddressWrapper *w_t4 = NULL;
2986 struct IPv6HttpAddress * t6 = NULL; 2980 struct IPv6HttpAddress *t6 = NULL;
2987 struct IPv6HttpAddressWrapper * w_t6 = NULL; 2981 struct IPv6HttpAddressWrapper *w_t6 = NULL;
2988 int af; 2982 int af;
2989 2983
2990 af = addr->sa_family; 2984 af = addr->sa_family;
@@ -2994,61 +2988,63 @@ tcp_nat_cb_add_addr (void *cls,
2994 w_t4 = plugin->ipv4_addr_head; 2988 w_t4 = plugin->ipv4_addr_head;
2995 while (w_t4 != NULL) 2989 while (w_t4 != NULL)
2996 { 2990 {
2997 int res = memcmp(&w_t4->addr->ipv4_addr, 2991 int res = memcmp (&w_t4->addr->ipv4_addr,
2998 &((struct sockaddr_in *) addr)->sin_addr, 2992 &((struct sockaddr_in *) addr)->sin_addr,
2999 sizeof (struct in_addr)); 2993 sizeof (struct in_addr));
2994
3000 if (0 == res) 2995 if (0 == res)
3001 break; 2996 break;
3002 w_t4 = w_t4->next; 2997 w_t4 = w_t4->next;
3003 } 2998 }
3004 if (w_t4 == NULL) 2999 if (w_t4 == NULL)
3005 { 3000 {
3006 w_t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddressWrapper)); 3001 w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
3007 t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); 3002 t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
3008 memcpy (&t4->ipv4_addr, 3003 memcpy (&t4->ipv4_addr,
3009 &((struct sockaddr_in *) addr)->sin_addr, 3004 &((struct sockaddr_in *) addr)->sin_addr,
3010 sizeof (struct in_addr)); 3005 sizeof (struct in_addr));
3011 t4->port = htons (plugin->port_inbound); 3006 t4->port = htons (plugin->port_inbound);
3012 3007
3013 w_t4->addr = t4; 3008 w_t4->addr = t4;
3014 3009
3015 GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, 3010 GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
3016 plugin->ipv4_addr_tail,w_t4); 3011 plugin->ipv4_addr_tail, w_t4);
3017 } 3012 }
3018 plugin->env->notify_address(plugin->env->cls, 3013 plugin->env->notify_address (plugin->env->cls,
3019 add_remove, 3014 add_remove,
3020 w_t4->addr, sizeof (struct IPv4HttpAddress)); 3015 w_t4->addr, sizeof (struct IPv4HttpAddress));
3021 3016
3022 break; 3017 break;
3023 case AF_INET6: 3018 case AF_INET6:
3024 w_t6 = plugin->ipv6_addr_head; 3019 w_t6 = plugin->ipv6_addr_head;
3025 while (w_t6) 3020 while (w_t6)
3026 { 3021 {
3027 int res = memcmp(&w_t6->addr->ipv6_addr, 3022 int res = memcmp (&w_t6->addr->ipv6_addr,
3028 &((struct sockaddr_in6 *) addr)->sin6_addr, 3023 &((struct sockaddr_in6 *) addr)->sin6_addr,
3029 sizeof (struct in6_addr)); 3024 sizeof (struct in6_addr));
3025
3030 if (0 == res) 3026 if (0 == res)
3031 break; 3027 break;
3032 w_t6 = w_t6->next; 3028 w_t6 = w_t6->next;
3033 } 3029 }
3034 if (w_t6 == NULL) 3030 if (w_t6 == NULL)
3035 { 3031 {
3036 w_t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddressWrapper)); 3032 w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
3037 t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); 3033 t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
3038 3034
3039 memcpy (&t6->ipv6_addr, 3035 memcpy (&t6->ipv6_addr,
3040 &((struct sockaddr_in6 *) addr)->sin6_addr, 3036 &((struct sockaddr_in6 *) addr)->sin6_addr,
3041 sizeof (struct in6_addr)); 3037 sizeof (struct in6_addr));
3042 t6->port = htons (plugin->port_inbound); 3038 t6->port = htons (plugin->port_inbound);
3043 3039
3044 w_t6->addr = t6; 3040 w_t6->addr = t6;
3045 3041
3046 GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, 3042 GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
3047 plugin->ipv6_addr_tail,w_t6); 3043 plugin->ipv6_addr_tail, w_t6);
3048 } 3044 }
3049 plugin->env->notify_address(plugin->env->cls, 3045 plugin->env->notify_address (plugin->env->cls,
3050 add_remove, 3046 add_remove,
3051 w_t6->addr, sizeof (struct IPv6HttpAddress)); 3047 w_t6->addr, sizeof (struct IPv6HttpAddress));
3052 break; 3048 break;
3053 default: 3049 default:
3054 return; 3050 return;
@@ -3058,13 +3054,12 @@ tcp_nat_cb_add_addr (void *cls,
3058 3054
3059static void 3055static void
3060tcp_nat_cb_remove_addr (void *cls, 3056tcp_nat_cb_remove_addr (void *cls,
3061 int add_remove, 3057 int add_remove,
3062 const struct sockaddr *addr, 3058 const struct sockaddr *addr, socklen_t addrlen)
3063 socklen_t addrlen)
3064{ 3059{
3065 struct Plugin *plugin = cls; 3060 struct Plugin *plugin = cls;
3066 struct IPv4HttpAddressWrapper * w_t4 = NULL; 3061 struct IPv4HttpAddressWrapper *w_t4 = NULL;
3067 struct IPv6HttpAddressWrapper * w_t6 = NULL; 3062 struct IPv6HttpAddressWrapper *w_t6 = NULL;
3068 int af; 3063 int af;
3069 3064
3070 af = addr->sa_family; 3065 af = addr->sa_family;
@@ -3072,45 +3067,47 @@ tcp_nat_cb_remove_addr (void *cls,
3072 { 3067 {
3073 case AF_INET: 3068 case AF_INET:
3074 w_t4 = plugin->ipv4_addr_head; 3069 w_t4 = plugin->ipv4_addr_head;
3075 while (w_t4 != NULL) 3070 while (w_t4 != NULL)
3076 { 3071 {
3077 int res = memcmp(&w_t4->addr->ipv4_addr, 3072 int res = memcmp (&w_t4->addr->ipv4_addr,
3078 &((struct sockaddr_in *) addr)->sin_addr, 3073 &((struct sockaddr_in *) addr)->sin_addr,
3079 sizeof (struct in_addr)); 3074 sizeof (struct in_addr));
3080 if (0 == res) 3075
3081 break; 3076 if (0 == res)
3082 w_t4 = w_t4->next; 3077 break;
3083 } 3078 w_t4 = w_t4->next;
3084 if (w_t4 == NULL) 3079 }
3085 return; 3080 if (w_t4 == NULL)
3086 plugin->env->notify_address(plugin->env->cls, 3081 return;
3087 add_remove, 3082 plugin->env->notify_address (plugin->env->cls,
3088 w_t4->addr, sizeof (struct IPv4HttpAddress)); 3083 add_remove,
3089 3084 w_t4->addr, sizeof (struct IPv4HttpAddress));
3090 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head, 3085
3091 plugin->ipv4_addr_tail,w_t4); 3086 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head,
3092 GNUNET_free (w_t4->addr); 3087 plugin->ipv4_addr_tail, w_t4);
3093 GNUNET_free (w_t4); 3088 GNUNET_free (w_t4->addr);
3089 GNUNET_free (w_t4);
3094 break; 3090 break;
3095 case AF_INET6: 3091 case AF_INET6:
3096 w_t6 = plugin->ipv6_addr_head; 3092 w_t6 = plugin->ipv6_addr_head;
3097 while (w_t6 != NULL) 3093 while (w_t6 != NULL)
3098 { 3094 {
3099 int res = memcmp(&w_t6->addr->ipv6_addr, 3095 int res = memcmp (&w_t6->addr->ipv6_addr,
3100 &((struct sockaddr_in6 *) addr)->sin6_addr, 3096 &((struct sockaddr_in6 *) addr)->sin6_addr,
3101 sizeof (struct in6_addr)); 3097 sizeof (struct in6_addr));
3098
3102 if (0 == res) 3099 if (0 == res)
3103 break; 3100 break;
3104 w_t6 = w_t6->next; 3101 w_t6 = w_t6->next;
3105 } 3102 }
3106 if (w_t6 == NULL) 3103 if (w_t6 == NULL)
3107 return; 3104 return;
3108 plugin->env->notify_address(plugin->env->cls, 3105 plugin->env->notify_address (plugin->env->cls,
3109 add_remove, 3106 add_remove,
3110 w_t6->addr, sizeof (struct IPv6HttpAddress)); 3107 w_t6->addr, sizeof (struct IPv6HttpAddress));
3111 3108
3112 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head, 3109 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head,
3113 plugin->ipv6_addr_tail,w_t6); 3110 plugin->ipv6_addr_tail, w_t6);
3114 GNUNET_free (w_t6->addr); 3111 GNUNET_free (w_t6->addr);
3115 GNUNET_free (w_t6); 3112 GNUNET_free (w_t6);
3116 break; 3113 break;
@@ -3132,10 +3129,9 @@ tcp_nat_cb_remove_addr (void *cls,
3132static void 3129static void
3133tcp_nat_port_map_callback (void *cls, 3130tcp_nat_port_map_callback (void *cls,
3134 int add_remove, 3131 int add_remove,
3135 const struct sockaddr *addr, 3132 const struct sockaddr *addr, socklen_t addrlen)
3136 socklen_t addrlen)
3137{ 3133{
3138 GNUNET_assert(cls !=NULL ); 3134 GNUNET_assert (cls != NULL);
3139#if DEBUG_HTTP 3135#if DEBUG_HTTP
3140 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 3136 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
3141 "NPMC called to %s address `%s'\n", 3137 "NPMC called to %s address `%s'\n",
@@ -3163,74 +3159,77 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3163 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 3159 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
3164 struct Plugin *plugin = api->cls; 3160 struct Plugin *plugin = api->cls;
3165 CURLMcode mret; 3161 CURLMcode mret;
3166 struct IPv4HttpAddressWrapper * w_t4; 3162 struct IPv4HttpAddressWrapper *w_t4;
3167 struct IPv6HttpAddressWrapper * w_t6; 3163 struct IPv6HttpAddressWrapper *w_t6;
3168 GNUNET_assert(cls !=NULL); 3164
3165 GNUNET_assert (cls != NULL);
3169 3166
3170 if (plugin->nat != NULL) 3167 if (plugin->nat != NULL)
3171 GNUNET_NAT_unregister (plugin->nat); 3168 GNUNET_NAT_unregister (plugin->nat);
3172 3169
3173 if (plugin->http_server_daemon_v4 != NULL) 3170 if (plugin->http_server_daemon_v4 != NULL)
3174 { 3171 {
3175 MHD_stop_daemon (plugin->http_server_daemon_v4); 3172 MHD_stop_daemon (plugin->http_server_daemon_v4);
3176 plugin->http_server_daemon_v4 = NULL; 3173 plugin->http_server_daemon_v4 = NULL;
3177 } 3174 }
3178 if (plugin->http_server_daemon_v6 != NULL) 3175 if (plugin->http_server_daemon_v6 != NULL)
3179 { 3176 {
3180 MHD_stop_daemon (plugin->http_server_daemon_v6); 3177 MHD_stop_daemon (plugin->http_server_daemon_v6);
3181 plugin->http_server_daemon_v6 = NULL; 3178 plugin->http_server_daemon_v6 = NULL;
3182 } 3179 }
3183 if ( plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 3180 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
3184 { 3181 {
3185 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v4); 3182 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v4);
3186 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK; 3183 plugin->http_server_task_v4 = GNUNET_SCHEDULER_NO_TASK;
3187 } 3184 }
3188 if ( plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) 3185 if (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK)
3189 { 3186 {
3190 GNUNET_SCHEDULER_cancel(plugin->http_server_task_v6); 3187 GNUNET_SCHEDULER_cancel (plugin->http_server_task_v6);
3191 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK; 3188 plugin->http_server_task_v6 = GNUNET_SCHEDULER_NO_TASK;
3192 } 3189 }
3190
3191 while (plugin->ipv4_addr_head != NULL)
3192 {
3193 w_t4 = plugin->ipv4_addr_head;
3194 GNUNET_CONTAINER_DLL_remove (plugin->ipv4_addr_head, plugin->ipv4_addr_tail,
3195 w_t4);
3196 GNUNET_free (w_t4->addr);
3197 GNUNET_free (w_t4);
3198 }
3199
3200 while (plugin->ipv6_addr_head != NULL)
3201 {
3202 w_t6 = plugin->ipv6_addr_head;
3203 GNUNET_CONTAINER_DLL_remove (plugin->ipv6_addr_head, plugin->ipv6_addr_tail,
3204 w_t6);
3205 GNUNET_free (w_t6->addr);
3206 GNUNET_free (w_t6);
3207 }
3193 3208
3194 while (plugin->ipv4_addr_head!=NULL)
3195 {
3196 w_t4 = plugin->ipv4_addr_head;
3197 GNUNET_CONTAINER_DLL_remove(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,w_t4);
3198 GNUNET_free(w_t4->addr);
3199 GNUNET_free(w_t4);
3200 }
3201
3202 while (plugin->ipv6_addr_head!=NULL)
3203 {
3204 w_t6 = plugin->ipv6_addr_head;
3205 GNUNET_CONTAINER_DLL_remove(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,w_t6);
3206 GNUNET_free(w_t6->addr);
3207 GNUNET_free(w_t6);
3208 }
3209
3210 /* free all peer information */ 3209 /* free all peer information */
3211 if (plugin->peers!=NULL) 3210 if (plugin->peers != NULL)
3212 { 3211 {
3213 GNUNET_CONTAINER_multihashmap_iterate (plugin->peers, 3212 GNUNET_CONTAINER_multihashmap_iterate (plugin->peers,
3214 &remove_peer_context_Iterator, 3213 &remove_peer_context_Iterator,
3215 plugin); 3214 plugin);
3216 GNUNET_CONTAINER_multihashmap_destroy (plugin->peers); 3215 GNUNET_CONTAINER_multihashmap_destroy (plugin->peers);
3217 } 3216 }
3218 if (plugin->multi_handle!=NULL) 3217 if (plugin->multi_handle != NULL)
3219 { 3218 {
3220 mret = curl_multi_cleanup(plugin->multi_handle); 3219 mret = curl_multi_cleanup (plugin->multi_handle);
3221 if (CURLM_OK != mret) 3220 if (CURLM_OK != mret)
3222 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3221 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
3223 "curl multihandle clean up failed\n"); 3222 "curl multihandle clean up failed\n");
3224 plugin->multi_handle = NULL; 3223 plugin->multi_handle = NULL;
3225 } 3224 }
3226 curl_global_cleanup(); 3225 curl_global_cleanup ();
3227 3226
3228 if ( plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK) 3227 if (plugin->http_curl_task != GNUNET_SCHEDULER_NO_TASK)
3229 { 3228 {
3230 GNUNET_SCHEDULER_cancel(plugin->http_curl_task); 3229 GNUNET_SCHEDULER_cancel (plugin->http_curl_task);
3231 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK; 3230 plugin->http_curl_task = GNUNET_SCHEDULER_NO_TASK;
3232 } 3231 }
3233 3232
3234 3233
3235 GNUNET_free_non_null (plugin->bind4_address); 3234 GNUNET_free_non_null (plugin->bind4_address);
3236 GNUNET_free_non_null (plugin->bind6_address); 3235 GNUNET_free_non_null (plugin->bind6_address);
@@ -3244,35 +3243,36 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
3244 GNUNET_free (api); 3243 GNUNET_free (api);
3245#if DEBUG_HTTP 3244#if DEBUG_HTTP
3246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3245 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3247 "Unload %s plugin complete...\n", 3246 "Unload %s plugin complete...\n", PROTOCOL_PREFIX);
3248 PROTOCOL_PREFIX);
3249#endif 3247#endif
3250 return NULL; 3248 return NULL;
3251} 3249}
3252 3250
3253#if BUILD_HTTPS 3251#if BUILD_HTTPS
3254static char * 3252static char *
3255load_certificate( const char * file ) 3253load_certificate (const char *file)
3256{ 3254{
3257 struct GNUNET_DISK_FileHandle * gn_file; 3255 struct GNUNET_DISK_FileHandle *gn_file;
3258 struct stat fstat; 3256 struct stat fstat;
3259 char * text = NULL; 3257 char *text = NULL;
3260 3258
3261 if (0 != STAT(file, &fstat)) 3259 if (0 != STAT (file, &fstat))
3262 return NULL; 3260 return NULL;
3263 text = GNUNET_malloc (fstat.st_size+1); 3261 text = GNUNET_malloc (fstat.st_size + 1);
3264 gn_file = GNUNET_DISK_file_open(file, GNUNET_DISK_OPEN_READ, GNUNET_DISK_PERM_USER_READ); 3262 gn_file =
3265 if (gn_file==NULL) 3263 GNUNET_DISK_file_open (file, GNUNET_DISK_OPEN_READ,
3266 { 3264 GNUNET_DISK_PERM_USER_READ);
3267 GNUNET_free(text); 3265 if (gn_file == NULL)
3268 return NULL; 3266 {
3269 } 3267 GNUNET_free (text);
3268 return NULL;
3269 }
3270 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size)) 3270 if (GNUNET_SYSERR == GNUNET_DISK_file_read (gn_file, text, fstat.st_size))
3271 { 3271 {
3272 GNUNET_free (text); 3272 GNUNET_free (text);
3273 GNUNET_DISK_file_close (gn_file); 3273 GNUNET_DISK_file_close (gn_file);
3274 return NULL; 3274 return NULL;
3275 } 3275 }
3276 text[fstat.st_size] = '\0'; 3276 text[fstat.st_size] = '\0';
3277 GNUNET_DISK_file_close (gn_file); 3277 GNUNET_DISK_file_close (gn_file);
3278 return text; 3278 return text;
@@ -3295,21 +3295,19 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3295 struct sockaddr **addrs; 3295 struct sockaddr **addrs;
3296 socklen_t *addrlens; 3296 socklen_t *addrlens;
3297 int ret; 3297 int ret;
3298 char * component_name; 3298 char *component_name;
3299
3299#if BUILD_HTTPS 3300#if BUILD_HTTPS
3300 char * key_file = NULL; 3301 char *key_file = NULL;
3301 char * cert_file = NULL; 3302 char *cert_file = NULL;
3302#endif 3303#endif
3303 3304
3304 GNUNET_assert(cls !=NULL); 3305 GNUNET_assert (cls != NULL);
3305#if DEBUG_HTTP 3306#if DEBUG_HTTP
3306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3307 "Starting %s plugin...\n", 3308 "Starting %s plugin...\n", PROTOCOL_PREFIX);
3308 PROTOCOL_PREFIX);
3309#endif 3309#endif
3310 GNUNET_asprintf(&component_name, 3310 GNUNET_asprintf (&component_name, "transport-%s", PROTOCOL_PREFIX);
3311 "transport-%s",
3312 PROTOCOL_PREFIX);
3313 3311
3314 plugin = GNUNET_malloc (sizeof (struct Plugin)); 3312 plugin = GNUNET_malloc (sizeof (struct Plugin));
3315 plugin->stats = env->stats; 3313 plugin->stats = env->stats;
@@ -3317,8 +3315,8 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3317 plugin->peers = NULL; 3315 plugin->peers = NULL;
3318 plugin->bind4_address = NULL; 3316 plugin->bind4_address = NULL;
3319 plugin->bind6_address = NULL; 3317 plugin->bind6_address = NULL;
3320 plugin->use_ipv6 = GNUNET_YES; 3318 plugin->use_ipv6 = GNUNET_YES;
3321 plugin->use_ipv4 = GNUNET_YES; 3319 plugin->use_ipv4 = GNUNET_YES;
3322 plugin->use_localaddresses = GNUNET_NO; 3320 plugin->use_localaddresses = GNUNET_NO;
3323 3321
3324 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 3322 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
@@ -3330,207 +3328,207 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3330 api->address_to_string = &http_plugin_address_to_string; 3328 api->address_to_string = &http_plugin_address_to_string;
3331 3329
3332 /* Hashing our identity to use it in URLs */ 3330 /* Hashing our identity to use it in URLs */
3333 GNUNET_CRYPTO_hash_to_enc (&(plugin->env->my_identity->hashPubKey), 3331 GNUNET_CRYPTO_hash_to_enc (&(plugin->env->my_identity->hashPubKey),
3334 &plugin->my_ascii_hash_ident); 3332 &plugin->my_ascii_hash_ident);
3335 3333
3336 3334
3337 if (GNUNET_OK != 3335 if (GNUNET_OK !=
3338 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3336 GNUNET_CONFIGURATION_get_value_number (env->cfg,
3339 component_name, 3337 component_name,
3340 "MAX_CONNECTIONS", 3338 "MAX_CONNECTIONS", &tneigh))
3341 &tneigh))
3342 tneigh = 128; 3339 tneigh = 128;
3343 plugin->max_connect_per_transport = tneigh; 3340 plugin->max_connect_per_transport = tneigh;
3344 3341
3345 3342
3346 /* Use IPv6? */ 3343 /* Use IPv6? */
3347 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3344 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv6"))
3348 component_name, "USE_IPv6")) 3345 {
3349 { 3346 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3350 plugin->use_ipv6 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3347 component_name,
3351 component_name, 3348 "USE_IPv6");
3352 "USE_IPv6"); 3349 }
3353 }
3354 /* Use IPv4? */ 3350 /* Use IPv4? */
3355 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3351 if (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "USE_IPv4"))
3356 component_name, "USE_IPv4")) 3352 {
3357 { 3353 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3358 plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3354 component_name,
3359 component_name,"USE_IPv4"); 3355 "USE_IPv4");
3360 } 3356 }
3361 /* use local addresses? */ 3357 /* use local addresses? */
3362 3358
3363 if (GNUNET_CONFIGURATION_have_value (env->cfg, 3359 if (GNUNET_CONFIGURATION_have_value (env->cfg,
3364 component_name, "USE_LOCALADDR")) 3360 component_name, "USE_LOCALADDR"))
3365 { 3361 {
3366 plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, 3362 plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
3367 component_name, 3363 component_name,
3368 "USE_LOCALADDR"); 3364 "USE_LOCALADDR");
3369 } 3365 }
3370 /* Reading port number from config file */ 3366 /* Reading port number from config file */
3371 if ((GNUNET_OK != 3367 if ((GNUNET_OK !=
3372 GNUNET_CONFIGURATION_get_value_number (env->cfg, 3368 GNUNET_CONFIGURATION_get_value_number (env->cfg,
3373 component_name, 3369 component_name,
3374 "PORT", 3370 "PORT", &port)) || (port > 65535))
3375 &port)) || 3371 {
3376 (port > 65535) ) 3372 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3377 { 3373 component_name,
3378 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3374 _
3379 component_name, 3375 ("Require valid port number for transport plugin `%s' in configuration!\n"),
3380 _("Require valid port number for transport plugin `%s' in configuration!\n"), 3376 PROTOCOL_PREFIX);
3381 PROTOCOL_PREFIX); 3377 GNUNET_free (component_name);
3382 GNUNET_free(component_name); 3378 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3383 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3379 return NULL;
3384 return NULL; 3380 }
3385 }
3386 3381
3387 /* Reading ipv4 addresse to bind to from config file */ 3382 /* Reading ipv4 addresse to bind to from config file */
3388 if ( (plugin->use_ipv4==GNUNET_YES) && 3383 if ((plugin->use_ipv4 == GNUNET_YES) &&
3389 (GNUNET_CONFIGURATION_have_value (env->cfg, 3384 (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO4")))
3390 component_name, "BINDTO4"))) 3385 {
3391 { 3386 GNUNET_break (GNUNET_OK ==
3392 GNUNET_break (GNUNET_OK == 3387 GNUNET_CONFIGURATION_get_value_string (env->cfg,
3393 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3388 component_name,
3394 component_name, 3389 "BINDTO4",
3395 "BINDTO4", 3390 &plugin->bind_hostname));
3396 &plugin->bind_hostname)); 3391 plugin->bind4_address = GNUNET_malloc (sizeof (struct sockaddr_in));
3397 plugin->bind4_address = GNUNET_malloc(sizeof(struct sockaddr_in)); 3392 plugin->bind4_address->sin_family = AF_INET;
3398 plugin->bind4_address->sin_family = AF_INET; 3393 plugin->bind4_address->sin_port = htons (port);
3399 plugin->bind4_address->sin_port = htons (port); 3394
3400 3395 if (plugin->bind_hostname != NULL)
3401 if (plugin->bind_hostname!=NULL) 3396 {
3402 { 3397 if (inet_pton
3403 if (inet_pton(AF_INET,plugin->bind_hostname, &plugin->bind4_address->sin_addr)<=0) 3398 (AF_INET, plugin->bind_hostname,
3404 { 3399 &plugin->bind4_address->sin_addr) <= 0)
3405 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3400 {
3406 component_name, 3401 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3407 _("Misconfigured address to bind to in configuration!\n")); 3402 component_name,
3408 GNUNET_free(plugin->bind4_address); 3403 _
3409 GNUNET_free(plugin->bind_hostname); 3404 ("Misconfigured address to bind to in configuration!\n"));
3410 plugin->bind_hostname = NULL; 3405 GNUNET_free (plugin->bind4_address);
3411 plugin->bind4_address = NULL; 3406 GNUNET_free (plugin->bind_hostname);
3412 } 3407 plugin->bind_hostname = NULL;
3413 } 3408 plugin->bind4_address = NULL;
3409 }
3414 } 3410 }
3415 3411 }
3412
3416 /* Reading ipv4 addresse to bind to from config file */ 3413 /* Reading ipv4 addresse to bind to from config file */
3417 if ( (plugin->use_ipv6==GNUNET_YES) && 3414 if ((plugin->use_ipv6 == GNUNET_YES) &&
3418 (GNUNET_CONFIGURATION_have_value (env->cfg, 3415 (GNUNET_CONFIGURATION_have_value (env->cfg, component_name, "BINDTO6")))
3419 component_name, "BINDTO6"))) 3416 {
3420 { 3417 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg,
3421 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (env->cfg, 3418 component_name,
3422 component_name, 3419 "BINDTO6",
3423 "BINDTO6", 3420 &plugin->bind_hostname))
3424 &plugin->bind_hostname)) 3421 {
3425 { 3422 plugin->bind6_address = GNUNET_malloc (sizeof (struct sockaddr_in6));
3426 plugin->bind6_address = GNUNET_malloc(sizeof(struct sockaddr_in6)); 3423 plugin->bind6_address->sin6_family = AF_INET6;
3427 plugin->bind6_address->sin6_family = AF_INET6; 3424 plugin->bind6_address->sin6_port = htons (port);
3428 plugin->bind6_address->sin6_port = htons (port); 3425 if (plugin->bind_hostname != NULL)
3429 if (plugin->bind_hostname!=NULL) 3426 {
3430 { 3427 if (inet_pton
3431 if (inet_pton(AF_INET6,plugin->bind_hostname, &plugin->bind6_address->sin6_addr)<=0) 3428 (AF_INET6, plugin->bind_hostname,
3432 { 3429 &plugin->bind6_address->sin6_addr) <= 0)
3433 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3430 {
3434 component_name, 3431 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3435 _("Misconfigured address to bind to in configuration!\n")); 3432 component_name,
3436 GNUNET_free(plugin->bind6_address); 3433 _
3437 GNUNET_free(plugin->bind_hostname); 3434 ("Misconfigured address to bind to in configuration!\n"));
3438 plugin->bind_hostname = NULL; 3435 GNUNET_free (plugin->bind6_address);
3439 plugin->bind6_address = NULL; 3436 GNUNET_free (plugin->bind_hostname);
3440 } 3437 plugin->bind_hostname = NULL;
3441 } 3438 plugin->bind6_address = NULL;
3442 } 3439 }
3440 }
3443 } 3441 }
3444 3442 }
3443
3445#if BUILD_HTTPS 3444#if BUILD_HTTPS
3446 /* Reading HTTPS crypto related configuration */ 3445 /* Reading HTTPS crypto related configuration */
3447 /* Get crypto init string from config */ 3446 /* Get crypto init string from config */
3448 if ( (GNUNET_OK != 3447 if ((GNUNET_OK !=
3449 GNUNET_CONFIGURATION_get_value_string (env->cfg, 3448 GNUNET_CONFIGURATION_get_value_string (env->cfg,
3450 "transport-https", 3449 "transport-https",
3451 "CRYPTO_INIT", 3450 "CRYPTO_INIT",
3452 &plugin->crypto_init)) || 3451 &plugin->crypto_init)) ||
3453 (GNUNET_OK != 3452 (GNUNET_OK !=
3454 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 3453 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
3455 "transport-https", 3454 "transport-https",
3456 "KEY_FILE", 3455 "KEY_FILE",
3457 &key_file)) || 3456 &key_file)) ||
3458 (GNUNET_OK != 3457 (GNUNET_OK !=
3459 GNUNET_CONFIGURATION_get_value_filename (env->cfg, 3458 GNUNET_CONFIGURATION_get_value_filename (env->cfg,
3460 "transport-https", 3459 "transport-https",
3461 "CERT_FILE", 3460 "CERT_FILE", &cert_file)))
3462 &cert_file)) ) 3461 {
3463 { 3462 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3464 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3463 "https",
3465 "https", 3464 _
3466 _("Required configuration options missing in section `%s'\n"), 3465 ("Required configuration options missing in section `%s'\n"),
3467 "transport-https"); 3466 "transport-https");
3468 GNUNET_free (component_name); 3467 GNUNET_free (component_name);
3469 GNUNET_free_non_null (key_file); 3468 GNUNET_free_non_null (key_file);
3470 GNUNET_free_non_null (cert_file); 3469 GNUNET_free_non_null (cert_file);
3471 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3470 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3472 return NULL; 3471 return NULL;
3473 } 3472 }
3474 3473
3475 /* read key & certificates from file */ 3474 /* read key & certificates from file */
3476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3477 "Loading TLS certificate `%s' `%s'\n", 3476 "Loading TLS certificate `%s' `%s'\n", key_file, cert_file);
3478 key_file, cert_file);
3479 3477
3480 plugin->key = load_certificate (key_file); 3478 plugin->key = load_certificate (key_file);
3481 plugin->cert = load_certificate (cert_file); 3479 plugin->cert = load_certificate (cert_file);
3482 3480
3483 if ( (plugin->key==NULL) || (plugin->cert==NULL) ) 3481 if ((plugin->key == NULL) || (plugin->cert == NULL))
3484 { 3482 {
3485 struct GNUNET_OS_Process *certcreation; 3483 struct GNUNET_OS_Process *certcreation;
3486 3484
3487 GNUNET_free_non_null (plugin->key); 3485 GNUNET_free_non_null (plugin->key);
3488 plugin->key = NULL; 3486 plugin->key = NULL;
3489 GNUNET_free_non_null (plugin->cert); 3487 GNUNET_free_non_null (plugin->cert);
3490 plugin->cert = NULL; 3488 plugin->cert = NULL;
3491#if DEBUG_HTTP 3489#if DEBUG_HTTP
3492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3493 "No usable TLS certificate found, creating certificate\n"); 3491 "No usable TLS certificate found, creating certificate\n");
3494#endif 3492#endif
3495 errno = 0; 3493 errno = 0;
3496 certcreation = GNUNET_OS_start_process (NULL, NULL, 3494 certcreation = GNUNET_OS_start_process (NULL, NULL,
3497 "gnunet-transport-certificate-creation", 3495 "gnunet-transport-certificate-creation",
3498 "gnunet-transport-certificate-creation", 3496 "gnunet-transport-certificate-creation",
3499 key_file, cert_file, 3497 key_file, cert_file, NULL);
3500 NULL); 3498 if (certcreation == NULL)
3501 if (certcreation == NULL)
3502 {
3503 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3504 "https",
3505 _("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
3506 GNUNET_free (key_file);
3507 GNUNET_free (cert_file);
3508 GNUNET_free (component_name);
3509 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3510 return NULL;
3511 }
3512 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
3513 GNUNET_OS_process_close (certcreation);
3514 plugin->key = load_certificate (key_file);
3515 plugin->cert = load_certificate (cert_file);
3516 }
3517 if ( (plugin->key==NULL) || (plugin->cert==NULL) )
3518 { 3499 {
3519 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3500 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3520 "https", 3501 "https",
3521 _("No usable TLS certificate found and creating one failed!\n"), 3502 _
3522 "transport-https"); 3503 ("Could not create a new TLS certificate, program `gnunet-transport-certificate-creation' could not be started!\n"));
3523 GNUNET_free (key_file); 3504 GNUNET_free (key_file);
3524 GNUNET_free (cert_file); 3505 GNUNET_free (cert_file);
3525 GNUNET_free (component_name); 3506 GNUNET_free (component_name);
3526 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3507 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3527 return NULL; 3508 return NULL;
3528 } 3509 }
3510 GNUNET_assert (GNUNET_OK == GNUNET_OS_process_wait (certcreation));
3511 GNUNET_OS_process_close (certcreation);
3512 plugin->key = load_certificate (key_file);
3513 plugin->cert = load_certificate (cert_file);
3514 }
3515 if ((plugin->key == NULL) || (plugin->cert == NULL))
3516 {
3517 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3518 "https",
3519 _
3520 ("No usable TLS certificate found and creating one failed!\n"),
3521 "transport-https");
3522 GNUNET_free (key_file);
3523 GNUNET_free (cert_file);
3524 GNUNET_free (component_name);
3525 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3526 return NULL;
3527 }
3529 GNUNET_free (key_file); 3528 GNUNET_free (key_file);
3530 GNUNET_free (cert_file); 3529 GNUNET_free (cert_file);
3531#if DEBUG_HTTP 3530#if DEBUG_HTTP
3532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "TLS certificate loaded\n");
3533 "TLS certificate loaded\n");
3534#endif 3532#endif
3535#endif 3533#endif
3536 3534
@@ -3538,171 +3536,199 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
3538 plugin->port_inbound = port; 3536 plugin->port_inbound = port;
3539 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT; 3537 gn_timeout = GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT;
3540 unsigned int timeout = (gn_timeout.rel_value) / 1000; 3538 unsigned int timeout = (gn_timeout.rel_value) / 1000;
3541 if ( (plugin->http_server_daemon_v6 == NULL) && 3539
3542 (plugin->use_ipv6 == GNUNET_YES) && 3540 if ((plugin->http_server_daemon_v6 == NULL) &&
3543 (port != 0) ) 3541 (plugin->use_ipv6 == GNUNET_YES) && (port != 0))
3544 { 3542 {
3545 struct sockaddr * tmp = (struct sockaddr *) plugin->bind6_address; 3543 struct sockaddr *tmp = (struct sockaddr *) plugin->bind6_address;
3546 plugin->http_server_daemon_v6 = MHD_start_daemon ( 3544
3545 plugin->http_server_daemon_v6 = MHD_start_daemon (
3547#if DEBUG_MHD 3546#if DEBUG_MHD
3548 MHD_USE_DEBUG | 3547 MHD_USE_DEBUG |
3549#endif 3548#endif
3550#if BUILD_HTTPS 3549#if BUILD_HTTPS
3551 MHD_USE_SSL | 3550 MHD_USE_SSL |
3552#endif 3551#endif
3553 MHD_USE_IPv6, 3552 MHD_USE_IPv6,
3554 port, 3553 port,
3555 &mhd_accept_cb, plugin, 3554 &mhd_accept_cb, plugin,
3556 &mhd_access_cb, plugin, 3555 &mhd_access_cb, plugin,
3557 MHD_OPTION_SOCK_ADDR, tmp, 3556 MHD_OPTION_SOCK_ADDR,
3558 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport, 3557 tmp,
3558 MHD_OPTION_CONNECTION_LIMIT,
3559 (unsigned int)
3560 plugin->max_connect_per_transport,
3559#if BUILD_HTTPS 3561#if BUILD_HTTPS
3560 MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, 3562 MHD_OPTION_HTTPS_PRIORITIES,
3561 MHD_OPTION_HTTPS_MEM_KEY, plugin->key, 3563 plugin->crypto_init,
3562 MHD_OPTION_HTTPS_MEM_CERT, plugin->cert, 3564 MHD_OPTION_HTTPS_MEM_KEY,
3563#endif 3565 plugin->key,
3564 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) timeout, 3566 MHD_OPTION_HTTPS_MEM_CERT,
3565 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 * GNUNET_SERVER_MAX_MESSAGE_SIZE), 3567 plugin->cert,
3566 MHD_OPTION_NOTIFY_COMPLETED, &mhd_termination_cb, plugin, 3568#endif
3567 MHD_OPTION_EXTERNAL_LOGGER, mhd_logger, plugin->mhd_log, 3569 MHD_OPTION_CONNECTION_TIMEOUT,
3568 MHD_OPTION_END); 3570 (unsigned int) timeout,
3569 } 3571 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
3570 if ( (plugin->http_server_daemon_v4 == NULL) && 3572 (size_t) (2 *
3571 (plugin->use_ipv4 == GNUNET_YES) && 3573 GNUNET_SERVER_MAX_MESSAGE_SIZE),
3572 (port != 0) ) 3574 MHD_OPTION_NOTIFY_COMPLETED,
3573 { 3575 &mhd_termination_cb,
3574 plugin->http_server_daemon_v4 = MHD_start_daemon ( 3576 plugin,
3577 MHD_OPTION_EXTERNAL_LOGGER,
3578 mhd_logger,
3579 plugin->mhd_log,
3580 MHD_OPTION_END);
3581 }
3582 if ((plugin->http_server_daemon_v4 == NULL) &&
3583 (plugin->use_ipv4 == GNUNET_YES) && (port != 0))
3584 {
3585 plugin->http_server_daemon_v4 = MHD_start_daemon (
3575#if DEBUG_MHD 3586#if DEBUG_MHD
3576 MHD_USE_DEBUG | 3587 MHD_USE_DEBUG |
3577#endif 3588#endif
3578#if BUILD_HTTPS 3589#if BUILD_HTTPS
3579 MHD_USE_SSL | 3590 MHD_USE_SSL |
3580#endif 3591#endif
3581 MHD_NO_FLAG, 3592 MHD_NO_FLAG,
3582 port, 3593 port,
3583 &mhd_accept_cb, plugin , 3594 &mhd_accept_cb, plugin,
3584 &mhd_access_cb, plugin, 3595 &mhd_access_cb, plugin,
3585 MHD_OPTION_SOCK_ADDR, (struct sockaddr_in *) plugin->bind4_address, 3596 MHD_OPTION_SOCK_ADDR,
3586 MHD_OPTION_CONNECTION_LIMIT, (unsigned int) plugin->max_connect_per_transport, 3597 (struct sockaddr_in *)
3598 plugin->bind4_address,
3599 MHD_OPTION_CONNECTION_LIMIT,
3600 (unsigned int)
3601 plugin->max_connect_per_transport,
3587#if BUILD_HTTPS 3602#if BUILD_HTTPS
3588 MHD_OPTION_HTTPS_PRIORITIES, plugin->crypto_init, 3603 MHD_OPTION_HTTPS_PRIORITIES,
3589 3604 plugin->crypto_init,
3590 MHD_OPTION_HTTPS_MEM_KEY, plugin->key, 3605 MHD_OPTION_HTTPS_MEM_KEY,
3591 MHD_OPTION_HTTPS_MEM_CERT, plugin->cert, 3606 plugin->key,
3592#endif 3607 MHD_OPTION_HTTPS_MEM_CERT,
3593 MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) timeout, 3608 plugin->cert,
3594 MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (2 * GNUNET_SERVER_MAX_MESSAGE_SIZE), 3609#endif
3595 MHD_OPTION_NOTIFY_COMPLETED, &mhd_termination_cb, plugin, 3610 MHD_OPTION_CONNECTION_TIMEOUT,
3596 MHD_OPTION_EXTERNAL_LOGGER, mhd_logger, plugin->mhd_log, 3611 (unsigned int) timeout,
3597 MHD_OPTION_END); 3612 MHD_OPTION_CONNECTION_MEMORY_LIMIT,
3598 } 3613 (size_t) (2 *
3614 GNUNET_SERVER_MAX_MESSAGE_SIZE),
3615 MHD_OPTION_NOTIFY_COMPLETED,
3616 &mhd_termination_cb,
3617 plugin,
3618 MHD_OPTION_EXTERNAL_LOGGER,
3619 mhd_logger,
3620 plugin->mhd_log,
3621 MHD_OPTION_END);
3622 }
3599 if (plugin->http_server_daemon_v4 != NULL) 3623 if (plugin->http_server_daemon_v4 != NULL)
3600 plugin->http_server_task_v4 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4); 3624 plugin->http_server_task_v4 =
3625 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v4);
3601 if (plugin->http_server_daemon_v6 != NULL) 3626 if (plugin->http_server_daemon_v6 != NULL)
3602 plugin->http_server_task_v6 = http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6); 3627 plugin->http_server_task_v6 =
3603 3628 http_server_daemon_prepare (plugin, plugin->http_server_daemon_v6);
3604 3629
3630
3605 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) 3631 if (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK)
3606 { 3632 {
3607#if DEBUG_HTTP 3633#if DEBUG_HTTP
3608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3609 "Starting MHD with IPv4 bound to %s with port %u\n", 3635 "Starting MHD with IPv4 bound to %s with port %u\n",
3610 (plugin->bind_hostname!=NULL) ? plugin->bind_hostname : "every address",port); 3636 (plugin->bind_hostname !=
3637 NULL) ? plugin->bind_hostname : "every address", port);
3611#endif 3638#endif
3612 } 3639 }
3613 else if ( (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) && 3640 else if ((plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
3614 (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK) ) 3641 (plugin->http_server_task_v4 != GNUNET_SCHEDULER_NO_TASK))
3615 { 3642 {
3616#if DEBUG_HTTP 3643#if DEBUG_HTTP
3617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3618 "Starting MHD with IPv6 bound to %s with port %u\n", 3645 "Starting MHD with IPv6 bound to %s with port %u\n",
3619 (plugin->bind_hostname!=NULL) ? plugin->bind_hostname : "every address", port); 3646 (plugin->bind_hostname !=
3647 NULL) ? plugin->bind_hostname : "every address", port);
3620#endif 3648#endif
3621 } 3649 }
3622 else if ( (plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) && 3650 else if ((plugin->http_server_task_v6 != GNUNET_SCHEDULER_NO_TASK) &&
3623 (plugin->http_server_task_v4 == GNUNET_SCHEDULER_NO_TASK) ) 3651 (plugin->http_server_task_v4 == GNUNET_SCHEDULER_NO_TASK))
3624 { 3652 {
3625#if DEBUG_HTTP 3653#if DEBUG_HTTP
3626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3627 "Starting MHD with IPv4 and IPv6 bound to %s with port %u\n", 3655 "Starting MHD with IPv4 and IPv6 bound to %s with port %u\n",
3628 (plugin->bind_hostname!=NULL) ? plugin->bind_hostname : "every address", 3656 (plugin->bind_hostname !=
3629 port); 3657 NULL) ? plugin->bind_hostname : "every address", port);
3630#endif 3658#endif
3631 } 3659 }
3632 else 3660 else
3633 { 3661 {
3634 char * tmp = NULL; 3662 char *tmp = NULL;
3635 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_YES)) 3663
3636 GNUNET_asprintf(&tmp,"with IPv4 and IPv6 enabled"); 3664 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_YES))
3637 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_YES)) 3665 GNUNET_asprintf (&tmp, "with IPv4 and IPv6 enabled");
3638 GNUNET_asprintf(&tmp,"with IPv4 enabled"); 3666 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_YES))
3639 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_NO)) 3667 GNUNET_asprintf (&tmp, "with IPv4 enabled");
3640 GNUNET_asprintf(&tmp,"with IPv6 enabled"); 3668 if ((plugin->use_ipv6 == GNUNET_YES) && (plugin->use_ipv4 == GNUNET_NO))
3641 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_NO)) 3669 GNUNET_asprintf (&tmp, "with IPv6 enabled");
3642 GNUNET_asprintf(&tmp,"with NO IP PROTOCOL enabled"); 3670 if ((plugin->use_ipv6 == GNUNET_NO) && (plugin->use_ipv4 == GNUNET_NO))
3643 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 3671 GNUNET_asprintf (&tmp, "with NO IP PROTOCOL enabled");
3644 _("HTTP Server with %s could not be started on port %u! %s plugin failed!\n"), 3672 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3645 tmp, port, PROTOCOL_PREFIX); 3673 _
3646 GNUNET_free (tmp); 3674 ("HTTP Server with %s could not be started on port %u! %s plugin failed!\n"),
3647 GNUNET_free (component_name); 3675 tmp, port, PROTOCOL_PREFIX);
3648 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3676 GNUNET_free (tmp);
3649 return NULL; 3677 GNUNET_free (component_name);
3650 } 3678 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3651 3679 return NULL;
3680 }
3681
3652 /* Initializing cURL */ 3682 /* Initializing cURL */
3653 curl_global_init(CURL_GLOBAL_ALL); 3683 curl_global_init (CURL_GLOBAL_ALL);
3654 plugin->multi_handle = curl_multi_init(); 3684 plugin->multi_handle = curl_multi_init ();
3655 3685
3656 if ( NULL == plugin->multi_handle ) 3686 if (NULL == plugin->multi_handle)
3657 { 3687 {
3658 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 3688 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
3659 component_name, 3689 component_name,
3660 _("Could not initialize curl multi handle, failed to start %s plugin!\n"), 3690 _
3661 PROTOCOL_PREFIX); 3691 ("Could not initialize curl multi handle, failed to start %s plugin!\n"),
3662 GNUNET_free(component_name); 3692 PROTOCOL_PREFIX);
3663 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); 3693 GNUNET_free (component_name);
3664 return NULL; 3694 LIBGNUNET_PLUGIN_TRANSPORT_DONE (api);
3665 } 3695 return NULL;
3666 3696 }
3697
3667 ret = GNUNET_SERVICE_get_server_addresses (component_name, 3698 ret = GNUNET_SERVICE_get_server_addresses (component_name,
3668 env->cfg, 3699 env->cfg, &addrs, &addrlens);
3669 &addrs,
3670 &addrlens);
3671 3700
3672 if (ret != GNUNET_SYSERR) 3701 if (ret != GNUNET_SYSERR)
3673 { 3702 {
3674 plugin->nat = GNUNET_NAT_register (env->cfg, 3703 plugin->nat = GNUNET_NAT_register (env->cfg,
3675 GNUNET_YES, 3704 GNUNET_YES,
3676 port, 3705 port,
3677 (unsigned int) ret, 3706 (unsigned int) ret,
3678 (const struct sockaddr **) addrs, 3707 (const struct sockaddr **) addrs,
3679 addrlens, 3708 addrlens,
3680 &tcp_nat_port_map_callback, 3709 &tcp_nat_port_map_callback,
3681 &try_connection_reversal, 3710 &try_connection_reversal, plugin);
3682 plugin); 3711 while (ret > 0)
3683 while (ret > 0) 3712 {
3684 { 3713 ret--;
3685 ret--; 3714 GNUNET_assert (addrs[ret] != NULL);
3686 GNUNET_assert (addrs[ret] != NULL); 3715 GNUNET_free (addrs[ret]);
3687 GNUNET_free (addrs[ret]); 3716 }
3688 } 3717 GNUNET_free_non_null (addrs);
3689 GNUNET_free_non_null (addrs); 3718 GNUNET_free_non_null (addrlens);
3690 GNUNET_free_non_null (addrlens);
3691 } 3719 }
3692 else 3720 else
3693 { 3721 {
3694 plugin->nat = GNUNET_NAT_register (env->cfg, 3722 plugin->nat = GNUNET_NAT_register (env->cfg,
3695 GNUNET_YES, 3723 GNUNET_YES,
3696 0, 3724 0,
3697 0, NULL, NULL, 3725 0, NULL, NULL,
3698 NULL, 3726 NULL, &try_connection_reversal, plugin);
3699 &try_connection_reversal,
3700 plugin);
3701 } 3727 }
3702 3728
3703 plugin->peers = GNUNET_CONTAINER_multihashmap_create (10); 3729 plugin->peers = GNUNET_CONTAINER_multihashmap_create (10);
3704 3730
3705 GNUNET_free(component_name); 3731 GNUNET_free (component_name);
3706 //GNUNET_SCHEDULER_add_now(address_notification, plugin); 3732 //GNUNET_SCHEDULER_add_now(address_notification, plugin);
3707 return api; 3733 return api;
3708} 3734}
diff --git a/src/transport/plugin_transport_smtp.c b/src/transport/plugin_transport_smtp.c
index 9c0ac5ea5..074bc16fc 100644
--- a/src/transport/plugin_transport_smtp.c
+++ b/src/transport/plugin_transport_smtp.c
@@ -146,7 +146,7 @@ static GNUNET_CronTime last_transmission;
146 146
147#define FILLCHAR '=' 147#define FILLCHAR '='
148static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 148static char *cvt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
149 "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; 149 "abcdefghijklmnopqrstuvwxyz" "0123456789+/";
150 150
151/** 151/**
152 * Encode into Base64. 152 * Encode into Base64.
@@ -179,41 +179,41 @@ base64_encode (const char *data, unsigned int len, char **output)
179 opt[1] = '\n'; 179 opt[1] = '\n';
180 ret += 2; 180 ret += 2;
181 for (i = 0; i < len; ++i) 181 for (i = 0; i < len; ++i)
182 {
183 c = (data[i] >> 2) & 0x3f;
184 opt[ret++] = cvt[(int) c];
185 CHECKLINE;
186 c = (data[i] << 4) & 0x3f;
187 if (++i < len)
188 c |= (data[i] >> 4) & 0x0f;
189 opt[ret++] = cvt[(int) c];
190 CHECKLINE;
191 if (i < len)
182 { 192 {
183 c = (data[i] >> 2) & 0x3f; 193 c = (data[i] << 2) & 0x3f;
194 if (++i < len)
195 c |= (data[i] >> 6) & 0x03;
184 opt[ret++] = cvt[(int) c]; 196 opt[ret++] = cvt[(int) c];
185 CHECKLINE; 197 CHECKLINE;
186 c = (data[i] << 4) & 0x3f; 198 }
187 if (++i < len) 199 else
188 c |= (data[i] >> 4) & 0x0f; 200 {
201 ++i;
202 opt[ret++] = FILLCHAR;
203 CHECKLINE;
204 }
205 if (i < len)
206 {
207 c = data[i] & 0x3f;
189 opt[ret++] = cvt[(int) c]; 208 opt[ret++] = cvt[(int) c];
190 CHECKLINE; 209 CHECKLINE;
191 if (i < len)
192 {
193 c = (data[i] << 2) & 0x3f;
194 if (++i < len)
195 c |= (data[i] >> 6) & 0x03;
196 opt[ret++] = cvt[(int) c];
197 CHECKLINE;
198 }
199 else
200 {
201 ++i;
202 opt[ret++] = FILLCHAR;
203 CHECKLINE;
204 }
205 if (i < len)
206 {
207 c = data[i] & 0x3f;
208 opt[ret++] = cvt[(int) c];
209 CHECKLINE;
210 }
211 else
212 {
213 opt[ret++] = FILLCHAR;
214 CHECKLINE;
215 }
216 } 210 }
211 else
212 {
213 opt[ret++] = FILLCHAR;
214 CHECKLINE;
215 }
216 }
217 opt[ret++] = FILLCHAR; 217 opt[ret++] = FILLCHAR;
218 return ret; 218 return ret;
219} 219}
@@ -252,38 +252,38 @@ base64_decode (const char *data, unsigned int len, char **output)
252 "base64_decode decoding len=%d\n", len); 252 "base64_decode decoding len=%d\n", len);
253#endif 253#endif
254 for (i = 0; i < len; ++i) 254 for (i = 0; i < len; ++i)
255 {
256 CHECK_CRLF;
257 if (data[i] == FILLCHAR)
258 break;
259 c = (char) cvtfind (data[i]);
260 ++i;
261 CHECK_CRLF;
262 c1 = (char) cvtfind (data[i]);
263 c = (c << 2) | ((c1 >> 4) & 0x3);
264 (*output)[ret++] = c;
265 if (++i < len)
255 { 266 {
256 CHECK_CRLF; 267 CHECK_CRLF;
257 if (data[i] == FILLCHAR) 268 c = data[i];
269 if (FILLCHAR == c)
258 break; 270 break;
259 c = (char) cvtfind (data[i]); 271 c = (char) cvtfind (c);
260 ++i; 272 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
273 (*output)[ret++] = c1;
274 }
275 if (++i < len)
276 {
261 CHECK_CRLF; 277 CHECK_CRLF;
262 c1 = (char) cvtfind (data[i]); 278 c1 = data[i];
263 c = (c << 2) | ((c1 >> 4) & 0x3); 279 if (FILLCHAR == c1)
280 break;
281
282 c1 = (char) cvtfind (c1);
283 c = ((c << 6) & 0xc0) | c1;
264 (*output)[ret++] = c; 284 (*output)[ret++] = c;
265 if (++i < len)
266 {
267 CHECK_CRLF;
268 c = data[i];
269 if (FILLCHAR == c)
270 break;
271 c = (char) cvtfind (c);
272 c1 = ((c1 << 4) & 0xf0) | ((c >> 2) & 0xf);
273 (*output)[ret++] = c1;
274 }
275 if (++i < len)
276 {
277 CHECK_CRLF;
278 c1 = data[i];
279 if (FILLCHAR == c1)
280 break;
281
282 c1 = (char) cvtfind (c1);
283 c = ((c << 6) & 0xc0) | c1;
284 (*output)[ret++] = c;
285 }
286 } 285 }
286 }
287END: 287END:
288 return ret; 288 return ret;
289} 289}
@@ -323,83 +323,83 @@ listenAndDistribute (void *unused)
323 323
324 324
325 while (smtp_shutdown == GNUNET_NO) 325 while (smtp_shutdown == GNUNET_NO)
326 {
327 fd = OPEN (pipename, O_RDONLY | O_ASYNC);
328 if (fd == -1)
326 { 329 {
327 fd = OPEN (pipename, O_RDONLY | O_ASYNC); 330 if (smtp_shutdown == GNUNET_NO)
328 if (fd == -1) 331 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS);
329 { 332 continue;
330 if (smtp_shutdown == GNUNET_NO) 333 }
331 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); 334 fdes = fdopen (fd, "r");
332 continue; 335 while (smtp_shutdown == GNUNET_NO)
333 } 336 {
334 fdes = fdopen (fd, "r"); 337 /* skip until end of header */
335 while (smtp_shutdown == GNUNET_NO) 338 do
336 { 339 {
337 /* skip until end of header */ 340 READLINE (line, linesize);
338 do 341 }
339 { 342 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */
340 READLINE (line, linesize); 343 READLINE (line, linesize); /* read base64 encoded message; decode, process */
341 } 344 pos = 0;
342 while ((line[0] != '\r') && (line[0] != '\n')); /* expect newline */ 345 while (1)
343 READLINE (line, linesize); /* read base64 encoded message; decode, process */ 346 {
344 pos = 0; 347 pos = strlen (line) - 1; /* ignore new line */
345 while (1) 348 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */
346 { 349 if ((line[pos] == '\r') || (line[pos] == '\n'))
347 pos = strlen (line) - 1; /* ignore new line */ 350 break; /* empty line => end of message! */
348 READLINE (&line[pos], linesize - pos); /* read base64 encoded message; decode, process */ 351 }
349 if ((line[pos] == '\r') || (line[pos] == '\n')) 352 size = base64_decode (line, pos, &out);
350 break; /* empty line => end of message! */ 353 if (size < sizeof (SMTPMessage))
351 } 354 {
352 size = base64_decode (line, pos, &out); 355 GNUNET_GE_BREAK (ectx, 0);
353 if (size < sizeof (SMTPMessage)) 356 GNUNET_free (out);
354 { 357 goto END;
355 GNUNET_GE_BREAK (ectx, 0); 358 }
356 GNUNET_free (out); 359
357 goto END; 360 mp = (SMTPMessage *) &out[size - sizeof (SMTPMessage)];
358 } 361 if (ntohs (mp->header.size) != size)
359 362 {
360 mp = (SMTPMessage *) & out[size - sizeof (SMTPMessage)]; 363 GNUNET_GE_LOG (ectx,
361 if (ntohs (mp->header.size) != size) 364 GNUNET_GE_WARNING | GNUNET_GE_BULK |
362 { 365 GNUNET_GE_USER,
363 GNUNET_GE_LOG (ectx, 366 _
364 GNUNET_GE_WARNING | GNUNET_GE_BULK | 367 ("Received malformed message via %s. Ignored.\n"),
365 GNUNET_GE_USER, 368 "SMTP");
366 _
367 ("Received malformed message via %s. Ignored.\n"),
368 "SMTP");
369#if DEBUG_SMTP
370 GNUNET_GE_LOG (ectx,
371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
372 GNUNET_GE_USER,
373 "Size returned by base64=%d, in the msg=%d.\n",
374 size, ntohl (mp->size));
375#endif
376 GNUNET_free (out);
377 goto END;
378 }
379 if (stats != NULL)
380 stats->change (stat_bytesReceived, size);
381 coreMP = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
382 coreMP->msg = out;
383 coreMP->size = size - sizeof (SMTPMessage);
384 coreMP->tsession = NULL;
385 coreMP->sender = mp->sender;
386#if DEBUG_SMTP 369#if DEBUG_SMTP
387 GNUNET_GE_LOG (ectx, 370 GNUNET_GE_LOG (ectx,
388 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 371 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST |
389 "SMTP message passed to the core.\n"); 372 GNUNET_GE_USER,
373 "Size returned by base64=%d, in the msg=%d.\n",
374 size, ntohl (mp->size));
390#endif 375#endif
391 376 GNUNET_free (out);
392 coreAPI->receive (coreMP); 377 goto END;
393 } 378 }
394 END: 379 if (stats != NULL)
380 stats->change (stat_bytesReceived, size);
381 coreMP = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
382 coreMP->msg = out;
383 coreMP->size = size - sizeof (SMTPMessage);
384 coreMP->tsession = NULL;
385 coreMP->sender = mp->sender;
395#if DEBUG_SMTP 386#if DEBUG_SMTP
396 GNUNET_GE_LOG (ectx, 387 GNUNET_GE_LOG (ectx,
397 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER, 388 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
398 "SMTP message processed.\n"); 389 "SMTP message passed to the core.\n");
399#endif 390#endif
400 if (fdes != NULL) 391
401 fclose (fdes); 392 coreAPI->receive (coreMP);
402 } 393 }
394END:
395#if DEBUG_SMTP
396 GNUNET_GE_LOG (ectx,
397 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
398 "SMTP message processed.\n");
399#endif
400 if (fdes != NULL)
401 fclose (fdes);
402 }
403 GNUNET_free (line); 403 GNUNET_free (line);
404 return NULL; 404 return NULL;
405} 405}
@@ -425,10 +425,10 @@ api_verify_hello (const GNUNET_MessageHello * hello)
425 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) || 425 sizeof (GNUNET_MessageHello) + ntohs (hello->senderAddressSize)) ||
426 (maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 - 426 (maddr->senderAddress[ntohs (hello->senderAddressSize) - 1 -
427 FILTER_STRING_SIZE] != '\0')) 427 FILTER_STRING_SIZE] != '\0'))
428 { 428 {
429 GNUNET_GE_BREAK (ectx, 0); 429 GNUNET_GE_BREAK (ectx, 0);
430 return GNUNET_SYSERR; /* obviously invalid */ 430 return GNUNET_SYSERR; /* obviously invalid */
431 } 431 }
432 if (NULL == strstr (maddr->filter, ": ")) 432 if (NULL == strstr (maddr->filter, ": "))
433 return GNUNET_SYSERR; 433 return GNUNET_SYSERR;
434 return GNUNET_OK; 434 return GNUNET_OK;
@@ -453,27 +453,26 @@ api_create_hello ()
453 "SMTP", "FILTER", 453 "SMTP", "FILTER",
454 "X-mailer: GNUnet", &filter); 454 "X-mailer: GNUnet", &filter);
455 if (NULL == strstr (filter, ": ")) 455 if (NULL == strstr (filter, ": "))
456 { 456 {
457 GNUNET_GE_LOG (ectx, 457 GNUNET_GE_LOG (ectx,
458 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 458 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
459 _("SMTP filter string to invalid, lacks ': '\n")); 459 _("SMTP filter string to invalid, lacks ': '\n"));
460 GNUNET_free (filter); 460 GNUNET_free (filter);
461 return NULL; 461 return NULL;
462 } 462 }
463 463
464 if (strlen (filter) > FILTER_STRING_SIZE) 464 if (strlen (filter) > FILTER_STRING_SIZE)
465 { 465 {
466 filter[FILTER_STRING_SIZE] = '\0'; 466 filter[FILTER_STRING_SIZE] = '\0';
467 GNUNET_GE_LOG (ectx, 467 GNUNET_GE_LOG (ectx,
468 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER, 468 GNUNET_GE_WARNING | GNUNET_GE_BULK | GNUNET_GE_USER,
469 _("SMTP filter string to long, capped to `%s'\n"), 469 _("SMTP filter string to long, capped to `%s'\n"), filter);
470 filter); 470 }
471 }
472 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */ 471 i = (strlen (email) + 8) & (~7); /* make multiple of 8 */
473 msg = 472 msg =
474 GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i); 473 GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
475 memset (msg, 0, sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i); 474 memset (msg, 0, sizeof (GNUNET_MessageHello) + sizeof (EmailAddress) + i);
476 haddr = (EmailAddress *) & msg[1]; 475 haddr = (EmailAddress *) &msg[1];
477 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE); 476 memset (&haddr->filter[0], 0, FILTER_STRING_SIZE);
478 strcpy (&haddr->filter[0], filter); 477 strcpy (&haddr->filter[0], filter);
479 memcpy (&haddr->senderAddress[0], email, strlen (email) + 1); 478 memcpy (&haddr->senderAddress[0], email, strlen (email) + 1);
@@ -501,10 +500,10 @@ get_message (void **buf, int *len, void *cls)
501 500
502 *buf = NULL; 501 *buf = NULL;
503 if (len == NULL) 502 if (len == NULL)
504 { 503 {
505 gmc->pos = 0; 504 gmc->pos = 0;
506 return NULL; 505 return NULL;
507 } 506 }
508 if (gmc->pos == gmc->esize) 507 if (gmc->pos == gmc->esize)
509 return NULL; /* done */ 508 return NULL; /* done */
510 *len = gmc->esize; 509 *len = gmc->esize;
@@ -535,6 +534,7 @@ api_send (GNUNET_TSession * tsession,
535 smtp_session_t session; 534 smtp_session_t session;
536 smtp_message_t message; 535 smtp_message_t message;
537 smtp_recipient_t recipient; 536 smtp_recipient_t recipient;
537
538#define EBUF_LEN 128 538#define EBUF_LEN 128
539 char ebuf[EBUF_LEN]; 539 char ebuf[EBUF_LEN];
540 GNUNET_CronTime now; 540 GNUNET_CronTime now;
@@ -542,10 +542,10 @@ api_send (GNUNET_TSession * tsession,
542 if (smtp_shutdown == GNUNET_YES) 542 if (smtp_shutdown == GNUNET_YES)
543 return GNUNET_SYSERR; 543 return GNUNET_SYSERR;
544 if ((size == 0) || (size > smtpAPI.mtu)) 544 if ((size == 0) || (size > smtpAPI.mtu))
545 { 545 {
546 GNUNET_GE_BREAK (ectx, 0); 546 GNUNET_GE_BREAK (ectx, 0);
547 return GNUNET_SYSERR; 547 return GNUNET_SYSERR;
548 } 548 }
549 now = GNUNET_get_time (); 549 now = GNUNET_get_time ();
550 if ((important != GNUNET_YES) && 550 if ((important != GNUNET_YES) &&
551 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS) 551 ((now - last_transmission) * rate_limit) < GNUNET_CRON_HOURS)
@@ -558,42 +558,42 @@ api_send (GNUNET_TSession * tsession,
558 GNUNET_mutex_lock (lock); 558 GNUNET_mutex_lock (lock);
559 session = smtp_create_session (); 559 session = smtp_create_session ();
560 if (session == NULL) 560 if (session == NULL)
561 { 561 {
562 GNUNET_GE_LOG (ectx, 562 GNUNET_GE_LOG (ectx,
563 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 563 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
564 GNUNET_GE_IMMEDIATE, 564 GNUNET_GE_IMMEDIATE,
565 _("SMTP: `%s' failed: %s.\n"), 565 _("SMTP: `%s' failed: %s.\n"),
566 "smtp_create_session", 566 "smtp_create_session",
567 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 567 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
568 GNUNET_mutex_unlock (lock); 568 GNUNET_mutex_unlock (lock);
569 return GNUNET_SYSERR; 569 return GNUNET_SYSERR;
570 } 570 }
571 if (0 == smtp_set_server (session, smtp_server_name)) 571 if (0 == smtp_set_server (session, smtp_server_name))
572 { 572 {
573 GNUNET_GE_LOG (ectx, 573 GNUNET_GE_LOG (ectx,
574 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER | 574 GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
575 GNUNET_GE_IMMEDIATE, 575 GNUNET_GE_IMMEDIATE,
576 _("SMTP: `%s' failed: %s.\n"), 576 _("SMTP: `%s' failed: %s.\n"),
577 "smtp_set_server", 577 "smtp_set_server",
578 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 578 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
579 smtp_destroy_session (session); 579 smtp_destroy_session (session);
580 GNUNET_mutex_unlock (lock); 580 GNUNET_mutex_unlock (lock);
581 return GNUNET_SYSERR; 581 return GNUNET_SYSERR;
582 } 582 }
583 haddr = (const EmailAddress *) &hello[1]; 583 haddr = (const EmailAddress *) &hello[1];
584 message = smtp_add_message (session); 584 message = smtp_add_message (session);
585 if (message == NULL) 585 if (message == NULL)
586 { 586 {
587 GNUNET_GE_LOG (ectx, 587 GNUNET_GE_LOG (ectx,
588 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 588 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
589 GNUNET_GE_BULK, 589 GNUNET_GE_BULK,
590 _("SMTP: `%s' failed: %s.\n"), 590 _("SMTP: `%s' failed: %s.\n"),
591 "smtp_add_message", 591 "smtp_add_message",
592 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 592 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
593 smtp_destroy_session (session); 593 smtp_destroy_session (session);
594 GNUNET_mutex_unlock (lock); 594 GNUNET_mutex_unlock (lock);
595 return GNUNET_SYSERR; 595 return GNUNET_SYSERR;
596 } 596 }
597 smtp_set_header (message, "To", NULL, haddr->senderAddress); 597 smtp_set_header (message, "To", NULL, haddr->senderAddress);
598 smtp_set_header (message, "From", NULL, email); 598 smtp_set_header (message, "From", NULL, email);
599 599
@@ -603,84 +603,82 @@ api_send (GNUNET_TSession * tsession,
603 fvalue[0] = '\0'; 603 fvalue[0] = '\0';
604 fvalue += 2; 604 fvalue += 2;
605 if (0 == smtp_set_header (message, filter, fvalue)) 605 if (0 == smtp_set_header (message, filter, fvalue))
606 { 606 {
607 GNUNET_GE_LOG (ectx, 607 GNUNET_GE_LOG (ectx,
608 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 608 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
609 GNUNET_GE_BULK, 609 GNUNET_GE_BULK,
610 _("SMTP: `%s' failed: %s.\n"), 610 _("SMTP: `%s' failed: %s.\n"),
611 "smtp_set_header", 611 "smtp_set_header",
612 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 612 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
613 smtp_destroy_session (session); 613 smtp_destroy_session (session);
614 GNUNET_mutex_unlock (lock); 614 GNUNET_mutex_unlock (lock);
615 GNUNET_free (filter); 615 GNUNET_free (filter);
616 return GNUNET_SYSERR; 616 return GNUNET_SYSERR;
617 } 617 }
618 GNUNET_free (filter); 618 GNUNET_free (filter);
619 m = GNUNET_malloc (size + sizeof (SMTPMessage)); 619 m = GNUNET_malloc (size + sizeof (SMTPMessage));
620 memcpy (m, msg, size); 620 memcpy (m, msg, size);
621 mp = (SMTPMessage *) & m[size]; 621 mp = (SMTPMessage *) &m[size];
622 mp->header.size = htons (size + sizeof (SMTPMessage)); 622 mp->header.size = htons (size + sizeof (SMTPMessage));
623 mp->header.type = htons (0); 623 mp->header.type = htons (0);
624 mp->sender = *coreAPI->my_identity; 624 mp->sender = *coreAPI->my_identity;
625 gm_cls.ebody = NULL; 625 gm_cls.ebody = NULL;
626 gm_cls.pos = 0; 626 gm_cls.pos = 0;
627 gm_cls.esize = 627 gm_cls.esize = base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody);
628 base64_encode (m, size + sizeof (SMTPMessage), &gm_cls.ebody);
629 GNUNET_free (m); 628 GNUNET_free (m);
630 if (0 == smtp_size_set_estimate (message, gm_cls.esize)) 629 if (0 == smtp_size_set_estimate (message, gm_cls.esize))
631 { 630 {
632 GNUNET_GE_LOG (ectx, 631 GNUNET_GE_LOG (ectx,
633 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 632 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
634 GNUNET_GE_BULK, 633 GNUNET_GE_BULK,
635 _("SMTP: `%s' failed: %s.\n"), 634 _("SMTP: `%s' failed: %s.\n"),
636 "smtp_size_set_estimate", 635 "smtp_size_set_estimate",
637 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 636 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
638 } 637 }
639 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls)) 638 if (0 == smtp_set_messagecb (message, &get_message, &gm_cls))
640 { 639 {
641 GNUNET_GE_LOG (ectx, 640 GNUNET_GE_LOG (ectx,
642 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 641 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
643 GNUNET_GE_BULK, 642 GNUNET_GE_BULK,
644 _("SMTP: `%s' failed: %s.\n"), 643 _("SMTP: `%s' failed: %s.\n"),
645 "smtp_set_messagecb", 644 "smtp_set_messagecb",
646 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 645 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
647 smtp_destroy_session (session); 646 smtp_destroy_session (session);
648 GNUNET_mutex_unlock (lock); 647 GNUNET_mutex_unlock (lock);
649 GNUNET_free (gm_cls.ebody); 648 GNUNET_free (gm_cls.ebody);
650 return GNUNET_SYSERR; 649 return GNUNET_SYSERR;
651 } 650 }
652 recipient = smtp_add_recipient (message, haddr->senderAddress); 651 recipient = smtp_add_recipient (message, haddr->senderAddress);
653 if (recipient == NULL) 652 if (recipient == NULL)
654 { 653 {
655 GNUNET_GE_LOG (ectx, 654 GNUNET_GE_LOG (ectx,
656 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 655 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
657 GNUNET_GE_BULK, 656 GNUNET_GE_BULK,
658 _("SMTP: `%s' failed: %s.\n"), 657 _("SMTP: `%s' failed: %s.\n"),
659 "smtp_add_recipient", 658 "smtp_add_recipient",
660 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 659 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
661 smtp_destroy_session (session); 660 smtp_destroy_session (session);
662 GNUNET_mutex_unlock (lock); 661 GNUNET_mutex_unlock (lock);
663 return GNUNET_SYSERR; 662 return GNUNET_SYSERR;
664 } 663 }
665 if (0 == smtp_start_session (session)) 664 if (0 == smtp_start_session (session))
666 { 665 {
667 GNUNET_GE_LOG (ectx, 666 GNUNET_GE_LOG (ectx,
668 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER | 667 GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
669 GNUNET_GE_BULK, 668 GNUNET_GE_BULK,
670 _("SMTP: `%s' failed: %s.\n"), 669 _("SMTP: `%s' failed: %s.\n"),
671 "smtp_start_session", 670 "smtp_start_session",
672 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN)); 671 smtp_strerror (smtp_errno (), ebuf, EBUF_LEN));
673 smtp_destroy_session (session); 672 smtp_destroy_session (session);
674 GNUNET_mutex_unlock (lock); 673 GNUNET_mutex_unlock (lock);
675 GNUNET_free (gm_cls.ebody); 674 GNUNET_free (gm_cls.ebody);
676 return GNUNET_SYSERR; 675 return GNUNET_SYSERR;
677 } 676 }
678 if (stats != NULL) 677 if (stats != NULL)
679 stats->change (stat_bytesSent, size); 678 stats->change (stat_bytesSent, size);
680 if (coreAPI->load_monitor != NULL) 679 if (coreAPI->load_monitor != NULL)
681 GNUNET_network_monitor_notify_transmission (coreAPI->load_monitor, 680 GNUNET_network_monitor_notify_transmission (coreAPI->load_monitor,
682 GNUNET_ND_UPLOAD, 681 GNUNET_ND_UPLOAD, gm_cls.esize);
683 gm_cls.esize);
684 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */ 682 smtp_message_reset_status (message); /* this is needed to plug a 28-byte/message memory leak in libesmtp */
685 smtp_destroy_session (session); 683 smtp_destroy_session (session);
686 GNUNET_mutex_unlock (lock); 684 GNUNET_mutex_unlock (lock);
@@ -720,11 +718,11 @@ static int
720api_disconnect (GNUNET_TSession * tsession) 718api_disconnect (GNUNET_TSession * tsession)
721{ 719{
722 if (tsession != NULL) 720 if (tsession != NULL)
723 { 721 {
724 if (tsession->internal != NULL) 722 if (tsession->internal != NULL)
725 GNUNET_free (tsession->internal); 723 GNUNET_free (tsession->internal);
726 GNUNET_free (tsession); 724 GNUNET_free (tsession);
727 } 725 }
728 return GNUNET_OK; 726 return GNUNET_OK;
729} 727}
730 728
@@ -737,15 +735,14 @@ api_start_transport_server ()
737{ 735{
738 smtp_shutdown = GNUNET_NO; 736 smtp_shutdown = GNUNET_NO;
739 /* initialize SMTP network */ 737 /* initialize SMTP network */
740 dispatchThread = 738 dispatchThread = GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
741 GNUNET_thread_create (&listenAndDistribute, NULL, 1024 * 4);
742 if (dispatchThread == NULL) 739 if (dispatchThread == NULL)
743 { 740 {
744 GNUNET_GE_DIE_STRERROR (ectx, 741 GNUNET_GE_DIE_STRERROR (ectx,
745 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 742 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
746 GNUNET_GE_FATAL, "pthread_create"); 743 GNUNET_GE_FATAL, "pthread_create");
747 return GNUNET_SYSERR; 744 return GNUNET_SYSERR;
748 } 745 }
749 return GNUNET_OK; 746 return GNUNET_OK;
750} 747}
751 748
@@ -809,13 +806,13 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
809 coreAPI = core; 806 coreAPI = core;
810 ectx = core->ectx; 807 ectx = core->ectx;
811 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL")) 808 if (!GNUNET_GC_have_configuration_value (coreAPI->cfg, "SMTP", "EMAIL"))
812 { 809 {
813 GNUNET_GE_LOG (ectx, 810 GNUNET_GE_LOG (ectx,
814 GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER, 811 GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
815 _ 812 _
816 ("No email-address specified, can not start SMTP transport.\n")); 813 ("No email-address specified, can not start SMTP transport.\n"));
817 return NULL; 814 return NULL;
818 } 815 }
819 GNUNET_GC_get_configuration_value_number (coreAPI->cfg, 816 GNUNET_GC_get_configuration_value_number (coreAPI->cfg,
820 "SMTP", 817 "SMTP",
821 "MTU", 818 "MTU",
@@ -828,13 +825,13 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
828 0, 0, 1024 * 1024, &rate_limit); 825 0, 0, 1024 * 1024, &rate_limit);
829 stats = coreAPI->service_request ("stats"); 826 stats = coreAPI->service_request ("stats");
830 if (stats != NULL) 827 if (stats != NULL)
831 { 828 {
832 stat_bytesReceived 829 stat_bytesReceived
833 = stats->create (gettext_noop ("# bytes received via SMTP")); 830 = stats->create (gettext_noop ("# bytes received via SMTP"));
834 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP")); 831 stat_bytesSent = stats->create (gettext_noop ("# bytes sent via SMTP"));
835 stat_bytesDropped 832 stat_bytesDropped
836 = stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)")); 833 = stats->create (gettext_noop ("# bytes dropped by SMTP (outgoing)"));
837 } 834 }
838 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg, 835 GNUNET_GC_get_configuration_value_filename (coreAPI->cfg,
839 "SMTP", 836 "SMTP",
840 "PIPE", 837 "PIPE",
@@ -842,17 +839,17 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
842 "/smtp-pipe", &pipename); 839 "/smtp-pipe", &pipename);
843 UNLINK (pipename); 840 UNLINK (pipename);
844 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 841 if (0 != mkfifo (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
845 { 842 {
846 GNUNET_GE_LOG_STRERROR (ectx, 843 GNUNET_GE_LOG_STRERROR (ectx,
847 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 844 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
848 GNUNET_GE_FATAL, "mkfifo"); 845 GNUNET_GE_FATAL, "mkfifo");
849 GNUNET_free (pipename); 846 GNUNET_free (pipename);
850 coreAPI->service_release (stats); 847 coreAPI->service_release (stats);
851 stats = NULL; 848 stats = NULL;
852 return NULL; 849 return NULL;
853 } 850 }
854 /* we need to allow the mailer program to send us messages; 851 /* we need to allow the mailer program to send us messages;
855 easiest done by giving it write permissions (see Mantis #1142) */ 852 * easiest done by giving it write permissions (see Mantis #1142) */
856 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH)) 853 if (0 != chmod (pipename, S_IWUSR | S_IRUSR | S_IWGRP | S_IWOTH))
857 GNUNET_GE_LOG_STRERROR (ectx, 854 GNUNET_GE_LOG_STRERROR (ectx,
858 GNUNET_GE_ADMIN | GNUNET_GE_BULK | 855 GNUNET_GE_ADMIN | GNUNET_GE_BULK |
@@ -863,8 +860,7 @@ inittransport_smtp (GNUNET_CoreAPIForTransport * core)
863 GNUNET_GC_get_configuration_value_string (coreAPI->cfg, 860 GNUNET_GC_get_configuration_value_string (coreAPI->cfg,
864 "SMTP", 861 "SMTP",
865 "SERVER", 862 "SERVER",
866 "localhost:25", 863 "localhost:25", &smtp_server_name);
867 &smtp_server_name);
868 sa.sa_handler = SIG_IGN; 864 sa.sa_handler = SIG_IGN;
869 sigemptyset (&sa.sa_mask); 865 sigemptyset (&sa.sa_mask);
870 sa.sa_flags = 0; 866 sa.sa_flags = 0;
@@ -892,10 +888,10 @@ donetransport_smtp ()
892 sigaction (SIGPIPE, &old_handler, NULL); 888 sigaction (SIGPIPE, &old_handler, NULL);
893 GNUNET_free (smtp_server_name); 889 GNUNET_free (smtp_server_name);
894 if (stats != NULL) 890 if (stats != NULL)
895 { 891 {
896 coreAPI->service_release (stats); 892 coreAPI->service_release (stats);
897 stats = NULL; 893 stats = NULL;
898 } 894 }
899 GNUNET_mutex_destroy (lock); 895 GNUNET_mutex_destroy (lock);
900 lock = NULL; 896 lock = NULL;
901 UNLINK (pipename); 897 UNLINK (pipename);
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 2c20ba35e..bd2f4aa6a 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -343,7 +343,7 @@ struct Plugin
343 * Map of peers we have tried to contact behind a NAT 343 * Map of peers we have tried to contact behind a NAT
344 */ 344 */
345 struct GNUNET_CONTAINER_MultiHashMap *nat_wait_conns; 345 struct GNUNET_CONTAINER_MultiHashMap *nat_wait_conns;
346 346
347 /** 347 /**
348 * List of active TCP probes. 348 * List of active TCP probes.
349 */ 349 */
@@ -358,7 +358,7 @@ struct Plugin
358 * Handle for (DYN)DNS lookup of our external IP. 358 * Handle for (DYN)DNS lookup of our external IP.
359 */ 359 */
360 struct GNUNET_RESOLVER_RequestHandle *ext_dns; 360 struct GNUNET_RESOLVER_RequestHandle *ext_dns;
361 361
362 /** 362 /**
363 * How many more TCP sessions are we allowed to open right now? 363 * How many more TCP sessions are we allowed to open right now?
364 */ 364 */
@@ -397,9 +397,8 @@ struct Plugin
397 */ 397 */
398static int 398static int
399plugin_tcp_access_check (void *cls, 399plugin_tcp_access_check (void *cls,
400 const struct GNUNET_CONNECTION_Credentials *ucred, 400 const struct GNUNET_CONNECTION_Credentials *ucred,
401 const struct sockaddr *addr, 401 const struct sockaddr *addr, socklen_t addrlen)
402 socklen_t addrlen)
403{ 402{
404 struct Plugin *plugin = cls; 403 struct Plugin *plugin = cls;
405 404
@@ -421,9 +420,8 @@ plugin_tcp_access_check (void *cls,
421 */ 420 */
422static void 421static void
423tcp_nat_port_map_callback (void *cls, 422tcp_nat_port_map_callback (void *cls,
424 int add_remove, 423 int add_remove,
425 const struct sockaddr *addr, 424 const struct sockaddr *addr, socklen_t addrlen)
426 socklen_t addrlen)
427{ 425{
428 struct Plugin *plugin = cls; 426 struct Plugin *plugin = cls;
429 struct IPv4TcpAddress t4; 427 struct IPv4TcpAddress t4;
@@ -432,37 +430,34 @@ tcp_nat_port_map_callback (void *cls,
432 size_t args; 430 size_t args;
433 431
434 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 432 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
435 "tcp", 433 "tcp",
436 "NPMC called with %d for address `%s'\n", 434 "NPMC called with %d for address `%s'\n",
437 add_remove, 435 add_remove, GNUNET_a2s (addr, addrlen));
438 GNUNET_a2s (addr, addrlen));
439 /* convert 'addr' to our internal format */ 436 /* convert 'addr' to our internal format */
440 switch (addr->sa_family) 437 switch (addr->sa_family)
441 { 438 {
442 case AF_INET: 439 case AF_INET:
443 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 440 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
444 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 441 t4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
445 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port; 442 t4.t4_port = ((struct sockaddr_in *) addr)->sin_port;
446 arg = &t4; 443 arg = &t4;
447 args = sizeof (t4); 444 args = sizeof (t4);
448 break; 445 break;
449 case AF_INET6: 446 case AF_INET6:
450 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 447 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
451 memcpy (&t6.ipv6_addr, 448 memcpy (&t6.ipv6_addr,
452 &((struct sockaddr_in6 *) addr)->sin6_addr, 449 &((struct sockaddr_in6 *) addr)->sin6_addr,
453 sizeof (struct in6_addr)); 450 sizeof (struct in6_addr));
454 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port; 451 t6.t6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
455 arg = &t6; 452 arg = &t6;
456 args = sizeof (t6); 453 args = sizeof (t6);
457 break; 454 break;
458 default: 455 default:
459 GNUNET_break (0); 456 GNUNET_break (0);
460 return; 457 return;
461 } 458 }
462 /* modify our published address list */ 459 /* modify our published address list */
463 plugin->env->notify_address (plugin->env->cls, 460 plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
464 add_remove,
465 arg, args);
466} 461}
467 462
468 463
@@ -477,10 +472,8 @@ tcp_nat_port_map_callback (void *cls,
477 * @param addrlen length of the address 472 * @param addrlen length of the address
478 * @return string representing the same address 473 * @return string representing the same address
479 */ 474 */
480static const char* 475static const char *
481tcp_address_to_string (void *cls, 476tcp_address_to_string (void *cls, const void *addr, size_t addrlen)
482 const void *addr,
483 size_t addrlen)
484{ 477{
485 static char rbuf[INET6_ADDRSTRLEN + 12]; 478 static char rbuf[INET6_ADDRSTRLEN + 12];
486 char buf[INET6_ADDRSTRLEN]; 479 char buf[INET6_ADDRSTRLEN];
@@ -493,40 +486,38 @@ tcp_address_to_string (void *cls,
493 uint16_t port; 486 uint16_t port;
494 487
495 if (addrlen == sizeof (struct IPv6TcpAddress)) 488 if (addrlen == sizeof (struct IPv6TcpAddress))
496 { 489 {
497 t6 = addr; 490 t6 = addr;
498 af = AF_INET6; 491 af = AF_INET6;
499 port = ntohs (t6->t6_port); 492 port = ntohs (t6->t6_port);
500 memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); 493 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
501 sb = &a6; 494 sb = &a6;
502 } 495 }
503 else if (addrlen == sizeof (struct IPv4TcpAddress)) 496 else if (addrlen == sizeof (struct IPv4TcpAddress))
504 { 497 {
505 t4 = addr; 498 t4 = addr;
506 af = AF_INET; 499 af = AF_INET;
507 port = ntohs (t4->t4_port); 500 port = ntohs (t4->t4_port);
508 memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); 501 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
509 sb = &a4; 502 sb = &a4;
510 } 503 }
511 else 504 else
512 { 505 {
513 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 506 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
514 "tcp", 507 "tcp",
515 _("Unexpected address length: %u bytes\n"), 508 _("Unexpected address length: %u bytes\n"),
516 (unsigned int) addrlen); 509 (unsigned int) addrlen);
517 GNUNET_break (0); 510 GNUNET_break (0);
518 return NULL; 511 return NULL;
519 } 512 }
520 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN)) 513 if (NULL == inet_ntop (af, sb, buf, INET6_ADDRSTRLEN))
521 { 514 {
522 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop"); 515 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "inet_ntop");
523 return NULL; 516 return NULL;
524 } 517 }
525 GNUNET_snprintf (rbuf, 518 GNUNET_snprintf (rbuf,
526 sizeof (rbuf), 519 sizeof (rbuf),
527 (af == AF_INET6) ? "[%s]:%u" : "%s:%u", 520 (af == AF_INET6) ? "[%s]:%u" : "%s:%u", buf, port);
528 buf,
529 port);
530 return rbuf; 521 return rbuf;
531} 522}
532 523
@@ -565,8 +556,7 @@ find_session_by_client (struct Plugin *plugin,
565static struct Session * 556static struct Session *
566create_session (struct Plugin *plugin, 557create_session (struct Plugin *plugin,
567 const struct GNUNET_PeerIdentity *target, 558 const struct GNUNET_PeerIdentity *target,
568 struct GNUNET_SERVER_Client *client, 559 struct GNUNET_SERVER_Client *client, int is_nat)
569 int is_nat)
570{ 560{
571 struct Session *ret; 561 struct Session *ret;
572 struct PendingMessage *pm; 562 struct PendingMessage *pm;
@@ -578,24 +568,25 @@ create_session (struct Plugin *plugin,
578 GNUNET_assert (client == NULL); 568 GNUNET_assert (client == NULL);
579#if DEBUG_TCP 569#if DEBUG_TCP
580 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 570 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
581 "tcp", 571 "tcp",
582 "Creating new session for peer `%4s'\n", 572 "Creating new session for peer `%4s'\n",
583 GNUNET_i2s (target)); 573 GNUNET_i2s (target));
584#endif 574#endif
585 ret = GNUNET_malloc (sizeof (struct Session)); 575 ret = GNUNET_malloc (sizeof (struct Session));
586 ret->last_activity = GNUNET_TIME_absolute_get (); 576 ret->last_activity = GNUNET_TIME_absolute_get ();
587 ret->plugin = plugin; 577 ret->plugin = plugin;
588 ret->is_nat = is_nat; 578 ret->is_nat = is_nat;
589 if (is_nat != GNUNET_YES) /* If not a NAT WAIT conn, add it to global list */ 579 if (is_nat != GNUNET_YES) /* If not a NAT WAIT conn, add it to global list */
590 { 580 {
591 ret->next = plugin->sessions; 581 ret->next = plugin->sessions;
592 plugin->sessions = ret; 582 plugin->sessions = ret;
593 } 583 }
594 ret->client = client; 584 ret->client = client;
595 ret->target = *target; 585 ret->target = *target;
596 ret->expecting_welcome = GNUNET_YES; 586 ret->expecting_welcome = GNUNET_YES;
597 pm = GNUNET_malloc (sizeof (struct PendingMessage) + sizeof (struct WelcomeMessage)); 587 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
598 pm->msg = (const char*) &pm[1]; 588 sizeof (struct WelcomeMessage));
589 pm->msg = (const char *) &pm[1];
599 pm->message_size = sizeof (struct WelcomeMessage); 590 pm->message_size = sizeof (struct WelcomeMessage);
600 welcome.header.size = htons (sizeof (struct WelcomeMessage)); 591 welcome.header.size = htons (sizeof (struct WelcomeMessage));
601 welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME); 592 welcome.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME);
@@ -603,17 +594,14 @@ create_session (struct Plugin *plugin,
603 memcpy (&pm[1], &welcome, sizeof (welcome)); 594 memcpy (&pm[1], &welcome, sizeof (welcome));
604 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS; 595 pm->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
605 GNUNET_STATISTICS_update (plugin->env->stats, 596 GNUNET_STATISTICS_update (plugin->env->stats,
606 gettext_noop ("# bytes currently in TCP buffers"), 597 gettext_noop ("# bytes currently in TCP buffers"),
607 pm->message_size, 598 pm->message_size, GNUNET_NO);
608 GNUNET_NO);
609 GNUNET_CONTAINER_DLL_insert (ret->pending_messages_head, 599 GNUNET_CONTAINER_DLL_insert (ret->pending_messages_head,
610 ret->pending_messages_tail, 600 ret->pending_messages_tail, pm);
611 pm);
612 if (is_nat != GNUNET_YES) 601 if (is_nat != GNUNET_YES)
613 GNUNET_STATISTICS_update (plugin->env->stats, 602 GNUNET_STATISTICS_update (plugin->env->stats,
614 gettext_noop ("# TCP sessions active"), 603 gettext_noop ("# TCP sessions active"),
615 1, 604 1, GNUNET_NO);
616 GNUNET_NO);
617 return ret; 605 return ret;
618} 606}
619 607
@@ -655,111 +643,101 @@ do_transmit (void *cls, size_t size, void *buf)
655 session->transmit_handle = NULL; 643 session->transmit_handle = NULL;
656 plugin = session->plugin; 644 plugin = session->plugin;
657 if (buf == NULL) 645 if (buf == NULL)
658 { 646 {
659#if DEBUG_TCP 647#if DEBUG_TCP
660 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 648 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
661 "tcp", 649 "tcp",
662 "Timeout trying to transmit to peer `%4s', discarding message queue.\n", 650 "Timeout trying to transmit to peer `%4s', discarding message queue.\n",
663 GNUNET_i2s (&session->target)); 651 GNUNET_i2s (&session->target));
664#endif 652#endif
665 /* timeout; cancel all messages that have already expired */ 653 /* timeout; cancel all messages that have already expired */
666 hd = NULL; 654 hd = NULL;
667 tl = NULL; 655 tl = NULL;
668 ret = 0; 656 ret = 0;
669 now = GNUNET_TIME_absolute_get (); 657 now = GNUNET_TIME_absolute_get ();
670 while ( (NULL != (pos = session->pending_messages_head)) && 658 while ((NULL != (pos = session->pending_messages_head)) &&
671 (pos->timeout.abs_value <= now.abs_value) ) 659 (pos->timeout.abs_value <= now.abs_value))
672 { 660 {
673 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 661 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
674 session->pending_messages_tail, 662 session->pending_messages_tail, pos);
675 pos);
676#if DEBUG_TCP 663#if DEBUG_TCP
677 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 664 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
678 "tcp", 665 "tcp",
679 "Failed to transmit %u byte message to `%4s'.\n", 666 "Failed to transmit %u byte message to `%4s'.\n",
680 pos->message_size, 667 pos->message_size, GNUNET_i2s (&session->target));
681 GNUNET_i2s (&session->target));
682#endif 668#endif
683 ret += pos->message_size; 669 ret += pos->message_size;
684 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); 670 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
685 } 671 }
686 /* do this call before callbacks (so that if callbacks destroy 672 /* do this call before callbacks (so that if callbacks destroy
687 session, they have a chance to cancel actions done by this 673 * session, they have a chance to cancel actions done by this
688 call) */ 674 * call) */
689 process_pending_messages (session); 675 process_pending_messages (session);
690 pid = session->target; 676 pid = session->target;
691 /* no do callbacks and do not use session again since 677 /* no do callbacks and do not use session again since
692 the callbacks may abort the session */ 678 * the callbacks may abort the session */
693 while (NULL != (pos = hd)) 679 while (NULL != (pos = hd))
694 { 680 {
695 GNUNET_CONTAINER_DLL_remove (hd, tl, pos); 681 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
696 if (pos->transmit_cont != NULL) 682 if (pos->transmit_cont != NULL)
697 pos->transmit_cont (pos->transmit_cont_cls, 683 pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_SYSERR);
698 &pid, GNUNET_SYSERR); 684 GNUNET_free (pos);
699 GNUNET_free (pos);
700 }
701 GNUNET_STATISTICS_update (plugin->env->stats,
702 gettext_noop ("# bytes currently in TCP buffers"),
703 - (int64_t) ret,
704 GNUNET_NO);
705 GNUNET_STATISTICS_update (plugin->env->stats,
706 gettext_noop ("# bytes discarded by TCP (timeout)"),
707 ret,
708 GNUNET_NO);
709 return 0;
710 } 685 }
686 GNUNET_STATISTICS_update (plugin->env->stats,
687 gettext_noop ("# bytes currently in TCP buffers"),
688 -(int64_t) ret, GNUNET_NO);
689 GNUNET_STATISTICS_update (plugin->env->stats,
690 gettext_noop
691 ("# bytes discarded by TCP (timeout)"), ret,
692 GNUNET_NO);
693 return 0;
694 }
711 /* copy all pending messages that would fit */ 695 /* copy all pending messages that would fit */
712 ret = 0; 696 ret = 0;
713 cbuf = buf; 697 cbuf = buf;
714 hd = NULL; 698 hd = NULL;
715 tl = NULL; 699 tl = NULL;
716 while (NULL != (pos = session->pending_messages_head)) 700 while (NULL != (pos = session->pending_messages_head))
717 { 701 {
718 if (ret + pos->message_size > size) 702 if (ret + pos->message_size > size)
719 break; 703 break;
720 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 704 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
721 session->pending_messages_tail, 705 session->pending_messages_tail, pos);
722 pos); 706 GNUNET_assert (size >= pos->message_size);
723 GNUNET_assert (size >= pos->message_size); 707 /* FIXME: this memcpy can be up to 7% of our total runtime */
724 /* FIXME: this memcpy can be up to 7% of our total runtime */ 708 memcpy (cbuf, pos->msg, pos->message_size);
725 memcpy (cbuf, pos->msg, pos->message_size); 709 cbuf += pos->message_size;
726 cbuf += pos->message_size; 710 ret += pos->message_size;
727 ret += pos->message_size; 711 size -= pos->message_size;
728 size -= pos->message_size; 712 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos);
729 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); 713 }
730 }
731 /* schedule 'continuation' before callbacks so that callbacks that 714 /* schedule 'continuation' before callbacks so that callbacks that
732 cancel everything don't cause us to use a session that no longer 715 * cancel everything don't cause us to use a session that no longer
733 exists... */ 716 * exists... */
734 process_pending_messages (session); 717 process_pending_messages (session);
735 session->last_activity = GNUNET_TIME_absolute_get (); 718 session->last_activity = GNUNET_TIME_absolute_get ();
736 pid = session->target; 719 pid = session->target;
737 /* we'll now call callbacks that may cancel the session; hence 720 /* we'll now call callbacks that may cancel the session; hence
738 we should not use 'session' after this point */ 721 * we should not use 'session' after this point */
739 while (NULL != (pos = hd)) 722 while (NULL != (pos = hd))
740 { 723 {
741 GNUNET_CONTAINER_DLL_remove (hd, tl, pos); 724 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
742 if (pos->transmit_cont != NULL) 725 if (pos->transmit_cont != NULL)
743 pos->transmit_cont (pos->transmit_cont_cls, 726 pos->transmit_cont (pos->transmit_cont_cls, &pid, GNUNET_OK);
744 &pid, GNUNET_OK); 727 GNUNET_free (pos);
745 GNUNET_free (pos); 728 }
746 }
747 GNUNET_assert (hd == NULL); 729 GNUNET_assert (hd == NULL);
748 GNUNET_assert (tl == NULL); 730 GNUNET_assert (tl == NULL);
749#if DEBUG_TCP > 1 731#if DEBUG_TCP > 1
750 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
751 "tcp", 733 "tcp", "Transmitting %u bytes\n", ret);
752 "Transmitting %u bytes\n",
753 ret);
754#endif 734#endif
755 GNUNET_STATISTICS_update (plugin->env->stats, 735 GNUNET_STATISTICS_update (plugin->env->stats,
756 gettext_noop ("# bytes currently in TCP buffers"), 736 gettext_noop ("# bytes currently in TCP buffers"),
757 - (int64_t) ret, 737 -(int64_t) ret, GNUNET_NO);
758 GNUNET_NO);
759 GNUNET_STATISTICS_update (plugin->env->stats, 738 GNUNET_STATISTICS_update (plugin->env->stats,
760 gettext_noop ("# bytes transmitted via TCP"), 739 gettext_noop ("# bytes transmitted via TCP"),
761 ret, 740 ret, GNUNET_NO);
762 GNUNET_NO);
763 return ret; 741 return ret;
764} 742}
765 743
@@ -782,11 +760,11 @@ process_pending_messages (struct Session *session)
782 return; 760 return;
783 761
784 session->transmit_handle 762 session->transmit_handle
785 = GNUNET_SERVER_notify_transmit_ready (session->client, 763 = GNUNET_SERVER_notify_transmit_ready (session->client,
786 pm->message_size, 764 pm->message_size,
787 GNUNET_TIME_absolute_get_remaining 765 GNUNET_TIME_absolute_get_remaining
788 (pm->timeout), 766 (pm->timeout),
789 &do_transmit, session); 767 &do_transmit, session);
790} 768}
791 769
792 770
@@ -806,22 +784,22 @@ disconnect_session (struct Session *session)
806 784
807#if DEBUG_TCP 785#if DEBUG_TCP
808 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 786 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
809 "tcp", 787 "tcp",
810 "Disconnecting from `%4s' at %s.\n", 788 "Disconnecting from `%4s' at %s.\n",
811 GNUNET_i2s (&session->target), 789 GNUNET_i2s (&session->target),
812 (session->connect_addr != NULL) ? 790 (session->connect_addr != NULL) ?
813 tcp_address_to_string (session->plugin, 791 tcp_address_to_string (session->plugin,
814 session->connect_addr, 792 session->connect_addr,
815 session->connect_alen) : "*"); 793 session->connect_alen) : "*");
816#endif 794#endif
817 /* remove from session list */ 795 /* remove from session list */
818 prev = NULL; 796 prev = NULL;
819 pos = session->plugin->sessions; 797 pos = session->plugin->sessions;
820 while (pos != session) 798 while (pos != session)
821 { 799 {
822 prev = pos; 800 prev = pos;
823 pos = pos->next; 801 pos = pos->next;
824 } 802 }
825 if (prev == NULL) 803 if (prev == NULL)
826 session->plugin->sessions = session->next; 804 session->plugin->sessions = session->next;
827 else 805 else
@@ -829,57 +807,51 @@ disconnect_session (struct Session *session)
829 807
830 /* clean up state */ 808 /* clean up state */
831 if (session->transmit_handle != NULL) 809 if (session->transmit_handle != NULL)
832 { 810 {
833 GNUNET_CONNECTION_notify_transmit_ready_cancel 811 GNUNET_CONNECTION_notify_transmit_ready_cancel (session->transmit_handle);
834 (session->transmit_handle); 812 session->transmit_handle = NULL;
835 session->transmit_handle = NULL; 813 }
836 }
837 session->plugin->env->session_end (session->plugin->env->cls, 814 session->plugin->env->session_end (session->plugin->env->cls,
838 &session->target, 815 &session->target, session);
839 session);
840 while (NULL != (pm = session->pending_messages_head)) 816 while (NULL != (pm = session->pending_messages_head))
841 { 817 {
842#if DEBUG_TCP 818#if DEBUG_TCP
843 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 819 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
844 "tcp", 820 "tcp",
845 pm->transmit_cont != NULL 821 pm->transmit_cont != NULL
846 ? "Could not deliver message to `%4s'.\n" 822 ? "Could not deliver message to `%4s'.\n"
847 : "Could not deliver message to `%4s', notifying.\n", 823 : "Could not deliver message to `%4s', notifying.\n",
848 GNUNET_i2s (&session->target)); 824 GNUNET_i2s (&session->target));
849#endif 825#endif
850 GNUNET_STATISTICS_update (session->plugin->env->stats, 826 GNUNET_STATISTICS_update (session->plugin->env->stats,
851 gettext_noop ("# bytes currently in TCP buffers"), 827 gettext_noop ("# bytes currently in TCP buffers"),
852 - (int64_t) pm->message_size, 828 -(int64_t) pm->message_size, GNUNET_NO);
853 GNUNET_NO); 829 GNUNET_STATISTICS_update (session->plugin->env->stats,
854 GNUNET_STATISTICS_update (session->plugin->env->stats, 830 gettext_noop
855 gettext_noop ("# bytes discarded by TCP (disconnect)"), 831 ("# bytes discarded by TCP (disconnect)"),
856 pm->message_size, 832 pm->message_size, GNUNET_NO);
857 GNUNET_NO); 833 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
858 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 834 session->pending_messages_tail, pm);
859 session->pending_messages_tail, 835 if (NULL != pm->transmit_cont)
860 pm); 836 pm->transmit_cont (pm->transmit_cont_cls,
861 if (NULL != pm->transmit_cont) 837 &session->target, GNUNET_SYSERR);
862 pm->transmit_cont (pm->transmit_cont_cls, 838 GNUNET_free (pm);
863 &session->target, GNUNET_SYSERR); 839 }
864 GNUNET_free (pm);
865 }
866 GNUNET_break (session->client != NULL); 840 GNUNET_break (session->client != NULL);
867 if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK) 841 if (session->receive_delay_task != GNUNET_SCHEDULER_NO_TASK)
868 { 842 {
869 GNUNET_SCHEDULER_cancel (session->receive_delay_task); 843 GNUNET_SCHEDULER_cancel (session->receive_delay_task);
870 if (session->client != NULL) 844 if (session->client != NULL)
871 GNUNET_SERVER_receive_done (session->client, 845 GNUNET_SERVER_receive_done (session->client, GNUNET_SYSERR);
872 GNUNET_SYSERR); 846 }
873 }
874 if (session->client != NULL) 847 if (session->client != NULL)
875 { 848 {
876 GNUNET_SERVER_client_drop (session->client); 849 GNUNET_SERVER_client_drop (session->client);
877 session->client = NULL; 850 session->client = NULL;
878 } 851 }
879 GNUNET_STATISTICS_update (session->plugin->env->stats, 852 GNUNET_STATISTICS_update (session->plugin->env->stats,
880 gettext_noop ("# TCP sessions active"), 853 gettext_noop ("# TCP sessions active"),
881 -1, 854 -1, GNUNET_NO);
882 GNUNET_NO);
883 GNUNET_free_non_null (session->connect_addr); 855 GNUNET_free_non_null (session->connect_addr);
884 GNUNET_assert (NULL == session->transmit_handle); 856 GNUNET_assert (NULL == session->transmit_handle);
885 GNUNET_free (session); 857 GNUNET_free (session);
@@ -894,28 +866,25 @@ disconnect_session (struct Session *session)
894 * @return "better" session (more active) 866 * @return "better" session (more active)
895 */ 867 */
896static struct Session * 868static struct Session *
897select_better_session (struct Session *s1, 869select_better_session (struct Session *s1, struct Session *s2)
898 struct Session *s2)
899{ 870{
900 if (s1 == NULL) 871 if (s1 == NULL)
901 return s2; 872 return s2;
902 if (s2 == NULL) 873 if (s2 == NULL)
903 return s1; 874 return s1;
904 if ( (s1->expecting_welcome == GNUNET_NO) && 875 if ((s1->expecting_welcome == GNUNET_NO) &&
905 (s2->expecting_welcome == GNUNET_YES) ) 876 (s2->expecting_welcome == GNUNET_YES))
906 return s1; 877 return s1;
907 if ( (s1->expecting_welcome == GNUNET_YES) && 878 if ((s1->expecting_welcome == GNUNET_YES) &&
908 (s2->expecting_welcome == GNUNET_NO) ) 879 (s2->expecting_welcome == GNUNET_NO))
909 return s2; 880 return s2;
910 if (s1->last_activity.abs_value < s2->last_activity.abs_value) 881 if (s1->last_activity.abs_value < s2->last_activity.abs_value)
911 return s2; 882 return s2;
912 if (s1->last_activity.abs_value > s2->last_activity.abs_value) 883 if (s1->last_activity.abs_value > s2->last_activity.abs_value)
913 return s1; 884 return s1;
914 if ( (GNUNET_YES == s1->inbound) && 885 if ((GNUNET_YES == s1->inbound) && (GNUNET_NO == s2->inbound))
915 (GNUNET_NO == s2->inbound) )
916 return s1; 886 return s1;
917 if ( (GNUNET_NO == s1->inbound) && 887 if ((GNUNET_NO == s1->inbound) && (GNUNET_YES == s2->inbound))
918 (GNUNET_YES == s2->inbound) )
919 return s2; 888 return s2;
920 return s1; 889 return s1;
921} 890}
@@ -965,10 +934,10 @@ tcp_plugin_send (void *cls,
965 size_t msgbuf_size, 934 size_t msgbuf_size,
966 uint32_t priority, 935 uint32_t priority,
967 struct GNUNET_TIME_Relative timeout, 936 struct GNUNET_TIME_Relative timeout,
968 struct Session *session, 937 struct Session *session,
969 const void *addr, 938 const void *addr,
970 size_t addrlen, 939 size_t addrlen,
971 int force_address, 940 int force_address,
972 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 941 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
973{ 942{
974 struct Plugin *plugin = cls; 943 struct Plugin *plugin = cls;
@@ -986,234 +955,217 @@ tcp_plugin_send (void *cls,
986 unsigned int is_natd; 955 unsigned int is_natd;
987 956
988 GNUNET_STATISTICS_update (plugin->env->stats, 957 GNUNET_STATISTICS_update (plugin->env->stats,
989 gettext_noop ("# bytes TCP was asked to transmit"), 958 gettext_noop ("# bytes TCP was asked to transmit"),
990 msgbuf_size, 959 msgbuf_size, GNUNET_NO);
991 GNUNET_NO);
992 /* FIXME: we could do this cheaper with a hash table 960 /* FIXME: we could do this cheaper with a hash table
993 where we could restrict the iteration to entries that match 961 * where we could restrict the iteration to entries that match
994 the target peer... */ 962 * the target peer... */
995 is_natd = GNUNET_NO; 963 is_natd = GNUNET_NO;
996 if (session == NULL) 964 if (session == NULL)
965 {
966 cand_session = NULL;
967 next = plugin->sessions;
968 while (NULL != (session = next))
997 { 969 {
998 cand_session = NULL; 970 next = session->next;
999 next = plugin->sessions; 971 GNUNET_assert (session->client != NULL);
1000 while (NULL != (session = next)) 972 if (0 != memcmp (target,
1001 { 973 &session->target, sizeof (struct GNUNET_PeerIdentity)))
1002 next = session->next; 974 continue;
1003 GNUNET_assert (session->client != NULL); 975 if (((GNUNET_SYSERR == force_address) &&
1004 if (0 != memcmp (target, 976 (session->expecting_welcome == GNUNET_NO)) ||
1005 &session->target, 977 (GNUNET_NO == force_address))
1006 sizeof (struct GNUNET_PeerIdentity))) 978 {
1007 continue; 979 cand_session = select_better_session (cand_session, session);
1008 if ( ( (GNUNET_SYSERR == force_address) && 980 continue;
1009 (session->expecting_welcome == GNUNET_NO) ) || 981 }
1010 (GNUNET_NO == force_address) ) 982 if (GNUNET_SYSERR == force_address)
1011 { 983 continue;
1012 cand_session = select_better_session (cand_session, 984 GNUNET_break (GNUNET_YES == force_address);
1013 session); 985 if (addr == NULL)
1014 continue; 986 {
1015 } 987 GNUNET_break (0);
1016 if (GNUNET_SYSERR == force_address) 988 break;
1017 continue; 989 }
1018 GNUNET_break (GNUNET_YES == force_address); 990 if ((addrlen != session->connect_alen) && (session->is_nat == GNUNET_NO))
1019 if (addr == NULL) 991 continue;
1020 { 992 if ((0 != memcmp (session->connect_addr,
1021 GNUNET_break (0); 993 addr, addrlen)) && (session->is_nat == GNUNET_NO))
1022 break; 994 continue;
1023 } 995 cand_session = select_better_session (cand_session, session);
1024 if ( (addrlen != session->connect_alen) &&
1025 (session->is_nat == GNUNET_NO) )
1026 continue;
1027 if ((0 != memcmp (session->connect_addr,
1028 addr,
1029 addrlen)) && (session->is_nat == GNUNET_NO))
1030 continue;
1031 cand_session = select_better_session (cand_session,
1032 session);
1033 }
1034 session = cand_session;
1035 } 996 }
1036 if ( (session == NULL) && 997 session = cand_session;
1037 (addr == NULL) ) 998 }
1038 { 999 if ((session == NULL) && (addr == NULL))
1000 {
1039#if DEBUG_TCP 1001#if DEBUG_TCP
1040 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1002 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1041 "tcp", 1003 "tcp",
1042 "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n", 1004 "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n",
1043 GNUNET_i2s (target)); 1005 GNUNET_i2s (target));
1044#endif 1006#endif
1045 GNUNET_STATISTICS_update (plugin->env->stats, 1007 GNUNET_STATISTICS_update (plugin->env->stats,
1046 gettext_noop ("# bytes discarded by TCP (no address and no connection)"), 1008 gettext_noop
1047 msgbuf_size, 1009 ("# bytes discarded by TCP (no address and no connection)"),
1048 GNUNET_NO); 1010 msgbuf_size, GNUNET_NO);
1049 return -1; 1011 return -1;
1050 } 1012 }
1051 if (session == NULL) 1013 if (session == NULL)
1014 {
1015 if (addrlen == sizeof (struct IPv6TcpAddress))
1052 { 1016 {
1053 if (addrlen == sizeof (struct IPv6TcpAddress)) 1017 t6 = addr;
1054 { 1018 af = AF_INET6;
1055 t6 = addr; 1019 memset (&a6, 0, sizeof (a6));
1056 af = AF_INET6;
1057 memset (&a6, 0, sizeof (a6));
1058#if HAVE_SOCKADDR_IN_SIN_LEN 1020#if HAVE_SOCKADDR_IN_SIN_LEN
1059 a6.sin6_len = sizeof (a6); 1021 a6.sin6_len = sizeof (a6);
1060#endif 1022#endif
1061 a6.sin6_family = AF_INET6; 1023 a6.sin6_family = AF_INET6;
1062 a6.sin6_port = t6->t6_port; 1024 a6.sin6_port = t6->t6_port;
1063 if (t6->t6_port == 0) 1025 if (t6->t6_port == 0)
1064 is_natd = GNUNET_YES; 1026 is_natd = GNUNET_YES;
1065 memcpy (&a6.sin6_addr, 1027 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
1066 &t6->ipv6_addr, 1028 sb = &a6;
1067 sizeof (struct in6_addr)); 1029 sbs = sizeof (a6);
1068 sb = &a6; 1030 }
1069 sbs = sizeof (a6); 1031 else if (addrlen == sizeof (struct IPv4TcpAddress))
1070 } 1032 {
1071 else if (addrlen == sizeof (struct IPv4TcpAddress)) 1033 t4 = addr;
1072 { 1034 af = AF_INET;
1073 t4 = addr; 1035 memset (&a4, 0, sizeof (a4));
1074 af = AF_INET;
1075 memset (&a4, 0, sizeof (a4));
1076#if HAVE_SOCKADDR_IN_SIN_LEN 1036#if HAVE_SOCKADDR_IN_SIN_LEN
1077 a4.sin_len = sizeof (a4); 1037 a4.sin_len = sizeof (a4);
1078#endif 1038#endif
1079 a4.sin_family = AF_INET; 1039 a4.sin_family = AF_INET;
1080 a4.sin_port = t4->t4_port; 1040 a4.sin_port = t4->t4_port;
1081 if (t4->t4_port == 0) 1041 if (t4->t4_port == 0)
1082 is_natd = GNUNET_YES; 1042 is_natd = GNUNET_YES;
1083 a4.sin_addr.s_addr = t4->ipv4_addr; 1043 a4.sin_addr.s_addr = t4->ipv4_addr;
1084 sb = &a4; 1044 sb = &a4;
1085 sbs = sizeof (a4); 1045 sbs = sizeof (a4);
1086 } 1046 }
1087 else 1047 else
1088 { 1048 {
1089 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1049 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1090 "tcp", 1050 "tcp", _("Address of unexpected length: %u\n"), addrlen);
1091 _("Address of unexpected length: %u\n"), 1051 GNUNET_break (0);
1092 addrlen); 1052 return -1;
1093 GNUNET_break (0); 1053 }
1094 return -1; 1054
1095 } 1055 if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress)))
1096 1056 return -1; /* NAT client only works with IPv4 addresses */
1097 if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct IPv6TcpAddress))) 1057 if (0 == plugin->max_connections)
1098 return -1; /* NAT client only works with IPv4 addresses */ 1058 return -1; /* saturated */
1099 if (0 == plugin->max_connections) 1059
1100 return -1; /* saturated */ 1060 if ((is_natd == GNUNET_YES) &&
1101 1061 (NULL != plugin->nat) &&
1102 if ( (is_natd == GNUNET_YES) && 1062 (GNUNET_NO ==
1103 (NULL != plugin->nat) && 1063 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1104 (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, 1064 &target->hashPubKey)))
1105 &target->hashPubKey)) ) 1065 {
1106 {
1107#if DEBUG_TCP_NAT 1066#if DEBUG_TCP_NAT
1108 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1067 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1109 "tcp", 1068 "tcp",
1110 _("Found valid IPv4 NAT address (creating session)!\n")); 1069 _("Found valid IPv4 NAT address (creating session)!\n"));
1111#endif 1070#endif
1112 session = create_session (plugin, 1071 session = create_session (plugin, target, NULL, GNUNET_YES);
1113 target, 1072 GNUNET_assert (session != NULL);
1114 NULL, 1073
1115 GNUNET_YES); 1074 /* create new message entry */
1116 GNUNET_assert (session != NULL); 1075 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
1117 1076 /* FIXME: the memset of this malloc can be up to 2% of our total runtime */
1118 /* create new message entry */ 1077 pm->msg = (const char *) &pm[1];
1119 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); 1078 memcpy (&pm[1], msg, msgbuf_size);
1120 /* FIXME: the memset of this malloc can be up to 2% of our total runtime */ 1079 /* FIXME: this memcpy can be up to 7% of our total run-time
1121 pm->msg = (const char*) &pm[1]; 1080 * (for transport service) */
1122 memcpy (&pm[1], msg, msgbuf_size); 1081 pm->message_size = msgbuf_size;
1123 /* FIXME: this memcpy can be up to 7% of our total run-time 1082 pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1124 (for transport service) */ 1083 pm->transmit_cont = cont;
1125 pm->message_size = msgbuf_size; 1084 pm->transmit_cont_cls = cont_cls;
1126 pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1085
1127 pm->transmit_cont = cont; 1086 /* append pm to pending_messages list */
1128 pm->transmit_cont_cls = cont_cls; 1087 GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
1129 1088 session->pending_messages_tail,
1130 /* append pm to pending_messages list */ 1089 session->pending_messages_tail, pm);
1131 GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head, 1090
1132 session->pending_messages_tail, 1091 GNUNET_assert (GNUNET_CONTAINER_multihashmap_put (plugin->nat_wait_conns,
1133 session->pending_messages_tail, 1092 &target->hashPubKey,
1134 pm); 1093 session,
1135 1094 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)
1136 GNUNET_assert(GNUNET_CONTAINER_multihashmap_put(plugin->nat_wait_conns, 1095 == GNUNET_OK);
1137 &target->hashPubKey,
1138 session,
1139 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY) == GNUNET_OK);
1140#if DEBUG_TCP_NAT 1096#if DEBUG_TCP_NAT
1141 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1097 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1142 "tcp", 1098 "tcp",
1143 "Created NAT WAIT connection to `%4s' at `%s'\n", 1099 "Created NAT WAIT connection to `%4s' at `%s'\n",
1144 GNUNET_i2s (target), 1100 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1145 GNUNET_a2s (sb, sbs));
1146#endif 1101#endif
1147 GNUNET_NAT_run_client (plugin->nat, &a4); 1102 GNUNET_NAT_run_client (plugin->nat, &a4);
1148 return 0; 1103 return 0;
1149 } 1104 }
1150 if ( (is_natd == GNUNET_YES) && 1105 if ((is_natd == GNUNET_YES) &&
1151 (GNUNET_YES == GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns, 1106 (GNUNET_YES ==
1152 &target->hashPubKey)) ) 1107 GNUNET_CONTAINER_multihashmap_contains (plugin->nat_wait_conns,
1153 { 1108 &target->hashPubKey)))
1154 /* Only do one NAT punch attempt per peer identity */ 1109 {
1155 return -1; 1110 /* Only do one NAT punch attempt per peer identity */
1156 } 1111 return -1;
1157 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs); 1112 }
1158 if (sa == NULL) 1113 sa = GNUNET_CONNECTION_create_from_sockaddr (af, sb, sbs);
1159 { 1114 if (sa == NULL)
1115 {
1160#if DEBUG_TCP 1116#if DEBUG_TCP
1161 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1162 "tcp",
1163 "Failed to create connection to `%4s' at `%s'\n",
1164 GNUNET_i2s (target),
1165 GNUNET_a2s (sb, sbs));
1166#endif
1167 GNUNET_STATISTICS_update (plugin->env->stats,
1168 gettext_noop ("# bytes discarded by TCP (failed to connect)"),
1169 msgbuf_size,
1170 GNUNET_NO);
1171 return -1;
1172 }
1173 GNUNET_assert (0 != plugin->max_connections);
1174 plugin->max_connections--;
1175#if DEBUG_TCP_NAT
1176 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1117 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1177 "tcp", 1118 "tcp",
1178 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n", 1119 "Failed to create connection to `%4s' at `%s'\n",
1179 GNUNET_i2s (target), 1120 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1180 GNUNET_a2s (sb, sbs));
1181#endif 1121#endif
1182 session = create_session (plugin, 1122 GNUNET_STATISTICS_update (plugin->env->stats,
1183 target, 1123 gettext_noop
1184 GNUNET_SERVER_connect_socket (plugin->server, 1124 ("# bytes discarded by TCP (failed to connect)"),
1185 sa), 1125 msgbuf_size, GNUNET_NO);
1186 GNUNET_NO); 1126 return -1;
1187 session->connect_addr = GNUNET_malloc (addrlen);
1188 memcpy (session->connect_addr,
1189 addr,
1190 addrlen);
1191 session->connect_alen = addrlen;
1192 } 1127 }
1193 else /* session != NULL */ 1128 GNUNET_assert (0 != plugin->max_connections);
1129 plugin->max_connections--;
1130#if DEBUG_TCP_NAT
1131 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1132 "tcp",
1133 "Asked to transmit to `%4s', creating fresh session using address `%s'.\n",
1134 GNUNET_i2s (target), GNUNET_a2s (sb, sbs));
1135#endif
1136 session = create_session (plugin,
1137 target,
1138 GNUNET_SERVER_connect_socket (plugin->server,
1139 sa), GNUNET_NO);
1140 session->connect_addr = GNUNET_malloc (addrlen);
1141 memcpy (session->connect_addr, addr, addrlen);
1142 session->connect_alen = addrlen;
1143 }
1144 else /* session != NULL */
1145 {
1146 /* check if session is valid */
1147 struct Session *ses = plugin->sessions;
1148
1149 while ((ses != NULL) && (ses != session))
1150 ses = ses->next;
1151 if (ses == NULL)
1194 { 1152 {
1195 /* check if session is valid */ 1153 GNUNET_break (0);
1196 struct Session * ses = plugin->sessions; 1154 return -1;
1197 while ((ses != NULL) && (ses != session))
1198 ses = ses->next;
1199 if (ses == NULL)
1200 {
1201 GNUNET_break (0);
1202 return -1;
1203 }
1204 } 1155 }
1156 }
1205 GNUNET_assert (session != NULL); 1157 GNUNET_assert (session != NULL);
1206 GNUNET_assert (session->client != NULL); 1158 GNUNET_assert (session->client != NULL);
1207 1159
1208 1160
1209 GNUNET_SERVER_client_set_timeout(session->client, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1161 GNUNET_SERVER_client_set_timeout (session->client,
1162 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1210 GNUNET_STATISTICS_update (plugin->env->stats, 1163 GNUNET_STATISTICS_update (plugin->env->stats,
1211 gettext_noop ("# bytes currently in TCP buffers"), 1164 gettext_noop ("# bytes currently in TCP buffers"),
1212 msgbuf_size, 1165 msgbuf_size, GNUNET_NO);
1213 GNUNET_NO);
1214 /* create new message entry */ 1166 /* create new message entry */
1215 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size); 1167 pm = GNUNET_malloc (sizeof (struct PendingMessage) + msgbuf_size);
1216 pm->msg = (const char*) &pm[1]; 1168 pm->msg = (const char *) &pm[1];
1217 memcpy (&pm[1], msg, msgbuf_size); 1169 memcpy (&pm[1], msg, msgbuf_size);
1218 pm->message_size = msgbuf_size; 1170 pm->message_size = msgbuf_size;
1219 pm->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1171 pm->timeout = GNUNET_TIME_relative_to_absolute (timeout);
@@ -1222,15 +1174,13 @@ tcp_plugin_send (void *cls,
1222 1174
1223 /* append pm to pending_messages list */ 1175 /* append pm to pending_messages list */
1224 GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head, 1176 GNUNET_CONTAINER_DLL_insert_after (session->pending_messages_head,
1225 session->pending_messages_tail, 1177 session->pending_messages_tail,
1226 session->pending_messages_tail, 1178 session->pending_messages_tail, pm);
1227 pm);
1228#if DEBUG_TCP 1179#if DEBUG_TCP
1229 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1180 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1230 "tcp", 1181 "tcp",
1231 "Asked to transmit %u bytes to `%s', added message to list.\n", 1182 "Asked to transmit %u bytes to `%s', added message to list.\n",
1232 msgbuf_size, 1183 msgbuf_size, GNUNET_i2s (target));
1233 GNUNET_i2s (target));
1234#endif 1184#endif
1235 process_pending_messages (session); 1185 process_pending_messages (session);
1236 return msgbuf_size; 1186 return msgbuf_size;
@@ -1254,8 +1204,7 @@ tcp_plugin_send (void *cls,
1254 * to be cancelled 1204 * to be cancelled
1255 */ 1205 */
1256static void 1206static void
1257tcp_plugin_disconnect (void *cls, 1207tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1258 const struct GNUNET_PeerIdentity *target)
1259{ 1208{
1260 struct Plugin *plugin = cls; 1209 struct Plugin *plugin = cls;
1261 struct Session *session; 1210 struct Session *session;
@@ -1264,31 +1213,29 @@ tcp_plugin_disconnect (void *cls,
1264 1213
1265#if DEBUG_TCP 1214#if DEBUG_TCP
1266 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1215 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1267 "tcp", 1216 "tcp",
1268 "Asked to cancel session with `%4s'\n", 1217 "Asked to cancel session with `%4s'\n", GNUNET_i2s (target));
1269 GNUNET_i2s (target));
1270#endif 1218#endif
1271 next = plugin->sessions; 1219 next = plugin->sessions;
1272 while (NULL != (session = next)) 1220 while (NULL != (session = next))
1221 {
1222 next = session->next;
1223 if (0 != memcmp (target,
1224 &session->target, sizeof (struct GNUNET_PeerIdentity)))
1225 continue;
1226 pm = session->pending_messages_head;
1227 while (pm != NULL)
1273 { 1228 {
1274 next = session->next; 1229 pm->transmit_cont = NULL;
1275 if (0 != memcmp (target, 1230 pm->transmit_cont_cls = NULL;
1276 &session->target, 1231 pm = pm->next;
1277 sizeof (struct GNUNET_PeerIdentity)))
1278 continue;
1279 pm = session->pending_messages_head;
1280 while (pm != NULL)
1281 {
1282 pm->transmit_cont = NULL;
1283 pm->transmit_cont_cls = NULL;
1284 pm = pm->next;
1285 }
1286 GNUNET_STATISTICS_update (session->plugin->env->stats,
1287 gettext_noop ("# transport-service disconnect requests for TCP"),
1288 1,
1289 GNUNET_NO);
1290 disconnect_session (session);
1291 } 1232 }
1233 GNUNET_STATISTICS_update (session->plugin->env->stats,
1234 gettext_noop
1235 ("# transport-service disconnect requests for TCP"),
1236 1, GNUNET_NO);
1237 disconnect_session (session);
1238 }
1292} 1239}
1293 1240
1294 1241
@@ -1327,11 +1274,11 @@ append_port (void *cls, const char *hostname)
1327 char *ret; 1274 char *ret;
1328 1275
1329 if (hostname == NULL) 1276 if (hostname == NULL)
1330 { 1277 {
1331 ppc->asc (ppc->asc_cls, NULL); 1278 ppc->asc (ppc->asc_cls, NULL);
1332 GNUNET_free (ppc); 1279 GNUNET_free (ppc);
1333 return; 1280 return;
1334 } 1281 }
1335 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port); 1282 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
1336 ppc->asc (ppc->asc_cls, ret); 1283 ppc->asc (ppc->asc_cls, ret);
1337 GNUNET_free (ret); 1284 GNUNET_free (ret);
@@ -1372,43 +1319,39 @@ tcp_plugin_address_pretty_printer (void *cls,
1372 uint16_t port; 1319 uint16_t port;
1373 1320
1374 if (addrlen == sizeof (struct IPv6TcpAddress)) 1321 if (addrlen == sizeof (struct IPv6TcpAddress))
1375 { 1322 {
1376 t6 = addr; 1323 t6 = addr;
1377 memset (&a6, 0, sizeof (a6)); 1324 memset (&a6, 0, sizeof (a6));
1378 a6.sin6_family = AF_INET6; 1325 a6.sin6_family = AF_INET6;
1379 a6.sin6_port = t6->t6_port; 1326 a6.sin6_port = t6->t6_port;
1380 memcpy (&a6.sin6_addr, 1327 memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof (struct in6_addr));
1381 &t6->ipv6_addr, 1328 port = ntohs (t6->t6_port);
1382 sizeof (struct in6_addr)); 1329 sb = &a6;
1383 port = ntohs (t6->t6_port); 1330 sbs = sizeof (a6);
1384 sb = &a6; 1331 }
1385 sbs = sizeof (a6);
1386 }
1387 else if (addrlen == sizeof (struct IPv4TcpAddress)) 1332 else if (addrlen == sizeof (struct IPv4TcpAddress))
1388 { 1333 {
1389 t4 = addr; 1334 t4 = addr;
1390 memset (&a4, 0, sizeof (a4)); 1335 memset (&a4, 0, sizeof (a4));
1391 a4.sin_family = AF_INET; 1336 a4.sin_family = AF_INET;
1392 a4.sin_port = t4->t4_port; 1337 a4.sin_port = t4->t4_port;
1393 a4.sin_addr.s_addr = t4->ipv4_addr; 1338 a4.sin_addr.s_addr = t4->ipv4_addr;
1394 port = ntohs (t4->t4_port); 1339 port = ntohs (t4->t4_port);
1395 sb = &a4; 1340 sb = &a4;
1396 sbs = sizeof (a4); 1341 sbs = sizeof (a4);
1397 } 1342 }
1398 else 1343 else
1399 { 1344 {
1400 /* invalid address */ 1345 /* invalid address */
1401 GNUNET_break_op (0); 1346 GNUNET_break_op (0);
1402 asc (asc_cls, NULL); 1347 asc (asc_cls, NULL);
1403 return; 1348 return;
1404 } 1349 }
1405 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 1350 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
1406 ppc->asc = asc; 1351 ppc->asc = asc;
1407 ppc->asc_cls = asc_cls; 1352 ppc->asc_cls = asc_cls;
1408 ppc->port = port; 1353 ppc->port = port;
1409 GNUNET_RESOLVER_hostname_get (sb, 1354 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
1410 sbs,
1411 !numeric, timeout, &append_port, ppc);
1412} 1355}
1413 1356
1414 1357
@@ -1423,8 +1366,7 @@ tcp_plugin_address_pretty_printer (void *cls,
1423 * @return GNUNET_OK if port is either open_port or adv_port 1366 * @return GNUNET_OK if port is either open_port or adv_port
1424 */ 1367 */
1425static int 1368static int
1426check_port (struct Plugin *plugin, 1369check_port (struct Plugin *plugin, uint16_t in_port)
1427 uint16_t in_port)
1428{ 1370{
1429 if ((in_port == plugin->adv_port) || (in_port == plugin->open_port)) 1371 if ((in_port == plugin->adv_port) || (in_port == plugin->open_port))
1430 return GNUNET_OK; 1372 return GNUNET_OK;
@@ -1448,9 +1390,7 @@ check_port (struct Plugin *plugin,
1448 * and transport, GNUNET_SYSERR if not 1390 * and transport, GNUNET_SYSERR if not
1449 */ 1391 */
1450static int 1392static int
1451tcp_plugin_check_address (void *cls, 1393tcp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1452 const void *addr,
1453 size_t addrlen)
1454{ 1394{
1455 struct Plugin *plugin = cls; 1395 struct Plugin *plugin = cls;
1456 struct IPv4TcpAddress *v4; 1396 struct IPv4TcpAddress *v4;
@@ -1458,37 +1398,35 @@ tcp_plugin_check_address (void *cls,
1458 1398
1459 if ((addrlen != sizeof (struct IPv4TcpAddress)) && 1399 if ((addrlen != sizeof (struct IPv4TcpAddress)) &&
1460 (addrlen != sizeof (struct IPv6TcpAddress))) 1400 (addrlen != sizeof (struct IPv6TcpAddress)))
1461 { 1401 {
1462 GNUNET_break_op (0); 1402 GNUNET_break_op (0);
1463 return GNUNET_SYSERR; 1403 return GNUNET_SYSERR;
1464 } 1404 }
1465 if (addrlen == sizeof (struct IPv4TcpAddress)) 1405 if (addrlen == sizeof (struct IPv4TcpAddress))
1466 { 1406 {
1467 v4 = (struct IPv4TcpAddress *) addr; 1407 v4 = (struct IPv4TcpAddress *) addr;
1468 if (GNUNET_OK != 1408 if (GNUNET_OK != check_port (plugin, ntohs (v4->t4_port)))
1469 check_port (plugin, ntohs (v4->t4_port))) 1409 return GNUNET_SYSERR;
1470 return GNUNET_SYSERR; 1410 if (GNUNET_OK !=
1471 if (GNUNET_OK != 1411 GNUNET_NAT_test_address (plugin->nat,
1472 GNUNET_NAT_test_address (plugin->nat, 1412 &v4->ipv4_addr, sizeof (struct in_addr)))
1473 &v4->ipv4_addr, sizeof (struct in_addr))) 1413 return GNUNET_SYSERR;
1474 return GNUNET_SYSERR; 1414 }
1475 }
1476 else 1415 else
1416 {
1417 v6 = (struct IPv6TcpAddress *) addr;
1418 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1477 { 1419 {
1478 v6 = (struct IPv6TcpAddress *) addr; 1420 GNUNET_break_op (0);
1479 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 1421 return GNUNET_SYSERR;
1480 {
1481 GNUNET_break_op (0);
1482 return GNUNET_SYSERR;
1483 }
1484 if (GNUNET_OK !=
1485 check_port (plugin, ntohs (v6->t6_port)))
1486 return GNUNET_SYSERR;
1487 if (GNUNET_OK !=
1488 GNUNET_NAT_test_address (plugin->nat,
1489 &v6->ipv6_addr, sizeof (struct in6_addr)))
1490 return GNUNET_SYSERR;
1491 } 1422 }
1423 if (GNUNET_OK != check_port (plugin, ntohs (v6->t6_port)))
1424 return GNUNET_SYSERR;
1425 if (GNUNET_OK !=
1426 GNUNET_NAT_test_address (plugin->nat,
1427 &v6->ipv6_addr, sizeof (struct in6_addr)))
1428 return GNUNET_SYSERR;
1429 }
1492 return GNUNET_OK; 1430 return GNUNET_OK;
1493} 1431}
1494 1432
@@ -1504,8 +1442,8 @@ tcp_plugin_check_address (void *cls,
1504 */ 1442 */
1505static void 1443static void
1506handle_tcp_nat_probe (void *cls, 1444handle_tcp_nat_probe (void *cls,
1507 struct GNUNET_SERVER_Client *client, 1445 struct GNUNET_SERVER_Client *client,
1508 const struct GNUNET_MessageHeader *message) 1446 const struct GNUNET_MessageHeader *message)
1509{ 1447{
1510 struct Plugin *plugin = cls; 1448 struct Plugin *plugin = cls;
1511 struct Session *session; 1449 struct Session *session;
@@ -1518,9 +1456,7 @@ handle_tcp_nat_probe (void *cls,
1518 const struct sockaddr_in6 *s6; 1456 const struct sockaddr_in6 *s6;
1519 1457
1520#if DEBUG_TCP_NAT 1458#if DEBUG_TCP_NAT
1521 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1459 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "tcp", "received NAT probe\n");
1522 "tcp",
1523 "received NAT probe\n");
1524#endif 1460#endif
1525 /* We have received a TCP NAT probe, meaning we (hopefully) initiated 1461 /* We have received a TCP NAT probe, meaning we (hopefully) initiated
1526 * a connection to this peer by running gnunet-nat-client. This peer 1462 * a connection to this peer by running gnunet-nat-client. This peer
@@ -1528,51 +1464,49 @@ handle_tcp_nat_probe (void *cls,
1528 * as the default for that peer. Do so and then send a WELCOME message 1464 * as the default for that peer. Do so and then send a WELCOME message
1529 * so we can really be connected! 1465 * so we can really be connected!
1530 */ 1466 */
1531 if (ntohs(message->size) != sizeof(struct TCP_NAT_ProbeMessage)) 1467 if (ntohs (message->size) != sizeof (struct TCP_NAT_ProbeMessage))
1532 { 1468 {
1533 GNUNET_break_op(0); 1469 GNUNET_break_op (0);
1534 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1470 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1535 return; 1471 return;
1536 } 1472 }
1537 1473
1538 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *)message; 1474 tcp_nat_probe = (const struct TCP_NAT_ProbeMessage *) message;
1539 if (0 == memcmp (&tcp_nat_probe->clientIdentity, 1475 if (0 == memcmp (&tcp_nat_probe->clientIdentity,
1540 plugin->env->my_identity, 1476 plugin->env->my_identity,
1541 sizeof (struct GNUNET_PeerIdentity))) 1477 sizeof (struct GNUNET_PeerIdentity)))
1542 { 1478 {
1543 /* refuse connections from ourselves */ 1479 /* refuse connections from ourselves */
1544 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1480 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1545 return; 1481 return;
1546 } 1482 }
1547 1483
1548 session = GNUNET_CONTAINER_multihashmap_get(plugin->nat_wait_conns, 1484 session = GNUNET_CONTAINER_multihashmap_get (plugin->nat_wait_conns,
1549 &tcp_nat_probe->clientIdentity.hashPubKey); 1485 &tcp_nat_probe->
1486 clientIdentity.hashPubKey);
1550 if (session == NULL) 1487 if (session == NULL)
1551 { 1488 {
1552#if DEBUG_TCP_NAT 1489#if DEBUG_TCP_NAT
1553 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1490 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1554 "tcp", 1491 "tcp", "Did NOT find session for NAT probe!\n");
1555 "Did NOT find session for NAT probe!\n");
1556#endif 1492#endif
1557 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1493 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1558 return; 1494 return;
1559 } 1495 }
1560#if DEBUG_TCP_NAT 1496#if DEBUG_TCP_NAT
1561 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1497 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1562 "tcp", 1498 "tcp", "Found session for NAT probe!\n");
1563 "Found session for NAT probe!\n");
1564#endif 1499#endif
1565 GNUNET_assert(GNUNET_CONTAINER_multihashmap_remove(plugin->nat_wait_conns, 1500 GNUNET_assert (GNUNET_CONTAINER_multihashmap_remove (plugin->nat_wait_conns,
1566 &tcp_nat_probe->clientIdentity.hashPubKey, 1501 &tcp_nat_probe->clientIdentity.hashPubKey,
1567 session) == GNUNET_YES); 1502 session) == GNUNET_YES);
1568 if (GNUNET_OK != 1503 if (GNUNET_OK != GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1569 GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1504 {
1570 { 1505 GNUNET_break (0);
1571 GNUNET_break (0); 1506 GNUNET_free (session);
1572 GNUNET_free (session); 1507 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1573 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1508 return;
1574 return; 1509 }
1575 }
1576 1510
1577 GNUNET_SERVER_client_keep (client); 1511 GNUNET_SERVER_client_keep (client);
1578 session->client = client; 1512 session->client = client;
@@ -1581,51 +1515,47 @@ handle_tcp_nat_probe (void *cls,
1581 1515
1582#if DEBUG_TCP_NAT 1516#if DEBUG_TCP_NAT
1583 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1517 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1584 "tcp", 1518 "tcp",
1585 "Found address `%s' for incoming connection\n", 1519 "Found address `%s' for incoming connection\n",
1586 GNUNET_a2s (vaddr, alen)); 1520 GNUNET_a2s (vaddr, alen));
1587#endif 1521#endif
1588 switch (((const struct sockaddr *)vaddr)->sa_family) 1522 switch (((const struct sockaddr *) vaddr)->sa_family)
1589 { 1523 {
1590 case AF_INET: 1524 case AF_INET:
1591 s4 = vaddr; 1525 s4 = vaddr;
1592 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress)); 1526 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
1593 t4->t4_port = s4->sin_port; 1527 t4->t4_port = s4->sin_port;
1594 t4->ipv4_addr = s4->sin_addr.s_addr; 1528 t4->ipv4_addr = s4->sin_addr.s_addr;
1595 session->connect_addr = t4; 1529 session->connect_addr = t4;
1596 session->connect_alen = sizeof (struct IPv4TcpAddress); 1530 session->connect_alen = sizeof (struct IPv4TcpAddress);
1597 break; 1531 break;
1598 case AF_INET6: 1532 case AF_INET6:
1599 s6 = vaddr; 1533 s6 = vaddr;
1600 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress)); 1534 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
1601 t6->t6_port = s6->sin6_port; 1535 t6->t6_port = s6->sin6_port;
1602 memcpy (&t6->ipv6_addr, 1536 memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
1603 &s6->sin6_addr, 1537 session->connect_addr = t6;
1604 sizeof (struct in6_addr)); 1538 session->connect_alen = sizeof (struct IPv6TcpAddress);
1605 session->connect_addr = t6; 1539 break;
1606 session->connect_alen = sizeof (struct IPv6TcpAddress); 1540 default:
1607 break; 1541 GNUNET_break_op (0);
1608 default:
1609 GNUNET_break_op (0);
1610#if DEBUG_TCP_NAT 1542#if DEBUG_TCP_NAT
1611 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1543 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1612 "tcp", 1544 "tcp", "Bad address for incoming connection!\n");
1613 "Bad address for incoming connection!\n");
1614#endif 1545#endif
1615 GNUNET_free (vaddr); 1546 GNUNET_free (vaddr);
1616 GNUNET_SERVER_client_drop (client); 1547 GNUNET_SERVER_client_drop (client);
1617 GNUNET_free (session); 1548 GNUNET_free (session);
1618 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1549 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1619 return; 1550 return;
1620 } 1551 }
1621 GNUNET_free (vaddr); 1552 GNUNET_free (vaddr);
1622 1553
1623 session->next = plugin->sessions; 1554 session->next = plugin->sessions;
1624 plugin->sessions = session; 1555 plugin->sessions = session;
1625 GNUNET_STATISTICS_update (plugin->env->stats, 1556 GNUNET_STATISTICS_update (plugin->env->stats,
1626 gettext_noop ("# TCP sessions active"), 1557 gettext_noop ("# TCP sessions active"),
1627 1, 1558 1, GNUNET_NO);
1628 GNUNET_NO);
1629 process_pending_messages (session); 1559 process_pending_messages (session);
1630 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1560 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1631} 1561}
@@ -1653,109 +1583,100 @@ handle_tcp_welcome (void *cls,
1653 struct IPv6TcpAddress *t6; 1583 struct IPv6TcpAddress *t6;
1654 const struct sockaddr_in *s4; 1584 const struct sockaddr_in *s4;
1655 const struct sockaddr_in6 *s6; 1585 const struct sockaddr_in6 *s6;
1656 1586
1657 if (0 == memcmp (&wm->clientIdentity, 1587 if (0 == memcmp (&wm->clientIdentity,
1658 plugin->env->my_identity, 1588 plugin->env->my_identity,
1659 sizeof (struct GNUNET_PeerIdentity))) 1589 sizeof (struct GNUNET_PeerIdentity)))
1660 { 1590 {
1661 /* refuse connections from ourselves */ 1591 /* refuse connections from ourselves */
1662 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1592 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1663 return; 1593 return;
1664 } 1594 }
1665#if DEBUG_TCP 1595#if DEBUG_TCP
1666 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1596 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1667 "tcp", 1597 "tcp",
1668 "Received %s message from `%4s'.\n", 1598 "Received %s message from `%4s'.\n",
1669 "WELCOME", 1599 "WELCOME", GNUNET_i2s (&wm->clientIdentity));
1670 GNUNET_i2s (&wm->clientIdentity));
1671#endif 1600#endif
1672 GNUNET_STATISTICS_update (plugin->env->stats, 1601 GNUNET_STATISTICS_update (plugin->env->stats,
1673 gettext_noop ("# TCP WELCOME messages received"), 1602 gettext_noop ("# TCP WELCOME messages received"),
1674 1, 1603 1, GNUNET_NO);
1675 GNUNET_NO);
1676 session = find_session_by_client (plugin, client); 1604 session = find_session_by_client (plugin, client);
1677 1605
1678 if (session == NULL) 1606 if (session == NULL)
1679 { 1607 {
1680#if DEBUG_TCP_NAT 1608#if DEBUG_TCP_NAT
1681 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1609 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1682 "tcp", 1610 "tcp",
1683 "Received %s message from a `%4s', creating new session\n", 1611 "Received %s message from a `%4s', creating new session\n",
1684 "WELCOME", 1612 "WELCOME", GNUNET_i2s (&wm->clientIdentity));
1685 GNUNET_i2s (&wm->clientIdentity));
1686#endif 1613#endif
1687 GNUNET_SERVER_client_keep (client); 1614 GNUNET_SERVER_client_keep (client);
1688 session = create_session (plugin, 1615 session = create_session (plugin, &wm->clientIdentity, client, GNUNET_NO);
1689 &wm->clientIdentity, 1616 session->inbound = GNUNET_YES;
1690 client, 1617 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1691 GNUNET_NO); 1618 {
1692 session->inbound = GNUNET_YES;
1693 if (GNUNET_OK ==
1694 GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1695 {
1696#if DEBUG_TCP_NAT 1619#if DEBUG_TCP_NAT
1697 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1620 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1698 "tcp", 1621 "tcp",
1699 "Found address `%s' for incoming connection\n", 1622 "Found address `%s' for incoming connection\n",
1700 GNUNET_a2s (vaddr, alen)); 1623 GNUNET_a2s (vaddr, alen));
1701#endif 1624#endif
1702 if (alen == sizeof (struct sockaddr_in)) 1625 if (alen == sizeof (struct sockaddr_in))
1703 { 1626 {
1704 s4 = vaddr; 1627 s4 = vaddr;
1705 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress)); 1628 t4 = GNUNET_malloc (sizeof (struct IPv4TcpAddress));
1706 t4->t4_port = s4->sin_port; 1629 t4->t4_port = s4->sin_port;
1707 t4->ipv4_addr = s4->sin_addr.s_addr; 1630 t4->ipv4_addr = s4->sin_addr.s_addr;
1708 session->connect_addr = t4; 1631 session->connect_addr = t4;
1709 session->connect_alen = sizeof (struct IPv4TcpAddress); 1632 session->connect_alen = sizeof (struct IPv4TcpAddress);
1710 } 1633 }
1711 else if (alen == sizeof (struct sockaddr_in6)) 1634 else if (alen == sizeof (struct sockaddr_in6))
1712 { 1635 {
1713 s6 = vaddr; 1636 s6 = vaddr;
1714 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress)); 1637 t6 = GNUNET_malloc (sizeof (struct IPv6TcpAddress));
1715 t6->t6_port = s6->sin6_port; 1638 t6->t6_port = s6->sin6_port;
1716 memcpy (&t6->ipv6_addr, 1639 memcpy (&t6->ipv6_addr, &s6->sin6_addr, sizeof (struct in6_addr));
1717 &s6->sin6_addr, 1640 session->connect_addr = t6;
1718 sizeof (struct in6_addr)); 1641 session->connect_alen = sizeof (struct IPv6TcpAddress);
1719 session->connect_addr = t6; 1642 }
1720 session->connect_alen = sizeof (struct IPv6TcpAddress); 1643
1721 } 1644 GNUNET_free (vaddr);
1722 1645 }
1723 GNUNET_free (vaddr); 1646 else
1724 } 1647 {
1725 else
1726 {
1727#if DEBUG_TCP 1648#if DEBUG_TCP
1728 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1649 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1729 "tcp", 1650 "tcp",
1730 "Did not obtain TCP socket address for incoming connection\n"); 1651 "Did not obtain TCP socket address for incoming connection\n");
1731#endif 1652#endif
1732 }
1733 process_pending_messages (session);
1734 } 1653 }
1654 process_pending_messages (session);
1655 }
1735 else 1656 else
1736 { 1657 {
1737#if DEBUG_TCP_NAT 1658#if DEBUG_TCP_NAT
1738 if (GNUNET_OK == 1659 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
1739 GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 1660 {
1740 { 1661 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1741 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1662 "tcp",
1742 "tcp", 1663 "Found address `%s' (already have session)\n",
1743 "Found address `%s' (already have session)\n", 1664 GNUNET_a2s (vaddr, alen));
1744 GNUNET_a2s (vaddr, alen)); 1665 GNUNET_free (vaddr);
1745 GNUNET_free (vaddr);
1746 }
1747#endif
1748 } 1666 }
1667#endif
1668 }
1749 1669
1750 if (session->expecting_welcome != GNUNET_YES) 1670 if (session->expecting_welcome != GNUNET_YES)
1751 { 1671 {
1752 GNUNET_break_op (0); 1672 GNUNET_break_op (0);
1753 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1673 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1754 return; 1674 return;
1755 } 1675 }
1756 session->last_activity = GNUNET_TIME_absolute_get (); 1676 session->last_activity = GNUNET_TIME_absolute_get ();
1757 session->expecting_welcome = GNUNET_NO; 1677 session->expecting_welcome = GNUNET_NO;
1758 GNUNET_SERVER_client_set_timeout(client, GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1678 GNUNET_SERVER_client_set_timeout (client,
1679 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1759 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1680 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1760} 1681}
1761 1682
@@ -1768,24 +1689,20 @@ handle_tcp_welcome (void *cls,
1768 * @param tc task context (unused) 1689 * @param tc task context (unused)
1769 */ 1690 */
1770static void 1691static void
1771delayed_done (void *cls, 1692delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1772 const struct GNUNET_SCHEDULER_TaskContext *tc)
1773{ 1693{
1774 struct Session *session = cls; 1694 struct Session *session = cls;
1775 struct GNUNET_TIME_Relative delay; 1695 struct GNUNET_TIME_Relative delay;
1776 1696
1777 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK; 1697 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
1778 delay = session->plugin->env->receive (session->plugin->env->cls, 1698 delay = session->plugin->env->receive (session->plugin->env->cls,
1779 &session->target, 1699 &session->target,
1780 NULL, 1700 NULL, NULL, 0, session, NULL, 0);
1781 NULL, 0,
1782 session,
1783 NULL, 0);
1784 if (delay.rel_value == 0) 1701 if (delay.rel_value == 0)
1785 GNUNET_SERVER_receive_done (session->client, GNUNET_OK); 1702 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
1786 else 1703 else
1787 session->receive_delay_task = 1704 session->receive_delay_task =
1788 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); 1705 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
1789} 1706}
1790 1707
1791 1708
@@ -1808,60 +1725,62 @@ handle_tcp_data (void *cls,
1808 uint16_t type; 1725 uint16_t type;
1809 1726
1810 type = ntohs (message->type); 1727 type = ntohs (message->type);
1811 if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) || 1728 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
1812 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) ) 1729 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type))
1813 { 1730 {
1814 /* We don't want to propagate WELCOME and NAT Probe messages up! */ 1731 /* We don't want to propagate WELCOME and NAT Probe messages up! */
1815 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1732 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1816 return; 1733 return;
1817 } 1734 }
1818 session = find_session_by_client (plugin, client); 1735 session = find_session_by_client (plugin, client);
1819 if ( (NULL == session) || (GNUNET_YES == session->expecting_welcome) ) 1736 if ((NULL == session) || (GNUNET_YES == session->expecting_welcome))
1820 { 1737 {
1821 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 1738 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1822 return; 1739 return;
1823 } 1740 }
1824 session->last_activity = GNUNET_TIME_absolute_get (); 1741 session->last_activity = GNUNET_TIME_absolute_get ();
1825#if DEBUG_TCP > 1 1742#if DEBUG_TCP > 1
1826 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1743 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1827 "tcp", 1744 "tcp",
1828 "Passing %u bytes of type %u from `%4s' to transport service.\n", 1745 "Passing %u bytes of type %u from `%4s' to transport service.\n",
1829 (unsigned int) ntohs (message->size), 1746 (unsigned int) ntohs (message->size),
1830 (unsigned int) ntohs (message->type), 1747 (unsigned int) ntohs (message->type),
1831 GNUNET_i2s (&session->target)); 1748 GNUNET_i2s (&session->target));
1832#endif 1749#endif
1833 GNUNET_STATISTICS_update (plugin->env->stats, 1750 GNUNET_STATISTICS_update (plugin->env->stats,
1834 gettext_noop ("# bytes received via TCP"), 1751 gettext_noop ("# bytes received via TCP"),
1835 ntohs (message->size), 1752 ntohs (message->size), GNUNET_NO);
1836 GNUNET_NO);
1837 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 1753 struct GNUNET_TRANSPORT_ATS_Information distance[2];
1754
1838 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 1755 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
1839 distance[0].value = htonl (1); 1756 distance[0].value = htonl (1);
1840 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 1757 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
1841 distance[1].value = htonl (0); 1758 distance[1].value = htonl (0);
1842 delay = plugin->env->receive (plugin->env->cls, &session->target, message, 1759 delay = plugin->env->receive (plugin->env->cls, &session->target, message,
1843 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 1760 (const struct GNUNET_TRANSPORT_ATS_Information
1844 2, 1761 *) &distance, 2, session,
1845 session, 1762 (GNUNET_YES ==
1846 (GNUNET_YES == session->inbound) ? NULL : session->connect_addr, 1763 session->
1847 (GNUNET_YES == session->inbound) ? 0 : session->connect_alen); 1764 inbound) ? NULL : session->connect_addr,
1765 (GNUNET_YES ==
1766 session->inbound) ? 0 : session->connect_alen);
1848 if (delay.rel_value == 0) 1767 if (delay.rel_value == 0)
1849 { 1768 {
1850 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1769 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1851 } 1770 }
1852 else 1771 else
1853 { 1772 {
1854#if DEBUG_TCP 1773#if DEBUG_TCP
1855 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1774 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1856 "tcp", 1775 "tcp",
1857 "Throttling receiving from `%s' for %llu ms\n", 1776 "Throttling receiving from `%s' for %llu ms\n",
1858 GNUNET_i2s (&session->target), 1777 GNUNET_i2s (&session->target),
1859 (unsigned long long) delay.rel_value); 1778 (unsigned long long) delay.rel_value);
1860#endif 1779#endif
1861 GNUNET_SERVER_disable_receive_done_warning (client); 1780 GNUNET_SERVER_disable_receive_done_warning (client);
1862 session->receive_delay_task = 1781 session->receive_delay_task =
1863 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session); 1782 GNUNET_SCHEDULER_add_delayed (delay, &delayed_done, session);
1864 } 1783 }
1865} 1784}
1866 1785
1867 1786
@@ -1873,8 +1792,7 @@ handle_tcp_data (void *cls,
1873 * @param client identification of the client 1792 * @param client identification of the client
1874 */ 1793 */
1875static void 1794static void
1876disconnect_notify (void *cls, 1795disconnect_notify (void *cls, struct GNUNET_SERVER_Client *client)
1877 struct GNUNET_SERVER_Client *client)
1878{ 1796{
1879 struct Plugin *plugin = cls; 1797 struct Plugin *plugin = cls;
1880 struct Session *session; 1798 struct Session *session;
@@ -1887,18 +1805,18 @@ disconnect_notify (void *cls,
1887 return; /* unknown, nothing to do */ 1805 return; /* unknown, nothing to do */
1888#if DEBUG_TCP 1806#if DEBUG_TCP
1889 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 1807 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
1890 "tcp", 1808 "tcp",
1891 "Destroying session of `%4s' with %s due to network-level disconnect.\n", 1809 "Destroying session of `%4s' with %s due to network-level disconnect.\n",
1892 GNUNET_i2s (&session->target), 1810 GNUNET_i2s (&session->target),
1893 (session->connect_addr != NULL) ? 1811 (session->connect_addr != NULL) ?
1894 tcp_address_to_string (session->plugin, 1812 tcp_address_to_string (session->plugin,
1895 session->connect_addr, 1813 session->connect_addr,
1896 session->connect_alen) : "*"); 1814 session->connect_alen) : "*");
1897#endif 1815#endif
1898 GNUNET_STATISTICS_update (session->plugin->env->stats, 1816 GNUNET_STATISTICS_update (session->plugin->env->stats,
1899 gettext_noop ("# network-level TCP disconnect events"), 1817 gettext_noop
1900 1, 1818 ("# network-level TCP disconnect events"), 1,
1901 GNUNET_NO); 1819 GNUNET_NO);
1902 disconnect_session (session); 1820 disconnect_session (session);
1903} 1821}
1904 1822
@@ -1912,9 +1830,7 @@ disconnect_notify (void *cls,
1912 * @return number of bytes copied into buf 1830 * @return number of bytes copied into buf
1913 */ 1831 */
1914static size_t 1832static size_t
1915notify_send_probe (void *cls, 1833notify_send_probe (void *cls, size_t size, void *buf)
1916 size_t size,
1917 void *buf)
1918{ 1834{
1919 struct TCPProbeContext *tcp_probe_ctx = cls; 1835 struct TCPProbeContext *tcp_probe_ctx = cls;
1920 struct Plugin *plugin = tcp_probe_ctx->plugin; 1836 struct Plugin *plugin = tcp_probe_ctx->plugin;
@@ -1922,20 +1838,19 @@ notify_send_probe (void *cls,
1922 1838
1923 tcp_probe_ctx->transmit_handle = NULL; 1839 tcp_probe_ctx->transmit_handle = NULL;
1924 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, 1840 GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
1925 plugin->probe_tail, 1841 plugin->probe_tail, tcp_probe_ctx);
1926 tcp_probe_ctx);
1927 if (buf == NULL) 1842 if (buf == NULL)
1928 { 1843 {
1929 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO); 1844 GNUNET_CONNECTION_destroy (tcp_probe_ctx->sock, GNUNET_NO);
1930 GNUNET_free(tcp_probe_ctx); 1845 GNUNET_free (tcp_probe_ctx);
1931 return 0; 1846 return 0;
1932 } 1847 }
1933 GNUNET_assert(size >= sizeof(tcp_probe_ctx->message)); 1848 GNUNET_assert (size >= sizeof (tcp_probe_ctx->message));
1934 memcpy(buf, &tcp_probe_ctx->message, sizeof(tcp_probe_ctx->message)); 1849 memcpy (buf, &tcp_probe_ctx->message, sizeof (tcp_probe_ctx->message));
1935 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server, 1850 GNUNET_SERVER_connect_socket (tcp_probe_ctx->plugin->server,
1936 tcp_probe_ctx->sock); 1851 tcp_probe_ctx->sock);
1937 ret = sizeof(tcp_probe_ctx->message); 1852 ret = sizeof (tcp_probe_ctx->message);
1938 GNUNET_free(tcp_probe_ctx); 1853 GNUNET_free (tcp_probe_ctx);
1939 return ret; 1854 return ret;
1940} 1855}
1941 1856
@@ -1951,8 +1866,7 @@ notify_send_probe (void *cls,
1951 */ 1866 */
1952static void 1867static void
1953try_connection_reversal (void *cls, 1868try_connection_reversal (void *cls,
1954 const struct sockaddr *addr, 1869 const struct sockaddr *addr, socklen_t addrlen)
1955 socklen_t addrlen)
1956{ 1870{
1957 struct Plugin *plugin = cls; 1871 struct Plugin *plugin = cls;
1958 struct GNUNET_CONNECTION_Handle *sock; 1872 struct GNUNET_CONNECTION_Handle *sock;
@@ -1962,37 +1876,34 @@ try_connection_reversal (void *cls,
1962 * We have received an ICMP response, ostensibly from a peer 1876 * We have received an ICMP response, ostensibly from a peer
1963 * that wants to connect to us! Send a message to establish a connection. 1877 * that wants to connect to us! Send a message to establish a connection.
1964 */ 1878 */
1965 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, 1879 sock = GNUNET_CONNECTION_create_from_sockaddr (AF_INET, addr, addrlen);
1966 addr,
1967 addrlen);
1968 if (sock == NULL) 1880 if (sock == NULL)
1969 { 1881 {
1970 /* failed for some odd reason (out of sockets?); ignore attempt */ 1882 /* failed for some odd reason (out of sockets?); ignore attempt */
1971 return; 1883 return;
1972 } 1884 }
1973 1885
1974 /* FIXME: do we need to track these probe context objects so that 1886 /* FIXME: do we need to track these probe context objects so that
1975 we can clean them up on plugin unload? */ 1887 * we can clean them up on plugin unload? */
1976 tcp_probe_ctx 1888 tcp_probe_ctx = GNUNET_malloc (sizeof (struct TCPProbeContext));
1977 = GNUNET_malloc(sizeof(struct TCPProbeContext));
1978 tcp_probe_ctx->message.header.size 1889 tcp_probe_ctx->message.header.size
1979 = htons(sizeof(struct TCP_NAT_ProbeMessage)); 1890 = htons (sizeof (struct TCP_NAT_ProbeMessage));
1980 tcp_probe_ctx->message.header.type 1891 tcp_probe_ctx->message.header.type
1981 = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE); 1892 = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE);
1982 memcpy (&tcp_probe_ctx->message.clientIdentity, 1893 memcpy (&tcp_probe_ctx->message.clientIdentity,
1983 plugin->env->my_identity, 1894 plugin->env->my_identity, sizeof (struct GNUNET_PeerIdentity));
1984 sizeof(struct GNUNET_PeerIdentity));
1985 tcp_probe_ctx->plugin = plugin; 1895 tcp_probe_ctx->plugin = plugin;
1986 tcp_probe_ctx->sock = sock; 1896 tcp_probe_ctx->sock = sock;
1987 GNUNET_CONTAINER_DLL_insert (plugin->probe_head, 1897 GNUNET_CONTAINER_DLL_insert (plugin->probe_head,
1988 plugin->probe_tail, 1898 plugin->probe_tail, tcp_probe_ctx);
1989 tcp_probe_ctx); 1899 tcp_probe_ctx->transmit_handle
1990 tcp_probe_ctx->transmit_handle 1900 = GNUNET_CONNECTION_notify_transmit_ready (sock,
1991 = GNUNET_CONNECTION_notify_transmit_ready (sock, 1901 ntohs (tcp_probe_ctx->
1992 ntohs (tcp_probe_ctx->message.header.size), 1902 message.header.size),
1993 GNUNET_TIME_UNIT_FOREVER_REL, 1903 GNUNET_TIME_UNIT_FOREVER_REL,
1994 &notify_send_probe, tcp_probe_ctx); 1904 &notify_send_probe,
1995 1905 tcp_probe_ctx);
1906
1996} 1907}
1997 1908
1998 1909
@@ -2008,7 +1919,8 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2008 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { 1919 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
2009 {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, 1920 {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
2010 sizeof (struct WelcomeMessage)}, 1921 sizeof (struct WelcomeMessage)},
2011 {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, sizeof (struct TCP_NAT_ProbeMessage)}, 1922 {&handle_tcp_nat_probe, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
1923 sizeof (struct TCP_NAT_ProbeMessage)},
2012 {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, 1924 {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0},
2013 {NULL, NULL, 0, 0} 1925 {NULL, NULL, 0, 0}
2014 }; 1926 };
@@ -2031,42 +1943,41 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2031 "MAX_CONNECTIONS", 1943 "MAX_CONNECTIONS",
2032 &max_connections)) 1944 &max_connections))
2033 max_connections = 128; 1945 max_connections = 128;
2034 1946
2035 aport = 0; 1947 aport = 0;
2036 if ( (GNUNET_OK != 1948 if ((GNUNET_OK !=
2037 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1949 GNUNET_CONFIGURATION_get_value_number (env->cfg,
2038 "transport-tcp", 1950 "transport-tcp",
2039 "PORT", 1951 "PORT",
2040 &bport)) || 1952 &bport)) ||
2041 (bport > 65535) || 1953 (bport > 65535) ||
2042 ((GNUNET_OK == 1954 ((GNUNET_OK ==
2043 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1955 GNUNET_CONFIGURATION_get_value_number (env->cfg,
2044 "transport-tcp", 1956 "transport-tcp",
2045 "ADVERTISED-PORT", 1957 "ADVERTISED-PORT",
2046 &aport)) && 1958 &aport)) && (aport > 65535)))
2047 (aport > 65535)) ) 1959 {
2048 { 1960 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2049 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1961 "tcp",
2050 "tcp", 1962 _
2051 _("Require valid port number for service `%s' in configuration!\n"), 1963 ("Require valid port number for service `%s' in configuration!\n"),
2052 "transport-tcp"); 1964 "transport-tcp");
2053 return NULL; 1965 return NULL;
2054 } 1966 }
2055 if (aport == 0) 1967 if (aport == 0)
2056 aport = bport; 1968 aport = bport;
2057 if (bport == 0) 1969 if (bport == 0)
2058 aport = 0; 1970 aport = 0;
2059 if (bport != 0) 1971 if (bport != 0)
1972 {
1973 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg);
1974 if (service == NULL)
2060 { 1975 {
2061 service = GNUNET_SERVICE_start ("transport-tcp", env->cfg); 1976 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
2062 if (service == NULL) 1977 "tcp", _("Failed to start service.\n"));
2063 { 1978 return NULL;
2064 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING,
2065 "tcp",
2066 _("Failed to start service.\n"));
2067 return NULL;
2068 }
2069 } 1979 }
1980 }
2070 else 1981 else
2071 service = NULL; 1982 service = NULL;
2072 1983
@@ -2078,41 +1989,37 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2078 plugin->adv_port = aport; 1989 plugin->adv_port = aport;
2079 plugin->env = env; 1990 plugin->env = env;
2080 plugin->lsock = NULL; 1991 plugin->lsock = NULL;
2081 if ( (service != NULL) && 1992 if ((service != NULL) &&
2082 (GNUNET_SYSERR != 1993 (GNUNET_SYSERR !=
2083 (ret = GNUNET_SERVICE_get_server_addresses ("transport-tcp", 1994 (ret = GNUNET_SERVICE_get_server_addresses ("transport-tcp",
2084 env->cfg, 1995 env->cfg,
2085 &addrs, 1996 &addrs, &addrlens))))
2086 &addrlens))) ) 1997 {
1998 plugin->nat = GNUNET_NAT_register (env->cfg,
1999 GNUNET_YES,
2000 aport,
2001 (unsigned int) ret,
2002 (const struct sockaddr **) addrs,
2003 addrlens,
2004 &tcp_nat_port_map_callback,
2005 &try_connection_reversal, plugin);
2006 while (ret > 0)
2087 { 2007 {
2088 plugin->nat = GNUNET_NAT_register (env->cfg, 2008 ret--;
2089 GNUNET_YES, 2009 GNUNET_assert (addrs[ret] != NULL);
2090 aport, 2010 GNUNET_free (addrs[ret]);
2091 (unsigned int) ret,
2092 (const struct sockaddr **) addrs,
2093 addrlens,
2094 &tcp_nat_port_map_callback,
2095 &try_connection_reversal,
2096 plugin);
2097 while (ret > 0)
2098 {
2099 ret--;
2100 GNUNET_assert (addrs[ret] != NULL);
2101 GNUNET_free (addrs[ret]);
2102 }
2103 GNUNET_free_non_null (addrs);
2104 GNUNET_free_non_null (addrlens);
2105 } 2011 }
2012 GNUNET_free_non_null (addrs);
2013 GNUNET_free_non_null (addrlens);
2014 }
2106 else 2015 else
2107 { 2016 {
2108 plugin->nat = GNUNET_NAT_register (env->cfg, 2017 plugin->nat = GNUNET_NAT_register (env->cfg,
2109 GNUNET_YES, 2018 GNUNET_YES,
2110 0, 2019 0,
2111 0, NULL, NULL, 2020 0, NULL, NULL,
2112 NULL, 2021 NULL, &try_connection_reversal, plugin);
2113 &try_connection_reversal, 2022 }
2114 plugin);
2115 }
2116 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 2023 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
2117 api->cls = plugin; 2024 api->cls = plugin;
2118 api->send = &tcp_plugin_send; 2025 api->send = &tcp_plugin_send;
@@ -2121,32 +2028,31 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2121 api->check_address = &tcp_plugin_check_address; 2028 api->check_address = &tcp_plugin_check_address;
2122 api->address_to_string = &tcp_address_to_string; 2029 api->address_to_string = &tcp_address_to_string;
2123 plugin->service = service; 2030 plugin->service = service;
2124 if (service != NULL) 2031 if (service != NULL)
2125 { 2032 {
2126 plugin->server = GNUNET_SERVICE_get_server (service); 2033 plugin->server = GNUNET_SERVICE_get_server (service);
2127 } 2034 }
2128 else 2035 else
2036 {
2037 if (GNUNET_OK !=
2038 GNUNET_CONFIGURATION_get_value_time (env->cfg,
2039 "transport-tcp",
2040 "TIMEOUT", &idle_timeout))
2129 { 2041 {
2130 if (GNUNET_OK != 2042 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
2131 GNUNET_CONFIGURATION_get_value_time (env->cfg, 2043 "tcp",
2132 "transport-tcp", 2044 _("Failed to find option %s in section %s!\n"),
2133 "TIMEOUT", 2045 "TIMEOUT", "transport-tcp");
2134 &idle_timeout)) 2046 if (plugin->nat != NULL)
2135 { 2047 GNUNET_NAT_unregister (plugin->nat);
2136 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 2048 GNUNET_free (plugin);
2137 "tcp", 2049 GNUNET_free (api);
2138 _("Failed to find option %s in section %s!\n"), 2050 return NULL;
2139 "TIMEOUT",
2140 "transport-tcp");
2141 if (plugin->nat != NULL)
2142 GNUNET_NAT_unregister (plugin->nat);
2143 GNUNET_free (plugin);
2144 GNUNET_free (api);
2145 return NULL;
2146 }
2147 plugin->server = GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, plugin, NULL,
2148 idle_timeout, GNUNET_YES);
2149 } 2051 }
2052 plugin->server =
2053 GNUNET_SERVER_create_with_sockets (&plugin_tcp_access_check, plugin,
2054 NULL, idle_timeout, GNUNET_YES);
2055 }
2150 plugin->handlers = GNUNET_malloc (sizeof (my_handlers)); 2056 plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
2151 memcpy (plugin->handlers, my_handlers, sizeof (my_handlers)); 2057 memcpy (plugin->handlers, my_handlers, sizeof (my_handlers));
2152 for (i = 0; 2058 for (i = 0;
@@ -2154,23 +2060,21 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2154 i++) 2060 i++)
2155 plugin->handlers[i].callback_cls = plugin; 2061 plugin->handlers[i].callback_cls = plugin;
2156 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); 2062 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers);
2157 GNUNET_SERVER_disconnect_notify (plugin->server, 2063 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin);
2158 &disconnect_notify, 2064 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create (16);
2159 plugin);
2160 plugin->nat_wait_conns = GNUNET_CONTAINER_multihashmap_create(16);
2161 if (bport != 0) 2065 if (bport != 0)
2162 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2066 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
2163 "tcp", 2067 "tcp", _("TCP transport listening on port %llu\n"), bport);
2164 _("TCP transport listening on port %llu\n"),
2165 bport);
2166 else 2068 else
2167 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2069 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
2168 "tcp", 2070 "tcp",
2169 _("TCP transport not listening on any port (client only)\n")); 2071 _
2072 ("TCP transport not listening on any port (client only)\n"));
2170 if (aport != bport) 2073 if (aport != bport)
2171 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, 2074 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO,
2172 "tcp", 2075 "tcp",
2173 _("TCP transport advertises itself as being on port %llu\n"), 2076 _
2077 ("TCP transport advertises itself as being on port %llu\n"),
2174 aport); 2078 aport);
2175 return api; 2079 return api;
2176} 2080}
@@ -2197,13 +2101,12 @@ libgnunet_plugin_transport_tcp_done (void *cls)
2197 if (plugin->nat != NULL) 2101 if (plugin->nat != NULL)
2198 GNUNET_NAT_unregister (plugin->nat); 2102 GNUNET_NAT_unregister (plugin->nat);
2199 while (NULL != (tcp_probe = plugin->probe_head)) 2103 while (NULL != (tcp_probe = plugin->probe_head))
2200 { 2104 {
2201 GNUNET_CONTAINER_DLL_remove (plugin->probe_head, 2105 GNUNET_CONTAINER_DLL_remove (plugin->probe_head,
2202 plugin->probe_tail, 2106 plugin->probe_tail, tcp_probe);
2203 tcp_probe); 2107 GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO);
2204 GNUNET_CONNECTION_destroy (tcp_probe->sock, GNUNET_NO); 2108 GNUNET_free (tcp_probe);
2205 GNUNET_free (tcp_probe); 2109 }
2206 }
2207 GNUNET_CONTAINER_multihashmap_destroy (plugin->nat_wait_conns); 2110 GNUNET_CONTAINER_multihashmap_destroy (plugin->nat_wait_conns);
2208 GNUNET_free (plugin); 2111 GNUNET_free (plugin);
2209 GNUNET_free (api); 2112 GNUNET_free (api);
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index fb0421ee3..d83807a36 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -152,13 +152,12 @@ struct Plugin
152 */ 152 */
153static ssize_t 153static ssize_t
154template_plugin_send (void *cls, 154template_plugin_send (void *cls,
155 const struct GNUNET_PeerIdentity * 155 const struct GNUNET_PeerIdentity *target,
156 target,
157 const char *msgbuf, 156 const char *msgbuf,
158 size_t msgbuf_size, 157 size_t msgbuf_size,
159 unsigned int priority, 158 unsigned int priority,
160 struct GNUNET_TIME_Relative timeout, 159 struct GNUNET_TIME_Relative timeout,
161 struct Session *session, 160 struct Session *session,
162 const void *addr, 161 const void *addr,
163 size_t addrlen, 162 size_t addrlen,
164 int force_address, 163 int force_address,
@@ -166,6 +165,7 @@ template_plugin_send (void *cls,
166 cont, void *cont_cls) 165 cont, void *cont_cls)
167{ 166{
168 int bytes_sent = 0; 167 int bytes_sent = 0;
168
169 /* struct Plugin *plugin = cls; */ 169 /* struct Plugin *plugin = cls; */
170 return bytes_sent; 170 return bytes_sent;
171} 171}
@@ -181,8 +181,7 @@ template_plugin_send (void *cls,
181 * @param target peer from which to disconnect 181 * @param target peer from which to disconnect
182 */ 182 */
183static void 183static void
184template_plugin_disconnect (void *cls, 184template_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
185 const struct GNUNET_PeerIdentity *target)
186{ 185{
187 // struct Plugin *plugin = cls; 186 // struct Plugin *plugin = cls;
188 // FIXME 187 // FIXME
@@ -231,14 +230,12 @@ template_plugin_address_pretty_printer (void *cls,
231 * and transport 230 * and transport
232 */ 231 */
233static int 232static int
234template_plugin_address_suggested (void *cls, 233template_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
235 const void *addr,
236 size_t addrlen)
237{ 234{
238 /* struct Plugin *plugin = cls; */ 235 /* struct Plugin *plugin = cls; */
239 236
240 /* check if the address is plausible; if so, 237 /* check if the address is plausible; if so,
241 add it to our list! */ 238 * add it to our list! */
242 return GNUNET_OK; 239 return GNUNET_OK;
243} 240}
244 241
@@ -254,10 +251,8 @@ template_plugin_address_suggested (void *cls,
254 * @param addrlen length of the address 251 * @param addrlen length of the address
255 * @return string representing the same address 252 * @return string representing the same address
256 */ 253 */
257static const char* 254static const char *
258template_plugin_address_to_string (void *cls, 255template_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
259 const void *addr,
260 size_t addrlen)
261{ 256{
262 GNUNET_break (0); 257 GNUNET_break (0);
263 return NULL; 258 return NULL;
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 7d8c1520f..df8447a12 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -193,7 +193,7 @@ struct ReceiveContext
193 193
194 /** 194 /**
195 * Node in the defrag heap. 195 * Node in the defrag heap.
196 */ 196 */
197 struct GNUNET_CONTAINER_HeapNode *hnode; 197 struct GNUNET_CONTAINER_HeapNode *hnode;
198 198
199 /** 199 /**
@@ -297,11 +297,10 @@ struct Plugin
297 * @return NULL if we have no session 297 * @return NULL if we have no session
298 */ 298 */
299struct PeerSession * 299struct PeerSession *
300find_session (struct Plugin *plugin, 300find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
301 const struct GNUNET_PeerIdentity *peer)
302{ 301{
303 return GNUNET_CONTAINER_multihashmap_get (plugin->sessions, 302 return GNUNET_CONTAINER_multihashmap_get (plugin->sessions,
304 &peer->hashPubKey); 303 &peer->hashPubKey);
305} 304}
306 305
307 306
@@ -322,9 +321,9 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
322 if (NULL == session) 321 if (NULL == session)
323 return; 322 return;
324 GNUNET_assert (GNUNET_OK == 323 GNUNET_assert (GNUNET_OK ==
325 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions, 324 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
326 &target->hashPubKey, 325 &target->hashPubKey,
327 session)); 326 session));
328 plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag); 327 plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag);
329 session->cont (session->cont_cls, target, GNUNET_SYSERR); 328 session->cont (session->cont_cls, target, GNUNET_SYSERR);
330 GNUNET_free (session); 329 GNUNET_free (session);
@@ -352,48 +351,43 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
352 */ 351 */
353static ssize_t 352static ssize_t
354udp_send (struct Plugin *plugin, 353udp_send (struct Plugin *plugin,
355 const struct sockaddr *sa, 354 const struct sockaddr *sa, const struct GNUNET_MessageHeader *msg)
356 const struct GNUNET_MessageHeader *msg)
357{ 355{
358 ssize_t sent; 356 ssize_t sent;
359 size_t slen; 357 size_t slen;
360 358
361 switch (sa->sa_family) 359 switch (sa->sa_family)
362 { 360 {
363 case AF_INET: 361 case AF_INET:
364 if (NULL == plugin->sockv4) 362 if (NULL == plugin->sockv4)
365 return 0;
366 sent =
367 GNUNET_NETWORK_socket_sendto (plugin->sockv4,
368 msg,
369 ntohs (msg->size),
370 sa,
371 slen = sizeof (struct sockaddr_in));
372 break;
373 case AF_INET6:
374 if (NULL == plugin->sockv6)
375 return 0;
376 sent =
377 GNUNET_NETWORK_socket_sendto (plugin->sockv6,
378 msg,
379 ntohs (msg->size),
380 sa,
381 slen = sizeof (struct sockaddr_in6));
382 break;
383 default:
384 GNUNET_break (0);
385 return 0; 363 return 0;
386 } 364 sent =
365 GNUNET_NETWORK_socket_sendto (plugin->sockv4,
366 msg,
367 ntohs (msg->size),
368 sa, slen = sizeof (struct sockaddr_in));
369 break;
370 case AF_INET6:
371 if (NULL == plugin->sockv6)
372 return 0;
373 sent =
374 GNUNET_NETWORK_socket_sendto (plugin->sockv6,
375 msg,
376 ntohs (msg->size),
377 sa, slen = sizeof (struct sockaddr_in6));
378 break;
379 default:
380 GNUNET_break (0);
381 return 0;
382 }
387 if (GNUNET_SYSERR == sent) 383 if (GNUNET_SYSERR == sent)
388 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, 384 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "sendto");
389 "sendto");
390#if DEBUG_UDP 385#if DEBUG_UDP
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "UDP transmited %u-byte message to %s (%d: %s)\n", 387 "UDP transmited %u-byte message to %s (%d: %s)\n",
393 (unsigned int) ntohs (msg->size), 388 (unsigned int) ntohs (msg->size),
394 GNUNET_a2s (sa, slen), 389 GNUNET_a2s (sa, slen),
395 (int) sent, 390 (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
396 (sent < 0) ? STRERROR (errno) : "ok");
397#endif 391#endif
398 return sent; 392 return sent;
399} 393}
@@ -408,15 +402,12 @@ udp_send (struct Plugin *plugin,
408 * @param cls closure, the 'struct PeerSession' 402 * @param cls closure, the 'struct PeerSession'
409 * @param msg the message that was created 403 * @param msg the message that was created
410 */ 404 */
411static void 405static void
412send_fragment (void *cls, 406send_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
413 const struct GNUNET_MessageHeader *msg)
414{ 407{
415 struct PeerSession *session = cls; 408 struct PeerSession *session = cls;
416 409
417 udp_send (session->plugin, 410 udp_send (session->plugin, session->sock_addr, msg);
418 session->sock_addr,
419 msg);
420 GNUNET_FRAGMENT_context_transmission_done (session->frag); 411 GNUNET_FRAGMENT_context_transmission_done (session->frag);
421} 412}
422 413
@@ -447,16 +438,16 @@ send_fragment (void *cls,
447 */ 438 */
448static ssize_t 439static ssize_t
449udp_plugin_send (void *cls, 440udp_plugin_send (void *cls,
450 const struct GNUNET_PeerIdentity *target, 441 const struct GNUNET_PeerIdentity *target,
451 const char *msgbuf, 442 const char *msgbuf,
452 size_t msgbuf_size, 443 size_t msgbuf_size,
453 unsigned int priority, 444 unsigned int priority,
454 struct GNUNET_TIME_Relative timeout, 445 struct GNUNET_TIME_Relative timeout,
455 struct Session *session, 446 struct Session *session,
456 const void *addr, 447 const void *addr,
457 size_t addrlen, 448 size_t addrlen,
458 int force_address, 449 int force_address,
459 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 450 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
460{ 451{
461 struct Plugin *plugin = cls; 452 struct Plugin *plugin = cls;
462 struct PeerSession *peer_session; 453 struct PeerSession *peer_session;
@@ -472,50 +463,54 @@ udp_plugin_send (void *cls,
472 return GNUNET_SYSERR; 463 return GNUNET_SYSERR;
473 GNUNET_assert (NULL == session); 464 GNUNET_assert (NULL == session);
474 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 465 if (mlen >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
475 { 466 {
476 GNUNET_break (0); 467 GNUNET_break (0);
477 return GNUNET_SYSERR; 468 return GNUNET_SYSERR;
478 } 469 }
479 switch (addrlen) 470 switch (addrlen)
471 {
472 case sizeof (struct IPv4UdpAddress):
473 if (NULL == plugin->sockv4)
480 { 474 {
481 case sizeof(struct IPv4UdpAddress): 475 cont (cont_cls, target, GNUNET_SYSERR);
482 if (NULL == plugin->sockv4) 476 return 0;
483 { 477 }
484 cont (cont_cls, target, GNUNET_SYSERR); 478 t4 = addr;
485 return 0; 479 peer_session =
486 } 480 GNUNET_malloc (sizeof (struct PeerSession) +
487 t4 = addr; 481 sizeof (struct sockaddr_in));
488 peer_session = GNUNET_malloc (sizeof (struct PeerSession) + sizeof (struct sockaddr_in)); 482 v4 = (struct sockaddr_in *) &peer_session[1];
489 v4 = (struct sockaddr_in*) &peer_session[1]; 483 v4->sin_family = AF_INET;
490 v4->sin_family = AF_INET;
491#if HAVE_SOCKADDR_IN_SIN_LEN 484#if HAVE_SOCKADDR_IN_SIN_LEN
492 v4->sin_len = sizeof (struct sockaddr_in); 485 v4->sin_len = sizeof (struct sockaddr_in);
493#endif 486#endif
494 v4->sin_port = t4->u4_port; 487 v4->sin_port = t4->u4_port;
495 v4->sin_addr.s_addr = t4->ipv4_addr; 488 v4->sin_addr.s_addr = t4->ipv4_addr;
496 break; 489 break;
497 case sizeof(struct IPv6UdpAddress): 490 case sizeof (struct IPv6UdpAddress):
498 if (NULL == plugin->sockv6) 491 if (NULL == plugin->sockv6)
499 { 492 {
500 cont (cont_cls, target, GNUNET_SYSERR); 493 cont (cont_cls, target, GNUNET_SYSERR);
501 return 0; 494 return 0;
502 } 495 }
503 t6 = addr; 496 t6 = addr;
504 peer_session = GNUNET_malloc (sizeof (struct PeerSession) + sizeof (struct sockaddr_in6)); 497 peer_session =
505 v6 = (struct sockaddr_in6*) &peer_session[1]; 498 GNUNET_malloc (sizeof (struct PeerSession) +
506 v6->sin6_family = AF_INET6; 499 sizeof (struct sockaddr_in6));
500 v6 = (struct sockaddr_in6 *) &peer_session[1];
501 v6->sin6_family = AF_INET6;
507#if HAVE_SOCKADDR_IN_SIN_LEN 502#if HAVE_SOCKADDR_IN_SIN_LEN
508 v6->sin6_len = sizeof (struct sockaddr_in6); 503 v6->sin6_len = sizeof (struct sockaddr_in6);
509#endif 504#endif
510 v6->sin6_port = t6->u6_port; 505 v6->sin6_port = t6->u6_port;
511 v6->sin6_addr = t6->ipv6_addr; 506 v6->sin6_addr = t6->ipv6_addr;
512 break; 507 break;
513 default: 508 default:
514 /* Must have a valid address to send to */ 509 /* Must have a valid address to send to */
515 GNUNET_break_op(0); 510 GNUNET_break_op (0);
516 return GNUNET_SYSERR; 511 return GNUNET_SYSERR;
517 } 512 }
518 udp = (struct UDPMessage*) mbuf; 513 udp = (struct UDPMessage *) mbuf;
519 udp->header.size = htons (mlen); 514 udp->header.size = htons (mlen);
520 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE); 515 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE);
521 udp->reserved = htonl (0); 516 udp->reserved = htonl (0);
@@ -523,32 +518,30 @@ udp_plugin_send (void *cls,
523 memcpy (&udp[1], msgbuf, msgbuf_size); 518 memcpy (&udp[1], msgbuf, msgbuf_size);
524 peer_session->target = *target; 519 peer_session->target = *target;
525 peer_session->plugin = plugin; 520 peer_session->plugin = plugin;
526 peer_session->sock_addr = (const struct sockaddr*) &peer_session[1]; 521 peer_session->sock_addr = (const struct sockaddr *) &peer_session[1];
527 peer_session->cont = cont; 522 peer_session->cont = cont;
528 peer_session->cont_cls = cont_cls; 523 peer_session->cont_cls = cont_cls;
529 if (mlen <= UDP_MTU) 524 if (mlen <= UDP_MTU)
530 { 525 {
531 mlen = udp_send (plugin, 526 mlen = udp_send (plugin, peer_session->sock_addr, &udp->header);
532 peer_session->sock_addr, 527 cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR);
533 &udp->header); 528 GNUNET_free (peer_session);
534 cont (cont_cls, target, (mlen > 0) ? GNUNET_OK : GNUNET_SYSERR); 529 }
535 GNUNET_free (peer_session);
536 }
537 else 530 else
538 { 531 {
539 GNUNET_assert (GNUNET_OK == 532 GNUNET_assert (GNUNET_OK ==
540 GNUNET_CONTAINER_multihashmap_put (plugin->sessions, 533 GNUNET_CONTAINER_multihashmap_put (plugin->sessions,
541 &target->hashPubKey, 534 &target->hashPubKey,
542 peer_session, 535 peer_session,
543 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 536 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
544 peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats, 537 peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
545 UDP_MTU, 538 UDP_MTU,
546 &plugin->tracker, 539 &plugin->tracker,
547 plugin->last_expected_delay, 540 plugin->last_expected_delay,
548 &udp->header, 541 &udp->header,
549 &send_fragment, 542 &send_fragment,
550 peer_session); 543 peer_session);
551 } 544 }
552 return mlen; 545 return mlen;
553} 546}
554 547
@@ -562,7 +555,7 @@ struct SourceInformation
562 * Sender identity. 555 * Sender identity.
563 */ 556 */
564 struct GNUNET_PeerIdentity sender; 557 struct GNUNET_PeerIdentity sender;
565 558
566 /** 559 /**
567 * Source address. 560 * Source address.
568 */ 561 */
@@ -585,11 +578,11 @@ struct SourceInformation
585 */ 578 */
586static void 579static void
587process_inbound_tokenized_messages (void *cls, 580process_inbound_tokenized_messages (void *cls,
588 void *client, 581 void *client,
589 const struct GNUNET_MessageHeader *hdr) 582 const struct GNUNET_MessageHeader *hdr)
590{ 583{
591 struct Plugin *plugin = cls; 584 struct Plugin *plugin = cls;
592 struct SourceInformation* si = client; 585 struct SourceInformation *si = client;
593 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 586 struct GNUNET_TRANSPORT_ATS_Information distance[2];
594 587
595 /* setup ATS */ 588 /* setup ATS */
@@ -598,12 +591,8 @@ process_inbound_tokenized_messages (void *cls,
598 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 591 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
599 distance[1].value = htonl (0); 592 distance[1].value = htonl (0);
600 593
601 plugin->env->receive (plugin->env->cls, 594 plugin->env->receive (plugin->env->cls,
602 &si->sender, 595 &si->sender, hdr, distance, 2, NULL, si->arg, si->args);
603 hdr,
604 distance, 2,
605 NULL,
606 si->arg, si->args);
607} 596}
608 597
609 598
@@ -617,55 +606,56 @@ process_inbound_tokenized_messages (void *cls,
617 */ 606 */
618static void 607static void
619process_udp_message (struct Plugin *plugin, 608process_udp_message (struct Plugin *plugin,
620 const struct UDPMessage *msg, 609 const struct UDPMessage *msg,
621 const struct sockaddr *sender_addr, 610 const struct sockaddr *sender_addr,
622 socklen_t sender_addr_len) 611 socklen_t sender_addr_len)
623{ 612{
624 struct SourceInformation si; 613 struct SourceInformation si;
625 struct IPv4UdpAddress u4; 614 struct IPv4UdpAddress u4;
626 struct IPv6UdpAddress u6; 615 struct IPv6UdpAddress u6;
627 const void *arg; 616 const void *arg;
628 size_t args; 617 size_t args;
629 618
630 if (0 != ntohl (msg->reserved)) 619 if (0 != ntohl (msg->reserved))
631 { 620 {
632 GNUNET_break_op (0); 621 GNUNET_break_op (0);
633 return; 622 return;
634 } 623 }
635 if (ntohs (msg->header.size) < sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage)) 624 if (ntohs (msg->header.size) <
636 { 625 sizeof (struct GNUNET_MessageHeader) + sizeof (struct UDPMessage))
637 GNUNET_break_op (0); 626 {
638 return; 627 GNUNET_break_op (0);
639 } 628 return;
629 }
640 630
641 /* convert address */ 631 /* convert address */
642 switch (sender_addr->sa_family) 632 switch (sender_addr->sa_family)
643 { 633 {
644 case AF_INET: 634 case AF_INET:
645 GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in)); 635 GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in));
646 u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr; 636 u4.ipv4_addr = ((struct sockaddr_in *) sender_addr)->sin_addr.s_addr;
647 u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port; 637 u4.u4_port = ((struct sockaddr_in *) sender_addr)->sin_port;
648 arg = &u4; 638 arg = &u4;
649 args = sizeof (u4); 639 args = sizeof (u4);
650 break; 640 break;
651 case AF_INET6: 641 case AF_INET6:
652 GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6)); 642 GNUNET_assert (sender_addr_len == sizeof (struct sockaddr_in6));
653 u6.ipv6_addr = ((struct sockaddr_in6*) sender_addr)->sin6_addr; 643 u6.ipv6_addr = ((struct sockaddr_in6 *) sender_addr)->sin6_addr;
654 u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port; 644 u6.u6_port = ((struct sockaddr_in6 *) sender_addr)->sin6_port;
655 arg = &u6; 645 arg = &u6;
656 args = sizeof (u6); 646 args = sizeof (u6);
657 break; 647 break;
658 default: 648 default:
659 GNUNET_break (0); 649 GNUNET_break (0);
660 return; 650 return;
661 } 651 }
662#if DEBUG_UDP 652#if DEBUG_UDP
663 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 653 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
664 "udp", 654 "udp",
665 "Received message with %u bytes from peer `%s' at `%s'\n", 655 "Received message with %u bytes from peer `%s' at `%s'\n",
666 (unsigned int) ntohs (msg->header.size), 656 (unsigned int) ntohs (msg->header.size),
667 GNUNET_i2s (&msg->sender), 657 GNUNET_i2s (&msg->sender),
668 GNUNET_a2s (sender_addr, sender_addr_len)); 658 GNUNET_a2s (sender_addr, sender_addr_len));
669#endif 659#endif
670 660
671 /* iterate over all embedded messages */ 661 /* iterate over all embedded messages */
@@ -673,11 +663,10 @@ process_udp_message (struct Plugin *plugin,
673 si.arg = arg; 663 si.arg = arg;
674 si.args = args; 664 si.args = args;
675 GNUNET_SERVER_mst_receive (plugin->mst, 665 GNUNET_SERVER_mst_receive (plugin->mst,
676 &si, 666 &si,
677 (const char*) &msg[1], 667 (const char *) &msg[1],
678 ntohs (msg->header.size) - sizeof (struct UDPMessage), 668 ntohs (msg->header.size) -
679 GNUNET_YES, 669 sizeof (struct UDPMessage), GNUNET_YES, GNUNET_NO);
680 GNUNET_NO);
681} 670}
682 671
683 672
@@ -688,26 +677,24 @@ process_udp_message (struct Plugin *plugin,
688 * @param msg the message 677 * @param msg the message
689 */ 678 */
690static void 679static void
691fragment_msg_proc (void *cls, 680fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
692 const struct GNUNET_MessageHeader *msg)
693{ 681{
694 struct ReceiveContext *rc = cls; 682 struct ReceiveContext *rc = cls;
695 683
696 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE) 684 if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
697 { 685 {
698 GNUNET_break (0); 686 GNUNET_break (0);
699 return; 687 return;
700 } 688 }
701 if (ntohs (msg->size) < sizeof(struct UDPMessage)) 689 if (ntohs (msg->size) < sizeof (struct UDPMessage))
702 { 690 {
703 GNUNET_break (0); 691 GNUNET_break (0);
704 return; 692 return;
705 } 693 }
706 process_udp_message (rc->plugin, 694 process_udp_message (rc->plugin,
707 (const struct UDPMessage*) msg, 695 (const struct UDPMessage *) msg,
708 rc->src_addr, 696 rc->src_addr, rc->addr_len);
709 rc->addr_len); 697}
710}
711 698
712 699
713/** 700/**
@@ -718,9 +705,7 @@ fragment_msg_proc (void *cls,
718 * @param msg ack to transmit 705 * @param msg ack to transmit
719 */ 706 */
720static void 707static void
721ack_proc (void *cls, 708ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
722 uint32_t id,
723 const struct GNUNET_MessageHeader *msg)
724{ 709{
725 struct ReceiveContext *rc = cls; 710 struct ReceiveContext *rc = cls;
726 size_t msize = sizeof (struct UDPMessage) + ntohs (msg->size); 711 size_t msize = sizeof (struct UDPMessage) + ntohs (msg->size);
@@ -729,22 +714,20 @@ ack_proc (void *cls,
729 714
730#if DEBUG_UDP 715#if DEBUG_UDP
731 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 716 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
732 "udp", 717 "udp",
733 "Sending ACK to `%s'\n", 718 "Sending ACK to `%s'\n",
734 GNUNET_a2s (rc->src_addr, 719 GNUNET_a2s (rc->src_addr,
735 (rc->src_addr->sa_family == AF_INET) 720 (rc->src_addr->sa_family == AF_INET)
736 ? sizeof (struct sockaddr_in) 721 ? sizeof (struct sockaddr_in)
737 : sizeof (struct sockaddr_in6))); 722 : sizeof (struct sockaddr_in6)));
738#endif 723#endif
739 udp = (struct UDPMessage*) buf; 724 udp = (struct UDPMessage *) buf;
740 udp->header.size = htons ((uint16_t) msize); 725 udp->header.size = htons ((uint16_t) msize);
741 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK); 726 udp->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK);
742 udp->reserved = htonl (0); 727 udp->reserved = htonl (0);
743 udp->sender = *rc->plugin->env->my_identity; 728 udp->sender = *rc->plugin->env->my_identity;
744 memcpy (&udp[1], msg, ntohs (msg->size)); 729 memcpy (&udp[1], msg, ntohs (msg->size));
745 (void) udp_send (rc->plugin, 730 (void) udp_send (rc->plugin, rc->src_addr, &udp->header);
746 rc->src_addr,
747 &udp->header);
748} 731}
749 732
750 733
@@ -782,21 +765,18 @@ struct FindReceiveContext
782 */ 765 */
783static int 766static int
784find_receive_context (void *cls, 767find_receive_context (void *cls,
785 struct GNUNET_CONTAINER_HeapNode *node, 768 struct GNUNET_CONTAINER_HeapNode *node,
786 void *element, 769 void *element, GNUNET_CONTAINER_HeapCostType cost)
787 GNUNET_CONTAINER_HeapCostType cost)
788{ 770{
789 struct FindReceiveContext *frc = cls; 771 struct FindReceiveContext *frc = cls;
790 struct ReceiveContext *e = element; 772 struct ReceiveContext *e = element;
791 773
792 if ( (frc->addr_len == e->addr_len) && 774 if ((frc->addr_len == e->addr_len) &&
793 (0 == memcmp (frc->addr, 775 (0 == memcmp (frc->addr, e->src_addr, frc->addr_len)))
794 e->src_addr, 776 {
795 frc->addr_len) ) ) 777 frc->rc = e;
796 { 778 return GNUNET_NO;
797 frc->rc = e; 779 }
798 return GNUNET_NO;
799 }
800 return GNUNET_YES; 780 return GNUNET_YES;
801} 781}
802 782
@@ -808,8 +788,7 @@ find_receive_context (void *cls,
808 * @param rsock socket to read from 788 * @param rsock socket to read from
809 */ 789 */
810static void 790static void
811udp_read (struct Plugin *plugin, 791udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
812 struct GNUNET_NETWORK_Handle *rsock)
813{ 792{
814 socklen_t fromlen; 793 socklen_t fromlen;
815 char addr[32]; 794 char addr[32];
@@ -824,144 +803,142 @@ udp_read (struct Plugin *plugin,
824 struct FindReceiveContext frc; 803 struct FindReceiveContext frc;
825 804
826 fromlen = sizeof (addr); 805 fromlen = sizeof (addr);
827 memset (&addr, 0, sizeof(addr)); 806 memset (&addr, 0, sizeof (addr));
828 ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), 807 ret = GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf),
829 (struct sockaddr *)&addr, &fromlen); 808 (struct sockaddr *) &addr, &fromlen);
830 if (ret < sizeof (struct GNUNET_MessageHeader)) 809 if (ret < sizeof (struct GNUNET_MessageHeader))
831 { 810 {
832 GNUNET_break_op (0); 811 GNUNET_break_op (0);
833 return; 812 return;
834 } 813 }
835#if DEBUG_UDP 814#if DEBUG_UDP
836 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
837 "UDP received %u-byte message from `%s'\n", 816 "UDP received %u-byte message from `%s'\n",
838 (unsigned int) ret, 817 (unsigned int) ret,
839 GNUNET_a2s ((const struct sockaddr*) addr, fromlen)); 818 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
840#endif 819#endif
841 msg = (const struct GNUNET_MessageHeader *) buf; 820 msg = (const struct GNUNET_MessageHeader *) buf;
842 if (ret != ntohs (msg->size)) 821 if (ret != ntohs (msg->size))
822 {
823 GNUNET_break_op (0);
824 return;
825 }
826 switch (ntohs (msg->type))
827 {
828 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE:
829 if (ntohs (msg->size) < sizeof (struct UDPMessage))
843 { 830 {
844 GNUNET_break_op (0); 831 GNUNET_break_op (0);
845 return; 832 return;
846 } 833 }
847 switch (ntohs (msg->type)) 834 process_udp_message (plugin,
835 (const struct UDPMessage *) msg,
836 (const struct sockaddr *) addr, fromlen);
837 return;
838 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK:
839 if (ntohs (msg->size) <
840 sizeof (struct UDPMessage) + sizeof (struct GNUNET_MessageHeader))
848 { 841 {
849 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: 842 GNUNET_break_op (0);
850 if (ntohs (msg->size) < sizeof (struct UDPMessage))
851 {
852 GNUNET_break_op (0);
853 return;
854 }
855 process_udp_message (plugin,
856 (const struct UDPMessage *) msg,
857 (const struct sockaddr*) addr,
858 fromlen);
859 return; 843 return;
860 case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK: 844 }
861 if (ntohs (msg->size) < sizeof (struct UDPMessage) + sizeof (struct GNUNET_MessageHeader)) 845 udp = (const struct UDPMessage *) msg;
862 { 846 if (ntohl (udp->reserved) != 0)
863 GNUNET_break_op (0); 847 {
864 return; 848 GNUNET_break_op (0);
865 } 849 return;
866 udp = (const struct UDPMessage *) msg; 850 }
867 if (ntohl (udp->reserved) != 0) 851 ack = (const struct GNUNET_MessageHeader *) &udp[1];
868 { 852 if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDPMessage))
869 GNUNET_break_op (0); 853 {
870 return; 854 GNUNET_break_op (0);
871 } 855 return;
872 ack = (const struct GNUNET_MessageHeader*) &udp[1]; 856 }
873 if (ntohs (ack->size) != ntohs (msg->size) - sizeof (struct UDPMessage))
874 {
875 GNUNET_break_op (0);
876 return;
877 }
878#if DEBUG_UDP 857#if DEBUG_UDP
879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
880 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n", 859 "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
881 (unsigned int) ntohs (msg->size), 860 (unsigned int) ntohs (msg->size),
882 GNUNET_i2s (&udp->sender), 861 GNUNET_i2s (&udp->sender),
883 GNUNET_a2s ((const struct sockaddr*) addr, fromlen)); 862 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
884#endif 863#endif
885 864
886 peer_session = find_session (plugin, &udp->sender); 865 peer_session = find_session (plugin, &udp->sender);
887 if (NULL == peer_session) 866 if (NULL == peer_session)
888 { 867 {
889#if DEBUG_UDP 868#if DEBUG_UDP
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 "Session for ACK not found, dropping ACK!\n"); 870 "Session for ACK not found, dropping ACK!\n");
892#endif 871#endif
893 return;
894 }
895 if (GNUNET_OK !=
896 GNUNET_FRAGMENT_process_ack (peer_session->frag,
897 ack))
898 return;
899 GNUNET_assert (GNUNET_OK ==
900 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
901 &udp->sender.hashPubKey,
902 peer_session));
903 plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (peer_session->frag);
904 peer_session->cont (peer_session->cont_cls,
905 &udp->sender,
906 GNUNET_OK);
907 GNUNET_free (peer_session);
908 return; 872 return;
909 case GNUNET_MESSAGE_TYPE_FRAGMENT: 873 }
910 frc.rc = NULL; 874 if (GNUNET_OK != GNUNET_FRAGMENT_process_ack (peer_session->frag, ack))
911 frc.addr = (const struct sockaddr*) addr; 875 return;
912 frc.addr_len = fromlen; 876 GNUNET_assert (GNUNET_OK ==
913 GNUNET_CONTAINER_heap_iterate (plugin->defrags, 877 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
914 &find_receive_context, 878 &udp->
915 &frc); 879 sender.hashPubKey,
916 now = GNUNET_TIME_absolute_get (); 880 peer_session));
917 rc = frc.rc; 881 plugin->last_expected_delay =
918 if (rc == NULL) 882 GNUNET_FRAGMENT_context_destroy (peer_session->frag);
919 { 883 peer_session->cont (peer_session->cont_cls, &udp->sender, GNUNET_OK);
920 /* need to create a new RC */ 884 GNUNET_free (peer_session);
921 rc = GNUNET_malloc (sizeof (struct ReceiveContext) + fromlen); 885 return;
922 memcpy (&rc[1], addr, fromlen); 886 case GNUNET_MESSAGE_TYPE_FRAGMENT:
923 rc->src_addr = (const struct sockaddr*) &rc[1]; 887 frc.rc = NULL;
924 rc->addr_len = fromlen; 888 frc.addr = (const struct sockaddr *) addr;
925 rc->plugin = plugin; 889 frc.addr_len = fromlen;
926 rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats, 890 GNUNET_CONTAINER_heap_iterate (plugin->defrags,
927 UDP_MTU, 891 &find_receive_context, &frc);
928 UDP_MAX_MESSAGES_IN_DEFRAG, 892 now = GNUNET_TIME_absolute_get ();
929 rc, 893 rc = frc.rc;
930 &fragment_msg_proc, 894 if (rc == NULL)
931 &ack_proc); 895 {
932 rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags, 896 /* need to create a new RC */
933 rc, 897 rc = GNUNET_malloc (sizeof (struct ReceiveContext) + fromlen);
934 (GNUNET_CONTAINER_HeapCostType) now.abs_value); 898 memcpy (&rc[1], addr, fromlen);
935 } 899 rc->src_addr = (const struct sockaddr *) &rc[1];
900 rc->addr_len = fromlen;
901 rc->plugin = plugin;
902 rc->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
903 UDP_MTU,
904 UDP_MAX_MESSAGES_IN_DEFRAG,
905 rc,
906 &fragment_msg_proc,
907 &ack_proc);
908 rc->hnode = GNUNET_CONTAINER_heap_insert (plugin->defrags,
909 rc,
910 (GNUNET_CONTAINER_HeapCostType)
911 now.abs_value);
912 }
936#if DEBUG_UDP 913#if DEBUG_UDP
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 "UDP processes %u-byte fragment from `%s'\n", 915 "UDP processes %u-byte fragment from `%s'\n",
939 (unsigned int) ntohs (msg->size), 916 (unsigned int) ntohs (msg->size),
940 GNUNET_a2s ((const struct sockaddr*) addr, fromlen)); 917 GNUNET_a2s ((const struct sockaddr *) addr, fromlen));
941#endif 918#endif
942 919
943 if (GNUNET_OK == 920 if (GNUNET_OK == GNUNET_DEFRAGMENT_process_fragment (rc->defrag, msg))
944 GNUNET_DEFRAGMENT_process_fragment (rc->defrag, 921 {
945 msg)) 922 /* keep this 'rc' from expiring */
946 { 923 GNUNET_CONTAINER_heap_update_cost (plugin->defrags,
947 /* keep this 'rc' from expiring */ 924 rc->hnode,
948 GNUNET_CONTAINER_heap_update_cost (plugin->defrags, 925 (GNUNET_CONTAINER_HeapCostType)
949 rc->hnode, 926 now.abs_value);
950 (GNUNET_CONTAINER_HeapCostType) now.abs_value);
951 }
952 if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) > UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
953 {
954 /* remove 'rc' that was inactive the longest */
955 rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags);
956 GNUNET_assert (NULL != rc);
957 GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
958 GNUNET_free (rc);
959 }
960 return;
961 default:
962 GNUNET_break_op (0);
963 return;
964 } 927 }
928 if (GNUNET_CONTAINER_heap_get_size (plugin->defrags) >
929 UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG)
930 {
931 /* remove 'rc' that was inactive the longest */
932 rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags);
933 GNUNET_assert (NULL != rc);
934 GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
935 GNUNET_free (rc);
936 }
937 return;
938 default:
939 GNUNET_break_op (0);
940 return;
941 }
965} 942}
966 943
967 944
@@ -974,28 +951,25 @@ udp_read (struct Plugin *plugin,
974 * @param tc the scheduling context (for rescheduling this function again) 951 * @param tc the scheduling context (for rescheduling this function again)
975 */ 952 */
976static void 953static void
977udp_plugin_select (void *cls, 954udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
978 const struct GNUNET_SCHEDULER_TaskContext *tc)
979{ 955{
980 struct Plugin *plugin = cls; 956 struct Plugin *plugin = cls;
981 957
982 plugin->select_task = GNUNET_SCHEDULER_NO_TASK; 958 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
983 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 959 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
984 return; 960 return;
985 if ( (NULL != plugin->sockv4) && 961 if ((NULL != plugin->sockv4) &&
986 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 962 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
987 plugin->sockv4)) )
988 udp_read (plugin, plugin->sockv4); 963 udp_read (plugin, plugin->sockv4);
989 if ( (NULL != plugin->sockv6) && 964 if ((NULL != plugin->sockv6) &&
990 (GNUNET_NETWORK_fdset_isset (tc->read_ready, 965 (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
991 plugin->sockv6)) )
992 udp_read (plugin, plugin->sockv6); 966 udp_read (plugin, plugin->sockv6);
993 plugin->select_task = 967 plugin->select_task =
994 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 968 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
995 GNUNET_SCHEDULER_NO_TASK, 969 GNUNET_SCHEDULER_NO_TASK,
996 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, 970 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
997 NULL, &udp_plugin_select, plugin); 971 NULL, &udp_plugin_select, plugin);
998 972
999} 973}
1000 974
1001 975
@@ -1011,8 +985,7 @@ udp_plugin_select (void *cls,
1011static int 985static int
1012check_port (struct Plugin *plugin, uint16_t in_port) 986check_port (struct Plugin *plugin, uint16_t in_port)
1013{ 987{
1014 if ( (in_port == plugin->port) || 988 if ((in_port == plugin->port) || (in_port == plugin->aport))
1015 (in_port == plugin->aport) )
1016 return GNUNET_OK; 989 return GNUNET_OK;
1017 return GNUNET_SYSERR; 990 return GNUNET_SYSERR;
1018} 991}
@@ -1035,9 +1008,7 @@ check_port (struct Plugin *plugin, uint16_t in_port)
1035 * 1008 *
1036 */ 1009 */
1037static int 1010static int
1038udp_plugin_check_address (void *cls, 1011udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
1039 const void *addr,
1040 size_t addrlen)
1041{ 1012{
1042 struct Plugin *plugin = cls; 1013 struct Plugin *plugin = cls;
1043 struct IPv4UdpAddress *v4; 1014 struct IPv4UdpAddress *v4;
@@ -1045,37 +1016,35 @@ udp_plugin_check_address (void *cls,
1045 1016
1046 if ((addrlen != sizeof (struct IPv4UdpAddress)) && 1017 if ((addrlen != sizeof (struct IPv4UdpAddress)) &&
1047 (addrlen != sizeof (struct IPv6UdpAddress))) 1018 (addrlen != sizeof (struct IPv6UdpAddress)))
1048 { 1019 {
1049 GNUNET_break_op (0); 1020 GNUNET_break_op (0);
1050 return GNUNET_SYSERR; 1021 return GNUNET_SYSERR;
1051 } 1022 }
1052 if (addrlen == sizeof (struct IPv4UdpAddress)) 1023 if (addrlen == sizeof (struct IPv4UdpAddress))
1053 { 1024 {
1054 v4 = (struct IPv4UdpAddress *) addr; 1025 v4 = (struct IPv4UdpAddress *) addr;
1055 if (GNUNET_OK != 1026 if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
1056 check_port (plugin, ntohs (v4->u4_port))) 1027 return GNUNET_SYSERR;
1057 return GNUNET_SYSERR; 1028 if (GNUNET_OK !=
1058 if (GNUNET_OK != 1029 GNUNET_NAT_test_address (plugin->nat,
1059 GNUNET_NAT_test_address (plugin->nat, 1030 &v4->ipv4_addr, sizeof (struct in_addr)))
1060 &v4->ipv4_addr, sizeof (struct in_addr))) 1031 return GNUNET_SYSERR;
1061 return GNUNET_SYSERR; 1032 }
1062 }
1063 else 1033 else
1034 {
1035 v6 = (struct IPv6UdpAddress *) addr;
1036 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1064 { 1037 {
1065 v6 = (struct IPv6UdpAddress *) addr; 1038 GNUNET_break_op (0);
1066 if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) 1039 return GNUNET_SYSERR;
1067 {
1068 GNUNET_break_op (0);
1069 return GNUNET_SYSERR;
1070 }
1071 if (GNUNET_OK !=
1072 check_port (plugin, ntohs (v6->u6_port)))
1073 return GNUNET_SYSERR;
1074 if (GNUNET_OK !=
1075 GNUNET_NAT_test_address (plugin->nat,
1076 &v6->ipv6_addr, sizeof (struct in6_addr)))
1077 return GNUNET_SYSERR;
1078 } 1040 }
1041 if (GNUNET_OK != check_port (plugin, ntohs (v6->u6_port)))
1042 return GNUNET_SYSERR;
1043 if (GNUNET_OK !=
1044 GNUNET_NAT_test_address (plugin->nat,
1045 &v6->ipv6_addr, sizeof (struct in6_addr)))
1046 return GNUNET_SYSERR;
1047 }
1079 return GNUNET_OK; 1048 return GNUNET_OK;
1080} 1049}
1081 1050
@@ -1091,10 +1060,8 @@ udp_plugin_check_address (void *cls,
1091 * @param addrlen length of the address 1060 * @param addrlen length of the address
1092 * @return string representing the same address 1061 * @return string representing the same address
1093 */ 1062 */
1094static const char* 1063static const char *
1095udp_address_to_string (void *cls, 1064udp_address_to_string (void *cls, const void *addr, size_t addrlen)
1096 const void *addr,
1097 size_t addrlen)
1098{ 1065{
1099 static char rbuf[INET6_ADDRSTRLEN + 10]; 1066 static char rbuf[INET6_ADDRSTRLEN + 10];
1100 char buf[INET6_ADDRSTRLEN]; 1067 char buf[INET6_ADDRSTRLEN];
@@ -1107,32 +1074,28 @@ udp_address_to_string (void *cls,
1107 uint16_t port; 1074 uint16_t port;
1108 1075
1109 if (addrlen == sizeof (struct IPv6UdpAddress)) 1076 if (addrlen == sizeof (struct IPv6UdpAddress))
1110 { 1077 {
1111 t6 = addr; 1078 t6 = addr;
1112 af = AF_INET6; 1079 af = AF_INET6;
1113 port = ntohs (t6->u6_port); 1080 port = ntohs (t6->u6_port);
1114 memcpy (&a6, &t6->ipv6_addr, sizeof (a6)); 1081 memcpy (&a6, &t6->ipv6_addr, sizeof (a6));
1115 sb = &a6; 1082 sb = &a6;
1116 } 1083 }
1117 else if (addrlen == sizeof (struct IPv4UdpAddress)) 1084 else if (addrlen == sizeof (struct IPv4UdpAddress))
1118 { 1085 {
1119 t4 = addr; 1086 t4 = addr;
1120 af = AF_INET; 1087 af = AF_INET;
1121 port = ntohs (t4->u4_port); 1088 port = ntohs (t4->u4_port);
1122 memcpy (&a4, &t4->ipv4_addr, sizeof (a4)); 1089 memcpy (&a4, &t4->ipv4_addr, sizeof (a4));
1123 sb = &a4; 1090 sb = &a4;
1124 } 1091 }
1125 else 1092 else
1126 { 1093 {
1127 GNUNET_break_op (0); 1094 GNUNET_break_op (0);
1128 return NULL; 1095 return NULL;
1129 } 1096 }
1130 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN); 1097 inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
1131 GNUNET_snprintf (rbuf, 1098 GNUNET_snprintf (rbuf, sizeof (rbuf), "%s:%u", buf, port);
1132 sizeof (rbuf),
1133 "%s:%u",
1134 buf,
1135 port);
1136 return rbuf; 1099 return rbuf;
1137} 1100}
1138 1101
@@ -1172,15 +1135,12 @@ append_port (void *cls, const char *hostname)
1172 char *ret; 1135 char *ret;
1173 1136
1174 if (hostname == NULL) 1137 if (hostname == NULL)
1175 { 1138 {
1176 ppc->asc (ppc->asc_cls, NULL); 1139 ppc->asc (ppc->asc_cls, NULL);
1177 GNUNET_free (ppc); 1140 GNUNET_free (ppc);
1178 return; 1141 return;
1179 } 1142 }
1180 GNUNET_asprintf (&ret, 1143 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
1181 "%s:%d",
1182 hostname,
1183 ppc->port);
1184 ppc->asc (ppc->asc_cls, ret); 1144 ppc->asc (ppc->asc_cls, ret);
1185 GNUNET_free (ret); 1145 GNUNET_free (ret);
1186} 1146}
@@ -1220,50 +1180,45 @@ udp_plugin_address_pretty_printer (void *cls,
1220 uint16_t port; 1180 uint16_t port;
1221 1181
1222 if (addrlen == sizeof (struct IPv6UdpAddress)) 1182 if (addrlen == sizeof (struct IPv6UdpAddress))
1223 { 1183 {
1224 u6 = addr; 1184 u6 = addr;
1225 memset (&a6, 0, sizeof (a6)); 1185 memset (&a6, 0, sizeof (a6));
1226 a6.sin6_family = AF_INET6; 1186 a6.sin6_family = AF_INET6;
1227#if HAVE_SOCKADDR_IN_SIN_LEN 1187#if HAVE_SOCKADDR_IN_SIN_LEN
1228 a6.sin6_len = sizeof (a6); 1188 a6.sin6_len = sizeof (a6);
1229#endif 1189#endif
1230 a6.sin6_port = u6->u6_port; 1190 a6.sin6_port = u6->u6_port;
1231 memcpy (&a6.sin6_addr, 1191 memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
1232 &u6->ipv6_addr, 1192 port = ntohs (u6->u6_port);
1233 sizeof (struct in6_addr)); 1193 sb = &a6;
1234 port = ntohs (u6->u6_port); 1194 sbs = sizeof (a6);
1235 sb = &a6; 1195 }
1236 sbs = sizeof (a6);
1237 }
1238 else if (addrlen == sizeof (struct IPv4UdpAddress)) 1196 else if (addrlen == sizeof (struct IPv4UdpAddress))
1239 { 1197 {
1240 u4 = addr; 1198 u4 = addr;
1241 memset (&a4, 0, sizeof (a4)); 1199 memset (&a4, 0, sizeof (a4));
1242 a4.sin_family = AF_INET; 1200 a4.sin_family = AF_INET;
1243#if HAVE_SOCKADDR_IN_SIN_LEN 1201#if HAVE_SOCKADDR_IN_SIN_LEN
1244 a4.sin_len = sizeof (a4); 1202 a4.sin_len = sizeof (a4);
1245#endif 1203#endif
1246 a4.sin_port = u4->u4_port; 1204 a4.sin_port = u4->u4_port;
1247 a4.sin_addr.s_addr = u4->ipv4_addr; 1205 a4.sin_addr.s_addr = u4->ipv4_addr;
1248 port = ntohs (u4->u4_port); 1206 port = ntohs (u4->u4_port);
1249 sb = &a4; 1207 sb = &a4;
1250 sbs = sizeof (a4); 1208 sbs = sizeof (a4);
1251 } 1209 }
1252 else 1210 else
1253 { 1211 {
1254 /* invalid address */ 1212 /* invalid address */
1255 GNUNET_break_op (0); 1213 GNUNET_break_op (0);
1256 asc (asc_cls, NULL); 1214 asc (asc_cls, NULL);
1257 return; 1215 return;
1258 } 1216 }
1259 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 1217 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
1260 ppc->asc = asc; 1218 ppc->asc = asc;
1261 ppc->asc_cls = asc_cls; 1219 ppc->asc_cls = asc_cls;
1262 ppc->port = port; 1220 ppc->port = port;
1263 GNUNET_RESOLVER_hostname_get (sb, 1221 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
1264 sbs,
1265 !numeric, timeout,
1266 &append_port, ppc);
1267} 1222}
1268 1223
1269 1224
@@ -1278,9 +1233,8 @@ udp_plugin_address_pretty_printer (void *cls,
1278 */ 1233 */
1279static void 1234static void
1280udp_nat_port_map_callback (void *cls, 1235udp_nat_port_map_callback (void *cls,
1281 int add_remove, 1236 int add_remove,
1282 const struct sockaddr *addr, 1237 const struct sockaddr *addr, socklen_t addrlen)
1283 socklen_t addrlen)
1284{ 1238{
1285 struct Plugin *plugin = cls; 1239 struct Plugin *plugin = cls;
1286 struct IPv4UdpAddress u4; 1240 struct IPv4UdpAddress u4;
@@ -1290,31 +1244,29 @@ udp_nat_port_map_callback (void *cls,
1290 1244
1291 /* convert 'addr' to our internal format */ 1245 /* convert 'addr' to our internal format */
1292 switch (addr->sa_family) 1246 switch (addr->sa_family)
1293 { 1247 {
1294 case AF_INET: 1248 case AF_INET:
1295 GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); 1249 GNUNET_assert (addrlen == sizeof (struct sockaddr_in));
1296 u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; 1250 u4.ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
1297 u4.u4_port = ((struct sockaddr_in *) addr)->sin_port; 1251 u4.u4_port = ((struct sockaddr_in *) addr)->sin_port;
1298 arg = &u4; 1252 arg = &u4;
1299 args = sizeof (u4); 1253 args = sizeof (u4);
1300 break; 1254 break;
1301 case AF_INET6: 1255 case AF_INET6:
1302 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6)); 1256 GNUNET_assert (addrlen == sizeof (struct sockaddr_in6));
1303 memcpy (&u6.ipv6_addr, 1257 memcpy (&u6.ipv6_addr,
1304 &((struct sockaddr_in6 *) addr)->sin6_addr, 1258 &((struct sockaddr_in6 *) addr)->sin6_addr,
1305 sizeof (struct in6_addr)); 1259 sizeof (struct in6_addr));
1306 u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port; 1260 u6.u6_port = ((struct sockaddr_in6 *) addr)->sin6_port;
1307 arg = &u6; 1261 arg = &u6;
1308 args = sizeof (u6); 1262 args = sizeof (u6);
1309 break; 1263 break;
1310 default: 1264 default:
1311 GNUNET_break (0); 1265 GNUNET_break (0);
1312 return; 1266 return;
1313 } 1267 }
1314 /* modify our published address list */ 1268 /* modify our published address list */
1315 plugin->env->notify_address (plugin->env->cls, 1269 plugin->env->notify_address (plugin->env->cls, add_remove, arg, args);
1316 add_remove,
1317 arg, args);
1318} 1270}
1319 1271
1320 1272
@@ -1345,38 +1297,32 @@ libgnunet_plugin_transport_udp_init (void *cls)
1345 1297
1346 if (GNUNET_OK != 1298 if (GNUNET_OK !=
1347 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1299 GNUNET_CONFIGURATION_get_value_number (env->cfg,
1348 "transport-udp", 1300 "transport-udp", "PORT", &port))
1349 "PORT",
1350 &port))
1351 port = 2086; 1301 port = 2086;
1352 if (GNUNET_OK != 1302 if (GNUNET_OK !=
1353 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1303 GNUNET_CONFIGURATION_get_value_number (env->cfg,
1354 "transport-udp", 1304 "transport-udp",
1355 "MAX_BPS", 1305 "MAX_BPS", &udp_max_bps))
1356 &udp_max_bps)) 1306 udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */
1357 udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */
1358 if (GNUNET_OK != 1307 if (GNUNET_OK !=
1359 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1308 GNUNET_CONFIGURATION_get_value_number (env->cfg,
1360 "transport-udp", 1309 "transport-udp",
1361 "ADVERTISED_PORT", 1310 "ADVERTISED_PORT", &aport))
1362 &aport))
1363 aport = port; 1311 aport = port;
1364 if (port > 65535) 1312 if (port > 65535)
1365 { 1313 {
1366 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1314 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1367 _("Given `%s' option is out of range: %llu > %u\n"), 1315 _("Given `%s' option is out of range: %llu > %u\n"),
1368 "PORT", 1316 "PORT", port, 65535);
1369 port, 1317 return NULL;
1370 65535); 1318 }
1371 return NULL;
1372 }
1373 memset (&serverAddrv6, 0, sizeof (serverAddrv6)); 1319 memset (&serverAddrv6, 0, sizeof (serverAddrv6));
1374 memset (&serverAddrv4, 0, sizeof (serverAddrv4)); 1320 memset (&serverAddrv4, 0, sizeof (serverAddrv4));
1375 1321
1376 plugin = GNUNET_malloc (sizeof (struct Plugin)); 1322 plugin = GNUNET_malloc (sizeof (struct Plugin));
1377 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker, 1323 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
1378 GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 1324 GNUNET_BANDWIDTH_value_init ((uint32_t)
1379 30); 1325 udp_max_bps), 30);
1380 plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS; 1326 plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS;
1381 plugin->port = port; 1327 plugin->port = port;
1382 plugin->aport = aport; 1328 plugin->aport = aport;
@@ -1390,178 +1336,167 @@ libgnunet_plugin_transport_udp_init (void *cls)
1390 api->address_to_string = &udp_address_to_string; 1336 api->address_to_string = &udp_address_to_string;
1391 api->check_address = &udp_plugin_check_address; 1337 api->check_address = &udp_plugin_check_address;
1392 1338
1393 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, 1339 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
1394 "transport-udp", 1340 "transport-udp",
1395 "BINDTO", 1341 "BINDTO",
1396 &plugin->bind4_address)) 1342 &plugin->bind4_address))
1343 {
1344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1345 "Binding udp plugin to specific address: `%s'\n",
1346 plugin->bind4_address);
1347 if (1 != inet_pton (AF_INET, plugin->bind4_address, &serverAddrv4.sin_addr))
1397 { 1348 {
1398 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1349 GNUNET_free (plugin->bind4_address);
1399 "Binding udp plugin to specific address: `%s'\n", 1350 GNUNET_free (plugin);
1400 plugin->bind4_address); 1351 GNUNET_free (api);
1401 if (1 != inet_pton(AF_INET, 1352 return NULL;
1402 plugin->bind4_address,
1403 &serverAddrv4.sin_addr))
1404 {
1405 GNUNET_free (plugin->bind4_address);
1406 GNUNET_free (plugin);
1407 GNUNET_free (api);
1408 return NULL;
1409 }
1410 } 1353 }
1411 1354 }
1412 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string(env->cfg, 1355
1413 "transport-udp", 1356 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (env->cfg,
1414 "BINDTO6", 1357 "transport-udp",
1415 &plugin->bind6_address)) 1358 "BINDTO6",
1359 &plugin->bind6_address))
1360 {
1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1362 "Binding udp plugin to specific address: `%s'\n",
1363 plugin->bind6_address);
1364 if (1 != inet_pton (AF_INET6,
1365 plugin->bind6_address, &serverAddrv6.sin6_addr))
1416 { 1366 {
1417 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 1367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1418 "Binding udp plugin to specific address: `%s'\n", 1368 _("Invalid IPv6 address: `%s'\n"), plugin->bind6_address);
1419 plugin->bind6_address); 1369 GNUNET_free_non_null (plugin->bind4_address);
1420 if (1 != inet_pton(AF_INET6, 1370 GNUNET_free (plugin->bind6_address);
1421 plugin->bind6_address, 1371 GNUNET_free (plugin);
1422 &serverAddrv6.sin6_addr)) 1372 GNUNET_free (api);
1423 { 1373 return NULL;
1424 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1425 _("Invalid IPv6 address: `%s'\n"),
1426 plugin->bind6_address);
1427 GNUNET_free_non_null (plugin->bind4_address);
1428 GNUNET_free (plugin->bind6_address);
1429 GNUNET_free (plugin);
1430 GNUNET_free (api);
1431 return NULL;
1432 }
1433 } 1374 }
1375 }
1434 1376
1435 plugin->defrags = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1377 plugin->defrags =
1436 plugin->sessions = GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG * 2); 1378 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1379 plugin->sessions =
1380 GNUNET_CONTAINER_multihashmap_create (UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG
1381 * 2);
1437 sockets_created = 0; 1382 sockets_created = 0;
1438 if ( (GNUNET_YES != 1383 if ((GNUNET_YES !=
1439 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, 1384 GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg,
1440 "nat", 1385 "nat", "DISABLEV6")))
1441 "DISABLEV6"))) 1386 {
1387 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
1388 if (NULL == plugin->sockv6)
1389 {
1390 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
1391 }
1392 else
1442 { 1393 {
1443 plugin->sockv6 = GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0);
1444 if (NULL == plugin->sockv6)
1445 {
1446 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
1447 }
1448 else
1449 {
1450#if HAVE_SOCKADDR_IN_SIN_LEN 1394#if HAVE_SOCKADDR_IN_SIN_LEN
1451 serverAddrv6.sin6_len = sizeof (serverAddrv6); 1395 serverAddrv6.sin6_len = sizeof (serverAddrv6);
1452#endif 1396#endif
1453 serverAddrv6.sin6_family = AF_INET6; 1397 serverAddrv6.sin6_family = AF_INET6;
1454 serverAddrv6.sin6_addr = in6addr_any; 1398 serverAddrv6.sin6_addr = in6addr_any;
1455 serverAddrv6.sin6_port = htons (plugin->port); 1399 serverAddrv6.sin6_port = htons (plugin->port);
1456 addrlen = sizeof (serverAddrv6); 1400 addrlen = sizeof (serverAddrv6);
1457 serverAddr = (struct sockaddr *) &serverAddrv6; 1401 serverAddr = (struct sockaddr *) &serverAddrv6;
1458#if DEBUG_UDP 1402#if DEBUG_UDP
1459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1403 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1460 "Binding to IPv6 port %d\n", 1404 "Binding to IPv6 port %d\n", ntohs (serverAddrv6.sin6_port));
1461 ntohs(serverAddrv6.sin6_port));
1462#endif 1405#endif
1463 tries = 0; 1406 tries = 0;
1464 while (GNUNET_NETWORK_socket_bind (plugin->sockv6, 1407 while (GNUNET_NETWORK_socket_bind (plugin->sockv6,
1465 serverAddr, addrlen) != 1408 serverAddr, addrlen) != GNUNET_OK)
1466 GNUNET_OK) 1409 {
1467 { 1410 serverAddrv6.sin6_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1468 serverAddrv6.sin6_port
1469 = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1470#if DEBUG_UDP 1411#if DEBUG_UDP
1471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1472 "IPv6 Binding failed, trying new port %d\n", 1413 "IPv6 Binding failed, trying new port %d\n",
1473 ntohs(serverAddrv6.sin6_port)); 1414 ntohs (serverAddrv6.sin6_port));
1474#endif 1415#endif
1475 tries++; 1416 tries++;
1476 if (tries > 10) 1417 if (tries > 10)
1477 { 1418 {
1478 GNUNET_NETWORK_socket_close (plugin->sockv6); 1419 GNUNET_NETWORK_socket_close (plugin->sockv6);
1479 plugin->sockv6 = NULL; 1420 plugin->sockv6 = NULL;
1480 break; 1421 break;
1481 } 1422 }
1482 } 1423 }
1483 if (plugin->sockv6 != NULL) 1424 if (plugin->sockv6 != NULL)
1484 { 1425 {
1485 addrs[sockets_created] = (struct sockaddr*) &serverAddrv6; 1426 addrs[sockets_created] = (struct sockaddr *) &serverAddrv6;
1486 addrlens[sockets_created] = sizeof (serverAddrv6); 1427 addrlens[sockets_created] = sizeof (serverAddrv6);
1487 sockets_created++; 1428 sockets_created++;
1488 } 1429 }
1489 }
1490 } 1430 }
1431 }
1491 1432
1492 plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, 1433 plugin->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages,
1493 plugin); 1434 plugin);
1494 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); 1435 plugin->sockv4 = GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0);
1495 if (NULL == plugin->sockv4) 1436 if (NULL == plugin->sockv4)
1496 { 1437 {
1497 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); 1438 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket");
1498 } 1439 }
1499 else 1440 else
1500 { 1441 {
1501#if HAVE_SOCKADDR_IN_SIN_LEN 1442#if HAVE_SOCKADDR_IN_SIN_LEN
1502 serverAddrv4.sin_len = sizeof (serverAddrv4); 1443 serverAddrv4.sin_len = sizeof (serverAddrv4);
1503#endif 1444#endif
1504 serverAddrv4.sin_family = AF_INET; 1445 serverAddrv4.sin_family = AF_INET;
1505 serverAddrv4.sin_addr.s_addr = INADDR_ANY; 1446 serverAddrv4.sin_addr.s_addr = INADDR_ANY;
1506 serverAddrv4.sin_port = htons (plugin->port); 1447 serverAddrv4.sin_port = htons (plugin->port);
1507 addrlen = sizeof (serverAddrv4); 1448 addrlen = sizeof (serverAddrv4);
1508 serverAddr = (struct sockaddr *) &serverAddrv4; 1449 serverAddr = (struct sockaddr *) &serverAddrv4;
1509#if DEBUG_UDP 1450#if DEBUG_UDP
1510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1451 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1511 "Binding to IPv4 port %d\n", 1452 "Binding to IPv4 port %d\n", ntohs (serverAddrv4.sin_port));
1512 ntohs(serverAddrv4.sin_port));
1513#endif 1453#endif
1514 tries = 0; 1454 tries = 0;
1515 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) != 1455 while (GNUNET_NETWORK_socket_bind (plugin->sockv4, serverAddr, addrlen) !=
1516 GNUNET_OK) 1456 GNUNET_OK)
1517 { 1457 {
1518 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */ 1458 serverAddrv4.sin_port = htons (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 33537) + 32000); /* Find a good, non-root port */
1519#if DEBUG_UDP 1459#if DEBUG_UDP
1520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1460 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1521 "IPv4 Binding failed, trying new port %d\n", 1461 "IPv4 Binding failed, trying new port %d\n",
1522 ntohs(serverAddrv4.sin_port)); 1462 ntohs (serverAddrv4.sin_port));
1523#endif 1463#endif
1524 tries++; 1464 tries++;
1525 if (tries > 10) 1465 if (tries > 10)
1526 { 1466 {
1527 GNUNET_NETWORK_socket_close (plugin->sockv4); 1467 GNUNET_NETWORK_socket_close (plugin->sockv4);
1528 plugin->sockv4 = NULL; 1468 plugin->sockv4 = NULL;
1529 break; 1469 break;
1530 } 1470 }
1531 }
1532 if (plugin->sockv4 != NULL)
1533 {
1534 addrs[sockets_created] = (struct sockaddr*) &serverAddrv4;
1535 addrlens[sockets_created] = sizeof (serverAddrv4);
1536 sockets_created++;
1537 }
1538 } 1471 }
1472 if (plugin->sockv4 != NULL)
1473 {
1474 addrs[sockets_created] = (struct sockaddr *) &serverAddrv4;
1475 addrlens[sockets_created] = sizeof (serverAddrv4);
1476 sockets_created++;
1477 }
1478 }
1539 1479
1540 plugin->rs = GNUNET_NETWORK_fdset_create (); 1480 plugin->rs = GNUNET_NETWORK_fdset_create ();
1541 GNUNET_NETWORK_fdset_zero (plugin->rs); 1481 GNUNET_NETWORK_fdset_zero (plugin->rs);
1542 if (NULL != plugin->sockv4) 1482 if (NULL != plugin->sockv4)
1543 GNUNET_NETWORK_fdset_set (plugin->rs, 1483 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv4);
1544 plugin->sockv4);
1545 if (NULL != plugin->sockv6) 1484 if (NULL != plugin->sockv6)
1546 GNUNET_NETWORK_fdset_set (plugin->rs, 1485 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->sockv6);
1547 plugin->sockv6);
1548 1486
1549 plugin->select_task = 1487 plugin->select_task =
1550 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1488 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1551 GNUNET_SCHEDULER_NO_TASK, 1489 GNUNET_SCHEDULER_NO_TASK,
1552 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, 1490 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
1553 NULL, &udp_plugin_select, plugin); 1491 NULL, &udp_plugin_select, plugin);
1554 if (sockets_created == 0) 1492 if (sockets_created == 0)
1555 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1493 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n"));
1556 _("Failed to open UDP sockets\n"));
1557 plugin->nat = GNUNET_NAT_register (env->cfg, 1494 plugin->nat = GNUNET_NAT_register (env->cfg,
1558 GNUNET_NO, 1495 GNUNET_NO,
1559 port, 1496 port,
1560 sockets_created, 1497 sockets_created,
1561 (const struct sockaddr**) addrs, addrlens, 1498 (const struct sockaddr **) addrs, addrlens,
1562 &udp_nat_port_map_callback, 1499 &udp_nat_port_map_callback, NULL, plugin);
1563 NULL,
1564 plugin);
1565 return api; 1500 return api;
1566} 1501}
1567 1502
@@ -1575,9 +1510,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
1575 * @return GNUNET_OK (continue to iterate) 1510 * @return GNUNET_OK (continue to iterate)
1576 */ 1511 */
1577static int 1512static int
1578destroy_session (void *cls, 1513destroy_session (void *cls, const GNUNET_HashCode * key, void *value)
1579 const GNUNET_HashCode *key,
1580 void *value)
1581{ 1514{
1582 struct PeerSession *peer_session = value; 1515 struct PeerSession *peer_session = value;
1583 1516
@@ -1602,32 +1535,31 @@ libgnunet_plugin_transport_udp_done (void *cls)
1602 1535
1603 /* FIXME: clean up heap and hashmap */ 1536 /* FIXME: clean up heap and hashmap */
1604 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions, 1537 GNUNET_CONTAINER_multihashmap_iterate (plugin->sessions,
1605 &destroy_session, 1538 &destroy_session, NULL);
1606 NULL);
1607 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 1539 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
1608 plugin->sessions = NULL; 1540 plugin->sessions = NULL;
1609 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags))) 1541 while (NULL != (rc = GNUNET_CONTAINER_heap_remove_root (plugin->defrags)))
1610 { 1542 {
1611 GNUNET_DEFRAGMENT_context_destroy (rc->defrag); 1543 GNUNET_DEFRAGMENT_context_destroy (rc->defrag);
1612 GNUNET_free (rc); 1544 GNUNET_free (rc);
1613 } 1545 }
1614 GNUNET_CONTAINER_heap_destroy (plugin->defrags); 1546 GNUNET_CONTAINER_heap_destroy (plugin->defrags);
1615 1547
1616 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) 1548 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
1617 { 1549 {
1618 GNUNET_SCHEDULER_cancel (plugin->select_task); 1550 GNUNET_SCHEDULER_cancel (plugin->select_task);
1619 plugin->select_task = GNUNET_SCHEDULER_NO_TASK; 1551 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
1620 } 1552 }
1621 if (plugin->sockv4 != NULL) 1553 if (plugin->sockv4 != NULL)
1622 { 1554 {
1623 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4)); 1555 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv4));
1624 plugin->sockv4 = NULL; 1556 plugin->sockv4 = NULL;
1625 } 1557 }
1626 if (plugin->sockv6 != NULL) 1558 if (plugin->sockv6 != NULL)
1627 { 1559 {
1628 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6)); 1560 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->sockv6));
1629 plugin->sockv6 = NULL; 1561 plugin->sockv6 = NULL;
1630 } 1562 }
1631 GNUNET_SERVER_mst_destroy (plugin->mst); 1563 GNUNET_SERVER_mst_destroy (plugin->mst);
1632 GNUNET_NETWORK_fdset_destroy (plugin->rs); 1564 GNUNET_NETWORK_fdset_destroy (plugin->rs);
1633 GNUNET_NAT_unregister (plugin->nat); 1565 GNUNET_NAT_unregister (plugin->nat);
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 2a7dc9065..22dda8e8b 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -375,26 +375,27 @@ unix_transport_server_stop (void *cls)
375 375
376 pos = retry_list_head; 376 pos = retry_list_head;
377 377
378 while(NULL != (pos = retry_list_head)) 378 while (NULL != (pos = retry_list_head))
379 {
380 GNUNET_CONTAINER_DLL_remove (retry_list_head, retry_list_tail, pos);
381 if (GNUNET_SCHEDULER_NO_TASK != pos->retry_ctx->retry_task)
379 { 382 {
380 GNUNET_CONTAINER_DLL_remove(retry_list_head, retry_list_tail, pos); 383 GNUNET_SCHEDULER_cancel (pos->retry_ctx->retry_task);
381 if (GNUNET_SCHEDULER_NO_TASK != pos->retry_ctx->retry_task)
382 {
383 GNUNET_SCHEDULER_cancel(pos->retry_ctx->retry_task);
384 }
385 GNUNET_free(pos->retry_ctx->msg);
386 GNUNET_free(pos->retry_ctx->addr);
387 GNUNET_free(pos->retry_ctx);
388 GNUNET_free(pos);
389 } 384 }
385 GNUNET_free (pos->retry_ctx->msg);
386 GNUNET_free (pos->retry_ctx->addr);
387 GNUNET_free (pos->retry_ctx);
388 GNUNET_free (pos);
389 }
390 390
391 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK) 391 if (plugin->select_task != GNUNET_SCHEDULER_NO_TASK)
392 { 392 {
393 GNUNET_SCHEDULER_cancel (plugin->select_task); 393 GNUNET_SCHEDULER_cancel (plugin->select_task);
394 plugin->select_task = GNUNET_SCHEDULER_NO_TASK; 394 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
395 } 395 }
396 396
397 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (plugin->unix_sock.desc)); 397 GNUNET_break (GNUNET_OK ==
398 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc));
398 plugin->unix_sock.desc = NULL; 399 plugin->unix_sock.desc = NULL;
399 400
400 return GNUNET_OK; 401 return GNUNET_OK;
@@ -402,18 +403,17 @@ unix_transport_server_stop (void *cls)
402 403
403 404
404struct PeerSession * 405struct PeerSession *
405find_session (struct Plugin *plugin, 406find_session (struct Plugin *plugin, const struct GNUNET_PeerIdentity *peer)
406 const struct GNUNET_PeerIdentity *peer)
407{ 407{
408 struct PeerSession *pos; 408 struct PeerSession *pos;
409 409
410 pos = plugin->sessions; 410 pos = plugin->sessions;
411 while (pos != NULL) 411 while (pos != NULL)
412 { 412 {
413 if (memcmp(&pos->target, peer, sizeof(struct GNUNET_PeerIdentity)) == 0) 413 if (memcmp (&pos->target, peer, sizeof (struct GNUNET_PeerIdentity)) == 0)
414 return pos; 414 return pos;
415 pos = pos->next; 415 pos = pos->next;
416 } 416 }
417 417
418 return pos; 418 return pos;
419} 419}
@@ -430,8 +430,7 @@ unix_real_send (void *cls,
430 struct GNUNET_TIME_Relative timeout, 430 struct GNUNET_TIME_Relative timeout,
431 const void *addr, 431 const void *addr,
432 size_t addrlen, 432 size_t addrlen,
433 GNUNET_TRANSPORT_TransmitContinuation cont, 433 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls);
434 void *cont_cls);
435 434
436/** 435/**
437 * Retry sending a message. 436 * Retry sending a message.
@@ -439,18 +438,18 @@ unix_real_send (void *cls,
439 * @param cls closure a struct RetrySendContext 438 * @param cls closure a struct RetrySendContext
440 * @param tc context information 439 * @param tc context information
441 */ 440 */
442void retry_send_message (void *cls, 441void
443 const struct GNUNET_SCHEDULER_TaskContext * tc) 442retry_send_message (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
444{ 443{
445 struct RetrySendContext *retry_ctx = cls; 444 struct RetrySendContext *retry_ctx = cls;
446 445
447 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 446 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
448 { 447 {
449 GNUNET_free(retry_ctx->msg); 448 GNUNET_free (retry_ctx->msg);
450 GNUNET_free(retry_ctx->addr); 449 GNUNET_free (retry_ctx->addr);
451 GNUNET_free(retry_ctx); 450 GNUNET_free (retry_ctx);
452 return; 451 return;
453 } 452 }
454 453
455 unix_real_send (retry_ctx->plugin, 454 unix_real_send (retry_ctx->plugin,
456 retry_ctx, 455 retry_ctx,
@@ -461,9 +460,7 @@ void retry_send_message (void *cls,
461 retry_ctx->priority, 460 retry_ctx->priority,
462 GNUNET_TIME_absolute_get_remaining (retry_ctx->timeout), 461 GNUNET_TIME_absolute_get_remaining (retry_ctx->timeout),
463 retry_ctx->addr, 462 retry_ctx->addr,
464 retry_ctx->addrlen, 463 retry_ctx->addrlen, retry_ctx->cont, retry_ctx->cont_cls);
465 retry_ctx->cont,
466 retry_ctx->cont_cls);
467 return; 464 return;
468} 465}
469 466
@@ -493,15 +490,14 @@ static ssize_t
493unix_real_send (void *cls, 490unix_real_send (void *cls,
494 struct RetrySendContext *incoming_retry_context, 491 struct RetrySendContext *incoming_retry_context,
495 struct GNUNET_NETWORK_Handle *send_handle, 492 struct GNUNET_NETWORK_Handle *send_handle,
496 const struct GNUNET_PeerIdentity *target, 493 const struct GNUNET_PeerIdentity *target,
497 const char *msgbuf, 494 const char *msgbuf,
498 size_t msgbuf_size, 495 size_t msgbuf_size,
499 unsigned int priority, 496 unsigned int priority,
500 struct GNUNET_TIME_Relative timeout, 497 struct GNUNET_TIME_Relative timeout,
501 const void *addr, 498 const void *addr,
502 size_t addrlen, 499 size_t addrlen,
503 GNUNET_TRANSPORT_TransmitContinuation cont, 500 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
504 void *cont_cls)
505{ 501{
506 struct Plugin *plugin = cls; 502 struct Plugin *plugin = cls;
507 struct UNIXMessage *message; 503 struct UNIXMessage *message;
@@ -516,26 +512,26 @@ unix_real_send (void *cls,
516 int retry; 512 int retry;
517 513
518 if (send_handle == NULL) 514 if (send_handle == NULL)
519 { 515 {
520#if DEBUG_UNIX 516#if DEBUG_UNIX
521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
522 "unix_real_send with send_handle NULL!\n"); 518 "unix_real_send with send_handle NULL!\n");
523#endif 519#endif
524 /* failed to open send socket for AF */ 520 /* failed to open send socket for AF */
525 if (cont != NULL) 521 if (cont != NULL)
526 cont (cont_cls, target, GNUNET_SYSERR); 522 cont (cont_cls, target, GNUNET_SYSERR);
527 return 0; 523 return 0;
528 } 524 }
529 if ((addr == NULL) || (addrlen == 0)) 525 if ((addr == NULL) || (addrlen == 0))
530 { 526 {
531#if DEBUG_UNIX 527#if DEBUG_UNIX
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 528 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "unix_real_send called without address, returning!\n"); 529 "unix_real_send called without address, returning!\n");
534#endif 530#endif
535 if (cont != NULL) 531 if (cont != NULL)
536 cont (cont_cls, target, GNUNET_SYSERR); 532 cont (cont_cls, target, GNUNET_SYSERR);
537 return 0; /* Can never send if we don't have an address!! */ 533 return 0; /* Can never send if we don't have an address!! */
538 } 534 }
539 535
540 /* Build the message to be sent */ 536 /* Build the message to be sent */
541 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size); 537 message = GNUNET_malloc (sizeof (struct UNIXMessage) + msgbuf_size);
@@ -547,13 +543,13 @@ unix_real_send (void *cls,
547 sizeof (struct GNUNET_PeerIdentity)); 543 sizeof (struct GNUNET_PeerIdentity));
548 memcpy (&message[1], msgbuf, msgbuf_size); 544 memcpy (&message[1], msgbuf, msgbuf_size);
549 545
550 memset(&un, 0, sizeof(un)); 546 memset (&un, 0, sizeof (un));
551 un.sun_family = AF_UNIX; 547 un.sun_family = AF_UNIX;
552 slen = strlen (addr) + 1; 548 slen = strlen (addr) + 1;
553 if (slen >= sizeof (un.sun_path)) 549 if (slen >= sizeof (un.sun_path))
554 slen = sizeof (un.sun_path) - 1; 550 slen = sizeof (un.sun_path) - 1;
555 sent = 0; 551 sent = 0;
556 GNUNET_assert(slen < sizeof(un.sun_path)); 552 GNUNET_assert (slen < sizeof (un.sun_path));
557 memcpy (un.sun_path, addr, slen); 553 memcpy (un.sun_path, addr, slen);
558 un.sun_path[slen] = '\0'; 554 un.sun_path[slen] = '\0';
559 slen = sizeof (struct sockaddr_un); 555 slen = sizeof (struct sockaddr_un);
@@ -563,104 +559,105 @@ unix_real_send (void *cls,
563#if HAVE_SOCKADDR_IN_SIN_LEN 559#if HAVE_SOCKADDR_IN_SIN_LEN
564 un.sun_len = (u_char) slen; 560 un.sun_len = (u_char) slen;
565#endif 561#endif
566 sb = (struct sockaddr*) &un; 562 sb = (struct sockaddr *) &un;
567 sbs = slen; 563 sbs = slen;
568 retry = GNUNET_NO; 564 retry = GNUNET_NO;
569 565
570 sent = GNUNET_NETWORK_socket_sendto(send_handle, message, ssize, sb, sbs); 566 sent = GNUNET_NETWORK_socket_sendto (send_handle, message, ssize, sb, sbs);
571 567
572 if ((GNUNET_SYSERR == sent) && (errno == EAGAIN)) 568 if ((GNUNET_SYSERR == sent) && (errno == EAGAIN))
573 retry = GNUNET_YES; 569 retry = GNUNET_YES;
574 570
575 if ((GNUNET_SYSERR == sent) && (errno == EMSGSIZE)) 571 if ((GNUNET_SYSERR == sent) && (errno == EMSGSIZE))
576 { 572 {
577 socklen_t size = 0; 573 socklen_t size = 0;
578 socklen_t len = sizeof (size); 574 socklen_t len = sizeof (size);
579 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle * ) send_handle, 575
580 SOL_SOCKET, 576 GNUNET_NETWORK_socket_getsockopt ((struct GNUNET_NETWORK_Handle *)
581 SO_SNDBUF, 577 send_handle, SOL_SOCKET, SO_SNDBUF, &size,
582 &size, &len); 578 &len);
583 579
584 if (size < ssize) 580 if (size < ssize)
585 { 581 {
586#if DEBUG_UNIX 582#if DEBUG_UNIX
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Trying to increase socket buffer size from %i to %i for message size %i\n", 584 "Trying to increase socket buffer size from %i to %i for message size %i\n",
589 size, 585 size, ((ssize / 1000) + 2) * 1000, ssize);
590 ((ssize / 1000) + 2) * 1000, ssize);
591#endif 586#endif
592 size = ((ssize / 1000) + 2) * 1000; 587 size = ((ssize / 1000) + 2) * 1000;
593 if (GNUNET_NETWORK_socket_setsockopt ((struct GNUNET_NETWORK_Handle * ) send_handle, 588 if (GNUNET_NETWORK_socket_setsockopt
594 SOL_SOCKET, 589 ((struct GNUNET_NETWORK_Handle *) send_handle, SOL_SOCKET, SO_SNDBUF,
595 SO_SNDBUF, 590 &size, sizeof (size)) == GNUNET_OK)
596 &size, sizeof(size)) == GNUNET_OK) 591 retry = GNUNET_YES;
597 retry = GNUNET_YES; 592 else
598 else 593 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
599 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt"); 594 }
600 }
601 } 595 }
602 596
603 if (retry == GNUNET_YES) 597 if (retry == GNUNET_YES)
598 {
599 if (incoming_retry_context == NULL)
604 { 600 {
605 if (incoming_retry_context == NULL) 601 retry_list_entry = GNUNET_malloc (sizeof (struct RetryList));
606 { 602 retry_ctx = GNUNET_malloc (sizeof (struct RetrySendContext));
607 retry_list_entry = GNUNET_malloc(sizeof(struct RetryList)); 603 retry_ctx->addr = GNUNET_malloc (addrlen);
608 retry_ctx = GNUNET_malloc(sizeof(struct RetrySendContext)); 604 retry_ctx->msg = GNUNET_malloc (msgbuf_size);
609 retry_ctx->addr = GNUNET_malloc(addrlen); 605 retry_ctx->plugin = plugin;
610 retry_ctx->msg = GNUNET_malloc(msgbuf_size); 606 memcpy (retry_ctx->addr, addr, addrlen);
611 retry_ctx->plugin = plugin; 607 memcpy (retry_ctx->msg, msgbuf, msgbuf_size);
612 memcpy(retry_ctx->addr, addr, addrlen); 608 retry_ctx->msg_size = msgbuf_size;
613 memcpy(retry_ctx->msg, msgbuf, msgbuf_size); 609 retry_ctx->addrlen = addrlen;
614 retry_ctx->msg_size = msgbuf_size; 610 retry_ctx->send_handle = send_handle;
615 retry_ctx->addrlen = addrlen; 611 retry_ctx->cont = cont;
616 retry_ctx->send_handle = send_handle; 612 retry_ctx->cont_cls = cont_cls;
617 retry_ctx->cont = cont; 613 retry_ctx->priority = priority;
618 retry_ctx->cont_cls = cont_cls; 614 retry_ctx->timeout = GNUNET_TIME_relative_to_absolute (timeout);
619 retry_ctx->priority = priority; 615 memcpy (&retry_ctx->target, target, sizeof (struct GNUNET_PeerIdentity));
620 retry_ctx->timeout = GNUNET_TIME_relative_to_absolute(timeout); 616 retry_ctx->delay = GNUNET_TIME_UNIT_MILLISECONDS;
621 memcpy(&retry_ctx->target, target, sizeof(struct GNUNET_PeerIdentity)); 617 retry_ctx->retry_list_entry = retry_list_entry;
622 retry_ctx->delay = GNUNET_TIME_UNIT_MILLISECONDS; 618 retry_list_entry->retry_ctx = retry_ctx;
623 retry_ctx->retry_list_entry = retry_list_entry; 619 GNUNET_CONTAINER_DLL_insert (retry_list_head, retry_list_tail,
624 retry_list_entry->retry_ctx = retry_ctx; 620 retry_list_entry);
625 GNUNET_CONTAINER_DLL_insert(retry_list_head, retry_list_tail, retry_list_entry);
626 }
627 else
628 {
629 retry_ctx = incoming_retry_context;
630 retry_ctx->delay = GNUNET_TIME_relative_multiply(retry_ctx->delay, 2);
631 }
632 retry_ctx->retry_task = GNUNET_SCHEDULER_add_delayed(retry_ctx->delay, &retry_send_message, retry_ctx);
633
634 //GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
635 GNUNET_free(message);
636 return ssize;
637 } 621 }
622 else
623 {
624 retry_ctx = incoming_retry_context;
625 retry_ctx->delay = GNUNET_TIME_relative_multiply (retry_ctx->delay, 2);
626 }
627 retry_ctx->retry_task =
628 GNUNET_SCHEDULER_add_delayed (retry_ctx->delay, &retry_send_message,
629 retry_ctx);
630
631 //GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
632 GNUNET_free (message);
633 return ssize;
634 }
638#if DEBUG_UNIX 635#if DEBUG_UNIX
639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
640 "UNIX transmit %u-byte message to %s (%d: %s)\n", 637 "UNIX transmit %u-byte message to %s (%d: %s)\n",
641 (unsigned int) ssize, 638 (unsigned int) ssize,
642 GNUNET_a2s (sb, sbs), 639 GNUNET_a2s (sb, sbs),
643 (int) sent, 640 (int) sent, (sent < 0) ? STRERROR (errno) : "ok");
644 (sent < 0) ? STRERROR (errno) : "ok");
645#endif 641#endif
646 if (cont != NULL) 642 if (cont != NULL)
643 {
644 if (sent == GNUNET_SYSERR)
645 cont (cont_cls, target, GNUNET_SYSERR);
646 else
647 { 647 {
648 if (sent == GNUNET_SYSERR) 648 cont (cont_cls, target, GNUNET_OK);
649 cont (cont_cls, target, GNUNET_SYSERR);
650 else
651 {
652 cont (cont_cls, target, GNUNET_OK);
653 }
654 } 649 }
650 }
655 651
656 if (incoming_retry_context != NULL) 652 if (incoming_retry_context != NULL)
657 { 653 {
658 GNUNET_CONTAINER_DLL_remove(retry_list_head, retry_list_tail, incoming_retry_context->retry_list_entry); 654 GNUNET_CONTAINER_DLL_remove (retry_list_head, retry_list_tail,
659 GNUNET_free(incoming_retry_context->retry_list_entry); 655 incoming_retry_context->retry_list_entry);
660 GNUNET_free(incoming_retry_context->msg); 656 GNUNET_free (incoming_retry_context->retry_list_entry);
661 GNUNET_free(incoming_retry_context->addr); 657 GNUNET_free (incoming_retry_context->msg);
662 GNUNET_free(incoming_retry_context); 658 GNUNET_free (incoming_retry_context->addr);
663 } 659 GNUNET_free (incoming_retry_context);
660 }
664 661
665 GNUNET_free (message); 662 GNUNET_free (message);
666 return sent; 663 return sent;
@@ -693,16 +690,16 @@ unix_real_send (void *cls,
693 */ 690 */
694static ssize_t 691static ssize_t
695unix_plugin_send (void *cls, 692unix_plugin_send (void *cls,
696 const struct GNUNET_PeerIdentity *target, 693 const struct GNUNET_PeerIdentity *target,
697 const char *msgbuf, 694 const char *msgbuf,
698 size_t msgbuf_size, 695 size_t msgbuf_size,
699 unsigned int priority, 696 unsigned int priority,
700 struct GNUNET_TIME_Relative timeout, 697 struct GNUNET_TIME_Relative timeout,
701 struct Session *session, 698 struct Session *session,
702 const void *addr, 699 const void *addr,
703 size_t addrlen, 700 size_t addrlen,
704 int force_address, 701 int force_address,
705 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 702 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
706{ 703{
707 struct Plugin *plugin = cls; 704 struct Plugin *plugin = cls;
708 ssize_t sent; 705 ssize_t sent;
@@ -712,17 +709,18 @@ unix_plugin_send (void *cls,
712 GNUNET_assert (NULL == session); 709 GNUNET_assert (NULL == session);
713 710
714#if DEBUG_UNIX 711#if DEBUG_UNIX
715 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n", (char *)addr); 712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asked to send message to `%s'\n",
713 (char *) addr);
716#endif 714#endif
717 sent = unix_real_send(cls, 715 sent = unix_real_send (cls,
718 NULL, 716 NULL,
719 plugin->unix_sock.desc, 717 plugin->unix_sock.desc,
720 target, 718 target,
721 msgbuf, msgbuf_size, 719 msgbuf, msgbuf_size,
722 priority, timeout, addr, addrlen, 720 priority, timeout, addr, addrlen, cont, cont_cls);
723 cont, cont_cls);
724#if DEBUG_UNIX 721#if DEBUG_UNIX
725 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", sent, (char *)addr); 722 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sent %d bytes to `%s'\n", sent,
723 (char *) addr);
726#endif 724#endif
727 if (sent == GNUNET_SYSERR) 725 if (sent == GNUNET_SYSERR)
728 return 0; 726 return 0;
@@ -740,11 +738,10 @@ unix_plugin_send (void *cls,
740 * @param fromlen the length of the address 738 * @param fromlen the length of the address
741 */ 739 */
742static void 740static void
743unix_demultiplexer(struct Plugin *plugin, 741unix_demultiplexer (struct Plugin *plugin,
744 struct GNUNET_PeerIdentity *sender, 742 struct GNUNET_PeerIdentity *sender,
745 const struct GNUNET_MessageHeader *currhdr, 743 const struct GNUNET_MessageHeader *currhdr,
746 const struct sockaddr_un *un, 744 const struct sockaddr_un *un, size_t fromlen)
747 size_t fromlen)
748{ 745{
749 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 746 struct GNUNET_TRANSPORT_ATS_Information distance[2];
750 747
@@ -753,14 +750,16 @@ unix_demultiplexer(struct Plugin *plugin,
753 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 750 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
754 distance[1].value = htonl (0); 751 distance[1].value = htonl (0);
755 752
756 GNUNET_assert(fromlen >= sizeof(struct sockaddr_un)); 753 GNUNET_assert (fromlen >= sizeof (struct sockaddr_un));
757 754
758#if DEBUG_UNIX 755#if DEBUG_UNIX
759 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n", un->sun_path); 756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from %s\n",
757 un->sun_path);
760#endif 758#endif
761 plugin->env->receive (plugin->env->cls, sender, currhdr, 759 plugin->env->receive (plugin->env->cls, sender, currhdr,
762 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, 760 (const struct GNUNET_TRANSPORT_ATS_Information *)
763 NULL, un->sun_path, strlen(un->sun_path) + 1); 761 &distance, 2, NULL, un->sun_path,
762 strlen (un->sun_path) + 1);
764} 763}
765 764
766 765
@@ -774,8 +773,7 @@ unix_demultiplexer(struct Plugin *plugin,
774 * 773 *
775 */ 774 */
776static void 775static void
777unix_plugin_select (void *cls, 776unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
778 const struct GNUNET_SCHEDULER_TaskContext *tc)
779{ 777{
780 struct Plugin *plugin = cls; 778 struct Plugin *plugin = cls;
781 char buf[65536]; 779 char buf[65536];
@@ -791,33 +789,35 @@ unix_plugin_select (void *cls,
791 uint16_t csize; 789 uint16_t csize;
792 790
793 plugin->select_task = GNUNET_SCHEDULER_NO_TASK; 791 plugin->select_task = GNUNET_SCHEDULER_NO_TASK;
794 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 792 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
795 return; 793 return;
796 794
797 addrlen = sizeof(un); 795 addrlen = sizeof (un);
798 memset(&un, 0, sizeof(un)); 796 memset (&un, 0, sizeof (un));
799 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->unix_sock.desc)); 797 GNUNET_assert (GNUNET_NETWORK_fdset_isset
798 (tc->read_ready, plugin->unix_sock.desc));
800 ret = 799 ret =
801 GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof (buf), 800 GNUNET_NETWORK_socket_recvfrom (plugin->unix_sock.desc, buf, sizeof (buf),
802 (struct sockaddr *)&un, &addrlen); 801 (struct sockaddr *) &un, &addrlen);
803 802
804 if (ret == GNUNET_SYSERR) 803 if (ret == GNUNET_SYSERR)
805 { 804 {
806 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 805 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom");
807 plugin->select_task = 806 plugin->select_task =
808 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 807 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
809 GNUNET_SCHEDULER_NO_TASK, 808 GNUNET_SCHEDULER_NO_TASK,
810 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, 809 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
811 NULL, &unix_plugin_select, plugin); 810 NULL, &unix_plugin_select, plugin);
812 return; 811 return;
813 } 812 }
814 else 813 else
815 { 814 {
816#if LINUX 815#if LINUX
817 un.sun_path[0] = '/'; 816 un.sun_path[0] = '/';
818#endif 817#endif
819#if DEBUG_UNIX 818#if DEBUG_UNIX
820 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret, &un.sun_path[0]); 819 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret,
820 &un.sun_path[0]);
821#endif 821#endif
822 } 822 }
823 823
@@ -825,40 +825,38 @@ unix_plugin_select (void *cls,
825 825
826 msg = (struct UNIXMessage *) buf; 826 msg = (struct UNIXMessage *) buf;
827 csize = ntohs (msg->header.size); 827 csize = ntohs (msg->header.size);
828 if ( (csize < sizeof (struct UNIXMessage)) || 828 if ((csize < sizeof (struct UNIXMessage)) || (csize > ret))
829 (csize > ret) ) 829 {
830 { 830 GNUNET_break_op (0);
831 GNUNET_break_op (0); 831 plugin->select_task =
832 plugin->select_task = 832 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
833 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 833 GNUNET_SCHEDULER_NO_TASK,
834 GNUNET_SCHEDULER_NO_TASK, 834 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
835 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, 835 NULL, &unix_plugin_select, plugin);
836 NULL, &unix_plugin_select, plugin); 836 return;
837 return; 837 }
838 } 838 msgbuf = (char *) &msg[1];
839 msgbuf = (char *)&msg[1];
840 memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); 839 memcpy (&sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity));
841 offset = 0; 840 offset = 0;
842 tsize = csize - sizeof (struct UNIXMessage); 841 tsize = csize - sizeof (struct UNIXMessage);
843 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 842 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize)
843 {
844 currhdr = (struct GNUNET_MessageHeader *) &msgbuf[offset];
845 csize = ntohs (currhdr->size);
846 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
847 (csize > tsize - offset))
844 { 848 {
845 currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; 849 GNUNET_break_op (0);
846 csize = ntohs (currhdr->size); 850 break;
847 if ( (csize < sizeof (struct GNUNET_MessageHeader)) ||
848 (csize > tsize - offset) )
849 {
850 GNUNET_break_op (0);
851 break;
852 }
853 unix_demultiplexer(plugin, &sender, currhdr,
854 &un, sizeof(un));
855 offset += csize;
856 } 851 }
852 unix_demultiplexer (plugin, &sender, currhdr, &un, sizeof (un));
853 offset += csize;
854 }
857 plugin->select_task = 855 plugin->select_task =
858 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 856 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
859 GNUNET_SCHEDULER_NO_TASK, 857 GNUNET_SCHEDULER_NO_TASK,
860 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, 858 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
861 NULL, &unix_plugin_select, plugin); 859 NULL, &unix_plugin_select, plugin);
862} 860}
863 861
864/** 862/**
@@ -876,7 +874,7 @@ unix_transport_server_start (void *cls)
876 struct sockaddr_un un; 874 struct sockaddr_un un;
877 size_t slen; 875 size_t slen;
878 876
879 memset(&un, 0, sizeof(un)); 877 memset (&un, 0, sizeof (un));
880 un.sun_family = AF_UNIX; 878 un.sun_family = AF_UNIX;
881 slen = strlen (plugin->unix_socket_path) + 1; 879 slen = strlen (plugin->unix_socket_path) + 1;
882 if (slen >= sizeof (un.sun_path)) 880 if (slen >= sizeof (un.sun_path))
@@ -889,42 +887,40 @@ unix_transport_server_start (void *cls)
889 un.sun_len = (u_char) slen; 887 un.sun_len = (u_char) slen;
890#endif 888#endif
891 889
892 serverAddr = (struct sockaddr*) &un; 890 serverAddr = (struct sockaddr *) &un;
893 addrlen = slen; 891 addrlen = slen;
894#if LINUX 892#if LINUX
895 un.sun_path[0] = '\0'; 893 un.sun_path[0] = '\0';
896#endif 894#endif
897 895
898 plugin->unix_sock.desc = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 896 plugin->unix_sock.desc =
897 GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0);
899 if (NULL == plugin->unix_sock.desc) 898 if (NULL == plugin->unix_sock.desc)
900 { 899 {
901 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 900 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
902 return GNUNET_SYSERR; 901 return GNUNET_SYSERR;
903 } 902 }
904 if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen) != 903 if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen)
905 GNUNET_OK) 904 != GNUNET_OK)
906 { 905 {
907 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); 906 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
908 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); 907 GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
909 plugin->unix_sock.desc = NULL; 908 plugin->unix_sock.desc = NULL;
910 return GNUNET_SYSERR; 909 return GNUNET_SYSERR;
911 } 910 }
912#if DEBUG_UNIX 911#if DEBUG_UNIX
913 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, 912 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
914 "unix", 913 "unix", "Bound to `%s'\n", &un.sun_path[0]);
915 "Bound to `%s'\n",
916 &un.sun_path[0]);
917#endif 914#endif
918 plugin->rs = GNUNET_NETWORK_fdset_create (); 915 plugin->rs = GNUNET_NETWORK_fdset_create ();
919 GNUNET_NETWORK_fdset_zero (plugin->rs); 916 GNUNET_NETWORK_fdset_zero (plugin->rs);
920 GNUNET_NETWORK_fdset_set (plugin->rs, 917 GNUNET_NETWORK_fdset_set (plugin->rs, plugin->unix_sock.desc);
921 plugin->unix_sock.desc);
922 918
923 plugin->select_task = 919 plugin->select_task =
924 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 920 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
925 GNUNET_SCHEDULER_NO_TASK, 921 GNUNET_SCHEDULER_NO_TASK,
926 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs, 922 GNUNET_TIME_UNIT_FOREVER_REL, plugin->rs,
927 NULL, &unix_plugin_select, plugin); 923 NULL, &unix_plugin_select, plugin);
928 return 1; 924 return 1;
929} 925}
930 926
@@ -946,15 +942,13 @@ unix_transport_server_start (void *cls)
946 * 942 *
947 */ 943 */
948static int 944static int
949unix_check_address (void *cls, 945unix_check_address (void *cls, const void *addr, size_t addrlen)
950 const void *addr,
951 size_t addrlen)
952{ 946{
953 947
954#if DEBUG_UNIX 948#if DEBUG_UNIX
955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 949 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
956 "Informing transport service about my address `%s'\n", 950 "Informing transport service about my address `%s'\n",
957 (char *)addr); 951 (char *) addr);
958#endif 952#endif
959 return GNUNET_OK; 953 return GNUNET_OK;
960} 954}
@@ -970,11 +964,11 @@ append_port (void *cls, const char *hostname)
970 char *ret; 964 char *ret;
971 965
972 if (hostname == NULL) 966 if (hostname == NULL)
973 { 967 {
974 ppc->asc (ppc->asc_cls, NULL); 968 ppc->asc (ppc->asc_cls, NULL);
975 GNUNET_free (ppc); 969 GNUNET_free (ppc);
976 return; 970 return;
977 } 971 }
978 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port); 972 GNUNET_asprintf (&ret, "%s:%d", hostname, ppc->port);
979 ppc->asc (ppc->asc_cls, ret); 973 ppc->asc (ppc->asc_cls, ret);
980 GNUNET_free (ret); 974 GNUNET_free (ret);
@@ -997,13 +991,13 @@ append_port (void *cls, const char *hostname)
997 */ 991 */
998static void 992static void
999unix_plugin_address_pretty_printer (void *cls, 993unix_plugin_address_pretty_printer (void *cls,
1000 const char *type, 994 const char *type,
1001 const void *addr, 995 const void *addr,
1002 size_t addrlen, 996 size_t addrlen,
1003 int numeric, 997 int numeric,
1004 struct GNUNET_TIME_Relative timeout, 998 struct GNUNET_TIME_Relative timeout,
1005 GNUNET_TRANSPORT_AddressStringCallback asc, 999 GNUNET_TRANSPORT_AddressStringCallback asc,
1006 void *asc_cls) 1000 void *asc_cls)
1007{ 1001{
1008 struct PrettyPrinterContext *ppc; 1002 struct PrettyPrinterContext *ppc;
1009 const void *sb; 1003 const void *sb;
@@ -1015,43 +1009,39 @@ unix_plugin_address_pretty_printer (void *cls,
1015 uint16_t port; 1009 uint16_t port;
1016 1010
1017 if (addrlen == sizeof (struct IPv6UdpAddress)) 1011 if (addrlen == sizeof (struct IPv6UdpAddress))
1018 { 1012 {
1019 u6 = addr; 1013 u6 = addr;
1020 memset (&a6, 0, sizeof (a6)); 1014 memset (&a6, 0, sizeof (a6));
1021 a6.sin6_family = AF_INET6; 1015 a6.sin6_family = AF_INET6;
1022 a6.sin6_port = u6->u6_port; 1016 a6.sin6_port = u6->u6_port;
1023 memcpy (&a6.sin6_addr, 1017 memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof (struct in6_addr));
1024 &u6->ipv6_addr, 1018 port = ntohs (u6->u6_port);
1025 sizeof (struct in6_addr)); 1019 sb = &a6;
1026 port = ntohs (u6->u6_port); 1020 sbs = sizeof (a6);
1027 sb = &a6; 1021 }
1028 sbs = sizeof (a6);
1029 }
1030 else if (addrlen == sizeof (struct IPv4UdpAddress)) 1022 else if (addrlen == sizeof (struct IPv4UdpAddress))
1031 { 1023 {
1032 u4 = addr; 1024 u4 = addr;
1033 memset (&a4, 0, sizeof (a4)); 1025 memset (&a4, 0, sizeof (a4));
1034 a4.sin_family = AF_INET; 1026 a4.sin_family = AF_INET;
1035 a4.sin_port = u4->u_port; 1027 a4.sin_port = u4->u_port;
1036 a4.sin_addr.s_addr = u4->ipv4_addr; 1028 a4.sin_addr.s_addr = u4->ipv4_addr;
1037 port = ntohs (u4->u_port); 1029 port = ntohs (u4->u_port);
1038 sb = &a4; 1030 sb = &a4;
1039 sbs = sizeof (a4); 1031 sbs = sizeof (a4);
1040 } 1032 }
1041 else 1033 else
1042 { 1034 {
1043 /* invalid address */ 1035 /* invalid address */
1044 GNUNET_break_op (0); 1036 GNUNET_break_op (0);
1045 asc (asc_cls, NULL); 1037 asc (asc_cls, NULL);
1046 return; 1038 return;
1047 } 1039 }
1048 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext)); 1040 ppc = GNUNET_malloc (sizeof (struct PrettyPrinterContext));
1049 ppc->asc = asc; 1041 ppc->asc = asc;
1050 ppc->asc_cls = asc_cls; 1042 ppc->asc_cls = asc_cls;
1051 ppc->port = port; 1043 ppc->port = port;
1052 GNUNET_RESOLVER_hostname_get (sb, 1044 GNUNET_RESOLVER_hostname_get (sb, sbs, !numeric, timeout, &append_port, ppc);
1053 sbs,
1054 !numeric, timeout, &append_port, ppc);
1055} 1045}
1056 1046
1057/** 1047/**
@@ -1065,10 +1055,8 @@ unix_plugin_address_pretty_printer (void *cls,
1065 * @param addrlen length of the address 1055 * @param addrlen length of the address
1066 * @return string representing the same address 1056 * @return string representing the same address
1067 */ 1057 */
1068static const char* 1058static const char *
1069unix_address_to_string (void *cls, 1059unix_address_to_string (void *cls, const void *addr, size_t addrlen)
1070 const void *addr,
1071 size_t addrlen)
1072{ 1060{
1073 if ((addr != NULL) && (addrlen > 0)) 1061 if ((addr != NULL) && (addrlen > 0))
1074 return (const char *) addr; 1062 return (const char *) addr;
@@ -1083,14 +1071,14 @@ unix_address_to_string (void *cls,
1083 * @param tc unused 1071 * @param tc unused
1084 */ 1072 */
1085static void 1073static void
1086address_notification (void *cls, 1074address_notification (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1087 const struct GNUNET_SCHEDULER_TaskContext *tc)
1088{ 1075{
1089 struct Plugin *plugin = cls; 1076 struct Plugin *plugin = cls;
1090 plugin->env->notify_address(plugin->env->cls, 1077
1091 GNUNET_YES, 1078 plugin->env->notify_address (plugin->env->cls,
1092 plugin->unix_socket_path, 1079 GNUNET_YES,
1093 strlen(plugin->unix_socket_path) + 1); 1080 plugin->unix_socket_path,
1081 strlen (plugin->unix_socket_path) + 1);
1094} 1082}
1095 1083
1096/** 1084/**
@@ -1108,17 +1096,14 @@ libgnunet_plugin_transport_unix_init (void *cls)
1108 1096
1109 if (GNUNET_OK != 1097 if (GNUNET_OK !=
1110 GNUNET_CONFIGURATION_get_value_number (env->cfg, 1098 GNUNET_CONFIGURATION_get_value_number (env->cfg,
1111 "transport-unix", 1099 "transport-unix", "PORT", &port))
1112 "PORT",
1113 &port))
1114 port = UNIX_NAT_DEFAULT_PORT; 1100 port = UNIX_NAT_DEFAULT_PORT;
1115 plugin = GNUNET_malloc (sizeof (struct Plugin)); 1101 plugin = GNUNET_malloc (sizeof (struct Plugin));
1116 plugin->port = port; 1102 plugin->port = port;
1117 plugin->env = env; 1103 plugin->env = env;
1118 GNUNET_asprintf (&plugin->unix_socket_path, 1104 GNUNET_asprintf (&plugin->unix_socket_path,
1119 "/tmp/unix-plugin-sock.%d", 1105 "/tmp/unix-plugin-sock.%d", plugin->port);
1120 plugin->port); 1106
1121
1122 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 1107 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
1123 api->cls = plugin; 1108 api->cls = plugin;
1124 1109
@@ -1129,10 +1114,9 @@ libgnunet_plugin_transport_unix_init (void *cls)
1129 api->check_address = &unix_check_address; 1114 api->check_address = &unix_check_address;
1130 sockets_created = unix_transport_server_start (plugin); 1115 sockets_created = unix_transport_server_start (plugin);
1131 if (sockets_created == 0) 1116 if (sockets_created == 0)
1132 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1117 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UNIX sockets\n"));
1133 _("Failed to open UNIX sockets\n"));
1134 1118
1135 GNUNET_SCHEDULER_add_now(address_notification, plugin); 1119 GNUNET_SCHEDULER_add_now (address_notification, plugin);
1136 return api; 1120 return api;
1137} 1121}
1138 1122
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c
index 80b6f2d6f..6ed367293 100644
--- a/src/transport/plugin_transport_wlan.c
+++ b/src/transport/plugin_transport_wlan.c
@@ -96,7 +96,7 @@
96#define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO 96#define DEBUG_wlan_ip_udp_packets_on_air GNUNET_NO
97 97
98 98
99#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ 99#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
100 100
101#define IEEE80211_FC0_VERSION_MASK 0x03 101#define IEEE80211_FC0_VERSION_MASK 0x03
102#define IEEE80211_FC0_VERSION_SHIFT 0 102#define IEEE80211_FC0_VERSION_SHIFT 0
@@ -113,25 +113,25 @@
113struct iph 113struct iph
114{ 114{
115#if __BYTE_ORDER == __LITTLE_ENDIAN 115#if __BYTE_ORDER == __LITTLE_ENDIAN
116 unsigned int ip_hl :4; /* header length */ 116 unsigned int ip_hl:4; /* header length */
117 unsigned int ip_v :4; /* version */ 117 unsigned int ip_v:4; /* version */
118#endif 118#endif
119#if __BYTE_ORDER == __BIG_ENDIAN 119#if __BYTE_ORDER == __BIG_ENDIAN
120 unsigned int ip_v:4; /* version */ 120 unsigned int ip_v:4; /* version */
121 unsigned int ip_hl:4; /* header length */ 121 unsigned int ip_hl:4; /* header length */
122#endif 122#endif
123 u_int8_t ip_tos; /* type of service */ 123 u_int8_t ip_tos; /* type of service */
124 u_short ip_len; /* total length */ 124 u_short ip_len; /* total length */
125 u_short ip_id; /* identification */ 125 u_short ip_id; /* identification */
126 u_short ip_off; /* fragment offset field */ 126 u_short ip_off; /* fragment offset field */
127#define IP_RF 0x8000 /* reserved fragment flag */ 127#define IP_RF 0x8000 /* reserved fragment flag */
128#define IP_DF 0x4000 /* dont fragment flag */ 128#define IP_DF 0x4000 /* dont fragment flag */
129#define IP_MF 0x2000 /* more fragments flag */ 129#define IP_MF 0x2000 /* more fragments flag */
130#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ 130#define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
131 u_int8_t ip_ttl; /* time to live */ 131 u_int8_t ip_ttl; /* time to live */
132 u_int8_t ip_p; /* protocol */ 132 u_int8_t ip_p; /* protocol */
133 u_short ip_sum; /* checksum */ 133 u_short ip_sum; /* checksum */
134 struct in_addr ip_src, ip_dst; /* source and dest address */ 134 struct in_addr ip_src, ip_dst; /* source and dest address */
135}; 135};
136 136
137struct udphdr 137struct udphdr
@@ -154,11 +154,11 @@ struct ieee80211_frame
154 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 154 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
155 u_int8_t i_seq[2]; 155 u_int8_t i_seq[2];
156#if DEBUG_wlan_ip_udp_packets_on_air 156#if DEBUG_wlan_ip_udp_packets_on_air
157u_int8_t llc[4]; 157 u_int8_t llc[4];
158struct iph ip; 158 struct iph ip;
159struct udphdr udp; 159 struct udphdr udp;
160#endif 160#endif
161}GNUNET_PACKED; 161} GNUNET_PACKED;
162 162
163/** 163/**
164 * Encapsulation of all of the state of the plugin. 164 * Encapsulation of all of the state of the plugin.
@@ -173,12 +173,12 @@ struct Plugin
173 /** 173 /**
174 * List of open connections. head 174 * List of open connections. head
175 */ 175 */
176 struct MacEndpoint * mac_head; 176 struct MacEndpoint *mac_head;
177 177
178 /** 178 /**
179 * List of open connections. tail 179 * List of open connections. tail
180 */ 180 */
181 struct MacEndpoint * mac_tail; 181 struct MacEndpoint *mac_tail;
182 182
183 /** 183 /**
184 * Number of connections 184 * Number of connections
@@ -188,12 +188,12 @@ struct Plugin
188 /** 188 /**
189 * encapsulation of data from the local wlan helper program 189 * encapsulation of data from the local wlan helper program
190 */ 190 */
191 struct GNUNET_SERVER_MessageStreamTokenizer * suid_tokenizer; 191 struct GNUNET_SERVER_MessageStreamTokenizer *suid_tokenizer;
192 192
193 /** 193 /**
194 * encapsulation of packets received from the wlan helper 194 * encapsulation of packets received from the wlan helper
195 */ 195 */
196 struct GNUNET_SERVER_MessageStreamTokenizer * data_tokenizer; 196 struct GNUNET_SERVER_MessageStreamTokenizer *data_tokenizer;
197 197
198 /** 198 /**
199 * stdout pipe handle for the gnunet-wlan-helper process 199 * stdout pipe handle for the gnunet-wlan-helper process
@@ -249,13 +249,13 @@ struct Plugin
249 * Sessions currently pending for transmission 249 * Sessions currently pending for transmission
250 * to a peer, if any. 250 * to a peer, if any.
251 */ 251 */
252 struct Sessionqueue * pending_Sessions_head; 252 struct Sessionqueue *pending_Sessions_head;
253 253
254 /** 254 /**
255 * Sessions currently pending for transmission 255 * Sessions currently pending for transmission
256 * to a peer (tail), if any. 256 * to a peer (tail), if any.
257 */ 257 */
258 struct Sessionqueue * pending_Sessions_tail; 258 struct Sessionqueue *pending_Sessions_tail;
259 259
260 /** 260 /**
261 * number of pending sessions 261 * number of pending sessions
@@ -270,11 +270,11 @@ struct Plugin
270 /** 270 /**
271 * messages ready for send, head 271 * messages ready for send, head
272 */ 272 */
273 struct FragmentMessage_queue * sending_messages_head; 273 struct FragmentMessage_queue *sending_messages_head;
274 /** 274 /**
275 * messages ready for send, tail 275 * messages ready for send, tail
276 */ 276 */
277 struct FragmentMessage_queue * sending_messages_tail; 277 struct FragmentMessage_queue *sending_messages_tail;
278 /** 278 /**
279 * time of the next "hello-beacon" 279 * time of the next "hello-beacon"
280 */ 280 */
@@ -283,12 +283,12 @@ struct Plugin
283 /** 283 /**
284 * queue to send acks for received fragments (head) 284 * queue to send acks for received fragments (head)
285 */ 285 */
286 struct AckSendQueue * ack_send_queue_head; 286 struct AckSendQueue *ack_send_queue_head;
287 287
288 /** 288 /**
289 * queue to send acks for received fragments (tail) 289 * queue to send acks for received fragments (tail)
290 */ 290 */
291 struct AckSendQueue * ack_send_queue_tail; 291 struct AckSendQueue *ack_send_queue_tail;
292 292
293 /** 293 /**
294 * Tracker for bandwidth limit 294 * Tracker for bandwidth limit
@@ -301,9 +301,9 @@ struct Plugin
301 */ 301 */
302struct Finish_send 302struct Finish_send
303{ 303{
304 struct Plugin * plugin; 304 struct Plugin *plugin;
305 char * msgheader; 305 char *msgheader;
306 struct GNUNET_MessageHeader * msgstart; 306 struct GNUNET_MessageHeader *msgstart;
307 ssize_t size; 307 ssize_t size;
308}; 308};
309 309
@@ -313,9 +313,9 @@ struct Finish_send
313//TODO DOXIGEN 313//TODO DOXIGEN
314struct Sessionqueue 314struct Sessionqueue
315{ 315{
316 struct Sessionqueue * next; 316 struct Sessionqueue *next;
317 struct Sessionqueue * prev; 317 struct Sessionqueue *prev;
318 struct Session * content; 318 struct Session *content;
319}; 319};
320 320
321/** 321/**
@@ -324,9 +324,9 @@ struct Sessionqueue
324//TODO DOXIGEN 324//TODO DOXIGEN
325struct FragmentMessage_queue 325struct FragmentMessage_queue
326{ 326{
327 struct FragmentMessage_queue * next; 327 struct FragmentMessage_queue *next;
328 struct FragmentMessage_queue * prev; 328 struct FragmentMessage_queue *prev;
329 struct FragmentMessage * content; 329 struct FragmentMessage *content;
330}; 330};
331 331
332/** 332/**
@@ -335,10 +335,10 @@ struct FragmentMessage_queue
335//TODO DOXIGEN 335//TODO DOXIGEN
336struct Receive_Fragment_Queue 336struct Receive_Fragment_Queue
337{ 337{
338 struct Receive_Fragment_Queue * next; 338 struct Receive_Fragment_Queue *next;
339 struct Receive_Fragment_Queue * prev; 339 struct Receive_Fragment_Queue *prev;
340 uint16_t num; 340 uint16_t num;
341 const char * msg; 341 const char *msg;
342 uint16_t size; 342 uint16_t size;
343 struct Radiotap_rx rxinfo; 343 struct Radiotap_rx rxinfo;
344}; 344};
@@ -346,16 +346,16 @@ struct Receive_Fragment_Queue
346//TODO DOXIGEN 346//TODO DOXIGEN
347struct MacEndpoint_id_fragment_triple 347struct MacEndpoint_id_fragment_triple
348{ 348{
349 struct MacEndpoint * endpoint; 349 struct MacEndpoint *endpoint;
350 uint32_t message_id; 350 uint32_t message_id;
351 struct FragmentMessage * fm; 351 struct FragmentMessage *fm;
352}; 352};
353 353
354//TODO DOXIGEN 354//TODO DOXIGEN
355struct Plugin_Session_pair 355struct Plugin_Session_pair
356{ 356{
357 struct Plugin * plugin; 357 struct Plugin *plugin;
358 struct Session * session; 358 struct Session *session;
359}; 359};
360 360
361/** 361/**
@@ -367,11 +367,11 @@ struct PendingMessage
367 /** 367 /**
368 * dll next 368 * dll next
369 */ 369 */
370 struct PendingMessage * next; 370 struct PendingMessage *next;
371 /** 371 /**
372 * dll prev 372 * dll prev
373 */ 373 */
374 struct PendingMessage * prev; 374 struct PendingMessage *prev;
375 375
376 /** 376 /**
377 * The pending message 377 * The pending message
@@ -393,7 +393,7 @@ struct PendingMessage
393 /** 393 /**
394 * Cls for transmit_cont 394 * Cls for transmit_cont
395 */ 395 */
396 void * transmit_cont_cls; 396 void *transmit_cont_cls;
397 397
398 /** 398 /**
399 * Timeout value for the pending message. 399 * Timeout value for the pending message.
@@ -411,15 +411,15 @@ struct AckSendQueue
411 /** 411 /**
412 * next ack in the ack send queue 412 * next ack in the ack send queue
413 */ 413 */
414 struct AckSendQueue * next; 414 struct AckSendQueue *next;
415 /** 415 /**
416 * previous ack in the ack send queue 416 * previous ack in the ack send queue
417 */ 417 */
418 struct AckSendQueue * prev; 418 struct AckSendQueue *prev;
419 /** 419 /**
420 * pointer to the session this ack belongs to 420 * pointer to the session this ack belongs to
421 */ 421 */
422 struct MacEndpoint * endpoint; 422 struct MacEndpoint *endpoint;
423 /** 423 /**
424 * ID of message, to distinguish between the messages, picked randomly. 424 * ID of message, to distinguish between the messages, picked randomly.
425 */ 425 */
@@ -428,15 +428,15 @@ struct AckSendQueue
428 /** 428 /**
429 * msg to send 429 * msg to send
430 */ 430 */
431 struct GNUNET_MessageHeader * hdr; 431 struct GNUNET_MessageHeader *hdr;
432 /** 432 /**
433 * pointer to the ieee wlan header 433 * pointer to the ieee wlan header
434 */ 434 */
435 struct ieee80211_frame * ieeewlanheader; 435 struct ieee80211_frame *ieeewlanheader;
436 /** 436 /**
437 * pointer to the radiotap header 437 * pointer to the radiotap header
438 */ 438 */
439 struct Radiotap_Send * radioHeader; 439 struct Radiotap_Send *radioHeader;
440}; 440};
441 441
442/** 442/**
@@ -448,7 +448,7 @@ struct Session_light
448 /** 448 /**
449 * the session this message belongs to 449 * the session this message belongs to
450 */ 450 */
451 struct Session * session; 451 struct Session *session;
452 /** 452 /**
453 * peer mac address 453 * peer mac address
454 */ 454 */
@@ -457,7 +457,7 @@ struct Session_light
457 /** 457 /**
458 * mac endpoint 458 * mac endpoint
459 */ 459 */
460 struct MacEndpoint * macendpoint; 460 struct MacEndpoint *macendpoint;
461}; 461};
462 462
463/** 463/**
@@ -475,13 +475,13 @@ struct Session
475 * Message currently pending for transmission 475 * Message currently pending for transmission
476 * to this peer, if any. head 476 * to this peer, if any. head
477 */ 477 */
478 struct PendingMessage * pending_message_head; 478 struct PendingMessage *pending_message_head;
479 479
480 /** 480 /**
481 * Message currently pending for transmission 481 * Message currently pending for transmission
482 * to this peer, if any. tail 482 * to this peer, if any. tail
483 */ 483 */
484 struct PendingMessage * pending_message_tail; 484 struct PendingMessage *pending_message_tail;
485 485
486 /** 486 /**
487 * To whom are we talking to (set to our identity 487 * To whom are we talking to (set to our identity
@@ -509,7 +509,7 @@ struct Session
509 /** 509 /**
510 * peer connection 510 * peer connection
511 */ 511 */
512 struct MacEndpoint * mac; 512 struct MacEndpoint *mac;
513 513
514 /** 514 /**
515 * count of messages in the fragment out queue for this session 515 * count of messages in the fragment out queue for this session
@@ -531,22 +531,22 @@ struct MacEndpoint
531 /** 531 /**
532 * Struct to hold the session reachable over this mac; head 532 * Struct to hold the session reachable over this mac; head
533 */ 533 */
534 struct Sessionqueue * sessions_head; 534 struct Sessionqueue *sessions_head;
535 /** 535 /**
536 * Struct to hold the session reachable over this mac; tail 536 * Struct to hold the session reachable over this mac; tail
537 */ 537 */
538 struct Sessionqueue * sessions_tail; 538 struct Sessionqueue *sessions_tail;
539 /** 539 /**
540 * Messages currently sending 540 * Messages currently sending
541 * to a peer, if any. 541 * to a peer, if any.
542 */ 542 */
543 struct FragmentMessage * sending_messages_head; 543 struct FragmentMessage *sending_messages_head;
544 544
545 /** 545 /**
546 * Messages currently sending 546 * Messages currently sending
547 * to a peer (tail), if any. 547 * to a peer (tail), if any.
548 */ 548 */
549 struct FragmentMessage * sending_messages_tail; 549 struct FragmentMessage *sending_messages_tail;
550 /** 550 /**
551 * dll next 551 * dll next
552 */ 552 */
@@ -564,7 +564,7 @@ struct MacEndpoint
564 /** 564 /**
565 * Defrag context for this mac endpoint 565 * Defrag context for this mac endpoint
566 */ 566 */
567 struct GNUNET_DEFRAGMENT_Context * defrag; 567 struct GNUNET_DEFRAGMENT_Context *defrag;
568 568
569 /** 569 /**
570 * count of messages in the fragment out queue for this mac endpoint 570 * count of messages in the fragment out queue for this mac endpoint
@@ -630,7 +630,7 @@ struct FragmentMessage
630 /** 630 /**
631 * Fragmentation context 631 * Fragmentation context
632 */ 632 */
633 struct GNUNET_FRAGMENT_Context * fragcontext; 633 struct GNUNET_FRAGMENT_Context *fragcontext;
634 634
635 /** 635 /**
636 * Timeout value for the message. 636 * Timeout value for the message.
@@ -645,7 +645,7 @@ struct FragmentMessage
645 /** 645 /**
646 * Fragment to send 646 * Fragment to send
647 */ 647 */
648 char * frag; 648 char *frag;
649 649
650 /** 650 /**
651 * size of message 651 * size of message
@@ -655,20 +655,20 @@ struct FragmentMessage
655 /** 655 /**
656 * pointer to the ieee wlan header 656 * pointer to the ieee wlan header
657 */ 657 */
658 struct ieee80211_frame * ieeewlanheader; 658 struct ieee80211_frame *ieeewlanheader;
659 /** 659 /**
660 * pointer to the radiotap header 660 * pointer to the radiotap header
661 */ 661 */
662 struct Radiotap_Send * radioHeader; 662 struct Radiotap_Send *radioHeader;
663}; 663};
664 664
665static void 665static void
666do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 666do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
667static void 667static void
668free_session(struct Plugin * plugin, struct Sessionqueue * queue, 668free_session (struct Plugin *plugin, struct Sessionqueue *queue,
669 int do_free_macendpoint); 669 int do_free_macendpoint);
670static struct MacEndpoint * 670static struct MacEndpoint *create_macendpoint (struct Plugin *plugin,
671create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr); 671 const struct MacAddress *addr);
672 672
673/** 673/**
674 * Generates a nice hexdump of a memory area. 674 * Generates a nice hexdump of a memory area.
@@ -677,51 +677,50 @@ create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr);
677 * \param length how many bytes to dump 677 * \param length how many bytes to dump
678 */ 678 */
679void 679void
680hexdump(void *mem, unsigned length) 680hexdump (void *mem, unsigned length)
681{ 681{
682 char line[80]; 682 char line[80];
683 char *src = (char*) mem; 683 char *src = (char *) mem;
684 684
685 printf( 685 printf ("dumping %u bytes from %p\r\n"
686 "dumping %u bytes from %p\r\n" 686 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n",
687 " 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF\r\n", 687 length, src);
688 length, src);
689 unsigned i; 688 unsigned i;
690 int j; 689 int j;
691 690
692 for (i = 0; i < length; i += 16, src += 16) 691 for (i = 0; i < length; i += 16, src += 16)
693 { 692 {
694 char *t = line; 693 char *t = line;
695 694
696 t += sprintf(t, "%04x: ", i); 695 t += sprintf (t, "%04x: ", i);
697 for (j = 0; j < 16; j++) 696 for (j = 0; j < 16; j++)
698 { 697 {
699 if (i + j < length) 698 if (i + j < length)
700 t += sprintf(t, "%02X", src[j] & 0xff); 699 t += sprintf (t, "%02X", src[j] & 0xff);
701 else 700 else
702 t += sprintf(t, " "); 701 t += sprintf (t, " ");
703 t += sprintf(t, j % 2 ? " " : "-"); 702 t += sprintf (t, j % 2 ? " " : "-");
704 } 703 }
705
706 t += sprintf(t, " ");
707 for (j = 0; j < 16; j++)
708 {
709 if (i + j < length)
710 {
711 if (isprint((unsigned char)src[j]))
712 t += sprintf(t, "%c", src[j]);
713 else
714 t += sprintf(t, ".");
715 }
716 else
717 {
718 t += sprintf(t, " ");
719 }
720 }
721 704
722 t += sprintf(t, "\r\n"); 705 t += sprintf (t, " ");
723 printf("%s", line); 706 for (j = 0; j < 16; j++)
707 {
708 if (i + j < length)
709 {
710 if (isprint ((unsigned char) src[j]))
711 t += sprintf (t, "%c", src[j]);
712 else
713 t += sprintf (t, ".");
714 }
715 else
716 {
717 t += sprintf (t, " ");
718 }
724 } 719 }
720
721 t += sprintf (t, "\r\n");
722 printf ("%s", line);
723 }
725} 724}
726 725
727/** 726/**
@@ -732,28 +731,30 @@ hexdump(void *mem, unsigned length)
732 * @return 731 * @return
733 */ 732 */
734static struct MacEndpoint * 733static struct MacEndpoint *
735get_macendpoint(struct Plugin *plugin, const struct MacAddress *addr, 734get_macendpoint (struct Plugin *plugin, const struct MacAddress *addr,
736 int create_new) 735 int create_new)
737{ 736{
738 struct MacEndpoint * queue = plugin->mac_head; 737 struct MacEndpoint *queue = plugin->mac_head;
738
739 while (queue != NULL) 739 while (queue != NULL)
740 { 740 {
741 GNUNET_assert (queue->sessions_head != NULL); 741 GNUNET_assert (queue->sessions_head != NULL);
742 if (memcmp(addr, &queue->addr, sizeof(struct MacAddress)) == 0) 742 if (memcmp (addr, &queue->addr, sizeof (struct MacAddress)) == 0)
743 return queue; /* session found */ 743 return queue; /* session found */
744 queue = queue->next; 744 queue = queue->next;
745 } 745 }
746 746
747 if (create_new == GNUNET_YES) 747 if (create_new == GNUNET_YES)
748 { 748 {
749 return create_macendpoint(plugin, addr); 749 return create_macendpoint (plugin, addr);
750 } 750 }
751 else 751 else
752 { 752 {
753 return NULL; 753 return NULL;
754 } 754 }
755 755
756} 756}
757
757/** 758/**
758 * search for a session with the addr and peer id 759 * search for a session with the addr and peer id
759 * 760 *
@@ -763,20 +764,20 @@ get_macendpoint(struct Plugin *plugin, const struct MacAddress *addr,
763 * @return returns the session 764 * @return returns the session
764 */ 765 */
765static struct Session * 766static struct Session *
766search_session(struct Plugin *plugin, const struct MacEndpoint * endpoint, 767search_session (struct Plugin *plugin, const struct MacEndpoint *endpoint,
767 const struct GNUNET_PeerIdentity * peer) 768 const struct GNUNET_PeerIdentity *peer)
768{ 769{
769 GNUNET_assert(endpoint != NULL); 770 GNUNET_assert (endpoint != NULL);
770 struct Sessionqueue * queue = endpoint->sessions_head; 771 struct Sessionqueue *queue = endpoint->sessions_head;
771 772
772 while (queue != NULL) 773 while (queue != NULL)
773 { 774 {
774 GNUNET_assert (queue->content != NULL); 775 GNUNET_assert (queue->content != NULL);
775 if (memcmp(peer, &queue->content->target, 776 if (memcmp (peer, &queue->content->target,
776 sizeof(struct GNUNET_PeerIdentity)) == 0) 777 sizeof (struct GNUNET_PeerIdentity)) == 0)
777 return queue->content; /* session found */ 778 return queue->content; /* session found */
778 queue = queue->next; 779 queue = queue->next;
779 } 780 }
780 return NULL; 781 return NULL;
781} 782}
782 783
@@ -791,21 +792,21 @@ search_session(struct Plugin *plugin, const struct MacEndpoint * endpoint,
791 * @param addrlen length of the address 792 * @param addrlen length of the address
792 * @return string representing the same address 793 * @return string representing the same address
793 */ 794 */
794static const char* 795static const char *
795wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen) 796wlan_plugin_address_to_string (void *cls, const void *addr, size_t addrlen)
796{ 797{
797 static char ret[40]; 798 static char ret[40];
798 const struct MacAddress *mac; 799 const struct MacAddress *mac;
799 800
800 if (addrlen != sizeof(struct MacAddress)) 801 if (addrlen != sizeof (struct MacAddress))
801 { 802 {
802 GNUNET_break (0); 803 GNUNET_break (0);
803 return NULL; 804 return NULL;
804 } 805 }
805 mac = addr; 806 mac = addr;
806 GNUNET_snprintf(ret, sizeof(ret), "%s Mac-Address %X:%X:%X:%X:%X:%X", 807 GNUNET_snprintf (ret, sizeof (ret), "%s Mac-Address %X:%X:%X:%X:%X:%X",
807 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2], mac->mac[3], 808 PROTOCOL_PREFIX, mac->mac[0], mac->mac[1], mac->mac[2],
808 mac->mac[4], mac->mac[5]); 809 mac->mac[3], mac->mac[4], mac->mac[5]);
809 return ret; 810 return ret;
810} 811}
811 812
@@ -815,25 +816,27 @@ wlan_plugin_address_to_string(void *cls, const void *addr, size_t addrlen)
815 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext 816 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
816 */ 817 */
817static void 818static void
818session_timeout (void *cls, 819session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
819 const struct GNUNET_SCHEDULER_TaskContext *tc){ 820{
820 struct Sessionqueue * queue = cls; 821 struct Sessionqueue *queue = cls;
821 GNUNET_assert(queue != NULL); 822
823 GNUNET_assert (queue != NULL);
822 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK; 824 queue->content->timeout_task = GNUNET_SCHEDULER_NO_TASK;
823 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){ 825 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
824 return; 826 {
827 return;
828 }
829 if (GNUNET_TIME_absolute_get_remaining
830 (GNUNET_TIME_absolute_add
831 (queue->content->last_activity, SESSION_TIMEOUT)).rel_value == 0)
832 {
833 free_session (queue->content->mac->plugin, queue, GNUNET_YES);
825 } 834 }
826 if (GNUNET_TIME_absolute_get_remaining(
827 GNUNET_TIME_absolute_add(queue->content->last_activity, SESSION_TIMEOUT)).rel_value
828 == 0)
829 {
830 free_session(queue->content->mac->plugin,queue,GNUNET_YES);
831 }
832 else 835 else
833 { 836 {
834 queue->content->timeout_task = GNUNET_SCHEDULER_add_delayed(SESSION_TIMEOUT, 837 queue->content->timeout_task =
835 &session_timeout, queue); 838 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
836 } 839 }
837} 840}
838 841
839/** 842/**
@@ -845,24 +848,29 @@ session_timeout (void *cls,
845 */ 848 */
846 849
847static struct Session * 850static struct Session *
848create_session(struct Plugin *plugin, struct MacEndpoint * endpoint, 851create_session (struct Plugin *plugin, struct MacEndpoint *endpoint,
849 const struct GNUNET_PeerIdentity * peer) 852 const struct GNUNET_PeerIdentity *peer)
850{ 853{
851 GNUNET_assert(endpoint != NULL); 854 GNUNET_assert (endpoint != NULL);
852 struct Sessionqueue * queue = GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session)); 855 struct Sessionqueue *queue =
856 GNUNET_malloc (sizeof (struct Sessionqueue) + sizeof (struct Session));
853 857
854 GNUNET_CONTAINER_DLL_insert_tail(endpoint->sessions_head, endpoint->sessions_tail, queue); 858 GNUNET_CONTAINER_DLL_insert_tail (endpoint->sessions_head,
859 endpoint->sessions_tail, queue);
855 860
856 queue->content = (struct Session *) &queue[1]; 861 queue->content = (struct Session *) &queue[1];
857 queue->content->mac = endpoint; 862 queue->content->mac = endpoint;
858 memcpy(&(queue->content->target), peer, sizeof(struct GNUNET_PeerIdentity)); 863 memcpy (&(queue->content->target), peer, sizeof (struct GNUNET_PeerIdentity));
859 queue->content->last_activity = GNUNET_TIME_absolute_get(); 864 queue->content->last_activity = GNUNET_TIME_absolute_get ();
860 queue->content->timeout_task = GNUNET_SCHEDULER_add_delayed(SESSION_TIMEOUT,&session_timeout, queue); 865 queue->content->timeout_task =
866 GNUNET_SCHEDULER_add_delayed (SESSION_TIMEOUT, &session_timeout, queue);
861 867
862#if DEBUG_wlan 868#if DEBUG_wlan
863 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "New session %p with endpoint %p: %s\n", 869 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
864 queue->content, endpoint, 870 "New session %p with endpoint %p: %s\n", queue->content,
865 wlan_plugin_address_to_string(NULL, endpoint->addr.mac, 6)); 871 endpoint, wlan_plugin_address_to_string (NULL,
872 endpoint->addr.mac,
873 6));
866#endif 874#endif
867 875
868 return queue->content; 876 return queue->content;
@@ -877,16 +885,17 @@ create_session(struct Plugin *plugin, struct MacEndpoint * endpoint,
877 * @return returns the session 885 * @return returns the session
878 */ 886 */
879static struct Session * 887static struct Session *
880get_session(struct Plugin *plugin, const struct MacAddress *addr, 888get_session (struct Plugin *plugin, const struct MacAddress *addr,
881 const struct GNUNET_PeerIdentity * peer) 889 const struct GNUNET_PeerIdentity *peer)
882{ 890{
883 struct MacEndpoint * mac; 891 struct MacEndpoint *mac;
884 mac = get_macendpoint(plugin, addr, GNUNET_YES); 892
885 struct Session * session = search_session(plugin, mac, peer); 893 mac = get_macendpoint (plugin, addr, GNUNET_YES);
894 struct Session *session = search_session (plugin, mac, peer);
886 895
887 if (session != NULL) 896 if (session != NULL)
888 return session; 897 return session;
889 return create_session(plugin, mac, peer); 898 return create_session (plugin, mac, peer);
890} 899}
891 900
892/** 901/**
@@ -897,35 +906,35 @@ get_session(struct Plugin *plugin, const struct MacAddress *addr,
897 * @param session pointer to the session to add 906 * @param session pointer to the session to add
898 */ 907 */
899static void 908static void
900queue_session(struct Plugin *plugin, struct Session * session) 909queue_session (struct Plugin *plugin, struct Session *session)
901{ 910{
902 struct Sessionqueue * queue = plugin->pending_Sessions_head; 911 struct Sessionqueue *queue = plugin->pending_Sessions_head;
903 912
904 if (session->pending_message_head != NULL) 913 if (session->pending_message_head != NULL)
914 {
915 while (queue != NULL)
905 { 916 {
906 while (queue != NULL) 917 // content is never NULL
907 { 918 GNUNET_assert (queue->content != NULL);
908 // content is never NULL 919 // is session already in queue?
909 GNUNET_assert (queue->content != NULL); 920 if (session == queue->content)
910 // is session already in queue? 921 {
911 if (session == queue->content) 922 return;
912 { 923 }
913 return; 924 // try next
914 } 925 queue = queue->next;
915 // try next 926 }
916 queue = queue->next;
917 }
918 927
919 // Session is not in the queue 928 // Session is not in the queue
920 929
921 queue = GNUNET_malloc (sizeof (struct Sessionqueue)); 930 queue = GNUNET_malloc (sizeof (struct Sessionqueue));
922 queue->content = session; 931 queue->content = session;
923 932
924 //insert at the tail 933 //insert at the tail
925 GNUNET_CONTAINER_DLL_insert_tail(plugin->pending_Sessions_head, 934 GNUNET_CONTAINER_DLL_insert_tail (plugin->pending_Sessions_head,
926 plugin->pending_Sessions_tail, queue); 935 plugin->pending_Sessions_tail, queue);
927 plugin->pendingsessions++; 936 plugin->pendingsessions++;
928 } 937 }
929 938
930} 939}
931 940
@@ -935,9 +944,10 @@ queue_session(struct Plugin *plugin, struct Session * session)
935 * @param tc GNUNET_SCHEDULER_TaskContext pointer 944 * @param tc GNUNET_SCHEDULER_TaskContext pointer
936 */ 945 */
937static void 946static void
938delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 947delay_fragment_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
939{ 948{
940 struct Plugin * plugin = cls; 949 struct Plugin *plugin = cls;
950
941 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 951 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
942 952
943 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 953 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -945,11 +955,12 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
945 955
946 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg 956 // GNUNET_TIME_UNIT_FOREVER_REL is needed to clean up old msg
947 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK) 957 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
948 { 958 {
949 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 959 plugin->server_write_task =
950 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 960 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
951 &do_transmit, plugin); 961 plugin->server_stdin_handle,
952 } 962 &do_transmit, plugin);
963 }
953} 964}
954 965
955/** 966/**
@@ -958,32 +969,33 @@ delay_fragment_task(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
958 */ 969 */
959 970
960static void 971static void
961set_next_beacon_time(struct Plugin * const plugin) 972set_next_beacon_time (struct Plugin *const plugin)
962{ 973{
963 //under 10 known peers: once a second 974 //under 10 known peers: once a second
964 if (plugin->mac_count < 10) 975 if (plugin->mac_count < 10)
965 { 976 {
966 plugin->beacon_time = GNUNET_TIME_absolute_add( 977 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
967 GNUNET_TIME_absolute_get(), 978 GNUNET_TIME_relative_multiply
968 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 979 (GNUNET_TIME_UNIT_SECONDS,
969 HALLO_BEACON_SCALING_FACTOR)); 980 HALLO_BEACON_SCALING_FACTOR));
970 } 981 }
971 //under 30 known peers: every 10 seconds 982 //under 30 known peers: every 10 seconds
972 else if (plugin->mac_count < 30) 983 else if (plugin->mac_count < 30)
973 { 984 {
974 plugin->beacon_time = GNUNET_TIME_absolute_add( 985 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
975 GNUNET_TIME_absolute_get(), 986 GNUNET_TIME_relative_multiply
976 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 987 (GNUNET_TIME_UNIT_SECONDS,
977 10 * HALLO_BEACON_SCALING_FACTOR)); 988 10 *
978 } 989 HALLO_BEACON_SCALING_FACTOR));
990 }
979 //over 30 known peers: once a minute 991 //over 30 known peers: once a minute
980 else 992 else
981 { 993 {
982 plugin->beacon_time = GNUNET_TIME_absolute_add( 994 plugin->beacon_time = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
983 GNUNET_TIME_absolute_get(), 995 GNUNET_TIME_relative_multiply
984 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 996 (GNUNET_TIME_UNIT_MINUTES,
985 HALLO_BEACON_SCALING_FACTOR)); 997 HALLO_BEACON_SCALING_FACTOR));
986 } 998 }
987} 999}
988 1000
989/** 1001/**
@@ -992,55 +1004,57 @@ set_next_beacon_time(struct Plugin * const plugin)
992 */ 1004 */
993 1005
994static void 1006static void
995set_next_send(struct Plugin * const plugin) 1007set_next_send (struct Plugin *const plugin)
996{ 1008{
997 struct GNUNET_TIME_Relative next_send; 1009 struct GNUNET_TIME_Relative next_send;
998 1010
999 //cancel old task 1011 //cancel old task
1000 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 1012 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
1001 { 1013 {
1002 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); 1014 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
1003 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 1015 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
1004 } 1016 }
1005 1017
1006 //check if some acks are in the queue 1018 //check if some acks are in the queue
1007 if (plugin->ack_send_queue_head != NULL) 1019 if (plugin->ack_send_queue_head != NULL)
1008 { 1020 {
1009 next_send = GNUNET_TIME_UNIT_ZERO; 1021 next_send = GNUNET_TIME_UNIT_ZERO;
1010 } 1022 }
1011 1023
1012 //check if there are some fragments in the queue 1024 //check if there are some fragments in the queue
1013 else if (plugin->sending_messages_head != NULL) 1025 else if (plugin->sending_messages_head != NULL)
1014 { 1026 {
1015 next_send = GNUNET_TIME_UNIT_ZERO; 1027 next_send = GNUNET_TIME_UNIT_ZERO;
1016 } 1028 }
1017 else 1029 else
1018 { 1030 {
1019 next_send = GNUNET_TIME_absolute_get_remaining(plugin->beacon_time); 1031 next_send = GNUNET_TIME_absolute_get_remaining (plugin->beacon_time);
1020 } 1032 }
1021 1033
1022#if DEBUG_wlan 1034#if DEBUG_wlan
1023 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Next packet is send in: %u\n", 1035 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1024 next_send.rel_value); 1036 "Next packet is send in: %u\n", next_send.rel_value);
1025#endif 1037#endif
1026 1038
1027 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value) 1039 if (next_send.rel_value == GNUNET_TIME_UNIT_ZERO.rel_value)
1040 {
1041 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK)
1028 { 1042 {
1029 if (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK) 1043 plugin->server_write_task =
1030 { 1044 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1031 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 1045 plugin->server_stdin_handle,
1032 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 1046 &do_transmit, plugin);
1033 &do_transmit, plugin);
1034 }
1035 } 1047 }
1048 }
1036 else 1049 else
1050 {
1051 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK)
1037 { 1052 {
1038 if (plugin->server_write_delay_task == GNUNET_SCHEDULER_NO_TASK) 1053 plugin->server_write_delay_task =
1039 { 1054 GNUNET_SCHEDULER_add_delayed (next_send, &delay_fragment_task,
1040 plugin->server_write_delay_task = GNUNET_SCHEDULER_add_delayed( 1055 plugin);
1041 next_send, &delay_fragment_task, plugin);
1042 }
1043 } 1056 }
1057 }
1044} 1058}
1045 1059
1046/** 1060/**
@@ -1049,77 +1063,81 @@ set_next_send(struct Plugin * const plugin)
1049 * @return pointer to the session found, returns NULL if there is now session in the queue 1063 * @return pointer to the session found, returns NULL if there is now session in the queue
1050 */ 1064 */
1051static struct Session * 1065static struct Session *
1052get_next_queue_session(struct Plugin * plugin) 1066get_next_queue_session (struct Plugin *plugin)
1053{ 1067{
1054 struct Session * session; 1068 struct Session *session;
1055 struct Sessionqueue * sessionqueue; 1069 struct Sessionqueue *sessionqueue;
1056 struct Sessionqueue * sessionqueue_alt; 1070 struct Sessionqueue *sessionqueue_alt;
1057 struct PendingMessage * pm; 1071 struct PendingMessage *pm;
1072
1058 sessionqueue = plugin->pending_Sessions_head; 1073 sessionqueue = plugin->pending_Sessions_head;
1059 1074
1060 while (sessionqueue != NULL) 1075 while (sessionqueue != NULL)
1061 { 1076 {
1062 session = sessionqueue->content; 1077 session = sessionqueue->content;
1063 1078
1064 GNUNET_assert(session != NULL); 1079 GNUNET_assert (session != NULL);
1065 pm = session->pending_message_head; 1080 pm = session->pending_message_head;
1066 1081
1067#if DEBUG_wlan 1082#if DEBUG_wlan
1068 if (pm == NULL) 1083 if (pm == NULL)
1069 { 1084 {
1070 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1085 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1071 "pending message is empty, should not happen. session %p\n", 1086 "pending message is empty, should not happen. session %p\n",
1072 session); 1087 session);
1073 } 1088 }
1074#endif 1089#endif
1075 1090
1076 GNUNET_assert(pm != NULL); 1091 GNUNET_assert (pm != NULL);
1077 1092
1078 //check for message timeout 1093 //check for message timeout
1079 if (GNUNET_TIME_absolute_get_remaining(pm->timeout).rel_value > 0) 1094 if (GNUNET_TIME_absolute_get_remaining (pm->timeout).rel_value > 0)
1080 { 1095 {
1081 //check if session has no message in the fragment queue 1096 //check if session has no message in the fragment queue
1082 if ((session->mac->fragment_messages_out_count 1097 if ((session->mac->fragment_messages_out_count
1083 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT) 1098 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_MACENDPOINT)
1084 && (session->fragment_messages_out_count 1099 && (session->fragment_messages_out_count
1085 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION)) 1100 < FRAGMENT_QUEUE_MESSAGES_OUT_PER_SESSION))
1086 { 1101 {
1087 plugin->pendingsessions--; 1102 plugin->pendingsessions--;
1088 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1103 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1089 plugin->pending_Sessions_tail, sessionqueue); 1104 plugin->pending_Sessions_tail,
1090 GNUNET_free(sessionqueue); 1105 sessionqueue);
1091 1106 GNUNET_free (sessionqueue);
1092 return session; 1107
1093 } 1108 return session;
1094 else 1109 }
1095 {
1096 sessionqueue = sessionqueue->next;
1097 }
1098 }
1099 else 1110 else
1100 { 1111 {
1101 GNUNET_CONTAINER_DLL_remove(session->pending_message_head, session->pending_message_tail, pm); 1112 sessionqueue = sessionqueue->next;
1102 1113 }
1103 //call the cont func that it did not work 1114 }
1104 if (pm->transmit_cont != NULL) 1115 else
1105 pm->transmit_cont(pm->transmit_cont_cls, &(session->target), 1116 {
1106 GNUNET_SYSERR); 1117 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1107 GNUNET_free(pm->msg); 1118 session->pending_message_tail, pm);
1108 GNUNET_free(pm);
1109
1110 if (session->pending_message_head == NULL)
1111 {
1112 sessionqueue_alt = sessionqueue;
1113 sessionqueue = sessionqueue->next;
1114 plugin->pendingsessions--;
1115 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1116 plugin->pending_Sessions_tail, sessionqueue_alt);
1117
1118 GNUNET_free(sessionqueue_alt);
1119 }
1120 }
1121 1119
1120 //call the cont func that it did not work
1121 if (pm->transmit_cont != NULL)
1122 pm->transmit_cont (pm->transmit_cont_cls, &(session->target),
1123 GNUNET_SYSERR);
1124 GNUNET_free (pm->msg);
1125 GNUNET_free (pm);
1126
1127 if (session->pending_message_head == NULL)
1128 {
1129 sessionqueue_alt = sessionqueue;
1130 sessionqueue = sessionqueue->next;
1131 plugin->pendingsessions--;
1132 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1133 plugin->pending_Sessions_tail,
1134 sessionqueue_alt);
1135
1136 GNUNET_free (sessionqueue_alt);
1137 }
1122 } 1138 }
1139
1140 }
1123 return NULL; 1141 return NULL;
1124} 1142}
1125 1143
@@ -1129,42 +1147,45 @@ get_next_queue_session(struct Plugin * plugin)
1129 * @param fm message to free 1147 * @param fm message to free
1130 */ 1148 */
1131static void 1149static void
1132free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm) 1150free_fragment_message (struct Plugin *plugin, struct FragmentMessage *fm)
1133{ 1151{
1134 struct Session * session = fm->session; 1152 struct Session *session = fm->session;
1135 struct MacEndpoint * endpoint = session->mac; 1153 struct MacEndpoint *endpoint = session->mac;
1136 struct FragmentMessage_queue * fmq; 1154 struct FragmentMessage_queue *fmq;
1137 struct FragmentMessage_queue * fmq_next; 1155 struct FragmentMessage_queue *fmq_next;
1138 1156
1139 if (fm != NULL) 1157 if (fm != NULL)
1158 {
1159 fmq = plugin->sending_messages_head;
1160 while (fmq != NULL)
1140 { 1161 {
1141 fmq = plugin->sending_messages_head; 1162 fmq_next = fmq->next;
1142 while (fmq != NULL) 1163 if (fmq->content == fm)
1143 { 1164 {
1144 fmq_next = fmq->next; 1165 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1145 if (fmq->content == fm) 1166 plugin->sending_messages_tail, fmq);
1146 { 1167 GNUNET_free (fmq);
1147 GNUNET_CONTAINER_DLL_remove(plugin->sending_messages_head,plugin->sending_messages_tail, fmq); 1168 }
1148 GNUNET_free(fmq); 1169 fmq = fmq_next;
1149 } 1170 }
1150 fmq = fmq_next;
1151 }
1152
1153 (session->mac->fragment_messages_out_count)--;
1154 session->fragment_messages_out_count--;
1155 plugin->pending_Fragment_Messages--;
1156 GNUNET_CONTAINER_DLL_remove(endpoint->sending_messages_head,endpoint->sending_messages_tail, fm);
1157 GNUNET_FRAGMENT_context_destroy(fm->fragcontext);
1158 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1159 GNUNET_SCHEDULER_cancel(fm->timeout_task);
1160 GNUNET_free(fm);
1161 1171
1162 queue_session(plugin, session); 1172 (session->mac->fragment_messages_out_count)--;
1173 session->fragment_messages_out_count--;
1174 plugin->pending_Fragment_Messages--;
1175 GNUNET_CONTAINER_DLL_remove (endpoint->sending_messages_head,
1176 endpoint->sending_messages_tail, fm);
1177 GNUNET_FRAGMENT_context_destroy (fm->fragcontext);
1178 if (fm->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1179 GNUNET_SCHEDULER_cancel (fm->timeout_task);
1180 GNUNET_free (fm);
1181
1182 queue_session (plugin, session);
1163#if DEBUG_wlan 1183#if DEBUG_wlan
1164 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1184 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1165 "Free pending fragment messages %p, session %p\n", fm, session); 1185 "Free pending fragment messages %p, session %p\n", fm,
1186 session);
1166#endif 1187#endif
1167 } 1188 }
1168} 1189}
1169 1190
1170/** 1191/**
@@ -1175,22 +1196,22 @@ free_fragment_message(struct Plugin * plugin, struct FragmentMessage * fm)
1175 * @return GNUNET_YES at success 1196 * @return GNUNET_YES at success
1176 */ 1197 */
1177static int 1198static int
1178getRadiotapHeader(struct Plugin * plugin, struct MacEndpoint * endpoint, 1199getRadiotapHeader (struct Plugin *plugin, struct MacEndpoint *endpoint,
1179 struct Radiotap_Send * header) 1200 struct Radiotap_Send *header)
1180{ 1201{
1181 1202
1182 if (endpoint != NULL) 1203 if (endpoint != NULL)
1183 { 1204 {
1184 header->rate = endpoint->rate; 1205 header->rate = endpoint->rate;
1185 header->tx_power = endpoint->tx_power; 1206 header->tx_power = endpoint->tx_power;
1186 header->antenna = endpoint->antenna; 1207 header->antenna = endpoint->antenna;
1187 } 1208 }
1188 else 1209 else
1189 { 1210 {
1190 header->rate = 255; 1211 header->rate = 255;
1191 header->tx_power = 0; 1212 header->tx_power = 0;
1192 header->antenna = 0; 1213 header->antenna = 0;
1193 } 1214 }
1194 1215
1195 return GNUNET_YES; 1216 return GNUNET_YES;
1196} 1217}
@@ -1203,50 +1224,52 @@ getRadiotapHeader(struct Plugin * plugin, struct MacEndpoint * endpoint,
1203 * @return GNUNET_YES if there was no error 1224 * @return GNUNET_YES if there was no error
1204 */ 1225 */
1205static int 1226static int
1206getWlanHeader(struct ieee80211_frame * Header, 1227getWlanHeader (struct ieee80211_frame *Header,
1207 const struct MacAddress * to_mac_addr, struct Plugin * plugin, 1228 const struct MacAddress *to_mac_addr, struct Plugin *plugin,
1208 unsigned int size) 1229 unsigned int size)
1209{ 1230{
1210 uint16_t * tmp16; 1231 uint16_t *tmp16;
1211 const int rate = 11000000; 1232 const int rate = 11000000;
1212 1233
1213 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA; 1234 Header->i_fc[0] = IEEE80211_FC0_TYPE_DATA;
1214 Header->i_fc[1] = 0x00; 1235 Header->i_fc[1] = 0x00;
1215 memcpy(&Header->i_addr3, &mac_bssid, sizeof(mac_bssid)); 1236 memcpy (&Header->i_addr3, &mac_bssid, sizeof (mac_bssid));
1216 memcpy(&Header->i_addr2, plugin->mac_address.mac, sizeof(plugin->mac_address)); 1237 memcpy (&Header->i_addr2, plugin->mac_address.mac,
1217 memcpy(&Header->i_addr1, to_mac_addr, sizeof(struct MacAddress)); 1238 sizeof (plugin->mac_address));
1239 memcpy (&Header->i_addr1, to_mac_addr, sizeof (struct MacAddress));
1218 1240
1219 tmp16 = (uint16_t*) Header->i_dur; 1241 tmp16 = (uint16_t *) Header->i_dur;
1220 *tmp16 = (uint16_t) htole16((size * 1000000) / rate + 290); 1242 *tmp16 = (uint16_t) htole16 ((size * 1000000) / rate + 290);
1221 1243
1222#if DEBUG_wlan_ip_udp_packets_on_air 1244#if DEBUG_wlan_ip_udp_packets_on_air
1223 uint crc = 0; 1245 uint crc = 0;
1224 uint16_t * x; 1246 uint16_t *x;
1225 int count; 1247 int count;
1226 Header->ip.ip_dst.s_addr = *((uint32_t*) &to_mac_addr->mac[2]); 1248
1227 Header->ip.ip_src.s_addr = *((uint32_t*) &plugin->mac_address.mac[2]); 1249 Header->ip.ip_dst.s_addr = *((uint32_t *) & to_mac_addr->mac[2]);
1250 Header->ip.ip_src.s_addr = *((uint32_t *) & plugin->mac_address.mac[2]);
1228 Header->ip.ip_v = 4; 1251 Header->ip.ip_v = 4;
1229 Header->ip.ip_hl = 5; 1252 Header->ip.ip_hl = 5;
1230 Header->ip.ip_p = 17; 1253 Header->ip.ip_p = 17;
1231 Header->ip.ip_ttl = 1; 1254 Header->ip.ip_ttl = 1;
1232 Header->ip.ip_len = htons(size + 8); 1255 Header->ip.ip_len = htons (size + 8);
1233 Header->ip.ip_sum = 0; 1256 Header->ip.ip_sum = 0;
1234 x =(uint16_t *) &Header->ip; 1257 x = (uint16_t *) & Header->ip;
1235 count = sizeof(struct iph); 1258 count = sizeof (struct iph);
1236 while (count > 1) 1259 while (count > 1)
1237 { 1260 {
1238 /* This is the inner loop */ 1261 /* This is the inner loop */
1239 crc += (unsigned short) * x++; 1262 crc += (unsigned short) *x++;
1240 count -= 2; 1263 count -= 2;
1241 } 1264 }
1242 /* Add left-over byte, if any */ 1265 /* Add left-over byte, if any */
1243 if( count > 0 ) 1266 if (count > 0)
1244 crc += * (unsigned char *) x; 1267 crc += *(unsigned char *) x;
1245 crc = (crc & 0xffff) + (crc >> 16); 1268 crc = (crc & 0xffff) + (crc >> 16);
1246 Header->ip.ip_sum = htons(~ (unsigned short) crc); 1269 Header->ip.ip_sum = htons (~(unsigned short) crc);
1247 Header->llc[0] = 6; 1270 Header->llc[0] = 6;
1248 Header->llc[1] = 6; 1271 Header->llc[1] = 6;
1249 Header->udp.len = htons(size - sizeof(struct ieee80211_frame)); 1272 Header->udp.len = htons (size - sizeof (struct ieee80211_frame));
1250 1273
1251#endif 1274#endif
1252 1275
@@ -1263,10 +1286,10 @@ getWlanHeader(struct ieee80211_frame * Header,
1263 */ 1286 */
1264 1287
1265uint32_t 1288uint32_t
1266getcrc32(const char *msgbuf, size_t msgbuf_size) 1289getcrc32 (const char *msgbuf, size_t msgbuf_size)
1267{ 1290{
1268 1291
1269 return GNUNET_CRYPTO_crc32_n(msgbuf, msgbuf_size);; 1292 return GNUNET_CRYPTO_crc32_n (msgbuf, msgbuf_size);;
1270} 1293}
1271 1294
1272/** 1295/**
@@ -1279,7 +1302,7 @@ getcrc32(const char *msgbuf, size_t msgbuf_size)
1279 */ 1302 */
1280 1303
1281uint16_t 1304uint16_t
1282getcrc16(const char *msgbuf, size_t msgbuf_size) 1305getcrc16 (const char *msgbuf, size_t msgbuf_size)
1283{ 1306{
1284 //TODO calc some crc 1307 //TODO calc some crc
1285 return 0; 1308 return 0;
@@ -1292,46 +1315,46 @@ getcrc16(const char *msgbuf, size_t msgbuf_size)
1292 */ 1315 */
1293 1316
1294void 1317void
1295add_message_for_send(void *cls, const struct GNUNET_MessageHeader *hdr) 1318add_message_for_send (void *cls, const struct GNUNET_MessageHeader *hdr)
1296{ 1319{
1297 1320
1298 struct FragmentMessage * fm = cls; 1321 struct FragmentMessage *fm = cls;
1299 struct FragmentMessage_queue * fmqueue; 1322 struct FragmentMessage_queue *fmqueue;
1300 1323
1301 GNUNET_assert(cls != NULL); 1324 GNUNET_assert (cls != NULL);
1302 GNUNET_assert(fm->frag == NULL); 1325 GNUNET_assert (fm->frag == NULL);
1303 struct MacEndpoint * endpoint = fm->session->mac; 1326 struct MacEndpoint *endpoint = fm->session->mac;
1304 struct Plugin * plugin = endpoint->plugin; 1327 struct Plugin *plugin = endpoint->plugin;
1305 struct GNUNET_MessageHeader * msgheader; 1328 struct GNUNET_MessageHeader *msgheader;
1306 struct GNUNET_MessageHeader * msgheader2; 1329 struct GNUNET_MessageHeader *msgheader2;
1307 uint16_t size; 1330 uint16_t size;
1308 1331
1309#if DEBUG_wlan_retransmission 1332#if DEBUG_wlan_retransmission
1310 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1333 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1311 "Adding fragment of message %p to send, session %p, endpoint %p\n", fm, 1334 "Adding fragment of message %p to send, session %p, endpoint %p\n",
1312 fm->session, endpoint); 1335 fm, fm->session, endpoint);
1313#endif 1336#endif
1314 1337
1315 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1338 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1316 + sizeof(struct ieee80211_frame) + ntohs(hdr->size); 1339 + sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1317 fm->frag = GNUNET_malloc(size); 1340 fm->frag = GNUNET_malloc (size);
1318 fm->size = size; 1341 fm->size = size;
1319 1342
1320 msgheader = (struct GNUNET_MessageHeader *) fm->frag; 1343 msgheader = (struct GNUNET_MessageHeader *) fm->frag;
1321 msgheader->size = htons(size); 1344 msgheader->size = htons (size);
1322 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1345 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1323 1346
1324 fm->radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1347 fm->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1325 fm->ieeewlanheader = (struct ieee80211_frame*) &fm->radioHeader[1]; 1348 fm->ieeewlanheader = (struct ieee80211_frame *) &fm->radioHeader[1];
1326 msgheader2 = (struct GNUNET_MessageHeader*) &fm->ieeewlanheader[1]; 1349 msgheader2 = (struct GNUNET_MessageHeader *) &fm->ieeewlanheader[1];
1327 memcpy(msgheader2, hdr, ntohs(hdr->size)); 1350 memcpy (msgheader2, hdr, ntohs (hdr->size));
1328 1351
1329 fmqueue = GNUNET_malloc(sizeof(struct FragmentMessage_queue)); 1352 fmqueue = GNUNET_malloc (sizeof (struct FragmentMessage_queue));
1330 fmqueue->content = fm; 1353 fmqueue->content = fm;
1331 1354
1332 GNUNET_CONTAINER_DLL_insert_tail(plugin->sending_messages_head, 1355 GNUNET_CONTAINER_DLL_insert_tail (plugin->sending_messages_head,
1333 plugin->sending_messages_tail, fmqueue); 1356 plugin->sending_messages_tail, fmqueue);
1334 set_next_send(plugin); 1357 set_next_send (plugin);
1335} 1358}
1336 1359
1337/** 1360/**
@@ -1339,60 +1362,63 @@ add_message_for_send(void *cls, const struct GNUNET_MessageHeader *hdr)
1339 * @param plugin pointer to the plugin struct 1362 * @param plugin pointer to the plugin struct
1340 */ 1363 */
1341static void 1364static void
1342send_hello_beacon(struct Plugin * plugin) 1365send_hello_beacon (struct Plugin *plugin)
1343{ 1366{
1344 1367
1345#if DEBUG_wlan 1368#if DEBUG_wlan
1346 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Sending hello beacon\n"); 1369 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1370 "Sending hello beacon\n");
1347#endif 1371#endif
1348 1372
1349 uint16_t size; 1373 uint16_t size;
1350 ssize_t bytes; 1374 ssize_t bytes;
1351 uint16_t hallo_size; 1375 uint16_t hallo_size;
1352 struct GNUNET_MessageHeader * msgheader; 1376 struct GNUNET_MessageHeader *msgheader;
1353 struct ieee80211_frame * ieeewlanheader; 1377 struct ieee80211_frame *ieeewlanheader;
1354 struct Radiotap_Send * radioHeader; 1378 struct Radiotap_Send *radioHeader;
1355 struct GNUNET_MessageHeader * msgheader2; 1379 struct GNUNET_MessageHeader *msgheader2;
1356 const struct GNUNET_MessageHeader *hello; 1380 const struct GNUNET_MessageHeader *hello;
1357 1381
1358 hello = plugin->env->get_our_hello (); 1382 hello = plugin->env->get_our_hello ();
1359 hallo_size = GNUNET_HELLO_size((struct GNUNET_HELLO_Message*)hello); 1383 hallo_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
1360 GNUNET_assert(sizeof(struct WlanHeader) + hallo_size <= WLAN_MTU); 1384 GNUNET_assert (sizeof (struct WlanHeader) + hallo_size <= WLAN_MTU);
1361 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1385 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1362 + sizeof(struct ieee80211_frame) + sizeof(struct GNUNET_MessageHeader) 1386 + sizeof (struct ieee80211_frame) + sizeof (struct GNUNET_MessageHeader)
1363 + hallo_size; 1387 + hallo_size;
1364 1388
1365 msgheader = GNUNET_malloc(size); 1389 msgheader = GNUNET_malloc (size);
1366 msgheader->size = htons(size); 1390 msgheader->size = htons (size);
1367 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1391 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1368 1392
1369 radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1393 radioHeader = (struct Radiotap_Send *) &msgheader[1];
1370 getRadiotapHeader(plugin, NULL, radioHeader); 1394 getRadiotapHeader (plugin, NULL, radioHeader);
1371 ieeewlanheader = (struct ieee80211_frame*) &radioHeader[1]; 1395 ieeewlanheader = (struct ieee80211_frame *) &radioHeader[1];
1372 getWlanHeader(ieeewlanheader, &bc_all_mac, plugin, size); 1396 getWlanHeader (ieeewlanheader, &bc_all_mac, plugin, size);
1373 1397
1374 msgheader2 = (struct GNUNET_MessageHeader*) &ieeewlanheader[1]; 1398 msgheader2 = (struct GNUNET_MessageHeader *) &ieeewlanheader[1];
1375 msgheader2->size = htons(GNUNET_HELLO_size((struct GNUNET_HELLO_Message*)hello) 1399 msgheader2->size =
1376 + sizeof(struct GNUNET_MessageHeader)); 1400 htons (GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello) +
1401 sizeof (struct GNUNET_MessageHeader));
1377 1402
1378 msgheader2->type = htons(GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT); 1403 msgheader2->type = htons (GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT);
1379 memcpy(&msgheader2[1], hello, hallo_size); 1404 memcpy (&msgheader2[1], hello, hallo_size);
1380 1405
1381 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, msgheader, size); 1406 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, msgheader, size);
1382 1407
1383 if (bytes == GNUNET_SYSERR) 1408 if (bytes == GNUNET_SYSERR)
1384 { 1409 {
1385 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1410 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1386 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 1411 _
1387 errno, strerror(errno)); 1412 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1413 errno, strerror (errno));
1388 1414
1389 } 1415 }
1390 GNUNET_assert(bytes != GNUNET_SYSERR); 1416 GNUNET_assert (bytes != GNUNET_SYSERR);
1391 GNUNET_assert(bytes == size); 1417 GNUNET_assert (bytes == size);
1392 GNUNET_free(msgheader); 1418 GNUNET_free (msgheader);
1393 1419
1394 set_next_beacon_time(plugin); 1420 set_next_beacon_time (plugin);
1395 set_next_send(plugin); 1421 set_next_send (plugin);
1396} 1422}
1397 1423
1398/** 1424/**
@@ -1404,50 +1430,50 @@ send_hello_beacon(struct Plugin * plugin)
1404 */ 1430 */
1405 1431
1406static void 1432static void
1407add_ack_for_send(void *cls, uint32_t msg_id, 1433add_ack_for_send (void *cls, uint32_t msg_id,
1408 const struct GNUNET_MessageHeader *hdr) 1434 const struct GNUNET_MessageHeader *hdr)
1409{ 1435{
1410 1436
1411 struct AckSendQueue * ack; 1437 struct AckSendQueue *ack;
1412 1438
1413 GNUNET_assert(cls != NULL); 1439 GNUNET_assert (cls != NULL);
1414 struct MacEndpoint * endpoint = cls; 1440 struct MacEndpoint *endpoint = cls;
1415 struct Plugin * plugin = endpoint->plugin; 1441 struct Plugin *plugin = endpoint->plugin;
1416 struct GNUNET_MessageHeader * msgheader; 1442 struct GNUNET_MessageHeader *msgheader;
1417 struct GNUNET_MessageHeader * msgheader2; 1443 struct GNUNET_MessageHeader *msgheader2;
1418 uint16_t size; 1444 uint16_t size;
1419 1445
1420 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1446 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1421 + sizeof(struct ieee80211_frame) + ntohs(hdr->size) 1447 + sizeof (struct ieee80211_frame) + ntohs (hdr->size)
1422 + sizeof(struct AckSendQueue); 1448 + sizeof (struct AckSendQueue);
1423 1449
1424 ack = GNUNET_malloc(size); 1450 ack = GNUNET_malloc (size);
1425 ack->message_id = msg_id; 1451 ack->message_id = msg_id;
1426 ack->endpoint = endpoint; 1452 ack->endpoint = endpoint;
1427 1453
1428 size = sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_Send) 1454 size = sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_Send)
1429 + sizeof(struct ieee80211_frame) + ntohs(hdr->size); 1455 + sizeof (struct ieee80211_frame) + ntohs (hdr->size);
1430 1456
1431 msgheader = (struct GNUNET_MessageHeader *) &ack[1]; 1457 msgheader = (struct GNUNET_MessageHeader *) &ack[1];
1432 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1]; 1458 ack->hdr = (struct GNUNET_MessageHeader *) &ack[1];
1433 msgheader->size = htons(size); 1459 msgheader->size = htons (size);
1434 msgheader->type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 1460 msgheader->type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
1435 1461
1436 ack->radioHeader = (struct Radiotap_Send*) &msgheader[1]; 1462 ack->radioHeader = (struct Radiotap_Send *) &msgheader[1];
1437 ack->ieeewlanheader = (struct ieee80211_frame*) &(ack->radioHeader)[1]; 1463 ack->ieeewlanheader = (struct ieee80211_frame *) &(ack->radioHeader)[1];
1438 msgheader2 = (struct GNUNET_MessageHeader*) &(ack->ieeewlanheader)[1]; 1464 msgheader2 = (struct GNUNET_MessageHeader *) &(ack->ieeewlanheader)[1];
1439 memcpy(msgheader2, hdr, ntohs(hdr->size)); 1465 memcpy (msgheader2, hdr, ntohs (hdr->size));
1440 1466
1441 GNUNET_CONTAINER_DLL_insert_tail(plugin->ack_send_queue_head, 1467 GNUNET_CONTAINER_DLL_insert_tail (plugin->ack_send_queue_head,
1442 plugin->ack_send_queue_tail, ack); 1468 plugin->ack_send_queue_tail, ack);
1443 1469
1444#if DEBUG_wlan_retransmission 1470#if DEBUG_wlan_retransmission
1445 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1471 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1446 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n", 1472 "Adding ack with message id %u to send, AckSendQueue %p, endpoint %p\n",
1447 msg_id, ack, endpoint); 1473 msg_id, ack, endpoint);
1448#endif 1474#endif
1449 1475
1450 set_next_send(plugin); 1476 set_next_send (plugin);
1451} 1477}
1452 1478
1453/** 1479/**
@@ -1457,14 +1483,17 @@ add_ack_for_send(void *cls, uint32_t msg_id,
1457 */ 1483 */
1458static void 1484static void
1459fragmentmessage_timeout (void *cls, 1485fragmentmessage_timeout (void *cls,
1460 const struct GNUNET_SCHEDULER_TaskContext *tc){ 1486 const struct GNUNET_SCHEDULER_TaskContext *tc)
1461 struct FragmentMessage * fm = cls; 1487{
1462 GNUNET_assert(fm != NULL); 1488 struct FragmentMessage *fm = cls;
1489
1490 GNUNET_assert (fm != NULL);
1463 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1491 fm->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1464 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){ 1492 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
1465 return; 1493 {
1494 return;
1466 } 1495 }
1467 free_fragment_message(fm->session->mac->plugin,fm); 1496 free_fragment_message (fm->session->mac->plugin, fm);
1468} 1497}
1469 1498
1470/** 1499/**
@@ -1474,66 +1503,75 @@ fragmentmessage_timeout (void *cls,
1474 */ 1503 */
1475 1504
1476static void 1505static void
1477check_fragment_queue(struct Plugin * plugin) 1506check_fragment_queue (struct Plugin *plugin)
1478{ 1507{
1479 struct Session * session; 1508 struct Session *session;
1480 struct FragmentMessage * fm; 1509 struct FragmentMessage *fm;
1481 struct GNUNET_PeerIdentity pid; 1510 struct GNUNET_PeerIdentity pid;
1482 1511
1483 struct PendingMessage * pm; 1512 struct PendingMessage *pm;
1484 1513
1485 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE) 1514 if (plugin->pending_Fragment_Messages < FRAGMENT_QUEUE_SIZE)
1515 {
1516 session = get_next_queue_session (plugin);
1517 if (session != NULL)
1486 { 1518 {
1487 session = get_next_queue_session(plugin); 1519 pm = session->pending_message_head;
1488 if (session != NULL) 1520 GNUNET_CONTAINER_DLL_remove (session->pending_message_head,
1489 { 1521 session->pending_message_tail, pm);
1490 pm = session->pending_message_head; 1522 session->mac->fragment_messages_out_count++;
1491 GNUNET_CONTAINER_DLL_remove(session->pending_message_head, session->pending_message_tail, pm); 1523 session->fragment_messages_out_count++;
1492 session->mac->fragment_messages_out_count++; 1524 plugin->pending_Fragment_Messages++;
1493 session->fragment_messages_out_count++; 1525 GNUNET_assert (pm != NULL);
1494 plugin->pending_Fragment_Messages++; 1526
1495 GNUNET_assert(pm != NULL); 1527 fm = GNUNET_malloc (sizeof (struct FragmentMessage));
1496 1528 fm->session = session;
1497 fm = GNUNET_malloc(sizeof(struct FragmentMessage)); 1529 fm->timeout.abs_value = pm->timeout.abs_value;
1498 fm->session = session; 1530 fm->frag = NULL;
1499 fm->timeout.abs_value = pm->timeout.abs_value; 1531 fm->fragcontext = GNUNET_FRAGMENT_context_create (plugin->env->stats,
1500 fm->frag = NULL; 1532 WLAN_MTU,
1501 fm->fragcontext = GNUNET_FRAGMENT_context_create(plugin->env->stats, 1533 &plugin->tracker,
1502 WLAN_MTU, &plugin->tracker, GNUNET_TIME_UNIT_SECONDS, 1534 GNUNET_TIME_UNIT_SECONDS,
1503 &(pm->msg->header), &add_message_for_send, 1535 &(pm->msg->header),
1504 fm); 1536 &add_message_for_send,
1505 fm->timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_absolute_get_remaining(fm->timeout),fragmentmessage_timeout,fm); 1537 fm);
1506 GNUNET_CONTAINER_DLL_insert_tail(session->mac->sending_messages_head,session->mac->sending_messages_tail,fm); 1538 fm->timeout_task =
1507 1539 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
1508 if (pm->transmit_cont != NULL) 1540 (fm->timeout), fragmentmessage_timeout,
1509 { 1541 fm);
1510 pid = session->target; 1542 GNUNET_CONTAINER_DLL_insert_tail (session->mac->sending_messages_head,
1511 pm->transmit_cont(pm->transmit_cont_cls, &pid, GNUNET_OK); 1543 session->mac->sending_messages_tail,
1544 fm);
1545
1546 if (pm->transmit_cont != NULL)
1547 {
1548 pid = session->target;
1549 pm->transmit_cont (pm->transmit_cont_cls, &pid, GNUNET_OK);
1512#if DEBUG_wlan 1550#if DEBUG_wlan
1513 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1551 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1514 "called pm->transmit_cont for %p\n", session); 1552 "called pm->transmit_cont for %p\n", session);
1515#endif 1553#endif
1516 } 1554 }
1517 else 1555 else
1518 { 1556 {
1519#if DEBUG_wlan 1557#if DEBUG_wlan
1520 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1558 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1521 "no pm->transmit_cont for %p\n", session); 1559 "no pm->transmit_cont for %p\n", session);
1522#endif 1560#endif
1523 } 1561 }
1524 GNUNET_free(pm); 1562 GNUNET_free (pm);
1525 1563
1526 if (session->pending_message_head != NULL) 1564 if (session->pending_message_head != NULL)
1527 { 1565 {
1528 //requeue session 1566 //requeue session
1529 queue_session(plugin, session); 1567 queue_session (plugin, session);
1530 } 1568 }
1531 1569
1532 }
1533 } 1570 }
1571 }
1534 1572
1535 //check if timeout changed 1573 //check if timeout changed
1536 set_next_send(plugin); 1574 set_next_send (plugin);
1537} 1575}
1538 1576
1539/** 1577/**
@@ -1542,34 +1580,35 @@ check_fragment_queue(struct Plugin * plugin)
1542 * @param ack pointer to the ack to send 1580 * @param ack pointer to the ack to send
1543 */ 1581 */
1544static void 1582static void
1545send_ack(struct Plugin * plugin, struct AckSendQueue * ack) 1583send_ack (struct Plugin *plugin, struct AckSendQueue *ack)
1546{ 1584{
1547 1585
1548 ssize_t bytes; 1586 ssize_t bytes;
1549 1587
1550#if DEBUG_wlan 1588#if DEBUG_wlan
1551 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1589 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1552 "Sending ack for message_id %u for mac endpoint %p, size %u\n", 1590 "Sending ack for message_id %u for mac endpoint %p, size %u\n",
1553 ack->message_id, ack->endpoint, 1591 ack->message_id, ack->endpoint,
1554 ntohs(ack->hdr->size) - sizeof(struct Radiotap_Send)); 1592 ntohs (ack->hdr->size) - sizeof (struct Radiotap_Send));
1555#endif 1593#endif
1556 1594
1557 getRadiotapHeader(plugin, ack->endpoint, ack->radioHeader); 1595 getRadiotapHeader (plugin, ack->endpoint, ack->radioHeader);
1558 getWlanHeader(ack->ieeewlanheader, &ack->endpoint->addr, plugin, 1596 getWlanHeader (ack->ieeewlanheader, &ack->endpoint->addr, plugin,
1559 ntohs(ack->hdr->size)); 1597 ntohs (ack->hdr->size));
1560 1598
1561 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, ack->hdr, 1599 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, ack->hdr,
1562 ntohs(ack->hdr->size)); 1600 ntohs (ack->hdr->size));
1563 if (bytes == GNUNET_SYSERR) 1601 if (bytes == GNUNET_SYSERR)
1564 { 1602 {
1565 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1603 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1566 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 1604 _
1567 errno, strerror(errno)); 1605 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1606 errno, strerror (errno));
1568 1607
1569 } 1608 }
1570 GNUNET_assert(bytes != GNUNET_SYSERR); 1609 GNUNET_assert (bytes != GNUNET_SYSERR);
1571 GNUNET_assert(bytes == ntohs(ack->hdr->size)); 1610 GNUNET_assert (bytes == ntohs (ack->hdr->size));
1572 set_next_send(plugin); 1611 set_next_send (plugin);
1573} 1612}
1574 1613
1575/** 1614/**
@@ -1578,39 +1617,40 @@ send_ack(struct Plugin * plugin, struct AckSendQueue * ack)
1578 * @param tc TaskContext 1617 * @param tc TaskContext
1579 */ 1618 */
1580static void 1619static void
1581finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1620finish_sending (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1582{ 1621{
1583 struct Finish_send * finish = cls; 1622 struct Finish_send *finish = cls;
1584 struct Plugin * plugin; 1623 struct Plugin *plugin;
1585 ssize_t bytes; 1624 ssize_t bytes;
1586 1625
1587 plugin = finish->plugin; 1626 plugin = finish->plugin;
1588 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 1627 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1589 1628
1590 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) 1629 if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason))
1591 { 1630 {
1592 GNUNET_free (finish->msgstart); 1631 GNUNET_free (finish->msgstart);
1593 GNUNET_free (finish); 1632 GNUNET_free (finish);
1594 return; 1633 return;
1595 } 1634 }
1596 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, 1635 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle,
1597 finish->msgheader, finish->size); 1636 finish->msgheader, finish->size);
1598 GNUNET_assert (bytes != GNUNET_SYSERR); 1637 GNUNET_assert (bytes != GNUNET_SYSERR);
1599 1638
1600 if (bytes != finish->size) 1639 if (bytes != finish->size)
1601 { 1640 {
1602 finish->msgheader = finish->msgheader + bytes; 1641 finish->msgheader = finish->msgheader + bytes;
1603 finish->size = finish->size - bytes; 1642 finish->size = finish->size - bytes;
1604 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 1643 plugin->server_write_task =
1605 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 1644 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1606 &finish_sending, finish); 1645 plugin->server_stdin_handle,
1607 } 1646 &finish_sending, finish);
1647 }
1608 else 1648 else
1609 { 1649 {
1610 GNUNET_free(finish->msgstart); 1650 GNUNET_free (finish->msgstart);
1611 GNUNET_free(finish); 1651 GNUNET_free (finish);
1612 set_next_send(plugin); 1652 set_next_send (plugin);
1613 } 1653 }
1614} 1654}
1615 1655
1616/** 1656/**
@@ -1620,96 +1660,99 @@ finish_sending(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1620 * @param tc GNUNET_SCHEDULER_TaskContext 1660 * @param tc GNUNET_SCHEDULER_TaskContext
1621 */ 1661 */
1622static void 1662static void
1623do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 1663do_transmit (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1624{ 1664{
1625 struct Plugin * plugin = cls; 1665 struct Plugin *plugin = cls;
1626 1666
1627 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 1667 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
1628 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1668 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1629 return; 1669 return;
1630 1670
1631 struct Session * session; 1671 struct Session *session;
1632 struct FragmentMessage * fm; 1672 struct FragmentMessage *fm;
1633 struct Finish_send * finish; 1673 struct Finish_send *finish;
1634 struct FragmentMessage_queue * fmq; 1674 struct FragmentMessage_queue *fmq;
1635 struct AckSendQueue * ack; 1675 struct AckSendQueue *ack;
1636 ssize_t bytes; 1676 ssize_t bytes;
1637 1677
1638 if (plugin->ack_send_queue_head != NULL) 1678 if (plugin->ack_send_queue_head != NULL)
1639 { 1679 {
1640 ack = plugin->ack_send_queue_head; 1680 ack = plugin->ack_send_queue_head;
1641 GNUNET_CONTAINER_DLL_remove(plugin->ack_send_queue_head, 1681 GNUNET_CONTAINER_DLL_remove (plugin->ack_send_queue_head,
1642 plugin->ack_send_queue_tail, ack); 1682 plugin->ack_send_queue_tail, ack);
1643 send_ack(plugin, ack); 1683 send_ack (plugin, ack);
1644 GNUNET_free(ack); 1684 GNUNET_free (ack);
1645 return; 1685 return;
1646 } 1686 }
1647 1687
1648 //test if a "hello-beacon" has to be send 1688 //test if a "hello-beacon" has to be send
1649 if (GNUNET_TIME_absolute_get_remaining(plugin->beacon_time).rel_value == 0) 1689 if (GNUNET_TIME_absolute_get_remaining (plugin->beacon_time).rel_value == 0)
1650 { 1690 {
1651 send_hello_beacon(plugin); 1691 send_hello_beacon (plugin);
1652 return; 1692 return;
1653 } 1693 }
1654 1694
1655 if (plugin->sending_messages_head != NULL) 1695 if (plugin->sending_messages_head != NULL)
1656 { 1696 {
1657 fmq = plugin->sending_messages_head; 1697 fmq = plugin->sending_messages_head;
1658 fm = fmq->content; 1698 fm = fmq->content;
1659 GNUNET_CONTAINER_DLL_remove(plugin->sending_messages_head,plugin->sending_messages_tail,fmq); 1699 GNUNET_CONTAINER_DLL_remove (plugin->sending_messages_head,
1660 GNUNET_free(fmq); 1700 plugin->sending_messages_tail, fmq);
1701 GNUNET_free (fmq);
1661 1702
1662 session = fm->session; 1703 session = fm->session;
1663 GNUNET_assert(session != NULL); 1704 GNUNET_assert (session != NULL);
1664 1705
1665#if DEBUG_wlan 1706#if DEBUG_wlan
1666 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG,PLUGIN_LOG_NAME, 1707 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1667 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n", 1708 "Sending GNUNET_MESSAGE_TYPE_WLAN_FRAGMENT for fragment message %p, size: %u\n",
1668 fm, fm->size); 1709 fm, fm->size);
1669#endif 1710#endif
1670 1711
1671 getRadiotapHeader(plugin, session->mac, fm->radioHeader); 1712 getRadiotapHeader (plugin, session->mac, fm->radioHeader);
1672 getWlanHeader(fm->ieeewlanheader, &(fm->session->mac->addr), plugin, 1713 getWlanHeader (fm->ieeewlanheader, &(fm->session->mac->addr), plugin,
1673 fm->size); 1714 fm->size);
1674 1715
1675 bytes = GNUNET_DISK_file_write(plugin->server_stdin_handle, fm->frag, 1716 bytes = GNUNET_DISK_file_write (plugin->server_stdin_handle, fm->frag,
1676 fm->size); 1717 fm->size);
1677 if (bytes == GNUNET_SYSERR) 1718 if (bytes == GNUNET_SYSERR)
1678 { 1719 {
1679 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1720 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1680 _("Error writing to wlan healper. errno == %d, ERROR: %s\n"), 1721 _
1681 errno, strerror(errno)); 1722 ("Error writing to wlan healper. errno == %d, ERROR: %s\n"),
1723 errno, strerror (errno));
1682 1724
1683 } 1725 }
1684 GNUNET_assert(bytes != GNUNET_SYSERR); 1726 GNUNET_assert (bytes != GNUNET_SYSERR);
1685 1727
1686 if (bytes != fm->size) 1728 if (bytes != fm->size)
1687 { 1729 {
1688 finish = GNUNET_malloc(sizeof( struct Finish_send)); 1730 finish = GNUNET_malloc (sizeof (struct Finish_send));
1689 finish->plugin = plugin; 1731 finish->plugin = plugin;
1690 finish->msgheader = fm->frag + bytes; 1732 finish->msgheader = fm->frag + bytes;
1691 finish->size = fm->size - bytes; 1733 finish->size = fm->size - bytes;
1692 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag; 1734 finish->msgstart = (struct GNUNET_MessageHeader *) fm->frag;
1693 1735
1694 GNUNET_assert(plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK); 1736 GNUNET_assert (plugin->server_write_task == GNUNET_SCHEDULER_NO_TASK);
1695 1737
1696 plugin->server_write_task = GNUNET_SCHEDULER_add_write_file( 1738 plugin->server_write_task =
1697 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdin_handle, 1739 GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
1698 &finish_sending, finish); 1740 plugin->server_stdin_handle,
1699 fm->frag = NULL; 1741 &finish_sending, finish);
1700 } 1742 fm->frag = NULL;
1701 else 1743 }
1702 { 1744 else
1703 GNUNET_free(fm->frag); 1745 {
1704 fm->frag = NULL; 1746 GNUNET_free (fm->frag);
1705 set_next_send(plugin); 1747 fm->frag = NULL;
1706 } 1748 set_next_send (plugin);
1707 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
1708 return;
1709 } 1749 }
1750 GNUNET_FRAGMENT_context_transmission_done (fm->fragcontext);
1751 return;
1752 }
1710 1753
1711 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, 1754 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
1712 "do_transmit did nothing, should not happen!\n"); 1755 "do_transmit did nothing, should not happen!\n");
1713} 1756}
1714 1757
1715/** 1758/**
@@ -1725,21 +1768,21 @@ do_transmit(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1725 * and transport 1768 * and transport
1726 */ 1769 */
1727static int 1770static int
1728wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen) 1771wlan_plugin_address_suggested (void *cls, const void *addr, size_t addrlen)
1729{ 1772{
1730 //struct Plugin *plugin = cls; 1773 //struct Plugin *plugin = cls;
1731 1774
1732 /* check if the address is plausible; if so, 1775 /* check if the address is plausible; if so,
1733 add it to our list! */ 1776 * add it to our list! */
1734 1777
1735 GNUNET_assert(cls !=NULL); 1778 GNUNET_assert (cls != NULL);
1736 //FIXME mitm is not checked 1779 //FIXME mitm is not checked
1737 //Mac Address has 6 bytes 1780 //Mac Address has 6 bytes
1738 if (addrlen == 6) 1781 if (addrlen == 6)
1739 { 1782 {
1740 /* TODO check for bad addresses like multicast, broadcast, etc */ 1783 /* TODO check for bad addresses like multicast, broadcast, etc */
1741 return GNUNET_OK; 1784 return GNUNET_OK;
1742 } 1785 }
1743 1786
1744 return GNUNET_SYSERR; 1787 return GNUNET_SYSERR;
1745} 1788}
@@ -1771,33 +1814,33 @@ wlan_plugin_address_suggested(void *cls, const void *addr, size_t addrlen)
1771 * and does NOT mean that the message was not transmitted (DV) 1814 * and does NOT mean that the message was not transmitted (DV)
1772 */ 1815 */
1773static ssize_t 1816static ssize_t
1774wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target, 1817wlan_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target,
1775 const char *msgbuf, size_t msgbuf_size, unsigned int priority, 1818 const char *msgbuf, size_t msgbuf_size, unsigned int priority,
1776 struct GNUNET_TIME_Relative timeout, struct Session *session, 1819 struct GNUNET_TIME_Relative timeout, struct Session *session,
1777 const void *addr, size_t addrlen, int force_address, 1820 const void *addr, size_t addrlen, int force_address,
1778 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 1821 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
1779{ 1822{
1780 struct Plugin * plugin = cls; 1823 struct Plugin *plugin = cls;
1781 struct PendingMessage * newmsg; 1824 struct PendingMessage *newmsg;
1782 struct WlanHeader * wlanheader; 1825 struct WlanHeader *wlanheader;
1783 1826
1784 //check if msglen > 0 1827 //check if msglen > 0
1785 GNUNET_assert(msgbuf_size > 0); 1828 GNUNET_assert (msgbuf_size > 0);
1786 1829
1787 //get session if needed 1830 //get session if needed
1788 if (session == NULL) 1831 if (session == NULL)
1832 {
1833 if (wlan_plugin_address_suggested (plugin, addr, addrlen) == GNUNET_OK)
1789 { 1834 {
1790 if (wlan_plugin_address_suggested(plugin, addr, addrlen) == GNUNET_OK) 1835 session = get_session (plugin, addr, target);
1791 { 1836 }
1792 session = get_session(plugin, addr, target); 1837 else
1793 } 1838 {
1794 else 1839 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1795 { 1840 _("Wlan Address len %d is wrong\n"), addrlen);
1796 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1841 return -1;
1797 _("Wlan Address len %d is wrong\n"), addrlen);
1798 return -1;
1799 }
1800 } 1842 }
1843 }
1801 1844
1802 //queue message: 1845 //queue message:
1803 1846
@@ -1805,50 +1848,53 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1805 //test if there is no other message in the "queue" 1848 //test if there is no other message in the "queue"
1806 //FIXME: to many send requests 1849 //FIXME: to many send requests
1807 if (session->pending_message_head != NULL) 1850 if (session->pending_message_head != NULL)
1808 { 1851 {
1809 newmsg = session->pending_message_head; 1852 newmsg = session->pending_message_head;
1810 GNUNET_log_from(GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME, 1853 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, PLUGIN_LOG_NAME,
1811 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages for this mac connection %u\n", 1854 "wlan_plugin_send: a pending message is already in the queue for this client\n remaining time to send this message is %u, queued fragment messages for this mac connection %u\n",
1812 GNUNET_TIME_absolute_get_remaining(newmsg->timeout).rel_value, 1855 GNUNET_TIME_absolute_get_remaining (newmsg->
1813 session->mac->fragment_messages_out_count); 1856 timeout).rel_value,
1814 } 1857 session->mac->fragment_messages_out_count);
1858 }
1815 1859
1816 newmsg = GNUNET_malloc(sizeof(struct PendingMessage)); 1860 newmsg = GNUNET_malloc (sizeof (struct PendingMessage));
1817 newmsg->msg = GNUNET_malloc(msgbuf_size + sizeof(struct WlanHeader)); 1861 newmsg->msg = GNUNET_malloc (msgbuf_size + sizeof (struct WlanHeader));
1818 wlanheader = newmsg->msg; 1862 wlanheader = newmsg->msg;
1819 //copy msg to buffer, not fragmented / segmented yet, but with message header 1863 //copy msg to buffer, not fragmented / segmented yet, but with message header
1820 wlanheader->header.size = htons(msgbuf_size + sizeof(struct WlanHeader)); 1864 wlanheader->header.size = htons (msgbuf_size + sizeof (struct WlanHeader));
1821 wlanheader->header.type = htons(GNUNET_MESSAGE_TYPE_WLAN_DATA); 1865 wlanheader->header.type = htons (GNUNET_MESSAGE_TYPE_WLAN_DATA);
1822 memcpy(&(wlanheader->target), target, sizeof(struct GNUNET_PeerIdentity)); 1866 memcpy (&(wlanheader->target), target, sizeof (struct GNUNET_PeerIdentity));
1823 memcpy(&(wlanheader->source), plugin->env->my_identity, 1867 memcpy (&(wlanheader->source), plugin->env->my_identity,
1824 sizeof(struct GNUNET_PeerIdentity)); 1868 sizeof (struct GNUNET_PeerIdentity));
1825 wlanheader->crc = 0; 1869 wlanheader->crc = 0;
1826 memcpy(&wlanheader[1], msgbuf, msgbuf_size); 1870 memcpy (&wlanheader[1], msgbuf, msgbuf_size);
1827 wlanheader->crc = htonl( 1871 wlanheader->crc =
1828 getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader))); 1872 htonl (getcrc32
1873 ((char *) wlanheader, msgbuf_size + sizeof (struct WlanHeader)));
1829 //GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc); 1874 //GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, "Wlan message Header crc: %u, %u\n",getcrc32((char*) wlanheader, msgbuf_size + sizeof(struct WlanHeader)), wlanheader->crc);
1830 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader)); 1875 //hexdump(newmsg->msg, msgbuf_size + sizeof(struct WlanHeader));
1831 1876
1832 newmsg->transmit_cont = cont; 1877 newmsg->transmit_cont = cont;
1833 newmsg->transmit_cont_cls = cont_cls; 1878 newmsg->transmit_cont_cls = cont_cls;
1834 newmsg->timeout = GNUNET_TIME_relative_to_absolute(timeout); 1879 newmsg->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1835 1880
1836 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500; 1881 newmsg->timeout.abs_value = newmsg->timeout.abs_value - 500;
1837 1882
1838 newmsg->message_size = msgbuf_size + sizeof(struct WlanHeader); 1883 newmsg->message_size = msgbuf_size + sizeof (struct WlanHeader);
1839 1884
1840 GNUNET_CONTAINER_DLL_insert_tail(session->pending_message_head, session->pending_message_tail, newmsg); 1885 GNUNET_CONTAINER_DLL_insert_tail (session->pending_message_head,
1886 session->pending_message_tail, newmsg);
1841 1887
1842#if DEBUG_wlan 1888#if DEBUG_wlan
1843 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 1889 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
1844 "New message for %p with size (incl wlan header) %u added\n", session, 1890 "New message for %p with size (incl wlan header) %u added\n",
1845 newmsg->message_size); 1891 session, newmsg->message_size);
1846#endif 1892#endif
1847 1893
1848 //queue session 1894 //queue session
1849 queue_session(plugin, session); 1895 queue_session (plugin, session);
1850 1896
1851 check_fragment_queue(plugin); 1897 check_fragment_queue (plugin);
1852 //FIXME not the correct size 1898 //FIXME not the correct size
1853 return msgbuf_size; 1899 return msgbuf_size;
1854 1900
@@ -1860,24 +1906,25 @@ wlan_plugin_send(void *cls, const struct GNUNET_PeerIdentity * target,
1860 * @param endpoin pointer to the MacEndpoint to free 1906 * @param endpoin pointer to the MacEndpoint to free
1861 */ 1907 */
1862static void 1908static void
1863free_macendpoint(struct Plugin * plugin, struct MacEndpoint * endpoint) 1909free_macendpoint (struct Plugin *plugin, struct MacEndpoint *endpoint)
1864{ 1910{
1865 struct Sessionqueue * sessions; 1911 struct Sessionqueue *sessions;
1866 struct Sessionqueue * sessions_next; 1912 struct Sessionqueue *sessions_next;
1867 GNUNET_assert(endpoint != NULL); 1913
1914 GNUNET_assert (endpoint != NULL);
1868 1915
1869 sessions = endpoint->sessions_head; 1916 sessions = endpoint->sessions_head;
1870 while (sessions != NULL) 1917 while (sessions != NULL)
1871 { 1918 {
1872 sessions_next = sessions->next; 1919 sessions_next = sessions->next;
1873 free_session(plugin, sessions, GNUNET_NO); 1920 free_session (plugin, sessions, GNUNET_NO);
1874 sessions = sessions_next; 1921 sessions = sessions_next;
1875 } 1922 }
1876 1923
1877 GNUNET_CONTAINER_DLL_remove(plugin->mac_head,plugin->mac_tail,endpoint); 1924 GNUNET_CONTAINER_DLL_remove (plugin->mac_head, plugin->mac_tail, endpoint);
1878 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK) 1925 if (endpoint->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1879 GNUNET_SCHEDULER_cancel(endpoint->timeout_task); 1926 GNUNET_SCHEDULER_cancel (endpoint->timeout_task);
1880 GNUNET_free(endpoint); 1927 GNUNET_free (endpoint);
1881 1928
1882} 1929}
1883 1930
@@ -1888,75 +1935,75 @@ free_macendpoint(struct Plugin * plugin, struct MacEndpoint * endpoint)
1888 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint 1935 * @param free_macendpoint if GNUNET_YES and mac endpoint would be empty, free mac endpoint
1889 */ 1936 */
1890static void 1937static void
1891free_session(struct Plugin * plugin, struct Sessionqueue * queue, 1938free_session (struct Plugin *plugin, struct Sessionqueue *queue,
1892 int do_free_macendpoint) 1939 int do_free_macendpoint)
1893{ 1940{
1894 struct Sessionqueue * pendingsession; 1941 struct Sessionqueue *pendingsession;
1895 struct Sessionqueue * pendingsession_tmp; 1942 struct Sessionqueue *pendingsession_tmp;
1896 struct PendingMessage * pm; 1943 struct PendingMessage *pm;
1897 struct MacEndpoint * endpoint; 1944 struct MacEndpoint *endpoint;
1898 struct FragmentMessage * fm; 1945 struct FragmentMessage *fm;
1899 struct FragmentMessage * fmnext; 1946 struct FragmentMessage *fmnext;
1900 int check = 0; 1947 int check = 0;
1901 1948
1902 GNUNET_assert(queue != NULL); 1949 GNUNET_assert (queue != NULL);
1903 GNUNET_assert(queue->content != NULL); 1950 GNUNET_assert (queue->content != NULL);
1904 1951
1905 //session found 1952 //session found
1906 //is this session pending for send 1953 //is this session pending for send
1907 pendingsession = plugin->pending_Sessions_head; 1954 pendingsession = plugin->pending_Sessions_head;
1908 while (pendingsession != NULL) 1955 while (pendingsession != NULL)
1956 {
1957 pendingsession_tmp = pendingsession->next;
1958 if (pendingsession->content == queue->content)
1909 { 1959 {
1910 pendingsession_tmp = pendingsession->next; 1960 plugin->pendingsessions--;
1911 if (pendingsession->content == queue->content) 1961 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head,
1912 { 1962 plugin->pending_Sessions_tail,
1913 plugin->pendingsessions--; 1963 pendingsession);
1914 GNUNET_CONTAINER_DLL_remove (plugin->pending_Sessions_head, 1964 GNUNET_free (pendingsession);
1915 plugin->pending_Sessions_tail, 1965
1916 pendingsession); 1966 GNUNET_assert (check == 0);
1917 GNUNET_free(pendingsession); 1967 check = 1;
1918
1919 GNUNET_assert (check == 0);
1920 check = 1;
1921 }
1922 pendingsession = pendingsession_tmp;
1923 } 1968 }
1969 pendingsession = pendingsession_tmp;
1970 }
1924 1971
1925 endpoint = queue->content->mac; 1972 endpoint = queue->content->mac;
1926 fm = endpoint->sending_messages_head; 1973 fm = endpoint->sending_messages_head;
1927 while (fm != NULL) 1974 while (fm != NULL)
1975 {
1976 fmnext = fm->next;
1977 if (fm->session == queue->content)
1928 { 1978 {
1929 fmnext = fm->next; 1979 free_fragment_message (plugin, fm);
1930 if (fm->session == queue->content)
1931 {
1932 free_fragment_message(plugin, fm);
1933 }
1934 fm = fmnext;
1935 } 1980 }
1981 fm = fmnext;
1982 }
1936 1983
1937 // remove PendingMessage 1984 // remove PendingMessage
1938 pm = queue->content->pending_message_head; 1985 pm = queue->content->pending_message_head;
1939 while (pm != NULL) 1986 while (pm != NULL)
1940 { 1987 {
1941 GNUNET_CONTAINER_DLL_remove(queue->content->pending_message_head,queue->content->pending_message_tail,pm); 1988 GNUNET_CONTAINER_DLL_remove (queue->content->pending_message_head,
1942 GNUNET_free(pm->msg); 1989 queue->content->pending_message_tail, pm);
1943 GNUNET_free(pm); 1990 GNUNET_free (pm->msg);
1944 pm = queue->content->pending_message_head; 1991 GNUNET_free (pm);
1945 } 1992 pm = queue->content->pending_message_head;
1993 }
1946 1994
1947 GNUNET_CONTAINER_DLL_remove(endpoint->sessions_head , 1995 GNUNET_CONTAINER_DLL_remove (endpoint->sessions_head,
1948 endpoint->sessions_tail, 1996 endpoint->sessions_tail, queue);
1949 queue);
1950 1997
1951 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES) 1998 if (endpoint->sessions_head == NULL && do_free_macendpoint == GNUNET_YES)
1952 { 1999 {
1953 free_macendpoint(plugin, endpoint); 2000 free_macendpoint (plugin, endpoint);
1954 } 2001 }
1955 2002
1956 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK) 2003 if (queue->content->timeout_task != GNUNET_SCHEDULER_NO_TASK)
1957 GNUNET_SCHEDULER_cancel(queue->content->timeout_task); 2004 GNUNET_SCHEDULER_cancel (queue->content->timeout_task);
1958 GNUNET_free(queue); 2005 GNUNET_free (queue);
1959 check_fragment_queue(plugin); 2006 check_fragment_queue (plugin);
1960} 2007}
1961 2008
1962/** 2009/**
@@ -1968,33 +2015,34 @@ free_session(struct Plugin * plugin, struct Sessionqueue * queue,
1968 * @param target peer from which to disconnect 2015 * @param target peer from which to disconnect
1969 */ 2016 */
1970static void 2017static void
1971wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target) 2018wlan_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
1972{ 2019{
1973 struct Plugin *plugin = cls; 2020 struct Plugin *plugin = cls;
1974 struct Sessionqueue * queue; 2021 struct Sessionqueue *queue;
1975 struct Sessionqueue * queue_next; 2022 struct Sessionqueue *queue_next;
1976 struct MacEndpoint * endpoint = plugin->mac_head; 2023 struct MacEndpoint *endpoint = plugin->mac_head;
1977 struct MacEndpoint * endpoint_next; 2024 struct MacEndpoint *endpoint_next;
2025
1978 // just look at all the session for the needed one 2026 // just look at all the session for the needed one
1979 while (endpoint != NULL) 2027 while (endpoint != NULL)
2028 {
2029 queue = endpoint->sessions_head;
2030 endpoint_next = endpoint->next;
2031 while (queue != NULL)
1980 { 2032 {
1981 queue = endpoint->sessions_head; 2033 // content is never NULL
1982 endpoint_next = endpoint->next; 2034 GNUNET_assert (queue->content != NULL);
1983 while (queue != NULL) 2035 queue_next = queue->next;
1984 { 2036 if (memcmp (target, &(queue->content->target),
1985 // content is never NULL 2037 sizeof (struct GNUNET_PeerIdentity)) == 0)
1986 GNUNET_assert (queue->content != NULL); 2038 {
1987 queue_next = queue->next; 2039 free_session (plugin, queue, GNUNET_YES);
1988 if (memcmp(target, &(queue->content->target), 2040 }
1989 sizeof(struct GNUNET_PeerIdentity)) == 0) 2041 // try next
1990 { 2042 queue = queue_next;
1991 free_session(plugin, queue, GNUNET_YES);
1992 }
1993 // try next
1994 queue = queue_next;
1995 }
1996 endpoint = endpoint_next;
1997 } 2043 }
2044 endpoint = endpoint_next;
2045 }
1998} 2046}
1999 2047
2000/** 2048/**
@@ -2012,26 +2060,29 @@ wlan_plugin_disconnect(void *cls, const struct GNUNET_PeerIdentity *target)
2012 * @param asc_cls closure for asc 2060 * @param asc_cls closure for asc
2013 */ 2061 */
2014static void 2062static void
2015wlan_plugin_address_pretty_printer(void *cls, const char *type, 2063wlan_plugin_address_pretty_printer (void *cls, const char *type,
2016 const void *addr, size_t addrlen, int numeric, 2064 const void *addr, size_t addrlen,
2017 struct GNUNET_TIME_Relative timeout, 2065 int numeric,
2018 GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls) 2066 struct GNUNET_TIME_Relative timeout,
2067 GNUNET_TRANSPORT_AddressStringCallback asc,
2068 void *asc_cls)
2019{ 2069{
2020 char ret[92]; 2070 char ret[92];
2021 const unsigned char * input; 2071 const unsigned char *input;
2022 2072
2023 //GNUNET_assert(cls !=NULL); 2073 //GNUNET_assert(cls !=NULL);
2024 if (addrlen != 6) 2074 if (addrlen != 6)
2025 { 2075 {
2026 /* invalid address (MAC addresses have 6 bytes) */GNUNET_break (0); 2076 /* invalid address (MAC addresses have 6 bytes) */ GNUNET_break (0);
2027 asc(asc_cls, NULL); 2077 asc (asc_cls, NULL);
2028 return; 2078 return;
2029 } 2079 }
2030 input = (const unsigned char*) addr; 2080 input = (const unsigned char *) addr;
2031 GNUNET_snprintf(ret, sizeof(ret), 2081 GNUNET_snprintf (ret, sizeof (ret),
2032 "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X", PROTOCOL_PREFIX, 2082 "%s Mac-Address %.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
2033 input[0], input[1], input[2], input[3], input[4], input[5]); 2083 PROTOCOL_PREFIX, input[0], input[1], input[2], input[3],
2034 asc(asc_cls, ret); 2084 input[4], input[5]);
2085 asc (asc_cls, ret);
2035} 2086}
2036 2087
2037/** 2088/**
@@ -2041,136 +2092,137 @@ wlan_plugin_address_pretty_printer(void *cls, const char *type,
2041 * @param hdr pointer to the data 2092 * @param hdr pointer to the data
2042 */ 2093 */
2043static void 2094static void
2044wlan_data_message_handler(void *cls, const struct GNUNET_MessageHeader *hdr) 2095wlan_data_message_handler (void *cls, const struct GNUNET_MessageHeader *hdr)
2045{ 2096{
2046 struct MacEndpoint * endpoint = (struct MacEndpoint *) cls; 2097 struct MacEndpoint *endpoint = (struct MacEndpoint *) cls;
2047 struct Plugin * plugin = endpoint->plugin; 2098 struct Plugin *plugin = endpoint->plugin;
2048 struct WlanHeader * wlanheader; 2099 struct WlanHeader *wlanheader;
2049 struct Session * session; 2100 struct Session *session;
2101
2050 //const char * tempmsg; 2102 //const char * tempmsg;
2051 const struct GNUNET_MessageHeader * temp_hdr; 2103 const struct GNUNET_MessageHeader *temp_hdr;
2052 struct GNUNET_PeerIdentity tmpsource; 2104 struct GNUNET_PeerIdentity tmpsource;
2053 int crc; 2105 int crc;
2054 2106
2055 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA) 2107 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_DATA)
2056 { 2108 {
2057 2109
2058#if DEBUG_wlan 2110#if DEBUG_wlan
2059 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2111 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2060 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n", 2112 "Func wlan_data_message_handler got GNUNET_MESSAGE_TYPE_WLAN_DATA size: %u\n",
2061 ntohs(hdr->size)); 2113 ntohs (hdr->size));
2062#endif 2114#endif
2063 2115
2064 if (ntohs(hdr->size) < sizeof(struct WlanHeader) 2116 if (ntohs (hdr->size) < sizeof (struct WlanHeader)
2065 + sizeof(struct GNUNET_MessageHeader)) 2117 + sizeof (struct GNUNET_MessageHeader))
2066 { 2118 {
2067 //packet not big enought 2119 //packet not big enought
2068 return; 2120 return;
2069 } 2121 }
2070 2122
2071 wlanheader = (struct WlanHeader *) hdr; 2123 wlanheader = (struct WlanHeader *) hdr;
2072 2124
2073 session = search_session(plugin, endpoint, &wlanheader->source); 2125 session = search_session (plugin, endpoint, &wlanheader->source);
2074 2126
2075 //tempmsg = (char*) &wlanheader[1]; 2127 //tempmsg = (char*) &wlanheader[1];
2076 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1]; 2128 temp_hdr = (const struct GNUNET_MessageHeader *) &wlanheader[1];
2077 crc = ntohl(wlanheader->crc); 2129 crc = ntohl (wlanheader->crc);
2078 wlanheader->crc = 0; 2130 wlanheader->crc = 0;
2079 if (getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)) != crc) 2131 if (getcrc32 ((char *) wlanheader, ntohs (wlanheader->header.size)) != crc)
2080 { 2132 {
2081 //wrong crc, dispose message 2133 //wrong crc, dispose message
2082 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, 2134 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2083 "Wlan message header crc was wrong: %u != %u\n", 2135 "Wlan message header crc was wrong: %u != %u\n",
2084 getcrc32((char *) wlanheader, ntohs(wlanheader->header.size)), 2136 getcrc32 ((char *) wlanheader,
2085 crc); 2137 ntohs (wlanheader->header.size)), crc);
2086 hexdump((void *) hdr, ntohs(hdr->size)); 2138 hexdump ((void *) hdr, ntohs (hdr->size));
2087 return; 2139 return;
2088 } 2140 }
2089 2141
2090 //if not in session list 2142 //if not in session list
2091 if (session == NULL) 2143 if (session == NULL)
2092 { 2144 {
2093#if DEBUG_wlan 2145#if DEBUG_wlan
2094 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2146 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2095 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n", 2147 "WLAN client not in session list: packet size = %u, inner size = %u, header size = %u\n",
2096 ntohs(wlanheader->header.size), ntohs(temp_hdr->size), 2148 ntohs (wlanheader->header.size), ntohs (temp_hdr->size),
2097 sizeof(struct WlanHeader)); 2149 sizeof (struct WlanHeader));
2098#endif 2150#endif
2099 //try if it is a hello message 2151 //try if it is a hello message
2100 if (ntohs(wlanheader->header.size) >= ntohs(temp_hdr->size) 2152 if (ntohs (wlanheader->header.size) >= ntohs (temp_hdr->size)
2101 + sizeof(struct WlanHeader)) 2153 + sizeof (struct WlanHeader))
2102 { 2154 {
2103 if (ntohs(temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO) 2155 if (ntohs (temp_hdr->type) == GNUNET_MESSAGE_TYPE_HELLO)
2104 { 2156 {
2105 if (GNUNET_HELLO_get_id( 2157 if (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
2106 (const struct GNUNET_HELLO_Message *) temp_hdr, 2158 temp_hdr, &tmpsource) == GNUNET_OK)
2107 &tmpsource) == GNUNET_OK) 2159 {
2108 { 2160 session = create_session (plugin, endpoint, &tmpsource);
2109 session = create_session(plugin, endpoint, &tmpsource); 2161 }
2110 }
2111 else
2112 {
2113 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2114 "WLAN client not in session list and hello message is not okay\n");
2115 return;
2116 }
2117
2118 }
2119 else
2120 {
2121 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2122 "WLAN client not in session list and not a hello message\n");
2123 return;
2124 }
2125 }
2126 else 2162 else
2127 { 2163 {
2128 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, 2164 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2129 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n", 2165 "WLAN client not in session list and hello message is not okay\n");
2130 ntohs(wlanheader->header.size), ntohs(temp_hdr->size), 2166 return;
2131 sizeof(struct WlanHeader)); 2167 }
2132 return;
2133 }
2134 }
2135
2136 //"receive" the message
2137 2168
2138 if (memcmp(&wlanheader->source, &session->target,
2139 sizeof(struct GNUNET_PeerIdentity)) != 0)
2140 {
2141 //wrong peer id
2142#if DEBUG_wlan
2143 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2144 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2145 session);
2146#endif
2147 return;
2148 } 2169 }
2149 2170 else
2150 if (memcmp(&wlanheader->target, plugin->env->my_identity,
2151 sizeof(struct GNUNET_PeerIdentity)) != 0)
2152 { 2171 {
2153 //wrong peer id 2172 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2154#if DEBUG_wlan 2173 "WLAN client not in session list and not a hello message\n");
2155 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2156 "WLAN peer target id doesn't match our peer id: session %p\n",
2157 session);
2158#endif
2159 return; 2174 return;
2160 } 2175 }
2176 }
2177 else
2178 {
2179 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2180 "WLAN client not in session list and message size in does not fit\npacket size = %u, inner size = %u, header size = %u\n",
2181 ntohs (wlanheader->header.size),
2182 ntohs (temp_hdr->size), sizeof (struct WlanHeader));
2183 return;
2184 }
2185 }
2161 2186
2162 GNUNET_SERVER_mst_receive(plugin->data_tokenizer, session, 2187 //"receive" the message
2163 (const char *) temp_hdr,
2164 ntohs(hdr->size) - sizeof(struct WlanHeader), GNUNET_YES, GNUNET_NO);
2165 2188
2189 if (memcmp (&wlanheader->source, &session->target,
2190 sizeof (struct GNUNET_PeerIdentity)) != 0)
2191 {
2192 //wrong peer id
2193#if DEBUG_wlan
2194 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2195 "WLAN peer source id doesn't match packet peer source id: session %p\n",
2196 session);
2197#endif
2166 return; 2198 return;
2167 } 2199 }
2168 else 2200
2201 if (memcmp (&wlanheader->target, plugin->env->my_identity,
2202 sizeof (struct GNUNET_PeerIdentity)) != 0)
2169 { 2203 {
2170 GNUNET_log_from(GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME, 2204 //wrong peer id
2171 "wlan_data_message_handler got wrong message type\n"); 2205#if DEBUG_wlan
2206 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2207 "WLAN peer target id doesn't match our peer id: session %p\n",
2208 session);
2209#endif
2172 return; 2210 return;
2173 } 2211 }
2212
2213 GNUNET_SERVER_mst_receive (plugin->data_tokenizer, session,
2214 (const char *) temp_hdr,
2215 ntohs (hdr->size) - sizeof (struct WlanHeader),
2216 GNUNET_YES, GNUNET_NO);
2217
2218 return;
2219 }
2220 else
2221 {
2222 GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, PLUGIN_LOG_NAME,
2223 "wlan_data_message_handler got wrong message type\n");
2224 return;
2225 }
2174} 2226}
2175 2227
2176/** 2228/**
@@ -2181,30 +2233,35 @@ wlan_data_message_handler(void *cls, const struct GNUNET_MessageHeader *hdr)
2181 */ 2233 */
2182//TODO ATS informations 2234//TODO ATS informations
2183static void 2235static void
2184process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 2236process_data (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2185{ 2237{
2186 2238
2187 GNUNET_assert(client != NULL); 2239 GNUNET_assert (client != NULL);
2188 GNUNET_assert(cls != NULL); 2240 GNUNET_assert (cls != NULL);
2189 struct Session * session = (struct Session *) client; 2241 struct Session *session = (struct Session *) client;
2190 struct Plugin * plugin = (struct Plugin *) cls; 2242 struct Plugin *plugin = (struct Plugin *) cls;
2191 2243
2192 struct GNUNET_TRANSPORT_ATS_Information distance[2]; 2244 struct GNUNET_TRANSPORT_ATS_Information distance[2];
2193 distance[0].type = htonl(GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 2245
2194 distance[0].value = htonl(1); 2246 distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
2195 distance[1].type = htonl(GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 2247 distance[0].value = htonl (1);
2196 distance[1].value = htonl(0); 2248 distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
2249 distance[1].value = htonl (0);
2197 2250
2198#if DEBUG_wlan 2251#if DEBUG_wlan
2199 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2252 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2200 "Calling plugin->env->receive for session %p; %s; size: %u\n", session, 2253 "Calling plugin->env->receive for session %p; %s; size: %u\n",
2201 wlan_plugin_address_to_string(NULL, session->mac->addr.mac, 6), 2254 session, wlan_plugin_address_to_string (NULL,
2202 htons(hdr->size)); 2255 session->mac->
2256 addr.mac, 6),
2257 htons (hdr->size));
2203#endif 2258#endif
2204 2259
2205 plugin->env->receive(plugin->env->cls, &(session->target), hdr, 2260 plugin->env->receive (plugin->env->cls, &(session->target), hdr,
2206 (const struct GNUNET_TRANSPORT_ATS_Information *) &distance, 2, session, 2261 (const struct GNUNET_TRANSPORT_ATS_Information *)
2207 (const char*) &session->mac->addr, sizeof(session->mac->addr)); 2262 &distance, 2, session,
2263 (const char *) &session->mac->addr,
2264 sizeof (session->mac->addr));
2208} 2265}
2209 2266
2210/** 2267/**
@@ -2215,166 +2272,183 @@ process_data(void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
2215 * @param hdr hdr of the GNUNET_MessageHeader 2272 * @param hdr hdr of the GNUNET_MessageHeader
2216 */ 2273 */
2217static void 2274static void
2218wlan_data_helper(void *cls, struct Session_light * session_light, 2275wlan_data_helper (void *cls, struct Session_light *session_light,
2219 const struct GNUNET_MessageHeader * hdr, const struct Radiotap_rx * rxinfo) 2276 const struct GNUNET_MessageHeader *hdr,
2277 const struct Radiotap_rx *rxinfo)
2220{ 2278{
2221 struct Plugin *plugin = cls; 2279 struct Plugin *plugin = cls;
2222 struct FragmentMessage * fm; 2280 struct FragmentMessage *fm;
2223 struct FragmentMessage * fm2; 2281 struct FragmentMessage *fm2;
2224 2282
2225 //ADVERTISEMENT 2283 //ADVERTISEMENT
2226 if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT) 2284 if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT)
2227 { 2285 {
2228 2286
2229 //TODO better DOS protection, error handling 2287 //TODO better DOS protection, error handling
2230 //TODO test first than create session 2288 //TODO test first than create session
2231 GNUNET_assert(session_light != NULL); 2289 GNUNET_assert (session_light != NULL);
2232 2290
2233#if DEBUG_wlan 2291#if DEBUG_wlan
2234 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2292 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2235 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n", 2293 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_WLAN_ADVERTISEMENT size: %u; %s\n",
2236 ntohs(hdr->size), 2294 ntohs (hdr->size),
2237 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2295 wlan_plugin_address_to_string (NULL,
2296 session_light->addr.mac,
2297 6));
2238#endif 2298#endif
2239 2299
2240 if (session_light->macendpoint == NULL) 2300 if (session_light->macendpoint == NULL)
2241 { 2301 {
2242 session_light->macendpoint = get_macendpoint(plugin, 2302 session_light->macendpoint = get_macendpoint (plugin,
2243 &session_light->addr, GNUNET_NO); 2303 &session_light->addr,
2244 } 2304 GNUNET_NO);
2245 GNUNET_assert(GNUNET_HELLO_get_id(
2246 (const struct GNUNET_HELLO_Message *) &hdr[1],
2247 &(session_light->session->target) ) != GNUNET_SYSERR);
2248
2249 } 2305 }
2306 GNUNET_assert (GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
2307 &hdr[1],
2308 &(session_light->session->target)) !=
2309 GNUNET_SYSERR);
2310
2311 }
2250 2312
2251 //FRAGMENT 2313 //FRAGMENT
2252 2314
2253 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT) 2315 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT)
2254 { 2316 {
2255 2317
2256 GNUNET_assert(session_light != NULL); 2318 GNUNET_assert (session_light != NULL);
2257 if (session_light->macendpoint == NULL) 2319 if (session_light->macendpoint == NULL)
2258 { 2320 {
2259 session_light->macendpoint = get_macendpoint(plugin, 2321 session_light->macendpoint = get_macendpoint (plugin,
2260 &session_light->addr, GNUNET_YES); 2322 &session_light->addr,
2261 } 2323 GNUNET_YES);
2324 }
2262 2325
2263#if DEBUG_wlan 2326#if DEBUG_wlan
2264 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2327 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2265 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n", 2328 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT with size: %u; mac endpoint %p: %s\n",
2266 ntohs(hdr->size), session_light->macendpoint, 2329 ntohs (hdr->size), session_light->macendpoint,
2267 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2330 wlan_plugin_address_to_string (NULL,
2331 session_light->addr.mac,
2332 6));
2268#endif 2333#endif
2269 2334
2270 int ret = GNUNET_DEFRAGMENT_process_fragment( 2335 int ret =
2271 session_light->macendpoint->defrag, hdr); 2336 GNUNET_DEFRAGMENT_process_fragment (session_light->macendpoint->defrag,
2272 if (ret == GNUNET_NO) 2337 hdr);
2273 {
2274 session_light->macendpoint->dups++;
2275 }
2276 else if (ret == GNUNET_OK)
2277 {
2278 session_light->macendpoint->fragc++;
2279 }
2280 set_next_send(plugin);
2281 2338
2339 if (ret == GNUNET_NO)
2340 {
2341 session_light->macendpoint->dups++;
2342 }
2343 else if (ret == GNUNET_OK)
2344 {
2345 session_light->macendpoint->fragc++;
2282 } 2346 }
2347 set_next_send (plugin);
2348
2349 }
2283 2350
2284 //ACK 2351 //ACK
2285 2352
2286 else if (ntohs(hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK) 2353 else if (ntohs (hdr->type) == GNUNET_MESSAGE_TYPE_FRAGMENT_ACK)
2354 {
2355 GNUNET_assert (session_light != NULL);
2356 if (session_light->macendpoint == NULL)
2287 { 2357 {
2288 GNUNET_assert(session_light != NULL); 2358 session_light->macendpoint = get_macendpoint (plugin,
2289 if (session_light->macendpoint == NULL) 2359 &session_light->addr,
2290 { 2360 GNUNET_NO);
2291 session_light->macendpoint = get_macendpoint(plugin, 2361 }
2292 &session_light->addr, GNUNET_NO);
2293 }
2294 2362
2295 if (session_light->macendpoint == NULL) 2363 if (session_light->macendpoint == NULL)
2296 { 2364 {
2297#if DEBUG_wlan 2365#if DEBUG_wlan
2298 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2366 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2299 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n", 2367 "Macendpoint does not exist for this GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; %s\n",
2300 ntohs(hdr->size), 2368 ntohs (hdr->size),
2301 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2369 wlan_plugin_address_to_string (NULL,
2370 session_light->addr.mac,
2371 6));
2302#endif 2372#endif
2303 return; 2373 return;
2304 } 2374 }
2305 2375
2306#if DEBUG_wlan 2376#if DEBUG_wlan
2307 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2377 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2308 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n", 2378 "Func wlan_data_helper got GNUNET_MESSAGE_TYPE_FRAGMENT_ACK size: %u; mac endpoint: %p; %s\n",
2309 ntohs(hdr->size), session_light->macendpoint, 2379 ntohs (hdr->size), session_light->macendpoint,
2310 wlan_plugin_address_to_string(NULL, session_light->addr.mac, 6)); 2380 wlan_plugin_address_to_string (NULL,
2381 session_light->addr.mac,
2382 6));
2311#endif 2383#endif
2312 fm = session_light->macendpoint->sending_messages_head; 2384 fm = session_light->macendpoint->sending_messages_head;
2313 while (fm != NULL) 2385 while (fm != NULL)
2314 { 2386 {
2315 fm2 = fm->next; 2387 fm2 = fm->next;
2316 int ret = GNUNET_FRAGMENT_process_ack(fm->fragcontext, hdr); 2388 int ret = GNUNET_FRAGMENT_process_ack (fm->fragcontext, hdr);
2317 if (ret == GNUNET_OK) 2389
2318 { 2390 if (ret == GNUNET_OK)
2391 {
2319#if DEBUG_wlan_retransmission 2392#if DEBUG_wlan_retransmission
2320 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2393 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2321 "Got last ack, finished fragment message %p\n", fm); 2394 "Got last ack, finished fragment message %p\n", fm);
2322#endif 2395#endif
2323 session_light->macendpoint->acks++; 2396 session_light->macendpoint->acks++;
2324 fm->session->last_activity = GNUNET_TIME_absolute_get(); 2397 fm->session->last_activity = GNUNET_TIME_absolute_get ();
2325 session_light->macendpoint->last_activity = fm->session->last_activity; 2398 session_light->macendpoint->last_activity = fm->session->last_activity;
2326 free_fragment_message(plugin, fm); 2399 free_fragment_message (plugin, fm);
2327 check_fragment_queue(plugin); 2400 check_fragment_queue (plugin);
2328 return; 2401 return;
2329 } 2402 }
2330 if (ret == GNUNET_NO) 2403 if (ret == GNUNET_NO)
2331 { 2404 {
2332#if DEBUG_wlan_retransmission 2405#if DEBUG_wlan_retransmission
2333 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "Got ack for: %p\n", fm); 2406 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2407 "Got ack for: %p\n", fm);
2334#endif 2408#endif
2335 session_light->macendpoint->acks++; 2409 session_light->macendpoint->acks++;
2336 return; 2410 return;
2337 } 2411 }
2338 if (ret == GNUNET_SYSERR) 2412 if (ret == GNUNET_SYSERR)
2339 { 2413 {
2340 2414
2341 } 2415 }
2342 2416
2343 fm = fm2; 2417 fm = fm2;
2344 } 2418 }
2345 2419
2346#if DEBUG_wlan_retransmission 2420#if DEBUG_wlan_retransmission
2347 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2421 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2348 "WLAN fragment not in fragment list\n"); 2422 "WLAN fragment not in fragment list\n");
2349#endif 2423#endif
2350 return; 2424 return;
2351 2425
2352 } 2426 }
2353 else 2427 else
2354 { 2428 {
2355 // TODO Wrong data? 2429 // TODO Wrong data?
2356 GNUNET_log_from(GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME, 2430 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, PLUGIN_LOG_NAME,
2357 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n", 2431 "WLAN packet inside the WLAN helper packet has not the right type: %u size: %u\n",
2358 ntohs(hdr->type), ntohs(hdr->size)); 2432 ntohs (hdr->type), ntohs (hdr->size));
2359 GNUNET_break(0); 2433 GNUNET_break (0);
2360 return; 2434 return;
2361 } 2435 }
2362 2436
2363#if 0 2437#if 0
2364 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2438 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2365 "Helper finished\n"); 2439 "Helper finished\n");
2366#endif 2440#endif
2367 2441
2368} 2442}
2369 2443
2370//TODO DOXIGEN 2444//TODO DOXIGEN
2371const char * 2445const char *
2372macprinter(const u_int8_t * mac) 2446macprinter (const u_int8_t * mac)
2373{ 2447{
2374 static char macstr[20]; 2448 static char macstr[20];
2375 2449
2376 GNUNET_snprintf(macstr, sizeof(macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1], 2450 GNUNET_snprintf (macstr, sizeof (macstr), "%X:%X:%X:%X:%X:%X", mac[0], mac[1],
2377 mac[2], mac[3], mac[4], mac[5]); 2451 mac[2], mac[3], mac[4], mac[5]);
2378 return macstr; 2452 return macstr;
2379} 2453}
2380 2454
@@ -2384,25 +2458,28 @@ macprinter(const u_int8_t * mac)
2384 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext 2458 * @param tc pointer to the GNUNET_SCHEDULER_TaskContext
2385 */ 2459 */
2386static void 2460static void
2387macendpoint_timeout (void *cls, 2461macendpoint_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2388 const struct GNUNET_SCHEDULER_TaskContext *tc){ 2462{
2389 struct MacEndpoint * endpoint = cls; 2463 struct MacEndpoint *endpoint = cls;
2390 GNUNET_assert(endpoint != NULL); 2464
2465 GNUNET_assert (endpoint != NULL);
2391 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK; 2466 endpoint->timeout_task = GNUNET_SCHEDULER_NO_TASK;
2392 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN){ 2467 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2393 return; 2468 {
2469 return;
2470 }
2471 if (GNUNET_TIME_absolute_get_remaining
2472 (GNUNET_TIME_absolute_add
2473 (endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value == 0)
2474 {
2475 free_macendpoint (endpoint->plugin, endpoint);
2394 } 2476 }
2395 if (GNUNET_TIME_absolute_get_remaining(
2396 GNUNET_TIME_absolute_add(endpoint->last_activity, MACENDPOINT_TIMEOUT)).rel_value
2397 == 0)
2398 {
2399 free_macendpoint(endpoint->plugin,endpoint);
2400 }
2401 else 2477 else
2402 { 2478 {
2403 endpoint->timeout_task = GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, 2479 endpoint->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT,
2404 &macendpoint_timeout, endpoint); 2480 &macendpoint_timeout,
2405 } 2481 endpoint);
2482 }
2406} 2483}
2407 2484
2408/** 2485/**
@@ -2412,25 +2489,31 @@ macendpoint_timeout (void *cls,
2412 * @return returns a macendpoint 2489 * @return returns a macendpoint
2413 */ 2490 */
2414static struct MacEndpoint * 2491static struct MacEndpoint *
2415create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr) 2492create_macendpoint (struct Plugin *plugin, const struct MacAddress *addr)
2416{ 2493{
2417 struct MacEndpoint * newend = GNUNET_malloc(sizeof (struct MacEndpoint)); 2494 struct MacEndpoint *newend = GNUNET_malloc (sizeof (struct MacEndpoint));
2495
2418 newend->addr = *addr; 2496 newend->addr = *addr;
2419 newend->plugin = plugin; 2497 newend->plugin = plugin;
2420 newend->addr = *addr; 2498 newend->addr = *addr;
2421 newend->fragment_messages_out_count = 0; 2499 newend->fragment_messages_out_count = 0;
2422 newend->defrag = GNUNET_DEFRAGMENT_context_create(plugin->env->stats, 2500 newend->defrag = GNUNET_DEFRAGMENT_context_create (plugin->env->stats,
2423 WLAN_MTU, MESSAGES_IN_DEFRAG_QUEUE_PER_MAC, newend, 2501 WLAN_MTU,
2424 &wlan_data_message_handler, &add_ack_for_send); 2502 MESSAGES_IN_DEFRAG_QUEUE_PER_MAC,
2425 newend->last_activity = GNUNET_TIME_absolute_get(); 2503 newend,
2426 newend->timeout_task = GNUNET_SCHEDULER_add_delayed(MACENDPOINT_TIMEOUT, 2504 &wlan_data_message_handler,
2427 &macendpoint_timeout, newend); 2505 &add_ack_for_send);
2506 newend->last_activity = GNUNET_TIME_absolute_get ();
2507 newend->timeout_task = GNUNET_SCHEDULER_add_delayed (MACENDPOINT_TIMEOUT,
2508 &macendpoint_timeout,
2509 newend);
2428 2510
2429 plugin->mac_count++; 2511 plugin->mac_count++;
2430 GNUNET_CONTAINER_DLL_insert_tail(plugin->mac_head, plugin->mac_tail, newend); 2512 GNUNET_CONTAINER_DLL_insert_tail (plugin->mac_head, plugin->mac_tail, newend);
2431#if DEBUG_wlan 2513#if DEBUG_wlan
2432 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "New Mac Endpoint %p: %s\n", newend, 2514 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2433 wlan_plugin_address_to_string(NULL, newend->addr.mac, 6)); 2515 "New Mac Endpoint %p: %s\n", newend,
2516 wlan_plugin_address_to_string (NULL, newend->addr.mac, 6));
2434#endif 2517#endif
2435 return newend; 2518 return newend;
2436} 2519}
@@ -2443,125 +2526,126 @@ create_macendpoint(struct Plugin *plugin, const struct MacAddress *addr)
2443 * @param hdr header of the GNUNET_MessageHeader 2526 * @param hdr header of the GNUNET_MessageHeader
2444 */ 2527 */
2445static void 2528static void
2446wlan_process_helper(void *cls, void *client, 2529wlan_process_helper (void *cls, void *client,
2447 const struct GNUNET_MessageHeader *hdr) 2530 const struct GNUNET_MessageHeader *hdr)
2448{ 2531{
2449 struct Plugin *plugin = cls; 2532 struct Plugin *plugin = cls;
2450 struct ieee80211_frame * wlanIeeeHeader = NULL; 2533 struct ieee80211_frame *wlanIeeeHeader = NULL;
2451 struct Session_light * session_light = NULL; 2534 struct Session_light *session_light = NULL;
2452 struct Radiotap_rx * rxinfo; 2535 struct Radiotap_rx *rxinfo;
2453 const struct GNUNET_MessageHeader * temp_hdr = NULL; 2536 const struct GNUNET_MessageHeader *temp_hdr = NULL;
2454 2537
2455 int datasize = 0; 2538 int datasize = 0;
2456 int pos; 2539 int pos;
2457 2540
2458 switch (ntohs(hdr->type)) 2541 switch (ntohs (hdr->type))
2459 { 2542 {
2460 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA: 2543 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA:
2461#if DEBUG_wlan 2544#if DEBUG_wlan
2462 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2545 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2463 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n", 2546 "Func wlan_process_helper got GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA size: %u\n",
2464 ntohs(hdr->size)); 2547 ntohs (hdr->size));
2465#endif 2548#endif
2466 2549
2467 //call wlan_process_helper with the message inside, later with wlan: analyze signal 2550 //call wlan_process_helper with the message inside, later with wlan: analyze signal
2468 if (ntohs(hdr->size) < sizeof(struct ieee80211_frame) 2551 if (ntohs (hdr->size) < sizeof (struct ieee80211_frame)
2469 + sizeof(struct GNUNET_MessageHeader) + sizeof(struct Radiotap_rx)) 2552 + sizeof (struct GNUNET_MessageHeader) + sizeof (struct Radiotap_rx))
2470 { 2553 {
2471#if DEBUG_wlan 2554#if DEBUG_wlan
2472 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2555 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2473 "Size of packet is too small; size: %u min size: %u\n", 2556 "Size of packet is too small; size: %u min size: %u\n",
2474 ntohs(hdr->size), 2557 ntohs (hdr->size),
2475 sizeof(struct ieee80211_frame) 2558 sizeof (struct ieee80211_frame)
2476 + sizeof(struct GNUNET_MessageHeader)); 2559 + sizeof (struct GNUNET_MessageHeader));
2477#endif 2560#endif
2478 //GNUNET_break (0); 2561 //GNUNET_break (0);
2479 /* FIXME: restart SUID process */ 2562 /* FIXME: restart SUID process */
2480 return; 2563 return;
2481 } 2564 }
2482 rxinfo = (struct Radiotap_rx *) &hdr[1]; 2565 rxinfo = (struct Radiotap_rx *) &hdr[1];
2483 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1]; 2566 wlanIeeeHeader = (struct ieee80211_frame *) &rxinfo[1];
2484 2567
2485 //process only if it is an broadcast or for this computer both with the gnunet bssid 2568 //process only if it is an broadcast or for this computer both with the gnunet bssid
2486 2569
2487 //check for bssid 2570 //check for bssid
2488 if (memcmp(&(wlanIeeeHeader->i_addr3), &mac_bssid, 2571 if (memcmp (&(wlanIeeeHeader->i_addr3), &mac_bssid,
2489 sizeof(struct MacAddress)) == 0) 2572 sizeof (struct MacAddress)) == 0)
2573 {
2574 //check for broadcast or mac
2575 if (memcmp (&(wlanIeeeHeader->i_addr1), &bc_all_mac,
2576 sizeof (struct MacAddress) == 0) ||
2577 memcmp (&(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2578 sizeof (struct MacAddress)) == 0)
2490 { 2579 {
2491 //check for broadcast or mac
2492 if (memcmp(&(wlanIeeeHeader->i_addr1), &bc_all_mac,
2493 sizeof(struct MacAddress) == 0) || memcmp(
2494 &(wlanIeeeHeader->i_addr1), &(plugin->mac_address),
2495 sizeof(struct MacAddress)) == 0)
2496 {
2497 2580
2498 // process the inner data 2581 // process the inner data
2499 2582
2500 2583
2501 datasize = ntohs(hdr->size) - sizeof(struct ieee80211_frame) 2584 datasize = ntohs (hdr->size) - sizeof (struct ieee80211_frame)
2502 - sizeof(struct GNUNET_MessageHeader) 2585 - sizeof (struct GNUNET_MessageHeader)
2503 - sizeof(struct Radiotap_rx); 2586 - sizeof (struct Radiotap_rx);
2504 2587
2505 session_light = GNUNET_malloc(sizeof(struct Session_light)); 2588 session_light = GNUNET_malloc (sizeof (struct Session_light));
2506 memcpy(&session_light->addr, &(wlanIeeeHeader->i_addr2), 2589 memcpy (&session_light->addr, &(wlanIeeeHeader->i_addr2),
2507 sizeof(struct MacAddress)); 2590 sizeof (struct MacAddress));
2508 //session_light->session = search_session(plugin,session_light->addr); 2591 //session_light->session = search_session(plugin,session_light->addr);
2509 2592
2510 pos = 0; 2593 pos = 0;
2511 while (pos < datasize) 2594 while (pos < datasize)
2512 { 2595 {
2513 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] 2596 temp_hdr = (struct GNUNET_MessageHeader *) &wlanIeeeHeader[1] + pos;
2514 + pos;
2515 2597
2516 wlan_data_helper(plugin, session_light, temp_hdr, rxinfo); 2598 wlan_data_helper (plugin, session_light, temp_hdr, rxinfo);
2517 pos += ntohs(temp_hdr->size); 2599 pos += ntohs (temp_hdr->size);
2518 2600
2519 } 2601 }
2520 2602
2521 //clean up 2603 //clean up
2522 GNUNET_free(session_light); 2604 GNUNET_free (session_light);
2523 } 2605 }
2524 else 2606 else
2525 { 2607 {
2526#if DEBUG_wlan 2608#if DEBUG_wlan
2527 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2609 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2528 "Func wlan_process_helper got wrong MAC: %s\n", 2610 "Func wlan_process_helper got wrong MAC: %s\n",
2529 macprinter(wlanIeeeHeader->i_addr1)); 2611 macprinter (wlanIeeeHeader->i_addr1));
2530#endif 2612#endif
2531 }
2532 } 2613 }
2614 }
2533 else 2615 else
2534 { 2616 {
2535#if DEBUG_wlan 2617#if DEBUG_wlan
2536 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2618 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2537 "Func wlan_process_helper got wrong BSSID: %s\n", 2619 "Func wlan_process_helper got wrong BSSID: %s\n",
2538 macprinter(wlanIeeeHeader->i_addr2)); 2620 macprinter (wlanIeeeHeader->i_addr2));
2539#endif 2621#endif
2540 } 2622 }
2541 break; 2623 break;
2542 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL: 2624 case GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL:
2543 //TODO more control messages 2625 //TODO more control messages
2544 //TODO use struct wlan_helper_control 2626 //TODO use struct wlan_helper_control
2545 if (ntohs(hdr->size) != sizeof(struct Wlan_Helper_Control_Message)) 2627 if (ntohs (hdr->size) != sizeof (struct Wlan_Helper_Control_Message))
2546 { 2628 {
2547 GNUNET_break (0); 2629 GNUNET_break (0);
2548 /* FIXME: restart SUID process */ 2630 /* FIXME: restart SUID process */
2549 return; 2631 return;
2550 } 2632 }
2551 memcpy(&plugin->mac_address, &hdr[1], sizeof(struct MacAddress)); 2633 memcpy (&plugin->mac_address, &hdr[1], sizeof (struct MacAddress));
2552#if DEBUG_wlan 2634#if DEBUG_wlan
2553 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2635 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2554 "Received WLAN_HELPER_CONTROL message with transport of address %s\n", 2636 "Received WLAN_HELPER_CONTROL message with transport of address %s\n",
2555 wlan_plugin_address_to_string(cls, &plugin->mac_address, 2637 wlan_plugin_address_to_string (cls, &plugin->mac_address,
2556 sizeof(struct MacAddress))); 2638 sizeof (struct
2639 MacAddress)));
2557#endif 2640#endif
2558 plugin->env->notify_address(plugin->env->cls, GNUNET_YES, 2641 plugin->env->notify_address (plugin->env->cls, GNUNET_YES,
2559 &plugin->mac_address, sizeof(struct MacAddress)); 2642 &plugin->mac_address,
2643 sizeof (struct MacAddress));
2560 break; 2644 break;
2561 default: 2645 default:
2562 GNUNET_break (0); 2646 GNUNET_break (0);
2563 return; 2647 return;
2564 } 2648 }
2565} 2649}
2566 2650
2567/** 2651/**
@@ -2573,36 +2657,39 @@ wlan_process_helper(void *cls, void *client,
2573 * @param tc the scheduling context 2657 * @param tc the scheduling context
2574 */ 2658 */
2575static void 2659static void
2576wlan_plugin_helper_read(void *cls, 2660wlan_plugin_helper_read (void *cls,
2577 const struct GNUNET_SCHEDULER_TaskContext *tc) 2661 const struct GNUNET_SCHEDULER_TaskContext *tc)
2578{ 2662{
2579 struct Plugin *plugin = cls; 2663 struct Plugin *plugin = cls;
2664
2580 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2665 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2581 2666
2582 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 2667 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
2583 return; 2668 return;
2584 2669
2585 char mybuf[WLAN_MTU + sizeof(struct GNUNET_MessageHeader)]; 2670 char mybuf[WLAN_MTU + sizeof (struct GNUNET_MessageHeader)];
2586 ssize_t bytes; 2671 ssize_t bytes;
2587 2672
2588 bytes = GNUNET_DISK_file_read(plugin->server_stdout_handle, mybuf, 2673 bytes = GNUNET_DISK_file_read (plugin->server_stdout_handle, mybuf,
2589 sizeof(mybuf)); 2674 sizeof (mybuf));
2590 if (bytes <= 0) 2675 if (bytes <= 0)
2591 { 2676 {
2592#if DEBUG_wlan 2677#if DEBUG_wlan
2593 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2678 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2594 _("Finished reading from wlan-helper stdout with code: %d\n"), 2679 _
2595 bytes); 2680 ("Finished reading from wlan-helper stdout with code: %d\n"),
2681 bytes);
2596#endif 2682#endif
2597 return; 2683 return;
2598 } 2684 }
2599 GNUNET_SERVER_mst_receive(plugin->suid_tokenizer, NULL, mybuf, bytes, 2685 GNUNET_SERVER_mst_receive (plugin->suid_tokenizer, NULL, mybuf, bytes,
2600 GNUNET_NO, GNUNET_NO); 2686 GNUNET_NO, GNUNET_NO);
2601 2687
2602 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); 2688 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2603 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( 2689 plugin->server_read_task =
2604 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, 2690 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
2605 &wlan_plugin_helper_read, plugin); 2691 plugin->server_stdout_handle,
2692 &wlan_plugin_helper_read, plugin);
2606} 2693}
2607 2694
2608/** 2695/**
@@ -2613,85 +2700,93 @@ wlan_plugin_helper_read(void *cls,
2613 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error 2700 * @return GNUNET_YES if process was started, GNUNET_SYSERR on error
2614 */ 2701 */
2615static int 2702static int
2616wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode) 2703wlan_transport_start_wlan_helper (struct Plugin *plugin, int testmode)
2617{ 2704{
2618 const char * filenamehw = "gnunet-transport-wlan-helper"; 2705 const char *filenamehw = "gnunet-transport-wlan-helper";
2619 const char * filenameloopback = "gnunet-transport-wlan-helper-dummy"; 2706 const char *filenameloopback = "gnunet-transport-wlan-helper-dummy";
2620 plugin->server_stdout = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_NO, GNUNET_YES); 2707
2708 plugin->server_stdout = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
2621 if (plugin->server_stdout == NULL) 2709 if (plugin->server_stdout == NULL)
2622 return GNUNET_SYSERR; 2710 return GNUNET_SYSERR;
2623 2711
2624 plugin->server_stdin = GNUNET_DISK_pipe(GNUNET_YES, GNUNET_YES, GNUNET_NO); 2712 plugin->server_stdin = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO);
2625 if (plugin->server_stdin == NULL) 2713 if (plugin->server_stdin == NULL)
2626 return GNUNET_SYSERR; 2714 return GNUNET_SYSERR;
2627 2715
2628 /* Start the server process */ 2716 /* Start the server process */
2629 2717
2630 if (testmode == 0) 2718 if (testmode == 0)
2631 { 2719 {
2632 2720
2633#if DEBUG_wlan 2721#if DEBUG_wlan
2634 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2722 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2635 "Starting gnunet-wlan-helper process cmd: %s %s %i\n", filenamehw, 2723 "Starting gnunet-wlan-helper process cmd: %s %s %i\n",
2636 plugin->interface, testmode); 2724 filenamehw, plugin->interface, testmode);
2637#endif 2725#endif
2638 2726
2639 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2727 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
2640 plugin->server_stdout, filenamehw, filenamehw, plugin->interface, 2728 plugin->server_stdout,
2641 NULL); 2729 filenamehw, filenamehw,
2642 } 2730 plugin->interface, NULL);
2731 }
2643 else if (testmode == 1) 2732 else if (testmode == 1)
2644 { 2733 {
2645 2734
2646#if DEBUG_wlan 2735#if DEBUG_wlan
2647 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2736 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2648 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n", 2737 "Starting gnunet-wlan-helper loopback 1 process cmd: %s %s %i\n",
2649 filenameloopback, plugin->interface, testmode); 2738 filenameloopback, plugin->interface, testmode);
2650#endif 2739#endif
2651 2740
2652 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2741 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
2653 plugin->server_stdout, filenameloopback, filenameloopback, "1", NULL); 2742 plugin->server_stdout,
2654 } 2743 filenameloopback,
2744 filenameloopback, "1", NULL);
2745 }
2655 else if (testmode == 2) 2746 else if (testmode == 2)
2656 { 2747 {
2657#if DEBUG_wlan 2748#if DEBUG_wlan
2658 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2749 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2659 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n", 2750 "Starting gnunet-wlan-helper loopback 2 process cmd: %s %s %i\n",
2660 filenameloopback, plugin->interface, testmode); 2751 filenameloopback, plugin->interface, testmode);
2661#endif 2752#endif
2662 plugin->server_proc = GNUNET_OS_start_process(plugin->server_stdin, 2753 plugin->server_proc = GNUNET_OS_start_process (plugin->server_stdin,
2663 plugin->server_stdout, filenameloopback, filenameloopback, "2", NULL); 2754 plugin->server_stdout,
2664 } 2755 filenameloopback,
2756 filenameloopback, "2", NULL);
2757 }
2665 if (plugin->server_proc == NULL) 2758 if (plugin->server_proc == NULL)
2666 { 2759 {
2667#if DEBUG_wlan 2760#if DEBUG_wlan
2668 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2761 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2669 "Failed to start gnunet-wlan-helper process\n"); 2762 "Failed to start gnunet-wlan-helper process\n");
2670#endif 2763#endif
2671 return GNUNET_SYSERR; 2764 return GNUNET_SYSERR;
2672 } 2765 }
2673 2766
2674 /* Close the write end of the read pipe */ 2767 /* Close the write end of the read pipe */
2675 GNUNET_DISK_pipe_close_end(plugin->server_stdout, GNUNET_DISK_PIPE_END_WRITE); 2768 GNUNET_DISK_pipe_close_end (plugin->server_stdout,
2769 GNUNET_DISK_PIPE_END_WRITE);
2676 2770
2677 /* Close the read end of the write pipe */ 2771 /* Close the read end of the write pipe */
2678 GNUNET_DISK_pipe_close_end(plugin->server_stdin, GNUNET_DISK_PIPE_END_READ); 2772 GNUNET_DISK_pipe_close_end (plugin->server_stdin, GNUNET_DISK_PIPE_END_READ);
2679 2773
2680 plugin->server_stdout_handle = GNUNET_DISK_pipe_handle(plugin->server_stdout, 2774 plugin->server_stdout_handle = GNUNET_DISK_pipe_handle (plugin->server_stdout,
2681 GNUNET_DISK_PIPE_END_READ); 2775 GNUNET_DISK_PIPE_END_READ);
2682 plugin->server_stdin_handle = GNUNET_DISK_pipe_handle(plugin->server_stdin, 2776 plugin->server_stdin_handle = GNUNET_DISK_pipe_handle (plugin->server_stdin,
2683 GNUNET_DISK_PIPE_END_WRITE); 2777 GNUNET_DISK_PIPE_END_WRITE);
2684 2778
2685 GNUNET_assert(plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK); 2779 GNUNET_assert (plugin->server_read_task == GNUNET_SCHEDULER_NO_TASK);
2686 2780
2687#if DEBUG_wlan 2781#if DEBUG_wlan
2688 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2782 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2689 "Adding server_read_task for the wlan-helper\n"); 2783 "Adding server_read_task for the wlan-helper\n");
2690#endif 2784#endif
2691 2785
2692 plugin->server_read_task = GNUNET_SCHEDULER_add_read_file( 2786 plugin->server_read_task =
2693 GNUNET_TIME_UNIT_FOREVER_REL, plugin->server_stdout_handle, 2787 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
2694 &wlan_plugin_helper_read, plugin); 2788 plugin->server_stdout_handle,
2789 &wlan_plugin_helper_read, plugin);
2695 2790
2696 return GNUNET_YES; 2791 return GNUNET_YES;
2697} 2792}
@@ -2703,55 +2798,55 @@ wlan_transport_start_wlan_helper(struct Plugin *plugin, int testmode)
2703 2798
2704//FIXME cleanup 2799//FIXME cleanup
2705void * 2800void *
2706libgnunet_plugin_transport_wlan_done(void *cls) 2801libgnunet_plugin_transport_wlan_done (void *cls)
2707{ 2802{
2708 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 2803 struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
2709 struct Plugin *plugin = api->cls; 2804 struct Plugin *plugin = api->cls;
2710 struct MacEndpoint * endpoint = plugin->mac_head; 2805 struct MacEndpoint *endpoint = plugin->mac_head;
2711 struct MacEndpoint * endpoint_next; 2806 struct MacEndpoint *endpoint_next;
2712 2807
2713#if DEBUG_wlan 2808#if DEBUG_wlan
2714 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, 2809 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2715 "libgnunet_plugin_transport_wlan_done started\n"); 2810 "libgnunet_plugin_transport_wlan_done started\n");
2716#endif 2811#endif
2717 2812
2718 GNUNET_DISK_pipe_close(plugin->server_stdout); 2813 GNUNET_DISK_pipe_close (plugin->server_stdout);
2719 GNUNET_DISK_pipe_close(plugin->server_stdin); 2814 GNUNET_DISK_pipe_close (plugin->server_stdin);
2720 GNUNET_OS_process_kill(plugin->server_proc, 9); 2815 GNUNET_OS_process_kill (plugin->server_proc, 9);
2721 GNUNET_OS_process_close(plugin->server_proc); 2816 GNUNET_OS_process_close (plugin->server_proc);
2722 2817
2723 GNUNET_assert (cls !=NULL); 2818 GNUNET_assert (cls != NULL);
2724 //free sessions 2819 //free sessions
2725 while (endpoint != NULL) 2820 while (endpoint != NULL)
2726 { 2821 {
2727 endpoint_next = endpoint->next; 2822 endpoint_next = endpoint->next;
2728 free_macendpoint(plugin, endpoint); 2823 free_macendpoint (plugin, endpoint);
2729 endpoint = endpoint_next; 2824 endpoint = endpoint_next;
2730 2825
2731 } 2826 }
2732 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK) 2827 if (plugin->server_write_delay_task != GNUNET_SCHEDULER_NO_TASK)
2733 { 2828 {
2734 GNUNET_SCHEDULER_cancel(plugin->server_write_delay_task); 2829 GNUNET_SCHEDULER_cancel (plugin->server_write_delay_task);
2735 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 2830 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2736 } 2831 }
2737 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK) 2832 if (plugin->server_write_task != GNUNET_SCHEDULER_NO_TASK)
2738 { 2833 {
2739 GNUNET_SCHEDULER_cancel(plugin->server_write_task); 2834 GNUNET_SCHEDULER_cancel (plugin->server_write_task);
2740 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 2835 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2741 } 2836 }
2742 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK) 2837 if (plugin->server_read_task != GNUNET_SCHEDULER_NO_TASK)
2743 { 2838 {
2744 GNUNET_SCHEDULER_cancel(plugin->server_read_task); 2839 GNUNET_SCHEDULER_cancel (plugin->server_read_task);
2745 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2840 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2746 } 2841 }
2747 2842
2748 if (plugin->suid_tokenizer != NULL) 2843 if (plugin->suid_tokenizer != NULL)
2749 GNUNET_SERVER_mst_destroy(plugin->suid_tokenizer); 2844 GNUNET_SERVER_mst_destroy (plugin->suid_tokenizer);
2750 2845
2751 if (plugin->data_tokenizer != NULL) 2846 if (plugin->data_tokenizer != NULL)
2752 GNUNET_SERVER_mst_destroy(plugin->data_tokenizer); 2847 GNUNET_SERVER_mst_destroy (plugin->data_tokenizer);
2753 2848
2754 GNUNET_free_non_null(plugin->interface); 2849 GNUNET_free_non_null (plugin->interface);
2755 GNUNET_free (plugin); 2850 GNUNET_free (plugin);
2756 GNUNET_free (api); 2851 GNUNET_free (api);
2757 return NULL; 2852 return NULL;
@@ -2764,7 +2859,7 @@ libgnunet_plugin_transport_wlan_done(void *cls)
2764 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error 2859 * @return the 'struct GNUNET_TRANSPORT_PluginFunctions*' or NULL on error
2765 */ 2860 */
2766void * 2861void *
2767libgnunet_plugin_transport_wlan_init(void *cls) 2862libgnunet_plugin_transport_wlan_init (void *cls)
2768{ 2863{
2769 //struct GNUNET_SERVICE_Context *service; 2864 //struct GNUNET_SERVICE_Context *service;
2770 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; 2865 struct GNUNET_TRANSPORT_PluginEnvironment *env = cls;
@@ -2772,7 +2867,7 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2772 struct Plugin *plugin; 2867 struct Plugin *plugin;
2773 static unsigned long long testmode = 0; 2868 static unsigned long long testmode = 0;
2774 2869
2775 GNUNET_assert(cls !=NULL); 2870 GNUNET_assert (cls != NULL);
2776 2871
2777 plugin = GNUNET_malloc (sizeof (struct Plugin)); 2872 plugin = GNUNET_malloc (sizeof (struct Plugin));
2778 plugin->env = env; 2873 plugin->env = env;
@@ -2781,13 +2876,14 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2781 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK; 2876 plugin->server_write_task = GNUNET_SCHEDULER_NO_TASK;
2782 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK; 2877 plugin->server_read_task = GNUNET_SCHEDULER_NO_TASK;
2783 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK; 2878 plugin->server_write_delay_task = GNUNET_SCHEDULER_NO_TASK;
2784 GNUNET_BANDWIDTH_tracker_init(&plugin->tracker, 2879 GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
2785 GNUNET_BANDWIDTH_value_init(100 * 1024 * 1024 / 8), 100); 2880 GNUNET_BANDWIDTH_value_init (100 * 1024 *
2881 1024 / 8), 100);
2786 2882
2787 plugin->suid_tokenizer = GNUNET_SERVER_mst_create(&wlan_process_helper, 2883 plugin->suid_tokenizer = GNUNET_SERVER_mst_create (&wlan_process_helper,
2788 plugin); 2884 plugin);
2789 2885
2790 plugin->data_tokenizer = GNUNET_SERVER_mst_create(&process_data, plugin); 2886 plugin->data_tokenizer = GNUNET_SERVER_mst_create (&process_data, plugin);
2791 2887
2792 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue)); 2888 //plugin->sessions = GNUNET_malloc (sizeof (struct Sessionqueue));
2793 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue)); 2889 //plugin->pending_Sessions_head = GNUNET_malloc (sizeof (struct Sessionqueue));
@@ -2801,30 +2897,35 @@ libgnunet_plugin_transport_wlan_init(void *cls)
2801 api->address_to_string = &wlan_plugin_address_to_string; 2897 api->address_to_string = &wlan_plugin_address_to_string;
2802 //read config 2898 //read config
2803 2899
2804 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "TESTMODE")) 2900 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "TESTMODE"))
2805 { 2901 {
2806 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(env->cfg, 2902 if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (env->cfg,
2807 "transport-wlan", "TESTMODE", &testmode)) 2903 "transport-wlan",
2808 testmode = 0; //default value 2904 "TESTMODE",
2809 } 2905 &testmode))
2906 testmode = 0; //default value
2907 }
2810 2908
2811 if (GNUNET_CONFIGURATION_have_value(env->cfg, "transport-wlan", "INTERFACE")) 2909 if (GNUNET_CONFIGURATION_have_value (env->cfg, "transport-wlan", "INTERFACE"))
2910 {
2911 if (GNUNET_CONFIGURATION_get_value_string (env->cfg, "transport-wlan",
2912 "INTERFACE",
2913 &(plugin->interface)) !=
2914 GNUNET_YES)
2812 { 2915 {
2813 if (GNUNET_CONFIGURATION_get_value_string(env->cfg, "transport-wlan", 2916 libgnunet_plugin_transport_wlan_done (api);
2814 "INTERFACE", &(plugin->interface)) != GNUNET_YES) 2917 return NULL;
2815 {
2816 libgnunet_plugin_transport_wlan_done(api);
2817 return NULL;
2818 }
2819 } 2918 }
2919 }
2820 2920
2821 //start the plugin 2921 //start the plugin
2822 set_next_beacon_time(plugin); 2922 set_next_beacon_time (plugin);
2823 2923
2824 wlan_transport_start_wlan_helper(plugin, testmode); 2924 wlan_transport_start_wlan_helper (plugin, testmode);
2825 2925
2826#if DEBUG_wlan 2926#if DEBUG_wlan
2827 GNUNET_log_from(GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME, "wlan init finished\n"); 2927 GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, PLUGIN_LOG_NAME,
2928 "wlan init finished\n");
2828#endif 2929#endif
2829 2930
2830 return api; 2931 return api;
diff --git a/src/transport/plugin_transport_wlan.h b/src/transport/plugin_transport_wlan.h
index 8528d984a..aa6a8aa52 100644
--- a/src/transport/plugin_transport_wlan.h
+++ b/src/transport/plugin_transport_wlan.h
@@ -72,41 +72,39 @@ struct WlanHeader
72 72
73/* Wlan IEEE80211 header default */ 73/* Wlan IEEE80211 header default */
74//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html 74//Informations (in German) http://www.umtslink.at/content/WLAN_macheader-196.html
75static const uint8_t u8aIeeeHeader[] = 75static const uint8_t u8aIeeeHeader[] = { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0;
76 { 0x08, 0x01, // Frame Control 0x08= 00001000 -> | b1,2 = 0 -> Version 0; 76 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data
77 // b3,4 = 10 -> Data; b5-8 = 0 -> Normal Data 77 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS;
78 // 0x01 = 00000001 -> | b1 = 1 to DS; b2 = 0 not from DS; 78 0x00, 0x00, // Duration/ID
79 0x00, 0x00, // Duration/ID 79 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver
80 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // mac1 - in this case receiver 80 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender
81 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac2 - in this case sender 81 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid
82 0x13, 0x22, 0x33, 0x44, 0x55, 0x66, // mac3 - in this case bssid 82 0x10, 0x86, //Sequence Control
83 0x10, 0x86, //Sequence Control 83};
84 };
85 84
86// gnunet bssid 85// gnunet bssid
87static const struct MacAddress mac_bssid = 86static const struct MacAddress mac_bssid = {
88 { 87 {0x13, 0x22, 0x33, 0x44, 0x55, 0x66}
89 { 0x13, 0x22, 0x33, 0x44, 0x55, 0x66 } }; 88};
90 89
91// broadcast mac 90// broadcast mac
92static const struct MacAddress bc_all_mac = 91static const struct MacAddress bc_all_mac = {
93 { 92 {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}
94 { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF } }; 93};
95 94
96/* this is the template radiotap header we send packets out with */ 95/* this is the template radiotap header we send packets out with */
97 96
98static const uint8_t u8aRadiotapHeader[] = 97static const uint8_t u8aRadiotapHeader[] = { 0x00, 0x00, // <-- radiotap version
99 { 0x00, 0x00, // <-- radiotap version 98 0x19, 0x00, // <- radiotap header length
100 0x19, 0x00, // <- radiotap header length 99 0x6f, 0x08, 0x00, 0x00, // <-- bitmap
101 0x6f, 0x08, 0x00, 0x00, // <-- bitmap 100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp
102 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // <-- timestamp 101 0x00, // <-- flags (Offset +0x10)
103 0x00, // <-- flags (Offset +0x10) 102 0x6c, // <-- rate (0ffset +0x11)
104 0x6c, // <-- rate (0ffset +0x11) 103 0x71, 0x09, 0xc0, 0x00, // <-- channel
105 0x71, 0x09, 0xc0, 0x00, // <-- channel 104 0xde, // <-- antsignal
106 0xde, // <-- antsignal 105 0x00, // <-- antnoise
107 0x00, // <-- antnoise 106 0x01, // <-- antenna
108 0x01, // <-- antenna 107};
109 };
110 108
111struct Radiotap_Send 109struct Radiotap_Send
112{ 110{
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c
index 0c335d6ba..e66e04ead 100644
--- a/src/transport/test_plugin_transport.c
+++ b/src/transport/test_plugin_transport.c
@@ -90,9 +90,8 @@ static void
90receive (void *cls, 90receive (void *cls,
91 const struct GNUNET_PeerIdentity 91 const struct GNUNET_PeerIdentity
92 *peer, const struct GNUNET_MessageHeader *message, 92 *peer, const struct GNUNET_MessageHeader *message,
93 uint32_t distance, 93 uint32_t distance,
94 const char *sender_address, 94 const char *sender_address, size_t sender_address_len)
95 size_t sender_address_len)
96{ 95{
97 /* do nothing */ 96 /* do nothing */
98} 97}
@@ -116,8 +115,7 @@ static void
116unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 115unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
117{ 116{
118 GNUNET_assert (NULL == 117 GNUNET_assert (NULL ==
119 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp", 118 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_tcp", api));
120 api));
121 if (my_private_key != NULL) 119 if (my_private_key != NULL)
122 GNUNET_CRYPTO_rsa_key_free (my_private_key); 120 GNUNET_CRYPTO_rsa_key_free (my_private_key);
123 121
@@ -128,6 +126,7 @@ static void
128unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 126unload_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
129{ 127{
130 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 128 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
129
131 unload_plugins (NULL, cfg); 130 unload_plugins (NULL, cfg);
132} 131}
133 132
@@ -160,8 +159,7 @@ test_validation ()
160 soaddr.sin_port = htons (2368 /* FIXME: get from config! */ ); 159 soaddr.sin_port = htons (2368 /* FIXME: get from config! */ );
161 soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 160 soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
162 GNUNET_assert (GNUNET_OK == 161 GNUNET_assert (GNUNET_OK ==
163 api->check_address (api->cls, 162 api->check_address (api->cls, &soaddr, sizeof (soaddr)));
164 &soaddr, sizeof (soaddr)));
165 ok = 0; 163 ok = 0;
166 GNUNET_SCHEDULER_add_continuation (&unload_task, 164 GNUNET_SCHEDULER_add_continuation (&unload_task,
167 (void *) cfg, 165 (void *) cfg,
@@ -207,24 +205,23 @@ run (void *cls,
207 GNUNET_CONFIGURATION_get_value_filename (c, 205 GNUNET_CONFIGURATION_get_value_filename (c,
208 "GNUNETD", 206 "GNUNETD",
209 "HOSTKEY", &keyfile))) 207 "HOSTKEY", &keyfile)))
210 { 208 {
211 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
212 _ 210 _
213 ("Transport service is lacking key configuration settings. Exiting.\n")); 211 ("Transport service is lacking key configuration settings. Exiting.\n"));
214 GNUNET_SCHEDULER_shutdown (s); 212 GNUNET_SCHEDULER_shutdown (s);
215 return; 213 return;
216 } 214 }
217 max_connect_per_transport = (uint32_t) tneigh; 215 max_connect_per_transport = (uint32_t) tneigh;
218 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 216 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
219 GNUNET_free (keyfile); 217 GNUNET_free (keyfile);
220 if (my_private_key == NULL) 218 if (my_private_key == NULL)
221 { 219 {
222 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 220 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
223 _ 221 _("Transport service could not access hostkey. Exiting.\n"));
224 ("Transport service could not access hostkey. Exiting.\n")); 222 GNUNET_SCHEDULER_shutdown (s);
225 GNUNET_SCHEDULER_shutdown (s); 223 return;
226 return; 224 }
227 }
228 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 225 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
229 GNUNET_CRYPTO_hash (&my_public_key, 226 GNUNET_CRYPTO_hash (&my_public_key,
230 sizeof (my_public_key), &my_identity.hashPubKey); 227 sizeof (my_public_key), &my_identity.hashPubKey);
@@ -239,12 +236,12 @@ run (void *cls,
239 api = GNUNET_PLUGIN_load (libname, &env); 236 api = GNUNET_PLUGIN_load (libname, &env);
240 GNUNET_free (libname); 237 GNUNET_free (libname);
241 if (api == NULL) 238 if (api == NULL)
242 { 239 {
243 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 240 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
244 _("Failed to load transport plugin for tcp\n")); 241 _("Failed to load transport plugin for tcp\n"));
245 /* FIXME: set some error code for main */ 242 /* FIXME: set some error code for main */
246 return; 243 return;
247 } 244 }
248 test_validation (); 245 test_validation ();
249} 246}
250 247
@@ -263,6 +260,7 @@ main (int argc, char *const *argv)
263 GNUNET_GETOPT_OPTION_END 260 GNUNET_GETOPT_OPTION_END
264 }; 261 };
265 int ret; 262 int ret;
263
266 char *const argv_prog[] = { 264 char *const argv_prog[] = {
267 "test_plugin_transport", 265 "test_plugin_transport",
268 "-c", 266 "-c",
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 5ba8c573a..921f9ec32 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -75,12 +75,12 @@ struct Plugin_Address
75 /** 75 /**
76 * Next field for linked list 76 * Next field for linked list
77 */ 77 */
78 struct Plugin_Address * next; 78 struct Plugin_Address *next;
79 79
80 /** 80 /**
81 * buffer containing data to send 81 * buffer containing data to send
82 */ 82 */
83 void * addr; 83 void *addr;
84 84
85 /** 85 /**
86 * amount of data to sent 86 * amount of data to sent
@@ -162,9 +162,9 @@ struct HTTP_Transfer
162 */ 162 */
163struct IPv4HttpAddress 163struct IPv4HttpAddress
164{ 164{
165 struct IPv4HttpAddress * next; 165 struct IPv4HttpAddress *next;
166 166
167 struct IPv4HttpAddress * prev; 167 struct IPv4HttpAddress *prev;
168 168
169 /** 169 /**
170 * IPv4 address, in network byte order. 170 * IPv4 address, in network byte order.
@@ -184,9 +184,9 @@ struct IPv4HttpAddress
184 */ 184 */
185struct IPv6HttpAddress 185struct IPv6HttpAddress
186{ 186{
187 struct IPv6HttpAddress * next; 187 struct IPv6HttpAddress *next;
188 188
189 struct IPv6HttpAddress * prev; 189 struct IPv6HttpAddress *prev;
190 190
191 /** 191 /**
192 * IPv6 address. 192 * IPv6 address.
@@ -229,7 +229,7 @@ static long long unsigned int port;
229/** 229/**
230 * Peer's addr 230 * Peer's addr
231 */ 231 */
232static char * test_addr; 232static char *test_addr;
233 233
234/** 234/**
235 * Our statistics handle. 235 * Our statistics handle.
@@ -277,12 +277,13 @@ static struct HTTP_Message buffer_out;
277static struct HTTP_Message buffer_in; 277static struct HTTP_Message buffer_in;
278 278
279 279
280struct Plugin_Address * addr_head; 280struct Plugin_Address *addr_head;
281 281
282/** 282/**
283 * Did the test pass or fail? 283 * Did the test pass or fail?
284 */ 284 */
285static int fail_notify_address; 285static int fail_notify_address;
286
286/** 287/**
287 * Did the test pass or fail? 288 * Did the test pass or fail?
288 */ 289 */
@@ -386,7 +387,7 @@ static CURLM *multi_handle;
386 */ 387 */
387static GNUNET_SCHEDULER_TaskIdentifier http_task_send; 388static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
388 389
389static char * servicehome; 390static char *servicehome;
390 391
391/** 392/**
392 * Shutdown testcase 393 * Shutdown testcase
@@ -394,53 +395,51 @@ static char * servicehome;
394static void 395static void
395shutdown_clean () 396shutdown_clean ()
396{ 397{
397 struct Plugin_Address * tmp; 398 struct Plugin_Address *tmp;
398 399
399 /* Evaluate results */ 400 /* Evaluate results */
400 fail = 0; 401 fail = 0;
401 if ( (fail_notify_address == GNUNET_YES) || 402 if ((fail_notify_address == GNUNET_YES) ||
402 (fail_pretty_printer == GNUNET_YES) || 403 (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES))
403 (fail_addr_to_str == GNUNET_YES)) 404 {
404 { 405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 406 "Phase 0: Test plugin functions failed\n");
406 "Phase 0: Test plugin functions failed\n"); 407 fail = 1;
407 fail = 1; 408 }
408 } 409 if ((test_no_ident.test_failed == GNUNET_YES) ||
409 if ( (test_no_ident.test_failed == GNUNET_YES) || 410 (test_too_short_ident.test_failed == GNUNET_YES) ||
410 (test_too_short_ident.test_failed == GNUNET_YES) || 411 (test_too_long_ident.test_failed == GNUNET_YES) ||
411 (test_too_long_ident.test_failed == GNUNET_YES) || 412 (test_valid_ident.test_failed == GNUNET_YES))
412 (test_valid_ident.test_failed == GNUNET_YES) )
413 { 413 {
414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
415 "Phase 1: Test connect with wrong data failed\n"); 415 "Phase 1: Test connect with wrong data failed\n");
416 fail = 1; 416 fail = 1;
417 } 417 }
418 if ( (fail_session_selection_any != GNUNET_NO) || 418 if ((fail_session_selection_any != GNUNET_NO) ||
419 (fail_session_selection_reliable != GNUNET_NO) || 419 (fail_session_selection_reliable != GNUNET_NO) ||
420 (fail_session_selection_session != GNUNET_NO) || 420 (fail_session_selection_session != GNUNET_NO) ||
421 (fail_session_selection_session_big != GNUNET_NO) ) 421 (fail_session_selection_session_big != GNUNET_NO))
422 { 422 {
423 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 423 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
424 "Phase 2: Test session selection failed\n"); 424 "Phase 2: Test session selection failed\n");
425 fail = 1; 425 fail = 1;
426 } 426 }
427 if ( (fail_msgs_transmited_to_local_addrs != count_str_addr) || 427 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) ||
428 (fail_multiple_msgs_in_transmission != 2) || 428 (fail_multiple_msgs_in_transmission != 2) ||
429 (fail_msg_transmited_max_size == GNUNET_YES) ) 429 (fail_msg_transmited_max_size == GNUNET_YES))
430 { 430 {
431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
432 "Phase 3: Test sending with plugin failed\n"); 432 "Phase 3: Test sending with plugin failed\n");
433 fail = 1; 433 fail = 1;
434 } 434 }
435 if (fail != 1) 435 if (fail != 1)
436 { 436 {
437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 437 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
438 "All tests successful\n"); 438 }
439 } 439
440 440 api->disconnect (api->cls, &my_identity);
441 api->disconnect(api->cls,&my_identity);
442 441
443 curl_multi_cleanup(multi_handle); 442 curl_multi_cleanup (multi_handle);
444 443
445 if (NULL != curl_handle) 444 if (NULL != curl_handle)
446 curl_easy_cleanup (curl_handle); 445 curl_easy_cleanup (curl_handle);
@@ -451,37 +450,37 @@ shutdown_clean ()
451 tmp = addr_head->next; 450 tmp = addr_head->next;
452 GNUNET_free (addr_head->addr); 451 GNUNET_free (addr_head->addr);
453 GNUNET_free (addr_head); 452 GNUNET_free (addr_head);
454 addr_head=tmp; 453 addr_head = tmp;
455 } 454 }
456 455
457 if (ti_send != GNUNET_SCHEDULER_NO_TASK) 456 if (ti_send != GNUNET_SCHEDULER_NO_TASK)
458 { 457 {
459 GNUNET_SCHEDULER_cancel(ti_send); 458 GNUNET_SCHEDULER_cancel (ti_send);
460 ti_send = GNUNET_SCHEDULER_NO_TASK; 459 ti_send = GNUNET_SCHEDULER_NO_TASK;
461 } 460 }
462 461
463 if (http_task_send != GNUNET_SCHEDULER_NO_TASK) 462 if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
464 { 463 {
465 GNUNET_SCHEDULER_cancel(http_task_send); 464 GNUNET_SCHEDULER_cancel (http_task_send);
466 http_task_send = GNUNET_SCHEDULER_NO_TASK; 465 http_task_send = GNUNET_SCHEDULER_NO_TASK;
467 } 466 }
468 467
469 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK) 468 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
470 { 469 {
471 GNUNET_SCHEDULER_cancel(ti_timeout); 470 GNUNET_SCHEDULER_cancel (ti_timeout);
472 ti_timeout = GNUNET_SCHEDULER_NO_TASK; 471 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
473 } 472 }
474 473
475 GNUNET_free(test_addr); 474 GNUNET_free (test_addr);
476 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading http plugin\n");
477 "Unloading http plugin\n"); 476 GNUNET_assert (NULL ==
478 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin_http", api)); 477 GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin_http",
478 api));
479 479
480 GNUNET_SCHEDULER_shutdown(); 480 GNUNET_SCHEDULER_shutdown ();
481 GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http"); 481 GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin_http");
482 482
483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 483 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Exiting testcase\n");
484 "Exiting testcase\n");
485 484
486 if (servicehome != NULL) 485 if (servicehome != NULL)
487 { 486 {
@@ -489,7 +488,7 @@ shutdown_clean ()
489 GNUNET_free (servicehome); 488 GNUNET_free (servicehome);
490 } 489 }
491 490
492 exit(fail); 491 exit (fail);
493 return; 492 return;
494} 493}
495 494
@@ -502,102 +501,98 @@ shutdown_clean ()
502 */ 501 */
503 502
504static void 503static void
505task_send_cont (void *cls, 504task_send_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result)
506 const struct GNUNET_PeerIdentity * target,
507 int result)
508{ 505{
509 if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR)) 506 if ((cls == &fail_msg_transmited_bigger_max_size) &&
510 { 507 (result == GNUNET_SYSERR))
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 508 {
512 "Message bigger max msg size was not sent!\n"); 509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
513 fail_msg_transmited_bigger_max_size = GNUNET_NO; 510 "Message bigger max msg size was not sent!\n");
514 return; 511 fail_msg_transmited_bigger_max_size = GNUNET_NO;
515 } 512 return;
513 }
516 514
517 if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK)) 515 if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
518 { 516 {
519 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 517 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
520 "Message with max msg size succesfully sent!\n", 518 "Message with max msg size succesfully sent!\n",
521 fail_msgs_transmited_to_local_addrs); 519 fail_msgs_transmited_to_local_addrs);
522 fail_msg_transmited_max_size = GNUNET_NO; 520 fail_msg_transmited_max_size = GNUNET_NO;
523 } 521 }
524} 522}
525 523
526 524
527static void run_connection_tests( int phase , void * cls); 525static void run_connection_tests (int phase, void *cls);
528 526
529/** 527/**
530 * Recieves messages from plugin, in real world transport 528 * Recieves messages from plugin, in real world transport
531 */ 529 */
532static struct GNUNET_TIME_Relative 530static struct GNUNET_TIME_Relative
533receive (void *cls, const struct GNUNET_PeerIdentity *peer, 531receive (void *cls, const struct GNUNET_PeerIdentity *peer,
534 const struct GNUNET_MessageHeader *message, 532 const struct GNUNET_MessageHeader *message,
535 const struct GNUNET_TRANSPORT_ATS_Information *ats, 533 const struct GNUNET_TRANSPORT_ATS_Information *ats,
536 uint32_t ats_count, 534 uint32_t ats_count,
537 struct Session *session, 535 struct Session *session,
538 const char *sender_address, 536 const char *sender_address, uint16_t sender_address_len)
539 uint16_t sender_address_len)
540{ 537{
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
542 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", 539 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
543 GNUNET_i2s(peer), 540 GNUNET_i2s (peer),
544 ntohs(message->type), 541 ntohs (message->type), ntohs (message->size), session);
545 ntohs(message->size),
546 session);
547 542
548 if ( (ntohs(message->type)>=10) && 543 if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
549 (ntohs(message->type)<20) ) 544 {
550 { 545 fail_msgs_transmited_to_local_addrs++;
551 fail_msgs_transmited_to_local_addrs++; 546 if (fail_msgs_transmited_to_local_addrs == count_str_addr)
552 if (fail_msgs_transmited_to_local_addrs == count_str_addr) 547 run_connection_tests (2, session);
553 run_connection_tests(2, session); 548 }
554 } 549 if ((ntohs (message->type) == 20))
555 if ((ntohs(message->type)==20)) 550 {
556 { 551 fail_session_selection_reliable = GNUNET_NO;
557 fail_session_selection_reliable = GNUNET_NO; 552 }
558 } 553 if ((ntohs (message->type) == 21))
559 if ((ntohs(message->type)==21)) 554 {
560 { 555 fail_session_selection_any = GNUNET_NO;
561 fail_session_selection_any = GNUNET_NO; 556 }
562 } 557 if ((ntohs (message->type) == 22))
563 if ((ntohs(message->type)==22)) 558 {
564 { 559 fail_session_selection_session = GNUNET_NO;
565 fail_session_selection_session = GNUNET_NO; 560 }
566 } 561 if ((ntohs (message->type) == 23))
567 if ((ntohs(message->type)==23)) 562 {
568 { 563 fail_session_selection_session_big = GNUNET_NO;
569 fail_session_selection_session_big = GNUNET_NO; 564 run_connection_tests (3, NULL);
570 run_connection_tests(3, NULL); 565 }
571 } 566 if ((ntohs (message->type) == 30) || (ntohs (message->type) == 31))
572 if ((ntohs(message->type)==30) || (ntohs(message->type)==31)) 567 {
573 { 568 fail_multiple_msgs_in_transmission++;
574 fail_multiple_msgs_in_transmission ++; 569 }
575 } 570 if ((ntohs (message->type) == 32) &&
576 if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1)) 571 (ntohs (message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE - 1))
577 { 572 {
578 fail_msg_transmited_max_size = GNUNET_NO; 573 fail_msg_transmited_max_size = GNUNET_NO;
579 shutdown_clean(); 574 shutdown_clean ();
580 } 575 }
581 return GNUNET_TIME_UNIT_ZERO; 576 return GNUNET_TIME_UNIT_ZERO;
582} 577}
583 578
584 579
585static size_t 580static size_t
586send_function (void *stream, size_t size, size_t nmemb, void *ptr) 581send_function (void *stream, size_t size, size_t nmemb, void *ptr)
587{ 582{
588 unsigned int len; 583 unsigned int len;
589 584
590 len = buffer_out.len; 585 len = buffer_out.len;
591 586
592 if (( buffer_out.pos == len) || (len > (size * nmemb))) 587 if ((buffer_out.pos == len) || (len > (size * nmemb)))
593 return 0; 588 return 0;
594 memcpy(stream, buffer_out.buf, len); 589 memcpy (stream, buffer_out.buf, len);
595 buffer_out.pos = len; 590 buffer_out.pos = len;
596 return len; 591 return len;
597 592
598} 593}
599 594
600static size_t 595static size_t
601recv_function (void *ptr, size_t size, size_t nmemb, void *ctx) 596recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
602{ 597{
603 598
@@ -613,54 +608,50 @@ recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
613} 608}
614 609
615static size_t 610static size_t
616header_function( void *ptr, size_t size, size_t nmemb, void *stream) 611header_function (void *ptr, size_t size, size_t nmemb, void *stream)
617{ 612{
618 struct HTTP_Transfer * res = stream; 613 struct HTTP_Transfer *res = stream;
619 char * tmp; 614 char *tmp;
620 unsigned int len = size * nmemb; 615 unsigned int len = size * nmemb;
621 616
622 tmp = GNUNET_malloc ( len+1 ); 617 tmp = GNUNET_malloc (len + 1);
623 memcpy(tmp,ptr,len); 618 memcpy (tmp, ptr, len);
624 if (tmp[len-2] == 13) 619 if (tmp[len - 2] == 13)
625 tmp[len-2]= '\0'; 620 tmp[len - 2] = '\0';
626#if DEBUG_CURL 621#if DEBUG_CURL
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 622 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n", tmp);
628 "Header: `%s'\n",
629 tmp);
630#endif 623#endif
631 if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) 624 if (0 == strcmp (tmp, "HTTP/1.1 100 Continue"))
632 { 625 {
633 res->http_result_code=100; 626 res->http_result_code = 100;
634 } 627 }
635 if (0==strcmp (tmp,"HTTP/1.1 200 OK")) 628 if (0 == strcmp (tmp, "HTTP/1.1 200 OK"))
636 { 629 {
637 res->http_result_code=200; 630 res->http_result_code = 200;
638 } 631 }
639 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request")) 632 if (0 == strcmp (tmp, "HTTP/1.1 400 Bad Request"))
640 { 633 {
641 res->http_result_code=400; 634 res->http_result_code = 400;
642 } 635 }
643 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) 636 if (0 == strcmp (tmp, "HTTP/1.1 404 Not Found"))
644 { 637 {
645 res->http_result_code=404; 638 res->http_result_code = 404;
646 } 639 }
647 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large")) 640 if (0 == strcmp (tmp, "HTTP/1.1 413 Request entity too large"))
648 { 641 {
649 res->http_result_code=413; 642 res->http_result_code = 413;
650 } 643 }
651 644
652 GNUNET_free (tmp); 645 GNUNET_free (tmp);
653 return size * nmemb; 646 return size * nmemb;
654} 647}
655 648
656 649
657static size_t 650static size_t send_prepare (struct HTTP_Transfer *result);
658send_prepare( struct HTTP_Transfer * result);
659 651
660 652
661static void 653static void
662send_execute (void *cls, 654send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
663 const struct GNUNET_SCHEDULER_TaskContext *tc)
664{ 655{
665 struct HTTP_Transfer *res; 656 struct HTTP_Transfer *res;
666 657
@@ -674,104 +665,106 @@ send_execute (void *cls,
674 return; 665 return;
675 666
676 do 667 do
668 {
669 running = 0;
670 mret = curl_multi_perform (multi_handle, &running);
671 if (running == 0)
677 { 672 {
678 running = 0; 673 do
679 mret = curl_multi_perform (multi_handle, &running); 674 {
680 if (running == 0)
681 {
682 do
683 {
684 675
685 msg = curl_multi_info_read (multi_handle, &running); 676 msg = curl_multi_info_read (multi_handle, &running);
686 if (msg == NULL) 677 if (msg == NULL)
687 break; 678 break;
688 /* get session for affected curl handle */ 679 /* get session for affected curl handle */
689 //cs = find_session_by_curlhandle (msg->easy_handle); 680 //cs = find_session_by_curlhandle (msg->easy_handle);
690 //GNUNET_assert ( cs != NULL ); 681 //GNUNET_assert ( cs != NULL );
691 switch (msg->msg) 682 switch (msg->msg)
692 { 683 {
693
694 case CURLMSG_DONE:
695 if ( (msg->data.result != CURLE_OK) &&
696 (msg->data.result != CURLE_GOT_NOTHING) )
697 {
698
699 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
700 _("curl failed for `%s' at %s:%d: `%s'\n"),
701 "curl_multi_perform",
702 __FILE__,
703 __LINE__,
704 curl_easy_strerror (msg->data.result));
705 /* sending msg failed*/
706 curl_easy_cleanup(curl_handle);
707 curl_handle=NULL;
708
709 run_connection_tests(0, NULL);
710 }
711 if (res == &test_no_ident)
712 {
713 if ((res->http_result_code==404) && (buffer_in.len==208))
714 {
715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
716 "Connecting to peer without any peer identification: test passed\n");
717 res->test_failed = GNUNET_NO;
718 }
719 else
720 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
721 _("Connecting to peer without any peer identification: test failed\n"));
722 }
723 if (res == &test_too_short_ident)
724 {
725 if ((res->http_result_code==404) && (buffer_in.len==208))
726 {
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
728 "Connecting to peer with too short peer identification: test passed\n");
729 res->test_failed = GNUNET_NO;
730 }
731 else
732 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
733 _("Connecting to peer with too short peer identification: test failed\n"));
734 }
735 if (res == &test_too_long_ident)
736 {
737 if ((res->http_result_code==404) && (buffer_in.len==208))
738 {
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
740 "Connecting to peer with too long peer identification: test passed\n");
741 res->test_failed = GNUNET_NO;
742 }
743 else
744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
745 _("Connecting to peer with too long peer identification: test failed\n"));
746 }
747 if (res == &test_valid_ident)
748 {
749 if ((res->http_result_code==200))
750 {
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Connecting to peer with valid peer identification: test passed\n");
753 res->test_failed = GNUNET_NO;
754 }
755 else
756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
757 "Connecting to peer with valid peer identification: test failed\n");
758 }
759 curl_easy_cleanup(curl_handle);
760 curl_handle=NULL;
761 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
762 run_connection_tests(1, NULL);
763 run_connection_tests(0, NULL);
764 return;
765 default:
766 break;
767 }
768 684
685 case CURLMSG_DONE:
686 if ((msg->data.result != CURLE_OK) &&
687 (msg->data.result != CURLE_GOT_NOTHING))
688 {
689
690 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
691 _("curl failed for `%s' at %s:%d: `%s'\n"),
692 "curl_multi_perform",
693 __FILE__,
694 __LINE__, curl_easy_strerror (msg->data.result));
695 /* sending msg failed */
696 curl_easy_cleanup (curl_handle);
697 curl_handle = NULL;
698
699 run_connection_tests (0, NULL);
700 }
701 if (res == &test_no_ident)
702 {
703 if ((res->http_result_code == 404) && (buffer_in.len == 208))
704 {
705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
706 "Connecting to peer without any peer identification: test passed\n");
707 res->test_failed = GNUNET_NO;
708 }
709 else
710 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
711 _
712 ("Connecting to peer without any peer identification: test failed\n"));
713 }
714 if (res == &test_too_short_ident)
715 {
716 if ((res->http_result_code == 404) && (buffer_in.len == 208))
717 {
718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
719 "Connecting to peer with too short peer identification: test passed\n");
720 res->test_failed = GNUNET_NO;
721 }
722 else
723 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
724 _
725 ("Connecting to peer with too short peer identification: test failed\n"));
726 }
727 if (res == &test_too_long_ident)
728 {
729 if ((res->http_result_code == 404) && (buffer_in.len == 208))
730 {
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "Connecting to peer with too long peer identification: test passed\n");
733 res->test_failed = GNUNET_NO;
769 } 734 }
770 while ( (running > 0) ); 735 else
736 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
737 _
738 ("Connecting to peer with too long peer identification: test failed\n"));
739 }
740 if (res == &test_valid_ident)
741 {
742 if ((res->http_result_code == 200))
743 {
744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "Connecting to peer with valid peer identification: test passed\n");
746 res->test_failed = GNUNET_NO;
747 }
748 else
749 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
750 "Connecting to peer with valid peer identification: test failed\n");
751 }
752 curl_easy_cleanup (curl_handle);
753 curl_handle = NULL;
754 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
755 run_connection_tests (1, NULL);
756 run_connection_tests (0, NULL);
757 return;
758 default:
759 break;
771 } 760 }
761
762 }
763 while ((running > 0));
772 } 764 }
765 }
773 while (mret == CURLM_CALL_MULTI_PERFORM); 766 while (mret == CURLM_CALL_MULTI_PERFORM);
774 send_prepare(cls); 767 send_prepare (cls);
775} 768}
776 769
777 770
@@ -781,7 +774,7 @@ send_execute (void *cls,
781 * @return bytes sent to peer 774 * @return bytes sent to peer
782 */ 775 */
783static size_t 776static size_t
784send_prepare( struct HTTP_Transfer * result) 777send_prepare (struct HTTP_Transfer *result)
785{ 778{
786 fd_set rs; 779 fd_set rs;
787 fd_set ws; 780 fd_set ws;
@@ -798,34 +791,33 @@ send_prepare( struct HTTP_Transfer * result)
798 FD_ZERO (&es); 791 FD_ZERO (&es);
799 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); 792 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
800 if (mret != CURLM_OK) 793 if (mret != CURLM_OK)
801 { 794 {
802 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
803 _("%s failed at %s:%d: `%s'\n"), 796 _("%s failed at %s:%d: `%s'\n"),
804 "curl_multi_fdset", __FILE__, __LINE__, 797 "curl_multi_fdset", __FILE__, __LINE__,
805 curl_multi_strerror (mret)); 798 curl_multi_strerror (mret));
806 return -1; 799 return -1;
807 } 800 }
808 mret = curl_multi_timeout (multi_handle, &to); 801 mret = curl_multi_timeout (multi_handle, &to);
809 if (mret != CURLM_OK) 802 if (mret != CURLM_OK)
810 { 803 {
811 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
812 _("%s failed at %s:%d: `%s'\n"), 805 _("%s failed at %s:%d: `%s'\n"),
813 "curl_multi_timeout", __FILE__, __LINE__, 806 "curl_multi_timeout", __FILE__, __LINE__,
814 curl_multi_strerror (mret)); 807 curl_multi_strerror (mret));
815 return -1; 808 return -1;
816 } 809 }
817 810
818 grs = GNUNET_NETWORK_fdset_create (); 811 grs = GNUNET_NETWORK_fdset_create ();
819 gws = GNUNET_NETWORK_fdset_create (); 812 gws = GNUNET_NETWORK_fdset_create ();
820 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 813 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
821 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 814 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
822 http_task_send = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 815 http_task_send =
823 GNUNET_SCHEDULER_NO_TASK, 816 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
824 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), 817 GNUNET_SCHEDULER_NO_TASK,
825 grs, 818 GNUNET_TIME_relative_multiply
826 gws, 819 (GNUNET_TIME_UNIT_SECONDS, 0), grs, gws,
827 &send_execute, 820 &send_execute, result);
828 result);
829 GNUNET_NETWORK_fdset_destroy (gws); 821 GNUNET_NETWORK_fdset_destroy (gws);
830 GNUNET_NETWORK_fdset_destroy (grs); 822 GNUNET_NETWORK_fdset_destroy (grs);
831 823
@@ -836,35 +828,35 @@ send_prepare( struct HTTP_Transfer * result)
836/** 828/**
837 * function to send data to server 829 * function to send data to server
838 */ 830 */
839static int 831static int
840send_data(struct HTTP_Transfer * result, 832send_data (struct HTTP_Transfer *result, char *url)
841 char * url)
842{ 833{
843 834
844 curl_handle = curl_easy_init(); 835 curl_handle = curl_easy_init ();
845 if( NULL == curl_handle) 836 if (NULL == curl_handle)
846 { 837 {
847 printf("easy_init failed \n"); 838 printf ("easy_init failed \n");
848 return GNUNET_SYSERR; 839 return GNUNET_SYSERR;
849 } 840 }
850#if DEBUG_CURL 841#if DEBUG_CURL
851 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); 842 curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 1L);
852#endif 843#endif
853 curl_easy_setopt(curl_handle, CURLOPT_URL, url); 844 curl_easy_setopt (curl_handle, CURLOPT_URL, url);
854 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L); 845 curl_easy_setopt (curl_handle, CURLOPT_PUT, 1L);
855 curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function); 846 curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
856 curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result); 847 curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
857 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function); 848 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
858 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); 849 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
859 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function); 850 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
860 curl_easy_setopt (curl_handle, CURLOPT_READDATA, result); 851 curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
861 curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len); 852 curl_easy_setopt (curl_handle, CURLOPT_INFILESIZE_LARGE,
862 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); 853 (curl_off_t) buffer_out.len);
863 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); 854 curl_easy_setopt (curl_handle, CURLOPT_TIMEOUT, 30);
855 curl_easy_setopt (curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
864 856
865 curl_multi_add_handle(multi_handle, curl_handle); 857 curl_multi_add_handle (multi_handle, curl_handle);
866 858
867 send_prepare(result); 859 send_prepare (result);
868 860
869 return GNUNET_OK; 861 return GNUNET_OK;
870} 862}
@@ -873,58 +865,54 @@ send_data(struct HTTP_Transfer * result,
873 * Plugin notifies transport (aka testcase) about its addresses 865 * Plugin notifies transport (aka testcase) about its addresses
874 */ 866 */
875static void 867static void
876notify_address (void *cls, 868notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
877 int add_remove,
878 const void *addr,
879 size_t addrlen)
880{ 869{
881 char address[INET6_ADDRSTRLEN]; 870 char address[INET6_ADDRSTRLEN];
882 unsigned int port; 871 unsigned int port;
883 struct Plugin_Address * pl_addr; 872 struct Plugin_Address *pl_addr;
884 struct Plugin_Address * cur; 873 struct Plugin_Address *cur;
885 874
886 if (addrlen == (sizeof (struct IPv4HttpAddress))) 875 if (addrlen == (sizeof (struct IPv4HttpAddress)))
887 { 876 {
888 inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN); 877 inet_ntop (AF_INET, (struct in_addr *) addr, address, INET_ADDRSTRLEN);
889 port = ntohs(((struct IPv4HttpAddress *) addr)->u_port); 878 port = ntohs (((struct IPv4HttpAddress *) addr)->u_port);
890 } 879 }
891 else if (addrlen == (sizeof (struct IPv6HttpAddress))) 880 else if (addrlen == (sizeof (struct IPv6HttpAddress)))
892 { 881 {
893 inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN); 882 inet_ntop (AF_INET6, (struct in6_addr *) addr, address, INET6_ADDRSTRLEN);
894 port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port); 883 port = ntohs (((struct IPv6HttpAddress *) addr)->u6_port);
895 } 884 }
896 else 885 else
897 { 886 {
898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 887 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
899 _("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"), 888 _
889 ("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"),
900 sizeof (struct IPv6HttpAddress), 890 sizeof (struct IPv6HttpAddress),
901 sizeof (struct IPv4HttpAddress), 891 sizeof (struct IPv4HttpAddress), addrlen);
902 addrlen); 892 return;
903 return; 893 }
904 }
905 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 894 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
906 _("Transport plugin notification for address: `%s':%u\n"), 895 _("Transport plugin notification for address: `%s':%u\n"),
907 address, 896 address, port);
908 port); 897 pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address));
909 pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
910 pl_addr->addrlen = addrlen; 898 pl_addr->addrlen = addrlen;
911 pl_addr->addr = GNUNET_malloc(addrlen); 899 pl_addr->addr = GNUNET_malloc (addrlen);
912 memcpy(pl_addr->addr,addr,addrlen); 900 memcpy (pl_addr->addr, addr, addrlen);
913 pl_addr->next = NULL; 901 pl_addr->next = NULL;
914 902
915 if ( NULL == addr_head) 903 if (NULL == addr_head)
916 { 904 {
917 addr_head = pl_addr; 905 addr_head = pl_addr;
918 } 906 }
919 else 907 else
908 {
909 cur = addr_head;
910 while (NULL != cur->next)
920 { 911 {
921 cur = addr_head; 912 cur = cur->next;
922 while (NULL != cur->next)
923 {
924 cur = cur->next;
925 }
926 cur->next = pl_addr;
927 } 913 }
914 cur->next = pl_addr;
915 }
928 fail_notify_address_count++; 916 fail_notify_address_count++;
929 fail_notify_address = GNUNET_NO; 917 fail_notify_address = GNUNET_NO;
930} 918}
@@ -936,8 +924,7 @@ plugin_env_session_end (void *cls,
936{ 924{
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
938 "Pluging tells me: session %X to peer `%s' ended\n", 926 "Pluging tells me: session %X to peer `%s' ended\n",
939 session, 927 session, GNUNET_i2s (peer));
940 GNUNET_i2s(peer));
941} 928}
942 929
943 930
@@ -962,8 +949,7 @@ setup_plugin_environment ()
962 * Task shutting down testcase if it a timeout occurs 949 * Task shutting down testcase if it a timeout occurs
963 */ 950 */
964static void 951static void
965task_timeout (void *cls, 952task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
966 const struct GNUNET_SCHEDULER_TaskContext *tc)
967{ 953{
968 ti_timeout = GNUNET_SCHEDULER_NO_TASK; 954 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
969 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 955 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -971,35 +957,34 @@ task_timeout (void *cls,
971 957
972 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n"); 958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
973 fail = GNUNET_YES; 959 fail = GNUNET_YES;
974 shutdown_clean(); 960 shutdown_clean ();
975 return; 961 return;
976} 962}
977 963
978 964
979static void 965static void
980pretty_printer_cb (void *cls, 966pretty_printer_cb (void *cls, const char *address)
981 const char *address)
982{ 967{
983 if (NULL==address) 968 if (NULL == address)
984 return; 969 return;
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
986 "Plugin returned pretty address: `%s'\n", 971 "Plugin returned pretty address: `%s'\n", address);
987 address);
988 fail_pretty_printer_count++; 972 fail_pretty_printer_count++;
989} 973}
990 974
991/** 975/**
992 * Runs every single test to test the plugin 976 * Runs every single test to test the plugin
993 */ 977 */
994static void 978static void
995run_connection_tests( int phase , void * cls) 979run_connection_tests (int phase, void *cls)
996{ 980{
997 struct GNUNET_MessageHeader * msg; 981 struct GNUNET_MessageHeader *msg;
998 unsigned int size; 982 unsigned int size;
999 983
1000 if (phase==0) 984 if (phase == 0)
1001 { 985 {
1002 char * host_str = NULL; 986 char *host_str = NULL;
987
1003 /* resetting buffers */ 988 /* resetting buffers */
1004 buffer_in.size = HTTP_BUFFER_SIZE; 989 buffer_in.size = HTTP_BUFFER_SIZE;
1005 buffer_in.pos = 0; 990 buffer_in.pos = 0;
@@ -1010,217 +995,210 @@ run_connection_tests( int phase , void * cls)
1010 buffer_out.len = 0; 995 buffer_out.len = 0;
1011 996
1012 if (test_no_ident.test_executed == GNUNET_NO) 997 if (test_no_ident.test_executed == GNUNET_NO)
1013 { 998 {
1014 /* Connecting to peer without identification */ 999 /* Connecting to peer without identification */
1015 const char * ident = ""; 1000 const char *ident = "";
1016 GNUNET_asprintf (&host_str, 1001
1017 "%s://%s/%s", 1002 GNUNET_asprintf (&host_str,
1018 PROTOCOL_PREFIX, 1003 "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident);
1019 test_addr,ident); 1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1005 _("Connecting to peer without any peer identification.\n"));
1021 _("Connecting to peer without any peer identification.\n")); 1006 test_no_ident.test_executed = GNUNET_YES;
1022 test_no_ident.test_executed = GNUNET_YES; 1007 send_data (&test_no_ident, host_str);
1023 send_data ( &test_no_ident, host_str); 1008 GNUNET_free (host_str);
1024 GNUNET_free (host_str); 1009 return;
1025 return; 1010 }
1026 }
1027 if (test_too_short_ident.test_executed == GNUNET_NO) 1011 if (test_too_short_ident.test_executed == GNUNET_NO)
1028 { 1012 {
1029 const char * ident = "AAAAAAAAAA"; 1013 const char *ident = "AAAAAAAAAA";
1030 /* Connecting to peer with too short identification */ 1014
1031 GNUNET_asprintf (&host_str, 1015 /* Connecting to peer with too short identification */
1032 "%s://%s/%s", 1016 GNUNET_asprintf (&host_str,
1033 PROTOCOL_PREFIX, 1017 "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident);
1034 test_addr, 1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1035 ident); 1019 _
1036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1020 ("Connecting to peer with too short peer identification.\n"));
1037 _("Connecting to peer with too short peer identification.\n")); 1021 test_too_short_ident.test_executed = GNUNET_YES;
1038 test_too_short_ident.test_executed = GNUNET_YES; 1022 send_data (&test_too_short_ident, host_str);
1039 send_data ( &test_too_short_ident, host_str); 1023 GNUNET_free (host_str);
1040 GNUNET_free (host_str); 1024 return;
1041 return; 1025 }
1042 }
1043 1026
1044 if (test_too_long_ident.test_executed == GNUNET_NO) 1027 if (test_too_long_ident.test_executed == GNUNET_NO)
1045 { 1028 {
1046 const char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 1029 const char *ident =
1030 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1047 1031
1048 /* Connecting to peer with too long identification */ 1032 /* Connecting to peer with too long identification */
1049 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); 1033 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1034 ident);
1051 _("Connecting to peer with too long peer identification.\n")); 1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1052 test_too_long_ident.test_executed = GNUNET_YES; 1036 _("Connecting to peer with too long peer identification.\n"));
1053 send_data ( &test_too_long_ident, host_str); 1037 test_too_long_ident.test_executed = GNUNET_YES;
1054 GNUNET_free (host_str); 1038 send_data (&test_too_long_ident, host_str);
1055 return; 1039 GNUNET_free (host_str);
1040 return;
1056 } 1041 }
1057 if (test_valid_ident.test_executed == GNUNET_NO) 1042 if (test_valid_ident.test_executed == GNUNET_NO)
1058 {
1059 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1060 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident);
1061 GNUNET_asprintf (&host_str,
1062 "%s://%s/%s%s",
1063 PROTOCOL_PREFIX,
1064 test_addr,
1065 (char *) &ident,
1066 ";0");
1067 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068 _("Connecting to peer with valid peer identification.\n"));
1069 test_valid_ident.test_executed = GNUNET_YES;
1070 send_data ( &test_valid_ident, host_str);
1071 GNUNET_free (host_str);
1072 return;
1073 }
1074 }
1075 if (phase==1)
1076 { 1043 {
1044 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1045
1046 GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
1047 GNUNET_asprintf (&host_str,
1048 "%s://%s/%s%s",
1049 PROTOCOL_PREFIX, test_addr, (char *) &ident, ";0");
1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1078 "\nPhase 1: transmit data to all suggested addresses\n\n"); 1051 _("Connecting to peer with valid peer identification.\n"));
1079 /* Using one of the addresses the plugin proposed */ 1052 test_valid_ident.test_executed = GNUNET_YES;
1080 GNUNET_assert (addr_head->addr != NULL); 1053 send_data (&test_valid_ident, host_str);
1081 1054 GNUNET_free (host_str);
1082 struct Plugin_Address * tmp_addr;
1083 struct GNUNET_MessageHeader msg;
1084 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader));
1085 char address[INET6_ADDRSTRLEN];
1086 unsigned int port;
1087 unsigned int type = 10;
1088
1089 msg.size=htons(sizeof(struct GNUNET_MessageHeader));
1090 tmp_addr = addr_head;
1091 /* send a message to all addresses advertised by plugin */
1092
1093 int count = 0;
1094 while (tmp_addr != NULL)
1095 {
1096 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1097 {
1098 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN);
1099 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1101 "Sending message to addres no. %u: `%s':%u\n",
1102 count,
1103 address,
1104 port);
1105 }
1106 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1107 {
1108 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN);
1109 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1111 "Sending message to addres no. %u: `%s':%u\n",
1112 count,
1113 address,
1114 port);
1115 }
1116 msg.type=htons(type);
1117 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader));
1118 api->send(api->cls,
1119 &my_identity,
1120 tmp, sizeof(struct GNUNET_MessageHeader),
1121 0, TIMEOUT,
1122 NULL,
1123 tmp_addr->addr, tmp_addr->addrlen,
1124 GNUNET_YES,
1125 &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1126 tmp_addr = tmp_addr->next;
1127 count++;
1128 type++;
1129 }
1130 GNUNET_free(tmp);
1131 return; 1055 return;
1132 } 1056 }
1057 }
1058 if (phase == 1)
1059 {
1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1061 "\nPhase 1: transmit data to all suggested addresses\n\n");
1062 /* Using one of the addresses the plugin proposed */
1063 GNUNET_assert (addr_head->addr != NULL);
1064
1065 struct Plugin_Address *tmp_addr;
1066 struct GNUNET_MessageHeader msg;
1067 char *tmp = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
1068 char address[INET6_ADDRSTRLEN];
1069 unsigned int port;
1070 unsigned int type = 10;
1071
1072 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
1073 tmp_addr = addr_head;
1074 /* send a message to all addresses advertised by plugin */
1133 1075
1134 if (phase==2) 1076 int count = 0;
1077
1078 while (tmp_addr != NULL)
1135 { 1079 {
1136 struct Session * session = cls; 1080 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1137 msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader)); 1081 {
1138 1082 inet_ntop (AF_INET, (struct in_addr *) tmp_addr->addr, address,
1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1083 INET_ADDRSTRLEN);
1140 "Phase 2: session selection\n\n"); 1084 port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1141 size = sizeof(struct GNUNET_MessageHeader); 1085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1142 msg->size=htons(size); 1086 "Sending message to addres no. %u: `%s':%u\n",
1143 msg->type = htons(20); 1087 count, address, port);
1144 api->send(api->cls, 1088 }
1145 &my_identity, 1089 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1146 (const char *) msg, size, 1090 {
1147 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, 1091 inet_ntop (AF_INET6, (struct in6_addr *) tmp_addr->addr, address,
1148 &task_send_cont, NULL); 1092 INET6_ADDRSTRLEN);
1149 1093 port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1150 msg->type = htons(21); 1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1151 api->send(api->cls, 1095 "Sending message to addres no. %u: `%s':%u\n",
1152 &my_identity, 1096 count, address, port);
1153 (const char *) msg, size, 1097 }
1154 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, 1098 msg.type = htons (type);
1155 &task_send_cont, NULL); 1099 memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
1156 1100 api->send (api->cls,
1157 /* answer on session*/ 1101 &my_identity,
1158 size = sizeof( struct GNUNET_MessageHeader); 1102 tmp, sizeof (struct GNUNET_MessageHeader),
1159 msg->size = htons(size); 1103 0, TIMEOUT,
1160 msg->type = htons(22); 1104 NULL,
1161 api->send(api->cls, 1105 tmp_addr->addr, tmp_addr->addrlen,
1162 &my_identity, 1106 GNUNET_YES,
1163 (const char *) msg, size, 1107 &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1164 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR, 1108 tmp_addr = tmp_addr->next;
1165 &task_send_cont, NULL); 1109 count++;
1166 GNUNET_free(msg); 1110 type++;
1167
1168 /* answer on session with big message not fitting in mhd send buffer*/
1169 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1;
1170 msg = GNUNET_malloc (size);
1171 msg->size=htons(size);
1172 msg->type = htons(23);
1173 api->send(api->cls,
1174 &my_identity,
1175 (const char *) msg, size,
1176 0, TIMEOUT, session, NULL, 0, GNUNET_NO,
1177 &task_send_cont, NULL);
1178 GNUNET_free(msg);
1179 return;
1180 } 1111 }
1181 1112 GNUNET_free (tmp);
1182 if (phase==3) 1113 return;
1183 { 1114 }
1184 1115
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1116 if (phase == 2)
1117 {
1118 struct Session *session = cls;
1119
1120 msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
1121
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 2: session selection\n\n");
1123 size = sizeof (struct GNUNET_MessageHeader);
1124 msg->size = htons (size);
1125 msg->type = htons (20);
1126 api->send (api->cls,
1127 &my_identity,
1128 (const char *) msg, size,
1129 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1130
1131 msg->type = htons (21);
1132 api->send (api->cls,
1133 &my_identity,
1134 (const char *) msg, size,
1135 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1136
1137 /* answer on session */
1138 size = sizeof (struct GNUNET_MessageHeader);
1139 msg->size = htons (size);
1140 msg->type = htons (22);
1141 api->send (api->cls,
1142 &my_identity,
1143 (const char *) msg, size,
1144 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1145 &task_send_cont, NULL);
1146 GNUNET_free (msg);
1147
1148 /* answer on session with big message not fitting in mhd send buffer */
1149 size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1150 msg = GNUNET_malloc (size);
1151 msg->size = htons (size);
1152 msg->type = htons (23);
1153 api->send (api->cls,
1154 &my_identity,
1155 (const char *) msg, size,
1156 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1157 GNUNET_free (msg);
1158 return;
1159 }
1160
1161 if (phase == 3)
1162 {
1163
1164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1186 "Phase 3: send multiple or big messages after disconnect\n\n"); 1165 "Phase 3: send multiple or big messages after disconnect\n\n");
1187 /* disconnect from peer, so new connections are created */ 1166 /* disconnect from peer, so new connections are created */
1188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); 1167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect from peer: `%s'\n",
1189 api->disconnect(api->cls, &my_identity); 1168 GNUNET_i2s (&my_identity));
1190 1169 api->disconnect (api->cls, &my_identity);
1170
1191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n"); 1171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Phase 3: sending messages\n");
1192 /* send a multiple GNUNET_messages at a time*/ 1172 /* send a multiple GNUNET_messages at a time */
1193 size = 2 * sizeof(struct GNUNET_MessageHeader); 1173 size = 2 * sizeof (struct GNUNET_MessageHeader);
1194 msg = GNUNET_malloc( 2* size); 1174 msg = GNUNET_malloc (2 * size);
1195 msg->size = htons(size); 1175 msg->size = htons (size);
1196 msg->type = htons(30); 1176 msg->type = htons (30);
1197 struct GNUNET_MessageHeader * msg2 = &msg[2]; 1177 struct GNUNET_MessageHeader *msg2 = &msg[2];
1198 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 1178
1199 msg2->type = htons(31); 1179 msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
1200 api->send(api->cls, 1180 msg2->type = htons (31);
1201 &my_identity, 1181 api->send (api->cls,
1202 (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader), 1182 &my_identity,
1203 0, TIMEOUT, NULL, 1183 (const char *) msg, 4 * sizeof (struct GNUNET_MessageHeader),
1204 addr_head->addr, addr_head->addrlen, 1184 0, TIMEOUT, NULL,
1205 GNUNET_NO, 1185 addr_head->addr, addr_head->addrlen,
1206 &task_send_cont, &fail_multiple_msgs_in_transmission); 1186 GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission);
1207 GNUNET_free(msg); 1187 GNUNET_free (msg);
1208 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1188 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1209 1189
1210 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1; 1190 size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1211 msg = GNUNET_malloc(size); 1191 msg = GNUNET_malloc (size);
1212 msg->size = htons(size); 1192 msg->size = htons (size);
1213 msg->type = htons(32); 1193 msg->type = htons (32);
1214 api->send(api->cls, 1194 api->send (api->cls,
1215 &my_identity, 1195 &my_identity,
1216 (const char *) msg, size, 1196 (const char *) msg, size,
1217 0, TIMEOUT, NULL, 1197 0, TIMEOUT, NULL,
1218 addr_head->addr, addr_head->addrlen, 1198 addr_head->addr, addr_head->addrlen,
1219 GNUNET_NO, 1199 GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size);
1220 &task_send_cont, &fail_msg_transmited_max_size); 1200 GNUNET_free (msg);
1221 GNUNET_free(msg); 1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
1222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1223 "No more tests to run\n");
1224 } 1202 }
1225} 1203}
1226 1204
@@ -1236,12 +1214,13 @@ run (void *cls,
1236 char *const *args, 1214 char *const *args,
1237 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) 1215 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1238{ 1216{
1239 char * libname; 1217 char *libname;
1218
1240 cfg = c; 1219 cfg = c;
1241 char *keyfile; 1220 char *keyfile;
1242 unsigned long long tneigh; 1221 unsigned long long tneigh;
1243 struct Plugin_Address * cur; 1222 struct Plugin_Address *cur;
1244 const char * addr_str; 1223 const char *addr_str;
1245 1224
1246 1225
1247 unsigned int suggest_res; 1226 unsigned int suggest_res;
@@ -1260,8 +1239,9 @@ run (void *cls,
1260 addr_head = NULL; 1239 addr_head = NULL;
1261 count_str_addr = 0; 1240 count_str_addr = 0;
1262 /* parse configuration */ 1241 /* parse configuration */
1263 if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME")) 1242 if (GNUNET_CONFIGURATION_have_value (c, "PATHS", "SERVICEHOME"))
1264 GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME", &servicehome); 1243 GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
1244 &servicehome);
1265 1245
1266 if ((GNUNET_OK != 1246 if ((GNUNET_OK !=
1267 GNUNET_CONFIGURATION_get_value_number (c, 1247 GNUNET_CONFIGURATION_get_value_number (c,
@@ -1272,20 +1252,21 @@ run (void *cls,
1272 GNUNET_CONFIGURATION_get_value_filename (c, 1252 GNUNET_CONFIGURATION_get_value_filename (c,
1273 "GNUNETD", 1253 "GNUNETD",
1274 "HOSTKEY", &keyfile))) 1254 "HOSTKEY", &keyfile)))
1275 { 1255 {
1276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1277 _("Transport service is lacking key configuration settings. Exiting.\n")); 1257 _
1278 GNUNET_SCHEDULER_shutdown (); 1258 ("Transport service is lacking key configuration settings. Exiting.\n"));
1279 fail = 1; 1259 GNUNET_SCHEDULER_shutdown ();
1280 return; 1260 fail = 1;
1281 } 1261 return;
1262 }
1282 1263
1283 if ((GNUNET_OK != 1264 if ((GNUNET_OK !=
1284 GNUNET_CONFIGURATION_get_value_number (cfg, 1265 GNUNET_CONFIGURATION_get_value_number (cfg,
1285 "transport-http", 1266 "transport-http",
1286 "PORT", 1267 "PORT",
1287 &port)) || 1268 &port)) ||
1288 (port > 65535) || (port == 0)) 1269 (port > 65535) || (port == 0))
1289 { 1270 {
1290 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1271 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1291 "http", 1272 "http",
@@ -1298,16 +1279,17 @@ run (void *cls,
1298 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1279 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1299 GNUNET_free (keyfile); 1280 GNUNET_free (keyfile);
1300 if (my_private_key == NULL) 1281 if (my_private_key == NULL)
1301 { 1282 {
1302 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1283 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1303 _("Transport service could not access hostkey. Exiting.\n")); 1284 _("Transport service could not access hostkey. Exiting.\n"));
1304 GNUNET_SCHEDULER_shutdown (); 1285 GNUNET_SCHEDULER_shutdown ();
1305 fail = 1; 1286 fail = 1;
1306 return; 1287 return;
1307 } 1288 }
1308 1289
1309 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 1290 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1310 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey); 1291 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
1292 &my_identity.hashPubKey);
1311 1293
1312 /* assertions before start */ 1294 /* assertions before start */
1313 GNUNET_assert ((port > 0) && (port <= 65535)); 1295 GNUNET_assert ((port > 0) && (port <= 65535));
@@ -1315,9 +1297,8 @@ run (void *cls,
1315 /* load plugins... */ 1297 /* load plugins... */
1316 setup_plugin_environment (); 1298 setup_plugin_environment ();
1317 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http"); 1299 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1318 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1300 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1319 _("Loading HTTP transport plugin `%s'\n"), 1301 _("Loading HTTP transport plugin `%s'\n"), libname);
1320 libname);
1321 api = GNUNET_PLUGIN_load (libname, &env); 1302 api = GNUNET_PLUGIN_load (libname, &env);
1322 GNUNET_free (libname); 1303 GNUNET_free (libname);
1323 if (api == NULL) 1304 if (api == NULL)
@@ -1332,49 +1313,51 @@ run (void *cls,
1332 ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL); 1313 ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL);
1333 1314
1334 /* testing plugin functionality */ 1315 /* testing plugin functionality */
1335 GNUNET_assert (0!=fail_notify_address_count); 1316 GNUNET_assert (0 != fail_notify_address_count);
1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1337 "Transport plugin returned %u addresses to connect to\n", 1318 "Transport plugin returned %u addresses to connect to\n",
1338 fail_notify_address_count); 1319 fail_notify_address_count);
1339 1320
1340 /* testing pretty printer with all addresses obtained from the plugin*/ 1321 /* testing pretty printer with all addresses obtained from the plugin */
1341 cur = addr_head; 1322 cur = addr_head;
1342 while (cur != NULL) 1323 while (cur != NULL)
1343 { 1324 {
1344 api->address_pretty_printer (api->cls, "http", 1325 api->address_pretty_printer (api->cls, "http",
1345 cur->addr,cur->addrlen, GNUNET_NO,TEST_TIMEOUT, 1326 cur->addr, cur->addrlen, GNUNET_NO,
1346 &pretty_printer_cb, NULL); 1327 TEST_TIMEOUT, &pretty_printer_cb, NULL);
1347 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); 1328 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1348 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); 1329 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1349 1330
1350 GNUNET_assert (GNUNET_OK == suggest_res); 1331 GNUNET_assert (GNUNET_OK == suggest_res);
1351 GNUNET_assert (NULL != addr_str); 1332 GNUNET_assert (NULL != addr_str);
1352 count_str_addr++; 1333 count_str_addr++;
1353 GNUNET_free ( (char *) addr_str); 1334 GNUNET_free ((char *) addr_str);
1354 cur = cur->next; 1335 cur = cur->next;
1355 } 1336 }
1356 GNUNET_assert (fail_pretty_printer_count > 0); 1337 GNUNET_assert (fail_pretty_printer_count > 0);
1357 GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count); 1338 GNUNET_assert (fail_pretty_printer_count == fail_notify_address_count);
1358 GNUNET_assert (fail_pretty_printer_count==count_str_addr); 1339 GNUNET_assert (fail_pretty_printer_count == count_str_addr);
1359 fail_pretty_printer=GNUNET_NO; 1340 fail_pretty_printer = GNUNET_NO;
1360 fail_addr_to_str=GNUNET_NO; 1341 fail_addr_to_str = GNUNET_NO;
1361 1342
1362 struct IPv4HttpAddress failing_addr; 1343 struct IPv4HttpAddress failing_addr;
1363 1344
1364 /* Suggesting addresses with wrong size*/ 1345 /* Suggesting addresses with wrong size */
1365 failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); 1346 failing_addr.ipv4_addr = htonl (INADDR_LOOPBACK);
1366 failing_addr.u_port = htons(0); 1347 failing_addr.u_port = htons (0);
1367 suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv6HttpAddress)); 1348 suggest_res =
1349 api->check_address (api->cls, &failing_addr,
1350 sizeof (struct IPv6HttpAddress));
1368 GNUNET_assert (GNUNET_SYSERR == suggest_res); 1351 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1369 1352
1370 /* Suggesting addresses with wrong address*/ 1353 /* Suggesting addresses with wrong address */
1371 failing_addr.ipv4_addr = htonl(0xffc00000); 1354 failing_addr.ipv4_addr = htonl (0xffc00000);
1372 failing_addr.u_port = htons(12389); 1355 failing_addr.u_port = htons (12389);
1373 suggest_res = api->check_address (api->cls,&failing_addr,100); 1356 suggest_res = api->check_address (api->cls, &failing_addr, 100);
1374 GNUNET_assert (GNUNET_SYSERR == suggest_res); 1357 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1375 1358
1376 /* test sending to client */ 1359 /* test sending to client */
1377 multi_handle = curl_multi_init(); 1360 multi_handle = curl_multi_init ();
1378 1361
1379 /* Setting up buffers */ 1362 /* Setting up buffers */
1380 buffer_in.size = HTTP_BUFFER_SIZE; 1363 buffer_in.size = HTTP_BUFFER_SIZE;
@@ -1403,10 +1386,12 @@ run (void *cls,
1403 test_valid_ident.test_executed = GNUNET_NO; 1386 test_valid_ident.test_executed = GNUNET_NO;
1404 test_valid_ident.test_failed = GNUNET_YES; 1387 test_valid_ident.test_failed = GNUNET_YES;
1405 1388
1406 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); 1389 test_addr =
1390 (char *) api->address_to_string (api->cls, addr_head->addr,
1391 addr_head->addrlen);
1407 1392
1408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n")); 1393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Phase 0\n\n"));
1409 run_connection_tests(0, NULL); 1394 run_connection_tests (0, NULL);
1410 /* testing finished */ 1395 /* testing finished */
1411} 1396}
1412 1397
@@ -1425,6 +1410,7 @@ main (int argc, char *const *argv)
1425 GNUNET_GETOPT_OPTION_END 1410 GNUNET_GETOPT_OPTION_END
1426 }; 1411 };
1427 int ret; 1412 int ret;
1413
1428 char *const argv_prog[] = { 1414 char *const argv_prog[] = {
1429 "test_gnunet_transport_plugin_http", 1415 "test_gnunet_transport_plugin_http",
1430 "-c", 1416 "-c",
@@ -1446,11 +1432,15 @@ main (int argc, char *const *argv)
1446 NULL); 1432 NULL);
1447 1433
1448 struct GNUNET_CONFIGURATION_Handle *cfg; 1434 struct GNUNET_CONFIGURATION_Handle *cfg;
1435
1449 cfg = GNUNET_CONFIGURATION_create (); 1436 cfg = GNUNET_CONFIGURATION_create ();
1450 1437
1451 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_plugin_transport_data_http.conf")); 1438 GNUNET_assert (GNUNET_OK ==
1452 if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME")) 1439 GNUNET_CONFIGURATION_load (cfg,
1453 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &servicehome); 1440 "test_plugin_transport_data_http.conf"));
1441 if (GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "SERVICEHOME"))
1442 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
1443 &servicehome);
1454 GNUNET_DISK_directory_remove (servicehome); 1444 GNUNET_DISK_directory_remove (servicehome);
1455 GNUNET_CONFIGURATION_destroy (cfg); 1445 GNUNET_CONFIGURATION_destroy (cfg);
1456 1446
@@ -1458,7 +1448,8 @@ main (int argc, char *const *argv)
1458 GNUNET_PROGRAM_run (5, 1448 GNUNET_PROGRAM_run (5,
1459 argv_prog, 1449 argv_prog,
1460 "test_gnunet_transport_plugin_http", 1450 "test_gnunet_transport_plugin_http",
1461 "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES; 1451 "testcase", options, &run,
1452 NULL)) ? GNUNET_NO : GNUNET_YES;
1462 1453
1463 if (servicehome != NULL) 1454 if (servicehome != NULL)
1464 { 1455 {
diff --git a/src/transport/test_plugin_transport_https.c b/src/transport/test_plugin_transport_https.c
index 0845c8cd4..e6e71c7f5 100644
--- a/src/transport/test_plugin_transport_https.c
+++ b/src/transport/test_plugin_transport_https.c
@@ -75,12 +75,12 @@ struct Plugin_Address
75 /** 75 /**
76 * Next field for linked list 76 * Next field for linked list
77 */ 77 */
78 struct Plugin_Address * next; 78 struct Plugin_Address *next;
79 79
80 /** 80 /**
81 * buffer containing data to send 81 * buffer containing data to send
82 */ 82 */
83 void * addr; 83 void *addr;
84 84
85 /** 85 /**
86 * amount of data to sent 86 * amount of data to sent
@@ -162,9 +162,9 @@ struct HTTP_Transfer
162 */ 162 */
163struct IPv4HttpAddress 163struct IPv4HttpAddress
164{ 164{
165 struct IPv4HttpAddress * next; 165 struct IPv4HttpAddress *next;
166 166
167 struct IPv4HttpAddress * prev; 167 struct IPv4HttpAddress *prev;
168 168
169 /** 169 /**
170 * IPv4 address, in network byte order. 170 * IPv4 address, in network byte order.
@@ -184,9 +184,9 @@ struct IPv4HttpAddress
184 */ 184 */
185struct IPv6HttpAddress 185struct IPv6HttpAddress
186{ 186{
187 struct IPv6HttpAddress * next; 187 struct IPv6HttpAddress *next;
188 188
189 struct IPv6HttpAddress * prev; 189 struct IPv6HttpAddress *prev;
190 190
191 /** 191 /**
192 * IPv6 address. 192 * IPv6 address.
@@ -228,7 +228,7 @@ static long long unsigned int port;
228/** 228/**
229 * Peer's addr 229 * Peer's addr
230 */ 230 */
231static char * test_addr; 231static char *test_addr;
232 232
233/** 233/**
234 * Our statistics handle. 234 * Our statistics handle.
@@ -276,12 +276,13 @@ static struct HTTP_Message buffer_out;
276static struct HTTP_Message buffer_in; 276static struct HTTP_Message buffer_in;
277 277
278 278
279struct Plugin_Address * addr_head; 279struct Plugin_Address *addr_head;
280 280
281/** 281/**
282 * Did the test pass or fail? 282 * Did the test pass or fail?
283 */ 283 */
284static int fail_notify_address; 284static int fail_notify_address;
285
285/** 286/**
286 * Did the test pass or fail? 287 * Did the test pass or fail?
287 */ 288 */
@@ -386,10 +387,10 @@ static CURLM *multi_handle;
386static GNUNET_SCHEDULER_TaskIdentifier http_task_send; 387static GNUNET_SCHEDULER_TaskIdentifier http_task_send;
387 388
388 389
389static char * key_file; 390static char *key_file;
390static char * cert_file; 391static char *cert_file;
391 392
392static char * servicehome; 393static char *servicehome;
393 394
394/** 395/**
395 * Shutdown testcase 396 * Shutdown testcase
@@ -397,28 +398,41 @@ static char * servicehome;
397static void 398static void
398shutdown_clean () 399shutdown_clean ()
399{ 400{
400 struct Plugin_Address * tmp; 401 struct Plugin_Address *tmp;
401 402
402 /* Evaluate results */ 403 /* Evaluate results */
403 fail = 0; 404 fail = 0;
404 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) 405 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES)
406 || (fail_addr_to_str == GNUNET_YES))
405 { 407 {
406 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 0: Test plugin functions failed\n")); 408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
409 _("Phase 0: Test plugin functions failed\n"));
407 fail = 1; 410 fail = 1;
408 } 411 }
409 if ((test_no_ident.test_failed == GNUNET_YES) || (test_too_short_ident.test_failed == GNUNET_YES) || (test_too_long_ident.test_failed == GNUNET_YES) || (test_valid_ident.test_failed == GNUNET_YES)) 412 if ((test_no_ident.test_failed == GNUNET_YES) ||
413 (test_too_short_ident.test_failed == GNUNET_YES) ||
414 (test_too_long_ident.test_failed == GNUNET_YES) ||
415 (test_valid_ident.test_failed == GNUNET_YES))
410 { 416 {
411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 1: Test connect with wrong data failed\n")); 417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
418 _("Phase 1: Test connect with wrong data failed\n"));
412 fail = 1; 419 fail = 1;
413 } 420 }
414 if ((fail_session_selection_any != GNUNET_NO) || (fail_session_selection_reliable != GNUNET_NO) || (fail_session_selection_session != GNUNET_NO) || (fail_session_selection_session_big != GNUNET_NO)) 421 if ((fail_session_selection_any != GNUNET_NO) ||
422 (fail_session_selection_reliable != GNUNET_NO) ||
423 (fail_session_selection_session != GNUNET_NO) ||
424 (fail_session_selection_session_big != GNUNET_NO))
415 { 425 {
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 2: Test session selection failed\n")); 426 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
427 _("Phase 2: Test session selection failed\n"));
417 fail = 1; 428 fail = 1;
418 } 429 }
419 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) || (fail_multiple_msgs_in_transmission != 2) || (fail_msg_transmited_max_size == GNUNET_YES)) 430 if ((fail_msgs_transmited_to_local_addrs != count_str_addr) ||
431 (fail_multiple_msgs_in_transmission != 2) ||
432 (fail_msg_transmited_max_size == GNUNET_YES))
420 { 433 {
421 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Phase 3: Test sending with plugin failed\n")); 434 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
435 _("Phase 3: Test sending with plugin failed\n"));
422 fail = 1; 436 fail = 1;
423 } 437 }
424 if (fail != 1) 438 if (fail != 1)
@@ -426,9 +440,9 @@ shutdown_clean ()
426 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n"); 440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All tests successful\n");
427 } 441 }
428 442
429 api->disconnect(api->cls,&my_identity); 443 api->disconnect (api->cls, &my_identity);
430 444
431 curl_multi_cleanup(multi_handle); 445 curl_multi_cleanup (multi_handle);
432 446
433 if (NULL != curl_handle) 447 if (NULL != curl_handle)
434 curl_easy_cleanup (curl_handle); 448 curl_easy_cleanup (curl_handle);
@@ -439,49 +453,57 @@ shutdown_clean ()
439 tmp = addr_head->next; 453 tmp = addr_head->next;
440 GNUNET_free (addr_head->addr); 454 GNUNET_free (addr_head->addr);
441 GNUNET_free (addr_head); 455 GNUNET_free (addr_head);
442 addr_head=tmp; 456 addr_head = tmp;
443 } 457 }
444 458
445 if (ti_send != GNUNET_SCHEDULER_NO_TASK) 459 if (ti_send != GNUNET_SCHEDULER_NO_TASK)
446 { 460 {
447 GNUNET_SCHEDULER_cancel(ti_send); 461 GNUNET_SCHEDULER_cancel (ti_send);
448 ti_send = GNUNET_SCHEDULER_NO_TASK; 462 ti_send = GNUNET_SCHEDULER_NO_TASK;
449 } 463 }
450 464
451 if (http_task_send != GNUNET_SCHEDULER_NO_TASK) 465 if (http_task_send != GNUNET_SCHEDULER_NO_TASK)
452 { 466 {
453 GNUNET_SCHEDULER_cancel(http_task_send); 467 GNUNET_SCHEDULER_cancel (http_task_send);
454 http_task_send = GNUNET_SCHEDULER_NO_TASK; 468 http_task_send = GNUNET_SCHEDULER_NO_TASK;
455 } 469 }
456 470
457 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK) 471 if (ti_timeout != GNUNET_SCHEDULER_NO_TASK)
458 { 472 {
459 GNUNET_SCHEDULER_cancel(ti_timeout); 473 GNUNET_SCHEDULER_cancel (ti_timeout);
460 ti_timeout = GNUNET_SCHEDULER_NO_TASK; 474 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
461 } 475 }
462 476
463 GNUNET_free(test_addr); 477 GNUNET_free (test_addr);
464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading https plugin\n"); 478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unloading https plugin\n");
465 GNUNET_assert (NULL == GNUNET_PLUGIN_unload ("libgnunet_gnunet_transport_plugin.https", api)); 479 GNUNET_assert (NULL ==
480 GNUNET_PLUGIN_unload
481 ("libgnunet_gnunet_transport_plugin.https", api));
466 482
467 GNUNET_SCHEDULER_shutdown(); 483 GNUNET_SCHEDULER_shutdown ();
468 GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin.http"); 484 GNUNET_DISK_directory_remove ("/tmp/test_gnunet_transport_plugin.http");
469 485
470 struct stat sbuf; 486 struct stat sbuf;
471 if (0 == stat (cert_file, &sbuf )) 487
488 if (0 == stat (cert_file, &sbuf))
472 { 489 {
473 if (0 == remove(cert_file)) 490 if (0 == remove (cert_file))
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file); 491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
475 else 492 "Successfully removed existing certificate file `%s'\n",
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file); 493 cert_file);
494 else
495 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",
496 cert_file);
477 } 497 }
478 498
479 if (0 == stat (key_file, &sbuf )) 499 if (0 == stat (key_file, &sbuf))
480 { 500 {
481 if (0 == remove(key_file)) 501 if (0 == remove (key_file))
482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file); 502 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
483 else 503 "Successfully removed private key file `%s'\n", key_file);
484 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file); 504 else
505 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",
506 key_file);
485 } 507 }
486 508
487 GNUNET_free (key_file); 509 GNUNET_free (key_file);
@@ -495,7 +517,7 @@ shutdown_clean ()
495 GNUNET_free (servicehome); 517 GNUNET_free (servicehome);
496 } 518 }
497 519
498 exit(fail); 520 exit (fail);
499 return; 521 return;
500} 522}
501 523
@@ -507,97 +529,105 @@ shutdown_clean ()
507 * @result GNUNET_OK or GNUNET_SYSERR 529 * @result GNUNET_OK or GNUNET_SYSERR
508 */ 530 */
509 531
510static void task_send_cont (void *cls, 532static void
511 const struct GNUNET_PeerIdentity * target, 533task_send_cont (void *cls, const struct GNUNET_PeerIdentity *target, int result)
512 int result)
513{ 534{
514 if ((cls == &fail_msg_transmited_bigger_max_size) && (result == GNUNET_SYSERR)) 535 if ((cls == &fail_msg_transmited_bigger_max_size) &&
536 (result == GNUNET_SYSERR))
515 { 537 {
516 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bigger max msg size was not sent!\n"); 538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Message bigger max msg size was not sent!\n");
517 fail_msg_transmited_bigger_max_size = GNUNET_NO; 540 fail_msg_transmited_bigger_max_size = GNUNET_NO;
518 return; 541 return;
519 } 542 }
520 543
521 if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK)) 544 if ((cls == &fail_msg_transmited_max_size) && (result == GNUNET_OK))
522 { 545 {
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message with max msg size succesfully sent!\n",fail_msgs_transmited_to_local_addrs); 546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
547 "Message with max msg size succesfully sent!\n",
548 fail_msgs_transmited_to_local_addrs);
524 fail_msg_transmited_max_size = GNUNET_NO; 549 fail_msg_transmited_max_size = GNUNET_NO;
525 } 550 }
526} 551}
527 552
528 553
529static void run_connection_tests( int phase , void * cls); 554static void run_connection_tests (int phase, void *cls);
530 555
531/** 556/**
532 * Recieves messages from plugin, in real world transport 557 * Recieves messages from plugin, in real world transport
533 */ 558 */
534static struct GNUNET_TIME_Relative 559static struct GNUNET_TIME_Relative
535receive (void *cls, const struct GNUNET_PeerIdentity *peer, 560receive (void *cls, const struct GNUNET_PeerIdentity *peer,
536 const struct GNUNET_MessageHeader *message, 561 const struct GNUNET_MessageHeader *message,
537 const struct GNUNET_TRANSPORT_ATS_Information *ats, 562 const struct GNUNET_TRANSPORT_ATS_Information *ats,
538 uint32_t ats_count, 563 uint32_t ats_count,
539 struct Session *session, 564 struct Session *session,
540 const char *sender_address, 565 const char *sender_address, uint16_t sender_address_len)
541 uint16_t sender_address_len)
542{ 566{
543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", GNUNET_i2s(peer), ntohs(message->type), ntohs(message->size),session); 567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
568 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
569 GNUNET_i2s (peer), ntohs (message->type), ntohs (message->size),
570 session);
544 571
545 if ((ntohs(message->type)>=10) && (ntohs(message->type)<20)) 572 if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
546 { 573 {
547 fail_msgs_transmited_to_local_addrs++; 574 fail_msgs_transmited_to_local_addrs++;
548 if (fail_msgs_transmited_to_local_addrs == count_str_addr) 575 if (fail_msgs_transmited_to_local_addrs == count_str_addr)
549 run_connection_tests(2, session); 576 run_connection_tests (2, session);
550 } 577 }
551 578
552 579
553 if ((ntohs(message->type)==20)) 580 if ((ntohs (message->type) == 20))
554 { 581 {
555 fail_session_selection_reliable = GNUNET_NO; 582 fail_session_selection_reliable = GNUNET_NO;
556 } 583 }
557 584
558 if ((ntohs(message->type)==21)) 585 if ((ntohs (message->type) == 21))
559 { 586 {
560 fail_session_selection_any = GNUNET_NO; 587 fail_session_selection_any = GNUNET_NO;
561 } 588 }
562 if ((ntohs(message->type)==22)) 589 if ((ntohs (message->type) == 22))
563 { 590 {
564 fail_session_selection_session = GNUNET_NO; 591 fail_session_selection_session = GNUNET_NO;
565 } 592 }
566 593
567 if ((ntohs(message->type)==23)) 594 if ((ntohs (message->type) == 23))
568 { 595 {
569 fail_session_selection_session_big = GNUNET_NO; 596 fail_session_selection_session_big = GNUNET_NO;
570 run_connection_tests(3, NULL); 597 run_connection_tests (3, NULL);
571 } 598 }
572 599
573 if ((ntohs(message->type)==30) || (ntohs(message->type)==31)) 600 if ((ntohs (message->type) == 30) || (ntohs (message->type) == 31))
574 { 601 {
575 fail_multiple_msgs_in_transmission ++; 602 fail_multiple_msgs_in_transmission++;
576 } 603 }
577 604
578 if ((ntohs(message->type)==32) && (ntohs(message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE-1)) 605 if ((ntohs (message->type) == 32) &&
606 (ntohs (message->size) == GNUNET_SERVER_MAX_MESSAGE_SIZE - 1))
579 { 607 {
580 fail_msg_transmited_max_size = GNUNET_NO; 608 fail_msg_transmited_max_size = GNUNET_NO;
581 shutdown_clean(); 609 shutdown_clean ();
582 } 610 }
583 611
584 return GNUNET_TIME_UNIT_ZERO; 612 return GNUNET_TIME_UNIT_ZERO;
585} 613}
586 614
587static size_t send_function (void *stream, size_t size, size_t nmemb, void *ptr) 615static size_t
616send_function (void *stream, size_t size, size_t nmemb, void *ptr)
588{ 617{
589 unsigned int len; 618 unsigned int len;
590 619
591 len = buffer_out.len; 620 len = buffer_out.len;
592 621
593 if (( buffer_out.pos == len) || (len > (size * nmemb))) 622 if ((buffer_out.pos == len) || (len > (size * nmemb)))
594 return 0; 623 return 0;
595 memcpy(stream, buffer_out.buf, len); 624 memcpy (stream, buffer_out.buf, len);
596 buffer_out.pos = len; 625 buffer_out.pos = len;
597 return len; 626 return len;
598} 627}
599 628
600static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx) 629static size_t
630recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
601{ 631{
602 632
603 if (buffer_in.pos + size * nmemb > buffer_in.size) 633 if (buffer_in.pos + size * nmemb > buffer_in.size)
@@ -611,50 +641,51 @@ static size_t recv_function (void *ptr, size_t size, size_t nmemb, void *ctx)
611 return buffer_in.pos; 641 return buffer_in.pos;
612} 642}
613 643
614static size_t header_function( void *ptr, size_t size, size_t nmemb, void *stream) 644static size_t
645header_function (void *ptr, size_t size, size_t nmemb, void *stream)
615{ 646{
616 struct HTTP_Transfer * res = (struct HTTP_Transfer *) stream; 647 struct HTTP_Transfer *res = (struct HTTP_Transfer *) stream;
617 char * tmp; 648 char *tmp;
618 unsigned int len = size * nmemb; 649 unsigned int len = size * nmemb;
619 650
620 tmp = GNUNET_malloc ( len+1 ); 651 tmp = GNUNET_malloc (len + 1);
621 memcpy(tmp,ptr,len); 652 memcpy (tmp, ptr, len);
622 if (tmp[len-2] == 13) 653 if (tmp[len - 2] == 13)
623 tmp[len-2]= '\0'; 654 tmp[len - 2] = '\0';
624#if DEBUG_CURL 655#if DEBUG_CURL
625 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n",tmp); 656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Header: `%s'\n", tmp);
626#endif 657#endif
627 if (0==strcmp (tmp,"HTTP/1.1 100 Continue")) 658 if (0 == strcmp (tmp, "HTTP/1.1 100 Continue"))
628 { 659 {
629 res->http_result_code=100; 660 res->http_result_code = 100;
630 } 661 }
631 if (0==strcmp (tmp,"HTTP/1.1 200 OK")) 662 if (0 == strcmp (tmp, "HTTP/1.1 200 OK"))
632 { 663 {
633 res->http_result_code=200; 664 res->http_result_code = 200;
634 } 665 }
635 if (0==strcmp (tmp,"HTTP/1.1 400 Bad Request")) 666 if (0 == strcmp (tmp, "HTTP/1.1 400 Bad Request"))
636 { 667 {
637 res->http_result_code=400; 668 res->http_result_code = 400;
638 } 669 }
639 if (0==strcmp (tmp,"HTTP/1.1 404 Not Found")) 670 if (0 == strcmp (tmp, "HTTP/1.1 404 Not Found"))
640 { 671 {
641 res->http_result_code=404; 672 res->http_result_code = 404;
642 } 673 }
643 if (0==strcmp (tmp,"HTTP/1.1 413 Request entity too large")) 674 if (0 == strcmp (tmp, "HTTP/1.1 413 Request entity too large"))
644 { 675 {
645 res->http_result_code=413; 676 res->http_result_code = 413;
646 } 677 }
647 678
648 GNUNET_free (tmp); 679 GNUNET_free (tmp);
649 return size * nmemb; 680 return size * nmemb;
650} 681}
651 682
652static size_t send_prepare( struct HTTP_Transfer * result); 683static size_t send_prepare (struct HTTP_Transfer *result);
653 684
654 685
655 686
656static void send_execute (void *cls, 687static void
657 const struct GNUNET_SCHEDULER_TaskContext *tc) 688send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
658{ 689{
659 struct HTTP_Transfer *res; 690 struct HTTP_Transfer *res;
660 691
@@ -668,96 +699,107 @@ static void send_execute (void *cls,
668 return; 699 return;
669 700
670 do 701 do
702 {
703 running = 0;
704 mret = curl_multi_perform (multi_handle, &running);
705 if (running == 0)
671 { 706 {
672 running = 0; 707 do
673 mret = curl_multi_perform (multi_handle, &running); 708 {
674 if (running == 0) 709
710 msg = curl_multi_info_read (multi_handle, &running);
711 if (msg == NULL)
712 break;
713 /* get session for affected curl handle */
714 //cs = find_session_by_curlhandle (msg->easy_handle);
715 //GNUNET_assert ( cs != NULL );
716 switch (msg->msg)
675 { 717 {
676 do
677 {
678
679 msg = curl_multi_info_read (multi_handle, &running);
680 if (msg == NULL)
681 break;
682 /* get session for affected curl handle */
683 //cs = find_session_by_curlhandle (msg->easy_handle);
684 //GNUNET_assert ( cs != NULL );
685 switch (msg->msg)
686 {
687
688 case CURLMSG_DONE:
689 if ( (msg->data.result != CURLE_OK) &&
690 (msg->data.result != CURLE_GOT_NOTHING) )
691 {
692
693 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
694 _("curl failed for `%s' at %s:%d: `%s'\n"),
695 "curl_multi_perform",
696 __FILE__,
697 __LINE__,
698 curl_easy_strerror (msg->data.result));
699 /* sending msg failed*/
700 curl_easy_cleanup(curl_handle);
701 curl_handle=NULL;
702
703 run_connection_tests(0, NULL);
704 }
705 if (res == &test_no_ident)
706 {
707 if ((res->http_result_code==404) && (buffer_in.len==208))
708 {
709 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer without any peer identification: test passed\n");
710 res->test_failed = GNUNET_NO;
711 }
712 else
713 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer without any peer identification: test failed\n"));
714 }
715 if (res == &test_too_short_ident)
716 {
717 if ((res->http_result_code==404) && (buffer_in.len==208))
718 {
719 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer with too short peer identification: test passed\n");
720 res->test_failed = GNUNET_NO;
721 }
722 else
723 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with too short peer identification: test failed\n"));
724 }
725 if (res == &test_too_long_ident)
726 {
727 if ((res->http_result_code==404) && (buffer_in.len==208))
728 {
729 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer with too long peer identification: test passed\n");
730 res->test_failed = GNUNET_NO;
731 }
732 else
733 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with too long peer identification: test failed\n"));
734 }
735 if (res == &test_valid_ident)
736 {
737 if ((res->http_result_code==200))
738 {
739 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connecting to peer with valid peer identification: test passed\n");
740 res->test_failed = GNUNET_NO;
741 }
742 else
743 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Connecting to peer with valid peer identification: test failed\n"));
744 }
745 curl_easy_cleanup(curl_handle);
746 curl_handle=NULL;
747 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
748 run_connection_tests(1, NULL);
749 run_connection_tests(0, NULL);
750 return;
751 default:
752 break;
753 }
754 718
719 case CURLMSG_DONE:
720 if ((msg->data.result != CURLE_OK) &&
721 (msg->data.result != CURLE_GOT_NOTHING))
722 {
723
724 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
725 _("curl failed for `%s' at %s:%d: `%s'\n"),
726 "curl_multi_perform",
727 __FILE__,
728 __LINE__, curl_easy_strerror (msg->data.result));
729 /* sending msg failed */
730 curl_easy_cleanup (curl_handle);
731 curl_handle = NULL;
732
733 run_connection_tests (0, NULL);
734 }
735 if (res == &test_no_ident)
736 {
737 if ((res->http_result_code == 404) && (buffer_in.len == 208))
738 {
739 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
740 "Connecting to peer without any peer identification: test passed\n");
741 res->test_failed = GNUNET_NO;
742 }
743 else
744 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
745 _
746 ("Connecting to peer without any peer identification: test failed\n"));
747 }
748 if (res == &test_too_short_ident)
749 {
750 if ((res->http_result_code == 404) && (buffer_in.len == 208))
751 {
752 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
753 "Connecting to peer with too short peer identification: test passed\n");
754 res->test_failed = GNUNET_NO;
755 }
756 else
757 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
758 _
759 ("Connecting to peer with too short peer identification: test failed\n"));
760 }
761 if (res == &test_too_long_ident)
762 {
763 if ((res->http_result_code == 404) && (buffer_in.len == 208))
764 {
765 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
766 "Connecting to peer with too long peer identification: test passed\n");
767 res->test_failed = GNUNET_NO;
755 } 768 }
756 while ( (running > 0) ); 769 else
770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
771 _
772 ("Connecting to peer with too long peer identification: test failed\n"));
773 }
774 if (res == &test_valid_ident)
775 {
776 if ((res->http_result_code == 200))
777 {
778 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
779 "Connecting to peer with valid peer identification: test passed\n");
780 res->test_failed = GNUNET_NO;
781 }
782 else
783 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
784 _
785 ("Connecting to peer with valid peer identification: test failed\n"));
786 }
787 curl_easy_cleanup (curl_handle);
788 curl_handle = NULL;
789 if ((res == &test_valid_ident) && (res->test_failed == GNUNET_NO))
790 run_connection_tests (1, NULL);
791 run_connection_tests (0, NULL);
792 return;
793 default:
794 break;
757 } 795 }
796
797 }
798 while ((running > 0));
758 } 799 }
800 }
759 while (mret == CURLM_CALL_MULTI_PERFORM); 801 while (mret == CURLM_CALL_MULTI_PERFORM);
760 send_prepare(cls); 802 send_prepare (cls);
761} 803}
762 804
763/** 805/**
@@ -765,7 +807,8 @@ static void send_execute (void *cls,
765 * @param ses session to send data to 807 * @param ses session to send data to
766 * @return bytes sent to peer 808 * @return bytes sent to peer
767 */ 809 */
768static size_t send_prepare( struct HTTP_Transfer * result) 810static size_t
811send_prepare (struct HTTP_Transfer *result)
769{ 812{
770 fd_set rs; 813 fd_set rs;
771 fd_set ws; 814 fd_set ws;
@@ -782,34 +825,33 @@ static size_t send_prepare( struct HTTP_Transfer * result)
782 FD_ZERO (&es); 825 FD_ZERO (&es);
783 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); 826 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
784 if (mret != CURLM_OK) 827 if (mret != CURLM_OK)
785 { 828 {
786 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 829 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
787 _("%s failed at %s:%d: `%s'\n"), 830 _("%s failed at %s:%d: `%s'\n"),
788 "curl_multi_fdset", __FILE__, __LINE__, 831 "curl_multi_fdset", __FILE__, __LINE__,
789 curl_multi_strerror (mret)); 832 curl_multi_strerror (mret));
790 return -1; 833 return -1;
791 } 834 }
792 mret = curl_multi_timeout (multi_handle, &to); 835 mret = curl_multi_timeout (multi_handle, &to);
793 if (mret != CURLM_OK) 836 if (mret != CURLM_OK)
794 { 837 {
795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 838 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
796 _("%s failed at %s:%d: `%s'\n"), 839 _("%s failed at %s:%d: `%s'\n"),
797 "curl_multi_timeout", __FILE__, __LINE__, 840 "curl_multi_timeout", __FILE__, __LINE__,
798 curl_multi_strerror (mret)); 841 curl_multi_strerror (mret));
799 return -1; 842 return -1;
800 } 843 }
801 844
802 grs = GNUNET_NETWORK_fdset_create (); 845 grs = GNUNET_NETWORK_fdset_create ();
803 gws = GNUNET_NETWORK_fdset_create (); 846 gws = GNUNET_NETWORK_fdset_create ();
804 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1); 847 GNUNET_NETWORK_fdset_copy_native (grs, &rs, max + 1);
805 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1); 848 GNUNET_NETWORK_fdset_copy_native (gws, &ws, max + 1);
806 http_task_send = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 849 http_task_send =
850 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
807 GNUNET_SCHEDULER_NO_TASK, 851 GNUNET_SCHEDULER_NO_TASK,
808 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 0), 852 GNUNET_TIME_relative_multiply
809 grs, 853 (GNUNET_TIME_UNIT_SECONDS, 0), grs, gws,
810 gws, 854 &send_execute, result);
811 &send_execute,
812 result);
813 GNUNET_NETWORK_fdset_destroy (gws); 855 GNUNET_NETWORK_fdset_destroy (gws);
814 GNUNET_NETWORK_fdset_destroy (grs); 856 GNUNET_NETWORK_fdset_destroy (grs);
815 857
@@ -820,36 +862,38 @@ static size_t send_prepare( struct HTTP_Transfer * result)
820/** 862/**
821 * function to send data to server 863 * function to send data to server
822 */ 864 */
823static int send_data( struct HTTP_Transfer * result, char * url) 865static int
866send_data (struct HTTP_Transfer *result, char *url)
824{ 867{
825 868
826 curl_handle = curl_easy_init(); 869 curl_handle = curl_easy_init ();
827 if( NULL == curl_handle) 870 if (NULL == curl_handle)
828 { 871 {
829 printf("easy_init failed \n"); 872 printf ("easy_init failed \n");
830 return GNUNET_SYSERR; 873 return GNUNET_SYSERR;
831 } 874 }
832#if DEBUG_CURL 875#if DEBUG_CURL
833 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L); 876 curl_easy_setopt (curl_handle, CURLOPT_VERBOSE, 1L);
834#endif 877#endif
835 curl_easy_setopt(curl_handle, CURLOPT_URL, url); 878 curl_easy_setopt (curl_handle, CURLOPT_URL, url);
836 curl_easy_setopt(curl_handle, CURLOPT_PUT, 1L); 879 curl_easy_setopt (curl_handle, CURLOPT_PUT, 1L);
837 //curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); 880 //curl_easy_setopt(curl_handle, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
838 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0); 881 curl_easy_setopt (curl_handle, CURLOPT_SSL_VERIFYPEER, 0);
839 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0); 882 curl_easy_setopt (curl_handle, CURLOPT_SSL_VERIFYHOST, 0);
840 curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function); 883 curl_easy_setopt (curl_handle, CURLOPT_HEADERFUNCTION, &header_function);
841 curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result); 884 curl_easy_setopt (curl_handle, CURLOPT_WRITEHEADER, result);
842 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function); 885 curl_easy_setopt (curl_handle, CURLOPT_WRITEFUNCTION, &recv_function);
843 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result); 886 curl_easy_setopt (curl_handle, CURLOPT_WRITEDATA, result);
844 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function); 887 curl_easy_setopt (curl_handle, CURLOPT_READFUNCTION, &send_function);
845 curl_easy_setopt (curl_handle, CURLOPT_READDATA, result); 888 curl_easy_setopt (curl_handle, CURLOPT_READDATA, result);
846 curl_easy_setopt(curl_handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t) buffer_out.len); 889 curl_easy_setopt (curl_handle, CURLOPT_INFILESIZE_LARGE,
847 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 30); 890 (curl_off_t) buffer_out.len);
848 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 20); 891 curl_easy_setopt (curl_handle, CURLOPT_TIMEOUT, 30);
892 curl_easy_setopt (curl_handle, CURLOPT_CONNECTTIMEOUT, 20);
849 893
850 curl_multi_add_handle(multi_handle, curl_handle); 894 curl_multi_add_handle (multi_handle, curl_handle);
851 895
852 send_prepare(result); 896 send_prepare (result);
853 897
854 return GNUNET_OK; 898 return GNUNET_OK;
855} 899}
@@ -858,68 +902,66 @@ static int send_data( struct HTTP_Transfer * result, char * url)
858 * Plugin notifies transport (aka testcase) about its addresses 902 * Plugin notifies transport (aka testcase) about its addresses
859 */ 903 */
860void 904void
861notify_address (void *cls, 905notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
862 int add_remove,
863 const void *addr,
864 size_t addrlen)
865{ 906{
866 char address[INET6_ADDRSTRLEN]; 907 char address[INET6_ADDRSTRLEN];
867 unsigned int port; 908 unsigned int port;
868 struct Plugin_Address * pl_addr; 909 struct Plugin_Address *pl_addr;
869 struct Plugin_Address * cur; 910 struct Plugin_Address *cur;
870 911
871 if (addrlen == (sizeof (struct IPv4HttpAddress))) 912 if (addrlen == (sizeof (struct IPv4HttpAddress)))
872 { 913 {
873 inet_ntop(AF_INET, (struct in_addr *) addr,address,INET_ADDRSTRLEN); 914 inet_ntop (AF_INET, (struct in_addr *) addr, address, INET_ADDRSTRLEN);
874 port = ntohs(((struct IPv4HttpAddress *) addr)->u_port); 915 port = ntohs (((struct IPv4HttpAddress *) addr)->u_port);
875 } 916 }
876 else if (addrlen == (sizeof (struct IPv6HttpAddress))) 917 else if (addrlen == (sizeof (struct IPv6HttpAddress)))
877 { 918 {
878 inet_ntop(AF_INET6, (struct in6_addr *) addr,address,INET6_ADDRSTRLEN); 919 inet_ntop (AF_INET6, (struct in6_addr *) addr, address, INET6_ADDRSTRLEN);
879 port = ntohs(((struct IPv6HttpAddress *) addr)->u6_port); 920 port = ntohs (((struct IPv6HttpAddress *) addr)->u6_port);
880 } 921 }
881 else 922 else
882 { 923 {
883 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 924 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
884 _("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"), 925 _
926 ("Unknown address size: ipv6 has %u ipv4 has %u but this has %u\n"),
885 sizeof (struct IPv6HttpAddress), 927 sizeof (struct IPv6HttpAddress),
886 sizeof (struct IPv4HttpAddress), 928 sizeof (struct IPv4HttpAddress), addrlen);
887 addrlen); 929 return;
888 return; 930 }
889 }
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 931 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 _("Transport plugin notification for address: `%s':%u\n"), 932 _("Transport plugin notification for address: `%s':%u\n"),
892 address, 933 address, port);
893 port); 934 pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address));
894 pl_addr = GNUNET_malloc (sizeof (struct Plugin_Address) );
895 pl_addr->addrlen = addrlen; 935 pl_addr->addrlen = addrlen;
896 pl_addr->addr = GNUNET_malloc(addrlen); 936 pl_addr->addr = GNUNET_malloc (addrlen);
897 memcpy(pl_addr->addr,addr,addrlen); 937 memcpy (pl_addr->addr, addr, addrlen);
898 pl_addr->next = NULL; 938 pl_addr->next = NULL;
899 939
900 if ( NULL == addr_head) 940 if (NULL == addr_head)
901 { 941 {
902 addr_head = pl_addr; 942 addr_head = pl_addr;
903 } 943 }
904 else 944 else
945 {
946 cur = addr_head;
947 while (NULL != cur->next)
905 { 948 {
906 cur = addr_head; 949 cur = cur->next;
907 while (NULL != cur->next)
908 {
909 cur = cur->next;
910 }
911 cur->next = pl_addr;
912 } 950 }
951 cur->next = pl_addr;
952 }
913 fail_notify_address_count++; 953 fail_notify_address_count++;
914 fail_notify_address = GNUNET_NO; 954 fail_notify_address = GNUNET_NO;
915} 955}
916 956
917static void 957static void
918plugin_env_session_end (void *cls, 958plugin_env_session_end (void *cls,
919 const struct GNUNET_PeerIdentity *peer, 959 const struct GNUNET_PeerIdentity *peer,
920 struct Session *session) 960 struct Session *session)
921{ 961{
922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Pluging tells me: session %X to peer `%s' ended\n", session, GNUNET_i2s(peer)); 962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "Pluging tells me: session %X to peer `%s' ended\n", session,
964 GNUNET_i2s (peer));
923} 965}
924 966
925 967
@@ -944,8 +986,7 @@ setup_plugin_environment ()
944 * Task shutting down testcase if it a timeout occurs 986 * Task shutting down testcase if it a timeout occurs
945 */ 987 */
946static void 988static void
947task_timeout (void *cls, 989task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
948 const struct GNUNET_SCHEDULER_TaskContext *tc)
949{ 990{
950 ti_timeout = GNUNET_SCHEDULER_NO_TASK; 991 ti_timeout = GNUNET_SCHEDULER_NO_TASK;
951 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 992 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
@@ -953,30 +994,33 @@ task_timeout (void *cls,
953 994
954 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n"); 995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Testcase timeout\n");
955 fail = GNUNET_YES; 996 fail = GNUNET_YES;
956 shutdown_clean(); 997 shutdown_clean ();
957 return; 998 return;
958} 999}
959 1000
960static void pretty_printer_cb (void *cls, 1001static void
961 const char *address) 1002pretty_printer_cb (void *cls, const char *address)
962{ 1003{
963 if (NULL==address) 1004 if (NULL == address)
964 return; 1005 return;
965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Plugin returned pretty address: `%s'\n",address); 1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Plugin returned pretty address: `%s'\n",
1007 address);
966 fail_pretty_printer_count++; 1008 fail_pretty_printer_count++;
967} 1009}
968 1010
969/** 1011/**
970 * Runs every single test to test the plugin 1012 * Runs every single test to test the plugin
971 */ 1013 */
972static void run_connection_tests( int phase , void * cls) 1014static void
1015run_connection_tests (int phase, void *cls)
973{ 1016{
974 struct GNUNET_MessageHeader * msg; 1017 struct GNUNET_MessageHeader *msg;
975 unsigned int size; 1018 unsigned int size;
976 1019
977 if (phase==0) 1020 if (phase == 0)
978 { 1021 {
979 char * host_str = NULL; 1022 char *host_str = NULL;
1023
980 /* resetting buffers */ 1024 /* resetting buffers */
981 buffer_in.size = HTTP_BUFFER_SIZE; 1025 buffer_in.size = HTTP_BUFFER_SIZE;
982 buffer_in.pos = 0; 1026 buffer_in.pos = 0;
@@ -989,154 +1033,192 @@ static void run_connection_tests( int phase , void * cls)
989 if (test_no_ident.test_executed == GNUNET_NO) 1033 if (test_no_ident.test_executed == GNUNET_NO)
990 { 1034 {
991 /* Connecting to peer without identification */ 1035 /* Connecting to peer without identification */
992 char * ident = ""; 1036 char *ident = "";
993 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); 1037
994 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer without any peer identification.\n")); 1038 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1039 ident);
1040 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1041 _("Connecting to peer without any peer identification.\n"));
995 test_no_ident.test_executed = GNUNET_YES; 1042 test_no_ident.test_executed = GNUNET_YES;
996 send_data ( &test_no_ident, host_str); 1043 send_data (&test_no_ident, host_str);
997 GNUNET_free (host_str); 1044 GNUNET_free (host_str);
998 return; 1045 return;
999 } 1046 }
1000 if (test_too_short_ident.test_executed == GNUNET_NO) 1047 if (test_too_short_ident.test_executed == GNUNET_NO)
1001 { 1048 {
1002 char * ident = "AAAAAAAAAA"; 1049 char *ident = "AAAAAAAAAA";
1050
1003 /* Connecting to peer with too short identification */ 1051 /* Connecting to peer with too short identification */
1004 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); 1052 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1005 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too short peer identification.\n")); 1053 ident);
1054 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1055 _
1056 ("Connecting to peer with too short peer identification.\n"));
1006 test_too_short_ident.test_executed = GNUNET_YES; 1057 test_too_short_ident.test_executed = GNUNET_YES;
1007 send_data ( &test_too_short_ident, host_str); 1058 send_data (&test_too_short_ident, host_str);
1008 GNUNET_free (host_str); 1059 GNUNET_free (host_str);
1009 return; 1060 return;
1010 } 1061 }
1011 1062
1012 if (test_too_long_ident.test_executed == GNUNET_NO) 1063 if (test_too_long_ident.test_executed == GNUNET_NO)
1013 { 1064 {
1014 char * ident = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"; 1065 char *ident =
1066 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
1015 1067
1016 /* Connecting to peer with too long identification */ 1068 /* Connecting to peer with too long identification */
1017 GNUNET_asprintf (&host_str, "%s://%s/%s",PROTOCOL_PREFIX, test_addr,ident); 1069 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1018 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with too long peer identification.\n")); 1070 ident);
1071 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1072 _("Connecting to peer with too long peer identification.\n"));
1019 test_too_long_ident.test_executed = GNUNET_YES; 1073 test_too_long_ident.test_executed = GNUNET_YES;
1020 send_data ( &test_too_long_ident, host_str); 1074 send_data (&test_too_long_ident, host_str);
1021 GNUNET_free (host_str); 1075 GNUNET_free (host_str);
1022 return; 1076 return;
1023 } 1077 }
1024 if (test_valid_ident.test_executed == GNUNET_NO) 1078 if (test_valid_ident.test_executed == GNUNET_NO)
1025 { 1079 {
1026 struct GNUNET_CRYPTO_HashAsciiEncoded ident; 1080 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1027 GNUNET_CRYPTO_hash_to_enc(&my_identity.hashPubKey,&ident); 1081
1028 GNUNET_asprintf (&host_str, "%s://%s/%s%s",PROTOCOL_PREFIX, test_addr,(char *) &ident,";0"); 1082 GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
1029 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Connecting to peer with valid peer identification.\n")); 1083 GNUNET_asprintf (&host_str, "%s://%s/%s%s", PROTOCOL_PREFIX, test_addr,
1084 (char *) &ident, ";0");
1085 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1086 _("Connecting to peer with valid peer identification.\n"));
1030 test_valid_ident.test_executed = GNUNET_YES; 1087 test_valid_ident.test_executed = GNUNET_YES;
1031 send_data ( &test_valid_ident, host_str); 1088 send_data (&test_valid_ident, host_str);
1032 GNUNET_free (host_str); 1089 GNUNET_free (host_str);
1033 return; 1090 return;
1034 } 1091 }
1035 } 1092 }
1036 if (phase==1) 1093 if (phase == 1)
1037 { 1094 {
1038 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 1: transmit data to all suggested addresses\n\n")); 1095 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1096 _("\nPhase 1: transmit data to all suggested addresses\n\n"));
1039 /* Using one of the addresses the plugin proposed */ 1097 /* Using one of the addresses the plugin proposed */
1040 GNUNET_assert (addr_head->addr != NULL); 1098 GNUNET_assert (addr_head->addr != NULL);
1041 1099
1042 struct Plugin_Address * tmp_addr; 1100 struct Plugin_Address *tmp_addr;
1043 struct GNUNET_MessageHeader msg; 1101 struct GNUNET_MessageHeader msg;
1044 char * tmp = GNUNET_malloc(sizeof(struct GNUNET_MessageHeader)); 1102 char *tmp = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
1045 char address[INET6_ADDRSTRLEN]; 1103 char address[INET6_ADDRSTRLEN];
1046 unsigned int port; 1104 unsigned int port;
1047 unsigned int type = 10; 1105 unsigned int type = 10;
1048 1106
1049 msg.size=htons(sizeof(struct GNUNET_MessageHeader)); 1107 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
1050 tmp_addr = addr_head; 1108 tmp_addr = addr_head;
1051 /* send a message to all addresses advertised by plugin */ 1109 /* send a message to all addresses advertised by plugin */
1052 1110
1053 int count = 0; 1111 int count = 0;
1112
1054 while (tmp_addr != NULL) 1113 while (tmp_addr != NULL)
1055 { 1114 {
1056 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress))) 1115 if (tmp_addr->addrlen == (sizeof (struct IPv4HttpAddress)))
1057 { 1116 {
1058 inet_ntop(AF_INET, (struct in_addr *) tmp_addr->addr,address,INET_ADDRSTRLEN); 1117 inet_ntop (AF_INET, (struct in_addr *) tmp_addr->addr, address,
1059 port = ntohs(((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); 1118 INET_ADDRSTRLEN);
1060 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address, port); 1119 port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1061 } 1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1121 "Sending message to addres no. %u: `%s':%u\n", count,
1122 address, port);
1123 }
1062 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) 1124 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1063 { 1125 {
1064 inet_ntop(AF_INET6, (struct in6_addr *) tmp_addr->addr,address,INET6_ADDRSTRLEN); 1126 inet_ntop (AF_INET6, (struct in6_addr *) tmp_addr->addr, address,
1065 port = ntohs(((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); 1127 INET6_ADDRSTRLEN);
1066 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Sending message to addres no. %u: `%s':%u\n", count,address,port); 1128 port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1067 } 1129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1068 msg.type=htons(type); 1130 "Sending message to addres no. %u: `%s':%u\n", count,
1069 memcpy(tmp,&msg,sizeof(struct GNUNET_MessageHeader)); 1131 address, port);
1070 api->send(api->cls, &my_identity, tmp, sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont, &fail_msgs_transmited_to_local_addrs); 1132 }
1133 msg.type = htons (type);
1134 memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
1135 api->send (api->cls, &my_identity, tmp,
1136 sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
1137 tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont,
1138 &fail_msgs_transmited_to_local_addrs);
1071 tmp_addr = tmp_addr->next; 1139 tmp_addr = tmp_addr->next;
1072 1140
1073 count ++; 1141 count++;
1074 type ++; 1142 type++;
1075 } 1143 }
1076 GNUNET_free(tmp); 1144 GNUNET_free (tmp);
1077 return; 1145 return;
1078 } 1146 }
1079 1147
1080 if (phase==2) 1148 if (phase == 2)
1081 { 1149 {
1082 struct Session * session = cls; 1150 struct Session *session = cls;
1083 msg = GNUNET_malloc (sizeof(struct GNUNET_MessageHeader));
1084
1085 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n"));
1086 size = sizeof(struct GNUNET_MessageHeader);
1087 msg->size=htons(size);
1088 msg->type = htons(20);
1089 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1090
1091 msg->type = htons(21);
1092 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1093
1094 /* answer on session*/
1095 size = sizeof( struct GNUNET_MessageHeader);
1096 msg->size = htons(size);
1097 msg->type = htons(22);
1098 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1099 1151
1100 GNUNET_free(msg); 1152 msg = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader));
1101 1153
1102 /* answer on session with big message not fitting in mhd send buffer*/ 1154 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 2: session selection\n\n"));
1103 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1; 1155 size = sizeof (struct GNUNET_MessageHeader);
1156 msg->size = htons (size);
1157 msg->type = htons (20);
1158 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1159 NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1160
1161 msg->type = htons (21);
1162 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1163 NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1164
1165 /* answer on session */
1166 size = sizeof (struct GNUNET_MessageHeader);
1167 msg->size = htons (size);
1168 msg->type = htons (22);
1169 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1170 session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1171
1172 GNUNET_free (msg);
1173
1174 /* answer on session with big message not fitting in mhd send buffer */
1175 size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1104 msg = GNUNET_malloc (size); 1176 msg = GNUNET_malloc (size);
1105 msg->size=htons(size); 1177 msg->size = htons (size);
1106 msg->type = htons(23); 1178 msg->type = htons (23);
1107 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL); 1179 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1108 GNUNET_free(msg); 1180 session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1181 GNUNET_free (msg);
1109 return; 1182 return;
1110 } 1183 }
1111 1184
1112 if (phase==3) 1185 if (phase == 3)
1113 { 1186 {
1114 1187
1115 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 3: send multiple or big messages after disconnect\n\n")); 1188 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1189 _
1190 ("\nPhase 3: send multiple or big messages after disconnect\n\n"));
1116 /* disconnect from peer, so new connections are created */ 1191 /* disconnect from peer, so new connections are created */
1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Disconnect from peer: `%s'\n", GNUNET_i2s(&my_identity)); 1192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect from peer: `%s'\n",
1118 api->disconnect(api->cls, &my_identity); 1193 GNUNET_i2s (&my_identity));
1194 api->disconnect (api->cls, &my_identity);
1119 1195
1120 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Phase 3: sending messages\n")); 1196 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Phase 3: sending messages\n"));
1121 /* send a multiple GNUNET_messages at a time*/ 1197 /* send a multiple GNUNET_messages at a time */
1122 size = 2 * sizeof(struct GNUNET_MessageHeader); 1198 size = 2 * sizeof (struct GNUNET_MessageHeader);
1123 msg = GNUNET_malloc( 2* size); 1199 msg = GNUNET_malloc (2 * size);
1124 msg->size = htons(size); 1200 msg->size = htons (size);
1125 msg->type = htons(30); 1201 msg->type = htons (30);
1126 struct GNUNET_MessageHeader * msg2 = &msg[2]; 1202 struct GNUNET_MessageHeader *msg2 = &msg[2];
1127 msg2->size = htons(2 * sizeof(struct GNUNET_MessageHeader)); 1203
1128 msg2->type = htons(31); 1204 msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
1129 api->send(api->cls, &my_identity, (const char *) msg, 4 * sizeof(struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission); 1205 msg2->type = htons (31);
1130 GNUNET_free(msg); 1206 api->send (api->cls, &my_identity, (const char *) msg,
1207 4 * sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
1208 addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont,
1209 &fail_multiple_msgs_in_transmission);
1210 GNUNET_free (msg);
1131 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1211 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1132 1212
1133 size = GNUNET_SERVER_MAX_MESSAGE_SIZE-1; 1213 size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1;
1134 msg = GNUNET_malloc(size); 1214 msg = GNUNET_malloc (size);
1135 msg->size = htons(size); 1215 msg->size = htons (size);
1136 msg->type = htons(32); 1216 msg->type = htons (32);
1137 api->send(api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT, NULL,addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size); 1217 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1138 GNUNET_free(msg); 1218 NULL, addr_head->addr, addr_head->addrlen, GNUNET_NO,
1139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"No more tests to run\n"); 1219 &task_send_cont, &fail_msg_transmited_max_size);
1220 GNUNET_free (msg);
1221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
1140 } 1222 }
1141} 1223}
1142 1224
@@ -1152,12 +1234,13 @@ run (void *cls,
1152 char *const *args, 1234 char *const *args,
1153 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) 1235 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1154{ 1236{
1155 char * libname; 1237 char *libname;
1238
1156 cfg = c; 1239 cfg = c;
1157 char *keyfile; 1240 char *keyfile;
1158 unsigned long long tneigh; 1241 unsigned long long tneigh;
1159 struct Plugin_Address * cur; 1242 struct Plugin_Address *cur;
1160 const char * addr_str; 1243 const char *addr_str;
1161 struct stat sbuf; 1244 struct stat sbuf;
1162 unsigned int suggest_res; 1245 unsigned int suggest_res;
1163 1246
@@ -1175,8 +1258,9 @@ run (void *cls,
1175 addr_head = NULL; 1258 addr_head = NULL;
1176 count_str_addr = 0; 1259 count_str_addr = 0;
1177 /* parse configuration */ 1260 /* parse configuration */
1178 if (GNUNET_CONFIGURATION_have_value (c,"PATHS", "SERVICEHOME")) 1261 if (GNUNET_CONFIGURATION_have_value (c, "PATHS", "SERVICEHOME"))
1179 GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME", &servicehome); 1262 GNUNET_CONFIGURATION_get_value_string (c, "PATHS", "SERVICEHOME",
1263 &servicehome);
1180 1264
1181 1265
1182 if ((GNUNET_OK != 1266 if ((GNUNET_OK !=
@@ -1188,21 +1272,21 @@ run (void *cls,
1188 GNUNET_CONFIGURATION_get_value_filename (c, 1272 GNUNET_CONFIGURATION_get_value_filename (c,
1189 "GNUNETD", 1273 "GNUNETD",
1190 "HOSTKEY", &keyfile))) 1274 "HOSTKEY", &keyfile)))
1191 { 1275 {
1192 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1193 _ 1277 _
1194 ("Transport service is lacking key configuration settings. Exiting.\n")); 1278 ("Transport service is lacking key configuration settings. Exiting.\n"));
1195 GNUNET_SCHEDULER_shutdown (); 1279 GNUNET_SCHEDULER_shutdown ();
1196 fail = 1; 1280 fail = 1;
1197 return; 1281 return;
1198 } 1282 }
1199 1283
1200 if ((GNUNET_OK != 1284 if ((GNUNET_OK !=
1201 GNUNET_CONFIGURATION_get_value_number (cfg, 1285 GNUNET_CONFIGURATION_get_value_number (cfg,
1202 "transport-https", 1286 "transport-https",
1203 "PORT", 1287 "PORT",
1204 &port)) || 1288 &port)) ||
1205 (port > 65535) || (port == 0)) 1289 (port > 65535) || (port == 0))
1206 { 1290 {
1207 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1291 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
1208 "https", 1292 "https",
@@ -1212,59 +1296,63 @@ run (void *cls,
1212 } 1296 }
1213 1297
1214 /* Get private key file from config */ 1298 /* Get private key file from config */
1215 if (GNUNET_CONFIGURATION_have_value (cfg, 1299 if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "KEY_FILE"))
1216 "transport-https", "KEY_FILE"))
1217 { 1300 {
1218 GNUNET_CONFIGURATION_get_value_string (cfg, 1301 GNUNET_CONFIGURATION_get_value_string (cfg,
1219 "transport-https", 1302 "transport-https",
1220 "KEY_FILE", 1303 "KEY_FILE", &key_file);
1221 &key_file);
1222 } 1304 }
1223 if (key_file == NULL) 1305 if (key_file == NULL)
1224 GNUNET_asprintf(&key_file,"https.key"); 1306 GNUNET_asprintf (&key_file, "https.key");
1225 1307
1226 if (0 == stat (key_file, &sbuf )) 1308 if (0 == stat (key_file, &sbuf))
1227 { 1309 {
1228 if (0 == remove(key_file)) 1310 if (0 == remove (key_file))
1229 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing private key file `%s'\n",key_file); 1311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1230 else 1312 "Successfully removed existing private key file `%s'\n",
1231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove private key file `%s'\n",key_file); 1313 key_file);
1314 else
1315 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1316 "Failed to remove private key file `%s'\n", key_file);
1232 } 1317 }
1233 1318
1234 /* Get private key file from config */ 1319 /* Get private key file from config */
1235 if (GNUNET_CONFIGURATION_have_value (cfg, 1320 if (GNUNET_CONFIGURATION_have_value (cfg, "transport-https", "CERT_FILE"))
1236 "transport-https", "CERT_FILE"))
1237 { 1321 {
1238 GNUNET_CONFIGURATION_get_value_string (cfg, 1322 GNUNET_CONFIGURATION_get_value_string (cfg,
1239 "transport-https", 1323 "transport-https",
1240 "CERT_FILE", 1324 "CERT_FILE", &cert_file);
1241 &cert_file);
1242 } 1325 }
1243 if (cert_file == NULL) 1326 if (cert_file == NULL)
1244 GNUNET_asprintf(&cert_file,"https.cert"); 1327 GNUNET_asprintf (&cert_file, "https.cert");
1245 1328
1246 if (0 == stat (cert_file, &sbuf )) 1329 if (0 == stat (cert_file, &sbuf))
1247 { 1330 {
1248 if (0 == remove(cert_file)) 1331 if (0 == remove (cert_file))
1249 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Successfully removed existing certificate file `%s'\n",cert_file); 1332 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1250 else 1333 "Successfully removed existing certificate file `%s'\n",
1251 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove existing certificate file `%s'\n",cert_file); 1334 cert_file);
1335 else
1336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1337 "Failed to remove existing certificate file `%s'\n",
1338 cert_file);
1252 } 1339 }
1253 1340
1254 max_connect_per_transport = (uint32_t) tneigh; 1341 max_connect_per_transport = (uint32_t) tneigh;
1255 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 1342 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
1256 GNUNET_free (keyfile); 1343 GNUNET_free (keyfile);
1257 if (my_private_key == NULL) 1344 if (my_private_key == NULL)
1258 { 1345 {
1259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1346 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1260 _("Transport service could not access hostkey. Exiting.\n")); 1347 _("Transport service could not access hostkey. Exiting.\n"));
1261 GNUNET_SCHEDULER_shutdown (); 1348 GNUNET_SCHEDULER_shutdown ();
1262 fail = 1; 1349 fail = 1;
1263 return; 1350 return;
1264 } 1351 }
1265 1352
1266 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 1353 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
1267 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), &my_identity.hashPubKey); 1354 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
1355 &my_identity.hashPubKey);
1268 1356
1269 /* assertions before start */ 1357 /* assertions before start */
1270 GNUNET_assert ((port > 0) && (port <= 65535)); 1358 GNUNET_assert ((port > 0) && (port <= 65535));
@@ -1272,7 +1360,8 @@ run (void *cls,
1272 /* load plugins... */ 1360 /* load plugins... */
1273 setup_plugin_environment (); 1361 setup_plugin_environment ();
1274 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_https"); 1362 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_https");
1275 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTPS transport plugin `%s'\n"),libname); 1363 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1364 _("Loading HTTPS transport plugin `%s'\n"), libname);
1276 api = GNUNET_PLUGIN_load (libname, &env); 1365 api = GNUNET_PLUGIN_load (libname, &env);
1277 GNUNET_free (libname); 1366 GNUNET_free (libname);
1278 if (api == NULL) 1367 if (api == NULL)
@@ -1286,46 +1375,52 @@ run (void *cls,
1286 ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL); 1375 ti_timeout = GNUNET_SCHEDULER_add_delayed (TEST_TIMEOUT, &task_timeout, NULL);
1287 1376
1288 /* testing plugin functionality */ 1377 /* testing plugin functionality */
1289 GNUNET_assert (0!=fail_notify_address_count); 1378 GNUNET_assert (0 != fail_notify_address_count);
1290 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Transport plugin returned %u addresses to connect to\n"), fail_notify_address_count); 1379 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1380 _("Transport plugin returned %u addresses to connect to\n"),
1381 fail_notify_address_count);
1291 1382
1292 /* testing pretty printer with all addresses obtained from the plugin*/ 1383 /* testing pretty printer with all addresses obtained from the plugin */
1293 cur = addr_head; 1384 cur = addr_head;
1294 while (cur != NULL) 1385 while (cur != NULL)
1295 { 1386 {
1296 1387
1297 api->address_pretty_printer (api->cls, "http",cur->addr,cur->addrlen, GNUNET_NO,TEST_TIMEOUT, &pretty_printer_cb,NULL); 1388 api->address_pretty_printer (api->cls, "http", cur->addr, cur->addrlen,
1389 GNUNET_NO, TEST_TIMEOUT, &pretty_printer_cb,
1390 NULL);
1298 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); 1391 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1299 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); 1392 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1300 1393
1301 GNUNET_assert (GNUNET_OK == suggest_res); 1394 GNUNET_assert (GNUNET_OK == suggest_res);
1302 GNUNET_assert (NULL != addr_str); 1395 GNUNET_assert (NULL != addr_str);
1303 count_str_addr++; 1396 count_str_addr++;
1304 GNUNET_free ( (char *) addr_str); 1397 GNUNET_free ((char *) addr_str);
1305 cur = cur->next; 1398 cur = cur->next;
1306 } 1399 }
1307 GNUNET_assert (fail_pretty_printer_count > 0); 1400 GNUNET_assert (fail_pretty_printer_count > 0);
1308 GNUNET_assert (fail_pretty_printer_count==fail_notify_address_count); 1401 GNUNET_assert (fail_pretty_printer_count == fail_notify_address_count);
1309 GNUNET_assert (fail_pretty_printer_count==count_str_addr); 1402 GNUNET_assert (fail_pretty_printer_count == count_str_addr);
1310 fail_pretty_printer=GNUNET_NO; 1403 fail_pretty_printer = GNUNET_NO;
1311 fail_addr_to_str=GNUNET_NO; 1404 fail_addr_to_str = GNUNET_NO;
1312 1405
1313 struct IPv4HttpAddress failing_addr; 1406 struct IPv4HttpAddress failing_addr;
1314 1407
1315 /* Suggesting addresses with wrong size*/ 1408 /* Suggesting addresses with wrong size */
1316 failing_addr.ipv4_addr = htonl(INADDR_LOOPBACK); 1409 failing_addr.ipv4_addr = htonl (INADDR_LOOPBACK);
1317 failing_addr.u_port = htons(0); 1410 failing_addr.u_port = htons (0);
1318 suggest_res = api->check_address (api->cls,&failing_addr,sizeof (struct IPv6HttpAddress)); 1411 suggest_res =
1412 api->check_address (api->cls, &failing_addr,
1413 sizeof (struct IPv6HttpAddress));
1319 GNUNET_assert (GNUNET_SYSERR == suggest_res); 1414 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1320 1415
1321 /* Suggesting addresses with wrong address*/ 1416 /* Suggesting addresses with wrong address */
1322 failing_addr.ipv4_addr = htonl(0xffc00000); 1417 failing_addr.ipv4_addr = htonl (0xffc00000);
1323 failing_addr.u_port = htons(12389); 1418 failing_addr.u_port = htons (12389);
1324 suggest_res = api->check_address (api->cls,&failing_addr,100); 1419 suggest_res = api->check_address (api->cls, &failing_addr, 100);
1325 GNUNET_assert (GNUNET_SYSERR == suggest_res); 1420 GNUNET_assert (GNUNET_SYSERR == suggest_res);
1326 1421
1327 /* test sending to client */ 1422 /* test sending to client */
1328 multi_handle = curl_multi_init(); 1423 multi_handle = curl_multi_init ();
1329 1424
1330 /* Setting up buffers */ 1425 /* Setting up buffers */
1331 buffer_in.size = HTTP_BUFFER_SIZE; 1426 buffer_in.size = HTTP_BUFFER_SIZE;
@@ -1354,10 +1449,12 @@ run (void *cls,
1354 test_valid_ident.test_executed = GNUNET_NO; 1449 test_valid_ident.test_executed = GNUNET_NO;
1355 test_valid_ident.test_failed = GNUNET_YES; 1450 test_valid_ident.test_failed = GNUNET_YES;
1356 1451
1357 test_addr = (char *) api->address_to_string (api->cls,addr_head->addr,addr_head->addrlen); 1452 test_addr =
1453 (char *) api->address_to_string (api->cls, addr_head->addr,
1454 addr_head->addrlen);
1358 1455
1359 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n")); 1456 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("\nPhase 0\n\n"));
1360 run_connection_tests(0, NULL); 1457 run_connection_tests (0, NULL);
1361 1458
1362 /* testing finished */ 1459 /* testing finished */
1363 1460
@@ -1380,6 +1477,7 @@ main (int argc, char *const *argv)
1380 GNUNET_GETOPT_OPTION_END 1477 GNUNET_GETOPT_OPTION_END
1381 }; 1478 };
1382 int ret; 1479 int ret;
1480
1383 char *const argv_prog[] = { 1481 char *const argv_prog[] = {
1384 "test_gnunet_transport_plugin.https", 1482 "test_gnunet_transport_plugin.https",
1385 "-c", 1483 "-c",
@@ -1401,11 +1499,15 @@ main (int argc, char *const *argv)
1401 NULL); 1499 NULL);
1402 1500
1403 struct GNUNET_CONFIGURATION_Handle *cfg; 1501 struct GNUNET_CONFIGURATION_Handle *cfg;
1502
1404 cfg = GNUNET_CONFIGURATION_create (); 1503 cfg = GNUNET_CONFIGURATION_create ();
1405 1504
1406 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, "test_plugin_transport_data_http.conf")); 1505 GNUNET_assert (GNUNET_OK ==
1407 if (GNUNET_CONFIGURATION_have_value (cfg,"PATHS", "SERVICEHOME")) 1506 GNUNET_CONFIGURATION_load (cfg,
1408 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME", &servicehome); 1507 "test_plugin_transport_data_http.conf"));
1508 if (GNUNET_CONFIGURATION_have_value (cfg, "PATHS", "SERVICEHOME"))
1509 GNUNET_CONFIGURATION_get_value_string (cfg, "PATHS", "SERVICEHOME",
1510 &servicehome);
1409 GNUNET_DISK_directory_remove (servicehome); 1511 GNUNET_DISK_directory_remove (servicehome);
1410 GNUNET_CONFIGURATION_destroy (cfg); 1512 GNUNET_CONFIGURATION_destroy (cfg);
1411 1513
@@ -1413,7 +1515,8 @@ main (int argc, char *const *argv)
1413 GNUNET_PROGRAM_run (5, 1515 GNUNET_PROGRAM_run (5,
1414 argv_prog, 1516 argv_prog,
1415 "test_gnunet_transport_plugin.https", 1517 "test_gnunet_transport_plugin.https",
1416 "testcase", options, &run, NULL)) ? GNUNET_NO : GNUNET_YES; 1518 "testcase", options, &run,
1519 NULL)) ? GNUNET_NO : GNUNET_YES;
1417 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n")); 1520 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("\ndelete\n\n"));
1418 if (servicehome != NULL) 1521 if (servicehome != NULL)
1419 { 1522 {
diff --git a/src/transport/test_plugin_transport_udp.c b/src/transport/test_plugin_transport_udp.c
index f790ccedc..b23d4eb67 100644
--- a/src/transport/test_plugin_transport_udp.c
+++ b/src/transport/test_plugin_transport_udp.c
@@ -90,11 +90,10 @@ static int ok;
90 */ 90 */
91static void 91static void
92receive (void *cls, 92receive (void *cls,
93 const struct GNUNET_PeerIdentity * peer, 93 const struct GNUNET_PeerIdentity *peer,
94 const struct GNUNET_MessageHeader * message, 94 const struct GNUNET_MessageHeader *message,
95 uint32_t distance, 95 uint32_t distance,
96 const char *sender_address, 96 const char *sender_address, size_t sender_address_len)
97 size_t sender_address_len)
98{ 97{
99 /* do nothing */ 98 /* do nothing */
100} 99}
@@ -118,8 +117,7 @@ static void
118unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 117unload_plugins (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
119{ 118{
120 GNUNET_assert (NULL == 119 GNUNET_assert (NULL ==
121 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp", 120 GNUNET_PLUGIN_unload ("libgnunet_plugin_transport_udp", api));
122 api));
123 if (my_private_key != NULL) 121 if (my_private_key != NULL)
124 GNUNET_CRYPTO_rsa_key_free (my_private_key); 122 GNUNET_CRYPTO_rsa_key_free (my_private_key);
125 123
@@ -146,10 +144,9 @@ test_validation ()
146 soaddr.sin_port = htons (2368 /* FIXME: get from config! */ ); 144 soaddr.sin_port = htons (2368 /* FIXME: get from config! */ );
147 soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 145 soaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
148 146
149 api->check_address(api->cls, 147 api->check_address (api->cls, &soaddr, sizeof (soaddr));
150 &soaddr, sizeof (soaddr));
151 148
152 unload_plugins(env.cls, env.cfg); 149 unload_plugins (env.cls, env.cfg);
153} 150}
154 151
155 152
@@ -190,24 +187,23 @@ run (void *cls,
190 GNUNET_CONFIGURATION_get_value_filename (c, 187 GNUNET_CONFIGURATION_get_value_filename (c,
191 "GNUNETD", 188 "GNUNETD",
192 "HOSTKEY", &keyfile))) 189 "HOSTKEY", &keyfile)))
193 { 190 {
194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 191 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
195 _ 192 _
196 ("Transport service is lacking key configuration settings. Exiting.\n")); 193 ("Transport service is lacking key configuration settings. Exiting.\n"));
197 GNUNET_SCHEDULER_shutdown (s); 194 GNUNET_SCHEDULER_shutdown (s);
198 return; 195 return;
199 } 196 }
200 max_connect_per_transport = (uint32_t) tneigh; 197 max_connect_per_transport = (uint32_t) tneigh;
201 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile); 198 my_private_key = GNUNET_CRYPTO_rsa_key_create_from_file (keyfile);
202 GNUNET_free (keyfile); 199 GNUNET_free (keyfile);
203 if (my_private_key == NULL) 200 if (my_private_key == NULL)
204 { 201 {
205 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
206 _ 203 _("Transport service could not access hostkey. Exiting.\n"));
207 ("Transport service could not access hostkey. Exiting.\n")); 204 GNUNET_SCHEDULER_shutdown (s);
208 GNUNET_SCHEDULER_shutdown (s); 205 return;
209 return; 206 }
210 }
211 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key); 207 GNUNET_CRYPTO_rsa_key_get_public (my_private_key, &my_public_key);
212 GNUNET_CRYPTO_hash (&my_public_key, 208 GNUNET_CRYPTO_hash (&my_public_key,
213 sizeof (my_public_key), &my_identity.hashPubKey); 209 sizeof (my_public_key), &my_identity.hashPubKey);
@@ -220,12 +216,12 @@ run (void *cls,
220 api = GNUNET_PLUGIN_load (libname, &env); 216 api = GNUNET_PLUGIN_load (libname, &env);
221 GNUNET_free (libname); 217 GNUNET_free (libname);
222 if (api == NULL) 218 if (api == NULL)
223 { 219 {
224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 220 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
225 _("Failed to load transport plugin for udp\n")); 221 _("Failed to load transport plugin for udp\n"));
226 /* FIXME: set some error code for main */ 222 /* FIXME: set some error code for main */
227 return; 223 return;
228 } 224 }
229 test_validation (); 225 test_validation ();
230} 226}
231 227
@@ -244,6 +240,7 @@ main (int argc, char *const *argv)
244 GNUNET_GETOPT_OPTION_END 240 GNUNET_GETOPT_OPTION_END
245 }; 241 };
246 int ret; 242 int ret;
243
247 char *const argv_prog[] = { 244 char *const argv_prog[] = {
248 "test_plugin_transport", 245 "test_plugin_transport",
249 "-c", 246 "-c",
diff --git a/src/transport/test_plugin_transport_wlan_dummy.c b/src/transport/test_plugin_transport_wlan_dummy.c
index 173d22bba..eba4f9dbd 100644
--- a/src/transport/test_plugin_transport_wlan_dummy.c
+++ b/src/transport/test_plugin_transport_wlan_dummy.c
@@ -55,76 +55,79 @@
55static int first; 55static int first;
56 56
57static void 57static void
58sigfunc(int sig) 58sigfunc (int sig)
59{ 59{
60 closeprog = 1; 60 closeprog = 1;
61 unlink(FIFO_FILE1); 61 unlink (FIFO_FILE1);
62 unlink(FIFO_FILE2); 62 unlink (FIFO_FILE2);
63} 63}
64 64
65static void 65static void
66stdin_send(void *cls, void *client, 66stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
67 const struct GNUNET_MessageHeader *hdr)
68{ 67{
69 struct sendbuf *write_pout = cls; 68 struct sendbuf *write_pout = cls;
70 int sendsize; 69 int sendsize;
71 struct GNUNET_MessageHeader newheader; 70 struct GNUNET_MessageHeader newheader;
72 char * to_data; 71 char *to_data;
73 char * to_radiotap; 72 char *to_radiotap;
74 char * to_start; 73 char *to_start;
75 74
76 sendsize = ntohs(hdr->size) - sizeof(struct Radiotap_Send) 75 sendsize = ntohs (hdr->size) - sizeof (struct Radiotap_Send)
77 + sizeof(struct Radiotap_rx); 76 + sizeof (struct Radiotap_rx);
78 77
79 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) 78 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
80 { 79 {
81 fprintf(stderr, "Function stdin_send: wrong packet type\n"); 80 fprintf (stderr, "Function stdin_send: wrong packet type\n");
82 exit(1); 81 exit (1);
83 } 82 }
84 if ((sendsize + write_pout->size) > MAXLINE * 2) 83 if ((sendsize + write_pout->size) > MAXLINE * 2)
85 { 84 {
86 fprintf(stderr, "Function stdin_send: Packet too big for buffer\n"); 85 fprintf (stderr, "Function stdin_send: Packet too big for buffer\n");
87 exit(1); 86 exit (1);
88 } 87 }
89 88
90 newheader.size = htons(sendsize); 89 newheader.size = htons (sendsize);
91 newheader.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA); 90 newheader.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA);
92 91
93 to_start = write_pout->buf + write_pout->size; 92 to_start = write_pout->buf + write_pout->size;
94 memcpy(to_start, &newheader, sizeof(struct GNUNET_MessageHeader)); 93 memcpy (to_start, &newheader, sizeof (struct GNUNET_MessageHeader));
95 write_pout->size += sizeof(struct GNUNET_MessageHeader); 94 write_pout->size += sizeof (struct GNUNET_MessageHeader);
96 95
97 to_radiotap = to_start + sizeof(struct GNUNET_MessageHeader); 96 to_radiotap = to_start + sizeof (struct GNUNET_MessageHeader);
98 memset(to_radiotap, 0, sizeof (struct Radiotap_rx)); 97 memset (to_radiotap, 0, sizeof (struct Radiotap_rx));
99 write_pout->size += sizeof(struct Radiotap_rx); 98 write_pout->size += sizeof (struct Radiotap_rx);
100 99
101 to_data = to_radiotap + sizeof(struct Radiotap_rx); 100 to_data = to_radiotap + sizeof (struct Radiotap_rx);
102 memcpy(to_data, 101 memcpy (to_data,
103 ((char *) hdr) + sizeof(struct Radiotap_Send) + sizeof(struct GNUNET_MessageHeader), 102 ((char *) hdr) + sizeof (struct Radiotap_Send) +
104 ntohs(hdr->size) - sizeof(struct Radiotap_Send) - sizeof(struct GNUNET_MessageHeader)); 103 sizeof (struct GNUNET_MessageHeader),
105 write_pout->size += ntohs(hdr->size) - sizeof(struct Radiotap_Send) - sizeof(struct GNUNET_MessageHeader); 104 ntohs (hdr->size) - sizeof (struct Radiotap_Send) -
105 sizeof (struct GNUNET_MessageHeader));
106 write_pout->size +=
107 ntohs (hdr->size) - sizeof (struct Radiotap_Send) -
108 sizeof (struct GNUNET_MessageHeader);
106} 109}
107 110
108static void 111static void
109file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr) 112file_in_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr)
110{ 113{
111 struct sendbuf * write_std = cls; 114 struct sendbuf *write_std = cls;
112 uint16_t sendsize; 115 uint16_t sendsize;
113 116
114 sendsize = ntohs(hdr->size); 117 sendsize = ntohs (hdr->size);
115 118
116 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs(hdr->type)) 119 if (GNUNET_MESSAGE_TYPE_WLAN_HELPER_DATA != ntohs (hdr->type))
117 { 120 {
118 fprintf(stderr, "Function file_in_send: wrong packet type\n"); 121 fprintf (stderr, "Function file_in_send: wrong packet type\n");
119 exit(1); 122 exit (1);
120 } 123 }
121 if ((sendsize + write_std->size) > MAXLINE * 2) 124 if ((sendsize + write_std->size) > MAXLINE * 2)
122 { 125 {
123 fprintf(stderr, "Function file_in_send: Packet too big for buffer\n"); 126 fprintf (stderr, "Function file_in_send: Packet too big for buffer\n");
124 exit(1); 127 exit (1);
125 } 128 }
126 129
127 memcpy(write_std->buf + write_std->size, hdr, sendsize); 130 memcpy (write_std->buf + write_std->size, hdr, sendsize);
128 write_std->size += sendsize; 131 write_std->size += sendsize;
129} 132}
130 133
@@ -132,7 +135,7 @@ int closeprog;
132 135
133 136
134int 137int
135testmode(int argc, char *argv[]) 138testmode (int argc, char *argv[])
136{ 139{
137 struct stat st; 140 struct stat st;
138 int erg; 141 int erg;
@@ -144,111 +147,113 @@ testmode(int argc, char *argv[])
144 int fdpout; 147 int fdpout;
145 148
146 //make the fifos if needed 149 //make the fifos if needed
147 if (0 != stat(FIFO_FILE1, &st)) 150 if (0 != stat (FIFO_FILE1, &st))
151 {
152 if (0 == stat (FIFO_FILE2, &st))
148 { 153 {
149 if (0 == stat(FIFO_FILE2, &st)) 154 fprintf (stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n");
150 { 155 exit (1);
151 fprintf(stderr, "FIFO_FILE2 exists, but FIFO_FILE1 not\n"); 156 }
152 exit(1);
153 }
154
155 umask(0);
156 //unlink(FIFO_FILE1);
157 //unlink(FIFO_FILE2);
158 // FIXME: use mkfifo!
159 erg = mknod(FIFO_FILE1, S_IFIFO | 0666, 0);
160 if (0 != erg)
161 {
162 fprintf(stderr, "Error at mknode1 \n");
163 //exit(1);
164 }
165 erg = mknod(FIFO_FILE2, S_IFIFO | 0666, 0);
166 if (0 != erg)
167 {
168 fprintf(stderr, "Error at mknode2 \n");
169 //exit(1);
170 }
171 157
158 umask (0);
159 //unlink(FIFO_FILE1);
160 //unlink(FIFO_FILE2);
161 // FIXME: use mkfifo!
162 erg = mknod (FIFO_FILE1, S_IFIFO | 0666, 0);
163 if (0 != erg)
164 {
165 fprintf (stderr, "Error at mknode1 \n");
166 //exit(1);
172 } 167 }
173 else 168 erg = mknod (FIFO_FILE2, S_IFIFO | 0666, 0);
169 if (0 != erg)
174 { 170 {
171 fprintf (stderr, "Error at mknode2 \n");
172 //exit(1);
173 }
175 174
176 if (0 != stat(FIFO_FILE2, &st)) 175 }
177 { 176 else
178 fprintf(stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n"); 177 {
179 exit(1);
180 }
181 178
179 if (0 != stat (FIFO_FILE2, &st))
180 {
181 fprintf (stderr, "FIFO_FILE1 exists, but FIFO_FILE2 not\n");
182 exit (1);
182 } 183 }
183 184
184 if (strstr(argv[1], "1")) 185 }
185 {
186 //fprintf(stderr, "First\n");
187 first = 1;
188 fpin = fopen(FIFO_FILE1, "r");
189 if (NULL == fpin)
190 {
191 fprintf(stderr, "fopen of read FIFO_FILE1\n");
192 goto end;
193 }
194 fpout = fopen(FIFO_FILE2, "w");
195 if (NULL == fpout)
196 {
197 fprintf(stderr, "fopen of write FIFO_FILE2\n");
198 goto end;
199 }
200 186
187 if (strstr (argv[1], "1"))
188 {
189 //fprintf(stderr, "First\n");
190 first = 1;
191 fpin = fopen (FIFO_FILE1, "r");
192 if (NULL == fpin)
193 {
194 fprintf (stderr, "fopen of read FIFO_FILE1\n");
195 goto end;
201 } 196 }
202 else 197 fpout = fopen (FIFO_FILE2, "w");
198 if (NULL == fpout)
203 { 199 {
204 first = 0; 200 fprintf (stderr, "fopen of write FIFO_FILE2\n");
205 //fprintf(stderr, "Second\n"); 201 goto end;
206 fpout = fopen(FIFO_FILE1, "w");
207 if (NULL == fpout)
208 {
209 fprintf(stderr, "fopen of write FIFO_FILE1\n");
210 goto end;
211 }
212 fpin = fopen(FIFO_FILE2, "r");
213 if (NULL == fpin)
214 {
215 fprintf(stderr, "fopen of read FIFO_FILE2\n");
216 goto end;
217 }
218
219 } 202 }
220 203
221 fdpin = fileno(fpin); 204 }
222 GNUNET_assert(fpin >= 0); 205 else
223 206 {
224 if (fdpin >= FD_SETSIZE) 207 first = 0;
208 //fprintf(stderr, "Second\n");
209 fpout = fopen (FIFO_FILE1, "w");
210 if (NULL == fpout)
225 { 211 {
226 fprintf(stderr, "File fdpin number too large (%d > %u)\n", fdpin, 212 fprintf (stderr, "fopen of write FIFO_FILE1\n");
227 (unsigned int) FD_SETSIZE);
228 goto end; 213 goto end;
229 } 214 }
215 fpin = fopen (FIFO_FILE2, "r");
216 if (NULL == fpin)
217 {
218 fprintf (stderr, "fopen of read FIFO_FILE2\n");
219 goto end;
220 }
221
222 }
223
224 fdpin = fileno (fpin);
225 GNUNET_assert (fpin >= 0);
226
227 if (fdpin >= FD_SETSIZE)
228 {
229 fprintf (stderr, "File fdpin number too large (%d > %u)\n", fdpin,
230 (unsigned int) FD_SETSIZE);
231 goto end;
232 }
230 233
231 fdpout = fileno(fpout); 234 fdpout = fileno (fpout);
232 GNUNET_assert(fdpout >= 0 ); 235 GNUNET_assert (fdpout >= 0);
233 236
234 if (fdpout >= FD_SETSIZE) 237 if (fdpout >= FD_SETSIZE)
235 { 238 {
236 fprintf(stderr, "File fdpout number too large (%d > %u)\n", fdpout, 239 fprintf (stderr, "File fdpout number too large (%d > %u)\n", fdpout,
237 (unsigned int) FD_SETSIZE); 240 (unsigned int) FD_SETSIZE);
238 goto end; 241 goto end;
239 242
240 } 243 }
241 244
242 signal(SIGINT, &sigfunc); 245 signal (SIGINT, &sigfunc);
243 signal(SIGTERM, &sigfunc); 246 signal (SIGTERM, &sigfunc);
244 247
245 char readbuf[MAXLINE]; 248 char readbuf[MAXLINE];
246 int readsize = 0; 249 int readsize = 0;
247 struct sendbuf write_std; 250 struct sendbuf write_std;
251
248 write_std.size = 0; 252 write_std.size = 0;
249 write_std.pos = 0; 253 write_std.pos = 0;
250 254
251 struct sendbuf write_pout; 255 struct sendbuf write_pout;
256
252 write_pout.size = 0; 257 write_pout.size = 0;
253 write_pout.pos = 0; 258 write_pout.pos = 0;
254 259
@@ -260,11 +265,11 @@ testmode(int argc, char *argv[])
260 struct timeval tv; 265 struct timeval tv;
261 int retval; 266 int retval;
262 267
263 struct GNUNET_SERVER_MessageStreamTokenizer * stdin_mst; 268 struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst;
264 struct GNUNET_SERVER_MessageStreamTokenizer * file_in_mst; 269 struct GNUNET_SERVER_MessageStreamTokenizer *file_in_mst;
265 270
266 stdin_mst = GNUNET_SERVER_mst_create(&stdin_send, &write_pout); 271 stdin_mst = GNUNET_SERVER_mst_create (&stdin_send, &write_pout);
267 file_in_mst = GNUNET_SERVER_mst_create(&file_in_send, &write_std); 272 file_in_mst = GNUNET_SERVER_mst_create (&file_in_send, &write_std);
268 273
269 //send mac first 274 //send mac first
270 275
@@ -275,187 +280,185 @@ testmode(int argc, char *argv[])
275 macaddr.mac[1] = 0x22; 280 macaddr.mac[1] = 0x22;
276 macaddr.mac[2] = 0x33; 281 macaddr.mac[2] = 0x33;
277 macaddr.mac[3] = 0x44; 282 macaddr.mac[3] = 0x44;
278 macaddr.mac[4] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_STRONG, 256); 283 macaddr.mac[4] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, 256);
279 macaddr.mac[5] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, 256); 284 macaddr.mac[5] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 256);
280 285
281 write_std.size = send_mac_to_plugin(write_std.buf, macaddr.mac); 286 write_std.size = send_mac_to_plugin (write_std.buf, macaddr.mac);
282 287
283 while (0 == closeprog) 288 while (0 == closeprog)
284 { 289 {
285
286 maxfd = 0;
287 290
288 //set timeout 291 maxfd = 0;
289 tv.tv_sec = 5;
290 tv.tv_usec = 0;
291 292
292 FD_ZERO(&rfds); 293 //set timeout
293 // if output queue is empty 294 tv.tv_sec = 5;
294 if (0 == write_pout.size) 295 tv.tv_usec = 0;
295 {
296 FD_SET(STDIN_FILENO, &rfds);
297 296
298 } 297 FD_ZERO (&rfds);
299 if (0 == write_std.size) 298 // if output queue is empty
300 { 299 if (0 == write_pout.size)
301 FD_SET(fdpin, &rfds); 300 {
302 maxfd = fdpin; 301 FD_SET (STDIN_FILENO, &rfds);
303 }
304 FD_ZERO(&wfds);
305 // if there is something to write
306 if (0 < write_std.size)
307 {
308 FD_SET(STDOUT_FILENO, &wfds);
309 maxfd = MAX(maxfd, STDOUT_FILENO);
310 }
311 302
312 if (0 < write_pout.size) 303 }
313 { 304 if (0 == write_std.size)
314 FD_SET(fdpout, &wfds); 305 {
315 maxfd = MAX(maxfd, fdpout); 306 FD_SET (fdpin, &rfds);
316 } 307 maxfd = fdpin;
308 }
309 FD_ZERO (&wfds);
310 // if there is something to write
311 if (0 < write_std.size)
312 {
313 FD_SET (STDOUT_FILENO, &wfds);
314 maxfd = MAX (maxfd, STDOUT_FILENO);
315 }
317 316
318 retval = select(maxfd + 1, &rfds, &wfds, NULL, &tv); 317 if (0 < write_pout.size)
318 {
319 FD_SET (fdpout, &wfds);
320 maxfd = MAX (maxfd, fdpout);
321 }
319 322
320 if (-1 == retval && EINTR == errno) 323 retval = select (maxfd + 1, &rfds, &wfds, NULL, &tv);
321 {
322 continue;
323 }
324 if (0 > retval)
325 {
326 fprintf(stderr, "select failed: %s\n", strerror(errno));
327 closeprog = 1;
328 break;
329 }
330 324
331 if (FD_ISSET(STDOUT_FILENO, &wfds)) 325 if (-1 == retval && EINTR == errno)
332 { 326 {
333 ret = write(STDOUT_FILENO, 327 continue;
334 write_std.buf + write_std.pos, 328 }
335 write_std.size - write_std.pos); 329 if (0 > retval)
336 if (0 > ret) 330 {
337 { 331 fprintf (stderr, "select failed: %s\n", strerror (errno));
338 closeprog = 1; 332 closeprog = 1;
339 fprintf(stderr, "Write ERROR to STDOUT\n"); 333 break;
340 break; 334 }
341 }
342 else
343 {
344 write_std.pos += ret;
345 // check if finished
346 if (write_std.pos == write_std.size)
347 {
348 write_std.pos = 0;
349 write_std.size = 0;
350 }
351 }
352 }
353 335
354 if (FD_ISSET(fdpout, &wfds)) 336 if (FD_ISSET (STDOUT_FILENO, &wfds))
337 {
338 ret = write (STDOUT_FILENO,
339 write_std.buf + write_std.pos,
340 write_std.size - write_std.pos);
341 if (0 > ret)
342 {
343 closeprog = 1;
344 fprintf (stderr, "Write ERROR to STDOUT\n");
345 break;
346 }
347 else
348 {
349 write_std.pos += ret;
350 // check if finished
351 if (write_std.pos == write_std.size)
355 { 352 {
356 ret = write(fdpout, 353 write_std.pos = 0;
357 write_pout.buf + write_pout.pos, 354 write_std.size = 0;
358 write_pout.size - write_pout.pos);
359
360 if (0 > ret)
361 {
362 closeprog = 1;
363 fprintf(stderr, "Write ERROR to fdpout\n");
364 }
365 else
366 {
367 write_pout.pos += ret;
368 // check if finished
369 if (write_pout.pos == write_pout.size)
370 {
371 write_pout.pos = 0;
372 write_pout.size = 0;
373 }
374 }
375 } 355 }
356 }
357 }
376 358
377 if (FD_ISSET(STDIN_FILENO, &rfds)) 359 if (FD_ISSET (fdpout, &wfds))
360 {
361 ret = write (fdpout,
362 write_pout.buf + write_pout.pos,
363 write_pout.size - write_pout.pos);
364
365 if (0 > ret)
366 {
367 closeprog = 1;
368 fprintf (stderr, "Write ERROR to fdpout\n");
369 }
370 else
371 {
372 write_pout.pos += ret;
373 // check if finished
374 if (write_pout.pos == write_pout.size)
378 { 375 {
379 readsize = read(STDIN_FILENO, readbuf, sizeof(readbuf)); 376 write_pout.pos = 0;
380 377 write_pout.size = 0;
381 if (0 > readsize)
382 {
383 closeprog = 1;
384 fprintf(stderr, "Read ERROR to STDIN_FILENO\n");
385 }
386 else if (0 < readsize)
387 {
388 GNUNET_SERVER_mst_receive(stdin_mst, NULL, readbuf, readsize,
389 GNUNET_NO, GNUNET_NO);
390
391 }
392 else
393 {
394 //eof
395 closeprog = 1;
396 }
397 } 378 }
379 }
380 }
398 381
399 if (FD_ISSET(fdpin, &rfds)) 382 if (FD_ISSET (STDIN_FILENO, &rfds))
400 { 383 {
401 readsize = read(fdpin, readbuf, sizeof(readbuf)); 384 readsize = read (STDIN_FILENO, readbuf, sizeof (readbuf));
402 385
403 if (0 > readsize) 386 if (0 > readsize)
404 { 387 {
405 closeprog = 1; 388 closeprog = 1;
406 fprintf(stderr, "Read ERROR to fdpin: %s\n", strerror(errno)); 389 fprintf (stderr, "Read ERROR to STDIN_FILENO\n");
407 break; 390 }
408 } 391 else if (0 < readsize)
409 else if (0 < readsize) 392 {
410 { 393 GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, readsize,
411 GNUNET_SERVER_mst_receive(file_in_mst, NULL, readbuf, readsize, 394 GNUNET_NO, GNUNET_NO);
412 GNUNET_NO, GNUNET_NO); 395
413 396 }
414 } 397 else
415 else 398 {
416 { 399 //eof
417 //eof 400 closeprog = 1;
418 closeprog = 1; 401 }
419 } 402 }
420 }
421 403
404 if (FD_ISSET (fdpin, &rfds))
405 {
406 readsize = read (fdpin, readbuf, sizeof (readbuf));
407
408 if (0 > readsize)
409 {
410 closeprog = 1;
411 fprintf (stderr, "Read ERROR to fdpin: %s\n", strerror (errno));
412 break;
413 }
414 else if (0 < readsize)
415 {
416 GNUNET_SERVER_mst_receive (file_in_mst, NULL, readbuf, readsize,
417 GNUNET_NO, GNUNET_NO);
418
419 }
420 else
421 {
422 //eof
423 closeprog = 1;
424 }
422 } 425 }
423 426
427 }
428
424 //clean up 429 //clean up
425 430
426 GNUNET_SERVER_mst_destroy(stdin_mst); 431 GNUNET_SERVER_mst_destroy (stdin_mst);
427 GNUNET_SERVER_mst_destroy(file_in_mst); 432 GNUNET_SERVER_mst_destroy (file_in_mst);
428 433
429 end: if (fpout != NULL) 434end:if (fpout != NULL)
430 fclose(fpout); 435 fclose (fpout);
431 if (fpin != NULL) 436 if (fpin != NULL)
432 fclose(fpin); 437 fclose (fpin);
433 438
434 if (1 == first) 439 if (1 == first)
435 { 440 {
436 unlink(FIFO_FILE1); 441 unlink (FIFO_FILE1);
437 unlink(FIFO_FILE2); 442 unlink (FIFO_FILE2);
438 } 443 }
439 444
440 return (0); 445 return (0);
441} 446}
442 447
443int 448int
444main(int argc, char *argv[]) 449main (int argc, char *argv[])
445{ 450{
446 if (2 != argc) 451 if (2 != argc)
447 { 452 {
448 fprintf (stderr, 453 fprintf (stderr,
449 "This program must be started with the operating mode as argument.\n"); 454 "This program must be started with the operating mode as argument.\n");
450 fprintf (stderr, 455 fprintf (stderr,
451 "Usage: options\n" 456 "Usage: options\n"
452 "options:\n" 457 "options:\n"
453 "1 = first loopback file\n" 458 "1 = first loopback file\n" "2 = second loopback file\n" "\n");
454 "2 = second loopback file\n" 459 return 1;
455 "\n"); 460 }
456 return 1; 461 if (strstr (argv[1], "1") || strstr (argv[1], "2"))
457 } 462 return testmode (argc, argv);
458 if (strstr(argv[1], "1") || strstr(argv[1], "2"))
459 return testmode(argc, argv);
460 return 1; 463 return 1;
461} 464}
diff --git a/src/transport/test_quota_compliance.c b/src/transport/test_quota_compliance.c
index 921fa9542..e4638e4fc 100644
--- a/src/transport/test_quota_compliance.c
+++ b/src/transport/test_quota_compliance.c
@@ -141,7 +141,7 @@ static GNUNET_SCHEDULER_TaskIdentifier tct;
141static GNUNET_SCHEDULER_TaskIdentifier measurement_task; 141static GNUNET_SCHEDULER_TaskIdentifier measurement_task;
142static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task; 142static GNUNET_SCHEDULER_TaskIdentifier measurement_counter_task;
143 143
144static struct GNUNET_TRANSPORT_TransmitHandle * transmit_handle; 144static struct GNUNET_TRANSPORT_TransmitHandle *transmit_handle;
145 145
146#define OKPP do { ok++; } while (0) 146#define OKPP do { ok++; } while (0)
147 147
@@ -151,28 +151,27 @@ end ()
151{ 151{
152 GNUNET_SCHEDULER_cancel (die_task); 152 GNUNET_SCHEDULER_cancel (die_task);
153 die_task = GNUNET_SCHEDULER_NO_TASK; 153 die_task = GNUNET_SCHEDULER_NO_TASK;
154 154
155 if (measurement_task != GNUNET_SCHEDULER_NO_TASK) 155 if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
156 { 156 {
157 GNUNET_SCHEDULER_cancel (measurement_task); 157 GNUNET_SCHEDULER_cancel (measurement_task);
158 measurement_task = GNUNET_SCHEDULER_NO_TASK; 158 measurement_task = GNUNET_SCHEDULER_NO_TASK;
159 } 159 }
160 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) 160 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
161 { 161 {
162 GNUNET_SCHEDULER_cancel (measurement_counter_task); 162 GNUNET_SCHEDULER_cancel (measurement_counter_task);
163 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; 163 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
164 } 164 }
165 fprintf(stderr,"\n"); 165 fprintf (stderr, "\n");
166 GNUNET_SCHEDULER_shutdown (); 166 GNUNET_SCHEDULER_shutdown ();
167#if DEBUG_CONNECTIONS 167#if DEBUG_CONNECTIONS
168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
169 "Disconnecting from transports!\n");
170#endif 169#endif
171 GNUNET_TRANSPORT_disconnect (p1.th); 170 GNUNET_TRANSPORT_disconnect (p1.th);
172 GNUNET_TRANSPORT_disconnect (p2.th); 171 GNUNET_TRANSPORT_disconnect (p2.th);
173#if DEBUG_CONNECTIONS 172#if DEBUG_CONNECTIONS
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Transports disconnected, returning success!\n"); 174 "Transports disconnected, returning success!\n");
176#endif 175#endif
177 GNUNET_SCHEDULER_shutdown (); 176 GNUNET_SCHEDULER_shutdown ();
178} 177}
@@ -194,8 +193,7 @@ stop_arm (struct PeerContext *p)
194 193
195 194
196static void 195static void
197end_badly (void *cls, 196end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
198 const struct GNUNET_SCHEDULER_TaskContext *tc)
199{ 197{
200 if (measurement_task != GNUNET_SCHEDULER_NO_TASK) 198 if (measurement_task != GNUNET_SCHEDULER_NO_TASK)
201 { 199 {
@@ -203,16 +201,16 @@ end_badly (void *cls,
203 measurement_task = GNUNET_SCHEDULER_NO_TASK; 201 measurement_task = GNUNET_SCHEDULER_NO_TASK;
204 } 202 }
205 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) 203 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
206 { 204 {
207 GNUNET_SCHEDULER_cancel (measurement_counter_task); 205 GNUNET_SCHEDULER_cancel (measurement_counter_task);
208 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; 206 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
209 } 207 }
210 GNUNET_break (0); 208 GNUNET_break (0);
211 if (GNUNET_SCHEDULER_NO_TASK != tct) 209 if (GNUNET_SCHEDULER_NO_TASK != tct)
212 { 210 {
213 GNUNET_SCHEDULER_cancel (tct); 211 GNUNET_SCHEDULER_cancel (tct);
214 tct = GNUNET_SCHEDULER_NO_TASK; 212 tct = GNUNET_SCHEDULER_NO_TASK;
215 } 213 }
216 if (p1.th != NULL) 214 if (p1.th != NULL)
217 GNUNET_TRANSPORT_disconnect (p1.th); 215 GNUNET_TRANSPORT_disconnect (p1.th);
218 if (p2.th != NULL) 216 if (p2.th != NULL)
@@ -235,32 +233,32 @@ get_size ()
235 233
236static void 234static void
237notify_receive_new (void *cls, 235notify_receive_new (void *cls,
238 const struct GNUNET_PeerIdentity *peer, 236 const struct GNUNET_PeerIdentity *peer,
239 const struct GNUNET_MessageHeader *message, 237 const struct GNUNET_MessageHeader *message,
240 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) 238 const struct GNUNET_TRANSPORT_ATS_Information *ats,
239 uint32_t ats_count)
241{ 240{
242 const struct TestMessage *hdr; 241 const struct TestMessage *hdr;
243 242
244 GNUNET_assert (message != NULL); 243 GNUNET_assert (message != NULL);
245 hdr = (const struct TestMessage*) message; 244 hdr = (const struct TestMessage *) message;
246 if (measurement_running == GNUNET_NO) 245 if (measurement_running == GNUNET_NO)
247 return; 246 return;
248 if (MTYPE != ntohs (message->type)) 247 if (MTYPE != ntohs (message->type))
249 return; 248 return;
250 249
251#if DEBUG_MEASUREMENT 250#if DEBUG_MEASUREMENT
252 if (ntohl(hdr->num) % 5000 == 0) 251 if (ntohl (hdr->num) % 5000 == 0)
253 { 252 {
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "Got message %u of size %u\n", 254 "Got message %u of size %u\n",
256 ntohl (hdr->num), 255 ntohl (hdr->num), ntohs (message->size));
257 ntohs (message->size)); 256 }
258 }
259#endif 257#endif
260 /* 258 /*
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 259 * GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Got message %u\n", 260 * "Got message %u\n",
263 ntohl (hdr->num));*/ 261 * ntohl (hdr->num)); */
264 last_msg_recv = ntohl (hdr->num); 262 last_msg_recv = ntohl (hdr->num);
265} 263}
266 264
@@ -278,15 +276,15 @@ notify_ready (void *cls, size_t size, void *buf)
278 return 0; 276 return 0;
279 277
280 if (buf == NULL) 278 if (buf == NULL)
281 { 279 {
282 ok = 42; 280 ok = 42;
283 return 0; 281 return 0;
284 } 282 }
285 if (measurement_running != GNUNET_YES) 283 if (measurement_running != GNUNET_YES)
286 { 284 {
287 send_running = GNUNET_NO; 285 send_running = GNUNET_NO;
288 return 0; 286 return 0;
289 } 287 }
290 send_running = GNUNET_YES; 288 send_running = GNUNET_YES;
291 ret = 0; 289 ret = 0;
292 s = get_size (); 290 s = get_size ();
@@ -295,271 +293,268 @@ notify_ready (void *cls, size_t size, void *buf)
295 last_msg_sent++; 293 last_msg_sent++;
296 cbuf = buf; 294 cbuf = buf;
297 do 295 do
298 { 296 {
299 hdr.header.size = htons (s); 297 hdr.header.size = htons (s);
300 hdr.header.type = htons (MTYPE); 298 hdr.header.type = htons (MTYPE);
301 hdr.num = htonl (last_msg_sent); 299 hdr.num = htonl (last_msg_sent);
302 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); 300 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
303 ret += sizeof (struct TestMessage); 301 ret += sizeof (struct TestMessage);
304 memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage)); 302 memset (&cbuf[ret], last_msg_sent, s - sizeof (struct TestMessage));
305 ret += s - sizeof (struct TestMessage); 303 ret += s - sizeof (struct TestMessage);
306#if DEBUG_MEASUREMENT 304#if DEBUG_MEASUREMENT
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 305 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message %u\n", last_msg_sent);
308 "Sending message %u\n",
309 last_msg_sent);
310#endif 306#endif
311 s = get_size (); 307 s = get_size ();
312 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16)) 308 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
313 break; /* sometimes pack buffer full, sometimes not */ 309 break; /* sometimes pack buffer full, sometimes not */
314 } 310 }
315 while (size - ret >= s); 311 while (size - ret >= s);
316 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 312 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
317 &p1.id, 313 &p1.id,
318 s, 0, SEND_TIMEOUT, 314 s, 0, SEND_TIMEOUT,
319 &notify_ready, 315 &notify_ready,
320 NULL); 316 NULL);
321 total_bytes_sent += s; 317 total_bytes_sent += s;
322 return ret; 318 return ret;
323} 319}
324 320
325 321
326static void 322static void measure (unsigned long long quota_p1, unsigned long long quota_p2);
327measure (unsigned long long quota_p1, unsigned long long quota_p2);
328 323
329static void 324static void
330measurement_counter (void *cls, 325measurement_counter (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
331 const struct GNUNET_SCHEDULER_TaskContext *tc)
332{ 326{
333 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; 327 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
334 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 328 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
335 return; 329 return;
336 330
337 fprintf(stderr,"."); 331 fprintf (stderr, ".");
338 measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 332 measurement_counter_task =
339 &measurement_counter, 333 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
340 NULL); 334 &measurement_counter, NULL);
341} 335}
342 336
343 337
344static void 338static void
345measurement_end (void *cls, 339measurement_end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
346 const struct GNUNET_SCHEDULER_TaskContext *tc)
347{ 340{
348 static int strike_counter; 341 static int strike_counter;
349 static int failed_measurement_counter = 1; 342 static int failed_measurement_counter = 1;
350 unsigned long long quota_allowed = 0; 343 unsigned long long quota_allowed = 0;
351 int delta = 0; 344 int delta = 0;
352 345
353 measurement_task = GNUNET_SCHEDULER_NO_TASK; 346 measurement_task = GNUNET_SCHEDULER_NO_TASK;
354 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 347 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
355 return; 348 return;
356 349
357 measurement_running = GNUNET_NO; 350 measurement_running = GNUNET_NO;
358 struct GNUNET_TIME_Relative duration 351 struct GNUNET_TIME_Relative duration
359 = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get()); 352 = GNUNET_TIME_absolute_get_difference (start_time,
353 GNUNET_TIME_absolute_get ());
360 354
361 355
362 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) 356 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
363 { 357 {
364 GNUNET_SCHEDULER_cancel (measurement_counter_task); 358 GNUNET_SCHEDULER_cancel (measurement_counter_task);
365 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK; 359 measurement_counter_task = GNUNET_SCHEDULER_NO_TASK;
366 } 360 }
367 361
368 if (transmit_handle != NULL) 362 if (transmit_handle != NULL)
369 { 363 {
370 GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); 364 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
371 transmit_handle = NULL; 365 transmit_handle = NULL;
372 } 366 }
373 367
374 if (current_quota_p1 < current_quota_p2) 368 if (current_quota_p1 < current_quota_p2)
375 quota_allowed = current_quota_p1; 369 quota_allowed = current_quota_p1;
376 else 370 else
377 quota_allowed = current_quota_p2; 371 quota_allowed = current_quota_p2;
378 372
379 373
380 if (MEASUREMENT_SOFT_LIMIT > (quota_allowed/3)) 374 if (MEASUREMENT_SOFT_LIMIT > (quota_allowed / 3))
381 delta = MEASUREMENT_SOFT_LIMIT; 375 delta = MEASUREMENT_SOFT_LIMIT;
382 else 376 else
383 delta = (quota_allowed/3); 377 delta = (quota_allowed / 3);
384 378
385 /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */ 379 /* Throughput is far too slow. This is to prevent the test to exit with success when throughput is 0 */
386 if ((total_bytes_sent/(duration.rel_value / 1000)) < 100) 380 if ((total_bytes_sent / (duration.rel_value / 1000)) < 100)
381 {
382 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
383 "\nQuota compliance failed: \n"
384 "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"
385 "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"
386 "Throughput : %10llu kB/s (%llu B/s)\n",
387 (quota_allowed / (1024)), quota_allowed,
388 ((quota_allowed + delta) / (1024)), quota_allowed + delta,
389 (total_bytes_sent / (duration.rel_value / 1000) / 1024),
390 total_bytes_sent / (duration.rel_value / 1000));
391 ok = 1;
392 failed_measurement_counter--;
393 if (failed_measurement_counter < 0)
387 { 394 {
388 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 395 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
389 "\nQuota compliance failed: \n" \ 396 "\nQuota measurement failed and no free strike: %i\n",
390 "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n" \ 397 failed_measurement_counter);
391 "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n" \ 398 end ();
392 "Throughput : %10llu kB/s (%llu B/s)\n", 399 return;
393 (quota_allowed / (1024)), quota_allowed,
394 ((quota_allowed+delta) / (1024)), quota_allowed+delta,
395 (total_bytes_sent/(duration.rel_value / 1000)/1024),
396 total_bytes_sent/(duration.rel_value / 1000));
397 ok = 1;
398 failed_measurement_counter--;
399 if (failed_measurement_counter < 0)
400 {
401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
402 "\nQuota measurement failed and no free strike: %i\n",
403 failed_measurement_counter);
404 end();
405 return;
406 }
407 else
408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
409 "\nQuota measurement failed and %i free strikes\n",
410 failed_measurement_counter);
411 } 400 }
412 401 else
413 /* Throughput is bigger than allowed quota + some extra*/ 402 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
414 if ((total_bytes_sent/(duration.rel_value / 1000)) > (quota_allowed + delta)) 403 "\nQuota measurement failed and %i free strikes\n",
404 failed_measurement_counter);
405 }
406
407 /* Throughput is bigger than allowed quota + some extra */
408 if ((total_bytes_sent / (duration.rel_value / 1000)) >
409 (quota_allowed + delta))
410 {
411 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
412 "\nQuota compliance failed: \n"
413 "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n"
414 "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n"
415 "Throughput : %10llu kB/s (%llu B/s)\n",
416 (quota_allowed / (1024)), quota_allowed,
417 ((quota_allowed + delta) / (1024)), quota_allowed + delta,
418 (total_bytes_sent / (duration.rel_value / 1000) / 1024),
419 total_bytes_sent / (duration.rel_value / 1000));
420 ok = 1;
421 failed_measurement_counter--;
422 if (failed_measurement_counter < 0)
415 { 423 {
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 424 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
417 "\nQuota compliance failed: \n" \ 425 "\nQuota measurement failed and no free strike: %i\n",
418 "Hard quota limit allowed: %10llu kB/s (%llu B/s)\n" \ 426 failed_measurement_counter);
419 "Soft quota limit allowed: %10llu kB/s (%llu B/s)\n" \ 427 end ();
420 "Throughput : %10llu kB/s (%llu B/s)\n", 428 return;
421 (quota_allowed / (1024)), quota_allowed,
422 ((quota_allowed+delta) / (1024)), quota_allowed+delta,
423 (total_bytes_sent/(duration.rel_value / 1000)/1024),
424 total_bytes_sent/(duration.rel_value / 1000));
425 ok = 1;
426 failed_measurement_counter--;
427 if (failed_measurement_counter < 0)
428 {
429 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
430 "\nQuota measurement failed and no free strike: %i\n",failed_measurement_counter);
431 end();
432 return;
433 }
434 else
435 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
436 "\nQuota measurement failed and %i free strikes\n",failed_measurement_counter);
437 } 429 }
430 else
431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
432 "\nQuota measurement failed and %i free strikes\n",
433 failed_measurement_counter);
434 }
438 else 435 else
436 {
437 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
438 "\nQuota compliance ok: \n"
439 "Quota allowed: %10llu kB/s\n"
440 "Throughput : %10llu kB/s\n",
441 (quota_allowed / (1024)),
442 (total_bytes_sent / (duration.rel_value / 1000) / 1024));
443 if (failed_measurement_counter < 2)
444 failed_measurement_counter++;
445 ok = 0;
446 }
447
448 if ((quota_allowed) > (2 * (total_bytes_sent / (duration.rel_value / 1000))))
449 {
450 if (failed_measurement_counter < 2)
451 failed_measurement_counter++;
452 if (strike_counter == 2)
439 { 453 {
440 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 454 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
441 "\nQuota compliance ok: \n" \ 455 "Maximum transmission rate reached, stopping test\n");
442 "Quota allowed: %10llu kB/s\n" \ 456 end ();
443 "Throughput : %10llu kB/s\n", 457 return;
444 (quota_allowed / (1024)),
445 (total_bytes_sent/(duration.rel_value / 1000)/1024));
446 if (failed_measurement_counter < 2)
447 failed_measurement_counter++;
448 ok = 0;
449 }
450
451 if ((quota_allowed) > (2 *(total_bytes_sent/(duration.rel_value / 1000))))
452 {
453 if (failed_measurement_counter < 2)
454 failed_measurement_counter++;
455 if (strike_counter == 2)
456 {
457 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
458 "Maximum transmission rate reached, stopping test\n");
459 end();
460 return;
461 }
462 } 458 }
459 }
463 else 460 else
464 { 461 {
465 strike_counter = 0; 462 strike_counter = 0;
466 } 463 }
467 464
468 if (quota_allowed == MEASUREMENT_MAX_QUOTA) 465 if (quota_allowed == MEASUREMENT_MAX_QUOTA)
469 { 466 {
470 end(); 467 end ();
471 return; 468 return;
472 } 469 }
473 if (is_asymmetric_send_constant == GNUNET_YES) 470 if (is_asymmetric_send_constant == GNUNET_YES)
474 { 471 {
475 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA) 472 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
476 measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA); 473 measure (current_quota_p1 * 2, MEASUREMENT_MAX_QUOTA);
477 else 474 else
478 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA); 475 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
479 } 476 }
480 else if (is_asymmetric_recv_constant == GNUNET_YES) 477 else if (is_asymmetric_recv_constant == GNUNET_YES)
481 { 478 {
482 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA) 479 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
483 measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2); 480 measure (MEASUREMENT_MAX_QUOTA, current_quota_p2 * 2);
484 else 481 else
485 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA); 482 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
486 } 483 }
487 else 484 else
488 { 485 {
489 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA) 486 if ((quota_allowed * 2) < MEASUREMENT_MAX_QUOTA)
490 measure ((current_quota_p1) * 2, (current_quota_p2) * 2); 487 measure ((current_quota_p1) * 2, (current_quota_p2) * 2);
491 else 488 else
492 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA); 489 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MAX_QUOTA);
493 } 490 }
494} 491}
495 492
496static void 493static void
497measure (unsigned long long quota_p1, unsigned long long quota_p2) 494measure (unsigned long long quota_p1, unsigned long long quota_p2)
498{ 495{
499 current_quota_p1 = quota_p1; 496 current_quota_p1 = quota_p1;
500 current_quota_p2 = quota_p2; 497 current_quota_p2 = quota_p2;
501#if VERBOSE 498#if VERBOSE
502 if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES)) 499 if ((is_asymmetric_send_constant == GNUNET_YES) ||
500 (is_asymmetric_recv_constant == GNUNET_YES))
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
504 "Starting transport level measurement for %u seconds, receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n", 502 "Starting transport level measurement for %u seconds, receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n",
505 MEASUREMENT_INTERVALL.rel_value / 1000 , 503 MEASUREMENT_INTERVALL.rel_value / 1000, current_quota_p1 / 1024,
506 current_quota_p1 / 1024, 504 current_quota_p2 / 1024);
507 current_quota_p2 / 1024);
508 else 505 else
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n", 507 "Starting transport level measurement for %u seconds, symmetric quota %llu kB/s\n",
511 MEASUREMENT_INTERVALL.rel_value / 1000, 508 MEASUREMENT_INTERVALL.rel_value / 1000,
512 current_quota_p2 / 1024); 509 current_quota_p2 / 1024);
513 510
514#endif 511#endif
515 GNUNET_TRANSPORT_set_quota (p1.th, 512 GNUNET_TRANSPORT_set_quota (p1.th,
516 &p2.id, 513 &p2.id,
517 GNUNET_BANDWIDTH_value_init (current_quota_p1), 514 GNUNET_BANDWIDTH_value_init (current_quota_p1),
518 GNUNET_BANDWIDTH_value_init (current_quota_p1)); 515 GNUNET_BANDWIDTH_value_init (current_quota_p1));
519 GNUNET_TRANSPORT_set_quota (p2.th, 516 GNUNET_TRANSPORT_set_quota (p2.th,
520 &p1.id, 517 &p1.id,
521 GNUNET_BANDWIDTH_value_init (current_quota_p2), 518 GNUNET_BANDWIDTH_value_init (current_quota_p2),
522 GNUNET_BANDWIDTH_value_init (current_quota_p2)); 519 GNUNET_BANDWIDTH_value_init (current_quota_p2));
523 GNUNET_SCHEDULER_cancel (die_task); 520 GNUNET_SCHEDULER_cancel (die_task);
524 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 521 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
525 &end_badly,
526 NULL);
527 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK) 522 if (measurement_counter_task != GNUNET_SCHEDULER_NO_TASK)
528 GNUNET_SCHEDULER_cancel (measurement_counter_task); 523 GNUNET_SCHEDULER_cancel (measurement_counter_task);
529 measurement_counter_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 524 measurement_counter_task =
530 &measurement_counter, 525 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
531 NULL); 526 &measurement_counter, NULL);
532 measurement_task = GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL, 527 measurement_task =
533 &measurement_end, 528 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL, &measurement_end,
534 NULL); 529 NULL);
535 total_bytes_sent = 0; 530 total_bytes_sent = 0;
536 last_msg_sent = 0; 531 last_msg_sent = 0;
537 last_msg_recv = 0; 532 last_msg_recv = 0;
538 measurement_running = GNUNET_YES; 533 measurement_running = GNUNET_YES;
539 start_time = GNUNET_TIME_absolute_get (); 534 start_time = GNUNET_TIME_absolute_get ();
540 535
541 if (transmit_handle != NULL) 536 if (transmit_handle != NULL)
542 GNUNET_TRANSPORT_notify_transmit_ready_cancel(transmit_handle); 537 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
543 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 538 transmit_handle = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
544 &p1.id, 539 &p1.id,
545 get_size (), 0, SEND_TIMEOUT, 540 get_size (), 0,
546 &notify_ready, 541 SEND_TIMEOUT,
547 NULL); 542 &notify_ready,
543 NULL);
548} 544}
549 545
550 546
551static void 547static void
552exchange_hello_last (void *cls, 548exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
553 const struct GNUNET_MessageHeader *message)
554{ 549{
555 struct PeerContext *me = cls; 550 struct PeerContext *me = cls;
556 551
557 GNUNET_assert (message != NULL); 552 GNUNET_assert (message != NULL);
558#if DEBUG_CONNECTIONS 553#if DEBUG_CONNECTIONS
559 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
560 "Exchanging HELLO of size %d with peer (%s)!\n", 555 "Exchanging HELLO of size %d with peer (%s)!\n",
561 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 556 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
562 GNUNET_i2s (&me->id)); 557 message), GNUNET_i2s (&me->id));
563#endif 558#endif
564 GNUNET_assert (GNUNET_OK == 559 GNUNET_assert (GNUNET_OK ==
565 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 560 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
@@ -570,8 +565,7 @@ exchange_hello_last (void *cls,
570 565
571 566
572static void 567static void
573exchange_hello (void *cls, 568exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
574 const struct GNUNET_MessageHeader *message)
575{ 569{
576 struct PeerContext *me = cls; 570 struct PeerContext *me = cls;
577 571
@@ -581,9 +575,9 @@ exchange_hello (void *cls,
581 message, &me->id)); 575 message, &me->id));
582#if DEBUG_CONNECTIONS 576#if DEBUG_CONNECTIONS
583 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
584 "Exchanging HELLO of size %d from peer %s!\n", 578 "Exchanging HELLO of size %d from peer %s!\n",
585 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 579 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
586 GNUNET_i2s (&me->id)); 580 message), GNUNET_i2s (&me->id));
587#endif 581#endif
588 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); 582 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
589} 583}
@@ -592,43 +586,40 @@ exchange_hello (void *cls,
592static void 586static void
593notify_connect (void *cls, 587notify_connect (void *cls,
594 const struct GNUNET_PeerIdentity *peer, 588 const struct GNUNET_PeerIdentity *peer,
595 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count) 589 const struct GNUNET_TRANSPORT_ATS_Information *ats,
596{ 590 uint32_t ats_count)
591{
597 connected++; 592 connected++;
598 if (cls == &p1) 593 if (cls == &p1)
599 { 594 {
600#if DEBUG_CONNECTIONS 595#if DEBUG_CONNECTIONS
601 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 596 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
602 "Peer 1 `%4s' connected to us (%p)!\n", 597 "Peer 1 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
603 GNUNET_i2s (peer),
604 cls);
605#endif 598#endif
606 } 599 }
607 else 600 else
608 { 601 {
609#if DEBUG_CONNECTIONS 602#if DEBUG_CONNECTIONS
610 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
611 "Peer 2 `%4s' connected to us (%p)!\n", 604 "Peer 2 `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
612 GNUNET_i2s (peer),
613 cls);
614#endif 605#endif
615 } 606 }
616 if (connected == 2) 607 if (connected == 2)
608 {
609 if (GNUNET_SCHEDULER_NO_TASK != tct)
617 { 610 {
618 if (GNUNET_SCHEDULER_NO_TASK != tct) 611 GNUNET_SCHEDULER_cancel (tct);
619 { 612 tct = GNUNET_SCHEDULER_NO_TASK;
620 GNUNET_SCHEDULER_cancel (tct);
621 tct = GNUNET_SCHEDULER_NO_TASK;
622 }
623 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
624 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
625 if (is_asymmetric_send_constant == GNUNET_YES)
626 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
627 else if (is_asymmetric_recv_constant == GNUNET_YES)
628 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
629 else
630 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
631 } 613 }
614 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
615 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
616 if (is_asymmetric_send_constant == GNUNET_YES)
617 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MAX_QUOTA);
618 else if (is_asymmetric_recv_constant == GNUNET_YES)
619 measure (MEASUREMENT_MAX_QUOTA, MEASUREMENT_MIN_QUOTA);
620 else
621 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA);
622 }
632} 623}
633 624
634 625
@@ -636,18 +627,17 @@ static void
636notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 627notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
637{ 628{
638 if (cls == &p2) 629 if (cls == &p2)
630 {
631 if (NULL != transmit_handle)
639 { 632 {
640 if (NULL != transmit_handle) 633 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
641 { 634 transmit_handle = NULL;
642 GNUNET_TRANSPORT_notify_transmit_ready_cancel (transmit_handle);
643 transmit_handle = NULL;
644 }
645 } 635 }
636 }
646 connected--; 637 connected--;
647#if DEBUG_CONNECTIONS 638#if DEBUG_CONNECTIONS
648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 639 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
649 "Peer `%4s' disconnected (%p)!\n", 640 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
650 GNUNET_i2s (peer), cls);
651#endif 641#endif
652} 642}
653 643
@@ -657,46 +647,41 @@ setup_peer (struct PeerContext *p, const char *cfgname)
657{ 647{
658 p->cfg = GNUNET_CONFIGURATION_create (); 648 p->cfg = GNUNET_CONFIGURATION_create ();
659 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 649 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
660 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 650 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
661 { 651 {
662 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome); 652 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
663 GNUNET_DISK_directory_remove (p->servicehome); 653 &p->servicehome);
664 } 654 GNUNET_DISK_directory_remove (p->servicehome);
655 }
665 656
666#if START_ARM 657#if START_ARM
667 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, 658 p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
668 "gnunet-service-arm", 659 "gnunet-service-arm",
669 "gnunet-service-arm", 660 "gnunet-service-arm",
670#if VERBOSE_ARM 661#if VERBOSE_ARM
671 "-L", "DEBUG", 662 "-L", "DEBUG",
672#endif 663#endif
673 "-c", cfgname, NULL); 664 "-c", cfgname, NULL);
674#endif 665#endif
675 666
676 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, 667 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
677 p, 668 p,
678 &notify_receive_new, 669 &notify_receive_new,
679 &notify_connect, 670 &notify_connect, &notify_disconnect);
680 &notify_disconnect);
681 GNUNET_assert (p->th != NULL); 671 GNUNET_assert (p->th != NULL);
682} 672}
683 673
684 674
685static void 675static void
686try_connect (void *cls, 676try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
687 const struct GNUNET_SCHEDULER_TaskContext *tc)
688{ 677{
689#if DEBUG_CONNECTIONS 678#if DEBUG_CONNECTIONS
690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
691 "Asking peers to connect...\n");
692#endif 680#endif
693 GNUNET_TRANSPORT_try_connect (p2.th, 681 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
694 &p1.id); 682 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
695 GNUNET_TRANSPORT_try_connect (p1.th,
696 &p2.id);
697 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 683 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
698 &try_connect, 684 &try_connect, NULL);
699 NULL);
700} 685}
701 686
702 687
@@ -708,102 +693,100 @@ run (void *cls,
708 GNUNET_assert (ok == 1); 693 GNUNET_assert (ok == 1);
709 OKPP; 694 OKPP;
710 695
711 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 696 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
712 &end_badly,
713 NULL);
714 measurement_running = GNUNET_NO; 697 measurement_running = GNUNET_NO;
715 send_running = GNUNET_NO; 698 send_running = GNUNET_NO;
716 recv_running = GNUNET_NO; 699 recv_running = GNUNET_NO;
717 700
718 if (is_tcp) 701 if (is_tcp)
719 { 702 {
720 if (is_asymmetric_recv_constant == GNUNET_YES) 703 if (is_asymmetric_recv_constant == GNUNET_YES)
721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
722 "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n"); 705 "Testing asymmetric quota compliance (receiver quota constant) for TCP transport plugin\n");
723 else if (is_asymmetric_send_constant == GNUNET_YES) 706 else if (is_asymmetric_send_constant == GNUNET_YES)
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
725 "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n"); 708 "Testing asymmetric quota compliance (sender quota constant) for TCP transport plugin\n");
726 else 709 else
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
728 "Testing symmetric quota compliance for TCP transport plugin\n"); 711 "Testing symmetric quota compliance for TCP transport plugin\n");
729 setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf"); 712 setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
730 setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf"); 713 setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
731 } 714 }
732 else if (is_http) 715 else if (is_http)
733 { 716 {
734 if (is_asymmetric_recv_constant == GNUNET_YES) 717 if (is_asymmetric_recv_constant == GNUNET_YES)
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n"); 719 "Testing asymmetric quota compliance (receiver quota constant) for HTTP transport plugin\n");
737 else if (is_asymmetric_send_constant == GNUNET_YES) 720 else if (is_asymmetric_send_constant == GNUNET_YES)
738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
739 "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n"); 722 "Testing asymmetric quota compliance (sender quota constant) for HTTP transport plugin\n");
740 else 723 else
741 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
742 "Testing symmetric quota compliance for HTTP transport plugin\n"); 725 "Testing symmetric quota compliance for HTTP transport plugin\n");
743 setup_peer (&p1, "test_quota_compliance_http_peer1.conf"); 726 setup_peer (&p1, "test_quota_compliance_http_peer1.conf");
744 setup_peer (&p2, "test_quota_compliance_http_peer2.conf"); 727 setup_peer (&p2, "test_quota_compliance_http_peer2.conf");
745 } 728 }
746 else if (is_https) 729 else if (is_https)
747 { 730 {
748 if (is_asymmetric_recv_constant == GNUNET_YES) 731 if (is_asymmetric_recv_constant == GNUNET_YES)
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
750 "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n"); 733 "Testing asymmetric quota compliance (receiver quota constant) for HTTPS transport plugin\n");
751 else if (is_asymmetric_send_constant == GNUNET_YES) 734 else if (is_asymmetric_send_constant == GNUNET_YES)
752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
753 "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n"); 736 "Testing asymmetric quota compliance (sender quota constant) for HTTPS transport plugin\n");
754 else 737 else
755 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
756 "Testing symmetric quota compliance for HTTPS transport plugin\n"); 739 "Testing symmetric quota compliance for HTTPS transport plugin\n");
757 setup_peer (&p1, "test_quota_compliance_https_peer1.conf"); 740 setup_peer (&p1, "test_quota_compliance_https_peer1.conf");
758 setup_peer (&p2, "test_quota_compliance_https_peer2.conf"); 741 setup_peer (&p2, "test_quota_compliance_https_peer2.conf");
759 } 742 }
760 else if (is_udp) 743 else if (is_udp)
761 { 744 {
762 if (is_asymmetric_recv_constant == GNUNET_YES) 745 if (is_asymmetric_recv_constant == GNUNET_YES)
763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
764 "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n"); 747 "Testing asymmetric quota compliance (receiver quota constant) for UDP transport plugin\n");
765 else if (is_asymmetric_send_constant == GNUNET_YES) 748 else if (is_asymmetric_send_constant == GNUNET_YES)
766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
767 "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n"); 750 "Testing asymmetric quota compliance (sender quota constant) for UDP transport plugin\n");
768 else 751 else
769 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 752 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
770 "Testing symmetric quota compliance for UDP transport plugin\n"); 753 "Testing symmetric quota compliance for UDP transport plugin\n");
771 setup_peer (&p1, "test_quota_compliance_udp_peer1.conf"); 754 setup_peer (&p1, "test_quota_compliance_udp_peer1.conf");
772 setup_peer (&p2, "test_quota_compliance_udp_peer2.conf"); 755 setup_peer (&p2, "test_quota_compliance_udp_peer2.conf");
773 } 756 }
774 else if (is_unix) 757 else if (is_unix)
775 { 758 {
776 if (is_asymmetric_recv_constant == GNUNET_YES) 759 if (is_asymmetric_recv_constant == GNUNET_YES)
777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 760 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
778 "Testing asymmetric quota compliance (receiver quota constant) for UNIX transport plugin\n"); 761 "Testing asymmetric quota compliance (receiver quota constant) for UNIX transport plugin\n");
779 else if (is_asymmetric_send_constant == GNUNET_YES) 762 else if (is_asymmetric_send_constant == GNUNET_YES)
780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 763 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 "Testing asymmetric quota compliance (sender quota constant) for UNIX transport plugin\n"); 764 "Testing asymmetric quota compliance (sender quota constant) for UNIX transport plugin\n");
782 else 765 else
783 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
784 "Testing symmetric quota compliance for UNIX transport plugin\n"); 767 "Testing symmetric quota compliance for UNIX transport plugin\n");
785 setup_peer (&p1, "test_quota_compliance_unix_peer1.conf"); 768 setup_peer (&p1, "test_quota_compliance_unix_peer1.conf");
786 setup_peer (&p2, "test_quota_compliance_unix_peer2.conf"); 769 setup_peer (&p2, "test_quota_compliance_unix_peer2.conf");
787 } 770 }
788 else if (is_tcp_nat) 771 else if (is_tcp_nat)
789 { 772 {
790 if (is_asymmetric_recv_constant == GNUNET_YES) 773 if (is_asymmetric_recv_constant == GNUNET_YES)
791 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 774 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
792 "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n"); 775 "Testing asymmetric quota compliance (receiver quota constant) for TCP NAT transport plugin\n");
793 else if (is_asymmetric_send_constant == GNUNET_YES) 776 else if (is_asymmetric_send_constant == GNUNET_YES)
794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
795 "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n"); 778 "Testing asymmetric quota compliance (sender quota constant) for TCP NAT transport plugin\n");
796 else 779 else
797 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
798 "Testing symmetric quota compliance for TCP NAT transport plugin\n"); 781 "Testing symmetric quota compliance for TCP NAT transport plugin\n");
799 setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf"); 782 setup_peer (&p1, "test_quota_compliance_tcp_peer1.conf");
800 setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf"); 783 setup_peer (&p2, "test_quota_compliance_tcp_peer2.conf");
801 } 784 }
802 else 785 else
803 GNUNET_assert (0); 786 GNUNET_assert (0);
804 787
805 GNUNET_assert(p1.th != NULL); 788 GNUNET_assert (p1.th != NULL);
806 GNUNET_assert(p2.th != NULL); 789 GNUNET_assert (p2.th != NULL);
807 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 790 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
808 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); 791 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
809 tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL); 792 tct = GNUNET_SCHEDULER_add_now (&try_connect, NULL);
@@ -814,96 +797,114 @@ int
814main (int argc, char *argv[]) 797main (int argc, char *argv[])
815{ 798{
816 int ret = 0; 799 int ret = 0;
817 if (strstr(argv[0], "tcp_nat") != NULL)
818 {
819 is_tcp_nat = GNUNET_YES;
820 }
821 else if (strstr(argv[0], "tcp") != NULL)
822 {
823 is_tcp = GNUNET_YES;
824 }
825 else if (strstr(argv[0], "https") != NULL)
826 {
827 is_https = GNUNET_YES;
828 }
829 else if (strstr(argv[0], "http") != NULL)
830 {
831 is_http = GNUNET_YES;
832 }
833 else if (strstr(argv[0], "udp") != NULL)
834 {
835 is_udp = GNUNET_YES;
836 }
837 else if (strstr(argv[0], "unix") != NULL)
838 {
839 is_unix = GNUNET_YES;
840 }
841 800
842 if (strstr(argv[0], "asymmetric_recv") != NULL) 801 if (strstr (argv[0], "tcp_nat") != NULL)
802 {
803 is_tcp_nat = GNUNET_YES;
804 }
805 else if (strstr (argv[0], "tcp") != NULL)
806 {
807 is_tcp = GNUNET_YES;
808 }
809 else if (strstr (argv[0], "https") != NULL)
810 {
811 is_https = GNUNET_YES;
812 }
813 else if (strstr (argv[0], "http") != NULL)
814 {
815 is_http = GNUNET_YES;
816 }
817 else if (strstr (argv[0], "udp") != NULL)
818 {
819 is_udp = GNUNET_YES;
820 }
821 else if (strstr (argv[0], "unix") != NULL)
822 {
823 is_unix = GNUNET_YES;
824 }
825
826 if (strstr (argv[0], "asymmetric_recv") != NULL)
843 { 827 {
844 is_asymmetric_recv_constant = GNUNET_YES; 828 is_asymmetric_recv_constant = GNUNET_YES;
845 } 829 }
846 else 830 else
847 is_asymmetric_recv_constant = GNUNET_NO; 831 is_asymmetric_recv_constant = GNUNET_NO;
848 if (strstr(argv[0], "asymmetric_send") != NULL) 832 if (strstr (argv[0], "asymmetric_send") != NULL)
849 { 833 {
850 is_asymmetric_send_constant = GNUNET_YES; 834 is_asymmetric_send_constant = GNUNET_YES;
851 } 835 }
852 else 836 else
853 is_asymmetric_send_constant = GNUNET_NO; 837 is_asymmetric_send_constant = GNUNET_NO;
854 838
855 char * logger; 839 char *logger;
840
856 if (is_tcp == GNUNET_YES) 841 if (is_tcp == GNUNET_YES)
857 { 842 {
858 if (is_asymmetric_recv_constant == GNUNET_YES) 843 if (is_asymmetric_recv_constant == GNUNET_YES)
859 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_recv_constant"); 844 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
860 else if (is_asymmetric_send_constant == GNUNET_YES) 845 "asymmetric_recv_constant");
861 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","asymmetric_send_constant"); 846 else if (is_asymmetric_send_constant == GNUNET_YES)
862 else 847 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
863 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","tcp","symmetric"); 848 "asymmetric_send_constant");
864 } 849 else
850 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "tcp",
851 "symmetric");
852 }
865 else if (is_udp == GNUNET_YES) 853 else if (is_udp == GNUNET_YES)
866 { 854 {
867 if (is_asymmetric_recv_constant == GNUNET_YES) 855 if (is_asymmetric_recv_constant == GNUNET_YES)
868 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_recv_constant"); 856 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
869 else if (is_asymmetric_send_constant == GNUNET_YES) 857 "asymmetric_recv_constant");
870 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","asymmetric_send_constant"); 858 else if (is_asymmetric_send_constant == GNUNET_YES)
871 else 859 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
872 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","udp","symmetric"); 860 "asymmetric_send_constant");
873 } 861 else
862 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "udp",
863 "symmetric");
864 }
874 else if (is_unix == GNUNET_YES) 865 else if (is_unix == GNUNET_YES)
875 { 866 {
876 if (is_asymmetric_recv_constant == GNUNET_YES) 867 if (is_asymmetric_recv_constant == GNUNET_YES)
877 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","unix","asymmetric_recv_constant"); 868 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
878 else if (is_asymmetric_send_constant == GNUNET_YES) 869 "asymmetric_recv_constant");
879 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","unix","asymmetric_send_constant"); 870 else if (is_asymmetric_send_constant == GNUNET_YES)
880 else 871 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
881 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","unix","symmetric"); 872 "asymmetric_send_constant");
882 } 873 else
874 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "unix",
875 "symmetric");
876 }
883 else if (is_http == GNUNET_YES) 877 else if (is_http == GNUNET_YES)
884 { 878 {
885 if (is_asymmetric_recv_constant == GNUNET_YES) 879 if (is_asymmetric_recv_constant == GNUNET_YES)
886 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_recv_constant"); 880 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
887 else if (is_asymmetric_send_constant == GNUNET_YES) 881 "asymmetric_recv_constant");
888 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","asymmetric_send_constant"); 882 else if (is_asymmetric_send_constant == GNUNET_YES)
889 else 883 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
890 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","http","symmetric"); 884 "asymmetric_send_constant");
891 } 885 else
886 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "http",
887 "symmetric");
888 }
892 else if (is_https == GNUNET_YES) 889 else if (is_https == GNUNET_YES)
893 { 890 {
894 if (is_asymmetric_recv_constant == GNUNET_YES) 891 if (is_asymmetric_recv_constant == GNUNET_YES)
895 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_recv_constant"); 892 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
896 else if (is_asymmetric_send_constant == GNUNET_YES) 893 "asymmetric_recv_constant");
897 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","asymmetric_send_constant"); 894 else if (is_asymmetric_send_constant == GNUNET_YES)
898 else 895 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
899 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","https","symmetric"); 896 "asymmetric_send_constant");
900 } 897 else
898 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "https",
899 "symmetric");
900 }
901 else 901 else
902 { 902 {
903 GNUNET_asprintf(&logger, "test-quota-compliance-%s-%s","noplugin","none"); 903 GNUNET_asprintf (&logger, "test-quota-compliance-%s-%s", "noplugin",
904 } 904 "none");
905 }
905 906
906 fprintf(stderr, "Running `%s'\n", logger); 907 fprintf (stderr, "Running `%s'\n", logger);
907 GNUNET_log_setup ("test-quota-compliance", 908 GNUNET_log_setup ("test-quota-compliance",
908#if VERBOSE 909#if VERBOSE
909 "DEBUG", 910 "DEBUG",
@@ -924,23 +925,22 @@ main (int argc, char *argv[])
924 }; 925 };
925 ok = 1; 926 ok = 1;
926 GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1, 927 GNUNET_PROGRAM_run ((sizeof (argv1) / sizeof (char *)) - 1,
927 argv1, logger , "nohelp", 928 argv1, logger, "nohelp", options, &run, &ok);
928 options, &run, &ok);
929 ret = ok; 929 ret = ok;
930 stop_arm (&p1); 930 stop_arm (&p1);
931 stop_arm (&p2); 931 stop_arm (&p2);
932 932
933 if (p1.servicehome != NULL) 933 if (p1.servicehome != NULL)
934 { 934 {
935 GNUNET_DISK_directory_remove (p1.servicehome); 935 GNUNET_DISK_directory_remove (p1.servicehome);
936 GNUNET_free(p1.servicehome); 936 GNUNET_free (p1.servicehome);
937 } 937 }
938 if (p2.servicehome != NULL) 938 if (p2.servicehome != NULL)
939 { 939 {
940 GNUNET_DISK_directory_remove (p2.servicehome); 940 GNUNET_DISK_directory_remove (p2.servicehome);
941 GNUNET_free(p2.servicehome); 941 GNUNET_free (p2.servicehome);
942 } 942 }
943 GNUNET_free(logger); 943 GNUNET_free (logger);
944 return ret; 944 return ret;
945} 945}
946 946
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c
index 0e3473441..f9ac6a8e5 100644
--- a/src/transport/test_transport_api.c
+++ b/src/transport/test_transport_api.c
@@ -57,17 +57,17 @@
57 57
58static int ok; 58static int ok;
59 59
60static GNUNET_SCHEDULER_TaskIdentifier die_task; 60static GNUNET_SCHEDULER_TaskIdentifier die_task;
61 61
62struct PeerContext * p1; 62struct PeerContext *p1;
63 63
64struct PeerContext * p2; 64struct PeerContext *p2;
65 65
66struct GNUNET_TRANSPORT_TransmitHandle * th; 66struct GNUNET_TRANSPORT_TransmitHandle *th;
67 67
68char * cfg_file_p1; 68char *cfg_file_p1;
69 69
70char * cfg_file_p2; 70char *cfg_file_p2;
71 71
72#if VERBOSE 72#if VERBOSE
73#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 73#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
@@ -82,33 +82,33 @@ end ()
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
83 83
84 if (die_task != GNUNET_SCHEDULER_NO_TASK) 84 if (die_task != GNUNET_SCHEDULER_NO_TASK)
85 GNUNET_SCHEDULER_cancel(die_task); 85 GNUNET_SCHEDULER_cancel (die_task);
86 86
87 if (th != NULL) 87 if (th != NULL)
88 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 88 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
89 th = NULL; 89 th = NULL;
90 90
91 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 91 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
92 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 92 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
93} 93}
94 94
95static void 95static void
96end_badly () 96end_badly ()
97{ 97{
98 if (die_task != GNUNET_SCHEDULER_NO_TASK) 98 if (die_task != GNUNET_SCHEDULER_NO_TASK)
99 GNUNET_SCHEDULER_cancel(die_task); 99 GNUNET_SCHEDULER_cancel (die_task);
100 100
101 die_task = GNUNET_SCHEDULER_NO_TASK; 101 die_task = GNUNET_SCHEDULER_NO_TASK;
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
103 103
104 if (th != NULL) 104 if (th != NULL)
105 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 105 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
106 th = NULL; 106 th = NULL;
107 107
108 if (p1 != NULL) 108 if (p1 != NULL)
109 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 109 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
110 if (p2 != NULL) 110 if (p2 != NULL)
111 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 111 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
112 112
113 ok = GNUNET_SYSERR; 113 ok = GNUNET_SYSERR;
114} 114}
@@ -121,22 +121,21 @@ notify_receive (void *cls,
121 const struct GNUNET_TRANSPORT_ATS_Information *ats, 121 const struct GNUNET_TRANSPORT_ATS_Information *ats,
122 uint32_t ats_count) 122 uint32_t ats_count)
123{ 123{
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
125 "Received message of type %d from peer %s!\n", 125 "Received message of type %d from peer %s!\n",
126 ntohs(message->type), 126 ntohs (message->type), GNUNET_i2s (peer));
127 GNUNET_i2s (peer));
128 127
129 if ((MTYPE == ntohs (message->type)) && 128 if ((MTYPE == ntohs (message->type)) &&
130 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size))) 129 (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)))
131 { 130 {
132 ok = 0; 131 ok = 0;
133 end(); 132 end ();
134 } 133 }
135 else 134 else
136 { 135 {
137 GNUNET_break (0); 136 GNUNET_break (0);
138 ok = 1; 137 ok = 1;
139 end(); 138 end ();
140 } 139 }
141} 140}
142 141
@@ -150,9 +149,8 @@ notify_ready (void *cls, size_t size, void *buf)
150 th = NULL; 149 th = NULL;
151 150
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
153 "Transmitting message with %u bytes to peer %s\n", 152 "Transmitting message with %u bytes to peer %s\n",
154 sizeof (struct GNUNET_MessageHeader), 153 sizeof (struct GNUNET_MessageHeader), GNUNET_i2s (&p->id));
155 GNUNET_i2s (&p->id));
156 GNUNET_assert (size >= 256); 154 GNUNET_assert (size >= 256);
157 155
158 if (buf != NULL) 156 if (buf != NULL)
@@ -172,41 +170,37 @@ notify_connect (void *cls,
172 uint32_t ats_count) 170 uint32_t ats_count)
173{ 171{
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "Peer `%4s' connected to us (%p)!\n", 173 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
176 GNUNET_i2s (peer),
177 cls);
178} 174}
179 175
180 176
181static void 177static void
182notify_disconnect (void *cls, 178notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
183 const struct GNUNET_PeerIdentity *peer)
184{ 179{
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Peer `%4s' disconnected (%p)!\n", 181 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
187 GNUNET_i2s (peer), cls);
188} 182}
189 183
190static void 184static void
191sendtask () 185sendtask ()
192{ 186{
193 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th, 187 th = GNUNET_TRANSPORT_notify_transmit_ready (p1->th,
194 &p2->id, 188 &p2->id,
195 256, 0, TIMEOUT, &notify_ready, 189 256, 0, TIMEOUT, &notify_ready,
196 &p1); 190 &p1);
197} 191}
198 192
199static void 193static void
200testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) 194testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
201{ 195{
202 char * p1_c = strdup (GNUNET_i2s(&p1->id)); 196 char *p1_c = strdup (GNUNET_i2s (&p1->id));
197
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", 198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n",
204 p1_c, 199 p1_c, GNUNET_i2s (&p2->id));
205 GNUNET_i2s (&p2->id));
206 GNUNET_free (p1_c); 200 GNUNET_free (p1_c);
207 201
208 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! 202 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
209 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); 203 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
210} 204}
211 205
212static void 206static void
@@ -214,21 +208,18 @@ run (void *cls,
214 char *const *args, 208 char *const *args,
215 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 209 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
216{ 210{
217 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 211 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
218 &end_badly, NULL); 212
219 213 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
220 p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1, 214 &notify_receive,
221 &notify_receive, 215 &notify_connect,
222 &notify_connect, 216 &notify_disconnect, NULL);
223 &notify_disconnect, 217 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
224 NULL); 218 &notify_receive,
225 p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2, 219 &notify_connect,
226 &notify_receive, 220 &notify_disconnect, NULL);
227 &notify_connect, 221
228 &notify_disconnect, 222 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
229 NULL);
230
231 GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
232} 223}
233 224
234static int 225static int
@@ -247,12 +238,11 @@ check ()
247 }; 238 };
248 239
249#if WRITECONFIG 240#if WRITECONFIG
250 setTransportOptions("test_transport_api_data.conf"); 241 setTransportOptions ("test_transport_api_data.conf");
251#endif 242#endif
252 ok = 1; 243 ok = 1;
253 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 244 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
254 argv, "test-transport-api", "nohelp", 245 argv, "test-transport-api", "nohelp", options, &run, &ok);
255 options, &run, &ok);
256 246
257 return ok; 247 return ok;
258} 248}
@@ -274,32 +264,32 @@ get_path_from_PATH (char *binary)
274 264
275 p = getenv ("PATH"); 265 p = getenv ("PATH");
276 if (p == NULL) 266 if (p == NULL)
277 { 267 {
278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
279 _("PATH environment variable is unset.\n")); 269 _("PATH environment variable is unset.\n"));
280 return NULL; 270 return NULL;
281 } 271 }
282 path = GNUNET_strdup (p); /* because we write on it */ 272 path = GNUNET_strdup (p); /* because we write on it */
283 buf = GNUNET_malloc (strlen (path) + 20); 273 buf = GNUNET_malloc (strlen (path) + 20);
284 pos = path; 274 pos = path;
285 275
286 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 276 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
287 { 277 {
288 *end = '\0'; 278 *end = '\0';
289 sprintf (buf, "%s/%s", pos, binary); 279 sprintf (buf, "%s/%s", pos, binary);
290 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 280 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
291 {
292 GNUNET_free (path);
293 return buf;
294 }
295 pos = end + 1;
296 }
297 sprintf (buf, "%s/%s", pos, binary);
298 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
299 { 281 {
300 GNUNET_free (path); 282 GNUNET_free (path);
301 return buf; 283 return buf;
302 } 284 }
285 pos = end + 1;
286 }
287 sprintf (buf, "%s/%s", pos, binary);
288 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
289 {
290 GNUNET_free (path);
291 return buf;
292 }
303 GNUNET_free (buf); 293 GNUNET_free (buf);
304 GNUNET_free (path); 294 GNUNET_free (path);
305 return NULL; 295 return NULL;
@@ -316,16 +306,18 @@ get_path_from_PATH (char *binary)
316 * can be run properly, GNUNET_NO otherwise 306 * can be run properly, GNUNET_NO otherwise
317 */ 307 */
318static int 308static int
319check_gnunet_nat_binary(char *binary) 309check_gnunet_nat_binary (char *binary)
320{ 310{
321 struct stat statbuf; 311 struct stat statbuf;
322 char *p; 312 char *p;
313
323#ifdef MINGW 314#ifdef MINGW
324 SOCKET rawsock; 315 SOCKET rawsock;
325#endif 316#endif
326 317
327#ifdef MINGW 318#ifdef MINGW
328 char *binaryexe; 319 char *binaryexe;
320
329 GNUNET_asprintf (&binaryexe, "%s.exe", binary); 321 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
330 p = get_path_from_PATH (binaryexe); 322 p = get_path_from_PATH (binaryexe);
331 free (binaryexe); 323 free (binaryexe);
@@ -333,36 +325,34 @@ check_gnunet_nat_binary(char *binary)
333 p = get_path_from_PATH (binary); 325 p = get_path_from_PATH (binary);
334#endif 326#endif
335 if (p == NULL) 327 if (p == NULL)
336 { 328 {
337 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 329 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
338 _("Could not find binary `%s' in PATH!\n"), 330 _("Could not find binary `%s' in PATH!\n"), binary);
339 binary); 331 return GNUNET_NO;
340 return GNUNET_NO; 332 }
341 }
342 if (0 != STAT (p, &statbuf)) 333 if (0 != STAT (p, &statbuf))
343 { 334 {
344 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 335 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
345 _("stat (%s) failed: %s\n"), 336 _("stat (%s) failed: %s\n"), p, STRERROR (errno));
346 p, 337 GNUNET_free (p);
347 STRERROR (errno)); 338 return GNUNET_SYSERR;
348 GNUNET_free (p); 339 }
349 return GNUNET_SYSERR;
350 }
351 GNUNET_free (p); 340 GNUNET_free (p);
352#ifndef MINGW 341#ifndef MINGW
353 if ( (0 != (statbuf.st_mode & S_ISUID)) && 342 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
354 (statbuf.st_uid == 0) )
355 return GNUNET_YES; 343 return GNUNET_YES;
356 return GNUNET_NO; 344 return GNUNET_NO;
357#else 345#else
358 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); 346 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
359 if (INVALID_SOCKET == rawsock) 347 if (INVALID_SOCKET == rawsock)
360 { 348 {
361 DWORD err = GetLastError (); 349 DWORD err = GetLastError ();
362 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 350
363 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err); 351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
364 return GNUNET_NO; /* not running as administrator */ 352 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
365 } 353 err);
354 return GNUNET_NO; /* not running as administrator */
355 }
366 closesocket (rawsock); 356 closesocket (rawsock);
367 return GNUNET_YES; 357 return GNUNET_YES;
368#endif 358#endif
@@ -381,13 +371,13 @@ main (int argc, char *argv[])
381#endif 371#endif
382 NULL); 372 NULL);
383 373
384 char * pch = strdup(argv[0]); 374 char *pch = strdup (argv[0]);
385 char * backup = pch; 375 char *backup = pch;
386 char * filename = NULL; 376 char *filename = NULL;
387 char *dotexe; 377 char *dotexe;
388 378
389 /* get executable filename */ 379 /* get executable filename */
390 pch = strtok (pch,"/"); 380 pch = strtok (pch, "/");
391 while (pch != NULL) 381 while (pch != NULL)
392 { 382 {
393 pch = strtok (NULL, "/"); 383 pch = strtok (NULL, "/");
@@ -395,35 +385,35 @@ main (int argc, char *argv[])
395 filename = pch; 385 filename = pch;
396 } 386 }
397 /* remove "lt-" */ 387 /* remove "lt-" */
398 filename = strstr(filename, "tes"); 388 filename = strstr (filename, "tes");
399 if (NULL != (dotexe = strstr (filename, ".exe"))) 389 if (NULL != (dotexe = strstr (filename, ".exe")))
400 dotexe[0] = '\0'; 390 dotexe[0] = '\0';
401 391
402 /* create cfg filename */ 392 /* create cfg filename */
403 GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename); 393 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
404 GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename); 394 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
405 GNUNET_free (backup); 395 GNUNET_free (backup);
406 396
407 if (strstr(argv[0], "tcp_nat") != NULL) 397 if (strstr (argv[0], "tcp_nat") != NULL)
398 {
399 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
408 { 400 {
409 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 401 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
410 { 402 "`%s' not properly installed, cannot run NAT test!\n",
411 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 403 "gnunet-nat-server");
412 "`%s' not properly installed, cannot run NAT test!\n", 404 return 0;
413 "gnunet-nat-server");
414 return 0;
415 }
416 } 405 }
417 else if (strstr(argv[0], "udp_nat") != NULL) 406 }
407 else if (strstr (argv[0], "udp_nat") != NULL)
408 {
409 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
418 { 410 {
419 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 411 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
420 { 412 "`%s' not properly installed, cannot run NAT test!\n",
421 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 413 "gnunet-nat-server");
422 "`%s' not properly installed, cannot run NAT test!\n", 414 return 0;
423 "gnunet-nat-server");
424 return 0;
425 }
426 } 415 }
416 }
427 417
428 ret = check (); 418 ret = check ();
429 419
diff --git a/src/transport/test_transport_api_disconnect.c b/src/transport/test_transport_api_disconnect.c
index 35cda3d04..08f57b670 100644
--- a/src/transport/test_transport_api_disconnect.c
+++ b/src/transport/test_transport_api_disconnect.c
@@ -67,11 +67,11 @@ static int peers_connected = 0;
67static int counter; 67static int counter;
68static int msgs_recv; 68static int msgs_recv;
69 69
70static GNUNET_SCHEDULER_TaskIdentifier die_task; 70static GNUNET_SCHEDULER_TaskIdentifier die_task;
71 71
72static GNUNET_SCHEDULER_TaskIdentifier tct; 72static GNUNET_SCHEDULER_TaskIdentifier tct;
73 73
74struct GNUNET_TRANSPORT_TransmitHandle * th; 74struct GNUNET_TRANSPORT_TransmitHandle *th;
75 75
76#if VERBOSE 76#if VERBOSE
77#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 77#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
@@ -80,18 +80,16 @@ struct GNUNET_TRANSPORT_TransmitHandle * th;
80#endif 80#endif
81 81
82 82
83static void 83static void peers_connect ();
84peers_connect ();
85 84
86static void 85static void
87end () 86end ()
88{ 87{
89 if (GNUNET_SCHEDULER_NO_TASK != die_task) 88 if (GNUNET_SCHEDULER_NO_TASK != die_task)
90 GNUNET_SCHEDULER_cancel (die_task); 89 GNUNET_SCHEDULER_cancel (die_task);
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 90 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
92 "Disconnecting from transports!\n");
93 if (th != NULL) 91 if (th != NULL)
94 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 92 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
95 th = NULL; 93 th = NULL;
96 94
97 if (p1.th != NULL) 95 if (p1.th != NULL)
@@ -100,8 +98,8 @@ end ()
100 if (p2.th != NULL) 98 if (p2.th != NULL)
101 GNUNET_TRANSPORT_disconnect (p2.th); 99 GNUNET_TRANSPORT_disconnect (p2.th);
102 die_task = GNUNET_SCHEDULER_NO_TASK; 100 die_task = GNUNET_SCHEDULER_NO_TASK;
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
104 "Transports disconnected, returning success!\n"); 102 "Transports disconnected, returning success!\n");
105 ok = 0; 103 ok = 0;
106} 104}
107 105
@@ -110,13 +108,13 @@ stop_arm (struct PeerContext *p)
110{ 108{
111#if START_ARM 109#if START_ARM
112 if (NULL != p->arm_proc) 110 if (NULL != p->arm_proc)
113 { 111 {
114 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 112 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
115 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 113 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
116 GNUNET_OS_process_wait (p->arm_proc); 114 GNUNET_OS_process_wait (p->arm_proc);
117 GNUNET_OS_process_close (p->arm_proc); 115 GNUNET_OS_process_close (p->arm_proc);
118 p->arm_proc = NULL; 116 p->arm_proc = NULL;
119 } 117 }
120#endif 118#endif
121 GNUNET_CONFIGURATION_destroy (p->cfg); 119 GNUNET_CONFIGURATION_destroy (p->cfg);
122} 120}
@@ -125,16 +123,15 @@ stop_arm (struct PeerContext *p)
125 123
126 124
127static void 125static void
128exchange_hello_last (void *cls, 126exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
129 const struct GNUNET_MessageHeader *message)
130{ 127{
131 struct PeerContext *me = cls; 128 struct PeerContext *me = cls;
132 129
133 GNUNET_assert (message != NULL); 130 GNUNET_assert (message != NULL);
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
135 "Exchanging HELLO of size %d with peer (%s)!\n", 132 "Exchanging HELLO of size %d with peer (%s)!\n",
136 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 133 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
137 GNUNET_i2s (&me->id)); 134 message), GNUNET_i2s (&me->id));
138 GNUNET_assert (GNUNET_OK == 135 GNUNET_assert (GNUNET_OK ==
139 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 136 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
140 message, &me->id)); 137 message, &me->id));
@@ -143,8 +140,7 @@ exchange_hello_last (void *cls,
143 140
144 141
145static void 142static void
146exchange_hello (void *cls, 143exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
147 const struct GNUNET_MessageHeader *message)
148{ 144{
149 struct PeerContext *me = cls; 145 struct PeerContext *me = cls;
150 146
@@ -153,9 +149,9 @@ exchange_hello (void *cls,
153 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 149 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
154 message, &me->id)); 150 message, &me->id));
155 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
156 "Exchanging HELLO of size %d from peer %s!\n", 152 "Exchanging HELLO of size %d from peer %s!\n",
157 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 153 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
158 GNUNET_i2s (&me->id)); 154 message), GNUNET_i2s (&me->id));
159 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); 155 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
160} 156}
161 157
@@ -167,23 +163,23 @@ end_badly ()
167 GNUNET_break (0); 163 GNUNET_break (0);
168 164
169 if (th != NULL) 165 if (th != NULL)
170 { 166 {
171 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 167 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
172 th = NULL; 168 th = NULL;
173 } 169 }
174 else 170 else
175 { 171 {
176 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); 172 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
177 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); 173 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
178 } 174 }
179 175
180 GNUNET_TRANSPORT_disconnect (p1.th); 176 GNUNET_TRANSPORT_disconnect (p1.th);
181 GNUNET_TRANSPORT_disconnect (p2.th); 177 GNUNET_TRANSPORT_disconnect (p2.th);
182 if (GNUNET_SCHEDULER_NO_TASK != tct) 178 if (GNUNET_SCHEDULER_NO_TASK != tct)
183 { 179 {
184 GNUNET_SCHEDULER_cancel (tct); 180 GNUNET_SCHEDULER_cancel (tct);
185 tct = GNUNET_SCHEDULER_NO_TASK; 181 tct = GNUNET_SCHEDULER_NO_TASK;
186 } 182 }
187 ok = 1; 183 ok = 1;
188} 184}
189 185
@@ -196,20 +192,17 @@ notify_receive (void *cls,
196 uint32_t ats_count) 192 uint32_t ats_count)
197{ 193{
198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
199 "Received message of type %d from peer %s!\n", 195 "Received message of type %d from peer %s!\n",
200 ntohs(message->type), 196 ntohs (message->type), GNUNET_i2s (peer));
201 GNUNET_i2s (peer));
202 OKPP; 197 OKPP;
203 GNUNET_assert (MTYPE == ntohs (message->type)); 198 GNUNET_assert (MTYPE == ntohs (message->type));
204 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 199 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size));
205 ntohs (message->size));
206 200
207 msgs_recv++; 201 msgs_recv++;
208} 202}
209 203
210static void 204static void
211peers_disconnect (void *cls, 205peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
212 const struct GNUNET_SCHEDULER_TaskContext *tc);
213 206
214static size_t 207static size_t
215notify_ready (void *cls, size_t size, void *buf) 208notify_ready (void *cls, size_t size, void *buf)
@@ -220,9 +213,8 @@ notify_ready (void *cls, size_t size, void *buf)
220 th = NULL; 213 th = NULL;
221 214
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
223 "Transmitting message with %u bytes to peer %s\n", 216 "Transmitting message with %u bytes to peer %s\n",
224 sizeof (struct GNUNET_MessageHeader), 217 sizeof (struct GNUNET_MessageHeader), GNUNET_i2s (&p->id));
225 GNUNET_i2s (&p->id));
226 GNUNET_assert (size >= 256); 218 GNUNET_assert (size >= 256);
227 OKPP; 219 OKPP;
228 if (buf != NULL) 220 if (buf != NULL)
@@ -245,94 +237,83 @@ notify_connect (void *cls,
245 uint32_t ats_count) 237 uint32_t ats_count)
246{ 238{
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 239 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
248 "Peer `%4s' connected to us (%p)!\n", 240 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
249 GNUNET_i2s (peer),
250 cls);
251 peers_connected++; 241 peers_connected++;
252 if (cls == &p1) 242 if (cls == &p1)
253 { 243 {
254 GNUNET_assert (ok >= 2); 244 GNUNET_assert (ok >= 2);
255 OKPP; 245 OKPP;
256 OKPP; 246 OKPP;
257 if (GNUNET_SCHEDULER_NO_TASK != die_task) 247 if (GNUNET_SCHEDULER_NO_TASK != die_task)
258 GNUNET_SCHEDULER_cancel (die_task); 248 GNUNET_SCHEDULER_cancel (die_task);
259 if (GNUNET_SCHEDULER_NO_TASK != tct) 249 if (GNUNET_SCHEDULER_NO_TASK != tct)
260 GNUNET_SCHEDULER_cancel (tct); 250 GNUNET_SCHEDULER_cancel (tct);
261 tct = GNUNET_SCHEDULER_NO_TASK; 251 tct = GNUNET_SCHEDULER_NO_TASK;
262 252
263 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, 253 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
264 &end_badly, NULL); 254 &end_badly, NULL);
265 th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 255 th = GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
266 &p2.id, 256 &p2.id,
267 256, 0, TIMEOUT, &notify_ready, 257 256, 0, TIMEOUT, &notify_ready,
268 &p1); 258 &p1);
269 } 259 }
270} 260}
271 261
272 262
273static void 263static void
274notify_disconnect (void *cls, 264notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
275 const struct GNUNET_PeerIdentity *peer)
276{ 265{
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
278 "Peer `%4s' disconnected (%p)!\n", 267 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
279 GNUNET_i2s (peer), cls);
280 peers_connected--; 268 peers_connected--;
281} 269}
282 270
283 271
284static void 272static void
285setup_peer (struct PeerContext *p, 273setup_peer (struct PeerContext *p, const char *cfgname)
286 const char *cfgname)
287{ 274{
288 p->cfg = GNUNET_CONFIGURATION_create (); 275 p->cfg = GNUNET_CONFIGURATION_create ();
289 276
290 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 277 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
291 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 278 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
292 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome); 279 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
280 &p->servicehome);
293 if (NULL != p->servicehome) 281 if (NULL != p->servicehome)
294 GNUNET_DISK_directory_remove (p->servicehome); 282 GNUNET_DISK_directory_remove (p->servicehome);
295 283
296#if START_ARM 284#if START_ARM
297 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 285 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
298 "gnunet-service-arm", 286 "gnunet-service-arm",
299#if VERBOSE_ARM 287#if VERBOSE_ARM
300 "-L", "DEBUG", 288 "-L", "DEBUG",
301#endif 289#endif
302 "-c", cfgname, NULL); 290 "-c", cfgname, NULL);
303#endif 291#endif
304 292
305} 293}
306 294
307 295
308static void 296static void
309try_connect (void *cls, 297try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
310 const struct GNUNET_SCHEDULER_TaskContext *tc)
311{ 298{
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
313 "Asking peers to connect...\n");
314 /* FIXME: 'pX.id' may still be all-zeros here... */ 300 /* FIXME: 'pX.id' may still be all-zeros here... */
315 GNUNET_TRANSPORT_try_connect (p2.th, 301 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
316 &p1.id); 302 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
317 GNUNET_TRANSPORT_try_connect (p1.th,
318 &p2.id);
319 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 303 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
320 &try_connect, 304 &try_connect, NULL);
321 NULL);
322} 305}
323 306
324 307
325static void 308static void
326peers_disconnect (void *cls, 309peers_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
327 const struct GNUNET_SCHEDULER_TaskContext *tc)
328{ 310{
329 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 311 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
330 return; 312 return;
331 313
332 //while (peers_connected > 0); 314 //while (peers_connected > 0);
333 315
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 316 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from Transport \n");
335 "Disconnecting from Transport \n");
336 317
337 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); 318 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
338 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); 319 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
@@ -343,10 +324,10 @@ peers_disconnect (void *cls,
343 GNUNET_TRANSPORT_disconnect (p2.th); 324 GNUNET_TRANSPORT_disconnect (p2.th);
344 p2.th = NULL; 325 p2.th = NULL;
345 326
346 while (peers_connected > 0); 327 while (peers_connected > 0) ;
347 328
348 if (counter < ITERATIONS) 329 if (counter < ITERATIONS)
349 peers_connect(); 330 peers_connect ();
350 else 331 else
351 end (); 332 end ();
352} 333}
@@ -354,8 +335,9 @@ peers_disconnect (void *cls,
354static void 335static void
355peers_connect () 336peers_connect ()
356{ 337{
357 counter ++; 338 counter++;
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration %i of %i\n", counter, ITERATIONS); 339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Iteration %i of %i\n", counter,
340 ITERATIONS);
359 341
360 GNUNET_assert (p1.th == NULL); 342 GNUNET_assert (p1.th == NULL);
361 p1.th = GNUNET_TRANSPORT_connect (p1.cfg, 343 p1.th = GNUNET_TRANSPORT_connect (p1.cfg,
@@ -369,8 +351,8 @@ peers_connect ()
369 &notify_receive, 351 &notify_receive,
370 &notify_connect, &notify_disconnect); 352 &notify_connect, &notify_disconnect);
371 353
372 GNUNET_assert(p1.th != NULL); 354 GNUNET_assert (p1.th != NULL);
373 GNUNET_assert(p2.th != NULL); 355 GNUNET_assert (p2.th != NULL);
374 356
375 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 357 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
376 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); 358 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
@@ -384,8 +366,7 @@ run (void *cls,
384{ 366{
385 GNUNET_assert (ok == 1); 367 GNUNET_assert (ok == 1);
386 OKPP; 368 OKPP;
387 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 369 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
388 &end_badly, NULL);
389 370
390 setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); 371 setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
391 setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); 372 setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
@@ -409,25 +390,24 @@ check ()
409 }; 390 };
410 391
411#if WRITECONFIG 392#if WRITECONFIG
412 setTransportOptions("test_transport_api_data.conf"); 393 setTransportOptions ("test_transport_api_data.conf");
413#endif 394#endif
414 ok = 1; 395 ok = 1;
415 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 396 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
416 argv, "test-transport-api", "nohelp", 397 argv, "test-transport-api", "nohelp", options, &run, &ok);
417 options, &run, &ok);
418 stop_arm (&p1); 398 stop_arm (&p1);
419 stop_arm (&p2); 399 stop_arm (&p2);
420 400
421 if (p1.servicehome != NULL) 401 if (p1.servicehome != NULL)
422 { 402 {
423 GNUNET_DISK_directory_remove (p1.servicehome); 403 GNUNET_DISK_directory_remove (p1.servicehome);
424 GNUNET_free(p1.servicehome); 404 GNUNET_free (p1.servicehome);
425 } 405 }
426 if (p2.servicehome != NULL) 406 if (p2.servicehome != NULL)
427 { 407 {
428 GNUNET_DISK_directory_remove (p2.servicehome); 408 GNUNET_DISK_directory_remove (p2.servicehome);
429 GNUNET_free(p2.servicehome); 409 GNUNET_free (p2.servicehome);
430 } 410 }
431 return ok; 411 return ok;
432} 412}
433 413
diff --git a/src/transport/test_transport_api_multiaddress.c b/src/transport/test_transport_api_multiaddress.c
index b2ac507d2..63ef28862 100644
--- a/src/transport/test_transport_api_multiaddress.c
+++ b/src/transport/test_transport_api_multiaddress.c
@@ -63,9 +63,9 @@ static int ok;
63 63
64static int is_tcp; 64static int is_tcp;
65 65
66static GNUNET_SCHEDULER_TaskIdentifier die_task; 66static GNUNET_SCHEDULER_TaskIdentifier die_task;
67 67
68static GNUNET_SCHEDULER_TaskIdentifier tct; 68static GNUNET_SCHEDULER_TaskIdentifier tct;
69 69
70 70
71#if VERBOSE 71#if VERBOSE
@@ -81,13 +81,13 @@ stop_arm (struct PeerContext *p)
81{ 81{
82#if START_ARM 82#if START_ARM
83 if (NULL != p->arm_proc) 83 if (NULL != p->arm_proc)
84 { 84 {
85 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 85 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
86 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 86 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
87 GNUNET_OS_process_wait (p->arm_proc); 87 GNUNET_OS_process_wait (p->arm_proc);
88 GNUNET_OS_process_close (p->arm_proc); 88 GNUNET_OS_process_close (p->arm_proc);
89 p->arm_proc = NULL; 89 p->arm_proc = NULL;
90 } 90 }
91#endif 91#endif
92 GNUNET_CONFIGURATION_destroy (p->cfg); 92 GNUNET_CONFIGURATION_destroy (p->cfg);
93} 93}
@@ -96,16 +96,15 @@ stop_arm (struct PeerContext *p)
96 96
97 97
98static void 98static void
99exchange_hello_last (void *cls, 99exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
100 const struct GNUNET_MessageHeader *message)
101{ 100{
102 struct PeerContext *me = cls; 101 struct PeerContext *me = cls;
103 102
104 GNUNET_assert (message != NULL); 103 GNUNET_assert (message != NULL);
105 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
106 "Exchanging HELLO of size %d with peer (%s)!\n", 105 "Exchanging HELLO of size %d with peer (%s)!\n",
107 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 106 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
108 GNUNET_i2s (&me->id)); 107 message), GNUNET_i2s (&me->id));
109 GNUNET_assert (GNUNET_OK == 108 GNUNET_assert (GNUNET_OK ==
110 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 109 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
111 message, &me->id)); 110 message, &me->id));
@@ -114,8 +113,7 @@ exchange_hello_last (void *cls,
114 113
115 114
116static void 115static void
117exchange_hello (void *cls, 116exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
118 const struct GNUNET_MessageHeader *message)
119{ 117{
120 struct PeerContext *me = cls; 118 struct PeerContext *me = cls;
121 119
@@ -124,9 +122,9 @@ exchange_hello (void *cls,
124 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 122 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
125 message, &me->id)); 123 message, &me->id));
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Exchanging HELLO of size %d from peer %s!\n", 125 "Exchanging HELLO of size %d from peer %s!\n",
128 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 126 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
129 GNUNET_i2s (&me->id)); 127 message), GNUNET_i2s (&me->id));
130 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); 128 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
131} 129}
132 130
@@ -142,10 +140,10 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
142 GNUNET_TRANSPORT_disconnect (p1.th); 140 GNUNET_TRANSPORT_disconnect (p1.th);
143 GNUNET_TRANSPORT_disconnect (p2.th); 141 GNUNET_TRANSPORT_disconnect (p2.th);
144 if (GNUNET_SCHEDULER_NO_TASK != tct) 142 if (GNUNET_SCHEDULER_NO_TASK != tct)
145 { 143 {
146 GNUNET_SCHEDULER_cancel (tct); 144 GNUNET_SCHEDULER_cancel (tct);
147 tct = GNUNET_SCHEDULER_NO_TASK; 145 tct = GNUNET_SCHEDULER_NO_TASK;
148 } 146 }
149 ok = 1; 147 ok = 1;
150} 148}
151 149
@@ -159,10 +157,10 @@ end_normally (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159 GNUNET_TRANSPORT_disconnect (p1.th); 157 GNUNET_TRANSPORT_disconnect (p1.th);
160 GNUNET_TRANSPORT_disconnect (p2.th); 158 GNUNET_TRANSPORT_disconnect (p2.th);
161 if (GNUNET_SCHEDULER_NO_TASK != tct) 159 if (GNUNET_SCHEDULER_NO_TASK != tct)
162 { 160 {
163 GNUNET_SCHEDULER_cancel (tct); 161 GNUNET_SCHEDULER_cancel (tct);
164 tct = GNUNET_SCHEDULER_NO_TASK; 162 tct = GNUNET_SCHEDULER_NO_TASK;
165 } 163 }
166 ok = 0; 164 ok = 0;
167} 165}
168 166
@@ -173,87 +171,76 @@ notify_connect (void *cls,
173 uint32_t ats_count) 171 uint32_t ats_count)
174{ 172{
175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
176 "Peer `%4s' connected to us (%p)!\n", 174 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
177 GNUNET_i2s (peer),
178 cls);
179 if (cls == &p1) 175 if (cls == &p1)
180 { 176 {
181 GNUNET_assert (ok >= 2); 177 GNUNET_assert (ok >= 2);
182 OKPP; 178 OKPP;
183 OKPP; 179 OKPP;
184 if (GNUNET_SCHEDULER_NO_TASK != die_task) 180 if (GNUNET_SCHEDULER_NO_TASK != die_task)
185 GNUNET_SCHEDULER_cancel (die_task); 181 GNUNET_SCHEDULER_cancel (die_task);
186 if (GNUNET_SCHEDULER_NO_TASK != tct) 182 if (GNUNET_SCHEDULER_NO_TASK != tct)
187 GNUNET_SCHEDULER_cancel (tct); 183 GNUNET_SCHEDULER_cancel (tct);
188 tct = GNUNET_SCHEDULER_NO_TASK; 184 tct = GNUNET_SCHEDULER_NO_TASK;
189 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT, 185 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT_TRANSMIT,
190 &end_normally, NULL); 186 &end_normally, NULL);
191 } 187 }
192} 188}
193 189
194 190
195static void 191static void
196notify_disconnect (void *cls, 192notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
197 const struct GNUNET_PeerIdentity *peer)
198{ 193{
199 if ( (ok != 60) && 194 if ((ok != 60) && (GNUNET_SCHEDULER_NO_TASK != die_task))
200 (GNUNET_SCHEDULER_NO_TASK != die_task) ) 195 {
201 { 196 GNUNET_SCHEDULER_cancel (die_task);
202 GNUNET_SCHEDULER_cancel (die_task); 197 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
203 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 198 }
204 }
205 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 199 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
206 "Peer `%4s' disconnected (%p)!\n", 200 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
207 GNUNET_i2s (peer), cls);
208} 201}
209 202
210 203
211static void 204static void
212setup_peer (struct PeerContext *p, 205setup_peer (struct PeerContext *p, const char *cfgname)
213 const char *cfgname)
214{ 206{
215 p->cfg = GNUNET_CONFIGURATION_create (); 207 p->cfg = GNUNET_CONFIGURATION_create ();
216 208
217 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 209 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
218 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 210 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
219 { 211 {
220 GNUNET_assert (GNUNET_OK == 212 GNUNET_assert (GNUNET_OK ==
221 GNUNET_CONFIGURATION_get_value_string (p->cfg, 213 GNUNET_CONFIGURATION_get_value_string (p->cfg,
222 "PATHS", "SERVICEHOME", 214 "PATHS",
223 &p->servicehome)); 215 "SERVICEHOME",
224 GNUNET_DISK_directory_remove (p->servicehome); 216 &p->servicehome));
225 } 217 GNUNET_DISK_directory_remove (p->servicehome);
218 }
226 219
227#if START_ARM 220#if START_ARM
228 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 221 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
229 "gnunet-service-arm", 222 "gnunet-service-arm",
230#if VERBOSE_ARM 223#if VERBOSE_ARM
231 "-L", "DEBUG", 224 "-L", "DEBUG",
232#endif 225#endif
233 "-c", cfgname, NULL); 226 "-c", cfgname, NULL);
234#endif 227#endif
235 p->th = GNUNET_TRANSPORT_connect (p->cfg, 228 p->th = GNUNET_TRANSPORT_connect (p->cfg,
236 NULL, p, 229 NULL, p,
237 NULL, 230 NULL, &notify_connect, &notify_disconnect);
238 &notify_connect, &notify_disconnect);
239 GNUNET_assert (p->th != NULL); 231 GNUNET_assert (p->th != NULL);
240} 232}
241 233
242 234
243static void 235static void
244try_connect (void *cls, 236try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
245 const struct GNUNET_SCHEDULER_TaskContext *tc)
246{ 237{
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
248 "Asking peers to connect...\n");
249 /* FIXME: 'pX.id' may still be all-zeros here... */ 239 /* FIXME: 'pX.id' may still be all-zeros here... */
250 GNUNET_TRANSPORT_try_connect (p2.th, 240 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
251 &p1.id); 241 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
252 GNUNET_TRANSPORT_try_connect (p1.th,
253 &p2.id);
254 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 242 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
255 &try_connect, 243 &try_connect, NULL);
256 NULL);
257} 244}
258 245
259 246
@@ -264,15 +251,14 @@ run (void *cls,
264{ 251{
265 GNUNET_assert (ok == 1); 252 GNUNET_assert (ok == 1);
266 OKPP; 253 OKPP;
267 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 254 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
268 &end_badly, NULL);
269 if (is_tcp) 255 if (is_tcp)
270 { 256 {
271 setup_peer (&p1, "test_transport_api_multiaddress_tcp_peer1.conf"); 257 setup_peer (&p1, "test_transport_api_multiaddress_tcp_peer1.conf");
272 setup_peer (&p2, "test_transport_api_multiaddress_tcp_peer2.conf"); 258 setup_peer (&p2, "test_transport_api_multiaddress_tcp_peer2.conf");
273 } 259 }
274 GNUNET_assert(p1.th != NULL); 260 GNUNET_assert (p1.th != NULL);
275 GNUNET_assert(p2.th != NULL); 261 GNUNET_assert (p2.th != NULL);
276 262
277 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 263 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
278 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); 264 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
@@ -295,25 +281,24 @@ check ()
295 }; 281 };
296 282
297#if WRITECONFIG 283#if WRITECONFIG
298 setTransportOptions("test_transport_api_data.conf"); 284 setTransportOptions ("test_transport_api_data.conf");
299#endif 285#endif
300 ok = 1; 286 ok = 1;
301 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 287 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
302 argv, "test-transport-api", "nohelp", 288 argv, "test-transport-api", "nohelp", options, &run, &ok);
303 options, &run, &ok);
304 stop_arm (&p1); 289 stop_arm (&p1);
305 stop_arm (&p2); 290 stop_arm (&p2);
306 291
307 if (p1.servicehome != NULL) 292 if (p1.servicehome != NULL)
308 { 293 {
309 GNUNET_DISK_directory_remove (p1.servicehome); 294 GNUNET_DISK_directory_remove (p1.servicehome);
310 GNUNET_free(p1.servicehome); 295 GNUNET_free (p1.servicehome);
311 } 296 }
312 if (p2.servicehome != NULL) 297 if (p2.servicehome != NULL)
313 { 298 {
314 GNUNET_DISK_directory_remove (p2.servicehome); 299 GNUNET_DISK_directory_remove (p2.servicehome);
315 GNUNET_free(p2.servicehome); 300 GNUNET_free (p2.servicehome);
316 } 301 }
317 return ok; 302 return ok;
318} 303}
319 304
@@ -331,10 +316,10 @@ main (int argc, char *argv[])
331#endif 316#endif
332 NULL); 317 NULL);
333 318
334 if (strstr(argv[0], "tcp") != NULL) 319 if (strstr (argv[0], "tcp") != NULL)
335 { 320 {
336 is_tcp = GNUNET_YES; 321 is_tcp = GNUNET_YES;
337 } 322 }
338 323
339 ret = check (); 324 ret = check ();
340 325
diff --git a/src/transport/test_transport_api_reliability.c b/src/transport/test_transport_api_reliability.c
index 37395ad0f..60191394d 100644
--- a/src/transport/test_transport_api_reliability.c
+++ b/src/transport/test_transport_api_reliability.c
@@ -51,17 +51,17 @@
51 51
52static int ok; 52static int ok;
53 53
54static GNUNET_SCHEDULER_TaskIdentifier die_task; 54static GNUNET_SCHEDULER_TaskIdentifier die_task;
55 55
56struct PeerContext * p1; 56struct PeerContext *p1;
57 57
58struct PeerContext * p2; 58struct PeerContext *p2;
59 59
60struct GNUNET_TRANSPORT_TransmitHandle * th; 60struct GNUNET_TRANSPORT_TransmitHandle *th;
61 61
62char * cfg_file_p1; 62char *cfg_file_p1;
63 63
64char * cfg_file_p2; 64char *cfg_file_p2;
65 65
66/* 66/*
67 * Testcase specific declarations 67 * Testcase specific declarations
@@ -108,27 +108,27 @@ static void
108end () 108end ()
109{ 109{
110 unsigned long long delta; 110 unsigned long long delta;
111
111 //char *value_name; 112 //char *value_name;
112 113
113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
114 115
115 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 116 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
116 fprintf (stderr, 117 fprintf (stderr,
117 "\nThroughput was %llu kb/s\n", 118 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
118 total_bytes * 1000 / 1024 / delta);
119 //GNUNET_asprintf(&value_name, "reliable_%s", test_name); 119 //GNUNET_asprintf(&value_name, "reliable_%s", test_name);
120 //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); 120 //GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s");
121 //GNUNET_free(value_name); 121 //GNUNET_free(value_name);
122 122
123 if (die_task != GNUNET_SCHEDULER_NO_TASK) 123 if (die_task != GNUNET_SCHEDULER_NO_TASK)
124 GNUNET_SCHEDULER_cancel(die_task); 124 GNUNET_SCHEDULER_cancel (die_task);
125 125
126 if (th != NULL) 126 if (th != NULL)
127 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 127 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
128 th = NULL; 128 th = NULL;
129 129
130 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 130 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
131 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 131 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
132} 132}
133 133
134static void 134static void
@@ -138,13 +138,13 @@ end_badly ()
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
139 139
140 if (th != NULL) 140 if (th != NULL)
141 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th); 141 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th);
142 th = NULL; 142 th = NULL;
143 143
144 if (p1 != NULL) 144 if (p1 != NULL)
145 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 145 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
146 if (p2 != NULL) 146 if (p2 != NULL)
147 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 147 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
148 148
149 ok = GNUNET_SYSERR; 149 ok = GNUNET_SYSERR;
150} 150}
@@ -172,75 +172,66 @@ notify_receive (void *cls,
172 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 172 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
173 const struct TestMessage *hdr; 173 const struct TestMessage *hdr;
174 174
175 hdr = (const struct TestMessage*) message; 175 hdr = (const struct TestMessage *) message;
176 s = get_size (n); 176 s = get_size (n);
177 if (MTYPE != ntohs (message->type)) 177 if (MTYPE != ntohs (message->type))
178 return; 178 return;
179 msg_recv_expected = n; 179 msg_recv_expected = n;
180 msg_recv = ntohl(hdr->num); 180 msg_recv = ntohl (hdr->num);
181 if (ntohs (message->size) != (s)) 181 if (ntohs (message->size) != (s))
182 { 182 {
183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
184 "Expected message %u of size %u, got %u bytes of message %u\n", 184 "Expected message %u of size %u, got %u bytes of message %u\n",
185 n, s, 185 n, s, ntohs (message->size), ntohl (hdr->num));
186 ntohs (message->size), 186 if (die_task != GNUNET_SCHEDULER_NO_TASK)
187 ntohl (hdr->num)); 187 GNUNET_SCHEDULER_cancel (die_task);
188 if (die_task != GNUNET_SCHEDULER_NO_TASK) 188 test_failed = GNUNET_YES;
189 GNUNET_SCHEDULER_cancel (die_task); 189 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
190 test_failed = GNUNET_YES; 190 return;
191 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 191 }
192 return;
193 }
194 if (ntohl (hdr->num) != n) 192 if (ntohl (hdr->num) != n)
195 { 193 {
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 194 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "Expected message %u of size %u, got %u bytes of message %u\n", 195 "Expected message %u of size %u, got %u bytes of message %u\n",
198 n, s, 196 n, s, ntohs (message->size), ntohl (hdr->num));
199 ntohs (message->size), 197 if (die_task != GNUNET_SCHEDULER_NO_TASK)
200 ntohl (hdr->num)); 198 GNUNET_SCHEDULER_cancel (die_task);
201 if (die_task != GNUNET_SCHEDULER_NO_TASK) 199 test_failed = GNUNET_YES;
202 GNUNET_SCHEDULER_cancel (die_task); 200 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
203 test_failed = GNUNET_YES; 201 return;
204 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 202 }
205 return;
206 }
207 memset (cbuf, n, s - sizeof (struct TestMessage)); 203 memset (cbuf, n, s - sizeof (struct TestMessage));
208 if (0 != memcmp (cbuf, 204 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
209 &hdr[1], 205 {
210 s - sizeof (struct TestMessage))) 206 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
211 { 207 "Expected message %u with bits %u, but body did not match\n",
212 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 208 n, (unsigned char) n);
213 "Expected message %u with bits %u, but body did not match\n", 209 if (die_task != GNUNET_SCHEDULER_NO_TASK)
214 n, (unsigned char) n); 210 GNUNET_SCHEDULER_cancel (die_task);
215 if (die_task != GNUNET_SCHEDULER_NO_TASK) 211 test_failed = GNUNET_YES;
216 GNUNET_SCHEDULER_cancel (die_task); 212 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
217 test_failed = GNUNET_YES; 213 return;
218 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 214 }
219 return;
220 }
221#if VERBOSE 215#if VERBOSE
222 if (ntohl(hdr->num) % 5000 == 0) 216 if (ntohl (hdr->num) % 5000 == 0)
223 { 217 {
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
225 "Got message %u of size %u\n", 219 "Got message %u of size %u\n",
226 ntohl (hdr->num), 220 ntohl (hdr->num), ntohs (message->size));
227 ntohs (message->size)); 221 }
228 }
229#endif 222#endif
230 n++; 223 n++;
231 if (0 == (n % (TOTAL_MSGS/100))) 224 if (0 == (n % (TOTAL_MSGS / 100)))
232 { 225 {
233 fprintf (stderr, "."); 226 fprintf (stderr, ".");
234 if (die_task != GNUNET_SCHEDULER_NO_TASK) 227 if (die_task != GNUNET_SCHEDULER_NO_TASK)
235 GNUNET_SCHEDULER_cancel (die_task); 228 GNUNET_SCHEDULER_cancel (die_task);
236 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 229 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
237 &end_badly, 230 }
238 NULL);
239 }
240 if (n == TOTAL_MSGS) 231 if (n == TOTAL_MSGS)
241 { 232 {
242 ok = 0; 233 ok = 0;
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages received\n"); 234 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages received\n");
244 end (); 235 end ();
245 } 236 }
246} 237}
@@ -256,11 +247,11 @@ notify_ready (void *cls, size_t size, void *buf)
256 unsigned int ret; 247 unsigned int ret;
257 248
258 if (buf == NULL) 249 if (buf == NULL)
259 { 250 {
260 GNUNET_break (0); 251 GNUNET_break (0);
261 ok = 42; 252 ok = 42;
262 return 0; 253 return 0;
263 } 254 }
264 th = NULL; 255 th = NULL;
265 ret = 0; 256 ret = 0;
266 s = get_size (n); 257 s = get_size (n);
@@ -268,50 +259,46 @@ notify_ready (void *cls, size_t size, void *buf)
268 GNUNET_assert (buf != NULL); 259 GNUNET_assert (buf != NULL);
269 cbuf = buf; 260 cbuf = buf;
270 do 261 do
271 { 262 {
272 hdr.header.size = htons (s); 263 hdr.header.size = htons (s);
273 hdr.header.type = htons (MTYPE); 264 hdr.header.type = htons (MTYPE);
274 hdr.num = htonl (n); 265 hdr.num = htonl (n);
275 msg_sent = n; 266 msg_sent = n;
276 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); 267 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
277 ret += sizeof (struct TestMessage); 268 ret += sizeof (struct TestMessage);
278 memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); 269 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
279 ret += s - sizeof (struct TestMessage); 270 ret += s - sizeof (struct TestMessage);
280#if VERBOSE 271#if VERBOSE
281 if (n % 5000 == 0) 272 if (n % 5000 == 0)
282 { 273 {
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 274 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
284 "Sending message %u of size %u\n", 275 "Sending message %u of size %u\n", n, s);
285 n,
286 s);
287 }
288#endif
289 n++;
290 s = get_size (n);
291 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
292 break; /* sometimes pack buffer full, sometimes not */
293 } 276 }
277#endif
278 n++;
279 s = get_size (n);
280 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
281 break; /* sometimes pack buffer full, sometimes not */
282 }
294 while (size - ret >= s); 283 while (size - ret >= s);
295 if (n < TOTAL_MSGS) 284 if (n < TOTAL_MSGS)
296 { 285 {
297 if (th == NULL) 286 if (th == NULL)
298 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 287 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
299 &p1->id, 288 &p1->id,
300 s, 0, TIMEOUT, 289 s, 0, TIMEOUT,
301 &notify_ready, 290 &notify_ready, NULL);
302 NULL);
303 msg_scheduled = n; 291 msg_scheduled = n;
304 } 292 }
305 if (n % 5000 == 0) 293 if (n % 5000 == 0)
306 { 294 {
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "Returning total message block of size %u\n", 296 "Returning total message block of size %u\n", ret);
309 ret); 297 }
310 }
311 total_bytes += ret; 298 total_bytes += ret;
312 if (n == TOTAL_MSGS) 299 if (n == TOTAL_MSGS)
313 { 300 {
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"All messages sent\n"); 301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All messages sent\n");
315 } 302 }
316 return ret; 303 return ret;
317} 304}
@@ -325,34 +312,34 @@ notify_connect (void *cls,
325{ 312{
326 313
327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
328 "Peer `%4s' connected to us (%p)!\n", 315 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
329 GNUNET_i2s (peer),
330 cls);
331 316
332 if (cls == p1) 317 if (cls == p1)
333 { 318 {
334 GNUNET_TRANSPORT_set_quota (p1->th, 319 GNUNET_TRANSPORT_set_quota (p1->th,
335 &p2->id, 320 &p2->id,
336 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), 321 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
337 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); 322 1024),
338 } 323 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
339 else if (cls == p2) 324 1024));
340 { 325 }
341 GNUNET_TRANSPORT_set_quota (p2->th, 326 else if (cls == p2)
342 &p1->id, 327 {
343 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024), 328 GNUNET_TRANSPORT_set_quota (p2->th,
344 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024)); 329 &p1->id,
345 } 330 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
331 1024),
332 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
333 1024));
334 }
346} 335}
347 336
348 337
349static void 338static void
350notify_disconnect (void *cls, 339notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
351 const struct GNUNET_PeerIdentity *peer)
352{ 340{
353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
354 "Peer `%4s' disconnected (%p)!\n", 342 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
355 GNUNET_i2s (peer), cls);
356} 343}
357 344
358static void 345static void
@@ -360,23 +347,22 @@ sendtask ()
360{ 347{
361 start_time = GNUNET_TIME_absolute_get (); 348 start_time = GNUNET_TIME_absolute_get ();
362 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th, 349 th = GNUNET_TRANSPORT_notify_transmit_ready (p2->th,
363 &p1->id, 350 &p1->id,
364 get_size (0), 0, TIMEOUT, 351 get_size (0), 0, TIMEOUT,
365 &notify_ready, 352 &notify_ready, NULL);
366 NULL);
367} 353}
368 354
369static void 355static void
370testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) 356testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
371{ 357{
372 char * p1_c = strdup (GNUNET_i2s(&p1->id)); 358 char *p1_c = strdup (GNUNET_i2s (&p1->id));
359
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n", 360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers connected: %s <-> %s\n",
374 p1_c, 361 p1_c, GNUNET_i2s (&p2->id));
375 GNUNET_i2s (&p2->id));
376 GNUNET_free (p1_c); 362 GNUNET_free (p1_c);
377 363
378 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG! 364 // FIXME: THIS IS REQUIRED! SEEMS TO BE A BUG!
379 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL); 365 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &sendtask, NULL);
380} 366}
381 367
382static void 368static void
@@ -384,21 +370,18 @@ run (void *cls,
384 char *const *args, 370 char *const *args,
385 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 371 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
386{ 372{
387 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 373 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
388 &end_badly, NULL); 374
389 375 p1 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p1,
390 p1 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p1, 376 &notify_receive,
391 &notify_receive, 377 &notify_connect,
392 &notify_connect, 378 &notify_disconnect, NULL);
393 &notify_disconnect, 379 p2 = GNUNET_TRANSPORT_TESTING_start_peer (cfg_file_p2,
394 NULL); 380 &notify_receive,
395 p2 = GNUNET_TRANSPORT_TESTING_start_peer(cfg_file_p2, 381 &notify_connect,
396 &notify_receive, 382 &notify_disconnect, NULL);
397 &notify_connect, 383
398 &notify_disconnect, 384 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
399 NULL);
400
401 GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL);
402} 385}
403 386
404static int 387static int
@@ -417,12 +400,11 @@ check ()
417 }; 400 };
418 401
419#if WRITECONFIG 402#if WRITECONFIG
420 setTransportOptions("test_transport_api_data.conf"); 403 setTransportOptions ("test_transport_api_data.conf");
421#endif 404#endif
422 ok = 1; 405 ok = 1;
423 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 406 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
424 argv, "test-transport-api", "nohelp", 407 argv, "test-transport-api", "nohelp", options, &run, &ok);
425 options, &run, &ok);
426 408
427 return ok; 409 return ok;
428} 410}
@@ -444,32 +426,32 @@ get_path_from_PATH (char *binary)
444 426
445 p = getenv ("PATH"); 427 p = getenv ("PATH");
446 if (p == NULL) 428 if (p == NULL)
447 { 429 {
448 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 430 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
449 _("PATH environment variable is unset.\n")); 431 _("PATH environment variable is unset.\n"));
450 return NULL; 432 return NULL;
451 } 433 }
452 path = GNUNET_strdup (p); /* because we write on it */ 434 path = GNUNET_strdup (p); /* because we write on it */
453 buf = GNUNET_malloc (strlen (path) + 20); 435 buf = GNUNET_malloc (strlen (path) + 20);
454 pos = path; 436 pos = path;
455 437
456 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 438 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
457 { 439 {
458 *end = '\0'; 440 *end = '\0';
459 sprintf (buf, "%s/%s", pos, binary); 441 sprintf (buf, "%s/%s", pos, binary);
460 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 442 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
461 {
462 GNUNET_free (path);
463 return buf;
464 }
465 pos = end + 1;
466 }
467 sprintf (buf, "%s/%s", pos, binary);
468 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
469 { 443 {
470 GNUNET_free (path); 444 GNUNET_free (path);
471 return buf; 445 return buf;
472 } 446 }
447 pos = end + 1;
448 }
449 sprintf (buf, "%s/%s", pos, binary);
450 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
451 {
452 GNUNET_free (path);
453 return buf;
454 }
473 GNUNET_free (buf); 455 GNUNET_free (buf);
474 GNUNET_free (path); 456 GNUNET_free (path);
475 return NULL; 457 return NULL;
@@ -486,16 +468,18 @@ get_path_from_PATH (char *binary)
486 * can be run properly, GNUNET_NO otherwise 468 * can be run properly, GNUNET_NO otherwise
487 */ 469 */
488static int 470static int
489check_gnunet_nat_binary(char *binary) 471check_gnunet_nat_binary (char *binary)
490{ 472{
491 struct stat statbuf; 473 struct stat statbuf;
492 char *p; 474 char *p;
475
493#ifdef MINGW 476#ifdef MINGW
494 SOCKET rawsock; 477 SOCKET rawsock;
495#endif 478#endif
496 479
497#ifdef MINGW 480#ifdef MINGW
498 char *binaryexe; 481 char *binaryexe;
482
499 GNUNET_asprintf (&binaryexe, "%s.exe", binary); 483 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
500 p = get_path_from_PATH (binaryexe); 484 p = get_path_from_PATH (binaryexe);
501 free (binaryexe); 485 free (binaryexe);
@@ -503,36 +487,34 @@ check_gnunet_nat_binary(char *binary)
503 p = get_path_from_PATH (binary); 487 p = get_path_from_PATH (binary);
504#endif 488#endif
505 if (p == NULL) 489 if (p == NULL)
506 { 490 {
507 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
508 _("Could not find binary `%s' in PATH!\n"), 492 _("Could not find binary `%s' in PATH!\n"), binary);
509 binary); 493 return GNUNET_NO;
510 return GNUNET_NO; 494 }
511 }
512 if (0 != STAT (p, &statbuf)) 495 if (0 != STAT (p, &statbuf))
513 { 496 {
514 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 497 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
515 _("stat (%s) failed: %s\n"), 498 _("stat (%s) failed: %s\n"), p, STRERROR (errno));
516 p, 499 GNUNET_free (p);
517 STRERROR (errno)); 500 return GNUNET_SYSERR;
518 GNUNET_free (p); 501 }
519 return GNUNET_SYSERR;
520 }
521 GNUNET_free (p); 502 GNUNET_free (p);
522#ifndef MINGW 503#ifndef MINGW
523 if ( (0 != (statbuf.st_mode & S_ISUID)) && 504 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
524 (statbuf.st_uid == 0) )
525 return GNUNET_YES; 505 return GNUNET_YES;
526 return GNUNET_NO; 506 return GNUNET_NO;
527#else 507#else
528 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); 508 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
529 if (INVALID_SOCKET == rawsock) 509 if (INVALID_SOCKET == rawsock)
530 { 510 {
531 DWORD err = GetLastError (); 511 DWORD err = GetLastError ();
532 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 512
533 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err); 513 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
534 return GNUNET_NO; /* not running as administrator */ 514 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
535 } 515 err);
516 return GNUNET_NO; /* not running as administrator */
517 }
536 closesocket (rawsock); 518 closesocket (rawsock);
537 return GNUNET_YES; 519 return GNUNET_YES;
538#endif 520#endif
@@ -551,13 +533,13 @@ main (int argc, char *argv[])
551#endif 533#endif
552 NULL); 534 NULL);
553 535
554 char * pch = strdup(argv[0]); 536 char *pch = strdup (argv[0]);
555 char * backup = pch; 537 char *backup = pch;
556 char * filename = NULL; 538 char *filename = NULL;
557 char *dotexe; 539 char *dotexe;
558 540
559 /* get executable filename */ 541 /* get executable filename */
560 pch = strtok (pch,"/"); 542 pch = strtok (pch, "/");
561 while (pch != NULL) 543 while (pch != NULL)
562 { 544 {
563 pch = strtok (NULL, "/"); 545 pch = strtok (NULL, "/");
@@ -565,35 +547,35 @@ main (int argc, char *argv[])
565 filename = pch; 547 filename = pch;
566 } 548 }
567 /* remove "lt-" */ 549 /* remove "lt-" */
568 filename = strstr(filename, "tes"); 550 filename = strstr (filename, "tes");
569 if (NULL != (dotexe = strstr (filename, ".exe"))) 551 if (NULL != (dotexe = strstr (filename, ".exe")))
570 dotexe[0] = '\0'; 552 dotexe[0] = '\0';
571 553
572 /* create cfg filename */ 554 /* create cfg filename */
573 GNUNET_asprintf(&cfg_file_p1, "%s_peer1.conf",filename); 555 GNUNET_asprintf (&cfg_file_p1, "%s_peer1.conf", filename);
574 GNUNET_asprintf(&cfg_file_p2, "%s_peer2.conf", filename); 556 GNUNET_asprintf (&cfg_file_p2, "%s_peer2.conf", filename);
575 GNUNET_free (backup); 557 GNUNET_free (backup);
576 558
577 if (strstr(argv[0], "tcp_nat") != NULL) 559 if (strstr (argv[0], "tcp_nat") != NULL)
560 {
561 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
578 { 562 {
579 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 563 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
580 { 564 "`%s' not properly installed, cannot run NAT test!\n",
581 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 565 "gnunet-nat-server");
582 "`%s' not properly installed, cannot run NAT test!\n", 566 return 0;
583 "gnunet-nat-server");
584 return 0;
585 }
586 } 567 }
587 else if (strstr(argv[0], "udp_nat") != NULL) 568 }
569 else if (strstr (argv[0], "udp_nat") != NULL)
570 {
571 if (GNUNET_YES != check_gnunet_nat_binary ("gnunet-nat-server"))
588 { 572 {
589 if (GNUNET_YES != check_gnunet_nat_binary("gnunet-nat-server")) 573 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
590 { 574 "`%s' not properly installed, cannot run NAT test!\n",
591 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 575 "gnunet-nat-server");
592 "`%s' not properly installed, cannot run NAT test!\n", 576 return 0;
593 "gnunet-nat-server");
594 return 0;
595 }
596 } 577 }
578 }
597 579
598 ret = check (); 580 ret = check ();
599 581
diff --git a/src/transport/test_transport_api_unreliability.c b/src/transport/test_transport_api_unreliability.c
index e7cb00274..88df23eb4 100644
--- a/src/transport/test_transport_api_unreliability.c
+++ b/src/transport/test_transport_api_unreliability.c
@@ -50,7 +50,7 @@
50 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise 50 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
51 * messages may be dropped even for a reliable transport. 51 * messages may be dropped even for a reliable transport.
52 */ 52 */
53#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */ 53#define TOTAL_MSGS (1024 * 3) /* Total messages should be divisible by 8, so we can make a nice bitmap */
54 54
55/** 55/**
56 * How long until we give up on transmitting the message? 56 * How long until we give up on transmitting the message?
@@ -91,7 +91,7 @@ static GNUNET_SCHEDULER_TaskIdentifier die_task;
91 91
92static GNUNET_SCHEDULER_TaskIdentifier tct; 92static GNUNET_SCHEDULER_TaskIdentifier tct;
93 93
94struct GNUNET_TRANSPORT_TransmitHandle * th_p2; 94struct GNUNET_TRANSPORT_TransmitHandle *th_p2;
95 95
96static char *key_file_p1; 96static char *key_file_p1;
97static char *cert_file_p1; 97static char *cert_file_p1;
@@ -123,11 +123,13 @@ set_bit (unsigned int bitIdx)
123{ 123{
124 size_t arraySlot; 124 size_t arraySlot;
125 unsigned int targetBit; 125 unsigned int targetBit;
126 if (bitIdx >= sizeof(bitmap) * 8) 126
127 { 127 if (bitIdx >= sizeof (bitmap) * 8)
128 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n", bitIdx, sizeof(bitmap) * 8); 128 {
129 return; 129 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "tried to set bit %d of %d(!?!?)\n",
130 } 130 bitIdx, sizeof (bitmap) * 8);
131 return;
132 }
131 arraySlot = bitIdx / 8; 133 arraySlot = bitIdx / 8;
132 targetBit = (1L << (bitIdx % 8)); 134 targetBit = (1L << (bitIdx % 8));
133 bitmap[arraySlot] |= targetBit; 135 bitmap[arraySlot] |= targetBit;
@@ -144,10 +146,11 @@ int
144get_bit (const char *map, unsigned int bit) 146get_bit (const char *map, unsigned int bit)
145{ 147{
146 if (bit >= TOTAL_MSGS) 148 if (bit >= TOTAL_MSGS)
147 { 149 {
148 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit, sizeof(bitmap) * 8); 150 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "get bit %d of %d(!?!?)\n", bit,
149 return 0; 151 sizeof (bitmap) * 8);
150 } 152 return 0;
153 }
151 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0; 154 return ((map)[bit >> 3] & (1 << (bit & 7))) > 0;
152} 155}
153 156
@@ -161,13 +164,13 @@ end ()
161 164
162 result = 0; 165 result = 0;
163 for (i = 0; i < TOTAL_MSGS; i++) 166 for (i = 0; i < TOTAL_MSGS; i++)
167 {
168 if (get_bit (bitmap, i) == 0)
164 { 169 {
165 if (get_bit(bitmap, i) == 0) 170 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n", i);
166 { 171 result = -1;
167 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Did not receive message %d\n", i);
168 result = -1;
169 }
170 } 172 }
173 }
171 174
172 if (GNUNET_SCHEDULER_NO_TASK != die_task) 175 if (GNUNET_SCHEDULER_NO_TASK != die_task)
173 GNUNET_SCHEDULER_cancel (die_task); 176 GNUNET_SCHEDULER_cancel (die_task);
@@ -176,22 +179,22 @@ end ()
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
177#endif 180#endif
178 if (th_p2 != NULL) 181 if (th_p2 != NULL)
179 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); 182 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
180 th_p2 = NULL; 183 th_p2 = NULL;
181 184
182 GNUNET_TRANSPORT_disconnect (p1.th); 185 GNUNET_TRANSPORT_disconnect (p1.th);
183 GNUNET_TRANSPORT_disconnect (p2.th); 186 GNUNET_TRANSPORT_disconnect (p2.th);
184#if VERBOSE 187#if VERBOSE
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
186 "Transports disconnected, returning success!\n"); 189 "Transports disconnected, returning success!\n");
187#endif 190#endif
188 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 191 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
189 GNUNET_asprintf(&value_name, "unreliable_%s", test_name); 192 GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
190 GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); 193 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
191 GNUNET_free(value_name); 194 "kb/s");
195 GNUNET_free (value_name);
192 fprintf (stderr, 196 fprintf (stderr,
193 "\nThroughput was %llu kb/s\n", 197 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
194 total_bytes * 1000 / 1024 / delta);
195 ok = result; 198 ok = result;
196 199
197} 200}
@@ -203,22 +206,23 @@ end_unreliably ()
203 int i; 206 int i;
204 int num_failed; 207 int num_failed;
205 char *value_name; 208 char *value_name;
209
206 num_failed = 0; 210 num_failed = 0;
207 for (i = 0; i < TOTAL_MSGS; i++) 211 for (i = 0; i < TOTAL_MSGS; i++)
212 {
213 if (get_bit (bitmap, i) == 0)
208 { 214 {
209 if (get_bit(bitmap, i) == 0) 215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n", i);
210 { 216 num_failed++;
211 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Did not receive message %d\n", i);
212 num_failed++;
213 }
214 } 217 }
218 }
215 219
216 die_task = GNUNET_SCHEDULER_NO_TASK; 220 die_task = GNUNET_SCHEDULER_NO_TASK;
217#if VERBOSE 221#if VERBOSE
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
219#endif 223#endif
220 if (th_p2 != NULL) 224 if (th_p2 != NULL)
221 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); 225 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
222 226
223 GNUNET_TRANSPORT_disconnect (p1.th); 227 GNUNET_TRANSPORT_disconnect (p1.th);
224 GNUNET_TRANSPORT_disconnect (p2.th); 228 GNUNET_TRANSPORT_disconnect (p2.th);
@@ -228,15 +232,16 @@ end_unreliably ()
228#endif 232#endif
229 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 233 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
230 fprintf (stderr, 234 fprintf (stderr,
231 "\nThroughput was %llu kb/s\n", 235 "\nThroughput was %llu kb/s\n", total_bytes * 1000 / 1024 / delta);
232 total_bytes * 1000 / 1024 / delta); 236 GNUNET_asprintf (&value_name, "unreliable_%s", test_name);
233 GNUNET_asprintf(&value_name, "unreliable_%s", test_name); 237 GAUGER ("TRANSPORT", value_name, (int) (total_bytes * 1000 / 1024 / delta),
234 GAUGER ("TRANSPORT", value_name, (int)(total_bytes * 1000 / 1024 /delta), "kb/s"); 238 "kb/s");
235 GNUNET_free(value_name); 239 GNUNET_free (value_name);
236 GNUNET_asprintf(&value_name, "unreliable_failed_%s", test_name); 240 GNUNET_asprintf (&value_name, "unreliable_failed_%s", test_name);
237 GAUGER ("TRANSPORT", value_name, (int)num_failed, "msgs"); 241 GAUGER ("TRANSPORT", value_name, (int) num_failed, "msgs");
238 GNUNET_free(value_name); 242 GNUNET_free (value_name);
239 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n", num_failed); 243 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Had %d failed messages!\n",
244 num_failed);
240 ok = 0; 245 ok = 0;
241 246
242} 247}
@@ -259,16 +264,15 @@ stop_arm (struct PeerContext *p)
259 264
260 265
261static void 266static void
262exchange_hello_last (void *cls, 267exchange_hello_last (void *cls, const struct GNUNET_MessageHeader *message)
263 const struct GNUNET_MessageHeader *message)
264{ 268{
265 struct PeerContext *me = cls; 269 struct PeerContext *me = cls;
266 270
267 GNUNET_assert (message != NULL); 271 GNUNET_assert (message != NULL);
268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
269 "Exchanging HELLO of size %d with peer (%s)!\n", 273 "Exchanging HELLO of size %d with peer (%s)!\n",
270 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 274 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
271 GNUNET_i2s (&me->id)); 275 message), GNUNET_i2s (&me->id));
272 GNUNET_assert (GNUNET_OK == 276 GNUNET_assert (GNUNET_OK ==
273 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 277 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
274 message, &me->id)); 278 message, &me->id));
@@ -278,8 +282,7 @@ exchange_hello_last (void *cls,
278 282
279 283
280static void 284static void
281exchange_hello (void *cls, 285exchange_hello (void *cls, const struct GNUNET_MessageHeader *message)
282 const struct GNUNET_MessageHeader *message)
283{ 286{
284 struct PeerContext *me = cls; 287 struct PeerContext *me = cls;
285 288
@@ -288,52 +291,47 @@ exchange_hello (void *cls,
288 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 291 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
289 message, &me->id)); 292 message, &me->id));
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
291 "Exchanging HELLO of size %d from peer %s!\n", 294 "Exchanging HELLO of size %d from peer %s!\n",
292 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 295 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
293 GNUNET_i2s (&me->id)); 296 message), GNUNET_i2s (&me->id));
294 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL); 297 GNUNET_TRANSPORT_offer_hello (p2.th, message, NULL, NULL);
295} 298}
296 299
297 300
298 301
299static void 302static void
300end_badly (void *cls, 303end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
301 const struct GNUNET_SCHEDULER_TaskContext *tc)
302{ 304{
303 if (test_failed == GNUNET_NO) 305 if (test_failed == GNUNET_NO)
304 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timeout\n");
305 "Testcase timeout\n");
306 else 307 else
307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
308 "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n", 309 "Reliability failed: Last message sent %u, Next message scheduled %u, Last message received %u, Message expected %u\n",
309 msg_sent, 310 msg_sent, msg_scheduled, msg_recv, msg_recv_expected);
310 msg_scheduled, 311
311 msg_recv,
312 msg_recv_expected);
313
314 GNUNET_break (0); 312 GNUNET_break (0);
315 if (th_p2 != NULL) 313 if (th_p2 != NULL)
316 { 314 {
317 GNUNET_TRANSPORT_notify_transmit_ready_cancel(th_p2); 315 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
318 th_p2 = NULL; 316 th_p2 = NULL;
319 } 317 }
320 if (p2_hello_canceled == GNUNET_NO) 318 if (p2_hello_canceled == GNUNET_NO)
321 { 319 {
322 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2); 320 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
323 p2_hello_canceled = GNUNET_YES; 321 p2_hello_canceled = GNUNET_YES;
324 } 322 }
325 if (p1_hello_canceled == GNUNET_NO) 323 if (p1_hello_canceled == GNUNET_NO)
326 { 324 {
327 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1); 325 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
328 p1_hello_canceled = GNUNET_YES; 326 p1_hello_canceled = GNUNET_YES;
329 } 327 }
330 GNUNET_TRANSPORT_disconnect (p1.th); 328 GNUNET_TRANSPORT_disconnect (p1.th);
331 GNUNET_TRANSPORT_disconnect (p2.th); 329 GNUNET_TRANSPORT_disconnect (p2.th);
332 if (GNUNET_SCHEDULER_NO_TASK != tct) 330 if (GNUNET_SCHEDULER_NO_TASK != tct)
333 { 331 {
334 GNUNET_SCHEDULER_cancel (tct); 332 GNUNET_SCHEDULER_cancel (tct);
335 tct = GNUNET_SCHEDULER_NO_TASK; 333 tct = GNUNET_SCHEDULER_NO_TASK;
336 } 334 }
337 ok = 1; 335 ok = 1;
338} 336}
339 337
@@ -368,63 +366,56 @@ notify_receive (void *cls,
368 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1]; 366 char cbuf[GNUNET_SERVER_MAX_MESSAGE_SIZE - 1];
369 const struct TestMessage *hdr; 367 const struct TestMessage *hdr;
370 368
371 hdr = (const struct TestMessage*) message; 369 hdr = (const struct TestMessage *) message;
372 370
373 if (MTYPE != ntohs (message->type)) 371 if (MTYPE != ntohs (message->type))
374 return; 372 return;
375 msg_recv_expected = n; 373 msg_recv_expected = n;
376 msg_recv = ntohl(hdr->num); 374 msg_recv = ntohl (hdr->num);
377 s = get_size (ntohl(hdr->num)); 375 s = get_size (ntohl (hdr->num));
378 376
379 if (ntohs (message->size) != s) 377 if (ntohs (message->size) != s)
380 { 378 {
381 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
382 "Expected message %u of size %u, got %u bytes of message %u\n", 380 "Expected message %u of size %u, got %u bytes of message %u\n",
383 ntohl(hdr->num), s, 381 ntohl (hdr->num), s, ntohs (message->size), ntohl (hdr->num));
384 ntohs (message->size), 382 if (GNUNET_SCHEDULER_NO_TASK != die_task)
385 ntohl (hdr->num)); 383 GNUNET_SCHEDULER_cancel (die_task);
386 if (GNUNET_SCHEDULER_NO_TASK != die_task) 384 test_failed = GNUNET_YES;
387 GNUNET_SCHEDULER_cancel (die_task); 385 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
388 test_failed = GNUNET_YES; 386 return;
389 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 387 }
390 return;
391 }
392 388
393 memset (cbuf, ntohl(hdr->num), s - sizeof (struct TestMessage)); 389 memset (cbuf, ntohl (hdr->num), s - sizeof (struct TestMessage));
394 if (0 != memcmp (cbuf, 390 if (0 != memcmp (cbuf, &hdr[1], s - sizeof (struct TestMessage)))
395 &hdr[1], 391 {
396 s - sizeof (struct TestMessage))) 392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
397 { 393 "Expected message %u with bits %u, but body did not match\n",
398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 394 ntohl (hdr->num), (unsigned char) n);
399 "Expected message %u with bits %u, but body did not match\n", 395 if (GNUNET_SCHEDULER_NO_TASK != die_task)
400 ntohl(hdr->num), (unsigned char) n); 396 GNUNET_SCHEDULER_cancel (die_task);
401 if (GNUNET_SCHEDULER_NO_TASK != die_task) 397 test_failed = GNUNET_YES;
402 GNUNET_SCHEDULER_cancel (die_task); 398 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
403 test_failed = GNUNET_YES; 399 return;
404 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 400 }
405 return;
406 }
407#if VERBOSE 401#if VERBOSE
408 if (ntohl(hdr->num) % 5 == 0) 402 if (ntohl (hdr->num) % 5 == 0)
409 { 403 {
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
411 "Got message %u of size %u\n", 405 "Got message %u of size %u\n",
412 ntohl (hdr->num), 406 ntohl (hdr->num), ntohs (message->size));
413 ntohs (message->size)); 407 }
414 }
415#endif 408#endif
416 n++; 409 n++;
417 set_bit(ntohl(hdr->num)); 410 set_bit (ntohl (hdr->num));
418 if (0 == (n % (TOTAL_MSGS / 100))) 411 if (0 == (n % (TOTAL_MSGS / 100)))
419 { 412 {
420 fprintf (stderr, "."); 413 fprintf (stderr, ".");
421 if (GNUNET_SCHEDULER_NO_TASK != die_task) 414 if (GNUNET_SCHEDULER_NO_TASK != die_task)
422 GNUNET_SCHEDULER_cancel (die_task); 415 GNUNET_SCHEDULER_cancel (die_task);
423 test_failed = GNUNET_YES; 416 test_failed = GNUNET_YES;
424 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 417 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
425 &end_badly, 418 }
426 NULL);
427 }
428 if (n == TOTAL_MSGS) 419 if (n == TOTAL_MSGS)
429 end (); 420 end ();
430} 421}
@@ -442,63 +433,62 @@ notify_ready (void *cls, size_t size, void *buf)
442 th_p2 = NULL; 433 th_p2 = NULL;
443 434
444 if (buf == NULL) 435 if (buf == NULL)
445 { 436 {
446 GNUNET_break (0); 437 GNUNET_break (0);
447 ok = 42; 438 ok = 42;
448 return 0; 439 return 0;
449 } 440 }
450 ret = 0; 441 ret = 0;
451 s = get_size (n); 442 s = get_size (n);
452 GNUNET_assert (size >= s); 443 GNUNET_assert (size >= s);
453 GNUNET_assert (buf != NULL); 444 GNUNET_assert (buf != NULL);
454 cbuf = buf; 445 cbuf = buf;
455 do 446 do
456 { 447 {
457 hdr.header.size = htons (s); 448 hdr.header.size = htons (s);
458 hdr.header.type = htons (MTYPE); 449 hdr.header.type = htons (MTYPE);
459 hdr.num = htonl (n); 450 hdr.num = htonl (n);
460 msg_sent = n; 451 msg_sent = n;
461 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage)); 452 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
462 ret += sizeof (struct TestMessage); 453 ret += sizeof (struct TestMessage);
463 memset (&cbuf[ret], n, s - sizeof (struct TestMessage)); 454 memset (&cbuf[ret], n, s - sizeof (struct TestMessage));
464 ret += s - sizeof (struct TestMessage); 455 ret += s - sizeof (struct TestMessage);
465#if VERBOSE 456#if VERBOSE
466 if (n % 5000 == 0) 457 if (n % 5000 == 0)
467 { 458 {
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 459 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "Sending message %u of size %u\n", 460 "Sending message %u of size %u\n", n, s);
470 n,
471 s);
472 }
473#endif
474 n++;
475 s = get_size (n);
476 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
477 break; /* sometimes pack buffer full, sometimes not */
478 } 461 }
462#endif
463 n++;
464 s = get_size (n);
465 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
466 break; /* sometimes pack buffer full, sometimes not */
467 }
479 while (size - ret >= s); 468 while (size - ret >= s);
480 if (n < TOTAL_MSGS) 469 if (n < TOTAL_MSGS)
481 { 470 {
482 th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th, 471 th_p2 = GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
483 &p1.id, 472 &p1.id,
484 s, 0, TIMEOUT, 473 s, 0, TIMEOUT,
485 &notify_ready, 474 &notify_ready, NULL);
486 NULL);
487 msg_scheduled = n; 475 msg_scheduled = n;
488 } 476 }
489 else 477 else
490 { 478 {
491 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "All messages scheduled to be sent!!\n"); 479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
492 if (GNUNET_SCHEDULER_NO_TASK != die_task) 480 "All messages scheduled to be sent!!\n");
493 GNUNET_SCHEDULER_cancel(die_task); 481 if (GNUNET_SCHEDULER_NO_TASK != die_task)
494 die_task = GNUNET_SCHEDULER_add_delayed (UNRELIABLE_TIMEOUT, &end_unreliably, NULL); 482 GNUNET_SCHEDULER_cancel (die_task);
495 } 483 die_task =
484 GNUNET_SCHEDULER_add_delayed (UNRELIABLE_TIMEOUT, &end_unreliably,
485 NULL);
486 }
496 if (n % 5000 == 0) 487 if (n % 5000 == 0)
497 { 488 {
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
499 "Returning total message block of size %u\n", 490 "Returning total message block of size %u\n", ret);
500 ret); 491 }
501 }
502 total_bytes += ret; 492 total_bytes += ret;
503 return ret; 493 return ret;
504} 494}
@@ -511,14 +501,13 @@ notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
511 connected--; 501 connected--;
512#if VERBOSE 502#if VERBOSE
513 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
514 "Peer `%4s' disconnected (%p)!\n", 504 "Peer `%4s' disconnected (%p)!\n", GNUNET_i2s (peer), cls);
515 GNUNET_i2s (peer), cls);
516#endif 505#endif
517 if (th_p2 != NULL) 506 if (th_p2 != NULL)
518 { 507 {
519 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2); 508 GNUNET_TRANSPORT_notify_transmit_ready_cancel (th_p2);
520 th_p2 = NULL; 509 th_p2 = NULL;
521 } 510 }
522} 511}
523 512
524 513
@@ -530,57 +519,57 @@ notify_connect (void *cls,
530 uint32_t ats_count) 519 uint32_t ats_count)
531{ 520{
532 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
533 "Peer `%4s' connected to us (%p)!\n", 522 "Peer `%4s' connected to us (%p)!\n", GNUNET_i2s (peer), cls);
534 GNUNET_i2s (peer),
535 cls);
536 if (cls == &p1) 523 if (cls == &p1)
524 {
525 GNUNET_TRANSPORT_set_quota (p1.th,
526 &p2.id,
527 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
528 1024),
529 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
530 1024));
531 start_time = GNUNET_TIME_absolute_get ();
532 connected++;
533 }
534 else
535 {
536 GNUNET_TRANSPORT_set_quota (p2.th,
537 &p1.id,
538 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
539 1024),
540 GNUNET_BANDWIDTH_value_init (1024 * 1024 *
541 1024));
542 connected++;
543 }
544 if (2 == connected)
545 {
546 if (GNUNET_SCHEDULER_NO_TASK != die_task)
537 { 547 {
538 GNUNET_TRANSPORT_set_quota (p1.th, 548 GNUNET_SCHEDULER_cancel (die_task);
539 &p2.id,
540 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024),
541 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024));
542 start_time = GNUNET_TIME_absolute_get ();
543 connected++;
544 } 549 }
545 else 550 if (GNUNET_SCHEDULER_NO_TASK != tct)
546 { 551 {
547 GNUNET_TRANSPORT_set_quota (p2.th, 552 GNUNET_SCHEDULER_cancel (tct);
548 &p1.id, 553 tct = GNUNET_SCHEDULER_NO_TASK;
549 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024),
550 GNUNET_BANDWIDTH_value_init (1024 * 1024 * 1024));
551 connected++;
552 } 554 }
553 if (2 == connected) 555 if (p2_hello_canceled == GNUNET_NO)
554 { 556 {
555 if (GNUNET_SCHEDULER_NO_TASK != die_task) 557 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
556 { 558 p2_hello_canceled = GNUNET_YES;
557 GNUNET_SCHEDULER_cancel (die_task);
558 }
559 if (GNUNET_SCHEDULER_NO_TASK != tct)
560 {
561 GNUNET_SCHEDULER_cancel (tct);
562 tct = GNUNET_SCHEDULER_NO_TASK;
563 }
564 if (p2_hello_canceled == GNUNET_NO)
565 {
566 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_last, &p2);
567 p2_hello_canceled = GNUNET_YES;
568 }
569 if (p1_hello_canceled == GNUNET_NO)
570 {
571 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
572 p1_hello_canceled = GNUNET_YES;
573 }
574
575 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
576 &end_badly, NULL);
577 GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
578 &p1.id,
579 get_size (0), 0, TIMEOUT,
580 &notify_ready,
581 NULL);
582
583 } 559 }
560 if (p1_hello_canceled == GNUNET_NO)
561 {
562 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, &p1);
563 p1_hello_canceled = GNUNET_YES;
564 }
565
566 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
567 GNUNET_TRANSPORT_notify_transmit_ready (p2.th,
568 &p1.id,
569 get_size (0), 0, TIMEOUT,
570 &notify_ready, NULL);
571
572 }
584} 573}
585 574
586 575
@@ -591,31 +580,31 @@ setup_peer (struct PeerContext *p, const char *cfgname)
591 p->cfg = GNUNET_CONFIGURATION_create (); 580 p->cfg = GNUNET_CONFIGURATION_create ();
592 581
593 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 582 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
594 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 583 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
595 { 584 {
596 GNUNET_assert (GNUNET_OK == 585 GNUNET_assert (GNUNET_OK ==
597 GNUNET_CONFIGURATION_get_value_string (p->cfg, 586 GNUNET_CONFIGURATION_get_value_string (p->cfg,
598 "PATHS", "SERVICEHOME", 587 "PATHS",
599 &p->servicehome)); 588 "SERVICEHOME",
600 GNUNET_DISK_directory_remove (p->servicehome); 589 &p->servicehome));
601 } 590 GNUNET_DISK_directory_remove (p->servicehome);
591 }
602 592
603 593
604#if START_ARM 594#if START_ARM
605 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, 595 p->arm_proc = GNUNET_OS_start_process (NULL, NULL,
606 "gnunet-service-arm", 596 "gnunet-service-arm",
607 "gnunet-service-arm", 597 "gnunet-service-arm",
608#if VERBOSE_ARM 598#if VERBOSE_ARM
609 "-L", "DEBUG", 599 "-L", "DEBUG",
610#endif 600#endif
611 "-c", cfgname, NULL); 601 "-c", cfgname, NULL);
612#endif 602#endif
613 603
614 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, 604 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
615 p, 605 p,
616 &notify_receive, 606 &notify_receive,
617 &notify_connect, 607 &notify_connect, &notify_disconnect);
618 &notify_disconnect);
619 GNUNET_assert (p->th != NULL); 608 GNUNET_assert (p->th != NULL);
620} 609}
621 610
@@ -637,32 +626,32 @@ get_path_from_PATH (char *binary)
637 626
638 p = getenv ("PATH"); 627 p = getenv ("PATH");
639 if (p == NULL) 628 if (p == NULL)
640 { 629 {
641 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 630 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
642 _("PATH environment variable is unset.\n")); 631 _("PATH environment variable is unset.\n"));
643 return NULL; 632 return NULL;
644 } 633 }
645 path = GNUNET_strdup (p); /* because we write on it */ 634 path = GNUNET_strdup (p); /* because we write on it */
646 buf = GNUNET_malloc (strlen (path) + 20); 635 buf = GNUNET_malloc (strlen (path) + 20);
647 pos = path; 636 pos = path;
648 637
649 while (NULL != (end = strchr (pos, PATH_SEPARATOR))) 638 while (NULL != (end = strchr (pos, PATH_SEPARATOR)))
650 { 639 {
651 *end = '\0'; 640 *end = '\0';
652 sprintf (buf, "%s/%s", pos, binary); 641 sprintf (buf, "%s/%s", pos, binary);
653 if (GNUNET_DISK_file_test (buf) == GNUNET_YES) 642 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
654 {
655 GNUNET_free (path);
656 return buf;
657 }
658 pos = end + 1;
659 }
660 sprintf (buf, "%s/%s", pos, binary);
661 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
662 { 643 {
663 GNUNET_free (path); 644 GNUNET_free (path);
664 return buf; 645 return buf;
665 } 646 }
647 pos = end + 1;
648 }
649 sprintf (buf, "%s/%s", pos, binary);
650 if (GNUNET_DISK_file_test (buf) == GNUNET_YES)
651 {
652 GNUNET_free (path);
653 return buf;
654 }
666 GNUNET_free (buf); 655 GNUNET_free (buf);
667 GNUNET_free (path); 656 GNUNET_free (path);
668 return NULL; 657 return NULL;
@@ -679,16 +668,18 @@ get_path_from_PATH (char *binary)
679 * can be run properly, GNUNET_NO otherwise 668 * can be run properly, GNUNET_NO otherwise
680 */ 669 */
681static int 670static int
682check_gnunet_nat_binary(char *binary) 671check_gnunet_nat_binary (char *binary)
683{ 672{
684 struct stat statbuf; 673 struct stat statbuf;
685 char *p; 674 char *p;
675
686#ifdef MINGW 676#ifdef MINGW
687 SOCKET rawsock; 677 SOCKET rawsock;
688#endif 678#endif
689 679
690#ifdef MINGW 680#ifdef MINGW
691 char *binaryexe; 681 char *binaryexe;
682
692 GNUNET_asprintf (&binaryexe, "%s.exe", binary); 683 GNUNET_asprintf (&binaryexe, "%s.exe", binary);
693 p = get_path_from_PATH (binaryexe); 684 p = get_path_from_PATH (binaryexe);
694 free (binaryexe); 685 free (binaryexe);
@@ -696,36 +687,34 @@ check_gnunet_nat_binary(char *binary)
696 p = get_path_from_PATH (binary); 687 p = get_path_from_PATH (binary);
697#endif 688#endif
698 if (p == NULL) 689 if (p == NULL)
699 { 690 {
700 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 691 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
701 _("Could not find binary `%s' in PATH!\n"), 692 _("Could not find binary `%s' in PATH!\n"), binary);
702 binary); 693 return GNUNET_NO;
703 return GNUNET_NO; 694 }
704 }
705 if (0 != STAT (p, &statbuf)) 695 if (0 != STAT (p, &statbuf))
706 { 696 {
707 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 697 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
708 _("stat (%s) failed: %s\n"), 698 _("stat (%s) failed: %s\n"), p, STRERROR (errno));
709 p, 699 GNUNET_free (p);
710 STRERROR (errno)); 700 return GNUNET_SYSERR;
711 GNUNET_free (p); 701 }
712 return GNUNET_SYSERR;
713 }
714 GNUNET_free (p); 702 GNUNET_free (p);
715#ifndef MINGW 703#ifndef MINGW
716 if ( (0 != (statbuf.st_mode & S_ISUID)) && 704 if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0))
717 (statbuf.st_uid == 0) )
718 return GNUNET_YES; 705 return GNUNET_YES;
719 return GNUNET_NO; 706 return GNUNET_NO;
720#else 707#else
721 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); 708 rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP);
722 if (INVALID_SOCKET == rawsock) 709 if (INVALID_SOCKET == rawsock)
723 { 710 {
724 DWORD err = GetLastError (); 711 DWORD err = GetLastError ();
725 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 712
726 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n", err); 713 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
727 return GNUNET_NO; /* not running as administrator */ 714 "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) have failed! GLE = %d\n",
728 } 715 err);
716 return GNUNET_NO; /* not running as administrator */
717 }
729 closesocket (rawsock); 718 closesocket (rawsock);
730 return GNUNET_YES; 719 return GNUNET_YES;
731#endif 720#endif
@@ -733,18 +722,13 @@ check_gnunet_nat_binary(char *binary)
733 722
734 723
735static void 724static void
736try_connect (void *cls, 725try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
737 const struct GNUNET_SCHEDULER_TaskContext *tc)
738{ 726{
739 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
740 "Asking peers to connect...\n"); 728 GNUNET_TRANSPORT_try_connect (p2.th, &p1.id);
741 GNUNET_TRANSPORT_try_connect (p2.th, 729 GNUNET_TRANSPORT_try_connect (p1.th, &p2.id);
742 &p1.id);
743 GNUNET_TRANSPORT_try_connect (p1.th,
744 &p2.id);
745 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 730 tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
746 &try_connect, 731 &try_connect, NULL);
747 NULL);
748} 732}
749 733
750 734
@@ -754,48 +738,46 @@ run (void *cls,
754 char *const *args, 738 char *const *args,
755 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 739 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
756{ 740{
757 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 741 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
758 &end_badly,
759 NULL);
760 if (is_tcp) 742 if (is_tcp)
761 { 743 {
762 setup_peer (&p1, "test_transport_api_tcp_peer1.conf"); 744 setup_peer (&p1, "test_transport_api_tcp_peer1.conf");
763 setup_peer (&p2, "test_transport_api_tcp_peer2.conf"); 745 setup_peer (&p2, "test_transport_api_tcp_peer2.conf");
764 } 746 }
765 else if (is_http) 747 else if (is_http)
766 { 748 {
767 setup_peer (&p1, "test_transport_api_rel_http_peer1.conf"); 749 setup_peer (&p1, "test_transport_api_rel_http_peer1.conf");
768 setup_peer (&p2, "test_transport_api_rel_http_peer2.conf"); 750 setup_peer (&p2, "test_transport_api_rel_http_peer2.conf");
769 } 751 }
770 else if (is_https) 752 else if (is_https)
771 { 753 {
772 setup_peer (&p1, "test_transport_api_rel_https_peer1.conf"); 754 setup_peer (&p1, "test_transport_api_rel_https_peer1.conf");
773 setup_peer (&p2, "test_transport_api_rel_https_peer2.conf"); 755 setup_peer (&p2, "test_transport_api_rel_https_peer2.conf");
774 } 756 }
775 else if (is_udp) 757 else if (is_udp)
776 { 758 {
777 setup_peer (&p1, "test_transport_api_udp_peer1.conf"); 759 setup_peer (&p1, "test_transport_api_udp_peer1.conf");
778 setup_peer (&p2, "test_transport_api_udp_peer2.conf"); 760 setup_peer (&p2, "test_transport_api_udp_peer2.conf");
779 } 761 }
780 else if (is_unix) 762 else if (is_unix)
781 { 763 {
782 setup_peer (&p1, "test_transport_api_unix_peer1.conf"); 764 setup_peer (&p1, "test_transport_api_unix_peer1.conf");
783 setup_peer (&p2, "test_transport_api_unix_peer2.conf"); 765 setup_peer (&p2, "test_transport_api_unix_peer2.conf");
784 } 766 }
785 else if (is_tcp_nat) 767 else if (is_tcp_nat)
786 { 768 {
787 setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf"); 769 setup_peer (&p1, "test_transport_api_tcp_nat_peer1.conf");
788 setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf"); 770 setup_peer (&p2, "test_transport_api_tcp_nat_peer2.conf");
789 } 771 }
790 else if (is_wlan) 772 else if (is_wlan)
791 { 773 {
792 setup_peer (&p1, "test_transport_api_wlan_peer1.conf"); 774 setup_peer (&p1, "test_transport_api_wlan_peer1.conf");
793 setup_peer (&p2, "test_transport_api_wlan_peer2.conf"); 775 setup_peer (&p2, "test_transport_api_wlan_peer2.conf");
794 } 776 }
795 else 777 else
796 GNUNET_assert (0); 778 GNUNET_assert (0);
797 GNUNET_assert(p1.th != NULL); 779 GNUNET_assert (p1.th != NULL);
798 GNUNET_assert(p2.th != NULL); 780 GNUNET_assert (p2.th != NULL);
799 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 781 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
800 p1_hello_canceled = GNUNET_NO; 782 p1_hello_canceled = GNUNET_NO;
801 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); 783 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2);
@@ -820,15 +802,17 @@ check ()
820 }; 802 };
821 803
822#if WRITECONFIG 804#if WRITECONFIG
823 setTransportOptions("test_transport_api_data.conf"); 805 setTransportOptions ("test_transport_api_data.conf");
824#endif 806#endif
825 ok = 1; 807 ok = 1;
826 808
827 if ((GNUNET_YES == is_tcp_nat) && (check_gnunet_nat_binary("gnunet-nat-server") != GNUNET_YES)) 809 if ((GNUNET_YES == is_tcp_nat) &&
828 { 810 (check_gnunet_nat_binary ("gnunet-nat-server") != GNUNET_YES))
829 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Not running NAT test case, binaries not properly installed.\n"); 811 {
830 return 0; 812 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
831 } 813 "Not running NAT test case, binaries not properly installed.\n");
814 return 0;
815 }
832 816
833 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 817 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
834 argv, "test-transport-api-unreliability", "nohelp", 818 argv, "test-transport-api-unreliability", "nohelp",
@@ -839,53 +823,66 @@ check ()
839 if (is_https) 823 if (is_https)
840 { 824 {
841 struct stat sbuf; 825 struct stat sbuf;
842 if (0 == stat (cert_file_p1, &sbuf )) 826
827 if (0 == stat (cert_file_p1, &sbuf))
843 { 828 {
844 if (0 == remove(cert_file_p1)) 829 if (0 == remove (cert_file_p1))
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p1); 830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
831 "Successfully removed existing certificate file `%s'\n",
832 cert_file_p1);
846 else 833 else
847 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p1); 834 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",
835 cert_file_p1);
848 } 836 }
849 837
850 if (0 == stat (key_file_p1, &sbuf )) 838 if (0 == stat (key_file_p1, &sbuf))
851 { 839 {
852 if (0 == remove(key_file_p1)) 840 if (0 == remove (key_file_p1))
853 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p1); 841 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
842 "Successfully removed private key file `%s'\n",
843 key_file_p1);
854 else 844 else
855 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p1); 845 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
846 "Failed to private key file `%s'\n", key_file_p1);
856 } 847 }
857 848
858 if (0 == stat (cert_file_p2, &sbuf )) 849 if (0 == stat (cert_file_p2, &sbuf))
859 { 850 {
860 if (0 == remove(cert_file_p2)) 851 if (0 == remove (cert_file_p2))
861 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed existing certificate file `%s'\n",cert_file_p2); 852 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
853 "Successfully removed existing certificate file `%s'\n",
854 cert_file_p2);
862 else 855 else
863 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",cert_file_p2); 856 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to remove certfile `%s'\n",
857 cert_file_p2);
864 } 858 }
865 859
866 if (0 == stat (key_file_p2, &sbuf )) 860 if (0 == stat (key_file_p2, &sbuf))
867 { 861 {
868 if (0 == remove(key_file_p2)) 862 if (0 == remove (key_file_p2))
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Successfully removed private key file `%s'\n",key_file_p2); 863 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
864 "Successfully removed private key file `%s'\n",
865 key_file_p2);
870 else 866 else
871 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to private key file `%s'\n",key_file_p2); 867 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
868 "Failed to private key file `%s'\n", key_file_p2);
872 } 869 }
873 GNUNET_free(key_file_p1); 870 GNUNET_free (key_file_p1);
874 GNUNET_free(key_file_p2); 871 GNUNET_free (key_file_p2);
875 GNUNET_free(cert_file_p1); 872 GNUNET_free (cert_file_p1);
876 GNUNET_free(cert_file_p2); 873 GNUNET_free (cert_file_p2);
877 } 874 }
878 875
879 if (p1.servicehome != NULL) 876 if (p1.servicehome != NULL)
880 { 877 {
881 GNUNET_DISK_directory_remove (p1.servicehome); 878 GNUNET_DISK_directory_remove (p1.servicehome);
882 GNUNET_free(p1.servicehome); 879 GNUNET_free (p1.servicehome);
883 } 880 }
884 if (p2.servicehome != NULL) 881 if (p2.servicehome != NULL)
885 { 882 {
886 GNUNET_DISK_directory_remove (p2.servicehome); 883 GNUNET_DISK_directory_remove (p2.servicehome);
887 GNUNET_free(p2.servicehome); 884 GNUNET_free (p2.servicehome);
888 } 885 }
889 return ok; 886 return ok;
890} 887}
891 888
@@ -900,40 +897,40 @@ main (int argc, char *argv[])
900 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1"); 897 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
901 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2"); 898 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
902 899
903 if (strstr(argv[0], "tcp_nat") != NULL) 900 if (strstr (argv[0], "tcp_nat") != NULL)
904 { 901 {
905 is_tcp_nat = GNUNET_YES; 902 is_tcp_nat = GNUNET_YES;
906 GNUNET_asprintf(&test_name, "tcp_nat"); 903 GNUNET_asprintf (&test_name, "tcp_nat");
907 } 904 }
908 else if (strstr(argv[0], "tcp") != NULL) 905 else if (strstr (argv[0], "tcp") != NULL)
909 { 906 {
910 is_tcp = GNUNET_YES; 907 is_tcp = GNUNET_YES;
911 GNUNET_asprintf(&test_name, "tcp"); 908 GNUNET_asprintf (&test_name, "tcp");
912 } 909 }
913 else if (strstr(argv[0], "https") != NULL) 910 else if (strstr (argv[0], "https") != NULL)
914 { 911 {
915 is_https = GNUNET_YES; 912 is_https = GNUNET_YES;
916 GNUNET_asprintf(&test_name, "https"); 913 GNUNET_asprintf (&test_name, "https");
917 } 914 }
918 else if (strstr(argv[0], "http") != NULL) 915 else if (strstr (argv[0], "http") != NULL)
919 { 916 {
920 is_http = GNUNET_YES; 917 is_http = GNUNET_YES;
921 GNUNET_asprintf(&test_name, "http"); 918 GNUNET_asprintf (&test_name, "http");
922 } 919 }
923 else if (strstr(argv[0], "udp") != NULL) 920 else if (strstr (argv[0], "udp") != NULL)
924 { 921 {
925 is_udp = GNUNET_YES; 922 is_udp = GNUNET_YES;
926 GNUNET_asprintf(&test_name, "udp"); 923 GNUNET_asprintf (&test_name, "udp");
927 } 924 }
928 else if (strstr(argv[0], "unix") != NULL) 925 else if (strstr (argv[0], "unix") != NULL)
929 { 926 {
930 is_unix = GNUNET_YES; 927 is_unix = GNUNET_YES;
931 GNUNET_asprintf(&test_name, "unix"); 928 GNUNET_asprintf (&test_name, "unix");
932 } 929 }
933 else if (strstr(argv[0], "wlan") != NULL) 930 else if (strstr (argv[0], "wlan") != NULL)
934 { 931 {
935 is_wlan = GNUNET_YES; 932 is_wlan = GNUNET_YES;
936 } 933 }
937 GNUNET_log_setup ("test-transport-api-unreliability", 934 GNUNET_log_setup ("test-transport-api-unreliability",
938#if VERBOSE 935#if VERBOSE
939 "DEBUG", 936 "DEBUG",
@@ -943,7 +940,7 @@ main (int argc, char *argv[])
943 NULL); 940 NULL);
944 ret = check (); 941 ret = check ();
945 942
946 GNUNET_free_non_null(test_name); 943 GNUNET_free_non_null (test_name);
947 return ret; 944 return ret;
948} 945}
949 946
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c
index bf7bc0fe5..d9e4b23d5 100644
--- a/src/transport/test_transport_ats.c
+++ b/src/transport/test_transport_ats.c
@@ -28,18 +28,17 @@
28 28
29#define VERBOSE GNUNET_YES 29#define VERBOSE GNUNET_YES
30 30
31static struct ATS_Handle * ats; 31static struct ATS_Handle *ats;
32 32
33static struct GNUNET_CONFIGURATION_Handle * cfg; 33static struct GNUNET_CONFIGURATION_Handle *cfg;
34 34
35static struct TransportConfiguration *tc; 35static struct TransportConfiguration *tc;
36 36
37 37
38static void 38static void
39ats_result_cb () 39ats_result_cb ()
40{ 40{
41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 41 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n");
42 "ATS Result callback\n");
43} 42}
44 43
45struct TransportConfiguration 44struct TransportConfiguration
@@ -47,35 +46,35 @@ struct TransportConfiguration
47 int peers; 46 int peers;
48 int mechanisms; 47 int mechanisms;
49 48
50 struct ATS_peer * p_head; 49 struct ATS_peer *p_head;
51 struct ATS_peer * p_tail; 50 struct ATS_peer *p_tail;
52 51
53 struct ATS_mechanism * m_head; 52 struct ATS_mechanism *m_head;
54 struct ATS_mechanism * m_tail; 53 struct ATS_mechanism *m_tail;
55}; 54};
56 55
57 56
58static void 57static void
59create_ats_information (struct ATS_peer **p, int * c_p, 58create_ats_information (struct ATS_peer **p, int *c_p,
60 struct ATS_mechanism ** m, int * c_m) 59 struct ATS_mechanism **m, int *c_m)
61{ 60{
62 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n");
63 "ATS needs addresses\n");
64 62
65 (*p) = tc->p_head; 63 (*p) = tc->p_head;
66 (*c_p) = tc->mechanisms; 64 (*c_p) = tc->mechanisms;
67 (*m) = tc->m_head; 65 (*m) = tc->m_head;
68 (*c_m) = tc->mechanisms; 66 (*c_m) = tc->mechanisms;
69} 67}
70 68
71 69
72static 70static int
73int run_ats () 71run_ats ()
74{ 72{
75 int ret = 0; 73 int ret = 0;
74
76 ats_calculate_bandwidth_distribution (ats); 75 ats_calculate_bandwidth_distribution (ats);
77 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
78 "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); 77 "Running ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED");
79 return ret; 78 return ret;
80} 79}
81 80
@@ -84,96 +83,96 @@ static int
84init_ats () 83init_ats ()
85{ 84{
86 int ret = 0; 85 int ret = 0;
87 ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, 86
88 create_ats_information, 87 ats = ats_init (1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION,
89 ats_result_cb); 88 create_ats_information, ats_result_cb);
90 //GNUNET_assert (ats != NULL); 89 //GNUNET_assert (ats != NULL);
91 90
92 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 91 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
93 "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); 92 "Initializing ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED");
94 return ret; 93 return ret;
95} 94}
96 95
97 96
98static int 97static int
99shutdown_ats () 98shutdown_ats ()
100{ 99{
101 int ret = 0; 100 int ret = 0;
101
102 ats_delete_problem (ats); 102 ats_delete_problem (ats);
103 ats_shutdown (ats); 103 ats_shutdown (ats);
104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 104 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
105 "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); 105 "Shutdown ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED");
106 return ret; 106 return ret;
107} 107}
108 108
109 109
110/* To make compiler happy */ 110/* To make compiler happy */
111void 111void
112dummy() 112dummy ()
113{ 113{
114 struct ATS_quality_metric * q = qm; 114 struct ATS_quality_metric *q = qm;
115
115 q = NULL; 116 q = NULL;
116 struct ATS_ressource * r = ressources; 117 struct ATS_ressource *r = ressources;
118
117 r = NULL; 119 r = NULL;
118 q++; 120 q++;
119 r++; 121 r++;
120} 122}
121 123
122 124
123static void 125static void
124iterate_peer_values (void *cls, 126iterate_peer_values (void *cls,
125 const char *section, 127 const char *section, const char *option, const char *value)
126 const char *option,
127 const char *value)
128{ 128{
129 if (strcmp (option, "f") == 0) 129 if (strcmp (option, "f") == 0)
130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 130 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
131 "\t %s %s\n", option, value);
132} 131}
133 132
134static void 133static void
135iterate_mech_values (void *cls, 134iterate_mech_values (void *cls,
136 const char *section, 135 const char *section, const char *option, const char *value)
137 const char *option,
138 const char *value)
139{ 136{
140 if (strcmp (option, "f") == 0) 137 if (strcmp (option, "f") == 0)
141 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 138 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value);
142 "\t %s %s\n", option, value);
143} 139}
144 140
145static void 141static void
146iterate_sections (void *cls, 142iterate_sections (void *cls, const char *section)
147 const char *section)
148{ 143{
149 struct TransportConfiguration * tc = cls; 144 struct TransportConfiguration *tc = cls;
145
150 /* Peer definition */ 146 /* Peer definition */
151 if (99 == strlen(section)) 147 if (99 == strlen (section))
152 { 148 {
153 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section); 149 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
154 GNUNET_HashCode h; 150 GNUNET_HashCode h;
155 int res =GNUNET_CRYPTO_hash_from_string(section, &h); 151 int res = GNUNET_CRYPTO_hash_from_string (section, &h);
156 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res); 152
157 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_peer_values, NULL); 153 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res);
158 tc->peers++; 154 GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
159 } 155 iterate_peer_values, NULL);
160 if (10 == strlen(section)) 156 tc->peers++;
161 { 157 }
162 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section); 158 if (10 == strlen (section))
163 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_mech_values, NULL); 159 {
164 tc->peers++; 160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n", section);
165 } 161 GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
162 iterate_mech_values, NULL);
163 tc->peers++;
164 }
166} 165}
167 166
168 167
169static struct TransportConfiguration * 168static struct TransportConfiguration *
170load_transport_configuration (char * filename) 169load_transport_configuration (char *filename)
171{ 170{
172 struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration)); 171 struct TransportConfiguration *ret =
172 GNUNET_malloc (sizeof (struct TransportConfiguration));
173 173
174 cfg = GNUNET_CONFIGURATION_create(); 174 cfg = GNUNET_CONFIGURATION_create ();
175 GNUNET_assert (GNUNET_OK == 175 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, filename));
176 GNUNET_CONFIGURATION_load(cfg, filename));
177 GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret); 176 GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret);
178 GNUNET_CONFIGURATION_destroy (cfg); 177 GNUNET_CONFIGURATION_destroy (cfg);
179 cfg = NULL; 178 cfg = NULL;
diff --git a/src/transport/test_transport_ats_multiple_peers.c b/src/transport/test_transport_ats_multiple_peers.c
index 9d30a061d..d060a4d4b 100644
--- a/src/transport/test_transport_ats_multiple_peers.c
+++ b/src/transport/test_transport_ats_multiple_peers.c
@@ -46,17 +46,17 @@ static int peers_left;
46static int failed_peers; 46static int failed_peers;
47 47
48static int measurement_started = GNUNET_NO; 48static int measurement_started = GNUNET_NO;
49static char * config_file; 49static char *config_file;
50 50
51static struct GNUNET_TESTING_PeerGroup *pg; 51static struct GNUNET_TESTING_PeerGroup *pg;
52 52
53static GNUNET_SCHEDULER_TaskIdentifier shutdown_task; 53static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
54static GNUNET_SCHEDULER_TaskIdentifier stats_task; 54static GNUNET_SCHEDULER_TaskIdentifier stats_task;
55static GNUNET_SCHEDULER_TaskIdentifier send_task; 55static GNUNET_SCHEDULER_TaskIdentifier send_task;
56struct GNUNET_TESTING_Daemon * master_deamon; 56struct GNUNET_TESTING_Daemon *master_deamon;
57struct GNUNET_TESTING_Daemon * ping_deamon; 57struct GNUNET_TESTING_Daemon *ping_deamon;
58 58
59struct GNUNET_STATISTICS_Handle * stats; 59struct GNUNET_STATISTICS_Handle *stats;
60 60
61struct TEST_result 61struct TEST_result
62{ 62{
@@ -87,21 +87,21 @@ static int force_rebuild;
87static int send_msg; 87static int send_msg;
88static int machine_parsable; 88static int machine_parsable;
89 89
90static struct TEST_result results_new [MEASUREMENTS+1]; 90static struct TEST_result results_new[MEASUREMENTS + 1];
91static struct TEST_result results_modified [MEASUREMENTS+1]; 91static struct TEST_result results_modified[MEASUREMENTS + 1];
92static struct TEST_result results_unmodified[MEASUREMENTS+1]; 92static struct TEST_result results_unmodified[MEASUREMENTS + 1];
93static struct TEST_result current; 93static struct TEST_result current;
94 94
95static struct GNUNET_STATISTICS_GetHandle * s_solution; 95static struct GNUNET_STATISTICS_GetHandle *s_solution;
96static struct GNUNET_STATISTICS_GetHandle * s_time; 96static struct GNUNET_STATISTICS_GetHandle *s_time;
97static struct GNUNET_STATISTICS_GetHandle * s_peers; 97static struct GNUNET_STATISTICS_GetHandle *s_peers;
98static struct GNUNET_STATISTICS_GetHandle * s_mechs; 98static struct GNUNET_STATISTICS_GetHandle *s_mechs;
99static struct GNUNET_STATISTICS_GetHandle * s_duration; 99static struct GNUNET_STATISTICS_GetHandle *s_duration;
100static struct GNUNET_STATISTICS_GetHandle * s_invalid; 100static struct GNUNET_STATISTICS_GetHandle *s_invalid;
101static struct GNUNET_STATISTICS_GetHandle * s_state; 101static struct GNUNET_STATISTICS_GetHandle *s_state;
102 102
103struct GNUNET_TRANSPORT_TransmitHandle * t; 103struct GNUNET_TRANSPORT_TransmitHandle *t;
104struct GNUNET_TRANSPORT_Handle * th; 104struct GNUNET_TRANSPORT_Handle *th;
105 105
106/** 106/**
107 * Check whether peers successfully shut down. 107 * Check whether peers successfully shut down.
@@ -110,463 +110,459 @@ static void
110shutdown_callback (void *cls, const char *emsg) 110shutdown_callback (void *cls, const char *emsg)
111{ 111{
112 if (emsg != NULL) 112 if (emsg != NULL)
113 { 113 {
114#if VERBOSE 114#if VERBOSE
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown of peers failed!\n");
116 "Shutdown of peers failed!\n");
117#endif 116#endif
118 if (ok == 0) 117 if (ok == 0)
119 ok = 666; 118 ok = 666;
120 } 119 }
121 else 120 else
122 { 121 {
123#if VERBOSE 122#if VERBOSE
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers successfully shut down!\n");
125 "All peers successfully shut down!\n"); 124 if (stats != NULL)
126 if (stats != NULL) 125 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
127 GNUNET_STATISTICS_destroy(stats, GNUNET_NO); 126 stats = NULL;
128 stats = NULL;
129#endif 127#endif
130 } 128 }
131} 129}
132 130
133static void 131static void
134shutdown_peers() 132shutdown_peers ()
135{ 133{
136 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK) 134 if (shutdown_task != GNUNET_SCHEDULER_NO_TASK)
137 { 135 {
138 GNUNET_SCHEDULER_cancel(shutdown_task); 136 GNUNET_SCHEDULER_cancel (shutdown_task);
139 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 137 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
140 } 138 }
141 if (stats_task != GNUNET_SCHEDULER_NO_TASK) 139 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
142 { 140 {
143 GNUNET_SCHEDULER_cancel(stats_task); 141 GNUNET_SCHEDULER_cancel (stats_task);
144 stats_task = GNUNET_SCHEDULER_NO_TASK; 142 stats_task = GNUNET_SCHEDULER_NO_TASK;
145 } 143 }
146 if (send_task != GNUNET_SCHEDULER_NO_TASK) 144 if (send_task != GNUNET_SCHEDULER_NO_TASK)
147 { 145 {
148 GNUNET_SCHEDULER_cancel(send_task); 146 GNUNET_SCHEDULER_cancel (send_task);
149 send_task = GNUNET_SCHEDULER_NO_TASK; 147 send_task = GNUNET_SCHEDULER_NO_TASK;
150 } 148 }
151 149
152 if (t != NULL) 150 if (t != NULL)
153 { 151 {
154 GNUNET_TRANSPORT_notify_transmit_ready_cancel(t); 152 GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
155 t = NULL; 153 t = NULL;
156 } 154 }
157 GNUNET_TRANSPORT_disconnect(th); 155 GNUNET_TRANSPORT_disconnect (th);
158 if (s_time != NULL) 156 if (s_time != NULL)
159 { 157 {
160 GNUNET_STATISTICS_get_cancel(s_time); 158 GNUNET_STATISTICS_get_cancel (s_time);
161 s_time = NULL; 159 s_time = NULL;
162 } 160 }
163 if (s_peers != NULL) 161 if (s_peers != NULL)
164 { 162 {
165 GNUNET_STATISTICS_get_cancel(s_peers); 163 GNUNET_STATISTICS_get_cancel (s_peers);
166 s_peers = NULL; 164 s_peers = NULL;
167 } 165 }
168 if (s_mechs != NULL) 166 if (s_mechs != NULL)
169 { 167 {
170 GNUNET_STATISTICS_get_cancel(s_mechs); 168 GNUNET_STATISTICS_get_cancel (s_mechs);
171 s_mechs = NULL; 169 s_mechs = NULL;
172 } 170 }
173 if (s_solution != NULL) 171 if (s_solution != NULL)
174 { 172 {
175 GNUNET_STATISTICS_get_cancel(s_solution); 173 GNUNET_STATISTICS_get_cancel (s_solution);
176 s_solution = NULL; 174 s_solution = NULL;
177 } 175 }
178 if (s_duration != NULL) 176 if (s_duration != NULL)
179 { 177 {
180 GNUNET_STATISTICS_get_cancel(s_duration); 178 GNUNET_STATISTICS_get_cancel (s_duration);
181 s_duration = NULL; 179 s_duration = NULL;
182 } 180 }
183 if (s_invalid != NULL) 181 if (s_invalid != NULL)
184 { 182 {
185 GNUNET_STATISTICS_get_cancel(s_invalid); 183 GNUNET_STATISTICS_get_cancel (s_invalid);
186 s_invalid = NULL; 184 s_invalid = NULL;
187 } 185 }
188 if (s_state != NULL) 186 if (s_state != NULL)
189 { 187 {
190 GNUNET_STATISTICS_get_cancel(s_state); 188 GNUNET_STATISTICS_get_cancel (s_state);
191 s_state = NULL; 189 s_state = NULL;
192 } 190 }
193 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); 191 GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL);
194} 192}
195 193
196static void 194static void
197evaluate_measurements() 195evaluate_measurements ()
198{ 196{
199 int c; 197 int c;
198
200 //int mechs = 0; 199 //int mechs = 0;
201 double average[3]; 200 double average[3];
202 double stddev[3]; 201 double stddev[3];
202
203 //char * output; 203 //char * output;
204 c = 1; 204 c = 1;
205 205
206 //GNUNET_asprintf(&output, "p,%i,m,%i,",peers, MEASUREMENTS, results_modified[0].mechs, 206 //GNUNET_asprintf(&output, "p,%i,m,%i,",peers, MEASUREMENTS, results_modified[0].mechs,
207 207
208 average[0] = 0.0; 208 average[0] = 0.0;
209 for (c=0; c<c_new;c++) 209 for (c = 0; c < c_new; c++)
210 { 210 {
211 average[0] += (double) results_new[c].duration; 211 average[0] += (double) results_new[c].duration;
212 } 212 }
213 average[0] /= c_new; 213 average[0] /= c_new;
214 214
215 stddev[0] = 0.0; 215 stddev[0] = 0.0;
216 for (c=0; c<c_new;c++) 216 for (c = 0; c < c_new; c++)
217 { 217 {
218 stddev[0] += (results_new[c].duration - average[0]) * 218 stddev[0] += (results_new[c].duration - average[0]) *
219 (results_new[c].duration - average[0]); 219 (results_new[c].duration - average[0]);
220 } 220 }
221 stddev[0] /= c_new; 221 stddev[0] /= c_new;
222 stddev[0] = sqrt (stddev[0]); 222 stddev[0] = sqrt (stddev[0]);
223 if (!machine_parsable) 223 if (!machine_parsable)
224 fprintf (stderr, 224 fprintf (stderr,
225 "new, %i measurements, average: %f stddev: %f\n", 225 "new, %i measurements, average: %f stddev: %f\n",
226 c_new, average[0], stddev[0]); 226 c_new, average[0], stddev[0]);
227 227
228 average[1] = 0.0; 228 average[1] = 0.0;
229 for (c=0; c<c_modified;c++) 229 for (c = 0; c < c_modified; c++)
230 { 230 {
231 average[1] += (double) results_modified[c].duration; 231 average[1] += (double) results_modified[c].duration;
232 } 232 }
233 average[1] /= c_modified; 233 average[1] /= c_modified;
234 234
235 stddev[1] = 0.0; 235 stddev[1] = 0.0;
236 for (c=0; c<c_modified;c++) 236 for (c = 0; c < c_modified; c++)
237 { 237 {
238 stddev[1] += (results_modified[c].duration - average[1]) * 238 stddev[1] += (results_modified[c].duration - average[1]) *
239 (results_modified[c].duration - average[1]); 239 (results_modified[c].duration - average[1]);
240 } 240 }
241 stddev[1] /= c_modified; 241 stddev[1] /= c_modified;
242 stddev[1] = sqrt (stddev[1]); 242 stddev[1] = sqrt (stddev[1]);
243 if (!machine_parsable) 243 if (!machine_parsable)
244 fprintf (stderr, 244 fprintf (stderr,
245 "modified, %i measurements, average: %f stddev: %f\n", 245 "modified, %i measurements, average: %f stddev: %f\n",
246 c_modified, average[1], stddev[1]); 246 c_modified, average[1], stddev[1]);
247 247
248 average[2] = 0.0; 248 average[2] = 0.0;
249 for (c=0; c<c_unmodified;c++) 249 for (c = 0; c < c_unmodified; c++)
250 { 250 {
251 average[2] += (double) results_unmodified[c].duration; 251 average[2] += (double) results_unmodified[c].duration;
252 } 252 }
253 average[2] /= c_unmodified; 253 average[2] /= c_unmodified;
254 stddev[2] = 0.0; 254 stddev[2] = 0.0;
255 for (c=0; c<c_unmodified;c++) 255 for (c = 0; c < c_unmodified; c++)
256 { 256 {
257 stddev[2] += (results_unmodified[c].duration - average[2]) * 257 stddev[2] += (results_unmodified[c].duration - average[2]) *
258 (results_unmodified[c].duration - average[2]); 258 (results_unmodified[c].duration - average[2]);
259 } 259 }
260 stddev[2] /= c_unmodified; 260 stddev[2] /= c_unmodified;
261 stddev[2] = sqrt (stddev[2]); 261 stddev[2] = sqrt (stddev[2]);
262 262
263 if (!machine_parsable) 263 if (!machine_parsable)
264 fprintf (stderr, 264 fprintf (stderr,
265 "unmodified, %i measurements, average: %f stddev: %f\n", 265 "unmodified, %i measurements, average: %f stddev: %f\n",
266 c_unmodified, average[2], stddev[2]); 266 c_unmodified, average[2], stddev[2]);
267 267
268 if (machine_parsable) 268 if (machine_parsable)
269 fprintf (stderr, 269 fprintf (stderr,
270 "peers,%i,mechs,%llu," 270 "peers,%i,mechs,%llu,"
271 "new,%i,%f,%f," 271 "new,%i,%f,%f,"
272 "mod,%i,%f,%f," 272 "mod,%i,%f,%f,"
273 "unmod,%i,%f,%f\n", 273 "unmod,%i,%f,%f\n",
274 peers-1, (unsigned long long) results_unmodified[0].mechs, 274 peers - 1, (unsigned long long) results_unmodified[0].mechs,
275 c_new, average[0], stddev[0], 275 c_new, average[0], stddev[0],
276 c_modified, average[1], stddev[1], 276 c_modified, average[1], stddev[1],
277 c_unmodified, average[2], stddev[2]); 277 c_unmodified, average[2], stddev[2]);
278 shutdown_peers(); 278 shutdown_peers ();
279} 279}
280 280
281 281
282static int 282static int
283stats_cb (void *cls, 283stats_cb (void *cls,
284 const char *subsystem, 284 const char *subsystem,
285 const char *name, 285 const char *name, uint64_t value, int is_persistent)
286 uint64_t value,
287 int is_persistent)
288{ 286{
289 static int printed = GNUNET_NO; 287 static int printed = GNUNET_NO;
288
290#if VERBOSE_ATS 289#if VERBOSE_ATS
291 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s = %llu\n", name ,value); 290 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s = %llu\n", name, value);
292#endif 291#endif
293 if (0 == strcmp (name,"ATS invalid solutions")) 292 if (0 == strcmp (name, "ATS invalid solutions"))
294 { 293 {
295 if (stats_task != GNUNET_SCHEDULER_NO_TASK) 294 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
296 {
297 GNUNET_SCHEDULER_cancel(stats_task);
298 stats_task = GNUNET_SCHEDULER_NO_TASK;
299 }
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"MLP produced invalid %llu result(s)!\n",
301 value);
302 shutdown_peers();
303 return GNUNET_SYSERR;
304 }
305
306 if (0 == strcmp (name,"ATS solution"))
307 { 295 {
308 s_solution = NULL; 296 GNUNET_SCHEDULER_cancel (stats_task);
309 } 297 stats_task = GNUNET_SCHEDULER_NO_TASK;
310
311 if (0 == strcmp (name,"ATS peers"))
312 {
313 s_peers = NULL;
314 } 298 }
315 299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
316 if (0 == strcmp (name,"ATS mechanisms")) 300 "MLP produced invalid %llu result(s)!\n", value);
317 { 301 shutdown_peers ();
318 s_mechs = NULL; 302 return GNUNET_SYSERR;
303 }
304
305 if (0 == strcmp (name, "ATS solution"))
306 {
307 s_solution = NULL;
308 }
309
310 if (0 == strcmp (name, "ATS peers"))
311 {
312 s_peers = NULL;
313 }
314
315 if (0 == strcmp (name, "ATS mechanisms"))
316 {
317 s_mechs = NULL;
318 }
319
320 if (0 == strcmp (name, "ATS duration"))
321 {
322 s_duration = NULL;
323 }
324 if (0 == strcmp (name, "ATS timestamp"))
325 {
326 s_time = NULL;
327 }
328 if (0 == strcmp (name, "ATS state"))
329 {
330 s_state = NULL;
331 }
332
333 if ((measurement_started == GNUNET_NO) &&
334 (0 == strcmp (name, "ATS peers")) && (value == peers - 1))
335 {
336 measurement_started = GNUNET_YES;
337 count = 1;
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All %llu peers connected\n", value);
339#if !VERBOSE
340 if (!machine_parsable)
341 fprintf (stderr, "%i", count);
342#endif
343 }
344
345 if (measurement_started == GNUNET_YES)
346 {
347 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value);
348 if (0 == strcmp (name, "ATS timestamp"))
349 {
350 if (current.timestamp == 0)
351 {
352 printed = GNUNET_NO;
353 current.timestamp = value;
354 }
355 if (current.timestamp == value)
356 {
357 printed = GNUNET_YES;
358 }
359 if (current.timestamp != value)
360 {
361 if (current.state == ATS_NEW)
362 {
363 if (c_new < MEASUREMENTS)
364 {
365 results_new[c_new] = current;
366 c_new++;
367 }
368 else
369 {
370 force_rebuild = GNUNET_NO;
371 force_q_updates = GNUNET_NO;
372 send_msg = GNUNET_NO;
373 }
374 }
375 if (current.state == ATS_UNMODIFIED)
376 {
377 if (c_unmodified < MEASUREMENTS)
378 {
379 results_unmodified[c_unmodified] = current;
380 c_unmodified++;
381 }
382
383 }
384 if (current.state == ATS_QUALITY_UPDATED)
385 {
386 if (c_modified < MEASUREMENTS)
387 {
388 results_modified[c_modified] = current;
389 c_modified++;
390 }
391 else
392 {
393 force_q_updates = GNUNET_NO;
394 force_rebuild = GNUNET_YES;
395 }
396 }
397 count++;
398#if VERBOSE
399 fprintf (stderr,
400 "(new: %i / modified: %i / unmodified: %i) of %i \n",
401 c_new, c_modified, c_unmodified, MEASUREMENTS);
402#endif
403 if ((c_modified >= MEASUREMENTS) &&
404 (c_new >= MEASUREMENTS) && (c_unmodified >= MEASUREMENTS))
405 {
406#if !VERBOSE
407 if (!machine_parsable)
408 fprintf (stdout, "\n");
409#endif
410 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
411 {
412 GNUNET_SCHEDULER_cancel (stats_task);
413 stats_task = GNUNET_SCHEDULER_NO_TASK;
414 }
415 evaluate_measurements ();
416 return GNUNET_SYSERR;
417 }
418
419 printed = GNUNET_NO;
420 current.timestamp = value;
421#if !VERBOSE
422 if (!machine_parsable)
423 fprintf (stderr, "..%i", count);
424#endif
425 return GNUNET_OK;
426 }
319 } 427 }
320 428
321 if (0 == strcmp (name,"ATS duration")) 429 if (0 == strcmp (name, "ATS solution"))
322 { 430 {
323 s_duration = NULL; 431 current.solution = value;
432 if (printed == GNUNET_NO)
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
434 count, name, value);
324 } 435 }
325 if (0 == strcmp (name,"ATS timestamp")) 436
437 if (0 == strcmp (name, "ATS peers"))
326 { 438 {
327 s_time = NULL; 439 current.peers = value;
440 if (printed == GNUNET_NO)
441 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
442 count, name, value);
328 } 443 }
329 if (0 == strcmp (name,"ATS state")) 444
445 if (0 == strcmp (name, "ATS mechanisms"))
330 { 446 {
331 s_state = NULL; 447 current.mechs = value;
448 if (printed == GNUNET_NO)
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
450 count, name, value);
332 } 451 }
333 452
334 if ( (measurement_started == GNUNET_NO) && 453 if (0 == strcmp (name, "ATS duration"))
335 (0 == strcmp (name, "ATS peers")) &&
336 (value == peers-1) )
337 { 454 {
338 measurement_started = GNUNET_YES; 455 current.duration = value;
339 count = 1; 456 if (printed == GNUNET_NO)
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
341 "All %llu peers connected\n", 458 count, name, value);
342 value);
343#if !VERBOSE
344 if (! machine_parsable)
345 fprintf(stderr, "%i", count);
346#endif
347 } 459 }
348 460 if (0 == strcmp (name, "ATS state"))
349 if (measurement_started == GNUNET_YES)
350 { 461 {
351 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s == %llu\n", name ,value); 462 current.state = value;
352 if (0 == strcmp (name,"ATS timestamp")) 463 const char *cont;
353 { 464
354 if (current.timestamp == 0) 465 switch (value)
355 { 466 {
356 printed = GNUNET_NO; 467 case ATS_NEW:
357 current.timestamp = value; 468 cont = "NEW";
358 } 469 break;
359 if (current.timestamp == value) 470 case ATS_COST_UPDATED:
360 { 471 cont = "C_UPDATED";
361 printed = GNUNET_YES; 472 break;
362 } 473 case ATS_QUALITY_UPDATED:
363 if (current.timestamp != value) 474 cont = "Q_UPDATED";
364 { 475 break;
365 if (current.state == ATS_NEW) 476 case ATS_QUALITY_COST_UPDATED:
366 { 477 cont = "QC_UPDATED";
367 if (c_new < MEASUREMENTS) 478 break;
368 { 479 case ATS_UNMODIFIED:
369 results_new[c_new] = current; 480 cont = "UNMODIFIED";
370 c_new++; 481 break;
371 } 482 default:
372 else 483 GNUNET_break (0);
373 { 484 cont = "<undefined>";
374 force_rebuild = GNUNET_NO; 485 break;
375 force_q_updates = GNUNET_NO; 486 }
376 send_msg = GNUNET_NO; 487 if (printed == GNUNET_NO)
377 } 488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378 } 489 "[%i] ATS state: %s\n", count, cont);
379 if (current.state == ATS_UNMODIFIED)
380 {
381 if (c_unmodified < MEASUREMENTS)
382 {
383 results_unmodified[c_unmodified] = current;
384 c_unmodified++;
385 }
386
387 }
388 if (current.state == ATS_QUALITY_UPDATED)
389 {
390 if (c_modified < MEASUREMENTS)
391 {
392 results_modified[c_modified] = current;
393 c_modified++;
394 }
395 else
396 {
397 force_q_updates = GNUNET_NO;
398 force_rebuild = GNUNET_YES;
399 }
400 }
401 count ++;
402#if VERBOSE
403 fprintf (stderr,
404 "(new: %i / modified: %i / unmodified: %i) of %i \n",
405 c_new, c_modified, c_unmodified , MEASUREMENTS);
406#endif
407 if ((c_modified >= MEASUREMENTS) &&
408 (c_new >= MEASUREMENTS) &&
409 (c_unmodified >= MEASUREMENTS))
410 {
411#if !VERBOSE
412 if (!machine_parsable)
413 fprintf(stdout, "\n");
414#endif
415 if (stats_task != GNUNET_SCHEDULER_NO_TASK)
416 {
417 GNUNET_SCHEDULER_cancel(stats_task);
418 stats_task = GNUNET_SCHEDULER_NO_TASK;
419 }
420 evaluate_measurements();
421 return GNUNET_SYSERR;
422 }
423
424 printed = GNUNET_NO;
425 current.timestamp = value;
426#if !VERBOSE
427 if (! machine_parsable)
428 fprintf(stderr, "..%i", count);
429#endif
430 return GNUNET_OK;
431 }
432 }
433
434 if (0 == strcmp (name,"ATS solution"))
435 {
436 current.solution = value;
437 if (printed == GNUNET_NO)
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
439 count, name, value);
440 }
441
442 if (0 == strcmp (name,"ATS peers"))
443 {
444 current.peers = value;
445 if (printed == GNUNET_NO)
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
447 count, name, value);
448 }
449
450 if (0 == strcmp (name,"ATS mechanisms"))
451 {
452 current.mechs = value;
453 if (printed == GNUNET_NO)
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
455 count, name, value);
456 }
457
458 if (0 == strcmp (name,"ATS duration"))
459 {
460 current.duration = value;
461 if (printed == GNUNET_NO)
462 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "[%i] %s: %llu \n",
463 count, name, value);
464 }
465 if (0 == strcmp (name,"ATS state"))
466 {
467 current.state = value;
468 const char * cont;
469 switch (value)
470 {
471 case ATS_NEW:
472 cont = "NEW";
473 break;
474 case ATS_COST_UPDATED:
475 cont = "C_UPDATED";
476 break;
477 case ATS_QUALITY_UPDATED:
478 cont = "Q_UPDATED";
479 break;
480 case ATS_QUALITY_COST_UPDATED:
481 cont = "QC_UPDATED";
482 break;
483 case ATS_UNMODIFIED:
484 cont = "UNMODIFIED";
485 break;
486 default:
487 GNUNET_break (0);
488 cont = "<undefined>";
489 break;
490 }
491 if (printed == GNUNET_NO)
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "[%i] ATS state: %s\n",
494 count,
495 cont);
496 }
497 } 490 }
491 }
498 return GNUNET_OK; 492 return GNUNET_OK;
499} 493}
500 494
501 495
502static void 496static void
503stats_get_task (void *cls, 497stats_get_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
504 const struct GNUNET_SCHEDULER_TaskContext *tc)
505{ 498{
506 stats_task = GNUNET_SCHEDULER_NO_TASK; 499 stats_task = GNUNET_SCHEDULER_NO_TASK;
507 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 500 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
508 return; 501 return;
509 502
510 s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp", 503 s_time = GNUNET_STATISTICS_get (stats, "transport", "ATS timestamp",
511 TIMEOUT, NULL, &stats_cb, NULL); 504 TIMEOUT, NULL, &stats_cb, NULL);
512 s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution", 505 s_solution = GNUNET_STATISTICS_get (stats, "transport", "ATS solution",
513 TIMEOUT, NULL, &stats_cb, NULL); 506 TIMEOUT, NULL, &stats_cb, NULL);
514 s_duration = GNUNET_STATISTICS_get (stats, "transport","ATS duration", 507 s_duration = GNUNET_STATISTICS_get (stats, "transport", "ATS duration",
515 TIMEOUT, NULL, &stats_cb, NULL); 508 TIMEOUT, NULL, &stats_cb, NULL);
516 s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers", 509 s_peers = GNUNET_STATISTICS_get (stats, "transport", "ATS peers",
517 TIMEOUT, NULL, &stats_cb, NULL); 510 TIMEOUT, NULL, &stats_cb, NULL);
518 s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms", 511 s_mechs = GNUNET_STATISTICS_get (stats, "transport", "ATS mechanisms",
519 TIMEOUT, NULL, &stats_cb, NULL); 512 TIMEOUT, NULL, &stats_cb, NULL);
520 s_invalid = GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions", 513 s_invalid =
521 TIMEOUT, NULL, &stats_cb, NULL); 514 GNUNET_STATISTICS_get (stats, "transport", "ATS invalid solutions",
522 s_state = GNUNET_STATISTICS_get (stats, "transport", "ATS state", 515 TIMEOUT, NULL, &stats_cb, NULL);
523 TIMEOUT, NULL, &stats_cb, NULL); 516 s_state =
524 517 GNUNET_STATISTICS_get (stats, "transport", "ATS state", TIMEOUT, NULL,
525 stats_task = GNUNET_SCHEDULER_add_delayed( 518 &stats_cb, NULL);
526 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100), 519
527 &stats_get_task, 520 stats_task =
528 NULL); 521 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
522 (GNUNET_TIME_UNIT_MILLISECONDS, 100),
523 &stats_get_task, NULL);
529} 524}
530 525
531 526
532static void 527static void
533delay (void *cls, 528delay (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
534 const struct GNUNET_SCHEDULER_TaskContext *tc)
535{ 529{
536 shutdown_task = GNUNET_SCHEDULER_NO_TASK; 530 shutdown_task = GNUNET_SCHEDULER_NO_TASK;
537 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 531 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
538 return; 532 return;
539#if VERBOSE 533#if VERBOSE
540 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Delay over\n");
541 "Delay over\n");
542#endif 535#endif
543 shutdown_peers (); 536 shutdown_peers ();
544} 537}
545 538
546static void 539static void
547connect_peers() 540connect_peers ()
548{ 541{
549 shutdown_task = GNUNET_SCHEDULER_add_delayed(DELAY, &delay, NULL); 542 shutdown_task = GNUNET_SCHEDULER_add_delayed (DELAY, &delay, NULL);
550} 543}
551 544
552 545
553/* To make compiler happy */ 546/* To make compiler happy */
554void dummy(void) 547void
548dummy (void)
555{ 549{
556 struct ATS_quality_metric * q = qm; 550 struct ATS_quality_metric *q = qm;
551
557 q = NULL; 552 q = NULL;
558 q++; 553 q++;
559 struct ATS_ressource * r = ressources; 554 struct ATS_ressource *r = ressources;
555
560 r = NULL; 556 r = NULL;
561 r++; 557 r++;
562} 558}
563 559
564static size_t 560static size_t
565send_dummy_data_task (void *cls, size_t size, void *buf) 561send_dummy_data_task (void *cls, size_t size, void *buf)
566{ 562{
567 int s = sizeof (struct TestMessage); 563 int s = sizeof (struct TestMessage);
568 struct TestMessage hdr; 564 struct TestMessage hdr;
569 565
570 hdr.header.size = htons (s); 566 hdr.header.size = htons (s);
571 hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ATS); 567 hdr.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ATS);
572 if (force_rebuild) 568 if (force_rebuild)
@@ -574,7 +570,7 @@ send_dummy_data_task (void *cls, size_t size, void *buf)
574 else if (force_q_updates) 570 else if (force_q_updates)
575 hdr.num = htonl (2); 571 hdr.num = htonl (2);
576 else 572 else
577 hdr.num = htonl (0); 573 hdr.num = htonl (0);
578 memcpy (buf, &hdr, s); 574 memcpy (buf, &hdr, s);
579 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i of %i\n", s, s); 575 // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Sent bytes: %i of %i\n", s, s);
580 t = NULL; 576 t = NULL;
@@ -582,30 +578,29 @@ send_dummy_data_task (void *cls, size_t size, void *buf)
582} 578}
583 579
584 580
585static void 581static void
586send_task_f (void *cls, 582send_task_f (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
587 const struct GNUNET_SCHEDULER_TaskContext *tc)
588{ 583{
589 send_task = GNUNET_SCHEDULER_NO_TASK; 584 send_task = GNUNET_SCHEDULER_NO_TASK;
590 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 585 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
591 return; 586 return;
592 587
593 if (t!=NULL) 588 if (t != NULL)
594 { 589 {
595 GNUNET_TRANSPORT_notify_transmit_ready_cancel(t); 590 GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
596 t = NULL; 591 t = NULL;
597 } 592 }
598 593
599 if (send_msg == GNUNET_YES) 594 if (send_msg == GNUNET_YES)
600 t = GNUNET_TRANSPORT_notify_transmit_ready(th, 595 t = GNUNET_TRANSPORT_notify_transmit_ready (th,
601 &master_deamon->id, 596 &master_deamon->id,
602 sizeof (struct TestMessage), 0, 597 sizeof (struct TestMessage), 0,
603 SEND_TIMEOUT, 598 SEND_TIMEOUT,
604 &send_dummy_data_task, NULL); 599 &send_dummy_data_task, NULL);
605 send_task = GNUNET_SCHEDULER_add_delayed( 600 send_task =
606 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,1000), 601 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
607 &send_task_f, 602 (GNUNET_TIME_UNIT_MILLISECONDS, 1000),
608 NULL); 603 &send_task_f, NULL);
609 604
610} 605}
611 606
@@ -615,135 +610,127 @@ notify_connect (void *cls,
615 const struct GNUNET_TRANSPORT_ATS_Information *ats, 610 const struct GNUNET_TRANSPORT_ATS_Information *ats,
616 uint32_t ats_count) 611 uint32_t ats_count)
617{ 612{
618 send_task = GNUNET_SCHEDULER_add_now(&send_task_f, NULL); 613 send_task = GNUNET_SCHEDULER_add_now (&send_task_f, NULL);
619} 614}
620 615
621static void 616static void
622notify_disconnect (void *cls, 617notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
623 const struct GNUNET_PeerIdentity *peer)
624{ 618{
625 if (GNUNET_SCHEDULER_NO_TASK != send_task) 619 if (GNUNET_SCHEDULER_NO_TASK != send_task)
626 { 620 {
627 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
628 "Disconnect event before transmission request could be scheduled!\n"); 622 "Disconnect event before transmission request could be scheduled!\n");
629 GNUNET_SCHEDULER_cancel (send_task); 623 GNUNET_SCHEDULER_cancel (send_task);
630 send_task = GNUNET_SCHEDULER_NO_TASK; 624 send_task = GNUNET_SCHEDULER_NO_TASK;
631 } 625 }
632 if (NULL != t) 626 if (NULL != t)
633 { 627 {
634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 628 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
635 "Disconnect event before transmission request could be completed!\n"); 629 "Disconnect event before transmission request could be completed!\n");
636 GNUNET_TRANSPORT_notify_transmit_ready_cancel (t); 630 GNUNET_TRANSPORT_notify_transmit_ready_cancel (t);
637 t = NULL; 631 t = NULL;
638 } 632 }
639} 633}
640 634
641static void 635static void
642daemon_connect_cb(void *cls, 636daemon_connect_cb (void *cls,
643 const struct GNUNET_PeerIdentity *first, 637 const struct GNUNET_PeerIdentity *first,
644 const struct GNUNET_PeerIdentity *second, 638 const struct GNUNET_PeerIdentity *second,
645 uint32_t distance, 639 uint32_t distance,
646 const struct GNUNET_CONFIGURATION_Handle *first_cfg, 640 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
647 const struct GNUNET_CONFIGURATION_Handle *second_cfg, 641 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
648 struct GNUNET_TESTING_Daemon *first_daemon, 642 struct GNUNET_TESTING_Daemon *first_daemon,
649 struct GNUNET_TESTING_Daemon *second_daemon, 643 struct GNUNET_TESTING_Daemon *second_daemon,
650 const char *emsg) 644 const char *emsg)
651{ 645{
652 char * firstc = strdup(GNUNET_i2s(first)); 646 char *firstc = strdup (GNUNET_i2s (first));
653 char * secondc = strdup(GNUNET_i2s(second)); 647 char *secondc = strdup (GNUNET_i2s (second));
648
654 connected++; 649 connected++;
655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 650 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
656 "Connected peers `%s'<->`%s' (%i/%i)\n", 651 "Connected peers `%s'<->`%s' (%i/%i)\n",
657 firstc, secondc, connected, peers-1); 652 firstc, secondc, connected, peers - 1);
658 GNUNET_free(firstc); 653 GNUNET_free (firstc);
659 GNUNET_free(secondc); 654 GNUNET_free (secondc);
660 655
661 if ( ( (first_daemon == ping_deamon) || 656 if (((first_daemon == ping_deamon) ||
662 (second_daemon == ping_deamon) ) && 657 (second_daemon == ping_deamon)) &&
663 (master_deamon != NULL) && 658 (master_deamon != NULL) && (ping_deamon != NULL))
664 (ping_deamon != NULL) ) 659 {
665 { 660 th = GNUNET_TRANSPORT_connect (ping_deamon->cfg,
666 th = GNUNET_TRANSPORT_connect (ping_deamon->cfg, 661 &ping_deamon->id,
667 &ping_deamon->id, 662 NULL, NULL,
668 NULL, NULL, 663 &notify_connect, &notify_disconnect);
669 &notify_connect, 664 force_q_updates = GNUNET_YES;
670 &notify_disconnect); 665 send_msg = GNUNET_YES;
671 force_q_updates = GNUNET_YES; 666 }
672 send_msg = GNUNET_YES;
673 }
674} 667}
675 668
676 669
677 670
678static void 671static void
679daemon_start_cb (void *cls, 672daemon_start_cb (void *cls,
680 const struct GNUNET_PeerIdentity *id, 673 const struct GNUNET_PeerIdentity *id,
681 const struct GNUNET_CONFIGURATION_Handle *cfg, 674 const struct GNUNET_CONFIGURATION_Handle *cfg,
682 struct GNUNET_TESTING_Daemon *d, const char *emsg) 675 struct GNUNET_TESTING_Daemon *d, const char *emsg)
683{ 676{
684 if (id == NULL) 677 if (id == NULL)
678 {
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "Start callback called with error (too long starting peers), aborting test!\n");
681 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Error from testing: `%s'\n");
682 failed_peers++;
683 if (failed_peers == peers_left)
685 { 684 {
686 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 685 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
687 "Start callback called with error (too long starting peers), aborting test!\n"); 686 "Too many peers failed, ending test!\n");
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 687 ok = 1;
689 "Error from testing: `%s'\n"); 688 shutdown_peers ();
690 failed_peers++;
691 if (failed_peers == peers_left)
692 {
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
694 "Too many peers failed, ending test!\n");
695 ok = 1;
696 shutdown_peers ();
697 }
698 return;
699 } 689 }
690 return;
691 }
700 peers_left--; 692 peers_left--;
701 693
702 if (master_deamon == NULL) 694 if (master_deamon == NULL)
703 { 695 {
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 696 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
705 "Master peer `%s' '%s'\n", 697 "Master peer `%s' '%s'\n", GNUNET_i2s (id), d->cfgfile);
706 GNUNET_i2s(id), d->cfgfile); 698 master_deamon = d;
707 master_deamon = d; 699 stats = GNUNET_STATISTICS_create ("transport", master_deamon->cfg);
708 stats = GNUNET_STATISTICS_create("transport", master_deamon->cfg); 700 GNUNET_assert (stats != NULL);
709 GNUNET_assert (stats != NULL); 701 stats_task = GNUNET_SCHEDULER_add_now (&stats_get_task, NULL);
710 stats_task = GNUNET_SCHEDULER_add_now(&stats_get_task, NULL); 702 }
711 }
712 else 703 else
713 { 704 {
714 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 705 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
715 "Connecting peer `%s'\n", 706 "Connecting peer `%s'\n",
716 GNUNET_i2s(id), GNUNET_i2s(&master_deamon->id)); 707 GNUNET_i2s (id), GNUNET_i2s (&master_deamon->id));
717 GNUNET_TESTING_daemons_connect(d, 708 GNUNET_TESTING_daemons_connect (d,
718 master_deamon, 709 master_deamon,
719 TIMEOUT, 710 TIMEOUT,
720 0, 711 0, GNUNET_YES, &daemon_connect_cb, NULL);
721 GNUNET_YES, 712 }
722 &daemon_connect_cb, 713
723 NULL);
724 }
725
726 if (peers_left == 0) 714 if (peers_left == 0)
715 {
716 if (ping_deamon == NULL)
727 { 717 {
728 if (ping_deamon == NULL) 718 ping_deamon = d;
729 {
730 ping_deamon = d;
731 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
732 "Ping peer `%s' '%s'\n", GNUNET_i2s(id), d->cfgfile);
733 }
734
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 719 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "All peers started successfully!\n"); 720 "Ping peer `%s' '%s'\n", GNUNET_i2s (id), d->cfgfile);
737 connect_peers();
738 ok = 0;
739 } 721 }
722
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers started successfully!\n");
724 connect_peers ();
725 ok = 0;
726 }
740 else if (failed_peers == peers_left) 727 else if (failed_peers == peers_left)
741 { 728 {
742 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 729 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
743 "Too many peers failed, ending test!\n"); 730 "Too many peers failed, ending test!\n");
744 shutdown_peers(); 731 shutdown_peers ();
745 ok = 1; 732 ok = 1;
746 } 733 }
747} 734}
748 735
749 736
@@ -758,10 +745,9 @@ run (void *cls,
758 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers); 745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting %i peers.\n", peers);
759#endif 746#endif
760 peers_left = peers; 747 peers_left = peers;
761 pg = GNUNET_TESTING_daemons_start (cfg, 748 pg = GNUNET_TESTING_daemons_start (cfg, peers_left, /* Total number of peers */
762 peers_left, /* Total number of peers */ 749 peers_left, /* Number of outstanding connections */
763 peers_left, /* Number of outstanding connections */ 750 peers_left, /* Number of parallel ssh connections, or peers being started at once */
764 peers_left, /* Number of parallel ssh connections, or peers being started at once */
765 TIMEOUT, 751 TIMEOUT,
766 NULL, NULL, 752 NULL, NULL,
767 &daemon_start_cb, NULL, NULL, NULL, NULL); 753 &daemon_start_cb, NULL, NULL, NULL, NULL);
@@ -808,28 +794,29 @@ main (int argc, char *argv[])
808 config_file = "test_transport_ats_4addr.conf"; 794 config_file = "test_transport_ats_4addr.conf";
809 795
810 int c = 0; 796 int c = 0;
797
811 if (argc >= 2) 798 if (argc >= 2)
812 { 799 {
813 for (c=0; c<argc; c++) 800 for (c = 0; c < argc; c++)
814 { 801 {
815 /* set peers */ 802 /* set peers */
816 if ((strcmp(argv[c], "-p") == 0) && c < (argc-1)) 803 if ((strcmp (argv[c], "-p") == 0) && c < (argc - 1))
817 { 804 {
818 peers = atoi(argv[c+1]); 805 peers = atoi (argv[c + 1]);
819 peers++; 806 peers++;
820 } 807 }
821 /* set machine parsable */ 808 /* set machine parsable */
822 if (strcmp(argv[c], "-m") == 0) 809 if (strcmp (argv[c], "-m") == 0)
823 { 810 {
824 machine_parsable = GNUNET_YES; 811 machine_parsable = GNUNET_YES;
825 } 812 }
826 /* set config file */ 813 /* set config file */
827 if ((strcmp(argv[c], "-c") == 0) && c < (argc-1)) 814 if ((strcmp (argv[c], "-c") == 0) && c < (argc - 1))
828 { 815 {
829 config_file = argv[c+1]; 816 config_file = argv[c + 1];
830 } 817 }
831 } 818 }
832 } 819 }
833 820
834 ret = check (); 821 ret = check ();
835 /** 822 /**
diff --git a/src/transport/test_transport_testing.c b/src/transport/test_transport_testing.c
index 514dd2b6e..cd5d7ed2c 100644
--- a/src/transport/test_transport_testing.c
+++ b/src/transport/test_transport_testing.c
@@ -50,8 +50,8 @@
50 50
51GNUNET_SCHEDULER_TaskIdentifier timeout_task; 51GNUNET_SCHEDULER_TaskIdentifier timeout_task;
52 52
53static struct PeerContext * p1; 53static struct PeerContext *p1;
54static struct PeerContext * p2; 54static struct PeerContext *p2;
55 55
56static int connected = GNUNET_NO; 56static int connected = GNUNET_NO;
57 57
@@ -63,10 +63,10 @@ end ()
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n"); 63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stopping peers\n");
64 64
65 if (timeout_task != GNUNET_SCHEDULER_NO_TASK) 65 if (timeout_task != GNUNET_SCHEDULER_NO_TASK)
66 GNUNET_SCHEDULER_cancel(timeout_task); 66 GNUNET_SCHEDULER_cancel (timeout_task);
67 67
68 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 68 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
69 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 69 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
70} 70}
71 71
72static void 72static void
@@ -75,21 +75,21 @@ end_badly ()
75 timeout_task = GNUNET_SCHEDULER_NO_TASK; 75 timeout_task = GNUNET_SCHEDULER_NO_TASK;
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n"); 76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Fail! Stopping peers\n");
77 77
78 GNUNET_TRANSPORT_TESTING_stop_peer(p1); 78 GNUNET_TRANSPORT_TESTING_stop_peer (p1);
79 GNUNET_TRANSPORT_TESTING_stop_peer(p2); 79 GNUNET_TRANSPORT_TESTING_stop_peer (p2);
80 80
81 ret = GNUNET_SYSERR; 81 ret = GNUNET_SYSERR;
82} 82}
83 83
84static void 84static void
85testing_connect_cb (struct PeerContext * p1, struct PeerContext * p2, void *cls) 85testing_connect_cb (struct PeerContext *p1, struct PeerContext *p2, void *cls)
86{ 86{
87 char * p1_c = strdup (GNUNET_i2s(&p1->id)); 87 char *p1_c = strdup (GNUNET_i2s (&p1->id));
88
88 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n", 89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peers connected: %s <-> %s\n",
89 p1_c, 90 p1_c, GNUNET_i2s (&p2->id));
90 GNUNET_i2s (&p2->id)); 91 GNUNET_free (p1_c);
91 GNUNET_free(p1_c); 92 end ();
92 end();
93} 93}
94 94
95static void 95static void
@@ -99,7 +99,7 @@ notify_connect (void *cls,
99 uint32_t ats_count) 99 uint32_t ats_count)
100{ 100{
101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n", 101 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' connected \n",
102 GNUNET_i2s (peer)); 102 GNUNET_i2s (peer));
103 connected++; 103 connected++;
104} 104}
105 105
@@ -107,7 +107,7 @@ static void
107notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 107notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
108{ 108{
109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n", 109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer `%s' disconnected \n",
110 GNUNET_i2s (peer)); 110 GNUNET_i2s (peer));
111} 111}
112 112
113static void 113static void
@@ -126,38 +126,39 @@ run (void *cls,
126 char *const *args, 126 char *const *args,
127 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) 127 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
128{ 128{
129 timeout_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL); 129 timeout_task =
130 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, &end_badly, NULL);
130 131
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n"); 132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting peer\n");
132 p1 = GNUNET_TRANSPORT_TESTING_start_peer("test_transport_api_tcp_peer1.conf", 133 p1 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer1.conf",
133 &notify_receive, 134 &notify_receive,
134 &notify_connect, 135 &notify_connect,
135 &notify_disconnect, 136 &notify_disconnect, p1);
136 p1); 137
137 138 p2 = GNUNET_TRANSPORT_TESTING_start_peer ("test_transport_api_tcp_peer2.conf",
138 p2 = GNUNET_TRANSPORT_TESTING_start_peer("test_transport_api_tcp_peer2.conf", 139 &notify_receive,
139 &notify_receive, 140 &notify_connect,
140 &notify_connect, 141 &notify_disconnect, p2);
141 &notify_disconnect,
142 p2);
143 142
144 if (p1 != NULL) 143 if (p1 != NULL)
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was successfully started\n"); 144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was successfully started\n");
146 else 145 else
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer1 was not started successfully\n"); 146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
147 "Peer1 was not started successfully\n");
148 GNUNET_assert (p1 != NULL); 148 GNUNET_assert (p1 != NULL);
149 GNUNET_assert (p1->th != NULL); 149 GNUNET_assert (p1->th != NULL);
150 150
151 if (p2 != NULL) 151 if (p2 != NULL)
152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was successfully started\n"); 152 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was successfully started\n");
153 else 153 else
154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer2 was not started successfully\n"); 154 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
155 "Peer2 was not started successfully\n");
155 GNUNET_assert (p2 != NULL); 156 GNUNET_assert (p2 != NULL);
156 GNUNET_assert (p2->th != NULL); 157 GNUNET_assert (p2->th != NULL);
157 158
158 159
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers\n"); 160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting peers\n");
160 GNUNET_TRANSPORT_TESTING_connect_peers(p1, p2, &testing_connect_cb, NULL); 161 GNUNET_TRANSPORT_TESTING_connect_peers (p1, p2, &testing_connect_cb, NULL);
161} 162}
162 163
163int 164int
diff --git a/src/transport/transport-testing.c b/src/transport/transport-testing.c
index 01419ce44..e6fcabb48 100644
--- a/src/transport/transport-testing.c
+++ b/src/transport/transport-testing.c
@@ -29,11 +29,11 @@
29 29
30struct ConnectingContext 30struct ConnectingContext
31{ 31{
32 struct PeerContext * p1; 32 struct PeerContext *p1;
33 struct PeerContext * p2; 33 struct PeerContext *p2;
34 GNUNET_SCHEDULER_TaskIdentifier tct; 34 GNUNET_SCHEDULER_TaskIdentifier tct;
35 GNUNET_TRANSPORT_TESTING_connect_cb cb; 35 GNUNET_TRANSPORT_TESTING_connect_cb cb;
36 void * cb_cls; 36 void *cb_cls;
37 37
38 struct GNUNET_TRANSPORT_Handle *th_p1; 38 struct GNUNET_TRANSPORT_Handle *th_p1;
39 struct GNUNET_TRANSPORT_Handle *th_p2; 39 struct GNUNET_TRANSPORT_Handle *th_p2;
@@ -42,41 +42,43 @@ struct ConnectingContext
42}; 42};
43 43
44static void 44static void
45exchange_hello_last (void *cb_cls, 45exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message);
46 const struct GNUNET_MessageHeader *message);
47static void 46static void
48exchange_hello (void *cb_cls, 47exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message);
49 const struct GNUNET_MessageHeader *message);
50 48
51static void 49static void
52notify_connect_internal (void *cls, 50notify_connect_internal (void *cls,
53 const struct GNUNET_PeerIdentity *peer, 51 const struct GNUNET_PeerIdentity *peer,
54 const struct GNUNET_TRANSPORT_ATS_Information *ats, 52 const struct GNUNET_TRANSPORT_ATS_Information *ats,
55 uint32_t ats_count) 53 uint32_t ats_count)
56{ 54{
57 struct ConnectingContext * cc = cls; 55 struct ConnectingContext *cc = cls;
58 56
59 GNUNET_assert(cc != NULL); 57 GNUNET_assert (cc != NULL);
60 58
61 if (0 == memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey, sizeof (GNUNET_HashCode))) 59 if (0 ==
62 { 60 memcmp (&(*peer).hashPubKey, &cc->p1->id.hashPubKey,
61 sizeof (GNUNET_HashCode)))
62 {
63 if (cc->p1_c == GNUNET_NO) 63 if (cc->p1_c == GNUNET_NO)
64 cc->p1_c = GNUNET_YES; 64 cc->p1_c = GNUNET_YES;
65 } 65 }
66 if (0 == memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey, sizeof (GNUNET_HashCode))) 66 if (0 ==
67 { 67 memcmp (&(*peer).hashPubKey, &cc->p2->id.hashPubKey,
68 sizeof (GNUNET_HashCode)))
69 {
68 if (cc->p2_c == GNUNET_NO) 70 if (cc->p2_c == GNUNET_NO)
69 cc->p2_c = GNUNET_YES; 71 cc->p2_c = GNUNET_YES;
70 } 72 }
71 73
72 if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES)) 74 if ((cc->p2_c == GNUNET_YES) && (cc->p2_c == GNUNET_YES))
73 { 75 {
74 /* clean up */ 76 /* clean up */
75 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc); 77 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p2, &exchange_hello_last, cc);
76 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p1, &exchange_hello, cc); 78 GNUNET_TRANSPORT_get_hello_cancel (cc->th_p1, &exchange_hello, cc);
77 79
78 if (cc->tct != GNUNET_SCHEDULER_NO_TASK) 80 if (cc->tct != GNUNET_SCHEDULER_NO_TASK)
79 GNUNET_SCHEDULER_cancel(cc->tct); 81 GNUNET_SCHEDULER_cancel (cc->tct);
80 82
81 cc->tct = GNUNET_SCHEDULER_NO_TASK; 83 cc->tct = GNUNET_SCHEDULER_NO_TASK;
82 84
@@ -86,7 +88,7 @@ notify_connect_internal (void *cls,
86 if (cc->cb != NULL) 88 if (cc->cb != NULL)
87 cc->cb (cc->p1, cc->p2, cc->cb_cls); 89 cc->cb (cc->p1, cc->p2, cc->cb_cls);
88 90
89 GNUNET_free(cc); 91 GNUNET_free (cc);
90 } 92 }
91} 93}
92 94
@@ -96,7 +98,8 @@ notify_connect (void *cls,
96 const struct GNUNET_TRANSPORT_ATS_Information *ats, 98 const struct GNUNET_TRANSPORT_ATS_Information *ats,
97 uint32_t ats_count) 99 uint32_t ats_count)
98{ 100{
99 struct PeerContext * p = cls; 101 struct PeerContext *p = cls;
102
100 if (p == NULL) 103 if (p == NULL)
101 return; 104 return;
102 if (p->nc != NULL) 105 if (p->nc != NULL)
@@ -106,7 +109,8 @@ notify_connect (void *cls,
106static void 109static void
107notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) 110notify_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
108{ 111{
109 struct PeerContext * p = cls; 112 struct PeerContext *p = cls;
113
110 if (p == NULL) 114 if (p == NULL)
111 return; 115 return;
112 if (p->nd != NULL) 116 if (p->nd != NULL)
@@ -120,7 +124,8 @@ notify_receive (void *cls,
120 const struct GNUNET_TRANSPORT_ATS_Information *ats, 124 const struct GNUNET_TRANSPORT_ATS_Information *ats,
121 uint32_t ats_count) 125 uint32_t ats_count)
122{ 126{
123 struct PeerContext * p = cls; 127 struct PeerContext *p = cls;
128
124 if (p == NULL) 129 if (p == NULL)
125 return; 130 return;
126 if (p->rec != NULL) 131 if (p->rec != NULL)
@@ -129,18 +134,18 @@ notify_receive (void *cls,
129 134
130 135
131static void 136static void
132exchange_hello_last (void *cb_cls, 137exchange_hello_last (void *cb_cls, const struct GNUNET_MessageHeader *message)
133 const struct GNUNET_MessageHeader *message)
134{ 138{
135 struct ConnectingContext * cc = cb_cls; 139 struct ConnectingContext *cc = cb_cls;
136 struct PeerContext *me = cc->p2; 140 struct PeerContext *me = cc->p2;
141
137 //struct PeerContext *p1 = cc->p1; 142 //struct PeerContext *p1 = cc->p1;
138 143
139 GNUNET_assert (message != NULL); 144 GNUNET_assert (message != NULL);
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
141 "Exchanging HELLO of size %d with peer (%s)!\n", 146 "Exchanging HELLO of size %d with peer (%s)!\n",
142 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 147 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
143 GNUNET_i2s (&me->id)); 148 message), GNUNET_i2s (&me->id));
144 GNUNET_assert (GNUNET_OK == 149 GNUNET_assert (GNUNET_OK ==
145 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 150 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
146 message, &me->id)); 151 message, &me->id));
@@ -149,11 +154,11 @@ exchange_hello_last (void *cb_cls,
149 154
150 155
151static void 156static void
152exchange_hello (void *cb_cls, 157exchange_hello (void *cb_cls, const struct GNUNET_MessageHeader *message)
153 const struct GNUNET_MessageHeader *message)
154{ 158{
155 struct ConnectingContext * cc = cb_cls; 159 struct ConnectingContext *cc = cb_cls;
156 struct PeerContext *me = cc->p1; 160 struct PeerContext *me = cc->p1;
161
157 //struct PeerContext *p2 = cc->p2; 162 //struct PeerContext *p2 = cc->p2;
158 163
159 GNUNET_assert (message != NULL); 164 GNUNET_assert (message != NULL);
@@ -162,34 +167,29 @@ exchange_hello (void *cb_cls,
162 message, &me->id)); 167 message, &me->id));
163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 168 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
164 "Exchanging HELLO of size %d from peer %s!\n", 169 "Exchanging HELLO of size %d from peer %s!\n",
165 (int) GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message), 170 (int) GNUNET_HELLO_size ((const struct GNUNET_HELLO_Message *)
166 GNUNET_i2s (&me->id)); 171 message), GNUNET_i2s (&me->id));
167 GNUNET_TRANSPORT_offer_hello (cc->th_p2, message, NULL, NULL); 172 GNUNET_TRANSPORT_offer_hello (cc->th_p2, message, NULL, NULL);
168} 173}
169 174
170static void 175static void
171try_connect (void *cls, 176try_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
172 const struct GNUNET_SCHEDULER_TaskContext *tc)
173{ 177{
174 struct ConnectingContext * cc = cls; 178 struct ConnectingContext *cc = cls;
175 struct PeerContext *p1 = cc->p1; 179 struct PeerContext *p1 = cc->p1;
176 struct PeerContext *p2 = cc->p2; 180 struct PeerContext *p2 = cc->p2;
177 181
178 cc->tct = GNUNET_SCHEDULER_NO_TASK; 182 cc->tct = GNUNET_SCHEDULER_NO_TASK;
179 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 183 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
180 return; 184 return;
181 185
182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking peers to connect...\n");
183 "Asking peers to connect...\n");
184 /* FIXME: 'pX.id' may still be all-zeros here... */ 187 /* FIXME: 'pX.id' may still be all-zeros here... */
185 GNUNET_TRANSPORT_try_connect (cc->th_p1, 188 GNUNET_TRANSPORT_try_connect (cc->th_p1, &p2->id);
186 &p2->id); 189 GNUNET_TRANSPORT_try_connect (cc->th_p2, &p1->id);
187 GNUNET_TRANSPORT_try_connect (cc->th_p2,
188 &p1->id);
189 190
190 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 191 cc->tct = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
191 &try_connect, 192 &try_connect, cc);
192 cc);
193} 193}
194 194
195 195
@@ -202,30 +202,30 @@ try_connect (void *cls,
202 * @return the peer context 202 * @return the peer context
203 */ 203 */
204struct PeerContext * 204struct PeerContext *
205GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, 205GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
206 GNUNET_TRANSPORT_ReceiveCallback rec, 206 GNUNET_TRANSPORT_ReceiveCallback rec,
207 GNUNET_TRANSPORT_NotifyConnect nc, 207 GNUNET_TRANSPORT_NotifyConnect nc,
208 GNUNET_TRANSPORT_NotifyDisconnect nd, 208 GNUNET_TRANSPORT_NotifyDisconnect nd,
209 void * cb_cls) 209 void *cb_cls)
210{ 210{
211 struct PeerContext * p = GNUNET_malloc (sizeof (struct PeerContext)); 211 struct PeerContext *p = GNUNET_malloc (sizeof (struct PeerContext));
212 212
213 p->cfg = GNUNET_CONFIGURATION_create (); 213 p->cfg = GNUNET_CONFIGURATION_create ();
214 214
215 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 215 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
216 if (GNUNET_CONFIGURATION_have_value (p->cfg,"PATHS", "SERVICEHOME")) 216 if (GNUNET_CONFIGURATION_have_value (p->cfg, "PATHS", "SERVICEHOME"))
217 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME", &p->servicehome); 217 GNUNET_CONFIGURATION_get_value_string (p->cfg, "PATHS", "SERVICEHOME",
218 &p->servicehome);
218 if (NULL != p->servicehome) 219 if (NULL != p->servicehome)
219 GNUNET_DISK_directory_remove (p->servicehome); 220 GNUNET_DISK_directory_remove (p->servicehome);
220 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 221 p->arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
221 "gnunet-service-arm", 222 "gnunet-service-arm", "-c", cfgname,
222 "-c", cfgname,
223#if VERBOSE_PEERS 223#if VERBOSE_PEERS
224 "-L", "DEBUG", 224 "-L", "DEBUG",
225#else 225#else
226 "-L", "ERROR", 226 "-L", "ERROR",
227#endif 227#endif
228 NULL); 228 NULL);
229 p->nc = nc; 229 p->nc = nc;
230 p->nd = nd; 230 p->nd = nd;
231 p->rec = rec; 231 p->rec = rec;
@@ -234,11 +234,10 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
234 else 234 else
235 p->cb_cls = p; 235 p->cb_cls = p;
236 236
237 p->th = GNUNET_TRANSPORT_connect(p->cfg, NULL, 237 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL,
238 p, 238 p,
239 &notify_receive, 239 &notify_receive,
240 &notify_connect, 240 &notify_connect, &notify_disconnect);
241 &notify_disconnect);
242 GNUNET_assert (p->th != NULL); 241 GNUNET_assert (p->th != NULL);
243 return p; 242 return p;
244} 243}
@@ -248,25 +247,25 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
248 * @param p the peer 247 * @param p the peer
249 */ 248 */
250void 249void
251GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p) 250GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *p)
252{ 251{
253 if (p->th != NULL) 252 if (p->th != NULL)
254 GNUNET_TRANSPORT_disconnect(p->th); 253 GNUNET_TRANSPORT_disconnect (p->th);
255 254
256 if (NULL != p->arm_proc) 255 if (NULL != p->arm_proc)
257 { 256 {
258 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 257 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
259 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 258 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
260 GNUNET_OS_process_wait (p->arm_proc); 259 GNUNET_OS_process_wait (p->arm_proc);
261 GNUNET_OS_process_close (p->arm_proc); 260 GNUNET_OS_process_close (p->arm_proc);
262 p->arm_proc = NULL; 261 p->arm_proc = NULL;
263 } 262 }
264 GNUNET_CONFIGURATION_destroy (p->cfg); 263 GNUNET_CONFIGURATION_destroy (p->cfg);
265 if (p->servicehome != NULL) 264 if (p->servicehome != NULL)
266 { 265 {
267 GNUNET_DISK_directory_remove (p->servicehome); 266 GNUNET_DISK_directory_remove (p->servicehome);
268 GNUNET_free(p->servicehome); 267 GNUNET_free (p->servicehome);
269 } 268 }
270 GNUNET_free (p); 269 GNUNET_free (p);
271} 270}
272 271
@@ -280,12 +279,13 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * p)
280 * @param cb_cls callback cls 279 * @param cb_cls callback cls
281 */ 280 */
282void 281void
283GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, 282GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
284 struct PeerContext * p2, 283 struct PeerContext *p2,
285 GNUNET_TRANSPORT_TESTING_connect_cb cb, 284 GNUNET_TRANSPORT_TESTING_connect_cb cb,
286 void * cb_cls) 285 void *cb_cls)
287{ 286{
288 struct ConnectingContext * cc = GNUNET_malloc (sizeof (struct ConnectingContext)); 287 struct ConnectingContext *cc =
288 GNUNET_malloc (sizeof (struct ConnectingContext));
289 289
290 GNUNET_assert (p1 != NULL); 290 GNUNET_assert (p1 != NULL);
291 GNUNET_assert (p2 != NULL); 291 GNUNET_assert (p2 != NULL);
@@ -296,17 +296,13 @@ GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1,
296 cc->cb = cb; 296 cc->cb = cb;
297 cc->cb_cls = cb_cls; 297 cc->cb_cls = cb_cls;
298 298
299 cc->th_p1 = GNUNET_TRANSPORT_connect(cc->p1->cfg, NULL, 299 cc->th_p1 = GNUNET_TRANSPORT_connect (cc->p1->cfg, NULL,
300 cc, 300 cc,
301 NULL, 301 NULL, &notify_connect_internal, NULL);
302 &notify_connect_internal, 302
303 NULL); 303 cc->th_p2 = GNUNET_TRANSPORT_connect (cc->p2->cfg, NULL,
304 304 cc,
305 cc->th_p2 = GNUNET_TRANSPORT_connect(cc->p2->cfg, NULL, 305 NULL, &notify_connect_internal, NULL);
306 cc,
307 NULL,
308 &notify_connect_internal,
309 NULL);
310 306
311 GNUNET_assert (cc->th_p1 != NULL); 307 GNUNET_assert (cc->th_p1 != NULL);
312 GNUNET_assert (cc->th_p2 != NULL); 308 GNUNET_assert (cc->th_p2 != NULL);
diff --git a/src/transport/transport-testing.h b/src/transport/transport-testing.h
index 10ef030f4..a867df4c1 100644
--- a/src/transport/transport-testing.h
+++ b/src/transport/transport-testing.h
@@ -53,16 +53,18 @@ struct PeerContext
53 53
54 GNUNET_TRANSPORT_NotifyDisconnect nd; 54 GNUNET_TRANSPORT_NotifyDisconnect nd;
55 55
56 void * cb_cls; 56 void *cb_cls;
57 57
58 char * servicehome; 58 char *servicehome;
59}; 59};
60 60
61/** 61/**
62 * Callback when two peers are connected and both have called the connect callback 62 * Callback when two peers are connected and both have called the connect callback
63 * to notify clients about a new peer 63 * to notify clients about a new peer
64 */ 64 */
65typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1, struct PeerContext * p2, void *cls); 65typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1,
66 struct PeerContext * p2,
67 void *cls);
66 68
67 69
68/** 70/**
@@ -74,12 +76,13 @@ typedef void (*GNUNET_TRANSPORT_TESTING_connect_cb) (struct PeerContext * p1, st
74 * if NULL passed the PeerContext * will be used! 76 * if NULL passed the PeerContext * will be used!
75 * @return the peer context 77 * @return the peer context
76 */ 78 */
77struct PeerContext * 79struct PeerContext *GNUNET_TRANSPORT_TESTING_start_peer (const char *cfgname,
78GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname, 80 GNUNET_TRANSPORT_ReceiveCallback
79 GNUNET_TRANSPORT_ReceiveCallback rec, 81 rec,
80 GNUNET_TRANSPORT_NotifyConnect nc, 82 GNUNET_TRANSPORT_NotifyConnect
81 GNUNET_TRANSPORT_NotifyDisconnect nd, 83 nc,
82 void * cb_cls); 84 GNUNET_TRANSPORT_NotifyDisconnect
85 nd, void *cb_cls);
83 86
84 87
85/** 88/**
@@ -87,8 +90,7 @@ GNUNET_TRANSPORT_TESTING_start_peer (const char * cfgname,
87 * @param p the peer 90 * @param p the peer
88 */ 91 */
89 92
90void 93void GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext *pc);
91GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * pc);
92 94
93 95
94/** 96/**
@@ -101,9 +103,9 @@ GNUNET_TRANSPORT_TESTING_stop_peer (struct PeerContext * pc);
101 * @param cb_cls callback cls 103 * @param cb_cls callback cls
102 */ 104 */
103void 105void
104GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext * p1, 106GNUNET_TRANSPORT_TESTING_connect_peers (struct PeerContext *p1,
105 struct PeerContext * p2, 107 struct PeerContext *p2,
106 GNUNET_TRANSPORT_TESTING_connect_cb cb, 108 GNUNET_TRANSPORT_TESTING_connect_cb cb,
107 void * cls); 109 void *cls);
108 110
109/* end of transport_testing.h */ 111/* end of transport_testing.h */
diff --git a/src/transport/transport.h b/src/transport/transport.h
index 4d1d370d9..a694d86e5 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -319,7 +319,7 @@ struct AddressLookupMessage
319 uint32_t addrlen GNUNET_PACKED; 319 uint32_t addrlen GNUNET_PACKED;
320 320
321 /* followed by 'addrlen' bytes of the actual address, then 321 /* followed by 'addrlen' bytes of the actual address, then
322 followed by the 0-terminated name of the transport */ 322 * followed by the 0-terminated name of the transport */
323}; 323};
324 324
325 325
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 4583cf876..2cdaacad6 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -255,7 +255,7 @@ struct GNUNET_TRANSPORT_Handle
255 * specify when we could next send a message to the respective peer. 255 * specify when we could next send a message to the respective peer.
256 * Excludes control messages (which can always go out immediately). 256 * Excludes control messages (which can always go out immediately).
257 * Maps time stamps to 'struct Neighbour' entries. 257 * Maps time stamps to 'struct Neighbour' entries.
258 */ 258 */
259 struct GNUNET_CONTAINER_Heap *ready_heap; 259 struct GNUNET_CONTAINER_Heap *ready_heap;
260 260
261 /** 261 /**
@@ -295,8 +295,7 @@ struct GNUNET_TRANSPORT_Handle
295 * 295 *
296 * @param h transport service to schedule a transmission for 296 * @param h transport service to schedule a transmission for
297 */ 297 */
298static void 298static void schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
299schedule_transmission (struct GNUNET_TRANSPORT_Handle *h);
300 299
301 300
302/** 301/**
@@ -320,7 +319,7 @@ static struct Neighbour *
320neighbour_find (struct GNUNET_TRANSPORT_Handle *h, 319neighbour_find (struct GNUNET_TRANSPORT_Handle *h,
321 const struct GNUNET_PeerIdentity *peer) 320 const struct GNUNET_PeerIdentity *peer)
322{ 321{
323 return GNUNET_CONTAINER_multihashmap_get(h->neighbours, &peer->hashPubKey); 322 return GNUNET_CONTAINER_multihashmap_get (h->neighbours, &peer->hashPubKey);
324} 323}
325 324
326 325
@@ -337,21 +336,20 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
337 336
338#if DEBUG_TRANSPORT 337#if DEBUG_TRANSPORT
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 "Creating entry for neighbour `%4s'.\n", 339 "Creating entry for neighbour `%4s'.\n", GNUNET_i2s (pid));
341 GNUNET_i2s (pid));
342#endif 340#endif
343 n = GNUNET_malloc (sizeof (struct Neighbour)); 341 n = GNUNET_malloc (sizeof (struct Neighbour));
344 n->id = *pid; 342 n->id = *pid;
345 n->h = h; 343 n->h = h;
346 n->is_ready = GNUNET_YES; 344 n->is_ready = GNUNET_YES;
347 GNUNET_BANDWIDTH_tracker_init (&n->out_tracker, 345 GNUNET_BANDWIDTH_tracker_init (&n->out_tracker,
348 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 346 GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT,
349 MAX_BANDWIDTH_CARRY_S); 347 MAX_BANDWIDTH_CARRY_S);
350 GNUNET_assert (GNUNET_OK == 348 GNUNET_assert (GNUNET_OK ==
351 GNUNET_CONTAINER_multihashmap_put (h->neighbours, 349 GNUNET_CONTAINER_multihashmap_put (h->neighbours,
352 &pid->hashPubKey, 350 &pid->hashPubKey,
353 n, 351 n,
354 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 352 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
355 return n; 353 return n;
356} 354}
357 355
@@ -367,22 +365,18 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h,
367 * GNUNET_NO if not. 365 * GNUNET_NO if not.
368 */ 366 */
369static int 367static int
370neighbour_delete (void *cls, 368neighbour_delete (void *cls, const GNUNET_HashCode * key, void *value)
371 const GNUNET_HashCode * key,
372 void *value)
373{ 369{
374 struct GNUNET_TRANSPORT_Handle *handle = cls; 370 struct GNUNET_TRANSPORT_Handle *handle = cls;
375 struct Neighbour *n = value; 371 struct Neighbour *n = value;
376 372
377 if (NULL != handle->nd_cb) 373 if (NULL != handle->nd_cb)
378 handle->nd_cb (handle->cls, 374 handle->nd_cb (handle->cls, &n->id);
379 &n->id);
380 GNUNET_assert (NULL == n->th); 375 GNUNET_assert (NULL == n->th);
381 GNUNET_assert (NULL == n->hn); 376 GNUNET_assert (NULL == n->hn);
382 GNUNET_assert (GNUNET_YES == 377 GNUNET_assert (GNUNET_YES ==
383 GNUNET_CONTAINER_multihashmap_remove (handle->neighbours, 378 GNUNET_CONTAINER_multihashmap_remove (handle->neighbours,
384 key, 379 key, n));
385 n));
386 GNUNET_free (n); 380 GNUNET_free (n);
387 return GNUNET_YES; 381 return GNUNET_YES;
388} 382}
@@ -395,8 +389,7 @@ neighbour_delete (void *cls,
395 * @param msg message received, NULL on timeout or fatal error 389 * @param msg message received, NULL on timeout or fatal error
396 */ 390 */
397static void 391static void
398demultiplexer (void *cls, 392demultiplexer (void *cls, const struct GNUNET_MessageHeader *msg)
399 const struct GNUNET_MessageHeader *msg)
400{ 393{
401 struct GNUNET_TRANSPORT_Handle *h = cls; 394 struct GNUNET_TRANSPORT_Handle *h = cls;
402 const struct DisconnectInfoMessage *dim; 395 const struct DisconnectInfoMessage *dim;
@@ -413,177 +406,171 @@ demultiplexer (void *cls,
413 406
414 GNUNET_assert (h->client != NULL); 407 GNUNET_assert (h->client != NULL);
415 if (msg == NULL) 408 if (msg == NULL)
416 { 409 {
417#if DEBUG_TRANSPORT 410#if DEBUG_TRANSPORT
418 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 411 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
419 "Error receiving from transport service, disconnecting temporarily.\n"); 412 "Error receiving from transport service, disconnecting temporarily.\n");
420#endif 413#endif
421 disconnect_and_schedule_reconnect (h); 414 disconnect_and_schedule_reconnect (h);
422 return; 415 return;
423 } 416 }
424 GNUNET_CLIENT_receive (h->client, 417 GNUNET_CLIENT_receive (h->client,
425 &demultiplexer, h, 418 &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL);
426 GNUNET_TIME_UNIT_FOREVER_REL);
427 size = ntohs (msg->size); 419 size = ntohs (msg->size);
428 switch (ntohs (msg->type)) 420 switch (ntohs (msg->type))
421 {
422 case GNUNET_MESSAGE_TYPE_HELLO:
423 if (GNUNET_OK !=
424 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
429 { 425 {
430 case GNUNET_MESSAGE_TYPE_HELLO: 426 GNUNET_break (0);
431 if (GNUNET_OK != 427 break;
432 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, 428 }
433 &me))
434 {
435 GNUNET_break (0);
436 break;
437 }
438#if DEBUG_TRANSPORT 429#if DEBUG_TRANSPORT
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Receiving (my own) `%s' message, I am `%4s'.\n", 431 "Receiving (my own) `%s' message, I am `%4s'.\n",
441 "HELLO", GNUNET_i2s (&me)); 432 "HELLO", GNUNET_i2s (&me));
442#endif 433#endif
443 GNUNET_free_non_null (h->my_hello); 434 GNUNET_free_non_null (h->my_hello);
444 h->my_hello = NULL; 435 h->my_hello = NULL;
445 if (size < sizeof (struct GNUNET_MessageHeader)) 436 if (size < sizeof (struct GNUNET_MessageHeader))
446 { 437 {
447 GNUNET_break (0); 438 GNUNET_break (0);
448 break; 439 break;
449 } 440 }
450 h->my_hello = GNUNET_malloc (size); 441 h->my_hello = GNUNET_malloc (size);
451 memcpy (h->my_hello, msg, size); 442 memcpy (h->my_hello, msg, size);
452 hwl = h->hwl_head; 443 hwl = h->hwl_head;
453 while (NULL != hwl) 444 while (NULL != hwl)
454 { 445 {
455 next_hwl = hwl->next; 446 next_hwl = hwl->next;
456 hwl->rec (hwl->rec_cls, 447 hwl->rec (hwl->rec_cls,
457 (const struct GNUNET_MessageHeader *) h->my_hello); 448 (const struct GNUNET_MessageHeader *) h->my_hello);
458 hwl = next_hwl; 449 hwl = next_hwl;
459 } 450 }
451 break;
452 case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT:
453 if (size < sizeof (struct ConnectInfoMessage))
454 {
455 GNUNET_break (0);
456 break;
457 }
458 cim = (const struct ConnectInfoMessage *) msg;
459 ats_count = ntohl (cim->ats_count);
460 if (size !=
461 sizeof (struct ConnectInfoMessage) +
462 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))
463 {
464 GNUNET_break (0);
460 break; 465 break;
461 case GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT: 466 }
462 if (size < sizeof (struct ConnectInfoMessage))
463 {
464 GNUNET_break (0);
465 break;
466 }
467 cim = (const struct ConnectInfoMessage *) msg;
468 ats_count = ntohl (cim->ats_count);
469 if (size != sizeof (struct ConnectInfoMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information))
470 {
471 GNUNET_break (0);
472 break;
473 }
474#if DEBUG_TRANSPORT 467#if DEBUG_TRANSPORT
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
476 "Receiving `%s' message for `%4s'.\n", 469 "Receiving `%s' message for `%4s'.\n",
477 "CONNECT", GNUNET_i2s (&cim->id)); 470 "CONNECT", GNUNET_i2s (&cim->id));
478#endif 471#endif
479 n = neighbour_find (h, &cim->id); 472 n = neighbour_find (h, &cim->id);
480 if (n != NULL) 473 if (n != NULL)
481 { 474 {
482 GNUNET_break (0); 475 GNUNET_break (0);
483 break; 476 break;
484 } 477 }
485 n = neighbour_add (h, &cim->id); 478 n = neighbour_add (h, &cim->id);
486 if (h->nc_cb != NULL) 479 if (h->nc_cb != NULL)
487 h->nc_cb (h->cls, &n->id, 480 h->nc_cb (h->cls, &n->id, &cim->ats, ats_count);
488 &cim->ats, ats_count); 481 break;
482 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT:
483 if (size != sizeof (struct DisconnectInfoMessage))
484 {
485 GNUNET_break (0);
489 break; 486 break;
490 case GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT: 487 }
491 if (size != sizeof (struct DisconnectInfoMessage)) 488 dim = (const struct DisconnectInfoMessage *) msg;
492 { 489 GNUNET_break (ntohl (dim->reserved) == 0);
493 GNUNET_break (0);
494 break;
495 }
496 dim = (const struct DisconnectInfoMessage *) msg;
497 GNUNET_break (ntohl (dim->reserved) == 0);
498#if DEBUG_TRANSPORT_DISCONNECT 490#if DEBUG_TRANSPORT_DISCONNECT
499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
500 "Receiving `%s' message for `%4s'.\n", 492 "Receiving `%s' message for `%4s'.\n",
501 "DISCONNECT", 493 "DISCONNECT", GNUNET_i2s (&dim->peer));
502 GNUNET_i2s (&dim->peer));
503#endif 494#endif
504 n = neighbour_find (h, &dim->peer); 495 n = neighbour_find (h, &dim->peer);
505 if (n == NULL) 496 if (n == NULL)
506 { 497 {
507 GNUNET_break (0); 498 GNUNET_break (0);
508 break; 499 break;
509 } 500 }
510 neighbour_delete (h, &dim->peer.hashPubKey, n); 501 neighbour_delete (h, &dim->peer.hashPubKey, n);
502 break;
503 case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK:
504 if (size != sizeof (struct SendOkMessage))
505 {
506 GNUNET_break (0);
511 break; 507 break;
512 case GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK: 508 }
513 if (size != sizeof (struct SendOkMessage)) 509 okm = (const struct SendOkMessage *) msg;
514 {
515 GNUNET_break (0);
516 break;
517 }
518 okm = (const struct SendOkMessage *) msg;
519#if DEBUG_TRANSPORT 510#if DEBUG_TRANSPORT
520 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
521 "Receiving `%s' message, transmission %s.\n", "SEND_OK", 512 "Receiving `%s' message, transmission %s.\n", "SEND_OK",
522 ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed"); 513 ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
523#endif 514#endif
524 n = neighbour_find (h, &okm->peer); 515 n = neighbour_find (h, &okm->peer);
525 if (n == NULL) 516 if (n == NULL)
526 break;
527 GNUNET_break (GNUNET_NO == n->is_ready);
528 n->is_ready = GNUNET_YES;
529 if ( (n->th != NULL) &&
530 (n->hn == NULL) )
531 {
532 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task);
533 GNUNET_SCHEDULER_cancel (n->th->timeout_task);
534 n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
535 /* we've been waiting for this (congestion, not quota,
536 caused delayed transmission) */
537 n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap,
538 n, 0);
539 schedule_transmission (h);
540 }
541 break; 517 break;
542 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV: 518 GNUNET_break (GNUNET_NO == n->is_ready);
519 n->is_ready = GNUNET_YES;
520 if ((n->th != NULL) && (n->hn == NULL))
521 {
522 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != n->th->timeout_task);
523 GNUNET_SCHEDULER_cancel (n->th->timeout_task);
524 n->th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
525 /* we've been waiting for this (congestion, not quota,
526 * caused delayed transmission) */
527 n->hn = GNUNET_CONTAINER_heap_insert (h->ready_heap, n, 0);
528 schedule_transmission (h);
529 }
530 break;
531 case GNUNET_MESSAGE_TYPE_TRANSPORT_RECV:
543#if DEBUG_TRANSPORT 532#if DEBUG_TRANSPORT
544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving `%s' message.\n", "RECV");
545 "Receiving `%s' message.\n", "RECV");
546#endif 534#endif
547 if (size < 535 if (size <
548 sizeof (struct InboundMessage) + 536 sizeof (struct InboundMessage) + sizeof (struct GNUNET_MessageHeader))
549 sizeof (struct GNUNET_MessageHeader)) 537 {
550 { 538 GNUNET_break (0);
551 GNUNET_break (0); 539 break;
552 break; 540 }
553 } 541 im = (const struct InboundMessage *) msg;
554 im = (const struct InboundMessage *) msg; 542 GNUNET_break (0 == ntohl (im->reserved));
555 GNUNET_break (0 == ntohl (im->reserved)); 543 ats_count = ntohl (im->ats_count);
556 ats_count = ntohl(im->ats_count); 544 imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count + 1]);
557 imm = (const struct GNUNET_MessageHeader *) &((&(im->ats))[ats_count+1]); 545
558 546 if (ntohs (imm->size) + sizeof (struct InboundMessage) +
559 if (ntohs (imm->size) + sizeof (struct InboundMessage) + ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size) 547 ats_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) != size)
560 { 548 {
561 GNUNET_break (0); 549 GNUNET_break (0);
562 break; 550 break;
563 } 551 }
564#if DEBUG_TRANSPORT 552#if DEBUG_TRANSPORT
565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
566 "Received message of type %u from `%4s'.\n", 554 "Received message of type %u from `%4s'.\n",
567 ntohs (imm->type), GNUNET_i2s (&im->peer)); 555 ntohs (imm->type), GNUNET_i2s (&im->peer));
568#endif 556#endif
569 n = neighbour_find (h, &im->peer); 557 n = neighbour_find (h, &im->peer);
570 if (n == NULL) 558 if (n == NULL)
571 { 559 {
572 GNUNET_break (0);
573 break;
574 }
575 if (h->rec != NULL)
576 h->rec (h->cls, &im->peer, imm,
577 &im->ats, ats_count);
578 break;
579 default:
580 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
581 _
582 ("Received unexpected message of type %u in %s:%u\n"),
583 ntohs (msg->type), __FILE__, __LINE__);
584 GNUNET_break (0); 560 GNUNET_break (0);
585 break; 561 break;
586 } 562 }
563 if (h->rec != NULL)
564 h->rec (h->cls, &im->peer, imm, &im->ats, ats_count);
565 break;
566 default:
567 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
568 _
569 ("Received unexpected message of type %u in %s:%u\n"),
570 ntohs (msg->type), __FILE__, __LINE__);
571 GNUNET_break (0);
572 break;
573 }
587} 574}
588 575
589 576
@@ -596,7 +583,8 @@ demultiplexer (void *cls,
596 */ 583 */
597static void 584static void
598timeout_request_due_to_congestion (void *cls, 585timeout_request_due_to_congestion (void *cls,
599 const struct GNUNET_SCHEDULER_TaskContext *tc) 586 const struct GNUNET_SCHEDULER_TaskContext
587 *tc)
600{ 588{
601 struct GNUNET_TRANSPORT_TransmitHandle *th = cls; 589 struct GNUNET_TRANSPORT_TransmitHandle *th = cls;
602 struct Neighbour *n = th->neighbour; 590 struct Neighbour *n = th->neighbour;
@@ -633,77 +621,78 @@ transport_notify_ready (void *cls, size_t size, void *buf)
633 GNUNET_assert (NULL != h->client); 621 GNUNET_assert (NULL != h->client);
634 h->cth = NULL; 622 h->cth = NULL;
635 if (NULL == buf) 623 if (NULL == buf)
636 { 624 {
637 /* transmission failed */ 625 /* transmission failed */
638 disconnect_and_schedule_reconnect (h); 626 disconnect_and_schedule_reconnect (h);
639 return 0; 627 return 0;
640 } 628 }
641 629
642 cbuf = buf; 630 cbuf = buf;
643 ret = 0; 631 ret = 0;
644 /* first send control messages */ 632 /* first send control messages */
645 while ( (NULL != (th = h->control_head)) && 633 while ((NULL != (th = h->control_head)) && (th->notify_size <= size))
646 (th->notify_size <= size) ) 634 {
647 { 635 GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
648 GNUNET_CONTAINER_DLL_remove (h->control_head, 636 nret = th->notify (th->notify_cls, size, &cbuf[ret]);
649 h->control_tail,
650 th);
651 nret = th->notify (th->notify_cls, size, &cbuf[ret]);
652#if DEBUG_TRANSPORT 637#if DEBUG_TRANSPORT
653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 638 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
654 "Added %u bytes of control message at %u\n", 639 "Added %u bytes of control message at %u\n", nret, ret);
655 nret,
656 ret);
657#endif 640#endif
658 GNUNET_free (th); 641 GNUNET_free (th);
659 ret += nret; 642 ret += nret;
660 size -= nret; 643 size -= nret;
661 } 644 }
662 645
663 /* then, if possible and no control messages pending, send data messages */ 646 /* then, if possible and no control messages pending, send data messages */
664 while ( (NULL == h->control_head) && 647 while ((NULL == h->control_head) &&
665 (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) ) 648 (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))))
649 {
650 if (GNUNET_YES != n->is_ready)
666 { 651 {
667 if (GNUNET_YES != n->is_ready) 652 /* peer not ready, wait for notification! */
668 {
669 /* peer not ready, wait for notification! */
670 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
671 n->hn = NULL;
672 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task);
673 n->th->timeout_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (n->th->timeout),
674 &timeout_request_due_to_congestion,
675 n->th);
676 continue;
677 }
678 th = n->th;
679 if (th->notify_size + sizeof (struct OutboundMessage) > size)
680 break; /* does not fit */
681 if (GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, th->notify_size).rel_value > 0)
682 break; /* too early */
683 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); 653 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
684 n->hn = NULL; 654 n->hn = NULL;
685 n->th = NULL; 655 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->th->timeout_task);
686 n->is_ready = GNUNET_NO; 656 n->th->timeout_task =
687 GNUNET_assert (size >= sizeof (struct OutboundMessage)); 657 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
688 mret = th->notify (th->notify_cls, 658 (n->th->timeout),
689 size - sizeof (struct OutboundMessage), 659 &timeout_request_due_to_congestion,
690 &cbuf[ret + sizeof (struct OutboundMessage)]); 660 n->th);
691 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage)); 661 continue;
692 if (mret != 0) 662 }
693 { 663 th = n->th;
694 GNUNET_assert (mret + sizeof (struct OutboundMessage) < GNUNET_SERVER_MAX_MESSAGE_SIZE); 664 if (th->notify_size + sizeof (struct OutboundMessage) > size)
695 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND); 665 break; /* does not fit */
696 obm.header.size = htons (mret + sizeof (struct OutboundMessage)); 666 if (GNUNET_BANDWIDTH_tracker_get_delay
697 obm.priority = htonl (th->priority); 667 (&n->out_tracker, th->notify_size).rel_value > 0)
698 obm.timeout = GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining (th->timeout)); 668 break; /* too early */
699 obm.peer = n->id; 669 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
700 memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage)); 670 n->hn = NULL;
701 ret += (mret + sizeof (struct OutboundMessage)); 671 n->th = NULL;
702 size -= (mret + sizeof (struct OutboundMessage)); 672 n->is_ready = GNUNET_NO;
703 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret); 673 GNUNET_assert (size >= sizeof (struct OutboundMessage));
704 } 674 mret = th->notify (th->notify_cls,
705 GNUNET_free (th); 675 size - sizeof (struct OutboundMessage),
676 &cbuf[ret + sizeof (struct OutboundMessage)]);
677 GNUNET_assert (mret <= size - sizeof (struct OutboundMessage));
678 if (mret != 0)
679 {
680 GNUNET_assert (mret + sizeof (struct OutboundMessage) <
681 GNUNET_SERVER_MAX_MESSAGE_SIZE);
682 obm.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_SEND);
683 obm.header.size = htons (mret + sizeof (struct OutboundMessage));
684 obm.priority = htonl (th->priority);
685 obm.timeout =
686 GNUNET_TIME_relative_hton (GNUNET_TIME_absolute_get_remaining
687 (th->timeout));
688 obm.peer = n->id;
689 memcpy (&cbuf[ret], &obm, sizeof (struct OutboundMessage));
690 ret += (mret + sizeof (struct OutboundMessage));
691 size -= (mret + sizeof (struct OutboundMessage));
692 GNUNET_BANDWIDTH_tracker_consume (&n->out_tracker, mret);
706 } 693 }
694 GNUNET_free (th);
695 }
707 /* if there are more pending messages, try to schedule those */ 696 /* if there are more pending messages, try to schedule those */
708 schedule_transmission (h); 697 schedule_transmission (h);
709#if DEBUG_TRANSPORT 698#if DEBUG_TRANSPORT
@@ -723,7 +712,7 @@ transport_notify_ready (void *cls, size_t size, void *buf)
723 */ 712 */
724static void 713static void
725schedule_transmission_task (void *cls, 714schedule_transmission_task (void *cls,
726 const struct GNUNET_SCHEDULER_TaskContext *tc) 715 const struct GNUNET_SCHEDULER_TaskContext *tc)
727{ 716{
728 struct GNUNET_TRANSPORT_Handle *h = cls; 717 struct GNUNET_TRANSPORT_Handle *h = cls;
729 size_t size; 718 size_t size;
@@ -733,48 +722,45 @@ schedule_transmission_task (void *cls,
733 h->quota_task = GNUNET_SCHEDULER_NO_TASK; 722 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
734 GNUNET_assert (NULL != h->client); 723 GNUNET_assert (NULL != h->client);
735 /* destroy all requests that have timed out */ 724 /* destroy all requests that have timed out */
736 while ( (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) && 725 while ((NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) &&
737 (GNUNET_TIME_absolute_get_remaining (n->th->timeout).rel_value == 0) ) 726 (GNUNET_TIME_absolute_get_remaining (n->th->timeout).rel_value == 0))
738 { 727 {
739 /* notify client that the request could not be satisfied within 728 /* notify client that the request could not be satisfied within
740 the given time constraints */ 729 * the given time constraints */
741 th = n->th; 730 th = n->th;
742 n->th = NULL; 731 n->th = NULL;
743 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap)); 732 GNUNET_assert (n == GNUNET_CONTAINER_heap_remove_root (h->ready_heap));
744 n->hn = NULL; 733 n->hn = NULL;
745#if DEBUG_TRANSPORT 734#if DEBUG_TRANSPORT
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
747 "Signalling timeout for transmission to peer %s due to congestion\n", 736 "Signalling timeout for transmission to peer %s due to congestion\n",
748 GNUNET_i2s (&n->id)); 737 GNUNET_i2s (&n->id));
749#endif 738#endif
750 GNUNET_assert (0 == 739 GNUNET_assert (0 == th->notify (th->notify_cls, 0, NULL));
751 th->notify (th->notify_cls, 0, NULL)); 740 GNUNET_free (th);
752 GNUNET_free (th); 741 }
753 }
754 if (NULL != h->cth) 742 if (NULL != h->cth)
755 return; 743 return;
756 if (NULL != h->control_head) 744 if (NULL != h->control_head)
757 { 745 {
758 size = h->control_head->notify_size; 746 size = h->control_head->notify_size;
759 } 747 }
760 else 748 else
761 { 749 {
762 n = GNUNET_CONTAINER_heap_peek (h->ready_heap); 750 n = GNUNET_CONTAINER_heap_peek (h->ready_heap);
763 if (NULL == n) 751 if (NULL == n)
764 return; /* no pending messages */ 752 return; /* no pending messages */
765 size = n->th->notify_size + sizeof (struct OutboundMessage); 753 size = n->th->notify_size + sizeof (struct OutboundMessage);
766 } 754 }
767#if DEBUG_TRANSPORT 755#if DEBUG_TRANSPORT
768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 756 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Calling notify_transmit_ready\n");
769 "Calling notify_transmit_ready\n");
770#endif 757#endif
771 h->cth = 758 h->cth =
772 GNUNET_CLIENT_notify_transmit_ready (h->client, 759 GNUNET_CLIENT_notify_transmit_ready (h->client,
773 size, 760 size,
774 GNUNET_TIME_UNIT_FOREVER_REL, 761 GNUNET_TIME_UNIT_FOREVER_REL,
775 GNUNET_NO, 762 GNUNET_NO,
776 &transport_notify_ready, 763 &transport_notify_ready, h);
777 h);
778 GNUNET_assert (NULL != h->cth); 764 GNUNET_assert (NULL != h->cth);
779} 765}
780 766
@@ -793,22 +779,23 @@ schedule_transmission (struct GNUNET_TRANSPORT_Handle *h)
793 779
794 GNUNET_assert (NULL != h->client); 780 GNUNET_assert (NULL != h->client);
795 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK) 781 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
796 { 782 {
797 GNUNET_SCHEDULER_cancel (h->quota_task); 783 GNUNET_SCHEDULER_cancel (h->quota_task);
798 h->quota_task = GNUNET_SCHEDULER_NO_TASK; 784 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
799 } 785 }
800 if (NULL != h->control_head) 786 if (NULL != h->control_head)
801 delay = GNUNET_TIME_UNIT_ZERO; 787 delay = GNUNET_TIME_UNIT_ZERO;
802 else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap))) 788 else if (NULL != (n = GNUNET_CONTAINER_heap_peek (h->ready_heap)))
803 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, n->th->notify_size); 789 delay =
790 GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker,
791 n->th->notify_size);
804 else 792 else
805 return; /* no work to be done */ 793 return; /* no work to be done */
806 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
807 "Scheduling next transmission to service in %llu ms\n", 795 "Scheduling next transmission to service in %llu ms\n",
808 (unsigned long long) delay.rel_value); 796 (unsigned long long) delay.rel_value);
809 h->quota_task = GNUNET_SCHEDULER_add_delayed (delay, 797 h->quota_task = GNUNET_SCHEDULER_add_delayed (delay,
810 &schedule_transmission_task, 798 &schedule_transmission_task, h);
811 h);
812} 799}
813 800
814 801
@@ -831,16 +818,13 @@ schedule_control_transmit (struct GNUNET_TRANSPORT_Handle *h,
831 818
832#if DEBUG_TRANSPORT 819#if DEBUG_TRANSPORT
833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 820 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
834 "Control transmit of %u bytes requested\n", 821 "Control transmit of %u bytes requested\n", size);
835 size);
836#endif 822#endif
837 th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); 823 th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle));
838 th->notify = notify; 824 th->notify = notify;
839 th->notify_cls = notify_cls; 825 th->notify_cls = notify_cls;
840 th->notify_size = size; 826 th->notify_size = size;
841 GNUNET_CONTAINER_DLL_insert_tail (h->control_head, 827 GNUNET_CONTAINER_DLL_insert_tail (h->control_head, h->control_tail, th);
842 h->control_tail,
843 th);
844 schedule_transmission (h); 828 schedule_transmission (h);
845} 829}
846 830
@@ -860,18 +844,16 @@ send_start (void *cls, size_t size, void *buf)
860 struct StartMessage s; 844 struct StartMessage s;
861 845
862 if (buf == NULL) 846 if (buf == NULL)
863 { 847 {
864 /* Can only be shutdown, just give up */ 848 /* Can only be shutdown, just give up */
865#if DEBUG_TRANSPORT 849#if DEBUG_TRANSPORT
866 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 850 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
867 "Shutdown while trying to transmit `%s' request.\n", 851 "Shutdown while trying to transmit `%s' request.\n", "START");
868 "START");
869#endif 852#endif
870 return 0; 853 return 0;
871 } 854 }
872#if DEBUG_TRANSPORT 855#if DEBUG_TRANSPORT
873 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "START");
874 "Transmitting `%s' request.\n", "START");
875#endif 857#endif
876 GNUNET_assert (size >= sizeof (struct StartMessage)); 858 GNUNET_assert (size >= sizeof (struct StartMessage));
877 s.header.size = htons (sizeof (struct StartMessage)); 859 s.header.size = htons (sizeof (struct StartMessage));
@@ -892,29 +874,25 @@ send_start (void *cls, size_t size, void *buf)
892 * @param tc scheduler context 874 * @param tc scheduler context
893 */ 875 */
894static void 876static void
895reconnect (void *cls, 877reconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
896 const struct GNUNET_SCHEDULER_TaskContext *tc)
897{ 878{
898 struct GNUNET_TRANSPORT_Handle *h = cls; 879 struct GNUNET_TRANSPORT_Handle *h = cls;
899 880
900 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 881 h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
901 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 882 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
902 { 883 {
903 /* shutdown, just give up */ 884 /* shutdown, just give up */
904 return; 885 return;
905 } 886 }
906#if DEBUG_TRANSPORT 887#if DEBUG_TRANSPORT
907 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 888 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
908 "Connecting to transport service.\n");
909#endif 889#endif
910 GNUNET_assert (h->client == NULL); 890 GNUNET_assert (h->client == NULL);
911 GNUNET_assert (h->control_head == NULL); 891 GNUNET_assert (h->control_head == NULL);
912 GNUNET_assert (h->control_tail == NULL); 892 GNUNET_assert (h->control_tail == NULL);
913 h->client = GNUNET_CLIENT_connect ("transport", h->cfg); 893 h->client = GNUNET_CLIENT_connect ("transport", h->cfg);
914 GNUNET_assert (h->client != NULL); 894 GNUNET_assert (h->client != NULL);
915 schedule_control_transmit (h, 895 schedule_control_transmit (h, sizeof (struct StartMessage), &send_start, h);
916 sizeof (struct StartMessage),
917 &send_start, h);
918} 896}
919 897
920 898
@@ -931,50 +909,45 @@ disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_Handle *h)
931 909
932 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK); 910 GNUNET_assert (h->reconnect_task == GNUNET_SCHEDULER_NO_TASK);
933 /* Forget about all neighbours that we used to be connected to */ 911 /* Forget about all neighbours that we used to be connected to */
934 GNUNET_CONTAINER_multihashmap_iterate(h->neighbours, 912 GNUNET_CONTAINER_multihashmap_iterate (h->neighbours, &neighbour_delete, h);
935 &neighbour_delete,
936 h);
937 if (NULL != h->cth) 913 if (NULL != h->cth)
938 { 914 {
939 GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth); 915 GNUNET_CLIENT_notify_transmit_ready_cancel (h->cth);
940 h->cth = NULL; 916 h->cth = NULL;
941 } 917 }
942 if (NULL != h->client) 918 if (NULL != h->client)
943 { 919 {
944 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES); 920 GNUNET_CLIENT_disconnect (h->client, GNUNET_YES);
945 h->client = NULL; 921 h->client = NULL;
946 } 922 }
947 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK) 923 if (h->quota_task != GNUNET_SCHEDULER_NO_TASK)
948 { 924 {
949 GNUNET_SCHEDULER_cancel (h->quota_task); 925 GNUNET_SCHEDULER_cancel (h->quota_task);
950 h->quota_task = GNUNET_SCHEDULER_NO_TASK; 926 h->quota_task = GNUNET_SCHEDULER_NO_TASK;
951 } 927 }
952 while ( (NULL != (th = h->control_head))) 928 while ((NULL != (th = h->control_head)))
953 { 929 {
954 GNUNET_CONTAINER_DLL_remove (h->control_head, 930 GNUNET_CONTAINER_DLL_remove (h->control_head, h->control_tail, th);
955 h->control_tail, 931 th->notify (th->notify_cls, 0, NULL);
956 th); 932 GNUNET_free (th);
957 th->notify (th->notify_cls, 0, NULL); 933 }
958 GNUNET_free (th);
959 }
960#if DEBUG_TRANSPORT 934#if DEBUG_TRANSPORT
961 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 935 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
962 "Scheduling task to reconnect to transport service in %llu ms.\n", 936 "Scheduling task to reconnect to transport service in %llu ms.\n",
963 h->reconnect_delay.rel_value); 937 h->reconnect_delay.rel_value);
964#endif 938#endif
965 h->reconnect_task 939 h->reconnect_task
966 = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, 940 = GNUNET_SCHEDULER_add_delayed (h->reconnect_delay, &reconnect, h);
967 &reconnect, h);
968 if (h->reconnect_delay.rel_value == 0) 941 if (h->reconnect_delay.rel_value == 0)
969 { 942 {
970 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS; 943 h->reconnect_delay = GNUNET_TIME_UNIT_MILLISECONDS;
971 } 944 }
972 else 945 else
973 { 946 {
974 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2); 947 h->reconnect_delay = GNUNET_TIME_relative_multiply (h->reconnect_delay, 2);
975 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS, 948 h->reconnect_delay = GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
976 h->reconnect_delay); 949 h->reconnect_delay);
977 } 950 }
978} 951}
979 952
980 953
@@ -1011,15 +984,14 @@ send_set_quota (void *cls, size_t size, void *buf)
1011 struct QuotaSetMessage msg; 984 struct QuotaSetMessage msg;
1012 985
1013 if (buf == NULL) 986 if (buf == NULL)
1014 { 987 {
1015 GNUNET_free (sqc); 988 GNUNET_free (sqc);
1016 return 0; 989 return 0;
1017 } 990 }
1018#if DEBUG_TRANSPORT 991#if DEBUG_TRANSPORT
1019 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 992 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1020 "Transmitting `%s' request with respect to `%4s'.\n", 993 "Transmitting `%s' request with respect to `%4s'.\n",
1021 "SET_QUOTA", 994 "SET_QUOTA", GNUNET_i2s (&sqc->target));
1022 GNUNET_i2s (&sqc->target));
1023#endif 995#endif
1024 GNUNET_assert (size >= sizeof (struct QuotaSetMessage)); 996 GNUNET_assert (size >= sizeof (struct QuotaSetMessage));
1025 msg.header.size = htons (sizeof (struct QuotaSetMessage)); 997 msg.header.size = htons (sizeof (struct QuotaSetMessage));
@@ -1049,32 +1021,29 @@ GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
1049{ 1021{
1050 struct Neighbour *n; 1022 struct Neighbour *n;
1051 struct SetQuotaContext *sqc; 1023 struct SetQuotaContext *sqc;
1052 1024
1053 n = neighbour_find (handle, target); 1025 n = neighbour_find (handle, target);
1054 if (NULL == n) 1026 if (NULL == n)
1055 { 1027 {
1056 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1028 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1057 "Quota changed to %u for peer `%s', but I have no such neighbour!\n", 1029 "Quota changed to %u for peer `%s', but I have no such neighbour!\n",
1058 (unsigned int) ntohl (quota_out.value__), 1030 (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
1059 GNUNET_i2s (target)); 1031 return;
1060 return; 1032 }
1061 }
1062 GNUNET_assert (NULL != handle->client); 1033 GNUNET_assert (NULL != handle->client);
1063#if DEBUG_TRANSPORT 1034#if DEBUG_TRANSPORT
1064 if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__) 1035 if (ntohl (quota_out.value__) != n->out_tracker.available_bytes_per_s__)
1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1036 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1066 "Quota changed from %u to %u for peer `%s'\n", 1037 "Quota changed from %u to %u for peer `%s'\n",
1067 (unsigned int) n->out_tracker.available_bytes_per_s__, 1038 (unsigned int) n->out_tracker.available_bytes_per_s__,
1068 (unsigned int) ntohl (quota_out.value__), 1039 (unsigned int) ntohl (quota_out.value__), GNUNET_i2s (target));
1069 GNUNET_i2s (target));
1070 else 1040 else
1071 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1041 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1072 "Quota remains at %u for peer `%s'\n", 1042 "Quota remains at %u for peer `%s'\n",
1073 (unsigned int) n->out_tracker.available_bytes_per_s__, 1043 (unsigned int) n->out_tracker.available_bytes_per_s__,
1074 GNUNET_i2s (target)); 1044 GNUNET_i2s (target));
1075#endif 1045#endif
1076 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, 1046 GNUNET_BANDWIDTH_tracker_update_quota (&n->out_tracker, quota_out);
1077 quota_out);
1078 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext)); 1047 sqc = GNUNET_malloc (sizeof (struct SetQuotaContext));
1079 sqc->target = *target; 1048 sqc->target = *target;
1080 sqc->quota_in = quota_in; 1049 sqc->quota_in = quota_in;
@@ -1099,15 +1068,14 @@ send_try_connect (void *cls, size_t size, void *buf)
1099 struct TransportRequestConnectMessage msg; 1068 struct TransportRequestConnectMessage msg;
1100 1069
1101 if (buf == NULL) 1070 if (buf == NULL)
1102 { 1071 {
1103 GNUNET_free (pid); 1072 GNUNET_free (pid);
1104 return 0; 1073 return 0;
1105 } 1074 }
1106#if DEBUG_TRANSPORT 1075#if DEBUG_TRANSPORT
1107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1076 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1108 "Transmitting `%s' request with respect to `%4s'.\n", 1077 "Transmitting `%s' request with respect to `%4s'.\n",
1109 "REQUEST_CONNECT", 1078 "REQUEST_CONNECT", GNUNET_i2s (pid));
1110 GNUNET_i2s (pid));
1111#endif 1079#endif
1112 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage)); 1080 GNUNET_assert (size >= sizeof (struct TransportRequestConnectMessage));
1113 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage)); 1081 msg.header.size = htons (sizeof (struct TransportRequestConnectMessage));
@@ -1129,7 +1097,7 @@ send_try_connect (void *cls, size_t size, void *buf)
1129 */ 1097 */
1130void 1098void
1131GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle, 1099GNUNET_TRANSPORT_try_connect (struct GNUNET_TRANSPORT_Handle *handle,
1132 const struct GNUNET_PeerIdentity *target) 1100 const struct GNUNET_PeerIdentity *target)
1133{ 1101{
1134 struct GNUNET_PeerIdentity *pid; 1102 struct GNUNET_PeerIdentity *pid;
1135 1103
@@ -1158,18 +1126,16 @@ send_hello (void *cls, size_t size, void *buf)
1158 uint16_t ssize; 1126 uint16_t ssize;
1159 1127
1160 if (buf == NULL) 1128 if (buf == NULL)
1161 { 1129 {
1162#if DEBUG_TRANSPORT_TIMEOUT 1130#if DEBUG_TRANSPORT_TIMEOUT
1163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1164 "Timeout while trying to transmit `%s' request.\n", 1132 "Timeout while trying to transmit `%s' request.\n", "HELLO");
1165 "HELLO");
1166#endif 1133#endif
1167 GNUNET_free (msg); 1134 GNUNET_free (msg);
1168 return 0; 1135 return 0;
1169 } 1136 }
1170#if DEBUG_TRANSPORT 1137#if DEBUG_TRANSPORT
1171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting `%s' request.\n", "HELLO");
1172 "Transmitting `%s' request.\n", "HELLO");
1173#endif 1139#endif
1174 ssize = ntohs (msg->size); 1140 ssize = ntohs (msg->size);
1175 GNUNET_assert (size >= ssize); 1141 GNUNET_assert (size >= ssize);
@@ -1193,8 +1159,7 @@ send_hello (void *cls, size_t size, void *buf)
1193void 1159void
1194GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, 1160GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1195 const struct GNUNET_MessageHeader *hello, 1161 const struct GNUNET_MessageHeader *hello,
1196 GNUNET_SCHEDULER_Task cont, 1162 GNUNET_SCHEDULER_Task cont, void *cls)
1197 void *cls)
1198{ 1163{
1199 uint16_t size; 1164 uint16_t size;
1200 struct GNUNET_PeerIdentity peer; 1165 struct GNUNET_PeerIdentity peer;
@@ -1205,23 +1170,20 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
1205 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO); 1170 GNUNET_break (ntohs (hello->type) == GNUNET_MESSAGE_TYPE_HELLO);
1206 size = ntohs (hello->size); 1171 size = ntohs (hello->size);
1207 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader)); 1172 GNUNET_break (size >= sizeof (struct GNUNET_MessageHeader));
1208 if (GNUNET_OK != GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message*) hello, 1173 if (GNUNET_OK !=
1209 &peer)) 1174 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) hello, &peer))
1210 { 1175 {
1211 GNUNET_break (0); 1176 GNUNET_break (0);
1212 return; 1177 return;
1213 } 1178 }
1214 msg = GNUNET_malloc(size); 1179 msg = GNUNET_malloc (size);
1215 memcpy (msg, hello, size); 1180 memcpy (msg, hello, size);
1216#if DEBUG_TRANSPORT 1181#if DEBUG_TRANSPORT
1217 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1182 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1218 "Offering `%s' message of `%4s' to transport for validation.\n", 1183 "Offering `%s' message of `%4s' to transport for validation.\n",
1219 "HELLO", 1184 "HELLO", GNUNET_i2s (&peer));
1220 GNUNET_i2s (&peer));
1221#endif 1185#endif
1222 schedule_control_transmit (handle, 1186 schedule_control_transmit (handle, size, &send_hello, msg);
1223 size,
1224 &send_hello, msg);
1225} 1187}
1226 1188
1227 1189
@@ -1245,9 +1207,7 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
1245 hwl = GNUNET_malloc (sizeof (struct HelloWaitList)); 1207 hwl = GNUNET_malloc (sizeof (struct HelloWaitList));
1246 hwl->rec = rec; 1208 hwl->rec = rec;
1247 hwl->rec_cls = rec_cls; 1209 hwl->rec_cls = rec_cls;
1248 GNUNET_CONTAINER_DLL_insert (handle->hwl_head, 1210 GNUNET_CONTAINER_DLL_insert (handle->hwl_head, handle->hwl_tail, hwl);
1249 handle->hwl_tail,
1250 hwl);
1251 if (handle->my_hello == NULL) 1211 if (handle->my_hello == NULL)
1252 return; 1212 return;
1253 rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello); 1213 rec (rec_cls, (const struct GNUNET_MessageHeader *) handle->my_hello);
@@ -1263,25 +1223,22 @@ GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
1263 */ 1223 */
1264void 1224void
1265GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle, 1225GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
1266 GNUNET_TRANSPORT_HelloUpdateCallback rec, 1226 GNUNET_TRANSPORT_HelloUpdateCallback rec,
1267 void *rec_cls) 1227 void *rec_cls)
1268{ 1228{
1269 struct HelloWaitList *pos; 1229 struct HelloWaitList *pos;
1270 1230
1271 pos = handle->hwl_head; 1231 pos = handle->hwl_head;
1272 while (pos != NULL) 1232 while (pos != NULL)
1273 { 1233 {
1274 if ( (pos->rec == rec) && 1234 if ((pos->rec == rec) && (pos->rec_cls == rec_cls))
1275 (pos->rec_cls == rec_cls) ) 1235 break;
1276 break; 1236 pos = pos->next;
1277 pos = pos->next; 1237 }
1278 }
1279 GNUNET_break (pos != NULL); 1238 GNUNET_break (pos != NULL);
1280 if (pos == NULL) 1239 if (pos == NULL)
1281 return; 1240 return;
1282 GNUNET_CONTAINER_DLL_remove (handle->hwl_head, 1241 GNUNET_CONTAINER_DLL_remove (handle->hwl_head, handle->hwl_tail, pos);
1283 handle->hwl_tail,
1284 pos);
1285 GNUNET_free (pos); 1242 GNUNET_free (pos);
1286} 1243}
1287 1244
@@ -1300,7 +1257,7 @@ GNUNET_TRANSPORT_get_hello_cancel (struct GNUNET_TRANSPORT_Handle *handle,
1300 */ 1257 */
1301struct GNUNET_TRANSPORT_Handle * 1258struct GNUNET_TRANSPORT_Handle *
1302GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 1259GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1303 const struct GNUNET_PeerIdentity *self, 1260 const struct GNUNET_PeerIdentity *self,
1304 void *cls, 1261 void *cls,
1305 GNUNET_TRANSPORT_ReceiveCallback rec, 1262 GNUNET_TRANSPORT_ReceiveCallback rec,
1306 GNUNET_TRANSPORT_NotifyConnect nc, 1263 GNUNET_TRANSPORT_NotifyConnect nc,
@@ -1310,18 +1267,20 @@ GNUNET_TRANSPORT_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
1310 1267
1311 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle)); 1268 ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle));
1312 if (self != NULL) 1269 if (self != NULL)
1313 { 1270 {
1314 ret->self = *self; 1271 ret->self = *self;
1315 ret->check_self = GNUNET_YES; 1272 ret->check_self = GNUNET_YES;
1316 } 1273 }
1317 ret->cfg = cfg; 1274 ret->cfg = cfg;
1318 ret->cls = cls; 1275 ret->cls = cls;
1319 ret->rec = rec; 1276 ret->rec = rec;
1320 ret->nc_cb = nc; 1277 ret->nc_cb = nc;
1321 ret->nd_cb = nd; 1278 ret->nd_cb = nd;
1322 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO; 1279 ret->reconnect_delay = GNUNET_TIME_UNIT_ZERO;
1323 ret->neighbours = GNUNET_CONTAINER_multihashmap_create(STARTING_NEIGHBOURS_SIZE); 1280 ret->neighbours =
1324 ret->ready_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1281 GNUNET_CONTAINER_multihashmap_create (STARTING_NEIGHBOURS_SIZE);
1282 ret->ready_heap =
1283 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1325 ret->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, ret); 1284 ret->reconnect_task = GNUNET_SCHEDULER_add_now (&reconnect, ret);
1326 return ret; 1285 return ret;
1327} 1286}
@@ -1336,25 +1295,24 @@ void
1336GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle) 1295GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1337{ 1296{
1338#if DEBUG_TRANSPORT 1297#if DEBUG_TRANSPORT
1339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport disconnect called!\n");
1340 "Transport disconnect called!\n");
1341#endif 1299#endif
1342 /* this disconnects all neighbours... */ 1300 /* this disconnects all neighbours... */
1343 if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK) 1301 if (handle->reconnect_task == GNUNET_SCHEDULER_NO_TASK)
1344 disconnect_and_schedule_reconnect (handle); 1302 disconnect_and_schedule_reconnect (handle);
1345 /* and now we stop trying to connect again... */ 1303 /* and now we stop trying to connect again... */
1346 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK) 1304 if (handle->reconnect_task != GNUNET_SCHEDULER_NO_TASK)
1347 { 1305 {
1348 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 1306 GNUNET_SCHEDULER_cancel (handle->reconnect_task);
1349 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK; 1307 handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
1350 } 1308 }
1351 GNUNET_CONTAINER_multihashmap_destroy (handle->neighbours); 1309 GNUNET_CONTAINER_multihashmap_destroy (handle->neighbours);
1352 handle->neighbours = NULL; 1310 handle->neighbours = NULL;
1353 if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK) 1311 if (handle->quota_task != GNUNET_SCHEDULER_NO_TASK)
1354 { 1312 {
1355 GNUNET_SCHEDULER_cancel (handle->quota_task); 1313 GNUNET_SCHEDULER_cancel (handle->quota_task);
1356 handle->quota_task = GNUNET_SCHEDULER_NO_TASK; 1314 handle->quota_task = GNUNET_SCHEDULER_NO_TASK;
1357 } 1315 }
1358 GNUNET_free_non_null (handle->my_hello); 1316 GNUNET_free_non_null (handle->my_hello);
1359 handle->my_hello = NULL; 1317 handle->my_hello = NULL;
1360 GNUNET_assert (handle->hwl_head == NULL); 1318 GNUNET_assert (handle->hwl_head == NULL);
@@ -1386,31 +1344,30 @@ GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle)
1386 */ 1344 */
1387struct GNUNET_TRANSPORT_TransmitHandle * 1345struct GNUNET_TRANSPORT_TransmitHandle *
1388GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle, 1346GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1389 const struct GNUNET_PeerIdentity *target, 1347 const struct GNUNET_PeerIdentity
1390 size_t size, 1348 *target, size_t size, uint32_t priority,
1391 uint32_t priority,
1392 struct GNUNET_TIME_Relative timeout, 1349 struct GNUNET_TIME_Relative timeout,
1393 GNUNET_CONNECTION_TransmitReadyNotify notify, 1350 GNUNET_CONNECTION_TransmitReadyNotify
1394 void *notify_cls) 1351 notify, void *notify_cls)
1395{ 1352{
1396 struct Neighbour *n; 1353 struct Neighbour *n;
1397 struct GNUNET_TRANSPORT_TransmitHandle *th; 1354 struct GNUNET_TRANSPORT_TransmitHandle *th;
1398 struct GNUNET_TIME_Relative delay; 1355 struct GNUNET_TIME_Relative delay;
1399 1356
1400 n = neighbour_find (handle, target); 1357 n = neighbour_find (handle, target);
1401 if (NULL == n) 1358 if (NULL == n)
1402 { 1359 {
1403 /* use GNUNET_TRANSPORT_try_connect first, only use this function 1360 /* use GNUNET_TRANSPORT_try_connect first, only use this function
1404 once a connection has been established */ 1361 * once a connection has been established */
1405 GNUNET_assert (0); 1362 GNUNET_assert (0);
1406 return NULL; 1363 return NULL;
1407 } 1364 }
1408 if (NULL != n->th) 1365 if (NULL != n->th)
1409 { 1366 {
1410 /* attempt to send two messages at the same time to the same peer */ 1367 /* attempt to send two messages at the same time to the same peer */
1411 GNUNET_assert (0); 1368 GNUNET_assert (0);
1412 return NULL; 1369 return NULL;
1413 } 1370 }
1414 GNUNET_assert (NULL == n->hn); 1371 GNUNET_assert (NULL == n->hn);
1415 th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle)); 1372 th = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_TransmitHandle));
1416 th->neighbour = n; 1373 th->neighbour = n;
@@ -1423,16 +1380,13 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1423 /* calculate when our transmission should be ready */ 1380 /* calculate when our transmission should be ready */
1424 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size); 1381 delay = GNUNET_BANDWIDTH_tracker_get_delay (&n->out_tracker, size);
1425 if (delay.rel_value > timeout.rel_value) 1382 if (delay.rel_value > timeout.rel_value)
1426 delay.rel_value = 0; /* notify immediately (with failure) */ 1383 delay.rel_value = 0; /* notify immediately (with failure) */
1427#if DEBUG_TRANSPORT 1384#if DEBUG_TRANSPORT
1428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1429 "Bandwidth tracker allows next transmission to peer %s in %llu ms\n", 1386 "Bandwidth tracker allows next transmission to peer %s in %llu ms\n",
1430 GNUNET_i2s (target), 1387 GNUNET_i2s (target), (unsigned long long) delay.rel_value);
1431 (unsigned long long) delay.rel_value);
1432#endif 1388#endif
1433 n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap, 1389 n->hn = GNUNET_CONTAINER_heap_insert (handle->ready_heap, n, delay.rel_value);
1434 n,
1435 delay.rel_value);
1436 schedule_transmission (handle); 1390 schedule_transmission (handle);
1437 return th; 1391 return th;
1438} 1392}
@@ -1444,7 +1398,9 @@ GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle *handle,
1444 * @param th handle returned from GNUNET_TRANSPORT_notify_transmit_ready 1398 * @param th handle returned from GNUNET_TRANSPORT_notify_transmit_ready
1445 */ 1399 */
1446void 1400void
1447GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitHandle *th) 1401GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
1402 GNUNET_TRANSPORT_TransmitHandle
1403 *th)
1448{ 1404{
1449 struct Neighbour *n; 1405 struct Neighbour *n;
1450 1406
@@ -1454,17 +1410,17 @@ GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct GNUNET_TRANSPORT_TransmitH
1454 GNUNET_assert (th == n->th); 1410 GNUNET_assert (th == n->th);
1455 n->th = NULL; 1411 n->th = NULL;
1456 if (n->hn != NULL) 1412 if (n->hn != NULL)
1457 { 1413 {
1458 GNUNET_CONTAINER_heap_remove_node (n->hn); 1414 GNUNET_CONTAINER_heap_remove_node (n->hn);
1459 n->hn = NULL; 1415 n->hn = NULL;
1460 } 1416 }
1461 else 1417 else
1462 { 1418 {
1463 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != th->timeout_task); 1419 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != th->timeout_task);
1464 GNUNET_SCHEDULER_cancel (th->timeout_task); 1420 GNUNET_SCHEDULER_cancel (th->timeout_task);
1465 th->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1421 th->timeout_task = GNUNET_SCHEDULER_NO_TASK;
1466 } 1422 }
1467 GNUNET_free (th); 1423 GNUNET_free (th);
1468} 1424}
1469 1425
1470 1426
diff --git a/src/transport/transport_api_address_iterate.c b/src/transport/transport_api_address_iterate.c
index 7bbeb499d..4f442fda0 100644
--- a/src/transport/transport_api_address_iterate.c
+++ b/src/transport/transport_api_address_iterate.c
@@ -82,37 +82,37 @@ peer_address_response_processor (void *cls,
82 uint16_t size; 82 uint16_t size;
83 83
84 if (msg == NULL) 84 if (msg == NULL)
85 { 85 {
86 alucb->cb (alucb->cb_cls, NULL); 86 alucb->cb (alucb->cb_cls, NULL);
87 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 87 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
88 GNUNET_free (alucb); 88 GNUNET_free (alucb);
89 return; 89 return;
90 } 90 }
91 GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 91 GNUNET_break (ntohs (msg->type) ==
92 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
92 size = ntohs (msg->size); 93 size = ntohs (msg->size);
93 if (size == sizeof (struct GNUNET_MessageHeader)) 94 if (size == sizeof (struct GNUNET_MessageHeader))
94 { 95 {
95 /* done! */ 96 /* done! */
96 alucb->cb (alucb->cb_cls, NULL); 97 alucb->cb (alucb->cb_cls, NULL);
97 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 98 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
98 GNUNET_free (alucb); 99 GNUNET_free (alucb);
99 return; 100 return;
100 } 101 }
101 address = (const char *) &msg[1]; 102 address = (const char *) &msg[1];
102 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 103 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
103 { 104 {
104 /* invalid reply */ 105 /* invalid reply */
105 GNUNET_break (0); 106 GNUNET_break (0);
106 alucb->cb (alucb->cb_cls, NULL); 107 alucb->cb (alucb->cb_cls, NULL);
107 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 108 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
108 GNUNET_free (alucb); 109 GNUNET_free (alucb);
109 return; 110 return;
110 } 111 }
111 /* expect more replies */ 112 /* expect more replies */
112 GNUNET_CLIENT_receive (alucb->client, 113 GNUNET_CLIENT_receive (alucb->client,
113 &peer_address_response_processor, alucb, 114 &peer_address_response_processor, alucb,
114 GNUNET_TIME_absolute_get_remaining 115 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
115 (alucb->timeout));
116 alucb->cb (alucb->cb_cls, address); 116 alucb->cb (alucb->cb_cls, address);
117} 117}
118 118
@@ -128,7 +128,8 @@ peer_address_response_processor (void *cls,
128void 128void
129GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 129GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
130 struct GNUNET_TIME_Relative timeout, 130 struct GNUNET_TIME_Relative timeout,
131 GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, 131 GNUNET_TRANSPORT_AddressLookUpCallback
132 peer_address_callback,
132 void *peer_address_callback_cls) 133 void *peer_address_callback_cls)
133{ 134{
134 struct AddressIterateMessage msg; 135 struct AddressIterateMessage msg;
@@ -138,13 +139,13 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
138 139
139 client = GNUNET_CLIENT_connect ("transport", cfg); 140 client = GNUNET_CLIENT_connect ("transport", cfg);
140 if (client == NULL) 141 if (client == NULL)
141 { 142 {
142 peer_address_callback (peer_address_callback_cls, NULL); 143 peer_address_callback (peer_address_callback_cls, NULL);
143 return; 144 return;
144 } 145 }
145 abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); 146 abs_timeout = GNUNET_TIME_relative_to_absolute (timeout);
146 147
147 msg.header.size = htons (sizeof(struct AddressLookupMessage)); 148 msg.header.size = htons (sizeof (struct AddressLookupMessage));
148 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE); 149 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_ITERATE);
149 msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout); 150 msg.timeout = GNUNET_TIME_absolute_hton (abs_timeout);
150 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx)); 151 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));
@@ -153,12 +154,12 @@ GNUNET_TRANSPORT_address_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
153 peer_address_lookup_cb->timeout = abs_timeout; 154 peer_address_lookup_cb->timeout = abs_timeout;
154 peer_address_lookup_cb->client = client; 155 peer_address_lookup_cb->client = client;
155 GNUNET_assert (GNUNET_OK == 156 GNUNET_assert (GNUNET_OK ==
156 GNUNET_CLIENT_transmit_and_get_response (client, 157 GNUNET_CLIENT_transmit_and_get_response (client,
157 &msg.header, 158 &msg.header,
158 timeout, 159 timeout,
159 GNUNET_YES, 160 GNUNET_YES,
160 &peer_address_response_processor, 161 &peer_address_response_processor,
161 peer_address_lookup_cb)); 162 peer_address_lookup_cb));
162} 163}
163 164
164/* end of transport_api_address_iterate.c */ 165/* end of transport_api_address_iterate.c */
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c
index 619e60a43..4aadf10f4 100644
--- a/src/transport/transport_api_address_lookup.c
+++ b/src/transport/transport_api_address_lookup.c
@@ -62,45 +62,44 @@ struct AddressLookupCtx
62 * message with the human-readable address 62 * message with the human-readable address
63 */ 63 */
64static void 64static void
65address_response_processor (void *cls, 65address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
66 const struct GNUNET_MessageHeader *msg)
67{ 66{
68 struct AddressLookupCtx *alucb = cls; 67 struct AddressLookupCtx *alucb = cls;
69 const char *address; 68 const char *address;
70 uint16_t size; 69 uint16_t size;
71 70
72 if (msg == NULL) 71 if (msg == NULL)
73 { 72 {
74 alucb->cb (alucb->cb_cls, NULL); 73 alucb->cb (alucb->cb_cls, NULL);
75 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 74 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
76 GNUNET_free (alucb); 75 GNUNET_free (alucb);
77 return; 76 return;
78 } 77 }
79 GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 78 GNUNET_break (ntohs (msg->type) ==
79 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
80 size = ntohs (msg->size); 80 size = ntohs (msg->size);
81 if (size == sizeof (struct GNUNET_MessageHeader)) 81 if (size == sizeof (struct GNUNET_MessageHeader))
82 { 82 {
83 /* done! */ 83 /* done! */
84 alucb->cb (alucb->cb_cls, NULL); 84 alucb->cb (alucb->cb_cls, NULL);
85 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 85 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
86 GNUNET_free (alucb); 86 GNUNET_free (alucb);
87 return; 87 return;
88 } 88 }
89 address = (const char *) &msg[1]; 89 address = (const char *) &msg[1];
90 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 90 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
91 { 91 {
92 /* invalid reply */ 92 /* invalid reply */
93 GNUNET_break (0); 93 GNUNET_break (0);
94 alucb->cb (alucb->cb_cls, NULL); 94 alucb->cb (alucb->cb_cls, NULL);
95 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 95 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
96 GNUNET_free (alucb); 96 GNUNET_free (alucb);
97 return; 97 return;
98 } 98 }
99 /* expect more replies */ 99 /* expect more replies */
100 GNUNET_CLIENT_receive (alucb->client, 100 GNUNET_CLIENT_receive (alucb->client,
101 &address_response_processor, alucb, 101 &address_response_processor, alucb,
102 GNUNET_TIME_absolute_get_remaining 102 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
103 (alucb->timeout));
104 alucb->cb (alucb->cb_cls, address); 103 alucb->cb (alucb->cb_cls, address);
105} 104}
106 105
@@ -120,9 +119,9 @@ address_response_processor (void *cls,
120 */ 119 */
121void 120void
122GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, 121GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
123 const char *address, 122 const char *address,
124 size_t addressLen, 123 size_t addressLen,
125 int numeric, 124 int numeric,
126 const char *nameTrans, 125 const char *nameTrans,
127 struct GNUNET_TIME_Relative timeout, 126 struct GNUNET_TIME_Relative timeout,
128 GNUNET_TRANSPORT_AddressLookUpCallback aluc, 127 GNUNET_TRANSPORT_AddressLookUpCallback aluc,
@@ -138,17 +137,17 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
138 slen = strlen (nameTrans) + 1; 137 slen = strlen (nameTrans) + 1;
139 len = sizeof (struct AddressLookupMessage) + addressLen + slen; 138 len = sizeof (struct AddressLookupMessage) + addressLen + slen;
140 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 139 if (len >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
141 { 140 {
142 GNUNET_break (0); 141 GNUNET_break (0);
143 aluc (aluc_cls, NULL); 142 aluc (aluc_cls, NULL);
144 return; 143 return;
145 } 144 }
146 client = GNUNET_CLIENT_connect ("transport", cfg); 145 client = GNUNET_CLIENT_connect ("transport", cfg);
147 if (client == NULL) 146 if (client == NULL)
148 { 147 {
149 aluc (aluc_cls, NULL); 148 aluc (aluc_cls, NULL);
150 return; 149 return;
151 } 150 }
152 msg = GNUNET_malloc (len); 151 msg = GNUNET_malloc (len);
153 msg->header.size = htons (len); 152 msg->header.size = htons (len);
154 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); 153 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP);
@@ -164,12 +163,12 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg,
164 aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout); 163 aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout);
165 aluCB->client = client; 164 aluCB->client = client;
166 GNUNET_assert (GNUNET_OK == 165 GNUNET_assert (GNUNET_OK ==
167 GNUNET_CLIENT_transmit_and_get_response (client, 166 GNUNET_CLIENT_transmit_and_get_response (client,
168 &msg->header, 167 &msg->header,
169 timeout, 168 timeout,
170 GNUNET_YES, 169 GNUNET_YES,
171 &address_response_processor, 170 &address_response_processor,
172 aluCB)); 171 aluCB));
173 GNUNET_free (msg); 172 GNUNET_free (msg);
174} 173}
175 174
diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c
index 2315b515f..f8f430995 100644
--- a/src/transport/transport_api_blacklist.c
+++ b/src/transport/transport_api_blacklist.c
@@ -42,7 +42,7 @@ struct GNUNET_TRANSPORT_Blacklist
42 /** 42 /**
43 * Connection to transport service. 43 * Connection to transport service.
44 */ 44 */
45 struct GNUNET_CLIENT_Connection * client; 45 struct GNUNET_CLIENT_Connection *client;
46 46
47 /** 47 /**
48 * Configuration to use. 48 * Configuration to use.
@@ -78,8 +78,7 @@ struct GNUNET_TRANSPORT_Blacklist
78 * 78 *
79 * @param br overall handle 79 * @param br overall handle
80 */ 80 */
81static void 81static void reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
82reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
83 82
84 83
85/** 84/**
@@ -87,8 +86,7 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br);
87 * 86 *
88 * @param br our overall context 87 * @param br our overall context
89 */ 88 */
90static void 89static void reply (struct GNUNET_TRANSPORT_Blacklist *br);
91reply (struct GNUNET_TRANSPORT_Blacklist *br);
92 90
93 91
94/** 92/**
@@ -98,19 +96,18 @@ reply (struct GNUNET_TRANSPORT_Blacklist *br);
98 * @param msg query 96 * @param msg query
99 */ 97 */
100static void 98static void
101query_handler (void *cls, 99query_handler (void *cls, const struct GNUNET_MessageHeader *msg)
102 const struct GNUNET_MessageHeader *msg)
103{ 100{
104 struct GNUNET_TRANSPORT_Blacklist *br = cls; 101 struct GNUNET_TRANSPORT_Blacklist *br = cls;
105 const struct BlacklistMessage *bm; 102 const struct BlacklistMessage *bm;
106 103
107 if ( (ntohs(msg->size) != sizeof (struct BlacklistMessage)) || 104 if ((ntohs (msg->size) != sizeof (struct BlacklistMessage)) ||
108 (ntohs(msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY) ) 105 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY))
109 { 106 {
110 reconnect (br); 107 reconnect (br);
111 return; 108 return;
112 } 109 }
113 bm = (const struct BlacklistMessage *)msg; 110 bm = (const struct BlacklistMessage *) msg;
114 GNUNET_break (0 == ntohl (bm->is_allowed)); 111 GNUNET_break (0 == ntohl (bm->is_allowed));
115 br->peer = bm->peer; 112 br->peer = bm->peer;
116 reply (br); 113 reply (br);
@@ -126,9 +123,7 @@ static void
126receive (struct GNUNET_TRANSPORT_Blacklist *br) 123receive (struct GNUNET_TRANSPORT_Blacklist *br)
127{ 124{
128 GNUNET_CLIENT_receive (br->client, 125 GNUNET_CLIENT_receive (br->client,
129 &query_handler, 126 &query_handler, br, GNUNET_TIME_UNIT_FOREVER_REL);
130 br,
131 GNUNET_TIME_UNIT_FOREVER_REL);
132} 127}
133 128
134 129
@@ -141,17 +136,16 @@ receive (struct GNUNET_TRANSPORT_Blacklist *br)
141 * @return number of bytes written to buf 136 * @return number of bytes written to buf
142 */ 137 */
143static size_t 138static size_t
144transmit_blacklist_init (void *cls, 139transmit_blacklist_init (void *cls, size_t size, void *buf)
145 size_t size, void *buf)
146{ 140{
147 struct GNUNET_TRANSPORT_Blacklist *br = cls; 141 struct GNUNET_TRANSPORT_Blacklist *br = cls;
148 struct GNUNET_MessageHeader req; 142 struct GNUNET_MessageHeader req;
149 143
150 if (buf == NULL) 144 if (buf == NULL)
151 { 145 {
152 reconnect (br); 146 reconnect (br);
153 return 0; 147 return 0;
154 } 148 }
155 req.size = htons (sizeof (struct GNUNET_MessageHeader)); 149 req.size = htons (sizeof (struct GNUNET_MessageHeader));
156 req.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT); 150 req.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_INIT);
157 memcpy (buf, &req, sizeof (req)); 151 memcpy (buf, &req, sizeof (req));
@@ -170,15 +164,14 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
170{ 164{
171 if (br->client != NULL) 165 if (br->client != NULL)
172 GNUNET_CLIENT_disconnect (br->client, GNUNET_NO); 166 GNUNET_CLIENT_disconnect (br->client, GNUNET_NO);
173 br->client = GNUNET_CLIENT_connect ("transport", 167 br->client = GNUNET_CLIENT_connect ("transport", br->cfg);
174 br->cfg);
175 GNUNET_assert (br->client != NULL); 168 GNUNET_assert (br->client != NULL);
176 br->th = GNUNET_CLIENT_notify_transmit_ready (br->client, 169 br->th = GNUNET_CLIENT_notify_transmit_ready (br->client,
177 sizeof (struct GNUNET_MessageHeader), 170 sizeof (struct
178 GNUNET_TIME_UNIT_FOREVER_REL, 171 GNUNET_MessageHeader),
179 GNUNET_YES, 172 GNUNET_TIME_UNIT_FOREVER_REL,
180 &transmit_blacklist_init, 173 GNUNET_YES,
181 br); 174 &transmit_blacklist_init, br);
182} 175}
183 176
184 177
@@ -191,17 +184,16 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
191 * @return number of bytes written to buf 184 * @return number of bytes written to buf
192 */ 185 */
193static size_t 186static size_t
194transmit_blacklist_reply (void *cls, 187transmit_blacklist_reply (void *cls, size_t size, void *buf)
195 size_t size, void *buf)
196{ 188{
197 struct GNUNET_TRANSPORT_Blacklist *br = cls; 189 struct GNUNET_TRANSPORT_Blacklist *br = cls;
198 struct BlacklistMessage req; 190 struct BlacklistMessage req;
199 191
200 if (buf == NULL) 192 if (buf == NULL)
201 { 193 {
202 reconnect (br); 194 reconnect (br);
203 return 0; 195 return 0;
204 } 196 }
205 req.header.size = htons (sizeof (req)); 197 req.header.size = htons (sizeof (req));
206 req.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY); 198 req.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_REPLY);
207 req.is_allowed = htonl (br->cb (br->cb_cls, &br->peer)); 199 req.is_allowed = htonl (br->cb (br->cb_cls, &br->peer));
@@ -221,16 +213,16 @@ static void
221reply (struct GNUNET_TRANSPORT_Blacklist *br) 213reply (struct GNUNET_TRANSPORT_Blacklist *br)
222{ 214{
223 br->th = GNUNET_CLIENT_notify_transmit_ready (br->client, 215 br->th = GNUNET_CLIENT_notify_transmit_ready (br->client,
224 sizeof (struct BlacklistMessage), 216 sizeof (struct
225 GNUNET_TIME_UNIT_FOREVER_REL, 217 BlacklistMessage),
226 GNUNET_NO, 218 GNUNET_TIME_UNIT_FOREVER_REL,
227 &transmit_blacklist_reply, 219 GNUNET_NO,
228 br); 220 &transmit_blacklist_reply, br);
229 if (br->th == NULL) 221 if (br->th == NULL)
230 { 222 {
231 reconnect (br); 223 reconnect (br);
232 return; 224 return;
233 } 225 }
234} 226}
235 227
236 228
@@ -250,10 +242,9 @@ reply (struct GNUNET_TRANSPORT_Blacklist *br)
250 */ 242 */
251struct GNUNET_TRANSPORT_Blacklist * 243struct GNUNET_TRANSPORT_Blacklist *
252GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg, 244GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
253 GNUNET_TRANSPORT_BlacklistCallback cb, 245 GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
254 void *cb_cls)
255{ 246{
256 struct GNUNET_CLIENT_Connection * client; 247 struct GNUNET_CLIENT_Connection *client;
257 struct GNUNET_TRANSPORT_Blacklist *ret; 248 struct GNUNET_TRANSPORT_Blacklist *ret;
258 249
259 client = GNUNET_CLIENT_connect ("transport", cfg); 250 client = GNUNET_CLIENT_connect ("transport", cfg);
@@ -263,11 +254,11 @@ GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
263 ret->client = client; 254 ret->client = client;
264 ret->cfg = cfg; 255 ret->cfg = cfg;
265 ret->th = GNUNET_CLIENT_notify_transmit_ready (client, 256 ret->th = GNUNET_CLIENT_notify_transmit_ready (client,
266 sizeof (struct GNUNET_MessageHeader), 257 sizeof (struct
267 GNUNET_TIME_UNIT_FOREVER_REL, 258 GNUNET_MessageHeader),
268 GNUNET_YES, 259 GNUNET_TIME_UNIT_FOREVER_REL,
269 &transmit_blacklist_init, 260 GNUNET_YES,
270 ret); 261 &transmit_blacklist_init, ret);
271 return ret; 262 return ret;
272} 263}
273 264
diff --git a/src/transport/transport_api_peer_address_lookup.c b/src/transport/transport_api_peer_address_lookup.c
index c63856d4a..50536b47d 100644
--- a/src/transport/transport_api_peer_address_lookup.c
+++ b/src/transport/transport_api_peer_address_lookup.c
@@ -82,37 +82,37 @@ peer_address_response_processor (void *cls,
82 uint16_t size; 82 uint16_t size;
83 83
84 if (msg == NULL) 84 if (msg == NULL)
85 { 85 {
86 alucb->cb (alucb->cb_cls, NULL); 86 alucb->cb (alucb->cb_cls, NULL);
87 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 87 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
88 GNUNET_free (alucb); 88 GNUNET_free (alucb);
89 return; 89 return;
90 } 90 }
91 GNUNET_break (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); 91 GNUNET_break (ntohs (msg->type) ==
92 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY);
92 size = ntohs (msg->size); 93 size = ntohs (msg->size);
93 if (size == sizeof (struct GNUNET_MessageHeader)) 94 if (size == sizeof (struct GNUNET_MessageHeader))
94 { 95 {
95 /* done! */ 96 /* done! */
96 alucb->cb (alucb->cb_cls, NULL); 97 alucb->cb (alucb->cb_cls, NULL);
97 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 98 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
98 GNUNET_free (alucb); 99 GNUNET_free (alucb);
99 return; 100 return;
100 } 101 }
101 address = (const char *) &msg[1]; 102 address = (const char *) &msg[1];
102 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0') 103 if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
103 { 104 {
104 /* invalid reply */ 105 /* invalid reply */
105 GNUNET_break (0); 106 GNUNET_break (0);
106 alucb->cb (alucb->cb_cls, NULL); 107 alucb->cb (alucb->cb_cls, NULL);
107 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO); 108 GNUNET_CLIENT_disconnect (alucb->client, GNUNET_NO);
108 GNUNET_free (alucb); 109 GNUNET_free (alucb);
109 return; 110 return;
110 } 111 }
111 /* expect more replies */ 112 /* expect more replies */
112 GNUNET_CLIENT_receive (alucb->client, 113 GNUNET_CLIENT_receive (alucb->client,
113 &peer_address_response_processor, alucb, 114 &peer_address_response_processor, alucb,
114 GNUNET_TIME_absolute_get_remaining 115 GNUNET_TIME_absolute_get_remaining (alucb->timeout));
115 (alucb->timeout));
116 alucb->cb (alucb->cb_cls, address); 116 alucb->cb (alucb->cb_cls, address);
117} 117}
118 118
@@ -127,10 +127,12 @@ peer_address_response_processor (void *cls,
127 * @param peer_address_callback_cls closure for peer_address_callback 127 * @param peer_address_callback_cls closure for peer_address_callback
128 */ 128 */
129void 129void
130GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, 130GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle
131 *cfg,
131 const struct GNUNET_PeerIdentity *peer, 132 const struct GNUNET_PeerIdentity *peer,
132 struct GNUNET_TIME_Relative timeout, 133 struct GNUNET_TIME_Relative timeout,
133 GNUNET_TRANSPORT_AddressLookUpCallback peer_address_callback, 134 GNUNET_TRANSPORT_AddressLookUpCallback
135 peer_address_callback,
134 void *peer_address_callback_cls) 136 void *peer_address_callback_cls)
135{ 137{
136 struct PeerAddressLookupMessage msg; 138 struct PeerAddressLookupMessage msg;
@@ -139,26 +141,26 @@ GNUNET_TRANSPORT_peer_address_lookup (const struct GNUNET_CONFIGURATION_Handle *
139 141
140 client = GNUNET_CLIENT_connect ("transport", cfg); 142 client = GNUNET_CLIENT_connect ("transport", cfg);
141 if (client == NULL) 143 if (client == NULL)
142 { 144 {
143 peer_address_callback (peer_address_callback_cls, NULL); 145 peer_address_callback (peer_address_callback_cls, NULL);
144 return; 146 return;
145 } 147 }
146 msg.header.size = htons (sizeof(struct PeerAddressLookupMessage)); 148 msg.header.size = htons (sizeof (struct PeerAddressLookupMessage));
147 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP); 149 msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PEER_ADDRESS_LOOKUP);
148 msg.timeout = GNUNET_TIME_relative_hton (timeout); 150 msg.timeout = GNUNET_TIME_relative_hton (timeout);
149 memcpy(&msg.peer, peer, sizeof(struct GNUNET_PeerIdentity)); 151 memcpy (&msg.peer, peer, sizeof (struct GNUNET_PeerIdentity));
150 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx)); 152 peer_address_lookup_cb = GNUNET_malloc (sizeof (struct AddressLookupCtx));
151 peer_address_lookup_cb->cb = peer_address_callback; 153 peer_address_lookup_cb->cb = peer_address_callback;
152 peer_address_lookup_cb->cb_cls = peer_address_callback_cls; 154 peer_address_lookup_cb->cb_cls = peer_address_callback_cls;
153 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout); 155 peer_address_lookup_cb->timeout = GNUNET_TIME_relative_to_absolute (timeout);
154 peer_address_lookup_cb->client = client; 156 peer_address_lookup_cb->client = client;
155 GNUNET_assert (GNUNET_OK == 157 GNUNET_assert (GNUNET_OK ==
156 GNUNET_CLIENT_transmit_and_get_response (client, 158 GNUNET_CLIENT_transmit_and_get_response (client,
157 &msg.header, 159 &msg.header,
158 timeout, 160 timeout,
159 GNUNET_YES, 161 GNUNET_YES,
160 &peer_address_response_processor, 162 &peer_address_response_processor,
161 peer_address_lookup_cb)); 163 peer_address_lookup_cb));
162} 164}
163 165
164/* end of transport_api_peer_address_lookup.c */ 166/* end of transport_api_peer_address_lookup.c */
diff --git a/src/transport/wlan/byteorder.h b/src/transport/wlan/byteorder.h
index c982669bf..e065e24d6 100644
--- a/src/transport/wlan/byteorder.h
+++ b/src/transport/wlan/byteorder.h
@@ -16,418 +16,421 @@
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */ 19 */
20 20
21#ifndef _AIRCRACK_NG_BYTEORDER_H_ 21#ifndef _AIRCRACK_NG_BYTEORDER_H_
22#define _AIRCRACK_NG_BYTEORDER_H_ 22#define _AIRCRACK_NG_BYTEORDER_H_
23 23
24 #define ___my_swab16(x) \ 24#define ___my_swab16(x) \
25 ((u_int16_t)( \ 25 ((u_int16_t) (\
26 (((u_int16_t)(x) & (u_int16_t)0x00ffU) << 8) | \ 26 (((u_int16_t) (x) & (u_int16_t) 0x00ffU) << 8) | \
27 (((u_int16_t)(x) & (u_int16_t)0xff00U) >> 8) )) 27 (((u_int16_t) (x) & (u_int16_t) 0xff00U) >> 8)))
28 #define ___my_swab32(x) \ 28#define ___my_swab32(x) \
29 ((u_int32_t)( \ 29 ((u_int32_t) (\
30 (((u_int32_t)(x) & (u_int32_t)0x000000ffUL) << 24) | \ 30 (((u_int32_t) (x) & (u_int32_t) 0x000000ffUL) << 24) | \
31 (((u_int32_t)(x) & (u_int32_t)0x0000ff00UL) << 8) | \ 31 (((u_int32_t) (x) & (u_int32_t) 0x0000ff00UL) << 8) | \
32 (((u_int32_t)(x) & (u_int32_t)0x00ff0000UL) >> 8) | \ 32 (((u_int32_t) (x) & (u_int32_t) 0x00ff0000UL) >> 8) | \
33 (((u_int32_t)(x) & (u_int32_t)0xff000000UL) >> 24) )) 33 (((u_int32_t) (x) & (u_int32_t) 0xff000000UL) >> 24)))
34 #define ___my_swab64(x) \ 34#define ___my_swab64(x) \
35 ((u_int64_t)( \ 35 ((u_int64_t) (\
36 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000000000ffULL) << 56) | \ 36 (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
37 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000000000ff00ULL) << 40) | \ 37 0x00000000000000ffULL) << 56) |
38 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000000000ff0000ULL) << 24) | \ 38 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
39 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00000000ff000000ULL) << 8) | \ 39 0x000000000000ff00ULL) << 40) |
40 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x000000ff00000000ULL) >> 8) | \ 40 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
41 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x0000ff0000000000ULL) >> 24) | \ 41 0x0000000000ff0000ULL) << 24) |
42 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0x00ff000000000000ULL) >> 40) | \ 42 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
43 (u_int64_t)(((u_int64_t)(x) & (u_int64_t)0xff00000000000000ULL) >> 56) )) 43 0x00000000ff000000ULL) << 8) |
44 44 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
45 45 0x000000ff00000000ULL) >> 8) |
46 /* 46 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
47 * Linux 47 0x0000ff0000000000ULL) >> 24) |
48 */ 48 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
49 #if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__) 49 0x00ff000000000000ULL) >> 40) |
50 #include <endian.h> 50 \ (u_int64_t) (((u_int64_t) (x) & (u_int64_t)
51 #include <unistd.h> 51 0xff00000000000000ULL) >> 56)))
52 #include <stdint.h> 52 /*
53 53 * Linux
54 #ifndef __int8_t_defined 54 */
55 typedef uint64_t u_int64_t; 55#if defined(linux) || defined(Linux) || defined(__linux__) || defined(__linux) || defined(__gnu_linux__)
56 typedef uint32_t u_int32_t; 56#include <endian.h>
57 typedef uint16_t u_int16_t; 57#include <unistd.h>
58 typedef uint8_t u_int8_t; 58#include <stdint.h>
59 #endif 59
60 60#ifndef __int8_t_defined
61typedef uint64_t u_int64_t;
62 typedef uint32_t u_int32_t;
63 typedef uint16_t u_int16_t;
64 typedef uint8_t u_int8_t;
65
66
67#endif /* */
68
61#ifndef htole16 69#ifndef htole16
62# if __BYTE_ORDER == __LITTLE_ENDIAN 70#if __BYTE_ORDER == __LITTLE_ENDIAN
63# define htobe16(x) ___my_swab16 (x) 71#define htobe16(x) ___my_swab16 (x)
64# define htole16(x) (x) 72#define htole16(x) (x)
65# define be16toh(x) ___my_swab16 (x) 73#define be16toh(x) ___my_swab16 (x)
66# define le16toh(x) (x) 74#define le16toh(x) (x)
67 75
68# define htobe32(x) ___my_swab32 (x) 76#define htobe32(x) ___my_swab32 (x)
69# define htole32(x) (x) 77#define htole32(x) (x)
70# define be32toh(x) ___my_swab32 (x) 78#define be32toh(x) ___my_swab32 (x)
71# define le32toh(x) (x) 79#define le32toh(x) (x)
72 80
73# define htobe64(x) ___my_swab64 (x) 81#define htobe64(x) ___my_swab64 (x)
74# define htole64(x) (x) 82#define htole64(x) (x)
75# define be64toh(x) ___my_swab64 (x) 83#define be64toh(x) ___my_swab64 (x)
76# define le64toh(x) (x) 84#define le64toh(x) (x)
77# else 85#else /* */
78# define htobe16(x) (x) 86#define htobe16(x) (x)
79# define htole16(x) ___my_swab16 (x) 87#define htole16(x) ___my_swab16 (x)
80# define be16toh(x) (x) 88#define be16toh(x) (x)
81# define le16toh(x) ___my_swab16 (x) 89#define le16toh(x) ___my_swab16 (x)
82 90
83# define htobe32(x) (x) 91#define htobe32(x) (x)
84# define htole32(x) ___my_swab32 (x) 92#define htole32(x) ___my_swab32 (x)
85# define be32toh(x) (x) 93#define be32toh(x) (x)
86# define le32toh(x) ___my_swab32 (x) 94#define le32toh(x) ___my_swab32 (x)
87 95
88# define htobe64(x) (x) 96#define htobe64(x) (x)
89# define htole64(x) ___my_swab64 (x) 97#define htole64(x) ___my_swab64 (x)
90# define be64toh(x) (x) 98#define be64toh(x) (x)
91# define le64toh(x) ___my_swab64 (x) 99#define le64toh(x) ___my_swab64 (x)
92# endif 100#endif /* */
93#endif 101#endif /* */
94 102
95 103#endif /* */
96 104
97 #endif 105 /*
98 106 * Cygwin
99 /* 107 */
100 * Cygwin 108#if defined(__CYGWIN32__)
101 */ 109#include <asm/byteorder.h>
102 #if defined(__CYGWIN32__) 110#include <unistd.h>
103 #include <asm/byteorder.h> 111
104 #include <unistd.h> 112#define __be64_to_cpu(x) ___my_swab64(x)
105 113#define __be32_to_cpu(x) ___my_swab32(x)
106 #define __be64_to_cpu(x) ___my_swab64(x) 114#define __be16_to_cpu(x) ___my_swab16(x)
107 #define __be32_to_cpu(x) ___my_swab32(x) 115#define __cpu_to_be64(x) ___my_swab64(x)
108 #define __be16_to_cpu(x) ___my_swab16(x) 116#define __cpu_to_be32(x) ___my_swab32(x)
109 #define __cpu_to_be64(x) ___my_swab64(x) 117#define __cpu_to_be16(x) ___my_swab16(x)
110 #define __cpu_to_be32(x) ___my_swab32(x) 118#define __le64_to_cpu(x) (x)
111 #define __cpu_to_be16(x) ___my_swab16(x) 119#define __le32_to_cpu(x) (x)
112 #define __le64_to_cpu(x) (x) 120#define __le16_to_cpu(x) (x)
113 #define __le32_to_cpu(x) (x) 121#define __cpu_to_le64(x) (x)
114 #define __le16_to_cpu(x) (x) 122#define __cpu_to_le32(x) (x)
115 #define __cpu_to_le64(x) (x) 123#define __cpu_to_le16(x) (x)
116 #define __cpu_to_le32(x) (x) 124
117 #define __cpu_to_le16(x) (x) 125#define AIRCRACK_NG_BYTE_ORDER_DEFINED
118 126
119 #define AIRCRACK_NG_BYTE_ORDER_DEFINED 127#endif /* */
120 128
121 #endif 129 /*
122 130 * Windows (DDK)
123 /* 131 */
124 * Windows (DDK) 132#if defined(__WIN__)
125 */ 133
126 #if defined(__WIN__) 134#include <io.h>
127 135
128 #include <io.h> 136#define __be64_to_cpu(x) ___my_swab64(x)
129 137#define __be32_to_cpu(x) ___my_swab32(x)
130 #define __be64_to_cpu(x) ___my_swab64(x) 138#define __be16_to_cpu(x) ___my_swab16(x)
131 #define __be32_to_cpu(x) ___my_swab32(x) 139#define __cpu_to_be64(x) ___my_swab64(x)
132 #define __be16_to_cpu(x) ___my_swab16(x) 140#define __cpu_to_be32(x) ___my_swab32(x)
133 #define __cpu_to_be64(x) ___my_swab64(x) 141#define __cpu_to_be16(x) ___my_swab16(x)
134 #define __cpu_to_be32(x) ___my_swab32(x) 142#define __le64_to_cpu(x) (x)
135 #define __cpu_to_be16(x) ___my_swab16(x) 143#define __le32_to_cpu(x) (x)
136 #define __le64_to_cpu(x) (x) 144#define __le16_to_cpu(x) (x)
137 #define __le32_to_cpu(x) (x) 145#define __cpu_to_le64(x) (x)
138 #define __le16_to_cpu(x) (x) 146#define __cpu_to_le32(x) (x)
139 #define __cpu_to_le64(x) (x) 147#define __cpu_to_le16(x) (x)
140 #define __cpu_to_le32(x) (x) 148
141 #define __cpu_to_le16(x) (x) 149#define AIRCRACK_NG_BYTE_ORDER_DEFINED
142 150
143 #define AIRCRACK_NG_BYTE_ORDER_DEFINED 151#endif /* */
144 152
145 #endif 153 /*
146 154 * MAC (Darwin)
147 /* 155 */
148 * MAC (Darwin) 156#if defined(__APPLE_CC__)
149 */ 157#if defined(__x86_64__) && defined(__APPLE__)
150 #if defined(__APPLE_CC__) 158
151 #if defined(__x86_64__) && defined(__APPLE__) 159#include <libkern/OSByteOrder.h>
152 160
153 #include <libkern/OSByteOrder.h> 161#define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x)
154 162#define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x)
155 #define __swab64(x) (unsigned long long) OSSwapInt64((uint64_t)x) 163#define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x)
156 #define __swab32(x) (unsigned long) OSSwapInt32((uint32_t)x) 164#define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x)
157 #define __swab16(x) (unsigned short) OSSwapInt16((uint16_t)x) 165#define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x)
158 #define __be64_to_cpu(x) (unsigned long long) OSSwapBigToHostInt64((uint64_t)x) 166#define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x)
159 #define __be32_to_cpu(x) (unsigned long) OSSwapBigToHostInt32((uint32_t)x) 167#define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x)
160 #define __be16_to_cpu(x) (unsigned short) OSSwapBigToHostInt16((uint16_t)x) 168#define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x)
161 #define __le64_to_cpu(x) (unsigned long long) OSSwapLittleToHostInt64((uint64_t)x) 169#define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x)
162 #define __le32_to_cpu(x) (unsigned long) OSSwapLittleToHostInt32((uint32_t)x) 170#define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x)
163 #define __le16_to_cpu(x) (unsigned short) OSSwapLittleToHostInt16((uint16_t)x) 171#define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x)
164 #define __cpu_to_be64(x) (unsigned long long) OSSwapHostToBigInt64((uint64_t)x) 172#define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x)
165 #define __cpu_to_be32(x) (unsigned long) OSSwapHostToBigInt32((uint32_t)x) 173#define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x)
166 #define __cpu_to_be16(x) (unsigned short) OSSwapHostToBigInt16((uint16_t)x) 174#define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x)
167 #define __cpu_to_le64(x) (unsigned long long) OSSwapHostToLittleInt64((uint64_t)x) 175#define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x)
168 #define __cpu_to_le32(x) (unsigned long) OSSwapHostToLittleInt32((uint32_t)x) 176
169 #define __cpu_to_le16(x) (unsigned short) OSSwapHostToLittleInt16((uint16_t)x) 177#else /* */
170 178
171 #else 179#include <architecture/byte_order.h>
172 180
173 #include <architecture/byte_order.h> 181#define __swab64(x) NXSwapLongLong(x)
174 182#define __swab32(x) NXSwapLong(x)
175 #define __swab64(x) NXSwapLongLong(x) 183#define __swab16(x) NXSwapShort(x)
176 #define __swab32(x) NXSwapLong(x) 184#define __be64_to_cpu(x) NXSwapBigLongLongToHost(x)
177 #define __swab16(x) NXSwapShort(x) 185#define __be32_to_cpu(x) NXSwapBigLongToHost(x)
178 #define __be64_to_cpu(x) NXSwapBigLongLongToHost(x) 186#define __be16_to_cpu(x) NXSwapBigShortToHost(x)
179 #define __be32_to_cpu(x) NXSwapBigLongToHost(x) 187#define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x)
180 #define __be16_to_cpu(x) NXSwapBigShortToHost(x) 188#define __le32_to_cpu(x) NXSwapLittleLongToHost(x)
181 #define __le64_to_cpu(x) NXSwapLittleLongLongToHost(x) 189#define __le16_to_cpu(x) NXSwapLittleShortToHost(x)
182 #define __le32_to_cpu(x) NXSwapLittleLongToHost(x) 190#define __cpu_to_be64(x) NXSwapHostLongLongToBig(x)
183 #define __le16_to_cpu(x) NXSwapLittleShortToHost(x) 191#define __cpu_to_be32(x) NXSwapHostLongToBig(x)
184 #define __cpu_to_be64(x) NXSwapHostLongLongToBig(x) 192#define __cpu_to_be16(x) NXSwapHostShortToBig(x)
185 #define __cpu_to_be32(x) NXSwapHostLongToBig(x) 193#define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x)
186 #define __cpu_to_be16(x) NXSwapHostShortToBig(x) 194#define __cpu_to_le32(x) NXSwapHostLongToLittle(x)
187 #define __cpu_to_le64(x) NXSwapHostLongLongToLittle(x) 195#define __cpu_to_le16(x) NXSwapHostShortToLittle(x)
188 #define __cpu_to_le32(x) NXSwapHostLongToLittle(x) 196
189 #define __cpu_to_le16(x) NXSwapHostShortToLittle(x) 197#endif /* */
190 198
191 #endif 199#define __LITTLE_ENDIAN 1234
192 200#define __BIG_ENDIAN 4321
193 #define __LITTLE_ENDIAN 1234 201#define __PDP_ENDIAN 3412
194 #define __BIG_ENDIAN 4321 202#define __BYTE_ORDER __BIG_ENDIAN
195 #define __PDP_ENDIAN 3412 203
196 #define __BYTE_ORDER __BIG_ENDIAN 204#define AIRCRACK_NG_BYTE_ORDER_DEFINED
197 205
198 #define AIRCRACK_NG_BYTE_ORDER_DEFINED 206#endif /* */
199 207
200 #endif 208 /*
201 209 * Solaris
202 /* 210 * -------
203 * Solaris 211 */
204 * ------- 212#if defined(__sparc__) && defined(__sun__)
205 */ 213#include <sys/byteorder.h>
206 #if defined(__sparc__) && defined(__sun__) 214#include <sys/types.h>
207 #include <sys/byteorder.h> 215#include <unistd.h>
208 #include <sys/types.h> 216
209 #include <unistd.h> 217#define __be64_to_cpu(x) (x)
210 218#define __be32_to_cpu(x) (x)
211 #define __be64_to_cpu(x) (x) 219#define __be16_to_cpu(x) (x)
212 #define __be32_to_cpu(x) (x) 220#define __cpu_to_be64(x) (x)
213 #define __be16_to_cpu(x) (x) 221#define __cpu_to_be32(x) (x)
214 #define __cpu_to_be64(x) (x) 222#define __cpu_to_be16(x) (x)
215 #define __cpu_to_be32(x) (x) 223#define __le64_to_cpu(x) ___my_swab64(x)
216 #define __cpu_to_be16(x) (x) 224#define __le32_to_cpu(x) ___my_swab32(x)
217 #define __le64_to_cpu(x) ___my_swab64(x) 225#define __le16_to_cpu(x) ___my_swab16(x)
218 #define __le32_to_cpu(x) ___my_swab32(x) 226#define __cpu_to_le64(x) ___my_swab64(x)
219 #define __le16_to_cpu(x) ___my_swab16(x) 227#define __cpu_to_le32(x) ___my_swab32(x)
220 #define __cpu_to_le64(x) ___my_swab64(x) 228#define __cpu_to_le16(x) ___my_swab16(x)
221 #define __cpu_to_le32(x) ___my_swab32(x) 229 typedef uint64_t u_int64_t;
222 #define __cpu_to_le16(x) ___my_swab16(x) 230 typedef uint32_t u_int32_t;
223 231 typedef uint16_t u_int16_t;
224 typedef uint64_t u_int64_t; 232 typedef uint8_t u_int8_t;
225 typedef uint32_t u_int32_t; 233
226 typedef uint16_t u_int16_t; 234
227 typedef uint8_t u_int8_t; 235#define AIRCRACK_NG_BYTE_ORDER_DEFINED
228 236
229 #define AIRCRACK_NG_BYTE_ORDER_DEFINED 237#endif /* */
230 238
231 #endif 239 /*
232 240 * Custom stuff
233 /* 241 */
234 * Custom stuff 242#if defined(__MACH__) && !defined(__APPLE_CC__)
235 */ 243#include <libkern/OSByteOrder.h>
236 #if defined(__MACH__) && !defined(__APPLE_CC__) 244#define __cpu_to_be64(x) = OSSwapHostToBigInt64(x)
237 #include <libkern/OSByteOrder.h> 245#define __cpu_to_be32(x) = OSSwapHostToBigInt32(x)
238 #define __cpu_to_be64(x) = OSSwapHostToBigInt64(x) 246
239 #define __cpu_to_be32(x) = OSSwapHostToBigInt32(x) 247#define AIRCRACK_NG_BYTE_ORDER_DEFINED
240 248
241 #define AIRCRACK_NG_BYTE_ORDER_DEFINED 249#endif /* */
242 250
243 #endif 251 // FreeBSD
244 252#ifdef __FreeBSD__
245 253#include <machine/endian.h>
246 // FreeBSD 254#endif /* */
247 #ifdef __FreeBSD__ 255
248 #include <machine/endian.h> 256 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...?
249 #endif 257
250 258 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h
251 // XXX: Is there anything to include on OpenBSD/NetBSD/DragonFlyBSD/...? 259 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html
252 260 // Write to apple to ask what should be used.
253 261
254 // XXX: Mac: Check http://www.opensource.apple.com/source/CF/CF-476.18/CFByteOrder.h 262#if defined(LITTLE_ENDIAN)
255 // http://developer.apple.com/DOCUMENTATION/CoreFoundation/Reference/CFByteOrderUtils/Reference/reference.html 263#define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN
256 // Write to apple to ask what should be used. 264#elif defined(__LITTLE_ENDIAN)
257 265#define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN
258 #if defined(LITTLE_ENDIAN) 266#elif defined(_LITTLE_ENDIAN)
259 #define AIRCRACK_NG_LITTLE_ENDIAN LITTLE_ENDIAN 267#define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN
260 #elif defined(__LITTLE_ENDIAN) 268#endif /* */
261 #define AIRCRACK_NG_LITTLE_ENDIAN __LITTLE_ENDIAN 269
262 #elif defined(_LITTLE_ENDIAN) 270#if defined(BIG_ENDIAN)
263 #define AIRCRACK_NG_LITTLE_ENDIAN _LITTLE_ENDIAN 271#define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN
264 #endif 272#elif defined(__BIG_ENDIAN)
265 273#define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN
266 #if defined(BIG_ENDIAN) 274#elif defined(_BIG_ENDIAN)
267 #define AIRCRACK_NG_BIG_ENDIAN BIG_ENDIAN 275#define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN
268 #elif defined(__BIG_ENDIAN) 276#endif /* */
269 #define AIRCRACK_NG_BIG_ENDIAN __BIG_ENDIAN 277
270 #elif defined(_BIG_ENDIAN) 278#if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN)
271 #define AIRCRACK_NG_BIG_ENDIAN _BIG_ENDIAN 279#error Impossible to determine endianness (Little or Big endian), please contact the author.
272 #endif 280#endif /* */
273 281
274 #if !defined(AIRCRACK_NG_LITTLE_ENDIAN) && !defined(AIRCRACK_NG_BIG_ENDIAN) 282#if defined(BYTE_ORDER)
275 #error Impossible to determine endianness (Little or Big endian), please contact the author. 283#if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
276 #endif 284#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
277 285#elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
278 #if defined(BYTE_ORDER) 286#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
279 #if (BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) 287#endif /* */
280 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN 288#elif defined(__BYTE_ORDER)
281 #elif (BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) 289#if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
282 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN 290#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
283 #endif 291#elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
284 #elif defined(__BYTE_ORDER) 292#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
285 #if (__BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) 293#endif /* */
286 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN 294#elif defined(_BYTE_ORDER)
287 #elif (__BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) 295#if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
288 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN 296#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN
289 #endif 297#elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
290 #elif defined(_BYTE_ORDER) 298#define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN
291 #if (_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) 299#endif /* */
292 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_LITTLE_ENDIAN 300#endif /* */
293 #elif (_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) 301
294 #define AIRCRACK_NG_BYTE_ORDER AIRCRACK_NG_BIG_ENDIAN 302#ifndef AIRCRACK_NG_BYTE_ORDER
295 #endif 303#error Impossible to determine endianness (Little or Big endian), please contact the author.
296 #endif 304#endif /* */
297 305
298 #ifndef AIRCRACK_NG_BYTE_ORDER 306#if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN)
299 #error Impossible to determine endianness (Little or Big endian), please contact the author. 307
300 #endif 308#ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
301 309#define __be64_to_cpu(x) ___my_swab64(x)
302 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_LITTLE_ENDIAN) 310#define __be32_to_cpu(x) ___my_swab32(x)
303 311#define __be16_to_cpu(x) ___my_swab16(x)
304 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED 312#define __cpu_to_be64(x) ___my_swab64(x)
305 #define __be64_to_cpu(x) ___my_swab64(x) 313#define __cpu_to_be32(x) ___my_swab32(x)
306 #define __be32_to_cpu(x) ___my_swab32(x) 314#define __cpu_to_be16(x) ___my_swab16(x)
307 #define __be16_to_cpu(x) ___my_swab16(x) 315#define __le64_to_cpu(x) (x)
308 #define __cpu_to_be64(x) ___my_swab64(x) 316#define __le32_to_cpu(x) (x)
309 #define __cpu_to_be32(x) ___my_swab32(x) 317#define __le16_to_cpu(x) (x)
310 #define __cpu_to_be16(x) ___my_swab16(x) 318#define __cpu_to_le64(x) (x)
311 #define __le64_to_cpu(x) (x) 319#define __cpu_to_le32(x) (x)
312 #define __le32_to_cpu(x) (x) 320#define __cpu_to_le16(x) (x)
313 #define __le16_to_cpu(x) (x) 321#endif /* */
314 #define __cpu_to_le64(x) (x) 322
315 #define __cpu_to_le32(x) (x) 323#ifndef htobe16
316 #define __cpu_to_le16(x) (x) 324#define htobe16 ___my_swab16
317 #endif 325#endif /* */
318 326#ifndef htobe32
319 #ifndef htobe16 327#define htobe32 ___my_swab32
320 #define htobe16 ___my_swab16 328#endif /* */
321 #endif 329#ifndef betoh16
322 #ifndef htobe32 330#define betoh16 ___my_swab16
323 #define htobe32 ___my_swab32 331#endif /* */
324 #endif 332#ifndef betoh32
325 #ifndef betoh16 333#define betoh32 ___my_swab32
326 #define betoh16 ___my_swab16 334#endif /* */
327 #endif 335
328 #ifndef betoh32 336#ifndef htole16
329 #define betoh32 ___my_swab32 337#define htole16(x) (x)
330 #endif 338#endif /* */
331 339#ifndef htole32
332 #ifndef htole16 340#define htole32(x) (x)
333 #define htole16(x) (x) 341#endif /* */
334 #endif 342#ifndef letoh16
335 #ifndef htole32 343#define letoh16(x) (x)
336 #define htole32(x) (x) 344#endif /* */
337 #endif 345#ifndef letoh32
338 #ifndef letoh16 346#define letoh32(x) (x)
339 #define letoh16(x) (x) 347#endif /* */
340 #endif 348
341 #ifndef letoh32 349#endif /* */
342 #define letoh32(x) (x) 350
343 #endif 351#if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN)
344 352
345 #endif 353#ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED
346 354#define __be64_to_cpu(x) (x)
347 #if (AIRCRACK_NG_BYTE_ORDER == AIRCRACK_NG_BIG_ENDIAN) 355#define __be32_to_cpu(x) (x)
348 356#define __be16_to_cpu(x) (x)
349 #ifndef AIRCRACK_NG_BYTE_ORDER_DEFINED 357#define __cpu_to_be64(x) (x)
350 #define __be64_to_cpu(x) (x) 358#define __cpu_to_be32(x) (x)
351 #define __be32_to_cpu(x) (x) 359#define __cpu_to_be16(x) (x)
352 #define __be16_to_cpu(x) (x) 360#define __le64_to_cpu(x) ___my_swab64(x)
353 #define __cpu_to_be64(x) (x) 361#define __le32_to_cpu(x) ___my_swab32(x)
354 #define __cpu_to_be32(x) (x) 362#define __le16_to_cpu(x) ___my_swab16(x)
355 #define __cpu_to_be16(x) (x) 363#define __cpu_to_le64(x) ___my_swab64(x)
356 #define __le64_to_cpu(x) ___my_swab64(x) 364#define __cpu_to_le32(x) ___my_swab32(x)
357 #define __le32_to_cpu(x) ___my_swab32(x) 365#define __cpu_to_le16(x) ___my_swab16(x)
358 #define __le16_to_cpu(x) ___my_swab16(x) 366#endif /* */
359 #define __cpu_to_le64(x) ___my_swab64(x) 367
360 #define __cpu_to_le32(x) ___my_swab32(x) 368#ifndef htobe16
361 #define __cpu_to_le16(x) ___my_swab16(x) 369#define htobe16(x) (x)
362 #endif 370#endif /* */
363 371#ifndef htobe32
364 #ifndef htobe16 372#define htobe32(x) (x)
365 #define htobe16(x) (x) 373#endif /* */
366 #endif 374#ifndef betoh16
367 #ifndef htobe32 375#define betoh16(x) (x)
368 #define htobe32(x) (x) 376#endif /* */
369 #endif 377#ifndef betoh32
370 #ifndef betoh16 378#define betoh32(x) (x)
371 #define betoh16(x) (x) 379#endif /* */
372 #endif 380
373 #ifndef betoh32 381#ifndef htole16
374 #define betoh32(x) (x) 382#define htole16 ___my_swab16
375 #endif 383#endif /* */
376 384#ifndef htole32
377 #ifndef htole16 385#define htole32 ___my_swab32
378 #define htole16 ___my_swab16 386#endif /* */
379 #endif 387#ifndef letoh16
380 #ifndef htole32 388#define letoh16 ___my_swab16
381 #define htole32 ___my_swab32 389#endif /* */
382 #endif 390#ifndef letoh32
383 #ifndef letoh16 391#define letoh32 ___my_swab32
384 #define letoh16 ___my_swab16 392#endif /* */
385 #endif 393
386 #ifndef letoh32 394#endif /* */
387 #define letoh32 ___my_swab32 395
388 #endif 396 // Common defines
389 397#define cpu_to_le64 __cpu_to_le64
390 #endif 398#define le64_to_cpu __le64_to_cpu
391 399#define cpu_to_le32 __cpu_to_le32
392 // Common defines 400#define le32_to_cpu __le32_to_cpu
393 #define cpu_to_le64 __cpu_to_le64 401#define cpu_to_le16 __cpu_to_le16
394 #define le64_to_cpu __le64_to_cpu 402#define le16_to_cpu __le16_to_cpu
395 #define cpu_to_le32 __cpu_to_le32 403#define cpu_to_be64 __cpu_to_be64
396 #define le32_to_cpu __le32_to_cpu 404#define be64_to_cpu __be64_to_cpu
397 #define cpu_to_le16 __cpu_to_le16 405#define cpu_to_be32 __cpu_to_be32
398 #define le16_to_cpu __le16_to_cpu 406#define be32_to_cpu __be32_to_cpu
399 #define cpu_to_be64 __cpu_to_be64 407#define cpu_to_be16 __cpu_to_be16
400 #define be64_to_cpu __be64_to_cpu 408#define be16_to_cpu __be16_to_cpu
401 #define cpu_to_be32 __cpu_to_be32 409
402 #define be32_to_cpu __be32_to_cpu 410#ifndef le16toh
403 #define cpu_to_be16 __cpu_to_be16 411#define le16toh le16_to_cpu
404 #define be16_to_cpu __be16_to_cpu 412#endif /* */
405 413#ifndef be16toh
406 #ifndef le16toh 414#define be16toh be16_to_cpu
407 #define le16toh le16_to_cpu 415#endif /* */
408 #endif 416#ifndef le32toh
409 #ifndef be16toh 417#define le32toh le32_to_cpu
410 #define be16toh be16_to_cpu 418#endif /* */
411 #endif 419#ifndef be32toh
412 #ifndef le32toh 420#define be32toh be32_to_cpu
413 #define le32toh le32_to_cpu 421#endif /* */
414 #endif 422
415 #ifndef be32toh 423#ifndef htons
416 #define be32toh be32_to_cpu 424#define htons be16_to_cpu
417 #endif 425#endif /* */
418 426#ifndef htonl
419 427#define htonl cpu_to_be16
420 #ifndef htons 428#endif /* */
421 #define htons be16_to_cpu 429#ifndef ntohs
422 #endif 430#define ntohs cpu_to_be16
423 #ifndef htonl 431#endif /* */
424 #define htonl cpu_to_be16 432#ifndef ntohl
425 #endif 433#define ntohl cpu_to_be32
426 #ifndef ntohs 434#endif /* */
427 #define ntohs cpu_to_be16 435
428 #endif 436#endif /* */
429 #ifndef ntohl
430 #define ntohl cpu_to_be32
431 #endif
432
433#endif
diff --git a/src/transport/wlan/crctable_osdep.h b/src/transport/wlan/crctable_osdep.h
index 4f14d245b..04c769f2a 100644
--- a/src/transport/wlan/crctable_osdep.h
+++ b/src/transport/wlan/crctable_osdep.h
@@ -1,40 +1,71 @@
1#ifndef _CRCTABLE_OSDEP_H 1#ifndef _CRCTABLE_OSDEP_H
2#define _CRCTABLE_OSDEP_H 2#define _CRCTABLE_OSDEP_H
3 3
4const unsigned long int crc_tbl_osdep[256] = 4const unsigned long int crc_tbl_osdep[256] = {
5{ 5 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F,
6 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 6 0xE963A535, 0x9E6495A3,
7 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 7 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD,
8 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 8 0xE7B82D07, 0x90BF1D91,
9 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 9 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 0x1ADAD47D, 0x6DDDE4EB,
10 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 10 0xF4D4B551, 0x83D385C7,
11 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 11 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 0x14015C4F, 0x63066CD9,
12 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 12 0xFA0F3D63, 0x8D080DF5,
13 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 13 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 0x3C03E4D1, 0x4B04D447,
14 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 14 0xD20D85FD, 0xA50AB56B,
15 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 15 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 0x32D86CE3, 0x45DF5C75,
16 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 16 0xDCD60DCF, 0xABD13D59,
17 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 17 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 0x21B4F4B5, 0x56B3C423,
18 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 18 0xCFBA9599, 0xB8BDA50F,
19 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 19 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 0x2F6F7C87, 0x58684C11,
20 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 20 0xC1611DAB, 0xB6662D3D,
21 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 21 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 0x71B18589, 0x06B6B51F,
22 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 22 0x9FBFE4A5, 0xE8B8D433,
23 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 23 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 0x7F6A0DBB, 0x086D3D2D,
24 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 24 0x91646C97, 0xE6635C01,
25 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 25 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 0x6C0695ED, 0x1B01A57B,
26 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 26 0x8208F4C1, 0xF50FC457,
27 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 27 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 0x62DD1DDF, 0x15DA2D49,
28 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 28 0x8CD37CF3, 0xFBD44C65,
29 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 29 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 0x4ADFA541, 0x3DD895D7,
30 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 30 0xA4D1C46D, 0xD3D6F4FB,
31 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 31 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 0x44042D73, 0x33031DE5,
32 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 32 0xAA0A4C5F, 0xDD0D7CC9,
33 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 33 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 0x5768B525, 0x206F85B3,
34 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 34 0xB966D409, 0xCE61E49F,
35 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 35 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 0x59B33D17, 0x2EB40D81,
36 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 36 0xB7BD5C3B, 0xC0BA6CAD,
37 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D 37 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 0xEAD54739, 0x9DD277AF,
38 0x04DB2615, 0x73DC1683,
39 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 0xE40ECF0B, 0x9309FF9D,
40 0x0A00AE27, 0x7D079EB1,
41 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 0xF762575D, 0x806567CB,
42 0x196C3671, 0x6E6B06E7,
43 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 0xF9B9DF6F, 0x8EBEEFF9,
44 0x17B7BE43, 0x60B08ED5,
45 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 0xD1BB67F1, 0xA6BC5767,
46 0x3FB506DD, 0x48B2364B,
47 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 0xDF60EFC3, 0xA867DF55,
48 0x316E8EEF, 0x4669BE79,
49 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 0xCC0C7795, 0xBB0B4703,
50 0x220216B9, 0x5505262F,
51 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 0xC2D7FFA7, 0xB5D0CF31,
52 0x2CD99E8B, 0x5BDEAE1D,
53 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 0x9C0906A9, 0xEB0E363F,
54 0x72076785, 0x05005713,
55 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 0x92D28E9B, 0xE5D5BE0D,
56 0x7CDCEFB7, 0x0BDBDF21,
57 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 0x81BE16CD, 0xF6B9265B,
58 0x6FB077E1, 0x18B74777,
59 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 0x8F659EFF, 0xF862AE69,
60 0x616BFFD3, 0x166CCF45,
61 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 0xA7672661, 0xD06016F7,
62 0x4969474D, 0x3E6E77DB,
63 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 0xA9BCAE53, 0xDEBB9EC5,
64 0x47B2CF7F, 0x30B5FFE9,
65 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 0xBAD03605, 0xCDD70693,
66 0x54DE5729, 0x23D967BF,
67 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1,
68 0x5A05DF1B, 0x2D02EF8D
38}; 69};
39 70
40#endif /* crctable_osdep.h */ 71#endif /* crctable_osdep.h */
diff --git a/src/transport/wlan/helper_common.c b/src/transport/wlan/helper_common.c
index 24782ed11..d4b1204f6 100644
--- a/src/transport/wlan/helper_common.c
+++ b/src/transport/wlan/helper_common.c
@@ -34,17 +34,17 @@
34 * @return number of bytes written 34 * @return number of bytes written
35 */ 35 */
36int 36int
37send_mac_to_plugin(char * buffer, uint8_t * mac) 37send_mac_to_plugin (char *buffer, uint8_t * mac)
38{ 38{
39 39
40 struct Wlan_Helper_Control_Message macmsg; 40 struct Wlan_Helper_Control_Message macmsg;
41 41
42 memcpy(macmsg.mac.mac, mac, sizeof(struct MacAddress)); 42 memcpy (macmsg.mac.mac, mac, sizeof (struct MacAddress));
43 macmsg.hdr.size = htons(sizeof(struct Wlan_Helper_Control_Message)); 43 macmsg.hdr.size = htons (sizeof (struct Wlan_Helper_Control_Message));
44 macmsg.hdr.type = htons(GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL); 44 macmsg.hdr.type = htons (GNUNET_MESSAGE_TYPE_WLAN_HELPER_CONTROL);
45 45
46 memcpy(buffer, &macmsg, sizeof(struct Wlan_Helper_Control_Message)); 46 memcpy (buffer, &macmsg, sizeof (struct Wlan_Helper_Control_Message));
47 return sizeof(struct Wlan_Helper_Control_Message); 47 return sizeof (struct Wlan_Helper_Control_Message);
48} 48}
49 49
50/* 50/*
@@ -70,40 +70,54 @@ send_mac_to_plugin(char * buffer, uint8_t * mac)
70/** 70/**
71 * Return the frequency in Mhz from a channel number 71 * Return the frequency in Mhz from a channel number
72 */ 72 */
73int getFrequencyFromChannel(int channel) 73int
74getFrequencyFromChannel (int channel)
74{ 75{
75 static int frequencies[] = { 76 static int frequencies[] = {
76 -1, // No channel 0 77 -1, // No channel 0
77 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484, 78 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467,
78 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive) 79 2472, 2484,
79 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225, 5230, 5235, 5240, 5245, 80 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // Nothing from channel 15 to 34 (exclusive)
80 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305, 5310, 5315, 5320, 5325, 81 5170, 5175, 5180, 5185, 5190, 5195, 5200, 5205, 5210, 5215, 5220, 5225,
81 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385, 5390, 5395, 5400, 5405, 82 5230, 5235, 5240, 5245,
82 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465, 5470, 5475, 5480, 5485, 83 5250, 5255, 5260, 5265, 5270, 5275, 5280, 5285, 5290, 5295, 5300, 5305,
83 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545, 5550, 5555, 5560, 5565, 84 5310, 5315, 5320, 5325,
84 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625, 5630, 5635, 5640, 5645, 85 5330, 5335, 5340, 5345, 5350, 5355, 5360, 5365, 5370, 5375, 5380, 5385,
85 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705, 5710, 5715, 5720, 5725, 86 5390, 5395, 5400, 5405,
86 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785, 5790, 5795, 5800, 5805, 87 5410, 5415, 5420, 5425, 5430, 5435, 5440, 5445, 5450, 5455, 5460, 5465,
87 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865, 5870, 5875, 5880, 5885, 88 5470, 5475, 5480, 5485,
88 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945, 5950, 5955, 5960, 5965, 89 5490, 5495, 5500, 5505, 5510, 5515, 5520, 5525, 5530, 5535, 5540, 5545,
89 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025, 6030, 6035, 6040, 6045, 90 5550, 5555, 5560, 5565,
90 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100 91 5570, 5575, 5580, 5585, 5590, 5595, 5600, 5605, 5610, 5615, 5620, 5625,
91 }; 92 5630, 5635, 5640, 5645,
93 5650, 5655, 5660, 5665, 5670, 5675, 5680, 5685, 5690, 5695, 5700, 5705,
94 5710, 5715, 5720, 5725,
95 5730, 5735, 5740, 5745, 5750, 5755, 5760, 5765, 5770, 5775, 5780, 5785,
96 5790, 5795, 5800, 5805,
97 5810, 5815, 5820, 5825, 5830, 5835, 5840, 5845, 5850, 5855, 5860, 5865,
98 5870, 5875, 5880, 5885,
99 5890, 5895, 5900, 5905, 5910, 5915, 5920, 5925, 5930, 5935, 5940, 5945,
100 5950, 5955, 5960, 5965,
101 5970, 5975, 5980, 5985, 5990, 5995, 6000, 6005, 6010, 6015, 6020, 6025,
102 6030, 6035, 6040, 6045,
103 6050, 6055, 6060, 6065, 6070, 6075, 6080, 6085, 6090, 6095, 6100
104 };
92 105
93 return (channel > 0 && channel <= 221) ? frequencies[channel] : -1; 106 return (channel > 0 && channel <= 221) ? frequencies[channel] : -1;
94} 107}
95 108
96/** 109/**
97 * Return the channel from the frequency (in Mhz) 110 * Return the channel from the frequency (in Mhz)
98 */ 111 */
99int getChannelFromFrequency(int frequency) 112int
113getChannelFromFrequency (int frequency)
100{ 114{
101 if (frequency >= 2412 && frequency <= 2472) 115 if (frequency >= 2412 && frequency <= 2472)
102 return (frequency - 2407) / 5; 116 return (frequency - 2407) / 5;
103 else if (frequency == 2484) 117 else if (frequency == 2484)
104 return 14; 118 return 14;
105 else if (frequency >= 5000 && frequency <= 6100) 119 else if (frequency >= 5000 && frequency <= 6100)
106 return (frequency - 5000) / 5; 120 return (frequency - 5000) / 5;
107 else 121 else
108 return -1; 122 return -1;
109} 123}
diff --git a/src/transport/wlan/helper_common.h b/src/transport/wlan/helper_common.h
index 71c3e1b9b..550ebda6f 100644
--- a/src/transport/wlan/helper_common.h
+++ b/src/transport/wlan/helper_common.h
@@ -8,8 +8,8 @@
8#ifndef HELPER_COMMON_H_ 8#ifndef HELPER_COMMON_H_
9#define HELPER_COMMON_H_ 9#define HELPER_COMMON_H_
10 10
11int getFrequencyFromChannel(int channel); 11int getFrequencyFromChannel (int channel);
12int getChannelFromFrequency(int frequency); 12int getChannelFromFrequency (int frequency);
13int send_mac_to_plugin(char * buffer, uint8_t * mac); 13int send_mac_to_plugin (char *buffer, uint8_t * mac);
14 14
15#endif /* HELPER_COMMON_H_ */ 15#endif /* HELPER_COMMON_H_ */
diff --git a/src/transport/wlan/ieee80211.h b/src/transport/wlan/ieee80211.h
index 8df1d2c29..a952674ca 100644
--- a/src/transport/wlan/ieee80211.h
+++ b/src/transport/wlan/ieee80211.h
@@ -38,72 +38,78 @@
38 * 802.11 protocol definitions. 38 * 802.11 protocol definitions.
39 */ 39 */
40 40
41#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */ 41#define IEEE80211_ADDR_LEN 6 /* size of 802.11 address */
42/* is 802.11 address multicast/broadcast? */ 42/* is 802.11 address multicast/broadcast? */
43#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01) 43#define IEEE80211_IS_MULTICAST(_a) (*(_a) & 0x01)
44 44
45/* IEEE 802.11 PLCP header */ 45/* IEEE 802.11 PLCP header */
46struct ieee80211_plcp_hdr { 46struct ieee80211_plcp_hdr
47 u_int16_t i_sfd; 47{
48 u_int8_t i_signal; 48 u_int16_t i_sfd;
49 u_int8_t i_service; 49 u_int8_t i_signal;
50 u_int16_t i_length; 50 u_int8_t i_service;
51 u_int16_t i_crc; 51 u_int16_t i_length;
52 u_int16_t i_crc;
52} GNUNET_PACKED; 53} GNUNET_PACKED;
53 54
54#define IEEE80211_PLCP_SFD 0xF3A0 55#define IEEE80211_PLCP_SFD 0xF3A0
55#define IEEE80211_PLCP_SERVICE 0x00 56#define IEEE80211_PLCP_SERVICE 0x00
56 57
57/* 58/*
58 * generic definitions for IEEE 802.11 frames 59 * generic definitions for IEEE 802.11 frames
59 */ 60 */
60struct ieee80211_frame { 61struct ieee80211_frame
61 u_int8_t i_fc[2]; 62{
62 u_int8_t i_dur[2]; 63 u_int8_t i_fc[2];
63 u_int8_t i_addr1[IEEE80211_ADDR_LEN]; 64 u_int8_t i_dur[2];
64 u_int8_t i_addr2[IEEE80211_ADDR_LEN]; 65 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
65 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 66 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
66 u_int8_t i_seq[2]; 67 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
67 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ 68 u_int8_t i_seq[2];
68 /* see below */ 69 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
70 /* see below */
69} GNUNET_PACKED; 71} GNUNET_PACKED;
70 72
71struct ieee80211_qosframe { 73struct ieee80211_qosframe
72 u_int8_t i_fc[2]; 74{
73 u_int8_t i_dur[2]; 75 u_int8_t i_fc[2];
74 u_int8_t i_addr1[IEEE80211_ADDR_LEN]; 76 u_int8_t i_dur[2];
75 u_int8_t i_addr2[IEEE80211_ADDR_LEN]; 77 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
76 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 78 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
77 u_int8_t i_seq[2]; 79 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
78 u_int8_t i_qos[2]; 80 u_int8_t i_seq[2];
79 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */ 81 u_int8_t i_qos[2];
80 /* see below */ 82 /* possibly followed by addr4[IEEE80211_ADDR_LEN]; */
83 /* see below */
81} GNUNET_PACKED; 84} GNUNET_PACKED;
82 85
83struct ieee80211_qoscntl { 86struct ieee80211_qoscntl
84 u_int8_t i_qos[2]; 87{
88 u_int8_t i_qos[2];
85}; 89};
86 90
87struct ieee80211_frame_addr4 { 91struct ieee80211_frame_addr4
88 u_int8_t i_fc[2]; 92{
89 u_int8_t i_dur[2]; 93 u_int8_t i_fc[2];
90 u_int8_t i_addr1[IEEE80211_ADDR_LEN]; 94 u_int8_t i_dur[2];
91 u_int8_t i_addr2[IEEE80211_ADDR_LEN]; 95 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
92 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 96 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
93 u_int8_t i_seq[2]; 97 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
94 u_int8_t i_addr4[IEEE80211_ADDR_LEN]; 98 u_int8_t i_seq[2];
99 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
95} GNUNET_PACKED; 100} GNUNET_PACKED;
96 101
97 102
98struct ieee80211_qosframe_addr4 { 103struct ieee80211_qosframe_addr4
99 u_int8_t i_fc[2]; 104{
100 u_int8_t i_dur[2]; 105 u_int8_t i_fc[2];
101 u_int8_t i_addr1[IEEE80211_ADDR_LEN]; 106 u_int8_t i_dur[2];
102 u_int8_t i_addr2[IEEE80211_ADDR_LEN]; 107 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
103 u_int8_t i_addr3[IEEE80211_ADDR_LEN]; 108 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
104 u_int8_t i_seq[2]; 109 u_int8_t i_addr3[IEEE80211_ADDR_LEN];
105 u_int8_t i_addr4[IEEE80211_ADDR_LEN]; 110 u_int8_t i_seq[2];
106 u_int8_t i_qos[2]; 111 u_int8_t i_addr4[IEEE80211_ADDR_LEN];
112 u_int8_t i_qos[2];
107} GNUNET_PACKED; 113} GNUNET_PACKED;
108 114
109#define IEEE80211_FC0_VERSION_MASK 0x03 115#define IEEE80211_FC0_VERSION_MASK 0x03
@@ -149,10 +155,10 @@ struct ieee80211_qosframe_addr4 {
149#define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0 155#define IEEE80211_FC0_SUBTYPE_QOS_NULL 0xc0
150 156
151#define IEEE80211_FC1_DIR_MASK 0x03 157#define IEEE80211_FC1_DIR_MASK 0x03
152#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */ 158#define IEEE80211_FC1_DIR_NODS 0x00 /* STA->STA */
153#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */ 159#define IEEE80211_FC1_DIR_TODS 0x01 /* STA->AP */
154#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */ 160#define IEEE80211_FC1_DIR_FROMDS 0x02 /* AP ->STA */
155#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */ 161#define IEEE80211_FC1_DIR_DSTODS 0x03 /* AP ->AP */
156 162
157#define IEEE80211_FC1_MORE_FRAG 0x04 163#define IEEE80211_FC1_MORE_FRAG 0x04
158#define IEEE80211_FC1_RETRY 0x08 164#define IEEE80211_FC1_RETRY 0x08
@@ -185,65 +191,68 @@ struct ieee80211_qosframe_addr4 {
185/* 191/*
186 * WME/802.11e information element. 192 * WME/802.11e information element.
187 */ 193 */
188struct ieee80211_wme_info { 194struct ieee80211_wme_info
189 u_int8_t wme_id; /* IEEE80211_ELEMID_VENDOR */ 195{
190 u_int8_t wme_len; /* length in bytes */ 196 u_int8_t wme_id; /* IEEE80211_ELEMID_VENDOR */
191 u_int8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */ 197 u_int8_t wme_len; /* length in bytes */
192 u_int8_t wme_type; /* OUI type */ 198 u_int8_t wme_oui[3]; /* 0x00, 0x50, 0xf2 */
193 u_int8_t wme_subtype; /* OUI subtype */ 199 u_int8_t wme_type; /* OUI type */
194 u_int8_t wme_version; /* spec revision */ 200 u_int8_t wme_subtype; /* OUI subtype */
195 u_int8_t wme_info; /* QoS info */ 201 u_int8_t wme_version; /* spec revision */
202 u_int8_t wme_info; /* QoS info */
196} GNUNET_PACKED; 203} GNUNET_PACKED;
197 204
198/* 205/*
199 * WME/802.11e Tspec Element 206 * WME/802.11e Tspec Element
200 */ 207 */
201struct ieee80211_wme_tspec { 208struct ieee80211_wme_tspec
202 u_int8_t ts_id; 209{
203 u_int8_t ts_len; 210 u_int8_t ts_id;
204 u_int8_t ts_oui[3]; 211 u_int8_t ts_len;
205 u_int8_t ts_oui_type; 212 u_int8_t ts_oui[3];
206 u_int8_t ts_oui_subtype; 213 u_int8_t ts_oui_type;
207 u_int8_t ts_version; 214 u_int8_t ts_oui_subtype;
208 u_int8_t ts_tsinfo[3]; 215 u_int8_t ts_version;
209 u_int8_t ts_nom_msdu[2]; 216 u_int8_t ts_tsinfo[3];
210 u_int8_t ts_max_msdu[2]; 217 u_int8_t ts_nom_msdu[2];
211 u_int8_t ts_min_svc[4]; 218 u_int8_t ts_max_msdu[2];
212 u_int8_t ts_max_svc[4]; 219 u_int8_t ts_min_svc[4];
213 u_int8_t ts_inactv_intv[4]; 220 u_int8_t ts_max_svc[4];
214 u_int8_t ts_susp_intv[4]; 221 u_int8_t ts_inactv_intv[4];
215 u_int8_t ts_start_svc[4]; 222 u_int8_t ts_susp_intv[4];
216 u_int8_t ts_min_rate[4]; 223 u_int8_t ts_start_svc[4];
217 u_int8_t ts_mean_rate[4]; 224 u_int8_t ts_min_rate[4];
218 u_int8_t ts_max_burst[4]; 225 u_int8_t ts_mean_rate[4];
219 u_int8_t ts_min_phy[4]; 226 u_int8_t ts_max_burst[4];
220 u_int8_t ts_peak_rate[4]; 227 u_int8_t ts_min_phy[4];
221 u_int8_t ts_delay[4]; 228 u_int8_t ts_peak_rate[4];
222 u_int8_t ts_surplus[2]; 229 u_int8_t ts_delay[4];
223 u_int8_t ts_medium_time[2]; 230 u_int8_t ts_surplus[2];
231 u_int8_t ts_medium_time[2];
224} GNUNET_PACKED; 232} GNUNET_PACKED;
225 233
226/* 234/*
227 * WME AC parameter field 235 * WME AC parameter field
228 */ 236 */
229struct ieee80211_wme_acparams { 237struct ieee80211_wme_acparams
230 u_int8_t acp_aci_aifsn; 238{
231 u_int8_t acp_logcwminmax; 239 u_int8_t acp_aci_aifsn;
232 u_int16_t acp_txop; 240 u_int8_t acp_logcwminmax;
241 u_int16_t acp_txop;
233} GNUNET_PACKED; 242} GNUNET_PACKED;
234 243
235#define WME_NUM_AC 4 /* 4 AC categories */ 244#define WME_NUM_AC 4 /* 4 AC categories */
236 245
237#define WME_PARAM_ACI 0x60 /* Mask for ACI field */ 246#define WME_PARAM_ACI 0x60 /* Mask for ACI field */
238#define WME_PARAM_ACI_S 5 /* Shift for ACI field */ 247#define WME_PARAM_ACI_S 5 /* Shift for ACI field */
239#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */ 248#define WME_PARAM_ACM 0x10 /* Mask for ACM bit */
240#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */ 249#define WME_PARAM_ACM_S 4 /* Shift for ACM bit */
241#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */ 250#define WME_PARAM_AIFSN 0x0f /* Mask for aifsn field */
242#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */ 251#define WME_PARAM_AIFSN_S 0 /* Shift for aifsn field */
243#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */ 252#define WME_PARAM_LOGCWMIN 0x0f /* Mask for CwMin field (in log) */
244#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */ 253#define WME_PARAM_LOGCWMIN_S 0 /* Shift for CwMin field */
245#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */ 254#define WME_PARAM_LOGCWMAX 0xf0 /* Mask for CwMax field (in log) */
246#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */ 255#define WME_PARAM_LOGCWMAX_S 4 /* Shift for CwMax field */
247 256
248#define WME_AC_TO_TID(_ac) ( \ 257#define WME_AC_TO_TID(_ac) ( \
249 ((_ac) == WME_AC_VO) ? 6 : \ 258 ((_ac) == WME_AC_VO) ? 6 : \
@@ -260,28 +269,31 @@ struct ieee80211_wme_acparams {
260/* 269/*
261 * WME Parameter Element 270 * WME Parameter Element
262 */ 271 */
263struct ieee80211_wme_param { 272struct ieee80211_wme_param
264 u_int8_t param_id; 273{
265 u_int8_t param_len; 274 u_int8_t param_id;
266 u_int8_t param_oui[3]; 275 u_int8_t param_len;
267 u_int8_t param_oui_type; 276 u_int8_t param_oui[3];
268 u_int8_t param_oui_sybtype; 277 u_int8_t param_oui_type;
269 u_int8_t param_version; 278 u_int8_t param_oui_sybtype;
270 u_int8_t param_qosInfo; 279 u_int8_t param_version;
271#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */ 280 u_int8_t param_qosInfo;
272 u_int8_t param_reserved; 281#define WME_QOSINFO_COUNT 0x0f /* Mask for param count field */
273 struct ieee80211_wme_acparams params_acParams[WME_NUM_AC]; 282 u_int8_t param_reserved;
283 struct ieee80211_wme_acparams params_acParams[WME_NUM_AC];
274} GNUNET_PACKED; 284} GNUNET_PACKED;
275 285
276/* 286/*
277 * Management Notification Frame 287 * Management Notification Frame
278 */ 288 */
279struct ieee80211_mnf { 289struct ieee80211_mnf
280 u_int8_t mnf_category; 290{
281 u_int8_t mnf_action; 291 u_int8_t mnf_category;
282 u_int8_t mnf_dialog; 292 u_int8_t mnf_action;
283 u_int8_t mnf_status; 293 u_int8_t mnf_dialog;
294 u_int8_t mnf_status;
284} GNUNET_PACKED; 295} GNUNET_PACKED;
296
285#define MNF_SETUP_REQ 0 297#define MNF_SETUP_REQ 0
286#define MNF_SETUP_RESP 1 298#define MNF_SETUP_RESP 1
287#define MNF_TEARDOWN 2 299#define MNF_TEARDOWN 2
@@ -289,50 +301,56 @@ struct ieee80211_mnf {
289/* 301/*
290 * Control frames. 302 * Control frames.
291 */ 303 */
292struct ieee80211_frame_min { 304struct ieee80211_frame_min
293 u_int8_t i_fc[2]; 305{
294 u_int8_t i_dur[2]; 306 u_int8_t i_fc[2];
295 u_int8_t i_addr1[IEEE80211_ADDR_LEN]; 307 u_int8_t i_dur[2];
296 u_int8_t i_addr2[IEEE80211_ADDR_LEN]; 308 u_int8_t i_addr1[IEEE80211_ADDR_LEN];
297 /* FCS */ 309 u_int8_t i_addr2[IEEE80211_ADDR_LEN];
310 /* FCS */
298} GNUNET_PACKED; 311} GNUNET_PACKED;
299 312
300struct ieee80211_frame_rts { 313struct ieee80211_frame_rts
301 u_int8_t i_fc[2]; 314{
302 u_int8_t i_dur[2]; 315 u_int8_t i_fc[2];
303 u_int8_t i_ra[IEEE80211_ADDR_LEN]; 316 u_int8_t i_dur[2];
304 u_int8_t i_ta[IEEE80211_ADDR_LEN]; 317 u_int8_t i_ra[IEEE80211_ADDR_LEN];
305 /* FCS */ 318 u_int8_t i_ta[IEEE80211_ADDR_LEN];
319 /* FCS */
306} GNUNET_PACKED; 320} GNUNET_PACKED;
307 321
308struct ieee80211_frame_cts { 322struct ieee80211_frame_cts
309 u_int8_t i_fc[2]; 323{
310 u_int8_t i_dur[2]; 324 u_int8_t i_fc[2];
311 u_int8_t i_ra[IEEE80211_ADDR_LEN]; 325 u_int8_t i_dur[2];
312 /* FCS */ 326 u_int8_t i_ra[IEEE80211_ADDR_LEN];
327 /* FCS */
313} GNUNET_PACKED; 328} GNUNET_PACKED;
314 329
315struct ieee80211_frame_ack { 330struct ieee80211_frame_ack
316 u_int8_t i_fc[2]; 331{
317 u_int8_t i_dur[2]; 332 u_int8_t i_fc[2];
318 u_int8_t i_ra[IEEE80211_ADDR_LEN]; 333 u_int8_t i_dur[2];
319 /* FCS */ 334 u_int8_t i_ra[IEEE80211_ADDR_LEN];
335 /* FCS */
320} GNUNET_PACKED; 336} GNUNET_PACKED;
321 337
322struct ieee80211_frame_pspoll { 338struct ieee80211_frame_pspoll
323 u_int8_t i_fc[2]; 339{
324 u_int8_t i_aid[2]; 340 u_int8_t i_fc[2];
325 u_int8_t i_bssid[IEEE80211_ADDR_LEN]; 341 u_int8_t i_aid[2];
326 u_int8_t i_ta[IEEE80211_ADDR_LEN]; 342 u_int8_t i_bssid[IEEE80211_ADDR_LEN];
327 /* FCS */ 343 u_int8_t i_ta[IEEE80211_ADDR_LEN];
344 /* FCS */
328} GNUNET_PACKED; 345} GNUNET_PACKED;
329 346
330struct ieee80211_frame_cfend { /* NB: also CF-End+CF-Ack */ 347struct ieee80211_frame_cfend
331 u_int8_t i_fc[2]; 348{ /* NB: also CF-End+CF-Ack */
332 u_int8_t i_dur[2]; /* should be zero */ 349 u_int8_t i_fc[2];
333 u_int8_t i_ra[IEEE80211_ADDR_LEN]; 350 u_int8_t i_dur[2]; /* should be zero */
334 u_int8_t i_bssid[IEEE80211_ADDR_LEN]; 351 u_int8_t i_ra[IEEE80211_ADDR_LEN];
335 /* FCS */ 352 u_int8_t i_bssid[IEEE80211_ADDR_LEN];
353 /* FCS */
336} GNUNET_PACKED; 354} GNUNET_PACKED;
337 355
338/* 356/*
@@ -372,63 +390,68 @@ typedef u_int8_t *ieee80211_mgt_beacon_t;
372/* 390/*
373 * 802.11i/WPA information element (maximally sized). 391 * 802.11i/WPA information element (maximally sized).
374 */ 392 */
375struct ieee80211_ie_wpa { 393struct ieee80211_ie_wpa
376 u_int8_t wpa_id; /* IEEE80211_ELEMID_VENDOR */ 394{
377 u_int8_t wpa_len; /* length in bytes */ 395 u_int8_t wpa_id; /* IEEE80211_ELEMID_VENDOR */
378 u_int8_t wpa_oui[3]; /* 0x00, 0x50, 0xf2 */ 396 u_int8_t wpa_len; /* length in bytes */
379 u_int8_t wpa_type; /* OUI type */ 397 u_int8_t wpa_oui[3]; /* 0x00, 0x50, 0xf2 */
380 u_int16_t wpa_version; /* spec revision */ 398 u_int8_t wpa_type; /* OUI type */
381 u_int32_t wpa_mcipher[1]; /* multicast/group key cipher */ 399 u_int16_t wpa_version; /* spec revision */
382 u_int16_t wpa_uciphercnt; /* # pairwise key ciphers */ 400 u_int32_t wpa_mcipher[1]; /* multicast/group key cipher */
383 u_int32_t wpa_uciphers[8];/* ciphers */ 401 u_int16_t wpa_uciphercnt; /* # pairwise key ciphers */
384 u_int16_t wpa_authselcnt; /* authentication selector cnt*/ 402 u_int32_t wpa_uciphers[8]; /* ciphers */
385 u_int32_t wpa_authsels[8];/* selectors */ 403 u_int16_t wpa_authselcnt; /* authentication selector cnt */
386 u_int16_t wpa_caps; /* 802.11i capabilities */ 404 u_int32_t wpa_authsels[8]; /* selectors */
387 u_int16_t wpa_pmkidcnt; /* 802.11i pmkid count */ 405 u_int16_t wpa_caps; /* 802.11i capabilities */
388 u_int16_t wpa_pmkids[8]; /* 802.11i pmkids */ 406 u_int16_t wpa_pmkidcnt; /* 802.11i pmkid count */
407 u_int16_t wpa_pmkids[8]; /* 802.11i pmkids */
389} GNUNET_PACKED; 408} GNUNET_PACKED;
390 409
391/* 410/*
392 * Management information element payloads. 411 * Management information element payloads.
393 */ 412 */
394 413
395enum { 414enum
396 IEEE80211_ELEMID_SSID = 0, 415{
397 IEEE80211_ELEMID_RATES = 1, 416 IEEE80211_ELEMID_SSID = 0,
398 IEEE80211_ELEMID_FHPARMS = 2, 417 IEEE80211_ELEMID_RATES = 1,
399 IEEE80211_ELEMID_DSPARMS = 3, 418 IEEE80211_ELEMID_FHPARMS = 2,
400 IEEE80211_ELEMID_CFPARMS = 4, 419 IEEE80211_ELEMID_DSPARMS = 3,
401 IEEE80211_ELEMID_TIM = 5, 420 IEEE80211_ELEMID_CFPARMS = 4,
402 IEEE80211_ELEMID_IBSSPARMS = 6, 421 IEEE80211_ELEMID_TIM = 5,
403 IEEE80211_ELEMID_COUNTRY = 7, 422 IEEE80211_ELEMID_IBSSPARMS = 6,
404 IEEE80211_ELEMID_CHALLENGE = 16, 423 IEEE80211_ELEMID_COUNTRY = 7,
405 /* 17-31 reserved for challenge text extension */ 424 IEEE80211_ELEMID_CHALLENGE = 16,
406 IEEE80211_ELEMID_ERP = 42, 425 /* 17-31 reserved for challenge text extension */
407 IEEE80211_ELEMID_RSN = 48, 426 IEEE80211_ELEMID_ERP = 42,
408 IEEE80211_ELEMID_XRATES = 50, 427 IEEE80211_ELEMID_RSN = 48,
409 IEEE80211_ELEMID_TPC = 150, 428 IEEE80211_ELEMID_XRATES = 50,
410 IEEE80211_ELEMID_CCKM = 156, 429 IEEE80211_ELEMID_TPC = 150,
411 IEEE80211_ELEMID_VENDOR = 221, /* vendor private */ 430 IEEE80211_ELEMID_CCKM = 156,
431 IEEE80211_ELEMID_VENDOR = 221, /* vendor private */
412}; 432};
413 433
414struct ieee80211_tim_ie { 434struct ieee80211_tim_ie
415 u_int8_t tim_ie; /* IEEE80211_ELEMID_TIM */ 435{
416 u_int8_t tim_len; 436 u_int8_t tim_ie; /* IEEE80211_ELEMID_TIM */
417 u_int8_t tim_count; /* DTIM count */ 437 u_int8_t tim_len;
418 u_int8_t tim_period; /* DTIM period */ 438 u_int8_t tim_count; /* DTIM count */
419 u_int8_t tim_bitctl; /* bitmap control */ 439 u_int8_t tim_period; /* DTIM period */
420 u_int8_t tim_bitmap[1]; /* variable-length bitmap */ 440 u_int8_t tim_bitctl; /* bitmap control */
441 u_int8_t tim_bitmap[1]; /* variable-length bitmap */
421} GNUNET_PACKED; 442} GNUNET_PACKED;
422 443
423struct ieee80211_country_ie { 444struct ieee80211_country_ie
424 u_int8_t ie; /* IEEE80211_ELEMID_COUNTRY */ 445{
425 u_int8_t len; 446 u_int8_t ie; /* IEEE80211_ELEMID_COUNTRY */
426 u_int8_t cc[3]; /* ISO CC+(I)ndoor/(O)utdoor */ 447 u_int8_t len;
427 struct { 448 u_int8_t cc[3]; /* ISO CC+(I)ndoor/(O)utdoor */
428 u_int8_t schan; /* starting channel */ 449 struct
429 u_int8_t nchan; /* number channels */ 450 {
430 u_int8_t maxtxpwr; /* tx power cap */ 451 u_int8_t schan; /* starting channel */
431 } GNUNET_PACKED band[4]; /* up to 4 sub bands */ 452 u_int8_t nchan; /* number channels */
453 u_int8_t maxtxpwr; /* tx power cap */
454 } GNUNET_PACKED band[4]; /* up to 4 sub bands */
432} GNUNET_PACKED; 455} GNUNET_PACKED;
433 456
434#define IEEE80211_CHALLENGE_LEN 128 457#define IEEE80211_CHALLENGE_LEN 128
@@ -448,13 +471,13 @@ struct ieee80211_country_ie {
448/* bits 3-6 reserved */ 471/* bits 3-6 reserved */
449#define ATHEROS_CAP_BOOST 0x80 472#define ATHEROS_CAP_BOOST 0x80
450 473
451#define ATH_OUI 0x7f0300 /* Atheros OUI */ 474#define ATH_OUI 0x7f0300 /* Atheros OUI */
452#define ATH_OUI_TYPE 0x01 475#define ATH_OUI_TYPE 0x01
453#define ATH_OUI_VERSION 0x01 476#define ATH_OUI_VERSION 0x01
454 477
455#define WPA_OUI 0xf25000 478#define WPA_OUI 0xf25000
456#define WPA_OUI_TYPE 0x01 479#define WPA_OUI_TYPE 0x01
457#define WPA_VERSION 1 /* current supported version */ 480#define WPA_VERSION 1 /* current supported version */
458 481
459#define WPA_CSE_NULL 0x00 482#define WPA_CSE_NULL 0x00
460#define WPA_CSE_WEP40 0x01 483#define WPA_CSE_WEP40 0x01
@@ -467,7 +490,7 @@ struct ieee80211_country_ie {
467#define WPA_ASE_8021X_PSK 0x02 490#define WPA_ASE_8021X_PSK 0x02
468 491
469#define RSN_OUI 0xac0f00 492#define RSN_OUI 0xac0f00
470#define RSN_VERSION 1 /* current supported version */ 493#define RSN_VERSION 1 /* current supported version */
471 494
472#define RSN_CSE_NULL 0x00 495#define RSN_CSE_NULL 0x00
473#define RSN_CSE_WEP40 0x01 496#define RSN_CSE_WEP40 0x01
@@ -489,10 +512,10 @@ struct ieee80211_country_ie {
489#define WME_VERSION 1 512#define WME_VERSION 1
490 513
491/* WME stream classes */ 514/* WME stream classes */
492#define WME_AC_BE 0 /* best effort */ 515#define WME_AC_BE 0 /* best effort */
493#define WME_AC_BK 1 /* background */ 516#define WME_AC_BK 1 /* background */
494#define WME_AC_VI 2 /* video */ 517#define WME_AC_VI 2 /* video */
495#define WME_AC_VO 3 /* voice */ 518#define WME_AC_VO 3 /* voice */
496 519
497/* 520/*
498 * AUTH management packets 521 * AUTH management packets
@@ -518,16 +541,18 @@ typedef u_int8_t *ieee80211_mgt_auth_t;
518#define IEEE80211_AUTH_ALG_SHARED 0x0001 541#define IEEE80211_AUTH_ALG_SHARED 0x0001
519#define IEEE80211_AUTH_ALG_LEAP 0x0080 542#define IEEE80211_AUTH_ALG_LEAP 0x0080
520 543
521enum { 544enum
522 IEEE80211_AUTH_OPEN_REQUEST = 1, 545{
523 IEEE80211_AUTH_OPEN_RESPONSE = 2, 546 IEEE80211_AUTH_OPEN_REQUEST = 1,
547 IEEE80211_AUTH_OPEN_RESPONSE = 2,
524}; 548};
525 549
526enum { 550enum
527 IEEE80211_AUTH_SHARED_REQUEST = 1, 551{
528 IEEE80211_AUTH_SHARED_CHALLENGE = 2, 552 IEEE80211_AUTH_SHARED_REQUEST = 1,
529 IEEE80211_AUTH_SHARED_RESPONSE = 3, 553 IEEE80211_AUTH_SHARED_CHALLENGE = 2,
530 IEEE80211_AUTH_SHARED_PASS = 4, 554 IEEE80211_AUTH_SHARED_RESPONSE = 3,
555 IEEE80211_AUTH_SHARED_PASS = 4,
531}; 556};
532 557
533/* 558/*
@@ -536,47 +561,48 @@ enum {
536 * Unlisted codes are reserved 561 * Unlisted codes are reserved
537 */ 562 */
538 563
539enum { 564enum
540 IEEE80211_REASON_UNSPECIFIED = 1, 565{
541 IEEE80211_REASON_AUTH_EXPIRE = 2, 566 IEEE80211_REASON_UNSPECIFIED = 1,
542 IEEE80211_REASON_AUTH_LEAVE = 3, 567 IEEE80211_REASON_AUTH_EXPIRE = 2,
543 IEEE80211_REASON_ASSOC_EXPIRE = 4, 568 IEEE80211_REASON_AUTH_LEAVE = 3,
544 IEEE80211_REASON_ASSOC_TOOMANY = 5, 569 IEEE80211_REASON_ASSOC_EXPIRE = 4,
545 IEEE80211_REASON_NOT_AUTHED = 6, 570 IEEE80211_REASON_ASSOC_TOOMANY = 5,
546 IEEE80211_REASON_NOT_ASSOCED = 7, 571 IEEE80211_REASON_NOT_AUTHED = 6,
547 IEEE80211_REASON_ASSOC_LEAVE = 8, 572 IEEE80211_REASON_NOT_ASSOCED = 7,
548 IEEE80211_REASON_ASSOC_NOT_AUTHED = 9, 573 IEEE80211_REASON_ASSOC_LEAVE = 8,
549 574 IEEE80211_REASON_ASSOC_NOT_AUTHED = 9,
550 IEEE80211_REASON_RSN_REQUIRED = 11, 575
551 IEEE80211_REASON_RSN_INCONSISTENT = 12, 576 IEEE80211_REASON_RSN_REQUIRED = 11,
552 IEEE80211_REASON_IE_INVALID = 13, 577 IEEE80211_REASON_RSN_INCONSISTENT = 12,
553 IEEE80211_REASON_MIC_FAILURE = 14, 578 IEEE80211_REASON_IE_INVALID = 13,
554 579 IEEE80211_REASON_MIC_FAILURE = 14,
555 IEEE80211_STATUS_SUCCESS = 0, 580
556 IEEE80211_STATUS_UNSPECIFIED = 1, 581 IEEE80211_STATUS_SUCCESS = 0,
557 IEEE80211_STATUS_CAPINFO = 10, 582 IEEE80211_STATUS_UNSPECIFIED = 1,
558 IEEE80211_STATUS_NOT_ASSOCED = 11, 583 IEEE80211_STATUS_CAPINFO = 10,
559 IEEE80211_STATUS_OTHER = 12, 584 IEEE80211_STATUS_NOT_ASSOCED = 11,
560 IEEE80211_STATUS_ALG = 13, 585 IEEE80211_STATUS_OTHER = 12,
561 IEEE80211_STATUS_SEQUENCE = 14, 586 IEEE80211_STATUS_ALG = 13,
562 IEEE80211_STATUS_CHALLENGE = 15, 587 IEEE80211_STATUS_SEQUENCE = 14,
563 IEEE80211_STATUS_TIMEOUT = 16, 588 IEEE80211_STATUS_CHALLENGE = 15,
564 IEEE80211_STATUS_TOOMANY = 17, 589 IEEE80211_STATUS_TIMEOUT = 16,
565 IEEE80211_STATUS_BASIC_RATE = 18, 590 IEEE80211_STATUS_TOOMANY = 17,
566 IEEE80211_STATUS_SP_REQUIRED = 19, 591 IEEE80211_STATUS_BASIC_RATE = 18,
567 IEEE80211_STATUS_PBCC_REQUIRED = 20, 592 IEEE80211_STATUS_SP_REQUIRED = 19,
568 IEEE80211_STATUS_CA_REQUIRED = 21, 593 IEEE80211_STATUS_PBCC_REQUIRED = 20,
569 IEEE80211_STATUS_TOO_MANY_STATIONS = 22, 594 IEEE80211_STATUS_CA_REQUIRED = 21,
570 IEEE80211_STATUS_RATES = 23, 595 IEEE80211_STATUS_TOO_MANY_STATIONS = 22,
571 IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25, 596 IEEE80211_STATUS_RATES = 23,
572 IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26, 597 IEEE80211_STATUS_SHORTSLOT_REQUIRED = 25,
598 IEEE80211_STATUS_DSSSOFDM_REQUIRED = 26,
573}; 599};
574 600
575#define IEEE80211_WEP_KEYLEN 5 /* 40bit */ 601#define IEEE80211_WEP_KEYLEN 5 /* 40bit */
576#define IEEE80211_WEP_IVLEN 3 /* 24bit */ 602#define IEEE80211_WEP_IVLEN 3 /* 24bit */
577#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */ 603#define IEEE80211_WEP_KIDLEN 1 /* 1 octet */
578#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */ 604#define IEEE80211_WEP_CRCLEN 4 /* CRC-32 */
579#define IEEE80211_WEP_NKID 4 /* number of key ids */ 605#define IEEE80211_WEP_NKID 4 /* number of key ids */
580 606
581/* 607/*
582 * 802.11i defines an extended IV for use with non-WEP ciphers. 608 * 802.11i defines an extended IV for use with non-WEP ciphers.
@@ -586,8 +612,8 @@ enum {
586 * CCMP header rather than IV+extended-IV. 612 * CCMP header rather than IV+extended-IV.
587 */ 613 */
588#define IEEE80211_WEP_EXTIV 0x20 614#define IEEE80211_WEP_EXTIV 0x20
589#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */ 615#define IEEE80211_WEP_EXTIVLEN 4 /* extended IV length */
590#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */ 616#define IEEE80211_WEP_MICLEN 8 /* trailing MIC */
591 617
592#define IEEE80211_CRC_LEN 4 618#define IEEE80211_CRC_LEN 4
593 619
@@ -641,16 +667,16 @@ enum {
641 * As above, we treat default as implementation-dependent so 667 * As above, we treat default as implementation-dependent so
642 * define it elsewhere. 668 * define it elsewhere.
643 */ 669 */
644#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */ 670#define IEEE80211_BINTVAL_MAX 1000 /* max beacon interval (TU's) */
645#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */ 671#define IEEE80211_BINTVAL_MIN 25 /* min beacon interval (TU's) */
646 672
647/* 673/*
648 * DTIM period (beacons). Min+max are not really defined 674 * DTIM period (beacons). Min+max are not really defined
649 * by the protocol but we want them publicly visible so 675 * by the protocol but we want them publicly visible so
650 * define them here. 676 * define them here.
651 */ 677 */
652#define IEEE80211_DTIM_MAX 15 /* max DTIM period */ 678#define IEEE80211_DTIM_MAX 15 /* max DTIM period */
653#define IEEE80211_DTIM_MIN 1 /* min DTIM period */ 679#define IEEE80211_DTIM_MIN 1 /* min DTIM period */
654 680
655/* 681/*
656 * Beacon miss threshold (beacons). As for DTIM, we define 682 * Beacon miss threshold (beacons). As for DTIM, we define
diff --git a/src/transport/wlan/ieee80211_radiotap.h b/src/transport/wlan/ieee80211_radiotap.h
index b132d402d..f3afbecce 100644
--- a/src/transport/wlan/ieee80211_radiotap.h
+++ b/src/transport/wlan/ieee80211_radiotap.h
@@ -66,25 +66,26 @@
66/* The radio capture header precedes the 802.11 header. 66/* The radio capture header precedes the 802.11 header.
67 * All data in the header is little endian on all platforms. 67 * All data in the header is little endian on all platforms.
68 */ 68 */
69struct ieee80211_radiotap_header { 69struct ieee80211_radiotap_header
70 u8 it_version; /* Version 0. Only increases 70{
71 * for drastic changes, 71 u8 it_version; /* Version 0. Only increases
72 * introduction of compatible 72 * for drastic changes,
73 * new fields does not count. 73 * introduction of compatible
74 */ 74 * new fields does not count.
75 u8 it_pad; 75 */
76 u16 it_len; /* length of the whole 76 u8 it_pad;
77 * header in bytes, including 77 u16 it_len; /* length of the whole
78 * it_version, it_pad, 78 * header in bytes, including
79 * it_len, and data fields. 79 * it_version, it_pad,
80 */ 80 * it_len, and data fields.
81 u32 it_present; /* A bitmap telling which 81 */
82 * fields are present. Set bit 31 82 u32 it_present; /* A bitmap telling which
83 * (0x80000000) to extend the 83 * fields are present. Set bit 31
84 * bitmap by another 32 bits. 84 * (0x80000000) to extend the
85 * Additional extensions are made 85 * bitmap by another 32 bits.
86 * by setting bit 31. 86 * Additional extensions are made
87 */ 87 * by setting bit 31.
88 */
88}; 89};
89 90
90#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000 91#define IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK 0x80000000
@@ -186,68 +187,69 @@ struct ieee80211_radiotap_header {
186 * Number of unicast retries a transmitted frame used. 187 * Number of unicast retries a transmitted frame used.
187 * 188 *
188 */ 189 */
189enum ieee80211_radiotap_type { 190enum ieee80211_radiotap_type
190 IEEE80211_RADIOTAP_TSFT = 0, 191{
191 IEEE80211_RADIOTAP_FLAGS = 1, 192 IEEE80211_RADIOTAP_TSFT = 0,
192 IEEE80211_RADIOTAP_RATE = 2, 193 IEEE80211_RADIOTAP_FLAGS = 1,
193 IEEE80211_RADIOTAP_CHANNEL = 3, 194 IEEE80211_RADIOTAP_RATE = 2,
194 IEEE80211_RADIOTAP_FHSS = 4, 195 IEEE80211_RADIOTAP_CHANNEL = 3,
195 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, 196 IEEE80211_RADIOTAP_FHSS = 4,
196 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, 197 IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5,
197 IEEE80211_RADIOTAP_LOCK_QUALITY = 7, 198 IEEE80211_RADIOTAP_DBM_ANTNOISE = 6,
198 IEEE80211_RADIOTAP_TX_ATTENUATION = 8, 199 IEEE80211_RADIOTAP_LOCK_QUALITY = 7,
199 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, 200 IEEE80211_RADIOTAP_TX_ATTENUATION = 8,
200 IEEE80211_RADIOTAP_DBM_TX_POWER = 10, 201 IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9,
201 IEEE80211_RADIOTAP_ANTENNA = 11, 202 IEEE80211_RADIOTAP_DBM_TX_POWER = 10,
202 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, 203 IEEE80211_RADIOTAP_ANTENNA = 11,
203 IEEE80211_RADIOTAP_DB_ANTNOISE = 13, 204 IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12,
204 IEEE80211_RADIOTAP_RX_FLAGS = 14, 205 IEEE80211_RADIOTAP_DB_ANTNOISE = 13,
205 IEEE80211_RADIOTAP_TX_FLAGS = 15, 206 IEEE80211_RADIOTAP_RX_FLAGS = 14,
206 IEEE80211_RADIOTAP_RTS_RETRIES = 16, 207 IEEE80211_RADIOTAP_TX_FLAGS = 15,
207 IEEE80211_RADIOTAP_DATA_RETRIES = 17, 208 IEEE80211_RADIOTAP_RTS_RETRIES = 16,
208 IEEE80211_RADIOTAP_EXT = 31 209 IEEE80211_RADIOTAP_DATA_RETRIES = 17,
210 IEEE80211_RADIOTAP_EXT = 31
209}; 211};
210 212
211/* Channel flags. */ 213/* Channel flags. */
212#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */ 214#define IEEE80211_CHAN_TURBO 0x0010 /* Turbo channel */
213#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */ 215#define IEEE80211_CHAN_CCK 0x0020 /* CCK channel */
214#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */ 216#define IEEE80211_CHAN_OFDM 0x0040 /* OFDM channel */
215#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */ 217#define IEEE80211_CHAN_2GHZ 0x0080 /* 2 GHz spectrum channel. */
216#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */ 218#define IEEE80211_CHAN_5GHZ 0x0100 /* 5 GHz spectrum channel */
217#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */ 219#define IEEE80211_CHAN_PASSIVE 0x0200 /* Only passive scan allowed */
218#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */ 220#define IEEE80211_CHAN_DYN 0x0400 /* Dynamic CCK-OFDM channel */
219#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */ 221#define IEEE80211_CHAN_GFSK 0x0800 /* GFSK channel (FHSS PHY) */
220 222
221/* For IEEE80211_RADIOTAP_FLAGS */ 223/* For IEEE80211_RADIOTAP_FLAGS */
222#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received 224#define IEEE80211_RADIOTAP_F_CFP 0x01 /* sent/received
223 * during CFP 225 * during CFP
224 */ 226 */
225#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received 227#define IEEE80211_RADIOTAP_F_SHORTPRE 0x02 /* sent/received
226 * with short 228 * with short
227 * preamble 229 * preamble
228 */ 230 */
229#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received 231#define IEEE80211_RADIOTAP_F_WEP 0x04 /* sent/received
230 * with WEP encryption 232 * with WEP encryption
231 */ 233 */
232#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received 234#define IEEE80211_RADIOTAP_F_FRAG 0x08 /* sent/received
233 * with fragmentation 235 * with fragmentation
234 */ 236 */
235#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */ 237#define IEEE80211_RADIOTAP_F_FCS 0x10 /* frame includes FCS */
236#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between 238#define IEEE80211_RADIOTAP_F_DATAPAD 0x20 /* frame has padding between
237 * 802.11 header and payload 239 * 802.11 header and payload
238 * (to 32-bit boundary) 240 * (to 32-bit boundary)
239 */ 241 */
240/* For IEEE80211_RADIOTAP_RX_FLAGS */ 242/* For IEEE80211_RADIOTAP_RX_FLAGS */
241#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */ 243#define IEEE80211_RADIOTAP_F_RX_BADFCS 0x0001 /* frame failed crc check */
242 244
243/* For IEEE80211_RADIOTAP_TX_FLAGS */ 245/* For IEEE80211_RADIOTAP_TX_FLAGS */
244#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive 246#define IEEE80211_RADIOTAP_F_TX_FAIL 0x0001 /* failed due to excessive
245 * retries */ 247 * retries */
246#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */ 248#define IEEE80211_RADIOTAP_F_TX_CTS 0x0002 /* used cts 'protection' */
247#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */ 249#define IEEE80211_RADIOTAP_F_TX_RTS 0x0004 /* used rts/cts handshake */
248#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */ 250#define IEEE80211_RADIOTAP_F_TX_NOACK 0x0008 /* frame should not be ACKed */
249#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled 251#define IEEE80211_RADIOTAP_F_TX_NOSEQ 0x0010 /* sequence number handled
250 * by userspace */ 252 * by userspace */
251 253
252/* Ugly macro to convert literal channel numbers into their mhz equivalents 254/* Ugly macro to convert literal channel numbers into their mhz equivalents
253 * There are certianly some conditions that will break this (like feeding it '30') 255 * There are certianly some conditions that will break this (like feeding it '30')
@@ -257,4 +259,4 @@ enum ieee80211_radiotap_type {
257 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \ 259 (((x) == 14) ? 2484 : ((x) * 5) + 2407) : \
258 ((x) + 1000) * 5) 260 ((x) + 1000) * 5)
259 261
260#endif /* IEEE80211_RADIOTAP_H */ 262#endif /* IEEE80211_RADIOTAP_H */
diff --git a/src/transport/wlan/loopback_helper.h b/src/transport/wlan/loopback_helper.h
index 7c9fd5d07..d6afb1129 100644
--- a/src/transport/wlan/loopback_helper.h
+++ b/src/transport/wlan/loopback_helper.h
@@ -14,7 +14,6 @@
14 14
15//static void file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr); 15//static void file_in_send(void *cls, void *client, const struct GNUNET_MessageHeader *hdr);
16 16
17int 17int testmode (int argc, char *argv[]);
18testmode(int argc, char *argv[]);
19 18
20#endif /* LOOPBACK_HELPER_H_ */ 19#endif /* LOOPBACK_HELPER_H_ */
diff --git a/src/transport/wlan/radiotap-parser.c b/src/transport/wlan/radiotap-parser.c
index 46ea6d542..51dfd7107 100644
--- a/src/transport/wlan/radiotap-parser.c
+++ b/src/transport/wlan/radiotap-parser.c
@@ -38,67 +38,69 @@
38 */ 38 */
39 39
40 40
41int ieee80211_radiotap_iterator_init( 41int
42 struct ieee80211_radiotap_iterator * iterator, 42ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator *iterator,
43 struct ieee80211_radiotap_header * radiotap_header, 43 struct ieee80211_radiotap_header
44 int max_length) 44 *radiotap_header, int max_length)
45{ 45{
46 if(iterator == NULL) 46 if (iterator == NULL)
47 return (-EINVAL); 47 return (-EINVAL);
48 48
49 if(radiotap_header == NULL) 49 if (radiotap_header == NULL)
50 return (-EINVAL); 50 return (-EINVAL);
51 /* Linux only supports version 0 radiotap format */ 51 /* Linux only supports version 0 radiotap format */
52 52
53 if (radiotap_header->it_version) 53 if (radiotap_header->it_version)
54 return (-EINVAL); 54 return (-EINVAL);
55 55
56 /* sanity check for allowed length and radiotap length field */ 56 /* sanity check for allowed length and radiotap length field */
57 57
58 if (max_length < (le16_to_cpu(radiotap_header->it_len))) 58 if (max_length < (le16_to_cpu (radiotap_header->it_len)))
59 return (-EINVAL); 59 return (-EINVAL);
60 60
61 iterator->rtheader = radiotap_header; 61 iterator->rtheader = radiotap_header;
62 iterator->max_length = le16_to_cpu(radiotap_header->it_len); 62 iterator->max_length = le16_to_cpu (radiotap_header->it_len);
63 iterator->arg_index = 0; 63 iterator->arg_index = 0;
64 iterator->bitmap_shifter = le32_to_cpu(radiotap_header->it_present); 64 iterator->bitmap_shifter = le32_to_cpu (radiotap_header->it_present);
65 iterator->arg = ((u8 *)radiotap_header) + 65 iterator->arg = ((u8 *) radiotap_header) +
66 sizeof (struct ieee80211_radiotap_header); 66 sizeof (struct ieee80211_radiotap_header);
67 iterator->this_arg = 0; 67 iterator->this_arg = 0;
68 68
69 /* find payload start allowing for extended bitmap(s) */ 69 /* find payload start allowing for extended bitmap(s) */
70 70
71 if (unlikely(iterator->bitmap_shifter & 71 if (unlikely (iterator->bitmap_shifter &
72 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)) { 72 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK))
73 while (le32_to_cpu(*((u32 *)iterator->arg)) & 73 {
74 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK) { 74 while (le32_to_cpu (*((u32 *) iterator->arg)) &
75 iterator->arg += sizeof (u32); 75 IEEE80211_RADIOTAP_PRESENT_EXTEND_MASK)
76 {
77 iterator->arg += sizeof (u32);
76 78
77 /* 79 /*
78 * check for insanity where the present bitmaps 80 * check for insanity where the present bitmaps
79 * keep claiming to extend up to or even beyond the 81 * keep claiming to extend up to or even beyond the
80 * stated radiotap header length 82 * stated radiotap header length
81 */ 83 */
82 84
83 if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) > 85 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
84 iterator->max_length) 86 iterator->max_length)
85 return (-EINVAL); 87 return (-EINVAL);
86 88
87 } 89 }
88 90
89 iterator->arg += sizeof (u32); 91 iterator->arg += sizeof (u32);
90 92
91 /* 93 /*
92 * no need to check again for blowing past stated radiotap 94 * no need to check again for blowing past stated radiotap
93 * header length, becuase ieee80211_radiotap_iterator_next 95 * header length, becuase ieee80211_radiotap_iterator_next
94 * checks it before it is dereferenced 96 * checks it before it is dereferenced
95 */ 97 */
96 98
97 } 99 }
98 100
99 /* we are all initialized happily */ 101 /* we are all initialized happily */
100 102
101 return (0); 103 return (0);
102} 104}
103 105
104 106
@@ -115,137 +117,143 @@ int ieee80211_radiotap_iterator_init(
115 * format. 117 * format.
116 */ 118 */
117 119
118int ieee80211_radiotap_iterator_next( 120int
119 struct ieee80211_radiotap_iterator * iterator) 121ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator *iterator)
120{ 122{
121 123
122 /* 124 /*
123 * small length lookup table for all radiotap types we heard of 125 * small length lookup table for all radiotap types we heard of
124 * starting from b0 in the bitmap, so we can walk the payload 126 * starting from b0 in the bitmap, so we can walk the payload
125 * area of the radiotap header 127 * area of the radiotap header
126 * 128 *
127 * There is a requirement to pad args, so that args 129 * There is a requirement to pad args, so that args
128 * of a given length must begin at a boundary of that length 130 * of a given length must begin at a boundary of that length
129 * -- but note that compound args are allowed (eg, 2 x u16 131 * -- but note that compound args are allowed (eg, 2 x u16
130 * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not 132 * for IEEE80211_RADIOTAP_CHANNEL) so total arg length is not
131 * a reliable indicator of alignment requirement. 133 * a reliable indicator of alignment requirement.
132 * 134 *
133 * upper nybble: content alignment for arg 135 * upper nybble: content alignment for arg
134 * lower nybble: content length for arg 136 * lower nybble: content length for arg
135 */ 137 */
136 138
137 static const u8 rt_sizes[] = { 139 static const u8 rt_sizes[] = {
138 [IEEE80211_RADIOTAP_TSFT] = 0x88, 140 [IEEE80211_RADIOTAP_TSFT] = 0x88,
139 [IEEE80211_RADIOTAP_FLAGS] = 0x11, 141 [IEEE80211_RADIOTAP_FLAGS] = 0x11,
140 [IEEE80211_RADIOTAP_RATE] = 0x11, 142 [IEEE80211_RADIOTAP_RATE] = 0x11,
141 [IEEE80211_RADIOTAP_CHANNEL] = 0x24, 143 [IEEE80211_RADIOTAP_CHANNEL] = 0x24,
142 [IEEE80211_RADIOTAP_FHSS] = 0x22, 144 [IEEE80211_RADIOTAP_FHSS] = 0x22,
143 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11, 145 [IEEE80211_RADIOTAP_DBM_ANTSIGNAL] = 0x11,
144 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11, 146 [IEEE80211_RADIOTAP_DBM_ANTNOISE] = 0x11,
145 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22, 147 [IEEE80211_RADIOTAP_LOCK_QUALITY] = 0x22,
146 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22, 148 [IEEE80211_RADIOTAP_TX_ATTENUATION] = 0x22,
147 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22, 149 [IEEE80211_RADIOTAP_DB_TX_ATTENUATION] = 0x22,
148 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11, 150 [IEEE80211_RADIOTAP_DBM_TX_POWER] = 0x11,
149 [IEEE80211_RADIOTAP_ANTENNA] = 0x11, 151 [IEEE80211_RADIOTAP_ANTENNA] = 0x11,
150 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11, 152 [IEEE80211_RADIOTAP_DB_ANTSIGNAL] = 0x11,
151 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11, 153 [IEEE80211_RADIOTAP_DB_ANTNOISE] = 0x11,
152 [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22, 154 [IEEE80211_RADIOTAP_TX_FLAGS] = 0x22,
153 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22, 155 [IEEE80211_RADIOTAP_RX_FLAGS] = 0x22,
154 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11, 156 [IEEE80211_RADIOTAP_RTS_RETRIES] = 0x11,
155 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11 157 [IEEE80211_RADIOTAP_DATA_RETRIES] = 0x11
156 /* 158 /*
157 * add more here as they are defined in 159 * add more here as they are defined in
158 * include/net/ieee80211_radiotap.h 160 * include/net/ieee80211_radiotap.h
159 */ 161 */
160 }; 162 };
161 163
162 /* 164 /*
163 * for every radiotap entry we can at 165 * for every radiotap entry we can at
164 * least skip (by knowing the length)... 166 * least skip (by knowing the length)...
165 */ 167 */
166 168
167 while (iterator->arg_index < (int)sizeof (rt_sizes)) { 169 while (iterator->arg_index < (int) sizeof (rt_sizes))
168 int hit = 0; 170 {
169 171 int hit = 0;
170 if (!(iterator->bitmap_shifter & 1)) 172
171 goto next_entry; /* arg not present */ 173 if (!(iterator->bitmap_shifter & 1))
172 174 goto next_entry; /* arg not present */
173 /* 175
174 * arg is present, account for alignment padding 176 /*
175 * 8-bit args can be at any alignment 177 * arg is present, account for alignment padding
176 * 16-bit args must start on 16-bit boundary 178 * 8-bit args can be at any alignment
177 * 32-bit args must start on 32-bit boundary 179 * 16-bit args must start on 16-bit boundary
178 * 64-bit args must start on 64-bit boundary 180 * 32-bit args must start on 32-bit boundary
179 * 181 * 64-bit args must start on 64-bit boundary
180 * note that total arg size can differ from alignment of 182 *
181 * elements inside arg, so we use upper nybble of length 183 * note that total arg size can differ from alignment of
182 * table to base alignment on 184 * elements inside arg, so we use upper nybble of length
183 * 185 * table to base alignment on
184 * also note: these alignments are ** relative to the 186 *
185 * start of the radiotap header **. There is no guarantee 187 * also note: these alignments are ** relative to the
186 * that the radiotap header itself is aligned on any 188 * start of the radiotap header **. There is no guarantee
187 * kind of boundary. 189 * that the radiotap header itself is aligned on any
188 */ 190 * kind of boundary.
189 191 */
190 if ((((void*)iterator->arg)-((void*)iterator->rtheader)) & 192
191 ((rt_sizes[iterator->arg_index] >> 4) - 1)) 193 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) &
192 iterator->arg_index += 194 ((rt_sizes[iterator->arg_index] >> 4) - 1))
193 (rt_sizes[iterator->arg_index] >> 4) - 195 iterator->arg_index +=
194 ((((void*)iterator->arg) - 196 (rt_sizes[iterator->arg_index] >> 4) -
195 ((void*)iterator->rtheader)) & 197 ((((void *) iterator->arg) -
196 ((rt_sizes[iterator->arg_index] >> 4) - 1)); 198 ((void *) iterator->rtheader)) &
197 199 ((rt_sizes[iterator->arg_index] >> 4) - 1));
198 /* 200
199 * this is what we will return to user, but we need to 201 /*
200 * move on first so next call has something fresh to test 202 * this is what we will return to user, but we need to
201 */ 203 * move on first so next call has something fresh to test
202 204 */
203 iterator->this_arg_index = iterator->arg_index; 205
204 iterator->this_arg = iterator->arg; 206 iterator->this_arg_index = iterator->arg_index;
205 hit = 1; 207 iterator->this_arg = iterator->arg;
206 208 hit = 1;
207 /* internally move on the size of this arg */ 209
208 210 /* internally move on the size of this arg */
209 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f; 211
210 212 iterator->arg += rt_sizes[iterator->arg_index] & 0x0f;
211 /* 213
212 * check for insanity where we are given a bitmap that 214 /*
213 * claims to have more arg content than the length of the 215 * check for insanity where we are given a bitmap that
214 * radiotap section. We will normally end up equalling this 216 * claims to have more arg content than the length of the
215 * max_length on the last arg, never exceeding it. 217 * radiotap section. We will normally end up equalling this
216 */ 218 * max_length on the last arg, never exceeding it.
217 219 */
218 if ((((void*)iterator->arg) - ((void*)iterator->rtheader)) > 220
219 iterator->max_length) 221 if ((((void *) iterator->arg) - ((void *) iterator->rtheader)) >
220 return (-EINVAL); 222 iterator->max_length)
221 223 return (-EINVAL);
222 next_entry: 224
223 225next_entry:
224 iterator->arg_index++; 226
225 if (unlikely((iterator->arg_index & 31) == 0)) { 227 iterator->arg_index++;
226 /* completed current u32 bitmap */ 228 if (unlikely ((iterator->arg_index & 31) == 0))
227 if (iterator->bitmap_shifter & 1) { 229 {
228 /* b31 was set, there is more */ 230 /* completed current u32 bitmap */
229 /* move to next u32 bitmap */ 231 if (iterator->bitmap_shifter & 1)
230 iterator->bitmap_shifter = le32_to_cpu( 232 {
231 *iterator->next_bitmap); 233 /* b31 was set, there is more */
232 iterator->next_bitmap++; 234 /* move to next u32 bitmap */
233 } else { 235 iterator->bitmap_shifter = le32_to_cpu (*iterator->next_bitmap);
234 /* no more bitmaps: end */ 236 iterator->next_bitmap++;
235 iterator->arg_index = sizeof (rt_sizes); 237 }
236 } 238 else
237 } else { /* just try the next bit */ 239 {
238 iterator->bitmap_shifter >>= 1; 240 /* no more bitmaps: end */
239 } 241 iterator->arg_index = sizeof (rt_sizes);
240 242 }
241 /* if we found a valid arg earlier, return it now */ 243 }
242 244 else
243 if (hit) 245 { /* just try the next bit */
244 return (iterator->this_arg_index); 246 iterator->bitmap_shifter >>= 1;
245 247 }
246 } 248
247 249 /* if we found a valid arg earlier, return it now */
248 /* we don't know how to handle any more args, we're done */ 250
249 251 if (hit)
250 return (-1); 252 return (iterator->this_arg_index);
253
254 }
255
256 /* we don't know how to handle any more args, we're done */
257
258 return (-1);
251} 259}
diff --git a/src/transport/wlan/radiotap-parser.h b/src/transport/wlan/radiotap-parser.h
index b36037369..fb6d8e2af 100644
--- a/src/transport/wlan/radiotap-parser.h
+++ b/src/transport/wlan/radiotap-parser.h
@@ -57,22 +57,23 @@ typedef uint8_t u8;
57 * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present 57 * @bitmap_shifter: internal shifter for curr u32 bitmap, b0 set == arg present
58 */ 58 */
59 59
60struct ieee80211_radiotap_iterator { 60struct ieee80211_radiotap_iterator
61 struct ieee80211_radiotap_header *rtheader; 61{
62 int max_length; 62 struct ieee80211_radiotap_header *rtheader;
63 int this_arg_index; 63 int max_length;
64 u8 * this_arg; 64 int this_arg_index;
65 u8 *this_arg;
65 66
66 int arg_index; 67 int arg_index;
67 u8 * arg; 68 u8 *arg;
68 u32 *next_bitmap; 69 u32 *next_bitmap;
69 u32 bitmap_shifter; 70 u32 bitmap_shifter;
70}; 71};
71 72
72int ieee80211_radiotap_iterator_init( 73int ieee80211_radiotap_iterator_init (struct ieee80211_radiotap_iterator
73 struct ieee80211_radiotap_iterator * iterator, 74 *iterator,
74 struct ieee80211_radiotap_header * radiotap_header, 75 struct ieee80211_radiotap_header
75 int max_length); 76 *radiotap_header, int max_length);
76 77
77int ieee80211_radiotap_iterator_next( 78int ieee80211_radiotap_iterator_next (struct ieee80211_radiotap_iterator
78 struct ieee80211_radiotap_iterator * iterator); 79 *iterator);