Skip to content

Commit

Permalink
Fixing exn send handling to account for sending asynchronously for mu…
Browse files Browse the repository at this point in the history
…ltisig AIDs if my participant is the "lead"

Signed-off-by: pfeairheller <pfeairheller@gmail.com>
  • Loading branch information
pfeairheller committed Oct 21, 2023
1 parent 8abb3bd commit 4081ac0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 12 deletions.
37 changes: 37 additions & 0 deletions src/keria/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts):
self.anchors = decking.Deck()
self.witners = decking.Deck()
self.queries = decking.Deck()
self.exchanges = decking.Deck()

receiptor = agenting.Receiptor(hby=hby)
self.postman = forwarding.Poster(hby=hby)
Expand Down Expand Up @@ -357,6 +358,7 @@ def __init__(self, hby, rgy, agentHab, agency, caid, **opts):
ParserDoer(kvy=self.kvy, parser=self.parser),
Witnesser(receiptor=receiptor, witners=self.witners),
Delegator(agentHab=agentHab, swain=self.swain, anchors=self.anchors),
ExchangeSender(hby=hby, agentHab=agentHab, exc=self.exc, postman=self.postman, exchanges=self.exchanges),
GroupRequester(hby=hby, agentHab=agentHab, counselor=self.counselor, groups=self.groups),
SeekerDoer(seeker=self.seeker, cues=self.verifier.cues),
ExnSeekerDoer(seeker=self.exnseeker, cues=self.exc.cues)
Expand Down Expand Up @@ -448,6 +450,41 @@ def recur(self, tyme=None):
return False


class ExchangeSender(doing.Doer):

def __init__(self, hby, agentHab, postman, exc, exchanges):
self.hby = hby
self.agentHab = agentHab
self.postman = postman
self.exc = exc
self.exchanges = exchanges
super(ExchangeSender, self).__init__()

def recur(self, tyme):
if self.exchanges:
msg = self.exchanges.popleft()
said = msg['said']
if not self.exc.complete(said=said):
self.exchanges.append(msg)
return False

serder, pathed = exchanging.cloneMessage(self.hby, said)

pre = msg["pre"]
rec = msg["rec"]
topic = msg['topic']
hab = self.hby.habs[pre]
if self.exc.lead(hab, said=said):
atc = exchanging.serializeMessage(self.hby, said)
del atc[:serder.size]
for recp in rec:
self.postman.send(hab=self.agentHab,
dest=recp,
topic=topic,
serder=serder,
attachment=atc)


class SeekerDoer(doing.Doer):

def __init__(self, seeker, cues):
Expand Down
13 changes: 5 additions & 8 deletions src/keria/peer/exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ def on_post(req, rep, name):
# now get rid of the event so we can pass it as atc to send
del ims[:serder.size]

for recp in rec: # now let's send it off the all the recipients
agent.postman.send(hab=agent.agentHab,
dest=recp,
topic=topic,
serder=serder,
attachment=ims)
msg = dict(said=serder.said, pre=hab.pre, rec=rec, topic=topic)

rep.status = falcon.HTTP_200
agent.exchanges.append(msg)

rep.status = falcon.HTTP_202
rep.data = json.dumps(serder.ked).encode("utf-8")


Expand Down Expand Up @@ -169,7 +166,7 @@ def on_get(req, rep, name, said):
if serder is None:
raise falcon.HTTPNotFound(description=f"SAID {said} does not match a verified EXN message")

exn = dict(exn=serder.ked, pathed=pathed)
exn = dict(exn=serder.ked, pathed={k: v.decode("utf-8") for k, v in pathed.items()})
rep.status = falcon.HTTP_200
rep.content_type = "application/json"
rep.data = json.dumps(exn).encode("utf-8")
3 changes: 2 additions & 1 deletion tests/app/test_aiding.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,7 +1230,8 @@ def test_oobi_ends(helpers):

# Test before endroles are added
res = client.simulate_get("/identifiers/pal/oobis?role=agent")
assert res.status_code == 404
assert res.status_code == 200
assert res.json == {'oobis': [], 'role': 'agent'}

rpy = helpers.endrole(iserder.pre, agent.agentHab.pre)
sigs = helpers.sign(salt, 0, 0, rpy.raw)
Expand Down
23 changes: 20 additions & 3 deletions tests/peer/test_exchanging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""
import json

from hio.base import doing
from keri.core import coring
from keri.peer.exchanging import exchange

Expand All @@ -31,6 +32,12 @@ def test_exchange_end(helpers):
with helpers.openKeria() as (agency, agent, app, client):
exchanging.loadEnds(app=app)

tock = 0.03125
limit = 1.0
doist = doing.Doist(limit=limit, tock=tock, real=True)

deeds = doist.enter(doers=[agent])

end = aiding.IdentifierCollectionEnd()
app.add_route("/identifiers", end)
endRolesEnd = aiding.EndRoleCollectionEnd()
Expand Down Expand Up @@ -65,9 +72,14 @@ def test_exchange_end(helpers):
)

res = client.simulate_post(path="/identifiers/aid1/exchanges", json=body)
assert res.status_code == 200
assert res.status_code == 202
assert res.json == cexn.ked
assert len(agent.exchanges) == 1

doist.recur(deeds=deeds)

assert len(agent.postman.evts) == 1
assert len(agent.exchanges) == 0
agent.exnseeker.index(cexn.said)

QVI_SAID = "EFgnk_c08WmZGgv9_mpldibRuqFMTQN-rAgtD-TCOwbs"
Expand All @@ -92,9 +104,14 @@ def test_exchange_end(helpers):
assert res.status_code == 404

res = client.simulate_post(path="/identifiers/aid1/exchanges", json=body)
assert res.status_code == 200
assert res.status_code == 202
assert len(agent.exchanges) == 1
assert res.json == exn.ked
assert len(agent.postman.evts) == 2

doist.recur(deeds=deeds)

assert len(agent.postman.evts) == 1
assert len(agent.exchanges) == 0
agent.exnseeker.index(exn.said)

body = json.dumps({}).encode("utf-8")
Expand Down

0 comments on commit 4081ac0

Please sign in to comment.