Exemplo n.º 1
0
    def got_response(self, stream, request, response):
        if response.code != "200":
            LOG.complete("bad response")
            self._schedule()
        else:
            LOG.complete()
            s = response.body.read()
            try:
                m1 = marshal.unmarshal_object(s, "application/json", compat.RendezvousResponse)
            except ValueError:
                LOG.exception()
                self._schedule()
            else:
                if "version" in m1.update and "uri" in m1.update:
                    ver, uri = m1.update["version"], m1.update["uri"]
                    LOG.info("Version %s available at %s" % (ver, uri))
                    STATE.update("update", {"version": ver, "uri": uri})
                    _open_browser_on_windows("update.html")

                # Update tests known by the runner
                runner_lst.update(m1.available)

                #
                # Choose the test we would like to run even if
                # we're not going to run it because we're running
                # in debug mode or tests are disabled.
                # This allows us to print to the logger the test
                # we /would/ have choosen if we were allowed to run
                # it.
                #
                test = runner_lst.get_next_test()
                if not test:
                    LOG.warning("No test available")
                    self._schedule()
                    return

                LOG.info("* Chosen test: %s" % test)

                # Are we allowed to run a test?
                if not CONFIG["enabled"] or CONFIG["rendezvous.client.debug"]:
                    LOG.info("Tests are disabled... not running")
                    self._schedule()
                else:

                    # Do we have negotiate URI for test?
                    negotiate_uri = runner_lst.test_to_negotiate_uri(test)
                    if not negotiate_uri:
                        LOG.warning("No negotiate URI for test")
                        self._schedule()
                    else:

                        # Actually run the test
                        runner_core.run(test, negotiate_uri, self._schedule)
Exemplo n.º 2
0
    def got_request_headers(self, stream, request):
        ret = True
        TRACKER.register_connection(stream, request["authorization"])

        if request.uri == "/speedtest/upload":
            request.body.write = lambda octets: None

        only_auth = self.conf.get("speedtest.negotiate.auth_only", False)
        if (only_auth and request.uri != "/speedtest/negotiate" and
          not TRACKER.session_active(request["authorization"])):
            LOG.warning("* Connection %s: Forbidden" % stream.logname)
            ret = False

        return ret
Exemplo n.º 3
0
    def collect_legacy(self, stream, request_body, request):
        ''' Invoked when we must save the result of a session '''
        ident = str(hash(stream))
        if ident not in self.clients:
            #
            # Before Neubot 0.4.2 we were using multiple connections
            # for speedtest, which were used both for testing and for
            # negotiating/collecting.  Sometimes the connection used
            # to collect is not the one used to negotiate: the code
            # uses the one that terminates the upload first.
            # When this happens we inspect the Authorization header
            # before deciding the collect request is an abuse.
            #
            authorization = request['Authorization']
            if authorization not in self.clients:
                raise RuntimeError('Not authorized to collect')
            else:
                LOG.warning('speedtest: working around multiple conns issue')
                ident = authorization

        # Note: no more than one collect per session
        self.clients.remove(ident)

        #
        # Backward compatibility: the variable name changed from
        # can_share to can_publish after Neubot 0.4.5
        #
        if 'privacy_can_share' in request_body:
            request_body['privacy_can_publish'] = request_body[
              'privacy_can_share']
            del request_body['privacy_can_share']

        if privacy.collect_allowed(request_body):
            table_speedtest.insert(DATABASE.connection(), request_body)
        else:
            LOG.warning('* bad privacy settings: %s' % str(stream))

        return {}
Exemplo n.º 4
0
 def accept_failed(self, listener, exception):
     ''' Print a warning if accept() fails (often due to SSL) '''
     LOG.warning("ServerHTTP: accept() failed: %s" % str(exception))
Exemplo n.º 5
0
 def accept_failed(self, listener, exception):
     LOG.warning("ServerHTTP: accept() failed: %s" % str(exception))
