示例#1
0
def main(args):

    CONFIG.register_descriptions({
        "speedtest.client.uri": "Base URI to connect to",
        "speedtest.client.nconn": "Number of concurrent connections to use",
        "speedtest.client.latency_tries": "Number of latency measurements",
    })

    common.main("speedtest.client", "Speedtest client", args)
    conf = CONFIG.copy()

    #
    # If possible use the runner, which will execute the
    # test in the context of the neubot daemon.  Then exit
    # to bypass the POLLER.loop() invokation that is below
    # here.
    # If the runner fails, fallback to the usual code path,
    # which executes the test in the context of the local
    # process.
    # Set 'runned.enabled' to 0 to bypass the runner and
    # run the test locally.
    #
    if (utils.intify(conf['runner.enabled']) and
        runner_clnt.runner_client(conf["agent.api.address"],
                                  conf["agent.api.port"],
                                  LOG.noisy, "speedtest")):
        sys.exit(0)

    LOG.info('Will run the test in the local context...')

    client = ClientSpeedtest(POLLER)
    client.configure(conf)
    client.connect_uri()
    POLLER.loop()
示例#2
0
def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], "6A:np:vy")
    except getopt.error:
        sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]")
    if arguments:
        sys.exit("usage: neubot skype [-6nvy] [-A address] [-p port]")

    prefer_ipv6 = 0
    # address = 'master.neubot.org'
    address = "localhost"
    runner = 1
    port = 8080
    noisy = 0
    fakeprivacy = 0
    for name, value in options:
        if name == "-6":
            prefer_ipv6 = 1
        elif name == "-A":
            address = value
        elif name == "-n":
            runner = 0
        elif name == "-p":
            port = int(value)
        elif name == "-v":
            noisy = 1
        elif name == "-y":
            fakeprivacy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning("skype: database file is missing: %s", DATABASE.path)
        BACKEND.use_backend("null")
    if noisy:
        log.set_verbose()
    if runner:
        result = runner_clnt.runner_client(
            CONFIG["agent.api.address"], CONFIG["agent.api.port"], CONFIG["verbose"], "skype"
        )
        if result:
            sys.exit(0)

    logging.info("skype: running the test in the local process context...")
    if not fakeprivacy and not privacy.allowed_to_run():
        privacy.complain()
        logging.info("skype: otherwise use -y option to temporarily provide " "privacy permissions")
        sys.exit(1)

    handler = SkypeNegotiate()
    handler.connect((address, port), prefer_ipv6, 0, {})
    POLLER.loop()
示例#3
0
def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], "6A:fp:v")
    except getopt.error:
        sys.exit("usage: neubot speedtest [-6fv] [-A address] [-p port]")
    if arguments:
        sys.exit("usage: neubot speedtest [-6fv] [-A address] [-p port]")

    prefer_ipv6 = 0
    address = "master.neubot.org"
    force = 0
    port = 8080
    noisy = 0
    for name, value in options:
        if name == "-6":
            prefer_ipv6 = 1
        elif name == "-A":
            address = value
        elif name == "-f":
            force = 1
        elif name == "-p":
            port = int(value)
        elif name == "-v":
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning("speedtest: database file is missing: %s", DATABASE.path)
        BACKEND.use_backend("null")
    if noisy:
        log.set_verbose()

    conf = CONFIG.copy()
    conf["speedtest.client.uri"] = "http://%s:%d/" % (address, port)
    conf["prefer_ipv6"] = prefer_ipv6

    if not force:
        if runner_clnt.runner_client(conf["agent.api.address"], conf["agent.api.port"], CONFIG["verbose"], "speedtest"):
            sys.exit(0)
        logging.warning("speedtest: failed to contact Neubot; is Neubot running?")
        sys.exit(1)

    logging.info("speedtest: run the test in the local process context...")
    client = ClientSpeedtest(POLLER)
    client.configure(conf)
    client.connect_uri()
    POLLER.loop()
