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]))
     if ReadMyOriginalIdentitySource():
         lg.warn('my original identity is not empty')
     else:
         config.conf().setData('services/proxy-transport/my-original-identity',
                               my_id.getLocalIdentity().serialize())
     self.request_service_packet_id = []
     callback.insert_inbox_callback(0, self._on_inbox_packet_received)
     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]))
Beispiel #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()
def init():
    """
    Needs to be called before other methods here.
    """
    lg.out(4, 'contact_status.init')
    callback.insert_inbox_callback(-1, Inbox)
    callback.add_outbox_callback(Outbox)
    callback.add_queue_item_status_callback(OutboxStatus)
def init():
    """
    Needs to be called before other methods here.
    """
    lg.out(4, 'contact_status.init')
    callback.insert_inbox_callback(1, Inbox)  # try to not overwrite top callback in the list, but stay on top
    callback.add_outbox_callback(Outbox)
    callback.add_queue_item_status_callback(OutboxStatus)
Beispiel #5
0
def init():
    """
    Needs to be called before other methods here.
    """
    lg.out(4, 'contact_status.init')
    callback.insert_inbox_callback(-1, Inbox)
    callback.add_outbox_callback(Outbox)
    callback.add_queue_item_status_callback(OutboxStatus)
Beispiel #6
0
 def doInit(self, arg):
     version_number = bpio.ReadTextFile(
         settings.VersionNumberFile()).strip()
     if _Debug:
         lg.out(
             4,
             'p2p_connector.doInit RevisionNumber=%s' % str(version_number))
     callback.insert_inbox_callback(0, inbox)
Beispiel #7
0
 def start(self):
     from transport import gateway
     from transport import callback
     from transport import bandwidth
     gateway.init()
     bandwidth.init()
     callback.insert_inbox_callback(0, bandwidth.INfile)
     callback.add_finish_file_sending_callback(bandwidth.OUTfile)
     return True
Beispiel #8
0
 def doInit(self, *args, **kwargs):
     """
     Action method.
     """
     self._load_routes()
     network_connector.A().addStateChangedCallback(
         self._on_network_connector_state_changed)
     callback.insert_inbox_callback(0, self._on_inbox_packet_received)
     callback.add_finish_file_sending_callback(self._on_finish_file_sending)
Beispiel #9
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]))
Beispiel #10
0
    def doInit(self, arg):
        """
        Action method.
        """
#         self.starting_transports = []
        self._load_routes()
        network_connector.A().addStateChangedCallback(self._on_network_connector_state_changed)
        # gateway.add_transport_state_changed_callback(self._on_transport_state_changed)
        callback.insert_inbox_callback(0, self._on_inbox_packet_received)
        callback.add_finish_file_sending_callback(self._on_finish_file_sending)
    def start(self):
        from transport import gateway
        from transport import callback
        from transport import bandwidth

        gateway.init()
        bandwidth.init()
        callback.insert_inbox_callback(0, bandwidth.INfile)
        callback.add_finish_file_sending_callback(bandwidth.OUTfile)
        return True
Beispiel #12
0
 def doInit(self, arg):
     """
     Action method.
     """
     #         self.starting_transports = []
     self._load_routes()
     network_connector.A().addStateChangedCallback(
         self._on_network_connector_state_changed)
     # gateway.add_transport_state_changed_callback(self._on_transport_state_changed)
     callback.insert_inbox_callback(0, self._on_inbox_packet_received)
     callback.add_finish_file_sending_callback(self._on_finish_file_sending)
Beispiel #13
0
def init():
    """
    Needs to be called before other methods here.
    """
    global _OfflineCheckTask
    lg.out(4, 'online_status.init')
    callback.insert_inbox_callback(
        1, Inbox
    )  # try to not overwrite top callback in the list, but stay on top
    callback.add_queue_item_status_callback(OutboxStatus)
    _OfflineCheckTask = LoopingCall(RunOfflineChecks)
    _OfflineCheckTask.start(10, now=False)
 def doStartListening(self, arg):
     """
     Action method.
     """
     response, info = arg
     self.router_proto_host = (info.proto, info.host)
     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]))
     callback.insert_inbox_callback(0, self._on_inbox_packet_received)
     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]))
Beispiel #15
0
def init():
    """
    Called from top level code when the software is starting.
    Needs to be called before other methods here.
    """
    global _OfflineCheckTask
    global _ShutdownFlag
    lg.out(4, 'online_status.init')
    _ShutdownFlag = False
    callback.insert_inbox_callback(1, Inbox)  # try to not overwrite top callback in the list, but stay on top
    callback.add_queue_item_status_callback(OutboxStatus)
    _OfflineCheckTask = LoopingCall(RunOfflineChecks)
    _OfflineCheckTask.start(10, now=False)
Beispiel #16
0
 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()
Beispiel #17
0
    def start(self):
        from transport import packet_out
        from transport import packet_in
        from transport import gateway
        from transport import callback
        from transport import bandwidth
        from services import driver
        from userid import my_id 
        packet_out.init()
        packet_in.init()
        gateway.init()
        bandwidth.init()
        callback.insert_inbox_callback(0, bandwidth.INfile)
        callback.add_finish_file_sending_callback(bandwidth.OUTfile)
#         if driver.is_on('service_entangled_dht'):
#             from dht import dht_service
#             dht_service.set_node_data('idurl', my_id.getLocalID().to_text())
        return True
Beispiel #18
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]))
Beispiel #19
0
def init(root=None, path='traffic', port=9997):
    global _WebListener
    if root is not None:
        from transport import callback
        callback.insert_inbox_callback(-1, inbox)
        callback.add_finish_file_sending_callback(outbox)
        root.putChild(path, TrafficPage())
        return
    if _WebListener:
        return
    root = resource.Resource()
    root.putChild('', TrafficPage())
    site = server.Site(root)
    try:
        _WebListener = reactor.listenTCP(port, site)
    except:
        from logs import lg
        lg.exc()
        return
    from transport import callback
    callback.insert_inbox_callback(-1, inbox)
    callback.add_finish_file_sending_callback(outbox)
Beispiel #20
0
def init(root=None, path='traffic', port=9997):
    global _WebListener
    if root is not None:
        from transport import callback
        callback.insert_inbox_callback(-1, inbox)
        callback.add_finish_file_sending_callback(outbox)
        root.putChild(path, TrafficPage())
        return
    if _WebListener:
        return
    root = resource.Resource()
    root.putChild('', TrafficPage())
    site = server.Site(root)
    try:
        _WebListener = reactor.listenTCP(port, site)
    except:
        from logs import lg
        lg.exc()
        return
    from transport import callback
    callback.insert_inbox_callback(-1, inbox)
    callback.add_finish_file_sending_callback(outbox)
Beispiel #21
0
 def doInit(self, arg):
     """
     Action method.
     """
     callback.insert_inbox_callback(0, self._inbox_packet_received)
Beispiel #22
0
 def doInit(self, arg):
     """
     Action method.
     """
     self.exclude_nodes = arg[0]
     callback.insert_inbox_callback(0, self._inbox_packet_received)
 def doInit(self, arg):
     """
     Action method.
     """
     callback.insert_inbox_callback(0, self._inbox_packet_received)
Beispiel #24
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()