Commit 1b272c71 authored by Julien Muchembled's avatar Julien Muchembled

More sanity check

parent c231062f
...@@ -84,15 +84,20 @@ class PeerDB(object): ...@@ -84,15 +84,20 @@ class PeerDB(object):
logging.info('Getting Boot peer...') logging.info('Getting Boot peer...')
try: try:
bootpeer = self._proxy.getBootstrapPeer(self._prefix).data bootpeer = self._proxy.getBootstrapPeer(self._prefix).data
except (socket.error, xmlrpclib.Fault), e: p = subprocess.Popen(
('openssl', 'rsautl', '-decrypt', '-inkey', self._key_path),
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out, err = p.communicate(bootpeer)
if p.returncode:
raise subprocess.CalledProcessError(p.returncode, err)
prefix, address = out.split()
except (socket.error, xmlrpclib.Fault, subprocess.CalledProcessError,
ValueError), e:
logging.warning('Failed to bootstrap (%s)', e) logging.warning('Failed to bootstrap (%s)', e)
else: else:
p = subprocess.Popen(('openssl', 'rsautl', '-decrypt', '-inkey', self._key_path), if prefix != self._prefix:
stdin=subprocess.PIPE, stdout=subprocess.PIPE) self.addPeer(prefix, address)
bootpeer = p.communicate(bootpeer)[0].split() return prefix, address
if bootpeer[0] != self._prefix:
self.addPeer(*bootpeer)
return bootpeer
logging.warning('Buggy registry sent us our own address') logging.warning('Buggy registry sent us our own address')
def addPeer(self, prefix, address, set_preferred=False): def addPeer(self, prefix, address, set_preferred=False):
......
...@@ -405,10 +405,13 @@ class TunnelManager(object): ...@@ -405,10 +405,13 @@ class TunnelManager(object):
return return
code = ord(msg[0]) code = ord(msg[0])
if code == 1: # answer if code == 1: # answer
# TODO: do not fail if message contains garbage
# We parse the message in a way to discard a truncated line. # We parse the message in a way to discard a truncated line.
for peer in msg[1:].split('\n')[:-1]: for peer in msg[1:].split('\n')[:-1]:
prefix, address = peer.split() try:
prefix, address = peer.split()
int(prefix, 2)
except ValueError:
break
if prefix != self._prefix: if prefix != self._prefix:
self._peer_db.addPeer(prefix, address) self._peer_db.addPeer(prefix, address)
try: try:
......
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