Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
arminveres committed Nov 15, 2023
1 parent cd2f412 commit 47b89b1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 2 additions & 0 deletions impl/src/agents/agent_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ def __init__(
self.last_proof_received = None

async def detect_connection(self):
self._connection_ready = asyncio.Future()
log_msg("Waiting for connection...")
await self._connection_ready
self._connection_ready = None

Expand Down
33 changes: 22 additions & 11 deletions impl/src/agents/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PERF_LOG = "./.agent_cache/time_log"


def log_time_to_file(text):
async def log_time_to_file(text):
with open(PERF_LOG, mode="a", encoding="utf-8") as perf_log:
perf_log.write(text)

Expand Down Expand Up @@ -146,8 +146,8 @@ async def handle_notify_vulnerability(self, message):
# mark devices to be revoked
for device in self.db_client.db_keys[vuln_db_name]:
db_result = await self.db_client.query_key(vuln_db_name, device)
log_json(db_result)
log_json(vulnerability)
# log_json(db_result)
# log_json(vulnerability)

for component_key, component_value in db_result["components"].items():
for (
Expand Down Expand Up @@ -213,7 +213,7 @@ async def handle_node_updated(self, message):

await self.issue_credential(node_did, node_name, node_cred, DB_NAME)
await self.db_client.record_key(DB_NAME, node_name, db_entry)
log_time_to_file(f"UPDATE: time: {time.perf_counter_ns()}, node: {node_name}\n")
await log_time_to_file(f"UPDATE: time: {time.perf_counter_ns()}, node: {node_name}\n")

# =============================================================================================
# Additional methods
Expand All @@ -229,6 +229,9 @@ async def revoke_credential(
Revoke a credentials and publish it.
"""
response = await self.db_client.query_key(db_name, node_name)
cred_ex_id = response.get("cred_ex_id")

# update database with removed credential id
response["cred_ex_id"] = ""
response["valid"] = False
await self.db_client.record_key(db_name, node_name, response)
Expand All @@ -250,7 +253,7 @@ async def issue_credential(
node_did: str,
node_name: str,
node_cred: dict,
domain: str,
db_name: str,
):
"""
Issue a predetermined credential to a node
Expand All @@ -262,7 +265,7 @@ async def issue_credential(
"""
recipient_key = await self.send_invitation(node_did)
# we set the recipient key for later identification
self.db_client.db_keys[domain][node_name]["recipient_key"] = recipient_key
self.db_client.db_keys[db_name][node_name]["recipient_key"] = recipient_key

self._connection_ready = asyncio.Future()
log_msg("Waiting for connection...")
Expand All @@ -276,9 +279,9 @@ async def issue_credential(
for conn in response["results"]:
if conn["invitation_key"] == recipient_key:
conn_id = conn["connection_id"]
self.db_client.db_keys[domain][node_name]["connection_id"] = conn_id
self.db_client.db_keys[db_name][node_name]["connection_id"] = conn_id
# remove recipient/invitation key
self.db_client.db_keys[domain][node_name].pop("recipient_key")
self.db_client.db_keys[db_name][node_name].pop("recipient_key")

self.reset_connection()

Expand All @@ -296,7 +299,7 @@ async def issue_credential(
"credential_preview": cred_preview,
"filter": {"indy": {"cred_def_id": self.cred_def_id}},
}
response = await self.admin_POST("/issue-credential-2.0/send-offer", offer_request)
_ = await self.admin_POST("/issue-credential-2.0/send-offer", offer_request)

async def onboard_node(self, domain: str, node_name: str, node_did: str):
"""
Expand Down Expand Up @@ -349,7 +352,7 @@ async def mass_onboard(self):
await self.onboard_node(DB_NAME, node["name"], node["did"])

async def remove_device(self, node_name: str):
db_result = await self.db_client.query_key(DB_NAME, node_name)
# db_result = await self.db_client.query_key(DB_NAME, node_name)
await self.revoke_credential(
"",
DB_NAME,
Expand Down Expand Up @@ -482,6 +485,14 @@ def get_prompt():
# =========================================================================================
# New prompt based event loop, events such as webhooks still run in the background.

await setup_database(agent_container, DB_NAME)
prompt_options.pop("setup_db")
# add onboarding option and update order by values
prompt_options = add_option(
prompt_options, "onboard", " [3]: Onboard node with public DID\n"
)
prompt_options = add_option(prompt_options, "mass_onboard", " [4]: Mass Onboard fleet\n")

async for option in prompt_loop(get_prompt):
if option is not None:
option = option.strip()
Expand Down Expand Up @@ -529,7 +540,7 @@ def get_prompt():
node_did = node_did.strip()

await agent_container.agent.onboard_node(
domain=DB_NAME,
db_name=DB_NAME,
node_did=node_did,
node_name=node_name,
)
Expand Down

0 comments on commit 47b89b1

Please sign in to comment.