X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Ftransport%2Fgnunet-service-transport.c;h=cd9bb5c65e2018cd2f21c8d7badba5ff8ba69fae;hb=107a20218f88dcd4f41869c233d89835fb9c1ac5;hp=7fd4760ef6511336f5256cdf8a7b38db845daa4d;hpb=91c4da14bcfa26a9a077d07fb9063d4460ae095e;p=oweals%2Fgnunet.git diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 7fd4760ef..cd9bb5c65 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -90,7 +90,7 @@ static void transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, - const struct GNUNET_HELLO_Address *address) + const struct GNUNET_HELLO_Address *address) { const struct GNUNET_MessageHeader *hello = cls; @@ -118,7 +118,9 @@ process_hello_update (void *cls, const struct GNUNET_MessageHeader *hello) * We received some payload. Prepare to pass it on to our clients. * * @param peer (claimed) identity of the other peer - * @param message the message, never NULL + * @param address the address + * @param session session used + * @param message the message to process * @param ats performance information * @param ats_count number of records in ats * @return how long the plugin should wait until receiving more data @@ -136,7 +138,7 @@ process_payload (const struct GNUNET_PeerIdentity *peer, size_t msg_size = ntohs (message->size); size_t size = sizeof (struct InboundMessage) + msg_size + - sizeof (struct GNUNET_ATS_Information) * (ats_count + 1); + sizeof (struct GNUNET_ATS_Information) * (ats_count + 1); char buf[size]; struct GNUNET_ATS_Information *ap; @@ -168,10 +170,11 @@ process_payload (const struct GNUNET_PeerIdentity *peer, ap = (struct GNUNET_ATS_Information *) &im[1]; memcpy (ap, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); ap[ats_count].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); - ap[ats_count].value = htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value); + ap[ats_count].value = + htonl ((uint32_t) GST_neighbour_get_latency (peer).rel_value); memcpy (&ap[ats_count + 1], message, ntohs (message->size)); - GNUNET_ATS_address_update (GST_ats, address, session, ap, ats_count +1 ); + GNUNET_ATS_address_update (GST_ats, address, session, ap, ats_count + 1); GST_clients_broadcast (&im->header, GNUNET_YES); return ret; @@ -202,8 +205,7 @@ process_payload (const struct GNUNET_PeerIdentity *peer, * (plugins that do not support this, can ignore the return value) */ static struct GNUNET_TIME_Relative -plugin_env_receive_callback (void *cls, - const struct GNUNET_PeerIdentity *peer, +plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *message, const struct GNUNET_ATS_Information *ats, uint32_t ats_count, struct Session *session, @@ -237,8 +239,8 @@ plugin_env_receive_callback (void *cls, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Processing `%s' from `%s'\n", "PING", - (sender_address != NULL) ? GST_plugins_a2s (&address) - : ""); + (sender_address != + NULL) ? GST_plugins_a2s (&address) : ""); #endif GST_validation_handle_ping (peer, message, &address, session); break; @@ -246,20 +248,22 @@ plugin_env_receive_callback (void *cls, #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, "Processing `%s' from `%s'\n", "PONG", - (sender_address != NULL) ? GST_plugins_a2s (&address) - : ""); + (sender_address != + NULL) ? GST_plugins_a2s (&address) : ""); #endif GST_validation_handle_pong (peer, message); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: - GST_neighbours_handle_connect (message, peer, &address, session, ats, ats_count); + GST_neighbours_handle_connect (message, peer, &address, session, ats, + ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: - GST_neighbours_handle_connect_ack (message, peer, &address, - session, ats, ats_count); + GST_neighbours_handle_connect_ack (message, peer, &address, session, ats, + ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: - GST_neighbours_handle_ack (message, peer, &address, session, ats, ats_count); + GST_neighbours_handle_ack (message, peer, &address, session, ats, + ats_count); break; case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: GST_neighbours_handle_disconnect_message (peer, message); @@ -333,8 +337,10 @@ static void plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, struct Session *session) { + const char *transport_name = cls; struct GNUNET_HELLO_Address address; + GNUNET_assert (strlen (transport_name) > 0); #if DEBUG_TRANSPORT GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", session, GNUNET_i2s (peer)); @@ -347,9 +353,45 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, address.peer = *peer; address.address = NULL; address.address_length = 0; - address.transport_name = cls; - GNUNET_ATS_address_destroyed (GST_ats, &address, session); + address.transport_name = transport_name; GST_neighbours_session_terminated (peer, session); + GNUNET_ATS_address_destroyed (GST_ats, &address, session); +} + + +/** + * Function that will be called to figure if an address is an loopback, + * LAN, WAN etc. address + * + * @param cls closure + * @param addr binary address + * @param addrlen length of the address + * @return ATS Information containing the network type + */ +static const struct GNUNET_ATS_Information +plugin_env_address_to_type (void *cls, + const struct sockaddr *addr, + size_t addrlen) +{ + struct GNUNET_ATS_Information ats; + ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); + ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); + if (GST_ats == NULL) + { + GNUNET_break (0); + return ats; + } + if (((addr->sa_family != AF_INET) && (addrlen != sizeof (struct sockaddr_in))) && + ((addr->sa_family != AF_INET6) && (addrlen != sizeof (struct sockaddr_in6))) && + (addr->sa_family != AF_UNIX)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed address with length %u `%s'\n", + addrlen, + GNUNET_a2s(addr, addrlen)); + GNUNET_break (0); + return (const struct GNUNET_ATS_Information) ats; + } + return GNUNET_ATS_address_get_type(GST_ats, addr, addrlen); } @@ -365,10 +407,12 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, * @param session session to use (if available) * @param bandwidth_out assigned outbound bandwidth for the connection, 0 to disconnect from peer * @param bandwidth_in assigned inbound bandwidth for the connection, 0 to disconnect from peer + * @param ats ATS information + * @param ats_count number of ATS elements */ static void -ats_request_address_change (void *cls, - const struct GNUNET_HELLO_Address *address, +ats_request_address_change (void *cls, + const struct GNUNET_HELLO_Address *address, struct Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, @@ -390,8 +434,7 @@ ats_request_address_change (void *cls, return; } /* will never return GNUNET_YES since connection is to be established */ - GST_neighbours_switch_to_address_3way (&address->peer, - address, session, ats, + GST_neighbours_switch_to_address (&address->peer, address, session, ats, ats_count, bandwidth_in, bandwidth_out); } @@ -450,6 +493,23 @@ neighbours_disconnect_notification (void *cls, } +/** + * Function called to notify transport users that a neighbour peer changed its + * active address. + * + * @param cls closure + * @param peer peer this update is about (never NULL) + * @param address address, NULL on disconnect + */ +static void +neighbours_address_notification (void *cls, + const struct GNUNET_PeerIdentity *peer, + const struct GNUNET_HELLO_Address *address) +{ + GST_clients_broadcast_address_notification (peer, address); +} + + /** * Function called when the service shuts down. Unloads our plugins * and cancels pending validations. @@ -540,13 +600,16 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, /* start subsystems */ GST_hello_start (&process_hello_update, NULL); GST_blacklist_start (server); - GST_plugins_load (&plugin_env_receive_callback, - &plugin_env_address_change_notification, - &plugin_env_session_end); GST_ats = GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); - GST_neighbours_start (NULL, &neighbours_connect_notification, - &neighbours_disconnect_notification); + GST_plugins_load (&plugin_env_receive_callback, + &plugin_env_address_change_notification, + &plugin_env_session_end, + &plugin_env_address_to_type); + GST_neighbours_start (NULL, + &neighbours_connect_notification, + &neighbours_disconnect_notification, + &neighbours_address_notification); GST_clients_start (server); GST_validation_start (); }