Beispiel #1
0
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 test_install_available_servers(self, mock1, mock2, mock3, mock4, mock5, mock6, mock7, mock8, mock9, mock10, mock11):
        config = PlebNetConfig()
        config.get('bought').append(test_bought)
        config.save()

        server_installer.install_available_servers(config, self.test_qtable)

        self.assertEqual(config.get('installed'), [test_bought])
        self.assertEqual(config.get('bought'), [])
    def test_install_available_servers(self, mock1, mock2, mock3, mock4):
        config = PlebNetConfig()
        config.get('bought').append(test_bought)
        config.save()

        server_installer.install_available_servers(config, self.test_dna)

        self.assertEqual(config.get('installed'), [{'linevast': False}])
        self.assertEqual(config.get('bought'), [])
Beispiel #4
0
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!")
Beispiel #5
0
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!")
Beispiel #6
0
class Strategy():
    __metaclass__ = ABCMeta

    def __init__(self):
        self.config = PlebNetConfig()

    @abstractmethod
    def apply(self):
        """
        Performs the whole strategy step for one plebnet check iteration
        :return:
        """
        pass

    @abstractmethod
    def sell_reputation(self):
        """
        Sells or holds current reputation (MB) depending on the implementing strategy
        :return:
        """
        pass

    @abstractmethod
    def create_offer(self, amount_mb, timeout):
        """
        Creates a new order in the market, with parameters depending on the implementing strategy
        :return:
        """
        pass

    def get_available_mb(self):
        return market_controller.get_balance('MB')

    @staticmethod
    def get_replication_price(vps_provider, option, vpn_provider='azirevpn'):
        return (calculate_price(vps_provider, option) +
                calculate_price_vpn(vpn_provider)) * BTC_FLUCTUATION_MARGIN

    def update_offer(self, mb_amount, timeout=plebnet_settings.TIME_IN_HOUR):
        """
        Check if "timeout" has passed since the last offer made, if passed create a new offer.
        """
        if self.config.time_since_offer() > timeout:
            logger.log("Calculating new offer", log_name)
            self.config.save()
            return self.create_offer(mb_amount, timeout)

    def place_offer(self, mb_amount, chosen_est_price, timeout, config):
        """
        Sells the received MB amount for the chosen estimated price on the Tribler market.
        :param mb_amount: Amount of MB to sell
        :param config: config
        :param timeout: timeout of the offer to place
        :param chosen_est_price: Target amount of BTC to receive
        :return: success of offer placement
        """
        if chosen_est_price == 0 or mb_amount == 0:
            return False
        config.bump_offer_date()

        coin = 'TBTC' if plebnet_settings.get_instance().wallets_testnet(
        ) else 'BTC'

        config.set('last_offer', {coin: chosen_est_price, 'MB': mb_amount})

        if coin == 'TBTC':
            return market_controller.put_ask(
                first_asset_amount=mb_amount,
                first_asset_type='MB',
                second_asset_amount=btc_to_satoshi(chosen_est_price),
                second_asset_type=coin,
                timeout=timeout)
        return market_controller.put_bid(
            first_asset_amount=btc_to_satoshi(chosen_est_price),
            first_asset_type=coin,
            second_asset_amount=mb_amount,
            second_asset_type='MB',
            timeout=timeout)