You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* @file transport/plugin_transport_tcp.c
* Optional options and flags for this address,
* see `enum TcpAddressOptions`
*/
- uint32_t options;
+ uint32_t options GNUNET_PACKED;
/**
* IPv4 address, in network byte order.
* Optional flags for this address
* see `enum TcpAddressOptions`
*/
- uint32_t options;
+ uint32_t options GNUNET_PACKED;
/**
* IPv6 address.
struct Plugin *plugin = ppc->plugin;
char *ret;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "append_port called with hostname `%s'\n",
+ hostname);
if (NULL == hostname)
{
/* Final call, done */
else
{
/* invalid address */
+ LOG (GNUNET_ERROR_TYPE_WARNING,
+ _("Unexpected address length: %u bytes\n"),
+ (unsigned int) addrlen);
asc (asc_cls, NULL, GNUNET_SYSERR);
asc (asc_cls, NULL, GNUNET_OK);
return;
ppc->asc_cls = asc_cls;
ppc->port = port;
ppc->options = options;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Starting DNS reverse lookup\n");
ppc->resolver_handle = GNUNET_RESOLVER_hostname_get (sb,
sbs,
! numeric,
if (ntohs (message->size) != sizeof(struct TCP_NAT_ProbeMessage))
{
GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
sizeof(struct GNUNET_PeerIdentity)))
{
/* refuse connections from ourselves */
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
{
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Did NOT find session for NAT probe!\n");
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Bad address for incoming connection!\n");
GNUNET_free(vaddr);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
tcp_plugin_disconnect_session (plugin,
session);
return;
{
GNUNET_break (0);
GNUNET_free_non_null (vaddr);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
session = create_session (plugin,
LOG(GNUNET_ERROR_TYPE_DEBUG,
"Did not obtain TCP socket address for incoming connection\n");
GNUNET_break(0);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
return;
}
}
if (session->expecting_welcome != GNUNET_YES)
{
GNUNET_break_op(0);
- GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_SYSERR);
GNUNET_break(0);
return;
}
process_pending_messages (session);
GNUNET_SERVER_client_set_timeout (client,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
}
reschedule_session_timeout (session);
if (0 == delay.rel_value_us)
{
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
}
else
{
- LOG(GNUNET_ERROR_TYPE_DEBUG,
- "Throttling receiving from `%s' for %s\n",
- GNUNET_i2s (&session->target),
- GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Throttling receiving from `%s' for %s\n",
+ GNUNET_i2s (&session->target),
+ GNUNET_STRINGS_relative_time_to_string (delay,
+ GNUNET_YES));
GNUNET_SERVER_disable_receive_done_warning (client);
+ GNUNET_assert (NULL == session->receive_delay_task);
session->receive_delay_task = GNUNET_SCHEDULER_add_delayed (delay,
- &delayed_done, session);
+ &delayed_done,
+ session);
}
}
{
struct Plugin *plugin = cls;
+ if (NULL == client)
+ return;
plugin->cur_connections++;
+ GNUNET_STATISTICS_set (plugin->env->stats,
+ gettext_noop ("# TCP server connections active"),
+ plugin->cur_connections,
+ GNUNET_NO);
+ GNUNET_STATISTICS_update (plugin->env->stats,
+ gettext_noop ("# TCP server connect events"),
+ 1,
+ GNUNET_NO);
if (plugin->cur_connections != plugin->max_connections)
return;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
if (NULL == client)
return;
- session = lookup_session_by_client (plugin, client);
+ GNUNET_assert (plugin->cur_connections >= 1);
+ plugin->cur_connections--;
+ session = lookup_session_by_client (plugin,
+ client);
if (NULL == session)
return; /* unknown, nothing to do */
LOG (GNUNET_ERROR_TYPE_DEBUG,
GNUNET_NO);
GNUNET_SERVER_resume (plugin->server); /* Resume server */
}
- GNUNET_assert (plugin->cur_connections >= 1);
- plugin->cur_connections--;
+ GNUNET_STATISTICS_set (plugin->env->stats,
+ gettext_noop ("# TCP server connections active"),
+ plugin->cur_connections,
+ GNUNET_NO);
GNUNET_STATISTICS_update (session->plugin->env->stats,
gettext_noop ("# network-level TCP disconnect events"),
1,
}
+/**
+ * Function obtain the network type for an address.
+ *
+ * @param cls closure (`struct Plugin *`)
+ * @param address the address
+ * @return the network type
+ */
+static enum GNUNET_ATS_Network_Type
+tcp_plugin_get_network_for_address (void *cls,
+ const struct GNUNET_HELLO_Address *address)
+{
+ struct Plugin *plugin = cls;
+ size_t addrlen;
+ struct sockaddr_in a4;
+ struct sockaddr_in6 a6;
+ const struct IPv4TcpAddress *t4;
+ const struct IPv6TcpAddress *t6;
+ const void *sb;
+ size_t sbs;
+
+ addrlen = address->address_length;
+ if (addrlen == sizeof(struct IPv6TcpAddress))
+ {
+ GNUNET_assert (NULL != address->address); /* make static analysis happy */
+ t6 = address->address;
+ memset (&a6, 0, sizeof(a6));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ a6.sin6_len = sizeof (a6);
+#endif
+ a6.sin6_family = AF_INET6;
+ a6.sin6_port = t6->t6_port;
+ memcpy (&a6.sin6_addr, &t6->ipv6_addr, sizeof(struct in6_addr));
+ sb = &a6;
+ sbs = sizeof(a6);
+ }
+ else if (addrlen == sizeof(struct IPv4TcpAddress))
+ {
+ GNUNET_assert (NULL != address->address); /* make static analysis happy */
+ t4 = address->address;
+ memset (&a4, 0, sizeof(a4));
+#if HAVE_SOCKADDR_IN_SIN_LEN
+ a4.sin_len = sizeof (a4);
+#endif
+ a4.sin_family = AF_INET;
+ a4.sin_port = t4->t4_port;
+ a4.sin_addr.s_addr = t4->ipv4_addr;
+ sb = &a4;
+ sbs = sizeof(a4);
+ }
+ else
+ {
+ GNUNET_break (0);
+ return GNUNET_ATS_NET_UNSPECIFIED;
+ }
+ return plugin->env->get_address_type (plugin->env->cls,
+ sb,
+ sbs);
+}
+
+
/**
* Return information about the given session to the
* monitor callback.
(const struct sockaddr **) addrs, addrlens,
&tcp_nat_port_map_callback,
&try_connection_reversal,
- plugin);
+ plugin, NULL);
for (ret = ret_s -1; ret >= 0; ret--)
GNUNET_free (addrs[ret]);
GNUNET_free_non_null (addrs);
NULL,
NULL,
&try_connection_reversal,
- plugin);
+ plugin,
+ NULL);
}
api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions);
api->cls = plugin;
api->address_to_string = &tcp_plugin_address_to_string;
api->string_to_address = &tcp_plugin_string_to_address;
api->get_network = &tcp_plugin_get_network;
+ api->get_network_for_address = &tcp_plugin_get_network_for_address;
api->update_session_timeout = &tcp_plugin_update_session_timeout;
api->update_inbound_delay = &tcp_plugin_update_inbound_delay;
api->setup_monitor = &tcp_plugin_setup_monitor;
GNUNET_SERVICE_stop (plugin->service);
else
GNUNET_SERVER_destroy (plugin->server);
- GNUNET_free(plugin->handlers);
+ GNUNET_free (plugin->handlers);
if (NULL != plugin->nat)
GNUNET_NAT_unregister (plugin->nat);
while (NULL != (tcp_probe = plugin->probe_head))
plugin->probe_tail,
tcp_probe);
GNUNET_CONNECTION_destroy (tcp_probe->sock);
- GNUNET_free(tcp_probe);
+ GNUNET_free (tcp_probe);
}
GNUNET_CONTAINER_multipeermap_destroy (plugin->nat_wait_conns);
GNUNET_CONTAINER_multipeermap_destroy (plugin->sessionmap);
- GNUNET_free(plugin);
- GNUNET_free(api);
+ GNUNET_break (0 == plugin->cur_connections);
+ GNUNET_free (plugin);
+ GNUNET_free (api);
return NULL;
}