Exemplo n.º 6
0
    logging.info("INFO w/ logging.info")
    # The following should work because it should not interpolate
    logging.debug("DEBUG w/ logging.debug", "ciao")
    logging.warning("WARNING w/ logging.warning")
    logging.error("ERROR w/ logging.error")

    LOG.verbose()

    logging.info("INFO w/ logging.info")
    logging.debug("DEBUG w/ logging.debug")
    logging.warning("WARNING w/ logging.warning")
    logging.error("ERROR w/ logging.error")

    LOG.error("testing neubot logger -- This is an error message")
    LOG.warning("testing neubot logger -- This is an warning message")
    LOG.info("testing neubot logger -- This is an info message")
    LOG.debug("testing neubot logger -- This is a debug message")
    print compat.json.dumps(LOG.listify())

    try:
        raise Exception("Testing LOG.exception")
    except (KeyboardInterrupt, SystemExit):
        raise
    except:
        LOG.exception()
        LOG.exception(func=LOG.warning)

    LOG.start("Testing the in-progress feature")
    LOG.progress("...")
    LOG.progress()
Exemplo n.º 7
0
    def got_response(self, stream, request, response):
        if response.code != "200":
            LOG.complete("bad response")
            self._schedule()
        else:
            LOG.complete()
            s = response.body.read()
            try:
                m1 = marshal.unmarshal_object(s, "application/json",
                  compat.RendezvousResponse)
            except ValueError:
                LOG.exception()
                self._schedule()
            else:
                if "version" in m1.update and "uri" in m1.update:
                    ver, uri = m1.update["version"], m1.update["uri"]
                    LOG.info("Version %s available at %s" % (ver, uri))
                    STATE.update("update", {"version": ver, "uri": uri})

                #
                # Choose the test we would like to run even if
                # we're not going to run it because we're running
                # in debug mode or tests are disabled.
                # This allows us to print to the logger the test
                # we /would/ have choosen if we were allowed to run
                # it.
                #
                tests = []
                if "speedtest" in m1.available:
                    tests.append("speedtest")
                if "bittorrent" in m1.available:
                    tests.append("bittorrent")
                #XXX alternate the two tests
                if self._latest:
                    tests.remove(self._latest)
                test = random.choice(tests)
                self._latest = test
                LOG.info("* Chosen test: %s" % test)

                # Are we allowed to run a test?
                if not CONFIG["enabled"] or CONFIG["rendezvous.client.debug"]:
                    LOG.info("Tests are disabled... not running")
                    self._schedule()
                else:

                    if (CONFIG["privacy.informed"] and
                      not CONFIG["privacy.can_collect"]):
                        LOG.warning("cannot run test without permission "
                          "to save the results")
                        self._schedule()
                    else:

                        conf = self.conf.copy()

                        #
                        # Subscribe _before_ connecting.  This way we
                        # immediately see "testdone" if the connection fails
                        # and we can _schedule the next attempt.
                        #
                        NOTIFIER.subscribe("testdone", lambda *a, **kw: \
                                                         self._schedule())

                        if test == "speedtest":
                            conf["speedtest.client.uri"] =  m1.available[
                                                              "speedtest"][0]
                            client = ClientSpeedtest(POLLER)
                            client.configure(conf)
                            client.connect_uri()

                        elif test == "bittorrent":
                            conf["bittorrent._uri"] =  m1.available[
                                                        "bittorrent"][0]
                            bittorrent.run(POLLER, conf)

                        else:
                            NOTIFIER.publish("testdone")
Exemplo n.º 8
0
def complain():
    ''' Complain with the user about privacy settings '''
    LOG.warning('Neubot is disabled because privacy settings are not OK.')
    LOG.warning('Please, set privacy settings via web user interface.')
    LOG.warning('Alternatively, you can use the `neubot privacy` command.')
Exemplo n.º 9
0
 def __init__(self, key):
     LOG.warning("arcfour: ARC4 support not available")
     self.key = key
