def grant(self, bob, uri, m=None, n=None, expiration=None, deposit=None): if not m: # TODO: get m from config #176 raise NotImplementedError if not n: # TODO: get n from config #176 raise NotImplementedError if not expiration: # TODO: check default duration in config #176 raise NotImplementedError if not deposit: default_deposit = None # TODO: Check default deposit in config. #176 if not default_deposit: deposit = self.network_middleware.get_competitive_rate() if deposit == NotImplemented: deposit = constants.NON_PAYMENT(b"0000000") policy = self.create_policy(bob, uri, m, n) # We'll find n Ursulas by default. It's possible to "play the field" # by trying differet # deposits and expirations on a limited number of Ursulas. # Users may decide to inject some market strategies here. found_ursulas = policy.find_ursulas(self.network_middleware, deposit, expiration, num_ursulas=n) policy.match_kfrags_to_found_ursulas(found_ursulas) # REST call happens here, as does population of TreasureMap. policy.enact(self.network_middleware) policy.publish_treasure_map(self.network_middleware) return policy # Now with TreasureMap affixed!
def enacted_policy(idle_policy, ursulas): # Alice has a policy in mind and knows of enough qualifies Ursulas; she crafts an offer for them. deposit = constants.NON_PAYMENT(b"0000000") contract_end_datetime = maya.now() + datetime.timedelta(days=5) networky_stuff = MockNetworkyStuff(ursulas) found_ursulas = idle_policy.find_ursulas(networky_stuff, deposit, expiration=contract_end_datetime) idle_policy.match_kfrags_to_found_ursulas(found_ursulas) idle_policy.enact(networky_stuff) # REST call happens here, as does population of TreasureMap. return idle_policy
def grant(self, bob, uri, m=None, n=None, expiration=None, deposit=None, handpicked_ursulas=None): if not m: # TODO: get m from config #176 raise NotImplementedError if not n: # TODO: get n from config #176 raise NotImplementedError if not expiration: # TODO: check default duration in config #176 raise NotImplementedError if not deposit: default_deposit = None # TODO: Check default deposit in config. #176 if not default_deposit: deposit = self.network_middleware.get_competitive_rate() if deposit == NotImplemented: deposit = constants.NON_PAYMENT(b"0000000") if handpicked_ursulas is None: handpicked_ursulas = set() policy = self.create_policy(bob, uri, m, n) # # We'll find n Ursulas by default. It's possible to "play the field" by trying different # deposit and expiration combinations on a limited number of Ursulas; # Users may decide to inject some market strategies here. # # TODO: 289 # If we're federated only, we need to block to make sure we have enough nodes. if self.federated_only and len(self.known_nodes) < n: good_to_go = self.block_until_number_of_known_nodes_is(n, learn_on_this_thread=True) if not good_to_go: raise ValueError( "To make a Policy in federated mode, you need to know about\ all the Ursulas you need (in this case, {}); there's no other way to\ know which nodes to use. Either pass them here or when you make\ the Policy, or run the learning loop on a network with enough Ursulas.".format(self.n)) if len(handpicked_ursulas) < n: number_of_ursulas_needed = n - len(handpicked_ursulas) new_ursulas = random.sample(list(self.known_nodes.values()), number_of_ursulas_needed) handpicked_ursulas.update(new_ursulas) policy.make_arrangements(network_middleware=self.network_middleware, deposit=deposit, expiration=expiration, handpicked_ursulas=handpicked_ursulas, ) # REST call happens here, as does population of TreasureMap. policy.enact(network_middleware=self.network_middleware) return policy # Now with TreasureMap affixed!
def enacted_blockchain_policy(idle_blockchain_policy, blockchain_ursulas): # Alice has a policy in mind and knows of enough qualifies Ursulas; she crafts an offer for them. deposit = constants.NON_PAYMENT(b"0000000") contract_end_datetime = maya.now() + datetime.timedelta(days=5) network_middleware = MockRestMiddleware() idle_blockchain_policy.make_arrangements(network_middleware, deposit=deposit, expiration=contract_end_datetime, ursulas=list(blockchain_ursulas)) idle_blockchain_policy.enact(network_middleware) # REST call happens here, as does population of TreasureMap. return idle_blockchain_policy