aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-07 14:15:38 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-07 14:15:38 +0000
commite5bd8fb4aa72717b8707a4652f14c0735acb52c4 (patch)
tree08398e22b9408cc24b6b9e6cb360fe04b9eeae05 /src/transport/plugin_transport_udp.c
parent572bab1ace57fb9d7acbd218d6940cb1e9a0797b (diff)
downloadgnunet-e5bd8fb4aa72717b8707a4652f14c0735acb52c4.tar.gz
gnunet-e5bd8fb4aa72717b8707a4652f14c0735acb52c4.zip
determine network scope for ATS even if we do not yet have a session and only have an address
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c67
1 files changed, 64 insertions, 3 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index 7c36e172c..ca5166600 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -614,13 +614,73 @@ udp_query_keepalive_factor (void *cls)
614 * @return the network type 614 * @return the network type
615 */ 615 */
616static enum GNUNET_ATS_Network_Type 616static enum GNUNET_ATS_Network_Type
617udp_get_network (void *cls, 617udp_plugin_get_network (void *cls,
618 struct Session *session) 618 struct Session *session)
619{ 619{
620 return session->scope; 620 return session->scope;
621} 621}
622 622
623 623
624/**
625 * Function obtain the network type for an address.
626 *
627 * @param cls closure (`struct Plugin *`)
628 * @param address the address
629 * @return the network type
630 */
631static enum GNUNET_ATS_Network_Type
632udp_plugin_get_network_for_address (void *cls,
633 const struct GNUNET_HELLO_Address *address)
634{
635 struct Plugin *plugin = cls;
636 size_t addrlen;
637 struct sockaddr_in a4;
638 struct sockaddr_in6 a6;
639 const struct IPv4UdpAddress *u4;
640 const struct IPv6UdpAddress *u6;
641 const void *sb;
642 size_t sbs;
643
644 addrlen = address->address_length;
645 if (addrlen == sizeof(struct IPv6UdpAddress))
646 {
647 GNUNET_assert (NULL != address->address); /* make static analysis happy */
648 u6 = address->address;
649 memset (&a6, 0, sizeof(a6));
650#if HAVE_SOCKADDR_IN_SIN_LEN
651 a6.sin6_len = sizeof (a6);
652#endif
653 a6.sin6_family = AF_INET6;
654 a6.sin6_port = u6->u6_port;
655 memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
656 sb = &a6;
657 sbs = sizeof(a6);
658 }
659 else if (addrlen == sizeof(struct IPv4UdpAddress))
660 {
661 GNUNET_assert (NULL != address->address); /* make static analysis happy */
662 u4 = address->address;
663 memset (&a4, 0, sizeof(a4));
664#if HAVE_SOCKADDR_IN_SIN_LEN
665 a4.sin_len = sizeof (a4);
666#endif
667 a4.sin_family = AF_INET;
668 a4.sin_port = u4->u4_port;
669 a4.sin_addr.s_addr = u4->ipv4_addr;
670 sb = &a4;
671 sbs = sizeof(a4);
672 }
673 else
674 {
675 GNUNET_break (0);
676 return GNUNET_ATS_NET_UNSPECIFIED;
677 }
678 return plugin->env->get_address_type (plugin->env->cls,
679 sb,
680 sbs);
681}
682
683
624/* ******************* Event loop ******************** */ 684/* ******************* Event loop ******************** */
625 685
626/** 686/**
@@ -3766,7 +3826,8 @@ libgnunet_plugin_transport_udp_init (void *cls)
3766 api->check_address = &udp_plugin_check_address; 3826 api->check_address = &udp_plugin_check_address;
3767 api->get_session = &udp_plugin_get_session; 3827 api->get_session = &udp_plugin_get_session;
3768 api->send = &udp_plugin_send; 3828 api->send = &udp_plugin_send;
3769 api->get_network = &udp_get_network; 3829 api->get_network = &udp_plugin_get_network;
3830 api->get_network_for_address = &udp_plugin_get_network_for_address;
3770 api->update_session_timeout = &udp_plugin_update_session_timeout; 3831 api->update_session_timeout = &udp_plugin_update_session_timeout;
3771 api->setup_monitor = &udp_plugin_setup_monitor; 3832 api->setup_monitor = &udp_plugin_setup_monitor;
3772 return api; 3833 return api;