[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r15646 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r15646 - gnunet/src/transport |
Date: |
Thu, 16 Jun 2011 10:18:07 +0200 |
Author: grothoff
Date: 2011-06-16 10:18:06 +0200 (Thu, 16 Jun 2011)
New Revision: 15646
Modified:
gnunet/src/transport/plugin_transport_tcp.c
Log:
add connection limit to TCP
Modified: gnunet/src/transport/plugin_transport_tcp.c
===================================================================
--- gnunet/src/transport/plugin_transport_tcp.c 2011-06-16 08:09:46 UTC (rev
15645)
+++ gnunet/src/transport/plugin_transport_tcp.c 2011-06-16 08:18:06 UTC (rev
15646)
@@ -462,6 +462,11 @@
* Handle for (DYN)DNS lookup of our external IP.
*/
struct GNUNET_RESOLVER_RequestHandle *ext_dns;
+
+ /**
+ * How many more TCP sessions are we allowed to open right now?
+ */
+ unsigned long long max_connections;
/**
* ID of task used to update our addresses when one expires.
@@ -508,6 +513,33 @@
/**
+ * Function to check if an inbound connection is acceptable.
+ * Mostly used to limit the total number of open connections
+ * we can have.
+ *
+ * @param cls the 'struct Plugin'
+ * @param ucred credentials, if available, otherwise NULL
+ * @param addr address
+ * @param addrlen length of address
+ * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR
+ * for unknown address family (will be denied).
+ */
+static int
+plugin_tcp_access_check (void *cls,
+ const struct GNUNET_CONNECTION_Credentials *ucred,
+ const struct sockaddr *addr,
+ socklen_t addrlen)
+{
+ struct Plugin *plugin = cls;
+
+ if (0 == plugin->max_connections)
+ return GNUNET_NO;
+ plugin->max_connections--;
+ return GNUNET_YES;
+}
+
+
+/**
* Our external IP address/port mapping has changed.
*
* @param cls closure, the 'struct LocalAddrList'
@@ -1387,8 +1419,9 @@
if ((is_natd == GNUNET_YES) && (addrlen == sizeof (struct
IPv6TcpAddress)))
return -1; /* NAT client only works with IPv4 addresses */
+ if (0 == plugin->max_connections)
+ return -1; /* saturated */
-
if ( (plugin->enable_nat_client == GNUNET_YES) &&
(is_natd == GNUNET_YES) &&
(GNUNET_NO ==
GNUNET_CONTAINER_multihashmap_contains(plugin->nat_wait_conns,
@@ -1460,6 +1493,8 @@
GNUNET_NO);
return -1;
}
+ GNUNET_assert (0 != plugin->max_connections);
+ plugin->max_connections--;
#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"tcp",
@@ -2160,6 +2195,7 @@
if (client == NULL)
return;
+ plugin->max_connections++;
session = find_session_by_client (plugin, client);
if (session == NULL)
return; /* unknown, nothing to do */
@@ -2839,6 +2875,7 @@
struct GNUNET_SERVICE_Context *service;
unsigned long long aport;
unsigned long long bport;
+ unsigned long long max_connections;
unsigned int i;
int behind_nat;
int nat_punched;
@@ -2975,6 +3012,12 @@
"tcp","New internal address `%s'\n",
internal_address);
}
}
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_number (env->cfg,
+ "transport-tcp",
+ "MAX_CONNECTIONS",
+ &max_connections))
+ max_connections = 128;
aport = 0;
if ( (GNUNET_OK !=
@@ -3025,6 +3068,7 @@
service = NULL;
plugin = GNUNET_malloc (sizeof (struct Plugin));
+ plugin->max_connections = max_connections;
plugin->open_port = bport;
plugin->adv_port = aport;
plugin->bind_address = bind_address;
@@ -3068,7 +3112,7 @@
GNUNET_free (api);
return NULL;
}
- plugin->server = GNUNET_SERVER_create_with_sockets (NULL, NULL, NULL,
+ plugin->server = GNUNET_SERVER_create_with_sockets
(&plugin_tcp_access_check, plugin, NULL,
idle_timeout,
GNUNET_YES);
}
plugin->handlers = GNUNET_malloc (sizeof (my_handlers));
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r15646 - gnunet/src/transport,
gnunet <=