Commit 0b7f4b32 authored by Ulysse Beaugnon's avatar Ulysse Beaugnon

Upnp is now used when necessary

parent d297a650
......@@ -13,6 +13,7 @@ To be done :
Contact the server using vifibnet and not the underlying network when possible
Use a timeout for the peersDB
The peer DB size should depend on the number of connection and the refresh time
Specify a lease duration in ForwardViaUPnP
To be discuss:
U : Remove the --no-boot option since we know when no node is avalaible
......@@ -24,6 +25,4 @@ To be discuss:
U : From what I've read on the internet, when you create a server object, you don't connect to the server,
You only connect to the server once you send a request for a methode and then you can automatically use the same connection for 15sec
Is the bootstrap node used ?
We should separate the getNodesList and advertise options
\ No newline at end of file
Is the bootstrap node used ?
\ No newline at end of file
......@@ -10,7 +10,7 @@ def ForwardViaUPnP(localPort):
u.selectigd()
externalPort = 1194
while True:
while u.getspecificportmapping(externalPort, 'TCP') != None:
while u.getspecificportmapping(externalPort, 'UDP') != None:
externalPort = max(externalPort + 1, 49152)
if externalPort == 65536:
raise Exception
......@@ -18,18 +18,3 @@ def ForwardViaUPnP(localPort):
return (u.externalipaddress(), externalPort)
# TODO : specify a lease duration
# TODO : use more precises exceptions
# TODO : be sure that GetLocalIp do not bug
def GetLocalIp():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('10.8.8.8', 0))
return s.getsockname()[0]
def GetExternalInfo(localPort):
try:
return ForwardViaUPnP(localPort)
except Exception:
return (GetLocalIp(), localPort)
#!/usr/bin/env python
import argparse, errno, math, os, select, subprocess, sys, time, traceback
import argparse, errno, math, os, select, subprocess, sys, time, traceback, upnpigd
from OpenSSL import crypto
import db, plib, upnpigd, utils, tunnel
......@@ -12,7 +12,7 @@ def getConfig():
help='Address for peer discovery server')
_('--server-port', required=True, type=int,
help='Peer discovery server port')
_('-l', '--log', default='/var/log',
_('-log', '-l', default='/var/log',
help='Path to vifibnet logs directory')
_('--tunnel-refresh', default=300, type=int,
help='the time (seconds) to wait before changing the connections')
......@@ -65,6 +65,12 @@ def main():
read_pipe = os.fdopen(r_pipe)
# Init db and tunnels
if config.external_ip == None:
try:
config.external_ip, config.external_port = upnpigd.ForwardViaUPnP(config.internal_port)
except Exception:
utils.log('An atempt to forward a port via UPnP failed', 5)
peer_db = db.PeerManager(config.db, config.server, config.server_port, config.peers_db_refresh,
config.external_ip, internal_ip, config.external_port, config.proto, 200)
tunnel_manager = tunnel.TunnelManager(write_pipe, peer_db, openvpn_args, config.tunnel_refresh, config.connection_count, config.refresh_rate)
......
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