forked from indymedia/epicyon
Outbox thread
parent
7603b85ff7
commit
97665c08cb
42
daemon.py
42
daemon.py
|
@ -244,6 +244,21 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def _postToOutboxThread(self,messageJson: {}) -> bool:
|
||||||
|
"""Creates a thread to send a post
|
||||||
|
"""
|
||||||
|
if self.server.outboxThread:
|
||||||
|
print('Waiting for previous outbox thread to end')
|
||||||
|
while self.server.outboxThread.isAlive():
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
|
print('Creating outbox thread')
|
||||||
|
self.server.outboxThread= \
|
||||||
|
threadWithTrace(target=self._postToOutbox, \
|
||||||
|
args=(messageJson.copy()),daemon=True)
|
||||||
|
print('Starting outbox thread')
|
||||||
|
self.server.outboxThread.start()
|
||||||
|
|
||||||
def _postToOutbox(self,messageJson: {}) -> bool:
|
def _postToOutbox(self,messageJson: {}) -> bool:
|
||||||
"""post is received by the outbox
|
"""post is received by the outbox
|
||||||
Client to server message post
|
Client to server message post
|
||||||
|
@ -929,7 +944,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.debug, \
|
self.server.debug, \
|
||||||
self.server.projectVersion)
|
self.server.projectVersion)
|
||||||
if announceJson:
|
if announceJson:
|
||||||
self._postToOutbox(announceJson)
|
self._postToOutboxThread(announceJson)
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
self._redirect_headers(actor+'/inbox',cookie)
|
self._redirect_headers(actor+'/inbox',cookie)
|
||||||
return
|
return
|
||||||
|
@ -962,7 +977,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'type': 'Announce'
|
'type': 'Announce'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self._postToOutbox(newUndoAnnounce)
|
self._postToOutboxThread(newUndoAnnounce)
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
self._redirect_headers(actor+'/inbox',cookie)
|
self._redirect_headers(actor+'/inbox',cookie)
|
||||||
return
|
return
|
||||||
|
@ -1027,7 +1042,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'actor': likeActor,
|
'actor': likeActor,
|
||||||
'object': likeUrl
|
'object': likeUrl
|
||||||
}
|
}
|
||||||
self._postToOutbox(likeJson)
|
self._postToOutboxThread(likeJson)
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
self._redirect_headers(actor+'/inbox',cookie)
|
self._redirect_headers(actor+'/inbox',cookie)
|
||||||
return
|
return
|
||||||
|
@ -1057,7 +1072,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'object': likeUrl
|
'object': likeUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self._postToOutbox(undoLikeJson)
|
self._postToOutboxThread(undoLikeJson)
|
||||||
self.server.GETbusy=False
|
self.server.GETbusy=False
|
||||||
self._redirect_headers(actor+'/inbox',cookie)
|
self._redirect_headers(actor+'/inbox',cookie)
|
||||||
return
|
return
|
||||||
|
@ -1976,7 +1991,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'], fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
self.postToNickname=nickname
|
self.postToNickname=nickname
|
||||||
if self._postToOutbox(messageJson):
|
if self._postToOutboxThread(messageJson):
|
||||||
populateReplies(self.server.baseDir, \
|
populateReplies(self.server.baseDir, \
|
||||||
self.server.httpPrefix, \
|
self.server.httpPrefix, \
|
||||||
self.server.domainFull, \
|
self.server.domainFull, \
|
||||||
|
@ -1998,7 +2013,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'], fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
self.postToNickname=nickname
|
self.postToNickname=nickname
|
||||||
if self._postToOutbox(messageJson):
|
if self._postToOutboxThread(messageJson):
|
||||||
populateReplies(self.server.baseDir, \
|
populateReplies(self.server.baseDir, \
|
||||||
self.server.httpPrefix, \
|
self.server.httpPrefix, \
|
||||||
self.server.domain, \
|
self.server.domain, \
|
||||||
|
@ -2020,7 +2035,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
fields['replyTo'], fields['replyTo'],fields['subject'])
|
fields['replyTo'], fields['replyTo'],fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
self.postToNickname=nickname
|
self.postToNickname=nickname
|
||||||
if self._postToOutbox(messageJson):
|
if self._postToOutboxThread(messageJson):
|
||||||
populateReplies(self.server.baseDir, \
|
populateReplies(self.server.baseDir, \
|
||||||
self.server.httpPrefix, \
|
self.server.httpPrefix, \
|
||||||
self.server.domain, \
|
self.server.domain, \
|
||||||
|
@ -2049,7 +2064,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.postToNickname=nickname
|
self.postToNickname=nickname
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: new DM to '+str(messageJson['object']['to']))
|
print('DEBUG: new DM to '+str(messageJson['object']['to']))
|
||||||
if self._postToOutbox(messageJson):
|
if self._postToOutboxThread(messageJson):
|
||||||
populateReplies(self.server.baseDir, \
|
populateReplies(self.server.baseDir, \
|
||||||
self.server.httpPrefix, \
|
self.server.httpPrefix, \
|
||||||
self.server.domain, \
|
self.server.domain, \
|
||||||
|
@ -2079,7 +2094,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.debug,fields['subject'])
|
self.server.debug,fields['subject'])
|
||||||
if messageJson:
|
if messageJson:
|
||||||
self.postToNickname=nickname
|
self.postToNickname=nickname
|
||||||
if self._postToOutbox(messageJson):
|
if self._postToOutboxThread(messageJson):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
return -1
|
return -1
|
||||||
|
@ -2461,7 +2476,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'object': actorJson
|
'object': actorJson
|
||||||
}
|
}
|
||||||
self.postToNickname=nickname
|
self.postToNickname=nickname
|
||||||
self._postToOutbox(updateActorJson)
|
self._postToOutboxThread(updateActorJson)
|
||||||
self._redirect_headers(actorStr,cookie)
|
self._redirect_headers(actorStr,cookie)
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
|
@ -2737,7 +2752,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
pprint(deleteJson)
|
pprint(deleteJson)
|
||||||
self.postToNickname=getNicknameFromActor(removePostActor)
|
self.postToNickname=getNicknameFromActor(removePostActor)
|
||||||
if self.postToNickname:
|
if self.postToNickname:
|
||||||
self._postToOutbox(deleteJson)
|
self._postToOutboxThread(deleteJson)
|
||||||
self._redirect_headers(originPathStr+'/outbox',cookie)
|
self._redirect_headers(originPathStr+'/outbox',cookie)
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
|
@ -2818,7 +2833,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
}
|
}
|
||||||
pathUsersSection=self.path.split('/users/')[1]
|
pathUsersSection=self.path.split('/users/')[1]
|
||||||
self.postToNickname=pathUsersSection.split('/')[0]
|
self.postToNickname=pathUsersSection.split('/')[0]
|
||||||
self._postToOutbox(unfollowJson)
|
self._postToOutboxThread(unfollowJson)
|
||||||
self._redirect_headers(originPathStr,cookie)
|
self._redirect_headers(originPathStr,cookie)
|
||||||
self.server.POSTbusy=False
|
self.server.POSTbusy=False
|
||||||
return
|
return
|
||||||
|
@ -3165,7 +3180,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
# https://www.w3.org/TR/activitypub/#object-without-create
|
# https://www.w3.org/TR/activitypub/#object-without-create
|
||||||
if self.outboxAuthenticated:
|
if self.outboxAuthenticated:
|
||||||
if self._postToOutbox(messageJson):
|
if self._postToOutboxThread(messageJson):
|
||||||
if messageJson.get('id'):
|
if messageJson.get('id'):
|
||||||
self.headers['Location']= \
|
self.headers['Location']= \
|
||||||
messageJson['id'].replace('/activity','').replace('/undo','')
|
messageJson['id'].replace('/activity','').replace('/undo','')
|
||||||
|
@ -3293,6 +3308,7 @@ def runDaemon(projectVersion, \
|
||||||
else:
|
else:
|
||||||
httpd = ThreadingHTTPServer(serverAddress, PubServer)
|
httpd = ThreadingHTTPServer(serverAddress, PubServer)
|
||||||
# max POST size of 10M
|
# max POST size of 10M
|
||||||
|
httpd.outboxThread=None
|
||||||
httpd.projectVersion=projectVersion
|
httpd.projectVersion=projectVersion
|
||||||
httpd.maxPostLength=1024*1024*30
|
httpd.maxPostLength=1024*1024*30
|
||||||
httpd.maxMediaSize=httpd.maxPostLength
|
httpd.maxMediaSize=httpd.maxPostLength
|
||||||
|
|
Loading…
Reference in New Issue