def __init__(self, *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) self.error_queue = [] self.desired_con_state = None # ??? status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) super(EIPConductor, self).__init__(*args, **kwargs)
class EIPConductor(OpenVPNConnection): """ Manages the execution of the OpenVPN process, auto starts, monitors the network connection, handles configuration, fixes leaky hosts, handles errors, etc. Preferences will be stored via the Storage API. (TBD) Status updates (connected, bandwidth, etc) are signaled to the GUI. """ def __init__(self, *args, **kwargs): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) self.error_queue = [] self.desired_con_state = None # ??? status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) super(EIPConductor, self).__init__(*args, **kwargs) def connect(self): """ entry point for connection process """ self.manager.forget_errors() self._try_connection() # XXX should capture errors? def disconnect(self): """ disconnects client """ self._disconnect() self.status.change_to(self.status.DISCONNECTED) pass def shutdown(self): """ shutdown and quit """ self.desired_con_state = self.status.DISCONNECTED def connection_state(self): """ returns the current connection state """ return self.status.current def desired_connection_state(self): """ returns the desired_connection state """ return self.desired_con_state def poll_connection_state(self): """ """ try: state = self.manager.get_connection_state() except ConnectionRefusedError: # connection refused. might be not ready yet. return if not state: return (ts, status_step, ok, ip, remote) = state self.status.set_vpn_state(status_step) status_step = self.status.get_readable_status() return (ts, status_step, ok, ip, remote) def get_icon_name(self): """ get icon name from status object """ return self.status.get_state_icon() # # private methods # def _disconnect(self): """ private method for disconnecting """ if self.subp is not None: self.subp.terminate() self.subp = None # XXX signal state changes! :) def _is_alive(self): """ don't know yet """ pass def _connect(self): """ entry point for connection cascade methods. """ #conn_result = ConState.DISCONNECTED try: conn_result = self._try_connection() except UnrecoverableError as except_msg: logger.error("FATAL: %s" % unicode(except_msg)) conn_result = self.status.UNRECOVERABLE except Exception as except_msg: self.error_queue.append(except_msg) logger.error("Failed Connection: %s" % unicode(except_msg)) return conn_result