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
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
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
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'])
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
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'])