Better -v messages for fn-fmsread.
diff --git a/infocalypse/fms.py b/infocalypse/fms.py
--- a/infocalypse/fms.py
+++ b/infocalypse/fms.py
@@ -205,10 +205,13 @@ def strip_names(trust_map):
class USKIndexUpdateParser(IFmsMessageSink):
""" Class which accumulates USK index update notifications
from fms messages. """
- def __init__(self, trust_map):
+ def __init__(self, trust_map, keep_untrusted=False):
IFmsMessageSink.__init__(self)
self.trust_map = strip_names(trust_map)
self.updates = {}
+ self.untrusted = None
+ if keep_untrusted:
+ self.untrusted = {}
def wants_msg(self, dummy, items):
""" IFmsMessageSink implementation. """
@@ -216,6 +219,9 @@ class USKIndexUpdateParser(IFmsMessageSi
# Skip replies
return False
+ if not self.untrusted is None:
+ return True
+
if clean_nym(items[2]) not in self.trust_map:
#print "Not trusted: ", items[2]
# Sender not authoritative on any USK.
@@ -225,7 +231,7 @@ class USKIndexUpdateParser(IFmsMessageSi
def recv_fms_msg(self, dummy, items, lines):
""" IFmsMessageSink implementation. """
- allowed_hashes = self.trust_map[clean_nym(items[2])]
+ allowed_hashes = self.trust_map.get(clean_nym(items[2]), ())
#print "---\nSender: %s\nSubject: %s\n" % (items[2], items[1])
for update in parse(lines, True)[0]:
@@ -233,15 +239,24 @@ class USKIndexUpdateParser(IFmsMessageSi
# Only update if the nym is trusted *for the specific USK*.
#print "UPDATING ---\nSender: %s\nSubject:
# %s\n" % (items[2], items[1])
- self.handle_update(update)
+ self.handle_trusted_update(update)
+ else:
+ self.handle_untrusted_update(items[2], update)
- def handle_update(self, update):
+ def handle_trusted_update(self, update):
""" INTERNAL: Handle a single update. """
index = update[1]
value = self.updates.get(update[0], index)
if index >= value:
self.updates[update[0]] = index
+ def handle_untrusted_update(self, sender, update):
+ """ INTERNAL: Handle a single untrusted update. """
+ entry = self.untrusted.get(update[0], [])
+ if not sender in entry:
+ entry.append(sender)
+ self.untrusted[update[0]] = entry
+
def updated(self, previous=None):
""" Returns a USK hash -> index map for USKs which
have been updated. """
diff --git a/infocalypse/infcmds.py b/infocalypse/infcmds.py
--- a/infocalypse/infcmds.py
+++ b/infocalypse/infcmds.py
@@ -714,7 +714,7 @@ def execute_info(ui_, params, stored_cfg
ui_.status(INFO_FMT %
(usk_hash, max_index or -1, request_uri, insert_uri))
-def handled_listall(ui_, params, stored_cfg):
+def handled_list(ui_, params, stored_cfg):
""" INTERNAL: Helper function to simplify execute_fmsread. """
if params['FMSREAD'] != 'list' and params['FMSREAD'] != 'listall':
return False
@@ -760,7 +760,7 @@ def execute_fmsread(ui_, params, stored_
' '.join(stored_cfg.fmsread_groups)))
# Listing announced Repo USKs
- if handled_listall(ui_, params, stored_cfg):
+ if handled_list(ui_, params, stored_cfg):
return
# Updating Repo USK indices for repos which are
@@ -768,6 +768,8 @@ def execute_fmsread(ui_, params, stored_
# config file.
trust_map = stored_cfg.fmsread_trust_map.copy() # paranoid copy
if params['VERBOSITY'] >= 2:
+ if not params['REQUEST_URI'] is None:
+ ui_.status("USK Hash: %s\n" % get_usk_hash(params['REQUEST_URI']))
fms_ids = trust_map.keys()
fms_ids.sort()
ui_.status("Update Trust Map:\n")
@@ -775,19 +777,39 @@ def execute_fmsread(ui_, params, stored_
ui_.status(" %s: %s\n" % (fms_id,
' '.join(trust_map[fms_id])))
ui_.status("\n")
- parser = USKIndexUpdateParser(trust_map)
+ ui_.status("Raking through fms messages. This make take a while...\n")
+ parser = USKIndexUpdateParser(trust_map, True)
recv_msgs(stored_cfg.defaults['FMS_HOST'],
stored_cfg.defaults['FMS_PORT'],
parser,
stored_cfg.fmsread_groups)
changed = parser.updated(stored_cfg.version_table)
+
+ if params['VERBOSITY'] >= 2:
+ if parser.untrusted and len(parser.untrusted) > 0:
+ text = 'Skipped Untrusted Updates:\n'
+ for usk_hash in parser.untrusted:
+ text += usk_hash + ':\n'
+ fms_ids = parser.untrusted[usk_hash]
+ for fms_id in fms_ids:
+ text += ' ' + fms_id + '\n'
+ text += '\n'
+ ui_.status(text)
+
if len(changed) == 0:
ui_.status('No updates found.\n')
return
- # Back map to uris ?
- for usk_hash in changed:
- ui_.status('%s:%i\n' % (usk_hash, changed[usk_hash]))
+ # Back map to uris ? Can't always do it.
+ if len(changed) > 0:
+ text = 'Updates:\n'
+ for usk_hash in changed:
+ text += '%s:%i\n' % (usk_hash, changed[usk_hash])
+ ui_.status(text)
+ if ((not params['REQUEST_URI'] is None) and
+ get_usk_hash(params['REQUEST_URI']) in changed):
+ ui_.status("Current repo has update to index %s.\n" %
+ changed[get_usk_hash(params['REQUEST_URI'])])
if params['DRYRUN']:
ui_.status('Exiting without saving because --dryrun was set.\n')
@@ -796,6 +818,7 @@ def execute_fmsread(ui_, params, stored_
for usk_hash in changed:
stored_cfg.update_index(usk_hash, changed[usk_hash])
+
Config.to_file(stored_cfg)
ui_.status('Saved updated indices.\n')