def test_compare(self): """ Make sure that LibVersion.compare() behaves ad advertised in comparing different version numbers. """ self.assertTrue(LibVersion.compare("7.5.3", "7.5.3") == 0) self.assertTrue(LibVersion.compare("7.0", "7.5.3") < 0) self.assertTrue(LibVersion.compare("8.0", "7.5.3") > 0) self.assertTrue(LibVersion.compare("8.0.0", "8.0.1") < 0) self.assertTrue(LibVersion.compare("8.0.0-rc3", "8.0.0-rc4") < 0) self.assertTrue(LibVersion.compare("8.0.0-rc3", "8.0.0") < 0)
def process_request(self, stream, request): m = marshal.unmarshal_object(request.body.read(), "application/xml", compat.RendezvousRequest) m1 = compat.RendezvousResponse() version = self.conf["rendezvous.server.update_version"] # # Don't offer a release candidate update if the user is not # running a release candidate as well and viceversa. # if (("-rc" in version and "-rc" in m.version) or (not "-rc" in version and not "-rc" in m.version)): if m.version and LibVersion.compare(version, m.version) > 0: m1.update["uri"] = self.conf["rendezvous.server.update_uri"] m1.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. # 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) 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.debug("* selected test server: %s" % server) if "speedtest" in m.accept: m1.available["speedtest"] = [ "http://%s/speedtest" % server ] if "bittorrent" in m.accept: m1.available["bittorrent"] = [ "http://%s:8000/" % 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 m.version and LibVersion.compare(m.version, "0.3.7") >= 0: s = marshal.marshal_object(m1, "application/json") mimetype = "application/json" else: s = compat.adhoc_marshaller(m1) mimetype = "text/xml" stringio = StringIO.StringIO() stringio.write(s) stringio.seek(0) response = Message() response.compose(code="200", reason="Ok", mimetype=mimetype, body=stringio) stream.send_response(request, response)