示例#4
0
def main(args):
    ''' Main function '''
    try:
        options, arguments = getopt.getopt(args[1:], '6A:fp:v')
    except getopt.error:
        sys.exit('usage: neubot raw [-6fv] [-A address] [-p port]')
    if arguments:
        sys.exit('usage: neubot raw [-6fv] [-A address] [-p port]')

    prefer_ipv6 = 0
    address = 'master.neubot.org'
    force = 0
    port = 8080
    noisy = 0
    for name, value in options:
        if name == '-6':
            prefer_ipv6 = 1
        elif name == '-A':
            address = value
        elif name == '-f':
            force = 1
        elif name == '-p':
            port = int(value)
        elif name == '-v':
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning('raw: database file is missing: %s', DATABASE.path)
        BACKEND.use_backend('null')
    if noisy:
        log.set_verbose()

    if not force:
        result = runner_clnt.runner_client(CONFIG['agent.api.address'],
          CONFIG['agent.api.port'], CONFIG['verbose'], 'raw')
        if result:
            sys.exit(0)
        logging.warning('raw: failed to contact Neubot; is Neubot running?')
        sys.exit(1)

    logging.info('raw: run the test in the local process context...')
    handler = RawNegotiate()
    handler.connect((address, port), prefer_ipv6, 0, {})
    POLLER.loop()
示例#5
0
def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], "6A:b:d:flnp:v")
    except getopt.error:
        sys.exit(USAGE)
    if arguments:
        sys.exit(USAGE)

    prefer_ipv6 = 0
    address = "127.0.0.1"
    backend = "volatile"
    datadir = None  # means: pick the default
    force = 0
    listen = 0
    negotiate = 1
    port = 80
    noisy = 0
    for name, value in options:
        if name == "-6":
            prefer_ipv6 = 1
        elif name == "-A":
            address = value
        elif name == "-b":
            backend = value
        elif name == "-d":
            datadir = value
        elif name == "-f":
            force = 1
        elif name == "-l":
            listen = 1
        elif name == "-n":
            negotiate = 0
        elif name == "-p":
            port = int(value)
        elif name == "-v":
            noisy = 1

    if noisy:
        log.set_verbose()

    conf = CONFIG.copy()

    BACKEND.use_backend(backend)
    BACKEND.datadir_init(None, datadir)

    if listen:
        if not negotiate:
            server = DASHServerSmpl(POLLER)
            server.configure(conf)
            server.listen((address, port))

        else:
            # Code adapted from neubot/server.py

            conf["http.server.rootdir"] = ""
            server = ServerHTTP(POLLER)
            server.configure(conf)
            server.listen((address, port))

            negotiate_server = NegotiateServer(POLLER)
            negotiate_server.configure(conf)
            server.register_child(negotiate_server, "/negotiate")
            server.register_child(negotiate_server, "/collect")

            dash_negotiate_server = DASHNegotiateServer()
            negotiate_server.register_module("dash", dash_negotiate_server)

            dash_server = DASHServerGlue(POLLER, dash_negotiate_server)
            dash_server.configure(conf)
            server.register_child(dash_server, "/dash")

    elif not force:
        result = runner_clnt.runner_client(CONFIG["agent.api.address"],
          CONFIG["agent.api.port"], CONFIG["verbose"], "dash")
        if result:
            sys.exit(0)
        logging.warning("dash: failed to contact Neubot; is Neubot running?")
        sys.exit(1)

    else:
        if negotiate:
            client = DASHNegotiateClient(POLLER)
        else:
            client = DASHClientSmpl(POLLER, None, DASH_RATES)
        client.configure(conf)
        client.connect((address, port))

    POLLER.loop()
示例#6
0
def main(args):

    config.register_descriptions()
    common.main("bittorrent", "Neubot BitTorrent module", args)
    conf = CONFIG.copy()
    config.finalize_conf(conf)

    if conf["bittorrent.listen"]:

        #
        # If we need to negotiate and we're runing
        # standalone we also need to bring up the
        # global HTTP server.
        #
        if conf["bittorrent.negotiate"]:
            HTTP_SERVER.configure(conf)
            HTTP_SERVER.listen((conf["bittorrent.address"],
                               conf["bittorrent.negotiate.port"]))
            conf["negotiate.listen"] = True
            negotiate.run(POLLER, conf)

        #
        # Drop privileges after listen() so we can
        # bind() to privileged ports
        #
        if conf["bittorrent.daemonize"]:
            system.change_dir()
            system.go_background()
            LOG.redirect()

        system.drop_privileges(LOG.error)

    else:

        #
        # If possible use the runner, which will execute the
        # test in the context of the neubot daemon.  Then exit
        # to bypass the run() invokation that is below here.
        # If the runner fails, fallback to the usual code path,
        # which executes the test in the context of the local
        # process.
        # Set 'runned.enabled' to 0 to bypass the runner and
        # run the test locally.
        #
        if (utils.intify(conf['runner.enabled']) and
            runner_clnt.runner_client(conf["agent.api.address"],
                                      conf["agent.api.port"],
                                      LOG.noisy, "bittorrent")):
            sys.exit(0)

        LOG.info('Will run the test in the local context...')

        #
        # When we're connecting to a remote host to perform a test
        # we want Neubot to quit at the end of the test.  When this
        # happens the test code publishes the "testdone" event, so
        # here we prepare to intercept the event and break our main
        # loop.
        #
        NOTIFIER.subscribe("testdone", lambda event, ctx: POLLER.break_loop())

    run(POLLER, conf)

    POLLER.loop()
