Skip to content

Commit

Permalink
allow the rotate command to add witness poller for any new witnesses. (
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeairheller authored Jun 20, 2023
1 parent 691c639 commit 7a86f84
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/keri/app/cli/commands/incept.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="")
Expand Down
5 changes: 4 additions & 1 deletion src/keri/app/cli/commands/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/keri/app/habbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down
28 changes: 19 additions & 9 deletions src/keri/app/indirecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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


Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
8 changes: 7 additions & 1 deletion src/keri/app/storing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7a86f84

Please sign in to comment.