Beispiel #1
0
 def send_file(self, remote_idurl, filename, host, description=''):
     """
     """
     from transport.udp import udp_session
     from transport.udp import udp_node
     # lg.out(20, 'udp_interface.send_file %s %s %s' % (filename, host, description))
     result_defer = Deferred()
     #        if udp_node.A().state not in ['LISTEN', 'DHT_READ',]:
     #            result_defer.callback(False)
     #            lg.out(4, 'udp_interface.send_file WARNING udp_node state is %s' % udp_node.A().state)
     #            return result_defer
     active_sessions = udp_session.get_by_peer_id(host)
     if active_sessions:
         if description.startswith('Identity') or description.startswith(
                 'Ack'):
             active_sessions[0].file_queue.insert_outbox_file(
                 filename, description, result_defer, keep_alive=True)
         else:
             active_sessions[0].file_queue.append_outbox_file(
                 filename, description, result_defer, keep_alive=True)
     else:
         udp_session.add_pending_outbox_file(filename,
                                             host,
                                             description,
                                             result_defer,
                                             keep_alive=True)
         udp_node.A('connect', host)
     return result_defer
    def send_file(
            self,
            remote_idurl,
            filename,
            host,
            description='',
            single=False):
        """
        
        """
        from transport.udp import udp_session
        from transport.udp import udp_node
        # lg.out(20, 'udp_interface.send_file %s %s %s' % (filename, host, description))
        result_defer = Deferred()
#        if udp_node.A().state not in ['LISTEN', 'DHT_READ',]:
#            result_defer.callback(False)
#            lg.out(4, 'udp_interface.send_file WARNING udp_node state is %s' % udp_node.A().state)
#            return result_defer
        s = udp_session.get_by_peer_id(host)
        if s:
            if description.startswith(
                    'Identity') or description.startswith('Ack'):
                s.file_queue.insert_outbox_file(
                    filename, description, result_defer, single)
            else:
                s.file_queue.append_outbox_file(
                    filename, description, result_defer, single)
        else:
            udp_session.add_pending_outbox_file(
                filename, host, description, result_defer, single)
            udp_node.A('connect', host)
        return result_defer
 def _try_connect():
     if udp_node.A().state == 'LISTEN':
         print 'connect'
         gateway.stop_packets_timeout_loop()
         udp_session.add_pending_outbox_file(
             sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False)
         udp_node.A('connect', sys.argv[2])
         reactor.callLater(5, _try_reconnect)
     else:
         reactor.callLater(1, _try_connect)
Beispiel #4
0
 def _try_connect():
     if udp_node.A().state == 'LISTEN':
         print('connect')
         gateway.stop_packets_timeout_loop()
         udp_session.add_pending_outbox_file(
             sys.argv[1] + '.signed', sys.argv[2], 'descr',
             Deferred(), False)
         udp_node.A('connect', sys.argv[2])
         reactor.callLater(5, _try_reconnect)
     else:
         reactor.callLater(1, _try_connect)
 def _try_reconnect():
     sess = udp_session.get_by_peer_id(sys.argv[2])
     reconnect = False
     if not sess:
         reconnect = True
         print 'sessions', udp_session.sessions_by_peer_id().keys()
         print map(lambda s: s.peer_id, udp_session.sessions().values())
     else:
         if sess.state != 'CONNECTED':
             print 'state: ', sess.state
             reconnect = True
     if reconnect:
         print 'reconnect', sess
         udp_session.add_pending_outbox_file(
             sys.argv[1] + '.signed', sys.argv[2], 'descr', Deferred(), False)
         udp_node.A('connect', sys.argv[2])
     reactor.callLater(0.5, _try_reconnect)
Beispiel #6
0
 def _try_reconnect():
     sess = udp_session.get_by_peer_id(sys.argv[2])
     reconnect = False
     if not sess:
         reconnect = True
         print 'sessions', udp_session.sessions_by_peer_id().keys()
         print map(lambda s: s.peer_id,
                   udp_session.sessions().values())
     else:
         if sess.state != 'CONNECTED':
             print 'state: ', sess.state
             reconnect = True
     if reconnect:
         print 'reconnect', sess
         udp_session.add_pending_outbox_file(
             sys.argv[1] + '.signed', sys.argv[2], 'descr',
             Deferred(), False)
         udp_node.A('connect', sys.argv[2])
     reactor.callLater(0.5, _try_reconnect)