Esempio n. 1
0
 def connect(self, endpoint, prefer_ipv6, sslconfig, extra):
     logging.info('runner_mlabns: server discovery... in progress')
     extra['address'] = endpoint[0]
     extra['port'] = endpoint[1]
     extra['requests'] = 0
     if extra['policy'] not in ('random', ''):
         raise RuntimeError('runner_mlabns: unknown policy')
     return HttpClient.connect(self, endpoint, prefer_ipv6, sslconfig, extra)
Esempio n. 2
0
 def handle_end_of_body(self, stream):
     HttpClient.handle_end_of_body(self, stream)
     context = stream.opaque
     extra = context.extra
     if extra['requests'] <= 0:
         raise RuntimeError('runner_mlabns: unexpected response')
     extra['requests'] -= 1
     tmp = context.headers.get(CONTENT_TYPE)
     if context.code != CODE200 or tmp != APPLICATION_JSON:
         logging.error('runner_mlabns: bad response')
         stream.close()
         return
     content = six.bytes_to_string(context.body.getvalue(), 'utf-8')
     response = json.loads(content)
     http_utils.prettyprint_json(response, '<')
     if extra['policy'] == 'random':
         RUNNER_HOSTS.set_random_host(response)
     else:
         RUNNER_HOSTS.set_closest_host(response)
     stream.close()
Esempio n. 3
0
 def handle_end_of_body(self, stream):
     # Note: this function MUST be callable multiple times
     HttpClient.handle_end_of_body(self, stream)
     context = stream.opaque
     extra = context.extra
     if extra['requests'] <= 0:
         raise RuntimeError('raw_negotiate: unexpected response')
     extra['requests'] -= 1
     tmp = context.headers.get(CONTENT_TYPE)
     if context.code != CODE200 or tmp != APPLICATION_JSON:
         logging.error('raw_negotiate: bad response')
         stream.close()
         return
     response = json.loads(six.u(context.body.getvalue()))
     http_utils.prettyprint_json(response, '<')
     if STATE.current == 'negotiate':
         self._process_negotiate_response(stream, response)
     elif STATE.current == 'collect':
         self._process_collect_response(stream, response)
     else:
         raise RuntimeError('raw_negotiate: internal error')
Esempio n. 4
0
    def connect(self, endpoint, prefer_ipv6, sslconfig, extra):

        # Reset web interface
        STATE.update('test_skype', '---', publish=False)
        STATE.update('test_name', 'skype', publish=False)
        STATE.update('negotiate')

        # Variables
        extra['address'] = endpoint[0]
        extra['authorization'] = ''
        extra['body'] = http_utils.Body()
        extra['local_result'] = None
        extra['port'] = endpoint[1]
        extra['prefer_ipv6'] = prefer_ipv6
        extra['requests'] = 0
        extra['saved_stream'] = None
        extra['final_state'] = 0

        return HttpClient.connect(self, endpoint, prefer_ipv6, sslconfig, extra)
Esempio n. 5
0
    def connect(self, endpoint, prefer_ipv6, sslconfig, extra):

        # Reset web interface
        STATE.update('test_latency', '---', publish=False)
        STATE.update('test_download', '---', publish=False)
        STATE.update('test_upload', '---', publish=False)
        STATE.update('test_progress', '0%', publish=False)
        STATE.update('test_name', 'raw', publish=False)
        STATE.update('negotiate')

        # Variables
        extra['address'] = endpoint[0]
        extra['authorization'] = ''
        extra['local_result'] = None
        extra['port'] = endpoint[1]
        extra['prefer_ipv6'] = prefer_ipv6
        extra['requests'] = 0
        extra['saved_stream'] = None
        extra['final_state'] = 0

        return HttpClient.connect(self, endpoint, prefer_ipv6, sslconfig, extra)