def generate_work_orders(self, map_id, *capsules, num_ursulas=None): from nucypher.policy.models import WorkOrder # Prevent circular import try: treasure_map_to_use = self.treasure_maps[map_id] except KeyError: raise KeyError( "Bob doesn't have the TreasureMap {}; can't generate work orders.".format(map_id)) generated_work_orders = OrderedDict() if not treasure_map_to_use: raise ValueError( "Bob doesn't have a TreasureMap to match any of these capsules: {}".format( capsules)) for node_id, arrangement_id in treasure_map_to_use: ursula = self.known_nodes[node_id] capsules_to_include = [] for capsule in capsules: if not capsule in self._saved_work_orders[node_id]: capsules_to_include.append(capsule) if capsules_to_include: work_order = WorkOrder.construct_by_bob( arrangement_id, capsules_to_include, ursula, self) generated_work_orders[node_id] = work_order self._saved_work_orders[node_id][capsule] = work_order if num_ursulas is not None: if num_ursulas == len(generated_work_orders): break return generated_work_orders
def generate_work_orders(self, kfrag_hrac, *capsules, num_ursulas=None): from nucypher.policy.models import WorkOrder # Prevent circular import try: treasure_map_to_use = self.treasure_maps[kfrag_hrac] except KeyError: raise KeyError( "Bob doesn't have a TreasureMap matching the hrac {}".format( kfrag_hrac)) generated_work_orders = OrderedDict() if not treasure_map_to_use: raise ValueError( "Bob doesn't have a TreasureMap to match any of these capsules: {}" .format(capsules)) for ursula_dht_key in treasure_map_to_use: ursula = self.known_nodes[UmbralPublicKey.from_bytes( ursula_dht_key)] capsules_to_include = [] for capsule in capsules: if not capsule in self._saved_work_orders[ursula_dht_key]: capsules_to_include.append(capsule) if capsules_to_include: work_order = WorkOrder.construct_by_bob( kfrag_hrac, capsules_to_include, ursula, self) generated_work_orders[ursula_dht_key] = work_order self._saved_work_orders[ursula_dht_key][capsule] = work_order if num_ursulas is not None: if num_ursulas == len(generated_work_orders): break return generated_work_orders