예제 #1
0
 def doStartListening(self, *args, **kwargs):
     """
     Action method.
     """
     try:
         _, info = args[0]
         self.router_proto_host = (info.proto, info.host)
     except:
         try:
             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()
     previous_identity = ReadMyOriginalIdentitySource()
     if previous_identity:
         lg.warn('my original identity is not empty, SKIP overwriting')
         lg.out(2, '\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 contact_status.isKnown(self.router_idurl):
         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:
             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(2, 'proxy_receiver.doStartListening !!!!!!! router: %s at %s://%s' % (
             self.router_idurl, self.router_proto_host[0], self.router_proto_host[1]))
예제 #2
0
 def doStopListening(self, *args, **kwargs):
     """
     Action method.
     """
     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')
예제 #3
0
 def doStartListening(self, arg):
     """
     Action method.
     """
     try:
         _, info = arg
         self.router_proto_host = (info.proto, info.host)
     except:
         try:
             s = config.conf().getString(
                 'services/proxy-transport/current-router').strip()
             _, router_proto, router_host = s.split(' ')
             self.router_proto_host = (router_proto, router_host)
         except:
             lg.exc()
     self.router_identity = identitycache.FromCache(self.router_idurl)
     config.conf().setString(
         'services/proxy-transport/current-router',
         '%s %s %s' % (self.router_idurl, self.router_proto_host[0],
                       self.router_proto_host[1]))
     current_identity = my_id.getLocalIdentity().serialize()
     previous_identity = ReadMyOriginalIdentitySource()
     if previous_identity:
         lg.warn('my original identity is not empty, SKIP overwriting')
         lg.out(2, '\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 contact_status.isKnown(self.router_idurl):
         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')
     if _Debug:
         lg.out(
             2,
             'proxy_receiver.doStartListening !!!!!!! router: %s at %s://%s'
             % (self.router_idurl, self.router_proto_host[0],
                self.router_proto_host[1]))
예제 #4
0
def nickname_observer_result(sessionkey, target_username, result, nik, pos, idurl):
    lg.out(6, 'django.nickname_observer_result: %s' % str((sessionkey, target_username, result, nik, idurl)))
    global _SearchLookups
    try:
        status = ''
        if result == 'exist':
            if contact_status.isKnown(idurl):
                status = contact_status.getStatusLabel(idurl)
            else:
                propagate.single(idurl,
                                 ack_handler=lambda ackpacket, info:
                                 contact_acked(sessionkey, target_username, ackpacket, info),
                                 fail_handler=lambda failpacket, info:
                                 contact_failed(sessionkey, target_username, failpacket, info),
                                 wide=True)
                status = 'checking'
            _SearchLookups[sessionkey][target_username].append({
                'nickname': nik,
                'position': pos,
                'idurl': idurl,
                'status': status, })
    except:
        lg.exc()
        return
예제 #5
0
파일: views.py 프로젝트: hack-bitdust/devel
def nickname_observer_result(sessionkey, target_username, result, nik, pos, idurl):
    lg.out(6, 'django.nickname_observer_result: %s' % str((sessionkey, target_username, result, nik, idurl)))
    global _SearchLookups
    try:
        status = ''
        if result == 'exist':
            if contact_status.isKnown(idurl):
                status = contact_status.getStatusLabel(idurl)
            else:
                propagate.single(idurl,
                                 ack_handler=lambda ackpacket, info:
                                     contact_acked(sessionkey, target_username, ackpacket, info),
                                 fail_handler=lambda failpacket, info:
                                     contact_failed(sessionkey, target_username, failpacket, info),
                                 wide=True)
                status = 'checking'
            _SearchLookups[sessionkey][target_username].append({
                'nickname': nik,
                'position': pos,
                'idurl': idurl,
                'status': status, })
    except:
        lg.exc()
        return