sender_address_len);
+/**
+ * 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
+ */
+typedef const struct GNUNET_ATS_Information
+(*GNUNET_TRANSPORT_AddressToType) (void *cls,
+ const struct sockaddr *addr,
+ size_t addrlen);
+
/**
* Function that will be called for each address the transport
* is aware that it might be reachable under.
*/
struct GNUNET_STATISTICS_Handle *stats;
- /**
- * ATS Handle to request address type.
- */
- struct GNUNET_ATS_SchedulingHandle *ats;
-
-
/**
* Function that should be called by the transport plugin
* whenever a message is received.
*/
GNUNET_TRANSPORT_SessionEnd session_end;
+ /**
+ * Function that will be called to figure if an address is an loopback,
+ * LAN, WAN etc. address
+ */
+ GNUNET_TRANSPORT_AddressToType get_address_type;
+
+
/**
* What is the maximum number of connections that this transport
* should allow? Transports that do not have sessions (such as
* to a string (numeric conversion only).
*/
GNUNET_TRANSPORT_AddressToString address_to_string;
-
};
}
+/**
+ * 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 ((addrlen != sizeof (struct sockaddr_in)) && (addrlen != sizeof (struct sockaddr_in6)))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed address with length %u `%s'\n",
+ addrlen,
+ GNUNET_a2s(addr, addrlen));
+ GNUNET_break (0);
+ return 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
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);
+ &plugin_env_session_end,
+ &plugin_env_address_to_type);
GST_neighbours_start (NULL, &neighbours_connect_notification,
&neighbours_disconnect_notification);
GST_clients_start (server);
* @param recv_cb function to call when data is received
* @param address_cb function to call when our public addresses changed
* @param session_end_cb function to call when a session was terminated
+ * @param address_type_cb function to call when a address type is requested
*/
void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
GNUNET_TRANSPORT_AddressNotification address_cb,
- GNUNET_TRANSPORT_SessionEnd session_end_cb)
+ GNUNET_TRANSPORT_SessionEnd session_end_cb,
+ GNUNET_TRANSPORT_AddressToType address_type_cb)
{
struct TransportPlugin *plug;
struct TransportPlugin *next;
plug->env.receive = recv_cb;
plug->env.notify_address = address_cb;
plug->env.session_end = session_end_cb;
+ plug->env.get_address_type = address_type_cb;
plug->env.max_connections = tneigh;
plug->env.stats = GST_stats;
- plug->env.ats = GST_ats;
GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug);
}
GNUNET_free (plugs);
* @param recv_cb function to call when data is received
* @param address_cb function to call when our public addresses changed
* @param session_end_cb function to call when a session was terminated
+ * @param address_type_cb function to call when a address type is requested
*/
void
GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb,
GNUNET_TRANSPORT_AddressNotification address_cb,
- GNUNET_TRANSPORT_SessionEnd session_end_cb);
-
+ GNUNET_TRANSPORT_SessionEnd session_end_cb,
+ GNUNET_TRANSPORT_AddressToType address_type_cb);
/**
* Unload all plugins
session->connect_addr = GNUNET_malloc (addrlen);
memcpy (session->connect_addr, addr, addrlen);
session->connect_alen = addrlen;
- if ((addrlen != 0) && (plugin->env->ats != NULL))
+ if (addrlen != 0)
{
struct GNUNET_ATS_Information ats;
- GNUNET_assert(plugin->env->ats != NULL);
- ats = GNUNET_ATS_address_get_type(plugin->env->ats, sb ,sbs);
+ ats = plugin->env->get_address_type (plugin->env->cls, sb ,sbs);
session->ats_address_network_type = ats.value;
}
else
session->connect_alen = sizeof (struct IPv6TcpAddress);
}
- if (plugin->env->ats != NULL)
- {
- struct GNUNET_ATS_Information ats;
- GNUNET_assert(plugin->env->ats != NULL);
- ats = GNUNET_ATS_address_get_type(plugin->env->ats, vaddr ,alen);
- session->ats_address_network_type = ats.value;
- }
- else
- GNUNET_break (0);
+ struct GNUNET_ATS_Information ats;
+ ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen);
+ session->ats_address_network_type = ats.value;
+
GNUNET_free (vaddr);
}
else