def attempt_purchase(): """ Check if enough money to buy a server, and if so, do so, """ (provider, option, _) = config.get('chosen_provider') if settings.wallets_testnet(): domain = 'TBTC' else: domain = 'BTC' if market_controller.get_balance(domain) >= ( cloudomate_controller.calculate_price(provider, option) + cloudomate_controller.calculate_price_vpn()): logger.log("Try to buy a new server from %s" % provider, log_name) success = cloudomate_controller.purchase_choice(config) if success == plebnet_settings.SUCCESS: # Evolve yourself positively if you are successful dna.evolve(True) logger.log( "Purchasing vps for child %s successful" % (dna.get_own_tree() + '.' + str(config.get('child_index')))) # purchase VPN with same config if server allows for it if cloudomate_controller.get_vps_providers( )[provider].TUN_TAP_SETTINGS: attempt_purchase_vpn() elif success == plebnet_settings.FAILURE: # Evolve provider negatively if not successful dna.evolve(False, provider) config.increment_child_index() fake_generator.generate_child_account() config.set('chosen_provider', None) config.save()
def setup(args): logger.log("Setting up PlebNet") # Prepare Cloudomate if args.test_net: settings.wallets_testnet("1") settings.settings.write() fake_generator.generate_child_account() # TODO: change --> Prepare plebnet config = PlebNetConfig() config.set('expiration_date', time.time() + 30 * plebnet_settings.TIME_IN_DAY) config.save() # handle the DNA dna = DNA() dna.read_dictionary(cloudomate_controller.get_vps_providers()) dna.write_dictionary() # Prepare the IRC Client irc_handler.init_irc_client() irc_handler.start_irc_client() logger.success("PlebNet is ready to roll!")
def setUp(self, mock): if os.path.isfile(test_log_file): os.remove(test_log_file) if os.path.isfile(test_child_file): os.remove(test_child_file) self.test_qtable = QTable() fake_generator.generate_child_account() global test_account test_account.read_settings(test_child_file)
def setup(args): """ This method should only be called once and is responsible for the initial setup of the PlebNet agent. All necessary configuration files are created and IRC communication is started. :param args: If running in Testnet mode. """ global qtable, config logger.log("Setting up PlebNet") # Set general info about the PlebNet agent settings.irc_nick(settings.irc_nick_def() + str(random.randint(1000, 10000))) config = PlebNetConfig() config.set('expiration_date', time.time() + TIME_ALIVE) # Prepare the QTable configuration qtable = QTable() if args.test_net: settings.wallets_testnet("1") qtable.read_dictionary({ 'proxhost': cloudomate_controller.get_vps_providers()['proxhost'] }) else: providers = cloudomate_controller.get_vps_providers() if providers.has_key('proxhost'): del providers["proxhost"] # Create QTable if it does not exist qtable.read_dictionary(providers) if args.exit_node: logger.log("Running as exitnode") settings.tribler_exitnode('1') settings.settings.write() # Prepare first child configuration fake_generator.generate_child_account() # Prepare the IRC Client irc_handler.init_irc_client() irc_handler.start_irc_client() config.save() # add learning_consumer as a consumer for qtable channel in addressbook qtable.address_book.receiver.register_consumer("qtable", learning_consumer) logger.success("PlebNet is ready to roll!")
def setup(args): """ This method should only be called once and is responsible for the initial setup of the PlebNet agent. All necessary configuration files are created and IRC communication is started. :param args: If running in Testnet mode. """ global dna, config logger.log("Setting up PlebNet") # Prepare the DNA configuration dna = DNA() if args.test_net: settings.wallets_testnet("1") settings.settings.write() dna.read_dictionary({ 'proxhost': cloudomate_controller.get_vps_providers()['proxhost'] }) else: dna.read_dictionary(cloudomate_controller.get_vps_providers()) if 'proxhost' in dna.vps.keys(): dna.remove_provider('proxhost') dna.write_dictionary() if args.exit_node: logger.log("Running as exitnode") settings.tribler_exitnode('1') # Prepare first child configuration fake_generator.generate_child_account() # Set general info about the PlebNet agent settings.irc_nick(settings.irc_nick_def() + str(random.randint(1000, 10000))) config = PlebNetConfig() config.set('expiration_date', time.time() + 30 * plebnet_settings.TIME_IN_DAY) # Prepare the IRC Client irc_handler.init_irc_client() irc_handler.start_irc_client() if dna.get_own_tree() == '': logger.log("tree set to %s" % settings.irc_nick()) dna.set_own_tree(settings.irc_nick()) config.save() logger.success("PlebNet is ready to roll!")
def attempt_purchase(): """ Check if enough money to buy a server, and if so, do so, """ (provider, option, _) = config.get('chosen_provider') provider_offer_ID = str(provider).lower() + "_" + str(option).lower() if settings.wallets_testnet(): domain = 'TBTC' else: domain = 'BTC' btc_balance = satoshi_to_btc(market_controller.get_balance(domain)) vps_price = cloudomate_controller.calculate_price(provider, option) vpn_price = cloudomate_controller.calculate_price_vpn() logger.log('Selected VPS: %s (%s), %s BTC' % (provider, option, vps_price), log_name) logger.log('Selected VPN: %s, %s BTC' % ("mullvad", vpn_price), log_name) logger.log("Balance: %s %s" % (btc_balance, domain), log_name) if btc_balance >= vps_price + vpn_price: logger.log( "Before trying to purchase VPS share current QTable with other agents" ) qtable.share_qtable() logger.log("Try to buy a new server from %s" % provider, log_name) success = cloudomate_controller.purchase_choice(config) if success == plebnet_settings.SUCCESS: # Update qtable yourself positively if you are successful qtable.update_qtable(remote_tables, provider_offer_ID, True, get_reward_qlearning()) # purchase VPN with same config if server allows for it # purchase VPN with same config if server allows for it if cloudomate_controller.get_vps_providers( )[provider].TUN_TAP_SETTINGS: attempt_purchase_vpn() elif success == plebnet_settings.FAILURE: # Update qtable provider negatively if not successful qtable.update_qtable(remote_tables, provider_offer_ID, False, get_reward_qlearning()) qtable.write_dictionary() config.increment_child_index() fake_generator.generate_child_account() config.set('chosen_provider', None) config.save()
def test_generate_child_has_content(self, mock): fake_generator.generate_child_account() account = settings.Settings() account.read_settings(test_file) self.assertIsNotNone(account.get('user', 'email')) self.assertIsNotNone(account.get('user', 'firstname')) self.assertIsNotNone(account.get('user', 'lastname')) self.assertIsNotNone(account.get('user', 'companyname')) self.assertIsNotNone(account.get('user', 'phonenumber')) self.assertIsNotNone(account.get('user', 'password')) self.assertIsNotNone(account.get('address', 'address')) self.assertIsNotNone(account.get('address', 'city')) self.assertIsNotNone(account.get('address', 'state')) self.assertIsNotNone(account.get('address', 'countrycode')) self.assertIsNotNone(account.get('address', 'zipcode')) self.assertIsNotNone(account.get('server', 'root_password')) self.assertEqual(account.get('server', 'ns1'), 'ns1') self.assertEqual(account.get('server', 'ns2'), 'ns2') self.assertIsNotNone(account.get('server', 'hostname'))
def purchase_choice(config): """ Purchase the cheapest provider in chosen_providers. If buying is successful this provider is moved to bought. In any case the provider is removed from choices. :param config: config :return: success """ (provider, option, _) = config.get('chosen_provider') provider_instance = cloudomate_providers['vps'][provider](child_account()) PlebNetConfig().increment_child_index() fake_generator.generate_child_account() wallet = TriblerWallet( plebnet_settings.get_instance().wallets_testnet_created()) c = cloudomate_providers['vps'][provider] configurations = c.get_options() option = configurations[option] transaction_hash, _ = provider_instance.purchase(wallet, option) if not transaction_hash: logger.warning("Failed to purchase server") return plebnet_settings.FAILURE # TODO: how to spot the difference? if False: logger.warning("Insufficient funds to purchase server") return plebnet_settings.UNKNOWN config.get('bought').append( (provider, transaction_hash, config.get('child_index') - 1)) config.get('transactions').append(transaction_hash) config.set('chosen_provider', None) config.save() return plebnet_settings.SUCCESS
def test_generate_child_account_file_created(self, mock): fake_generator.generate_child_account() self.assertTrue(os.path.isfile(test_file))