コード例 #1
0
def createPost(postSubject, postText, parentFingerprint, ownerUsername,
               postLanguage):
    ephemeralConnectionId = int(random.random() * 10**10)
    post = Post(Subject=postSubject,
                Body=postText,
                OwnerUsername=ownerUsername,
                ParentPostFingerprint=parentFingerprint,
                LocallyCreated=True,
                Language=postLanguage,
                EphemeralConnectionId=ephemeralConnectionId,
                Upvoted=True,
                UpvoteCount=1)

    parent = session.query(Post).filter(
        Post.PostFingerprint == post.ParentPostFingerprint).one()
    postHeader = PostHeader(PostFingerprint=post.PostFingerprint,
                            ParentPostFingerprint=post.ParentPostFingerprint,
                            Language=postLanguage)

    localnode = session.query(Node).filter(
        Node.LastConnectedIP == 'LOCAL').one()
    vote = Vote(Direction=1, Node=localnode, PostHeader=postHeader)

    session.add(post)
    session.add(postHeader)
    session.add(vote)
    session.commit()
    print "The post has been added to the database."
    Demeter.incrementAncestryCommentCount(ephemeralConnectionId)
    if post.Subject == '':
        eventLoop.marduk(
        )  # Only call if post, because otherwise it results in a double call. And there is no way
        # to create a subject without a post anyway.
    return post.PostFingerprint
コード例 #2
0
ファイル: Hermes.py プロジェクト: Ryman/aether-public
def createPost(postSubject, postText, parentFingerprint, ownerUsername, postLanguage):
    ephemeralConnectionId = int(random.random()*10**10)
    post = Post(Subject=postSubject, Body=postText, OwnerUsername=ownerUsername,
                ParentPostFingerprint=parentFingerprint, LocallyCreated=True, Language=postLanguage,
                EphemeralConnectionId=ephemeralConnectionId, Upvoted=True, UpvoteCount=1)


    parent = session.query(Post).filter(Post.PostFingerprint == post.ParentPostFingerprint).one()
    postHeader = PostHeader(PostFingerprint=post.PostFingerprint,
                            ParentPostFingerprint=post.ParentPostFingerprint, Language=postLanguage
                            )

    localnode = session.query(Node).filter(Node.LastConnectedIP=='LOCAL').one()
    vote = Vote(Direction=1,Node=localnode, PostHeader=postHeader)

    session.add(post)
    session.add(postHeader)
    session.add(vote)
    session.commit()
    print "The post has been added to the database."
    Demeter.incrementAncestryCommentCount(ephemeralConnectionId)
    if post.Subject == '':
        eventLoop.marduk() # Only call if post, because otherwise it results in a double call. And there is no way
        # to create a subject without a post anyway.
    return post.PostFingerprint
コード例 #3
0
ファイル: Hermes.py プロジェクト: Ryman/aether-public
def createTopic(topicName):
    ephemeralConnectionId = int(random.random()*10**10)
    topic = Post(Subject= topicName, LocallyCreated=True, EphemeralConnectionId=ephemeralConnectionId)
    topicHeader = PostHeader(PostFingerprint=topic.PostFingerprint, Dirty = False)
    session.add(topic)
    session.add(topicHeader)
    session.commit()
    print "This topic has been added to the database"
    Demeter.incrementAncestryCommentCount(ephemeralConnectionId)
    return topic.PostFingerprint
コード例 #4
0
 def guiCommitted(self, PostFingerprint):
     #committer.commit()
     # TODO: Do other stuff required when user adds something.
     # I need to find the last n dudes I connected at, and ignore the cooldown and connect back to them
     # to serve my newest shit.
     # Okay, get the connectToNode method
     Demeter.committer.newPostsToIncrement.append(PostFingerprint)
     Demeter.connectToLastConnected(10)
     print('I received a commit signal from main (gui) process.')
     return {}
