def main(reactorString, ampChildPath):
#def main():

    from twisted.internet import reactor, stdio
    from twisted.python import reflect, runtime
    #ampChild = reflect.namedAny(ampChildPath)
    #protInstance = ampChild(*sys.argv[1:-2]) # This is how you reach the prot from here.
    protInstance = ''

    from twisted.internet import reactor # this is actually used, ignore the warning.
    hermes = Hermes.Hermes(protInstance)
    charon = Charon(hermes)
    view = AetherMainWindow(charon, reactor, baseurl, protInstance)
    trayIcon = SystemTrayIcon(basedir, app, view)
    trayIcon.protInstance = protInstance
    #protInstance.trayIcon = trayIcon
    ef = ModifierEventFilter()
    app.view = view
    ef.view = view
    app.trayIcon = trayIcon
    view.trayIcon = trayIcon
    ef.trayIcon = trayIcon
    charon.trayIcon = trayIcon
    trayIcon.webView = view
    app.installEventFilter(ef)
    trayIcon.show()

    #FIXME before package
    enableWebkitInspector = False
    if enableWebkitInspector is True:
        from PyQt5.QtWebKit import QWebSettings
        QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
        inspect = QWebInspector()
        inspect.resize(1450, 300)
        inspect.move(0,0)
        inspect.setPage(view.webView.page())
        view.setContextMenuPolicy(Qt.DefaultContextMenu)
        inspect.show()

    splash.finish(view)
    if not globals.appStartedAtBoot:
        view.show()
        trayIcon.toggleVisibilityMenuItem.setText('Hide Aether')

    if runtime.platform.isWindows():
        stdio.StandardIO(protInstance)
    else:
        stdio.StandardIO(protInstance, 3, 4)
    #enter = getattr(ampChild, '__enter__', None)
    # if enter is not None:
    #     enter()
    # try:
    #     reactor.run()
    # except:
    #     if enter is not None:
    #         info = sys.exc_info()
    #         if not ampChild.__exit__(*info):
    #             raise
    #     else:
    #         raise
    # else:
    #     if enter is not None:
    #         ampChild.__exit__(None, None, None)
    reactor.run()
Example #2
0
def main():
    from time import sleep
    charon = Charon()
    global view
    view = aetherMainWindow(reactor)
    view.page().mainFrame().addToJavaScriptWindowObject("Charon", charon)
    view.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)

    def checkForUpdates():
        # One catch, any result available out of this will only be visible after next boot of the app.
        d = getPage('http://192.30.33.227')

        def processReceivedVersion(reply):

            if int(reply[:3]) > globals.appVersion:
                globals.updateAvailable = True
                print(
                    'There is an update available, local version is %d and gathered version is %s.'
                    % (globals.appVersion, reply))
            else:
                globals.updateAvailable = False
                print('There is no update available')
            globals.setUpdateAvailable(globals.updateAvailable)

        d.addCallback(processReceivedVersion)

    checkForUpdates()

    def iconClicked(self, reason):
        pass

    trayIcon = SystemTrayIcon(iconClicked, view)
    trayIcon.show()

    d = Demeter.checkUPNPStatus(10000)

    def upnpSanityCheck(returnVal):
        if returnVal is False:
            print(
                'Oops, the network could not map in 10 seconds. Trying a minute.'
            )
            Demeter.checkUPNPStatus(60000)
            # If that also fails, we're in hostile territory.

    d.addCallback(upnpSanityCheck)

    persephone = LoopingCall(eventLoop.persephone)
    persephone.start(10)  # this should be 60 under normal circumstances.
    marduk = LoopingCall(eventLoop.marduk)
    marduk.start(60)  # 5 minutes normally, which is 300

    logSender = LoopingCall(eventLoop.sendLogs, reactor)
    logSender.start(86400)  # send it every day.

    #enableWebkitInspector = True
    if enableWebkitInspector is True:
        from PyQt5.QtWebKit import QWebSettings
        QWebSettings.globalSettings().setAttribute(
            QWebSettings.DeveloperExtrasEnabled, True)
        inspect = QWebInspector()
        inspect.resize(1450, 300)
        inspect.move(0, 0)
        inspect.setPage(view.page())
        view.setContextMenuPolicy(Qt.DefaultContextMenu)
        inspect.show()

    listenerEndpoint = SSL4ServerEndpoint(reactor, aetherListeningPort,
                                          globals.AetherContextFactory())
    listenerEndpoint.listen(aetherProtocol.AetherProtocolFactory())

    splash.finish(view)
    if not globals.appStartedAtBoot:
        view.show()
        toggleVisibilityMenuItem.setText('Hide Aether')
    reactor.run()
Example #3
0
def main():

    global reactor

    from twisted.internet import reactor

    print('Spawning the networking daemon...')
    # Spawn the networking daemon.
    from InputOutput import interprocessChildProt
    from ampoule_aether import pool
    from InputOutput import interprocessParentProt
    from ampoule_aether import main as ampouleMain

    if FROZEN:
        procStarter = ampouleMain.ProcessStarter()
    else:
        procStarter = ampouleMain.ProcessStarter(
            bootstrap=interprocessChildProt.childBootstrap)

    global pp
    pp = pool.ProcessPool(interprocessChildProt.NetworkingProcessProtocol,
                          ampParent=interprocessParentProt.MainProcessProtocol,
                          starter=procStarter,
                          recycleAfter=0,
                          min=1,
                          max=1)

    pp.start()
    pp.ampParent.processPool = pp  # Self referential much?
    # Networking daemon spawnage ends here.
    print('Networking daemon spawned.')

    hermes = Hermes.Hermes(pp)

    charon = Charon(hermes)
    view = AetherMainWindow(charon, reactor, baseurl, app)
    if PLATFORM == 'OSX' or PLATFORM == 'WIN':
        trayIcon = SystemTrayIcon(BASEDIR, app, view)
    # trayIcon.protInstance = protInstance
    # protInstance.trayIcon = trayIcon
    ef = ModifierEventFilter()
    app.view = view
    ef.view = view
    view.pp = pp
    if PLATFORM == 'OSX' or PLATFORM == 'WIN':
        app.trayIcon = trayIcon
        view.trayIcon = trayIcon
        ef.trayIcon = trayIcon
        charon.trayIcon = trayIcon
        trayIcon.webView = view
        trayIcon.show()
    app.installEventFilter(ef)

    # Attach the items to the parent protocol, so it can react on the events arriving from networking daemon.
    pp.ampParent.Hermes = hermes
    if PLATFORM == 'OSX' or PLATFORM == 'WIN':
        pp.ampParent.trayIcon = trayIcon
    pp.ampParent.JSContext = view.JSContext

    if globals.userProfile.get('debugDetails', 'enableWebkitInspector'):
        from PyQt5.QtWebKit import QWebSettings
        QWebSettings.globalSettings().setAttribute(
            QWebSettings.DeveloperExtrasEnabled, True)
        inspect = QWebInspector()
        inspect.resize(1450, 300)
        inspect.move(0, 0)
        inspect.setPage(view.webView.page())
        view.setContextMenuPolicy(Qt.DefaultContextMenu)
        inspect.show()

    splash.finish(view)
    if globals.APP_STARTED_AT_SYSTEM_STARTUP:
        if PLATFORM == 'LNX':
            # Because there is no tray icon on Linux, app starts minimised ( (-) state).
            view.showMinimized()
        elif PLATFORM == 'OSX' or PLATFORM == 'WIN':
            pass  # Do nothing, there is already a tray icon in place.
    else:  # If not started at boot
        view.show()

    def checkForUpdates():

        # One catch, any result available out of this will only be visible after next boot of the app.
        d = getPage('http://www.getaether.net/updatecheck')

        def processReceivedVersion(reply):
            if int(reply[:3]) > AETHER_VERSION:
                globals.userProfile.set('machineDetails', 'updateAvailable',
                                        True)
                print(
                    'There is an update available, local version is %d and gathered version is %s.'
                    % (AETHER_VERSION, reply))
            else:
                globals.userProfile.set('machineDetails', 'updateAvailable',
                                        False)
                print('There is no update available')

        return d.addCallback(processReceivedVersion)

    if globals.userProfile.get('machineDetails', 'checkForUpdates'):
        d = checkForUpdates()
        d.addErrback(
            print,
            'Checking for updates failed. Either the server is down, or the internet connection is not available.'
        )

    def setPublicIPAddress():
        # For privacy reasons, this can be disabled by setting 'allowPublicIPLookup' to false at your user profile json.
        # The only use case for this is to show you your IP address in the settings, so you can give your IP address
        # and port to your friend to use you as the bootstrap node. If you can read this, you don't need that. Disable.
        data = str(urlopen('http://checkip.dyndns.com/').read())
        result = re.compile(r'Address: (\d+\.\d+\.\d+\.\d+)').search(
            data).group(1)
        globals.userProfile.set('machineDetails', 'externalIP', result)
        print('Public IP of this machine is %s' % result)
        return True

    if globals.userProfile.get('machineDetails', 'allowPublicIPLookup'):
        d2 = threads.deferToThread(setPublicIPAddress)
        # d2.addErrback(print, 'The public IP address could not be found. The internet connection is not available.')

    reactor.run()
