Limit inbox queue length

master
Bob Mottram 2019-07-15 13:27:26 +01:00
parent 1871e90bf8
commit 1f2a3dbb42
2 changed files with 32 additions and 6 deletions

View File

@ -152,9 +152,14 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain,messageJson,'outbox') self.server.domain,messageJson,'outbox')
return True return True
def _updateInboxQueue(self,nickname: str,messageJson: {}) -> bool: def _updateInboxQueue(self,nickname: str,messageJson: {}) -> int:
"""Update the inbox queue """Update the inbox queue
""" """
# Check if the queue is full
if len(self.server.inboxQueue)>=self.server.maxQueueLength:
return 1
# save the json for later queue processing
queueFilename = \ queueFilename = \
savePostToInboxQueue(self.server.baseDir, \ savePostToInboxQueue(self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
@ -166,13 +171,14 @@ class PubServer(BaseHTTPRequestHandler):
'/'+self.path.split('/')[-1], '/'+self.path.split('/')[-1],
self.server.debug) self.server.debug)
if queueFilename: if queueFilename:
# add json to the queue
if queueFilename not in self.server.inboxQueue: if queueFilename not in self.server.inboxQueue:
self.server.inboxQueue.append(queueFilename) self.server.inboxQueue.append(queueFilename)
self.send_response(201) self.send_response(201)
self.end_headers() self.end_headers()
self.server.POSTbusy=False self.server.POSTbusy=False
return True return 0
return False return 2
def _isAuthorized(self) -> bool: def _isAuthorized(self) -> bool:
if self.headers.get('Authorization'): if self.headers.get('Authorization'):
@ -644,7 +650,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
self.postToNickname=pathUsersSection.split('/')[0] self.postToNickname=pathUsersSection.split('/')[0]
if self.postToNickname: if self.postToNickname:
if self._updateInboxQueue(self.postToNickname,messageJson): queueStatus=self._updateInboxQueue(self.postToNickname,messageJson)
if queueStatus==0:
self.send_response(200)
self.end_headers()
self.server.POSTbusy=False
return
if queueStatus==1:
self.send_response(403)
self.end_headers()
self.server.POSTbusy=False
return return
self.send_response(403) self.send_response(403)
self.end_headers() self.end_headers()
@ -653,7 +668,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if self.path == '/sharedInbox' or self.path == '/inbox': if self.path == '/sharedInbox' or self.path == '/inbox':
print('DEBUG: POST to shared inbox') print('DEBUG: POST to shared inbox')
if self._updateInboxQueue('inbox',messageJson): queueStatus-_updateInboxQueue('inbox',messageJson)
if queueStatus==0:
self.send_response(200)
self.end_headers()
self.server.POSTbusy=False
return
if queueStatus==1:
self.send_response(403)
self.end_headers()
self.server.POSTbusy=False
return return
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
@ -694,6 +718,7 @@ def runDaemon(clientToServer: bool,baseDir: str,domain: str, \
httpd.inboxQueue=[] httpd.inboxQueue=[]
httpd.sendThreads=[] httpd.sendThreads=[]
httpd.postLog=[] httpd.postLog=[]
httpd.maxQueueLength=16
httpd.ocapAlways=ocapAlways httpd.ocapAlways=ocapAlways
httpd.acceptedCaps=["inbox:write","objects:read"] httpd.acceptedCaps=["inbox:write","objects:read"]
if noreply: if noreply:

View File

@ -526,6 +526,7 @@ def threadSendPost(session,postJsonObject: {},federationList: [],\
if postResult: if postResult:
if debug: if debug:
print('DEBUG: json post to '+inboxUrl+' succeeded') print('DEBUG: json post to '+inboxUrl+' succeeded')
if postJsonObject.get('published'):
postLog.append(postJsonObject['published']+' '+postResult+'\n') postLog.append(postJsonObject['published']+' '+postResult+'\n')
# keep the length of the log finite # keep the length of the log finite
# Don't accumulate massive files on systems with limited resources # Don't accumulate massive files on systems with limited resources