示例#1
0
文件: core.py 项目: codesalad/PlebNet
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!")
示例#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!")
示例#3
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!")
示例#4
0
    def test_failure(self):
        subprocess.call = self.call_false

        success = irc_handler.start_irc_client()
        self.assertFalse(success)

        success = irc_handler.stop_irc_client()
        self.assertFalse(success)

        success = irc_handler.restart_irc_client()
        self.assertFalse(success)
示例#5
0
    def test_succes(self):
        subprocess.call = self.call_true

        success = irc_handler.start_irc_client()
        self.assertTrue(success)

        success = irc_handler.stop_irc_client()
        self.assertTrue(success)

        success = irc_handler.restart_irc_client()
        self.assertTrue(success)

        success = irc_handler.status_irc_client()
        self.assertTrue(success)
示例#6
0
def check_irc():
    """
    Checks whether IRC client is running and starts it if needed.
    """
    if irc_handler.status_irc_client() != 0:
        irc_handler.start_irc_client()