コード例 #5
0
 def guiCommitted(self, PostFingerprint):
     #committer.commit()
     # TODO: Do other stuff required when user adds something.
     # I need to find the last n dudes I connected at, and ignore the cooldown and connect back to them
     # to serve my newest shit.
     # Okay, get the connectToNode method
     Demeter.committer.newPostsToIncrement.append(PostFingerprint)
     Demeter.connectToLastConnected(10)
     print('I received a commit signal from main (gui) process.')
     return {}
コード例 #6
0
ファイル: aetherProtocol.py プロジェクト: Ryman/aether-public
 def connectionLost(self, reason):
     print('Connection lost. Reason: %s' %reason)
     self.factory.currentConnectionCount -= 1
     self.statusCheckerLoop.stop()
     Demeter.incrementAncestryCommentCount(self.ephemeralConnectionId) # this increments all parency of new posts' comment count.
     try:
         cprint('REMOTE %s HAS SUCCESSFULLY CLOSED THE CONNECTION at UTC %s'
                %(self.connectedNode['NodeId'], datetime.utcnow()), 'grey', 'on_white', attrs=['bold'])
     except:
         cprint('SOMETHING WENT HORRIBLY WRONG. THE CONNECTION FAILED BEFORE THE HANDSHAKE. ONE OF THE PEERS MIGHT HAVE '
                'ATTEMPTED AN ILLEGAL REQUEST SUCH AS A NON-ENCRYPTED CONNECTION OR DIDN\'T FOLLOW THE PROTOCOL. \nEXITING.'
             , 'white', 'on_red', attrs=['bold'])
コード例 #7
0
def createTopic(topicName):
    ephemeralConnectionId = int(random.random() * 10**10)
    topic = Post(Subject=topicName,
                 LocallyCreated=True,
                 EphemeralConnectionId=ephemeralConnectionId)
    topicHeader = PostHeader(PostFingerprint=topic.PostFingerprint,
                             Dirty=False)
    session.add(topic)
    session.add(topicHeader)
    session.commit()
    print "This topic has been added to the database"
    Demeter.incrementAncestryCommentCount(ephemeralConnectionId)
    return topic.PostFingerprint
コード例 #8
0
ファイル: eventLoop.py プロジェクト: anastiel/aether-public
def marduk(factoryInstance, committerInstance):
    if globals.appIsPaused: # If the app is explicitly paused, don't create active network events.
        return

    d3 = Demeter.getNodesToConnect(maxOutboundCount, cooldown)
    print('max outbound count:', maxOutboundCount, 'cooldown:', cooldown)
    def connectToNodes(nodes, openConnsList):
        # if not committerInstance.commitInProgress: # Don't connect outbound if a commit is in progress.
        if len(nodes) == 0:
            print('There are no nodes to connect to!')
            lastBareIP = globals.userProfile.get('machineDetails', 'lastConnectedBareIP')
            lastBarePort = globals.userProfile.get('machineDetails', 'lastConnectedBarePort')
            if isinstance(lastBarePort, int) and isinstance(lastBareIP, basestring) and \
                            lastBarePort != 0 and not Demeter.committer.commitInProgress:
            # Only connect if there is a bare connection request before and there is no commit in progress.
            # This is to prevent the first connection repeatedly calling over and wasting bandwidth while he has
            # everything in memory, just committing.
                print('Reaching out to the last bare '
                      'connect attempt at %s : %s' % (lastBareIP, lastBarePort))
                connectWithIP(lastBareIP, lastBarePort)
            else:
                print('This computer has never bare-connected to another node or a commit is in progress. '
                      'This usually means onboarding is not completed. lastBarePort = %s, commitInProgress = %s' %
                      (lastBarePort, Demeter.committer.commitInProgress))
        print('Number of open connections:', len(openConnsList))
        for n in nodes:
             print('I\'m attempting to connect to node %s at %s:%s'
                   %(n.NodeId,
                     n.LastConnectedIP if n.LastConnectedIP is not None else n.LastRetrievedIP,
                     n.LastConnectedPort if n.LastConnectedPort is not None else n.LastRetrievedPort))
             connectWithNode(n.asDict())
        # else:
        #     print('A commit is in progress. Skipping this round of marduk.')
    d3.addCallback(connectToNodes, factoryInstance.openConnections)
