Commit 09a8ff1a authored by Julien Muchembled's avatar Julien Muchembled

re6stnet: resurrect --client-count and --max-clients

This replaces --connection-count, for more customization, but without requiring
more configuration from the user.
parent 4e883b88
......@@ -7,6 +7,6 @@ dh m1/dh2048.pem
ca ca.crt
cert m1/cert.crt
key m1/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://10.0.0.2:80
......@@ -7,6 +7,6 @@ dh m2/dh2048.pem
ca ca.crt
cert m2/cert.crt
key m2/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://10.0.0.2:80
......@@ -7,6 +7,6 @@ dh m3/dh2048.pem
ca ca.crt
cert m3/cert.crt
key m3/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://10.0.0.2:80
......@@ -7,6 +7,6 @@ dh m4/dh2048.pem
ca ca.crt
cert m4/cert.crt
key m4/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://10.0.0.2:80
......@@ -7,6 +7,6 @@ dh m5/dh2048.pem
ca ca.crt
cert m5/cert.crt
key m5/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://10.0.0.2:80
......@@ -7,6 +7,6 @@ dh m6/dh2048.pem
ca ca.crt
cert m6/cert.crt
key m6/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://10.0.0.2:80
......@@ -6,6 +6,6 @@ dh registry/dh2048.pem
ca ca.crt
cert registry/cert.crt
key registry/cert.key
connection-count 4
client-count 2
tunnel-refresh 100
registry http://localhost/
......@@ -30,7 +30,7 @@ class Connection:
class TunnelManager(object):
def __init__(self, write_pipe, peer_db, openvpn_args, hello_interval,
refresh, connection_count, iface_list, network, prefix,
refresh, client_count, iface_list, network, prefix,
address, ip_changed, encrypt):
self._write_pipe = write_pipe
self._peer_db = peer_db
......@@ -58,10 +58,10 @@ class TunnelManager(object):
self.next_refresh = time.time()
self._next_tunnel_refresh = time.time()
self._client_count = (connection_count + 1) // 2
self._client_count = client_count
self._refresh_count = 1
self.free_interface_set = set('re6stnet' + str(i)
for i in xrange(1, self._client_count + 1))
for i in xrange(1, client_count + 1))
def refresh(self):
logging.debug('Checking tunnels...')
......
......@@ -76,13 +76,16 @@ def getConfig():
" Common name defines the allocated prefix in the network.")
_('--key', required=True,
help="Local peer's private key in .pem format.")
_('--connection-count', default=20, type=int,
help="Maximum number of accepted clients per OpenVPN server."
" Also represents the average number of tunnels to peers.")
_('--client-count', default=10, type=int,
help="Number of client tunnels to set up.")
_('--max-clients', type=int,
help="Maximum number of accepted clients per OpenVPN server. (default:"
" client-count * 2, which actually represents the average number"
" of tunnels to other peers)")
_('--tunnel-refresh', default=300, type=int,
help="Interval in seconds between two tunnel refresh: the worst"
" tunnel is closed if the number of client tunnels has reached"
" its maximum number (half of connection-count).")
" its maximum number (client-count).")
_('openvpn_args', nargs=argparse.REMAINDER,
help="Use pseudo-argument '--' to forward positional arguments as extra"
......@@ -113,6 +116,9 @@ def main():
signal.signal(signal.SIGHUP, lambda *args: sys.exit(-1))
signal.signal(signal.SIGTERM, lambda *args: sys.exit())
if config.max_clients is None:
config.max_clients = config.client_count * 2
address = []
if config.pp:
pp = [(int(port), proto) for port, proto in config.pp]
......@@ -143,7 +149,7 @@ def main():
# Init db and tunnels
peer_db = db.PeerDB(db_path, config.registry, config.key, prefix)
tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, openvpn_args,
config.hello, config.tunnel_refresh, config.connection_count,
config.hello, config.tunnel_refresh, config.client_count,
config.iface_list, network, prefix, address, ip_changed,
config.encrypt)
......@@ -164,7 +170,7 @@ def main():
server_process.append(plib.server(iface,
utils.ipFromBin(subnet, '1') if proto == pp[0][1] else None,
len(network) + len(prefix),
config.connection_count, config.dh, write_pipe, port,
config.max_clients, config.dh, write_pipe, port,
proto, config.hello, config.encrypt, *openvpn_args))
while True:
next = tunnel_manager.next_refresh
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment