Commit 8fc115a5 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

The socket is only bind on the openvpn server ip

To bind it we have to wait 3sec after the 'ip addr add ...'
We have to uderstand why and solve this
parent f098a0c4
...@@ -17,7 +17,4 @@ To be done : ...@@ -17,7 +17,4 @@ To be done :
Put a section about how to build the package from the sources in the README Put a section about how to build the package from the sources in the README
http://pdos.csail.mit.edu/p2psim/kingdata/
http://www.eecs.harvard.edu/~syrah/nc/king/lats.n8.gz
http://www.cs.cornell.edu/People/egs/meridian/data.php
...@@ -23,8 +23,7 @@ class PeerManager: ...@@ -23,8 +23,7 @@ class PeerManager:
self.tunnel_manager = None self.tunnel_manager = None
self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM) self.sock = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
self.sock.bind(('::', 326)) self.socket_file = None
self.socket_file = self.sock.makefile()
logging.info('Connecting to peers database...') logging.info('Connecting to peers database...')
self._db = sqlite3.connect(db_path, isolation_level=None) self._db = sqlite3.connect(db_path, isolation_level=None)
...@@ -165,6 +164,14 @@ class PeerManager: ...@@ -165,6 +164,14 @@ class PeerManager:
except socket.error, e: except socket.error, e:
logging.debug('socket.error : %s' % e) logging.debug('socket.error : %s' % e)
logging.info("""Connection to server failed while declaring external infos""") logging.info("""Connection to server failed while declaring external infos""")
elif script_type == 'up':
if int(arg) != 0:
logging.info('Server creation failed, terminating')
raise RuntimeError
logging.debug('Creating the socket for peer advertising')
time.sleep(3) # TODO : We cannot bind without this. We have to understand why
self.sock.bind((self._internal_ip, 326))
self.socket_file = self.sock.makefile()
else: else:
logging.debug('Unknow message recieved from the openvpn pipe : %s' logging.debug('Unknow message recieved from the openvpn pipe : %s'
% msg) % msg)
......
...@@ -42,11 +42,13 @@ script_type = os.environ['script_type'] ...@@ -42,11 +42,13 @@ script_type = os.environ['script_type']
if script_type == 'up': if script_type == 'up':
from subprocess import call from subprocess import call
dev = os.environ['dev'] dev = os.environ['dev']
if sys.argv[1] != 'none': if sys.argv[2] != 'none':
sys.exit(call(('ip', 'link', 'set', dev, 'up')) out = (call(('ip', 'link', 'set', dev, 'up'))
or call(('ip', 'addr', 'add', sys.argv[1], 'dev', dev))) or call(('ip', 'addr', 'add', sys.argv[2], 'dev', dev)))
os.write(int(sys.argv[1]), 'up %s\n' % out)
else: else:
sys.exit(call(('ip', 'link', 'set', dev, 'up'))) out = call(('ip', 'link', 'set', dev, 'up'))
sys.exit(out)
if script_type == 'client-connect': if script_type == 'client-connect':
# Send client its external ip address # Send client its external ip address
......
...@@ -28,9 +28,9 @@ def openvpn(hello_interval, encrypt, *args, **kw): ...@@ -28,9 +28,9 @@ def openvpn(hello_interval, encrypt, *args, **kw):
def server(server_ip, ip_length, max_clients, dh_path, pipe_fd, port, proto, hello_interval, encrypt, *args, **kw): def server(server_ip, ip_length, max_clients, dh_path, pipe_fd, port, proto, hello_interval, encrypt, *args, **kw):
logging.debug('Starting server...') logging.debug('Starting server...')
if server_ip != '': if server_ip != '':
script_up = '%s %s/%u' % (ovpn_server, server_ip, 64) script_up = '%s %s %s/%u' % (ovpn_server, pipe_fd, server_ip, 64)
else: else:
script_up = '%s none' % (ovpn_server) script_up = '%s %s none' % (ovpn_server, pipe_fd)
return openvpn(hello_interval, encrypt, return openvpn(hello_interval, encrypt,
'--tls-server', '--tls-server',
'--mode', 'server', '--mode', 'server',
......
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