Be more strict on form of features dictionary
This commit is contained in:
parent
31755e1dac
commit
8236aaf234
13
lib/peer.py
13
lib/peer.py
@ -49,6 +49,7 @@ class Peer(object):
|
|||||||
a dictionary of features, and a record of the source.'''
|
a dictionary of features, and a record of the source.'''
|
||||||
assert isinstance(host, str)
|
assert isinstance(host, str)
|
||||||
assert isinstance(features, dict)
|
assert isinstance(features, dict)
|
||||||
|
assert host in features.get('hosts', {})
|
||||||
self.host = host
|
self.host = host
|
||||||
self.features = features.copy()
|
self.features = features.copy()
|
||||||
# Canonicalize / clean-up
|
# Canonicalize / clean-up
|
||||||
@ -105,10 +106,14 @@ class Peer(object):
|
|||||||
|
|
||||||
def update_features(self, features):
|
def update_features(self, features):
|
||||||
'''Update features in-place.'''
|
'''Update features in-place.'''
|
||||||
tmp = Peer(self.host, features)
|
try:
|
||||||
self.features = tmp.features
|
tmp = Peer(self.host, features)
|
||||||
for feature in self.FEATURES:
|
except Exception:
|
||||||
setattr(self, feature, getattr(tmp, feature))
|
pass
|
||||||
|
else:
|
||||||
|
self.features = tmp.features
|
||||||
|
for feature in self.FEATURES:
|
||||||
|
setattr(self, feature, getattr(tmp, feature))
|
||||||
|
|
||||||
def connection_port_pairs(self):
|
def connection_port_pairs(self):
|
||||||
'''Return a list of (kind, port) pairs to try when making a
|
'''Return a list of (kind, port) pairs to try when making a
|
||||||
|
|||||||
@ -508,8 +508,8 @@ class Controller(util.LoggedClass):
|
|||||||
host = features['hosts'][hostname]
|
host = features['hosts'][hostname]
|
||||||
yield fmt.format(hostname[:30],
|
yield fmt.format(hostname[:30],
|
||||||
item['status'],
|
item['status'],
|
||||||
host['tcp_port'] or '',
|
host.get('tcp_port') or '',
|
||||||
host['ssl_port'] or '',
|
host.get('ssl_port') or '',
|
||||||
features['server_version'] or 'unknown',
|
features['server_version'] or 'unknown',
|
||||||
features['protocol_min'],
|
features['protocol_min'],
|
||||||
features['protocol_max'],
|
features['protocol_max'],
|
||||||
|
|||||||
@ -400,7 +400,12 @@ class PeerManager(util.LoggedClass):
|
|||||||
if data:
|
if data:
|
||||||
version, items = ast.literal_eval(data)
|
version, items = ast.literal_eval(data)
|
||||||
if version == 1:
|
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)
|
self.add_peers(peers, source='peers file', limit=None)
|
||||||
|
|
||||||
def import_peers(self):
|
def import_peers(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user