*/
struct GNUNET_ATS_SchedulingHandle *GST_ats;
+/**
+ * DEBUGGING connection counter
+ */
+static int connections;
+
/**
* Transmit our HELLO message to the given (connected) neighbour.
* @param peer (claimed) identity of the other peer
* @param address the address
* @param session session used
- * @param msg the message to process
+ * @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
session, GNUNET_i2s (peer));
#endif
if (NULL != session)
- GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
"transport-ats",
"Telling ATS to destroy session %p from peer %s\n",
session, GNUNET_i2s (peer));
}
+/**
+ * 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);
+}
+
+
/**
* Function called by ATS to notify the callee that the
* assigned bandwidth or address for a given peer was changed. If the
* @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 number of ATS elements
+ * @param ats_count number of ATS elements
*/
static void
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);
}
struct ConnectInfoMessage *connect_msg = (struct ConnectInfoMessage *) buf;
struct GNUNET_ATS_Information *ap;
+ connections++;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "We are now connected to peer `%s' and %u peers in total\n",
+ GNUNET_i2s (peer), connections);
+
connect_msg->header.size = htons (sizeof (buf));
connect_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT);
connect_msg->ats_count = htonl (ats_count);
{
struct DisconnectInfoMessage disconnect_msg;
+ connections--;
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+ "Peer `%s' disconnected and we are connected to %u peers\n",
+ GNUNET_i2s (peer), connections);
+
disconnect_msg.header.size = htons (sizeof (struct DisconnectInfoMessage));
disconnect_msg.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT);
disconnect_msg.reserved = htonl (0);
}
+/**
+ * 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.
GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
GST_plugins_load (&plugin_env_receive_callback,
&plugin_env_address_change_notification,
- &plugin_env_session_end);
- GST_neighbours_start (NULL, &neighbours_connect_notification,
- &neighbours_disconnect_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 ();
}