コード例 #9
0
def marduk(factoryInstance, committerInstance):
    if globals.appIsPaused:  # If the app is explicitly paused, don't create active network events.
        return

    d3 = Demeter.getNodesToConnect(globals.maxOutboundCount, globals.cooldown)
    print('max outbound count:', globals.maxOutboundCount, 'cooldown:',
          globals.cooldown)

    def connectToNodes(nodes, openConnsList):
        if len(nodes) == 0:
            # If this is a bootstrap.
            global firstConnectTriggered
            if not firstConnectTriggered and (globals.newborn or globals.nuked
                                              or globals.resetted):
                firstConnectTriggered = True
                print('We\'re bootstrapping!')
                connectWithIP('151.236.11.192', 39994)  # austria #FIXME 39994
            else:
                print('There are no nodes to connect to!')
                print('Number of open connections:', len(openConnsList),
                      'Commit in Progress: ',
                      committerInstance.commitInProgress)
                if not len(openConnsList
                           ) and not committerInstance.commitInProgress:
                    connectWithIP('151.236.11.192',
                                  39994)  # austria #FIXME 39994

        for n in nodes:
            print('I\'m attempting to connect to node %s at %s:%s' %
                  (n.NodeId, n.LastConnectedIP if n.LastConnectedIP is not None
                   else n.LastRetrievedIP, n.LastConnectedPort if
                   n.LastConnectedPort is not None else n.LastRetrievedPort))
            connectWithNode(n.asDict())

    d3.addCallback(connectToNodes, factoryInstance.openConnections)
コード例 #10
0
ファイル: eventLoop.py プロジェクト: gordol/aether-public
def marduk(factoryInstance, committerInstance):
    if globals.appIsPaused: # If the app is explicitly paused, don't create active network events.
        return

    d3 = Demeter.getNodesToConnect(globals.maxOutboundCount, globals.cooldown)
    print('max outbound count:', globals.maxOutboundCount, 'cooldown:', globals.cooldown)
    def connectToNodes(nodes, openConnsList):
        if len(nodes) == 0:
            # If this is a bootstrap.
            global firstConnectTriggered
            if not firstConnectTriggered and (globals.newborn or globals.nuked or globals.resetted):
                firstConnectTriggered = True
                print('We\'re bootstrapping!')
                connectWithIP('151.236.11.192', 39994) # austria #FIXME 39994
            else:
                print('There are no nodes to connect to!')
                print('Number of open connections:', len(openConnsList), 'Commit in Progress: ', committerInstance.commitInProgress)
                if not len(openConnsList) and not committerInstance.commitInProgress:
                    connectWithIP('151.236.11.192', 39994) # austria #FIXME 39994

        for n in nodes:
             print('I\'m attempting to connect to node %s at %s:%s'
                   %(n.NodeId,
                     n.LastConnectedIP if n.LastConnectedIP is not None else n.LastRetrievedIP,
                     n.LastConnectedPort if n.LastConnectedPort is not None else n.LastRetrievedPort))
             connectWithNode(n.asDict())
    d3.addCallback(connectToNodes, factoryInstance.openConnections)
コード例 #11
0
 def connectionLost(self, reason):
     print('Connection lost. Reason: %s' % reason)
     self.factory.currentConnectionCount -= 1
     self.statusCheckerLoop.stop()
     Demeter.incrementAncestryCommentCount(
         self.ephemeralConnectionId
     )  # this increments all parency of new posts' comment count.
     try:
         cprint(
             'REMOTE %s HAS SUCCESSFULLY CLOSED THE CONNECTION at UTC %s' %
             (self.connectedNode['NodeId'], datetime.utcnow()),
             'grey',
             'on_white',
             attrs=['bold'])
     except:
         cprint(
             'SOMETHING WENT HORRIBLY WRONG. THE CONNECTION FAILED BEFORE THE HANDSHAKE. ONE OF THE PEERS MIGHT HAVE '
             'ATTEMPTED AN ILLEGAL REQUEST SUCH AS A NON-ENCRYPTED CONNECTION OR DIDN\'T FOLLOW THE PROTOCOL. \nEXITING.',
             'white',
             'on_red',
             attrs=['bold'])
コード例 #12
0
def main():
    ampChildPath = 'InputOutput.interprocessChildProt.NetworkingProcessProtocol'
    from twisted.internet import stdio
    from twisted.python import reflect
    protInstance = reflect.namedAny(ampChildPath)(
        reactor)  # Invoke what you found.
    Demeter.committer.receiveInterprocessProtocolInstance(protInstance)
    d = Demeter.checkUPNPStatus(2000)

    def maybeCommit():
        print(
            'Attempting to commit. Commit In Progress flag is %s, last commit was at %s'
            %
            (Demeter.committer.commitInProgress, Demeter.committer.lastCommit))
        if Demeter.committer.commitInProgress is False:
            print('Commit loop decided to commit. #COMMITSTART')
            Demeter.committer.commit()
        else:
            print(
                'Commit loop decided to NOT commit, variables are: commitInProgress = %s, lastCommit = %s '
                '#COMMITDECLINE' % (Demeter.committer.commitInProgress,
                                    Demeter.committer.lastCommit))

    persephone = LoopingCall(maybeCommit)
    persephone.start(30)  # this should be 60 under normal circumstances.
    marduk = LoopingCall(eventLoop.marduk,
                         aetherProtocol.aetherProtocolFactoryInstance,
                         Demeter.committer)
    marduk.start(30)  # Should this be 5 minutes? (300)
    listenerEndpoint = SSL4ServerEndpoint(
        reactor, globals.userProfile.get('machineDetails', 'listeningPort'),
        globals.AetherContextFactory())
    listenerEndpoint.listen(aetherProtocol.aetherProtocolFactoryInstance)

    if FROZEN:
        if PLATFORM == 'WIN':
            stdio.StandardIO(protInstance)
        elif PLATFORM == 'OSX':
            stdio.StandardIO(protInstance, 7, 8)
        elif PLATFORM == 'LNX':
            stdio.StandardIO(protInstance, 7, 8)
    else:
        if PLATFORM == 'WIN':
            stdio.StandardIO(protInstance)
        elif PLATFORM == 'OSX':
            stdio.StandardIO(protInstance, 7, 8)
        elif PLATFORM == 'LNX':
            stdio.StandardIO(protInstance, 7, 8)

    reactor.run()
コード例 #13
0
def marduk():
    if globals.appIsPaused: # If the app is explicitly paused, don't create active network events.
        return

    d3 = Demeter.getNodesToConnect(10, 0)
    def connectToNodes(nodes):
        if len(nodes) == 0 and (globals.newborn or globals.nuked):
        # If there is only the local node, that means no one to connect to.
            print('There are no nodes to connect to!')
            connectWithIP('151.236.11.192', 39994) # austria
        for n in nodes:
             print('I\'m attempting to connect to node %s at %s:%s'
                   %(n.NodeId,
                     n.LastConnectedIP if n.LastConnectedIP is not None else n.LastRetrievedIP,
                     n.LastConnectedPort if n.LastConnectedPort is not None else n.LastRetrievedPort))
             connectWithNode(n.asDict())
    d3.addCallback(connectToNodes)
