Example #1
0
 def data_received(self, data):
     request = None
     if len(self.buf) + len(data or b'') >= MAX_REQUEST_SIZE:
         log.warning("request from %s is too large",
                     self.peer_address_and_port)
         self.close()
         return
     if data:
         self.blob_manager.connection_manager.received_data(
             self.peer_address_and_port, len(data))
         _, separator, remainder = data.rpartition(b'}')
         if not separator:
             self.buf += data
             return
         try:
             request = BlobRequest.deserialize(self.buf + data)
             self.buf = remainder
         except JSONDecodeError:
             log.error(
                 "request from %s is not valid json (%i bytes): %s",
                 self.peer_address_and_port, len(self.buf + data),
                 '' if not data else binascii.hexlify(self.buf +
                                                      data).decode())
             self.close()
             return
     if not request.requests:
         log.error(
             "failed to decode request from %s (%i bytes): %s",
             self.peer_address_and_port, len(self.buf + data),
             '' if not data else binascii.hexlify(self.buf + data).decode())
         self.close()
         return
     self.loop.create_task(self.handle_request(request))
Example #2
0
 def data_received(self, data):
     request = None
     if data:
         self.blob_manager.connection_manager.received_data(
             self.peer_address_and_port, len(data))
         message, separator, remainder = data.rpartition(b'}')
         if not separator:
             self.buf += data
             return
         try:
             request = BlobRequest.deserialize(self.buf + data)
             self.buf = remainder
         except JSONDecodeError:
             addr = self.transport.get_extra_info('peername')
             peer_address, peer_port = addr
             log.error(
                 "failed to decode blob request from %s:%i (%i bytes): %s",
                 peer_address, peer_port, len(data),
                 '' if not data else binascii.hexlify(data).decode())
     if not request:
         addr = self.transport.get_extra_info('peername')
         peer_address, peer_port = addr
         log.warning("failed to decode blob request from %s:%i",
                     peer_address, peer_port)
         self.transport.close()
         return
     self.loop.create_task(self.handle_request(request))