def collect(self, stream, request_body): """ Invoked when we must save the result of a session """ sha256 = self._stream_to_sha256(stream) if sha256 not in self.peers: raise RuntimeError("dash: not authorized: %s", sha256) # Note: no more than one collect per session result = self.peers.pop(sha256) logging.debug("dash: del sha256 (OK): %s", sha256) server_timestamp = utils.timestamp() BACKEND.store_generic("dash", { "srvr_schema_version": 3, "srvr_timestamp": server_timestamp, "client": request_body, "server": result, }) # # Return back, at a minimum, the server timestamp. # TODO Also gather and return Web100 stats. # for index in range(len(request_body)): if index <= len(result): result.append({}) result[index]["timestamp"] = server_timestamp return result
def got_response(self, stream, request, response): if response.code != "200": logging.warning("dash: http request error: %s", response.code) stream.close() return if self.state == STATE_NEGOTIATE: response_body = json.load(response.body) # # Note: the following are the standard fields that # the negotiate API call MUST return. # self.authorization = response_body["authorization"] self.queue_pos = response_body["queue_pos"] self.real_address = response_body["real_address"] self.unchoked = response_body["unchoked"] if not self.unchoked: logging.info("dash: negotiate... done (queue pos %d)", self.queue_pos) STATE.update("negotiate", {"queue_pos": self.queue_pos}) self.connection_ready(stream) return logging.info("dash: negotiate... done (unchoked)") self.stream = stream # # The server may override the vector of rates with a "better" # vector of rates of its choice. # rates = list(response_body.get("dash_rates", DASH_RATES)) self.client = DASHClientSmpl(self.poller, self, rates) self.client.configure(self.conf.copy()) self.client.connect((self.stream.peername[0], 80)) # XXX elif self.state == STATE_COLLECT: response_body = json.load(response.body) # # We store each iteration of the test as a separate row of # the backend. We also add a whole test timestamp, to allow # one to understand which row belong to the same test. # whole_test_timestamp = utils.timestamp() for index, elem in enumerate(self.measurements): elem["clnt_schema_version"] = 3 elem["whole_test_timestamp"] = whole_test_timestamp if index < len(response_body): elem["srvr_data"] = response_body[index] BACKEND.store_generic("dash", elem) stream.close() else: raise RuntimeError("dash: internal error")