示例#7
0
def main(args):
    """ Main function """
    try:
        options, arguments = getopt.getopt(args[1:], '6A:fp:v')
    except getopt.error:
        sys.exit('usage: neubot speedtest [-6fv] [-A address] [-p port]')
    if arguments:
        sys.exit('usage: neubot speedtest [-6fv] [-A address] [-p port]')

    prefer_ipv6 = 0
    address = 'master.neubot.org'
    force = 0
    port = 8080
    noisy = 0
    for name, value in options:
        if name == '-6':
            prefer_ipv6 = 1
        elif name == '-A':
            address = value
        elif name == '-f':
            force = 1
        elif name == '-p':
            port = int(value)
        elif name == '-v':
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning('speedtest: database file is missing: %s',
                        DATABASE.path)
        BACKEND.use_backend('null')
    if noisy:
        log.set_verbose()

    conf = CONFIG.copy()
    conf["speedtest.client.uri"] = "http://%s:%d/" % (address, port)
    conf["prefer_ipv6"] = prefer_ipv6

    if not force:
        if runner_clnt.runner_client(conf["agent.api.address"],
                                     conf["agent.api.port"],
                                     CONFIG['verbose'],
                                     "speedtest"):
            sys.exit(0)
        logging.warning(
          'speedtest: failed to contact Neubot; is Neubot running?')
        sys.exit(1)

    logging.info('speedtest: run the test in the local process context...')
    client = ClientSpeedtest(POLLER)
    client.configure(conf)

    #
    # XXX Quick and dirty fix such that `neubot speedtest` when
    # there is no daemon running considers both the master and
    # the backup master server.  At the same time, respect user
    # choices if she overrides the default URI.
    #
    if CONFIG['speedtest.client.uri'] == 'http://master.neubot.org/':
        client.connect(('localhost', 8080))
    else:
        client.connect_uri()

    POLLER.loop()
示例#8
0
def main(args):
    '''
     This function is invoked when the user wants
     to run precisely this module.
    '''

    try:
        options, arguments = getopt.getopt(args[1:], '6A:fp:v')
    except getopt.error:
        sys.exit('usage: neubot bittorrent [-6fv] [-A address] [-p port]')
    if arguments:
        sys.exit('usage: neubot bittorrent [-6fv] [-A address] [-p port]')

    prefer_ipv6 = 0
    address = 'master.neubot.org'
    force = 0
    port = 6881
    noisy = 0
    for name, value in options:
        if name == '-6':
            prefer_ipv6 = 1
        elif name == '-A':
            address = value
        elif name == '-f':
            force = 1
        elif name == '-p':
            port = int(value)
        elif name == '-v':
            noisy = 1

    if os.path.isfile(DATABASE.path):
        DATABASE.connect()
        CONFIG.merge_database(DATABASE.connection())
    else:
        logging.warning('bittorrent: database file is missing: %s',
                        DATABASE.path)
        BACKEND.use_backend('null')
    if noisy:
        log.set_verbose()

    config.register_descriptions()  # Needed?
    conf = CONFIG.copy()
    config.finalize_conf(conf)

    conf['bittorrent.address'] = address
    conf['bittorrent.port'] = port
    conf['prefer_ipv6'] = prefer_ipv6

    if not force:
        if runner_clnt.runner_client(conf["agent.api.address"],
                                     conf["agent.api.port"],
                                     CONFIG['verbose'],
                                     "bittorrent"):
            sys.exit(0)
        logging.warning(
          'bittorrent: failed to contact Neubot; is Neubot running?')
        sys.exit(1)

    logging.info('bittorrent: run the test in the local process context...')

    #
    # When we're connecting to a remote host to perform a test
    # we want Neubot to quit at the end of the test.  When this
    # happens the test code publishes the "testdone" event, so
    # here we prepare to intercept the event and break our main
    # loop.
    #
    NOTIFIER.subscribe("testdone", lambda event, ctx: POLLER.break_loop())
    run(POLLER, conf)
    POLLER.loop()