Commit 4536d8eb authored by Julien Muchembled's avatar Julien Muchembled

Reread routing table when a established tunnel breaks

The main reason is to speed up recovery from temporary network cut:
- by not wasting time trying remaining distant peers that were collected during
  the last read of the routing table.
- by not blacklisting good peers, which would happen if too many of them were
  retried before network is back
parent 4ea3e7be
...@@ -95,12 +95,14 @@ class Connection(object): ...@@ -95,12 +95,14 @@ class Connection(object):
logging.info('Connection with %s/%s has failed with return code %s', logging.info('Connection with %s/%s has failed with return code %s',
int(self._prefix, 2), len(self._prefix), int(self._prefix, 2), len(self._prefix),
self.process.returncode) self.process.returncode)
if self._retry is None or len(self.address_list) <= self._retry: if self._retry is None:
return False return 1
if len(self.address_list) <= self._retry:
return -1
logging.info('Retrying with alternate address') logging.info('Retrying with alternate address')
self.close() self.close()
self.open() self.open()
return True return 0
class TunnelKiller(object): class TunnelKiller(object):
...@@ -251,8 +253,8 @@ class TunnelManager(object): ...@@ -251,8 +253,8 @@ class TunnelManager(object):
def refresh(self): def refresh(self):
logging.debug('Checking tunnels...') logging.debug('Checking tunnels...')
self._cleanDeads() if self._cleanDeads() or \
if self._next_tunnel_refresh < time.time() or \ self._next_tunnel_refresh < time.time() or \
self._killing or \ self._killing or \
self._makeNewTunnels(False): self._makeNewTunnels(False):
self._next_refresh = None self._next_refresh = None
...@@ -290,9 +292,13 @@ class TunnelManager(object): ...@@ -290,9 +292,13 @@ class TunnelManager(object):
self._next_refresh = time.time() + 5 self._next_refresh = time.time() + 5
def _cleanDeads(self): def _cleanDeads(self):
disconnected = False
for prefix in self._connection_dict.keys(): for prefix in self._connection_dict.keys():
if not self._connection_dict[prefix].refresh(): status = self._connection_dict[prefix].refresh()
if status:
disconnected |= status > 0
self._kill(prefix) self._kill(prefix)
return disconnected
def _tunnelScore(self, prefix): def _tunnelScore(self, prefix):
n = 0 n = 0
......
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