コード例 #14
0
def main():
    ampChildPath = 'InputOutput.interprocessChildProt.NetworkingProcessProtocol'
    from twisted.internet import stdio
    from twisted.python import reflect
    protInstance = reflect.namedAny(ampChildPath)(reactor)  # Invoke what you found.
    Demeter.committer.receiveInterprocessProtocolInstance(protInstance)
    d = Demeter.checkUPNPStatus(2000)

    def maybeCommit():
        print('Attempting to commit. Commit In Progress flag is %s, last commit was at %s' %
              (Demeter.committer.commitInProgress, Demeter.committer.lastCommit))
        if Demeter.committer.commitInProgress is False:
            print('Commit loop decided to commit. #COMMITSTART')
            Demeter.committer.commit()
        else:
            print('Commit loop decided to NOT commit, variables are: commitInProgress = %s, lastCommit = %s '
                  '#COMMITDECLINE' % (Demeter.committer.commitInProgress, Demeter.committer.lastCommit))

    persephone = LoopingCall(maybeCommit)
    persephone.start(30)  # this should be 60 under normal circumstances.
    marduk = LoopingCall(eventLoop.marduk, aetherProtocol.aetherProtocolFactoryInstance, Demeter.committer)
    marduk.start(30)  # Should this be 5 minutes? (300)
    listenerEndpoint = SSL4ServerEndpoint(reactor, globals.userProfile.get('machineDetails', 'listeningPort'), globals.AetherContextFactory())
    listenerEndpoint.listen(aetherProtocol.aetherProtocolFactoryInstance)

    if FROZEN:
        if PLATFORM == 'WIN':
            stdio.StandardIO(protInstance)
        elif PLATFORM == 'OSX':
            stdio.StandardIO(protInstance, 7, 8)
        elif PLATFORM == 'LNX':
            stdio.StandardIO(protInstance, 7, 8)
    else:
        if PLATFORM == 'WIN':
            stdio.StandardIO(protInstance)
        elif PLATFORM == 'OSX':
            stdio.StandardIO(protInstance, 7, 8)
        elif PLATFORM == 'LNX':
            stdio.StandardIO(protInstance, 7, 8)

    reactor.run()
コード例 #15
0
def marduk(factoryInstance, committerInstance):
    if globals.appIsPaused:  # If the app is explicitly paused, don't create active network events.
        return

    d3 = Demeter.getNodesToConnect(maxOutboundCount, cooldown)
    print('max outbound count:', maxOutboundCount, 'cooldown:', cooldown)

    def connectToNodes(nodes, openConnsList):
        # if not committerInstance.commitInProgress: # Don't connect outbound if a commit is in progress.
        if len(nodes) == 0:
            print('There are no nodes to connect to!')
            lastBareIP = globals.userProfile.get('machineDetails',
                                                 'lastConnectedBareIP')
            lastBarePort = globals.userProfile.get('machineDetails',
                                                   'lastConnectedBarePort')
            if isinstance(lastBarePort, int) and isinstance(lastBareIP, basestring) and \
                            lastBarePort != 0 and not Demeter.committer.commitInProgress:
                # Only connect if there is a bare connection request before and there is no commit in progress.
                # This is to prevent the first connection repeatedly calling over and wasting bandwidth while he has
                # everything in memory, just committing.
                print('Reaching out to the last bare '
                      'connect attempt at %s : %s' %
                      (lastBareIP, lastBarePort))
                connectWithIP(lastBareIP, lastBarePort)
            else:
                print(
                    'This computer has never bare-connected to another node or a commit is in progress. '
                    'This usually means onboarding is not completed. lastBarePort = %s, commitInProgress = %s'
                    % (lastBarePort, Demeter.committer.commitInProgress))
        print('Number of open connections:', len(openConnsList))
        for n in nodes:
            print('I\'m attempting to connect to node %s at %s:%s' %
                  (n.NodeId, n.LastConnectedIP if n.LastConnectedIP is not None
                   else n.LastRetrievedIP, n.LastConnectedPort if
                   n.LastConnectedPort is not None else n.LastRetrievedPort))
            connectWithNode(n.asDict())
        # else:
        #     print('A commit is in progress. Skipping this round of marduk.')

    d3.addCallback(connectToNodes, factoryInstance.openConnections)
