Exemple #1
0
 def start(self):
     from logs import lg
     from userid import my_id
     from main.config import conf
     my_id.loadLocalIdentity()
     if my_id._LocalIdentity is None:
         lg.warn(
             'Loading local identity failed - need to create an identity first'
         )
         return False
     from main import events
     from contacts import identitycache
     from userid import known_servers
     from p2p import propagate
     from contacts import contactsdb
     identitycache.init()
     d = contactsdb.init()
     propagate.init()
     conf().addConfigNotifier('services/identity-propagate/known-servers',
                              self._on_known_servers_changed)
     lg.info('known ID servers are : %r' % known_servers.by_host())
     events.add_subscriber(self._on_local_identity_modified,
                           'local-identity-modified')
     events.add_subscriber(self._on_my_identity_rotated,
                           'my-identity-rotated')
     return d
Exemple #2
0
def main():
    lg.life_begins()
    bpio.init()
    settings.init()
    misc.init()
    my_id.init()
    identitycache.init()
    from crypt import key
    key.InitMyKey()
    (options, args) = parseCommandLine()
    settings.override('transport.transport-tcp.transport-tcp-port',
                      options.tcpport)
    settings.override('transport.transport-udp.transport-udp-port',
                      options.udpport)
    settings.override('network.network-dht-port', options.dhtport)
    lg.set_debug_level(options.debug)
    tmpfile.init()
    if True:
        import lib.udp
        lib.udp.listen(options.udpport)
        import dht.dht_service
        dht.dht_service.init(options.dhtport)
    reactor.addSystemEventTrigger('before', 'shutdown',
                                  shutdown)  # @UndefinedVariable
    init()
    start()
    globals()['num_in'] = 0

    def _in(a, b, c, d):
        lg.out(2, 'INBOX %d : %r' % (globals()['num_in'], a))
        globals()['num_in'] += 1
        return False

    callback.insert_inbox_callback(0, _in)
    if len(args) > 0:
        globals()['num_out'] = 0

        def _s():
            p = signed.Packet(commands.Data(), my_id.getLocalID(),
                              my_id.getLocalID(), my_id.getLocalID(),
                              bpio.ReadBinaryFile(args[1]), args[0])
            outbox(p, wide=True)
            lg.out(2, 'OUTBOX %d : %r' % (globals()['num_out'], p))
            globals()['num_out'] += 1

        old_state_changed = transport('udp').state_changed

        def new_state_changed(oldstate, newstate, event, *args, **kwargs):
            old_state_changed(oldstate, newstate, event, *args, **kwargs)
            if newstate == 'LISTENING':
                reactor.callLater(1, _s)  # @UndefinedVariable

        transport('udp').state_changed = new_state_changed
        # t = task.LoopingCall(_s)
        # reactor.callLater(5, t.start, 60, True)
        # reactor.callLater(2, t.stop)

    reactor.run()  # @UndefinedVariable
    settings.shutdown()
Exemple #3
0
 def start(self):
     from userid import my_id
     my_id.loadLocalIdentity()
     if my_id._LocalIdentity is None:
         from logs import lg
         lg.warn('Loading local identity failed - need to create an identity first')
         return False
     from contacts import identitycache
     identitycache.init()
     from contacts import contactsdb
     contactsdb.init()
     from p2p import propagate
     propagate.init()
     return True
 def start(self):
     from logs import lg
     from userid import my_id
     my_id.loadLocalIdentity()
     if my_id._LocalIdentity is None:
         lg.warn(
             'Loading local identity failed - need to create an identity first'
         )
         return False
     from contacts import identitycache
     identitycache.init()
     from contacts import contactsdb
     contactsdb.init()
     from p2p import propagate
     propagate.init()
     from userid import known_servers
     lg.info('known ID servers are : %r' % known_servers.by_host())
     return True
Exemple #5
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()
Exemple #6
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()
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()
Exemple #8
0
def main():
    lg.life_begins()
    bpio.init()
    settings.init()
    misc.init()
    my_id.init()
    identitycache.init()
    from crypt import key

    key.InitMyKey()
    (options, args) = parseCommandLine()
    settings.override("transport.transport-tcp.transport-tcp-port", options.tcpport)
    settings.override("transport.transport-udp.transport-udp-port", options.udpport)
    settings.override("network.network-dht-port", options.dhtport)
    lg.set_debug_level(options.debug)
    tmpfile.init()
    if True:
        import lib.udp

        lib.udp.listen(options.udpport)
        import dht.dht_service

        dht.dht_service.init(options.dhtport)
    reactor.addSystemEventTrigger("before", "shutdown", shutdown)
    init()
    start()
    globals()["num_in"] = 0

    def _in(a, b, c, d):
        lg.out(2, "INBOX %d : %r" % (globals()["num_in"], a))
        globals()["num_in"] += 1
        return True

    callback.insert_inbox_callback(-1, _in)
    if len(args) > 0:
        globals()["num_out"] = 0

        def _s():
            p = signed.Packet(
                commands.Data(),
                my_id.getLocalID(),
                my_id.getLocalID(),
                my_id.getLocalID(),
                bpio.ReadBinaryFile(args[1]),
                args[0],
            )
            outbox(p, wide=True)
            lg.out(2, "OUTBOX %d : %r" % (globals()["num_out"], p))
            globals()["num_out"] += 1

        old_state_changed = transport("udp").state_changed

        def new_state_changed(oldstate, newstate, event, arg):
            old_state_changed(oldstate, newstate, event, arg)
            if newstate == "LISTENING":
                reactor.callLater(1, _s)

        transport("udp").state_changed = new_state_changed
        # t = task.LoopingCall(_s)
        # reactor.callLater(5, t.start, 60, True)
        # reactor.callLater(2, t.stop)

    reactor.run()