Beispiel #1
0
 def _read_size(self, data):
     try:
         size = struct.unpack('>l', data)[0]
         self.stream.read_bytes(size, self._read_body)
     except Exception:
         self.close()
         self.trigger('error', nsq.IntegrityError('failed to unpack size'))
Beispiel #2
0
    def _on_identify_response(self, data, **kwargs):
        self.off('response', self._on_identify_response)

        if data == 'OK':
            logger.warning(
                'nsqd version does not support feature netgotiation')
            return self.trigger('ready', conn=self)

        try:
            data = json.loads(data)
        except ValueError:
            self.close()
            err = 'failed to parse IDENTIFY response JSON from nsqd - %r' % data
            self.trigger('error', conn=self, error=nsq.IntegrityError(err))
            return

        self.trigger('identify_response', conn=self, data=data)

        self._features_to_enable = []
        if self.tls_v1 and data.get('tls_v1'):
            self._features_to_enable.append('tls_v1')
        if self.snappy and data.get('snappy'):
            self._features_to_enable.append('snappy')
        if self.deflate and data.get('deflate'):
            self._features_to_enable.append('deflate')

        if data.get('auth_required'):
            self._authentication_required = True

        self.on('response', self._on_response_continue)
        self._on_response_continue(conn=self, data=None)
Beispiel #3
0
    def _on_auth_response(self, data, **kwargs):
        try:
            data = json.loads(data)
        except ValueError:
            self.close()
            err = 'failed to parse AUTH response JSON from nsqd - %r' % data
            self.trigger('error', conn=self, error=nsq.IntegrityError(err))
            return

        self.off('response', self._on_auth_response)
        self.trigger('auth_response', conn=self, data=data)
        return self.trigger('ready', conn=self)
Beispiel #4
0
    def _on_identify_response(self, data, **kwargs):
        self.off('response', self._on_identify_response)

        if data == 'OK':
            return self.trigger('ready', conn=self)

        try:
            data = json.loads(data)
        except ValueError:
            self.close()
            err = 'failed to parse IDENTIFY response JSON from nsqd - %r' % data
            self.trigger('error', conn=self, error=nsq.IntegrityError(err))
            return

        self.trigger('identify_response', conn=self, data=data)

        self._features_to_enable = []
        if self.tls_v1 and data.get('tls_v1'):
            self._features_to_enable.append('tls_v1')
        if self.snappy and data.get('snappy'):
            self._features_to_enable.append('snappy')

        self.on('response', self._on_response_continue)
        self._on_response_continue(conn=self, data=None)