How to use the fbtftp.constants.OPCODE_ACK function in fbtftp

To help you get started, we’ve selected a few fbtftp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github facebook / fbtftp / fbtftp / base_handler.py View on Github external
code, block_number = struct.unpack("!HH", data[:4])
        if code == constants.OPCODE_ERROR:
            # When the client sends an OPCODE_ERROR#
            # the block number is the ERR codes in constants.py
            self._stats.error = {
                "error_code": block_number,
                "error_message": data[4:-1].decode("ascii", "ignore"),
            }
            # An error was reported by the client which terminates the exchange
            logging.error(
                "Error reported from client: %s" % self._stats.error["error_message"]
            )
            self._transmit_error()
            self._should_stop = True
            return
        if code != constants.OPCODE_ACK:
            logging.error(
                "Expected an ACK opcode from %s, got: %d" % (self._peer, code)
            )
            self._stats.error = {
                "error_code": constants.ERR_ILLEGAL_OPERATION,
                "error_message": "I only do reads, really",
            }
            self._transmit_error()
            self._should_stop = True
            return
        self._handle_ack(block_number)