Example #1
0
 def msg_general(self):
     qtable = QTable()
     qtable.read_dictionary()
     data = {
         'host': qtable.self_state.provider,
         'option': qtable.self_state.option,
         'vpn': vpn_is_running(),
         'tree': qtable.tree,
         'exitnode': plebnet_settings.get_instance().tribler_exitnode()
     }
     self.send_msg("general: %s" % data)
Example #2
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!")
Example #3
0
def pick_provider(providers):
    """
    This method picks a provider based on the DNA o the agent.
    :param providers:
    :return:
    """
    from plebnet.agent.qtable import QTable

    qtable = QTable()
    qtable.read_dictionary(providers)
    chosen_option = qtable.choose_option(providers)

    gateway = get_vps_providers()[chosen_option["provider_name"]].get_gateway()
    btc_price = gateway.estimate_price(wallet_util.get_price(chosen_option["price"], chosen_option["currency"]))

    return chosen_option["provider_name"], chosen_option["option_name"], btc_price
Example #4
0
    def msg_qtable(self):
        qtable = QTable()
        qtable.read_dictionary()
        headers = ["-"]
        table = []
        header_dict = {}
        # get all the available vps options
        for k, v in qtable.qtable.items():
            shorter_item = k.split(" ")[0].split("_")[0] + "1"
            num = 1
            while shorter_item in headers:
                num += 1
                shorter_item = shorter_item.replace(shorter_item[-1], str(num))
            headers.append(shorter_item)
            header_dict[k] = shorter_item

        # get the rest of the table
        index = 0
        for k, v in qtable.qtable.items():
            table.append([header_dict[k]])
            for k2, v2 in v.items():
                table[index].append(str(v2))
            index += 1

        # get the format string used for each line in the table
        formatt = "{:<%i} "
        max_len = 20
        for vps_service in headers[1:]:
            max_len = max(len(vps_service) + 2, max_len)
            formatt += "{:<%i} " % max(20, (len(vps_service) + 2))
        formatt = formatt % max_len
        formatt = formatt[:-1]
        headers[0] *= (max_len - 2)

        # send individual messages for each line of the qtable
        # , because IRC only supports up until 512 characters per message
        self.send_msg(formatt.format(*headers))
        # message = formatt.format(*headers)
        time.sleep(3)
        for line in table:
            time.sleep(3)
            # message += formatt.format(*line)
            self.send_msg(formatt.format(*line))
Example #5
0
def check():
    """
    The method is the main function which should run periodically. It controls the behaviour of the agent,
    starting Tribler and buying servers.
    """
    global config, qtable
    global sold_mb_tokens, previous_mb_tokens
    logger.log("Checking PlebNet", log_name)

    # Read general configuration
    if settings.wallets_testnet_created():
        os.environ['TESTNET'] = '1'
    config = PlebNetConfig()
    qtable = QTable()
    qtable.read_dictionary()
    # check if own vpn is installed before continuing
    if not check_vpn_install():
        logger.error("!!! VPN is not installed, child may get banned !!!",
                     "Plebnet Check")

    # Requires time to setup, continue in the next iteration.
    if not check_tribler():
        return

    check_irc()

    if not settings.wallets_initiate_once():
        create_wallet()

    select_provider()

    # if is going to die, move all currency to a wallet
    if config.time_to_expiration() < plebnet_settings.TIME_IN_HOUR:
        save_all_currency()

    # These need a matchmaker, otherwise agent will be stuck waiting.
    if market_controller.has_matchmakers():
        strategies[plebnet_settings.get_instance().strategy_name()]().apply()

    install_vps()