def handle_data_received(self, data): """ 异步wrapper :param data: :return: """ if not self.cipher_man: self.cipher_man = CipherMan.get_cipher_by_port(self.port, self._transport_protocol, self._peer) try: data = self.cipher_man.decrypt(data) except Exception as e: logger.exception( f"decrypt data error:{e} remote:{self._peer},type:{self._transport_protocol_human} closing..." ) self.close() return if not data: return if self._stage == self.STAGE_INIT: asyncio.create_task(self._handle_stage_init(data)) elif self._stage == self.STAGE_CONNECT: self._handle_stage_connect(data) elif self._stage == self.STAGE_STREAM: self._handle_stage_stream(data) elif self._stage == self.STAGE_ERROR: self.close() elif self._stage == self.STAGE_DESTROY: self.close() else: logger.warning(f"unknown stage:{self._stage}")
def handle_data_received(self, data): if not self.cipher or self._transport_protocol == flag.TRANSPORT_UDP: self.cipher = CipherMan.get_cipher_by_port( self.port, self._transport_protocol, self._peername ) try: data = self.cipher.decrypt(data) except Exception as e: logging.warning( f"decrypt data error:{e} remote:{self._peername},type:{self._transport_protocol}" ) self.close() return if not data: return if self._stage == self.STAGE_INIT: asyncio.create_task(self._handle_stage_init(data)) elif self._stage == self.STAGE_CONNECT: self._handle_stage_connect(data) elif self._stage == self.STAGE_STREAM: self._handle_stage_stream(data) elif self._stage == self.STAGE_ERROR: self.close() elif self._stage == self.STAGE_DESTROY: self.close() else: logging.warning(f"unknown stage:{self._stage}") self.close()
def __init__(self, addr, port, data, local_hander): super().__init__() self.data = data self.local = local_hander self.cipher = CipherMan.get_cipher_by_port(self.local.port) self.peername = None self._transport = None
def _init_cipher(self): self.cipher = CipherMan.get_cipher_by_port(self.port, self._transport_protocol)
def _init_cipher(self): self.cipher = CipherMan.get_cipher_by_port(self.port)