Esempio n. 1
0
def define_env(settings_file_path=""):
    """
    This function sets up some global variables
    """

    # Set defaults
    env.deploy_redcap_cron = False

    # first, copy the secrets file into the deploy directory
    if os.path.exists(settings_file_path):
        config.read(settings_file_path)
    else:
        print("The secrets file path cannot be found. It is set to: %s" %
              settings_file_path)
        abort("Secrets File not set")

    if utility.get_config('deploy_user', settings_file_path) != "":
        env.user = utility.get_config('deploy_user', settings_file_path)

    section = "instance"
    for (name, value) in config.items(section):
        env[name] = value
    # Set variables that do not have corresponding values in vagrant.ini file
    time = utility.timestamp()
    env.remote_project_name = '%s-%s' % (env.project_path, time)
    env.live_project_full_path = env.live_pre_path + "/" + env.project_path
    env.backup_project_full_path = env.backup_pre_path + "/" + env.project_path
    env.upload_project_full_path = env.backup_pre_path

    env.hosts = [env.host]
    env.port = env.host_ssh_port

    # Turn deploy_redcap_cron into a boolean
    env.deploy_redcap_cron = utility.is_affirmative(env.deploy_redcap_cron)
Esempio n. 2
0
def define_env(settings_file_path=""):
    """
    This function sets up some global variables
    """

    # Set defaults
    env.deploy_redcap_cron = False

    # first, copy the secrets file into the deploy directory
    if os.path.exists(settings_file_path):
        config.read(settings_file_path)
    else:
        print(("The secrets file path cannot be found. It is set to: %s" % settings_file_path))
        abort("Secrets File not set")

    utility.get_config('deploy_user', settings_file_path)

    section="instance"
    for (name,value) in config.items(section):
        env[name] = value
    # Set variables that do not have corresponding values in vagrant.ini file
    time = utility.timestamp()
    env.remote_project_name = '%s-%s' % (env.project_path,time)
    env.live_project_full_path = env.live_pre_path + "/" + env.project_path
    env.backup_project_full_path = env.backup_pre_path + "/" + env.project_path
    env.upload_project_full_path = env.backup_pre_path

    env.hosts = [env.host]
    env.port = env.host_ssh_port

    # Turn deploy_redcap_cron into a boolean
    env.deploy_redcap_cron = utility.is_affirmative(env.deploy_redcap_cron)
Esempio n. 3
0
 def __init__(self,app):
 
     self.app = app
     self.node = app.node
     self.list = utility.get_config("channels", {'#welcome': {'muted': 0}})
     self.ads = {}
     self.subs = {}
     self.cache = {} # cache the list of people wo are listening to a channel
Esempio n. 4
0
def run(experiment_suite_id, experiment_name):
    log.info(f"Run Experiment {experiment_name}")
    log.debug(f"  with test time: {config.EXP_TEST_TIME}")

    configurations = utility.get_config(f"./configs/{experiment_name}.json")
    network_test_done = False

    for exp_config in tqdm(configurations, desc=f"  {experiment_name}"):
        log.info("Start New Config")
        log.debug(f"  with exp_config: {exp_config}")

        if (not network_test_done
            ) or exp_config['n_client'] != n_client or exp_config[
                'n_middleware'] != n_middleware or exp_config[
                    'n_server'] != n_server:
            network_test_done = True
            n_server = exp_config['n_server']
            n_middleware = exp_config['n_middleware']
            n_client = exp_config['n_client']
            network_stats = network_test.execute_network_test(
                n_client=n_client, n_mw=n_middleware, n_server=n_server)

        result_ids = []

        for repetition in tqdm(range(exp_config['repetitions']),
                               desc="    rep",
                               leave=False):
            result_id = run_repetition(experiment_suite_id, experiment_name,
                                       repetition, exp_config, network_stats)
            result_ids.append(result_id)

        fail_count, total_count = quick_check.throughput_check(
            suite=experiment_suite_id,
            result_ids=result_ids,
            threshold=const.cov_threshold)
        ok_count = total_count - fail_count

        while (total_count != 0 and ok_count < 3 and total_count < 6
               ):  # repeat until we have 3 valid repetitions or max 6
            for add_rep in tqdm(range(total_count, total_count + 3 - ok_count),
                                desc="    add rep",
                                leave=False):
                log.info(
                    "Throughput check not passed -> run another repetition")
                result_id = run_repetition(experiment_suite_id,
                                           experiment_name, add_rep,
                                           exp_config, network_stats)
                result_ids.append(result_id)
            fail_count, total_count = quick_check.throughput_check(
                suite=experiment_suite_id,
                result_ids=result_ids,
                threshold=const.cov_threshold)
            ok_count = total_count - fail_count
Esempio n. 5
0
    def __init__(self, app):

        self.app = app
        self.node = app.node

        self.any_gossip_gets = 0

        self.update_requests = [ ]

        gossip_list = utility.get_config("gossip", [ ])
        self.gossip = [ ]
        for item in gossip_list:
            if type(item) != types.DictionaryType:
                print _("Warning: ignoring corrupt gossip item: "), `item`
                continue
            wodge = Wodge(item)
            wodge.adjust_decays()
            self.gossip.append(wodge)
Esempio n. 6
0
    def __init__(self, app, node, random_func):
        utility.Task_manager.__init__(self)

        self.app = app
        self.node = node

        self.key = utility.get_config("private_key",None)

        if self.key == None:
            random = random_func()
            self.key = crypto.RSA.deconstruct(crypto.RSA.generate(1024,random.randfunc))
            random.finish()
            utility.set_config("private_key",self.key)

        self.key  = crypto.RSA.construct(self.key)
        self.public_key = crypto.RSA.deconstruct(self.key.publickey())
        self.public_key_name = key_name(self.public_key)
        self.public_key_name_offline = hash.hash_of('identity-offline '+key_name(self.public_key))
        self.name   = None
        self.info   = { }
        self.status = { }    # eg chat status stored under 'chat' key

        # For searching for all people
        self.service_name = hash.hash_of("service identity")

        self.acquaintances = { }
        self.nicknames     = { }

        self.watchers      = [ ]                    #the people who are watching me
        
        self.watch_callbacks = [ ]

        self.start_time = time.time()

        self.get_info_func = lambda self=self: self.app.name_server.get_info()
        # - has to be a distinct object to allow unpublish
 
        self.aborted = 0
        self.disconnect_threads = 0

        # Proof of @R.I22: @E25
        self.check_invar()
Esempio n. 7
0
 def start(self):
     self.cache = utility.get_config("hash_cache",{ })
     utility.Task_manager.start(self)        
     self.node.add_handler('download chunk', self, ('name', 'integer', 'integer'), types.StringType)
     self.node.add_handler('files available', self)
     utility.start_thread(file_server_poll_thread(self))
import utility

exp_ids = ['exp21', 'exp22', 'exp31', 'exp32', 'exp41', 'exp51', 'exp52', 'exp60']

n_experiments = 0
n_repetitions = 4
sec_per_exp = 90

for experiment_name in exp_ids:
    configurations = utility.get_config(f"./configs/{experiment_name}.json")
    n_experiments += n_repetitions * len(configurations)

