How to use the fbtftp.base_handler.SessionStats 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
self._response_data = None
        self._listener = None

        self._peer = peer
        logging.info(
            "New connection from peer `%s` asking for path `%s`"
            % (str(peer), str(path))
        )
        self._family = socket.AF_INET6
        # the format of the peer tuple is different for v4 and v6
        if isinstance(ipaddress.ip_address(server_addr[0]), ipaddress.IPv4Address):
            self._family = socket.AF_INET
            # peer address format is different in v4 world
            self._peer = (self._peer[0].replace("::ffff:", ""), self._peer[1])

        self._stats = SessionStats(self._server_addr, self._peer, self._path)

        try:
            self._response_data = self.get_response_data()
        except FileNotFoundError as e:
            logging.warning(str(e))
            self._stats.error = {
                "error_code": constants.ERR_FILE_NOT_FOUND,
                "error_message": str(e),
            }
        except Exception as e:
            logging.exception("Caught exception: %s." % e)
            self._stats.error = {
                "error_code": constants.ERR_UNDEFINED,
                "error_message": str(e),
            }