Commit 6b35d638 authored by Julien Muchembled's avatar Julien Muchembled

Select gateway in turns instead of randomly

This reduces the probability to lose all connections at the same time when a
gateway becomes out-of-order.
parent 65c1630f
#!/usr/bin/python #!/usr/bin/python
import atexit, errno, logging, os, random, select, signal import atexit, errno, logging, os, select, signal
import sqlite3, subprocess, sys, time, traceback import sqlite3, subprocess, sys, time, traceback
from collections import deque
from re6st import plib, utils, db, tunnel from re6st import plib, utils, db, tunnel
...@@ -99,7 +100,7 @@ def getConfig(): ...@@ -99,7 +100,7 @@ def getConfig():
" its maximum number (client-count).") " its maximum number (client-count).")
_('--remote-gateway', action='append', dest='gw_list', _('--remote-gateway', action='append', dest='gw_list',
help="Force each tunnel to be created through one the given gateways," help="Force each tunnel to be created through one the given gateways,"
" randomly.") " in a round-robin fashion.")
_('--client', metavar='HOST,PORT,PROTO[;...]', _('--client', metavar='HOST,PORT,PROTO[;...]',
help="Do not run any OpenVPN server, but only 1 OpenVPN client," help="Do not run any OpenVPN server, but only 1 OpenVPN client,"
" with specified remotes. Any other option not required in this" " with specified remotes. Any other option not required in this"
...@@ -150,8 +151,13 @@ def main(): ...@@ -150,8 +151,13 @@ def main():
else: else:
pp = (1194, 'udp'), (1194, 'tcp') pp = (1194, 'udp'), (1194, 'tcp')
ip_changed = lambda ip: [(ip, str(port), proto) for port, proto in pp] ip_changed = lambda ip: [(ip, str(port), proto) for port, proto in pp]
remote_gateway = config.gw_list and (lambda _: if config.gw_list:
random.choice(config.gw_list)) gw_list = deque(config.gw_list)
def remote_gateway(dest):
gw_list.rotate()
return gw_list[0]
else:
remote_gateway = None
forwarder = None forwarder = None
if len(config.ip) > 1 and 'upnp' in config.ip or 'any' in config.ip: if len(config.ip) > 1 and 'upnp' in config.ip or 'any' in config.ip:
sys.exit("error: argument --ip can be given only once with 'any'" sys.exit("error: argument --ip can be given only once with 'any'"
......
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