Пример #1
0
    def test_compare(self):

        """
         Make sure that LibVersion.compare() behaves ad advertised
         in comparing different version numbers.
        """

        self.assertTrue(utils_version.compare("7.5.3", "7.5.3") == 0)
        self.assertTrue(utils_version.compare("7.0", "7.5.3") < 0)
        self.assertTrue(utils_version.compare("8.0", "7.5.3") > 0)
        self.assertTrue(utils_version.compare("8.0.0", "8.0.1") < 0)
        self.assertTrue(utils_version.compare("8.0.0-rc3", "8.0.0-rc4") < 0)
        self.assertTrue(utils_version.compare("8.0.0-rc3", "8.0.0") < 0)
Пример #2
0
    def test_compare(self):
        """
         Make sure that LibVersion.compare() behaves ad advertised
         in comparing different version numbers.
        """

        self.assertTrue(utils_version.compare("7.5.3.0", "7.5.3.0") == 0)
        self.assertTrue(utils_version.compare("7.0.0.0", "7.5.3.0") < 0)
        self.assertTrue(utils_version.compare("8.0.0.0", "7.5.3.0") > 0)
        self.assertTrue(utils_version.compare("8.0.0.0", "8.0.1.0") < 0)

        # Legacy
        self.assertTrue(utils_version.compare("0.0.0-rc3", "0.0.0-rc4") < 0)
        self.assertTrue(utils_version.compare("0.0.0-rc3", "0.0.0") < 0)
Пример #3
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)
            logging.debug("rendezvous: version=%s ibody.version=%s diff=%f", version, ibody.version, diff)
            if diff > 0:
                obody.update["uri"] = "http://neubot.org/"
                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")
        logging.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:
                    logging.info("* learning new country: %s", country)
                    table_geoloc.insert_server(DATABASE.connection(), country, server)
                    servers = [server]
                server = random.choice(servers)
                logging.info("rendezvous_server: %s[%s] -> %s", agent_address, country, server)

        else:
            logging.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):
            #
            # Note: Here we will have problems if we store unquoted
            # IPv6 addresses into the database.  Because the resulting
            # URI won't be valid.
            #
            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)