Example #1
0
    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)
Example #2
0
    def peer_test_complete(self, stream, download_speed, rtt, target_bytes):
        self.success = True
        stream = self.http_stream

        # Update the downstream channel estimate
        estimate.DOWNLOAD = target_bytes

        self.my_side = {
            # The server will override our timestamp
            "timestamp": utils.timestamp(),
            "uuid": self.conf.get("uuid"),
            "internal_address": stream.myname[0],
            "real_address": self.conf.get("_real_address", ""),
            "remote_address": stream.peername[0],

            "privacy_informed": self.conf.get("privacy.informed", 0),
            "privacy_can_collect": self.conf.get("privacy.can_collect", 0),
            "privacy_can_publish": self.conf.get("privacy.can_publish", 0),

            # Upload speed measured at the server
            "connect_time": rtt,
            "download_speed": download_speed,

            # OS and version info
            "neubot_version": LibVersion.to_numeric("0.4.6-rc3"),
            "platform": sys.platform,
        }

        LOG.start("BitTorrent: collecting")
        STATE.update("collect")

        s = json.dumps(self.my_side)
        stringio = StringIO.StringIO(s)

        request = Message()
        request.compose(method="POST", pathquery="/collect/bittorrent",
          body=stringio, mimetype="application/json", host=self.host_header)
        request["authorization"] = self.conf.get("_authorization", "")

        stream.send_request(request)
Example #3
0
    def connection_ready(self, stream):
        m1 = SpeedtestCollect()
        m1.client = self.conf.get("uuid", "")
        m1.timestamp = utils.timestamp()
        m1.internalAddress = stream.myname[0]
        m1.realAddress = self.conf.get("speedtest.client.public_address", "")
        m1.remoteAddress = stream.peername[0]

        m1.latency = self.conf.get("speedtest.client.latency", 0.0)
        m1.downloadSpeed = self.conf.get("speedtest.client.download", 0.0)
        m1.uploadSpeed = self.conf.get("speedtest.client.upload", 0.0)

        m1.privacy_informed = self.conf.get("privacy.informed", 0)
        m1.privacy_can_collect = self.conf.get("privacy.can_collect", 0)
        m1.privacy_can_share = self.conf.get("privacy.can_publish", 0)  # XXX

        m1.neubot_version = LibVersion.to_numeric("0.4.6-rc3")
        m1.platform = sys.platform

        m1.connectTime = sum(self.rtts) / len(self.rtts)

        s = marshal.marshal_object(m1, "text/xml")
        stringio = StringIO.StringIO(s)

        #
        # Pass a dictionary because the function does not accept
        # anymore an object
        #
        if privacy.collect_allowed(m1.__dict__):
            insertxxx(DATABASE.connection(), m1)

        request = Message()
        request.compose(method="POST", pathquery="/speedtest/collect",
                        body=stringio, mimetype="application/xml",
                        host=self.host_header)
        request["authorization"] = self.conf.get(
          "speedtest.client.authorization", "")

        stream.send_request(request)
Example #4
0
    def test_double_conversion(self):

        """
         Convert from canonical to numeric and then again to canonical
         (and viceversa) to make sure that we get what is expected.
        """

        # canonical -> numeric -> canonical
        self.assertEquals(LibVersion.to_canonical(
          LibVersion.to_numeric("133.35.71-rc19")),
          "133.35.71-rc19")

        # Same as above but check for -rc999
        self.assertEquals(LibVersion.to_canonical(
          LibVersion.to_numeric("133.35.71-rc999")),
          "133.35.71")

        # numeric -> canonical -> numeric
        self.assertEquals(LibVersion.to_numeric(
          LibVersion.to_canonical("133.035071019")),
          "133.035071019")
Example #5
0
    def process_request(self, stream, request):
        m = marshal.unmarshal_object(request.body.read(),
          "application/xml", compat.RendezvousRequest)

        m1 = 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 m.version:
            diff = LibVersion.compare(version, m.version)
            LOG.debug('rendezvous: version=%s m.version=%s diff=%f' % (
                      version, m.version, diff))
            if diff > 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.
        # 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 = m.__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.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/" % 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)
Example #6
0
TOPDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

#
# This simplifies things a lot.
#
MACOSDIR = os.sep.join([TOPDIR, "MacOS"])
os.chdir(MACOSDIR)

if __name__ == "__main__":
    sys.path.insert(0, TOPDIR)

from neubot.utils.version import LibVersion

VERSION = "0.4.6-rc3"
NUMERIC_VERSION = LibVersion.to_numeric(VERSION)

IGNORER = shutil.ignore_patterns(".DS_Store")


def __call(cmdline):
    """ exit() if the subprocess fails """
    retval = subprocess.call(shlex.split(cmdline))
    if retval != 0:
        sys.exit(1)


def _init():

    """
     Make sure we start from a clean environment and that