mirror of https://github.com/nucypher/nucypher.git
Group completed work orders by capsule in work_orders_for_capsules()
parent
af7e9701bf
commit
fb55fd349a
|
@ -39,6 +39,7 @@ from constant_sorrow.constants import (
|
||||||
READY,
|
READY,
|
||||||
INVALIDATED
|
INVALIDATED
|
||||||
)
|
)
|
||||||
|
from collections import OrderedDict, defaultdict
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
|
from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurve
|
||||||
from cryptography.hazmat.primitives.serialization import Encoding
|
from cryptography.hazmat.primitives.serialization import Encoding
|
||||||
|
@ -701,7 +702,7 @@ class Bob(Character):
|
||||||
raise KeyError(f"Bob doesn't have the TreasureMap {map_id}; can't generate work orders.")
|
raise KeyError(f"Bob doesn't have the TreasureMap {map_id}; can't generate work orders.")
|
||||||
|
|
||||||
incomplete_work_orders = OrderedDict()
|
incomplete_work_orders = OrderedDict()
|
||||||
complete_work_orders = OrderedDict()
|
complete_work_orders = defaultdict(list)
|
||||||
|
|
||||||
if not treasure_map_to_use:
|
if not treasure_map_to_use:
|
||||||
raise ValueError(f"Bob doesn't have a TreasureMap to match any of these capsules: {capsules}")
|
raise ValueError(f"Bob doesn't have a TreasureMap to match any of these capsules: {capsules}")
|
||||||
|
@ -715,7 +716,7 @@ class Bob(Character):
|
||||||
try:
|
try:
|
||||||
precedent_work_order = self._completed_work_orders.most_recent_replete(capsule)[node_id]
|
precedent_work_order = self._completed_work_orders.most_recent_replete(capsule)[node_id]
|
||||||
self.log.debug(f"{capsule} already has a saved WorkOrder for this Node:{node_id}.")
|
self.log.debug(f"{capsule} already has a saved WorkOrder for this Node:{node_id}.")
|
||||||
complete_work_orders[node_id] = precedent_work_order
|
complete_work_orders[capsule].append(precedent_work_order)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# Don't have a precedent completed WorkOrder for this Ursula for this Capsule.
|
# Don't have a precedent completed WorkOrder for this Ursula for this Capsule.
|
||||||
# We need to make a new one.
|
# We need to make a new one.
|
||||||
|
@ -737,8 +738,9 @@ class Bob(Character):
|
||||||
# TODO: Presently, the order here is haphazard . Do we want to do the complete or incomplete specifically first? NRN
|
# TODO: Presently, the order here is haphazard . Do we want to do the complete or incomplete specifically first? NRN
|
||||||
break
|
break
|
||||||
|
|
||||||
if incomplete_work_orders == OrderedDict():
|
if not incomplete_work_orders:
|
||||||
self.log.warn("No new WorkOrders created. Try calling this with different parameters.") # TODO: Clearer instructions. NRN
|
self.log.warn(
|
||||||
|
"No new WorkOrders created. Try calling this with different parameters.") # TODO: Clearer instructions. NRN
|
||||||
|
|
||||||
return incomplete_work_orders, complete_work_orders
|
return incomplete_work_orders, complete_work_orders
|
||||||
|
|
||||||
|
@ -827,13 +829,13 @@ class Bob(Character):
|
||||||
alice_verifying_key=alice_verifying_key,
|
alice_verifying_key=alice_verifying_key,
|
||||||
*capsules_to_activate)
|
*capsules_to_activate)
|
||||||
|
|
||||||
self.log.info(f"Found {len(complete_work_orders)} for Capsules ({capsules_to_activate}).")
|
self.log.info(f"Found {len(complete_work_orders)} complete work orders "
|
||||||
|
f"for Capsules ({capsules_to_activate}).")
|
||||||
|
|
||||||
if complete_work_orders:
|
if complete_work_orders:
|
||||||
if use_precedent_work_orders:
|
if use_precedent_work_orders:
|
||||||
for capsule in capsules_to_activate:
|
for capsule, work_orders in complete_work_orders.items():
|
||||||
for work_order in complete_work_orders.values():
|
for work_order in work_orders:
|
||||||
if capsule in work_order.tasks:
|
|
||||||
cfrag_in_question = work_order.tasks[capsule].cfrag
|
cfrag_in_question = work_order.tasks[capsule].cfrag
|
||||||
capsule.attach_cfrag(cfrag_in_question)
|
capsule.attach_cfrag(cfrag_in_question)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue