Example #1
0
def main():
    lg.set_debug_level(18)
    lg.life_begins()
    from crypt import key
    key.InitMyKey()
    from contacts import identitycache
    identitycache.init()
    from system import tmpfile
    tmpfile.init()
    from services import driver
    driver.disabled_services().add('service_tcp_connections')
    driver.disabled_services().add('service_p2p_hookups')
    driver.disabled_services().add('service_nodes_lookup')
    driver.disabled_services().add('service_identity_propagate')
    driver.disabled_services().add('service_ip_port_responder')
    driver.init()
    driver.enabled_services().clear()
    driver.enabled_services().add('service_udp_transport')
    driver.enabled_services().add('service_udp_datagrams')
    driver.enabled_services().add('service_my_ip_port')
    driver.enabled_services().add('service_gateway')
    driver.enabled_services().add('service_entangled_dht')
    driver.enabled_services().add('service_network')
    driver.start()
    # options = { 'idurl': my_id.getLocalID(),}
    # options['host'] = nameurl.GetName(my_id.getLocalID())+'@'+'somehost.org'
    # options['dht_port'] = int(settings.getDHTPort())
    # options['udp_port'] = int(settings.getUDPPort())
    # udp.listen(int(settings.getUDPPort()))
    # dht_service.init(settings.getDHTPort())
    # dht_service.connect()
    # udp_node.A('go-online', options)
    reactor.addSystemEventTrigger('before', 'shutdown', gateway.shutdown)
    gateway.init()
    gateway.start()

    def _ok_to_send(transport, oldstate, newstate):
        if newstate != 'LISTENING':
            return
        # [filename] [peer idurl]
        if len(sys.argv) >= 3:
            # bpio.WriteFile(sys.argv[1]+'.signed', p.Serialize())

            def _try_reconnect():
                sess = udp_session.get_by_peer_id(sys.argv[2])
                reconnect = False
                if not sess:
                    reconnect = True
                    print('sessions',
                          list(udp_session.sessions_by_peer_id().keys()))
                    print([
                        s.peer_id
                        for s in list(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)

            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)

            # _try_connect()

            def _send(c):
                from transport.udp import udp_stream
                for idurl in sys.argv[2:]:
                    print('_send', list(udp_stream.streams().keys()))
                    p = signed.Packet(commands.Data(), my_id.getLocalID(),
                                      my_id.getLocalID(), 'packet%d' % c,
                                      bpio.ReadBinaryFile(sys.argv[1]), idurl)
                    gateway.outbox(p)
                if c > 1:
                    reactor.callLater(0.01, _send, c - 1)

            reactor.callLater(0, _send, 15)

    gateway.add_transport_state_changed_callback(_ok_to_send)
    reactor.run()
Example #2
0
def main():
    lg.set_debug_level(18)
    lg.life_begins()
    from crypt import key
    key.InitMyKey()
    from contacts import identitycache
    identitycache.init()
    from system import tmpfile
    tmpfile.init()
    from services import driver

    required_services = [
        'service_http_connections',
        'service_http_transport',
        'service_gateway',
        'service_network',
    ]
    available_services_dir = os.path.join(bpio.getExecutableDir(), 'services')
    for filename in os.listdir(available_services_dir):
        if not filename.endswith('.py') and not filename.endswith(
                '.pyo') and not filename.endswith('.pyc'):
            continue
        if not filename.startswith('service_'):
            continue
        name = str(filename[:filename.rfind('.')])
        if name in required_services:
            continue
        driver.disabled_services().add(name)
    driver.init()
    driver.enabled_services().clear()
    driver.enabled_services().add('service_http_transport')
    driver.enabled_services().add('service_http_connections')
    driver.enabled_services().add('service_gateway')
    driver.enabled_services().add('service_network')
    driver.start()
    # options = { 'idurl': my_id.getIDURL(),}
    # options['host'] = nameurl.GetName(my_id.getIDURL())+'@'+'somehost.org'
    # options['dht_port'] = int(settings.getDHTPort())
    # options['udp_port'] = int(settings.getUDPPort())
    # udp.listen(int(settings.getUDPPort()))
    # dht_service.init(settings.getDHTPort())
    # dht_service.connect()
    # udp_node.A('go-online', options)
    reactor.addSystemEventTrigger('before', 'shutdown', gateway.shutdown)
    gateway.init()
    gateway.start()

    def _ok_to_send(transport, oldstate, newstate):
        if newstate != 'LISTENING':
            return
        # [filename] [peer idurl]
        if len(sys.argv) >= 3:
            pass
            # bpio.WriteFile(sys.argv[1]+'.signed', p.Serialize())


#             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)
#
#             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)
#             # _try_connect()
#
#             def _send(c):
#                 from transport.udp import udp_stream
#                 for idurl in sys.argv[2:]:
#                     print '_send', udp_stream.streams().keys()
#                     p = signed.Packet(commands.Data(),
#                                       my_id.getIDURL(),
#                                       my_id.getIDURL(),
#                                       'packet%d' % c,
#                                       bpio.ReadBinaryFile(sys.argv[1]),
#                                       idurl)
#                     gateway.outbox(p)
#                 if c > 1:
#                     reactor.callLater(0.01, _send, c - 1)
#             reactor.callLater(0, _send, 15)

    gateway.add_transport_state_changed_callback(_ok_to_send)
    reactor.run()
def main():
    lg.set_debug_level(18)
    lg.life_begins()
    from crypt import key
    key.InitMyKey()
    from contacts import identitycache
    identitycache.init()
    from system import tmpfile
    tmpfile.init()
    from services import driver
    driver.disabled_services().add('service_tcp_connections')
    driver.disabled_services().add('service_p2p_hookups')
    driver.disabled_services().add('service_nodes_lookup')
    driver.disabled_services().add('service_identity_propagate')
    driver.disabled_services().add('service_ip_port_responder')
    driver.init()
    driver.enabled_services().clear()
    driver.enabled_services().add('service_udp_transport')
    driver.enabled_services().add('service_udp_datagrams')
    driver.enabled_services().add('service_my_ip_port')
    driver.enabled_services().add('service_gateway')
    driver.enabled_services().add('service_entangled_dht')
    driver.enabled_services().add('service_network')
    driver.start()
    # options = { 'idurl': my_id.getLocalID(),}
    # options['host'] = nameurl.GetName(my_id.getLocalID())+'@'+'somehost.org'
    # options['dht_port'] = int(settings.getDHTPort())
    # options['udp_port'] = int(settings.getUDPPort())
    # udp.listen(int(settings.getUDPPort()))
    # dht_service.init(settings.getDHTPort())
    # dht_service.connect()
    # udp_node.A('go-online', options)
    reactor.addSystemEventTrigger('before', 'shutdown', gateway.shutdown)
    gateway.init()
    gateway.start()

    def _ok_to_send(transport, oldstate, newstate):
        if newstate != 'LISTENING':
            return
        # [filename] [peer idurl]
        if len(sys.argv) >= 3:
            # bpio.WriteFile(sys.argv[1]+'.signed', p.Serialize())

            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)

            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)
            # _try_connect()

            def _send(c):
                from transport.udp import udp_stream
                for idurl in sys.argv[2:]:
                    print '_send', udp_stream.streams().keys()
                    p = signed.Packet(commands.Data(),
                                      my_id.getLocalID(),
                                      my_id.getLocalID(),
                                      'packet%d' % c,
                                      bpio.ReadBinaryFile(sys.argv[1]),
                                      idurl)
                    gateway.outbox(p)
                if c > 1:
                    reactor.callLater(0.01, _send, c - 1)
            reactor.callLater(0, _send, 15)

    gateway.add_transport_state_changed_callback(_ok_to_send)
    reactor.run()