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;
* 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
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;
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;
* (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,
#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)
- : "<inbound>");
+ (sender_address !=
+ NULL) ? GST_plugins_a2s (&address) : "<inbound>");
#endif
GST_validation_handle_ping (peer, message, &address, session);
break;
#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)
- : "<inbound>");
+ (sender_address !=
+ NULL) ? GST_plugins_a2s (&address) : "<inbound>");
#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);
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));
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);
}
* @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,
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);
}
}
+/**
+ * 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.
/* 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 ();
}