def doStopListening(self, *args, **kwargs): """ Action method. """ if online_status.isKnown(self.router_idurl): online_status.remove_online_status_listener_callbackove_( idurl=self.router_idurl, callback_method=self._on_router_contact_status_connected, ) online_status.remove_online_status_listener_callbackove_( idurl=self.router_idurl, callback_method=self._on_router_contact_status_offline, ) # if contact_status.isKnown(self.router_idurl): # contact_status.A(self.router_idurl).removeStateChangedCallback(self._on_router_contact_status_connected) # contact_status.A(self.router_idurl).removeStateChangedCallback(self._on_router_contact_status_offline) WriteMyOriginalIdentitySource('') config.conf().setString('services/proxy-transport/current-router', '') callback.remove_inbox_callback(self._on_inbox_packet_received) self.router_identity = None self.router_idurl = None self.router_proto_host = None self.request_service_packet_id = [] self.router_connection_info = None my_id.rebuildLocalIdentity() if _Debug: lg.out(2, 'proxy_receiver.doStopListening')
def doStopListening(self, *args, **kwargs): """ Action method. """ if _Debug: lg.args(_DebugLevel, router_idurl=self.router_idurl) if online_status.isKnown(self.router_idurl): online_status.remove_online_status_listener_callback( idurl=self.router_idurl, callback_method=self._on_router_contact_status_connected, ) online_status.remove_online_status_listener_callback( idurl=self.router_idurl, callback_method=self._on_router_contact_status_offline, ) active_router_session_machine_index = None if self.router_connection_info: active_router_session_machine = None active_router_session_machine_index = self.router_connection_info.get('index', None) if active_router_session_machine_index is not None: active_router_session_machine = automat.by_index(active_router_session_machine_index) if not active_router_session_machine: active_router_sessions = gateway.find_active_session( proto=self.router_connection_info.get('proto'), host=self.router_connection_info.get('host'), ) if not active_router_sessions: active_router_sessions = gateway.find_active_session( proto=self.router_connection_info.get('proto'), idurl=id_url.to_bin(self.router_idurl), ) if active_router_sessions: active_router_session_machine = automat.by_index(active_router_sessions[0].index) if active_router_session_machine is not None: active_router_session_machine.removeStateChangedCallback(self._on_router_session_disconnected) lg.info('removed callback from router active session: %r' % active_router_session_machine) else: lg.err('did not found active router session state machine with index %s' % active_router_session_machine_index) WriteMyOriginalIdentitySource('') config.conf().setString('services/proxy-transport/current-router', '') callback.remove_inbox_callback(self._on_inbox_packet_received) self.router_identity = None self.router_idurl = None self.router_id = '' self.router_proto_host = None self.request_service_packet_id = [] self.router_connection_info = None my_id.rebuildLocalIdentity()
def doStartListening(self, *args, **kwargs): """ Action method. """ try: _, info, active_router_session_machine = args[0] self.router_proto_host = (info.proto, info.host) except: try: # TODO: move that setting to separate file s = config.conf().getString('services/proxy-transport/current-router').strip() _, router_proto, router_host = s.split(' ') self.router_proto_host = (router_proto, strng.to_bin(router_host), ) except: lg.exc() self.router_identity = identitycache.FromCache(self.router_idurl) if _Debug: lg.args(_DebugLevel, router_idurl=self.router_idurl) config.conf().setString('services/proxy-transport/current-router', '%s %s %s' % ( strng.to_text(self.router_idurl), strng.to_text(self.router_proto_host[0]), strng.to_text(self.router_proto_host[1]), )) current_identity = my_id.getLocalIdentity().serialize(as_text=True) previous_identity = ReadMyOriginalIdentitySource() if previous_identity: lg.err('my original identity is not empty, SKIP overwriting') if _Debug: lg.out(_DebugLevel, 'PREVIOUS ORIGINAL IDENTITY:\n%s\n' % previous_identity) WriteMyOriginalIdentitySource(current_identity) lg.info('copy of my current identity was stored as my "original" identity') self.request_service_packet_id = [] callback.insert_inbox_callback(0, self._on_inbox_packet_received) if online_status.isKnown(self.router_idurl): online_status.add_online_status_listener_callback( idurl=self.router_idurl, callback_method=self._on_router_contact_status_connected, newstate='CONNECTED', ) online_status.add_online_status_listener_callback( idurl=self.router_idurl, callback_method=self._on_router_contact_status_offline, newstate='OFFLINE', ) active_router_session_machine.addStateChangedCallback(self._on_router_session_disconnected, oldstate='CONNECTED') lg.info('router %s is connected at %s://%s' % (self.router_idurl, self.router_proto_host[0], self.router_proto_host[1], )) my_id.rebuildLocalIdentity()
def doStartListening(self, *args, **kwargs): """ Action method. """ try: _, info = args[0] self.router_proto_host = (info.proto, info.host) except: try: # TODO: move that setting to separate file s = config.conf().getString( 'services/proxy-transport/current-router').strip() _, router_proto, router_host = s.split(' ') self.router_proto_host = ( router_proto, strng.to_bin(router_host), ) except: lg.exc() self.router_identity = identitycache.FromCache(self.router_idurl) config.conf().setString( 'services/proxy-transport/current-router', '%s %s %s' % ( strng.to_text(self.router_idurl), strng.to_text(self.router_proto_host[0]), strng.to_text(self.router_proto_host[1]), )) current_identity = my_id.getLocalIdentity().serialize(as_text=True) previous_identity = ReadMyOriginalIdentitySource() if previous_identity: lg.warn('my original identity is not empty, SKIP overwriting') if _Debug: lg.out( _DebugLevel, '\nPREVIOUS ORIGINAL IDENTITY:\n%s\n' % current_identity) else: WriteMyOriginalIdentitySource(current_identity) lg.warn('current identity was stored as my-original-identity') self.request_service_packet_id = [] callback.insert_inbox_callback(0, self._on_inbox_packet_received) if online_status.isKnown(self.router_idurl): online_status.add_online_status_listener_callback( idurl=self.router_idurl, callback_method=self._on_router_contact_status_connected, newstate='CONNECTED', ) online_status.add_online_status_listener_callback( idurl=self.router_idurl, callback_method=self._on_router_contact_status_offline, newstate='OFFLINE', ) # contact_status.A(self.router_idurl).addStateChangedCallback( # self._on_router_contact_status_connected, newstate='CONNECTED') # contact_status.A(self.router_idurl).addStateChangedCallback( # self._on_router_contact_status_offline, newstate='OFFLINE') active_router_sessions = gateway.find_active_session( info.proto, info.host) if active_router_sessions: self.router_connection_info = { 'id': active_router_sessions[0].id, 'index': active_router_sessions[0].index, 'proto': info.proto, 'host': info.host, 'idurl': self.router_idurl, 'global_id': global_id.UrlToGlobalID(self.router_idurl), } active_router_session_machine = automat.objects().get( self.router_connection_info['index'], None) if active_router_session_machine is not None: active_router_session_machine.addStateChangedCallback( self._on_router_session_disconnected, oldstate='CONNECTED') lg.info( 'connected to proxy router and set active session: %s' % self.router_connection_info) else: lg.err('not found proxy router session state machine: %s' % self.router_connection_info['index']) else: lg.err( 'active connection with proxy router at %s:%s was not found' % ( info.proto, info.host, )) if _Debug: lg.out( _DebugLevel, 'proxy_receiver.doStartListening !!!!!!! router: %s at %s://%s' % (self.router_idurl, self.router_proto_host[0], self.router_proto_host[1]))