aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c59
-rw-r--r--src/transport/gnunet-service-transport.h5
-rw-r--r--src/transport/gnunet-service-transport_ats.c6
-rw-r--r--src/transport/gnunet-service-transport_clients.c28
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c402
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c31
-rw-r--r--src/transport/gnunet-service-transport_plugins.c57
-rw-r--r--src/transport/gnunet-service-transport_plugins.h4
-rw-r--r--src/transport/gnunet-service-transport_validation.c5
-rw-r--r--src/transport/plugin_transport_http_client.c22
-rw-r--r--src/transport/plugin_transport_tcp.c231
-rw-r--r--src/transport/plugin_transport_udp.c18
12 files changed, 500 insertions, 368 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index fcd2a492d..5840eec5e 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -176,7 +176,7 @@ static struct SessionKiller *sk_tail;
176/** 176/**
177 * Interface scanner determines our LAN address range(s). 177 * Interface scanner determines our LAN address range(s).
178 */ 178 */
179static struct GNUNET_ATS_InterfaceScanner *is; 179struct GNUNET_ATS_InterfaceScanner *GST_is;
180 180
181/** 181/**
182 * Head of DLL of blacklist checks we have pending for 182 * Head of DLL of blacklist checks we have pending for
@@ -697,53 +697,6 @@ plugin_env_session_end (void *cls,
697 697
698 698
699/** 699/**
700 * Function that will be called to figure if an address is an loopback,
701 * LAN, WAN etc. address
702 *
703 * @param cls closure
704 * @param addr binary address
705 * @param addrlen length of the @a addr
706 * @return type of the network @a addr belongs to
707 */
708static enum GNUNET_ATS_Network_Type
709plugin_env_address_to_type (void *cls,
710 const struct sockaddr *addr,
711 size_t addrlen)
712{
713 if (NULL == GST_ats)
714 {
715 GNUNET_break(0);
716 return GNUNET_ATS_NET_UNSPECIFIED;
717 }
718 return GNUNET_ATS_scanner_address_get_type (is,
719 addr,
720 addrlen);
721}
722
723
724/**
725 * Function that will be called to update metrics for an address
726 *
727 * @param cls closure
728 * @param address address to update metrics for
729 * @param session the session
730 * @param ats the ats information to update
731 * @param ats_count the number of @a ats elements
732 */
733static void
734plugin_env_update_metrics (void *cls,
735 const struct GNUNET_HELLO_Address *address,
736 struct Session *session,
737 const struct GNUNET_ATS_Information *ats,
738 uint32_t ats_count)
739{
740 GST_ats_update_metrics (address,
741 session,
742 ats, ats_count);
743}
744
745
746/**
747 * Black list check result from blacklist check triggered when a 700 * Black list check result from blacklist check triggered when a
748 * plugin gave us a new session in #plugin_env_session_start(). If 701 * plugin gave us a new session in #plugin_env_session_start(). If
749 * connection to the peer is disallowed, kill the session. 702 * connection to the peer is disallowed, kill the session.
@@ -940,8 +893,8 @@ shutdown_task (void *cls,
940 GST_ats = NULL; 893 GST_ats = NULL;
941 GNUNET_ATS_connectivity_done (GST_ats_connect); 894 GNUNET_ATS_connectivity_done (GST_ats_connect);
942 GST_ats_connect = NULL; 895 GST_ats_connect = NULL;
943 GNUNET_ATS_scanner_done (is); 896 GNUNET_ATS_scanner_done (GST_is);
944 is = NULL; 897 GST_is = NULL;
945 GST_clients_stop (); 898 GST_clients_stop ();
946 GST_blacklist_stop (); 899 GST_blacklist_stop ();
947 GST_hello_stop (); 900 GST_hello_stop ();
@@ -1075,7 +1028,7 @@ run (void *cls,
1075 GST_blacklist_start (GST_server, 1028 GST_blacklist_start (GST_server,
1076 GST_cfg, 1029 GST_cfg,
1077 &GST_my_identity); 1030 &GST_my_identity);
1078 is = GNUNET_ATS_scanner_init (); 1031 GST_is = GNUNET_ATS_scanner_init ();
1079 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg); 1032 GST_ats_connect = GNUNET_ATS_connectivity_init (GST_cfg);
1080 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, 1033 GST_ats = GNUNET_ATS_scheduling_init (GST_cfg,
1081 &ats_request_address_change, 1034 &ats_request_address_change,
@@ -1085,9 +1038,7 @@ run (void *cls,
1085 GST_plugins_load (&GST_manipulation_recv, 1038 GST_plugins_load (&GST_manipulation_recv,
1086 &plugin_env_address_change_notification, 1039 &plugin_env_address_change_notification,
1087 &plugin_env_session_start, 1040 &plugin_env_session_start,
1088 &plugin_env_session_end, 1041 &plugin_env_session_end);
1089 &plugin_env_address_to_type,
1090 &plugin_env_update_metrics);
1091 GST_neighbours_start ((max_fd / 3) * 2); 1042 GST_neighbours_start ((max_fd / 3) * 2);
1092 GST_clients_start (GST_server); 1043 GST_clients_start (GST_server);
1093 GST_validation_start ((max_fd / 3)); 1044 GST_validation_start ((max_fd / 3));
diff --git a/src/transport/gnunet-service-transport.h b/src/transport/gnunet-service-transport.h
index afceca3df..21a9ee2bc 100644
--- a/src/transport/gnunet-service-transport.h
+++ b/src/transport/gnunet-service-transport.h
@@ -68,6 +68,11 @@ extern struct GNUNET_ATS_SchedulingHandle *GST_ats;
68 */ 68 */
69extern struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect; 69extern struct GNUNET_ATS_ConnectivityHandle *GST_ats_connect;
70 70
71/**
72 * Interface scanner determines our LAN address range(s).
73 */
74extern struct GNUNET_ATS_InterfaceScanner *GST_is;
75
71 76
72/** 77/**
73 * Function to call when a peer's address has changed 78 * Function to call when a peer's address has changed
diff --git a/src/transport/gnunet-service-transport_ats.c b/src/transport/gnunet-service-transport_ats.c
index 5abc0531b..cb05e2fef 100644
--- a/src/transport/gnunet-service-transport_ats.c
+++ b/src/transport/gnunet-service-transport_ats.c
@@ -575,9 +575,9 @@ GST_ats_update_metrics (const struct GNUNET_HELLO_Address *address,
575 and if we get metrics for those, they were never known to 575 and if we get metrics for those, they were never known to
576 ATS which means we end up here (however, in this 576 ATS which means we end up here (however, in this
577 case, the address must be an outbound address). */ 577 case, the address must be an outbound address). */
578 GNUNET_assert (GNUNET_YES != 578 GNUNET_break (GNUNET_YES !=
579 GNUNET_HELLO_address_check_option (address, 579 GNUNET_HELLO_address_check_option (address,
580 GNUNET_HELLO_ADDRESS_INFO_INBOUND)); 580 GNUNET_HELLO_ADDRESS_INFO_INBOUND));
581 return; 581 return;
582 } 582 }
583 /* Call to manipulation to manipulate ATS information */ 583 /* Call to manipulation to manipulate ATS information */
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c
index db863ae65..87bc0699b 100644
--- a/src/transport/gnunet-service-transport_clients.c
+++ b/src/transport/gnunet-service-transport_clients.c
@@ -747,7 +747,8 @@ clients_handle_send (void *cls,
747 { 747 {
748 /* client asked for transmission before 'START' */ 748 /* client asked for transmission before 'START' */
749 GNUNET_break (0); 749 GNUNET_break (0);
750 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 750 GNUNET_SERVER_receive_done (client,
751 GNUNET_SYSERR);
751 return; 752 return;
752 } 753 }
753 754
@@ -756,7 +757,8 @@ clients_handle_send (void *cls,
756 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader)) 757 sizeof (struct OutboundMessage) + sizeof (struct GNUNET_MessageHeader))
757 { 758 {
758 GNUNET_break (0); 759 GNUNET_break (0);
759 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 760 GNUNET_SERVER_receive_done (client,
761 GNUNET_SYSERR);
760 return; 762 return;
761 } 763 }
762 obm = (const struct OutboundMessage *) message; 764 obm = (const struct OutboundMessage *) message;
@@ -765,7 +767,8 @@ clients_handle_send (void *cls,
765 if (msize < sizeof (struct GNUNET_MessageHeader)) 767 if (msize < sizeof (struct GNUNET_MessageHeader))
766 { 768 {
767 GNUNET_break (0); 769 GNUNET_break (0);
768 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 770 GNUNET_SERVER_receive_done (client,
771 GNUNET_SYSERR);
769 return; 772 return;
770 } 773 }
771 774
@@ -779,23 +782,27 @@ clients_handle_send (void *cls,
779 gettext_noop 782 gettext_noop
780 ("# bytes payload dropped (other peer was not connected)"), 783 ("# bytes payload dropped (other peer was not connected)"),
781 msize, GNUNET_NO); 784 msize, GNUNET_NO);
782 GNUNET_SERVER_receive_done (client, GNUNET_OK); 785 GNUNET_SERVER_receive_done (client,
786 GNUNET_OK);
783 return; 787 return;
784 } 788 }
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
786 "Received `%s' request from client with target `%4s' and first message of type %u and total size %u\n", 790 "Received SEND request for `%s' and first message of type %u and total size %u\n",
787 "SEND",
788 GNUNET_i2s (&obm->peer), 791 GNUNET_i2s (&obm->peer),
789 ntohs (obmm->type), 792 ntohs (obmm->type),
790 msize); 793 msize);
791 GNUNET_SERVER_receive_done (client, GNUNET_OK); 794 GNUNET_SERVER_receive_done (client,
795 GNUNET_OK);
792 stcc = GNUNET_new (struct SendTransmitContinuationContext); 796 stcc = GNUNET_new (struct SendTransmitContinuationContext);
793 stcc->target = obm->peer; 797 stcc->target = obm->peer;
794 stcc->client = client; 798 stcc->client = client;
795 GNUNET_SERVER_client_keep (client); 799 GNUNET_SERVER_client_keep (client);
796 GST_manipulation_send (&obm->peer, obmm, msize, 800 GST_manipulation_send (&obm->peer,
801 obmm,
802 msize,
797 GNUNET_TIME_relative_ntoh (obm->timeout), 803 GNUNET_TIME_relative_ntoh (obm->timeout),
798 &handle_send_transmit_continuation, stcc); 804 &handle_send_transmit_continuation,
805 stcc);
799} 806}
800 807
801 808
@@ -824,7 +831,8 @@ clients_handle_request_connect (void *cls,
824 sizeof (struct GNUNET_PeerIdentity))) 831 sizeof (struct GNUNET_PeerIdentity)))
825 { 832 {
826 GNUNET_break (0); 833 GNUNET_break (0);
827 GNUNET_SERVER_receive_done (client, GNUNET_OK); 834 GNUNET_SERVER_receive_done (client,
835 GNUNET_OK);
828 return; 836 return;
829 } 837 }
830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c
index 31b8a3a29..f52634edc 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -195,6 +195,7 @@ struct DelayQueueEntry *generic_dqe_tail;
195 */ 195 */
196struct GNUNET_SCHEDULER_Task * generic_send_delay_task; 196struct GNUNET_SCHEDULER_Task * generic_send_delay_task;
197 197
198
198static void 199static void
199set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value) 200set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value)
200{ 201{
@@ -228,9 +229,9 @@ set_metric(struct TM_Peer *dest, int direction, uint32_t type, uint32_t value)
228 default: 229 default:
229 break; 230 break;
230 } 231 }
231
232} 232}
233 233
234
234static uint32_t 235static uint32_t
235find_metric(struct TM_Peer *dest, uint32_t type, int direction) 236find_metric(struct TM_Peer *dest, uint32_t type, int direction)
236{ 237{
@@ -245,10 +246,10 @@ find_metric(struct TM_Peer *dest, uint32_t type, int direction)
245 return UINT32_MAX; 246 return UINT32_MAX;
246} 247}
247 248
249
248/** 250/**
249 * Clean up metrics for a peer 251 * Clean up metrics for a peer
250 */ 252 */
251
252static void 253static void
253free_metric(struct TM_Peer *dest) 254free_metric(struct TM_Peer *dest)
254{ 255{
@@ -263,6 +264,7 @@ free_metric(struct TM_Peer *dest)
263 } 264 }
264} 265}
265 266
267
266/** 268/**
267 * Set traffic metric to manipulate 269 * Set traffic metric to manipulate
268 * 270 *
@@ -349,6 +351,7 @@ GST_manipulation_set_metric(void *cls, struct GNUNET_SERVER_Client *client,
349 GNUNET_SERVER_receive_done(client, GNUNET_OK); 351 GNUNET_SERVER_receive_done(client, GNUNET_OK);
350} 352}
351 353
354
352static void 355static void
353send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 356send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
354{ 357{
@@ -359,11 +362,18 @@ send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
359 362
360 if (NULL != tmp) 363 if (NULL != tmp)
361 { 364 {
362 GNUNET_break(GNUNET_YES == GST_neighbours_test_connected (&dqe->id)); 365 GNUNET_break (GNUNET_YES ==
366 GST_neighbours_test_connected (&dqe->id));
363 tmp->send_delay_task = NULL; 367 tmp->send_delay_task = NULL;
364 GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe); 368 GNUNET_CONTAINER_DLL_remove (tmp->send_head,
365 GST_neighbours_send(&dqe->id, dqe->msg, dqe->msg_size, dqe->timeout, 369 tmp->send_tail,
366 dqe->cont, dqe->cont_cls); 370 dqe);
371 GST_neighbours_send (&dqe->id,
372 dqe->msg,
373 dqe->msg_size,
374 dqe->timeout,
375 dqe->cont,
376 dqe->cont_cls);
367 377
368 next = tmp->send_head; 378 next = tmp->send_head;
369 if (NULL != next) 379 if (NULL != next)
@@ -394,90 +404,114 @@ send_delayed(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
394 GNUNET_free(dqe); 404 GNUNET_free(dqe);
395} 405}
396 406
407
397/** 408/**
398 * Adapter function between transport's send function and transport plugins 409 * Adapter function between transport's send function and transport plugins.
410 * Delays message transmission if an artificial delay is configured.
399 * 411 *
400 * @param target the peer the message to send to 412 * @param target the peer the message to send to
401 * @param msg the message received 413 * @param msg the message received
402 * @param msg_size message size 414 * @param msg_size message size
403 * @param timeout timeout 415 * @param timeout timeout
404 * @param cont the continuation to call after sending 416 * @param cont the continuation to call after sending
405 * @param cont_cls cls for continuation 417 * @param cont_cls cls for @a cont
406 */ 418 */
407void 419void
408GST_manipulation_send(const struct GNUNET_PeerIdentity *target, const void *msg, 420GST_manipulation_send (const struct GNUNET_PeerIdentity *target,
409 size_t msg_size, struct GNUNET_TIME_Relative timeout, 421 const void *msg,
410 GST_NeighbourSendContinuation cont, void *cont_cls) 422 size_t msg_size,
423 struct GNUNET_TIME_Relative timeout,
424 GST_NeighbourSendContinuation cont,
425 void *cont_cls)
411{ 426{
412 struct TM_Peer *tmp; 427 struct TM_Peer *tmp;
413 struct DelayQueueEntry *dqe; 428 struct DelayQueueEntry *dqe;
414 struct GNUNET_TIME_Relative delay; 429 struct GNUNET_TIME_Relative delay;
430 int do_delay;
415 431
416 if (NULL 432 do_delay = GNUNET_NO;
417 != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, target))) 433 if (NULL != (tmp =
418 { 434 GNUNET_CONTAINER_multipeermap_get (man_handle.peers,
419 GNUNET_break(GNUNET_YES == GST_neighbours_test_connected(target)); 435 target)))
420 /* Manipulate here */ 436 {
421 /* Delay */ 437 GNUNET_break (GNUNET_YES ==
422 if (UINT32_MAX != find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, TM_SEND)) 438 GST_neighbours_test_connected(target));
423 { 439 /* check for peer-specific delay */
424 /* We have a delay */ 440 if (UINT32_MAX !=
425 delay.rel_value_us = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY, 441 find_metric (tmp,
426 TM_SEND); 442 GNUNET_ATS_QUALITY_NET_DELAY,
427 dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size); 443 TM_SEND))
428 dqe->id = *target;
429 dqe->tmp = tmp;
430 dqe->sent_at = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
431 delay);
432 dqe->cont = cont;
433 dqe->cont_cls = cont_cls;
434 dqe->msg = &dqe[1];
435 dqe->msg_size = msg_size;
436 dqe->timeout = timeout;
437 memcpy(dqe->msg, msg, msg_size);
438 GNUNET_CONTAINER_DLL_insert_tail(tmp->send_head, tmp->send_tail, dqe);
439 if (NULL == tmp->send_delay_task)
440 tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed(delay,
441 &send_delayed, dqe);
442 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
443 "Delaying %u byte message to peer `%s' with generic delay for %ms\n", msg_size, GNUNET_i2s (target), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
444 return;
445 }
446 }
447 else if (UINT32_MAX
448 != find_metric(&man_handle.general, GNUNET_ATS_QUALITY_NET_DELAY,
449 TM_SEND))
450 { 444 {
451 GNUNET_break(GNUNET_YES == GST_neighbours_test_connected(target));
452 /* We have a delay */ 445 /* We have a delay */
453 delay.rel_value_us = find_metric(&man_handle.general, 446 delay.rel_value_us = find_metric(tmp, GNUNET_ATS_QUALITY_NET_DELAY,
454 GNUNET_ATS_QUALITY_NET_DELAY, TM_SEND); 447 TM_SEND);
455 dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size); 448 do_delay = GNUNET_YES;
456 dqe->id = *target;
457 dqe->tmp = NULL;
458 dqe->sent_at = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(),
459 delay);
460 dqe->cont = cont;
461 dqe->cont_cls = cont_cls;
462 dqe->msg = &dqe[1];
463 dqe->msg_size = msg_size;
464 dqe->timeout = timeout;
465 memcpy(dqe->msg, msg, msg_size);
466 GNUNET_CONTAINER_DLL_insert_tail(generic_dqe_head, generic_dqe_tail, dqe);
467 if (NULL == generic_send_delay_task)
468 {
469 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed(delay,
470 &send_delayed, dqe);
471 }
472 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
473 "Delaying %u byte message to peer `%s' with peer specific delay for %s\n", msg_size, GNUNET_i2s (target), GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
474 return;
475 } 449 }
476 450 }
477 /* Normal sending */ 451 else if (UINT32_MAX !=
478 GST_neighbours_send(target, msg, msg_size, timeout, cont, cont_cls); 452 find_metric(&man_handle.general,
453 GNUNET_ATS_QUALITY_NET_DELAY,
454 TM_SEND))
455 {
456 GNUNET_break (GNUNET_YES ==
457 GST_neighbours_test_connected (target));
458 /* We have a delay */
459 delay.rel_value_us = find_metric (&man_handle.general,
460 GNUNET_ATS_QUALITY_NET_DELAY,
461 TM_SEND);
462 do_delay = GNUNET_YES;
463 }
464 if (GNUNET_NO == do_delay)
465 {
466 /* Normal sending */
467 GST_neighbours_send (target,
468 msg,
469 msg_size,
470 timeout,
471 cont, cont_cls);
472 return;
473 }
474 dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size);
475 dqe->id = *target;
476 dqe->tmp = tmp;
477 dqe->sent_at = GNUNET_TIME_relative_to_absolute (delay);
478 dqe->cont = cont;
479 dqe->cont_cls = cont_cls;
480 dqe->msg = &dqe[1];
481 dqe->msg_size = msg_size;
482 dqe->timeout = timeout;
483 memcpy (dqe->msg,
484 msg,
485 msg_size);
486 if (NULL == tmp)
487 {
488 GNUNET_CONTAINER_DLL_insert_tail (generic_dqe_head,
489 generic_dqe_tail,
490 dqe);
491 if (NULL == generic_send_delay_task)
492 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
493 &send_delayed,
494 dqe);
495 }
496 else
497 {
498 GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head,
499 tmp->send_tail,
500 dqe);
501 if (NULL == tmp->send_delay_task)
502 tmp->send_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
503 &send_delayed,
504 dqe);
505 }
506 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
507 "Delaying %u byte message to peer `%s' with peer specific delay for %s\n",
508 msg_size,
509 GNUNET_i2s (target),
510 GNUNET_STRINGS_relative_time_to_string (delay,
511 GNUNET_YES));
479} 512}
480 513
514
481/** 515/**
482 * Function that will be called to manipulate ATS information according to 516 * Function that will be called to manipulate ATS information according to
483 * current manipulation settings 517 * current manipulation settings
@@ -489,10 +523,10 @@ GST_manipulation_send(const struct GNUNET_PeerIdentity *target, const void *msg,
489 * @param ats_count the number of ats information 523 * @param ats_count the number of ats information
490 */ 524 */
491struct GNUNET_ATS_Information * 525struct GNUNET_ATS_Information *
492GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address, 526GST_manipulation_manipulate_metrics (const struct GNUNET_HELLO_Address *address,
493 struct Session *session, 527 struct Session *session,
494 const struct GNUNET_ATS_Information *ats, 528 const struct GNUNET_ATS_Information *ats,
495 uint32_t ats_count) 529 uint32_t ats_count)
496{ 530{
497 const struct GNUNET_PeerIdentity *peer = &address->peer; 531 const struct GNUNET_PeerIdentity *peer = &address->peer;
498 struct GNUNET_ATS_Information *ats_new; 532 struct GNUNET_ATS_Information *ats_new;
@@ -510,8 +544,11 @@ GST_manipulation_manipulate_metrics(const struct GNUNET_HELLO_Address *address,
510 ats_new[d] = ats[d]; 544 ats_new[d] = ats[d];
511 m_tmp = UINT32_MAX; 545 m_tmp = UINT32_MAX;
512 if (NULL != tmp) 546 if (NULL != tmp)
513 m_tmp = find_metric(tmp, ntohl(ats[d].type), TM_RECEIVE); 547 m_tmp = find_metric (tmp, ntohl(ats[d].type),
514 g_tmp = find_metric(&man_handle.general, ntohl(ats[d].type), TM_RECEIVE); 548 TM_RECEIVE);
549 g_tmp = find_metric (&man_handle.general,
550 ntohl(ats[d].type),
551 TM_RECEIVE);
515 552
516 if (UINT32_MAX != g_tmp) 553 if (UINT32_MAX != g_tmp)
517 ats_new[d].value = htonl(g_tmp); 554 ats_new[d].value = htonl(g_tmp);
@@ -565,14 +602,15 @@ GST_manipulation_recv (void *cls,
565 if (quota_delay.rel_value_us > m_delay.rel_value_us) 602 if (quota_delay.rel_value_us > m_delay.rel_value_us)
566 m_delay = quota_delay; 603 m_delay = quota_delay;
567 604
568 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
569 "Delaying next receive for peer `%s' for %s\n", 606 "Delaying next receive for peer `%s' for %s\n",
570 GNUNET_i2s (&address->peer), 607 GNUNET_i2s (&address->peer),
571 GNUNET_STRINGS_relative_time_to_string (m_delay, GNUNET_YES)); 608 GNUNET_STRINGS_relative_time_to_string (m_delay,
609 GNUNET_YES));
572 return m_delay; 610 return m_delay;
573
574} 611}
575 612
613
576/** 614/**
577 * Initialize traffic manipulation 615 * Initialize traffic manipulation
578 * 616 *
@@ -584,15 +622,21 @@ GST_manipulation_init(const struct GNUNET_CONFIGURATION_Handle *GST_cfg)
584 unsigned long long tmp; 622 unsigned long long tmp;
585 struct GNUNET_TIME_Relative delay; 623 struct GNUNET_TIME_Relative delay;
586 624
587 if ((GNUNET_OK 625 if ( (GNUNET_OK ==
588 == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport", 626 GNUNET_CONFIGURATION_get_value_number(GST_cfg,
589 "MANIPULATE_DISTANCE_IN", &tmp)) && (tmp > 0)) 627 "transport",
590 { 628 "MANIPULATE_DISTANCE_IN",
591 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 629 &tmp)) &&
592 "Setting inbound distance_in to %llu\n", (unsigned long long) tmp); 630 (tmp > 0) )
593 set_metric(&man_handle.general, TM_RECEIVE, 631 {
594 GNUNET_ATS_QUALITY_NET_DISTANCE, tmp); 632 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
595 } 633 "Setting inbound distance_in to %llu\n",
634 (unsigned long long) tmp);
635 set_metric (&man_handle.general,
636 TM_RECEIVE,
637 GNUNET_ATS_QUALITY_NET_DISTANCE,
638 tmp);
639 }
596 640
597 if ((GNUNET_OK 641 if ((GNUNET_OK
598 == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport", 642 == GNUNET_CONFIGURATION_get_value_number(GST_cfg, "transport",
@@ -625,92 +669,106 @@ GST_manipulation_init(const struct GNUNET_CONFIGURATION_Handle *GST_cfg)
625 man_handle.peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO); 669 man_handle.peers = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
626} 670}
627 671
672
628static int 673static int
629free_tmps(void *cls, const struct GNUNET_PeerIdentity *key, void *value) 674free_tmps (void *cls,
675 const struct GNUNET_PeerIdentity *key,
676 void *value)
630{ 677{
678 struct TM_Peer *tmp = value;
631 struct DelayQueueEntry *dqe; 679 struct DelayQueueEntry *dqe;
632 struct DelayQueueEntry *next;
633 680
634 if (NULL != value) 681 if (NULL == tmp)
635 { 682 return GNUNET_OK;
636 struct TM_Peer *tmp = (struct TM_Peer *) value; 683 GNUNET_break (GNUNET_YES ==
637 684 GNUNET_CONTAINER_multipeermap_remove (man_handle.peers,
638 if (GNUNET_YES 685 key,
639 != GNUNET_CONTAINER_multipeermap_remove(man_handle.peers, key, value)) 686 value));
640 GNUNET_break(0); 687 free_metric (tmp);
641 free_metric(tmp); 688 while (NULL != (dqe = tmp->send_head))
642 next = tmp->send_head; 689 {
643 while (NULL != (dqe = next)) 690 GNUNET_CONTAINER_DLL_remove (tmp->send_head,
644 { 691 tmp->send_tail,
645 next = dqe->next; 692 dqe);
646 GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe); 693 if (NULL != dqe->cont)
647 if (NULL != dqe->cont) 694 dqe->cont (dqe->cont_cls,
648 dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0); 695 GNUNET_SYSERR,
649 GNUNET_free(dqe); 696 dqe->msg_size,
650 } 697 0);
651 if (NULL != tmp->send_delay_task) 698 GNUNET_free (dqe);
652 { 699 }
653 GNUNET_SCHEDULER_cancel(tmp->send_delay_task); 700 if (NULL != tmp->send_delay_task)
654 tmp->send_delay_task = NULL; 701 {
655 } 702 GNUNET_SCHEDULER_cancel(tmp->send_delay_task);
656 GNUNET_free(tmp); 703 tmp->send_delay_task = NULL;
657 } 704 }
705 GNUNET_free(tmp);
658 return GNUNET_OK; 706 return GNUNET_OK;
659} 707}
660 708
709
661/** 710/**
662 * Notify manipulation about disconnect so it can discard queued messages 711 * Notify manipulation about disconnect so it can discard queued messages
663 * 712 *
664 * @param peer the disconnecting peer 713 * @param peer the disconnecting peer
665 */ 714 */
666void 715void
667GST_manipulation_peer_disconnect(const struct GNUNET_PeerIdentity *peer) 716GST_manipulation_peer_disconnect (const struct GNUNET_PeerIdentity *peer)
668{ 717{
669 struct TM_Peer *tmp; 718 struct TM_Peer *tmp;
670 struct DelayQueueEntry *dqe; 719 struct DelayQueueEntry *dqe;
671 struct DelayQueueEntry *next; 720 struct DelayQueueEntry *next;
672 721
673 if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer))) 722 if (NULL != (tmp = GNUNET_CONTAINER_multipeermap_get(man_handle.peers, peer)))
723 {
724 while (NULL != (dqe = tmp->send_head))
674 { 725 {
675 next = tmp->send_head; 726 GNUNET_CONTAINER_DLL_remove (tmp->send_head,
676 while (NULL != (dqe = next)) 727 tmp->send_tail,
677 { 728 dqe);
678 next = dqe->next; 729 if (NULL != dqe->cont)
679 GNUNET_CONTAINER_DLL_remove(tmp->send_head, tmp->send_tail, dqe); 730 dqe->cont (dqe->cont_cls,
680 if (NULL != dqe->cont) 731 GNUNET_SYSERR,
681 dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0); 732 dqe->msg_size,
682 GNUNET_free(dqe); 733 0);
683 } 734 GNUNET_free(dqe);
684 } 735 }
685 else if (UINT32_MAX 736 }
686 != find_metric(&man_handle.general, GNUNET_ATS_QUALITY_NET_DELAY, 737 else if (UINT32_MAX != find_metric (&man_handle.general,
687 TM_SEND)) 738 GNUNET_ATS_QUALITY_NET_DELAY,
739 TM_SEND))
740 {
741 next = generic_dqe_head;
742 while (NULL != (dqe = next))
688 { 743 {
689 next = generic_dqe_head; 744 next = dqe->next;
690 while (NULL != (dqe = next)) 745 if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id)))
691 { 746 {
692 next = dqe->next; 747 GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
693 if (0 == memcmp(peer, &dqe->id, sizeof(dqe->id))) 748 generic_dqe_tail,
694 { 749 dqe);
695 GNUNET_CONTAINER_DLL_remove(generic_dqe_head, generic_dqe_tail, 750 if (NULL != dqe->cont)
696 dqe); 751 dqe->cont (dqe->cont_cls,
697 if (NULL != dqe->cont) 752 GNUNET_SYSERR,
698 dqe->cont(dqe->cont_cls, GNUNET_SYSERR, dqe->msg_size, 0); 753 dqe->msg_size,
699 GNUNET_free(dqe); 754 0);
700 } 755 GNUNET_free(dqe);
701 } 756 }
702 if (NULL != generic_send_delay_task) 757 }
703 { 758 if (NULL != generic_send_delay_task)
704 GNUNET_SCHEDULER_cancel(generic_send_delay_task); 759 {
705 generic_send_delay_task = NULL; 760 GNUNET_SCHEDULER_cancel (generic_send_delay_task);
706 if (NULL != generic_dqe_head) 761 generic_send_delay_task = NULL;
707 generic_send_delay_task = GNUNET_SCHEDULER_add_delayed( 762 if (NULL != generic_dqe_head)
708 GNUNET_TIME_absolute_get_remaining(generic_dqe_head->sent_at), 763 generic_send_delay_task
709 &send_delayed, generic_dqe_head); 764 = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining(generic_dqe_head->sent_at),
710 } 765 &send_delayed,
766 generic_dqe_head);
711 } 767 }
768 }
712} 769}
713 770
771
714/** 772/**
715 * Stop traffic manipulation 773 * Stop traffic manipulation
716 */ 774 */
@@ -718,26 +776,30 @@ void
718GST_manipulation_stop() 776GST_manipulation_stop()
719{ 777{
720 struct DelayQueueEntry *cur; 778 struct DelayQueueEntry *cur;
721 struct DelayQueueEntry *next;
722 GNUNET_CONTAINER_multipeermap_iterate(man_handle.peers, &free_tmps, NULL);
723 GNUNET_CONTAINER_multipeermap_destroy(man_handle.peers);
724 779
725 next = generic_dqe_head; 780 GNUNET_CONTAINER_multipeermap_iterate (man_handle.peers,
726 while (NULL != (cur = next)) 781 &free_tmps,
727 { 782 NULL);
728 next = cur->next; 783 GNUNET_CONTAINER_multipeermap_destroy (man_handle.peers);
729 GNUNET_CONTAINER_DLL_remove(generic_dqe_head, generic_dqe_tail, cur);
730 if (NULL != cur->cont)
731 cur->cont(cur->cont_cls, GNUNET_SYSERR, cur->msg_size, 0);
732 GNUNET_free(cur);
733 }
734 if (NULL != generic_send_delay_task)
735 {
736 GNUNET_SCHEDULER_cancel(generic_send_delay_task);
737 generic_send_delay_task = NULL;
738 }
739 784
740 free_metric(&man_handle.general); 785 while (NULL != (cur = generic_dqe_head))
786 {
787 GNUNET_CONTAINER_DLL_remove (generic_dqe_head,
788 generic_dqe_tail,
789 cur);
790 if (NULL != cur->cont)
791 cur->cont (cur->cont_cls,
792 GNUNET_SYSERR,
793 cur->msg_size,
794 0);
795 GNUNET_free (cur);
796 }
797 if (NULL != generic_send_delay_task)
798 {
799 GNUNET_SCHEDULER_cancel (generic_send_delay_task);
800 generic_send_delay_task = NULL;
801 }
802 free_metric (&man_handle.general);
741 man_handle.peers = NULL; 803 man_handle.peers = NULL;
742} 804}
743 805
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 9316169a1..5cfb5ed6d 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1034,7 +1034,7 @@ send_with_session (struct NeighbourMapEntry *n,
1034 struct GNUNET_TRANSPORT_PluginFunctions *papi; 1034 struct GNUNET_TRANSPORT_PluginFunctions *papi;
1035 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL; 1035 struct GNUNET_TIME_Relative result = GNUNET_TIME_UNIT_FOREVER_REL;
1036 1036
1037 GNUNET_assert (n->primary_address.session != NULL); 1037 GNUNET_assert (NULL != n->primary_address.session);
1038 if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) || 1038 if ( ((NULL == (papi = GST_plugins_find (n->primary_address.address->transport_name)) ||
1039 (-1 == papi->send (papi->cls, 1039 (-1 == papi->send (papi->cls,
1040 n->primary_address.session, 1040 n->primary_address.session,
@@ -1561,7 +1561,8 @@ GST_neighbours_keepalive_response (const struct GNUNET_PeerIdentity *neighbour,
1561 : (uint32_t) latency.rel_value_us ); 1561 : (uint32_t) latency.rel_value_us );
1562 GST_ats_update_metrics (n->primary_address.address, 1562 GST_ats_update_metrics (n->primary_address.address,
1563 n->primary_address.session, 1563 n->primary_address.session,
1564 &ats, 1); 1564 &ats,
1565 1);
1565} 1566}
1566 1567
1567 1568
@@ -1680,14 +1681,20 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1680 { 1681 {
1681 GNUNET_break (0); 1682 GNUNET_break (0);
1682 if (NULL != cont) 1683 if (NULL != cont)
1683 cont (cont_cls, GNUNET_SYSERR, msg_size, 0); 1684 cont (cont_cls,
1685 GNUNET_SYSERR,
1686 msg_size,
1687 0);
1684 return; 1688 return;
1685 } 1689 }
1686 if (GNUNET_YES != test_connected (n)) 1690 if (GNUNET_YES != test_connected (n))
1687 { 1691 {
1688 GNUNET_break (0); 1692 GNUNET_break (0);
1689 if (NULL != cont) 1693 if (NULL != cont)
1690 cont (cont_cls, GNUNET_SYSERR, msg_size, 0); 1694 cont (cont_cls,
1695 GNUNET_SYSERR,
1696 msg_size,
1697 0);
1691 return; 1698 return;
1692 } 1699 }
1693 bytes_in_send_queue += msg_size; 1700 bytes_in_send_queue += msg_size;
@@ -1703,10 +1710,13 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
1703 mq->message_buf_size = msg_size; 1710 mq->message_buf_size = msg_size;
1704 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout); 1711 mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1705 1712
1706 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enqueueing %u bytes to send to peer %s\n", 1713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1707 msg_size, GNUNET_i2s (target)); 1714 "Enqueueing %u bytes to send to peer %s\n",
1708 1715 msg_size,
1709 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq); 1716 GNUNET_i2s (target));
1717 GNUNET_CONTAINER_DLL_insert_tail (n->messages_head,
1718 n->messages_tail,
1719 mq);
1710 if (NULL != n->task) 1720 if (NULL != n->task)
1711 GNUNET_SCHEDULER_cancel (n->task); 1721 GNUNET_SCHEDULER_cancel (n->task);
1712 n->task = GNUNET_SCHEDULER_add_now (&master_task, n); 1722 n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
@@ -2814,7 +2824,7 @@ send_utilization_data (void *cls,
2814 void *value) 2824 void *value)
2815{ 2825{
2816 struct NeighbourMapEntry *n = value; 2826 struct NeighbourMapEntry *n = value;
2817 struct GNUNET_ATS_Information atsi[4]; 2827 struct GNUNET_ATS_Information atsi[2];
2818 uint32_t bps_in; 2828 uint32_t bps_in;
2819 uint32_t bps_out; 2829 uint32_t bps_out;
2820 struct GNUNET_TIME_Relative delta; 2830 struct GNUNET_TIME_Relative delta;
@@ -2842,7 +2852,8 @@ send_utilization_data (void *cls,
2842 atsi[1].value = htonl (bps_in); 2852 atsi[1].value = htonl (bps_in);
2843 GST_ats_update_metrics (n->primary_address.address, 2853 GST_ats_update_metrics (n->primary_address.address,
2844 n->primary_address.session, 2854 n->primary_address.session,
2845 atsi, 2); 2855 atsi,
2856 2);
2846 n->util_total_bytes_recv = 0; 2857 n->util_total_bytes_recv = 0;
2847 n->util_total_bytes_sent = 0; 2858 n->util_total_bytes_sent = 0;
2848 n->last_util_transmission = GNUNET_TIME_absolute_get (); 2859 n->last_util_transmission = GNUNET_TIME_absolute_get ();
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c
index 79f7f4ddd..1571cee71 100644
--- a/src/transport/gnunet-service-transport_plugins.c
+++ b/src/transport/gnunet-service-transport_plugins.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-transport.h" 27#include "gnunet-service-transport.h"
28#include "gnunet-service-transport_hello.h" 28#include "gnunet-service-transport_hello.h"
29#include "gnunet-service-transport_ats.h"
29#include "gnunet-service-transport_plugins.h" 30#include "gnunet-service-transport_plugins.h"
30 31
31/** 32/**
@@ -79,6 +80,53 @@ static struct TransportPlugin *plugins_tail;
79 80
80 81
81/** 82/**
83 * Function that will be called to update metrics for an address
84 *
85 * @param cls closure
86 * @param address address to update metrics for
87 * @param session the session
88 * @param ats the ats information to update
89 * @param ats_count the number of @a ats elements
90 */
91static void
92plugin_env_update_metrics (void *cls,
93 const struct GNUNET_HELLO_Address *address,
94 struct Session *session,
95 const struct GNUNET_ATS_Information *ats,
96 uint32_t ats_count)
97{
98 GST_ats_update_metrics (address,
99 session,
100 ats, ats_count);
101}
102
103
104/**
105 * Function that will be called to figure if an address is an loopback,
106 * LAN, WAN etc. address
107 *
108 * @param cls closure
109 * @param addr binary address
110 * @param addrlen length of the @a addr
111 * @return type of the network @a addr belongs to
112 */
113static enum GNUNET_ATS_Network_Type
114plugin_env_address_to_type (void *cls,
115 const struct sockaddr *addr,
116 size_t addrlen)
117{
118 if (NULL == GST_is)
119 {
120 GNUNET_break(0);
121 return GNUNET_ATS_NET_UNSPECIFIED;
122 }
123 return GNUNET_ATS_scanner_address_get_type (GST_is,
124 addr,
125 addrlen);
126}
127
128
129/**
82 * Load and initialize all plugins. The respective functions will be 130 * Load and initialize all plugins. The respective functions will be
83 * invoked by the plugins when the respective events happen. The 131 * invoked by the plugins when the respective events happen. The
84 * closure will be set to a 'const char*' containing the name of the 132 * closure will be set to a 'const char*' containing the name of the
@@ -89,15 +137,12 @@ static struct TransportPlugin *plugins_tail;
89 * @param session_start_cb function to call when a session was created 137 * @param session_start_cb function to call when a session was created
90 * @param session_end_cb function to call when a session was terminated 138 * @param session_end_cb function to call when a session was terminated
91 * @param address_type_cb function to call when a address type is requested 139 * @param address_type_cb function to call when a address type is requested
92 * @param metric_update_cb function to call when address metrics change
93 */ 140 */
94void 141void
95GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 142GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
96 GNUNET_TRANSPORT_AddressNotification address_cb, 143 GNUNET_TRANSPORT_AddressNotification address_cb,
97 GNUNET_TRANSPORT_SessionStart session_start_cb, 144 GNUNET_TRANSPORT_SessionStart session_start_cb,
98 GNUNET_TRANSPORT_SessionEnd session_end_cb, 145 GNUNET_TRANSPORT_SessionEnd session_end_cb)
99 GNUNET_TRANSPORT_AddressToType address_type_cb,
100 GNUNET_TRANSPORT_UpdateAddressMetrics metric_update_cb)
101{ 146{
102 struct TransportPlugin *plug; 147 struct TransportPlugin *plug;
103 struct TransportPlugin *next; 148 struct TransportPlugin *next;
@@ -145,8 +190,8 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
145 plug->env.notify_address = address_cb; 190 plug->env.notify_address = address_cb;
146 plug->env.session_start = session_start_cb; 191 plug->env.session_start = session_start_cb;
147 plug->env.session_end = session_end_cb; 192 plug->env.session_end = session_end_cb;
148 plug->env.get_address_type = address_type_cb; 193 plug->env.get_address_type = &plugin_env_address_to_type;
149 plug->env.update_address_metrics = metric_update_cb; 194 plug->env.update_address_metrics = &plugin_env_update_metrics;
150 plug->env.max_connections = tneigh; 195 plug->env.max_connections = tneigh;
151 plug->env.stats = GST_stats; 196 plug->env.stats = GST_stats;
152 GNUNET_CONTAINER_DLL_insert (plugins_head, 197 GNUNET_CONTAINER_DLL_insert (plugins_head,
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h
index 461394f7e..006945678 100644
--- a/src/transport/gnunet-service-transport_plugins.h
+++ b/src/transport/gnunet-service-transport_plugins.h
@@ -52,9 +52,7 @@ void
52GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, 52GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
53 GNUNET_TRANSPORT_AddressNotification address_cb, 53 GNUNET_TRANSPORT_AddressNotification address_cb,
54 GNUNET_TRANSPORT_SessionStart session_start_cb, 54 GNUNET_TRANSPORT_SessionStart session_start_cb,
55 GNUNET_TRANSPORT_SessionEnd session_end_cb, 55 GNUNET_TRANSPORT_SessionEnd session_end_cb);
56 GNUNET_TRANSPORT_AddressToType address_type_cb,
57 GNUNET_TRANSPORT_UpdateAddressMetrics metric_update_cb);
58 56
59/** 57/**
60 * Unload all plugins 58 * Unload all plugins
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index cd5a87696..d8966f1a4 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -1473,7 +1473,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1473 ats[1].value = htonl ((uint32_t) ve->network); 1473 ats[1].value = htonl ((uint32_t) ve->network);
1474 if (GNUNET_YES == ve->known_to_ats) 1474 if (GNUNET_YES == ve->known_to_ats)
1475 { 1475 {
1476 GST_ats_update_metrics (ve->address, NULL, ats, 2); 1476 GST_ats_update_metrics (ve->address,
1477 NULL,
1478 ats,
1479 2);
1477 } 1480 }
1478 else 1481 else
1479 { 1482 {
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c
index 9dc2d114f..6e994d467 100644
--- a/src/transport/plugin_transport_http_client.c
+++ b/src/transport/plugin_transport_http_client.c
@@ -1884,13 +1884,13 @@ client_connect (struct Session *s)
1884 return GNUNET_SYSERR; 1884 return GNUNET_SYSERR;
1885 } 1885 }
1886 1886
1887 GNUNET_asprintf(&s->url, 1887 GNUNET_asprintf (&s->url,
1888 "%s/%s;%u", 1888 "%s/%s;%u",
1889 http_common_plugin_address_to_url(NULL, 1889 http_common_plugin_address_to_url (NULL,
1890 s->address->address, 1890 s->address->address,
1891 s->address->address_length), 1891 s->address->address_length),
1892 GNUNET_i2s_full (plugin->env->my_identity), 1892 GNUNET_i2s_full (plugin->env->my_identity),
1893 plugin->last_tag); 1893 plugin->last_tag);
1894 1894
1895 plugin->last_tag++; 1895 plugin->last_tag++;
1896 LOG (GNUNET_ERROR_TYPE_DEBUG, 1896 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -1911,21 +1911,23 @@ client_connect (struct Session *s)
1911 1911
1912 LOG (GNUNET_ERROR_TYPE_DEBUG, 1912 LOG (GNUNET_ERROR_TYPE_DEBUG,
1913 "Session %p: connected with GET %p and PUT %p\n", 1913 "Session %p: connected with GET %p and PUT %p\n",
1914 s, s->get.easyhandle, s->put.easyhandle); 1914 s, s->get.easyhandle,
1915 s->put.easyhandle);
1915 /* Perform connect */ 1916 /* Perform connect */
1916 GNUNET_STATISTICS_set (plugin->env->stats, 1917 GNUNET_STATISTICS_set (plugin->env->stats,
1917 HTTP_STAT_STR_CONNECTIONS, 1918 HTTP_STAT_STR_CONNECTIONS,
1918 plugin->cur_requests, 1919 plugin->cur_requests,
1919 GNUNET_NO); 1920 GNUNET_NO);
1920 /* Re-schedule since handles have changed */ 1921 /* Re-schedule since handles have changed */
1921 if (plugin->client_perform_task != NULL) 1922 if (NULL != plugin->client_perform_task)
1922 { 1923 {
1923 GNUNET_SCHEDULER_cancel (plugin->client_perform_task); 1924 GNUNET_SCHEDULER_cancel (plugin->client_perform_task);
1924 plugin->client_perform_task = NULL; 1925 plugin->client_perform_task = NULL;
1925 } 1926 }
1926 1927
1927 /* Schedule task to run immediately */ 1928 /* Schedule task to run immediately */
1928 plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run, plugin); 1929 plugin->client_perform_task = GNUNET_SCHEDULER_add_now (client_run,
1930 plugin);
1929 return res; 1931 return res;
1930} 1932}
1931 1933
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index f95e11f80..5396d5247 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -269,7 +269,7 @@ struct Session
269 /** 269 /**
270 * Task cleaning up a NAT client connection establishment attempt; 270 * Task cleaning up a NAT client connection establishment attempt;
271 */ 271 */
272 struct GNUNET_SCHEDULER_Task * nat_connection_timeout; 272 struct GNUNET_SCHEDULER_Task *nat_connection_timeout;
273 273
274 /** 274 /**
275 * Messages currently pending for transmission 275 * Messages currently pending for transmission
@@ -296,12 +296,12 @@ struct Session
296 /** 296 /**
297 * ID of task used to delay receiving more to throttle sender. 297 * ID of task used to delay receiving more to throttle sender.
298 */ 298 */
299 struct GNUNET_SCHEDULER_Task * receive_delay_task; 299 struct GNUNET_SCHEDULER_Task *receive_delay_task;
300 300
301 /** 301 /**
302 * Session timeout task 302 * Session timeout task
303 */ 303 */
304 struct GNUNET_SCHEDULER_Task * timeout_task; 304 struct GNUNET_SCHEDULER_Task *timeout_task;
305 305
306 /** 306 /**
307 * When will this session time out? 307 * When will this session time out?
@@ -891,7 +891,7 @@ tcp_plugin_disconnect_session (void *cls,
891 session, 891 session,
892 GNUNET_TRANSPORT_SS_DONE); 892 GNUNET_TRANSPORT_SS_DONE);
893 893
894 if (session->receive_delay_task != NULL) 894 if (NULL != session->receive_delay_task)
895 { 895 {
896 GNUNET_SCHEDULER_cancel (session->receive_delay_task); 896 GNUNET_SCHEDULER_cancel (session->receive_delay_task);
897 if (NULL != session->client) 897 if (NULL != session->client)
@@ -1101,8 +1101,8 @@ do_transmit (void *cls, size_t size, void *buf)
1101 tl = NULL; 1101 tl = NULL;
1102 ret = 0; 1102 ret = 0;
1103 now = GNUNET_TIME_absolute_get (); 1103 now = GNUNET_TIME_absolute_get ();
1104 while ((NULL != (pos = session->pending_messages_head)) 1104 while ( (NULL != (pos = session->pending_messages_head)) &&
1105 && (pos->timeout.abs_value_us <= now.abs_value_us)) 1105 (pos->timeout.abs_value_us <= now.abs_value_us) )
1106 { 1106 {
1107 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head, 1107 GNUNET_CONTAINER_DLL_remove (session->pending_messages_head,
1108 session->pending_messages_tail, 1108 session->pending_messages_tail,
@@ -1116,7 +1116,10 @@ do_transmit (void *cls, size_t size, void *buf)
1116 pos->message_size, 1116 pos->message_size,
1117 GNUNET_i2s (&session->target)); 1117 GNUNET_i2s (&session->target));
1118 ret += pos->message_size; 1118 ret += pos->message_size;
1119 GNUNET_CONTAINER_DLL_insert_after (hd, tl, tl, pos); 1119 GNUNET_CONTAINER_DLL_insert_after (hd,
1120 tl,
1121 tl,
1122 pos);
1120 } 1123 }
1121 /* do this call before callbacks (so that if callbacks destroy 1124 /* do this call before callbacks (so that if callbacks destroy
1122 * session, they have a chance to cancel actions done by this 1125 * session, they have a chance to cancel actions done by this
@@ -1127,12 +1130,15 @@ do_transmit (void *cls, size_t size, void *buf)
1127 * the callbacks may abort the session */ 1130 * the callbacks may abort the session */
1128 while (NULL != (pos = hd)) 1131 while (NULL != (pos = hd))
1129 { 1132 {
1130 GNUNET_CONTAINER_DLL_remove (hd, tl, pos); 1133 GNUNET_CONTAINER_DLL_remove (hd,
1131 if (pos->transmit_cont != NULL) 1134 tl,
1135 pos);
1136 if (NULL != pos->transmit_cont)
1132 pos->transmit_cont (pos->transmit_cont_cls, 1137 pos->transmit_cont (pos->transmit_cont_cls,
1133 &pid, 1138 &pid,
1134 GNUNET_SYSERR, 1139 GNUNET_SYSERR,
1135 pos->message_size, 0); 1140 pos->message_size,
1141 0);
1136 GNUNET_free (pos); 1142 GNUNET_free (pos);
1137 } 1143 }
1138 GNUNET_STATISTICS_update (plugin->env->stats, 1144 GNUNET_STATISTICS_update (plugin->env->stats,
@@ -1165,19 +1171,23 @@ do_transmit (void *cls, size_t size, void *buf)
1165 GNUNET_assert (pos->message_size <= session->bytes_in_queue); 1171 GNUNET_assert (pos->message_size <= session->bytes_in_queue);
1166 session->bytes_in_queue -= pos->message_size; 1172 session->bytes_in_queue -= pos->message_size;
1167 GNUNET_assert(size >= pos->message_size); 1173 GNUNET_assert(size >= pos->message_size);
1168 LOG(GNUNET_ERROR_TYPE_DEBUG, 1174 LOG (GNUNET_ERROR_TYPE_DEBUG,
1169 "Transmitting message of type %u size %u to %s\n", 1175 "Transmitting message of type %u size %u to %s\n",
1170 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type), 1176 ntohs (((struct GNUNET_MessageHeader *) pos->msg)->type),
1171 pos->message_size, 1177 pos->message_size,
1172 tcp_plugin_address_to_string (session->plugin, 1178 tcp_plugin_address_to_string (session->plugin,
1173 session->address->address, 1179 session->address->address,
1174 session->address->address_length)); 1180 session->address->address_length));
1175 /* FIXME: this memcpy can be up to 7% of our total runtime */ 1181 /* FIXME: this memcpy can be up to 7% of our total runtime */
1176 memcpy (cbuf, pos->msg, pos->message_size); 1182 memcpy (cbuf,
1183 pos->msg,
1184 pos->message_size);
1177 cbuf += pos->message_size; 1185 cbuf += pos->message_size;
1178 ret += pos->message_size; 1186 ret += pos->message_size;
1179 size -= pos->message_size; 1187 size -= pos->message_size;
1180 GNUNET_CONTAINER_DLL_insert_tail (hd, tl, pos); 1188 GNUNET_CONTAINER_DLL_insert_tail (hd,
1189 tl,
1190 pos);
1181 } 1191 }
1182 notify_session_monitor (session->plugin, 1192 notify_session_monitor (session->plugin,
1183 session, 1193 session,
@@ -1193,19 +1203,19 @@ do_transmit (void *cls, size_t size, void *buf)
1193 while (NULL != (pos = hd)) 1203 while (NULL != (pos = hd))
1194 { 1204 {
1195 GNUNET_CONTAINER_DLL_remove (hd, tl, pos); 1205 GNUNET_CONTAINER_DLL_remove (hd, tl, pos);
1196 if (pos->transmit_cont != NULL) 1206 if (NULL != pos->transmit_cont)
1197 pos->transmit_cont (pos->transmit_cont_cls, 1207 pos->transmit_cont (pos->transmit_cont_cls,
1198 &pid, 1208 &pid,
1199 GNUNET_OK, 1209 GNUNET_OK,
1200 pos->message_size, 1210 pos->message_size,
1201 pos->message_size); /* FIXME: include TCP overhead */ 1211 pos->message_size); /* FIXME: include TCP overhead */
1202 GNUNET_free(pos); 1212 GNUNET_free (pos);
1203 } 1213 }
1204 GNUNET_assert (NULL == hd); 1214 GNUNET_assert (NULL == hd);
1205 GNUNET_assert (NULL == tl); 1215 GNUNET_assert (NULL == tl);
1206 LOG(GNUNET_ERROR_TYPE_DEBUG, 1216 LOG (GNUNET_ERROR_TYPE_DEBUG,
1207 "Transmitting %u bytes\n", 1217 "Transmitting %u bytes\n",
1208 ret); 1218 ret);
1209 GNUNET_STATISTICS_update (plugin->env->stats, 1219 GNUNET_STATISTICS_update (plugin->env->stats,
1210 gettext_noop ("# bytes currently in TCP buffers"), 1220 gettext_noop ("# bytes currently in TCP buffers"),
1211 - (int64_t) ret, 1221 - (int64_t) ret,
@@ -1294,7 +1304,8 @@ tcp_plugin_send (void *cls,
1294 1304
1295 LOG(GNUNET_ERROR_TYPE_DEBUG, 1305 LOG(GNUNET_ERROR_TYPE_DEBUG,
1296 "Asked to transmit %u bytes to `%s', added message to list.\n", 1306 "Asked to transmit %u bytes to `%s', added message to list.\n",
1297 msgbuf_size, GNUNET_i2s (&session->target)); 1307 msgbuf_size,
1308 GNUNET_i2s (&session->target));
1298 1309
1299 if (GNUNET_YES == 1310 if (GNUNET_YES ==
1300 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap, 1311 GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
@@ -1303,10 +1314,11 @@ tcp_plugin_send (void *cls,
1303 { 1314 {
1304 GNUNET_assert (NULL != session->client); 1315 GNUNET_assert (NULL != session->client);
1305 GNUNET_SERVER_client_set_timeout (session->client, 1316 GNUNET_SERVER_client_set_timeout (session->client,
1306 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1317 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1307 GNUNET_STATISTICS_update (plugin->env->stats, 1318 GNUNET_STATISTICS_update (plugin->env->stats,
1308 gettext_noop ("# bytes currently in TCP buffers"), msgbuf_size, 1319 gettext_noop ("# bytes currently in TCP buffers"),
1309 GNUNET_NO); 1320 msgbuf_size,
1321 GNUNET_NO);
1310 1322
1311 /* append pm to pending_messages list */ 1323 /* append pm to pending_messages list */
1312 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head, 1324 GNUNET_CONTAINER_DLL_insert_tail (session->pending_messages_head,
@@ -1320,10 +1332,10 @@ tcp_plugin_send (void *cls,
1320 process_pending_messages (session); 1332 process_pending_messages (session);
1321 return msgbuf_size; 1333 return msgbuf_size;
1322 } 1334 }
1323 else if (GNUNET_YES == 1335 if (GNUNET_YES ==
1324 GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns, 1336 GNUNET_CONTAINER_multipeermap_contains_value (plugin->nat_wait_conns,
1325 &session->target, 1337 &session->target,
1326 session)) 1338 session))
1327 { 1339 {
1328 LOG (GNUNET_ERROR_TYPE_DEBUG, 1340 LOG (GNUNET_ERROR_TYPE_DEBUG,
1329 "This NAT WAIT session for peer `%s' is not yet ready!\n", 1341 "This NAT WAIT session for peer `%s' is not yet ready!\n",
@@ -1342,23 +1354,21 @@ tcp_plugin_send (void *cls,
1342 GNUNET_TRANSPORT_SS_HANDSHAKE); 1354 GNUNET_TRANSPORT_SS_HANDSHAKE);
1343 return msgbuf_size; 1355 return msgbuf_size;
1344 } 1356 }
1345 else 1357 LOG(GNUNET_ERROR_TYPE_ERROR,
1346 { 1358 "Invalid session %p\n",
1347 LOG(GNUNET_ERROR_TYPE_ERROR, 1359 session);
1348 "Invalid session %p\n", 1360 if (NULL != cont)
1349 session); 1361 cont (cont_cls,
1350 if (NULL != cont) 1362 &session->target,
1351 cont (cont_cls, 1363 GNUNET_SYSERR,
1352 &session->target, 1364 pm->message_size,
1353 GNUNET_SYSERR, 1365 0);
1354 pm->message_size, 1366 GNUNET_break (0);
1355 0); 1367 GNUNET_free (pm);
1356 GNUNET_break (0); 1368 return GNUNET_SYSERR; /* session does not exist here */
1357 GNUNET_free (pm);
1358 return GNUNET_SYSERR; /* session does not exist here */
1359 }
1360} 1369}
1361 1370
1371
1362/** 1372/**
1363 * Closure for #session_lookup_it(). 1373 * Closure for #session_lookup_it().
1364 */ 1374 */
@@ -1390,12 +1400,13 @@ session_lookup_it (void *cls,
1390 const struct GNUNET_PeerIdentity *key, 1400 const struct GNUNET_PeerIdentity *key,
1391 void *value) 1401 void *value)
1392{ 1402{
1393 struct SessionItCtx * si_ctx = cls; 1403 struct SessionItCtx *si_ctx = cls;
1394 struct Session * session = value; 1404 struct Session *session = value;
1395 1405
1396 if (0 != GNUNET_HELLO_address_cmp (si_ctx->address, session->address)) 1406 if (0 !=
1407 GNUNET_HELLO_address_cmp (si_ctx->address,
1408 session->address))
1397 return GNUNET_YES; 1409 return GNUNET_YES;
1398 /* Found existing session */
1399 si_ctx->result = session; 1410 si_ctx->result = session;
1400 return GNUNET_NO; 1411 return GNUNET_NO;
1401} 1412}
@@ -2273,12 +2284,16 @@ handle_tcp_welcome (void *cls,
2273 sizeof(struct GNUNET_PeerIdentity))) 2284 sizeof(struct GNUNET_PeerIdentity)))
2274 { 2285 {
2275 /* refuse connections from ourselves */ 2286 /* refuse connections from ourselves */
2276 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2287 GNUNET_SERVER_receive_done (client,
2277 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 2288 GNUNET_SYSERR);
2289 if (GNUNET_OK ==
2290 GNUNET_SERVER_client_get_address (client,
2291 &vaddr,
2292 &alen))
2278 { 2293 {
2279 LOG (GNUNET_ERROR_TYPE_INFO, 2294 LOG (GNUNET_ERROR_TYPE_INFO,
2280 "Received %s message from my own identity `%4s' on address `%s'\n", 2295 "Received WELCOME message from my own identity `%4s' on address `%s'\n",
2281 "WELCOME", GNUNET_i2s (&wm->clientIdentity), 2296 GNUNET_i2s (&wm->clientIdentity),
2282 GNUNET_a2s (vaddr, alen)); 2297 GNUNET_a2s (vaddr, alen));
2283 GNUNET_free(vaddr); 2298 GNUNET_free(vaddr);
2284 } 2299 }
@@ -2286,9 +2301,9 @@ handle_tcp_welcome (void *cls,
2286 } 2301 }
2287 2302
2288 LOG(GNUNET_ERROR_TYPE_DEBUG, 2303 LOG(GNUNET_ERROR_TYPE_DEBUG,
2289 "Received %s message from `%4s' %p\n", 2304 "Received WELCOME message from `%4s' %p\n",
2290 "WELCOME", 2305 GNUNET_i2s (&wm->clientIdentity),
2291 GNUNET_i2s (&wm->clientIdentity), client); 2306 client);
2292 GNUNET_STATISTICS_update (plugin->env->stats, 2307 GNUNET_STATISTICS_update (plugin->env->stats,
2293 gettext_noop ("# TCP WELCOME messages received"), 2308 gettext_noop ("# TCP WELCOME messages received"),
2294 1, 2309 1,
@@ -2296,7 +2311,8 @@ handle_tcp_welcome (void *cls,
2296 session = lookup_session_by_client (plugin, client); 2311 session = lookup_session_by_client (plugin, client);
2297 if (NULL != session) 2312 if (NULL != session)
2298 { 2313 {
2299 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 2314 if (GNUNET_OK ==
2315 GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
2300 { 2316 {
2301 LOG (GNUNET_ERROR_TYPE_DEBUG, 2317 LOG (GNUNET_ERROR_TYPE_DEBUG,
2302 "Found existing session %p for peer `%s'\n", 2318 "Found existing session %p for peer `%s'\n",
@@ -2313,7 +2329,8 @@ handle_tcp_welcome (void *cls,
2313 if (plugin->cur_connections == plugin->max_connections) 2329 if (plugin->cur_connections == plugin->max_connections)
2314 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */ 2330 GNUNET_SERVER_suspend (plugin->server); /* Maximum number of connections rechead */
2315 2331
2316 if (GNUNET_OK == GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) 2332 if (GNUNET_OK ==
2333 GNUNET_SERVER_client_get_address (client, &vaddr, &alen))
2317 { 2334 {
2318 if (alen == sizeof(struct sockaddr_in)) 2335 if (alen == sizeof(struct sockaddr_in))
2319 { 2336 {
@@ -2336,8 +2353,10 @@ handle_tcp_welcome (void *cls,
2336 t6.t6_port = s6->sin6_port; 2353 t6.t6_port = s6->sin6_port;
2337 memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr)); 2354 memcpy (&t6.ipv6_addr, &s6->sin6_addr, sizeof(struct in6_addr));
2338 address = GNUNET_HELLO_address_allocate (&wm->clientIdentity, 2355 address = GNUNET_HELLO_address_allocate (&wm->clientIdentity,
2339 PLUGIN_NAME, &t6, sizeof (t6), 2356 PLUGIN_NAME,
2340 GNUNET_HELLO_ADDRESS_INFO_INBOUND); 2357 &t6,
2358 sizeof (t6),
2359 GNUNET_HELLO_ADDRESS_INFO_INBOUND);
2341 } 2360 }
2342 else 2361 else
2343 { 2362 {
@@ -2345,9 +2364,15 @@ handle_tcp_welcome (void *cls,
2345 GNUNET_free_non_null (vaddr); 2364 GNUNET_free_non_null (vaddr);
2346 return; 2365 return;
2347 } 2366 }
2348 session = create_session (plugin, address, client, GNUNET_NO); 2367 session = create_session (plugin,
2368 address,
2369 client,
2370 GNUNET_NO);
2349 GNUNET_HELLO_address_free (address); 2371 GNUNET_HELLO_address_free (address);
2350 session->ats_address_network_type = plugin->env->get_address_type (plugin->env->cls, vaddr, alen); 2372 session->ats_address_network_type
2373 = plugin->env->get_address_type (plugin->env->cls,
2374 vaddr,
2375 alen);
2351 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); 2376 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
2352 ats.value = htonl (session->ats_address_network_type); 2377 ats.value = htonl (session->ats_address_network_type);
2353 LOG (GNUNET_ERROR_TYPE_DEBUG, 2378 LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -2418,13 +2443,15 @@ handle_tcp_data (void *cls,
2418 struct Session *session; 2443 struct Session *session;
2419 struct GNUNET_TIME_Relative delay; 2444 struct GNUNET_TIME_Relative delay;
2420 uint16_t type; 2445 uint16_t type;
2446 struct GNUNET_ATS_Information distance;
2421 2447
2422 type = ntohs (message->type); 2448 type = ntohs (message->type);
2423 if ((GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) 2449 if ( (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == type) ||
2424 || (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type)) 2450 (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE == type) )
2425 { 2451 {
2426 /* We don't want to propagate WELCOME and NAT Probe messages up! */ 2452 /* We don't want to propagate WELCOME and NAT Probe messages up! */
2427 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2453 GNUNET_SERVER_receive_done (client,
2454 GNUNET_OK);
2428 return; 2455 return;
2429 } 2456 }
2430 session = lookup_session_by_client (plugin, client); 2457 session = lookup_session_by_client (plugin, client);
@@ -2434,14 +2461,19 @@ handle_tcp_data (void *cls,
2434 void *vaddr; 2461 void *vaddr;
2435 size_t alen; 2462 size_t alen;
2436 2463
2437 GNUNET_SERVER_client_get_address (client, &vaddr, &alen); 2464 GNUNET_SERVER_client_get_address (client,
2438 LOG(GNUNET_ERROR_TYPE_ERROR, 2465 &vaddr,
2439 "Received unexpected %u bytes of type %u from `%s'\n", 2466 &alen);
2440 (unsigned int) ntohs (message->size), 2467 LOG (GNUNET_ERROR_TYPE_ERROR,
2441 (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen)); 2468 "Received unexpected %u bytes of type %u from `%s'\n",
2469 (unsigned int) ntohs (message->size),
2470 (unsigned int) ntohs (message->type),
2471 GNUNET_a2s (vaddr,
2472 alen));
2442 GNUNET_break_op(0); 2473 GNUNET_break_op(0);
2443 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2474 GNUNET_SERVER_receive_done (client,
2444 GNUNET_free_non_null(vaddr); 2475 GNUNET_SYSERR);
2476 GNUNET_free_non_null (vaddr);
2445 return; 2477 return;
2446 } 2478 }
2447 else if (GNUNET_YES == session->expecting_welcome) 2479 else if (GNUNET_YES == session->expecting_welcome)
@@ -2451,35 +2483,37 @@ handle_tcp_data (void *cls,
2451 size_t alen; 2483 size_t alen;
2452 2484
2453 GNUNET_SERVER_client_get_address (client, &vaddr, &alen); 2485 GNUNET_SERVER_client_get_address (client, &vaddr, &alen);
2454 LOG(GNUNET_ERROR_TYPE_ERROR, 2486 LOG (GNUNET_ERROR_TYPE_ERROR,
2455 "Received unexpected %u bytes of type %u from `%s'\n", 2487 "Received unexpected %u bytes of type %u from `%s'\n",
2456 (unsigned int) ntohs (message->size), 2488 (unsigned int) ntohs (message->size),
2457 (unsigned int) ntohs (message->type), GNUNET_a2s (vaddr, alen)); 2489 (unsigned int) ntohs (message->type),
2490 GNUNET_a2s (vaddr, alen));
2458 GNUNET_break_op(0); 2491 GNUNET_break_op(0);
2459 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2492 GNUNET_SERVER_receive_done (client,
2460 GNUNET_free_non_null(vaddr); 2493 GNUNET_SYSERR);
2494 GNUNET_free_non_null (vaddr);
2461 return; 2495 return;
2462 } 2496 }
2463 2497
2464 session->last_activity = GNUNET_TIME_absolute_get (); 2498 session->last_activity = GNUNET_TIME_absolute_get ();
2465 LOG(GNUNET_ERROR_TYPE_DEBUG, 2499 LOG (GNUNET_ERROR_TYPE_DEBUG,
2466 "Passing %u bytes of type %u from `%4s' to transport service.\n", 2500 "Passing %u bytes of type %u from `%4s' to transport service.\n",
2467 (unsigned int) ntohs (message->size), 2501 (unsigned int) ntohs (message->size),
2468 (unsigned int) ntohs (message->type), GNUNET_i2s (&session->target)); 2502 (unsigned int) ntohs (message->type),
2503 GNUNET_i2s (&session->target));
2469 2504
2470 GNUNET_STATISTICS_update (plugin->env->stats, 2505 GNUNET_STATISTICS_update (plugin->env->stats,
2471 gettext_noop ("# bytes received via TCP"), ntohs (message->size), 2506 gettext_noop ("# bytes received via TCP"),
2472 GNUNET_NO); 2507 ntohs (message->size),
2473 struct GNUNET_ATS_Information distance; 2508 GNUNET_NO);
2474 2509
2475 distance.type = htonl (GNUNET_ATS_NETWORK_TYPE); 2510 distance.type = htonl (GNUNET_ATS_NETWORK_TYPE);
2476 distance.value = htonl ((uint32_t) session->ats_address_network_type); 2511 distance.value = htonl ((uint32_t) session->ats_address_network_type);
2477 GNUNET_break(session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED); 2512 GNUNET_break (session->ats_address_network_type != GNUNET_ATS_NET_UNSPECIFIED);
2478
2479 GNUNET_assert(GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
2480 &session->target,
2481 session));
2482 2513
2514 GNUNET_assert (GNUNET_CONTAINER_multipeermap_contains_value (plugin->sessionmap,
2515 &session->target,
2516 session));
2483 delay = plugin->env->receive (plugin->env->cls, 2517 delay = plugin->env->receive (plugin->env->cls,
2484 session->address, 2518 session->address,
2485 session, 2519 session,
@@ -2722,9 +2756,11 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2722{ 2756{
2723 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = { 2757 static const struct GNUNET_SERVER_MessageHandler my_handlers[] = {
2724 { &handle_tcp_welcome, NULL, 2758 { &handle_tcp_welcome, NULL,
2725 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, sizeof(struct WelcomeMessage) }, 2759 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME,
2760 sizeof(struct WelcomeMessage) },
2726 { &handle_tcp_nat_probe, NULL, 2761 { &handle_tcp_nat_probe, NULL,
2727 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE, sizeof(struct TCP_NAT_ProbeMessage) }, 2762 GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_NAT_PROBE,
2763 sizeof(struct TCP_NAT_ProbeMessage) },
2728 { &handle_tcp_data, NULL, 2764 { &handle_tcp_data, NULL,
2729 GNUNET_MESSAGE_TYPE_ALL, 0 }, 2765 GNUNET_MESSAGE_TYPE_ALL, 0 },
2730 { NULL, NULL, 0, 0 } 2766 { NULL, NULL, 0, 0 }
@@ -2936,8 +2972,11 @@ libgnunet_plugin_transport_tcp_init (void *cls)
2936 for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++) 2972 for (i = 0;i < sizeof(my_handlers) / sizeof(struct GNUNET_SERVER_MessageHandler);i++)
2937 plugin->handlers[i].callback_cls = plugin; 2973 plugin->handlers[i].callback_cls = plugin;
2938 2974
2939 GNUNET_SERVER_add_handlers (plugin->server, plugin->handlers); 2975 GNUNET_SERVER_add_handlers (plugin->server,
2940 GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, plugin); 2976 plugin->handlers);
2977 GNUNET_SERVER_disconnect_notify (plugin->server,
2978 &disconnect_notify,
2979 plugin);
2941 plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16, 2980 plugin->nat_wait_conns = GNUNET_CONTAINER_multipeermap_create (16,
2942 GNUNET_YES); 2981 GNUNET_YES);
2943 if (0 != bport) 2982 if (0 != bport)
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 0a8c3cab4..f185c8738 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -2265,13 +2265,17 @@ process_udp_message (struct Plugin *plugin,
2265 udp_addr, 2265 udp_addr,
2266 udp_addr_len, 2266 udp_addr_len,
2267 GNUNET_HELLO_ADDRESS_INFO_NONE); 2267 GNUNET_HELLO_ADDRESS_INFO_NONE);
2268 if (NULL == (s = udp_plugin_lookup_session (plugin, address))) 2268 if (NULL ==
2269 (s = udp_plugin_lookup_session (plugin, address)))
2269 { 2270 {
2270 s = udp_plugin_create_session (plugin, 2271 s = udp_plugin_create_session (plugin,
2271 address, 2272 address,
2272 network_type); 2273 network_type);
2273 plugin->env->session_start (plugin->env->cls, 2274 plugin->env->session_start (plugin->env->cls,
2274 address, s, NULL, 0); 2275 address,
2276 s,
2277 NULL,
2278 0);
2275 notify_session_monitor (s->plugin, 2279 notify_session_monitor (s->plugin,
2276 s, 2280 s,
2277 GNUNET_TRANSPORT_SS_INIT); 2281 GNUNET_TRANSPORT_SS_INIT);
@@ -3566,9 +3570,13 @@ libgnunet_plugin_transport_udp_init (void *cls)
3566 p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); 3570 p->sessions = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
3567 p->defrag_ctxs = GNUNET_CONTAINER_heap_create ( 3571 p->defrag_ctxs = GNUNET_CONTAINER_heap_create (
3568 GNUNET_CONTAINER_HEAP_ORDER_MIN); 3572 GNUNET_CONTAINER_HEAP_ORDER_MIN);
3569 p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, p); 3573 p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages,
3570 GNUNET_BANDWIDTH_tracker_init (&p->tracker, NULL, NULL, 3574 p);
3571 GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps), 30); 3575 GNUNET_BANDWIDTH_tracker_init (&p->tracker,
3576 NULL,
3577 NULL,
3578 GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps),
3579 30);
3572 LOG(GNUNET_ERROR_TYPE_DEBUG, 3580 LOG(GNUNET_ERROR_TYPE_DEBUG,
3573 "Setting up sockets\n"); 3581 "Setting up sockets\n");
3574 res = setup_sockets (p, 3582 res = setup_sockets (p,