diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-12-14 08:53:29 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-12-14 08:53:29 +0000 |
commit | 2a46bac24eaca8ce16d12359e88f4a9d3cf49c28 (patch) | |
tree | 832a1ebc38fd60e512fa69688f94abda5019741b | |
parent | 47bd57c6a129474f51001cf02d15a04340d9b834 (diff) | |
download | gnunet-2a46bac24eaca8ce16d12359e88f4a9d3cf49c28.tar.gz gnunet-2a46bac24eaca8ce16d12359e88f4a9d3cf49c28.zip |
removing ats functions from plugins, instead provide callback function
-rw-r--r-- | src/include/gnunet_transport_plugin.h | 28 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport.c | 37 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.c | 6 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_plugins.h | 5 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 18 |
5 files changed, 70 insertions, 24 deletions
diff --git a/src/include/gnunet_transport_plugin.h b/src/include/gnunet_transport_plugin.h index 84f1b1f4a..705886d53 100644 --- a/src/include/gnunet_transport_plugin.h +++ b/src/include/gnunet_transport_plugin.h | |||
@@ -128,6 +128,20 @@ typedef struct | |||
128 | 128 | ||
129 | 129 | ||
130 | /** | 130 | /** |
131 | * Function that will be called to figure if an address is an loopback, | ||
132 | * LAN, WAN etc. address | ||
133 | * | ||
134 | * @param cls closure | ||
135 | * @param addr binary address | ||
136 | * @param addrlen length of the address | ||
137 | * @return ATS Information containing the network type | ||
138 | */ | ||
139 | typedef const struct GNUNET_ATS_Information | ||
140 | (*GNUNET_TRANSPORT_AddressToType) (void *cls, | ||
141 | const struct sockaddr *addr, | ||
142 | size_t addrlen); | ||
143 | |||
144 | /** | ||
131 | * Function that will be called for each address the transport | 145 | * Function that will be called for each address the transport |
132 | * is aware that it might be reachable under. | 146 | * is aware that it might be reachable under. |
133 | * | 147 | * |
@@ -203,12 +217,6 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
203 | struct GNUNET_STATISTICS_Handle *stats; | 217 | struct GNUNET_STATISTICS_Handle *stats; |
204 | 218 | ||
205 | /** | 219 | /** |
206 | * ATS Handle to request address type. | ||
207 | */ | ||
208 | struct GNUNET_ATS_SchedulingHandle *ats; | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Function that should be called by the transport plugin | 220 | * Function that should be called by the transport plugin |
213 | * whenever a message is received. | 221 | * whenever a message is received. |
214 | */ | 222 | */ |
@@ -234,6 +242,13 @@ struct GNUNET_TRANSPORT_PluginEnvironment | |||
234 | GNUNET_TRANSPORT_SessionEnd session_end; | 242 | GNUNET_TRANSPORT_SessionEnd session_end; |
235 | 243 | ||
236 | /** | 244 | /** |
245 | * Function that will be called to figure if an address is an loopback, | ||
246 | * LAN, WAN etc. address | ||
247 | */ | ||
248 | GNUNET_TRANSPORT_AddressToType get_address_type; | ||
249 | |||
250 | |||
251 | /** | ||
237 | * What is the maximum number of connections that this transport | 252 | * What is the maximum number of connections that this transport |
238 | * should allow? Transports that do not have sessions (such as | 253 | * should allow? Transports that do not have sessions (such as |
239 | * UDP) can ignore this value. | 254 | * UDP) can ignore this value. |
@@ -464,7 +479,6 @@ struct GNUNET_TRANSPORT_PluginFunctions | |||
464 | * to a string (numeric conversion only). | 479 | * to a string (numeric conversion only). |
465 | */ | 480 | */ |
466 | GNUNET_TRANSPORT_AddressToString address_to_string; | 481 | GNUNET_TRANSPORT_AddressToString address_to_string; |
467 | |||
468 | }; | 482 | }; |
469 | 483 | ||
470 | 484 | ||
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 644d27e24..8294f35dc 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -360,6 +360,40 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
360 | 360 | ||
361 | 361 | ||
362 | /** | 362 | /** |
363 | * Function that will be called to figure if an address is an loopback, | ||
364 | * LAN, WAN etc. address | ||
365 | * | ||
366 | * @param cls closure | ||
367 | * @param addr binary address | ||
368 | * @param addrlen length of the address | ||
369 | * @return ATS Information containing the network type | ||
370 | */ | ||
371 | static const struct GNUNET_ATS_Information | ||
372 | plugin_env_address_to_type (void *cls, | ||
373 | const struct sockaddr *addr, | ||
374 | size_t addrlen) | ||
375 | { | ||
376 | struct GNUNET_ATS_Information ats; | ||
377 | ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
378 | ats.value = htonl (GNUNET_ATS_NET_UNSPECIFIED); | ||
379 | if (GST_ats == NULL) | ||
380 | { | ||
381 | GNUNET_break (0); | ||
382 | return ats; | ||
383 | } | ||
384 | if ((addrlen != sizeof (struct sockaddr_in)) && (addrlen != sizeof (struct sockaddr_in6))) | ||
385 | { | ||
386 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Malformed address with length %u `%s'\n", | ||
387 | addrlen, | ||
388 | GNUNET_a2s(addr, addrlen)); | ||
389 | GNUNET_break (0); | ||
390 | return ats; | ||
391 | } | ||
392 | return GNUNET_ATS_address_get_type(GST_ats, addr, addrlen); | ||
393 | } | ||
394 | |||
395 | |||
396 | /** | ||
363 | * Function called by ATS to notify the callee that the | 397 | * Function called by ATS to notify the callee that the |
364 | * assigned bandwidth or address for a given peer was changed. If the | 398 | * assigned bandwidth or address for a given peer was changed. If the |
365 | * callback is called with address/bandwidth assignments of zero, the | 399 | * callback is called with address/bandwidth assignments of zero, the |
@@ -551,7 +585,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
551 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); | 585 | GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); |
552 | GST_plugins_load (&plugin_env_receive_callback, | 586 | GST_plugins_load (&plugin_env_receive_callback, |
553 | &plugin_env_address_change_notification, | 587 | &plugin_env_address_change_notification, |
554 | &plugin_env_session_end); | 588 | &plugin_env_session_end, |
589 | &plugin_env_address_to_type); | ||
555 | GST_neighbours_start (NULL, &neighbours_connect_notification, | 590 | GST_neighbours_start (NULL, &neighbours_connect_notification, |
556 | &neighbours_disconnect_notification); | 591 | &neighbours_disconnect_notification); |
557 | GST_clients_start (server); | 592 | GST_clients_start (server); |
diff --git a/src/transport/gnunet-service-transport_plugins.c b/src/transport/gnunet-service-transport_plugins.c index 61bbd22c2..fc14b6e76 100644 --- a/src/transport/gnunet-service-transport_plugins.c +++ b/src/transport/gnunet-service-transport_plugins.c | |||
@@ -88,11 +88,13 @@ static struct TransportPlugin *plugins_tail; | |||
88 | * @param recv_cb function to call when data is received | 88 | * @param recv_cb function to call when data is received |
89 | * @param address_cb function to call when our public addresses changed | 89 | * @param address_cb function to call when our public addresses changed |
90 | * @param session_end_cb function to call when a session was terminated | 90 | * @param session_end_cb function to call when a session was terminated |
91 | * @param address_type_cb function to call when a address type is requested | ||
91 | */ | 92 | */ |
92 | void | 93 | void |
93 | GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | 94 | GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, |
94 | GNUNET_TRANSPORT_AddressNotification address_cb, | 95 | GNUNET_TRANSPORT_AddressNotification address_cb, |
95 | GNUNET_TRANSPORT_SessionEnd session_end_cb) | 96 | GNUNET_TRANSPORT_SessionEnd session_end_cb, |
97 | GNUNET_TRANSPORT_AddressToType address_type_cb) | ||
96 | { | 98 | { |
97 | struct TransportPlugin *plug; | 99 | struct TransportPlugin *plug; |
98 | struct TransportPlugin *next; | 100 | struct TransportPlugin *next; |
@@ -130,9 +132,9 @@ GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | |||
130 | plug->env.receive = recv_cb; | 132 | plug->env.receive = recv_cb; |
131 | plug->env.notify_address = address_cb; | 133 | plug->env.notify_address = address_cb; |
132 | plug->env.session_end = session_end_cb; | 134 | plug->env.session_end = session_end_cb; |
135 | plug->env.get_address_type = address_type_cb; | ||
133 | plug->env.max_connections = tneigh; | 136 | plug->env.max_connections = tneigh; |
134 | plug->env.stats = GST_stats; | 137 | plug->env.stats = GST_stats; |
135 | plug->env.ats = GST_ats; | ||
136 | GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug); | 138 | GNUNET_CONTAINER_DLL_insert (plugins_head, plugins_tail, plug); |
137 | } | 139 | } |
138 | GNUNET_free (plugs); | 140 | GNUNET_free (plugs); |
diff --git a/src/transport/gnunet-service-transport_plugins.h b/src/transport/gnunet-service-transport_plugins.h index 3cca3ce10..04bb5ea22 100644 --- a/src/transport/gnunet-service-transport_plugins.h +++ b/src/transport/gnunet-service-transport_plugins.h | |||
@@ -42,12 +42,13 @@ | |||
42 | * @param recv_cb function to call when data is received | 42 | * @param recv_cb function to call when data is received |
43 | * @param address_cb function to call when our public addresses changed | 43 | * @param address_cb function to call when our public addresses changed |
44 | * @param session_end_cb function to call when a session was terminated | 44 | * @param session_end_cb function to call when a session was terminated |
45 | * @param address_type_cb function to call when a address type is requested | ||
45 | */ | 46 | */ |
46 | void | 47 | void |
47 | GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, | 48 | GST_plugins_load (GNUNET_TRANSPORT_PluginReceiveCallback recv_cb, |
48 | GNUNET_TRANSPORT_AddressNotification address_cb, | 49 | GNUNET_TRANSPORT_AddressNotification address_cb, |
49 | GNUNET_TRANSPORT_SessionEnd session_end_cb); | 50 | GNUNET_TRANSPORT_SessionEnd session_end_cb, |
50 | 51 | GNUNET_TRANSPORT_AddressToType address_type_cb); | |
51 | 52 | ||
52 | /** | 53 | /** |
53 | * Unload all plugins | 54 | * Unload all plugins |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index bfe1dc805..dfd4ccee0 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1126,11 +1126,10 @@ tcp_plugin_send (void *cls, const struct GNUNET_PeerIdentity *target, | |||
1126 | session->connect_addr = GNUNET_malloc (addrlen); | 1126 | session->connect_addr = GNUNET_malloc (addrlen); |
1127 | memcpy (session->connect_addr, addr, addrlen); | 1127 | memcpy (session->connect_addr, addr, addrlen); |
1128 | session->connect_alen = addrlen; | 1128 | session->connect_alen = addrlen; |
1129 | if ((addrlen != 0) && (plugin->env->ats != NULL)) | 1129 | if (addrlen != 0) |
1130 | { | 1130 | { |
1131 | struct GNUNET_ATS_Information ats; | 1131 | struct GNUNET_ATS_Information ats; |
1132 | GNUNET_assert(plugin->env->ats != NULL); | 1132 | ats = plugin->env->get_address_type (plugin->env->cls, sb ,sbs); |
1133 | ats = GNUNET_ATS_address_get_type(plugin->env->ats, sb ,sbs); | ||
1134 | session->ats_address_network_type = ats.value; | 1133 | session->ats_address_network_type = ats.value; |
1135 | } | 1134 | } |
1136 | else | 1135 | else |
@@ -1638,15 +1637,10 @@ handle_tcp_welcome (void *cls, struct GNUNET_SERVER_Client *client, | |||
1638 | session->connect_alen = sizeof (struct IPv6TcpAddress); | 1637 | session->connect_alen = sizeof (struct IPv6TcpAddress); |
1639 | } | 1638 | } |
1640 | 1639 | ||
1641 | if (plugin->env->ats != NULL) | 1640 | struct GNUNET_ATS_Information ats; |
1642 | { | 1641 | ats = plugin->env->get_address_type (plugin->env->cls, vaddr ,alen); |
1643 | struct GNUNET_ATS_Information ats; | 1642 | session->ats_address_network_type = ats.value; |
1644 | GNUNET_assert(plugin->env->ats != NULL); | 1643 | |
1645 | ats = GNUNET_ATS_address_get_type(plugin->env->ats, vaddr ,alen); | ||
1646 | session->ats_address_network_type = ats.value; | ||
1647 | } | ||
1648 | else | ||
1649 | GNUNET_break (0); | ||
1650 | GNUNET_free (vaddr); | 1644 | GNUNET_free (vaddr); |
1651 | } | 1645 | } |
1652 | else | 1646 | else |