def recv(self, data): """Receive message from downstream.""" self.last_receive = time() self._inb += data lines, self._inb = self.protocol.parser(self._inb) if not lines: return if self._state == Session.LOGIN: login_m = self.protocol.validate(lines.pop(0)) if login_m is None: raise SessionError, (self, exc.S_ELOGIN) self.log.debug("VALIDATE LOGIN: '******'", str(login_m)) if self.protocol.login_auth(login_m, self.server): self._state = Session.INSESSION del_timer(self._tid) self._start_hb_watchdog() if self._state == Session.INSESSION: for line in lines: msg = self.protocol.validate(line) if msg is None: raise SessionError, (self, exc.S_EINVAL) self.protocol.received(msg, self.server)
def _disconnect_client(self): self._state = Session.IDLE del_timer(self._tid) if self.listener is not None: # delete old client transport del self.transport self.transport = None self.listener.listen(5)
def _request_reconnect(self): del_timer(self._tid) self.log.debug("RECONNECT: %s", self._last_address) self.transport.create() if self._ssl is not None: self.transport.ssl_wrap(self._ssl) self.transport.add_channel() self.transport.start(self._last_address)
def _disconnect(self): self.transport.close() self.transport.del_channel() self._state = Session.IDLE del_timer(self._tid) if self.server: self._disconnect_client() else: self._arm_reconnect()
def _start_hb_watchdog(self): del_timer(self._tid) self.watchdog_secs = self.get_conf("watchdog_interval", 0) self.hb_interval = self.get_conf("heartbeat_interval", 0) if self.watchdog_secs <= 0 and self.hb_interval > 0: self.watchdog_secs = max(1, self.hb_interval / 2) if self.watchdog_secs > 0: # self.log.debug("arming hb status checker %d sec", self.watchdog_secs) self._tid = add_timer(self.watchdog_secs, self._check_hb_status)
def _start_hb_watchdog(self): del_timer(self._tid) self.watchdog_secs = self.get_conf('watchdog_interval', 0) self.hb_interval = self.get_conf('heartbeat_interval', 0) if self.watchdog_secs <= 0 and self.hb_interval > 0: self.watchdog_secs = max(1, self.hb_interval / 2) if self.watchdog_secs > 0: # self.log.debug("arming hb status checker %d sec", self.watchdog_secs) self._tid = add_timer(self.watchdog_secs, self._check_hb_status)
def stop(self): self.log.debug("Stopping: %s", str(self)) if self.listener is not None: # self.log.warning("Closing listen transport: %s", str(self)) self.listener.close() self.listener.del_channel() if self.transport is not None: # self.log.warning("Closing forcibly open session: %s", str(self)) self.transport.close() self.transport.del_channel() del_timer(self._tid) self._state = Session.STOPPED
def stop(self): self.log.debug("Stopping: %s", str(self)) if self.listener is not None: #self.log.warning("Closing listen transport: %s", str(self)) self.listener.close() self.listener.del_channel() if self.transport is not None: #self.log.warning("Closing forcibly open session: %s", str(self)) self.transport.close() self.transport.del_channel() del_timer(self._tid) self._state = Session.STOPPED
def _arm_reconnect(self): if self.server: return del_timer(self._tid) timeout_sec = self.get_conf("reconnect_interval", 5) self._tid = add_timer(timeout_sec, self._request_reconnect)
def _arm_login_timer(self): del_timer(self._tid) timeout_sec = int(self.get_conf("login_wait_time", 20)) self.log.debug("arming login timer %d", timeout_sec) self._tid = add_timer(timeout_sec, self._login_timeout)
def _arm_reconnect(self): if self.server: return del_timer(self._tid) timeout_sec = self.get_conf('reconnect_interval', 5) self._tid = add_timer(timeout_sec, self._request_reconnect)
def _arm_login_timer(self): del_timer(self._tid) timeout_sec = int(self.get_conf('login_wait_time', 20)) self.log.debug("arming login timer %d", timeout_sec) self._tid = add_timer(timeout_sec, self._login_timeout)