Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Faber demo to use oob with aip10 to support connection reuse #2903

Merged
merged 9 commits into from
Apr 19, 2024
6 changes: 4 additions & 2 deletions demo/runners/agent_container.py
ianco marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ async def handle_out_of_band(self, message):

async def handle_connection_reuse(self, message):
# we are reusing an existing connection, set our status to the existing connection
print("handle_connection_reuse()")
if self._connection_ready is not None:
if not self._connection_ready.done():
self.connection_id = message["connection_id"]
Expand All @@ -131,6 +132,7 @@ async def handle_connection_reuse(self, message):

async def handle_connection_reuse_accepted(self, message):
# we are reusing an existing connection, set our status to the existing connection
print("handle_connection_reuse_accepted()")
if not self._connection_ready.done():
self.connection_id = message["connection_id"]
self.log("Connected")
Expand Down Expand Up @@ -1540,8 +1542,8 @@ async def create_agent_with_args(args, ident: str = None, extra_args: list = Non
)

reuse_connections = "reuse_connections" in args and args.reuse_connections
if reuse_connections and aip != 20:
raise Exception("Can only specify `--reuse-connections` with AIP 2.0")
# if reuse_connections and aip != 20:
# raise Exception("Can only specify `--reuse-connections` with AIP 2.0")
multi_use_invitations = (
"multi_use_invitations" in args and args.multi_use_invitations
)
Expand Down
47 changes: 32 additions & 15 deletions demo/runners/support/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -1455,20 +1455,20 @@ async def get_invite(
emit_did_peer_4: bool = False,
):
self.connection_id = None
if emit_did_peer_2:
use_did_method = "did:peer:2"
elif emit_did_peer_4:
use_did_method = "did:peer:4"
else:
use_did_method = None

create_unique_did = (
use_did_method is not None
and (not reuse_connections)
and (not public_did_connections)
)
if use_did_exchange:
# TODO can mediation be used with DID exchange connections?
if emit_did_peer_2:
use_did_method = "did:peer:2"
elif emit_did_peer_4:
use_did_method = "did:peer:4"
else:
use_did_method = None

create_unique_did = (
use_did_method is not None
and (not reuse_connections)
and (not public_did_connections)
)
invi_params = {
"auto_accept": json.dumps(auto_accept),
"multi_use": json.dumps(multi_use_invitations),
Expand All @@ -1482,14 +1482,32 @@ async def get_invite(
payload["mediation_id"] = self.mediator_request_id
if use_did_method:
payload["use_did_method"] = use_did_method
print("Calling /out-of-band/create-invitation with:", payload, invi_params)
invi_rec = await self.admin_POST(
"/out-of-band/create-invitation",
payload,
params=invi_params,
)
else:
if self.mediation:
if reuse_connections:
# use oob for connection reuse
invi_params = {
"auto_accept": json.dumps(auto_accept),
"create_unique_did": json.dumps(create_unique_did),
}
payload = {
"handshake_protocols": ["https://didcomm.org/connections/1.0"],
"use_public_did": public_did_connections,
}
if self.mediation:
payload["mediation_id"] = self.mediator_request_id
if use_did_method:
payload["use_did_method"] = use_did_method
invi_rec = await self.admin_POST(
"/out-of-band/create-invitation",
payload,
params=invi_params,
)
elif self.mediation:
invi_params = {
"auto_accept": json.dumps(auto_accept),
}
Expand All @@ -1514,7 +1532,6 @@ async def receive_invite(self, invite, auto_accept: bool = True):
if "/out-of-band/" in invite.get("@type", ""):
# reuse connections if requested and possible
params["use_existing_connection"] = json.dumps(self.reuse_connections)
print("Receiving invitation with params:", params)
connection = await self.admin_POST(
"/out-of-band/receive-invitation",
invite,
Expand Down