sec = n_experiments * sec_per_exp
print(f"Number of Experiments: {n_experiments}")
print(f"  with {sec_per_exp} seconds per experiment and {n_repetitions} repetitions")
print(f"=> Expected Test Time: {sec/3600} hours")
Esempio n. 9
0
    def run(self, initial_command=None, proxy_mode="none"):
        """ This is the daemon mainloop. """

        self.thread_list = utility.thread_list

        if proxy_mode == "always" or (proxy_mode == "auto" and node.need_proxy()):
            print _("Circle needs to run a proxy (see documentation).")
            print
            print _("SSH to where ([email protected])? "),
            proxy_host = sys.stdin.readline().strip()
            proxy_obj = proxy.Proxy(proxy_host)
        else:
            proxy_obj = None

        if sys.platform == "win32" or initial_command == "no-fork\n":
            fork = 0
            initial_command = "gtk\n"
        else:
            fork = 1

        if fork:
            branch = os.fork()
        else:
            branch = 0

        if not branch:
            # Note: 'print' statements are not allowed within this branch of the fork

            # os.setsid()
            sys.stdin.close()
            dev_null = open("/dev/null", "wt")
            sys.stdout.close()
            sys.stderr.close()
            sys.stdout = dev_null
            sys.stderr = dev_null

            if fork:
                com_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
                com_sock_file = os.path.join(utility.config_dir, "daemon_socket")
                try:
                    os.unlink(com_sock_file)
                except OSError:
                    pass
                com_sock.bind(com_sock_file)
                com_sock.listen(5)

            self.start()
            self.node = node.Node()
            self.node.start(proxy_obj)

            self.file_server = file_server.File_server(self.node)
            self.cache = cache.Cache(self.node)
            self.interface = None

            self.config = utility.get_config("daemon", {})
            for pair in [
                ("public_dir", ""),
                ("private_dir", ""),
                ("download_dir", ""),
                ("stay_alive", 1),
                ("http", 0),
                ("publish_apt", 0),
                ("keep_sharing", 0),
            ]:

                if not self.config.has_key(pair[0]):
                    self.config[pair[0]] = pair[1]

            self.file_server.set_roots(self.config)
            self.file_server.start()
            self.cache.start()

            # if fork:
            #    def signal_handler(signal, frame):
            #        raise error.Error('signal')
            # else:
            #    def signal_handler(signal, frame):
            #        print _("Received signal %d.") % signal

            # for s in exit_signals:
            #    signal.signal(s, signal_handler)

            self.accept_gtk = 1
            self.stopping = 0
            self.http_running = 0
            self.set_http()
            self.interface_running = 0

            if not fork:
                from ui_gtk import circle_gtk

                self.gtk_interface_requested = 1
                utility.Task(circle_gtk.gui_task, self, fork).start()
                output = sys.stdout
            else:
                self.gtk_interface_requested = 0
                gui_task_launched = 0
                while not self.stopping:
                    # at this point it cannot be 'text'
                    if initial_command:
                        command = initial_command
                        initial_command = None
                        # if command == 'text\n':
                        input = sys.stdin
                        output = sys.stdout
                        connection = None
                    else:
                        try:
                            while not select.select([com_sock], [], [], 0.1)[0]:
                                if self.stopping:
                                    break
                                try:
                                    utility._daemon_action_timeout()
                                except:
                                    apply(utility.report_bug, sys.exc_info())

                            # if stopping we need to exit the 2nd loop too:
                            if self.stopping:
                                break

                            connection = com_sock.accept()[0]
                            input = connection.makefile("rt")
                            output = connection.makefile("wt")
                            command = input.readline()
                        except:
                            apply(utility.report_bug, sys.exc_info())
                            continue

                    if command == "quit\n":
                        if self.interface_running:
                            output.write("Shutting down interface...\n")
                            self.interface.shutdown()
                        self.stopping = 1
                        break

                    if command == "shutdown\n":
                        if self.interface_running:
                            output.write("Shutting down interface...")
                            self.interface.shutdown()
                        else:
                            output.write("No interface running.")

                    elif command == "sync config\n":
                        self.config = utility.get_config("daemon", {})
                        self.file_server.set_roots(self.config)
                        output.write(_("Active circle daemon has updated its settings."))

                    elif command == "status\n":
                        str = self.status()
                        output.write(str)

                    elif command == "activate\n":
                        self.node.activate_hashtable()
                        output.write("Hashtable activated")

                    elif command == "gtk\n":

                        if not self.accept_gtk:
                            output.write("cannot run gtk interface: problem with gtk threads")
                        else:
                            if not gui_task_launched:
                                from ui_gtk import circle_gtk

                                utility.Task(circle_gtk.gui_task, self, fork).start()
                                gui_task_launched = 1

                            if not self.interface_running:
                                self.gtk_interface_requested = 1
                            else:
                                output.write("Circle interface already running")

                    elif command == "text\n":

                        def text_task(self, input, output):
                            from ui_text import circle_text
                            import settings

                            settings.terminal_encoding = sys.getdefaultencoding()
                            self.interface = circle_text.Circle_text(self, input, output)
                            self.interface.run_main()
                            self.interface_running = 0
                            # try:
                            input.close()
                            if connection:
                                connection.close()
                            output.close()
                            # except:
                            #    pass

                        if not self.interface_running:
                            self.interface_running = 1
                            output.write("Starting text interface\n")
                            utility.Task(text_task, self, input, output).start()
                        else:
                            output.write("Circle interface already running")
                            input.close()
                            if connection:
                                connection.close()
                            output.close()
                    elif command == "debug\n":
                        for item in threading.enumerate():
                            output.write(repr(item) + "\n\n")
                    elif command[0:6] == "search":
                        utility.Task(search_task, self, command[7:-1], input, output, connection).start()
                    elif command[0:4] == "find":
                        utility.Task(find_task, self, command[5:-1], input, output, connection).start()
                    elif command[0:4] == "get ":
                        utility.Task(get_file_task, self, command[4:38], input, output, connection).start()
                    elif command == "http local\n":
                        self.config["http"] = 2
                        output.write(self.set_http())
                    elif command == "http remote\n":
                        self.config["http"] = 1
                        output.write(self.set_http())
                    elif command == "http stop\n":
                        self.config["http"] = 0
                        output.write(self.set_http())
                    elif command[0:7] == "connect":
                        try:
                            address = utility.parse_address(self.node.address, command[8:-1])
                            self.node.probe(address)
                        except:
                            output.write(sys.exc_info()[1])

                    else:
                        output.write(_("Huh?"))

                    if command.split()[0] not in ["search", "find", "get", "text"]:
                        try:
                            input.close()
                            connection.close()
                            output.close()
                        except:
                            pass

            if self.accept_gtk and self.gtk_interface_requested:
                # print "waiting for interface..."
                while self.gtk_interface_requested:
                    utility._daemon_action_timeout()
                    time.sleep(0.01)
                # print "interface is down"

            # utility.threadnice_mainloop_stop()
            # except error.Error: # signal, eg ^C, SIGTERM
            #    pass

            for s in exit_signals:
                signal.signal(s, signal.SIG_IGN)

            self.cache.stop()
            self.file_server.stop()

            if self.node.hashtable_running:
                initial_links = len(self.node.links)
                self.node.deactivate_hashtable()
                while self.node.hashtable_offloaders or self.node.links:
                    utility._daemon_action_timeout()
                    time.sleep(0.01)
                    output.write(
                        "offloading : %.1f%% \r" % ((initial_links - len(self.node.links)) * 100.0 / initial_links)
                    )
                    output.flush()

            # todo: ensure that this terminates
            # node.stop() needs to be called, interrupt is bad
            if self.interface:
                if self.interface.name_server.disconnect_threads:
                    print "disconnecting identity..."
                while self.interface.name_server.disconnect_threads:
                    time.sleep(0.01)
                    utility._daemon_action_timeout()

            print "stopping node"
            self.node.stop()
            if fork:
                com_sock.close()
                os.unlink(com_sock_file)

            if self.http_running:
                circle_http.stop()

            if self.stopping:
                self.running = 0
                try:
                    if fork:
                        output.write(_("Circle daemon stopped."))
                        input.close()
                        output.flush()
                        output.close()
                        connection.close()
                except:
                    pass

            self.stop()
        else:
            print _("Circle daemon started.")