コード例 #1
0
    def datagram_received(self, data, addr):
        try:
            reply = Packet(packet=data, dict=self.client.dict)

            if reply and reply.id in self.pending_requests:
                req = self.pending_requests[reply.id]
                packet = req['packet']

                reply.dict = packet.dict
                reply.secret = packet.secret

                if packet.VerifyReply(reply, data):
                    req['future'].set_result(reply)
                    # Remove request for map
                    del self.pending_requests[reply.id]
                else:
                    self.logger.warn(
                        '[%s:%d] Ignore invalid reply for id %d. %s',
                        self.server, self.port, reply.id)
            else:
                self.logger.warn('[%s:%d] Ignore invalid reply: %d',
                                 self.server, self.port, data)

        except Exception as exc:
            self.logger.error('[%s:%d] Error on decode packet: %s',
                              self.server, self.port, exc)
コード例 #2
0
ファイル: client_async.py プロジェクト: MikhailMS/pyrad
    def datagram_received(self, data, addr):
        try:
            reply = Packet(packet=data, dict=self.client.dict)
            self.logger.info(reply)

            if reply and reply.id in self.pending_requests:
                self.logger.info('Request found')
                req = self.pending_requests[reply.id]
                packet = req['packet']

                reply.dict = packet.dict
                reply.secret = packet.secret

                if packet.VerifyReply(reply, data):
                    req['future'].set_result(reply)
                    # Remove request for map
                    del self.pending_requests[reply.id]
                else:
                    self.logger.warn(
                        '[{}:{}] Ignore invalid reply for id {}'.format(
                            self.server, self.port, reply.id))
            else:
                self.logger.info('Request was not found')
                try:
                    self.logger.warn('[{}:{}] Ignore invalid reply: {}'.format(
                        self.server, self.port, data.decode('utf-8')))
                except:
                    self.logger.warn('[{}:{}] Ignore invalid reply: {}'.format(
                        self.server, self.port, data))

        except Exception as exc:
            self.logger.error('[{}:{}] Error on decode packet: {}'.format(
                self.server, self.port, exc))
コード例 #3
0
ファイル: client_async.py プロジェクト: lemquoc/pyrad
    def datagram_received(self, data, addr):

        socket = self.transport.get_extra_info('socket') \
            if self.transport else None
        try:

            received_date = datetime.now()
            reply = Packet(packet=data,
                           dict=self.client.dict,
                           creation_date=received_date)

            if reply is not None and reply.id in self.pending_requests:
                req = self.pending_requests[reply.id]
                packet = req['packet']

                reply.secret = packet.secret

                if packet.VerifyReply(reply, data):

                    if reply.message_authenticator and not \
                        reply.verify_message_authenticator(
                            original_authenticator=packet.authenticator):
                        self.logger.warn(
                            '[%s:%d:%d] Received invalid reply for id %d. %s' %
                            (self.server, self.port, socket.getsockname()[1]
                             if socket else '', reply.id,
                             'Invalid Message-Authenticator. Ignoring it.'))
                        self.errors += 1
                    else:

                        req['future'].set_result(reply)
                        # Remove request for map
                        del self.pending_requests[reply.id]
                else:
                    self.logger.warn(
                        '[%s:%d:%d] Received invalid reply for id %d. %s' %
                        (self.server, self.port, socket.getsockname()[1]
                         if socket else '', reply.id, 'Ignoring it.'))
                    self.errors += 1
            else:
                self.logger.warn(
                    '[%s:%d:%d] Received invalid reply with id %d: %s.\nIgnoring it.'
                    % (
                        self.server,
                        self.port,
                        socket.getsockname()[1] if socket else '',
                        (-1, reply.id)[reply is not None],
                        data.hex(),
                    ))
                self.errors += 1

        except Exception as exc:
            self.logger.error(
                '[%s:%d:%d] Error on decode packet: %s.' %
                (self.server, self.port,
                 socket.getsockname()[1] if socket else '', (exc, '\n'.join(
                     traceback.format_exc().splitlines()))[self.client.debug]))
コード例 #4
0
ファイル: client_async.py プロジェクト: wichert/pyrad
    def datagram_received(self, data, addr):
        try:
            reply = Packet(packet=data, dict=self.client.dict)

            if reply and reply.id in self.pending_requests:
                req = self.pending_requests[reply.id]
                packet = req['packet']

                reply.dict = packet.dict
                reply.secret = packet.secret

                if packet.VerifyReply(reply, data):
                    req['future'].set_result(reply)
                    # Remove request for map
                    del self.pending_requests[reply.id]
                else:
                    self.logger.warn('[%s:%d] Ignore invalid reply for id %d. %s', self.server, self.port, reply.id)
            else:
                self.logger.warn('[%s:%d] Ignore invalid reply: %d', self.server, self.port, data)

        except Exception as exc:
            self.logger.error('[%s:%d] Error on decode packet: %s', self.server, self.port, exc)