Exemplo n.º 10
0
    def process_request(self, stream, request):
        ''' Process rendezvous request '''

        if request['content-type'] == 'application/json':
            ibody = marshal.unmarshal_object(request.body.read(),
              'application/json', compat.RendezvousRequest)
        else:
            ibody = marshal.unmarshal_object(request.body.read(),
              "application/xml", compat.RendezvousRequest)

        obody = compat.RendezvousResponse()

        #
        # If we don't say anything the rendezvous server is not
        # going to prompt for updates.  We need to specify the
        # updated version number explicitly when we start it up.
        # This should guarantee that we do not advertise -rc
        # releases and other weird things.
        #
        version = self.conf["rendezvous.server.update_version"]
        if version and ibody.version:
            diff = utils_version.compare(version, ibody.version)
            LOG.debug('rendezvous: version=%s ibody.version=%s diff=%f' % (
                      version, ibody.version, diff))
            if diff > 0:
                obody.update["uri"] = self.conf["rendezvous.server.update_uri"]
                obody.update["version"] = version

        #
        # Select test server address.
        # The default test server is the master server itself.
        # If we know the country, lookup the list of servers for
        # that country in the database.
        # We only redirect to other servers clients that have
        # agreed to give us the permission to publish, in order
        # to be compliant with M-Lab policy.
        # If there are no servers for that country, register
        # the master server for the country so that we can notice
        # we have new users and can take the proper steps to
        # deploy nearby servers.
        #
        server = self.conf.get("rendezvous.server.default",
                               "master.neubot.org")
        LOG.debug("* default test server: %s" % server)

        #
        # Backward compatibility: the variable name changed from
        # can_share to can_publish after Neubot 0.4.5
        #
        request_body = ibody.__dict__.copy()
        if 'privacy_can_share' in request_body:
            request_body['privacy_can_publish'] = request_body[
              'privacy_can_share']
            del request_body['privacy_can_share']

        # Redirect IFF have ALL privacy permissions
        if privacy.count_valid(request_body, 'privacy_') == 3:
            agent_address = stream.peername[0]
            country = GEOLOCATOR.lookup_country(agent_address)
            if country:
                servers = table_geoloc.lookup_servers(DATABASE.connection(),
                                                      country)
                if not servers:
                    LOG.info("* learning new country: %s" % country)
                    table_geoloc.insert_server(DATABASE.connection(),
                                               country, server)
                    servers = [server]
                server = random.choice(servers)
                LOG.info("rendezvous_server: %s[%s] -> %s", agent_address,
                         country, server)

        else:
            LOG.warning('rendezvous_server: cannot redirect to M-Lab: %s',
                        request_body)

        #
        # We require at least informed and can_collect since 0.4.4
        # (released 25 October 2011), so stop clients with empty
        # privacy settings, who were still using master.
        #
        if privacy.collect_allowed(request_body):
            if "speedtest" in ibody.accept:
                obody.available["speedtest"] = [
                    "http://%s/speedtest" % server ]

            if "bittorrent" in ibody.accept:
                obody.available["bittorrent"] = [ "http://%s/" % server ]

        #
        # Neubot <=0.3.7 expects to receive an XML document while
        # newer Neubots want a JSON.  I hope old clients will upgrade
        # pretty soon.
        #
        if ibody.version and utils_version.compare(ibody.version, "0.3.7") >= 0:
            body = marshal.marshal_object(obody, "application/json")
            mimetype = "application/json"
        else:
            body = compat.adhoc_marshaller(obody)
            mimetype = "text/xml"

        response = Message()
        response.compose(code="200", reason="Ok",
          mimetype=mimetype, body=body)
        stream.send_response(request, response)
Exemplo n.º 11
0
 def got_have(self, index):
     if self.state != UPLOADING:
         raise RuntimeError("HAVE when state != UPLOADING")
     self.peer_bitfield[index] = 1
     # We don't use HAVE messages at the moment
     LOG.warning("Ignoring unexpected HAVE message")