Example #4
0
def main():

    global reactor

    from twisted.internet import reactor

    print('Spawning the networking daemon...')
    # Spawn the networking daemon.
    from InputOutput import interprocessChildProt
    from ampoule_aether import pool
    from  InputOutput import interprocessParentProt
    from ampoule_aether import main as ampouleMain

    if FROZEN:
        procStarter = ampouleMain.ProcessStarter()
    else:
        procStarter = ampouleMain.ProcessStarter(bootstrap=interprocessChildProt.childBootstrap)


    global pp
    pp = pool.ProcessPool(interprocessChildProt.NetworkingProcessProtocol,
                          ampParent=interprocessParentProt.MainProcessProtocol,
                          starter=procStarter,
                          recycleAfter=0,
                          min=1, max=1)

    pp.start()
    pp.ampParent.processPool = pp # Self referential much?
    # Networking daemon spawnage ends here.
    print('Networking daemon spawned.')


    hermes = Hermes.Hermes(pp)

    charon = Charon(hermes)
    view = AetherMainWindow(charon, reactor, baseurl, app)
    if PLATFORM == 'OSX' or PLATFORM == 'WIN':
        trayIcon = SystemTrayIcon(BASEDIR, app, view)
    # trayIcon.protInstance = protInstance
    # protInstance.trayIcon = trayIcon
    ef = ModifierEventFilter()
    app.view = view
    ef.view = view
    view.pp = pp
    if PLATFORM == 'OSX' or PLATFORM == 'WIN':
        app.trayIcon = trayIcon
        view.trayIcon = trayIcon
        ef.trayIcon = trayIcon
        charon.trayIcon = trayIcon
        trayIcon.webView = view
        trayIcon.show()
    app.installEventFilter(ef)


    # Attach the items to the parent protocol, so it can react on the events arriving from networking daemon.
    pp.ampParent.Hermes = hermes
    if PLATFORM == 'OSX' or PLATFORM == 'WIN':
        pp.ampParent.trayIcon = trayIcon
    pp.ampParent.JSContext = view.JSContext


    if globals.userProfile.get('debugDetails', 'enableWebkitInspector'):
        from PyQt5.QtWebKit import QWebSettings
        QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
        inspect = QWebInspector()
        inspect.resize(1450, 300)
        inspect.move(0,0)
        inspect.setPage(view.webView.page())
        view.setContextMenuPolicy(Qt.DefaultContextMenu)
        inspect.show()

    splash.finish(view)
    if globals.APP_STARTED_AT_SYSTEM_STARTUP:
        if PLATFORM == 'LNX':
            # Because there is no tray icon on Linux, app starts minimised ( (-) state).
            view.showMinimized()
        elif PLATFORM == 'OSX' or PLATFORM == 'WIN':
            pass # Do nothing, there is already a tray icon in place.
    else: # If not started at boot
        view.show()


    def checkForUpdates():

        # One catch, any result available out of this will only be visible after next boot of the app.
        d = getPage('http://www.getaether.net/updatecheck')

        def processReceivedVersion(reply):
            if int(reply[:3]) > AETHER_VERSION:
                globals.userProfile.set('machineDetails', 'updateAvailable', True)
                print('There is an update available, local version is %d and gathered version is %s.'
                      % (AETHER_VERSION, reply))
            else:
                globals.userProfile.set('machineDetails', 'updateAvailable', False)
                print('There is no update available')

        return d.addCallback(processReceivedVersion)

    if globals.userProfile.get('machineDetails', 'checkForUpdates'):
        d = checkForUpdates()
        d.addErrback(print,
                     'Checking for updates failed. Either the server is down, or the internet connection is not available.')

    def setPublicIPAddress():
        # For privacy reasons, this can be disabled by setting 'allowPublicIPLookup' to false at your user profile json.
        # The only use case for this is to show you your IP address in the settings, so you can give your IP address
        # and port to your friend to use you as the bootstrap node. If you can read this, you don't need that. Disable.
        data = str(urlopen('http://checkip.dyndns.com/').read())
        result = re.compile(r'Address: (\d+\.\d+\.\d+\.\d+)').search(data).group(1)
        globals.userProfile.set('machineDetails', 'externalIP', result)
        print('Public IP of this machine is %s' % result)
        return True



    if globals.userProfile.get('machineDetails', 'allowPublicIPLookup'):
        d2 = threads.deferToThread(setPublicIPAddress)
        # d2.addErrback(print, 'The public IP address could not be found. The internet connection is not available.')

    reactor.run()