コード例 #16
0
ファイル: main.py プロジェクト: gordol/aether-public
def main():

    from InputOutput import interprocessChildProt
    from ampoule import pool
    from  InputOutput import interprocessParentProt
    from ampoule import main as ampouleMain

    procStarter = ampouleMain.ProcessStarter(bootstrap=interprocessChildProt.childBootstrap)
    global pp
    pp = pool.ProcessPool(interprocessChildProt.GUIProcessProtocol,
                          ampParent=interprocessParentProt.MainProcessProtocol,
                          starter=procStarter,
                          recycleAfter=0,
                          min=1, max=1)

    pp.start()
    pp.ampParent.processPool = pp # Self referential much?

    Demeter.committer.receiveInterprocessProtocolInstance(pp)

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

    d = Demeter.checkUPNPStatus(2000)

    def maybeCommit():
        thirtySecondsAgo = datetime.datetime.utcnow() - datetime.timedelta(seconds=10) # FIXME make it 30 in live.
        if Demeter.committer.lastCommit < thirtySecondsAgo and Demeter.committer.commitInProgress is False:
            print('Commit loop decided to commit.')
            Demeter.committer.commit()

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

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


    # def checksan():
    #     d = pp.callRemote(interprocessChildProt.checkSanity)
    #     d.addCallback(print)
    # def bootstuff():
    #     d = pp.callRemote(interprocessChildProt.bootGUI)
    #     d.addCallback(print)
    # reactor.callLater(2, bootstuff)
    # reactor.callLater(20, checksan)
    #reactor.callLater(5, aetherProtocol.connectWithIP,'151.236.11.192', 39994) #192 ends
    reactor.run()
コード例 #17
0
ファイル: main.py プロジェクト: Ryman/aether-public
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()
コード例 #18
0
def persephone():
    Demeter.updatePostStatus()
コード例 #19
0
ファイル: main.py プロジェクト: Ryman/aether-public
 def upnpSanityCheck(returnVal):
     if returnVal is False:
         print('Oops, the network could not map in 10 seconds. Trying a minute.')
         Demeter.checkUPNPStatus(60000)
コード例 #20
0
ファイル: main.py プロジェクト: payingattention/aether-public
def main():

    from InputOutput import interprocessChildProt
    from ampoule import pool
    from InputOutput import interprocessParentProt
    from ampoule import main as ampouleMain

    procStarter = ampouleMain.ProcessStarter(
        bootstrap=interprocessChildProt.childBootstrap)
    global pp
    pp = pool.ProcessPool(interprocessChildProt.GUIProcessProtocol,
                          ampParent=interprocessParentProt.MainProcessProtocol,
                          starter=procStarter,
                          recycleAfter=0,
                          min=1,
                          max=1)

    pp.start()
    pp.ampParent.processPool = pp  # Self referential much?

    Demeter.committer.receiveInterprocessProtocolInstance(pp)

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

    d = Demeter.checkUPNPStatus(2000)

    def maybeCommit():
        thirtySecondsAgo = datetime.datetime.utcnow() - datetime.timedelta(
            seconds=10)  # FIXME make it 30 in live.
        if Demeter.committer.lastCommit < thirtySecondsAgo and Demeter.committer.commitInProgress is False:
            print('Commit loop decided to commit.')
            Demeter.committer.commit()

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

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

    # def checksan():
    #     d = pp.callRemote(interprocessChildProt.checkSanity)
    #     d.addCallback(print)
    # def bootstuff():
    #     d = pp.callRemote(interprocessChildProt.bootGUI)
    #     d.addCallback(print)
    # reactor.callLater(2, bootstuff)
    # reactor.callLater(20, checksan)
    #reactor.callLater(5, aetherProtocol.connectWithIP,'151.236.11.192', 39994) #192 ends
    reactor.run()
コード例 #21
0
ファイル: main.py プロジェクト: ailurocrat/aether-public
 def upnpSanityCheck(returnVal):
     if returnVal is False:
         print(
             'Oops, the network could not map in 10 seconds. Trying a minute.'
         )
         Demeter.checkUPNPStatus(60000)
コード例 #22
0
ファイル: main.py プロジェクト: ailurocrat/aether-public
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()