From b7538ef7d2a8cd0aa046443fb2856199c847e9e0 Mon Sep 17 00:00:00 2001 From: pfeairheller Date: Tue, 20 Jun 2023 14:33:53 -0700 Subject: [PATCH] allow the rotate command to add witness poller for any new witnesses. --- src/keri/app/cli/commands/incept.py | 3 +-- src/keri/app/cli/commands/rotate.py | 5 ++++- src/keri/app/habbing.py | 5 +++-- src/keri/app/indirecting.py | 28 +++++++++++++++++++--------- src/keri/app/storing.py | 8 +++++++- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/keri/app/cli/commands/incept.py b/src/keri/app/cli/commands/incept.py index 9f581565f..6fdce392e 100644 --- a/src/keri/app/cli/commands/incept.py +++ b/src/keri/app/cli/commands/incept.py @@ -16,8 +16,7 @@ logger = help.ogler.getLogger() parser = argparse.ArgumentParser(description='Initialize a prefix') -parser.set_defaults(handler=lambda args: handler(args), - transferable=True) +parser.set_defaults(handler=lambda args: handler(args)) parser.add_argument('--name', '-n', help='keystore name and file location of KERI keystore', required=True) parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore', required=False, default="") diff --git a/src/keri/app/cli/commands/rotate.py b/src/keri/app/cli/commands/rotate.py index 4ef44af1d..7e0cd66cd 100644 --- a/src/keri/app/cli/commands/rotate.py +++ b/src/keri/app/cli/commands/rotate.py @@ -176,7 +176,6 @@ def rotateDo(self, tymth, tock=0.0): self.adds = set(self.wits) - set(ewits) if self.endpoint: for wit in self.adds: - print(f"catching up {wit}") yield from receiptor.catchup(hab.pre, wit) hab.rotate(isith=self.isith, nsith=self.nsith, ncount=self.count, toad=self.toad, @@ -193,6 +192,10 @@ def rotateDo(self, tymth, tock=0.0): if self.endpoint: yield from receiptor.receipt(hab.pre, sn=hab.kever.sn) else: + for wit in self.adds: + self.mbx.addPoller(hab, witness=wit) + + print("Waiting for witness receipts...") witDoer = agenting.WitnessReceiptor(hby=self.hby) self.extend(doers=[witDoer]) yield self.tock diff --git a/src/keri/app/habbing.py b/src/keri/app/habbing.py index 517282414..1f5bd7174 100644 --- a/src/keri/app/habbing.py +++ b/src/keri/app/habbing.py @@ -395,7 +395,7 @@ def loadHabs(self): self.reconfigure() # post hab load reconfiguration - def makeHab(self, name, ns=None, **kwa): + def makeHab(self, name, ns=None, cf=None, **kwa): """Make new Hab with name, pre is generated from **kwa Parameters: (Passthrough to hab.make) @@ -418,7 +418,8 @@ def makeHab(self, name, ns=None, **kwa): if ns is not None and "." in ns: raise kering.ConfigurationError("Hab namespace names are not allowed to contain the '.' character") - hab = Hab(ks=self.ks, db=self.db, cf=self.cf, mgr=self.mgr, + cf = cf if cf is not None else self.cf + hab = Hab(ks=self.ks, db=self.db, cf=cf, mgr=self.mgr, rtr=self.rtr, rvy=self.rvy, kvy=self.kvy, psr=self.psr, name=name, ns=ns, temp=self.temp) diff --git a/src/keri/app/indirecting.py b/src/keri/app/indirecting.py index 75158ba0d..c0454efd5 100644 --- a/src/keri/app/indirecting.py +++ b/src/keri/app/indirecting.py @@ -34,7 +34,7 @@ logger = help.ogler.getLogger() -def setupWitness(hby, alias="witness", mbx=None, tcpPort=5631, httpPort=5632): +def setupWitness(hby, alias="witness", mbx=None, aids=None, tcpPort=5631, httpPort=5632): """ Setup witness controller and doers @@ -59,7 +59,7 @@ def setupWitness(hby, alias="witness", mbx=None, tcpPort=5631, httpPort=5632): app = falcon.App(cors_enable=True) ending.loadEnds(app=app, hby=hby, default=hab.pre) oobiRes = oobiing.loadEnds(app=app, hby=hby, prefix="/ext") - rep = storing.Respondant(hby=hby, mbx=mbx) + rep = storing.Respondant(hby=hby, mbx=mbx, aids=aids) rvy = routing.Revery(db=hby.db, cues=cues) kvy = eventing.Kevery(db=hby.db, @@ -83,7 +83,7 @@ def setupWitness(hby, alias="witness", mbx=None, tcpPort=5631, httpPort=5632): httpEnd = HttpEnd(rxbs=parser.ims, mbx=mbx) app.add_route("/", httpEnd) - receiptEnd = ReceiptEnd(hab=hab, inbound=cues) + receiptEnd = ReceiptEnd(hab=hab, inbound=cues, aids=aids) app.add_route("/receipts", receiptEnd) server = http.Server(port=httpPort, app=app) @@ -92,18 +92,19 @@ def setupWitness(hby, alias="witness", mbx=None, tcpPort=5631, httpPort=5632): # setup doers regDoer = basing.BaserDoer(baser=verfer.reger) - server = serving.Server(host="", port=tcpPort) - serverDoer = serving.ServerDoer(server=server) + if tcpPort is not None: + server = serving.Server(host="", port=tcpPort) + serverDoer = serving.ServerDoer(server=server) - directant = directing.Directant(hab=hab, server=server, verifier=verfer) + directant = directing.Directant(hab=hab, server=server, verifier=verfer) + doers.extend([directant, serverDoer]) witStart = WitnessStart(hab=hab, parser=parser, cues=receiptEnd.outbound, kvy=kvy, tvy=tvy, rvy=rvy, exc=exchanger, replies=rep.reps, responses=rep.cues, queries=httpEnd.qrycues) doers.extend(oobiRes) - doers.extend([regDoer, exchanger, directant, serverDoer, httpServerDoer, rep, witStart, receiptEnd, *oobiery.doers]) - + doers.extend([regDoer, exchanger, httpServerDoer, rep, witStart, receiptEnd, *oobiery.doers]) return doers @@ -627,6 +628,11 @@ def addPollers(self, hab): self.prefixes.add(hab.pre) + def addPoller(self, hab, witness): + poller = Poller(hab=hab, topics=self.topics, witness=witness) + self.pollers.append(poller) + self.extend([poller]) + def processPollIter(self): """ Iterate through cues and yields one or more responses for each cue. @@ -1012,10 +1018,11 @@ class ReceiptEnd(doing.DoDoer): """ - def __init__(self, hab, inbound=None, outbound=None): + def __init__(self, hab, inbound=None, outbound=None, aids=None): self.hab = hab self.inbound = inbound if inbound is not None else decking.Deck() self.outbound = outbound if outbound is not None else decking.Deck() + self.aids = aids self.receipts = set() self.psr = parsing.Parser(framed=True, kvy=self.hab.kvy) @@ -1042,6 +1049,9 @@ def on_post(self, req, rep): serder = eventing.Serder(ked=cr.payload, kind=eventing.Serials.json) pre = serder.ked["i"] + if self.aids is not None and pre not in self.aids: + raise falcon.HTTPBadRequest(description=f"invalid AID={pre} for witnessing receipting") + ilk = serder.ked["t"] if ilk not in (Ilks.icp, Ilks.rot, Ilks.ixn, Ilks.dip, Ilks.drt): raise falcon.HTTPBadRequest(description=f"invalid event type ({ilk})for receipting") diff --git a/src/keri/app/storing.py b/src/keri/app/storing.py index 5a02560e8..77bf3aa57 100644 --- a/src/keri/app/storing.py +++ b/src/keri/app/storing.py @@ -140,7 +140,7 @@ class Respondant(doing.DoDoer): """ - def __init__(self, hby, reps=None, cues=None, mbx=None, **kwa): + def __init__(self, hby, reps=None, cues=None, mbx=None, aids=None, **kwa): """ Creates Respondant that uses local environment to find the destination KEL and stores peer to peer messages in mbx, the mailboxer @@ -154,6 +154,7 @@ def __init__(self, hby, reps=None, cues=None, mbx=None, **kwa): self.cues = cues if cues is not None else decking.Deck() self.hby = hby + self.aids = aids self.mbx = mbx if mbx is not None else Mailboxer(name=self.hby.name) self.postman = forwarding.Poster(hby=self.hby, mbx=self.mbx) @@ -225,6 +226,11 @@ def cueDo(self, tymth=None, tock=0.0): serder = cue["serder"] # Serder of received event for other pre cuedKed = serder.ked cuedPrefixer = coring.Prefixer(qb64=cuedKed["i"]) + + # If respondant configured with list of acceptable AIDs to witness for, check them here + if self.aids is not None and cuedPrefixer.qb64 not in self.aids: + continue + if cuedPrefixer.qb64 in self.hby.kevers: kever = self.hby.kevers[cuedPrefixer.qb64] owits = oset(kever.wits)