Browse Source

Be more strict on form of features dictionary

master
Neil Booth 8 years ago
parent
commit
8236aaf234
  1. 13
      lib/peer.py
  2. 4
      server/controller.py
  3. 7
      server/peers.py

13
lib/peer.py

@ -49,6 +49,7 @@ class Peer(object):
a dictionary of features, and a record of the source.'''
assert isinstance(host, str)
assert isinstance(features, dict)
assert host in features.get('hosts', {})
self.host = host
self.features = features.copy()
# Canonicalize / clean-up
@ -105,10 +106,14 @@ class Peer(object):
def update_features(self, features):
'''Update features in-place.'''
tmp = Peer(self.host, features)
self.features = tmp.features
for feature in self.FEATURES:
setattr(self, feature, getattr(tmp, feature))
try:
tmp = Peer(self.host, features)
except Exception:
pass
else:
self.features = tmp.features
for feature in self.FEATURES:
setattr(self, feature, getattr(tmp, feature))
def connection_port_pairs(self):
'''Return a list of (kind, port) pairs to try when making a

4
server/controller.py

@ -508,8 +508,8 @@ class Controller(util.LoggedClass):
host = features['hosts'][hostname]
yield fmt.format(hostname[:30],
item['status'],
host['tcp_port'] or '',
host['ssl_port'] or '',
host.get('tcp_port') or '',
host.get('ssl_port') or '',
features['server_version'] or 'unknown',
features['protocol_min'],
features['protocol_max'],

7
server/peers.py

@ -400,7 +400,12 @@ class PeerManager(util.LoggedClass):
if data:
version, items = ast.literal_eval(data)
if version == 1:
peers = [Peer.deserialize(item) for item in items]
peers = []
for item in items:
try:
peers.append(Peer.deserialize(item))
except Exception:
pass
self.add_peers(peers, source='peers file', limit=None)
def import_peers(self):

Loading…
Cancel
Save